Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

RE: zsh and line breaks



On Fri, 2 Apr 2004, Dave Korn wrote:

Hi Dave,

> > -----Original Message-----
> > From: cygwin-owner On Behalf Of Peter A. Castro
> > Sent: 01 April 2004 22:21
>
> >   In system.h I've added a #define in the #ifdef
> > __CYGWIN__ section of:
> > #define ORO_TEXT | O_TEXT
> > And for the #else case:
> > #define ORO_TEXT
> >
> > Then in code which needs it I have modified it to look like this:
> >
> > if ((fd = open(name, O_RDONLY ORO_TEXT)) < 0) {
> >
> > It's really just utilizing the macro ability of the compiler,
> > and it's a
> > style judgement call.  I don't have a problem with it, obviously, but
> > others might look at it and wonder how it could possible
> > compile if they
> > didn't look in system.h first.  If you think that might present
> > confusion, then I'll change it to be explicitly "| OR_TEXT" and have
> > #define O_TEXT to be 0 if not defined at all.
> >
> > Any thoughts on this?
>
>   It's pretty reasonable but as you say could be confusing.  Here's another
> approach that might seem nicer because it's kind of function-like:
>
> #ifdef __CYGWIN__
> #define MAYBE_ADD_O_TEXT_FLAG(x) (O_TEXT | (x))
> #else
> #define MAYBE_ADD_O_TEXT_FLAG(x) (x)
> #endif
>
> Then say
>
> if ((fd = open(name, MAYBE_ADD_O_TEXT_FLAG(O_RDONLY))) < 0) {
>
> You might well want to choose a better name for the function-like macro than
> that, but I think the pattern is slightly clearer.

It's always interesting to see how people solve the same problem using a
different style.  Yes, I'd though of using a wrapper macro, but decided I
didn't want to change mainline code that much.  I'm really looking for
something that's pretty non-intrusive.  Corinna just emailed a possible
solution, which may be the best yet because it works at a lower level and
wouldn't require all of those 43 open calls to be changed!

> > The primary problem is with running scripts with CR/LFs.
> > That gets fixed
> > with adding O_TEXT everywhere.  A secondary problem is with redirected
> > input and/or output which is processed by the shell.
> >
> > I've been reviewing this problem and I think maybe I've been
> > attacking it
> > incorrectly.  I had though that adding O_TEXT everywhere
> > would solve this
> > problem.  However, the environment is complicating things :)
> >
> > Here's the deal:
>
> >  So where the file located in the filesystem
> > determines
> > the default handling of translation when opened as a text file.
> > This is for normal unix style coding of opens without any O_TEXT or
> > O_BINARY cruft.
> >
> > Now, adding an explicit O_TEXT or O_BINARY forces one mode or
> > the other,
> > ignoring the filesystem mount attributes.  The problem is, I
> > don't want
> > to force the mode,
> >
> > Thanks for listening.  Any suggestions are welcome.
>
>   Doesn't the POSIX standard specify something about shells should open
> stdin, stdout and stderr in textmode?  IOW, aren't you obliged to force the
> mode?

The posix standard specifies a textmode should be used, but says nothing
about what really constitues a "textmode".  Textmode means adding line
termination according to the platform definitions.  However, in the case
of Cygwin, I believe we are supposed to honor the mode of the filesystem
as much as possible, which means sometimes line termination has CRs and
sometimes it doesn't.  One thing is for sure: reading script files
directly must remove CRs.  Everthing else is up for discussion :)
I'm going to experiment with Corinna's idea and see what happens first.
If that doesn't work, I'll have to continue my analysis of what the code
does with those opened files.

>     cheers,
>       DaveK

-- 
Peter A. Castro <doctor@xxxxxxxxxxxx> or <Peter.Castro@xxxxxxxxxx>
	"Cats are just autistic Dogs" -- Dr. Tony Attwood



Messages sorted by: Reverse Date, Date, Thread, Author