ReactOS 0.4.15-dev-8052-gc0e3179
color.c
Go to the documentation of this file.
1/*
2 * COLOR.C - color internal command.
3 *
4 *
5 * History:
6 *
7 * 13-Dec-1998 (Eric Kohl)
8 * Started.
9 *
10 * 19-Jan-1999 (Eric Kohl)
11 * Unicode ready!
12 *
13 * 20-Jan-1999 (Eric Kohl)
14 * Redirection ready!
15 *
16 * 14-Oct-1999 (Paolo Pantaleo <paolopan@freemail.it>)
17 * 4nt's syntax implemented.
18 *
19 * 03-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
20 * Move all hardcoded strings in En.rc.
21 */
22
23#include "precomp.h"
24
25#ifdef INCLUDE_CMD_COLOR
26
27/*
28 * color
29 *
30 * internal dir command
31 */
33{
34 WORD wColor = 0x00;
35
36 /* The user asked for help */
37 if (_tcsncmp(rest, _T("/?"), 2) == 0)
38 {
40 return 0;
41 }
42
43 /* Let's prepare %ERRORLEVEL% */
44 nErrorLevel = 0;
45
46 /* No parameter: Set the default colors */
47 if (rest[0] == _T('\0'))
48 {
50 return 0;
51 }
52
53 /* The parameter is just one character: Set color text */
54 if (_tcslen(rest) == 1)
55 {
56 if ((rest[0] >= _T('0')) && (rest[0] <= _T('9')))
57 {
58 wColor = (WORD)_ttoi(rest);
59 }
60 else if ((rest[0] >= _T('a')) && (rest[0] <= _T('f')))
61 {
62 wColor = (WORD)(rest[0] + 10 - _T('a'));
63 }
64 else if ((rest[0] >= _T('A')) && (rest[0] <= _T('F')))
65 {
66 wColor = (WORD)(rest[0] + 10 - _T('A'));
67 }
68 else /* Invalid character */
69 {
71 nErrorLevel = 1;
72 return 1;
73 }
74 }
75 /* Color string: advanced choice: two-digits, "Color ON Color", "Foreground ON Background" */
76 else if (StringToColor(&wColor, &rest) == FALSE)
77 {
78 /* Invalid color string */
80 nErrorLevel = 1;
81 return 1;
82 }
83
84 TRACE("Color %02x\n", wColor);
85
86 /*
87 * Set the chosen color. Use also the following advanced flag:
88 * /-F to avoid changing already buffered foreground/background.
89 */
91 !_tcsstr(rest, _T("/-F")) && !_tcsstr(rest, _T("/-f"))) == FALSE)
92 {
93 /* Failed because foreground and background colors were the same */
95 nErrorLevel = 1;
96 return 1;
97 }
98
99 /* Return success */
100 return 0;
101}
102
103#endif /* INCLUDE_CMD_COLOR */
104
105/* EOF */
#define StdOut
Definition: fc.c:14
INT nErrorLevel
Definition: cmd.c:158
WORD wDefColor
Definition: cmd.c:180
BOOL StringToColor(LPWORD, LPTSTR *)
Definition: strtoclr.c:255
WORD wColor
BOOL ConSetScreenColor(HANDLE hOutput, WORD wColor, BOOL bFill)
Definition: console.c:302
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define ConErrResPuts(uID)
Definition: console.h:38
#define STRING_COLOR_HELP1
Definition: resource.h:92
#define STRING_COLOR_ERROR1
Definition: resource.h:32
INT CommandColor(LPTSTR rest)
Definition: color.c:32
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned short WORD
Definition: ntddk_ex.h:93
#define _tcsncmp
Definition: tchar.h:1428
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240
#define TRACE(s)
Definition: solgame.cpp:4
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
#define _ttoi
Definition: xmlstorage.h:195
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcsstr
Definition: xmlstorage.h:199
#define _tcslen
Definition: xmlstorage.h:198