]> git.wh0rd.org Git - fontconfig.git/blob - fc-arch/fc-arch.c
[fc-arch] Beautify the arch template
[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 0x01020304
28 #define MACHINE_SIGNATURE_SIZE 1024
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, "%01x%01x%01x%01x_"
38              "%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_"
39              "%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x_%02x",
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 (FcStrSet *), /* For FcLangSet */
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
64     return buf;
65 }
66
67 int
68 main (int argc, char **argv)
69 {
70     static char         line[1024];
71     char                *signature;
72     int                 signature_length;
73     char                *space;
74     char                *arch = NULL;
75     int                 lineno = 0;
76     
77     if (argc != 2)
78         fprintf (stderr, "Usage: %s <architecture>|auto < fcarch.tmpl.h > fcarch.h\n",
79                  argv[0]);
80     arch = argv[1];
81     /*
82      * Scan the input until the marker is found
83      */
84     
85     while (fgets (line, sizeof (line), stdin))
86     {
87         lineno++;
88         if (!strncmp (line, "@@@", 3))
89             break;
90         fputs (line, stdout);
91     }
92     signature = FcCacheMachineSignature();
93     signature_length = strlen (signature);
94     
95     if (strcmp (arch, "auto") == 0)
96     {
97         arch = NULL;
98         /*
99          * Search for signature
100          */
101         while (fgets (line, sizeof (line), stdin)) 
102         {
103             lineno++;
104             /*
105              * skip comments
106              */
107             if (!strncmp (line, "@@@", 3))
108                 continue;
109             space = line;
110             while (*space && !isspace (*space))
111                 space++;
112             if (!space)
113             {
114                 fprintf (stderr, "%s: malformed input on line %d\n",
115                          argv[0], lineno);
116                 exit (1);
117             }
118             *space++ = '\0';
119             while (isspace (*space))
120                 space++;
121             if (!strncmp (space, signature, signature_length))
122             {
123                 arch = line;
124                 break;
125             }
126         }
127     }
128     if (!arch)
129     {
130         fprintf (stderr, "%s: unknown signature \"%s\"\n", argv[0], signature);
131         fprintf (stderr, "\tPlease update fcarch.tmpl.h and rebuild\n");
132         exit (1);
133     }
134     printf ("#define FC_ARCHITECTURE \"%s\"\n", arch);
135     fflush (stdout);
136     exit (ferror (stdout));
137 }
138