diff options
author | dgp <dgp@noemail.net> | 2005-09-30 19:28:54 (GMT) |
---|---|---|
committer | dgp <dgp@noemail.net> | 2005-09-30 19:28:54 (GMT) |
commit | 136d83a9f98e0436826415d083a7da8986b43eef (patch) | |
tree | fcd0953397a1c06c6d26d2e0a5a067b33a7591c7 | |
parent | 57d18692b6ce62519a57f8780ccc9e67460d779e (diff) | |
download | tcl-136d83a9f98e0436826415d083a7da8986b43eef.zip tcl-136d83a9f98e0436826415d083a7da8986b43eef.tar.gz tcl-136d83a9f98e0436826415d083a7da8986b43eef.tar.bz2 |
* generic/tclMain.c: Separate encoding conversion of command line
arguments from list formatting. [Bug 1306162].
FossilOrigin-Name: 365b1366e3c51638342233e2a5327eaad6ff9b06
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | generic/tclMain.c | 49 |
2 files changed, 28 insertions, 26 deletions
@@ -1,3 +1,8 @@ +2005-09-30 Don Porter <dgp@users.sourceforge.net> + + * generic/tclMain.c: Separate encoding conversion of command line + arguments from list formatting. [Bug 1306162]. + 2005-09-27 Donal K. Fellows <donal.k.fellows@man.ac.uk> * generic/tclBinary.c (FormatNumber): Factorize out copying of diff --git a/generic/tclMain.c b/generic/tclMain.c index 1380ce8..1b73be6 100644 --- a/generic/tclMain.c +++ b/generic/tclMain.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclMain.c,v 1.20 2002/05/29 22:59:33 dgp Exp $ + * RCS: @(#) $Id: tclMain.c,v 1.20.2.1 2005/09/30 19:28:55 dgp Exp $ */ #include "tcl.h" @@ -204,15 +204,12 @@ Tcl_Main(argc, argv, appInitProc) * initialization but before starting to * execute commands. */ { - Tcl_Obj *resultPtr; - Tcl_Obj *commandPtr = NULL; - char buffer[TCL_INTEGER_SPACE + 5], *args; + Tcl_Obj *resultPtr, *argvPtr, *commandPtr = NULL; PromptType prompt = PROMPT_START; - int code, length, tty; - int exitCode = 0; + int code, length, tty, exitCode = 0; Tcl_Channel inChannel, outChannel, errChannel; Tcl_Interp *interp; - Tcl_DString argString; + Tcl_DString appName; Tcl_FindExecutable(argv[0]); @@ -233,28 +230,28 @@ Tcl_Main(argc, argv, appInitProc) } } - /* - * The CONST casting is safe, and better we do it here than force - * all callers of Tcl_Main to do it. (Those callers are likely - * in a main() that can't easily change its signature.) - */ - - args = Tcl_Merge(argc-1, (CONST char **)argv+1); - Tcl_ExternalToUtfDString(NULL, args, -1, &argString); - Tcl_SetVar(interp, "argv", Tcl_DStringValue(&argString), TCL_GLOBAL_ONLY); - Tcl_DStringFree(&argString); - ckfree(args); - if (TclGetStartupScriptPath() == NULL) { - Tcl_ExternalToUtfDString(NULL, argv[0], -1, &argString); + Tcl_ExternalToUtfDString(NULL, argv[0], -1, &appName); } else { TclSetStartupScriptFileName(Tcl_ExternalToUtfDString(NULL, - TclGetStartupScriptFileName(), -1, &argString)); + TclGetStartupScriptFileName(), -1, &appName)); } - - TclFormatInt(buffer, (long) argc-1); - Tcl_SetVar(interp, "argc", buffer, TCL_GLOBAL_ONLY); - Tcl_SetVar(interp, "argv0", Tcl_DStringValue(&argString), TCL_GLOBAL_ONLY); + Tcl_SetVar(interp, "argv0", Tcl_DStringValue(&appName), TCL_GLOBAL_ONLY); + Tcl_DStringFree(&appName); + argc--; + argv++; + + Tcl_SetVar2Ex(interp, "argc", NULL, Tcl_NewIntObj(argc), TCL_GLOBAL_ONLY); + + argvPtr = Tcl_NewListObj(0, NULL); + while (argc--) { + Tcl_DString ds; + Tcl_ExternalToUtfDString(NULL, *argv++, -1, &ds); + Tcl_ListObjAppendElement(NULL, argvPtr, Tcl_NewStringObj( + Tcl_DStringValue(&ds), Tcl_DStringLength(&ds))); + Tcl_DStringFree(&ds); + } + Tcl_SetVar2Ex(interp, "argv", NULL, argvPtr, TCL_GLOBAL_ONLY); /* * Set the "tcl_interactive" variable. @@ -308,7 +305,6 @@ Tcl_Main(argc, argv, appInitProc) } goto done; } - Tcl_DStringFree(&argString); /* * We're running interactively. Source a user-specific startup @@ -496,6 +492,7 @@ Tcl_Main(argc, argv, appInitProc) */ if (!Tcl_InterpDeleted(interp)) { + char buffer[TCL_INTEGER_SPACE + 5]; sprintf(buffer, "exit %d", exitCode); Tcl_Eval(interp, buffer); |