OSDN Git Service

322f6ae5cc177979013e9e0012387e9da73c0fa7
[putex/putex.git] / src / texsourc / yandy_inlines.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 "texd.h"
21
22 inline void push_input(void)
23 {
24   if (input_ptr > max_in_stack)
25   {
26     max_in_stack = input_ptr;
27
28 #ifdef ALLOCATEINPUTSTACK
29     if (input_ptr == current_stack_size)
30       input_stack = realloc_input_stack(increment_stack_size);
31     
32     if (input_ptr == current_stack_size)
33     {
34       overflow("input stack size", current_stack_size);
35       return;
36     }
37 #else
38     if (input_ptr == stack_size)
39     {
40       overflow("input stack size", stack_size);
41       return;
42     }
43 #endif
44   }
45   
46   input_stack[input_ptr] = cur_input;
47   incr(input_ptr);
48 }
49 inline void pop_input(void)
50 {
51   decr(input_ptr);
52   cur_input = input_stack[input_ptr];
53 }
54 inline void ensure_dvi_open(void)
55 {
56   if (output_file_name == 0)
57   {
58     if (job_name == 0)
59       open_log_file();
60
61     pack_job_name(".dvi");
62
63     while (!b_open_out(dvi_file))
64     {
65       prompt_file_name("file name for output", ".dvi");
66     }
67
68     output_file_name = b_make_name_string(dvi_file);
69   }
70 }
71
72 inline void write_dvi(size_t a, size_t b)
73 {
74   if (fwrite((char *) &dvi_buf[a], sizeof(dvi_buf[a]),
75     ((b) - (a) + 1), dvi_file) != ((b) - (a) + 1))
76     FATAL_PERROR ("\n! dvi file");
77 }
78 inline void prompt_input(const char * s)
79 {
80   print_string(s);
81   term_input();
82 }
83 inline void synch_h(void)
84 {
85   if (cur_h != dvi_h)
86   {
87     movement(cur_h - dvi_h, right1);
88     dvi_h = cur_h;
89   }
90 }
91 inline void synch_v(void)
92 {
93   if (cur_v != dvi_v)
94   {
95     movement(cur_v - dvi_v, down1);
96     dvi_v = cur_v;
97   }
98 }
99 inline void set_cur_lang(void)
100 {
101   if (language <= 0)
102     cur_lang = 0;
103   else if (language > 255)
104     cur_lang = 0;
105   else
106     cur_lang = language;
107 }
108 inline void free_avail_(halfword p)
109 {
110   link(p) = avail;
111   avail = p;
112 #ifdef STAT
113   decr(dyn_used);
114 #endif
115 }
116 inline void dvi_out_(ASCII_code op)
117 {
118   dvi_buf[dvi_ptr] = op;
119   incr(dvi_ptr);
120
121   if (dvi_ptr == dvi_limit)
122     dvi_swap();
123 }
124 inline void succumb (void)
125 {
126   if (interaction == error_stop_mode)
127     interaction = scroll_mode;
128
129   if (log_opened)
130   {
131     error();
132   }
133
134 #ifdef DEBUG
135   if (interaction > 0)
136     debug_help();
137 #endif
138
139   history = error_stop_mode;
140   jump_out();
141 }
142 inline void flush_string (void)
143 {
144   decr(str_ptr);
145   pool_ptr = str_start[str_ptr];
146 }
147 inline void append_char (ASCII_code c)
148 {
149   str_pool[pool_ptr] = c;
150   incr(pool_ptr);
151 }
152 inline void append_lc_hex (ASCII_code c)
153 {
154   if (c < 10)
155     append_char(c + '0');
156   else
157     append_char(c - 10 + 'a');
158 }
159 inline void print_err (const char * s)
160 {
161   if (interaction == error_stop_mode);
162     print_nl("! ");
163
164   print_string(s);
165 }
166 inline void tex_help (unsigned int n, ...)
167 {
168   int i;
169   va_list help_arg;
170
171   if (n > 6)
172     n = 6;
173
174   help_ptr = n;
175   va_start(help_arg, n);
176
177   for (i = n - 1; i > -1; --i)
178     help_line[i] = va_arg(help_arg, char *);
179
180   va_end(help_arg);
181 }
182 inline void str_room(int val)
183 {
184 #ifdef ALLOCATESTRING
185   if (pool_ptr + val > current_pool_size)
186     str_pool = realloc_str_pool(increment_pool_size);
187
188   if (pool_ptr + val > current_pool_size)
189     overflow("pool size", current_pool_size - init_pool_ptr);
190 #else
191   if (pool_ptr + val > pool_size)
192     overflow("pool size", pool_size - init_pool_ptr);
193 #endif
194 }
195 inline void tail_append_ (pointer val)
196 {
197   link(tail) = val;
198   tail = link(tail);
199 }