mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-28 05:54:19 -04:00
eci.c: replace libiconv-adapted code with own implementations so
as to fully comply with BSD license (for why Library GPL 2+ not compatible see https://opensource.stackexchange.com/a/6701), ~3% slower (maybe), +~6K extra in data (gb18030.c, gb2313.c & sjis.c removed, mapping .TXT files moved to backend/tools/data & extra ones added, 2 new PHP generators) GUI: CODE39/EXCODE39: show/hide HIBC check digit option in addition to enable/disable (less confusing) CLI: batch: pedantic check for EOF using intChar in newline fgetc() loop test_args.c: don't use WIFEXITED(), WEXITSTATUS() on Windows manual: lessen some copy/paste verbiage by referring back, other small tweaks/typos
This commit is contained in:
parent
d9f2e85246
commit
ab3cf4f395
69 changed files with 61287 additions and 11905 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2021-2022 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
@ -27,51 +27,120 @@
|
|||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
*/
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
||||
#include "testcommon.h"
|
||||
#include "test_big5_tab.h"
|
||||
#include "../big5.h"
|
||||
/* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */
|
||||
//#define TEST_JUST_SAY_GNO
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
#include "../just_say_gno/big5_gnu.h"
|
||||
#endif
|
||||
|
||||
INTERNAL int u_big5_test(const unsigned int u, unsigned char *dest);
|
||||
|
||||
// Version of `u_big5()` taking unsigned int destination for backward-compatible testing
|
||||
static int u_big5_int(unsigned int u, unsigned int *d) {
|
||||
unsigned char dest[2];
|
||||
int ret = u_big5_test(u, dest);
|
||||
if (ret) {
|
||||
*d = ret == 1 ? dest[0] : ((dest[0] << 8) | dest[1]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// As control convert to Big5 using simple table generated from https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/OTHER/BIG5.TXT plus simple processing
|
||||
static int big5_wctomb_zint2(unsigned int *r, unsigned int wc) {
|
||||
static int u_big5_int2(unsigned int u, unsigned int *dest) {
|
||||
int tab_length = ARRAY_SIZE(test_big5_tab);
|
||||
int start_i = test_big5_tab_ind[wc >> 10];
|
||||
int start_i = test_big5_tab_ind[u >> 10];
|
||||
int end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800;
|
||||
int i;
|
||||
if (wc < 0x80) {
|
||||
return 0;
|
||||
if (u < 0x80) {
|
||||
*dest = u;
|
||||
return 1;
|
||||
}
|
||||
for (i = start_i; i < end_i; i += 2) {
|
||||
if (test_big5_tab[i + 1] == wc) {
|
||||
*r = test_big5_tab[i];
|
||||
return *r > 0xFF ? 2 : 1;
|
||||
if (test_big5_tab[i + 1] == u) {
|
||||
*dest = test_big5_tab[i];
|
||||
return *dest > 0xFF ? 2 : 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_big5_wctomb_zint(void) {
|
||||
#include <time.h>
|
||||
|
||||
#define TEST_PERF_TIME(arg) (((arg) * 1000.0) / CLOCKS_PER_SEC)
|
||||
#define TEST_PERF_RATIO(a1, a2) (a2 ? TEST_PERF_TIME(a1) / TEST_PERF_TIME(a2) : 0)
|
||||
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
#define TEST_INT_PERF_ITERATIONS 100
|
||||
#endif
|
||||
|
||||
static void test_u_big5_int(int debug) {
|
||||
|
||||
unsigned int i;
|
||||
int ret, ret2;
|
||||
unsigned int val, val2;
|
||||
|
||||
testStart("test_big5_wctomb_zint");
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
int j;
|
||||
clock_t start;
|
||||
clock_t total = 0, total_gno = 0;
|
||||
#else
|
||||
(void)debug;
|
||||
#endif
|
||||
|
||||
testStart("test_u_big5_int");
|
||||
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
if ((debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
printf("test_u_big5_int perf iterations: %d\n", TEST_INT_PERF_ITERATIONS);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 0xFFFE; i++) {
|
||||
if (i >= 0xD800 && i < 0xE000) { // UTF-16 surrogates
|
||||
continue;
|
||||
}
|
||||
val = val2 = 0;
|
||||
ret = big5_wctomb_zint(&val, i);
|
||||
ret2 = big5_wctomb_zint2(&val2, i);
|
||||
ret = u_big5_int(i, &val);
|
||||
ret2 = u_big5_int2(i, &val2);
|
||||
assert_equal(ret, ret2, "i:%d 0x%04X ret %d != ret2 %d, val 0x%04X, val2 0x%04X\n", (int) i, i, ret, ret2, val, val2);
|
||||
if (ret2) {
|
||||
assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2);
|
||||
}
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
val2 = 0;
|
||||
ret2 = big5_wctomb_zint(&val2, i);
|
||||
} else {
|
||||
for (j = 0; j < TEST_INT_PERF_ITERATIONS; j++) {
|
||||
val = val2 = 0;
|
||||
|
||||
start = clock();
|
||||
ret = u_big5_int(i, &val);
|
||||
total += clock() - start;
|
||||
|
||||
start = clock();
|
||||
ret2 = big5_wctomb_zint(&val2, i);
|
||||
total_gno += clock() - start;
|
||||
}
|
||||
}
|
||||
|
||||
assert_equal(ret, ret2, "i:%d 0x%04X ret %d != ret2 %d, val 0x%04X, val2 0x%04X\n", (int) i, i, ret, ret2, val, val2);
|
||||
if (ret2) {
|
||||
assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
if ((debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
printf("test_u_big5_int perf totals: new % 8gms, gno % 8gms ratio %g\n",
|
||||
TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno));
|
||||
}
|
||||
#endif
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
|
@ -92,7 +161,7 @@ static int big5_utf8(struct zint_symbol *symbol, const unsigned char source[], i
|
|||
}
|
||||
|
||||
for (i = 0, length = *p_length; i < length; i++) {
|
||||
if (!big5_wctomb_zint(b5data + i, utfdata[i])) {
|
||||
if (!u_big5_int(utfdata[i], b5data + i)) {
|
||||
strcpy(symbol->errtxt, "800: Invalid character in input data");
|
||||
return ZINT_ERROR_INVALID_DATA;
|
||||
}
|
||||
|
@ -150,7 +219,7 @@ static void test_big5_utf8(int index) {
|
|||
int main(int argc, char *argv[]) {
|
||||
|
||||
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
|
||||
{ "test_big5_wctomb_zint", test_big5_wctomb_zint, 0, 0, 0 },
|
||||
{ "test_u_big5_int", test_u_big5_int, 0, 0, 1 },
|
||||
{ "test_big5_utf8", test_big5_utf8, 1, 0, 0 },
|
||||
};
|
||||
|
||||
|
@ -160,3 +229,5 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4 et : */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue