zsh-workers
 help / color / mirror / code / Atom feed
From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@math.gatech.edu
Subject: PATCH: module-defined condition cleanup
Date: Fri, 18 Dec 1998 10:05:11 +0100 (MET)	[thread overview]
Message-ID: <199812180905.KAA15517@beta.informatik.hu-berlin.de> (raw)


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


                 reply	other threads:[~1998-12-18  9:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199812180905.KAA15517@beta.informatik.hu-berlin.de \
    --to=wischnow@informatik.hu-berlin.de \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).