Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 4423fd66e4f39f97a90a06963ab08d9c7d821118
Ticket: 414778ffffffffffffffffffffffffffffffffff
Auto wrap Tcl_UtfToExternal
User & Date: vcc on 2001-04-09 01:43:18
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    I wrote some packages use C/C++ , I must use 
    Tcl_UtfToExternal convert in
    args form UTF-8 to cp936 to made process chinese word 
    in erveywhere. so I
    hacked Tcl source code to auto do it.
    It just simple, I add a flag needUtfToExternal to 
    struct Command and
    Tcl_Interp,Interp, and add a command 
    needutftoexternal. if a C write package
    need auto convert UTF to External just set the flag. 
    like:
    needutftoexternal 1
    load mypackage.dll
    ......
    
    
    --- ./tcl.h.orig Sun Apr  8 12:49:44 2001
    +++ ./tcl.h Sun Apr  8 12:54:18 2001
    @@ -369,6 +369,7 @@
         int errorLine;              /* When TCL_ERROR is 
    returned, this gives
                                      * the line number 
    within the command where
                                      * the error occurred 
    (1 if first line). */
    +    int needUtfToExternal; /* Zero means the the C 
    Command  not need
    UtfToExternal, other values need.*/
     } Tcl_Interp;
    
     typedef struct Tcl_AsyncHandler_ *Tcl_AsyncHandler;
    --- ./tclBasic.c.orig Sun Apr  8 12:49:45 2001
    +++ ./tclBasic.c Sun Apr  8 12:59:52 2001
    @@ -449,6 +449,7 @@
          cmdPtr->deleteData = (ClientData) NULL;
          cmdPtr->deleted = 0;
          cmdPtr->importRefPtr = NULL;
    +     cmdPtr->needUtfToExternal = 0;
          Tcl_SetHashValue(hPtr, cmdPtr);
      }
         }
    @@ -1524,6 +1525,9 @@
          */
    
         TclResetShadowedCmdRefs(interp, cmdPtr);
    +
    +    cmdPtr->needUtfToExternal = interp-
    >needUtfToExternal;
    +
         return (Tcl_Command) cmdPtr;
     }
    
    @@ -1685,6 +1689,9 @@
          */
    
         TclResetShadowedCmdRefs(interp, cmdPtr);
    +
    +    cmdPtr->needUtfToExternal = interp-
    >needUtfToExternal;
    +
         return (Tcl_Command) cmdPtr;
     }
    
    --- ./tclExecute.c.orig Sun Apr  8 12:49:46 2001
    +++ ./tclExecute.c Sun Apr  8 15:35:17 2001
    @@ -842,8 +842,40 @@
    
       iPtr->cmdCount++;
       DECACHE_STACK_INFO();
    +
    +  if (cmdPtr->needUtfToExternal) {
    +   for (i = 0; i < objc; i++) {
    +    if (objv[i]->typePtr == NULL && objv[i]->length>0 
    && objv[i]->bytes) {
    +     Tcl_DString ds;
    +     int len;
    +     Tcl_UtfToExternalDString(NULL,objv[i]->bytes,objv
    [i]->length,&ds);
    +     len = Tcl_DStringLength(&ds);
    +     memcpy(objv[i]->bytes,Tcl_DStringValue(&ds),len);
    +     objv[i]->bytes[len] = 0;
    +     objv[i]->length = len;
    +     Tcl_DStringFree(&ds);
    +    }
    +   }
    +  }
    +
       result = (*cmdPtr->objProc)(cmdPtr->objClientData, 
    interp,
              objc, objv);
    +
    +  if (cmdPtr->needUtfToExternal) {
    +   for (i = 0; i < objc; i++) {
    +    if (objv[i]->typePtr == NULL && objv[i]->length>0 
    && objv[i]->bytes) {
    +     Tcl_DString ds;
    +     int len;
    +     Tcl_ExternalToUtfDString(NULL,objv[i]->bytes,objv
    [i]->length,&ds);
    +     len = Tcl_DStringLength(&ds);
    +     memcpy(objv[i]->bytes,Tcl_DStringValue(&ds),len);
    +     objv[i]->bytes[len] = 0;
    +     objv[i]->length = len;
    +     Tcl_DStringFree(&ds);
    +    }
    +   }
    +  }
    +
       if (Tcl_AsyncReady()) {
           result = Tcl_AsyncInvoke(interp, result);
       }
    --- ./tclInt.h.orig Sun Apr  8 12:49:47 2001
    +++ ./tclInt.h Sun Apr  8 12:57:36 2001
    @@ -1031,6 +1031,7 @@
          * command. The list is used to remove all
          * those imported commands when deleting
          * this "real" command. */
    + int needUtfToExternal; /* 1 : args need 
    Tcl_UtfToExternal */
     } Command;
    
     /*
    @@ -1106,6 +1107,9 @@
         int errorLine;  /* When TCL_ERROR is returned, 
    this gives
          * the line number in the command where the
          * error occurred (1 means first line). */
    +
    + int needUtfToExternal;
    +
         struct TclStubs *stubTable;
         /* Pointer to the exported Tcl stub table.
          * On previous versions of Tcl this is a
    --- ./tclInterp.c.orig Sun Apr  8 12:49:47 2001
    +++ ./tclInterp.c Sun Apr  8 14:27:29 2001
    @@ -191,6 +191,30 @@
     static void  SlaveObjCmdDeleteProc _ANSI_ARGS_((
            ClientData clientData));
    
    +int Tcl_InterpNeedUtfToExternalCmd _ANSI_ARGS_
    ((ClientData clientData,
    +      Tcl_Interp *interp, int argc, Tcl_Obj *CONST 
    objv[]));
    +
    +
    +int
    +Tcl_InterpNeedUtfToExternalCmd(clientData, interp, 
    objc, objv)
    +    ClientData clientData;  /* Unused. */
    +    Tcl_Interp *interp;   /* Current interpreter. */
    +    int objc;        /* Number of arguments. */
    +    Tcl_Obj *CONST objv[];  /* Argument objects. */
    +{
    +
    +    Tcl_Obj* result = Tcl_GetObjResult(interp);
    +    Tcl_SetIntObj(result,interp->needUtfToExternal);
    +
    +    if (objc >= 2) {
    +        int need ;
    +        Tcl_GetIntFromObj(interp,objv[1],&need);
    +        interp->needUtfToExternal = need;
    +    }
    +
    +    return TCL_OK;
    +}
    +
     /*
    
    *------------------------------------------------------
    ---------------------
      *
    @@ -231,13 +255,17 @@
         slavePtr->slaveInterp = interp;
         slavePtr->interpCmd  = NULL;
         Tcl_InitHashTable(&slavePtr->aliasTable, 
    TCL_STRING_KEYS);
    -
    +
    +    interp->needUtfToExternal = 0;
    +
         Tcl_CreateObjCommand(interp, "interp", 
    Tcl_InterpObjCmd, NULL, NULL);
    +    Tcl_CreateObjCommand(interp, "needutftoexternal",
    Tcl_InterpNeedUtfToExternalCmd, NULL, NULL);
    
         Tcl_CallWhenDeleted(interp, InterpInfoDeleteProc, 
    NULL);
         return TCL_OK;
     }
    
    +
     /*
    
    *------------------------------------------------------
    ---------------------
      *
    --- ./tcl.h.orig Sun Apr  8 12:49:44 2001
    +++ ./tcl.h Sun Apr  8 12:54:18 2001
    @@ -369,6 +369,7 @@
         int errorLine;              /* When TCL_ERROR is 
    returned, this gives
                                      * the line number 
    within the command where
                                      * the error occurred 
    (1 if first line). */
    +    int needUtfToExternal; /* Zero means the the C 
    Command  not need
    UtfToExternal, other values need.*/
     } Tcl_Interp;
    
     typedef struct Tcl_AsyncHandler_ *Tcl_AsyncHandler;
    --- ./tclBasic.c.orig Sun Apr  8 12:49:45 2001
    +++ ./tclBasic.c Sun Apr  8 12:59:52 2001
    @@ -449,6 +449,7 @@
          cmdPtr->deleteData = (ClientData) NULL;
          cmdPtr->deleted = 0;
          cmdPtr->importRefPtr = NULL;
    +     cmdPtr->needUtfToExternal = 0;
          Tcl_SetHashValue(hPtr, cmdPtr);
      }
         }
    @@ -1524,6 +1525,9 @@
          */
    
         TclResetShadowedCmdRefs(interp, cmdPtr);
    +
    +    cmdPtr->needUtfToExternal = interp-
    >needUtfToExternal;
    +
         return (Tcl_Command) cmdPtr;
     }
    
    @@ -1685,6 +1689,9 @@
          */
    
         TclResetShadowedCmdRefs(interp, cmdPtr);
    +
    +    cmdPtr->needUtfToExternal = interp-
    >needUtfToExternal;
    +
         return (Tcl_Command) cmdPtr;
     }
    
    --- ./tclExecute.c.orig Sun Apr  8 12:49:46 2001
    +++ ./tclExecute.c Sun Apr  8 15:35:17 2001
    @@ -842,8 +842,40 @@
    
       iPtr->cmdCount++;
       DECACHE_STACK_INFO();
    +
    +  if (cmdPtr->needUtfToExternal) {
    +   for (i = 0; i < objc; i++) {
    +    if (objv[i]->typePtr == NULL && objv[i]->length>0 
    && objv[i]->bytes) {
    +     Tcl_DString ds;
    +     int len;
    +     Tcl_UtfToExternalDString(NULL,objv[i]->bytes,objv
    [i]->length,&ds);
    +     len = Tcl_DStringLength(&ds);
    +     memcpy(objv[i]->bytes,Tcl_DStringValue(&ds),len);
    +     objv[i]->bytes[len] = 0;
    +     objv[i]->length = len;
    +     Tcl_DStringFree(&ds);
    +    }
    +   }
    +  }
    +
       result = (*cmdPtr->objProc)(cmdPtr->objClientData, 
    interp,
              objc, objv);
    +
    +  if (cmdPtr->needUtfToExternal) {
    +   for (i = 0; i < objc; i++) {
    +    if (objv[i]->typePtr == NULL && objv[i]->length>0 
    && objv[i]->bytes) {
    +     Tcl_DString ds;
    +     int len;
    +     Tcl_ExternalToUtfDString(NULL,objv[i]->bytes,objv
    [i]->length,&ds);
    +     len = Tcl_DStringLength(&ds);
    +     memcpy(objv[i]->bytes,Tcl_DStringValue(&ds),len);
    +     objv[i]->bytes[len] = 0;
    +     objv[i]->length = len;
    +     Tcl_DStringFree(&ds);
    +    }
    +   }
    +  }
    +
       if (Tcl_AsyncReady()) {
           result = Tcl_AsyncInvoke(interp, result);
       }
    --- ./tclInt.h.orig Sun Apr  8 12:49:47 2001
    +++ ./tclInt.h Sun Apr  8 12:57:36 2001
    @@ -1031,6 +1031,7 @@
          * command. The list is used to remove all
          * those imported commands when deleting
          * this "real" command. */
    + int needUtfToExternal; /* 1 : args need 
    Tcl_UtfToExternal */
     } Command;
    
     /*
    @@ -1106,6 +1107,9 @@
         int errorLine;  /* When TCL_ERROR is returned, 
    this gives
          * the line number in the command where the
          * error occurred (1 means first line). */
    +
    + int needUtfToExternal;
    +
         struct TclStubs *stubTable;
         /* Pointer to the exported Tcl stub table.
          * On previous versions of Tcl this is a
    --- ./tclInterp.c.orig Sun Apr  8 12:49:47 2001
    +++ ./tclInterp.c Sun Apr  8 14:27:29 2001
    @@ -191,6 +191,30 @@
     static void  SlaveObjCmdDeleteProc _ANSI_ARGS_((
            ClientData clientData));
    
    +int Tcl_InterpNeedUtfToExternalCmd _ANSI_ARGS_
    ((ClientData clientData,
    +      Tcl_Interp *interp, int argc, Tcl_Obj *CONST 
    objv[]));
    +
    +
    +int
    +Tcl_InterpNeedUtfToExternalCmd(clientData, interp, 
    objc, objv)
    +    ClientData clientData;  /* Unused. */
    +    Tcl_Interp *interp;   /* Current interpreter. */
    +    int objc;        /* Number of arguments. */
    +    Tcl_Obj *CONST objv[];  /* Argument objects. */
    +{
    +
    +    Tcl_Obj* result = Tcl_GetObjResult(interp);
    +    Tcl_SetIntObj(result,interp->needUtfToExternal);
    +
    +    if (objc >= 2) {
    +        int need ;
    +        Tcl_GetIntFromObj(interp,objv[1],&need);
    +        interp->needUtfToExternal = need;
    +    }
    +
    +    return TCL_OK;
    +}
    +
     /*
    
    *------------------------------------------------------
    ---------------------
      *
    @@ -231,13 +255,17 @@
         slavePtr->slaveInterp = interp;
         slavePtr->interpCmd  = NULL;
         Tcl_InitHashTable(&slavePtr->aliasTable, 
    TCL_STRING_KEYS);
    -
    +
    +    interp->needUtfToExternal = 0;
    +
         Tcl_CreateObjCommand(interp, "interp", 
    Tcl_InterpObjCmd, NULL, NULL);
    +    Tcl_CreateObjCommand(interp, "needutftoexternal",
    Tcl_InterpNeedUtfToExternalCmd, NULL, NULL);
    
         Tcl_CallWhenDeleted(interp, InterpInfoDeleteProc, 
    NULL);
         return TCL_OK;
     }
    
    +
     /*
    
    *------------------------------------------------------
    ---------------------
      *
    --- tcl.h.orig Sun Apr  8 12:49:44 2001
    +++ tcl.h Sun Apr  8 12:54:18 2001
    @@ -369,6 +369,7 @@
         int errorLine;              /* When TCL_ERROR is 
    returned, this gives
                                      * the line number 
    within the command where
                                      * the error occurred 
    (1 if first line). */
    +    int needUtfToExternal; /* Zero means the the C 
    Command  not need
    UtfToExternal, other values need.*/
     } Tcl_Interp;
    
     typedef struct Tcl_AsyncHandler_ *Tcl_AsyncHandler;
    --- tclBasic.c.orig Sun Apr  8 12:49:45 2001
    +++ tclBasic.c Sun Apr  8 12:59:52 2001
    @@ -449,6 +449,7 @@
          cmdPtr->deleteData = (ClientData) NULL;
          cmdPtr->deleted = 0;
          cmdPtr->importRefPtr = NULL;
    +     cmdPtr->needUtfToExternal = 0;
          Tcl_SetHashValue(hPtr, cmdPtr);
      }
         }
    @@ -1524,6 +1525,9 @@
          */
    
         TclResetShadowedCmdRefs(interp, cmdPtr);
    +
    +    cmdPtr->needUtfToExternal = interp-
    >needUtfToExternal;
    +
         return (Tcl_Command) cmdPtr;
     }
    
    @@ -1685,6 +1689,9 @@
          */
    
         TclResetShadowedCmdRefs(interp, cmdPtr);
    +
    +    cmdPtr->needUtfToExternal = interp-
    >needUtfToExternal;
    +
         return (Tcl_Command) cmdPtr;
     }
    
    --- tclExecute.c.orig Sun Apr  8 12:49:46 2001
    +++ tclExecute.c Sun Apr  8 15:35:17 2001
    @@ -842,8 +842,40 @@
    
       iPtr->cmdCount++;
       DECACHE_STACK_INFO();
    +
    +  if (cmdPtr->needUtfToExternal) {
    +   for (i = 0; i < objc; i++) {
    +    if (objv[i]->typePtr == NULL && objv[i]->length>0 
    && objv[i]->bytes) {
    +     Tcl_DString ds;
    +     int len;
    +     Tcl_UtfToExternalDString(NULL,objv[i]->bytes,objv
    [i]->length,&ds);
    +     len = Tcl_DStringLength(&ds);
    +     memcpy(objv[i]->bytes,Tcl_DStringValue(&ds),len);
    +     objv[i]->bytes[len] = 0;
    +     objv[i]->length = len;
    +     Tcl_DStringFree(&ds);
    +    }
    +   }
    +  }
    +
       result = (*cmdPtr->objProc)(cmdPtr->objClientData, 
    interp,
              objc, objv);
    +
    +  if (cmdPtr->needUtfToExternal) {
    +   for (i = 0; i < objc; i++) {
    +    if (objv[i]->typePtr == NULL && objv[i]->length>0 
    && objv[i]->bytes) {
    +     Tcl_DString ds;
    +     int len;
    +     Tcl_ExternalToUtfDString(NULL,objv[i]->bytes,objv
    [i]->length,&ds);
    +     len = Tcl_DStringLength(&ds);
    +     memcpy(objv[i]->bytes,Tcl_DStringValue(&ds),len);
    +     objv[i]->bytes[len] = 0;
    +     objv[i]->length = len;
    +     Tcl_DStringFree(&ds);
    +    }
    +   }
    +  }
    +
       if (Tcl_AsyncReady()) {
           result = Tcl_AsyncInvoke(interp, result);
       }
    --- tclInt.h.orig Sun Apr  8 12:49:47 2001
    +++ tclInt.h Sun Apr  8 12:57:36 2001
    @@ -1031,6 +1031,7 @@
          * command. The list is used to remove all
          * those imported commands when deleting
          * this "real" command. */
    + int needUtfToExternal; /* 1 : args need 
    Tcl_UtfToExternal */
     } Command;
    
     /*
    @@ -1106,6 +1107,9 @@
         int errorLine;  /* When TCL_ERROR is returned, 
    this gives
          * the line number in the command where the
          * error occurred (1 means first line). */
    +
    + int needUtfToExternal;
    +
         struct TclStubs *stubTable;
         /* Pointer to the exported Tcl stub table.
          * On previous versions of Tcl this is a
    --- tclInterp.c.orig Sun Apr  8 12:49:47 2001
    +++ tclInterp.c Sun Apr  8 14:27:29 2001
    @@ -191,6 +191,30 @@
     static void  SlaveObjCmdDeleteProc _ANSI_ARGS_((
            ClientData clientData));
    
    +int Tcl_InterpNeedUtfToExternalCmd _ANSI_ARGS_
    ((ClientData clientData,
    +      Tcl_Interp *interp, int argc, Tcl_Obj *CONST 
    objv[]));
    +
    +
    +int
    +Tcl_InterpNeedUtfToExternalCmd(clientData, interp, 
    objc, objv)
    +    ClientData clientData;  /* Unused. */
    +    Tcl_Interp *interp;   /* Current interpreter. */
    +    int objc;        /* Number of arguments. */
    +    Tcl_Obj *CONST objv[];  /* Argument objects. */
    +{
    +
    +    Tcl_Obj* result = Tcl_GetObjResult(interp);
    +    Tcl_SetIntObj(result,interp->needUtfToExternal);
    +
    +    if (objc >= 2) {
    +        int need ;
    +        Tcl_GetIntFromObj(interp,objv[1],&need);
    +        interp->needUtfToExternal = need;
    +    }
    +
    +    return TCL_OK;
    +}
    +
     /*
    
    *------------------------------------------------------
    ---------------------
      *
    @@ -231,13 +255,17 @@
         slavePtr->slaveInterp = interp;
         slavePtr->interpCmd  = NULL;
         Tcl_InitHashTable(&slavePtr->aliasTable, 
    TCL_STRING_KEYS);
    -
    +
    +    interp->needUtfToExternal = 0;
    +
         Tcl_CreateObjCommand(interp, "interp", 
    Tcl_InterpObjCmd, NULL, NULL);
    +    Tcl_CreateObjCommand(interp, "needutftoexternal",
    Tcl_InterpNeedUtfToExternalCmd, NULL, NULL);
    
         Tcl_CallWhenDeleted(interp, InterpInfoDeleteProc, 
    NULL);
         return TCL_OK;
     }
    
    +
     /*
    
    *------------------------------------------------------
    ---------------------
      *
    
    
    
    
    
    
    
    
    
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "vcc"
  9. subsystem changed to: "None"
  10. title changed to: "Auto wrap Tcl_UtfToExternal"
  11. type changed to: "Patch"