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