Re: [hackers] [sbase] tput should be in ubase || sin

2015-02-25 Thread Roberto E. Vargas Caballero

>  tabs
> -tput
>  
>  The  following  programs have  been  imported  from  OpenBSD and  need
>  replacing or cleaning up:

The same applies to tabs. It needs terminfo.

Regards,




[hackers] [ubase] add tput to TODO || sin

2015-02-25 Thread git
commit 9297082b969917a3a1e715c5855d3af2960b484d
Author: sin 
Date:   Wed Feb 25 22:04:21 2015 +

add tput to TODO

diff --git a/TODO b/TODO
index c33c2ec..6eeb71d 100644
--- a/TODO
+++ b/TODO
@@ -27,6 +27,7 @@ fakeroot
 less or pg
 ionice
 fuser
+tput
 
 Misc
 



[hackers] [sbase] tput should be in ubase || sin

2015-02-25 Thread git
commit a06db62e1187e2f2c1dfb33bce0ffeaffa4918da
Author: sin 
Date:   Wed Feb 25 22:03:56 2015 +

tput should be in ubase

diff --git a/TODO b/TODO
index c0dafda..69578ab 100644
--- a/TODO
+++ b/TODO
@@ -18,7 +18,6 @@ patch
 pathchk
 stty
 tabs
-tput
 
 The  following  programs have  been  imported  from  OpenBSD and  need
 replacing or cleaning up:



[hackers] [sbase] re-typedef Test, use NOTREACHED comment instead of comma operator, both as per style guide || Evan Gates

2015-02-25 Thread git
commit 2f181afa2da61626955b9a5ea1c8617db00af075
Author: Evan Gates 
Date:   Wed Feb 25 09:01:20 2015 -0800

re-typedef Test, use NOTREACHED comment instead of comma operator, both as 
per style guide

