asm_command *asm_command_search(asm_command_table *table, char *text_buffer) { if(!text_buffer) PLEASE_KILL_MY_VERY_BAD_FUNCTION(NULL_PTR); if(asm_command_table_ok(table)) PLEASE_KILL_MY_VERY_BAD_FUNCTION(asm_command_table_ok(table)); char* str_pointer = text_buffer; param_t operator1 = NONE; param_t operator2 = NONE; for(int i = 0; i < table->quantity_elements; i++) { if(!strcmp(table->command[i].name, str_pointer)) { if(table->command[i].param1_t != NONE) operator1 = str_to_type (str_pointer + strlen(str_pointer) + 1); if(table->command[i].param2_t != NONE) operator2 = str_to_type (str_pointer + 2 + strlen(str_pointer) + strlen(str_pointer + strlen(str_pointer) + 1)); printf("%d %d %s %d\n", operator1, operator2, text_buffer, str_pointer + 2 + strlen(str_pointer) + strlen(str_pointer + strlen(str_pointer) + 1)); if((operator1 == DATA)&&(table->command[i].param1_t == CHARDATA)) return &table->command[i]; if((operator1 == NONE)&&((table->command[i].param1_t == FAROFFSET)||(table->command[i].param1_t == FAR8OFFSET))) return &table->command[i]; if((operator1 == table->command[i].param1_t)&&(operator2 == table->command[i].param2_t)) return &table->command[i]; if(operator2 == REGISTER) if((operator1 == table->command[i].param1_t)&&(RMEMORY == table->command[i].param2_t)) return &table->command[i]; if(operator1 == REGISTER) if((RMEMORY == table->command[i].param1_t)&&(operator2 == table->command[i].param2_t)) return &table->command[i]; if(operator1 == REGISTER) if((operator1 == table->command[i].param1_t)&&(table->command[i].param2_t == OFFSET)) return &table->command[i]; } } if(asm_command_table_ok(table)) PLEASE_KILL_MY_VERY_BAD_FUNCTION(asm_command_table_ok(table)); return &table->command[0]; }
void take_item(t_env *e, int cs) { char *item; int resource; int player_x; int player_y; item = e->users[cs]->player.acts[e->users[cs]->player.cur_aread].cmd; player_x = e->users[cs]->player.x; player_y = e->users[cs]->player.y; if ((resource = str_to_type(item)) == -1) tmp_to_bc(&e->users[cs]->buf_write, "ko", 1); else { if (e->map[player_y][player_x].ground[resource] == 0) tmp_to_bc(&e->users[cs]->buf_write, "ko", 1); else { e->map[player_y][player_x].ground[resource]--; e->users[cs]->player.inv[resource]++; tmp_to_bc(&e->users[cs]->buf_write, "ok", 1); } } gfx_send_npc(e, cs, gfx_pin); gfx_send_map(e, player_x, player_y, gfx_bct); }
void gfx_take_item(t_env *e, int cs) { char *item; int resource; item = e->users[cs]->player.acts[e->users[cs]->player.cur_aread].cmd; resource = str_to_type(item); if (resource < 0) return ; gfx_send_act(e, cs, gfx_pgt, resource); }
static void *iir_init(const struct dspfilter_info *info, const struct dspfilter_config *config, void *userdata) { struct iir_data *iir = (struct iir_data*)calloc(1, sizeof(*iir)); if (!iir) return NULL; float freq, qual, gain; config->get_float(userdata, "frequency", &freq, 1024.0f); config->get_float(userdata, "quality", &qual, 0.707f); config->get_float(userdata, "gain", &gain, 0.0f); char *type = NULL; config->get_string(userdata, "type", &type, "LPF"); enum IIRFilter filter = str_to_type(type); config->free(type); iir_filter_init(iir, info->input_rate, freq, qual, gain, filter); return iir; }
void MainMenu::build_menu_item(Fl_XmlNode *node) { if(!node) return; int type = str_to_type(node->get_attribute("Type")); if(type==ITEM_NONE) return; Fl_Widget *w=0; EItemGroup *g=0; EItem *i=0; switch(type) { case ITEM_EXEC: i = new EItem(this); i->callback((Fl_Callback*)cb_exec_item); set_exec(i, node->get_attribute("Exec")); i->image(run_pix); w = (Fl_Widget *)i; break; case ITEM_APPDIR: g = new EItemGroup(this, APP_GROUP); g->image(programs_pix); g->dir(get_item_dir(node)); break; case ITEM_SUBDIR: g = new EItemGroup(this, APP_GROUP); g->image(programs_pix); break; case ITEM_FILEBROWSER: g = new EItemGroup(this, BROWSER_GROUP); g->dir(get_item_dir(node)); g->image(find_pix); break; case ITEM_DIVIDER: w = (Fl_Widget *)new Fl_Menu_Divider(); break; } if(g) { g->begin(); w = (Fl_Widget*)g; } Fl_Image *im=0; if(node->has_attribute("Icon")) { im = find_image(node->get_attribute("Icon")); } else { Fl_String im_path(node->get_attribute("Exec")); im_path += ".png"; im = find_image(im_path); } if(im) w->image(im); Fl_String label = get_item_name(node); w->label(label); for(uint n=0; n<node->children(); n++) { Fl_XmlNode *np = node->child(n); if((np->is_element() || np->is_leaf()) && np->name()=="Item") build_menu_item(np); } if(w->is_group()) ((Fl_Group*)w)->end(); }
void test_str_to_type(void) { assert_int_equals(J_VOID, str_to_type("V")); assert_int_equals(J_BYTE, str_to_type("B")); assert_int_equals(J_CHAR, str_to_type("C")); assert_int_equals(J_DOUBLE, str_to_type("D")); assert_int_equals(J_FLOAT, str_to_type("F")); assert_int_equals(J_INT, str_to_type("I")); assert_int_equals(J_LONG, str_to_type("J")); assert_int_equals(J_SHORT, str_to_type("S")); assert_int_equals(J_BOOLEAN, str_to_type("Z")); assert_int_equals(J_REFERENCE, str_to_type("[L")); assert_int_equals(J_REFERENCE, str_to_type("[java/lang/Object;")); }