* [9fans] Printenv(1)
@ 2004-05-08 8:38 lucio
2004-05-08 11:32 ` Richard Miller
0 siblings, 1 reply; 6+ messages in thread
From: lucio @ 2004-05-08 8:38 UTC (permalink / raw)
To: 9fans
[-- Attachment #1: Type: text/plain, Size: 292 bytes --]
This makes it possible for me to test (and fix) ENV handling in Tcl.
Others may find it useful, I'm sure I should not have reinvented the
wheel, but it was quicker than looking up the wheel patent application
:-)
Add features to taste, I didn't even consult the Unix man pages.
++L
[-- Attachment #2: printenv.c --]
[-- Type: text/plain, Size: 310 bytes --]
#include <u.h>
#include <libc.h>
main (int argc, char **argv) {
int fd, x;
long nd;
Dir *buf;
USED(argc);
USED(argv);
fd = open ("#e", OREAD);
nd = dirreadall (fd, &buf);
for (x = 0; x < nd; x++) {
print ("%s=%s\n", buf[x].name, getenv (buf[x].name));
}
exits (0);
return 0;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] Printenv(1)
2004-05-08 8:38 [9fans] Printenv(1) lucio
@ 2004-05-08 11:32 ` Richard Miller
0 siblings, 0 replies; 6+ messages in thread
From: Richard Miller @ 2004-05-08 11:32 UTC (permalink / raw)
To: 9fans
> Others may find it useful, I'm sure I should not have reinvented the
> wheel, ...
For a lazier way to get a similar result, try grep '^' /env/*
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] Printenv(1)
2004-05-11 19:06 ` Russ Cox
2004-05-11 19:16 ` rog
@ 2004-05-12 5:18 ` lucio
1 sibling, 0 replies; 6+ messages in thread
From: lucio @ 2004-05-12 5:18 UTC (permalink / raw)
To: 9fans
> It'd be even better if it printed the ( and )
> so that the output was valid rc syntax.
Hey, wait a minute! I was looking for a POSIX operation!
I was assuming that Plan 9 did not need such a thing, otherwise Bell
Labs would have provided one.
Really, now!
++L
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] Printenv(1)
2004-05-11 19:06 ` Russ Cox
@ 2004-05-11 19:16 ` rog
2004-05-12 5:18 ` lucio
1 sibling, 0 replies; 6+ messages in thread
From: rog @ 2004-05-11 19:16 UTC (permalink / raw)
To: 9fans
> 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);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] Printenv(1)
2004-05-11 18:41 ` rog
@ 2004-05-11 19:06 ` Russ Cox
2004-05-11 19:16 ` rog
2004-05-12 5:18 ` lucio
0 siblings, 2 replies; 6+ messages in thread
From: Russ Cox @ 2004-05-11 19:06 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
It'd be even better if it printed the ( and )
so that the output was valid rc syntax.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [9fans] Printenv(1)
[not found] <ee9e417a040508081457f3fe12@mail.gmail.com>
@ 2004-05-11 18:41 ` rog
2004-05-11 19:06 ` Russ Cox
0 siblings, 1 reply; 6+ messages in thread
From: rog @ 2004-05-11 18:41 UTC (permalink / raw)
To: 9fans
> For something that handles lists properly,
>
> cd /env
> whatis * | grep '='
pity about the "not found" messages, problems with variables
containing newlines and other exceptions...
for more-than-casual use, i think a C tool would probably
be better, maybe something like this:
#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);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-05-12 5:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-08 8:38 [9fans] Printenv(1) lucio
2004-05-08 11:32 ` Richard Miller
[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
2004-05-12 5:18 ` lucio
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).