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

zreaddir() improvement



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

This patch moves all the code for ignoring `.' and `..' entries into
zreaddir().  Most of the callers had separate code to do this; this
patch avoids this code duplication.  There are no functional changes.

      Index: Src/glob.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/glob.c,v
      retrieving revision 1.23
      retrieving revision 1.25
      diff -c -r1.23 -r1.25
      *** Src/glob.c	1996/12/22 09:11:44	1.23
      --- Src/glob.c	1996/12/22 22:26:26	1.25
      ***************
      *** 1529,1543 ****
        
        	    if (lock == NULL)
        		return;
      ! 	    while ((fn = zreaddir(lock))) {
      ! 		/* Loop through the directory */
      ! 		if (errflag)
      ! 		    break;
      ! 		/* skip this and parent directory */
      ! 		if (fn[0] == '.'
      ! 		    && (fn[1] == '\0'
      ! 			|| (fn[1] == '.' && fn[2] == '\0')))
      ! 		    continue;
        		/* prefix and suffix are zle trickery */
        		if (!dirs && !colonmod &&
        		    ((glob_pre && !strpfx(glob_pre, fn))
      --- 1529,1535 ----
        
        	    if (lock == NULL)
        		return;
      ! 	    while ((fn = zreaddir(lock, 1)) && !errflag) {
        		/* prefix and suffix are zle trickery */
        		if (!dirs && !colonmod &&
        		    ((glob_pre && !strpfx(glob_pre, fn))
      Index: Src/hashtable.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/hashtable.c,v
      retrieving revision 1.14
      retrieving revision 1.16
      diff -c -r1.14 -r1.16
      *** Src/hashtable.c	1996/12/22 04:50:27	1.14
      --- Src/hashtable.c	1996/12/22 22:26:26	1.16
      ***************
      *** 573,584 ****
            if (isrelative(*dirp) || !(dir = opendir(unmeta(*dirp))))
        	return;
        
      !     while ((fn = zreaddir(dir))) {
      ! 	/* Ignore `.' and `..'. */
      ! 	if (fn[0] == '.' &&
      ! 	    (fn[1] == '\0' ||
      ! 	     (fn[1] == '.' && fn[2] == '\0')))
      ! 	    continue;
        	if (!cmdnamtab->getnode(cmdnamtab, fn)) {
        	    cn = (Cmdnam) zcalloc(sizeof *cn);
        	    cn->flags = 0;
      --- 573,579 ----
            if (isrelative(*dirp) || !(dir = opendir(unmeta(*dirp))))
        	return;
        
      !     while ((fn = zreaddir(dir, 1))) {
        	if (!cmdnamtab->getnode(cmdnamtab, fn)) {
        	    cn = (Cmdnam) zcalloc(sizeof *cn);
        	    cn->flags = 0;
      Index: Src/utils.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/utils.c,v
      retrieving revision 1.40
      retrieving revision 1.42
      diff -c -r1.40 -r1.42
      *** Src/utils.c	1996/12/22 09:11:48	1.40
      --- Src/utils.c	1996/12/22 22:26:27	1.42
      ***************
      *** 665,678 ****
        		HEAPALLOC {
        		    pushheap();
        		    l = newlinklist();
      ! 		    while ((fn = zreaddir(lock))) {
      ! 			if (errflag)
      ! 			    break;
      ! 			/* Ignore `.' and `..'. */
      ! 			if (fn[0] == '.' &&
      ! 			    (fn[1] == '\0' ||
      ! 			     (fn[1] == '.' && fn[2] == '\0')))
      ! 			    continue;
        			if (u)
        			    sprintf(buf, "%s/%s?%s", *s, fn, u);
        			else
      --- 665,671 ----
        		HEAPALLOC {
        		    pushheap();
        		    l = newlinklist();
      ! 		    while ((fn = zreaddir(lock, 1)) && !errflag) {
        			if (u)
        			    sprintf(buf, "%s/%s?%s", *s, fn, u);
        			else
      ***************
      *** 2376,2382 ****
            }
            if (!(dd = opendir(unmeta(dir))))
        	return mindistd;
      !     while ((fn = zreaddir(dd))) {
        	nd = spdist(fn, mindistguess,
        		    (int)strlen(mindistguess) / 4 + 1);
        	if (nd <= mindistd) {
      --- 2369,2375 ----
            }
            if (!(dd = opendir(unmeta(dir))))
        	return mindistd;
      !     while ((fn = zreaddir(dd, 0))) {
        	nd = spdist(fn, mindistguess,
        		    (int)strlen(mindistguess) / 4 + 1);
        	if (nd <= mindistd) {
      ***************
      *** 2876,2886 ****
        
        /**/
        char *
      ! zreaddir(DIR *dir)
        {
      !     struct dirent *de = readdir(dir);
        
      !     return de ? metafy(de->d_name, -1, META_STATIC) : NULL;
        }
        
        /* Unmetafy and output a string. */
      --- 2869,2886 ----
        
        /**/
        char *
      ! zreaddir(DIR *dir, int ignoredots)
        {
      !     struct dirent *de;
        
      !     do {
      ! 	de = readdir(dir);
      ! 	if(!de)
      ! 	    return NULL;
      !     } while(ignoredots && de->d_name[0] == '.' &&
      ! 	(!de->d_name[1] || (de->d_name[1] == '.' && !de->d_name[2])));
      ! 
      !     return metafy(de->d_name, -1, META_STATIC);
        }
        
        /* Unmetafy and output a string. */
      Index: Src/Zle/zle_tricky.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/Zle/zle_tricky.c,v
      retrieving revision 1.2
      retrieving revision 1.4
      diff -c -r1.2 -r1.4
      *** Src/Zle/zle_tricky.c	1996/12/22 09:11:55	1.2
      --- Src/Zle/zle_tricky.c	1996/12/22 22:26:34	1.4
      ***************
      *** 1986,1995 ****
        	    q = p + strlen(prpre);
        	}
        	/* Fine, now read the directory. */
      ! 	while ((n = zreaddir(d)) && !errflag) {
      ! 	    /* Ignore `.' and `..'. */
      ! 	    if (n[0] == '.' && (n[1] == '\0' || (n[1] == '.' && n[2] == '\0')))
      ! 		continue;
        	    /* Ignore files beginning with `.' unless the thing we found on *
        	     * the command line also starts with a dot or GLOBDOTS is set.  */
        	    if (*n != '.' || *fpre == '.' || isset(GLOBDOTS)) {
      --- 1986,1992 ----
        	    q = p + strlen(prpre);
        	}
        	/* Fine, now read the directory. */
      ! 	while ((n = zreaddir(d, 1)) && !errflag) {
        	    /* Ignore files beginning with `.' unless the thing we found on *
        	     * the command line also starts with a dot or GLOBDOTS is set.  */
        	    if (*n != '.' || *fpre == '.' || isset(GLOBDOTS)) {

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

iQCVAwUBMr22knD/+HJTpU/hAQEHJgP/USBS4AFn9Lw1g+1hZO6zAi5FDSNLuyi5
RzNRsKK5NZjfe6L64ir3GqpQhjiOLw90tTUSSUqTnIztrfZtLwlHEh+CMwSNigAz
DOFbvAJr64JdKFAAfYuCP59z6Z6vexrWxB4isGS8ZRuA0NT0pbvD+Nc/zSiXBK2o
rxaSD9gDkjI=
=k9zU
-----END PGP SIGNATURE-----



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