]> git.wh0rd.org - fontconfig.git/blob - src/fcdbg.c
Various config changes plus a couple of optimizations from Owen
[fontconfig.git] / src / fcdbg.c
1 /*
2 * $XFree86: xc/lib/fontconfig/src/fcdbg.c,v 1.7 2002/08/11 18:10:42 keithp Exp $
3 *
4 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
5 *
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
15 *
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
23 */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include "fcint.h"
28
29 void
30 FcValuePrint (const FcValue v)
31 {
32 switch (v.type) {
33 case FcTypeVoid:
34 printf (" <void>");
35 break;
36 case FcTypeInteger:
37 printf (" %d", v.u.i);
38 break;
39 case FcTypeDouble:
40 printf (" %g", v.u.d);
41 break;
42 case FcTypeString:
43 printf (" \"%s\"", v.u.s);
44 break;
45 case FcTypeBool:
46 printf (" %s", v.u.b ? "FcTrue" : "FcFalse");
47 break;
48 case FcTypeMatrix:
49 printf (" (%f %f; %f %f)", v.u.m->xx, v.u.m->xy, v.u.m->yx, v.u.m->yy);
50 break;
51 case FcTypeCharSet: /* XXX */
52 printf (" set");
53 break;
54 case FcTypeFTFace:
55 printf (" face");
56 break;
57 }
58 }
59
60 void
61 FcValueListPrint (const FcValueList *l)
62 {
63 for (; l; l = l->next)
64 FcValuePrint (l->value);
65 }
66
67 void
68 FcPatternPrint (const FcPattern *p)
69 {
70 int i;
71 FcPatternElt *e;
72
73 if (!p)
74 {
75 printf ("Null pattern\n");
76 return;
77 }
78 printf ("Pattern %d of %d\n", p->num, p->size);
79 for (i = 0; i < p->num; i++)
80 {
81 e = &p->elts[i];
82 printf ("\t%s:", e->object);
83 FcValueListPrint (e->values);
84 printf ("\n");
85 }
86 printf ("\n");
87 }
88
89 void
90 FcOpPrint (FcOp op)
91 {
92 switch (op) {
93 case FcOpInteger: printf ("Integer"); break;
94 case FcOpDouble: printf ("Double"); break;
95 case FcOpString: printf ("String"); break;
96 case FcOpMatrix: printf ("Matrix"); break;
97 case FcOpBool: printf ("Bool"); break;
98 case FcOpCharSet: printf ("CharSet"); break;
99 case FcOpField: printf ("Field"); break;
100 case FcOpConst: printf ("Const"); break;
101 case FcOpAssign: printf ("Assign"); break;
102 case FcOpAssignReplace: printf ("AssignReplace"); break;
103 case FcOpPrepend: printf ("Prepend"); break;
104 case FcOpPrependFirst: printf ("PrependFirst"); break;
105 case FcOpAppend: printf ("Append"); break;
106 case FcOpAppendLast: printf ("AppendLast"); break;
107 case FcOpQuest: printf ("Quest"); break;
108 case FcOpOr: printf ("Or"); break;
109 case FcOpAnd: printf ("And"); break;
110 case FcOpEqual: printf ("Equal"); break;
111 case FcOpContains: printf ("Contains"); break;
112 case FcOpNotEqual: printf ("NotEqual"); break;
113 case FcOpLess: printf ("Less"); break;
114 case FcOpLessEqual: printf ("LessEqual"); break;
115 case FcOpMore: printf ("More"); break;
116 case FcOpMoreEqual: printf ("MoreEqual"); break;
117 case FcOpPlus: printf ("Plus"); break;
118 case FcOpMinus: printf ("Minus"); break;
119 case FcOpTimes: printf ("Times"); break;
120 case FcOpDivide: printf ("Divide"); break;
121 case FcOpNot: printf ("Not"); break;
122 case FcOpNil: printf ("Nil"); break;
123 case FcOpComma: printf ("Comma"); break;
124 case FcOpInvalid: printf ("Invalid"); break;
125 }
126 }
127
128 void
129 FcExprPrint (const FcExpr *expr)
130 {
131 switch (expr->op) {
132 case FcOpInteger: printf ("%d", expr->u.ival); break;
133 case FcOpDouble: printf ("%g", expr->u.dval); break;
134 case FcOpString: printf ("\"%s\"", expr->u.sval); break;
135 case FcOpMatrix: printf ("[%g %g %g %g]",
136 expr->u.mval->xx,
137 expr->u.mval->xy,
138 expr->u.mval->yx,
139 expr->u.mval->yy); break;
140 case FcOpBool: printf ("%s", expr->u.bval ? "true" : "false"); break;
141 case FcOpCharSet: printf ("charset\n"); break;
142 case FcOpNil: printf ("nil\n"); break;
143 case FcOpField: printf ("%s", expr->u.field); break;
144 case FcOpConst: printf ("%s", expr->u.constant); break;
145 case FcOpQuest:
146 FcExprPrint (expr->u.tree.left);
147 printf (" quest ");
148 FcExprPrint (expr->u.tree.right->u.tree.left);
149 printf (" colon ");
150 FcExprPrint (expr->u.tree.right->u.tree.right);
151 break;
152 case FcOpAssign:
153 case FcOpAssignReplace:
154 case FcOpPrependFirst:
155 case FcOpPrepend:
156 case FcOpAppend:
157 case FcOpAppendLast:
158 case FcOpOr:
159 case FcOpAnd:
160 case FcOpEqual:
161 case FcOpContains:
162 case FcOpNotEqual:
163 case FcOpLess:
164 case FcOpLessEqual:
165 case FcOpMore:
166 case FcOpMoreEqual:
167 case FcOpPlus:
168 case FcOpMinus:
169 case FcOpTimes:
170 case FcOpDivide:
171 case FcOpComma:
172 FcExprPrint (expr->u.tree.left);
173 printf (" ");
174 switch (expr->op) {
175 case FcOpAssign: printf ("Assign"); break;
176 case FcOpAssignReplace: printf ("AssignReplace"); break;
177 case FcOpPrependFirst: printf ("PrependFirst"); break;
178 case FcOpPrepend: printf ("Prepend"); break;
179 case FcOpAppend: printf ("Append"); break;
180 case FcOpAppendLast: printf ("AppendLast"); break;
181 case FcOpOr: printf ("Or"); break;
182 case FcOpAnd: printf ("And"); break;
183 case FcOpEqual: printf ("Equal"); break;
184 case FcOpContains: printf ("Contains"); break;
185 case FcOpNotEqual: printf ("NotEqual"); break;
186 case FcOpLess: printf ("Less"); break;
187 case FcOpLessEqual: printf ("LessEqual"); break;
188 case FcOpMore: printf ("More"); break;
189 case FcOpMoreEqual: printf ("MoreEqual"); break;
190 case FcOpPlus: printf ("Plus"); break;
191 case FcOpMinus: printf ("Minus"); break;
192 case FcOpTimes: printf ("Times"); break;
193 case FcOpDivide: printf ("Divide"); break;
194 case FcOpComma: printf ("Comma"); break;
195 default: break;
196 }
197 printf (" ");
198 FcExprPrint (expr->u.tree.right);
199 break;
200 case FcOpNot:
201 printf ("Not ");
202 FcExprPrint (expr->u.tree.left);
203 break;
204 case FcOpInvalid: printf ("Invalid"); break;
205 }
206 }
207
208 void
209 FcTestPrint (const FcTest *test)
210 {
211 switch (test->kind) {
212 case FcMatchPattern:
213 printf ("pattern ");
214 break;
215 case FcMatchFont:
216 printf ("font ");
217 break;
218 }
219 switch (test->qual) {
220 case FcQualAny:
221 printf ("any ");
222 break;
223 case FcQualAll:
224 printf ("all ");
225 break;
226 case FcQualFirst:
227 printf ("first ");
228 break;
229 case FcQualNotFirst:
230 printf ("not_first ");
231 break;
232 }
233 printf ("%s ", test->field);
234 FcOpPrint (test->op);
235 printf (" ");
236 FcExprPrint (test->expr);
237 printf ("\n");
238 }
239
240 void
241 FcEditPrint (const FcEdit *edit)
242 {
243 printf ("Edit %s ", edit->field);
244 FcOpPrint (edit->op);
245 printf (" ");
246 FcExprPrint (edit->expr);
247 }
248
249 void
250 FcSubstPrint (const FcSubst *subst)
251 {
252 FcEdit *e;
253 FcTest *t;
254
255 printf ("match\n");
256 for (t = subst->test; t; t = t->next)
257 {
258 printf ("\t");
259 FcTestPrint (t);
260 }
261 printf ("edit\n");
262 for (e = subst->edit; e; e = e->next)
263 {
264 printf ("\t");
265 FcEditPrint (e);
266 printf (";\n");
267 }
268 printf ("\n");
269 }
270
271 void
272 FcFontSetPrint (const FcFontSet *s)
273 {
274 int i;
275
276 printf ("FontSet %d of %d\n", s->nfont, s->sfont);
277 for (i = 0; i < s->nfont; i++)
278 {
279 printf ("Font %d ", i);
280 FcPatternPrint (s->fonts[i]);
281 }
282 }
283
284 int
285 FcDebug (void)
286 {
287 static int initialized;
288 static int debug;
289
290 if (!initialized)
291 {
292 char *e;
293
294 initialized = 1;
295 e = getenv ("FC_DEBUG");
296 if (e)
297 {
298 printf ("FC_DEBUG=%s\n", e);
299 debug = atoi (e);
300 if (debug < 0)
301 debug = 0;
302 }
303 }
304 return debug;
305 }