OSDN Git Service

version 2.3.0-final.
[putex/putex.git] / src / texsourc / utils.c
1 /*\r
2    Copyright 2014 Clerk Ma\r
3 \r
4    This program is free software; you can redistribute it and/or modify\r
5    it under the terms of the GNU General Public License as published by\r
6    the Free Software Foundation; either version 2 of the License, or\r
7    (at your option) any later version.\r
8 \r
9    This program is distributed in the hope that it will be useful, but\r
10    WITHOUT ANY WARRANTY; without even the implied warranty of\r
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
12    General Public License for more details.\r
13 \r
14    You should have received a copy of the GNU General Public License\r
15    along with this program; if not, write to the Free Software\r
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
17    02110-1301 USA.\r
18 */\r
19 \r
20 #define EXTERN extern\r
21 #include "yandytex.h"\r
22 \r
23 /* sec 0016 */\r
24 void do_nothing(void)\r
25 {\r
26   /* todo */\r
27 }\r
28 void wake_up_terminal (void)\r
29 {\r
30   /* todo */\r
31 }\r
32 /* sec 0034 */\r
33 void update_terminal(void)\r
34 {\r
35   fflush(stdout);\r
36 }\r
37 /* sec 0042 */\r
38 void append_char (ASCII_code c)\r
39 {\r
40   str_pool[pool_ptr] = c;\r
41   incr(pool_ptr);\r
42 }\r
43 /* sec 0042 */\r
44 void str_room(int val)\r
45 {\r
46 #ifdef ALLOCATESTRING\r
47   if (pool_ptr + val > current_pool_size)\r
48     str_pool = realloc_str_pool(increment_pool_size);\r
49 \r
50   if (pool_ptr + val > current_pool_size)\r
51     overflow("pool size", current_pool_size - init_pool_ptr);\r
52 #else\r
53   if (pool_ptr + val > pool_size)\r
54     overflow("pool size", pool_size - init_pool_ptr);\r
55 #endif\r
56 }\r
57 /* sec 0044 */\r
58 void flush_string (void)\r
59 {\r
60   decr(str_ptr);\r
61   pool_ptr = str_start[str_ptr];\r
62 }\r
63 /* sec 0048 */\r
64 void append_lc_hex (ASCII_code c)\r
65 {\r
66   if (c < 10)\r
67     append_char(c + '0');\r
68   else\r
69     append_char(c - 10 + 'a');\r
70 }\r
71 /* sec 0056 */\r
72 /* sec 0073 */\r
73 void print_err (const char * s)\r
74 {\r
75   if (interaction == error_stop_mode)\r
76     wake_up_terminal();\r
77   \r
78   print_nl("! ");\r
79   prints(s);\r
80 }\r
81 /* sec 0071 */\r
82 void prompt_input(const char * s)\r
83 {\r
84   wake_up_terminal();\r
85   prints(s);\r
86   term_input();\r
87 }\r
88 /* sec 0079 */\r
89 void tex_help (unsigned int n, ...)\r
90 {\r
91   int i;\r
92   va_list help_arg;\r
93 \r
94   if (n > 6)\r
95     n = 6;\r
96 \r
97   help_ptr = n;\r
98   va_start(help_arg, n);\r
99 \r
100   for (i = n - 1; i > -1; --i)\r
101     help_line[i] = va_arg(help_arg, char *);\r
102 \r
103   va_end(help_arg);\r
104 }\r
105 /* sec 0093 */\r
106 void succumb (void)\r
107 {\r
108   if (interaction == error_stop_mode)\r
109     interaction = scroll_mode;\r
110 \r
111   if (log_opened)\r
112     error();\r
113 \r
114 #ifdef DEBUG\r
115   if (interaction > 0)\r
116     debug_help();\r
117 #endif\r
118 \r
119   history = error_stop_mode;\r
120   jump_out();\r
121 }\r
122 /* sec 0121 */\r
123 void free_avail_(halfword p)\r
124 {\r
125   link(p) = avail;\r
126   avail = p;\r
127 #ifdef STAT\r
128   decr(dyn_used);\r
129 #endif\r
130 }\r
131 /* sec 0180 */\r
132 void node_list_display (integer p)\r
133 {\r
134   append_char('.');\r
135   show_node_list(p);\r
136   decr(pool_ptr);\r
137 }\r
138 /* sec 0214 */\r
139 void tail_append_ (pointer val)\r
140 {\r
141   link(tail) = val;\r
142   tail = link(tail);\r
143 }\r
144 /* sec 0273 */\r
145 void check_full_save_stack(void)\r
146 {\r
147   if (save_ptr > max_save_stack)\r
148   {\r
149     max_save_stack = save_ptr;\r
150 \r
151 #ifdef ALLOCATESAVESTACK\r
152     if (max_save_stack > current_save_size - 6)\r
153       save_stack = realloc_save_stack(increment_save_size);\r
154 \r
155     if (max_save_stack > current_save_size - 6)\r
156     {\r
157       overflow("save size", current_save_size);\r
158       return;\r
159     }\r
160 #else\r
161     if (max_save_stack > save_size - 6)\r
162     {\r
163       overflow("save size", save_size);\r
164       return;\r
165     }\r
166 #endif\r
167   }\r
168 }\r
169 /* sec 0321 */\r
170 void push_input(void)\r
171 {\r
172   if (input_ptr > max_in_stack)\r
173   {\r
174     max_in_stack = input_ptr;\r
175 \r
176 #ifdef ALLOCATEINPUTSTACK\r
177     if (input_ptr == current_stack_size)\r
178       input_stack = realloc_input_stack(increment_stack_size);\r
179     \r
180     if (input_ptr == current_stack_size)\r
181     {\r
182       overflow("input stack size", current_stack_size);\r
183       return;\r
184     }\r
185 #else\r
186     if (input_ptr == stack_size)\r
187     {\r
188       overflow("input stack size", stack_size);\r
189       return;\r
190     }\r
191 #endif\r
192   }\r
193   \r
194   input_stack[input_ptr] = cur_input;\r
195   incr(input_ptr);\r
196 }\r
197 /* sec 0322 */\r
198 void pop_input(void)\r
199 {\r
200   decr(input_ptr);\r
201   cur_input = input_stack[input_ptr];\r
202 }\r
203 /* sec 0532 */\r
204 void ensure_dvi_open (void)\r
205 {\r
206   if (output_file_name == 0)\r
207   {\r
208     if (job_name == 0)\r
209       open_log_file();\r
210 \r
211     pack_job_name(".dvi");\r
212 \r
213     while (!b_open_out(dvi_file))\r
214       prompt_file_name("file name for output", ".dvi");\r
215 \r
216     output_file_name = b_make_name_string(dvi_file);\r
217   }\r
218 }\r
219 /* sec 0564 */\r
220 void fget (void)\r
221 {\r
222   fbyte = getc(tfm_file);\r
223 }\r
224 /* sec 0597 */\r
225 void write_dvi(size_t a, size_t b)\r
226 {\r
227   if (fwrite((char *)&dvi_buf[a], sizeof(dvi_buf[a]),\r
228     (b - a + 1), dvi_file) != (b - a + 1))\r
229     FATAL_PERROR("\n! dvi file");\r
230 }\r
231 /* sec 0598 */\r
232 void dvi_out_(ASCII_code op)\r
233 {\r
234   dvi_buf[dvi_ptr] = op;\r
235   incr(dvi_ptr);\r
236 \r
237   if (dvi_ptr == dvi_limit)\r
238     dvi_swap();\r
239 }\r
240 /* sec 0616 */\r
241 void synch_h (void)\r
242 {\r
243   if (cur_h != dvi_h)\r
244   {\r
245     movement(cur_h - dvi_h, right1);\r
246     dvi_h = cur_h;\r
247   }\r
248 }\r
249 /* sec 0616 */\r
250 void synch_v (void)\r
251 {\r
252   if (cur_v != dvi_v)\r
253   {\r
254     movement(cur_v - dvi_v, down1);\r
255     dvi_v = cur_v;\r
256   }\r
257 }\r
258 /* sec 0934 */\r
259 void set_cur_lang (void)\r
260 {\r
261   if (language <= 0)\r
262     cur_lang = 0;\r
263   else if (language > 255)\r
264     cur_lang = 0;\r
265   else\r
266     cur_lang = language;\r
267 }\r
268 /* sec 0985 */\r
269 void print_plus (int i, const char * s)\r
270 {\r
271   if (page_so_far[i] != 0)\r
272   {\r
273     prints(" plus ");\r
274     print_scaled(page_so_far[i]);\r
275     prints(s);\r
276   }\r
277 }