Author: cfinck
Date: Thu May 8 13:11:56 2008
New Revision: 33379
URL:
http://svn.reactos.org/svn/reactos?rev=33379&view=rev
Log:
- 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
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] Thu May 8
13:11:56 2008
@@ -5,131 +5,135 @@
static VOID
partstrlwr (LPTSTR str)
{
- LPTSTR c = str;
- while (*c && !_istspace (*c) && *c != _T('='))
- {
- *c = _totlower (*c);
- c++;
- }
+ LPTSTR c = str;
+ while (*c && !_istspace (*c) && *c != _T('='))
+ {
+ *c = _totlower (*c);
+ c++;
+ }
}
static VOID
PrintAlias (VOID)
{
- LPTSTR Aliases;
- LPTSTR ptr;
- DWORD len;
+ LPTSTR Aliases;
+ LPTSTR ptr;
+ DWORD len;
- len = GetConsoleAliasesLength(_T("cmd.exe"));
- if (len <= 0)
- return;
+ len = GetConsoleAliasesLength(_T("cmd.exe"));
+ if (len <= 0)
+ return;
- /* allocate memory for an extra \0 char to make parsing easier */
- ptr = HeapAlloc(GetProcessHeap(), 0, (len + sizeof(TCHAR)));
- if (!ptr)
- return;
+ /* allocate memory for an extra \0 char to make parsing easier */
+ ptr = HeapAlloc(GetProcessHeap(), 0, (len + sizeof(TCHAR)));
+ if (!ptr)
+ return;
- Aliases = ptr;
+ Aliases = ptr;
- ZeroMemory(Aliases, len + sizeof(TCHAR));
+ ZeroMemory(Aliases, len + sizeof(TCHAR));
- if (GetConsoleAliases(Aliases, len, _T("cmd.exe")) != 0)
- {
- while (*Aliases != '\0')
- {
- _tprintf(_T("%s\n"), Aliases);
- Aliases = Aliases + lstrlen(Aliases);
- Aliases++;
- }
- }
- HeapFree(GetProcessHeap(), 0 , ptr);
+ if (GetConsoleAliases(Aliases, len, _T("cmd.exe")) != 0)
+ {
+ while (*Aliases != '\0')
+ {
+ _tprintf(_T("%s\n"), Aliases);
+ Aliases = Aliases + lstrlen(Aliases);
+ Aliases++;
+ }
+ }
+ HeapFree(GetProcessHeap(), 0 , ptr);
}
INT SetMacro (LPTSTR param)
{
- LPTSTR ptr;
+ LPTSTR ptr;
- while (*param == _T(' '))
- param++;
+ while (*param == _T(' '))
+ param++;
- /* error if no '=' found */
- if ((ptr = _tcschr (param, _T('='))) == 0)
- return 1;
+ /* error if no '=' found */
+ if ((ptr = _tcschr (param, _T('='))) == 0)
+ return 1;
- while (*param == _T(' '))
- param++;
+ while (*param == _T(' '))
+ param++;
- while (*ptr == _T(' '))
- ptr--;
+ while (*ptr == _T(' '))
+ ptr--;
- /* Split rest into name and substitute */
- *ptr++ = _T('\0');
+ /* Split rest into name and substitute */
+ *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'))
- AddConsoleAlias(param, NULL, _T("cmd.exe"));
- else
- AddConsoleAlias(param, ptr, _T("cmd.exe"));
+ if (ptr[0] == _T('\0'))
+ AddConsoleAlias(param, NULL, _T("cmd.exe"));
+ else
+ AddConsoleAlias(param, ptr, _T("cmd.exe"));
- return 0;
+ return 0;
}
-static VOID ReadFromFile(LPSTR param)
+static VOID ReadFromFile(LPTSTR param)
{
- FILE* fp;
- char line[MAX_PATH];
-#ifdef UNICODE
- WCHAR lineW[MAX_PATH];
-#endif
+ FILE* fp;
+ TCHAR line[MAX_PATH];
- /* FIXME */
- param += 11;
+ /* Skip the "/macrofile=" prefix */
+ param += 11;
- fp = fopen(param,"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
- }
+ fp = _tfopen(param, _T("r"));
- fclose(fp);
- return;
+ while ( _fgetts(line, MAX_PATH, fp) != NULL)
+ SetMacro(line);
+
+ fclose(fp);
+ return;
}
int
-main (int argc, char **argv)
+_tmain (int argc, LPTSTR argv[])
{
-#ifdef UNICODE
- WCHAR lineW[MAX_PATH];
-#endif
+ if (argc < 2)
+ return 0;
- if (argc < 2)
- return 0;
+ if (argv[1][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] == '/')
- {
- if (strnicmp(argv[1], "/macrofile", 10) == 0)
- ReadFromFile(argv[1]);
- if (stricmp(argv[1], "/macros") == 0)
- PrintAlias();
- }
- else
- {
-#ifdef UNICODE
- MultiByteToWideChar(CP_ACP, 0, argv[1], -1, lineW, MAX_PATH);
- SetMacro(lineW);
-#else
- SetMacro(argv[1]);
-#endif
- }
+ /* Skip the application name */
+ if(*szCommandLine == '\"')
+ {
+ do
+ {
+ szCommandLine++;
+ }
+ while(*szCommandLine != '\"');
+ }
+ else
+ {
+ do
+ {
+ szCommandLine++;
+ }
+ while(*szCommandLine != ' ');
+ }
- return 0;
+ /* Skip the trailing quotation mark/whitespace and pass the command line to
SetMacro */
+ SetMacro(++szCommandLine);
+ }
+
+ return 0;
}
-