Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: module-defined condition cleanup
- X-seq: zsh-workers 4842
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx
- Subject: PATCH: module-defined condition cleanup
- Date: Fri, 18 Dec 1998 10:05:11 +0100 (MET)
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@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author