Re: Dropping needless globals (ksh)

2015-09-10 Thread Alexey Suslikov
Michael McConville  sccs.swarthmore.edu> writes:

> RCS file: /cvs/src/bin/ksh/c_ksh.c,v



> - shprintf(newline);
> + shprintf("\n");

In terms of portability, are you sure newline is \n on all platforms?



Re: Dropping needless globals (ksh)

2015-09-10 Thread Michael McConville
Alexey Suslikov wrote:
> Michael McConville  sccs.swarthmore.edu> writes:
> 
> > RCS file: /cvs/src/bin/ksh/c_ksh.c,v
> 
> 
> 
> > -   shprintf(newline);
> > +   shprintf("\n");
> 
> In terms of portability, are you sure newline is \n on all platforms?

I'm not. Do we do this sort of thing elsewhere in the toolchain, though?
It seems that \n is often hardcoded in the ksh code, too.



Re: Dropping needless globals (ksh)

2015-09-10 Thread Nicholas Marriott
looks good to me, any other ok?

null is serious poo and really needs to go as well


On Thu, Sep 10, 2015 at 10:45:46AM -0400, Michael McConville wrote:
> Does this look good? I'm not sure why these globals existed.
> 
> It looks like it's going to take a little more than search-and-replace
> to remove null.
> 
> 
> Index: c_ksh.c
> ===
> RCS file: /cvs/src/bin/ksh/c_ksh.c,v
> retrieving revision 1.36
> diff -u -p -r1.36 c_ksh.c
> --- c_ksh.c   8 Sep 2015 11:35:57 -   1.36
> +++ c_ksh.c   10 Sep 2015 14:37:54 -
> @@ -515,7 +515,7 @@ c_whence(char **wp)
>   break;
>   }
>   if (vflag || !ret)
> - shprintf(newline);
> + shprintf("\n");
>   }
>   return ret;
>  }
> @@ -816,7 +816,7 @@ c_typeset(char **wp)
>   else
>   
> print_value_quoted(s);
>   }
> - shprintf(newline);
> + shprintf("\n");
>   }
>   /* Only report first `element' of an 
> array with
>   * no set elements.
> @@ -906,7 +906,7 @@ c_alias(char **wp)
>   shf_putc('=', shl_stdout);
>   print_value_quoted(ap->val.s);
>   }
> - shprintf(newline);
> + shprintf("\n");
>   }
>   }
>  
> @@ -930,7 +930,7 @@ c_alias(char **wp)
>   shf_putc('=', shl_stdout);
>   print_value_quoted(ap->val.s);
>   }
> - shprintf(newline);
> + shprintf("\n");
>   } else {
>   shprintf("%s alias not found\n", alias);
>   rv = 1;
> @@ -1184,10 +1184,10 @@ c_kill(char **wp)
>   }
>   } else if (Flag(FPOSIX)) {
>   p = null;
> - for (i = 1; i < NSIG; i++, p = space)
> + for (i = 1; i < NSIG; i++, p = " ")
>   if (sigtraps[i].name)
>   shprintf("%s%s", p, sigtraps[i].name);
> - shprintf(newline);
> + shprintf("\n");
>   } else {
>   int w, i;
>   int mess_width;
> Index: emacs.c
> ===
> RCS file: /cvs/src/bin/ksh/emacs.c,v
> retrieving revision 1.51
> diff -u -p -r1.51 emacs.c
> --- emacs.c   1 Sep 2015 13:12:31 -   1.51
> +++ emacs.c   10 Sep 2015 14:37:54 -
> @@ -1758,7 +1758,7 @@ x_expand(int c)
>   x_delete(end - start, false);
>   for (i = 0; i < nwords;) {
>   if (x_escape(words[i], strlen(words[i]), x_emacs_putbuf) < 0 ||
> - (++i < nwords && x_ins(space) < 0)) {
> + (++i < nwords && x_ins(" ") < 0)) {
>   x_e_putc(BEL);
>   return KSTD;
>   }
> @@ -1806,7 +1806,7 @@ do_complete(int flags,  /* XCF_{COMMAND,F
>   }
>   /* add space if single non-dir match */
>   if (nwords == 1 && words[0][nlen - 1] != '/') {
> - x_ins(space);
> + x_ins(" ");
>   completed = 1;
>   }
>  
> @@ -1914,7 +1914,7 @@ x_debug_info(int c)
>   shellf("\txbp == 0x%lx,\txbuf == 0x%lx\n", (long) xbp, (long) xbuf);
>   shellf("\txlp == 0x%lx\n", (long) xlp);
>   shellf("\txlp == 0x%lx\n", (long) x_lastcp());
> - shellf(newline);
> + shellf("\n");
>   x_redraw(-1);
>   return 0;
>  }
> Index: exec.c
> ===
> RCS file: /cvs/src/bin/ksh/exec.c,v
> retrieving revision 1.51
> diff -u -p -r1.51 exec.c
> --- exec.c18 Apr 2015 18:28:36 -  1.51
> +++ exec.c10 Sep 2015 14:37:54 -
> @@ -83,7 +83,7 @@ execute(struct op *volatile t,
>   PS4_SUBSTITUTE(str_val(global("PS4";
>   for (i = 0; ap[i]; i++)
>   shf_fprintf(shl_out, "%s%s", ap[i],
> - ap[i + 1] ? space : newline);
> + ap[i + 1] ? " " : "\n");
>   shf_flush(shl_out);
>   }
>   if (ap[0])
> @@ -499,7 +499,7 @@ comexec(struct op *t, struct tbl *volati
>   shf_fprintf(shl_out, "%s",
>   

Re: Dropping needless globals (ksh)

2015-09-10 Thread Nicholas Marriott
Hi

On Thu, Sep 10, 2015 at 04:33:07PM -0600, Todd C. Miller wrote:
> On Thu, 10 Sep 2015 23:26:53 +0100, Nicholas Marriott wrote:
> 
> > looks good to me, any other ok?
> > 
> > null is serious poo and really needs to go as well
> 
> Beware!  Some of these values are used in pointer comparisons so
> I'm not sure it is same to remove them.

Yes, that's what I meant :-).

Possibly they can be replaced by things like *p != '\0', but it is
complicated trying to work out if it is alright that any empty string
can be the same as null.

> I don't see any comparisons with newline so it should be safe
> to remove.

ok then?



Re: Dropping needless globals (ksh)

2015-09-10 Thread Michael McConville
Todd C. Miller wrote:
> On Thu, 10 Sep 2015 23:26:53 +0100, Nicholas Marriott wrote:
> > looks good to me, any other ok?
> > 
> > null is serious poo and really needs to go as well
> 
> Beware!  Some of these values are used in pointer comparisons so
> I'm not sure it is same to remove them.
> 
> I don't see any comparisons with newline so it should be safe
> to remove.

Indeed. This is why null is less trivial than the other two.



Re: Dropping needless globals (ksh)

2015-09-10 Thread Todd C. Miller
On Thu, 10 Sep 2015 23:43:15 +0100, Nicholas Marriott wrote:

> ok then?

OK for removing newline (and space too).

 - todd



Re: Dropping needless globals (ksh)

2015-09-10 Thread Todd C. Miller
On Thu, 10 Sep 2015 23:26:53 +0100, Nicholas Marriott wrote:

> looks good to me, any other ok?
> 
> null is serious poo and really needs to go as well

Beware!  Some of these values are used in pointer comparisons so
I'm not sure it is same to remove them.

I don't see any comparisons with newline so it should be safe
to remove.

 - todd



Re: Dropping needless globals (ksh)

2015-09-10 Thread Ted Unangst
Michael McConville wrote:
> Alexey Suslikov wrote:
> > Michael McConville  sccs.swarthmore.edu> writes:
> > 
> > > RCS file: /cvs/src/bin/ksh/c_ksh.c,v
> > 
> > 
> > 
> > > - shprintf(newline);
> > > + shprintf("\n");
> > 
> > In terms of portability, are you sure newline is \n on all platforms?
> 
> I'm not. Do we do this sort of thing elsewhere in the toolchain, though?
> It seems that \n is often hardcoded in the ksh code, too.

I think it's time we drop ebcdic support or whatever this is from various base
tools. We're not running a museum.

We should be reasonably tolerant of posix compatibility for the sake of
portability, but nothing ridiculous.