]> git.wh0rd.org - fontconfig.git/blob - fc-arch/fc-arch.c
017903465fd8c8fd2518143251a701fbb2993e6a
[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*21 + 1)
29 #define MACHINE_ARCH_SIZE 32
30 /* for when we don't have sysconf: */
31 #define FC_HARDCODED_PAGESIZE 8192
32
33 static char *
34 FcCacheMachineSignature (void)
35 {
36 static char buf[MACHINE_SIGNATURE_SIZE];
37 int32_t magic = ENDIAN_TEST;
38 char * m = (char *)&magic;
39
40 sprintf (buf, "%2x%2x%2x%2x_"
41 "%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x_"
42 "%08x_%08x_%08x_%08x_%08x_%08x_%08x_%08x",
43 m[0], m[1], m[2], m[3],
44 (unsigned int)sizeof (char),
45 (unsigned int)sizeof (char *),
46 (unsigned int)sizeof (int),
47 (unsigned int)sizeof (FcPattern),
48 (unsigned int)sizeof (FcPatternEltPtr),
49 (unsigned int)sizeof (struct FcPatternElt *),
50 (unsigned int)sizeof (FcPatternElt),
51 (unsigned int)sizeof (FcObjectPtr),
52 (unsigned int)sizeof (FcValueListPtr),
53 (unsigned int)sizeof (FcValue),
54 (unsigned int)sizeof (FcValueBinding),
55 (unsigned int)sizeof (struct FcValueList *),
56 (unsigned int)sizeof (FcCharSet),
57 (unsigned int)sizeof (FcCharLeaf **),
58 (unsigned int)sizeof (FcChar16 *),
59 (unsigned int)sizeof (FcChar16),
60 (unsigned int)sizeof (FcCharLeaf),
61 (unsigned int)sizeof (FcChar32),
62 (unsigned int)sizeof (FcCache),
63 #if defined (HAVE_SYSCONF)
64 (unsigned int)sysconf(_SC_PAGESIZE)
65 #else
66 (unsigned int)FC_HARDCODED_PAGESIZE
67 #endif
68 );
69
70 return buf;
71 }
72
73 int
74 main (int argc, char **argv)
75 {
76 static char line[1024];
77 char *signature;
78 int signature_length;
79 char *space;
80 char *arch = NULL;
81 int lineno = 0;
82
83 if (argc != 2)
84 fprintf (stderr, "Usage: %s <architecture>|auto < fcarch.tmpl.h > fcarch.h\n",
85 argv[0]);
86 arch = argv[1];
87 /*
88 * Scan the input until the marker is found
89 */
90
91 while (fgets (line, sizeof (line), stdin))
92 {
93 lineno++;
94 if (!strncmp (line, "@@@", 3))
95 break;
96 fputs (line, stdout);
97 }
98 signature = FcCacheMachineSignature();
99 signature_length = strlen (signature);
100
101 if (strcmp (arch, "auto") == 0)
102 {
103 arch = NULL;
104 /*
105 * Search for signature
106 */
107 while (fgets (line, sizeof (line), stdin))
108 {
109 lineno++;
110 /*
111 * skip comments
112 */
113 if (!strncmp (line, "@@@", 3))
114 continue;
115 space = line;
116 while (*space && !isspace (*space))
117 space++;
118 if (!space)
119 {
120 fprintf (stderr, "%s: malformed input on line %d\n",
121 argv[0], lineno);
122 exit (1);
123 }
124 *space++ = '\0';
125 while (isspace (*space))
126 space++;
127 if (!strncmp (space, signature, signature_length))
128 {
129 arch = line;
130 break;
131 }
132 }
133 }
134 if (!arch)
135 {
136 fprintf (stderr, "%s: unknown signature \"%s\"\n", argv[0], signature);
137 fprintf (stderr, "\tPlease update fcarch.tmpl.h and rebuild\n");
138 exit (1);
139 }
140 printf ("#define FC_ARCHITECTURE \"%s\"\n", arch);
141 fflush (stdout);
142 exit (ferror (stdout));
143 }
144