Ejemplo n.º 1
0
void tex::sub_sup ()
	{
	ptr	p;
	int	t;

	p = null;
	t = EMPTY;
	if (tail != head && scripts_allowed(tail)) {
		p = (cur_cmd == SUP_MARK) ? supscr(tail) : subscr(tail);
		t = math_type(p);
	}
	if (p == null || t != EMPTY) {
		tail_append(new_noad());
		p = (cur_cmd == SUP_MARK) ? supscr(tail) : subscr(tail);
		if (t != EMPTY) {
			if (cur_cmd == SUP_MARK) {
				print_err("Double superscript");
				help_double_sup();
			} else {
				print_err("Double subscript");
				help_double_sub();
			}
			error();
		}
	}
	scan_math(p);
}
Ejemplo n.º 2
0
void tex::math_left_right ()
	{
	ptr	p;
	int	t;
	mcell	garbage;

	t = cur_chr;
	if (t == RIGHT_NOAD && cur_group != MATH_LEFT_GROUP) {
		if (cur_group == MATH_SHIFT_GROUP) {
			scan_delimiter((ptr)&garbage, FALSE);
			print_err("Extra ");
			print_esc("right");
			help_xtra_right();
			error();
		} else {
			off_save();
		}
	} else {
		p = new_noad();
		type(p) = t;
		scan_delimiter(delimiter(p), FALSE);
		if (t == LEFT_NOAD) {
			push_math(MATH_LEFT_GROUP);
			tail = link(head) = p;
		} else {
			p = fin_mlist(p);
			unsave();
			tail_append(new_noad());
			type(tail) = INNER_NOAD;
			math_type(nucleus(tail)) = SUB_MLIST;
			math_link(nucleus(tail)) = p;
		}
	}
}
Ejemplo n.º 3
0
void tex::math_ac ()
	{
	if (cur_cmd == ACCENT) {
		print_err("Please use ");
		print_esc("mathaccent");
		print(" for accents in math mode");
		help_math_accent();
		error();
	}
	tail_append(new_node(ACCENT_NOAD_SIZE));
	type(tail) = ACCENT_NOAD;
	subtype(tail) = NORMAL;
	mzero(nucleus(tail));
	mzero(subscr(tail));
	mzero(supscr(tail));
	math_type(accent_chr(tail)) = MATH_CHAR;
	scan_fifteen_bit_int();
	character(accent_chr(tail)) = cur_val % 256;
	if (cur_val >= VAR_CODE && fam_in_range()) {
		fam(accent_chr(tail)) = cur_fam;
	} else {
		fam(accent_chr(tail)) = cur_val / 256 % 16;
	}
	scan_math(nucleus(tail));
	}
Ejemplo n.º 4
0
static void write_image_or_node(lua_State * L, wrtype_e writetype)
{
    image *a, **aa;
    image_dict *ad;
    halfword n;
    if (lua_gettop(L) != 1)
        luaL_error(L, "%s expects an argument", wrtype_s[writetype]);
    if (lua_istable(L, 1))
        (void) l_new_image(L);
    aa = (image **) luaL_checkudata(L, 1, TYPE_IMG);
    a = *aa;
    ad = img_dict(a);
    setup_image(static_pdf, a, writetype);
    switch (writetype) {
        case WR_WRITE:
            n = img_to_node(L, a);
            tail_append(n);
            break;
        case WR_IMMEDIATEWRITE:
            write_img(static_pdf, ad);
            break;
        case WR_NODE:
            lua_pop(L, 1); /* - */
            n = img_to_node(L, a);
            lua_nodelib_push_fast(L, n);
            break;
        default:
            luaL_error(L, "%s expects an valid image", wrtype_s[writetype]);
    }
    if (img_state(ad) < DICT_REFERED)
        img_state(ad) = DICT_REFERED;
}
Ejemplo n.º 5
0
void tex::set_math_char(int c)
	{
	ptr	p;

	if (c >= 0100000) {
		cur_cs = active_base[cur_chr];
		cur_cmd = eq_type(cur_cs);
		cur_chr = equiv(cur_cs);
		x_token();
		back_input();
	} else {
		p = new_noad();
		math_type(nucleus(p)) = MATH_CHAR;
		character(nucleus(p)) = c % 256;
		fam(nucleus(p)) = c / 256 % 16;
		if (c >= VAR_CODE) {
			if (fam_in_range())
				fam(nucleus(p)) = cur_fam;
			type(p) = ORD_NOAD;
		} else {
			type(p) = ORD_NOAD + c / 010000;
		}
		tail_append(p);
	}
}
Ejemplo n.º 6
0
void tex::append_penalty ()
	{
	scan_int();
	tail_append(new_penalty(cur_val));
	if (mode == VMODE) 
		build_page();
	}
