diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /appl/cmd/getfile.b | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'appl/cmd/getfile.b')
| -rw-r--r-- | appl/cmd/getfile.b | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/appl/cmd/getfile.b b/appl/cmd/getfile.b new file mode 100644 index 00000000..ec0ff34c --- /dev/null +++ b/appl/cmd/getfile.b @@ -0,0 +1,74 @@ +implement Getfile; + +include "sys.m"; + sys: Sys; + stderr: ref Sys->FD; +include "draw.m"; + draw: Draw; + Rect: import draw; +include "tk.m"; + tk: Tk; +include "wmlib.m"; + wmlib: Wmlib; +include "arg.m"; + +Getfile: module +{ + init: fn(ctxt: ref Draw->Context, argv: list of string); +}; + +usage() +{ + sys->fprint(stderr, "usage: getfile [-g geom] [-d startdir] [pattern...]\n"); + raise "fail:usage"; +} + +init(ctxt: ref Draw->Context, argv: list of string) +{ + sys = load Sys Sys->PATH; + stderr = sys->fildes(2); + draw = load Draw Draw->PATH; + tk = load Tk Tk->PATH; + wmlib = load Wmlib Wmlib->PATH; + if (wmlib == nil) { + sys->fprint(stderr, "getfile: cannot load %s: %r\n", Wmlib->PATH); + raise "fail:bad module"; + } + arg := load Arg Arg->PATH; + if (arg == nil) { + sys->fprint(stderr, "getfile: cannot load %s: %r\n", Arg->PATH); + raise "fail:bad module"; + } + + if (ctxt == nil) { + sys->fprint(stderr, "getfile: no window context\n"); + raise "fail:bad context"; + } + + wmlib->init(); + + startdir := "."; + geom := "-x " + string (ctxt.screen.image.r.dx() / 5) + + " -y " + string (ctxt.screen.image.r.dy() / 5); + title := "Select a file"; + arg->init(argv); + while (opt := arg->opt()) { + case opt { + 'g' => + geom = arg->arg(); + 'd' => + startdir = arg->arg(); + 't' => + title = arg->arg(); + * => + sys->fprint(stderr, "getfile: unknown option -%c\n", opt); + usage(); + } + } + if (geom == nil || startdir == nil || title == nil) + usage(); + top := tk->toplevel(ctxt.screen, geom); + argv = arg->argv(); + arg = nil; + sys->print("%s\n", wmlib->filename(ctxt.screen, top, title, argv, startdir)); +} |
