Buffer * renderFrame(Buffer *Cbuf, int force_reload) { Str tmp; FILE *f; Buffer *buf; int flag; struct frameset *fset; #ifdef USE_M17N wc_ces doc_charset = DocumentCharset; #endif tmp = tmpfname(TMPF_FRAME, ".html"); f = fopen(tmp->ptr, "w"); if (f == NULL) return NULL; /* * if (Cbuf->frameQ != NULL) fset = Cbuf->frameQ->frameset; else */ fset = Cbuf->frameset; if (fset == NULL || createFrameFile(fset, f, Cbuf, 0, force_reload) < 0) return NULL; fclose(f); flag = RG_FRAME; if ((Cbuf->currentURL).is_nocache) flag |= RG_NOCACHE; renderFrameSet = Cbuf->frameset; flushFrameSet(renderFrameSet); #ifdef USE_M17N DocumentCharset = InnerCharset; #endif buf = loadGeneralFile(tmp->ptr, NULL, NULL, flag, NULL); #ifdef USE_M17N DocumentCharset = doc_charset; #endif renderFrameSet = NULL; if (buf == NULL || buf == NO_BUFFER) return NULL; buf->sourcefile = tmp->ptr; #ifdef USE_M17N buf->document_charset = Cbuf->document_charset; #endif copyParsedURL(&buf->currentURL, &Cbuf->currentURL); preFormUpdateBuffer(buf); return buf; }
static void writeLocalCookie() { FILE *f; if (no_rc_dir) return; if (Local_cookie_file) return; Local_cookie_file = tmpfname(TMPF_COOKIE, NULL)->ptr; set_environ("LOCAL_COOKIE_FILE", Local_cookie_file); f = fopen(Local_cookie_file, "wb"); if (!f) return; localCookie(); fwrite(Local_cookie->ptr, sizeof(char), Local_cookie->length, f); fclose(f); chmod(Local_cookie_file, S_IRUSR | S_IWUSR); }
virtual bool SetPatchset(const char *sfont) { if(UsingSTDIO) { int newid = fluid_synth_sfload(fluidSynth, sfont, true); if(newid == FLUID_FAILED) { SetError("Failed to load soundfont"); return false; } if(fontID != FLUID_FAILED) fluid_synth_sfunload(fluidSynth, fontID, true); fontID = newid; doFontLoad = false; return true; } /* FluidSynth has no way to load a soundfont using IO callbacks. So we * have to copy the specified file using the callbacks to a regular * file that FluidSynth can open. */ int newid = FLUID_FAILED; InStream istream(sfont); if(istream.fail()) { SetError("Failed to open file"); return false; } /* First, get a temp filename */ const char *str = getenv("TEMP"); if(!str || !str[0]) str = getenv("TMP"); #ifdef _WIN32 if(!str || !str[0]) str = "."; #else if(!str || !str[0]) str = "/tmp"; #endif std::string fname = str; fname += "/alure-sfont-XXXXXX"; for(size_t i = 0;i < fname.size();i++) { if(fname[i] == '\\') fname[i] = '/'; } std::vector<char> tmpfname(fname.begin(), fname.end()); tmpfname.push_back(0); /* Open a temp file */ int fd = -1; FILE *file; #ifdef _WIN32 if(mktemp(&tmpfname[0]) == NULL || (file=fopen(&tmpfname[0], "wb")) == NULL) #else if((fd=mkstemp(&tmpfname[0])) == -1 || (file=fdopen(fd, "wb")) == NULL) #endif { if(fd >= 0) { close(fd); remove(&tmpfname[0]); } SetError("Failed to create temp file"); return false; } bool copyok = false; char buf[4096]; size_t got; do { istream.read(buf, sizeof(buf)); if((got=istream.gcount()) == 0) { copyok = true; break; } } while(fwrite(buf, 1, got, file) == got); if(copyok) { fflush(file); newid = fluid_synth_sfload(fluidSynth, &tmpfname[0], true); } fclose(file); remove(&tmpfname[0]); if(!copyok) { SetError("Failed to copy file"); return false; } if(newid == FLUID_FAILED) { SetError("Failed to load soundfont"); return false; } if(fontID != FLUID_FAILED) fluid_synth_sfunload(fluidSynth, fontID, true); fontID = newid; doFontLoad = false; return true; }
void _updateDataFile() { //char *datfname = (char*)"datafile.dat"; char *tmpdatfname = tmpfname(datfname); ProgramData *programData = newProgramData(); int i, res; if(!readDataFile(datfname, programData, 1)) { /* datafile exists, update */ if(programData->version != _instrumentationInfo->id) { fprintf(stderr, "Data corruption reading file:\n"); fprintf(stderr, " Invalid instrumentation version of existing datafile.\n"); fprintf(stderr, " Remove or rename datafile and try again.\n"); abort(); } programData->passFail = realloc(programData->passFail, (programData->nRuns+_instrumentationInfo->run+1) * sizeof(char)); for(i=0; i<(int)_instrumentationInfo->run; i++) { programData->passFail[programData->nRuns+i] = _instrumentationInfo->passFail[i]; } programData->nRuns+=_instrumentationInfo->run; programData->passFail[programData->nRuns] = 0; for(i=0; i<MAX_SPECTRA; i++) { int comps = programData->spectrum[i].nComponents; programData->spectrum[i].data = (unsigned int*)realloc(programData->spectrum[i].data, comps * programData->nRuns * sizeof(unsigned int)); if(comps > 0) { int r; for(r=0; r<(int)_instrumentationInfo->run; r++) { int c; int pdRun = programData->nRuns - _instrumentationInfo->run + r; for(c=0; c<comps; c++) { programData->spectrum[i].data[pdRun*comps + c] = SPECTRUM(i).data[r*comps + c]; } } } } for(i=0; i<MAX_INVARIANTTYPES; i++) { int invs = programData->invariantType[i].nInvariants; int inv; for(inv=0; inv<invs; inv++) { programData->invariantType[i].data[inv] = INVARIANTTYPE(i).data[inv]; } } /* write data */ res = writeDataFile(tmpdatfname, programData); if(res) { fprintf(stderr, "Error writing datafile: res=%d\n", res); } else { if(remove(datfname)) { fprintf(stderr, "Error removing outdated datafile '%s'\n", datfname); fprintf(stderr, "New datafile is stored in '%s'\n", tmpdatfname); } else if(rename(tmpdatfname, datfname)) { fprintf(stderr, "Error renaming temporary datafile '%s' to '%s'\n", tmpdatfname, datfname); fprintf(stderr, "New datafile is stored in '%s'\n", tmpdatfname); } else { } } } else { /* no datafile exists, create */ programData->version = _instrumentationInfo->id; programData->opMode = 0; programData->nRuns = _instrumentationInfo->run; programData->passFail = calloc(_instrumentationInfo->run+1, sizeof(char)); for(i=0; i<(int)_instrumentationInfo->run; i++) { programData->passFail[i] = _instrumentationInfo->passFail[i]; } for(i=0; i<MAX_SPECTRA; i++) { int comps = SPECTRUM(i).nComponents; programData->spectrum[i] = SPECTRUM(i); programData->spectrum[i].data = (unsigned int*)calloc(comps * programData->nRuns, sizeof(unsigned int)); if(comps > 0) { int r; for(r=0; r<(int)_instrumentationInfo->run; r++) { int c; int pdRun = programData->nRuns - _instrumentationInfo->run + r; for(c=0; c<comps; c++) { programData->spectrum[i].data[pdRun*comps + c] = SPECTRUM(i).data[r*comps + c]; } } } } for(i=0; i<MAX_INVARIANTTYPES; i++) { int invs = INVARIANTTYPE(i).nInvariants; int inv; programData->invariantType[i] = INVARIANTTYPE(i); programData->invariantType[i].name = (char*)calloc(strlen(INVARIANTTYPE(i).name)+1, sizeof(char)); strcpy(programData->invariantType[i].name, INVARIANTTYPE(i).name); programData->invariantType[i].data = (_Invariant*)calloc(invs, sizeof(_Invariant)); for(inv=0; inv<invs; inv++) { programData->invariantType[i].data[inv] = INVARIANTTYPE(i).data[inv]; } } res = writeDataFile(tmpdatfname, programData); if(res) { fprintf(stderr, "Error writing datafile: res=%d\n", res); } else { if(rename(tmpdatfname, datfname)) { fprintf(stderr, "Error renaming temporary datafile '%s' to '%s'\n", tmpdatfname, datfname); fprintf(stderr, "New datafile is stored in '%s'\n", tmpdatfname); } else { } } } free(tmpdatfname); freeProgramData(programData); }