OSDN Git Service

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