Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

empty shell functions



-----BEGIN PGP SIGNED MESSAGE-----

This patch changes the getfpfunc() and getshfunc() interfaces so that
they return &dummy_list instead of NULL to indicate that the function
is undefined.  NULL is still returned for empty functions.  This makes it
possible to autoload empty functions, or use empty functions for widgets.

This patch depends slightly on my previous patch, chnaging the way
ksh-style autoloads are handled.

 -zefram

      *** Src/builtin.c	1997/03/23 20:20:26	1.67
      --- Src/builtin.c	1997/03/26 04:17:10
      ***************
      *** 793,799 ****
            }
        
            /* execute the chpwd function */
      !     if ((l = getshfunc("chpwd"))) {
        	fflush(stdout);
        	fflush(stderr);
        	doshfunc(l, NULL, 0, 1);
      --- 793,799 ----
            }
        
            /* execute the chpwd function */
      !     if ((l = getshfunc("chpwd")) != &dummy_list) {
        	fflush(stdout);
        	fflush(stderr);
        	doshfunc(l, NULL, 0, 1);
      *** Src/exec.c	1997/03/26 03:09:19	1.54
      --- Src/exec.c	1997/03/26 04:14:32
      ***************
      *** 2461,2468 ****
        void
        execshfunc(Cmd cmd, Shfunc shf)
        {
      -     List funcdef;
      -     char *nam;
            LinkList last_file_list = NULL;
        
            if (errflag)
      --- 2461,2466 ----
      ***************
      *** 2478,2492 ****
        
            /* Are we dealing with an autoloaded shell function? */
            if (shf->flags & PM_UNDEFINED) {
      ! 	nam = (char *) peekfirst(cmd->args);
      ! 	if (!(funcdef = getfpfunc(nam))) {
      ! 	    zerr("function not found: %s", nam, 0);
        	    lastval = 1;
        	    goto end;
        	}
        	shf->flags &= ~PM_UNDEFINED;
        	PERMALLOC {
      ! 	    shf->funcdef = (List) dupstruct(funcdef);
        	} LASTALLOC;
            }
            doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
      --- 2476,2489 ----
        
            /* Are we dealing with an autoloaded shell function? */
            if (shf->flags & PM_UNDEFINED) {
      ! 	if((shf->funcdef = getfpfunc(shf->nam)) == &dummy_list) {
      ! 	    zerr("function not found: %s", shf->nam, 0);
        	    lastval = 1;
        	    goto end;
        	}
        	shf->flags &= ~PM_UNDEFINED;
        	PERMALLOC {
      ! 	    shf->funcdef = (List) dupstruct(shf->funcdef);
        	} LASTALLOC;
            }
            doshfunc(shf->funcdef, cmd->args, shf->flags, 0);
      ***************
      *** 2660,2666 ****
        	    }
        	}
            }
      !     return NULL;
        }
        
        /* Handle ksh-style autoloading.  Given the list read from an autoload file, *
      --- 2657,2663 ----
        	    }
        	}
            }
      !     return &dummy_list;
        }
        
        /* Handle ksh-style autoloading.  Given the list read from an autoload file, *
      *** Src/utils.c	1997/03/22 01:55:41	1.67
      --- Src/utils.c	1997/03/26 04:17:26
      ***************
      *** 578,584 ****
        
            /* If a shell function named "precmd" exists, *
             * then execute it.                           */
      !     if ((list = getshfunc("precmd")))
        	doshfunc(list, NULL, 0, 1);
            if (errflag)
        	return;
      --- 578,584 ----
        
            /* If a shell function named "precmd" exists, *
             * then execute it.                           */
      !     if ((list = getshfunc("precmd")) != &dummy_list)
        	doshfunc(list, NULL, 0, 1);
            if (errflag)
        	return;
      ***************
      *** 587,593 ****
             * "periodic" exists, 3) it's been greater than PERIOD since we *
             * executed "periodic", then execute it now.                    */
            if (period && (time(NULL) > lastperiodic + period) &&
      ! 	(list = getshfunc("periodic"))) {
        	doshfunc(list, NULL, 0, 1);
        	lastperiodic = time(NULL);
            }
      --- 587,593 ----
             * "periodic" exists, 3) it's been greater than PERIOD since we *
             * executed "periodic", then execute it now.                    */
            if (period && (time(NULL) > lastperiodic + period) &&
      ! 	(list = getshfunc("periodic")) != &dummy_list) {
        	doshfunc(list, NULL, 0, 1);
        	lastperiodic = time(NULL);
            }
      ***************
      *** 1649,1672 ****
        getshfunc(char *nam)
        {
            Shfunc shf;
      -     List l;
        
      !     if ((shf = (Shfunc) shfunctab->getnode(shfunctab, nam))) {
      ! 	/* if autoloaded and currently undefined */
      ! 	if (shf->flags & PM_UNDEFINED) {
      ! 	    if (!(l = getfpfunc(nam))) {
      ! 		zerr("function not found: %s", nam, 0);
      ! 		return NULL;
      ! 	    }
      ! 	    shf->flags &= ~PM_UNDEFINED;
      ! 	    PERMALLOC {
      ! 		shf->funcdef = (List) dupstruct(l);
      ! 	    } LASTALLOC;
      ! 	}
      ! 	return shf->funcdef;
      !     } else {
      ! 	return NULL;
            }
        }
        
        /* allocate a tree element */
      --- 1649,1667 ----
        getshfunc(char *nam)
        {
            Shfunc shf;
        
      !     if (!(shf = (Shfunc) shfunctab->getnode(shfunctab, nam)))
      ! 	return &dummy_list;
      ! 
      !     /* if autoloaded and currently undefined */
      !     if ((shf->flags & PM_UNDEFINED) &&
      ! 	(shf->funcdef = getfpfunc(nam)) != &dummy_list) {
      ! 	shf->flags &= ~PM_UNDEFINED;
      ! 	PERMALLOC {
      ! 	    shf->funcdef = (List) dupstruct(shf->funcdef);
      ! 	} LASTALLOC;
            }
      +     return shf->funcdef;
        }
        
        /* allocate a tree element */
      *** Src/Zle/zle_main.c	1997/03/23 20:20:43	1.32
      --- Src/Zle/zle_main.c	1997/03/26 04:17:44
      ***************
      *** 504,510 ****
            } else {
        	List l = getshfunc(w->u.fnnam);
        
      ! 	if(!l) {
        	    /* the shell function doesn't exist */
        	    char *nm = niceztrdup(w->u.fnnam);
        	    char *msg = tricat("No such shell function `", nm, "'");
      --- 504,510 ----
            } else {
        	List l = getshfunc(w->u.fnnam);
        
      ! 	if(l == &dummy_list) {
        	    /* the shell function doesn't exist */
        	    char *nm = niceztrdup(w->u.fnnam);
        	    char *msg = tricat("No such shell function `", nm, "'");
      *** Src/Zle/zle_tricky.c	1997/03/23 20:20:46	1.27
      --- Src/Zle/zle_tricky.c	1997/03/26 04:18:00
      ***************
      *** 2714,2720 ****
        	int lv = lastval;
        
        	/* Get the function. */
      ! 	if ((list = getshfunc(cc->func))) {
        	    /* We have it, so build a argument list. */
        	    LinkList args = newlinklist();
        
      --- 2714,2720 ----
        	int lv = lastval;
        
        	/* Get the function. */
      ! 	if ((list = getshfunc(cc->func)) != &dummy_list) {
        	    /* We have it, so build a argument list. */
        	    LinkList args = newlinklist();
        

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii

iQCVAwUBMzipoXD/+HJTpU/hAQHmawP+Ovq1luee9NelyihdnW+beZDvL7HuisEh
YPtZUn3wZh/posLhPaNo/RCY/yP9K+awBvFYYmDQn3qgU4VwDTl9Hx9KgBrhW7fr
hjT4oLscduHJckGnGCJSUa81kMMpxB5BKj4uflqcgo75WyzsgG6IMqK+p7dyTwLL
8kM0/MZpMP4=
=L9hv
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author