diff --git a/lib/huftable.h b/lib/huftable.h new file mode 100644 index 00000000..b7eb426f --- /dev/null +++ b/lib/huftable.h @@ -0,0 +1,527 @@ +static unsigned char lextable[] = { +/* pos 0000: 0 */ /* 0 */ 0x42 /* (to 0x0084 state 98) */, + /* 1 */ 0x01 /* (to 0x0002 state 1) */, +/* pos 0002: 1 */ /* 0 */ 0x5C /* (to 0x00BA state 151) */, + /* 1 */ 0x01 /* (to 0x0004 state 2) */, +/* pos 0004: 2 */ /* 0 */ 0x66 /* (to 0x00D0 state 173) */, + /* 1 */ 0x01 /* (to 0x0006 state 3) */, +/* pos 0006: 3 */ /* 0 */ 0x74 /* (to 0x00EE state 204) */, + /* 1 */ 0x01 /* (to 0x0008 state 4) */, +/* pos 0008: 4 */ /* 0 */ 0x8C /* (to 0x0120 state 263) */, + /* 1 */ 0x01 /* (to 0x000A state 5) */, +/* pos 000a: 5 */ /* 0 */ 0x46 /* (to 0x0096 state 113) */, + /* 1 */ 0x01 /* (to 0x000C state 6) */, +/* pos 000c: 6 */ /* 0 */ 0x75 /* (to 0x00F6 state 211) */, + /* 1 */ 0x01 /* (to 0x000E state 7) */, +/* pos 000e: 7 */ /* 0 */ 0x40 /* (to 0x008E state 104) */, + /* 1 */ 0x01 /* (to 0x0010 state 8) */, +/* pos 0010: 8 */ /* 0 */ 0x45 /* (to 0x009A state 116) */, + /* 1 */ 0x01 /* (to 0x0012 state 9) */, +/* pos 0012: 9 */ /* 0 */ 0x40 /* (to 0x0092 state 108) */, + /* 1 */ 0x01 /* (to 0x0014 state 10) */, +/* pos 0014: 10 */ /* 0 */ 0x01 /* (to 0x0016 state 11) */, + /* 1 */ 0x03 /* (to 0x001A state 14) */, +/* pos 0016: 11 */ /* 0 */ 0x01 /* (to 0x0018 state 12) */, + /* 1 */ 0x5B /* (to 0x00CC state 166) */, +/* pos 0018: 12 */ /* terminal 0 */ 0x00, + /* terminal 36 */ 0x24, +/* pos 001a: 14 */ /* 0 */ 0x72 /* (to 0x00FE state 220) */, + /* 1 */ 0x01 /* (to 0x001C state 15) */, +/* pos 001c: 15 */ /* 0 */ 0x72 /* (to 0x0100 state 222) */, + /* 1 */ 0x01 /* (to 0x001E state 16) */, +/* pos 001e: 16 */ /* 0 */ 0x53 /* (to 0x00C4 state 158) */, + /* 1 */ 0x01 /* (to 0x0020 state 17) */, +/* pos 0020: 17 */ /* terminal 123 */ 0x7B, + /* 1 */ 0x01 /* (to 0x0022 state 18) */, +/* pos 0022: 18 */ /* 0 */ 0x6B /* (to 0x00F8 state 216) */, + /* 1 */ 0x01 /* (to 0x0024 state 19) */, +/* pos 0024: 19 */ /* 0 */ 0x84 /* (to 0x012C state 279) */, + /* 1 */ 0x01 /* (to 0x0026 state 20) */, +/* pos 0026: 20 */ /* 0 */ 0x01 /* (to 0x0028 state 21) */, + /* 1 */ 0x06 /* (to 0x0032 state 27) */, +/* pos 0028: 21 */ /* 0 */ 0xB3 /* (to 0x018E state 377) */, + /* 1 */ 0x01 /* (to 0x002A state 22) */, +/* pos 002a: 22 */ /* 0 */ 0xC3 /* (to 0x01B0 state 414) */, + /* 1 */ 0x01 /* (to 0x002C state 23) */, +/* pos 002c: 23 */ /* 0 */ 0x01 /* (to 0x002E state 24) */, + /* 1 */ 0x8C /* (to 0x0144 state 301) */, +/* pos 002e: 24 */ /* 0 */ 0x01 /* (to 0x0030 state 25) */, + /* 1 */ 0x8A /* (to 0x0142 state 298) */, +/* pos 0030: 25 */ /* terminal 1 */ 0x01, + /* terminal 135 */ 0x87, +/* pos 0032: 27 */ /* 0 */ 0x8E /* (to 0x014E state 314) */, + /* 1 */ 0x01 /* (to 0x0034 state 28) */, +/* pos 0034: 28 */ /* 0 */ 0x0F /* (to 0x0052 state 50) */, + /* 1 */ 0x01 /* (to 0x0036 state 29) */, +/* pos 0036: 29 */ /* 0 */ 0xA4 /* (to 0x017E state 362) */, + /* 1 */ 0x01 /* (to 0x0038 state 30) */, +/* pos 0038: 30 */ /* 0 */ 0xB7 /* (to 0x01A6 state 403) */, + /* 1 */ 0x01 /* (to 0x003A state 31) */, +/* pos 003a: 31 */ /* 0 */ 0xC8 /* (to 0x01CA state 440) */, + /* 1 */ 0x01 /* (to 0x003C state 32) */, +/* pos 003c: 32 */ /* 0 */ 0x01 /* (to 0x003E state 33) */, + /* 1 */ 0x0F /* (to 0x005A state 55) */, +/* pos 003e: 33 */ /* 0 */ 0x01 /* (to 0x0040 state 34) */, + /* 1 */ 0x07 /* (to 0x004C state 46) */, +/* pos 0040: 34 */ /* 0 */ 0x01 /* (to 0x0042 state 35) */, + /* 1 */ 0x03 /* (to 0x0046 state 39) */, +/* pos 0042: 35 */ /* terminal 254 */ 0xFE, + /* 1 */ 0x01 /* (to 0x0044 state 36) */, +/* pos 0044: 36 */ /* terminal 2 */ 0x02, + /* terminal 3 */ 0x03, +/* pos 0046: 39 */ /* 0 */ 0x01 /* (to 0x0048 state 40) */, + /* 1 */ 0x02 /* (to 0x004A state 43) */, +/* pos 0048: 40 */ /* terminal 4 */ 0x04, + /* terminal 5 */ 0x05, +/* pos 004a: 43 */ /* terminal 6 */ 0x06, + /* terminal 7 */ 0x07, +/* pos 004c: 46 */ /* 0 */ 0x01 /* (to 0x004E state 47) */, + /* 1 */ 0x0E /* (to 0x0068 state 67) */, +/* pos 004e: 47 */ /* 0 */ 0x01 /* (to 0x0050 state 48) */, + /* 1 */ 0x0C /* (to 0x0066 state 63) */, +/* pos 0050: 48 */ /* terminal 8 */ 0x08, + /* terminal 11 */ 0x0B, +/* pos 0052: 50 */ /* 0 */ 0xA7 /* (to 0x01A0 state 396) */, + /* 1 */ 0x01 /* (to 0x0054 state 51) */, +/* pos 0054: 51 */ /* 0 */ 0x01 /* (to 0x0056 state 52) */, + /* 1 */ 0x7B /* (to 0x014A state 309) */, +/* pos 0056: 52 */ /* terminal 239 */ 0xEF, + /* 1 */ 0x01 /* (to 0x0058 state 53) */, +/* pos 0058: 53 */ /* terminal 9 */ 0x09, + /* terminal 142 */ 0x8E, +/* pos 005a: 55 */ /* 0 */ 0x0A /* (to 0x006E state 74) */, + /* 1 */ 0x01 /* (to 0x005C state 56) */, +/* pos 005c: 56 */ /* 0 */ 0x11 /* (to 0x007E state 91) */, + /* 1 */ 0x01 /* (to 0x005E state 57) */, +/* pos 005e: 57 */ /* 0 */ 0x64 /* (to 0x0126 state 274) */, + /* 1 */ 0x01 /* (to 0x0060 state 58) */, +/* pos 0060: 58 */ /* terminal 249 */ 0xF9, + /* 1 */ 0x01 /* (to 0x0062 state 59) */, +/* pos 0062: 59 */ /* 0 */ 0x01 /* (to 0x0064 state 60) */, + /* 1 */ 0x0A /* (to 0x0076 state 81) */, +/* pos 0064: 60 */ /* terminal 10 */ 0x0A, + /* terminal 13 */ 0x0D, +/* pos 0066: 63 */ /* terminal 12 */ 0x0C, + /* terminal 14 */ 0x0E, +/* pos 0068: 67 */ /* 0 */ 0x01 /* (to 0x006A state 68) */, + /* 1 */ 0x02 /* (to 0x006C state 71) */, +/* pos 006a: 68 */ /* terminal 15 */ 0x0F, + /* terminal 16 */ 0x10, +/* pos 006c: 71 */ /* terminal 17 */ 0x11, + /* terminal 18 */ 0x12, +/* pos 006e: 74 */ /* 0 */ 0x01 /* (to 0x0070 state 75) */, + /* 1 */ 0x05 /* (to 0x0078 state 84) */, +/* pos 0070: 75 */ /* 0 */ 0x01 /* (to 0x0072 state 76) */, + /* 1 */ 0x02 /* (to 0x0074 state 79) */, +/* pos 0072: 76 */ /* terminal 19 */ 0x13, + /* terminal 20 */ 0x14, +/* pos 0074: 79 */ /* terminal 21 */ 0x15, + /* terminal 23 */ 0x17, +/* pos 0076: 81 */ /* terminal 22 */ 0x16, + /* terminal 256 */ 0x00, +/* pos 0078: 84 */ /* 0 */ 0x01 /* (to 0x007A state 85) */, + /* 1 */ 0x02 /* (to 0x007C state 88) */, +/* pos 007a: 85 */ /* terminal 24 */ 0x18, + /* terminal 25 */ 0x19, +/* pos 007c: 88 */ /* terminal 26 */ 0x1A, + /* terminal 27 */ 0x1B, +/* pos 007e: 91 */ /* 0 */ 0x01 /* (to 0x0080 state 92) */, + /* 1 */ 0x02 /* (to 0x0082 state 95) */, +/* pos 0080: 92 */ /* terminal 28 */ 0x1C, + /* terminal 29 */ 0x1D, +/* pos 0082: 95 */ /* terminal 30 */ 0x1E, + /* terminal 31 */ 0x1F, +/* pos 0084: 98 */ /* 0 */ 0x13 /* (to 0x00AA state 133) */, + /* 1 */ 0x01 /* (to 0x0086 state 99) */, +/* pos 0086: 99 */ /* 0 */ 0x01 /* (to 0x0088 state 100) */, + /* 1 */ 0x0F /* (to 0x00A4 state 129) */, +/* pos 0088: 100 */ /* 0 */ 0x4B /* (to 0x011E state 258) */, + /* 1 */ 0x01 /* (to 0x008A state 101) */, +/* pos 008a: 101 */ /* 0 */ 0x01 /* (to 0x008C state 102) */, + /* 1 */ 0x0C /* (to 0x00A2 state 126) */, +/* pos 008c: 102 */ /* terminal 32 */ 0x20, + /* terminal 37 */ 0x25, +/* pos 008e: 104 */ /* 0 */ 0x01 /* (to 0x0090 state 105) */, + /* 1 */ 0x08 /* (to 0x009E state 119) */, +/* pos 0090: 105 */ /* terminal 33 */ 0x21, + /* terminal 34 */ 0x22, +/* pos 0092: 108 */ /* terminal 124 */ 0x7C, + /* 1 */ 0x01 /* (to 0x0094 state 109) */, +/* pos 0094: 109 */ /* terminal 35 */ 0x23, + /* terminal 62 */ 0x3E, +/* pos 0096: 113 */ /* 0 */ 0x01 /* (to 0x0098 state 114) */, + /* 1 */ 0x05 /* (to 0x00A0 state 124) */, +/* pos 0098: 114 */ /* terminal 38 */ 0x26, + /* terminal 42 */ 0x2A, +/* pos 009a: 116 */ /* terminal 63 */ 0x3F, + /* 1 */ 0x01 /* (to 0x009C state 117) */, +/* pos 009c: 117 */ /* terminal 39 */ 0x27, + /* terminal 43 */ 0x2B, +/* pos 009e: 119 */ /* terminal 40 */ 0x28, + /* terminal 41 */ 0x29, +/* pos 00a0: 124 */ /* terminal 44 */ 0x2C, + /* terminal 59 */ 0x3B, +/* pos 00a2: 126 */ /* terminal 45 */ 0x2D, + /* terminal 46 */ 0x2E, +/* pos 00a4: 129 */ /* 0 */ 0x01 /* (to 0x00A6 state 130) */, + /* 1 */ 0x08 /* (to 0x00B4 state 144) */, +/* pos 00a6: 130 */ /* 0 */ 0x01 /* (to 0x00A8 state 131) */, + /* 1 */ 0x06 /* (to 0x00B2 state 141) */, +/* pos 00a8: 131 */ /* terminal 47 */ 0x2F, + /* terminal 51 */ 0x33, +/* pos 00aa: 133 */ /* 0 */ 0x01 /* (to 0x00AC state 134) */, + /* 1 */ 0x2D /* (to 0x0104 state 229) */, +/* pos 00ac: 134 */ /* 0 */ 0x01 /* (to 0x00AE state 135) */, + /* 1 */ 0x02 /* (to 0x00B0 state 138) */, +/* pos 00ae: 135 */ /* terminal 48 */ 0x30, + /* terminal 49 */ 0x31, +/* pos 00b0: 138 */ /* terminal 50 */ 0x32, + /* terminal 97 */ 0x61, +/* pos 00b2: 141 */ /* terminal 52 */ 0x34, + /* terminal 53 */ 0x35, +/* pos 00b4: 144 */ /* 0 */ 0x01 /* (to 0x00B6 state 145) */, + /* 1 */ 0x02 /* (to 0x00B8 state 148) */, +/* pos 00b6: 145 */ /* terminal 54 */ 0x36, + /* terminal 55 */ 0x37, +/* pos 00b8: 148 */ /* terminal 56 */ 0x38, + /* terminal 57 */ 0x39, +/* pos 00ba: 151 */ /* 0 */ 0x06 /* (to 0x00C6 state 160) */, + /* 1 */ 0x01 /* (to 0x00BC state 152) */, +/* pos 00bc: 152 */ /* 0 */ 0x2C /* (to 0x0114 state 246) */, + /* 1 */ 0x01 /* (to 0x00BE state 153) */, +/* pos 00be: 153 */ /* 0 */ 0x2F /* (to 0x011C state 256) */, + /* 1 */ 0x01 /* (to 0x00C0 state 154) */, +/* pos 00c0: 154 */ /* 0 */ 0x01 /* (to 0x00C2 state 155) */, + /* 1 */ 0x07 /* (to 0x00CE state 170) */, +/* pos 00c2: 155 */ /* terminal 58 */ 0x3A, + /* terminal 66 */ 0x42, +/* pos 00c4: 158 */ /* terminal 60 */ 0x3C, + /* terminal 96 */ 0x60, +/* pos 00c6: 160 */ /* 0 */ 0x01 /* (to 0x00C8 state 161) */, + /* 1 */ 0x21 /* (to 0x0108 state 232) */, +/* pos 00c8: 161 */ /* 0 */ 0x01 /* (to 0x00CA state 162) */, + /* 1 */ 0x1D /* (to 0x0102 state 224) */, +/* pos 00ca: 162 */ /* terminal 61 */ 0x3D, + /* terminal 65 */ 0x41, +/* pos 00cc: 166 */ /* terminal 64 */ 0x40, + /* terminal 91 */ 0x5B, +/* pos 00ce: 170 */ /* terminal 67 */ 0x43, + /* terminal 68 */ 0x44, +/* pos 00d0: 173 */ /* 0 */ 0x01 /* (to 0x00D2 state 174) */, + /* 1 */ 0x08 /* (to 0x00E0 state 189) */, +/* pos 00d2: 174 */ /* 0 */ 0x01 /* (to 0x00D4 state 175) */, + /* 1 */ 0x04 /* (to 0x00DA state 182) */, +/* pos 00d4: 175 */ /* 0 */ 0x01 /* (to 0x00D6 state 176) */, + /* 1 */ 0x02 /* (to 0x00D8 state 179) */, +/* pos 00d6: 176 */ /* terminal 69 */ 0x45, + /* terminal 70 */ 0x46, +/* pos 00d8: 179 */ /* terminal 71 */ 0x47, + /* terminal 72 */ 0x48, +/* pos 00da: 182 */ /* 0 */ 0x01 /* (to 0x00DC state 183) */, + /* 1 */ 0x02 /* (to 0x00DE state 186) */, +/* pos 00dc: 183 */ /* terminal 73 */ 0x49, + /* terminal 74 */ 0x4A, +/* pos 00de: 186 */ /* terminal 75 */ 0x4B, + /* terminal 76 */ 0x4C, +/* pos 00e0: 189 */ /* 0 */ 0x01 /* (to 0x00E2 state 190) */, + /* 1 */ 0x04 /* (to 0x00E8 state 197) */, +/* pos 00e2: 190 */ /* 0 */ 0x01 /* (to 0x00E4 state 191) */, + /* 1 */ 0x02 /* (to 0x00E6 state 194) */, +/* pos 00e4: 191 */ /* terminal 77 */ 0x4D, + /* terminal 78 */ 0x4E, +/* pos 00e6: 194 */ /* terminal 79 */ 0x4F, + /* terminal 80 */ 0x50, +/* pos 00e8: 197 */ /* 0 */ 0x01 /* (to 0x00EA state 198) */, + /* 1 */ 0x02 /* (to 0x00EC state 201) */, +/* pos 00ea: 198 */ /* terminal 81 */ 0x51, + /* terminal 82 */ 0x52, +/* pos 00ec: 201 */ /* terminal 83 */ 0x53, + /* terminal 84 */ 0x54, +/* pos 00ee: 204 */ /* 0 */ 0x01 /* (to 0x00F0 state 205) */, + /* 1 */ 0x11 /* (to 0x0110 state 242) */, +/* pos 00f0: 205 */ /* 0 */ 0x01 /* (to 0x00F2 state 206) */, + /* 1 */ 0x02 /* (to 0x00F4 state 209) */, +/* pos 00f2: 206 */ /* terminal 85 */ 0x55, + /* terminal 86 */ 0x56, +/* pos 00f4: 209 */ /* terminal 87 */ 0x57, + /* terminal 89 */ 0x59, +/* pos 00f6: 211 */ /* terminal 88 */ 0x58, + /* terminal 90 */ 0x5A, +/* pos 00f8: 216 */ /* 0 */ 0x01 /* (to 0x00FA state 217) */, + /* 1 */ 0x1F /* (to 0x0136 state 286) */, +/* pos 00fa: 217 */ /* 0 */ 0x01 /* (to 0x00FC state 218) */, + /* 1 */ 0x17 /* (to 0x0128 state 276) */, +/* pos 00fc: 218 */ /* terminal 92 */ 0x5C, + /* terminal 195 */ 0xC3, +/* pos 00fe: 220 */ /* terminal 93 */ 0x5D, + /* terminal 126 */ 0x7E, +/* pos 0100: 222 */ /* terminal 94 */ 0x5E, + /* terminal 125 */ 0x7D, +/* pos 0102: 224 */ /* terminal 95 */ 0x5F, + /* terminal 98 */ 0x62, +/* pos 0104: 229 */ /* 0 */ 0x01 /* (to 0x0106 state 230) */, + /* 1 */ 0x05 /* (to 0x010E state 240) */, +/* pos 0106: 230 */ /* terminal 99 */ 0x63, + /* terminal 101 */ 0x65, +/* pos 0108: 232 */ /* 0 */ 0x01 /* (to 0x010A state 233) */, + /* 1 */ 0x02 /* (to 0x010C state 237) */, +/* pos 010a: 233 */ /* terminal 100 */ 0x64, + /* terminal 102 */ 0x66, +/* pos 010c: 237 */ /* terminal 103 */ 0x67, + /* terminal 104 */ 0x68, +/* pos 010e: 240 */ /* terminal 105 */ 0x69, + /* terminal 111 */ 0x6F, +/* pos 0110: 242 */ /* 0 */ 0x01 /* (to 0x0112 state 243) */, + /* 1 */ 0x05 /* (to 0x011A state 254) */, +/* pos 0112: 243 */ /* terminal 106 */ 0x6A, + /* terminal 107 */ 0x6B, +/* pos 0114: 246 */ /* 0 */ 0x01 /* (to 0x0116 state 247) */, + /* 1 */ 0x02 /* (to 0x0118 state 250) */, +/* pos 0116: 247 */ /* terminal 108 */ 0x6C, + /* terminal 109 */ 0x6D, +/* pos 0118: 250 */ /* terminal 110 */ 0x6E, + /* terminal 112 */ 0x70, +/* pos 011a: 254 */ /* terminal 113 */ 0x71, + /* terminal 118 */ 0x76, +/* pos 011c: 256 */ /* terminal 114 */ 0x72, + /* terminal 117 */ 0x75, +/* pos 011e: 258 */ /* terminal 115 */ 0x73, + /* terminal 116 */ 0x74, +/* pos 0120: 263 */ /* 0 */ 0x01 /* (to 0x0122 state 264) */, + /* 1 */ 0x02 /* (to 0x0124 state 267) */, +/* pos 0122: 264 */ /* terminal 119 */ 0x77, + /* terminal 120 */ 0x78, +/* pos 0124: 267 */ /* terminal 121 */ 0x79, + /* terminal 122 */ 0x7A, +/* pos 0126: 274 */ /* terminal 127 */ 0x7F, + /* terminal 220 */ 0xDC, +/* pos 0128: 276 */ /* terminal 208 */ 0xD0, + /* 1 */ 0x01 /* (to 0x012A state 277) */, +/* pos 012a: 277 */ /* terminal 128 */ 0x80, + /* terminal 130 */ 0x82, +/* pos 012c: 279 */ /* 0 */ 0x2E /* (to 0x0188 state 372) */, + /* 1 */ 0x01 /* (to 0x012E state 280) */, +/* pos 012e: 280 */ /* 0 */ 0x01 /* (to 0x0130 state 281) */, + /* 1 */ 0x1B /* (to 0x0164 state 332) */, +/* pos 0130: 281 */ /* 0 */ 0x01 /* (to 0x0132 state 282) */, + /* 1 */ 0x06 /* (to 0x013C state 291) */, +/* pos 0132: 282 */ /* terminal 230 */ 0xE6, + /* 1 */ 0x01 /* (to 0x0134 state 283) */, +/* pos 0134: 283 */ /* terminal 129 */ 0x81, + /* terminal 132 */ 0x84, +/* pos 0136: 286 */ /* 0 */ 0x01 /* (to 0x0138 state 287) */, + /* 1 */ 0x14 /* (to 0x015E state 328) */, +/* pos 0138: 287 */ /* 0 */ 0x01 /* (to 0x013A state 288) */, + /* 1 */ 0x30 /* (to 0x0198 state 388) */, +/* pos 013a: 288 */ /* terminal 131 */ 0x83, + /* terminal 162 */ 0xA2, +/* pos 013c: 291 */ /* 0 */ 0x01 /* (to 0x013E state 292) */, + /* 1 */ 0x02 /* (to 0x0140 state 296) */, +/* pos 013e: 292 */ /* terminal 133 */ 0x85, + /* terminal 134 */ 0x86, +/* pos 0140: 296 */ /* terminal 136 */ 0x88, + /* terminal 146 */ 0x92, +/* pos 0142: 298 */ /* terminal 137 */ 0x89, + /* terminal 138 */ 0x8A, +/* pos 0144: 301 */ /* 0 */ 0x01 /* (to 0x0146 state 302) */, + /* 1 */ 0x02 /* (to 0x0148 state 305) */, +/* pos 0146: 302 */ /* terminal 139 */ 0x8B, + /* terminal 140 */ 0x8C, +/* pos 0148: 305 */ /* terminal 141 */ 0x8D, + /* terminal 143 */ 0x8F, +/* pos 014a: 309 */ /* 0 */ 0x01 /* (to 0x014C state 310) */, + /* 1 */ 0x06 /* (to 0x0156 state 319) */, +/* pos 014c: 310 */ /* terminal 144 */ 0x90, + /* terminal 145 */ 0x91, +/* pos 014e: 314 */ /* 0 */ 0x01 /* (to 0x0150 state 315) */, + /* 1 */ 0x12 /* (to 0x0172 state 350) */, +/* pos 0150: 315 */ /* 0 */ 0x01 /* (to 0x0152 state 316) */, + /* 1 */ 0x05 /* (to 0x015A state 325) */, +/* pos 0152: 316 */ /* 0 */ 0x01 /* (to 0x0154 state 317) */, + /* 1 */ 0x03 /* (to 0x0158 state 322) */, +/* pos 0154: 317 */ /* terminal 147 */ 0x93, + /* terminal 149 */ 0x95, +/* pos 0156: 319 */ /* terminal 148 */ 0x94, + /* terminal 159 */ 0x9F, +/* pos 0158: 322 */ /* terminal 150 */ 0x96, + /* terminal 151 */ 0x97, +/* pos 015a: 325 */ /* 0 */ 0x01 /* (to 0x015C state 326) */, + /* 1 */ 0x08 /* (to 0x016A state 338) */, +/* pos 015c: 326 */ /* terminal 152 */ 0x98, + /* terminal 155 */ 0x9B, +/* pos 015e: 328 */ /* 0 */ 0x42 /* (to 0x01E2 state 465) */, + /* 1 */ 0x01 /* (to 0x0160 state 329) */, +/* pos 0160: 329 */ /* 0 */ 0x01 /* (to 0x0162 state 330) */, + /* 1 */ 0x0C /* (to 0x0178 state 355) */, +/* pos 0162: 330 */ /* terminal 153 */ 0x99, + /* terminal 161 */ 0xA1, +/* pos 0164: 332 */ /* 0 */ 0x01 /* (to 0x0166 state 333) */, + /* 1 */ 0x05 /* (to 0x016E state 347) */, +/* pos 0166: 333 */ /* 0 */ 0x01 /* (to 0x0168 state 334) */, + /* 1 */ 0x03 /* (to 0x016C state 342) */, +/* pos 0168: 334 */ /* terminal 154 */ 0x9A, + /* terminal 156 */ 0x9C, +/* pos 016a: 338 */ /* terminal 157 */ 0x9D, + /* terminal 158 */ 0x9E, +/* pos 016c: 342 */ /* terminal 160 */ 0xA0, + /* terminal 163 */ 0xA3, +/* pos 016e: 347 */ /* 0 */ 0x01 /* (to 0x0170 state 348) */, + /* 1 */ 0x07 /* (to 0x017C state 360) */, +/* pos 0170: 348 */ /* terminal 164 */ 0xA4, + /* terminal 169 */ 0xA9, +/* pos 0172: 350 */ /* 0 */ 0x01 /* (to 0x0174 state 351) */, + /* 1 */ 0x09 /* (to 0x0184 state 369) */, +/* pos 0174: 351 */ /* 0 */ 0x01 /* (to 0x0176 state 352) */, + /* 1 */ 0x03 /* (to 0x017A state 357) */, +/* pos 0176: 352 */ /* terminal 165 */ 0xA5, + /* terminal 166 */ 0xA6, +/* pos 0178: 355 */ /* terminal 167 */ 0xA7, + /* terminal 172 */ 0xAC, +/* pos 017a: 357 */ /* terminal 168 */ 0xA8, + /* terminal 174 */ 0xAE, +/* pos 017c: 360 */ /* terminal 170 */ 0xAA, + /* terminal 173 */ 0xAD, +/* pos 017e: 362 */ /* 0 */ 0x01 /* (to 0x0180 state 363) */, + /* 1 */ 0x1B /* (to 0x01B4 state 417) */, +/* pos 0180: 363 */ /* 0 */ 0x01 /* (to 0x0182 state 364) */, + /* 1 */ 0x2A /* (to 0x01D4 state 449) */, +/* pos 0182: 364 */ /* terminal 171 */ 0xAB, + /* terminal 206 */ 0xCE, +/* pos 0184: 369 */ /* 0 */ 0x01 /* (to 0x0186 state 370) */, + /* 1 */ 0x09 /* (to 0x0196 state 385) */, +/* pos 0186: 370 */ /* terminal 175 */ 0xAF, + /* terminal 180 */ 0xB4, +/* pos 0188: 372 */ /* 0 */ 0x01 /* (to 0x018A state 373) */, + /* 1 */ 0x27 /* (to 0x01D6 state 451) */, +/* pos 018a: 373 */ /* 0 */ 0x01 /* (to 0x018C state 374) */, + /* 1 */ 0x05 /* (to 0x0194 state 381) */, +/* pos 018c: 374 */ /* terminal 176 */ 0xB0, + /* terminal 177 */ 0xB1, +/* pos 018e: 377 */ /* 0 */ 0x01 /* (to 0x0190 state 378) */, + /* 1 */ 0x07 /* (to 0x019C state 393) */, +/* pos 0190: 378 */ /* 0 */ 0x01 /* (to 0x0192 state 379) */, + /* 1 */ 0x05 /* (to 0x019A state 390) */, +/* pos 0192: 379 */ /* terminal 178 */ 0xB2, + /* terminal 181 */ 0xB5, +/* pos 0194: 381 */ /* terminal 179 */ 0xB3, + /* terminal 209 */ 0xD1, +/* pos 0196: 385 */ /* terminal 182 */ 0xB6, + /* terminal 183 */ 0xB7, +/* pos 0198: 388 */ /* terminal 184 */ 0xB8, + /* terminal 194 */ 0xC2, +/* pos 019a: 390 */ /* terminal 185 */ 0xB9, + /* terminal 186 */ 0xBA, +/* pos 019c: 393 */ /* 0 */ 0x01 /* (to 0x019E state 394) */, + /* 1 */ 0x04 /* (to 0x01A4 state 400) */, +/* pos 019e: 394 */ /* terminal 187 */ 0xBB, + /* terminal 189 */ 0xBD, +/* pos 01a0: 396 */ /* 0 */ 0x01 /* (to 0x01A2 state 397) */, + /* 1 */ 0x07 /* (to 0x01AE state 412) */, +/* pos 01a2: 397 */ /* terminal 188 */ 0xBC, + /* terminal 191 */ 0xBF, +/* pos 01a4: 400 */ /* terminal 190 */ 0xBE, + /* terminal 196 */ 0xC4, +/* pos 01a6: 403 */ /* 0 */ 0x01 /* (to 0x01A8 state 404) */, + /* 1 */ 0x0D /* (to 0x01C0 state 427) */, +/* pos 01a8: 404 */ /* 0 */ 0x01 /* (to 0x01AA state 405) */, + /* 1 */ 0x0A /* (to 0x01BC state 424) */, +/* pos 01aa: 405 */ /* 0 */ 0x01 /* (to 0x01AC state 406) */, + /* 1 */ 0x08 /* (to 0x01BA state 421) */, +/* pos 01ac: 406 */ /* terminal 192 */ 0xC0, + /* terminal 193 */ 0xC1, +/* pos 01ae: 412 */ /* terminal 197 */ 0xC5, + /* terminal 231 */ 0xE7, +/* pos 01b0: 414 */ /* 0 */ 0x01 /* (to 0x01B2 state 415) */, + /* 1 */ 0x1B /* (to 0x01E6 state 475) */, +/* pos 01b2: 415 */ /* terminal 198 */ 0xC6, + /* terminal 228 */ 0xE4, +/* pos 01b4: 417 */ /* 0 */ 0x1B /* (to 0x01EA state 481) */, + /* 1 */ 0x01 /* (to 0x01B6 state 418) */, +/* pos 01b6: 418 */ /* 0 */ 0x01 /* (to 0x01B8 state 419) */, + /* 1 */ 0x19 /* (to 0x01E8 state 478) */, +/* pos 01b8: 419 */ /* terminal 199 */ 0xC7, + /* terminal 207 */ 0xCF, +/* pos 01ba: 421 */ /* terminal 200 */ 0xC8, + /* terminal 201 */ 0xC9, +/* pos 01bc: 424 */ /* 0 */ 0x01 /* (to 0x01BE state 425) */, + /* 1 */ 0x06 /* (to 0x01C8 state 438) */, +/* pos 01be: 425 */ /* terminal 202 */ 0xCA, + /* terminal 205 */ 0xCD, +/* pos 01c0: 427 */ /* 0 */ 0x0D /* (to 0x01DA state 455) */, + /* 1 */ 0x01 /* (to 0x01C2 state 428) */, +/* pos 01c2: 428 */ /* 0 */ 0x17 /* (to 0x01F0 state 490) */, + /* 1 */ 0x01 /* (to 0x01C4 state 429) */, +/* pos 01c4: 429 */ /* terminal 255 */ 0xFF, + /* 1 */ 0x01 /* (to 0x01C6 state 430) */, +/* pos 01c6: 430 */ /* terminal 203 */ 0xCB, + /* terminal 204 */ 0xCC, +/* pos 01c8: 438 */ /* terminal 210 */ 0xD2, + /* terminal 213 */ 0xD5, +/* pos 01ca: 440 */ /* 0 */ 0x01 /* (to 0x01CC state 441) */, + /* 1 */ 0x14 /* (to 0x01F2 state 494) */, +/* pos 01cc: 441 */ /* 0 */ 0x01 /* (to 0x01CE state 442) */, + /* 1 */ 0x09 /* (to 0x01DE state 461) */, +/* pos 01ce: 442 */ /* 0 */ 0x01 /* (to 0x01D0 state 443) */, + /* 1 */ 0x02 /* (to 0x01D2 state 447) */, +/* pos 01d0: 443 */ /* terminal 211 */ 0xD3, + /* terminal 212 */ 0xD4, +/* pos 01d2: 447 */ /* terminal 214 */ 0xD6, + /* terminal 221 */ 0xDD, +/* pos 01d4: 449 */ /* terminal 215 */ 0xD7, + /* terminal 225 */ 0xE1, +/* pos 01d6: 451 */ /* 0 */ 0x01 /* (to 0x01D8 state 452) */, + /* 1 */ 0x07 /* (to 0x01E4 state 469) */, +/* pos 01d8: 452 */ /* terminal 216 */ 0xD8, + /* terminal 217 */ 0xD9, +/* pos 01da: 455 */ /* 0 */ 0x01 /* (to 0x01DC state 456) */, + /* 1 */ 0x09 /* (to 0x01EC state 484) */, +/* pos 01dc: 456 */ /* terminal 218 */ 0xDA, + /* terminal 219 */ 0xDB, +/* pos 01de: 461 */ /* 0 */ 0x01 /* (to 0x01E0 state 462) */, + /* 1 */ 0x08 /* (to 0x01EE state 488) */, +/* pos 01e0: 462 */ /* terminal 222 */ 0xDE, + /* terminal 223 */ 0xDF, +/* pos 01e2: 465 */ /* terminal 224 */ 0xE0, + /* terminal 226 */ 0xE2, +/* pos 01e4: 469 */ /* terminal 227 */ 0xE3, + /* terminal 229 */ 0xE5, +/* pos 01e6: 475 */ /* terminal 232 */ 0xE8, + /* terminal 233 */ 0xE9, +/* pos 01e8: 478 */ /* terminal 234 */ 0xEA, + /* terminal 235 */ 0xEB, +/* pos 01ea: 481 */ /* terminal 236 */ 0xEC, + /* terminal 237 */ 0xED, +/* pos 01ec: 484 */ /* terminal 238 */ 0xEE, + /* terminal 240 */ 0xF0, +/* pos 01ee: 488 */ /* terminal 241 */ 0xF1, + /* terminal 244 */ 0xF4, +/* pos 01f0: 490 */ /* terminal 242 */ 0xF2, + /* terminal 243 */ 0xF3, +/* pos 01f2: 494 */ /* 0 */ 0x01 /* (to 0x01F4 state 495) */, + /* 1 */ 0x04 /* (to 0x01FA state 503) */, +/* pos 01f4: 495 */ /* 0 */ 0x01 /* (to 0x01F6 state 496) */, + /* 1 */ 0x02 /* (to 0x01F8 state 499) */, +/* pos 01f6: 496 */ /* terminal 245 */ 0xF5, + /* terminal 246 */ 0xF6, +/* pos 01f8: 499 */ /* terminal 247 */ 0xF7, + /* terminal 248 */ 0xF8, +/* pos 01fa: 503 */ /* 0 */ 0x01 /* (to 0x01FC state 504) */, + /* 1 */ 0x02 /* (to 0x01FE state 507) */, +/* pos 01fc: 504 */ /* terminal 250 */ 0xFA, + /* terminal 251 */ 0xFB, +/* pos 01fe: 507 */ /* terminal 252 */ 0xFC, + /* terminal 253 */ 0xFD, +/* total size 512 bytes, biggest jump 200/256, fails=0 */ +}; + + static unsigned char lextable_terms[] = { + + 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x03, 0x00, + 0x34, 0x0f, 0x43, 0x03, 0xf1, 0x3c, 0xfc, 0x3c, + 0x0f, 0x30, 0x37, 0xf7, 0x0f, 0xc3, 0xcf, 0x03, + 0x3c, 0xfc, 0xc0, 0xf3, 0xf0, 0x3c, 0xfc, 0xf0, + 0xcf, 0xfc, 0xcc, 0xff, 0xfc, 0x0d, 0x34, 0xcc, + 0xcf, 0x33, 0xf0, 0x33, 0x0c, 0x3f, 0xc3, 0x3f, + 0xcc, 0x30, 0xfc, 0xcf, 0x3c, 0xf0, 0x0c, 0xcf, + 0xd0, 0x03, 0x3f, 0x33, 0xff, 0xff, 0xc3, 0xf3, +}; diff --git a/lib/minihuf.c b/lib/minihuf.c new file mode 100644 index 00000000..9f7b970e --- /dev/null +++ b/lib/minihuf.c @@ -0,0 +1,510 @@ +/* + * minilex.c + * + * High efficiency lexical state parser + * + * Copyright (C)2011-2014 Andy Green + * + * Licensed under LGPL2 + * + * Usage: gcc minihuf.c -o minihuf && ./minihuf > huftable.h + * + * Run it twice to test parsing on the generated table on stderr + */ + +#include +#include +#include + +#define ARRAY_SIZE(n) (sizeof(n) / sizeof(n[0])) + +struct huf { + unsigned int code; + unsigned char len; +}; + +static struct huf huf_literal[] = { + /* 0x00 */ { 0x1ff8, 13 }, + /* 0x01 */ { 0x7fffd8, 23 }, + /* 0x02 */ { 0xfffffe2, 28 }, + /* 0x03 */ { 0xfffffe3, 28 }, + /* 0x04 */ { 0xfffffe4, 28 }, + /* 0x05 */ { 0xfffffe5, 28 }, + /* 0x06 */ { 0xfffffe6, 28 }, + /* 0x07 */ { 0xfffffe7, 28 }, + /* 0x08 */ { 0xfffffe8, 28 }, + /* 0x09 */ { 0xffffea, 24 }, + /* 0x0a */ { 0x3ffffffc, 30 }, + /* 0x0b */ { 0xfffffe9, 28 }, + + /* 0x0c */ { 0xfffffea, 28 }, + /* 0x0d */ { 0x3ffffffd, 30 }, + /* 0x0e */ { 0xfffffeb, 28 }, + /* 0x0f */ { 0xfffffec, 28 }, + /* 0x10 */ { 0xfffffed, 28 }, + /* 0x11 */ { 0xfffffee, 28 }, + /* 0x12 */ { 0xfffffef, 28 }, + /* 0x13 */ { 0xffffff0, 28 }, + /* 0x14 */ { 0xffffff1, 28 }, + /* 0x15 */ { 0xffffff2, 28 }, + /* 0x16 */ { 0x3ffffffe, 30 }, + /* 0x17 */ { 0xffffff3, 28 }, + /* 0x18 */ { 0xffffff4, 28 }, + /* 0x19 */ { 0xffffff5, 28 }, + /* 0x1a */ { 0xffffff6, 28 }, + /* 0x1b */ { 0xffffff7, 28 }, + /* 0x1c */ { 0xffffff8, 28 }, + /* 0x1d */ { 0xffffff9, 28 }, + /* 0x1e */ { 0xffffffa, 28 }, + /* 0x1f */ { 0xffffffb, 28 }, + /* 0x20 */ { 0x14, 6 }, + /* 0x21 */ { 0x3f8, 10 }, + /* 0x22 */ { 0x3f9, 10 }, + /* 0x23 */ { 0xffa, 12 }, + /* 0x24 */ { 0x1ff9, 13 }, + /* 0x25 */ { 0x15, 6 }, + /* 0x26 */ { 0xf8, 8 }, + /* 0x27 */ { 0x7fa, 11 }, + /* 0x28 */ { 0x3fa, 10 }, + /* 0x29 */ { 0x3fb, 10 }, + /* 0x2a */ { 0xf9, 8 }, + /* 0x2b */ { 0x7fb, 11 }, + /* 0x2c */ { 0xfa, 8 }, + /* 0x2d */ { 0x16, 6 }, + /* 0x2e */ { 0x17, 6 }, + /* 0x2f */ { 0x18, 6 }, + /* 0x30 */ { 0x0, 5 }, + /* 0x31 */ { 0x1, 5 }, + /* 0x32 */ { 0x2, 5 }, + /* 0x33 */ { 0x19, 6 }, + /* 0x34 */ { 0x1a, 6 }, + /* 0x35 */ { 0x1b, 6 }, + /* 0x36 */ { 0x1c, 6 }, + /* 0x37 */ { 0x1d, 6 }, + /* 0x38 */ { 0x1e, 6 }, + /* 0x39 */ { 0x1f, 6 }, + /* 0x3a */ { 0x5c, 7 }, + /* 0x3b */ { 0xfb, 8 }, + + /* 0x3c */ { 0x7ffc, 15 }, + /* 0x3d */ { 0x20, 6 }, + /* 0x3e */ { 0xffb, 12 }, + /* 0x3f */ { 0x3fc, 10 }, + /* 0x40 */ { 0x1ffa, 13 }, + /* 0x41 */ { 0x21, 6 }, + /* 0x42 */ { 0x5d, 7 }, + /* 0x43 */ { 0x5e, 7 }, + /* 0x44 */ { 0x5f, 7 }, + /* 0x45 */ { 0x60, 7 }, + /* 0x46 */ { 0x61, 7 }, + /* 0x47 */ { 0x62, 7 }, + /* 0x48 */ { 0x63, 7 }, + /* 0x49 */ { 0x64, 7 }, + /* 0x4a */ { 0x65, 7 }, + /* 0x4b */ { 0x66, 7 }, + /* 0x4c */ { 0x67, 7 }, + /* 0x4d */ { 0x68, 7 }, + /* 0x4e */ { 0x69, 7 }, + /* 0x4f */ { 0x6a, 7 }, + /* 0x50 */ { 0x6b, 7 }, + /* 0x51 */ { 0x6c, 7 }, + /* 0x52 */ { 0x6d, 7 }, + /* 0x53 */ { 0x6e, 7 }, + /* 0x54 */ { 0x6f, 7 }, + /* 0x55 */ { 0x70, 7 }, + /* 0x56 */ { 0x71, 7 }, + /* 0x57 */ { 0x72, 7 }, + /* 0x58 */ { 0xfc, 8 }, + /* 0x59 */ { 0x73, 7 }, + /* 0x5a */ { 0xfd, 8 }, + /* 0x5b */ { 0x1ffb, 13 }, + /* 0x5c */ { 0x7fff0, 19 }, + /* 0x5d */ { 0x1ffc, 13 }, + /* 0x5e */ { 0x3ffc, 14 }, + /* 0x5f */ { 0x22, 6 }, + /* 0x60 */ { 0x7ffd, 15 }, + /* 0x61 */ { 0x3, 5 }, + /* 0x62 */ { 0x23, 6 }, + /* 0x63 */ { 0x4, 5 }, + /* 0x64 */ { 0x24, 6 }, + /* 0x65 */ { 0x5, 5 }, + /* 0x66 */ { 0x25, 6 }, + /* 0x67 */ { 0x26, 6 }, + /* 0x68 */ { 0x27, 6 }, + /* 0x69 */ { 0x6, 5 }, + /* 0x6a */ { 0x74, 7 }, + /* 0x6b */ { 0x75, 7 }, + + + /* 0x6c */ { 0x28, 6 }, + /* 0x6d */ { 0x29, 6 }, + /* 0x6e */ { 0x2a, 6 }, + /* 0x6f */ { 0x7, 5 }, + /* 0x70 */ { 0x2b, 6 }, + /* 0x71 */ { 0x76, 7 }, + /* 0x72 */ { 0x2c, 6 }, + /* 0x73 */ { 0x8, 5 }, + /* 0x74 */ { 0x9, 5 }, + /* 0x75 */ { 0x2d, 6 }, + /* 0x76 */ { 0x77, 7 }, + /* 0x77 */ { 0x78, 7 }, + /* 0x78 */ { 0x79, 7 }, + /* 0x79 */ { 0x7a, 7 }, + /* 0x7a */ { 0x7b, 7 }, + /* 0x7b */ { 0x7ffe, 15 }, + /* 0x7c */ { 0x7fc, 11 }, + /* 0x7d */ { 0x3ffd, 14 }, + /* 0x7e */ { 0x1ffd, 13 }, + /* 0x7f */ { 0xffffffc, 28 }, + /* 0x80 */ { 0xfffe6, 20 }, + /* 0x81 */ { 0x3fffd2, 22 }, + /* 0x82 */ { 0xfffe7, 20 }, + /* 0x83 */ { 0xfffe8, 20 }, + /* 0x84 */ { 0x3fffd3, 22 }, + /* 0x85 */ { 0x3fffd4, 22 }, + /* 0x86 */ { 0x3fffd5, 22 }, + /* 0x87 */ { 0x7fffd9, 23 }, + /* 0x88 */ { 0x3fffd6, 22 }, + /* 0x89 */ { 0x7fffda, 23 }, + /* 0x8a */ { 0x7fffdb, 23 }, + /* 0x8b */ { 0x7fffdc, 23 }, + /* 0x8c */ { 0x7fffdd, 23 }, + /* 0x8d */ { 0x7fffde, 23 }, + /* 0x8e */ { 0xffffeb, 24 }, + /* 0x8f */ { 0x7fffdf, 23 }, + /* 0x90 */ { 0xffffec, 24 }, + /* 0x91 */ { 0xffffed, 24 }, + /* 0x92 */ { 0x3fffd7, 22 }, + /* 0x93 */ { 0x7fffe0, 23 }, + /* 0x94 */ { 0xffffee, 24 }, + /* 0x95 */ { 0x7fffe1, 23 }, + /* 0x96 */ { 0x7fffe2, 23 }, + /* 0x97 */ { 0x7fffe3, 23 }, + /* 0x98 */ { 0x7fffe4, 23 }, + /* 0x99 */ { 0x1fffdc, 21 }, + /* 0x9a */ { 0x3fffd8, 22 }, + /* 0x9b */ { 0x7fffe5, 23 }, + + /* 0x9c */ { 0x3fffd9, 22 }, + /* 0x9d */ { 0x7fffe6, 23 }, + /* 0x9e */ { 0x7fffe7, 23 }, + /* 0x9f */ { 0xffffef, 24 }, + /* 0xa0 */ { 0x3fffda, 22 }, + /* 0xa1 */ { 0x1fffdd, 21 }, + /* 0xa2 */ { 0xfffe9, 20 }, + /* 0xa3 */ { 0x3fffdb, 22 }, + /* 0xa4 */ { 0x3fffdc, 22 }, + /* 0xa5 */ { 0x7fffe8, 23 }, + /* 0xa6 */ { 0x7fffe9, 23 }, + /* 0xa7 */ { 0x1fffde, 21 }, + /* 0xa8 */ { 0x7fffea, 23 }, + /* 0xa9 */ { 0x3fffdd, 22 }, + /* 0xaa */ { 0x3fffde, 22 }, + /* 0xab */ { 0xfffff0, 24 }, + /* 0xac */ { 0x1fffdf, 21 }, + /* 0xad */ { 0x3fffdf, 22 }, + /* 0xae */ { 0x7fffeb, 23 }, + /* 0xaf */ { 0x7fffec, 23 }, + /* 0xb0 */ { 0x1fffe0, 21 }, + /* 0xb1 */ { 0x1fffe1, 21 }, + /* 0xb2 */ { 0x3fffe0, 22 }, + /* 0xb3 */ { 0x1fffe2, 21 }, + /* 0xb4 */ { 0x7fffed, 23 }, + /* 0xb5 */ { 0x3fffe1, 22 }, + /* 0xb6 */ { 0x7fffee, 23 }, + /* 0xb7 */ { 0x7fffef, 23 }, + /* 0xb8 */ { 0xfffea, 20 }, + /* 0xb9 */ { 0x3fffe2, 22 }, + /* 0xba */ { 0x3fffe3, 22 }, + /* 0xbb */ { 0x3fffe4, 22 }, + /* 0xbc */ { 0x7ffff0, 23 }, + /* 0xbd */ { 0x3fffe5, 22 }, + /* 0xbe */ { 0x3fffe6, 22 }, + /* 0xbf */ { 0x7ffff1, 23 }, + /* 0xc0 */ { 0x3ffffe0, 26 }, + /* 0xc1 */ { 0x3ffffe1, 26 }, + /* 0xc2 */ { 0xfffeb, 20 }, + /* 0xc3 */ { 0x7fff1, 19 }, + /* 0xc4 */ { 0x3fffe7, 22 }, + /* 0xc5 */ { 0x7ffff2, 23 }, + /* 0xc6 */ { 0x3fffe8, 22 }, + /* 0xc7 */ { 0x1ffffec, 25 }, + /* 0xc8 */ { 0x3ffffe2, 26 }, + /* 0xc9 */ { 0x3ffffe3, 26 }, + /* 0xca */ { 0x3ffffe4, 26 }, + /* 0xcb */ { 0x7ffffde, 27 }, + + /* 0xcc */ { 0x7ffffdf, 27 }, + /* 0xcd */ { 0x3ffffe5, 26 }, + /* 0xce */ { 0xfffff1, 24 }, + /* 0xcf */ { 0x1ffffed, 25 }, + /* 0xd0 */ { 0x7fff2, 19 }, + /* 0xd1 */ { 0x1fffe3, 21 }, + /* 0xd2 */ { 0x3ffffe6, 26 }, + /* 0xd3 */ { 0x7ffffe0, 27 }, + /* 0xd4 */ { 0x7ffffe1, 27 }, + /* 0xd5 */ { 0x3ffffe7, 26 }, + /* 0xd6 */ { 0x7ffffe2, 27 }, + /* 0xd7 */ { 0xfffff2, 24 }, + /* 0xd8 */ { 0x1fffe4, 21 }, + /* 0xd9 */ { 0x1fffe5, 21 }, + /* 0xda */ { 0x3ffffe8, 26 }, + /* 0xdb */ { 0x3ffffe9, 26 }, + /* 0xdc */ { 0xffffffd, 28 }, + /* 0xdd */ { 0x7ffffe3, 27 }, + /* 0xde */ { 0x7ffffe4, 27 }, + /* 0xdf */ { 0x7ffffe5, 27 }, + /* 0xe0 */ { 0xfffec, 20 }, + /* 0xe1 */ { 0xfffff3, 24 }, + /* 0xe2 */ { 0xfffed, 20 }, + /* 0xe3 */ { 0x1fffe6, 21 }, + /* 0xe4 */ { 0x3fffe9, 22 }, + /* 0xe5 */ { 0x1fffe7, 21 }, + /* 0xe6 */ { 0x1fffe8, 21 }, + /* 0xe7 */ { 0x7ffff3, 23 }, + /* 0xe8 */ { 0x3fffea, 22 }, + /* 0xe9 */ { 0x3fffeb, 22 }, + /* 0xea */ { 0x1ffffee, 25 }, + /* 0xeb */ { 0x1ffffef, 25 }, + /* 0xec */ { 0xfffff4, 24 }, + /* 0xed */ { 0xfffff5, 24 }, + /* 0xee */ { 0x3ffffea, 26 }, + /* 0xef */ { 0x7ffff4, 23 }, + /* 0xf0 */ { 0x3ffffeb, 26 }, + /* 0xf1 */ { 0x7ffffe6, 27 }, + /* 0xf2 */ { 0x3ffffec, 26 }, + /* 0xf3 */ { 0x3ffffed, 26 }, + /* 0xf4 */ { 0x7ffffe7, 27 }, + /* 0xf5 */ { 0x7ffffe8, 27 }, + /* 0xf6 */ { 0x7ffffe9, 27 }, + /* 0xf7 */ { 0x7ffffea, 27 }, + /* 0xf8 */ { 0x7ffffeb, 27 }, + /* 0xf9 */ { 0xffffffe, 28 }, + /* 0xfa */ { 0x7ffffec, 27 }, + /* 0xfb */ { 0x7ffffed, 27 }, + + /* 0xfc */ { 0x7ffffee, 27 }, + /* 0xfd */ { 0x7ffffef, 27 }, + /* 0xfe */ { 0x7fffff0, 27 }, + /* 0xff */ { 0x3ffffee, 26 }, + /* 0x100 */ { 0x3fffffff, 30 }, +}; + +int code_bit(int idx, int bit) +{ + if (bit < huf_literal[idx].len) + return !!(huf_literal[idx].code & (1 << (huf_literal[idx].len - 1 - bit))); + + return -1; +} + +#include "huftable.h" + +#define PARALLEL 2 + +struct state { + int terminal; + int state[PARALLEL]; + int bytepos; + + int real_pos; +}; + +struct state state[2000]; +unsigned char terms[2000]; +int next = 1; + +int lextable_decode(int pos, char c) +{ + int q = pos + !!c; + + if (lextable_terms[q >> 3] & (1 << (q & 7))) /* terminal */ + return lextable[q] | 0x8000; + + return pos + (lextable[q] << 1); +} + +int main(void) +{ + int n = 0; + int m = 0; + int prev; + char c; + int walk; + int saw; + int y; + int j; + int q; + int pos = 0; + int biggest = 0; + int fails = 0; + + m = 0; + while (m < ARRAY_SIZE(state)) { + for (j = 0; j < PARALLEL; j++) { + state[m].state[j] = 0xffff; + state[m].terminal = 0; + } + m++; + } + + while (n < ARRAY_SIZE(huf_literal)) { + + m = 0; + walk = 0; + prev = 0; + + while (m < huf_literal[n].len) { + + saw = 0; + if (state[walk].state[code_bit(n, m)] != 0xffff) { + /* exists -- go forward */ + walk = state[walk].state[code_bit(n, m)]; + goto again; + } + + /* something we didn't see before */ + + state[walk].state[code_bit(n, m)] = next; + walk = next++; +again: + m++; + } + + state[walk].terminal = n++; + state[walk].state[0] = 0; /* terminal marker */ + } + + walk = 0; + for (n = 0; n < next; n++) { + state[n].bytepos = walk; + walk += (2 * 2); + } + + /* compute everyone's position first */ + + pos = 0; + walk = 0; + for (n = 0; n < next; n++) { + + state[n].real_pos = pos; + + if (state[n].state[0]) /* nonterminal */ + pos += 2; + + walk ++; + } + + fprintf(stdout, "static unsigned char lextable[] = {\n"); + +#define TERMINAL_MASK 0x8000 + + walk = 0; + pos = 0; + q = 0; + for (n = 0; n < next; n++) { + q = pos; + for (m = 0; m < 2; m++) { + saw = state[n].state[m]; + + if (saw == 0) { // c is a terminal then + m = 2; + continue; + } + if (!m) + fprintf(stdout, "/* pos %04x: %3d */ ", + state[n].real_pos, n); + else + fprintf(stdout, " "); + + if (saw == 0xffff) { + fprintf(stdout, + " 0xff, 0xff, /* 0 = fail */\n "); + pos ++; /* fail */ + fails++; + continue; + } + + if (state[saw].state[0] == 0) { /* points to terminal */ + fprintf(stdout, " /* terminal %d */ 0x%02X,\n", + state[saw].terminal, + state[saw].terminal & 0xff); + terms[(state[n].real_pos + m) >> 3] |= + 1 << ((state[n].real_pos + m) & 7); + pos++; + walk++; + continue; + } + + j = (state[saw].real_pos - q) >> 1; + + if (j > biggest) + biggest = j; + + if (j > 0xffff) { + fprintf(stderr, + "Jump > 64K bytes ahead (%d to %d)\n", + state[n].real_pos, state[saw].real_pos); + return 1; + } + + fprintf(stdout, " /* %d */ 0x%02X " + "/* (to 0x%04X state %3d) */,\n", + m, + j & 0xff, + state[saw].real_pos, saw); + pos++; + + walk++; + } + } + + fprintf(stdout, "/* total size %d bytes, biggest jump %d/256, fails=%d */\n};\n" + "\n static unsigned char lextable_terms[] = {\n", + pos, biggest, fails); + + for (n = 0; n < (walk + 7) / 8; n++) { + if (!(n & 7)) + fprintf(stdout, "\n\t"); + fprintf(stdout, "0x%02x, ", terms[n]); + } + fprintf(stdout, "\n};\n"); + + /* + * Try to parse every legal input string + */ + + for (n = 0; n < ARRAY_SIZE(huf_literal); n++) { + walk = 0; + m = 0; + y = -1; + + fprintf(stderr, " trying %d\n", n); + + while (m < huf_literal[n].len) { + walk = lextable_decode(walk, code_bit(n, m)); + + if (walk == 0xffff) { + fprintf(stderr, "failed\n"); + return 3; + } + + if (walk & 0x8000) { + y = walk & 0x7fff; + if (y == 0 && m == 29) + y |= 0x100; + break; + } + m++; + } + + if (y != n) { + fprintf(stderr, "decode failed %d got %d (0x%x)\n", n, y, y); + return 4; + } + } + + fprintf(stderr, "All decode OK\n"); + + return 0; +}