about summary refs log tree commit diff
path: root/Src/Modules/example.c
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-04-15 18:09:05 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-04-15 18:09:05 +0000
commit9003d99d16c46b5679da7fcf1f2a41adef495ff9 (patch)
tree95244be534cc37c03a628068faf7712da6317196 /Src/Modules/example.c
parentf13624e0f8a3c28c90aa0ce8ee36b639a491e4a9 (diff)
downloadzsh-9003d99d16c46b5679da7fcf1f2a41adef495ff9.tar.gz
zsh-9003d99d16c46b5679da7fcf1f2a41adef495ff9.tar.xz
zsh-9003d99d16c46b5679da7fcf1f2a41adef495ff9.zip
zsh-3.1.5-pws-3 zsh-3.1.5-pws-3
Diffstat (limited to 'Src/Modules/example.c')
-rw-r--r--Src/Modules/example.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/Src/Modules/example.c b/Src/Modules/example.c
index 45ef3c28f..a71806c3a 100644
--- a/Src/Modules/example.c
+++ b/Src/Modules/example.c
@@ -49,6 +49,53 @@ bin_example(char *nam, char **args, char *ops, int func)
     return 0;
 }
 
+/**/
+static int
+cond_p_len(Conddef c, char **a)
+{
+    char *s1 = a[0], *s2 = a[1];
+
+    singsub(&s1);
+    untokenize(s1);
+    if (s2) {
+	singsub(&s2);
+	untokenize(s2);
+	return strlen(s1) == matheval(s2);
+    } else {
+	return !s1[0];
+    }
+}
+
+/**/
+static int
+cond_i_ex(Conddef c, char **a)
+{
+    char *s1 = a[0], *s2 = a[1];
+
+    singsub(&s1);
+    untokenize(s1);
+    singsub(&s2);
+    untokenize(s2);
+    return !strcmp("example", dyncat(s1, s2));
+}
+
+/**/
+static int
+ex_wrapper(List list, FuncWrap w, char *name)
+{
+    if (strncmp(name, "example", 7))
+	return 1;
+    else {
+	int ogd = opts[GLOBDOTS];
+
+	opts[GLOBDOTS] = 1;
+	runshfunc(list, w, name);
+	opts[GLOBDOTS] = ogd;
+
+	return 0;
+    }
+}
+
 /*
  * boot_example is executed when the module is loaded.
  */
@@ -57,11 +104,22 @@ static struct builtin bintab[] = {
     BUILTIN("example", 0, bin_example, 0, -1, 0, "flags", NULL),
 };
 
+static struct conddef cotab[] = {
+    CONDDEF("len", 0, 1, 2, cond_p_len),
+    CONDDEF("ex", CONDF_INFIX, 0, 0, cond_i_ex),
+};
+
+static struct funcwrap wrapper[] = {
+    WRAPDEF(ex_wrapper),
+};
+
 /**/
 int
 boot_example(Module m)
 {
-    return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+    return !(addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) |
+	     addconddefs(m->nam, cotab, sizeof(cotab)/sizeof(*cotab)) |
+	     !addwrapper(m, wrapper));
 }
 
 #ifdef MODULE
@@ -71,6 +129,8 @@ int
 cleanup_example(Module m)
 {
     deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
+    deleteconddefs(m->nam, cotab, sizeof(cotab)/sizeof(*cotab));
+    deletewrapper(m, wrapper);
     return 0;
 }
 #endif