Re: [hackers] [PATCH][sbase] paste: Allow null delim

2020-03-05 Thread Evan Gates
On Thu, Mar 5, 2020, 02:16 Quentin Rameau  wrote:
>
> On Thu, 5 Mar 2020 01:42:37 -0800
> Michael Forney  wrote:
>
> > >> and `-d""` is invalid, since paste(1) must follow the
> > >> utility syntax guidelines (guideline 7).
> > >
> > > Not sure what you mean there, -d"" is the concatenation of -d and
> > > '', which is standard.
> > > Did you quote the correct guideline? “Guideline 7: Option-arguments
> > > should not be optional.” here there's an option-argument, that's an
> > > empty string.
> >
> > I guess it's a combination of 6 and 7. Option arguments must be
> > separate parameters and non-optional (unless specified otherwise).
> > There is an exception made that allows conforming implementations to
> > accept an option adjacent with its option argument in the same
> > argument, but I think this only makes sense if the option-argument is
> > non-empty.
> >
> > POSIX says
> >
> >   The construct '\0' is used to mean "no separator" because historical
> > versions of paste did not follow the syntax guidelines, and the
> > command:
> >
> >   paste -d"" ...
> >
> >   could not be handled properly by getopt().
> >
> > I think this implies that `paste -d""` is no longer valid, due to the
> > requirements of the syntax guidelines.
>
> Rather it's due to a getopt() limitation with the (not so) special case
> of an empty string option-argument, but I'm not sure why.

This has nothing to do with getopt(). This is about how the shell parses
and splits words into arguments. -d"" is exactly the same as -d. It is
the same word, adding an empty string to the end of a string does not
change that original string. There is no argument to -d there. If you
wanted to -d"" to pass two arguments "-d" and "" then you'd have to
write a new shell to do that. As it stands shells pass on "-d" in argv
when they come across -d"".



Re: [hackers] [sbase][PATCH] Support -- in all utilities except echo(1)

2019-06-30 Thread Evan Gates
On Fri, Jun 28, 2019 at 3:08 AM Michael Forney  wrote:
>
> Then, maybe something like the following would work for those cases.
>
> ARGBEGIN {
> default:
> goto done;
> } ARGEND
> done:

Seeing as we have more confusion and bugs to deal with in argument
handling, perhaps now is a time to revist the conversation surrounding
getopt(3p)?  There is a POSIX mandated libc function that parses POSIX
options following the utility syntax guidelines.  I strongly suggest
using it.  I know there has been pushback in the past but it's a
portable option that solves our exact problems.  This is why it exists.
It's already part of libc.  We should stop avoiding it in favor of a
difficult to read block of macros that have trouble dealing with corner
cases.  Removing arg.h simplifies sbase code and maintenance and helps
break the cycle of NIH that we often fall into.



Re: [hackers] [sbase] [PATCH] libutil: Rename functions in reserved namespace to prevent potential conflict

2019-05-21 Thread Evan Gates
On Tue, May 21, 2019 at 10:17 AM Quentin Rameau  wrote:
> x* is not a reserved namespace, nor is strsep.

strsep is reserved.

C11 standard section 7.30 Future library directions:

The following names are grouped under individual headers for
convenience. All external names described below are reserved no matter
what headers are included by the program.

7.30.10 String handling 

Function names that begin with str, mem, or wcs and a lowercase letter
may be added to the declarations in the  header.



Re: [hackers][sbase][PATCH v2] testing: add first shell-based tests

2018-10-07 Thread Evan Gates
On Sun, Oct 7, 2018 at 6:38 AM Silvan Jegen  wrote:
> * use "ls" instead of "find" in subshell

Don't do that. Use globs.
https://mywiki.wooledge.org/ParsingLs

> +for testfile in $(ls *.test); do

for testfile in *.test; do



Re: [hackers] [slstatus] Explicitly list component-objects in the Makefile || Laslo Hunhold

2018-05-29 Thread Evan Gates
On Sun, May 27, 2018 at 1:55 PM  wrote:

> commit 0efd64ffaa04715eff9c834c437562952c4531cd
> Author: Laslo Hunhold 
> AuthorDate: Sun May 27 22:40:00 2018 +0200
> Commit: Aaron Marcher 
> CommitDate: Sun May 27 22:55:15 2018 +0200

>  Explicitly list component-objects in the Makefile

>  There was a long tinkering process at farbfeld about this, but the sad
>  truth is that it's the only way to make the Makefile truly portable.
>  Listing it just as

> $(COM:=.o): config.mk $(REQ:=.h)

>  omits the dependency on the c-file itself, which incurs that strictly
>  speaking the object file is not depending on the source file, which is
>  nonsense.

That is not true. The .o already depends on the .c and a target with
prerequisites but no commands just adds to the list of prerequisites for
that target.



Re: [hackers] [sbase] [PATCH] which: absolute path not handled

2017-10-12 Thread Evan Gates
Alex Pilon <a...@alexpilon.ca> wrote:

> > > On 2017-10-10-17, Evan Gates <evan.ga...@gmail.com> wrote:
> > >> I dislike that which(1) is even part of sbase as it's not POSIX. The
> > > > sh builtin 'command' can and should be used in its place as it is
> > > > standardized.
> > >
> > On 10/12/17, Michael Forney <mfor...@mforney.org> wrote:
> > > I'm fine removing it assuming there isn't a huge amount of scripts out
> > > there that depend on it.
> >
> On Thu, Oct 12, 2017 at 04:39:02PM +0200, isabella parakiss wrote:
> > https://github.com/search?l=Shell=which=Code=%E2%9C%93
> >
> > Showing 2,155,004 available code results
> 
> Is there practical value for this project though to support such broken code?
> Are sbase users going to use that code?
> 
> I have to say, the first result lists a page of clearly crappy code on GitHub.
> Truly a mecca of `git`tish code. And I know you guys hate Node and Bash.

Almost all scripts you run into in the wild are crap. If sbase doesn't
supply what that crap uses, no one will use it. There are many of these
non standard tools that people rely on, seq is another.



Re: [hackers] [sbase] [PATCH] which: absolute path not handled

2017-10-12 Thread Evan Gates
Michael Forney <mfor...@mforney.org> wrote:

> On 2017-10-10-17, Evan Gates <evan.ga...@gmail.com> wrote:
> > I dislike that which(1) is even part of sbase as it's not POSIX. The
> > sh builtin 'command' can and should be used in its place as it is
> > standardized.
> 
> I'm fine removing it assuming there isn't a huge amount of scripts out
> there that depend on it.

Unfortunately there are. As much as I dislike having it in sbase it's
pragmatic to include it.



Re: [hackers] [sbase] [PATCH] which: absolute path not handled

2017-10-10 Thread Evan Gates
I dislike that which(1) is even part of sbase as it's not POSIX. The
sh builtin 'command' can and should be used in its place as it is
standardized.

That being said you are correct, that output is terrible and a patch
would be appreciated.


On Tue, Oct 10, 2017 at 3:56 PM Pieter Kockx  wrote:
>
> Hello hackers
>
> $ which /usr/bin/env
> /usr/bin//usr/bin/env
>
> which should probably be idempotent when applied to its own output as in 
> which $(which $(which env)).
>
> The underlying reason is that fstatat ignores dirfd if the the given
> filename is an absolute path.
> The following fix is possible:
>
> if ((dirfd = open(p, O_RDONLY, 0)) >= 0) {
>   if (!fstatat(dirfd, name, , 0) &&
>   S_ISREG(st.st_mode) &&
>   !faccessat(dirfd, name, X_OK, 0)) {
> found = 1;
> +   if (name[0] == '/') {
> + puts(name);
> + close(dirfd);
> + break;
> +   }
> fputs(p, stdout);
> if (i && ptr[i - 1] != '/')
>   fputc('/', stdout);
> puts(name);
> if (!aflag) {
>   close(dirfd);
>   break;
> }
>   }
> }
>
> This fix is not perfect though, since which will (still) return
> a different result if PATH contains no valid directories:
>
> $ PATH=/foo which /usr/bin/env
> Error
> $ PATH=/ which /usr/bin/env
> /usr/bin/env
>
> Patch incoming.
>
> Something else, utilities like which are often used used to check for the 
> existence of a file, so printing an error message seems undesirable.
>
> Thoughts?
>
> -- Pieter



[hackers] Re: [sbase][ubase] maintainers

2017-09-08 Thread Evan Gates
On Fri, Sep 8, 2017 at 9:03 AM, Evan Gates <evan.ga...@gmail.com> wrote:
> Hello suckless,
>
> I decided to become maintainer of sbase and ubase months ago and
> quickly fell out of touch. I apologize for my absence and lack of
> communication on the matter. I'm back and I'm starting to dig through
> the months of patches on the mailing list. If anybody already has a
> list of patches or wants to help please let me know. I should be
> answering email and in #suckless on oftc.
>
> emg

