Commit 365f86fd authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

cmd.exe: Add pushd and popd.

parent 7aa2e616
......@@ -196,6 +196,12 @@ The verify flag has no function in Wine.\n"
WCMD_VOL, "Help about VOL\n"
WCMD_PUSHD, "PUSHD <directoryname> saves the current directory onto a\n\
stack, and then changes the current directory to the supplied one.\n"
WCMD_POPD, "POPD changes current directory to the last one saved with\n\
PUSHD.\n"
WCMD_EXIT,
"EXIT terminates the current command session and returns\n\
to the operating system or shell from which you invoked cmd.\n"
......@@ -215,7 +221,9 @@ HELP\t\tShow brief help details on a topic\n\
MD (MKDIR)\tCreate a subdirectory\n\
MOVE\t\tMove a file, set of files or directory tree\n\
PATH\t\tSet or show the search path\n\
POPD\t\tRestores the directory to the last one saved with PUSHD\n\
PROMPT\t\tChange the command prompt\n\
PUSHD\t\tChanges to a new directory, saving the current one\n\
REN (RENAME)\tRename a file\n\
RD (RMDIR)\tDelete a subdirectory\n\
SET\t\tSet or show environment variables\n\
......
......@@ -45,6 +45,7 @@ struct env_stack
};
struct env_stack *saved_environment;
struct env_stack *pushd_directories;
extern HINSTANCE hinst;
extern char *inbuilt[];
......@@ -449,6 +450,59 @@ char string[MAX_PATH];
return;
}
/*****************************************************************************
* WCMD_pushd
*
* Push a directory onto the stack
*/
void WCMD_pushd (void) {
struct env_stack *curdir;
BOOL status;
WCHAR *thisdir;
curdir = LocalAlloc (LMEM_FIXED, sizeof (struct env_stack));
thisdir = LocalAlloc (LMEM_FIXED, 1024 * sizeof(WCHAR));
if( !curdir || !thisdir ) {
LocalFree(curdir);
LocalFree(thisdir);
WCMD_output ("out of memory\n");
return;
}
GetCurrentDirectoryW (1024, thisdir);
status = SetCurrentDirectoryA (param1);
if (!status) {
WCMD_print_error ();
LocalFree(curdir);
LocalFree(thisdir);
return;
} else {
curdir -> next = pushd_directories;
curdir -> strings = thisdir;
pushd_directories = curdir;
}
}
/*****************************************************************************
* WCMD_popd
*
* Pop a directory from the stack
*/
void WCMD_popd (void) {
struct env_stack *temp = pushd_directories;
if (!pushd_directories)
return;
/* pop the old environment from the stack, and make it the current dir */
pushd_directories = temp->next;
SetCurrentDirectoryW(temp->strings);
LocalFree (temp->strings);
LocalFree (temp);
}
/****************************************************************************
* WCMD_if
......
......@@ -49,8 +49,10 @@ void WCMD_output_asis (const char *message);
void WCMD_parse (char *s, char *q, char *p1, char *p2);
void WCMD_pause (void);
void WCMD_pipe (char *command);
void WCMD_popd (void);
void WCMD_print_error (void);
void WCMD_process_command (char *command);
void WCMD_pushd (void);
int WCMD_read_console (char *string, int str_len);
void WCMD_remove_dir (void);
void WCMD_rename (void);
......@@ -137,9 +139,11 @@ typedef struct {
#define WCMD_ENDLOCAL 36
#define WCMD_SETLOCAL 37
#define WCMD_PUSHD 38
#define WCMD_POPD 39
/* Must be last in list */
#define WCMD_EXIT 38
#define WCMD_EXIT 40
/* Some standard messages */
extern const char nyi[];
......
......@@ -32,7 +32,7 @@ const char * const inbuilt[] = {"ATTRIB", "CALL", "CD", "CHDIR", "CLS", "COPY",
"HELP", "IF", "LABEL", "MD", "MKDIR", "MOVE", "PATH", "PAUSE",
"PROMPT", "REM", "REN", "RENAME", "RD", "RMDIR", "SET", "SHIFT",
"TIME", "TITLE", "TYPE", "VERIFY", "VER", "VOL",
"ENDLOCAL", "SETLOCAL", "EXIT" };
"ENDLOCAL", "SETLOCAL", "PUSHD", "POPD", "EXIT" };
HINSTANCE hinst;
DWORD errorlevel;
......@@ -522,6 +522,12 @@ void WCMD_process_command (char *command)
case WCMD_VOL:
WCMD_volume (0, p);
break;
case WCMD_PUSHD:
WCMD_pushd();
break;
case WCMD_POPD:
WCMD_popd();
break;
case WCMD_EXIT:
WCMD_exit ();
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment