mirror of
https://github.com/reactos/reactos.git
synced 2024-10-07 18:04:41 +00:00
- Fix build by converting everything to use TCHAR's
- Bugfix: Previously macros like "gotoroot=cd \" weren't passed correctly as we just used argv[1]. Now use GetCommandLine and pass the full command line. - Fix indentation svn path=/trunk/; revision=33379
This commit is contained in:
parent
b26bf1b115
commit
4198aafc54
|
@ -5,131 +5,135 @@
|
||||||
static VOID
|
static VOID
|
||||||
partstrlwr (LPTSTR str)
|
partstrlwr (LPTSTR str)
|
||||||
{
|
{
|
||||||
LPTSTR c = str;
|
LPTSTR c = str;
|
||||||
while (*c && !_istspace (*c) && *c != _T('='))
|
while (*c && !_istspace (*c) && *c != _T('='))
|
||||||
{
|
{
|
||||||
*c = _totlower (*c);
|
*c = _totlower (*c);
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
PrintAlias (VOID)
|
PrintAlias (VOID)
|
||||||
{
|
{
|
||||||
LPTSTR Aliases;
|
LPTSTR Aliases;
|
||||||
LPTSTR ptr;
|
LPTSTR ptr;
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
|
||||||
len = GetConsoleAliasesLength(_T("cmd.exe"));
|
len = GetConsoleAliasesLength(_T("cmd.exe"));
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* allocate memory for an extra \0 char to make parsing easier */
|
/* allocate memory for an extra \0 char to make parsing easier */
|
||||||
ptr = HeapAlloc(GetProcessHeap(), 0, (len + sizeof(TCHAR)));
|
ptr = HeapAlloc(GetProcessHeap(), 0, (len + sizeof(TCHAR)));
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Aliases = ptr;
|
Aliases = ptr;
|
||||||
|
|
||||||
ZeroMemory(Aliases, len + sizeof(TCHAR));
|
ZeroMemory(Aliases, len + sizeof(TCHAR));
|
||||||
|
|
||||||
if (GetConsoleAliases(Aliases, len, _T("cmd.exe")) != 0)
|
if (GetConsoleAliases(Aliases, len, _T("cmd.exe")) != 0)
|
||||||
{
|
{
|
||||||
while (*Aliases != '\0')
|
while (*Aliases != '\0')
|
||||||
{
|
{
|
||||||
_tprintf(_T("%s\n"), Aliases);
|
_tprintf(_T("%s\n"), Aliases);
|
||||||
Aliases = Aliases + lstrlen(Aliases);
|
Aliases = Aliases + lstrlen(Aliases);
|
||||||
Aliases++;
|
Aliases++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HeapFree(GetProcessHeap(), 0 , ptr);
|
HeapFree(GetProcessHeap(), 0 , ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
INT SetMacro (LPTSTR param)
|
INT SetMacro (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR ptr;
|
LPTSTR ptr;
|
||||||
|
|
||||||
while (*param == _T(' '))
|
while (*param == _T(' '))
|
||||||
param++;
|
param++;
|
||||||
|
|
||||||
/* error if no '=' found */
|
/* error if no '=' found */
|
||||||
if ((ptr = _tcschr (param, _T('='))) == 0)
|
if ((ptr = _tcschr (param, _T('='))) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
while (*param == _T(' '))
|
while (*param == _T(' '))
|
||||||
param++;
|
param++;
|
||||||
|
|
||||||
while (*ptr == _T(' '))
|
while (*ptr == _T(' '))
|
||||||
ptr--;
|
ptr--;
|
||||||
|
|
||||||
/* Split rest into name and substitute */
|
/* Split rest into name and substitute */
|
||||||
*ptr++ = _T('\0');
|
*ptr++ = _T('\0');
|
||||||
|
|
||||||
partstrlwr (param);
|
partstrlwr (param);
|
||||||
|
|
||||||
_tprintf(_T("%s, %s\n"), ptr, param);
|
_tprintf(_T("%s, %s\n"), ptr, 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, ptr, _T("cmd.exe"));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID ReadFromFile(LPSTR param)
|
static VOID ReadFromFile(LPTSTR param)
|
||||||
{
|
{
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
char line[MAX_PATH];
|
TCHAR line[MAX_PATH];
|
||||||
#ifdef UNICODE
|
|
||||||
WCHAR lineW[MAX_PATH];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* FIXME */
|
/* Skip the "/macrofile=" prefix */
|
||||||
param += 11;
|
param += 11;
|
||||||
|
|
||||||
fp = fopen(param,"r");
|
fp = _tfopen(param, _T("r"));
|
||||||
while ( fgets(line, MAX_PATH, fp) != NULL)
|
|
||||||
{
|
|
||||||
#ifdef UNICODE
|
|
||||||
MultiByteToWideChar(CP_ACP, 0, line, -1, lineW, MAX_PATH);
|
|
||||||
SetMacro(lineW);
|
|
||||||
#else
|
|
||||||
SetMacro(line);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
while ( _fgetts(line, MAX_PATH, fp) != NULL)
|
||||||
return;
|
SetMacro(line);
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
_tmain (int argc, LPTSTR argv[])
|
||||||
{
|
{
|
||||||
#ifdef UNICODE
|
if (argc < 2)
|
||||||
WCHAR lineW[MAX_PATH];
|
return 0;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (argc < 2)
|
if (argv[1][0] == '/')
|
||||||
return 0;
|
{
|
||||||
|
if (_tcsnicmp(argv[1], _T("/macrofile"), 10) == 0)
|
||||||
|
ReadFromFile(argv[1]);
|
||||||
|
if (_tcscmp(argv[1], _T("/macros")) == 0)
|
||||||
|
PrintAlias();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Get the full command line using GetCommandLine().
|
||||||
|
We can't just pass argv[1] here, because then a parameter like "gotoroot=cd \" wouldn't be passed completely. */
|
||||||
|
TCHAR* szCommandLine = GetCommandLine();
|
||||||
|
|
||||||
if (argv[1][0] == '/')
|
/* Skip the application name */
|
||||||
{
|
if(*szCommandLine == '\"')
|
||||||
if (strnicmp(argv[1], "/macrofile", 10) == 0)
|
{
|
||||||
ReadFromFile(argv[1]);
|
do
|
||||||
if (stricmp(argv[1], "/macros") == 0)
|
{
|
||||||
PrintAlias();
|
szCommandLine++;
|
||||||
}
|
}
|
||||||
else
|
while(*szCommandLine != '\"');
|
||||||
{
|
}
|
||||||
#ifdef UNICODE
|
else
|
||||||
MultiByteToWideChar(CP_ACP, 0, argv[1], -1, lineW, MAX_PATH);
|
{
|
||||||
SetMacro(lineW);
|
do
|
||||||
#else
|
{
|
||||||
SetMacro(argv[1]);
|
szCommandLine++;
|
||||||
#endif
|
}
|
||||||
}
|
while(*szCommandLine != ' ');
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
/* Skip the trailing quotation mark/whitespace and pass the command line to SetMacro */
|
||||||
|
SetMacro(++szCommandLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue