From mboxrd@z Thu Jan 1 00:00:00 1970 Message-Id: <200302271630.h1RGUaM21552@augusta.math.psu.edu> To: 9fans@cse.psu.edu Cc: 9trouble@cse.psu.edu From: Dan Cross Subject: [9fans] /sys/lib/libauth/newns.c patch to add `.' command, handle quoting. Date: Thu, 27 Feb 2003 11:30:36 -0500 Topicbox-Message-UUID: 74e82ef0-eacb-11e9-9e20-41e7f4b1d025 A while back I mentioned that I had modified newns.c to add a ``.'' command to source namespace commands from other files. I also changed splitargs() within newns.c to call tokenize instead of doing it's own tokenization; this allows it to correctly deal with quoted tokens (like #rune, as returned by ns). I think these changes are handy enough to share; I'm using them all over the place now. In particular, I added the following to the end of my /lib/namespace: . /lib/local.namespace This allows me to easily make custom changes to my namespace without a maintenance hassle; usually, one wants to add something, not take it away, from a common core. This makes doing that pretty trivial, as I can just add local customizations to /lib/local.namespace and have them apply to all hosts on my network (note: the name is local.namespace instead of namespace.local to avoid clashes if you added a host named, ``local'' to your network; newns() still looks for /lib/namespace.$sysname, and uses that to override /lib/namespace if it exists). Note that at the end of /lib/local.namespace, I have: . /lib/$sysname.namespace To pick up system dependent namespace changes. This is preferable to /lib/namespace.$sysname since it allows me to add a delta to my common namespace, instead of overriding it completely. It'd be nice to see this stuff go onto sources. - Dan C. All diffs are in diff -e format. The diff for /lib/namespace is trivial: term% diff -e /n/sources/plan9/lib/namespace /lib/namespace 28a # site dependent . /lib/local.namespace . term% And the changes to newns.c are: 241a if(q && q < arg) arg = q; q = utfrune(p, L'.'); . 213c if (n == (maxargsplus1 - 1)) return 0; return n; . 210c if (!argbuf) . 197,208c n = tokenize(p, argv, maxargsplus1); for (i = 0; i < n; i++) { q = argv[i]; argv[i] = argbuf; . 195c int i, n; . 192c splitargs(char *p, char *argv[], char *argbuf, int maxargsplus1) . 136c if(strcmp(argv0, ".") == 0 && argc == 1){ Biobuf *spec; spec = Bopen(argv[0], OREAD); if(spec == nil){ werrstr("can't open %s: %r", argv[0]); return; } nsfile(spec, rpc); Bterm(spec); }else if(strcmp(argv0, "bind") == 0 && argc == 2) . 74,79d 69c argc = splitargs(cmd, argv, argbuf, NARG + 1); . 61a nsfile(spec, rpc); Bterm(spec); if(rpc){ close(rpc->afd); auth_freerpc(rpc); } return 0; } static void nsfile(Biobuf *spec, AuthRpc *rpc) { int argc; char *cmd, *argv[NARG + 1], argbuf[MAXARG*NARG]; . 27d 25d 16a static void nsfile(Biobuf *, AuthRpc *); .