From 87f59e02aed624d2fa58b0d67e3d6ab8e8a0af08 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Wed, 22 Jun 2011 12:11:40 +1000 Subject: Fix script line numbering for multi-line commands The line number stored with each line of the script should be the line number of the first token, not the last token. Signed-off-by: Steve Bennett --- jim.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'jim.c') diff --git a/jim.c b/jim.c index 3ef60be..2a5fb4b 100644 --- a/jim.c +++ b/jim.c @@ -2932,9 +2932,15 @@ static Jim_Obj *JimNewScriptLineObj(Jim_Interp *interp, int argc, int line) { Jim_Obj *objPtr; - objPtr = Jim_NewObj(interp); - objPtr->typePtr = &scriptLineObjType; +#ifdef DEBUG_SHOW_SCRIPT + char buf[100]; + snprintf(buf, sizeof(buf), "line=%d, argc=%d", line, argc); + objPtr = Jim_NewStringObj(interp, buf, -1); +#else + objPtr = Jim_NewEmptyStringObj(interp); objPtr->bytes = JimEmptyStringRep; +#endif + objPtr->typePtr = &scriptLineObjType; objPtr->internalRep.scriptLineValue.argc = argc; objPtr->internalRep.scriptLineValue.line = line; @@ -3275,8 +3281,11 @@ static void ScriptObjAddTokens(Jim_Interp *interp, struct ScriptObj *script, } } + if (lineargs == 0) { + /* First real token on the line, so record the line number */ + linenr = tokenlist->list[i].line; + } lineargs++; - linenr = tokenlist->list[i].line; /* Add each non-separator word token to the line */ while (wordtokens--) { @@ -3303,7 +3312,7 @@ static void ScriptObjAddTokens(Jim_Interp *interp, struct ScriptObj *script, assert(script->len < count); #ifdef DEBUG_SHOW_SCRIPT - printf("==== Script ====\n"); + printf("==== Script (%s) ====\n", script->fileName); for (i = 0; i < script->len; i++) { const ScriptToken *t = &script->token[i]; printf("[%2d] %s %s\n", i, jim_tt_name(t->type), Jim_String(t->objPtr)); -- cgit v1.1