diff --git a/src/files.c b/src/files.c index 9f5c0310..30e12991 100644 --- a/src/files.c +++ b/src/files.c @@ -163,6 +163,7 @@ int ReadLine(void) LineNo = CLine->LineNo; CLine = CLine->next; FreshLine = 1; + clear_callstack(); if (DebugFlag & DB_ECHO_LINE) OutputLine(ErrFp); return OK; } @@ -263,6 +264,7 @@ static int ReadLineFromFile(int use_pclose) } FreshLine = 1; + clear_callstack(); if (DebugFlag & DB_ECHO_LINE) OutputLine(ErrFp); return OK; } @@ -818,6 +820,7 @@ static int IncludeCmd(char const *cmd) int old_flag; FreshLine = 1; + clear_callstack(); if (IStackPtr+1 >= INCLUDE_NEST) return E_NESTED_INCLUDE; i = &IStack[IStackPtr]; @@ -935,6 +938,7 @@ int IncludeFile(char const *fname) struct stat statbuf; FreshLine = 1; + clear_callstack(); if (IStackPtr+1 >= INCLUDE_NEST) return E_NESTED_INCLUDE; i = &IStack[IStackPtr]; diff --git a/src/main.c b/src/main.c index 3e8574ee..82820009 100644 --- a/src/main.c +++ b/src/main.c @@ -605,12 +605,16 @@ void Eprint(char const *fmt, ...) if (FreshLine && FileName) { FreshLine = 0; - if (strcmp(FileName, "-")) + if (strcmp(FileName, "-")) { + print_callstack(ErrFp); (void) fprintf(ErrFp, "%s(%d): ", FileName, LineNo); - else + } else { + print_callstack(ErrFp); (void) fprintf(ErrFp, "-stdin-(%d): ", LineNo); + } if (DebugFlag & DB_PRTLINE) OutputLine(ErrFp); } else if (FileName) { + print_callstack(ErrFp); fprintf(ErrFp, " "); } diff --git a/src/protos.h b/src/protos.h index e847c9c0..2e45877e 100644 --- a/src/protos.h +++ b/src/protos.h @@ -175,4 +175,4 @@ int push_call(char const *filename, char const *func, int lineno); void clear_callstack(void); int have_callstack(void); int print_callstack(FILE *fp); - +void pop_call(void); diff --git a/src/userfns.c b/src/userfns.c index 0f0cb4ba..c4f79bab 100644 --- a/src/userfns.c +++ b/src/userfns.c @@ -316,7 +316,11 @@ int CallUserFunc(char const *name, int nargs, ParsePtr p) /* Skip the opening bracket, if there's one */ while (isempty(*s)) s++; if (*s == BEG_OF_EXPR) s++; + push_call(f->filename, f->name, f->lineno); h = Evaluate(&s, f->locals, p); + if (h == OK) { + pop_call(); + } f->IsActive = 0; DestroyLocalVals(f); if (DebugFlag &DB_PRTEXPR) { diff --git a/src/utils.c b/src/utils.c index 22b47e64..eae20e5e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -237,9 +237,18 @@ print_callstack(FILE *fp) int done = 0; cs *entry = callstack; while(entry) { - (void) fprintf(fp, "%s(%d): %s\n", entry->filename, entry->lineno, entry->func); + (void) fprintf(fp, "%s(%d): In function `%s'\n", entry->filename, entry->lineno, entry->func); done = 1; entry = entry->next; } return done; } +void +pop_call(void) +{ + cs *entry = callstack; + if (entry) { + callstack = entry->next; + destroy_cs(entry); + } +} diff --git a/tests/test.cmp b/tests/test.cmp index 47507b0c..d7c57379 100644 --- a/tests/test.cmp +++ b/tests/test.cmp @@ -324,7 +324,8 @@ x => 30 y => "Heshvan" z => 1991-02-16 a => 5761 -hebdate(30, "Heshvan", 1991-02-16, 5761) => ../tests/test.rem(74): 30 Heshvan 5761: Invalid Hebrew date +hebdate(30, "Heshvan", 1991-02-16, 5761) => ../tests/test.rem(71): In function `_i' +../tests/test.rem(74): 30 Heshvan 5761: Invalid Hebrew date Invalid Hebrew date Leaving UserFN _i() => Invalid Hebrew date @@ -357,7 +358,8 @@ x => 30 y => "Kislev" z => 1991-02-16 a => 5761 -hebdate(30, "Kislev", 1991-02-16, 5761) => ../tests/test.rem(78): 30 Kislev 5761: Invalid Hebrew date +hebdate(30, "Kislev", 1991-02-16, 5761) => ../tests/test.rem(71): In function `_i' +../tests/test.rem(78): 30 Kislev 5761: Invalid Hebrew date Invalid Hebrew date Leaving UserFN _i() => Invalid Hebrew date @@ -379,7 +381,8 @@ x => 30 y => "Adar A" z => 1991-02-16 a => 5756 -hebdate(30, "Adar A", 1991-02-16, 5756) => ../tests/test.rem(81): No Adar A in 5756 +hebdate(30, "Adar A", 1991-02-16, 5756) => ../tests/test.rem(71): In function `_i' +../tests/test.rem(81): No Adar A in 5756 Invalid Hebrew date Leaving UserFN _i() => Invalid Hebrew date [_i(29, "Adar A", today(), 5755)] MSG Leap @@ -400,7 +403,8 @@ x => 29 y => "Adar A" z => 1991-02-16 a => 5756 -hebdate(29, "Adar A", 1991-02-16, 5756) => ../tests/test.rem(83): No Adar A in 5756 +hebdate(29, "Adar A", 1991-02-16, 5756) => ../tests/test.rem(71): In function `_i' +../tests/test.rem(83): No Adar A in 5756 Invalid Hebrew date Leaving UserFN _i() => Invalid Hebrew date @@ -1099,6 +1103,7 @@ y => 11:33 x => "foo" y => 11:33 "foo" * 11:33 => Type mismatch +../tests/test.rem(334): In function `h' ../tests/test.rem(337): `*': Type mismatch Leaving UserFN h() => Type mismatch set a074 dosubst("%a %b %c %d %e %f %g %h", '1992/5/5') @@ -3789,6 +3794,7 @@ trig("sun warn w") => ../tests/test.rem(740): Trig = Sunday, 17 February, 1991 Entering UserFN w(1) x => 1 1 / 0 => Division by zero +../tests/test.rem(739): In function `w' ../tests/test.rem(740): `/': Division by zero Leaving UserFN w() => Division by zero 1990-01-01