Introduce ARG* macros to simplify arg handling.

This commit is contained in:
Christoph Lohmann 2012-04-06 20:44:47 +02:00
parent c4e4f05fa6
commit b137773914
2 changed files with 20 additions and 31 deletions

View File

@ -36,7 +36,7 @@ dist: clean
@echo creating dist tarball @echo creating dist tarball
@mkdir -p tabbed-${VERSION} @mkdir -p tabbed-${VERSION}
@cp -R LICENSE Makefile README config.def.h config.mk \ @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} @tar -cf tabbed-${VERSION}.tar tabbed-${VERSION}
@gzip tabbed-${VERSION}.tar @gzip tabbed-${VERSION}.tar
@rm -rf tabbed-${VERSION} @rm -rf tabbed-${VERSION}

View File

@ -15,6 +15,8 @@
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include "arg.h"
/* XEMBED messages */ /* XEMBED messages */
#define XEMBED_EMBEDDED_NOTIFY 0 #define XEMBED_EMBEDDED_NOTIFY 0
#define XEMBED_WINDOW_ACTIVATE 1 #define XEMBED_WINDOW_ACTIVATE 1
@ -150,6 +152,8 @@ static Client *clients = NULL, *sel = NULL, *lastsel = NULL;
static int (*xerrorxlib)(Display *, XErrorEvent *); static int (*xerrorxlib)(Display *, XErrorEvent *);
static char winid[64]; static char winid[64];
static char **cmd = NULL; static char **cmd = NULL;
char *argv0;
/* configuration, allows nested code to access above variables */ /* configuration, allows nested code to access above variables */
#include "config.h" #include "config.h"
@ -874,37 +878,22 @@ usage(void)
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
int detach = 0; int detach = 0;
char _argc;
char **_argv;
for(argv0 = *argv, argv++, argc--; ARGBEGIN {
argv[0] && argv[0][1] && argv[0][0] == '-'; case 'v':
argc--, argv++) { die("tabbed-"VERSION", © 2009-2011"
if(argv[0][1] == '-' && argv[0][2] == '\0') { " tabbed engineers, see LICENSE"
argv++; " for details.\n");
argc--; case 's':
break; doinitspawn = False;
} break;
for(argv[0]++, _argv = argv; argv[0][0]; argv[0]++) { case 'h':
if(_argv != argv) usage();
break; case 'd':
_argc = argv[0][0]; detach = 1;
switch(_argc) { break;
case 'v': } ARGEND;
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;
}
}
}
if(argc < 1) if(argc < 1)
doinitspawn = False; doinitspawn = False;
setcmd(argc, argv); setcmd(argc, argv);