home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / cli / man / man.c < prev    next >
C/C++ Source or Header  |  1994-03-04  |  25KB  |  991 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.11
  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.11
  24. ** --------------
  25. ** created on Monday, 28.02.94 19:33:29  by  Kai Iske.   LogMessage :
  26. **  -*-  changed on Saturday, 05.03.94 02:30:54  by  Kai Iske.   LogMessage :
  27. **   - Man produced an enforcer hit when no manpage was supplied
  28. **     (Reported by : Michael van Elst)
  29. **  -*-  changed on Monday, 28.02.94 20:03:34  by  Kai Iske.   LogMessage :
  30. **   - Man will no longer issue an error if you a) didn`t specify a
  31. **     manpage and b) set the MANGETFILE attribute for the File
  32. **     Requester. This way the Requester will popup if you
  33. **     call MAN without any arguments
  34. **     (Requested by : Bill Hogsett)
  35. **  -*-  changed on Monday, 28.02.94 20:02:39  by  Kai Iske.   LogMessage :
  36. **   - The FileRequester will pop up on the default PubScreen now
  37. **     (Requested by : Bill Hogsett)
  38. **   - The default path for the FileRequester will be set to the
  39. **     first Dir of the MANPATHS now
  40. **     (Requested by : Bill Hogsett)
  41. **  -*-  created on Monday, 28.02.94 19:33:29  by  Kai Iske.   LogMessage :
  42. **   - Support for DVI files added
  43. **   - MAN will set the Viewer`s current dir of that where the
  44. **     man page resides in
  45. **
  46. ** Revision V1.10
  47. ** --------------
  48. ** created on Tuesday, 25.01.94 14:41:58  by  Kai Iske.   LogMessage :
  49. **   - Mike Barsoom added MANBASENAME attribute for stripping
  50. **     off any path names from the manpage name. Useful when
  51. **     launching MAN from within (ie) ToolsDaemon
  52. **     (Submitted by : Mike Barsoom)
  53. **
  54. ** Revision V1.9
  55. ** --------------
  56. ** created on Sunday, 23.01.94 21:36:26  by  Kai Iske.   LogMessage :
  57. **   - Recompiled using SAS/C 6.51
  58. **   - Added MANGETFILE parameter
  59. **     (Requested by : Bill Hogsett)
  60. **
  61. ** Revision V1.8
  62. ** --------------
  63. ** created on Saturday, 15.01.94 01:14:17  by  Kai Iske.   LogMessage :
  64. **   - Man now correctly handles multi-assigns, since ExAll
  65. **     doesn`t....;)
  66. **     (Reported by : Jan Hoeydahl)
  67. **
  68. ** Revision V1.7
  69. ** --------------
  70. ** created on Friday, 31.12.93 14:00:28  by  Kai Iske.   LogMessage :
  71. **   - All config variables have been moved to a single one,
  72. **     which will be parsed just like a CommandLine
  73. **     (Suggested by : Michael 'Mick' Hohmann)
  74. **
  75. ** Revision V1.6
  76. ** --------------
  77. ** created on Thursday, 16.12.93 16:49:51  by  Kai Iske.   LogMessage :
  78. **   - Added MANRMEXT, MANAGEXT and MANNOVIEW options,
  79. **     which may be used for extensibility of MAN
  80. **     (Somehow suggested by : Michael 'Mick' Hohmann)
  81. **
  82. ** Revision V1.5
  83. ** --------------
  84. ** created on Thursday, 09.12.93 00:58:47  by  Kai Iske.   LogMessage :
  85. **   - Referenced free memory area
  86. **
  87. ** Revision V1.4
  88. ** --------------
  89. ** created on Wednesday, 08.12.93 22:07:47  by  Kai Iske.   LogMessage :
  90. **  -*-  created on Wednesday, 08.12.93 22:07:47  by  Kai Iske.   LogMessage :
  91. **   - DOS-Library wasn`t closed
  92. **
  93. ** Revision V1.3
  94. ** --------------
  95. ** created on Wednesday, 08.12.93 19:26:17  by  Kai Iske.   LogMessage :
  96. **  -*-  changed on Wednesday, 08.12.93 19:31:23  by  Kai Iske.   LogMessage :
  97. **   - Added CTRL-C checking
  98. **  -*-  created on Wednesday, 08.12.93 19:26:17  by  Kai Iske.   LogMessage :
  99. **   - Recompiled using SAS 6.50
  100. **   - Reduced stack usage
  101. **   - Reduced executable size
  102. **
  103. ** Revision V1.2
  104. ** --------------
  105. ** created on Tuesday, 27.07.93 15:20:51  by  Kai Iske.   LogMessage :
  106. **   - Used MAN as a keyword for the template which prevented MAN
  107. **     to accept inputs like "man man".
  108. **
  109. ** Revision V1.1
  110. ** --------------
  111. ** created on Monday, 26.07.93 17:42:32  by  Kai Iske.   LogMessage :
  112. **   - Accidentially called Exit() instead of exit(), which
  113. **     prevented the program to pass the cleanup code of SAS.
  114. **     So a lock to the directory was kept and the shell could
  115. **     never been left.............
  116. **
  117. ** Revision V1.0
  118. ** --------------
  119. ** created on Friday, 16.07.93 18:00:23  by  Kai Iske.   LogMessage :
  120. **  -*-  changed on Saturday, 17.07.93 16:30:41  by  Kai Iske.   LogMessage :
  121. **   - Man now searches for files that end up with .doc/.man/.guide
  122. **     If a .guide file is found, the second Viewer (MANVIEWAG)
  123. **     will be used to display the AmigaGuide viewer. Otherwise
  124. **     the normal viewer (MANVIEW) will be used
  125. **  -*-  created on Friday, 16.07.93 18:00:23  by  Kai Iske.   LogMessage :
  126. **     --- Initial release ---
  127. **
  128. *********************************************************************************/
  129. #define REVISION "1.11a"
  130. #define REVDATE  "05.03.94"
  131. #define REVTIME  "02:30:54"
  132. #define AUTHOR   "Kai Iske"
  133. #define VERNUM   1
  134. #define REVNUM   11
  135.  
  136.  
  137.  
  138. #define        _USE_SYSBASE
  139.  
  140.  
  141.  
  142. /**********************************************************************/
  143. /*         This is, so that the code references our Libraries         */
  144. /*                      stored in our structure                       */
  145. /**********************************************************************/
  146. #define        DOSBase        MC->mc_DOSBase
  147. #define        UtilityBase    MC->mc_UtilityBase
  148.  
  149.  
  150. #include    <string.h>
  151. #include    <stdlib.h>
  152. #include    <exec/types.h>
  153. #include    <exec/memory.h>
  154. #include    <exec/execbase.h>
  155. #include    <libraries/asl.h>
  156. #include    <dos/dos.h>
  157. #include    <dos/exall.h>
  158. #include    <dos/dostags.h>
  159. #include    <proto/exec.h>
  160. #include    <proto/asl.h>
  161. #include    <clib/dos_protos.h>
  162. #include    <clib/utility_protos.h>
  163. #include    <pragmas/dos_pragmas.h>
  164. #include    <pragmas/utility_pragmas.h>
  165.  
  166.  
  167.  
  168.  
  169. /**********************************************************************/
  170. /*             This is the private structure for all vars             */
  171. /**********************************************************************/
  172. struct ManControl
  173. {
  174.     struct    DOSLibrary    *mc_DOSBase;
  175.     struct    Library        *mc_UtilityBase;
  176.     struct    ExAllControl    *mc_EAC;
  177.     char            mc_ManOpt[1536],
  178.                 mc_ManPaths[1024],
  179.                 mc_ViewCmd[1024],
  180.                 mc_ViewCmdAG[1024],
  181.                 mc_ViewCmdDVI[1024],
  182.                 mc_CheckDir[1024],
  183.                 mc_SearchName[1536],
  184.                 mc_FileName[1024],
  185.                 mc_Pattern[3074],
  186.                 mc_NormExt[1024],
  187.                 mc_AGExt[1024],
  188.                 mc_DVIExt[1024],
  189.                 mc_NameBuffer[1024],
  190.                 mc_NonExt[1024];
  191.     APTR            *mc_EAB;
  192.     BPTR            mc_OutHandle;
  193.     BOOL            mc_Found,
  194.                 mc_Breaked;
  195. };
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. /**********************************************************************/
  203. /*                             Prototypes                             */
  204. /**********************************************************************/
  205. static char    *GetDir(char *NewName, char *OldName);
  206. static BOOL    DoCheckDir(struct ManControl *MC);
  207. static BOOL    IsAssign(struct ManControl *MC);
  208. static void    DetermineFileType(struct ManControl *MC);
  209.  
  210.  
  211.  
  212.  
  213.  
  214. /**********************************************************************/
  215. /*                           Version-String                           */
  216. /**********************************************************************/
  217. static const char *Version    = "$VER: Man "REVISION" ("REVDATE")\0";
  218.  
  219.  
  220.  
  221.  
  222. /**********************************************************************/
  223. /*                 Template for Command-Line parsing                  */
  224. /**********************************************************************/
  225. static const char *Template    = "MANPAGE";
  226. enum {MAN_ARG, TMP_LAST_ARG};
  227.  
  228.  
  229.  
  230.  
  231. /**********************************************************************/
  232. /*                    Template for MANOPT settings                    */
  233. /**********************************************************************/
  234. static const char *ManTemplate    = "MANPATHS/K/A,MANVIEW/K/A,MANVIEWAG/K/A,MANVIEWDVI/K/A,MANNRMEXT/K,MANAGEXT/K,MANDVIEXT/K,MANNOVIEW/K,MANGETFILE/S,MANBASENAME/S";
  235. enum {MANPATHS_ARG, MANVIEW_ARG, MANVIEWAG_ARG, MANVIEWDVI_ARG, MANNRMEXT_ARG, MANAGEXT_ARG, MANDVIEXT_ARG, M