-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathman.c
211 lines (194 loc) · 3.75 KB
/
man.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#
/*
* man - intelligent man command
*
* Author: Bill Joy UCB August 25, 1977
*
* Man is an intelligent man command which obviates the need to know
* section numbers in the manual. Also if the standard output is a teletype and
* the option - is not given we pipe through "ssp" to eliminate piled
* up blank lines.
*
* Ported to Unix V6 release running on SimH PDP11/40
* Peter Collinson
* June 2023
*
* Needs Blll Joy's ssp binary installed to remove blank lines
*/
extern int fout;
int nossp;
/* some defines to allow for change */
#define MANBASE "/usr/doc/man"
main(argc, argv)
int argc;
char *argv[];
{
int i, pvec[2], section, io, tty[3];
/*
* pc: Don't think we need logging
io = open("/usr/adm/manlog", 1);
if (io > 0 && fork() == 0) {
char buf[100];
register char *cp;
fout = io;
seek(io, 0, 2);
if (getpw(getuid(), buf))
exit(1);
for (cp = buf; *cp && *cp != ':'; cp++)
continue;
*cp = 0;
printf("%c %-8s man", ttyn(1), buf);
for (i = 1; i <= argc; i++)
printf(" %s", argv[i]);
putchar('\n');
flush();
exit(0);
}
close(io);
*/
fout = 2;
if (chdir(MANBASE) < 0) {
printf("Can't chdir to %s\n", MANBASE);
exit(1);
}
argc--, argv++;
if (argv[0][0] == '-') {
argc--, argv++;
nossp++;
} else if (gtty(1, tty))
nossp++;
if (argc == 0) {
printf("Usage: man [ section ] name ...\n");
exit(1);
}
if (nossp == 0) {
pipe(pvec);
i = fork();
if (i != -1) {
if (i != 0) {
close(0);
close(pvec[1]);
dup(pvec[0]);
close(pvec[0]);
/* execl("/usr/pascal/ssp", "ssp", 0); */
execl("/bin/ssp", "ssp", 0);
execl("/usr/bin/ssp", "ssp", 0);
printf("Can't find ssp!\n");
execl("/bin/cat", "cat", 0);
printf("or cat - gott in himmel!\n");
exit(1);
}
close(pvec[0]);
close(1);
dup(pvec[1]);
close(pvec[1]);
fout = 1;
}
}
section = 0;
do {
if (argv[0][0] >= '0' && argv[0][0] <= '9' && !argv[0][1]) {
section = argv[0][0] - '0';
argc--, argv++;
if (argc == 0) {
printf("But what do you want from section %s?\n", argv[-1]);
exit(1);
}
continue;
}
manual(section, argv[0]);
argc--, argv++;
} while (argc > 0);
exit(0);
}
manual(section, name)
int section;
char *name;
{
char work[100];
char stbuf[36];
int last;
strcpy(work, "manx/");
strcat(work, name);
strcat(work, ".x");
last = strlen(work) - 1;
if (section == 0) {
for (section = '1'; section <= '9'; section++) {
work[3] = section;
work[last] = section;
if (stat(work, stbuf) >= 0)
break;
}
if (section > '9') {
printf("No section in the manual has %s in it\n", name);
return;
}
} else {
work[3] = section + '0';
work[last] = section + '0';
if (stat(work, stbuf) < 0) {
printf("%s is not in section %d of the manual\n", name, section);
return;
}
}
nroff(work);
}
nroff(cp)
char *cp;
{
int i;
i = fork();
if (i < 0) {
printf("No more processes\n");
exit(1);
}
if (i == 0) {
donroff("/bin/nroff", cp);
donroff("/usr/bin/nroff", cp);
printf("Can't find a nroff - come again\n");
exit(1);
}
while (wait(&i) != -1)
continue;
}
/* pc:
* added naa-man which is a changed version of the
* naa macros removing some of the aspects that don't
* work too well on modern screens
*/
donroff(nis, what)
char *nis, *what;
{
execl(nis, "nroff", "-h", "man0/naa-man", what, 0);
}
/*
* pc:
* These functions were all defined as
* register char *
* which caused the compiler to complain
* because the first two parameters are already
* in registers
*/
strcpy(to, from)
char *to, *from;
{
while (*to++ = *from++)
continue;
}
strcat(after, with)
char *after, *with;
{
while (*after)
after++;
strcpy(after, with);
}
strlen(src)
char *src;
{
register int len;
len = 0;
while (*src++) {
len++;
}
return(len);
}