public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
[parent not found: <19981030020029.5367.rocketmail.cygnus.gnu-win32@send102.yahoomail.com>]
* Re: When is \n converted to \r\n? and why?
@ 1998-10-31 10:50 Earnie Boyd
  1998-11-02  5:50 ` Urban Widmark
  0 siblings, 1 reply; 10+ messages in thread
From: Earnie Boyd @ 1998-10-31 10:50 UTC (permalink / raw)
  To: Urban Widmark, Larry Hall; +Cc: gnu-win32

---Urban Widmark <urban@svenskatest.se> wrote:
>
> On Thu, 29 Oct 1998, Larry Hall wrote:
> 
> > 
> > Nope.  Its not a tr or any other kind of bug.  You said it
yourself above.
> > Translation is done when writing to (and reading from) the disk. 
How can
> > tr be expected to remove something that doesn't exist.  Remember,
text/
> > binary modes have to do with how things are written to files on
the disk,
> > not how they are handled in stdin, stdout, pipes, and whatever.
> > 
> 
> Which means writing the file to disk and then doing cat is not the
same as
> piping it directly. I think that is wrong.
> 

Yep!  Me too.

> Or is the \r removed when reading a \r\n file from disk with text
mode? 
> Is it always removed or does it depend on the program I use (eg cat
> doesn't remove it, tr/wc does ...).

In text mode processing the read function will remove the \r and
return subtract it from the count of bytes read.  If the file contains
only \n it will be read also, the only difference is that the \r is
removed and not counted as read and a C-z will cause a EOF.

Unless you've personally modified them cat, tr and wc use the default
processing mode which you have appropriately set to text mode.

> 
> The amount of problems this will cause seems endless if I have to
remember
> which programs convert and which doesn't. Assuming it matters for
the end
> result, which it did in this case, the windows program wouldn't work
if
> the configuration files we tried to generate contained \r. A bug in
that
> software? definitely! But the cygwin behaviour is still confusing.
> 

What _WINDOWS_ program doesn't like a \r\n?  Please inform us as this
is very unwindows like.

> 
> Btw, I don't have anything against \r\n, I just don't like when
programs
> convert things automagically when I haven't told them to do so ... I
guess
> it's a control thingy. :)

No what you mean.  But, if you understand what is happening you can
adjust for it.

==
-                  \\||//
-------------o0O0--Earnie--0O0o--------------
--          earnie_boyd@yahoo.com          --
-- http://www.freeyellow.com/members5/gw32 --
----------------ooo0O--O0ooo-----------------

PS: Newbie's, you should visit my page.
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: When is \n converted to \r\n? and why?
@ 1998-10-31  8:05 Earnie Boyd
  0 siblings, 0 replies; 10+ messages in thread
From: Earnie Boyd @ 1998-10-31  8:05 UTC (permalink / raw)
  To: Larry Hall, Urban Widmark, gnu-win32

---Larry Hall <lhall@rfk.com> wrote:
>
> At 04:18 PM 10/28/98 +0100, Urban Widmark wrote:
> >(using cygwin32 19.3 & 19.1?)
> >
> >If I create a small example file:
> >
> >$ echo a > xx
> >$ ls -l xx
> >-rw-r--r--   1 544      everyone        3 Oct 28 15:43 xx
> >
> >it will contain "a\r\n" since I use the default (non-binary mounts)
> >
> >But if I do:
> >$ echo a | wc -c
> >      2
> >
> >I get only 2 chars ... ok, so the translation is done when writing to
> >disk. Then something like this will fail:
> >
> >$ echo a | tr -d '\r' > yy
> >$ ls -l yy
> >-rw-r--r--   1 544      everyone        3 Oct 28 15:48 yy
> >
> >So how am I supposed to remove the \r from the echo output?  Well,
I know
> >non-cygwin ways to remove the \r, the issue is if this is a tr bug, a
> >cygwin conversion bug or ...
> 
> Nope.  Its not a tr or any other kind of bug.  You said it yourself
above.
> Translation is done when writing to (and reading from) the disk. 
How can
> tr be expected to remove something that doesn't exist.  Remember,
text/
> binary modes have to do with how things are written to files on the
disk,
> not how they are handled in stdin, stdout, pipes, and whatever.
> 

`tr' should setmode(outdesc, O_BINARY) to avoid rewriting the \r.

==
-                  \\||//
-------------o0O0--Earnie--0O0o--------------
--          earnie_boyd@yahoo.com          --
-- http://www.freeyellow.com/members5/gw32 --
----------------ooo0O--O0ooo-----------------

