aboutsummaryrefslogtreecommitdiff
path: root/src/cmdline.opt
blob: 82e0e9549bd62e9e77e7653859a4ca638752df93 (plain)
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
/* This file is part of Eclat.
   Copyright (C) 2012 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 {
	char **s_ptr;
	char *s_val;
};

int
replace_string_var(void *p)
{
	struct replvar *rv = p;
	*rv->s_ptr = rv->s_val;
	return 0;
}

OPTIONS_BEGIN("eclat",
              [<EC2 Command Line Administrator Tool>],[<>],
	      [<gnu>],
              [<copyright_year=2012>],
              [<copyright_holder=Sergey Poznyakoff>])

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(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(config-file,c,FILE,
       [<use FILE instead of the default configuration>])
BEGIN
	conffile = optarg;
END

GROUP(Commands)

OPTION(start-instances,,,
       [<Start named instances>])
BEGIN
	eclat_command = eclat_command_start_instances;
END	

OPTION(stop-instances,,,
       [<Stop named instances>])
BEGIN
	eclat_command = eclat_command_stop_instances;
END	

OPTION(describe-tags,,,
       [<describe tags>])
BEGIN
	eclat_command = eclat_command_describe_tags;
END	

GROUP(Modifiers)

OPTION(region,,NAME,
       [<define AWS region>])
BEGIN
	struct replvar *rv = grecs_malloc(sizeof(*rv));
	rv->s_ptr = &region_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,KEY,
       [<set access key to use>])
BEGIN
	access_key = optarg;
END

OPTION(secret-key,W,KEY,
       [<set secret key to use>])
BEGIN
	secret_key = optarg;
END

OPTION(ssl,,,
       [<use SSL (HTTPS) connection>])
BEGIN
	use_ssl = 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 = 4;
	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;

        p = optarg;
	do {
		if (*p == '\\' || *p == '"')
			pp_cmd_buffer[pp_cmd_buflevel++] = '\\';
		pp_cmd_buffer[pp_cmd_buflevel++] = *p;
	} while (*p++);
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(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

GROUP([<Additional help>])
OPTION(config-help,,,
       [<show configuration file summary>])
BEGIN
	config_help();
	exit(0);
END

OPTIONS_END

void
set_program_name(const char *arg)
{
	program_name = strrchr(arg, '/');
	if (!program_name)
	        program_name = arg;
	else
	        program_name++;
}

void
parse_options(int argc, char *argv[], int *index)
{
        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);
	}
}

Return to:

Send suggestions and report system problems to the System administrator.