zsh-workers
 help / color / mirror / code / Atom feed
* popd patch
@ 1996-05-22 17:35 Anthony Heading
  0 siblings, 0 replies; only message in thread
From: Anthony Heading @ 1996-05-22 17:35 UTC (permalink / raw)
  To: zsh-workers

A bit later than intended, but this should fix the problem with popd.
I think this bit of the code should be commented better, but I've left
that out in the interests of the clarity of the patch.

For anyone interested in how this is supposed to work:

The key variable is "dir" in cd_get_dest.  It either points to an
element of the dirlist (e.g. from cd +5), or is null. The latter
*always* implies a new item on the top of the dirlist: either
the path argument to cd (e.g. cd /tmp) or a default (e.g $HOME).
This convention hopefully makes it reasonably straightforward to
keep the dirstack consistent and unwindable.

The current code screwed up by always changing to the targetted directory,
even though popd wants that directory simply to be discarded.

Any problems, please shout.

Anthony

*** builtin.c.orig	Tue May 21 19:00:23 1996
--- builtin.c	Wed May 22 18:08:37 1996
***************
*** 968,974 ****
  cd_get_dest(char *nam, char **argv, char *ops, int func)
  {
      LinkNode dir = NULL;
!     int newtxt = 0;
      char *dest;
  
      if (!argv[0]) {
--- 968,974 ----
  cd_get_dest(char *nam, char **argv, char *ops, int func)
  {
      LinkNode dir = NULL;
!     LinkNode target;
      char *dest;
  
      if (!argv[0]) {
***************
*** 1019,1032 ****
  	doprintdir++;
      }
  
!     if (!dir) {
! 	if (!(newtxt = (func != BIN_POPD))) {
  	    zsfree(getlinknode(dirstack));
  	}
  	dir = firstnode(dirstack);
      }
      if (!(dest = cd_do_chdir(nam, getdata(dir)))) {
! 	if (newtxt)
  	    zsfree(getlinknode(dirstack));
  	return NULL;
      }
--- 1019,1039 ----
  	doprintdir++;
      }
  
!     target = dir;
!     if (func == BIN_POPD) {
! 	if (!dir) {
  	    zsfree(getlinknode(dirstack));
+ 	    target = dir = firstnode(dirstack);
+ 	} else if (dir != firstnode(dirstack)) {
+ 	    return dir;
  	}
+ 	dir = nextnode(dir);
+     }
+     if (!dir) {
  	dir = firstnode(dirstack);
      }
      if (!(dest = cd_do_chdir(nam, getdata(dir)))) {
! 	if (!target)
  	    zsfree(getlinknode(dirstack));
  	return NULL;
      }
***************
*** 1034,1040 ****
  	zsfree(getdata(dir));
  	setdata(dir, dest);
      }
!     return dir; 
  }
  
  /* Change to given directory, if possible.  This function works out  *
--- 1041,1047 ----
  	zsfree(getdata(dir));
  	setdata(dir, dest);
      }
!     return target ? target : dir;
  }
  
  /* Change to given directory, if possible.  This function works out  *
***************
*** 1211,1217 ****
  	zsfree(getlinknode(dirstack));
  
      if (isset(CHASELINKS)) {
! s = new_pwd;
  	new_pwd = findpwd(s);
  	zsfree(s);
      }
--- 1218,1224 ----
  	zsfree(getlinknode(dirstack));
  
      if (isset(CHASELINKS)) {
! 	s = new_pwd;
  	new_pwd = findpwd(s);
  	zsfree(s);
      }



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-05-22 18:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-22 17:35 popd patch Anthony Heading

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).