Jason Edmeades : cmd.exe: Add pushd and popd.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Feb 26 07:59:29 CST 2007
Module: wine
Branch: master
Commit: 365f86fd7ec3013149d6167b4710656cea2c0f2e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=365f86fd7ec3013149d6167b4710656cea2c0f2e
Author: Jason Edmeades <us at edmeades.me.uk>
Date: Fri Feb 23 22:17:28 2007 +0000
cmd.exe: Add pushd and popd.
---
programs/cmd/En.rc | 8 +++++++
programs/cmd/builtins.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++
programs/cmd/wcmd.h | 6 ++++-
programs/cmd/wcmdmain.c | 8 ++++++-
4 files changed, 74 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/En.rc b/programs/cmd/En.rc
index fda556e..1a8877d 100644
--- a/programs/cmd/En.rc
+++ b/programs/cmd/En.rc
@@ -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\
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index a81c90c..346591a 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -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
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 263412e..07d1649 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -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[];
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 0e58197..84d1c04 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -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;
More information about the wine-cvs
mailing list