home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 16 / FREEDOS.ZIP / FD_A4PRE.ZIP / SOURCE / MICROC.ZIP / MAN.C < prev    next >
C/C++ Source or Header  |  1995-06-21  |  3KB  |  130 lines

  1. /***********************************************************************
  2.  * This program displays the help pages for Free-DOS.  It assumes the
  3.  * env. variables HELPATH and PAGER have been set.  HELPPATH should not
  4.  * have a trailing backslash.
  5.  *
  6.  * Author: James Hall
  7.  */
  8.  
  9. /*
  10.    This program is free software; you can redistribute it and/or modify
  11.    it under the terms of the GNU General Public License as published by
  12.    the Free Software Foundation; either version 2 of the License, or
  13.    (at your option) any later version.
  14.  
  15.    This program is distributed in the hope that it will be useful,
  16.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.    You should have received a copy of the GNU General Public License
  21.    along with this program; if not, write to the Free Software
  22.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <file.h>               /* Declares FF_block, etc. */
  27. #include "freedos.h"            /* Free-DOS stuff */
  28. #include "getopt.c"             /* For getopt */
  29. #include "pagef.c"              /* File pager */
  30.  
  31. void usage (void);
  32. int topics (char item[MAX_STR], char path[MAX_STR]);
  33.  
  34. main (int argc, char **argv)
  35.  
  36. {
  37.     int i;
  38.     char *buf, hPager[MAX_STR], hPath[MAX_STR], hItem[MAX_STR], 
  39.         hDisplay[MAX_STR];
  40.  
  41.     FILE *tempfile;
  42.  
  43.     /* Scan the command line */
  44.     while ((i = getopt (argc, argv, NULL, NULL )) != EOF)
  45.         {
  46.         switch (i)
  47.             {
  48.             default:
  49.                 usage ();
  50.                 break;
  51.             }
  52.         }
  53.  
  54.     if ((argc - optind) < 1)
  55.         {
  56.         strcpy (hItem, "\0");
  57.         topics (hItem, hPath);
  58.         }
  59.  
  60.     /* Get the environment variables */
  61.     if (getenv ("HELPPATH", buf))
  62.         strcpy (hPath, buf);
  63.     else
  64.         strcpy (hPath, "C:\\FREEDOS\\HELP");
  65.  
  66.     /* Display the Help pages */
  67.     for (i = optind; i < argc; i++)
  68.         {
  69.         strcpy (hItem, argv[i]);
  70.         strupr (hItem);
  71.         if (getenv ("PAGER", buf))
  72.             {
  73.             strcpy (hPager, buf);
  74.             sprintf (hDisplay, "%s %s\\%s.", hPager, hPath, hItem);
  75.             if (system (hDisplay))
  76.                 topics (hItem, hPath);
  77.             }
  78.         else
  79.             {
  80.             sprintf (hDisplay, "%s\\%s.", hPath, hItem);
  81.             if ((tempfile = fopen (hDisplay, "r")) != NULL)
  82.                 {
  83.                 pagef (tempfile);
  84.                 fclose (tempfile);
  85.                 }
  86.             else
  87.                 topics(hItem, hPath);
  88.             }
  89.         }
  90.  
  91.     exit (0);
  92.     }
  93.  
  94. void usage (void)
  95. {
  96.     printp ("MAN", "Displays the manual pages for Free-DOS commands");
  97.     printc ("1995", "James Hall and M. \"Hannibal\" Toal");
  98.     printu ("MAN", "[topic..]");
  99.     exit (1);
  100. }
  101.  
  102. int topics (char item[MAX_STR], char path[MAX_STR])
  103.  
  104. {
  105.     struct FF_block fbp;
  106.     char *buf;
  107.  
  108.     printf ("\n");
  109.     printf (MSG_NOHELP, item, path);
  110.     printf ("\n");
  111.  
  112.     sprintf (buf, "%s\\*.", path);
  113.  
  114.     if (!findfirst (buf, fbp, 0))
  115.         {
  116.         printf (MSG_TOPICS);
  117.         printf ("\n");
  118.         do
  119.             {
  120.             printf ("%-20s", fbp.FF_name);
  121.             }
  122.         while (!findnext (fbp)); 
  123.         printf ("\n");
  124.         }
  125.     else
  126.         printf (MSG_NOTOPICS);
  127.  
  128.     exit (1);
  129. }
  130.