mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-27 21:44:13 -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) 2019 - 2021 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2019-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,87 +27,142 @@
|
|||
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_sjis_tab.h"
|
||||
#include "../sjis.h"
|
||||
#include "../eci.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/sjis_gnu.c"
|
||||
#endif
|
||||
|
||||
INTERNAL int u_sjis_int_test(const unsigned int u, unsigned int *dest);
|
||||
|
||||
// As control convert to Shift JIS using simple table generated from https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/SHIFTJIS.TXT plus simple processing
|
||||
static int sjis_wctomb_zint2(unsigned int *r, unsigned int wc) {
|
||||
static int u_sjis_int2(unsigned int u, unsigned int *dest) {
|
||||
int tab_length, start_i, end_i;
|
||||
int i;
|
||||
if (wc < 0x20 || wc == 0x7F) {
|
||||
*r = wc;
|
||||
if (u < 0x20 || u == 0x7F) {
|
||||
*dest = u;
|
||||
return 1;
|
||||
}
|
||||
// Shortcut
|
||||
if ((wc > 0x00F7 && wc < 0x0391) || (wc > 0x0451 && wc < 0x2010) || (wc > 0x9FA0 && wc < 0xE000) || (wc > 0xE757 && wc < 0xFF01) || wc > 0xFFE5) {
|
||||
if ((u > 0x00F7 && u < 0x0391) || (u > 0x0451 && u < 0x2010) || (u > 0x9FA0 && u < 0xE000) || (u > 0xE757 && u < 0xFF01) || u > 0xFFE5) {
|
||||
return 0;
|
||||
}
|
||||
if (wc >= 0xE000 && wc <= 0xE757) { // PUA mappings, not in SHIFTJIS.TXT
|
||||
if (wc <= 0xE0BB) {
|
||||
*r = wc - 0xE000 + 0xF040 + (wc >= 0xE000 + 0x3F);
|
||||
} else if (wc <= 0xE177) {
|
||||
*r = wc - 0xE0BC + 0xF140 + (wc >= 0xE0BC + 0x3F);
|
||||
} else if (wc <= 0xE233) {
|
||||
*r = wc - 0xE178 + 0xF240 + (wc >= 0xE178 + 0x3F);
|
||||
} else if (wc <= 0xE2EF) {
|
||||
*r = wc - 0xE234 + 0xF340 + (wc >= 0xE234 + 0x3F);
|
||||
} else if (wc <= 0xE3AB) {
|
||||
*r = wc - 0xE2F0 + 0xF440 + (wc >= 0xE2F0 + 0x3F);
|
||||
} else if (wc <= 0xE467) {
|
||||
*r = wc - 0xE3AC + 0xF540 + (wc >= 0xE3AC + 0x3F);
|
||||
} else if (wc <= 0xE523) {
|
||||
*r = wc - 0xE468 + 0xF640 + (wc >= 0xE468 + 0x3F);
|
||||
} else if (wc <= 0xE5DF) {
|
||||
*r = wc - 0xE524 + 0xF740 + (wc >= 0xE524 + 0x3F);
|
||||
} else if (wc <= 0xE69B) {
|
||||
*r = wc - 0xE5E0 + 0xF840 + (wc >= 0xE5E0 + 0x3F);
|
||||
if (u >= 0xE000 && u <= 0xE757) { // PUA mappings, not in SHIFTJIS.TXT
|
||||
if (u <= 0xE0BB) {
|
||||
*dest = u - 0xE000 + 0xF040 + (u >= 0xE000 + 0x3F);
|
||||
} else if (u <= 0xE177) {
|
||||
*dest = u - 0xE0BC + 0xF140 + (u >= 0xE0BC + 0x3F);
|
||||
} else if (u <= 0xE233) {
|
||||
*dest = u - 0xE178 + 0xF240 + (u >= 0xE178 + 0x3F);
|
||||
} else if (u <= 0xE2EF) {
|
||||
*dest = u - 0xE234 + 0xF340 + (u >= 0xE234 + 0x3F);
|
||||
} else if (u <= 0xE3AB) {
|
||||
*dest = u - 0xE2F0 + 0xF440 + (u >= 0xE2F0 + 0x3F);
|
||||
} else if (u <= 0xE467) {
|
||||
*dest = u - 0xE3AC + 0xF540 + (u >= 0xE3AC + 0x3F);
|
||||
} else if (u <= 0xE523) {
|
||||
*dest = u - 0xE468 + 0xF640 + (u >= 0xE468 + 0x3F);
|
||||
} else if (u <= 0xE5DF) {
|
||||
*dest = u - 0xE524 + 0xF740 + (u >= 0xE524 + 0x3F);
|
||||
} else if (u <= 0xE69B) {
|
||||
*dest = u - 0xE5E0 + 0xF840 + (u >= 0xE5E0 + 0x3F);
|
||||
} else {
|
||||
*r = wc - 0xE69C + 0xF940 + (wc >= 0xE69C + 0x3F);
|
||||
*dest = u - 0xE69C + 0xF940 + (u >= 0xE69C + 0x3F);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
tab_length = sizeof(test_sjis_tab) / sizeof(unsigned int);
|
||||
start_i = test_sjis_tab_ind[wc >> 10];
|
||||
start_i = test_sjis_tab_ind[u >> 10];
|
||||
end_i = start_i + 0x800 > tab_length ? tab_length : start_i + 0x800;
|
||||
for (i = start_i; i < end_i; i += 2) {
|
||||
if (test_sjis_tab[i + 1] == wc) {
|
||||
*r = test_sjis_tab[i];
|
||||
return *r > 0xFF ? 2 : 1;
|
||||
if (test_sjis_tab[i + 1] == u) {
|
||||
*dest = test_sjis_tab[i];
|
||||
return *dest > 0xFF ? 2 : 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_sjis_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_sjis_int(int debug) {
|
||||
|
||||
int ret, ret2;
|
||||
unsigned int val, val2;
|
||||
unsigned int i;
|
||||
|
||||
testStart("test_sjis_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_sjis_int");
|
||||
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
if ((debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
printf("test_u_sjis_int perf iterations: %d\n", TEST_INT_PERF_ITERATIONS);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 0xFFFE; i++) {
|
||||
if (i >= 0xD800 && i <= 0xDFFF) { // UTF-16 surrogates
|
||||
continue;
|
||||
}
|
||||
val = val2 = 0;
|
||||
ret = sjis_wctomb_zint(&val, i);
|
||||
ret2 = sjis_wctomb_zint2(&val2, i);
|
||||
if (i == 0xFF3C) { // Extra mapping full-width reverse solidus U+FF3C to 0x815F, duplicate of U+005C (backslash)
|
||||
assert_equal(ret, 2, "i:%d 0x%04X ret %d != 2, val 0x%04X\n", (int) i, i, ret, val);
|
||||
assert_equal(val, 0x815F, "i:%d 0x%04X val 0x%04X != 0x815F\n", (int) i, i, val);
|
||||
assert_zero(ret2, "i:%d 0x%04X ret2 %d != 0, val2 0x%04X\n", (int) i, i, ret2, val2);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
ret = u_sjis_int_test(i, &val);
|
||||
ret2 = u_sjis_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 (i != 0xFF3C) { // Full-width reverse solidus duplicate no longer mapped to ignore
|
||||
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
val2 = 0;
|
||||
ret2 = sjis_wctomb_zint(&val2, i);
|
||||
} else {
|
||||
for (j = 0; j < TEST_INT_PERF_ITERATIONS; j++) {
|
||||
val = val2 = 0;
|
||||
|
||||
start = clock();
|
||||
ret = u_sjis_int_test(i, &val);
|
||||
total += clock() - start;
|
||||
|
||||
start = clock();
|
||||
ret2 = sjis_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_sjis_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();
|
||||
}
|
||||
|
||||
|
@ -128,7 +183,7 @@ static void test_sjis_utf8(int index) {
|
|||
// ・ U+FF65 half-width katakana, not in ISO/Win, in Shift JIS single-byte 0xA5 (\245), UTF-8 EFBDA5
|
||||
// ソ U+FF7F half-width katakana, not in ISO/Win, in Shift JIS single-byte 0xBF (\277), UTF-8 EFBDBF
|
||||
// ‾ U+203E overline, not in ISO/Win, in Shift JIS single-byte 0x7E (\176) (tilde), UTF-8 E280BE
|
||||
// \ U+FF3C full-width reverse solidus, in Shift JIS 0x815F, duplicate of mapping of U+005C, UTF-8 EFBCBC
|
||||
// \ U+FF3C full-width reverse solidus, in Shift JIS 0x815F, was duplicate of mapping of U+005C, UTF-8 EFBCBC
|
||||
// 点 U+70B9 kanji, in Shift JIS 0x935F (\223\137), UTF-8 E782B9
|
||||
// 茗 U+8317 kanji, in Shift JIS 0xE4AA (\344\252), UTF-8 E88C97
|
||||
// テ U+30C6 katakana, in Shift JIS 0x8365 (\203\145), UTF-8 E38386
|
||||
|
@ -138,8 +193,9 @@ static void test_sjis_utf8(int index) {
|
|||
/* 1*/ { "~", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" },
|
||||
/* 2*/ { "β", -1, 0, 1, { 0x83C0 }, "" },
|
||||
/* 3*/ { "¥", -1, 0, 1, { 0x5C }, "" },
|
||||
/* 4*/ { "aβcЖ¥・ソ‾\\\点茗テ", -1, 0, 13, { 'a', 0x83C0, 'c', 0x8447, 0x5C, 0xA5, 0xBF, 0x7E, 0x815F, 0x815F, 0x935F, 0xE4AA, 0x8365 }, "" },
|
||||
/* 5*/ { "\200", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "Invalid UTF-8" },
|
||||
/* 4*/ { "aβcЖ¥・ソ‾\\点茗テ", -1, 0, 12, { 'a', 0x83C0, 'c', 0x8447, 0x5C, 0xA5, 0xBF, 0x7E, 0x815F, 0x935F, 0xE4AA, 0x8365 }, "" },
|
||||
/* 5*/ { "\", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "U+FF3C full-width reverse solidus no longer duplicate mapping of U+005C" },
|
||||
/* 6*/ { "\200", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "Invalid UTF-8" },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
int i, length, ret;
|
||||
|
@ -310,13 +366,93 @@ static void test_sjis_cpy(int index) {
|
|||
testFinish();
|
||||
}
|
||||
|
||||
#define TEST_PERF_ITER_MILLES 100
|
||||
#define TEST_PERF_ITERATIONS (TEST_PERF_ITER_MILLES * 1000)
|
||||
|
||||
// Not a real test, just performance indicator
|
||||
static void test_perf(int index, int debug) {
|
||||
|
||||
struct item {
|
||||
char *data;
|
||||
int ret;
|
||||
|
||||
char *comment;
|
||||
};
|
||||
struct item data[] = {
|
||||
/* 0*/ { "1234567890", 0, "10 numerics" },
|
||||
/* 1*/ { "貫やぐ識禁ぱい再2間変字全ノレ没無8裁", 0, "Small mixed" },
|
||||
/* 2*/ { "貫やぐ識禁ぱい再2間変字全ノレ没無8裁花ほゃ過法ひなご札17能つーびれ投覧マ勝動エヨ額界よみ作皇ナヲニ打題ヌルヲ掲布益フが。入35能ト権話しこを断兆モヘ細情おじ名4減エヘイハ側機はょが意見想ハ業独案ユヲウ患職ヲ平美さ毎放どぽたけ家没べお化富べ町大シ情魚ッでれ一冬すぼめり。", 0, "Bigger mixed" },
|
||||
/* 3*/ { "貫やぐ識禁ぱい再2間変字全ノレ没無8裁花ほゃ過法ひなご札17能つーびれ投覧マ勝動エヨ額界よみ作皇ナヲニ打題ヌルヲ掲布益フが。入35能ト権話しこを断兆モヘ細情おじ名4減エヘイハ側機はょが意見想ハ業独案ユヲウ患職ヲ平美さ毎放どぽたけ家没べお化富べ町大シ情魚ッでれ一冬すぼめり。社ト可化モマ試音ばじご育青康演ぴぎ権型固スで能麩ぜらもほ河都しちほラ収90作の年要とだむ部動ま者断チ第41一1米索焦茂げむしれ。測フ物使だて目月国スリカハ夏検にいへ児72告物ゆは載核ロアメヱ登輸どべゃ催行アフエハ議歌ワ河倫剖だ。記タケウ因載ヒイホヤ禁3輩彦関トえび肝区勝ワリロ成禁ぼよ界白ウヒキレ中島べせぜい各安うしぽリ覧生テ基一でむしゃ中新トヒキソ声碁スしび起田ア信大未ゅもばち。", 0, "Bigger mixed" },
|
||||
/* 4*/ { "点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点点", 0, "784 kanji" },
|
||||
};
|
||||
int data_size = ARRAY_SIZE(data);
|
||||
int i, length, ret;
|
||||
|
||||
struct zint_symbol symbol = {0};
|
||||
int ret_length, ret_length2;
|
||||
unsigned int ddata[8192];
|
||||
int ret2 = 0;
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
unsigned int ddata2[8192];
|
||||
#endif
|
||||
|
||||
clock_t start;
|
||||
clock_t total = 0, total_gno = 0;
|
||||
clock_t diff, diff_gno;
|
||||
int comment_max = 0;
|
||||
|
||||
if (!(debug & ZINT_DEBUG_TEST_PERFORMANCE)) { /* -d 256 */
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment);
|
||||
|
||||
printf("Iterations %d\n", TEST_PERF_ITERATIONS);
|
||||
|
||||
for (i = 0; i < data_size; i++) {
|
||||
int j;
|
||||
|
||||
if (index != -1 && i != index) continue;
|
||||
|
||||
length = (int) strlen(data[i].data);
|
||||
|
||||
diff = diff_gno = 0;
|
||||
|
||||
for (j = 0; j < TEST_PERF_ITERATIONS; j++) {
|
||||
ret_length = ret_length2 = length;
|
||||
|
||||
start = clock();
|
||||
ret = sjis_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, ddata);
|
||||
diff += clock() - start;
|
||||
|
||||
#ifdef TEST_JUST_SAY_GNO
|
||||
start = clock();
|
||||
ret2 = sjis_utf8_wctomb(&symbol, (unsigned char *) data[i].data, &ret_length2, ddata2);
|
||||
diff_gno += clock() - start;
|
||||
#endif
|
||||
}
|
||||
assert_equal(ret, ret2, "i:%d ret %d != ret2 %d\n", (int) i, ret, ret2);
|
||||
|
||||
printf("%*s: new % 8gms, gno % 8gms ratio %g\n", comment_max, data[i].comment,
|
||||
TEST_PERF_TIME(diff), TEST_PERF_TIME(diff_gno), TEST_PERF_RATIO(diff, diff_gno));
|
||||
|
||||
total += diff;
|
||||
total_gno += diff_gno;
|
||||
}
|
||||
if (index == -1) {
|
||||
printf("%*s: new % 8gms, gno % 8gms ratio %g\n", comment_max, "totals",
|
||||
TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
|
||||
{ "test_sjis_wctomb_zint", test_sjis_wctomb_zint, 0, 0, 0 },
|
||||
{ "test_u_sjis_int", test_u_sjis_int, 0, 0, 1 },
|
||||
{ "test_sjis_utf8", test_sjis_utf8, 1, 0, 0 },
|
||||
{ "test_sjis_utf8_to_eci", test_sjis_utf8_to_eci, 1, 0, 0 },
|
||||
{ "test_sjis_cpy", test_sjis_cpy, 1, 0, 0 },
|
||||
{ "test_perf", test_perf, 1, 0, 1 },
|
||||
};
|
||||
|
||||
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
||||
|
@ -325,3 +461,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