OSDN Git Service

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