PS: Newbie's, you should visit my page.
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: When is \n converted to \r\n? and why?
@ 1998-10-30  5:08 Earnie Boyd
  1998-10-29 18:15 ` Christopher Faylor
  0 siblings, 1 reply; 10+ messages in thread
From: Earnie Boyd @ 1998-10-30  5:08 UTC (permalink / raw)
  To: Urban Widmark, gnu-win32; +Cc: noer, cgf

---Urban Widmark <urban@svenskatest.se> wrote:
>
> (using cygwin32 19.3 & 19.1?)
> 
> If I create a small example file:
> 
> $ echo a > xx
> $ ls -l xx
> -rw-r--r--   1 544      everyone        3 Oct 28 15:43 xx
> 
> it will contain "a\r\n" since I use the default (non-binary mounts)
> 
> But if I do:
> $ echo a | wc -c
>       2
> 
> I get only 2 chars ... ok, so the translation is done when writing to
> disk. Then something like this will fail:
> 

Actually, the translation is done at the time of read.  The \r is
removed when processing in text mode and the read would return 2 even
though 3 was actully read from disk.

> $ echo a | tr -d '\r' > yy
> $ ls -l yy
> -rw-r--r--   1 544      everyone        3 Oct 28 15:48 yy
> 

Well, another improperly ported utility.  `tr' should open it's input
and output in binary mode; obviously from this example it isn't.

> So how am I supposed to remove the \r from the echo output?  Well, I
know
> non-cygwin ways to remove the \r, the issue is if this is a tr bug, a
> cygwin conversion bug or ...
> 
> 
> It's also strange that writing to a pipe is different from writing to
> disk, that seems very non-unix'ish. I think it would be better if
> conversion could be toggled by changing an environment variable, it
should
> not depend on the destination of my output.
> 

Well, you are at the mercy of the filesystem and text mode processing
will prefix a \r to every \n.  This is only a problem if the programs
are not properly ported.

> An environment variable would be better than a registry entry, since
it's
> hard to write "non-conversion" shell scripts that can be run on other
> machines if they depend on a registry entry ... Also some scripts
may need
> the feature turned on, others off.
> 

Actually, I'd be in favor of not having either if that meant getting
properly ported code.  I wonder if we could get this resolved prior to
the b20 release?

==
-                  \\||//
-------------o0O0--Earnie--0O0o--------------
--          earnie_boyd@yahoo.com          --
-- http://www.freeyellow.com/members5/gw32 --
----------------ooo0O--O0ooo-----------------

PS: Newbie's, you should visit my page.
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 10+ messages in thread
* When is \n converted to \r\n? and why?
@ 1998-10-28 11:32 Urban Widmark
  1998-10-30  5:08 ` Larry Hall
  0 siblings, 1 reply; 10+ messages in thread
From: Urban Widmark @ 1998-10-28 11:32 UTC (permalink / raw)
  To: gnu-win32

(using cygwin32 19.3 & 19.1?)

If I create a small example file:

$ echo a > xx
$ ls -l xx
-rw-r--r--   1 544      everyone        3 Oct 28 15:43 xx

it will contain "a\r\n" since I use the default (non-binary mounts)

But if I do:
$ echo a | wc -c
      2

I get only 2 chars ... ok, so the translation is done when writing to
disk. Then something like this will fail:

$ echo a | tr -d '\r' > yy
$ ls -l yy
-rw-r--r--   1 544      everyone        3 Oct 28 15:48 yy

So how am I supposed to remove the \r from the echo output?  Well, I know
non-cygwin ways to remove the \r, the issue is if this is a tr bug, a
cygwin conversion bug or ...


It's also strange that writing to a pipe is different from writing to
disk, that seems very non-unix'ish. I think it would be better if
conversion could be toggled by changing an environment variable, it should
not depend on the destination of my output.

An environment variable would be better than a registry entry, since it's
hard to write "non-conversion" shell scripts that can be run on other
machines if they depend on a registry entry ... Also some scripts may need
the feature turned on, others off.

/Urban, who knows next to nothing about windows .dlls

---
Urban Widmark                           urban@svenskatest.se
Svenska Test AB                         +46 90 71 71 23

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1998-11-02  5:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <Pine.GSO.3.96.981028153437.966D-100000.cygnus.gnu-win32@fungus>
1998-10-30  9:06 ` When is \n converted to \r\n? and why? Christopher G. Faylor
     [not found] <19981030020029.5367.rocketmail.cygnus.gnu-win32@send102.yahoomail.com>
1998-10-31 18:06 ` Christopher G. Faylor
1998-10-31 10:50 Earnie Boyd
1998-11-02  5:50 ` Urban Widmark
  -- strict thread matches above, loose matches on Subject: below --
1998-10-31  8:05 Earnie Boyd
1998-10-30  5:08 Earnie Boyd
1998-10-29 18:15 ` Christopher Faylor
1998-10-28 11:32 Urban Widmark
1998-10-30  5:08 ` Larry Hall
1998-10-30  5:08   ` Urban Widmark

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).