Esempio n. 1
0
tex::lig_t::lig_t(int f, int c, ptr q)
	{
	tex::type(this) = LIGATURE_NODE;
	tex::subtype(this) = 0;
	font(lig_char(this)) = f;
	character(lig_char(this)) = c;
	lig_ptr(this) = q;
	}
Esempio n. 2
0
void tex::show_ligature(ptr p)
	{
	print_font_and_char(lig_char(p));
	print(" (ligature ");
	if (subtype(p) > 1)
		print("|");
	font_in_short_display = font(lig_char(p));
	short_display(lig_ptr(p));
	if (odd(subtype(p)))
		print("|");
	print(")");
	}
Esempio n. 3
0
void short_display(int p)
{
while(p!=null){
if(is_char_node(p)){
if(lig_ptr(p)!=null){
short_display(lig_ptr(p));
}else{
if(font(p)!=font_in_short_display){
if(!is_valid_font(font(p)))
print_char('*');
else
print_font_identifier(font(p));
print_char(' ');
font_in_short_display= font(p);
}
print(character(p));
}
}else{

print_short_node_contents(p);
}
p= vlink(p);
}
}
Esempio n. 4
0
void
try_hyph ()
{
	int	c, j;
	ptr	prev_p, p, q;
	
	prev_p = cur_p;
	p = link(cur_p);
	if (p != null) {
		loop {
			if (is_char_node(p)) {
				c = character(p);
				hf = font(p);
			} else if (type(p) == LIGATURE_NODE) {
				if (lig_ptr(p) == null)
					goto contin;
				q = lig_ptr(p);
				c = character(q);
				hf = font(q);
			} else if (type(p) == KERN_NODE
				&& subtype(p) == NORMAL) {
				goto contin;
			} else if (type(p) == WHATSIT_NODE) {
				try_hyph_whatsit(p);
				goto contin;
			} else {
				goto done1;
			}
			if (lc_code(c) != 0) {
				if (lc_code(c) == c || uc_hyph > 0) {
					goto done2;
				} else {
					goto done1;
				}
			}
		contin:
			prev_p = p;
			p = link(p);
		}
	done2:
		hyf_char = hyphen_char(hf);
		if (hyf_char < 0 || hyf_char > 255)
			goto done1;
		ha = prev_p;
		if (l_hyf + r_hyf > 63)
			goto done1;
		hn = 0;
		loop {
			if (is_char_node(p)) {
				if (font(p) != hf)
					goto done3;
				c = character(p);
				if (lc_code(c) == 0 || hn == 63)
					goto done3;
				hb = p;
				incr(hn);
				hu[hn] = c;
				hc[hn] = lc_code(c);
			} else if (type(p) == LIGATURE_NODE) {
				if (font(lig_char(p)) != hf)
					goto done3;
				j = hn;
				q = lig_ptr(p);
				while (q != null) {
					c = character(q);
					if (lc_code(c) == 0 || j == 63)
						goto done3;
					incr(j);
					hu[j] = c;
					hc[j] = lc_code(c);
					q = link(q);
				}
				hb = p;
				hn = j;
			} else if (type(p) != KERN_NODE
				|| subtype(p) != NORMAL) {
				goto done3;
			}
			p = link(p);
		}
	done3:
		if (hn < l_hyf + r_hyf)
			goto done1;
		loop {
			if (!is_char_node(p)) {
				switch (type(p))
				{
				case LIGATURE_NODE:
					break;

				case KERN_NODE:
					if (subtype(p) != NORMAL)
						goto done4;
					break;

				case WHATSIT_NODE:
				case GLUE_NODE:
				case PENALTY_NODE:
				case INS_NODE:
				case ADJUST_NODE:
				case MARK_NODE:
					goto done4;
				
				default: 
					goto done1;
				}
			}
			p = link(p);
		}

	done4:
		hyphenate();
	}
Esempio n. 5
0
void
hyphenate ()
{
	str	t, u;
	ptr	q, r, s;
	ptr	hyf_node;
	int	bchar;
	int	c_loc;
	int	r_count;
	ptr	major_tail;
	ptr	minor_tail;
	int	c, h, i, j, l, v, z;

	for (j = 0; j <= hn; incr(j))
		hyf[j] = 0;
	h = hc[1];
	incr(hn);
	hc[hn] = cur_lang;
	for (j = 2; j <= hn; incr(j))
		h = (h + h + hc[j]) % HYPH_SIZE;
	loop {
		t = hyph_word[h];
		if (t == null_str)
			goto not_found;
		l = hyph_len[h];
		if (l < hn)
			goto not_found;
		if (l == hn) {
			j = 1;
			u = t;
			while (j <= hn) {
				if (*u < hc[j])
					goto not_found;
				if (*u > hc[j])
					goto done;
				incr(u);
				incr(j);
			}
			for (s = hyph_list[h]; s != null; s = link(s))
				hyf[info(s)] = 1;
			decr(hn);
			goto found;
		}

	done:
		if (h > 0) {
			decr(h);
		} else {
			h = HYPH_SIZE;
		}
	}

not_found:
	decr(hn);
	if (trie_char(cur_lang + 1) != cur_lang)
		return;
	hc[0] = 0;
	hc[hn + 1] = 0;
	hc[hn + 2] = 256;
	for (j = 0; j <= hn - r_hyf + 1; incr(j)) {
		z = trie_link(cur_lang + 1) + hc[j];
		l = j;
		while (hc[l] == trie_char(z)) {
			if (v = trie_op(z)) {
				while (v) {
					v += op_start[cur_lang];
					i = l - hyf_distance[v];
					if (hyf_num[v] > hyf[i])
						hyf[i] = hyf_num[v];
					v = hyf_next[v];
				}
			}
			incr(l);
			z = trie_link(z) + hc[l];
		}
	}

found:
	for (j = 0; j < l_hyf; incr(j)) {
		hyf[j] = 0;
	}
	for (j = 0; j < r_hyf; incr(j)) {
		hyf[hn - j] = 0;
	}
	for (j = l_hyf; j <= hn - r_hyf; incr(j))
		if (odd(hyf[j]))
			goto found1;
	return;

found1:
	q = link(hb);
	link(hb) = null;
	r = link(ha);
	link(ha) = null;
	bchar = NON_CHAR;
	if (type(hb) == LIGATURE_NODE && odd(subtype(hb))) {
		bchar = font_bchar(hf);
	}
	if (is_char_node(ha)) {
		if (font(ha) != hf) {
			goto found2;
		} else {
			init_list = ha;
			init_lig = FALSE;
			hu[0] = character(ha);
		}
	} else if (type(ha) == LIGATURE_NODE) {
		if (font(lig_char(ha)) != hf) {
			goto found2;
		} else {
			init_list = lig_ptr(ha);
			init_lig = TRUE;
			init_lft = subtype(ha) > 1;
			hu[0] = character(lig_char(ha));
			if (init_list == null && init_lft) {
				hu[0] = 256;
				init_lig = FALSE;
			}
			free_node(ha, SMALL_NODE_SIZE);
		}
	} else {
		if (type(r) == LIGATURE_NODE && subtype(r) > 1) {
			goto found2;
		}
		j = 1;
		s = ha;
		init_list = null;
		goto common_end;
	}
	s = cur_p;
	while (link(s) != ha)
		s = link(s);
	j = 0;
	goto common_end;

found2:
	s = ha;
	j = 0;
	hu[0] = 256;
	init_lig = FALSE;
	init_list = null;

common_end:
	flush_node_list(r);

#define advance_major_tail()						\
{	major_tail = link(major_tail);					\
	incr(r_count);							\
}

#define put_pre_break()							\
{	minor_tail = null;						\
	pre_break(r) = null;						\
	hyf_node = new_character(hf, hyf_char);				\
	if (hyf_node != null) {						\
		incr(i);						\
		c = hu[i];						\
		hu[i] = hyf_char;					\
		free_avail(hyf_node);					\
	}								\
	while (l <= i) {						\
		l = reconstitute(l, i, font_bchar(hf), NON_CHAR) + 1;	\
		if (link(hold_head) == null) {				\
			continue;					\
		}							\
		if (minor_tail == null) {				\
			pre_break(r) = link(hold_head);			\
		} else {						\
			link(minor_tail) = link(hold_head);		\
		}							\
		minor_tail = link(hold_head);				\
		while (link(minor_tail) != null)			\
			minor_tail = link(minor_tail);			\
	}								\
	if (hyf_node != null) {						\
		hu[i] = c;						\
		l = i;							\
		decr(i);						\
	}								\
}

#define put_post_break()						\
{	minor_tail = null;						\
	post_break(r) = null;						\
	c_loc = 0;							\
	if (bchar_label(hf) != NON_ADDRESS) {				\
		decr(l);						\
		c = hu[l];						\
		c_loc = l;						\
		hu[l] = 256;						\
	}								\
	while (l < j) {							\
		do {							\
			l = reconstitute(l, hn, bchar, NON_CHAR) + 1;	\
			if (c_loc > 0) {				\
				hu[c_loc] = c;				\
				c_loc = 0;				\
			}						\
			if (link(hold_head) == null) {			\
				continue;				\
			}						\
			if (minor_tail == null) {			\
				post_break(r) = link(hold_head);	\
			} else {					\
				link(minor_tail) = link(hold_head);	\
			}						\
			minor_tail = link(hold_head);			\
			while (link(minor_tail) != null)		\
				minor_tail = link(minor_tail);		\
		} while (l < j);					\
		while (l > j) {						\
			j = reconstitute(j, hn, bchar, NON_CHAR) + 1;	\
			link(major_tail) = link(hold_head);		\
			while (link(major_tail) != null) {		\
				advance_major_tail();			\
			}						\
		}							\
	}								\
}

	do {
		l = j;
		j = reconstitute(j, hn, bchar, hyf_char) + 1;
		if (hyphen_passed == 0) {
			link(s) = link(hold_head);
			while (link(s) != null)
				s = link(s);
			if (odd(hyf[j - 1])) {
				l = j;
				hyphen_passed = j - 1;
				link(hold_head) = null;
			}
		}
		if (hyphen_passed > 0) {
			do {
				r = new_node(SMALL_NODE_SIZE);
				link(r) = link(hold_head);
				type(r) = DISC_NODE;
				major_tail = r;
				r_count = 0;
				while (link(major_tail) != null) {
					advance_major_tail();
				}
				i = hyphen_passed;
				hyf[i] = 0;
				put_pre_break();
				put_post_break();
				if (r_count > 127) {
					link(s) = link(r);
					link(r) = null;
					flush_node_list(r);
				} else {
					link(s) = r;
					replace_count(r) = r_count;
				}
				s = major_tail;
				hyphen_passed = j - 1;
				link(hold_head) = null;
			} while (odd(hyf[j - 1]));
		}
	} while (j <= hn);
	link(s) = q;
	flush_list(init_list);
}
Esempio n. 6
0
ptr tex::copy_node_list(ptr p)
	{
	ptr	h;
	ptr	q;
	ptr	r=0;

	h = q = new_avail();
	while (p != null) {
		if (is_char_node(p)) {
			r = new_avail();
			font(r) = font(p);
			character(r) = character(p);
		} else {
			switch (type(p))
			{
			case HLIST_NODE:
			case VLIST_NODE:
			case UNSET_NODE:
				r = tex::new_node(BOX_NODE_SIZE);
				memcpy((void *)r, (void *)p, BOX_NODE_SIZE);
				list_ptr(r) = copy_node_list(list_ptr(p));
				break;
			
			case RULE_NODE:
				r = tex::new_node(RULE_NODE_SIZE);
				memcpy((void *)r, (void *)p, RULE_NODE_SIZE);
				break;

			case INS_NODE:
				r = tex::new_node(INS_NODE_SIZE);
				memcpy((void *)r, (void *)p, INS_NODE_SIZE);
				add_glue_ref(split_top_ptr(p));
				ins_ptr(r) = copy_node_list(ins_ptr(p));
				break;

			case WHATSIT_NODE:
				r = copy_whatsit(p);
				break;
			
			case GLUE_NODE:
				r = tex::new_node(SMALL_NODE_SIZE);
				memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
				add_glue_ref(glue_ptr(p));
				glue_ptr(r) = glue_ptr(p);
				leader_ptr(r) = copy_node_list(leader_ptr(p));
				break;
			
			case KERN_NODE:
			case MATH_NODE:
			case PENALTY_NODE:
				r = tex::new_node(SMALL_NODE_SIZE);
				memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
				break;
			
			case LIGATURE_NODE:
				r = tex::new_node(SMALL_NODE_SIZE);
				memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
				lig_ptr(r) = copy_node_list(lig_ptr(p));
				break;
				
			case DISC_NODE:
				r = tex::new_node(SMALL_NODE_SIZE);
				memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
				pre_break(r) = copy_node_list(pre_break(p));
				post_break(r) = copy_node_list(post_break(p));
				break;

			case MARK_NODE:
				r = tex::new_node(SMALL_NODE_SIZE);
				memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
				add_token_ref(mark_ptr(p));
				break;

			case ADJUST_NODE:
				r = tex::new_node(SMALL_NODE_SIZE);
				memcpy((void *)r, (void *)p, SMALL_NODE_SIZE);
				adjust_ptr(r) = copy_node_list(adjust_ptr(p));
				break;
			
			default:
				confusion("copying");
				break;
			}
		}
		q = link(q) = r;
		p = link(p);
	}
	link(q) = null;
	q = link(h);
	free_avail(h);
	return q;
}
Esempio n. 7
0
void tex::flush_node_list(ptr p)
	{
	ptr	q;

	while (p != null) {
		q = link(p);
		if (is_char_node(p)) {
			free_avail(p);
		} else {
			switch (type(p))
			{
			case HLIST_NODE:
			case VLIST_NODE:
			case UNSET_NODE:
				flush_node_list(list_ptr(p));
				free_node(p, BOX_NODE_SIZE);
				goto done;
					
			case RULE_NODE:
				free_node(p, RULE_NODE_SIZE);
				goto done;

			case INS_NODE:
				flush_node_list(ins_ptr(p));
				delete_glue_ref(split_top_ptr(p));
				free_node(p, INS_NODE_SIZE);
				goto done;

			case WHATSIT_NODE:
				free_whatsit(p);
				goto done;
			
			case GLUE_NODE:
				fast_delete_glue_ref(glue_ptr(p));
				if (leader_ptr(p) != null)
					flush_node_list(leader_ptr(p));
				break;

			case KERN_NODE:
			case MATH_NODE:
			case PENALTY_NODE:
				break;

			case LIGATURE_NODE:
				flush_node_list(lig_ptr(p));
				break;

			case MARK_NODE:
				delete_token_ref(mark_ptr(p));
				break;
			
			case DISC_NODE:
				flush_node_list(pre_break(p));
				flush_node_list(post_break(p));
				break;

			case ADJUST_NODE:
				flush_node_list(adjust_ptr(p));
				break;

			case STYLE_NODE:
				free_node(p, STYLE_NODE_SIZE);
				goto done;

			case CHOICE_NODE:
				flush_node_list(display_mlist(p));
				flush_node_list(text_mlist(p));
				flush_node_list(script_mlist(p));
				flush_node_list(script_script_mlist(p));
				free_node(p, STYLE_NODE_SIZE);
				goto done;

			case ORD_NOAD:
			case OP_NOAD:
			case BIN_NOAD:
			case REL_NOAD:
			case OPEN_NOAD:
			case CLOSE_NOAD:
			case PUNCT_NOAD:
			case INNER_NOAD:
			case RADICAL_NOAD:
			case OVER_NOAD:
			case UNDER_NOAD:
			case VCENTER_NOAD:
			case ACCENT_NOAD:
				if (math_type(nucleus(p)) >= SUB_BOX)
					flush_node_list(math_link(nucleus(p)));
				if (math_type(supscr(p)) >= SUB_BOX)
					flush_node_list(math_link(supscr(p)));
				if (math_type(subscr(p)) >= SUB_BOX)
					flush_node_list(math_link(subscr(p)));
				if (type(p) == RADICAL_NOAD)
					free_node(p, RADICAL_NOAD_SIZE);
				else if (type(p) == ACCENT_NOAD)
					free_node(p, ACCENT_NOAD_SIZE);
				else free_node(p, NOAD_SIZE);
				goto done;
			
			case LEFT_NOAD:
			case RIGHT_NOAD:
				free_node(p, NOAD_SIZE);
				goto done;
			
			case FRACTION_NOAD:
				flush_node_list(math_link(numerator(p)));
				flush_node_list(math_link(denominator(p)));
				free_node(p, FRACTION_NOAD_SIZE);
				goto done;

			default:
				confusion("flushing");
				break;
			}
			free_node(p, SMALL_NODE_SIZE);
			done:;	
		}
		p = q;
	}
}
Esempio n. 8
0
tex::lig_t::lig_t(int c) // lig_item
	{
	tex::type(this) = LIGATURE_NODE;
	tex::subtype(this) = c;
	lig_ptr(this) = 0;
	}
Esempio n. 9
0
void tex::short_display(ptr p)
	{
	int	n;

	for (; p != null; p = link(p)) {
		if (is_char_node(p)) {
			if (font(p) != font_in_short_display) {
				if (font(p) < FONT_BASE || font(p) > FONT_MAX) {
					print("*");
				} else {
					print_esc(null_str);
					print(font_id_text(font(p)));
				}
				print(" ");
				font_in_short_display = font(p);
			}
			print_ASCII(character(p));
		} else {
			switch (tex::type(p))
			{
			case HLIST_NODE:
			case VLIST_NODE: 
			case INS_NODE:
			case WHATSIT_NODE:
			case MARK_NODE:
			case ADJUST_NODE:
			case UNSET_NODE:
				print("[]");
				break;

			case RULE_NODE:
				print("|");
				break;

			case GLUE_NODE:
				if (glue_ptr(p) != zero_glue)
					print(" ");
				break;

			case MATH_NODE:
				print("$");
				break;

			case LIGATURE_NODE:
				short_display(lig_ptr(p));
				break;

			case DISC_NODE:
				short_display(pre_break(p));
				short_display(post_break(p));
				n = replace_count(p);
				while (n > 0) {
					if (link(p) != null)
						p = link(p);
					decr(n);
				}
				break;

			default:
				break;
			}
		}
	}
}
Esempio n. 10
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;
}