home *** CD-ROM | disk | FTP | other *** search
- /* HELP.C */
- static char sccsid[] = "@(#)help.c 1.12 93/04/21 Copyright (c)1993 thalerd";
- #include <stdio.h>
- #include <string.h>
- #include <sys/types.h>
- #include <ctype.h>
- #include "config.h"
- #include "struct.h"
- #include "lib.h"
- #include "globals.h"
- #include "conf.h" /* for get_idx */
-
- /* Index files of help text, in order by mode */
- #define HELPINDEX "Index"
-
- void
- show_help(count,argc,argv,file,hdr)
- int *count; /* Number of arguments */
- int argc;
- char **argv; /* Argument list */
- char *file;/* Filename of list */
- char *hdr; /* Help display header */
- {
- assoc_t helplist[MAX_LIST_LENGTH];
- short helpsize,idx=0,i,j;
- char *dir,*fil;
- char **header,name[MAX_LINE_LENGTH];
-
- /* Set location */
- if (file[0]=='%') {
- dir = bbsdir;
- fil = file+1;
- } else {
- dir = helpdir;
- fil = file;
- }
-
- /* Is this a text file or a list? */
- if (!(header = grab_file(dir,fil,GF_HEADER))) return;
- if (strcmp(header[0],"!<hl01>")) {
- if (*count < argc)
- printf("Sorry, only this message available.\n");
- else if (hdr)
- printf("**** %s ****\n",hdr);
- if (!more(dir,fil))
- printf("UNK Can't find help file %s/%s.\n",dir,fil);
- xfree(header);
- return;
- }
- xfree(header);
-
- /* Read in help list */
- if (!grab_list(dir,fil,helplist,&helpsize)) return;
-
- /* Display requested file */
- if (*count>=argc) {
-
- /* No arguments, use default file */
- show_help(count,argc,argv,helplist[0].location,hdr);
-
- } else {
-
- idx=get_idx(argv[*count],helplist,helpsize);
- (*count)++;
- if (idx<0)
- printf("Sorry, no help available for \"%s\"\n",argv[(*count)-1]);
-
- /* %filename indicates file is in bbsdir not helpdir */
- else if (helplist[idx].location[0]=='%') {
- show_help(count,argc,argv,helplist[idx].location,hdr);
-
- /* normal help files are in helpdir & get a header displayed */
- } else {
- char buff[MAX_LINE_LENGTH];
-
- strcpy(name,compress(helplist[idx].name));
- for (j=strlen(name)-1; j>=0; j--)
- name[j]=toupper(name[j]);
- if (hdr)
- sprintf(buff,"%s %s",hdr,name);
- else
- strcpy(buff,name);
- show_help(count,argc,argv,helplist[idx].location,buff);
- }
- }
-
- /* Free the list */
- for (i=0; i<helpsize; i++) {
- xfree(helplist[i].name);
- xfree(helplist[i].location);
- }
- }
-
- /*****************************************************************************/
- /* GET HELP ON SOME TOPIC */
- /*****************************************************************************/
- int /* RETURNS: (nothing) */
- help(argc,argv) /* ARGUMENTS: */
- int argc; /* Number of arguments */
- char **argv; /* Argument list */
- {
- char **helpfile;
- int count=1;
-
- if (!(helpfile = grab_file(helpdir,HELPINDEX,0))) return 1;
- do {
- show_help(&count,argc,argv,helpfile[mode],(char*)0);
- } while (count<argc);
- xfree(helpfile);
- return 1;
- }
-