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
)
40 lpDir
= (LPDIRENTRY
)malloc (sizeof (DIRENTRY
));
43 error_out_of_memory ();
48 if (lpStackTop
== NULL
)
51 lpStackBottom
= lpDir
;
55 lpDir
->next
= lpStackTop
;
56 lpStackTop
->prev
= lpDir
;
60 lpDir
->pszPath
= (LPTSTR
)malloc ((_tcslen(pszPath
)+1)*sizeof(TCHAR
));
64 error_out_of_memory ();
68 _tcscpy (lpDir
->pszPath
, pszPath
);
85 lpStackTop
= lpDir
->next
;
86 if (lpStackTop
!= NULL
)
87 lpStackTop
->prev
= NULL
;
91 free (lpDir
->pszPath
);
99 GetDirectoryStackTop (LPTSTR pszPath
)
102 _tcsncpy (pszPath
, lpStackTop
->pszPath
, MAX_PATH
);
109 * initialize directory stack
111 VOID
InitDirectoryStack (VOID
)
115 lpStackBottom
= NULL
;
120 * destroy directory stack
122 VOID
DestroyDirectoryStack (VOID
)
129 INT
GetDirectoryStackDepth (VOID
)
138 INT
CommandPushd (LPTSTR first
, LPTSTR rest
)
140 TCHAR curPath
[MAX_PATH
];
141 TCHAR newPath
[MAX_PATH
];
142 BOOL bChangePath
= FALSE
;
143 WCHAR szMsg
[RC_STRING_MAX_SIZE
];
145 if (!_tcsncmp (rest
, _T("/?"), 2))
147 LoadString( GetModuleHandle(NULL
), STRING_DIRSTACK_HELP1
, (LPTSTR
) szMsg
,sizeof(szMsg
));
148 ConOutPuts (_T((LPTSTR
)szMsg
));
153 if (rest
[0] != _T('\0'))
155 GetFullPathName (rest
, MAX_PATH
, newPath
, NULL
);
156 bChangePath
= IsValidPathName (newPath
);
159 GetCurrentDirectory (MAX_PATH
, curPath
);
160 if (PushDirectory (curPath
))
164 SetCurrentDirectory (newPath
);
173 INT
CommandPopd (LPTSTR first
, LPTSTR rest
)
175 TCHAR szPath
[MAX_PATH
];
176 WCHAR szMsg
[RC_STRING_MAX_SIZE
];
178 if (!_tcsncmp(rest
, _T("/?"), 2))
180 LoadString( GetModuleHandle(NULL
), STRING_DIRSTACK_HELP2
, (LPTSTR
) szMsg
,sizeof(szMsg
));
181 ConOutPuts (_T((LPTSTR
)szMsg
));
186 if (GetDirectoryStackDepth () == 0)
189 GetDirectoryStackTop (szPath
);
192 SetCurrentDirectory (szPath
);
201 INT
CommandDirs (LPTSTR first
, LPTSTR rest
)
204 WCHAR szMsg
[RC_STRING_MAX_SIZE
];
206 if (!_tcsncmp(rest
, _T("/?"), 2))
208 LoadString( GetModuleHandle(NULL
), STRING_DIRSTACK_HELP3
, (LPTSTR
) szMsg
,sizeof(szMsg
));
209 ConOutPuts (_T((LPTSTR
)szMsg
));
215 lpDir
= lpStackBottom
;
219 LoadString( GetModuleHandle(NULL
), STRING_DIRSTACK_HELP4
, (LPTSTR
) szMsg
,sizeof(szMsg
));
220 ConOutPuts (_T((LPTSTR
)szMsg
));
225 while (lpDir
!= NULL
)
227 ConOutPuts (lpDir
->pszPath
);
235 #endif /* FEATURE_DIRECTORY_STACK */