/ DeleteIndexFile: Delete DOS/UNIX index file(s) using platform API. */ /
| 247 | /* DeleteIndexFile: Delete DOS/UNIX index file(s) using platform API. */ |
| 248 | /***********************************************************************/ |
| 249 | bool DOSDEF::DeleteIndexFile(PGLOBAL g, PIXDEF pxdf) |
| 250 | { |
| 251 | PCSZ ftype; |
| 252 | char filename[_MAX_PATH]; |
| 253 | bool sep, rc = false; |
| 254 | |
| 255 | if (!To_Indx) |
| 256 | return false; // No index |
| 257 | |
| 258 | // If true indexes are in separate files |
| 259 | sep = GetBoolCatInfo("SepIndex", false); |
| 260 | |
| 261 | if (!sep && pxdf) { |
| 262 | safe_strcpy(g->Message, sizeof(g->Message), MSG(NO_RECOV_SPACE)); |
| 263 | return true; |
| 264 | } // endif sep |
| 265 | |
| 266 | switch (Recfm) { |
| 267 | case RECFM_VAR: ftype = ".dnx"; break; |
| 268 | case RECFM_FIX: ftype = ".fnx"; break; |
| 269 | case RECFM_BIN: ftype = ".bnx"; break; |
| 270 | case RECFM_VCT: ftype = ".vnx"; break; |
| 271 | case RECFM_CSV: ftype = ".cnx"; break; |
| 272 | case RECFM_DBF: ftype = ".dbx"; break; |
| 273 | default: |
| 274 | snprintf(g->Message, sizeof(g->Message), MSG(BAD_RECFM_VAL), Recfm); |
| 275 | return true; |
| 276 | } // endswitch Ftype |
| 277 | |
| 278 | /*********************************************************************/ |
| 279 | /* Check for existence of an index file. */ |
| 280 | /*********************************************************************/ |
| 281 | if (sep) { |
| 282 | // Indexes are save in separate files |
| 283 | #if defined(_WIN32) |
| 284 | char drive[_MAX_DRIVE]; |
| 285 | #else |
| 286 | char *drive = NULL; |
| 287 | #endif |
| 288 | char direc[_MAX_DIR]; |
| 289 | char fname[_MAX_FNAME]; |
| 290 | bool all = !pxdf; |
| 291 | |
| 292 | if (all) |
| 293 | pxdf = To_Indx; |
| 294 | |
| 295 | for (; pxdf; pxdf = pxdf->GetNext()) { |
| 296 | _splitpath(Ofn, drive, direc, fname, NULL); |
| 297 | safe_strcat(fname, sizeof(fname), "_"); |
| 298 | safe_strcat(fname, sizeof(fname), pxdf->GetName()); |
| 299 | _makepath(filename, drive, direc, fname, ftype); |
| 300 | PlugSetPath(filename, filename, GetPath()); |
| 301 | #if defined(_WIN32) |
| 302 | if (!DeleteFile(filename)) |
| 303 | rc |= (GetLastError() != ERROR_FILE_NOT_FOUND); |
| 304 | #else // UNIX |
| 305 | if (remove(filename)) |
| 306 | rc |= (errno != ENOENT); |
no test coverage detected