[hackers] [tabbed] Introduce ARG* macros to simplify arg handling. || Christoph Lohmann

From: <hg_AT_suckless.org>
Date: Fri, 6 Apr 2012 20:45:43 +0200 (CEST)

changeset: 155:d0002cc272e8
user: Christoph Lohmann <20h_AT_r-36.net>
date: Fri Apr 06 20:44:47 2012 +0200
files: Makefile tabbed.c
description:
Introduce ARG* macros to simplify arg handling.


diff -r c42dd0b27167 -r d0002cc272e8 Makefile
--- a/Makefile Fri Apr 06 18:45:04 2012 +0200
+++ b/Makefile Fri Apr 06 20:44:47 2012 +0200
_AT_@ -36,7 +36,7 @@
         _AT_echo creating dist tarball
         _AT_mkdir -p tabbed-${VERSION}
         _AT_cp -R LICENSE Makefile README config.def.h config.mk \
- tabbed.1 ${SRC} tabbed-${VERSION}
+ tabbed.1 arg.h ${SRC} tabbed-${VERSION}
         _AT_tar -cf tabbed-${VERSION}.tar tabbed-${VERSION}
         _AT_gzip tabbed-${VERSION}.tar
         _AT_rm -rf tabbed-${VERSION}
diff -r c42dd0b27167 -r d0002cc272e8 tabbed.c
--- a/tabbed.c Fri Apr 06 18:45:04 2012 +0200
+++ b/tabbed.c Fri Apr 06 20:44:47 2012 +0200
_AT_@ -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
_AT_@ -150,6 +152,8 @@
 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"
 
_AT_@ -874,37 +878,22 @@
 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);
Received on Fri Apr 06 2012 - 20:45:43 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 06 2012 - 20:48:06 CEST