/* Ask user for confirmation to proceed Based an assembler version confirm.asm. They behaves the same way. Written because assembler version does not work in Windows 7 64-bit. see use.txt for more details. Syntax ====== @echo off echo Do you really want to do this dangerous thing? confirm.exe If ERRORLEVEL 1 GoTo NO GoTo YES Note, no parameters or messages go on the confirm command line itself. Confirm 1.3 Copyright: (c) 2010-2017 Roedy Green, Canadian Mind Products #101 - 2536 Wark Street Victoria, BC Canada V8T 4G8 tel:(250) 361-9093 mailto:roedyg@mindprod.com http://mindprod.com Compiled as a Windows console App, without precompiled headers. For Visual C++ Express options see http://mindprod.com/jgloss/cpp.html#COMPILING Version History: 1.2 2010-01-30 port the DOS assembler version 1.3 2012-05-08 allow CONFIRM=Y or CONFIRM=N set override. */ /* ==================================== */ // allow getenv, We won't hurt the master copy. #define _CRT_SECURE_NO_WARNINGS #include /* exit, putenv, _splitpath */ #include /* fclose, fgetc, printf, remove, rename, setvbuf */ #include /* getch, putch */ #include /* strlen */ /* ==================================== */ /* P R O T O T Y P E S */ void banner(void); void processResponse ( char response ); int main (int argc, char *argv[]); /* ==================================== */ void processResponse(char response) { /* not echoed because user might hit tab or Enter */ /* and mess up the screen */ switch ( response ) { case 'Y': case 'y': printf(" Yes\r\n"); exit ( 0 ); case 'N': case 'n': case '\x1b' /* Esc */ : printf(" No\r\n"); exit ( 1 ); default: printf("\a"); // beep and keep looping } } /* ==================================== */ int main(int argc, char *argv[]) { char* override = getenv( "confirm" ); if ( override != NULL && strlen( override ) >= 1 ) { processResponse( override[0] ); } printf( "\r\nHit Y for yes, or N for no.\r\n" ); // prompt user once while ( 1 ) { /* loop forever till user enters Y or N */ processResponse( _getch() ); } // should never get here return(2); } /* embedded display copyright banner, with shaded splashes. There is no possible syntax error to trigger it. */ void banner(void) { printf("\n" "\xb0\xb1\xb2\xdb" " Confirm 1.3 " "\xdb\xb2\xb1\xb0" "\nFreeware ask user for confirmation command" "\nCopyright: (c) 1993-2017 Roedy Green, Canadian Mind Products" "\n" "#101 - 2536 Wark Street, Victoria, BC Canada V8T 4G8" "\n" "tel:(250) 361-9093 mailto:roedyg@mindprod.com http://mindprod.com" "\n" "May be used freely for non-military use only" "\n\n"); } /* -30- */