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)
16 * Added support for quoted arguments (type "test file.dat").
19 * 19-Jan-1999 (Eric Kohl)
20 * Unicode and redirection ready!
22 * 19-Jan-1999 (Paolo Pantaleo <paolopan@freemail.it>)
23 * Added multiple file support (copied from y.c)
25 * 30-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
26 * Remove all hardcoded strings in En.rc
31 #ifdef INCLUDE_CMD_TYPE
34 INT
cmd_type(LPTSTR param
)
37 HANDLE hFile
, hConsoleOut
;
43 BOOL bFirstTime
= TRUE
;
45 hConsoleOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
47 if (!_tcsncmp(param
, _T("/?"), 2))
49 ConOutResPaging(TRUE
,STRING_TYPE_HELP1
);
55 error_req_param_missing();
59 argv
= split(param
, &argc
, TRUE
, FALSE
);
61 for (i
= 0; i
< argc
; i
++)
63 if (argv
[i
][0] == _T('/') && _tcslen(argv
[i
]) == 2 && _totupper(argv
[i
][1]) == _T('P'))
69 for (i
= 0; i
< argc
; i
++)
71 if (argv
[i
][0] == _T('/') && _totupper(argv
[i
][1]) != _T('P'))
73 ConErrResPrintf(STRING_TYPE_ERROR1
, argv
[i
] + 1);
76 if (argv
[i
][0] == _T('/') && _tcslen(argv
[i
]) == 2 && _totupper(argv
[i
][1]) == _T('P'))
83 hFile
= CreateFile(argv
[i
],
85 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
87 FILE_ATTRIBUTE_NORMAL
, NULL
);
89 if (hFile
== INVALID_HANDLE_VALUE
)
91 FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
|
92 FORMAT_MESSAGE_IGNORE_INSERTS
|
93 FORMAT_MESSAGE_FROM_SYSTEM
,
96 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
100 ConErrPrintf (_T("%s - %s"), argv
[i
], errmsg
);
108 while (FileGetString(hFile
, buff
, ARRAYSIZE(buff
)))
110 if (!ConOutPrintfPaging(bFirstTime
, _T("%s"), buff
))
122 while (ReadFile(hFile
, buff
, sizeof(buff
), &dwRet
, NULL
) && dwRet
> 0)
124 WriteFile(hConsoleOut
, buff
, dwRet
, &dwRet
, NULL
);