2 * Copyright (C) 2013 Intel Corporation.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * José Bollo <jose.bollo@open.eurogiciel.org>
20 * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
21 * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
29 #include <tzplatform_config.h>
31 #define basename(x) (x)
33 static const char usage [] = "type '%s --help' to get help.\n";
35 static const char help [] = "\
37 usage: %s [options...] [keys...]\n\
41 -a --all all keys (must not be followed by keys)\n\
42 -n --not not in the keys\n\
43 -e --export prefix with export\n\
44 -l --list prints only the key names, not the values\n\
45 -s --space separate with spaces instead of new-lines\n\
46 -q --query silently check that given variables are existing\n\
47 -c --continue continue to process if error\n\
51 int main(int argc, char **argv)
53 char *progname = *argv++;
54 int all = 0, not = 0, query = 0, export = 0, space = 0, list = 0, cont = 0;
56 enum tzplatform_variable id;
59 while(*argv && **argv=='-') {
60 char c, *opt = 1+*argv++;
66 case 'a': x = "all"; break;
67 case 'n': x = "not"; break;
68 case 'q': x = "query"; break;
69 case 'e': x = "export"; break;
70 case 's': x = "space"; break;
71 case 'l': x = "list"; break;
72 case 'c': x = "continue"; break;
73 case 'h': x = "help"; break;
75 if (!x || strcmp(x,opt))
85 case 'a': all = 1; break;
86 case 'n': not = 1; break;
87 case 'q': query = 1; break;
88 case 'e': export = 1; break;
89 case 's': space = 1; break;
90 case 'l': list = 1; break;
91 case 'c': cont = 1; break;
93 fprintf( stdout, help, basename(progname));
96 fprintf( stderr, usage, basename(progname));
106 "error! --all and --query aren't compatibles.\n");
111 "error! --not and --query aren't compatibles.\n");
116 "error! --list and --query aren't compatibles.\n");
121 "error! --continue and --query aren't compatibles.\n");
126 "warning! --space option ignored for queries.\n");
130 "warning! --export option ignored for queries.\n");
136 "error! --all doesn't accept any key.\n");
139 /* all is like not nothing!! */
144 n = tzplatform_getcount();
145 sel = calloc( sizeof(int), n);
147 fprintf( stderr, "error! out of memory!\n");
151 /* get the variables from the list */
153 id = tzplatform_getid( *argv);
154 if (id == _TZPLATFORM_VARIABLES_INVALID_) {
157 fprintf( stderr, "error! %s isn't a variable.\n", *argv);
167 /* finished for queries */
171 /* emits the result */
172 for (p = i = 0 ; i < n ; i++) {
175 printf( space ? " " : export ? "\nexport " : "\n");
178 id = (enum tzplatform_variable) i;
179 printf( "%s", tzplatform_getname(id));
181 printf( "=%s", tzplatform_getenv(id));