[hackers] [tabbed] Adding the form of -r1, which will result in -r 1 in arg.h. || Christoph Lohmann

From: <hg_AT_suckless.org>
Date: Tue, 27 Nov 2012 21:19:06 +0100 (CET)

changeset: 184:53d8e35b337a
tag: tip
user: Christoph Lohmann <20h_AT_r-36.net>
date: Tue Nov 27 21:17:10 2012 +0100
files: arg.h
description:
Adding the form of -r1, which will result in -r 1 in arg.h.


diff -r 56523f87e30c -r 53d8e35b337a arg.h
--- a/arg.h Tue Nov 27 20:25:56 2012 +0100
+++ b/arg.h Tue Nov 27 21:17:10 2012 +0100
_AT_@ -1,26 +1,30 @@
 /*
- * See LICENSE file for copyright and license details.
+ * Copy me if you can.
+ * by 20h
  */
 
-#ifndef __CMD_H__
-#define __CMD_H__
+#ifndef __ARG_H__
+#define __ARG_H__
 
 extern char *argv0;
 
-#define USED(x) ((void)(x))
+#define USED(x) ((void)(x))
 
+/* use main(int argc, char *argv[]) */
 #define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
                                         argv[0] && argv[0][1]\
                                         && argv[0][0] == '-';\
                                         argc--, argv++) {\
                                 char _argc;\
                                 char **_argv;\
+ int brk;\
                                 if (argv[0][1] == '-' && argv[0][2] == '\0') {\
                                         argv++;\
                                         argc--;\
                                         break;\
                                 }\
- for (argv[0]++, _argv = argv; argv[0][0];\
+ for (brk = 0, argv[0]++, _argv = argv;\
+ argv[0][0] && !brk;\
                                                 argv[0]++) {\
                                         if (_argv != argv)\
                                                 break;\
_AT_@ -33,8 +37,19 @@
                         USED(argv);\
                         USED(argc);
 
-#define EARGF(x) ((argv[1] == NULL)? ((x), abort(), (char *)0) :\
- (argc--, argv++, argv[0]))
+#define ARGC() _argc
+
+#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
+ ((x), abort(), (char *)0) :\
+ (brk = 1, (argv[0][1] != '\0')?\
+ (&argv[0][1]) :\
+ (argc--, argv++, argv[0])))
+
+#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
+ (char *)0 :\
+ (brk = 1, (argv[0][1] != '\0')?\
+ (&argv[0][1]) :\
+ (argc--, argv++, argv[0])))
 
 #endif
 
Received on Tue Nov 27 2012 - 21:19:06 CET

This archive was generated by hypermail 2.3.0 : Tue Nov 27 2012 - 21:24:06 CET