From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17038 invoked from network); 24 Jun 1999 10:31:06 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 24 Jun 1999 10:31:06 -0000 Received: (qmail 27886 invoked by alias); 24 Jun 1999 10:30:46 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6823 Received: (qmail 27879 invoked from network); 24 Jun 1999 10:30:45 -0000 Message-Id: <9906241002.AA16000@ibmth.df.unipi.it> To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Subject: PATCH: pws-N: function line numbers Date: Thu, 24 Jun 1999 12:02:07 +0200 From: Peter Stephenson Now line numbers work properly in functions, we can use them for printing error messages. To get the name of the function right, I hijacked scriptname. That neatly solves the problem of deciding whether the nearest enclosing object is a sourced script or a function. It would be sort of nice to fix this stuff in 3.0.6 too, but that means adapting both Sven's and my previous fixes, which is a rather deathly task. --- Src/exec.c.fnln Thu Jun 24 10:46:29 1999 +++ Src/exec.c Thu Jun 24 11:40:38 1999 @@ -2879,7 +2879,7 @@ { char **tab, **x, *oargv0 = NULL; int oldzoptind, oldlastval; - char saveopts[OPT_SIZE]; + char saveopts[OPT_SIZE], *oldscriptname; int obreaks = breaks; HEAPALLOC { @@ -2891,6 +2891,8 @@ starttrapscope(); tab = pparams; + oldscriptname = scriptname; + scriptname = name; oldzoptind = zoptind; zoptind = 1; @@ -2933,6 +2935,7 @@ argzero = oargv0; } zoptind = oldzoptind; + scriptname = oldscriptname; pparams = tab; if (isset(LOCALOPTIONS)) { --- Src/utils.c.fnln Wed Jun 23 17:35:29 1999 +++ Src/utils.c Thu Jun 24 11:42:42 1999 @@ -62,9 +62,10 @@ /* * scriptname is set when sourcing scripts, so that we get the * correct name instead of the generic name of whatever - * program/script is running. + * program/script is running. It's also set in shell functions, + * so test locallevel, too. */ - nicezputs(isset(SHINSTDIN) ? "zsh" : + nicezputs((isset(SHINSTDIN) && !locallevel) ? "zsh" : scriptname ? scriptname : argzero, stderr); fputs(": ", stderr); zerrnam(NULL, fmt, str, num); @@ -79,7 +80,7 @@ return; errflag = 1; trashzle(); - if(unset(SHINSTDIN)) { + if (unset(SHINSTDIN) || locallevel) { nicezputs(scriptname ? scriptname : argzero, stderr); fputs(": ", stderr); } @@ -133,7 +134,7 @@ putc(*fmt == Meta ? *++fmt ^ 32 : *fmt, stderr); fmt++; } - if (unset(SHINSTDIN) && lineno) + if ((unset(SHINSTDIN) || locallevel) && lineno) fprintf(stderr, " [%ld]\n", (long)lineno); else putc('\n', stderr); -- Peter Stephenson Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy