--------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: E3^00021 Date: 03/28/97 From: JARI LAAKSONEN Time: 09:58pm \/To: ALL (Read 5 times) Subj: 05/11 Comment utilities for Java ========== CSplit: Version 2.0 ========== ========== CSplit: Begin part 5/11 ========== if (ReadCh == '\n') { print ('\r'); } print (ReadCh); } } //================================================================== /** * Print current line number. */ protected void printLineNumber() { String str = "\n" + lines + ":\n"; print (str); } //================================================================== /** * Write current state to output file. */ protected void logState() { if (itsPrevState == itsState) return; String str = "\t\t\t\t| "; CPState st = new CPState (itsState); str += st.toString(); str += "\n"; print (str); } //==================================================================== /** * The heart of the comment parser. A finite state machine which * does nothing else than determines the current state based on * the events. */ private void processState (int theEvent) { if (itsState != CPState.InsideEscape) itsPrevState = itsState; // Escaped character. if (theEvent == CPEvent.FOUND_BACKSLASH) { itsState = CPState.InsideEscape; return; } switch (itsState) { case CPState.NormalInput: switch (theEvent) { case CPEvent.FOUND_QUOTE: itsState = CPState.InsideString; break; case CPEvent.FOUND_SINGLEQUOTE: itsState = CPState.InsideChar; break; case CPEvent.FOUND_SLASH: // to be investigated: begin of comment. itsState = CPState.BeginComment; break; } break; case CPState.InsideString: switch (theEvent) { case CPEvent.FOUND_QUOTE: // End of the string. itsState = CPState.NormalInput; break; } break; case CPState.InsideChar: switch (theEvent) { case CPEvent.FOUND_SINGLEQUOTE: // End of the character constant. itsState = CPState.NormalInput; break; } break; // We have found a '/', maybe this is a comment... case CPState.BeginComment: switch (theEvent) { case CPEvent.FOUND_SLASH: // Yes, it's a C++ comment. itsState = CPState.InCppComment; break; case CPEvent.FOUND_STAR: // Yes, it's a C comment. itsState = CPState.InCComment; break; default: // No, just a slash. itsState = CPState.NormalInput; break; } break; case CPState.InsideEscape: // Found backslash -- restore previous state. itsState = itsPrevState; break; case CPState.InCppComment: switch (theEvent) { case CPEvent.FOUND_CR: case CPEvent.FOUND_NL: // Newline is end of C++ comment. itsState = CPState.NormalInput; break; case CPEvent.FOUND_STAR: itsState = CPState.StarInCppComment; break; } break; case CPState.InCComment: switch (theEvent) { case CPEvent.FOUND_STAR: // to be investigated: end of comment. itsState = CPState.StarInCComment; break; } break; // '*' in C++ comment: action processors can use this to check // e.g. C comments inside C++ comment. ========== CSplit: End part 5/11 crc: 898b ========== // Albert email: jla@to.icl.fi --- GoldED/2 2.50+ * Origin: Albert's Point/2 in Finland, Europe (2:221/360.20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: E3^00022 Date: 03/28/97 From: JARI LAAKSONEN Time: 09:58pm \/To: ALL (Read 5 times) Subj: 06/11 Comment utilities for Java ========== CSplit: Version 2.0 ========== ========== CSplit: Begin part 6/11 ========== case CPState.StarInCppComment: switch (theEvent) { case CPEvent.FOUND_STAR: // another '*' -- don't change state. itsState = CPState.StarInCppComment; break; case CPEvent.FOUND_CR: case CPEvent.FOUND_NL: // Newline is end of C++ comment. itsState = CPState.NormalInput; break; default: itsState = CPState.InCppComment; break; } break; // We are inside a C comment, and there is a '*'; // maybe this is the end of the comment... case CPState.StarInCComment: switch (theEvent) { case CPEvent.FOUND_STAR: // another '*' -- don't change state. itsState = CPState.StarInCComment; break; case CPEvent.FOUND_SLASH: // Yes, it's end of the C comment. itsState = CPState.NormalInput; break; default: // No, we are still in C comment. itsState = CPState.InCComment; break; } break; } } //================================================================== /** * Read character from input file. * @return read character. */ private int readChar() { int ch; try { ch = InFile.read(); // BugBug: this assumes that input files contain // 0x0D0A, not just 0x0D. // TODO: implement own input buffer to emulate // DOSish text mode read. if (ch == '\r') { ch = InFile.read(); } ReadCh = ch; } catch (IOException e) { System.err.println (e.toString()); ReadCh = EOF; } return ReadCh; } //================================================================== /** * Selects the next event according to the read character. * Increments the number of read lines. * @see CPEvent#getEvent * @return the value of event. */ private int getEvent() { int theEvent = CPEvent.getEvent(ReadCh); if (ReadCh == '\n') { // count processed lines, if someone needs it... lines++; } return theEvent; } } ========== CSplit: End file CommentParser.java ========== ========== CSplit: Begin file Converter.java ========== /** * Converter.java * Implementation of comment converter. * * 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 CommentConverter extends CommentParser { //================================================================== /** * Action processor. */ protected void processActions (int theEvent) { switch (itsState) { case CPState.BeginComment: // Yes, it's a C++ comment... if (theEvent == CPEvent.FOUND_SLASH) { changeChar ('*'); // ...change to C-style. } break; case CPState.InCppComment: switch (theEvent) { // EOF: if we are still in C++ comment... case CPEvent.END_OF_FILE: case CPEvent.FOUND_NL: // End of C++ comment... print (" */"); // ...put ending C-comment mark. break; } break; case CPState.StarInCppComment: switch (theEvent) { // End of C comment -- add space to prevent nested C comment. // For example: "// /*comment*/" ========== CSplit: End part 6/11 crc: 26fc ========== // Albert email: jla@to.icl.fi --- GoldED/2 2.50+ * Origin: Albert's Point/2 in Finland, Europe (2:221/360.20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: E3^00023 Date: 03/28/97 From: JARI LAAKSONEN Time: 09:58pm \/To: ALL (Read 5 times) Subj: 07/11 Comment utilities for Java ========== CSplit: Version 2.0 ========== ========== CSplit: Begin part 7/11 ========== // becomes: "/* /*comment* / */" case CPEvent.FOUND_SLASH: print (' '); break; case CPEvent.FOUND_NL: // End of C++ comment... print (" */"); // ...put ending C-comment mark. break; } break; } printChar(); } } public class Converter { public static void main (String args[]) { CommentConverter obj = new CommentConverter(); int argc = args.length; if (! obj.init (argc, args)) { System.err.println ("USAGE: Converter InFile [OutFile]"); } else { obj.run(); obj.unInit(); } } } ========== CSplit: End file Converter.java ========== ========== CSplit: Begin file Counter.java ========== /** * Counter.java * Implementation of comment counter. * * 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 CommentCounter extends CommentParser { private long code_lines = 0; private long cpp_comments = 0; private long cmt_lines = 0; private int open_comment = 0; private int close_comment = 0; private long tot_cpp_comments = 0; private long tot_cmt_lines = 0; private long tot_lines = 0; private long tot_code_lines = 0; private int chars = 0; //================================================================== /** * */ public CommentCounter() { reset(); } //================================================================== /** * @return the number of code lines. */ public long getCodeLines() { return code_lines; } //================================================================== /** * @return the number of C++ style comments. */ public long getCppComments() { return cpp_comments; } //================================================================== /** * @return the number of comment lines. */ public long getCommentLines() { return cmt_lines; } //================================================================== /** * @return the number of open comments. */ public int getOpenComment() { return open_comment; } //================================================================== /** * @return the number of close comments. */ public int getCloseComment() { return close_comment; } //================================================================== /** * @return the total number of C++ style comments. */ public long getTotCppComments() { return tot_cpp_comments; } //================================================================== /** * @return the total number of comment lines. */ public long getTotCommentLines() { return tot_cmt_lines; } //================================================================== /** * @return the total number of lines. */ public long getTotLines() { ========== CSplit: End part 7/11 crc: dd05 ========== // Albert email: jla@to.icl.fi --- GoldED/2 2.50+ * Origin: Albert's Point/2 in Finland, Europe (2:221/360.20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: E3^00024 Date: 03/28/97 From: JARI LAAKSONEN Time: 09:58pm \/To: ALL (Read 5 times) Subj: 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) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: E3^00025 Date: 03/28/97 From: JARI LAAKSONEN Time: 09:58pm \/To: ALL (Read 5 times) Subj: 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) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: E3^00026 Date: 03/28/97 From: JARI LAAKSONEN Time: 09:58pm \/To: ALL (Read 5 times) Subj: 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) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: E3^00027 Date: 03/28/97 From: JARI LAAKSONEN Time: 09:58pm \/To: ALL (Read 5 times) Subj: 11/11 Comment utilities for Java ========== CSplit: Version 2.0 ========== ========== CSplit: Begin part 11/11 ========== if (! nl && theEvent == CPEvent.FOUND_NL) { rc = true; } if (rc) printChar(); } } public class Remover { public static void main (String args[]) { CommentRemover obj = new CommentRemover(); int argc = args.length; if (! obj.init (argc, args)) { System.err.println ("USAGE: Remover InFile [OutFile]"); } else { obj.run(); obj.unInit(); System.err.println ( "\nOK! " + obj.getLines() + " lines processed. Last state = " + obj.getLastStateStr() ); } } } ========== CSplit: End file Remover.java ========== ========== CSplit: Begin file cmttests.c ========== /* +++Date last modified: 02-Aug-1996 */ /* * Test file for Comment Utilities. * This file should be compilable before AND after comment * conversion or removal. * * Jari Laaksonen * Arkkitehdinkatu 30 A 2 * FIN-33720 Tampere * FINLAND * Fidonet: 2:221/360.20 * Internet: jla@to.icl.fi */ #include int main() { /* comment */ int a; /* comment continues in same line */ /* C comment */ int b; // C++ comment /* C comment */ int c; // C++ comment /**** comment ****/ //*** comment ****/ char ch = '\"'; /* double quote but not a start of a string */ char x1[] // here we... = ""; char x2[] = ""; /* ...have some... */ char x3[] = "" /* ...empty... */ ; char x4[] = ""; // ...strings. printf ("this is a string"); /* C comment */ printf ("this is \" another string"); // C++ comment printf ("this is \' another string"); // C++ comment printf ("yet another \\ string"); // C++ comment /* C comment in one line */ // C++ comment in one line /* C comment in several lines printf ("// not a comment"); */ /* C comment in several lines */ // C comment in C++ comment: /* comment */ /* C++ comment in C comment: // comment */ /* C++ comment in C comment: // comment */ printf ("this /* is not // a comment * * ! "); printf ("this /* is not a comment * * ! "); printf ("this // is not a comment * * ! "); printf ("this */ is not a comment * * ! "); // C++ comment // C++ comment / // C++ comment in \ several \ lines /\ / C++ comment a = 0; /\ * C comment */ /* C *\ * * \* comment */ /* C comment \ C comment */ // char s[] = "string \ string"; // not a multiline C++ \comment b = 0; // not a multiline C++ \ comment c = 0; return 0; } // end file ========== CSplit: End file cmttests.c ========== ========== CSplit: End part 11/11 crc: 5b44 ========== // Albert email: jla@to.icl.fi --- GoldED/2 2.50+ * Origin: Albert's Point/2 in Finland, Europe (2:221/360.20) --------------- FIDO MESSAGE AREA==> TOPIC: 203 C++ Ref: E3^00028 Date: 03/31/97 From: MAX BADRAK Time: 01:08am \/To: KEVIN CAMPBELL (Read 5 times) Subj: MS-DOS Env. Hello, Kevin! KC> Does anyone know how to inset information into the environment block KC> (eg: SET Bob=C:\Bob\), inside a C++ program in a way that the KC> information will remain, even when the program exits, or, the program KC> quits using dos_keep() (a TSR). TC> I suggest you read SNIPPETS ENVIRON.TXT file. That will give you TC> more info. Its kind of impossible to do, unless you're willing to TC> back up and rewrite the user's AUTOEXEC.BAT file to reflect the TC> change and have the user reboot. That's about the only way I can TC> see it would work. There is an undocumented way to obtain pointer to the MS-DOS "master" environment. I've used it to set PATH variable to length more than 128 bytes. And it works. At least under MS-DOS 6.22. The idea comes from "UNDOCUMENTED DOS" by Andrew Schulman andrew@pharlap.com uunet!pharlap!andrew CIS: 76320,302 (files last updated at 23 January 1990) And here is the part of my source: ------------------- REGS r1; SREGS r2; r1.x.ax=0x352e; int86x(0x21,&r1,&r1,&r2); int E2VectSeg=r2.es; unsigned *EnvSegPointer=(unsigned *)MK_FP(E2VectSeg,0x002c); char *EnvPointer=(char *)MK_FP(*EnvSegPointer,0); /*pointer to master environment */ unsigned EnvSize=(*(int *)MK_FP(*EnvSegPointer-1,3))*0x10; //size of master environment according to its MCB */ ------------------- I hope it will help. Good bye. Max --- * Origin: (2:463/321.1023)