Debian Codegraph @

texk/web2c/pdftexdir/ptexmac.h

raw
1 /* ptexmac.h: common macros for pdfTeX.
2 Copyright 1996-2021 Han The Thanh, <[email protected]>
3
4 This file is part of pdfTeX.
5
6 pdfTeX is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 pdfTeX is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef PDFTEXMAC
21 # define PDFTEXMAC
22
23 # ifdef WIN32
24 /* Why relying on gmalloc() ??? */
25 # define gmalloc(n) xmalloc(n)
26 # define gfree(p) free(p)
27 # define inline __inline
28 # define srandom(n) srand(n)
29 # define random() rand()
30 # endif
31
32 /* Pascal WEB macros */
33 # define maxinteger 0x7FFFFFFF
34 # define maxdimen 0x3FFFFFFF
35
36 # define objinfo(n) objtab[n].int0
37
38 # define pdfroom(n) do { \
39 if ((unsigned)(n + pdfptr) > (unsigned)pdfbufsize) { \
40 if (pdfosmode) \
41 pdfosgetosbuf(n); \
42 else { \
43 if ((unsigned)(n) > (unsigned)pdfbufsize) \
44 pdftex_fail("PDF output buffer overflowed"); \
45 else \
46 pdfflush(); \
47 } \
48 } \
49 } while (0)
50
51 # define pdfout(c) do { \
52 pdfroom(1); \
53 pdfbuf[pdfptr++] = c; \
54 } while (0)
55
56 # define pdfoffset() (pdfgone + pdfptr)
57
58 # define MAX_CHAR_CODE 255
59 # define PRINTF_BUF_SIZE 1024
60 # define MAX_CSTRING_LEN 1024 * 1024
61 # define MAX_PSTRING_LEN 1024
62 # define SMALL_BUF_SIZE 256
63 # define SMALL_ARRAY_SIZE 256
64 # define FONTNAME_BUF_SIZE 128
65 /* a PDF name can be maximum 127 chars long */
66
67 # define pdftex_debug tex_printf
68
69 # define check_buf(size, buf_size) \
70 if ((unsigned)(size) > (unsigned)(buf_size)) \
71 pdftex_fail("buffer overflow at file %s, line %d", __FILE__, __LINE__ )
72
73 # define append_char_to_buf(c, p, buf, buf_size) do { \
74 if (c == 9) \
75 c = 32; \
76 if (c == 13 || c == EOF) \
77 c = 10; \
78 if (c != ' ' || (p > buf && p[-1] != 32)) { \
79 check_buf(p - buf + 1, (buf_size)); \
80 *p++ = c; \
81 } \
82 } while (0)
83
84 # define append_eol(p, buf, buf_size) do { \
85 check_buf(p - buf + 2, (buf_size)); \
86 if (p - buf > 1 && p[-1] != 10) \
87 *p++ = 10; \
88 if (p - buf > 2 && p[-2] == 32) { \
89 p[-2] = 10; \
90 p--; \
91 } \
92 *p = 0; \
93 } while (0)
94
95 # define remove_eol(p, buf) do { \
96 p = strend(buf) - 1; \
97 if (*p == 10) \
98 *p = 0; \
99 } while (0)
100
101 # define skip(p, c) if (*p == c) p++
102
103 # define alloc_array(T, n, s) do { \
104 if (T##_array == NULL) { \
105 T##_limit = (s); \
106 if ((unsigned)(n) > (unsigned)(T##_limit)) \
107 T##_limit = (n); \
108 T##_array = xtalloc(T##_limit, T##_entry); \
109 T##_ptr = T##_array; \
110 } \
111 else if ((unsigned)(T##_ptr - T##_array + (n)) > (unsigned)(T##_limit)) { \
112 last_ptr_index = T##_ptr - T##_array; \
113 T##_limit *= 2; \
114 if ((unsigned)(T##_ptr - T##_array + (n)) > (unsigned)(T##_limit)) \
115 T##_limit = T##_ptr - T##_array + (n); \
116 if ((unsigned)(T##_limit) > INT_MAX) \
117 pdftex_fail(#T "_array exceeds size limit"); \
118 xretalloc(T##_array, T##_limit, T##_entry); \
119 T##_ptr = T##_array + last_ptr_index; \
120 } \
121 } while (0)
122
123 # define is_cfg_comment(c) \
124 (c == 10 || c == '*' || c == '#' || c == ';' || c == '%')
125
126 # define define_array(T) \
127 T##_entry *T##_ptr, *T##_array = NULL; \
128 size_t T##_limit
129
130 # define xfree(p) do { if (p != NULL) free(p); p = NULL; } while (0)
131 # define strend(s) strchr(s, 0)
132 # define xtalloc XTALLOC
133 # define xretalloc XRETALLOC
134
135 # define ASCENT_CODE 0
136 # define CAPHEIGHT_CODE 1
137 # define DESCENT_CODE 2
138 # define ITALIC_ANGLE_CODE 3
139 # define STEMV_CODE 4
140 # define XHEIGHT_CODE 5
141 # define FONTBBOX1_CODE 6
142 # define FONTBBOX2_CODE 7
143 # define FONTBBOX3_CODE 8
144 # define FONTBBOX4_CODE 9
145 # define FONTNAME_CODE 10
146 # define GEN_KEY_NUM (XHEIGHT_CODE + 1)
147 # define MAX_KEY_CODE (FONTBBOX1_CODE + 1)
148 # define INT_KEYS_NUM (FONTBBOX4_CODE + 1)
149 # define FONT_KEYS_NUM (FONTNAME_CODE + 1)
150
151 # define F_INCLUDED 0x01
152 # define F_SUBSETTED 0x02
153 # define F_STDT1FONT 0x04
154 # define F_SUBFONT 0x08
155 # define F_TYPE1 0x10
156 # define F_TRUETYPE 0x20
157 # define F_OTF 0x40
158 # define F_PK 0x80
159
160 # define set_included(fm) ((fm)->type |= F_INCLUDED)
161 # define set_subsetted(fm) ((fm)->type |= F_SUBSETTED)
162 # define set_std_t1font(fm) ((fm)->type |= F_STDT1FONT)
163 # define set_subfont(fm) ((fm)->type |= F_SUBFONT)
164 # define set_type1(fm) ((fm)->type |= F_TYPE1)
165 # define set_truetype(fm) ((fm)->type |= F_TRUETYPE)
166 # define set_opentype(fm) ((fm)->type |= F_OTF)
167 # define set_pk(fm) ((fm)->type |= F_PK)
168
169 # define unset_included(fm) ((fm)->type &= ~F_INCLUDED)
170 # define unset_subsetted(fm) ((fm)->type &= ~F_SUBSETTED)
171 # define unset_std_t1font(fm)((fm)->type &= ~F_STDT1FONT)
172 # define unset_subfont(fm) ((fm)->type &= ~F_SUBFONT)
173 # define unset_type1(fm) ((fm)->type &= ~F_TYPE1)
174 # define unset_truetype(fm) ((fm)->type &= ~F_TRUETYPE)
175 # define unset_opentype(fm) ((fm)->type &= ~F_OTF)
176 # define unset_pk(fm) ((fm)->type &= ~F_PK)
177
178 # define is_included(fm) (((fm)->type & F_INCLUDED) != 0)
179 # define is_subsetted(fm) (((fm)->type & F_SUBSETTED) != 0)
180 # define is_std_t1font(fm) (((fm)->type & F_STDT1FONT) != 0)
181 # define is_subfont(fm) (((fm)->type & F_SUBFONT) != 0)
182 # define is_type1(fm) (((fm)->type & F_TYPE1) != 0)
183 # define is_truetype(fm) (((fm)->type & F_TRUETYPE) != 0)
184 # define is_opentype(fm) (((fm)->type & F_OTF) != 0)
185 # define is_pk(fm) (((fm)->type & F_PK) != 0)
186
187 # define fm_slant(fm) (fm)->slant
188 # define fm_extend(fm) (fm)->extend
189 # define fm_fontfile(fm) (fm)->ff_name
190
191 # define is_reencoded(fm) ((fm)->encname != NULL)
192 # define is_fontfile(fm) (fm_fontfile(fm) != NULL)
193 # define is_t1fontfile(fm) (is_fontfile(fm) && is_type1(fm))
194 # define is_builtin(fm) (!is_fontfile(fm))
195
196 # define LINK_TFM 0x01
197 # define LINK_PS 0x02
198 # define set_tfmlink(fm) ((fm)->links |= LINK_TFM)
199 # define set_pslink(fm) ((fm)->links |= LINK_PS)
200 # define unset_tfmlink(fm) ((fm)->links &= ~LINK_TFM)
201 # define unset_pslink(fm) ((fm)->links &= ~LINK_PS)
202 # define has_tfmlink(fm) ((fm)->links & LINK_TFM)
203 # define has_pslink(fm) ((fm)->links & LINK_PS)
204
205
206 # define set_cur_file_name(s) \
207 cur_file_name = s; \
208 packfilename(maketexstring(cur_file_name), getnullstr(), getnullstr())
209
210 /* This macro doesn't handle the case where a==b. It turns out that is
211 * convenient for the way it's used; for example, see writettf.c.
212 * All uses (must) follow the same pattern.
213 */
214 # define cmp_return(a, b) \
215 if ((a) > (b)) \
216 return 1; \
217 if ((a) < (b)) \
218 return -1
219
220 # define str_prefix(s1, s2) (strncmp((s1), (s2), strlen(s2)) == 0)
221
222 /* (un)dumping a string means dumping the allocation size, followed
223 * by the bytes. The trailing \0 is (un)dumped as well, because that
224 * makes the code simpler.
225 */
226
227 #define dumpcharptr(a) \
228 do { \
229 integer x; \
230 if (a!=NULL) { \
231 x = strlen(a)+1; \
232 generic_dump(x); dumpthings(*a, x); \
233 } else { \
234 x = 0; generic_dump(x); \
235 } \
236 } while (0)
237
238 #define undumpcharptr(s) \
239 do { \
240 integer x; \
241 char *a; \
242 generic_undump (x); \
243 if (x>0) { \
244 a = xmalloc(x); \
245 undumpthings(*a,x); \
246 s = a ; \
247 } else { s = NULL; } \
248 } while (0)
249
250 #endif /* PDFTEXMAC */