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

  1. /*
  2.  *    colornum -- return the IBM number for the color
  3.  *    presented as a string; return -1 if no match.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <local\ibmcolor.h>
  9.  
  10. #define NCHARS    3
  11.  
  12. int
  13. colornum(name)
  14. char *name;
  15. {
  16.     register int n;
  17.     static struct color_st {
  18.         char *c_name;
  19.         int c_num;
  20.     } colortab[] = {
  21.         "black",    IBM_BLACK,
  22.         "blue",        IBM_BLUE,
  23.         "green",    IBM_GREEN,
  24.         "cyan",        IBM_CYAN,
  25.         "red",        IBM_RED,
  26.         "magenta",    IBM_MAGENTA,
  27.         "brown",    IBM_BROWN,
  28.         "white",    IBM_WHITE,
  29.         "normal",    IBM_NORMAL,
  30.         "bright",    IBM_BRIGHT,
  31.         "light",    IBM_BRIGHT,
  32.         "bold",        IBM_BRIGHT,
  33.         "yellow",    IBM_BROWN + IBM_BRIGHT,
  34.         "blink",    IBM_BLINK,
  35.         "reverse",    IBM_REVERSE,
  36.         "invisible",    IBM_INVISIBLE,
  37.         NULL,        (-1)
  38.     };
  39.  
  40.     (void) strlwr(name);
  41.     for (n = 0; colortab[n].c_name != NULL; ++n)
  42.         if ((strncmp(name, colortab[n].c_name, NCHARS)) == 0)
  43.             return (colortab[n].c_num);
  44.     return (-1);
  45. }
  46.