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

========== CSplit: Version 2.0 ==========
========== CSplit: Begin part 8/11 ==========
        return tot_lines;
    }
    //==================================================================
    /**
     * @return the total number of code lines.
     */
    public long getTotCodeLines()
    {
        return tot_code_lines;
    }
    //==================================================================
    /**
     * Reset the counter values.
     */
    public void reset()
    {
        code_lines = 0;
        cmt_lines = 0;
        cpp_comments = 0;
        open_comment = 0;
        close_comment = 0;
    }
    //==================================================================
    /**
     * Count the total values.
     */
    public void sumTotals()
    {
        tot_cpp_comments += cpp_comments;
        tot_cmt_lines    += cmt_lines;
        tot_lines        += getLines();
        tot_code_lines   += code_lines;
    }
    //==================================================================
    /**
     * Action processor.
     */
    protected void processActions (int theEvent)
    {
        if (theEvent == CPEvent.FOUND_NL)
        {
            switch (itsState)
            {
            case CPState.BeginComment:
                code_lines++;
                break;
            case CPState.InCppComment:
                if (chars > 0)
                    code_lines++;
                break;
            case CPState.InCComment:
            case CPState.StarInCComment:
                break;
            case CPState.InsideEscape:
                if (itsPrevState == CPState.InCppComment)
                    cmt_lines++;
                if (itsPrevState == CPState.InCppComment
                    || itsPrevState == CPState.InCComment)
                    break;
            default:
                if (chars > 0)
                    code_lines++;
            }
            if (open_comment > close_comment)
            {
                cmt_lines++;
            }
            chars = 0;
        }
        switch (itsState)
        {
        case CPState.NormalInput:
            switch (theEvent)
            {
            case CPEvent.FOUND_SLASH:
            case CPEvent.FOUND_CR:
            case CPEvent.FOUND_NL:
            case CPEvent.FOUND_WHITESPACE:
                break;
            default:
                chars++;
            }
            break;
        case CPState.BeginComment:
            switch (theEvent)
            {
            case CPEvent.FOUND_SLASH:       // Yes, it's a C++ comment.
                cpp_comments++;
                cmt_lines++;
                break;
            case CPEvent.FOUND_STAR:        // Yes, it's a C comment.
                open_comment++;
                cmt_lines++;
                break;
            }
            break;
        case CPState.StarInCComment:
            switch (theEvent)
            {
            case CPEvent.FOUND_SLASH:       // End of C comment.
                close_comment++;
                break;
            }
            break;
        }
    }
}
public class Counter
{
    public static void main (String args[])
    {
        CommentCounter obj = new CommentCounter();
        int argc = args.length;
        if (! obj.init (argc, args))
        {
            System.err.println ("USAGE: Counter InFile");
            System.exit (1);
        }
        obj.run();
        obj.unInit();
        long ratio = 1000 * obj.getCommentLines() / obj.getLines();
        System.err.println (args[0]);
        System.err.println ("C++ cmts     : " + obj.getCppComments());
        System.err.println ("Cmt lin      : " + obj.getCommentLines());
        System.err.println ("Cod lin      : " + obj.getCodeLines());
========== CSplit: End part 8/11 crc: 9103 ==========
        // 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™.