Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-04-16
23:22 • Closed ticket [218560ffff]: Objectify the "open" command plus 4 ot... artifact: b2d1d1413b user: dgp
23:21 • Open ticket [218560ffff]. artifact: 71a87727d7 user: dgp
2000-10-26
08:24 • Closed ticket [218560ffff]. artifact: 031b104284 user: welch
01:02 • New ticket [218560ffff]. artifact: 20bc2c78ed user: nobody

Objectify the "open" command

Closed / Fixed218560ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:02:18
OriginalBugID: 1113 RFE
Version: 8.0.4
SubmitDate: '1999-01-26'
LastModified: '1999-02-02'
Severity: SER
Status: Released
Submitter: welch
ChangedBy: stanton
OS: Other
OSVersion: any platform
Machine: NA
FixedDate: '1999-02-02'
FixedInVersion: 8.0.5
ClosedDate: '2000-10-25'


Name:

Jan Nijtmans


DesiredBehavior:

The "open" command in tclIOCmd.c, is implemented as an old-style command,

using argv and argc for the arguments. This requests is about objectifying

the "source" command, such that the arguments become available as Tcl_Obj's.


Patch:

*** generic/tclInt.h.origSun Jan 17 15:37:10 1999

--- generic/tclInt.hSun Jan 17 15:37:46 1999

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

*** 1784,1791 ****

      Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));

  EXTERN intTcl_NamespaceObjCmd _ANSI_ARGS_((ClientData clientData,

      Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));

! EXTERN intTcl_OpenCmd _ANSI_ARGS_((ClientData clientData,

!     Tcl_Interp *interp, int argc, char **argv));

  EXTERN intTcl_PackageCmd _ANSI_ARGS_((ClientData clientData,

      Tcl_Interp *interp, int argc, char **argv));

  EXTERN intTcl_PidObjCmd _ANSI_ARGS_((ClientData clientData,

--- 1784,1791 ----

      Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));

  EXTERN intTcl_NamespaceObjCmd _ANSI_ARGS_((ClientData clientData,

      Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));

! EXTERN intTcl_OpenObjCmd _ANSI_ARGS_((ClientData clientData,

!     Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));

  EXTERN intTcl_PackageCmd _ANSI_ARGS_((ClientData clientData,

      Tcl_Interp *interp, int argc, char **argv));

  EXTERN intTcl_PidObjCmd _ANSI_ARGS_((ClientData clientData,

*** generic/tclBasic.c.origSun Jan 17 15:38:35 1999

--- generic/tclBasic.cSun Jan 17 15:39:28 1999

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

*** 188,194 ****

          (CompileProc *) NULL,1},

      {"glob",Tcl_GlobCmd,(Tcl_ObjCmdProc *) NULL,

          (CompileProc *) NULL,0},

!     {"open",Tcl_OpenCmd,(Tcl_ObjCmdProc *) NULL,

          (CompileProc *) NULL,0},

      {"pid",(Tcl_CmdProc *) NULL,Tcl_PidObjCmd,

          (CompileProc *) NULL,1},

--- 188,194 ----

          (CompileProc *) NULL,1},

      {"glob",Tcl_GlobCmd,(Tcl_ObjCmdProc *) NULL,

          (CompileProc *) NULL,0},

!     {"open",(Tcl_CmdProc *) NULL,Tcl_OpenObjCmd,

          (CompileProc *) NULL,0},

      {"pid",(Tcl_CmdProc *) NULL,Tcl_PidObjCmd,

          (CompileProc *) NULL,1},

*** generic/tclIOCmd.c.origSun Jan 17 15:30:39 1999

--- generic/tclIOCmd.cSun Jan 17 15:30:43 1999

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

*** 965,999 ****


  /* ARGSUSED */

  int

! Tcl_OpenCmd(notUsed, interp, argc, argv)

      ClientData notUsed;/* Not used. */

      Tcl_Interp *interp;/* Current interpreter. */

      int argc;/* Number of arguments. */