Ejemplo n.º 7
0
static void write_image_or_node(lua_State * L, wrtype_e writetype)
{
    image *a, **aa;
    image_dict *ad;
    halfword n;
    if (lua_gettop(L) != 1)
        luaL_error(L, "%s needs exactly 1 argument", wrtype_s[writetype]);
    if (lua_istable(L, 1))
        (void) l_new_image(L);  /* image --- if everything worked well */
    aa = (image **) luaL_checkudata(L, 1, TYPE_IMG);    /* image */
    a = *aa;
    ad = img_dict(a);
    setup_image(static_pdf, a, writetype);
    switch (writetype) {
    case WR_WRITE:
        n = img_to_node(a);
        tail_append(n);
        break;                  /* image */
    case WR_IMMEDIATEWRITE:
        write_img(static_pdf, ad);
        break;                  /* image */
    case WR_NODE:              /* image */
        lua_pop(L, 1);          /* - */
        n = img_to_node(a);
        lua_nodelib_push_fast(L, n);
        break;                  /* node */
    default:
        assert(0);
    }
    if (img_state(ad) < DICT_REFERED)
        img_state(ad) = DICT_REFERED;
}
Ejemplo n.º 8
0
void tex::append_choices ()
	{
	tail_append(new_choice());
	incr(save_ptr);
	saved(-1) = 0;
	scan_left_brace();
	push_math(MATH_CHOICE_GROUP);
	}
Ejemplo n.º 9
0
bool tex::its_all_over ()
	{
	if (privileged()) {
		if (page_head == page_tail
			 && head == tail
			 && dead_cycles == 0) {
			return TRUE;
			}
		back_input();
		tail_append(new_null_box());
		box_width(tail) = hsize;
		tail_append(new_glue(fill_glue));
		tail_append(new_penalty(-010000000000));
		build_page();
		}
	return FALSE;
	}
Ejemplo n.º 10
0
void tex::append_kern ()
	{
	int	s;
	
	s = cur_chr;
	scan_dimen(s == MU_GLUE, FALSE, FALSE);
	tail_append(new_kern(cur_val));
	subtype(tail) = s;
	}
Ejemplo n.º 11
0
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);
	}
Ejemplo n.º 12
0
void tex::math_radical ()
	{
	tail_append(new_node(RADICAL_NOAD_SIZE));
	type(tail) = RADICAL_NOAD;
	subtype(tail) = NORMAL;
	mzero(nucleus(tail));
	mzero(supscr(tail));
	mzero(subscr(tail));
	scan_delimiter(left_delimiter(tail), TRUE);
	scan_math(nucleus(tail));
	}
Ejemplo n.º 13
0
void tex::append_to_vlist(ptr b)
	{
	scal	d;
	ptr	p;

	append_to_vlist_called=true;
	if (prev_depth > IGNORE_DEPTH) {
		d = glue_width(baseline_skip) - prev_depth - box_height(b);
		if (d < line_skip_limit) {
			p = new_param_glue(LINE_SKIP_CODE);
			} 
		else {
			p = new_skip_param(BASELINE_SKIP_CODE);
			glue_width(glue_ptr(p)) = d;
			}
		tail_append(p);
		}
	tail_append(b);
	prev_depth = box_depth(b);
	}
Ejemplo n.º 14
0
void tex::make_accent ()
	{
	fnt	f;
	qcell	i;
	ptr	p, q, r;
	scal	a, h, w, x;
	float	s, t;
	scal	delta;

	scan_char_num();
	f = cur_font;
	p = new_character(f, cur_val);
	if (p != null) {
		x = x_height(f);
		s = (float) slant(f) / 65536.0;
		a = char_width(f, char_info(f, character(p)));
		do_assignments();
		q = null;
		f = cur_font;
		if (cur_cmd == LETTER
		|| cur_cmd == OTHER_CHAR
		|| cur_cmd ==  CHAR_GIVEN) {
			q = new_character(f, cur_chr);
		} else if (cur_cmd ==  CHAR_NUM) {
			scan_char_num();
			q = new_character(f, cur_val);
		} else {
			back_input();
		}
		if (q != null) {
			t = (float) slant(f) / 65536.0;
			i = char_info(f, character(q));
			w = char_width(f, i); 
			h = char_height(f, height_depth(i));
			if (h != x) {
				p = hpack(p, 0, ADDITIONAL);
				shift_amount(p) = x - h;
			}
			delta = round((float) (w - a) / 2.0 + h * t - x * s);
			r = new_kern(delta);
			subtype(r) = ACC_KERN;
			link(tail) = r;
			link(r) = p;
			tail = new_kern(-a - delta);
			subtype(tail) = ACC_KERN;
			link(p) = tail;
			p = q;
		}
		tail_append(p);
		space_factor = 1000;
		}
	}
Ejemplo n.º 15
0
void scan_pdfrefximage(PDF pdf)
{
    /*tex One could scan transform as well. */
    int transform = 0;
    /*tex Begin of experiment. */
    int open = 0;
    /*tex End of experiment. */
    image_dict *idict;
    /*tex This scans |<rule spec>| to |alt_rule|. */
    scaled_whd alt_rule, dim;
    alt_rule = scan_alt_rule();
    /*tex Begin of experiment. */
    if (scan_keyword("keepopen")) {
        open = 1;
    }
    /*tex End of experiment. */
    scan_int();
    check_obj_type(pdf, obj_type_ximage, cur_val);
    tail_append(new_rule(image_rule));
    idict = idict_array[obj_data_ptr(pdf, cur_val)];
    /*tex Begin of experiment, */
    if (open) {
        /*tex So we keep the original value when no close is given. */
        idict->keepopen = 1;
    }
    /*tex End of experiment. */
    if (img_state(idict) == DICT_NEW) {
        normal_warning("image","don't rely on the image data to be okay");
        width(tail_par) = 0;
        height(tail_par) = 0;
        depth(tail_par) = 0;
    } else {
        if (alt_rule.wd != null_flag || alt_rule.ht != null_flag || alt_rule.dp != null_flag) {
            dim = scale_img(idict, alt_rule, transform);
        } else {
            dim = scale_img(idict, img_dimen(idict), img_transform(idict));
        }
        width(tail_par) = dim.wd;
        height(tail_par) = dim.ht;
        depth(tail_par) = dim.dp;
        rule_transform(tail_par) = transform;
        rule_index(tail_par) = img_index(idict);
    }
}
Ejemplo n.º 16
0
void tex::indent_in_hmode ()
	{
	ptr	p, q;
	
	if (cur_chr > 0) {
		p = new_null_box();
		box_width(p) = par_indent;
		if (abs(mode) == HMODE) {
			space_factor = 1000;
			} 
		else {
			q = new_noad();
			math_type(nucleus(q)) = SUB_BOX;
			math_link(nucleus(q)) = p;
			p = q;
			}
		tail_append(p);
		}
	}
