diff options
Diffstat (limited to 'appl/cmd/fs/size.b')
| -rw-r--r-- | appl/cmd/fs/size.b | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/appl/cmd/fs/size.b b/appl/cmd/fs/size.b new file mode 100644 index 00000000..d72edd99 --- /dev/null +++ b/appl/cmd/fs/size.b @@ -0,0 +1,54 @@ +implement Fsmodule; +include "sys.m"; + sys: Sys; +include "draw.m"; +include "sh.m"; +include "fslib.m"; + fslib: Fslib; + Report, Value, type2s, quit: import fslib; + Fschan, Fsdata, Entrychan, Entry, + Gatechan, Gatequery, Nilentry, Option, + Next, Down, Skip, Quit: import Fslib; + +types(): string +{ + return "vt"; +} + +badmod(p: string) +{ + sys->fprint(sys->fildes(2), "fs: size: cannot load %s: %r\n", p); + raise "fail:bad module"; +} + +init() +{ + sys = load Sys Sys->PATH; + fslib = load Fslib Fslib->PATH; + if(fslib == nil) + badmod(Fslib->PATH); +} + +run(nil: ref Draw->Context, report: ref Report, + nil: list of Option, args: list of ref Value): ref Value +{ + sync := chan of int; + spawn sizeproc(sync, (hd args).t().i, report.start("size")); + return ref Value.V(sync); +} + +sizeproc(sync: chan of int, c: Entrychan, errorc: chan of string) +{ + if(<-sync == 0){ + c.sync <-= 0; + quit(errorc); + exit; + } + c.sync <-= 1; + + size := big 0; + while(((d, nil, nil) := <-c.c).t0 != nil) + size += d.length; + sys->print("%bd\n", size); + quit(errorc); +} |
