home *** CD-ROM | disk | FTP | other *** search
/ Micro R&D 1 / MicroRD-CD-ROM-Vol1-1994.iso / os30 / cli / setcon.lha / SetCon.c < prev   
C/C++ Source or Header  |  1993-05-20  |  3KB  |  96 lines

  1. /*      SetCon
  2.  *        by
  3.  *    Phil Dietz -- NCEMRSoft 1993
  4.  *
  5.  *    USAGE:    SetCon FORE/N,BACK/N,CLEAR/S,BOLD/S,FAINT/S,ITALIC/S,
  6.  *                     UNDER/S,REVERSE/S,CONCEAL/S,RESTORE/S,RESET/S
  7.  *
  8.  *              FORE #    - sets forground color from color0 to color9
  9.  *              BACK #    - sets background color from color0 to color9
  10.  *              CLEAR     - clears the screen
  11.  *              BOLD      - sets bold
  12.  *              FAINT     - sets faint
  13.  *              ITALIC    - sets italic
  14.  *              UNDER     - sets underline
  15.  *              REVERSE   - sets reverse
  16.  *              CONCEAL   - sets conceal (warning invisible!)
  17.  *              RESTORE   - (DEFAULT) restores to the last style/SGR
  18.  *                          'SetCon RESTORE' is the same as just 'SetCon'.
  19.  *              RESET     - resets the style to the bootup style
  20.  *
  21.  *    SUMMARY:  Sets the style for the current console/shell.
  22.  *              In WB3.0, SetCon will also store your custom style as the
  23.  *              default SGR/shell style so clears and resets
  24.  *              won't erase your fav. settings!!
  25.  *
  26.  *    REQUIREMENTS:  WB2.0 version 37
  27.  *                   WB3.0 to use SGR setting option
  28.  *
  29.  *    NOTES:    This program is PURE so it can be made RESIDENT.
  30.  *              If you cant see what you are typing, try 'setcon reset'
  31.  *              or just type ESCc
  32.  *
  33.  */
  34.  
  35. #include <stdio.h>
  36. #include <exec/types.h>
  37. #include <exec/memory.h>
  38. #include <dos/dos.h>
  39. #include <dos/dosextens.h>
  40. #include <dos/rdargs.h>
  41. #include <libraries/dos.h>
  42. #include <libraries/dosextens.h>
  43. #include <devices/conunit.h>
  44. #include <proto/dos.h>
  45. #include <proto/exec.h>
  46. #include <clib/dos_protos.h>
  47. #include <clib/exec_protos.h>
  48.  
  49. #define RESTORE    "\33[0m"
  50. #define TEMPLATE   "FORE/N,BACK/N,CLEAR/S,BOLD/S,FAINT/S,ITALIC/S,UNDER/S,REVERSE/S,CONCEAL/S,RESTORE/S,RESET/S\n"
  51. #define NUM        11
  52.  
  53. static char *ver="$VER: SetCon (19.5.93) by Phil Dietz";
  54.  
  55. static char *style[NUM]={
  56.    "\33[3xm",   /* Initial forgorund string */
  57.    "\33[4xm",   /* Initial background string */
  58.    "\14",       /* Clear  */
  59.    "\33[1m",    /* Bold   */
  60.    "\33[2m",    /* Faint  */
  61.    "\33[3m",    /* Italic */
  62.    "\33[4m",    /* Underline */
  63.    "\33[7m",    /* Reverse video */
  64.    "\33[8m",    /* Concealed mode */
  65.    RESTORE,     /* Restore from last SGR */
  66.    "\33c"       /* Reset all style and colors */
  67.    };
  68.  
  69. int __oslibversion=37;   /* SAS/C var. to prevent <KS37 from running */
  70.  
  71. main()
  72.    {
  73.    struct RDArgs *rd;
  74.    LONG *args;
  75.    int i=0;
  76.  
  77.    args=(LONG *)AllocMem(NUM*4,MEMF_PUBLIC | MEMF_CLEAR);  /* Get array  */
  78.      rd=ReadArgs(TEMPLATE,args,NULL);                      /* Parse args */
  79.  
  80.    PutStr(RESTORE);     /* RESTORE to default style        */
  81.  
  82.    for(;i<NUM;i++)      /* Scan args and print strings     */
  83.       if(args[i])
  84.          {
  85.          if(i<2)   /* Replace x in style with ASCII number */
  86.             style[i][3]=*((LONG *)args[i])+48;
  87.          PutStr(style[i]);
  88.          }
  89.  
  90.    PutStr("\33[ s");     /* Set default style/SGR in WB3.0 */
  91.                          /*   which is harmless in WB2.0 */
  92.    Flush(Output());      /* Flush the output to the CON: */
  93.    FreeArgs(rd);         /* Free the readargs structure  */
  94.    FreeMem(args,NUM*4);  /* Free memory for flag stuff   */
  95.    }
  96.