ReactOS  0.4.14-dev-315-gbb6fece
strtoclr.c File Reference
#include "precomp.h"
Include dependency graph for strtoclr.c:

Go to the source code of this file.

Classes

struct  _CLRTABLE
 

Macros

#define _B   FOREGROUND_BLUE
 
#define _G   FOREGROUND_GREEN
 
#define _R   FOREGROUND_RED
 
#define _I   FOREGROUND_INTENSITY
 
#define CP_OK   0
 
#define CP_BLANK_NOT_FOUND   1
 
#define CP_END_OF_STRING   2
 
#define SC_HEX   0x0100
 
#define SC_TXT   0x0200
 

Typedefs

typedef struct _CLRTABLE CLRTABLE
 

Functions

static INT chop_blank (LPTSTR *arg_str)
 
static WORD hex_clr (LPTSTR str)
 
static WORD txt_clr (LPTSTR str)
 
static WORD str_to_color (LPTSTR *arg_str)
 
BOOL StringToColor (LPWORD lpColor, LPTSTR *str)
 

Variables

CLRTABLE clrtable []
 

Macro Definition Documentation

◆ _B

Definition at line 21 of file strtoclr.c.

◆ _G

Definition at line 22 of file strtoclr.c.

◆ _I

Definition at line 24 of file strtoclr.c.

◆ _R

Definition at line 23 of file strtoclr.c.

◆ CP_BLANK_NOT_FOUND

#define CP_BLANK_NOT_FOUND   1

Definition at line 29 of file strtoclr.c.

◆ CP_END_OF_STRING

#define CP_END_OF_STRING   2

Definition at line 30 of file strtoclr.c.

◆ CP_OK

#define CP_OK   0

Definition at line 28 of file strtoclr.c.

◆ SC_HEX

#define SC_HEX   0x0100

Definition at line 33 of file strtoclr.c.

◆ SC_TXT

#define SC_TXT   0x0200

Definition at line 34 of file strtoclr.c.

Typedef Documentation

◆ CLRTABLE

Function Documentation

◆ chop_blank()

static INT chop_blank ( LPTSTR arg_str)
static

Definition at line 93 of file strtoclr.c.

94 {
95  LPTSTR str;
96  str = _tcschr(*arg_str,_T(' '));
97  if (!str)
98  {
99  str = _tcschr (*arg_str, _T('\0'));
100  if (str != NULL)
101  *arg_str=str;
102  return CP_BLANK_NOT_FOUND;
103  }
104 
105  while(_istspace(*str))
106  str++;
107 
108  if (*str == _T('\0'))
109  {
110  *arg_str=str;
111  return CP_END_OF_STRING;
112  }
113 
114  *arg_str = str;
115 
116  return CP_OK;
117 }
CHAR * LPTSTR
Definition: xmlstorage.h:192
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
#define CP_END_OF_STRING
Definition: strtoclr.c:30
#define _T(x)
Definition: vfdio.h:22
#define CP_OK
Definition: strtoclr.c:28
#define CP_BLANK_NOT_FOUND
Definition: strtoclr.c:29
#define _istspace
Definition: tchar.h:1504

Referenced by str_to_color(), and StringToColor().

◆ hex_clr()

static WORD hex_clr ( LPTSTR  str)
static

Definition at line 125 of file strtoclr.c.

126 {
127  WORD ret= (WORD)-1;
128  TCHAR ch;
129 
130  ch = str[1];
131 
132  if (_istdigit(ch))
133  ret = ch-_T('0');
134  else
135  {
136  ch=_totupper(ch);
137 
138  if ( ch >= _T('A') && ch <= _T('F') )
139  ret = ch-_T('A')+10;
140  else
141  return (WORD)-1;
142  }
143 
144  ch = str[0];
145 
146  if (_istdigit(ch))
147  ret |= (ch-_T('0')) << 4;
148  else
149  {
150  ch=_totupper(ch);
151 
152  if ( ch >= _T('A') && ch <= _T('F') )
153  ret |= (ch-_T('A')+10) <<4;
154  else
155  return (WORD)-1;
156  }
157 
158  return ret;
159 }
#define _istdigit
Definition: tchar.h:1494
#define _totupper
Definition: tchar.h:1509
const WCHAR * str
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
unsigned short WORD
Definition: ntddk_ex.h:93
int ret

