CODE128: reduce extended latch cut-off from 5 to 4 for better

encodation in certain cases (and no pessimizations found so far),
  props lyngklip (BWIPP);
  fix extended char latching when exactly 3 extended chars at end;
  count code set C (not digits) in loop deciding when to
  shift/latch to extended for better estimate
AZTEC: return warning if ECC < 5% (due to bit-stuffing when version
  given); return error if > 22 layers (Zint 26) for Reader
  Initialisation symbol requested for better error message
AZTEC/HANXIN/QRCODE: consolidate different ECC data size tables
  into one indexed by ECC
DBAR_EXP: check for reduced length <= 77 up front for better error
  message
HANXIN: use `malloc()` rather than `z_alloca()` for large binary
  array
QRCODE: `ecc_level` now 0-based (not 1-based)
MICROQR: consolidate different version end routines into one
  `microqr_end()` and use new `microqr_data` table to simplify code
MICROPDF417: use table for max codewords per column
library: centralize all error messages using new `errtxt()`,
  `errtxtf()`, `errtxt_adj()` funcs that protect `symbol->errtxt`
  from overflow, & try to make error messages more consistent
  thru-out, adding more feedback info to many, & use positional
  args "%n$" in prep for l10n (maybe);
  `is_sane/is_sane_lookup()` -> `not_sane/not_sane_lookup()`,
  returning 1-based position (zero on failure) instead of bool;
  `long` ints -> plain `int` (except those dealing with `ftell()`,
  `fread()` etc) as depend on int being 32-bits already
GUI: in "grpDATF.ui" use "PlainText" rather than "RichText" for
  tracker ratio examples as height of text messing up sometimes
manual: clarify Codablock-F length maximum & add examples
docs: README: pandoc 3.5, Ubuntu 24.04
CMake: use "-Wpedantic" for Clang only as GNU complains about
  `errtxtf()` positional args "%n$"
This commit is contained in:
gitlost 2024-10-27 21:33:33 +00:00
parent 752c1fae5d
commit 5e2044ff2e
104 changed files with 8102 additions and 7755 deletions

View file

