forked from qrush/unix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunknown.c
80 lines (71 loc) · 1.22 KB
/
unknown.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
char b[242];
char c[60];
int nread 1;
char buf[512];
main(argc,argv) int argc; char *argv[]; {
int l,isw,k,ifile,i,j;
if(--argc <= 0)
{ifile = 0;
argc = 0;
goto newl;
}
l = 1;
while(argc--)
{printf("%s:\n \n",argv[l]);
ifile = open(argv[l++],0);
if(ifile < 0)
{printf("cannot open input file\n");
exit();
}
newl:
isw = j = 0;
i = -1;
cont:
while((b[++i] = get(ifile)) != 0)
{if((b[i] >= 'a' & b[i] <= 'z') |
(b[i] >= 'A' & b[i] <= 'Z'))
{c[j++] = b[i];
goto cont;
}
if(b[i] == '-')
{c[j++] = b[i];
if((b[++i] = get(ifile)) != '\n')
{c[j++] = b[i];
goto cont;
}
if(j == 1)goto newl;
isw = 1;
i = -1;
while(((b[++i] = get(ifile)) == ' ')
| (b[i] == '\t') | (b[i] == '\n'));
c[j++] = b[i];
goto cont;
}
if(b[i] == '\n'){if(isw != 1)goto newl;
i = -1; }
if(isw == 1)
{k = 0;
c[j++] = '\n';
while(k < j)putchar(c[k++]);
}
isw = j = 0;
}
}
}
get(ifile) int ifile;{
char *ibuf;
static ibuf;
if(--nread){
return(*ibuf++);}
if(nread = read(ifile,buf,512)){
if(nread < 0)goto err;
ibuf = buf;
return(*ibuf++);
}
nread = 1;
return(0);
err:
nread = 1;
printf("read error\n");
return(0);
}