home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 21 / CD_ASCQ_21_040595.iso / dos / prg / c / freedos3 / source / jh_utils / cls.c < prev    next >
C/C++ Source or Header  |  1995-01-07  |  2KB  |  122 lines

  1. /*
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.  
  7.    This program is distributed in the hope that it will be useful,
  8.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.    GNU General Public License for more details.
  11.  
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program; if not, write to the Free Software
  14.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.    */
  16.  
  17. /***********************************************************************
  18.  * This program clears the screen and optionally sets the color.
  19.  * Requires ANSI.SYS to be loaded.
  20.  *
  21.  * author: James Hall
  22.  */
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "getopt.h"
  28. #include "freedos.h"
  29.  
  30. /* Define the colors */
  31.  
  32. #define BOLD 1
  33. #define NORMAL 0
  34. #define FOREGROUND 30
  35. #define BACKGROUND 40
  36. #define BLACK 0
  37. #define WHITE 8
  38.  
  39.  
  40. void usage (void);
  41.  
  42.  
  43. main (int argc, char **argv)
  44. {
  45.   int i, iBold = NORMAL, iFore = WHITE, iBack = BLACK, iSet = FALSE;
  46.  
  47.   /* Scan the command line */
  48.  
  49.   while ((i = getopt (argc, argv, "sS?")) != EOF)
  50.     {
  51.       switch (i)
  52.     {
  53.     case 's':
  54.     case 'S':
  55.       iSet = TRUE;
  56.       break;
  57.     default:
  58.       usage ();
  59.       break;
  60.     }
  61.     }
  62.  
  63.   /* How many args are left? */
  64.  
  65.   i = optind;
  66.   if ((argc - i) > 0)
  67.     {
  68.  
  69.       /* Check if "bright" foreground */
  70.  
  71.       if (strcmpi (argv[i], "bright") == 0)
  72.     {
  73.       iBold = BOLD;
  74.       i++;
  75.     }
  76.  
  77.       /* Check the foreground */
  78.  
  79.       if (i >= argc)
  80.     usage ();
  81.  
  82.       if ((iFore = color (argv[i++])) < 0)
  83.     usage ();
  84.  
  85.       /* Skip an argument for the "on" */
  86.  
  87.       if (i >= argc)
  88.     usage ();
  89.  
  90.       if (strcmpi (argv[i++], "on") != 0)
  91.     usage ();
  92.  
  93.       /* Check the background */
  94.  
  95.       if (i >= argc)
  96.     usage ();
  97.  
  98.       if ((iBack = color (argv[i])) < 0)
  99.     usage ();
  100.  
  101.       /* Print the color string */
  102.  
  103.       printf ("\033[%d;%d;%dm", iBold, iFore + 30, iBack + 40);
  104.     }
  105.  
  106.   /* Clear the screen */
  107.  
  108.   if (!iSet)
  109.     printf ("\033[2J");
  110.  
  111.   exit (0);
  112. }
  113.  
  114. void 
  115. usage (void)
  116. {
  117.   printp ("CLS", "Clears the screen and optionally sets the color.");
  118.   printu ("CLS", "[/S] [[BRIGHT] foreground ON background]");
  119.   printo ("/S", "Only set the screen colors.. do not clear the screen.");
  120.   exit (1);
  121. }
  122.