diff options
author | B. Watson <urchlay@slackware.uk> | 2022-11-12 03:02:10 -0500 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2022-11-12 03:02:10 -0500 |
commit | af9405654fa3978308b05264881fd5c55486ce36 (patch) | |
tree | 33170dba03609cb7b9af4b255953510765743f37 | |
parent | ac68e0e071c194ce127afaa711298dd0bc0d5f92 (diff) | |
download | dla-asm-af9405654fa3978308b05264881fd5c55486ce36.tar.gz |
dla2csv.xex: Add "Exit program?" option when user enters an empty filename.
-rw-r--r-- | dla2csv.c | 76 | ||||
-rw-r--r-- | dla2csv.xex | bin | 10885 -> 10948 bytes |
2 files changed, 47 insertions, 29 deletions
@@ -89,15 +89,20 @@ void disable_break() { } /* no-op */ /* Read a string from stdin (E: on the Atari). Exit on EOF (or Break key on the Atari, except we disable it). - On DOS 2.0S, we end up back at the DUP menu... but - SpartaDOS 3.2d locks up with a black screen. So don't - suggest using this... + On Linux, EOF is the ^D character, and this works. + On the Atari, EOF is ^3... On DOS 2.0S, we end up back at the DUP + menu... but SpartaDOS 3.2d locks up with a black screen. So don't + document ctrl-3 as a way to exit the program (too bad), and just + hope the user never presses it. */ void readstring(void) { char *result; memset(stringbuf, 0, STRINGBUF_SIZE); result = fgets(stringbuf, STRINGBUF_SIZE - 1, stdin); - if(result == NULL) exit(1); + if(result == NULL) { + enable_break(); + exit(1); + } } #ifdef __ATARI__ @@ -136,6 +141,29 @@ void show_dir(char drive) { } #endif +int prompt_yn(char *prompt, int default_y) { + char *yn = "y/N"; + if(default_y) yn = "Y/n"; + + printf("%s[%s]? ", prompt, yn); + fflush(stdout); + readstring(); + + switch(stringbuf[0]) { + case 'y': + case 'Y': + return 1; + break; + case 'n': + case 'N': + return 0; + break; + default: + break; + } + return default_y; +} + /* Prompt for a filename, try to open it. If there's an error, show error message and retry. Will not return until it opens the file. */ @@ -147,7 +175,13 @@ FILE *prompt_filename(const char *name, const char *mode) { fflush(stdout); readstring(); stringbuf[strlen(stringbuf) - 1] = '\0'; /* kill trailing \n */ - if(strlen(stringbuf) == 0) continue; + if(strlen(stringbuf) == 0) { + if(prompt_yn("Exit program", 0)) { + enable_break(); + exit(0); + } + continue; + } #ifdef __ATARI__ /* if the user enters a single digit, show directory of that drive. */ if(isdigit(stringbuf[0])) { @@ -169,29 +203,6 @@ FILE *prompt_filename(const char *name, const char *mode) { return f; } -int prompt_yn(char *prompt, int default_y) { - char *yn = "y/N"; - if(default_y) yn = "Y/n"; - - printf("%s[%s]? ", prompt, yn); - fflush(stdout); - readstring(); - - switch(stringbuf[0]) { - case 'y': - case 'Y': - return 1; - break; - case 'n': - case 'N': - return 0; - break; - default: - break; - } - return default_y; -} - /* Prompt for and read EOL type, retry if needed. Will not return until a valid number was entered. */ char *prompt_eol(void) { @@ -235,6 +246,11 @@ int main(int argc, char **argv) { POKE 702,64 */ *((char *)0x02be) = 0x40; + /* also, cc65 sets APPMHI to $bc1f (last byte before the GR.0 + display list). which causes the atari to lock up when Reset + is pressed. I can't believe this is useful behaviour... */ + *((int *)0x0e) = 0; + /* clear the screen */ putchar(0x7d); #endif @@ -370,6 +386,8 @@ int main(int argc, char **argv) { } if(!prompt_yn("\nConvert another file", 1)) - return 0; + break; } + enable_break(); + exit(0); } diff --git a/dla2csv.xex b/dla2csv.xex Binary files differindex 8bb40ee..6382173 100644 --- a/dla2csv.xex +++ b/dla2csv.xex |