blob: 6ac32656cbb2b28d2b68c38c6e56c181307319a3 [file] [log] [blame]
Craig Tiller49772e02015-08-21 08:08:37 -07001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller49772e02015-08-21 08:08:37 -07004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34/* generates constant table for metadata.c */
35
36#include <stdio.h>
37#include <string.h>
38
39static unsigned char legal_bits[256 / 8];
40
41static void legal(int x) {
42 int byte = x / 8;
43 int bit = x % 8;
David Garcia Quintas809831e2015-10-05 13:40:07 -070044 /* NB: the following integer arithmetic operation needs to be in its
45 * expanded form due to the "integral promotion" performed (see section
David Garcia Quintas35284f02015-10-06 11:05:05 -070046 * 3.2.1.1 of the C89 draft standard). A cast to the smaller container type
47 * is then required to avoid the compiler warning */
David Garcia Quintasd76cdac2015-10-03 15:57:09 -070048 legal_bits[byte] =
49 (unsigned char)((legal_bits[byte] | (unsigned char)(1 << bit)));
Craig Tiller49772e02015-08-21 08:08:37 -070050}
51
52static void dump(void) {
53 int i;
54
Craig Tiller6f871642016-02-03 16:15:31 -080055 printf("static const uint8_t legal_header_bits[256/8] = ");
Craig Tiller49772e02015-08-21 08:08:37 -070056 for (i = 0; i < 256 / 8; i++)
57 printf("%c 0x%02x", i ? ',' : '{', legal_bits[i]);
58 printf(" };\n");
59}
60
61static void clear(void) { memset(legal_bits, 0, sizeof(legal_bits)); }
62
63int main(void) {
64 int i;
65
66 clear();
67 for (i = 'a'; i <= 'z'; i++) legal(i);
Craig Tiller49772e02015-08-21 08:08:37 -070068 for (i = '0'; i <= '9'; i++) legal(i);
69 legal('-');
Craig Tiller80aa2802015-08-21 08:50:51 -070070 legal('_');
Craig Tillera7615892015-12-15 10:41:54 -080071 legal('.');
Craig Tiller49772e02015-08-21 08:08:37 -070072 dump();
73
74 clear();
Craig Tiller240b7db2015-08-27 15:35:32 -070075 for (i = 32; i <= 126; i++) {
Craig Tiller240b7db2015-08-27 15:35:32 -070076 legal(i);
77 }
Craig Tiller49772e02015-08-21 08:08:37 -070078 dump();
79
80 return 0;
81}