@ -30,6 +30,7 @@
*/
/* SPDX-License-Identifier: BSD-3-Clause */
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include "common.h"
@ -37,8 +38,9 @@
#include "reedsol.h"
#include "large.h"
#define C1_MAX_CWS 1480 /* Max data codewords for Version H */
#define C1_MAX_ECCS 560 /* Max ECC codewords for Version H */
#define C1_MAX_CWS 1480 /* Max data codewords for Version H */
#define C1_MAX_CWS_S "1480" /* String version of above */
#define C1_MAX_ECCS 560 /* Max ECC codewords for Version H */
#define C1_ASCII 1
#define C1_C40 2
@ -1023,35 +1025,33 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i
int row, col;
int sub_version = 0;
rs_t rs;
int error_number = 0;
const int gs1 = (symbol->input_mode & 0x07) == GS1_MODE;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
if ((symbol->option_2 < 0) || (symbol->option_2 > 10)) {
strcpy(symbol->errtxt, "513: Invalid symbol size");
return ZINT_ERROR_INVALID_OPTION;
return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 513, "Version '%d' out of range (1 to 10)",
symbol->option_2);
}
if (symbol->structapp.count) {
if (symbol->option_2 == 9) { /* Version S */
strcpy(symbol->errtxt, "714: Structured Append not available for Version S");
return ZINT_ERROR_INVALID_OPTION;
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 714, "Structured Append not available for Version S");
}
if (gs1) {
strcpy(symbol->errtxt, "710: Cannot have Structured Append and GS1 mode at the same time");
return ZINT_ERROR_INVALID_OPTION;
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 710,
"Cannot have Structured Append and GS1 mode at the same time");
}
if (symbol->structapp.count < 2 || symbol->structapp.count > 128) {
strcpy(symbol->errtxt, "711: Structured Append count out of range (2-128)");
return ZINT_ERROR_INVALID_OPTION;
return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 711,
"Structured Append count '%d' out of range (2 to 128)", symbol->structapp.count);
}
if (symbol->structapp.index < 1 || symbol->structapp.index > symbol->structapp.count) {
sprintf(symbol->errtxt, "712: Structured Append index out of range (1-%d)", symbol->structapp.count);
return ZINT_ERROR_INVALID_OPTION;
return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 712,
"Structured Append index '%1$d' out of range (1 to count %2$d)",
symbol->structapp.index, symbol->structapp.count);
}
if (symbol->structapp.id[0]) {
strcpy(symbol->errtxt, "713: Structured Append ID not available for Code One");
return ZINT_ERROR_INVALID_OPTION;
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 713, "Structured Append ID not available for Code One");
}
}
@ -1063,16 +1063,15 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i
int block_width;
if (seg_count > 1) {
strcpy(symbol->errtxt, "715: Multiple segments not supported for Version S");
return ZINT_ERROR_INVALID_OPTION;
return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 715, "Multiple segments not supported for Version S");
}
if (segs[0].length > 18) {
strcpy(symbol->errtxt, "514: Input data too long for Version S");
return ZINT_ERROR_TOO_LONG;
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 514, "Input length %d too long for Version S (maximum 18)",
segs[0].length);
}
if (!is_sane(NEON_F, segs[0].source, segs[0].length)) {
strcpy(symbol->errtxt, "515: Invalid input data (Version S encodes numeric input only)");
return ZINT_ERROR_INVALID_DATA;
if ((i = not_sane(NEON_F, segs[0].source, segs[0].length))) {
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 515,
"Invalid character at position %d in input (Version S encodes digits only)", i);
}
size = 9;
@ -1142,18 +1141,19 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i
unsigned int ecc[22];
int data_length;
int data_cw, ecc_cw, block_width;
int last_mode;
int last_mode = 0; /* Suppress gcc 14 "-Wmaybe-uninitialized" false positive */
if (c1_total_length_segs(segs, seg_count) > 90) {
strcpy(symbol->errtxt, "519: Input data too long for Version T");
return ZINT_ERROR_TOO_LONG;
if ((i = c1_total_length_segs(segs, seg_count)) > 90) {
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 519, "Input length %d too long for Version T (maximum 90)",
i);
}
data_length = c1_encode_segs(symbol, segs, seg_count, gs1, target, &last_mode);
if (data_length == 0 || data_length > 38) {
strcpy(symbol->errtxt, "516: Input data too long for Version T");
return ZINT_ERROR_TOO_LONG;
assert(data_length); /* Can't exceed C1_MAX_CWS as input <= 90 */
if (data_length > 38) {
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 516,
"Input too long for Version T, requires %d codewords (maximum 38)", data_length);
}
size = 10;
@ -1234,8 +1234,8 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i
data_length = c1_encode_segs(symbol, segs, seg_count, gs1, target, &last_mode);
if (data_length == 0) {
strcpy(symbol->errtxt, "517: Input data is too long");
return ZINT_ERROR_TOO_LONG;
return errtxt(ZINT_ERROR_TOO_LONG, symbol, 517,
"Input too long, requires too many codewords (maximum " C1_MAX_CWS_S ")");
}
for (i = 7; i >= 0; i--) {
@ -1249,8 +1249,9 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i
}
if ((symbol->option_2 != 0) && (symbol->option_2 < size)) {
strcpy(symbol->errtxt, "518: Input too long for selected symbol size");
return ZINT_ERROR_TOO_LONG;
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 518,
"Input too long for Version %1$c, requires %2$d codewords (maximum %3$d)",
'A' + symbol->option_2 - 1, data_length, c1_data_length[symbol->option_2 - 1]);
}
data_cw = c1_data_length[size - 1];
@ -1577,16 +1578,14 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i
if (symbol->option_2 == 9) { /* Version S */
if (symbol->eci || gs1) {
sprintf(symbol->errtxt, "511: %s ignored for Version S",
symbol->eci && gs1 ? "ECI and GS1 mode" : symbol->eci ? "ECI" : "GS1 mode");
error_number = ZINT_WARN_INVALID_OPTION;
return errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 511, "%s ignored for Version S",
symbol->eci && gs1 ? "ECI and GS1 mode" : symbol->eci ? "ECI" : "GS1 mode");
}
} else if (symbol->eci && gs1) {
strcpy(symbol->errtxt, "512: ECI ignored for GS1 mode");
error_number = ZINT_WARN_INVALID_OPTION;
return errtxt(ZINT_WARN_INVALID_OPTION, symbol, 512, "ECI ignored for GS1 mode");
}
return error_number;
return 0;
}
/* vim: set ts=4 sw=4 et : */