Craig Tiller | 49772e0 | 2015-08-21 08:08:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 49772e0 | 2015-08-21 08:08:37 -0700 | [diff] [blame] | 4 | * 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 | |
| 39 | static unsigned char legal_bits[256 / 8]; |
| 40 | |
| 41 | static void legal(int x) { |
| 42 | int byte = x / 8; |
| 43 | int bit = x % 8; |
David Garcia Quintas | 809831e | 2015-10-05 13:40:07 -0700 | [diff] [blame] | 44 | /* NB: the following integer arithmetic operation needs to be in its |
| 45 | * expanded form due to the "integral promotion" performed (see section |
David Garcia Quintas | 35284f0 | 2015-10-06 11:05:05 -0700 | [diff] [blame] | 46 | * 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 Quintas | d76cdac | 2015-10-03 15:57:09 -0700 | [diff] [blame] | 48 | legal_bits[byte] = |
| 49 | (unsigned char)((legal_bits[byte] | (unsigned char)(1 << bit))); |
Craig Tiller | 49772e0 | 2015-08-21 08:08:37 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static void dump(void) { |
| 53 | int i; |
| 54 | |
Craig Tiller | 6f87164 | 2016-02-03 16:15:31 -0800 | [diff] [blame] | 55 | printf("static const uint8_t legal_header_bits[256/8] = "); |
Craig Tiller | 49772e0 | 2015-08-21 08:08:37 -0700 | [diff] [blame] | 56 | for (i = 0; i < 256 / 8; i++) |
| 57 | printf("%c 0x%02x", i ? ',' : '{', legal_bits[i]); |
| 58 | printf(" };\n"); |
| 59 | } |
| 60 | |
| 61 | static void clear(void) { memset(legal_bits, 0, sizeof(legal_bits)); } |
| 62 | |
| 63 | int main(void) { |
| 64 | int i; |
| 65 | |
| 66 | clear(); |
| 67 | for (i = 'a'; i <= 'z'; i++) legal(i); |
Craig Tiller | 49772e0 | 2015-08-21 08:08:37 -0700 | [diff] [blame] | 68 | for (i = '0'; i <= '9'; i++) legal(i); |
| 69 | legal('-'); |
Craig Tiller | 80aa280 | 2015-08-21 08:50:51 -0700 | [diff] [blame] | 70 | legal('_'); |
Craig Tiller | a761589 | 2015-12-15 10:41:54 -0800 | [diff] [blame] | 71 | legal('.'); |
Craig Tiller | 49772e0 | 2015-08-21 08:08:37 -0700 | [diff] [blame] | 72 | dump(); |
| 73 | |
| 74 | clear(); |
Craig Tiller | 240b7db | 2015-08-27 15:35:32 -0700 | [diff] [blame] | 75 | for (i = 32; i <= 126; i++) { |
Craig Tiller | 240b7db | 2015-08-27 15:35:32 -0700 | [diff] [blame] | 76 | legal(i); |
| 77 | } |
Craig Tiller | 49772e0 | 2015-08-21 08:08:37 -0700 | [diff] [blame] | 78 | dump(); |
| 79 | |
| 80 | return 0; |
| 81 | } |