home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / HELP.C < prev    next >
C/C++ Source or Header  |  1993-03-07  |  2KB  |  67 lines

  1. /* Help.c written by paul@wolf.demon.co.uk for ka9qnos */
  2. /* Generic help routine, using a single help file with multiple topics */
  3. #include <stdio.h>
  4. #include "global.h"
  5. #include "ftp.h"
  6. #include "proc.h"
  7. #include "cmdparse.h"
  8. #include "help.h"
  9.  
  10. /* Call help routine with the helpfile name in 'helpfile'
  11.  *  the current command list structure array in 'cmdlist',
  12.  *  and the help arguments in argc and argv
  13.  */
  14. /* The helpfile lives in the Helpdir directory (as specified
  15.  * in files.h
  16.  * For the format of an example help file, look at FTP.HLP
  17.  */
  18. int
  19. helproutine(argc,argv,cmdlist,helpfile)
  20. int argc;
  21. char *argv[];
  22. struct cmds *cmdlist;
  23. char *helpfile;
  24. {
  25.     char helpcmd[255],
  26.          buf[85];
  27.     int i;
  28.     FILE *fp;
  29.     int found=0;
  30.  
  31.     strcpy(helpcmd,"help"); /* if command isn't found use 'help' as topic */
  32.     if(argc > 1)
  33.         for(i=0; cmdlist[i].name != NULLCHAR; ++i)
  34.             if(!strncmp(cmdlist[i].name,argv[1],strlen(argv[1]))) {
  35.                 strcpy(helpcmd,cmdlist[i].name);
  36.                 break;
  37.             }
  38.     strcat(helpcmd,"}");
  39.  
  40.     /* Scan helpfile looking for topic */
  41.     if((fp = fopen(helpfile,READ_TEXT)) != NULLFILE) {
  42.         while (fgets(buf,84,fp)!=NULL)
  43.         {
  44.             if (buf[0]=='{') {
  45.                 if (found)
  46.                     break;
  47.                 else
  48.                 if (strnicmp(buf+1,helpcmd,strlen(helpcmd))==0)
  49.                     found=1;
  50.              continue;
  51.             }
  52.             if (found)
  53.                 tprintf(buf);
  54.         }
  55.         if (!found)
  56.         {
  57.             helpcmd[strlen(helpcmd)-1]=0;
  58.             tprintf("No help available. (topic %s not found)\n",helpcmd);
  59.         }
  60.         fclose(fp);
  61.     }
  62.     else
  63.         tprintf("No help available. (file %s not found)\n",helpfile);
  64.     return 0;
  65. }
  66.  
  67.