1 /*****************************************************************************
2 * fourcc_gen.c: FourCC preprocessor
3 *****************************************************************************
4 * Copyright © 2015 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 /* DO NOT include "config.h" here */
33 typedef uint32_t vlc_fourcc_t
;
34 typedef struct { unsigned num
, den
; } vlc_rational_t
;
35 #include "../include/vlc_fourcc.h"
37 #define VLC_FOURCC(a,b,c,d) { a, b, c, d }
38 #define A(sfcc) E(sfcc, NULL)
39 #define B(fcc,dsc) { true, fcc, dsc }
40 #define E(sfcc,dsc) { false, sfcc, dsc }
46 const char *description
;
49 #include "misc/fourcc_list.h"
58 static int cmp_entry(const void *a
, const void *b
)
60 const struct entry
*ea
= a
, *eb
= b
;
61 int d
= memcmp(ea
->alias
, eb
->alias
, 4);
63 d
= memcmp(ea
->fourcc
, eb
->fourcc
, 4);
67 static void process_list(const char *name
, const staticentry_t
*list
, size_t n
)
69 struct entry
*entries
= malloc(sizeof (*entries
) * n
);
73 const staticentry_t
*klass
= NULL
;
75 for (size_t i
= 0; i
< n
; i
++)
82 fprintf(stderr
, "Error: FourCC \"%.4s\" not mapped!\n",
87 memcpy(entries
[i
].fourcc
, klass
->fourcc
, 4);
88 memcpy(entries
[i
].alias
, list
[i
].fourcc
, 4);
89 entries
[i
].desc
= list
[i
].description
;
92 qsort(entries
, n
, sizeof (*entries
), cmp_entry
);
95 for (size_t i
= 1; i
< n
; i
++)
96 if (!memcmp(entries
[i
- 1].alias
, entries
[i
].alias
, 4)
97 && memcmp(entries
[i
- 1].fourcc
, entries
[i
].fourcc
, 4))
99 fprintf(stderr
, "Error: FourCC alias \"%.4s\" conflict: "
100 "\"%.4s\" and \"%.4s\"\n", entries
[i
].alias
,
101 entries
[i
- 1].fourcc
, entries
[i
].fourcc
);
108 printf("static const struct fourcc_mapping mapping_%s[] = {\n", name
);
109 for (size_t i
= 0; i
< n
; i
++)
111 if (!memcmp(entries
[i
].fourcc
, entries
[i
].alias
, 4))
113 printf(" { { { 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx } }, "
114 "{ { 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx } } },\n",
115 entries
[i
].alias
[0], entries
[i
].alias
[1], entries
[i
].alias
[2],
116 entries
[i
].alias
[3], entries
[i
].fourcc
[0], entries
[i
].fourcc
[1],
117 entries
[i
].fourcc
[2], entries
[i
].fourcc
[3]);
120 printf("static const struct fourcc_desc desc_%s[] = {\n", name
);
121 for (size_t i
= 0; i
< n
; i
++)
123 if (entries
[i
].desc
== NULL
)
125 printf(" { { { 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx } }, "
126 "\"%s\" },\n", entries
[i
].alias
[0], entries
[i
].alias
[1],
127 entries
[i
].alias
[2], entries
[i
].alias
[3], entries
[i
].desc
);
132 fprintf(stderr
, "%s: %zu entries\n", name
, n
);
137 puts("/* This file is generated automatically. DO NOT EDIT! */");
138 puts("struct fourcc_mapping {");
139 puts(" union { unsigned char alias_str[4]; vlc_fourcc_t alias; };");
140 puts(" union { unsigned char fourcc_str[4]; vlc_fourcc_t fourcc; };");
142 puts("struct fourcc_desc {");
143 puts(" union { unsigned char alias_str[4]; vlc_fourcc_t alias; };");
144 puts(" const char desc[52];");
148 process_list(#t, p_list_##t, \
149 sizeof (p_list_##t) / sizeof ((p_list_##t)[0]))