]>
git.wh0rd.org - fontconfig.git/blob - src/fcformat.c
2 * Copyright © 2008 Red Hat, Inc.
4 * Red Hat Author(s): Behdad Esfahbod
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.
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.
32 message (const char *fmt
, ...)
36 fprintf (stderr
, "Fontconfig: ");
37 vfprintf (stderr
, fmt
, args
);
38 fprintf (stderr
, "\n");
43 static FcChar8
*scratch1
;
44 static FcChar8
*scratch2
;
45 static const FcChar8
*format_orig
;
47 static const FcChar8
*
48 interpret_percent (FcPattern
*pat
,
50 const FcChar8
*format
)
58 format
++; /* skip over '{' */
60 p
= (FcChar8
*) strpbrk ((const char *) format
, "}");
63 message ("Pattern format missing closing brace");
66 /* extract the element name */
67 memcpy (scratch1
, format
, p
- format
);
68 scratch1
[p
- format
] = '\0';
70 e
= FcPatternObjectFindElt (pat
, FcObjectFromName ((const char *) scratch1
));
74 l
= FcPatternEltValues(e
);
75 FcNameUnparseValueList (buf
, l
, '\0');
78 p
++; /* skip over '}' */
82 message ("Pattern format has invalid character after '%%' at %d",
83 format
- format_orig
);
88 static char escaped_char(const char ch
)
91 case 'a': return '\a';
92 case 'b': return '\b';
93 case 'f': return '\f';
94 case 'n': return '\n';
95 case 'r': return '\r';
96 case 't': return '\t';
97 case 'v': return '\v';
102 static const FcChar8
*
103 interpret (FcPattern
*pat
,
105 const FcChar8
*format
,
110 for (end
= format
; *end
&& *end
!= term
;)
115 end
++; /* skip over '\\' */
116 FcStrBufChar (buf
, escaped_char (*end
++));
119 end
++; /* skip over '%' */
122 end
= interpret_percent (pat
, buf
, end
);
125 FcStrBufChar (buf
, *end
);
129 message ("Pattern format ended while looking for '%c'", term
);
135 FcPatternFormat (FcPattern
*pat
, const FcChar8
*format
)
140 FcStrBufInit (&buf
, 0, 0);
141 len
= strlen ((const char *) format
);
142 scratch1
= malloc (len
);
143 scratch2
= malloc (len
);
144 format_orig
= format
;
146 interpret (pat
, &buf
, format
, '\0');
150 return FcStrBufDone (&buf
);
154 #include "fcaliastail.h"