mirror of
https://git.code.sf.net/p/zint/code
synced 2025-12-17 18:07:02 +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:
@@ -39,7 +39,7 @@
|
||||
|
||||
/* Was in "code128.c" */
|
||||
|
||||
INTERNAL int gs1_128(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
INTERNAL int zint_gs1_128(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
|
||||
/* Helper to do NVE18 or EAN14 */
|
||||
static int nve18_or_ean14(struct zint_symbol *symbol, const unsigned char source[], int length, const int data_len) {
|
||||
@@ -66,12 +66,12 @@ static int nve18_or_ean14(struct zint_symbol *symbol, const unsigned char source
|
||||
length -= 2;
|
||||
}
|
||||
if (length > data_len + 1) {
|
||||
return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 345, "Input length %1$d too long (maximum %2$d)",
|
||||
length, data_len + 1);
|
||||
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 345, "Input length %1$d too long (maximum %2$d)",
|
||||
length, data_len + 1);
|
||||
}
|
||||
if ((i = not_sane(NEON_F, source, length))) {
|
||||
if ((i = z_not_sane(NEON_F, source, length))) {
|
||||
/* Note: for all "at position" error messages, escape sequences not accounted for */
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 346,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 346,
|
||||
"Invalid character at position %d in input (digits only)", i);
|
||||
}
|
||||
if (length == data_len + 1) {
|
||||
@@ -84,29 +84,29 @@ static int nve18_or_ean14(struct zint_symbol *symbol, const unsigned char source
|
||||
memset(ean128_equiv + 4, '0', zeroes);
|
||||
memcpy(ean128_equiv + 4 + zeroes, source, length);
|
||||
|
||||
check_digit = (unsigned char) gs1_check_digit(ean128_equiv + 4, data_len);
|
||||
check_digit = (unsigned char) zint_gs1_check_digit(ean128_equiv + 4, data_len);
|
||||
if (have_check_digit && have_check_digit != check_digit) {
|
||||
return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 347, "Invalid check digit '%1$c', expecting '%2$c'",
|
||||
have_check_digit, check_digit);
|
||||
return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 347, "Invalid check digit '%1$c', expecting '%2$c'",
|
||||
have_check_digit, check_digit);
|
||||
}
|
||||
ean128_equiv[data_len + 4] = check_digit;
|
||||
ean128_equiv[data_len + 5] = '\0'; /* Terminating NUL required by `c128_cost()` */
|
||||
|
||||
error_number = gs1_128(symbol, ean128_equiv, data_len + 5);
|
||||
error_number = zint_gs1_128(symbol, ean128_equiv, data_len + 5);
|
||||
|
||||
/* Use `raw_text` set by `gs1_128()` */
|
||||
/* Use `raw_text` set by `zint_gs1_128()` */
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
||||
/* Add check digit if encoding an NVE18 symbol */
|
||||
INTERNAL int nve18(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
INTERNAL int zint_nve18(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
return nve18_or_ean14(symbol, source, length, 17 /*data_len*/);
|
||||
}
|
||||
|
||||
/* EAN-14 - A version of EAN-128 */
|
||||
INTERNAL int ean14(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
INTERNAL int zint_ean14(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
return nve18_or_ean14(symbol, source, length, 13 /*data_len*/);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ static const char KRSET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
/* DPD (Deutscher Paketdienst) Code */
|
||||
/* Specification at https://esolutions.dpd.com/dokumente/DPD_Parcel_Label_Specification_2.4.1_EN.pdf
|
||||
* and identification tag info (Barcode ID) at https://esolutions.dpd.com/dokumente/DPD_Routing_Database_1.3_EN.pdf */
|
||||
INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
INTERNAL int zint_dpd(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i, p;
|
||||
unsigned char ident_tag;
|
||||
unsigned char local_source_buf[29];
|
||||
@@ -129,10 +129,10 @@ INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
if ((length != 27 && length != 28) || (length == 28 && relabel)) {
|
||||
if (relabel) {
|
||||
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 830,
|
||||
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 830,
|
||||
"DPD relabel input length %d wrong (27 characters required)", length);
|
||||
}
|
||||
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 349, "DPD input length %d wrong (27 or 28 characters required)",
|
||||
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 349, "DPD input length %d wrong (27 or 28 characters required)",
|
||||
length);
|
||||
}
|
||||
|
||||
@@ -146,22 +146,22 @@ INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
ident_tag = local_source[0];
|
||||
|
||||
to_upper(local_source + !relabel, length - !relabel);
|
||||
if ((i = not_sane(KRSET_F, local_source + !relabel, length - !relabel))) {
|
||||
z_to_upper(local_source + !relabel, length - !relabel);
|
||||
if ((i = z_not_sane(KRSET_F, local_source + !relabel, length - !relabel))) {
|
||||
if (local_source == local_source_buf || relabel) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 300,
|
||||
"Invalid character at position %d in input (alphanumerics only)", i);
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 300,
|
||||
"Invalid character at position %d in input (alphanumerics only)", i);
|
||||
}
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 299,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 299,
|
||||
"Invalid character at position %d in input (alphanumerics only after first)", i);
|
||||
}
|
||||
|
||||
if (z_iscntrl(ident_tag) || !z_isascii(ident_tag)) {
|
||||
return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 343,
|
||||
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 343,
|
||||
"Invalid DPD identification tag (first character), ASCII values 32 to 126 only");
|
||||
}
|
||||
|
||||
if ((error_number = code128(symbol, local_source, length))) {
|
||||
if ((error_number = zint_code128(symbol, local_source, length))) {
|
||||
assert(error_number == ZINT_ERROR_MEMORY); /* Too long can't happen */
|
||||
return error_number;
|
||||
}
|
||||
@@ -179,13 +179,13 @@ INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
25mm / 0.4mm (X max) = 62.5 min, 25mm / 0.375 (X) ~ 66.66 default */
|
||||
if (relabel) { /* If relabel then half-size */
|
||||
const float default_height = 33.3333321f; /* 12.5 / 0.375 */
|
||||
error_number = set_height(symbol, 31.25f, default_height, 0.0f, 0 /*no_errtxt*/);
|
||||
error_number = z_set_height(symbol, 31.25f, default_height, 0.0f, 0 /*no_errtxt*/);
|
||||
} else {
|
||||
const float default_height = 66.6666641f; /* 25.0 / 0.375 */
|
||||
error_number = set_height(symbol, 62.5f, default_height, 0.0f, 0 /*no_errtxt*/);
|
||||
error_number = z_set_height(symbol, 62.5f, default_height, 0.0f, 0 /*no_errtxt*/);
|
||||
}
|
||||
} else {
|
||||
(void) set_height(symbol, 0.0f, relabel ? 25.0f : 50.0f, 0.0f, 1 /*no_errtxt*/);
|
||||
(void) z_set_height(symbol, 0.0f, relabel ? 25.0f : 50.0f, 0.0f, 1 /*no_errtxt*/);
|
||||
}
|
||||
|
||||
cd = mod;
|
||||
@@ -193,7 +193,7 @@ INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
for (i = !relabel, p = 0; i < length; i++) {
|
||||
hrt[p++] = local_source[i];
|
||||
|
||||
cd += posn(KRSET, local_source[i]);
|
||||
cd += z_posn(KRSET, local_source[i]);
|
||||
if (cd > mod) cd -= mod;
|
||||
cd *= 2;
|
||||
if (cd >= (mod + 1)) cd -= mod + 1;
|
||||
@@ -215,20 +215,20 @@ INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
cd = mod + 1 - cd;
|
||||
if (cd == mod) cd = 0;
|
||||
|
||||
hrt[p] = xtoc(cd);
|
||||
hrt[p] = z_xtoc(cd);
|
||||
|
||||
hrt_cpy_nochk(symbol, hrt, p + 1);
|
||||
z_hrt_cpy_nochk(symbol, hrt, p + 1);
|
||||
|
||||
/* Use `raw_text` from `code128()` */
|
||||
/* Use `raw_text` from `zint_code128()` */
|
||||
|
||||
/* Some compliance checks */
|
||||
if (not_sane(NEON_F, local_source + length - 16, 16)) {
|
||||
if (not_sane(NEON_F, local_source + length - 3, 3)) { /* 3-digit Country Code (ISO 3166-1) */
|
||||
errtxt(0, symbol, 831, "Destination Country Code (last 3 characters) should be numeric");
|
||||
} else if (not_sane(NEON_F, local_source + length - 6, 3)) { /* 3-digit Service Code */
|
||||
errtxt(0, symbol, 832, "Service Code (characters 6-4 from end) should be numeric");
|
||||
if (z_not_sane(NEON_F, local_source + length - 16, 16)) {
|
||||
if (z_not_sane(NEON_F, local_source + length - 3, 3)) { /* 3-digit Country Code (ISO 3166-1) */
|
||||
z_errtxt(0, symbol, 831, "Destination Country Code (last 3 characters) should be numeric");
|
||||
} else if (z_not_sane(NEON_F, local_source + length - 6, 3)) { /* 3-digit Service Code */
|
||||
z_errtxt(0, symbol, 832, "Service Code (characters 6-4 from end) should be numeric");
|
||||
} else { /* Last 10 characters of Tracking No. */
|
||||
errtxt(0, symbol, 833,
|
||||
z_errtxt(0, symbol, 833,
|
||||
"Last 10 characters of Tracking Number (characters 16-7 from end) should be numeric");
|
||||
}
|
||||
error_number = ZINT_WARN_NONCOMPLIANT;
|
||||
@@ -239,7 +239,7 @@ INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Universal Postal Union S10 */
|
||||
/* https://www.upu.int/UPU/media/upu/files/postalSolutions/programmesAndServices/standards/S10-12.pdf */
|
||||
INTERNAL int upu_s10(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
INTERNAL int zint_upu_s10(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
static const char weights[8] = { 8, 6, 4, 2, 3, 5, 9, 7 };
|
||||
unsigned char local_source[13 + 1];
|
||||
unsigned char have_check_digit = '\0';
|
||||
@@ -249,7 +249,7 @@ INTERNAL int upu_s10(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
int error_number;
|
||||
|
||||
if (length != 12 && length != 13) {
|
||||
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 834, "Input length %d wrong (12 or 13 characters required)",
|
||||
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 834, "Input length %d wrong (12 or 13 characters required)",
|
||||
length);
|
||||
}
|
||||
if (length == 13) { /* Includes check digit - remove for now */
|
||||
@@ -260,25 +260,25 @@ INTERNAL int upu_s10(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
} else {
|
||||
memcpy(local_source, source, length);
|
||||
}
|
||||
to_upper(local_source, length);
|
||||
z_to_upper(local_source, length);
|
||||
|
||||
if (!z_isupper(local_source[0]) || !z_isupper(local_source[1])) {
|
||||
return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 835,
|
||||
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 835,
|
||||
"Invalid character in Service Indictor (first 2 characters) (alphabetic only)");
|
||||
}
|
||||
if (not_sane(NEON_F, local_source + 2, 12 - 4) || (have_check_digit && !z_isdigit(have_check_digit))) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 836,
|
||||
if (z_not_sane(NEON_F, local_source + 2, 12 - 4) || (have_check_digit && !z_isdigit(have_check_digit))) {
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 836,
|
||||
"Invalid character in Serial Number (middle %d characters) (digits only)",
|
||||
have_check_digit ? 9 : 8);
|
||||
}
|
||||
if (!z_isupper(local_source[10]) || !z_isupper(local_source[11])) {
|
||||
return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 837,
|
||||
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 837,
|
||||
"Invalid character in Country Code (last 2 characters) (alphabetic only)");
|
||||
}
|
||||
|
||||
check_digit = 0;
|
||||
for (i = 2; i < 10; i++) { /* Serial Number only */
|
||||
check_digit += ctoi(local_source[i]) * weights[i - 2];
|
||||
check_digit += z_ctoi(local_source[i]) * weights[i - 2];
|
||||
}
|
||||
check_digit %= 11;
|
||||
check_digit = 11 - check_digit;
|
||||
@@ -287,31 +287,31 @@ INTERNAL int upu_s10(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
} else if (check_digit == 11) {
|
||||
check_digit = 5;
|
||||
}
|
||||
if (have_check_digit && ctoi(have_check_digit) != check_digit) {
|
||||
return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 838, "Invalid check digit '%1$c', expecting '%2$c'",
|
||||
have_check_digit, itoc(check_digit));
|
||||
if (have_check_digit && z_ctoi(have_check_digit) != check_digit) {
|
||||
return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 838, "Invalid check digit '%1$c', expecting '%2$c'",
|
||||
have_check_digit, z_itoc(check_digit));
|
||||
}
|
||||
/* Add in (back) check digit */
|
||||
local_source[12] = local_source[11];
|
||||
local_source[11] = local_source[10];
|
||||
local_source[10] = itoc(check_digit);
|
||||
local_source[10] = z_itoc(check_digit);
|
||||
local_source[13] = '\0'; /* Terminating NUL required by `c128_cost()` */
|
||||
|
||||
if ((error_number = code128(symbol, local_source, 13))) {
|
||||
if ((error_number = zint_code128(symbol, local_source, 13))) {
|
||||
assert(error_number == ZINT_ERROR_MEMORY); /* Too long can't happen */
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Do some checks on the Service Indicator (first char only) and Country Code */
|
||||
if (strchr("JKSTW", local_source[0]) != NULL) { /* These are reserved & cannot be assigned */
|
||||
error_number = errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 839,
|
||||
error_number = z_errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 839,
|
||||
"Invalid Service Indicator '%.2s' (first character should not be any of \"JKSTW\")",
|
||||
local_source);
|
||||
} else if (strchr("FIOXY", local_source[0]) != NULL) { /* These aren't allocated as of spec Oct 2017 */
|
||||
error_number = errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 840,
|
||||
error_number = z_errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 840,
|
||||
"Non-standard Service Indicator '%.2s' (first 2 characters)", local_source);
|
||||
} else if (!gs1_iso3166_alpha2(local_source + 11)) {
|
||||
error_number = errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 841,
|
||||
} else if (!zint_gs1_iso3166_alpha2(local_source + 11)) {
|
||||
error_number = z_errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 841,
|
||||
"Country Code '%.2s' (last two characters) is not ISO 3166-1", local_source + 11);
|
||||
}
|
||||
|
||||
@@ -321,26 +321,26 @@ INTERNAL int upu_s10(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
}
|
||||
hrt[j++] = local_source[i];
|
||||
}
|
||||
hrt_cpy_nochk(symbol, hrt, j);
|
||||
z_hrt_cpy_nochk(symbol, hrt, j);
|
||||
|
||||
/* Use `raw_text` set by `code128()` */
|
||||
/* Use `raw_text` set by `zint_code128()` */
|
||||
|
||||
if (symbol->output_options & COMPLIANT_HEIGHT) {
|
||||
/* Universal Postal Union S10 Section 8, using max X 0.51mm & minimum height 12.5mm or 15% of width */
|
||||
const float min_height_min = 24.5098038f; /* 12.5 / 0.51 */
|
||||
float min_height = stripf(symbol->width * 0.15f);
|
||||
float min_height = z_stripf(symbol->width * 0.15f);
|
||||
if (min_height < min_height_min) {
|
||||
min_height = min_height_min;
|
||||
}
|
||||
/* Using 50 as default as none recommended */
|
||||
if (error_number == 0) {
|
||||
error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f,
|
||||
error_number = z_set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f,
|
||||
0 /*no_errtxt*/);
|
||||
} else {
|
||||
(void) set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f, 1 /*no_errtxt*/);
|
||||
(void) z_set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f, 1 /*no_errtxt*/);
|
||||
}
|
||||
} else {
|
||||
(void) set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
|
||||
(void) z_set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/);
|
||||
}
|
||||
|
||||
return error_number;
|
||||
|
||||
Reference in New Issue
Block a user