From 9003d99d16c46b5679da7fcf1f2a41adef495ff9 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 15 Apr 1999 18:09:05 +0000 Subject: zsh-3.1.5-pws-3 --- Src/Modules/example.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'Src/Modules/example.c') 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 -- cgit 1.4.1