|
@@ -0,0 +1,734 @@
|
|
1
|
+/*
|
|
2
|
+ File autogenerated by gengetopt version 2.22.6
|
|
3
|
+ generated with the following command:
|
|
4
|
+ gengetopt
|
|
5
|
+
|
|
6
|
+ The developers of gengetopt consider the fixed text that goes in all
|
|
7
|
+ gengetopt output files to be in the public domain:
|
|
8
|
+ we make no copyright claims on it.
|
|
9
|
+*/
|
|
10
|
+
|
|
11
|
+/* If we use autoconf. */
|
|
12
|
+#ifdef HAVE_CONFIG_H
|
|
13
|
+#include "config.h"
|
|
14
|
+#endif
|
|
15
|
+
|
|
16
|
+#include <stdio.h>
|
|
17
|
+#include <stdlib.h>
|
|
18
|
+#include <string.h>
|
|
19
|
+
|
|
20
|
+#ifndef FIX_UNUSED
|
|
21
|
+#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
|
|
22
|
+#endif
|
|
23
|
+
|
|
24
|
+#include <getopt.h>
|
|
25
|
+
|
|
26
|
+#include "cmdline.h"
|
|
27
|
+
|
|
28
|
+const char *gengetopt_args_info_purpose = "";
|
|
29
|
+
|
|
30
|
+const char *gengetopt_args_info_usage = "Usage: slop [options]";
|
|
31
|
+
|
|
32
|
+const char *gengetopt_args_info_versiontext = "Copyright (C) 2014 Dalton Nell, GPLv3";
|
|
33
|
+
|
|
34
|
+const char *gengetopt_args_info_description = "slop (Select Operation) is an application that queries for a selection from the\nuser and prints the region to stdout.";
|
|
35
|
+
|
|
36
|
+const char *gengetopt_args_info_help[] = {
|
|
37
|
+ " -h, --help Print help and exit",
|
|
38
|
+ " -V, --version Print version and exit",
|
|
39
|
+ "Options",
|
|
40
|
+ " --xdisplay=hostname:number.screen_number\n Sets the x display. (default=`:0')",
|
|
41
|
+ " --nokeyboard Disables the ability to cancel selections with\n the keyboard. (default=off)",
|
|
42
|
+ " -b, --bordersize=INT Set the selection rectangle's thickness. Does\n nothing when --highlight is enabled.\n (default=`5')",
|
|
43
|
+ " -p, --padding=INT Set the padding size of the selection. Can be\n negative. (default=`0')",
|
|
44
|
+ " -t, --tolerance=INT How far in pixels the mouse can move after\n clicking and still be detected as a normal\n click instead of a click and drag. Setting\n this to 0 will disable window selections.\n (default=`2')",
|
|
45
|
+ " -g, --gracetime=FLOAT Set the amount of time before slop will check\n for keyboard cancellations in seconds.\n (default=`0.4')",
|
|
46
|
+ " -c, --color=FLOAT,FLOAT,FLOAT,FLOAT\n Set the selection rectangle's color. Supports\n RGB or RGBA values.\n (default=`0.5,0.5,0.5,1')",
|
|
47
|
+ " -n, --nodecorations Attempt to select child windows in order to\n avoid window decorations. (default=off)",
|
|
48
|
+ " --min=INT Set the minimum output of width or height\n values. This is useful to avoid outputting 0.\n Setting min and max to the same value\n disables drag selections. (default=`0')",
|
|
49
|
+ " --max=INT Set the maximum output of width or height\n values. Setting min and max to the same value\n disables drag selections. (default=`0')",
|
|
50
|
+ " -l, --highlight Instead of outlining selections, slop\n highlights it. This is only useful when\n --color is set to a transparent color.\n (default=off)",
|
|
51
|
+ "\nExamples\n $ # Gray, thick, transparent border for maximum visiblity.\n $ slop -b 20 -c 0.5,0.5,0.5,0.8\n\n $ # Remove window decorations.\n $ slop --nodecorations\n\n $ # Disable window selections. Useful for selecting individual pixels.\n $ slop -t 0\n\n $ # Classic Windows XP selection.\n $ slop -l -c 0.3,0.4,0.6,0.4\n",
|
|
52
|
+ 0
|
|
53
|
+};
|
|
54
|
+
|
|
55
|
+typedef enum {ARG_NO
|
|
56
|
+ , ARG_FLAG
|
|
57
|
+ , ARG_STRING
|
|
58
|
+ , ARG_INT
|
|
59
|
+} cmdline_parser_arg_type;
|
|
60
|
+
|
|
61
|
+static
|
|
62
|
+void clear_given (struct gengetopt_args_info *args_info);
|
|
63
|
+static
|
|
64
|
+void clear_args (struct gengetopt_args_info *args_info);
|
|
65
|
+
|
|
66
|
+static int
|
|
67
|
+cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
|
|
68
|
+ struct cmdline_parser_params *params, const char *additional_error);
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+static char *
|
|
72
|
+gengetopt_strdup (const char *s);
|
|
73
|
+
|
|
74
|
+static
|
|
75
|
+void clear_given (struct gengetopt_args_info *args_info)
|
|
76
|
+{
|
|
77
|
+ args_info->help_given = 0 ;
|
|
78
|
+ args_info->version_given = 0 ;
|
|
79
|
+ args_info->xdisplay_given = 0 ;
|
|
80
|
+ args_info->nokeyboard_given = 0 ;
|
|
81
|
+ args_info->bordersize_given = 0 ;
|
|
82
|
+ args_info->padding_given = 0 ;
|
|
83
|
+ args_info->tolerance_given = 0 ;
|
|
84
|
+ args_info->gracetime_given = 0 ;
|
|
85
|
+ args_info->color_given = 0 ;
|
|
86
|
+ args_info->nodecorations_given = 0 ;
|
|
87
|
+ args_info->min_given = 0 ;
|
|
88
|
+ args_info->max_given = 0 ;
|
|
89
|
+ args_info->highlight_given = 0 ;
|
|
90
|
+}
|
|
91
|
+
|
|
92
|
+static
|
|
93
|
+void clear_args (struct gengetopt_args_info *args_info)
|
|
94
|
+{
|
|
95
|
+ FIX_UNUSED (args_info);
|
|
96
|
+ args_info->xdisplay_arg = gengetopt_strdup (":0");
|
|
97
|
+ args_info->xdisplay_orig = NULL;
|
|
98
|
+ args_info->nokeyboard_flag = 0;
|
|
99
|
+ args_info->bordersize_arg = 5;
|
|
100
|
+ args_info->bordersize_orig = NULL;
|
|
101
|
+ args_info->padding_arg = 0;
|
|
102
|
+ args_info->padding_orig = NULL;
|
|
103
|
+ args_info->tolerance_arg = 2;
|
|
104
|
+ args_info->tolerance_orig = NULL;
|
|
105
|
+ args_info->gracetime_arg = gengetopt_strdup ("0.4");
|
|
106
|
+ args_info->gracetime_orig = NULL;
|
|
107
|
+ args_info->color_arg = gengetopt_strdup ("0.5,0.5,0.5,1");
|
|
108
|
+ args_info->color_orig = NULL;
|
|
109
|
+ args_info->nodecorations_flag = 0;
|
|
110
|
+ args_info->min_arg = 0;
|
|
111
|
+ args_info->min_orig = NULL;
|
|
112
|
+ args_info->max_arg = 0;
|
|
113
|
+ args_info->max_orig = NULL;
|
|
114
|
+ args_info->highlight_flag = 0;
|
|
115
|
+
|
|
116
|
+}
|
|
117
|
+
|
|
118
|
+static
|
|
119
|
+void init_args_info(struct gengetopt_args_info *args_info)
|
|
120
|
+{
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+ args_info->help_help = gengetopt_args_info_help[0] ;
|
|
124
|
+ args_info->version_help = gengetopt_args_info_help[1] ;
|
|
125
|
+ args_info->xdisplay_help = gengetopt_args_info_help[3] ;
|
|
126
|
+ args_info->nokeyboard_help = gengetopt_args_info_help[4] ;
|
|
127
|
+ args_info->bordersize_help = gengetopt_args_info_help[5] ;
|
|
128
|
+ args_info->padding_help = gengetopt_args_info_help[6] ;
|
|
129
|
+ args_info->tolerance_help = gengetopt_args_info_help[7] ;
|
|
130
|
+ args_info->gracetime_help = gengetopt_args_info_help[8] ;
|
|
131
|
+ args_info->color_help = gengetopt_args_info_help[9] ;
|
|
132
|
+ args_info->nodecorations_help = gengetopt_args_info_help[10] ;
|
|
133
|
+ args_info->min_help = gengetopt_args_info_help[11] ;
|
|
134
|
+ args_info->max_help = gengetopt_args_info_help[12] ;
|
|
135
|
+ args_info->highlight_help = gengetopt_args_info_help[13] ;
|
|
136
|
+
|
|
137
|
+}
|
|
138
|
+
|
|
139
|
+void
|
|
140
|
+cmdline_parser_print_version (void)
|
|
141
|
+{
|
|
142
|
+ printf ("%s %s\n",
|
|
143
|
+ (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
|
|
144
|
+ CMDLINE_PARSER_VERSION);
|
|
145
|
+
|
|
146
|
+ if (strlen(gengetopt_args_info_versiontext) > 0)
|
|
147
|
+ printf("\n%s\n", gengetopt_args_info_versiontext);
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+static void print_help_common(void) {
|
|
151
|
+ cmdline_parser_print_version ();
|
|
152
|
+
|
|
153
|
+ if (strlen(gengetopt_args_info_purpose) > 0)
|
|
154
|
+ printf("\n%s\n", gengetopt_args_info_purpose);
|
|
155
|
+
|
|
156
|
+ if (strlen(gengetopt_args_info_usage) > 0)
|
|
157
|
+ printf("\n%s\n", gengetopt_args_info_usage);
|
|
158
|
+
|
|
159
|
+ printf("\n");
|
|
160
|
+
|
|
161
|
+ if (strlen(gengetopt_args_info_description) > 0)
|
|
162
|
+ printf("%s\n\n", gengetopt_args_info_description);
|
|
163
|
+}
|
|
164
|
+
|
|
165
|
+void
|
|
166
|
+cmdline_parser_print_help (void)
|
|
167
|
+{
|
|
168
|
+ int i = 0;
|
|
169
|
+ print_help_common();
|
|
170
|
+ while (gengetopt_args_info_help[i])
|
|
171
|
+ printf("%s\n", gengetopt_args_info_help[i++]);
|
|
172
|
+}
|
|
173
|
+
|
|
174
|
+void
|
|
175
|
+cmdline_parser_init (struct gengetopt_args_info *args_info)
|
|
176
|
+{
|
|
177
|
+ clear_given (args_info);
|
|
178
|
+ clear_args (args_info);
|
|
179
|
+ init_args_info (args_info);
|
|
180
|
+}
|
|
181
|
+
|
|
182
|
+void
|
|
183
|
+cmdline_parser_params_init(struct cmdline_parser_params *params)
|
|
184
|
+{
|
|
185
|
+ if (params)
|
|
186
|
+ {
|
|
187
|
+ params->override = 0;
|
|
188
|
+ params->initialize = 1;
|
|
189
|
+ params->check_required = 1;
|
|
190
|
+ params->check_ambiguity = 0;
|
|
191
|
+ params->print_errors = 1;
|
|
192
|
+ }
|
|
193
|
+}
|
|
194
|
+
|
|
195
|
+struct cmdline_parser_params *
|
|
196
|
+cmdline_parser_params_create(void)
|
|
197
|
+{
|
|
198
|
+ struct cmdline_parser_params *params =
|
|
199
|
+ (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
|
|
200
|
+ cmdline_parser_params_init(params);
|
|
201
|
+ return params;
|
|
202
|
+}
|
|
203
|
+
|
|
204
|
+static void
|
|
205
|
+free_string_field (char **s)
|
|
206
|
+{
|
|
207
|
+ if (*s)
|
|
208
|
+ {
|
|
209
|
+ free (*s);
|
|
210
|
+ *s = 0;
|
|
211
|
+ }
|
|
212
|
+}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+static void
|
|
216
|
+cmdline_parser_release (struct gengetopt_args_info *args_info)
|
|
217
|
+{
|
|
218
|
+
|
|
219
|
+ free_string_field (&(args_info->xdisplay_arg));
|
|
220
|
+ free_string_field (&(args_info->xdisplay_orig));
|
|
221
|
+ free_string_field (&(args_info->bordersize_orig));
|
|
222
|
+ free_string_field (&(args_info->padding_orig));
|
|
223
|
+ free_string_field (&(args_info->tolerance_orig));
|
|
224
|
+ free_string_field (&(args_info->gracetime_arg));
|
|
225
|
+ free_string_field (&(args_info->gracetime_orig));
|
|
226
|
+ free_string_field (&(args_info->color_arg));
|
|
227
|
+ free_string_field (&(args_info->color_orig));
|
|
228
|
+ free_string_field (&(args_info->min_orig));
|
|
229
|
+ free_string_field (&(args_info->max_orig));
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+ clear_given (args_info);
|
|
234
|
+}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+static void
|
|
238
|
+write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
|
|
239
|
+{
|
|
240
|
+ FIX_UNUSED (values);
|
|
241
|
+ if (arg) {
|
|
242
|
+ fprintf(outfile, "%s=\"%s\"\n", opt, arg);
|
|
243
|
+ } else {
|
|
244
|
+ fprintf(outfile, "%s\n", opt);
|
|
245
|
+ }
|
|
246
|
+}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+int
|
|
250
|
+cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
|
|
251
|
+{
|
|
252
|
+ int i = 0;
|
|
253
|
+
|
|
254
|
+ if (!outfile)
|
|
255
|
+ {
|
|
256
|
+ fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
|
|
257
|
+ return EXIT_FAILURE;
|
|
258
|
+ }
|
|
259
|
+
|
|
260
|
+ if (args_info->help_given)
|
|
261
|
+ write_into_file(outfile, "help", 0, 0 );
|
|
262
|
+ if (args_info->version_given)
|
|
263
|
+ write_into_file(outfile, "version", 0, 0 );
|
|
264
|
+ if (args_info->xdisplay_given)
|
|
265
|
+ write_into_file(outfile, "xdisplay", args_info->xdisplay_orig, 0);
|
|
266
|
+ if (args_info->nokeyboard_given)
|
|
267
|
+ write_into_file(outfile, "nokeyboard", 0, 0 );
|
|
268
|
+ if (args_info->bordersize_given)
|
|
269
|
+ write_into_file(outfile, "bordersize", args_info->bordersize_orig, 0);
|
|
270
|
+ if (args_info->padding_given)
|
|
271
|
+ write_into_file(outfile, "padding", args_info->padding_orig, 0);
|
|
272
|
+ if (args_info->tolerance_given)
|
|
273
|
+ write_into_file(outfile, "tolerance", args_info->tolerance_orig, 0);
|
|
274
|
+ if (args_info->gracetime_given)
|
|
275
|
+ write_into_file(outfile, "gracetime", args_info->gracetime_orig, 0);
|
|
276
|
+ if (args_info->color_given)
|
|
277
|
+ write_into_file(outfile, "color", args_info->color_orig, 0);
|
|
278
|
+ if (args_info->nodecorations_given)
|
|
279
|
+ write_into_file(outfile, "nodecorations", 0, 0 );
|
|
280
|
+ if (args_info->min_given)
|
|
281
|
+ write_into_file(outfile, "min", args_info->min_orig, 0);
|
|
282
|
+ if (args_info->max_given)
|
|
283
|
+ write_into_file(outfile, "max", args_info->max_orig, 0);
|
|
284
|
+ if (args_info->highlight_given)
|
|
285
|
+ write_into_file(outfile, "highlight", 0, 0 );
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+ i = EXIT_SUCCESS;
|
|
289
|
+ return i;
|
|
290
|
+}
|
|
291
|
+
|
|
292
|
+int
|
|
293
|
+cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
|
|
294
|
+{
|
|
295
|
+ FILE *outfile;
|
|
296
|
+ int i = 0;
|
|
297
|
+
|
|
298
|
+ outfile = fopen(filename, "w");
|
|
299
|
+
|
|
300
|
+ if (!outfile)
|
|
301
|
+ {
|
|
302
|
+ fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
|
|
303
|
+ return EXIT_FAILURE;
|
|
304
|
+ }
|
|
305
|
+
|
|
306
|
+ i = cmdline_parser_dump(outfile, args_info);
|
|
307
|
+ fclose (outfile);
|
|
308
|
+
|
|
309
|
+ return i;
|
|
310
|
+}
|
|
311
|
+
|
|
312
|
+void
|
|
313
|
+cmdline_parser_free (struct gengetopt_args_info *args_info)
|
|
314
|
+{
|
|
315
|
+ cmdline_parser_release (args_info);
|
|
316
|
+}
|
|
317
|
+
|
|
318
|
+/** @brief replacement of strdup, which is not standard */
|
|
319
|
+char *
|
|
320
|
+gengetopt_strdup (const char *s)
|
|
321
|
+{
|
|
322
|
+ char *result = 0;
|
|
323
|
+ if (!s)
|
|
324
|
+ return result;
|
|
325
|
+
|
|
326
|
+ result = (char*)malloc(strlen(s) + 1);
|
|
327
|
+ if (result == (char*)0)
|
|
328
|
+ return (char*)0;
|
|
329
|
+ strcpy(result, s);
|
|
330
|
+ return result;
|
|
331
|
+}
|
|
332
|
+
|
|
333
|
+int
|
|
334
|
+cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
|
|
335
|
+{
|
|
336
|
+ return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
|
|
337
|
+}
|
|
338
|
+
|
|
339
|
+int
|
|
340
|
+cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
|
|
341
|
+ struct cmdline_parser_params *params)
|
|
342
|
+{
|
|
343
|
+ int result;
|
|
344
|
+ result = cmdline_parser_internal (argc, argv, args_info, params, 0);
|
|
345
|
+
|
|
346
|
+ if (result == EXIT_FAILURE)
|
|
347
|
+ {
|
|
348
|
+ cmdline_parser_free (args_info);
|
|
349
|
+ exit (EXIT_FAILURE);
|
|
350
|
+ }
|
|
351
|
+
|
|
352
|
+ return result;
|
|
353
|
+}
|
|
354
|
+
|
|
355
|
+int
|
|
356
|
+cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
|
|
357
|
+{
|
|
358
|
+ int result;
|
|
359
|
+ struct cmdline_parser_params params;
|
|
360
|
+
|
|
361
|
+ params.override = override;
|
|
362
|
+ params.initialize = initialize;
|
|
363
|
+ params.check_required = check_required;
|
|
364
|
+ params.check_ambiguity = 0;
|
|
365
|
+ params.print_errors = 1;
|
|
366
|
+
|
|
367
|
+ result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
|
|
368
|
+
|
|
369
|
+ if (result == EXIT_FAILURE)
|
|
370
|
+ {
|
|
371
|
+ cmdline_parser_free (args_info);
|
|
372
|
+ exit (EXIT_FAILURE);
|
|
373
|
+ }
|
|
374
|
+
|
|
375
|
+ return result;
|
|
376
|
+}
|
|
377
|
+
|
|
378
|
+int
|
|
379
|
+cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
|
|
380
|
+{
|
|
381
|
+ FIX_UNUSED (args_info);
|
|
382
|
+ FIX_UNUSED (prog_name);
|
|
383
|
+ return EXIT_SUCCESS;
|
|
384
|
+}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+static char *package_name = 0;
|
|
388
|
+
|
|
389
|
+/**
|
|
390
|
+ * @brief updates an option
|
|
391
|
+ * @param field the generic pointer to the field to update
|
|
392
|
+ * @param orig_field the pointer to the orig field
|
|
393
|
+ * @param field_given the pointer to the number of occurrence of this option
|
|
394
|
+ * @param prev_given the pointer to the number of occurrence already seen
|
|
395
|
+ * @param value the argument for this option (if null no arg was specified)
|
|
396
|
+ * @param possible_values the possible values for this option (if specified)
|
|
397
|
+ * @param default_value the default value (in case the option only accepts fixed values)
|
|
398
|
+ * @param arg_type the type of this option
|
|
399
|
+ * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
|
|
400
|
+ * @param override @see cmdline_parser_params.override
|
|
401
|
+ * @param no_free whether to free a possible previous value
|
|
402
|
+ * @param multiple_option whether this is a multiple option
|
|
403
|
+ * @param long_opt the corresponding long option
|
|
404
|
+ * @param short_opt the corresponding short option (or '-' if none)
|
|
405
|
+ * @param additional_error possible further error specification
|
|
406
|
+ */
|
|
407
|
+static
|
|
408
|
+int update_arg(void *field, char **orig_field,
|
|
409
|
+ unsigned int *field_given, unsigned int *prev_given,
|
|
410
|
+ char *value, const char *possible_values[],
|
|
411
|
+ const char *default_value,
|
|
412
|
+ cmdline_parser_arg_type arg_type,
|
|
413
|
+ int check_ambiguity, int override,
|
|
414
|
+ int no_free, int multiple_option,
|
|
415
|
+ const char *long_opt, char short_opt,
|
|
416
|
+ const char *additional_error)
|
|
417
|
+{
|
|
418
|
+ char *stop_char = 0;
|
|
419
|
+ const char *val = value;
|
|
420
|
+ int found;
|
|
421
|
+ char **string_field;
|
|
422
|
+ FIX_UNUSED (field);
|
|
423
|
+
|
|
424
|
+ stop_char = 0;
|
|
425
|
+ found = 0;
|
|
426
|
+
|
|
427
|
+ if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
|
|
428
|
+ {
|
|
429
|
+ if (short_opt != '-')
|
|
430
|
+ fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
|
|
431
|
+ package_name, long_opt, short_opt,
|
|
432
|
+ (additional_error ? additional_error : ""));
|
|
433
|
+ else
|
|
434
|
+ fprintf (stderr, "%s: `--%s' option given more than once%s\n",
|
|
435
|
+ package_name, long_opt,
|
|
436
|
+ (additional_error ? additional_error : ""));
|
|
437
|
+ return 1; /* failure */
|
|
438
|
+ }
|
|
439
|
+
|
|
440
|
+ FIX_UNUSED (default_value);
|
|
441
|
+
|
|
442
|
+ if (field_given && *field_given && ! override)
|
|
443
|
+ return 0;
|
|
444
|
+ if (prev_given)
|
|
445
|
+ (*prev_given)++;
|
|
446
|
+ if (field_given)
|
|
447
|
+ (*field_given)++;
|
|
448
|
+ if (possible_values)
|
|
449
|
+ val = possible_values[found];
|
|
450
|
+
|
|
451
|
+ switch(arg_type) {
|
|
452
|
+ case ARG_FLAG:
|
|
453
|
+ *((int *)field) = !*((int *)field);
|
|
454
|
+ break;
|
|
455
|
+ case ARG_INT:
|
|
456
|
+ if (val) *((int *)field) = strtol (val, &stop_char, 0);
|
|
457
|
+ break;
|
|
458
|
+ case ARG_STRING:
|
|
459
|
+ if (val) {
|
|
460
|
+ string_field = (char **)field;
|
|
461
|
+ if (!no_free && *string_field)
|
|
462
|
+ free (*string_field); /* free previous string */
|
|
463
|
+ *string_field = gengetopt_strdup (val);
|
|
464
|
+ }
|
|
465
|
+ break;
|
|
466
|
+ default:
|
|
467
|
+ break;
|
|
468
|
+ };
|
|
469
|
+
|
|
470
|
+ /* check numeric conversion */
|
|
471
|
+ switch(arg_type) {
|
|
472
|
+ case ARG_INT:
|
|
473
|
+ if (val && !(stop_char && *stop_char == '\0')) {
|
|
474
|
+ fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
|
|
475
|
+ return 1; /* failure */
|
|
476
|
+ }
|
|
477
|
+ break;
|
|
478
|
+ default:
|
|
479
|
+ ;
|
|
480
|
+ };
|
|
481
|
+
|
|
482
|
+ /* store the original value */
|
|
483
|
+ switch(arg_type) {
|
|
484
|
+ case ARG_NO:
|
|
485
|
+ case ARG_FLAG:
|
|
486
|
+ break;
|
|
487
|
+ default:
|
|
488
|
+ if (value && orig_field) {
|
|
489
|
+ if (no_free) {
|
|
490
|
+ *orig_field = value;
|
|
491
|
+ } else {
|
|
492
|
+ if (*orig_field)
|
|
493
|
+ free (*orig_field); /* free previous string */
|
|
494
|
+ *orig_field = gengetopt_strdup (value);
|
|
495
|
+ }
|
|
496
|
+ }
|
|
497
|
+ };
|
|
498
|
+
|
|
499
|
+ return 0; /* OK */
|
|
500
|
+}
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+int
|
|
504
|
+cmdline_parser_internal (
|
|
505
|
+ int argc, char **argv, struct gengetopt_args_info *args_info,
|
|
506
|
+ struct cmdline_parser_params *params, const char *additional_error)
|
|
507
|
+{
|
|
508
|
+ int c; /* Character of the parsed option. */
|
|
509
|
+
|
|
510
|
+ int error_occurred = 0;
|
|
511
|
+ struct gengetopt_args_info local_args_info;
|
|
512
|
+
|
|
513
|
+ int override;
|
|
514
|
+ int initialize;
|
|
515
|
+ int check_required;
|
|
516
|
+ int check_ambiguity;
|
|
517
|
+
|
|
518
|
+ package_name = argv[0];
|
|
519
|
+
|
|
520
|
+ override = params->override;
|
|
521
|
+ initialize = params->initialize;
|
|
522
|
+ check_required = params->check_required;
|
|
523
|
+ check_ambiguity = params->check_ambiguity;
|
|
524
|
+
|
|
525
|
+ if (initialize)
|
|
526
|
+ cmdline_parser_init (args_info);
|
|
527
|
+
|
|
528
|
+ cmdline_parser_init (&local_args_info);
|
|
529
|
+
|
|
530
|
+ optarg = 0;
|
|
531
|
+ optind = 0;
|
|
532
|
+ opterr = params->print_errors;
|
|
533
|
+ optopt = '?';
|
|
534
|
+
|
|
535
|
+ while (1)
|
|
536
|
+ {
|
|
537
|
+ int option_index = 0;
|
|
538
|
+
|
|
539
|
+ static struct option long_options[] = {
|
|
540
|
+ { "help", 0, NULL, 'h' },
|
|
541
|
+ { "version", 0, NULL, 'V' },
|
|
542
|
+ { "xdisplay", 1, NULL, 0 },
|
|
543
|
+ { "nokeyboard", 0, NULL, 0 },
|
|
544
|
+ { "bordersize", 1, NULL, 'b' },
|
|
545
|
+ { "padding", 1, NULL, 'p' },
|
|
546
|
+ { "tolerance", 1, NULL, 't' },
|
|
547
|
+ { "gracetime", 1, NULL, 'g' },
|
|
548
|
+ { "color", 1, NULL, 'c' },
|
|
549
|
+ { "nodecorations", 0, NULL, 'n' },
|
|
550
|
+ { "min", 1, NULL, 0 },
|
|
551
|
+ { "max", 1, NULL, 0 },
|
|
552
|
+ { "highlight", 0, NULL, 'l' },
|
|
553
|
+ { 0, 0, 0, 0 }
|
|
554
|
+ };
|
|
555
|
+
|
|
556
|
+ c = getopt_long (argc, argv, "hVb:p:t:g:c:nl", long_options, &option_index);
|
|
557
|
+
|
|
558
|
+ if (c == -1) break; /* Exit from `while (1)' loop. */
|
|
559
|
+
|
|
560
|
+ switch (c)
|
|
561
|
+ {
|
|
562
|
+ case 'h': /* Print help and exit. */
|
|
563
|
+ cmdline_parser_print_help ();
|
|
564
|
+ cmdline_parser_free (&local_args_info);
|
|
565
|
+ exit (EXIT_SUCCESS);
|
|
566
|
+
|
|
567
|
+ case 'V': /* Print version and exit. */
|
|
568
|
+ cmdline_parser_print_version ();
|
|
569
|
+ cmdline_parser_free (&local_args_info);
|
|
570
|
+ exit (EXIT_SUCCESS);
|
|
571
|
+
|
|
572
|
+ case 'b': /* Set the selection rectangle's thickness. Does nothing when --highlight is enabled.. */
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+ if (update_arg( (void *)&(args_info->bordersize_arg),
|
|
576
|
+ &(args_info->bordersize_orig), &(args_info->bordersize_given),
|
|
577
|
+ &(local_args_info.bordersize_given), optarg, 0, "5", ARG_INT,
|
|
578
|
+ check_ambiguity, override, 0, 0,
|
|
579
|
+ "bordersize", 'b',
|
|
580
|
+ additional_error))
|
|
581
|
+ goto failure;
|
|
582
|
+
|
|
583
|
+ break;
|
|
584
|
+ case 'p': /* Set the padding size of the selection. Can be negative.. */
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+ if (update_arg( (void *)&(args_info->padding_arg),
|
|
588
|
+ &(args_info->padding_orig), &(args_info->padding_given),
|
|
589
|
+ &(local_args_info.padding_given), optarg, 0, "0", ARG_INT,
|
|
590
|
+ check_ambiguity, override, 0, 0,
|
|
591
|
+ "padding", 'p',
|
|
592
|
+ additional_error))
|
|
593
|
+ goto failure;
|
|
594
|
+
|
|
595
|
+ break;
|
|
596
|
+ case 't': /* How far in pixels the mouse can move after clicking and still be detected as a normal click instead of a click and drag. Setting this to 0 will disable window selections.. */
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+ if (update_arg( (void *)&(args_info->tolerance_arg),
|
|
600
|
+ &(args_info->tolerance_orig), &(args_info->tolerance_given),
|
|
601
|
+ &(local_args_info.tolerance_given), optarg, 0, "2", ARG_INT,
|
|
602
|
+ check_ambiguity, override, 0, 0,
|
|
603
|
+ "tolerance", 't',
|
|
604
|
+ additional_error))
|
|
605
|
+ goto failure;
|
|
606
|
+
|
|
607
|
+ break;
|
|
608
|
+ case 'g': /* Set the amount of time before slop will check for keyboard cancellations in seconds.. */
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+ if (update_arg( (void *)&(args_info->gracetime_arg),
|
|
612
|
+ &(args_info->gracetime_orig), &(args_info->gracetime_given),
|
|
613
|
+ &(local_args_info.gracetime_given), optarg, 0, "0.4", ARG_STRING,
|
|
614
|
+ check_ambiguity, override, 0, 0,
|
|
615
|
+ "gracetime", 'g',
|
|
616
|
+ additional_error))
|
|
617
|
+ goto failure;
|
|
618
|
+
|
|
619
|
+ break;
|
|
620
|
+ case 'c': /* Set the selection rectangle's color. Supports RGB or RGBA values.. */
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+ if (update_arg( (void *)&(args_info->color_arg),
|
|
624
|
+ &(args_info->color_orig), &(args_info->color_given),
|
|
625
|
+ &(local_args_info.color_given), optarg, 0, "0.5,0.5,0.5,1", ARG_STRING,
|
|
626
|
+ check_ambiguity, override, 0, 0,
|
|
627
|
+ "color", 'c',
|
|
628
|
+ additional_error))
|
|
629
|
+ goto failure;
|
|
630
|
+
|
|
631
|
+ break;
|
|
632
|
+ case 'n': /* Attempt to select child windows in order to avoid window decorations.. */
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+ if (update_arg((void *)&(args_info->nodecorations_flag), 0, &(args_info->nodecorations_given),
|
|
636
|
+ &(local_args_info.nodecorations_given), optarg, 0, 0, ARG_FLAG,
|
|
637
|
+ check_ambiguity, override, 1, 0, "nodecorations", 'n',
|
|
638
|
+ additional_error))
|
|
639
|
+ goto failure;
|
|
640
|
+
|
|
641
|
+ break;
|
|
642
|
+ case 'l': /* Instead of outlining selections, slop highlights it. This is only useful when --color is set to a transparent color.. */
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+ if (update_arg((void *)&(args_info->highlight_flag), 0, &(args_info->highlight_given),
|
|
646
|
+ &(local_args_info.highlight_given), optarg, 0, 0, ARG_FLAG,
|
|
647
|
+ check_ambiguity, override, 1, 0, "highlight", 'l',
|
|
648
|
+ additional_error))
|
|
649
|
+ goto failure;
|
|
650
|
+
|
|
651
|
+ break;
|
|
652
|
+
|
|
653
|
+ case 0: /* Long option with no short option */
|
|
654
|
+ /* Sets the x display.. */
|
|
655
|
+ if (strcmp (long_options[option_index].name, "xdisplay") == 0)
|
|
656
|
+ {
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+ if (update_arg( (void *)&(args_info->xdisplay_arg),
|
|
660
|
+ &(args_info->xdisplay_orig), &(args_info->xdisplay_given),
|
|
661
|
+ &(local_args_info.xdisplay_given), optarg, 0, ":0", ARG_STRING,
|
|
662
|
+ check_ambiguity, override, 0, 0,
|
|
663
|
+ "xdisplay", '-',
|
|
664
|
+ additional_error))
|
|
665
|
+ goto failure;
|
|
666
|
+
|
|
667
|
+ }
|
|
668
|
+ /* Disables the ability to cancel selections with the keyboard.. */
|
|
669
|
+ else if (strcmp (long_options[option_index].name, "nokeyboard") == 0)
|
|
670
|
+ {
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+ if (update_arg((void *)&(args_info->nokeyboard_flag), 0, &(args_info->nokeyboard_given),
|
|
674
|
+ &(local_args_info.nokeyboard_given), optarg, 0, 0, ARG_FLAG,
|
|
675
|
+ check_ambiguity, override, 1, 0, "nokeyboard", '-',
|
|
676
|
+ additional_error))
|
|
677
|
+ goto failure;
|
|
678
|
+
|
|
679
|
+ }
|
|
680
|
+ /* Set the minimum output of width or height values. This is useful to avoid outputting 0. Setting min and max to the same value disables drag selections.. */
|
|
681
|
+ else if (strcmp (long_options[option_index].name, "min") == 0)
|
|
682
|
+ {
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+ if (update_arg( (void *)&(args_info->min_arg),
|
|
686
|
+ &(args_info->min_orig), &(args_info->min_given),
|
|
687
|
+ &(local_args_info.min_given), optarg, 0, "0", ARG_INT,
|
|
688
|
+ check_ambiguity, override, 0, 0,
|
|
689
|
+ "min", '-',
|
|
690
|
+ additional_error))
|
|
691
|
+ goto failure;
|
|
692
|
+
|
|
693
|
+ }
|
|
694
|
+ /* Set the maximum output of width or height values. Setting min and max to the same value disables drag selections.. */
|
|
695
|
+ else if (strcmp (long_options[option_index].name, "max") == 0)
|
|
696
|
+ {
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+ if (update_arg( (void *)&(args_info->max_arg),
|
|
700
|
+ &(args_info->max_orig), &(args_info->max_given),
|
|
701
|
+ &(local_args_info.max_given), optarg, 0, "0", ARG_INT,
|
|
702
|
+ check_ambiguity, override, 0, 0,
|
|
703
|
+ "max", '-',
|
|
704
|
+ additional_error))
|
|
705
|
+ goto failure;
|
|
706
|
+
|
|
707
|
+ }
|
|
708
|
+
|
|
709
|
+ break;
|
|
710
|
+ case '?': /* Invalid option. */
|
|
711
|
+ /* `getopt_long' already printed an error message. */
|
|
712
|
+ goto failure;
|
|
713
|
+
|
|
714
|
+ default: /* bug: option not considered. */
|
|
715
|
+ fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
|
|
716
|
+ abort ();
|
|
717
|
+ } /* switch */
|
|
718
|
+ } /* while */
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+ cmdline_parser_release (&local_args_info);
|
|
724
|
+
|
|
725
|
+ if ( error_occurred )
|
|
726
|
+ return (EXIT_FAILURE);
|
|
727
|
+
|
|
728
|
+ return 0;
|
|
729
|
+
|
|
730
|
+failure:
|
|
731
|
+
|
|
732
|
+ cmdline_parser_release (&local_args_info);
|
|
733
|
+ return (EXIT_FAILURE);
|
|
734
|
+}
|