How can I modify this function to read from a string instead of a file? glfxin is obviously a FILE object. If I could somehow inject a const char* in to the FILE class, I would be set. Any ideas?
bool glfxParseEffectFromFile( int effect, const char* file )
{
bool retVal=true;
fopen_s(&glfxin, file, "r");
if(glfxin==NULL) {
gEffects[effect]->Log()<<"Cannot open file "<<file<<endl;
gEffects[effect]->Active()=false;
return false;
}
try {
//glfxdebug=1;
gEffect=gEffects[effect];
string fname(file);
size_t lastSlash=fname.find_last_of('/')+1;
size_t lastBackSlash=fname.find_last_of('\\')+1;
lastSlash=max(lastSlash, lastBackSlash);
gEffect->Dir()=fname.substr(0, lastSlash);
glfxrestart(glfxin);
glfxset_lineno(1);
glfxparse();
}
catch(const char* err) {
gEffect->Log()<<err<<endl;
gEffect->Active()=false;
retVal=false;
}
catch(const string& err) {
gEffect->Log()<<err<<endl;
gEffect->Active()=false;
retVal=false;
}
catch(...) {
gEffect->Log()<<"Unknown error occurred during parsing of "<<file<<endl;
gEffect->Active()=false;
retVal=false;
}
fclose(glfxin);
return retVal;
}
On POSIX-compliant sytems, you can use the
fmemopen()function to open a character array as aFILE *object.