2 * DIRSTACK.C - pushd / pop (directory stack) internal commands.
7 * 14-Dec-1998 (Eric Kohl)
8 * Implemented PUSHD and POPD command.
10 * 20-Jan-1999 (Eric Kohl)
11 * Unicode and redirection safe!
13 * 20-Jan-1999 (Eric Kohl)
19 #ifdef FEATURE_DIRECTORY_STACK
21 typedef struct tagDIRENTRY
23 struct tagDIRENTRY
*prev
;
24 struct tagDIRENTRY
*next
;
26 } DIRENTRY
, *LPDIRENTRY
;
29 static INT nStackDepth
;
30 static LPDIRENTRY lpStackTop
;
31 static LPDIRENTRY lpStackBottom
;
35 PushDirectory (LPTSTR pszPath
)
37 LPDIRENTRY lpDir
= cmd_alloc(FIELD_OFFSET(DIRENTRY
, szPath
[_tcslen(pszPath
) + 1]));
40 error_out_of_memory ();
45 lpDir
->next
= lpStackTop
;
46 if (lpStackTop
== NULL
)
47 lpStackBottom
= lpDir
;
49 lpStackTop
->prev
= lpDir
;
52 _tcscpy(lpDir
->szPath
, pszPath
);
56 return nErrorLevel
= 0;
63 LPDIRENTRY lpDir
= lpStackTop
;
64 lpStackTop
= lpDir
->next
;
65 if (lpStackTop
!= NULL
)
66 lpStackTop
->prev
= NULL
;
77 * initialize directory stack
79 VOID
InitDirectoryStack (VOID
)
88 * destroy directory stack
90 VOID
DestroyDirectoryStack (VOID
)
97 INT
GetDirectoryStackDepth (VOID
)
106 INT
CommandPushd (LPTSTR rest
)
108 TCHAR curPath
[MAX_PATH
];
110 if (!_tcsncmp (rest
, _T("/?"), 2))
112 ConOutResPuts(STRING_DIRSTACK_HELP1
);
116 GetCurrentDirectory (MAX_PATH
, curPath
);
118 if (rest
[0] != _T('\0'))
120 if (!SetRootPath(NULL
, rest
))
124 return PushDirectory(curPath
);
131 INT
CommandPopd (LPTSTR rest
)
134 if (!_tcsncmp(rest
, _T("/?"), 2))
136 ConOutResPuts(STRING_DIRSTACK_HELP2
);
140 if (nStackDepth
== 0)
143 ret
= _tchdir(lpStackTop
->szPath
) != 0;
153 INT
CommandDirs (LPTSTR rest
)
157 if (!_tcsncmp(rest
, _T("/?"), 2))
159 ConOutResPuts(STRING_DIRSTACK_HELP3
);
165 lpDir
= lpStackBottom
;
169 ConOutResPuts(STRING_DIRSTACK_HELP4
);
173 while (lpDir
!= NULL
)
175 ConOutPuts(lpDir
->szPath
);
182 #endif /* FEATURE_DIRECTORY_STACK */