summaryrefslogtreecommitdiff
path: root/src/skaembutils
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-02-10 20:12:16 +0000
committerLaurent Bercot <ska@appnovation.com>2023-02-10 20:12:16 +0000
commit790c8681d3451b61a536871dad234fc294796fd8 (patch)
treea75384fa450410cb339d50439b4c522568138688 /src/skaembutils
parentcf07a7b62346c8b5ab8e1c0714590f6566c411fe (diff)
downloads6-portable-utils-790c8681d3451b61a536871dad234fc294796fd8.tar.xz
Clean up all the code
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/skaembutils')
-rw-r--r--src/skaembutils/deps-exe/s6-test1
-rw-r--r--src/skaembutils/s6-basename.c1
-rw-r--r--src/skaembutils/s6-chmod.c1
-rw-r--r--src/skaembutils/s6-chown.c1
-rw-r--r--src/skaembutils/s6-clock.c6
-rw-r--r--src/skaembutils/s6-cut.c14
-rw-r--r--src/skaembutils/s6-dirname.c1
-rw-r--r--src/skaembutils/s6-expr.c66
-rw-r--r--src/skaembutils/s6-format-filter.c1
-rw-r--r--src/skaembutils/s6-grep.c16
-rw-r--r--src/skaembutils/s6-head.c14
-rw-r--r--src/skaembutils/s6-hiercopy.c1
-rw-r--r--src/skaembutils/s6-linkname.c1
-rw-r--r--src/skaembutils/s6-ln.c10
-rw-r--r--src/skaembutils/s6-ls.c1
-rw-r--r--src/skaembutils/s6-maximumtime.c1
-rw-r--r--src/skaembutils/s6-mkdir.c13
-rw-r--r--src/skaembutils/s6-mkfifo.c1
-rw-r--r--src/skaembutils/s6-nuke.c1
-rw-r--r--src/skaembutils/s6-pause.c18
-rw-r--r--src/skaembutils/s6-printenv.c1
-rw-r--r--src/skaembutils/s6-quote-filter.c1
-rw-r--r--src/skaembutils/s6-quote.c1
-rw-r--r--src/skaembutils/s6-rename.c1
-rw-r--r--src/skaembutils/s6-seq.c1
-rw-r--r--src/skaembutils/s6-sort.c59
-rw-r--r--src/skaembutils/s6-tail.c24
-rw-r--r--src/skaembutils/s6-test.c538
-rw-r--r--src/skaembutils/s6-unquote-filter.c22
-rw-r--r--src/skaembutils/s6-unquote.c1
-rw-r--r--src/skaembutils/s6-update-symlinks.c51
-rw-r--r--src/skaembutils/seekablepipe.c2
32 files changed, 176 insertions, 695 deletions
diff --git a/src/skaembutils/deps-exe/s6-test b/src/skaembutils/deps-exe/s6-test
deleted file mode 100644
index e7187fe..0000000
--- a/src/skaembutils/deps-exe/s6-test
+++ /dev/null
@@ -1 +0,0 @@
--lskarnet
diff --git a/src/skaembutils/s6-basename.c b/src/skaembutils/s6-basename.c
index aca585c..9e00763 100644
--- a/src/skaembutils/s6-basename.c
+++ b/src/skaembutils/s6-basename.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/strerr.h>
diff --git a/src/skaembutils/s6-chmod.c b/src/skaembutils/s6-chmod.c
index 90500b0..946a318 100644
--- a/src/skaembutils/s6-chmod.c
+++ b/src/skaembutils/s6-chmod.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <sys/stat.h>
+
#include <skalibs/types.h>
#include <skalibs/strerr.h>
diff --git a/src/skaembutils/s6-chown.c b/src/skaembutils/s6-chown.c
index 33d6e20..77cd94b 100644
--- a/src/skaembutils/s6-chown.c
+++ b/src/skaembutils/s6-chown.c
@@ -2,6 +2,7 @@
#include <unistd.h>
#include <stdlib.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/types.h>
#include <skalibs/strerr.h>
diff --git a/src/skaembutils/s6-clock.c b/src/skaembutils/s6-clock.c
index 20f943a..5a9e67a 100644
--- a/src/skaembutils/s6-clock.c
+++ b/src/skaembutils/s6-clock.c
@@ -6,7 +6,7 @@
#define USAGE "s6-clock [ tai64nlabel ]"
-static int getit (void)
+static int s6clock_getit (void)
{
char fmt[TIMESTAMP+1] ;
timestamp(fmt) ;
@@ -16,7 +16,7 @@ static int getit (void)
return 0 ;
}
-static int setit (char const *h)
+static int s6clock_setit (char const *h)
{
tain a ;
if (!timestamp_scan(h, &a)) strerr_dieusage(100, USAGE) ;
@@ -27,5 +27,5 @@ static int setit (char const *h)
int main (int argc, char const *const *argv)
{
PROG = "s6-clock" ;
- return (argc < 2) ? getit() : setit(argv[1]) ;
+ return (argc < 2) ? s6clock_getit() : s6clock_setit(argv[1]) ;
}
diff --git a/src/skaembutils/s6-cut.c b/src/skaembutils/s6-cut.c
index d111ecd..e55907b 100644
--- a/src/skaembutils/s6-cut.c
+++ b/src/skaembutils/s6-cut.c
@@ -34,7 +34,7 @@ static void disizealloc_normalize (genalloc *list)
genalloc_setlen(disize, list, cur+1) ;
}
-static void scanlist (genalloc *list, char const *s)
+static void s6cut_scanlist (genalloc *list, char const *s)
{
size_t i = 0 ;
genalloc_setlen(disize, list, 0) ;
@@ -72,7 +72,7 @@ static void scanlist (genalloc *list, char const *s)
}
}
-static int doit (int fd, disize const *s, size_t len, unsigned int flags, char delim)
+static int s6cut_doit (int fd, disize const *s, size_t len, unsigned int flags, char delim)
{
char buf[BUFFER_INSIZE] ;
buffer b = BUFFER_INIT(&buffer_flush1read, fd, buf, BUFFER_INSIZE) ;
@@ -164,14 +164,14 @@ int main (int argc, char const *const *argv)
{
if (what) strerr_dieusage(100, USAGE) ;
what = 2 ;
- scanlist(&list, l.arg) ;
+ s6cut_scanlist(&list, l.arg) ;
break ;
}
case 'f':
{
if (what) strerr_dieusage(100, USAGE) ;
what = 4 ;
- scanlist(&list, l.arg) ;
+ s6cut_scanlist(&list, l.arg) ;
break ;
}
default : strerr_dieusage(100, USAGE) ;
@@ -185,7 +185,7 @@ int main (int argc, char const *const *argv)
if (!argc)
{
- if (!doit(0, genalloc_s(disize, &list), genalloc_len(disize, &list), what, delim))
+ if (!s6cut_doit(0, genalloc_s(disize, &list), genalloc_len(disize, &list), what, delim))
strerr_diefu1sys(111, "cut stdin") ;
}
else
@@ -194,7 +194,7 @@ int main (int argc, char const *const *argv)
{
if ((argv[0][0] == '-') && !argv[0][1])
{
- if (!doit(0, genalloc_s(disize, &list), genalloc_len(disize, &list), what, delim))
+ if (!s6cut_doit(0, genalloc_s(disize, &list), genalloc_len(disize, &list), what, delim))
strerr_diefu1sys(111, "process stdin") ;
}
else
@@ -202,7 +202,7 @@ int main (int argc, char const *const *argv)
int fd = open_readb(*argv) ;
if (fd == -1)
strerr_diefu3sys(111, "open ", *argv, " for reading") ;
- if (!doit(fd, genalloc_s(disize, &list), genalloc_len(disize, &list), what, delim))
+ if (!s6cut_doit(fd, genalloc_s(disize, &list), genalloc_len(disize, &list), what, delim))
strerr_diefu2sys(111, "cut ", *argv) ;
fd_close(fd) ;
}
diff --git a/src/skaembutils/s6-dirname.c b/src/skaembutils/s6-dirname.c
index e76f4cc..83782ac 100644
--- a/src/skaembutils/s6-dirname.c
+++ b/src/skaembutils/s6-dirname.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/strerr.h>
diff --git a/src/skaembutils/s6-expr.c b/src/skaembutils/s6-expr.c
index ac5321b..91be041 100644
--- a/src/skaembutils/s6-expr.c
+++ b/src/skaembutils/s6-expr.c
@@ -8,7 +8,7 @@
#define USAGE "s6-expr arithmetic expression"
#define bail() strerr_dief1x(2, "invalid expression")
-enum opnum
+enum expr_opnum_e
{
T_DATA,
T_AND,
@@ -28,25 +28,25 @@ enum opnum
T_MOD
} ;
-struct token
+struct expr_token_s
{
char const *string ;
- enum opnum op ;
+ enum expr_opnum_e op ;
unsigned int type ;
} ;
-struct node
+struct expr_node_s
{
- enum opnum op ;
+ enum expr_opnum_e op ;
unsigned int type ;
unsigned int arg1 ;
unsigned int arg2 ;
long data ;
} ;
-static unsigned int lex (struct node *tree, char const *const *argv)
+static unsigned int expr_lex (struct expr_node_s *tree, char const *const *argv)
{
- static struct token const tokens[16] =
+ static struct expr_token_s const tokens[16] =
{
{ "+", T_PLUS, 3 },
{ "-", T_MINUS, 3 },
@@ -87,7 +87,7 @@ static unsigned int lex (struct node *tree, char const *const *argv)
return pos ;
}
-static void reduce (struct node *tree, unsigned int *stack, unsigned int *sp, unsigned int type)
+static void expr_reduce (struct expr_node_s *tree, unsigned int *stack, unsigned int *sp, unsigned int type)
{
if (tree[stack[*sp-1]].type == type)
{
@@ -99,7 +99,7 @@ static void reduce (struct node *tree, unsigned int *stack, unsigned int *sp, un
tree[stack[*sp]].type = type + 7 ;
}
-static unsigned int parse (struct node *tree, unsigned int n)
+static unsigned int expr_parse (struct expr_node_s *tree, unsigned int n)
{
static char const table[9][15] =
{
@@ -130,11 +130,11 @@ static unsigned int parse (struct node *tree, unsigned int n)
if (tree[stack[sp-2]].type != 7) bail() ;
stack[sp-2] = stack[sp-1] ;
sp -= 2 ;
- case 'm' : reduce(tree, stack, &sp, 2) ; break ;
- case 'a' : reduce(tree, stack, &sp, 3) ; break ;
- case 'c' : reduce(tree, stack, &sp, 4) ; break ;
- case 'A' : reduce(tree, stack, &sp, 5) ; break ;
- case 'O' : reduce(tree, stack, &sp, 6) ; break ;
+ case 'm' : expr_reduce(tree, stack, &sp, 2) ; break ;
+ case 'a' : expr_reduce(tree, stack, &sp, 3) ; break ;
+ case 'c' : expr_reduce(tree, stack, &sp, 4) ; break ;
+ case 'A' : expr_reduce(tree, stack, &sp, 5) ; break ;
+ case 'O' : expr_reduce(tree, stack, &sp, 6) ; break ;
case 'E' : tree[stack[sp]].type = 14 ; break ;
case 'z' :
default : strerr_dief1x(101, "internal error in parse, please submit a bug-report.") ; /* can't happen */
@@ -144,7 +144,7 @@ static unsigned int parse (struct node *tree, unsigned int n)
return stack[1] ;
}
-static long run (struct node const *tree, unsigned int root)
+static long expr_run (struct expr_node_s const *tree, unsigned int root)
{
switch (tree[root].op)
{
@@ -152,37 +152,37 @@ static long run (struct node const *tree, unsigned int root)
return tree[root].data ;
case T_OR :
{
- long r = run(tree, tree[root].arg1) ;
- return r ? r : run(tree, tree[root].arg2) ;
+ long r = expr_run(tree, tree[root].arg1) ;
+ return r ? r : expr_run(tree, tree[root].arg2) ;
}
case T_AND :
{
- long r = run(tree, tree[root].arg1) ;
- return r ? run(tree, tree[root].arg2) ? r : 0 : 0 ;
+ long r = expr_run(tree, tree[root].arg1) ;
+ return r ? expr_run(tree, tree[root].arg2) ? r : 0 : 0 ;
}
case T_EQUAL :
- return run(tree, tree[root].arg1) == run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) == expr_run(tree, tree[root].arg2) ;
case T_NEQUAL :
- return run(tree, tree[root].arg1) != run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) != expr_run(tree, tree[root].arg2) ;
case T_GREATER :
- return run(tree, tree[root].arg1) > run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) > expr_run(tree, tree[root].arg2) ;
case T_GREATERE :
- return run(tree, tree[root].arg1) >= run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) >= expr_run(tree, tree[root].arg2) ;
case T_LESSER :
- return run(tree, tree[root].arg1) < run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) < expr_run(tree, tree[root].arg2) ;
case T_LESSERE :
- return run(tree, tree[root].arg1) <= run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) <= expr_run(tree, tree[root].arg2) ;
case T_PLUS :
- return run(tree, tree[root].arg1) + run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) + expr_run(tree, tree[root].arg2) ;
case T_MINUS :
- return run(tree, tree[root].arg1) - run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) - expr_run(tree, tree[root].arg2) ;
case T_TIMES :
- return run(tree, tree[root].arg1) * run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) * expr_run(tree, tree[root].arg2) ;
case T_DIV :
- return run(tree, tree[root].arg1) / run(tree, tree[root].arg2) ;
+ return expr_run(tree, tree[root].arg1) / expr_run(tree, tree[root].arg2) ;
case T_MOD :
- return run(tree, tree[root].arg1) % run(tree, tree[root].arg2) ;
- default : strerr_dief1x(101, "internal error in run, please submit a bug-report") ;
+ return expr_run(tree, tree[root].arg1) % expr_run(tree, tree[root].arg2) ;
+ default : strerr_dief1x(101, "internal error in expr_run, please submit a bug-report") ;
}
}
@@ -194,8 +194,8 @@ int main (int argc, char const *const *argv)
PROG = "s6-expr" ;
if (argc <= 1) return 2 ;
{
- struct node tree[argc + 1] ;
- val = run(tree, parse(tree, lex(tree, argv+1))) ;
+ struct expr_node_s tree[argc + 1] ;
+ val = expr_run(tree, expr_parse(tree, expr_lex(tree, argv+1))) ;
}
len = long_fmt(fmt, val) ;
fmt[len++] = '\n' ;
diff --git a/src/skaembutils/s6-format-filter.c b/src/skaembutils/s6-format-filter.c
index 3d02fc1..57b2869 100644
--- a/src/skaembutils/s6-format-filter.c
+++ b/src/skaembutils/s6-format-filter.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <errno.h>
+
#include <skalibs/strerr.h>
#include <skalibs/buffer.h>
#include <skalibs/stralloc.h>
diff --git a/src/skaembutils/s6-grep.c b/src/skaembutils/s6-grep.c
index 3529977..ebfa064 100644
--- a/src/skaembutils/s6-grep.c
+++ b/src/skaembutils/s6-grep.c
@@ -17,8 +17,8 @@
#define USAGE "s6-grep [ -E | -F ] [ -i ] [ -c ] [ -n ] [ -q ] [ -v ] pattern"
#define dieusage() strerr_dieusage(100, USAGE)
-typedef struct flags_s flags_t, *flags_t_ref ;
-struct flags_s
+typedef struct grep_flags_s grep_flags_t, *grep_flags_t_ref ;
+struct grep_flags_s
{
unsigned int extended : 1 ;
unsigned int ignorecase: 1 ;
@@ -28,9 +28,9 @@ struct flags_s
unsigned int quiet : 1 ;
unsigned int not : 1 ;
} ;
-#define FLAGS_ZERO { .extended = 0, .ignorecase = 0, .fixed = 0, .count = 0, .num = 0, .quiet = 0, .not = 0 }
+#define GREP_FLAGS_ZERO { .extended = 0, .ignorecase = 0, .fixed = 0, .count = 0, .num = 0, .quiet = 0, .not = 0 }
-static void xout (char const *s, size_t len)
+static void grep_xout (char const *s, size_t len)
{
if (buffer_put(buffer_1, s, len) < 0)
strerr_diefu1sys(111, "write to stdout") ;
@@ -39,7 +39,7 @@ static void xout (char const *s, size_t len)
int main (int argc, char const *const *argv)
{
unsigned int count = 0 ;
- flags_t flags = FLAGS_ZERO ;
+ grep_flags_t flags = GREP_FLAGS_ZERO ;
PROG = "s6-grep" ;
{
subgetopt l = SUBGETOPT_ZERO ;
@@ -118,9 +118,9 @@ int main (int argc, char const *const *argv)
char fmt[UINT_FMT] ;
size_t n = uint_fmt(fmt, num) ;
fmt[n++] = ':' ;
- xout(fmt, n) ;
+ grep_xout(fmt, n) ;
}
- xout(line.s, line.len) ;
+ grep_xout(line.s, line.len) ;
}
}
}
@@ -133,7 +133,7 @@ int main (int argc, char const *const *argv)
char fmt[UINT_FMT] ;
size_t n = uint_fmt(fmt, count) ;
fmt[n++] = '\n' ;
- xout(fmt, n) ;
+ grep_xout(fmt, n) ;
}
return !count ;
}
diff --git a/src/skaembutils/s6-head.c b/src/skaembutils/s6-head.c
index a8eebf3..de7d937 100644
--- a/src/skaembutils/s6-head.c
+++ b/src/skaembutils/s6-head.c
@@ -16,10 +16,10 @@
#define USAGE "s6-head [ -S ] [ -1..9 | -n lines | -c chars ] [ file... ]"
#define dieusage() strerr_dieusage(100, USAGE)
-typedef int hea$1_func (int, size_t) ;
-typedef hea$1_func *hea$1_func_ref ;
+typedef int head_func (int, size_t) ;
+typedef head_func *head_func_ref ;
-static int dolines (int fd, size_t lines)
+static int head_dolines (int fd, size_t lines)
{
char buf[BUFFER_INSIZE] ;
buffer in = BUFFER_INIT(&buffer_read, fd, buf, BUFFER_INSIZE) ;
@@ -56,7 +56,7 @@ static int dolines (int fd, size_t lines)
return 1 ;
}
-static int safedolines (int fd, size_t lines)
+static int head_safedolines (int fd, size_t lines)
{
char tmp[lines] ;
while (lines)
@@ -72,14 +72,14 @@ static int safedolines (int fd, size_t lines)
return 1 ;
}
-static int safedochars (int fd, size_t chars)
+static int head_safedochars (int fd, size_t chars)
{
return (fd_catn(fd, 1, chars) >= chars) ;
}
int main (int argc, char const *const *argv)
{
- hea$1_func_ref f ;
+ head_func_ref f ;
unsigned int lines = 10 ;
int islines = 1, safe = 0 ;
PROG = "s6-head" ;
@@ -131,7 +131,7 @@ int main (int argc, char const *const *argv)
argc -= l.ind ; argv += l.ind ;
}
if (argc) safe = 0 ;
- f = islines ? safe ? &safedolines : &dolines : &safedochars ;
+ f = islines ? safe ? &head_safedolines : &head_dolines : &head_safedochars ;
if (!argc)
{
if (!(*f)(0, lines))
diff --git a/src/skaembutils/s6-hiercopy.c b/src/skaembutils/s6-hiercopy.c
index f9cb8e5..a57dd69 100644
--- a/src/skaembutils/s6-hiercopy.c
+++ b/src/skaembutils/s6-hiercopy.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <sys/stat.h>
+
#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
diff --git a/src/skaembutils/s6-linkname.c b/src/skaembutils/s6-linkname.c
index 8d0865a..8471ac4 100644
--- a/src/skaembutils/s6-linkname.c
+++ b/src/skaembutils/s6-linkname.c
@@ -39,6 +39,5 @@ int main (int argc, char const *const *argv)
|| (!buffer_flush(buffer_1small)))
strerr_diefu1sys(111, "write to stdout") ;
- /* stralloc_free(&sa) ; */
return 0 ;
}
diff --git a/src/skaembutils/s6-ln.c b/src/skaembutils/s6-ln.c
index f4ce8b4..b33562f 100644
--- a/src/skaembutils/s6-ln.c
+++ b/src/skaembutils/s6-ln.c
@@ -42,7 +42,7 @@ static int linkderef (char const *old, char const *new)
#endif
-static int doit (char const *old, char const *new, link_func_ref mylink, int force)
+static int ln_doit (char const *old, char const *new, link_func_ref mylink, int force)
{
if ((*mylink)(old, new) == -1)
{
@@ -123,7 +123,7 @@ int main (int argc, char const *const *argv)
e++ ;
continue ;
}
- e += doit(argv[i], sa.s, mylink, force) ;
+ e += ln_doit(argv[i], sa.s, mylink, force) ;
}
return e ;
}
@@ -133,10 +133,10 @@ int main (int argc, char const *const *argv)
if (nodir ? lstat(argv[1], &st) : stat(argv[1], &st) < 0)
{
if (errno != ENOENT) strerr_diefu2sys(111, "stat ", argv[1]) ;
- return doit(argv[0], argv[1], mylink, force) ;
+ return ln_doit(argv[0], argv[1], mylink, force) ;
}
if (!S_ISDIR(st.st_mode))
- return doit(argv[0], argv[1], mylink, force) ;
+ return ln_doit(argv[0], argv[1], mylink, force) ;
}
{
@@ -146,6 +146,6 @@ int main (int argc, char const *const *argv)
|| !sabasename(&sa, argv[0], strlen(argv[0]))
|| !stralloc_0(&sa))
strerr_diefu1sys(111, "stralloc_catb") ;
- return doit(argv[0], sa.s, mylink, force) ;
+ return ln_doit(argv[0], sa.s, mylink, force) ;
}
}
diff --git a/src/skaembutils/s6-ls.c b/src/skaembutils/s6-ls.c
index f6410bd..b426da7 100644
--- a/src/skaembutils/s6-ls.c
+++ b/src/skaembutils/s6-ls.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/direntry.h>
#include <skalibs/buffer.h>
diff --git a/src/skaembutils/s6-maximumtime.c b/src/skaembutils/s6-maximumtime.c
index 6b2621c..4da7e89 100644
--- a/src/skaembutils/s6-maximumtime.c
+++ b/src/skaembutils/s6-maximumtime.c
@@ -4,6 +4,7 @@
#include <signal.h>
#include <errno.h>
#include <unistd.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/types.h>
#include <skalibs/error.h>
diff --git a/src/skaembutils/s6-mkdir.c b/src/skaembutils/s6-mkdir.c
index 3985b5a..8212813 100644
--- a/src/skaembutils/s6-mkdir.c
+++ b/src/skaembutils/s6-mkdir.c
@@ -4,6 +4,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/types.h>
#include <skalibs/buffer.h>
@@ -12,7 +13,7 @@
#define USAGE "s6-mkdir [ -p ] [ -v ] [ -m mode ] dir"
#define dieusage() strerr_dieusage(100, USAGE)
-static int doit (char const *s, unsigned int mode, int verbose, int ee)
+static int mkdir_doit (char const *s, unsigned int mode, int verbose, int ee)
{
if (mkdir(s, mode) == -1)
{
@@ -32,7 +33,7 @@ static int doit (char const *s, unsigned int mode, int verbose, int ee)
return 0 ;
}
-static int doparents (char const *s, unsigned int mode, int verbose)
+static int mkdir_doparents (char const *s, unsigned int mode, int verbose)
{
size_t n = strlen(s), i = 0 ;
char tmp[n+1] ;
@@ -42,12 +43,12 @@ static int doparents (char const *s, unsigned int mode, int verbose)
{
int e ;
tmp[i] = 0 ;
- e = doit(tmp, mode, verbose, 0) ;
+ e = mkdir_doit(tmp, mode, verbose, 0) ;
if (e) return e ;
}
tmp[i] = s[i] ;
}
- return doit(s, mode, verbose, 0) ;
+ return mkdir_doit(s, mode, verbose, 0) ;
}
int main (int argc, char const *const *argv)
@@ -75,7 +76,7 @@ int main (int argc, char const *const *argv)
}
if (noumask) umask(0) ;
for ( ; *argv ; argv++)
- e |= parents ? doparents(*argv, mode, verbose) :
- doit(*argv, mode, verbose, 1) ;
+ e |= parents ? mkdir_doparents(*argv, mode, verbose) :
+ mkdir_doit(*argv, mode, verbose, 1) ;
return e ;
}
diff --git a/src/skaembutils/s6-mkfifo.c b/src/skaembutils/s6-mkfifo.c
index e77028a..37e84af 100644
--- a/src/skaembutils/s6-mkfifo.c
+++ b/src/skaembutils/s6-mkfifo.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <sys/stat.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/types.h>
#include <skalibs/strerr.h>
diff --git a/src/skaembutils/s6-nuke.c b/src/skaembutils/s6-nuke.c
index 361cefc..ff80b6c 100644
--- a/src/skaembutils/s6-nuke.c
+++ b/src/skaembutils/s6-nuke.c
@@ -2,6 +2,7 @@
#include <signal.h>
#include <errno.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
#include <skalibs/sig.h>
diff --git a/src/skaembutils/s6-pause.c b/src/skaembutils/s6-pause.c
index 466eff6..e0416ba 100644
--- a/src/skaembutils/s6-pause.c
+++ b/src/skaembutils/s6-pause.c
@@ -10,12 +10,12 @@
#define USAGE "s6-pause [ -t ] [ -h ] [ -a ] [ -q ] [ -b ] [ -i ] [ -p signal,signal... ]"
#define dieusage() strerr_dieusage(100, USAGE)
-#define MAX 64
+#define PAUSE_MAX 64
int main (int argc, char const *const *argv)
{
PROG = "s6-pause" ;
- unsigned int sigs[MAX] ;
+ unsigned int sigs[PAUSE_MAX] ;
size_t nsig = 0 ;
{
subgetopt l = SUBGETOPT_ZERO ;
@@ -25,16 +25,16 @@ int main (int argc, char const *const *argv)
if (opt == -1) break ;
switch (opt)
{
- case 't' : if (nsig >= MAX) dieusage() ; sigs[nsig++] = SIGTERM ; break ;
- case 'h' : if (nsig >= MAX) dieusage() ; sigs[nsig++] = SIGHUP ; break ;
- case 'a' : if (nsig >= MAX) dieusage() ; sigs[nsig++] = SIGALRM ; break ;
- case 'q' : if (nsig >= MAX) dieusage() ; sigs[nsig++] = SIGQUIT ; break ;
- case 'b' : if (nsig >= MAX) dieusage() ; sigs[nsig++] = SIGABRT ; break ;
- case 'i' : if (nsig >= MAX) dieusage() ; sigs[nsig++] = SIGINT ; break ;
+ case 't' : if (nsig >= PAUSE_MAX) dieusage() ; sigs[nsig++] = SIGTERM ; break ;
+ case 'h' : if (nsig >= PAUSE_MAX) dieusage() ; sigs[nsig++] = SIGHUP ; break ;
+ case 'a' : if (nsig >= PAUSE_MAX) dieusage() ; sigs[nsig++] = SIGALRM ; break ;
+ case 'q' : if (nsig >= PAUSE_MAX) dieusage() ; sigs[nsig++] = SIGQUIT ; break ;
+ case 'b' : if (nsig >= PAUSE_MAX) dieusage() ; sigs[nsig++] = SIGABRT ; break ;
+ case 'i' : if (nsig >= PAUSE_MAX) dieusage() ; sigs[nsig++] = SIGINT ; break ;
case 'p' :
{
size_t n ;
- if (!uint_scanlist(sigs + nsig, MAX - nsig, l.arg, &n)) dieusage() ;
+ if (!uint_scanlist(sigs + nsig, PAUSE_MAX - nsig, l.arg, &n)) dieusage() ;
nsig += n ;
break ;
}
diff --git a/src/skaembutils/s6-printenv.c b/src/skaembutils/s6-printenv.c
index f23df4f..d1a48de 100644
--- a/src/skaembutils/s6-printenv.c
+++ b/src/skaembutils/s6-printenv.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr.h>
diff --git a/src/skaembutils/s6-quote-filter.c b/src/skaembutils/s6-quote-filter.c
index 8319f38..5ed5b60 100644
--- a/src/skaembutils/s6-quote-filter.c
+++ b/src/skaembutils/s6-quote-filter.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
#include <skalibs/buffer.h>
diff --git a/src/skaembutils/s6-quote.c b/src/skaembutils/s6-quote.c
index e9799eb..74c137c 100644
--- a/src/skaembutils/s6-quote.c
+++ b/src/skaembutils/s6-quote.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/strerr.h>
#include <skalibs/allreadwrite.h>
diff --git a/src/skaembutils/s6-rename.c b/src/skaembutils/s6-rename.c
index 48eb42e..a4fc1ee 100644
--- a/src/skaembutils/s6-rename.c
+++ b/src/skaembutils/s6-rename.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <stdio.h>
+
#include <skalibs/strerr.h>
#define USAGE "s6-rename old new"
diff --git a/src/skaembutils/s6-seq.c b/src/skaembutils/s6-seq.c
index f0ac49c..a7b70ba 100644
--- a/src/skaembutils/s6-seq.c
+++ b/src/skaembutils/s6-seq.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/buffer.h>
diff --git a/src/skaembutils/s6-sort.c b/src/skaembutils/s6-sort.c
index f7a7721..66955fe 100644
--- a/src/skaembutils/s6-sort.c
+++ b/src/skaembutils/s6-sort.c
@@ -4,6 +4,7 @@
#include <strings.h>
#include <stdlib.h>
#include <errno.h>
+
#include <skalibs/allreadwrite.h>
#include <skalibs/sgetopt.h>
#include <skalibs/buffer.h>
@@ -15,26 +16,34 @@
#define USAGE "s6-sort [ -bcfru0 ]"
-typedef int strncmp_t (char const *, char const *, size_t) ;
-typedef strncmp_t *strncmp_t_ref ;
-typedef int qsortcmp_t (void const *, void const *) ;
-typedef qsortcmp_t *qsortcmp_t_ref ;
+typedef int strncmp_func (char const *, char const *, size_t) ;
+typedef strncmp_func *strncmp_func_ref ;
+typedef int qsortcmp_func (void const *, void const *) ;
+typedef qsortcmp_func *qsortcmp_func_ref ;
-static int flagnoblanks = 0, flagreverse = 0, flaguniq = 0 ;
+typedef struct sort_global_s sort_global, *sort_global_ref ;
+struct sort_global_s
+{
+ strncmp_func_ref comp ;
+ unsigned char flagnoblanks : 1 ;
+ unsigned char flagreverse : 1 ;
+ unsigned char flaguniq : 1 ;
+} ;
+#define SORT_GLOBAL_ZERO { .flagnoblanks = 0, .flagreverse = 0, .flaguniq = 0, .comp = &strncmp }
-static strncmp_t_ref comp = &strncmp ;
+static sort_global_ref sort_G ;
static int compit (char const *s1, size_t n1, char const *s2, size_t n2)
{
int r ;
- if (flagnoblanks)
+ if (sort_G->flagnoblanks)
{
while ((*s1 == ' ') || (*s1 == '\t')) (s1++, n1--) ;
while ((*s2 == ' ') || (*s2 == '\t')) (s2++, n2--) ;
}
- r = (*comp)(s1, s2, n1 < n2 ? n1 : n2) ;
+ r = (*sort_G->comp)(s1, s2, n1 < n2 ? n1 : n2) ;
if (!r) r = n1 - n2 ;
- return flagreverse ? -r : r ;
+ return sort_G->flagreverse ? -r : r ;
}
static int sacmp (stralloc const *a, stralloc const *b)
@@ -42,7 +51,7 @@ static int sacmp (stralloc const *a, stralloc const *b)
return compit(a->s, a->len - 1, b->s, b->len - 1) ;
}
-static ssize_t slurplines (genalloc *lines, char sep)
+static ssize_t sort_slurplines (genalloc *lines, char sep)
{
ssize_t i = 0 ;
for (;; i++)
@@ -58,7 +67,7 @@ static ssize_t slurplines (genalloc *lines, char sep)
return i ;
}
-static void uniq (genalloc *lines)
+static void sort_uniq (genalloc *lines)
{
size_t len = genalloc_len(stralloc, lines) ;
stralloc *s = genalloc_s(stralloc, lines) ;
@@ -67,7 +76,7 @@ static void uniq (genalloc *lines)
if (!sacmp(s+i-1, s+i)) stralloc_free(s+i-1) ;
}
-static ssize_t outputlines (stralloc const *s, size_t len)
+static ssize_t sort_outputlines (stralloc const *s, size_t len)
{
size_t i = 0 ;
for (; i < len ; i++)
@@ -75,19 +84,21 @@ static ssize_t outputlines (stralloc const *s, size_t len)
return buffer_flush(buffer_1) ;
}
-static int check (stralloc const *s, size_t len)
+static int sort_check (stralloc const *s, size_t len)
{
size_t i = 1 ;
for (; i < len ; i++)
- if (sacmp(s+i-1, s+i) >= !flaguniq) return 0 ;
+ if (sacmp(s+i-1, s+i) >= !sort_G->flaguniq) return 0 ;
return 1 ;
}
int main (int argc, char const *const *argv)
{
genalloc lines = GENALLOC_ZERO ; /* array of stralloc */
- char sep = '\n' ;
int flagcheck = 0 ;
+ char sep = '\n' ;
+ sort_global globals = SORT_GLOBAL_ZERO ;
+ sort_G = &globals ;
PROG = "s6-sort" ;
{
subgetopt l = SUBGETOPT_ZERO ;
@@ -97,11 +108,11 @@ int main (int argc, char const *const *argv)
if (opt == -1) break ;
switch (opt)
{
- case 'b' : flagnoblanks = 1 ; break ;
+ case 'b' : sort_G->flagnoblanks = 1 ; break ;
case 'c' : flagcheck = 1 ; break ;
- case 'f' : comp = &strncasecmp ; break ;
- case 'r' : flagreverse = 1 ; break ;
- case 'u' : flaguniq = 1 ; break ;
+ case 'f' : sort_G->comp = &strncasecmp ; break ;
+ case 'r' : sort_G->flagreverse = 1 ; break ;
+ case 'u' : sort_G->flaguniq = 1 ; break ;
case '0' : sep = '\0' ; break ;
default : strerr_dieusage(100, USAGE) ;
}
@@ -109,11 +120,11 @@ int main (int argc, char const *const *argv)
argc -= l.ind ; argv += l.ind ;
}
- if (slurplines(&lines, sep) < 0) strerr_diefu1sys(111, "read from stdin") ;
- if (flagcheck) return !check(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines)) ;
- qsort(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines), sizeof(stralloc), (qsortcmp_t_ref)&sacmp) ;
- if (flaguniq) uniq(&lines) ;
- if (!outputlines(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines)))
+ if (sort_slurplines(&lines, sep) < 0) strerr_diefu1sys(111, "read from stdin") ;
+ if (flagcheck) return !sort_check(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines)) ;
+ qsort(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines), sizeof(stralloc), (qsortcmp_func_ref)&sacmp) ;
+ if (sort_G->flaguniq) sort_uniq(&lines) ;
+ if (!sort_outputlines(genalloc_s(stralloc, &lines), genalloc_len(stralloc, &lines)))
strerr_diefu1sys(111, "write to stdout") ;
return 0 ;
}
diff --git a/src/skaembutils/s6-tail.c b/src/skaembutils/s6-tail.c
index bee40d1..a3091cd 100644
--- a/src/skaembutils/s6-tail.c
+++ b/src/skaembutils/s6-tail.c
@@ -14,10 +14,10 @@
#define USAGE "s6-tail [ -c chars | -n lines | -1..9 ] [ file ]"
-typedef int tai$1_func (int, size_t) ;
-typedef tai$1_func *tai$1_func_ref ;
+typedef int tail_func (int, size_t) ;
+typedef tail_func *tail_func_ref ;
-static int pluslines (int fd, size_t n)
+static int tail_pluslines (int fd, size_t n)
{
if (n) n-- ;
{
@@ -48,7 +48,7 @@ static int pluslines (int fd, size_t n)
return (fd_cat(fd, 1) >= 0) ;
}
-static int pluschars (int fd, size_t n)
+static int tail_pluschars (int fd, size_t n)
{
if (n-- > 1)
{
@@ -64,7 +64,7 @@ static int pluschars (int fd, size_t n)
return (fd_cat(fd, 1) >= 0) ;
}
-static int minuslines (int fd, size_t n)
+static int tail_minuslines (int fd, size_t n)
{
char buf[BUFFER_INSIZE] ;
buffer b = BUFFER_INIT(&buffer_read, fd, buf, BUFFER_INSIZE) ;
@@ -102,7 +102,7 @@ static int minuslines (int fd, size_t n)
return 0 ;
}
-static int minuschars (int fd, size_t n)
+static int tail_minuschars (int fd, size_t n)
{
char buf[BUFFER_INSIZE + n] ;
buffer b = BUFFER_INIT(&buffer_read, fd, buf, BUFFER_INSIZE + n) ;
@@ -121,7 +121,7 @@ static int minuschars (int fd, size_t n)
int main (int argc, char const *const *argv)
{
- tai$1_func_ref f = &minuslines ;
+ tail_func_ref f = &tail_minuslines ;
unsigned int n = 10 ;
int gotit = 0 ;
PROG = "s6-tail" ;
@@ -145,7 +145,7 @@ int main (int argc, char const *const *argv)
{
if (gotit) strerr_dieusage(100, USAGE) ;
gotit = 1 ;
- f = &minuslines ;
+ f = &tail_minuslines ;
n = opt - '0' ;
break ;
}
@@ -153,11 +153,11 @@ int main (int argc, char const *const *argv)
{
if (gotit) strerr_dieusage(100, USAGE) ;
gotit = 1 ;
- f = &minuslines ;
+ f = &tail_minuslines ;
if (*l.arg == '-') l.arg++ ;
else if (*l.arg == '+')
{
- f = &pluslines ;
+ f = &tail_pluslines ;
l.arg++ ;
}
if (!uint0_scan(l.arg, &n)) strerr_dieusage(100, USAGE) ;
@@ -167,11 +167,11 @@ int main (int argc, char const *const *argv)
{
if (gotit) strerr_dieusage(100, USAGE) ;
gotit = 1 ;
- f = &minuschars ;
+ f = &tail_minuschars ;
if (*l.arg == '-') l.arg++ ;
else if (*l.arg == '+')
{
- f = &pluschars ;
+ f = &tail_pluschars ;
l.arg++ ;
}
if (!uint0_scan(l.arg, &n)) strerr_dieusage(100, USAGE) ;
diff --git a/src/skaembutils/s6-test.c b/src/skaembutils/s6-test.c
deleted file mode 100644
index d537619..0000000
--- a/src/skaembutils/s6-test.c
+++ /dev/null
@@ -1,538 +0,0 @@
-/* ISC license. */
-
-#include <sys/stat.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <regex.h>
-
-#include <skalibs/posixplz.h>
-#include <skalibs/types.h>
-#include <skalibs/strerr.h>
-#include <skalibs/djbunix.h>
-
-#define USAGE "s6-test expression... or [ expression... ]"
-
-enum opnum
-{
- T_NOT,
- T_AND,
- T_OR,
- T_LEFTP,
- T_RIGHTP,
- T_BLOCK,
- T_CHAR,
- T_DIR,
- T_EXIST,
- T_REGULAR,
- T_SGID,
- T_SYMLINK,
- T_STICKY,
- T_NONZERO,
- T_FIFO,
- T_READABLE,
- T_NONZEROFILE,
- T_TERM,
- T_SUID,
- T_WRITABLE,
- T_EXECUTABLE,
- T_ZERO,
- T_EUID,
- T_EGID,
- T_SOCKET,
- T_MODIFIED,
- T_NEWER,
- T_OLDER,
- T_DEVINO,
- T_STREQUAL,
- T_STRNEQUAL,
- T_STRLESSER,
- T_STRLESSERE,
- T_STRGREATER,
- T_STRGREATERE,
- T_NUMEQUAL,
- T_NUMNEQUAL,
- T_NUMGREATER,
- T_NUMGREATERE,
- T_NUMLESSER,
- T_NUMLESSERE,
- T_ENV,
- T_MATCH
-} ;
-
-struct token
-{
- char const *string ;
- enum opnum op ;
- unsigned int type ;
-} ;
-
-struct node
-{
- enum opnum op ;
- unsigned int type ;
- unsigned int arg1 ;
- unsigned int arg2 ;
- char const *data ;
-} ;
-
-static unsigned int lex (struct node *tree, char const *const *argv)
-{
- static struct token const tokens[46] =
- {
- { "-n", T_NONZERO, 2 },
- { "-z", T_ZERO, 2 },
- { "=", T_STREQUAL, 3 },
- { "!=", T_STRNEQUAL, 3 },
- { "-eq", T_NUMEQUAL, 3 },
- { "-ne", T_NUMNEQUAL, 3 },
- { "-gt", T_NUMGREATER, 3 },
- { "-ge", T_NUMGREATERE, 3 },
- { "-lt", T_NUMLESSER, 3 },
- { "-le", T_NUMLESSERE, 3 },
- { "-f", T_REGULAR, 2 },
- { "-h", T_SYMLINK, 2 },
- { "-L", T_SYMLINK, 2 },
- { "-e", T_EXIST, 2 },
- { "-k", T_STICKY, 2 },
- { "-a", T_AND, 7 },
- { "-o", T_OR, 8 },
- { "!", T_NOT, 6 },
- { "(", T_LEFTP, 4 },
- { ")", T_RIGHTP, 5 },
- { "-b", T_BLOCK, 2 },
- { "-c", T_CHAR, 2 },
- { "-d", T_DIR, 2 },
- { "-g", T_SGID, 2 },
- { "-p", T_FIFO, 2 },
- { "-r", T_READABLE, 2 },
- { "-s", T_NONZEROFILE, 2 },
- { "-t", T_TERM, 2 },
- { "-u", T_SUID, 2 },
- { "-w", T_WRITABLE, 2 },
- { "-x", T_EXECUTABLE, 2 },
- { "-O", T_EUID, 2 },
- { "-U", T_EUID, 2 },
- { "-G", T_EGID, 2 },
- { "-S", T_SOCKET, 2 },
- { "-N", T_MODIFIED, 2 },
- { "-nt", T_NEWER, 3 },
- { "-ot", T_OLDER, 3 },
- { "-ef", T_DEVINO, 3 },
- { "<", T_STRLESSER, 3 },
- { "<=", T_STRLESSERE, 3 },
- { ">", T_STRGREATER, 3 },
- { ">=", T_STRGREATERE, 3 },
- { "-v", T_ENV, 2 },
- { "=~", T_MATCH, 3 },
- { 0, 0, 0 }
- } ;
- unsigned int pos = 0 ;
-
- for (; argv[pos] ; pos++)
- {
- unsigned int i = 0 ;
- tree[pos].data = argv[pos] ;
- for (i = 0 ; tokens[i].string ; i++)
- if (!strcmp(argv[pos], tokens[i].string))
- {
- tree[pos].op = tokens[i].op ;
- tree[pos].type = tokens[i].type ;
- break ;
- }
- if (!tokens[i].string)
- {
- tree[pos].op = T_NONZERO ;
- tree[pos].type = 0 ;
- tree[pos].arg1 = pos ;
- if (*(argv[pos]) == '\\') tree[pos].data++ ; /* better than SUSv3 */
- }
- }
- return pos ;
-}
-
-static unsigned int parse (struct node *tree, unsigned int n)
-{
- static char const table[9][13] =
- {
- "xssssxsssxxxx",
- "xxxxxaxxxxxxx",
- "xsxxsxsssxxxx",
- "sxxxxxxxxxxxx",
- "xsxxsxsssxxxx",
- "nxxxxNxxxAOEs",
- "xsxxsxsssxxxx",
- "nxxxxNxxxAsxx",
- "nxxxxNxxxAOsx"
- } ;
-
- unsigned int stack[n+2] ;
- unsigned int sp = 0, pos = 0 ;
- int cont = 1 ;
-
- stack[0] = n+1 ;
- tree[n].type = 5 ; /* add ) for the final reduce */
- tree[n+1].type = 1 ; /* add EOF */
-
- while (cont)
- {
- switch (table[tree[pos].type][tree[stack[sp]].type])
- {
- case 'x' : /* error */
- {
- char fmt[UINT_FMT] ;
- fmt[uint_fmt(fmt, pos)] = 0 ;
- strerr_dief2x(100, "parse error at argument ", fmt) ;
- break ;
- }
- case 'a' : /* accept */
- {
- cont = 0 ;
- break ;
- }
- case 's' : /* shift */
- {
- stack[++sp] = pos++ ;
- break ;
- }
- case 'n' : /* reduce -> expr without nots, from atom */
- {
- switch (tree[stack[sp-1]].type)
- {
- case 2 :
- {
- tree[stack[sp-1]].arg1 = stack[sp] ;
- sp-- ;
- break ;
- }
- case 3 :
- {
- tree[stack[sp-1]].arg1 = stack[sp-2] ;
- tree[stack[sp-1]].arg2 = stack[sp] ;
- stack[sp-2] = stack[sp-1] ;
- sp -= 2 ;
- break ;
- }
- /* default : assert: its a zero */
- }
- tree[stack[sp]].type = 9 ;
- while (tree[stack[sp-1]].type == 6)
- {
- tree[stack[sp-1]].type = 9 ;
- tree[stack[sp-1]].arg1 = stack[sp] ;
- sp-- ;
- }
- break ;
- }
- case 'N' : /* reduce -> expr without nots, from expr */
- {
- if (tree[stack[sp-2]].type != 4)
- {
- char fmt[UINT_FMT] ;
- fmt[uint_fmt(fmt, pos)] = 0 ;
- strerr_dief2x(100, "parse error: bad right parenthesis at argument ", fmt) ;
- }
- stack[sp-2] = stack[sp-1] ;
- sp -= 2 ;
- tree[stack[sp]].type = 9 ;
- while (tree[stack[sp-1]].type == 6)
- {
- tree[stack[sp-1]].type = 9 ;
- tree[stack[sp-1]].arg1 = stack[sp] ;
- sp-- ;
- }
- break ;
- }
- case 'A' : /* reduce -> exprs without ands */
- {
- if (tree[stack[sp-1]].type == 7)
- {
- tree[stack[sp-1]].arg1 = stack[sp-2] ;
- tree[stack[sp-1]].arg2 = stack[sp] ;
- stack[sp-2] = stack[sp-1] ;
- sp -= 2 ;
- }
- tree[stack[sp]].type = 10 ;
- break ;
- }
- case 'O' : /* reduce -> expr without ors */
- {
- if (tree[stack[sp-1]].type == 8)
- {
- tree[stack[sp-1]].arg1 = stack[sp-2] ;
- tree[stack[sp-1]].arg2 = stack[sp] ;
- stack[sp-2] = stack[sp-1] ;
- sp -= 2 ;
- }
- tree[stack[sp]].type = 11 ;
- break ;
- }
- case 'E' : /* reduce -> expr */
- {
- tree[stack[sp]].type = 12 ;
- break ;
- }
- default : /* can't happen */
- strerr_dief1x(101, "internal error, please submit a bug-report.") ;
- }
- }
- if (sp != 2) strerr_dief1x(100, "parse error: too many left parentheses") ;
- return stack[1] ;
-}
-
-static int run (struct node const *tree, unsigned int root)
-{
- switch (tree[root].op)
- {
- case T_NOT :
- return !run(tree, tree[root].arg1) ;
- case T_AND :
- return run(tree, tree[root].arg1) && run(tree, tree[root].arg2) ;
- case T_OR :
- return run(tree, tree[root].arg1) || run(tree, tree[root].arg2) ;
- case T_EXIST :
- {
- struct stat st ;
- return !stat(tree[tree[root].arg1].data, &st) ;
- }
- case T_BLOCK :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return S_ISBLK(st.st_mode) ;
- }
- case T_CHAR :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return S_ISCHR(st.st_mode) ;
- }
- case T_DIR :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return S_ISDIR(st.st_mode) ;
- }
- case T_REGULAR :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return S_ISREG(st.st_mode) ;
- }
- case T_FIFO :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return S_ISFIFO(st.st_mode) ;
- }
- case T_SOCKET :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return S_ISSOCK(st.st_mode) ;
- }
- case T_SYMLINK :
- {
- struct stat st ;
- if (lstat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return S_ISLNK(st.st_mode) ;
- }
- case T_SGID :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return (st.st_mode & S_ISGID) ;
- }
- case T_SUID :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return (st.st_mode & S_ISUID) ;
- }
- case T_STICKY :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return (st.st_mode & S_ISVTX) ;
- }
- case T_NONZEROFILE :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return (st.st_size > 0) ;
- }
- case T_MODIFIED :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return (st.st_mtime > st.st_atime) ;
- }
- case T_EUID :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return st.st_uid == geteuid() ;
- }
- case T_EGID :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- return st.st_gid == getegid() ;
- }
- case T_READABLE :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- if (st.st_uid == geteuid()) return st.st_mode & S_IRUSR ;
- else if (st.st_gid == getegid()) return st.st_mode & S_IRGRP ;
- else return st.st_mode & S_IROTH ;
- }
- case T_WRITABLE :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- if (st.st_uid == geteuid()) return st.st_mode & S_IWUSR ;
- else if (st.st_gid == getegid()) return st.st_mode & S_IWGRP ;
- else return st.st_mode & S_IWOTH ;
- }
- case T_EXECUTABLE :
- {
- struct stat st ;
- if (stat(tree[tree[root].arg1].data, &st) == -1) return 0 ;
- if (st.st_uid == geteuid()) return st.st_mode & S_IXUSR ;
- else if (st.st_gid == getegid()) return st.st_mode & S_IXGRP ;
- else return st.st_mode & S_IXOTH ;
- }
- case T_NEWER :
- {
- struct stat st1, st2 ;
- if (stat(tree[tree[root].arg1].data, &st1) == -1) return 0 ;
- if (stat(tree[tree[root].arg2].data, &st2) == -1) return 1 ;
- return st1.st_mtime > st2.st_mtime ;
- }
- case T_OLDER :
- {
- struct stat st1, st2 ;
- if (stat(tree[tree[root].arg1].data, &st1) == -1) return 1 ;
- if (stat(tree[tree[root].arg2].data, &st2) == -1) return 0 ;
- return st1.st_mtime < st2.st_mtime ;
- }
- case T_DEVINO :
- {
- struct stat st1, st2 ;
- if (stat(tree[tree[root].arg1].data, &st1) == -1) return 0 ;
- if (stat(tree[tree[root].arg2].data, &st2) == -1) return 1 ;
- return (st1.st_dev == st2.st_dev) && (st1.st_ino == st2.st_ino) ;
- }
- case T_TERM :
- {
- unsigned int fd ;
- if (!uint0_scan(tree[tree[root].arg1].data, &fd))
- strerr_dief2x(100, tree[root].data, " requires an integer argument") ;
- return isatty(fd) ;
- }
- case T_NONZERO :
- return tree[tree[root].arg1].data[0] ;
- case T_ZERO :
- return !tree[tree[root].arg1].data[0] ;
- case T_STREQUAL :
- return !strcmp(tree[tree[root].arg1].data, tree[tree[root].arg2].data) ;
- case T_STRNEQUAL :
- return !!strcmp(tree[tree[root].arg1].data, tree[tree[root].arg2].data) ;
- case T_STRLESSER :
- return strcmp(tree[tree[root].arg1].data, tree[tree[root].arg2].data) < 0 ;
- case T_STRLESSERE :
- return strcmp(tree[tree[root].arg1].data, tree[tree[root].arg2].data) <= 0 ;
- case T_STRGREATER :
- return strcmp(tree[tree[root].arg1].data, tree[tree[root].arg2].data) > 0 ;
- case T_STRGREATERE :
- return strcmp(tree[tree[root].arg1].data, tree[tree[root].arg2].data) >= 0 ;
- case T_NUMEQUAL :
- {
- int n1, n2 ;
- if (!int_scan(tree[tree[root].arg1].data, &n1)
- || !int_scan(tree[tree[root].arg2].data, &n2))
- goto errorint ;
- return n1 == n2 ;
- }
- case T_NUMNEQUAL :
- {
- int n1, n2 ;
- if (!int_scan(tree[tree[root].arg1].data, &n1)
- || !int_scan(tree[tree[root].arg2].data, &n2))
- goto errorint ;
- return n1 != n2 ;
- }
- case T_NUMGREATER :
- {
- int n1, n2 ;
- if (!int_scan(tree[tree[root].arg1].data, &n1)
- || !int_scan(tree[tree[root].arg2].data, &n2))
- goto errorint ;
- return n1 > n2 ;
- }
- case T_NUMGREATERE :
- {
- int n1, n2 ;
- if (!int_scan(tree[tree[root].arg1].data, &n1)
- || !int_scan(tree[tree[root].arg2].data, &n2))
- goto errorint ;
- return n1 >= n2 ;
- }
- case T_NUMLESSER :
- {
- int n1, n2 ;
- if (!int_scan(tree[tree[root].arg1].data, &n1)
- || !int_scan(tree[tree[root].arg2].data, &n2))
- goto errorint ;
- return n1 < n2 ;
- }
- case T_NUMLESSERE :
- {
- int n1, n2 ;
- if (!int_scan(tree[tree[root].arg1].data, &n1)
- || !int_scan(tree[tree[root].arg2].data, &n2))
- goto errorint ;
- return n1 <= n2 ;
- }
- case T_ENV :
- return !!getenv(tree[tree[root].arg1].data) ;
- case T_MATCH :
- {
- regex_t re ;
- int r = skalibs_regcomp(&re, tree[tree[root].arg2].data, REG_EXTENDED | REG_NOSUB) ;
- if (r)
- {
- char buf[256] ;
- regerror(r, &re, buf, 256) ;
- strerr_diefu4x(r == REG_ESPACE ? 111 : 100, "compile ", tree[tree[root].arg2].data, " into a regular expression: ", buf) ;
- }
- r = regexec(&re, tree[tree[root].arg1].data, 0, 0, 0) ;
- regfree(&re) ;
- return !r ;
- }
- default:
- strerr_dief1x(101, "operation not implemented") ;
- }
-
-errorint:
- strerr_dief2x(100, tree[root].data, " requires integer arguments") ;
-}
-
-int main (int argc, char const *const *argv)
-{
- PROG = "s6-test" ;
- strerr_warnw1x("this program is now deprecated. Please use execline's eltest instead.") ;
- if (argc <= 1) return 1 ;
- {
- struct node tree[argc + 2] ;
- unsigned int n = lex(tree, argv+1) ;
- if ((argv[0][0] == '[') && !argv[0][1])
- {
- if (n && (!tree[n-1].type) && (tree[n-1].data[0] == ']') && !tree[n-1].data[1])
- n-- ;
- else strerr_dief1x(100, "parse error: missing closing bracket") ;
- }
- return !run(tree, parse(tree, n)) ;
- }
-}
diff --git a/src/skaembutils/s6-unquote-filter.c b/src/skaembutils/s6-unquote-filter.c
index d7f340e..4b1b4ef 100644
--- a/src/skaembutils/s6-unquote-filter.c
+++ b/src/skaembutils/s6-unquote-filter.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <errno.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/types.h>
#include <skalibs/strerr.h>
@@ -11,11 +12,7 @@
#define USAGE "s6-unquote-filter [ -q | -Q | -v | -w ] [ -d delim ]"
-static unsigned int strictness = 1 ;
-static char const *delim = "\"" ;
-static size_t delimlen = 1 ;
-
-static void fillfmt (char *fmt, char const *s, size_t len)
+static void unquotefilter_fillfmt (char *fmt, char const *s, size_t len)
{
size_t n = len < 39 ? len+1 : 36 ;
memcpy(fmt, s, n) ;
@@ -27,7 +24,7 @@ static void fillfmt (char *fmt, char const *s, size_t len)
fmt[n] = 0 ;
}
-static int doit (char const *s, size_t len)
+static int unquotefilter_doit (char const *s, size_t len, unsigned int strictness, char const *delim, size_t delimlen)
{
if (delimlen)
{
@@ -59,7 +56,7 @@ static int doit (char const *s, size_t len)
case 2 :
{
char fmt[40] ;
- fillfmt(fmt, s, len) ;
+ unquotefilter_fillfmt(fmt, s, len) ;
strerr_warnw3x("invalid starting quote character", " in line: ", fmt) ;
return 0 ;
}
@@ -88,7 +85,7 @@ static int doit (char const *s, size_t len)
case 2 :
{
char fmt[40] ;
- fillfmt(fmt, s, len) ;
+ unquotefilter_fillfmt(fmt, s, len) ;
strerr_warnwu3sys("unquote", " line: ", fmt) ;
return 0 ;
}
@@ -117,7 +114,7 @@ static int doit (char const *s, size_t len)
case 2 :
{
char fmt[40] ;
- fillfmt(fmt, s, len) ;
+ unquotefilter_fillfmt(fmt, s, len) ;
strerr_warnwu5x("unquote", ": no ending quote character", " in ", "line: ", fmt) ;
return 0 ;
}
@@ -136,7 +133,7 @@ static int doit (char const *s, size_t len)
char fmtnum[SIZE_FMT] ;
char fmtden[SIZE_FMT] ;
char fmt[40] ;
- fillfmt(fmt, s, len) ;
+ unquotefilter_fillfmt(fmt, s, len) ;
fmtnum[size_fmt(fmtnum, r+1)] = 0 ;
fmtden[size_fmt(fmtden, len-1)] = 0 ;
strerr_warnw7x("found ending quote character at position ", fmtnum, "/", fmtden, ", ignoring remainder of ", "line: ", fmt) ;
@@ -152,6 +149,9 @@ static int doit (char const *s, size_t len)
int main (int argc, char const *const *argv)
{
stralloc src = STRALLOC_ZERO ;
+ unsigned int strictness = 1 ;
+ char const *delim = "\"" ;
+ size_t delimlen = 1 ;
PROG = "s6-unquote-filter" ;
{
subgetopt l = SUBGETOPT_ZERO ;
@@ -183,7 +183,7 @@ int main (int argc, char const *const *argv)
if (errno != EPIPE) strerr_diefu1sys(111, "read from stdin") ;
}
else src.len-- ;
- if (!doit(src.s, src.len))
+ if (!unquotefilter_doit(src.s, src.len, strictness, delim, delimlen))
{
if (buffer_put(buffer_1, src.s, src.len) < (ssize_t)src.len)
strerr_diefu1sys(111, "write to stdout") ;
diff --git a/src/skaembutils/s6-unquote.c b/src/skaembutils/s6-unquote.c
index a1df8fa..34dcea5 100644
--- a/src/skaembutils/s6-unquote.c
+++ b/src/skaembutils/s6-unquote.c
@@ -1,6 +1,7 @@
/* ISC license. */
#include <string.h>
+
#include <skalibs/sgetopt.h>
#include <skalibs/types.h>
#include <skalibs/strerr.h>
diff --git a/src/skaembutils/s6-update-symlinks.c b/src/skaembutils/s6-update-symlinks.c
index 87783de..6b9a145 100644
--- a/src/skaembutils/s6-update-symlinks.c
+++ b/src/skaembutils/s6-update-symlinks.c
@@ -14,38 +14,34 @@
#define USAGE "s6-update-symlinks /destdir /srcdir [ /srcdir ... ]"
-#define MAGICNEW ":s6-update-symlinks-new"
-#define MAGICOLD ":s6-update-symlinks-old"
+#define UPDATESYMLINKS_MAGICNEW ":s6-update-symlinks-new"
+#define UPDATESYMLINKS_MAGICOLD ":s6-update-symlinks-old"
#define CONFLICT -2
#define ERROR -1
#define MODIFIED 0
#define OVERRIDEN 1
-static stralloc errdst = STRALLOC_ZERO ;
-static stralloc errsrc = STRALLOC_ZERO ;
-
-
-typedef struct stralloc3 stralloc3, *stralloc3_ref ;
-struct stralloc3
+typedef struct stralloc5 stralloc5, *stralloc5_ref ;
+struct stralloc5
{
stralloc dst ;
stralloc src ;
stralloc tmp ;
+ stralloc errdst ;
+ stralloc errsrc ;
} ;
-#define STRALLOC3_ZERO { STRALLOC_ZERO, STRALLOC_ZERO, STRALLOC_ZERO }
-
+#define STRALLOC5_ZERO { STRALLOC_ZERO, STRALLOC_ZERO, STRALLOC_ZERO, STRALLOC_ZERO, STRALLOC_ZERO }
-static void cleanup (stralloc *sa, unsigned int pos)
+static void updatesymlinks_cleanup (stralloc *sa, unsigned int pos)
{
int e = errno ;
rm_rf_in_tmp(sa, pos) ;
errno = e ;
}
-
-static int makeuniquename (stralloc *sa, char const *path, char const *magic)
+static int updatesymlinks_makeuniquename (stralloc *sa, char const *path, char const *magic)
{
size_t base = sa->len ;
int wasnull = !sa->s ;
@@ -60,8 +56,7 @@ err:
return 0 ;
}
-
-static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
+static int updatesymlinks_addlink (stralloc5 *blah, unsigned int dstpos, unsigned int srcpos)
{
if (symlink(blah->src.s + srcpos, blah->dst.s + dstpos) >= 0) return MODIFIED ;
if (errno != EEXIST) return ERROR ;
@@ -189,9 +184,9 @@ static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
blah->src.len = srcbase ;
blah->dst.len = dstbase ;
if (errno != ENOTDIR) return ERROR ;
- errdst.len = errsrc.len = 0 ;
- if (!stralloc_cats(&errdst, blah->dst.s + dstpos) || !stralloc_0(&errdst)
- || !stralloc_cats(&errsrc, blah->src.s + srcpos) || !stralloc_0(&errsrc))
+ blah->errdst.len = blah->errsrc.len = 0 ;
+ if (!stralloc_cats(&blah->errdst, blah->dst.s + dstpos) || !stralloc_0(&blah->errdst)
+ || !stralloc_cats(&blah->errsrc, blah->src.s + srcpos) || !stralloc_0(&blah->errsrc))
return ERROR ;
return CONFLICT ; /* dst is a dir but src is not */
}
@@ -245,7 +240,7 @@ static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
}
i += n ;
}
- switch (addlink(blah, dstbase, srcbase))
+ switch (updatesymlinks_addlink(blah, dstbase, srcbase))
{
case ERROR :
blah->tmp.len = tmpbase ;
@@ -281,7 +276,7 @@ static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
int main (int argc, char *const *argv)
{
- stralloc3 blah = STRALLOC3_ZERO ;
+ stralloc5 blah = STRALLOC5_ZERO ;
PROG = "s6-update-symlinks" ;
if (argc < 3) strerr_dieusage(100, USAGE) ;
{
@@ -293,7 +288,7 @@ int main (int argc, char *const *argv)
while (i && (argv[1][i-1] == '/')) argv[1][--i] = 0 ;
if (!i) strerr_diefu1x(100, "replace root directory") ;
}
- if (!makeuniquename(&blah.dst, argv[1], MAGICNEW))
+ if (!updatesymlinks_makeuniquename(&blah.dst, argv[1], UPDATESYMLINKS_MAGICNEW))
strerr_diefu2sys(111, "make random unique name based on ", argv[1]) ;
if ((unlink(blah.dst.s) == -1) && (errno != ENOENT))
strerr_diefu2sys(111, "unlink ", blah.dst.s) ;
@@ -306,15 +301,15 @@ int main (int argc, char *const *argv)
blah.src.len = 0 ;
if (!stralloc_cats(&blah.src, *p) || !stralloc_0(&blah.src))
strerr_diefu1sys(111, "make stralloc") ;
- r = addlink(&blah, 0, 0) ;
+ r = updatesymlinks_addlink(&blah, 0, 0) ;
if (r < 0)
{
stralloc_free(&blah.tmp) ;
stralloc_free(&blah.src) ;
- cleanup(&blah.dst, 0) ;
+ updatesymlinks_cleanup(&blah.dst, 0) ;
stralloc_free(&blah.dst) ;
if (r == CONFLICT)
- strerr_dief4x(100, "destination ", errdst.s, " conflicts with source ", errsrc.s) ;
+ strerr_dief4x(100, "destination ", blah.errdst.s, " conflicts with source ", blah.errsrc.s) ;
else
strerr_dief2sys(111, "error processing ", *p) ;
}
@@ -325,22 +320,22 @@ int main (int argc, char *const *argv)
if (rename(blah.dst.s, argv[1]) == -1) /* be atomic if possible */
{
blah.src.len = 0 ;
- if (!makeuniquename(&blah.src, argv[1], MAGICOLD))
+ if (!updatesymlinks_makeuniquename(&blah.src, argv[1], UPDATESYMLINKS_MAGICOLD))
{
- cleanup(&blah.dst, 0) ;
+ updatesymlinks_cleanup(&blah.dst, 0) ;
strerr_diefu2sys(111, "make random unique name based on ", argv[1]) ;
}
if (rename(argv[1], blah.src.s) == -1)
{
- cleanup(&blah.dst, 0) ;
+ updatesymlinks_cleanup(&blah.dst, 0) ;
strerr_diefu4sys(111, "rename ", argv[1], " to ", blah.src.s) ;
}
/* XXX: unavoidable race condition here: argv[1] does not exist */
if (rename(blah.dst.s, argv[1]) == -1)
{
rename(blah.src.s, argv[1]) ;
- cleanup(&blah.dst, 0) ;
+ updatesymlinks_cleanup(&blah.dst, 0) ;
strerr_diefu4sys(111, "rename ", blah.dst.s, " to ", argv[1]) ;
}
stralloc_free(&blah.dst) ;
diff --git a/src/skaembutils/seekablepipe.c b/src/skaembutils/seekablepipe.c
index d3030cd..5ae6a2d 100644
--- a/src/skaembutils/seekablepipe.c
+++ b/src/skaembutils/seekablepipe.c
@@ -9,8 +9,6 @@
#define USAGE "seekablepipe tempfile prog..."
-#define N 8192
-
int main (int argc, char const *const *argv)
{
int fdr, fdw ;