2 * DIRSTACK.C - pushd / pop (directory stack) internal commands.
7 * 14-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
8 * Implemented PUSHD and POPD command.
10 * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
11 * Unicode and redirection safe!
13 * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
20 #ifdef FEATURE_DIRECTORY_STACK
22 typedef struct tagDIRENTRY
24 struct tagDIRENTRY
*prev
;
25 struct tagDIRENTRY
*next
;
27 } DIRENTRY
, *LPDIRENTRY
;
30 static INT nStackDepth
;
31 static LPDIRENTRY lpStackTop
;
32 static LPDIRENTRY lpStackBottom
;
36 PushDirectory (LPTSTR pszPath
)
42 lpDir
= (LPDIRENTRY
)malloc (sizeof (DIRENTRY
));
45 error_out_of_memory ();
50 if (lpStackTop
== NULL
)
53 lpStackBottom
= lpDir
;
57 lpDir
->next
= lpStackTop
;
58 lpStackTop
->prev
= lpDir
;
62 lpDir
->pszPath
= (LPTSTR
)malloc ((_tcslen(pszPath
)+1)*sizeof(TCHAR
));
66 error_out_of_memory ();
70 _tcscpy (lpDir
->pszPath
, pszPath
);
89 lpStackTop
= lpDir
->next
;
90 if (lpStackTop
!= NULL
)
91 lpStackTop
->prev
= NULL
;
95 free (lpDir
->pszPath
);
103 GetDirectoryStackTop (LPTSTR pszPath
)
108 _tcsncpy (pszPath
, lpStackTop
->pszPath
, MAX_PATH
);
115 * initialize directory stack
117 VOID
InitDirectoryStack (VOID
)
121 lpStackBottom
= NULL
;
126 * destroy directory stack
128 VOID
DestroyDirectoryStack (VOID
)
135 INT
GetDirectoryStackDepth (VOID
)
144 INT
CommandPushd (LPTSTR first
, LPTSTR rest
)
146 TCHAR curPath
[MAX_PATH
];
147 TCHAR newPath
[MAX_PATH
];
148 BOOL bChangePath
= FALSE
;
150 if (!_tcsncmp (rest
, _T("/?"), 2))
152 ConOutResPuts(STRING_DIRSTACK_HELP1
);
158 if (rest
[0] != _T('\0'))
160 GetFullPathName (rest
, MAX_PATH
, newPath
, NULL
);
161 bChangePath
= IsValidPathName (newPath
);
164 GetCurrentDirectory (MAX_PATH
, curPath
);
165 if (PushDirectory (curPath
))
169 SetCurrentDirectory (newPath
);
178 INT
CommandPopd (LPTSTR first
, LPTSTR rest
)
180 TCHAR szPath
[MAX_PATH
];
182 if (!_tcsncmp(rest
, _T("/?"), 2))
184 ConOutResPuts(STRING_DIRSTACK_HELP2
);
190 if (GetDirectoryStackDepth () == 0)
193 GetDirectoryStackTop (szPath
);
196 SetCurrentDirectory (szPath
);
205 INT
CommandDirs (LPTSTR first
, LPTSTR rest
)
209 if (!_tcsncmp(rest
, _T("/?"), 2))
211 ConOutResPuts(STRING_DIRSTACK_HELP3
);
217 lpDir
= lpStackBottom
;
221 ConOutResPuts(STRING_DIRSTACK_HELP4
);
225 while (lpDir
!= NULL
)
227 ConOutPuts (lpDir
->pszPath
);
235 #endif /* FEATURE_DIRECTORY_STACK */