!     char **argv;/* Argument strings. */

  {

      int pipeline, prot;

!     char *modeString;

      Tcl_Channel chan;


      if ((argc < 2) || (argc > 4)) {

! Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],

! " fileName ?access? ?permissions?\"", (char *) NULL);

  return TCL_ERROR;

      }

      prot = 0666;

      if (argc == 2) {

  modeString = "r";

      } else {

! modeString = argv[2];

  if (argc == 4) {

!     if (Tcl_GetInt(interp, argv[3], &prot) != TCL_OK) {

  return TCL_ERROR;

      }

  }

      }


      pipeline = 0;

!     if (argv[1][0] == '|') {

  pipeline = 1;

      }


--- 965,999 ----


  /* ARGSUSED */

  int

! Tcl_OpenObjCmd(notUsed, interp, argc, objv)

      ClientData notUsed;/* Not used. */

      Tcl_Interp *interp;/* Current interpreter. */

      int argc;/* Number of arguments. */

!     Tcl_Obj * CONST objv[];/* Argument objects. */

  {

      int pipeline, prot;

!     char *modeString, *arg1;

      Tcl_Channel chan;


      if ((argc < 2) || (argc > 4)) {

! Tcl_WrongNumArgs(interp, 1, objv, "fileName ?access? ?permissions?");

  return TCL_ERROR;

      }

      prot = 0666;

      if (argc == 2) {

  modeString = "r";

      } else {

! modeString = Tcl_GetStringFromObj(objv[2], NULL);

  if (argc == 4) {

!     if (Tcl_GetIntFromObj(interp, objv[3], &prot) != TCL_OK) {

  return TCL_ERROR;

      }

  }

      }


+     arg1 = Tcl_GetStringFromObj(objv[1], NULL);

      pipeline = 0;

!     if (arg1[0] == '|') {

  pipeline = 1;

      }


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

*** 1002,1011 ****

       */


      if (!pipeline) {

!         chan = Tcl_OpenFileChannel(interp, argv[1], modeString, prot);

      } else {

  #ifdef MAC_TCL

! Tcl_AppendResult(interp,

  "command pipelines not supported on Macintosh OS",

  (char *)NULL);

  return TCL_ERROR;

--- 1002,1011 ----

       */


      if (!pipeline) {

!         chan = Tcl_OpenFileChannel(interp, arg1, modeString, prot);

      } else {

  #ifdef MAC_TCL

! Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),

  "command pipelines not supported on Macintosh OS",

  (char *)NULL);

  return TCL_ERROR;

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

*** 1013,1019 ****

  int mode, seekFlag, cmdArgc;

  char **cmdArgv;


!         if (Tcl_SplitList(interp, argv[1]+1, &cmdArgc, &cmdArgv) != TCL_OK) {

              return TCL_ERROR;

          }


--- 1013,1019 ----

  int mode, seekFlag, cmdArgc;

  char **cmdArgv;


!         if (Tcl_SplitList(interp, arg1+1, &cmdArgc, &cmdArgv) != TCL_OK) {

              return TCL_ERROR;

          }


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

*** 1045,1051 ****

          return TCL_ERROR;

      }

      Tcl_RegisterChannel(interp, chan);

!     Tcl_AppendResult(interp, Tcl_GetChannelName(chan), (char *) NULL);

      return TCL_OK;

  }

  

--- 1045,1052 ----

          return TCL_ERROR;

      }

      Tcl_RegisterChannel(interp, chan);

!     Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),

! Tcl_GetChannelName(chan), (char *) NULL);

      return TCL_OK;

  }

  


PatchFiles:

tclInt.h tclBasic.c tclIOCmd.c




This change is crucial for a new extension I am writing, therefore
I request that it will be implemented in Tcl8.0.5, and not delayed
until Tcl8.1. It's difficult to explain in a few words why, but
you'll read it in the announcement.

The patch shows that implementation of this feature is trivial.
welch Closed ticket [218560ffff]. [History diff]2000-10-26 08:24:14
dgp Open ticket [218560ffff]. [History diff]2001-04-16 23:21:50
dgp Closed ticket [218560ffff]. [History diff]2001-04-16 23:22:12
Log in (anonymous is fine) to add a comment.