mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 10:12:58 +00:00
[CMD]
Fix whitespace (part 3/x) (convert tabs into 4-space indent). svn path=/trunk/; revision=59379
This commit is contained in:
parent
9b6dc5bd15
commit
6437619ff3
25 changed files with 3026 additions and 3010 deletions
|
@ -25,8 +25,8 @@
|
||||||
* 24-Jan-1998 Eric Kohl
|
* 24-Jan-1998 Eric Kohl
|
||||||
* Redirection safe!
|
* Redirection safe!
|
||||||
*
|
*
|
||||||
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*
|
*
|
||||||
* 02-Feb-2008 (Christoph von Wittich) <christoph_vw@reactos.org>)
|
* 02-Feb-2008 (Christoph von Wittich) <christoph_vw@reactos.org>)
|
||||||
* rewrote alias handling for doskey compat
|
* rewrote alias handling for doskey compat
|
||||||
|
@ -42,168 +42,168 @@
|
||||||
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 = cmd_alloc(len + sizeof(TCHAR));
|
ptr = cmd_alloc(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')
|
||||||
{
|
{
|
||||||
ConOutPrintf(_T("%s\n"), Aliases);
|
ConOutPrintf(_T("%s\n"), Aliases);
|
||||||
Aliases = Aliases + lstrlen(Aliases);
|
Aliases = Aliases + lstrlen(Aliases);
|
||||||
Aliases++;
|
Aliases++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd_free(ptr);
|
cmd_free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* specified routines */
|
/* specified routines */
|
||||||
VOID ExpandAlias (LPTSTR cmd, INT maxlen)
|
VOID ExpandAlias (LPTSTR cmd, INT maxlen)
|
||||||
{
|
{
|
||||||
LPTSTR buffer;
|
LPTSTR buffer;
|
||||||
TCHAR *position, *in, *out;
|
TCHAR *position, *in, *out;
|
||||||
LPTSTR Token;
|
LPTSTR Token;
|
||||||
LPTSTR tmp;
|
LPTSTR tmp;
|
||||||
|
|
||||||
tmp = cmd_dup(cmd);
|
tmp = cmd_dup(cmd);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* first part is the macro name */
|
/* first part is the macro name */
|
||||||
position = tmp + _tcscspn(tmp, _T(" \n"));
|
position = tmp + _tcscspn(tmp, _T(" \n"));
|
||||||
if (position == tmp)
|
if (position == tmp)
|
||||||
{
|
{
|
||||||
cmd_free(tmp);
|
cmd_free(tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*position++ = _T('\0');
|
*position++ = _T('\0');
|
||||||
position += _tcsspn(position, _T(" "));
|
position += _tcsspn(position, _T(" "));
|
||||||
|
|
||||||
buffer = cmd_alloc(maxlen);
|
buffer = cmd_alloc(maxlen);
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
cmd_free(tmp);
|
cmd_free(tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetConsoleAlias(tmp, buffer, maxlen, _T("cmd.exe")) == 0)
|
|
||||||
{
|
|
||||||
cmd_free(tmp);
|
|
||||||
cmd_free(buffer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
in = buffer;
|
if (GetConsoleAlias(tmp, buffer, maxlen, _T("cmd.exe")) == 0)
|
||||||
out = cmd;
|
{
|
||||||
while (*in)
|
cmd_free(tmp);
|
||||||
{
|
cmd_free(buffer);
|
||||||
if (*in == _T('$'))
|
return;
|
||||||
{
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (out >= &cmd[maxlen - 1])
|
|
||||||
break;
|
|
||||||
*out++ = *in++;
|
|
||||||
}
|
|
||||||
*out++ = _T('\n');
|
|
||||||
*out = _T('\0');
|
|
||||||
|
|
||||||
cmd_free(buffer);
|
in = buffer;
|
||||||
cmd_free(tmp);
|
out = cmd;
|
||||||
|
while (*in)
|
||||||
|
{
|
||||||
|
if (*in == _T('$'))
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (out >= &cmd[maxlen - 1])
|
||||||
|
break;
|
||||||
|
*out++ = *in++;
|
||||||
|
}
|
||||||
|
*out++ = _T('\n');
|
||||||
|
*out = _T('\0');
|
||||||
|
|
||||||
|
cmd_free(buffer);
|
||||||
|
cmd_free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
INT CommandAlias (LPTSTR param)
|
INT CommandAlias (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR ptr;
|
LPTSTR ptr;
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_ALIAS_HELP);
|
ConOutResPaging(TRUE,STRING_ALIAS_HELP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
if (param[0] == _T('\0'))
|
if (param[0] == _T('\0'))
|
||||||
{
|
{
|
||||||
PrintAlias ();
|
PrintAlias ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
/* error if no '=' found */
|
/* error if no '=' found */
|
||||||
if ((ptr = _tcschr (param, _T('='))) == 0)
|
if ((ptr = _tcschr (param, _T('='))) == 0)
|
||||||
{
|
{
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Split rest into name and substitute */
|
/* Split rest into name and substitute */
|
||||||
*ptr++ = _T('\0');
|
*ptr++ = _T('\0');
|
||||||
|
|
||||||
partstrlwr (param);
|
partstrlwr (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;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,236 +24,235 @@
|
||||||
static INT
|
static INT
|
||||||
PrintAssociation(LPTSTR extension)
|
PrintAssociation(LPTSTR extension)
|
||||||
{
|
{
|
||||||
DWORD return_val;
|
DWORD return_val;
|
||||||
HKEY hKey = NULL, hInsideKey = NULL;
|
HKEY hKey = NULL, hInsideKey = NULL;
|
||||||
|
|
||||||
DWORD fileTypeLength = 0;
|
DWORD fileTypeLength = 0;
|
||||||
LPTSTR fileType = NULL;
|
LPTSTR fileType = NULL;
|
||||||
|
|
||||||
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);
|
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return_val = RegOpenKeyEx(hKey, extension, 0, KEY_READ, &hInsideKey);
|
return_val = RegOpenKeyEx(hKey, extension, 0, KEY_READ, &hInsideKey);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
RegCloseKey(hInsideKey);
|
RegCloseKey(hInsideKey);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* obtain string length */
|
/* obtain string length */
|
||||||
return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, NULL, &fileTypeLength);
|
return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, NULL, &fileTypeLength);
|
||||||
|
|
||||||
if(return_val == ERROR_FILE_NOT_FOUND) /* no default value, don't display */
|
if(return_val == ERROR_FILE_NOT_FOUND) /* no default value, don't display */
|
||||||
{
|
{
|
||||||
RegCloseKey(hInsideKey);
|
RegCloseKey(hInsideKey);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(hInsideKey);
|
RegCloseKey(hInsideKey);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileType = cmd_alloc(fileTypeLength * sizeof(TCHAR));
|
fileType = cmd_alloc(fileTypeLength * sizeof(TCHAR));
|
||||||
|
|
||||||
/* obtain actual file type */
|
/* obtain actual file type */
|
||||||
return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, (LPBYTE) fileType, &fileTypeLength);
|
return_val = RegQueryValueEx(hInsideKey, NULL, NULL, NULL, (LPBYTE) fileType, &fileTypeLength);
|
||||||
|
|
||||||
RegCloseKey(hInsideKey);
|
RegCloseKey(hInsideKey);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
cmd_free(fileType);
|
cmd_free(fileType);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileTypeLength != 0) /* if there is a default key, display relevant information */
|
if(fileTypeLength != 0) /* if there is a default key, display relevant information */
|
||||||
{
|
{
|
||||||
ConOutPrintf(_T("%s=%s\r\n"), extension, fileType);
|
ConOutPrintf(_T("%s=%s\r\n"), extension, fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileTypeLength)
|
if(fileTypeLength)
|
||||||
cmd_free(fileType);
|
cmd_free(fileType);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INT
|
static INT
|
||||||
PrintAllAssociations()
|
PrintAllAssociations()
|
||||||
{
|
{
|
||||||
DWORD return_val = 0;
|
DWORD return_val = 0;
|
||||||
HKEY hKey = NULL;
|
HKEY hKey = NULL;
|
||||||
DWORD numKeys = 0;
|
DWORD numKeys = 0;
|
||||||
|
|
||||||
DWORD extLength = 0;
|
DWORD extLength = 0;
|
||||||
LPTSTR extName = NULL;
|
LPTSTR extName = NULL;
|
||||||
DWORD keyCtr = 0;
|
DWORD keyCtr = 0;
|
||||||
|
|
||||||
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);
|
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_READ, &hKey);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return_val = RegQueryInfoKey(hKey, NULL, NULL, NULL, &numKeys, &extLength, NULL, NULL, NULL, NULL, NULL, NULL);
|
return_val = RegQueryInfoKey(hKey, NULL, NULL, NULL, &numKeys, &extLength, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
extName = cmd_alloc(extLength * sizeof(TCHAR));
|
extName = cmd_alloc(extLength * sizeof(TCHAR));
|
||||||
|
|
||||||
for(keyCtr = 0; keyCtr < numKeys; keyCtr++)
|
for(keyCtr = 0; keyCtr < numKeys; keyCtr++)
|
||||||
{
|
{
|
||||||
DWORD buffer_size = extLength;
|
DWORD buffer_size = extLength;
|
||||||
return_val = RegEnumKeyEx(hKey, keyCtr, extName, &buffer_size, NULL, NULL, NULL, NULL);
|
return_val = RegEnumKeyEx(hKey, keyCtr, extName, &buffer_size, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
if(return_val == ERROR_SUCCESS || return_val == ERROR_MORE_DATA)
|
if(return_val == ERROR_SUCCESS || return_val == ERROR_MORE_DATA)
|
||||||
{
|
{
|
||||||
if(*extName == _T('.'))
|
if(*extName == _T('.'))
|
||||||
PrintAssociation(extName);
|
PrintAssociation(extName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd_free(extName);
|
cmd_free(extName);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
if(extName)
|
if(extName)
|
||||||
cmd_free(extName);
|
cmd_free(extName);
|
||||||
|
|
||||||
return numKeys;
|
return numKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INT
|
static INT
|
||||||
AddAssociation(LPTSTR extension, LPTSTR type)
|
AddAssociation(LPTSTR extension, LPTSTR type)
|
||||||
{
|
{
|
||||||
DWORD return_val;
|
DWORD return_val;
|
||||||
HKEY hKey = NULL, insideKey = NULL;
|
HKEY hKey = NULL, insideKey = NULL;
|
||||||
|
|
||||||
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_ALL_ACCESS, &hKey);
|
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_ALL_ACCESS, &hKey);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return_val = RegCreateKeyEx(hKey, extension, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &insideKey, NULL);
|
return_val = RegCreateKeyEx(hKey, extension, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &insideKey, NULL);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return_val = RegSetValueEx(insideKey, NULL, 0, REG_SZ, (LPBYTE)type, (_tcslen(type) + 1) * sizeof(TCHAR));
|
return_val = RegSetValueEx(insideKey, NULL, 0, REG_SZ, (LPBYTE)type, (_tcslen(type) + 1) * sizeof(TCHAR));
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(insideKey);
|
RegCloseKey(insideKey);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(insideKey);
|
RegCloseKey(insideKey);
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
RemoveAssociation(LPTSTR extension)
|
RemoveAssociation(LPTSTR extension)
|
||||||
{
|
{
|
||||||
DWORD return_val;
|
DWORD return_val;
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
|
|
||||||
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_ALL_ACCESS, &hKey);
|
return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes"), 0, KEY_ALL_ACCESS, &hKey);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return_val = RegDeleteKey(hKey, extension);
|
return_val = RegDeleteKey(hKey, extension);
|
||||||
|
|
||||||
if(return_val != ERROR_SUCCESS)
|
if(return_val != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INT CommandAssoc (LPTSTR param)
|
INT CommandAssoc (LPTSTR param)
|
||||||
{
|
{
|
||||||
|
/* print help */
|
||||||
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
|
{
|
||||||
|
ConOutResPaging(TRUE,STRING_ASSOC_HELP);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* print help */
|
nErrorLevel = 0;
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
|
||||||
{
|
|
||||||
ConOutResPaging(TRUE,STRING_ASSOC_HELP);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
nErrorLevel = 0;
|
if(_tcslen(param) == 0)
|
||||||
|
PrintAllAssociations();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LPTSTR lpEqualSign = _tcschr(param, _T('='));
|
||||||
|
if(lpEqualSign != NULL)
|
||||||
|
{
|
||||||
|
LPTSTR fileType = lpEqualSign + 1;
|
||||||
|
LPTSTR extension = cmd_alloc((lpEqualSign - param + 1) * sizeof(TCHAR));
|
||||||
|
|
||||||
if(_tcslen(param) == 0)
|
_tcsncpy(extension, param, lpEqualSign - param);
|
||||||
PrintAllAssociations();
|
extension[lpEqualSign - param] = (TCHAR)0;
|
||||||
else
|
|
||||||
{
|
|
||||||
LPTSTR lpEqualSign = _tcschr(param, _T('='));
|
|
||||||
if(lpEqualSign != NULL)
|
|
||||||
{
|
|
||||||
LPTSTR fileType = lpEqualSign + 1;
|
|
||||||
LPTSTR extension = cmd_alloc((lpEqualSign - param + 1) * sizeof(TCHAR));
|
|
||||||
|
|
||||||
_tcsncpy(extension, param, lpEqualSign - param);
|
if(_tcslen(fileType) == 0)
|
||||||
extension[lpEqualSign - param] = (TCHAR)0;
|
/* if the equal sign is the last character
|
||||||
|
in the string, then delete the key */
|
||||||
|
{
|
||||||
|
RemoveAssociation(extension);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* otherwise, add the key and print out the association*/
|
||||||
|
{
|
||||||
|
AddAssociation( extension, fileType);
|
||||||
|
PrintAssociation(extension);
|
||||||
|
}
|
||||||
|
|
||||||
if(_tcslen(fileType) == 0)
|
cmd_free(extension);
|
||||||
/* if the equal sign is the last character
|
}
|
||||||
in the string, then delete the key */
|
else
|
||||||
{
|
{
|
||||||
RemoveAssociation(extension);
|
/* no equal sign, print all associations */
|
||||||
}
|
INT retval = PrintAssociation(param);
|
||||||
else
|
|
||||||
/* otherwise, add the key and print out the association*/
|
|
||||||
{
|
|
||||||
AddAssociation( extension, fileType);
|
|
||||||
PrintAssociation(extension);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd_free(extension);
|
if(retval == 0) /* if nothing printed out */
|
||||||
}
|
ConOutResPrintf(STRING_ASSOC_ERROR, param);
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
/* no equal sign, print all associations */
|
|
||||||
INT retval = PrintAssociation(param);
|
|
||||||
|
|
||||||
if(retval == 0) /* if nothing printed out */
|
return 0;
|
||||||
ConOutResPrintf(STRING_ASSOC_ERROR, param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_ASSOC */
|
#endif /* INCLUDE_CMD_ASSOC */
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
* 23-Jan-1999 Eric Kohl
|
* 23-Jan-1999 Eric Kohl
|
||||||
* Added handling of multiple filenames.
|
* Added handling of multiple filenames.
|
||||||
*
|
*
|
||||||
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -39,306 +39,306 @@
|
||||||
static VOID
|
static VOID
|
||||||
PrintAttribute (LPTSTR pszPath, LPTSTR pszFile, BOOL bRecurse)
|
PrintAttribute (LPTSTR pszPath, LPTSTR pszFile, BOOL bRecurse)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA findData;
|
WIN32_FIND_DATA findData;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
TCHAR szFullName[MAX_PATH];
|
TCHAR szFullName[MAX_PATH];
|
||||||
LPTSTR pszFileName;
|
LPTSTR pszFileName;
|
||||||
|
|
||||||
/* prepare full file name buffer */
|
/* prepare full file name buffer */
|
||||||
_tcscpy (szFullName, pszPath);
|
_tcscpy (szFullName, pszPath);
|
||||||
pszFileName = szFullName + _tcslen (szFullName);
|
pszFileName = szFullName + _tcslen (szFullName);
|
||||||
|
|
||||||
/* display all subdirectories */
|
/* display all subdirectories */
|
||||||
if (bRecurse)
|
if (bRecurse)
|
||||||
{
|
{
|
||||||
/* append file name */
|
/* append file name */
|
||||||
_tcscpy (pszFileName, pszFile);
|
_tcscpy (pszFileName, pszFile);
|
||||||
|
|
||||||
hFind = FindFirstFile (szFullName, &findData);
|
hFind = FindFirstFile (szFullName, &findData);
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
ErrorMessage (GetLastError (), pszFile);
|
ErrorMessage (GetLastError (), pszFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!_tcscmp (findData.cFileName, _T(".")) ||
|
if (!_tcscmp (findData.cFileName, _T(".")) ||
|
||||||
!_tcscmp (findData.cFileName, _T("..")))
|
!_tcscmp (findData.cFileName, _T("..")))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_tcscpy (pszFileName, findData.cFileName);
|
_tcscpy (pszFileName, findData.cFileName);
|
||||||
_tcscat (pszFileName, _T("\\"));
|
_tcscat (pszFileName, _T("\\"));
|
||||||
PrintAttribute (szFullName, pszFile, bRecurse);
|
PrintAttribute (szFullName, pszFile, bRecurse);
|
||||||
}
|
}
|
||||||
while (FindNextFile (hFind, &findData));
|
while (FindNextFile (hFind, &findData));
|
||||||
FindClose (hFind);
|
FindClose (hFind);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* append file name */
|
/* append file name */
|
||||||
_tcscpy (pszFileName, pszFile);
|
_tcscpy (pszFileName, pszFile);
|
||||||
|
|
||||||
/* display current directory */
|
/* display current directory */
|
||||||
hFind = FindFirstFile (szFullName, &findData);
|
hFind = FindFirstFile (szFullName, &findData);
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
ErrorMessage (GetLastError (), pszFile);
|
ErrorMessage (GetLastError (), pszFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_tcscpy (pszFileName, findData.cFileName);
|
_tcscpy (pszFileName, findData.cFileName);
|
||||||
|
|
||||||
ConOutPrintf (_T("%c %c%c%c %s\n"),
|
ConOutPrintf (_T("%c %c%c%c %s\n"),
|
||||||
(findData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? _T('A') : _T(' '),
|
(findData.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) ? _T('A') : _T(' '),
|
||||||
(findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? _T('S') : _T(' '),
|
(findData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) ? _T('S') : _T(' '),
|
||||||
(findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? _T('H') : _T(' '),
|
(findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ? _T('H') : _T(' '),
|
||||||
(findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? _T('R') : _T(' '),
|
(findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? _T('R') : _T(' '),
|
||||||
szFullName);
|
szFullName);
|
||||||
}
|
}
|
||||||
while (FindNextFile (hFind, &findData));
|
while (FindNextFile (hFind, &findData));
|
||||||
FindClose (hFind);
|
FindClose (hFind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
ChangeAttribute (LPTSTR pszPath, LPTSTR pszFile, DWORD dwMask,
|
ChangeAttribute(LPTSTR pszPath, LPTSTR pszFile, DWORD dwMask,
|
||||||
DWORD dwAttrib, BOOL bRecurse, BOOL bDirectories)
|
DWORD dwAttrib, BOOL bRecurse, BOOL bDirectories)
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA findData;
|
WIN32_FIND_DATA findData;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
DWORD dwAttribute;
|
DWORD dwAttribute;
|
||||||
TCHAR szFullName[MAX_PATH];
|
TCHAR szFullName[MAX_PATH];
|
||||||
LPTSTR pszFileName;
|
LPTSTR pszFileName;
|
||||||
|
|
||||||
|
|
||||||
/* prepare full file name buffer */
|
/* prepare full file name buffer */
|
||||||
_tcscpy (szFullName, pszPath);
|
_tcscpy (szFullName, pszPath);
|
||||||
pszFileName = szFullName + _tcslen (szFullName);
|
pszFileName = szFullName + _tcslen (szFullName);
|
||||||
|
|
||||||
/* change all subdirectories */
|
/* change all subdirectories */
|
||||||
if (bRecurse)
|
if (bRecurse)
|
||||||
{
|
{
|
||||||
/* append file name */
|
/* append file name */
|
||||||
_tcscpy (pszFileName, _T("*.*"));
|
_tcscpy (pszFileName, _T("*.*"));
|
||||||
|
|
||||||
hFind = FindFirstFile (szFullName, &findData);
|
hFind = FindFirstFile (szFullName, &findData);
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
ErrorMessage (GetLastError (), pszFile);
|
ErrorMessage (GetLastError (), pszFile);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
{
|
{
|
||||||
if (!_tcscmp (findData.cFileName, _T(".")) ||
|
if (!_tcscmp (findData.cFileName, _T(".")) ||
|
||||||
!_tcscmp (findData.cFileName, _T("..")))
|
!_tcscmp (findData.cFileName, _T("..")))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_tcscpy (pszFileName, findData.cFileName);
|
_tcscpy (pszFileName, findData.cFileName);
|
||||||
_tcscat (pszFileName, _T("\\"));
|
_tcscat (pszFileName, _T("\\"));
|
||||||
|
|
||||||
ChangeAttribute (szFullName, pszFile, dwMask,
|
ChangeAttribute (szFullName, pszFile, dwMask,
|
||||||
dwAttrib, bRecurse, bDirectories);
|
dwAttrib, bRecurse, bDirectories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (FindNextFile (hFind, &findData));
|
while (FindNextFile (hFind, &findData));
|
||||||
FindClose (hFind);
|
FindClose (hFind);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* append file name */
|
/* append file name */
|
||||||
_tcscpy (pszFileName, pszFile);
|
_tcscpy (pszFileName, pszFile);
|
||||||
|
|
||||||
hFind = FindFirstFile (szFullName, &findData);
|
hFind = FindFirstFile (szFullName, &findData);
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
ErrorMessage (GetLastError (), pszFile);
|
ErrorMessage (GetLastError (), pszFile);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_tcscpy (pszFileName, findData.cFileName);
|
_tcscpy (pszFileName, findData.cFileName);
|
||||||
|
|
||||||
dwAttribute = GetFileAttributes (szFullName);
|
dwAttribute = GetFileAttributes (szFullName);
|
||||||
|
|
||||||
if (dwAttribute != 0xFFFFFFFF)
|
if (dwAttribute != 0xFFFFFFFF)
|
||||||
{
|
{
|
||||||
dwAttribute = (dwAttribute & ~dwMask) | dwAttrib;
|
dwAttribute = (dwAttribute & ~dwMask) | dwAttrib;
|
||||||
SetFileAttributes (szFullName, dwAttribute);
|
SetFileAttributes (szFullName, dwAttribute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (FindNextFile (hFind, &findData));
|
while (FindNextFile (hFind, &findData));
|
||||||
FindClose (hFind);
|
FindClose (hFind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INT CommandAttrib (LPTSTR param)
|
INT CommandAttrib (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR *arg;
|
LPTSTR *arg;
|
||||||
INT argc, i;
|
INT argc, i;
|
||||||
TCHAR szPath[MAX_PATH];
|
TCHAR szPath[MAX_PATH];
|
||||||
TCHAR szFileName [MAX_PATH];
|
TCHAR szFileName [MAX_PATH];
|
||||||
BOOL bRecurse = FALSE;
|
BOOL bRecurse = FALSE;
|
||||||
BOOL bDirectories = FALSE;
|
BOOL bDirectories = FALSE;
|
||||||
DWORD dwAttrib = 0;
|
DWORD dwAttrib = 0;
|
||||||
DWORD dwMask = 0;
|
DWORD dwMask = 0;
|
||||||
|
|
||||||
/* initialize strings */
|
/* initialize strings */
|
||||||
szPath[0] = _T('\0');
|
szPath[0] = _T('\0');
|
||||||
szFileName[0] = _T('\0');
|
szFileName[0] = _T('\0');
|
||||||
|
|
||||||
/* print help */
|
/* print help */
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_ATTRIB_HELP);
|
ConOutResPaging(TRUE,STRING_ATTRIB_HELP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
/* build parameter array */
|
/* build parameter array */
|
||||||
arg = split (param, &argc, FALSE, FALSE);
|
arg = split (param, &argc, FALSE, FALSE);
|
||||||
|
|
||||||
/* check for options */
|
/* check for options */
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (_tcsicmp (arg[i], _T("/s")) == 0)
|
if (_tcsicmp (arg[i], _T("/s")) == 0)
|
||||||
bRecurse = TRUE;
|
bRecurse = TRUE;
|
||||||
else if (_tcsicmp (arg[i], _T("/d")) == 0)
|
else if (_tcsicmp (arg[i], _T("/d")) == 0)
|
||||||
bDirectories = TRUE;
|
bDirectories = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create attributes and mask */
|
/* create attributes and mask */
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (*arg[i] == _T('+'))
|
if (*arg[i] == _T('+'))
|
||||||
{
|
{
|
||||||
if (_tcslen (arg[i]) != 2)
|
if (_tcslen (arg[i]) != 2)
|
||||||
{
|
{
|
||||||
error_invalid_parameter_format (arg[i]);
|
error_invalid_parameter_format (arg[i]);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ((TCHAR)_totupper (arg[i][1]))
|
switch ((TCHAR)_totupper (arg[i][1]))
|
||||||
{
|
{
|
||||||
case _T('A'):
|
case _T('A'):
|
||||||
dwMask |= FILE_ATTRIBUTE_ARCHIVE;
|
dwMask |= FILE_ATTRIBUTE_ARCHIVE;
|
||||||
dwAttrib |= FILE_ATTRIBUTE_ARCHIVE;
|
dwAttrib |= FILE_ATTRIBUTE_ARCHIVE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('H'):
|
case _T('H'):
|
||||||
dwMask |= FILE_ATTRIBUTE_HIDDEN;
|
dwMask |= FILE_ATTRIBUTE_HIDDEN;
|
||||||
dwAttrib |= FILE_ATTRIBUTE_HIDDEN;
|
dwAttrib |= FILE_ATTRIBUTE_HIDDEN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('R'):
|
case _T('R'):
|
||||||
dwMask |= FILE_ATTRIBUTE_READONLY;
|
dwMask |= FILE_ATTRIBUTE_READONLY;
|
||||||
dwAttrib |= FILE_ATTRIBUTE_READONLY;
|
dwAttrib |= FILE_ATTRIBUTE_READONLY;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('S'):
|
case _T('S'):
|
||||||
dwMask |= FILE_ATTRIBUTE_SYSTEM;
|
dwMask |= FILE_ATTRIBUTE_SYSTEM;
|
||||||
dwAttrib |= FILE_ATTRIBUTE_SYSTEM;
|
dwAttrib |= FILE_ATTRIBUTE_SYSTEM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error_invalid_parameter_format (arg[i]);
|
error_invalid_parameter_format (arg[i]);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (*arg[i] == _T('-'))
|
else if (*arg[i] == _T('-'))
|
||||||
{
|
{
|
||||||
if (_tcslen (arg[i]) != 2)
|
if (_tcslen (arg[i]) != 2)
|
||||||
{
|
{
|
||||||
error_invalid_parameter_format (arg[i]);
|
error_invalid_parameter_format (arg[i]);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ((TCHAR)_totupper (arg[i][1]))
|
switch ((TCHAR)_totupper (arg[i][1]))
|
||||||
{
|
{
|
||||||
case _T('A'):
|
case _T('A'):
|
||||||
dwMask |= FILE_ATTRIBUTE_ARCHIVE;
|
dwMask |= FILE_ATTRIBUTE_ARCHIVE;
|
||||||
dwAttrib &= ~FILE_ATTRIBUTE_ARCHIVE;
|
dwAttrib &= ~FILE_ATTRIBUTE_ARCHIVE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('H'):
|
case _T('H'):
|
||||||
dwMask |= FILE_ATTRIBUTE_HIDDEN;
|
dwMask |= FILE_ATTRIBUTE_HIDDEN;
|
||||||
dwAttrib &= ~FILE_ATTRIBUTE_HIDDEN;
|
dwAttrib &= ~FILE_ATTRIBUTE_HIDDEN;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('R'):
|
case _T('R'):
|
||||||
dwMask |= FILE_ATTRIBUTE_READONLY;
|
dwMask |= FILE_ATTRIBUTE_READONLY;
|
||||||
dwAttrib &= ~FILE_ATTRIBUTE_READONLY;
|
dwAttrib &= ~FILE_ATTRIBUTE_READONLY;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('S'):
|
case _T('S'):
|
||||||
dwMask |= FILE_ATTRIBUTE_SYSTEM;
|
dwMask |= FILE_ATTRIBUTE_SYSTEM;
|
||||||
dwAttrib &= ~FILE_ATTRIBUTE_SYSTEM;
|
dwAttrib &= ~FILE_ATTRIBUTE_SYSTEM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error_invalid_parameter_format (arg[i]);
|
error_invalid_parameter_format (arg[i]);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
{
|
{
|
||||||
DWORD len;
|
DWORD len;
|
||||||
|
|
||||||
len = GetCurrentDirectory (MAX_PATH, szPath);
|
len = GetCurrentDirectory (MAX_PATH, szPath);
|
||||||
if (szPath[len-1] != _T('\\'))
|
if (szPath[len-1] != _T('\\'))
|
||||||
{
|
{
|
||||||
szPath[len] = _T('\\');
|
szPath[len] = _T('\\');
|
||||||
szPath[len + 1] = 0;
|
szPath[len + 1] = 0;
|
||||||
}
|
}
|
||||||
_tcscpy (szFileName, _T("*.*"));
|
_tcscpy (szFileName, _T("*.*"));
|
||||||
PrintAttribute (szPath, szFileName, bRecurse);
|
PrintAttribute (szPath, szFileName, bRecurse);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get full file name */
|
/* get full file name */
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
if ((*arg[i] != _T('+')) && (*arg[i] != _T('-')) && (*arg[i] != _T('/')))
|
if ((*arg[i] != _T('+')) && (*arg[i] != _T('-')) && (*arg[i] != _T('/')))
|
||||||
{
|
{
|
||||||
LPTSTR p;
|
LPTSTR p;
|
||||||
GetFullPathName (arg[i], MAX_PATH, szPath, NULL);
|
GetFullPathName (arg[i], MAX_PATH, szPath, NULL);
|
||||||
p = _tcsrchr (szPath, _T('\\')) + 1;
|
p = _tcsrchr (szPath, _T('\\')) + 1;
|
||||||
_tcscpy (szFileName, p);
|
_tcscpy (szFileName, p);
|
||||||
*p = _T('\0');
|
*p = _T('\0');
|
||||||
|
|
||||||
if (dwMask == 0)
|
if (dwMask == 0)
|
||||||
PrintAttribute (szPath, szFileName, bRecurse);
|
PrintAttribute (szPath, szFileName, bRecurse);
|
||||||
else
|
else
|
||||||
ChangeAttribute (szPath, szFileName, dwMask,
|
ChangeAttribute (szPath, szFileName, dwMask,
|
||||||
dwAttrib, bRecurse, bDirectories);
|
dwAttrib, bRecurse, bDirectories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_ATTRIB */
|
#endif /* INCLUDE_CMD_ATTRIB */
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
* 20-Jan-1999 (Eric Kohl)
|
* 20-Jan-1999 (Eric Kohl)
|
||||||
* Redirection ready!
|
* Redirection ready!
|
||||||
*
|
*
|
||||||
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -31,19 +31,19 @@
|
||||||
|
|
||||||
INT cmd_beep (LPTSTR param)
|
INT cmd_beep (LPTSTR param)
|
||||||
{
|
{
|
||||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_BEEP_HELP);
|
ConOutResPaging(TRUE,STRING_BEEP_HELP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* check if run in batch mode */
|
/* check if run in batch mode */
|
||||||
if (bc == NULL)
|
if (bc == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
MessageBeep (-1);
|
MessageBeep (-1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
* 20-Jan-1999 (Eric Kohl)
|
* 20-Jan-1999 (Eric Kohl)
|
||||||
* Unicode and redirection safe!
|
* Unicode and redirection safe!
|
||||||
*
|
*
|
||||||
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -36,48 +36,48 @@
|
||||||
|
|
||||||
INT cmd_call (LPTSTR param)
|
INT cmd_call (LPTSTR param)
|
||||||
{
|
{
|
||||||
TCHAR line[CMDLINE_LENGTH + 1];
|
TCHAR line[CMDLINE_LENGTH + 1];
|
||||||
TCHAR *first;
|
TCHAR *first;
|
||||||
BOOL bInQuote = FALSE;
|
BOOL bInQuote = FALSE;
|
||||||
|
|
||||||
TRACE ("cmd_call: (\'%s\')\n", debugstr_aw(param));
|
TRACE ("cmd_call: (\'%s\')\n", debugstr_aw(param));
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_CALL_HELP);
|
ConOutResPaging(TRUE,STRING_CALL_HELP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do a second round of %-variable substitutions */
|
/* Do a second round of %-variable substitutions */
|
||||||
if (!SubstituteVars(param, line, _T('%')))
|
if (!SubstituteVars(param, line, _T('%')))
|
||||||
return nErrorLevel = 1;
|
return nErrorLevel = 1;
|
||||||
|
|
||||||
/* Find start and end of first word */
|
/* Find start and end of first word */
|
||||||
first = line;
|
first = line;
|
||||||
while (_istspace(*first))
|
while (_istspace(*first))
|
||||||
first++;
|
first++;
|
||||||
|
|
||||||
for (param = first; *param; param++)
|
for (param = first; *param; param++)
|
||||||
{
|
{
|
||||||
if (!bInQuote && (_istspace(*param) || _tcschr(_T(",;="), *param)))
|
if (!bInQuote && (_istspace(*param) || _tcschr(_T(",;="), *param)))
|
||||||
break;
|
break;
|
||||||
bInQuote ^= (*param == _T('"'));
|
bInQuote ^= (*param == _T('"'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Separate first word from rest of line */
|
/* Separate first word from rest of line */
|
||||||
memmove(param + 1, param, (_tcslen(param) + 1) * sizeof(TCHAR));
|
memmove(param + 1, param, (_tcslen(param) + 1) * sizeof(TCHAR));
|
||||||
*param++ = _T('\0');
|
*param++ = _T('\0');
|
||||||
|
|
||||||
if (*first == _T(':') && (bc))
|
if (*first == _T(':') && (bc))
|
||||||
{
|
{
|
||||||
/* CALL :label - call a subroutine of the current batch file */
|
/* CALL :label - call a subroutine of the current batch file */
|
||||||
while (*param == _T(' '))
|
while (*param == _T(' '))
|
||||||
param++;
|
param++;
|
||||||
nErrorLevel = Batch(bc->BatchFilePath, first, param, NULL);
|
nErrorLevel = Batch(bc->BatchFilePath, first, param, NULL);
|
||||||
return nErrorLevel;
|
return nErrorLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
nErrorLevel = DoCommand(first, param, NULL);
|
nErrorLevel = DoCommand(first, param, NULL);
|
||||||
return nErrorLevel;
|
return nErrorLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
* 23-Dec-1998 (Eric Kohl)
|
* 23-Dec-1998 (Eric Kohl)
|
||||||
* Started.
|
* Started.
|
||||||
*
|
*
|
||||||
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -17,64 +17,64 @@
|
||||||
|
|
||||||
INT CommandChcp (LPTSTR param)
|
INT CommandChcp (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR *arg;
|
LPTSTR *arg;
|
||||||
INT args;
|
INT args;
|
||||||
UINT uNewCodePage;
|
UINT uNewCodePage;
|
||||||
|
|
||||||
/* print help */
|
/* print help */
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_CHCP_HELP);
|
ConOutResPaging(TRUE,STRING_CHCP_HELP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
/* get parameters */
|
/* get parameters */
|
||||||
arg = split (param, &args, FALSE, FALSE);
|
arg = split (param, &args, FALSE, FALSE);
|
||||||
|
|
||||||
if (args == 0)
|
if (args == 0)
|
||||||
{
|
{
|
||||||
/* display active code page number */
|
/* display active code page number */
|
||||||
ConErrResPrintf(STRING_CHCP_ERROR1, InputCodePage);
|
ConErrResPrintf(STRING_CHCP_ERROR1, InputCodePage);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args >= 2)
|
if (args >= 2)
|
||||||
{
|
{
|
||||||
/* too many parameters */
|
/* too many parameters */
|
||||||
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, param);
|
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, param);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uNewCodePage = (UINT)_ttoi(arg[0]);
|
uNewCodePage = (UINT)_ttoi(arg[0]);
|
||||||
|
|
||||||
if (uNewCodePage == 0)
|
if (uNewCodePage == 0)
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, arg[0]);
|
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, arg[0]);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetConsoleCP(uNewCodePage))
|
if (!SetConsoleCP(uNewCodePage))
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_CHCP_ERROR4);
|
ConErrResPuts(STRING_CHCP_ERROR4);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
SetConsoleOutputCP (uNewCodePage);
|
SetConsoleOutputCP (uNewCodePage);
|
||||||
InitLocale ();
|
InitLocale ();
|
||||||
InputCodePage= GetConsoleCP();
|
InputCodePage= GetConsoleCP();
|
||||||
}
|
}
|
||||||
|
|
||||||
freep (arg);
|
freep (arg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_CHCP */
|
#endif /* INCLUDE_CMD_CHCP */
|
||||||
|
|
|
@ -13,9 +13,8 @@
|
||||||
* 26 Sep 1999 (Paolo Pantaleo)
|
* 26 Sep 1999 (Paolo Pantaleo)
|
||||||
* Fixed timeout.
|
* Fixed timeout.
|
||||||
*
|
*
|
||||||
* 02 Apr 2005 (Magnus Olsen
|
* 02 Apr 2005 (Magnus Olsen)
|
||||||
* Remove Hardcode string so
|
* Remove hardcoded strings so that they can be translated.
|
||||||
* they can be translate
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -24,9 +23,9 @@
|
||||||
#ifdef INCLUDE_CMD_CHOICE
|
#ifdef INCLUDE_CMD_CHOICE
|
||||||
|
|
||||||
|
|
||||||
#define GC_TIMEOUT -1
|
#define GC_TIMEOUT -1
|
||||||
#define GC_NOKEY 0 //an event occurred but it wasn't a key pressed
|
#define GC_NOKEY 0 //an event occurred but it wasn't a key pressed
|
||||||
#define GC_KEYREAD 1 //a key has been read
|
#define GC_KEYREAD 1 //a key has been read
|
||||||
|
|
||||||
|
|
||||||
static INT
|
static INT
|
||||||
|
@ -37,275 +36,275 @@ GetCharacterTimeout (LPTCH ch, DWORD dwMilliseconds)
|
||||||
// The function will wait a limited amount
|
// The function will wait a limited amount
|
||||||
// of time, then the function returns GC_TIMEOUT.
|
// of time, then the function returns GC_TIMEOUT.
|
||||||
//
|
//
|
||||||
// dwMilliseconds is the timeout value, that can
|
// dwMilliseconds is the timeout value, that can
|
||||||
// be set to INFINITE, so the function works like
|
// be set to INFINITE, so the function works like
|
||||||
// stdio.h's getchar()
|
// stdio.h's getchar()
|
||||||
|
|
||||||
HANDLE hInput;
|
HANDLE hInput;
|
||||||
DWORD dwRead;
|
DWORD dwRead;
|
||||||
|
|
||||||
INPUT_RECORD lpBuffer;
|
INPUT_RECORD lpBuffer;
|
||||||
|
|
||||||
hInput = GetStdHandle (STD_INPUT_HANDLE);
|
hInput = GetStdHandle (STD_INPUT_HANDLE);
|
||||||
|
|
||||||
//if the timeout experied return GC_TIMEOUT
|
//if the timeout experied return GC_TIMEOUT
|
||||||
if (WaitForSingleObject (hInput, dwMilliseconds) == WAIT_TIMEOUT)
|
if (WaitForSingleObject (hInput, dwMilliseconds) == WAIT_TIMEOUT)
|
||||||
return GC_TIMEOUT;
|
return GC_TIMEOUT;
|
||||||
|
|
||||||
//otherwise get the event
|
//otherwise get the event
|
||||||
ReadConsoleInput (hInput, &lpBuffer, 1, &dwRead);
|
ReadConsoleInput (hInput, &lpBuffer, 1, &dwRead);
|
||||||
|
|
||||||
//if the event is a key pressed
|
//if the event is a key pressed
|
||||||
if ((lpBuffer.EventType == KEY_EVENT) &&
|
if ((lpBuffer.EventType == KEY_EVENT) &&
|
||||||
(lpBuffer.Event.KeyEvent.bKeyDown == TRUE))
|
(lpBuffer.Event.KeyEvent.bKeyDown == TRUE))
|
||||||
{
|
{
|
||||||
//read the key
|
//read the key
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
*ch = lpBuffer.Event.KeyEvent.uChar.UnicodeChar;
|
*ch = lpBuffer.Event.KeyEvent.uChar.UnicodeChar;
|
||||||
#else
|
#else
|
||||||
*ch = lpBuffer.Event.KeyEvent.uChar.AsciiChar;
|
*ch = lpBuffer.Event.KeyEvent.uChar.AsciiChar;
|
||||||
#endif
|
#endif
|
||||||
return GC_KEYREAD;
|
return GC_KEYREAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
//else return no key
|
//else return no key
|
||||||
return GC_NOKEY;
|
return GC_NOKEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INT
|
static INT
|
||||||
IsKeyInString (LPTSTR lpString, TCHAR cKey, BOOL bCaseSensitive)
|
IsKeyInString (LPTSTR lpString, TCHAR cKey, BOOL bCaseSensitive)
|
||||||
{
|
{
|
||||||
LPTCH p = lpString;
|
LPTCH p = lpString;
|
||||||
INT val = 0;
|
INT val = 0;
|
||||||
|
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
if (bCaseSensitive)
|
if (bCaseSensitive)
|
||||||
{
|
{
|
||||||
if (*p == cKey)
|
if (*p == cKey)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_totlower (*p) == _totlower (cKey))
|
if (_totlower (*p) == _totlower (cKey))
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
val++;
|
val++;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INT
|
INT
|
||||||
CommandChoice (LPTSTR param)
|
CommandChoice (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR lpOptions;
|
LPTSTR lpOptions;
|
||||||
TCHAR Options[6];
|
TCHAR Options[6];
|
||||||
LPTSTR lpText = NULL;
|
LPTSTR lpText = NULL;
|
||||||
BOOL bNoPrompt = FALSE;
|
BOOL bNoPrompt = FALSE;
|
||||||
BOOL bCaseSensitive = FALSE;
|
BOOL bCaseSensitive = FALSE;
|
||||||
BOOL bTimeout = FALSE;
|
BOOL bTimeout = FALSE;
|
||||||
INT nTimeout = 0;
|
INT nTimeout = 0;
|
||||||
TCHAR cDefault = _T('\0');
|
TCHAR cDefault = _T('\0');
|
||||||
INPUT_RECORD ir;
|
INPUT_RECORD ir;
|
||||||
LPTSTR p, np;
|
LPTSTR p, np;
|
||||||
LPTSTR *arg;
|
LPTSTR *arg;
|
||||||
INT argc;
|
INT argc;
|
||||||
INT i;
|
INT i;
|
||||||
INT val;
|
INT val;
|
||||||
|
|
||||||
INT GCret;
|
INT GCret;
|
||||||
TCHAR Ch;
|
TCHAR Ch;
|
||||||
DWORD amount,clk;
|
DWORD amount,clk;
|
||||||
|
|
||||||
LoadString(CMD_ModuleHandle, STRING_CHOICE_OPTION, Options, 4);
|
LoadString(CMD_ModuleHandle, STRING_CHOICE_OPTION, Options, 4);
|
||||||
lpOptions = Options;
|
lpOptions = Options;
|
||||||
|
|
||||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_CHOICE_HELP);
|
ConOutResPaging(TRUE,STRING_CHOICE_HELP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* retrieve text */
|
/* retrieve text */
|
||||||
p = param;
|
p = param;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
if (*p == _T('\0'))
|
if (*p == _T('\0'))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (*p != _T('/'))
|
if (*p != _T('/'))
|
||||||
{
|
{
|
||||||
lpText = p;
|
lpText = p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
np = _tcschr (p, _T(' '));
|
np = _tcschr (p, _T(' '));
|
||||||
if (!np)
|
if (!np)
|
||||||
break;
|
break;
|
||||||
p = np + 1;
|
p = np + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* build parameter array */
|
/* build parameter array */
|
||||||
arg = split (param, &argc, FALSE, FALSE);
|
arg = split (param, &argc, FALSE, FALSE);
|
||||||
|
|
||||||
/* evaluate arguments */
|
/* evaluate arguments */
|
||||||
if (argc > 0)
|
if (argc > 0)
|
||||||
{
|
{
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (_tcsnicmp (arg[i], _T("/c"), 2) == 0)
|
if (_tcsnicmp (arg[i], _T("/c"), 2) == 0)
|
||||||
{
|
{
|
||||||
if (arg[i][2] == _T(':'))
|
if (arg[i][2] == _T(':'))
|
||||||
lpOptions = &arg[i][3];
|
lpOptions = &arg[i][3];
|
||||||
else
|
else
|
||||||
lpOptions = &arg[i][2];
|
lpOptions = &arg[i][2];
|
||||||
|
|
||||||
if (_tcslen (lpOptions) == 0)
|
if (_tcslen (lpOptions) == 0)
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_CHOICE_ERROR);
|
ConErrResPuts(STRING_CHOICE_ERROR);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp (arg[i], _T("/n"), 2) == 0)
|
else if (_tcsnicmp (arg[i], _T("/n"), 2) == 0)
|
||||||
{
|
{
|
||||||
bNoPrompt = TRUE;
|
bNoPrompt = TRUE;
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp (arg[i], _T("/s"), 2) == 0)
|
else if (_tcsnicmp (arg[i], _T("/s"), 2) == 0)
|
||||||
{
|
{
|
||||||
bCaseSensitive = TRUE;
|
bCaseSensitive = TRUE;
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp (arg[i], _T("/t"), 2) == 0)
|
else if (_tcsnicmp (arg[i], _T("/t"), 2) == 0)
|
||||||
{
|
{
|
||||||
LPTSTR s;
|
LPTSTR s;
|
||||||
|
|
||||||
if (arg[i][2] == _T(':'))
|
if (arg[i][2] == _T(':'))
|
||||||
{
|
{
|
||||||
cDefault = arg[i][3];
|
cDefault = arg[i][3];
|
||||||
s = &arg[i][4];
|
s = &arg[i][4];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cDefault = arg[i][2];
|
cDefault = arg[i][2];
|
||||||
s = &arg[i][3];
|
s = &arg[i][3];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*s != _T(','))
|
if (*s != _T(','))
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_CHOICE_ERROR_TXT);
|
ConErrResPuts(STRING_CHOICE_ERROR_TXT);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s++;
|
s++;
|
||||||
nTimeout = _ttoi(s);
|
nTimeout = _ttoi(s);
|
||||||
bTimeout = TRUE;
|
bTimeout = TRUE;
|
||||||
}
|
}
|
||||||
else if (arg[i][0] == _T('/'))
|
else if (arg[i][0] == _T('/'))
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_CHOICE_ERROR_OPTION, arg[i]);
|
ConErrResPrintf(STRING_CHOICE_ERROR_OPTION, arg[i]);
|
||||||
freep (arg);
|
freep (arg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print text */
|
/* print text */
|
||||||
if (lpText)
|
if (lpText)
|
||||||
ConOutPrintf (_T("%s"), lpText);
|
ConOutPrintf (_T("%s"), lpText);
|
||||||
|
|
||||||
/* print options */
|
/* print options */
|
||||||
if (bNoPrompt == FALSE)
|
if (bNoPrompt == FALSE)
|
||||||
{
|
{
|
||||||
ConOutPrintf (_T("[%c"), lpOptions[0]);
|
ConOutPrintf (_T("[%c"), lpOptions[0]);
|
||||||
|
|
||||||
for (i = 1; (unsigned)i < _tcslen (lpOptions); i++)
|
for (i = 1; (unsigned)i < _tcslen (lpOptions); i++)
|
||||||
ConOutPrintf (_T(",%c"), lpOptions[i]);
|
ConOutPrintf (_T(",%c"), lpOptions[i]);
|
||||||
|
|
||||||
ConOutPrintf (_T("]?"));
|
ConOutPrintf (_T("]?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConInFlush ();
|
ConInFlush ();
|
||||||
|
|
||||||
if(!bTimeout)
|
if(!bTimeout)
|
||||||
{
|
{
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
ConInKey (&ir);
|
ConInKey (&ir);
|
||||||
|
|
||||||
val = IsKeyInString (lpOptions,
|
val = IsKeyInString (lpOptions,
|
||||||
#ifdef _UNICODE
|
#ifdef _UNICODE
|
||||||
ir.Event.KeyEvent.uChar.UnicodeChar,
|
ir.Event.KeyEvent.uChar.UnicodeChar,
|
||||||
#else
|
#else
|
||||||
ir.Event.KeyEvent.uChar.AsciiChar,
|
ir.Event.KeyEvent.uChar.AsciiChar,
|
||||||
#endif
|
#endif
|
||||||
bCaseSensitive);
|
bCaseSensitive);
|
||||||
|
|
||||||
if (val >= 0)
|
if (val >= 0)
|
||||||
{
|
{
|
||||||
ConOutPrintf (_T("%c\n"), lpOptions[val]);
|
ConOutPrintf (_T("%c\n"), lpOptions[val]);
|
||||||
|
|
||||||
nErrorLevel = val + 1;
|
nErrorLevel = val + 1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Beep (440, 50);
|
Beep (440, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
freep (arg);
|
freep (arg);
|
||||||
TRACE ("ErrorLevel: %d\n", nErrorLevel);
|
TRACE ("ErrorLevel: %d\n", nErrorLevel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
clk = GetTickCount ();
|
clk = GetTickCount ();
|
||||||
amount = nTimeout*1000;
|
amount = nTimeout*1000;
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
GCret = GetCharacterTimeout (&Ch, amount - (GetTickCount () - clk));
|
GCret = GetCharacterTimeout (&Ch, amount - (GetTickCount () - clk));
|
||||||
|
|
||||||
switch (GCret)
|
switch (GCret)
|
||||||
{
|
{
|
||||||
case GC_TIMEOUT:
|
case GC_TIMEOUT:
|
||||||
TRACE ("GC_TIMEOUT\n");
|
TRACE ("GC_TIMEOUT\n");
|
||||||
TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
|
TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GC_NOKEY:
|
case GC_NOKEY:
|
||||||
TRACE ("GC_NOKEY\n");
|
TRACE ("GC_NOKEY\n");
|
||||||
TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
|
TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
|
||||||
goto loop;
|
goto loop;
|
||||||
|
|
||||||
case GC_KEYREAD:
|
case GC_KEYREAD:
|
||||||
TRACE ("GC_KEYREAD\n");
|
TRACE ("GC_KEYREAD\n");
|
||||||
TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
|
TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
|
||||||
TRACE ("read %c", Ch);
|
TRACE ("read %c", Ch);
|
||||||
if ((val=IsKeyInString(lpOptions,Ch,bCaseSensitive))==-1)
|
if ((val=IsKeyInString(lpOptions,Ch,bCaseSensitive))==-1)
|
||||||
{
|
{
|
||||||
Beep (440, 50);
|
Beep (440, 50);
|
||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
cDefault=Ch;
|
cDefault=Ch;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACE ("exiting wait loop after %d msecs\n",
|
TRACE ("exiting wait loop after %d msecs\n",
|
||||||
GetTickCount () - clk);
|
GetTickCount () - clk);
|
||||||
|
|
||||||
val = IsKeyInString (lpOptions, cDefault, bCaseSensitive);
|
val = IsKeyInString (lpOptions, cDefault, bCaseSensitive);
|
||||||
ConOutPrintf (_T("%c\n"), lpOptions[val]);
|
ConOutPrintf (_T("%c\n"), lpOptions[val]);
|
||||||
|
|
||||||
nErrorLevel = val + 1;
|
nErrorLevel = val + 1;
|
||||||
|
|
||||||
freep (arg);
|
freep (arg);
|
||||||
|
|
||||||
TRACE ("ErrorLevel: %d\n", nErrorLevel);
|
TRACE ("ErrorLevel: %d\n", nErrorLevel);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* INCLUDE_CMD_CHOICE */
|
#endif /* INCLUDE_CMD_CHOICE */
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
* 20-Jan-1998 (Eric Kohl)
|
* 20-Jan-1998 (Eric Kohl)
|
||||||
* Redirection ready!
|
* Redirection ready!
|
||||||
*
|
*
|
||||||
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -32,34 +32,34 @@
|
||||||
|
|
||||||
INT cmd_cls (LPTSTR param)
|
INT cmd_cls (LPTSTR param)
|
||||||
{
|
{
|
||||||
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
COORD coPos;
|
COORD coPos;
|
||||||
DWORD dwWritten;
|
DWORD dwWritten;
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_CLS_HELP);
|
ConOutResPaging(TRUE,STRING_CLS_HELP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetConsoleScreenBufferInfo(hOutput, &csbi))
|
if (GetConsoleScreenBufferInfo(hOutput, &csbi))
|
||||||
{
|
{
|
||||||
coPos.X = 0;
|
coPos.X = 0;
|
||||||
coPos.Y = 0;
|
coPos.Y = 0;
|
||||||
FillConsoleOutputAttribute(hOutput, csbi.wAttributes,
|
FillConsoleOutputAttribute(hOutput, csbi.wAttributes,
|
||||||
csbi.dwSize.X * csbi.dwSize.Y,
|
csbi.dwSize.X * csbi.dwSize.Y,
|
||||||
coPos, &dwWritten);
|
coPos, &dwWritten);
|
||||||
FillConsoleOutputCharacter(hOutput, _T(' '),
|
FillConsoleOutputCharacter(hOutput, _T(' '),
|
||||||
csbi.dwSize.X * csbi.dwSize.Y,
|
csbi.dwSize.X * csbi.dwSize.Y,
|
||||||
coPos, &dwWritten);
|
coPos, &dwWritten);
|
||||||
SetConsoleCursorPosition(hOutput, coPos);
|
SetConsoleCursorPosition(hOutput, coPos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConOutChar(_T('\f'));
|
ConOutChar(_T('\f'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,263 +19,265 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
/* a list of all the internal commands, associating their command names */
|
/*
|
||||||
/* to the functions to process them */
|
* A list of all the internal commands, associating their command names
|
||||||
|
* to the functions to process them.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
COMMAND cmds[] =
|
COMMAND cmds[] =
|
||||||
{
|
{
|
||||||
{_T("?"), 0, CommandShowCommands},
|
{_T("?"), 0, CommandShowCommands},
|
||||||
|
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_ACTIVATE
|
#ifdef INCLUDE_CMD_ACTIVATE
|
||||||
{_T("activate"), 0, CommandActivate},
|
{_T("activate"), 0, CommandActivate},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_ALIASES
|
#ifdef FEATURE_ALIASES
|
||||||
{_T("alias"), 0, CommandAlias},
|
{_T("alias"), 0, CommandAlias},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_ASSOC
|
#ifdef INCLUDE_CMD_ASSOC
|
||||||
{_T("assoc"), 0, CommandAssoc},
|
{_T("assoc"), 0, CommandAssoc},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_ATTRIB
|
#ifdef INCLUDE_CMD_ATTRIB
|
||||||
{_T("attrib"), 0, CommandAttrib},
|
{_T("attrib"), 0, CommandAttrib},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_BEEP
|
#ifdef INCLUDE_CMD_BEEP
|
||||||
{_T("beep"), 0, cmd_beep},
|
{_T("beep"), 0, cmd_beep},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{_T("call"), CMD_BATCHONLY, cmd_call},
|
{_T("call"), CMD_BATCHONLY, cmd_call},
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_CHDIR
|
#ifdef INCLUDE_CMD_CHDIR
|
||||||
{_T("cd"), CMD_SPECIAL, cmd_chdir},
|
{_T("cd"), CMD_SPECIAL, cmd_chdir},
|
||||||
{_T("chdir"), CMD_SPECIAL, cmd_chdir},
|
{_T("chdir"), CMD_SPECIAL, cmd_chdir},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_CHCP
|
#ifdef INCLUDE_CMD_CHCP
|
||||||
{_T("chcp"), 0, CommandChcp},
|
{_T("chcp"), 0, CommandChcp},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_CHOICE
|
#ifdef INCLUDE_CMD_CHOICE
|
||||||
{_T("choice"), 0, CommandChoice},
|
{_T("choice"), 0, CommandChoice},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_CLS
|
#ifdef INCLUDE_CMD_CLS
|
||||||
{_T("cls"), 0, cmd_cls},
|
{_T("cls"), 0, cmd_cls},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_COLOR
|
#ifdef INCLUDE_CMD_COLOR
|
||||||
{_T("color"), 0, CommandColor},
|
{_T("color"), 0, CommandColor},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_COPY
|
#ifdef INCLUDE_CMD_COPY
|
||||||
{_T("copy"), 0, cmd_copy},
|
{_T("copy"), 0, cmd_copy},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_DATE
|
#ifdef INCLUDE_CMD_DATE
|
||||||
{_T("date"), 0, cmd_date},
|
{_T("date"), 0, cmd_date},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_DEL
|
#ifdef INCLUDE_CMD_DEL
|
||||||
{_T("del"), 0, CommandDelete},
|
{_T("del"), 0, CommandDelete},
|
||||||
{_T("delete"), 0, CommandDelete},
|
{_T("delete"), 0, CommandDelete},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_DELAY
|
#ifdef INCLUDE_CMD_DELAY
|
||||||
{_T("delay"), 0, CommandDelay},
|
{_T("delay"), 0, CommandDelay},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_DIR
|
#ifdef INCLUDE_CMD_DIR
|
||||||
{_T("dir"), CMD_SPECIAL, CommandDir},
|
{_T("dir"), CMD_SPECIAL, CommandDir},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_DIRECTORY_STACK
|
#ifdef FEATURE_DIRECTORY_STACK
|
||||||
{_T("dirs"), 0, CommandDirs},
|
{_T("dirs"), 0, CommandDirs},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{_T("echo"), CMD_SPECIAL, CommandEcho},
|
{_T("echo"), CMD_SPECIAL, CommandEcho},
|
||||||
{_T("echos"), 0, CommandEchos},
|
{_T("echos"), 0, CommandEchos},
|
||||||
{_T("echoerr"), CMD_SPECIAL, CommandEchoerr},
|
{_T("echoerr"), CMD_SPECIAL, CommandEchoerr},
|
||||||
{_T("echoserr"), 0, CommandEchoserr},
|
{_T("echoserr"), 0, CommandEchoserr},
|
||||||
|
|
||||||
{_T("endlocal"), 0, cmd_endlocal},
|
{_T("endlocal"), 0, cmd_endlocal},
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_DEL
|
#ifdef INCLUDE_CMD_DEL
|
||||||
{_T("erase"), 0, CommandDelete},
|
{_T("erase"), 0, CommandDelete},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{_T("exit"), 0, CommandExit},
|
{_T("exit"), 0, CommandExit},
|
||||||
|
|
||||||
{_T("for"), 0, cmd_for},
|
{_T("for"), 0, cmd_for},
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_FREE
|
#ifdef INCLUDE_CMD_FREE
|
||||||
{_T("free"), 0, CommandFree},
|
{_T("free"), 0, CommandFree},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{_T("goto"), CMD_BATCHONLY, cmd_goto},
|
{_T("goto"), CMD_BATCHONLY, cmd_goto},
|
||||||
|
|
||||||
{_T("help"), 0, CommandShowCommandsDetail},
|
{_T("help"), 0, CommandShowCommandsDetail},
|
||||||
|
|
||||||
#ifdef FEATURE_HISTORY
|
#ifdef FEATURE_HISTORY
|
||||||
{_T("history"), 0, CommandHistory},
|
{_T("history"), 0, CommandHistory},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{_T("if"), 0, cmd_if},
|
{_T("if"), 0, cmd_if},
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_LABEL
|
#ifdef INCLUDE_CMD_LABEL
|
||||||
{_T("label"), 0, cmd_label},
|
{_T("label"), 0, cmd_label},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_MEMORY
|
#ifdef INCLUDE_CMD_MEMORY
|
||||||
{_T("memory"), 0, CommandMemory},
|
{_T("memory"), 0, CommandMemory},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_MKDIR
|
#ifdef INCLUDE_CMD_MKDIR
|
||||||
{_T("md"), CMD_SPECIAL, cmd_mkdir},
|
{_T("md"), CMD_SPECIAL, cmd_mkdir},
|
||||||
{_T("mkdir"), CMD_SPECIAL, cmd_mkdir},
|
{_T("mkdir"), CMD_SPECIAL, cmd_mkdir},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_MKLINK
|
#ifdef INCLUDE_CMD_MKLINK
|
||||||
{_T("mklink"), 0, cmd_mklink},
|
{_T("mklink"), 0, cmd_mklink},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_MOVE
|
#ifdef INCLUDE_CMD_MOVE
|
||||||
{_T("move"), 0, cmd_move},
|
{_T("move"), 0, cmd_move},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_MSGBOX
|
#ifdef INCLUDE_CMD_MSGBOX
|
||||||
{_T("msgbox"), 0, CommandMsgbox},
|
{_T("msgbox"), 0, CommandMsgbox},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_PATH
|
#ifdef INCLUDE_CMD_PATH
|
||||||
{_T("path"), 0, cmd_path},
|
{_T("path"), 0, cmd_path},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_PAUSE
|
#ifdef INCLUDE_CMD_PAUSE
|
||||||
{_T("pause"), 0, cmd_pause},
|
{_T("pause"), 0, cmd_pause},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_DIRECTORY_STACK
|
#ifdef FEATURE_DIRECTORY_STACK
|
||||||
{_T("popd"), 0, CommandPopd},
|
{_T("popd"), 0, CommandPopd},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_PROMPT
|
#ifdef INCLUDE_CMD_PROMPT
|
||||||
{_T("prompt"), 0, cmd_prompt},
|
{_T("prompt"), 0, cmd_prompt},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_DIRECTORY_STACK
|
#ifdef FEATURE_DIRECTORY_STACK
|
||||||
{_T("pushd"), 0, CommandPushd},
|
{_T("pushd"), 0, CommandPushd},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_RMDIR
|
#ifdef INCLUDE_CMD_RMDIR
|
||||||
{_T("rd"), CMD_SPECIAL, cmd_rmdir},
|
{_T("rd"), CMD_SPECIAL, cmd_rmdir},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_REM
|
#ifdef INCLUDE_CMD_REM
|
||||||
{_T("rem"), 0, CommandRem},
|
{_T("rem"), 0, CommandRem},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_RENAME
|
#ifdef INCLUDE_CMD_RENAME
|
||||||
{_T("ren"), 0, cmd_rename},
|
{_T("ren"), 0, cmd_rename},
|
||||||
{_T("rename"), 0, cmd_rename},
|
{_T("rename"), 0, cmd_rename},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_REPLACE
|
#ifdef INCLUDE_CMD_REPLACE
|
||||||
{_T("replace"), 0, cmd_replace},
|
{_T("replace"), 0, cmd_replace},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_RMDIR
|
#ifdef INCLUDE_CMD_RMDIR
|
||||||
{_T("rmdir"), CMD_SPECIAL, cmd_rmdir},
|
{_T("rmdir"), CMD_SPECIAL, cmd_rmdir},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_SCREEN
|
#ifdef INCLUDE_CMD_SCREEN
|
||||||
{_T("screen"), 0, CommandScreen},
|
{_T("screen"), 0, CommandScreen},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_SET
|
#ifdef INCLUDE_CMD_SET
|
||||||
{_T("set"), 0, cmd_set},
|
{_T("set"), 0, cmd_set},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{_T("setlocal"), 0, cmd_setlocal},
|
{_T("setlocal"), 0, cmd_setlocal},
|
||||||
|
|
||||||
{_T("shift"), CMD_BATCHONLY, cmd_shift},
|
{_T("shift"), CMD_BATCHONLY, cmd_shift},
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_START
|
#ifdef INCLUDE_CMD_START
|
||||||
{_T("start"), 0, cmd_start},
|
{_T("start"), 0, cmd_start},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_TIME
|
#ifdef INCLUDE_CMD_TIME
|
||||||
{_T("time"), 0, cmd_time},
|
{_T("time"), 0, cmd_time},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_TIMER
|
#ifdef INCLUDE_CMD_TIMER
|
||||||
{_T("timer"), 0, CommandTimer},
|
{_T("timer"), 0, CommandTimer},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_TITLE
|
#ifdef INCLUDE_CMD_TITLE
|
||||||
{_T("title"), 0, cmd_title},
|
{_T("title"), 0, cmd_title},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_TYPE
|
#ifdef INCLUDE_CMD_TYPE
|
||||||
{_T("type"), 0, cmd_type},
|
{_T("type"), 0, cmd_type},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_VER
|
#ifdef INCLUDE_CMD_VER
|
||||||
{_T("ver"), 0, cmd_ver},
|
{_T("ver"), 0, cmd_ver},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_VERIFY
|
#ifdef INCLUDE_CMD_VERIFY
|
||||||
{_T("verify"), 0, cmd_verify},
|
{_T("verify"), 0, cmd_verify},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_VOL
|
#ifdef INCLUDE_CMD_VOL
|
||||||
{_T("vol"), 0, cmd_vol},
|
{_T("vol"), 0, cmd_vol},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CMD_WINDOW
|
#ifdef INCLUDE_CMD_WINDOW
|
||||||
{_T("window"), 0, CommandWindow},
|
{_T("window"), 0, CommandWindow},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{NULL, 0, NULL}
|
{NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
VOID PrintCommandList (VOID)
|
VOID PrintCommandList (VOID)
|
||||||
{
|
{
|
||||||
LPCOMMAND cmdptr;
|
LPCOMMAND cmdptr;
|
||||||
INT y;
|
INT y;
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
cmdptr = cmds;
|
cmdptr = cmds;
|
||||||
while (cmdptr->name)
|
while (cmdptr->name)
|
||||||
{
|
{
|
||||||
if (!(cmdptr->flags & CMD_HIDE))
|
if (!(cmdptr->flags & CMD_HIDE))
|
||||||
{
|
{
|
||||||
if (++y == 8)
|
if (++y == 8)
|
||||||
{
|
{
|
||||||
ConOutPuts (cmdptr->name);
|
ConOutPuts (cmdptr->name);
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConOutPrintf (_T("%-10s"), cmdptr->name);
|
ConOutPrintf (_T("%-10s"), cmdptr->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdptr++;
|
cmdptr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y != 0)
|
if (y != 0)
|
||||||
ConOutChar ('\n');
|
ConOutChar ('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID PrintCommandListDetail (VOID)
|
VOID PrintCommandListDetail (VOID)
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_HELP1);
|
ConOutResPaging(TRUE,STRING_HELP1);
|
||||||
ConOutResPaging(FALSE,STRING_HELP2);
|
ConOutResPaging(FALSE,STRING_HELP2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
* 14-Oct-1999 (Paolo Pantaleo <paolopan@freemail.it>)
|
* 14-Oct-1999 (Paolo Pantaleo <paolopan@freemail.it>)
|
||||||
* 4nt's syntax implemented.
|
* 4nt's syntax implemented.
|
||||||
*
|
*
|
||||||
* 03-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 03-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Move all hardcoded strings to En.rc.
|
* Move all hardcoded strings in En.rc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -26,32 +26,32 @@
|
||||||
|
|
||||||
BOOL SetScreenColor(WORD wColor, BOOL bNoFill)
|
BOOL SetScreenColor(WORD wColor, BOOL bNoFill)
|
||||||
{
|
{
|
||||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
DWORD dwWritten;
|
DWORD dwWritten;
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||||
COORD coPos;
|
COORD coPos;
|
||||||
|
|
||||||
/* Foreground and Background colors can't be the same */
|
/* Foreground and Background colors can't be the same */
|
||||||
if ((wColor & 0x0F) == (wColor & 0xF0) >> 4)
|
if ((wColor & 0x0F) == (wColor & 0xF0) >> 4)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Fill the whole background if needed */
|
/* Fill the whole background if needed */
|
||||||
if (bNoFill != TRUE)
|
if (bNoFill != TRUE)
|
||||||
{
|
{
|
||||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||||
|
|
||||||
coPos.X = 0;
|
coPos.X = 0;
|
||||||
coPos.Y = 0;
|
coPos.Y = 0;
|
||||||
FillConsoleOutputAttribute(hConsole,
|
FillConsoleOutputAttribute(hConsole,
|
||||||
wColor & 0x00FF,
|
wColor & 0x00FF,
|
||||||
csbi.dwSize.X * csbi.dwSize.Y,
|
csbi.dwSize.X * csbi.dwSize.Y,
|
||||||
coPos,
|
coPos,
|
||||||
&dwWritten);
|
&dwWritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the text attribute */
|
/* Set the text attribute */
|
||||||
SetConsoleTextAttribute(hConsole, wColor & 0x00FF);
|
SetConsoleTextAttribute(hConsole, wColor & 0x00FF);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -61,76 +61,76 @@ BOOL SetScreenColor(WORD wColor, BOOL bNoFill)
|
||||||
*/
|
*/
|
||||||
INT CommandColor(LPTSTR rest)
|
INT CommandColor(LPTSTR rest)
|
||||||
{
|
{
|
||||||
WORD wColor = 0x00;
|
WORD wColor = 0x00;
|
||||||
|
|
||||||
/* The user asked for help */
|
/* The user asked for help */
|
||||||
if (_tcsncmp(rest, _T("/?"), 2) == 0)
|
if (_tcsncmp(rest, _T("/?"), 2) == 0)
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE, STRING_COLOR_HELP1);
|
ConOutResPaging(TRUE, STRING_COLOR_HELP1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Let's prepare %ERRORLEVEL% */
|
/* Let's prepare %ERRORLEVEL% */
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
/* No parameter. Set the default colors */
|
/* No parameter. Set the default colors */
|
||||||
if (rest[0] == _T('\0'))
|
if (rest[0] == _T('\0'))
|
||||||
{
|
{
|
||||||
SetScreenColor(wDefColor, FALSE);
|
SetScreenColor(wDefColor, FALSE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The parameter is just one character: Set color text */
|
/* The parameter is just one character: Set color text */
|
||||||
if (_tcslen(rest) == 1)
|
if (_tcslen(rest) == 1)
|
||||||
{
|
{
|
||||||
if ((rest[0] >= _T('0')) && (rest[0] <= _T('9')))
|
if ((rest[0] >= _T('0')) && (rest[0] <= _T('9')))
|
||||||
{
|
{
|
||||||
wColor = (WORD)_ttoi(rest);
|
wColor = (WORD)_ttoi(rest);
|
||||||
}
|
}
|
||||||
else if ((rest[0] >= _T('a')) && (rest[0] <= _T('f')))
|
else if ((rest[0] >= _T('a')) && (rest[0] <= _T('f')))
|
||||||
{
|
{
|
||||||
wColor = (WORD)(rest[0] + 10 - _T('a'));
|
wColor = (WORD)(rest[0] + 10 - _T('a'));
|
||||||
}
|
}
|
||||||
else if ((rest[0] >= _T('A')) && (rest[0] <= _T('F')))
|
else if ((rest[0] >= _T('A')) && (rest[0] <= _T('F')))
|
||||||
{
|
{
|
||||||
wColor = (WORD)(rest[0] + 10 - _T('A'));
|
wColor = (WORD)(rest[0] + 10 - _T('A'));
|
||||||
}
|
}
|
||||||
else /* Invalid character */
|
else /* Invalid character */
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE, STRING_COLOR_HELP1);
|
ConOutResPaging(TRUE, STRING_COLOR_HELP1);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Color string: advanced choice: two-digits, "Color ON Color" , "Foreground ON Background" */
|
/* Color string: advanced choice: two-digits, "Color ON Color" , "Foreground ON Background" */
|
||||||
else if (StringToColor(&wColor, &rest) == FALSE)
|
else if (StringToColor(&wColor, &rest) == FALSE)
|
||||||
{
|
{
|
||||||
/* Invalid color string */
|
/* Invalid color string */
|
||||||
ConOutResPaging(TRUE, STRING_COLOR_HELP1);
|
ConOutResPaging(TRUE, STRING_COLOR_HELP1);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print the chosen color if we are in echo mode (NOTE: Not Windows-compliant) */
|
/* Print the chosen color if we are in echo mode (NOTE: Not Windows-compliant) */
|
||||||
if ((bc && bc->bEcho) || !bc)
|
if ((bc && bc->bEcho) || !bc)
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_COLOR_ERROR3, wColor);
|
ConErrResPrintf(STRING_COLOR_ERROR3, wColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the chosen color. Use also the following advanced flag:
|
* Set the chosen color. Use also the following advanced flag:
|
||||||
* /-F to avoid changing already buffered foreground/background.
|
* /-F to avoid changing already buffered foreground/background.
|
||||||
*/
|
*/
|
||||||
if (SetScreenColor(wColor, (_tcsstr(rest, _T("/-F")) || _tcsstr(rest, _T("/-f")))) == FALSE)
|
if (SetScreenColor(wColor, (_tcsstr(rest, _T("/-F")) || _tcsstr(rest, _T("/-f")))) == FALSE)
|
||||||
{
|
{
|
||||||
/* Failed because foreground and background colors were the same */
|
/* Failed because foreground and background colors were the same */
|
||||||
ConErrResPuts(STRING_COLOR_ERROR1);
|
ConErrResPuts(STRING_COLOR_ERROR1);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return success */
|
/* Return success */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_COLOR */
|
#endif /* INCLUDE_CMD_COLOR */
|
||||||
|
|
|
@ -16,33 +16,33 @@
|
||||||
|
|
||||||
INT CommandDelay (LPTSTR param)
|
INT CommandDelay (LPTSTR param)
|
||||||
{
|
{
|
||||||
DWORD val;
|
DWORD val;
|
||||||
DWORD mul=1000;
|
DWORD mul=1000;
|
||||||
|
|
||||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_DELAY_HELP);
|
ConOutResPaging(TRUE,STRING_DELAY_HELP);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
if (*param==0)
|
if (*param==0)
|
||||||
{
|
{
|
||||||
error_req_param_missing ();
|
error_req_param_missing ();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_tcsnicmp(param,_T("/m"),2) == 0)
|
if (_tcsnicmp(param,_T("/m"),2) == 0)
|
||||||
{
|
{
|
||||||
mul = 1;
|
mul = 1;
|
||||||
param += 2;
|
param += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
val = _ttoi(param);
|
val = _ttoi(param);
|
||||||
Sleep(val * mul);
|
Sleep(val * mul);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_DELAY */
|
#endif /* INCLUDE_CMD_DELAY */
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
|
|
||||||
typedef struct tagDIRENTRY
|
typedef struct tagDIRENTRY
|
||||||
{
|
{
|
||||||
struct tagDIRENTRY *prev;
|
struct tagDIRENTRY *prev;
|
||||||
struct tagDIRENTRY *next;
|
struct tagDIRENTRY *next;
|
||||||
TCHAR szPath[1];
|
TCHAR szPath[1];
|
||||||
} DIRENTRY, *LPDIRENTRY;
|
} DIRENTRY, *LPDIRENTRY;
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,42 +34,42 @@ static LPDIRENTRY lpStackBottom;
|
||||||
static INT
|
static INT
|
||||||
PushDirectory (LPTSTR pszPath)
|
PushDirectory (LPTSTR pszPath)
|
||||||
{
|
{
|
||||||
LPDIRENTRY lpDir = cmd_alloc(FIELD_OFFSET(DIRENTRY, szPath[_tcslen(pszPath) + 1]));
|
LPDIRENTRY lpDir = cmd_alloc(FIELD_OFFSET(DIRENTRY, szPath[_tcslen(pszPath) + 1]));
|
||||||
if (!lpDir)
|
if (!lpDir)
|
||||||
{
|
{
|
||||||
error_out_of_memory ();
|
error_out_of_memory ();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lpDir->prev = NULL;
|
lpDir->prev = NULL;
|
||||||
lpDir->next = lpStackTop;
|
lpDir->next = lpStackTop;
|
||||||
if (lpStackTop == NULL)
|
if (lpStackTop == NULL)
|
||||||
lpStackBottom = lpDir;
|
lpStackBottom = lpDir;
|
||||||
else
|
else
|
||||||
lpStackTop->prev = lpDir;
|
lpStackTop->prev = lpDir;
|
||||||
lpStackTop = lpDir;
|
lpStackTop = lpDir;
|
||||||
|
|
||||||
_tcscpy(lpDir->szPath, pszPath);
|
_tcscpy(lpDir->szPath, pszPath);
|
||||||
|
|
||||||
nStackDepth++;
|
nStackDepth++;
|
||||||
|
|
||||||
return nErrorLevel = 0;
|
return nErrorLevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static VOID
|
static VOID
|
||||||
PopDirectory (VOID)
|
PopDirectory (VOID)
|
||||||
{
|
{
|
||||||
LPDIRENTRY lpDir = lpStackTop;
|
LPDIRENTRY lpDir = lpStackTop;
|
||||||
lpStackTop = lpDir->next;
|
lpStackTop = lpDir->next;
|
||||||
if (lpStackTop != NULL)
|
if (lpStackTop != NULL)
|
||||||
lpStackTop->prev = NULL;
|
lpStackTop->prev = NULL;
|
||||||
else
|
else
|
||||||
lpStackBottom = NULL;
|
lpStackBottom = NULL;
|
||||||
|
|
||||||
cmd_free (lpDir);
|
cmd_free (lpDir);
|
||||||
|
|
||||||
nStackDepth--;
|
nStackDepth--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,9 +78,9 @@ PopDirectory (VOID)
|
||||||
*/
|
*/
|
||||||
VOID InitDirectoryStack (VOID)
|
VOID InitDirectoryStack (VOID)
|
||||||
{
|
{
|
||||||
nStackDepth = 0;
|
nStackDepth = 0;
|
||||||
lpStackTop = NULL;
|
lpStackTop = NULL;
|
||||||
lpStackBottom = NULL;
|
lpStackBottom = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,14 +89,14 @@ VOID InitDirectoryStack (VOID)
|
||||||
*/
|
*/
|
||||||
VOID DestroyDirectoryStack (VOID)
|
VOID DestroyDirectoryStack (VOID)
|
||||||
{
|
{
|
||||||
while (nStackDepth)
|
while (nStackDepth)
|
||||||
PopDirectory ();
|
PopDirectory ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INT GetDirectoryStackDepth (VOID)
|
INT GetDirectoryStackDepth (VOID)
|
||||||
{
|
{
|
||||||
return nStackDepth;
|
return nStackDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,23 +105,23 @@ INT GetDirectoryStackDepth (VOID)
|
||||||
*/
|
*/
|
||||||
INT CommandPushd (LPTSTR rest)
|
INT CommandPushd (LPTSTR rest)
|
||||||
{
|
{
|
||||||
TCHAR curPath[MAX_PATH];
|
TCHAR curPath[MAX_PATH];
|
||||||
|
|
||||||
if (!_tcsncmp (rest, _T("/?"), 2))
|
if (!_tcsncmp (rest, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPuts(STRING_DIRSTACK_HELP1);
|
ConOutResPuts(STRING_DIRSTACK_HELP1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetCurrentDirectory (MAX_PATH, curPath);
|
GetCurrentDirectory (MAX_PATH, curPath);
|
||||||
|
|
||||||
if (rest[0] != _T('\0'))
|
if (rest[0] != _T('\0'))
|
||||||
{
|
{
|
||||||
if (!SetRootPath(NULL, rest))
|
if (!SetRootPath(NULL, rest))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PushDirectory(curPath);
|
return PushDirectory(curPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,20 +130,20 @@ INT CommandPushd (LPTSTR rest)
|
||||||
*/
|
*/
|
||||||
INT CommandPopd (LPTSTR rest)
|
INT CommandPopd (LPTSTR rest)
|
||||||
{
|
{
|
||||||
INT ret = 0;
|
INT ret = 0;
|
||||||
if (!_tcsncmp(rest, _T("/?"), 2))
|
if (!_tcsncmp(rest, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPuts(STRING_DIRSTACK_HELP2);
|
ConOutResPuts(STRING_DIRSTACK_HELP2);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nStackDepth == 0)
|
if (nStackDepth == 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
ret = _tchdir(lpStackTop->szPath) != 0;
|
ret = _tchdir(lpStackTop->szPath) != 0;
|
||||||
PopDirectory ();
|
PopDirectory ();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,31 +152,31 @@ INT CommandPopd (LPTSTR rest)
|
||||||
*/
|
*/
|
||||||
INT CommandDirs (LPTSTR rest)
|
INT CommandDirs (LPTSTR rest)
|
||||||
{
|
{
|
||||||
LPDIRENTRY lpDir;
|
LPDIRENTRY lpDir;
|
||||||
|
|
||||||
if (!_tcsncmp(rest, _T("/?"), 2))
|
if (!_tcsncmp(rest, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPuts(STRING_DIRSTACK_HELP3);
|
ConOutResPuts(STRING_DIRSTACK_HELP3);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
lpDir = lpStackBottom;
|
lpDir = lpStackBottom;
|
||||||
|
|
||||||
if (lpDir == NULL)
|
if (lpDir == NULL)
|
||||||
{
|
{
|
||||||
ConOutResPuts(STRING_DIRSTACK_HELP4);
|
ConOutResPuts(STRING_DIRSTACK_HELP4);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (lpDir != NULL)
|
while (lpDir != NULL)
|
||||||
{
|
{
|
||||||
ConOutPuts(lpDir->szPath);
|
ConOutPuts(lpDir->szPath);
|
||||||
lpDir = lpDir->prev;
|
lpDir = lpDir->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* FEATURE_DIRECTORY_STACK */
|
#endif /* FEATURE_DIRECTORY_STACK */
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
* 13-Jul-2000 (Eric Kohl)
|
* 13-Jul-2000 (Eric Kohl)
|
||||||
* Implemented 'echo.' and 'echoerr.'.
|
* Implemented 'echo.' and 'echoerr.'.
|
||||||
*
|
*
|
||||||
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -31,105 +31,105 @@
|
||||||
BOOL
|
BOOL
|
||||||
OnOffCommand(LPTSTR param, LPBOOL flag, INT message)
|
OnOffCommand(LPTSTR param, LPBOOL flag, INT message)
|
||||||
{
|
{
|
||||||
TCHAR *p2;
|
TCHAR *p2;
|
||||||
if (_tcsnicmp(param, D_OFF, sizeof(D_OFF)/sizeof(TCHAR) - 1) == 0)
|
if (_tcsnicmp(param, D_OFF, sizeof(D_OFF)/sizeof(TCHAR) - 1) == 0)
|
||||||
{
|
{
|
||||||
p2 = param + sizeof(D_OFF)/sizeof(TCHAR) - 1;
|
p2 = param + sizeof(D_OFF)/sizeof(TCHAR) - 1;
|
||||||
while (_istspace(*p2))
|
while (_istspace(*p2))
|
||||||
p2++;
|
p2++;
|
||||||
if (*p2 == _T('\0'))
|
if (*p2 == _T('\0'))
|
||||||
{
|
{
|
||||||
*flag = FALSE;
|
*flag = FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp(param, D_ON, sizeof(D_ON)/sizeof(TCHAR) - 1) == 0)
|
else if (_tcsnicmp(param, D_ON, sizeof(D_ON)/sizeof(TCHAR) - 1) == 0)
|
||||||
{
|
{
|
||||||
p2 = param + sizeof(D_ON)/sizeof(TCHAR) - 1;
|
p2 = param + sizeof(D_ON)/sizeof(TCHAR) - 1;
|
||||||
while (_istspace(*p2))
|
while (_istspace(*p2))
|
||||||
p2++;
|
p2++;
|
||||||
if (*p2 == _T('\0'))
|
if (*p2 == _T('\0'))
|
||||||
{
|
{
|
||||||
*flag = TRUE;
|
*flag = TRUE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (*param == _T('\0'))
|
else if (*param == _T('\0'))
|
||||||
{
|
{
|
||||||
ConOutResPrintf(message, *flag ? D_ON : D_OFF);
|
ConOutResPrintf(message, *flag ? D_ON : D_OFF);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
INT CommandEcho (LPTSTR param)
|
INT CommandEcho (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR p1;
|
LPTSTR p1;
|
||||||
|
|
||||||
TRACE ("CommandEcho: '%s'\n", debugstr_aw(param));
|
TRACE ("CommandEcho: '%s'\n", debugstr_aw(param));
|
||||||
|
|
||||||
/* skip all spaces for the check of '/?', 'ON' and 'OFF' */
|
/* skip all spaces for the check of '/?', 'ON' and 'OFF' */
|
||||||
p1 = param;
|
p1 = param;
|
||||||
while(_istspace(*p1))
|
while(_istspace(*p1))
|
||||||
p1++;
|
p1++;
|
||||||
|
|
||||||
if (!_tcsncmp (p1, _T("/?"), 2))
|
if (!_tcsncmp (p1, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_ECHO_HELP4);
|
ConOutResPaging(TRUE,STRING_ECHO_HELP4);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OnOffCommand(p1, &bEcho, STRING_ECHO_HELP5))
|
if (!OnOffCommand(p1, &bEcho, STRING_ECHO_HELP5))
|
||||||
{
|
{
|
||||||
/* skip the first character */
|
/* skip the first character */
|
||||||
ConOutPuts(param + 1);
|
ConOutPuts(param + 1);
|
||||||
ConOutPuts(_T("\r\n"));
|
ConOutPuts(_T("\r\n"));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
INT CommandEchos (LPTSTR param)
|
INT CommandEchos (LPTSTR param)
|
||||||
{
|
{
|
||||||
TRACE ("CommandEchos: '%s'\n", debugstr_aw(param));
|
TRACE ("CommandEchos: '%s'\n", debugstr_aw(param));
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPuts(STRING_ECHO_HELP1);
|
ConOutResPuts(STRING_ECHO_HELP1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConOutPrintf (_T("%s"), param);
|
ConOutPrintf (_T("%s"), param);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INT CommandEchoerr (LPTSTR param)
|
INT CommandEchoerr (LPTSTR param)
|
||||||
{
|
{
|
||||||
TRACE ("CommandEchoerr: '%s'\n", debugstr_aw(param));
|
TRACE ("CommandEchoerr: '%s'\n", debugstr_aw(param));
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPuts(STRING_ECHO_HELP2);
|
ConOutResPuts(STRING_ECHO_HELP2);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConErrPuts (param);
|
ConErrPuts (param);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INT CommandEchoserr (LPTSTR param)
|
INT CommandEchoserr (LPTSTR param)
|
||||||
{
|
{
|
||||||
TRACE ("CommandEchoserr: '%s'\n", debugstr_aw(param));
|
TRACE ("CommandEchoserr: '%s'\n", debugstr_aw(param));
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPuts(STRING_ECHO_HELP3);
|
ConOutResPuts(STRING_ECHO_HELP3);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConErrPrintf (_T("%s"), param);
|
ConErrPrintf (_T("%s"), param);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
* 02-Feb-1999 (Eric Kohl)
|
* 02-Feb-1999 (Eric Kohl)
|
||||||
* Use FormatMessage() for error reports.
|
* Use FormatMessage() for error reports.
|
||||||
*
|
*
|
||||||
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -25,145 +25,145 @@
|
||||||
|
|
||||||
VOID ErrorMessage (DWORD dwErrorCode, LPTSTR szFormat, ...)
|
VOID ErrorMessage (DWORD dwErrorCode, LPTSTR szFormat, ...)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
TCHAR szMessage[1024];
|
TCHAR szMessage[1024];
|
||||||
LPTSTR szError;
|
LPTSTR szError;
|
||||||
va_list arg_ptr;
|
va_list arg_ptr;
|
||||||
|
|
||||||
if (dwErrorCode == ERROR_SUCCESS)
|
if (dwErrorCode == ERROR_SUCCESS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
|
|
||||||
if (szFormat)
|
if (szFormat)
|
||||||
{
|
{
|
||||||
va_start (arg_ptr, szFormat);
|
va_start (arg_ptr, szFormat);
|
||||||
_vstprintf (szMessage, szFormat, arg_ptr);
|
_vstprintf (szMessage, szFormat, arg_ptr);
|
||||||
va_end (arg_ptr);
|
va_end (arg_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||||
NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
NULL, dwErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
(LPTSTR)&szError, 0, NULL))
|
(LPTSTR)&szError, 0, NULL))
|
||||||
{
|
{
|
||||||
ConErrPrintf (_T("%s %s\n"), szError, szMessage);
|
ConErrPrintf (_T("%s %s\n"), szError, szMessage);
|
||||||
if(szError)
|
if(szError)
|
||||||
LocalFree (szError);
|
LocalFree (szError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fall back just in case the error is not defined */
|
/* Fall back just in case the error is not defined */
|
||||||
if (szFormat)
|
if (szFormat)
|
||||||
ConErrPrintf (_T("%s -- %s\n"), szMsg, szMessage);
|
ConErrPrintf (_T("%s -- %s\n"), szMsg, szMessage);
|
||||||
else
|
else
|
||||||
ConErrPrintf (_T("%s\n"), szMsg);
|
ConErrPrintf (_T("%s\n"), szMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID error_parameter_format(TCHAR ch)
|
VOID error_parameter_format(TCHAR ch)
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_ERROR_PARAMETERF_ERROR, ch);
|
ConErrResPrintf(STRING_ERROR_PARAMETERF_ERROR, ch);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_invalid_switch (TCHAR ch)
|
VOID error_invalid_switch (TCHAR ch)
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_ERROR_INVALID_SWITCH, ch);
|
ConErrResPrintf(STRING_ERROR_INVALID_SWITCH, ch);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_too_many_parameters (LPTSTR s)
|
VOID error_too_many_parameters (LPTSTR s)
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_ERROR_TOO_MANY_PARAMETERS, s);
|
ConErrResPrintf(STRING_ERROR_TOO_MANY_PARAMETERS, s);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_path_not_found (VOID)
|
VOID error_path_not_found (VOID)
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_ERROR_PATH_NOT_FOUND);
|
ConErrResPuts(STRING_ERROR_PATH_NOT_FOUND);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_file_not_found (VOID)
|
VOID error_file_not_found (VOID)
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_ERROR_FILE_NOT_FOUND);
|
ConErrResPuts(STRING_ERROR_FILE_NOT_FOUND);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_sfile_not_found (LPTSTR f)
|
VOID error_sfile_not_found (LPTSTR f)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
|
|
||||||
LoadString(CMD_ModuleHandle, STRING_ERROR_FILE_NOT_FOUND, szMsg, RC_STRING_MAX_SIZE);
|
LoadString(CMD_ModuleHandle, STRING_ERROR_FILE_NOT_FOUND, szMsg, RC_STRING_MAX_SIZE);
|
||||||
ConErrPrintf(_T("%s - %s\n"), szMsg, f);
|
ConErrPrintf(_T("%s - %s\n"), szMsg, f);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_req_param_missing (VOID)
|
VOID error_req_param_missing (VOID)
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
|
ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_invalid_drive (VOID)
|
VOID error_invalid_drive (VOID)
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_ERROR_INVALID_DRIVE);
|
ConErrResPuts(STRING_ERROR_INVALID_DRIVE);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_bad_command (LPTSTR s)
|
VOID error_bad_command (LPTSTR s)
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_ERROR_BADCOMMAND, s);
|
ConErrResPrintf(STRING_ERROR_BADCOMMAND, s);
|
||||||
nErrorLevel = 9009;
|
nErrorLevel = 9009;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_no_pipe (VOID)
|
VOID error_no_pipe (VOID)
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_ERROR_CANNOTPIPE);
|
ConErrResPuts(STRING_ERROR_CANNOTPIPE);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_out_of_memory (VOID)
|
VOID error_out_of_memory (VOID)
|
||||||
{
|
{
|
||||||
ConErrResPuts(STRING_ERROR_OUT_OF_MEMORY);
|
ConErrResPuts(STRING_ERROR_OUT_OF_MEMORY);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_invalid_parameter_format (LPTSTR s)
|
VOID error_invalid_parameter_format (LPTSTR s)
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, s);
|
ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT, s);
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID error_syntax (LPTSTR s)
|
VOID error_syntax (LPTSTR s)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
|
|
||||||
LoadString(CMD_ModuleHandle, STRING_ERROR_ERROR2, szMsg, RC_STRING_MAX_SIZE);
|
LoadString(CMD_ModuleHandle, STRING_ERROR_ERROR2, szMsg, RC_STRING_MAX_SIZE);
|
||||||
|
|
||||||
if (s)
|
if (s)
|
||||||
ConErrPrintf(_T("%s - %s\n"), szMsg, s);
|
ConErrPrintf(_T("%s - %s\n"), szMsg, s);
|
||||||
else
|
else
|
||||||
ConErrPrintf(_T("%s.\n"), szMsg);
|
ConErrPrintf(_T("%s.\n"), szMsg);
|
||||||
|
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VOID msg_pause (VOID)
|
VOID msg_pause (VOID)
|
||||||
{
|
{
|
||||||
ConOutResPuts(STRING_ERROR_D_PAUSEMSG);
|
ConOutResPuts(STRING_ERROR_D_PAUSEMSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
* Implemented preservation of echo flag. Some other for related
|
* Implemented preservation of echo flag. Some other for related
|
||||||
* code in other files fixed, too.
|
* code in other files fixed, too.
|
||||||
*
|
*
|
||||||
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -36,16 +36,16 @@
|
||||||
/* FOR is a special command, so this function is only used for showing help now */
|
/* FOR is a special command, so this function is only used for showing help now */
|
||||||
INT cmd_for (LPTSTR param)
|
INT cmd_for (LPTSTR param)
|
||||||
{
|
{
|
||||||
TRACE ("cmd_for (\'%s\')\n", debugstr_aw(param));
|
TRACE ("cmd_for (\'%s\')\n", debugstr_aw(param));
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_FOR_HELP1);
|
ConOutResPaging(TRUE,STRING_FOR_HELP1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_syntax(param);
|
error_syntax(param);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The stack of current FOR contexts.
|
/* The stack of current FOR contexts.
|
||||||
|
@ -55,322 +55,322 @@ LPFOR_CONTEXT fc = NULL;
|
||||||
/* Get the next element of the FOR's list */
|
/* Get the next element of the FOR's list */
|
||||||
static BOOL GetNextElement(TCHAR **pStart, TCHAR **pEnd)
|
static BOOL GetNextElement(TCHAR **pStart, TCHAR **pEnd)
|
||||||
{
|
{
|
||||||
TCHAR *p = *pEnd;
|
TCHAR *p = *pEnd;
|
||||||
BOOL InQuotes = FALSE;
|
BOOL InQuotes = FALSE;
|
||||||
while (_istspace(*p))
|
while (_istspace(*p))
|
||||||
p++;
|
p++;
|
||||||
if (!*p)
|
if (!*p)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
*pStart = p;
|
*pStart = p;
|
||||||
while (*p && (InQuotes || !_istspace(*p)))
|
while (*p && (InQuotes || !_istspace(*p)))
|
||||||
InQuotes ^= (*p++ == _T('"'));
|
InQuotes ^= (*p++ == _T('"'));
|
||||||
*pEnd = p;
|
*pEnd = p;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute a single instance of a FOR command */
|
/* Execute a single instance of a FOR command */
|
||||||
static INT RunInstance(PARSED_COMMAND *Cmd)
|
static INT RunInstance(PARSED_COMMAND *Cmd)
|
||||||
{
|
{
|
||||||
if (bEcho && !bDisableBatchEcho && Cmd->Subcommands->Type != C_QUIET)
|
if (bEcho && !bDisableBatchEcho && Cmd->Subcommands->Type != C_QUIET)
|
||||||
{
|
{
|
||||||
if (!bIgnoreEcho)
|
if (!bIgnoreEcho)
|
||||||
ConOutChar(_T('\n'));
|
ConOutChar(_T('\n'));
|
||||||
PrintPrompt();
|
PrintPrompt();
|
||||||
EchoCommand(Cmd->Subcommands);
|
EchoCommand(Cmd->Subcommands);
|
||||||
ConOutChar(_T('\n'));
|
ConOutChar(_T('\n'));
|
||||||
}
|
}
|
||||||
/* Just run the command (variable expansion is done in DoDelayedExpansion) */
|
/* Just run the command (variable expansion is done in DoDelayedExpansion) */
|
||||||
return ExecuteCommand(Cmd->Subcommands);
|
return ExecuteCommand(Cmd->Subcommands);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if this FOR should be terminated early */
|
/* Check if this FOR should be terminated early */
|
||||||
static BOOL Exiting(PARSED_COMMAND *Cmd)
|
static BOOL Exiting(PARSED_COMMAND *Cmd)
|
||||||
{
|
{
|
||||||
/* Someone might have removed our context */
|
/* Someone might have removed our context */
|
||||||
return bCtrlBreak || fc != Cmd->For.Context;
|
return bCtrlBreak || fc != Cmd->For.Context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the contents of a text file into memory,
|
/* Read the contents of a text file into memory,
|
||||||
* dynamically allocating enough space to hold it all */
|
* dynamically allocating enough space to hold it all */
|
||||||
static LPTSTR ReadFileContents(FILE *InputFile, TCHAR *Buffer)
|
static LPTSTR ReadFileContents(FILE *InputFile, TCHAR *Buffer)
|
||||||
{
|
{
|
||||||
SIZE_T Len = 0;
|
SIZE_T Len = 0;
|
||||||
SIZE_T AllocLen = 1000;
|
SIZE_T AllocLen = 1000;
|
||||||
LPTSTR Contents = cmd_alloc(AllocLen * sizeof(TCHAR));
|
LPTSTR Contents = cmd_alloc(AllocLen * sizeof(TCHAR));
|
||||||
if (!Contents)
|
if (!Contents)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
while (_fgetts(Buffer, CMDLINE_LENGTH, InputFile))
|
while (_fgetts(Buffer, CMDLINE_LENGTH, InputFile))
|
||||||
{
|
{
|
||||||
ULONG_PTR CharsRead = _tcslen(Buffer);
|
ULONG_PTR CharsRead = _tcslen(Buffer);
|
||||||
while (Len + CharsRead >= AllocLen)
|
while (Len + CharsRead >= AllocLen)
|
||||||
{
|
{
|
||||||
LPTSTR OldContents = Contents;
|
LPTSTR OldContents = Contents;
|
||||||
Contents = cmd_realloc(Contents, (AllocLen *= 2) * sizeof(TCHAR));
|
Contents = cmd_realloc(Contents, (AllocLen *= 2) * sizeof(TCHAR));
|
||||||
if (!Contents)
|
if (!Contents)
|
||||||
{
|
{
|
||||||
cmd_free(OldContents);
|
cmd_free(OldContents);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_tcscpy(&Contents[Len], Buffer);
|
_tcscpy(&Contents[Len], Buffer);
|
||||||
Len += CharsRead;
|
Len += CharsRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
Contents[Len] = _T('\0');
|
Contents[Len] = _T('\0');
|
||||||
return Contents;
|
return Contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INT ForF(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
|
static INT ForF(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
|
||||||
{
|
{
|
||||||
LPTSTR Delims = _T(" \t");
|
LPTSTR Delims = _T(" \t");
|
||||||
TCHAR Eol = _T(';');
|
TCHAR Eol = _T(';');
|
||||||
INT SkipLines = 0;
|
INT SkipLines = 0;
|
||||||
DWORD Tokens = (1 << 1);
|
DWORD Tokens = (1 << 1);
|
||||||
BOOL RemainderVar = FALSE;
|
BOOL RemainderVar = FALSE;
|
||||||
TCHAR StringQuote = _T('"');
|
TCHAR StringQuote = _T('"');
|
||||||
TCHAR CommandQuote = _T('\'');
|
TCHAR CommandQuote = _T('\'');
|
||||||
LPTSTR Variables[32];
|
LPTSTR Variables[32];
|
||||||
TCHAR *Start, *End;
|
TCHAR *Start, *End;
|
||||||
INT i;
|
INT i;
|
||||||
INT Ret = 0;
|
INT Ret = 0;
|
||||||
|
|
||||||
if (Cmd->For.Params)
|
if (Cmd->For.Params)
|
||||||
{
|
{
|
||||||
TCHAR Quote = 0;
|
TCHAR Quote = 0;
|
||||||
TCHAR *Param = Cmd->For.Params;
|
TCHAR *Param = Cmd->For.Params;
|
||||||
if (*Param == _T('"') || *Param == _T('\''))
|
if (*Param == _T('"') || *Param == _T('\''))
|
||||||
Quote = *Param++;
|
Quote = *Param++;
|
||||||
|
|
||||||
while (*Param && *Param != Quote)
|
while (*Param && *Param != Quote)
|
||||||
{
|
{
|
||||||
if (*Param <= _T(' '))
|
if (*Param <= _T(' '))
|
||||||
{
|
{
|
||||||
Param++;
|
Param++;
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp(Param, _T("delims="), 7) == 0)
|
else if (_tcsnicmp(Param, _T("delims="), 7) == 0)
|
||||||
{
|
{
|
||||||
Param += 7;
|
Param += 7;
|
||||||
/* delims=xxx: Specifies the list of characters that separate tokens */
|
/* delims=xxx: Specifies the list of characters that separate tokens */
|
||||||
Delims = Param;
|
Delims = Param;
|
||||||
while (*Param && *Param != Quote)
|
while (*Param && *Param != Quote)
|
||||||
{
|
{
|
||||||
if (*Param == _T(' '))
|
if (*Param == _T(' '))
|
||||||
{
|
{
|
||||||
TCHAR *FirstSpace = Param;
|
TCHAR *FirstSpace = Param;
|
||||||
Param += _tcsspn(Param, _T(" "));
|
Param += _tcsspn(Param, _T(" "));
|
||||||
/* Exclude trailing spaces if this is not the last parameter */
|
/* Exclude trailing spaces if this is not the last parameter */
|
||||||
if (*Param && *Param != Quote)
|
if (*Param && *Param != Quote)
|
||||||
*FirstSpace = _T('\0');
|
*FirstSpace = _T('\0');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Param++;
|
Param++;
|
||||||
}
|
}
|
||||||
if (*Param == Quote)
|
if (*Param == Quote)
|
||||||
*Param++ = _T('\0');
|
*Param++ = _T('\0');
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp(Param, _T("eol="), 4) == 0)
|
else if (_tcsnicmp(Param, _T("eol="), 4) == 0)
|
||||||
{
|
{
|
||||||
Param += 4;
|
Param += 4;
|
||||||
/* eol=c: Lines starting with this character (may be
|
/* eol=c: Lines starting with this character (may be
|
||||||
* preceded by delimiters) are skipped. */
|
* preceded by delimiters) are skipped. */
|
||||||
Eol = *Param;
|
Eol = *Param;
|
||||||
if (Eol != _T('\0'))
|
if (Eol != _T('\0'))
|
||||||
Param++;
|
Param++;
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp(Param, _T("skip="), 5) == 0)
|
else if (_tcsnicmp(Param, _T("skip="), 5) == 0)
|
||||||
{
|
{
|
||||||
/* skip=n: Number of lines to skip at the beginning of each file */
|
/* skip=n: Number of lines to skip at the beginning of each file */
|
||||||
SkipLines = _tcstol(Param + 5, &Param, 0);
|
SkipLines = _tcstol(Param + 5, &Param, 0);
|
||||||
if (SkipLines <= 0)
|
if (SkipLines <= 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp(Param, _T("tokens="), 7) == 0)
|
else if (_tcsnicmp(Param, _T("tokens="), 7) == 0)
|
||||||
{
|
{
|
||||||
Param += 7;
|
Param += 7;
|
||||||
/* tokens=x,y,m-n: List of token numbers (must be between
|
/* tokens=x,y,m-n: List of token numbers (must be between
|
||||||
* 1 and 31) that will be assigned into variables. */
|
* 1 and 31) that will be assigned into variables. */
|
||||||
Tokens = 0;
|
Tokens = 0;
|
||||||
while (*Param && *Param != Quote && *Param != _T('*'))
|
while (*Param && *Param != Quote && *Param != _T('*'))
|
||||||
{
|
{
|
||||||
INT First = _tcstol(Param, &Param, 0);
|
INT First = _tcstol(Param, &Param, 0);
|
||||||
INT Last = First;
|
INT Last = First;
|
||||||
if (First < 1)
|
if (First < 1)
|
||||||
goto error;
|
goto error;
|
||||||
if (*Param == _T('-'))
|
if (*Param == _T('-'))
|
||||||
{
|
{
|
||||||
/* It's a range of tokens */
|
/* It's a range of tokens */
|
||||||
Last = _tcstol(Param + 1, &Param, 0);
|
Last = _tcstol(Param + 1, &Param, 0);
|
||||||
if (Last < First || Last > 31)
|
if (Last < First || Last > 31)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
Tokens |= (2 << Last) - (1 << First);
|
Tokens |= (2 << Last) - (1 << First);
|
||||||
|
|
||||||
if (*Param != _T(','))
|
if (*Param != _T(','))
|
||||||
break;
|
break;
|
||||||
Param++;
|
Param++;
|
||||||
}
|
}
|
||||||
/* With an asterisk at the end, an additional variable
|
/* With an asterisk at the end, an additional variable
|
||||||
* will be created to hold the remainder of the line
|
* will be created to hold the remainder of the line
|
||||||
* (after the last token specified). */
|
* (after the last token specified). */
|
||||||
if (*Param == _T('*'))
|
if (*Param == _T('*'))
|
||||||
{
|
{
|
||||||
RemainderVar = TRUE;
|
RemainderVar = TRUE;
|
||||||
Param++;
|
Param++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_tcsnicmp(Param, _T("useback"), 7) == 0)
|
else if (_tcsnicmp(Param, _T("useback"), 7) == 0)
|
||||||
{
|
{
|
||||||
Param += 7;
|
Param += 7;
|
||||||
/* usebackq: Use alternate quote characters */
|
/* usebackq: Use alternate quote characters */
|
||||||
StringQuote = _T('\'');
|
StringQuote = _T('\'');
|
||||||
CommandQuote = _T('`');
|
CommandQuote = _T('`');
|
||||||
/* Can be written as either "useback" or "usebackq" */
|
/* Can be written as either "useback" or "usebackq" */
|
||||||
if (_totlower(*Param) == _T('q'))
|
if (_totlower(*Param) == _T('q'))
|
||||||
Param++;
|
Param++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
error:
|
error:
|
||||||
error_syntax(Param);
|
error_syntax(Param);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Count how many variables will be set: one for each token,
|
/* Count how many variables will be set: one for each token,
|
||||||
* plus maybe one for the remainder */
|
* plus maybe one for the remainder */
|
||||||
fc->varcount = RemainderVar;
|
fc->varcount = RemainderVar;
|
||||||
for (i = 1; i < 32; i++)
|
for (i = 1; i < 32; i++)
|
||||||
fc->varcount += (Tokens >> i & 1);
|
fc->varcount += (Tokens >> i & 1);
|
||||||
fc->values = Variables;
|
fc->values = Variables;
|
||||||
|
|
||||||
if (*List == StringQuote || *List == CommandQuote)
|
if (*List == StringQuote || *List == CommandQuote)
|
||||||
{
|
{
|
||||||
/* Treat the entire "list" as one single element */
|
/* Treat the entire "list" as one single element */
|
||||||
Start = List;
|
Start = List;
|
||||||
End = &List[_tcslen(List)];
|
End = &List[_tcslen(List)];
|
||||||
goto single_element;
|
goto single_element;
|
||||||
}
|
}
|
||||||
|
|
||||||
End = List;
|
End = List;
|
||||||
while (GetNextElement(&Start, &End))
|
while (GetNextElement(&Start, &End))
|
||||||
{
|
{
|
||||||
FILE *InputFile;
|
FILE *InputFile;
|
||||||
LPTSTR FullInput, In, NextLine;
|
LPTSTR FullInput, In, NextLine;
|
||||||
INT Skip;
|
INT Skip;
|
||||||
single_element:
|
single_element:
|
||||||
|
|
||||||
if (*Start == StringQuote && End[-1] == StringQuote)
|
if (*Start == StringQuote && End[-1] == StringQuote)
|
||||||
{
|
{
|
||||||
/* Input given directly as a string */
|
/* Input given directly as a string */
|
||||||
End[-1] = _T('\0');
|
End[-1] = _T('\0');
|
||||||
FullInput = cmd_dup(Start + 1);
|
FullInput = cmd_dup(Start + 1);
|
||||||
}
|
}
|
||||||
else if (*Start == CommandQuote && End[-1] == CommandQuote)
|
else if (*Start == CommandQuote && End[-1] == CommandQuote)
|
||||||
{
|
{
|
||||||
/* Read input from a command */
|
/* Read input from a command */
|
||||||
End[-1] = _T('\0');
|
End[-1] = _T('\0');
|
||||||
InputFile = _tpopen(Start + 1, _T("r"));
|
InputFile = _tpopen(Start + 1, _T("r"));
|
||||||
if (!InputFile)
|
if (!InputFile)
|
||||||
{
|
{
|
||||||
error_bad_command(Start + 1);
|
error_bad_command(Start + 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
FullInput = ReadFileContents(InputFile, Buffer);
|
FullInput = ReadFileContents(InputFile, Buffer);
|
||||||
_pclose(InputFile);
|
_pclose(InputFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Read input from a file */
|
/* Read input from a file */
|
||||||
TCHAR Temp = *End;
|
TCHAR Temp = *End;
|
||||||
*End = _T('\0');
|
*End = _T('\0');
|
||||||
StripQuotes(Start);
|
StripQuotes(Start);
|
||||||
InputFile = _tfopen(Start, _T("r"));
|
InputFile = _tfopen(Start, _T("r"));
|
||||||
*End = Temp;
|
*End = Temp;
|
||||||
if (!InputFile)
|
if (!InputFile)
|
||||||
{
|
{
|
||||||
error_sfile_not_found(Start);
|
error_sfile_not_found(Start);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
FullInput = ReadFileContents(InputFile, Buffer);
|
FullInput = ReadFileContents(InputFile, Buffer);
|
||||||
fclose(InputFile);
|
fclose(InputFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FullInput)
|
if (!FullInput)
|
||||||
{
|
{
|
||||||
error_out_of_memory();
|
error_out_of_memory();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop over the input line by line */
|
/* Loop over the input line by line */
|
||||||
In = FullInput;
|
In = FullInput;
|
||||||
Skip = SkipLines;
|
Skip = SkipLines;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
DWORD RemainingTokens = Tokens;
|
DWORD RemainingTokens = Tokens;
|
||||||
LPTSTR *CurVar = Variables;
|
LPTSTR *CurVar = Variables;
|
||||||
|
|
||||||
NextLine = _tcschr(In, _T('\n'));
|
NextLine = _tcschr(In, _T('\n'));
|
||||||
if (NextLine)
|
if (NextLine)
|
||||||
*NextLine++ = _T('\0');
|
*NextLine++ = _T('\0');
|
||||||
|
|
||||||
if (--Skip >= 0)
|
if (--Skip >= 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Ignore lines where the first token starts with the eol character */
|
/* Ignore lines where the first token starts with the eol character */
|
||||||
In += _tcsspn(In, Delims);
|
In += _tcsspn(In, Delims);
|
||||||
if (*In == Eol)
|
if (*In == Eol)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
while ((RemainingTokens >>= 1) != 0)
|
while ((RemainingTokens >>= 1) != 0)
|
||||||
{
|
{
|
||||||
/* Save pointer to this token in a variable if requested */
|
/* Save pointer to this token in a variable if requested */
|
||||||
if (RemainingTokens & 1)
|
if (RemainingTokens & 1)
|
||||||
*CurVar++ = In;
|
*CurVar++ = In;
|
||||||
/* Find end of token */
|
/* Find end of token */
|
||||||
In += _tcscspn(In, Delims);
|
In += _tcscspn(In, Delims);
|
||||||
/* Nul-terminate it and advance to next token */
|
/* Nul-terminate it and advance to next token */
|
||||||
if (*In)
|
if (*In)
|
||||||
{
|
{
|
||||||
*In++ = _T('\0');
|
*In++ = _T('\0');
|
||||||
In += _tcsspn(In, Delims);
|
In += _tcsspn(In, Delims);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Save pointer to remainder of line */
|
/* Save pointer to remainder of line */
|
||||||
*CurVar = In;
|
*CurVar = In;
|
||||||
|
|
||||||
/* Don't run unless the line had enough tokens to fill at least one variable */
|
/* Don't run unless the line had enough tokens to fill at least one variable */
|
||||||
if (*Variables[0])
|
if (*Variables[0])
|
||||||
Ret = RunInstance(Cmd);
|
Ret = RunInstance(Cmd);
|
||||||
} while (!Exiting(Cmd) && (In = NextLine) != NULL);
|
} while (!Exiting(Cmd) && (In = NextLine) != NULL);
|
||||||
cmd_free(FullInput);
|
cmd_free(FullInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FOR /L: Do a numeric loop */
|
/* FOR /L: Do a numeric loop */
|
||||||
static INT ForLoop(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
|
static INT ForLoop(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
|
||||||
{
|
{
|
||||||
enum { START, STEP, END };
|
enum { START, STEP, END };
|
||||||
INT params[3] = { 0, 0, 0 };
|
INT params[3] = { 0, 0, 0 };
|
||||||
INT i;
|
INT i;
|
||||||
INT Ret = 0;
|
INT Ret = 0;
|
||||||
|
|
||||||
TCHAR *Start, *End = List;
|
TCHAR *Start, *End = List;
|
||||||
for (i = 0; i < 3 && GetNextElement(&Start, &End); i++)
|
for (i = 0; i < 3 && GetNextElement(&Start, &End); i++)
|
||||||
params[i] = _tcstol(Start, NULL, 0);
|
params[i] = _tcstol(Start, NULL, 0);
|
||||||
|
|
||||||
i = params[START];
|
i = params[START];
|
||||||
while (!Exiting(Cmd) &&
|
while (!Exiting(Cmd) &&
|
||||||
(params[STEP] >= 0 ? (i <= params[END]) : (i >= params[END])))
|
(params[STEP] >= 0 ? (i <= params[END]) : (i >= params[END])))
|
||||||
{
|
{
|
||||||
_itot(i, Buffer, 10);
|
_itot(i, Buffer, 10);
|
||||||
Ret = RunInstance(Cmd);
|
Ret = RunInstance(Cmd);
|
||||||
i += params[STEP];
|
i += params[STEP];
|
||||||
}
|
}
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process a FOR in one directory. Stored in Buffer (up to BufPos) is a
|
/* Process a FOR in one directory. Stored in Buffer (up to BufPos) is a
|
||||||
|
@ -378,135 +378,135 @@ static INT ForLoop(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
|
||||||
* it will be empty, but in FOR /R it will be the directory name. */
|
* it will be empty, but in FOR /R it will be the directory name. */
|
||||||
static INT ForDir(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
|
static INT ForDir(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
|
||||||
{
|
{
|
||||||
TCHAR *Start, *End = List;
|
TCHAR *Start, *End = List;
|
||||||
INT Ret = 0;
|
INT Ret = 0;
|
||||||
while (!Exiting(Cmd) && GetNextElement(&Start, &End))
|
while (!Exiting(Cmd) && GetNextElement(&Start, &End))
|
||||||
{
|
{
|
||||||
if (BufPos + (End - Start) > &Buffer[CMDLINE_LENGTH])
|
if (BufPos + (End - Start) > &Buffer[CMDLINE_LENGTH])
|
||||||
continue;
|
continue;
|
||||||
memcpy(BufPos, Start, (End - Start) * sizeof(TCHAR));
|
memcpy(BufPos, Start, (End - Start) * sizeof(TCHAR));
|
||||||
BufPos[End - Start] = _T('\0');
|
BufPos[End - Start] = _T('\0');
|
||||||
|
|
||||||
if (_tcschr(BufPos, _T('?')) || _tcschr(BufPos, _T('*')))
|
if (_tcschr(BufPos, _T('?')) || _tcschr(BufPos, _T('*')))
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA w32fd;
|
WIN32_FIND_DATA w32fd;
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
TCHAR *FilePart;
|
TCHAR *FilePart;
|
||||||
|
|
||||||
StripQuotes(BufPos);
|
StripQuotes(BufPos);
|
||||||
hFind = FindFirstFile(Buffer, &w32fd);
|
hFind = FindFirstFile(Buffer, &w32fd);
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
continue;
|
continue;
|
||||||
FilePart = _tcsrchr(BufPos, _T('\\'));
|
FilePart = _tcsrchr(BufPos, _T('\\'));
|
||||||
FilePart = FilePart ? FilePart + 1 : BufPos;
|
FilePart = FilePart ? FilePart + 1 : BufPos;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
|
if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
|
||||||
continue;
|
continue;
|
||||||
if (!(w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if (!(w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
!= !(Cmd->For.Switches & FOR_DIRS))
|
!= !(Cmd->For.Switches & FOR_DIRS))
|
||||||
continue;
|
continue;
|
||||||
if (_tcscmp(w32fd.cFileName, _T(".")) == 0 ||
|
if (_tcscmp(w32fd.cFileName, _T(".")) == 0 ||
|
||||||
_tcscmp(w32fd.cFileName, _T("..")) == 0)
|
_tcscmp(w32fd.cFileName, _T("..")) == 0)
|
||||||
continue;
|
continue;
|
||||||
_tcscpy(FilePart, w32fd.cFileName);
|
_tcscpy(FilePart, w32fd.cFileName);
|
||||||
Ret = RunInstance(Cmd);
|
Ret = RunInstance(Cmd);
|
||||||
} while (!Exiting(Cmd) && FindNextFile(hFind, &w32fd));
|
} while (!Exiting(Cmd) && FindNextFile(hFind, &w32fd));
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Ret = RunInstance(Cmd);
|
Ret = RunInstance(Cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FOR /R: Process a FOR in each directory of a tree, recursively. */
|
/* FOR /R: Process a FOR in each directory of a tree, recursively. */
|
||||||
static INT ForRecursive(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
|
static INT ForRecursive(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
|
||||||
{
|
{
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
WIN32_FIND_DATA w32fd;
|
WIN32_FIND_DATA w32fd;
|
||||||
INT Ret = 0;
|
INT Ret = 0;
|
||||||
|
|
||||||
if (BufPos[-1] != _T('\\'))
|
if (BufPos[-1] != _T('\\'))
|
||||||
{
|
{
|
||||||
*BufPos++ = _T('\\');
|
*BufPos++ = _T('\\');
|
||||||
*BufPos = _T('\0');
|
*BufPos = _T('\0');
|
||||||
}
|
}
|
||||||
|
|
||||||
Ret = ForDir(Cmd, List, Buffer, BufPos);
|
Ret = ForDir(Cmd, List, Buffer, BufPos);
|
||||||
|
|
||||||
_tcscpy(BufPos, _T("*"));
|
_tcscpy(BufPos, _T("*"));
|
||||||
hFind = FindFirstFile(Buffer, &w32fd);
|
hFind = FindFirstFile(Buffer, &w32fd);
|
||||||
if (hFind == INVALID_HANDLE_VALUE)
|
if (hFind == INVALID_HANDLE_VALUE)
|
||||||
return Ret;
|
return Ret;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!(w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
if (!(w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||||
continue;
|
continue;
|
||||||
if (_tcscmp(w32fd.cFileName, _T(".")) == 0 ||
|
if (_tcscmp(w32fd.cFileName, _T(".")) == 0 ||
|
||||||
_tcscmp(w32fd.cFileName, _T("..")) == 0)
|
_tcscmp(w32fd.cFileName, _T("..")) == 0)
|
||||||
continue;
|
continue;
|
||||||
Ret = ForRecursive(Cmd, List, Buffer, _stpcpy(BufPos, w32fd.cFileName));
|
Ret = ForRecursive(Cmd, List, Buffer, _stpcpy(BufPos, w32fd.cFileName));
|
||||||
} while (!Exiting(Cmd) && FindNextFile(hFind, &w32fd));
|
} while (!Exiting(Cmd) && FindNextFile(hFind, &w32fd));
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
ExecuteFor(PARSED_COMMAND *Cmd)
|
ExecuteFor(PARSED_COMMAND *Cmd)
|
||||||
{
|
{
|
||||||
TCHAR Buffer[CMDLINE_LENGTH]; /* Buffer to hold the variable value */
|
TCHAR Buffer[CMDLINE_LENGTH]; /* Buffer to hold the variable value */
|
||||||
LPTSTR BufferPtr = Buffer;
|
LPTSTR BufferPtr = Buffer;
|
||||||
LPFOR_CONTEXT lpNew;
|
LPFOR_CONTEXT lpNew;
|
||||||
INT Ret;
|
INT Ret;
|
||||||
LPTSTR List = DoDelayedExpansion(Cmd->For.List);
|
LPTSTR List = DoDelayedExpansion(Cmd->For.List);
|
||||||
|
|
||||||
if (!List)
|
if (!List)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Create our FOR context */
|
/* Create our FOR context */
|
||||||
lpNew = cmd_alloc(sizeof(FOR_CONTEXT));
|
lpNew = cmd_alloc(sizeof(FOR_CONTEXT));
|
||||||
if (!lpNew)
|
if (!lpNew)
|
||||||
{
|
{
|
||||||
cmd_free(List);
|
cmd_free(List);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
lpNew->prev = fc;
|
lpNew->prev = fc;
|
||||||
lpNew->firstvar = Cmd->For.Variable;
|
lpNew->firstvar = Cmd->For.Variable;
|
||||||
lpNew->varcount = 1;
|
lpNew->varcount = 1;
|
||||||
lpNew->values = &BufferPtr;
|
lpNew->values = &BufferPtr;
|
||||||
|
|
||||||
Cmd->For.Context = lpNew;
|
Cmd->For.Context = lpNew;
|
||||||
fc = lpNew;
|
fc = lpNew;
|
||||||
|
|
||||||
if (Cmd->For.Switches & FOR_F)
|
if (Cmd->For.Switches & FOR_F)
|
||||||
{
|
{
|
||||||
Ret = ForF(Cmd, List, Buffer);
|
Ret = ForF(Cmd, List, Buffer);
|
||||||
}
|
}
|
||||||
else if (Cmd->For.Switches & FOR_LOOP)
|
else if (Cmd->For.Switches & FOR_LOOP)
|
||||||
{
|
{
|
||||||
Ret = ForLoop(Cmd, List, Buffer);
|
Ret = ForLoop(Cmd, List, Buffer);
|
||||||
}
|
}
|
||||||
else if (Cmd->For.Switches & FOR_RECURSIVE)
|
else if (Cmd->For.Switches & FOR_RECURSIVE)
|
||||||
{
|
{
|
||||||
DWORD Len = GetFullPathName(Cmd->For.Params ? Cmd->For.Params : _T("."),
|
DWORD Len = GetFullPathName(Cmd->For.Params ? Cmd->For.Params : _T("."),
|
||||||
MAX_PATH, Buffer, NULL);
|
MAX_PATH, Buffer, NULL);
|
||||||
Ret = ForRecursive(Cmd, List, Buffer, &Buffer[Len]);
|
Ret = ForRecursive(Cmd, List, Buffer, &Buffer[Len]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Ret = ForDir(Cmd, List, Buffer, Buffer);
|
Ret = ForDir(Cmd, List, Buffer, Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove our context, unless someone already did that */
|
/* Remove our context, unless someone already did that */
|
||||||
if (fc == lpNew)
|
if (fc == lpNew)
|
||||||
fc = lpNew->prev;
|
fc = lpNew->prev;
|
||||||
|
|
||||||
cmd_free(lpNew);
|
cmd_free(lpNew);
|
||||||
cmd_free(List);
|
cmd_free(List);
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
* 01-Sep-1999 (Eric Kohl)
|
* 01-Sep-1999 (Eric Kohl)
|
||||||
* Started.
|
* Started.
|
||||||
*
|
*
|
||||||
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -18,102 +18,101 @@
|
||||||
static VOID
|
static VOID
|
||||||
PrintDiskInfo (LPTSTR szDisk)
|
PrintDiskInfo (LPTSTR szDisk)
|
||||||
{
|
{
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
TCHAR szRootPath[4] = _T("A:\\");
|
TCHAR szRootPath[4] = _T("A:\\");
|
||||||
TCHAR szDrive[2] = _T("A");
|
TCHAR szDrive[2] = _T("A");
|
||||||
TCHAR szVolume[64];
|
TCHAR szVolume[64];
|
||||||
TCHAR szSerial[10];
|
TCHAR szSerial[10];
|
||||||
TCHAR szTotal[40];
|
TCHAR szTotal[40];
|
||||||
TCHAR szUsed[40];
|
TCHAR szUsed[40];
|
||||||
TCHAR szFree[40];
|
TCHAR szFree[40];
|
||||||
DWORD dwSerial;
|
DWORD dwSerial;
|
||||||
ULONGLONG uliSize;
|
ULONGLONG uliSize;
|
||||||
DWORD dwSecPerCl;
|
DWORD dwSecPerCl;
|
||||||
DWORD dwBytPerSec;
|
DWORD dwBytPerSec;
|
||||||
DWORD dwFreeCl;
|
DWORD dwFreeCl;
|
||||||
DWORD dwTotCl;
|
DWORD dwTotCl;
|
||||||
|
|
||||||
if (_tcslen (szDisk) < 2 || szDisk[1] != _T(':'))
|
if (_tcslen (szDisk) < 2 || szDisk[1] != _T(':'))
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_FREE_ERROR1);
|
ConErrResPrintf(STRING_FREE_ERROR1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
szRootPath[0] = szDisk[0];
|
szRootPath[0] = szDisk[0];
|
||||||
szDrive[0] = _totupper (szRootPath[0]);
|
szDrive[0] = _totupper (szRootPath[0]);
|
||||||
|
|
||||||
if (!GetVolumeInformation (szRootPath, szVolume, 64, &dwSerial,
|
if (!GetVolumeInformation (szRootPath, szVolume, 64, &dwSerial,
|
||||||
NULL, NULL, NULL, 0))
|
NULL, NULL, NULL, 0))
|
||||||
{
|
{
|
||||||
LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
|
LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
|
||||||
ConErrPrintf(_T("%s %s:\n"), szMsg, szDrive);
|
ConErrPrintf(_T("%s %s:\n"), szMsg, szDrive);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (szVolume[0] == _T('\0'))
|
if (szVolume[0] == _T('\0'))
|
||||||
{
|
{
|
||||||
|
|
||||||
LoadString(CMD_ModuleHandle, STRING_FREE_ERROR2, szMsg, RC_STRING_MAX_SIZE);
|
LoadString(CMD_ModuleHandle, STRING_FREE_ERROR2, szMsg, RC_STRING_MAX_SIZE);
|
||||||
_tcscpy (szVolume, szMsg);
|
_tcscpy (szVolume, szMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
_stprintf (szSerial,
|
_stprintf (szSerial,
|
||||||
_T("%04X-%04X"),
|
_T("%04X-%04X"),
|
||||||
HIWORD(dwSerial),
|
HIWORD(dwSerial),
|
||||||
LOWORD(dwSerial));
|
LOWORD(dwSerial));
|
||||||
|
|
||||||
if (!GetDiskFreeSpace (szRootPath, &dwSecPerCl,
|
if (!GetDiskFreeSpace (szRootPath, &dwSecPerCl,
|
||||||
&dwBytPerSec, &dwFreeCl, &dwTotCl))
|
&dwBytPerSec, &dwFreeCl, &dwTotCl))
|
||||||
{
|
{
|
||||||
LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
|
LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, RC_STRING_MAX_SIZE);
|
||||||
ConErrPrintf (_T("%s %s:\n"), szMsg, szDrive);
|
ConErrPrintf (_T("%s %s:\n"), szMsg, szDrive);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwTotCl;
|
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwTotCl;
|
||||||
ConvertULargeInteger(uliSize, szTotal, 40, TRUE);
|
ConvertULargeInteger(uliSize, szTotal, 40, TRUE);
|
||||||
|
|
||||||
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)(dwTotCl - dwFreeCl);
|
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)(dwTotCl - dwFreeCl);
|
||||||
ConvertULargeInteger(uliSize, szUsed, 40, TRUE);
|
ConvertULargeInteger(uliSize, szUsed, 40, TRUE);
|
||||||
|
|
||||||
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwFreeCl;
|
uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwFreeCl;
|
||||||
ConvertULargeInteger(uliSize, szFree, 40, TRUE);
|
ConvertULargeInteger(uliSize, szFree, 40, TRUE);
|
||||||
|
|
||||||
|
ConOutResPrintf(STRING_FREE_HELP1, szDrive, szVolume, szSerial, szTotal, szUsed, szFree);
|
||||||
ConOutResPrintf(STRING_FREE_HELP1, szDrive, szVolume, szSerial, szTotal, szUsed, szFree);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INT CommandFree (LPTSTR param)
|
INT CommandFree (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR szParam;
|
LPTSTR szParam;
|
||||||
TCHAR szDefPath[MAX_PATH];
|
TCHAR szDefPath[MAX_PATH];
|
||||||
INT argc, i;
|
INT argc, i;
|
||||||
LPTSTR *arg;
|
LPTSTR *arg;
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_FREE_HELP2);
|
ConOutResPaging(TRUE,STRING_FREE_HELP2);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!param || *param == _T('\0'))
|
if (!param || *param == _T('\0'))
|
||||||
{
|
{
|
||||||
GetCurrentDirectory (MAX_PATH, szDefPath);
|
GetCurrentDirectory (MAX_PATH, szDefPath);
|
||||||
szDefPath[2] = _T('\0');
|
szDefPath[2] = _T('\0');
|
||||||
szParam = szDefPath;
|
szParam = szDefPath;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
szParam = param;
|
szParam = param;
|
||||||
|
|
||||||
arg = split (szParam, &argc, FALSE, FALSE);
|
arg = split (szParam, &argc, FALSE, FALSE);
|
||||||
|
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
PrintDiskInfo (arg[i]);
|
PrintDiskInfo (arg[i]);
|
||||||
|
|
||||||
freep (arg);
|
freep (arg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_FREE */
|
#endif /* INCLUDE_CMD_FREE */
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
* 27-Jan-1999 (Eric Kohl)
|
* 27-Jan-1999 (Eric Kohl)
|
||||||
* Added help text ("/?").
|
* Added help text ("/?").
|
||||||
*
|
*
|
||||||
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -38,82 +38,82 @@
|
||||||
|
|
||||||
INT cmd_goto (LPTSTR param)
|
INT cmd_goto (LPTSTR param)
|
||||||
{
|
{
|
||||||
LPTSTR tmp, tmp2;
|
LPTSTR tmp, tmp2;
|
||||||
|
|
||||||
TRACE ("cmd_goto (\'%s\')\n", debugstr_aw(param));
|
TRACE ("cmd_goto (\'%s\')\n", debugstr_aw(param));
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_GOTO_HELP1);
|
ConOutResPaging(TRUE,STRING_GOTO_HELP1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if not in batch -- error!! */
|
/* if not in batch -- error!! */
|
||||||
if (bc == NULL)
|
if (bc == NULL)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*param == _T('\0'))
|
if (*param == _T('\0'))
|
||||||
{
|
{
|
||||||
ConErrResPrintf(STRING_GOTO_ERROR1);
|
ConErrResPrintf(STRING_GOTO_ERROR1);
|
||||||
ExitBatch();
|
ExitBatch();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* terminate label at first space char */
|
/* terminate label at first space char */
|
||||||
tmp = param+1;
|
tmp = param+1;
|
||||||
while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':')))
|
while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':')))
|
||||||
tmp++;
|
tmp++;
|
||||||
*(tmp) = _T('\0');
|
*(tmp) = _T('\0');
|
||||||
|
|
||||||
/* jump to end of the file */
|
/* jump to end of the file */
|
||||||
if ( _tcsicmp( param, _T(":eof"))==0)
|
if ( _tcsicmp( param, _T(":eof"))==0)
|
||||||
{
|
{
|
||||||
bc->mempos=bc->memsize; /* position at the end of the batchfile */
|
bc->mempos=bc->memsize; /* position at the end of the batchfile */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* jump to begin of the file */
|
/* jump to begin of the file */
|
||||||
bc->mempos=0;
|
bc->mempos=0;
|
||||||
|
|
||||||
while (BatchGetString (textline, sizeof(textline) / sizeof(textline[0])))
|
while (BatchGetString (textline, sizeof(textline) / sizeof(textline[0])))
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
INT_PTR size;
|
INT_PTR size;
|
||||||
|
|
||||||
/* Strip out any trailing spaces or control chars */
|
/* Strip out any trailing spaces or control chars */
|
||||||
tmp = textline + _tcslen (textline) - 1;
|
tmp = textline + _tcslen (textline) - 1;
|
||||||
|
|
||||||
while (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':')))
|
while (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':')))
|
||||||
tmp--;
|
tmp--;
|
||||||
*(tmp + 1) = _T('\0');
|
*(tmp + 1) = _T('\0');
|
||||||
|
|
||||||
/* Then leading spaces... */
|
/* Then leading spaces... */
|
||||||
tmp = textline;
|
tmp = textline;
|
||||||
while (_istspace (*tmp))
|
while (_istspace (*tmp))
|
||||||
tmp++;
|
tmp++;
|
||||||
|
|
||||||
/* All space after leading space terminate the string */
|
/* All space after leading space terminate the string */
|
||||||
size = _tcslen(tmp) -1;
|
size = _tcslen(tmp) -1;
|
||||||
pos=0;
|
pos=0;
|
||||||
while (tmp+pos < tmp+size)
|
while (tmp+pos < tmp+size)
|
||||||
{
|
{
|
||||||
if (_istspace(tmp[pos]))
|
if (_istspace(tmp[pos]))
|
||||||
tmp[pos]=_T('\0');
|
tmp[pos]=_T('\0');
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp2 = param;
|
tmp2 = param;
|
||||||
/* use whole label name */
|
/* use whole label name */
|
||||||
if ((*tmp == _T(':')) && ((_tcsicmp (++tmp, param) == 0) || (_tcsicmp (tmp, ++tmp2) == 0)))
|
if ((*tmp == _T(':')) && ((_tcsicmp (++tmp, param) == 0) || (_tcsicmp (tmp, ++tmp2) == 0)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ConErrResPrintf(STRING_GOTO_ERROR2, param);
|
ConErrResPrintf(STRING_GOTO_ERROR2, param);
|
||||||
ExitBatch();
|
ExitBatch();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
* 17-Feb-2001 (ea)
|
* 17-Feb-2001 (ea)
|
||||||
* IF DEFINED variable command
|
* IF DEFINED variable command
|
||||||
*
|
*
|
||||||
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -35,144 +35,144 @@
|
||||||
static INT GenericCmp(INT (*StringCmp)(LPCTSTR, LPCTSTR),
|
static INT GenericCmp(INT (*StringCmp)(LPCTSTR, LPCTSTR),
|
||||||
LPCTSTR Left, LPCTSTR Right)
|
LPCTSTR Left, LPCTSTR Right)
|
||||||
{
|
{
|
||||||
TCHAR *end;
|
TCHAR *end;
|
||||||
INT nLeft = _tcstol(Left, &end, 0);
|
INT nLeft = _tcstol(Left, &end, 0);
|
||||||
if (*end == _T('\0'))
|
if (*end == _T('\0'))
|
||||||
{
|
{
|
||||||
INT nRight = _tcstol(Right, &end, 0);
|
INT nRight = _tcstol(Right, &end, 0);
|
||||||
if (*end == _T('\0'))
|
if (*end == _T('\0'))
|
||||||
{
|
{
|
||||||
/* both arguments are numeric */
|
/* both arguments are numeric */
|
||||||
return (nLeft < nRight) ? -1 : (nLeft > nRight);
|
return (nLeft < nRight) ? -1 : (nLeft > nRight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return StringCmp(Left, Right);
|
return StringCmp(Left, Right);
|
||||||
}
|
}
|
||||||
|
|
||||||
INT cmd_if (LPTSTR param)
|
INT cmd_if (LPTSTR param)
|
||||||
{
|
{
|
||||||
TRACE ("cmd_if: (\'%s\')\n", debugstr_aw(param));
|
TRACE ("cmd_if: (\'%s\')\n", debugstr_aw(param));
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_IF_HELP1);
|
ConOutResPaging(TRUE,STRING_IF_HELP1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_syntax(param);
|
error_syntax(param);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
INT ExecuteIf(PARSED_COMMAND *Cmd)
|
INT ExecuteIf(PARSED_COMMAND *Cmd)
|
||||||
{
|
{
|
||||||
INT result = FALSE; /* when set cause 'then' clause to be executed */
|
INT result = FALSE; /* when set cause 'then' clause to be executed */
|
||||||
LPTSTR param;
|
LPTSTR param;
|
||||||
LPTSTR Left = NULL, Right;
|
LPTSTR Left = NULL, Right;
|
||||||
|
|
||||||
if (Cmd->If.LeftArg)
|
if (Cmd->If.LeftArg)
|
||||||
{
|
{
|
||||||
Left = DoDelayedExpansion(Cmd->If.LeftArg);
|
Left = DoDelayedExpansion(Cmd->If.LeftArg);
|
||||||
if (!Left)
|
if (!Left)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
Right = DoDelayedExpansion(Cmd->If.RightArg);
|
Right = DoDelayedExpansion(Cmd->If.RightArg);
|
||||||
if (!Right)
|
if (!Right)
|
||||||
{
|
{
|
||||||
cmd_free(Left);
|
cmd_free(Left);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cmd->If.Operator == IF_CMDEXTVERSION)
|
if (Cmd->If.Operator == IF_CMDEXTVERSION)
|
||||||
{
|
{
|
||||||
/* IF CMDEXTVERSION n: check if Command Extensions version
|
/* IF CMDEXTVERSION n: check if Command Extensions version
|
||||||
* is greater or equal to n */
|
* is greater or equal to n */
|
||||||
DWORD n = _tcstoul(Right, ¶m, 10);
|
DWORD n = _tcstoul(Right, ¶m, 10);
|
||||||
if (*param != _T('\0'))
|
if (*param != _T('\0'))
|
||||||
{
|
{
|
||||||
error_syntax(Right);
|
error_syntax(Right);
|
||||||
cmd_free(Right);
|
cmd_free(Right);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
result = (2 >= n);
|
result = (2 >= n);
|
||||||
}
|
}
|
||||||
else if (Cmd->If.Operator == IF_DEFINED)
|
else if (Cmd->If.Operator == IF_DEFINED)
|
||||||
{
|
{
|
||||||
/* IF DEFINED var: check if environment variable exists */
|
/* IF DEFINED var: check if environment variable exists */
|
||||||
result = (GetEnvVarOrSpecial(Right) != NULL);
|
result = (GetEnvVarOrSpecial(Right) != NULL);
|
||||||
}
|
}
|
||||||
else if (Cmd->If.Operator == IF_ERRORLEVEL)
|
else if (Cmd->If.Operator == IF_ERRORLEVEL)
|
||||||
{
|
{
|
||||||
/* IF ERRORLEVEL n: check if last exit code is greater or equal to n */
|
/* IF ERRORLEVEL n: check if last exit code is greater or equal to n */
|
||||||
INT n = _tcstol(Right, ¶m, 10);
|
INT n = _tcstol(Right, ¶m, 10);
|
||||||
if (*param != _T('\0'))
|
if (*param != _T('\0'))
|
||||||
{
|
{
|
||||||
error_syntax(Right);
|
error_syntax(Right);
|
||||||
cmd_free(Right);
|
cmd_free(Right);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
result = (nErrorLevel >= n);
|
result = (nErrorLevel >= n);
|
||||||
}
|
}
|
||||||
else if (Cmd->If.Operator == IF_EXIST)
|
else if (Cmd->If.Operator == IF_EXIST)
|
||||||
{
|
{
|
||||||
/* IF EXIST filename: check if file exists (wildcards allowed) */
|
/* IF EXIST filename: check if file exists (wildcards allowed) */
|
||||||
StripQuotes(Right);
|
StripQuotes(Right);
|
||||||
|
|
||||||
if (_tcschr(Right, _T('*')) || _tcschr(Right, _T('?')))
|
if (_tcschr(Right, _T('*')) || _tcschr(Right, _T('?')))
|
||||||
{
|
{
|
||||||
WIN32_FIND_DATA f;
|
WIN32_FIND_DATA f;
|
||||||
HANDLE hFind = FindFirstFile(Right, &f);
|
HANDLE hFind = FindFirstFile(Right, &f);
|
||||||
if (hFind != INVALID_HANDLE_VALUE)
|
if (hFind != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = (GetFileAttributes(Right) != INVALID_FILE_ATTRIBUTES);
|
result = (GetFileAttributes(Right) != INVALID_FILE_ATTRIBUTES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Do case-insensitive string comparisons if /I specified */
|
/* Do case-insensitive string comparisons if /I specified */
|
||||||
INT (*StringCmp)(LPCTSTR, LPCTSTR) =
|
INT (*StringCmp)(LPCTSTR, LPCTSTR) =
|
||||||
(Cmd->If.Flags & IFFLAG_IGNORECASE) ? _tcsicmp : _tcscmp;
|
(Cmd->If.Flags & IFFLAG_IGNORECASE) ? _tcsicmp : _tcscmp;
|
||||||
|
|
||||||
if (Cmd->If.Operator == IF_STRINGEQ)
|
if (Cmd->If.Operator == IF_STRINGEQ)
|
||||||
{
|
{
|
||||||
/* IF str1 == str2 */
|
/* IF str1 == str2 */
|
||||||
result = StringCmp(Left, Right) == 0;
|
result = StringCmp(Left, Right) == 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = GenericCmp(StringCmp, Left, Right);
|
result = GenericCmp(StringCmp, Left, Right);
|
||||||
switch (Cmd->If.Operator)
|
switch (Cmd->If.Operator)
|
||||||
{
|
{
|
||||||
case IF_EQU: result = (result == 0); break;
|
case IF_EQU: result = (result == 0); break;
|
||||||
case IF_NEQ: result = (result != 0); break;
|
case IF_NEQ: result = (result != 0); break;
|
||||||
case IF_LSS: result = (result < 0); break;
|
case IF_LSS: result = (result < 0); break;
|
||||||
case IF_LEQ: result = (result <= 0); break;
|
case IF_LEQ: result = (result <= 0); break;
|
||||||
case IF_GTR: result = (result > 0); break;
|
case IF_GTR: result = (result > 0); break;
|
||||||
case IF_GEQ: result = (result >= 0); break;
|
case IF_GEQ: result = (result >= 0); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_free(Left);
|
cmd_free(Left);
|
||||||
cmd_free(Right);
|
cmd_free(Right);
|
||||||
|
|
||||||
if (result ^ ((Cmd->If.Flags & IFFLAG_NEGATE) != 0))
|
if (result ^ ((Cmd->If.Flags & IFFLAG_NEGATE) != 0))
|
||||||
{
|
{
|
||||||
/* full condition was true, do the command */
|
/* full condition was true, do the command */
|
||||||
return ExecuteCommand(Cmd->Subcommands);
|
return ExecuteCommand(Cmd->Subcommands);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* full condition was false, do the "else" command if there is one */
|
/* full condition was false, do the "else" command if there is one */
|
||||||
if (Cmd->Subcommands->Next)
|
if (Cmd->Subcommands->Next)
|
||||||
return ExecuteCommand(Cmd->Subcommands->Next);
|
return ExecuteCommand(Cmd->Subcommands->Next);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* 19-Jan-1998 (Eric Kohl)
|
* 19-Jan-1998 (Eric Kohl)
|
||||||
* Unicode ready!
|
* Unicode ready!
|
||||||
*
|
*
|
||||||
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -24,80 +24,80 @@
|
||||||
|
|
||||||
INT cmd_label (LPTSTR param)
|
INT cmd_label (LPTSTR param)
|
||||||
{
|
{
|
||||||
TCHAR szRootPath[] = _T("A:\\");
|
TCHAR szRootPath[] = _T("A:\\");
|
||||||
TCHAR szLabel[80];
|
TCHAR szLabel[80];
|
||||||
TCHAR szOldLabel[80];
|
TCHAR szOldLabel[80];
|
||||||
DWORD dwSerialNr;
|
DWORD dwSerialNr;
|
||||||
|
|
||||||
/* set empty label string */
|
/* set empty label string */
|
||||||
szLabel[0] = _T('\0');
|
szLabel[0] = _T('\0');
|
||||||
|
|
||||||
nErrorLevel = 0;
|
nErrorLevel = 0;
|
||||||
|
|
||||||
/* print help */
|
/* print help */
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_LABEL_HELP1);
|
ConOutResPaging(TRUE,STRING_LABEL_HELP1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get parameters */
|
/* get parameters */
|
||||||
if (param[0] != _T('\0') && param[1] == _T(':'))
|
if (param[0] != _T('\0') && param[1] == _T(':'))
|
||||||
{
|
{
|
||||||
szRootPath[0] = toupper(*param);
|
szRootPath[0] = toupper(*param);
|
||||||
param += 2;
|
param += 2;
|
||||||
while (_istspace(*param))
|
while (_istspace(*param))
|
||||||
param++;
|
param++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* get label of current drive */
|
/* get label of current drive */
|
||||||
TCHAR szCurPath[MAX_PATH];
|
TCHAR szCurPath[MAX_PATH];
|
||||||
GetCurrentDirectory (MAX_PATH, szCurPath);
|
GetCurrentDirectory (MAX_PATH, szCurPath);
|
||||||
szRootPath[0] = szCurPath[0];
|
szRootPath[0] = szCurPath[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
_tcsncat(szLabel, param, 79);
|
_tcsncat(szLabel, param, 79);
|
||||||
|
|
||||||
/* check root path */
|
/* check root path */
|
||||||
if (!IsValidPathName (szRootPath))
|
if (!IsValidPathName (szRootPath))
|
||||||
{
|
{
|
||||||
error_invalid_drive ();
|
error_invalid_drive ();
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (szLabel[0] == _T('\0'))
|
if (szLabel[0] == _T('\0'))
|
||||||
{
|
{
|
||||||
GetVolumeInformation(szRootPath, szOldLabel, 80, &dwSerialNr,
|
GetVolumeInformation(szRootPath, szOldLabel, 80, &dwSerialNr,
|
||||||
NULL, NULL, NULL, 0);
|
NULL, NULL, NULL, 0);
|
||||||
|
|
||||||
/* print drive info */
|
/* print drive info */
|
||||||
if (szOldLabel[0] != _T('\0'))
|
if (szOldLabel[0] != _T('\0'))
|
||||||
{
|
{
|
||||||
ConOutResPrintf(STRING_LABEL_HELP2, _totupper(szRootPath[0]), szOldLabel);
|
ConOutResPrintf(STRING_LABEL_HELP2, _totupper(szRootPath[0]), szOldLabel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConOutResPrintf(STRING_LABEL_HELP3, _totupper(szRootPath[0]));
|
ConOutResPrintf(STRING_LABEL_HELP3, _totupper(szRootPath[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print the volume serial number */
|
/* print the volume serial number */
|
||||||
ConOutResPrintf(STRING_LABEL_HELP4, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
|
ConOutResPrintf(STRING_LABEL_HELP4, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
|
||||||
|
|
||||||
ConOutResPuts(STRING_LABEL_HELP5);
|
ConOutResPuts(STRING_LABEL_HELP5);
|
||||||
|
|
||||||
ConInString(szLabel, 80);
|
ConInString(szLabel, 80);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetVolumeLabel(szRootPath, szLabel))
|
if (!SetVolumeLabel(szRootPath, szLabel))
|
||||||
{
|
{
|
||||||
ConOutFormatMessage(GetLastError());
|
ConOutFormatMessage(GetLastError());
|
||||||
nErrorLevel = 1;
|
nErrorLevel = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_LABEL */
|
#endif /* INCLUDE_CMD_LABEL */
|
||||||
|
|
|
@ -24,32 +24,32 @@ INT nNumberGroups;
|
||||||
|
|
||||||
VOID InitLocale (VOID)
|
VOID InitLocale (VOID)
|
||||||
{
|
{
|
||||||
TCHAR szBuffer[256];
|
TCHAR szBuffer[256];
|
||||||
|
|
||||||
/* date settings */
|
/* date settings */
|
||||||
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDATE, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDATE, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
||||||
cDateSeparator = szBuffer[0];
|
cDateSeparator = szBuffer[0];
|
||||||
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_IDATE | LOCALE_RETURN_NUMBER, (LPTSTR)&nDateFormat, sizeof(nDateFormat) / sizeof(TCHAR));
|
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_IDATE | LOCALE_RETURN_NUMBER, (LPTSTR)&nDateFormat, sizeof(nDateFormat) / sizeof(TCHAR));
|
||||||
|
|
||||||
/* time settings */
|
/* time settings */
|
||||||
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STIME, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STIME, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
||||||
cTimeSeparator = szBuffer[0];
|
cTimeSeparator = szBuffer[0];
|
||||||
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITIME | LOCALE_RETURN_NUMBER, (LPTSTR)&nTimeFormat, sizeof(nTimeFormat) / sizeof(TCHAR));
|
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITIME | LOCALE_RETURN_NUMBER, (LPTSTR)&nTimeFormat, sizeof(nTimeFormat) / sizeof(TCHAR));
|
||||||
|
|
||||||
/* number settings */
|
/* number settings */
|
||||||
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
||||||
cThousandSeparator = szBuffer[0];
|
cThousandSeparator = szBuffer[0];
|
||||||
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
||||||
cDecimalSeparator = szBuffer[0];
|
cDecimalSeparator = szBuffer[0];
|
||||||
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SGROUPING, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SGROUPING, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
||||||
nNumberGroups = _ttoi(szBuffer);
|
nNumberGroups = _ttoi(szBuffer);
|
||||||
#if 0
|
#if 0
|
||||||
/* days of week */
|
/* days of week */
|
||||||
for (i = 0; i < 7; i++)
|
for (i = 0; i < 7; i++)
|
||||||
{
|
{
|
||||||
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
|
||||||
_tcscpy (aszDayNames[(i+1)%7], szBuffer); /* little hack */
|
_tcscpy (aszDayNames[(i+1)%7], szBuffer); /* little hack */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,26 +57,26 @@ VOID InitLocale (VOID)
|
||||||
LPTSTR
|
LPTSTR
|
||||||
GetDateString(VOID)
|
GetDateString(VOID)
|
||||||
{
|
{
|
||||||
static TCHAR szDate[32];
|
static TCHAR szDate[32];
|
||||||
SYSTEMTIME t;
|
SYSTEMTIME t;
|
||||||
INT len;
|
INT len;
|
||||||
GetLocalTime(&t);
|
GetLocalTime(&t);
|
||||||
|
|
||||||
len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, sizeof szDate);
|
len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, sizeof szDate);
|
||||||
szDate[len - 1] = _T(' ');
|
szDate[len - 1] = _T(' ');
|
||||||
FormatDate(&szDate[len], &t, TRUE);
|
FormatDate(&szDate[len], &t, TRUE);
|
||||||
return szDate;
|
return szDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return time in hh:mm:ss.xx format. Used for $T in prompt and %TIME% */
|
/* Return time in hh:mm:ss.xx format. Used for $T in prompt and %TIME% */
|
||||||
LPTSTR
|
LPTSTR
|
||||||
GetTimeString(VOID)
|
GetTimeString(VOID)
|
||||||
{
|
{
|
||||||
static TCHAR szTime[12];
|
static TCHAR szTime[12];
|
||||||
SYSTEMTIME t;
|
SYSTEMTIME t;
|
||||||
GetLocalTime(&t);
|
GetLocalTime(&t);
|
||||||
_stprintf(szTime, _T("%2d%c%02d%c%02d%c%02d"),
|
_stprintf(szTime, _T("%2d%c%02d%c%02d%c%02d"),
|
||||||
t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator,
|
t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator,
|
||||||
t.wSecond, cDecimalSeparator, t.wMilliseconds / 10);
|
t.wSecond, cDecimalSeparator, t.wMilliseconds / 10);
|
||||||
return szTime;
|
return szTime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
* 01-Sep-1999 (Eric Kohl)
|
* 01-Sep-1999 (Eric Kohl)
|
||||||
* Started.
|
* Started.
|
||||||
*
|
*
|
||||||
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 28-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -17,56 +17,56 @@
|
||||||
|
|
||||||
INT CommandMemory (LPTSTR param)
|
INT CommandMemory (LPTSTR param)
|
||||||
{
|
{
|
||||||
MEMORYSTATUSEX msex;
|
MEMORYSTATUSEX msex;
|
||||||
TCHAR szMemoryLoad[20];
|
TCHAR szMemoryLoad[20];
|
||||||
TCHAR szTotalPhys[40];
|
TCHAR szTotalPhys[40];
|
||||||
TCHAR szAvailPhys[40];
|
TCHAR szAvailPhys[40];
|
||||||
TCHAR szTotalPageFile[40];
|
TCHAR szTotalPageFile[40];
|
||||||
TCHAR szAvailPageFile[40];
|
TCHAR szAvailPageFile[40];
|
||||||
TCHAR szTotalVirtual[40];
|
TCHAR szTotalVirtual[40];
|
||||||
TCHAR szAvailVirtual[40];
|
TCHAR szAvailVirtual[40];
|
||||||
BOOL (WINAPI *GlobalMemoryStatusEx)(LPMEMORYSTATUSEX);
|
BOOL (WINAPI *GlobalMemoryStatusEx)(LPMEMORYSTATUSEX);
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
ConOutResPaging(TRUE,STRING_MEMMORY_HELP1);
|
ConOutResPaging(TRUE,STRING_MEMMORY_HELP1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalMemoryStatusEx
|
GlobalMemoryStatusEx
|
||||||
= (BOOL (WINAPI *)(LPMEMORYSTATUSEX))GetProcAddress(GetModuleHandle(_T("KERNEL32")), "GlobalMemoryStatusEx");
|
= (BOOL (WINAPI *)(LPMEMORYSTATUSEX))GetProcAddress(GetModuleHandle(_T("KERNEL32")), "GlobalMemoryStatusEx");
|
||||||
if (GlobalMemoryStatusEx)
|
if (GlobalMemoryStatusEx)
|
||||||
{
|
{
|
||||||
msex.dwLength = sizeof(MEMORYSTATUSEX);
|
msex.dwLength = sizeof(MEMORYSTATUSEX);
|
||||||
GlobalMemoryStatusEx(&msex);
|
GlobalMemoryStatusEx(&msex);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MEMORYSTATUS ms;
|
MEMORYSTATUS ms;
|
||||||
ms.dwLength = sizeof(MEMORYSTATUS);
|
ms.dwLength = sizeof(MEMORYSTATUS);
|
||||||
GlobalMemoryStatus(&ms);
|
GlobalMemoryStatus(&ms);
|
||||||
msex.dwMemoryLoad = ms.dwMemoryLoad;
|
msex.dwMemoryLoad = ms.dwMemoryLoad;
|
||||||
msex.ullTotalPhys = ms.dwTotalPhys;
|
msex.ullTotalPhys = ms.dwTotalPhys;
|
||||||
msex.ullAvailPhys = ms.dwAvailPhys;
|
msex.ullAvailPhys = ms.dwAvailPhys;
|
||||||
msex.ullTotalPageFile = ms.dwTotalPageFile;
|
msex.ullTotalPageFile = ms.dwTotalPageFile;
|
||||||
msex.ullAvailPageFile = ms.dwAvailPageFile;
|
msex.ullAvailPageFile = ms.dwAvailPageFile;
|
||||||
msex.ullTotalVirtual = ms.dwTotalVirtual;
|
msex.ullTotalVirtual = ms.dwTotalVirtual;
|
||||||
msex.ullAvailVirtual = ms.dwAvailVirtual;
|
msex.ullAvailVirtual = ms.dwAvailVirtual;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConvertULargeInteger(msex.dwMemoryLoad, szMemoryLoad, 20, FALSE);
|
ConvertULargeInteger(msex.dwMemoryLoad, szMemoryLoad, 20, FALSE);
|
||||||
ConvertULargeInteger(msex.ullTotalPhys, szTotalPhys, 40, TRUE);
|
ConvertULargeInteger(msex.ullTotalPhys, szTotalPhys, 40, TRUE);
|
||||||
ConvertULargeInteger(msex.ullAvailPhys, szAvailPhys, 40, TRUE);
|
ConvertULargeInteger(msex.ullAvailPhys, szAvailPhys, 40, TRUE);
|
||||||
ConvertULargeInteger(msex.ullTotalPageFile, szTotalPageFile, 40, TRUE);
|
ConvertULargeInteger(msex.ullTotalPageFile, szTotalPageFile, 40, TRUE);
|
||||||
ConvertULargeInteger(msex.ullAvailPageFile, szAvailPageFile, 40, TRUE);
|
ConvertULargeInteger(msex.ullAvailPageFile, szAvailPageFile, 40, TRUE);
|
||||||
ConvertULargeInteger(msex.ullTotalVirtual, szTotalVirtual, 40, TRUE);
|
ConvertULargeInteger(msex.ullTotalVirtual, szTotalVirtual, 40, TRUE);
|
||||||
ConvertULargeInteger(msex.ullAvailVirtual, szAvailVirtual, 40, TRUE);
|
ConvertULargeInteger(msex.ullAvailVirtual, szAvailVirtual, 40, TRUE);
|
||||||
|
|
||||||
ConOutResPrintf(STRING_MEMMORY_HELP2,
|
ConOutResPrintf(STRING_MEMMORY_HELP2,
|
||||||
szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,
|
szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,
|
||||||
szAvailPageFile, szTotalVirtual, szAvailVirtual);
|
szAvailPageFile, szTotalVirtual, szAvailVirtual);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_MEMORY */
|
#endif /* INCLUDE_CMD_MEMORY */
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* 25 Aug 1999
|
* 25 Aug 1999
|
||||||
* started - Paolo Pantaleo <paolopan@freemail.it>
|
* started - Paolo Pantaleo <paolopan@freemail.it>
|
||||||
*
|
*
|
||||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -24,130 +24,128 @@
|
||||||
|
|
||||||
INT CommandMsgbox (LPTSTR param)
|
INT CommandMsgbox (LPTSTR param)
|
||||||
{
|
{
|
||||||
|
//used to parse command line
|
||||||
|
LPTSTR tmp;
|
||||||
|
|
||||||
//used to parse command line
|
//used to find window title (used as messagebox title)
|
||||||
LPTSTR tmp;
|
//and to find window handle to pass to MessageBox
|
||||||
|
HWND hWnd;
|
||||||
|
TCHAR buff[128];
|
||||||
|
|
||||||
//used to find window title (used as messagebox title)
|
//these are MessabeBox() parameters
|
||||||
//and to find window handle to pass to MessageBox
|
LPTSTR title, prompt = "";
|
||||||
HWND hWnd;
|
UINT uType = U_TYPE_INIT;
|
||||||
TCHAR buff[128];
|
|
||||||
|
|
||||||
//these are MessabeBox() parameters
|
/* set default title to window title */
|
||||||
LPTSTR title, prompt = "";
|
GetConsoleTitle(buff, 128);
|
||||||
UINT uType = U_TYPE_INIT;
|
title = buff;
|
||||||
|
|
||||||
/* set default title to window title */
|
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
||||||
GetConsoleTitle(buff, 128);
|
{
|
||||||
title = buff;
|
ConOutResPaging(TRUE,STRING_MSGBOX_HELP);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (_tcsncmp (param, _T("/?"), 2) == 0)
|
//yes here things are quite massed up :)
|
||||||
{
|
|
||||||
ConOutResPaging(TRUE,STRING_MSGBOX_HELP);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//yes here things are quite massed up :)
|
//skip spaces
|
||||||
|
while(_istspace(*param))
|
||||||
|
param++;
|
||||||
|
|
||||||
//skip spaces
|
//search for type of messagebox (ok, okcancel, ...)
|
||||||
while(_istspace(*param))
|
if (_tcsnicmp(param, _T("ok "), 3) == 0)
|
||||||
param++;
|
{
|
||||||
|
uType |= MB_ICONEXCLAMATION | MB_OK;
|
||||||
//search for type of messagebox (ok, okcancel, ...)
|
param += 3;
|
||||||
if (_tcsnicmp(param, _T("ok "), 3) == 0)
|
}
|
||||||
{
|
else if (_tcsnicmp(param, _T("okcancel "), 9) == 0)
|
||||||
uType |= MB_ICONEXCLAMATION | MB_OK;
|
{
|
||||||
param += 3;
|
uType |= MB_ICONQUESTION | MB_OKCANCEL;
|
||||||
}
|
param += 9;
|
||||||
else if (_tcsnicmp(param, _T("okcancel "), 9) == 0)
|
}
|
||||||
{
|
else if (_tcsnicmp(param, _T("yesno "), 6) == 0)
|
||||||
uType |= MB_ICONQUESTION | MB_OKCANCEL;
|
{
|
||||||
param += 9;
|
uType |= MB_ICONQUESTION | MB_YESNO;
|
||||||
}
|
param += 6;
|
||||||
else if (_tcsnicmp(param, _T("yesno "), 6) == 0)
|
}
|
||||||
{
|
else if (_tcsnicmp(param, _T("yesnocancel "), 12) == 0)
|
||||||
uType |= MB_ICONQUESTION | MB_YESNO;
|
{
|
||||||
param += 6;
|
uType |= MB_ICONQUESTION | MB_YESNOCANCEL;
|
||||||
}
|
param += 12;
|
||||||
else if (_tcsnicmp(param, _T("yesnocancel "), 12) == 0)
|
}
|
||||||
{
|
else
|
||||||
uType |= MB_ICONQUESTION | MB_YESNOCANCEL;
|
{
|
||||||
param += 12;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef _SYNTAX_CHECK
|
#ifdef _SYNTAX_CHECK
|
||||||
error_req_param_missing ();
|
error_req_param_missing ();
|
||||||
return 1;
|
return 1;
|
||||||
#else
|
#else
|
||||||
uType |= MB_ICONEXCLAMATION | MB_OK;
|
uType |= MB_ICONEXCLAMATION | MB_OK;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//skip spaces
|
||||||
//skip spaces
|
while(_istspace(*param))
|
||||||
while(_istspace(*param))
|
param++;
|
||||||
param++;
|
|
||||||
|
|
||||||
#ifdef _SYNTAX_CHECK
|
#ifdef _SYNTAX_CHECK
|
||||||
//if reached end of string
|
//if reached end of string
|
||||||
//it is an error becuase we do not yet have prompt
|
//it is an error becuase we do not yet have prompt
|
||||||
if (*param == 0)
|
if (*param == 0)
|
||||||
{
|
{
|
||||||
error_req_param_missing ();
|
error_req_param_missing ();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//search for "title"
|
//search for "title"
|
||||||
tmp = param;
|
tmp = param;
|
||||||
|
|
||||||
if (*param == '"')
|
if (*param == '"')
|
||||||
{
|
{
|
||||||
tmp = _tcschr(param + 1, '"');
|
tmp = _tcschr(param + 1, '"');
|
||||||
if (tmp)
|
if (tmp)
|
||||||
{
|
{
|
||||||
*tmp = 0;
|
*tmp = 0;
|
||||||
title = param + 1;
|
title = param + 1;
|
||||||
tmp++;
|
tmp++;
|
||||||
param = tmp;
|
param = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//skip spaces
|
//skip spaces
|
||||||
while(_istspace(*param))
|
while(_istspace(*param))
|
||||||
param++;
|
param++;
|
||||||
|
|
||||||
#ifdef _SYNTAX_CHECK
|
#ifdef _SYNTAX_CHECK
|
||||||
//get prompt
|
//get prompt
|
||||||
if (*param == 0)
|
if (*param == 0)
|
||||||
{
|
{
|
||||||
error_req_param_missing ();
|
error_req_param_missing ();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
prompt = param;
|
prompt = param;
|
||||||
|
|
||||||
hWnd=GetConsoleWindow ();
|
hWnd=GetConsoleWindow ();
|
||||||
|
|
||||||
switch (MessageBox(hWnd, prompt, title, uType))
|
switch (MessageBox(hWnd, prompt, title, uType))
|
||||||
{
|
{
|
||||||
case IDYES:
|
case IDYES:
|
||||||
case IDOK:
|
case IDOK:
|
||||||
nErrorLevel = 10;
|
nErrorLevel = 10;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDNO:
|
case IDNO:
|
||||||
nErrorLevel = 11;
|
nErrorLevel = 11;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDCANCEL:
|
case IDCANCEL:
|
||||||
nErrorLevel = 12;
|
nErrorLevel = 12;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* INCLUDE_CMD_MSGBOX */
|
#endif /* INCLUDE_CMD_MSGBOX */
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,8 +22,8 @@
|
||||||
* 24-Jan-1999 (Eric Kohl)
|
* 24-Jan-1999 (Eric Kohl)
|
||||||
* Fixed Win32 environment handling.
|
* Fixed Win32 environment handling.
|
||||||
*
|
*
|
||||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
|
||||||
|
@ -35,53 +35,52 @@
|
||||||
|
|
||||||
INT cmd_path (LPTSTR param)
|
INT cmd_path (LPTSTR param)
|
||||||
{
|
{
|
||||||
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
|
{
|
||||||
|
ConOutResPaging(TRUE,STRING_PATH_HELP1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
nErrorLevel = 0;
|
||||||
{
|
|
||||||
ConOutResPaging(TRUE,STRING_PATH_HELP1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
nErrorLevel = 0;
|
/* if param is empty, display the PATH environment variable */
|
||||||
|
if (!param || !*param)
|
||||||
|
{
|
||||||
|
DWORD dwBuffer;
|
||||||
|
LPTSTR pszBuffer;
|
||||||
|
|
||||||
/* if param is empty, display the PATH environment variable */
|
pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||||
if (!param || !*param)
|
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
|
||||||
{
|
if (dwBuffer == 0)
|
||||||
DWORD dwBuffer;
|
{
|
||||||
LPTSTR pszBuffer;
|
cmd_free(pszBuffer);
|
||||||
|
ConOutResPrintf(STRING_VOL_HELP2, _T("PATH"));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (dwBuffer > ENV_BUFFER_SIZE)
|
||||||
|
{
|
||||||
|
pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
|
||||||
|
GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
ConOutPrintf (_T("PATH=%s\n"), pszBuffer);
|
||||||
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
|
cmd_free (pszBuffer);
|
||||||
if (dwBuffer == 0)
|
|
||||||
{
|
|
||||||
cmd_free(pszBuffer);
|
|
||||||
ConOutResPrintf(STRING_VOL_HELP2, _T("PATH"));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (dwBuffer > ENV_BUFFER_SIZE)
|
|
||||||
{
|
|
||||||
pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
|
|
||||||
GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConOutPrintf (_T("PATH=%s\n"), pszBuffer);
|
return 0;
|
||||||
cmd_free (pszBuffer);
|
}
|
||||||
|
|
||||||
return 0;
|
/* skip leading '=' */
|
||||||
}
|
if (*param == _T('='))
|
||||||
|
param++;
|
||||||
|
|
||||||
/* skip leading '=' */
|
/* set PATH environment variable */
|
||||||
if (*param == _T('='))
|
if (!SetEnvironmentVariable (_T("PATH"), param))
|
||||||
param++;
|
{
|
||||||
|
nErrorLevel = 1;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* set PATH environment variable */
|
return 0;
|
||||||
if (!SetEnvironmentVariable (_T("PATH"), param))
|
|
||||||
{
|
|
||||||
nErrorLevel = 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -30,29 +30,28 @@
|
||||||
* ?? Extend to include functionality of CHOICE if switch chars
|
* ?? Extend to include functionality of CHOICE if switch chars
|
||||||
* specified.
|
* specified.
|
||||||
*
|
*
|
||||||
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
|
* 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>
|
||||||
* Remove all hardcode string to En.rc
|
* Remove all hardcoded strings in En.rc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
INT cmd_pause (LPTSTR param)
|
INT cmd_pause (LPTSTR param)
|
||||||
{
|
{
|
||||||
|
TRACE ("cmd_pause: \'%s\')\n", debugstr_aw(param));
|
||||||
|
|
||||||
TRACE ("cmd_pause: \'%s\')\n", debugstr_aw(param));
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
|
{
|
||||||
|
ConOutResPaging(TRUE,STRING_PAUSE_HELP1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (*param)
|
||||||
{
|
ConOutPrintf (param);
|
||||||
ConOutResPaging(TRUE,STRING_PAUSE_HELP1);
|
else
|
||||||
return 0;
|
msg_pause ();
|
||||||
}
|
|
||||||
|
|
||||||
if (*param)
|
cgetchar ();
|
||||||
ConOutPrintf (param);
|
|
||||||
else
|
|
||||||
msg_pause ();
|
|
||||||
|
|
||||||
cgetchar ();
|
return 0;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue