Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] First try of null typeset



Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---

This achieves most of what Bart Schaefer's version achieves, except no extra hacks are needed, and
integer and floats are not changed.

This most definetly is not close to the final solution, but shows what can be achieved by narrowing
down the functional changes to two functions.

In my opinion a separate concept of "null" variable will be needed, and should be separate from
PM_UNSET, since that changes a lot of behavior.

Also, I don't think $empty[(i)] should return nothing, so probably paramsubst() would need to be
tuned, not simply set vunset=1.

Addtionally, this patch doesn't change the behavior of the private module.

 Src/params.c | 23 ++++++++++++++++++++++-
 Src/subst.c  |  2 +-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/Src/params.c b/Src/params.c
index 122f5da7d..7dbe67bd1 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3697,6 +3697,27 @@ unsetparam_pm(Param pm, int altflag, int exp)
     return 0;
 }
 
+/**/
+mod_export int
+isnull(Param pm)
+{
+    switch (PM_TYPE(pm->node.flags)) {
+    case PM_SCALAR:
+	if (pm->gsu.s->getfn == strgetfn && !pm->u.str)
+	    return 1;
+	break;
+    case PM_ARRAY:
+	if (pm->gsu.a->getfn == arrgetfn && !pm->u.arr)
+	    return 1;
+	break;
+    case PM_HASHED:
+	if (pm->gsu.h->getfn == hashgetfn && !pm->u.hash)
+	    return 1;
+	break;
+    }
+    return 0;
+}
+
 /* Standard function to unset a parameter.  This is mostly delegated to *
  * the specific set function.
  *
@@ -5955,7 +5976,7 @@ printparamnode(HashNode hn, int printflags)
 	}
     }
 
-    if ((printflags & PRINT_NAMEONLY) ||
+    if ((printflags & PRINT_NAMEONLY) || isnull(p) ||
 	((p->node.flags & PM_HIDEVAL) && !(printflags & PRINT_INCLUDEVALUE)))
 	quotedzputs(p->node.nam, stdout);
     else {
diff --git a/Src/subst.c b/Src/subst.c
index 8f5bd355e..42d18d58d 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -2532,7 +2532,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
 			     (wantt ? -1 :
 			      ((unset(KSHARRAYS) || inbrace) ? 1 : -1)),
 			     scanflags)) ||
-	    (v->pm && (v->pm->node.flags & PM_UNSET)) ||
+	    (v->pm && (v->pm->node.flags & PM_UNSET || isnull(v->pm))) ||
 	    (v->flags & VALFLAG_EMPTY))
 	    vunset = 1;
 
-- 
2.29.2





Messages sorted by: Reverse Date, Date, Thread, Author