1 # include "../hdr/defines.h" 2 3 static char Sccsid[] = "@(#)help.c 4.3 02/02/88"; 4 5 /* 6 Program to locate helpful info in an ascii file. 7 The program accepts a variable number of arguments. 8 9 The file to be searched is determined from the argument. If the 10 argument does not contain numerics, the search 11 will be attempted on '/usr/local/lib/help/cmds', with the search key 12 being the whole argument. 13 If the argument begins with non-numerics but contains 14 numerics (e.g, zz32) the search will be attempted on 15 '/usr/local/lib/help/<non-numeric prefix>', (e.g,/usr/lib/help/zz), 16 with the search key being <remainder of arg>, (e.g., 32). 17 If the argument is all numeric, or if the file as 18 determined above does not exist, the search will be attempted on 19 '/usr/local/lib/sccs.hf', which is the old help file, with the 20 search key being the entire argument. 21 In no case will more than one search per argument be performed. 22 23 File is formatted as follows: 24 25 * comment 26 * comment 27 -str1 28 text 29 -str2 30 text 31 * comment 32 text 33 -str3 34 text 35 36 The "str?" that matches the key is found and 37 the following text lines are printed. 38 Comments are ignored. 39 40 If the argument is omitted, the program requests it. 41 */ 42 char oldfile[] = "/usr/local/lib/sccs.hf"; 43 char helpdir[] = "/usr/local/lib/help/"; 44 char hfile[64]; 45 FILE *iop; 46 char line [512]; 47 48 49 main(argc,argv) 50 int argc; 51 char *argv[]; 52 { 53 register int i; 54 extern int Fcnt; 55 56 /* 57 Tell 'fatal' to issue messages, clean up, and return to its caller. 58 */ 59 Fflags = FTLMSG | FTLCLN | FTLJMP; 60 61 if (argc == 1) 62 findprt(ask()); /* ask user for argument */ 63 else 64 for (i = 1; i < argc; i++) 65 findprt(argv[i]); 66 67 exit(Fcnt ? 1 : 0); 68 } 69 70 71 findprt(p) 72 char *p; 73 { 74 register char *q; 75 char key[50]; 76 77 if (setjmp(Fjmp)) /* set up to return here from */ 78 return; /* 'fatal' and return to 'main' */ 79 80 if (size(p) > 50) 81 fatal("argument too long (he2)"); 82 83 q = p; 84 85 while (*q && !numeric(*q)) 86 q++; 87 88 if (*q == '\0') { /* all alphabetics */ 89 copy(p,key); 90 cat(hfile,helpdir,"cmds",0); 91 if (!exists(hfile)) 92 copy(oldfile,hfile); 93 } 94 else 95 if (q == p) { /* first char numeric */ 96 copy(p,key); 97 copy(oldfile,hfile); 98 } 99 else { /* first char alpha, then numeric */ 100 copy(p,key); /* key used as temporary */ 101 *(key + (q - p)) = '\0'; 102 cat(hfile,helpdir,key,0); 103 copy(q,key); 104 if (!exists(hfile)) { 105 copy(p,key); 106 copy(oldfile,hfile); 107 } 108 } 109 110 iop = xfopen(hfile,0); 111 112 /* 113 Now read file, looking for key. 114 */ 115 while ((q = fgets(line,512,iop)) != NULL) { 116 repl(line,'\n','\0'); /* replace newline char */ 117 if (line[0] == '-' && equal(&line[1],key)) 118 break; 119 } 120 121 if (q == NULL) { /* endfile? */ 122 printf("\n"); 123 sprintf(Error,"%s not found (he1)",p); 124 fatal(Error); 125 } 126 127 printf("\n%s:\n",p); 128 129 while (fgets(line,512,iop) != NULL && line[0] == '-') 130 ; 131 do { 132 if (line[0] != '*') 133 printf("%s",line); 134 } while (fgets(line,512,iop) != NULL && line[0] != '-'); 135 136 fclose(iop); 137 } 138 139 140 ask() 141 { 142 static char resp[51]; 143 144 iop = stdin; 145 146 printf("msg number or comd name? "); 147 fgets(resp,51,iop); 148 return(repl(resp,'\n','\0')); 149 } 150 151 152 clean_up() 153 { 154 fclose(iop); 155 } 156