home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume28 / yapp / part01 / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-29  |  3.0 KB  |  112 lines

  1. /* HELP.C */
  2. static    char sccsid[] = "@(#)help.c 1.12 93/04/21 Copyright (c)1993 thalerd";
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <sys/types.h>
  6. #include <ctype.h>
  7. #include "config.h"
  8. #include "struct.h"
  9. #include "lib.h"
  10. #include "globals.h"
  11. #include "conf.h"   /* for get_idx */
  12.  
  13. /* Index files of help text, in order by mode */
  14. #define HELPINDEX  "Index"
  15.  
  16. void
  17. show_help(count,argc,argv,file,hdr)
  18. int   *count;   /*    Number of arguments */
  19. int    argc;
  20. char **argv;    /*    Argument list       */
  21. char  *file;/*    Filename of list    */
  22. char  *hdr;     /*    Help display header */
  23. {
  24.    assoc_t helplist[MAX_LIST_LENGTH];
  25.    short helpsize,idx=0,i,j;
  26.    char *dir,*fil;
  27.    char **header,name[MAX_LINE_LENGTH];
  28.  
  29.    /* Set location */
  30.    if (file[0]=='%') {
  31.       dir = bbsdir;
  32.       fil = file+1;
  33.    } else {
  34.       dir = helpdir;
  35.       fil = file;
  36.    }
  37.  
  38.    /* Is this a text file or a list? */
  39.    if (!(header = grab_file(dir,fil,GF_HEADER))) return;
  40.    if (strcmp(header[0],"!<hl01>")) {
  41.       if (*count < argc) 
  42.          printf("Sorry, only this message available.\n");
  43.       else if (hdr)
  44.          printf("****    %s    ****\n",hdr);
  45.       if (!more(dir,fil))
  46.          printf("UNK Can't find help file %s/%s.\n",dir,fil);
  47.       xfree(header);
  48.       return;
  49.    }
  50.    xfree(header);
  51.  
  52.    /* Read in help list */
  53.    if (!grab_list(dir,fil,helplist,&helpsize)) return;
  54.  
  55.    /* Display requested file */
  56.    if (*count>=argc) {
  57.  
  58.       /* No arguments, use default file */
  59.       show_help(count,argc,argv,helplist[0].location,hdr);
  60.  
  61.    } else { 
  62.  
  63.       idx=get_idx(argv[*count],helplist,helpsize);
  64.       (*count)++;
  65.       if (idx<0) 
  66.          printf("Sorry, no help available for \"%s\"\n",argv[(*count)-1]);
  67.  
  68.       /* %filename indicates file is in bbsdir not helpdir */
  69.       else if (helplist[idx].location[0]=='%') {
  70.          show_help(count,argc,argv,helplist[idx].location,hdr);
  71.  
  72.       /* normal help files are in helpdir & get a header displayed */
  73.       } else {
  74.          char buff[MAX_LINE_LENGTH];
  75.  
  76.          strcpy(name,compress(helplist[idx].name));
  77.          for (j=strlen(name)-1; j>=0; j--)
  78.             name[j]=toupper(name[j]);
  79.          if (hdr)
  80.             sprintf(buff,"%s %s",hdr,name);
  81.          else
  82.             strcpy(buff,name);
  83.          show_help(count,argc,argv,helplist[idx].location,buff);
  84.       }
  85.    }
  86.  
  87.    /* Free the list */
  88.    for (i=0; i<helpsize; i++) {
  89.       xfree(helplist[i].name);
  90.       xfree(helplist[i].location);
  91.    }
  92. }
  93.  
  94. /*****************************************************************************/
  95. /* GET HELP ON SOME TOPIC                                                    */
  96. /*****************************************************************************/
  97. int             /* RETURNS: (nothing)     */
  98. help(argc,argv) /* ARGUMENTS:             */
  99. int    argc;    /*    Number of arguments */
  100. char **argv;    /*    Argument list       */
  101. {
  102.    char **helpfile;
  103.    int    count=1;
  104.  
  105.    if (!(helpfile = grab_file(helpdir,HELPINDEX,0))) return 1;
  106.    do {
  107.       show_help(&count,argc,argv,helpfile[mode],(char*)0);
  108.    } while (count<argc);
  109.    xfree(helpfile);
  110.    return 1;
  111. }
  112.