home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / os20 / man-1.9.lha / Man / Man.c < prev    next >
C/C++ Source or Header  |  1994-01-31  |  21KB  |  872 lines

  1. /*
  2. Auto:        sc <file>
  3. */
  4.  
  5. /* $Revision Header built automatically *************** (do not edit) ************
  6. **
  7. ** © Copyright by GuntherSoft
  8. **
  9. ** File             : SnakeSYS:CPrgs/Utils/Man.c
  10. ** Created on       : Friday, 16.07.93 18:00:23
  11. ** Created by       : Kai Iske
  12. ** Current revision : V1.9
  13. **
  14. **
  15. ** Purpose
  16. ** -------
  17. **   - This is a man program, which may scan different directories
  18. **     for man-pages. These directories are set within an ENV-VAR
  19. **     called MANPATHS. Additionally a VIEWER may be set using
  20. **     ENV-VAR MANVIEW (for plain ASCII) or MANVIEWAG (for
  21. **     AMIGAGUIDE). THIS ONE`S PURE AND IN THE PUBLIC DOMAIN
  22. **
  23. ** Revision V1.9
  24. ** --------------
  25. ** created on Sunday, 23.01.94 21:36:26  by  Kai Iske.   LogMessage :
  26. **   - Recompiled using SAS/C 6.51
  27. **   - Added MANGETFILE parameter
  28. **     (Requested by : Bill Hogsett)
  29. **
  30. ** Revision V1.8
  31. ** --------------
  32. ** created on Saturday, 15.01.94 01:14:17  by  Kai Iske.   LogMessage :
  33. **   - Man now correctly handles multi-assigns, since ExAll
  34. **     doesn`t....;)
  35. **     (Reported by : Jan Hoeydahl)
  36. **
  37. ** Revision V1.7
  38. ** --------------
  39. ** created on Friday, 31.12.93 14:00:28  by  Kai Iske.   LogMessage :
  40. **   - All config variables have been moved to a single one,
  41. **     which will be parsed just like a CommandLine
  42. **     (Suggested by : Michael 'Mick' Hohmann)
  43. **
  44. ** Revision V1.6
  45. ** --------------
  46. ** created on Thursday, 16.12.93 16:49:51  by  Kai Iske.   LogMessage :
  47. **   - Added MANRMEXT, MANAGEXT and MANNOVIEW options,
  48. **     which may be used for extensibility of MAN
  49. **     (Somehow suggested by : Michael 'Mick' Hohmann)
  50. **
  51. ** Revision V1.5
  52. ** --------------
  53. ** created on Thursday, 09.12.93 00:58:47  by  Kai Iske.   LogMessage :
  54. **   - Referenced free memory area
  55. **
  56. ** Revision V1.4
  57. ** --------------
  58. ** created on Wednesday, 08.12.93 22:07:47  by  Kai Iske.   LogMessage :
  59. **  -*-  created on Wednesday, 08.12.93 22:07:47  by  Kai Iske.   LogMessage :
  60. **   - DOS-Library wasn`t closed
  61. **
  62. ** Revision V1.3
  63. ** --------------
  64. ** created on Wednesday, 08.12.93 19:26:17  by  Kai Iske.   LogMessage :
  65. **  -*-  changed on Wednesday, 08.12.93 19:31:23  by  Kai Iske.   LogMessage :
  66. **   - Added CTRL-C checking
  67. **  -*-  created on Wednesday, 08.12.93 19:26:17  by  Kai Iske.   LogMessage :
  68. **   - Recompiled using SAS 6.50
  69. **   - Reduced stack usage
  70. **   - Reduced executable size
  71. **
  72. ** Revision V1.2
  73. ** --------------
  74. ** created on Tuesday, 27.07.93 15:20:51  by  Kai Iske.   LogMessage :
  75. **   - Used MAN as a keyword for the template which prevented MAN
  76. **     to accept inputs like "man man".
  77. **
  78. ** Revision V1.1
  79. ** --------------
  80. ** created on Monday, 26.07.93 17:42:32  by  Kai Iske.   LogMessage :
  81. **   - Accidentially called Exit() instead of exit(), which
  82. **     prevented the program to pass the cleanup code of SAS.
  83. **     So a lock to the directory was kept and the shell could
  84. **     never been left.............
  85. **
  86. ** Revision V1.0
  87. ** --------------
  88. ** created on Friday, 16.07.93 18:00:23  by  Kai Iske.   LogMessage :
  89. **  -*-  changed on Saturday, 17.07.93 16:30:41  by  Kai Iske.   LogMessage :
  90. **   - Man now searches for files that end up with .doc/.man/.guide
  91. **     If a .guide file is found, the second Viewer (MANVIEWAG)
  92. **     will be used to display the AmigaGuide viewer. Otherwise
  93. **     the normal viewer (MANVIEW) will be used
  94. **  -*-  created on Friday, 16.07.93 18:00:23  by  Kai Iske.   LogMessage :
  95. **     --- Initial release ---
  96. **
  97. *********************************************************************************/
  98. #define REVISION "1.9"
  99. #define REVDATE  "23.01.94"
  100. #define REVTIME  "21:36:26"
  101. #define AUTHOR   "Kai Iske"
  102. #define VERNUM   1
  103. #define REVNUM   9
  104.  
  105.  
  106.  
  107. #define        _USE_SYSBASE
  108.  
  109.  
  110.  
  111. /**********************************************************************/
  112. /*         This is, so that the code references our Libraries         */
  113. /*                      stored in our structure                       */
  114. /**********************************************************************/
  115. #define        DOSBase        MC->mc_DOSBase
  116. #define        UtilityBase    MC->mc_UtilityBase
  117.  
  118.  
  119. #include    <string.h>
  120. #include    <stdlib.h>
  121. #include    <exec/types.h>
  122. #include    <exec/memory.h>
  123. #include    <exec/execbase.h>
  124. #include    <libraries/asl.h>
  125. #include    <dos/dos.h>
  126. #include    <dos/exall.h>
  127. #include    <dos/dostags.h>
  128. #include    <proto/exec.h>
  129. #include    <proto/asl.h>
  130. #include    <clib/dos_protos.h>
  131. #include    <clib/utility_protos.h>
  132. #include    <pragmas/dos_pragmas.h>
  133. #include    <pragmas/utility_pragmas.h>
  134.  
  135.  
  136.  
  137.  
  138. /**********************************************************************/
  139. /*             This is the private structure for all vars             */
  140. /**********************************************************************/
  141. struct ManControl
  142. {
  143.     struct    DOSLibrary    *mc_DOSBase;
  144.     struct    Library        *mc_UtilityBase;
  145.     struct    ExAllControl    *mc_EAC;
  146.     char            mc_ManOpt[1024],
  147.                 mc_ManPaths[1024],
  148.                 mc_ViewCmd[1024],
  149.                 mc_ViewCmdAG[1024],
  150.                 mc_CheckDir[1024],
  151.                 mc_SearchName[1536],
  152.                 mc_FileName[1024],
  153.                 mc_Pattern[1024],
  154.                 mc_NormExt[1024],
  155.                 mc_AGExt[1024],
  156.                 mc_NameBuffer[1024],
  157.                 mc_NonExt[1024];
  158.     APTR            *mc_EAB;
  159.     BPTR            mc_OutHandle;
  160.     BOOL            mc_Found,
  161.                 mc_Breaked;
  162. };
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. /**********************************************************************/
  170. /*                             Prototypes                             */
  171. /**********************************************************************/
  172. static char    *GetDir(char *NewName, char *OldName);
  173. static BOOL    DoCheckDir(struct ManControl *MC);
  174. static BOOL    IsAssign(struct ManControl *MC);
  175. static void    DetermineFileType(struct ManControl *MC);
  176.  
  177.  
  178.  
  179.  
  180.  
  181. /**********************************************************************/
  182. /*                           Version-String                           */
  183. /**********************************************************************/
  184. static const char *Version    = "$VER: Man "REVISION" ("REVDATE")\0";
  185.  
  186.  
  187.  
  188.  
  189. /**********************************************************************/
  190. /*                 Template for Command-Line parsing                  */
  191. /**********************************************************************/
  192. static const char *Template    = "MANPAGE/A";
  193. enum {MAN_ARG, TMP_LAST_ARG};
  194.  
  195.  
  196.  
  197.  
  198. /**********************************************************************/
  199. /*                    Template for MANOPT settings                    */
  200. /**********************************************************************/
  201. static const char *ManTemplate    = "MANPATHS/K/A,MANVIEW/K/A,MANVIEWAG/K/A,MANNRMEXT/K,MANAGEXT/K,MANNOVIEW/K,MANGETFILE/S";
  202. enum {MANPATHS_ARG, MANVIEW_ARG, MANVIEWAG_ARG, MANNRMEXT_ARG, MANAGEXT_ARG, MANNOVIEW_ARG, MANGETFILE_ARG, MAN_LAST_ARG};
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209. /**********************************************************************/
  210. /*                       This is the main part                        */
  211. /**********************************************************************/
  212. ULONG __saveds main(void)
  213. {
  214.     struct    ManControl    *MC;
  215.     struct    Process        *MyProc;
  216.     struct    RDArgs        *RDArgs,
  217.                 *ManRDArgs;
  218.     APTR            *Args,
  219.                 *ManArgs;
  220.     ULONG            MySig;
  221.     char            *DirOffset;
  222.     BOOL            StartedSearch    = FALSE,
  223.                 UseAsl        = FALSE;
  224.  
  225.  
  226.  
  227.         // Allocate control structure
  228.  
  229.     if(!(MC = AllocVec(sizeof(struct ManControl), MEMF_CLEAR)))
  230.         return(20);
  231.  
  232.     MC->mc_Found        = FALSE;
  233.     MC->mc_Breaked        = FALSE;
  234.  
  235.  
  236.  
  237.  
  238.         // Don`t start from WB
  239.  
  240.     MyProc    = (struct Process *)FindTask(NULL);
  241.  
  242.     if(!MyProc->pr_CLI)
  243.     {
  244.         struct    WBStartup    *Msg;
  245.  
  246.         WaitPort(&MyProc->pr_MsgPort);
  247.         Msg    = (struct WBStartup *)GetMsg(&MyProc->pr_MsgPort);
  248.  
  249.         Disable();
  250.         ReplyMsg((struct Message *)Msg);
  251.         FreeVec(MC);
  252.  
  253.         return(0);
  254.     }
  255.  
  256.  
  257.  
  258.         // Try to open DOSBase
  259.  
  260.     if(!(DOSBase    = (struct DOSLibrary *)OpenLibrary("dos.library", 0)))
  261.     {
  262.         FreeVec(MC);
  263.         return(20);
  264.     }
  265.  
  266.  
  267.         // Get Out Handle
  268.  
  269.     MC->mc_OutHandle = Output();
  270.  
  271.  
  272.  
  273.         // Check for System we`re running on
  274.  
  275.     if(((struct Library *)*((ULONG **)0x4L))->lib_Version < 37)
  276.     {
  277.         Write(MC->mc_OutHandle, "You must use KickStart 2.04 (37.175) or higher for MAN\n", 55);
  278.  
  279.             // Close library
  280.  
  281.         CloseLibrary((struct Library *)DOSBase);
  282.             // Free buffer
  283.  
  284.         FreeVec(MC);
  285.         return(20);
  286.     }
  287.  
  288.  
  289.         // Try to open UtilityBase
  290.  
  291.     if(!(UtilityBase = OpenLibrary("utility.library", 0)))
  292.     {
  293.         CloseLibrary((struct Library *)DOSBa