Re: text vs. binary [Re: more gcc warnings]

2005-07-12 Thread Paul Eggert
[EMAIL PROTECTED] (Eric Blake) writes:

 http://lists.gnu.org/archive/html/bug-coreutils/2005-05/msg00136.html

I just looked at that, and don't really follow all the DOS stuff, but
have these comments anyway:

 cat - POSIX requires binary input and output, and this already has -B option 
 to fine-tune mode

I've removed -B.  It didn't really work on DOS, as far as I could see.
And it wasn't portable (it didn't work on GNU/Linux).

 head - POSIX requires text input, but compare to tail -c on binary input

Currently head runs in binary mode (which means, in DOS, that it
uses binary mode except if stdin/stdout is a tty).

 nohup - POSIX requires that stdout from utility may to go to nohup.out, so
 nohup.out should probably be opened in same mode as nohup's stdout (if it
 exists)

nohup.out is currently opened in text mode.  Let's just leave that
alone, unless someone really needs it.  (I doubt whether they will.)

 I've thought
 more about fcntl(fd, F_SETFL, flags), where the nice gnulib behavior
 would be:
 neither O_BINARY nor O_TEXT: leave mode unchanged
 O_BINARY: if not tty, force binary mode
 O_TEXT: if not tty, force text mode
 O_BINARY | O_TEXT: if not tty, swap mode

My kneejerk reaction is that sounds pretty confusing.  But perhaps I
don't see the application area.

 and have a wrapper on MS-DOS that defines freopen to not do anything
 if the first argument is NULL, the second ends in b, and the third a
 standard tty?

 Since POSIX states that w+b and wb+ are synonyms, for example,

OK, use 'contains b' instead of 'ends in b'.

 I'd like to see a deprecation period rather than outright removal,
 where -B is undocumented, and using it evokes a warning but
 is otherwise a no-op (rather than a fatal unrecognized option).

You could talk me into that, yes.

 Are there non-standard hosts out there that don't treat ab as
 a synonym to a per POSIX

Yes.  At least, such hosts used to exist.  Maybe we needn't worry
about them now.  I suppose I can rip out the (O_BINARY ? rb : r)
stuff.  (Though this does save a byte on POSIX hosts.  :-)


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: text vs. binary [Re: more gcc warnings]

2005-07-12 Thread Bob Proulx
Paul Eggert wrote:
 [EMAIL PROTECTED] (Eric Blake) writes:
  nohup - POSIX requires that stdout from utility may to go to nohup.out, so
  nohup.out should probably be opened in same mode as nohup's stdout (if it
  exists)
 
 nohup.out is currently opened in text mode.  Let's just leave that
 alone, unless someone really needs it.  (I doubt whether they will.)

Since nohup.out is expected to be the terminal output of the command
it makes the most sense to me if it is text mode since it is most
likely to always be text.  It seems very unlikely any normal case
would not be text.

Bob


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


text vs. binary [Re: more gcc warnings]

2005-07-11 Thread Eric Blake
 I've been putting off cleaning up this mess, but I found the time this
 weekend to give it a start.  I installed the following patch.  It
 avoids the use of setmode and io.h entirely, and it cleans up some
 of the inconsistencies in the code (in some cases, they were bugs that
 even infected the GNU/Linux version -- ouch!).

Thanks for starting this task.

 
 Since I don't use DOS, someone with some expertise in that area will
 have to double-check it.

I'm willing to check it on cygwin.  This is a partial review, I will probably
have more comments as I get more time to actually comple and test
some of the changes.  It would also be nice if someone could give anon
CVS a kick; it has been stuck since the 5th.

I would also like to compare your work to my email on the subject a
couple of months ago:
http://lists.gnu.org/archive/html/bug-coreutils/2005-05/msg00136.html

 
 I dislike all that isatty stuff -- is there some way that we could
 easily remove it from the mainline sources, and put it in config.h or
 somewhere we we don't have to see it?  For example, can we replace this:
 
   if (O_BINARY  ! isatty (STDIN_FILENO))
 freopen (NULL, rb, stdin);
 
 with this:
 
   if (O_BINARY)
 freopen (NULL, rb, stdin);

Sounds like a good candidate for a gnulib module.  Also, I've thought
more about fcntl(fd, F_SETFL, flags), where the nice gnulib behavior
would be:
neither O_BINARY nor O_TEXT: leave mode unchanged
O_BINARY: if not tty, force binary mode
O_TEXT: if not tty, force text mode
O_BINARY | O_TEXT: if not tty, swap mode

 
 and have a wrapper on MS-DOS that defines freopen to not do anything
 if the first argument is NULL, the second ends in b, and the third a
 standard tty?

Since POSIX states that w+b and wb+ are synonyms, for example,
we should be a little more careful than just checking for ends in 'b'.  Or
is there a coding style that states which of the two we should prefer?

 Index: src/cat.c
 @@ -553,9 +543,6 @@ main (int argc, char **argv)
  {show-ends, no_argument, NULL, 'E'},
  {show-tabs, no_argument, NULL, 'T'},
  {show-all, no_argument, NULL, 'A'},
 -#if O_BINARY
 -{binary, no_argument, NULL, 'B'},
 -#endif

I'd like to see a deprecation period rather than outright removal,
where -B is undocumented, and using it evokes a warning but
is otherwise a no-op (rather than a fatal unrecognized option).

 Index: src/tac.c
 Index: src/tee.c
 @@ -140,7 +140,10 @@ tee (int nfiles, const char **files)
ssize_t bytes_read;
int i;
bool ok = true;
 -  const char *mode_string = (append ? a : w);
 +  char const *mode_string =
 +(O_BINARY
 + ? (append ? ab : wb)
 + : (append ? a : w));

Are there non-standard hosts out there that don't treat ab as
a synonym to a per POSIX, and if so, should we cater to them
with a gnulib module?  It is much more readable to write this as:

char const *mode_string = (append ? ab : wb);

--
Eric Blake




___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils