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: 09/11 Comment utilities for Java

========== CSplit: Version 2.0 ==========
========== CSplit: Begin part 9/11 ==========
        System.err.println ("Tot lin      : " + obj.getLines());
        System.err.println ("Cmt/Lin ratio: " +
            ratio / 10 + "." + ratio % 10 + "%"
        );
        obj.sumTotals();
        obj.reset();
    }
}
========== CSplit: End file Counter.java ==========
========== CSplit: Begin file Extractor.java ==========
/**
 * Extractor.java
 * Implementation of comment extractor.
 *
 * 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 CommentExtractor extends CommentParser
{
    private boolean printWhiteSpace  = false;
    private boolean printLineNumbers = false;
    private boolean backsl = false;
    private boolean nl = false;
    // This flag is needed when comment starting is continued
    // in next line:
    //   /\
    //   * comment */
    // The BeginComment state is still on after InsideEscape state
    // and without flag the slash would be printed twice.
    private boolean slashPrinted = false;
    //==================================================================
    /**
     * Toggles the printing of white space on or off.
     */
    public void setWhiteSpace  (boolean OnOff)
    {
        printWhiteSpace  = OnOff;
    }
    //==================================================================
    /**
     * Toggles the printing of line numbers on or off.
     */
    public void setLineNumbers (boolean OnOff)
    {
        printLineNumbers = OnOff;
    }
    //==================================================================
    /**
     * Action processor.
     */
    protected void processActions (int theEvent)
    {
        boolean rc = false;
        switch (itsState)
        {
        case CPState.NormalInput:
            if (printWhiteSpace && theEvent == CPEvent.FOUND_WHITESPACE)
                rc = true;                  // Print whitespace.
            break;
        case CPState.BeginComment:
            switch (theEvent)
            {
            case CPEvent.FOUND_SLASH:       // Yes, it's a C++ comment.
            case CPEvent.FOUND_STAR:        // Yes, it's a C comment.
                rc = true;
                if (! slashPrinted)
                {
                    if (printLineNumbers)
                    {
                        printLineNumber();
                    }
                    // Comment starting slash was not yet printed,
                    // so print it now.
                    print ('/');
                    if (backsl)
                    {
                        // Print the previous backslash.
                        print ('\\');
                        backsl = false;
                    }
                    if (nl)
                    {
                        // Print the previous newline.
                        print ('\n');
                        nl = false;
                    }
                    slashPrinted = true;
                }
                else
                    slashPrinted = false;
                break;
            case CPEvent.FOUND_BACKSLASH:   // Escaped character.
                backsl = true;
                break;
            default:
                backsl = false;
                nl = false;
            }
            break;
        case CPState.InsideEscape:
            switch (itsPrevState)
            {
            case CPState.InCppComment:
            case CPState.InCComment:
            case CPState.StarInCppComment:
            case CPState.StarInCComment:
                rc = true;
                break;
            case CPState.BeginComment:
                if (theEvent == CPEvent.FOUND_NL)
                {
                    nl = true;
                }
                break;
            }
            break;
        case CPState.StarInCComment:
            if (theEvent == CPEvent.FOUND_SLASH)
            {
                // End of comment, clear flag.
                slashPrinted = false;
            }
            rc = true;
========== CSplit: End part 9/11 crc: eb57 ==========
        // 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™.