3 This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
5 Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata,
6 the dvipdfmx project team.
8 Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
36 #define TYPE_CHECK(o, t) do { \
37 if ((o) == NULL || pst_type_of((o)) != (t)) \
38 ERROR("typecheck: object %p not of type %d.", (o), (t)); \
42 pst_parse_any (unsigned char **inbuf, unsigned char *inbufend)
45 unsigned char *cur = *inbuf;
48 while (cur < inbufend && !PST_TOKEN_END(cur, inbufend))
52 data = NEW(len+1, unsigned char);
53 memcpy(data, *inbuf, len);
57 return pst_new_obj(PST_TYPE_UNKNOWN, data);
61 skip_line (unsigned char **inbuf, unsigned char *inbufend)
63 while (*inbuf < inbufend && **inbuf != '\n' && **inbuf != '\r')
65 if (*inbuf < inbufend && **inbuf == '\r')
67 if (*inbuf < inbufend && **inbuf == '\n')
72 skip_comments (unsigned char **inbuf, unsigned char *inbufend)
74 while (*inbuf < inbufend && **inbuf == '%') {
75 skip_line(inbuf, inbufend);
76 skip_white_spaces(inbuf, inbufend);
82 pst_parse_comment (unsigned char **inbuf, unsigned char *inbufend)
85 unsigned char *cur = *inbuf;
91 while (cur < inbufend && *cur != '\n' && *cur != '\r')
94 data = NEW(len+1, unsigned char);
95 memcpy(data, *inbuf, len);
99 return pst_new_obj(PST_TYPE_UNKNOWN, data);
103 /* NOTE: the input buffer must be null-terminated, i.e., *inbufend == 0 */
105 pst_get_token (unsigned char **inbuf, unsigned char *inbufend)
110 ASSERT(*inbuf <= inbufend && !*inbufend);
112 skip_white_spaces(inbuf, inbufend);
113 skip_comments(inbuf, inbufend);
114 if (*inbuf >= inbufend)
120 obj = pst_parse_comment(inbuf, inbufend);
124 obj = pst_parse_name(inbuf, inbufend);
126 case '[': case '{': /* This is wrong */
127 obj = pst_new_mark();
131 if (*inbuf + 1 >= inbufend)
135 obj = pst_new_mark();
137 } else if (isxdigit(c))
138 obj = pst_parse_string(inbuf, inbufend);
139 else if (c == '~') /* ASCII85 */
140 obj = pst_parse_string(inbuf, inbufend);
143 obj = pst_parse_string(inbuf, inbufend);
146 if (*inbuf + 1 >= inbufend || *(*inbuf+1) != '>') {
147 ERROR("Unexpected end of ASCII hex string marker.");
152 mark[0] = '>'; mark[1] = '>'; mark[2] = '\0';
153 obj = pst_new_obj(PST_TYPE_UNKNOWN, mark);
162 mark[0] = c; mark[1] = '\0';
163 obj = pst_new_obj(PST_TYPE_UNKNOWN, mark);
168 if (c == 't' || c == 'f')
169 obj = pst_parse_boolean(inbuf, inbufend);
171 obj = pst_parse_null(inbuf, inbufend);
172 else if (c == '+' || c == '-' || isdigit(c) || c == '.')
173 obj = pst_parse_number(inbuf, inbufend);
178 obj = pst_parse_any(inbuf, inbufend);