1999-03-20 20:28:42 +00:00
|
|
|
/*
|
|
|
|
* TYPE.C - type internal command.
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
*
|
|
|
|
* 07/08/1998 (John P. Price)
|
|
|
|
* started.
|
|
|
|
*
|
|
|
|
* 07/12/98 (Rob Lake)
|
|
|
|
* Changed error messages
|
|
|
|
*
|
|
|
|
* 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
|
|
|
|
* added config.h include
|
|
|
|
*
|
|
|
|
* 07-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Added support for quoted arguments (type "test file.dat").
|
|
|
|
* Cleaned up.
|
|
|
|
*
|
|
|
|
* 19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
|
|
|
* Unicode and redirection ready!
|
1999-11-27 19:14:59 +00:00
|
|
|
*
|
|
|
|
* 19-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>)
|
|
|
|
* Added multiple file support (copied from y.c)
|
1999-03-20 20:28:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#ifdef INCLUDE_CMD_TYPE
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "cmd.h"
|
|
|
|
|
|
|
|
|
|
|
|
INT cmd_type (LPTSTR cmd, LPTSTR param)
|
|
|
|
{
|
1999-11-27 19:14:59 +00:00
|
|
|
TCHAR buff[256];
|
2003-01-17 00:31:33 +00:00
|
|
|
HANDLE hFile, hConsoleOut;
|
1999-11-27 19:14:59 +00:00
|
|
|
DWORD dwRead;
|
|
|
|
DWORD dwWritten;
|
|
|
|
BOOL bRet;
|
|
|
|
INT argc,i;
|
|
|
|
LPTSTR *argv;
|
2003-01-17 00:31:33 +00:00
|
|
|
LPTSTR errmsg;
|
1999-11-27 19:14:59 +00:00
|
|
|
|
|
|
|
hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
|
1999-03-20 20:28:42 +00:00
|
|
|
if (!_tcsncmp (param, _T("/?"), 2))
|
|
|
|
{
|
|
|
|
ConOutPuts (_T("Displays the contents of text files.\n\n"
|
|
|
|
"TYPE [drive:][path]filename"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*param)
|
|
|
|
{
|
|
|
|
error_req_param_missing ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-01-17 00:31:33 +00:00
|
|
|
argv = split (param, &argc, TRUE);
|
1999-11-27 19:14:59 +00:00
|
|
|
|
1999-11-29 18:25:05 +00:00
|
|
|
for (i = 0; i < argc; i++)
|
1999-11-27 19:14:59 +00:00
|
|
|
{
|
2003-01-17 00:31:33 +00:00
|
|
|
if (_T('/') == argv[i][0])
|
1999-11-27 19:14:59 +00:00
|
|
|
{
|
2003-01-17 00:31:33 +00:00
|
|
|
ConErrPrintf("Invalid option \"%s\"\n", argv[i] + 1);
|
1999-11-27 19:14:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-01-17 00:31:33 +00:00
|
|
|
hFile = CreateFile(argv[i],
|
|
|
|
GENERIC_READ,
|
|
|
|
FILE_SHARE_READ,NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,NULL);
|
1999-11-27 19:14:59 +00:00
|
|
|
|
2003-01-17 00:31:33 +00:00
|
|
|
if(hFile == INVALID_HANDLE_VALUE)
|
1999-11-27 19:14:59 +00:00
|
|
|
{
|
2003-01-17 00:31:33 +00:00
|
|
|
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;
|
|
|
|
}
|
1999-11-27 19:14:59 +00:00
|
|
|
|
2003-01-17 00:31:33 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
bRet = ReadFile(hFile,buff,sizeof(buff),&dwRead,NULL);
|
1999-11-27 19:14:59 +00:00
|
|
|
|
2003-01-17 00:31:33 +00:00
|
|
|
if (dwRead>0 && bRet)
|
|
|
|
WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL);
|
1999-11-27 19:14:59 +00:00
|
|
|
|
2003-01-17 00:31:33 +00:00
|
|
|
} while(dwRead>0 && bRet);
|
1999-11-27 19:14:59 +00:00
|
|
|
|
2003-01-17 00:31:33 +00:00
|
|
|
CloseHandle(hFile);
|
1999-11-27 19:14:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
freep (argv);
|
1999-03-20 20:28:42 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|