home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / dmail / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-13  |  2.7 KB  |  150 lines

  1. /*
  2.  * HELP.C
  3.  *
  4.  *  (C) Copyright 1985-1990 by Matthew Dillon,    All Rights Reserved.
  5.  *
  6.  *  Global Routines:    DO_HELP()
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. #include "dmail.h"
  14. #include "execom.h"
  15. #include "config.h"
  16.  
  17. #ifdef AMIGA
  18. #define HELPFILE "dmail.help"
  19. #endif
  20.  
  21. Prototype int  do_help (char *garbage, int com);
  22.  
  23. #ifndef HELPFILE
  24. static char *help[] = {
  25. #include ".dmkout"
  26. };
  27.  
  28. int
  29. do_help (char *garbage, int com)
  30. {
  31.     int i, j;
  32.     char *ptr;
  33.  
  34.     if (push_base()) {
  35.     push_break();
  36.     pop_base();
  37.     PAGER (-1);
  38.     pop_break();
  39.     return;
  40.     }
  41.     PAGER (0);
  42.     if (ac == 1) {
  43.     for (j = 0; help[j] && *help[j] != '.'; ++j)
  44.         PAGER (help[j]);
  45.     for (i = 0; Command[i].name != NULL; ++i) {
  46.         if (*Command[i].name && !(Command[i].stat & C_NO)) {
  47.         if (Desc[i] == NULL)
  48.             puts("Software error, premature EOF in description table");
  49.         sprintf (Puf, "%-10s %s", Command[i].name, Desc[i]);
  50.         PAGER (Puf);
  51.         }
  52.     }
  53.     }
  54.     PAGER ("");
  55.     for (i = 1; i < ac; ++i) {
  56.     j = 0;
  57. again:
  58.     while (help[j]    &&  *help[j] != '.')
  59.         ++j;
  60.     if (help[j]) {
  61.         if (strncmp (av[i], help[j] + 1, strlen(av[i]))) {
  62.         ++j;
  63.         goto again;
  64.         }
  65.         while (help[j]  &&    *help[j] == '.')
  66.         ++j;
  67.         while (help[j]  &&    *help[j] != '.')
  68.         PAGER (help[j++]);
  69.         PAGER ("");
  70.         goto again;
  71.     }
  72.     }
  73.     PAGER (-1);
  74.     pop_base();
  75. }
  76.  
  77. #else
  78.  
  79. int
  80. do_help (char *garbage, int com)
  81. {
  82.     int i;
  83.     FILE *fi = NULL;
  84.     char *eof;
  85.  
  86.     if (push_base()) {
  87.     push_break();
  88.     pop_base();
  89.     PAGER ((char *) -1);
  90.     if (fi != NULL) {
  91.         fclose (fi);
  92.         fi = NULL;
  93.     }
  94.     pop_break();
  95.     return (-1);
  96.     }
  97. #ifdef AMIGA
  98.     fi = fopen (MakeConfigPath(UUMAN, HELPFILE), "r");
  99. #else
  100.     fi = fopen (HELPFILE, "r");
  101. #endif
  102.     if (fi == NULL) {
  103.     printf ("Cannot open help file: %s\n", HELPFILE);
  104.     PAGER ((char *) -1);
  105.     pop_base();
  106.     return (-1);
  107.     }
  108.     PAGER (0);
  109.     if (ac == 1) {
  110.     while (fgets (Puf, MAXFIELDSIZE, fi)  &&  *Puf != '.')
  111.         FPAGER (Puf);
  112.     fclose (fi);
  113.     fi = NULL;
  114.     for (i = 0; Command[i].name != NULL; ++i) {
  115.         if (*Command[i].name) {
  116.         sprintf (Puf, "%-10s %s", Command[i].name, Desc[i]);
  117.         PAGER (Puf);
  118.         }
  119.     }
  120.     PAGER ((char *) -1);
  121.     pop_base();
  122.     return (1);
  123.     }
  124.     PAGER ("");
  125.     for (i = 1; i < ac; ++i) {
  126.     fseek (fi, 0, 0);
  127. again:
  128.     while ((eof = fgets (Puf, MAXFIELDSIZE, fi))  &&  *Puf != '.');
  129.     if (!eof)
  130.         continue;
  131.     if (strncmp (av[i], Puf + 1, strlen(av[i])))
  132.         goto again;
  133.     while ((eof = fgets (Puf, MAXFIELDSIZE, fi))  &&  *Puf == '.');
  134.     if (!eof)
  135.         continue;
  136.     FPAGER (Puf);
  137.     while ((eof = fgets (Puf, MAXFIELDSIZE, fi))  &&  *Puf != '.')
  138.         FPAGER (Puf);
  139.     PAGER ("");
  140.     if (!eof)
  141.         continue;
  142.     goto again;
  143.     }
  144.     fclose (fi);
  145.     fi = NULL;
  146.     PAGER ((char *) -1);
  147.     pop_base();
  148. }
  149. #endif
  150.