delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/09/13/17:48:38

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Blake <ebb9 AT byu DOT net>
Subject: Re: =?utf-8?b?YmFzaC0zLjEtNxskQiEhGyhCQlVH?=
Date: Wed, 13 Sep 2006 21:48:07 +0000 (UTC)
Lines: 29
Message-ID: <loom.20060913T234039-426@post.gmane.org>
References: <091320060438 DOT 11140 DOT 45078B490008FD8600002B8422007610640A050E040D0C079D0A AT comcast DOT net> <20060913052510 DOT GB1256 AT trixie DOT casa DOT cgf DOT cx> <loom DOT 20060913T160909-692 AT post DOT gmane DOT org> <ee9oa9$sj$1 AT sea DOT gmane DOT org> <ee9q53$74g$1 AT sea DOT gmane DOT org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

mwoehlke <mwoehlke <at> tibco.com> writes:

> > Would it be possible to do this dynamically (instead of keying off of 
> > mounts, etc.): if the first line of the file read by bash has a \r\n, 
> > use text-mode (1-char-at-a-time) semantics, else use binary semantics 
> > (lseek)?
> 
> I hate to say this, but... if bash goes this route, could it be a shopt? 
> I would rather know that my scripts are broken (DOS-format).
> 

Thanks for the ideas; here's what I'll try.  Bash does indeed already scan the 
first line (I'm not sure if it is line or first 80 characters or what it is 
exactly, but I do know it scans) to see if it detects any NUL bytes, at which 
point it complains the file is binary and not a script.  So I can probably hack 
that scan to also look for \r.  So first I will open the file according to the 
mount point rules.  If the file is text mode, perform the scan in binary mode, 
and if any \r is seen, revert to text mode and no lseeks.  If the scan in 
binary mode succeeds, then leave the file in binary mode, assuming that the 
file is unix format even though it is on a text mount, and that lseeks will 
work.  If the file starts life binary mode (ie. was on a binary mount), skip 
the check for \r in the scan (under the assumption that on a binary mount, \r 
is intentional and not a line ending to be collapsed), and use lseeks.  No 
guarantees on whether this will pan out, or be bigger than I thought, but 
hopefully you will see a bash 3.1-8 with these semantics soon.

-- 
Eric Blake



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019