ReactOS 0.4.15-dev-5672-gf73ac17
dirstack.c File Reference
#include "precomp.h"
Include dependency graph for dirstack.c:

Go to the source code of this file.

Classes

struct  tagDIRENTRY
 

Typedefs

typedef struct tagDIRENTRY DIRENTRY
 
typedef struct tagDIRENTRYLPDIRENTRY
 

Functions

static INT PushDirectory (LPTSTR pszPath)
 
static VOID PopDirectory (VOID)
 
VOID InitDirectoryStack (VOID)
 
VOID DestroyDirectoryStack (VOID)
 
INT GetDirectoryStackDepth (VOID)
 
INT CommandPushd (LPTSTR rest)
 
INT CommandPopd (LPTSTR rest)
 
INT CommandDirs (LPTSTR rest)
 

Variables

static INT nStackDepth
 
static LPDIRENTRY lpStackTop
 
static LPDIRENTRY lpStackBottom
 

Typedef Documentation

◆ DIRENTRY

◆ LPDIRENTRY

Function Documentation

◆ CommandDirs()

INT CommandDirs ( LPTSTR  rest)

Definition at line 154 of file dirstack.c.

155{
156 LPDIRENTRY lpDir;
157
158 if (!_tcsncmp(rest, _T("/?"), 2))
159 {
161 return 0;
162 }
163
164 nErrorLevel = 0;
165
166 lpDir = lpStackBottom;
167
168 if (lpDir == NULL)
169 {
171 return 0;
172 }
173
174 while (lpDir != NULL)
175 {
176 ConOutPuts(lpDir->szPath);
177 lpDir = lpDir->prev;
178 }
179
180 return 0;
181}
INT nErrorLevel
Definition: cmd.c:158
#define ConOutPuts(szStr)
Definition: console.h:30
#define ConOutResPuts(uID)
Definition: console.h:36
#define STRING_DIRSTACK_HELP4
Definition: resource.h:118
#define STRING_DIRSTACK_HELP3
Definition: resource.h:117
static LPDIRENTRY lpStackBottom
Definition: dirstack.c:31
#define NULL
Definition: types.h:112
#define _tcsncmp
Definition: tchar.h:1428
TCHAR szPath[1]
Definition: dirstack.c:25
struct tagDIRENTRY * prev
Definition: dirstack.c:23
#define _T(x)
Definition: vfdio.h:22

◆ CommandPopd()

INT CommandPopd ( LPTSTR  rest)

Definition at line 132 of file dirstack.c.

133{
134 INT ret = 0;
135 if (!_tcsncmp(rest, _T("/?"), 2))
136 {
138 return 0;
139 }
140
141 if (nStackDepth == 0)
142 return 1;
143
144 ret = _tchdir(lpStackTop->szPath) != 0;
145 PopDirectory ();
146
147 return ret;
148}
#define STRING_DIRSTACK_HELP2
Definition: resource.h:116
static VOID PopDirectory(VOID)
Definition: dirstack.c:62
static LPDIRENTRY lpStackTop
Definition: dirstack.c:30
static INT nStackDepth
Definition: dirstack.c:29
#define _tchdir
Definition: tchar.h:672
int32_t INT
Definition: typedefs.h:58
int ret

◆ CommandPushd()

INT CommandPushd ( LPTSTR  rest)

Definition at line 107 of file dirstack.c.

108{
109 TCHAR curPath[MAX_PATH];
110
111 if (!_tcsncmp (rest, _T("/?"), 2))
112 {
114 return 0;
115 }
116
117 GetCurrentDirectory (MAX_PATH, curPath);
118
119 if (rest[0] != _T('\0'))
120 {
121 if (!SetRootPath(NULL, rest))
122 return 1;
123 }
124
125 return PushDirectory(curPath);
126}
BOOL SetRootPath(TCHAR *oldpath, TCHAR *InPath)
Definition: internal.c:182
#define STRING_DIRSTACK_HELP1
Definition: resource.h:115
static INT PushDirectory(LPTSTR pszPath)
Definition: dirstack.c:35
#define MAX_PATH
Definition: compat.h:34
#define GetCurrentDirectory
Definition: winbase.h:3676
char TCHAR
Definition: xmlstorage.h:189

◆ DestroyDirectoryStack()

VOID DestroyDirectoryStack ( VOID  )

Definition at line 91 of file dirstack.c.

92{
93 while (nStackDepth)
94 PopDirectory ();
95}

Referenced by Cleanup().

◆ GetDirectoryStackDepth()

INT GetDirectoryStackDepth ( VOID  )

Definition at line 98 of file dirstack.c.

99{
100 return nStackDepth;
101}

Referenced by PrintPrompt().

◆ InitDirectoryStack()

VOID InitDirectoryStack ( VOID  )

Definition at line 80 of file dirstack.c.

81{
82 nStackDepth = 0;
85}

Referenced by Initialize().

◆ PopDirectory()

static VOID PopDirectory ( VOID  )
static

Definition at line 62 of file dirstack.c.

63{
64 LPDIRENTRY lpDir = lpStackTop;
65 lpStackTop = lpDir->next;
66 if (lpStackTop != NULL)
68 else
70
71 cmd_free (lpDir);
72
74}
#define cmd_free(ptr)
Definition: cmddbg.h:31
struct tagDIRENTRY * next
Definition: dirstack.c:24

Referenced by CommandPopd(), and DestroyDirectoryStack().

◆ PushDirectory()

static INT PushDirectory ( LPTSTR  pszPath)
static

Definition at line 35 of file dirstack.c.

36{
37 LPDIRENTRY lpDir = cmd_alloc(FIELD_OFFSET(DIRENTRY, szPath[_tcslen(pszPath) + 1]));
38 if (!lpDir)
39 {
40 WARN("Cannot allocate memory for lpDir\n");
42 return -1;
43 }
44
45 lpDir->prev = NULL;
46 lpDir->next = lpStackTop;
47 if (lpStackTop == NULL)
48 lpStackBottom = lpDir;
49 else
50 lpStackTop->prev = lpDir;
51 lpStackTop = lpDir;
52
53 _tcscpy(lpDir->szPath, pszPath);
54
56
57 return nErrorLevel = 0;
58}
VOID error_out_of_memory(VOID)
Definition: error.c:138
#define WARN(fmt,...)
Definition: debug.h:112
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define _tcscpy
Definition: tchar.h:623
LPCWSTR szPath
Definition: env.c:37
Definition: fat.h:103
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define _tcslen
Definition: xmlstorage.h:198

Referenced by CommandPushd().

Variable Documentation

◆ lpStackBottom

LPDIRENTRY lpStackBottom
static

Definition at line 31 of file dirstack.c.

Referenced by CommandDirs(), InitDirectoryStack(), PopDirectory(), and PushDirectory().

◆ lpStackTop

LPDIRENTRY lpStackTop
static

Definition at line 30 of file dirstack.c.

Referenced by CommandPopd(), InitDirectoryStack(), PopDirectory(), and PushDirectory().

◆ nStackDepth