cmdline.c 25KB

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