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