-
Notifications
You must be signed in to change notification settings - Fork 1
/
getNAME.c
executable file
·76 lines (70 loc) · 1.27 KB
/
getNAME.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
/* Copyright (c) 1979 Regents of the University of California */
#include <retrofit.h>
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
argc--, argv++;
while (argc > 0)
getfrom(*argv++), argc--;
exit(0);
}
getfrom(name)
char *name;
{
char headbuf[BUFSIZ];
char linbuf[BUFSIZ];
register char *cp;
int i = 0;
if (freopen(name, "r", stdin) == 0) {
perror(name);
exit(1);
}
for (;;) {
if (fgets(headbuf, sizeof headbuf, stdin) == NULL)
return;
if (headbuf[0] != '.')
continue;
if (headbuf[1] == 'T' && headbuf[2] == 'H')
break;
if (headbuf[1] == 't' && headbuf[2] == 'h')
break;
}
for (;;) {
if (fgets(linbuf, sizeof linbuf, stdin) == NULL)
return;
if (linbuf[0] != '.')
continue;
if (linbuf[1] == 'S' && linbuf[2] == 'H')
break;
if (linbuf[1] == 's' && linbuf[2] == 'h')
break;
}
trimln(headbuf);
printf("%s\t", headbuf);
for (;;) {
if (fgets(linbuf, sizeof linbuf, stdin) == NULL)
break;
if (linbuf[0] == '.') {
if (linbuf[1] == 'S' && linbuf[2] == 'H')
break;
if (linbuf[1] == 's' && linbuf[2] == 'h')
break;
}
trimln(linbuf);
if (i != 0)
printf(" ");
i++;
printf("%s", linbuf);
}
printf("\n");
}
trimln(cp)
register char *cp;
{
while (*cp)
cp++;
if (*--cp == '\n')
*cp = 0;
}