1
/* $Header: /home/cvsroot/dvipdfmx/src/otl_opt.c,v 1.4 2011/03/06 03:14:14 chofchof Exp $
3
This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
5
Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata,
6
the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
#endif /* _HAVE_CONFIG_H */
42
struct bt_node *right;
47
#define FLAG_NOT (1 << 0)
48
#define FLAG_AND (1 << 1)
50
static int match_expr (struct bt_node *expr, const char *key);
52
match_expr (struct bt_node *expr, const char *key)
58
if (!expr->left && !expr->right) {
59
for (i = 0; i < 4; i++) {
60
if (expr->data[i] != '?' &&
61
expr->data[i] != key[i]) {
68
retval = match_expr(expr->left, key);
71
if (retval && (expr->flag & FLAG_AND)) /* and */
72
retval &= match_expr(expr->right, key);
73
else if (!retval && !(expr->flag & FLAG_AND)) /* or */
74
retval = match_expr(expr->right, key);
77
if (expr->flag & FLAG_NOT) /* not */
78
retval = retval ? 0 : 1;
85
static struct bt_node *
90
expr = NEW(1, struct bt_node);
94
memset(expr->data, 0, 4);
99
static void bt_release_tree (struct bt_node *tree);
102
bt_release_tree (struct bt_node *tree)
106
bt_release_tree(tree->left);
108
bt_release_tree(tree->right);
113
static struct bt_node *
114
parse_expr (const char **pp, const char *endptr)
116
struct bt_node *root, *curr;
121
root = curr = bt_new_tree();
122
while (*pp < endptr) {
126
curr->flag &= ~FLAG_NOT;
128
curr->flag |= FLAG_NOT;
134
struct bt_node *expr;
136
expr = parse_expr(pp, endptr);
138
WARN("Syntax error: %s\n", *pp);
142
WARN("Syntax error: Unbalanced ()\n");
145
curr->left = expr->left;
146
curr->right = expr->right;
147
memcpy(curr->data, expr->data, 4);
151
WARN("Syntax error: Unbalanced ()\n");
152
bt_release_tree(root);
162
WARN("Syntax error: %s\n", *pp);
163
bt_release_tree(root);
170
tmp->right = curr = bt_new_tree();
180
memset(curr->data, '?', 4);
184
if (*pp + 4 <= endptr) {
187
for (i = 0; i < 4; i++) {
188
if (**pp == ' ' || **pp == '?' ||
189
isalpha(**pp) || isdigit(**pp))
190
curr->data[i] = **pp;
191
else if (**pp == '_')
194
WARN("Invalid char in tag: %c\n", **pp);
195
bt_release_tree(root);
201
WARN("Syntax error: %s\n", *pp);
202
bt_release_tree(root);
215
struct bt_node *rule;
223
opt = NEW(1, struct otl_opt);
226
return (otl_opt *) opt;
231
otl_release_opt (otl_opt *opt)
234
bt_release_tree(opt->rule);
249
struct lv_range *ranges;
253
range_cmp (const void *v1, const void *v2)
255
struct lv_range *sv1, *sv2;
257
sv1 = (struct lv_range *) v1;
258
sv2 = (struct lv_range *) v2;
260
if (sv1->start < sv2->start)
269
range_overlap (const void *v1, const void *v2)
271
struct lv_range *sv1, *sv2;
273
sv1 = (struct lv_range *) v1;
274
sv2 = (struct lv_range *) v2;
276
/* Must be first sort in increasing start order */
277
if (sv1->end >= sv2->start)
279
else if (sv1->end < sv2->start)
286
check_uc_coverage (struct uc_coverage *coverage)
288
struct lv_range *r1, *r2;
291
for (i = 0; i < coverage->count; i++) {
292
r1 = &coverage->ranges[i];
293
r2 = bsearch(r1, coverage->ranges,
294
coverage->count, sizeof(struct lv_range),
296
if (r2 && r1 != r2) {
297
WARN("Overlapping Unicode range found:");
298
WARN("[%x-%x], [%x-%x] ==> [%x-%x]",
299
r1->start, r1->end, r2->start, r2->end,
300
MIN(r1->start, r2->start), MAX(r1->end, r2->end));
301
r2->start = MIN(r1->start, r2->start);
302
r2->end = MAX(r1->end , r2->end );
303
if (i < coverage->count - 1) {
304
memmove(&coverage->ranges[i], &coverage->ranges[i+1],
305
(coverage->count - i - 1) * sizeof(struct lv_range));
306
coverage->count -= 1;
311
if (coverage->count == 0) {
312
RELEASE(coverage->ranges);
313
coverage->ranges = NULL;
319
otl_parse_optstring (otl_opt *opt, const char *optstr)
321
const char *p, *endptr;
327
endptr = p + strlen(optstr);
328
opt->rule = parse_expr(&p, endptr);
335
otl_match_optrule (otl_opt *opt, const char *tag)
339
if (!opt || !opt->rule)
342
return match_expr(opt->rule, tag);