forked from FDOS/freecom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.c
92 lines (81 loc) · 1.68 KB
/
type.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* $Id$
* TYPE.C - type internal command
*
* Comments:
*
* 07/08/1998 (John P. Price)
* started.
*
* 07/12/98 (Rob Lake)
* - Changed error messages
*
* 27-Jul-1998 (John P Price <[email protected]>)
* - added config.h include
*
* 10-Aug-1998 ska
* - added ^Break checking
*
* 1999/01/24 ska
* add: support for CP/M style device names (openf.h)
*/
#include "../config.h"
#include <assert.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include "../include/cmdline.h"
#include "../include/command.h"
#include "../err_fcts.h"
#include "../include/openf.h"
#include "../strings.h"
int cmd_type(char *param)
{
char buf[256];
char **argv;
int argc, opts, ec = E_None;
int fd, len;
if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
return 1;
/* Because no option was passed into scanCmdline() no
option can have been processed */
assert(opts == 0);
if(!argc) {
error_req_param_missing();
ec = E_Useage;
goto errRet;
}
for(argc = 0; argv[argc]; ++argc) {
if((fd = devopen(argv[argc], O_RDONLY)) < 0) {
error_sfile_not_found(argv[argc]);
ec = E_Other;
break;
}
while((len = dos_read(fd, buf, sizeof(buf))) >= 0) {
char *bufp, *p;
if(cbreak) {
dos_close(fd);
ec = E_CBreak;
goto errRet;
}
bufp = buf;
for(p = buf; p < buf+len; p++) {
if(*p == 26) break; /* CTRL-Z */
if(*p == '\r' || *p == '\n') {
if(p > bufp) dos_write(1, bufp, p - bufp);
if(*p == '\n') dos_write(1, "\r\n", 2);
bufp = p + 1;
}
}
dos_write(1, bufp, p - bufp);
if (len == 0 || *p == 26) break;
}
dos_close(fd);
if(cbreak) {
ec = E_CBreak;
break;
}
}
errRet:
freep(argv);
return ec;
}