From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16351 invoked from network); 18 Dec 1998 09:11:44 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 18 Dec 1998 09:11:44 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id EAA23938; Fri, 18 Dec 1998 04:06:47 -0500 (EST) Resent-Date: Fri, 18 Dec 1998 04:06:47 -0500 (EST) Date: Fri, 18 Dec 1998 10:05:11 +0100 (MET) Message-Id: <199812180905.KAA15517@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@math.gatech.edu Subject: PATCH: module-defined condition cleanup Resent-Message-ID: <"xfPOt1.0.wr5.diXUs"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4842 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Hello While working on the completion stuff I realised that the precedence infix condition codes have in the current implementation may be a bit irritating. E.g.: % zmodload example % [[ -len -s 2 ]] will fail since the code searches only for an infix condition code named `-s'. This can be avoided by using `[[ -len \-s 2 ]]' but since most people won't consider `-' to be a special character needing quoting this will probably cause trouble. The patch below makes zsh first check for an infix condition code and, if none is found, after that look for an prefix condition code. Bye Sven diff -c os/cond.c Src/cond.c *** os/cond.c Thu Dec 17 15:06:19 1998 --- Src/cond.c Fri Dec 18 09:02:26 1998 *************** *** 48,54 **** { Conddef cd; ! if ((cd = getconddef((c->type == COND_MODI), (char *) c->left, 1))) { if (c->type == COND_MOD) { int l = arrlen((char **) c->right); --- 48,55 ---- { Conddef cd; ! if ((cd = getconddef((c->type == COND_MODI), ! ((char *) c->left) + 1, 1))) { if (c->type == COND_MOD) { int l = arrlen((char **) c->right); *************** *** 59,66 **** } return cd->handler((char **) c->right, cd->condid); } ! else ! zerr("unrecognized condition: `-%s'", (char *) c->left, 0); return 0; } } --- 60,81 ---- } return cd->handler((char **) c->right, cd->condid); } ! else { ! char **a = (char **) c->right, *s = a[0]; ! ! if (s && s[0] == '-' && ! (cd = getconddef(0, s + 1, 1))) { ! int l = arrlen(a); ! ! if (l < cd->min || (cd->max >= 0 && l > cd->max)) { ! zerr("unrecognized condition: `-%s'", (char *) c->left, 0); ! return 0; ! } ! a[0] = (char *) c->left; ! return cd->handler(a, cd->condid); ! } else ! zerr("unrecognized condition: `-%s'", (char *) c->left, 0); ! } return 0; } } diff -c os/parse.c Src/parse.c *** os/parse.c Thu Dec 17 15:06:21 1998 --- Src/parse.c Fri Dec 18 09:02:18 1998 *************** *** 1339,1345 **** n->ntype = NT_SET(N_COND, NT_STR, NT_STR | NT_ARR, 0, 0); n->type = COND_MOD; ! n->left = (void *) (a + 1); d[0] = b; d[1] = NULL; n->right = (void *) arrdup(d); --- 1339,1345 ---- n->ntype = NT_SET(N_COND, NT_STR, NT_STR | NT_ARR, 0, 0); n->type = COND_MOD; ! n->left = (void *) a; d[0] = b; d[1] = NULL; n->right = (void *) arrdup(d); *************** *** 1386,1392 **** n->ntype = NT_SET(N_COND, NT_STR, NT_STR | NT_ARR, 0, 0); n->type = COND_MODI; ! n->left = (void *) (b + 1); d[0] = a; d[1] = c; d[2] = NULL; --- 1386,1392 ---- n->ntype = NT_SET(N_COND, NT_STR, NT_STR | NT_ARR, 0, 0); n->type = COND_MODI; ! n->left = (void *) b; d[0] = a; d[1] = c; d[2] = NULL; *************** *** 1397,1403 **** n->ntype = NT_SET(N_COND, NT_STR, NT_STR | NT_ARR, 0, 0); n->type = COND_MOD; ! n->left = (void *) (a + 1); d[0] = b; d[1] = c; d[2] = NULL; --- 1397,1403 ---- n->ntype = NT_SET(N_COND, NT_STR, NT_STR | NT_ARR, 0, 0); n->type = COND_MOD; ! n->left = (void *) a; d[0] = b; d[1] = c; d[2] = NULL; -- Sven Wischnowsky wischnow@informatik.hu-berlin.de