int cmd_sample (struct lexer *lexer, struct dataset *ds) { struct sample_trns *trns; int type; int a, b; unsigned frac; if (!lex_force_num (lexer)) return CMD_FAILURE; if (!lex_is_integer (lexer)) { unsigned long min = gsl_rng_min (get_rng ()); unsigned long max = gsl_rng_max (get_rng ()); type = TYPE_FRACTION; if (lex_tokval (lexer) <= 0 || lex_tokval (lexer) >= 1) { msg (SE, _("The sampling factor must be between 0 and 1 " "exclusive.")); return CMD_FAILURE; } frac = lex_tokval (lexer) * (max - min) + min; a = b = 0; } else { type = TYPE_A_FROM_B; a = lex_integer (lexer); lex_get (lexer); if (!lex_force_match_id (lexer, "FROM")) return CMD_FAILURE; if (!lex_force_int (lexer)) return CMD_FAILURE; b = lex_integer (lexer); if (a >= b) { msg (SE, _("Cannot sample %d observations from a population of " "%d."), a, b); return CMD_FAILURE; } frac = 0; } lex_get (lexer); trns = xmalloc (sizeof *trns); trns->type = type; trns->n = a; trns->N = b; trns->m = trns->t = 0; trns->frac = frac; add_transformation (ds, sample_trns_proc, sample_trns_free, trns); return CMD_SUCCESS; }
/* Parses the XSAVE or XEXPORT transformation command. */ static int parse_output_trns (struct lexer *lexer, struct dataset *ds, enum writer_type writer_type) { struct output_trns *t = xmalloc (sizeof *t); t->writer = parse_write_command (lexer, ds, writer_type, XFORM_CMD, NULL); if (t->writer == NULL) { free (t); return CMD_CASCADING_FAILURE; } add_transformation (ds, output_trns_proc, output_trns_free, t); return CMD_SUCCESS; }
int main() { init_environment(); init_data(); init_display(); cuss::interface i_editor; Window w_editor(0, 0, 80, 24); if (!i_editor.load_from_file("cuss/i_element_ed.cuss")) { debugmsg("Can't load cuss/i_element_ed.cuss"); end_display(); return 1; } std::vector<std::string> element_names; std::vector<std::string> transform_names; std::vector<std::string> damage_names; i_editor.ref_data("list_elements", &element_names); i_editor.ref_data("list_transformations", &transform_names); i_editor.ref_data("list_damagetypes", &damage_names); i_editor.select ("list_elements"); bool quit = false; while (!quit) { element_names = get_names(); cuss::element* selected = i_editor.selected(); int ele_num = i_editor.get_int("list_elements"); element* cur_element = NULL; if (ele_num < ELEMENTS_POOL.size()) { cur_element = &(ELEMENTS_POOL[ele_num]); std::stringstream color_data; color_data << "<c=" << color_tag_name(cur_element->color) << ">************<c=/>"; i_editor.set_data("text_color", color_data.str()); i_editor.ref_data("entry_name", &(cur_element->name)); } transform_names = get_tra_names(cur_element); damage_names = get_dmg_names(cur_element); i_editor.draw(&w_editor); long ch = getch(); if (selected->name == "entry_name" && ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ' ')) { cur_element->name += ch; } else if (selected->name == "entry_name" && is_backspace(ch) && !cur_element->name.empty()) { cur_element->name = cur_element->name.substr( 0, cur_element->name.length() - 1); } else if (ch == 's' || ch == 'S') { quit = true; } else if (ch == 'c' || ch == 'C') { change_color(cur_element); } else if (ch == 'a' || ch == 'A') { // Where are we adding an element? if (selected->name == "list_elements") { element tmp; tmp.name = string_input_popup("Name:"); ELEMENTS_POOL.push_back(tmp); i_editor.set_data("list_elements", 999); } else if (selected->name == "list_transformations") { add_transformation(cur_element); i_editor.set_data("list_transformations", 0); } else if (selected->name == "list_damagetypes") { add_damagetype(cur_element); i_editor.set_data("list_damagetypes", 0); } } else if (ch == 'd' || ch == 'D') { // Where are we deleting an element? if (selected->name == "list_elements" && cur_element) { delete_element(ele_num); i_editor.set_data("list_elements", 0); } else if (selected->name == "list_transformations") { int index = i_editor.get_int("list_transformations"); if (cur_element && index >= 0 && index < cur_element->transformations.size()) { delete_transformation(cur_element, index); i_editor.set_data("list_transformations", 0); } } else if (selected->name == "list_damagetypes") { int index = i_editor.get_int("list_damagetypes"); if (cur_element && index >= 0 && index < cur_element->damages.size()) { delete_damagetype(cur_element, index); i_editor.set_data("list_damagetypes", 0); } } } else { i_editor.handle_action(ch); } } // while (!quit) save_data(); end_display(); return 0; }
/* Emits an END CASE transformation for INP. */ static void emit_END_CASE (struct dataset *ds, struct input_program_pgm *inp) { add_transformation (ds, end_case_trns_proc, NULL, inp); }
int main() { init_environment(); init_data(); init_display(); cuss::interface i_editor; Window w_editor(0, 0, 80, 24); if (!i_editor.load_from_file("cuss/i_terrain.cuss")) { debugmsg("Couldn't load cuss/i_terrain.cuss!"); end_display(); return 1; } std::vector<std::string> type_names; std::vector<std::string> flags; std::vector<std::string> transformations; i_editor.ref_data("list_types", &type_names); i_editor.ref_data("list_flags", &flags); i_editor.ref_data("list_transformations", &transformations); i_editor.select("list_types"); for (int i = 0; i < TER_MAX; i++) { if (i >= TERRAIN_POOL.size() || TERRAIN_POOL[i] == NULL) { TERRAIN_POOL.push_back( new terrain_type ); TERRAIN_POOL[i]->name = default_terrain_name( terrain_id(i) ); } } // Main loop bool quit = false; do { type_names = get_names(); cuss::element* selected = i_editor.selected(); int ter_num = i_editor.get_int("list_types"); terrain_type* current_ter = NULL; if (ter_num < TERRAIN_POOL.size()) { current_ter = TERRAIN_POOL[ i_editor.get_int("list_types") ]; flags = get_flag_names(current_ter); transformations = get_transformation_names(current_ter); i_editor.ref_data("num_move", &(current_ter->move_cost)); i_editor.ref_data("num_sight", &(current_ter->sight_cost)); i_editor.ref_data("text_name", &(current_ter->name)); } i_editor.draw(&w_editor); long ch = getch(); if (selected->name == "text_name" && ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ' ')) { current_ter->name += ch; } else if (selected->name == "text_name" && is_backspace(ch) && !current_ter->name.empty()) { current_ter->name = current_ter->name.substr(0, current_ter->name.length() - 1); } else if (ch == 's' || ch == 'S') { quit = true; } else if (ch == 'c' || ch == 'C') { set_symbol(current_ter); } else if (ch == 'a' || ch == 'A') { if (selected->name == "list_types") { terrain_type *tmp = new terrain_type; tmp->move_cost = 10; tmp->name = string_input_popup("Name:"); set_symbol(tmp); TERRAIN_POOL.push_back(tmp); i_editor.set_data("list_types", 999); } else if (selected->name == "list_flags") { add_flag(current_ter); i_editor.set_data("list_flags", 0); } else if (selected->name == "list_transformations") { add_transformation(current_ter); i_editor.set_data("list_transformations", 0); } } else if (ch == 'd' || ch == 'D') { if (selected->name == "list_flags") { int index = i_editor.get_int("list_flags"); if (index < flags.size()) { remove_flag(current_ter, index); i_editor.set_data("list_flags", 0); } } else if (selected->name == "list_transformations") { int index = i_editor.get_int("list_transformations"); if (index < transformations.size()) { remove_transformation(current_ter, index); i_editor.set_data("list_transformations", 0); } } } else if (ch == '?') { debugmsg("%d of %d", i_editor.get_int("list_transformations"), transformations.size()); debugmsg("%d (\\n = %d", TERRAIN_POOL[1]->name[0], '\n'); } else { i_editor.handle_action(ch); } } while (!quit); save_data(); end_display(); return 0; }