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

Name clash checking



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

Some more module changes, requiring both my configuration/build patch
and Peter's ZLE patch to be applied.  Changes are:

* Src/Makefile.in:
  Pseudo-target `modules' to build modules.  Also made the same changes
  for mod_deltochar that my earlier patch made for mod_example.

* Src/zle_main.c, Src/zle_misc.c:
  Changed zlefindfunc() to return -1, rather than the variable zlecmdtot,
  on failure.  This is easier to use, and a hair more efficient.

* Src/module.c:
  Added name clash checking in addbuiltin() and addzlefunction().

* Src/mod_deltochar.c, Src/mod_example.c:
  Error checking on adding and deleting builtins and ZLE functions.
  Also modified prototypes of the boot_mod/cleanup_mod functions to
  match that assumed when they are called.

Someone (I forget who) suggested establishing a separate directory for
module code.  This is a good idea, and I suggest we use zsh/Modules.
I think it would also be a good idea to establish a standard location
to *install* modules: I think $(libdir)/zsh/$(VERSION) would be
logical and would save us a lot of trouble each time a new version
makes binary-incompatible changes.  (Those of us that make several
incompatible builds with the same version number can be assumed to know
what we're doing.)

 -zefram

      Index: Src/Makefile.in
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/Makefile.in,v
      retrieving revision 1.2
      diff -c -r1.2 Makefile.in
      *** Makefile.in	1996/11/08 03:03:24	1.2
      --- Makefile.in	1996/11/09 14:09:03
      ***************
      *** 98,107 ****
        
        # zsh C source
        SRCS = builtin.c compat.c cond.c exec.c glob.c hashtable.c hist.c init.c \
      ! input.c jobs.c lex.c linklist.c loop.c math.c mem.c module.c mod_example.c \
      ! params.c parse.c signals.c subst.c text.c utils.c watch.c zle_bindings.c \
      ! zle_hist.c zle_main.c zle_misc.c zle_move.c zle_refresh.c zle_tricky.c \
      ! zle_utils.c zle_vi.c zle_word.c
        
        # generated prototypes
        DYNAMIC_PROTO = module.pro
      --- 98,107 ----
        
        # zsh C source
        SRCS = builtin.c compat.c cond.c exec.c glob.c hashtable.c hist.c init.c \
      ! input.c jobs.c lex.c linklist.c loop.c math.c mem.c module.c mod_deltochar.c \
      ! mod_example.c params.c parse.c signals.c subst.c text.c utils.c watch.c \
      ! zle_bindings.c zle_hist.c zle_main.c zle_misc.c zle_move.c zle_refresh.c \
      ! zle_tricky.c zle_utils.c zle_vi.c zle_word.c
        
        # generated prototypes
        DYNAMIC_PROTO = module.pro
      ***************
      *** 129,139 ****
      --- 129,145 ----
        # all files in this directory included in the distribution
        DIST = $(DIST_HDRS) $(SRCS) $(AUX)
        
      + # dynamically loadable modules
      + MODULES = mod_deltochar.$(DL_EXT) mod_example.$(DL_EXT)
      + MONULES =
      + 
        # ========= DEPENDENCIES FOR BUILDING ==========
        
        # default target
        all: zsh
        
      + modules: $(MO@D@ULES)
      + 
        zsh: $(PROTO) $(OBJS)
        	$(LINK) $(OBJS) $(LIBS)
        
      ***************
      *** 146,151 ****
      --- 152,159 ----
        $(OBJS): $(HDRS)
        
        $(PROTO): makepro.sed
      + 
      + mod_deltochar.$(DL_EXT): mod_deltochar.pro
        
        mod_example.$(DL_EXT): mod_example.pro
        
      Index: Src/mod_deltochar.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/mod_deltochar.c,v
      retrieving revision 1.1
      diff -c -r1.1 mod_deltochar.c
      *** mod_deltochar.c	1996/11/09 13:29:15	1.1
      --- mod_deltochar.c	1996/11/09 14:06:07
      ***************
      *** 31,36 ****
      --- 31,37 ----
        
        #define ZLE
        #include "zsh.h"
      + #include "mod_deltochar.pro"
        
        static int z_deltochar;
        
      ***************
      *** 71,86 ****
        
        /**/
        int
      ! boot_mod_deltochar(void *dummy)
        {
            z_deltochar = addzlefunction("delete-to-char", deltochar, ZLE_DELETE);
      !     return 0;
        }
        
        /**/
        int
      ! cleanup_mod_deltochar(void *dummy)
        {
      !     deletezlefunction(z_deltochar);
            return 0;
        }
      --- 72,92 ----
        
        /**/
        int
      ! boot_mod_deltochar(Module m)
        {
            z_deltochar = addzlefunction("delete-to-char", deltochar, ZLE_DELETE);
      !     if(z_deltochar != -1)
      ! 	return 0;
      !     zerrnam(m->nam, "name clash when adding ZLE function `delete-to-char'",
      ! 	NULL, 0);
      !     return 1;
        }
        
        /**/
        int
      ! cleanup_mod_deltochar(Module m)
        {
      !     if(z_deltochar != -1)
      ! 	deletezlefunction(z_deltochar);
            return 0;
        }
      Index: Src/mod_example.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/mod_example.c,v
      retrieving revision 1.3
      diff -c -r1.3 mod_example.c
      *** mod_example.c	1996/11/08 03:03:25	1.3
      --- mod_example.c	1996/11/09 14:05:34
      ***************
      *** 32,37 ****
      --- 32,39 ----
        #include "zsh.h"
        #include "mod_example.pro"
        
      + static int failed;
      + 
        /**/
        int
        bin_example(char *nam, char **args, char *ops, int func)
      ***************
      *** 64,79 ****
        
        /**/
        int
      ! boot_mod_example(void *dummy)
        {
      !     addbuiltin("example", 0, bin_example, 0, -1, "flags");
      !     return 0;
        }
        
        /**/
        int
      ! cleanup_mod_example(void *dummy)
        {
      !     deletebuiltin("example");
            return 0;
        }
      --- 66,84 ----
        
        /**/
        int
      ! boot_mod_example(Module m)
        {
      !     failed = addbuiltin("example", 0, bin_example, 0, -1, "flags");
      !     if(failed)
      ! 	zerrnam(m->nam, "name clash when adding builtin `example'", NULL, 0);
      !     return failed;
        }
        
        /**/
        int
      ! cleanup_mod_example(Module m)
        {
      !     if(!failed)
      ! 	deletebuiltin("example");
            return 0;
        }
      Index: Src/module.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/module.c,v
      retrieving revision 1.4
      diff -c -r1.4 module.c
      *** module.c	1996/11/09 13:29:15	1.4
      --- module.c	1996/11/09 14:13:01
      ***************
      *** 203,213 ****
        }
        
        /**/
      ! void
        addbuiltin(char *nam, int flags, HandlerFunc hfunc, int minargs, int maxargs, char *optstr)
        {
            Builtin bn;
        
            bn = zcalloc(sizeof(*bn));
            bn->nam = nam;
            bn->flags = flags;
      --- 203,215 ----
        }
        
        /**/
      ! int
        addbuiltin(char *nam, int flags, HandlerFunc hfunc, int minargs, int maxargs, char *optstr)
        {
            Builtin bn;
        
      +     if(builtintab->getnode(builtintab, nam))
      + 	return 1;
            bn = zcalloc(sizeof(*bn));
            bn->nam = nam;
            bn->flags = flags;
      ***************
      *** 218,223 ****
      --- 220,226 ----
            PERMALLOC {
        	builtintab->addnode(builtintab, bn->nam, bn);
            } LASTALLOC;
      +     return 0;
        }
        
        /**/
      ***************
      *** 237,243 ****
            struct zlecmd *zc = NULL;
            int slot, addsize = zlecmdtot - ZLECMDCOUNT;
        
      !     /* Should we check for a name clash, or let the module do it? */
        
            /* First try and find a free slot.
             * Slight problem:  if we re-use a slot then any key-binding
      --- 240,248 ----
            struct zlecmd *zc = NULL;
            int slot, addsize = zlecmdtot - ZLECMDCOUNT;
        
      !     /* Check for a name clash */
      !     if(zlefindfunc(name) != -1)
      ! 	return -1;
        
            /* First try and find a free slot.
             * Slight problem:  if we re-use a slot then any key-binding
      Index: Src/zle_main.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/zle_main.c,v
      retrieving revision 1.23
      diff -c -r1.23 zle_main.c
      *** zle_main.c	1996/11/09 13:29:15	1.23
      --- zle_main.c	1996/11/09 13:57:12
      ***************
      *** 897,903 ****
        	if (!(zs->flags & ZLE_DELETED) && !strcmp(name, zs->name))
        	    return zs - zlecmdadd + ZLECMDCOUNT;
        
      !     return zlecmdtot;
        }
        
        /**/
      --- 897,903 ----
        	if (!(zs->flags & ZLE_DELETED) && !strcmp(name, zs->name))
        	    return zs - zlecmdadd + ZLECMDCOUNT;
        
      !     return -1;
        }
        
        /**/
      ***************
      *** 1048,1054 ****
        	}
        	if (!ops['s']) {
        	    i = zlefindfunc(*argv);
      ! 	    if (i == zlecmdtot) {
        		zerr("undefined function: %s", *argv, 0);
        		zfree(s, len);
        		return 1;
      --- 1048,1054 ----
        	}
        	if (!ops['s']) {
        	    i = zlefindfunc(*argv);
      ! 	    if (i == -1) {
        		zerr("undefined function: %s", *argv, 0);
        		zfree(s, len);
        		return 1;
      Index: Src/zle_misc.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/zle_misc.c,v
      retrieving revision 1.24
      diff -c -r1.24 zle_misc.c
      *** zle_misc.c	1996/11/09 13:29:16	1.24
      --- zle_misc.c	1996/11/09 13:57:36
      ***************
      *** 617,623 ****
        	unambiguous:
        	    *ptr = 0;
        	    t0 = zlefindfunc(buf);
      ! 	    if (t0 != zlecmdtot) {
        		statusline = NULL;
        		bindtab = obindtab;
        		keybindtab = okeybindtab;
      --- 617,623 ----
        	unambiguous:
        	    *ptr = 0;
        	    t0 = zlefindfunc(buf);
      ! 	    if (t0 != -1) {
        		statusline = NULL;
        		bindtab = obindtab;
        		keybindtab = okeybindtab;

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMoSVrXD/+HJTpU/hAQH28QP/cdj71y8P4YLckOo7PeuPcJi0+tYU082S
nG/nZjcP+RcZ3XVeL54y6mzvJsamb+9BnXd/vC/5AS6N+NJD3MtmGcWET2HmTwyV
Rbh+MIc2lV514qhp+i1ltuPVJJ/QOsnfxCLoSD3Kx0/3cP986QTp3BadSnCKjCIB
FqjjYjxXt4U=
=Wisv
-----END PGP SIGNATURE-----



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