Skip to content
This repository
Browse code

- Make getopt stop processing as soon as the first non-option argumen…

…t is

  found. This should improve command chaining:
    previously required: xdotool search ... -- windowsize --usehints 80 24
    now : xdotool search ... windowsize --usehints 80 24

    The -- is no longer required to mark end of arguments for each command if a
    future command uses flags.

    From gnu's getopt_long(3):
      """If the first character of optstring is '+' or the environment variable
         POSIXLY_CORRECT is set, then option processing stops as soon as a
         non-option argument is encountered."""

Done with: sed -i -e '/getopt_long/ { s/"/"+/ }' *.c 



git-svn-id: https://semicomplete.googlecode.com/svn/xdotool@2940 66067f73-fe4c-0410-82e9-b9c6d0c95a22
  • Loading branch information...
commit 01c3953029f296639cb328036aad91791ea501c2 1 parent 0b2f7dc
Jordan Sissel authored
2  cmd_click.c
@@ -25,7 +25,7 @@ int cmd_click(context_t *context) {
25 25 "right = 3, wheel up = 4, wheel down = 5\n";
26 26 int option_index;
27 27
28   - while ((c = getopt_long_only(context->argc, context->argv, "cw:h",
  28 + while ((c = getopt_long_only(context->argc, context->argv, "+cw:h",
29 29 longopts, &option_index)) != -1) {
30 30 switch (c) {
31 31 case 'h':
2  cmd_get_desktop.c
@@ -13,7 +13,7 @@ int cmd_get_desktop(context_t *context) {
13 13 static const char *usage = "Usage: %s\n";
14 14 int option_index;
15 15
16   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  16 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
17 17 longopts, &option_index)) != -1) {
18 18 switch (c) {
19 19 case 'h':
2  cmd_get_desktop_for_window.c
@@ -15,7 +15,7 @@ int cmd_get_desktop_for_window(context_t *context) {
15 15 HELP_SEE_WINDOW_STACK;
16 16 int option_index;
17 17
18   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  18 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
19 19 longopts, &option_index)) != -1) {
20 20 switch (c) {
21 21 case 'h':
2  cmd_get_num_desktops.c
@@ -13,7 +13,7 @@ int cmd_get_num_desktops(context_t *context) {
13 13 static const char *usage = "Usage: %s\n";
14 14 int option_index;
15 15
16   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  16 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
17 17 longopts, &option_index)) != -1) {
18 18 switch (c) {
19 19 case 'h':
2  cmd_getactivewindow.c
@@ -13,7 +13,7 @@ int cmd_getactivewindow(context_t *context) {
13 13 static const char *usage = "Usage: %s\n";
14 14 int option_index;
15 15
16   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  16 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
17 17 longopts, &option_index)) != -1) {
18 18 switch (c) {
19 19 case 'h':
2  cmd_getmouselocation.c
@@ -17,7 +17,7 @@ int cmd_getmouselocation(context_t *context) {
17 17 int option_index;
18 18 int output_shell = 0;
19 19
20   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  20 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
21 21 longopts, &option_index)) != -1) {
22 22 switch (c) {
23 23 case 'h':
2  cmd_getwindowfocus.c
@@ -20,7 +20,7 @@ int cmd_getwindowfocus(context_t *context) {
20 20 " that has focus.\n";
21 21 int option_index;
22 22
23   - while ((c = getopt_long_only(context->argc, context->argv, "fh",
  23 + while ((c = getopt_long_only(context->argc, context->argv, "+fh",
24 24 longopts, &option_index)) != -1) {
25 25 switch (c) {
26 26 case 'h':
2  cmd_getwindowpid.c
@@ -12,7 +12,7 @@ int cmd_getwindowpid(context_t *context) {
12 12 static const char *usage = "Usage: %s <window id>\n";
13 13 int option_index;
14 14
15   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  15 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
16 16 longopts, &option_index)) != -1) {
17 17 switch (c) {
18 18 case 'h':
2  cmd_key.c
@@ -44,7 +44,7 @@ int cmd_key(context_t *context) {
44 44 HELP_CHAINING_ENDS;
45 45 int option_index;
46 46
47   - while ((c = getopt_long_only(context->argc, context->argv, "d:hcw:",
  47 + while ((c = getopt_long_only(context->argc, context->argv, "+d:hcw:",
48 48 longopts, &option_index)) != -1) {
49 49 switch (c) {
50 50 case 'w':
2  cmd_mousedown.c
@@ -22,7 +22,7 @@ int cmd_mousedown(context_t *context) {
22 22 "--clearmodifiers - reset active modifiers (alt, etc) while typing\n";
23 23 int option_index;
24 24
25   - while ((c = getopt_long_only(context->argc, context->argv, "chw:",
  25 + while ((c = getopt_long_only(context->argc, context->argv, "+chw:",
26 26 longopts, &option_index)) != -1) {
27 27 switch (c) {
28 28 case 'c':
2  cmd_mousemove.c
@@ -57,7 +57,7 @@ int cmd_mousemove(context_t *context) {
57 57 "-w, --window <windowid> - specify a window to move relative to.\n";
58 58 int option_index;
59 59
60   - while ((c = getopt_long_only(context->argc, context->argv, "chw:pd:",
  60 + while ((c = getopt_long_only(context->argc, context->argv, "+chw:pd:",
61 61 longopts, &option_index)) != -1) {
62 62 switch (c) {
63 63 case 'c':
2  cmd_mousemove_relative.c
@@ -38,7 +38,7 @@ int cmd_mousemove_relative(context_t *context) {
38 38 " %s 100 140\n";
39 39 int option_index;
40 40
41   - while ((c = getopt_long_only(context->argc, context->argv, "cph",
  41 + while ((c = getopt_long_only(context->argc, context->argv, "+cph",
42 42 longopts, &option_index)) != -1) {
43 43 switch (c) {
44 44 case 'h':
2  cmd_mouseup.c
@@ -22,7 +22,7 @@ int cmd_mouseup(context_t *context) {
22 22 "--clearmodifiers - reset active modifiers (alt, etc) while typing\n";
23 23 int option_index;
24 24
25   - while ((c = getopt_long_only(context->argc, context->argv, "cw:h",
  25 + while ((c = getopt_long_only(context->argc, context->argv, "+cw:h",
26 26 longopts, &option_index)) != -1) {
27 27 switch (c) {
28 28 case 'h':
2  cmd_search.c
@@ -57,7 +57,7 @@ int cmd_search(context_t *context) {
57 57 char *cmd = *context->argv;
58 58 int option_index;
59 59
60   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  60 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
61 61 longopts, &option_index)) != -1) {
62 62 switch (c) {
63 63 case 0:
2  cmd_set_desktop.c
@@ -12,7 +12,7 @@ int cmd_set_desktop(context_t *context) {
12 12 static const char *usage = "Usage: %s desktop\n";
13 13 int option_index;
14 14
15   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  15 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
16 16 longopts, &option_index)) != -1) {
17 17 switch (c) {
18 18 case 'h':
2  cmd_set_desktop_for_window.c
@@ -13,7 +13,7 @@ int cmd_set_desktop_for_window(context_t *context) {
13 13 static const char *usage = "Usage: %s <window> <desktop>\n";
14 14 int option_index;
15 15
16   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  16 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
17 17 longopts, &option_index)) != -1) {
18 18 switch (c) {
19 19 case 'h':
2  cmd_set_num_desktops.c
@@ -12,7 +12,7 @@ int cmd_set_num_desktops(context_t *context) {
12 12 static const char *usage = "Usage: %s num_desktops\n";
13 13 int option_index;
14 14
15   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  15 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
16 16 longopts, &option_index)) != -1) {
17 17 switch (c) {
18 18 case 'h':
2  cmd_set_window.c
@@ -25,7 +25,7 @@ int cmd_set_window(context_t *context) {
25 25 static const char *usage = "Usage: %s [--name name] [--icon-name name] "
26 26 "[--role role] [--classname classname] [--class class] window\n";
27 27
28   - while ((c = getopt_long_only(context->argc, context->argv, "hn:i:r:C:N:",
  28 + while ((c = getopt_long_only(context->argc, context->argv, "+hn:i:r:C:N:",
29 29 longopts, &option_index)) != -1) {
30 30 switch(c) {
31 31 case 'n':
2  cmd_type.c
@@ -30,7 +30,7 @@ int cmd_type(context_t *context) {
30 30 "-h, --help - show this help output\n";
31 31 int option_index;
32 32
33   - while ((c = getopt_long_only(context->argc, context->argv, "w:d:ch",
  33 + while ((c = getopt_long_only(context->argc, context->argv, "+w:d:ch",
34 34 longopts, &option_index)) != -1) {
35 35 switch (c) {
36 36 case 'w':
2  cmd_windowactivate.c
@@ -20,7 +20,7 @@ int cmd_windowactivate(context_t *context) {
20 20 "--sync - only exit once the window is active (is visible + active)\n";
21 21
22 22 int option_index;
23   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  23 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
24 24 longopts, &option_index)) != -1) {
25 25 switch (c) {
26 26 case 'h':
2  cmd_windowfocus.c
@@ -20,7 +20,7 @@ int cmd_windowfocus(context_t *context) {
20 20 "--sync - only exit once the window has focus\n";
21 21
22 22 int option_index;
23   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  23 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
24 24 longopts, &option_index)) != -1) {
25 25 switch (c) {
26 26 case 'h':
2  cmd_windowmap.c
@@ -21,7 +21,7 @@ int cmd_windowmap(context_t *context) {
21 21 "--sync - only exit once the window has been mapped (is visible)\n";
22 22
23 23 int option_index;
24   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  24 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
25 25 longopts, &option_index)) != -1) {
26 26 switch (c) {
27 27 case 'h':
2  cmd_windowmove.c
@@ -33,7 +33,7 @@ int cmd_windowmove(context_t *context) {
33 33 "--sync - only exit once the window has moved\n";
34 34
35 35 int option_index;
36   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  36 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
37 37 longopts, &option_index)) != -1) {
38 38 switch (c) {
39 39 case 'h':
2  cmd_windowraise.c
@@ -12,7 +12,7 @@ int cmd_windowraise(context_t *context) {
12 12 static const char *usage = "Usage: %s window\n";
13 13 int option_index;
14 14
15   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  15 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
16 16 longopts, &option_index)) != -1) {
17 17 switch (c) {
18 18 case 'h':
2  cmd_windowsize.c
@@ -27,7 +27,7 @@ int cmd_windowsize(context_t *context) {
27 27 "--sync - only exit once the window has resized\n";
28 28
29 29
30   - while ((c = getopt_long_only(context->argc, context->argv, "uh",
  30 + while ((c = getopt_long_only(context->argc, context->argv, "+uh",
31 31 longopts, &option_index)) != -1) {
32 32 switch (c) {
33 33 case 'h':
2  cmd_windowunmap.c
@@ -21,7 +21,7 @@ int cmd_windowunmap(context_t *context) {
21 21 "--sync - only exit once the window has been unmapped (is hidden)\n";
22 22
23 23 int option_index;
24   - while ((c = getopt_long_only(context->argc, context->argv, "h",
  24 + while ((c = getopt_long_only(context->argc, context->argv, "+h",
25 25 longopts, &option_index)) != -1) {
26 26 switch (c) {
27 27 case 'h':
2  xdotool.c
@@ -332,7 +332,7 @@ int args_main(int argc, char **argv) {
332 332 exit(1);
333 333 }
334 334
335   - while ((opt = getopt_long_only(argc, argv, "+hv", long_options, &option_index)) != -1) {
  335 + while ((opt = getopt_long_only(argc, argv, "++hv", long_options, &option_index)) != -1) {
336 336 switch (opt) {
337 337 case 'h':
338 338 cmd_help(NULL);

0 comments on commit 01c3953

Please sign in to comment.
Something went wrong with that request. Please try again.