diff options
Diffstat (limited to 'source/luametatex/source/tex')
-rw-r--r-- | source/luametatex/source/tex/texequivalents.c | 2 | ||||
-rw-r--r-- | source/luametatex/source/tex/texexpand.c | 2 | ||||
-rw-r--r-- | source/luametatex/source/tex/texfileio.c | 4 | ||||
-rw-r--r-- | source/luametatex/source/tex/texlanguage.c | 4 | ||||
-rw-r--r-- | source/luametatex/source/tex/texlinebreak.c | 4 | ||||
-rw-r--r-- | source/luametatex/source/tex/texmaincontrol.c | 23 | ||||
-rw-r--r-- | source/luametatex/source/tex/texmath.c | 32 | ||||
-rw-r--r-- | source/luametatex/source/tex/texmath.h | 4 | ||||
-rw-r--r-- | source/luametatex/source/tex/texprimitive.c | 14 | ||||
-rw-r--r-- | source/luametatex/source/tex/texprinting.c | 40 | ||||
-rw-r--r-- | source/luametatex/source/tex/texscanning.c | 15 | ||||
-rw-r--r-- | source/luametatex/source/tex/texstringpool.c | 18 | ||||
-rw-r--r-- | source/luametatex/source/tex/texstringpool.h | 64 | ||||
-rw-r--r-- | source/luametatex/source/tex/textoken.c | 26 | ||||
-rw-r--r-- | source/luametatex/source/tex/textoken.h | 8 |
15 files changed, 103 insertions, 157 deletions
diff --git a/source/luametatex/source/tex/texequivalents.c b/source/luametatex/source/tex/texequivalents.c index 291126fff..aa434d8fd 100644 --- a/source/luametatex/source/tex/texequivalents.c +++ b/source/luametatex/source/tex/texequivalents.c @@ -1437,7 +1437,7 @@ void tex_forced_word_define(int g, halfword p, singleword f, halfword w) void tex_save_for_after_group(halfword t) { - if (cur_level > level_one && tex_room_on_save_stack()) { + if (t && cur_level > level_one && tex_room_on_save_stack()) { save_type(lmt_save_state.save_stack_data.ptr) = insert_tokens_save_type; save_level(lmt_save_state.save_stack_data.ptr) = level_zero; save_value(lmt_save_state.save_stack_data.ptr) = t; diff --git a/source/luametatex/source/tex/texexpand.c b/source/luametatex/source/tex/texexpand.c index 25dcccdf3..a0416d118 100644 --- a/source/luametatex/source/tex/texexpand.c +++ b/source/luametatex/source/tex/texexpand.c @@ -684,7 +684,7 @@ inline static halfword tex_aux_get_cs_name(void) if (tex_aux_collect_cs_tokens(&p, &n)) { /*tex Look up the characters of list |r| in the hash table, and set |cur_cs|. */ int siz; - char *s = tex_tokenlist_to_tstring(h, 1, &siz, 0, 0, 0); + char *s = tex_tokenlist_to_tstring(h, 1, &siz, 0, 0, 0, 0); cur_cs = (siz > 0) ? tex_string_locate((char *) s, siz, 1) : null_cs; } else { tex_aux_complain_missing_csname(); diff --git a/source/luametatex/source/tex/texfileio.c b/source/luametatex/source/tex/texfileio.c index 4f712401b..c29e7cece 100644 --- a/source/luametatex/source/tex/texfileio.c +++ b/source/luametatex/source/tex/texfileio.c @@ -875,10 +875,8 @@ char *tex_read_file_name(int optionalequal, const char * name, const char* ext) } } DONE: - s = tex_tokenlist_to_tstring(result, 1, &l, 0, 0, 0); + s = tex_tokenlist_to_tstring(result, 1, &l, 0, 0, 0, 1); fn = s ? tex_aux_pack_file_name(s, l, name, ext) : NULL; - /*tex Shouldn't we also free |result| ? */ - tex_flush_token_list(result); return fn; } diff --git a/source/luametatex/source/tex/texlanguage.c b/source/luametatex/source/tex/texlanguage.c index 6f3460c22..22627ee58 100644 --- a/source/luametatex/source/tex/texlanguage.c +++ b/source/luametatex/source/tex/texlanguage.c @@ -364,7 +364,7 @@ void tex_clear_patterns(struct tex_language *lang) void tex_load_tex_patterns(halfword curlang, halfword head) { - char *s = tex_tokenlist_to_tstring(head, 1, NULL, 0, 0, 0); + char *s = tex_tokenlist_to_tstring(head, 1, NULL, 0, 0, 0, 0); if (s) { tex_load_patterns(tex_get_language(curlang), (unsigned char *) s); } @@ -539,7 +539,7 @@ void tex_clear_hyphenation(struct tex_language *lang) void tex_load_tex_hyphenation(halfword curlang, halfword head) { - char *s = tex_tokenlist_to_tstring(head, 1, NULL, 0, 0, 0); + char *s = tex_tokenlist_to_tstring(head, 1, NULL, 0, 0, 0, 0); if (s) { tex_load_hyphenation(tex_get_language(curlang), (unsigned char *) s); } diff --git a/source/luametatex/source/tex/texlinebreak.c b/source/luametatex/source/tex/texlinebreak.c index 2172277ec..2e0c945a7 100644 --- a/source/luametatex/source/tex/texlinebreak.c +++ b/source/luametatex/source/tex/texlinebreak.c @@ -3145,7 +3145,7 @@ static void tex_aux_post_line_break(const line_break_properties *properties, hal n = node_next(n); } } - if (! n) { + if (! n && normalize_line_mode_par) { /*tex For the moment: */ tex_normal_warning("tex", "right parinit skip is gone"); } @@ -3163,7 +3163,7 @@ static void tex_aux_post_line_break(const line_break_properties *properties, hal n = node_prev(n); } } - if (! n) { + if (! n && normalize_line_mode_par) { /*tex For the moment: */ tex_normal_warning("tex", "left parfill skip is gone"); } diff --git a/source/luametatex/source/tex/texmaincontrol.c b/source/luametatex/source/tex/texmaincontrol.c index a44aa1167..5e0bb2f92 100644 --- a/source/luametatex/source/tex/texmaincontrol.c +++ b/source/luametatex/source/tex/texmaincontrol.c @@ -1372,11 +1372,13 @@ static void tex_aux_run_after_something(void) { } while (cur_cmd == spacer_cmd); if (cur_cmd == left_brace_cmd) { halfword source = tex_scan_toks_normal(1, NULL); - if (source) { - tex_save_for_after_group(token_link(source)); - token_link(source) = null; + if (source) { + if (token_link(source)) { + tex_save_for_after_group(token_link(source)); + token_link(source) = null; + } + tex_put_available_token(source); } - tex_flush_token_list(source); } else { tex_handle_error( normal_error_type, @@ -1394,10 +1396,11 @@ static void tex_aux_run_after_something(void) { if (cur_cmd == left_brace_cmd) { halfword source = tex_scan_toks_normal(1, NULL); if (source) { + /*tex Always, also when empty. */ lmt_main_control_state.after_tokens = token_link(source); token_link(source) = null; + tex_put_available_token(source); } - tex_flush_token_list(source); } else { tex_handle_error( normal_error_type, @@ -1422,7 +1425,7 @@ static void tex_aux_run_after_something(void) { } token_link(p) = token_link(source); token_link(source) = null; - tex_flush_token_list(source); + tex_put_available_token(source); } else { update_tex_end_of_group(source); } @@ -4118,7 +4121,6 @@ static void tex_aux_set_shorthand_def(int a, int force) { mathcodeval mval = tex_scan_mathchar(tex_mathcode); tex_define(a, p, mathspec_cmd, tex_new_math_spec(mval, tex_mathcode)); - // tex_define(a, p, math_char_given_cmd, math_old_packed_character(mval.class_value,mval.family_value,mval.character_value)); break; } case math_dchar_def_code: @@ -4126,14 +4128,12 @@ static void tex_aux_set_shorthand_def(int a, int force) mathdictval dval = tex_scan_mathdict(); mathcodeval mval = tex_scan_mathchar(umath_mathcode); tex_define(a, p, mathspec_cmd, tex_new_math_dict_spec(dval, mval, umath_mathcode)); - // tex_define(a, p, math_char_xgiven_cmd, math_packed_character(mval.class_value,mval.family_value,mval.character_value)); break; } case math_xchar_def_code: { mathcodeval mval = tex_scan_mathchar(umath_mathcode); tex_define(a, p, mathspec_cmd, tex_new_math_spec(mval, umath_mathcode)); - // tex_define(a, p, math_char_xgiven_cmd, math_packed_character(mval.class_value,mval.family_value,mval.character_value)); break; } case count_def_code: @@ -5854,14 +5854,13 @@ static void tex_aux_run_message(void) strnumber s = tex_aux_scan_string(); if (error_help_par) { strnumber helpinfo = tex_tokens_to_string(error_help_par); - char *h = tex_makecstring(helpinfo); + char *h = tex_to_cstring(helpinfo); tex_handle_error( normal_error_type, "%T", s, h ); - lmt_memory_free(h); tex_flush_str(helpinfo); } else if (lmt_error_state.long_help_seen) { tex_handle_error( @@ -6298,8 +6297,6 @@ inline static void tex_aux_big_switch(int mode, int cmd) register_runner(italic_correction_cmd, tex_aux_run_illegal_case, tex_aux_run_text_italic_correction, tex_run_math_italic_correction); register_runner(math_char_number_cmd, tex_aux_run_math_non_math, tex_run_text_math_char_number, tex_run_math_math_char_number); - // register_runner(math_char_given_cmd, tex_aux_run_math_non_math, tex_run_text_math_char_given, tex_run_math_math_char_given); - // register_runner(math_char_xgiven_cmd, tex_aux_run_math_non_math, tex_run_text_math_char_xgiven, tex_run_math_math_char_xgiven); register_runner(mathspec_cmd, tex_aux_run_math_non_math, tex_run_text_math_spec, tex_run_math_math_spec); register_runner(vadjust_cmd, tex_aux_run_illegal_case, tex_run_vadjust, tex_run_vadjust); diff --git a/source/luametatex/source/tex/texmath.c b/source/luametatex/source/tex/texmath.c index 52e200657..3f452b1ff 100644 --- a/source/luametatex/source/tex/texmath.c +++ b/source/luametatex/source/tex/texmath.c @@ -1713,12 +1713,6 @@ static int tex_aux_scan_math(halfword target, halfword style, int usetextfont, h mval = tex_get_math_spec(cur_chr); dval = tex_get_math_dict(cur_chr); break; - // case math_char_given_cmd: - // mval = tex_mathchar_from_integer(cur_chr, tex_mathcode); - // break; - // case math_char_xgiven_cmd: - // mval = tex_mathchar_from_integer(cur_chr, umath_mathcode); - // break; case delimiter_number_cmd: switch (cur_chr) { case math_delimiter_code: @@ -1962,12 +1956,6 @@ int tex_scan_math_cmd_val(mathcodeval *mval, mathdictval *dval) tex_get_x_token(); } while (cur_cmd == spacer_cmd); switch (cur_cmd) { - // case math_char_given_cmd: - // *mval = tex_mathchar_from_integer(cur_chr, tex_mathcode); - // break; - // case math_char_xgiven_cmd: - // *mval = tex_mathchar_from_integer(cur_chr, umath_mathcode); - // break; case mathspec_cmd: *mval = tex_get_math_spec(cur_chr); break; @@ -2050,26 +2038,6 @@ void tex_run_math_math_char_number(void) { } } -/*tex We build up an argument to |append_math_char|: */ - -// void tex_run_text_math_char_given(void) { -// tex_aux_append_math_char_in_text(tex_mathchar_from_integer(cur_chr, tex_mathcode)); -// } -// -// void tex_run_math_math_char_given(void) { -// tex_aux_append_math_char(tex_mathchar_from_integer(cur_chr, tex_mathcode)); -// } - -/*tex We build up an argument to |append_math_char| the \LUATEX\ way: */ - -// void tex_run_text_math_char_xgiven(void) { -// tex_aux_append_math_char_in_text(tex_mathchar_from_integer(cur_chr, umath_mathcode)); -// } -// -// void tex_run_math_math_char_xgiven(void) { -// tex_aux_append_math_char(tex_mathchar_from_integer(cur_chr, umath_mathcode)); -// } - void tex_run_math_delimiter_number(void) { switch (cur_chr) { case math_delimiter_code: diff --git a/source/luametatex/source/tex/texmath.h b/source/luametatex/source/tex/texmath.h index e024a6ba2..cc7aa7e7f 100644 --- a/source/luametatex/source/tex/texmath.h +++ b/source/luametatex/source/tex/texmath.h @@ -642,10 +642,6 @@ extern void tex_run_math_math_char_number (void); extern void tex_run_text_math_char_number (void); extern void tex_run_math_char_number (void); extern void tex_run_math_delimiter_number (void); -// void tex_run_math_math_char_given (void); -// void tex_run_text_math_char_given (void); -// void tex_run_math_math_char_xgiven (void); -// void tex_run_text_math_char_xgiven (void); extern void tex_run_math_equation_number (void); extern void tex_run_math_shift (void); extern void tex_run_math_italic_correction (void); diff --git a/source/luametatex/source/tex/texprimitive.c b/source/luametatex/source/tex/texprimitive.c index bbeea1bc0..42344af15 100644 --- a/source/luametatex/source/tex/texprimitive.c +++ b/source/luametatex/source/tex/texprimitive.c @@ -185,7 +185,7 @@ static int tex_aux_room_in_hash(void) inline static halfword tex_aux_compute_hash(const char *j, int l) { halfword h = (unsigned const char) j[0]; - for (int k = 1; k < l; k++) { + for (unsigned k = 1; k < l; k++) { h = (h + h + (unsigned const char) j[k]) % hash_prime; } return h; @@ -765,18 +765,6 @@ void tex_print_cmd_chr(singleword cmd, halfword chr) tex_print_str_esc("char"); tex_print_qhex(chr); break; - // case math_char_given_cmd: - // /*tex - // Okay, it's better for old macro packages that mess with meaning to report a more - // traditional value. A compromise. But, this might be dropped. - // */ - // tex_print_str_esc("mathchar"); - // tex_show_mathcode_value(tex_mathchar_from_integer(chr, tex_mathcode), tex_mathcode); - // break; - // case math_char_xgiven_cmd: - // tex_print_str_esc("Umathchar"); - // tex_show_mathcode_value(tex_mathchar_from_integer(chr, umath_mathcode), umath_mathcode); - // break; case lua_call_cmd: tex_aux_show_lua_call("luacall", chr); break; diff --git a/source/luametatex/source/tex/texprinting.c b/source/luametatex/source/tex/texprinting.c index 9a7c1d729..deabb4b72 100644 --- a/source/luametatex/source/tex/texprinting.c +++ b/source/luametatex/source/tex/texprinting.c @@ -217,9 +217,9 @@ void tex_print_char(int s) The first 256 entries above the 17th unicode plane are used for a special trick: when \TEX\ has to print items in that range, it will instead print the character that results from substracting - 0x110000 from that value. This allows byte-oriented output to things like |\specials|. - - This feature will disappear. + 0x110000 from that value. This allows byte-oriented output to things like |\specials|. We dropped + this feature because it was never used (we used it as part of experiments with \LUATEX). The old + code branches can be found in the repository. */ @@ -245,13 +245,6 @@ static void tex_aux_uprint(int s) tex_print_char(0xE0 + (s / 0x1000)); tex_print_char(0x80 + ((s % 0x1000) / 0x40)); tex_print_char(0x80 + ((s % 0x1000) % 0x40)); - } else if (s >= 0x110000) { - int c = s - 0x110000; - if (c >= 256) { - tex_formatted_warning("print", "bad raw byte to print (c=%d), skipped",c); - } else { - tex_print_char(c); - } } else { tex_print_char(0xF0 + (s / 0x40000)); tex_print_char(0x80 + ((s % 0x40000) / 0x1000)); @@ -260,24 +253,6 @@ static void tex_aux_uprint(int s) } } -static void tex_aux_lprint(lstring *ss) { - /*tex current character code position */ - unsigned char *j = ss->s; - unsigned char *l = j + ss->l; - while (j < l) { - /*tex We don't bother checking the last two bytes explicitly */ - /* 0x110000 in utf=8: 0xF4 0x90 0x80 0x80 */ - if ((j < l - 4) && (*j == 0xF4) && (*(j + 1) == 0x90)) { - int c = (*(j + 2) - 128) * 64 + (*(j + 3) - 128); - tex_print_char(c); - j = j + 4; - } else { - tex_print_char(*j); - ++j; - } - } -} - void tex_print_tex_str(int s) { if (s >= lmt_string_pool_state.string_pool_data.ptr) { @@ -291,7 +266,10 @@ void tex_print_tex_str(int s) } else if (lmt_print_state.selector == new_string_selector_code) { tex_append_string(str_string(s), (unsigned) str_length(s)); } else { - tex_aux_lprint(&str_lstring(s)); + unsigned char *j = str_string(s); + for (unsigned i = 0; i < str_length(s); i++) { + tex_print_char(j[i]); + } } } @@ -453,7 +431,7 @@ void tex_print_tex_str_esc(strnumber s) { /*tex Set variable |c| to the current escape character: */ int c = escape_char_par; - if (c >= 0 && c < 0x110000) { + if (c >= 0) { tex_print_tex_str(c); } if (s) { @@ -467,7 +445,7 @@ void tex_print_str_esc(const char *s) { /*tex Set variable |c| to the current escape character: */ int c = escape_char_par; - if (c >= 0 && c < 0x110000) { + if (c >= 0) { tex_print_tex_str(c); } if (s) { diff --git a/source/luametatex/source/tex/texscanning.c b/source/luametatex/source/tex/texscanning.c index 5dd34b3b6..fec04356b 100644 --- a/source/luametatex/source/tex/texscanning.c +++ b/source/luametatex/source/tex/texscanning.c @@ -1088,18 +1088,13 @@ void tex_scan_something_simple(halfword cmd, halfword chr) switch (cmd) { /* begin of tex_aux_short_scan_something_internal */ case char_given_cmd: - // case math_char_given_cmd: - // case math_char_xgiven_cmd: cur_val = chr; cur_val_level = int_val_level; break; - -case mathspec_cmd: - cur_val = (chr && node_subtype(chr) == tex_mathcode) ? math_spec_value(chr) : 0; - cur_val_level = int_val_level; - break; - - + case mathspec_cmd: + cur_val = (chr && node_subtype(chr) == tex_mathcode) ? math_spec_value(chr) : 0; + cur_val_level = int_val_level; + break; case iterator_value_cmd: cur_val = chr > 0x100000 ? - (chr - 0x100000) : chr; cur_val_level = int_val_level; @@ -1254,8 +1249,6 @@ static halfword tex_aux_scan_something_internal(halfword cmd, halfword chr, int switch (cmd) { /* begin of tex_aux_short_scan_something_internal */ case char_given_cmd: - // case math_char_given_cmd: - // case math_char_xgiven_cmd: cur_val = chr; cur_val_level = int_val_level; break; diff --git a/source/luametatex/source/tex/texstringpool.c b/source/luametatex/source/tex/texstringpool.c index 8367447da..fd93758b5 100644 --- a/source/luametatex/source/tex/texstringpool.c +++ b/source/luametatex/source/tex/texstringpool.c @@ -435,6 +435,7 @@ char *tex_makeclstring(int s, size_t *len) } } +/* char *tex_makecstring(int s) { if (s < cs_offset_value) { @@ -443,6 +444,23 @@ char *tex_makecstring(int s) return lmt_memory_strdup((str_length(s) > 0) ? (const char *) str_string(s) : ""); } } +*/ + +/*tex + I might eventually replace this because in qite some calls we know that we knwo that we have + a pointer in string space. We can kin dof predict in what cases we are below |cs_offset_value| + anyway. +*/ + +char *tex_makecstring(int s, int *allocated) +{ + *allocated = s < cs_offset_value; + if (*allocated) { + return (char *) aux_uni2str((unsigned) s); + } else { + return str_length(s) > 0 ? (char *) str_string(s) : ""; + } +} /*tex diff --git a/source/luametatex/source/tex/texstringpool.h b/source/luametatex/source/tex/texstringpool.h index b3924a0fe..7302e7fb4 100644 --- a/source/luametatex/source/tex/texstringpool.h +++ b/source/luametatex/source/tex/texstringpool.h @@ -21,7 +21,7 @@ typedef struct lstring { unsigned char *s; const char *c; }; - size_t l; /* could be int, but this way we padd */ + size_t l; /* could be int, but this way we padd */ } lstring; typedef struct string_pool_info { @@ -76,35 +76,37 @@ extern string_pool_info lmt_string_pool_state; /*tex Forget the last character in the pool. */ -inline void tex_flush_char(void) { --lmt_string_pool_state.string_temp_top; } - -extern strnumber tex_make_string (void); -extern strnumber tex_push_string (const unsigned char *s, int l); -extern char *tex_take_string (int *len); -extern int tex_str_eq_buf (strnumber s, int k, int n); -extern int tex_str_eq_str (strnumber s, strnumber t); -extern int tex_str_eq_cstr (strnumber s, const char *, size_t); -extern int tex_get_strings_started (void); -extern void tex_reset_cur_string (void); -/* strnumber tex_search_string (strnumber search); */ -/* int tex_used_strings (void); */ -extern strnumber tex_maketexstring (const char *s); -extern strnumber tex_maketexlstring (const char *s, size_t); -extern void tex_append_char (unsigned char c); -extern void tex_append_string (const unsigned char *s, unsigned l); -extern char *tex_makecstring (int s); -extern char *tex_makeclstring (int s, size_t *len); -extern void tex_dump_string_pool (dumpstream f); -extern void tex_undump_string_pool (dumpstream f); -extern void tex_initialize_string_pool (void); -extern void tex_initialize_string_mem (void); -extern void tex_flush_str (strnumber s); -extern strnumber tex_save_cur_string (void); -extern void tex_restore_cur_string (strnumber u); - -/* void tex_increment_pool_string (int n); */ -/* void tex_decrement_pool_string (int n); */ - -extern void tex_compact_string_pool (void); +inline void tex_flush_char(void) { --lmt_string_pool_state.string_temp_top; } + +extern strnumber tex_make_string (void); +extern strnumber tex_push_string (const unsigned char *s, int l); +extern char *tex_take_string (int *len); +extern int tex_str_eq_buf (strnumber s, int k, int n); +extern int tex_str_eq_str (strnumber s, strnumber t); +extern int tex_str_eq_cstr (strnumber s, const char *, size_t); +extern int tex_get_strings_started (void); +extern void tex_reset_cur_string (void); +/* strnumber tex_search_string (strnumber search); */ +/* int tex_used_strings (void); */ +extern strnumber tex_maketexstring (const char *s); +extern strnumber tex_maketexlstring (const char *s, size_t); +extern void tex_append_char (unsigned char c); +extern void tex_append_string (const unsigned char *s, unsigned l); +extern char *tex_makecstring (int s, int *allocated); +extern char *tex_makeclstring (int s, size_t *len); +extern void tex_dump_string_pool (dumpstream f); +extern void tex_undump_string_pool (dumpstream f); +extern void tex_initialize_string_pool (void); +extern void tex_initialize_string_mem (void); +extern void tex_flush_str (strnumber s); +extern strnumber tex_save_cur_string (void); +extern void tex_restore_cur_string (strnumber u); + +/* void tex_increment_pool_string (int n); */ +/* void tex_decrement_pool_string (int n); */ + +extern void tex_compact_string_pool (void); + +inline char *tex_to_cstring (int s) { return str_length(s) > 0 ? (char *) str_string(s) : ""; } # endif diff --git a/source/luametatex/source/tex/textoken.c b/source/luametatex/source/tex/textoken.c index 0bb0f3e45..93bf3913a 100644 --- a/source/luametatex/source/tex/textoken.c +++ b/source/luametatex/source/tex/textoken.c @@ -2820,7 +2820,7 @@ void tex_run_convert_tokens(halfword code) /* halfword result = tex_scan_toks_expand(0, NULL, code == lua_token_string_code); */ lmt_token_state.in_lua_escape = 1; escape_char_par = '\\'; - str.s = (unsigned char *) tex_tokenlist_to_tstring(result, 0, &length, 0, 0, 0); + str.s = (unsigned char *) tex_tokenlist_to_tstring(result, 0, &length, 0, 0, 0, 0); str.l = (unsigned) length; lmt_token_state.in_lua_escape = saved_in_lua_escape; escape_char_par = saved_escape_char; @@ -3034,8 +3034,6 @@ static void tex_aux_append_uchar_to_buffer(int s) lmt_token_state.buffer[lmt_token_state.bufloc++] = (char) (0xE0 + (s / 0x1000)); lmt_token_state.buffer[lmt_token_state.bufloc++] = (char) (0x80 + ((s % 0x1000) / 0x40)); lmt_token_state.buffer[lmt_token_state.bufloc++] = (char) (0x80 + ((s % 0x1000) % 0x40)); - } else if (s >= 0x110000) { - lmt_token_state.buffer[lmt_token_state.bufloc++] = (char) (s - 0x11000); } else { lmt_token_state.buffer[lmt_token_state.bufloc++] = (char) (0xF0 + (s / 0x40000)); lmt_token_state.buffer[lmt_token_state.bufloc++] = (char) (0x80 + ((s % 0x40000) / 0x1000)); @@ -3078,7 +3076,7 @@ static void tex_aux_append_esc_to_buffer(const char *s) /* make two versions: macro and not */ -char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamble, int nospace, int strip) +char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamble, int nospace, int strip, int wipe) { if (pp) { /*tex We need to go beyond the reference. */ @@ -3100,6 +3098,8 @@ char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamb int min = 0; int max = lmt_token_memory_state.tokens_data.top; int skip = 0; + int tail = p; + int count = 0; if (skippreamble) { skip = get_token_parameters(pp); } @@ -3210,7 +3210,8 @@ char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamb if (txt < 0 || txt >= lmt_string_pool_state.string_pool_data.ptr) { tex_aux_append_str_to_buffer(error_string_nonexistent(36)); } else { - char *sh = tex_makecstring(txt); + int allocated = 0; + char *sh = tex_makecstring(txt, &allocated); char *s = sh; if (tex_is_active_cs(txt)) { s = s + 3; @@ -3219,7 +3220,7 @@ char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamb s++; } } else { - if (e >= 0 && e < 0x110000) { + if (e >= 0) { tex_aux_append_uchar_to_buffer(e); } while (*s) { @@ -3230,10 +3231,14 @@ char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamb tex_aux_append_char_to_buffer(' '); } } - lmt_memory_free(sh); + if (allocated) { + lmt_memory_free(sh); + } } } } + tail = p; + ++count; p = token_link(p); } } @@ -3251,7 +3256,14 @@ char *tex_tokenlist_to_tstring(int pp, int inhibit_par, int *siz, int skippreamb if (siz) { *siz = lmt_token_state.bufloc; } + if (wipe) { + tex_flush_token_list_head_tail(pp, tail, count); + } return lmt_token_state.buffer; + } else { + if (wipe) { + tex_put_available_token(pp); + } } } if (siz) { diff --git a/source/luametatex/source/tex/textoken.h b/source/luametatex/source/tex/textoken.h index 1996f351c..ad67dfcb5 100644 --- a/source/luametatex/source/tex/textoken.h +++ b/source/luametatex/source/tex/textoken.h @@ -366,8 +366,7 @@ extern void tex_run_combine_the_toks (void); extern void tex_run_convert_tokens (halfword code); extern strnumber tex_the_convert_string (halfword c, int i); extern strnumber tex_tokens_to_string (halfword p); -/* char *tex_tokenlist_to_cstring (int p, int inhibit_par, int *siz); */ -extern char *tex_tokenlist_to_tstring (int p, int inhibit_par, int *siz, int skip, int nospace, int strip); +extern char *tex_tokenlist_to_tstring (int p, int inhibit_par, int *siz, int skip, int nospace, int strip, int wipe); extern halfword tex_get_tex_dimen_register (int j, int internal); extern halfword tex_get_tex_skip_register (int j, int internal); @@ -391,9 +390,6 @@ extern halfword tex_copy_token_list (halfword h, halfword *t); extern halfword tex_parse_str_to_tok (halfword head, halfword *tail, halfword ct, const char *str, size_t lstr, int option); -inline int tex_valid_token(int t) -{ - return ((t >= 0) && (t <= (int) lmt_token_memory_state.tokens_data.top)); -} +inline int tex_valid_token (int t) { return ((t >= 0) && (t <= (int) lmt_token_memory_state.tokens_data.top)); } # endif |