diff --git a/test.c b/test.c
index 957b205..8395d1d 100644
--- a/test.c
+++ b/test.c
@@ -39,12 +39,12 @@ static int binary_ge(char *s1, char *s2) { long long a = 
STOI(s1), b = STOI(s2);
 static int binary_lt(char *s1, char *s2) { long long a = STOI(s1), b = 
STOI(s2); return a <  b; }
 static int binary_le(char *s1, char *s2) { long long a = STOI(s1), b = 
STOI(s2); return a <= b; }
 
-struct test {
+typedef struct {
char *name;
int (*func)();
-};
+} Test;
 
-static struct test unary[] = {
+static Test unary[] = {
{ "-b", unary_b },
{ "-c", unary_c },
{ "-d", unary_d },
@@ -67,7 +67,7 @@ static struct test unary[] = {
{ NULL, NULL },
 };
 
-static struct test binary[] = {
+static Test binary[] = {
{ "="  , binary_se },
{ "!=" , binary_sn },
{ "-eq", binary_eq },
@@ -80,10 +80,10 @@ static struct test binary[] = {
{ NULL, NULL },
 };
 
-static struct test *
-find_test(struct test *tests, char *name)
+static Test *
+find_test(Test *tests, char *name)
 {
-   struct test *t;
+   Test *t;
 
for (t = tests; t->name; ++t)
if (strcmp(t->name, name) == 0)
@@ -106,7 +106,7 @@ onearg(char **argv)
 static int
 twoarg(char **argv)
 {
-   struct test *t = find_test(unary, *argv);
+   Test *t = find_test(unary, *argv);
 
if (strcmp(argv[0], "!") == 0)
return !onearg(argv + 1);
@@ -114,13 +114,14 @@ twoarg(char **argv)
if (t)
return t->func(argv[1]);
 
-   return enprintf(2, "bad unary test %s\n", argv[0]), 0;
+   enprintf(2, "bad unary test %s\n", argv[0]);
+   return 0; /* NOTREACHED */
 }
 
 static int
 threearg(char **argv)
 {
-   struct test *t = find_test(binary, argv[1]);
+   Test *t = find_test(binary, argv[1]);
 
if (t)
return t->func(argv[0], argv[2]);
@@ -128,7 +129,8 @@ threearg(char **argv)
if (strcmp(argv[0], "!") == 0)
return !twoarg(argv + 1);
 
-   return enprintf(2, "bad binary test %s\n", argv[1]), 0;
+   enprintf(2, "bad binary test %s\n", argv[1]);
+   return 0; /* NOTREACHED */
 }
 
 static int
@@ -137,7 +139,8 @@ fourarg(char **argv)
if (strcmp(argv[0], "!") == 0)
return !threearg(argv + 1);
 
-   return enprintf(2, "too many arguments\n"), 0;
+   enprintf(2, "too many arguments\n");
+   return 0; /* NOTREACHED */
 }
 
 int



[hackers] [sbase] use struct literal instead of filling each field manually || Evan Gates

2015-02-25 Thread git
commit cd7a1002b7082db4251eb9c5ba35f805a4269343
Author: Evan Gates 
Date:   Tue Feb 24 18:44:13 2015 -0800

use struct literal instead of filling each field manually

diff --git a/find.c b/find.c
index 1461895..6dacc2c 100644
--- a/find.c
+++ b/find.c
@@ -853,11 +853,8 @@ parse(int argc, char **argv)
 * if there was an expression but no -print, -exec, or -ok, add -a 
-print
 * in rpn, not infix
 */
-   if (print) {
-   out->u.pinfo = find_primary("-print");
-   out->type = PRIM;
-   out++;
-   }
+   if (print)
+   *out++ = (Tok){ .u.pinfo = find_primary("-print"), .type = PRIM 
};
if (print == 2)
*out++ = and;
 



[hackers] [sbase] a bunch of cleanup || Evan Gates

2015-02-25 Thread git
commit f46d584c36ac0ab3c1c0d19e987ef9082348f31b
Author: Evan Gates 
Date:   Tue Feb 24 19:34:36 2015 -0800

a bunch of cleanup

diff --git a/find.c b/find.c
index 6dacc2c..3ee8182 100644
--- a/find.c
+++ b/find.c
@@ -35,6 +35,7 @@ typedef struct {
int(*func)(Arg *arg);
char **(*getarg)(char **argv, Extra *extra);
void   (*freearg)(Extra extra);
+   char   narg; /* -xdev, -depth, -print don't take args but have getarg() 
*/
 } Pri_info;
 
 /* Information about operators, for lookup table */
@@ -135,6 +136,7 @@ static int pri_depth  (Arg *arg);
 /* Getargs */
 static char **get_name_arg (char **argv, Extra *extra);
 static char **get_path_arg (char **argv, Extra *extra);
+static char **get_xdev_arg (char **argv, Extra *extra);
 static char **get_perm_arg (char **argv, Extra *extra);
 static char **get_type_arg (char **argv, Extra *extra);
 static char **get_n_arg(char **argv, Extra *extra);
@@ -143,7 +145,9 @@ static char **get_group_arg(char **argv, Extra *extra);
 static char **get_size_arg (char **argv, Extra *extra);
 static char **get_exec_arg (char **argv, Extra *extra);
 static char **get_ok_arg   (char **argv, Extra *extra);
+static char **get_print_arg(char **argv, Extra *extra);
 static char **get_newer_arg(char **argv, Extra *extra);
+static char **get_depth_arg(char **argv, Extra *extra);
 
 /* Freeargs */
 static void free_extra   (Extra extra);
@@ -151,6 +155,7 @@ static void free_exec_arg(Extra extra);
 static void free_ok_arg  (Extra extra);
 
 /* Parsing/Building/Running */
+static void fill_narg(char *s, Narg *n);
 static Pri_info *find_primary(char *name);
 static Op_info *find_op(char *name);
 static void parse(int argc, char **argv);
@@ -165,28 +170,28 @@ static int cmp_lt(int a, int b) { return a <  b; }
 
 /* order from find(1p), may want to alphabetize */
 static Pri_info primaries[] = {
-   { "-name"   , pri_name   , get_name_arg , NULL  },
-   { "-path"   , pri_path   , get_path_arg , NULL  },
-   { "-nouser" , pri_nouser , NULL , NULL  },
-   { "-nogroup", pri_nogroup, NULL , NULL  },
-   { "-xdev"   , pri_xdev   , NULL , NULL  },
-   { "-prune"  , pri_prune  , NULL , NULL  },
-   { "-perm"   , pri_perm   , get_perm_arg , free_extra},
-   { "-type"   , pri_type   , get_type_arg , NULL  },
-   { "-links"  , pri_links  , get_n_arg, free_extra},
-   { "-user"   , pri_user   , get_user_arg , NULL  },
-   { "-group"  , pri_group  , get_group_arg, NULL  },
-   { "-size"   , pri_size   , get_size_arg , free_extra},
-   { "-atime"  , pri_atime  , get_n_arg, free_extra},
-   { "-ctime"  , pri_ctime  , get_n_arg, free_extra},
-   { "-mtime"  , pri_mtime  , get_n_arg, free_extra},
-   { "-exec"   , pri_exec   , get_exec_arg , free_exec_arg },
-   { "-ok" , pri_ok , get_ok_arg   , free_ok_arg   },
-   { "-print"  , pri_print  , NULL , NULL  },
-   { "-newer"  , pri_newer  , get_newer_arg, NULL  },
-   { "-depth"  , pri_depth  , NULL , NULL  },
-
-   { NULL, NULL, NULL, NULL }
+   { "-name"   , pri_name   , get_name_arg , NULL , 1 },
+   { "-path"   , pri_path   , get_path_arg , NULL , 1 },
+   { "-nouser" , pri_nouser , NULL , NULL , 1 },
+   { "-nogroup", pri_nogroup, NULL , NULL , 1 },
+   { "-xdev"   , pri_xdev   , get_xdev_arg , NULL , 0 },
+   { "-prune"  , pri_prune  , NULL , NULL , 1 },
+   { "-perm"   , pri_perm   , get_perm_arg , free_extra   , 1 },
+   { "-type"   , pri_type   , get_type_arg , NULL , 1 },
+   { "-links"  , pri_links  , get_n_arg, free_extra   , 1 },
+   { "-user"   , pri_user   , get_user_arg , NULL , 1 },
+   { "-group"  , pri_group  , get_group_arg, NULL , 1 },
+   { "-size"   , pri_size   , get_size_arg , free_extra   , 1 },
+   { "-atime"  , pri_atime  , get_n_arg, free_extra   , 1 },
+   { "-ctime"  , pri_ctime  , get_n_arg, free_extra   , 1 },
+   { "-mtime"  , pri_mtime  , get_n_arg, free_extra   , 1 },
+   { "-exec"   , pri_exec   , get_exec_arg , free_exec_arg, 1 },
+   { "-ok" , pri_ok , get_ok_arg   , free_ok_arg  , 1 },
+   { "-print"  , pri_print  , get_print_arg, NULL , 0 },
+   { "-newer"  , pri_newer  , get_newer_arg, NULL , 1 },
+   { "-depth"  , pri_depth  , get_depth_arg, NULL , 0 },
+
+   { NULL, NULL, NULL, NULL, 0 }
 };
 
 static Op_info ops[] = {
@@ -216,6 +221,7 @@ static struct {
char l; /* -L, follow all symlinks (command line and search)  */
char prune; /* hit -prune */
char xdev ; /* -xdev, prune directories on different devices  */
+ 

[hackers] [sbase] no need for array of function pointers for comparisons, just use the necessary function pointer itself || Evan Gates

2015-02-25 Thread git
commit 71f39c202a0e7006b68fb829388864b72161d919
Author: Evan Gates 
Date:   Tue Feb 24 18:19:49 2015 -0800

no need for array of function pointers for comparisons, just use the 
necessary function pointer itself

diff --git a/find.c b/find.c
index 66f5672..1461895 100644
--- a/find.c
+++ b/find.c
@@ -75,9 +75,7 @@ typedef struct {
 /* for all arguments that take a number
  * +n, n, -n mean > n, == n, < n respectively */
 typedef struct {
-   enum {
-   GT, EQ, LT
-   } cmp;
+   int (*cmp)(int a, int b);
int n;
 } Narg;
 
@@ -165,12 +163,6 @@ static int cmp_gt(int a, int b) { return a >  b; }
 static int cmp_eq(int a, int b) { return a == b; }
 static int cmp_lt(int a, int b) { return a <  b; }
 
-static int (*cmps[])(int, int) = {
-   [GT] = cmp_gt,
-   [EQ] = cmp_eq,
-   [LT] = cmp_lt,
-};
-
 /* order from find(1p), may want to alphabetize */
 static Pri_info primaries[] = {
{ "-name"   , pri_name   , get_name_arg , NULL  },
@@ -294,7 +286,7 @@ static int
 pri_links(Arg *arg)
 {
Narg *n = arg->extra.p;
-   return cmps[n->cmp](arg->st->st_nlink, n->n);
+   return n->cmp(arg->st->st_nlink, n->n);
 }
 
 static int
@@ -318,7 +310,7 @@ pri_size(Arg *arg)
if (!s->bytes)
size = size / 512 + !!(size % 512);
 
-   return cmps[s->n.cmp](size, s->n.n);
+   return s->n.cmp(size, s->n.n);
 }
 
 /* FIXME: ignoring nanoseconds in atime, ctime, mtime */
@@ -327,7 +319,7 @@ pri_atime(Arg *arg)
 {
Narg *n = arg->extra.p;
time_t time = (n->n - start.tv_sec) / 86400;
-   return cmps[n->cmp](time, n->n);
+   return n->cmp(time, n->n);
 }
 
 static int
@@ -335,7 +327,7 @@ pri_ctime(Arg *arg)
 {
Narg *n = arg->extra.p;
time_t time = (n->n - start.tv_sec) / 86400;
-   return cmps[n->cmp](time, n->n);
+   return n->cmp(time, n->n);
 }
 
 static int
@@ -343,7 +335,7 @@ pri_mtime(Arg *arg)
 {
Narg *n = arg->extra.p;
time_t time = (n->n - start.tv_sec) / 86400;
-   return cmps[n->cmp](time, n->n);
+   return n->cmp(time, n->n);
 }
 
 static int
@@ -514,9 +506,9 @@ get_n_arg(char **argv, Extra *extra)
char *end;
 
switch (**argv) {
-   case '+': n->cmp = GT; (*argv)++; break;
-   case '-': n->cmp = LT; (*argv)++; break;
-   default : n->cmp = EQ;break;
+   case '+': n->cmp = cmp_gt; (*argv)++; break;
+   case '-': n->cmp = cmp_lt; (*argv)++; break;
+   default : n->cmp = cmp_eq;break;
}
 
n->n = strtol(*argv, &end, 10);
@@ -573,9 +565,9 @@ get_size_arg(char **argv, Extra *extra)
 
/* FIXME: no need to have this in get_n_arg and here */
switch (**argv) {
-   case '+': s->n.cmp = GT; (*argv)++; break;
-   case '-': s->n.cmp = LT; (*argv)++; break;
-   default : s->n.cmp = EQ;break;
+   case '+': s->n.cmp = cmp_gt; (*argv)++; break;
+   case '-': s->n.cmp = cmp_lt; (*argv)++; break;
+   default : s->n.cmp = cmp_eq;break;
}
 
s->n.n = strtol(*argv, &end, 10);