1 static char *sccsid = "@(#)getNAME.c 4.1 (Berkeley) 10/01/80"; 2 #include <stdio.h> 3 4 int tocrc; 5 6 main(argc, argv) 7 int argc; 8 char *argv[]; 9 { 10 11 argc--, argv++; 12 if (!strcmp(argv[0], "-t")) 13 argc--, argv++, tocrc++; 14 while (argc > 0) 15 getfrom(*argv++), argc--; 16 exit(0); 17 } 18 19 getfrom(name) 20 char *name; 21 { 22 char headbuf[BUFSIZ]; 23 char linbuf[BUFSIZ]; 24 register char *cp; 25 int i = 0; 26 27 if (freopen(name, "r", stdin) == 0) { 28 perror(name); 29 exit(1); 30 } 31 for (;;) { 32 if (fgets(headbuf, sizeof headbuf, stdin) == NULL) 33 return; 34 if (headbuf[0] != '.') 35 continue; 36 if (headbuf[1] == 'T' && headbuf[2] == 'H') 37 break; 38 if (headbuf[1] == 't' && headbuf[2] == 'h') 39 break; 40 } 41 for (;;) { 42 if (fgets(linbuf, sizeof linbuf, stdin) == NULL) 43 return; 44 if (linbuf[0] != '.') 45 continue; 46 if (linbuf[1] == 'S' && linbuf[2] == 'H') 47 break; 48 if (linbuf[1] == 's' && linbuf[2] == 'h') 49 break; 50 } 51 trimln(headbuf); 52 if (tocrc) { 53 register char *dp = name, *ep; 54 55 again: 56 while (*dp && *dp != '.') 57 putchar(*dp++); 58 if (*dp) 59 for (ep = dp+1; *ep; ep++) 60 if (*ep == '.') { 61 putchar(*dp++); 62 goto again; 63 } 64 putchar('('); 65 if (*dp) 66 dp++; 67 while (*dp) 68 putchar (*dp++); 69 putchar(')'); 70 putchar(' '); 71 } 72 printf("%s\t", headbuf); 73 for (;;) { 74 if (fgets(linbuf, sizeof linbuf, stdin) == NULL) 75 break; 76 if (linbuf[0] == '.') { 77 if (linbuf[1] == 'S' && linbuf[2] == 'H') 78 break; 79 if (linbuf[1] == 's' && linbuf[2] == 'h') 80 break; 81 } 82 trimln(linbuf); 83 if (i != 0) 84 printf(" "); 85 i++; 86 printf("%s", linbuf); 87 } 88 printf("\n"); 89 } 90 91 trimln(cp) 92 register char *cp; 93 { 94 95 while (*cp) 96 cp++; 97 if (*--cp == '\n') 98 *cp = 0; 99 } 100