Mercurial > hg > early-roguelike
comparison arogue7/save.c @ 128:c697782a9b37
arogue7: implement the -n option.
| author | John "Elwin" Edwards |
|---|---|
| date | Mon, 11 May 2015 16:46:00 -0400 |
| parents | b786053d2f37 |
| children | 89deb1197a2d |
comparison
equal
deleted
inserted
replaced
| 127:8ae3ffd6c6e7 | 128:c697782a9b37 |
|---|---|
| 61 * get file name | 61 * get file name |
| 62 */ | 62 */ |
| 63 mpos = 0; | 63 mpos = 0; |
| 64 if (file_name[0] != '\0') | 64 if (file_name[0] != '\0') |
| 65 { | 65 { |
| 66 msg("Save file (%s)? ", file_name); | 66 if (use_savedir) |
| 67 msg("Save game? "); | |
| 68 else | |
| 69 msg("Save file (%s)? ", file_name); | |
| 67 do | 70 do |
| 68 { | 71 { |
| 69 c = readchar(); | 72 c = readchar(); |
| 70 if (c == ESCAPE) return(0); | 73 if (c == ESCAPE) return(0); |
| 71 } while (c != 'n' && c != 'N' && c != 'y' && c != 'Y'); | 74 } while (c != 'n' && c != 'N' && c != 'y' && c != 'Y'); |
| 75 msg("File name: %s", file_name); | 78 msg("File name: %s", file_name); |
| 76 goto gotfile; | 79 goto gotfile; |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 | 82 |
| 83 if (use_savedir) | |
| 84 { | |
| 85 msg(""); | |
| 86 return FALSE; | |
| 87 } | |
| 88 | |
| 80 do | 89 do |
| 81 { | 90 { |
| 82 msg("File name: "); | 91 msg("File name: "); |
| 83 mpos = 0; | 92 mpos = 0; |
| 84 buf[0] = '\0'; | 93 buf[0] = '\0'; |
| 88 return FALSE; | 97 return FALSE; |
| 89 } | 98 } |
| 90 strcpy(file_name, buf); | 99 strcpy(file_name, buf); |
| 91 gotfile: | 100 gotfile: |
| 92 if ((savefd = open(file_name, O_WRONLY|O_CREAT|O_TRUNC,0666)) < 0) | 101 if ((savefd = open(file_name, O_WRONLY|O_CREAT|O_TRUNC,0666)) < 0) |
| 102 { | |
| 93 msg(strerror(errno)); /* fake perror() */ | 103 msg(strerror(errno)); /* fake perror() */ |
| 104 if (use_savedir) | |
| 105 return FALSE; | |
| 106 } | |
| 94 } while (savefd < 0); | 107 } while (savefd < 0); |
| 95 | 108 |
| 96 /* | 109 /* |
| 97 * write out encrpyted file (after a stat) | 110 * write out encrpyted file (after a stat) |
| 98 */ | 111 */ |
| 166 | 179 |
| 167 if (strcmp(file, "-r") == 0) | 180 if (strcmp(file, "-r") == 0) |
| 168 file = file_name; | 181 file = file_name; |
| 169 if ((inf = open(file, 0)) < 0) | 182 if ((inf = open(file, 0)) < 0) |
| 170 { | 183 { |
| 184 if (use_savedir && errno == ENOENT) | |
| 185 { | |
| 186 return TRUE; | |
| 187 } | |
| 171 perror(file); | 188 perror(file); |
| 172 return FALSE; | 189 return FALSE; |
| 173 } | 190 } |
| 174 | 191 |
| 175 fflush(stdout); | 192 fflush(stdout); |
