1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#pragma once
// ------------------------------------------------------------------------
// standard library
#include <rt.h>
#include <sys.h>
// TODO: remove dependency system headers
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h>
#include <wchar.h>
#include <errno.h>
#include <pwd.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
typedef wchar_t wchar;
/* must be included first */
#include <base/memory.h>
#include <base/string.h>
#include <base/error.h>
#include <base/io.h>
/* no dependencies */
#include <base/fmt.h>
#include <base/utf.h>
#include <base/coro.h>
#include <base/mmap.h>
#include <base/fs.h>
#include <base/flate.h>
#include <base/gz.h>
#include <base/sort.h>
#include <base/rng.h>
// -----------------------------------------------------------------------------
// variable arguments
/* from plan9 libc */
#define ERRMAX 128 /* max length of error string */
#define SET(x) ((x)=0)
#define USED(x) if(x){}else{}
#ifdef __GNUC__
# if __GNUC__ >= 3
# undef USED
# define USED(x) ((void)(x))
# endif
#endif
extern char *argv0;
#define ARGBEGIN for((argv0?0:(argv0=*argv)),argv++,argc--; \
argv[0] && argv[0][0]=='-' && argv[0][1]; \
argc--, argv++) { \
byte *_args, *_argt; \
uint32 _argc; \
_args = &argv[0][1]; \
if(_args[0]=='-' && _args[1]==0){ \
argc--; argv++; break; \
} \
_argc = 0; \
while(*_args && (_args += utf8·decode(_args, &_argc)))\
switch(_argc)
#define ARGEND SET(_argt);USED(_argt);USED(_argc);USED(_args);}USED(argv);USED(argc);
#define ARGF() (_argt=_args, _args="",\
(*_argt? _argt: argv[1]? (argc--, *++argv): 0))
#define EARGF(x) (_argt=_args, _args="",\
(*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0)))
#define ARGC() _argc
|