const char* parser_translate_include( ParserContext pc, const char* include ) { ParsingInfo* pi = (ParsingInfo*)get_extra( pc ); BehaviorTreeContext btc = get_bt_context( pc ); Allocator a; a.m_Alloc = &allocate_memory; a.m_Free = &free_memory; StringBuffer sb; init( a, &sb ); if( pi->m_Name ) { int s = 0, last = -1; for( const char* p = pi->m_Name; p && *p; ++p, ++s ) { if( *p == '/' ) last = s; } if( last != -1 ) append( &sb, pi->m_Name, last + 1 ); } append( &sb, include ); const char* ret = register_string( btc, sb.m_Str ); destroy( &sb ); return ret; }
static imgtoolerr_t imgtool_floppy_open_internal(imgtool_image *image, imgtool_stream *f, int noclose) { floperr_t ferr; imgtoolerr_t err; struct imgtool_floppy_image *fimg; const struct ImgtoolFloppyExtra *extra; extra = get_extra(img_module(image)); fimg = (struct imgtool_floppy_image *) img_extrabytes(image); /* open up the floppy */ ferr = floppy_open(f, noclose ? &imgtool_noclose_ioprocs : &imgtool_ioprocs, NULL, extra->format, FLOPPY_FLAGS_READWRITE, &fimg->floppy); if (ferr) { err = imgtool_floppy_error(ferr); return err; } if (extra->open) { err = extra->open(image, NULL); if (err) return err; } return IMGTOOLERR_SUCCESS; }
int read_file( ParserContext pc, char* buffer, int maxsize ) { ParsingInfo* pi = (ParsingInfo*)get_extra( pc ); if( !pi ) return 0; if( feof( pi->m_File ) ) return 0; return (int)fread( buffer, 1, maxsize, pi->m_File ); }
CAMLprim value pcre_study_stat_stub(value v_rex) { /* Generates the appropriate constant constructor [`Optimal] or [`Studied] if regexp has already been studied */ if (get_studied(v_rex)) return (get_extra(v_rex) == NULL) ? var_Optimal : var_Studied; return var_Not_studied; /* otherwise [`Not_studied] */ }
/* Finalizing deallocation function for compiled regular expressions */ static void pcre_dealloc_regexp(value v_rex) { void *extra = get_extra(v_rex); if (extra != NULL) #ifdef PCRE_STUDY_JIT_COMPILE pcre_free_study(extra); #else pcre_free(extra); #endif (pcre_free)(get_rex(v_rex)); }
/* Gets the match limit of a regular expression if it exists */ CAMLprim value pcre_get_match_limit_stub(value v_rex) { pcre_extra *extra = get_extra(v_rex); if (extra == NULL) return None; if (extra->flags & PCRE_EXTRA_MATCH_LIMIT) { value v_lim = Val_int(extra->match_limit); value v_res = caml_alloc_small(1, 0); Field(v_res, 0) = v_lim; return v_res; } return None; }
void parser_warning( ParserContext pc, const char* msg ) { ParsingInfo* pi = (ParsingInfo*)get_extra( pc ); if( pi ) { fprintf( stderr, "%s(%d): warning: %s\n", pi->m_Name, get_line_no( pc ), msg ); } else { fprintf( stderr, "%s(0): warning: %s\n", g_inputFileName, msg ); } }
CAMLprim value pcre_set_imp_match_limit_stub(value v_rex, intnat v_lim) { pcre_extra *extra = get_extra(v_rex); if (extra == NULL) { extra = pcre_malloc(sizeof(pcre_extra)); extra->flags = PCRE_EXTRA_MATCH_LIMIT; set_extra(v_rex, extra); } else { unsigned long *flags_ptr = &extra->flags; *flags_ptr = PCRE_EXTRA_MATCH_LIMIT | *flags_ptr; } extra->match_limit = v_lim; return v_rex; }
/* Function: al_get_d3d_texture_size */ bool al_get_d3d_texture_size(ALLEGRO_BITMAP *bitmap, int *width, int *height) { int bitmap_flags = al_get_bitmap_flags(bitmap); ASSERT(bitmap); ASSERT(width); ASSERT(height); if (!(bitmap_flags & _ALLEGRO_INTERNAL_OPENGL) && !(bitmap_flags & ALLEGRO_MEMORY_BITMAP)) { ALLEGRO_BITMAP_EXTRA_D3D *d3d_bmp = get_extra(bitmap); *width = d3d_bmp->texture_w; *height = d3d_bmp->texture_h; return true; } else { *width = 0; *height = 0; return false; } }
static imgtoolerr_t imgtool_floppy_create(imgtool_image *image, imgtool_stream *f, option_resolution *opts) { floperr_t ferr; imgtoolerr_t err = IMGTOOLERR_SUCCESS; const struct FloppyFormat *format; const struct ImgtoolFloppyExtra *extra; struct imgtool_floppy_image *fimg; extra = get_extra(img_module(image)); format = extra->format; fimg = (struct imgtool_floppy_image *) img_extrabytes(image); /* open up the floppy */ ferr = floppy_create(f, &imgtool_ioprocs, format, opts, &fimg->floppy); if (ferr) { err = imgtool_floppy_error(ferr); goto done; } /* do we have to do extra stuff when creating the image? */ if (extra->create) { err = extra->create(image, NULL, opts); if (err) goto done; } /* do we have to do extra stuff when opening the image? */ if (extra->open) { err = extra->open(image, NULL); if (err) goto done; } done: return err; }
void diffuse() { edge_id e_id; facet_id f_id; facetedge_id fe_id; body_id b_id,bb_id; REAL pressure; REAL mass; REAL coeff; if ( web.representation == STRING ) { edge_diffusion_attr = find_attribute(EDGE,DIFFUSE_EATTR_NAME); FOR_ALL_EDGES(e_id) { fe_id = get_edge_fe(e_id); if ( !valid_id(fe_id) ) return; b_id = get_facet_body(get_fe_facet(fe_id)); if ( !valid_id(b_id) ) invert(fe_id); b_id = get_facet_body(get_fe_facet(fe_id)); if ( !valid_id(b_id) ) continue; pressure = get_body_pressure(b_id); if ( !equal_id(fe_id,get_next_facet(fe_id)) ) { fe_id = get_next_facet(fe_id); bb_id = get_facet_body(get_fe_facet(fe_id)); if ( !valid_id(bb_id) ) invert(fe_id); bb_id = get_facet_body(get_fe_facet(fe_id)); pressure -= get_body_pressure(bb_id); } else bb_id = NULLBODY; if ( edge_diffusion_attr >= 0 ) coeff = *(REAL*)get_extra(e_id,edge_diffusion_attr); else coeff = web.diffusion_const; mass = web.scale*coeff*pressure*get_edge_length(e_id); set_body_fixvol(b_id,get_body_fixvol(b_id)-mass); if ( valid_id(bb_id) ) set_body_fixvol(bb_id,get_body_fixvol(bb_id)+mass); } } /* end STRING */
/* Performs the call to the pcre_fullinfo function */ static inline int pcre_fullinfo_stub(value v_rex, int what, void *where) { return pcre_fullinfo(get_rex(v_rex), get_extra(v_rex), what, where); }
/* * Draw a textured quad */ static void d3d_draw_textured_quad( ALLEGRO_DISPLAY_D3D *disp, ALLEGRO_BITMAP *bmp, ALLEGRO_COLOR tint, float sx, float sy, float sw, float sh, int flags) { float right; float bottom; float tu_start; float tv_start; float tu_end; float tv_end; int texture_w; int texture_h; ALLEGRO_BITMAP_EXTRA_D3D *extra = get_extra(bmp); const float z = 0.0f; ALLEGRO_DISPLAY* aldisp = (ALLEGRO_DISPLAY*)disp; if (aldisp->num_cache_vertices != 0 && (uintptr_t)bmp != aldisp->cache_texture) { aldisp->vt->flush_vertex_cache(aldisp); } aldisp->cache_texture = (uintptr_t)bmp; right = sw; bottom = sh; texture_w = extra->texture_w; texture_h = extra->texture_h; tu_start = sx / texture_w; tv_start = sy / texture_h; tu_end = sw / texture_w + tu_start; tv_end = sh / texture_h + tv_start; if (flags & ALLEGRO_FLIP_HORIZONTAL) { float temp = tu_start; tu_start = tu_end; tu_end = temp; } if (flags & ALLEGRO_FLIP_VERTICAL) { float temp = tv_start; tv_start = tv_end; tv_end = temp; } #define ALLEGRO_COLOR_TO_D3D(c) D3DCOLOR_COLORVALUE(c.r, c.g, c.b, c.a) #define SET(f) \ vertices[0].x = 0; \ vertices[0].y = 0; \ vertices[0].z = z; \ vertices[0].color = f(tint); \ vertices[0].u = tu_start; \ vertices[0].v = tv_start; \ \ vertices[1].x = right; \ vertices[1].y = 0; \ vertices[1].z = z; \ vertices[1].color = f(tint); \ vertices[1].u = tu_end; \ vertices[1].v = tv_start; \ \ vertices[2].x = right; \ vertices[2].y = bottom; \ vertices[2].z = z; \ vertices[2].color = f(tint); \ vertices[2].u = tu_end; \ vertices[2].v = tv_end; \ \ vertices[5].x = 0; \ vertices[5].y = bottom; \ vertices[5].z = z; \ vertices[5].color = f(tint); \ vertices[5].u = tu_start; \ vertices[5].v = tv_end; \ \ if (aldisp->cache_enabled) { \ transform_vertex(&vertices[0].x, &vertices[0].y); \ transform_vertex(&vertices[1].x, &vertices[1].y); \ transform_vertex(&vertices[2].x, &vertices[2].y); \ transform_vertex(&vertices[5].x, &vertices[5].y); \ } \ \ vertices[3] = vertices[0]; \ vertices[4] = vertices[2]; bool pp = (aldisp->flags & ALLEGRO_PROGRAMMABLE_PIPELINE) != 0; if (pp) { ALLEGRO_VERTEX *vertices = (ALLEGRO_VERTEX *)aldisp->vt->prepare_vertex_cache(aldisp, 6); SET(ALLEGRO_COLOR) } else {
/* Function: al_get_d3d_texture_size */ void al_get_d3d_texture_size(ALLEGRO_BITMAP *bitmap, int *width, int *height) { ALLEGRO_BITMAP_EXTRA_D3D *d3d_bmp = get_extra(bitmap); *width = d3d_bmp->texture_w; *height = d3d_bmp->texture_h; }
/* * Helper function for 'player_birth()'. * * This function handles "point-based" character creation. * * The player selects, for each stat, a value from 6 to 18 (inclusive), * each costing a certain amount of points (as above), from a pool of 30 * available points, to which race/house modifiers are then applied. * * Each unused point is converted into 100 experience points. */ static bool player_birth_aux_2(void) { int i; int row = 2; int col = 42; int stat = 0; int stats[A_MAX]; int cost; char ch; char buf[80]; /* Initialize stats */ for (i = 0; i < A_MAX; i++) { /* Initial stats */ stats[i] = p_ptr->stat_base[i]; } /* Determine experience and things */ get_extra(); /* Interact */ while (1) { /* Reset cost */ cost = 0; /* Process stats */ for (i = 0; i < A_MAX; i++) { /* Obtain a "bonus" for "race" */ int bonus = rp_ptr->r_adj[i] + hp_ptr->h_adj[i]; /* Apply the racial bonuses */ p_ptr->stat_base[i] = stats[i] + bonus; p_ptr->stat_drain[i] = 0; /* Total cost */ cost += birth_stat_costs[stats[i] + 4]; } /* Restrict cost */ if (cost > MAX_COST) { /* Warning */ bell("Excessive stats!"); /* Reduce stat */ stats[stat]--; /* Recompute costs */ continue; } p_ptr->new_exp = p_ptr->exp = PY_START_EXP; /* Calculate the bonuses and hitpoints */ p_ptr->update |= (PU_BONUS | PU_HP); /* Update stuff */ update_stuff(); /* Fully healed */ p_ptr->chp = p_ptr->mhp; /* Fully rested */ calc_voice(); p_ptr->csp = p_ptr->msp; /* Display the player */ display_player(0); /* Display the costs header */ c_put_str(TERM_WHITE, "Points Left:", 0, col + 21); strnfmt(buf, sizeof(buf), "%2d", MAX_COST - cost); c_put_str(TERM_L_GREEN, buf, 0, col + 34); /* Display the costs */ for (i = 0; i < A_MAX; i++) { byte attr = (i == stat) ? TERM_L_BLUE : TERM_L_WHITE; /* Display cost */ strnfmt(buf, sizeof(buf), "%4d", birth_stat_costs[stats[i] + 4]); c_put_str(attr, buf, row + i, col + 32); } /* Prompt */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, -1, TERM_SLATE, "Arrow keys allocate points to stats"); Term_putstr(QUESTION_COL, INSTRUCT_ROW + 2, -1, TERM_SLATE, " Enter accept current values"); /* Hack - highlight the key names */ Term_putstr(QUESTION_COL, INSTRUCT_ROW + 1, - 1, TERM_L_WHITE, "Arrow keys"); Term_putstr(QUESTION_COL + 5, INSTRUCT_ROW + 2, - 1, TERM_L_WHITE, "Enter"); /* Get key */ hide_cursor = TRUE; ch = inkey(); hide_cursor = FALSE; /* Quit */ if ((ch == 'Q') || (ch == 'q')) quit(NULL); /* Start over */ if (ch == ESCAPE) return (FALSE); /* Done */ if ((ch == '\r') || (ch == '\n')) break; /* Prev stat */ if (ch == '8') { stat = (stat + A_MAX - 1) % A_MAX; } /* Next stat */ if (ch == '2') { stat = (stat + 1) % A_MAX; } /* Decrease stat */ if ((ch == '4') && (stats[stat] > 0)) { stats[stat]--; } /* Increase stat */ if (ch == '6') { stats[stat]++; } } /* Done */ return (TRUE); }
CAMLprim value pcre_exec_stub0( intnat v_opt, value v_rex, intnat v_pos, intnat v_subj_start, value v_subj, value v_ovec, value v_maybe_cof, value v_workspace) { int ret; int is_dfa = v_workspace != (value) NULL; long pos = v_pos, len = caml_string_length(v_subj), subj_start = v_subj_start; long ovec_len = Wosize_val(v_ovec); if (pos > len || pos < subj_start) caml_invalid_argument("Pcre.pcre_exec_stub: illegal position"); if (subj_start > len || subj_start < 0) caml_invalid_argument("Pcre.pcre_exec_stub: illegal subject start"); pos -= subj_start; len -= subj_start; { const pcre *code = get_rex(v_rex); /* Compiled pattern */ const pcre_extra *extra = get_extra(v_rex); /* Extra info */ const char *ocaml_subj = String_val(v_subj) + subj_start; /* Subject string */ const int opt = v_opt; /* Runtime options */ /* Special case when no callout functions specified */ if (v_maybe_cof == None) { int *ovec = (int *) &Field(v_ovec, 0); /* Performs the match */ if (is_dfa) ret = pcre_dfa_exec(code, extra, ocaml_subj, len, pos, opt, ovec, ovec_len, (int *) &Field(v_workspace, 0), Wosize_val(v_workspace)); else ret = pcre_exec(code, extra, ocaml_subj, len, pos, opt, ovec, ovec_len); if (ret < 0) handle_exec_error("pcre_exec_stub", ret); else handle_pcre_exec_result(ovec, v_ovec, ovec_len, subj_start, ret); } /* There are callout functions */ else { value v_cof = Field(v_maybe_cof, 0); value v_substrings; char *subj = caml_stat_alloc(sizeof(char) * len); int *ovec = caml_stat_alloc(sizeof(int) * ovec_len); int workspace_len; int *workspace; struct cod cod = { 0, (value *) NULL, (value *) NULL, (value) NULL }; struct pcre_extra new_extra = #ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION # ifdef PCRE_EXTRA_MARK # ifdef PCRE_EXTRA_EXECUTABLE_JIT { PCRE_EXTRA_CALLOUT_DATA, NULL, 0, NULL, NULL, 0, NULL, NULL }; # else { PCRE_EXTRA_CALLOUT_DATA, NULL, 0, NULL, NULL, 0, NULL }; # endif # else { PCRE_EXTRA_CALLOUT_DATA, NULL, 0, NULL, NULL, 0 }; # endif #else { PCRE_EXTRA_CALLOUT_DATA, NULL, 0, NULL, NULL }; #endif cod.subj_start = subj_start; memcpy(subj, ocaml_subj, len); Begin_roots4(v_rex, v_cof, v_substrings, v_ovec); Begin_roots1(v_subj); v_substrings = caml_alloc_small(2, 0); End_roots(); Field(v_substrings, 0) = v_subj; Field(v_substrings, 1) = v_ovec; cod.v_substrings_p = &v_substrings; cod.v_cof_p = &v_cof; new_extra.callout_data = &cod; if (extra != NULL) { new_extra.flags = PCRE_EXTRA_CALLOUT_DATA | extra->flags; new_extra.study_data = extra->study_data; new_extra.match_limit = extra->match_limit; new_extra.tables = extra->tables; #ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION new_extra.match_limit_recursion = extra->match_limit_recursion; #endif } if (is_dfa) { workspace_len = Wosize_val(v_workspace); workspace = caml_stat_alloc(sizeof(int) * workspace_len); ret = pcre_dfa_exec(code, extra, subj, len, pos, opt, ovec, ovec_len, (int *) &Field(v_workspace, 0), workspace_len); } else ret = pcre_exec(code, &new_extra, subj, len, pos, opt, ovec, ovec_len); caml_stat_free(subj); End_roots(); if (ret < 0) { if (is_dfa) caml_stat_free(workspace); caml_stat_free(ovec); if (ret == PCRE_ERROR_CALLOUT) caml_raise(cod.v_exn); else handle_exec_error("pcre_exec_stub(callout)", ret); } else { handle_pcre_exec_result(ovec, v_ovec, ovec_len, subj_start, ret); if (is_dfa) { caml_int_ptr ocaml_workspace_dst = (caml_int_ptr) &Field(v_workspace, 0); const int *workspace_src = workspace; const int *workspace_src_stop = workspace + workspace_len; while (workspace_src != workspace_src_stop) { *ocaml_workspace_dst = *workspace_src; ocaml_workspace_dst++; workspace_src++; } caml_stat_free(workspace); } caml_stat_free(ovec); } } } return Val_unit; } CAMLprim value pcre_exec_stub( intnat v_opt, value v_rex, intnat v_pos, intnat v_subj_start, value v_subj, value v_ovec, value v_maybe_cof) { return pcre_exec_stub0(v_opt, v_rex, v_pos, v_subj_start, v_subj, v_ovec, v_maybe_cof, (value) NULL); } /* Byte-code hook for pcre_exec_stub Needed, because there are more than 5 arguments */ CAMLprim value pcre_exec_stub_bc(value *argv, int __unused argn) { return pcre_exec_stub0( Int_val(argv[0]), argv[1], Int_val(argv[2]), Int_val(argv[3]), argv[4], argv[5], argv[6], (value) NULL); } /* Byte-code hook for pcre_dfa_exec_stub Needed, because there are more than 5 arguments */ CAMLprim value pcre_dfa_exec_stub_bc(value *argv, int __unused argn) { return pcre_exec_stub0( Int_val(argv[0]), argv[1], Int_val(argv[2]), Int_val(argv[3]), argv[4], argv[5], argv[6], argv[7]); } static struct custom_operations tables_ops = { "pcre_ocaml_tables", pcre_dealloc_tables, custom_compare_default, custom_hash_default, custom_serialize_default, custom_deserialize_default, custom_compare_ext_default }; /* Generates a new set of chartables for the current locale (see man page of PCRE */ CAMLprim value pcre_maketables_stub(value __unused v_unit) { /* GC will do a full cycle every 1_000_000 table set allocations (one table set consumes 864 bytes -> maximum of 864_000_000 bytes unreclaimed table sets) */ const value v_tables = caml_alloc_custom( &tables_ops, sizeof(struct pcre_ocaml_tables), 1, 1000000); set_tables(v_tables, pcre_maketables()); return v_tables; } /* Wraps around the isspace-function */ CAMLprim value pcre_isspace_stub(value v_c) { return Val_bool(isspace(Int_val(v_c))); } /* Returns number of substring associated with a name */ CAMLprim intnat pcre_get_stringnumber_stub(value v_rex, value v_name) { const int ret = pcre_get_stringnumber(get_rex(v_rex), String_val(v_name)); if (ret == PCRE_ERROR_NOSUBSTRING) caml_invalid_argument("Named string not found"); return ret; } CAMLprim value pcre_get_stringnumber_stub_bc(value v_rex, value v_name) { return Val_int(pcre_get_stringnumber_stub(v_rex, v_name)); } /* Returns array of names of named substrings in a regexp */ CAMLprim value pcre_names_stub(value v_rex) { CAMLparam0(); CAMLlocal1(v_res); int name_count; int entry_size; const char *tbl_ptr; int i; int ret = pcre_fullinfo_stub(v_rex, PCRE_INFO_NAMECOUNT, &name_count); if (ret != 0) raise_internal_error("pcre_names_stub: namecount"); ret = pcre_fullinfo_stub(v_rex, PCRE_INFO_NAMEENTRYSIZE, &entry_size); if (ret != 0) raise_internal_error("pcre_names_stub: nameentrysize"); ret = pcre_fullinfo_stub(v_rex, PCRE_INFO_NAMETABLE, &tbl_ptr); if (ret != 0) raise_internal_error("pcre_names_stub: nametable"); v_res = caml_alloc(name_count, 0); for (i = 0; i < name_count; ++i) { value v_name = caml_copy_string(tbl_ptr + 2); Store_field(v_res, i, v_name); tbl_ptr += entry_size; } CAMLreturn(v_res); } /* Generic stub for getting integer results from pcre_config */ static inline int pcre_config_int(int what) { int ret; pcre_config(what, (void *) &ret); return ret; } /* Generic stub for getting long integer results from pcre_config */ static inline int pcre_config_long(int what) { long ret; pcre_config(what, (void *) &ret); return ret; }
struct eu_variant *eu_object_get(struct eu_object *obj, struct eu_string_ref name) { return get_extra(&object_metadata, (char *)obj, name); }