[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: some dumb questions
- To: inferno@interstice.com
- Subject: Re: some dumb questions
- From: Eric Grosse <ehg@bell-labs.com>
> scrambling parts of ls.b, grep.b and du.b The way I mirror changes from the main Inferno source tree to various outlying development computers uses a similar tool, reproduced below. You can adapt it to your own needs or even add a "find" user interface, if that's what you want. My main point is that I personally find it clean enough to invoke programs from other programs that I don't resort as quickly to a shell script as I did in Unix. Best wishes, Eric ----------------------- # variant of "du -nt|grep" for excluding selected directories and files # Copyright (c) 1996 Bell Laboratories. All Rights Reserved. implement dux; include "sys.m"; sys: Sys; print, sprint: import sys; include "draw.m"; include "lib.m"; readdir: Readdir; include "regex.m"; regex: Regex; dux: module{ init: fn(nil: ref Draw->Context, arg: list of string); }; Error(mess: string){ sys->fprint(sys->fildes(2),"dux: %s: %r\n",mess); exit; } init(ctxt: ref Draw->Context, nil: list of string){ sys = load Sys Sys->PATH; readdir = load Readdir Readdir->PATH; regex = load Regex Regex->PATH; # get top-level directories and exclude a few xpat := "^(bin|chan|cmd|dev|ftp|keydb|net|nvfs|os|prog|usr|utils)$"; exclude := regex->compile(xpat); if(exclude==nil) Error(sprint("bad pattern for regex: %s",xpat)); (de, nde) := readdir->init(".",readdir->NAME); dirs: list of string; for(i:=nde-1; i>=0; i--){ s := de[i].name; (matchl,nil) := regex->execute(exclude,s); if(matchl==-1) dirs = s :: dirs; } # use /tmp, since Inferno pipes are being worked on. tmpname := "/tmp/dux"+string ((sys->millisec()/10)%99999); tmp := sys->create(tmpname,sys->OWRITE,8r664); if(tmp==nil) Error(sprint("can't create %s",tmpname)); waitfd := sys->open("#p/"+string sys->pctl(0, nil)+"/wait",sys->OREAD); spawn du(ctxt,dirs,tmp); sys->read(waitfd,array[1] of byte,1); xpat = tmpname+" |^services/webget/webget.log|"+ "^man/./|^man/ohtml|^licensedb/[0-9]|"+ "/(386|mips|sparc|arm)/bin/|/cache/|"+ "\\.(dis|sbl|obj|lib|exe|pdb|ilk|a[58kv]|[ao58kv]) |"+ "/([58kv].out|acid) |^appl/.*\\.s "; grep := load dux "/dis/grep.dis"; grep->init(ctxt,"grep"::"-v"::xpat::tmpname::nil); tmp = nil; if(sys->remove(tmpname)!=0) Error(sprint("can't rm %s",tmpname)); } du(ctxt:ref Draw->Context, dirs:list of string, tmp:ref sys->FD){ # the second arg of pctl recently changed to list of int. sys->pctl(sys->NEWFD,tmp.fd::2::nil); sys->dup(tmp.fd,1); du := load dux "/dis/du.dis"; du->init(ctxt,"du"::"-nt"::dirs); }
- Prev by Date: Re: Apple
- Next by Date: Re: Apple
- Prev by thread: Re: some dumb questions
- Next by thread: RE: some dumb questions
- Index(es):