void Compile(const char *fn, char *stringsource, bool parsedump, bool disasm, bool verbose) { Parser parser(fn, st, stringsource); parser.Parse(); if (parsedump) { FILE *f = OpenForWriting("parsedump.txt", false); if (f) { fprintf(f, "%s\n", parser.Dump().c_str()); fclose(f); } } CodeGen cg(parser, st, code, linenumbers, verbose); if (disasm) { FILE *f = OpenForWriting("disasm.txt", false); if (f) { DisAsm(f, st, &code[0], linenumbers, (int)code.size()); fclose(f); } } //parserpool->printstats(); }
STARTDECL(write_file) (Value &file, Value &contents) { FILE *f = OpenForWriting(file.sval->str(), true); file.DEC(); size_t written = 0; if (f) { written = fwrite(contents.sval->str(), contents.sval->len, 1, f); fclose(f); } contents.DEC(); return Value(written == 1); }
void Save(const char *bcf) { Serializer ser(NULL); st.Serialize(ser, code, linenumbers); vector<uint> out; WEntropyCoder(ser.wbuf, out); FILE *f = OpenForWriting(bcf, true); if (f) { fwrite(fileheader, 4, 1, f); fwrite(out.data(), out.size(), sizeof(uint), f); fclose(f); } }
/* Used only by RageFile: */ RageFileObj *RageFileManager::Open( CString sPath, int mode, RageFile &p, int &err ) { LockMut( *g_Mutex ); err = ENOENT; if( (mode & RageFile::WRITE) && PathUsesSlowFlush(sPath) ) mode |= RageFile::SLOW_FLUSH; /* If writing, we need to do a heuristic to figure out which driver to write with--there * may be several that will work. */ if( mode & RageFile::WRITE ) return OpenForWriting( sPath, mode, p, err ); NormalizePath( sPath ); for( unsigned i = 0; i < g_Drivers.size(); ++i ) { LoadedDriver &ld = g_Drivers[i]; const CString path = ld.GetPath( sPath ); if( path.size() == 0 ) continue; int error; RageFileObj *ret = ld.driver->Open( path, mode, p, error ); if( ret ) { AddReference( ret, ld.driver ); return ret; } /* ENOENT (File not found) is low-priority: if some other error * was reported, return that instead. */ if( error != ENOENT ) err = error; } return NULL; }