From df2b3bcf44299d7060b3bc6c17c6e80a1f358692 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 25 Sep 2008 23:28:15 +0000 Subject: [PATCH] Fix stupid GNU getopt behaviour. --- GNUmakefile | 7 ++++++- cmd-bind-key.c | 4 ++-- cmd-generic.c | 8 ++++---- cmd-new-session.c | 4 ++-- cmd-new-window.c | 4 ++-- cmd-send-keys.c | 4 ++-- cmd-set-option.c | 4 ++-- cmd-set-window-option.c | 4 ++-- cmd-show-options.c | 4 ++-- cmd-switch-client.c | 4 ++-- cmd-unbind-key.c | 4 ++-- cmd.c | 4 ++-- tmux.c | 4 ++-- tmux.h | 6 +++++- 14 files changed, 37 insertions(+), 28 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index b0e9dad3..d478fdbe 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.40 2008-09-25 20:08:51 nicm Exp $ +# $Id: GNUmakefile,v 1.41 2008-09-25 23:28:12 nicm Exp $ .PHONY: clean @@ -91,6 +91,11 @@ SRCS+= compat/strlcpy.c compat/strlcat.c compat/strtonum.c compat/fgetln.c CFLAGS+= $(shell getconf LFS_CFLAGS) -D_GNU_SOURCE \ -DNO_STRLCPY -DNO_STRLCAT -DNO_STRTONUM -DNO_SETPROCTITLE \ -DNO_QUEUE_H -DNO_TREE_H -DUSE_PTY_H -DNO_FGETLN -std=c99 + +# GNU, as usual, decided on the insance default. So their stupid extensions +# are default and POSIX-compliance is optional (!). +CFLAGS+= -DGETOPT_PREFIX="\"+\"" + LIBS+= -lrt -lutil endif diff --git a/cmd-bind-key.c b/cmd-bind-key.c index 52587bb0..25a60e86 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -1,4 +1,4 @@ -/* $Id: cmd-bind-key.c,v 1.15 2008-06-05 21:54:47 nicm Exp $ */ +/* $Id: cmd-bind-key.c,v 1.16 2008-09-25 23:28:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -60,7 +60,7 @@ cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause) self->data = data = xmalloc(sizeof *data); data->cmd = NULL; - while ((opt = getopt(argc, argv, "")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "")) != EOF) { switch (opt) { default: goto usage; diff --git a/cmd-generic.c b/cmd-generic.c index 49bb14b2..f1322d1c 100644 --- a/cmd-generic.c +++ b/cmd-generic.c @@ -1,4 +1,4 @@ -/* $Id: cmd-generic.c,v 1.12 2008-06-29 07:04:30 nicm Exp $ */ +/* $Id: cmd-generic.c,v 1.13 2008-09-25 23:28:12 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -44,7 +44,7 @@ cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause) cmd_target_init(self, 0); data = self->data; - while ((opt = getopt(argc, argv, "dkt:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "dkt:")) != EOF) { switch (opt) { case 'd': if (self->entry->flags & CMD_DFLAG) { @@ -166,7 +166,7 @@ cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause) cmd_srcdst_init(self, 0); data = self->data; - while ((opt = getopt(argc, argv, "dks:t:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "dks:t:")) != EOF) { switch (opt) { case 'd': if (self->entry->flags & CMD_DFLAG) { @@ -299,7 +299,7 @@ cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause) cmd_buffer_init(self, 0); data = self->data; - while ((opt = getopt(argc, argv, "b:dkt:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "b:dkt:")) != EOF) { switch (opt) { case 'b': if (data->buffer == -1) { diff --git a/cmd-new-session.c b/cmd-new-session.c index 2671b495..626854ff 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-session.c,v 1.30 2008-06-21 10:19:36 nicm Exp $ */ +/* $Id: cmd-new-session.c,v 1.31 2008-09-25 23:28:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -75,7 +75,7 @@ cmd_new_session_parse(struct cmd *self, int argc, char **argv, char **cause) self->entry->init(self, 0); data = self->data; - while ((opt = getopt(argc, argv, "ds:n:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "ds:n:")) != EOF) { switch (opt) { case 'd': data->flag_detached = 1; diff --git a/cmd-new-window.c b/cmd-new-window.c index d139e94f..b1642626 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-window.c,v 1.24 2008-06-18 16:39:15 nicm Exp $ */ +/* $Id: cmd-new-window.c,v 1.25 2008-09-25 23:28:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -76,7 +76,7 @@ cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause) self->entry->init(self, 0); data = self->data; - while ((opt = getopt(argc, argv, "dt:n:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "dt:n:")) != EOF) { switch (opt) { case 'd': data->flag_detached = 1; diff --git a/cmd-send-keys.c b/cmd-send-keys.c index 3f6c2688..d26ec520 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -1,4 +1,4 @@ -/* $Id: cmd-send-keys.c,v 1.13 2008-06-20 17:31:48 nicm Exp $ */ +/* $Id: cmd-send-keys.c,v 1.14 2008-09-25 23:28:12 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -67,7 +67,7 @@ cmd_send_keys_parse(struct cmd *self, int argc, char **argv, char **cause) data->nkeys = 0; data->keys = NULL; - while ((opt = getopt(argc, argv, "t:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "t:")) != EOF) { switch (opt) { case 't': if (data->target == NULL) diff --git a/cmd-set-option.c b/cmd-set-option.c index 8f6a488d..44438d8f 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.41 2008-09-10 18:59:29 nicm Exp $ */ +/* $Id: cmd-set-option.c,v 1.42 2008-09-25 23:28:12 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -104,7 +104,7 @@ cmd_set_option_parse(struct cmd *self, int argc, char **argv, char **cause) data->option = NULL; data->value = NULL; - while ((opt = getopt(argc, argv, "t:s:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "t:s:")) != EOF) { switch (opt) { case 't': if (data->target == NULL) diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c index d7742b91..018d0809 100644 --- a/cmd-set-window-option.c +++ b/cmd-set-window-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-window-option.c,v 1.11 2008-06-29 07:04:30 nicm Exp $ */ +/* $Id: cmd-set-window-option.c,v 1.12 2008-09-25 23:28:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -66,7 +66,7 @@ cmd_set_window_option_parse( data->option = NULL; data->value = NULL; - while ((opt = getopt(argc, argv, "t:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "t:")) != EOF) { switch (opt) { case 't': if (data->target == NULL) diff --git a/cmd-show-options.c b/cmd-show-options.c index d1f5f559..c7ed643d 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -1,4 +1,4 @@ -/* $Id: cmd-show-options.c,v 1.6 2008-09-10 18:59:29 nicm Exp $ */ +/* $Id: cmd-show-options.c,v 1.7 2008-09-25 23:28:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -67,7 +67,7 @@ cmd_show_options_parse(struct cmd *self, int argc, char **argv, char **cause) data->target = NULL; data->flag_global = 1; - while ((opt = getopt(argc, argv, "t:s:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "t:s:")) != EOF) { switch (opt) { case 't': if (data->target == NULL) diff --git a/cmd-switch-client.c b/cmd-switch-client.c index 3a458746..bc5c9682 100644 --- a/cmd-switch-client.c +++ b/cmd-switch-client.c @@ -1,4 +1,4 @@ -/* $Id: cmd-switch-client.c,v 1.11 2008-06-23 22:26:52 nicm Exp $ */ +/* $Id: cmd-switch-client.c,v 1.12 2008-09-25 23:28:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -63,7 +63,7 @@ cmd_switch_client_parse(struct cmd *self, int argc, char **argv, char **cause) data->name = NULL; data->target = NULL; - while ((opt = getopt(argc, argv, "c:t:")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "c:t:")) != EOF) { switch (opt) { case 'c': data->name = xstrdup(optarg); diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c index 0ee85fea..c5074a77 100644 --- a/cmd-unbind-key.c +++ b/cmd-unbind-key.c @@ -1,4 +1,4 @@ -/* $Id: cmd-unbind-key.c,v 1.13 2008-06-05 21:25:00 nicm Exp $ */ +/* $Id: cmd-unbind-key.c,v 1.14 2008-09-25 23:28:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -57,7 +57,7 @@ cmd_unbind_key_parse(struct cmd *self, int argc, char **argv, char **cause) self->data = data = xmalloc(sizeof *data); - while ((opt = getopt(argc, argv, "")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "")) != EOF) { switch (opt) { default: goto usage; diff --git a/cmd.c b/cmd.c index 0b378e14..fbbd0112 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.63 2008-08-28 17:45:25 nicm Exp $ */ +/* $Id: cmd.c,v 1.64 2008-09-25 23:28:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -162,7 +162,7 @@ cmd_parse(int argc, char **argv, char **cause) optind = 1; if (entry->parse == NULL) { - while ((opt = getopt(argc, argv, "")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "")) != EOF) { switch (opt) { default: goto usage; diff --git a/tmux.c b/tmux.c index bf52e2ea..669fd3c9 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.76 2008-09-25 20:08:56 nicm Exp $ */ +/* $Id: tmux.c,v 1.77 2008-09-25 23:28:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -179,7 +179,7 @@ main(int argc, char **argv) flags = 0; path = NULL; - while ((opt = getopt(argc, argv, "2df:qS:uVv")) != EOF) { + while ((opt = getopt(argc, argv, GETOPT_PREFIX "2df:qS:uVv")) != EOF) { switch (opt) { case '2': flags |= IDENTIFY_256COLOURS; diff --git a/tmux.h b/tmux.h index d74b9e00..440c3a88 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.189 2008-09-25 20:08:56 nicm Exp $ */ +/* $Id: tmux.h,v 1.190 2008-09-25 23:28:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -58,6 +58,10 @@ extern const char *__progname; +#ifndef GETOPT_PREFIX +#define GETOPT_PREFIX "" +#endif + #ifndef INFTIM #define INFTIM -1 #endif