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_(bool mu, bool inf, bool 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)
364 cur_val = mult_and_add(savecurval, v, xn_over_d(v, f, 65536L), 1073741823L); /* 2^30 - 1 */
369 if (scan_keyword("mu"))
373 print_err("Illegal unit of measure (");
374 print_string("mu inserted)");
375 help4("The unit of measurement in math glue must be mu.",
376 "To recover gracefully from this error, it's best to",
377 "delete the erroneous units; e.g., type `2' to delete",
378 "two letters. (See Chapter 27 of The TeXbook.)");
384 if (scan_keyword("true"))
390 cur_val = xn_over_d(cur_val, 1000, mag);
391 f = (1000 * f + 65536L * tex_remainder) / mag;
392 cur_val = cur_val + (f / 65536L);
397 if (scan_keyword("pt"))
400 if (scan_keyword("in"))
405 else if (scan_keyword("pc"))
410 else if (scan_keyword("cm"))
415 else if (scan_keyword("mm"))
420 else if (scan_keyword("bp"))
425 else if (scan_keyword("dd"))
430 else if (scan_keyword("cc"))
435 else if (scan_keyword("Q"))
440 else if (scan_keyword("H"))
445 else if (scan_keyword("sp"))
449 print_err("Illegal unit of measure (");
450 print_string("pt inserted)");
451 help6("Dimensions can be in units of em, ex, in, pt, pc,",
452 "cm, mm, dd, cc, bp, or sp; but yours is a new one!",
453 "I'll assume that you meant to say pt, for printer's points.",
454 "To recover gracefully from this error, it's best to",
455 "delete the erroneous units; e.g., type `2' to delete",
456 "two letters. (See Chapter 27 of The TeXbook.)");
461 cur_val = xn_over_d(cur_val, num, denom);
462 f = (num * f + 65536L * tex_remainder) / denom;
463 cur_val = cur_val +(f / 65536L);
467 if (cur_val >= 16384) /* 2^14 */
470 cur_val = cur_val * 65536L + f;
475 if (cur_cmd != spacer)
479 if (arith_error || (abs(cur_val) >= 1073741824L)) /* 2^30 */
481 print_err("Dimension too large");
482 help2("I can't work with sizes bigger than about 19 feet.",
483 "Continue and I'll use the largest value I can.");
485 cur_val = 1073741823L; /* 2^30 - 1 */
490 cur_val = - (integer) cur_val;
493 void scan_glue_(small_number level)
499 mu = (level == mu_val);
508 while (!(cur_cmd != spacer));
510 if (cur_tok == other_token + '-')
512 negative = !negative;
513 cur_tok = other_token + '+';
516 while (!(cur_tok != other_token + '+'));
518 if ((cur_cmd >= min_internal) && (cur_cmd <= max_internal))
520 scan_something_internal(level, negative);
522 if (cur_val_level >= glue_val)
524 if (cur_val_level != level)
531 if (cur_val_level == int_val)
533 scan_dimen(mu, false, true);
535 else if (level == mu_val)
543 scan_dimen(mu, false, false);
546 cur_val = - (integer) cur_val;
548 q = new_spec(zero_glue);
551 if (scan_keyword("plus"))
553 scan_dimen(mu, true, false);
554 stretch(q) = cur_val;
555 stretch_order(q) = cur_order;
558 if (scan_keyword("minus"))
560 scan_dimen(mu, true, false);
562 shrink_order(q) = cur_order;
568 halfword scan_rule_spec (void)
574 if (cur_cmd == vrule)
575 width(q) = default_rule;
578 height(q) = default_rule;
584 if (scan_keyword("width"))
586 scan_dimen(false, false, false);
591 if (scan_keyword("height"))
593 scan_dimen(false, false, false);
598 if (scan_keyword("depth"))
600 scan_dimen(false, false, false);
608 halfword str_toks_(pool_pointer b)
636 avail = mem[q].hh.rh;
654 halfword the_toks (void)
656 register halfword Result;
662 scan_something_internal(tok_val, false);
664 if (cur_val_level >= ident_val)
669 if (cur_val_level == ident_val)
673 mem[q].hh.lh = cs_token_flag + cur_val;
676 else if (cur_val != 0)
680 while (r != 0) { /* while r<>null do l.9178 */
688 avail = mem[q].hh.rh;
696 mem[q].hh.lh = mem[r].hh.lh;
706 old_setting = selector;
707 selector = new_string;
710 switch (cur_val_level)
717 print_scaled(cur_val);
723 print_spec(cur_val, "pt");
724 delete_glue_ref(cur_val);
729 print_spec(cur_val, "mu");
730 delete_glue_ref(cur_val);
734 selector = old_setting;
735 Result = str_toks(b);
741 void ins_the_toks (void)
743 link(garbage) = the_toks();
744 begin_token_list(link(temp_head), 4);
747 void conv_toks (void)
751 small_number savescannerstatus;
759 case roman_numeral_code:
765 savescannerstatus = scanner_status;
768 scanner_status = savescannerstatus;
781 old_setting = selector;
782 selector = new_string;
791 case roman_numeral_code:
792 print_roman_int(cur_val);
807 print(font_name[cur_val]);
809 if (font_size[cur_val] != font_dsize[cur_val])
811 print_string(" at ");
812 print_scaled(font_size[cur_val]);
822 selector = old_setting;
823 link(garbage) = str_toks(b);
824 begin_token_list(link(temp_head), 4);
827 halfword scan_toks_(bool macrodef, bool xpand)
829 register halfword Result;
838 scanner_status = defining;
840 scanner_status = absorbing;
842 warning_index = cur_cs;
843 def_ref = get_avail();
844 token_ref_count(def_ref) = 0;
855 if (cur_tok < right_brace_limit)
858 if (cur_cmd == mac_param)
860 s = match_token + cur_chr;
863 if (cur_cmd == left_brace)
869 mem[q].hh.lh = cur_tok;
875 mem[q].hh.lh = end_match_token;
881 if (t == zero_token + 9)
883 print_err("You already have nine parameters");
884 help1("I'm going to ignore the # sign you just used.");
893 print_err("Parameters must be numbered consecutively");
894 help2("I've inserted the digit you should have used after the #.",
895 "Type `1' to delete what you did use.");
904 mem[q].hh.lh = cur_tok;
912 mem[q].hh.lh = end_match_token;
916 if (cur_cmd == right_brace)
918 print_err("Missing { inserted");
920 help2("Where was the left brace? You said something like `\\def\\a}',",
921 "which I'm going to interpret as `\\def\\a{}'.");
942 if (cur_cmd <= max_command)
953 if (link(temp_head) != 0)
955 link(p) = link(temp_head);
966 if (cur_tok < right_brace_limit)
967 if (cur_cmd < right_brace)
976 else if (cur_cmd == mac_param)
986 if (cur_cmd != mac_param)
987 if ((cur_tok <= zero_token) || (cur_tok > t))
989 print_err("Illegal parameter number in definition of ");
990 sprint_cs(warning_index);
991 help3("You meant to type ## instead of #, right?",
992 "Or maybe a } was forgotten somewhere earlier, and things",
993 "are all screwed up? I'm going to assume that you meant ##.");
998 cur_tok = out_param_token - '0' + cur_chr;
1003 mem[q].hh.lh = cur_tok;
1014 mem[q].hh.lh = hashbrace;
1020 /* used only in ITEX.C */
1022 void read_toks_(integer n, halfword r)
1027 /* small_number m; */
1028 int m; /* 95/Jan/7 */
1030 scanner_status = defining;
1032 def_ref = get_avail();
1033 token_ref_count(def_ref) = 0;
1039 mem[q].hh.lh = end_match_token;
1043 if ((n < 0) || (n > 15))
1049 align_state = 1000000L;
1053 begin_file_reading();
1054 cur_input.name_field = m + 1;
1056 if (read_open[m] == closed)
1057 if (interaction > nonstop_mode)
1075 fatal_error("*** (cannot \\read from terminal in nonstop modes)");
1076 return; // abort_flag set
1078 else if (read_open[m] == 1)
1079 if (input_ln(read_file[m], false))
1083 (void) a_close(read_file[m]);
1088 if (!input_ln(read_file[m], true))
1090 (void) a_close(read_file[m]);
1093 if (align_state != 1000000L)
1096 print_err("File ended within ");
1098 help1("This \\read has unbalanced braces.");
1099 align_state = 1000000L;
1105 cur_input.limit_field = last;
1107 if ((end_line_char < 0) || (end_line_char > 255))
1108 decr(cur_input.limit_field);
1110 buffer[cur_input.limit_field] = end_line_char;
1112 first = cur_input.limit_field + 1;
1113 cur_input.loc_field = cur_input.start_field;
1114 cur_input.state_field = new_line;
1123 if (align_state < 1000000L)
1129 while(!(cur_tok == 0));
1131 align_state = 1000000L;
1138 mem[q].hh.lh = cur_tok;
1145 while(!(align_state == 1000000L));
1148 scanner_status = normal;
1152 void pass_text (void)
1155 small_number savescannerstatus;
1157 savescannerstatus = scanner_status;
1158 scanner_status = skipping;
1166 if (cur_cmd == fi_or_else)
1174 else if (cur_cmd == if_test)
1178 scanner_status = savescannerstatus;
1181 void change_if_limit_(small_number l, halfword p)
1196 return; // abort_flag set
1209 /* called from tex2.c */
1211 void conditional (void)
1217 small_number savescannerstatus;
1218 halfword savecondptr;
1219 small_number thisif;
1222 p = get_node(if_node_size);
1225 subtype(p) = cur_if;
1226 if_line_field(p) = if_line;
1233 savecondptr = cond_ptr;
1244 if (cur_cmd == relax)
1245 if (cur_chr == no_expand_flag)
1247 cur_cmd = active_char;
1248 cur_chr = cur_tok - cs_token_flag - active_base;
1252 if ((cur_cmd > active_char) || (cur_chr > 255))
1265 if (cur_cmd == relax)
1266 if (cur_chr == no_expand_flag)
1268 cur_cmd = active_char;
1269 cur_chr = cur_tok - cs_token_flag - active_base;
1273 if ((cur_cmd > active_char) || (cur_chr > 255))
1279 if (thisif == if_char_code)
1289 if (thisif == if_int_code)
1292 scan_dimen(false, false, false);
1300 while(!(cur_cmd != spacer));
1302 if ((cur_tok >= other_token + '<') && (cur_tok <= other_token + '>'))
1303 r = cur_tok - other_token;
1306 print_err("Missing = inserted for ");
1307 print_cmd_chr(if_test, thisif);
1308 help1("I was expecting to see `<', `=', or `>'. Didn't.");
1313 if (thisif == if_int_code)
1316 scan_dimen(false, false, false);
1341 b = (abs(mode) == 1);
1345 b = (abs(mode) == 102);
1349 b = (abs(mode) == 203);
1360 scan_eight_bit_int();
1363 if (thisif == if_void_code)
1367 else if (thisif == if_hbox_code)
1368 b = (type(p) == hlist_node);
1370 b = (type(p) == vlist_node);
1376 savescannerstatus = scanner_status;
1386 else if (cur_cmd < call)
1397 while ((p != 0) && (q != 0))
1398 if (info(p) != info(q))
1406 b = ((p == 0) && (q == 0));
1410 scanner_status = savescannerstatus;
1416 scan_four_bit_int();
1417 b = (read_open[cur_val] == closed);
1434 if (tracing_commands > 1)
1437 print_string("{case ");
1440 end_diagnostic(false);
1447 if (cond_ptr == savecondptr)
1448 if (cur_chr == or_code)
1452 else if (cur_chr == fi_code)
1455 if_line = if_line_field(p);
1456 cur_if = subtype(p);
1459 free_node(p, if_node_size);
1463 change_if_limit(or_code, savecondptr);
1469 if (tracing_commands > 1)
1474 print_string("{true}");
1476 print_string("{false}");
1478 end_diagnostic(false);
1481 if (b) /* b may be used without ... */
1483 change_if_limit(else_code, savecondptr);
1491 if (cond_ptr == savecondptr)
1493 if (cur_chr != or_code)
1496 print_err("Extra ");
1498 help1("I'm ignoring this; it doesn't match any \\if.");
1501 else if (cur_chr == fi_code)
1504 if_line = if_line_field(p);
1505 cur_if = subtype(p);
1508 free_node(p, if_node_size);
1513 if (cur_chr == fi_code)
1516 if_line = if_line_field(p);
1517 cur_if = subtype(p);
1520 free_node(p, if_node_size);
1526 void begin_name (void)
1531 /* This gathers up a file name and makes a string of it */
1532 /* Also tries to break it into `file area' `file name' and `file extension' */
1533 /* Used by scan_file_name and prompt_file_name */
1534 /* We assume tilde has been converted to pseudo_tilde and space to pseudo_space */
1535 /* returns false if it is given a space character - end of file name */
1537 bool more_name_(ASCII_code c)
1539 if (quoted_file_name == 0 && c == ' ')
1541 else if (quoted_file_name != 0 && c == '"')
1543 quoted_file_name = 0; /* catch next space character */
1544 return true; /* accept ending quote, but throw away */
1551 if ((c == '/' || c == '\\' || c == ':'))
1553 area_delimiter = cur_length;
1557 ext_delimiter = cur_length;
1562 /******************************** 2000 August 15th start ***********************/
1564 // The following code is to save string space used by TeX for filenames
1565 // Not really critical in a system that has dynamic memory allocation
1566 // And may slow it down slightly - although this linear search only
1567 // occurs when opening a file, which is somewhat slow inany case...
1569 // see if string from str_pool[start] to str_pool[end]
1570 // occurs elsewhere in string pool - returns string number
1571 // returns -1 if not found in string pool 2000 Aug 15
1573 int find_string (int start, int end)
1575 int k, nlen = end - start;
1580 sprintf(log_line, "\nLOOKING for string (str_ptr %d nlen %d) ", str_ptr, end - start);
1581 s = log_line + strlen(log_line);
1582 strncpy(s, (const char *) str_pool + start, nlen);
1583 strcpy(s + nlen, "");
1584 show_line(log_line, 0);
1587 // avoid problems with(cur_name == flushablestring)by going only up to str_ptr-1
1588 // code in new_font (tex8.c) will take care of reuse of font name already
1589 for (k = 0; k < str_ptr - 1; k++)
1591 if (length(k) != nlen)
1594 if (strncmp((const char *) str_pool + start, (const char *) str_pool + str_start[k], nlen) == 0)
1598 sprintf(log_line, "\nFOUND the string %d (%d) ", k, str_start[k+1]-str_start[k]);
1599 s = log_line + strlen(log_line);
1600 strncpy(s, (const char *)str_pool + start, nlen);
1601 strcpy(s+nlen, "\n");
1602 show_line(log_line, 0);
1604 return k; // return number of matching string
1610 sprintf(log_line, "\nNOT FOUND string ");
1611 s = log_line + strlen(log_line);
1612 strncpy(s, (const char*)str_pool + start, nlen);
1613 strcpy(s + nlen, "\n");
1614 show_line(log_line, 0);
1617 return -1; // no match found
1620 // snip out the string from str_pool[start] to str_pool[end]
1621 // and move everything above it down 2000 Aug 15
1623 void remove_string (int start, int end)
1625 int nlen = pool_ptr - end; // how many bytes to move down
1628 // int trace_flag=1; // debugging only
1629 // if (end < start) show_line("\nEND < START", 1);
1630 // if (pool_ptr < end) show_line("\nPOOLPTR < END", 1);
1634 int n = end - start;
1635 sprintf(log_line, "\nSTRIPPING OUT %d %d ", n, nlen);
1636 s = log_line + strlen(log_line);
1637 strncpy(s, (const char *)str_pool + start, n);
1638 strcpy(s + n, "\n");
1639 show_line(log_line, 0);
1643 memcpy(str_pool + start, str_pool + end, nlen);
1645 pool_ptr = start + nlen; // poolprt - (end-start);
1648 void show_string (int k)
1650 int nlen = length(k);
1653 sprintf(log_line, "\nSTRING %5d (%3d) %5d--%5d ",
1654 k, nlen, str_start[k], str_start[k+1]);
1655 s = log_line + strlen(log_line);
1656 strncpy(s, (const char *)str_pool + str_start[k], nlen);
1657 strcpy(s + nlen, "");
1658 show_line(log_line, 0);
1661 void show_all_strings (void)
1665 for (k = 0; k < str_ptr; k++)
1669 /********************************** 2000 August 15 end ****************************/
1671 void end_name (void)
1673 #ifdef ALLOCATESTRING
1674 if (str_ptr + 3 > current_max_strings)
1675 str_start = realloc_str_start(increment_max_strings + 3);
1677 if (str_ptr + 3 > current_max_strings)
1679 overflow("number of strings", current_max_strings - init_str_ptr);
1680 return; // abort_flag set
1683 if (str_ptr + 3 > max_strings)
1685 overflow("number of strings", max_strings - init_str_ptr);
1686 return; // abort_flag set
1690 if (area_delimiter == 0) // no area delimiter ':' '/' or '\' found
1691 cur_area = 335; // "" default area
1694 if (save_strings_flag && (cur_area = find_string(str_start[str_ptr], str_start[str_ptr] + area_delimiter)) > 0)
1696 remove_string(str_start[str_ptr], str_start[str_ptr] + area_delimiter);
1697 area_delimiter = 0; // area_delimiter - area_delimiter;
1699 if (ext_delimiter != 0)
1700 ext_delimiter = ext_delimiter - area_delimiter;
1702 // str_start[str_ptr + 1]= str_start[str_ptr]+ area_delimiter; // test only
1703 // incr(str_ptr); // test only
1705 else // carve out string for "cur_area"
1708 str_start[str_ptr + 1] = str_start[str_ptr] + area_delimiter;
1713 if (ext_delimiter == 0) // no extension delimiter '.' found
1715 cur_ext = 335; // "" default extension
1717 if (save_strings_flag && (cur_name = find_string(str_start[str_ptr], pool_ptr)) > 0)
1719 remove_string(str_start[str_ptr], pool_ptr);
1720 // (void) make_string(); // test only
1722 else // Make string from str_start[str_ptr]to pool_ptr
1723 cur_name = make_string();
1725 else // did find an extension
1727 if (save_strings_flag &&
1728 (cur_name = find_string(str_start[str_ptr], str_start[str_ptr] + ext_delimiter - area_delimiter-1)) > 0)
1730 remove_string(str_start[str_ptr], str_start[str_ptr] + ext_delimiter - area_delimiter - 1);
1731 // str_start[str_ptr + 1]= str_start[str_ptr]+ ext_delimiter - area_delimiter - 1; // test only
1732 // incr(str_ptr); // test only
1734 else // carve out string for "cur_name"
1737 str_start[str_ptr + 1]= str_start[str_ptr]+ ext_delimiter - area_delimiter - 1;
1741 if (save_strings_flag && (cur_ext = find_string(str_start[str_ptr], pool_ptr)) > 0)
1743 remove_string(str_start[str_ptr], pool_ptr);
1744 // (void) make_string(); // test only
1746 else // Make string from str_start[str_ptr]to pool_ptr
1747 cur_ext = make_string();
1751 /* n current name, a current area, e current extension */
1752 /* result in name_of_file[] */
1754 void pack_file_name_(str_number n, str_number a, str_number e)
1762 for (j = str_start[a]; j <= str_start[a + 1] - 1; j++)
1768 name_of_file[k] = xchr[c];
1771 for (j = str_start[n]; j <= str_start[n + 1] - 1; j++)
1777 name_of_file[k] = xchr[c];
1780 for (j = str_start[e]; j <= str_start[e + 1] - 1; j++)
1786 name_of_file[k] = xchr[c];
1792 name_length = PATHMAX - 1;
1794 /* pad it out with spaces ... what for ? in case we modify and forget ? */
1795 for (k = name_length + 1; k <= PATHMAX; k++)
1796 name_of_file[k] = ' ';
1798 name_of_file[PATHMAX] = '\0'; /* paranoia 94/Mar/24 */
1801 name_of_file [name_length+1] = '\0';
1805 sprintf(log_line, " pack_file_name `%s' (%d) ", name_of_file + 1, name_length); /* debugging */
1806 show_line(log_line, 0);
1809 name_of_file [name_length + 1] = ' ';
1812 /* Called only from two places tex9.c for format name - specified and default */
1813 /* for specified format name args are 0, a, b name in buffer[a] --- buffer[b] */
1814 /* for default args are format_default_length-4, 1, 0 */
1816 void pack_buffered_name_(small_number n, integer a, integer b)
1822 if (n + b - a + 5 > PATHMAX)
1823 b = a + PATHMAX - n - 5;
1827 /* This loop kicks in when we want the default format name */
1828 for (j = 1; j <= n; j++)
1830 c = xord[TEX_format_default[j]];
1834 name_of_file[k] = xchr[c];
1836 /* This loop kicks in when we want a specififed format name */
1837 for (j = a; j <= b; j++)
1843 name_of_file[k] = xchr[c];
1846 /* This adds the extension from the default format name */
1847 for (j = format_default_length - 3; j <= format_default_length; j++)
1849 c = xord[TEX_format_default[j]];
1853 name_of_file[k] = xchr[c];
1859 name_length = PATHMAX - 1;
1861 /* pad it out with spaces ... what for ? */
1862 for (k = name_length + 1; k <= PATHMAX; k++)
1863 name_of_file[k]= ' ';
1865 name_of_file[PATHMAX] = '\0'; /* paranoia 94/Mar/24 */
1868 str_number make_name_string (void)
1872 #ifdef ALLOCATESTRING
1873 if (pool_ptr + name_length > current_pool_size)
1874 str_pool = realloc_str_pool(increment_pool_size + name_length);
1876 if (str_ptr == current_max_strings)
1877 str_start = realloc_str_start(increment_max_strings);
1879 if ((pool_ptr + name_length > current_pool_size) || (str_ptr == current_max_strings) || (cur_length > 0))
1881 if ((pool_ptr + name_length > pool_size) || (str_ptr == max_strings) || (cur_length > 0))
1888 for (k = 1; k <= name_length; k++)
1889 append_char(xord[name_of_file[k]]);
1891 return make_string();
1895 str_number a_make_name_string_(alpha_file * f)
1897 return make_name_string();
1900 str_number b_make_name_string_(byte_file * f)
1902 return make_name_string();
1905 str_number w_make_name_string_(word_file * f)
1907 return make_name_string();
1910 /* Used by start_input to scan file name on command line */
1911 /* Also in tex8.c new_font_, open_or_close_in, and do_extension */
1913 void scan_file_name (void)
1915 name_in_progress = true;
1922 while (!(cur_cmd != spacer));
1924 quoted_file_name = false;
1926 if (allow_quoted_names)
1930 quoted_file_name = 1;
1937 if ((cur_cmd > other_char) || (cur_chr > 255))
1943 if (!more_name(cur_chr)) /* up to next white space */
1951 name_in_progress = false;
1953 /* argument is string .fmt, .log, or .dvi */
1955 void pack_job_name_(str_number s)
1957 cur_area = 335; /* "" */
1959 cur_name = job_name;
1960 pack_file_name(cur_name, cur_area, cur_ext);
1963 /**********************************************************************/
1964 /* show TEXINPUTS=... or format specific */
1965 /* only show this if name was not fully qualified ? */
1966 void show_tex_inputs (void)
1970 s = "TEXINPUTS"; /* default */
1972 if (format_specific)
1974 s = format_name; /* try specific */
1976 if (grabenv(s) == NULL)
1977 s = "TEXINPUTS"; /* no format specific */
1980 if (grabenv(s) == NULL)
1981 s = "TEXINPUT"; /* 94/May/19 */
2005 /**********************************************************************/
2007 /* s - what can't be found, e - default */
2008 void prompt_file_name_(char * s, str_number e)
2012 if (interaction == scroll_mode);
2014 if (!strcmp("input file name", s))
2015 print_err("I can't find file `");
2017 print_err("I can't write on file `");
2019 print_file_name(cur_name, cur_area, cur_ext);
2022 if (!strcmp("input file name", s))
2024 if (cur_area == 335) /* "" only if path not specified */
2026 if (show_texinput_flag)
2031 if (e == 785) /* .tex */
2034 print_nl("Please type another ");
2037 if (interaction < 2)
2039 fatal_error("*** (job aborted, file error in nonstop mode)");
2040 return; // abort_flag set
2045 show_line(" (or ^z to exit)", 0);
2047 show_line(" (or Ctrl-Z to exit)", 0);
2051 term_input(": ", 0);
2053 /* should we deal with tilde and space in file name here ??? */
2058 while ((buffer[k] == ' ') && (k < last))
2060 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
2061 quoted_file_name = 0; /* 98/March/15 */
2063 if (allow_quoted_names && k < last) /* check whether quoted name */
2065 if (buffer[k]== '"')
2067 quoted_file_name = 1;
2076 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
2077 /* convert tilde '~' to pseudo tilde */
2078 if (pseudo_tilde != 0 && buffer[k]== '~')
2079 buffer[k] = pseudo_tilde;
2080 /* convert space ' ' to pseudo space */
2081 if (pseudo_space != 0 && buffer[k]== ' ')
2082 buffer[k] = pseudo_space;
2083 /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */
2084 if (!more_name(buffer[k]))
2093 if (cur_ext == 335) /* "" */
2094 cur_ext = e; /* use default extension */
2096 pack_file_name(cur_name, cur_area, cur_ext);
2099 void open_log_file (void)
2106 old_setting = selector;
2111 pack_job_name(".log");
2113 while (!a_open_out(log_file))
2115 selector = term_only;
2116 prompt_file_name("transcript file name", ".log");
2119 texmf_log_name = a_make_name_string(log_file);
2120 selector = log_only;
2127 strcat(log_line, "\n");
2128 (void) fputs(log_line, log_file);
2129 stampcopy(log_line);
2130 strcat(log_line, "\n");
2131 (void) fputs(log_line, log_file);
2134 (void) fputs(tex_version, log_file);
2135 (void) fprintf(log_file, " (%s %s)", application, yandyversion);
2137 if (format_ident > 0)
2138 slow_print(format_ident);
2148 months = " JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
2150 for (k = 3 * month - 2; k <= 3 * month; k++)
2151 (void) putc(months[k], log_file);
2161 print_two(tex_time / 60);
2163 print_two(tex_time % 60);
2166 input_stack[input_ptr] = cur_input;
2168 l = input_stack[0].limit_field;
2170 if (buffer[l] == end_line_char)
2173 for (k = 1; k <= l; k++)
2180 if (format_file != NULL)
2182 fprintf(log_file, "(%s)\n", format_file);
2188 selector = old_setting + 2;
2191 /**************************** start of insertion 98/Feb/7 **************/
2192 // Attempt to deal with foo.bar.tex given as foo.bar on command line
2193 // Makes copy of job_name with extension
2195 void more_name_copy(ASCII_code c)
2197 #ifdef ALLOCATESTRING
2198 if (pool_ptr + 1 > current_pool_size)
2199 str_pool = realloc_str_pool (increment_pool_size);
2201 if (pool_ptr + 1 > current_pool_size)
2203 overflow("pool size", current_pool_size - init_pool_ptr);
2207 if (pool_ptr + 1 > pool_size)
2209 overflow("pool size", pool_size - init_pool_ptr);
2214 str_pool[pool_ptr] = c;
2218 int end_name_copy(void)
2220 #ifdef ALLOCATESTRING
2221 if (str_ptr + 1 > current_max_strings)
2222 str_start = realloc_str_start(increment_max_strings + 1);
2224 if (str_ptr + 1 > current_max_strings)
2226 overflow("number of strings", current_max_strings - init_str_ptr);
2230 if (str_ptr + 1 > max_strings)
2232 overflow("number of strings", max_strings - init_str_ptr);
2237 return make_string();
2240 void job_name_append (void)
2244 k = str_start[job_name];
2245 n = str_start[job_name + 1];
2248 more_name_copy(str_pool[k++]);
2250 k = str_start[cur_ext];
2251 n = str_start[cur_ext + 1];
2254 more_name_copy(str_pool[k++]);
2256 job_name = end_name_copy();
2259 /**************************** end of insertion 98/Feb/7 **************/
2261 void start_input(void)
2263 bool added_extension = false;
2266 pack_file_name(cur_name, cur_area, cur_ext);
2270 added_extension = false;
2271 begin_file_reading();
2273 if ((cur_ext != 335) && a_open_in(input_file[cur_input.index_field], TEXINPUTPATH))
2276 if ((cur_ext != 785) && (name_length + 5 < PATHMAX))
2278 name_of_file[name_length + 1] = '.';
2279 name_of_file[name_length + 2] = 't';
2280 name_of_file[name_length + 3] = 'e';
2281 name_of_file[name_length + 4] = 'x';
2282 name_of_file[name_length + 5] = ' ';
2283 name_length = name_length + 4;
2285 added_extension = true;
2287 if (a_open_in(input_file[cur_input.index_field], TEXINPUTPATH))
2290 name_length = name_length - 4;
2291 name_of_file[name_length + 1] = ' ';
2292 added_extension = false;
2295 if ((cur_ext == 335) && a_open_in(input_file[cur_input.index_field], TEXINPUTPATH))
2299 prompt_file_name("input file name", ".tex");
2303 cur_input.name_field = a_make_name_string(input_file[cur_input.index_field]);
2307 job_name = cur_name;
2309 if (cur_ext != 335 && added_extension)
2315 if (term_offset + length(cur_input.name_field) > max_print_line - 2)
2317 else if ((term_offset > 0) || (file_offset > 0))
2323 if (open_parens > max_open_parens)
2324 max_open_parens = open_parens;
2326 slow_print(cur_input.name_field);
2332 cur_input.state_field = new_line;
2337 if (input_ln(input_file[cur_input.index_field], false));
2341 if ((end_line_char < 0) || (end_line_char > 255))
2342 decr(cur_input.limit_field);
2344 buffer[cur_input.limit_field] = end_line_char;
2346 first = cur_input.limit_field + 1;
2347 cur_input.loc_field = cur_input.start_field;
2351 /**********************************************************************/
2352 /* show TEXFONTS=... or format specific */
2353 /* only show this if name was not fully qualified ? */
2354 void show_tex_fonts (void)
2356 char *s, *t, *v, *u;
2361 if (encoding_specific)
2363 u = encoding_name; /* try specific */
2365 if ((t = grabenv(u)) != NULL)
2367 if (strchr(t, ':') != NULL && sscanf(t, "%d", &n) == 0)
2369 s = u; /* look here instead of TEXFONTS=... */
2396 internal_font_number read_font_info_(halfword u, str_number nom, str_number aire, scaled s)
2400 /* halfword lf, lh, bc, ec, nw, nh, nd, ni, nl, nk, ne, np; */
2401 halfword lf, lh, nw, nh, nd, ni, nl, nk, ne, np;
2402 /* halfword bc, ec; */
2403 int bc, ec; /* 95/Jan/7 */
2404 internal_font_number f;
2405 internal_font_number g;
2406 eight_bits a, b, c, d;
2416 file_opened = false;
2417 pack_file_name(nom, aire, 805); /* .tfm */
2419 if (!b_open_in(tfm_file))
2428 tfm_temp = getc(tfm_file);
2430 tfm_temp = getc(tfm_file);
2432 tfm_temp = getc(tfm_file);
2435 if ((bc > ec + 1)||(ec > 255))
2444 tfm_temp = getc(tfm_file);
2446 tfm_temp = getc(tfm_file);
2448 tfm_temp = getc(tfm_file);
2450 tfm_temp = getc(tfm_file);
2452 tfm_temp = getc(tfm_file);
2454 tfm_temp = getc(tfm_file);
2456 tfm_temp = getc(tfm_file);
2458 tfm_temp = getc(tfm_file);
2461 if (lf != 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np)
2464 if ((nw == 0) || (nh == 0) || (nd == 0) || (ni == 0))
2474 if ((fmem_ptr + lf > current_font_mem_size))
2475 font_info = realloc_font_info (increment_font_mem_size + lf);
2477 if ((font_ptr == font_max) || (fmem_ptr + lf > current_font_mem_size))
2479 if ((font_ptr == font_max) || (fmem_ptr + lf > font_mem_size))
2484 sprintf(log_line, "font_ptr %d font_max %d fmem_ptr %d lf %d font_mem_size %d\n",
2485 font_ptr, font_max, fmem_ptr, lf, font_mem_size); /* debugging */
2486 show_line(log_line, 0);
2492 print_file_name(nom, aire, 335); /* "" */
2496 print_string(" at ");
2500 else if (s != -1000)
2502 print_string(" scaled ");
2503 print_int(- (integer) s);
2506 print_string(" not loaded: Not enough room left");
2507 help4("I'm afraid I won't be able to make use of this font,",
2508 "because my memory for character-size data is too small.",
2509 "If you're really stuck, ask a wizard to enlarge me.",
2510 "Or maybe try `I\\font<same font id>=<name of loaded font>'.");
2516 char_base[f] = fmem_ptr - bc;
2517 width_base[f] = char_base[f] + ec + 1;
2518 height_base[f] = width_base[f] + nw;
2519 depth_base[f] = height_base[f] + nh;
2520 italic_base[f] = depth_base[f] + nd;
2521 lig_kern_base[f] = italic_base[f] + ni;
2522 kern_base[f] = lig_kern_base[f] + nl - 256 * (128);
2523 exten_base[f] = kern_base[f] + 256 * (128) + nk;
2524 param_base[f] = exten_base[f] + ne;
2530 /* build the font checksum now */
2531 store_four_quarters(font_check[f]);
2532 tfm_temp = getc(tfm_file);
2534 tfm_temp = getc(tfm_file);
2535 z = z * 256 + tfm_temp;
2536 tfm_temp = getc(tfm_file);
2537 z =(z * 16) + (tfm_temp / 16);
2544 tfm_temp = getc(tfm_file);
2545 tfm_temp = getc(tfm_file);
2546 tfm_temp = getc(tfm_file);
2547 tfm_temp = getc(tfm_file);
2557 z = xn_over_d(z, - (integer) s, 1000);
2562 for (k = fmem_ptr; k <= width_base[f] - 1; k++)
2564 store_four_quarters(font_info[k].qqqq);
2566 if ((a >= nw) || (b / 16 >= nh) || (b % 16 >= nd) || (c / 4 >= ni))
2584 if ((d < bc)||(d > ec))
2588 while (d < k + bc - fmem_ptr)
2590 qw = char_info(f, d);
2592 if (char_tag(qw) != list_tag)
2598 if (d == k + bc - fmem_ptr)
2613 while (z >= 8388608L) /* 2^23 */
2616 alpha = alpha + alpha;
2619 beta = (char) (256 / alpha);
2623 for (k = width_base[f]; k <= lig_kern_base[f] - 1; k++)
2625 tfm_temp = getc(tfm_file);
2627 tfm_temp = getc(tfm_file);
2629 tfm_temp = getc(tfm_file);
2631 tfm_temp = getc(tfm_file);
2633 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2636 font_info[k].cint = sw;
2638 font_info[k].cint = sw - alpha;
2643 if (font_info[width_base[f]].cint != 0)
2646 if (font_info[height_base[f]].cint != 0)
2649 if (font_info[depth_base[f]].cint != 0)
2652 if (font_info[italic_base[f]].cint != 0)
2656 bch_label = 32767; /* '77777 */
2661 for (k = lig_kern_base[f]; k <= kern_base[f] + 256 * (128) - 1; k++)
2663 store_four_quarters(font_info[k].qqqq);
2667 if (256 * c + d >= nl)
2668 goto lab11; /* error in TFM, abort */
2671 if (k == lig_kern_base[f])
2679 if ((b < bc) || (b > ec)) /* check-existence(b) */
2680 goto lab11; /* error in TFM, abort */
2683 qw = font_info[char_base[f] + b].qqqq;
2686 goto lab11; /* error in TFM, abort */
2692 if ((d < bc) || (d > ec)) /* check-existence(d) */
2693 goto lab11; /* error in TFM, abort */
2696 qw = font_info[char_base[f] + d].qqqq;
2699 goto lab11; /* error in TFM, abort */
2701 else if (256 * (c - 128) + d >= nk)
2702 goto lab11; /* error in TFM, abort */
2705 if (k - lig_kern_base[f] + a + 1 >= nl)
2706 goto lab11; /* error in TFM, abort */
2711 bch_label = 256 * c + d;
2714 for (k = kern_base[f] + 256 * (128); k <= exten_base[f] - 1; k++)
2716 tfm_temp = getc(tfm_file);
2718 tfm_temp = getc(tfm_file);
2720 tfm_temp = getc(tfm_file);
2722 tfm_temp = getc(tfm_file);
2724 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2727 font_info[k].cint = sw;
2729 font_info[k].cint = sw - alpha;
2733 /* read extensible character recipes */
2734 for (k = exten_base[f]; k <= param_base[f] - 1; k++)
2736 store_four_quarters(font_info[k].qqqq);
2741 if ((a < bc) || (a > ec))
2745 qw = font_info[char_base[f] + a].qqqq;
2754 if ((b < bc) || (b > ec))
2758 qw = font_info[char_base[f] + b].qqqq;
2767 if ((c < bc) || (c > ec))
2771 qw = font_info[char_base[f] + c].qqqq;
2779 if ((d < bc) || (d > ec))
2783 qw = font_info[char_base[f] + d].qqqq;
2791 for (k = 1; k <= np; k++)
2794 tfm_temp = getc(tfm_file);
2800 tfm_temp = getc(tfm_file);
2801 sw = sw * 256 + tfm_temp;
2802 tfm_temp = getc(tfm_file);
2803 sw = sw * 256 + tfm_temp;
2804 tfm_temp = getc(tfm_file);
2805 font_info[param_base[f]].cint = (sw * 16) + (tfm_temp / 16);
2809 tfm_temp = getc(tfm_file);
2811 tfm_temp = getc(tfm_file);
2813 tfm_temp = getc(tfm_file);
2815 tfm_temp = getc(tfm_file);
2817 sw = (((((d * z) / 256) + (c * z)) / 256) + (b * z)) / beta;
2820 font_info[param_base[f] + k - 1].cint = sw;
2822 font_info[param_base[f] + k - 1].cint = sw - alpha;
2829 for (k = np + 1; k <= 7; k++)
2830 font_info[param_base[f] + k - 1].cint = 0;
2834 font_params[f] = np;
2838 hyphen_char[f] = default_hyphen_char;
2839 skew_char[f] = default_skew_char;
2842 bchar_label[f] = bch_label + lig_kern_base[f];
2844 bchar_label[f] = non_address;
2846 font_bchar[f] = bchar;
2847 font_false_bchar[f] = bchar;
2852 qw = font_info[char_base[f] + bchar].qqqq;
2855 font_false_bchar[f] = 256;
2859 font_area[f] = aire;
2863 char_base[f] = char_base[f];
2864 width_base[f] = width_base[f];
2865 lig_kern_base[f] = lig_kern_base[f];
2866 kern_base[f] = kern_base[f];
2867 exten_base[f] = exten_base[f];
2868 decr(param_base[f]);
2869 fmem_ptr = fmem_ptr + lf;
2878 print_file_name(nom, aire, 335);
2882 print_string(" at ");
2886 else if (s != -1000)
2888 print_string("scaled");
2889 print_int(- (integer) s);
2893 print_string(" not loadable: Bad metric (TFM) file");
2895 print_string(" not loadable: Metric (TFM) file not found");
2899 if (show_texinput_flag)
2903 help5("I wasn't able to read the size data for this font,",
2904 "so I will ignore the font specification.",
2905 "[Wizards can fix TFM files using TFtoPL/PLtoTF.]",
2906 "You might try inserting a different font spec;",
2907 "e.g., type `I\\font<same font id>=<substitute font name>'.");