Fixed obvious typos.
[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 * 19-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>)
23 * Added multiple file support (copied from y.c)
24 */
25
26 #include "config.h"
27
28 #ifdef INCLUDE_CMD_TYPE
29
30 #include <windows.h>
31 #include <tchar.h>
32 #include <string.h>
33
34 #include "cmd.h"
35
36
37 INT cmd_type (LPTSTR cmd, LPTSTR param)
38 {
39 TCHAR buff[256];
40 HANDLE hFile, hConsoleOut, hFind;
41 DWORD dwRead;
42 DWORD dwWritten;
43 BOOL bRet;
44 INT argc,i;
45 LPTSTR *argv;
46 WIN32_FIND_DATA FindData;
47
48 hConsoleOut=GetStdHandle (STD_OUTPUT_HANDLE);
49
50
51
52 if (!_tcsncmp (param, _T("/?"), 2))
53 {
54 ConOutPuts (_T("Displays the contents of text files.\n\n"
55 "TYPE [drive:][path]filename"));
56 return 0;
57 }
58
59 if (!*param)
60 {
61 error_req_param_missing ();
62 return 1;
63 }
64
65 argv = split (param, &argc);
66
67 for (i = 0; i < argc; i++)
68 {
69 hFind=FindFirstFile(argv[i],&FindData);
70
71 if (hFind==INVALID_HANDLE_VALUE)
72 {
73 ConErrPrintf("File not found - %s\n",argv[i]);
74 continue;
75 }
76
77 do
78 {
79 hFile = CreateFile(FindData.cFileName,
80 GENERIC_READ,
81 FILE_SHARE_READ,NULL,
82 OPEN_EXISTING,
83 FILE_ATTRIBUTE_NORMAL,NULL);
84
85 if(hFile == INVALID_HANDLE_VALUE)
86 {
87 ConErrPrintf("File not found - %s\n",FindData.cFileName);
88 continue;
89 }
90
91 do
92 {
93 bRet = ReadFile(hFile,buff,sizeof(buff),&dwRead,NULL);
94
95 if (dwRead>0 && bRet)
96 WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL);
97
98 } while(dwRead>0 && bRet);
99
100 CloseHandle(hFile);
101
102 }
103 while(FindNextFile(hFind,&FindData));
104
105 FindClose(hFind);
106 }
107
108 /*
109 if (args > 1)
110 {
111 error_too_many_parameters (_T("\b \b"));
112 freep (arg);
113 return 1;
114 }
115
116 hFile = CreateFile (arg[0], GENERIC_READ, FILE_SHARE_READ,
117 NULL, OPEN_EXISTING,
118 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
119 NULL);
120
121 if (hFile == INVALID_HANDLE_VALUE)
122 {
123 error_sfile_not_found (param);
124 freep (arg);
125 return 1;
126 }
127
128 do
129 {
130 bResult = ReadFile (hFile, szBuffer, sizeof(szBuffer),
131 &dwBytesRead, NULL);
132 if (dwBytesRead)
133 WriteFile (GetStdHandle (STD_OUTPUT_HANDLE), szBuffer, dwBytesRead,
134 &dwBytesWritten, NULL);
135 }
136 while (bResult && dwBytesRead > 0);
137
138 CloseHandle (hFile);
139 */
140 freep (argv);
141
142 return 0;
143 }
144
145 #endif