-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
3,026 additions
and
147 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/dis/sh.dis | ||
|
||
webgrab -r -o - $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/dis/sh.dis | ||
index=/man/index | ||
x=$* | ||
*=`{echo $x|tr A-Z a-z|tr -dc 'a-z0-9_ \012'} # fold case, delete funny chars | ||
if {no $*}{ | ||
echo Usage: lookman key ... | ||
exit 1 | ||
} | ||
|
||
for i in $* { | ||
look $1 $index|sed 's/.* //'| sort | uniq |sed 's;/man/;; | ||
s;(.*)/(.*);man \1 \2 \# \2(\1);' | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
implement Plumb; | ||
|
||
include "sys.m"; | ||
sys: Sys; | ||
|
||
include "draw.m"; | ||
|
||
include "arg.m"; | ||
arg: Arg; | ||
|
||
include "plumbmsg.m"; | ||
plumbmsg: Plumbmsg; | ||
Msg, Attr: import plumbmsg; | ||
|
||
include "workdir.m"; | ||
workdir: Workdir; | ||
|
||
Plumb: module | ||
{ | ||
init: fn(nil: ref Draw->Context, nil: list of string); | ||
}; | ||
|
||
m : ref Msg; | ||
usage() | ||
{ | ||
sys->fprint(stderr(), "Usage: plumb [-s src] [-d dest] [-D dir] [-k kind] [-a name val] -i | ... data ...\n"); | ||
raise "fail:usage"; | ||
} | ||
|
||
gather() | ||
{ | ||
buf := array[8192] of byte; | ||
n, ndata: int; | ||
|
||
ndata = 0; | ||
m.data = nil; | ||
while((n = sys->read(sys->fildes(0), buf, len buf)) > 0){ | ||
b := array[ndata + len buf] of byte; | ||
if(b == nil){ | ||
err(sys->sprint("alloc failed: %r\n")); | ||
raise "alloc"; | ||
} | ||
if (ndata > 0) | ||
b[0:] = m.data[0:ndata]; | ||
b[ndata:] = buf[0:n]; | ||
m.data = b[0:ndata+n]; | ||
ndata += n; | ||
} | ||
|
||
if (n < 0){ | ||
err(sys->sprint("i/o error on input: %r\n")); | ||
raise "read"; | ||
} | ||
} | ||
|
||
init(nil: ref Draw->Context, args: list of string) | ||
{ | ||
sys = load Sys Sys->PATH; | ||
arg = load Arg Arg->PATH; | ||
if(arg == nil) | ||
nomod(Arg->PATH); | ||
plumbmsg = load Plumbmsg Plumbmsg->PATH; | ||
if(plumbmsg == nil) | ||
nomod(Plumbmsg->PATH); | ||
workdir = load Workdir Workdir->PATH; | ||
if(workdir == nil) | ||
nomod(Workdir->PATH); | ||
|
||
if(plumbmsg->init(1, nil, 0) < 0) | ||
err(sys->sprint("can't connect to plumb: %r")); | ||
|
||
attrs: list of ref Attr; | ||
input := 0; | ||
m = ref Msg("plumb", nil, workdir->init(), "text", nil, nil); | ||
arg->init(args); | ||
while((c := arg->opt()) != 0) | ||
case c { | ||
's' => | ||
m.src = use(arg->arg(), c); | ||
'd' => | ||
m.dst = use(arg->arg(), c); | ||
'D' => | ||
m.dir = use(arg->arg(), c); | ||
'i' => | ||
input++; | ||
't' or 'k'=> | ||
m.kind = use(arg->arg(), c); | ||
'a' => | ||
name := use(arg->arg(), c); | ||
val := use(arg->arg(), c); | ||
attrs = tack(attrs, ref Attr(name, val)); | ||
* => | ||
usage(); | ||
} | ||
args = arg->argv(); | ||
if((input && len args > 0) || (!input && len args < 1)) | ||
usage(); | ||
if(input){ | ||
gather(); | ||
(notfound, nil) := plumbmsg->lookup(plumbmsg->string2attrs(m.attr), "action"); | ||
if(notfound){ | ||
tack(attrs, ref Attr("action", "showdata")); | ||
} | ||
m.attr = plumbmsg->attrs2string(attrs); | ||
if(m.send() < 0){ | ||
err(sys->sprint("can't send message: %r\n")); | ||
raise "error"; | ||
} | ||
exit; | ||
} | ||
|
||
nb := 0; | ||
for(a := args; a != nil; a = tl a) | ||
nb += len array of byte hd a; | ||
nb += len args; | ||
buf := array[nb] of byte; | ||
nb = 0; | ||
for(a = args; a != nil; a = tl a){ | ||
b := array of byte hd a; | ||
buf[nb++] = byte ' '; | ||
buf[nb:] = b; | ||
nb += len b; | ||
} | ||
m.data = buf[1:]; | ||
m.attr = plumbmsg->attrs2string(attrs); | ||
if(m.send() < 0) | ||
err(sys->sprint("can't plumb message: %r")); | ||
} | ||
|
||
tack(l: list of ref Attr, v: ref Attr): list of ref Attr | ||
{ | ||
if(l == nil) | ||
return v :: nil; | ||
return hd l :: tack(tl l, v); | ||
} | ||
|
||
use(s: string, c: int): string | ||
{ | ||
if(s == nil) | ||
err(sys->sprint("missing value for -%c", c)); | ||
return s; | ||
} | ||
|
||
nomod(m: string) | ||
{ | ||
err(sys->sprint("can't load %s: %r\n", m)); | ||
} | ||
|
||
err(s: string) | ||
{ | ||
sys->fprint(stderr(), "plumb: %s\n", s); | ||
raise "fail:error"; | ||
} | ||
|
||
stderr(): ref Sys->FD | ||
{ | ||
return sys->fildes(2); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# these are in order from most specific to least, | ||
# since first rule that fires wins. | ||
# /n/local/usr/local/plan9/plumb/basic | ||
# to update: cat $home/lib/plumbing > /chan/plumb.rules | ||
# to read: cat /chan/plumb.rules | ||
|
||
# ofimatic files go to os ooffice2 | ||
kind is text | ||
data matches '[a-zA-Z0-9_\-./]+' | ||
data matches '([a-zA-Z0-9_\-./]+)\.(ppt|doc|xls|odt)' | ||
data isfile $0 | ||
plumb alwaysstart pdf | ||
plumb start /dis/os.dis ooffice2 /mnt/usb/inferno/$file | ||
|
||
# PDF files go to os xpdf | ||
kind is text | ||
data matches '[a-zA-Z0-9_\-./]+' | ||
data matches '([a-zA-Z0-9_\-./]+)\.(pdf|PDF)' | ||
data isfile $0 | ||
plumb alwaysstart pdf | ||
plumb start /dis/os.dis xpdf /mnt/usb/inferno/$file | ||
|
||
# PS files go to os gv | ||
kind is text | ||
data matches '[a-zA-Z0-9_\-./]+' | ||
data matches '([a-zA-Z0-9_\-./]+)\.ps(\.gz)?' | ||
data isfile $0 | ||
plumb alwaysstart ps | ||
plumb start /dis/os.dis gv /mnt/usb/inferno/$file | ||
|
||
# OPF files go to ebook | ||
kind is text | ||
data matches '[a-zA-Z0-9_\-./]+' | ||
data matches '([a-zA-Z0-9_\-./]+)\.opf?' | ||
data isfile $0 | ||
plumb alwaysstart opf | ||
plumb start /dis/ebook/ebook.dis $file | ||
|
||
# image files go to wm/view | ||
kind is text | ||
data matches '[a-zA-Z0-9_\-./]+' | ||
data matches '([a-zA-Z0-9_\-./]+)\.(jpg|jpeg|gif|bit|png)' | ||
data isfile $0 | ||
plumb to view | ||
plumb start /dis/wm/view.dis -i $file | ||
|
||
# sounds go to auplay | ||
kind is text | ||
data matches '[a-zA-Z0-9_\-./]+' | ||
data matches '([a-zA-Z0-9_\-./]+)\.(iaf|wav)' | ||
data isfile $0 | ||
plumb alwaysstart auplay | ||
plumb start /dis/auplay.dis $file | ||
|
||
# URLs go to wm/charon | ||
kind is text | ||
data matches '(https?|ftp|file|gopher|mailto|news|nntp|telnet|wais|prospero)://[a-zA-Z0-9_@]+([.:][a-zA-Z0-9_@]+)*/?[a-zA-Z0-9_?#~&/\-]+([:.][a-zA-Z0-9_?#~&/\-]+)*' | ||
plumb to web | ||
plumb start /dis/charon.dis $0 | ||
|
||
# file URLs go to wm/charon | ||
kind is text | ||
data matches '[a-zA-Z0-9_/\-]+\.(html|htm|php)?' | ||
data isfile $0 | ||
data set file://localhost$file | ||
plumb to web | ||
plumb start /dis/charon.dis $data | ||
|
||
# .m files are looked up in /module and passed to wm/brutus | ||
kind is text | ||
data matches '([a-zA-Z0-9]+\.m)(:[0-9]+)?' | ||
data isfile /module/$1 | ||
data set /module/$0 | ||
plumb to edit | ||
plumb start /dis/wm/brutus.dis $file:$2 | ||
|
||
# existing files, possibly tagged by line number, go to wm/brutus | ||
# | ||
kind is text | ||
data matches '([.a-zA-Z0-9_/\-]+[a-zA-Z0-9_/\-])(:([0-9]+|/[.a-zA-Z0-9_\-]+))?' | ||
data isfile $1 | ||
data set $file | ||
attr add addr=$3 | ||
plumb to edit | ||
plumb start /dis/wm/brutus.dis $file:$3 | ||
|
||
# existing files go to brutus | ||
#kind is text | ||
#data matches '[a-zA-Z0-9_./\-]+' | ||
#data isdir $0 | ||
#plumb alwaysstart dir # nasty plumbing hack | ||
#plumb start /dis/wm/dir.dis $dir | ||
|
||
# man pages | ||
kind is text | ||
data matches '([a-zA-Z0-9\-]+)\(([0-9]+)\)' | ||
plumb alwaysstart man # nasty plumbing hack | ||
plumb start /dis/sh.dis -c '/usr/salva/dis/man -b $2 $1' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<H1>NAME</H1> | ||
lab65 - Man pages in Acme | ||
|
||
<h1>NOTES</h1> | ||
This lab's purpose is to have man-pages opened in acme automatically. | ||
Easiest way to do this is to allow plumb to get it's data piped | ||
from another program. | ||
So we can do: | ||
<pre> | ||
man2txt /man/sec/file | plumb -i -d edit -a action showdata -a filename '/man/file(sec)'; | ||
</pre> | ||
given that we want to plumb it to acme we have to set the destination port -d edit, | ||
and instruct acme to show the data with the tag set to the value of the filename argument. | ||
|
||
<p> | ||
So now we can add to our plumbing rules something like: | ||
<pre> | ||
# man pages | ||
kind is text | ||
data matches '([a-zA-Z0-9\-]+)\(([0-9]+)\)' | ||
plumb alwaysstart man # nasty plumbing hack | ||
plumb start /dis/sh.dis -c '/usr/salva/dis/man -b $2 $1' | ||
</pre> | ||
|
||
where /usr/salva/dis/man is an adaptation of /rc/bin/man from Plan9, | ||
and in particular when invoked with the -b option does: | ||
<pre> | ||
man2txt $file | | ||
plumb -i -d edit -a action showdata -a filename '/man/'^${index 2 $*}^'('^${index 1 $*}^')' | ||
</pre> | ||
|
||
<p> | ||
But if we now start to try running it as a substitue to te default rule for opening man pages, | ||
sooner or later we will find it crashes with the following error, | ||
<pre> | ||
'Acme: can't read /chan/plumb.edit: buffer too short', | ||
</pre> | ||
that advice is generated from <b>/appl/acme/acme.b:/plumbproc()</b>. | ||
If we dig in the Msg.recv() code we will find that the data received from a channel | ||
is limited by maxdata, which is set when initializing the module plumbmsg.m, | ||
and gets it's value Dat->PLUMBSIZE in <b>/appl/acme/acme.b:/init(.*)</b>, | ||
which is by default 1024, thus sending a file bigger that 1024 bytes will crash the | ||
plumbproc process. | ||
To sort out this we can determine the biggest data that we will send to the plumber, | ||
in particular issuing a: | ||
<pre> | ||
du /man/*/* | sort -n | uniq | tail -n 1 | ||
</pre> | ||
will return us the size of the biggest man page that we can reach, it turns out to be 58Kb, so | ||
we set PLUMBSIZE: con 65536, with the following ed script: | ||
<pre> | ||
% ed /appl/acme/dat.m | ||
5192 | ||
/PLUMBSIZE : con 1024/ s/1024/65536 | ||
PLUMBSIZE : con 65536; | ||
w | ||
5193 | ||
q | ||
</pre> | ||
|
||
<p> | ||
Now we <b>cd /appl/acme</b> and issue a | ||
<pre> | ||
% mk && mk install | ||
</pre> | ||
and we're done. | ||
|
||
<p> | ||
And last, we can addapt | ||
<a href="http://plan9.cs.bell-labs.com/sources/plan9/rc/bin/wurl2txt">wurl2txt</a> and | ||
<a href="http://plan9.cs.bell-labs.com/sources/plan9/rc/bin/wdoc2txt">wdoc2txt</a> and | ||
add a pair of rules to our <b>$home/lib/plumbing</b> to have url's and .docs opened | ||
inside acme. | ||
You can make and script to emulate hget using | ||
<pre> | ||
webgrab -r -o - ur | ||
</pre> | ||
|
||
<h1>FILES</h1> | ||
plumb.b man lookman sig hget plumbing | ||
|
||
--gualteri |
Oops, something went wrong.