如何修改此函数以从字符串而不是文件中读取?glfxin 显然是一个 FILE 对象。如果我能以某种方式将 const char* 注入到 FILE 类中,我就会被设置。有任何想法吗?
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;
}