aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-07-30 03:21:52 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-07-30 03:21:52 +0000
commitbca250b0b2a1df4ceb939b71a269f71501fda024 (patch)
treef5e068250593ab854c215a0ec471e12b2295de0a /src
parenta78b3ea2b9097b0c40d7f7cfb8c03723c0d1273d (diff)
downloadexecline-bca250b0b2a1df4ceb939b71a269f71501fda024.tar.gz
Prepare for 2.10.0.0; remove pedantic posix; support loopwhilex -x ""
Diffstat (limited to 'src')
-rw-r--r--src/execline/cd.c (renamed from src/execline/execline-cd.c)2
-rw-r--r--src/execline/deps-exe/cd (renamed from src/execline/deps-exe/execline-cd)0
-rw-r--r--src/execline/deps-exe/posix-cd1
-rw-r--r--src/execline/deps-exe/posix-umask1
-rw-r--r--src/execline/deps-exe/umask (renamed from src/execline/deps-exe/execline-umask)0
-rw-r--r--src/execline/emptyenv.c36
-rw-r--r--src/execline/execline-umask.c19
-rw-r--r--src/execline/loopwhilex.c102
-rw-r--r--src/execline/posix-cd.c160
-rw-r--r--src/execline/redirfd.c94
-rw-r--r--src/execline/umask.c (renamed from src/execline/posix-umask.c)58
-rw-r--r--src/execline/umask.txt (renamed from src/execline/posix-umask.txt)0
-rw-r--r--src/execline/wait.c45
13 files changed, 166 insertions, 352 deletions
diff --git a/src/execline/execline-cd.c b/src/execline/cd.c
index 1762708..734c375 100644
--- a/src/execline/execline-cd.c
+++ b/src/execline/cd.c
@@ -9,7 +9,7 @@
int main (int argc, char const *const *argv)
{
- PROG = "execline-cd" ;
+ PROG = "cd" ;
if (argc < 3) strerr_dieusage(100, USAGE) ;
if (chdir(argv[1]) == -1)
strerr_diefu2sys(111, "chdir to ", argv[1]) ;
diff --git a/src/execline/deps-exe/execline-cd b/src/execline/deps-exe/cd
index e7187fe..e7187fe 100644
--- a/src/execline/deps-exe/execline-cd
+++ b/src/execline/deps-exe/cd
diff --git a/src/execline/deps-exe/posix-cd b/src/execline/deps-exe/posix-cd
deleted file mode 100644
index e7187fe..0000000
--- a/src/execline/deps-exe/posix-cd
+++ /dev/null
@@ -1 +0,0 @@
--lskarnet
diff --git a/src/execline/deps-exe/posix-umask b/src/execline/deps-exe/posix-umask
deleted file mode 100644
index e7187fe..0000000
--- a/src/execline/deps-exe/posix-umask
+++ /dev/null
@@ -1 +0,0 @@
--lskarnet
diff --git a/src/execline/deps-exe/execline-umask b/src/execline/deps-exe/umask
index e7187fe..e7187fe 100644
--- a/src/execline/deps-exe/execline-umask
+++ b/src/execline/deps-exe/umask
diff --git a/src/execline/emptyenv.c b/src/execline/emptyenv.c
index ac59697..ed1a893 100644
--- a/src/execline/emptyenv.c
+++ b/src/execline/emptyenv.c
@@ -19,22 +19,22 @@
enum emptyenv_golb_e
{
- GOLB_PATH = 0x01,
- GOLB_LIB = 0x02,
- GOLB_CLEANUP = 0x04,
- GOLB_OPT = 0x08,
- GOLB_POS = 0x10
+ EMPTYENV_GOLB_PATH = 0x01,
+ EMPTYENV_GOLB_LIB = 0x02,
+ EMPTYENV_GOLB_CLEANUP = 0x04,
+ EMPTYENV_GOLB_OPT = 0x08,
+ EMPTYENV_GOLB_POS = 0x10
} ;
int main (int argc, char const *const *argv)
{
static gol_bool const rgolb[5] =
{
- { .so = 'p', .lo = "keep-path", .clear = 0, .set = GOLB_PATH },
- { .so = 'l', .lo = "keep-ld-library-path", .clear = 0, .set = GOLB_LIB },
- { .so = 'c', .lo = "cleanup", .clear = 0, .set = GOLB_CLEANUP },
- { .so = 'o', .lo = "pop-elgetopt", .clear = 0, .set = GOLB_OPT },
- { .so = 'P', .lo = "pop-execline", .clear = 0, .set = GOLB_POS }
+ { .so = 'p', .lo = "keep-path", .clear = 0, .set = EMPTYENV_GOLB_PATH },
+ { .so = 'l', .lo = "keep-ld-library-path", .clear = 0, .set = EMPTYENV_GOLB_LIB },
+ { .so = 'c', .lo = "cleanup", .clear = 0, .set = EMPTYENV_GOLB_CLEANUP },
+ { .so = 'o', .lo = "pop-elgetopt", .clear = 0, .set = EMPTYENV_GOLB_OPT },
+ { .so = 'P', .lo = "pop-execline", .clear = 0, .set = EMPTYENV_GOLB_POS }
} ;
uint64_t wgolb = 0 ;
unsigned int golc ;
@@ -43,7 +43,7 @@ int main (int argc, char const *const *argv)
argc -= golc ; argv += golc ;
if (!argc) strerr_dieusage(100, USAGE) ;
- if (wgolb & GOLB_CLEANUP)
+ if (wgolb & EMPTYENV_GOLB_CLEANUP)
{
static char const *const onebyte = "!?#0" ;
char *const *envp = environ ;
@@ -88,12 +88,12 @@ int main (int argc, char const *const *argv)
strerr_diefu1sys(111, "clean up environment") ;
}
- else if (wgolb & (GOLB_OPT | GOLB_POS))
+ else if (wgolb & (EMPTYENV_GOLB_OPT | EMPTYENV_GOLB_POS))
{
static char const *const list[12] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "#", "ELGETOPT_" } ;
stralloc sa = STRALLOC_ZERO ;
size_t envlen = env_len((char const *const *)environ) ;
- int n = el_popenv(&sa, (char const *const *)environ, envlen, wgolb & GOLB_POS ? list : list + 11, (wgolb & GOLB_POS ? 11 : 0) + !!(wgolb & GOLB_OPT)) ;
+ int n = el_popenv(&sa, (char const *const *)environ, envlen, wgolb & EMPTYENV_GOLB_POS ? list : list + 11, (wgolb & EMPTYENV_GOLB_POS ? 11 : 0) + !!(wgolb & EMPTYENV_GOLB_OPT)) ;
if (n < 0) strerr_diefu1sys(111, "pop current execline environment") ;
{
char const *v[envlen - n + 1] ;
@@ -108,18 +108,18 @@ int main (int argc, char const *const *argv)
char const *newenv[3] = { 0, 0, 0 } ;
char *const *envp = environ ;
unsigned int m = 0 ;
- wgolb &= GOLB_PATH | GOLB_LIB ;
+ wgolb &= EMPTYENV_GOLB_PATH | EMPTYENV_GOLB_LIB ;
for (; wgolb && *envp ; envp++)
{
- if (wgolb & GOLB_PATH && !strncmp(*envp, "PATH=", 5))
+ if (wgolb & EMPTYENV_GOLB_PATH && !strncmp(*envp, "PATH=", 5))
{
newenv[m++] = *envp ;
- wgolb &= ~GOLB_PATH ;
+ wgolb &= ~EMPTYENV_GOLB_PATH ;
}
- if (wgolb & GOLB_LIB && !strncmp(*envp, "LD_LIBRARY_PATH=", 16))
+ if (wgolb & EMPTYENV_GOLB_LIB && !strncmp(*envp, "LD_LIBRARY_PATH=", 16))
{
newenv[m++] = *envp ;
- wgolb &= ~GOLB_LIB ;
+ wgolb &= ~EMPTYENV_GOLB_LIB ;
}
}
xexec_e(argv, newenv) ;
diff --git a/src/execline/execline-umask.c b/src/execline/execline-umask.c
deleted file mode 100644
index c5aacda..0000000
--- a/src/execline/execline-umask.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* ISC license. */
-
-#include <sys/stat.h>
-
-#include <skalibs/types.h>
-#include <skalibs/strerr.h>
-#include <skalibs/exec.h>
-
-#define USAGE "umask value prog..."
-
-int main (int argc, char const *const *argv)
-{
- unsigned int m ;
- PROG = "execline-umask" ;
- if (argc < 3) strerr_dieusage(100, USAGE) ;
- if (!uint_oscan(argv[1], &m)) strerr_dieusage(100, USAGE) ;
- umask(m) ;
- xexec(argv+2) ;
-}
diff --git a/src/execline/loopwhilex.c b/src/execline/loopwhilex.c
index acae3b3..fdd05b8 100644
--- a/src/execline/loopwhilex.c
+++ b/src/execline/loopwhilex.c
@@ -1,73 +1,91 @@
/* ISC license. */
+#include <stdint.h>
+#include <stdlib.h>
#include <errno.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/strerr.h>
+#include <skalibs/gol.h>
+#include <skalibs/uint64.h>
#include <skalibs/types.h>
+#include <skalibs/strerr.h>
#include <skalibs/djbunix.h>
#include <execline/execline.h>
-#define USAGE "loopwhilex [ -n ] [ -o okcode,okcode,... | -x exitcode,exitcode,... ] prog..."
+#define USAGE "loopwhilex [ -o okcode,okcode,... | -x exitcode,exitcode,... ] prog..."
#define dieusage() strerr_dieusage(100, USAGE)
-static int lw_isok (unsigned short *tab, unsigned int n, int code)
+enum lw_gola_e
+{
+ LW_GOLA_OK,
+ LW_GOLA_EXCLUDE,
+ LW_GOLA_N
+} ;
+
+static int lw_uint8_cmp (void const *a, void const *b)
+{
+ uint8_t aa = *(uint8_t const *)a ;
+ uint8_t bb = *(uint8_t const *)b ;
+ return aa < bb ? -1 : aa > bb ;
+}
+
+static size_t lw_scanlist (char const *s, uint8_t *tab)
{
- unsigned int i = 0 ;
- for (; i < n ; i++) if ((unsigned short)code == tab[i]) break ;
- return i < n ;
+ size_t n = 0 ;
+ while (*s)
+ {
+ uint64_t u ;
+ size_t l = uint64_scan(s, &u) ;
+ if (!l) break ;
+ if (u > 256 || n >= 255) dieusage() ;
+ tab[n++] = u ;
+ s += l ;
+ while (*s == ',') s++ ;
+ }
+ if (*s) dieusage() ;
+ qsort(tab, n, 1, &lw_uint8_cmp) ;
+ return n ;
}
int main (int argc, char const *const *argv, char const *const *envp)
{
- int wstat ;
- int not = 0, cont = 1, rev = 0 ;
- unsigned short okcodes[256] ;
- size_t nbc = 0 ;
+ static gol_arg const rgola[] =
+ {
+ { .so = 'o', .lo = "ok-codes", .i = LW_GOLA_OK },
+ { .so = 'x', .lo = "exclude-codes", .i = LW_GOLA_EXCLUDE },
+ } ;
+ int rev = 0 ;
+ char const *wgola[LW_GOLA_N] = { 0 } ;
+ size_t n = 0 ;
+ uint8_t codes[256] = { 0 } ;
PROG = "loopwhilex" ;
+
{
- subgetopt l = SUBGETOPT_ZERO ;
- for (;;)
- {
- int opt = subgetopt_r(argc, argv, "no:x:", &l) ;
- if (opt == -1) break ;
- switch (opt)
- {
- case 'n' : not = 1 ; break ;
- case 'o' :
- rev = 0 ;
- if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ;
- break ;
- case 'x' :
- rev = 1 ;
- if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ;
- break ;
- default : dieusage() ;
- }
- }
- argc -= l.ind ; argv += l.ind ;
+ unsigned int golc = gol_main(argc, argv, 0, 0, rgola, sizeof(rgola)/sizeof(gol_arg), 0, wgola) ;
+ argc -= golc ; argv += golc ;
}
if (!argc) dieusage() ;
-
- if (!nbc)
+ if (wgola[LW_GOLA_OK]) n = lw_scanlist(wgola[LW_GOLA_OK], codes) ;
+ else if (wgola[LW_GOLA_EXCLUDE])
{
- okcodes[0] = 0 ;
- nbc = 1 ;
+ n = lw_scanlist(wgola[LW_GOLA_EXCLUDE], codes) ;
+ rev = 1 ;
}
- else if (rev) not = !not ;
+ else n = 1 ;
- while (cont)
+ for (;;)
{
+ int wstat ;
pid_t pid = el_spawn0(argv[0], argv, envp) ;
if (!pid)
{
if (errno == ENOENT && argv[0][0] == ' ')
- strerr_diefu3x(111, "spawn ", argv[0], ": name begins with a space, are you trying to spawn a block as your loop body?") ;
- else strerr_diefu2sys(111, "spawn ", argv[0]) ;
+ strerr_dief(111, "spawn ", argv[0], ": name begins with a space, are you trying to spawn a block as your loop body?") ;
+ else strerr_diefusys(111, "spawn ", argv[0]) ;
}
- if (wait_pid(pid, &wstat) < 0) strerr_diefu1sys(111, "wait_pid") ;
- cont = not != lw_isok(okcodes, nbc, wait_estatus(wstat)) ;
+ if (wait_pid(pid, &wstat) < 0) strerr_diefusys(111, "wait_pid") ;
+ codes[255] = wait_estatus(wstat) ;
+ if (rev != !bsearch(codes + 255, codes, n, 1, &lw_uint8_cmp)) break ;
}
- return wait_estatus(wstat) ;
+ return codes[255] ;
}
diff --git a/src/execline/posix-cd.c b/src/execline/posix-cd.c
deleted file mode 100644
index e9bfd35..0000000
--- a/src/execline/posix-cd.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/* ISC license. */
-
-#include <sys/stat.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <locale.h>
-
-#include <skalibs/bytestr.h>
-#include <skalibs/sgetopt.h>
-#include <skalibs/allreadwrite.h>
-#include <skalibs/strerr.h>
-#include <skalibs/stralloc.h>
-#include <skalibs/djbunix.h>
-#include <skalibs/env.h>
-#include <skalibs/exec.h>
-
-#define USAGE "posix-cd [ -L | -P ] [ - | path ] [ prog... ]"
-#define dieusage() strerr_dieusage(100, USAGE)
-#define dienomem() strerr_diefu1sys(111, "stralloc_catb")
-
-int main (int argc, char const **argv)
-{
- int phy = 0 ;
- int dopwd = 0 ;
- char const *where ;
- int got = 0 ;
- stralloc sa = STRALLOC_ZERO ;
- PROG = "posix-cd" ;
- setlocale(LC_ALL, "") ; /* yeah, as if */
-
- {
- subgetopt l = SUBGETOPT_ZERO ;
- for (;;)
- {
- int opt = subgetopt_r(argc, argv, "LP", &l) ;
- if (opt == -1) break ;
- switch (opt)
- {
- case 'L' : phy = 0 ; break ;
- case 'P' : phy = 1 ; break ;
- default : dieusage() ;
- }
- }
- argc -= l.ind ; argv += l.ind ;
- }
- if (!argc) where = getenv("HOME") ;
- else
- {
- where = *argv++ ;
- if (!strcmp(where, "-"))
- {
- where = getenv("OLDPWD") ;
- dopwd = 1 ;
- }
- }
- if (!where || !where[0]) dieusage() ;
-
- if (!(where[0] == '/' || (where[0] == '.' && (!where[1] || where[1] == '/' || (where[1] == '.' && (!where[2] || where[2] == '/'))))))
- {
- char const *cdpath = getenv("CDPATH") ;
- if (cdpath)
- {
- size_t pos = 0 ;
- size_t len = strlen(cdpath) ;
- while (pos < len)
- {
- struct stat st ;
- size_t m = byte_chr(cdpath + pos, len - pos, ':') ;
- sa.len = 0 ;
- if (m)
- {
- if (!stralloc_catb(&sa, cdpath + pos, m)) dienomem() ;
- if (cdpath[pos + m - 1] != '/' && !stralloc_catb(&sa, "/", 1)) dienomem() ;
- }
- else if (!stralloc_catb(&sa, "./", 2)) dienomem() ;
- if (!stralloc_cats(&sa, where) || !stralloc_0(&sa)) dienomem() ;
- if (!stat(sa.s, &st) && S_ISDIR(st.st_mode))
- {
- got = 1 ;
- dopwd = 1 ;
- break ;
- }
- pos += m+1 ;
- }
- }
- }
-
- if (!got && (!stralloc_cats(&sa, where) || !stralloc_0(&sa))) dienomem() ;
-
- {
- size_t sabase = sa.len ;
- if (sagetcwd(&sa) < 0) strerr_diefu1sys(111, "getcwd") ;
- if (!stralloc_0(&sa)) dienomem() ;
- if (!env_mexec("OLDPWD", sa.s + sabase)) dienomem() ;
- sa.len = sabase ;
- }
-
- if (!phy)
- {
- char const *x = getenv("PWD") ;
- if (x && sa.s[0] != '/')
- {
- size_t len = strlen(x) ;
- int doslash = len && x[len-1] != '/' ;
- if (!stralloc_insertb(&sa, 0, x, len + doslash)) dienomem() ;
- if (doslash) sa.s[len] = '/' ;
- }
- {
- stralloc tmp = STRALLOC_ZERO ;
- if (!stralloc_ready(&tmp, sa.len + 2)) dienomem() ;
- tmp.len = path_canonicalize(tmp.s, sa.s, 1) ;
- if (!tmp.len++)
- strerr_diefu4sys(111, "canonicalize ", sa.s, ": problem with ", tmp.s) ;
- stralloc_free(&sa) ;
- sa = tmp ;
- }
- if (!env_mexec("PWD", sa.s)) dienomem() ;
-#ifdef PATH_MAX
- if (sa.len > PATH_MAX && strlen(where) < PATH_MAX && x && *x)
- {
- size_t len = strlen(x) ;
- int hasslash = x[len-1] == '/' ;
- if (!strncmp(sa.s, x, len))
- {
- if (hasslash || (sa.len > len && sa.s[len] == '/'))
- {
- sa.len -= len + !hasslash ;
- memmove(sa.s, sa.s + len + !hasslash, sa.len) ;
- }
- }
- }
-#endif
- }
-
- /* fking finally */
-
- if (chdir(sa.s) < 0)
- strerr_diefu2sys(111, "chdir to ", where) ;
-
- /* and there's still more nonsense to do afterwards! */
-
- if (phy)
- {
- sa.len = 0 ;
- if (sagetcwd(&sa) < 0) strerr_diefu1sys(111, "getcwd") ;
- if (!stralloc_0(&sa)) dienomem() ;
- if (!env_mexec("PWD", sa.s)) dienomem() ;
- }
-
- if (dopwd)
- {
- sa.s[sa.len - 1] = '\n' ;
- if (allwrite(1, sa.s, sa.len) < sa.len)
- strerr_diefu1sys(111, "write to stdout") ;
- }
-
- xmexec0(argv) ;
-}
diff --git a/src/execline/redirfd.c b/src/execline/redirfd.c
index c3562f9..c9a7f9e 100644
--- a/src/execline/redirfd.c
+++ b/src/execline/redirfd.c
@@ -13,47 +13,47 @@
#define USAGE "redirfd -[ r | w | u | a | x ] [ -N | -n ] [ -b ] [ -f ] [ -E | -e ] fd|var file prog..."
#define dieusage() strerr_dieusage(100, USAGE)
-enum golb_e
+enum redirfd_golb_e
{
- GOLB_READ = 0x0001,
- GOLB_WRITE = 0x0002,
- GOLB_CREAT = 0x0004,
- GOLB_APPEND = 0x0008,
- GOLB_TRUNC = 0x0010,
- GOLB_EXCL = 0x0020,
- GOLB_NONBLOCK = 0x0040,
- GOLB_CHANGEMODE = 0x0100,
- GOLB_OPEN = 0x0200,
- GOLB_AUTOIMPORT = 0x0400,
+ REDIRFD_GOLB_READ = 0x0001,
+ REDIRFD_GOLB_WRITE = 0x0002,
+ REDIRFD_GOLB_CREAT = 0x0004,
+ REDIRFD_GOLB_APPEND = 0x0008,
+ REDIRFD_GOLB_TRUNC = 0x0010,
+ REDIRFD_GOLB_EXCL = 0x0020,
+ REDIRFD_GOLB_NONBLOCK = 0x0040,
+ REDIRFD_GOLB_CHANGEMODE = 0x0100,
+ REDIRFD_GOLB_OPEN = 0x0200,
+ REDIRFD_GOLB_AUTOIMPORT = 0x0400,
} ;
int main (int argc, char const *const *argv)
{
static gol_bool const rgolb[] =
{
- { .so = 'r', .lo = 0, .clear = GOLB_WRITE | GOLB_APPEND | GOLB_CREAT | GOLB_TRUNC | GOLB_EXCL, .set = GOLB_READ },
- { .so = 'w', .lo = 0, .clear = GOLB_READ | GOLB_APPEND | GOLB_EXCL, .set = GOLB_WRITE | GOLB_CREAT | GOLB_TRUNC },
- { .so = 'u', .lo = 0, .clear = GOLB_APPEND | GOLB_CREAT | GOLB_TRUNC | GOLB_EXCL, .set = GOLB_READ | GOLB_WRITE },
- { .so = 'a', .lo = 0, .clear = GOLB_READ | GOLB_TRUNC | GOLB_EXCL, .set = GOLB_WRITE | GOLB_CREAT | GOLB_APPEND },
- { .so = 'x', .lo = 0, .clear = GOLB_READ | GOLB_APPEND | GOLB_TRUNC, .set = GOLB_WRITE | GOLB_CREAT | GOLB_EXCL },
- { .so = 'N', .lo = "block", .clear = GOLB_NONBLOCK, .set = 0 },
- { .so = 'n', .lo = "nonblock", .clear = 0, .set = GOLB_NONBLOCK },
- { .so = 'b', .lo = "switch-block", .clear = 0, .set = GOLB_CHANGEMODE },
- { .so = 'f', .lo = "open", .clear = 0, .set = GOLB_OPEN },
- { .so = 'e', .lo = "no-autoimport", .clear = GOLB_AUTOIMPORT, .set = 0 },
- { .so = 'E', .lo = "autoimport", .clear = 0, .set = GOLB_AUTOIMPORT },
- { .so = 0, .lo = "no-read", .clear = GOLB_READ, .set = 0 },
- { .so = 0, .lo = "read", .clear = 0, .set = GOLB_READ },
- { .so = 0, .lo = "no-write", .clear = GOLB_WRITE, .set = 0 },
- { .so = 0, .lo = "write", .clear = 0, .set = GOLB_WRITE },
- { .so = 0, .lo = "no-create", .clear = GOLB_CREAT, .set = 0 },
- { .so = 0, .lo = "create", .clear = 0, .set = GOLB_CREAT },
- { .so = 0, .lo = "no-append", .clear = GOLB_APPEND, .set = 0 },
- { .so = 0, .lo = "append", .clear = 0, .set = GOLB_APPEND },
- { .so = 0, .lo = "no-trunc", .clear = GOLB_TRUNC, .set = 0 },
- { .so = 0, .lo = "trunc", .clear = 0, .set = GOLB_TRUNC },
- { .so = 0, .lo = "no-excl", .clear = GOLB_EXCL, .set = 0 },
- { .so = 0, .lo = "excl", .clear = 0, .set = GOLB_EXCL },
+ { .so = 'r', .lo = 0, .clear = REDIRFD_GOLB_WRITE | REDIRFD_GOLB_APPEND | REDIRFD_GOLB_CREAT | REDIRFD_GOLB_TRUNC | REDIRFD_GOLB_EXCL, .set = REDIRFD_GOLB_READ },
+ { .so = 'w', .lo = 0, .clear = REDIRFD_GOLB_READ | REDIRFD_GOLB_APPEND | REDIRFD_GOLB_EXCL, .set = REDIRFD_GOLB_WRITE | REDIRFD_GOLB_CREAT | REDIRFD_GOLB_TRUNC },
+ { .so = 'u', .lo = 0, .clear = REDIRFD_GOLB_APPEND | REDIRFD_GOLB_CREAT | REDIRFD_GOLB_TRUNC | REDIRFD_GOLB_EXCL, .set = REDIRFD_GOLB_READ | REDIRFD_GOLB_WRITE },
+ { .so = 'a', .lo = 0, .clear = REDIRFD_GOLB_READ | REDIRFD_GOLB_TRUNC | REDIRFD_GOLB_EXCL, .set = REDIRFD_GOLB_WRITE | REDIRFD_GOLB_CREAT | REDIRFD_GOLB_APPEND },
+ { .so = 'x', .lo = 0, .clear = REDIRFD_GOLB_READ | REDIRFD_GOLB_APPEND | REDIRFD_GOLB_TRUNC, .set = REDIRFD_GOLB_WRITE | REDIRFD_GOLB_CREAT | REDIRFD_GOLB_EXCL },
+ { .so = 'N', .lo = "block", .clear = REDIRFD_GOLB_NONBLOCK, .set = 0 },
+ { .so = 'n', .lo = "nonblock", .clear = 0, .set = REDIRFD_GOLB_NONBLOCK },
+ { .so = 'b', .lo = "switch-block", .clear = 0, .set = REDIRFD_GOLB_CHANGEMODE },
+ { .so = 'f', .lo = "open", .clear = 0, .set = REDIRFD_GOLB_OPEN },
+ { .so = 'e', .lo = "no-autoimport", .clear = REDIRFD_GOLB_AUTOIMPORT, .set = 0 },
+ { .so = 'E', .lo = "autoimport", .clear = 0, .set = REDIRFD_GOLB_AUTOIMPORT },
+ { .so = 0, .lo = "no-read", .clear = REDIRFD_GOLB_READ, .set = 0 },
+ { .so = 0, .lo = "read", .clear = 0, .set = REDIRFD_GOLB_READ },
+ { .so = 0, .lo = "no-write", .clear = REDIRFD_GOLB_WRITE, .set = 0 },
+ { .so = 0, .lo = "write", .clear = 0, .set = REDIRFD_GOLB_WRITE },
+ { .so = 0, .lo = "no-create", .clear = REDIRFD_GOLB_CREAT, .set = 0 },
+ { .so = 0, .lo = "create", .clear = 0, .set = REDIRFD_GOLB_CREAT },
+ { .so = 0, .lo = "no-append", .clear = REDIRFD_GOLB_APPEND, .set = 0 },
+ { .so = 0, .lo = "append", .clear = 0, .set = REDIRFD_GOLB_APPEND },
+ { .so = 0, .lo = "no-trunc", .clear = REDIRFD_GOLB_TRUNC, .set = 0 },
+ { .so = 0, .lo = "trunc", .clear = 0, .set = REDIRFD_GOLB_TRUNC },
+ { .so = 0, .lo = "no-excl", .clear = REDIRFD_GOLB_EXCL, .set = 0 },
+ { .so = 0, .lo = "excl", .clear = 0, .set = REDIRFD_GOLB_EXCL },
} ;
uint64_t wgolb = 0 ;
unsigned int golc ;
@@ -65,20 +65,20 @@ int main (int argc, char const *const *argv)
golc = gol_main(argc, argv, rgolb, sizeof(rgolb)/sizeof(gol_bool), 0, 0, &wgolb, 0) ;
argc -= golc ; argv += golc ;
if (argc < 3) dieusage() ;
- if (!(wgolb & (GOLB_READ | GOLB_WRITE))) dieusage() ;
- if (!(wgolb & GOLB_OPEN))
+ if (!(wgolb & (REDIRFD_GOLB_READ | REDIRFD_GOLB_WRITE))) dieusage() ;
+ if (!(wgolb & REDIRFD_GOLB_OPEN))
if (!uint0_scan(argv[0], &fdto)) dieusage() ;
flags =
- (wgolb & GOLB_WRITE ? wgolb & GOLB_READ ? O_RDWR : O_WRONLY : O_RDONLY) |
- (wgolb & GOLB_CREAT ? O_CREAT : 0) |
- (wgolb & GOLB_APPEND ? O_APPEND : 0) |
- (wgolb & GOLB_TRUNC ? O_TRUNC : 0) |
- (wgolb & GOLB_EXCL ? O_EXCL : 0) |
- (wgolb & GOLB_NONBLOCK ? O_NONBLOCK : 0) ;
+ (wgolb & REDIRFD_GOLB_WRITE ? wgolb & REDIRFD_GOLB_READ ? O_RDWR : O_WRONLY : O_RDONLY) |
+ (wgolb & REDIRFD_GOLB_CREAT ? O_CREAT : 0) |
+ (wgolb & REDIRFD_GOLB_APPEND ? O_APPEND : 0) |
+ (wgolb & REDIRFD_GOLB_TRUNC ? O_TRUNC : 0) |
+ (wgolb & REDIRFD_GOLB_EXCL ? O_EXCL : 0) |
+ (wgolb & REDIRFD_GOLB_NONBLOCK ? O_NONBLOCK : 0) ;
fd = open3(argv[1], flags, 0666) ;
- if (fd == -1 && wgolb & GOLB_WRITE && errno == ENXIO)
+ if (fd == -1 && wgolb & REDIRFD_GOLB_WRITE && errno == ENXIO)
{
int fdr = open_read(argv[1]) ;
if (fdr == -1) strerr_diefu2sys(111, "open_read ", argv[1]) ;
@@ -87,14 +87,14 @@ int main (int argc, char const *const *argv)
}
if (fd == -1) strerr_diefu2sys(111, "open ", argv[1]) ;
- if (wgolb & GOLB_CHANGEMODE)
- if ((wgolb & GOLB_NONBLOCK ? ndelay_off(fd) : ndelay_on(fd)) == -1)
+ if (wgolb & REDIRFD_GOLB_CHANGEMODE)
+ if ((wgolb & REDIRFD_GOLB_NONBLOCK ? ndelay_off(fd) : ndelay_on(fd)) == -1)
strerr_diefu1sys(111, "change blocking mode") ;
- if (wgolb & GOLB_OPEN)
+ if (wgolb & REDIRFD_GOLB_OPEN)
{
char fmt[UINT_FMT] ;
fmt[uint_fmt(fmt, fd)] = 0 ;
- el_modif_and_exec(argv+2, argv[0], fmt, !!(wgolb & GOLB_AUTOIMPORT)) ;
+ el_modif_and_exec(argv+2, argv[0], fmt, !!(wgolb & REDIRFD_GOLB_AUTOIMPORT)) ;
}
else
{
diff --git a/src/execline/posix-umask.c b/src/execline/umask.c
index 69f4b08..819cf96 100644
--- a/src/execline/posix-umask.c
+++ b/src/execline/umask.c
@@ -2,24 +2,18 @@
#include <stdint.h>
#include <sys/stat.h>
-#include <locale.h>
#include <skalibs/gccattributes.h>
#include <skalibs/bytestr.h>
#include <skalibs/types.h>
-#include <skalibs/sgetopt.h>
+#include <skalibs/envexec.h>
#include <skalibs/buffer.h>
-#include <skalibs/strerr.h>
-#include <skalibs/exec.h>
-#define USAGE "posix-umask [ -S ] [ mask ] [ prog... ]"
+#define USAGE "umask [ -S ] [ mask ] [ prog... ]"
#define dieusage() strerr_dieusage(100, USAGE)
#define dieout() strerr_diefu1sys(111, "write to stdout")
-
- /* well, unlike posix-cd, at least this one was fun to write */
-
-static inline int pu_output (int sym)
+static inline int umask_output (int sym)
{
mode_t mode = umask(0) ;
size_t m = 0 ;
@@ -43,10 +37,10 @@ static inline int pu_output (int sym)
return 0 ;
}
-static void pu_diesyntax (char const *) gccattr_noreturn ;
-static void pu_diesyntax (char const *s)
+static void umask_diesyntax (char const *) gccattr_noreturn ;
+static void umask_diesyntax (char const *s)
{
- strerr_dief3x(101, "internal parsing error: bad ", s, ". Please submit a bug-report.") ;
+ strerr_dief(101, "internal parsing error: bad ", s, ". Please submit a bug-report.") ;
}
static inline uint8_t pu_cclass (char c)
@@ -73,7 +67,7 @@ static inline uint8_t pu_cclass (char c)
}
}
-static inline uint8_t pu_who_value (char c)
+static inline uint8_t umask_who_value (char c)
{
switch (c)
{
@@ -84,11 +78,11 @@ static inline uint8_t pu_who_value (char c)
case '+' : /* shortcut for when who is empty */
case '-' :
case '=' : return 7 ;
- default : pu_diesyntax("who") ;
+ default : umask_diesyntax("who") ;
}
}
-static inline uint8_t pu_perm_value (char c)
+static inline uint8_t umask_perm_value (char c)
{
switch (c)
{
@@ -98,11 +92,11 @@ static inline uint8_t pu_perm_value (char c)
case 'X' : return 1 ;
case 's' :
case 't' : return 0 ;
- default : pu_diesyntax("perm") ;
+ default : umask_diesyntax("perm") ;
}
}
-static inline unsigned int pu_parsemode (char const *s)
+static inline unsigned int umask_parsemode (char const *s)
{
static uint16_t const table[5][7] =
{
@@ -123,9 +117,9 @@ static inline unsigned int pu_parsemode (char const *s)
char c = *s++ ;
uint16_t what = table[state][pu_cclass(c)] ;
state = what & 7 ;
- if (what & 0x020) who |= pu_who_value(c) ;
+ if (what & 0x020) who |= umask_who_value(c) ;
if (what & 0x080) perm = modes[byte_chr("ogu", 3, c)] ;
- if (what & 0x100) perm |= pu_perm_value(c) ;
+ if (what & 0x100) perm |= umask_perm_value(c) ;
if (what & 0x800)
{
unsigned int i = 3 ;
@@ -135,7 +129,7 @@ static inline unsigned int pu_parsemode (char const *s)
case '-' : modes[i] &= ~perm ; break ;
case '+' : modes[i] |= perm ; break ;
case '=' : modes[i] = perm ; break ;
- default : pu_diesyntax("op") ;
+ default : umask_diesyntax("op") ;
}
}
if (what & 0x040) op = c ;
@@ -148,27 +142,17 @@ static inline unsigned int pu_parsemode (char const *s)
int main (int argc, char const **argv)
{
- int sym = 0 ;
+ static gol_bool const rgolb = { .so = 'S', .lo = "symbolic", .clear = 0, .set = 0x01 } ;
+ uint64_t wgolb = 0 ;
unsigned int mode ;
- PROG = "posix-umask" ;
- setlocale(LC_ALL, "") ; /* totally supported, I swear */
+ PROG = "umask" ;
{
- subgetopt l = SUBGETOPT_ZERO ;
- for (;;)
- {
- int opt = subgetopt_r(argc, argv, "S", &l) ;
- if (opt == -1) break ;
- switch (opt)
- {
- case 'S' : sym = 1 ; break ;
- default : dieusage() ;
- }
- }
- argc -= l.ind ; argv += l.ind ;
+ unsigned int golc = gol_main(argc, argv, &rgolb, 1, 0, 0, &wgolb, 0) ;
+ argc -= golc ; argv += golc ;
}
- if (!argc) return pu_output(sym) ;
- if (!uint0_oscan(argv[0], &mode)) mode = ~pu_parsemode(argv[0]) ;
+ if (!argc) return umask_output(wgolb & 0x01) ;
+ if (!uint0_oscan(argv[0], &mode)) mode = ~umask_parsemode(argv[0]) ;
umask(mode & 00777) ;
xexec0(argv+1) ;
}
diff --git a/src/execline/posix-umask.txt b/src/execline/umask.txt
index 5bf49a2..5bf49a2 100644
--- a/src/execline/posix-umask.txt
+++ b/src/execline/umask.txt
diff --git a/src/execline/wait.c b/src/execline/wait.c
index 6886c0c..d320d54 100644
--- a/src/execline/wait.c
+++ b/src/execline/wait.c
@@ -15,10 +15,6 @@
#include <execline/config.h>
#include <execline/execline.h>
-#ifdef EXECLINE_PEDANTIC_POSIX
-#include <locale.h>
-#endif
-
#define USAGE "wait [ -I | -i ] [ -a | -o ] [ -r | -t timeout ] { pids... } [ prog... ]"
#define dieusage() strerr_dieusage(100, USAGE)
@@ -157,51 +153,48 @@ static int wait_with_timeout (pid_t *pids, unsigned int n, pid_t *returned, ac_f
enum wait_golb_e
{
- GOLB_INSIST = 0x01,
- GOLB_JUSTONE = 0x02,
- GOLB_REAP = 0x04,
+ WAIT_GOLB_INSIST = 0x01,
+ WAIT_GOLB_JUSTONE = 0x02,
+ WAIT_GOLB_REAP = 0x04,
} ;
enum wait_gola_e
{
- GOLA_TIMEOUT,
- GOLA_N
+ WAIT_GOLA_TIMEOUT,
+ WAIT_GOLA_N
} ;
int main (int argc, char const **argv)
{
static gol_bool const rgolb[] =
{
- { .so = 'I', .lo = "no-insist", .clear = GOLB_INSIST, .set = 0 },
- { .so = 'i', .lo = "insist", .clear = 0, .set = GOLB_INSIST },
- { .so = 'a', .lo = "all", .clear = GOLB_JUSTONE, .set = 0 },
- { .so = 'o', .lo = "one", .clear = 0, .set = GOLB_JUSTONE },
- { .so = 'r', .lo = "reap", .clear = 0, .set = GOLB_REAP },
+ { .so = 'I', .lo = "no-insist", .clear = WAIT_GOLB_INSIST, .set = 0 },
+ { .so = 'i', .lo = "insist", .clear = 0, .set = WAIT_GOLB_INSIST },
+ { .so = 'a', .lo = "all", .clear = WAIT_GOLB_JUSTONE, .set = 0 },
+ { .so = 'o', .lo = "one", .clear = 0, .set = WAIT_GOLB_JUSTONE },
+ { .so = 'r', .lo = "reap", .clear = 0, .set = WAIT_GOLB_REAP },
} ;
static gol_arg const rgola[] =
{
- { .so = 't', .lo = "timeout", .i = GOLA_TIMEOUT },
+ { .so = 't', .lo = "timeout", .i = WAIT_GOLA_TIMEOUT },
} ;
tain tto = TAIN_INFINITE_RELATIVE ;
int argc1 ;
int hasblock = 1 ;
int e ;
uint64_t wgolb = 0 ;
- char const *wgola[GOLA_N] = { 0 } ;
+ char const *wgola[WAIT_GOLA_N] = { 0 } ;
unsigned int golc ;
pid_t pid = -1 ;
PROG = "wait" ;
-#ifdef EXECLINE_PEDANTIC_POSIX
- setlocale(LC_ALL, "") ; /* but of course, dear POSIX */
-#endif
golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
argc -= golc ; argv += golc ;
- if (wgolb & GOLB_REAP) wgola[GOLA_TIMEOUT] = "0" ;
- if (wgola[GOLA_TIMEOUT])
+ if (wgolb & WAIT_GOLB_REAP) wgola[WAIT_GOLA_TIMEOUT] = "0" ;
+ if (wgola[WAIT_GOLA_TIMEOUT])
{
unsigned int t = 0 ;
- if (!uint0_scan(wgola[GOLA_TIMEOUT], &t)) dieusage() ;
+ if (!uint0_scan(wgola[WAIT_GOLA_TIMEOUT], &t)) dieusage() ;
tain_from_millisecs(&tto, t) ;
}
@@ -223,9 +216,9 @@ int main (int argc, char const **argv)
}
else pids[0] = 0 ;
- e = wgola[GOLA_TIMEOUT] ? /* wait -t30000 whatever */
- wait_with_timeout(pids, n, &pid, argc1 ? &wait_one_from_list_nohang : &wait_one_nohang, &tto, !!(wgolb & GOLB_JUSTONE), !!(wgolb & GOLB_INSIST)) :
- wgolb & GOLB_JUSTONE ?
+ e = wgola[WAIT_GOLA_TIMEOUT] ? /* wait -t30000 whatever */
+ wait_with_timeout(pids, n, &pid, argc1 ? &wait_one_from_list_nohang : &wait_one_nohang, &tto, !!(wgolb & WAIT_GOLB_JUSTONE), !!(wgolb & WAIT_GOLB_INSIST)) :
+ wgolb & WAIT_GOLB_JUSTONE ?
argc1 ?
wait_one_from_list(pids, n, &pid) : /* wait -o -- 2 3 4 / wait -o -- { 2 3 4 } */
wait_one(&pid) : /* wait -o / wait -o { } */
@@ -234,7 +227,7 @@ int main (int argc, char const **argv)
wait_all() ; /* wait / wait { } */
}
if (!hasblock) _exit(e >= 0 ? e : 127) ;
- if (!(wgolb & GOLB_JUSTONE)) xexec0(argv + argc1 + 1) ;
+ if (!(wgolb & WAIT_GOLB_JUSTONE)) xexec0(argv + argc1 + 1) ;
if (e == -1) xmexec0_n(argv + argc1 + 1, "?\0!", 4, 2) ;
{