home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / CMTCONVR.CPP < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  76 lines

  1. // +++Date last modified: 05-Jul-1997
  2.  
  3. /*
  4.  * CMTCONVR.CPP
  5.  * Implementation of comment converter.
  6.  *
  7.  * ver 1.0, 30 Jun 1996
  8.  *
  9.  * Public domain by:
  10.  *   Jari Laaksonen
  11.  *   Arkkitehdinkatu 30 A 2
  12.  *   FIN-33720 Tampere
  13.  *   FINLAND
  14.  *
  15.  *   Fidonet : 2:221/360.20
  16.  *   Internet: jla@to.icl.fi
  17.  */
  18.  
  19. #include "cmtconvr.h"
  20.  
  21. void CommentConverter::ProcessActions (Event theEvent)
  22. {
  23.     switch (itsState)
  24.     {
  25.     case BeginComment:
  26.         if (theEvent == FOUND_SLASH)    // Yes, it's a C++ comment...
  27.         {
  28.             ChangeChar ('*');           // ...change to C-style.
  29.         }
  30.         break;
  31.  
  32.     case InCppComment:
  33.         switch (theEvent)
  34.         {
  35.         case END_OF_FILE:           // EOF: if we are still in C++ comment...
  36.         case FOUND_NL:              // End of C++ comment...
  37.             print (" */");          // ...put ending C-comment mark.
  38.             break;
  39.         }
  40.         break;
  41.  
  42.     case StarInCppComment:
  43.         // End of C comment -- add space to prevent nested C comment.
  44.         // For example: "// /*comment*/"
  45.         //     becomes: "/* /*comment* / */"
  46.         if (theEvent == FOUND_SLASH)
  47.         {
  48.             print (' ');
  49.         }
  50.         break;
  51.     }
  52.  
  53.     PrintChar();
  54. }
  55.  
  56. int   main (int argc, char **argv)
  57. {
  58.     CommentConverter CommConv;
  59.  
  60.     if (0 == CommConv.Init (argc, argv))
  61.     {
  62.         fprintf (stderr, "USAGE: CMTCONVR InFile [OutFile]\n");
  63.     }
  64.     else
  65.     {
  66.         CommConv.Run();
  67.         CommConv.Uninit();
  68.  
  69.         fprintf (stderr, "\nOK! %lu lines processed. Last state = %d\n",
  70.             CommConv.GetLines(), CommConv.GetLastState()
  71.         );
  72.     }
  73.  
  74.     return 0;
  75. }
  76.