Ejemplo n.º 17
0
void tex::append_discretionary ()
	{
	int	c;

	tail_append(new_disc());
	if (cur_chr == 1) {
		c = hyphen_char(cur_font);
		if (c >= 0 && c < 256)
			pre_break(tail) = new_character(cur_font, c);
		}
	else {
		incr(save_ptr);
		saved(-1) = 0;
		scan_left_brace();
		new_save_level(DISC_GROUP);
		push_nest();
		mode = -HMODE;
		space_factor = 1000;
		}
	}
Ejemplo n.º 18
0
void tex::new_graf(bool indented)
	{
	prev_graf = 0;
	if (mode == VMODE || head != tail)
		tail_append(new_param_glue(PAR_SKIP_CODE));
	lhmin = norm_min(left_hyphen_min);
	rhmin = norm_min(right_hyphen_min);
	push_nest();
	mode = HMODE;
	space_factor = 1000;
	clang = 0;	
	if (indented) {
		link(head) = tail = new_null_box();
		box_width(tail) = par_indent;
	}
	if (every_par != null)
		begin_token_list(every_par, EVERY_PAR_TEXT);
	if (nest_ptr == nest + 1) 
		build_page();
}
Ejemplo n.º 19
0
void tex::append_glue () 
	{
	int	s;
	
	s = cur_chr;
	switch (s) {
		case FIL_CODE: cur_val = fil_glue; break;
		case FILL_CODE: cur_val = fill_glue; break;
		case SS_CODE: cur_val = ss_glue; break;
		case FIL_NEG_CODE: cur_val = fil_neg_glue; break;
		case SKIP_CODE: scan_glue(GLUE_VAL); break;
		case MSKIP_CODE: scan_glue(MU_VAL); break;
		default: break;
		}
	tail_append(new_glue(cur_val));
	if (s >= SKIP_CODE) {
		decr(glue_ref_count(cur_val));
		if (s > SKIP_CODE)
			subtype(tail) = MU_GLUE;
		}
	}
Ejemplo n.º 20
0
void tex::app_space ()
	{
	ptr	p, q;
	
	if (space_factor >= 2000 && xspace_skip != zero_glue) {
		q = new_param_glue(XSPACE_SKIP_CODE);
		} 
	else {
		if (space_skip != zero_glue) {
			p = space_skip;
			} 
		else {
			p = find_font_glue(cur_font);
			}
		p = new_spec(p);
		if (space_factor >= 2000)
			glue_width(p) += extra_space(cur_font);
		stretch(p) = xn_over_d(stretch(p), space_factor, 1000);
		shrink(p) = xn_over_d(shrink(p), 1000L, space_factor);
		q = new_glue(p);
		glue_ref_count(p) = 0;
		}
	tail_append(q);
	}
