getNAME.c revision 1.22 1 1.22 itojun /* $NetBSD: getNAME.c,v 1.22 2003/09/19 05:41:33 itojun Exp $ */
2 1.4 mrg
3 1.1 cgd /*-
4 1.3 tls * Copyright (c) 1980, 1993
5 1.3 tls * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.21 agc * 3. Neither the name of the University nor the names of its contributors
16 1.21 agc * may be used to endorse or promote products derived from this software
17 1.21 agc * without specific prior written permission.
18 1.21 agc *
19 1.21 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.21 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.21 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.21 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.21 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.21 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.21 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.21 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.21 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.21 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.21 agc * SUCH DAMAGE.
30 1.21 agc */
31 1.21 agc
32 1.21 agc /*-
33 1.21 agc * Copyright (c) 1997, Christos Zoulas
34 1.21 agc *
35 1.21 agc * Redistribution and use in source and binary forms, with or without
36 1.21 agc * modification, are permitted provided that the following conditions
37 1.21 agc * are met:
38 1.21 agc * 1. Redistributions of source code must retain the above copyright
39 1.21 agc * notice, this list of conditions and the following disclaimer.
40 1.21 agc * 2. Redistributions in binary form must reproduce the above copyright
41 1.21 agc * notice, this list of conditions and the following disclaimer in the
42 1.21 agc * documentation and/or other materials provided with the distribution.
43 1.1 cgd * 3. All advertising materials mentioning features or use of this software
44 1.1 cgd * must display the following acknowledgement:
45 1.1 cgd * This product includes software developed by the University of
46 1.1 cgd * California, Berkeley and its contributors.
47 1.10 christos * This product includes software developed by Christos Zoulas.
48 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
49 1.1 cgd * may be used to endorse or promote products derived from this software
50 1.1 cgd * without specific prior written permission.
51 1.1 cgd *
52 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.1 cgd * SUCH DAMAGE.
63 1.1 cgd */
64 1.1 cgd
65 1.4 mrg #include <sys/cdefs.h>
66 1.1 cgd #ifndef lint
67 1.4 mrg __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
68 1.4 mrg The Regents of the University of California. All rights reserved.\n");
69 1.3 tls #if 0
70 1.3 tls static char sccsid[] = "@(#)getNAME.c 8.1 (Berkeley) 6/30/93";
71 1.4 mrg #else
72 1.22 itojun __RCSID("$NetBSD: getNAME.c,v 1.22 2003/09/19 05:41:33 itojun Exp $");
73 1.3 tls #endif
74 1.1 cgd #endif /* not lint */
75 1.1 cgd
76 1.1 cgd /*
77 1.1 cgd * Get name sections from manual pages.
78 1.1 cgd * -t for building toc
79 1.1 cgd * -i for building intro entries
80 1.8 mrg * -w for querying type of manual source
81 1.14 christos * -v verbose
82 1.1 cgd * other apropos database
83 1.1 cgd */
84 1.11 perry #include <err.h>
85 1.14 christos #include <ctype.h>
86 1.1 cgd #include <stdio.h>
87 1.3 tls #include <stdlib.h>
88 1.1 cgd #include <string.h>
89 1.11 perry #include <unistd.h>
90 1.10 christos
91 1.10 christos static int tocrc;
92 1.10 christos static int intro;
93 1.10 christos static int typeflag;
94 1.14 christos static int verbose;
95 1.10 christos
96 1.10 christos #define SLOP 10 /* strlen(" () - ") < 10 */
97 1.10 christos
98 1.10 christos static char *linebuf = NULL;
99 1.10 christos static size_t maxlen = 0;
100 1.10 christos
101 1.10 christos
102 1.10 christos static void doname __P((char *));
103 1.10 christos static void dorefname __P((char *));
104 1.10 christos static void getfrom __P((char *));
105 1.10 christos static void oldman __P((char *, char *));
106 1.10 christos static void newman __P((char *, char *));
107 1.10 christos static void remcomma __P((char *, size_t *));
108 1.10 christos static void remquote __P((char *, size_t *));
109 1.10 christos static void fixxref __P((char *, size_t *));
110 1.10 christos static void split __P((char *, char *));
111 1.10 christos static void usage __P((void));
112 1.1 cgd
113 1.4 mrg int main __P((int, char *[]));
114 1.3 tls
115 1.16 augustss /* The .SH NAMEs that are allowed. */
116 1.16 augustss char *names[] = { "name", "namn", 0 };
117 1.16 augustss
118 1.3 tls int
119 1.1 cgd main(argc, argv)
120 1.1 cgd int argc;
121 1.3 tls char *argv[];
122 1.1 cgd {
123 1.1 cgd int ch;
124 1.1 cgd
125 1.14 christos while ((ch = getopt(argc, argv, "itvw")) != -1)
126 1.6 enami switch (ch) {
127 1.1 cgd case 'i':
128 1.1 cgd intro = 1;
129 1.1 cgd break;
130 1.1 cgd case 't':
131 1.1 cgd tocrc = 1;
132 1.1 cgd break;
133 1.14 christos case 'v':
134 1.14 christos verbose = 1;
135 1.14 christos break;
136 1.3 tls case 'w':
137 1.3 tls typeflag = 1;
138 1.3 tls break;
139 1.1 cgd case '?':
140 1.1 cgd default:
141 1.1 cgd usage();
142 1.1 cgd }
143 1.1 cgd argc -= optind;
144 1.1 cgd argv += optind;
145 1.1 cgd
146 1.1 cgd if (!*argv)
147 1.1 cgd usage();
148 1.1 cgd
149 1.1 cgd for (; *argv; ++argv)
150 1.1 cgd getfrom(*argv);
151 1.1 cgd exit(0);
152 1.1 cgd }
153 1.1 cgd
154 1.3 tls void
155 1.3 tls getfrom(pathname)
156 1.3 tls char *pathname;
157 1.1 cgd {
158 1.10 christos char *name;
159 1.10 christos char *line;
160 1.10 christos size_t len;
161 1.1 cgd
162 1.3 tls if (freopen(pathname, "r", stdin) == 0) {
163 1.10 christos warn("Cannot open `%s'", pathname);
164 1.1 cgd return;
165 1.1 cgd }
166 1.10 christos if ((name = strrchr(pathname, '/')) != NULL)
167 1.3 tls name++;
168 1.3 tls else
169 1.3 tls name = pathname;
170 1.1 cgd for (;;) {
171 1.10 christos if ((line = fgetln(stdin, &len)) == NULL) {
172 1.3 tls if (typeflag)
173 1.10 christos printf("%-60s\tUNKNOWN\n", pathname);
174 1.1 cgd return;
175 1.3 tls }
176 1.20 christos if (len < 3)
177 1.20 christos continue;
178 1.10 christos if (line[0] != '.')
179 1.1 cgd continue;
180 1.10 christos if ((line[1] == 'T' && line[2] == 'H') ||
181 1.10 christos (line[1] == 't' && line[2] == 'h'))
182 1.10 christos return oldman(pathname, name);
183 1.10 christos if (line[1] == 'D' && line[2] == 't')
184 1.10 christos return newman(pathname, name);
185 1.3 tls }
186 1.14 christos if (verbose)
187 1.14 christos warnx("missing .TH or .Dt section in `%s'", pathname);
188 1.10 christos }
189 1.10 christos
190 1.10 christos static void
191 1.10 christos oldman(pathname, name)
192 1.10 christos char *pathname, *name;
193 1.10 christos {
194 1.22 itojun char *line, *ext, *s, *newlinebuf;
195 1.10 christos size_t len, i, extlen;
196 1.10 christos size_t curlen = 0;
197 1.22 itojun size_t newmaxlen;
198 1.10 christos
199 1.3 tls if (typeflag) {
200 1.10 christos printf("%-60s\tOLD\n", pathname);
201 1.3 tls return;
202 1.1 cgd }
203 1.1 cgd for (;;) {
204 1.14 christos if ((line = fgetln(stdin, &len)) == NULL) {
205 1.14 christos if (verbose)
206 1.14 christos warnx("missing .SH section in `%s'", pathname);
207 1.1 cgd return;
208 1.14 christos }
209 1.20 christos if (len < 4)
210 1.20 christos continue;
211 1.10 christos if (line[0] != '.')
212 1.1 cgd continue;
213 1.10 christos if (line[1] == 'S' && line[2] == 'H')
214 1.1 cgd break;
215 1.10 christos if (line[1] == 's' && line[2] == 'h')
216 1.1 cgd break;
217 1.1 cgd }
218 1.10 christos
219 1.14 christos for (s = &line[3]; s < &line[len] &&
220 1.14 christos (isspace((unsigned char) *s) || *s == '"' || *s == '\''); s++)
221 1.14 christos continue;
222 1.14 christos if (s == &line[len]) {
223 1.14 christos warnx("missing argument to .SH in `%s'", pathname);
224 1.14 christos return;
225 1.14 christos }
226 1.16 augustss for (i = 0; names[i]; i++)
227 1.16 augustss if (strncasecmp(s, names[i], strlen(names[i])) == 0)
228 1.16 augustss break;
229 1.16 augustss if (names[i] == NULL) {
230 1.14 christos warnx("first .SH section is not \"NAME\" in `%s'", pathname);
231 1.14 christos return;
232 1.14 christos }
233 1.14 christos
234 1.1 cgd if (tocrc)
235 1.1 cgd doname(name);
236 1.10 christos
237 1.10 christos for (i = 0;; i++) {
238 1.10 christos if ((line = fgetln(stdin, &len)) == NULL)
239 1.1 cgd break;
240 1.10 christos if (line[0] == '.') {
241 1.13 fair if (line[1] == '\\' && line[2] == '"')
242 1.13 fair continue; /* [nt]roff comment */
243 1.10 christos if (line[1] == 'S' && line[2] == 'H')
244 1.1 cgd break;
245 1.10 christos if (line[1] == 's' && line[2] == 'h')
246 1.12 mrg break;
247 1.12 mrg if (line[1] == 'P' && line[2] == 'P')
248 1.1 cgd break;
249 1.1 cgd }
250 1.10 christos if (line[len - 1] == '\n') {
251 1.10 christos line[len - 1] = '\0';
252 1.10 christos len--;
253 1.10 christos }
254 1.10 christos if ((ext = strrchr(name, '.')) != NULL) {
255 1.10 christos ext++;
256 1.10 christos extlen = strlen(ext);
257 1.10 christos }
258 1.10 christos else
259 1.10 christos extlen = 0;
260 1.10 christos
261 1.10 christos if (maxlen + extlen < curlen + len + SLOP) {
262 1.22 itojun newmaxlen = 2 * (curlen + len) + SLOP + extlen;
263 1.22 itojun if ((newlinebuf = realloc(linebuf, newmaxlen)) == NULL)
264 1.17 drochner err(1, NULL);
265 1.22 itojun linebuf = newlinebuf;
266 1.22 itojun maxlen = newmaxlen;
267 1.10 christos }
268 1.3 tls if (i != 0)
269 1.10 christos linebuf[curlen++] = ' ';
270 1.10 christos (void)memcpy(&linebuf[curlen], line, len);
271 1.10 christos curlen += len;
272 1.10 christos linebuf[curlen] = '\0';
273 1.15 hubertf
274 1.15 hubertf if(!tocrc && !intro) {
275 1.15 hubertf /* change the \- into (N) - */
276 1.15 hubertf if ((s = strstr(linebuf, "\\-")) != NULL) {
277 1.15 hubertf (void)memmove(s + extlen + 3, s + 1,
278 1.15 hubertf curlen - (s + 1 - linebuf));
279 1.15 hubertf curlen--;
280 1.15 hubertf if (extlen) {
281 1.15 hubertf *s++ = '(';
282 1.15 hubertf while (*ext)
283 1.15 hubertf *s++ = *ext++;
284 1.15 hubertf *s++ = ')';
285 1.15 hubertf *s++ = ' ';
286 1.15 hubertf curlen += extlen + 3;
287 1.15 hubertf }
288 1.15 hubertf linebuf[curlen] = '\0';
289 1.8 mrg }
290 1.8 mrg }
291 1.3 tls }
292 1.10 christos
293 1.3 tls if (intro)
294 1.10 christos split(linebuf, name);
295 1.3 tls else
296 1.10 christos printf("%s\n", linebuf);
297 1.3 tls return;
298 1.10 christos }
299 1.10 christos
300 1.10 christos static void
301 1.10 christos newman(pathname, name)
302 1.10 christos char *pathname, *name;
303 1.10 christos {
304 1.22 itojun char *line, *ext, *s, *newlinebuf;
305 1.10 christos size_t len, i, extlen;
306 1.10 christos size_t curlen = 0;
307 1.22 itojun size_t newmaxlen;
308 1.3 tls
309 1.9 lukem if (typeflag) {
310 1.10 christos printf("%-60s\tNEW\n", pathname);
311 1.9 lukem return;
312 1.9 lukem }
313 1.3 tls for (;;) {
314 1.14 christos if ((line = fgetln(stdin, &len)) == NULL) {
315 1.14 christos if (verbose)
316 1.14 christos warnx("missing .Sh section in `%s'", pathname);
317 1.3 tls return;
318 1.14 christos }
319 1.10 christos if (line[0] != '.')
320 1.1 cgd continue;
321 1.10 christos if (line[1] == 'S' && line[2] == 'h')
322 1.3 tls break;
323 1.14 christos }
324 1.14 christos
325 1.14 christos for (s = &line[3]; s < &line[len] && isspace((unsigned char) *s); s++)
326 1.14 christos continue;
327 1.14 christos if (s == &line[len]) {
328 1.14 christos warnx("missing argument to .Sh in `%s'", pathname);
329 1.14 christos return;
330 1.14 christos }
331 1.16 augustss for (i = 0; names[i]; i++)
332 1.16 augustss if (strncasecmp(s, names[i], strlen(names[i])) == 0)
333 1.16 augustss break;
334 1.16 augustss if (names[i] == NULL) {
335 1.16 augustss warnx("first .SH section is not \"NAME\" in `%s'", pathname);
336 1.14 christos return;
337 1.3 tls }
338 1.10 christos
339 1.3 tls if (tocrc)
340 1.3 tls doname(name);
341 1.10 christos
342 1.10 christos for (i = 0;; i++) {
343 1.10 christos if ((line = fgetln(stdin, &len)) == NULL)
344 1.3 tls break;
345 1.10 christos
346 1.10 christos if (line[0] == '.') {
347 1.13 fair if (line[1] == '\\' && line[2] == '"')
348 1.13 fair continue; /* [nt]roff comment */
349 1.10 christos if (line[1] == 'S' && line[2] == 'h')
350 1.3 tls break;
351 1.1 cgd }
352 1.10 christos
353 1.10 christos if (line[len - 1] == '\n') {
354 1.10 christos line[len - 1] = '\0';
355 1.10 christos len--;
356 1.10 christos }
357 1.10 christos
358 1.10 christos if ((ext = strrchr(name, '.')) != NULL) {
359 1.10 christos ext++;
360 1.10 christos extlen = strlen(ext);
361 1.10 christos }
362 1.10 christos else
363 1.10 christos extlen = 0;
364 1.10 christos
365 1.10 christos if (maxlen + extlen < curlen + len + SLOP) {
366 1.22 itojun newmaxlen = 2 * (curlen + len) + SLOP + extlen;
367 1.22 itojun if ((newlinebuf = realloc(linebuf, newmaxlen)) == NULL)
368 1.17 drochner err(1, NULL);
369 1.22 itojun linebuf = newlinebuf;
370 1.22 itojun maxlen = newmaxlen;
371 1.10 christos }
372 1.10 christos
373 1.1 cgd if (i != 0)
374 1.10 christos linebuf[curlen++] = ' ';
375 1.10 christos
376 1.10 christos remcomma(line, &len);
377 1.10 christos
378 1.10 christos if (line[0] != '.') {
379 1.10 christos (void)memcpy(&linebuf[curlen], line, len);
380 1.10 christos curlen += len;
381 1.10 christos }
382 1.10 christos else {
383 1.10 christos remquote(line, &len);
384 1.10 christos fixxref(line, &len);
385 1.8 mrg
386 1.3 tls /*
387 1.8 mrg * Put section and dash between names and description.
388 1.3 tls */
389 1.10 christos if (line[1] == 'N' && line[2] == 'd') {
390 1.15 hubertf if(!tocrc && !intro) {
391 1.15 hubertf if (extlen) {
392 1.15 hubertf linebuf[curlen++] = '(';
393 1.15 hubertf while (*ext)
394 1.15 hubertf linebuf[curlen++] = *ext++;
395 1.15 hubertf linebuf[curlen++] = ')';
396 1.15 hubertf linebuf[curlen++] = ' ';
397 1.15 hubertf }
398 1.8 mrg }
399 1.10 christos linebuf[curlen++] = '-';
400 1.10 christos linebuf[curlen++] = ' ';
401 1.8 mrg }
402 1.3 tls /*
403 1.3 tls * Skip over macro names.
404 1.3 tls */
405 1.10 christos if (len <= 4)
406 1.10 christos continue;
407 1.10 christos (void)memcpy(&linebuf[curlen], &line[4], len - 4);
408 1.10 christos curlen += len - 4;
409 1.3 tls }
410 1.1 cgd }
411 1.10 christos linebuf[curlen] = '\0';
412 1.3 tls if (intro)
413 1.10 christos split(linebuf, name);
414 1.3 tls else
415 1.10 christos printf("%s\n", linebuf);
416 1.1 cgd }
417 1.1 cgd
418 1.10 christos /*
419 1.10 christos * convert " ," -> " "
420 1.10 christos */
421 1.10 christos static void
422 1.10 christos remcomma(line, len)
423 1.10 christos char *line;
424 1.10 christos size_t *len;
425 1.10 christos {
426 1.10 christos char *pline = line, *loc;
427 1.10 christos size_t plen = *len;
428 1.10 christos
429 1.10 christos while ((loc = memchr(pline, ' ', plen)) != NULL) {
430 1.10 christos plen -= loc - pline + 1;
431 1.10 christos pline = loc;
432 1.10 christos if (loc[1] == ',') {
433 1.10 christos (void)memcpy(loc, &loc[1], plen);
434 1.10 christos (*len)--;
435 1.10 christos }
436 1.10 christos else
437 1.10 christos pline++;
438 1.10 christos }
439 1.10 christos }
440 1.10 christos
441 1.10 christos /*
442 1.10 christos * Get rid of quotes in macros.
443 1.10 christos */
444 1.10 christos static
445 1.10 christos void remquote(line, len)
446 1.10 christos char *line;
447 1.10 christos size_t *len;
448 1.10 christos {
449 1.10 christos char *loc;
450 1.10 christos char *pline = &line[4];
451 1.10 christos size_t plen = *len - 4;
452 1.10 christos
453 1.10 christos if (*len < 4)
454 1.10 christos return;
455 1.10 christos
456 1.10 christos while ((loc = memchr(pline, '"', plen)) != NULL) {
457 1.10 christos plen -= loc - pline + 1;
458 1.10 christos pline = loc;
459 1.10 christos (void)memcpy(loc, &loc[1], plen);
460 1.10 christos (*len)--;
461 1.10 christos }
462 1.10 christos }
463 1.10 christos
464 1.10 christos /*
465 1.10 christos * Handle cross references
466 1.10 christos */
467 1.10 christos static void
468 1.10 christos fixxref(line, len)
469 1.10 christos char *line;
470 1.10 christos size_t *len;
471 1.1 cgd {
472 1.10 christos char *loc;
473 1.10 christos char *pline = &line[4];
474 1.10 christos size_t plen = *len - 4;
475 1.1 cgd
476 1.10 christos if (*len < 4)
477 1.10 christos return;
478 1.10 christos
479 1.10 christos if (line[1] == 'X' && line[2] == 'r') {
480 1.10 christos if ((loc = memchr(pline, ' ', plen)) != NULL) {
481 1.10 christos *loc++ = '(';
482 1.10 christos loc++;
483 1.10 christos *loc++ = ')';
484 1.10 christos *len = loc - line;
485 1.10 christos }
486 1.10 christos }
487 1.1 cgd }
488 1.1 cgd
489 1.10 christos static void
490 1.1 cgd doname(name)
491 1.1 cgd char *name;
492 1.1 cgd {
493 1.9 lukem char *dp = name, *ep;
494 1.1 cgd
495 1.1 cgd again:
496 1.1 cgd while (*dp && *dp != '.')
497 1.1 cgd putchar(*dp++);
498 1.1 cgd if (*dp)
499 1.1 cgd for (ep = dp+1; *ep; ep++)
500 1.1 cgd if (*ep == '.') {
501 1.1 cgd putchar(*dp++);
502 1.1 cgd goto again;
503 1.1 cgd }
504 1.1 cgd putchar('(');
505 1.1 cgd if (*dp)
506 1.1 cgd dp++;
507 1.1 cgd while (*dp)
508 1.1 cgd putchar (*dp++);
509 1.1 cgd putchar(')');
510 1.1 cgd putchar(' ');
511 1.1 cgd }
512 1.1 cgd
513 1.10 christos static void
514 1.1 cgd split(line, name)
515 1.1 cgd char *line, *name;
516 1.1 cgd {
517 1.9 lukem char *cp, *dp;
518 1.1 cgd char *sp, *sep;
519 1.1 cgd
520 1.3 tls cp = strchr(line, '-');
521 1.1 cgd if (cp == 0)
522 1.1 cgd return;
523 1.1 cgd sp = cp + 1;
524 1.1 cgd for (--cp; *cp == ' ' || *cp == '\t' || *cp == '\\'; cp--)
525 1.1 cgd ;
526 1.1 cgd *++cp = '\0';
527 1.1 cgd while (*sp && (*sp == ' ' || *sp == '\t'))
528 1.1 cgd sp++;
529 1.1 cgd for (sep = "", dp = line; dp && *dp; dp = cp, sep = "\n") {
530 1.3 tls cp = strchr(dp, ',');
531 1.1 cgd if (cp) {
532 1.9 lukem char *tp;
533 1.1 cgd
534 1.1 cgd for (tp = cp - 1; *tp == ' ' || *tp == '\t'; tp--)
535 1.1 cgd ;
536 1.1 cgd *++tp = '\0';
537 1.1 cgd for (++cp; *cp == ' ' || *cp == '\t'; cp++)
538 1.1 cgd ;
539 1.1 cgd }
540 1.1 cgd printf("%s%s\t", sep, dp);
541 1.1 cgd dorefname(name);
542 1.15 hubertf printf("\t- %s", sp);
543 1.1 cgd }
544 1.15 hubertf putchar('\n');
545 1.1 cgd }
546 1.1 cgd
547 1.10 christos static void
548 1.1 cgd dorefname(name)
549 1.1 cgd char *name;
550 1.1 cgd {
551 1.9 lukem char *dp = name, *ep;
552 1.1 cgd
553 1.1 cgd again:
554 1.1 cgd while (*dp && *dp != '.')
555 1.1 cgd putchar(*dp++);
556 1.1 cgd if (*dp)
557 1.1 cgd for (ep = dp+1; *ep; ep++)
558 1.1 cgd if (*ep == '.') {
559 1.1 cgd putchar(*dp++);
560 1.1 cgd goto again;
561 1.1 cgd }
562 1.1 cgd putchar('.');
563 1.1 cgd if (*dp)
564 1.1 cgd dp++;
565 1.1 cgd while (*dp)
566 1.1 cgd putchar (*dp++);
567 1.1 cgd }
568 1.1 cgd
569 1.10 christos static void
570 1.1 cgd usage()
571 1.1 cgd {
572 1.19 cgd
573 1.19 cgd (void)fprintf(stderr, "Usage: %s [-itw] file ...\n", getprogname());
574 1.1 cgd exit(1);
575 1.1 cgd }
576