}
/* build parameter array */
- arg = split (param, &argc);
+ arg = split (param, &argc, FALSE);
/* check for options */
for (i = 0; i < argc; i++)
}
/* get parameters */
- arg = split (param, &args);
+ arg = split (param, &args, FALSE);
/* save old code page */
uOldCodePage = GetConsoleCP ();
}
/* build parameter array */
- arg = split (param, &argc);
+ arg = split (param, &argc, FALSE);
/* evaluate arguments */
if (argc > 0)
-/* $Id: cmd.h,v 1.21 2001/02/03 10:37:51 ekohl Exp $
+/* $Id: cmd.h,v 1.22 2003/01/17 00:31:32 gvg Exp $
*
* CMD.H - header file for the modules in CMD.EXE
*
/* Prototypes for MISC.C */
TCHAR cgetchar (VOID);
BOOL CheckCtrlBreak (INT);
-LPTSTR *split (LPTSTR, LPINT);
+LPTSTR *split (LPTSTR, LPINT, BOOL);
VOID freep (LPTSTR *);
LPTSTR stpcpy (LPTSTR, LPTSTR);
BOOL IsValidPathName (LPCTSTR);
-/* $Id: copy.c,v 1.7 2000/04/08 14:50:47 ekohl Exp $
+/* $Id: copy.c,v 1.8 2003/01/17 00:31:32 gvg Exp $
*
* COPY.C -- copy internal command.
*
return 1;
}
- p = split (rest, &argc);
+ p = split (rest, &argc, FALSE);
if (argc == 0)
{
}
/* build parameter array */
- arg = split (param, &argc);
+ arg = split (param, &argc, FALSE);
/* check for options */
for (i = 0; i < argc; i++)
return 0;
}
- arg = split (param, &args);
+ arg = split (param, &args, FALSE);
if (args > 0)
{
else
szParam = param;
- arg = split (szParam, &argc);
+ arg = split (szParam, &argc, FALSE);
for (i = 0; i < argc; i++)
PrintDiskInfo (arg[i]);
}
else
{
- p = split (param, &argc);
+ p = split (param, &argc, FALSE);
if (argc > 1)
{
/*JPP 20-Jul-1998 use standard error message */
}
else
{
- p = split (param, &argc);
+ p = split (param, &argc, FALSE);
if (argc > 1)
{
/*JPP 20-Jul-1998 use standard error message */
}
/* get parameters */
- arg = split (param, &args);
+ arg = split (param, &args, FALSE);
if (args > 2)
{
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
-//#include <stdarg.h>
#include <stdio.h>
#include <tchar.h>
return TRUE;
}
+/* add new entry for new argument */
+static BOOL add_entry (LPINT ac, LPTSTR **arg, LPTSTR entry)
+{
+ LPTSTR q;
+ LPTSTR *oldarg;
+
+ q = malloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
+ if (NULL == q)
+ {
+ return FALSE;
+ }
+ _tcscpy (q, entry);
+
+ oldarg = *arg;
+ *arg = realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
+ if (NULL == *arg)
+ {
+ *arg = oldarg;
+ return FALSE;
+ }
+
+ /* save new entry */
+ (*arg)[*ac] = q;
+ (*arg)[++(*ac)] = NULL;
+
+ return TRUE;
+}
+
+static BOOL expand (LPINT ac, LPTSTR **arg, LPTSTR pattern)
+{
+ HANDLE hFind;
+ WIN32_FIND_DATA FindData;
+ BOOL ok;
+
+ hFind = FindFirstFile (pattern, &FindData);
+ if (INVALID_HANDLE_VALUE != hFind)
+ {
+ do
+ {
+ ok = add_entry(ac, arg, FindData.cFileName);
+ } while (FindNextFile (hFind, &FindData) && ok);
+ FindClose (hFind);
+ }
+ else
+ {
+ ok = add_entry(ac, arg, pattern);
+ }
+
+ return ok;
+}
/*
* split - splits a line up into separate arguments, deliminators
* are spaces and slashes ('/').
*/
-LPTSTR *split (LPTSTR s, LPINT args)
+LPTSTR *split (LPTSTR s, LPINT args, BOOL expand_wildcards)
{
LPTSTR *arg;
- LPTSTR *p;
LPTSTR start;
LPTSTR q;
INT ac;
/* a word was found */
if (s != start)
{
- /* add new entry for new argument */
- arg = realloc (p = arg, (ac + 2) * sizeof (LPTSTR));
- if (!arg)
- {
- freep (p);
- return NULL;
- }
-
- /* create new entry */
- q = arg[ac] = malloc (((len = s - start) + 1) * sizeof (TCHAR));
- arg[++ac] = NULL;
+ q = malloc (((len = s - start) + 1) * sizeof (TCHAR));
if (!q)
{
- freep (arg);
return NULL;
}
memcpy (q, start, len * sizeof (TCHAR));
q[len] = _T('\0');
+ if (expand_wildcards && _T('/') != *start &&
+ (NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
+ {
+ if (! expand(&ac, &arg, q))
+ {
+ free (q);
+ freep (arg);
+ return NULL;
+ }
+ }
+ else
+ {
+ if (! add_entry(&ac, &arg, q))
+ {
+ free (q);
+ freep (arg);
+ return NULL;
+ }
+ }
+ free (q);
}
/* adjust string pointer if quoted (") */
return 0;
}
- arg = split (param, &argc);
+ arg = split (param, &argc, FALSE);
nFiles = argc;
/* read options */
}
/* split the argument list */
- arg = split(param, &args);
+ arg = split(param, &args, FALSE);
if (args < 2)
{
}
/* build parameter array */
- arg = split (param, &argc);
+ arg = split (param, &argc, FALSE);
/* check for options */
for (i = 0; i < argc; i++)
}
- p = split (param,&argc);
+ p = split (param, &argc, FALSE);
//read options
for (i = 0; i < argc; i++)
INT cmd_type (LPTSTR cmd, LPTSTR param)
{
TCHAR buff[256];
- HANDLE hFile, hConsoleOut, hFind;
+ HANDLE hFile, hConsoleOut;
DWORD dwRead;
DWORD dwWritten;
BOOL bRet;
INT argc,i;
LPTSTR *argv;
- WIN32_FIND_DATA FindData;
+ LPTSTR errmsg;
hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE);
-
-
if (!_tcsncmp (param, _T("/?"), 2))
{
ConOutPuts (_T("Displays the contents of text files.\n\n"
return 1;
}
- argv = split (param, &argc);
+ argv = split (param, &argc, TRUE);
for (i = 0; i < argc; i++)
{
- hFind=FindFirstFile(argv[i],&FindData);
-
- if (hFind==INVALID_HANDLE_VALUE)
+ if (_T('/') == argv[i][0])
{
- ConErrPrintf("File not found - %s\n",argv[i]);
+ ConErrPrintf("Invalid option \"%s\"\n", argv[i] + 1);
continue;
}
+ hFile = CreateFile(argv[i],
+ GENERIC_READ,
+ FILE_SHARE_READ,NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,NULL);
- do
+ if(hFile == INVALID_HANDLE_VALUE)
{
- hFile = CreateFile(FindData.cFileName,
- GENERIC_READ,
- FILE_SHARE_READ,NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,NULL);
-
- if(hFile == INVALID_HANDLE_VALUE)
- {
- ConErrPrintf("File not found - %s\n",FindData.cFileName);
- continue;
- }
+ FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_IGNORE_INSERTS |
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &errmsg,
+ 0,
+ NULL);
+ ConErrPrintf ("%s - %s", argv[i], errmsg);
+ LocalFree (errmsg);
+ continue;
+ }
- do
- {
- bRet = ReadFile(hFile,buff,sizeof(buff),&dwRead,NULL);
+ do
+ {
+ bRet = ReadFile(hFile,buff,sizeof(buff),&dwRead,NULL);
- if (dwRead>0 && bRet)
- WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL);
+ if (dwRead>0 && bRet)
+ WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL);
- } while(dwRead>0 && bRet);
-
- CloseHandle(hFile);
+ } while(dwRead>0 && bRet);
- }
- while(FindNextFile(hFind,&FindData));
-
- FindClose(hFind);
+ CloseHandle(hFile);
}
-/*
- if (args > 1)
- {
- error_too_many_parameters (_T("\b \b"));
- freep (arg);
- return 1;
- }
-
- hFile = CreateFile (arg[0], GENERIC_READ, FILE_SHARE_READ,
- NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
- NULL);
-
- if (hFile == INVALID_HANDLE_VALUE)
- {
- error_sfile_not_found (param);
- freep (arg);
- return 1;
- }
-
- do
- {
- bResult = ReadFile (hFile, szBuffer, sizeof(szBuffer),
- &dwBytesRead, NULL);
- if (dwBytesRead)
- WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szBuffer, dwBytesRead,
- &dwBytesWritten, NULL);
- }
- while (bResult && dwBytesRead > 0);
-
- CloseHandle (hFile);
- */
freep (argv);
return 0;