Ejemplo n.º 21
0
void tex::main_control()
	{
	if (every_job != null)
		begin_token_list(every_job, EVERY_JOB_TEXT);
	
	big_switch:
	get_x_token();

   reswitch:
	if (tracing_commands > 0)
		show_cur_cmd_chr();
	
	switch(abs(mode) + cur_cmd) {
		hmode(LETTER):
		hmode(OTHER_CHAR):
		hmode(CHAR_GIVEN):
			goto main_loop;
		
		hmode(CHAR_NUM):
			scan_char_num();
		   cur_chr = cur_val;
		   goto main_loop;
		
		hmode(NO_BOUNDARY):
			get_x_token();
		   if (cur_cmd == LETTER || cur_cmd == OTHER_CHAR
				 || cur_cmd == CHAR_GIVEN || cur_cmd == CHAR_NUM) {
				cancel_boundary = TRUE;
				}
			goto reswitch;

		hmode(SPACER):
			if (space_factor == 1000) {
				goto append_normal_space;
				} 
			else {
				app_space();
				}
		   break;
	
	hmode(EX_SPACE):
	mmode(EX_SPACE):
		goto append_normal_space;
	
	any_mode(RELAX):
	vmode(SPACER):
	mmode(SPACER):
	mmode(NO_BOUNDARY):
		break;
	
	any_mode(IGNORE_SPACES):
		get_nbx_token();
		goto reswitch;

	vmode(STOP):
		if (its_all_over())
			return;
		break;

	any_mode(LAST_ITEM):
	any_mode(MAC_PARAM):
	non_math(EQ_NO):
	vmode(VMOVE):
	hmode(HMOVE):
	mmode(HMOVE):
	vmode(VADJUST):
	vmode(ITAL_CORR):
		report_illegal_case();
		break;

	non_math(SUP_MARK):
	non_math(SUB_MARK):
	non_math(MATH_CHAR_NUM):
	non_math(MATH_GIVEN):
	non_math(MATH_COMP):
	non_math(DELIM_NUM):
	non_math(LEFT_RIGHT):
	non_math(ABOVE):
	non_math(RADICAL):
	non_math(MATH_STYLE):
	non_math(MATH_CHOICE):
	non_math(VCENTER):
	non_math(NON_SCRIPT):
	non_math(MKERN):
	non_math(LIMIT_SWITCH):
	non_math(MSKIP):
	non_math(MATH_ACCENT):
	mmode(ENDV):
	mmode(PAR_END):
	mmode(STOP):
	mmode(VSKIP):
	mmode(UN_VBOX):
	mmode(VALIGN):
	mmode(HRULE):
		insert_dollar_sign();
		break;
	
	vmode(HRULE):
	hmode(VRULE):
	mmode(VRULE):
		tail_append(scan_rule_spec());
		if (abs(mode) == VMODE)
			prev_depth = IGNORE_DEPTH;
		else if (abs(mode) == HMODE)
			space_factor = 1000;
		break;
	
	vmode(VSKIP):
	hmode(HSKIP):
	mmode(HSKIP):
	mmode(MSKIP):
		append_glue();
		break;
	
	any_mode(KERN):
	mmode(MKERN):
		append_kern();
		break;
	
	non_math(LEFT_BRACE):
		new_save_level(SIMPLE_GROUP);
		break;

	any_mode(BEGIN_GROUP):
		new_save_level(SEMI_SIMPLE_GROUP);
		break;

	any_mode(END_GROUP):
		if (cur_group == SEMI_SIMPLE_GROUP) {
			unsave();
		} else {
			off_save();
		}
		break;
	
	any_mode(RIGHT_BRACE):
		handle_right_brace();
		break;

	vmode(HMOVE):
	hmode(VMOVE):
	mmode(VMOVE): {
		int	t;

		t = cur_chr;
		scan_normal_dimen();
		if (t == 0) {
			scan_box(cur_val);
		} else {
			scan_box(-cur_val);
		}
		break;
	}
	any_mode(LEADER_SHIP):
		scan_box(LEADER_FLAG + cur_chr - A_LEADERS);
		break;
	
	any_mode(MAKE_BOX):
		begin_box(0);
		break;

	vmode(START_PAR):
		new_graf(cur_chr > 0);
		break;
	
	vmode(LETTER):
	vmode(OTHER_CHAR):
	vmode(CHAR_NUM):
	vmode(CHAR_GIVEN):
	vmode(MATH_SHIFT):
	vmode(UN_HBOX):
	vmode(VRULE):
	vmode(ACCENT):
	vmode(DISCRETIONARY):
	vmode(HSKIP):
	vmode(VALIGN):
	vmode(EX_SPACE):
	vmode(NO_BOUNDARY):
		back_input();
		new_graf(TRUE);
		break;
	
	hmode(START_PAR):
	mmode(START_PAR):
		indent_in_hmode();
		break;
	
	vmode(PAR_END):
		normal_paragraph();
		if (mode > 0)
			build_page();
		break;

	hmode(PAR_END):
		if (align_state < 0)
			off_save();
		end_graf();
		if (mode == VMODE)	
			build_page();
		break;
	
	hmode(STOP):
	hmode(VSKIP):
	hmode(HRULE):
	hmode(UN_VBOX):
	hmode(HALIGN):
		head_for_vmode();
		break;
	
	any_mode(INSERT):
	hmode(VADJUST):
	mmode(VADJUST):
		begin_insert_or_adjust();
		break;
	
	any_mode(MARK):
		make_mark();
		break;
	
	any_mode(BREAK_PENALTY):
		append_penalty();
		break;
	
	any_mode(REMOVE_ITEM):
		delete_last();
		break;
	
	vmode(UN_VBOX):
	hmode(UN_HBOX):
	mmode(UN_HBOX):
		unpackage();
		break;
	
	hmode(ITAL_CORR):
		append_italic_correction();
		break;
	
	mmode(ITAL_CORR):
		tail_append(new_kern(0));
		break;

	hmode(DISCRETIONARY):
	mmode(DISCRETIONARY):
		append_discretionary();
		break;
	
	hmode(ACCENT):
		make_accent();
		break;
	
	any_mode(CAR_RET):
	any_mode(TAB_MARK):
		align_error();
		break;

	any_mode(NO_ALIGN):
		no_align_error();
		break;
	
	any_mode(OMIT):
		omit_error();
		break;

	vmode(HALIGN):
	hmode(VALIGN):
		init_align();
		break;
	
	mmode(HALIGN):
		if (privileged()) {
			if (cur_group == MATH_SHIFT_GROUP) {
				init_align();
			} else {
				off_save();
			}
		}
		break;

	vmode(ENDV):
	hmode(ENDV):
		do_endv();
		break;
	
	any_mode(END_CS_NAME):
		cs_error();
		break;

	hmode(MATH_SHIFT):
		init_math();
		break;
	
	mmode(EQ_NO):
		if (privileged()) {
			if (cur_group == MATH_SHIFT_GROUP) {
				start_eq_no();
			} else {
				off_save();
			}
		}
		break;
	
	mmode(LEFT_BRACE):
		tail_append(new_noad());
		back_input();
		scan_math(nucleus(tail));
		break;

	mmode(LETTER):
	mmode(OTHER_CHAR):
	mmode(CHAR_GIVEN):
		if (cur_chr < 256)
			set_math_char(math_code(cur_chr));
		else set_math_char(cur_chr);
		break;
	
	mmode(CHAR_NUM):
		scan_char_num();
		cur_chr = cur_val;
		if (cur_chr < 256)
			set_math_char(math_code(cur_chr));
		else set_math_char(cur_chr);
		break;
	
	mmode(MATH_CHAR_NUM):
		scan_fifteen_bit_int();
		set_math_char(cur_val);
		break;
	
	mmode(MATH_GIVEN):
		set_math_char(cur_chr);
		break;

	mmode(DELIM_NUM):
		scan_twenty_seven_bit_int();
		set_math_char(cur_val / 010000);
		break;
	
	mmode(MATH_COMP):
		tail_append(new_noad());
		type(tail) = cur_chr;
		scan_math(nucleus(tail));
		break;
	
	mmode(LIMIT_SWITCH):
		math_limit_switch();
		break;

	mmode(RADICAL):
		math_radical();
		break;

	mmode(ACCENT):
	mmode(MATH_ACCENT):
		math_ac();
		break;

	mmode(VCENTER):
		scan_spec(VCENTER_GROUP, FALSE);
		normal_paragraph();
		push_nest();
		mode = -VMODE;
		prev_depth = IGNORE_DEPTH;
		if (every_vbox != null)
			begin_token_list(every_vbox, EVERY_VBOX_TEXT);
		break;
	
	mmode(MATH_STYLE):
		tail_append(new_style(cur_chr));
		break;
	
	mmode(NON_SCRIPT):
		tail_append(new_glue(zero_glue));
		subtype(tail) = COND_MATH_GLUE;
		break;
	
	mmode(MATH_CHOICE):
		append_choices();
		break;

	mmode(SUB_MARK):
	mmode(SUP_MARK):
		sub_sup();
		break;
	
	mmode(ABOVE):
		math_fraction();
		break;
	
	mmode(LEFT_RIGHT):
		math_left_right();
		break;

	mmode(MATH_SHIFT):
		if (cur_group == MATH_SHIFT_GROUP) {
			after_math();
		} else {
			off_save();
		}
		break;

	any_mode(AFTER_ASSIGNMENT):
		get_token();
		after_token = cur_tok;
		break;
	
	any_mode(AFTER_GROUP):
		get_token();
		save_for_after(cur_tok);
		break;

	any_mode(IN_STREAM):
		clopen_stream();
		break;

	any_mode(MESSAGE):
		issue_message();
		break;
	
	any_mode(CASE_SHIFT):
		shift_case();
		break;
	
	any_mode(XRAY):
		show_whatever();
		break;
	
	any_mode(EXTENSION):
		do_extension();
		break;
	
	default:
		prefixed_command();
		break;
	}
	goto big_switch;

#define adjust_space_factor() \
{ \
	main_s = sf_code(cur_chr); \
	if (main_s == 1000) { \
		space_factor = 1000; \
	} else if (main_s < 1000) { \
		if (main_s > 0) { \
			space_factor = main_s; \
		} \
	} else if (space_factor < 1000) { \
		space_factor = 1000; \
	} else { \
		space_factor = main_s; \
	} \
}
		
main_loop:
	adjust_space_factor();
	main_f = cur_font;
	bchar = font_bchar(main_f);
	false_bchar = font_false_bchar(main_f);
	if (mode > 0 && language != clang)
		fix_language();
	fast_new_avail(lig_stack);
	font(lig_stack) = main_f;
	character(lig_stack) = cur_l = cur_chr;
	cur_q = tail;
	if (cancel_boundary) {
		cancel_boundary = FALSE;
		main_k = NON_ADDRESS;
	} else {
		main_k = bchar_label(main_f);
	}
	if (main_k == NON_ADDRESS)
		goto main_loop_move_2;
	cur_r = cur_l;
	cur_l = NON_CHAR;
	goto main_lig_loop_1;

#define pack_lig(RT_HIT) \
{ \
	main_p = new_ligature(main_f, cur_l, link(cur_q)); \
	if (lft_hit) { \
		subtype(main_p) = 2; \
		lft_hit = FALSE; \
	} \
	if (RT_HIT && lig_stack == null) { \
		incr(subtype(main_p)); \
		rt_hit = FALSE; \
	} \
	tail = link(cur_q) = main_p; \
	ligature_present = FALSE; \
}

#define wrapup(RT_HIT) \
{ \
	if (cur_l < NON_CHAR) { \
		if (character(tail) == hyphen_char(main_f) \
		&& link(cur_q) != null) \
			ins_disc = TRUE; \
		if (ligature_present) \
			pack_lig(RT_HIT); \
		if (ins_disc) { \
			ins_disc = FALSE; \
			if (mode > 0) \
				tail_append(new_disc()); \
		} \
	} \
}

main_loop_wrapup:
	wrapup(rt_hit);

main_loop_move:
	if (lig_stack == null)
		goto reswitch;
	cur_q = tail;
	cur_l = cur_r;

main_loop_move_1:
	if (!is_char_node(lig_stack))
		goto main_loop_move_lig;

main_loop_move_2:
	if (cur_chr < font_bc(main_f) || cur_chr > font_ec(main_f)) {
		char_warning(main_f, cur_chr);
		free_avail(lig_stack);
		goto big_switch;
	}
	main_i = char_info(main_f, cur_l);
	if (!char_exists(main_i)) {
		char_warning(main_f, cur_chr);
		free_avail(lig_stack);
		goto big_switch;
	}
	tail_append(lig_stack);

main_loop_lookahead:
	get_next();
	if (cur_cmd == LETTER
	|| cur_cmd == OTHER_CHAR
	|| cur_cmd == CHAR_GIVEN) {
		goto main_loop_lookahead_1;
	}
	x_token();
	if (cur_cmd == LETTER
	|| cur_cmd == OTHER_CHAR
	|| cur_cmd == CHAR_GIVEN) {
		goto main_loop_lookahead_1;
	}
	if (cur_cmd == CHAR_NUM) {
		scan_char_num();
		cur_chr = cur_val;
		goto main_loop_lookahead_1;
	}
	if (cur_cmd == NO_BOUNDARY) {
		bchar = NON_CHAR;
	}
	cur_r = bchar;
	lig_stack = null;
	goto main_lig_loop;

main_loop_lookahead_1:
	adjust_space_factor();
	fast_new_avail(lig_stack);
	font(lig_stack) = main_f;
	character(lig_stack) = cur_r = cur_chr;
	if (cur_r == false_bchar) {
		cur_r = NON_CHAR;
	}

main_lig_loop:
	if (char_tag(main_i) != LIG_TAG) {
		goto main_loop_wrapup;
	}
	main_k = lig_kern_start(main_f, main_i);
	main_j = *main_k;
	if (skip_byte(main_j) <= STOP_FLAG) {
		goto main_lig_loop_2;
	}
	main_k = lig_kern_restart(main_f, main_j);

main_lig_loop_1:
	main_j = *main_k;

main_lig_loop_2:
	if (next_char(main_j) == cur_r
	&& skip_byte(main_j) <= STOP_FLAG) {
		if (op_byte(main_j) >= KERN_FLAG) {
			wrapup(rt_hit);
			tail_append(new_kern(char_kern(main_f, main_j)));
			goto main_loop_move;
		}
		if (cur_l == NON_CHAR) {
			lft_hit = TRUE;
		} else if (lig_stack == null) {
			rt_hit = TRUE;
		}
		if(interrupted) throw std::logic_error("interrupted");
		switch (op_byte(main_j))
		{
		case 1: case 5:
			cur_l = rem_byte(main_j);
			main_i = char_info(main_f, cur_l);
			ligature_present = TRUE;
			break;
			
		case 2: case 6:
			cur_r = rem_byte(main_j);
			if (lig_stack == null) {
				lig_stack = new_lig_item(cur_r);
				bchar = NON_CHAR;
			} else if (is_char_node(lig_stack)) {
				main_p = lig_stack;
				lig_stack = new_lig_item(cur_r);
				lig_ptr(lig_stack) = main_p;
			} else {
				character(lig_stack) = cur_r;
			}
			break;

		case 3:
			cur_r = rem_byte(main_j);
			main_p = lig_stack;
			lig_stack = new_lig_item(cur_r);
			link(lig_stack) = main_p;
			break;

		case 7: case 11:
			wrapup(FALSE);
			cur_q = tail;
			cur_l = rem_byte(main_j);
			main_i = char_info(main_f, cur_l);
			ligature_present = TRUE;
			break;

		default:
			cur_l = rem_byte(main_j);
			ligature_present = TRUE;
			if (lig_stack == null) {
				goto main_loop_wrapup;
			} else {
				goto main_loop_move_1;
			}
			break;
		}
		if (op_byte(main_j) > 4 && op_byte(main_j) != 7)
			goto main_loop_wrapup;
		if (cur_l < NON_CHAR)
			goto main_lig_loop;
		main_k = bchar_label(main_f);
		goto main_lig_loop_1;
	}
	if (skip_byte(main_j) == 0) {
		incr(main_k);
	} else {
		if (skip_byte(main_j) >= STOP_FLAG)
			goto main_loop_wrapup;
		main_k += skip_byte(main_j) + 1;
	}
	goto main_lig_loop_1;

main_loop_move_lig:
	main_p = lig_ptr(lig_stack);
	if (main_p != null) {
		tail_append(main_p);
	}
	main_t = lig_stack;
	lig_stack = link(main_t);
	free_node(main_t, SMALL_NODE_SIZE);
	main_i = char_info(main_f, cur_l);
	ligature_present = TRUE;
	if (lig_stack == null) {
		if (main_p != null) {
			goto main_loop_lookahead;
		} else {
			cur_r = bchar;
		}
	} else {
		cur_r = character(lig_stack);
	}
	goto main_lig_loop;

append_normal_space:
	if (space_skip == zero_glue) {
		main_p = font_glue(cur_font);
		if (main_p == null)
			main_p = find_font_glue(cur_font);
		main_t = new_glue(main_p);
	} else {
		main_t = new_param_glue(SPACE_SKIP_CODE);
	}
	tail_append(main_t);
	goto big_switch;
}
Ejemplo n.º 22
0
void tex::after_math ()
{
	ptr	a;
	ptr	b;
	scal	d;
	scal	e;
	bool	l;
	int	m;
	ptr	p;
	scal	q;
	ptr	r;
	scal	s;
	scal	t;
	scal	w;
	scal	z;
	int	g1;
	int	g2;
	bool	danger;

	danger = check_font_params();
	m = mode;
	l = FALSE;
	p = fin_mlist(null);
	if (mode == -m) {
		check_dollar();
		a = hpack(mlist_to_hlist(p, TEXT_STYLE, FALSE), 0, ADDITIONAL);
		unsave();
		decr(save_ptr);
		if (saved(0) == 1)
			l = TRUE;
		danger = check_font_params();
		m = mode;
		p = fin_mlist(null);
	} else {
		a = null;
	}
	if (m < 0) {
		tail_append(new_math(math_surround, BEFORE));
		link(tail) = mlist_to_hlist(p, TEXT_STYLE, mode > 0);
		while (link(tail) != null)
			tail = link(tail);
		tail_append(new_math(math_surround, AFTER));
		space_factor = 1000;
		unsave();
	} else {
		if (a == null)
			check_dollar();
		p = mlist_to_hlist(p, DISPLAY_STYLE, FALSE);
		tex::adjust_tail = tex::adjust_head;
		b = hpack(p, 0, ADDITIONAL);
		p = list_ptr(b);
		t = tex::adjust_tail;
		tex::adjust_tail = null;
		w = box_width(b);
		z = display_width;
		s = display_indent;
		if (a == null || danger) {
			e = q = 0;
		} else {
			e = box_width(a);
			q = e + math_quad(TEXT_SIZE);
		}
		if (w + q > z) {
			if (e != 0
			&& (w - tex::total_shrink[NORMAL] + q <= z
			|| tex::total_shrink[FIL] != 0
			|| tex::total_shrink[FILL] != 0
			|| tex::total_shrink[FILLL] != 0)) {
				free_node(b, BOX_NODE_SIZE);
				b = hpack(p, z - q, EXACTLY);
			} else {
				e = 0;
				if (w > z) {
					free_node(b, BOX_NODE_SIZE);
					b = hpack(p, z, EXACTLY);
				}
			}
			w = box_width(b);
		}
		d = half(z - w);
		if (e > 0 && d < 2 * e) {
			d = half(z - w - e);
			if (p != null && type(p) == GLUE_NODE) {
				d = 0;
			}
		}
		tail_append(new_penalty(pre_display_penalty));
		if (d + s <= pre_display_size || l) {
			g1 = ABOVE_DISPLAY_SKIP_CODE;
			g2 = BELOW_DISPLAY_SKIP_CODE;
		} else {
			g1 = ABOVE_DISPLAY_SHORT_SKIP_CODE;
			g2 = BELOW_DISPLAY_SHORT_SKIP_CODE;
		}
		if (l && e == 0) {
			shift_amount(a) = s;
			append_to_vlist(a);
			tail_append(new_penalty(INF_PENALTY));
		} else {
			tail_append(new_param_glue(g1));
		}
		if (e != 0) {
			r = new_kern(z - w - e - d);
			if (l) {
				link(a) = r;
				link(r) = b;
				b = a;
				d = 0;
			} else {
				link(b) = r;
				link(r) = a;
			}
			b = hpack(b, 0, ADDITIONAL);
		}
		shift_amount(b) = s + d;
		append_to_vlist(b);
		if (a != null && e == 0 && !l) {
			tail_append(new_penalty(INF_PENALTY));
			shift_amount(a) = s + z - box_width(a);
			append_to_vlist(a);
			g2 = 0;
		}
		if (t != tex::adjust_head) {
			link(tail) = link(tex::adjust_head);
			tail = t;
		}
		tail_append(new_penalty(post_display_penalty));
		if (g2 > 0) {
			tail_append(new_param_glue(g2));
		}
		resume_after_display();
	}
}
Ejemplo n.º 23
0
void tex::box_end(int box_context)
	{
	ptr	p;

#define LEADERS "Leaders not followed by proper glue"

	if (box_context < BOX_FLAG) {
		if (cur_box != null) {
			shift_amount(cur_box) = box_context;
			if (abs(mode) == VMODE) {
				append_to_vlist(cur_box);
				if (tex::adjust_tail != null) {
					if (tex::adjust_head != tex::adjust_tail) {
						link(tail) = link(tex::adjust_head);
						tail = tex::adjust_tail;
					}
					tex::adjust_tail = null;
				}
				if (mode > 0) 
					build_page();
			} else {
				if (abs(mode) == HMODE) {
					space_factor = 1000;
				} else {
					p = new_noad();
					math_type(nucleus(p)) = SUB_BOX;
					info(nucleus(p)) = cur_box;
					cur_box = p;
				}
				tail_append(cur_box);
			}
		}
	} else if (box_context < SHIP_OUT_FLAG) {
		if (box_context < BOX_FLAG + 256) {
			reg_define(box_reg[box_context - BOX_FLAG],
				BOX_REG, cur_box);
		} else {
			reg_gdefine(box_reg[box_context - BOX_FLAG - 256],
				BOX_REG, cur_box);
		}
	} else if (cur_box != null) {
		if (box_context > SHIP_OUT_FLAG) {
			get_nbrx_token();
			if (cur_cmd == HSKIP && abs(mode) != VMODE
			|| cur_cmd == VSKIP && abs(mode) == VMODE
			|| cur_cmd == MSKIP && abs(mode) == MMODE) {
				append_glue();
				leader_ptr(tail) = cur_box;
				subtype(tail) = box_context -
					(LEADER_FLAG - A_LEADERS);
			} else {
				print_err(LEADERS);
				help_leaders();
				back_error();
				flush_node_list(cur_box);
			}
		} else {
			ship_out(cur_box);
		}
	}
}
Ejemplo n.º 24
0
void tex::handle_right_brace ()
	{
	scal	d;
	int	f;
	ptr	p;
	ptr	q;
	
	switch (cur_group)
	{
	case SIMPLE_GROUP:
		unsave();
		break;
	
	case BOTTOM_LEVEL:
		print_err("Too many }'s");
		help_close_group();
		error();
		break;
	
	case SEMI_SIMPLE_GROUP:
	case MATH_SHIFT_GROUP:
	case MATH_LEFT_GROUP:
		extra_right_brace();
		break;

	case HBOX_GROUP:
		package(0);
		break;
	
	case ADJUSTED_HBOX_GROUP:
		tex::adjust_tail = tex::adjust_head;
		package(0);
		break;
	
	case VBOX_GROUP:
		end_graf();
		package(0);
		break;
	
	case VTOP_GROUP:
		end_graf();
		package(VTOP_CODE);
		break;

	case INSERT_GROUP:
		end_graf();
		q = split_top_skip;
		add_glue_ref(q);
		d = split_max_depth;
		f = floating_penalty;
		unsave();
		decr(save_ptr);
		p = vpack(link(head), 0, ADDITIONAL);
		pop_nest();
		if (saved(0) < 255) {
			tail_append(new_node(INS_NODE_SIZE));
			type(tail) = INS_NODE;
			subtype(tail) = saved(0);
			ins_height(tail) = box_height(p) + box_depth(p);
			ins_ptr(tail) = list_ptr(p);
			split_top_ptr(tail) = q;
			ins_depth(tail) = d;
			float_cost(tail) = f;
		} else {
			tail_append(new_node(SMALL_NODE_SIZE));
			type(tail) = ADJUST_NODE;
			subtype(tail) = 0;
			adjust_ptr(tail) = list_ptr(p);
			delete_glue_ref(q);
		}
		free_node(p, BOX_NODE_SIZE);
		if (nest_ptr == nest) 
			build_page();
		break;
	
	case OUTPUT_GROUP:
		if (loc != null
		|| (token_type != OUTPUT_TEXT && token_type != BACKED_UP)) {
			print_err("Unbalanced output routine");
			help_output_balance();
			error();
			do get_token();
			while (loc != null);
		}
		end_token_list();
		end_graf();
		unsave();
		output_active = FALSE;
		insert_penalties = 0;
		if (box(255) != null) {
			print_err("Output routine didn't use all of ");
			print_esc("box255");
			help_output();
			box_error(255);
		}
		if (tail != head) {
			link(page_tail) = link(head);
			page_tail = tail;
		}
		if (link(page_head) != null) {
			if (link(contrib_head) == null)
				contrib_tail = page_tail;
			link(page_tail) = link(contrib_head);
			link(contrib_head) = link(page_head);
			link(page_head) = null;
			page_tail = page_head;
		}
		pop_nest();
		build_page();
		break;
	
	case DISC_GROUP:
		build_discretionary();
		break;
	
	case ALIGN_GROUP:
		back_input();
		cur_tok = sym2tok(FROZEN_CR);
		print_err("Missing ");
		print_esc("cr");
		print(" inserted");
		help_align_cr();
		ins_error(); 
		break;

	case NO_ALIGN_GROUP:
		end_graf();
		unsave();
		align_peek();
		break;
	
	case VCENTER_GROUP:
		end_graf();
		unsave();
		save_ptr -= 2;
		p = vpackage(link(head), saved(1), saved(0), MAX_DIMEN);
		pop_nest();
		tail_append(new_noad());
		type(tail) = VCENTER_NOAD;
		math_type(nucleus(tail)) = SUB_BOX;
		info(nucleus(tail)) = p;
		break;
	
	case MATH_CHOICE_GROUP:
		build_choices();
		break;

	case MATH_GROUP:
		unsave();
		decr(save_ptr);
		math_type(saved(0)) = SUB_MLIST;
		p = fin_mlist(null);
		math_link(saved(0)) = p;
		if (p != null) {
			if (link(p) == null) {
				if (type(p) == ORD_NOAD) {
					if (math_type(subscr(p)) == EMPTY
					&& math_type(supscr(p)) == EMPTY) {
						mcopy(saved(0), nucleus(p));
						free_node(p, NOAD_SIZE);
					}
				} else if (type(p) == ACCENT_NOAD
					&& saved(0) == nucleus(tail)
					&& type(tail) == ORD_NOAD) {
					q = head;
					while (link(q) != tail)
						q = link(q);
					link(q) = p;
					free_node(tail, NOAD_SIZE);
					tail = p;
				}
			}
		}
		break;
	
	default:
		confusion("rightbrace");
		break;
	}
}