Added MORE command.
[reactos.git] / rosapps / cmd / type.c
1 /*
2 * TYPE.C - type internal command.
3 *
4 * History:
5 *
6 * 07/08/1998 (John P. Price)
7 * started.
8 *
9 * 07/12/98 (Rob Lake)
10 * Changed error messages
11 *
12 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
13 * added config.h include
14 *
15 * 07-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
16 * Added support for quoted arguments (type "test file.dat").
17 * Cleaned up.
18 *
19 * 19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
20 * Unicode and redirection ready!
21 */
22
23 #include "config.h"
24
25 #ifdef INCLUDE_CMD_TYPE
26
27 #include <windows.h>
28 #include <tchar.h>
29 #include <string.h>
30
31 #include "cmd.h"
32
33
34 INT cmd_type (LPTSTR cmd, LPTSTR param)
35 {
36 TCHAR szBuffer[256];
37 HANDLE hFile;
38 DWORD dwBytesRead;
39 DWORD dwBytesWritten;
40 BOOL bResult;
41 INT args;
42 LPTSTR *arg;
43
44 if (!_tcsncmp (param, _T("/?"), 2))
45 {
46 ConOutPuts (_T("Displays the contents of text files.\n\n"
47 "TYPE [drive:][path]filename"));
48 return 0;
49 }
50
51 if (!*param)
52 {
53 error_req_param_missing ();
54 return 1;
55 }
56
57 arg = split (param, &args);
58
59 if (args > 1)
60 {
61 error_too_many_parameters (_T("\b \b"));
62 freep (arg);
63 return 1;
64 }
65
66 hFile = CreateFile (arg[0], GENERIC_READ, FILE_SHARE_READ,
67 NULL, OPEN_EXISTING,
68 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
69 NULL);
70
71 if (hFile == INVALID_HANDLE_VALUE)
72 {
73 error_sfile_not_found (param);
74 freep (arg);
75 return 1;
76 }
77
78 do
79 {
80 bResult = ReadFile (hFile, szBuffer, sizeof(szBuffer),
81 &dwBytesRead, NULL);
82 if (dwBytesRead)
83 WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szBuffer, dwBytesRead,
84 &dwBytesWritten, NULL);
85 }
86 while (bResult && dwBytesRead > 0);
87
88 CloseHandle (hFile);
89 freep (arg);
90
91 return 0;
92 }
93
94 #endif