From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <00a67f17cdf69b4a75e59ac4de51f03b@vitanuova.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] Printenv(1) Date: Tue, 11 May 2004 20:16:15 +0100 From: rog@vitanuova.com In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Topicbox-Message-UUID: 776fa94e-eacd-11e9-9e20-41e7f4b1d025 > It'd be even better if it printed the ( and ) > so that the output was valid rc syntax. no sooner said than done! #include #include 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); }