2 * TYPE.C - type internal command.
6 * 07/08/1998 (John P. Price)
10 * Changed error messages
12 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
13 * added config.h include
15 * 07-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
16 * Added support for quoted arguments (type "test file.dat").
19 * 19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
20 * Unicode and redirection ready!
22 * 19-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>)
23 * Added multiple file support (copied from y.c)
28 #ifdef INCLUDE_CMD_TYPE
37 INT
cmd_type (LPTSTR cmd
, LPTSTR param
)
40 HANDLE hFile
, hConsoleOut
, hFind
;
46 WIN32_FIND_DATA FindData
;
48 hConsoleOut
=GetStdHandle (STD_OUTPUT_HANDLE
);
52 if (!_tcsncmp (param
, _T("/?"), 2))
54 ConOutPuts (_T("Displays the contents of text files.\n\n"
55 "TYPE [drive:][path]filename"));
61 error_req_param_missing ();
65 argv
= split (param
, &argc
);
67 for (i
= 0; i
< argc
; i
++)
69 hFind
=FindFirstFile(argv
[i
],&FindData
);
71 if (hFind
==INVALID_HANDLE_VALUE
)
73 ConErrPrintf("File not found - %s\n",argv
[i
]);
79 hFile
= CreateFile(FindData
.cFileName
,
83 FILE_ATTRIBUTE_NORMAL
,NULL
);
85 if(hFile
== INVALID_HANDLE_VALUE
)
87 ConErrPrintf("File not found - %s\n",FindData
.cFileName
);
93 bRet
= ReadFile(hFile
,buff
,sizeof(buff
),&dwRead
,NULL
);
96 WriteFile(hConsoleOut
,buff
,dwRead
,&dwWritten
,NULL
);
98 } while(dwRead
>0 && bRet
);
103 while(FindNextFile(hFind
,&FindData
));
111 error_too_many_parameters (_T("\b \b"));
116 hFile = CreateFile (arg[0], GENERIC_READ, FILE_SHARE_READ,
118 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
121 if (hFile == INVALID_HANDLE_VALUE)
123 error_sfile_not_found (param);
130 bResult = ReadFile (hFile, szBuffer, sizeof(szBuffer),
133 WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szBuffer, dwBytesRead,
134 &dwBytesWritten, NULL);
136 while (bResult && dwBytesRead > 0);