diff options
| author | Charles.Forsyth <devnull@localhost> | 2007-01-16 17:55:28 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2007-01-16 17:55:28 +0000 |
| commit | 56f3d04553e7fac260932ac4ac7fc826ee0b6b58 (patch) | |
| tree | 93c37736c71f968a985d2341e1566fa186da93dd | |
| parent | bdb6b18670ca169bd2557860231eb48a88f1461f (diff) | |
20070116 add /dis/lib/man.dis to repair wm/man
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | appl/lib/man.b | 136 | ||||
| -rw-r--r-- | appl/lib/mkfile | 1 | ||||
| -rw-r--r-- | dis/lib/man.dis | bin | 0 -> 1771 bytes | |||
| -rw-r--r-- | dis/wm/man.dis | bin | 14246 -> 14251 bytes | |||
| -rw-r--r-- | include/version.h | 2 | ||||
| -rw-r--r-- | lib/proto/inferno | 2 | ||||
| -rw-r--r-- | module/man.m | 2 |
8 files changed, 143 insertions, 2 deletions
@@ -1,3 +1,5 @@ +20070116 + move Man from /dis/man.dis (which vanished a few changes ago) to /dis/lib/man.dis. honestly. wm/man works again. 20070114 remove some unused static declarations in /utils/mk/shprint.c 20070111 diff --git a/appl/lib/man.b b/appl/lib/man.b new file mode 100644 index 00000000..bbd7e15e --- /dev/null +++ b/appl/lib/man.b @@ -0,0 +1,136 @@ +implement Man; + +include "sys.m"; + sys: Sys; +include "filepat.m"; +include "bufio.m"; +include "man.m"; + +MANPATH: con "/man/"; +PATHDEPTH: con 1; + +indices: list of (string, list of (string, string)); + +init() +{ + sys = load Sys Sys->PATH; +} + +loadsections(scanlist: list of string): string +{ + sys = load Sys Sys->PATH; + bufio := load Bufio Bufio->PATH; + Iobuf: import bufio; + + if (bufio == nil) + return sys->sprint("cannot load %s: %r", Bufio->PATH); + + indexpaths: list of string; + if (scanlist == nil) { + filepat := load Filepat Filepat->PATH; + if (filepat == nil) + return sys->sprint("cannot load %s: %r", Filepat->PATH); + + indexpaths = filepat->expand(MANPATH + "[0-9]*/INDEX"); + if (indexpaths == nil) + return sys->sprint("cannot find man pages"); + } else { + for (; scanlist != nil; scanlist = tl scanlist) + indexpaths = MANPATH + string hd scanlist + "/INDEX" :: indexpaths; + indexpaths = sortuniq(indexpaths); + } + + sections: list of string; + for (; indexpaths != nil; indexpaths = tl indexpaths) { + path := hd indexpaths; + (nil, toks) := sys->tokenize(path, "/"); + for (d := 0; d < PATHDEPTH; d++) + toks = tl toks; + sections = hd toks :: sections; + } + + for (sl := sections; sl != nil; sl = tl sl) { + section := hd sl; + path := MANPATH + string section + "/INDEX"; + iob := bufio->open(path, Sys->OREAD); + if (iob == nil) + continue; + pairs: list of (string, string) = nil; + + while((s := iob.gets('\n')) != nil) { + if (s[len s - 1] == '\n') + s = s[0:len s - 1]; + (n, toks) := sys->tokenize(s, " "); + if (n != 2) + continue; + pairs = (hd toks, hd tl toks) :: pairs; + } + iob.close(); + indices = (section, pairs) :: indices; + } + return nil; +} + +getfiles(sections: list of string, keys: list of string): list of (int, string, string) +{ + ixl: list of (string, list of (string, string)); + + if (sections == nil) + ixl = indices; + else { + for (; sections != nil; sections = tl sections) { + section := hd sections; + for (il := indices; il != nil; il = tl il) { + (s, mapl) := hd il; + if (s == section) { + ixl = (s, mapl) :: ixl; + break; + } + } + } + } + paths: list of (int, string, string); + for(keyl := keys; keyl != nil; keyl = tl keyl){ + for (; ixl != nil; ixl = tl ixl) { + for ((s, mapl) := hd ixl; mapl != nil; mapl = tl mapl) { + (kw, file) := hd mapl; + if (hd keyl == kw) { + p := MANPATH + s + "/" + file; + paths = (int s, kw, p) :: paths; + } + } + # allow files not in the index + if(paths == nil || (hd paths).t0 != int s || (hd paths).t1 != hd keyl){ + p := MANPATH + string s + "/" + hd keyl; + if(sys->stat(p).t0 != -1) + paths = (int s, hd keyl, p) :: paths; + } + } + } + return paths; +} + +sortuniq(strlist: list of string): list of string +{ + strs := array [len strlist] of string; + for (i := 0; strlist != nil; (i, strlist) = (i+1, tl strlist)) + strs[i] = hd strlist; + + # simple sort (greatest first) + for (i = 0; i < len strs - 1; i++) { + for (j := i+1; j < len strs; j++) + if (strs[i] < strs[j]) + (strs[i], strs[j]) = (strs[j], strs[i]); + } + + # construct list (result is ascending) + r: list of string; + prev := ""; + for (i = 0; i < len strs; i++) { + if (strs[i] != prev) { + r = strs[i] :: r; + prev = strs[i]; + } + } + return r; +} diff --git a/appl/lib/mkfile b/appl/lib/mkfile index 7ef57b48..8aea08c2 100644 --- a/appl/lib/mkfile +++ b/appl/lib/mkfile @@ -67,6 +67,7 @@ TARG=\ libc0.dis\ lock.dis\ login.dis\ + man.dis\ mpeg.dis\ nametree.dis\ names.dis\ diff --git a/dis/lib/man.dis b/dis/lib/man.dis Binary files differnew file mode 100644 index 00000000..0422aeb0 --- /dev/null +++ b/dis/lib/man.dis diff --git a/dis/wm/man.dis b/dis/wm/man.dis Binary files differindex b610d4ed..51955396 100644 --- a/dis/wm/man.dis +++ b/dis/wm/man.dis diff --git a/include/version.h b/include/version.h index 782f6bfd..46b96e1a 100644 --- a/include/version.h +++ b/include/version.h @@ -1 +1 @@ -#define VERSION "Fourth Edition (20070115)" +#define VERSION "Fourth Edition (20070116)" diff --git a/lib/proto/inferno b/lib/proto/inferno index 4eaf958c..0a6399a8 100644 --- a/lib/proto/inferno +++ b/lib/proto/inferno @@ -959,6 +959,7 @@ appl libc0.b lock.b login.b + man.b memfs.b mkfile mpeg.b @@ -1562,6 +1563,7 @@ dis libc0.dis lock.dis login.dis + man.dis mash + mashlib.dis diff --git a/module/man.m b/module/man.m index 3da6ad73..9d12fe88 100644 --- a/module/man.m +++ b/module/man.m @@ -34,7 +34,7 @@ Parseman: module { }; Man: module { - PATH: con "/dis/man.dis"; + PATH: con "/dis/lib/man.dis"; loadsections: fn(sections: list of string): string; getfiles: fn(sections: list of string , keys: list of string): list of (int, string, string); |
