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.");
306 goto attach_fraction;
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"))
372 goto attach_fraction;
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.)");
382 goto attach_fraction;
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"))
400 goto attach_fraction;
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);
443 if (cur_val >= 16384) /* 2^14 */
446 cur_val = cur_val * unity + f;
452 if (cur_cmd != spacer)
457 if (arith_error || (abs(cur_val) >= 1073741824L)) /* 2^30 */
459 print_err("Dimension too large");
460 help2("I can't work with sizes bigger than about 19 feet.",
461 "Continue and I'll use the largest value I can.");
468 cur_val = - (integer) cur_val;
471 void scan_glue_(small_number level)
477 mu = (level == mu_val);
486 while (!(cur_cmd != spacer));
488 if (cur_tok == other_token + '-')
490 negative = !negative;
491 cur_tok = other_token + '+';
494 while (!(cur_tok != other_token + '+'));
496 if ((cur_cmd >= min_internal) && (cur_cmd <= max_internal))
498 scan_something_internal(level, negative);
500 if (cur_val_level >= glue_val)
502 if (cur_val_level != level)
509 if (cur_val_level == int_val)
511 scan_dimen(mu, false, true);
513 else if (level == mu_val)
521 scan_dimen(mu, false, false);
524 cur_val = - (integer) cur_val;
526 q = new_spec(zero_glue);
529 if (scan_keyword("plus"))
531 scan_dimen(mu, true, false);
532 stretch(q) = cur_val;
533 stretch_order(q) = cur_order;
536 if (scan_keyword("minus"))
538 scan_dimen(mu, true, false);
540 shrink_order(q) = cur_order;
546 halfword scan_rule_spec (void)
552 if (cur_cmd == vrule)
553 width(q) = default_rule;
556 height(q) = default_rule;
562 if (scan_keyword("width"))
564 scan_dimen(false, false, false);
569 if (scan_keyword("height"))
571 scan_dimen(false, false, false);
576 if (scan_keyword("depth"))
578 scan_dimen(false, false, false);
586 halfword str_toks_(pool_pointer b)
607 fast_store_new_token(t);
616 halfword the_toks (void)
618 register halfword Result;
624 scan_something_internal(tok_val, false);
626 if (cur_val_level >= ident_val)
631 if (cur_val_level == ident_val)
632 store_new_token(cs_token_flag + cur_val);
633 else if (cur_val != 0)
639 fast_store_new_token(info(r));
648 old_setting = selector;
649 selector = new_string;
652 switch (cur_val_level)
659 print_scaled(cur_val);
665 print_spec(cur_val, "pt");
666 delete_glue_ref(cur_val);
671 print_spec(cur_val, "mu");
672 delete_glue_ref(cur_val);
676 selector = old_setting;
677 Result = str_toks(b);
683 void ins_the_toks (void)
685 link(garbage) = the_toks();
686 begin_token_list(link(temp_head), 4);
689 void conv_toks (void)
693 small_number save_scanner_status;
701 case roman_numeral_code:
707 save_scanner_status = scanner_status;
710 scanner_status = save_scanner_status;
723 old_setting = selector;
724 selector = new_string;
733 case roman_numeral_code:
734 print_roman_int(cur_val);
749 print(font_name[cur_val]);
751 if (font_size[cur_val] != font_dsize[cur_val])
753 print_string(" at ");
754 print_scaled(font_size[cur_val]);
764 selector = old_setting;
765 link(garbage) = str_toks(b);
766 begin_token_list(link(temp_head), 4);
769 halfword scan_toks_(boolean macrodef, boolean xpand)
771 register halfword Result;
780 scanner_status = defining;
782 scanner_status = absorbing;
784 warning_index = cur_cs;
785 def_ref = get_avail();
786 token_ref_count(def_ref) = 0;
797 if (cur_tok < right_brace_limit)
800 if (cur_cmd == mac_param)
802 s = match_token + cur_chr;
805 if (cur_cmd == left_brace)
808 store_new_token(cur_tok);
809 store_new_token(end_match_token);
813 if (t == zero_token + 9)
815 print_err("You already have nine parameters");
816 help1("I'm going to ignore the # sign you just used.");
825 print_err("Parameters must be numbered consecutively");
826 help2("I've inserted the digit you should have used after the #.",
827 "Type `1' to delete what you did use.");
834 store_new_token(cur_tok);
838 store_new_token(end_match_token);
840 if (cur_cmd == right_brace)
842 print_err("Missing { inserted");
844 help2("Where was the left brace? You said something like `\\def\\a}',",
845 "which I'm going to interpret as `\\def\\a{}'.");
866 if (cur_cmd <= max_command)
877 if (link(temp_head) != 0)
879 link(p) = link(temp_head);
890 if (cur_tok < right_brace_limit)
891 if (cur_cmd < right_brace)
900 else if (cur_cmd == mac_param)
910 if (cur_cmd != mac_param)
911 if ((cur_tok <= zero_token) || (cur_tok > t))
913 print_err("Illegal parameter number in definition of ");
914 sprint_cs(warning_index);
915 help3("You meant to type ## instead of #, right?",
916 "Or maybe a } was forgotten somewhere earlier, and things",
917 "are all screwed up? I'm going to assume that you meant ##.");
922 cur_tok = out_param_token - '0' + cur_chr;
925 store_new_token(cur_tok);
931 store_new_token(hashbrace);
936 /* used only in ITEX.C */
938 void read_toks_(integer n, halfword r)
943 /* small_number m; */
944 int m; /* 95/Jan/7 */
946 scanner_status = defining;
948 def_ref = get_avail();
949 token_ref_count(def_ref) = 0;
951 store_new_token(end_match_token);
953 if ((n < 0) || (n > 15))
959 align_state = 1000000L;
963 begin_file_reading();
964 cur_input.name_field = m + 1;
966 if (read_open[m] == closed)
967 if (interaction > nonstop_mode)
979 fatal_error("*** (cannot \\read from terminal in nonstop modes)");
982 else if (read_open[m] == 1)
983 if (input_ln(read_file[m], false))
987 (void) a_close(read_file[m]);
992 if (!input_ln(read_file[m], true))
994 (void) a_close(read_file[m]);
997 if (align_state != 1000000L)
1000 print_err("File ended within ");
1002 help1("This \\read has unbalanced braces.");
1003 align_state = 1000000L;
1011 if (end_line_char_inactive())
1014 buffer[limit] = end_line_char;
1027 if (align_state < 1000000L)
1033 while (!(cur_tok == 0));
1035 align_state = 1000000L;
1039 store_new_token(cur_tok);
1044 while (!(align_state == 1000000L));
1047 scanner_status = normal;
1051 void pass_text (void)
1054 small_number save_scanner_status;
1056 save_scanner_status = scanner_status;
1057 scanner_status = skipping;
1065 if (cur_cmd == fi_or_else)
1073 else if (cur_cmd == if_test)
1077 scanner_status = save_scanner_status;
1080 void change_if_limit_(small_number l, halfword p)
1108 /* called from tex2.c */
1110 void conditional (void)
1116 small_number save_scanner_status;
1117 halfword savecondptr;
1118 small_number thisif;
1121 p = get_node(if_node_size);
1124 subtype(p) = cur_if;
1125 if_line_field(p) = if_line;
1132 savecondptr = cond_ptr;
1143 if (cur_cmd == relax)
1144 if (cur_chr == no_expand_flag)
1146 cur_cmd = active_char;
1147 cur_chr = cur_tok - cs_token_flag - active_base;
1151 if ((cur_cmd > active_char) || (cur_chr > 255))
1164 if (cur_cmd == relax)
1165 if (cur_chr == no_expand_flag)
1167 cur_cmd = active_char;
1168 cur_chr = cur_tok - cs_token_flag - active_base;
1172 if ((cur_cmd > active_char) || (cur_chr > 255))
1178 if (thisif == if_char_code)
1188 if (thisif == if_int_code)
1191 scan_dimen(false, false, false);
1199 while (!(cur_cmd != spacer));
1201 if ((cur_tok >= other_token + '<') && (cur_tok <= other_token + '>'))
1202 r = cur_tok - other_token;
1205 print_err("Missing = inserted for ");
1206 print_cmd_chr(if_test, thisif);
1207 help1("I was expecting to see `<', `=', or `>'. Didn't.");
1212 if (thisif == if_int_code)
1215 scan_dimen(false, false, false);
1240 b = (abs(mode) == 1);
1244 b = (abs(mode) == 102);
1248 b = (abs(mode) == 203);
1259 scan_eight_bit_int();
1262 if (thisif == if_void_code)
1266 else if (thisif == if_hbox_code)
1267 b = (type(p) == hlist_node);
1269 b = (type(p) == vlist_node);
1275 save_scanner_status = scanner_status;
1285 else if (cur_cmd < call)
1296 while ((p != 0) && (q != 0))
1297 if (info(p) != info(q))
1305 b = ((p == 0) && (q == 0));
1309 scanner_status = save_scanner_status;
1315 scan_four_bit_int();
1316 b = (read_open[cur_val] == closed);
1333 if (tracing_commands > 1)
1336 print_string("{case ");
1339 end_diagnostic(false);
1346 if (cond_ptr == savecondptr)
1347 if (cur_chr == or_code)
1351 else if (cur_chr == fi_code)
1354 if_line = if_line_field(p);
1355 cur_if = subtype(p);
1358 free_node(p, if_node_size);
1362 change_if_limit(or_code, savecondptr);
1368 if (tracing_commands > 1)
1373 print_string("{true}");
1375 print_string("{false}");
1377 end_diagnostic(false);
1380 if (b) /* b may be used without ... */
1382 change_if_limit(else_code, savecondptr);
1390 if (cond_ptr == savecondptr)
1392 if (cur_chr != or_code)
1395 print_err("Extra ");
1397 help1("I'm ignoring this; it doesn't match any \\if.");
1400 else if (cur_chr == fi_code)
1403 if_line = if_line_field(p);
1404 cur_if = subtype(p);
1407 free_node(p, if_node_size);
1412 if (cur_chr == fi_code)
1415 if_line = if_line_field(p);
1416 cur_if = subtype(p);
1419 free_node(p, if_node_size);
1425 void begin_name (void)
1430 /* This gathers up a file name and makes a string of it */
1431 /* Also tries to break it into `file area' `file name' and `file extension' */
1432 /* Used by scan_file_name and prompt_file_name */
1433 /* We assume tilde has been converted to pseudo_tilde and space to pseudo_space */
1434 /* returns false if it is given a space character - end of file name */
1436 boolean more_name_(ASCII_code c)
1438 if (quoted_file_name == 0 && c == ' ')
1440 else if (quoted_file_name != 0 && c == '"')
1442 quoted_file_name = 0; /* catch next space character */
1443 return true; /* accept ending quote, but throw away */
1450 if ((c == '/' || c == '\\' || c == ':'))
1452 area_delimiter = cur_length;
1456 ext_delimiter = cur_length;
1463 void end_name (void)
1465 #ifdef ALLOCATESTRING
1466 if (str_ptr + 3 > current_max_strings)
1467 str_start = realloc_str_start(increment_max_strings + 3);
1469 if (str_ptr + 3 > current_max_strings)
1471 overflow("number of strings", current_max_strings - init_str_ptr);
1475 if (str_ptr + 3 > max_strings)
1477 overflow("number of strings", max_strings - init_str_ptr);
1482 if (area_delimiter == 0) // no area delimiter ':' '/' or '\' found
1483 cur_area = 335; // "" default area
1487 str_start[str_ptr + 1] = str_start[str_ptr] + area_delimiter;
1491 if (ext_delimiter == 0) // no extension delimiter '.' found
1493 cur_ext = 335; // "" default extension
1494 cur_name = make_string();
1496 else // did find an extension
1499 str_start[str_ptr + 1] = str_start[str_ptr]+ ext_delimiter - area_delimiter - 1;
1501 cur_ext = make_string();
1505 /* n current name, a current area, e current extension */
1506 /* result in name_of_file[] */
1508 void pack_file_name_(str_number n, str_number a, str_number e)
1516 for (j = str_start[a]; j <= str_start[a + 1] - 1; j++)
1521 if (k <= file_name_size)
1522 name_of_file[k] = xchr[c];
1525 for (j = str_start[n]; j <= str_start[n + 1] - 1; j++)
1530 if (k <= file_name_size)
1531 name_of_file[k] = xchr[c];
1534 for (j = str_start[e]; j <= str_start[e + 1] - 1; j++)
1539 if (k <= file_name_size)
1540 name_of_file[k] = xchr[c];
1543 if (k < file_name_size)
1546 name_length = file_name_size - 1;
1548 /* pad it out with spaces ... what for ? in case we modify and forget ? */
1549 for (k = name_length + 1; k <= file_name_size; k++)
1550 name_of_file[k] = ' ';
1552 name_of_file[file_name_size] = '\0'; /* paranoia 94/Mar/24 */
1555 name_of_file [name_length+1] = '\0';
1559 sprintf(log_line, " pack_file_name `%s' (%d) ", name_of_file + 1, name_length); /* debugging */
1560 show_line(log_line, 0);
1563 name_of_file [name_length + 1] = ' ';
1566 /* Called only from two places tex9.c for format name - specified and default */
1567 /* for specified format name args are 0, a, b name in buffer[a] --- buffer[b] */
1568 /* for default args are format_default_length-4, 1, 0 */
1570 void pack_buffered_name_(small_number n, integer a, integer b)
1576 if (n + b - a + 5 > file_name_size)
1577 b = a + file_name_size - n - 5;
1581 /* This loop kicks in when we want the default format name */
1582 for (j = 1; j <= n; j++)
1584 c = xord[TEX_format_default[j]];
1587 if (k <= file_name_size)
1588 name_of_file[k] = xchr[c];
1590 /* This loop kicks in when we want a specififed format name */
1591 for (j = a; j <= b; j++)
1596 if (k <= file_name_size)
1597 name_of_file[k] = xchr[c];
1600 /* This adds the extension from the default format name */
1601 for (j = format_default_length - 3; j <= format_default_length; j++)
1603 c = xord[TEX_format_default[j]];
1606 if (k <= file_name_size)
1607 name_of_file[k] = xchr[c];
1610 if (k < file_name_size)
1613 name_length = file_name_size - 1;
1615 /* pad it out with spaces ... what for ? */
1616 for (k = name_length + 1; k <= file_name_size; k++)
1617 name_of_file[k]= ' ';
1619 name_of_file[file_name_size] = '\0'; /* paranoia 94/Mar/24 */
1622 str_number make_name_string (void)
1626 #ifdef ALLOCATESTRING
1627 if (pool_ptr + name_length > current_pool_size)
1628 str_pool = realloc_str_pool(increment_pool_size + name_length);
1630 if (str_ptr == current_max_strings)
1631 str_start = realloc_str_start(increment_max_strings);
1633 if ((pool_ptr + name_length > current_pool_size) || (str_ptr == current_max_strings) || (cur_length > 0))
1635 if ((pool_ptr + name_length > pool_size) || (str_ptr == max_strings) || (cur_length > 0))
1642 for (k = 1; k <= name_length; k++)
1643 append_char(xord[name_of_file[k]]);
1645 return make_string();
1649 //str_number a_make_name_string_(alpha_file * f)
1650 str_number a_make_name_string_(void)
1652 return make_name_string();
1655 //str_number b_make_name_string_(byte_file * f)
1656 str_number b_make_name_string_(void)
1658 return make_name_string();
1661 //str_number w_make_name_string_(word_file * f)
1662 str_number w_make_name_string_(void)
1664 return make_name_string();
1667 /* Used by start_input to scan file name on command line */
1668 /* Also in tex8.c new_font_, open_or_close_in, and do_extension */
1670 void scan_file_name (void)
1672 name_in_progress = true;
1679 while (!(cur_cmd != spacer));
1681 quoted_file_name = false;
1683 if (allow_quoted_names)
1687 quoted_file_name = 1;
1694 if ((cur_cmd > other_char) || (cur_chr > 255))
1700 if (!more_name(cur_chr)) /* up to next white space */
1708 name_in_progress = false;
1710 /* argument is string .fmt, .log, or .dvi */
1712 void pack_job_name_(str_number s)
1714 cur_area = 335; /* "" */
1716 cur_name = job_name;
1717 pack_file_name(cur_name, cur_area, cur_ext);
1720 /**********************************************************************/
1722 /* s - what can't be found, e - default */
1723 void prompt_file_name_(char * s, str_number e)
1727 if (interaction == scroll_mode);
1729 if (!strcmp("input file name", s))
1730 print_err("I can't find file `");
1732 print_err("I can't write on file `");
1734 print_file_name(cur_name, cur_area, cur_ext);
1737 if (e == 785) /* .tex */
1740 print_nl("Please type another ");
1743 if (interaction < 2)
1745 fatal_error("*** (job aborted, file error in nonstop mode)");
1751 show_line(" (or ^z to exit)", 0);
1753 show_line(" (or Ctrl-Z to exit)", 0);
1757 /* should we deal with tilde and space in file name here ??? */
1762 while ((buffer[k] == ' ') && (k < last))
1764 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1765 quoted_file_name = 0; /* 98/March/15 */
1767 if (allow_quoted_names && k < last) /* check whether quoted name */
1769 if (buffer[k]== '"')
1771 quoted_file_name = 1;
1780 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1781 /* convert tilde '~' to pseudo tilde */
1782 if (pseudo_tilde != 0 && buffer[k]== '~')
1783 buffer[k] = pseudo_tilde;
1784 /* convert space ' ' to pseudo space */
1785 if (pseudo_space != 0 && buffer[k]== ' ')
1786 buffer[k] = pseudo_space;
1787 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
1788 if (!more_name(buffer[k]))
1797 if (cur_ext == 335) /* "" */
1798 cur_ext = e; /* use default extension */
1800 pack_file_name(cur_name, cur_area, cur_ext);
1803 void open_log_file (void)
1810 old_setting = selector;
1815 pack_job_name(".log");
1817 while (!a_open_out(log_file))
1819 selector = term_only;
1820 prompt_file_name("transcript file name", ".log");
1823 texmf_log_name = a_make_name_string(log_file);
1824 selector = log_only;
1831 strcat(log_line, "\n");
1832 (void) fputs(log_line, log_file);
1833 stampcopy(log_line);
1834 strcat(log_line, "\n");
1835 (void) fputs(log_line, log_file);
1838 fprintf(log_file, "%s (%s %s)", tex_version, application, yandyversion);
1840 if (format_ident > 0)
1841 slow_print(format_ident);
1851 months = " JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
1853 for (k = 3 * month - 2; k <= 3 * month; k++)
1854 (void) putc(months[k], log_file);
1864 print_two(tex_time / 60);
1866 print_two(tex_time % 60);
1869 input_stack[input_ptr] = cur_input;
1871 l = input_stack[0].limit_field;
1873 if (buffer[l] == end_line_char)
1876 for (k = 1; k <= l; k++)
1883 if (format_file != NULL)
1885 fprintf(log_file, "(%s)\n", format_file);
1891 selector = old_setting + 2;
1894 // Attempt to deal with foo.bar.tex given as foo.bar on command line
1895 // Makes copy of job_name with extension
1897 void more_name_copy(ASCII_code c)
1899 #ifdef ALLOCATESTRING
1900 if (pool_ptr + 1 > current_pool_size)
1901 str_pool = realloc_str_pool (increment_pool_size);
1903 if (pool_ptr + 1 > current_pool_size)
1905 overflow("pool size", current_pool_size - init_pool_ptr);
1909 if (pool_ptr + 1 > pool_size)
1911 overflow("pool size", pool_size - init_pool_ptr);
1916 str_pool[pool_ptr] = c;
1920 int end_name_copy(void)
1922 #ifdef ALLOCATESTRING
1923 if (str_ptr + 1 > current_max_strings)
1924 str_start = realloc_str_start(increment_max_strings + 1);
1926 if (str_ptr + 1 > current_max_strings)
1928 overflow("number of strings", current_max_strings - init_str_ptr);
1932 if (str_ptr + 1 > max_strings)
1934 overflow("number of strings", max_strings - init_str_ptr);
1939 return make_string();
1942 void job_name_append (void)
1946 k = str_start[job_name];
1947 n = str_start[job_name + 1];
1950 more_name_copy(str_pool[k++]);
1952 k = str_start[cur_ext];
1953 n = str_start[cur_ext + 1];
1956 more_name_copy(str_pool[k++]);
1958 job_name = end_name_copy();
1962 void start_input(void)
1965 pack_file_name(cur_name, cur_area, cur_ext);
1969 begin_file_reading();
1971 if (a_open_in(cur_file, TEXINPUTPATH))
1975 prompt_file_name("input file name", ".tex");
1979 cur_input.name_field = a_make_name_string(cur_file);
1983 job_name = cur_name;
1987 if (term_offset + length(cur_input.name_field) > max_print_line - 2)
1989 else if ((term_offset > 0) || (file_offset > 0))
1995 if (open_parens > max_open_parens)
1996 max_open_parens = open_parens;
1998 slow_print(cur_input.name_field);
2005 if (input_ln(cur_file, false));
2009 if (end_line_char_inactive())
2012 buffer[limit] = end_line_char;
2019 internal_font_number read_font_info_(halfword u, str_number nom, str_number aire, scaled s)
2022 boolean file_opened;
2023 halfword lf, lh, nw, nh, nd, ni, nl, nk, ne, np;
2025 internal_font_number f;
2026 internal_font_number g;
2027 eight_bits a, b, c, d;
2037 file_opened = false;
2038 pack_file_name(nom, aire, 805); /* .tfm */
2040 if (!b_open_in(tfm_file))
2049 tfm_temp = getc(tfm_file);
2051 tfm_temp = getc(tfm_file);
2053 tfm_temp = getc(tfm_file);
2056 if ((bc > ec + 1) || (ec > 255))
2065 tfm_temp = getc(tfm_file);
2067 tfm_temp = getc(tfm_file);
2069 tfm_temp = getc(tfm_file);
2071 tfm_temp = getc(tfm_file);
2073 tfm_temp = getc(tfm_file);
2075 tfm_temp = getc(tfm_file);
2077 tfm_temp = getc(tfm_file);
2079 tfm_temp = getc(tfm_file);
2082 if (lf != 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np)
2085 if ((nw == 0) || (nh == 0) || (nd == 0) || (ni == 0))
2095 if ((fmem_ptr + lf > current_font_mem_size))
2096 font_info = realloc_font_info (increment_font_mem_size + lf);
2098 if ((font_ptr == font_max) || (fmem_ptr + lf > current_font_mem_size))
2100 if ((font_ptr == font_max) || (fmem_ptr + lf > font_mem_size))
2105 sprintf(log_line, "font_ptr %d font_max %d fmem_ptr %d lf %d font_mem_size %d\n",
2106 font_ptr, font_max, fmem_ptr, lf, font_mem_size);
2107 show_line(log_line, 0);
2113 print_file_name(nom, aire, 335); /* "" */
2117 print_string(" at ");
2121 else if (s != -1000)
2123 print_string(" scaled ");
2124 print_int(- (integer) s);
2127 print_string(" not loaded: Not enough room left");
2128 help4("I'm afraid I won't be able to make use of this font,",
2129 "because my memory for character-size data is too small.",
2130 "If you're really stuck, ask a wizard to enlarge me.",
2131 "Or maybe try `I\\font<same font id>=<name of loaded font>'.");
2137 char_base[f] = fmem_ptr - bc;
2138 width_base[f] = char_base[f] + ec + 1;
2139 height_base[f] = width_base[f] + nw;
2140 depth_base[f] = height_base[f] + nh;
2141 italic_base[f] = depth_base[f] + nd;
2142 lig_kern_base[f] = italic_base[f] + ni;
2143 kern_base[f] = lig_kern_base[f] + nl - 256 * (128);
2144 exten_base[f] = kern_base[f] + 256 * (128) + nk;
2145 param_base[f] = exten_base[f] + ne;
2151 store_four_quarters(font_check[f]);
2152 tfm_temp = getc(tfm_file);
2154 tfm_temp = getc(tfm_file);
2155 z = z * 256 + tfm_temp;
2156 tfm_temp = getc(tfm_file);
2157 z =(z * 16) + (tfm_temp / 16);
2164 tfm_temp = getc(tfm_file);
2165 tfm_temp = getc(tfm_file);
2166 tfm_temp = getc(tfm_file);
2167 tfm_temp = getc(tfm_file);
2177 z = xn_over_d(z, - (integer) s, 1000);
2182 for (k = fmem_ptr; k <= width_base[f] - 1; k++)
2184 store_four_quarters(font_info[k].qqqq);
2186 if ((a >= nw) || (b / 16 >= nh) || (b % 16 >= nd) || (c / 4 >= ni))
2204 if ((d < bc) || (d > ec))
2208 while (d < k + bc - fmem_ptr)
2210 qw = char_info(f, d);
2212 if (char_tag(qw) != list_tag)
2218 if (d == k + bc - fmem_ptr)
2233 while (z >= 8388608L) /* 2^23 */
2236 alpha = alpha + alpha;
2239 beta = (char) (256 / alpha);
2243 for (k = width_base[f]; k <= lig_kern_base[f] - 1; k++)
2245 tfm_temp = getc(tfm_file);
2247 tfm_temp = getc(tfm_file);
2249 tfm_temp = getc(tfm_file);
2251 tfm_temp = getc(tfm_file);
2253 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2256 font_info[k].cint = sw;
2258 font_info[k].cint = sw - alpha;
2263 if (font_info[width_base[f]].cint != 0)
2266 if (font_info[height_base[f]].cint != 0)
2269 if (font_info[depth_base[f]].cint != 0)
2272 if (font_info[italic_base[f]].cint != 0)
2276 bch_label = 32767; /* '77777 */
2281 for (k = lig_kern_base[f]; k <= kern_base[f] + 256 * (128) - 1; k++)
2283 store_four_quarters(font_info[k].qqqq);
2287 if (256 * c + d >= nl)
2291 if (k == lig_kern_base[f])
2299 if ((b < bc) || (b > ec)) /* check-existence(b) */
2303 qw = font_info[char_base[f] + b].qqqq;
2312 if ((d < bc) || (d > ec)) /* check-existence(d) */
2316 qw = font_info[char_base[f] + d].qqqq;
2321 else if (256 * (c - 128) + d >= nk)
2325 if (k - lig_kern_base[f] + a + 1 >= nl)
2331 bch_label = 256 * c + d;
2334 for (k = kern_base[f] + 256 * (128); k <= exten_base[f] - 1; k++)
2336 tfm_temp = getc(tfm_file);
2338 tfm_temp = getc(tfm_file);
2340 tfm_temp = getc(tfm_file);
2342 tfm_temp = getc(tfm_file);
2344 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2347 font_info[k].cint = sw;
2349 font_info[k].cint = sw - alpha;
2354 for (k = exten_base[f]; k <= param_base[f] - 1; k++)
2356 store_four_quarters(font_info[k].qqqq);
2361 if ((a < bc) || (a > ec))
2365 qw = font_info[char_base[f] + a].qqqq;
2374 if ((b < bc) || (b > ec))
2378 qw = font_info[char_base[f] + b].qqqq;
2387 if ((c < bc) || (c > ec))
2391 qw = font_info[char_base[f] + c].qqqq;
2399 if ((d < bc) || (d > ec))
2403 qw = font_info[char_base[f] + d].qqqq;
2411 for (k = 1; k <= np; k++)
2414 tfm_temp = getc(tfm_file);
2420 tfm_temp = getc(tfm_file);
2421 sw = sw * 256 + tfm_temp;
2422 tfm_temp = getc(tfm_file);
2423 sw = sw * 256 + tfm_temp;
2424 tfm_temp = getc(tfm_file);
2425 font_info[param_base[f]].cint = (sw * 16) + (tfm_temp / 16);
2429 tfm_temp = getc(tfm_file);
2431 tfm_temp = getc(tfm_file);
2433 tfm_temp = getc(tfm_file);
2435 tfm_temp = getc(tfm_file);
2437 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2440 font_info[param_base[f] + k - 1].cint = sw;
2442 font_info[param_base[f] + k - 1].cint = sw - alpha;
2449 for (k = np + 1; k <= 7; k++)
2450 font_info[param_base[f] + k - 1].cint = 0;
2454 font_params[f] = np;
2458 hyphen_char[f] = default_hyphen_char;
2459 skew_char[f] = default_skew_char;
2462 bchar_label[f] = bch_label + lig_kern_base[f];
2464 bchar_label[f] = non_address;
2466 font_bchar[f] = bchar;
2467 font_false_bchar[f] = bchar;
2472 qw = font_info[char_base[f] + bchar].qqqq;
2475 font_false_bchar[f] = 256;
2479 font_area[f] = aire;
2483 char_base[f] = char_base[f];
2484 width_base[f] = width_base[f];
2485 lig_kern_base[f] = lig_kern_base[f];
2486 kern_base[f] = kern_base[f];
2487 exten_base[f] = exten_base[f];
2488 decr(param_base[f]);
2489 fmem_ptr = fmem_ptr + lf;
2498 print_file_name(nom, aire, 335);
2502 print_string(" at ");
2506 else if (s != -1000)
2508 print_string("scaled");
2509 print_int(- (integer) s);
2513 print_string(" not loadable: Bad metric (TFM) file");
2515 print_string(" not loadable: Metric (TFM) file not found");
2517 help5("I wasn't able to read the size data for this font,",
2518 "so I will ignore the font specification.",
2519 "[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
2520 "You might try inserting a different font spec;",
2521 "e.g., type `I\\font<same font id>=<substitute font name>'.");