Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenalias.c
Go to the documentation of this file.
00001 /* 00002 * ALIAS.C - alias administration module. 00003 * 00004 * 00005 * History: 00006 * 00007 * 02/02/1996 (Oliver Mueller) 00008 * started. 00009 * 00010 * 02/03/1996 (Oliver Mueller) 00011 * Added sorting algorithm and case sensitive substitution by using 00012 * partstrupr(). 00013 * 00014 * 27 Jul 1998 John P. Price 00015 * added config.h include 00016 * added ifdef's to disable aliases 00017 * 00018 * 09-Dec-1998 Eric Kohl 00019 * Fixed crash when removing an alias in DeleteAlias(). 00020 * Added help text ("/?"). 00021 * 00022 * 14-Jan-1998 Eric Kohl 00023 * Clean up and Unicode safe! 00024 * 00025 * 24-Jan-1998 Eric Kohl 00026 * Redirection safe! 00027 * 00028 * 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>) 00029 * Remove all hardcode string to En.rc 00030 * 00031 * 02-Feb-2008 (Christoph von Wittich) <christoph_vw@reactos.org>) 00032 * rewrote alias handling for doskey compat 00033 */ 00034 00035 00036 #include <precomp.h> 00037 00038 #ifdef FEATURE_ALIASES 00039 00040 /* module internal functions */ 00041 /* strlwr only for first word in string */ 00042 static VOID 00043 partstrlwr (LPTSTR str) 00044 { 00045 LPTSTR c = str; 00046 while (*c && !_istspace (*c) && *c != _T('=')) 00047 { 00048 *c = _totlower (*c); 00049 c++; 00050 } 00051 } 00052 00053 static VOID 00054 PrintAlias (VOID) 00055 { 00056 LPTSTR Aliases; 00057 LPTSTR ptr; 00058 DWORD len; 00059 00060 len = GetConsoleAliasesLength(_T("cmd.exe")); 00061 if (len <= 0) 00062 return; 00063 00064 /* allocate memory for an extra \0 char to make parsing easier */ 00065 ptr = cmd_alloc(len + sizeof(TCHAR)); 00066 if (!ptr) 00067 return; 00068 00069 Aliases = ptr; 00070 00071 ZeroMemory(Aliases, len + sizeof(TCHAR)); 00072 00073 if (GetConsoleAliases(Aliases, len, _T("cmd.exe")) != 0) 00074 { 00075 while (*Aliases != '\0') 00076 { 00077 ConOutPrintf(_T("%s\n"), Aliases); 00078 Aliases = Aliases + lstrlen(Aliases); 00079 Aliases++; 00080 } 00081 } 00082 cmd_free(ptr); 00083 } 00084 00085 /* specified routines */ 00086 VOID ExpandAlias (LPTSTR cmd, INT maxlen) 00087 { 00088 LPTSTR buffer; 00089 TCHAR *position, *in, *out; 00090 LPTSTR Token; 00091 LPTSTR tmp; 00092 00093 tmp = cmd_dup(cmd); 00094 if (!tmp) 00095 return; 00096 00097 /* first part is the macro name */ 00098 position = tmp + _tcscspn(tmp, _T(" \n")); 00099 if (position == tmp) 00100 { 00101 cmd_free(tmp); 00102 return; 00103 } 00104 *position++ = _T('\0'); 00105 position += _tcsspn(position, _T(" ")); 00106 00107 buffer = cmd_alloc(maxlen); 00108 if (!buffer) 00109 { 00110 cmd_free(tmp); 00111 return; 00112 } 00113 00114 if (GetConsoleAlias(tmp, buffer, maxlen, _T("cmd.exe")) == 0) 00115 { 00116 cmd_free(tmp); 00117 cmd_free(buffer); 00118 return; 00119 } 00120 00121 in = buffer; 00122 out = cmd; 00123 while (*in) 00124 { 00125 if (*in == _T('$')) 00126 { 00127 Token = position; 00128 if (in[1] >= _T('1') && in[1] <= _T('9')) 00129 { 00130 /* Copy a single space-delimited token from the input line */ 00131 INT num; 00132 for (num = in[1] - _T('1'); num > 0; num--) 00133 { 00134 Token += _tcscspn(Token, _T(" \n")); 00135 Token += _tcsspn(Token, _T(" ")); 00136 } 00137 while (!_tcschr(_T(" \n"), *Token)) 00138 { 00139 if (out >= &cmd[maxlen - 1]) 00140 break; 00141 *out++ = *Token++; 00142 } 00143 in += 2; 00144 continue; 00145 } 00146 else if (in[1] == _T('*')) 00147 { 00148 /* Copy the entire remainder of the line */ 00149 while (*Token && *Token != _T('\n')) 00150 { 00151 if (out >= &cmd[maxlen - 1]) 00152 break; 00153 *out++ = *Token++; 00154 } 00155 in += 2; 00156 continue; 00157 } 00158 } 00159 if (out >= &cmd[maxlen - 1]) 00160 break; 00161 *out++ = *in++; 00162 } 00163 *out++ = _T('\n'); 00164 *out = _T('\0'); 00165 00166 cmd_free(buffer); 00167 cmd_free(tmp); 00168 } 00169 00170 INT CommandAlias (LPTSTR param) 00171 { 00172 LPTSTR ptr; 00173 00174 if (!_tcsncmp (param, _T("/?"), 2)) 00175 { 00176 ConOutResPaging(TRUE,STRING_ALIAS_HELP); 00177 return 0; 00178 } 00179 00180 nErrorLevel = 0; 00181 00182 if (param[0] == _T('\0')) 00183 { 00184 PrintAlias (); 00185 return 0; 00186 } 00187 00188 nErrorLevel = 0; 00189 00190 /* error if no '=' found */ 00191 if ((ptr = _tcschr (param, _T('='))) == 0) 00192 { 00193 nErrorLevel = 1; 00194 return 1; 00195 } 00196 00197 /* Split rest into name and substitute */ 00198 *ptr++ = _T('\0'); 00199 00200 partstrlwr (param); 00201 00202 if (ptr[0] == _T('\0')) 00203 AddConsoleAlias(param, NULL, _T("cmd.exe")); 00204 else 00205 AddConsoleAlias(param, ptr, _T("cmd.exe")); 00206 00207 return 0; 00208 } 00209 #endif Generated on Sat May 26 2012 04:17:00 for ReactOS by
1.7.6.1
|