From fe29ed41ccdc03403220d017de90aab3c05bc949 Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Tue, 27 Feb 2007 23:20:05 +0000 Subject: [PATCH] cmd.exe: Support del /p. --- programs/cmd/builtins.c | 27 +++++++++++++++++++++------ programs/cmd/wcmd.h | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 771bcbb58d..c7c4839d79 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -240,7 +240,7 @@ char *p; /* If filename part of parameter is * or *.*, prompt unless /Q supplied. */ - if (strstr (quals, "/Q") == NULL) { + if ((strstr (quals, "/Q") == NULL) && (strstr (quals, "/P") == NULL)) { char drive[10]; char dir[MAX_PATH]; @@ -259,7 +259,7 @@ char *p; /* Ask for confirmation */ sprintf(question, "%s, ", fpath); - ok = WCMD_ask_confirm(question); + ok = WCMD_ask_confirm(question, TRUE); /* Abort if answer is 'N' */ if (!ok) return; @@ -288,7 +288,20 @@ char *p; } else strcpy (fpath, fd.cFileName); if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - if (!DeleteFile (fpath)) WCMD_print_error (); + /* /P means prompt for each file */ + if (strstr (quals, "/P") != NULL) { + BOOL ok; + char question[MAXSTRING]; + + /* Ask for confirmation */ + sprintf(question, "%s, Delete", fpath); + ok = WCMD_ask_confirm(question, FALSE); + + /* Only delete if answer is 'Y' */ + if (ok && !DeleteFile (fpath)) WCMD_print_error (); + } else { + if (!DeleteFile (fpath)) WCMD_print_error (); + } } } while (FindNextFile(hff, &fd) != 0); FindClose (hff); @@ -681,7 +694,7 @@ void WCMD_remove_dir (void) { /* Ask for confirmation */ sprintf(question, "%s, ", param1); - ok = WCMD_ask_confirm(question); + ok = WCMD_ask_confirm(question, TRUE); /* Abort if answer is 'N' */ if (!ok) return; @@ -1313,7 +1326,7 @@ void WCMD_exit (void) { * Returns True if Y answer is selected * */ -BOOL WCMD_ask_confirm (char *message) { +BOOL WCMD_ask_confirm (char *message, BOOL showSureText) { char msgbuffer[MAXSTRING]; char Ybuffer[MAXSTRING]; @@ -1329,7 +1342,9 @@ BOOL WCMD_ask_confirm (char *message) { /* Loop waiting on a Y or N */ while (answer[0] != Ybuffer[0] && answer[0] != Nbuffer[0]) { WCMD_output_asis (message); - WCMD_output_asis (msgbuffer); + if (showSureText) { + WCMD_output_asis (msgbuffer); + } WCMD_output_asis (" ("); WCMD_output_asis (Ybuffer); WCMD_output_asis ("/"); diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index 75079f1f52..d6357f0a20 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -80,7 +80,7 @@ char *WCMD_strtrim_leading_spaces (char *string); void WCMD_strtrim_trailing_spaces (char *string); void WCMD_opt_s_strip_quotes(char *cmd); void WCMD_HandleTildaModifiers(char **start, char *forVariable); -BOOL WCMD_ask_confirm (char *message); +BOOL WCMD_ask_confirm (char *message, BOOL showSureText); void WCMD_splitpath(const CHAR* path, CHAR* drv, CHAR* dir, CHAR* name, CHAR* ext);