home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
canada-remote-systems
/
cpower
/
globcp.arc
/
DEVGLOB.C
next >
Wrap
Text File
|
2019-04-13
|
3KB
|
112 lines
/*
* ├OPYRIGHT (├) ┴DRIAN ╨EPPER, 1989
*
* ┬UT ╔ (┴DRIAN ╨EPPER) CONSIDER THIS
* MATERIAL TO BE IN THE ╨UBLIC ─OMAIN.
*/
/*
* DEVGLOB.C - EXPAND WILDCARD FILENAMES
*
* DEVGLOB EXECUTES THE GIVEN FUNCTION
* FOR EACH FILE NAME RETURNED BY A
* DIRECTORY LISTING OF THE GIVEN
* FILENAME WILDCARD PATTERN ON THE
* GIVEN DEVICE
*
* RETURNS AS FUNCTION VALUE THE NUMBER
* OF NAMES MATCHED
*
* ╘HE 'SELECT' FUNCTION ARGUMENT ALLOWS
* THE FILE SELECTION PROCESS TO BE
* CUSTOMIZED.
*/
#INCLUDE <STDIO.H>
/*
* THIS STRUCTURE IS TO CREATE A LINKED
* LIST OF MATCHING FILE NAMES
*/
TYPEDEF STRUCT LINK █
STRUCT LINK *LñNEXT; /* POINT TO NEXT IN LIST */
CHAR *LñNAME; /* POINT TO NAME OF THIS FILE */
▌ ╠╔╬╦;
STATIC ╠╔╬╦ *NAMELIST;
STATIC CHAR BUF[100];
DEVGLOB(DEV,PAT,FUNC,SELECT)
UNSIGNED DEV; /* DEVICE TO USE FOR DIR */
CHAR *PAT; /* FILENAME PATTERN TO EXPAND */
INT (*FUNC)(); /* FUNCTION TO CALL ON MATCHES */
INT (*SELECT)(); /* EXTRA MATCHER */
█
EXTERN CHAR *MALLOC();
EXTERN CHAR *STRDUP();
╠╔╬╦ **PLINK; /* KEEP TRACK OF END OF LIST */
╠╔╬╦ *NLINK; /* POINTER TO NEW ╠╔╬╦ CREATED */
CHAR *NNAME; /* POINTER TO NEW SAVED NAME */
╠╔╬╦ *LLINK; /* GENERAL POINTER TO ╠╔╬╦ */
CHAR *B;
╞╔╠┼ FID;
INT N;
SPRINTF(BUF,"$%S", PAT); /* FORM DIRECTORY NAME */
FID = 5;
IF (!OPEN(FID, DEV, 0, BUF) ▀▀ FERROR() )
RETURN 0;
PLINK = &NAMELIST; /* MATCHING FILE NAMES WILL */
*PLINK = ╬╒╠╠; /* BE SAVED IN A LINKED LIST */
FGETC(FID); /* SKIP "LOAD ADDRESS" */
FGETC(FID); /* ... */
WHILE (GDIRLINE(BUF,FID) != ┼╧╞) █
IF (*BUF != ' ')
; /* NOT A FILENAME LINE; SKIP IT */
ELSE █
FOR (B = BUF+STRLEN(BUF);
B > BUF && *B != '"'; --B)
;
*B = '\0';
FOR (B = BUF; *B != '\0' && *B++ != '"'; )
; /* SKIP TO ┼╧╙ OR AFTER FIRST '"' */
IF (!SELECT ▀▀ (*SELECT)(B)) █
/* GOT A GOOD ONE! */
/* USE MALLOC TO CREATE A ╠╔╬╦ STRUCT FOR LIST */
NLINK = (╠╔╬╦ *)MALLOC(1,SIZEOF(╠╔╬╦));
NNAME = STRDUP(B); /* SAVE COPY OF NAME */
/* NOTE: BUG IN ╨╧╫┼╥ ├ CAUSES LOW BYTE */
/* ONLY TO BE TESTED IF ASSIGNMENT DONE INSIDE IF */
IF (!NLINK ▀▀ !NNAME) █
PRINTF("GLOB: TOO MANY NAMES AT %S\N", B );
BREAK; /* FINISH PREMATURELY */
▌
NLINK->LñNAME = NNAME; /* POINT TO NAME */
*PLINK = NLINK; /* AND LINK NEW ╠╔╬╦ */
PLINK = &NLINK->LñNEXT; /* LINK NEXT ONE HERE */
*PLINK = ╬╒╠╠; /* ╬╒╠╠ (END) FOR NOW */
▌
▌
▌
FCLOSE(FID); /* FCLOSE FOR OPEN() ALLOWS RE-USE */
/*
* NOW RUN THROUGH THE LIST OF SAVED
* NAMES, EXECUTING THE FUNCTION FOR
* EACH ONE
*/
N = 0;
FOR (LLINK = NAMELIST; LLINK; LLINK=NLINK) █
IF (FUNC)
(*FUNC)(LLINK->LñNAME); /* CALL FUNCTION */
NLINK = LLINK->LñNEXT; /* REMEMBER NEXT */
FREE(LLINK->LñNAME); /* BEFORE PTR FREED */
FREE(LLINK);
++N; /* COUNT MATCHING NAMES */
▌
RETURN N;
▌