1*9eba1e42Sjoerg /* $NetBSD: getNAME.c,v 1.27 2011/08/29 20:41:06 joerg Exp $ */
28e6ab883Sagc
38e6ab883Sagc /*-
4ba3c0c1bSchristos * Copyright (c) 1997, Christos Zoulas. All rights reserved.
58e6ab883Sagc * Copyright (c) 1980, 1993
68e6ab883Sagc * The Regents of the University of California. All rights reserved.
78e6ab883Sagc *
88e6ab883Sagc * Redistribution and use in source and binary forms, with or without
98e6ab883Sagc * modification, are permitted provided that the following conditions
108e6ab883Sagc * are met:
118e6ab883Sagc * 1. Redistributions of source code must retain the above copyright
128e6ab883Sagc * notice, this list of conditions and the following disclaimer.
138e6ab883Sagc * 2. Redistributions in binary form must reproduce the above copyright
148e6ab883Sagc * notice, this list of conditions and the following disclaimer in the
158e6ab883Sagc * documentation and/or other materials provided with the distribution.
168e6ab883Sagc * 3. Neither the name of the University nor the names of its contributors
178e6ab883Sagc * may be used to endorse or promote products derived from this software
188e6ab883Sagc * without specific prior written permission.
198e6ab883Sagc *
208e6ab883Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
218e6ab883Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
228e6ab883Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
238e6ab883Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
248e6ab883Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
258e6ab883Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
268e6ab883Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
278e6ab883Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
288e6ab883Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
298e6ab883Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
308e6ab883Sagc * SUCH DAMAGE.
318e6ab883Sagc */
3216e14cfdSmrg
3316e14cfdSmrg #include <sys/cdefs.h>
3461f28255Scgd #ifndef lint
350c4ddb15Slukem __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
360c4ddb15Slukem The Regents of the University of California. All rights reserved.");
3783c7e415Stls #if 0
3883c7e415Stls static char sccsid[] = "@(#)getNAME.c 8.1 (Berkeley) 6/30/93";
3916e14cfdSmrg #else
40*9eba1e42Sjoerg __RCSID("$NetBSD: getNAME.c,v 1.27 2011/08/29 20:41:06 joerg Exp $");
4183c7e415Stls #endif
4261f28255Scgd #endif /* not lint */
4361f28255Scgd
4461f28255Scgd /*
4561f28255Scgd * Get name sections from manual pages.
4661f28255Scgd * -t for building toc
4761f28255Scgd * -i for building intro entries
48ef53ad13Smrg * -w for querying type of manual source
49f7ab9656Schristos * -v verbose
5061f28255Scgd * other apropos database
5161f28255Scgd */
523ed4e7c6Sperry #include <err.h>
53f7ab9656Schristos #include <ctype.h>
5461f28255Scgd #include <stdio.h>
5583c7e415Stls #include <stdlib.h>
5661f28255Scgd #include <string.h>
573ed4e7c6Sperry #include <unistd.h>
5861f28255Scgd
5904691c5eSchristos static int tocrc;
6004691c5eSchristos static int intro;
6104691c5eSchristos static int typeflag;
62f7ab9656Schristos static int verbose;
6361f28255Scgd
6404691c5eSchristos #define SLOP 10 /* strlen(" () - ") < 10 */
6504691c5eSchristos
6604691c5eSchristos static char *linebuf = NULL;
6704691c5eSchristos static size_t maxlen = 0;
6804691c5eSchristos
6904691c5eSchristos
701074321aSchristos static void doname(char *);
711074321aSchristos static void dorefname(char *);
721074321aSchristos static void getfrom(char *);
731074321aSchristos static void oldman(char *, char *);
741074321aSchristos static void newman(char *, char *);
751074321aSchristos static void remcomma(char *, size_t *);
761074321aSchristos static void remquote(char *, size_t *);
771074321aSchristos static void fixxref(char *, size_t *);
781074321aSchristos static void split(char *, char *);
79*9eba1e42Sjoerg __dead static void usage(void);
8004691c5eSchristos
811074321aSchristos int main(int, char *[]);
8283c7e415Stls
83e165b790Saugustss /* The .SH NAMEs that are allowed. */
841074321aSchristos static const char *names[] = { "name", "namn", 0 };
85e165b790Saugustss
8683c7e415Stls int
main(int argc,char * argv[])871074321aSchristos main(int argc, char *argv[])
8861f28255Scgd {
8961f28255Scgd int ch;
9061f28255Scgd
91f7ab9656Schristos while ((ch = getopt(argc, argv, "itvw")) != -1)
9261f28255Scgd switch (ch) {
9361f28255Scgd case 'i':
9461f28255Scgd intro = 1;
9561f28255Scgd break;
9661f28255Scgd case 't':
9761f28255Scgd tocrc = 1;
9861f28255Scgd break;
99f7ab9656Schristos case 'v':
100f7ab9656Schristos verbose = 1;
101f7ab9656Schristos break;
10283c7e415Stls case 'w':
10383c7e415Stls typeflag = 1;
10483c7e415Stls break;
10561f28255Scgd case '?':
10661f28255Scgd default:
10761f28255Scgd usage();
10861f28255Scgd }
10961f28255Scgd argc -= optind;
11061f28255Scgd argv += optind;
11161f28255Scgd
11261f28255Scgd if (!*argv)
11361f28255Scgd usage();
11461f28255Scgd
11561f28255Scgd for (; *argv; ++argv)
11661f28255Scgd getfrom(*argv);
1171074321aSchristos return 0;
11861f28255Scgd }
11961f28255Scgd
1201074321aSchristos static void
getfrom(char * pathname)1211074321aSchristos getfrom(char *pathname)
12261f28255Scgd {
12304691c5eSchristos char *name;
12404691c5eSchristos char *line;
12504691c5eSchristos size_t len;
12661f28255Scgd
12783c7e415Stls if (freopen(pathname, "r", stdin) == 0) {
12804691c5eSchristos warn("Cannot open `%s'", pathname);
12961f28255Scgd return;
13061f28255Scgd }
13104691c5eSchristos if ((name = strrchr(pathname, '/')) != NULL)
13283c7e415Stls name++;
13383c7e415Stls else
13483c7e415Stls name = pathname;
13561f28255Scgd for (;;) {
13604691c5eSchristos if ((line = fgetln(stdin, &len)) == NULL) {
13783c7e415Stls if (typeflag)
1381074321aSchristos (void)printf("%-60s\tUNKNOWN\n", pathname);
1391074321aSchristos if (verbose)
1401074321aSchristos warnx("missing .TH or .Dt section in `%s'",
1411074321aSchristos pathname);
14261f28255Scgd return;
14383c7e415Stls }
144f71c29c5Schristos if (len < 3)
145f71c29c5Schristos continue;
14604691c5eSchristos if (line[0] != '.')
14761f28255Scgd continue;
14804691c5eSchristos if ((line[1] == 'T' && line[2] == 'H') ||
1491074321aSchristos (line[1] == 't' && line[2] == 'h')) {
1501074321aSchristos oldman(pathname, name);
1511074321aSchristos return;
15283c7e415Stls }
1531074321aSchristos if (line[1] == 'D' && line[2] == 't') {
1541074321aSchristos newman(pathname, name);
1551074321aSchristos return;
1561074321aSchristos }
1571074321aSchristos }
15804691c5eSchristos }
15904691c5eSchristos
16004691c5eSchristos static void
oldman(char * pathname,char * name)1611074321aSchristos oldman(char *pathname, char *name)
16204691c5eSchristos {
163143464d1Sitojun char *line, *ext, *s, *newlinebuf;
16404691c5eSchristos size_t len, i, extlen;
16504691c5eSchristos size_t curlen = 0;
166143464d1Sitojun size_t newmaxlen;
16751630586Shubertf size_t ocurlen = -1;
16804691c5eSchristos
16983c7e415Stls if (typeflag) {
1701074321aSchristos (void)printf("%-60s\tOLD\n", pathname);
17183c7e415Stls return;
17261f28255Scgd }
17361f28255Scgd for (;;) {
174f7ab9656Schristos if ((line = fgetln(stdin, &len)) == NULL) {
175f7ab9656Schristos if (verbose)
176f7ab9656Schristos warnx("missing .SH section in `%s'", pathname);
17761f28255Scgd return;
178f7ab9656Schristos }
179f71c29c5Schristos if (len < 4)
180f71c29c5Schristos continue;
18104691c5eSchristos if (line[0] != '.')
18261f28255Scgd continue;
18304691c5eSchristos if (line[1] == 'S' && line[2] == 'H')
18461f28255Scgd break;
18504691c5eSchristos if (line[1] == 's' && line[2] == 'h')
18661f28255Scgd break;
18761f28255Scgd }
18804691c5eSchristos
189f7ab9656Schristos for (s = &line[3]; s < &line[len] &&
190f7ab9656Schristos (isspace((unsigned char) *s) || *s == '"' || *s == '\''); s++)
191f7ab9656Schristos continue;
192f7ab9656Schristos if (s == &line[len]) {
193f7ab9656Schristos warnx("missing argument to .SH in `%s'", pathname);
194f7ab9656Schristos return;
195f7ab9656Schristos }
196e165b790Saugustss for (i = 0; names[i]; i++)
197e165b790Saugustss if (strncasecmp(s, names[i], strlen(names[i])) == 0)
198e165b790Saugustss break;
199e165b790Saugustss if (names[i] == NULL) {
200f7ab9656Schristos warnx("first .SH section is not \"NAME\" in `%s'", pathname);
201f7ab9656Schristos return;
202f7ab9656Schristos }
203f7ab9656Schristos
20451630586Shubertf again:
20561f28255Scgd if (tocrc)
20661f28255Scgd doname(name);
20704691c5eSchristos
20804691c5eSchristos for (i = 0;; i++) {
20904691c5eSchristos if ((line = fgetln(stdin, &len)) == NULL)
21061f28255Scgd break;
21104691c5eSchristos if (line[0] == '.') {
212c90e2a4bSfair if (line[1] == '\\' && line[2] == '"')
213c90e2a4bSfair continue; /* [nt]roff comment */
21404691c5eSchristos if (line[1] == 'S' && line[2] == 'H')
21561f28255Scgd break;
21604691c5eSchristos if (line[1] == 's' && line[2] == 'h')
21761f28255Scgd break;
2182ccff623Smrg if (line[1] == 'P' && line[2] == 'P')
2192ccff623Smrg break;
22051630586Shubertf if (line[1] == 'b' && line[2] == 'r') {
22151630586Shubertf if (intro)
22251630586Shubertf split(linebuf, name);
22351630586Shubertf else
22451630586Shubertf (void)printf("%s\n", linebuf);
22551630586Shubertf curlen = ocurlen;
22651630586Shubertf goto again;
22751630586Shubertf }
22861f28255Scgd }
22904691c5eSchristos if (line[len - 1] == '\n') {
23004691c5eSchristos line[len - 1] = '\0';
23104691c5eSchristos len--;
23204691c5eSchristos }
23304691c5eSchristos if ((ext = strrchr(name, '.')) != NULL) {
23404691c5eSchristos ext++;
23504691c5eSchristos extlen = strlen(ext);
23604691c5eSchristos }
23704691c5eSchristos else
23804691c5eSchristos extlen = 0;
23904691c5eSchristos
24004691c5eSchristos if (maxlen + extlen < curlen + len + SLOP) {
241143464d1Sitojun newmaxlen = 2 * (curlen + len) + SLOP + extlen;
242143464d1Sitojun if ((newlinebuf = realloc(linebuf, newmaxlen)) == NULL)
24385cbf55dSdrochner err(1, NULL);
244143464d1Sitojun linebuf = newlinebuf;
245143464d1Sitojun maxlen = newmaxlen;
24604691c5eSchristos }
24761f28255Scgd if (i != 0)
24804691c5eSchristos linebuf[curlen++] = ' ';
24904691c5eSchristos (void)memcpy(&linebuf[curlen], line, len);
25051630586Shubertf ocurlen = curlen;
25104691c5eSchristos curlen += len;
25204691c5eSchristos linebuf[curlen] = '\0';
25304691c5eSchristos
254030e6d4fShubertf if(!tocrc && !intro) {
255ef53ad13Smrg /* change the \- into (N) - */
25604691c5eSchristos if ((s = strstr(linebuf, "\\-")) != NULL) {
25704691c5eSchristos (void)memmove(s + extlen + 3, s + 1,
25804691c5eSchristos curlen - (s + 1 - linebuf));
25904691c5eSchristos curlen--;
26004691c5eSchristos if (extlen) {
261ef53ad13Smrg *s++ = '(';
26204691c5eSchristos while (*ext)
26304691c5eSchristos *s++ = *ext++;
264ef53ad13Smrg *s++ = ')';
265ef53ad13Smrg *s++ = ' ';
26604691c5eSchristos curlen += extlen + 3;
267ef53ad13Smrg }
26804691c5eSchristos linebuf[curlen] = '\0';
269ef53ad13Smrg }
27061f28255Scgd }
271030e6d4fShubertf }
27283c7e415Stls
27304691c5eSchristos if (intro)
27404691c5eSchristos split(linebuf, name);
27504691c5eSchristos else
2761074321aSchristos (void)printf("%s\n", linebuf);
27704691c5eSchristos return;
27804691c5eSchristos }
27904691c5eSchristos
28004691c5eSchristos static void
newman(char * pathname,char * name)2811074321aSchristos newman(char *pathname, char *name)
28204691c5eSchristos {
283143464d1Sitojun char *line, *ext, *s, *newlinebuf;
28404691c5eSchristos size_t len, i, extlen;
28504691c5eSchristos size_t curlen = 0;
286143464d1Sitojun size_t newmaxlen;
28704691c5eSchristos
288b0b8aac6Slukem if (typeflag) {
2891074321aSchristos (void)printf("%-60s\tNEW\n", pathname);
290b0b8aac6Slukem return;
291b0b8aac6Slukem }
29283c7e415Stls for (;;) {
293f7ab9656Schristos if ((line = fgetln(stdin, &len)) == NULL) {
294f7ab9656Schristos if (verbose)
295f7ab9656Schristos warnx("missing .Sh section in `%s'", pathname);
29683c7e415Stls return;
297f7ab9656Schristos }
29804691c5eSchristos if (line[0] != '.')
29983c7e415Stls continue;
30004691c5eSchristos if (line[1] == 'S' && line[2] == 'h')
30183c7e415Stls break;
30283c7e415Stls }
30304691c5eSchristos
304f7ab9656Schristos for (s = &line[3]; s < &line[len] && isspace((unsigned char) *s); s++)
305f7ab9656Schristos continue;
306f7ab9656Schristos if (s == &line[len]) {
307f7ab9656Schristos warnx("missing argument to .Sh in `%s'", pathname);
308f7ab9656Schristos return;
309f7ab9656Schristos }
310e165b790Saugustss for (i = 0; names[i]; i++)
311e165b790Saugustss if (strncasecmp(s, names[i], strlen(names[i])) == 0)
312e165b790Saugustss break;
313e165b790Saugustss if (names[i] == NULL) {
314e165b790Saugustss warnx("first .SH section is not \"NAME\" in `%s'", pathname);
315f7ab9656Schristos return;
316f7ab9656Schristos }
317f7ab9656Schristos
31883c7e415Stls if (tocrc)
31983c7e415Stls doname(name);
32004691c5eSchristos
32104691c5eSchristos for (i = 0;; i++) {
32204691c5eSchristos if ((line = fgetln(stdin, &len)) == NULL)
32383c7e415Stls break;
32404691c5eSchristos
32504691c5eSchristos if (line[0] == '.') {
326c90e2a4bSfair if (line[1] == '\\' && line[2] == '"')
327c90e2a4bSfair continue; /* [nt]roff comment */
32804691c5eSchristos if (line[1] == 'S' && line[2] == 'h')
32983c7e415Stls break;
33083c7e415Stls }
33104691c5eSchristos
33204691c5eSchristos if (line[len - 1] == '\n') {
33304691c5eSchristos line[len - 1] = '\0';
33404691c5eSchristos len--;
33504691c5eSchristos }
33604691c5eSchristos
33704691c5eSchristos if ((ext = strrchr(name, '.')) != NULL) {
33804691c5eSchristos ext++;
33904691c5eSchristos extlen = strlen(ext);
34004691c5eSchristos }
34183c7e415Stls else
34204691c5eSchristos extlen = 0;
34304691c5eSchristos
34404691c5eSchristos if (maxlen + extlen < curlen + len + SLOP) {
345143464d1Sitojun newmaxlen = 2 * (curlen + len) + SLOP + extlen;
346143464d1Sitojun if ((newlinebuf = realloc(linebuf, newmaxlen)) == NULL)
34785cbf55dSdrochner err(1, NULL);
348143464d1Sitojun linebuf = newlinebuf;
349143464d1Sitojun maxlen = newmaxlen;
35083c7e415Stls }
35104691c5eSchristos
35204691c5eSchristos if (i != 0)
35304691c5eSchristos linebuf[curlen++] = ' ';
35404691c5eSchristos
35504691c5eSchristos remcomma(line, &len);
35604691c5eSchristos
35704691c5eSchristos if (line[0] != '.') {
35804691c5eSchristos (void)memcpy(&linebuf[curlen], line, len);
35904691c5eSchristos curlen += len;
36083c7e415Stls }
36104691c5eSchristos else {
36204691c5eSchristos remquote(line, &len);
36304691c5eSchristos fixxref(line, &len);
364ef53ad13Smrg
36583c7e415Stls /*
366ef53ad13Smrg * Put section and dash between names and description.
36783c7e415Stls */
36804691c5eSchristos if (line[1] == 'N' && line[2] == 'd') {
369030e6d4fShubertf if(!tocrc && !intro) {
37004691c5eSchristos if (extlen) {
37104691c5eSchristos linebuf[curlen++] = '(';
37204691c5eSchristos while (*ext)
37304691c5eSchristos linebuf[curlen++] = *ext++;
37404691c5eSchristos linebuf[curlen++] = ')';
37504691c5eSchristos linebuf[curlen++] = ' ';
376ef53ad13Smrg }
377030e6d4fShubertf }
37804691c5eSchristos linebuf[curlen++] = '-';
37904691c5eSchristos linebuf[curlen++] = ' ';
380ef53ad13Smrg }
38183c7e415Stls /*
38283c7e415Stls * Skip over macro names.
38383c7e415Stls */
38404691c5eSchristos if (len <= 4)
38504691c5eSchristos continue;
38604691c5eSchristos (void)memcpy(&linebuf[curlen], &line[4], len - 4);
38704691c5eSchristos curlen += len - 4;
38883c7e415Stls }
38983c7e415Stls }
39004691c5eSchristos linebuf[curlen] = '\0';
39183c7e415Stls if (intro)
39204691c5eSchristos split(linebuf, name);
39383c7e415Stls else
3941074321aSchristos (void)printf("%s\n", linebuf);
39561f28255Scgd }
39661f28255Scgd
39704691c5eSchristos /*
39804691c5eSchristos * convert " ," -> " "
39904691c5eSchristos */
40004691c5eSchristos static void
remcomma(char * line,size_t * len)4011074321aSchristos remcomma(char *line, size_t *len)
40261f28255Scgd {
40304691c5eSchristos char *pline = line, *loc;
40404691c5eSchristos size_t plen = *len;
40561f28255Scgd
40604691c5eSchristos while ((loc = memchr(pline, ' ', plen)) != NULL) {
40704691c5eSchristos plen -= loc - pline + 1;
40804691c5eSchristos pline = loc;
40904691c5eSchristos if (loc[1] == ',') {
41004691c5eSchristos (void)memcpy(loc, &loc[1], plen);
41104691c5eSchristos (*len)--;
41204691c5eSchristos }
41304691c5eSchristos else
41404691c5eSchristos pline++;
41504691c5eSchristos }
41661f28255Scgd }
41761f28255Scgd
41804691c5eSchristos /*
41904691c5eSchristos * Get rid of quotes in macros.
42004691c5eSchristos */
4211074321aSchristos static void
remquote(char * line,size_t * len)4221074321aSchristos remquote(char *line, size_t *len)
42304691c5eSchristos {
42404691c5eSchristos char *loc;
42504691c5eSchristos char *pline = &line[4];
42604691c5eSchristos size_t plen = *len - 4;
42704691c5eSchristos
42804691c5eSchristos if (*len < 4)
42904691c5eSchristos return;
43004691c5eSchristos
43104691c5eSchristos while ((loc = memchr(pline, '"', plen)) != NULL) {
43204691c5eSchristos plen -= loc - pline + 1;
43304691c5eSchristos pline = loc;
43404691c5eSchristos (void)memcpy(loc, &loc[1], plen);
43504691c5eSchristos (*len)--;
43604691c5eSchristos }
43704691c5eSchristos }
43804691c5eSchristos
43904691c5eSchristos /*
44004691c5eSchristos * Handle cross references
44104691c5eSchristos */
44204691c5eSchristos static void
fixxref(char * line,size_t * len)4431074321aSchristos fixxref(char *line, size_t *len)
44404691c5eSchristos {
44504691c5eSchristos char *loc;
44604691c5eSchristos char *pline = &line[4];
44704691c5eSchristos size_t plen = *len - 4;
44804691c5eSchristos
44904691c5eSchristos if (*len < 4)
45004691c5eSchristos return;
45104691c5eSchristos
45204691c5eSchristos if (line[1] == 'X' && line[2] == 'r') {
45304691c5eSchristos if ((loc = memchr(pline, ' ', plen)) != NULL) {
45404691c5eSchristos *loc++ = '(';
45504691c5eSchristos loc++;
45604691c5eSchristos *loc++ = ')';
45704691c5eSchristos *len = loc - line;
45804691c5eSchristos }
45904691c5eSchristos }
46004691c5eSchristos }
46104691c5eSchristos
46204691c5eSchristos static void
doname(char * name)4631074321aSchristos doname(char *name)
46461f28255Scgd {
465b0b8aac6Slukem char *dp = name, *ep;
46661f28255Scgd
46761f28255Scgd again:
46861f28255Scgd while (*dp && *dp != '.')
4691074321aSchristos (void)putchar(*dp++);
47061f28255Scgd if (*dp)
47161f28255Scgd for (ep = dp+1; *ep; ep++)
47261f28255Scgd if (*ep == '.') {
4731074321aSchristos (void)putchar(*dp++);
47461f28255Scgd goto again;
47561f28255Scgd }
4761074321aSchristos (void)putchar('(');
47761f28255Scgd if (*dp)
47861f28255Scgd dp++;
47961f28255Scgd while (*dp)
4801074321aSchristos (void)putchar(*dp++);
4811074321aSchristos (void)putchar(')');
4821074321aSchristos (void)putchar(' ');
48361f28255Scgd }
48461f28255Scgd
48504691c5eSchristos static void
split(char * line,char * name)4861074321aSchristos split(char *line, char *name)
48761f28255Scgd {
488b0b8aac6Slukem char *cp, *dp;
4891074321aSchristos char *sp;
4901074321aSchristos const char *sep;
49161f28255Scgd
49283c7e415Stls cp = strchr(line, '-');
49361f28255Scgd if (cp == 0)
49461f28255Scgd return;
49561f28255Scgd sp = cp + 1;
49661f28255Scgd for (--cp; *cp == ' ' || *cp == '\t' || *cp == '\\'; cp--)
49761f28255Scgd ;
49861f28255Scgd *++cp = '\0';
49961f28255Scgd while (*sp && (*sp == ' ' || *sp == '\t'))
50061f28255Scgd sp++;
50161f28255Scgd for (sep = "", dp = line; dp && *dp; dp = cp, sep = "\n") {
50283c7e415Stls cp = strchr(dp, ',');
50361f28255Scgd if (cp) {
504b0b8aac6Slukem char *tp;
50561f28255Scgd
50661f28255Scgd for (tp = cp - 1; *tp == ' ' || *tp == '\t'; tp--)
50761f28255Scgd ;
50861f28255Scgd *++tp = '\0';
50961f28255Scgd for (++cp; *cp == ' ' || *cp == '\t'; cp++)
51061f28255Scgd ;
51161f28255Scgd }
5121074321aSchristos (void)printf("%s%s\t", sep, dp);
51361f28255Scgd dorefname(name);
5141074321aSchristos (void)printf("\t- %s", sp);
51561f28255Scgd }
5161074321aSchristos (void)putchar('\n');
51761f28255Scgd }
51861f28255Scgd
51904691c5eSchristos static void
dorefname(char * name)5201074321aSchristos dorefname(char *name)
52161f28255Scgd {
522b0b8aac6Slukem char *dp = name, *ep;
52361f28255Scgd
52461f28255Scgd again:
52561f28255Scgd while (*dp && *dp != '.')
5261074321aSchristos (void)putchar(*dp++);
52761f28255Scgd if (*dp)
52861f28255Scgd for (ep = dp+1; *ep; ep++)
52961f28255Scgd if (*ep == '.') {
5301074321aSchristos (void)putchar(*dp++);
53161f28255Scgd goto again;
53261f28255Scgd }
5331074321aSchristos (void)putchar('.');
53461f28255Scgd if (*dp)
53561f28255Scgd dp++;
53661f28255Scgd while (*dp)
5371074321aSchristos (void)putchar(*dp++);
53861f28255Scgd }
53961f28255Scgd
54004691c5eSchristos static void
usage(void)5411074321aSchristos usage(void)
54261f28255Scgd {
54365a10264Scgd
54465a10264Scgd (void)fprintf(stderr, "Usage: %s [-itw] file ...\n", getprogname());
54561f28255Scgd exit(1);
54661f28255Scgd }
547