blob: 79ea6ff9dae6bbd5770169332dca8adc3e757a4e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
implement Agrep;
include "sys.m";
include "draw.m";
include "sh.m";
Agrep : module {
init : fn(ctxt : ref Draw->Context, argl : list of string);
};
init(ctxt : ref Draw->Context, argl : list of string)
{
sys := load Sys Sys->PATH;
stderr := sys->fildes(2);
cmd := "grep";
file := cmd + ".dis";
c := load Command file;
if(c == nil) {
err := sys->sprint("%r");
if(file[0]!='/' && file[0:2]!="./"){
c = load Command "/dis/"+file;
if(c == nil)
err = sys->sprint("%r");
}
if(c == nil){
sys->fprint(stderr, "%s: %s\n", cmd, err);
return;
}
}
argl = tl argl;
argl = rev(argl);
argl = "/dev/null" :: argl;
argl = rev(argl);
argl = "-n" :: argl;
argl = cmd :: argl;
c->init(ctxt, argl);
}
rev(a : list of string) : list of string
{
b : list of string;
for ( ; a != nil; a = tl a)
b = hd a :: b;
return b;
}
|