ref: 2925d4f6ebe4948542060e4a0b284a2aad020077
parent: 9bfaf452c97c5bcbedd275e9f5a111639e54c3a1
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Jul 15 22:19:26 EDT 2024
separate ARGBEGIN & co into its own file with separate license
--- /dev/null
+++ b/unix/argbegin.h
@@ -1,0 +1,43 @@
+/*
+Copyright © 2021 Plan 9 Foundation
+Copyright © 20XX 9front authors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+*/
+
+static char *argv0;
+#define ARGBEGIN for((argv0? 0: (argv0=*argv)),argv++,argc--;\
+ argv[0] && argv[0][0]=='-' && argv[0][1];\
+ argc--, argv++) {\
+ char *_args, *_argt;\
+ int _argc;\
+ _args = &argv[0][1];\
+ if(_args[0]=='-' && _args[1]==0){\
+ argc--; argv++; break;\
+ }\
+ _argc = 0;\
+ while((_argc = *_args++) != 0)\
+ switch(_argc)
+#define ARGEND (void)_argt; (void)_argc; (void)_args;}(void)argv; (void)argc;
+#define ARGF() (_argt=_args, _args="",\
+ (*_argt? _argt: argv[1]? (argc--, *++argv): 0))
+#define ARGC() _argc
+
+#define EARGF(x) (_argt=_args, _args="",\
+ (*_argt? _argt: argv[1]? (argc--, *++argv): (x, (char*)0)))
--- a/unix/test.c
+++ b/unix/test.c
@@ -6,29 +6,7 @@
#include <string.h>
#include "otf.h"
#include "otfsys.h"
-
-static char *argv0;
-
-#define ARGBEGIN for((argv0? 0: (argv0=*argv)),argv++,argc--;\
- argv[0] && argv[0][0]=='-' && argv[0][1];\
- argc--, argv++) {\
- char *_args, *_argt;\
- int _argc;\
- _args = &argv[0][1];\
- if(_args[0]=='-' && _args[1]==0){\
- argc--; argv++; break;\
- }\
- _argc = 0;\
- while((_argc = *_args++) != 0)\
- switch(_argc)
-#define ARGEND (void)_argt; (void)_argc; (void)_args;}(void)argv; (void)argc;
-#define ARGF() (_argt=_args, _args="",\
- (*_argt? _argt: argv[1]? (argc--, *++argv): 0))
-#define ARGC() _argc
-
-#define EARGF(x) (_argt=_args, _args="",\
- (*_argt? _argt: argv[1]? (argc--, *++argv): (x, (char*)0)))
-
+#include "argbegin.h"
#include "test.h"
static int