summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--appl/cmd/src.b76
-rw-r--r--dis/src.disbin233 -> 1087 bytes
3 files changed, 74 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index 9323d2a3..4802dad6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,7 @@
20070901
add andrey's changes to emu/MacOSX/win.c (used by emu/MacOSX/mkfile-a)
- add saoret's changes to dis/lookman, dis/man
+ add saoret's changes to dis/lookman, dis/man (issue 58)
+ add micah.stetson's change to /appl/cmd/src.b (issue 57)
20070817
two old changes that weren't in the distribution...
libkeyring/rsaalg.c: previously failed to ensure the output key was the right length (really rsagen should do that)
diff --git a/appl/cmd/src.b b/appl/cmd/src.b
index 70c9da65..2b44b753 100644
--- a/appl/cmd/src.b
+++ b/appl/cmd/src.b
@@ -19,10 +19,78 @@ init(nil: ref Draw->Context, argv: list of string)
if(dis != nil){
dis->init();
for(argv = tl argv; argv != nil; argv = tl argv){
- src := dis->src(hd argv);
- if(src == nil)
- src = "?";
- sys->print("%s: %s\n", hd argv, src);
+ s := src(hd argv);
+ if(s == nil)
+ s = "?";
+ sys->print("%s: %s\n", hd argv, s);
}
}
}
+
+src(progname: string): string
+{
+ disfile := 0;
+ if (len progname >= 4 && progname[len progname-4:] == ".dis")
+ disfile = 1;
+ pathlist: list of string;
+ if (absolute(progname))
+ pathlist = list of {""};
+ else
+ pathlist = list of {"/dis", "."};
+
+ err := "";
+ do {
+ path: string;
+ if (hd pathlist != "")
+ path = hd pathlist + "/" + progname;
+ else
+ path = progname;
+
+ npath := path;
+ if (!disfile)
+ npath += ".dis";
+ src := dis->src(npath);
+ if(src != nil)
+ return src;
+ err = sys->sprint("%r");
+ if (nonexistent(err)) {
+ # try and find it as a shell script
+ if (!disfile) {
+ (ok, info) := sys->stat(path);
+ if (ok == 0 && (info.mode & Sys->DMDIR) == 0
+ && (info.mode & 8r111) != 0)
+ return path;
+ else
+ err = sys->sprint("%r");
+ }
+ }
+ pathlist = tl pathlist;
+ } while (pathlist != nil && nonexistent(err));
+ return nil;
+}
+
+absolute(p: string): int
+{
+ if (len p < 2)
+ return 0;
+ if (p[0] == '/' || p[0] == '#')
+ return 1;
+ if (len p < 3 || p[0] != '.')
+ return 0;
+ if (p[1] == '/')
+ return 1;
+ if (p[1] == '.' && p[2] == '/')
+ return 1;
+ return 0;
+}
+
+nonexistent(e: string): int
+{
+ errs := array[] of {"does not exist", "directory entry not found"};
+ for (i := 0; i < len errs; i++){
+ j := len errs[i];
+ if (j <= len e && e[len e-j:] == errs[i])
+ return 1;
+ }
+ return 0;
+}
diff --git a/dis/src.dis b/dis/src.dis
index de07c158..1f645fd4 100644
--- a/dis/src.dis
+++ b/dis/src.dis
Binary files differ