home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Zodiac Super OZ
/
MEDIADEPOT.ISO
/
FILES
/
16
/
FREEDOS.ZIP
/
FD_A4PRE.ZIP
/
SOURCE
/
MICROC.ZIP
/
CLS.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-15
|
4KB
|
158 lines
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
** This program clears the screen and optionally sets the color.
** Requires ANSI.SYS to be loaded.
**
** author: James Hall
*/
#include <stdio.h>
#include "freedos.h"
#include "getopt.c"
int ansi_mode, attr_only, attr_flag, cls_fgcolor, cls_bgcolor, cls_attr;
char *ATTRS[] =
{"normal", "bright", NULL, NULL, "underlined", "blinking", NULL, "reversed", "invisible"};
char *COLORS[] =
{"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"};
void usage (void);
void cls (void);
main (int argc, char **argv)
{
int i, j;
ansi_mode = TRUE;
attr_only = FALSE;
attr_flag = FALSE;
cls_attr = 0;
cls_fgcolor = 7;
cls_bgcolor = 0;
/* Scan the command line */
while ((i = getopt (argc, argv, "ABRS", NULL)) != EOF)
{
switch (i)
{
case 'A':
ansi_mode = TRUE;
break;
case 'B':
ansi_mode = FALSE;
break;
/* We are only setting attributes */
case 'S':
attr_only = TRUE;
break;
case 'R':
attr_flag = TRUE;
break;
/* Usage */
default:
usage ();
break;
}
}
if ((argv[optind] == NULL) || (attr_flag == TRUE))
cls ();
i = optind;
/* See if the first arg is an attribute */
for (j = 0; j < 10; j++)
if ((strstr (ATTRS[j], argv[i]) == ATTRS[j]) && (ATTRS[j] != NULL))
{
cls_attr = j;
attr_flag = TRUE;
i++;
break;
};
/* See if current arg is a color */
for (j = 0; j < 9; j++)
{
if (strstr (COLORS[j], argv[i]) == COLORS[j])
{
cls_fgcolor = j;
attr_flag = TRUE;
break;
}
if (j == 8)
usage ();
}
/* See if the next arg is a color and not NULL, skip "on" if found */
i++; if (argv[i] != NULL)
for (j = 0; j < 9; j++)
{
if (!strcmp ("on", argv[i]))
i++;
if (strstr (COLORS[j], argv[i]) == COLORS[j])
{
cls_bgcolor = j;
attr_flag = TRUE;
break;
}
if (j == 8)
usage ();
}
cls ();
}
void cls ()
{
if (ansi_mode)
{
if (attr_flag)
printf ("\033[%d;%d;%dm", cls_attr,
cls_fgcolor+30, cls_bgcolor+40);
if (!attr_only)
printf ("\033[2J");
}
else
printf ("BIOS clear screen.\n");
exit (0);
}
/**** Print usage statement */
void usage(void)
{
printp ("CLS","Clears the video monitor and sets colors.");
printc ("1995", "M. Toal, P. Mikalajunas, and J. Hall");
printu ("CLS", "[attribute] [color] [on] [color]");
printo ("A", "Forse ANSI mode");
printo ("B", "Force BIOS mode");
printo ("R", "Restore screen to normal white on black");
printo ("S", "Set attributes and colors only, do not clear screen.");
fprintf (stderr, " Attributes: Normal Bright Underlined Blinking Reversed Invisible\n");
fprintf (stderr, " Colors: Black Red Green Yellow Blue Magenta Cyan White\n");
exit (1);
}