commit c9aac796c8e932b836e659024821917ef989f749
parent f648c7fa7124d2ee8c4745ce25350404b3c9ba89
Author: Christoph Lohmann <20h@r-36.net>
Date: Wed, 29 May 2013 20:52:39 +0200
Fixing the ARG macros and adding nice.
Thanks "Galos, David" <galosd83@students.rowan.edu>!
Diffstat:
M | Makefile | | | 1 | + |
A | arg.h | | | 55 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | util.h | | | 24 | ++---------------------- |
3 files changed, 58 insertions(+), 22 deletions(-)
diff --git a/Makefile b/Makefile
@@ -41,6 +41,7 @@ SRC = \
mkdir.c \
mkfifo.c \
mv.c \
+ nice.c \
nl.c \
nohup.c \
paste.c \
diff --git a/arg.h b/arg.h
@@ -0,0 +1,55 @@
+/*
+ * Copy me if you can.
+ * by 20h
+ */
+
+#ifndef __ARG_H__
+#define __ARG_H__
+
+extern char *argv0;
+
+#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 (brk = 0, argv[0]++, _argv = argv;\
+ argv[0][0] && !brk;\
+ argv[0]++) {\
+ if (_argv != argv)\
+ break;\
+ _argc = argv[0][0];\
+ switch (_argc)
+
+#define ARGEND }\
+ USED(_argc);\
+ }\
+ USED(argv);\
+ USED(argc);
+
+#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
+
diff --git a/util.h b/util.h
@@ -1,5 +1,7 @@
/* See LICENSE file for copyright and license details. */
+#include "arg.h"
+
#define UTF8_POINT(c) (((c) & 0xc0) != 0x80)
#define MIN(x,y) ((x) < (y) ? (x) : (y))
@@ -7,28 +9,6 @@
#define LEN(x) (sizeof (x) / sizeof *(x))
-#define ARGBEGIN \
- { \
- if(!argv0) \
- argv0 = argv[0]; \
- for(argc--, argv++; argv[0] && argv[0][0] == '-' && argv[0][1] != '\0'; argc--, argv++) { \
- if(argv[0][1] == '-' && argv[0][2] == '\0') { /* -- signifies end of flags */ \
- argc--; argv++; \
- break; \
- } \
- for(argv[0]++; *argv[0] != '\0'; argv[0]++) \
- switch(*argv[0])
-
-#define ARGEND \
- } \
- }
-
-#define ARGC() (*argv[0])
-#define ARGF() (*argv[0] ? argv[0] \
- : argv[1] ? (argc--, *++argv) : NULL)
-#define EARGF(x) (*argv[0] ? argv[0] \
- : argv[1] ? (argc--, *++argv) : ((x), abort(), NULL))
-
extern char *argv0;
char *agetcwd(void);