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

========== CSplit: Version 2.0 ==========
========== CSplit: Begin part 3/11 ==========
        case StarInCComment:    str = "StarInCComment";       break;
        default:                str = "** unknown state **";  break;
        }
        return str;
    }
}
/**
 *  class CPEvent contains Event constants and one static method
 *  that maps given character to event.
 */
class CPEvent
{
    /**
     * Event constants.
     */
    static final int ANY_CHAR           = 0;
    static final int FOUND_BACKSLASH    = 1;
    static final int FOUND_NL           = 2;
    static final int FOUND_QUOTE        = 3;
    static final int FOUND_SINGLEQUOTE  = 4;
    static final int FOUND_SLASH        = 5;
    static final int FOUND_STAR         = 6;
    static final int FOUND_WHITESPACE   = 7;
    static final int END_OF_FILE        = 8;
    static final int FOUND_CR           = 9;
    //==================================================================
    /**
     * Selects the next event according to the read character.
     * @return the value of event.
     */
    static public int getEvent (int ch)
    {
        int v;
        switch (ch)
        {
        case ' ':
        case '\t': v = FOUND_WHITESPACE;   break;
        case '\"': v = FOUND_QUOTE;        break;
        case '\'': v = FOUND_SINGLEQUOTE;  break;
        case '\\': v = FOUND_BACKSLASH;    break;
        case '\n':
        case '\r': v = FOUND_NL;           break;
        case '/':  v = FOUND_SLASH;        break;
        case '*':  v = FOUND_STAR;         break;
        default:   v = ANY_CHAR;           break;
        }
        return v;
    }
}
/**
 *  class CommentParser
 */
abstract class CommentParser
{
    static final int EOF = -1;
    protected int           itsState = CPState.NormalInput;
    protected int           itsPrevState;
    private long            lines = 0;
    private int             bOutFile = 0;
    private int             ReadCh;
    private InputStream     InFile;
    private OutputStream    OutFile;
    //==================================================================
    /**
     *
     */
    public CommentParser (int InitState)
    {
        itsState = InitState;
    }
    //==================================================================
    /**
     *
     */
    public CommentParser ()
    {
    }
    //==================================================================
    /**
     * Initialization method which takes the program's command line
     * arguments and opens the input file and optionally the output
     * file.
     * @return true if successful, false if failed or no arguments.
     */
    public boolean init (int argc, String argv[])
    {
        if (argc < 1)
        {
            return false;
        }
        if (! init (argv[0], CPState.NormalInput))
        {
            return false;
        }
        if (argc == 2)
        {
            if (argv[0].equalsIgnoreCase (argv[1]))
            {
                // input and output files cannot be the same,
                // output goes to stdout instead.
                OutFile = System.out;
            }
            else
            {
                try
                {
                    OutFile = new FileOutputStream (argv[1]);
                    bOutFile = 1;
                }
                catch (IOException e)
                {
                    System.err.println (e.toString());
                    OutFile = System.out;
                }
            }
        }
        return true;
    }
    //==================================================================
    /**
     * Initialization method which opens the input file.
     * Action processors that don't need output file can use this
     * function.
     * @return true if successful, false if failed or no arguments.
     */
    public boolean init (String file, int InitState)
    {
        itsState = InitState;
        OutFile = System.out;
========== CSplit: End part 3/11 crc: 0e46 ==========
        // 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™.