ReactOS 0.4.15-dev-7924-g5949c20
color.c File Reference
#include "precomp.h"
Include dependency graph for color.c:

Go to the source code of this file.

Functions

INT CommandColor (LPTSTR rest)
 

Function Documentation

◆ CommandColor()

INT CommandColor ( LPTSTR  rest)

Definition at line 32 of file color.c.

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}
#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
#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
#define _T(x)
Definition: vfdio.h:22
#define _ttoi
Definition: xmlstorage.h:195
#define _tcsstr
Definition: xmlstorage.h:199
#define _tcslen
Definition: xmlstorage.h:198