home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / tools / rem_chans.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-11  |  4.6 KB  |  142 lines

  1. /*****************************************************************************
  2. * Comment the channel lines out of a tailoring file.  This is intended to    *
  3. * be run after fixtai has extraced the channel information into a            *
  4. * static-initialization.  The looked-for commands MUST agree with            *
  5. * the ones processed by fixtai.  The comment convention MUST agree           *
  6. * with the one used in the uncomment program used just before fixtai         *
  7. * is run                                                                     *
  8. *                                                                            *
  9. * Another subtlety is that the various functional pieces must agree          *
  10. * with the corresponding pieces in fixtai, even though they have been        *
  11. * recoded and may not look the same (e.g., cmdsrch, tai_token,               *
  12. * lexequ).                                                                   *
  13. *                                                                            *
  14. * Wed May 30 08:42:42 EDT 1984, bpc                                          *
  15. *****************************************************************************/
  16.  
  17. #include "util.h"
  18. #include "cmd.h"
  19.  
  20. #define     COMMENT_CHAR    ';'
  21. #define     COMMENT     ";:;"   /* Our special comment character */
  22.  
  23. extern int errno;
  24. extern char *malloc();
  25.  
  26. FILE * tai_handle;      /* for reading the tailoring file */
  27. #define MAXLINE     500 /* Max length of a line in the tailoring file */
  28. char tai_line[MAXLINE];
  29.  
  30. /*
  31. ** These next MUST agree with the corresponding data in fixtai
  32. */
  33. #define MMTBL           1
  34. #define MMCHAN          2
  35. #define ALIAS        3
  36. Cmd mycmdtab[] =
  37. {
  38.     "mchn",        MMCHAN,     1,
  39.     "mchan",       MMCHAN,     1,
  40.     "mtable",      MMTBL,      1,
  41.     "mtbl",        MMTBL,      1,
  42.     "alias",       ALIAS,      1,
  43.     0,             0,          0
  44. };
  45. /* */
  46. main (argc, argv)
  47.     char * argv[];
  48. {
  49.     if (argc != 2)
  50.     {
  51.     fprintf (stderr, "usage: %s tailoringfile_name\n", argv[0]);
  52.     exit (1);
  53.     }
  54.     tai_handle = fopen (argv[1], "r");
  55.     if (tai_handle == NULL)
  56.     {
  57.     fprintf (stderr, "Can't access tailoring file '%s'", argv[1]);
  58.     exit (1);
  59.     }
  60.     read_line ();
  61.     for ( ; ; )
  62.     {
  63.     char token[100];    /* First token on the line */
  64.     
  65.     if (tai_token (tai_line, token) != OK
  66.                             || mycmdsrch (token, mycmdtab) != OK)
  67.     {
  68.         printf ("%s", tai_line);
  69.         read_line ();
  70.     }
  71.     else
  72.         do             /* It is one of our commands, so 'remove' it */
  73.         {
  74.             printf ("%s%s", COMMENT, tai_line);
  75.             read_line ();
  76.         } while (tai_token (tai_line, token) != OK);
  77.     }
  78. }
  79. /* */
  80. mycmdsrch (str, cmd)        /* find command. return token reference */
  81.     char str[];                 /* test string  */
  82.     register Cmd *cmd;          /* table of known commands */
  83. {
  84.     for ( ; (cmd -> cmdname) != (char *) 0; cmd++)
  85.     if (lexequ (str, cmd -> cmdname))
  86.         return (OK);        /* got a hit */ 
  87.     return (NOTOK);
  88. }
  89.  
  90.  
  91. /*****************************************************************************
  92. *                           | r e a d _ l i n e |                            *
  93. *                            *******************                             *
  94. * Read the next line from the tailoring file.  If we hit EOF, just           *
  95. * quit                                                                       *
  96. *****************************************************************************/
  97. read_line ()
  98. {
  99.     if (fgets (tai_line, MAXLINE-1, tai_handle) == NULL)
  100.     exit (0);
  101. }
  102. /* /*****************************************************************************
  103. *                           | t a i _ t o k e n |                            *
  104. *                            *******************                             *
  105. * Find the first token on the supplied line - copy it out as                 *
  106. * requested                                                                  *
  107. *****************************************************************************/
  108. tai_token (strp, tokenp)
  109.     register char * strp;
  110.     register char * tokenp;
  111. {
  112.     if (!isalnum (*strp))
  113.     return (NOTOK);
  114.     for ( ; ; )
  115.     switch (*strp)
  116.     {
  117.         default:        /* just copy it                     */
  118.         *tokenp++ = *strp++;
  119.         break;
  120.  
  121.         case '\\':      /* quote next character             */
  122.         case '=':   /* make '=' prefix to pair  */
  123.         case '\"':      /* beginning or end of string       */
  124.         return (NOTOK); /* No commands we care about will
  125.                    include this stuff */
  126.  
  127.         case ' ':
  128.         case '\t':
  129.         case '\n':
  130.         case '\r':
  131.         case ',':
  132.         case ';':
  133.         case ':':
  134.         case '/':
  135.         case '|':
  136.         case '.':
  137.         case '\0':
  138.         *tokenp = '\0';
  139.         return (OK);
  140.     }
  141. }
  142.