[hackers] [sbase] tr: Provide a fallthrough case for single-arg -s || Laslo Hunhold

2016-10-05 Thread git
commit b5ebd49dd3fa06fd4a505ba9421fda8c6d65861f
Author: Laslo Hunhold 
AuthorDate: Thu Oct 6 01:59:36 2016 +0200
Commit: Laslo Hunhold 
CommitDate: Thu Oct 6 02:00:25 2016 +0200

tr: Provide a fallthrough case for single-arg -s

Previously, this would not work properly and not be let through the
sanity check.

This is a dirty hack until the next iteration where I'll clean up the
data structures and make this saner.

diff --git a/tr.c b/tr.c
index 3aef53e..a633d74 100644
--- a/tr.c
+++ b/tr.c
@@ -172,7 +172,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
-   Rune r = 0, lastrune = 0;
+   Rune r, lastrune = 0;
size_t off1, off2, i, m;
int ret = 0;
 
@@ -197,9 +197,9 @@ main(int argc, char *argv[])
if (argc == 2)
set2ranges = makeset(argv[1], , );
 
-   if (!dflag) {
+   if (!dflag || (argc == 2 && sflag)) {
/* sanity checks as we are translating */
-   if (!set2ranges && !set2check)
+   if (!sflag && !set2ranges && !set2check)
eprintf("cannot map to an empty set.\n");
if (set2check && set2check != islowerrune &&
set2check != isupperrune) {
@@ -211,6 +211,8 @@ read:
ret |= fshut(stdin, "") | fshut(stdout, "");
return ret;
}
+   if (argc == 1 && sflag)
+   goto write;
for (i = 0, off1 = 0; i < set1ranges; i++, off1 += rangelen(set1[i])) {
if (set1[i].start <= r && r <= set1[i].end) {
if (dflag) {
@@ -278,7 +280,15 @@ read:
if (dflag && cflag)
goto read;
 write:
-   if (sflag && r == lastrune) {
+   if (argc == 1 && sflag && r == lastrune) {
+   if (set1check && set1check(r))
+   goto read;
+   for (i = 0; i < set1ranges; i++) {
+   if (set1[i].start <= r && r <= set1[i].end)
+   goto read;
+   }
+   }
+   if (argc == 2 && sflag && r == lastrune) {
if (set2check && set2check(r))
goto read;
for (i = 0; i < set2ranges; i++) {
@@ -286,7 +296,7 @@ write:
goto read;
}
}
-   lastrune = r;
efputrune(, stdout, "");
+   lastrune = r;
goto read;
 }



[hackers] Re: [sbase][patch] respect -q handling with -l and -R

2016-10-05 Thread Evan Gates
On Wed, Oct 5, 2016 at 2:48 PM, Evan Gates  wrote:
> sbase-ls_-lq.diff: respect -q flag when using -l flag
> sbase-ls_-qR.diff: respect -q flag when printing directory headings with -R 
> flag

Updated versions. Add "ls: " to commit messages and malloc later/free
earlier in lsdir (thanks quinq).
From 6f7c1ebc00a40d65715bb0417b65e6b2c1a03acb Mon Sep 17 00:00:00 2001
From: Evan Gates 
Date: Wed, 5 Oct 2016 10:57:38 -0700
Subject: [PATCH] ls: fix ls -lq to respect -q flag

---
 ls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ls.c b/ls.c
index b5c4b00..7c80d56 100644
--- a/ls.c
+++ b/ls.c
@@ -207,7 +207,7 @@ output(const struct entry *ent)
printf("%10s ", humansize(ent->size));
else
printf("%10lu ", (unsigned long)ent->size);
-   printf("%s %s%s", buf, ent->name, indicator(ent->mode));
+   printf("%s %s%s", buf, name, indicator(ent->mode));
if (S_ISLNK(ent->mode)) {
if ((len = readlink(ent->name, buf, sizeof(buf) - 1)) < 0)
eprintf("readlink %s:", ent->name);
-- 
2.10.0

From f6bb38c2f9f773542a241f5d95090eeb28f56e0b Mon Sep 17 00:00:00 2001
From: Evan Gates 
Date: Wed, 5 Oct 2016 14:43:30 -0700
Subject: [PATCH] ls: respect -q when printing directory names with -R

break out the non printable character to ? code into a makeprint()
function so it can be used both in output() and lsdir()
---
 ls.c | 57 +++--
 1 file changed, 31 insertions(+), 26 deletions(-)

diff --git a/ls.c b/ls.c
index b5c4b00..0cc33d1 100644
--- a/ls.c
+++ b/ls.c
@@ -113,6 +113,27 @@ indicator(mode_t mode)
return "";
 }
 
+static char *
+makeprint(char *name)
+{
+   char *c, *u, *print = emalloc(strlen(name) + 1);
+   Rune r;
+   size_t l;
+
+   for (c = print, u = name; *u; u += l) {
+   l = chartorune(, u);
+   if (isprintrune(r)) {
+   memcpy(c, u, l);
+   c += l;
+   } else {
+   *c++ = '?';
+   }
+   }
+   *c = '\0';
+
+   return print;
+}
+
 static void
 output(const struct entry *ent)
 {
@@ -120,28 +141,9 @@ output(const struct entry *ent)
struct passwd *pw;
struct tm *tm;
ssize_t len;
-   size_t l;
-   char *name, *c, *u, *fmt, buf[BUFSIZ],
-pwname[_SC_LOGIN_NAME_MAX], grname[_SC_LOGIN_NAME_MAX],
-mode[] = "--";
-   Rune r;
-
-   if (qflag) {
-   name = emalloc(strlen(ent->name) + 1);
-
-   for (c = name, u = ent->name; *u; u += l) {
-   l = chartorune(, u);
-   if (isprintrune(r)) {
-   memcpy(c, u, l);
-   c += l;
-   } else {
-   *c++ = '?';
-   }
-   }
-   *c = '\0';
-   } else {
-   name = ent->name;
-   }
+   char *fmt, buf[BUFSIZ], pwname[_SC_LOGIN_NAME_MAX],
+grname[_SC_LOGIN_NAME_MAX], mode[] = "--",
+*name = qflag ? makeprint(ent->name) : ent->name;
 
if (iflag)
printf("%lu ", (unsigned long)ent->ino);
@@ -250,12 +252,11 @@ lsdir(const char *path, const struct entry *dir)
struct entry *ent, *ents = NULL;
struct dirent *d;
size_t i, n = 0;
-   char prefix[PATH_MAX];
+   char prefix[PATH_MAX], *name;
 
if (!(dp = opendir(dir->name))) {
ret = 1;
weprintf("opendir %s%s:", path, dir->name);
-   return;
}
if (chdir(dir->name) < 0)
eprintf("chdir %s:", dir->name);
@@ -278,8 +279,12 @@ lsdir(const char *path, const struct entry *dir)
if (!Uflag)
qsort(ents, n, sizeof(*ents), entcmp);
 
-   if (path[0] || showdirs)
-   printf("%s%s:\n", path, dir->name);
+   if (path[0] || showdirs) {
+   name = qflag ? makeprint(dir->name) : dir->name;
+   printf("%s%s:\n", path, name);
+   if (qflag)
+   free(name);
+   }
for (i = 0; i < n; i++)
output([i]);
 
-- 
2.10.0



Re: [hackers] [sbase][patch]find: copy path before using basename

2016-10-05 Thread Evan Gates
On Mon, Oct 3, 2016 at 3:10 PM, FRIGN  wrote:
> Please don't use VLA's. Use estrdup() in this case.

sbase-find_basename2.diff: revised patch without VLAs
sbase-find_noVLAs.diff: path to remove all VLAs in find
From 47b19cf1c341627eb796469f3793e5c26baea767 Mon Sep 17 00:00:00 2001
From: Evan Gates 
Date: Wed, 5 Oct 2016 15:37:34 -0700
Subject: [PATCH] find: estrdup before basename

"The basename() function may modify the string pointed to by path..."
Thanks POSIX
---
 find.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/find.c b/find.c
index b331486..77f2935 100644
--- a/find.c
+++ b/find.c
@@ -229,7 +229,10 @@ static struct {
 static int
 pri_name(struct arg *arg)
 {
-   return !fnmatch((char *)arg->extra.p, basename(arg->path), 0);
+   char *path = estrdup(arg->path);
+   int ret = !fnmatch((char *)arg->extra.p, basename(path), 0);
+   free(path);
+   return ret;
 }
 
 static int
-- 
2.10.0

From 5163140694907a7070a7ffa8baec57014bde1dfd Mon Sep 17 00:00:00 2001
From: Evan Gates 
Date: Wed, 5 Oct 2016 15:34:52 -0700
Subject: [PATCH] find: remove VLAs

---
 find.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/find.c b/find.c
index 5f75735..b331486 100644
--- a/find.c
+++ b/find.c
@@ -770,7 +770,9 @@ find_op(char *name)
 static void
 parse(int argc, char **argv)
 {
-   struct tok infix[2 * argc + 1], *stack[argc], *tok, *rpn, *out, **top;
+   struct tok *tok, *rpn, *out, **top,
+  *infix = emalloc((2 * argc + 1) * sizeof(*infix)),
+  **stack = emalloc(argc * sizeof(*stack));
struct op_info *op;
struct pri_info *pri;
char **arg;
@@ -887,6 +889,9 @@ parse(int argc, char **argv)
 
toks = rpn;
root = *top;
+
+   free(infix);
+   free(stack);
 }
 
 /* for a primary, run and return result
@@ -925,8 +930,9 @@ find(char *path, struct findhist *hist)
DIR *dir;
struct dirent *de;
struct findhist *f, cur;
-   size_t len = strlen(path) + 2; /* null and '/' */
+   size_t namelen, pathcap = 0, len = strlen(path) + 2; /* null and '/' */
struct arg arg = { path, , { NULL } };
+   char *p, *pathbuf = NULL;
 
if ((gflags.l || (gflags.h && !hist) ? stat(path, ) : lstat(path, 
)) < 0) {
weprintf("failed to stat %s:", path);
@@ -968,18 +974,20 @@ find(char *path, struct findhist *hist)
}
 
while (errno = 0, (de = readdir(dir))) {
-   size_t pathcap = len + strlen(de->d_name);
-   char pathbuf[pathcap], *p;
-
if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
continue;
-
+   namelen = strlen(de->d_name);
+   if (len + namelen > pathcap) {
+   pathcap = len + namelen;
+   pathbuf = erealloc(pathbuf, pathcap);
+   }
p = pathbuf + estrlcpy(pathbuf, path, pathcap);
if (*--p != '/')
estrlcat(pathbuf, "/", pathcap);
estrlcat(pathbuf, de->d_name, pathcap);
find(pathbuf, );
}
+   free(pathbuf);
if (errno) {
weprintf("readdir %s:", path);
closedir(dir);
-- 
2.10.0



[hackers] [sbase] tr(1): Properly handle the -dc case for character classes || Laslo Hunhold

2016-10-05 Thread git
commit c154ef7a0399b9ca0bbea96a044841657d743ea0
Author: Laslo Hunhold 
AuthorDate: Thu Oct 6 00:15:56 2016 +0200
Commit: Laslo Hunhold 
CommitDate: Thu Oct 6 00:16:30 2016 +0200

tr(1): Properly handle the -dc case for character classes

I actually did that properly in the set-case but forgot to add the same
logic to the character classes. Now it should work fine.

diff --git a/tr.c b/tr.c
index 29c9445..3aef53e 100644
--- a/tr.c
+++ b/tr.c
@@ -248,8 +248,12 @@ read:
}
}
if (set1check && set1check(r)) {
-   if (dflag && !cflag)
-   goto read;
+   if (dflag) {
+   if (cflag)
+   goto write;
+   else
+   goto read;
+   }
if (set2check) {
if (set2check == islowerrune)
r = tolowerrune(r);
@@ -258,6 +262,7 @@ read:
} else {
r = set2[set2ranges - 1].end;
}
+   goto write;
}
if (!dflag && cflag) {
if (set2check) {



[hackers] [sbase][patch] respect -q handling with -l and -R

2016-10-05 Thread Evan Gates
sbase-ls_-lq.diff: respect -q flag when using -l flag
sbase-ls_-qR.diff: respect -q flag when printing directory headings with -R flag
From da7bfffbe6d9f02421899b42b410301ad5718c54 Mon Sep 17 00:00:00 2001
From: Evan Gates 
Date: Wed, 5 Oct 2016 10:57:38 -0700
Subject: [PATCH] fix ls -lq to respect -q flag

---
 ls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ls.c b/ls.c
index b5c4b00..7c80d56 100644
--- a/ls.c
+++ b/ls.c
@@ -207,7 +207,7 @@ output(const struct entry *ent)
printf("%10s ", humansize(ent->size));
else
printf("%10lu ", (unsigned long)ent->size);
-   printf("%s %s%s", buf, ent->name, indicator(ent->mode));
+   printf("%s %s%s", buf, name, indicator(ent->mode));
if (S_ISLNK(ent->mode)) {
if ((len = readlink(ent->name, buf, sizeof(buf) - 1)) < 0)
eprintf("readlink %s:", ent->name);
-- 
2.10.0

From c23b1d3e881a3799527274e5cd43f47ddb6803bd Mon Sep 17 00:00:00 2001
From: Evan Gates 
Date: Wed, 5 Oct 2016 14:43:30 -0700
Subject: [PATCH] respect -q when printing directory names with -R

break out the non printable character to ? code into a makeprint()
function so it can be used both in output() and lsdir()
---
 ls.c | 56 +++-
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/ls.c b/ls.c
index b5c4b00..139014e 100644
--- a/ls.c
+++ b/ls.c
@@ -113,6 +113,27 @@ indicator(mode_t mode)
return "";
 }
 
+static char *
+makeprint(char *name)
+{
+   char *c, *u, *print = emalloc(strlen(name) + 1);
+   Rune r;
+   size_t l;
+
+   for (c = print, u = name; *u; u += l) {
+   l = chartorune(, u);
+   if (isprintrune(r)) {
+   memcpy(c, u, l);
+   c += l;
+   } else {
+   *c++ = '?';
+   }
+   }
+   *c = '\0';
+
+   return print;
+}
+
 static void
 output(const struct entry *ent)
 {
@@ -120,28 +141,9 @@ output(const struct entry *ent)
struct passwd *pw;
struct tm *tm;
ssize_t len;
-   size_t l;
-   char *name, *c, *u, *fmt, buf[BUFSIZ],
-pwname[_SC_LOGIN_NAME_MAX], grname[_SC_LOGIN_NAME_MAX],
-mode[] = "--";
-   Rune r;
-
-   if (qflag) {
-   name = emalloc(strlen(ent->name) + 1);
-
-   for (c = name, u = ent->name; *u; u += l) {
-   l = chartorune(, u);
-   if (isprintrune(r)) {
-   memcpy(c, u, l);
-   c += l;
-   } else {
-   *c++ = '?';
-   }
-   }
-   *c = '\0';
-   } else {
-   name = ent->name;
-   }
+   char *fmt, buf[BUFSIZ], pwname[_SC_LOGIN_NAME_MAX],
+grname[_SC_LOGIN_NAME_MAX], mode[] = "--",
+*name = qflag ? makeprint(ent->name) : ent->name;
 
if (iflag)
printf("%lu ", (unsigned long)ent->ino);
@@ -250,12 +252,12 @@ lsdir(const char *path, const struct entry *dir)
struct entry *ent, *ents = NULL;
struct dirent *d;
size_t i, n = 0;
-   char prefix[PATH_MAX];
+   char prefix[PATH_MAX], *name = qflag ? makeprint(dir->name) : dir->name;
 
if (!(dp = opendir(dir->name))) {
ret = 1;
weprintf("opendir %s%s:", path, dir->name);
-   return;
+   goto cleanup;
}
if (chdir(dir->name) < 0)
eprintf("chdir %s:", dir->name);
@@ -279,7 +281,7 @@ lsdir(const char *path, const struct entry *dir)
qsort(ents, n, sizeof(*ents), entcmp);
 
if (path[0] || showdirs)
-   printf("%s%s:\n", path, dir->name);
+   printf("%s%s:\n", path, name);
for (i = 0; i < n; i++)
output([i]);
 
@@ -303,6 +305,10 @@ lsdir(const char *path, const struct entry *dir)
for (i = 0; i < n; ++i)
free(ents[i].name);
free(ents);
+
+cleanup:
+   if (qflag)
+   free(name);
 }
 
 static int
-- 
2.10.0



[hackers] [sbase] tr(1): Properly jump to output when inside set complement || Laslo Hunhold

2016-10-05 Thread git
commit 096c504d82b99e36cce20b0298cb32c70f4c61fe
Author: Laslo Hunhold 
AuthorDate: Wed Oct 5 21:54:51 2016 +0200
Commit: Laslo Hunhold 
CommitDate: Wed Oct 5 21:54:51 2016 +0200

tr(1): Properly jump to output when inside set complement

diff --git a/tr.c b/tr.c
index 926d1eb..29c9445 100644
--- a/tr.c
+++ b/tr.c
@@ -215,7 +215,7 @@ read:
if (set1[i].start <= r && r <= set1[i].end) {
if (dflag) {
if (cflag)
-   continue;
+   goto write;
else
goto read;
}



[hackers] [sbase] tr.1: Make note of some changes in the utility || Laslo Hunhold

2016-10-05 Thread git
commit 456f3c4211d110fb6f19eab988a7db74de1c4768
Author: Laslo Hunhold 
AuthorDate: Wed Oct 5 21:42:24 2016 +0200
Commit: Laslo Hunhold 
CommitDate: Wed Oct 5 21:42:24 2016 +0200

tr.1: Make note of some changes in the utility

diff --git a/tr.1 b/tr.1
index a9b25c6..03a0b0f 100644
--- a/tr.1
+++ b/tr.1
@@ -1,4 +1,4 @@
-.Dd 2015-10-08
+.Dd 2016-10-05
 .Dt TR 1
 .Os sbase
 .Sh NAME
@@ -49,7 +49,9 @@ Resolve to
 .Sy c .
 .El
 .Sh TRANSLATION
-If no options are specified,
+If
+.Fl d
+is not set,
 .Nm
 translates from
 .Ar set1
@@ -60,7 +62,10 @@ by index or character class.
 If
 .Ar set2
 is shorter than
-.Ar set1 ,
+.Ar set1
+or
+.Ar set1
+is a character class,
 overflowing characters translate to the last character in
 .Ar set2 .
 .Sh EXIT STATUS



[hackers] [sbase] Revamp tr(1) set parsing and handling || FRIGN

2016-10-05 Thread git
commit bc4c293fe59de042c1ac71793d33bb685c4fb915
Author: FRIGN 
AuthorDate: Wed Oct 5 21:18:24 2016 +0200
Commit: FRIGN 
CommitDate: Wed Oct 5 21:18:24 2016 +0200

Revamp tr(1) set parsing and handling

If you look at GNU coreutils, they do not support the mappings

$ echo "1234abc" | tr "[:alnum:]" "[:upper:]"

$ echo "ABCabc" | tr -c "[:upper:]" "[l*]"

to only give a few examples. This commit broadens the scope of tr(1)
as far as humanly possible to map between classes and non-classes,
making tr a usable tool and actually fulfilling user expectations.
Posix really is of no help here as it still kind of assumes the
fixed ASCII table instead of complex Unicode code points or even
Grapheme clusters.

diff --git a/tr.c b/tr.c
index d6d1044..926d1eb 100644
--- a/tr.c
+++ b/tr.c
@@ -119,7 +119,7 @@ nextbrack:
}
 
/* REPEAT  [_*n] (only allowed in set2) */
-   if (j - i > 2 && rstr[i + 2] == '*' && set1ranges > 0) {
+   if (j - i > 2 && rstr[i + 2] == '*') {
/* check if right side of '*' is a number */
q = 0;
factor = 1;
@@ -138,7 +138,7 @@ nextbrack:
}
(*set)[setranges].start = rstr[i + 1];
(*set)[setranges].end   = rstr[i + 1];
-   (*set)[setranges].quant = q ? q : setlen(set1, 
set1ranges);
+   (*set)[setranges].quant = q ? q : setlen(set1, 
MAX(set1ranges, 1));
setranges++;
i = j;
continue;
@@ -196,69 +196,79 @@ main(int argc, char *argv[])
set1ranges = makeset(argv[0], , );
if (argc == 2)
set2ranges = makeset(argv[1], , );
-   if (dflag == sflag && !set2ranges && !set2check)
-   eprintf("set2 must be non-empty.\n");
-   if (argc == 2 && !set2check != !set1check)
-   eprintf("can't mix classes with non-classes.\n");
-   if (set2check && set2check != islowerrune && set2check != isupperrune)
-   eprintf("set2 can only be the 'lower' or 'upper' class.\n");
-   if (set2check && cflag && !dflag)
-   eprintf("set2 can't be imaged to from a complement.\n");
+
+   if (!dflag) {
+   /* sanity checks as we are translating */
+   if (!set2ranges && !set2check)
+   eprintf("cannot map to an empty set.\n");
+   if (set2check && set2check != islowerrune &&
+   set2check != isupperrune) {
+   eprintf("can only map to 'lower' and 'upper' class.\n");
+   }
+   }
 read:
if (!efgetrune(, stdin, "")) {
ret |= fshut(stdin, "") | fshut(stdout, "");
return ret;
}
-   off1 = off2 = 0;
-   for (i = 0; i < set1ranges; i++) {
+   for (i = 0, off1 = 0; i < set1ranges; i++, off1 += rangelen(set1[i])) {
if (set1[i].start <= r && r <= set1[i].end) {
if (dflag) {
-   if (!cflag)
-   goto read;
+   if (cflag)
+   continue;
else
-   goto write;
+   goto read;
}
if (cflag)
goto write;
-   for (m = 0; m < i; m++)
-   off1 += rangelen(set1[m]);
-   off1 += r - set1[m].start;
-   if (off1 > setlen(set2, set2ranges) - 1) {
-   r = set2[set2ranges - 1].end;
-   goto write;
-   }
-   for (m = 0; m < set2ranges; m++) {
-   if (off2 + rangelen(set2[m]) > off1) {
-   m++;
-   break;
+
+   /* map r to set2 */
+   if (set2check) {
+   if (set2check == islowerrune)
+   r = tolowerrune(r);
+   else
+   r = toupperrune(r);
+   } else {
+   off1 += r - set1[i].start;
+   if (off1 > setlen(set2, set2ranges) - 1) {
+   r = set2[set2ranges - 1].end;
+   goto write;
}
-   off2 += 

Re: [hackers] [st][PATCH] Make strdump(), csidump(), print to stderr

2016-10-05 Thread Martin Kühne
Looking at the original mail again, please disregard. I've made a fool
of myself.

cheers!
mar77i



[hackers] [sbase] use only one getconf header || Evan Gates

2016-10-05 Thread git
commit de28c8bfa7ef799ee2e8e49e8a3a1828f80a7442
Author: Evan Gates 
AuthorDate: Mon Oct 3 15:55:22 2016 -0700
Commit: FRIGN 
CommitDate: Wed Oct 5 18:48:10 2016 +0200

use only one getconf header

this simplifies the getconf.sh script and handling parallel make

diff --git a/Makefile b/Makefile
index 6b2bfdf..25bab70 100644
--- a/Makefile
+++ b/Makefile
@@ -205,10 +205,10 @@ $(LIBUTIL): $(LIBUTILOBJ)
$(AR) rc $@ $?
$(RANLIB) $@
 
-getconf.c: confstr_l.h limits_l.h sysconf_l.h pathconf_l.h
+getconf.o: getconf.h
 
-confstr_l.h limits_l.h sysconf_l.h pathconf_l.h: getconf.sh
-   ./getconf.sh
+getconf.h: getconf.sh
+   ./getconf.sh > $@
 
 install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
@@ -234,7 +234,7 @@ dist: clean
 sbase-box: $(LIB) $(SRC)
mkdir -p build
cp $(HDR) build
-   cp confstr_l.h limits_l.h sysconf_l.h pathconf_l.h build
+   cp getconf.h build
for f in $(SRC); do sed "s/^main(/$$(echo "$${f%.c}" | sed s/-/_/g)_&/" 
< $$f > build/$$f; done
echo '#include '  
   > build/$@.c
echo '#include '   
  >> build/$@.c
@@ -270,7 +270,7 @@ sbase-box-uninstall: uninstall
 
 clean:
rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz
-   rm -f confstr_l.h limits_l.h sysconf_l.h pathconf_l.h
+   rm -f getconf.h
 
 .PHONY:
all install uninstall dist sbase-box sbase-box-install 
sbase-box-uninstall clean
diff --git a/getconf.c b/getconf.c
index 94bff80..e611659 100644
--- a/getconf.c
+++ b/getconf.c
@@ -12,22 +12,7 @@ struct var {
long v;
 };
 
-static const struct var pathconf_l[] = {
-#include "pathconf_l.h"
-};
-
-static const struct var sysconf_l[] = {
-#include "sysconf_l.h"
-};
-
-static const struct var confstr_l[] = {
-#include "confstr_l.h"
-};
-
-static const struct var limits_l[] = {
-#include "limits_l.h"
-};
-
+#include "getconf.h"
 
 void
 usage(void)
diff --git a/getconf.sh b/getconf.sh
index cca5873..e826385 100755
--- a/getconf.sh
+++ b/getconf.sh
@@ -1,14 +1,12 @@
 #!/bin/sh
 
-ifdef()
-{
- awk '{printf("#ifdef %s\n"\
-  "\t{\"%s\",\t%s},\n"\
-  "#endif\n", $2, $1, $2)}' > $1
+ifdef() {
+   printf 'static const struct var %s[] = {\n' "$1"
+   awk '{printf("#ifdef %s\n\t{\"%s\",\t%s},\n#endif\n", $2, $1, $2)}'
+   echo '};'
 }
 
-
-cat <

[hackers] [sbase] getconf.sh: Be more explicit we are using a heredoc here || FRIGN

2016-10-05 Thread git
commit fac091b7cc918f2a7c4c20038141efc2279f03c7
Author: FRIGN 
AuthorDate: Tue Oct 4 01:20:52 2016 +0200
Commit: FRIGN 
CommitDate: Wed Oct 5 18:48:10 2016 +0200

getconf.sh: Be more explicit we are using a heredoc here

diff --git a/getconf.sh b/getconf.sh
index e826385..0df60f9 100755
--- a/getconf.sh
+++ b/getconf.sh
@@ -6,7 +6,7 @@ ifdef() {
echo '};'
 }
 
-cat <

[hackers] [sbase] test: -erwx test against effetive uid/gid, not real || Mattias Andrée

2016-10-05 Thread git
commit e8a3a3ec374c4321cb00c323749d29f7ad60ff91
Author: Mattias Andrée 
AuthorDate: Thu Mar 31 03:03:37 2016 +0200
Commit: FRIGN 
CommitDate: Wed Oct 5 18:48:10 2016 +0200

test: -erwx test against effetive uid/gid, not real

Signed-off-by: Mattias Andrée 

diff --git a/test.c b/test.c
index 3fe12c3..6045e4e 100644
--- a/test.c
+++ b/test.c
@@ -2,6 +2,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 
@@ -71,10 +72,10 @@ static int unary_u(char *s) { struct stat buf; if ( stat(s, 
)) return 0; ret
 static int unary_n(char *s) { return  *s; }
 static int unary_z(char *s) { return !*s; }
 
-static int unary_e(char *s) { return !access(s, F_OK); }
-static int unary_r(char *s) { return !access(s, R_OK); }
-static int unary_w(char *s) { return !access(s, W_OK); }
-static int unary_x(char *s) { return !access(s, X_OK); }
+static int unary_e(char *s) { return !faccessat(AT_FDCWD, s, F_OK, 
AT_EACCESS); }
+static int unary_r(char *s) { return !faccessat(AT_FDCWD, s, R_OK, 
AT_EACCESS); }
+static int unary_w(char *s) { return !faccessat(AT_FDCWD, s, W_OK, 
AT_EACCESS); }
+static int unary_x(char *s) { return !faccessat(AT_FDCWD, s, X_OK, 
AT_EACCESS); }
 
 static int unary_t(char *s) { int fd = enstrtonum(2, s, 0, INT_MAX); return 
isatty(fd); }
 



[hackers] [sbase] pathchk: fixes and cleanup || Mattias Andrée

2016-10-05 Thread git
commit da04e4cc2afd848e46287ac60f930fa3335b4316
Author: Mattias Andrée 
AuthorDate: Wed Mar 30 01:46:25 2016 +0200
Commit: FRIGN 
CommitDate: Wed Oct 5 18:48:10 2016 +0200

pathchk: fixes and cleanup

Signed-off-by: Mattias Andrée 

diff --git a/pathchk.c b/pathchk.c
index a72e8fd..6346de0 100644
--- a/pathchk.c
+++ b/pathchk.c
@@ -1,11 +1,12 @@
 /* See LICENSE file for copyright and license details. */
+#include 
+
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
 
 #include "util.h"
 
@@ -24,16 +25,12 @@ pathchk(char *filename)
struct stat st;
 
/* Empty? */
-   if (extra && !*filename) {
-   weprintf("%s: empty filename\n", argv0);
-   return 1;
-   }
+   if (extra && !*filename)
+   eprintf("empty filename\n");
 
/* Leading hyphen? */
-   if (extra && ((*filename == '-') || strstr(filename, "/-"))) {
-   weprintf("%s: %s: leading '-' in component of filename\n", 
argv0, filename);
-   return 1;
-   }
+   if (extra && ((*filename == '-') || strstr(filename, "/-")))
+   eprintf("%s: leading '-' in component of filename\n", filename);
 
/* Nonportable character? */
 #ifdef SYSTEM_CHARACTER_SET
@@ -45,38 +42,31 @@ pathchk(char *filename)
character_set = "/"PORTABLE_CHARACTER_SET;
if (character_set && *(invalid = filename + strspn(filename, 
character_set))) {
for (invalid_end = invalid + 1; *invalid_end & 0x80; 
invalid_end++);
-   weprintf("%s: %s: ", argv0, filename);
+   p = estrdup(filename);
*invalid_end = 0;
-   weprintf("nonportable character '%s'\n", invalid);
-   return 1;
+   eprintf("%s: nonportable character '%s'\n", p, invalid);
}
 
/* Symlink error? Non-searchable directory? */
if (lstat(filename, ) && errno != ENOENT) {
/* lstat rather than stat, so that if filename is a bad 
symlink, but
 * all parents are OK, no error will be detected. */
-   weprintf("%s: %s:", argv0, filename);
-   return 1;
+   eprintf("%s:", filename);
}
 
/* Too long pathname? */
maxlen = most ? _POSIX_PATH_MAX : PATH_MAX;
-   if (strlen(filename) >= maxlen) {
-   weprintf("%s: %s: is longer than %zu bytes\n",
-argv0, filename, maxlen);
-   return 1;
-   }
+   if (strlen(filename) >= maxlen)
+   eprintf("%s: is longer than %zu bytes\n", filename, maxlen);
 
/* Too long component? */
maxlen = most ? _POSIX_NAME_MAX : NAME_MAX;
for (p = filename; p; p = q) {
q = strchr(p, '/');
len = q ? (size_t)(q++ - p) : strlen(p);
-   if (len > maxlen) {
-   weprintf("%s: %s: includes component longer than %zu 
bytes\n",
-argv0, filename, maxlen);
-   return 1;
-   }
+   if (len > maxlen)
+   eprintf("%s: includes component longer than %zu 
bytes\n",
+filename, maxlen);
}
 
return 0;



[hackers] [sbase] find: check whether readdir failed, and properly check timestamps || Mattias Andrée

2016-10-05 Thread git
commit 96ccf5172d21cb355144e936232d328ab9aa4f31
Author: Mattias Andrée 
AuthorDate: Wed Mar 30 03:04:45 2016 +0200
Commit: FRIGN 
CommitDate: Wed Oct 5 18:48:10 2016 +0200

find: check whether readdir failed, and properly check timestamps

Signed-off-by: Mattias Andrée 

diff --git a/find.c b/find.c
index ad0c731..5f75735 100644
--- a/find.c
+++ b/find.c
@@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -322,24 +323,21 @@ static int
 pri_atime(struct arg *arg)
 {
struct narg *n = arg->extra.p;
-   time_t time = (n->n - start.tv_sec) / 86400;
-   return n->cmp(time, n->n);
+   return n->cmp((start.tv_sec - arg->st->st_atime) / 86400, n->n);
 }
 
 static int
 pri_ctime(struct arg *arg)
 {
struct narg *n = arg->extra.p;
-   time_t time = (n->n - start.tv_sec) / 86400;
-   return n->cmp(time, n->n);
+   return n->cmp((start.tv_sec - arg->st->st_ctime) / 86400, n->n);
 }
 
 static int
 pri_mtime(struct arg *arg)
 {
struct narg *n = arg->extra.p;
-   time_t time = (n->n - start.tv_sec) / 86400;
-   return n->cmp(time, n->n);
+   return n->cmp((start.tv_sec - arg->st->st_mtime) / 86400, n->n);
 }
 
 static int
@@ -397,7 +395,7 @@ pri_exec(struct arg *arg)
weprintf("exec %s failed:", *e->argv);
_exit(1);
}
-   /* FIXME: propper course of action for all waitpid() on EINTR? 
*/
+   /* FIXME: proper course of action for all waitpid() on EINTR? */
waitpid(pid, , 0);
return !!status;
}
@@ -969,8 +967,7 @@ find(char *path, struct findhist *hist)
return;
}
 
-   /* FIXME: check errno to see if we are done or encountered an error? */
-   while ((de = readdir(dir))) {
+   while (errno = 0, (de = readdir(dir))) {
size_t pathcap = len + strlen(de->d_name);
char pathbuf[pathcap], *p;
 
@@ -983,7 +980,12 @@ find(char *path, struct findhist *hist)
estrlcat(pathbuf, de->d_name, pathcap);
find(pathbuf, );
}
-   closedir(dir); /* check return value? */
+   if (errno) {
+   weprintf("readdir %s:", path);
+   closedir(dir);
+   return;
+   }
+   closedir(dir);
 
if (gflags.depth)
eval(root, );



Re: [hackers] [st][PATCH] Make strdump(), csidump(), print to stderr

2016-10-05 Thread Paride Legovini
On 2016-10-05 17:41, Martin Kühne wrote:
> If I set st to dumping, I want it to dump to stdout, obviously. The
> dumping in and on itself is not an error.

I don't think this would interfere with dumping to file or stdout (-o
option, if that's what you're referring to).

Paride




Re: [hackers] [st][PATCH] Make strdump(), csidump(), print to stderr

2016-10-05 Thread Martin Kühne
If I set st to dumping, I want it to dump to stdout, obviously. The
dumping in and on itself is not an error.
I suggest to instead add setbuf(stdout, NULL) at the top of the place
where the dump argument is parsed.

cheers!
mar77i



[hackers] [st][PATCH] Make strdump(), csidump(), print to stderr

2016-10-05 Thread Paride Legovini
The two functions strdump(), csidump() are called to show errors and
their output is introduced by a message printed to stderr. Thus, it it
more consistent to have them print to stderr.

Moreover stderr is unbuffered (at least on Linux), making problems
immediately visible.
---
 st.c | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/st.c b/st.c
index 6c16386..b2c66de 100644
--- a/st.c
+++ b/st.c
@@ -2484,22 +2484,22 @@ csidump(void)
int i;
uint c;
 
-   printf("ESC[");
+   fprintf(stderr, "ESC[");
for (i = 0; i < csiescseq.len; i++) {
c = csiescseq.buf[i] & 0xff;
if (isprint(c)) {
-   putchar(c);
+   putc(c, stderr);
} else if (c == '\n') {
-   printf("(\\n)");
+   fprintf(stderr, "(\\n)");
} else if (c == '\r') {
-   printf("(\\r)");
+   fprintf(stderr, "(\\r)");
} else if (c == 0x1b) {
-   printf("(\\e)");
+   fprintf(stderr, "(\\e)");
} else {
-   printf("(%02x)", c);
+   fprintf(stderr, "(%02x)", c);
}
}
-   putchar('\n');
+   putc('\n', stderr);
 }
 
 void
@@ -2588,24 +2588,25 @@ strdump(void)
int i;
uint c;
 
-   printf("ESC%c", strescseq.type);
+   fprintf(stderr, "ESC%c", strescseq.type);
for (i = 0; i < strescseq.len; i++) {
c = strescseq.buf[i] & 0xff;
if (c == '\0') {
+   putc('\n', stderr);
return;
} else if (isprint(c)) {
-   putchar(c);
+   putc(c, stderr);
} else if (c == '\n') {
-   printf("(\\n)");
+   fprintf(stderr, "(\\n)");
} else if (c == '\r') {
-   printf("(\\r)");
+   fprintf(stderr, "(\\r)");
} else if (c == 0x1b) {
-   printf("(\\e)");
+   fprintf(stderr, "(\\e)");
} else {
-   printf("(%02x)", c);
+   fprintf(stderr, "(%02x)", c);
}
}
-   printf("ESC\\\n");
+   fprintf(stderr, "ESC\\\n");
 }
 
 void
-- 
2.9.3




[hackers] [st][PATCH 1/2] Add tmux capabilities to st.info

2016-10-05 Thread Paride Legovini
---
 st.info | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/st.info b/st.info
index d411be7..13cc8eb 100644
--- a/st.info
+++ b/st.info
@@ -185,7 +185,10 @@ st| simpleterm,
tsl=\E]0;,
xenl,
vpa=\E[%i%p1%dd,
-
+# Tmux unofficial extensions, see TERMINFO EXTENSIONS in tmux(1)
+   Se,
+   Ss,
+   Tc,
 
 st-256color| simpleterm with 256 colors,
use=st,
-- 
2.9.3




[hackers] [st][PATCH 2/2] tic -s -> tic -sx (Treat unknown capabilities as user-defined.)

2016-10-05 Thread Paride Legovini
---
 FAQ  | 2 +-
 Makefile | 2 +-
 README   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/FAQ b/FAQ
index 3502c60..4defff9 100644
--- a/FAQ
+++ b/FAQ
@@ -6,7 +6,7 @@ Use the excellent tool of [utmp](http://git.suckless.org/utmp/) 
for this task.
 
 It means that st doesn’t have any terminfo entry on your system. Chances are
 you did not `make install`. If you just want to test it without installing it,
-you can manualy run `tic -s st.info`.
+you can manualy run `tic -sx st.info`.
 
 ## Nothing works, and nothing is said about an unknown terminal!
 
diff --git a/Makefile b/Makefile
index 6158ab2..fb026c4 100644
--- a/Makefile
+++ b/Makefile
@@ -49,7 +49,7 @@ install: all
@sed "s/VERSION/${VERSION}/g" < st.1 > ${DESTDIR}${MANPREFIX}/man1/st.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/st.1
@echo Please see the README file regarding the terminfo entry of st.
-   @tic -s st.info
+   @tic -sx st.info
 
 uninstall:
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
diff --git a/README b/README
index b38c88b..6a846ed 100644
--- a/README
+++ b/README
@@ -24,7 +24,7 @@ Running st
 If you did not install st with make clean install, you must compile
 the st terminfo entry with the following command:
 
-tic -s st.info
+tic -sx st.info
 
 See the man page for additional details.
 
-- 
2.9.3




[hackers] [scc] [cc2] Improve overflow check in cc2 || Roberto E. Vargas Caballero

2016-10-05 Thread git
commit cff1e86a7f61535db92a132d29fce0e805c8e529
Author: Roberto E. Vargas Caballero 
AuthorDate: Wed Oct 5 14:06:35 2016 +0200
Commit: Roberto E. Vargas Caballero 
CommitDate: Wed Oct 5 14:06:35 2016 +0200

[cc2] Improve overflow check in cc2

diff --git a/cc2/symbol.c b/cc2/symbol.c
index 271883b..9b1fdbc 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
@@ -50,7 +50,7 @@ getsym(unsigned id)
Symbol **htab, *sym;
static unsigned short num;
 
-   if (id > USHRT_MAX)
+   if (id >= USHRT_MAX)
error(EBADID);
 
htab = [id & NR_SYMHASH-1];



[hackers] [st][PATCH] Remove unreachable code

2016-10-05 Thread Iouri Kloubakov

Hi,

This is my first small patch.

---
 st.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/st.c b/st.c
index 6c16386..a6a4fc4 100644
--- a/st.c
+++ b/st.c
@@ -3756,8 +3756,6 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph 
base, int len, int x, i
if (base.fg == defaultfg) {
if (base.mode & ATTR_ITALIC)
base.fg = defaultitalic;
-   else if ((base.mode & ATTR_ITALIC) && (base.mode & ATTR_BOLD))
-   base.fg = defaultitalic;
else if (base.mode & ATTR_UNDERLINE)
base.fg = defaultunderline;
}
--
2.7.4