From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] Printenv(1)
Date: Tue, 11 May 2004 20:16:15 +0100 [thread overview]
Message-ID: <00a67f17cdf69b4a75e59ac4de51f03b@vitanuova.com> (raw)
In-Reply-To: <ee9e417a0405111206706289b0@mail.gmail.com>
> It'd be even better if it printed the ( and )
> so that the output was valid rc syntax.
no sooner said than done!
#include <u.h>
#include <libc.h>
void
printenv(char *name, int len)
{
int r, f, z;
char *ans, *t, *ep, *p;
char *ename;
ename = smprint("#e/%s", name);
f = open(ename, OREAD);
if(f < 0)
return;
ans = malloc(len+1);
if(ans){
r = read(f, ans, len);
print("%q=(", name);
if(r >= 0){
ep = ans + r;
t = ans;
z = 0;
for(p = ans; p < ep; p++){
if(*p == '\0'){
print("%q ", t);
t = p+1;
z = 1;
}
}
if(z == 0){
*p = '\0';
print("%q", ans);
}
print(")\n");
}
}
close(f);
free(ans);
}
void
main(int, char **)
{
int fd, i;
long nd;
Dir *buf;
fd = open("#e", OREAD);
nd = dirreadall(fd, &buf);
quotefmtinstall();
for(i = 0; i < nd; i++)
printenv(buf[i].name, buf[i].length);
}
next prev parent reply other threads:[~2004-05-11 19:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <ee9e417a040508081457f3fe12@mail.gmail.com>
2004-05-11 18:41 ` rog
2004-05-11 19:06 ` Russ Cox
2004-05-11 19:16 ` rog [this message]
2004-05-12 5:18 ` lucio
2004-05-08 8:38 lucio
2004-05-08 11:32 ` Richard Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=00a67f17cdf69b4a75e59ac4de51f03b@vitanuova.com \
--to=rog@vitanuova.com \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).