And I see that maintainership has been passed to Michael Forney now
(probably should have checked that before sending the previous email.
In that case, Michael I'd like to help get up to date with patches.
Let me know how you'd feel about that.

emg



[hackers] [sbase][ubase] maintainers

2017-09-08 Thread Evan Gates
Hello suckless,

I decided to become maintainer of sbase and ubase months ago and
quickly fell out of touch. I apologize for my absence and lack of
communication on the matter. I'm back and I'm starting to dig through
the months of patches on the mailing list. If anybody already has a
list of patches or wants to help please let me know. I should be
answering email and in #suckless on oftc.

emg



Re: Re: [hackers] [PATCH v3][sbase] libutil/unescape.c: simplify and add \E

2017-02-06 Thread Evan Gates
Mattias Andrée <maand...@kth.se> wrote:

> On Mon, 06 Feb 2017 15:05:32 -0800
> evan.ga...@gmail.com (Evan Gates) wrote:
> 
> > Mattias Andrée <maand...@kth.se> wrote:
> > 
> > > + } else if (escapes[*r & 255]) {
> > > + *w++ = escapes[*r++ & 255];  
> > 
> > Why do you & 255 here? I think a cast to unsigned char
> > would accomplish what you are trying to do and be more
> > correct (as char can default to either signed or
> > unsigned). Although I may misunderstand what is going on
> > here.
> 
> Yes. I used &255 because it's does clutter as much.

OK. I'm going to change to a cast to be on the safe side due to the
"implementation-defined and undefined aspects" mentioned in C99 6.5p4:

Some operators (the unary operator ~, and the binary operators <<, >>, &, ^, 
and |,
collectively described as bitwise operators) are required to have operands that 
have
integer type. These operators yield values that depend on the internal 
representations of
integers, and have implementation-defined and undefined aspects for signed 
types.

> > I think this is clearer, even though it adds a
> > conditional:
> > 
> > q = q * 16 + isdigit(*r) ? *r - '0' : tolower(*r) - 'a' + 10;
> 
> I think
> 
>   if (isdigit(*r))
>   q = q * 16 + (*r - '0');
>   else
>   q = q * 16 + (tolower(*r) - 'a') + 10;
> 
> is clearer, or at least brackets around the ternary.

You're right, the line was getting a bit long and convoluted with the
ternary, bad habit of mine.

Another thought just came to mind, isoctal is a reserved name. 7.26p1:

The following names are grouped under individual headers for convenience. All 
external
names described below are reserved no matter what headers are included by the 
program.

7.26.2p1:

Function names that begin with either is or to, and a lowercase letter may be 
added to
the declarations in the  header.

I don't know if it's worth being anal about that, especially as we have
already limited ourselves to C99 do we need to worry about future
directions? For now I've changed isoctal() to is_odigit() but I'm open
to discussion.

Updated patch for consideration:

- 8< - 8< - 8< -
From 30fd43d7f3b8716054eb9867c835aadc423f652c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Andr=C3=A9e?= <maand...@kth.se>
Date: Sun, 5 Feb 2017 00:44:35 +0100
Subject: [PATCH] libutil/unescape.c: simplify and add \E
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Mattias Andrée <maand...@kth.se>
---
 libutil/unescape.c | 101 ++---
 1 file changed, 42 insertions(+), 59 deletions(-)

diff --git a/libutil/unescape.c b/libutil/unescape.c
index d1503e6..7523db3 100644
--- a/libutil/unescape.c
+++ b/libutil/unescape.c
@@ -1,74 +1,57 @@
 /* See LICENSE file for copyright and license details. */
+#include 
 #include 
 
 #include "../util.h"
 
+#define is_odigit(c)  ('0' <= c && c <= '7')
+
 size_t
 unescape(char *s)
 {
-   size_t len, i, off, m, factor, q;
-
-   len = strlen(s);
+   static const char escapes[256] = {
+   ['"'] = '"',
+   ['\''] = '\'',
+   ['\\'] = '\\',
+   ['a'] = '\a',
+   ['b'] = '\b',
+   ['E'] = 033,
+   ['e'] = 033,
+   ['f'] = '\f',
+   ['n'] = '\n',
+   ['r'] = '\r',
+   ['t'] = '\t',
+   ['v'] = '\v'
+   };
+   size_t m, q;
+   char *r, *w;
 
-   for (i = 0; i < len; i++) {
-   if (s[i] != '\\')
+   for (r = w = s; *r;) {
+   if (*r != '\\') {
+   *w++ = *r++;
continue;
-   off = 0;
-
-   switch (s[i + 1]) {
-   case '\\': s[i] = '\\'; off++; break;
-   case '\'': s[i] = '\'', off++; break;
-   case '"':  s[i] =  '"', off++; break;
-   case 'a':  s[i] = '\a'; off++; break;
-   case 'b':  s[i] = '\b'; off++; break;
-   case 'e':  s[i] =  033; off++; break;
-   case 'f':  s[i] = '\f'; off++; break;
-   case 'n':  s[i] = '\n'; off++; break;
-   case 'r':  s[i] = '\r'; off++; break;
-   case 't':  s[i] = '\t'; off++; break;
-   case 'v':  s[i] = '\v'; off++; break;
-   case 'x':
-   /* "\xH[H]" hexadecimal escape */
-   for (m = i + 2; m < i + 1 + 3 && m < len; m++)
-   if ((s[m] < '0' && s[m] > '9') &&
-   (s[m] <

Re: [hackers] [PATCH v3][sbase] libutil/unescape.c: simplify and add \E

2017-02-06 Thread Evan Gates
Mattias Andrée  wrote:

> + } else if (escapes[*r & 255]) {
> + *w++ = escapes[*r++ & 255];

Why do you & 255 here? I think a cast to unsigned char would accomplish
what you are trying to do and be more correct (as char can default to
either signed or unsigned). Although I may misunderstand what is going
on here.

> + q = q * 8 + (*r & 7);

I think this is clearer:

q = q * 8 + (*r - '0');

> + *w++ = q > 255 ? 255 : q;

Probably use MIN(q, 255) instead of the explicit ternary.

> + for (q = 0, m = 2; m && isxdigit(*r); m--, r++)
> + q = q * 16 + (*r & 15) + 9 * !!isalpha(*r);

I think this is clearer, even though it adds a conditional:

q = q * 16 + isdigit(*r) ? *r - '0' : tolower(*r) - 'a' + 10;

Great work, much much simpler implementation. Once I understand the &255
and we agree on the best solution for these few lines I'll go ahead and
push this.



Re: [hackers] [PATCH][sbase] libutil/unescape.c: add \E and simplify \x

2017-02-06 Thread Evan Gates
On Mon, Feb 6, 2017 at 1:38 PM, Evan Gates <evan.ga...@gmail.com> wrote:
> On Mon, Feb 6, 2017 at 1:35 PM, Mattias Andrée <maand...@kth.se> wrote:
>>
>> I don't really have a prefers.
>
> OK, applied with that small change. Thanks.

Sorry, I just realized I was reading through these in the wrong order
and you had a v2 and v3 patch. I'm reading through v3 now and will
most likely go with that. Thanks for the simplifications.



Re: Re: [hackers] [sbase][PATCH] Fixed a couple of uninitialised variable warnings from Clang

2017-02-06 Thread Evan Gates
Hiltjo Posthuma <hil...@codemadness.org> wrote:

> Probably a false positive, but for ed.c it looks ok to me.
> 
> The join.c patch does not look ok to me (clang doesn't detect that
> eprintf() exists the program), so it's a false positive.

This is where the _Noreturn or noreturn attribute is handy.
Unfortunately that's C11.

It seems ed.c is the same problem, error() has a longjmp() instead of
return causing a false positive.

I do like getting rid of warnings but I'm not particularly fond of
changes purely for that reason.

As for join.c, if we do care about getting rid of warnings we can
rewrite to take advantage of the initialized values instead of assigning
again when s is "0". Although I'm not sure the intent is as clear this
way. Example patch below.

I'd like to hear more thoughts on this, if the community's response is
overwhelmingly one way or the other I'll gladly accept the changes.

- 8< - 8< -

From 5eae9c0bd10c6da57fcd8527e7bbc6c23cda4b08 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Mon, 6 Feb 2017 13:50:23 -0800
Subject: [PATCH] Initialize to avoid false positive clang warning

clang doesn't recognize eprintf exits and warns about possibily
uninitialized values. Initialize the values and rearrange the
conditionals to avoid redundant assignment.
---
 join.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/join.c b/join.c
index d3e2343..e62bb8f 100644
--- a/join.c
+++ b/join.c
@@ -314,16 +314,13 @@ static struct spec *
 makespec(char *s)
 {
struct spec *sp;
-   int fileno;
-   size_t fldno;
+   int fileno = 0; /* default to "0", join field must be 0 and nothing 
else */
+   size_t fldno = 0;
 
-   if (!strcmp(s, "0")) {   /* join field must be 0 and nothing else */
-   fileno = 0;
-   fldno = 0;
-   } else if ((s[0] == '1' || s[0] == '2') && s[1] == '.') {
+   if ((s[0] == '1' || s[0] == '2') && s[1] == '.') {
fileno = s[0] - '0';
fldno = estrtonum([2], 1, MIN(LLONG_MAX, SIZE_MAX)) - 1;
-   } else {
+   } else if (strcmp(s, "0")){
eprintf("%s: invalid format\n", s);
}
 
-- 
2.11.0




Re: [hackers] [PATCH][sbase] libutil/unescape.c: add \E and simplify \x

2017-02-06 Thread Evan Gates
On Mon, Feb 6, 2017 at 1:35 PM, Mattias Andrée  wrote:
>
> I don't really have a prefers.

OK, applied with that small change. Thanks.



Re: [hackers] [PATCH][sbase] libutil/unescape.c: add \E and simplify \x

2017-02-06 Thread Evan Gates
On Sat, Feb 4, 2017 at 1:32 PM, Mattias Andrée  wrote:
> @@ -39,10 +39,8 @@ unescape(char *s)
> off += m - i - 1;
> for (--m, q = 0, factor = 1; m > i + 1; m--) {
> -   if (s[m] >= '0' && s[m] <= '9')
> -   q += (s[m] - '0') * factor;
> -   else if (s[m] >= 'A' && s[m] <= 'F')
> -   q += ((s[m] - 'A') + 10) * factor;
> -   else if (s[m] >= 'a' && s[m] <= 'f')
> -   q += ((s[m] - 'a') + 10) * factor;
> +   if (isdigit(s[m]))
> +   q += (s[m] & 15) * factor;
> +   else
> +   q += ((s[m] & 15) + 9) * factor;
> factor *= 16;
> }
> --
> 2.11.0
>
>

I think this would be clearer as:

if (isdigit(s[m]))
q += (s[m] - '0') * factor;
else
q += (tolower(s[m]) - 'a' + 10) * factor;

But it is just a personal style preference. Or, if we do keep the bit
twiddling, I highly recommend using hex instead of decimal, e.g. (s[m]
& 0xf).

Thoughts?



Re: [hackers] [PATCH][sbase] libutil/unescape.c: only print argv0 once on error

2017-02-06 Thread Evan Gates
Mattias Andrée  wrote:

> Signed-off-by: Mattias Andrée 
> ---
>  libutil/unescape.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libutil/unescape.c b/libutil/unescape.c
> index 90a62c3..d1503e6 100644
> --- a/libutil/unescape.c
> +++ b/libutil/unescape.c
> @@ -35,7 +35,7 @@ unescape(char *s)
>   (s[m] < 'a' && s[m] > 'f'))
>   break;
>   if (m == i + 2)
> - eprintf("%s: invalid escape sequence '\\%c'\n", 
> argv0, s[i + 1]);
> + eprintf("invalid escape sequence '\\%c'\n", s[i 
> + 1]);
>   off += m - i - 1;
>   for (--m, q = 0, factor = 1; m > i + 1; m--) {
>   if (s[m] >= '0' && s[m] <= '9')
> @@ -49,14 +49,14 @@ unescape(char *s)
>   s[i] = q;
>   break;
>   case '\0':
> - eprintf("%s: null escape sequence\n", argv0);
> + eprintf("null escape sequence\n");
>   default:
>   /* "\O[OOO]" octal escape */
>   for (m = i + 1; m < i + 1 + 4 && m < len; m++)
>   if (s[m] < '0' || s[m] > '7')
>   break;
>   if (m == i + 1)
> - eprintf("%s: invalid escape sequence '\\%c'\n", 
> argv0, s[i + 1]);
> + eprintf("invalid escape sequence '\\%c'\n", s[i 
> + 1]);
>   off += m - i - 1;
>   for (--m, q = 0, factor = 1; m > i; m--) {
>   q += (s[m] - '0') * factor;
> -- 
> 2.11.0
> 

Thanks, Applied.



Re: [hackers] [PATCH][sbase] cp.1: source and dest are not optional

2017-01-31 Thread Evan Gates
Mattias Andrée  wrote:

> Signed-off-by: Mattias Andrée 
> ---
>  cp.1 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/cp.1 b/cp.1
> index 54126e2..f74127d 100644
> --- a/cp.1
> +++ b/cp.1
> @@ -11,8 +11,8 @@
>  .Fl R
>  .Op Fl H | L | P
>  .Oc
> -.Op Ar source ...
> -.Op Ar dest
> +.Ar source ...
> +.Ar dest
>  .Sh DESCRIPTION
>  .Nm
>  copies
> -- 
> 2.11.0
> 

Applied. Thanks.



Re: [hackers] [PATCH][sbase] getconf: fail if any other flag than -v is used

2017-01-31 Thread Evan Gates
Mattias Andrée  wrote:

> Signed-off-by: Mattias Andrée 
> ---
>  getconf.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/getconf.c b/getconf.c
> index e611659..d927f2d 100644
> --- a/getconf.c
> +++ b/getconf.c
> @@ -33,6 +33,9 @@ main(int argc, char *argv[])
>   /* ignore */
>   EARGF(usage());
>   break;
> + default:
> + usage();
> + break;
>   } ARGEND
>  
>   if (argc == 1) {
> -- 
> 2.11.0
> 

Applied. Thanks.



Re: [hackers] [sbase][PATCH] Add nologin(8) (from ubase) and simplify it

2017-01-03 Thread Evan Gates
On Mon, Jan 2, 2017 at 12:20 PM, Laslo Hunhold  wrote:
> yes, let's keep it as simple as possible. Do the others feel okay with
> adding nologin(1)?

I think it falls under the umbrella of "unix tools that are inherently
portable."



Re: [hackers] [sbase][Patch] date: add date/time setting capability

2016-12-28 Thread Evan Gates
On Dec 28, 2016 19:09, "John Vogel"  wrote:

On Wed, 28 Dec 2016 17:42:39 -0800
Michael Forney  wrote:

> Apart from these nits, this looks good to me.
>

Your help is greatly appreciated, thank you. Revised patch below.


For future reference, could I request use of  scissors for this? Git am[0]
has a feature to cut off everything above a line containing only 8< (looks
like scissors) and dashes. e.g.

8<8<

Keeping conversation above this line and patch bow it makes applying the
patch easier,  no need to manually get rid of the rest of the email.

Thanks

[0] https://git-scm.com/docs/git-am


Re: [hackers] [sbase] ls: print filenames on the fly rather than in a buffer

2016-12-28 Thread Evan Gates
Thanks. Changed to const as discussed on IRC and applied.



Re: [hackers] [sbase][PATCH] basename, dirname, printf: recognise -- and fail if options are used.

2016-12-27 Thread Evan Gates
On Tue, Dec 27, 2016 at 7:05 AM, Laslo Hunhold  wrote:
> On Tue, 27 Dec 2016 15:48:56 +0100
> Mattias Andrée  wrote:
>
> Hey Mattias,
>
>> Okay, I personally do not agree with this and see echo(1)
>> as an abomination, it treats any unrecognised flags as
>> strings, but if had debate on it, keep to want you agreed
>> to.

I agree echo is an abomination. Especially with POSIX saying things
like "If the first operand is -n, or if any of the operands contain a
 character, the results are implementation-defined." The
best thing we can do is not use echo in any scripts.

I think from a philosophical standpoint sbase echo should not include
-n, to be simpler and still POSIX compliant. However pragmatically
many scripts use echo -n so I think it makes sense to keep it.

>
> I respect your opinion and have to admit that this is not an easy
> discussion. Let's wait for some feedback and see what the others think
> about it.

I side with Mattias on this one. Accepting -- even in utilities that
don't have flags has the benefits of 1) complying with POSIX so we can
be a drop in replacement 2) consistency with all the other tools.



Re: [hackers] [sbase] [PATCH 11/11] tail: Process bytes with -c option, and add -m option for runes

2016-12-27 Thread Evan Gates
On Tue, Dec 27, 2016 at 5:55 AM, Laslo Hunhold  wrote:
> well-spotted! Still, it's _very_ counterintuitive to call the flag
> "-c". Instead of adding a non-portable m-flag, it would even sound
> better to me to add a b-flag for byte-offsets.
>
> It all depends on how many scripts rely on this behaviour. Can you give
> an example? I thought cut(1) was the tool of choice for extracting
> headers and such things.

I think deviating from POSIX here is a bad idea. Every deviation from
POSIX means that our tools cannot be used in another situation and
pushes prospective users away. If the user wants characters instead of
bytes we have tools to do that, don't surprise the user by doing
something different than every other implementation.

P.S. I too found -c confusing the first time I expected utf8
characters, but remembering these tools were created with ascii in
mind, I think of -c as char and it all works out...



Re: [hackers] [sbase] [patch] ed: Treat addresses of 0 as 1 for insert

2016-12-27 Thread Evan Gates
On Tue, Dec 27, 2016 at 4:31 AM, Laslo Hunhold  wrote:
> On Thu, 3 Nov 2016 15:19:35 +
> Thomas Mannay  wrote:
>
> Hey Thomas,
>
>> From 6665eaa1d2c25a95b44a4f4fb3d24a3bd5c1180f Mon Sep 17 00:00:00 2001
>> From: Thomas Mannay 
>> Date: Thu, 3 Nov 2016 15:16:32 +
>> Subject: [PATCH] Treat addresses of 0 as 1 for insert
>
> this patch looks logical to me, but what do the others say?
>
> Cheers
>
> Laslo
>
> --
> Laslo Hunhold 
>

POSIX says: "Address 0 shall be valid for this command; it shall be
interpreted as if address 1 were specified."



Re: [hackers] [sbase][PATCH] ls: add -1 option to manpage

2016-12-27 Thread Evan Gates
On Tue, Dec 27, 2016 at 4:20 AM, Laslo Hunhold  wrote:
> I am not 100% sure how to approach this, but -1 effectively does not do
> anything for our ls(1), except also implicitly activating the q-flag as
> mandated by Posix.
>
> What do the others think?
>
> Cheers
>
> Laslo
>
> --
> Laslo Hunhold 
>

As far as I can tell POSIX does not mandate the q-flag for -1. All
implementations I've seen do not do so and the point of POSIX is to
describe those common implementations. I could submit a report to the
austin group list for clarification...



Re: [hackers] [sbase][PATCH] grep: remove = flag from readme

2016-12-27 Thread Evan Gates
On Tue, Dec 27, 2016 at 3:09 AM, Laslo Hunhold  wrote:
> On Wed, 30 Mar 2016 19:01:16 +0200
> Mattias Andrée  wrote:
>
> Hey Mattias,
>
>>   $ echo äö | ./grep [å]
>>   äö
>>
>> This is not want one expects from
>> a program that supports UTF-8.
>
> as a general note, we may think about adding a setlocale() when we
> access the regex-engine. What do you guys think?
>
> Cheers
>
> Laslo
>
> --
> Laslo Hunhold 
>

Given the two options of using setlocale() or writing our own regex
engine, I think using setlocale() is the less sucky solution. If we
want to revisit it in the future we can but it'll give us working
tools now.



Re: [hackers] [slock][PATCH] Replace arg.h with if statements, simplify

2016-10-28 Thread Evan Gates
On Fri, Oct 28, 2016 at 11:27 AM, Klemens Nanni  wrote:
>
> ++argv is put on a seperate line since doing it within the execvp() call
> would produce a compiler warning.

Yes, because that's invoking undefined behavior. There is no guarantee
as to the order of execution of function parameters, and there are no
sequence points in there.



Re: [hackers] [dwm] [PATCH] get rid of unnecessary ternary operator

2016-10-28 Thread Evan Gates
On Fri, Oct 28, 2016 at 2:17 AM, Hiltjo Posthuma  wrote:
>
> FWIW: I disagree. The ternary form is slightly longer but more readable.

I too disagree. I think the !! is more readable and idiomatic (either
way, at least we aren't casting to bool...).  But I am curious, does
the compiler still generate a branch for the ternary? How does the
code compare for the 3 cases? I'll play around with that later.

That being said, isurgent is being used in the traditional boolean
sense where 0 is false and non 0 is true. As such there is no need to
do either. Just having

c->isurgent = wmh->flags & XUrgencyHint;

is fine.

emg



[hackers] [sbase][PATCH] printf: handle \0 in %b arguments

2016-10-24 Thread Evan Gates
The %b case was using fputs after unescape to print the argument, which
meant that it could not handle nul bytes. Instead, store the length
returned from unescape and use fwrite to properly handle them.
---
 printf.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/printf.c b/printf.c
index 7bf6fe5..4bc645b 100644
--- a/printf.c
+++ b/printf.c
@@ -19,7 +19,7 @@ int
 main(int argc, char *argv[])
 {
Rune *rarg;
-   size_t i, j, argi, lastargi, formatlen;
+   size_t i, j, argi, lastargi, formatlen, blen;
long long num;
double dou;
int cooldown = 0, width, precision, ret = 0;
@@ -112,12 +112,12 @@ main(int argc, char *argv[])
case 'b':
if ((tmp = strstr(arg, "\\c"))) {
*tmp = 0;
-   unescape(arg);
-   fputs(arg, stdout);
+   blen = unescape(arg);
+   fwrite(arg, sizeof(*arg), blen, stdout);
return 0;
}
-   unescape(arg);
-   fputs(arg, stdout);
+   blen = unescape(arg);
+   fwrite(arg, sizeof(*arg), blen, stdout);
break;
case 'c':
unescape(arg);
-- 
2.10.0




Re: [hackers] [sbase] [PATCH] tr: Fix multiple ranges with different lengths

2016-10-22 Thread Evan Gates
On Oct 22, 2016 02:41, "Michael Forney"  wrote:
> This also fixes range expressions in the form [a-z], which get encoded as
four
> ranges '[', 'a'..'z', ']', causing all a-z characters to get mapped to
']'. This
> form is occasionally used in shell scripts, including the syscalltbl.sh
script
> used to build linux.

Can you provide an example of what you mean? Brackets are not special
unless they are used for character classes or equivalence classes. An
argument of the form '[a-z]' means a set containing characters left
bracket, a to z, right bracket, and almost certainly the author meant just
'a-z'. Argument '[:lower:]' is a character class. There is often a
misconception that tr takes opening and closing brackets due to their use
in regex, but the arguments to tr are supposed to only be what would go
inside those brackets in the regex, the brackets themselves should be
omitted.


[hackers] [sbase][PATCH] Makefile: sort file lists

2016-10-20 Thread Evan Gates
---
 Makefile | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 25bab70..9d3afcc 100644
--- a/Makefile
+++ b/Makefile
@@ -23,10 +23,6 @@ HDR =\
 
 LIBUTF = libutf.a
 LIBUTFSRC =\
-   libutf/rune.c\
-   libutf/runetype.c\
-   libutf/utf.c\
-   libutf/utftorunestr.c\
libutf/fgetrune.c\
libutf/fputrune.c\
libutf/isalnumrune.c\
@@ -41,7 +37,11 @@ LIBUTFSRC =\
libutf/istitlerune.c\
libutf/isxdigitrune.c\
libutf/lowerrune.c\
-   libutf/upperrune.c
+   libutf/rune.c\
+   libutf/runetype.c\
+   libutf/upperrune.c\
+   libutf/utf.c\
+   libutf/utftorunestr.c
 
 LIBUTIL = libutil.a
 LIBUTILSRC =\
@@ -113,8 +113,8 @@ BIN =\
getconf\
grep\
head\
-   join\
hostname\
+   join\
kill\
link\
ln\
@@ -130,8 +130,8 @@ BIN =\
nl\
nohup\
od\
-   pathchk\
paste\
+   pathchk\
printenv\
printf\
pwd\
-- 
2.10.0




[hackers] [sbase]patch: fix PHONY

2016-10-20 Thread Evan Gates
targets must be prerequisites to PHONY, not commands
From e160605d1c27e433e9b5c72c3cf849522a802d17 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Wed, 19 Oct 2016 11:04:48 -0700
Subject: [PATCH] targets must be prerequisites to .PHONY not commands

---
 Makefile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 25bab70..c7fe373 100644
--- a/Makefile
+++ b/Makefile
@@ -272,5 +272,4 @@ clean:
rm -f $(BIN) $(OBJ) $(LIB) sbase-box sbase-$(VERSION).tar.gz
rm -f getconf.h
 
-.PHONY:
-   all install uninstall dist sbase-box sbase-box-install 
sbase-box-uninstall clean
+.PHONY: all install uninstall dist sbase-box sbase-box-install 
sbase-box-uninstall clean
-- 
2.10.0



[hackers] [sinit] patch: fix makefile

2016-10-11 Thread Evan Gates
sinit-makefile_fixes.diff:
don't use suffix rule def.h.h as it overwrites config.h when
config.def.h is updated
remove LDLIBS as it's not used
.PHONY: takes targets as prerequisites not as commands

sinit-makefile_changes.diff: some optional/style based changes to be
applied after sinit-makefile_fixes.diff
specify .POSIX: (already POSIX compliant, let's enforce POSIX behavior)
clear suffix list and only include .c as it's all we need
specify suffix rule .c to build binary and skip .o as it's not needed
remove LD as we're not using it anymore
remove OBJ as we're not building objects anymore
remove unnecessary input redirection for sed
in clean, remove all sinit tarballs not just for current VERSION
From c39397640e3da32841f2b8d5b861b9545096f5fe Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Tue, 11 Oct 2016 10:32:37 -0700
Subject: [PATCH] makefile changes

specify .POSIX: (already POSIX compliant, let's enforce POSIX behavior)
clear suffix list and only include .c as it's all we need
specify suffix rule .c to build binary and skip .o as it's not needed
remove LD as we're not using it anymore
remove OBJ as we're not building objects anymore
remove unnecessary input redirection for sed
in clean, remove all sinit tarballs not just for current VERSION
---
 Makefile  | 21 +++--
 config.mk |  1 -
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 32ca146..83a0f68 100644
--- a/Makefile
+++ b/Makefile
@@ -1,20 +1,23 @@
+.POSIX:
+.SUFFIXES:
+.SUFFIXES: .c
+.PHONY: all install uninstall dist clean
+
+.c:
+   $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
+
 include config.mk
 
-OBJ = sinit.o
 BIN = sinit
 
 all: $(BIN)
-
-$(BIN): $(OBJ)
-   $(CC) $(LDFLAGS) -o $@ $(OBJ)
-
-$(OBJ): config.h
+$(BIN): config.h
 
 install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f $(BIN) $(DESTDIR)$(PREFIX)/bin
mkdir -p $(DESTDIR)$(MANPREFIX)/man8
-   sed "s/VERSION/$(VERSION)/g" < $(BIN).8 > 
$(DESTDIR)$(MANPREFIX)/man8/$(BIN).8
+   sed "s/VERSION/$(VERSION)/g" $(BIN).8 > 
$(DESTDIR)$(MANPREFIX)/man8/$(BIN).8
 
 uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
@@ -28,9 +31,7 @@ dist: clean
rm -rf sinit-$(VERSION)
 
 clean:
-   rm -f $(BIN) $(OBJ) sinit-$(VERSION).tar.gz
+   rm -f $(BIN) sinit-*.tar.gz
 
 config.h:
cp config.def.h $@
-
-.PHONY: all install uninstall dist clean
diff --git a/config.mk b/config.mk
index c1f87b4..37c87a1 100644
--- a/config.mk
+++ b/config.mk
@@ -6,7 +6,6 @@ PREFIX = /usr/local
 MANPREFIX = $(PREFIX)/share/man
 
 CC = cc
-LD = $(CC)
 CPPFLAGS =
 CFLAGS   = -Wextra -Wall -Os
 LDFLAGS  = -s -static
-- 
2.10.0

From 94eca64e8764ab400f9e38211b4fe0794d43246c Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Tue, 11 Oct 2016 10:28:21 -0700
Subject: [PATCH] Makefile fixes

don't use suffix rule def.h.h as it overwrites config.h when
config.def.h is updated
remove LDLIBS as it's not used
.PHONY: takes targets as prerequisites not as commands
---
 Makefile | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 7e2fde5..32ca146 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ BIN = sinit
 all: $(BIN)
 
 $(BIN): $(OBJ)
-   $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS)
+   $(CC) $(LDFLAGS) -o $@ $(OBJ)
 
 $(OBJ): config.h
 
@@ -30,10 +30,7 @@ dist: clean
 clean:
rm -f $(BIN) $(OBJ) sinit-$(VERSION).tar.gz
 
-.SUFFIXES: .def.h
+config.h:
+   cp config.def.h $@
 
-.def.h.h:
-   cp $< $@
-
-.PHONY:
-   all install uninstall dist clean
+.PHONY: all install uninstall dist clean
-- 
2.10.0



[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 <evan.ga...@gmail.com> 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 <evan.ga...@gmail.com>
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 <evan.ga...@gmail.com>
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 <d...@frign.de> 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 <evan.ga...@gmail.com>
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 <evan.ga...@gmail.com>
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][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 <evan.ga...@gmail.com>
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 <evan.ga...@gmail.com>
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



Re: [hackers] [sbase][patches] sort makefile and add getconf guard file

2016-10-03 Thread Evan Gates
On Mon, Oct 3, 2016 at 11:19 AM, FRIGN <d...@frign.de> wrote:
> On Thu, 29 Sep 2016 08:54:30 -0700
> Evan Gates <evan.ga...@gmail.com> wrote:
>> sbase-getconf_guard.diff adds a guard file to the getconf rules so
>> that getconf.sh doesn't get run multiple times in parallel.
>
> This could be solved a bit more elegantly. You can see that getconf.sh
> generates the files confstr_l.h, limits_l.h, sysconf_l.h and
> pathconf_l.h. Maybe you can work something out. :)

After discussion on IRC, a patch that changes getconf.sh and creates a
single header.
From 0ef723e6c448f555c52b156a8abf488b4dd6f368 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Mon, 3 Oct 2016 15:55:22 -0700
Subject: [PATCH] use only one getconf header

this simplifies the getconf.sh script and handling parallel make
---
 Makefile   | 10 +-
 getconf.c  | 17 +
 getconf.sh | 18 --
 3 files changed, 14 insertions(+), 31 deletions(-)

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][patches] sort makefile and add getconf guard file

2016-09-29 Thread Evan Gates
sbase-sort_makefile.diff sorts all the lists in the Makefile. Sorry
that was bugging me.

sbase-getconf_guard.diff adds a guard file to the getconf rules so
that getconf.sh doesn't get run multiple times in parallel.

-emg
From a80d782ed8b7fb305096f20aa1615492b0a58e38 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Thu, 29 Sep 2016 08:43:19 -0700
Subject: [PATCH] add guard file for getconf.sh rule to avoid multiple parallel
 execution

for example try 'make -j4 getconf.c' and you will see getconf.sh run 4
times, this patch fixes that to only run once
---
 Makefile | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 319a4c3..fde7a1d 100644
--- a/Makefile
+++ b/Makefile
@@ -207,8 +207,11 @@ $(LIBUTIL): $(LIBUTILOBJ)
 
 getconf.c: confstr_l.h limits_l.h sysconf_l.h pathconf_l.h
 
-confstr_l.h limits_l.h sysconf_l.h pathconf_l.h: getconf.sh
+confstr_l.h limits_l.h sysconf_l.h pathconf_l.h: _getconf ;
+
+_getconf: getconf.sh
./getconf.sh
+   touch $@
 
 install: all
mkdir -p $(DESTDIR)$(PREFIX)/bin
@@ -270,7 +273,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 confstr_l.h limits_l.h sysconf_l.h pathconf_l.h _getconf
 
 .PHONY:
-   all install uninstall dist sbase-box sbase-box-install 
sbase-box-uninstall clean
+   all install uninstall dist sbase-box sbase-box-install 
sbase-box-uninstall clean _getconf
-- 
2.10.0

From 5edaa9f2ccced30183ae350504a08d8a81e4dad5 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Thu, 29 Sep 2016 08:42:23 -0700
Subject: [PATCH] sort lists in Makefile

---
 Makefile | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index 6b2bfdf..319a4c3 100644
--- a/Makefile
+++ b/Makefile
@@ -14,19 +14,15 @@ HDR =\
sha224.h\
sha256.h\
sha384.h\
-   sha512.h\
sha512-224.h\
sha512-256.h\
+   sha512.h\
text.h\
utf.h\
util.h
 
 LIBUTF = libutf.a
 LIBUTFSRC =\
-   libutf/rune.c\
-   libutf/runetype.c\
-   libutf/utf.c\
-   libutf/utftorunestr.c\
libutf/fgetrune.c\
libutf/fputrune.c\
libutf/isalnumrune.c\
@@ -41,7 +37,11 @@ LIBUTFSRC =\
libutf/istitlerune.c\
libutf/isxdigitrune.c\
libutf/lowerrune.c\
-   libutf/upperrune.c
+   libutf/rune.c\
+   libutf/runetype.c\
+   libutf/upperrune.c\
+   libutf/utf.c\
+   libutf/utftorunestr.c
 
 LIBUTIL = libutil.a
 LIBUTILSRC =\
@@ -71,9 +71,9 @@ LIBUTILSRC =\
libutil/sha224.c\
libutil/sha256.c\
libutil/sha384.c\
-   libutil/sha512.c\
libutil/sha512-224.c\
libutil/sha512-256.c\
+   libutil/sha512.c\
libutil/strcasestr.c\
libutil/strlcat.c\
libutil/strlcpy.c\
@@ -113,8 +113,8 @@ BIN =\
getconf\
grep\
head\
-   join\
hostname\
+   join\
kill\
link\
ln\
@@ -130,8 +130,8 @@ BIN =\
nl\
nohup\
od\
-   pathchk\
paste\
+   pathchk\
printenv\
printf\
pwd\
@@ -146,9 +146,9 @@ BIN =\
sha224sum\
sha256sum\
sha384sum\
-   sha512sum\
sha512-224sum\
sha512-256sum\
+   sha512sum\
sleep\
sort\
split\
-- 
2.10.0



[hackers] Re: [stali][patch] Change dependency specifications in makefiles

2016-09-14 Thread Evan Gates
On Wed, Sep 7, 2016 at 4:29 PM, Evan Gates <evan.ga...@gmail.com> wrote:
> I've made a lot of changes to the makefiles to specify dependencies
> correctly and allow parallel builds with make -j. Please be on the
> lookout for bugs and please bring up any objections/criticism.

e2fsprogs/misc/stali.mk and e2fsprogs/util/stali.mk were missing all
as a prerequisite for install. Fix attached.

-emg
From f6623c4dfcba94e27c539645302fca0e6889c316 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Wed, 14 Sep 2016 16:27:33 -0700
Subject: [PATCH] install target needs to list all as a prerequisite

---
 bin/e2fsprogs/misc/stali.mk | 2 +-
 bin/e2fsprogs/util/stali.mk | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bin/e2fsprogs/misc/stali.mk b/bin/e2fsprogs/misc/stali.mk
index f00e88f..bdaeafe 100644
--- a/bin/e2fsprogs/misc/stali.mk
+++ b/bin/e2fsprogs/misc/stali.mk
@@ -120,7 +120,7 @@ clean:
@echo cleaning
@rm -f $(BIN) $(OBJS) $(CLEAN_FILES) $(MAN8_FILES)
 
-install:
+install: all
@echo installing executable file to $(DESTDIR)$(PREFIX)/bin
@mkdir -p $(DESTDIR)$(PREFIX)/bin
@cp -f $(BINS) $(DESTDIR)$(PREFIX)/bin
diff --git a/bin/e2fsprogs/util/stali.mk b/bin/e2fsprogs/util/stali.mk
index 8817e1f..a7afab1 100644
--- a/bin/e2fsprogs/util/stali.mk
+++ b/bin/e2fsprogs/util/stali.mk
@@ -32,7 +32,7 @@ subst.conf:
@echo HOSTLD $<
@$(HOSTCC) -o $@ $< $(HOSTLDFLAGS) 
 
-install:
+install: all
 
 uninstall:
 
-- 
2.9.3



[hackers] Re: [9base][patch] fix path to tmac directory in tmac files

2016-09-14 Thread Evan Gates
On Wed, Sep 14, 2016 at 9:02 AM, Evan Gates <evan.ga...@gmail.com> wrote:
> fix path to tmac directory in tmac files (#9/tmac/ -> #9/lib/troff/tmac/)

I also just found many references to /usr/lib/tmac/... or
/lib/tmac/... without the #9, a few to /home/anselm/plan9port/..., two
to binaries that 9base does not include (auxpm and mnihongo), a few
other things in /usr/lib (btroff, macros).

It'll take some time for me to fix these.



[hackers] [9base][patch] fix path to tmac directory in tmac files

2016-09-14 Thread Evan Gates
fix path to tmac directory in tmac files (#9/tmac/ -> #9/lib/troff/tmac/)
From 50638159d4d40b2be0f684cedf402c2cff8ccce4 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Wed, 14 Sep 2016 08:58:57 -0700
Subject: [PATCH] fix path to tmac directory in tmac files (#9/tmac/ ->
 #9/lib/troff/tmac/)

---
 troff/tmac/mmn  | 2 +-
 troff/tmac/mmt  | 2 +-
 troff/tmac/tmac.e   | 2 +-
 troff/tmac/tmac.m   | 4 ++--
 troff/tmac/tmac.s   | 2 +-
 troff/tmac/tmac.spe | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/troff/tmac/mmn b/troff/tmac/mmn
index fab3973..9ea4da6 100644
--- a/troff/tmac/mmn
+++ b/troff/tmac/mmn
@@ -24,7 +24,7 @@
 .nr!8 0
 .nr!9 0
 .nr!M 0
-.so #9/tmac/strings.mm
+.so #9/lib/troff/tmac/strings.mm
 .if\*(]S .ds ]S \*(}Z
 .dsBU \(bu
 .dsEM \%--
diff --git a/troff/tmac/mmt b/troff/tmac/mmt
index c3c9c7d..799eed3 100644
--- a/troff/tmac/mmt
+++ b/troff/tmac/mmt
@@ -23,7 +23,7 @@
 .nr!8 0
 .nr!9 0
 .nr!M 0
-.so #9/tmac/strings.mm
+.so #9/lib/troff/tmac/strings.mm
 .if\*(]S .ds ]S \s14\f3\*(}Z\fP\s0
 .dsBU \s-2\(bu\s0
 .dsEM \(em
diff --git a/troff/tmac/tmac.e b/troff/tmac/tmac.e
index 8e52976..74b4c68 100644
--- a/troff/tmac/tmac.e
+++ b/troff/tmac/tmac.e
@@ -918,7 +918,7 @@
 .nr ii 5n
 .nr $m 1
 .nr $s 4n
-.ds || #9/tmac/me
+.ds || #9/lib/troff/tmac/me
 .bd S B 3
 .ds [ \u\x'-0.25v'
 .ds ] \d
diff --git a/troff/tmac/tmac.m b/troff/tmac/tmac.m
index 061b6d0..c1f4be5 100644
--- a/troff/tmac/tmac.m
+++ b/troff/tmac/tmac.m
@@ -1,3 +1,3 @@
 '''\"  TMAC.M @(#)tmacs.src1.7
-.if n .so #9/tmac/mmn
-.if t .so #9/tmac/mmt
+.if n .so #9/lib/troff/tmac/mmn
+.if t .so #9/lib/troff/tmac/mmt
diff --git a/troff/tmac/tmac.s b/troff/tmac/tmac.s
index 6f11186..09baa20 100644
--- a/troff/tmac/tmac.s
+++ b/troff/tmac/tmac.s
@@ -1,5 +1,5 @@
 .lg 0
-.ds sd #9/tmac
+.ds sd #9/lib/troff/tmac
 .\"RT -  reset everything to normal state
 .de RT
 .if \\n(CS \{\
diff --git a/troff/tmac/tmac.spe b/troff/tmac/tmac.spe
index ea77323..9a41702 100644
--- a/troff/tmac/tmac.spe
+++ b/troff/tmac/tmac.spe
@@ -1,5 +1,5 @@
 . July 1, 1991
-.so #9/tmac/tmac.pm
+.so #9/lib/troff/tmac/tmac.pm
 .
 .ig
 .nr VN 1   \" VN -- volume
-- 
2.9.3



[hackers] [9base][patch] check for _LARGEFILE64_SOURCE instead of __USE_LARGEFILE64

2016-09-09 Thread Evan Gates
glibc doesn't define getdents() and requires use of the raw syscall.
As such lib9/dirread.c needed to decide whether to use SYS_getdents or
SYS_getdents64 and was checking if __USE_LARGEFILE64 was defined in
order to do so. musl does not define __USE_LARGEFILE64 so the wrong
syscall was being used. musl does however define _LARGEFILE64_SOURCE,
the macro that glibc checks in order to define __USE_LARGEFILE64.
From 1711bb2c1648d355d1d6998f02c6df1a344663a8 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Fri, 9 Sep 2016 12:36:57 -0700
Subject: [PATCH] check for _LARGEFILE64_SOURCE instead of __USE_LARGEFILE64

glibc doesn't define getdents() and requires use of the raw syscall. As
such lib9/dirread.c needed to decide whether to use SYS_getdents or
SYS_getdents64 and was checking if __USE_LARGEFILE64 was defined in
order to do so. musl does not define __USE_LARGEFILE64 so the wrong
syscall was being used. musl does however define _LARGEFILE64_SOURCE,
the macro that glibc checks in order to define __USE_LARGEFILE64.
---
 lib9/dirread.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib9/dirread.c b/lib9/dirread.c
index f114195..6c494ab 100644
--- a/lib9/dirread.c
+++ b/lib9/dirread.c
@@ -6,7 +6,7 @@
 
 #if defined (__linux__)
 # include 
-# if defined (__USE_LARGEFILE64)
+# if defined (_LARGEFILE64_SOURCE)
 #  define getdents SYS_getdents64
 # else
 #  define getdents SYS_getdents
-- 
2.9.3



[hackers] Re: [stali][patch] Change dependency specifications in makefiles

2016-09-07 Thread Evan Gates
I forgot to add, one important side change is that after updating a
library, all packages that depend on it will now automatically rebuild due
to moving library dependencies out of LDFLAGS and into LIBS and specifying
that the BIN depends on LIBS.

On Sep 7, 2016 4:29 PM, "Evan Gates" <evan.ga...@gmail.com> wrote:

> I've made a lot of changes to the makefiles to specify dependencies
> correctly and allow parallel builds with make -j. Please be on the
> lookout for bugs and please bring up any objections/criticism.
>
> Specify dependencies correctly to allow parallel builds with -j.
> Previously the makefiles relied upon sequential execution in order to
> ensure prerequisites were built first. The new dependencies are done
> on a per package level and a per directory level. For example parts of
> the parted package depend on parts of the e2fsprogs package.  Instead
> of listing the exact dependencies and recipes in the parted makefile,
> list e2fsprog as a prerequisite for parted in the bin/stali.mk. While
> this isn't as exact, and means that you can't build parted directly
> from its directory without building anything else, it sucks much less
> to implement and puts dependencies in a more central location and
> makes them easier to read and add to.
>
> Using guard files to protect against redundant recipe execution. In
> some instances more than one target is built by a single execution of
> a recipe. For example, the awk package uses yacc to create both ytab.h
> and ytab.c from awkgram.y. However when doing a parallel build the
> recipe would be executed twice in parallel, once to create ytab.h and
> once to create ytab.c. In order to avoid this an intermediate rule is
> used. The rule could be PHONY, but then it would run every time
> instead of only when the grammar is updated. Instead the intermediate
> rule, called _ytab, touches a file called _ytab so we have a
> modification time to compare against. I used the convention of guard
> files begining with an underscore.
>


[hackers] [stali][patch] Change dependency specifications in makefiles

2016-09-07 Thread Evan Gates
I've made a lot of changes to the makefiles to specify dependencies
correctly and allow parallel builds with make -j. Please be on the
lookout for bugs and please bring up any objections/criticism.

Specify dependencies correctly to allow parallel builds with -j.
Previously the makefiles relied upon sequential execution in order to
ensure prerequisites were built first. The new dependencies are done
on a per package level and a per directory level. For example parts of
the parted package depend on parts of the e2fsprogs package.  Instead
of listing the exact dependencies and recipes in the parted makefile,
list e2fsprog as a prerequisite for parted in the bin/stali.mk. While
this isn't as exact, and means that you can't build parted directly
from its directory without building anything else, it sucks much less
to implement and puts dependencies in a more central location and
makes them easier to read and add to.

Using guard files to protect against redundant recipe execution. In
some instances more than one target is built by a single execution of
a recipe. For example, the awk package uses yacc to create both ytab.h
and ytab.c from awkgram.y. However when doing a parallel build the
recipe would be executed twice in parallel, once to create ytab.h and
once to create ytab.c. In order to avoid this an intermediate rule is
used. The rule could be PHONY, but then it would run every time
instead of only when the grammar is updated. Instead the intermediate
rule, called _ytab, touches a file called _ytab so we have a
modification time to compare against. I used the convention of guard
files begining with an underscore.
From 969482a848c1bd44284e80d1426a72c046f8d0f0 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Wed, 7 Sep 2016 16:03:28 -0700
Subject: [PATCH] Lots of makefile changes

Specify dependencies correctly to allow parallel builds with -j.
Previously the makefiles relied upon sequential execution in order to
ensure prerequisites were built first. The new dependencies are done
on a per package level and a per directory level. For example parts of
the parted package depend on parts of the e2fsprogs package.  Instead of
listing the exact dependencies and recipes in the parted makefile, list
e2fsprog as a prerequisite for parted in the bin/stali.mk. While this
isn't as exact, and means that you can't build parted directly from its
directory, it sucks much less to implement and puts dependencies in a
more central location and makes them easier to read and add to.

Using guard files to protect against redundant recipe execution.
In some instances more than one target is built by a single execution of
a recipe. For example, the awk package uses yacc to create both ytab.h
and ytab.c from awkgram.y. However when doing a parallel build the recipe
would be executed twice in parallel, once to create ytab.h and once to
create ytab.c. In order to avoid this an intermediate rule is used. The
rule could be PHONY, but then it would run every time instead of only
when the grammar is updated. Instead the intermediate rule, called _ytab,
touches a file called _ytab so we have a modification time to compare
against. I used the convention of guard files begining with an underscore.
---
 bin/abduco/stali.mk|  5 ++--
 bin/curl/src/stali.mk  |  2 +-
 bin/curl/stali.mk  |  2 ++
 bin/dvtm/stali.mk  |  7 +++---
 bin/e2fsprogs/debugfs/stali.mk | 15 +---
 bin/e2fsprogs/e2fsck/stali.mk  |  2 +-
 bin/e2fsprogs/intl/stali.mk|  4 +--
 bin/e2fsprogs/lib/blkid/stali.mk   |  5 ++--
 bin/e2fsprogs/lib/e2p/stali.mk |  1 -
 bin/e2fsprogs/lib/et/stali.mk  |  5 ++--
 bin/e2fsprogs/lib/ext2fs/stali.mk  | 10 +---
 bin/e2fsprogs/lib/ss/stali.mk  |  7 --
 bin/e2fsprogs/lib/support/stali.mk |  8 +++---
 bin/e2fsprogs/lib/uuid/stali.mk|  5 ++--
 bin/e2fsprogs/misc/stali.mk|  2 +-
 bin/e2fsprogs/resize/stali.mk  |  3 +--
 bin/e2fsprogs/stali.mk | 16 +---
 bin/e2fsprogs/util/stali.mk| 33 -
 bin/git/stali.mk   |  9 ---
 bin/gzip/lib/stali.mk  |  8 +++---
 bin/gzip/stali.mk  | 42 
 bin/hbase/_install/stali.mk|  2 --
 bin/hbase/awk/awkgram.y|  1 +
 bin/hbase/awk/stali.mk | 16 ++--
 bin/hbase/bc/stali.mk  | 13 --
 bin/hbase/dc/stali.mk  |  2 --
 bin/hbase/diff/stali.mk|  5 ++--
 bin/hbase/fmt/stali.mk |  2 --
 bin/hbase/hd/stali.mk  |  2 --
 bin/hbase/lex/stali.mk | 11 -
 bin/hbase/libcommon/stali.mk   | 11 +
 bin/hbase/libuxre/stali.mk |  2 --
 bin/hbase/patch/stali.mk   |  2 --
 bin/hbase/pgrep/stali.mk   |  3 ---
 bin/hbase/stali.mk | 11 ++---
 bin/hbase/stty/stali.mk|  2 --
 bin/hbas

Re: [hackers] [farbfeld] Shellcheck 2ff fixes || FRIGN

2016-09-07 Thread Evan Gates
On Wed, Sep 7, 2016 at 3:26 PM, FRIGN  wrote:
> Yes it is a reflex. The semicolons don't hurt anybody and I actually am
> not that much of a shell-god to really exactly know where I can get rid
> of them.

Anywhere you have a single semicolon at the end of the line you can
get rid of it.

>> Why not quote "$ret"? You don't have control over the environment in
>> which the user will run the script. I know it sounds stupid, but I
>> have literally seen a script run in a case where IFS=0 and if [ $? -ne
>> 0 ] broke. And it was a legitimate usage.
>
> I don't know about such environments. The question is if $? would ever
> return something that is something else than a number.

$? should always be a number. But some times IFS, the internal field
separator, can be set to weird values. Normally IFS is set to space,
tab, newline. When performing word splitting the shell splits on the
values in IFS. If a user happened to set IFS=0 and $? is 0, then $?
expands to nothing. Try this (I put it in a subshell so you don't lose
your IFS):

(IFS=0; true; if [ $? -ne 0 ]; then echo foo; fi)

You should get [ telling you that an integer expression was expected.

Does it make sense to have a weird IFS like that? Maybe, we don't know
what the user is doing. Is IFS inherited through the environment?
Maybe, different shells behave differently in this area even though
POSIX says it should be (e.g. bash doesn't).

> I honestly have to say that I'm not comfortable with those shell-tricks
> and in my opinion this lowers readability very much. If this was a part
> of the script that was executed 1 million times I would think about
> using "shell-native" functions, but this is just done once and you
> immediately see what it does because cut(1) is a common tool.
>
> For shells, I like to go for the UNIX approach. Use the provided Posix
> tools to solve a task and avoid builtin stuff, especially magic syntax,
> as much as possible.

That's fine, and I think that's a good enough reason to leave it as
is. I don't think it's something a shell needs (notice rc doesn't have
all that stuff, you always use external tools), just something I have
grown used to and don't avoid as it's in POSIX.



Re: [hackers] [farbfeld] Shellcheck 2ff fixes || FRIGN

2016-09-07 Thread Evan Gates
Hey FRIGN,

I'm glad you quoted! I do have a couple questions and discussion
points I'd value your feedback on.

Why all the extraneous semicolons? I see this a lot in awk, too. I
think it tends to be a reflex for C programmers.

Why not quote "$ret"? You don't have control over the environment in
which the user will run the script. I know it sounds stupid, but I
have literally seen a script run in a case where IFS=0 and if [ $? -ne
0 ] broke. And it was a legitimate usage.

And the following purely style questions:

What are your thoughts on
FORMAT=$(file -ib "$TMP") FORMAT=${FORMAT%;*}
instead of using the file | cut? I tend towards using shell parameter
expansion instead of piping. I think I started to do so in order to
save the fork and pipe, but now it just comes more naturally to me.

I still highly recommend not using all cap variables. I'm not sure
where the trend started, I don't see it in any other language (does
pop up in makefiles).



Re: [hackers] [quark] Use sizeof() instead of magic constants || FRIGN

2016-09-06 Thread Evan Gates
On Mon, Sep 5, 2016 at 12:41 AM, FRIGN  wrote:
> but this only happens if you typedef your structs, which I think is bad
> practice.
> If you do a
> #typedef struct hw homework
> this is your own fault. Using
> sizeof(struct hw)
> shows clearly it's a type, whereas
> sizeof(homework)
> is not clear. But this is more a criticism of extreme typedeffing. Stop
> using typedefs for structs and you won't have this problem any more. If
> you can't discern type names from variable names, this is your problem.

The style guide, which follows from "Unix Programming Environment,"
says to capitalize typedef names. In this way user defined types start
with a capital letter and all builtin types, variables, functions
start with a lower case letter.



Re: [hackers] [quark] Use sizeof() instead of magic constants || FRIGN

2016-09-06 Thread Evan Gates
On Sun, Sep 4, 2016 at 11:35 PM, Anselm R Garbe  wrote:
> See http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf 6.5.3
> for unary operator specification of the C language.

6.5.3 shows (the relevant parts)
unary-expression:
postfix-expression

sizeof unary-expression
sizeof ( type-name )

6.5.2:
postfix-expression:
primary-expression


6.5.1:
primary-expression:

( expression )

As a result the parens are required for types, and acceptable for variables.



[hackers] [9base][patch] add bclib

2016-08-17 Thread Evan Gates
bclib, for use with bc -l, is missing from 9base. I grabbed the file
from plan 9 sources, and made some changes to the makefiles in order
to install it.

I'm also including a patch to fix a typo I made in the yacc makefile.

-emg
From be81a44c57e884da9c53acc2a83eeb7b80effb0c Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Wed, 17 Aug 2016 11:40:29 -0700
Subject: [PATCH] fix DESTDIRK typo in yacc/Makefile

---
 yacc/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/yacc/Makefile b/yacc/Makefile
index ce9a420..bd9136c 100644
--- a/yacc/Makefile
+++ b/yacc/Makefile
@@ -6,8 +6,8 @@ TARG  = yacc
 include ../std.mk
 
 pre-uninstall:
-   rm -f ${DESTDIRK}${PREFIX}/yacc/yaccpar
-   rm -f ${DESTDIRK}${PREFIX}/yacc/yaccpars
+   rm -f ${DESTDIR}${PREFIX}/yacc/yaccpar
+   rm -f ${DESTDIR}${PREFIX}/yacc/yaccpars
 
 post-install:
@mkdir -p ${DESTDIR}${PREFIX}/yacc
-- 
2.9.3

From cd7fee3aa658de3d683ef8fc4f3d03ecde37e5ae Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Wed, 17 Aug 2016 11:45:57 -0700
Subject: [PATCH] add bclib from plan 9 sources

add post-install and pre-uninstall targets to tools using yacc.mk
mirroring those in std.mk in order to install and uninstall bclib
---
 awk/Makefile  |   4 +
 bc/Makefile   |   7 ++
 bc/bclib  | 246 ++
 grep/Makefile |   4 +
 hoc/Makefile  |   4 +
 yacc.mk   |   6 +-
 6 files changed, 269 insertions(+), 2 deletions(-)
 create mode 100644 bc/bclib

diff --git a/awk/Makefile b/awk/Makefile
index 80b32eb..d0e86b3 100644
--- a/awk/Makefile
+++ b/awk/Makefile
@@ -7,3 +7,7 @@ YFILES= awkgram.y
 MANFILES  = awk.1
 
 include ../yacc.mk
+
+pre-uninstall:
+
+post-install:
diff --git a/bc/Makefile b/bc/Makefile
index 0d3d1b0..8eed9d5 100644
--- a/bc/Makefile
+++ b/bc/Makefile
@@ -10,3 +10,10 @@ include ../yacc.mk
 
 # Solaris
 #LDFLAGS += -dy -lxnet
+
+pre-uninstall:
+   rm -f ${DESTDIR}${PREFIX}/lib/bclib
+
+post-install:
+   @mkdir -p ${DESTDIR}${PREFIX}/lib
+   @cp bclib ${DESTDIR}${PREFIX}/lib/
diff --git a/bc/bclib b/bc/bclib
new file mode 100644
index 000..97b1c92
--- /dev/null
+++ b/bc/bclib
@@ -0,0 +1,246 @@
+scale = 50
+define e(x) {
+   auto a, b, c, d, e, g, w, y, t, r
+
+   r = ibase
+   ibase = A
+
+   t = scale
+   scale = t + .434*x + 1
+
+   w = 0
+   if(x<0) {
+   x = -x
+   w = 1
+   }
+   y = 0
+   while(x>2) {
+   x /= 2
+   y++
+   }
+
+   a = 1
+   b = 1
+   c = b
+   d = 1
+   e = 1
+   for(a=1; 1; a++) {
+   b *= x
+   c = c*a+b
+   d *= a
+   g = c/d
+   if(g == e) {
+   g = g/1
+   while(y--) {
+   g *= g
+   }
+   scale = t
+   if(w==1) {
+   ibase = r
+   return 1/g
+   }
+   ibase = r
+   return g/1
+   }
+   e = g
+   }
+}
+
+define l(x) {
+   auto a, b, c, d, e, f, g, u, s, t, r, z
+
+   r = ibase
+   ibase = A
+   if(x <= 0) {
+   z = 1-10^scale
+   ibase = r
+   return z
+   }
+   t = scale
+
+   f = 1
+   scale += scale(x) - length(x) + 1
+   s = scale
+   while(x > 2) {
+   s += (length(x)-scale(x))/2 + 1
+   if(s>0) {
+   scale = s
+   }
+   x = sqrt(x)
+   f *= 2
+   }
+   while(x < .5) {
+   s += (length(x)-scale(x))/2 + 1
+   if(s>0) {
+   scale = s
+   }
+   x = sqrt(x)
+   f *= 2
+   }
+
+   scale = t + length(f) - scale(f) + 1
+   u = (x-1)/(x+1)
+
+   scale += 1.1*length(t) - 1.1*scale(t)
+   s = u*u
+   b = 2*f
+   c = b
+   d = 1
+   e = 1
+   for(a=3; 1; a=a+2){
+   b *= s
+   c = c*a + d*b
+   d *= a
+   g = c/d
+   if(g==e) {
+   scale = t
+   ibase = r
+   return u*c/d
+   }
+   e = g
+   }
+}
+
+define s(x) {
+   auto a, b, c, s, t, y, p, n, i, r
+
+   r = ibase
+   ibase = A
+   t = scale
+   y = x/.7853
+   s = t + length(y) - scale(y)
+   if(s<t) {
+   s = t
+   }
+   scale = s
+   p = a(1)
+
+   scale = 0
+   if(x>=0) {
+   n = (x/(2*p)+1)/2
+   }
+   if(x<0) {
+   n = (x/(2*p)-1)/2
+   }
+   x -= 4*n*p
+   if(n%2 != 0) {
+   x =

Re: [hackers] [sbase] [PATCH 3/3] ed: Fix substitutions with non-determinate patterns

2016-07-26 Thread Evan Gates
On Mon, Jul 25, 2016 at 8:47 PM, Wolfgang Corcoran-Mathe
 wrote:
> Right, and the same behavior is shown by all the seds I’ve seen (GNU,
> BSD, Busybox & Plan 9).  Interestingly, both GNU and BSD ed give an
> error instead (for global substitution against a null-matching regex).

Some more observations. Plan 9 sed has a definite bug, either way you
look at it.

[egates-devbox ~ 616]$ echo foobar | 9 sed 's/a*/./g'
.f.o.o.b..r

vi gives the same as 9 sed: .f.o.o.b..r

vim gives: .f.o.o.b.r

GNU awk, mawk, nawk, and 9 awk all return the same as sed, .f.o.o.b.r.
busybox awk gives .f.o.o.b..r.

9 ed gives us the same as busybox awk .f.o.o.b..r.
busybox ed is just plain broken in so many ways. I can't even get a result here.

Oh what fun! I think sed currently has the correct solution, but
that's because I spent some time convincing myself that was correct
and implementing it. I think I'll start a conversation on the Austin
ML to see what POSIX does or should require in this case. That being
said I know sbase is designed to deviate from POSIX where the result
would be complicated or non-intuitive.

emg



Re: [hackers] [sbase] [PATCH 3/3] ed: Fix substitutions with non-determinate patterns

2016-07-25 Thread Evan Gates
On Sun, Jul 24, 2016 at 8:17 PM, Wolfgang Corcoran-Mathe
 wrote:
> Sorry, this last patch is simpleminded.
>
> Given the following text and substitution, what should happen?
>
> 'glorious'
>
> s/G*/P/g
>
> sbase sed(1) gives us 'PgPlPoPrPiPoPuPsP' (matching every null
> string), while GNU ed(1) gives an error.  The above patch does
> not throw an error, but rather performs the first substitution
> and stops.
>
> Is there a case in which a global substitution for a regex that
> matches the null string is useful?  Should we produce output like
> 'PgPlPoPrPiPoPuPsP' (which is almost certainly unwanted garbage)
> or assume that such an expression is a mistake?
>
> Regards,
>
> --
> wcm
>

The sed behavior is based on other sed implementations. I think I
based it on GNU sed and busybox sed test cases that make sure to
increment the position in the string by one after each 0 length match.
Whereas GNU has problems with consistency, I think sbase should not.
Whether that means changing ed or sed, I think they should give the
same result. That being said I still think sed is in desperate need of
a (probably complete) rewrite in order to handle null bytes (i.e.
don't use libc string functions).

-emg



[hackers] [sbase][ed][patch] subtract 'a' from indices for marks

2016-07-15 Thread Evan Gates
Given:

static int marks['z' - 'a'];
marks[c];

In this case c is the character read and index is out of bounds. We
need marks[c - 'a']

While playing around with optimization settings gcc caught caught this.

Also fix one check for c, change from isalpha to islower.

-emg
From 2cc36818283e9068576c1042690c016a81b709a3 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.ga...@gmail.com>
Date: Fri, 15 Jul 2016 09:52:39 -0700
Subject: [PATCH] fix marks indexing

---
 ed.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ed.c b/ed.c
index ce19cf7..184ed30 100644
--- a/ed.c
+++ b/ed.c
@@ -478,9 +478,9 @@ linenum(int *line)
break;
case '\'':
skipblank();
-   if (!isalpha(c = input()))
+   if (!islower(c = input()))
error("invalid mark character");
-   if (!(ln = marks[c]))
+   if (!(ln = marks[c - 'a']))
error("invalid address");
break;
case '$':
@@ -1191,7 +1191,7 @@ repeat:
error("invalid mark character");
chkprint(1);
deflines(curln, curln);
-   marks[c] = line1;
+   marks[c - 'a'] = line1;
break;
case 'P':
if (nlines > 0)
-- 
2.9.0



Re: [hackers] [scc] Remove CPPFLAGS from Makefiles || Roberto E. Vargas Caballero

2015-11-25 Thread Evan Gates
On Wed, Nov 25, 2015 at 1:03 AM,   wrote:
> Remove CPPFLAGS from Makefiles
>
> CPPFLAGS is not POSIX, so it is better to define
> everything in CFLAGS and become more portable.

Glanced at the makefiles after the mention of POSIX here. Note the
.POSIX target is required to be the first non comment line in the
makefile.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html#tag_20_76_13_04

-emg



[hackers] [sbase]patch: man pages for sed and find

2015-08-04 Thread Evan Gates
They aren't pretty, they aren't complete, but they should be enough
for the 0.1 release.

-emg


find.1
Description: Binary data


sed.1
Description: Binary data


Re: [hackers] [scc][PATCH] Add total compability to the Makefiles

2015-07-16 Thread Evan Gates
On Thu, Jul 16, 2015 at 11:32 AM, Evan Gates evan.ga...@gmail.com wrote:
 A few notes on using sh.

Oh and one more I missed. You have

make $@

which should be

make $@

in order to maintain proper arguments. (In general there should never
be an unquoted expansion/substitution. There are a few acceptable uses
in POSIX sh as it doesn't support arrays.)

For example, notice how unquoted incorrectly expands to 3 parameters
instead of 2:

$ f() { printf '%s' $@; echo; printf '%s' $@; echo; }
$ f foo 'bar baz'
foobarbaz
foobar baz

-emg



Re: [hackers] [scc][PATCH] Add total compability to the Makefiles

2015-07-16 Thread Evan Gates
A few notes on using sh.

The x$var notation is unnecessary and a holdover from very old
prePOSIX shells that had difficulty handling certain arguments or
argument orders with test/[. In this instance, as you are trying to
explicitly match against an empty/unset variable within a case
statement I would write it as:

case $cc in
c99)
;;
''|gcc)
...

I also highly recommend against using backticks for command
substitution. $(cmd) follows the convention of using $ to introduce
a substitution and is easier to correctly nest and quote (that being
said the   case word in   is one of the very few places in which
quoting is not necessary as word splitting and glob expansion do not
happen, but it doesn't hurt either...). As such I would write the
first case as

case $(uname) in

Both of those are technically style related, but are IMO good
practice. Feel free to take it or leave it.


In build.sh you have an sh shebang but use source which is a bashism.
For sh it should be . not source.

-emg



Re: [hackers] [sbase][patch] find: empty line means no for -ok

2015-06-18 Thread Evan Gates
On Thu, Jun 18, 2015 at 3:57 PM, Wolfgang Corcoran-Mathe
first.lord.of.t...@gmail.com wrote:
 emg,

 Quoth Evan Gates on Thu, Jun 18 2015 14:47 -0700:

 diff --git a/find.c b/find.c
 index 186263b..0de1951 100644
 --- a/find.c
 +++ b/find.c
 @@ -415,10 +415,9 @@ pri_ok(struct arg *arg)
 reply = fgetc(stdin);

 /* throw away rest of line */
 -   while ((c = fgetc(stdin)) != '\n'  c != EOF)
 -   /* FIXME: what if the first character of the rest of the
 line is a null
 -* byte? */
 -   ;
 +   if (c != '\n')
 +   while ((c = fgetc(stdin)) != '\n'  c != EOF)
 +   ;


 I think you meant

if (reply != '\n')
...

Yes I most certainly did, this is what I get for submitting patches
without testing. The shame. New patch attached, also protects against
the glibc bug causing fgetc to hang after EOF was received.
-emg
From 9f3e3e5d9d8652e8df91c66aae7ecd9f5e8769ae Mon Sep 17 00:00:00 2001
From: Evan Gates evan.ga...@gmail.com
Date: Thu, 18 Jun 2015 18:00:06 -0700
Subject: [PATCH] empty line means no for -ok (also protect against glibc EOF
 bug)

---
 find.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/find.c b/find.c
index 186263b..f56e0bb 100644
--- a/find.c
+++ b/find.c
@@ -415,10 +415,9 @@ pri_ok(struct arg *arg)
reply = fgetc(stdin);
 
/* throw away rest of line */
-   while ((c = fgetc(stdin)) != '\n'  c != EOF)
-   /* FIXME: what if the first character of the rest of the line 
is a null
-* byte? */
-   ;
+   if (reply != '\n'  reply != EOF)
+   while ((c = fgetc(stdin)) != '\n'  c != EOF)
+   ;
 
if (feof(stdin)) /* FIXME: ferror()? */
clearerr(stdin);
-- 
2.4.4



[hackers] [9base][patch] cal: Bprint format specifier

2015-06-18 Thread Evan Gates
Bprint didn't seem to like %u, giving the following output:

[egates-vm 9base 686]$ cal/cal
   June %
% S  M Tu  W Th  F  S
1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Changing to %d fixes this:

[egates-vm 9base 692]$ cal/cal
   June 2015
 S  M Tu  W Th  F  S
1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Patch attached.
-emg
From ae17848c795860d34d358fb50f5c2188e59ec2e4 Mon Sep 17 00:00:00 2001
From: Evan Gates evan.ga...@gmail.com
Date: Thu, 18 Jun 2015 10:57:29 -0700
Subject: [PATCH] change %u to %d

---
 cal/cal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cal/cal.c b/cal/cal.c
index 3f1e075..36dd9dd 100644
--- a/cal/cal.c
+++ b/cal/cal.c
@@ -84,7 +84,7 @@ xshort:
goto badarg;
if(y  1 || y  )
goto badarg;
-   Bprint(bout,%s %u\n, smon[m-1], y);
+   Bprint(bout,%s %d\n, smon[m-1], y);
Bprint(bout, %s\n, dayw);
cal(m, y, string, 24);
for(i=0; i6*24; i+=24)
@@ -99,7 +99,7 @@ xlong:
if(y1 || y)
goto badarg;
Bprint(bout, \n\n\n);
-   Bprint(bout, %u\n, y);
+   Bprint(bout, %d\n, y);
Bprint(bout, \n);
for(i=0; i12; i+=3) {
for(j=0; j6*72; j++)
-- 
2.4.4



Re: [hackers] [sbase] [PATCH] find: Fix unterminated array

2015-06-15 Thread Evan Gates
On Sat, Jun 13, 2015 at 10:42 PM, Wolfgang Corcoran-Mathe
first.lord.of.t...@gmail.com wrote:
 This caused a segfault with semicolon-terminated -exec primaries.

good catch, needs to be done in get_ok_arg() as well, not currently
somewhere I can do that, mind adding another patch?
-emg



Re: [hackers] [sbase] [PATCH] find: Fix unterminated array

2015-06-15 Thread Evan Gates
On Mon, Jun 15, 2015 at 9:28 AM, Evan Gates evan.ga...@gmail.com wrote:
 On Sat, Jun 13, 2015 at 10:42 PM, Wolfgang Corcoran-Mathe
 first.lord.of.t...@gmail.com wrote:
 This caused a segfault with semicolon-terminated -exec primaries.

 good catch, needs to be done in get_ok_arg() as well, not currently
 somewhere I can do that, mind adding another patch?
 -emg

I'd recommend checking the isplus branch as well. If I screwed up the
semicolon case chances are I screwed up the plus case, too.
-emg



Re: [hackers] [sbase] [PATCH 1/3] find: Fix unterminated array in -ok primary

2015-06-15 Thread Evan Gates
On Mon, Jun 15, 2015 at 12:27 PM, Wolfgang Corcoran-Mathe
first.lord.of.t...@gmail.com wrote:
 ---
  find.c | 1 +
  1 file changed, 1 insertion(+)

 diff --git a/find.c b/find.c
 index dedf5a1..a870a90 100644
 --- a/find.c
 +++ b/find.c
 @@ -429,6 +429,7 @@ pri_ok(struct arg *arg)
 /* insert filename everywhere user gave us {} */
 for (brace = o-braces; *brace; brace++)
 **brace = arg-path;
 +   *brace = NULL;

 switch((pid = fork())) {
 case -1:
 --
 2.3.5



Not needed there, *brace will already be NULL or the loop wouldn't
have stopped (the cause of the segfault). Needed in get_ok_arg() so
that it is NULL when we get here. See attached.

-emg
From d842da4c8f9fffd304858a0ae62f1c2933c97cef Mon Sep 17 00:00:00 2001
From: Evan Gates evan.ga...@gmail.com
Date: Mon, 15 Jun 2015 13:49:38 -0700
Subject: [PATCH] NULL terminate braces array in get_ok_arg

---
 find.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/find.c b/find.c
index dcefca5..e9d8c1d 100644
--- a/find.c
+++ b/find.c
@@ -635,6 +635,7 @@ get_ok_arg(char *argv[], union extra *extra)
for (arg = argv, braces = o-braces; *arg; arg++)
if (!strcmp(*arg, {}))
*braces++ = arg;
+   *braces = NULL;
 
gflags.print = 0;
return arg;
-- 
2.4.3



Re: [hackers] [sbase] [PATCH 2/3] find: Fix flushing input buffer with -ok

2015-06-15 Thread Evan Gates
On Mon, Jun 15, 2015 at 12:27 PM, Wolfgang Corcoran-Mathe
first.lord.of.t...@gmail.com wrote:
 emg's FIXME about nulls still applies.

 /* throw away rest of line */
 -   while (fgets(buf, sizeof(buf), stdin)  *buf  buf[strlen(buf) - 1] 
 == '\n')
 +   while ((c = fgetc(stdin)) != '\n'  c != EOF)
 /* FIXME: what if the first character of the rest of the line 
 is a null
 -* byte? probably shouldn't juse fgets() */
 +* byte? */
 ;

Nope, not a problem anymore as you're explicitly checking against '\n'
and EOF so reading a '\0' is fine. Much better than the fgets.

-emg



Re: [hackers] [sbase] [PATCH] find

2015-06-15 Thread Evan Gates
On Mon, Jun 15, 2015 at 12:27 PM, Wolfgang Corcoran-Mathe
first.lord.of.t...@gmail.com wrote:
 emg,

 I noticed a few other things in get_ok_arg(), primarily that the fgets()
 flushing loop was causing find to hang mysteriously. Patch 2/3 should
 fix this, hopefully.

Should have said   buf[strlen(buf) - 1] != '\n'   in order to keep
reading until we got a full newline terminated line of input, not sure
how that got through. I prefer your solution as it doesn't run into
any of the '\0' problems.

 The isplus branch seems to work, based on limited testing.

Yep, it looks alright, the bug was specific to the array of pointers
to {} used in -ok and -exec \;
I had originally thought it was a bug relating to NULL termination for
execvp() when reading your mail (I finally have the code in front of
me, that's helpful).

 I've enjoyed reading your code, btw.

Thanks! Good to hear. Criticism, constructive or otherwise, is always welcome.
-emg



Re: [hackers] [sbase] expr: Don't interpret any arguments || sin

2015-04-21 Thread Evan Gates
Patch attached to accept and ignore leading --
-emg
From 52754da6090e98f82a5dfbf56c49693a3282e14f Mon Sep 17 00:00:00 2001
From: Evan Gates evan.ga...@gmail.com
Date: Tue, 21 Apr 2015 10:32:32 -0700
Subject: [PATCH] accept and ignore leading -- for expr

---
 expr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/expr.c b/expr.c
index 608d9a8..80e2579 100644
--- a/expr.c
+++ b/expr.c
@@ -258,6 +258,8 @@ main(int argc, char *argv[])
int ret;
 
argv0 = argv[0], argc--, argv++;
+   if (!strcmp(*argv, --))
+   argc--, argv++;
ret = !parse(argv, argc);
enfshut(3, stdout, stdout);
 
-- 
2.3.5



Re: [hackers] [sbase] expr: Don't interpret any arguments || sin

2015-04-21 Thread Evan Gates
If you want to allow a negative number to come first and not be
treated as an option that is fine, but you still need to accept -- as
an end to options. From the last paragraph of the APPLICATION USAGE
section of expr(1p)[0]:

Therefore, the conforming application must employ the -- construct
of Guideline 10 of the Base Definitions volumne of POSIX.1-2008,
Section 12.2, Utility Syntax Guidelines to protect its operands if
there is any chance the first operand might be a negative integer (or
any string with a leading minus).

We need to accept then ignore -- as a first argument. We can accept a
first argument with a leading - as a non-option if we want as an
extension.

-emg

[0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expr.html

On Tue, Apr 21, 2015 at 9:09 AM,  g...@suckless.org wrote:
 commit 504855ff96389b02fd92197792a7b26069cde593
 Author: sin s...@2f30.org
 Date:   Tue Apr 21 17:08:14 2015 +0100

 expr: Don't interpret any arguments

 expr -1 '' 1 failed previously.

 There is no need to have usage at all, any errors will be flagged
 up as necessary further down.

 diff --git a/expr.c b/expr.c
 index 5e4f19d..608d9a8 100644
 --- a/expr.c
 +++ b/expr.c
 @@ -252,22 +252,12 @@ parse(char *expr[], int numexpr)
 return (valp-str  *valp-str) || valp-num;
  }

 -static void
 -usage(void)
 -{
 -   enprintf(3, usage: %s expression\n, argv0);
 -}
 -
  int
  main(int argc, char *argv[])
  {
 int ret;

 -   ARGBEGIN {
 -   default:
 -   usage();
 -   } ARGEND;
 -
 +   argv0 = argv[0], argc--, argv++;
 ret = !parse(argv, argc);
 enfshut(3, stdout, stdout);





Re: [hackers] [sbase] Audit expr(1) || FRIGN

2015-03-23 Thread Evan Gates
If you want to pass structs by pointer instead of value as a style
change, that's ok. But then you're still using assignment instead of
memcpy(), well at least in one place, elsewhere you assign each member
individually. Why? What's wrong with passing/returning/assigning
structures? It's useful and clear and creates symmetry with builtin
types, i.e. writing a statement that does the same thing, the same way
with builtin and user defined types, as opposed to writing it two
different ways.

I disagree with getting rid of valstr() and instead duplicating the
code 4 times and using strings of if else blocks. It makes the code
longer and more confusing. It also introduces unnecessary allocations
alongside VLAs e.g. anchreg. And seeing as anchreg is now allocated
the use of sizeof(anchreg) in estrlcpy and estrlcat is wrong.

I disagree with adding 0, VAL, (, and ) to the precedence array. They
are not operators and do not have precedence, and the array is already
zero filled until the last element which is NE.

(*valp).str = v.str;
how about valp-str ... etc.

I disagree with removing all comments in the code, especially the one
explaining the algorithm used and a link to a better explanation of
it. The code is fairly simple but the algorithm is not obvious to
those who have not witnessed it before.



On Mon, Mar 23, 2015 at 10:35 AM,  g...@suckless.org wrote:
 commit a893db82b1029800f0d20ebb370946d94b9d174e
 Author: FRIGN d...@frign.de
 Date:   Sun Mar 22 14:32:56 2015 +0100

 Audit expr(1)

 No bugs found, but I changed intmax_t to long long to make it more
 predictable and removed some of the kitchen-sinking.
 Don't return structs themselves, as this is not very elegant.
 Do it like functions like stat(), which take a pointer to a
 struct to fill.

 diff --git a/README b/README
 index 4d97f00..a46dd79 100644
 --- a/README
 +++ b/README
 @@ -30,7 +30,7 @@ The following tools are implemented ('*' == finished, '#' 
 == UTF-8 support,
  =*| echoyes  none
  =*| env yes  none
  #*| expand  yes  none
 -#*  expryes  none
 +#*| expryes  none
  =*| false   yes  none
  =   findyes  none
  #*| foldyes  none
 diff --git a/expr.c b/expr.c
 index ef7c303..31b3726 100644
 --- a/expr.c
 +++ b/expr.c
 @@ -1,205 +1,203 @@
  /* See LICENSE file for copyright and license details. */
 -#include inttypes.h
 +#include limits.h
  #include stdio.h
 +#include stdlib.h
  #include string.h

  #include utf.h
  #include util.h

 -/* token types for lexing/parsing
 - * single character operators represent themselves */
 +/* tokens, one-character operators represent themselves */
  enum {
 VAL = CHAR_MAX + 1, GE, LE, NE
  };

  struct val {
 -   char *s; /* iff s is NULL, val is an integer */
 -   intmax_t n;
 +   char *str;
 +   long long num;
  };

 -static size_t intlen;
 +static size_t maxdigits;

  static void
 -enan(struct val v)
 +enan(struct val *v)
  {
 -   if (v.s)
 -   enprintf(2, syntax error: expected integer got `%s'\n, v.s);
 +   if (!v-str)
 +   return;
 +   enprintf(2, syntax error: expected integer, got %s\n, v-str);
  }

  static void
 -ezero(intmax_t n)
 +ezero(struct val *v)
  {
 -   if (n == 0)
 -   enprintf(2, division by zero\n);
 -}
 -
 -static char *
 -valstr(struct val val, char *buf, size_t bufsiz)
 -{
 -   if (val.s)
 -   return val.s;
 -   snprintf(buf, bufsiz, %PRIdMAX, val.n);
 -   return buf;
 +   if (v-num != 0)
 +   return;
 +   enprintf(2, division by zero\n);
  }

  static int
 -valcmp(struct val a, struct val b)
 +valcmp(struct val *a, struct val *b)
  {
 -   char buf1[intlen], buf2[intlen];
 -   char *astr = valstr(a, buf1, sizeof(buf1));
 -   char *bstr = valstr(b, buf2, sizeof(buf2));
 +   int ret;
 +   char buf[maxdigits];
 +
 +   if (!a-str  !b-str) {
 +   ret = (a-num  b-num) - (a-num  b-num);
 +   } else if (a-str  !b-str) {
 +   snprintf(buf, sizeof(buf), %lld, b-num);
 +   ret = strcmp(a-str, buf);
 +   } else if (!a-str  b-str) {
 +   snprintf(buf, sizeof(buf), %lld, a-num);
 +   ret = strcmp(buf, b-str);
 +   } else {
 +   ret = strcmp(a-str, b-str);
 +   }

 -   if (!a.s  !b.s)
 -   return (a.n  b.n) - (a.n  b.n);
 -   return strcmp(astr, bstr);
 +   return ret;
  }

 -/* match vstr against BRE vregx (treat both values as strings)
 - * if there is at least one subexpression \(...\)
 - * then return the text matched by it \1 (empty string for no match)
 - * else return number of characters matched (0 for no match)
 - */
 -static struct val
 

Re: [hackers] [sbase] Audit printenv(1) || FRIGN

2015-02-28 Thread Evan Gates
 2) safeguard argv-loop as already seen in echo(1) with argc-decrement.

The arg loops can simply be for (; *argv; argv++) as the standard
guarantees argv[argc] is NULL.

-emg


Re: [hackers] [sbase] config.mk: make cc the default $CC || Hiltjo Posthuma

2014-11-11 Thread Evan Gates
On Mon, Nov 10, 2014 at 10:39 PM,  k...@shike2.com wrote:

 If you want to do that, then the only thing you have to do is
 don't assign any value to CC, because cc is the default value.
 If you do in this way then the user can set his prefered
 compiler exporting CC. The same apply to LD, there is
 a default value that is the correct for the system.

Worth noting that POSIX doesn't specify a value for LD.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html#tag_20_76_13_09

-emg