]> git.wh0rd.org - fontconfig.git/blob - fc-arch/fc-arch.c
d0f5192e694c617906c920208d463ae4e99590ac
[fontconfig.git] / fc-arch / fc-arch.c
1 /*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2005 Patrick Lam
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the name of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. The copyright holders make no representations
12 * about the suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
14 *
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
22 */
23
24 #include "fcint.h"
25 #include <ctype.h>
26
27 #define ENDIAN_TEST 0x12345678
28 #define MACHINE_SIGNATURE_SIZE (9*22 + 1)
29
30 static char *
31 FcCacheMachineSignature (void)
32 {
33 static char buf[MACHINE_SIGNATURE_SIZE];
34 int32_t magic = ENDIAN_TEST;
35 char * m = (char *)&magic;
36
37 sprintf (buf, "%2x%2x%2x%2x_"
38 "%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_"
39 "%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x",
40 m[0], m[1], m[2], m[3],
41 (unsigned int)sizeof (FcAlign),
42 (unsigned int)sizeof (char),
43 (unsigned int)sizeof (char *),
44 (unsigned int)sizeof (int),
45 (unsigned int)sizeof (intptr_t),
46 (unsigned int)sizeof (FcPattern),
47 (unsigned int)sizeof (FcPatternEltPtr),
48 (unsigned int)sizeof (struct FcPatternElt *),
49 (unsigned int)sizeof (FcPatternElt),
50 (unsigned int)sizeof (FcObject),
51 (unsigned int)sizeof (FcValueListPtr),
52 (unsigned int)sizeof (FcValue),
53 (unsigned int)sizeof (FcValueBinding),
54 (unsigned int)sizeof (struct FcValueList *),
55 (unsigned int)sizeof (FcCharSet),
56 (unsigned int)sizeof (FcCharLeaf **),
57 (unsigned int)sizeof (FcChar16 *),
58 (unsigned int)sizeof (FcChar16),
59 (unsigned int)sizeof (FcCharLeaf),
60 (unsigned int)sizeof (FcChar32),
61 (unsigned int)sizeof (FcCache));
62
63 return buf;
64 }
65
66 int
67 main (int argc, char **argv)
68 {
69 static char line[1024];
70 char *signature;
71 int signature_length;
72 char *space;
73 char *arch = NULL;
74 int lineno = 0;
75
76 if (argc != 2)
77 fprintf (stderr, "Usage: %s <architecture>|auto < fcarch.tmpl.h > fcarch.h\n",
78 argv[0]);
79 arch = argv[1];
80 /*
81 * Scan the input until the marker is found
82 */
83
84 while (fgets (line, sizeof (line), stdin))
85 {
86 lineno++;
87 if (!strncmp (line, "@@@", 3))
88 break;
89 fputs (line, stdout);
90 }
91 signature = FcCacheMachineSignature();
92 signature_length = strlen (signature);
93
94 if (strcmp (arch, "auto") == 0)
95 {
96 arch = NULL;
97 /*
98 * Search for signature
99 */
100 while (fgets (line, sizeof (line), stdin))
101 {
102 lineno++;
103 /*
104 * skip comments
105 */
106 if (!strncmp (line, "@@@", 3))
107 continue;
108 space = line;
109 while (*space && !isspace (*space))
110 space++;
111 if (!space)
112 {
113 fprintf (stderr, "%s: malformed input on line %d\n",
114 argv[0], lineno);
115 exit (1);
116 }
117 *space++ = '\0';
118 while (isspace (*space))
119 space++;
120 if (!strncmp (space, signature, signature_length))
121 {
122 arch = line;
123 break;
124 }
125 }
126 }
127 if (!arch)
128 {
129 fprintf (stderr, "%s: unknown signature \"%s\"\n", argv[0], signature);
130 fprintf (stderr, "\tPlease update fcarch.tmpl.h and rebuild\n");
131 exit (1);
132 }
133 printf ("#define FC_ARCHITECTURE \"%s\"\n", arch);
134 fflush (stdout);
135 exit (ferror (stdout));
136 }
137