summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2012-04-06 20:44:47 +0200
committerChristoph Lohmann <20h@r-36.net>2012-04-06 20:44:47 +0200
commitb137773914989ad9e6158f286ff0bb247db4d5ea (patch)
tree5759345b9fa010946eacef93da36f7124b3c2a70
parentc4e4f05fa6e5044cb668cd5db4ffbd933a6469d8 (diff)
Introduce ARG* macros to simplify arg handling.
-rw-r--r--Makefile2
-rw-r--r--tabbed.c51
2 files changed, 21 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index d4bf93a..32cc25b 100644
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ dist: clean
@echo creating dist tarball
@mkdir -p tabbed-${VERSION}
@cp -R LICENSE Makefile README config.def.h config.mk \
- tabbed.1 ${SRC} tabbed-${VERSION}
+ tabbed.1 arg.h ${SRC} tabbed-${VERSION}
@tar -cf tabbed-${VERSION}.tar tabbed-${VERSION}
@gzip tabbed-${VERSION}.tar
@rm -rf tabbed-${VERSION}
diff --git a/tabbed.c b/tabbed.c
index 9fde784..8a42b97 100644
--- a/tabbed.c
+++ b/tabbed.c
@@ -15,6 +15,8 @@
#include <X11/Xproto.h>
#include <X11/Xutil.h>
+#include "arg.h"
+
/* XEMBED messages */
#define XEMBED_EMBEDDED_NOTIFY 0
#define XEMBED_WINDOW_ACTIVATE 1
@@ -150,6 +152,8 @@ static Client *clients = NULL, *sel = NULL, *lastsel = NULL;
static int (*xerrorxlib)(Display *, XErrorEvent *);
static char winid[64];
static char **cmd = NULL;
+
+char *argv0;
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -874,37 +878,22 @@ usage(void)
int
main(int argc, char *argv[]) {
int detach = 0;
- char _argc;
- char **_argv;
-
- for(argv0 = *argv, argv++, argc--;
- argv[0] && argv[0][1] && argv[0][0] == '-';
- argc--, argv++) {
- if(argv[0][1] == '-' && argv[0][2] == '\0') {
- argv++;
- argc--;
- break;
- }
- for(argv[0]++, _argv = argv; argv[0][0]; argv[0]++) {
- if(_argv != argv)
- break;
- _argc = argv[0][0];
- switch(_argc) {
- case 'v':
- die("tabbed-"VERSION", © 2009-2011"
- " tabbed engineers, see LICENSE"
- " for details.\n");
- case 's':
- doinitspawn = False;
- break;
- case 'h':
- usage();
- case 'd':
- detach = 1;
- break;
- }
- }
- }
+
+ ARGBEGIN {
+ case 'v':
+ die("tabbed-"VERSION", © 2009-2011"
+ " tabbed engineers, see LICENSE"
+ " for details.\n");
+ case 's':
+ doinitspawn = False;
+ break;
+ case 'h':
+ usage();
+ case 'd':
+ detach = 1;
+ break;
+ } ARGEND;
+
if(argc < 1)
doinitspawn = False;
setcmd(argc, argv);