3 Copyright 2009 Taco Hoekwater <taco@luatex.org>
5 This file is part of LuaTeX.
7 LuaTeX is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2 of the License, or (at your
10 option) any later version.
12 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License along
18 with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
24 extern int luatex_version
;
25 extern int luatex_revision
;
26 extern int luatex_date_info
;
27 extern const char *luatex_version_string
;
28 extern const char *engine_name
;
31 The following parameters can be changed at compile time to extend or
32 reduce \TeX's capacity. They may have different values in \.{INITEX} and
33 in production versions of \TeX.
35 @^system dependencies@>
38 # define ssup_max_strings 2097151
40 # define inf_max_strings 100000
41 # define sup_max_strings ssup_max_strings
42 # define inf_strings_free 100
43 # define sup_strings_free sup_max_strings
45 # define inf_buf_size 500
46 # define sup_buf_size 100000000
48 # define inf_nest_size 40
49 # define sup_nest_size 4000
51 # define inf_max_in_open 6
52 # define sup_max_in_open 600 /* was 127. now okay for some 512 nested lua calls */
54 # define inf_param_size 60
55 # define sup_param_size 32767
57 # define inf_save_size 600
58 # define sup_save_size 500000
60 # define inf_stack_size 200
61 # define sup_stack_size 50000
63 # define inf_dvi_buf_size 800
64 # define sup_dvi_buf_size 65536
66 # define sup_hash_extra sup_max_strings
67 # define inf_hash_extra 0
69 # define inf_expand_depth 100
70 # define sup_expand_depth 10000000
75 /* Types in the outer block */
76 typedef int ASCII_code
; /* characters */
77 typedef unsigned char eight_bits
; /* unsigned one-byte quantity */
78 typedef FILE *alpha_file
; /* files that contain textual data */
79 typedef FILE *byte_file
; /* files that contain binary data */
81 typedef int str_number
;
82 typedef int pool_pointer
;
83 typedef unsigned char packed_ASCII_code
;
85 typedef int scaled
; /* this type is used for scaled integers */
86 typedef char small_number
; /* this type is self-explanatory */
88 typedef float glue_ratio
; /* one-word representation of a glue expansion factor */
90 typedef unsigned short quarterword
;
93 typedef unsigned char glue_ord
; /* infinity to the 0, 1, 2, 3, or 4 power */
95 typedef unsigned short group_code
; /* |save_level| for a level boundary */
97 typedef int font_index
; /* index into |font_info| */
99 typedef int save_pointer
;
102 Characters of text that have been converted to \TeX's internal form
103 are said to be of type |ASCII_code|, which is a subrange of the integers.
105 We are assuming that our runtime system is able to read and write UTF-8.
107 Some of the ASCII codes without visible characters have been given symbolic
108 names in this program because they are used with a special meaning.
112 # define null_code '\0' /* ASCII code that might disappear */
113 # define carriage_return '\r' /* ASCII code used at end of line */
115 /* Global variables */
116 extern boolean luainit
; /* are we using lua for initializations */
117 extern boolean tracefilenames
; /* print file open-close info? */
120 extern boolean ini_version
; /* are we \.{INITEX}? */
121 extern boolean dump_option
;
122 extern boolean dump_line
;
123 extern int bound_default
;
124 extern char *bound_name
;
125 extern int error_line
;
126 extern int half_error_line
;
127 extern int max_print_line
;
128 extern int max_strings
;
129 extern int strings_free
;
132 extern int stack_size
;
133 extern int max_in_open
;
134 extern int param_size
;
135 extern int nest_size
;
136 extern int save_size
;
137 extern int expand_depth
;
138 extern int parsefirstlinep
;
139 extern int filelineerrorstylep
;
140 extern int haltonerrorp
;
141 extern boolean quoted_filename
;
144 In order to make efficient use of storage space, \TeX\ bases its major data
145 structures on a |memory_word|, which contains either a (signed) integer,
146 possibly scaled, or a (signed) |glue_ratio|, or a small number of
147 fields that are one half or one quarter of the size used for storing
150 If |x| is a variable of type |memory_word|, it contains up to four
151 fields that can be referred to as follows:
152 $$\vbox{\halign{\hfil#&#\hfil&#\hfil\cr
153 |x|&.|int|&(an |integer|)\cr
154 |x|&.|sc|\qquad&(a |scaled| integer)\cr
155 |x|&.|gr|&(a |glue_ratio|)\cr
156 |x.hh.lh|, |x.hh|&.|rh|&(two halfword fields)\cr
157 |x.hh.b0|, |x.hh.b1|, |x.hh|&.|rh|&(two quarterword fields, one halfword
159 |x.qqqq.b0|, |x.qqqq.b1|, |x.qqqq|&.|b2|, |x.qqqq.b3|\hskip-100pt
160 &\qquad\qquad\qquad(four quarterword fields)\cr}}$$
161 This is somewhat cumbersome to write, and not very readable either, but
162 macros will be used to make the notation shorter and more transparent.
163 The \PASCAL\ code below gives a formal definition of |memory_word| and
164 its subsidiary types, using packed variant records. \TeX\ makes no
165 assumptions about the relative positions of the fields within a word.
167 We are assuming 32-bit integers, a halfword must contain at least
168 32 bits, and a quarterword must contain at least 16 bits.
169 @^system dependencies@>
171 N.B.: Valuable memory space will be dreadfully wasted unless \TeX\ is compiled
172 by a \PASCAL\ that packs all of the |memory_word| variants into
173 the space of a single integer. This means, for example, that |glue_ratio|
174 words should be |short_real| instead of |real| on some computers. Some
175 \PASCAL\ compilers will pack an integer whose subrange is `|0..255|' into
176 an eight-bit field, but others insist on allocating space for an additional
177 sign bit; on such systems you can get 256 values into a quarterword only
178 if the subrange is `|-128..127|'.
180 The present implementation tries to accommodate as many variations as possible,
181 so it makes few assumptions. If integers having the subrange
182 `|min_quarterword..max_quarterword|' can be packed into a quarterword,
183 and if integers having the subrange `|min_halfword..max_halfword|'
184 can be packed into a halfword, everything should work satisfactorily.
186 It is usually most efficient to have |min_quarterword=min_halfword=0|,
187 so one should try to achieve this unless it causes a severe problem.
188 The values defined here are recommended for most 32-bit computers.
190 We cannot use the full range of 32 bits in a halfword, because we have
191 to allow negative values for potential backend tricks like web2c's
192 dynamic allocation, and parshapes pointers have to be able to store at
193 least twice the value |max_halfword| (see below). Therefore,
194 |max_halfword| is $2^{30}-1$
197 # include "tex/memoryword.h"
199 # define min_quarterword 0 /*smallest allowable value in a |quarterword| */
200 # define max_quarterword 65535 /* largest allowable value in a |quarterword| */
201 # define min_halfword -0x3FFFFFFF /* smallest allowable value in a |halfword| */
202 # define max_halfword 0x3FFFFFFF
203 /* largest allowable value in a |halfword| */
207 The following procedure, which is called just before \TeX\ initializes its
208 input and output, establishes the initial values of the date and time.
209 It calls a macro-defined |dateandtime| routine. |dateandtime| in turn is
210 also a C macro, which calls |get_date_and_time|, passing it the addresses of
211 the day, month, etc., so they can be set by the routine.
212 |get_date_and_time| also sets up interrupt catching if that
213 is conditionally compiled in the C code.
214 @^system dependencies@>
218 # define fix_date_and_time() dateandtime(int_par(time_code),int_par(day_code),int_par(month_code),int_par(year_code))
220 extern int get_luatexversion(void);
221 extern str_number
get_luatexrevision(void);
222 extern int get_luatex_date_info(void);
224 extern int ready_already
;
226 extern void main_body(void);
227 extern void close_files_and_terminate(void);
229 extern void final_cleanup(void);
230 extern void debug_help(void); /* routine to display various things */
232 extern int main_initialize(void);
235 # define get_cur_font() equiv(cur_font_loc)
236 # define zset_cur_font set_cur_font