annotate toys/env.c @ 562:4d802d438983

Match uint64_t with PRIu64 to avoid warnings on 64 bit builds.
author Rob Landley <rob@landley.net>
date Sat, 14 Apr 2012 21:27:00 -0500
parents 45c10e86be43
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
510
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
2 *
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
3 * env.c - Set the environment for command invocation.
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
4 *
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
5 * Copyright 2012 Tryn Mirell <tryn@mirell.org>
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
6 * env.c
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
7
409
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
8 USE_ENV(NEWTOY(env, "^i", TOYFLAG_USR|TOYFLAG_BIN))
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
9
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
10 config ENV
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
11 bool "env"
420
eda61bcf575a Basename and env are usable, default them to y.
Rob Landley <rob@landley.net>
parents: 409
diff changeset
12 default y
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
13 help
510
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
14 usage: env [-i] [NAME=VALUE...] [command [option...]]
409
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
15
510
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
16 Set the environment for command invocation.
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
17
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
18 -i Clear existing environment.
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
19 */
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
20
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
21 #include "toys.h"
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
22
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
23 extern char **environ;
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
24
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
25 void env_main(void)
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
26 {
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
27 char **ev;
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
28 char **command = NULL;
409
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
29 char *del = "=";
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
30
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
31 if (toys.optflags & 1) clearenv();
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
32
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
33 for (ev = toys.optargs; *ev != NULL; ev++) {
409
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
34 char *env, *val = NULL;
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
35
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
36 env = strtok(*ev, del);
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
37
409
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
38 if (env) val = strtok(NULL, del);
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
39
409
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
40 if (val) setenv(env, val, 1);
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
41 else {
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
42 command = ev;
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
43 break;
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
44 }
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
45 }
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
46
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
47 if (!command) {
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
48 char **ep;
510
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
49 for (ep = environ; *ep; ep++) xputs(*ep);
409
55598a9b8f21 'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents: 406
diff changeset
50 return;
510
45c10e86be43 Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents: 420
diff changeset
51 } else xexec(command);
406
c8a3d740c229 'env' implementation - Initial
Tryn Mirell <tryn@mirell.org>
parents:
diff changeset
52 }