12c393a42Smrg/*
2a6844aabSmrg * fontconfig/src/fcdbg.c
32c393a42Smrg *
42c393a42Smrg * Copyright © 2000 Keith Packard
52c393a42Smrg *
62c393a42Smrg * Permission to use, copy, modify, distribute, and sell this software and its
72c393a42Smrg * documentation for any purpose is hereby granted without fee, provided that
82c393a42Smrg * the above copyright notice appear in all copies and that both that
92c393a42Smrg * copyright notice and this permission notice appear in supporting
10ca08ab68Smrg * documentation, and that the name of the author(s) not be used in
112c393a42Smrg * advertising or publicity pertaining to distribution of the software without
12ca08ab68Smrg * specific, written prior permission.  The authors make no
132c393a42Smrg * representations about the suitability of this software for any purpose.  It
142c393a42Smrg * is provided "as is" without express or implied warranty.
152c393a42Smrg *
16a6844aabSmrg * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
172c393a42Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18a6844aabSmrg * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
192c393a42Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
202c393a42Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
212c393a42Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
222c393a42Smrg * PERFORMANCE OF THIS SOFTWARE.
232c393a42Smrg */
242c393a42Smrg
252c393a42Smrg#include "fcint.h"
262c393a42Smrg#include <stdio.h>
272c393a42Smrg#include <stdlib.h>
282c393a42Smrg
29ca08ab68Smrgstatic void
30c9710b42Smrg_FcValuePrintFile (FILE *f, const FcValue v)
312c393a42Smrg{
322c393a42Smrg    switch (v.type) {
336fc018e4Smrg    case FcTypeUnknown:
346fc018e4Smrg	fprintf (f, "<unknown>");
356fc018e4Smrg	break;
362c393a42Smrg    case FcTypeVoid:
37c9710b42Smrg	fprintf (f, "<void>");
382c393a42Smrg	break;
392c393a42Smrg    case FcTypeInteger:
40c9710b42Smrg	fprintf (f, "%d(i)", v.u.i);
412c393a42Smrg	break;
422c393a42Smrg    case FcTypeDouble:
43c9710b42Smrg	fprintf (f, "%g(f)", v.u.d);
442c393a42Smrg	break;
452c393a42Smrg    case FcTypeString:
46c9710b42Smrg	fprintf (f, "\"%s\"", v.u.s);
472c393a42Smrg	break;
482c393a42Smrg    case FcTypeBool:
49a32e9e42Smrg	fprintf (f,
50a32e9e42Smrg		 v.u.b == FcTrue  ? "True" :
51a32e9e42Smrg		 v.u.b == FcFalse ? "False" :
52a32e9e42Smrg				    "DontCare");
532c393a42Smrg	break;
542c393a42Smrg    case FcTypeMatrix:
55c9710b42Smrg	fprintf (f, "[%g %g; %g %g]", v.u.m->xx, v.u.m->xy, v.u.m->yx, v.u.m->yy);
562c393a42Smrg	break;
572c393a42Smrg    case FcTypeCharSet:	/* XXX */
58c9710b42Smrg	if (f == stdout)
59c9710b42Smrg	    FcCharSetPrint (v.u.c);
602c393a42Smrg	break;
612c393a42Smrg    case FcTypeLangSet:
622c393a42Smrg	FcLangSetPrint (v.u.l);
632c393a42Smrg	break;
642c393a42Smrg    case FcTypeFTFace:
65c9710b42Smrg	fprintf (f, "face");
662c393a42Smrg	break;
67953daebaSmrg    case FcTypeRange:
68a32e9e42Smrg	fprintf (f, "[%g %g]", v.u.r->begin, v.u.r->end);
69953daebaSmrg	break;
702c393a42Smrg    }
712c393a42Smrg}
722c393a42Smrg
73c9710b42Smrgvoid
74c9710b42SmrgFcValuePrintFile (FILE *f, const FcValue v)
75c9710b42Smrg{
76c9710b42Smrg    fprintf (f, " ");
77c9710b42Smrg    _FcValuePrintFile (f, v);
78c9710b42Smrg}
79c9710b42Smrg
80ca08ab68Smrgvoid
81ca08ab68SmrgFcValuePrint (const FcValue v)
82ca08ab68Smrg{
83ca08ab68Smrg    printf (" ");
84c9710b42Smrg    _FcValuePrintFile (stdout, v);
85ca08ab68Smrg}
86ca08ab68Smrg
87ca08ab68Smrgvoid
88ca08ab68SmrgFcValuePrintWithPosition (const FcValue v, FcBool show_pos_mark)
89ca08ab68Smrg{
90ca08ab68Smrg    if (show_pos_mark)
91c9710b42Smrg	printf (" [marker] ");
92ca08ab68Smrg    else
93ca08ab68Smrg	printf (" ");
94c9710b42Smrg    _FcValuePrintFile (stdout, v);
95ca08ab68Smrg}
96ca08ab68Smrg
97ca08ab68Smrgstatic void
98ca08ab68SmrgFcValueBindingPrint (const FcValueListPtr l)
99ca08ab68Smrg{
100ca08ab68Smrg    switch (l->binding) {
101ca08ab68Smrg    case FcValueBindingWeak:
102ca08ab68Smrg	printf ("(w)");
103ca08ab68Smrg	break;
104ca08ab68Smrg    case FcValueBindingStrong:
105ca08ab68Smrg	printf ("(s)");
106ca08ab68Smrg	break;
107ca08ab68Smrg    case FcValueBindingSame:
108ca08ab68Smrg	printf ("(=)");
109ca08ab68Smrg	break;
1106fc018e4Smrg    default:
1116fc018e4Smrg	/* shouldn't be reached */
1126fc018e4Smrg	printf ("(?)");
1136fc018e4Smrg	break;
114ca08ab68Smrg    }
115ca08ab68Smrg}
116ca08ab68Smrg
117ca08ab68Smrgvoid
118ca08ab68SmrgFcValueListPrintWithPosition (FcValueListPtr l, const FcValueListPtr pos)
119ca08ab68Smrg{
120ca08ab68Smrg    for (; l != NULL; l = FcValueListNext(l))
121ca08ab68Smrg    {
122ca08ab68Smrg	FcValuePrintWithPosition (FcValueCanonicalize (&l->value), pos != NULL && l == pos);
123ca08ab68Smrg	FcValueBindingPrint (l);
124ca08ab68Smrg    }
125ca08ab68Smrg    if (!pos)
126c9710b42Smrg	printf (" [marker]");
127ca08ab68Smrg}
128ca08ab68Smrg
1292c393a42Smrgvoid
1302c393a42SmrgFcValueListPrint (FcValueListPtr l)
1312c393a42Smrg{
1322c393a42Smrg    for (; l != NULL; l = FcValueListNext(l))
1332c393a42Smrg    {
134ca08ab68Smrg	FcValuePrint (FcValueCanonicalize (&l->value));
135ca08ab68Smrg	FcValueBindingPrint (l);
1362c393a42Smrg    }
1372c393a42Smrg}
1382c393a42Smrg
1392c393a42Smrgvoid
1402c393a42SmrgFcLangSetPrint (const FcLangSet *ls)
1412c393a42Smrg{
1422c393a42Smrg    FcStrBuf	buf;
1432c393a42Smrg    FcChar8	init_buf[1024];
144ca08ab68Smrg
1452c393a42Smrg    FcStrBufInit (&buf, init_buf, sizeof (init_buf));
1462c393a42Smrg    if (FcNameUnparseLangSet (&buf, ls) && FcStrBufChar (&buf,'\0'))
1472c393a42Smrg       printf ("%s", buf.buf);
1482c393a42Smrg    else
1492c393a42Smrg       printf ("langset (alloc error)");
1502c393a42Smrg    FcStrBufDestroy (&buf);
1512c393a42Smrg}
1522c393a42Smrg
1532c393a42Smrgvoid
1542c393a42SmrgFcCharSetPrint (const FcCharSet *c)
1552c393a42Smrg{
1562c393a42Smrg    int	i, j;
1572c393a42Smrg    intptr_t	*leaves = FcCharSetLeaves (c);
1582c393a42Smrg    FcChar16	*numbers = FcCharSetNumbers (c);
159ca08ab68Smrg
1602c393a42Smrg#if 0
1612c393a42Smrg    printf ("CharSet  0x%x\n", (intptr_t) c);
1622c393a42Smrg    printf ("Leaves:  +%d = 0x%x\n", c->leaves_offset, (intptr_t) leaves);
1632c393a42Smrg    printf ("Numbers: +%d = 0x%x\n", c->numbers_offset, (intptr_t) numbers);
164ca08ab68Smrg
1652c393a42Smrg    for (i = 0; i < c->num; i++)
1662c393a42Smrg    {
167ca08ab68Smrg	printf ("Page %d: %04x +%d = 0x%x\n",
168ca08ab68Smrg		i, numbers[i], leaves[i],
1692c393a42Smrg		(intptr_t) FcOffsetToPtr (leaves, leaves[i], FcCharLeaf));
1702c393a42Smrg    }
1712c393a42Smrg#endif
1722c393a42Smrg
173a6844aabSmrg    printf ("\n");
1742c393a42Smrg    for (i = 0; i < c->num; i++)
1752c393a42Smrg    {
1762c393a42Smrg	intptr_t	leaf_offset = leaves[i];
1772c393a42Smrg	FcCharLeaf	*leaf = FcOffsetToPtr (leaves, leaf_offset, FcCharLeaf);
1782c393a42Smrg
179a6844aabSmrg	printf ("\t");
1802c393a42Smrg	printf ("%04x:", numbers[i]);
1812c393a42Smrg	for (j = 0; j < 256/32; j++)
1822c393a42Smrg	    printf (" %08x", leaf->map[j]);
1832c393a42Smrg	printf ("\n");
1842c393a42Smrg    }
1852c393a42Smrg}
1862c393a42Smrg
1872c393a42Smrgvoid
1882c393a42SmrgFcPatternPrint (const FcPattern *p)
1892c393a42Smrg{
190a32e9e42Smrg    FcPatternIter iter;
191ca08ab68Smrg
1922c393a42Smrg    if (!p)
1932c393a42Smrg    {
1942c393a42Smrg	printf ("Null pattern\n");
1952c393a42Smrg	return;
1962c393a42Smrg    }
197a32e9e42Smrg    printf ("Pattern has %d elts (size %d)\n", FcPatternObjectCount (p), p->size);
198a32e9e42Smrg    FcPatternIterStart (p, &iter);
199a32e9e42Smrg    do
2002c393a42Smrg    {
201a32e9e42Smrg	printf ("\t%s:", FcPatternIterGetObject (p, &iter));
202a32e9e42Smrg	FcValueListPrint (FcPatternIterGetValues (p, &iter));
2032c393a42Smrg	printf ("\n");
204a32e9e42Smrg    } while (FcPatternIterNext (p, &iter));
2052c393a42Smrg    printf ("\n");
2062c393a42Smrg}
2072c393a42Smrg
208ca08ab68Smrg#define FcOpFlagsPrint(_o_)		\
209ca08ab68Smrg    {					\
210ca08ab68Smrg	int f = FC_OP_GET_FLAGS (_o_);	\
211ca08ab68Smrg	if (f & FcOpFlagIgnoreBlanks)	\
212ca08ab68Smrg	    printf ("(ignore blanks)");	\
213ca08ab68Smrg    }
214ca08ab68Smrg
215953daebaSmrgvoid
216953daebaSmrgFcPatternPrint2 (FcPattern         *pp1,
217953daebaSmrg		 FcPattern         *pp2,
218953daebaSmrg		 const FcObjectSet *os)
219953daebaSmrg{
220953daebaSmrg    int i, j, k, pos;
221953daebaSmrg    FcPatternElt *e1, *e2;
222953daebaSmrg    FcPattern *p1, *p2;
223953daebaSmrg
224953daebaSmrg    if (os)
225953daebaSmrg    {
226953daebaSmrg	p1 = FcPatternFilter (pp1, os);
227953daebaSmrg	p2 = FcPatternFilter (pp2, os);
228953daebaSmrg    }
229953daebaSmrg    else
230953daebaSmrg    {
231953daebaSmrg	p1 = pp1;
232953daebaSmrg	p2 = pp2;
233953daebaSmrg    }
234953daebaSmrg    printf ("Pattern has %d elts (size %d), %d elts (size %d)\n",
235953daebaSmrg	    p1->num, p1->size, p2->num, p2->size);
236953daebaSmrg    for (i = 0, j = 0; i < p1->num; i++)
237953daebaSmrg    {
238953daebaSmrg	e1 = &FcPatternElts(p1)[i];
239953daebaSmrg	e2 = &FcPatternElts(p2)[j];
240953daebaSmrg	if (!e2 || e1->object != e2->object)
241953daebaSmrg	{
242953daebaSmrg	    pos = FcPatternPosition (p2, FcObjectName (e1->object));
243953daebaSmrg	    if (pos >= 0)
244953daebaSmrg	    {
245953daebaSmrg		for (k = j; k < pos; k++)
246953daebaSmrg		{
247953daebaSmrg		    e2 = &FcPatternElts(p2)[k];
248953daebaSmrg		    printf ("\t%s: (None) -> ", FcObjectName (e2->object));
249953daebaSmrg		    FcValueListPrint (FcPatternEltValues (e2));
250953daebaSmrg		    printf ("\n");
251953daebaSmrg		}
252953daebaSmrg		j = pos;
253953daebaSmrg		goto cont;
254953daebaSmrg	    }
255953daebaSmrg	    else
256953daebaSmrg	    {
257953daebaSmrg		printf ("\t%s:", FcObjectName (e1->object));
258953daebaSmrg		FcValueListPrint (FcPatternEltValues (e1));
259953daebaSmrg		printf (" -> (None)\n");
260953daebaSmrg	    }
261953daebaSmrg	}
262953daebaSmrg	else
263953daebaSmrg	{
264953daebaSmrg	cont:
265953daebaSmrg	    printf ("\t%s:", FcObjectName (e1->object));
266953daebaSmrg	    FcValueListPrint (FcPatternEltValues (e1));
267953daebaSmrg	    printf (" -> ");
268953daebaSmrg	    e2 = &FcPatternElts(p2)[j];
269953daebaSmrg	    FcValueListPrint (FcPatternEltValues (e2));
270953daebaSmrg	    printf ("\n");
271953daebaSmrg	    j++;
272953daebaSmrg	}
273953daebaSmrg    }
274953daebaSmrg    if (j < p2->num)
275953daebaSmrg    {
276953daebaSmrg	for (k = j; k < p2->num; k++)
277953daebaSmrg	{
278953daebaSmrg	    e2 = &FcPatternElts(p2)[k];
279953daebaSmrg	    if (FcObjectName (e2->object))
280953daebaSmrg	    {
281953daebaSmrg		printf ("\t%s: (None) -> ", FcObjectName (e2->object));
282953daebaSmrg		FcValueListPrint (FcPatternEltValues (e2));
283953daebaSmrg		printf ("\n");
284953daebaSmrg	    }
285953daebaSmrg	}
286953daebaSmrg    }
287953daebaSmrg    if (p1 != pp1)
288953daebaSmrg	FcPatternDestroy (p1);
289953daebaSmrg    if (p2 != pp2)
290953daebaSmrg	FcPatternDestroy (p2);
291953daebaSmrg}
292953daebaSmrg
2932c393a42Smrgvoid
294ca08ab68SmrgFcOpPrint (FcOp op_)
2952c393a42Smrg{
296ca08ab68Smrg    FcOp op = FC_OP_GET_OP (op_);
297ca08ab68Smrg
2982c393a42Smrg    switch (op) {
2992c393a42Smrg    case FcOpInteger: printf ("Integer"); break;
3002c393a42Smrg    case FcOpDouble: printf ("Double"); break;
3012c393a42Smrg    case FcOpString: printf ("String"); break;
3022c393a42Smrg    case FcOpMatrix: printf ("Matrix"); break;
303ca08ab68Smrg    case FcOpRange: printf ("Range"); break;
3042c393a42Smrg    case FcOpBool: printf ("Bool"); break;
3052c393a42Smrg    case FcOpCharSet: printf ("CharSet"); break;
306ca08ab68Smrg    case FcOpLangSet: printf ("LangSet"); break;
3072c393a42Smrg    case FcOpField: printf ("Field"); break;
3082c393a42Smrg    case FcOpConst: printf ("Const"); break;
3092c393a42Smrg    case FcOpAssign: printf ("Assign"); break;
3102c393a42Smrg    case FcOpAssignReplace: printf ("AssignReplace"); break;
3112c393a42Smrg    case FcOpPrepend: printf ("Prepend"); break;
3122c393a42Smrg    case FcOpPrependFirst: printf ("PrependFirst"); break;
3132c393a42Smrg    case FcOpAppend: printf ("Append"); break;
3142c393a42Smrg    case FcOpAppendLast: printf ("AppendLast"); break;
315c9710b42Smrg    case FcOpDelete: printf ("Delete"); break;
316c9710b42Smrg    case FcOpDeleteAll: printf ("DeleteAll"); break;
3172c393a42Smrg    case FcOpQuest: printf ("Quest"); break;
3182c393a42Smrg    case FcOpOr: printf ("Or"); break;
3192c393a42Smrg    case FcOpAnd: printf ("And"); break;
320ca08ab68Smrg    case FcOpEqual: printf ("Equal"); FcOpFlagsPrint (op_); break;
321ca08ab68Smrg    case FcOpNotEqual: printf ("NotEqual"); FcOpFlagsPrint (op_); break;
3222c393a42Smrg    case FcOpLess: printf ("Less"); break;
3232c393a42Smrg    case FcOpLessEqual: printf ("LessEqual"); break;
3242c393a42Smrg    case FcOpMore: printf ("More"); break;
3252c393a42Smrg    case FcOpMoreEqual: printf ("MoreEqual"); break;
3262c393a42Smrg    case FcOpContains: printf ("Contains"); break;
3272c393a42Smrg    case FcOpNotContains: printf ("NotContains"); break;
3282c393a42Smrg    case FcOpPlus: printf ("Plus"); break;
3292c393a42Smrg    case FcOpMinus: printf ("Minus"); break;
3302c393a42Smrg    case FcOpTimes: printf ("Times"); break;
3312c393a42Smrg    case FcOpDivide: printf ("Divide"); break;
3322c393a42Smrg    case FcOpNot: printf ("Not"); break;
3332c393a42Smrg    case FcOpNil: printf ("Nil"); break;
3342c393a42Smrg    case FcOpComma: printf ("Comma"); break;
3352c393a42Smrg    case FcOpFloor: printf ("Floor"); break;
3362c393a42Smrg    case FcOpCeil: printf ("Ceil"); break;
3372c393a42Smrg    case FcOpRound: printf ("Round"); break;
3382c393a42Smrg    case FcOpTrunc: printf ("Trunc"); break;
339ca08ab68Smrg    case FcOpListing: printf ("Listing"); FcOpFlagsPrint (op_); break;
3402c393a42Smrg    case FcOpInvalid: printf ("Invalid"); break;
3412c393a42Smrg    }
3422c393a42Smrg}
3432c393a42Smrg
3442c393a42Smrgvoid
3452c393a42SmrgFcExprPrint (const FcExpr *expr)
3462c393a42Smrg{
3472c393a42Smrg    if (!expr) printf ("none");
348ca08ab68Smrg    else switch (FC_OP_GET_OP (expr->op)) {
3492c393a42Smrg    case FcOpInteger: printf ("%d", expr->u.ival); break;
3502c393a42Smrg    case FcOpDouble: printf ("%g", expr->u.dval); break;
3512c393a42Smrg    case FcOpString: printf ("\"%s\"", expr->u.sval); break;
352c9710b42Smrg    case FcOpMatrix:
353c9710b42Smrg	printf ("[");
354c9710b42Smrg	FcExprPrint (expr->u.mexpr->xx);
355c9710b42Smrg	printf (" ");
356c9710b42Smrg	FcExprPrint (expr->u.mexpr->xy);
357c9710b42Smrg	printf ("; ");
358c9710b42Smrg	FcExprPrint (expr->u.mexpr->yx);
359c9710b42Smrg	printf (" ");
360c9710b42Smrg	FcExprPrint (expr->u.mexpr->yy);
361c9710b42Smrg	printf ("]");
362c9710b42Smrg	break;
363953daebaSmrg    case FcOpRange:
364953daebaSmrg	printf ("(%g, %g)", expr->u.rval->begin, expr->u.rval->end);
365953daebaSmrg	break;
3662c393a42Smrg    case FcOpBool: printf ("%s", expr->u.bval ? "true" : "false"); break;
3672c393a42Smrg    case FcOpCharSet: printf ("charset\n"); break;
368ca08ab68Smrg    case FcOpLangSet:
369ca08ab68Smrg	printf ("langset:");
370ca08ab68Smrg	FcLangSetPrint(expr->u.lval);
371ca08ab68Smrg	printf ("\n");
372ca08ab68Smrg	break;
3732c393a42Smrg    case FcOpNil: printf ("nil\n"); break;
374c9710b42Smrg    case FcOpField: printf ("%s ", FcObjectName(expr->u.name.object));
375c9710b42Smrg      switch ((int) expr->u.name.kind) {
376c9710b42Smrg      case FcMatchPattern:
377c9710b42Smrg	  printf ("(pattern) ");
378c9710b42Smrg	  break;
379c9710b42Smrg      case FcMatchFont:
380c9710b42Smrg	  printf ("(font) ");
381c9710b42Smrg	  break;
382c9710b42Smrg      }
383c9710b42Smrg      break;
3842c393a42Smrg    case FcOpConst: printf ("%s", expr->u.constant); break;
3852c393a42Smrg    case FcOpQuest:
3862c393a42Smrg	FcExprPrint (expr->u.tree.left);
3872c393a42Smrg	printf (" quest ");
3882c393a42Smrg	FcExprPrint (expr->u.tree.right->u.tree.left);
3892c393a42Smrg	printf (" colon ");
3902c393a42Smrg	FcExprPrint (expr->u.tree.right->u.tree.right);
3912c393a42Smrg	break;
3922c393a42Smrg    case FcOpAssign:
3932c393a42Smrg    case FcOpAssignReplace:
3942c393a42Smrg    case FcOpPrependFirst:
3952c393a42Smrg    case FcOpPrepend:
3962c393a42Smrg    case FcOpAppend:
3972c393a42Smrg    case FcOpAppendLast:
3982c393a42Smrg    case FcOpOr:
3992c393a42Smrg    case FcOpAnd:
4002c393a42Smrg    case FcOpEqual:
4012c393a42Smrg    case FcOpNotEqual:
4022c393a42Smrg    case FcOpLess:
4032c393a42Smrg    case FcOpLessEqual:
4042c393a42Smrg    case FcOpMore:
4052c393a42Smrg    case FcOpMoreEqual:
4062c393a42Smrg    case FcOpContains:
4072c393a42Smrg    case FcOpListing:
4082c393a42Smrg    case FcOpNotContains:
4092c393a42Smrg    case FcOpPlus:
4102c393a42Smrg    case FcOpMinus:
4112c393a42Smrg    case FcOpTimes:
4122c393a42Smrg    case FcOpDivide:
4132c393a42Smrg    case FcOpComma:
4142c393a42Smrg	FcExprPrint (expr->u.tree.left);
4152c393a42Smrg	printf (" ");
416ca08ab68Smrg	switch (FC_OP_GET_OP (expr->op)) {
4172c393a42Smrg	case FcOpAssign: printf ("Assign"); break;
4182c393a42Smrg	case FcOpAssignReplace: printf ("AssignReplace"); break;
4192c393a42Smrg	case FcOpPrependFirst: printf ("PrependFirst"); break;
4202c393a42Smrg	case FcOpPrepend: printf ("Prepend"); break;
4212c393a42Smrg	case FcOpAppend: printf ("Append"); break;
4222c393a42Smrg	case FcOpAppendLast: printf ("AppendLast"); break;
4232c393a42Smrg	case FcOpOr: printf ("Or"); break;
4242c393a42Smrg	case FcOpAnd: printf ("And"); break;
425ca08ab68Smrg	case FcOpEqual: printf ("Equal"); FcOpFlagsPrint (expr->op); break;
426ca08ab68Smrg	case FcOpNotEqual: printf ("NotEqual"); FcOpFlagsPrint (expr->op); break;
4272c393a42Smrg	case FcOpLess: printf ("Less"); break;
4282c393a42Smrg	case FcOpLessEqual: printf ("LessEqual"); break;
4292c393a42Smrg	case FcOpMore: printf ("More"); break;
4302c393a42Smrg	case FcOpMoreEqual: printf ("MoreEqual"); break;
4312c393a42Smrg	case FcOpContains: printf ("Contains"); break;
432ca08ab68Smrg	case FcOpListing: printf ("Listing"); FcOpFlagsPrint (expr->op); break;
4332c393a42Smrg	case FcOpNotContains: printf ("NotContains"); break;
4342c393a42Smrg	case FcOpPlus: printf ("Plus"); break;
4352c393a42Smrg	case FcOpMinus: printf ("Minus"); break;
4362c393a42Smrg	case FcOpTimes: printf ("Times"); break;
4372c393a42Smrg	case FcOpDivide: printf ("Divide"); break;
4382c393a42Smrg	case FcOpComma: printf ("Comma"); break;
4392c393a42Smrg	default: break;
4402c393a42Smrg	}
4412c393a42Smrg	printf (" ");
4422c393a42Smrg	FcExprPrint (expr->u.tree.right);
4432c393a42Smrg	break;
4442c393a42Smrg    case FcOpNot:
4452c393a42Smrg	printf ("Not ");
4462c393a42Smrg	FcExprPrint (expr->u.tree.left);
4472c393a42Smrg	break;
4482c393a42Smrg    case FcOpFloor:
4492c393a42Smrg	printf ("Floor ");
4502c393a42Smrg	FcExprPrint (expr->u.tree.left);
4512c393a42Smrg	break;
4522c393a42Smrg    case FcOpCeil:
4532c393a42Smrg	printf ("Ceil ");
4542c393a42Smrg	FcExprPrint (expr->u.tree.left);
4552c393a42Smrg	break;
4562c393a42Smrg    case FcOpRound:
4572c393a42Smrg	printf ("Round ");
4582c393a42Smrg	FcExprPrint (expr->u.tree.left);
4592c393a42Smrg	break;
4602c393a42Smrg    case FcOpTrunc:
4612c393a42Smrg	printf ("Trunc ");
4622c393a42Smrg	FcExprPrint (expr->u.tree.left);
4632c393a42Smrg	break;
4642c393a42Smrg    case FcOpInvalid: printf ("Invalid"); break;
4652c393a42Smrg    }
4662c393a42Smrg}
4672c393a42Smrg
4682c393a42Smrgvoid
4692c393a42SmrgFcTestPrint (const FcTest *test)
4702c393a42Smrg{
4712c393a42Smrg    switch (test->kind) {
4722c393a42Smrg    case FcMatchPattern:
4732c393a42Smrg	printf ("pattern ");
4742c393a42Smrg	break;
4752c393a42Smrg    case FcMatchFont:
4762c393a42Smrg	printf ("font ");
4772c393a42Smrg	break;
4782c393a42Smrg    case FcMatchScan:
4792c393a42Smrg	printf ("scan ");
4802c393a42Smrg	break;
481a32e9e42Smrg    case FcMatchKindEnd:
482a32e9e42Smrg	/* shouldn't be reached */
483a32e9e42Smrg	return;
4842c393a42Smrg    }
4852c393a42Smrg    switch (test->qual) {
4862c393a42Smrg    case FcQualAny:
4872c393a42Smrg	printf ("any ");
4882c393a42Smrg	break;
4892c393a42Smrg    case FcQualAll:
4902c393a42Smrg	printf ("all ");
4912c393a42Smrg	break;
4922c393a42Smrg    case FcQualFirst:
4932c393a42Smrg	printf ("first ");
4942c393a42Smrg	break;
4952c393a42Smrg    case FcQualNotFirst:
4962c393a42Smrg	printf ("not_first ");
4972c393a42Smrg	break;
4982c393a42Smrg    }
4992c393a42Smrg    printf ("%s ", FcObjectName (test->object));
5002c393a42Smrg    FcOpPrint (test->op);
5012c393a42Smrg    printf (" ");
5022c393a42Smrg    FcExprPrint (test->expr);
5032c393a42Smrg    printf ("\n");
5042c393a42Smrg}
5052c393a42Smrg
5062c393a42Smrgvoid
5072c393a42SmrgFcEditPrint (const FcEdit *edit)
5082c393a42Smrg{
5092c393a42Smrg    printf ("Edit %s ", FcObjectName (edit->object));
5102c393a42Smrg    FcOpPrint (edit->op);
5112c393a42Smrg    printf (" ");
5122c393a42Smrg    FcExprPrint (edit->expr);
5132c393a42Smrg}
5142c393a42Smrg
5152c393a42Smrgvoid
516a32e9e42SmrgFcRulePrint (const FcRule *rule)
5172c393a42Smrg{
5186fc018e4Smrg    FcRuleType last_type = FcRuleUnknown;
519a32e9e42Smrg    const FcRule *r;
520ca08ab68Smrg
521a32e9e42Smrg    for (r = rule; r; r = r->next)
5222c393a42Smrg    {
5236fc018e4Smrg	if (last_type != r->type)
5246fc018e4Smrg	{
5256fc018e4Smrg	    switch (r->type) {
5266fc018e4Smrg	    case FcRuleTest:
5276fc018e4Smrg		printf ("[test]\n");
5286fc018e4Smrg		break;
5296fc018e4Smrg	    case FcRuleEdit:
5306fc018e4Smrg		printf ("[edit]\n");
5316fc018e4Smrg		break;
5326fc018e4Smrg	    default:
5336fc018e4Smrg		break;
5346fc018e4Smrg	    }
5356fc018e4Smrg	    last_type = r->type;
5366fc018e4Smrg	}
5372c393a42Smrg	printf ("\t");
5386fc018e4Smrg	switch (r->type) {
5396fc018e4Smrg	case FcRuleTest:
5406fc018e4Smrg	    FcTestPrint (r->u.test);
5416fc018e4Smrg	    break;
5426fc018e4Smrg	case FcRuleEdit:
5436fc018e4Smrg	    FcEditPrint (r->u.edit);
5446fc018e4Smrg	    printf (";\n");
5456fc018e4Smrg	    break;
5466fc018e4Smrg	default:
5476fc018e4Smrg	    break;
5486fc018e4Smrg	}
5492c393a42Smrg    }
5502c393a42Smrg    printf ("\n");
5512c393a42Smrg}
5522c393a42Smrg
5532c393a42Smrgvoid
5542c393a42SmrgFcFontSetPrint (const FcFontSet *s)
5552c393a42Smrg{
5562c393a42Smrg    int	    i;
5572c393a42Smrg
5582c393a42Smrg    printf ("FontSet %d of %d\n", s->nfont, s->sfont);
5592c393a42Smrg    for (i = 0; i < s->nfont; i++)
5602c393a42Smrg    {
5612c393a42Smrg	printf ("Font %d ", i);
5622c393a42Smrg	FcPatternPrint (s->fonts[i]);
5632c393a42Smrg    }
5642c393a42Smrg}
5652c393a42Smrg
5662c393a42Smrgint FcDebugVal;
5672c393a42Smrg
5682c393a42Smrgvoid
5692c393a42SmrgFcInitDebug (void)
5702c393a42Smrg{
571c9710b42Smrg    if (!FcDebugVal) {
572c9710b42Smrg	char    *e;
5732c393a42Smrg
574c9710b42Smrg	e = getenv ("FC_DEBUG");
575c9710b42Smrg	if (e)
576c9710b42Smrg	{
577c9710b42Smrg	    printf ("FC_DEBUG=%s\n", e);
578c9710b42Smrg	    FcDebugVal = atoi (e);
579c9710b42Smrg	    if (FcDebugVal < 0)
580c9710b42Smrg		FcDebugVal = 0;
581c9710b42Smrg	}
5822c393a42Smrg    }
5832c393a42Smrg}
5842c393a42Smrg#define __fcdbg__
5852c393a42Smrg#include "fcaliastail.h"
5862c393a42Smrg#undef __fcdbg__
587