TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: JARI LAAKSONEN
date: 1997-03-28 21:58:00
subject: 10/11 Comment utilities for Java

========== CSplit: Version 2.0 ==========
========== CSplit: Begin part 10/11 ==========
            break;
        case CPState.StarInCppComment:
        case CPState.InCppComment:
            if (theEvent == CPEvent.FOUND_NL)
            {
                // End of comment, clear flag.
                slashPrinted = false;
            }
            // fall thru.
        case CPState.InCComment:
            rc = true;
            break;
        }
        // Newline can be printed always.
        if (theEvent == CPEvent.FOUND_NL)
        {
            rc = true;
        }
        if (rc)
            printChar();
    }
}
public class Extractor
{
    public static void main (String args[])
    {
        CommentExtractor obj = new CommentExtractor();
        int argc = args.length;
        if (! obj.init (argc, args))
        {
            System.err.println ("USAGE: Extractor InFile [OutFile]");
        }
        else
        {
            obj.setWhiteSpace (false);
            obj.setLineNumbers (true);
            obj.run();
            obj.unInit();
        }
    }
}
========== CSplit: End file Extractor.java ==========
========== CSplit: Begin file Remover.java ==========
/**
 * Remover.java
 * Implementation of comment remover.
 *
 * ver 1.0, 23 Mar 1997
 *
 * Public domain by:
 *   Jari Laaksonen
 *   Arkkitehdinkatu 30 A 2
 *   FIN-33720 Tampere
 *   FINLAND
 *
 *   Fidonet : 2:221/360.20
 *   Internet: jla@to.icl.fi
 */
class CommentRemover extends CommentParser
{
    private boolean backsl = false;
    private boolean nl = false;
    //==================================================================
    /**
     * Action processor.
     */
    protected void processActions (int theEvent)
    {
        boolean rc = true;
        switch (itsState)
        {
        case CPState.NormalInput:
            if (theEvent == CPEvent.FOUND_SLASH)
            {
                rc = false;                 // Don't print it yet...
            }
            break;
        case CPState.BeginComment:
            switch (theEvent)
            {
            case CPEvent.FOUND_BACKSLASH:   // Escaped character.
                backsl = true;
            case CPEvent.FOUND_SLASH:   // Yes, it's a C++ comment...
            case CPEvent.FOUND_STAR:    // Yes, it's a C-style comment.
                rc = false;
                break;
            default:                        // No, just a slash...
                // Print the previous slash.
                print ('/');
                if (backsl)
                {
                    // Print the previous backslash.
                    print ('\\');
                    backsl = false;
                }
                if (nl)
                {
                    // Print the previous newline.
                    print ('\n');
                    nl = false;
                }
                break;
            }
            break;
        case CPState.InsideEscape:
            switch (itsPrevState)
            {
            case CPState.InCppComment:
            case CPState.InCComment:
            case CPState.StarInCppComment:
            case CPState.StarInCComment:
                rc = false;
                break;
            case CPState.BeginComment:
                if (theEvent == CPEvent.FOUND_NL)
                {
                    rc = false;             // Don't print it yet...
                    nl = true;
                }
                break;
            }
            break;
        case CPState.InCppComment:
        case CPState.InCComment:
        case CPState.StarInCppComment:
        case CPState.StarInCComment:
            rc = false;
            break;
        }
========== CSplit: End part 10/11 crc: 22d4 ==========
        // Albert                      email: jla@to.icl.fi
--- GoldED/2 2.50+
---------------
* Origin: Albert's Point/2 in Finland, Europe (2:221/360.20)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.