/** * im_buildlut: * @input: input mask * @output: output image * * This operation builds a lookup table from a set of points. Intermediate * values are generated by piecewise linear interpolation. * * For example, consider this 2 x 2 matrix of (x, y) coordinates: * * <tgroup cols='2' align='left' colsep='1' rowsep='1'> * <tbody> * <row> * <entry>0</entry> * <entry>0</entry> * </row> * <row> * <entry>255</entry> * <entry>100</entry> * </row> * </tbody> * </tgroup> * * We then generate: * * <tgroup cols='2' align='left' colsep='1' rowsep='1'> * <thead> * <row> * <entry>Index</entry> * <entry>Value</entry> * </row> * </thead> * <tbody> * <row> * <entry>0</entry> * <entry>0</entry> * </row> * <row> * <entry>1</entry> * <entry>0.4</entry> * </row> * <row> * <entry>...</entry> * <entry>etc. by linear interpolation</entry> * </row> * <row> * <entry>255</entry> * <entry>100</entry> * </row> * </tbody> * </tgroup> * * This is then written as the output image, with the left column giving the * index in the image to place the value. * * The (x, y) points don't need to be sorted: we do that. You can have * several Ys, each becomes a band in the output LUT. You don't need to * start at zero, any integer will do, including negatives. * * See also: im_identity(), im_invertlut(). * * Returns: 0 on success, -1 on error */ int im_buildlut( DOUBLEMASK *input, IMAGE *output ) { State state; if( !input || input->xsize < 2 || input->ysize < 1 ) { im_error( "im_buildlut", "%s", _( "bad input matrix size" ) ); return( -1 ); } if( build_state( &state, input ) || buildlut( &state ) ) { free_state( &state ); return( -1 ); } im_initdesc( output, state.lut_size, 1, input->xsize - 1, IM_BBITS_DOUBLE, IM_BANDFMT_DOUBLE, IM_CODING_NONE, IM_TYPE_HISTOGRAM, 1.0, 1.0, 0, 0 ); if( im_setupout( output ) || im_writeline( 0, output, (PEL *) state.buf ) ) { free_state( &state ); return( -1 ); } free_state( &state ); return( 0 ); }
/********************************************************************** * %FUNCTION: handle_writeable * %ARGUMENTS: * es -- event selector * fd -- the writeable socket * flags -- ignored * data -- the EventTcpState object * %RETURNS: * Nothing * %DESCRIPTION: * Continues to fill buffer. Calls callback when done. ***********************************************************************/ static void handle_writeable(EventSelector *es, int fd, unsigned int flags, void *data) { EventTcpState *state = (EventTcpState *) data; int done = state->cur - state->buf; int togo = state->len - done; int n; /* Timed out? */ if (flags & EVENT_FLAG_TIMEOUT) { errno = ETIMEDOUT; if (state->f) { (state->f)(es, state->socket, state->buf, done, EVENT_TCP_FLAG_TIMEOUT, state->data); } else { close(fd); } free_state(state); return; } /* togo had better not be zero here! */ n = write(fd, state->cur, togo); EVENT_DEBUG(("tcp_handle_writeable(es=%p, fd=%d, flags=%u, data=%p)\n", es, fd, flags, data)); if (n <= 0) { /* error */ if (state->f) { (state->f)(es, state->socket, state->buf, done, EVENT_TCP_FLAG_IOERROR, state->data); } else { close(fd); } free_state(state); return; } state->cur += n; done += n; if (done >= state->len) { /* Written enough! */ if (state->f) { (state->f)(es, state->socket, state->buf, done, EVENT_TCP_FLAG_COMPLETE, state->data); } else { close(fd); } free_state(state); return; } }
/** * _pango_layout_line_ellipsize: * @line: a #PangoLayoutLine * @attrs: Attributes being used for itemization/shaping * * Given a PangoLayoutLine with the runs still in logical order, ellipsize * it according the layout's policy to fit within the set width of the layout. **/ void _pango_layout_line_ellipsize (PangoLayoutLine *line, PangoAttrList *attrs) { EllipsizeState state; if (line->layout->ellipsize == PANGO_ELLIPSIZE_NONE || line->layout->width < 0) return; init_state (&state, line, attrs); if (state.total_width <= state.layout->width) goto out; find_initial_span (&state); while (current_width (&state) > state.layout->width) { if (!remove_one_span (&state)) break; } fixup_ellipsis_run (&state); g_slist_free (line->runs); line->runs = get_run_list (&state); out: free_state (&state); }
int main(int argc, char *argv[]) { if(argc < 2) { printf("Please provide the file-path of an MPEG-TS file.\n\n"); return -1; } char *filename = argv[1]; scan_state_t *state = find_first_program(filename); if(state == NULL) { printf("Could not do scan.\n\n"); return -2; } dump_state_info(state); free_state(state); return 0; }
int main(int argc, char** argv) { sim_param_t params; if (get_params(argc, argv, ¶ms) != 0) exit(-1); sim_state_t* state = init_particles(¶ms); FILE* fp = fopen(params.fname, "w"); int nframes = params.nframes; int npframe = params.npframe; float dt = params.dt; int n = state->n; double t_start = omp_get_wtime(); //write_header(fp, n); write_header(fp, n, nframes, params.h); write_frame_data(fp, n, state, NULL); compute_accel(state, ¶ms); leapfrog_start(state, dt); check_state(state); for (int frame = 1; frame < nframes; ++frame) { for (int i = 0; i < npframe; ++i) { compute_accel(state, ¶ms); leapfrog_step(state, dt); check_state(state); } printf("Frame: %d of %d - %2.1f%%\n",frame, nframes, 100*(float)frame/nframes); write_frame_data(fp, n, state, NULL); } double t_end = omp_get_wtime(); printf("Ran in %g seconds\n", t_end-t_start); fclose(fp); free_state(state); }
/** * delete_search * * Terminate the current search and free all the memory involved. */ void Wordrec::delete_search(SEARCH_RECORD *the_search) { float closeness; closeness = (the_search->num_joints ? (hamming_distance(reinterpret_cast<uinT32*>(the_search->first_state), reinterpret_cast<uinT32*>(the_search->best_state), 2) / (float) the_search->num_joints) : 0.0f); free_state (the_search->first_state); free_state (the_search->best_state); free_hash_table(the_search->closed_states); FreeHeapData (the_search->open_states, (void_dest) free_state); memfree(the_search); }
int archive_read_support_filter_program_signature(struct archive *_a, const char *cmd, const void *signature, size_t signature_len) { struct archive_read *a = (struct archive_read *)_a; struct archive_read_filter_bidder *bidder; struct program_bidder *state; /* * Get a bidder object from the read core. */ if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) return (ARCHIVE_FATAL); /* * Allocate our private state. */ state = (struct program_bidder *)calloc(1, sizeof (*state)); if (state == NULL) goto memerr; state->cmd = strdup(cmd); if (state->cmd == NULL) goto memerr; return set_bidder_signature(bidder, state, signature, signature_len); memerr: free_state(state); archive_set_error(_a, ENOMEM, "Can't allocate memory"); return (ARCHIVE_FATAL); }
/********************************************************************** * save_best_state * * Save this state away to be compared later. **********************************************************************/ void save_best_state(CHUNKS_RECORD *chunks_record) { STATE state; SEARCH_STATE chunk_groups; int num_joints; if (save_priorities) { num_joints = chunks_record->ratings->dimension() - 1; state.part1 = 0xffffffff; state.part2 = 0xffffffff; chunk_groups = bin_to_chunks (&state, num_joints); display_segmentation (chunks_record->chunks, chunk_groups); memfree(chunk_groups); cprintf ("Enter the correct segmentation > "); fflush(stdout); state.part1 = 0; scanf ("%x", &state.part2); chunk_groups = bin_to_chunks (&state, num_joints); display_segmentation (chunks_record->chunks, chunk_groups); memfree(chunk_groups); window_wait(segm_window); /* == 'n') */ if (known_best_state) free_state(known_best_state); known_best_state = new_state (&state); } }
static void draw_state(ModeInfo * mi, int state) { dilemmastruct *dp = &dilemmas[MI_SCREEN(mi)]; CellList *current; current = dp->cellList[state]; while (current) { int col = current->pt.x; int row = current->pt.y; int colrow = col + row * dp->ncols; drawcell(mi, col, row, dp->colors[(int) dp->sn[colrow]][(int) dp->s[colrow]], dp->sn[colrow], False); if (dp->s[colrow] && !dp->sn[colrow]) dp->defectors--; if (!dp->s[colrow] && dp->sn[colrow]) dp->defectors++; dp->s[colrow] = dp->sn[colrow]; current = current->next; } free_state(dp, state); XFlush(MI_DISPLAY(mi)); }
int get_args(int argc, char* const argv[], State* s) { const char* optstring = "hdf:F:l:v:s:n:"; char n; while((n=getopt(argc, argv, optstring)) != -1) { switch(n){ case 'f': // Center Frequency s->fc = atoi(optarg); break; case 'F': // Filename change_filename(s, optarg, strnlen(optarg, MAXFILENAMELEN)); break; case 's': // Sample Rate s->fs = atoi(optarg); break; case 'l': // LNA gain s->lna_gain = atoi(optarg); break; case 'v': // VGA gain s->vga_gain = atoi(optarg); break; case 'n': // Number of samples s->samples_needed = atoi(optarg); break; case 'd': break; case 'h': usage(); free_state(s); exit(0); default: usage(); free_state(s); exit(0); } } optind = 1; while((n=getopt(argc, argv, optstring)) != -1) { if (n == 'd') { print_state(s, stdout); free_state(s); exit(0); } } return 0; }
static int program_bidder_free(struct archive_read_filter_bidder *self) { struct program_bidder *state = (struct program_bidder *)self->data; free_state(state); return (ARCHIVE_OK); }
static void free_list(circuitstruct * wp) { int state; for (state = 0; state < COLORS - 1; state++) free_state(wp, state); }
static void free_list(dilemmastruct * dp) { int state; for (state = 0; state < COLORS; state++) free_state(dp, state); }
static void pop_state( stack * const pStack ) { if ( pStack->stack ) { state * const pState = pStack->stack->prev; free_state( pStack->stack ); pStack->stack = pState; } }
int main(int argc, char *argv[]) { FILE *code_file; int max_steps = 10000; // edit by leo init_sharemem(); // edit end state_ptr s = new_state(MEM_SIZE); mem_t saver = copy_reg(s->r); mem_t savem; int step = 0; stat_t e = STAT_AOK; if (argc < 2 || argc > 3) usage(argv[0]); code_file = fopen(argv[1], "r"); if (!code_file) { fprintf(stderr, "Can't open code file '%s'\n", argv[1]); exit(1); } if (!load_mem(s->m, code_file, 1)) { printf("Exiting\n"); return 1; } savem = copy_mem(s->m); // edit by leo // printf("error happen after here!\n"); // edit end if (argc > 2) max_steps = atoi(argv[2]); for (step = 0; step < max_steps && e == STAT_AOK; step++) e = step_state(s, stdout); printf("Stopped in %d steps at PC = 0x%x. Status '%s', CC %s\n", step, s->pc, stat_name(e), cc_name(s->cc)); printf("Changes to registers:\n"); diff_reg(saver, s->r, stdout); printf("\nChanges to memory:\n"); diff_mem(savem, s->m, stdout); free_state(s); free_reg(saver); free_mem(savem); return 0; }
static void free_list(demonstruct * dp) { int state; for (state = 0; state < dp->states; state++) free_state(dp, state); (void) free((void *) dp->cellList); dp->cellList = (CellList **) NULL; }
static void mboxdriver_uninitialize(mailsession * session) { struct mbox_session_state_data * data; data = get_data(session); free_state(data); free(data); }
static void pop_state(stack *pStack) { state *pState; if(pStack->stack != NULL) { pState = pStack->stack->prev; free_state(pStack->stack); pStack->stack = pState; } }
int main (int argc, char *argv[]) { int i; int found = 0; pstate *state = init_from_file("../sjson-examples/big.txt"); for(i=0; i<10000; i++) { found += parse(state); reset_state(state); } free_state(state); printf("%d\n", found); }
void Traverse::finish() { if (stack == nullptr) return; for (int i = 0; i < size; i++) if (stack[i].e != nullptr) free_state(stack + i); delete[] stack; stack = nullptr; }
int main(int argc, char* argv[]) { state_st state = {0}; // set locale, otherwise we cant use unicode characters for the walls setlocale(LC_ALL, ""); // seed random # srand(time(NULL)); // check for logging if (argc > 1) { if (!strcmp(argv[1], "--debug")) { logger_set_level(LOGGER_LEVEL_DEBUG); } else if (!strcmp(argv[1], "--verbose")) { logger_set_level(LOGGER_LEVEL_VERBOSE); } else if (!strcmp(argv[1], "--warn")) { logger_set_level(LOGGER_LEVEL_WARN); } else if (!strcmp(argv[1], "--error")) { logger_set_level(LOGGER_LEVEL_ERROR); } } // set up logger. If no level has been set this call will do nothing. logger_init(); // set up game state game_init(&state); // welcome screen. get rogue's name, roll rogue welcome(&state); // game loop do { // draw draw(&state); // input input_handler(&state); } while(state.running); endwin(); free_state(&state); logger_stop(); return (EXIT_SUCCESS); }
static int mboxdriver_logout(mailsession * session) { struct mbox_session_state_data * mbox_data; mbox_data = get_data(session); if (mbox_data->mbox_folder == NULL) return MAIL_ERROR_BAD_STATE; free_state(mbox_data); mbox_data->mbox_folder = NULL; return MAIL_NO_ERROR; }
void free_parse(s3_cfg_state_t *_parse) { int i; s3_cfg_state_t *scan = NULL; if (_parse->num_expanded > 0) { for (i = s3_arraylist_count(&_parse->expansions) - 1; i >= 0; i--) { scan = (s3_cfg_state_t *)s3_arraylist_get(&_parse->expansions, i); free_parse(scan); } } free_state(_parse); }
int main(int argc, char *argv[]) { FILE *code_file; int max_steps = 10000; state_ptr s = new_state(MEM_SIZE); mem_t saver = copy_reg(s->r); mem_t savem; int step = 0; exc_t e = EXC_NONE; if (argc < 2 || argc > 3) usage(argv[0]); code_file = fopen(argv[1], "r"); if (!code_file) { fprintf(stderr, "Can't open code file '%s'\n", argv[1]); exit(1); } if (!load_mem(s->m, code_file, 1)) { printf("Exiting\n"); return 1; } savem = copy_mem(s->m); if (argc > 2) max_steps = atoi(argv[2]); for (step = 0; step < max_steps && e == EXC_NONE; step++) e = step_state(s, stdout); printf("Stopped in %d steps at PC = 0x%x. Exception '%s', CC %s\n", step, s->pc, exc_name(e), cc_name(s->cc)); printf("Changes to registers:\n"); diff_reg(saver, s->r, stdout); printf("\nChanges to memory:\n"); diff_mem(savem, s->m, stdout); free_state(s); free_reg(saver); free_mem(savem); return 0; }
static struct dirent_state *create_state(PDENT_HND hnd) { struct dirent_state *state = malloc(sizeof(*state)); if (!state) return NULL; ZERO_STRUCTP(state); if (set_policy_state(hnd, free_state, (void *)state)) { policy_hnd_set_name(hnd, "dirent_state"); return state; } free_state(state); /* ha ha, joke, get it? */ return NULL; }
static void mhdriver_cached_uninitialize(mailsession * session) { struct mh_cached_session_state_data * data; data = get_cached_data(session); mh_flags_store_process(data->mh_flags_directory, data->mh_quoted_mb, data->mh_flags_store); mail_flags_store_free(data->mh_flags_store); free_state(data); mailsession_free(data->mh_ancestor); free(data); session->sess_data = NULL; }
static void free_syntax(struct syntax *syn) { int i; for (i = 0; i < syn->states.count; i++) free_state(syn->states.ptrs[i]); free(syn->states.ptrs); for (i = 0; i < syn->string_lists.count; i++) free_string_list(syn->string_lists.ptrs[i]); free(syn->string_lists.ptrs); for (i = 0; i < syn->default_colors.count; i++) free_strings(syn->default_colors.ptrs[i]); free(syn->default_colors.ptrs); free(syn->name); free(syn); }
static State * maybe_add_state(Grammar *g, State *s) { int i, j; for (i = 0; i < g->states.n; i++) { if (s->hash == g->states.v[i]->hash && s->items.n == g->states.v[i]->items.n) { for (j = 0; j < s->items.n; j++) if (s->items.v[j] != g->states.v[i]->items.v[j]) goto Lcont; free_state(s); return g->states.v[i]; Lcont:; } } s->index = g->states.n; vec_add(&g->states, s); return s; }
static void call_perl(struct req_state *state){ hv_store(state->rethash, "received", 8, newSViv(1) , 0); ev_timer_stop(EV_DEFAULT, &(state->timer) ); dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs( state->req_obj ); PUTBACK; call_sv(state->parent_listener->callback, G_VOID); free_state( state ); FREETMPS; LEAVE; };
void zebra_delete_rnh (struct rnh *rnh) { struct route_node *rn; if (!rnh || !(rn = rnh->node)) return; if (IS_ZEBRA_DEBUG_NHT) { char buf[INET6_ADDRSTRLEN]; zlog_debug("delete rnh %s", rnh_str(rnh, buf, INET6_ADDRSTRLEN)); } list_free(rnh->client_list); free_state(rnh->state); XFREE(MTYPE_RNH, rn->info); rn->info = NULL; route_unlock_node (rn); return; }