|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T g
Length: 1014 (0x3f6)
Types: TextFile
Names: »grep.c«
└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
└─⟦this⟧ »EUUGD11/euug-87hel/sec3/regex/grep.c«
#ifdef vms
#include stdio
#else
#include <stdio.h>
#endif
/*
* Rudimentary grep to test regex routines.
*
* DEBUG is only applicable
* to oZ version of regex. Make sure to
* compile regex.c with -DDEBUG as well.
*
*/
extern char *re_comp();
extern re_exec();
main(argc,argv)
char *argv[];
{
char str[512];
FILE *f;
register int n;
register char *p;
if (argc < 2)
error("usage: grep pat [file]");
if ((p = re_comp(argv[1])) != 0) {
printf("\t%s: %s\n", p, argv[1]);
exit(1);
}
#ifdef DEBUG
symbolic(argv[1]);
#endif
if (p = argv[2]) {
if ((f = fopen(p, "r")) == NULL) {
printf("cannot open %s\n", argv[2]);
exit(1);
}
while ((n = load(str, f)) != EOF)
if (re_exec(str))
printf("%s\n",str);
}
exit(0);
}
load (s, f)
char *s;
FILE *f;
{
register int c;
static int lineno = 0;
while ((c = getc(f)) != '\n' && c != EOF)
*s++ = c;
if (c == EOF)
return (EOF);
*s = (char) 0;
return (++lineno);
}
error(s) char *s ;
{
fprintf(stderr,"%s\n",s);
exit(1);
}