Author: jmorlan
Date: Sun Mar 1 22:11:55 2009
New Revision: 39834
URL:
http://svn.reactos.org/svn/reactos?rev=39834&view=rev
Log:
In the DOSKEY command:
- Fix handling of spaces
- When reading from file, remove ending '\n'
- Don't convert macro name to lower case
- Disallow empty macro name or macro names containing spaces
Modified:
trunk/reactos/base/applications/cmdutils/doskey/doskey.c
Modified: trunk/reactos/base/applications/cmdutils/doskey/doskey.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/cmdutils…
==============================================================================
--- trunk/reactos/base/applications/cmdutils/doskey/doskey.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/cmdutils/doskey/doskey.c [iso-8859-1] Sun Mar 1
22:11:55 2009
@@ -1,17 +1,6 @@
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
-
-static VOID
-partstrlwr (LPTSTR str)
-{
- LPTSTR c = str;
- while (*c && !_istspace (*c) && *c != _T('='))
- {
- *c = _totlower (*c);
- c++;
- }
-}
static VOID
PrintAlias (VOID)
@@ -47,7 +36,7 @@
INT SetMacro (LPTSTR param)
{
- LPTSTR ptr;
+ LPTSTR ptr, text;
while (*param == _T(' '))
param++;
@@ -56,23 +45,25 @@
if ((ptr = _tcschr (param, _T('='))) == 0)
return 1;
- while (*param == _T(' '))
- param++;
+ text = ptr + 1;
+ while (*text == _T(' '))
+ text++;
- while (*ptr == _T(' '))
+ while (ptr > param && ptr[-1] == _T(' '))
ptr--;
/* Split rest into name and substitute */
*ptr++ = _T('\0');
- partstrlwr (param);
+ if (*param == _T('\0') || _tcschr(param, _T(' ')))
+ return 1;
- _tprintf(_T("%s, %s\n"), ptr, param);
+ _tprintf(_T("%s, %s\n"), text, param);
if (ptr[0] == _T('\0'))
AddConsoleAlias(param, NULL, _T("cmd.exe"));
else
- AddConsoleAlias(param, ptr, _T("cmd.exe"));
+ AddConsoleAlias(param, text, _T("cmd.exe"));
return 0;
}
@@ -88,7 +79,14 @@
fp = _tfopen(param, _T("r"));
while ( _fgetts(line, MAX_PATH, fp) != NULL)
+ {
+ /* Remove newline character */
+ TCHAR *end = &line[_tcslen(line) - 1];
+ if (*end == _T('\n'))
+ *end = _T('\0');
+
SetMacro(line);
+ }
fclose(fp);
return;
@@ -121,6 +119,7 @@
szCommandLine++;
}
while(*szCommandLine != '\"');
+ szCommandLine++;
}
else
{
@@ -131,8 +130,8 @@
while(*szCommandLine != ' ');
}
- /* Skip the trailing quotation mark/whitespace and pass the command line to
SetMacro */
- SetMacro(++szCommandLine);
+ /* Skip the leading whitespace and pass the command line to SetMacro */
+ SetMacro(szCommandLine + _tcsspn(szCommandLine, _T(" \t")));
}
return 0;