ReactOS  0.4.13-dev-464-g6b95727
alias.c File Reference
#include "precomp.h"
Include dependency graph for alias.c:

Go to the source code of this file.

Functions

static VOID partstrlwr (LPTSTR str)
 
static VOID PrintAlias (VOID)
 
VOID ExpandAlias (LPTSTR cmd, INT maxlen)
 
INT CommandAlias (LPTSTR param)
 

Function Documentation

◆ CommandAlias()

INT CommandAlias ( LPTSTR  param)

Definition at line 174 of file alias.c.

175 {
176  LPTSTR ptr;
177 
178  if (!_tcsncmp (param, _T("/?"), 2))
179  {
181  return 0;
182  }
183 
184  nErrorLevel = 0;
185 
186  if (param[0] == _T('\0'))
187  {
188  PrintAlias ();
189  return 0;
190  }
191 
192  nErrorLevel = 0;
193 
194  /* error if no '=' found */
195  if ((ptr = _tcschr (param, _T('='))) == 0)
196  {
197  nErrorLevel = 1;
198  return 1;
199  }
200 
201  /* Split rest into name and substitute */
202  *ptr++ = _T('\0');
203 
204  partstrlwr (param);
205 
206  if (ptr[0] == _T('\0'))
207  AddConsoleAlias(param, NULL, _T("cmd.exe"));
208  else
209  AddConsoleAlias(param, ptr, _T("cmd.exe"));
210 
211  return 0;
212 }
INT nErrorLevel
Definition: cmd.c:157
static VOID PrintAlias(VOID)
Definition: alias.c:54
#define TRUE
Definition: types.h:120
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
CHAR * LPTSTR
Definition: xmlstorage.h:192
static PVOID ptr
Definition: dispmode.c:27
static VOID partstrlwr(LPTSTR str)
Definition: alias.c:43
smooth NULL
Definition: ftsmooth.c:416
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
#define _T(x)
Definition: vfdio.h:22
#define AddConsoleAlias
Definition: wincon.h:757
GLfloat param
Definition: glext.h:5796
#define STRING_ALIAS_HELP
Definition: resource.h:70
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ ExpandAlias()

VOID ExpandAlias ( LPTSTR  cmd,
INT  maxlen 
)

Definition at line 89 of file alias.c.

90 {
91  LPTSTR buffer;
92  TCHAR *position, *in, *out;
93  LPTSTR Token;
94  LPTSTR tmp;
95 
96  tmp = cmd_dup(cmd);
97  if (!tmp)
98  return;
99 
100  /* first part is the macro name */
101  position = tmp + _tcscspn(tmp, _T(" \n"));
102  if (position == tmp)
103  {
104  cmd_free(tmp);
105  return;
106  }
107  *position++ = _T('\0');
108  position += _tcsspn(position, _T(" "));
109 
110  buffer = cmd_alloc(maxlen);
111  if (!buffer)
112  {
113  WARN("Cannot allocate memory for alias buffer!\n");
114  cmd_free(tmp);
115  return;
116  }
117 
118  if (GetConsoleAlias(tmp, buffer, maxlen, _T("cmd.exe")) == 0)
119  {
120  cmd_free(tmp);
121  cmd_free(buffer);
122  return;
123  }
124 
125  in = buffer;
126  out = cmd;
127  while (*in)
128  {
129  if (*in == _T('$'))
130  {
131  Token = position;
132  if (in[1] >= _T('1') && in[1] <= _T('9'))
133  {
134  /* Copy a single space-delimited token from the input line */
135  INT num;
136  for (num = in[1] - _T('1'); num > 0; num--)
137  {
138  Token += _tcscspn(Token, _T(" \n"));
139  Token += _tcsspn(Token, _T(" "));
140  }
141  while (!_tcschr(_T(" \n"), *Token))
142  {
143  if (out >= &cmd[maxlen - 1])
144  break;
145  *out++ = *Token++;
146  }
147  in += 2;
148  continue;
149  }
150  else if (in[1] == _T('*'))
151  {
152  /* Copy the entire remainder of the line */
153  while (*Token && *Token != _T('\n'))
154  {
155  if (out >= &cmd[maxlen - 1])
156  break;
157  *out++ = *Token++;
158  }
159  in += 2;
160  continue;
161  }
162  }
163  if (out >= &cmd[maxlen - 1])
164  break;
165  *out++ = *in++;
166  }
167  *out++ = _T('\n');
168  *out = _T('\0');
169 
170  cmd_free(buffer);
171  cmd_free(tmp);
172 }
Definition: ftp_var.h:139
#define WARN(fmt,...)
Definition: debug.h:111
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE Token
GLuint buffer
Definition: glext.h:5915
char * cmd
Definition: vfdcmd.c:85
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetConsoleAlias
Definition: wincon.h:758
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static FILE * out
Definition: regtests2xml.c:44
GLuint GLuint num
Definition: glext.h:9618
#define _tcsspn
Definition: tchar.h:1414
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
GLuint in
Definition: glext.h:9616
#define cmd_dup(str)
Definition: cmddbg.h:32
#define _tcscspn
Definition: tchar.h:1407

Referenced by ReadCommand().

◆ partstrlwr()

static VOID partstrlwr ( LPTSTR  str)
static

Definition at line 43 of file alias.c.

44 {
45  LPTSTR c = str;
46  while (*c && !_istspace (*c) && *c != _T('='))
47  {
48  *c = _totlower (*c);
49  c++;
50  }
51 }
CHAR * LPTSTR
Definition: xmlstorage.h:192
const WCHAR * str
#define _T(x)
Definition: vfdio.h:22
const GLubyte * c
Definition: glext.h:8905
#define _totlower
Definition: tchar.h:1511
#define _istspace
Definition: tchar.h:1504

Referenced by CommandAlias().

◆ PrintAlias()

static VOID PrintAlias ( VOID  )
static

Definition at line 54 of file alias.c.

55 {
56  LPTSTR Aliases;
57  LPTSTR ptr;
58  DWORD len;
59 
60  len = GetConsoleAliasesLength(_T("cmd.exe"));
61  if (len == 0)
62  return;
63 
64  /* allocate memory for an extra \0 char to make parsing easier */
65  ptr = cmd_alloc(len + sizeof(TCHAR));
66  if (!ptr)
67  {
68  WARN("Cannot allocate memory for ptr!\n");
69  return;
70  }
71 
72  Aliases = ptr;
73 
74  ZeroMemory(Aliases, len + sizeof(TCHAR));
75 
76  if (GetConsoleAliases(Aliases, len, _T("cmd.exe")) != 0)
77  {
78  while (*Aliases != '\0')
79  {
80  ConOutPrintf(_T("%s\n"), Aliases);
81  Aliases = Aliases + lstrlen(Aliases);
82  Aliases++;
83  }
84  }
85  cmd_free(ptr);
86 }
#define WARN(fmt,...)
Definition: debug.h:111
#define ZeroMemory
Definition: winbase.h:1635
#define ConOutPrintf(szStr,...)
Definition: console.h:42
CHAR * LPTSTR
Definition: xmlstorage.h:192
static PVOID ptr
Definition: dispmode.c:27
#define GetConsoleAliases
Definition: wincon.h:759
#define GetConsoleAliasesLength
Definition: wincon.h:760
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define lstrlen
Definition: winbase.h:3690
#define cmd_free(ptr)
Definition: cmddbg.h:31

Referenced by CommandAlias().