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

  1. /*
  2.  *    userattr -- set video attributes to user-specified values
  3.  *    (DOS environment parameters) or to reasonable defaults and
  4.  *    return success or a failure indication for bad attributes
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <local\std.h>
  11. #include <local\ansi.h>
  12. #include <local\ibmcolor.h>
  13.  
  14. int
  15. userattr(foreground, background, border)
  16. char *foreground, *background, *border;
  17. {
  18.     register char *s;
  19.     static int attrset(POSITION, char *);
  20.     
  21.     if ((s = getenv("FGND")) == NULL)
  22.         s = foreground;
  23.     if (attrset(FGND, s) == -1)
  24.         return FAILURE;
  25.  
  26.     if ((s = getenv("BKGND")) == NULL)
  27.         s = background;
  28.     if (attrset(BKGND, s) == -1)
  29.         return FAILURE;
  30.  
  31.     if ((s = getenv("BORDER")) == NULL)
  32.         s = border;
  33.     if (attrset(BDR, s) == -1)
  34.         return FAILURE;
  35.  
  36.     return SUCCESS;
  37. }
  38.  
  39. /*
  40.  *    attrset -- parse the color spec and try to set it.
  41.  *    return 0 if OK and -1 upon error (bad color number)
  42.  */
  43. static int
  44. attrset(apos, str)
  45. POSITION apos;
  46. register char *str;
  47. {
  48.     register int attr;
  49.     extern int colornum(char *);
  50.     extern void setattr(POSITION, int);
  51.  
  52.     if ((attr = colornum(strtok(str, " \t"))) == IBM_BRIGHT)
  53.         attr |= colornum(strtok(NULL, " \t"));
  54.     if (attr >= 0)
  55.         setattr(apos, attr);
  56.     else
  57.         return (-1);
  58.     return (0);
  59. }
  60.