yuck... another custom text parser.
| 644 | |
| 645 | //yuck... another custom text parser. |
| 646 | bool LoadFM2(MovieData& movieData, EMUFILE* fp, int size, bool stopAfterHeader) |
| 647 | { |
| 648 | // if there's no "binary" tag in the movie header, consider it as a movie in text format |
| 649 | movieData.binaryFlag = false; |
| 650 | // Non-TASEditor projects consume until EOF |
| 651 | movieData.loadFrameCount = -1; |
| 652 | |
| 653 | std::ios::pos_type curr = fp->ftell(); |
| 654 | |
| 655 | if (!stopAfterHeader) |
| 656 | { |
| 657 | // first, look for an fcm signature |
| 658 | char fcmbuf[3]; |
| 659 | fp->fread(fcmbuf,3); |
| 660 | fp->fseek(curr,SEEK_SET); |
| 661 | if(!strncmp(fcmbuf,"FCM",3)) { |
| 662 | FCEU_PrintError("FCM File format is no longer supported. Please use Tools > Convert FCM"); |
| 663 | return false; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | //movie must start with "version 3" |
| 668 | char buf[9]; |
| 669 | curr = fp->ftell(); |
| 670 | fp->fread(buf,9); |
| 671 | fp->fseek(curr,SEEK_SET); |
| 672 | if(fp->fail()) return false; |
| 673 | if(memcmp(buf,"version 3",9)) |
| 674 | return false; |
| 675 | |
| 676 | std::string key,value; |
| 677 | enum { |
| 678 | NEWLINE, KEY, SEPARATOR, VALUE, RECORD, COMMENT, SUBTITLE |
| 679 | } state = NEWLINE; |
| 680 | bool bail = false; |
| 681 | bool iswhitespace, isrecchar, isnewline; |
| 682 | int c; |
| 683 | for(;;) |
| 684 | { |
| 685 | if(size--<=0) goto bail; |
| 686 | c = fp->fgetc(); |
| 687 | if(c == -1) |
| 688 | goto bail; |
| 689 | iswhitespace = (c==' '||c=='\t'); |
| 690 | isrecchar = (c=='|'); |
| 691 | isnewline = (c==10||c==13); |
| 692 | if(isrecchar && movieData.binaryFlag && !stopAfterHeader) |
| 693 | { |
| 694 | LoadFM2_binarychunk(movieData, fp, size); |
| 695 | return true; |
| 696 | } else if (isnewline && static_cast<size_t>(movieData.loadFrameCount) == movieData.records.size()) |
| 697 | // exit prematurely if loaded the specified amound of records |
| 698 | return true; |
| 699 | switch(state) |
| 700 | { |
| 701 | case NEWLINE: |
| 702 | if(isnewline) goto done; |
| 703 | if(iswhitespace) goto done; |
no test coverage detected