2 * compress_upcase_table.c
4 * Compress a table that maps each UCS-2 character to its upper case equivalent.
6 * ----------------------------------------------------------------------------
8 * Copyright (C) 2015 Eric Biggers
10 * This file is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU Lesser General Public License as published by the Free
12 * Software Foundation; either version 3 of the License, or (at your option) any
15 * This file is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this file; if not, see http://www.gnu.org/licenses/.
31 #define SIZE (65536 * sizeof(uint16_t))
34 match_length(const uint16_t *p1, const uint16_t *p2, uint16_t max_len)
38 while (len < max_len && p1[len] == p2[len])
45 longest_match(const uint16_t *tab, uint16_t cur_pos,
46 uint16_t *len_ret, uint16_t *src_pos_ret)
48 uint16_t max_len = LEN - cur_pos;
52 for (src_pos = 0; src_pos < cur_pos; src_pos++) {
53 /* check for match at this pos */
54 uint16_t len = match_length(&tab[cur_pos], &tab[src_pos], max_len);
57 *src_pos_ret = src_pos;
65 printf("0x%04x, ", v);
70 int fd = open("upcase.tab", O_RDONLY);
72 fprintf(stderr, "ERROR: upcase.tab not found\n");
75 uint16_t *tab = mmap(NULL, SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
79 for (i = 0; i < LEN; i++)
82 /* Simple LZ encoder */
83 for (i = 0; i < LEN; ) {
84 uint16_t len, src_pos;
85 longest_match(tab, i, &len, &src_pos);