]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/check/crc64_tablegen.c
Imported to git.
[icculus/xz.git] / src / liblzma / check / crc64_tablegen.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       crc64_tablegen.c
4 /// \brief      Generates CRC64 crc64_table.c
5 ///
6 /// Compiling: gcc -std=c99 -o crc64_tablegen crc64_tablegen.c crc64_init.c
7 /// Add -DWORDS_BIGENDIAN to generate big endian table.
8 //
9 //  This code has been put into the public domain.
10 //
11 //  This library 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.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16
17 #include <sys/types.h>
18 #include <inttypes.h>
19 #include <stdio.h>
20
21
22 extern void lzma_crc64_init(void);
23
24 extern uint64_t lzma_crc64_table[4][256];
25
26
27 int
28 main()
29 {
30         lzma_crc64_init();
31
32         printf("/* This file has been automatically generated by "
33                         "crc64_tablegen.c. */\n\n"
34                         "#include <inttypes.h>\n\n"
35                         "const uint64_t lzma_crc64_table[4][256] = {\n\t{");
36
37         for (size_t s = 0; s < 4; ++s) {
38                 for (size_t b = 0; b < 256; ++b) {
39                         if ((b % 2) == 0)
40                                 printf("\n\t\t");
41
42                         printf("UINT64_C(0x%016" PRIX64 ")",
43                                         lzma_crc64_table[s][b]);
44
45                         if (b != 255)
46                                 printf(", ");
47                 }
48
49                 if (s == 3)
50                         printf("\n\t}\n};\n");
51                 else
52                         printf("\n\t}, {");
53         }
54
55         return 0;
56 }