MCPcopy Create free account
hub / github.com/TASEmulators/fceux / LoadFM2

Function LoadFM2

src/movie.cpp:646–761  ·  view source on GitHub ↗

yuck... another custom text parser.

Source from the content-addressed store, hash-verified

644
645//yuck... another custom text parser.
646bool 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;

Callers 9

FCEUI_LoadMovieFunction · 0.85
FCEUMOV_ReadStateFunction · 0.85
FCEUI_MovieGetInfoFunction · 0.85
importInputDataFunction · 0.85
loadMethod · 0.85
fceuWrapperInitFunction · 0.85
loadMethod · 0.85
importMovieFileMethod · 0.85
mainFunction · 0.85

Calls 10

FCEU_PrintErrorFunction · 0.85
LoadFM2_binarychunkFunction · 0.85
freadMethod · 0.80
failMethod · 0.80
installValueMethod · 0.80
ftellMethod · 0.45
fseekMethod · 0.45
fgetcMethod · 0.45
sizeMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected