about summary refs log tree commit diff
path: root/Src/Modules/parameter.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-08-11 19:22:54 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-08-11 19:22:54 +0000
commit2853ca830ac8d504b7374de2be0ec82122d33c2d (patch)
treed86ea41af13f51f6a9549833a3463c6da307bfc0 /Src/Modules/parameter.c
parent2e485d60ffbf14a461a2d814b30245a9141abeb7 (diff)
downloadzsh-2853ca830ac8d504b7374de2be0ec82122d33c2d.tar.gz
zsh-2853ca830ac8d504b7374de2be0ec82122d33c2d.tar.xz
zsh-2853ca830ac8d504b7374de2be0ec82122d33c2d.zip
25247 with further modifications: add $funcsourcetrace
Diffstat (limited to 'Src/Modules/parameter.c')
-rw-r--r--Src/Modules/parameter.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index efb22fafd..74593afc0 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -286,7 +286,7 @@ setfunction(char *name, char *val, int dis)
 	zsfree(val);
 	return;
     }
-    shf = (Shfunc) zalloc(sizeof(*shf));
+    shf = (Shfunc) zshcalloc(sizeof(*shf));
     shf->funcdef = dupeprog(prog, 0);
     shf->node.flags = dis;
 
@@ -529,7 +529,35 @@ functracegetfn(UNUSED(Param pm))
 	char *colonpair;
 
 	colonpair = zhalloc(strlen(f->caller) + (f->lineno > 9999 ? 24 : 6));
-	sprintf(colonpair, "%s:%d", f->caller, f->lineno);
+	sprintf(colonpair, "%s:%ld", f->caller, (long)f->lineno);
+
+	*p = colonpair;
+    }
+    *p = NULL;
+
+    return ret;
+}
+
+/* Functions for the funcsourcetrace special parameter. */
+
+/**/
+static char **
+funcsourcetracegetfn(UNUSED(Param pm))
+{
+    Funcstack f;
+    int num;
+    char **ret, **p;
+
+    for (f = funcstack, num = 0; f; f = f->prev, num++);
+
+    ret = (char **) zhalloc((num + 1) * sizeof(char *));
+
+    for (f = funcstack, p = ret; f; f = f->prev, p++) {
+	char *colonpair;
+	char *fname = f->filename ? f->filename : "";
+
+	colonpair = zhalloc(strlen(fname) + (f->flineno > 9999 ? 24 : 6));
+	sprintf(colonpair, "%s:%ld", fname, (long)f->flineno);
 
 	*p = colonpair;
     }
@@ -1773,6 +1801,8 @@ static const struct gsu_array funcstack_gsu =
 { funcstackgetfn, arrsetfn, stdunsetfn };
 static const struct gsu_array functrace_gsu =
 { functracegetfn, arrsetfn, stdunsetfn };
+static const struct gsu_array funcsourcetrace_gsu =
+{ funcsourcetracegetfn, arrsetfn, stdunsetfn };
 static const struct gsu_array reswords_gsu =
 { reswordsgetfn, arrsetfn, stdunsetfn };
 static const struct gsu_array disreswords_gsu =
@@ -1801,6 +1831,8 @@ static struct paramdef partab[] = {
 	    &disreswords_gsu, NULL, NULL),
     SPECIALPMDEF("dis_saliases", 0,
 	    &pmdissaliases_gsu, getpmdissalias, scanpmdissaliases),
+    SPECIALPMDEF("funcsourcetrace", PM_ARRAY|PM_READONLY,
+	    &funcsourcetrace_gsu, NULL, NULL),
     SPECIALPMDEF("funcstack", PM_ARRAY|PM_READONLY,
 	    &funcstack_gsu, NULL, NULL),
     SPECIALPMDEF("functions", 0, &pmfunctions_gsu, getpmfunction,