Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendirstack.c
Go to the documentation of this file.
00001 /* 00002 * DIRSTACK.C - pushd / pop (directory stack) internal commands. 00003 * 00004 * 00005 * History: 00006 * 00007 * 14-Dec-1998 (Eric Kohl) 00008 * Implemented PUSHD and POPD command. 00009 * 00010 * 20-Jan-1999 (Eric Kohl) 00011 * Unicode and redirection safe! 00012 * 00013 * 20-Jan-1999 (Eric Kohl) 00014 * Added DIRS command. 00015 */ 00016 00017 #include <precomp.h> 00018 00019 #ifdef FEATURE_DIRECTORY_STACK 00020 00021 typedef struct tagDIRENTRY 00022 { 00023 struct tagDIRENTRY *prev; 00024 struct tagDIRENTRY *next; 00025 TCHAR szPath[1]; 00026 } DIRENTRY, *LPDIRENTRY; 00027 00028 00029 static INT nStackDepth; 00030 static LPDIRENTRY lpStackTop; 00031 static LPDIRENTRY lpStackBottom; 00032 00033 00034 static INT 00035 PushDirectory (LPTSTR pszPath) 00036 { 00037 LPDIRENTRY lpDir = cmd_alloc(FIELD_OFFSET(DIRENTRY, szPath[_tcslen(pszPath) + 1])); 00038 if (!lpDir) 00039 { 00040 error_out_of_memory (); 00041 return -1; 00042 } 00043 00044 lpDir->prev = NULL; 00045 lpDir->next = lpStackTop; 00046 if (lpStackTop == NULL) 00047 lpStackBottom = lpDir; 00048 else 00049 lpStackTop->prev = lpDir; 00050 lpStackTop = lpDir; 00051 00052 _tcscpy(lpDir->szPath, pszPath); 00053 00054 nStackDepth++; 00055 00056 return nErrorLevel = 0; 00057 } 00058 00059 00060 static VOID 00061 PopDirectory (VOID) 00062 { 00063 LPDIRENTRY lpDir = lpStackTop; 00064 lpStackTop = lpDir->next; 00065 if (lpStackTop != NULL) 00066 lpStackTop->prev = NULL; 00067 else 00068 lpStackBottom = NULL; 00069 00070 cmd_free (lpDir); 00071 00072 nStackDepth--; 00073 } 00074 00075 00076 /* 00077 * initialize directory stack 00078 */ 00079 VOID InitDirectoryStack (VOID) 00080 { 00081 nStackDepth = 0; 00082 lpStackTop = NULL; 00083 lpStackBottom = NULL; 00084 } 00085 00086 00087 /* 00088 * destroy directory stack 00089 */ 00090 VOID DestroyDirectoryStack (VOID) 00091 { 00092 while (nStackDepth) 00093 PopDirectory (); 00094 } 00095 00096 00097 INT GetDirectoryStackDepth (VOID) 00098 { 00099 return nStackDepth; 00100 } 00101 00102 00103 /* 00104 * pushd command 00105 */ 00106 INT CommandPushd (LPTSTR rest) 00107 { 00108 TCHAR curPath[MAX_PATH]; 00109 00110 if (!_tcsncmp (rest, _T("/?"), 2)) 00111 { 00112 ConOutResPuts(STRING_DIRSTACK_HELP1); 00113 return 0; 00114 } 00115 00116 GetCurrentDirectory (MAX_PATH, curPath); 00117 00118 if (rest[0] != _T('\0')) 00119 { 00120 if (!SetRootPath(NULL, rest)) 00121 return 1; 00122 } 00123 00124 return PushDirectory(curPath); 00125 } 00126 00127 00128 /* 00129 * popd command 00130 */ 00131 INT CommandPopd (LPTSTR rest) 00132 { 00133 INT ret = 0; 00134 if (!_tcsncmp(rest, _T("/?"), 2)) 00135 { 00136 ConOutResPuts(STRING_DIRSTACK_HELP2); 00137 return 0; 00138 } 00139 00140 if (nStackDepth == 0) 00141 return 1; 00142 00143 ret = _tchdir(lpStackTop->szPath) != 0; 00144 PopDirectory (); 00145 00146 return ret; 00147 } 00148 00149 00150 /* 00151 * dirs command 00152 */ 00153 INT CommandDirs (LPTSTR rest) 00154 { 00155 LPDIRENTRY lpDir; 00156 00157 if (!_tcsncmp(rest, _T("/?"), 2)) 00158 { 00159 ConOutResPuts(STRING_DIRSTACK_HELP3); 00160 return 0; 00161 } 00162 00163 nErrorLevel = 0; 00164 00165 lpDir = lpStackBottom; 00166 00167 if (lpDir == NULL) 00168 { 00169 ConOutResPuts(STRING_DIRSTACK_HELP4); 00170 return 0; 00171 } 00172 00173 while (lpDir != NULL) 00174 { 00175 ConOutPuts(lpDir->szPath); 00176 lpDir = lpDir->prev; 00177 } 00178 00179 return 0; 00180 } 00181 00182 #endif /* FEATURE_DIRECTORY_STACK */ Generated on Sat May 26 2012 04:17:03 for ReactOS by
1.7.6.1
|