--- tk/generic/tkMain.c 2016-06-01 12:30:57.989155981 +0200 +++ ../tk/generic/tkMain.c 2016-06-01 12:04:29.077276991 +0200 @@ -192,6 +193,8 @@ Tcl_Channel chan; InteractiveState is; + Tcl_SetVar(interp, "::L", "0", 0); + /* * Ensure that we are getting a compatible version of Tcl. */ @@ -424,6 +427,9 @@ InteractiveState *isPtr = clientData; Tcl_Channel chan = isPtr->input; Tcl_Interp *interp = isPtr->interp; + Tcl_DString dstr, Ldstr; + Tcl_Obj *LangObj; + int isL = 0; count = Tcl_Gets(chan, &isPtr->line); @@ -445,6 +451,26 @@ } isPtr->gotPartial = 0; + /* + * Check for the #lang comments and sub them out for + * meaningful commands. + */ + LangObj = Tcl_GetVar2Ex(interp, "::L", NULL, 0); + Tcl_GetIntFromObj(interp, LangObj, &isL); + Tcl_DStringInit(&dstr); + if (!isL && strlen(cmd) >= 7 && strncasecmp(cmd, "#lang l", 7) == 0) { + cmd = Tcl_DStringAppend(&dstr, "set ::L 1\n", 10); + } else if (isL && strlen(cmd) >= 9 && strncasecmp(cmd, "#lang tcl", 9) == 0) { + cmd = Tcl_DStringAppend(&dstr, "set('::L',0);\n", 14); + } + + if (isL) { + Tcl_DStringInit(&Ldstr); + Tcl_DStringAppend(&Ldstr, "L {", 3); + Tcl_DStringAppend(&Ldstr, cmd, strlen(cmd)-1); + cmd = Tcl_DStringAppend(&Ldstr, "}\n", 2); + } + /* * Disable the stdin channel handler while evaluating the command; * otherwise if the command re-enters the event loop we might process @@ -479,6 +505,12 @@ Prompt(interp, isPtr); } Tcl_ResetResult(interp); + + /* Free dynamic strings */ + Tcl_DStringFree(&dstr); + if (isL) { + Tcl_DStringFree(&Ldstr); + } } /*