]>
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
)
54 /* parse an optional width specifier */
55 width
= strtol (format
, (char **) &format
, 10);
65 format
++; /* skip over '{' */
67 p
= (FcChar8
*) strpbrk ((const char *) format
, "}");
70 message ("Pattern format missing closing brace");
73 /* extract the element name */
74 memcpy (scratch1
, format
, p
- format
);
75 scratch1
[p
- format
] = '\0';
77 e
= FcPatternObjectFindElt (pat
, FcObjectFromName ((const char *) scratch1
));
81 l
= FcPatternEltValues(e
);
82 FcNameUnparseValueList (buf
, l
, '\0');
85 p
++; /* skip over '}' */
90 message ("Pattern format has invalid character after '%%' at %d",
91 format
- format_orig
);
102 len
= after
- before
;
107 while (len
++ < -width
)
108 FcStrBufChar (buf
, ' ');
110 else if (len
< width
)
113 while (len
++ < width
)
114 FcStrBufChar (buf
, ' ');
115 len
= after
- before
;
116 memmove (buf
->buf
+ buf
->len
- len
,
117 buf
->buf
+ buf
->len
- width
,
119 memset (buf
->buf
+ buf
->len
- width
,
128 static char escaped_char(const char ch
)
131 case 'a': return '\a';
132 case 'b': return '\b';
133 case 'f': return '\f';
134 case 'n': return '\n';
135 case 'r': return '\r';
136 case 't': return '\t';
137 case 'v': return '\v';
142 static const FcChar8
*
143 interpret (FcPattern
*pat
,
145 const FcChar8
*format
,
150 for (end
= format
; *end
&& *end
!= term
;)
155 end
++; /* skip over '\\' */
156 FcStrBufChar (buf
, escaped_char (*end
++));
159 end
++; /* skip over '%' */
162 end
= interpret_percent (pat
, buf
, end
);
165 FcStrBufChar (buf
, *end
);
169 message ("Pattern format ended while looking for '%c'", term
);
175 FcPatternFormat (FcPattern
*pat
, const FcChar8
*format
)
180 FcStrBufInit (&buf
, 0, 0);
181 len
= strlen ((const char *) format
);
182 scratch1
= malloc (len
);
183 scratch2
= malloc (len
);
184 format_orig
= format
;
186 interpret (pat
, &buf
, format
, '\0');
190 return FcStrBufDone (&buf
);
194 #include "fcaliastail.h"