1 /* Copyright 2014 Clerk Ma
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
41 while (!(cur_cmd != spacer));
43 if (cur_tok == other_token + '-')
46 cur_tok = other_token + '+';
49 while (!(cur_tok != other_token + '+'));
51 if (cur_tok == alpha_token)
55 if (cur_tok < cs_token_flag)
59 if (cur_cmd <= right_brace)
60 if (cur_cmd == right_brace)
65 else if (cur_tok < cs_token_flag + single_base)
66 cur_val = cur_tok - cs_token_flag - active_base;
68 cur_val = cur_tok - cs_token_flag - single_base;
72 print_err("Improper alphabetic constant");
73 help2("A one-character control sequence belongs after a ` mark.",
74 "So I'm essentially inserting \\0 here.");
82 if (cur_cmd != spacer)
86 else if ((cur_cmd >= min_internal) && (cur_cmd <= max_internal))
88 scan_something_internal(int_val, false);
93 m = 214748364L; /* 7FFFFFFF hex */
95 if (cur_tok == octal_token)
98 m = 268435456L; /* 2^28 */
101 else if (cur_tok == hex_token)
104 m = 134217728L; /* 2^27 8000000 hex */
113 if ((cur_tok < zero_token + radix) && (cur_tok >= zero_token) && (cur_tok <= zero_token + 9))
114 d = cur_tok - zero_token;
115 else if (radix == 16)
116 if ((cur_tok <= A_token + 5) && (cur_tok >= A_token))
117 d = cur_tok - A_token + 10;
118 else if ((cur_tok <= other_A_token + 5) && (cur_tok >= other_A_token))
119 d = cur_tok - other_A_token;
127 if ((cur_val >= m) && ((cur_val > m) || (d > 7) || (radix != 10)))
131 print_err("Number too big");
132 help2("I can only go up to 2147483647='17777777777=\"7FFFFFFF,",
133 "so I'm using that number instead of yours.");
135 cur_val = 2147483647L; /* 7FFFFFFF hex */
140 cur_val = cur_val * radix + d;
147 print_err("Missing number, treated as zero");
148 help3("A number should have been here; I inserted `0'.",
149 "(If you can't figure out why I needed to see a number,",
150 "look up `weird error' in the index to The TeXbook.)");
153 else if (cur_cmd != spacer)
158 cur_val = - (integer) cur_val;
161 void scan_dimen_(boolean mu, boolean inf, boolean shortcut)
186 while (!(cur_cmd != spacer));
188 if (cur_tok == other_token + '-')
190 negative = ! negative;
191 cur_tok = other_token + '+';
194 while (!(cur_tok != other_token + '+'));
196 if ((cur_cmd >= min_internal) && (cur_cmd <= max_internal))
200 scan_something_internal(mu_val, false);
202 if (cur_val_level >= glue_val)
205 delete_glue_ref(cur_val);
209 if (cur_val_level == mu_val)
212 if (cur_val_level != int_val)
217 scan_something_internal(dimen_val, false);
219 if (cur_val_level == dimen_val)
227 if (cur_tok == continental_point_token)
228 cur_tok = point_token;
230 if (cur_tok != point_token)
240 if (cur_tok == continental_point_token)
241 cur_tok = point_token;
243 if ((radix == 10) && (cur_tok == point_token))
246 p = 0; /* p:=null l.8883 */
253 if ((cur_tok > zero_token + 9) || (cur_tok < zero_token))
260 info(q) = cur_tok - zero_token;
266 for (kk = k; kk >= 1; kk--)
268 dig[kk - 1] = info(p);
274 f = round_decimals(k);
276 if (cur_cmd != spacer)
284 negative = !negative;
285 cur_val = - (integer) cur_val;
290 if (scan_keyword("fil"))
294 while (scan_keyword("l"))
296 if (cur_order == filll)
298 print_err("Illegal unit of measure (");
299 print_string("replaced by filll)");
300 help1("I dddon't go any higher than filll.");
310 savecurval = cur_val;
316 while (!(cur_cmd != spacer));
318 if ((cur_cmd < min_internal) || (cur_cmd > max_internal))
324 scan_something_internal(mu_val, false);
326 if (cur_val_level >= glue_val)
329 delete_glue_ref(cur_val);
333 if (cur_val_level != mu_val)
340 scan_something_internal(dimen_val, false);
350 if (scan_keyword("em"))
352 else if (scan_keyword("ex"))
353 v = x_height(cur_font);
360 if (cur_cmd != spacer)
365 cur_val = mult_and_add(savecurval, v, xn_over_d(v, f, 65536L), 1073741823L); /* 2^30 - 1 */
371 if (scan_keyword("mu"))
375 print_err("Illegal unit of measure (");
376 print_string("mu inserted)");
377 help4("The unit of measurement in math glue must be mu.",
378 "To recover gracefully from this error, it's best to",
379 "delete the erroneous units; e.g., type `2' to delete",
380 "two letters. (See Chapter 27 of The TeXbook.)");
386 if (scan_keyword("true"))
392 cur_val = xn_over_d(cur_val, 1000, mag);
393 f = (1000 * f + 65536L * tex_remainder) / mag;
394 cur_val = cur_val + (f / 65536L);
399 if (scan_keyword("pt"))
402 if (scan_keyword("in"))
403 set_conversion(7227, 100);
404 else if (scan_keyword("pc"))
405 set_conversion(12, 1);
406 else if (scan_keyword("cm"))
407 set_conversion(7227, 254);
408 else if (scan_keyword("mm"))
409 set_conversion(7227, 2540);
410 else if (scan_keyword("bp"))
411 set_conversion(7227, 7200);
412 else if (scan_keyword("dd"))
413 set_conversion(1238, 1157);
414 else if (scan_keyword("cc"))
415 set_conversion(14856, 1157);
416 else if (scan_keyword("Q"))
417 set_conversion(7227, 10160);
418 else if (scan_keyword("H"))
419 set_conversion(7227, 10160);
420 else if (scan_keyword("sp"))
424 print_err("Illegal unit of measure (");
425 print_string("pt inserted)");
426 help6("Dimensions can be in units of em, ex, in, pt, pc,",
427 "cm, mm, dd, cc, bp, or sp; but yours is a new one!",
428 "I'll assume that you meant to say pt, for printer's points.",
429 "To recover gracefully from this error, it's best to",
430 "delete the erroneous units; e.g., type `2' to delete",
431 "two letters. (See Chapter 27 of The TeXbook.)");
436 cur_val = xn_over_d(cur_val, num, denom);
437 f = (num * f + 65536L * tex_remainder) / denom;
438 cur_val = cur_val +(f / 65536L);
442 if (cur_val >= 16384) /* 2^14 */
445 cur_val = cur_val * unity + f;
450 if (cur_cmd != spacer)
454 if (arith_error || (abs(cur_val) >= 1073741824L)) /* 2^30 */
456 print_err("Dimension too large");
457 help2("I can't work with sizes bigger than about 19 feet.",
458 "Continue and I'll use the largest value I can.");
465 cur_val = - (integer) cur_val;
468 void scan_glue_(small_number level)
474 mu = (level == mu_val);
483 while (!(cur_cmd != spacer));
485 if (cur_tok == other_token + '-')
487 negative = !negative;
488 cur_tok = other_token + '+';
491 while (!(cur_tok != other_token + '+'));
493 if ((cur_cmd >= min_internal) && (cur_cmd <= max_internal))
495 scan_something_internal(level, negative);
497 if (cur_val_level >= glue_val)
499 if (cur_val_level != level)
506 if (cur_val_level == int_val)
508 scan_dimen(mu, false, true);
510 else if (level == mu_val)
518 scan_dimen(mu, false, false);
521 cur_val = - (integer) cur_val;
523 q = new_spec(zero_glue);
526 if (scan_keyword("plus"))
528 scan_dimen(mu, true, false);
529 stretch(q) = cur_val;
530 stretch_order(q) = cur_order;
533 if (scan_keyword("minus"))
535 scan_dimen(mu, true, false);
537 shrink_order(q) = cur_order;
543 halfword scan_rule_spec (void)
549 if (cur_cmd == vrule)
550 width(q) = default_rule;
553 height(q) = default_rule;
559 if (scan_keyword("width"))
561 scan_dimen(false, false, false);
566 if (scan_keyword("height"))
568 scan_dimen(false, false, false);
573 if (scan_keyword("depth"))
575 scan_dimen(false, false, false);
583 halfword str_toks_(pool_pointer b)
604 fast_store_new_token(t);
613 halfword the_toks (void)
615 register halfword Result;
621 scan_something_internal(tok_val, false);
623 if (cur_val_level >= ident_val)
628 if (cur_val_level == ident_val)
629 store_new_token(cs_token_flag + cur_val);
630 else if (cur_val != 0)
636 fast_store_new_token(info(r));
645 old_setting = selector;
646 selector = new_string;
649 switch (cur_val_level)
656 print_scaled(cur_val);
662 print_spec(cur_val, "pt");
663 delete_glue_ref(cur_val);
668 print_spec(cur_val, "mu");
669 delete_glue_ref(cur_val);
673 selector = old_setting;
674 Result = str_toks(b);
680 void ins_the_toks (void)
682 link(garbage) = the_toks();
683 begin_token_list(link(temp_head), 4);
686 void conv_toks (void)
690 small_number save_scanner_status;
698 case roman_numeral_code:
704 save_scanner_status = scanner_status;
707 scanner_status = save_scanner_status;
720 old_setting = selector;
721 selector = new_string;
730 case roman_numeral_code:
731 print_roman_int(cur_val);
746 print(font_name[cur_val]);
748 if (font_size[cur_val] != font_dsize[cur_val])
750 print_string(" at ");
751 print_scaled(font_size[cur_val]);
761 selector = old_setting;
762 link(garbage) = str_toks(b);
763 begin_token_list(link(temp_head), 4);
766 halfword scan_toks_(boolean macrodef, boolean xpand)
768 register halfword Result;
777 scanner_status = defining;
779 scanner_status = absorbing;
781 warning_index = cur_cs;
782 def_ref = get_avail();
783 token_ref_count(def_ref) = 0;
794 if (cur_tok < right_brace_limit)
797 if (cur_cmd == mac_param)
799 s = match_token + cur_chr;
802 if (cur_cmd == left_brace)
805 store_new_token(cur_tok);
806 store_new_token(end_match_token);
810 if (t == zero_token + 9)
812 print_err("You already have nine parameters");
813 help1("I'm going to ignore the # sign you just used.");
822 print_err("Parameters must be numbered consecutively");
823 help2("I've inserted the digit you should have used after the #.",
824 "Type `1' to delete what you did use.");
831 store_new_token(cur_tok);
835 store_new_token(end_match_token);
837 if (cur_cmd == right_brace)
839 print_err("Missing { inserted");
841 help2("Where was the left brace? You said something like `\\def\\a}',",
842 "which I'm going to interpret as `\\def\\a{}'.");
863 if (cur_cmd <= max_command)
874 if (link(temp_head) != 0)
876 link(p) = link(temp_head);
887 if (cur_tok < right_brace_limit)
888 if (cur_cmd < right_brace)
897 else if (cur_cmd == mac_param)
907 if (cur_cmd != mac_param)
908 if ((cur_tok <= zero_token) || (cur_tok > t))
910 print_err("Illegal parameter number in definition of ");
911 sprint_cs(warning_index);
912 help3("You meant to type ## instead of #, right?",
913 "Or maybe a } was forgotten somewhere earlier, and things",
914 "are all screwed up? I'm going to assume that you meant ##.");
919 cur_tok = out_param_token - '0' + cur_chr;
922 store_new_token(cur_tok);
928 store_new_token(hashbrace);
933 /* used only in ITEX.C */
935 void read_toks_(integer n, halfword r)
940 /* small_number m; */
941 int m; /* 95/Jan/7 */
943 scanner_status = defining;
945 def_ref = get_avail();
946 token_ref_count(def_ref) = 0;
948 store_new_token(end_match_token);
950 if ((n < 0) || (n > 15))
956 align_state = 1000000L;
960 begin_file_reading();
961 cur_input.name_field = m + 1;
963 if (read_open[m] == closed)
964 if (interaction > nonstop_mode)
976 fatal_error("*** (cannot \\read from terminal in nonstop modes)");
979 else if (read_open[m] == 1)
980 if (input_ln(read_file[m], false))
984 (void) a_close(read_file[m]);
989 if (!input_ln(read_file[m], true))
991 (void) a_close(read_file[m]);
994 if (align_state != 1000000L)
997 print_err("File ended within ");
999 help1("This \\read has unbalanced braces.");
1000 align_state = 1000000L;
1008 if (end_line_char_inactive())
1011 buffer[limit] = end_line_char;
1024 if (align_state < 1000000L)
1030 while (!(cur_tok == 0));
1032 align_state = 1000000L;
1036 store_new_token(cur_tok);
1041 while (!(align_state == 1000000L));
1044 scanner_status = normal;
1048 void pass_text (void)
1051 small_number save_scanner_status;
1053 save_scanner_status = scanner_status;
1054 scanner_status = skipping;
1062 if (cur_cmd == fi_or_else)
1070 else if (cur_cmd == if_test)
1074 scanner_status = save_scanner_status;
1077 void change_if_limit_(small_number l, halfword p)
1105 /* called from tex2.c */
1107 void conditional (void)
1113 small_number save_scanner_status;
1114 halfword savecondptr;
1115 small_number thisif;
1118 p = get_node(if_node_size);
1121 subtype(p) = cur_if;
1122 if_line_field(p) = if_line;
1129 savecondptr = cond_ptr;
1140 if (cur_cmd == relax)
1141 if (cur_chr == no_expand_flag)
1143 cur_cmd = active_char;
1144 cur_chr = cur_tok - cs_token_flag - active_base;
1148 if ((cur_cmd > active_char) || (cur_chr > 255))
1161 if (cur_cmd == relax)
1162 if (cur_chr == no_expand_flag)
1164 cur_cmd = active_char;
1165 cur_chr = cur_tok - cs_token_flag - active_base;
1169 if ((cur_cmd > active_char) || (cur_chr > 255))
1175 if (thisif == if_char_code)
1185 if (thisif == if_int_code)
1188 scan_dimen(false, false, false);
1196 while (!(cur_cmd != spacer));
1198 if ((cur_tok >= other_token + '<') && (cur_tok <= other_token + '>'))
1199 r = cur_tok - other_token;
1202 print_err("Missing = inserted for ");
1203 print_cmd_chr(if_test, thisif);
1204 help1("I was expecting to see `<', `=', or `>'. Didn't.");
1209 if (thisif == if_int_code)
1212 scan_dimen(false, false, false);
1237 b = (abs(mode) == 1);
1241 b = (abs(mode) == 102);
1245 b = (abs(mode) == 203);
1256 scan_eight_bit_int();
1259 if (thisif == if_void_code)
1263 else if (thisif == if_hbox_code)
1264 b = (type(p) == hlist_node);
1266 b = (type(p) == vlist_node);
1272 save_scanner_status = scanner_status;
1282 else if (cur_cmd < call)
1293 while ((p != 0) && (q != 0))
1294 if (info(p) != info(q))
1302 b = ((p == 0) && (q == 0));
1306 scanner_status = save_scanner_status;
1312 scan_four_bit_int();
1313 b = (read_open[cur_val] == closed);
1330 if (tracing_commands > 1)
1333 print_string("{case ");
1336 end_diagnostic(false);
1343 if (cond_ptr == savecondptr)
1344 if (cur_chr == or_code)
1348 else if (cur_chr == fi_code)
1351 if_line = if_line_field(p);
1352 cur_if = subtype(p);
1355 free_node(p, if_node_size);
1359 change_if_limit(or_code, savecondptr);
1365 if (tracing_commands > 1)
1370 print_string("{true}");
1372 print_string("{false}");
1374 end_diagnostic(false);
1377 if (b) /* b may be used without ... */
1379 change_if_limit(else_code, savecondptr);
1387 if (cond_ptr == savecondptr)
1389 if (cur_chr != or_code)
1392 print_err("Extra ");
1394 help1("I'm ignoring this; it doesn't match any \\if.");
1397 else if (cur_chr == fi_code)
1400 if_line = if_line_field(p);
1401 cur_if = subtype(p);
1404 free_node(p, if_node_size);
1409 if (cur_chr == fi_code)
1412 if_line = if_line_field(p);
1413 cur_if = subtype(p);
1416 free_node(p, if_node_size);
1422 void begin_name (void)
1427 /* This gathers up a file name and makes a string of it */
1428 /* Also tries to break it into `file area' `file name' and `file extension' */
1429 /* Used by scan_file_name and prompt_file_name */
1430 /* We assume tilde has been converted to pseudo_tilde and space to pseudo_space */
1431 /* returns false if it is given a space character - end of file name */
1433 boolean more_name_(ASCII_code c)
1435 if (quoted_file_name == 0 && c == ' ')
1437 else if (quoted_file_name != 0 && c == '"')
1439 quoted_file_name = 0; /* catch next space character */
1440 return true; /* accept ending quote, but throw away */
1447 if ((c == '/' || c == '\\' || c == ':'))
1449 area_delimiter = cur_length;
1453 ext_delimiter = cur_length;
1460 void end_name (void)
1462 #ifdef ALLOCATESTRING
1463 if (str_ptr + 3 > current_max_strings)
1464 str_start = realloc_str_start(increment_max_strings + 3);
1466 if (str_ptr + 3 > current_max_strings)
1468 overflow("number of strings", current_max_strings - init_str_ptr);
1472 if (str_ptr + 3 > max_strings)
1474 overflow("number of strings", max_strings - init_str_ptr);
1479 if (area_delimiter == 0) // no area delimiter ':' '/' or '\' found
1480 cur_area = 335; // "" default area
1484 str_start[str_ptr + 1] = str_start[str_ptr] + area_delimiter;
1488 if (ext_delimiter == 0) // no extension delimiter '.' found
1490 cur_ext = 335; // "" default extension
1491 cur_name = make_string();
1493 else // did find an extension
1496 str_start[str_ptr + 1] = str_start[str_ptr]+ ext_delimiter - area_delimiter - 1;
1498 cur_ext = make_string();
1502 /* n current name, a current area, e current extension */
1503 /* result in name_of_file[] */
1505 void pack_file_name_(str_number n, str_number a, str_number e)
1513 for (j = str_start[a]; j <= str_start[a + 1] - 1; j++)
1518 if (k <= file_name_size)
1519 name_of_file[k] = xchr[c];
1522 for (j = str_start[n]; j <= str_start[n + 1] - 1; j++)
1527 if (k <= file_name_size)
1528 name_of_file[k] = xchr[c];
1531 for (j = str_start[e]; j <= str_start[e + 1] - 1; j++)
1536 if (k <= file_name_size)
1537 name_of_file[k] = xchr[c];
1540 if (k < file_name_size)
1543 name_length = file_name_size - 1;
1545 /* pad it out with spaces ... what for ? in case we modify and forget ? */
1546 for (k = name_length + 1; k <= file_name_size; k++)
1547 name_of_file[k] = ' ';
1549 name_of_file[file_name_size] = '\0'; /* paranoia 94/Mar/24 */
1552 name_of_file [name_length+1] = '\0';
1556 sprintf(log_line, " pack_file_name `%s' (%d) ", name_of_file + 1, name_length); /* debugging */
1557 show_line(log_line, 0);
1560 name_of_file [name_length + 1] = ' ';
1563 /* Called only from two places tex9.c for format name - specified and default */
1564 /* for specified format name args are 0, a, b name in buffer[a] --- buffer[b] */
1565 /* for default args are format_default_length-4, 1, 0 */
1567 void pack_buffered_name_(small_number n, integer a, integer b)
1573 if (n + b - a + 5 > file_name_size)
1574 b = a + file_name_size - n - 5;
1578 /* This loop kicks in when we want the default format name */
1579 for (j = 1; j <= n; j++)
1581 c = xord[TEX_format_default[j]];
1584 if (k <= file_name_size)
1585 name_of_file[k] = xchr[c];
1587 /* This loop kicks in when we want a specififed format name */
1588 for (j = a; j <= b; j++)
1593 if (k <= file_name_size)
1594 name_of_file[k] = xchr[c];
1597 /* This adds the extension from the default format name */
1598 for (j = format_default_length - 3; j <= format_default_length; j++)
1600 c = xord[TEX_format_default[j]];
1603 if (k <= file_name_size)
1604 name_of_file[k] = xchr[c];
1607 if (k < file_name_size)
1610 name_length = file_name_size - 1;
1612 /* pad it out with spaces ... what for ? */
1613 for (k = name_length + 1; k <= file_name_size; k++)
1614 name_of_file[k]= ' ';
1616 name_of_file[file_name_size] = '\0'; /* paranoia 94/Mar/24 */
1619 str_number make_name_string (void)
1623 #ifdef ALLOCATESTRING
1624 if (pool_ptr + name_length > current_pool_size)
1625 str_pool = realloc_str_pool(increment_pool_size + name_length);
1627 if (str_ptr == current_max_strings)
1628 str_start = realloc_str_start(increment_max_strings);
1630 if ((pool_ptr + name_length > current_pool_size) || (str_ptr == current_max_strings) || (cur_length > 0))
1632 if ((pool_ptr + name_length > pool_size) || (str_ptr == max_strings) || (cur_length > 0))
1639 for (k = 1; k <= name_length; k++)
1640 append_char(xord[name_of_file[k]]);
1642 return make_string();
1646 //str_number a_make_name_string_(alpha_file * f)
1647 str_number a_make_name_string_(void)
1649 return make_name_string();
1652 //str_number b_make_name_string_(byte_file * f)
1653 str_number b_make_name_string_(void)
1655 return make_name_string();
1658 //str_number w_make_name_string_(word_file * f)
1659 str_number w_make_name_string_(void)
1661 return make_name_string();
1664 /* Used by start_input to scan file name on command line */
1665 /* Also in tex8.c new_font_, open_or_close_in, and do_extension */
1667 void scan_file_name (void)
1669 name_in_progress = true;
1676 while (!(cur_cmd != spacer));
1678 quoted_file_name = false;
1680 if (allow_quoted_names)
1684 quoted_file_name = 1;
1691 if ((cur_cmd > other_char) || (cur_chr > 255))
1697 if (!more_name(cur_chr)) /* up to next white space */
1705 name_in_progress = false;
1707 /* argument is string .fmt, .log, or .dvi */
1709 void pack_job_name_(str_number s)
1711 cur_area = 335; /* "" */
1713 cur_name = job_name;
1714 pack_file_name(cur_name, cur_area, cur_ext);
1717 /**********************************************************************/
1719 /* s - what can't be found, e - default */
1720 void prompt_file_name_(char * s, str_number e)
1724 if (interaction == scroll_mode);
1726 if (!strcmp("input file name", s))
1727 print_err("I can't find file `");
1729 print_err("I can't write on file `");
1731 print_file_name(cur_name, cur_area, cur_ext);
1734 if (e == 785) /* .tex */
1737 print_nl("Please type another ");
1740 if (interaction < 2)
1742 fatal_error("*** (job aborted, file error in nonstop mode)");
1748 show_line(" (or ^z to exit)", 0);
1750 show_line(" (or Ctrl-Z to exit)", 0);
1754 /* should we deal with tilde and space in file name here ??? */
1759 while ((buffer[k] == ' ') && (k < last))
1761 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1762 quoted_file_name = 0; /* 98/March/15 */
1764 if (allow_quoted_names && k < last) /* check whether quoted name */
1766 if (buffer[k]== '"')
1768 quoted_file_name = 1;
1777 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1778 /* convert tilde '~' to pseudo tilde */
1779 if (pseudo_tilde != 0 && buffer[k]== '~')
1780 buffer[k] = pseudo_tilde;
1781 /* convert space ' ' to pseudo space */
1782 if (pseudo_space != 0 && buffer[k]== ' ')
1783 buffer[k] = pseudo_space;
1784 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1785 if (!more_name(buffer[k]))
1794 if (cur_ext == 335) /* "" */
1795 cur_ext = e; /* use default extension */
1797 pack_file_name(cur_name, cur_area, cur_ext);
1800 void open_log_file (void)
1807 old_setting = selector;
1812 pack_job_name(".log");
1814 while (!a_open_out(log_file))
1816 selector = term_only;
1817 prompt_file_name("transcript file name", ".log");
1820 texmf_log_name = a_make_name_string(log_file);
1821 selector = log_only;
1828 strcat(log_line, "\n");
1829 (void) fputs(log_line, log_file);
1830 stampcopy(log_line);
1831 strcat(log_line, "\n");
1832 (void) fputs(log_line, log_file);
1835 fprintf(log_file, "%s (%s %s)", tex_version, application, yandyversion);
1837 if (format_ident > 0)
1838 slow_print(format_ident);
1848 months = " JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
1850 for (k = 3 * month - 2; k <= 3 * month; k++)
1851 (void) putc(months[k], log_file);
1861 print_two(tex_time / 60);
1863 print_two(tex_time % 60);
1866 input_stack[input_ptr] = cur_input;
1868 l = input_stack[0].limit_field;
1870 if (buffer[l] == end_line_char)
1873 for (k = 1; k <= l; k++)
1880 if (format_file != NULL)
1882 fprintf(log_file, "(%s)\n", format_file);
1888 selector = old_setting + 2;
1891 // Attempt to deal with foo.bar.tex given as foo.bar on command line
1892 // Makes copy of job_name with extension
1894 void more_name_copy(ASCII_code c)
1896 #ifdef ALLOCATESTRING
1897 if (pool_ptr + 1 > current_pool_size)
1898 str_pool = realloc_str_pool (increment_pool_size);
1900 if (pool_ptr + 1 > current_pool_size)
1902 overflow("pool size", current_pool_size - init_pool_ptr);
1906 if (pool_ptr + 1 > pool_size)
1908 overflow("pool size", pool_size - init_pool_ptr);
1913 str_pool[pool_ptr] = c;
1917 int end_name_copy(void)
1919 #ifdef ALLOCATESTRING
1920 if (str_ptr + 1 > current_max_strings)
1921 str_start = realloc_str_start(increment_max_strings + 1);
1923 if (str_ptr + 1 > current_max_strings)
1925 overflow("number of strings", current_max_strings - init_str_ptr);
1929 if (str_ptr + 1 > max_strings)
1931 overflow("number of strings", max_strings - init_str_ptr);
1936 return make_string();
1939 void job_name_append (void)
1943 k = str_start[job_name];
1944 n = str_start[job_name + 1];
1947 more_name_copy(str_pool[k++]);
1949 k = str_start[cur_ext];
1950 n = str_start[cur_ext + 1];
1953 more_name_copy(str_pool[k++]);
1955 job_name = end_name_copy();
1959 void start_input(void)
1962 pack_file_name(cur_name, cur_area, cur_ext);
1966 begin_file_reading();
1968 if (a_open_in(cur_file, TEXINPUTPATH))
1972 prompt_file_name("input file name", ".tex");
1976 cur_input.name_field = a_make_name_string(cur_file);
1980 job_name = cur_name;
1984 if (term_offset + length(cur_input.name_field) > max_print_line - 2)
1986 else if ((term_offset > 0) || (file_offset > 0))
1992 if (open_parens > max_open_parens)
1993 max_open_parens = open_parens;
1995 slow_print(cur_input.name_field);
2006 if (input_ln(cur_file, false));
2010 if (end_line_char_inactive())
2013 buffer[limit] = end_line_char;
2020 internal_font_number read_font_info_(halfword u, str_number nom, str_number aire, scaled s)
2023 boolean file_opened;
2024 halfword lf, lh, nw, nh, nd, ni, nl, nk, ne, np;
2026 internal_font_number f;
2027 internal_font_number g;
2028 eight_bits a, b, c, d;
2038 file_opened = false;
2039 pack_file_name(nom, aire, 805); /* .tfm */
2041 if (!b_open_in(tfm_file))
2050 tfm_temp = getc(tfm_file);
2052 tfm_temp = getc(tfm_file);
2054 tfm_temp = getc(tfm_file);
2057 if ((bc > ec + 1) || (ec > 255))
2066 tfm_temp = getc(tfm_file);
2068 tfm_temp = getc(tfm_file);
2070 tfm_temp = getc(tfm_file);
2072 tfm_temp = getc(tfm_file);
2074 tfm_temp = getc(tfm_file);
2076 tfm_temp = getc(tfm_file);
2078 tfm_temp = getc(tfm_file);
2080 tfm_temp = getc(tfm_file);
2083 if (lf != 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np)
2086 if ((nw == 0) || (nh == 0) || (nd == 0) || (ni == 0))
2096 if ((fmem_ptr + lf > current_font_mem_size))
2097 font_info = realloc_font_info (increment_font_mem_size + lf);
2099 if ((font_ptr == font_max) || (fmem_ptr + lf > current_font_mem_size))
2101 if ((font_ptr == font_max) || (fmem_ptr + lf > font_mem_size))
2106 sprintf(log_line, "font_ptr %d font_max %d fmem_ptr %d lf %d font_mem_size %d\n",
2107 font_ptr, font_max, fmem_ptr, lf, font_mem_size);
2108 show_line(log_line, 0);
2114 print_file_name(nom, aire, 335); /* "" */
2118 print_string(" at ");
2122 else if (s != -1000)
2124 print_string(" scaled ");
2125 print_int(- (integer) s);
2128 print_string(" not loaded: Not enough room left");
2129 help4("I'm afraid I won't be able to make use of this font,",
2130 "because my memory for character-size data is too small.",
2131 "If you're really stuck, ask a wizard to enlarge me.",
2132 "Or maybe try `I\\font<same font id>=<name of loaded font>'.");
2138 char_base[f] = fmem_ptr - bc;
2139 width_base[f] = char_base[f] + ec + 1;
2140 height_base[f] = width_base[f] + nw;
2141 depth_base[f] = height_base[f] + nh;
2142 italic_base[f] = depth_base[f] + nd;
2143 lig_kern_base[f] = italic_base[f] + ni;
2144 kern_base[f] = lig_kern_base[f] + nl - 256 * (128);
2145 exten_base[f] = kern_base[f] + 256 * (128) + nk;
2146 param_base[f] = exten_base[f] + ne;
2152 store_four_quarters(font_check[f]);
2153 tfm_temp = getc(tfm_file);
2155 tfm_temp = getc(tfm_file);
2156 z = z * 256 + tfm_temp;
2157 tfm_temp = getc(tfm_file);
2158 z =(z * 16) + (tfm_temp / 16);
2165 tfm_temp = getc(tfm_file);
2166 tfm_temp = getc(tfm_file);
2167 tfm_temp = getc(tfm_file);
2168 tfm_temp = getc(tfm_file);
2178 z = xn_over_d(z, - (integer) s, 1000);
2183 for (k = fmem_ptr; k <= width_base[f] - 1; k++)
2185 store_four_quarters(font_info[k].qqqq);
2187 if ((a >= nw) || (b / 16 >= nh) || (b % 16 >= nd) || (c / 4 >= ni))
2205 if ((d < bc) || (d > ec))
2209 while (d < k + bc - fmem_ptr)
2211 qw = char_info(f, d);
2213 if (char_tag(qw) != list_tag)
2219 if (d == k + bc - fmem_ptr)
2234 while (z >= 8388608L) /* 2^23 */
2237 alpha = alpha + alpha;
2240 beta = (char) (256 / alpha);
2244 for (k = width_base[f]; k <= lig_kern_base[f] - 1; k++)
2246 tfm_temp = getc(tfm_file);
2248 tfm_temp = getc(tfm_file);
2250 tfm_temp = getc(tfm_file);
2252 tfm_temp = getc(tfm_file);
2254 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2257 font_info[k].cint = sw;
2259 font_info[k].cint = sw - alpha;
2264 if (font_info[width_base[f]].cint != 0)
2267 if (font_info[height_base[f]].cint != 0)
2270 if (font_info[depth_base[f]].cint != 0)
2273 if (font_info[italic_base[f]].cint != 0)
2277 bch_label = 32767; /* '77777 */
2282 for (k = lig_kern_base[f]; k <= kern_base[f] + 256 * (128) - 1; k++)
2284 store_four_quarters(font_info[k].qqqq);
2288 if (256 * c + d >= nl)
2289 goto lab11; /* error in TFM, abort */
2292 if (k == lig_kern_base[f])
2300 if ((b < bc) || (b > ec)) /* check-existence(b) */
2301 goto lab11; /* error in TFM, abort */
2304 qw = font_info[char_base[f] + b].qqqq;
2307 goto lab11; /* error in TFM, abort */
2313 if ((d < bc) || (d > ec)) /* check-existence(d) */
2314 goto lab11; /* error in TFM, abort */
2317 qw = font_info[char_base[f] + d].qqqq;
2320 goto lab11; /* error in TFM, abort */
2322 else if (256 * (c - 128) + d >= nk)
2323 goto lab11; /* error in TFM, abort */
2326 if (k - lig_kern_base[f] + a + 1 >= nl)
2327 goto lab11; /* error in TFM, abort */
2332 bch_label = 256 * c + d;
2335 for (k = kern_base[f] + 256 * (128); k <= exten_base[f] - 1; k++)
2337 tfm_temp = getc(tfm_file);
2339 tfm_temp = getc(tfm_file);
2341 tfm_temp = getc(tfm_file);
2343 tfm_temp = getc(tfm_file);
2345 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2348 font_info[k].cint = sw;
2350 font_info[k].cint = sw - alpha;
2354 /* read extensible character recipes */
2355 for (k = exten_base[f]; k <= param_base[f] - 1; k++)
2357 store_four_quarters(font_info[k].qqqq);
2362 if ((a < bc) || (a > ec))
2366 qw = font_info[char_base[f] + a].qqqq;
2375 if ((b < bc) || (b > ec))
2379 qw = font_info[char_base[f] + b].qqqq;
2388 if ((c < bc) || (c > ec))
2392 qw = font_info[char_base[f] + c].qqqq;
2400 if ((d < bc) || (d > ec))
2404 qw = font_info[char_base[f] + d].qqqq;
2412 for (k = 1; k <= np; k++)
2415 tfm_temp = getc(tfm_file);
2421 tfm_temp = getc(tfm_file);
2422 sw = sw * 256 + tfm_temp;
2423 tfm_temp = getc(tfm_file);
2424 sw = sw * 256 + tfm_temp;
2425 tfm_temp = getc(tfm_file);
2426 font_info[param_base[f]].cint = (sw * 16) + (tfm_temp / 16);
2430 tfm_temp = getc(tfm_file);
2432 tfm_temp = getc(tfm_file);
2434 tfm_temp = getc(tfm_file);
2436 tfm_temp = getc(tfm_file);
2438 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2441 font_info[param_base[f] + k - 1].cint = sw;
2443 font_info[param_base[f] + k - 1].cint = sw - alpha;
2450 for (k = np + 1; k <= 7; k++)
2451 font_info[param_base[f] + k - 1].cint = 0;
2455 font_params[f] = np;
2459 hyphen_char[f] = default_hyphen_char;
2460 skew_char[f] = default_skew_char;
2463 bchar_label[f] = bch_label + lig_kern_base[f];
2465 bchar_label[f] = non_address;
2467 font_bchar[f] = bchar;
2468 font_false_bchar[f] = bchar;
2473 qw = font_info[char_base[f] + bchar].qqqq;
2476 font_false_bchar[f] = 256;
2480 font_area[f] = aire;
2484 char_base[f] = char_base[f];
2485 width_base[f] = width_base[f];
2486 lig_kern_base[f] = lig_kern_base[f];
2487 kern_base[f] = kern_base[f];
2488 exten_base[f] = exten_base[f];
2489 decr(param_base[f]);
2490 fmem_ptr = fmem_ptr + lf;
2499 print_file_name(nom, aire, 335);
2503 print_string(" at ");
2507 else if (s != -1000)
2509 print_string("scaled");
2510 print_int(- (integer) s);
2514 print_string(" not loadable: Bad metric (TFM) file");
2516 print_string(" not loadable: Metric (TFM) file not found");
2518 help5("I wasn't able to read the size data for this font,",
2519 "so I will ignore the font specification.",
2520 "[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
2521 "You might try inserting a different font spec;",
2522 "e.g., type `I\\font<same font id>=<substitute font name>'.");