static int run_scan_argument(lua_State * L) /* HH */ { /* can be simplified, no need for intermediate list */ saved_tex_scanner texstate; halfword t, saved_defref; save_tex_scanner(texstate); do { get_token(); } while ((cur_cmd == spacer_cmd) || (cur_cmd == relax_cmd)); if (cur_cmd == left_brace_cmd) { back_input(); saved_defref = def_ref; (void) scan_toks(false, true); t = def_ref; def_ref = saved_defref; tokenlist_to_luastring(L,t); flush_list(t); } else if (cur_cmd == call_cmd) { halfword saved_cur_tok = cur_tok; cur_tok = right_brace_token + '}'; back_input(); cur_tok = saved_cur_tok; back_input(); cur_tok = left_brace_token + '{'; back_input(); saved_defref = def_ref; (void) scan_toks(false, true); t = def_ref; def_ref = saved_defref; tokenlist_to_luastring(L,t); flush_list(t); } else if (cur_cmd == 11 || cur_cmd == 12 ) { declare_buffer; while (1) { add_to_buffer(cur_chr); get_x_token(); if (cur_cmd != 11 && cur_cmd != 12 ) { break ; } } back_input(); push_buffer; } else { back_input(); lua_pushnil(L); } unsave_tex_scanner(texstate); return 1; }
void expand_macros_in_tokenlist(halfword p) { int old_mode; pointer q= get_avail(); pointer r= get_avail(); token_info(q)= right_brace_token+'}'; token_link(q)= r; token_info(r)= end_write_token; begin_token_list(q,inserted); begin_token_list(write_tokens(p),write_text); q= get_avail(); token_info(q)= left_brace_token+'{'; begin_token_list(q,inserted); old_mode= mode; mode= 0; cur_cs= write_loc; q= scan_toks(false,true); get_token(); if(cur_tok!=end_write_token){ const char*hlp[]= { "On this page there's a \\write with fewer real {'s than }'s.", "I can't handle that very well; good luck.",NULL }; tex_error("Unbalanced write command",hlp); do{ get_token(); }while(cur_tok!=end_write_token); } mode= old_mode; end_token_list(); }
static int run_scan_toks(lua_State * L) { saved_tex_scanner texstate; int macro_def = false, xpand = false; halfword t, saved_defref; int i = 1; int top = lua_gettop(L); if (top>0) macro_def = lua_toboolean(L,1); /* \\def ? */ if (top>1) xpand = lua_toboolean(L,2); /* expand ? */ save_tex_scanner(texstate); saved_defref = def_ref; (void) scan_toks(macro_def, xpand); t = def_ref; unsave_tex_scanner(texstate); def_ref = saved_defref; /* This function returns a pointer to the tail of a new token list, and it also makes |def_ref| point to the reference count at the head of that list. */ lua_newtable(L); while (token_link(t)) { t = token_link(t); push_token(L,t); lua_rawseti(L,-2,i++); } return 1; }
static void do_extension_dvi(int immediate) { if(scan_keyword("literal")){ new_whatsit(special_node); write_stream(tail)= null; scan_toks(false,true); write_tokens(tail)= def_ref; }else{ tex_error("unexpected use of \\dviextension",null); } }
void tex::make_mark () { ptr p; scan_toks(FALSE, TRUE); p = new_node(SMALL_NODE_SIZE); type(p) = MARK_NODE; subtype(p) = 0; mark_ptr(p) = def_ref; tail_append(p); }
static void do_extension_pdf(int immediate) { int i; if(scan_keyword("literal")){ new_whatsit(pdf_literal_node); if(scan_keyword("direct")) set_pdf_literal_mode(tail,direct_always); else if(scan_keyword("page")) set_pdf_literal_mode(tail,direct_page); else set_pdf_literal_mode(tail,set_origin); scan_toks(false,true); set_pdf_literal_type(tail,normal); set_pdf_literal_data(tail,def_ref); }else if(scan_keyword("dest")){ scan_pdfdest(static_pdf); }else if(scan_keyword("annot")){ scan_annot(static_pdf); }else if(scan_keyword("save")){ new_whatsit(pdf_save_node); }else if(scan_keyword("restore")){ new_whatsit(pdf_restore_node); }else if(scan_keyword("setmatrix")){ new_whatsit(pdf_setmatrix_node); scan_toks(false,true); set_pdf_setmatrix_data(tail,def_ref); }else if(scan_keyword("obj")){ scan_obj(static_pdf); if(immediate){ if(obj_data_ptr(static_pdf,pdf_last_obj)==0) normal_error("pdf backend","\\pdfextension obj 'reserveobjnum' cannot be used with \\immediate"); pdf_write_obj(static_pdf,pdf_last_obj); } }else if(scan_keyword("refobj")){ scan_refobj(static_pdf); }else if(scan_keyword("colorstack")){ scan_int(); if(cur_val>=colorstackused()){ print_err("Unknown color stack number "); print_int(cur_val); help3 ("Allocate and initialize a color stack with \\pdfextension colorstackinit.", "I'll use default color stack 0 here.", "Proceed, with fingers crossed."); error(); cur_val= 0; } if(cur_val<0){ print_err("Invalid negative color stack number"); help2("I'll use default color stack 0 here.", "Proceed, with fingers crossed."); error(); cur_val= 0; } if(scan_keyword("set")) i= colorstack_set; else if(scan_keyword("push")) i= colorstack_push; else if(scan_keyword("pop")) i= colorstack_pop; else if(scan_keyword("current")) i= colorstack_current; else i= -1; if(i>=0){ new_whatsit(pdf_colorstack_node); set_pdf_colorstack_stack(tail,cur_val); set_pdf_colorstack_cmd(tail,i); set_pdf_colorstack_data(tail,null); if(i<=colorstack_data){ scan_toks(false,true); set_pdf_colorstack_data(tail,def_ref); } }else{ print_err("Color stack action is missing"); help3("The expected actions for \\pdfextension colorstack:", " set, push, pop, current", "I'll ignore the color stack command."); error(); } }else if(scan_keyword("startlink")){ scan_startlink(static_pdf); }else if(scan_keyword("endlink")){ if(abs(mode)==vmode) normal_error("pdf backend","\\pdfextension endlink cannot be used in vertical mode"); new_whatsit(pdf_end_link_node); }else if(scan_keyword("startthread")){ new_annot_whatsit(pdf_start_thread_node); scan_thread_id(); }else if(scan_keyword("endthread")){ new_whatsit(pdf_end_thread_node); }else if(scan_keyword("thread")){ new_annot_whatsit(pdf_thread_node); scan_thread_id(); }else if(scan_keyword("outline")){ scan_pdfoutline(static_pdf); }else if(scan_keyword("glyphtounicode")){ glyph_to_unicode(); }else if(scan_keyword("catalog")){ scan_pdfcatalog(static_pdf); }else if(scan_keyword("fontattr")){ scan_font_ident(); i= cur_val; if(i==null_font) normal_error("pdf backend","invalid font identifier"); scan_toks(false,true); set_pdf_font_attr(i,tokens_to_string(def_ref)); if(str_length(pdf_font_attr(i))==0){ flush_str((str_ptr-1)); set_pdf_font_attr(i,0); } }else if(scan_keyword("mapfile")){ scan_toks(false,true); pdfmapfile(def_ref); delete_token_ref(def_ref); }else if(scan_keyword("mapline")){ scan_toks(false,true); pdfmapline(def_ref); delete_token_ref(def_ref); }else if(scan_keyword("includechars")){ pdf_include_chars(static_pdf); }else if(scan_keyword("info")){ scan_toks(false,true); pdf_info_toks= concat_tokens(pdf_info_toks,def_ref); }else if(scan_keyword("names")){ scan_toks(false,true); pdf_names_toks= concat_tokens(pdf_names_toks,def_ref); }else if(scan_keyword("trailer")){ scan_toks(false,true); pdf_trailer_toks= concat_tokens(pdf_trailer_toks,def_ref); }else{ tex_error("unexpected use of \\pdfextension",null); } }
void do_extension(int immediate) { halfword p; if(cur_cmd==extension_cmd){ switch(cur_chr){ case open_code: p= tail; new_write_whatsit(open_node_size,1); scan_optional_equals(); scan_file_name(); open_name(tail)= cur_name; open_area(tail)= cur_area; open_ext(tail)= cur_ext; if(immediate){ out_what(static_pdf,tail); flush_node_list(tail); tail= p; vlink(p)= null; } break; case write_code: p= tail; new_write_whatsit(write_node_size,0); cur_cs= write_stream(tail); scan_toks(false,false); write_tokens(tail)= def_ref; if(immediate){ out_what(static_pdf,tail); flush_node_list(tail); tail= p; vlink(p)= null; } break; case close_code: p= tail; new_write_whatsit(close_node_size,1); write_tokens(tail)= null; if(immediate){ out_what(static_pdf,tail); flush_node_list(tail); tail= p; vlink(p)= null; } break; case special_code: new_whatsit(special_node); write_stream(tail)= null; p= scan_toks(false,true); write_tokens(tail)= def_ref; break; case immediate_code: get_x_token(); do_extension(1); break; case use_box_resource_code: case use_image_resource_code: case save_box_resource_code: case save_image_resource_code: switch(get_o_mode()){ case OMODE_DVI: do_resource_dvi(immediate,cur_chr); break; case OMODE_PDF: do_resource_pdf(immediate,cur_chr); break; default: break; } break; case dvi_extension_code: if(get_o_mode()==OMODE_DVI) do_extension_dvi(immediate); break; case pdf_extension_code: if(get_o_mode()==OMODE_PDF) do_extension_pdf(immediate); break; default: if(immediate){ back_input(); }else{ confusion("invalid extension"); } break; } }else{ back_input(); } }
void scan_pdfximage(PDF pdf) { scaled_whd alt_rule; image_dict *idict; int transform = 0, page = 1, pagebox, colorspace = 0; char *named = NULL, *attr = NULL, *file_name = NULL, *user = NULL, *owner = NULL, *visible = NULL; alt_rule = scan_alt_rule(); if (scan_keyword("attr")) { scan_toks(false, true); attr = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("named")) { scan_toks(false, true); if (0) { named = tokenlist_to_cstring(def_ref, true, NULL); page = 0; } else { normal_warning("pdf backend","named pages are not supported, using page 1"); page = 1; } delete_token_ref(def_ref); } else if (scan_keyword("page")) { scan_int(); page = cur_val; } if (scan_keyword("userpassword")) { scan_toks(false, true); user = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("ownerpassword")) { scan_toks(false, true); owner = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("visiblefilename")) { scan_toks(false, true); visible = tokenlist_to_cstring(def_ref, true, NULL); delete_token_ref(def_ref); } if (scan_keyword("colorspace")) { scan_int(); colorspace = cur_val; } pagebox = scan_pdf_box_spec(); if (pagebox == PDF_BOX_SPEC_NONE) { pagebox = pdf_pagebox; if (pagebox == PDF_BOX_SPEC_NONE) pagebox = PDF_BOX_SPEC_CROP; } scan_toks(false, true); file_name = tokenlist_to_cstring(def_ref, true, NULL); if (file_name == NULL) { normal_error("pdf backend","no image filename given"); } delete_token_ref(def_ref); idict = read_image(file_name, page, named, colorspace, pagebox, user, owner, visible); img_attr(idict) = attr; img_dimen(idict) = alt_rule; img_transform(idict) = transform; last_saved_image_index = img_objnum(idict); last_saved_image_pages = img_totalpages(idict); }