113912Ssam #ifndef lint 2*13913Ssam static char *sccsid = "@(#)getNAME.c 4.3 (Berkeley) 07/10/83"; 313912Ssam #endif 413912Ssam 513912Ssam /* 613912Ssam * Get name sections from manual pages. 713912Ssam * -t for building toc 813912Ssam * -i for building intro entries 913912Ssam * other apropos database 1013912Ssam */ 1113912Ssam #include <strings.h> 121022Sbill #include <stdio.h> 131022Sbill 141022Sbill int tocrc; 1513912Ssam int intro; 161022Sbill 171022Sbill main(argc, argv) 181022Sbill int argc; 191022Sbill char *argv[]; 201022Sbill { 211022Sbill 221022Sbill argc--, argv++; 231022Sbill if (!strcmp(argv[0], "-t")) 241022Sbill argc--, argv++, tocrc++; 2513912Ssam if (!strcmp(argv[0], "-i")) 2613912Ssam argc--, argv++, intro++; 271022Sbill while (argc > 0) 281022Sbill getfrom(*argv++), argc--; 291022Sbill exit(0); 301022Sbill } 311022Sbill 321022Sbill getfrom(name) 331022Sbill char *name; 341022Sbill { 351022Sbill char headbuf[BUFSIZ]; 361022Sbill char linbuf[BUFSIZ]; 371022Sbill register char *cp; 381022Sbill int i = 0; 391022Sbill 401022Sbill if (freopen(name, "r", stdin) == 0) { 411022Sbill perror(name); 421022Sbill exit(1); 431022Sbill } 441022Sbill for (;;) { 451022Sbill if (fgets(headbuf, sizeof headbuf, stdin) == NULL) 461022Sbill return; 471022Sbill if (headbuf[0] != '.') 481022Sbill continue; 491022Sbill if (headbuf[1] == 'T' && headbuf[2] == 'H') 501022Sbill break; 511022Sbill if (headbuf[1] == 't' && headbuf[2] == 'h') 521022Sbill break; 531022Sbill } 541022Sbill for (;;) { 551022Sbill if (fgets(linbuf, sizeof linbuf, stdin) == NULL) 561022Sbill return; 571022Sbill if (linbuf[0] != '.') 581022Sbill continue; 591022Sbill if (linbuf[1] == 'S' && linbuf[2] == 'H') 601022Sbill break; 611022Sbill if (linbuf[1] == 's' && linbuf[2] == 'h') 621022Sbill break; 631022Sbill } 641022Sbill trimln(headbuf); 6513912Ssam if (tocrc) 6613912Ssam doname(name); 6713912Ssam if (!intro) 6813912Ssam printf("%s\t", headbuf); 691022Sbill for (;;) { 701022Sbill if (fgets(linbuf, sizeof linbuf, stdin) == NULL) 711022Sbill break; 721022Sbill if (linbuf[0] == '.') { 731022Sbill if (linbuf[1] == 'S' && linbuf[2] == 'H') 741022Sbill break; 751022Sbill if (linbuf[1] == 's' && linbuf[2] == 'h') 761022Sbill break; 771022Sbill } 781022Sbill trimln(linbuf); 7913912Ssam if (intro) { 8013912Ssam split(linbuf, name); 8113912Ssam continue; 8213912Ssam } 831022Sbill if (i != 0) 841022Sbill printf(" "); 851022Sbill i++; 861022Sbill printf("%s", linbuf); 871022Sbill } 881022Sbill printf("\n"); 891022Sbill } 901022Sbill 911022Sbill trimln(cp) 921022Sbill register char *cp; 931022Sbill { 941022Sbill 951022Sbill while (*cp) 961022Sbill cp++; 971022Sbill if (*--cp == '\n') 981022Sbill *cp = 0; 991022Sbill } 10013912Ssam 10113912Ssam doname(name) 10213912Ssam char *name; 10313912Ssam { 10413912Ssam register char *dp = name, *ep; 10513912Ssam 10613912Ssam again: 10713912Ssam while (*dp && *dp != '.') 10813912Ssam putchar(*dp++); 10913912Ssam if (*dp) 11013912Ssam for (ep = dp+1; *ep; ep++) 11113912Ssam if (*ep == '.') { 11213912Ssam putchar(*dp++); 11313912Ssam goto again; 11413912Ssam } 11513912Ssam putchar('('); 11613912Ssam if (*dp) 11713912Ssam dp++; 11813912Ssam while (*dp) 11913912Ssam putchar (*dp++); 12013912Ssam putchar(')'); 12113912Ssam putchar(' '); 12213912Ssam } 12313912Ssam 12413912Ssam split(line, name) 12513912Ssam char *line, *name; 12613912Ssam { 12713912Ssam register char *cp, *dp; 12813912Ssam char *sp, *sep; 12913912Ssam 13013912Ssam cp = index(line, '-'); 13113912Ssam if (cp == 0) 13213912Ssam return; 13313912Ssam sp = cp + 1; 13413912Ssam for (--cp; *cp == ' ' || *cp == '\t' || *cp == '\\'; cp--) 13513912Ssam ; 13613912Ssam *++cp = '\0'; 13713912Ssam while (*sp && (*sp == ' ' || *sp == '\t')) 13813912Ssam sp++; 13913912Ssam for (sep = "", dp = line; dp && *dp; dp = cp, sep = "\n") { 14013912Ssam cp = index(dp, ','); 14113912Ssam if (cp) { 14213912Ssam register char *tp; 14313912Ssam 14413912Ssam for (tp = cp - 1; *tp == ' ' || *tp == '\t'; tp--) 14513912Ssam ; 14613912Ssam *++tp = '\0'; 14713912Ssam for (++cp; *cp == ' ' || *cp == '\t'; cp++) 14813912Ssam ; 14913912Ssam } 15013912Ssam printf("%s%s\t", sep, dp); 151*13913Ssam dorefname(name); 15213912Ssam printf("\t%s", sp); 15313912Ssam } 15413912Ssam } 155*13913Ssam 156*13913Ssam dorefname(name) 157*13913Ssam char *name; 158*13913Ssam { 159*13913Ssam register char *dp = name, *ep; 160*13913Ssam 161*13913Ssam again: 162*13913Ssam while (*dp && *dp != '.') 163*13913Ssam putchar(*dp++); 164*13913Ssam if (*dp) 165*13913Ssam for (ep = dp+1; *ep; ep++) 166*13913Ssam if (*ep == '.') { 167*13913Ssam putchar(*dp++); 168*13913Ssam goto again; 169*13913Ssam } 170*13913Ssam putchar('.'); 171*13913Ssam if (*dp) 172*13913Ssam dp++; 173*13913Ssam while (*dp) 174*13913Ssam putchar (*dp++); 175*13913Ssam } 176