1
0
mirror of https://github.com/PDP-10/its.git synced 2026-03-03 18:26:16 +00:00

SEARCH, search for a string in files.

The files can have * wildcards.
This commit is contained in:
Lars Brinkhoff
2021-08-27 20:25:03 +02:00
parent 2bd04f1466
commit 80a4198d03
4 changed files with 80 additions and 0 deletions

View File

@@ -1498,6 +1498,8 @@ build_c_program "cprog/ralp" "sys2/ts.ralp"
build_c_program "cprog/shell" "sys2/ts.shell" {clib/c10job.stk}
build_c_program "cprog/search" "sys2/ts.search"
# Versatec spooler
# This has some harmless unresolved symbols (FOO, XE4).
respond "*" ":midas sys3;ts versa_dcp; versa\r"

View File

@@ -221,6 +221,7 @@ comlap/st_fas.20 198201251844.23
common/lins.463 199003180412.46
common/yow.22 198902131056.27
cprog/ralp.c 197801091731.46
cprog/search.c 197704190853.24
cprog/shell.c 197710221249.25
c/phase.args 197608191750.12
c/recipe.text 197608280859.25

View File

@@ -304,6 +304,7 @@
- SCRAM, encrypt/decrypt file.
- SCRIMP, XGP unspooler.
- SCRMBL/UNSCR, scramble/unscramble file.
- SEARCH, search for string in files.
- SEND/REPLY, replacements for DDT :SEND.
- SENDS, Chaosnet SEND server.
- SENSOR, an alternate message receiver.

76
src/cprog/search.c Normal file
View File

@@ -0,0 +1,76 @@
# include "c.defs"
char pattern[200];
main (argc, argv)
char *argv[];
{int i, prf();
char *s;
if (argc<3)
{cprint ("usage: search string file ...\n");
return;
}
stcpy (argv[1], pattern);
i = 2;
while (i<argc)
{s = argv[i++];
if (magic (s)) mapdir (s, prf);
else prfs (s);
}
}
magic (s) /* does it contain magic pattern chars? */
char *s;
{int c, flag;
flag = FALSE;
while (c = *s++) switch (c) {
case '?':
case '*': flag = TRUE; continue;
case '/': flag = FALSE; continue;
case '\\': if (*s) ++s; continue;
}
return (flag);
}
prf (fs)
filespec *fs;
{char buf[50];
prfile (fs, buf);
prfs (buf);
}
prfs (s)
char *s;
{char buf[500];
int f, line, ocin;
extern int cin;
ocin = cin;
cprint ("%s:\n", s);
f = copen (s, 'r');
if (f<0)
{cprint ("\tcan't open\n");
return;
}
cin = f;
line = 0;
while (TRUE)
{gets (buf);
if (ceof (cin)) break;
++line;
if (sindex (pattern, buf) >= 0)
cprint ("%d: %s\n", line, buf);
}
cclose (cin);
cin = ocin;
}