home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
mar94
/
os20
/
cli
/
man.lha
/
Man
/
Man.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-31
|
21KB
|
872 lines
/*
Auto: sc <file>
*/
/* $Revision Header built automatically *************** (do not edit) ************
**
** © Copyright by GuntherSoft
**
** File : SnakeSYS:CPrgs/Utils/Man.c
** Created on : Friday, 16.07.93 18:00:23
** Created by : Kai Iske
** Current revision : V1.9
**
**
** Purpose
** -------
** - This is a man program, which may scan different directories
** for man-pages. These directories are set within an ENV-VAR
** called MANPATHS. Additionally a VIEWER may be set using
** ENV-VAR MANVIEW (for plain ASCII) or MANVIEWAG (for
** AMIGAGUIDE). THIS ONE`S PURE AND IN THE PUBLIC DOMAIN
**
** Revision V1.9
** --------------
** created on Sunday, 23.01.94 21:36:26 by Kai Iske. LogMessage :
** - Recompiled using SAS/C 6.51
** - Added MANGETFILE parameter
** (Requested by : Bill Hogsett)
**
** Revision V1.8
** --------------
** created on Saturday, 15.01.94 01:14:17 by Kai Iske. LogMessage :
** - Man now correctly handles multi-assigns, since ExAll
** doesn`t....;)
** (Reported by : Jan Hoeydahl)
**
** Revision V1.7
** --------------
** created on Friday, 31.12.93 14:00:28 by Kai Iske. LogMessage :
** - All config variables have been moved to a single one,
** which will be parsed just like a CommandLine
** (Suggested by : Michael 'Mick' Hohmann)
**
** Revision V1.6
** --------------
** created on Thursday, 16.12.93 16:49:51 by Kai Iske. LogMessage :
** - Added MANRMEXT, MANAGEXT and MANNOVIEW options,
** which may be used for extensibility of MAN
** (Somehow suggested by : Michael 'Mick' Hohmann)
**
** Revision V1.5
** --------------
** created on Thursday, 09.12.93 00:58:47 by Kai Iske. LogMessage :
** - Referenced free memory area
**
** Revision V1.4
** --------------
** created on Wednesday, 08.12.93 22:07:47 by Kai Iske. LogMessage :
** -*- created on Wednesday, 08.12.93 22:07:47 by Kai Iske. LogMessage :
** - DOS-Library wasn`t closed
**
** Revision V1.3
** --------------
** created on Wednesday, 08.12.93 19:26:17 by Kai Iske. LogMessage :
** -*- changed on Wednesday, 08.12.93 19:31:23 by Kai Iske. LogMessage :
** - Added CTRL-C checking
** -*- created on Wednesday, 08.12.93 19:26:17 by Kai Iske. LogMessage :
** - Recompiled using SAS 6.50
** - Reduced stack usage
** - Reduced executable size
**
** Revision V1.2
** --------------
** created on Tuesday, 27.07.93 15:20:51 by Kai Iske. LogMessage :
** - Used MAN as a keyword for the template which prevented MAN
** to accept inputs like "man man".
**
** Revision V1.1
** --------------
** created on Monday, 26.07.93 17:42:32 by Kai Iske. LogMessage :
** - Accidentially called Exit() instead of exit(), which
** prevented the program to pass the cleanup code of SAS.
** So a lock to the directory was kept and the shell could
** never been left.............
**
** Revision V1.0
** --------------
** created on Friday, 16.07.93 18:00:23 by Kai Iske. LogMessage :
** -*- changed on Saturday, 17.07.93 16:30:41 by Kai Iske. LogMessage :
** - Man now searches for files that end up with .doc/.man/.guide
** If a .guide file is found, the second Viewer (MANVIEWAG)
** will be used to display the AmigaGuide viewer. Otherwise
** the normal viewer (MANVIEW) will be used
** -*- created on Friday, 16.07.93 18:00:23 by Kai Iske. LogMessage :
** --- Initial release ---
**
*********************************************************************************/
#define REVISION "1.9"
#define REVDATE "23.01.94"
#define REVTIME "21:36:26"
#define AUTHOR "Kai Iske"
#define VERNUM 1
#define REVNUM 9
#define _USE_SYSBASE
/**********************************************************************/
/* This is, so that the code references our Libraries */
/* stored in our structure */
/**********************************************************************/
#define DOSBase MC->mc_DOSBase
#define UtilityBase MC->mc_UtilityBase
#include <string.h>
#include <stdlib.h>
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <libraries/asl.h>
#include <dos/dos.h>
#include <dos/exall.h>
#include <dos/dostags.h>
#include <proto/exec.h>
#include <proto/asl.h>
#include <clib/dos_protos.h>
#include <clib/utility_protos.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/utility_pragmas.h>
/**********************************************************************/
/* This is the private structure for all vars */
/**********************************************************************/
struct ManControl
{
struct DOSLibrary *mc_DOSBase;
struct Library *mc_UtilityBase;
struct ExAllControl *mc_EAC;
char mc_ManOpt[1024],
mc_ManPaths[1024],
mc_ViewCmd[1024],
mc_ViewCmdAG[1024],
mc_CheckDir[1024],
mc_SearchName[1536],
mc_FileName[1024],
mc_Pattern[1024],
mc_NormExt[1024],
mc_AGExt[1024],
mc_NameBuffer[1024],
mc_NonExt[1024];
APTR *mc_EAB;
BPTR mc_OutHandle;
BOOL mc_Found,
mc_Breaked;
};
/**********************************************************************/
/* Prototypes */
/**********************************************************************/
static char *GetDir(char *NewName, char *OldName);
static BOOL DoCheckDir(struct ManControl *MC);
static BOOL IsAssign(struct ManControl *MC);
static void DetermineFileType(struct ManControl *MC);
/**********************************************************************/
/* Version-String */
/**********************************************************************/
static const char *Version = "$VER: Man "REVISION" ("REVDATE")\0";
/**********************************************************************/
/* Template for Command-Line parsing */
/**********************************************************************/
static const char *Template = "MANPAGE/A";
enum {MAN_ARG, TMP_LAST_ARG};
/**********************************************************************/
/* Template for MANOPT settings */
/**********************************************************************/
static const char *ManTemplate = "MANPATHS/K/A,MANVIEW/K/A,MANVIEWAG/K/A,MANNRMEXT/K,MANAGEXT/K,MANNOVIEW/K,MANGETFILE/S";
enum {MANPATHS_ARG, MANVIEW_ARG, MANVIEWAG_ARG, MANNRMEXT_ARG, MANAGEXT_ARG, MANNOVIEW_ARG, MANGETFILE_ARG, MAN_LAST_ARG};
/**********************************************************************/
/* This is the main part */
/**********************************************************************/
ULONG __saveds main(void)
{
struct ManControl *MC;
struct Process *MyProc;
struct RDArgs *RDArgs,
*ManRDArgs;
APTR *Args,
*ManArgs;
ULONG MySig;
char *DirOffset;
BOOL StartedSearch = FALSE,
UseAsl = FALSE;
// Allocate control structure
if(!(MC = AllocVec(sizeof(struct ManControl), MEMF_CLEAR)))
return(20);
MC->mc_Found = FALSE;
MC->mc_Breaked = FALSE;
// Don`t start from WB
MyProc = (struct Process *)FindTask(NULL);
if(!MyProc->pr_CLI)
{
struct WBStartup *Msg;
WaitPort(&MyProc->pr_MsgPort);
Msg = (struct WBStartup *)GetMsg(&MyProc->pr_MsgPort);
Disable();
ReplyMsg((struct Message *)Msg);
FreeVec(MC);
return(0);
}
// Try to open DOSBase
if(!(DOSBase = (struct DOSLibrary *)OpenLibrary("dos.library", 0)))
{
FreeVec(MC);
return(20);
}
// Get Out Handle
MC->mc_OutHandle = Output();
// Check for System we`re running on
if(((struct Library *)*((ULONG **)0x4L))->lib_Version < 37)
{
Write(MC->mc_OutHandle, "You must use KickStart 2.04 (37.175) or higher for MAN\n", 55);
// Close library
CloseLibrary((struct Library *)DOSBase);
// Free buffer
FreeVec(MC);
return(20);
}
// Try to open UtilityBase
if(!(UtilityBase = OpenLibrary("utility.library", 0)))
{
CloseLibrary((struct Library *)DOSBa