home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 13ansi / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.5 KB  |  72 lines

  1. /*
  2.  *    parse -- process a list of attribute specifications
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <local\ansi.h>
  7. #include <local\std.h>
  8. #include <local\ibmcolor.h>
  9.  
  10. /* buffer length for string comparisons */
  11. #define NCHARS    3
  12. #define C_MASK    0x7
  13.  
  14. void
  15. parse(nargs, argvec)
  16. int nargs;    /* number of argument vectors */
  17. char *argvec[];    /* pointer to the argument vector array */
  18. {
  19.     int i, intensity;
  20.     int attribute;
  21.     POSITION pos;
  22.     char str[NCHARS + 1];
  23.     extern int colornum(char *);
  24.     extern void setattr(POSITION, int);
  25.  
  26.     /* clear all attributes */
  27.     ANSI_SGR(ANSI_NORMAL);
  28.  
  29.     /* look for a single attribute specification */
  30.     if (nargs == 2) {
  31.         attribute = colornum(argvec[1]);
  32.         switch (attribute) {
  33.         case IBM_NORMAL:
  34.             palette(0, IBM_BLACK);
  35.             return;
  36.         case IBM_REVERSE:
  37.             ANSI_SGR(ANSI_REVERSE);
  38.             palette(0, IBM_WHITE);
  39.             return;
  40.         case IBM_INVISIBLE:
  41.             ANSI_SGR(ANSI_INVISIBLE);
  42.             return;
  43.         case IBM_BLINK:
  44.             ANSI_SGR(ANSI_BLINK);
  45.             return;
  46.         }
  47.     }
  48.  
  49.     /* must be separate attribute specifications */
  50.     pos = FGND;
  51.     intensity = 0;
  52.     for (i = 1; i < nargs; ++i) {
  53.         attribute = colornum(argvec[i]);
  54.         if (attribute == -1) {
  55.             ANSI_ED;
  56.             fprintf(stderr, "\nIllegal parameter\n");
  57.             exit (2);
  58.         }
  59.         if (attribute == IBM_BRIGHT) {
  60.             intensity = IBM_BRIGHT;
  61.             continue;
  62.         }
  63.         setattr(pos, attribute | intensity);
  64.         if (pos == FGND)
  65.             pos = BKGND;
  66.         else if (pos == BKGND)
  67.             pos = BDR;
  68.         intensity = 0;
  69.     }
  70.     return;
  71. }
  72.