src/tools/chdcd.c
| r12668 | r12669 | |
| 37 | 37 | IMPLEMENTATION |
| 38 | 38 | ***************************************************************************/ |
| 39 | 39 | |
| 40 | static astring get_file_path(astring &path) |
| 41 | { |
| 42 | int pos = path.rchr( 0, '\\'); |
| 43 | if (pos!=-1) { |
| 44 | path = path.substr(0,pos+1); |
| 45 | } else { |
| 46 | pos = path.rchr( 0, '/'); |
| 47 | path = path.substr(0,pos+1); |
| 48 | } |
| 49 | return path; |
| 50 | } |
| 40 | 51 | /*------------------------------------------------- |
| 41 | 52 | get_file_size - get the size of a file |
| 42 | 53 | -------------------------------------------------*/ |
| r12668 | r12669 | |
| 300 | 311 | UINT32 chain_offs, chunk_size; |
| 301 | 312 | int done = 0; |
| 302 | 313 | |
| 303 | | infile = fopen(tocfname, "rt"); |
| 314 | astring path = astring(tocfname); |
| 304 | 315 | |
| 316 | infile = fopen(tocfname, "rt"); |
| 317 | path = get_file_path(path); |
| 318 | |
| 305 | 319 | if (infile == (FILE *)NULL) |
| 306 | 320 | { |
| 307 | 321 | return CHDERR_FILE_NOT_FOUND; |
| r12668 | r12669 | |
| 374 | 388 | index2 = read_uint64(infile); |
| 375 | 389 | |
| 376 | 390 | // printf("Track %d: sector size %d mode %x index0 %llx index1 %llx index2 %llx (pregap %d sectors, length %d sectors)\n", track, size, mode, index0, index1, index2, (UINT32)(index1-index0)/size, (UINT32)(index2-index1)/size); |
| 377 | | |
| 378 | | strcpy(outinfo->fname[track-1], tocfname); |
| 391 | strncpy(outinfo->fname[track-1], path.cstr(), 256); |
| 392 | strncat(outinfo->fname[track-1], tocfname, 256); |
| 379 | 393 | outinfo->offset[track-1] = offset + (UINT32)(index1-index0); |
| 380 | 394 | outinfo->idx0offs[track-1] = 0; |
| 381 | 395 | outinfo->idx1offs[track-1] = 0; |
| r12668 | r12669 | |
| 444 | 458 | int i, numtracks; |
| 445 | 459 | //int chdpos=0; |
| 446 | 460 | |
| 447 | | infile = fopen(tocfname, "rt"); |
| 461 | astring path = astring(tocfname); |
| 448 | 462 | |
| 463 | infile = fopen(tocfname, "rt"); |
| 464 | path = get_file_path(path); |
| 465 | |
| 449 | 466 | if (infile == (FILE *)NULL) |
| 450 | 467 | { |
| 451 | 468 | return CHDERR_FILE_NOT_FOUND; |
| r12668 | r12669 | |
| 508 | 525 | outtoc->tracks[trknum].datasize=2352; |
| 509 | 526 | } |
| 510 | 527 | |
| 511 | | tok=strtok(NULL," "); |
| 512 | | strcpy(&(outinfo->fname[trknum][0]),tok); |
| 528 | astring name; |
| 529 | |
| 530 | tok=strtok(NULL," "); |
| 531 | name = tok; |
| 532 | if (tok[0]=='"') { |
| 533 | do { |
| 534 | tok=strtok(NULL," "); |
| 535 | if (tok!=NULL) { |
| 536 | name += " "; |
| 537 | name += tok; |
| 538 | } |
| 539 | } while(tok!=NULL && (strrchr(tok,'"')-tok !=(strlen(tok)-1))); |
| 540 | name = name.delchr('"'); |
| 541 | } |
| 542 | strncpy(outinfo->fname[trknum], path.cstr(), 256); |
| 543 | strncat(outinfo->fname[trknum], name, 256); |
| 544 | |
| 513 | 545 | sz=get_file_size(outinfo->fname[trknum]); |
| 514 | 546 | |
| 515 | 547 | outtoc->tracks[trknum].frames=sz/trksize; |
| r12668 | r12669 | |
| 557 | 589 | FILE *infile; |
| 558 | 590 | int i, trknum; |
| 559 | 591 | static char token[128]; |
| 560 | | static char lastfname[128]; |
| 592 | static char lastfname[256]; |
| 561 | 593 | UINT32 wavlen, wavoffs; |
| 594 | astring path = astring(tocfname); |
| 562 | 595 | |
| 563 | | infile = fopen(tocfname, "rt"); |
| 564 | | |
| 596 | infile = fopen(tocfname, "rt"); |
| 597 | path = get_file_path(path); |
| 565 | 598 | if (infile == (FILE *)NULL) |
| 566 | 599 | { |
| 567 | 600 | return CHDERR_FILE_NOT_FOUND; |
| r12668 | r12669 | |
| 592 | 625 | TOKENIZE |
| 593 | 626 | |
| 594 | 627 | /* keep the filename */ |
| 595 | | strncpy(lastfname, token, 128); |
| 628 | strncpy(lastfname, path.cstr(), 256); |
| 629 | strncat(lastfname, token, 256); |
| 596 | 630 | |
| 597 | 631 | /* get the file type */ |
| 598 | 632 | TOKENIZE |
| r12668 | r12669 | |
| 654 | 688 | outtoc->tracks[trknum].pregap = 0; |
| 655 | 689 | outinfo->idx0offs[trknum] = -1; |
| 656 | 690 | outinfo->idx1offs[trknum] = 0; |
| 657 | | strcpy(&outinfo->fname[trknum][0], lastfname); // default filename to the last one |
| 691 | |
| 692 | strncpy(outinfo->fname[trknum], lastfname, 256); // default filename to the last one |
| 658 | 693 | // printf("trk %d: fname %s offset %d\n", trknum, &outinfo->fname[trknum][0], outinfo->offset[trknum]); |
| 659 | 694 | |
| 660 | 695 | cdrom_convert_type_string_to_track_info(token, &outtoc->tracks[trknum]); |
| r12668 | r12669 | |
| 832 | 867 | return chdcd_parse_nero(tocfname, outtoc, outinfo); |
| 833 | 868 | } |
| 834 | 869 | |
| 835 | | infile = fopen(tocfname, "rt"); |
| 870 | astring path = astring(tocfname); |
| 836 | 871 | |
| 872 | infile = fopen(tocfname, "rt"); |
| 873 | path = get_file_path(path); |
| 874 | |
| 837 | 875 | if (infile == (FILE *)NULL) |
| 838 | 876 | { |
| 839 | 877 | return CHDERR_FILE_NOT_FOUND; |
| r12668 | r12669 | |
| 865 | 903 | TOKENIZE |
| 866 | 904 | |
| 867 | 905 | /* keep the filename */ |
| 868 | | strncpy(&outinfo->fname[trknum][0], token, strlen(token)); |
| 906 | strncpy(outinfo->fname[trknum], path.cstr(), 256); |
| 907 | strncat(outinfo->fname[trknum], token, 256); |
| 869 | 908 | |
| 870 | 909 | /* get either the offset or the length */ |
| 871 | 910 | TOKENIZE |