1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
/* This file is part of Eclat.
Copyright (C) 2012-2015 Sergey Poznyakoff.
Eclat is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Eclat is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_GETOPT_H
# include <getopt.h>
#endif
static char *pp_cmd_buffer;
static size_t pp_cmd_bufsize;
static size_t pp_cmd_buflevel;
struct replvar {
union {
char **strptr;
int *intptr;
} r_pointer;
#define s_ptr r_pointer.strptr
#define i_ptr r_pointer.intptr
union {
char *strval;
int intval;
} r_value;
#define s_val r_value.strval
#define i_val r_value.intval
};
int
replace_string_var(void *p)
{
struct replvar *rv = p;
*rv->s_ptr = rv->s_val;
return 0;
}
int
replace_int_var(void *p)
{
struct replvar *rv = p;
*rv->i_ptr = rv->i_val;
return 0;
}
OPTIONS_BEGIN("eclat",
[<EC2 Command Line Administrator Tool>],
[<COMMAND [COMMAND-OPTIONS...]>],
[<gnu>],
[<nopermute>],
[<copyright_year=2012-2015>],
[<copyright_holder=Sergey Poznyakoff>],[<nopermute>])
GROUP(Selecting program mode)
OPTION(lint,t,,
[<parse configuration file and exit>])
BEGIN
lint_mode = 1;
END
OPTION(,E,,
[<preprocess config and exit>])
BEGIN
preprocess_only = 1;
END
OPTION(match-commands,m,,
[<find matching command names>])
BEGIN
match_command_mode = 1;
END
OPTION(list-commands,l,FMT,
[<list commands using the supplied format>])
BEGIN
listcmd(optarg);
exit(0);
END
GROUP(Modifiers)
OPTION(config-file,c,FILE,
[<use FILE instead of the default configuration>])
BEGIN
conffile = optarg;
END
OPTION(region,,NAME,
[<set AWS region (availability zone)>])
BEGIN
struct replvar *rv = grecs_malloc(sizeof(*rv));
rv->s_ptr = ®ion_name;
rv->s_val = optarg;
add_config_finish_hook(replace_string_var, rv);
END
OPTION(access-file,a,NAME,
[<set access file>])
BEGIN
struct replvar *rv = grecs_malloc(sizeof(*rv));
rv->s_ptr = &access_file_name;
rv->s_val = optarg;
add_config_finish_hook(replace_string_var, rv);
END
OPTION(access-key,O,[<STRING>],
[<set access key to use>])
BEGIN
access_key = optarg;
END
OPTION(secret-key,W,[<STRING>],
[<set secret key to use>])
BEGIN
secret_key = optarg;
END
OPTION(ssl,,,
[<use SSL (HTTPS) connection>])
BEGIN
struct replvar *rv = grecs_malloc(sizeof(*rv));
rv->i_ptr = &use_ssl;
rv->i_val = 1;
add_config_finish_hook(replace_int_var, rv);
END
OPTION(format,H,NAME,
[<use format NAME for output>])
BEGIN
format_name_option = optarg;
END
OPTION(format-expression,e,EXPR,
[<format expression>])
BEGIN
format_expr_option = optarg;
END
OPTION(format-file,F,FILE,
[<use FILE to format the output>])
ALIAS(formfile)
BEGIN
format_file_option = optarg;
END
OPTION(sort,s,,
[<sort the returned XML tree prior to outputting it>])
BEGIN
sort_option = 1;
END
OPTION(yes,Y,,
[<assume `yes' to all questions>])
BEGIN
confirm_mode = eclat_confirm_positive;
END
OPTION(no,N,,
[<assume `no' to all questions>])
BEGIN
confirm_mode = eclat_confirm_negative;
END
GROUP(Identifier translation)
OPTION(translate,x,,
[<translate resource IDs>])
BEGIN
translate_option = 1;
END
OPTION(no-translate,X,,
[<disable resource ID translation>])
BEGIN
translate_option = 0;
END
OPTION(map,M,[<MAPNAME>],
[<use this map instead of the default one (implies --translate)>])
BEGIN
custom_map = optarg;
translate_option = 1;
END
OPTION(test-map,,[<MAPNAME>],
[<test the translation map; supply IDs as arguments>])
BEGIN
test_map_name = optarg;
translate_option = 1;
END
GROUP(Preprocessor control)
OPTION(include-directory,I,DIR,
[<add include directory>])
BEGIN
grecs_preproc_add_include_dir(optarg);
END
OPTION(define,D,SYMBOL[=VALUE],
[<define a preprocessor symbol>])
BEGIN
size_t len;
char *p;
len = 5;
for (p = optarg; *p; p++) {
if (*p == '\\' || *p == '"')
len++;
len++;
}
if (pp_cmd_buflevel + len + 1 > pp_cmd_bufsize) {
pp_cmd_bufsize = pp_cmd_buflevel + len + 1;
pp_cmd_buffer = grecs_realloc(pp_cmd_buffer, pp_cmd_bufsize);
}
memcpy(pp_cmd_buffer + pp_cmd_buflevel, " \"-D", 4);
pp_cmd_buflevel += 4;
for (p = optarg; *p; p++) {
if (*p == '\\' || *p == '"')
pp_cmd_buffer[pp_cmd_buflevel++] = '\\';
pp_cmd_buffer[pp_cmd_buflevel++] = *p;
}
pp_cmd_buffer[pp_cmd_buflevel++] = '"';
pp_cmd_buffer[pp_cmd_buflevel] = 0;
END
OPTION(preprocessor,,COMMAND,
[<use COMMAND instead of the default preprocessor>])
BEGIN
grecs_preprocessor = optarg;
END
OPTION(no-preprocessor,,,
[<disable preprocessing>])
BEGIN
grecs_preprocessor = NULL;
END
GROUP(Debugging)
OPTION(dry-run,n,,
[<do nothing, print almost everything>])
BEGIN
dry_run_mode = 1;
parse_debug_level("main.1");
parse_debug_level("curl.1");
END
OPTION(check-permissions,p,,
[<check if the requested action is permitted for current account>])
BEGIN
ec2_param_list_append(&extra_param, "DryRun", "true");
END
OPTION(dump-grammar-trace,,,
[<dump configuration grammar traces>])
BEGIN
grecs_gram_trace (1);
END
OPTION(dump-lex-trace,,,
[<dump lexical analyzer traces>])
BEGIN
grecs_lex_trace (1);
END
OPTION(debug,d,CAT[.LEVEL],
[<set debugging level>])
BEGIN
if (parse_debug_level(optarg)) {
die(EX_USAGE, "invalid debugging category or level");
}
END
OPTION(add-parameter,A,NAME=VALUE,
[<pass additional parameter to the AWS request>])
BEGIN
char *p = strchr(optarg, '=');
if (!p)
die(EX_USAGE, "malformed parameter: %s", optarg);
*p++ = 0;
ec2_param_list_append(&extra_param, optarg, p);
END
GROUP([<Additional help>])
OPTION(config-help,,,
[<show configuration file summary>])
BEGIN
config_help();
exit(0);
END
OPTIONS_END
static void
parse_options(int *pargc, char **pargv[])
{
int index;
int argc;
char **argv;
char *p;
argc = *pargc;
argv = *pargv;
p = getenv("ECLAT_OPTIONS");
if (p) {
struct wordsplit ws;
int i, j;
ws.ws_offs = argc;
if (wordsplit(p, &ws, WRDSF_DEFFLAGS|WRDSF_DOOFFS))
die(EX_SOFTWARE, "wordsplit failed at \"%s\": %s",
p, wordsplit_strerror(&ws));
memmove(ws.ws_wordv + 1, ws.ws_wordv + ws.ws_offs,
sizeof(ws.ws_wordv[0])*ws.ws_wordc);
ws.ws_wordv[0] = argv[0];
for (i = 1, j = ws.ws_wordc + 1; i < argc; i++, j++)
ws.ws_wordv[j] = argv[i];
argc += ws.ws_wordc;
argv = ws.ws_wordv;
}
GETOPT(argc, argv, index, exit(EX_USAGE))
if (pp_cmd_buffer && grecs_preprocessor) {
char *cmd = grecs_malloc(strlen(grecs_preprocessor) +
pp_cmd_buflevel + 1);
strcpy(cmd, grecs_preprocessor);
strcat(cmd, pp_cmd_buffer);
grecs_preprocessor = cmd;
free(pp_cmd_buffer);
}
*pargc = argc - index;
*pargv = argv + index;
}
|