12148Seric # include "../hdr/defines.h"
22148Seric
3*33423Sbostic static char Sccsid[] = "@(#)help.c 4.3 02/02/88";
42148Seric
52148Seric /*
62148Seric Program to locate helpful info in an ascii file.
72148Seric The program accepts a variable number of arguments.
82148Seric
92148Seric The file to be searched is determined from the argument. If the
102148Seric argument does not contain numerics, the search
112148Seric will be attempted on '/usr/local/lib/help/cmds', with the search key
122148Seric being the whole argument.
132148Seric If the argument begins with non-numerics but contains
142148Seric numerics (e.g, zz32) the search will be attempted on
152148Seric '/usr/local/lib/help/<non-numeric prefix>', (e.g,/usr/lib/help/zz),
162148Seric with the search key being <remainder of arg>, (e.g., 32).
172148Seric If the argument is all numeric, or if the file as
182148Seric determined above does not exist, the search will be attempted on
192148Seric '/usr/local/lib/sccs.hf', which is the old help file, with the
202148Seric search key being the entire argument.
212148Seric In no case will more than one search per argument be performed.
222148Seric
232148Seric File is formatted as follows:
242148Seric
252148Seric * comment
262148Seric * comment
272148Seric -str1
282148Seric text
292148Seric -str2
302148Seric text
312148Seric * comment
322148Seric text
332148Seric -str3
342148Seric text
352148Seric
362148Seric The "str?" that matches the key is found and
372148Seric the following text lines are printed.
382148Seric Comments are ignored.
392148Seric
402148Seric If the argument is omitted, the program requests it.
412148Seric */
4230498Slepreau char oldfile[] = "/usr/local/lib/sccs.hf";
4330498Slepreau char helpdir[] = "/usr/local/lib/help/";
442148Seric char hfile[64];
452148Seric FILE *iop;
462148Seric char line [512];
472148Seric
482148Seric
main(argc,argv)492148Seric main(argc,argv)
502148Seric int argc;
512148Seric char *argv[];
522148Seric {
532148Seric register int i;
542148Seric extern int Fcnt;
552148Seric
562148Seric /*
572148Seric Tell 'fatal' to issue messages, clean up, and return to its caller.
582148Seric */
592148Seric Fflags = FTLMSG | FTLCLN | FTLJMP;
602148Seric
612148Seric if (argc == 1)
622148Seric findprt(ask()); /* ask user for argument */
632148Seric else
642148Seric for (i = 1; i < argc; i++)
652148Seric findprt(argv[i]);
662148Seric
672148Seric exit(Fcnt ? 1 : 0);
682148Seric }
692148Seric
702148Seric
findprt(p)712148Seric findprt(p)
722148Seric char *p;
732148Seric {
742148Seric register char *q;
752148Seric char key[50];
762148Seric
772148Seric if (setjmp(Fjmp)) /* set up to return here from */
782148Seric return; /* 'fatal' and return to 'main' */
792148Seric
802148Seric if (size(p) > 50)
812148Seric fatal("argument too long (he2)");
822148Seric
832148Seric q = p;
842148Seric
852148Seric while (*q && !numeric(*q))
862148Seric q++;
872148Seric
882148Seric if (*q == '\0') { /* all alphabetics */
892148Seric copy(p,key);
902148Seric cat(hfile,helpdir,"cmds",0);
912148Seric if (!exists(hfile))
922148Seric copy(oldfile,hfile);
932148Seric }
942148Seric else
952148Seric if (q == p) { /* first char numeric */
962148Seric copy(p,key);
972148Seric copy(oldfile,hfile);
982148Seric }
992148Seric else { /* first char alpha, then numeric */
1002148Seric copy(p,key); /* key used as temporary */
1012148Seric *(key + (q - p)) = '\0';
1022148Seric cat(hfile,helpdir,key,0);
1032148Seric copy(q,key);
1042148Seric if (!exists(hfile)) {
1052148Seric copy(p,key);
1062148Seric copy(oldfile,hfile);
1072148Seric }
1082148Seric }
1092148Seric
1102148Seric iop = xfopen(hfile,0);
1112148Seric
1122148Seric /*
1132148Seric Now read file, looking for key.
1142148Seric */
1152148Seric while ((q = fgets(line,512,iop)) != NULL) {
1162148Seric repl(line,'\n','\0'); /* replace newline char */
1172148Seric if (line[0] == '-' && equal(&line[1],key))
1182148Seric break;
1192148Seric }
1202148Seric
1212148Seric if (q == NULL) { /* endfile? */
1222148Seric printf("\n");
123*33423Sbostic sprintf(Error,"%s not found (he1)",p);
124*33423Sbostic fatal(Error);
1252148Seric }
1262148Seric
1272148Seric printf("\n%s:\n",p);
1282148Seric
1292148Seric while (fgets(line,512,iop) != NULL && line[0] == '-')
1302148Seric ;
1312148Seric do {
1322148Seric if (line[0] != '*')
1332148Seric printf("%s",line);
1342148Seric } while (fgets(line,512,iop) != NULL && line[0] != '-');
1352148Seric
1362148Seric fclose(iop);
1372148Seric }
1382148Seric
1392148Seric
ask()1402148Seric ask()
1412148Seric {
1422148Seric static char resp[51];
1432148Seric
1442148Seric iop = stdin;
1452148Seric
1462148Seric printf("msg number or comd name? ");
1472148Seric fgets(resp,51,iop);
1482148Seric return(repl(resp,'\n','\0'));
1492148Seric }
1502148Seric
1512148Seric
clean_up()1522148Seric clean_up()
1532148Seric {
1542148Seric fclose(iop);
1552148Seric }
156