home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
8bitfiles.net/archives
/
archives.tar
/
archives
/
canada-remote-systems
/
cpower
/
globcp.arc
/
FINDSTR.C
< prev
next >
Wrap
Text File
|
2019-04-13
|
1KB
|
68 lines
/*
* ├OPYRIGHT (├) ┴DRIAN ╨EPPER, 1989
*
* ┬UT ╔ (┴DRIAN ╨EPPER) CONSIDER THIS
* MATERIAL TO BE IN THE ╨UBLIC ─OMAIN.
*/
/*
* FINDSTR.C - STRING SEARCH PROGRAM
*
* ╘HIS PROGRAM WILL PRINT ALL OCCURRENCES
* OF THE GIVEN STRING IN THE SPECIFIED FILES.
*
* ╘HE FILES CAN BE SPECIFIED AS A LIST OF
* PATTERNS.
*/
#INCLUDE <STDIO.H>
#DEFINE ═┴╪┬╒╞ 250
CHAR *INDEX();
STATIC CHAR *MATCHSTR = ╬╒╠╠;
MAIN(ARGC, ARGV)
UNSIGNED ARGC;
CHAR *ARGV[];
█
INT FINDSTR();
UNSIGNED I;
IF(ARGC < 3)█
FPRINTF(STDOUT, "%S: <MATCH-STRING> FILE(S)\N",
ARGV[0]);
EXIT();
▌
MATCHSTR = ARGV[1];
FOR(I=2; I<ARGC; ++I)
GLOB(ARGV[I],&FINDSTR);
▌
STATIC CHAR BUF[═┴╪┬╒╞] = █0▌;
FINDSTR(FILENAME)
CHAR *FILENAME;
█
╞╔╠┼ INFID;
CHAR *P;
CHAR C1;
UNSIGNED LENGTH, LINENO;
C1 = *MATCHSTR;
LENGTH = STRLEN(MATCHSTR);
INFID = FOPEN(FILENAME, "R");
IF(INFID == ╬╒╠╠) █
FPRINTF(STDOUT, "CANNOT OPEN %S.\N", FILENAME);
RETURN;
▌
FOR (LINENO=1; FGETS(BUF, ═┴╪┬╒╞, INFID); ++LINENO) █
FOR (P=BUF; (P=INDEX(P, C1)) != ╬╒╠╠; ++P) █
/* CONSIDER ALL OCCURRENCES OF C1 */
IF(STRNCMP(P, MATCHSTR, LENGTH) == 0) █
PRINTF("%S %D:%S", FILENAME, LINENO, BUF);
BREAK; /* STOP AFTER FIRST MATCH ON LINE */
▌
▌
▌
FCLOSE(INFID);
▌