Referenced by StringToColor().

◆ str_to_color()

static WORD str_to_color ( LPTSTR arg_str)
static

Definition at line 181 of file strtoclr.c.

182 {
183  LPTSTR str;
184  BOOL bBri;
185 
186  WORD tmp_clr,ret_clr;
187 
188  str = *arg_str;
189 
190  if (!(*str))
191  return (WORD)-1;
192 
193  /* foreground */
194  bBri = FALSE;
195 
196  if (_tcsnicmp(str,_T("bri"),3) == 0)
197  {
198  bBri = TRUE;
199 
200  if (chop_blank(&str))
201  return (WORD)-1;
202  }
203 
204  if ((tmp_clr = txt_clr(str)) == (WORD)-1)
205  {
206  return (WORD)-1;
207  }
208 
209  /* skip spaces and "on" keyword */
210  if (chop_blank(&str) || chop_blank(&str))
211  return (WORD)-1;
212 
213  ret_clr = tmp_clr | (bBri << 3);
214 
215  /* background */
216  bBri = FALSE;
217 
218  if (_tcsnicmp(str,_T("bri"),3) == 0 )
219  {
220  bBri = TRUE;
221 
222  if (chop_blank(&str))
223  return (WORD)-1;
224  }
225 
226  if ( (tmp_clr = txt_clr(str)) == (WORD)-1 )
227  return (WORD)-1;
228 
229  chop_blank(&str);
230 
231  *arg_str = str;
232 
233  /* NOTE: See the note on SC_HEX in the StringToColor()'s description */
234  return /* SC_HEX | */ ret_clr | tmp_clr << 4 | bBri << 7;
235 }
#define TRUE
Definition: types.h:120
static INT chop_blank(LPTSTR *arg_str)
Definition: strtoclr.c:93
CHAR * LPTSTR
Definition: xmlstorage.h:192
static WORD txt_clr(LPTSTR str)
Definition: strtoclr.c:167
unsigned int BOOL
Definition: ntddk_ex.h:94
#define _tcsnicmp
Definition: xmlstorage.h:207
const WCHAR * str
#define _T(x)
Definition: vfdio.h:22
unsigned short WORD
Definition: ntddk_ex.h:93

Referenced by StringToColor().

◆ StringToColor()

BOOL StringToColor ( LPWORD  lpColor,
LPTSTR str 
)

Definition at line 255 of file strtoclr.c.

256 {
257  WORD wRet;
258 
259  wRet = str_to_color (str);
260  if (wRet == (WORD)-1)
261  {
262  wRet=hex_clr (*str);
263  chop_blank (str);
264  if (wRet == (WORD)-1)
265  return FALSE;
266  }
267 
268  *lpColor = wRet;
269 
270  return TRUE;
271 }
#define TRUE
Definition: types.h:120
static INT chop_blank(LPTSTR *arg_str)
Definition: strtoclr.c:93
static WORD str_to_color(LPTSTR *arg_str)
Definition: strtoclr.c:181
const WCHAR * str
unsigned short WORD
Definition: ntddk_ex.h:93
static WORD hex_clr(LPTSTR str)
Definition: strtoclr.c:125

Referenced by CommandColor().

◆ txt_clr()

static WORD txt_clr ( LPTSTR  str)
static

Definition at line 167 of file strtoclr.c.

168 {
169  INT i;
170 
171  for(i = 0; *(clrtable[i].name); i++)
172  if (_tcsnicmp(str, clrtable[i].name, _tcslen(clrtable[i].name)) == 0)
173  return clrtable[i].val;
174 
175  return (WORD)-1;
176 }
CLRTABLE clrtable[]
Definition: strtoclr.c:44
int32_t INT
Definition: typedefs.h:56
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _tcsnicmp
Definition: xmlstorage.h:207
const WCHAR * str
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
GLuint GLfloat * val
Definition: glext.h:7180
unsigned short WORD
Definition: ntddk_ex.h:93
Definition: name.c:36
LPTSTR name
Definition: strtoclr.c:39

Referenced by str_to_color().

Variable Documentation

◆ clrtable

CLRTABLE clrtable[]

Definition at line 44 of file strtoclr.c.

Referenced by txt_clr().