Fwd: [Unison-hackers] Re: Bug in / patch for Unison 2.12.0's Makefile.OCaml

Benjamin Pierce bcpierce at cis.upenn.edu
Tue Jun 21 15:04:25 EDT 2005



Begin forwarded message:

> From: Nick Montfort <nickm at seas.upenn.edu>
> Date: June 21, 2005 11:27:59 AM EDT
> To: Benjamin Pierce <bcpierce at cis.upenn.edu>
> Cc: Unison hackers <unison-hackers at lists.seas.upenn.edu>
> Subject: Re: [Unison-hackers] Re: Bug in / patch for Unison 2.12.0's 
> Makefile.OCaml
> Reply-To: nickm at nickm.com
>
>
> In that case you might be looking for:
>
> tr -d '\015'
>
> To replace the final sed statement, if you do still want to get rid of 
> the
> literal ^M.
>
> -Nick Montfort  <mail> nickm at nickm.com  <web> http://nickm.com
>
> On Tue, 21 Jun 2005, Benjamin Pierce wrote:
>
>> OK, I'm backing out Nick's proposed change.   Perhaps the discussion
>> will converge on something better...
>>
>>     - B
>>
>>
>> On Jun 21, 2005, at 12:17 AM, Zvezdan Petkovic wrote:
>>
>>> On Mon, Jun 20, 2005 at 10:46:14PM -0400, Benjamin Pierce wrote:
>>>> Thanks for the suggestion, Nick.  I've made this change in the 
>>>> source.
>>>> (If someone can try it out on Windows, that would be great.)
>>>
>>> You might want to retract a part of it. :-)
>>>
>>>>>
>>>>> The literal control-M can be represented by "\r".
>>>>>
>>>
>>> WRONG!
>>> According to POSIX sed uses _basic_ regular expressions.
>>> OTOH, awk and egrep use _extended_ REs.
>>>
>>>>> This seems to work for me on Ubuntu 5.04 and Solaris as well as OS 
>>>>> X
>>>>> 10.4:
>>>
>>> Are you sure about Solaris?
>>>
>>>>>
>>>>> OCAMLLIBDIR=$(shell ocamlc -v | sed -n '$p' | sed -e 's/^Standard
>>>>> library directory: //' | sed -e 's/\\/\//g' | sed -e 's/\r//g')
>>>
>>> This last part doesn't work in most POSIXly correct sed
>>> implementations.
>>> I just tested it on OpenBSD, HP-UX, _and_ Solaris.
>>>
>>> The file is:
>>> aaa
>>> a^Mb
>>> bbb
>>>
>>> Now,
>>> $ cat t
>>> aaa
>>> b
>>> bbb
>>>
>>> You can't see a in the second line because ^M returns to the 
>>> beginning
>>> of the line and prints b over it.  Lets test how sed works:
>>>
>>> $ cat t | sed 's/\r//g'
>>> aaa
>>> b
>>> bbb
>>>
>>> No change when I redirect the output into the file.
>>> The ^M is still there.
>>>
>>> Now, using Ctrl-V Ctrl-M to type ^M I get.
>>>
>>> $ cat t | sed 's/^M//g'
>>> aaa
>>> ab
>>> bbb
>>>
>>> Now it works.
>>> And that is the only way it will work on OpenBSD, HP-UX _and_ 
>>> Solaris.
>>>
>>> Here's a fingerprint of all machines I ran it on without success when
>>> \r
>>> is used.
>>>
>>> $ uname -rs
>>> OpenBSD 3.7
>>>
>>> $ uname -rs
>>> HP-UX B.11.11
>>>
>>> $ uname -rs
>>> SunOS 5.9
>>>
>>> The only machine where it succeeded for me is:
>>>
>>> $ uname -rs
>>> Linux 2.6.5-7.155.29-smp
>>>
>>>>>
>>>>> I haven't tested it on Windows.
>>>>>
>>>
>>> Considering that Microsoft Services for UNIX return
>>>
>>> 	OpenBSD
>>>
>>> when you type
>>>
>>> 	string /usr/bin/* | grep BSD
>>>
>>> and it seems some very old rip-off version, I'll bet it will work the
>>> same on Windows on my office machine.
>>> Now, Cygwin could be a different beast being based on Linux.
>>>
>>> The bottom line is that \r in sed is _not_ portable.
>>> Keep ^M there.
>>> There's a good reason it was there for so long time.
>>>
>>> Welcome to the friendly world of UNIX portability.
>>> :-)
>>>
>>> 	Zvezdan Petkovic
>>> _______________________________________________
>>> Unison-hackers mailing list
>>> Unison-hackers at lists.seas.upenn.edu
>>> http://lists.seas.upenn.edu/mailman/listinfo/unison-hackers
>>



More information about the Unison-hackers mailing list