static array<tree> upgrade_brackets (array<tree> a, int level) { array<int> tp= symbol_types (a); //cout << "Upgrade " << a << ", " << tp << "\n"; if (admits_brackets (tp)) { //cout << " Downgrade dubious\n"; array<tree> r= simplify_matching (a, downgrade_dubious (tp), level); if (r != a) return upgrade_brackets (r, level); //cout << " Detect french\n"; r= simplify_matching (a, detect_french_interval (a, tp), level); if (r != a) return upgrade_brackets (r, level); //cout << " Detect absolute 1\n"; r= simplify_matching (a, detect_absolute (a, tp, false), level); if (r != a) return upgrade_brackets (r, level); //cout << " Detect absolute 2\n"; r= simplify_matching (a, detect_absolute (a, tp, true), level); if (r != a) return upgrade_brackets (r, level); //cout << " Detect probable\n"; r= simplify_matching (a, detect_probable (a, tp), level); if (r != a) return upgrade_brackets (r, level); //cout << " Detect dummy substitution\n"; if (replace_dummies (a) != a) { array<tree> a2= replace_dummies (a); array<int> tp2= symbol_types (a2); r= simplify_matching (a2, detect_probable (a2, tp2), level); if (r != a2) return upgrade_brackets (r, level); } //cout << " Confirm all\n"; r= simplify_matching (a, confirm_all (tp), level); if (r != a) return upgrade_brackets (r, level); //cout << " Missing left\n"; if (get_preference ("automatic brackets") != "off") r= add_missing_left (a, tp); if (r != a) return upgrade_brackets (r, level); //cout << " Missing right\n"; if (get_preference ("automatic brackets") != "off") r= add_missing_right (a, tp); if (r != a) return upgrade_brackets (r, level); } if (admits_bigops (tp)) { array<tree> r= prefix_split (a, tp, level); if (r != a) return upgrade_brackets (r, level); r= infix_split (a, tp, symbol_priorities (a), level); if (r != a) return upgrade_brackets (r, level); r= postfix_split (a, tp, level); if (r != a) return upgrade_brackets (r, level); ASSERT (tp[0] == SYMBOL_OPEN_BIG, "invalid situation"); r= upgrade_brackets (range (a, 1, N(a)), level + 1); tree body= concat_recompose (r); r= array<tree> (); r << make_around (a[0], body); return r; } return a; }
string pdf_version () { string version= get_preference ("texmacs->pdf:version"); if (version == "1.4" || version == "1.5" || version == "1.6" || version == "1.7") return version; return default_pdf_version (); }
string conservative_texmacs_to_latex (tree doc, object opts) { if (get_preference ("texmacs->latex:conservative", "off") != "on") return tracked_texmacs_to_latex (latex_expand (doc), opts); tree atts= extract (doc, "attachments"); hashmap<string,tree> atts_map (UNINIT, atts); if (!atts_map->contains ("latex-source")) return tracked_texmacs_to_latex (latex_expand (doc), opts); string lsource= as_string (atts_map["latex-source"]); tree ltarget= atts_map["latex-target"]; tree target= texmacs_unmark (ltarget); if (doc == target) return lsource; tree idoc= texmacs_invarianted (doc, ltarget, lsource); call ("latex-set-virtual-packages", get_used_packages (lsource)); string conv= tracked_texmacs_to_latex (latex_expand (idoc), opts); call ("latex-set-virtual-packages", null_object ()); if (latex_unchanged_metadata (target, doc)) conv= latex_merge_metadata (lsource, conv); if (latex_unchanged_abstract (target, doc)) conv= latex_merge_abstract (lsource, conv); //cout << "Conversion" << LF << HRULE << conv << HRULE; //if (texmacs_unchanged_preamble (target, doc)) //conv= latex_recover_preamble (conv, lsource); //else conv= latex_merge_preamble (lsource, conv); return conv; }
bool use_ps () { #ifdef PDF_RENDERER return get_preference ("native postscript", "on") == "on"; #else return true; #endif }
bool use_pdf () { #ifdef PDF_RENDERER return get_preference ("native pdf", "on") == "on"; #else return false; #endif }
bool edit_select_rep::semantic_select (path p, path& q1, path& q2, int mode) { if (!semantic_active (p)) return false; if (mode < 2 && get_preference ("semantic selections") != "on") return false; p= semantic_root (p); while (p != rp && !(p <= q1 && p <= q2)) p= semantic_root (path_up (p)); tree mt= get_env_value (MODE, end (et, p)); tree lt= get_env_value (MODE_LANGUAGE (mt->label), end (et, p)); string lan= (is_atomic (lt)? lt->label: string ("std-math")); path p1= q1 / p, p2= q2 / p; path cp= (p <= tp? tp / p: path ()); tree st= subtree (et, p); bool ret= packrat_select (lan, "Main", st, cp, p1, p2, mode); if (ret) { q1= p * p1; q2= p * p2; } return ret; }
void tm_frame_rep::interactive (object fun, scheme_tree p) { ASSERT (is_tuple (p), "tuple expected"); if (N(p) == 0) { string ret= object_to_string (call (fun)); if (ret != "" && ret != "<unspecified>" && ret != "#<unspecified>") set_message (verbatim (ret), "interactive command"); } else if (get_preference ("interactive questions") == "popup" || is_aux_buffer (get_current_buffer_safe ())) { int i, n= N(p); array<string> prompts (n); for (i=0; i<n; i++) prompts[i]= get_prompt (p, i); command cb= dialogue_command (get_server(), fun, p); widget wid= inputs_list_widget (cb, prompts); for (i=0; i<n; i++) { widget input_wid= get_form_field (wid, i); set_input_type (input_wid, get_type (p, i)); array<string> proposals= get_proposals (p, i); int j, k= N(proposals); if (k > 0) set_string_input (input_wid, proposals[0]); for (j=0; j<k; j++) add_input_proposal (input_wid, proposals[j]); } string title= translate ("Enter data"); if (ends (prompts[0], "?")) title= translate ("Question"); dialogue_start (title, wid); send_keyboard_focus (get_form_field (dialogue_wid, 0)); } else { if (concrete_window () -> get_interactive_mode ()) beep (); else { command interactive_cmd= tm_new<interactive_command_rep> (this, concrete_window (), fun, p); interactive_cmd (); } } }
void edit_main_rep::print (url name, bool conform, int first, int last) { bool ps = (suffix (name) == "ps"); bool pdf = (suffix (name) == "pdf"); url orig= resolve (name, ""); #ifdef USE_GS if (!use_pdf () && pdf) name= url_temp (".ps"); if (!use_ps () && ps) name= url_temp (".pdf"); #endif string medium = env->get_string (PAGE_MEDIUM); if (conform && (medium != "paper")) conform= false; // FIXME: better command for conform printing // Set environment variables for printing typeset_prepare (); env->write (DPI, printing_dpi); env->write (PAGE_SHOW_HF, "true"); env->write (PAGE_SCREEN_MARGIN, "false"); if (!conform) { env->write (PAGE_MEDIUM, "paper"); env->write (PAGE_PRINTED, "true"); } // Typeset pages for printing box the_box= typeset_as_document (env, subtree (et, rp), reverse (rp)); // Determine parameters for printer string page_type = env->get_string (PAGE_TYPE); double w = env->page_width; double h = env->page_height; double cm = env->as_length (string ("1cm")); bool landsc = env->page_landscape; int dpi = as_int (printing_dpi); int start = max (0, first-1); int end = min (N(the_box[0]), last); int pages = end-start; if (conform) { page_type= "user"; SI bw= the_box[0][0]->w(); SI bh= the_box[0][0]->h(); string bws= as_string (bw) * "tmpt"; string bhs= as_string (bh) * "tmpt"; w= env->as_length (bws); h= env->as_length (bhs); } // Print pages renderer ren; #ifdef PDF_RENDERER if (use_pdf () && (pdf || !use_ps ())) ren= pdf_hummus_renderer (name, dpi, pages, page_type, landsc, w/cm, h/cm); else ren= printer (name, dpi, pages, page_type, landsc, w/cm, h/cm); #else ren= printer (name, dpi, pages, page_type, landsc, w/cm, h/cm); #endif if (ren->is_started ()) { int i; ren->set_metadata ("title", get_metadata ("title")); ren->set_metadata ("author", get_metadata ("author")); ren->set_metadata ("subject", get_metadata ("subject")); for (i=start; i<end; i++) { tree bg= env->read (BG_COLOR); ren->set_background (bg); if (bg != "white") ren->clear_pattern (0, (SI) -h, (SI) w, 0); rectangles rs; the_box[0]->sx(i)= 0; the_box[0]->sy(i)= 0; the_box[0][i]->redraw (ren, path (0), rs); if (i<end-1) ren->next_page (); } } tm_delete (ren); #ifdef USE_GS if (!use_pdf () && pdf) { gs_to_pdf (name, orig, landsc, h/cm, w/cm); ::remove (name); } if (!use_ps () && ps) { gs_to_ps (name, orig, landsc, h/cm, w/cm); ::remove (name); } if (ps || pdf) if (get_preference ("texmacs->pdf:check", "off") == "on") { system_wait ("Checking exported file for correctness", "please wait"); gs_check (orig); } #endif }
void qt_tm_widget_rep::update_visibility () { #define XOR(exp1,exp2) (((!exp1) && (exp2)) || ((exp1) && (!exp2))) bool old_mainVisibility = mainToolBar->isVisible(); bool old_modeVisibility = modeToolBar->isVisible(); bool old_focusVisibility = focusToolBar->isVisible(); bool old_userVisibility = userToolBar->isVisible(); bool old_sideVisibility = sideTools->isVisible(); bool old_bottomVisibility = bottomTools->isVisible(); bool old_statusVisibility = mainwindow()->statusBar()->isVisible(); bool new_mainVisibility = visibility[1] && visibility[0]; bool new_modeVisibility = visibility[2] && visibility[0]; bool new_focusVisibility = visibility[3] && visibility[0]; bool new_userVisibility = visibility[4] && visibility[0]; bool new_statusVisibility = visibility[5]; bool new_sideVisibility = visibility[6]; bool new_bottomVisibility = visibility[7]; if ( XOR(old_mainVisibility, new_mainVisibility) ) mainToolBar->setVisible (new_mainVisibility); if ( XOR(old_modeVisibility, new_modeVisibility) ) modeToolBar->setVisible (new_modeVisibility); if ( XOR(old_focusVisibility, new_focusVisibility) ) focusToolBar->setVisible (new_focusVisibility); if ( XOR(old_userVisibility, new_userVisibility) ) userToolBar->setVisible (new_userVisibility); if ( XOR(old_sideVisibility, new_sideVisibility) ) sideTools->setVisible (new_sideVisibility); if ( XOR(old_bottomVisibility, new_bottomVisibility) ) bottomTools->setVisible (new_bottomVisibility); if ( XOR(old_statusVisibility, new_statusVisibility) ) mainwindow()->statusBar()->setVisible (new_statusVisibility); #ifndef Q_WS_MAC bool old_menuVisibility = mainwindow()->menuBar()->isVisible(); bool new_menuVisibility = visibility[0]; if ( XOR(old_menuVisibility, new_menuVisibility) ) mainwindow()->menuBar()->setVisible (new_menuVisibility); #endif //#if 0 #ifdef UNIFIED_TOOLBAR // do modifications only if needed to reduce flicker if ( XOR(old_mainVisibility, new_mainVisibility) || XOR(old_modeVisibility, new_modeVisibility) ) { // ensure that the topmost visible toolbar is always unified on Mac // (actually only for main and mode toolbars, unifying focus is not // appropriate) QBoxLayout *bl = qobject_cast<QBoxLayout*>(mainwindow()->centralWidget()->layout()); if (modeToolBarAction) modeToolBarAction->setVisible(modeToolBar->isVisible()); mainToolBarAction->setVisible(mainToolBar->isVisible()); //WARNING: jugglying around bugs in Qt unified toolbar implementation //do not try to change the order of the following operations.... if (mainToolBar->isVisible()) { bool tmp = modeToolBar->isVisible(); dumbToolBar->removeAction(modeToolBarAction); dumbToolBar->addAction(mainToolBarAction); bl->insertWidget(0, rulerWidget); bl->insertWidget(0, modeToolBar); mainToolBarAction->setVisible(true); rulerWidget->setVisible(true); modeToolBar->setVisible(tmp); if (modeToolBarAction) modeToolBarAction->setVisible(tmp); dumbToolBar->setVisible(true); } else { dumbToolBar->removeAction(mainToolBarAction); if (modeToolBar->isVisible()) { bl->removeWidget(rulerWidget); rulerWidget->setVisible(false); bl->removeWidget(modeToolBar); if (modeToolBarAction == NULL) { modeToolBarAction = dumbToolBar->addWidget(modeToolBar); } else { dumbToolBar->addAction(modeToolBarAction); } dumbToolBar->setVisible(true); } else { dumbToolBar->setVisible(false); dumbToolBar->removeAction(modeToolBarAction); } } } #endif // UNIFIED_TOOLBAR #undef XOR { QFont f = leftLabel->font(); int fs = as_int (get_preference ("gui:mini-fontsize", QTM_MINI_FONTSIZE)); f.setPixelSize (fs > 0 ? fs : QTM_MINI_FONTSIZE); leftLabel->setFont(f); rightLabel->setFont(f); } }
void initialize_color_decodings (string lan_name) { language lan= prog_language(lan_name); string pfx= "syntax:" * lan->lan_name * ":"; lan->color_decoding (-1)= get_preference (pfx * "none", "red"); lan->color_decoding (1) = get_preference (pfx * "comment", "brown"); lan->color_decoding (3) = get_preference (pfx * "error", "dark red"); lan->color_decoding (4) = get_preference (pfx * "preprocessor", "#004000"); lan->color_decoding (5) = get_preference (pfx * "preprocessor_directive", "#20a000"); lan->color_decoding (10)= get_preference (pfx * "constant", "#4040c0"); lan->color_decoding (11)= get_preference (pfx * "constant_identifier", "#4040c0"); lan->color_decoding (12)= get_preference (pfx * "constant_function", "#4040c0"); lan->color_decoding (13)= get_preference (pfx * "constant_type", "#4040c0"); lan->color_decoding (14)= get_preference (pfx * "constant_category", "#4040c0"); lan->color_decoding (15)= get_preference (pfx * "constant_module", "#4040c0"); lan->color_decoding (16)= get_preference (pfx * "constant_number", "#3030b0"); lan->color_decoding (17)= get_preference (pfx * "constant_string", "dark grey"); lan->color_decoding (18)= get_preference (pfx * "constant_char", "#333333"); lan->color_decoding (20)= get_preference (pfx * "variable", "#606060"); lan->color_decoding (21)= get_preference (pfx * "variable_identifier", "#204080"); lan->color_decoding (22)= get_preference (pfx * "variable_function", "#606060"); lan->color_decoding (23)= get_preference (pfx * "variable_type", "#00c000"); lan->color_decoding (24)= get_preference (pfx * "variable_category", "#00c000"); lan->color_decoding (25)= get_preference (pfx * "variable_module", "#00c000"); lan->color_decoding (26)= get_preference (pfx * "variable_ioarg", "#00b000"); lan->color_decoding (30)= get_preference (pfx * "declare", "#0000c0"); lan->color_decoding (31)= get_preference (pfx * "declare_identifier", "#0000c0"); lan->color_decoding (32)= get_preference (pfx * "declare_function", "#0000c0"); lan->color_decoding (33)= get_preference (pfx * "declare_type", "#0000c0"); lan->color_decoding (34)= get_preference (pfx * "declare_category", "#d030d0"); lan->color_decoding (35)= get_preference (pfx * "declare_module", "#0000c0"); lan->color_decoding (40)= get_preference (pfx * "operator", "#8b008b"); lan->color_decoding (41)= get_preference (pfx * "operator_openclose", "#B02020"); lan->color_decoding (42)= get_preference (pfx * "operator_field", "#888888"); lan->color_decoding (43)= get_preference (pfx * "operator_special", "orange"); lan->color_decoding (50)= get_preference (pfx * "keyword", "#309090"); lan->color_decoding (51)= get_preference (pfx * "keyword_conditional", "#309090"); lan->color_decoding (52)= get_preference (pfx * "keyword_control", "#000080"); }
void initialize(void) { int i; const char* p; add_preprocessor_option(yes, "-I%s", get_preference("RESOURCES_FOLDER")); root.numwindows = 0; root.messages.line = NULL; root.gldesc.max_screen_x = glutGet(GLUT_SCREEN_WIDTH); if (root.gldesc.max_screen_x <= 0) root.gldesc.max_screen_x = 1024; root.gldesc.max_screen_y = glutGet(GLUT_SCREEN_HEIGHT); if (root.gldesc.max_screen_y <= 0) root.gldesc.max_screen_y = 768; root.gldesc.max_screen_x -= 10; root.gldesc.max_screen_y -= 30; if (is_preference_on(get_preference("MULTIPLE_SCREENS")) == no) glueSetConstrainedWindows(yes); else glueSetConstrainedWindows(no); if (is_preference_on(get_preference("MULTIPLE_SCREENS")) == no) open_main_window(); init_global_lighting(); if (make_selectors() == code_bad) error(exit_program,tool_message); /* Initialize some root structure variables */ root.nummodels = 0; root.numplots = 0; root.numtools = 0; root.currentwindow = NO_WINDOW; root.modelcount = 0; root.confirm_window_open = no; root.gfont.defaultfont = SIMM_DEFAULT_FONT; root.gfont.largefont = SIMM_LARGE_FONT; root.gfont.smallfont = SIMM_SMALL_FONT; root.gfont.italics = SIMM_ITALIC_FONT; root.gfont.bold = SIMM_BOLD_FONT; /* Set all the plot pointers to NULL */ for (i=0; i<PLOTBUFFER; i++) gPlot[i] = NULL; /* Set all the model pointers to NULL */ for (i=0; i<MODELBUFFER; i++) gModel[i] = NULL; /* Set all the tool structures to unused */ for (i=0; i<TOOLBUFFER; i++) { tool[i].used = no; tool[i].name = NULL; } /* Make the [initially empty] model menu */ root.modelmenu = -1; root.plotmenu = -1; root.gravityMenu = glueCreateMenu("Gravity"); glueAddMenuEntryWithValue(root.gravityMenu, " +X", smX); glueAddMenuEntryWithValue(root.gravityMenu, " -X", smNegX); glueAddMenuEntryWithValue(root.gravityMenu, " +Y", smY); glueAddMenuEntryWithValue(root.gravityMenu, " -Y", smNegY); glueAddMenuEntryWithValue(root.gravityMenu, " +Z", smZ); glueAddMenuEntryWithValue(root.gravityMenu, " -Z", smNegZ); glueAddMenuEntryWithValue(root.gravityMenu, "none", smNoAlign); /* Init the command list */ root.num_commands = 0; for (i=0; i<COMMAND_BUFFER; i++) root.command[i] = NULL; updatemodelmenu(); /* Call routines to make the color map */ init_color_database(); /* Make the confirm-action menu */ make_confirm_menu(); /* Malloc the SIMM event queue */ root.simm_event_queue = (SimmEvent*)simm_malloc(EVENT_QUEUE_SIZE*sizeof(SimmEvent)); if (root.simm_event_queue == NULL) error(exit_program,tool_message); root.event_queue_length = EVENT_QUEUE_SIZE; root.events_in_queue = 0; }
ReturnCode init_model_display(ModelStruct* ms) { int i; ms->dis.motion_speed = DEFAULT_MOTION_SPEED; ms->dis.default_view = 0; // the default camera will be cam0 unless overridden by user ms->dis.show_highlighted_polygon = no; ms->dis.show_selected_coords = no; ms->dis.show_all_muscpts = no; ms->dis.show_shadow = no; ms->dis.applied_motion = NULL; ms->dis.current_motion = NULL; ms->dis.hpoly.segmentnum = -1; ms->dis.hpoly.bonenum = -1; ms->dis.hpoly.polynum = -1; ms->dis.continuous_motion = no; ms->dis.display_motion_info = yes; ms->dis.devs = (int*)simm_malloc(ms->numgencoords*2*sizeof(int)); ms->dis.dev_values = (int*)simm_malloc(ms->numgencoords*2*sizeof(int)); if (ms->dis.devs == NULL || ms->dis.dev_values == NULL) return code_bad; for (i=0; i<ms->numgencoords; i++) { ms->dis.devs[i*2] = ms->gencoord[i]->keys[0]; ms->dis.devs[i*2+1] = ms->gencoord[i]->keys[1]; } ms->dis.numdevs = ms->numgencoords*2; ms->dis.nummuscleson = ms->nummuscles; ms->dis.muscle_array_size = ms->muscle_array_size; if (ms->dis.muscle_array_size > 0) { ms->dis.muscleson = (int*)simm_malloc(ms->dis.muscle_array_size*sizeof(int)); if (ms->dis.muscleson == NULL) return code_bad; } ms->dis.muscle_cylinder_id = -1; for (i=0; i<ms->dis.muscle_array_size; i++) { if (i < ms->nummuscles) ms->dis.muscleson[i] = ms->muscle[i]->display; else ms->dis.muscleson[i] = 0; } for (i=0; i<COLUMNBUFFER; i++) ms->dis.menucolumns[i] = EMPTY; for (i=0; i<ms->numgroups; i++) { ms->dis.mgroup[i].state = off; ms->dis.mgroup[i].xo = -1; ms->dis.mgroup[i].yo = -1; } ms->dis.view_menu = 0; ms->dis.maindrawmodemenu = 0; ms->dis.allsegsdrawmodemenu = 0; ms->dis.allligsdrawmodemenu = 0; ms->dis.allworlddrawmodemenu = 0; ms->dis.alldrawmodemenu = 0; ms->dis.eachsegdrawmodemenu = 0; #if ! ENGINE ms->dis.display_motion_info = is_preference_on(get_preference("DISPLAY_MOTION_INFO")); #endif return code_fine; }
/* INITMODEL: this guy initializes much of the model structure. */ ReturnCode init_model(ModelStruct* ms) { int i; const char *p; // ms->modelnum is preset; store it here so you can restore it after memset(). int model_number = ms->modelnum; memset(ms, 0, sizeof(ModelStruct)); ms->modelnum = model_number; ms->is_demo_model = no; ms->useIK = yes; ms->defaultGCApproved = yes; ms->defaultLoopsOK = yes; ms->defaultConstraintsOK = yes; ms->constraintsOK = yes; ms->loopsOK = yes; ms->muscle_array_size = MUSCLE_ARRAY_INCREMENT; ms->ligament_array_size = MUSCLE_ARRAY_INCREMENT; ms->muscgroup_array_size = MUSCGROUP_ARRAY_INCREMENT; ms->world_array_size = INIT_WORLD_ARRAY_SIZE; ms->genc_array_size = GENC_ARRAY_INCREMENT; ms->segment_array_size = SEGMENT_ARRAY_INCREMENT; ms->joint_array_size = JOINT_ARRAY_INCREMENT; ms->func_array_size = FUNC_ARRAY_INCREMENT; ms->specified_min_thickness = yes; ms->specified_max_thickness = yes; ms->dynamics_ready = no; ms->max_diagonal_needs_recalc = yes; ms->GEFuncOK = no; ms->marker_visibility = yes; ms->marker_radius = DEFAULT_MARKER_RADIUS; ms->loop_tolerance = DEFAULT_LOOP_TOLERANCE; ms->loop_weight = DEFAULT_LOOP_WEIGHT; ms->solver.accuracy = DEFAULT_SOLVER_ACCURACY; ms->solver.method = smLevenbergMarquart; ms->solver.max_iterations = 100; ms->solver.joint_limits = smYes; ms->solver.orient_body = smNo; ms->solver.fg_contact = smNo; ms->global_show_masscenter = no; ms->global_show_inertia = no; ms->gravity = smNegY; ms->functionMenu = 0; ms->motion_array_size = MOTION_ARRAY_INCREMENT; ms->motion = (MotionSequence**)simm_malloc(ms->motion_array_size * sizeof(MotionSequence*)); if (ms->motion == NULL) { error(none,"Not enough memory to add another model."); return code_bad; } else { for (i = 0; i < ms->motion_array_size; i++) ms->motion[i] = NULL; } for (i=0; i<100; i++) ms->motionfilename[i] = NULL; ms->num_motion_files = 0; ms->joint = (JointStruct*)simm_malloc(ms->joint_array_size*sizeof(JointStruct)); ms->segment = (SegmentStruct*)simm_malloc(ms->segment_array_size*sizeof(SegmentStruct)); ms->muscgroup = (MuscleGroup*)simm_malloc(ms->muscgroup_array_size*sizeof(MuscleGroup)); ms->seggroup = NULL; ms->gencgroup = NULL; ms->gencoord = (GeneralizedCoord**)simm_calloc(ms->genc_array_size, sizeof(GeneralizedCoord*)); ms->muscle = (dpMuscleStruct**)simm_calloc(ms->muscle_array_size, sizeof(dpMuscleStruct*)); ms->ligament = (LigamentStruct*)simm_malloc(ms->ligament_array_size*sizeof(LigamentStruct)); ms->function = (dpFunction**)simm_calloc(ms->func_array_size, sizeof(dpFunction*)); ms->save.function = (dpFunction**)simm_calloc(ms->func_array_size, sizeof(dpFunction*)); ms->worldobj = (WorldObject*)simm_malloc(ms->world_array_size*sizeof(WorldObject)); if (ms->joint == NULL || ms->segment == NULL || ms->muscgroup == NULL || ms->gencoord == NULL || ms->function == NULL || ms->save.function == NULL || ms->worldobj == NULL) { error(none,"Not enough memory to add another model."); return code_bad; } ms->num_wrap_objects = 0; ms->wrap_object_array_size = WRAP_OBJECT_ARRAY_INCREMENT; ms->wrapobj = (dpWrapObject**)simm_malloc(ms->wrap_object_array_size*sizeof(dpWrapObject*)); if (ms->wrapobj == NULL) { error(none,"Not enough memory to add another wrap object."); return code_bad; } // ms->constraint_tolerance = DEFAULT_CONSTRAINT_TOLERANCE; ms->num_constraint_objects = 0; ms->constraint_object_array_size = CONSTRAINT_OBJECT_ARRAY_INCREMENT; ms->constraintobj = (ConstraintObject*)simm_malloc(ms->constraint_object_array_size*sizeof(ConstraintObject)); if (ms->constraintobj == NULL) { error(none,"Not enough memory to add another constraint."); return code_bad; } ms->num_deformities = 0; ms->deformity_array_size = DEFORMITY_ARRAY_INCREMENT; ms->deformity = (Deformity*) simm_malloc(ms->deformity_array_size * sizeof(Deformity)); if (ms->deformity == NULL) { error(none,"Not enough memory to add another deformity object."); return code_bad; } init_materials(ms); ms->num_motion_objects = 0; ms->motion_objects = NULL; #if ! ENGINE || OPENSMAC add_default_motion_objects(ms); #endif /* This part of the display structure must be initialized here because * it can be changed when reading in the joints file, which happens before * the display structure is initialized. */ ms->dis.num_file_views = 0; // ms->dis.muscle_array_size = 0;//dkb = MUSCLE_ARRAY_INCREMENT; ms->dis.muscle_array_size = MUSCLE_ARRAY_INCREMENT; ms->dis.fast_muscle_drawing = no; #if ! ENGINE ms->dis.fast_muscle_drawing = is_preference_on(get_preference("FASTER_MUSCLE_DRAWING")); #if INCLUDE_MSL_LENGTH_COLOR ms->dis.muscle_color_factor = 0.0; #endif for (i=0; i<MAXSAVEDVIEWS; i++) { ms->dis.view_used[i] = no; ms->dis.view_name[i] = NULL; } for (i=0; i<3; i++) { ms->dis.background_color[i] = 0.2f; ms->dis.vertex_label_color[i] = 0.0f; ms->dis.rotation_axes_color[i] = 1.0f; ms->dis.crosshairs_color[i] = 1.0f; } ms->dis.rotation_axes_color[2] = 0.0f; ms->dis.vertex_label_color[0] = 1.0f; ms->dis.background_color_spec = no; ms->dis.vertex_label_color_spec = no; ms->dis.rotation_axes_color_spec = no; ms->dis.crosshairs_color_spec = no; ms->modelLock = glutNewMutex(); ms->realtimeState = rtNotConnected; #endif /* ENGINE */ ms->gencoordmenu = -1; ms->gencoordmenu2 = -1; ms->gencoord_group_menu = -1; ms->xvarmenu = -1; ms->momentgencmenu = -1; ms->momentarmgencmenu = -1; ms->momentarmnumgencmenu = -1; ms->maxmomentgencmenu = -1; return code_fine; }
PlugExport int plugin_run(struct arglist * env) { int soc; struct sockaddr_in addr; struct in_addr *p = plug_get_host_ip(env); struct tftp_header * packet; char * p_packet; char * test_file = get_preference(env, "test_file"); char * read_timeout = get_preference(env, "checks_read_timeout"); char * file = NULL; char * test_file_with_header; int b; fd_set read_set; char * report; int flaw = 0; int len = sizeof(struct sockaddr_in); struct timeval timeout = {0,0}; int flag; if(read_timeout != NULL) { timeout.tv_sec = atoi(read_timeout); } if(timeout.tv_sec <= 0) timeout.tv_sec = 5; flag = (int)plug_get_key(env, "tftp/get_file"); if(flag)return(0); if ( test_file == NULL ) test_file = strdup("/etc/passwd"); p_packet = emalloc(512 + strlen(test_file)); packet = (struct tftp_header *)p_packet; packet->th_opcode=htons(RRQ); test_file_with_header = emalloc(strlen(test_file)+20); sprintf(test_file_with_header, "..%s", test_file); sprintf(packet->th_stuff, test_file_with_header); sprintf(packet->th_stuff+strlen(test_file_with_header)+1,"octet"); soc = socket(AF_INET, SOCK_DGRAM, 0); set_socket_source_addr( soc, 0 ); addr.sin_family = AF_INET; addr.sin_addr = *p; addr.sin_port = htons(69); connect(soc,( struct sockaddr*) &addr, sizeof(addr)); b = send(soc, packet, 22, 0); addr.sin_addr = *p; addr.sin_port = 0; b=512; while(b==512) { unsigned short block; addr.sin_addr = *p; addr.sin_port = 0; bzero(packet, 512); FD_ZERO(&read_set); FD_SET(soc, &read_set); select(soc+1, &read_set, NULL, NULL, &timeout); if(!FD_ISSET(soc, &read_set))break; b = recv(soc,packet, 512, 0); if ( b <= sizeof(struct tftp_header)) exit(0); if(ntohs(packet->th_opcode)==3) { /* We receive some data : there is a flaw */ char tmp[512]; char * tmp2; flaw++; snprintf(tmp, sizeof(tmp), "%s", packet->th_msg); if( file == NULL ) tmp2 = emalloc(sizeof(tmp)+1); else tmp2 = emalloc(strlen(file)+sizeof(tmp)+1); if( file == NULL ) strncpy(tmp2, tmp, strlen(tmp)); else snprintf(tmp2, sizeof(tmp) + 1, "%s%s", file,tmp); if(file != NULL ) efree(&file); file = emalloc(strlen(tmp2) + 1); strncpy(file, tmp2, strlen(tmp2)); efree(&tmp2); } else break; block = ntohs(packet->th_block); bzero(packet, 512); packet->th_opcode = htons(04); packet->th_block = htons(block); send(soc, packet, 4, 0); } efree(&test_file_with_header); if(flaw) { report = emalloc(255 + strlen(file) + strlen(test_file)); sprintf(report, "It was possible to retrieve the file %s\n\ through tftp by appending '..' in front of its name.\n\ Here is what we could grab : \n%s\n\n\ Solution : upgrade your tftpd", test_file, file); efree(&file); post_hole_udp(env, 69,report); } return(0); }
void AMTSimulation::simulateScores(int user, int triplet){ // Gather all documents into a set int index = 0; vector<int> rand_numbers; map<Document, int>::iterator it = _qrels.relDocs.begin(); for(;it != _qrels.relDocs.end(); it++){ allDocs.push_back((*it).first); rand_numbers.push_back(index); doc_index_map.insert(make_pair((*it).first, index)); // Initialize string code; ostringstream convert; convert << index; code = convert.str(); _utilScores[code] = arma::zeros(_qrels.relDocs.size()); _appearanceCounts[code] = arma::zeros(_qrels.relDocs.size()); index++; } set<Document>::iterator itnonrel = _qrels.nonRelDocs.begin(); for(;itnonrel != _qrels.nonRelDocs.end(); itnonrel++){ //allDocs.push_back((*itnonrel)); rand_numbers.push_back(index); //doc_index_map.insert(make_pair((*itnonrel), index)); // Initialize string code; ostringstream convert; convert << index; code = convert.str(); _utilScores[code] = arma::zeros(_qrels.relDocs.size() ); _appearanceCounts[code] = arma::zeros(_qrels.relDocs.size()); index++; } _utilScores[""] = arma::zeros(_qrels.relDocs.size()); _appearanceCounts[""] = arma::zeros(_qrels.relDocs.size()); if( _qrels.relDocs.size() < 3){ int numOfSubtopics = int(*_qrels.subtopics.rbegin()); arma::rowvec seen = arma::zeros<arma::rowvec>(numOfSubtopics); if(get_preference(_qrels.matrix.row(rand_numbers.at(0)), _qrels.matrix.row(rand_numbers.at(1)), seen)){ _utilScores[""](0) += 1; }else _utilScores[""](1) += 1; _appearanceCounts[""](0) += 1; _appearanceCounts[""](1) += 1; _utilScores[""] /= _appearanceCounts[""]; return; } // Simulate the preferences for only these 1000 triplets randomly vector<Qrels>::iterator qrels_iterator = _qrels_vector.begin(); for(int users=0;users < user; users++){ std::random_shuffle ( _qrels_vector.begin(), _qrels_vector.end() ); Qrels currentQrels = _qrels_vector.at(0); // Generate triplets and sample 1000 triplets randomly map<Triplet, int, triplet_comparison> triplets = sampleTriplets(rand_numbers, triplet); map<Triplet, int, triplet_comparison>::iterator triplet_iterator = triplets.begin(); map<Triplet, int, triplet_comparison> seen_pairs; set<int> relevantDocIndices; for(;triplet_iterator != triplets.end(); triplet_iterator++){ Triplet triplet = (*triplet_iterator).first; int numOfSubtopics = int(*currentQrels.subtopics.rbegin()); arma::rowvec seen = arma::zeros<arma::rowvec>(numOfSubtopics); if(arma::sum(currentQrels.matrix.row(triplet.topDoc)) <= 0 || triplet.topDoc >= currentQrels.matrix.n_rows ) triplet.topDoc = -1; if(arma::sum(currentQrels.matrix.row(triplet.leftDoc)) <= 0 || triplet.leftDoc >= currentQrels.matrix.n_rows) triplet.leftDoc = -1; if(arma::sum(currentQrels.matrix.row(triplet.rightDoc)) <= 0 || triplet.rightDoc >= currentQrels.matrix.n_rows) triplet.rightDoc = -1; // Update the scores // Keep Track of level 1 pairs for this user profile if(triplet.topDoc == -1){ if(triplet.leftDoc != -1 && triplet.rightDoc != -1){ if(checkPairs(seen_pairs, triplet.leftDoc, triplet.rightDoc)) continue; }else continue; }else if(triplet.topDoc != -1){ seen += currentQrels.matrix.row(triplet.topDoc); } if(triplet.leftDoc != -1 && triplet.rightDoc != -1){ if(get_preference(currentQrels.matrix.row(triplet.leftDoc), currentQrels.matrix.row(triplet.rightDoc), seen)) updateScores(triplet.topDoc, triplet.leftDoc, triplet.rightDoc, true); else updateScores(triplet.topDoc, triplet.leftDoc, triplet.rightDoc, false); } if(relevantDocIndices.find(triplet.topDoc) == relevantDocIndices.end() && triplet.topDoc != -1) relevantDocIndices.insert(triplet.topDoc); if(relevantDocIndices.find(triplet.leftDoc) == relevantDocIndices.end() && triplet.leftDoc != -1) relevantDocIndices.insert(triplet.leftDoc); if(relevantDocIndices.find(triplet.rightDoc) == relevantDocIndices.end() && triplet.rightDoc != -1) relevantDocIndices.insert(triplet.rightDoc); } /*map<string, arma::vec>::iterator codes = _utilScores.begin(); for(;codes!= _utilScores.end(); codes++){ set<int>::iterator relevantDocIterator = relevantDocIndices.begin(); for(; relevantDocIterator != relevantDocIndices.end(); relevantDocIterator++){ if((*codes).first != ""){ if((*relevantDocIterator) != atoi((*codes).first.c_str())) _utilScores[(*codes).first](*relevantDocIterator) += 1; }else _utilScores[(*codes).first](*relevantDocIterator) += 1; } _appearanceCounts[(*codes).first] += 2; }*/ } map<string, arma::vec>::iterator codes = _utilScores.begin(); for(;codes!= _utilScores.end(); codes++){ _utilScores[(*codes).first] /= (_appearanceCounts[(*codes).first] + 2); } }
bool supports_db () { return get_preference ("database tool") == "on"; }