path find_scrolled_box_path (box b, path sp, SI x, SI y, SI delta) { if (is_nil (sp)) return b->find_box_path (x, y, delta, false); else { int m= sp->item; SI xx= x - b->sx (m), yy= y - b->sy (m); SI dd= delta + get_delta (xx, b[m]->x1, b[m]->x2); return path (m, find_scrolled_box_path (b[m], sp->next, xx, yy, dd)); } }
/* ditto: */ void check_marks_int_list(sexpr x) { if (!GC_is_marked((ptr_t)x)) GC_printf("[unm:%p]", x); else GC_printf("[mkd:%p]", x); if (is_nil(x)) { (void)GC_printf("NIL\n"); } else { if (!GC_is_marked((ptr_t)car(x))) GC_printf("[unm car:%p]", car(x)); (void)GC_printf("(%d)", SEXPR_TO_INT(car(car(x)))); if (!is_nil(cdr(x))) { (void)GC_printf(", "); (void)check_marks_int_list(cdr(x)); } else { (void)GC_printf("\n"); } } }
void edit_env_rep::patch_env (hashmap<string,tree> patch) { if (patch->size == 0) return; int i=0, n=patch->n; for (; i<n; i++) { list<hashentry<string,tree> > l=patch->a[i]; for (; !is_nil(l); l=l->next) write_update (l->item.key, l->item.im); } }
path box_rep::find_box_path (path p, bool& found) { // cout << "Find box path " << box (this) << ", " << p // << "; " << reverse (ip) // << ", " << reverse (find_lip ()) // << " -- " << reverse (find_rip ()) << "\n"; found= (!is_nil(p)) && is_accessible (ip); if (last_item (p) == 0) return path (0); else return path (1); }
void bridge_compound_rep::notify_assign (path p, tree u) { // cout << "Assign " << p << ", " << u << " in " << st << "\n"; ASSERT (!is_nil (p) || L(u) >= START_EXTENSIONS, "nil path"); if (is_nil (p) || (p->item == 0) || is_nil (body)) { st= substitute (st, p, u); valid= false; } else { // bool mp_flag= is_multi_paragraph (st); if (is_func (fun, XMACRO, 2)) notify_macro (MACRO_ASSIGN, fun[0]->label, -1, p, u); else if (is_applicable (fun) && (p->item < N(fun))) notify_macro (MACRO_ASSIGN, fun[p->item-delta]->label, -1, p->next, u); st= substitute (st, p, u); // if (mp_flag != is_multi_paragraph (st)) valid= false; } status= CORRUPTED; }
void edit_select_rep::selection_set_start (path p) { if (!selection_active_any ()) { if (rp < start_p) select (start_p, start_p); else select (tp, tp); } if (is_nil (p)) selection_set_start (tp); else if (path_less_eq (end_p, p)) select (p, p); else if (rp < p) select (p, end_p); }
void rgive(bvm_cache *this_bvm, mword *list){ // rgive# if(is_nil(list)) return; pushd(this_bvm, (mword*)car(list), IMMORTAL); rgive(this_bvm,(mword*)cdr(list)); }
void bridge_compound_rep::initialize (tree body_t, int delta2, tree fun2) { if ((!valid) || (body->st != body_t) || (delta != delta2) || (fun != fun2)) { valid= true; if (is_nil (body)) body= make_bridge (ttt, attach_right (body_t, ip)); else replace_bridge (body, attach_right (body_t, ip)); delta= delta2; fun = fun2; } }
glyph poor_bbb_font_rep::get_glyph (string s) { glyph gl= base->get_glyph (s); if (is_nil (gl)) return gl; font_metric fnm; font_glyphs fng; int c= base->index_glyph (s, fnm, fng); if (c < 0) return glyph (); return make_bbb (gl, c, wpen, hpen, fat); }
void edit_env_rep::local_end (hashmap<string,tree>& prev_back) { int i=0, n=back->n; for (; i<n; i++) { list<hashentry<string,tree> > l=back->a[i]; for (; !is_nil(l); l=l->next) prev_back->write_back (l->item.key, back); } back= prev_back; }
static void SetUpHazMatItem(ref<CWarehouseItem> wh_item) { auto hazmat_item = goods_cast<CHazardousItem>(wh_item); if (hazmat_item.is_nil()) { return; } modify(hazmat_item)->SetHazMatCode(L"HZM-12"); modify(hazmat_item)->SetExtraData(GetItemBlobDaata()); }
tree texmacs_evaluate (environment env, tree t) { // re-entrancy if (!is_nil (reenter_rewrite_env)) env= reenter_rewrite_env; environment old_env= std_env; std_env= env; tree r= evaluate (t); std_env= old_env; return r; }
void bridge_document_rep::notify_assign (path p, tree u) { // cout << "Assign " << p << ", " << u << " in " << st << "\n"; ASSERT (!is_nil (p) || is_func (u, DOCUMENT) || is_func (u, PARA), "nil path"); if (is_nil (p)) { st= u; initialize (); } else { if (is_atom (p)) { replace_bridge (brs[p->item], u, descend (ip, p->item)); st= substitute (st, p->item, brs[p->item]->st); } else { brs[p->item]->notify_assign (p->next, u); st= substitute (st, p->item, brs[p->item]->st); } if (!is_nil (acc)) acc->notify_assign (p, u); } status= CORRUPTED; }
bool bridge_document_rep::my_typeset_will_be_complete () { if (is_nil (acc)) { int i, n= N(brs); for (i=0; i<n; i++) if (!brs[i]->my_typeset_will_be_complete ()) return false; return true; } else return acc->my_typeset_will_be_complete (); }
void bridge_document_rep::my_exec_until (path p) { if (is_nil (acc)) { int i; for (i=0; i<p->item; i++) brs[i]->exec_until (path (right_index (brs[i]->st)), true); if (i<N(st)) brs[i]->exec_until (p->next); } else acc->my_exec_until (p); }
path edit_select_rep::focus_get (bool skip_flag) { //cout << "Search focus " << focus_p << ", " << skip_flag << "\n"; if (!is_nil (focus_p)) return focus_search (focus_p, skip_flag, false); if (selection_active_any ()) return focus_search (selection_get_path (), skip_flag, false); else return focus_search (path_up (tp), skip_flag, true); }
highlight_box_rep::highlight_box_rep (path ip, box b, box xb, ornament_parameters ps): change_box_rep (ip, true), shape (ps->shape), lw (ps->lw), bw (ps->bw), rw (ps->rw), tw (ps->tw), lx ((SI) (ps->lext * lw)), bx ((SI) (ps->bext * bw)), rx ((SI) (ps->rext * rw)), tx ((SI) (ps->text * tw)), lpad (ps->lpad), bpad (ps->bpad), rpad (ps->rpad), tpad (ps->tpad), bg (ps->bg), xc (ps->xc), bc (ps->border) { ASSERT (N(bc) == 4 || N(bc) == 8, "invalid number of border colors"); if (shape == "ring" || shape == "band") { lpad= lpad + rpad; rpad= 0; } SI offx= 0, offy= 0; insert (b, lpad, 0); if (!is_nil (xb)) { offx= b->x1 - xb->x1; offy= b->y2 - xb->y1 + bpad + tpad; insert (xb, offx + lpad, offy); } position (); x1= b->x1; y1= b->y1 - bpad; x2= b->x2 + lpad + rpad; y2= b->y2 + tpad; x3= min (x1 - lx, b->x3 + lpad); y3= min (y1 - bx, b->y3); x4= max (x2 + rx, b->x4 + lpad); y4= max (y2 + tx, b->y4); if (!is_nil (xb)) { x1= min (x1, offx + xb->x1); y1= min (y1, offy + xb->y1 - bpad); x2= max (x2, offx + xb->x2 + lpad + rpad); y2= max (y2, offy + xb->y2 + tpad); x3= min (x3, min (x1, offx + xb->x3 + lpad)); y3= min (y3, min (y1, offy + xb->y3)); x4= max (x4, max (x2, offx + xb->x4 + lpad)); y4= max (y4, max (y2, offy + xb->y4)); } finalize (); }
void edit_select_rep::selection_paste (string key) { tree t; string s; (void) ::get_selection (key, t, s, selection_import); if (inside_active_graphics ()) { if (is_tuple (t, "texmacs", 3)) call ("graphics-paste", t[1]); return; } if (is_tuple (t, "extern", 1)) { string mode= get_env_string (MODE); string lan = get_env_string (MODE_LANGUAGE (mode)); if ((selection_import == "latex") && (mode == "prog")) mode= "verbatim"; if ((selection_import == "latex") && (mode == "math")) mode= "latex-math"; if ((selection_import == "html") && (mode == "prog")) mode= "verbatim"; string fm= selection_import * "-snippet"; tree doc= generic_to_tree (selection_decode(lan, as_string(t[1])), fm); if (is_func (doc, DOCUMENT, 1)) doc= doc[0]; // temporary fix insert_tree (doc); } if (is_tuple (t, "texmacs", 3)) { string mode= get_env_string (MODE); string lan = get_env_string (MODE_LANGUAGE (mode)); if (is_compound (t[1], "text", 1) && mode == "text") t= tuple ("texmacs", t[1][0], "text", lan); if (is_compound (t[1], "math", 1) && mode == "math") t= tuple ("texmacs", t[1][0], "math", lan); if (mode == "math" && t[2] == "text") set_message ("Error: invalid paste of text into a formula", "paste"); else if (mode == "prog" && t[2] == "math") { tree in= tuple (lan, t[1]); tree r= stree_to_tree (call ("plugin-math-input", tree_to_stree (in))); insert_tree (r); } else { if ((t[2] != mode) && (t[2] != "src") && (mode != "src") && ((t[2] == "math") || (mode == "math"))) { if (t[2] == "math") insert_tree (compound ("math", ""), path (0, 0)); else if (t[2] == "text") insert_tree (compound ("text", ""), path (0, 0)); else insert_tree (tree (WITH, copy (MODE), copy (t[2]), ""), path (2, 0)); } if (is_func (t[1], TFORMAT) || is_func (t[1], TABLE)) { int row, col; path fp= search_format (row, col); if (is_nil (fp)) insert_tree (compound (copy (TABULAR), t[1])); else table_write_subtable (fp, row, col, t[1]); } else insert_tree (t[1]); } } }
/* stack operator **down** (<-) > Analogous to doing a cdr on the stack itself. If the code\_ptr > becomes nil after executing one or more downs without a balancing > up, as many ups as are required to undo the downs will be executed > automatically. */ bvm_cache *down(bvm_cache *this_bvm){ // down# if(is_nil(this_bvm->dstack_ptr)) return this_bvm; pushu(this_bvm, dstack_get(this_bvm,0), IMMORTAL); popd(this_bvm); return this_bvm; }
tree edit_graphics_rep::graphical_select ( double x1, double y1, double x2, double y2) { frame f= find_frame (); if (is_nil (f)) return tuple (); gr_selections sels; point p1 = f (point (x1, y1)), p2= f (point (x2, y2)); sels= eb->graphical_select ((SI)p1[0], (SI)p1[1], (SI)p2[0], (SI)p2[1]); return as_tree (sels); }
void bridge_docrange_rep::notify_assign (path p, tree u) { ASSERT (!is_nil (p), "erroneous nil path"); if (divide) { int i, n= N(acc); for (i=0; i<n; i++) if ((p->item >= mid[i]) && (p->item < mid[i+1])) acc[i]->notify_assign (p, u); } status= CORRUPTED; }
/* stack operator **up** (->) > Undoes down */ bvm_cache *up(bvm_cache *this_bvm){ // up# if(is_nil(this_bvm->ustack_ptr)) // FIXME: Wrong return this_bvm; pushd(this_bvm, ustack_get(this_bvm,0), IMMORTAL); popu(this_bvm); return this_bvm; }
template <class T, class U> void rel_hashmap_rep<T,U>::change (hashmap<T,U> CH) { int i; for (i=0; i<CH->n; i++) { list<hashentry<T,U> > l (CH->a[i]); while (!is_nil (l)) { item (l->item.key)= l->item.im; l=l->next; } } }
void type_check_assign(Type tv,Type te) { if( tv==te ) return; if( is_numeric(tv) && is_numeric(te) && (te<=tv) ) return; if( ttab.type[tv].kind==POINTER_KIND && is_nil(te) ) return; if( is_string(tv) && ttab.type[te].strconst ) { if( ttab.type[te].size <= ttab.type[tv].size ) return; } fatal_error("invalid types in assignment\n"); }
void notify_insert_node (typesetter ttt, path p, tree t) { // cout << "Insert node " << p << ", " << t << "\n"; int i, pos= last_item (p), n= N(t); tree r (t, n+1); for (i=0; i<pos; i++) r[i]= t[i]; r[pos]= subtree (ttt->br->st, path_up (p)); for (i=pos; i<n; i++) r[i+1]= t[i]; if (is_nil (path_up (p))) ttt->br= make_bridge (ttt, r, ttt->br->ip); else ttt->br->notify_assign (path_up (p), r); }
widget make_menu_widget (object menu) { widget w= as_widget (call ("make-menu-widget", menu, 0)); //string s= "(make-menu-widget '" * menu * " 0)"; //widget w= as_widget (eval (s)); if (is_nil (w)) { array<widget> a (0); return horizontal_menu (a); } return w; }
void concater_rep::typeset_anim_accelerate (tree t, path ip) { if (N(t) != 2) { typeset_error (t, ip); return; } path uip= undecorate (ip); while (!has_subtree (the_et, reverse (uip))) uip= uip->next; player apl= get_player (uip); if (!is_nil (uip) && !has_player (uip)) { path aip= search_animation_ip (uip); player pl = is_nil (aip)? player (): get_player (aip); apl= accelerate (pl, t[1]); tree st= subtree (the_et, reverse (uip)); blackbox bb= close_box<player> (apl); (void) tree_addendum_new (st, ADDENDUM_PLAYER, bb, false); } box b= typeset_as_concat (env, t[0], descend (ip, 0)); apl->set_duration (b->anim_duration ()); array<box> bs; bs << b; print (composite_box (ip, bs)); }
sexp* set_in_env(sexp* e, sexp* var, sexp* val) { for (;!is_nil(e); e = cdr(e)) { sexp* defn = car(e); if (equal(var, car(defn))) { cdr(defn) = val; return &nil_sexp; } } error("Attempting to set! an undefined symbol: %s", var->symbol); return NULL; }
string count_trace (font fn, array<int> cs) { array<int> a; for (int i= 0; i < N(cs); i++) { string s; s << ((char) cs[i]); glyph g= fn->get_glyph (s); if (is_nil (g)) return ""; a << pixel_count (g); } return array_trace (a); }
bool is_table_selection (tree et, path p1, path p2, bool strict) { if (p1 == p2) return false; path p= common (p1, p2); if ((p == p1 || p == p2) && !is_nil (p)) p= path_up (p); tree t= subtree (et, p); return is_func (t, TFORMAT) || is_func (t, TABLE) || is_func (t, ROW) || is_func (t, CELL) || (!strict && N(t) == 1 && is_func (t[0], TFORMAT)); }