mirror of
https://github.com/reactos/reactos.git
synced 2024-07-04 11:44:33 +00:00
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 svn path=/trunk/; revision=39834
This commit is contained in:
parent
7f9c2e8970
commit
e81627a11d
|
@ -2,17 +2,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
static VOID
|
|
||||||
partstrlwr (LPTSTR str)
|
|
||||||
{
|
|
||||||
LPTSTR c = str;
|
|
||||||
while (*c && !_istspace (*c) && *c != _T('='))
|
|
||||||
{
|
|
||||||
*c = _totlower (*c);
|
|
||||||
c++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
PrintAlias (VOID)
|
PrintAlias (VOID)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +36,7 @@ PrintAlias (VOID)
|
||||||
|
|
||||||
INT SetMacro (LPTSTR param)
|
INT SetMacro (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR ptr;
|
LPTSTR ptr, text;
|
||||||
|
|
||||||
while (*param == _T(' '))
|
while (*param == _T(' '))
|
||||||
param++;
|
param++;
|
||||||
|
@ -56,23 +45,25 @@ INT SetMacro (LPTSTR param)
|
||||||
if ((ptr = _tcschr (param, _T('='))) == 0)
|
if ((ptr = _tcschr (param, _T('='))) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
while (*param == _T(' '))
|
text = ptr + 1;
|
||||||
param++;
|
while (*text == _T(' '))
|
||||||
|
text++;
|
||||||
|
|
||||||
while (*ptr == _T(' '))
|
while (ptr > param && ptr[-1] == _T(' '))
|
||||||
ptr--;
|
ptr--;
|
||||||
|
|
||||||
/* Split rest into name and substitute */
|
/* Split rest into name and substitute */
|
||||||
*ptr++ = _T('\0');
|
*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'))
|
if (ptr[0] == _T('\0'))
|
||||||
AddConsoleAlias(param, NULL, _T("cmd.exe"));
|
AddConsoleAlias(param, NULL, _T("cmd.exe"));
|
||||||
else
|
else
|
||||||
AddConsoleAlias(param, ptr, _T("cmd.exe"));
|
AddConsoleAlias(param, text, _T("cmd.exe"));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +79,14 @@ static VOID ReadFromFile(LPTSTR param)
|
||||||
fp = _tfopen(param, _T("r"));
|
fp = _tfopen(param, _T("r"));
|
||||||
|
|
||||||
while ( _fgetts(line, MAX_PATH, fp) != NULL)
|
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);
|
SetMacro(line);
|
||||||
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
|
@ -121,6 +119,7 @@ _tmain (int argc, LPTSTR argv[])
|
||||||
szCommandLine++;
|
szCommandLine++;
|
||||||
}
|
}
|
||||||
while(*szCommandLine != '\"');
|
while(*szCommandLine != '\"');
|
||||||
|
szCommandLine++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -131,8 +130,8 @@ _tmain (int argc, LPTSTR argv[])
|
||||||
while(*szCommandLine != ' ');
|
while(*szCommandLine != ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip the trailing quotation mark/whitespace and pass the command line to SetMacro */
|
/* Skip the leading whitespace and pass the command line to SetMacro */
|
||||||
SetMacro(++szCommandLine);
|
SetMacro(szCommandLine + _tcsspn(szCommandLine, _T(" \t")));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue