Mercurial > hg > toybox
annotate toys/other/printenv.c @ 1539:3e85af1f7e22 draft
First batch of sed tests.
Only good for TEST_HOST=1 at the moment because the test infrastructure itself
depends on sed, so if an unfinished sed is in the $PATH it goes boing. But
hey, corner cases!
I have... more.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 29 Oct 2014 18:44:33 -0500 |
parents | 786841fdb1e0 |
children |
rev | line source |
---|---|
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
1 /* printenv.c - Print environment variables. |
517
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
2 * |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
3 * Copyright 2012 Georgi Chorbadzhiyski <georgi@unixsol.org> |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
4 |
518
e0eed40f4ab1
Add longopt, refactor so only one instance of each loop, requre = as part of match, update exit code.
Rob Landley <rob@landley.net>
parents:
517
diff
changeset
|
5 USE_PRINTENV(NEWTOY(printenv, "0(null)", TOYFLAG_USR|TOYFLAG_BIN)) |
517
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
6 |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
7 config PRINTENV |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
8 bool "printenv" |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
9 default y |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
10 help |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
11 usage: printenv [-0] [env_var...] |
517
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
12 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
13 Print environment variables. |
518
e0eed40f4ab1
Add longopt, refactor so only one instance of each loop, requre = as part of match, update exit code.
Rob Landley <rob@landley.net>
parents:
517
diff
changeset
|
14 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
15 -0 Use \0 as delimiter instead of \n |
517
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
16 */ |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
17 |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
18 #include "toys.h" |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
19 |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
20 extern char **environ; |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
21 |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
22 void printenv_main(void) |
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
23 { |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
24 char **env, **var = toys.optargs; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
25 char delim = '\n'; |
517
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
26 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
27 if (toys.optflags) delim = 0; |
518
e0eed40f4ab1
Add longopt, refactor so only one instance of each loop, requre = as part of match, update exit code.
Rob Landley <rob@landley.net>
parents:
517
diff
changeset
|
28 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
29 do { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
30 int catch = 0, len = *var ? strlen(*var) : 0; |
517
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
31 |
694
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
32 for (env = environ; *env; env++) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
33 char *out = *env; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
34 if (*var) { |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
35 if (!strncmp(out, *var, len) && out[len] == '=') out += len +1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
36 else continue; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
37 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
38 xprintf("%s%c", out, delim); |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
39 catch++; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
40 } |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
41 if (*var && !catch) toys.exitval = 1; |
786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents:
656
diff
changeset
|
42 } while (*var && *(++var)); |
517
a191ea9bc5df
Implement printenv command.
Georgi Chorbadzhiyski <georgi@unixsol.org>
parents:
diff
changeset
|
43 } |