Author: jmorlan
Date: Sat Feb 28 21:00:38 2009
New Revision: 39817
URL:
http://svn.reactos.org/svn/reactos?rev=39817&view=rev
Log:
- FileGetString: Only end line on '\n', not on '\r'.
- Various improvements to ExpandAlias
Modified:
trunk/reactos/base/shell/cmd/alias.c
trunk/reactos/base/shell/cmd/misc.c
Modified: trunk/reactos/base/shell/cmd/alias.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/alias.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/alias.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/alias.c [iso-8859-1] Sat Feb 28 21:00:38 2009
@@ -86,21 +86,23 @@
VOID ExpandAlias (LPTSTR cmd, INT maxlen)
{
LPTSTR buffer;
- TCHAR* position;
+ TCHAR *position, *in, *out;
LPTSTR Token;
LPTSTR tmp;
- tmp = cmd_alloc(maxlen);
+ tmp = cmd_dup(cmd);
if (!tmp)
return;
- _tcscpy(tmp, cmd);
-
- Token = _tcstok(tmp, _T(" ")); /* first part is the macro name */
- if (!Token)
+
+ /* first part is the macro name */
+ position = tmp + _tcscspn(tmp, _T(" \n"));
+ if (position == tmp)
{
cmd_free(tmp);
return;
}
+ *position++ = _T('\0');
+ position += _tcsspn(position, _T(" "));
buffer = cmd_alloc(maxlen);
if (!buffer)
@@ -109,34 +111,60 @@
return;
}
- if (GetConsoleAlias(Token, buffer, maxlen, _T("cmd.exe")) == 0)
+ if (GetConsoleAlias(tmp, buffer, maxlen, _T("cmd.exe")) == 0)
{
cmd_free(tmp);
cmd_free(buffer);
return;
}
- Token = _tcstok (NULL, _T(" "));
-
- ZeroMemory(cmd, maxlen);
- position = _tcsstr(buffer, _T("$*"));
- if (position)
- {
- _tcsncpy(cmd, buffer, (INT) (position - buffer) - 1);
- if (Token)
+ in = buffer;
+ out = cmd;
+ while (*in)
+ {
+ if (*in == _T('$'))
{
- _tcscat(cmd, _T(" "));
- _tcscat(cmd, Token);
+ Token = position;
+ if (in[1] >= _T('1') && in[1] <= _T('9'))
+ {
+ /* Copy a single space-delimited token from the input line */
+ INT num;
+ for (num = in[1] - _T('1'); num > 0; num--)
+ {
+ Token += _tcscspn(Token, _T(" \n"));
+ Token += _tcsspn(Token, _T(" "));
+ }
+ while (!_tcschr(_T(" \n"), *Token))
+ {
+ if (out >= &cmd[maxlen - 1])
+ break;
+ *out++ = *Token++;
+ }
+ in += 2;
+ continue;
+ }
+ else if (in[1] == _T('*'))
+ {
+ /* Copy the entire remainder of the line */
+ while (*Token && *Token != _T('\n'))
+ {
+ if (out >= &cmd[maxlen - 1])
+ break;
+ *out++ = *Token++;
+ }
+ in += 2;
+ continue;
+ }
}
- }
- else
- {
- _tcscpy(cmd, buffer);
- }
+ if (out >= &cmd[maxlen - 1])
+ break;
+ *out++ = *in++;
+ }
+ *out++ = _T('\n');
+ *out = _T('\0');
cmd_free(buffer);
cmd_free(tmp);
-
}
INT CommandAlias (LPTSTR param)
Modified: trunk/reactos/base/shell/cmd/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/misc.c?rev=…
==============================================================================
--- trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/misc.c [iso-8859-1] Sat Feb 28 21:00:38 2009
@@ -515,7 +515,7 @@
ReadFile(hFile, &ch, 1, &dwRead, NULL) && dwRead)
{
lpString[len++] = ch;
- if ((ch == _T('\n')) || (ch == _T('\r')))
+ if (ch == '\n')
{
/* break at new line*/
break;
@@ -530,7 +530,7 @@
return FALSE;
}
- lpString[len++] = _T('\0');
+ lpString[len++] = '\0';
#ifdef _UNICODE
MultiByteToWideChar(CP_ACP, 0, lpString, -1, lpBuffer, len);
cmd_free(lpString);