home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 9
/
FreshFishVol9-CD2.bin
/
bbs
/
util
/
browserii-3.0.lha
/
BrowserII
/
Sources
/
For.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-09
|
21KB
|
747 lines
/*
* Copyright © 1992-94 by S.R. & P.C.
*
* Created: 30 Mar 1992 18:26:36
* Modified: 09 Nov 1994 23:11:45
*
* Make>> rx BumpRev For 3 8
* Make>> sc <file>.c
* Make>> slink LIB:cs.o <file>.o SC SD BATCH NOICONS TO <file> LIB LIB:c.lib
* Make>> protect <file> P ADD
*
*
* 30/03/1992: V1.0 (Pierre Carrette)
* Simple version with template: "Args/M,ALL/S,DONTFAIL/S,DO/K/A/F"
* 4/07/1994: V2.2 (Sylvain Rougier)
* No longer add the name of the object if no '%%' present
* 5/07/1994: V3.0
* Add the 'Quiet' option not to print hierarchy (but still print FileType if asked)
* Now work as it should always work: don't scan all the directory if no pattern
* but scan all subdir if 'All' option specified.
* Add the 'GivePathName' option to provide a Full Path arguments to the command.
* No longuer add '"' around the file name. User can type '"%%"' if he need it.
* 7/07/1994 V3.1
* If a full pathname file entry was specified, For don't find it type. fixed
* 15/07/1994 V3.2
* Guru if a single file was suplied. fixed
* Now FullPathArgs realy work
* Don't put optimize or it guru ! (see note)
* 31/07/1994 V3.3
* Check the stack size because it need at least 8192 (probably !...)
* put optimize again. just to see.
* 07/08/1994 V3.4
* Remove optimize because the sasc bug still here
* correct some error int the doc ( the '*' was incorrectly used instead of the '"')
* 21/08/1994 V3.5
* Now use StackSwap() to avoid stack pb
* 22/09/1994 V3.6 (Pierre Carrette is back :-)
* Major code cleanup. No more need StackSwap(). Bug fixes in template. whatis.library now Optional.
* Inverted 'Quiet' to 'Verbose'. Changed 'VNFileType' to more comprehensive 'FileTypeVar' keyword.
* Changed 'GivePathName' to 'FullPathArgs'.
* FileTypeVar was not set if Showbytes was off.
* Showbytes/ShowFileType is now off if no Cmd supplied.
* 'Type' argument syntax simplified. now: "#text,!source c"
* MatchFileType() bug fix. "#text,!source c" was not working!!
* SAS Optimisation now works!!!
* 22/09/1994 V3.7
* Recompiled with new version of c.lib which had a bug for 'ENV:' var parsing
* 09/11/1994 V3.8
* Bug fix. File UnLock()ed before processed so that command can open it for writing.
*/
#include <clib.h>
#include <libraries/WhatIsBase.h>
#include <proto/WhatIs.h>
#include "For_rev.h"
// Startup Modules...
CliArgs; ReadEnvArgs("For");
static char Version[] = VERSTAG;
STRPTR Template = "\
Pattern/A/M,Files/K,Dirs/K,Since/K,Before/K,MinSize/K/N,MaxSize/K/N,\
PosProtect/K,NegProtect/K,Type/K,All/S,ASync/S,ReadSize/K/N,ShowBytes/K/N,\
D=Deep/K/N,SFT=ShowFileType/S,FTV=FileTypeVar/K,FPA=FullPathArgs/S,Verbose/S,Do/K/F";
STRPTR CliHelp = VERS" ("DATE")
© Sylvain Rougier & Pierre Carrette.
\n\
Usage: For <Pattern> [Files <MATCH|YES|NO>] [Dirs <MATCH|YES|NO>]\n\
[Since <Date>] [Before <Date>] [MinSize <Number>] [MaxSize <Number>]\n\
[PosProtect <L|C|H|S|P|A|R|W|E|D>] [NegProtect <L|C|H|S|P|A|R|W|E|D>]\n\
[Type <[#=SUB,~=EXLC]FileType0,,,FileType15>] [All] [ASync] [ReadSize]\n\
[ShowBytes] [Deep] [ShowFileType] [FileTypeVar <var name>] [FullPathArgs]\n\
[DO <Command [args] [,Command [args] [,...]]>]\n";
#define ARG_Template 0
#define ARG_Files 1
#define ARG_Dirs 2
#define ARG_Since 3
#define ARG_Before 4
#define ARG_MinSize 5
#define ARG_MaxSize 6
#define ARG_PosProtect 7
#define ARG_NegProtect 8
#define ARG_Type 9
#define ARG_ALL 10
#define ARG_ASYNC 11
#define ARG_READSIZE 12
#define ARG_SHOWBYTES 13
#define ARG_DEEPWHATIS 14
#define ARG_SHOWFILETYPE 15
#define ARG_FileTypeVar 16
#define ARG_FullPathArgs 17
#define ARG_Verbose 18
#define ARG_CMD 19
#define ARG_ENDARG 20
struct Library *WhatIsBase;
#define MAX_PATHLEN 256
#define MAX_CMDLEN 512
/* char used in the filetype spec string */
#define NOTFileType '~'
#define WITHSubTypes '#'
/*******************************************************/
/* not in dos.h !! */
#define FIBB_HOLD 7
#define FIBF_HOLD (1<<FIBB_HOLD)
/* it is my own definition: not standard */
#define FIBB_COMMENT 8
#define FIBF_COMMENT (1<<FIBB_COMMENT)
#define FIBB_LINK 9
#define FIBF_LINK (1<<FIBB_LINK)
#define PATTERN_BUF_SIZE 40
#define MAX_FTS 16 /* Max FileTypeSpec in SelectInfo */
struct FileTypeSpec {
FileType fs_FileType;
UWORD fs_Flags;
};
/* FileTypeSpec flags */
#define FTSF_EXCLUDETYPE 0x0001 /* Exclude this type (otherwise include) */
#define FTSF_WITHSUBTYPES 0x0002 /* Affect Include/Exclude to subtypes */
struct SelectInfo {
UBYTE si_PatTok[PATTERN_BUF_SIZE]; /* PreParsed pattern */
LONG si_MinSize; /* Show files bigger than that */
LONG si_MaxSize; /* and smaller than that */
struct DateStamp si_SinceDate; /* Show files newer than that */
struct DateStamp si_BeforeDate; /* and older than that */
UWORD si_PosProtect; /* Show files that have these bits set */
UWORD si_NegProtect; /* Show files that have these bits clear */
struct FileTypeSpec si_FileTypes[MAX_FTS]; /* Include and Exclude file types */
UWORD si_NumFts; /* Number of FileTypeSpec in previous array */
UWORD si_Flags; /* Flags. See below */
};
/* SelectInfo flags */
#define SI_ALL_FILES 0x0001
#define SI_MATCH_FILES 0x0002
#define SI_ALL_DIRS 0x0004
#define SI_MATCH_DIRS 0x0008
#define SI_AFFECT_SUBDIRS 0x0010
#define SI_NAME 0x0020
#define SI_SIZE 0x0040
#define SI_SINCEDATE 0x0080
#define SI_BEFOREDATE 0x0100
#define SI_POSPROTECTION 0x0200
#define SI_NEGPROTECTION 0x0400
#define SI_POSFILETYPE 0x0800
#define SI_NEGFILETYPE 0x1000
#define SI_FILETYPE (SI_POSFILETYPE|SI_NEGFILETYPE)
#define SI_MATCHBITS (SI_NAME|SI_SIZE|SI_SINCEDATE|SI_BEFOREDATE|SI_POSPROTECTION|SI_NEGPROTECTION|SI_FILETYPE)
struct Opt {
BOOL Verbose; /* Print some information */
BOOL Async; /* Run commands Asynchronously */
BOOL FullPathArgs; /* Give Full PathName in Fmt ? */
BOOL ShowFileType; /* Show FileType ? */
LONG ReadSize; /* Size to read to find filetype */
ULONG Deep; /* deep level to find FileType */
UWORD Showbytes; /* number of bytes to show */
STRPTR FileTypeVar; /* Name of FileType var. no var if null */
};
/* return pointer to the first non blank char in a string, or to the '\0' if the string is empty */
static char *FirstNonBlank(char *buf)
{
while (*buf && *buf == ' ')
buf++;
return buf;
}
/* check if buffer is empty or not */
static BOOL IsEmpty(char *buf)
{
return (BOOL) ((*FirstNonBlank(buf)) ? FALSE : TRUE);
}
static BOOL String2Date(char *src, struct DateStamp *ds)
{
struct DateTime *dt;
BOOL Ok = TRUE;
char *s1, *s2;
char buf[60];
if (!(dt = AllocMem(sizeof(struct DateTime), MEMF_PUBLIC | MEMF_CLEAR)))
return FALSE;
strcpy(buf, src);
s1 = s2 = FirstNonBlank(buf);
if (*s1) {
dt->dat_StrDate = s1;
while (*s2 && *s2 != ' ')
s2++;
if (*s2) {
*s2++ = '\0';
s2 = FirstNonBlank(s2);
}
if (*s2) {
dt->dat_StrTime = s2;
if (!StrToDate(dt))
Ok = FALSE;
}
else if (!StrToDate(dt)) {
dt->dat_StrDate = NULL;
dt->dat_StrTime = s1;
if (!StrToDate(dt))
Ok = FALSE;
}
if (Ok)
*ds = dt->dat_Stamp;
}
FreeMem(dt, sizeof(struct DateTime));
return Ok;
}
static void PrintByte(UBYTE Buffer[], LONG BufLen, UBYTE Num)
{
register short i;
if (BufLen > 0) {
for (i = 0; i < Num && i < BufLen; i++)
Printf("%02lx", Buffer[i]);
}
}
/*
* Parse a line that may contain comas. Backslash ('\') is the override char.
*/
static UWORD ProtectBit(char P[])
{
UWORD PB = 0;
while (*P) {
switch (*P) {
case 'L':
case 'l':
PB |= FIBF_LINK; /* another magic bit! */
break;
case 'C':
case 'c':
PB |= FIBF_COMMENT; /* our magic bit! */
break;
case 'H':
case 'h':
PB |= FIBF_HOLD;
break;
case 'S':
case 's':
PB |= FIBF_SCRIPT;
break;
case 'P':
case 'p':
PB |= FIBF_PURE;
break;
case 'A':
case 'a':
PB |= FIBF_ARCHIVE;
break;
case 'R':
case 'r':
PB |= FIBF_READ;
break;
case 'W