// uninit driver static void uninit(sh_video_t *sh) { vd_xanim_ctx *priv = sh->context; int i; void (*close_func)(void); for (i=0; i < XA_CLOSE_FUNCS; i++) if (xa_close_func[i]) { close_func = xa_close_func[i]; close_func(); } dlclose(priv->file_handler); free(priv->decinfo); free(priv); }
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { struct LexState lexstate; struct FuncState funcstate; lexstate.buff = buff; luaX_setinput(L, &lexstate, z, luaS_new(L, name)); open_func(&lexstate, &funcstate); funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ luaX_next(&lexstate); /* read first token */ chunk(&lexstate); check(&lexstate, TK_EOS); close_func(&lexstate); lua_assert(funcstate.prev == NULL); lua_assert(funcstate.f->nups == 0); lua_assert(lexstate.fs == NULL); return funcstate.f; }
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff) { struct LexState lexstate; struct FuncState funcstate; lexstate.buff = buff; lexstate.nestlevel = 0; luaX_setinput(L, &lexstate, z, luaS_new(L, zname(z))); open_func(&lexstate, &funcstate); next(&lexstate); /* read first token */ chunk(&lexstate); check_condition(&lexstate, (lexstate.t.token == TK_EOS), "<eof> expected"); close_func(&lexstate); lua_assert(funcstate.prev == NULL); lua_assert(funcstate.f->nups == 0); lua_assert(lexstate.nestlevel == 0); return funcstate.f; }
static struct rldb_plugin_cnts * open_func( struct rldb_plugin_data *data, struct runlog_state *rl_state, const struct ejudge_cfg *config, const struct contest_desc *cnts, const struct section_global_data *global, int flags, time_t init_duration, time_t init_sched_time, time_t init_finish_time) { struct rldb_file_state *state = (struct rldb_file_state*) data; struct rldb_file_cnts *cs = 0; path_t runlog_path; ASSERT(state); XCALLOC(cs, 1); cs->plugin_state = state; state->nref++; cs->rl_state = rl_state; cs->run_fd = -1; runlog_path[0] = 0; if (global && global->run_log_file[0]) { snprintf(runlog_path, sizeof(runlog_path), "%s", global->run_log_file); } if (!runlog_path[0] && cnts && cnts->root_dir) { snprintf(runlog_path, sizeof(runlog_path), "%s/var/run.log", cnts->root_dir); } if (!runlog_path[0]) { err("`run_log_file' is undefined"); goto fail; } cs->runlog_path = xstrdup(runlog_path); if (do_run_open(cs, runlog_path, flags, init_duration, init_sched_time, init_finish_time) < 0) goto fail; return (struct rldb_plugin_cnts*) cs; fail: close_func((struct rldb_plugin_cnts*) cs); return 0; }
static void body (LexState *ls, expdesc *e, int needself, int line) { /* body -> `(' parlist `)' chunk END */ #ifdef LUA_UTILITIES_NET char szFuncName1[256]; char szFuncName2[256]; #endif FuncState new_fs; open_func(ls, &new_fs); new_fs.f->linedefined = line; #ifdef LUA_UTILITIES_NET szFuncName1[0] = 0; szFuncName2[0] = 0; TryGetFunctionName(ls->t.seminfo.ts, szFuncName1, 256); #endif checknext(ls, '('); if (needself) { new_localvarliteral(ls, "self", 0); adjustlocalvars(ls, 1); } parlist(ls); checknext(ls, ')'); chunk(ls); #ifdef LUA_UTILITIES_NET if (szFuncName1[0] == 0) TryGetFunctionName(ls->t.seminfo.ts, szFuncName2, 256); #endif new_fs.f->lastlinedefined = ls->linenumber; check_match(ls, TK_END, TK_FUNCTION, line); close_func(ls); #ifdef LUA_UTILITIES_NET // Use the correct function name based on values obtained if (szFuncName1[0] == 0) GetFunction(szFuncName2, ls, new_fs.f); else GetFunction(szFuncName1, ls, new_fs.f); #endif pushclosure(ls, &new_fs, e); }
static void body (LexState *ls, expdesc *e, int needself, int line) { /* body -> `(' parlist `)' chunk END */ FuncState new_fs; open_func(ls, &new_fs); new_fs.f->linedefined = line; checknext(ls, '('); if (needself) { new_localvarliteral(ls, "self", 0); adjustlocalvars(ls, 1); } parlist(ls); checknext(ls, ')'); chunk(ls); new_fs.f->lastlinedefined = ls->linenumber; check_match(ls, TK_END, TK_FUNCTION, line); close_func(ls); pushclosure(ls, &new_fs, e); }
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { struct LexState lexstate; struct FuncState *pfuncstate = (struct FuncState*)malloc(sizeof(struct FuncState)); Proto *res; lexstate.buff = buff; luaX_setinput(L, &lexstate, z, luaS_new(L, name)); open_func(&lexstate, pfuncstate); pfuncstate->f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ luaX_next(&lexstate); /* read first token */ chunk(&lexstate); check(&lexstate, TK_EOS); close_func(&lexstate); lua_assert(pfuncstate->prev == NULL); lua_assert(pfuncstate->f->nups == 0); lua_assert(lexstate.fs == NULL); res = pfuncstate->f; free(pfuncstate); return res; }
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) { struct LexState lexstate; struct FuncState funcstate; TString *tname = luaS_new(L, name); setsvalue2s(L, L->top, tname); /* protect name */ incr_top(L); lexstate.buff = buff; luaX_setinput(L, &lexstate, z, tname); open_func(&lexstate, &funcstate); funcstate.f->is_vararg = VARARG_ISVARARG; /* main func. is always vararg */ luaX_next(&lexstate); /* read first token */ chunk(&lexstate); check(&lexstate, TK_EOS); close_func(&lexstate); L->top--; /* remove 'name' from stack */ lua_assert(funcstate.prev == NULL); lua_assert(funcstate.f->nups == 0); lua_assert(lexstate.fs == NULL); return funcstate.f; }
static struct rldb_plugin_cnts * open_func( struct rldb_plugin_data *data, struct runlog_state *rl_state, const struct ejudge_cfg *config, const struct contest_desc *cnts, const struct section_global_data *global, int flags, time_t init_duration, time_t init_sched_time, time_t init_finish_time) { struct rldb_mysql_state *state = (struct rldb_mysql_state*) data; struct rldb_mysql_cnts *cs = 0; int r; ASSERT(state); XCALLOC(cs, 1); cs->plugin_state = state; state->nref++; cs->rl_state = rl_state; if (cnts) cs->contest_id = cnts->id; if (!cs->contest_id) { err("undefined contest_id"); goto fail; } if (do_open(state) < 0) goto fail; if ((r = load_header(cs, flags, init_duration, init_sched_time, init_finish_time)) < 0) goto fail; if (!r) return (struct rldb_plugin_cnts*) cs; if (load_runs(cs) < 0) goto fail; state->mi->free_res(state->md); return (struct rldb_plugin_cnts*) cs; fail: state->mi->free_res(state->md); close_func((struct rldb_plugin_cnts*) cs); return 0; }
static int write_func (const void *buf, size_t length) { static DWORD block = 0; if (debug_on < 2) debug_on = 2; if (block == 0) { tot_size = 0UL; start = time (NULL); fname = tftp_boot_local_file; fprintf (stderr, "opening `%s'\n", fname); file = fopen (fname, tftp_openmode ? tftp_openmode : "wb"); } if (!file) { perror (fname); return (-1); } #if defined(__DJGPP__) && 0 /* * Look for optional Watt-32 stubinfo in block 4. * If .exe file isn't newer, kill the connection */ if (block == 4 && is_exe && check_timestamp(buf) < our_timestamp) { close_func(); return (-1); } #endif if (fwrite (buf, 1, length, file) < length) return (-1); tot_size += length; block++; return (0); }
static void ThreadDecodeSub( PLUGINWORK *pPluginWork ) { static ov_callbacks callbacks = {read_func, seek_func, close_func, tell_func}; ULONG ulTmp; HFILE stream; ULONG ulAction; pPluginWork->jumpto = -1; pPluginWork->fStop = FALSE; pPluginWork->fTerminate = FALSE; pPluginWork->ffwd = FALSE; pPluginWork->rew = FALSE; pPluginWork->lRemain = 0; pPluginWork->lOffset = 0; DosWaitEventSem( pPluginWork->hevThreadTrigger, SEM_INDEFINITE_WAIT ); DosResetEventSem( pPluginWork->hevThreadTrigger, &ulTmp ); if(pPluginWork->fTerminate) { return; } pPluginWork->fStatus = DECODER_STARTING; DosOpen( pPluginWork->szFileName, &stream, &ulAction, 0, FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE, 0 ); { double posmarker = 0.0; vorbis_info *vi = NULL; int BytesPerSec; // The ov_open() function performs full stream detection and machine // initialization. If it returns 0, the stream *is* Vorbis and we're // fully ready to decode. if (ov_open_callbacks( (void *)stream, &pPluginWork->vf, NULL, 0, callbacks) < 0) { close_func( (void *)stream ); return; } vi = ov_info( &pPluginWork->vf, -1); pPluginWork->format.size = sizeof(FORMAT_INFO); pPluginWork->format.samplerate = vi->rate; pPluginWork->format.channels = vi->channels; pPluginWork->format.bits = 16; pPluginWork->format.format = WAVE_FORMAT_PCM; BytesPerSec = vi->rate * vi->channels * 2; /* 曲の時間(ms) */ pPluginWork->songlength = (int)(ov_time_total(&pPluginWork->vf, -1) * 1000.0); DosResetEventSem( pPluginWork->hevPlaySem, &ulTmp ); DosPostEventSem( pPluginWork->hevThreadA ); pPluginWork->fStatus = DECODER_PLAYING; //seekneeded = -1; while(!pPluginWork->fStop && !pPluginWork->fTerminate) { long read_size, read_size1; if(pPluginWork->jumpto != -1) { ov_time_seek( &pPluginWork->vf, pPluginWork->jumpto / 1000 ); posmarker = (double)(pPluginWork->jumpto / 1000) * BytesPerSec; pPluginWork->lOffset = 0; pPluginWork->lRemain = 0; pPluginWork->jumpto = -1; WinPostMsg( pPluginWork->hwnd, WM_SEEKSTOP, 0, 0 ); } #if 0 if(pPluginWork->rew) { posmarker -= 1 * BytesPerSec; /* 2s */ ov_time_seek( &pPluginWork->vf, (int)(posmarker / BytesPerSec * 1000.0) ); pPluginWork->lOffset = 0; pPluginWork->lRemain = 0; // pPluginWork->jumpto = -1; // WinPostMsg( pPluginWork->hwnd, WM_SEEKSTOP, 0, 0 ); } #endif read_size = Read( pPluginWork, pPluginWork->sample_buffer1, pPluginWork->BufferSize, &read_size1 ); if(read_size < pPluginWork->BufferSize) { if(read_size == 0) { break; } read_size = pPluginWork->BufferSize; memset( &pPluginWork->sample_buffer1[read_size], 0, pPluginWork->BufferSize - read_size ); } pPluginWork->output_play_samples( pPluginWork->a, &pPluginWork->format, pPluginWork->sample_buffer1, read_size, (int)(posmarker / BytesPerSec * 1000.0) ); posmarker += (double)read_size1; } ov_clear( &pPluginWork->vf ); WinPostMsg( pPluginWork->hwnd, WM_PLAYSTOP, 0, 0 ); pPluginWork->fStatus = 0; close_func( (void *)stream ); if(pPluginWork->fStop) { DosPostEventSem( pPluginWork->hevThreadA ); } DosPostEventSem( pPluginWork->hevPlaySem ); } }
int ftp_getfile(const char *infile, const char *outfile, getmode_t how, transfer_mode_t mode, ftp_transfer_func hookf) { FILE *fp; int r; struct stat statbuf; long rp = 0; int (*close_func)(FILE *fp); if(stat(outfile, &statbuf) == 0) { if(S_ISDIR(statbuf.st_mode)) { ftp_err(_("%s: is a directory\n"), outfile); return -1; } if(!(statbuf.st_mode & S_IWRITE)) { ftp_err(_("%s: permission denied\n"), outfile); return -1; } if(how == getResume) ftp->restart_offset = statbuf.st_size; } else ftp->restart_offset = 0L; ftp->ti.total_size = -1; /* we need to save this, because ftp_init_receive() sets it to zero */ rp = ftp->restart_offset; reset_transfer_info(); #ifdef HAVE_LIBSSH if (ftp->session) { /* we need to stat the remote file, so we are sure we can read it * this needs to be done before we call ssh_do_receive, because by * then, the file is created, and would leave a zero-size file opon * failure */ sftp_attributes a = sftp_stat(ftp->sftp_session, infile); if(!a) { ftp_err(_("Unable to stat file '%s': %s\n"), infile, ssh_get_error(ftp->session)); return -1; } sftp_attributes_free(a); /* FIXME: how can we check if it will be possible to transfer * the specified file? */ } else #endif if (ftp_init_receive(infile, mode, hookf) != 0) return -1; if(how == getPipe) { fp = popen(outfile, "w"); close_func = pclose; } else { fp = fopen(outfile, (rp > 0L || (how == getAppend)) ? "a" : "w"); close_func = fclose; } if(!fp) { ftp_err("%s: %s\n", outfile, strerror(errno)); ftp->restart_offset = 0L; return -1; } if(rp > 0L) { if(fseek(fp, rp, SEEK_SET) != 0) { ftp_err(_("%s: %s, transfer cancelled\n"), outfile, strerror(errno)); close_func(fp); ftp->restart_offset = 0L; return -1; } } free(ftp->ti.remote_name); free(ftp->ti.local_name); ftp->ti.remote_name = xstrdup(infile); ftp->ti.local_name = xstrdup(outfile); foo_hookf = hookf; #ifdef HAVE_LIBSSH if(ftp->session) r = ssh_do_receive(infile, fp, mode, hookf); else #endif r = ftp_do_receive(fp, mode, hookf); close_func(fp); return r; }