From mboxrd@z Thu Jan 1 00:00:00 1970
To: 9fans@cse.psu.edu
From: rog@vitanuova.com
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="upas-hnxfwcenidmmrngmnzxcwskqqk"
Message-Id: <20010808103450.57264199E3@mail.cse.psu.edu>
Subject: [9fans] ls -R
Date: Wed, 8 Aug 2001 11:45:13 +0100
Topicbox-Message-UUID: da2d6f16-eac9-11e9-9e20-41e7f4b1d025
This is a multi-part message in MIME format.
--upas-hnxfwcenidmmrngmnzxcwskqqk
Content-Disposition: inline
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
sorry, boyd's response wasn't enormously helpful.
as far as i know the only plan 9 utility around that traverses the
file tree is du(1).
personally, i have a little rc script in my bin called find
(attached), which does almost all of what i used to use find for under
unix, i.e. find files with a particular name.
e.g.
find . '\.c$'
to find all c source files.
i've also got a little version of xargs (also attached) that reads
filenames from stdin and occasionally executes a command with those as
arguments, which is useful when grepping in hierarchies where the list
of files will be larger than execv will tolerate (plus you start
getting results sooner). luckily newlines are illegal in plan 9 names
AFAIK so it's not vulnerable to the same problems as the unix xargs.
so ls -lR becomes:
find . . | xargs ls -l
cheers,
rog.
--upas-hnxfwcenidmmrngmnzxcwskqqk
Content-Disposition: attachment; filename=find
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
#!/bin/rc
if (~ $#* 1 0) {
echo 'usage: find
... ' >[1=2]
exit usage
}
a=()
while (! ~ $#* 1) {
a=($a $1)
shift
}
du -a $a | sed 's/^[^ ]*[ ]//' | grep $1
--upas-hnxfwcenidmmrngmnzxcwskqqk
Content-Disposition: attachment; filename=xargs.c
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
#include
#include
#include
char *makeline(void);
#define NUMARGS 470
#define MAXSIZE 5000
void run(char **cmd);
Biobuf stdin;
int main(int argc, char **argv)
{
char **cmd;
int i, n, m, size;
if (argc < 2) {
fprint(2, "Usage: xargs [cmd args...]\n");
exits("bad usage");
}
if (Binit(&stdin, 0, OREAD) == -1) {
fprint(2, "couldn't init stdin\n");
exits("error");
}
cmd = malloc((argc - 1 + NUMARGS + 1) * sizeof(char *));
n = 0;
for (i = 1; i < argc; i++) {
cmd[n++] = argv[i];
}
for (;;) {
int eof = 0;;
size = 0;
for (m = 0; m < NUMARGS && size < MAXSIZE; m++) {
if ((cmd[n + m] = makeline()) == 0) {
eof = 1;
break;
}
size += strlen(cmd[n + m]);
}
cmd[n + m] = 0;
if (m > 0)
run(cmd);
for (i = 0; i < m; i++) {
free(cmd[n+i]);
}
if (eof)
break;
}
return 0;
}
int pwait(void)
{
Waitmsg msg;
if (wait(&msg) == -1)
return -1;
return atoi(msg.pid);
}
void run(char **cmd)
{
char buf[256];
int npid, pid = fork();
if (pid == -1) {
perror("couldn't fork");
exits("no forkage");
}
if (pid == 0) {
if (cmd[0][0] != '/' && strncmp(cmd[0], "./", 2)) {
sprint(buf, "/bin/%s", cmd[0]);
exec(buf, cmd);
} else {
exec(cmd[0], cmd);
}
perror(cmd[0]);
exits("no exec");
}
while ((npid = pwait()) != pid && npid != -1)
;
}
char *makeline(void)
{
char *ln, *ret;
int len;
if ((ln = Brdline(&stdin, '\n')) == 0) {
return 0;
}
len = Blinelen(&stdin);
ret = malloc(len + 1);
memcpy(ret, ln, len);
ret[len-1] = '\0';
return ret;
}
--upas-hnxfwcenidmmrngmnzxcwskqqk--