mirror of
https://github.com/reactos/reactos.git
synced 2025-02-20 15:35:04 +00:00
Implemented 4nt compatible color command.
svn path=/trunk/; revision=752
This commit is contained in:
parent
cfb22d72df
commit
18a01fd10d
6 changed files with 367 additions and 45 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $Id: cmd.c,v 1.13 1999/10/23 18:17:37 ekohl Exp $
|
||||
/* $Id: cmd.c,v 1.14 1999/11/04 11:29:36 ekohl Exp $
|
||||
*
|
||||
* CMD.C - command-line interface.
|
||||
*
|
||||
|
@ -122,7 +122,7 @@
|
|||
#include "batch.h"
|
||||
|
||||
|
||||
#define CMDLINE_LENGTH 512
|
||||
#define CMDLINE_LENGTH 1024
|
||||
|
||||
|
||||
BOOL bExit = FALSE; /* indicates EXIT was typed */
|
||||
|
@ -987,7 +987,7 @@ Initialize (int argc, char *argv[])
|
|||
/* process /t (color) argument */
|
||||
wDefColor = (WORD)strtoul (&argv[i][3], NULL, 16);
|
||||
wColor = wDefColor;
|
||||
SetScreenColor (wColor);
|
||||
SetScreenColor (wColor, TRUE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -131,8 +131,9 @@ typedef struct tagCOMMAND
|
|||
|
||||
|
||||
/* Prototypes for COLOR.C */
|
||||
VOID SetScreenColor (WORD);
|
||||
INT cmd_color (LPTSTR, LPTSTR);
|
||||
VOID SetScreenColor(WORD wArgColor, BOOL bFill);
|
||||
//VOID SetScreenColor (WORD);
|
||||
INT CommandColor (LPTSTR, LPTSTR);
|
||||
|
||||
|
||||
/* Prototypes for CONSOLE.C */
|
||||
|
@ -337,6 +338,10 @@ INT cmd_set (LPTSTR, LPTSTR);
|
|||
INT cmd_start (LPTSTR, LPTSTR);
|
||||
|
||||
|
||||
/* Prototypes for STRTOCLR.C */
|
||||
BOOL StringToColor (LPWORD, LPTSTR *);
|
||||
|
||||
|
||||
/* Prototypes for TIME.C */
|
||||
INT cmd_time (LPTSTR, LPTSTR);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ COMMAND cmds[] =
|
|||
{_T("?"), 0, CommandShowCommands},
|
||||
|
||||
#ifdef INCLUDE_CMD_ACTIVATE
|
||||
{_T("activate"), 0, CommandActivate},
|
||||
{_T("activate"), 0, CommandActivate},
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_ALIASES
|
||||
|
@ -41,7 +41,7 @@ COMMAND cmds[] =
|
|||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_ATTRIB
|
||||
{_T("attrib"), 0, CommandAttrib},
|
||||
{_T("attrib"), 0, CommandAttrib},
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_BEEP
|
||||
|
@ -63,13 +63,12 @@ COMMAND cmds[] =
|
|||
{_T("choice"), 0, CommandChoice},
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef INCLUDE_CMD_CLS
|
||||
{_T("cls"), 0, cmd_cls},
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_COLOR
|
||||
{_T("color"), 0, cmd_color},
|
||||
{_T("color"), 0, CommandColor},
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_COPY
|
||||
|
@ -81,8 +80,8 @@ COMMAND cmds[] =
|
|||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_DEL
|
||||
{_T("del"), 0, CommandDelete},
|
||||
{_T("delete"), 0, CommandDelete},
|
||||
{_T("del"), 0, CommandDelete},
|
||||
{_T("delete"), 0, CommandDelete},
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_CMD_DELAY
|
||||
|
@ -94,7 +93,7 @@ COMMAND cmds[] =
|
|||
#endif
|
||||
|
||||
#ifdef FEATURE_DIRECTORY_STACK
|
||||
{_T("dirs"), 0, CommandDirs},
|
||||
{_T("dirs"), 0, CommandDirs},
|
||||
#endif
|
||||
|
||||
{_T("echo"), 0, CommandEcho},
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
/* $Id: color.c,v 1.3 1999/11/04 11:29:36 ekohl Exp $
|
||||
*
|
||||
* COLOR.C - color internal command.
|
||||
*
|
||||
*
|
||||
|
@ -12,6 +13,9 @@
|
|||
*
|
||||
* 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
||||
* Redirection ready!
|
||||
*
|
||||
* 14-Oct-1999 (Paolo Pantaleo <paolopan@freemail.it>)
|
||||
* 4nt's syntax implemented
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
@ -24,21 +28,59 @@
|
|||
|
||||
#include "cmd.h"
|
||||
|
||||
static VOID ColorHelp (VOID)
|
||||
{
|
||||
ConOutPuts (_T(
|
||||
"Sets the default foreground and background colors.\n"
|
||||
"\n"
|
||||
"COLOR [attr [/F]] \n\n"
|
||||
" attr Specifies color attribute of console output\n"
|
||||
" /F fill the console with color attribute\n"
|
||||
"\n"
|
||||
"There are three ways to specify the colors:"
|
||||
));
|
||||
|
||||
VOID SetScreenColor (WORD wColor)
|
||||
ConOutPuts (_T(
|
||||
"\n"
|
||||
"1) [bright] name on [bright] name (only the first three letters are required)\n"
|
||||
"2) decimal on decimal\n"
|
||||
"3) two hex digits\n"
|
||||
"\n"
|
||||
"Colors are:"
|
||||
));
|
||||
|
||||
ConOutPuts (_T(
|
||||
"dec hex name dec hex name\n"
|
||||
"0 0 Black 8 8 Gray(Bright black)\n"
|
||||
"1 1 Blue 9 9 Bright Blue\n"
|
||||
"2 2 Green 10 A Bright Green\n"
|
||||
"3 3 Cyan 11 B Bright Cyan\n"
|
||||
"4 4 Red 12 C Bright Red\n"
|
||||
"5 5 Magenta 13 D Bright Magenta\n"
|
||||
"6 6 Yellow 14 E Bright Yellow\n"
|
||||
"7 7 White 15 F Bright White"));
|
||||
}
|
||||
|
||||
|
||||
VOID SetScreenColor (WORD wColor, BOOL bFill)
|
||||
{
|
||||
DWORD dwWritten;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
COORD coPos;
|
||||
|
||||
GetConsoleScreenBufferInfo (hOut, &csbi);
|
||||
if (bFill == TRUE)
|
||||
{
|
||||
GetConsoleScreenBufferInfo (hOut, &csbi);
|
||||
|
||||
coPos.X = 0;
|
||||
coPos.Y = 0;
|
||||
FillConsoleOutputAttribute (hOut, wColor,
|
||||
(csbi.dwSize.X)*(csbi.dwSize.Y),
|
||||
coPos, &dwWritten);
|
||||
SetConsoleTextAttribute (hOut, wColor);
|
||||
coPos.X = 0;
|
||||
coPos.Y = 0;
|
||||
FillConsoleOutputAttribute (hOut,
|
||||
wColor & 0x00FF,
|
||||
(csbi.dwSize.X)*(csbi.dwSize.Y),
|
||||
coPos,
|
||||
&dwWritten);
|
||||
}
|
||||
SetConsoleTextAttribute (hOut, wColor & 0x00FF);
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,25 +89,11 @@ VOID SetScreenColor (WORD wColor)
|
|||
*
|
||||
* internal dir command
|
||||
*/
|
||||
INT cmd_color (LPTSTR first, LPTSTR rest)
|
||||
INT CommandColor (LPTSTR first, LPTSTR rest)
|
||||
{
|
||||
if (_tcsncmp (rest, _T("/?"), 2) == 0)
|
||||
{
|
||||
ConOutPuts (_T("Sets the default foreground and background colors.\n\n"
|
||||
"COLOR [attr]\n\n"
|
||||
" attr Specifies color attribute of console output\n\n"
|
||||
"Color attributes are specified by TWO hex digits -- the first\n"
|
||||
"corresponds to the background; the second to the foreground. Each digit\n"
|
||||
"can be one of the following:\n"));
|
||||
|
||||
ConOutPuts (_T(" 0 = Black 8 = Gray\n"
|
||||
" 1 = Blue 9 = Light Blue\n"
|
||||
" 2 = Green A = Light Green\n"
|
||||
" 3 = Aqua B = Light Aqua\n"
|
||||
" 4 = Red C = Light Red\n"
|
||||
" 5 = Purple D = Light Purple\n"
|
||||
" 6 = Yellow E = Light Yellow\n"
|
||||
" 7 = White F = Bright White\n"));
|
||||
ColorHelp ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -73,17 +101,17 @@ INT cmd_color (LPTSTR first, LPTSTR rest)
|
|||
{
|
||||
/* set default color */
|
||||
wColor = wDefColor;
|
||||
SetScreenColor (wColor);
|
||||
SetScreenColor (wColor, TRUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_tcslen (rest) != 2)
|
||||
if (StringToColor (&wColor, &rest) == FALSE)
|
||||
{
|
||||
ConErrPuts (_T("parameter error!"));
|
||||
ConErrPuts("error in color specification");
|
||||
return 1;
|
||||
}
|
||||
|
||||
wColor = (WORD)_tcstoul (rest, NULL, 16);
|
||||
ConErrPrintf ("Color %x\n", wColor);
|
||||
|
||||
if ((wColor & 0xF) == (wColor &0xF0) >> 4)
|
||||
{
|
||||
|
@ -92,9 +120,12 @@ INT cmd_color (LPTSTR first, LPTSTR rest)
|
|||
}
|
||||
|
||||
/* set color */
|
||||
SetScreenColor (wColor);
|
||||
SetScreenColor (wColor,
|
||||
(_tcsstr (rest,"/F") || _tcsstr (rest,"/f")));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* INCLUDE_CMD_COLOR */
|
||||
|
||||
/* EOF */
|
|
@ -11,8 +11,8 @@ OBJECTS = cmd.o attrib.o alias.o batch.o beep.o call.o chcp.o choice.o \
|
|||
delay.o dir.o dirstack.o echo.o error.o filecomp.o for.o free.o \
|
||||
goto.o history.o if.o internal.o label.o locale.o memory.o misc.o \
|
||||
move.o msgbox.o path.o pause.o prompt.o redir.o ren.o screen.o \
|
||||
set.o shift.o start.o time.o timer.o title.o type.o ver.o \
|
||||
verify.o vol.o where.o window.o cmd.coff
|
||||
set.o shift.o start.o strtoclr.o time.o timer.o title.o type.o \
|
||||
ver.o verify.o vol.o where.o window.o cmd.coff
|
||||
|
||||
CLEAN_FILES = *.o cmd.exe cmd.sym cmd.coff
|
||||
|
||||
|
|
287
rosapps/cmd/strtoclr.c
Normal file
287
rosapps/cmd/strtoclr.c
Normal file
|
@ -0,0 +1,287 @@
|
|||
/*
|
||||
* STRTOCLR.C - read color (for color command and other)
|
||||
*
|
||||
*
|
||||
* History:
|
||||
*
|
||||
* 07-Oct-1999 (Paolo Pantaleo)
|
||||
* Started.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/*only
|
||||
BOOL StringToColor(LPWORD lpColor, LPTSTR*str)
|
||||
is to be called
|
||||
other are internal service functions*/
|
||||
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
#define _B FOREGROUND_BLUE
|
||||
#define _G FOREGROUND_GREEN
|
||||
#define _R FOREGROUND_RED
|
||||
#define _I FOREGROUND_INTENSITY
|
||||
|
||||
|
||||
/*return values for chop_blank*/
|
||||
#define CP_OK 0
|
||||
#define CP_BLANK_NOT_FOUND 1
|
||||
#define CP_END_OF_STRING 2
|
||||
|
||||
#define SC_HEX 0x0100
|
||||
#define SC_TXT 0x0200
|
||||
|
||||
|
||||
|
||||
typedef struct _CLRTABLE
|
||||
{
|
||||
LPTSTR name;
|
||||
WORD val;
|
||||
} CLRTABLE;
|
||||
|
||||
|
||||
CLRTABLE clrtable[] =
|
||||
{
|
||||
{"bla" ,0 },
|
||||
{"blu" ,_B },
|
||||
{"gre" ,_G },
|
||||
{"cya" ,_B|_G },
|
||||
{"red" ,_R },
|
||||
{"mag" ,_B|_R },
|
||||
{"yel" ,_R|_G },
|
||||
{"whi" ,_R|_G|_B },
|
||||
{"gra" ,_I },
|
||||
|
||||
|
||||
{"0" ,0 },
|
||||
{"2" ,_G },
|
||||
{"3" ,_B|_G },
|
||||
{"4" ,_R },
|
||||
{"5" ,_B|_R },
|
||||
{"6" ,_R|_G },
|
||||
{"7" ,_R|_G|_B },
|
||||
|
||||
{"8" ,_I },
|
||||
{"9" ,_I|_B },
|
||||
{"10" ,_I|_G },
|
||||
{"11" ,_I|_B|_G },
|
||||
{"12" ,_I|_R },
|
||||
{"13" ,_I|_B|_R },
|
||||
{"14" ,_I|_R|_G },
|
||||
{"15" ,_I|_R|_G|_B},
|
||||
|
||||
|
||||
/* note that 1 is at the end of list
|
||||
to avoid to confuse it with 10-15*/
|
||||
{"1" ,_B },
|
||||
|
||||
/*cyan synonimous*/
|
||||
{"aqu" ,_B|_G },
|
||||
/*magenta synonimous*/
|
||||
{"pur" ,_B|_R },
|
||||
|
||||
|
||||
{"" ,0},
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
move string pointer to next word (skip all spaces)
|
||||
on erro retunr nonzero value
|
||||
*/
|
||||
static
|
||||
INT chop_blank(LPTSTR *arg_str)
|
||||
{
|
||||
|
||||
LPTSTR str;
|
||||
str = _tcschr(*arg_str,_T(' '));
|
||||
if(!str)
|
||||
{
|
||||
str = _tcschr (*arg_str, _T('\0'));
|
||||
if(str != NULL)
|
||||
*arg_str=str;
|
||||
return CP_BLANK_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
|
||||
while(_istspace(*str))
|
||||
str++;
|
||||
|
||||
if (*str == _T('\0'))
|
||||
{
|
||||
*arg_str=str;
|
||||
return CP_END_OF_STRING;
|
||||
}
|
||||
|
||||
*arg_str = str;
|
||||
|
||||
return CP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
read a color value in hex (like win nt's cmd syntax)
|
||||
if an error occurs return -1
|
||||
*/
|
||||
static
|
||||
WORD hex_clr(LPTSTR str)
|
||||
{
|
||||
WORD ret= (WORD)-1;
|
||||
TCHAR ch;
|
||||
|
||||
ch = str[1];
|
||||
|
||||
if(_istdigit(ch))
|
||||
ret = ch-_T('0');
|
||||
else
|
||||
{
|
||||
ch=_totupper(ch);
|
||||
|
||||
if( ch >= _T('A') && ch <= _T('F') )
|
||||
ret = ch-_T('A')+10;
|
||||
else
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
|
||||
ch = str[0];
|
||||
|
||||
if(_istdigit(ch))
|
||||
ret |= (ch-_T('0')) << 4;
|
||||
else
|
||||
{
|
||||
ch=_totupper(ch);
|
||||
|
||||
if( ch >= _T('A') && ch <= _T('F') )
|
||||
ret |= (ch-_T('A')+10) <<4;
|
||||
else
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
read a color value from a string (like 4nt's syntax)
|
||||
if an error occurs return -1
|
||||
*/
|
||||
static
|
||||
WORD txt_clr(LPTSTR str)
|
||||
{
|
||||
INT i;
|
||||
|
||||
for(i=0;*(clrtable[i].name);i++)
|
||||
if( _tcsnicmp(str,clrtable[i].name,_tcslen(clrtable[i].name)) == 0)
|
||||
return clrtable[i].val;
|
||||
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*search for x on y*/
|
||||
static
|
||||
WORD str_to_color(LPTSTR* arg_str)
|
||||
{
|
||||
LPTSTR str;
|
||||
BOOL bBri=FALSE;
|
||||
|
||||
WORD tmp_clr,ret_clr;
|
||||
|
||||
str = *arg_str;
|
||||
|
||||
|
||||
|
||||
if(!(*str))
|
||||
return (WORD)-1;
|
||||
|
||||
|
||||
/*foreground*/
|
||||
if(_tcsnicmp(str,"bri",3) == 0 )
|
||||
{
|
||||
bBri = TRUE;
|
||||
|
||||
if(chop_blank(&str))
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
if( (tmp_clr = txt_clr(str)) == (WORD)-1 )
|
||||
{
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
/*skip spaces and "on"*/
|
||||
if ( chop_blank(&str) || chop_blank(&str) )
|
||||
return (WORD)-1;
|
||||
|
||||
ret_clr = tmp_clr | (bBri << 3);
|
||||
|
||||
/*background*/
|
||||
|
||||
if(_tcsnicmp(str,"bri",3) == 0 )
|
||||
{
|
||||
bBri = TRUE;
|
||||
|
||||
if(chop_blank(&str))
|
||||
return (WORD)-1;
|
||||
}
|
||||
|
||||
|
||||
if( (tmp_clr = txt_clr(str)) == (WORD)-1 )
|
||||
return (WORD)-1;
|
||||
|
||||
chop_blank(&str);
|
||||
|
||||
*arg_str = str;
|
||||
|
||||
return SC_HEX | ret_clr | tmp_clr << 4 | bBri << 7;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****main function****/
|
||||
/*
|
||||
the only parameter is arg_str, a pointer to a string.
|
||||
the string is modified so it will begin to first word after
|
||||
color specification
|
||||
(only the char* is moved, no chars in the string are modfied)
|
||||
|
||||
|
||||
it returns the color in the l.o. byte, plus two flags in the
|
||||
h.o. byte, they are:
|
||||
SC_HEX win nt's cmd syntax (for exampl a0)
|
||||
SC_TXT 4nt's syntax ( "bri gre on bla" or "10 on 0")
|
||||
|
||||
if succedes also move the LPTSTR to end of
|
||||
string that specify color
|
||||
*/
|
||||
|
||||
|
||||
BOOL StringToColor(LPWORD lpColor, LPTSTR*str)
|
||||
{
|
||||
WORD wRet;
|
||||
|
||||
wRet = str_to_color (str);
|
||||
if (wRet == (WORD)-1)
|
||||
{
|
||||
wRet=hex_clr (*str);
|
||||
chop_blank (str);
|
||||
if (wRet == (WORD)-1)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*lpColor = wRet;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* EOF */
|
Loading…
Reference in a new issue