Skip to content
Tcl Source Code View Ticket
Login

View Ticket

CTRL/Z does not terminate script on Unix (-eofchar for sourc

Deleted218764ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:05:06
OriginalBugID: 2040 RFE
Version: 8.1
SubmitDate: '1999-05-10'
LastModified: '2000-05-10'
Severity: MED
Status: Released
Submitter: pat
ChangedBy: hobbs
OS: Other
Machine: NA
FixedDate: '2000-05-10'
FixedInVersion: 8.4a1
ClosedDate: '2000-10-25'


Name:

Jean-Claude Wippler



Comments:

The ability to run scripts which contain additional data (even binary

data) after the end of a script file makes it possible to create

"scripted documents" - i.e. scripts which include non-script data, or

even an entire database.  This is very similar to the various "wrap"

tools currently in existence, which are based on the fact that

executables (such as those based on the "ELF" format) also allow

appending uninterpreted data.  For a description of scripted documents,

see http://216.71.55.6/cgi-bin/jcw/ScriptedDoc (this mechanism is

already being used in a number of projects, including the Tcl'ers Wiki).

One of the unique features of scripted documents is that they can be

used to deploy "installation-less" and fully self-contained custom

applications.  Note: it is critical that script reading stops at CTRL/Z,

since subsequent data might contain invalid - or in fact even unparsable

- Tcl code (such as an unmatched right brace).



ObservedBehavior:

On Windows, text file reading stops upon encountering a CTRL/Z (\026)

character.

On Unix, everything else is also read in.



DesiredBehavior:

Consistent behavior across platforms.  The proposed behavior is to read

up to CTRL/Z on Unix as well.  The patch submitted here is a one-line

change to the Tcl core which maintains 100% compatibility (assuming

scripts never *include* a CTRL/Z, which would fail on Windows right now

anyway).



Patch:

*** tests/source.test.orig      Thu Apr 29 03:12:36 1999

--- tests/source.test   Sat May  8 18:13:22 1999

***************

*** 178,183 ****

--- 178,189 ----

      source source.file

      string length $x

  } 5

+ test source-6.2 {source skips everything after Ctrl-Z} {

+     set x {}

+     makeFile [list set x ab\32c] source.file

+     source source.file

+     string length $x

+ } 2

  

  # cleanup

  catch {::tcltest::removeFile source.file}

*** generic/tclIOUtil.c.orig    Thu Apr 29 03:11:44 1999

--- generic/tclIOUtil.c Sat May  8 17:59:49 1999

***************

*** 306,311 ****

--- 306,312 ----

                "\": ", Tcl_PosixError(interp), (char *) NULL);

        goto end;

      }

+     Tcl_SetChannelOption(interp, chan, "-eofchar", "\32");

      if (Tcl_ReadChars(chan, objPtr, -1, 0) < 0) {

          Tcl_Close(interp, chan);

        Tcl_AppendResult(interp, "couldn't read file \"", fileName,



PatchFiles:

source.test

    tclIOUtil.c





        This patch is incorrect. Unix file systems do not use file
        termination characters. The "fconfigure" command can be used
        to set the termination character after the file is open if the
        script needs to emulate Windows behavior.

JC's response:
This leads me to believe that the moderator/editor thought this report
had to do with the general case of opening text files.  This is not the
case - my purpose for submitting this change request may not have been
properly described in the comments: this is about the behavior of Tcl
reading and executing scripts from file (i.e. "source <file>").  The
proposed change takes advantage of an existing platform difference to
introduce a new feature which opens up a whole new way of running Tcl
scripts.  See http://216.71.55.6/cgi-bin/metakit/18.html for details.
There is no way one can use fconfigure in the context of "tclsh <file>".

With all due respect: would it be possible to pass this information on
to whoever reviewed issue 2040 and ask for a re-assessment?  I don't
want to make a nuisance of myself, but the proposed one-line change has
deeper implications (and uses) than my submission might have made clear.

-- Jean-Claude
--
This has been changed to RFE, because that is really what it is
(asking to change the default, functional, as expected behavior
of Unix scripts).
-- 05/25/1999 redman 
I think this would best be implemented with an option to source
like 'source -eofchar \32 ...'.  There isn't time to make this
into 8.3.0, but we'll look at it following.  It would be nice to
go in with a general overhaul of source that also supported
-encoding and -fid.  This would allow users to be certain of
cross-platform compatibility as well as system level compatibility. 
-- 02/08/2000 hobbs
JCW notes that such a feature needs to be as patched above, because
you would need to have support right from:
    tclsh script.tcl
where script.tcl will have ^Z separated code and data sections. 
-- 02/08/2000 hobbs
Patched, doc'ed (Tcl_EvalFile and source) and tested for 8.4a1. 
-- 05/10/2000 hobbs
welch Closed ticket [218764ffff]. [History diff]2000-10-26 08:28:14
dgp Open ticket [218764ffff]. [History diff]2001-04-05 07:46:17
dgp Deleted ticket [218764ffff]. [History diff]2001-04-05 07:48:32
Log in (anonymous is fine) to add a comment.