home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
451.lha
/
SType
/
SType.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-08
|
4KB
|
167 lines
/*======================================================*/
/* */
/* Type a file */
/* © J.Tyberghein */
/* Thu Aug 16 17:00:45 1990 V1.0 */
/* Mon Sep 24 10:07:11 1990 */
/* */
/*======================================================*/
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <dos/rdargs.h>
#include <string.h>
/*================================== Data ====================================*/
char CLI_Help[] = "\
Special Type 1.0
Written by J.Tyberghein from PowerPeak, 24 Sep 90
\n\n\
Usage:\n\
SType <File> [From <line>] [TO <line>] [Page <lines>]\n\n\
With:\n\
File : the file you want to type\n\
Page : list per pages\n\
From : the line number where you want to start typing\n\
To : the line number where you want to stop typing\n";
char CLI_Template[] = "File/a,F=FROM/n,TO/n,P=PAGE/n";
struct RDArgs *rcrda = NULL;
BPTR fh = 0;
extern APTR DOSBase;
void RealMain (char *file, int From, int To, int Page);
void __regargs CloseStuff (int);
void myPrintf (char *FormatStr, ...);
void OpenStuff ();
typedef void (*fntype)();
#define ERR_OPEN -1
#define ERR_READ -2
#define ERR_LIB -3
/*================================== Code ====================================*/
/*------------------------------- main program -------------------------------*/
void argmain ()
{
LONG Args[4];
int From,To,Page;
OpenStuff ();
Args[1] = Args[2] = Args[3] = 0;
rcrda = ReadArgs (CLI_Template,Args,NULL);
if (!rcrda)
{
PutStr (CLI_Help);
CloseStuff (0);
}
From = 0;
To = 2000000000;
Page = 0;
if (Args[1]) From = *(int *)Args[1];
if (Args[2]) To = *(int *)Args[2];
if (Args[3]) Page = *(int *)Args[3];
RealMain ((char *)Args[0],From,To,Page);
}
/*---------------------------------- printf ----------------------------------*/
void myPrintf (char *FormatStr, ...)
{
VPrintf (FormatStr,(LONG *)((&FormatStr)+1));
}
/*-------------------------------- CloseStuff --------------------------------*/
void __regargs CloseStuff (int Error)
{
if (fh) Close (fh);
if (rcrda) FreeArgs (rcrda);
XCEXIT (Error);
}
/*------------------------------ Print an error ------------------------------*/
void __regargs SayError (int Error, char *Object)
{
char *Head,*ObjSort;
ObjSort = "file";
switch (Error)
{
case ERR_OPEN : Head = "opening"; break;
case ERR_READ : Head = "reading"; break;
}
myPrintf ("\015
ERROR:
%s %s %s !\n",Head,ObjSort,Object);
CloseStuff (Error);
}
/*------------------------- Open everything we need --------------------------*/
void OpenStuff ()
{
APTR DosBase;
if (!(DosBase = (APTR)OpenLibrary (DOSNAME,36)))
{
Write (Output (),"Needs AmigaDOS 2.0 !\n",21);
XCEXIT (ERR_LIB);
}
CloseLibrary ((struct Library *)DosBase);
}
/*------------------------------ Main program --------------------------------*/
void RealMain (char *file, int From, int To, int Page)
{
int lin,pl;
char line[256],*i;
if (!(fh = Open (file,MODE_OLDFILE))) SayError (ERR_OPEN,file);
lin = 1;
pl = 0;
while (i = FGets (fh,line,255))
{
if (CheckSignal (SIGBREAKF_CTRL_C) == SIGBREAKF_CTRL_C)
{
PutStr ("***Break\n");
CloseStuff (0);
}
if (lin>=From && lin<=To)
{
if (Page)
{
if (pl == Page)
{
Write (Output (),"
--- MORE ---
",20);
if (FGetC (Input ()) == 'q') CloseStuff (0);
pl = 1;
}
else pl++;
}
PutStr (line);
}
lin++;
}
if (!i && IoErr ()) SayError (ERR_READ,file);
CloseStuff (0);
}
/*================================ The end ===================================*/