Unified warning prompts into new function UTIL_requireUserConfirmationToProceed()
This commit is contained in:
parent
dde97de6c4
commit
aab11ce3db
@ -605,16 +605,10 @@ FIO_openDstFile(FIO_prefs_t* const prefs,
|
|||||||
dstFileName);
|
dstFileName);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
DISPLAY("zstd: %s already exists; overwrite (y/N) ? ",
|
DISPLAY("zstd: %s already exists; ", dstFileName);
|
||||||
dstFileName);
|
if (UTIL_requireUserConfirmationToProceed("overwrite (y/n) ? ", "Not overwritten \n", "yY"))
|
||||||
{ int ch = getchar();
|
return NULL;
|
||||||
if ((ch!='Y') && (ch!='y')) {
|
}
|
||||||
DISPLAY(" not overwritten \n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
/* flush rest of input line */
|
|
||||||
while ((ch!=EOF) && (ch!='\n')) ch = getchar();
|
|
||||||
} }
|
|
||||||
/* need to unlink */
|
/* need to unlink */
|
||||||
FIO_removeFile(dstFileName);
|
FIO_removeFile(dstFileName);
|
||||||
} }
|
} }
|
||||||
@ -1683,19 +1677,8 @@ int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
|
|||||||
} else {
|
} else {
|
||||||
DISPLAY("zstd: WARNING: all input files will be processed and concatenated into a single output file: %s ", outFileName);
|
DISPLAY("zstd: WARNING: all input files will be processed and concatenated into a single output file: %s ", outFileName);
|
||||||
}
|
}
|
||||||
if (prefs->removeSrcFile) {
|
if (prefs->removeSrcFile)
|
||||||
DISPLAY("Proceed? (y/n): ");
|
error = UTIL_requireUserConfirmationToProceed("Proceed? (y/n): ", "Aborting...", "yY");
|
||||||
{
|
|
||||||
int ch = getchar();
|
|
||||||
if ((ch != 'y') && (ch != 'Y')) {
|
|
||||||
DISPLAY("zstd: aborting...\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
/* flush the rest */
|
|
||||||
while ((ch!=EOF) && (ch!='\n'))
|
|
||||||
ch = getchar();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DISPLAY("\n");
|
DISPLAY("\n");
|
||||||
}
|
}
|
||||||
ress.dstFile = FIO_openDstFile(prefs, NULL, outFileName);
|
ress.dstFile = FIO_openDstFile(prefs, NULL, outFileName);
|
||||||
|
@ -87,6 +87,22 @@ UTIL_STATIC void* UTIL_realloc(void *ptr, size_t size)
|
|||||||
******************************************/
|
******************************************/
|
||||||
int g_utilDisplayLevel;
|
int g_utilDisplayLevel;
|
||||||
|
|
||||||
|
int UTIL_requireUserConfirmationToProceed(const char* prompt, const char* abortMsg,
|
||||||
|
const char* acceptableLetters) {
|
||||||
|
int ch;
|
||||||
|
UTIL_DISPLAY("%s", prompt);
|
||||||
|
ch = getchar();
|
||||||
|
if (strchr(acceptableLetters, ch) == NULL) {
|
||||||
|
UTIL_DISPLAY("%s", abortMsg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/* flush the rest */
|
||||||
|
while ((ch!=EOF) && (ch!='\n'))
|
||||||
|
ch = getchar();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Constants
|
* Constants
|
||||||
|
@ -93,6 +93,12 @@ extern "C" {
|
|||||||
******************************************/
|
******************************************/
|
||||||
extern int g_utilDisplayLevel;
|
extern int g_utilDisplayLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays a message prompt and returns success (0) if first character from stdin
|
||||||
|
* matches any from acceptableLetters. Otherwise, returns failure (1) and displays abortMsg.
|
||||||
|
*/
|
||||||
|
int UTIL_requireUserConfirmationToProceed(const char* const prompt, const char* const abortMsg, const char* const acceptableLetters);
|
||||||
|
|
||||||
|
|
||||||
/*-****************************************
|
/*-****************************************
|
||||||
* File functions
|
* File functions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user