#include #include #include #include #include static TMError _from_file(TMDisclosureFramework self,TM tm, const char *filename,TMModel *mp); extern TMModel tm_create_tma_from_file(TMDisclosureFramework df,TM tm,FILE *file); static TMError lookup_model(TMDisclosureFramework self,TM tm,const char *name,TMModel *mp) { TMError e; char *p; char filename[1024]; /* FIXME */ p = (char*)tm_model_dict_lookup(tm,name); if(p) { strncpy(filename,p,sizeof(filename)); } else { if( strstr(name,"file://") == name) { snprintf(filename,sizeof(filename),"%s",name+7); } else { tm_set_error(tm,"cannot find model named %s" ,name); return TM_FAIL; } } if( (e = _from_file(self,tm,filename,mp)) != TM_OK) return e; return TM_OK; } struct TMDisclosureFramework www_df = { "www-df", lookup_model /* lookup_procmodel */ }; TMError _from_file(TMDisclosureFramework self,TM tm, const char *filename,TMModel *mp) { TMModel model; FILE *f; model = NULL; #if 0 char buf[1024]; char name_with_slashes[1024]; char *tmtk_home; char *p; tmtk_home = getenv("TMTK_HOME"); assert(sizeof(name_with_slashes) > strlen(name)); /* FIXME need a lot of work on all this here! */ strcpy(name_with_slashes,name); for(p=name_with_slashes;*p;p++) { if(*p == '.') *p = '/'; } /* FIXME: handle possible / at end of path although it is no problem */ /* FIXME: check TMTK envvar also, propably make PATH */ /* sprintf(buf,"%s/%s.xml", tmtk_home ? tmtk_home : "./" , name_with_slashes); */ /* PREFIX is determined by configure and compiled in */ sprintf(buf,"%s/tmtk/tma/%s.xml", PREFIX , name_with_slashes); #endif if( (f = fopen(filename,"r")) == NULL) { tm_set_error(tm, "cannot open %s, %s\n",filename,strerror(errno)); return TM_FAIL; } if( (model = tm_create_tma_from_file(self,tm,f)) == NULL) { return TM_FAIL; } fclose(f); *mp = model; return TM_OK; }