| 1263 | // be, and if valid, create the file and open it for writing. |
| 1264 | |
| 1265 | flag BeginFileX() |
| 1266 | { |
| 1267 | char sz[cchSzMax]; |
| 1268 | |
| 1269 | if (us.fNoWrite) |
| 1270 | return fFalse; |
| 1271 | #ifdef WIN |
| 1272 | if (gi.szFileOut == NULL) |
| 1273 | return fFalse; |
| 1274 | #endif |
| 1275 | |
| 1276 | #ifndef WIN |
| 1277 | if (gi.szFileOut == NULL && (gs.ft != ftBmp || (gs.ft == ftBmp && |
| 1278 | (gs.chBmpMode == 'B' || gs.chBmpMode == 'P')))) { |
| 1279 | sprintf(sz, "(It is recommended to specify an extension of '.%s'.)\n", |
| 1280 | gs.ft == ftBmp ? (gs.chBmpMode == 'B' ? "bmp" : "png") : |
| 1281 | gs.ft == ftWmf ? "wmf" : (gs.ft == ftSVG ? "svg" : (gs.ft == ftPS ? |
| 1282 | #ifdef PS |
| 1283 | (gs.fPSComplete ? "ps" : "eps") |
| 1284 | #else |
| 1285 | "ps" |
| 1286 | #endif |
| 1287 | : "dw"))); |
| 1288 | PrintSzScreen(sz); |
| 1289 | } |
| 1290 | #endif // WIN |
| 1291 | |
| 1292 | loop { |
| 1293 | #ifndef WIN |
| 1294 | if (gi.szFileOut == NULL) { |
| 1295 | sprintf(sz, "Enter name of file to write %s to", gs.ft == ftBmp ? |
| 1296 | "bitmap" : (gs.ft == ftPS ? "PostScript" : (gs.ft == ftWmf ? |
| 1297 | "metafile" : (gs.ft == ftSVG ? "SVG" : "wireframe")))); |
| 1298 | InputString(sz, sz); |
| 1299 | FCloneSz(sz, &gi.szFileOut); |
| 1300 | } |
| 1301 | #else |
| 1302 | // If autosaving in potentially rapid succession, ensure the file isn't |
| 1303 | // being opened by some other application before saving over it again. |
| 1304 | if (wi.fAutoSave) { |
| 1305 | if (wi.hMutex == NULL) |
| 1306 | wi.hMutex = CreateMutex(NULL, fFalse, szAppName); |
| 1307 | if (wi.hMutex != NULL) |
| 1308 | WaitForSingleObject(wi.hMutex, 1000); |
| 1309 | } |
| 1310 | #endif |
| 1311 | gi.file = fopen(gi.szFileOut, (gs.ft == ftBmp && (gs.chBmpMode == 'B' || |
| 1312 | gs.chBmpMode == 'P')) || gs.ft == ftWmf ? "wb" : "w"); |
| 1313 | if (gi.file != NULL) |
| 1314 | break; |
| 1315 | #ifdef WIN |
| 1316 | if (wi.fAutoSave) |
| 1317 | break; |
| 1318 | #endif |
| 1319 | sprintf(sz, "Couldn't create output file: %s", gi.szFileOut); |
| 1320 | PrintWarning(sz); |
| 1321 | FCloneSz(NULL, &gi.szFileOut); |
| 1322 | #ifdef WIN |
no test coverage detected