1
0
mirror of https://git.code.sf.net/p/zint/code synced 2025-12-18 02:17:06 +00:00

general: prefix all INTERNAL funcs/tables with zint_, except

those in "backend/common.h", which are prefixed by `z_` - makes
  symbol clashes more unlikely when zint is statically linked
  (ticket #337, props Ulrich Becker)
DOTCODE: fix padding allowance (10 -> 52 - probable max 35) to
  cover cases with large no. of columns requested and little data,
  to prevent `codeword_array` buffer overflow
AZTEC/CODEONE: some code fiddling
general_field: prefix defines with `GF_`, shorten static funcs
  prefix `general_field_` -> `gf_`
This commit is contained in:
gitlost
2025-08-26 23:48:00 +01:00
parent e18b047a45
commit 39380d6767
106 changed files with 4477 additions and 4360 deletions

View File

@@ -171,14 +171,14 @@ static void dm_ecc(unsigned char *binary, const int bytes, const int datablock,
int n;
rs_t rs;
rs_init_gf(&rs, 0x12d);
rs_init_code(&rs, rsblock, 1);
zint_rs_init_gf(&rs, 0x12d);
zint_rs_init_code(&rs, rsblock, 1);
for (b = 0; b < blocks; b++) {
unsigned char buf[256], ecc[256];
int p = 0;
for (n = b; n < bytes; n += blocks)
buf[p++] = binary[n];
rs_encode(&rs, p, buf, ecc);
zint_rs_encode(&rs, p, buf, ecc);
if (skew) {
/* Rotate ecc data to make 144x144 size symbols acceptable */
/* See http://groups.google.com/group/postscriptbarcode/msg/5ae8fda7757477da
@@ -1063,7 +1063,7 @@ static int dm_minimalenc(struct zint_symbol *symbol, const unsigned char source[
assert(length <= 10921); /* Can only handle (10921 + 1) * 6 = 65532 < 65536 (2*16) due to sizeof(previous) */
if (!dm_define_mode(symbol, modes, source, length, last_seg, gs1, debug_print)) {
return errtxt(ZINT_ERROR_MEMORY, symbol, 728, "Insufficient memory for mode buffers");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 728, "Insufficient memory for mode buffers");
}
while (sp < length) {
@@ -1111,8 +1111,8 @@ static int dm_minimalenc(struct zint_symbol *symbol, const unsigned char source[
if (current_mode == DM_ASCII) {
if (is_twodigits(source, length, sp)) {
target[tp++] = (unsigned char) ((10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130);
if (z_is_twodigits(source, length, sp)) {
target[tp++] = (unsigned char) (10 * z_ctoi(source[sp]) + z_ctoi(source[sp + 1]) + 130);
if (debug_print) printf("N%02d ", target[tp - 1] - 130);
sp += 2;
} else {
@@ -1190,7 +1190,7 @@ static int dm_minimalenc(struct zint_symbol *symbol, const unsigned char source[
} else if (z_isupper(source[sp])) {
value = (source[sp] - 'A') + 14;
} else {
value = posn(x12_nonalphanum_chars, source[sp]);
value = z_posn(x12_nonalphanum_chars, source[sp]);
}
process_buffer[process_p++] = value;
@@ -1222,7 +1222,7 @@ static int dm_minimalenc(struct zint_symbol *symbol, const unsigned char source[
}
if (tp > 1558) {
return errtxt(ZINT_ERROR_TOO_LONG, symbol, 729,
return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 729,
"Input too long, requires too many codewords (maximum 1558)");
}
@@ -1276,8 +1276,8 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
if (current_mode == DM_ASCII) {
next_mode = DM_ASCII;
if (is_twodigits(source, length, sp)) {
target[tp++] = (unsigned char) ((10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130);
if (z_is_twodigits(source, length, sp)) {
target[tp++] = (unsigned char) (10 * z_ctoi(source[sp]) + z_ctoi(source[sp + 1]) + 130);
if (debug_print) printf("N%02d ", target[tp - 1] - 130);
sp += 2;
} else {
@@ -1392,7 +1392,7 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
} else if (z_isupper(source[sp])) {
value = (source[sp] - 'A') + 14;
} else {
value = posn(x12_nonalphanum_chars, source[sp]);
value = z_posn(x12_nonalphanum_chars, source[sp]);
}
process_buffer[process_p++] = value;
@@ -1476,7 +1476,7 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
}
if (tp > 1558) {
return errtxt(ZINT_ERROR_TOO_LONG, symbol, 520,
return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 520,
"Input too long, requires too many codewords (maximum 1558)");
}
@@ -1581,8 +1581,8 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
target[tp++] = 254; /* Unlatch */
if (debug_print) fputs("ASC ", stdout);
for (; sp < length; sp++) {
if (is_twodigits(source, length, sp)) {
target[tp++] = (unsigned char) ((10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130);
if (z_is_twodigits(source, length, sp)) {
target[tp++] = (unsigned char) (10 * z_ctoi(source[sp]) + z_ctoi(source[sp + 1]) + 130);
if (debug_print) printf("N%02d ", target[tp - 1] - 130);
sp++;
} else if (source[sp] & 0x80) {
@@ -1671,8 +1671,8 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
}
#ifdef ZINT_TEST /* Wrapper for direct testing */
INTERNAL int dm_encode_test(struct zint_symbol *symbol, const unsigned char source[], const int length, const int eci,
const int last_seg, const int gs1, unsigned char target[], int *p_tp) {
INTERNAL int zint_test_dm_encode(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int eci, const int last_seg, const int gs1, unsigned char target[], int *p_tp) {
return dm_encode(symbol, source, length, eci, last_seg, gs1, target, p_tp);
}
#endif
@@ -1691,21 +1691,21 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
const int raw_text = (symbol->input_mode & 0x07) != GS1_MODE && (symbol->output_options & BARCODE_RAW_TEXT);
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
if ((i = segs_length(segs, seg_count)) > 3116) { /* Max is 3166 digits */
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 719, "Input length %d too long (maximum 3116)", i);
if ((i = z_segs_length(segs, seg_count)) > 3116) { /* Max is 3166 digits */
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 719, "Input length %d too long (maximum 3116)", i);
}
if (symbol->structapp.count) {
int id1, id2;
if (symbol->structapp.count < 2 || symbol->structapp.count > 16) {
return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 720,
return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 720,
"Structured Append count '%d' out of range (2 to 16)", symbol->structapp.count);
}
if (symbol->structapp.index < 1 || symbol->structapp.index > symbol->structapp.count) {
return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 721,
"Structured Append index '%1$d' out of range (1 to count %2$d)",
symbol->structapp.index, symbol->structapp.count);
return ZEXT z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 721,
"Structured Append index '%1$d' out of range (1 to count %2$d)",
symbol->structapp.index, symbol->structapp.count);
}
if (symbol->structapp.id[0]) {
int id, id_len, id1_err, id2_err;
@@ -1713,13 +1713,13 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
for (id_len = 1; id_len < 7 && symbol->structapp.id[id_len]; id_len++);
if (id_len > 6) { /* ID1 * 1000 + ID2 */
return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 722,
return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 722,
"Structured Append ID length %d too long (6 digit maximum)", id_len);
}
id = to_int((const unsigned char *) symbol->structapp.id, id_len);
id = z_to_int(ZCUCP(symbol->structapp.id), id_len);
if (id == -1) {
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 723, "Invalid Structured Append ID (digits only)");
return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 723, "Invalid Structured Append ID (digits only)");
}
id1 = id / 1000;
id2 = id % 1000;
@@ -1727,17 +1727,17 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
id2_err = id2 < 1 || id2 > 254;
if (id1_err || id2_err) {
if (id1_err && id2_err) {
return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 724,
"Structured Append ID1 '%1$03d' and ID2 '%2$03d' out of range (001 to 254)"
" (ID \"%3$03d%4$03d\")",
id1, id2, id1, id2);
return ZEXT z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 724,
"Structured Append ID1 '%1$03d' and ID2 '%2$03d' out of range"
" (001 to 254) (ID \"%3$03d%4$03d\")",
id1, id2, id1, id2);
}
if (id1_err) {
return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 725,
return ZEXT z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 725,
"Structured Append ID1 '%1$03d' out of range (001 to 254) (ID \"%2$03d%3$03d\")",
id1, id1, id2);
}
return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 726,
return ZEXT z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 726,
"Structured Append ID2 '%1$03d' out of range (001 to 254) (ID \"%2$03d%3$03d\")",
id2, id1, id2);
}
@@ -1769,10 +1769,10 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
if (symbol->output_options & READER_INIT) {
if (gs1) {
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 521, "Cannot use Reader Initialisation in GS1 mode");
return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 521, "Cannot use Reader Initialisation in GS1 mode");
}
if (symbol->structapp.count) {
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 727,
return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 727,
"Cannot have Structured Append and Reader Initialisation at the same time");
}
target[tp++] = 234; /* Reader Programming */
@@ -1802,8 +1802,8 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
in_macro = 1;
}
if (raw_text && rt_init_segs(symbol, seg_count)) {
return ZINT_ERROR_MEMORY; /* `rt_init_segs()` only fails with OOM */
if (raw_text && z_rt_init_segs(symbol, seg_count)) {
return ZINT_ERROR_MEMORY; /* `z_rt_init_segs()` only fails with OOM */
}
for (i = 0; i < seg_count; i++) {
@@ -1821,8 +1821,8 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
assert(error_number >= ZINT_ERROR);
return error_number;
}
if (raw_text && rt_cpy_seg(symbol, i, &segs[i])) { /* Note including macro header and RS + EOT */
return ZINT_ERROR_MEMORY; /* `rt_cpy_seg()` only fails with OOM */
if (raw_text && z_rt_cpy_seg(symbol, i, &segs[i])) { /* Note including macro header and RS + EOT */
return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg()` only fails with OOM */
}
}
@@ -1868,11 +1868,11 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
if (binlen > dm_matrixbytes[symbolsize]) {
if ((symbol->option_2 >= 1) && (symbol->option_2 <= DMSIZESCOUNT)) {
/* The symbol size was given by --ver (option_2) */
return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 522,
"Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)",
symbol->option_2, binlen, dm_matrixbytes[symbolsize]);
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 522,
"Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)",
symbol->option_2, binlen, dm_matrixbytes[symbolsize]);
}
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 523, "Input too long, requires %d codewords (maximum 1558)",
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 523, "Input too long, requires %d codewords (maximum 1558)",
binlen);
}
@@ -1917,7 +1917,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
#ifdef ZINT_TEST
if (symbol->debug & ZINT_DEBUG_TEST) {
debug_test_codeword_dump(symbol, binary, skew ? 1558 + 620 : bytes + rsblock * (bytes / datablock));
z_debug_test_codeword_dump(symbol, binary, skew ? 1558 + 620 : bytes + rsblock * (bytes / datablock));
}
#endif
{ /* placement */
@@ -1925,20 +1925,20 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
const int NR = H - 2 * (H / FH);
int x, y, *places;
if (!(places = (int *) calloc((size_t) NC * (size_t) NR, sizeof(int)))) {
return errtxt(ZINT_ERROR_MEMORY, symbol, 718, "Insufficient memory for placement array");
return z_errtxt(ZINT_ERROR_MEMORY, symbol, 718, "Insufficient memory for placement array");
}
dm_placement(places, NR, NC);
for (y = 0; y < H; y += FH) {
for (x = 0; x < W; x++)
set_module(symbol, (H - y) - 1, x);
z_set_module(symbol, (H - y) - 1, x);
for (x = 0; x < W; x += 2)
set_module(symbol, y, x);
z_set_module(symbol, y, x);
}
for (x = 0; x < W; x += FW) {
for (y = 0; y < H; y++)
set_module(symbol, (H - y) - 1, x);
z_set_module(symbol, (H - y) - 1, x);
for (y = 0; y < H; y += 2)
set_module(symbol, (H - y) - 1, x + FW - 1);
z_set_module(symbol, (H - y) - 1, x + FW - 1);
}
#ifdef DM_DEBUG
/* Print position matrix as in standard */
@@ -1955,7 +1955,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
for (x = 0; x < NC; x++) {
const int v = places[(NR - y - 1) * NC + x];
if (v == 1 || (v > 7 && (binary[(v >> 3) - 1] & (1 << (v & 7))))) {
set_module(symbol, H - (1 + y + 2 * (y / (FH - 2))) - 1, 1 + x + 2 * (x / (FW - 2)));
z_set_module(symbol, H - (1 + y + 2 * (y / (FH - 2))) - 1, 1 + x + 2 * (x / (FW - 2)));
}
}
}
@@ -1972,14 +1972,14 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
return error_number;
}
INTERNAL int datamatrix(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) {
INTERNAL int zint_datamatrix(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) {
if (symbol->option_1 <= 1) {
/* ECC 200 */
return dm_ecc200(symbol, segs, seg_count);
}
/* ECC 000 - 140 */
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 524, "Older Data Matrix standards are no longer supported");
return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 524, "Older Data Matrix standards are no longer supported");
}
/* vim: set ts=4 sw=4 et : */