Permalink
Browse files

- 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...
1 parent 0b2f7dc commit 01c3953029f296639cb328036aad91791ea501c2 @jordansissel committed Jun 13, 2010
View
2 cmd_click.c
@@ -25,7 +25,7 @@ int cmd_click(context_t *context) {
"right = 3, wheel up = 4, wheel down = 5\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "cw:h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+cw:h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_get_desktop.c
@@ -13,7 +13,7 @@ int cmd_get_desktop(context_t *context) {
static const char *usage = "Usage: %s\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_get_desktop_for_window.c
@@ -15,7 +15,7 @@ int cmd_get_desktop_for_window(context_t *context) {
HELP_SEE_WINDOW_STACK;
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_get_num_desktops.c
@@ -13,7 +13,7 @@ int cmd_get_num_desktops(context_t *context) {
static const char *usage = "Usage: %s\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_getactivewindow.c
@@ -13,7 +13,7 @@ int cmd_getactivewindow(context_t *context) {
static const char *usage = "Usage: %s\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_getmouselocation.c
@@ -17,7 +17,7 @@ int cmd_getmouselocation(context_t *context) {
int option_index;
int output_shell = 0;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_getwindowfocus.c
@@ -20,7 +20,7 @@ int cmd_getwindowfocus(context_t *context) {
" that has focus.\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "fh",
+ while ((c = getopt_long_only(context->argc, context->argv, "+fh",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_getwindowpid.c
@@ -12,7 +12,7 @@ int cmd_getwindowpid(context_t *context) {
static const char *usage = "Usage: %s <window id>\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_key.c
@@ -44,7 +44,7 @@ int cmd_key(context_t *context) {
HELP_CHAINING_ENDS;
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "d:hcw:",
+ while ((c = getopt_long_only(context->argc, context->argv, "+d:hcw:",
longopts, &option_index)) != -1) {
switch (c) {
case 'w':
View
2 cmd_mousedown.c
@@ -22,7 +22,7 @@ int cmd_mousedown(context_t *context) {
"--clearmodifiers - reset active modifiers (alt, etc) while typing\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "chw:",
+ while ((c = getopt_long_only(context->argc, context->argv, "+chw:",
longopts, &option_index)) != -1) {
switch (c) {
case 'c':
View
2 cmd_mousemove.c
@@ -57,7 +57,7 @@ int cmd_mousemove(context_t *context) {
"-w, --window <windowid> - specify a window to move relative to.\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "chw:pd:",
+ while ((c = getopt_long_only(context->argc, context->argv, "+chw:pd:",
longopts, &option_index)) != -1) {
switch (c) {
case 'c':
View
2 cmd_mousemove_relative.c
@@ -38,7 +38,7 @@ int cmd_mousemove_relative(context_t *context) {
" %s 100 140\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "cph",
+ while ((c = getopt_long_only(context->argc, context->argv, "+cph",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_mouseup.c
@@ -22,7 +22,7 @@ int cmd_mouseup(context_t *context) {
"--clearmodifiers - reset active modifiers (alt, etc) while typing\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "cw:h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+cw:h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_search.c
@@ -57,7 +57,7 @@ int cmd_search(context_t *context) {
char *cmd = *context->argv;
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 0:
View
2 cmd_set_desktop.c
@@ -12,7 +12,7 @@ int cmd_set_desktop(context_t *context) {
static const char *usage = "Usage: %s desktop\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_set_desktop_for_window.c
@@ -13,7 +13,7 @@ int cmd_set_desktop_for_window(context_t *context) {
static const char *usage = "Usage: %s <window> <desktop>\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_set_num_desktops.c
@@ -12,7 +12,7 @@ int cmd_set_num_desktops(context_t *context) {
static const char *usage = "Usage: %s num_desktops\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_set_window.c
@@ -25,7 +25,7 @@ int cmd_set_window(context_t *context) {
static const char *usage = "Usage: %s [--name name] [--icon-name name] "
"[--role role] [--classname classname] [--class class] window\n";
- while ((c = getopt_long_only(context->argc, context->argv, "hn:i:r:C:N:",
+ while ((c = getopt_long_only(context->argc, context->argv, "+hn:i:r:C:N:",
longopts, &option_index)) != -1) {
switch(c) {
case 'n':
View
2 cmd_type.c
@@ -30,7 +30,7 @@ int cmd_type(context_t *context) {
"-h, --help - show this help output\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "w:d:ch",
+ while ((c = getopt_long_only(context->argc, context->argv, "+w:d:ch",
longopts, &option_index)) != -1) {
switch (c) {
case 'w':
View
2 cmd_windowactivate.c
@@ -20,7 +20,7 @@ int cmd_windowactivate(context_t *context) {
"--sync - only exit once the window is active (is visible + active)\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_windowfocus.c
@@ -20,7 +20,7 @@ int cmd_windowfocus(context_t *context) {
"--sync - only exit once the window has focus\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_windowmap.c
@@ -21,7 +21,7 @@ int cmd_windowmap(context_t *context) {
"--sync - only exit once the window has been mapped (is visible)\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_windowmove.c
@@ -33,7 +33,7 @@ int cmd_windowmove(context_t *context) {
"--sync - only exit once the window has moved\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_windowraise.c
@@ -12,7 +12,7 @@ int cmd_windowraise(context_t *context) {
static const char *usage = "Usage: %s window\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_windowsize.c
@@ -27,7 +27,7 @@ int cmd_windowsize(context_t *context) {
"--sync - only exit once the window has resized\n";
- while ((c = getopt_long_only(context->argc, context->argv, "uh",
+ while ((c = getopt_long_only(context->argc, context->argv, "+uh",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 cmd_windowunmap.c
@@ -21,7 +21,7 @@ int cmd_windowunmap(context_t *context) {
"--sync - only exit once the window has been unmapped (is hidden)\n";
int option_index;
- while ((c = getopt_long_only(context->argc, context->argv, "h",
+ while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
View
2 xdotool.c
@@ -332,7 +332,7 @@ int args_main(int argc, char **argv) {
exit(1);
}
- while ((opt = getopt_long_only(argc, argv, "+hv", long_options, &option_index)) != -1) {
+ while ((opt = getopt_long_only(argc, argv, "++hv", long_options, &option_index)) != -1) {
switch (opt) {
case 'h':
cmd_help(NULL);

0 comments on commit 01c3953

Please sign in to comment.