Skip to content

Commit 3384fa1

Browse files
author
henesy
committed
make 9p.zone the default grid and rework how public grids are mounted ;; introduce engridden.b ;; fix hd(1) and tl(1) quoting
1 parent 1738507 commit 3384fa1

File tree

6 files changed

+151
-5
lines changed

6 files changed

+151
-5
lines changed

appl/cmd/engridden.b

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
implement Engridden;
2+
3+
include "sys.m";
4+
sys: Sys;
5+
include "draw.m";
6+
include "string.m";
7+
include "env.m";
8+
include "arg.m";
9+
include "bufio.m";
10+
11+
stderr: ref Sys->FD;
12+
13+
Engridden: module {
14+
init: fn(nil: ref Draw->Context, argv: list of string);
15+
};
16+
17+
18+
# Mount ourselves into the public grid
19+
# $pubgridreg sets the public grid registry dialstr
20+
init(nil: ref Draw->Context, argv: list of string)
21+
{
22+
sys = load Sys Sys->PATH;
23+
str := load String String->PATH;
24+
env := load Env Env->PATH;
25+
arg := load Arg Arg->PATH;
26+
bio := load Bufio Bufio->PATH;
27+
Iobuf: import bio;
28+
29+
reg := env->getenv("pubgridreg");
30+
mtpt := "/mnt/registry";
31+
ndir := "/n";
32+
33+
arg->init(argv);
34+
arg->setusage("engridden [-r tcp!registry] [-m /mnt/registry] [-n /n]");
35+
while((c := arg->opt()) != 0)
36+
case c {
37+
'm' => mtpt = arg->earg();
38+
'r' => reg = arg->earg();
39+
'n' => ndir = arg->earg();
40+
* => arg->usage();
41+
}
42+
argv = arg->argv();
43+
44+
if(reg == ""){
45+
sys->print("err: $pubgridreg or '-r' must be provided to mount a registry\n");
46+
exit;
47+
}
48+
49+
sys->print("Mounting public grid registry %s…\n", reg);
50+
51+
if(dialmount(reg, mtpt) < 0)
52+
exit;
53+
54+
buf := bio->open(mtpt + "/index", Bufio->OREAD);
55+
if(buf == nil){
56+
sys->print("err: open failed → %r\n");
57+
exit;
58+
}
59+
60+
Read:
61+
for(;;){
62+
line := buf.gets('\n');
63+
if(line == "")
64+
break Read;
65+
66+
(toks, err) := str->qtokenize(line);
67+
if(err != nil){
68+
sys->print("fail: can't parse line → %s\n", line);
69+
continue Read;
70+
}
71+
72+
if(len toks < 2){
73+
sys->print("fail: not enough tokens in line → %s\n", line);
74+
continue Read;
75+
}
76+
77+
dialstr := hd toks;
78+
name := "";
79+
toks = tl toks;
80+
81+
# Modeled after 9p.zone's registry
82+
for(; toks != nil; toks = tl toks){
83+
case hd toks {
84+
"description" =>
85+
toks = tl toks;
86+
name = hd toks;
87+
88+
* =>
89+
;
90+
}
91+
}
92+
93+
if(dialstr == ""){
94+
sys->print("fail: no dialstring in line → %s\n", line);
95+
continue Read;
96+
}
97+
98+
if(name == ""){
99+
sys->print("fail: could not find 'description' value in line → %s\n", line);
100+
continue Read;
101+
}
102+
at := ndir + "/" + name;
103+
104+
sys->print("Mounting %s at %s…\n", dialstr, at);
105+
106+
if(dialmount(dialstr, at) < 0)
107+
continue Read;
108+
}
109+
110+
sys->print("Done.\n");
111+
112+
exit;
113+
}
114+
115+
dialmount(dialstr, mtpt: string): int {
116+
(ok, conn) := sys->dial(dialstr, nil);
117+
if(ok < 0){
118+
sys->print("err: dial failed for %s → %r\n", dialstr);
119+
return ok;
120+
}
121+
122+
ok = sys->mount(conn.dfd, nil, mtpt, Sys->MREPL|Sys->MCREATE, nil);
123+
if(ok < 0){
124+
sys->print("err: mount failed for %s → %r\n", mtpt);
125+
return ok;
126+
}
127+
128+
return 0;
129+
}

appl/cmd/hd.b

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ init(nil: ref Draw->Context, argv: list of string)
2525

2626
argv = tl argv;
2727

28-
out := str->quoted(hd str->unquoted(str->quoted(argv)) :: nil);
28+
out := hd argv;
29+
(toks, err) := str->qtokenize(out);
30+
if(err != "" || len toks > 1)
31+
out = str->quoted(out :: nil);
2932
sys->print("%s\n", out);
3033

3134
exit;

appl/cmd/mkfile

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ TARG=\
6464
echo.dis\
6565
ed.dis\
6666
emuinit.dis\
67+
engridden.dis\
6768
env.dis\
6869
export.dis\
6970
fc.dis\

appl/cmd/tl.b

+15-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,25 @@ init(nil: ref Draw->Context, argv: list of string)
2020
stderr = sys->fildes(2);
2121
str := load String String->PATH;
2222

23-
if(len argv < 2)
23+
if(len argv < 3)
2424
usage();
2525

2626
argv = tl argv;
2727

28-
out := str->quoted(tl str->unquoted(str->quoted(argv)));
29-
sys->print("%s\n", out);
28+
out := tl argv;
29+
s := "";
30+
for(l := out; l != nil; l = tl l){
31+
w := hd l;
32+
(toks, nil) := str->qtokenize(w);
33+
if(len toks > 1)
34+
w = str->quoted(w :: nil);
35+
s += w + " ";
36+
}
37+
(nil, err) := str->qtokenize(s);
38+
if(err != "")
39+
s = str->quoted(out);
40+
41+
sys->print("%s\n", s);
3042

3143
exit;
3244
}

dis/gridstart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Connect to public grid services
33
load std
44

5-
run /dis/engridden
5+
engridden
66

77
echo '/n/griddisk
88
/fonts/vga/unicode.font

lib/sh/profile

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load std
33

44
user = `{cat /dev/user}
55
home = /usr/^$user
6+
pubgridreg = tcp!registry.9p.zone!registry
67
78
bind /locale/US_Central /locale/timezone
89

0 commit comments

Comments
 (0)