1 #ifndef lint 2 static char *sccsid = "@(#)refer1.c 4.1 (Berkeley) 05/06/83"; 3 #endif 4 5 #include <signal.h> 6 #include "refer..c" 7 8 main(argc,argv) /* process command-line arguments */ 9 char *argv[]; 10 { 11 char line[BUFSIZ], *s; 12 int nodeflt = 0; 13 14 signals(); 15 while (argv[1][0] == '-') { 16 switch(argv[1][1]) { 17 case 'e': 18 endpush++; 19 break; 20 case 's': 21 sort++; 22 endpush = 1; 23 if (argv[1][2]) 24 keystr = argv[1]+2; 25 break; 26 case 'l': 27 labels++; 28 s = argv[1]+2; 29 nmlen = atoi(s); 30 while (*s) 31 if (*s++ == ',') 32 break; 33 dtlen = atoi(s); 34 break; 35 case 'k': 36 keywant = (argv[1][2] ? argv[1][2] : 'L'); 37 labels++; 38 break; 39 case 'n': 40 nodeflt = 1; 41 break; 42 case 'p': 43 argc--; 44 argv++; 45 *search++ = argv[1]; 46 if (search-rdata > NSERCH) 47 err("too many -p options (%d)", NSERCH); 48 break; 49 case 'a': 50 authrev = atoi(argv[1]+2); 51 if (authrev<=0) 52 authrev = 1000; 53 break; 54 case 'b': 55 bare = (argv[1][2] == '1') ? 1 : 2; 56 break; 57 case 'c': 58 smallcaps = argv[1]+2; 59 break; 60 case 'f': 61 refnum = atoi(argv[1]+2) - 1; 62 break; 63 case 'B': 64 biblio++; 65 bare = 2; 66 if (argv[1][2]) 67 convert = argv[1]+2; 68 break; 69 case 'S': 70 science++; 71 labels = 1; 72 break; 73 case 'P': 74 postpunct++; 75 break; 76 } 77 argc--; 78 argv++; 79 } 80 if (getenv("REFER") != NULL) 81 *search++ = getenv("REFER"); 82 else if (nodeflt == 0) 83 *search++ = "/usr/dict/papers/Ind"; 84 if (endpush) { 85 sprintf(tfile, "/tmp/rj%da", getpid()); 86 fo = fopen(tfile, "w"); 87 if (fo == NULL) { 88 fo = ftemp; 89 fprintf(stderr, "Can't open scratch file"); 90 } 91 sep = 002; /* separate records without confusing sort..*/ 92 } 93 if (sort && !labels) { 94 sprintf(ofile, "/tmp/rj%db", getpid()); 95 ftemp = fopen(ofile, "w"); 96 if (ftemp == NULL) { 97 fprintf(stderr, "Can't open scratch file\n"); 98 exit(1); 99 } 100 } 101 do { 102 if (argc > 1) { 103 fclose(in); 104 Iline = 0; 105 in = fopen(Ifile = argv[1], "r"); 106 argc--; 107 argv++; 108 if (in == NULL) { 109 err("Can't read %s", (void) Ifile); 110 continue; 111 } 112 } 113 while (input(line)) { 114 Iline++; 115 if (biblio && *line == '\n') 116 doref(line); 117 else if (biblio && Iline == 1 && *line == '%') 118 doref(line); 119 else if (!prefix(".[", line)) 120 output(line); 121 else 122 doref(line); 123 } 124 } while (argc > 1); 125 126 if (endpush && fo != NULL) 127 dumpold(); 128 output(""); 129 if (sort && !labels) 130 recopy(ofile); 131 clfgrep(); 132 cleanup(); 133 exit(0); 134 } 135 136 extern int intr(); 137 138 signals() 139 { 140 if (signal(SIGINT, SIG_IGN) != SIG_IGN) 141 signal(SIGINT, intr); 142 signal(SIGHUP, intr); 143 signal(SIGPIPE, intr); 144 signal(SIGTERM, intr); 145 } 146 147 intr() 148 { 149 signal(SIGINT, SIG_IGN); 150 cleanup(); 151 exit(1); 152 } 153 154 cleanup() 155 { 156 if (tfile[0]) 157 unlink(tfile); 158 if (gfile[0]) 159 unlink(gfile); 160 if (ofile[0]) 161 unlink(ofile); 162 if (hidenam[0]) 163 unlink(hidenam); 164 } 165