ReactOS  0.4.15-dev-1397-g19779b3
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 STRING_DIRSTACK_HELP4
Definition: resource.h:118
struct tagDIRENTRY * prev
Definition: dirstack.c:23
static LPDIRENTRY lpStackBottom
Definition: dirstack.c:31
#define _T(x)
Definition: vfdio.h:22
TCHAR szPath[1]
Definition: dirstack.c:25
#define STRING_DIRSTACK_HELP3
Definition: resource.h:117
#define NULL
Definition: types.h:112
#define ConOutResPuts(uID)
Definition: console.h:36
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
VOID ConOutPuts(LPTSTR szText)
Definition: tee.c:27

◆ 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 }
int32_t INT
Definition: typedefs.h:58
static VOID PopDirectory(VOID)
Definition: dirstack.c:62
static INT nStackDepth
Definition: dirstack.c:29
#define _T(x)
Definition: vfdio.h:22
int ret
TCHAR szPath[1]
Definition: dirstack.c:25
#define STRING_DIRSTACK_HELP2
Definition: resource.h:116
#define ConOutResPuts(uID)
Definition: console.h:36
static LPDIRENTRY lpStackTop
Definition: dirstack.c:30
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
int _tchdir(const _TCHAR *_path)
Definition: chdir.c:8

◆ 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 }
#define GetCurrentDirectory
Definition: winbase.h:3645
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define MAX_PATH
Definition: compat.h:34
BOOL SetRootPath(TCHAR *oldpath, TCHAR *InPath)
Definition: internal.c:182
static INT PushDirectory(LPTSTR pszPath)
Definition: dirstack.c:35
#define NULL
Definition: types.h:112
#define ConOutResPuts(uID)
Definition: console.h:36
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
#define STRING_DIRSTACK_HELP1
Definition: resource.h:115

◆ DestroyDirectoryStack()

VOID DestroyDirectoryStack ( VOID  )

Definition at line 91 of file dirstack.c.

92 {
93  while (nStackDepth)
94  PopDirectory ();
95 }
static VOID PopDirectory(VOID)
Definition: dirstack.c:62
static INT nStackDepth
Definition: dirstack.c:29

Referenced by Cleanup().

◆ GetDirectoryStackDepth()

INT GetDirectoryStackDepth ( VOID  )

Definition at line 98 of file dirstack.c.

99 {
100  return nStackDepth;
101 }
static INT nStackDepth
Definition: dirstack.c:29

Referenced by PrintPrompt().

◆ InitDirectoryStack()

VOID InitDirectoryStack ( VOID  )

Definition at line 80 of file dirstack.c.

81 {
82  nStackDepth = 0;
83  lpStackTop = NULL;
85 }
static INT nStackDepth
Definition: dirstack.c:29
static LPDIRENTRY lpStackBottom
Definition: dirstack.c:31
#define NULL
Definition: types.h:112
static LPDIRENTRY lpStackTop
Definition: dirstack.c:30

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)
67  lpStackTop->prev = NULL;
68  else
70 
71  cmd_free (lpDir);
72 
73  nStackDepth--;
74 }
struct tagDIRENTRY * prev
Definition: dirstack.c:23
static INT nStackDepth
Definition: dirstack.c:29
struct tagDIRENTRY * next
Definition: dirstack.c:24
static LPDIRENTRY lpStackBottom
Definition: dirstack.c:31
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define NULL
Definition: types.h:112
static LPDIRENTRY lpStackTop
Definition: dirstack.c:30

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 
55  nStackDepth++;
56 
57  return nErrorLevel = 0;
58 }
INT nErrorLevel
Definition: cmd.c:158
struct tagDIRENTRY * prev
Definition: dirstack.c:23
#define WARN(fmt,...)
Definition: debug.h:112
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
VOID error_out_of_memory(VOID)
Definition: error.c:138
static INT nStackDepth
Definition: dirstack.c:29
struct tagDIRENTRY * next
Definition: dirstack.c:24
static LPDIRENTRY lpStackBottom
Definition: dirstack.c:31
TCHAR szPath[1]
Definition: dirstack.c:25
Definition: fat.h:102
#define cmd_alloc(size)
Definition: cmddbg.h:29
LPCWSTR szPath
Definition: env.c:35
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
static LPDIRENTRY lpStackTop
Definition: dirstack.c:30

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