2 * ALIAS.C - alias administration module.
7 * 02/02/1996 (Oliver Mueller)
10 * 02/03/1996 (Oliver Mueller)
11 * Added sorting algorithm and case sensitive substitution by using
14 * 27 Jul 1998 John P. Price
15 * added config.h include
16 * added ifdef's to disable aliases
18 * 09-Dec-1998 Eric Kohl
19 * Fixed crash when removing an alias in DeleteAlias().
20 * Added help text ("/?").
22 * 14-Jan-1998 Eric Kohl
23 * Clean up and Unicode safe!
25 * 24-Jan-1998 Eric Kohl
28 * 02-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
29 * Remove all hardcoded strings in En.rc
31 * 02-Feb-2008 (Christoph von Wittich <christoph_vw@reactos.org>)
32 * rewrote alias handling for doskey compat
38 #ifdef FEATURE_ALIASES
40 /* module internal functions */
41 /* strlwr only for first word in string */
43 partstrlwr (LPTSTR str
)
46 while (*c
&& !_istspace (*c
) && *c
!= _T('='))
60 len
= GetConsoleAliasesLength(_T("cmd.exe"));
64 /* allocate memory for an extra \0 char to make parsing easier */
65 ptr
= cmd_alloc(len
+ sizeof(TCHAR
));
71 ZeroMemory(Aliases
, len
+ sizeof(TCHAR
));
73 if (GetConsoleAliases(Aliases
, len
, _T("cmd.exe")) != 0)
75 while (*Aliases
!= '\0')
77 ConOutPrintf(_T("%s\n"), Aliases
);
78 Aliases
= Aliases
+ lstrlen(Aliases
);
85 /* specified routines */
86 VOID
ExpandAlias (LPTSTR cmd
, INT maxlen
)
89 TCHAR
*position
, *in
, *out
;
97 /* first part is the macro name */
98 position
= tmp
+ _tcscspn(tmp
, _T(" \n"));
104 *position
++ = _T('\0');
105 position
+= _tcsspn(position
, _T(" "));
107 buffer
= cmd_alloc(maxlen
);
114 if (GetConsoleAlias(tmp
, buffer
, maxlen
, _T("cmd.exe")) == 0)
128 if (in
[1] >= _T('1') && in
[1] <= _T('9'))
130 /* Copy a single space-delimited token from the input line */
132 for (num
= in
[1] - _T('1'); num
> 0; num
--)
134 Token
+= _tcscspn(Token
, _T(" \n"));
135 Token
+= _tcsspn(Token
, _T(" "));
137 while (!_tcschr(_T(" \n"), *Token
))
139 if (out
>= &cmd
[maxlen
- 1])
146 else if (in
[1] == _T('*'))
148 /* Copy the entire remainder of the line */
149 while (*Token
&& *Token
!= _T('\n'))
151 if (out
>= &cmd
[maxlen
- 1])
159 if (out
>= &cmd
[maxlen
- 1])
170 INT
CommandAlias (LPTSTR param
)
174 if (!_tcsncmp (param
, _T("/?"), 2))
176 ConOutResPaging(TRUE
,STRING_ALIAS_HELP
);
182 if (param
[0] == _T('\0'))
190 /* error if no '=' found */
191 if ((ptr
= _tcschr (param
, _T('='))) == 0)
197 /* Split rest into name and substitute */
202 if (ptr
[0] == _T('\0'))
203 AddConsoleAlias(param
, NULL
, _T("cmd.exe"));
205 AddConsoleAlias(param
, ptr
, _T("cmd.exe"));