diff --git a/ChangeLog b/ChangeLog index b52d4df8..e6b3d5c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -Version 2.15.0.9 (dev) not released yet (2025-04-24) +Version 2.15.0.9 (dev) not released yet (2025-08-25) ==================================================== **Incompatible changes** @@ -46,6 +46,9 @@ Changes - For EAN/UPC accept space as alternative add-on separator to '+', and accept GTIN-13 format with & without 2-digit or 5-digit add-on (no separator) - GS1PARENS_MODE: allow parentheses in AI data if backslashed and `ESCAPE_MODE` +- Prefix all `INTERNAL` funcs/tables with `zint_`, except for 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) Bugs ---- @@ -61,6 +64,8 @@ Bugs - MAILMARK_2D: fix postcode validation: no limited alphanumerics, spaced-out DPS "outward"-only allowed, all-blank DPS allowed (ticket #334, props Milton Neal) +- DOTCODE: fix padding allowance to cover cases with large no. of columns + requested and little data, to prevent buffer overflow - manual/man page: fix DATAMATRIX Sizes tables "28 12x26" -> "27 12x26" diff --git a/backend/2of5.c b/backend/2of5.c index 69a706de..4465a8e8 100644 --- a/backend/2of5.c +++ b/backend/2of5.c @@ -66,13 +66,13 @@ static int c25_common(struct zint_symbol *symbol, const unsigned char source[], if (length > max) { /* errtxt 301: 303: 305: 307: */ - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, error_base, "Input length %1$d too long (maximum %2$d)", - length, max); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, error_base, "Input length %1$d too long (maximum %2$d)", + length, max); } - 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 */ /* errtxt 302: 304: 306: 308: */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, error_base + 1, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, error_base + 1, "Invalid character at position %d in input (digits only)", i); } @@ -80,7 +80,7 @@ static int c25_common(struct zint_symbol *symbol, const unsigned char source[], if (have_checkdigit) { /* Add standard GS1 check digit */ - local_source[length] = gs1_check_digit(source, length); + local_source[length] = zint_gs1_check_digit(source, length); length++; if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %c\n", local_source[length - 1]); } @@ -103,38 +103,38 @@ static int c25_common(struct zint_symbol *symbol, const unsigned char source[], memcpy(d, start_stop[1], start_length - 1); d += start_length - 1; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); /* Exclude check digit from HRT if hidden */ - hrt_cpy_nochk(symbol, local_source, length - (symbol->option_2 == 2)); + z_hrt_cpy_nochk(symbol, local_source, length - (symbol->option_2 == 2)); - if (raw_text && rt_cpy(symbol, local_source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, local_source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return 0; } /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */ -INTERNAL int c25standard(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_c25standard(struct zint_symbol *symbol, unsigned char source[], int length) { /* 9 + (112 + 1) * 10 + 8 = 1147 */ return c25_common(symbol, source, length, 112, 1 /*is_matrix*/, C25MatrixStartStop, 6, 301); } /* Code 2 of 5 IATA */ -INTERNAL int c25iata(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_c25iata(struct zint_symbol *symbol, unsigned char source[], int length) { /* 4 + (80 + 1) * 14 + 5 = 1143 */ return c25_common(symbol, source, length, 80, 0 /*is_matrix*/, C25IataLogicStartStop, 4, 305); } /* Code 2 of 5 Data Logic */ -INTERNAL int c25logic(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_c25logic(struct zint_symbol *symbol, unsigned char source[], int length) { /* 4 + (113 + 1) * 10 + 5 = 1149 */ return c25_common(symbol, source, length, 113, 1 /*is_matrix*/, C25IataLogicStartStop, 4, 307); } /* Code 2 of 5 Industrial */ -INTERNAL int c25ind(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_c25ind(struct zint_symbol *symbol, unsigned char source[], int length) { /* 10 + (79 + 1) * 14 + 9 = 1139 */ return c25_common(symbol, source, length, 79, 0 /*is_matrix*/, C25IndustStartStop, 6, 303); } diff --git a/backend/2of5inter.c b/backend/2of5inter.c index 95e9942b..fe6b3d38 100644 --- a/backend/2of5inter.c +++ b/backend/2of5inter.c @@ -43,7 +43,7 @@ static const char C25InterTable[10][5] = { }; /* Common to Interleaved, and to ITF-14, DP Leitcode, DP Identcode */ -INTERNAL int c25_inter_common(struct zint_symbol *symbol, unsigned char source[], int length, +INTERNAL int zint_c25_inter_common(struct zint_symbol *symbol, unsigned char source[], int length, const int checkdigit_option, const int dont_set_height) { int i, j, error_number = 0; char dest[638]; /* 4 + (125 + 1) * 5 + 3 + 1 = 638 */ @@ -53,10 +53,10 @@ INTERNAL int c25_inter_common(struct zint_symbol *symbol, unsigned char source[] const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 125) { /* 4 + (125 + 1) * 9 + 5 = 1143 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 309, "Input length %d too long (maximum 125)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 309, "Input length %d too long (maximum 125)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 310, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 310, "Invalid character at position %d in input (digits only)", i); } @@ -72,7 +72,7 @@ INTERNAL int c25_inter_common(struct zint_symbol *symbol, unsigned char source[] if (have_checkdigit) { /* Add standard GS1 check digit */ - local_source[length] = gs1_check_digit(local_source, length); + local_source[length] = zint_gs1_check_digit(local_source, length); length++; } @@ -96,7 +96,7 @@ INTERNAL int c25_inter_common(struct zint_symbol *symbol, unsigned char source[] memcpy(d, "311", 3); d += 3; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (!dont_set_height) { if (symbol->output_options & COMPLIANT_HEIGHT) { @@ -105,31 +105,32 @@ INTERNAL int c25_inter_common(struct zint_symbol *symbol, unsigned char source[] width = (P(4N + 6) + N + 6)X = (length / 2) * 18 + 9 */ /* Taking min X = 0.330mm from Annex D.3.1 (application specification) */ const float min_height_min = 15.151515f; /* 5.0 / 0.33 */ - float min_height = stripf((18.0f * (length / 2) + 9.0f) * 0.15f); + float min_height = z_stripf((18.0f * (length / 2) + 9.0f) * 0.15f); if (min_height < min_height_min) { min_height = min_height_min; } /* Using 50 as default as none recommended */ - 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, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/); } } /* Exclude check digit from HRT if hidden */ - hrt_cpy_nochk(symbol, local_source, length - (symbol->option_2 == 2)); + z_hrt_cpy_nochk(symbol, local_source, length - (symbol->option_2 == 2)); - if (raw_text && rt_cpy(symbol, local_source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, local_source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; } /* Code 2 of 5 Interleaved ISO/IEC 16390:2007 */ -INTERNAL int c25inter(struct zint_symbol *symbol, unsigned char source[], int length) { - return c25_inter_common(symbol, source, length, symbol->option_2 /*checkdigit_option*/, 0 /*dont_set_height*/); +INTERNAL int zint_c25inter(struct zint_symbol *symbol, unsigned char source[], int length) { + return zint_c25_inter_common(symbol, source, length, symbol->option_2 /*checkdigit_option*/, + 0 /*dont_set_height*/); } /* vim: set ts=4 sw=4 et : */ diff --git a/backend/2of5inter_based.c b/backend/2of5inter_based.c index 9ded5b58..688d22c5 100644 --- a/backend/2of5inter_based.c +++ b/backend/2of5inter_based.c @@ -36,11 +36,11 @@ #include "common.h" #include "gs1.h" -INTERNAL int c25_inter_common(struct zint_symbol *symbol, unsigned char source[], int length, +INTERNAL int zint_c25_inter_common(struct zint_symbol *symbol, unsigned char source[], int length, const int checkdigit_option, const int dont_set_height); /* Interleaved 2-of-5 (ITF-14) */ -INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_itf14(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number, zeroes; unsigned char local_source[14]; unsigned char have_check_digit = '\0'; @@ -56,11 +56,11 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt length -= 2; } if (length > 14) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 311, "Input length %d too long (maximum 14)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 311, "Input length %d too long (maximum 14)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 312, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 312, "Invalid character at position %d in input (digits only)", i); } @@ -77,13 +77,13 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt memcpy(local_source + zeroes, source, length); /* Calculate the check digit - the same method used for EAN-13 */ - check_digit = (unsigned char) gs1_check_digit(local_source, 13); + check_digit = (unsigned char) zint_gs1_check_digit(local_source, 13); if (have_check_digit && have_check_digit != check_digit) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 850, "Invalid check digit '%1$c', expecting '%2$c'", - have_check_digit, check_digit); + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 850, "Invalid check digit '%1$c', expecting '%2$c'", + have_check_digit, check_digit); } local_source[13] = check_digit; - error_number = c25_inter_common(symbol, local_source, 14, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); + error_number = zint_c25_inter_common(symbol, local_source, 14, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); if (error_number < ZINT_ERROR) { if (!(symbol->output_options & (BARCODE_BOX | BARCODE_BIND | BARCODE_BIND_TOP))) { @@ -101,29 +101,29 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt height 5.8mm / 1.016mm (X max) ~ 5.7; default 31.75mm / 0.495mm ~ 64.14 */ const float min_height = 5.70866156f; /* 5.8 / 1.016 */ const float default_height = 64.1414108f; /* 31.75 / 0.495 */ - error_number = set_height(symbol, min_height, default_height, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, min_height, default_height, 0.0f, 0 /*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*/); } } - hrt_cpy_nochk(symbol, local_source, 14); + z_hrt_cpy_nochk(symbol, local_source, 14); - /* Use `raw_text` set by `c25_inter_common()` */ + /* Use `raw_text` set by `zint_c25_inter_common()` */ return error_number; } /* Deutsche Post check digit */ static char c25_dp_check_digit(const unsigned int count) { - return itoc((10 - (count % 10)) % 10); + return z_itoc((10 - (count % 10)) % 10); } /* Deutsche Post Leitcode */ /* Documentation (of a very incomplete and non-technical type): https://www.deutschepost.de/content/dam/dpag/images/D_d/dialogpost-schwer/dp-dialogpost-schwer-broschuere-072021.pdf */ -INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_dpleit(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number; unsigned int count; int factor; @@ -132,10 +132,10 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng count = 0; if (length > 13) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 313, "Input length %d too long (maximum 13)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 313, "Input length %d too long (maximum 13)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 314, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 314, "Invalid character at position %d in input (digits only)", i); } @@ -146,29 +146,29 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng factor = 4; for (i = 12; i >= 0; i--) { - count += factor * ctoi(local_source[i]); + count += factor * z_ctoi(local_source[i]); factor ^= 0x0D; /* Toggles 4 and 9 */ } local_source[13] = c25_dp_check_digit(count); - error_number = c25_inter_common(symbol, local_source, 14, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); + error_number = zint_c25_inter_common(symbol, local_source, 14, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); /* TODO: Find documentation on BARCODE_DPLEIT dimensions/height */ /* Based on eyeballing DIALOGPOST SCHWER, using 72X as default */ - (void) set_height(symbol, 0.0f, 72.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 72.0f, 0.0f, 1 /*no_errtxt*/); /* HRT formatting as per DIALOGPOST SCHWER brochure but TEC-IT differs as do examples at https://www.philaseiten.de/cgi-bin/index.pl?ST=8615&CP=0&F=1#M147 */ - hrt_printf_nochk(symbol, "%.5s.%.3s.%.3s.%.3s", local_source, local_source + 5, local_source + 8, - local_source + 11); + z_hrt_printf_nochk(symbol, "%.5s.%.3s.%.3s.%.3s", local_source, local_source + 5, local_source + 8, + local_source + 11); - /* Use `raw_text` set by `c25_inter_common()` */ + /* Use `raw_text` set by `zint_c25_inter_common()` */ return error_number; } /* Deutsche Post Identcode */ /* See dpleit() for (sort of) documentation reference */ -INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_dpident(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number, zeroes; unsigned int count; int factor; @@ -176,10 +176,10 @@ INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int len count = 0; if (length > 11) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 315, "Input length %d too long (maximum 11)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 315, "Input length %d too long (maximum 11)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 316, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 316, "Invalid character at position %d in input (digits only)", i); } @@ -190,21 +190,21 @@ INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int len factor = 4; for (i = 10; i >= 0; i--) { - count += factor * ctoi(local_source[i]); + count += factor * z_ctoi(local_source[i]); factor ^= 0x0D; /* Toggles 4 and 9 */ } local_source[11] = c25_dp_check_digit(count); - error_number = c25_inter_common(symbol, local_source, 12, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); + error_number = zint_c25_inter_common(symbol, local_source, 12, 0 /*checkdigit_option*/, 1 /*dont_set_height*/); /* TODO: Find documentation on BARCODE_DPIDENT dimensions/height */ /* Based on eyeballing DIALOGPOST SCHWER, using 72X as default */ - (void) set_height(symbol, 0.0f, 72.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 72.0f, 0.0f, 1 /*no_errtxt*/); /* HRT formatting as per DIALOGPOST SCHWER brochure but TEC-IT differs as do other examples (see above) */ - hrt_printf_nochk(symbol, "%.2s.%.2s %c.%.3s.%.3s %c", local_source, local_source + 2, local_source[4], - local_source + 5, local_source + 8, local_source[11]); + z_hrt_printf_nochk(symbol, "%.2s.%.2s %c.%.3s.%.3s %c", local_source, local_source + 2, local_source[4], + local_source + 5, local_source + 8, local_source[11]); - /* Use `raw_text` set by `c25_inter_common()` */ + /* Use `raw_text` set by `zint_c25_inter_common()` */ return error_number; } diff --git a/backend/auspost.c b/backend/auspost.c index 1d77b6b0..c5afba9d 100644 --- a/backend/auspost.c +++ b/backend/auspost.c @@ -86,9 +86,9 @@ static char *aus_rs_error(char data_pattern[], char *d) { + aus_convert_pattern(data_pattern[reader + 2], 0); } - rs_init_gf(&rs, 0x43); - rs_init_code(&rs, 4, 1); - rs_encode(&rs, triple_writer, triple, result); + zint_rs_init_gf(&rs, 0x43); + zint_rs_init_code(&rs, 4, 1); + zint_rs_encode(&rs, triple_writer, triple, result); for (reader = 0; reader < 4; reader++, d += 3) { memcpy(d, AusBarTable[result[reader]], 3); @@ -97,10 +97,10 @@ static char *aus_rs_error(char data_pattern[], char *d) { return d; } -INTERNAL int daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height); +INTERNAL int zint_daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height); /* Handles Australia Posts's 4 State Codes */ -INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_auspost(struct zint_symbol *symbol, unsigned char source[], int length) { /* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically (i.e. the FCC doesn't need to be specified by the user) dependent on the length of the input string */ @@ -127,16 +127,16 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len /* Do all of the length checking first to avoid stack smashing */ if (symbol->symbology == BARCODE_AUSPOST) { if (length != 8 && length != 13 && length != 16 && length != 18 && length != 23) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 401, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 401, "Input length %d wrong (8, 13, 16, 18 or 23 characters required)", length); } } else if (length > 8) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 403, "Input length %d too long (maximum 8)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 403, "Input length %d too long (maximum 8)", length); } /* Check input immediately to catch nuls */ - if ((i = not_sane(GDSET_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 404, + if ((i = z_not_sane(GDSET_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 404, "Invalid character at position %d in input (alphanumerics, space and \"#\" only)", i); } @@ -151,8 +151,8 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len break; case 16: memcpy(fcc, "59", 2); - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 402, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 402, "Invalid character at position %d in input (digits only for FCC 59 length 16)", i); } @@ -162,8 +162,8 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len break; case 23: memcpy(fcc, "62", 2); - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 406, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 406, "Invalid character at position %d in input (digits only for FCC 62 length 23)", i); } @@ -189,8 +189,8 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len length += zeroes; /* Verify that the first 8 characters are numbers */ memcpy(dpid, local_source, 8); - if ((i = not_sane(NEON_F, dpid, 8))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 405, + if ((i = z_not_sane(NEON_F, dpid, 8))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 405, "Invalid character at position %d in DPID (first 8 characters) (digits only)", i); } @@ -212,7 +212,7 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len if (length > 8) { if ((length == 13) || (length == 18)) { for (reader = 8; reader < length; reader++, d += 3) { - memcpy(d, AusCTable[posn(GDSET, local_source[reader])], 3); + memcpy(d, AusCTable[z_posn(GDSET, local_source[reader])], 3); } } else if ((length == 16) || (length == 23)) { for (reader = 8; reader < length; reader++, d += 2) { @@ -245,11 +245,11 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len h = d - data_pattern; for (loopey = 0; loopey < h; loopey++) { if ((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0')) { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); if ((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0')) { - set_module(symbol, 2, writer); + z_set_module(symbol, 2, writer); } writer += 2; } @@ -265,17 +265,18 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len */ symbol->row_height[0] = 3.7f; /* 1.85f / 0.5f */ symbol->row_height[1] = 2.6f; /* 1.3f / 0.5f */ - error_number = daft_set_height(symbol, 7.0f, 14.0f); /* Note using max X for minimum and min X for maximum */ + /* Note using max X for minimum and min X for maximum */ + error_number = zint_daft_set_height(symbol, 7.0f, 14.0f); } else { symbol->row_height[0] = 3.0f; symbol->row_height[1] = 2.0f; - error_number = daft_set_height(symbol, 0.0f, 0.0f); + error_number = zint_daft_set_height(symbol, 0.0f, 0.0f); } symbol->rows = 3; symbol->width = writer - 1; - if (raw_text && rt_cpy_cat(symbol, fcc, 2, '\xFF' /*separator (none)*/, local_source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, fcc, 2, '\xFF' /*separator (none)*/, local_source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; diff --git a/backend/aztec.c b/backend/aztec.c index aeec30d9..ef011038 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -95,13 +95,13 @@ static char az_get_next_mode(const char encode_mode[], const int src_len, int i) } } -/* Same as `bin_append_posn()`, except check for buffer overflow first */ +/* Same as `z_bin_append_posn()`, except check for buffer overflow first */ static int az_bin_append_posn(const int arg, const int length, char *binary, const int bin_posn) { if (bin_posn + length > AZTEC_BIN_CAPACITY) { return 0; /* Fail */ } - return bin_append_posn(arg, length, binary, bin_posn); + return z_bin_append_posn(arg, length, binary, bin_posn); } /* Determine encoding modes and encode */ @@ -402,47 +402,47 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp, } if (bp == gs1_bp && gs1) { - bp = bin_append_posn(0, 5, binary_string, bp); /* P/S */ - bp = bin_append_posn(0, 5, binary_string, bp); /* FLG(n) */ - bp = bin_append_posn(0, 3, binary_string, bp); /* FLG(0) */ + bp = z_bin_append_posn(0, 5, binary_string, bp); /* P/S */ + bp = z_bin_append_posn(0, 5, binary_string, bp); /* FLG(n) */ + bp = z_bin_append_posn(0, 3, binary_string, bp); /* FLG(0) */ } if (eci != 0) { - bp = bin_append_posn(0, initial_mode == 'D' ? 4 : 5, binary_string, bp); /* P/S */ - bp = bin_append_posn(0, 5, binary_string, bp); /* FLG(n) */ + bp = z_bin_append_posn(0, initial_mode == 'D' ? 4 : 5, binary_string, bp); /* P/S */ + bp = z_bin_append_posn(0, 5, binary_string, bp); /* FLG(n) */ if (eci < 10) { - bp = bin_append_posn(1, 3, binary_string, bp); /* FLG(1) */ - bp = bin_append_posn(2 + eci, 4, binary_string, bp); + bp = z_bin_append_posn(1, 3, binary_string, bp); /* FLG(1) */ + bp = z_bin_append_posn(2 + eci, 4, binary_string, bp); } else if (eci <= 99) { - bp = bin_append_posn(2, 3, binary_string, bp); /* FLG(2) */ - bp = bin_append_posn(2 + (eci / 10), 4, binary_string, bp); - bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); + bp = z_bin_append_posn(2, 3, binary_string, bp); /* FLG(2) */ + bp = z_bin_append_posn(2 + (eci / 10), 4, binary_string, bp); + bp = z_bin_append_posn(2 + (eci % 10), 4, binary_string, bp); } else if (eci <= 999) { - bp = bin_append_posn(3, 3, binary_string, bp); /* FLG(3) */ - bp = bin_append_posn(2 + (eci / 100), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); - bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); + bp = z_bin_append_posn(3, 3, binary_string, bp); /* FLG(3) */ + bp = z_bin_append_posn(2 + (eci / 100), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); + bp = z_bin_append_posn(2 + (eci % 10), 4, binary_string, bp); } else if (eci <= 9999) { - bp = bin_append_posn(4, 3, binary_string, bp); /* FLG(4) */ - bp = bin_append_posn(2 + (eci / 1000), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); - bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); + bp = z_bin_append_posn(4, 3, binary_string, bp); /* FLG(4) */ + bp = z_bin_append_posn(2 + (eci / 1000), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); + bp = z_bin_append_posn(2 + (eci % 10), 4, binary_string, bp); } else if (eci <= 99999) { - bp = bin_append_posn(5, 3, binary_string, bp); /* FLG(5) */ - bp = bin_append_posn(2 + (eci / 10000), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 10000) / 1000), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); - bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); + bp = z_bin_append_posn(5, 3, binary_string, bp); /* FLG(5) */ + bp = z_bin_append_posn(2 + (eci / 10000), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 10000) / 1000), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); + bp = z_bin_append_posn(2 + (eci % 10), 4, binary_string, bp); } else { - bp = bin_append_posn(6, 3, binary_string, bp); /* FLG(6) */ - bp = bin_append_posn(2 + (eci / 100000), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 100000) / 10000), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 10000) / 1000), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp); - bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); - bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); + bp = z_bin_append_posn(6, 3, binary_string, bp); /* FLG(6) */ + bp = z_bin_append_posn(2 + (eci / 100000), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 100000) / 10000), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 10000) / 1000), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp); + bp = z_bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); + bp = z_bin_append_posn(2 + (eci % 10), 4, binary_string, bp); } } @@ -693,8 +693,8 @@ static int aztec_text_process_segs(struct zint_symbol *symbol, struct zint_seg s /* GS1 raw text dealt with by `ZBarcode_Encode_Segs()` */ const int raw_text = (symbol->input_mode & 0x07) != GS1_MODE && (symbol->output_options & BARCODE_RAW_TEXT); - 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++) { @@ -702,8 +702,8 @@ static int aztec_text_process_segs(struct zint_symbol *symbol, struct zint_seg s ¤t_mode, &bp, debug_print)) { return ZINT_ERROR_TOO_LONG; /* `aztec_text_process()` only fails with too long */ } - if (raw_text && rt_cpy_seg(symbol, i, &segs[i])) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg(symbol, i, &segs[i])) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg()` only fails with OOM */ } } @@ -864,7 +864,7 @@ static int az_codeword_size(const int layers) { return codeword_size; } -INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int x, y, i, p, data_blocks, ecc_blocks, layers, total_bits; char bit_pattern[AZTEC_MAP_POSN_MAX + 1]; /* Note AZTEC_MAP_POSN_MAX > AZTEC_BIN_CAPACITY */ /* To lessen stack usage, share binary_string buffer with bit_pattern, as accessed separately */ @@ -890,7 +890,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int int dim; if (gs1 && reader_init) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 501, "Cannot use Reader Initialisation in GS1 mode"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 501, "Cannot use Reader Initialisation in GS1 mode"); } if (symbol->structapp.count) { @@ -900,24 +900,24 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int int id_len; if (symbol->structapp.count < 2 || symbol->structapp.count > 26) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 701, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 701, "Structured Append count '%d' out of range (2 to 26)", symbol->structapp.count); } if (symbol->structapp.index < 1 || symbol->structapp.index > symbol->structapp.count) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 702, - "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, 702, + "Structured Append index '%1$d' out of range (1 to count %2$d)", + symbol->structapp.index, symbol->structapp.count); } for (id_len = 0; id_len < 32 && symbol->structapp.id[id_len]; id_len++); - if (id_len && chr_cnt((const unsigned char *) symbol->structapp.id, id_len, ' ')) { + if (id_len && z_chr_cnt(ZCUCP(symbol->structapp.id), id_len, ' ')) { /* Note ID can contain any old chars apart from space so don't print in error message */ - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 703, "Structured Append ID cannot contain spaces"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 703, "Structured Append ID cannot contain spaces"); } - bp = bin_append_posn(29, 5, binary_string, bp); /* M/L */ - bp = bin_append_posn(29, 5, binary_string, bp); /* U/L */ + bp = z_bin_append_posn(29, 5, binary_string, bp); /* M/L */ + bp = z_bin_append_posn(29, 5, binary_string, bp); /* U/L */ sa_len = 0; if (id_len) { /* ID has a space on either side */ @@ -943,7 +943,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int debug_print))) { assert(error_number == ZINT_ERROR_TOO_LONG || error_number == ZINT_ERROR_MEMORY); if (error_number == ZINT_ERROR_TOO_LONG) { - return errtxt(error_number, symbol, 502, + return z_errtxt(error_number, symbol, 502, "Input too long, requires too many codewords (maximum " AZ_BIN_CAP_CWDS_S ")"); } return error_number; @@ -951,11 +951,11 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int assert(data_length > 0); /* Suppress clang-tidy warning: clang-analyzer-core.UndefinedBinaryOperatorResult */ if (symbol->option_1 < -1 || symbol->option_1 > 4) { - errtxtf(0, symbol, 503, "Error correction level '%d' out of range (1 to 4)", symbol->option_1); + z_errtxtf(0, symbol, 503, "Error correction level '%d' out of range (1 to 4)", symbol->option_1); if (symbol->warn_level == WARN_FAIL_ALL) { return ZINT_ERROR_INVALID_OPTION; } - error_number = errtxt_adj(ZINT_WARN_INVALID_OPTION, symbol, "%1$s%2$s", ", ignoring"); + error_number = z_errtxt_adj(ZINT_WARN_INVALID_OPTION, symbol, "%1$s%2$s", ", ignoring"); symbol->option_1 = -1; /* Feedback options */ } @@ -993,14 +993,14 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int if (layers == 0) { /* Couldn't find a symbol which fits the data */ if (adjustment_size == 0) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 707, + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 707, "Input too long for ECC level %1$d, requires too many codewords (maximum %2$d)", ecc_level, AztecDataSizes[ecc_level - 1][31] / 12); } - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 504, - "Input too long for ECC level %1$d, requires %2$d codewords (maximum %3$d)", - ecc_level, (data_length + adjustment_size + 11) / 12, - AztecDataSizes[ecc_level - 1][31] / 12); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 504, + "Input too long for ECC level %1$d, requires %2$d codewords (maximum %3$d)", + ecc_level, (data_length + adjustment_size + 11) / 12, + AztecDataSizes[ecc_level - 1][31] / 12); } codeword_size = az_codeword_size(layers); @@ -1008,7 +1008,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int adjusted_length = az_bitrun_stuff(binary_string, data_length, codeword_size, adjustment_size ? data_maxsize : AZTEC_BIN_CAPACITY, adjusted_string); if (adjusted_length == 0) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 705, + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 705, "Input too long for ECC level %1$d, requires too many codewords (maximum %2$d)", ecc_level, (adjustment_size ? data_maxsize : AZTEC_BIN_CAPACITY) / codeword_size); } @@ -1038,8 +1038,8 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int } else { /* The size of the symbol has been specified by the user */ if ((symbol->option_2 < 0) || (symbol->option_2 > 36)) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 510, "Version '%d' out of range (1 to 36)", - symbol->option_2); + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 510, "Version '%d' out of range (1 to 36)", + symbol->option_2); } if (reader_init) { /* For back-compatibility, silently ignore compact 2-4 requests but error on layers > 22 */ @@ -1047,7 +1047,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int symbol->option_2 = 5; } else if (symbol->option_2 > 26) { /* Caught below anyway but catch here also for better feedback */ - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 709, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 709, "Version '%d' out of range for Reader Initialisation symbols (maximum 26)", symbol->option_2); } @@ -1069,9 +1069,9 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int adjusted_length = az_bitrun_stuff(binary_string, data_length, codeword_size, data_maxsize, adjusted_string); if (adjusted_length == 0) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 704, - "Input too long for Version %1$d, requires too many codewords (maximum %2$d)", - symbol->option_2, data_maxsize / codeword_size); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 704, + "Input too long for Version %1$d, requires too many codewords (maximum %2$d)", + symbol->option_2, data_maxsize / codeword_size); } /* Add padding */ @@ -1086,10 +1086,10 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int /* Check if the data actually fits into the selected symbol size */ if (adjusted_length + padbits > data_maxsize) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 505, - "Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)", - symbol->option_2, (adjusted_length + padbits) / codeword_size, - data_maxsize / codeword_size); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 505, + "Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)", + symbol->option_2, (adjusted_length + padbits) / codeword_size, + data_maxsize / codeword_size); } adjusted_length = az_add_padding(padbits, codeword_size, adjusted_string, adjusted_length); @@ -1106,7 +1106,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int } if (reader_init && (layers > 22)) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 506, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 506, "Input too long for Reader Initialisation, requires %d layers (maximum 22)", layers); } @@ -1122,21 +1122,21 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int } if (ecc_blocks == 3) { ecc_ratio = 0.0f; - error_number = ZEXT errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 706, "Number of ECC codewords 3 at minimum"); + error_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 706, "Number of ECC codewords 3 at minimum"); symbol->option_1 = -1; /* Feedback options: indicate minimum 3 with -1 */ } else { - ecc_ratio = stripf((float) (ecc_blocks - 3) / (data_blocks + ecc_blocks)); + ecc_ratio = z_stripf((float) (ecc_blocks - 3) / (data_blocks + ecc_blocks)); if (ecc_ratio < 0.05f) { - error_number = ZEXT errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 708, - "Number of ECC codewords %1$d less than 5%% + 3 of data codewords %2$d", - ecc_blocks, data_blocks); + error_number = ZEXT z_errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 708, + "Number of ECC codewords %1$d less than 5%% + 3 of data codewords %2$d", + ecc_blocks, data_blocks); symbol->option_1 = 0; /* Feedback options: indicate < 5% + 3 with 0 */ } else { /* Feedback options: 0.165 = (.1 + .23) / 2 etc */ symbol->option_1 = ecc_ratio < 0.165f ? 1 : ecc_ratio < 0.295f ? 2 : ecc_ratio < 0.43f ? 3 : 4; } /* Feedback percentage in top byte */ - symbol->option_1 |= ((int) stripf(ecc_ratio * 100.0f)) << 8; + symbol->option_1 |= ((int) z_stripf(ecc_ratio * 100.0f)) << 8; } if (debug_print) { @@ -1164,36 +1164,36 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int switch (codeword_size) { case 6: - rs_init_gf(&rs, 0x43); - rs_init_code(&rs, ecc_blocks, 1); - rs_encode_uint(&rs, data_blocks, data_part, ecc_part); + zint_rs_init_gf(&rs, 0x43); + zint_rs_init_code(&rs, ecc_blocks, 1); + zint_rs_encode_uint(&rs, data_blocks, data_part, ecc_part); break; case 8: - rs_init_gf(&rs, 0x12d); - rs_init_code(&rs, ecc_blocks, 1); - rs_encode_uint(&rs, data_blocks, data_part, ecc_part); + zint_rs_init_gf(&rs, 0x12d); + zint_rs_init_code(&rs, ecc_blocks, 1); + zint_rs_encode_uint(&rs, data_blocks, data_part, ecc_part); break; case 10: - if (!rs_uint_init_gf(&rs_uint, 0x409, 1023)) { /* Can fail on malloc() */ - return errtxt(ZINT_ERROR_MEMORY, symbol, 500, "Insufficient memory for Reed-Solomon log tables"); + if (!zint_rs_uint_init_gf(&rs_uint, 0x409, 1023)) { /* Can fail on malloc() */ + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 500, "Insufficient memory for Reed-Solomon log tables"); } - rs_uint_init_code(&rs_uint, ecc_blocks, 1); - rs_uint_encode(&rs_uint, data_blocks, data_part, ecc_part); - rs_uint_free(&rs_uint); + zint_rs_uint_init_code(&rs_uint, ecc_blocks, 1); + zint_rs_uint_encode(&rs_uint, data_blocks, data_part, ecc_part); + zint_rs_uint_free(&rs_uint); break; case 12: - if (!rs_uint_init_gf(&rs_uint, 0x1069, 4095)) { /* Can fail on malloc() */ + if (!zint_rs_uint_init_gf(&rs_uint, 0x1069, 4095)) { /* Can fail on malloc() */ /* Note using AUSPOST error nos range as out of 50x ones & 51x taken by CODEONE */ - return errtxt(ZINT_ERROR_MEMORY, symbol, 700, "Insufficient memory for Reed-Solomon log tables"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 700, "Insufficient memory for Reed-Solomon log tables"); } - rs_uint_init_code(&rs_uint, ecc_blocks, 1); - rs_uint_encode(&rs_uint, data_blocks, data_part, ecc_part); - rs_uint_free(&rs_uint); + zint_rs_uint_init_code(&rs_uint, ecc_blocks, 1); + zint_rs_uint_encode(&rs_uint, data_blocks, data_part, ecc_part); + zint_rs_uint_free(&rs_uint); break; } for (i = 0; i < ecc_blocks; i++) { - adjusted_length = bin_append_posn(ecc_part[i], codeword_size, adjusted_string, adjusted_length); + adjusted_length = z_bin_append_posn(ecc_part[i], codeword_size, adjusted_string, adjusted_length); } /* Invert the data so that actual data is on the outside and reed-solomon on the inside */ @@ -1242,10 +1242,10 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int /* Add Reed-Solomon error correction with Galois field GF(16) and prime modulus x^4 + x + 1 (section 7.2.3) */ - rs_init_gf(&rs, 0x13); + zint_rs_init_gf(&rs, 0x13); if (compact) { - rs_init_code(&rs, 5, 1); - rs_encode(&rs, 2, desc_data, desc_ecc); + zint_rs_init_code(&rs, 5, 1); + zint_rs_encode(&rs, 2, desc_data, desc_ecc); for (i = 0; i < 5; i++) { descriptor[(i * 4) + 8] = (desc_ecc[i] & 0x08) ? '1' : '0'; descriptor[(i * 4) + 9] = (desc_ecc[i] & 0x04) ? '1' : '0'; @@ -1253,8 +1253,8 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int descriptor[(i * 4) + 11] = (desc_ecc[i] & 0x01) ? '1' : '0'; } } else { - rs_init_code(&rs, 6, 1); - rs_encode(&rs, 4, desc_data, desc_ecc); + zint_rs_init_code(&rs, 6, 1); + zint_rs_encode(&rs, 4, desc_data, desc_ecc); for (i = 0; i < 6; i++) { descriptor[(i * 4) + 16] = (desc_ecc[i] & 0x08) ? '1' : '0'; descriptor[(i * 4) + 17] = (desc_ecc[i] & 0x04) ? '1' : '0'; @@ -1279,7 +1279,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int for (x = offset; x < end_offset; x++) { const int map = AztecCompactMap[y_map + x]; if (map == 1 || (map >= 2 && bit_pattern[map - 2] == '1')) { - set_module(symbol, y - offset, x - offset); + z_set_module(symbol, y - offset, x - offset); } } symbol->row_height[y - offset] = 1; @@ -1294,7 +1294,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int for (x = offset; x < end_offset; x++) { const int map = AztecMap[y_map + x]; if (map == 1 || (map >= 2 && bit_pattern[map - 2] == '1')) { - set_module(symbol, y - offset, x - offset); + z_set_module(symbol, y - offset, x - offset); } } symbol->row_height[y - offset] = 1; @@ -1309,7 +1309,7 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int } /* Encodes Aztec runes as specified in ISO/IEC 24778:2008 Annex A */ -INTERNAL int azrune(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_azrune(struct zint_symbol *symbol, unsigned char source[], int length) { unsigned int input_value; int i, y, x, r; char binary_string[28]; @@ -1319,41 +1319,30 @@ INTERNAL int azrune(struct zint_symbol *symbol, unsigned char source[], int leng const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; - input_value = 0; if (length > 3) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 507, "Input length %d too long (maximum 3)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 507, "Input length %d too long (maximum 3)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 508, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 508, "Invalid character at position %d in input (digits only)", i); } - switch (length) { - case 3: - input_value = 100 * ctoi(source[0]) + 10 * ctoi(source[1]) + ctoi(source[2]); - break; - case 2: - input_value = 10 * ctoi(source[0]) + ctoi(source[1]); - break; - case 1: - input_value = ctoi(source[0]); - break; - } + input_value = z_to_int(source, length); if (input_value > 255) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 509, "Input value out of range (0 to 255)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 509, "Input value out of range (0 to 255)"); } - bp = bin_append_posn(input_value, 8, binary_string, bp); + bp = z_bin_append_posn(input_value, 8, binary_string, bp); data_codewords[0] = (unsigned char) (input_value >> 4); data_codewords[1] = (unsigned char) (input_value & 0xF); - rs_init_gf(&rs, 0x13); - rs_init_code(&rs, 5, 1); - rs_encode(&rs, 2, data_codewords, ecc_codewords); + zint_rs_init_gf(&rs, 0x13); + zint_rs_init_code(&rs, 5, 1); + zint_rs_encode(&rs, 2, data_codewords, ecc_codewords); for (i = 0; i < 5; i++) { - bp = bin_append_posn(ecc_codewords[i], 4, binary_string, bp); + bp = z_bin_append_posn(ecc_codewords[i], 4, binary_string, bp); } for (i = 0; i < 28; i += 2) { @@ -1368,9 +1357,9 @@ INTERNAL int azrune(struct zint_symbol *symbol, unsigned char source[], int leng r = y * 27; for (x = 8; x < 19; x++) { if (AztecCompactMap[r + x] == 1) { - set_module(symbol, y - 8, x - 8); + z_set_module(symbol, y - 8, x - 8); } else if (AztecCompactMap[r + x] && binary_string[AztecCompactMap[r + x] - 2000] == '1') { - set_module(symbol, y - 8, x - 8); + z_set_module(symbol, y - 8, x - 8); } } symbol->row_height[y - 8] = 1; @@ -1379,8 +1368,8 @@ INTERNAL int azrune(struct zint_symbol *symbol, unsigned char source[], int leng symbol->rows = 11; symbol->width = 11; - if (raw_text && rt_printf_256(symbol, "%03d", input_value)) { - return ZINT_ERROR_MEMORY; /* `rt_printf_256()` only fails with OOM */ + if (raw_text && z_rt_printf_256(symbol, "%03d", input_value)) { + return ZINT_ERROR_MEMORY; /* `z_rt_printf_256()` only fails with OOM */ } return 0; diff --git a/backend/bc412.c b/backend/bc412.c index c9f626ad..67257271 100644 --- a/backend/bc412.c +++ b/backend/bc412.c @@ -65,7 +65,7 @@ static const char BC412Table[35][8] = { {'1','2','1','3','1','1','1','2'} }; -INTERNAL int bc412(struct zint_symbol *symbol, unsigned char source[], int length) { /* IBM BC412 */ +INTERNAL int zint_bc412(struct zint_symbol *symbol, unsigned char source[], int length) { /* IBM BC412 */ unsigned char padded_source[20]; int posns[35]; int i, counter_odd = 0, counter_even = 0, check_sum = 0; @@ -75,12 +75,12 @@ INTERNAL int bc412(struct zint_symbol *symbol, unsigned char source[], int lengt const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 18) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 790, "Input length %d too long (maximum 18)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 790, "Input length %d too long (maximum 18)", length); } if (length < 7) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 792, "Input length %d too short (minimum 7)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 792, "Input length %d too short (minimum 7)", length); } - to_upper(source, length); + z_to_upper(source, length); padded_source[0] = source[0]; padded_source[1] = '0'; @@ -89,8 +89,8 @@ INTERNAL int bc412(struct zint_symbol *symbol, unsigned char source[], int lengt padded_source[i] = source[i - 1]; } - if ((i = not_sane_lookup(BROMINE, 35, padded_source, length + 1, posns))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 791, + if ((i = z_not_sane_lookup(BROMINE, 35, padded_source, length + 1, posns))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 791, "Invalid character at position %d in input (alphanumerics only, excluding \"O\")", i - 1); } @@ -130,7 +130,7 @@ INTERNAL int bc412(struct zint_symbol *symbol, unsigned char source[], int lengt memcpy(d, "111", 3); d += 3; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (symbol->output_options & COMPLIANT_HEIGHT) { /* SEMI T1-95 Table 1 "Module" (Character) Height 2mm ± 0.025mm, using Module Spacing 0.12mm ± 0.025mm as @@ -138,17 +138,17 @@ INTERNAL int bc412(struct zint_symbol *symbol, unsigned char source[], int lengt const float min_height = 13.6206894f; /* 1.975 / 0.145 */ const float default_height = 16.666666f; /* 2.0 / 0.12 */ const float max_height = 21.3157902f; /* 2.025 / 0.095 */ - error_number = set_height(symbol, min_height, default_height, max_height, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, min_height, default_height, max_height, 0 /*no_errtxt*/); } else { /* Using compliant height as default as no backwards compatibility to consider */ const float default_height = 16.666666f; /* 2.0 / 0.12 */ - (void) set_height(symbol, 0.0f, default_height, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, default_height, 0.0f, 1 /*no_errtxt*/); } - hrt_cpy_nochk(symbol, padded_source, length + 1); + z_hrt_cpy_nochk(symbol, padded_source, length + 1); - if (raw_text && rt_cpy(symbol, padded_source, length + 1)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, padded_source, length + 1)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; diff --git a/backend/bmp.c b/backend/bmp.c index 4c69979a..0c1f8ae6 100644 --- a/backend/bmp.c +++ b/backend/bmp.c @@ -38,7 +38,7 @@ #include "output.h" #include "bmp.h" /* Bitmap header structure */ -INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) { +INTERNAL int zint_bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) { int i, row, column; int bits_per_pixel; int colour_count; @@ -55,16 +55,16 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix unsigned char map[128]; unsigned char *rowbuf; - (void) out_colour_get_rgb(symbol->fgcolour, &fg.red, &fg.green, &fg.blue, NULL /*alpha*/); + (void) zint_out_colour_get_rgb(symbol->fgcolour, &fg.red, &fg.green, &fg.blue, NULL /*alpha*/); fg.reserved = 0x00; - (void) out_colour_get_rgb(symbol->bgcolour, &bg.red, &bg.green, &bg.blue, NULL /*alpha*/); + (void) zint_out_colour_get_rgb(symbol->bgcolour, &bg.red, &bg.green, &bg.blue, NULL /*alpha*/); bg.reserved = 0x00; if (symbol->symbology == BARCODE_ULTRA) { static const unsigned char ultra_chars[8] = { 'C', 'B', 'M', 'R', 'Y', 'G', 'K', 'W' }; for (i = 0; i < 8; i++) { - out_colour_char_to_rgb(ultra_chars[i], &palette[i].red, &palette[i].green, &palette[i].blue); + zint_out_colour_char_to_rgb(ultra_chars[i], &palette[i].red, &palette[i].green, &palette[i].blue); palette[i].reserved = 0x00; if (memcmp(&palette[i], &fg, sizeof(fg)) == 0) { ultra_fg_index = i + 1; @@ -88,51 +88,51 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix /* Must fit in `uint32_t` field in header */ if (file_size != (uint32_t) file_size) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 606, "Output size too large for file size field of BMP header"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 606, "Output size too large for file size field of BMP header"); } if (!(rowbuf = (unsigned char *) malloc(row_size))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 602, "Insufficient memory for BMP row buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 602, "Insufficient memory for BMP row buffer"); } - out_le_u16(file_header.header_field, 0x4d42); /* "BM" */ - out_le_u32(file_header.file_size, file_size); - out_le_u32(file_header.reserved, 0); - out_le_u32(file_header.data_offset, data_offset); + zint_out_le_u16(file_header.header_field, 0x4d42); /* "BM" */ + zint_out_le_u32(file_header.file_size, file_size); + zint_out_le_u32(file_header.reserved, 0); + zint_out_le_u32(file_header.data_offset, data_offset); - out_le_u32(info_header.header_size, sizeof(bitmap_info_header_t)); - out_le_i32(info_header.width, symbol->bitmap_width); - out_le_i32(info_header.height, symbol->bitmap_height); - out_le_u16(info_header.colour_planes, 1); - out_le_u16(info_header.bits_per_pixel, bits_per_pixel); - out_le_u32(info_header.compression_method, 0); /* BI_RGB */ - out_le_u32(info_header.image_size, 0); - resolution = symbol->dpmm ? (int) roundf(stripf(symbol->dpmm * 1000.0f)) : 0; /* pixels per metre */ - out_le_i32(info_header.horiz_res, resolution); - out_le_i32(info_header.vert_res, resolution); - out_le_u32(info_header.colours, colour_count); - out_le_u32(info_header.important_colours, colour_count); + zint_out_le_u32(info_header.header_size, sizeof(bitmap_info_header_t)); + zint_out_le_i32(info_header.width, symbol->bitmap_width); + zint_out_le_i32(info_header.height, symbol->bitmap_height); + zint_out_le_u16(info_header.colour_planes, 1); + zint_out_le_u16(info_header.bits_per_pixel, bits_per_pixel); + zint_out_le_u32(info_header.compression_method, 0); /* BI_RGB */ + zint_out_le_u32(info_header.image_size, 0); + resolution = symbol->dpmm ? (int) roundf(z_stripf(symbol->dpmm * 1000.0f)) : 0; /* pixels per metre */ + zint_out_le_i32(info_header.horiz_res, resolution); + zint_out_le_i32(info_header.vert_res, resolution); + zint_out_le_u32(info_header.colours, colour_count); + zint_out_le_u32(info_header.important_colours, colour_count); /* Open output file in binary mode */ - if (!fm_open(fmp, symbol, "wb")) { - ZEXT errtxtf(0, symbol, 601, "Could not open BMP output file (%1$d: %2$s)", fmp->err, strerror(fmp->err)); + if (!zint_fm_open(fmp, symbol, "wb")) { + ZEXT z_errtxtf(0, symbol, 601, "Could not open BMP output file (%1$d: %2$s)", fmp->err, strerror(fmp->err)); free(rowbuf); return ZINT_ERROR_FILE_ACCESS; } - fm_write(&file_header, sizeof(bitmap_file_header_t), 1, fmp); - fm_write(&info_header, sizeof(bitmap_info_header_t), 1, fmp); + zint_fm_write(&file_header, sizeof(bitmap_file_header_t), 1, fmp); + zint_fm_write(&info_header, sizeof(bitmap_info_header_t), 1, fmp); - fm_write(&bg, sizeof(color_ref_t), 1, fmp); + zint_fm_write(&bg, sizeof(color_ref_t), 1, fmp); if (bits_per_pixel == 4) { for (i = 0; i < 8; i++) { - fm_write(&palette[i], sizeof(color_ref_t), 1, fmp); + zint_fm_write(&palette[i], sizeof(color_ref_t), 1, fmp); } if (ultra_fg_index == 9) { - fm_write(&fg, sizeof(color_ref_t), 1, fmp); + zint_fm_write(&fg, sizeof(color_ref_t), 1, fmp); } } else { - fm_write(&fg, sizeof(color_ref_t), 1, fmp); + zint_fm_write(&fg, sizeof(color_ref_t), 1, fmp); } /* Pixel Plotting */ @@ -143,7 +143,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix for (column = 0; column < symbol->bitmap_width; column++) { rowbuf[column >> 1] |= map[pb[column]] << (!(column & 1) << 2); } - fm_write(rowbuf, 1, row_size, fmp); + zint_fm_write(rowbuf, 1, row_size, fmp); } } else { /* bits_per_pixel == 1 */ for (row = 0; row < symbol->bitmap_height; row++) { @@ -152,20 +152,20 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix for (column = 0; column < symbol->bitmap_width; column++) { rowbuf[column >> 3] |= map[pb[column]] >> (column & 7); } - fm_write(rowbuf, 1, row_size, fmp); + zint_fm_write(rowbuf, 1, row_size, fmp); } } free(rowbuf); - if (fm_error(fmp)) { - ZEXT errtxtf(0, symbol, 603, "Incomplete write of BMP output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); - (void) fm_close(fmp, symbol); + if (zint_fm_error(fmp)) { + ZEXT z_errtxtf(0, symbol, 603, "Incomplete write of BMP output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); + (void) zint_fm_close(fmp, symbol); return ZINT_ERROR_FILE_WRITE; } - if (!fm_close(fmp, symbol)) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 605, "Failure on closing BMP output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_close(fmp, symbol)) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 605, "Failure on closing BMP output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } return 0; diff --git a/backend/channel.c b/backend/channel.c index f3a7b2f5..fb29c3bb 100644 --- a/backend/channel.c +++ b/backend/channel.c @@ -172,7 +172,7 @@ nb0: if (++B[0] <= bmax[0]) goto lb0; } /* Channel Code - According to ANSI/AIM BC12-1998 */ -INTERNAL int channel(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_channel(struct zint_symbol *symbol, unsigned char source[], int length) { static const int max_ranges[] = { -1, -1, -1, 26, 292, 3493, 44072, 576688, 7742862 }; static const unsigned char zeroes_str[] = "0000000"; /* 7 zeroes */ int S[8] = {0}, B[8] = {0}; @@ -184,13 +184,13 @@ INTERNAL int channel(struct zint_symbol *symbol, unsigned char source[], int len const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 7) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 333, "Input length %d too long (maximum 7)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 333, "Input length %d too long (maximum 7)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 334, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 334, "Invalid character at position %d in input (digits only)", i); } - target_value = to_int(source, length); + target_value = z_to_int(source, length); if ((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; @@ -218,12 +218,13 @@ INTERNAL int channel(struct zint_symbol *symbol, unsigned char source[], int len if (target_value > max_ranges[channels]) { if (channels == 8) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 318, "Input value \"%1$d\" out of range (0 to %2$d)", - target_value, max_ranges[channels]); + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 318, + "Input value \"%1$d\" out of range (0 to %2$d)", + target_value, max_ranges[channels]); } - return ZEXT errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 335, - "Input value \"%1$d\" out of range (0 to %2$d for %3$d channels)", target_value, - max_ranges[channels], channels); + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 335, + "Input value \"%1$d\" out of range (0 to %2$d for %3$d channels)", + target_value, max_ranges[channels], channels); } /* Feedback options */ @@ -234,27 +235,27 @@ INTERNAL int channel(struct zint_symbol *symbol, unsigned char source[], int len memcpy(d, "111111111", 9); /* Finder pattern */ d += 9; for (i = 8 - channels; i < 8; i++) { - *d++ = itoc(S[i]); - *d++ = itoc(B[i]); + *d++ = z_itoc(S[i]); + *d++ = z_itoc(B[i]); } - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (symbol->output_options & COMPLIANT_HEIGHT) { /* ANSI/AIM BC12-1998 gives min height as 5mm or 15% of length; X left as application specification so use length = 1X (left qz) + (9 (finder) + 4 * 8 - 2) * X + 2X (right qz); use 20 as default based on figures in spec */ - const float min_height = stripf((1 + 9 + 4 * channels - 2 + 2) * 0.15f); - error_number = set_height(symbol, min_height, 20.0f, 0.0f, 0 /*no_errtxt*/); + const float min_height = z_stripf((1 + 9 + 4 * channels - 2 + 2) * 0.15f); + error_number = z_set_height(symbol, min_height, 20.0f, 0.0f, 0 /*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*/); } zeroes = channels - 1 - length; - hrt_cpy_cat_nochk(symbol, zeroes_str, zeroes, '\xFF' /*separator (none)*/, source, length); + z_hrt_cpy_cat_nochk(symbol, zeroes_str, zeroes, '\xFF' /*separator (none)*/, source, length); - if (raw_text && rt_cpy_cat(symbol, zeroes_str, zeroes, '\xFF' /*separator (none)*/, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, zeroes_str, zeroes, '\xFF' /*separator (none)*/, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; } diff --git a/backend/codabar.c b/backend/codabar.c index b281978a..e0fb4b4e 100644 --- a/backend/codabar.c +++ b/backend/codabar.c @@ -50,7 +50,7 @@ static const char CodaTable[20][8] = { }; /* The Codabar system consisting of simple substitution */ -INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_codabar(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number = 0; int posns[103]; @@ -61,31 +61,31 @@ INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int len const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 103) { /* No stack smashing please (103 + 1) * 11 = 1144 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 356, "Input length %d too long (maximum 103)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 356, "Input length %d too long (maximum 103)", length); } /* BS EN 798:1995 4.2 "'Codabar' symbols shall consist of ... b) start character; c) one or more symbol characters representing data ... d) stop character ..." */ if (length < 3) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 362, "Input length %d too short (minimum 3)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 362, "Input length %d too short (minimum 3)", length); } - to_upper(source, length); + z_to_upper(source, length); /* Codabar must begin and end with the characters A, B, C or D */ if ((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C') && (source[0] != 'D')) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 358, "Does not begin with \"A\", \"B\", \"C\" or \"D\""); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 358, "Does not begin with \"A\", \"B\", \"C\" or \"D\""); } if ((source[length - 1] != 'A') && (source[length - 1] != 'B') && (source[length - 1] != 'C') && (source[length - 1] != 'D')) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 359, "Does not end with \"A\", \"B\", \"C\" or \"D\""); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 359, "Does not end with \"A\", \"B\", \"C\" or \"D\""); } - if ((i = not_sane_lookup(CALCIUM, sizeof(CALCIUM) - 1, source, length, posns))) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 357, - "Invalid character at position %1$d in input (\"%2$s\" only)", i, CALCIUM); + if ((i = z_not_sane_lookup(CALCIUM, sizeof(CALCIUM) - 1, source, length, posns))) { + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 357, + "Invalid character at position %1$d in input (\"%2$s\" only)", i, CALCIUM); } /* And must not use A, B, C or D otherwise (BS EN 798:1995 4.3.2) */ - if ((i = not_sane(CALCIUM_INNER_F, source + 1, length - 2))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 363, + if ((i = z_not_sane(CALCIUM_INNER_F, source + 1, length - 2))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 363, "Invalid character at position %d in input (cannot contain \"A\", \"B\", \"C\" or \"D\")", i); } @@ -116,7 +116,7 @@ INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int len } } - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (symbol->output_options & COMPLIANT_HEIGHT) { /* BS EN 798:1995 4.4.1 (d) max of 5mm / 0.43mm (X max) ~ 11.628 or 15% of width where (taking N = @@ -124,23 +124,24 @@ INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int len = ((4 + 5) * C + (D + 2) + C - 1 + 2 * 10) * X = (10 * C + D + 21) * X Length (C) includes start/stop chars */ const float min_height_min = 11.6279068f; /* 5.0 / 0.43 */ - float min_height = stripf((10.0f * ((add_checksum ? length + 1 : length) + 2.0f) + d_chars + 21.0f) * 0.15f); + float min_height = z_stripf((10.0f * ((length + add_checksum) + 2.0f) + d_chars + 21.0f) * 0.15f); if (min_height < min_height_min) { min_height = min_height_min; } /* Using 50 as default as none recommended */ - error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f, 0 /*no_errtxt*/); + 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, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 50.0f, 0.0f, 1 /*no_errtxt*/); } /* If visible check char, place before final A/B/C/D character (BS EN 798:1995 A.3) */ - hrt_cpy_cat_nochk(symbol, source, length - 1, symbol->option_2 == 2 ? CALCIUM[checksum] : '\xFF', + z_hrt_cpy_cat_nochk(symbol, source, length - 1, symbol->option_2 == 2 ? CALCIUM[checksum] : '\xFF', source + length - 1, 1); - if (raw_text && rt_cpy_cat(symbol, source, length - 1, + if (raw_text && z_rt_cpy_cat(symbol, source, length - 1, add_checksum ? CALCIUM[checksum] : '\xFF', source + length - 1, 1)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; diff --git a/backend/codablock.c b/backend/codablock.c index bcc67f49..10bf7977 100644 --- a/backend/codablock.c +++ b/backend/codablock.c @@ -534,7 +534,7 @@ static void SumASCII(uchar **ppOutPos, const int Sum, const int CharacterSet) { /* Main function called by zint framework */ -INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_codablockf(struct zint_symbol *symbol, unsigned char source[], int length) { int charCur, dataLength; int error_number; int rows, columns, useColumns; @@ -560,35 +560,35 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int /* option1: rows <= 0: automatic, 1..44 */ rows = symbol->option_1; if (rows == 1) { - error_number = code128(symbol, source, length); + error_number = zint_code128(symbol, source, length); if (error_number < ZINT_ERROR) { symbol->output_options |= BARCODE_BIND; if (symbol->border_width == 0) { /* Allow override if non-zero */ symbol->border_width = 1; /* AIM ISS-X-24 Section 4.6.1 b) (note change from previous default 2) */ } - hrt_cpy_nochk(symbol, (const unsigned char *) "", 0); /* Zap HRT for compatibility with CODABLOCKF */ - /* Use `raw_text` from `code128()` */ + z_hrt_cpy_nochk(symbol, (const unsigned char *) "", 0); /* Zap HRT for compatibility with CODABLOCKF */ + /* Use `raw_text` from `zint_code128()` */ if (symbol->output_options & COMPLIANT_HEIGHT) { /* AIM ISS-X-24 Section 4.6.1 minimum row height 8X (for compatibility with CODABLOCKF, not specced for CODE128) */ if (error_number == 0) { - error_number = set_height(symbol, 8.0f, 10.0f, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 8.0f, 10.0f, 0.0f, 0 /*no_errtxt*/); } else { - (void) set_height(symbol, 8.0f, 10.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 8.0f, 10.0f, 0.0f, 1 /*no_errtxt*/); } } else { - (void) set_height(symbol, 0.0f, 5.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 5.0f, 0.0f, 1 /*no_errtxt*/); } } return error_number; } if (rows > 44) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 410, "Number of rows '%d' out of range (0 to 44)", rows); + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 410, "Number of rows '%d' out of range (0 to 44)", rows); } /* option_2: (usable data) columns: <= 0: automatic, 9..67 (min 9 == 4 data, max 67 == 62 data) */ columns = symbol->option_2; if (!(columns <= 0 || (columns >= 9 && columns <= 67))) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 411, "Number of columns '%d' out of range (9 to 67)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 411, "Number of columns '%d' out of range (9 to 67)", columns); } if (columns < 0) { /* Protect against negative overflow (ticket #300 (#9) Andre Maute) */ @@ -640,7 +640,7 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int error_number = Columns2Rows(T, dataLength, &rows, &useColumns, pSet, &fillings, debug); } if (error_number != 0) { - return errtxt(error_number, symbol, 413, + return z_errtxt(error_number, symbol, 413, "Input too long, requires too many symbol characters (maximum 2726)"); } /* Suppresses clang-analyzer-core.VLASize warning */ @@ -846,7 +846,7 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump(symbol, pOutput, rows * columns); + z_debug_test_codeword_dump(symbol, pOutput, rows * columns); } #endif @@ -857,23 +857,23 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int const int rc = r * columns; char *d = dest; for (c = 0; c < columns - 1; c++, d += 6) { - memcpy(d, C128Table[pOutput[rc + c]], 6); + memcpy(d, zint_C128Table[pOutput[rc + c]], 6); } - memcpy(d, "2331112", 7); /* Stop character (106, not in C128Table) */ + memcpy(d, "2331112", 7); /* Stop character (106, not in `zint_C128Table[]`) */ d += 7; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); } if (symbol->output_options & COMPLIANT_HEIGHT) { /* AIM ISS-X-24 Section 4.6.1 minimum row height; use 10 * rows as default */ - float min_row_height = stripf(0.55f * useColumns + 3.0f); + float min_row_height = z_stripf(0.55f * useColumns + 3.0f); if (min_row_height < 8.0f) { min_row_height = 8.0f; } - error_number = set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, + error_number = z_set_height(symbol, min_row_height, (min_row_height > 10.0f ? min_row_height : 10.0f) * rows, 0.0f, 0 /*no_errtxt*/); } else { - (void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/); } symbol->output_options |= BARCODE_BIND; @@ -882,8 +882,8 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int symbol->border_width = 1; /* AIM ISS-X-24 Section 4.6.1 b) (note change from previous default 2) */ } - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; diff --git a/backend/code.c b/backend/code.c index 4c046a5a..2e91ea64 100644 --- a/backend/code.c +++ b/backend/code.c @@ -119,7 +119,7 @@ static const char C93Table[47][6] = { }; /* Code 39 */ -INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_code39(struct zint_symbol *symbol, unsigned char source[], int length) { int i; int counter; int posns[86]; @@ -135,18 +135,18 @@ INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int leng /* LOGMARS MIL-STD-1189 Rev. B https://apps.dtic.mil/dtic/tr/fulltext/u2/a473534.pdf */ if ((symbol->symbology == BARCODE_LOGMARS) && (length > 30)) { /* MIL-STD-1189 Rev. B Section 5.2.6.2 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 322, "Input length %d too long (maximum 30)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 322, "Input length %d too long (maximum 30)", length); /* Prevent encoded_data out-of-bounds >= 143 for BARCODE_HIBC_39 due to wider 'wide' bars */ } else if ((symbol->symbology == BARCODE_HIBC_39) && (length > 70)) { /* 16 (Start) + 70*16 + 15 (Stop) = 1151 */ /* 70 less '+' and check */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 319, "Input length %d too long (maximum 68)", length - 2); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 319, "Input length %d too long (maximum 68)", length - 2); } else if (length > 86) { /* 13 (Start) + 86*13 + 12 (Stop) = 1143 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 323, "Input length %d too long (maximum 86)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 323, "Input length %d too long (maximum 86)", length); } - to_upper(source, length); - if ((i = not_sane_lookup(SILVER, 43 /* Up to "%" */, source, length, posns))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 324, + z_to_upper(source, length); + if ((i = z_not_sane_lookup(SILVER, 43 /* Up to "%" */, source, length, posns))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 324, "Invalid character at position %d in input (alphanumerics, space and \"-.$/+%%\" only)", i); } @@ -186,7 +186,7 @@ INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int leng printf("Barspaces: %.*s\n", (int) (d - dest), dest); } - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (symbol->output_options & COMPLIANT_HEIGHT) { if (symbol->symbology == BARCODE_LOGMARS) { @@ -195,20 +195,20 @@ INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int leng Default height 0.625" (average of 0.375" - 0.875") / 0.01375" (average of 0.0075" - 0.02") ~ 45.45 */ const float default_height = 45.4545441f; /* 0.625 / 0.01375 */ const float max_height = 116.666664f; /* 0.875 / 0.0075 */ - error_number = set_height(symbol, 6.25f, default_height, max_height, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 6.25f, default_height, max_height, 0 /*no_errtxt*/); } else if (symbol->symbology == BARCODE_CODE39 || symbol->symbology == BARCODE_EXCODE39 || symbol->symbology == BARCODE_HIBC_39) { /* ISO/IEC 16388:2007 4.4 (e) recommended min height 5.0mm or 15% of width excluding quiet zones; as X left to application specification use width = (C + 2) * (3 * N + 6) * X + (C + 1) * I = (C + 2) * 9 + C + 1) * X = (10 * C + 19); use 50 as default as none recommended */ - const float min_height = stripf((10.0f * (symbol->option_2 == 1 ? length + 1 : length) + 19.0f) * 0.15f); - error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f, + const float min_height = z_stripf((10.0f * (length + (symbol->option_2 == 1)) + 19.0f) * 0.15f); + error_number = z_set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f, 0 /*no_errtxt*/); } /* PZN and CODE32 set their own heights */ } else { - (void) set_height(symbol, 0.0f, 50.f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 50.f, 0.0f, 1 /*no_errtxt*/); } /* Display a space check digit as _, otherwise it looks like an error */ @@ -216,20 +216,20 @@ INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int leng check_digit = '_'; } if (symbol->symbology == BARCODE_CODE39) { - hrt_cpy_chr(symbol, '*'); - hrt_cat_nochk(symbol, source, length); + z_hrt_cpy_chr(symbol, '*'); + z_hrt_cat_nochk(symbol, source, length); if (symbol->option_2 == 1) { /* Visible check digit */ - hrt_cat_chr_nochk(symbol, check_digit); + z_hrt_cat_chr_nochk(symbol, check_digit); } - hrt_cat_chr_nochk(symbol, '*'); + z_hrt_cat_chr_nochk(symbol, '*'); } else { - hrt_cpy_cat_nochk(symbol, source, length, symbol->option_2 == 1 ? check_digit : '\xFF', NULL /*cat*/, 0); + z_hrt_cpy_cat_nochk(symbol, source, length, symbol->option_2 == 1 ? check_digit : '\xFF', NULL /*cat*/, 0); } if (raw_text) { - if (rt_cpy_cat(symbol, source, length, check_digit ? check_digit == '_' ? ' ' : check_digit : '\xFF', + if (z_rt_cpy_cat(symbol, source, length, check_digit ? check_digit == '_' ? ' ' : check_digit : '\xFF', NULL /*cat*/, 0)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } } @@ -237,7 +237,7 @@ INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int leng } /* Extended Code 39 - ISO/IEC 16388:2007 Annex A */ -INTERNAL int excode39(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_excode39(struct zint_symbol *symbol, unsigned char source[], int length) { int i; unsigned char buffer[86 * 2 + 1] = {0}; unsigned char *b = buffer; @@ -247,22 +247,22 @@ INTERNAL int excode39(struct zint_symbol *symbol, unsigned char source[], int le const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 86) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 328, "Input length %d too long (maximum 86)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 328, "Input length %d too long (maximum 86)", length); } /* Create a buffer string and place control characters into it */ for (i = 0; i < length; i++) { if (!z_isascii(source[i])) { /* Cannot encode extended ASCII */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 329, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 329, "Invalid character at position %d in input, extended ASCII not allowed", i + 1); } memcpy(b, EC39Ctrl[source[i]], 2); b += EC39Ctrl[source[i]][1] ? 2 : 1; } if (b - buffer > 86) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 317, "Input too long, requires %d symbol characters (maximum 86)", - (int) (b - buffer)); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 317, + "Input too long, requires %d symbol characters (maximum 86)", (int) (b - buffer)); } *b = '\0'; @@ -270,11 +270,11 @@ INTERNAL int excode39(struct zint_symbol *symbol, unsigned char source[], int le symbol->option_2 = 1; /* Make hidden check digit visible so returned in HRT */ } if (raw_text) { - symbol->output_options &= ~BARCODE_RAW_TEXT; /* Don't use `code39()`'s `raw_text` */ + symbol->output_options &= ~BARCODE_RAW_TEXT; /* Don't use `zint_code39()`'s `raw_text` */ } /* Then send the buffer to the C39 function */ - if ((error_number = code39(symbol, buffer, b - buffer)) >= ZINT_ERROR) { + if ((error_number = zint_code39(symbol, buffer, b - buffer)) >= ZINT_ERROR) { return error_number; } @@ -291,25 +291,25 @@ INTERNAL int excode39(struct zint_symbol *symbol, unsigned char source[], int le } /* Copy over source to HRT, subbing space for unprintables */ - (void) hrt_cpy_iso8859_1(symbol, source, length); /* Will fit (ASCII, length <= 86) */ + (void) z_hrt_cpy_iso8859_1(symbol, source, length); /* Will fit (ASCII, length <= 86) */ if (symbol->option_2 == 1) { - hrt_cat_chr_nochk(symbol, check_digit); + z_hrt_cat_chr_nochk(symbol, check_digit); } - if (raw_text && rt_cpy_cat(symbol, source, length, check_digit ? check_digit == '_' ? ' ' : check_digit : '\xFF', - NULL /*cat*/, 0)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, source, length, + check_digit ? check_digit == '_' ? ' ' : check_digit : '\xFF', NULL /*cat*/, 0)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; } /* Code 93 is an advancement on Code 39 and the definition is a lot tighter */ -INTERNAL int code93(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_code93(struct zint_symbol *symbol, unsigned char source[], int length) { /* SILVER includes the extra characters a, b, c and d to represent Code 93 specific shift characters 1, 2, 3 and 4 respectively. These characters are never used by - `code39()` and `excode39()` */ + `zint_code39()` and `excode39()` */ int i; int h, weight, c, k, error_number = 0; @@ -324,14 +324,14 @@ INTERNAL int code93(struct zint_symbol *symbol, unsigned char source[], int leng assert(length > 0); if (length > 123) { /* 9 (Start) + 123*9 + 2*9 (Checks) + 10 (Stop) = 1144 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 330, "Input length %d too long (maximum 123)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 330, "Input length %d too long (maximum 123)", length); } /* Message Content */ for (i = 0; i < length; i++) { if (!z_isascii(source[i])) { /* Cannot encode extended ASCII */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 331, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 331, "Invalid character at position %d in input, extended ASCII not allowed", i + 1); } memcpy(b, C93Ctrl[source[i]], 2); @@ -341,12 +341,12 @@ INTERNAL int code93(struct zint_symbol *symbol, unsigned char source[], int leng /* Now we can check the true length of the barcode */ h = b - buffer; if (h > 123) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 332, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 332, "Input too long, requires %d symbol characters (maximum 123)", h); } for (i = 0; i < h; i++) { - values[i] = posn(SILVER, buffer[i]); + values[i] = z_posn(SILVER, buffer[i]); } /* Putting the data into dest[] is not done until after check digits are calculated */ @@ -392,33 +392,34 @@ INTERNAL int code93(struct zint_symbol *symbol, unsigned char source[], int leng memcpy(d, "1111411", 7); d += 7; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (symbol->output_options & COMPLIANT_HEIGHT) { /* ANSI/AIM BC5-1995 Section 2.6 minimum height 0.2" or 15% of symbol length, whichever is greater no max X given so for min height use symbol length = (9 * (C + 4) + 1) * X + 2 * Q = symbol->width + 20; use 40 as default height based on figures in spec */ - const float min_height = stripf((symbol->width + 20) * 0.15f); - error_number = set_height(symbol, min_height, min_height > 40.0f ? min_height : 40.0f, 0.0f, 0 /*no_errtxt*/); + const float min_height = z_stripf((symbol->width + 20) * 0.15f); + error_number = z_set_height(symbol, min_height, min_height > 40.0f ? min_height : 40.0f, 0.0f, + 0 /*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*/); } - (void) hrt_cpy_iso8859_1(symbol, source, length); /* Will fit (ASCII, length <= 123) */ + (void) z_hrt_cpy_iso8859_1(symbol, source, length); /* Will fit (ASCII, length <= 123) */ if (symbol->option_2 == 1) { - hrt_cat_chr_nochk(symbol, SILVER[c]); - hrt_cat_chr_nochk(symbol, SILVER[k]); + z_hrt_cat_chr_nochk(symbol, SILVER[c]); + z_hrt_cat_chr_nochk(symbol, SILVER[k]); } - if (raw_text && rt_cpy_cat(symbol, source, length, SILVER[c], (const unsigned char *) SILVER + k, 1)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, source, length, SILVER[c], (const unsigned char *) SILVER + k, 1)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; } /* Vehicle Identification Number (VIN) */ -INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_vin(struct zint_symbol *symbol, unsigned char source[], int length) { /* This code verifies the check digit present in North American VIN codes */ @@ -433,16 +434,16 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length) /* Check length */ if (length != 17) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 336, "Input length %d wrong (17 characters required)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 336, "Input length %d wrong (17 characters required)", length); } /* Check input characters, I, O and Q are not allowed */ - if ((i = not_sane(ARSENIC_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 337, + if ((i = z_not_sane(ARSENIC_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 337, "Invalid character at position %d in input (alphanumerics only, excluding \"IOQ\")", i); } - to_upper(source, length); + z_to_upper(source, length); /* Check digit only valid for North America */ if (source[0] >= '1' && source[0] <= '5') { @@ -476,9 +477,9 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length) } if (input_check != output_check) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 338, - "Invalid check digit '%1$c' (position 9), expecting '%2$c'", input_check, - output_check); + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 338, + "Invalid check digit '%1$c' (position 9), expecting '%2$c'", input_check, + output_check); } } @@ -494,19 +495,19 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length) /* Copy glyphs to symbol */ for (i = 0; i < 17; i++, d += 10) { - memcpy(d, C39Table[posn(SILVER, source[i])], 10); + memcpy(d, C39Table[z_posn(SILVER, source[i])], 10); } /* Stop character */ memcpy(d, C39Table[43], 9); d += 9; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); - if (raw_text && rt_cpy_cat(symbol, NULL /*source*/, 0, symbol->option_2 == 1 ? 'I' : '\xFF', source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, NULL /*source*/, 0, symbol->option_2 == 1 ? 'I' : '\xFF', source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } /* Specification of dimensions/height for BARCODE_VIN unlikely */ diff --git a/backend/code1.c b/backend/code1.c index da28bee0..faa4143f 100644 --- a/backend/code1.c +++ b/backend/code1.c @@ -55,11 +55,11 @@ static void c1_horiz(struct zint_symbol *symbol, const int row_no, const int ful if (full) { for (i = 0; i < symbol->width; i++) { - set_module(symbol, row_no, i); + z_set_module(symbol, row_no, i); } } else { for (i = 1; i < symbol->width - 1; i++) { - set_module(symbol, row_no, i); + z_set_module(symbol, row_no, i); } } } @@ -75,35 +75,36 @@ static void c1_central_finder(struct zint_symbol *symbol, const int start_row, c } else { c1_horiz(symbol, start_row + (i * 2), 0); if (i != row_count - 1) { - set_module(symbol, start_row + (i * 2) + 1, 1); - set_module(symbol, start_row + (i * 2) + 1, symbol->width - 2); + z_set_module(symbol, start_row + (i * 2) + 1, 1); + z_set_module(symbol, start_row + (i * 2) + 1, symbol->width - 2); } } } } /* Add solid column */ -static void c1_vert(struct zint_symbol *symbol, const int column, const int height, const int top) { +static void c1_vert(struct zint_symbol *symbol, const int top_col, const int top_height, const int bot_col, + const int bot_height) { int i; - if (top) { - for (i = 0; i < height; i++) { - set_module(symbol, i, column); - } - } else { - for (i = 0; i < height; i++) { - set_module(symbol, symbol->rows - i - 1, column); - } + for (i = 0; i < top_height; i++) { + z_set_module(symbol, i, top_col); + } + for (i = 0; i < bot_height; i++) { + z_set_module(symbol, symbol->rows - i - 1, bot_col); } } /* Add bump to the right of the vertical recognition pattern column (Versions A-H) */ -static void c1_spigot(struct zint_symbol *symbol, const int row_no) { +static void c1_spigot(struct zint_symbol *symbol, const int row1, const int row2) { int i; for (i = symbol->width - 1; i > 0; i--) { - if (module_is_set(symbol, row_no, i - 1)) { - set_module(symbol, row_no, i); + if (z_module_is_set(symbol, row1, i - 1)) { + z_set_module(symbol, row1, i); + } + if (z_module_is_set(symbol, row2, i - 1)) { + z_set_module(symbol, row2, i); } } } @@ -323,7 +324,7 @@ static int c1_is_last_single_ascii(const unsigned char source[], const int lengt if (length - sp == 1 && source[sp] <= 127) { return 1; } - if (length - sp == 2 && is_twodigits(source, length, sp)) { + if (length - sp == 2 && z_is_twodigits(source, length, sp)) { return 1; } return 0; @@ -397,25 +398,25 @@ static int c1_decimal_unlatch(char decimal_binary[24], int db_p, unsigned int ta int sp = *p_sp; int bits_left; - db_p = bin_append_posn(63, 6, decimal_binary, db_p); /* Unlatch */ + db_p = z_bin_append_posn(63, 6, decimal_binary, db_p); /* Unlatch */ if (db_p >= 8) { db_p = c1_decimal_binary_transfer(decimal_binary, db_p, target, p_tp); } bits_left = (8 - db_p) & 0x07; if (decimal_count >= 1 && bits_left >= 4) { - db_p = bin_append_posn(ctoi(source[sp]) + 1, 4, decimal_binary, db_p); + db_p = z_bin_append_posn(z_ctoi(source[sp]) + 1, 4, decimal_binary, db_p); sp++; if (bits_left == 6) { - db_p = bin_append_posn(1, 2, decimal_binary, db_p); + db_p = z_bin_append_posn(1, 2, decimal_binary, db_p); } (void) c1_decimal_binary_transfer(decimal_binary, db_p, target, p_tp); } else if (bits_left) { if (bits_left >= 4) { - db_p = bin_append_posn(15, 4, decimal_binary, db_p); + db_p = z_bin_append_posn(15, 4, decimal_binary, db_p); } if (bits_left == 2 || bits_left == 6) { - db_p = bin_append_posn(1, 2, decimal_binary, db_p); + db_p = z_bin_append_posn(1, 2, decimal_binary, db_p); } (void) c1_decimal_binary_transfer(decimal_binary, db_p, target, p_tp); } @@ -494,7 +495,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len int db_p = 0; int byte_start = 0; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; - const int eci_length = length + 7 + chr_cnt(source, length, '\\'); + const int eci_length = length + 7 + z_chr_cnt(source, length, '\\'); unsigned char *eci_buf = (unsigned char *) z_alloca(eci_length + 1); int *num_digits = (int *) z_alloca(sizeof(int) * (eci_length + 1)); @@ -601,20 +602,20 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len /* Step B - ASCII encodation */ next_mode = C1_ASCII; - if ((length - sp) >= 21 && num_digits[sp] >= 21) { + if (length - sp >= 21 && num_digits[sp] >= 21) { /* Step B1 */ next_mode = C1_DECIMAL; - db_p = bin_append_posn(15, 4, decimal_binary, db_p); - } else if ((length - sp) >= 13 && num_digits[sp] == (length - sp)) { + db_p = z_bin_append_posn(15, 4, decimal_binary, db_p); + } else if (length - sp >= 13 && num_digits[sp] == length - sp) { /* Step B2 */ next_mode = C1_DECIMAL; - db_p = bin_append_posn(15, 4, decimal_binary, db_p); + db_p = z_bin_append_posn(15, 4, decimal_binary, db_p); } if (next_mode == C1_ASCII) { - if (is_twodigits(source, length, sp)) { + if (z_is_twodigits(source, length, sp)) { /* Step B3 */ - target[tp++] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130; + target[tp++] = z_to_int(source + sp, 2) + 130; if (debug_print) printf("ASCDD(%.2s) ", source + sp); sp += 2; } else { @@ -671,10 +672,10 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len next_mode = current_mode; if (cte_p == 0) { /* Step C/D1 */ - if ((length - sp) >= 12 && num_digits[sp] >= 12) { + if (length - sp >= 12 && num_digits[sp] >= 12) { /* Step C/D1a */ next_mode = C1_ASCII; - } else if ((length - sp) >= 8 && num_digits[sp] == (length - sp)) { + } else if (length - sp >= 8 && num_digits[sp] == length - sp) { /* Step C/D1b */ next_mode = C1_ASCII; } else { @@ -728,13 +729,13 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len next_mode = C1_EDI; if (cte_p == 0) { /* Step E1 */ - if ((length - sp) >= 12 && num_digits[sp] >= 12) { + if (length - sp >= 12 && num_digits[sp] >= 12) { /* Step E1a */ next_mode = C1_ASCII; - } else if ((length - sp) >= 8 && num_digits[sp] == (length - sp)) { + } else if (length - sp >= 8 && num_digits[sp] == length - sp) { /* Step E1b */ next_mode = C1_ASCII; - } else if ((length - sp) < 3 || !c1_isedi(source[sp]) || !c1_isedi(source[sp + 1]) + } else if (length - sp < 3 || !c1_isedi(source[sp]) || !c1_isedi(source[sp + 1]) || !c1_isedi(source[sp + 2])) { /* Step E1c */ /* This ensures ASCII switch if don't have EDI triplet, so cte_p will be zero on loop exit */ @@ -760,7 +761,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len } else if (z_isupper(source[sp])) { cte_buffer[cte_p++] = source[sp] - 'A' + 14; } else { - cte_buffer[cte_p++] = posn(edi_nonalphanum_chars, source[sp]); + cte_buffer[cte_p++] = z_posn(edi_nonalphanum_chars, source[sp]); } if (cte_p >= 3) { @@ -784,8 +785,8 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len && (can_ascii || (num_digits[sp] == 1 && bits_left >= 4))) { if (can_ascii) { /* Encode last character or last 2 digits as ASCII */ - if (is_twodigits(source, length, sp)) { - target[tp++] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130; + if (z_is_twodigits(source, length, sp)) { + target[tp++] = z_to_int(source + sp, 2) + 130; if (debug_print) printf("ASCDD(%.2s) ", source + sp); sp += 2; } else { @@ -795,10 +796,10 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len } } else { /* Encode last digit in 4 bits */ - db_p = bin_append_posn(ctoi(source[sp]) + 1, 4, decimal_binary, db_p); + db_p = z_bin_append_posn(z_ctoi(source[sp]) + 1, 4, decimal_binary, db_p); sp++; if (bits_left == 6) { - db_p = bin_append_posn(1, 2, decimal_binary, db_p); + db_p = z_bin_append_posn(1, 2, decimal_binary, db_p); } db_p = c1_decimal_binary_transfer(decimal_binary, db_p, target, &tp); } @@ -816,8 +817,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len } else { /* Step F3 */ /* There are three digits - convert the value to binary */ - int value = (100 * ctoi(source[sp])) + (10 * ctoi(source[sp + 1])) + ctoi(source[sp + 2]) + 1; - db_p = bin_append_posn(value, 10, decimal_binary, db_p); + db_p = z_bin_append_posn(z_to_int(source + sp, 3) + 1, 10, decimal_binary, db_p); if (db_p >= 8) { db_p = c1_decimal_binary_transfer(decimal_binary, db_p, target, &tp); } @@ -897,8 +897,8 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len target[tp++] = 255; /* Unlatch */ for (; sp < length; sp++) { - if (is_twodigits(source, length, sp)) { - target[tp++] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130; + if (z_is_twodigits(source, length, sp)) { + target[tp++] = z_to_int(source + sp, 2) + 130; sp++; } else if (source[sp] & 0x80) { target[tp++] = 235; /* FNC4 (Upper Shift) */ @@ -918,7 +918,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len /* Finish Decimal mode and go back to ASCII unless only one codeword remaining */ if (c1_codewords_remaining(symbol, tp) > 1) { - db_p = bin_append_posn(63, 6, decimal_binary, db_p); /* Unlatch */ + db_p = z_bin_append_posn(63, 6, decimal_binary, db_p); /* Unlatch */ } if (db_p >= 8) { @@ -929,12 +929,12 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len if (bits_left) { - if ((bits_left == 4) || (bits_left == 6)) { - db_p = bin_append_posn(15, 4, decimal_binary, db_p); + if (bits_left == 4 || bits_left == 6) { + db_p = z_bin_append_posn(15, 4, decimal_binary, db_p); } if (bits_left == 2 || bits_left == 6) { - db_p = bin_append_posn(1, 2, decimal_binary, db_p); + db_p = z_bin_append_posn(1, 2, decimal_binary, db_p); } (void) c1_decimal_binary_transfer(decimal_binary, db_p, target, &tp); @@ -984,14 +984,14 @@ static int c1_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co /* GS1 raw text dealt with by `ZBarcode_Encode_Segs()` */ const int raw_text = !gs1 && (symbol->output_options & BARCODE_RAW_TEXT); - 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++) { tp = c1_encode(symbol, segs[i].source, segs[i].length, segs[i].eci, seg_count, gs1, target, &tp, p_last_mode); - if (raw_text && rt_cpy_seg(symbol, i, &segs[i])) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg(symbol, i, &segs[i])) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg()` only fails with OOM */ } } @@ -1008,7 +1008,7 @@ static void c1_block_copy(struct zint_symbol *symbol, char datagrid[136][120], c for (i = start_row; i < (start_row + height); i++) { for (j = start_col; j < (start_col + width); j++) { if (datagrid[i][j]) { - set_module(symbol, i + row_offset, j + col_offset); + z_set_module(symbol, i + row_offset, j + col_offset); } } } @@ -1021,7 +1021,7 @@ static int c1_total_length_segs(struct zint_seg segs[], const int seg_count) { if (segs[0].eci || seg_count > 1) { for (i = 0; i < seg_count; i++) { - total_len += segs[i].length + 7 + chr_cnt(segs[i].source, segs[i].length, '\\'); + total_len += segs[i].length + 7 + z_chr_cnt(segs[i].source, segs[i].length, '\\'); } } else { total_len = segs[0].length; @@ -1030,7 +1030,7 @@ static int c1_total_length_segs(struct zint_seg segs[], const int seg_count) { return total_len; } -INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_codeone(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int size = 1, i, j; char datagrid[136][120]; int row, col; @@ -1039,30 +1039,31 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i 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)) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 513, "Version '%d' out of range (1 to 10)", - symbol->option_2); + if (symbol->option_2 < 0 || symbol->option_2 > 10) { + return z_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 */ - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 714, "Structured Append not available for Version S"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 714, "Structured Append not available for Version S"); } if (gs1) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 710, + return z_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) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 711, + return z_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) { - return ZEXT 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); + return ZEXT z_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]) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 713, "Structured Append ID not available for Code One"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 713, + "Structured Append ID not available for Code One"); } } @@ -1075,14 +1076,14 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; /* GS1 mode ignored for Version S */ if (seg_count > 1) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 715, "Multiple segments not supported for Version S"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 715, "Multiple segments not supported for Version S"); } if (segs[0].length > 18) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 514, "Input length %d too long for Version S (maximum 18)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 514, "Input length %d too long for Version S (maximum 18)", segs[0].length); } - if ((i = not_sane(NEON_F, segs[0].source, segs[0].length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 515, + if ((i = z_not_sane(NEON_F, segs[0].source, segs[0].length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 515, "Invalid character at position %d in input (Version S encodes digits only)", i); } @@ -1108,18 +1109,18 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i printf("Subversion: %d\n", sub_version); } - if (raw_text && rt_cpy(symbol, segs[0].source, segs[0].length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, segs[0].source, segs[0].length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } /* Convert value plus one to binary */ - large_load_str_u64(&elreg, segs[0].source, segs[0].length); - large_add_u64(&elreg, 1); - large_uint_array(&elreg, target, codewords, 5 /*bits*/); + zint_large_load_str_u64(&elreg, segs[0].source, segs[0].length); + zint_large_add_u64(&elreg, 1); + zint_large_uint_array(&elreg, target, codewords, 5 /*bits*/); - rs_init_gf(&rs, 0x25); - rs_init_code(&rs, codewords, 0); - rs_encode_uint(&rs, codewords, target, ecc); + zint_rs_init_gf(&rs, 0x25); + zint_rs_init_code(&rs, codewords, 0); + zint_rs_encode_uint(&rs, codewords, target, ecc); for (i = 0; i < codewords; i++) { target[i + codewords] = ecc[i]; @@ -1160,7 +1161,7 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i int last_mode = 0; /* Suppress gcc 14 "-Wmaybe-uninitialized" false positive */ 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)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 519, "Input length %d too long for Version T (maximum 90)", i); } @@ -1170,7 +1171,7 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i assert(data_length); /* Can't exceed C1_MAX_CWS as input <= 90 */ if (data_length > 38) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 516, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 516, "Input too long for Version T, requires %d codewords (maximum 38)", data_length); } @@ -1208,9 +1209,9 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i } /* Calculate error correction data */ - rs_init_gf(&rs, 0x12d); - rs_init_code(&rs, ecc_cw, 0); - rs_encode_uint(&rs, data_cw, target, ecc); + zint_rs_init_gf(&rs, 0x12d); + zint_rs_init_code(&rs, ecc_cw, 0); + zint_rs_encode_uint(&rs, data_cw, target, ecc); for (i = 0; i < ecc_cw; i++) { target[data_cw + i] = ecc[i]; @@ -1254,7 +1255,7 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i } if (data_length == 0) { - return errtxt(ZINT_ERROR_TOO_LONG, symbol, 517, + return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 517, "Input too long, requires too many codewords (maximum " C1_MAX_CWS_S ")"); } @@ -1268,10 +1269,10 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i size = symbol->option_2; } - if ((symbol->option_2 != 0) && (symbol->option_2 < size)) { - return ZEXT 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]); + if (symbol->option_2 && symbol->option_2 < size) { + return ZEXT z_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]); } /* Feedback options */ @@ -1301,13 +1302,13 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i ecc_blocks = c1_ecc_blocks[size - 1]; ecc_length = c1_ecc_length[size - 1]; - rs_init_gf(&rs, 0x12d); - rs_init_code(&rs, ecc_blocks, 0); + zint_rs_init_gf(&rs, 0x12d); + zint_rs_init_code(&rs, ecc_blocks, 0); for (i = 0; i < blocks; i++) { for (j = 0; j < data_blocks; j++) { sub_data[j] = target[j * blocks + i]; } - rs_encode_uint(&rs, data_blocks, sub_data, sub_ecc); + zint_rs_encode_uint(&rs, data_blocks, sub_data, sub_ecc); for (j = 0; j < ecc_blocks; j++) { target[data_cw + j * blocks + i] = sub_ecc[j]; } @@ -1345,11 +1346,9 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i switch (size) { case 1: /* Version A */ c1_central_finder(symbol, 6, 3, 1); - c1_vert(symbol, 4, 6, 1); - c1_vert(symbol, 12, 5, 0); - set_module(symbol, 5, 12); - c1_spigot(symbol, 0); - c1_spigot(symbol, 15); + c1_vert(symbol, 4, 6, 12, 5); + z_set_module(symbol, 5, 12); + c1_spigot(symbol, 0, 15); c1_block_copy(symbol, datagrid, 0, 0, 5, 4, 0, 0); c1_block_copy(symbol, datagrid, 0, 4, 5, 12, 0, 2); c1_block_copy(symbol, datagrid, 5, 0, 5, 12, 6, 0); @@ -1357,11 +1356,9 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i break; case 2: /* Version B */ c1_central_finder(symbol, 8, 4, 1); - c1_vert(symbol, 4, 8, 1); - c1_vert(symbol, 16, 7, 0); - set_module(symbol, 7, 16); - c1_spigot(symbol, 0); - c1_spigot(symbol, 21); + c1_vert(symbol, 4, 8, 16, 7); + z_set_module(symbol, 7, 16); + c1_spigot(symbol, 0, 21); c1_block_copy(symbol, datagrid, 0, 0, 7, 4, 0, 0); c1_block_copy(symbol, datagrid, 0, 4, 7, 16, 0, 2); c1_block_copy(symbol, datagrid, 7, 0, 7, 16, 8, 0); @@ -1369,12 +1366,9 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i break; case 3: /* Version C */ c1_central_finder(symbol, 11, 4, 2); - c1_vert(symbol, 4, 11, 1); - c1_vert(symbol, 26, 13, 1); - c1_vert(symbol, 4, 10, 0); - c1_vert(symbol, 26, 10, 0); - c1_spigot(symbol, 0); - c1_spigot(symbol, 27); + c1_vert(symbol, 4, 11, 4, 10); + c1_vert(symbol, 26, 13, 26, 10); + c1_spigot(symbol, 0, 27); c1_block_copy(symbol, datagrid, 0, 0, 10, 4, 0, 0); c1_block_copy(symbol, datagrid, 0, 4, 10, 20, 0, 2); c1_block_copy(symbol, datagrid, 0, 24, 10, 4, 0, 4); @@ -1384,16 +1378,11 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i break; case 4: /* Version D */ c1_central_finder(symbol, 16, 5, 1); - c1_vert(symbol, 4, 16, 1); - c1_vert(symbol, 20, 16, 1); - c1_vert(symbol, 36, 16, 1); - c1_vert(symbol, 4, 15, 0); - c1_vert(symbol, 20, 15, 0); - c1_vert(symbol, 36, 15, 0); - c1_spigot(symbol, 0); - c1_spigot(symbol, 12); - c1_spigot(symbol, 27); - c1_spigot(symbol, 39); + c1_vert(symbol, 4, 16, 4, 15); + c1_vert(symbol, 20, 16, 20, 15); + c1_vert(symbol, 36, 16, 36, 15); + c1_spigot(symbol, 0, 27); + c1_spigot(symbol, 12, 39); c1_block_copy(symbol, datagrid, 0, 0, 15, 4, 0, 0); c1_block_copy(symbol, datagrid, 0, 4, 15, 14, 0, 2); c1_block_copy(symbol, datagrid, 0, 18, 15, 14, 0, 4); @@ -1405,16 +1394,11 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i break; case 5: /* Version E */ c1_central_finder(symbol, 22, 5, 2); - c1_vert(symbol, 4, 22, 1); - c1_vert(symbol, 26, 24, 1); - c1_vert(symbol, 48, 22, 1); - c1_vert(symbol, 4, 21, 0); - c1_vert(symbol, 26, 21, 0); - c1_vert(symbol, 48, 21, 0); - c1_spigot(symbol, 0); - c1_spigot(symbol, 12); - c1_spigot(symbol, 39); - c1_spigot(symbol, 51); + c1_vert(symbol, 4, 22, 4, 21); + c1_vert(symbol, 26, 24, 26, 21); + c1_vert(symbol, 48, 22, 48, 21); + c1_spigot(symbol, 0, 39); + c1_spigot(symbol, 12, 51); c1_block_copy(symbol, datagrid, 0, 0, 21, 4, 0, 0); c1_block_copy(symbol, datagrid, 0, 4, 21, 20, 0, 2); c1_block_copy(symbol, datagrid, 0, 24, 21, 20, 0, 4); @@ -1426,132 +1410,85 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i break; case 6: /* Version F */ c1_central_finder(symbol, 31, 5, 3); - c1_vert(symbol, 4, 31, 1); - c1_vert(symbol, 26, 35, 1); - c1_vert(symbol, 48, 31, 1); - c1_vert(symbol, 70, 35, 1); - c1_vert(symbol, 4, 30, 0); - c1_vert(symbol, 26, 30, 0); - c1_vert(symbol, 48, 30, 0); - c1_vert(symbol, 70, 30, 0); - c1_spigot(symbol, 0); - c1_spigot(symbol, 12); - c1_spigot(symbol, 24); - c1_spigot(symbol, 45); - c1_spigot(symbol, 57); - c1_spigot(symbol, 69); + c1_vert(symbol, 4, 31, 4, 30); + c1_vert(symbol, 26, 35, 26, 30); + c1_vert(symbol, 48, 31, 48, 30); + c1_vert(symbol, 70, 35, 70, 30); + for (i = 0; i <= 24; i += 12) { + c1_spigot(symbol, i, i + 45); + } c1_block_copy(symbol, datagrid, 0, 0, 30, 4, 0, 0); - c1_block_copy(symbol, datagrid, 0, 4, 30, 20, 0, 2); - c1_block_copy(symbol, datagrid, 0, 24, 30, 20, 0, 4); - c1_block_copy(symbol, datagrid, 0, 44, 30, 20, 0, 6); c1_block_copy(symbol, datagrid, 0, 64, 30, 4, 0, 8); c1_block_copy(symbol, datagrid, 30, 0, 30, 4, 10, 0); - c1_block_copy(symbol, datagrid, 30, 4, 30, 20, 10, 2); - c1_block_copy(symbol, datagrid, 30, 24, 30, 20, 10, 4); - c1_block_copy(symbol, datagrid, 30, 44, 30, 20, 10, 6); c1_block_copy(symbol, datagrid, 30, 64, 30, 4, 10, 8); + for (i = 4, j = 2; i <= 44; i += 20, j += 2) { + c1_block_copy(symbol, datagrid, 0, i, 30, 20, 0, j); + c1_block_copy(symbol, datagrid, 30, i, 30, 20, 10, j); + } break; case 7: /* Version G */ c1_central_finder(symbol, 47, 6, 2); - c1_vert(symbol, 6, 47, 1); - c1_vert(symbol, 27, 49, 1); - c1_vert(symbol, 48, 47, 1); - c1_vert(symbol, 69, 49, 1); - c1_vert(symbol, 90, 47, 1); - c1_vert(symbol, 6, 46, 0); - c1_vert(symbol, 27, 46, 0); - c1_vert(symbol, 48, 46, 0); - c1_vert(symbol, 69, 46, 0); - c1_vert(symbol, 90, 46, 0); - c1_spigot(symbol, 0); - c1_spigot(symbol, 12); - c1_spigot(symbol, 24); - c1_spigot(symbol, 36); - c1_spigot(symbol, 67); - c1_spigot(symbol, 79); - c1_spigot(symbol, 91); - c1_spigot(symbol, 103); + c1_vert(symbol, 6, 47, 6, 46); + c1_vert(symbol, 27, 49, 27, 46); + c1_vert(symbol, 48, 47, 48, 46); + c1_vert(symbol, 69, 49, 69, 46); + c1_vert(symbol, 90, 47, 90, 46); + for (i = 0; i <= 36; i += 12) { + c1_spigot(symbol, i, i + 67); + } c1_block_copy(symbol, datagrid, 0, 0, 46, 6, 0, 0); - c1_block_copy(symbol, datagrid, 0, 6, 46, 19, 0, 2); - c1_block_copy(symbol, datagrid, 0, 25, 46, 19, 0, 4); - c1_block_copy(symbol, datagrid, 0, 44, 46, 19, 0, 6); - c1_block_copy(symbol, datagrid, 0, 63, 46, 19, 0, 8); c1_block_copy(symbol, datagrid, 0, 82, 46, 6, 0, 10); c1_block_copy(symbol, datagrid, 46, 0, 46, 6, 12, 0); - c1_block_copy(symbol, datagrid, 46, 6, 46, 19, 12, 2); - c1_block_copy(symbol, datagrid, 46, 25, 46, 19, 12, 4); - c1_block_copy(symbol, datagrid, 46, 44, 46, 19, 12, 6); - c1_block_copy(symbol, datagrid, 46, 63, 46, 19, 12, 8); c1_block_copy(symbol, datagrid, 46, 82, 46, 6, 12, 10); + for (i = 6, j = 2; i <= 63; i += 19, j += 2) { + c1_block_copy(symbol, datagrid, 0, i, 46, 19, 0, j); + c1_block_copy(symbol, datagrid, 46, i, 46, 19, 12, j); + } break; case 8: /* Version H */ c1_central_finder(symbol, 69, 6, 3); - c1_vert(symbol, 6, 69, 1); - c1_vert(symbol, 26, 73, 1); - c1_vert(symbol, 46, 69, 1); - c1_vert(symbol, 66, 73, 1); - c1_vert(symbol, 86, 69, 1); - c1_vert(symbol, 106, 73, 1); - c1_vert(symbol, 126, 69, 1); - c1_vert(symbol, 6, 68, 0); - c1_vert(symbol, 26, 68, 0); - c1_vert(symbol, 46, 68, 0); - c1_vert(symbol, 66, 68, 0); - c1_vert(symbol, 86, 68, 0); - c1_vert(symbol, 106, 68, 0); - c1_vert(symbol, 126, 68, 0); - c1_spigot(symbol, 0); - c1_spigot(symbol, 12); - c1_spigot(symbol, 24); - c1_spigot(symbol, 36); - c1_spigot(symbol, 48); - c1_spigot(symbol, 60); - c1_spigot(symbol, 87); - c1_spigot(symbol, 99); - c1_spigot(symbol, 111); - c1_spigot(symbol, 123); - c1_spigot(symbol, 135); - c1_spigot(symbol, 147); + c1_vert(symbol, 6, 69, 6, 68); + c1_vert(symbol, 26, 73, 26, 68); + c1_vert(symbol, 46, 69, 46, 68); + c1_vert(symbol, 66, 73, 66, 68); + c1_vert(symbol, 86, 69, 86, 68); + c1_vert(symbol, 106, 73, 106, 68); + c1_vert(symbol, 126, 69, 126, 68); + for (i = 0; i <= 60; i += 12) { + c1_spigot(symbol, i, i + 87); + } c1_block_copy(symbol, datagrid, 0, 0, 68, 6, 0, 0); - c1_block_copy(symbol, datagrid, 0, 6, 68, 18, 0, 2); - c1_block_copy(symbol, datagrid, 0, 24, 68, 18, 0, 4); - c1_block_copy(symbol, datagrid, 0, 42, 68, 18, 0, 6); - c1_block_copy(symbol, datagrid, 0, 60, 68, 18, 0, 8); - c1_block_copy(symbol, datagrid, 0, 78, 68, 18, 0, 10); - c1_block_copy(symbol, datagrid, 0, 96, 68, 18, 0, 12); c1_block_copy(symbol, datagrid, 0, 114, 68, 6, 0, 14); c1_block_copy(symbol, datagrid, 68, 0, 68, 6, 12, 0); - c1_block_copy(symbol, datagrid, 68, 6, 68, 18, 12, 2); - c1_block_copy(symbol, datagrid, 68, 24, 68, 18, 12, 4); - c1_block_copy(symbol, datagrid, 68, 42, 68, 18, 12, 6); - c1_block_copy(symbol, datagrid, 68, 60, 68, 18, 12, 8); - c1_block_copy(symbol, datagrid, 68, 78, 68, 18, 12, 10); - c1_block_copy(symbol, datagrid, 68, 96, 68, 18, 12, 12); c1_block_copy(symbol, datagrid, 68, 114, 68, 6, 12, 14); + for (i = 6, j = 2; i <= 96; i += 18, j += 2) { + c1_block_copy(symbol, datagrid, 0, i, 68, 18, 0, j); + c1_block_copy(symbol, datagrid, 68, i, 68, 18, 12, j); + } break; case 9: /* Version S */ c1_horiz(symbol, 5, 1); c1_horiz(symbol, 7, 1); - set_module(symbol, 6, 0); - set_module(symbol, 6, symbol->width - 1); - unset_module(symbol, 7, 1); - unset_module(symbol, 7, symbol->width - 2); + z_set_module(symbol, 6, 0); + z_set_module(symbol, 6, symbol->width - 1); + z_unset_module(symbol, 7, 1); + z_unset_module(symbol, 7, symbol->width - 2); switch (sub_version) { case 1: /* Version S-10 */ - set_module(symbol, 0, 5); + z_set_module(symbol, 0, 5); c1_block_copy(symbol, datagrid, 0, 0, 4, 5, 0, 0); c1_block_copy(symbol, datagrid, 0, 5, 4, 5, 0, 1); break; case 2: /* Version S-20 */ - set_module(symbol, 0, 10); - set_module(symbol, 4, 10); + z_set_module(symbol, 0, 10); + z_set_module(symbol, 4, 10); c1_block_copy(symbol, datagrid, 0, 0, 4, 10, 0, 0); c1_block_copy(symbol, datagrid, 0, 10, 4, 10, 0, 1); break; case 3: /* Version S-30 */ - set_module(symbol, 0, 15); - set_module(symbol, 4, 15); - set_module(symbol, 6, 15); + z_set_module(symbol, 0, 15); + z_set_module(symbol, 4, 15); + z_set_module(symbol, 6, 15); c1_block_copy(symbol, datagrid, 0, 0, 4, 15, 0, 0); c1_block_copy(symbol, datagrid, 0, 15, 4, 15, 0, 1); break; @@ -1561,33 +1498,33 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i c1_horiz(symbol, 11, 1); c1_horiz(symbol, 13, 1); c1_horiz(symbol, 15, 1); - set_module(symbol, 12, 0); - set_module(symbol, 12, symbol->width - 1); - set_module(symbol, 14, 0); - set_module(symbol, 14, symbol->width - 1); - unset_module(symbol, 13, 1); - unset_module(symbol, 13, symbol->width - 2); - unset_module(symbol, 15, 1); - unset_module(symbol, 15, symbol->width - 2); + z_set_module(symbol, 12, 0); + z_set_module(symbol, 12, symbol->width - 1); + z_set_module(symbol, 14, 0); + z_set_module(symbol, 14, symbol->width - 1); + z_unset_module(symbol, 13, 1); + z_unset_module(symbol, 13, symbol->width - 2); + z_unset_module(symbol, 15, 1); + z_unset_module(symbol, 15, symbol->width - 2); switch (sub_version) { case 1: /* Version T-16 */ - set_module(symbol, 0, 8); - set_module(symbol, 10, 8); + z_set_module(symbol, 0, 8); + z_set_module(symbol, 10, 8); c1_block_copy(symbol, datagrid, 0, 0, 10, 8, 0, 0); c1_block_copy(symbol, datagrid, 0, 8, 10, 8, 0, 1); break; case 2: /* Version T-32 */ - set_module(symbol, 0, 16); - set_module(symbol, 10, 16); - set_module(symbol, 12, 16); + z_set_module(symbol, 0, 16); + z_set_module(symbol, 10, 16); + z_set_module(symbol, 12, 16); c1_block_copy(symbol, datagrid, 0, 0, 10, 16, 0, 0); c1_block_copy(symbol, datagrid, 0, 16, 10, 16, 0, 1); break; case 3: /* Verion T-48 */ - set_module(symbol, 0, 24); - set_module(symbol, 10, 24); - set_module(symbol, 12, 24); - set_module(symbol, 14, 24); + z_set_module(symbol, 0, 24); + z_set_module(symbol, 10, 24); + z_set_module(symbol, 12, 24); + z_set_module(symbol, 14, 24); c1_block_copy(symbol, datagrid, 0, 0, 10, 24, 0, 0); c1_block_copy(symbol, datagrid, 0, 24, 10, 24, 0, 1); break; @@ -1602,11 +1539,11 @@ INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const i if (symbol->option_2 == 9) { /* Version S */ if (symbol->eci || gs1) { - 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"); + return z_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) { - return errtxt(ZINT_WARN_INVALID_OPTION, symbol, 512, "ECI ignored for GS1 mode"); + return z_errtxt(ZINT_WARN_INVALID_OPTION, symbol, 512, "ECI ignored for GS1 mode"); } return 0; diff --git a/backend/code11.c b/backend/code11.c index e36b3625..87702295 100644 --- a/backend/code11.c +++ b/backend/code11.c @@ -46,7 +46,7 @@ static const char C11Table[11 + 1][6] = { }; /* Code 11 */ -INTERNAL int code11(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_code11(struct zint_symbol *symbol, unsigned char source[], int length) { static const unsigned char checkchrs[11] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-' }; int i; int h; @@ -62,15 +62,15 @@ INTERNAL int code11(struct zint_symbol *symbol, unsigned char source[], int leng assert(length > 0); if (length > 140) { /* 8 (Start) + 140 * 8 + 2 * 8 (Check) + 7 (Stop) = 1151 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 320, "Input length %d too long (maximum 140)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 320, "Input length %d too long (maximum 140)", length); } - if ((i = not_sane(SODIUM_MNS_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 321, + if ((i = z_not_sane(SODIUM_MNS_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 321, "Invalid character at position %d in input (digits and \"-\" only)", i); } if (symbol->option_2 < 0 || symbol->option_2 > 2) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 339, "Invalid check digit version '%d' (1 or 2 only)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 339, "Invalid check digit version '%d' (1 or 2 only)", symbol->option_2); } if (symbol->option_2 == 2) { @@ -91,7 +91,7 @@ INTERNAL int code11(struct zint_symbol *symbol, unsigned char source[], int leng if (source[i] == '-') weight[i] = 10; else - weight[i] = ctoi(source[i]); + weight[i] = z_ctoi(source[i]); memcpy(d, C11Table[weight[i]], 6); } @@ -142,17 +142,17 @@ INTERNAL int code11(struct zint_symbol *symbol, unsigned char source[], int leng memcpy(d, C11Table[11], 5); d += 5; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); /* TODO: Find documentation on BARCODE_CODE11 dimensions/height */ - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); if (num_check_digits) { - hrt_cat_nochk(symbol, checkstr, num_check_digits); + z_hrt_cat_nochk(symbol, checkstr, num_check_digits); } - if (raw_text && rt_cpy_cat(symbol, source, length, '\xFF' /*separator (none)*/, checkstr, num_check_digits)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, source, length, '\xFF' /*separator (none)*/, checkstr, num_check_digits)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; diff --git a/backend/code128.c b/backend/code128.c index 8150765a..a5024985 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -45,7 +45,7 @@ /* Code 128 tables checked against ISO/IEC 15417:2007 */ /* Code 128 character encodation - Table 1 (with final CODE16K-only character in place of Stop character) */ -INTERNAL_DATA const char C128Table[107][6] = { /* Used by CODABLOCKF and CODE16K also */ +INTERNAL_DATA const char zint_C128Table[107][6] = { /* Used by CODABLOCKF and CODE16K also */ {'2','1','2','2','2','2'}, {'2','2','2','1','2','2'}, {'2','2','2','2','2','1'}, {'1','2','1','2','2','3'}, {'1','2','1','3','2','2'}, {'1','3','1','2','2','2'}, {'1','2','2','2','1','3'}, {'1','2','2','3','1','2'}, {'1','3','2','2','1','2'}, {'2','2','1','2','1','3'}, {'2','2','1','3','1','2'}, {'2','3','1','2','1','2'}, @@ -303,16 +303,16 @@ static void c128_expand(struct zint_symbol *symbol, int values[C128_VALUES_MAX], int i; /* Destination setting and check digit calculation */ - memcpy(d, C128Table[values[0]], 6); + memcpy(d, zint_C128Table[values[0]], 6); d += 6; total_sum = values[0]; for (i = 1; i < glyph_count; i++, d += 6) { - memcpy(d, C128Table[values[i]], 6); + memcpy(d, zint_C128Table[values[i]], 6); total_sum += values[i] * i; /* Note can't overflow as 106 * C128_SYMBOL_MAX * C128_SYMBOL_MAX = 1102824 */ } total_sum %= 103; - memcpy(d, C128Table[total_sum], 6); + memcpy(d, zint_C128Table[total_sum], 6); d += 6; values[glyph_count++] = total_sum; /* For debug/test */ @@ -332,11 +332,11 @@ static void c128_expand(struct zint_symbol *symbol, int values[C128_VALUES_MAX], } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump_int(symbol, values, glyph_count); + z_debug_test_codeword_dump_int(symbol, values, glyph_count); } #endif - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); } /* Helper to set `priority` array based on flags */ @@ -367,7 +367,7 @@ static void c128_set_priority(char priority[C128_STATES], const int have_a, cons } /* Handle Code 128, 128AB and HIBC 128 */ -INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_code128(struct zint_symbol *symbol, unsigned char source[], int length) { int i; int error_number; char manuals[C128_MAX] = {0}; @@ -388,7 +388,8 @@ INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int len if (length > C128_MAX) { /* This only blocks ridiculously long input - the actual length of the resulting barcode depends on the type of data, so this is trapped later */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 340, "Input length %d too long (maximum " C128_MAX_S ")", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 340, "Input length %d too long (maximum " C128_MAX_S ")", + length); } /* Detect special Code Set escapes for Code 128 in extra escape mode only */ @@ -422,7 +423,7 @@ INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int len if (j != length) { length = j; if (length == 0) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 842, "No input data"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 842, "No input data"); } src = src_buf; src[length] = '\0'; @@ -468,13 +469,13 @@ INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int len if (symbol->debug & ZINT_DEBUG_PRINT) { printf("Data (%d): %.*s", length, length >= 100 ? 1 : length >= 10 ? 2 : 3, " "); - debug_print_escape(src, length, NULL); + z_debug_print_escape(src, length, NULL); printf("\nGlyphs: %d\n", glyph_count); } /* Now we know how long the barcode is - stop it from being too long */ if (glyph_count > C128_SYMBOL_MAX) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 341, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 341, "Input too long, requires %d symbol characters (maximum " C128_SYMBOL_MAX_S ")", glyph_count); } @@ -494,17 +495,17 @@ INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int len } length = j; } - error_number = hrt_cpy_iso8859_1(symbol, src, length); /* Returns warning only */ + error_number = z_hrt_cpy_iso8859_1(symbol, src, length); /* Returns warning only */ - if (raw_text && rt_cpy(symbol, src, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, src, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; } /* Handle GS1-128 (formerly known as EAN-128), and composite version if `cc_mode` set */ -INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_mode, +INTERNAL int zint_gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_mode, const int cc_rows) { int i; int error_number; @@ -522,7 +523,8 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int if (length > C128_MAX) { /* This only blocks ridiculously long input - the actual length of the resulting barcode depends on the type of data, so this is trapped later */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 342, "Input length %d too long (maximum " C128_MAX_S ")", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 342, "Input length %d too long (maximum " C128_MAX_S ")", + length); } /* If part of a composite symbol make room for the separator pattern */ @@ -531,7 +533,7 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int symbol->row_height[separator_row] = 1; } - error_number = gs1_verify(symbol, source, &length, reduced, &reduced_length); + error_number = zint_gs1_verify(symbol, source, &length, reduced, &reduced_length); if (error_number >= ZINT_ERROR) { return error_number; } @@ -546,14 +548,14 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int if (symbol->debug & ZINT_DEBUG_PRINT) { printf("Data (%d): %.*s", reduced_length, reduced_length >= 100 ? 1 : reduced_length >= 10 ? 2 : 3, " "); - debug_print_escape(reduced, reduced_length, NULL); + z_debug_print_escape(reduced, reduced_length, NULL); printf("\nGlyphs: %d\n", glyph_count); } /* Now we can calculate how long the barcode is going to be - and stop it from being too long */ if (glyph_count + (cc_mode != 0) > C128_SYMBOL_MAX) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 344, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 344, "Input too long, requires %d symbol characters (maximum " C128_SYMBOL_MAX_S ")", glyph_count + (cc_mode != 0)); } @@ -595,15 +597,15 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int /* Add the separator pattern for composite symbols */ if (symbol->symbology == BARCODE_GS1_128_CC) { for (i = 0; i < symbol->width; i++) { - if (!(module_is_set(symbol, separator_row + 1, i))) { - set_module(symbol, separator_row, i); + if (!(z_module_is_set(symbol, separator_row + 1, i))) { + z_set_module(symbol, separator_row, i); } } } if (reduced_length > 48) { /* GS1 General Specifications 5.4.4.3 */ - if (error_number == 0) { /* Don't overwrite any `gs1_verify()` warning */ - error_number = errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 843, + if (error_number == 0) { /* Don't overwrite any `zint_gs1_verify()` warning */ + error_number = z_errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 843, "Input too long, requires %d characters (maximum 48)", reduced_length); } } @@ -618,10 +620,10 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int /* Pass back via temporary linear structure */ symbol->height = symbol->height ? min_height : default_height; } else { - if (error_number == 0) { /* Don't overwrite any `gs1_verify()` warning */ - error_number = set_height(symbol, min_height, default_height, 0.0f, 0 /*no_errtxt*/); + if (error_number == 0) { /* Don't overwrite any `zint_gs1_verify()` warning */ + error_number = z_set_height(symbol, min_height, default_height, 0.0f, 0 /*no_errtxt*/); } else { - (void) set_height(symbol, min_height, default_height, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, min_height, default_height, 0.0f, 1 /*no_errtxt*/); } } } else { @@ -629,33 +631,33 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int if (symbol->symbology == BARCODE_GS1_128_CC) { symbol->height = height - cc_rows * (cc_mode == 3 ? 3 : 2) - 1.0f; } else { - (void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); } } /* If no other warnings flag use of READER_INIT in GS1_MODE */ if (error_number == 0 && (symbol->output_options & READER_INIT)) { - error_number = errtxt(ZINT_WARN_INVALID_OPTION, symbol, 845, + error_number = z_errtxt(ZINT_WARN_INVALID_OPTION, symbol, 845, "Cannot use Reader Initialisation in GS1 mode, ignoring"); } /* Note won't overflow `text` buffer due to symbol character maximum restricted to C128_SYMBOL_MAX */ if (symbol->input_mode & GS1PARENS_MODE) { - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); } else { - hrt_conv_gs1_brackets_nochk(symbol, source, length); + z_hrt_conv_gs1_brackets_nochk(symbol, source, length); } - if (raw_text && rt_cpy(symbol, reduced, reduced_length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, reduced, reduced_length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; } /* Handle GS1-128 (formerly known as EAN-128) */ -INTERNAL int gs1_128(struct zint_symbol *symbol, unsigned char source[], int length) { - return gs1_128_cc(symbol, source, length, 0 /*cc_mode*/, 0 /*cc_rows*/); +INTERNAL int zint_gs1_128(struct zint_symbol *symbol, unsigned char source[], int length) { + return zint_gs1_128_cc(symbol, source, length, 0 /*cc_mode*/, 0 /*cc_rows*/); } /* vim: set ts=4 sw=4 et : */ diff --git a/backend/code128.h b/backend/code128.h index 6efd9b75..0b06123e 100644 --- a/backend/code128.h +++ b/backend/code128.h @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2020-2024 Robin Stuart + Copyright (C) 2020-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -40,9 +40,9 @@ extern "C" { #define C128_MAX 256 #define C128_MAX_S "256" /* String version of above */ -INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int length); +INTERNAL int zint_code128(struct zint_symbol *symbol, unsigned char source[], int length); -INTERNAL_DATA_EXTERN const char C128Table[107][6]; +INTERNAL_DATA_EXTERN const char zint_C128Table[107][6]; #ifdef __cplusplus } diff --git a/backend/code128_based.c b/backend/code128_based.c index f98a6a99..b2468580 100644 --- a/backend/code128_based.c +++ b/backend/code128_based.c @@ -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; diff --git a/backend/code16k.c b/backend/code16k.c index f85c79c7..0ff2e822 100644 --- a/backend/code16k.c +++ b/backend/code16k.c @@ -48,7 +48,7 @@ #define C16K_ABORC '9' #define C16K_AORB 'Z' -/* Note using C128Table with extra entry at 106 (Triple Shift) for C16KTable */ +/* Note using `zint_C128Table[]` with extra entry at 106 (Triple Shift) for C16KTable */ /* EN 12323 Table 3 and Table 4 - Start patterns and stop patterns */ static const char C16KStartStop[8][4] = { @@ -322,7 +322,7 @@ static void c16k_set_c(const unsigned char source_a, const unsigned char source_ } /* Code 16k EN 12323:2005 */ -INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], int length) { char width_pattern[40]; /* 4 (start) + 1 (guard) + 5*6 (chars) + 4 (stop) + 1 */ int current_row, rows, looper, first_check, second_check; int indexchaine; @@ -339,11 +339,12 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; if (length > C128_MAX) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 420, "Input length %d too long (maximum " C128_MAX_S ")", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 420, "Input length %d too long (maximum " C128_MAX_S ")", + length); } if (symbol->option_1 == 1 || symbol->option_1 > 16) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 424, "Minimum number of rows '%d' out of range (2 to 16)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 424, "Minimum number of rows '%d' out of range (2 to 16)", symbol->option_1); } @@ -388,7 +389,7 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len if (symbol->output_options & READER_INIT) { if (gs1) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 422, "Cannot use Reader Initialisation in GS1 mode"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 422, "Cannot use Reader Initialisation in GS1 mode"); } if (m == 2) { m = 5; @@ -482,7 +483,7 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len } if (bar_characters > 80 - 2) { /* Max rows 16 * 5 - 2 check chars */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 421, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 421, "Input too long, requires %d symbol characters (maximum 78)", bar_characters); } } while (read < length); @@ -535,7 +536,7 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump_int(symbol, values, bar_characters); /* Missing row start/stop */ + z_debug_test_codeword_dump_int(symbol, values, bar_characters); /* Missing row start/stop */ } #endif @@ -551,7 +552,7 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len d += 4; *d++ = '1'; for (i = 0; i < 5; i++, d += 6) { - memcpy(d, C128Table[values[(current_row * 5) + i]], 6); + memcpy(d, zint_C128Table[values[(current_row * 5) + i]], 6); } memcpy(d, C16KStartStop[C16KStopValues[current_row]], 4); d += 4; @@ -560,9 +561,9 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len writer = 0; flip_flop = 1; for (mx_reader = 0, len = d - width_pattern; mx_reader < len; mx_reader++) { - for (looper = 0; looper < ctoi(width_pattern[mx_reader]); looper++) { + for (looper = 0; looper < z_ctoi(width_pattern[mx_reader]); looper++) { if (flip_flop == 1) { - set_module(symbol, current_row, writer); + z_set_module(symbol, current_row, writer); } writer++; } @@ -578,12 +579,12 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len Section 4.5 (b) H = X[r(h + g) + g] = rows * row_height + (rows - 1) * separator as borders not included in symbol->height (added on) */ const int separator = symbol->option_3 >= 1 && symbol->option_3 <= 4 ? symbol->option_3 : 1; - const float min_row_height = stripf((8.0f * rows + separator * (rows - 1)) / rows); + const float min_row_height = z_stripf((8.0f * rows + separator * (rows - 1)) / rows); const float default_height = 10.0f * rows + separator * (rows - 1); - error_number = set_height(symbol, min_row_height, default_height, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, min_row_height, default_height, 0.0f, 0 /*no_errtxt*/); symbol->option_3 = separator; /* Feedback options */ } else { - (void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/); } symbol->output_options |= BARCODE_BIND; @@ -592,8 +593,8 @@ INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int len symbol->border_width = 1; /* BS EN 12323:2005 Section 4.3.7 minimum (note change from previous default 2) */ } - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; diff --git a/backend/code49.c b/backend/code49.c index 7861b211..62282404 100644 --- a/backend/code49.c +++ b/backend/code49.c @@ -38,7 +38,7 @@ static const char C49_INSET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%!&*" /* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */ -INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_code49(struct zint_symbol *symbol, unsigned char source[], int length) { int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value; char intermediate[170] = ""; char *d = intermediate; @@ -54,7 +54,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 81) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 430, "Input length %d too long (maximum 81)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 430, "Input length %d too long (maximum 81)", length); } if ((symbol->input_mode & 0x07) == GS1_MODE) { gs1 = 1; @@ -65,7 +65,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng for (i = 0; i < length; i++) { if (source[i] > 127) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 431, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 431, "Invalid character at position %d in input, extended ASCII not allowed", i + 1); } if (gs1 && source[i] == '\x1D') { @@ -99,11 +99,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng for (c = 0; c < block_count; c++) { if ((c == block_count - 1) && (block_remain == 2)) { /* Rule (d) */ - block_value = 100000; - block_value += ctoi(intermediate[i]) * 1000; - block_value += ctoi(intermediate[i + 1]) * 100; - block_value += ctoi(intermediate[i + 2]) * 10; - block_value += ctoi(intermediate[i + 3]); + block_value = 100000 + z_to_int(ZCUCP(intermediate + i), 4); codewords[codeword_count] = block_value / (48 * 48); block_value = block_value - (48 * 48) * codewords[codeword_count]; @@ -114,9 +110,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng codewords[codeword_count] = block_value; codeword_count++; i += 4; - block_value = ctoi(intermediate[i]) * 100; - block_value += ctoi(intermediate[i + 1]) * 10; - block_value += ctoi(intermediate[i + 2]); + block_value = z_to_int(ZCUCP(intermediate + i), 3); codewords[codeword_count] = block_value / 48; block_value = block_value - 48 * codewords[codeword_count]; @@ -125,11 +119,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng codeword_count++; i += 3; } else { - block_value = ctoi(intermediate[i]) * 10000; - block_value += ctoi(intermediate[i + 1]) * 1000; - block_value += ctoi(intermediate[i + 2]) * 100; - block_value += ctoi(intermediate[i + 3]) * 10; - block_value += ctoi(intermediate[i + 4]); + block_value = z_to_int(ZCUCP(intermediate + i), 5); codewords[codeword_count] = block_value / (48 * 48); block_value = block_value - (48 * 48) * codewords[codeword_count]; @@ -146,15 +136,13 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng switch (block_remain) { case 1: /* Rule (a) */ - codewords[codeword_count] = posn(C49_INSET, intermediate[i]); + codewords[codeword_count] = z_posn(C49_INSET, intermediate[i]); codeword_count++; i++; break; case 3: /* Rule (b) */ - block_value = ctoi(intermediate[i]) * 100; - block_value += ctoi(intermediate[i + 1]) * 10; - block_value += ctoi(intermediate[i + 2]); + block_value = z_to_int(ZCUCP(intermediate + i), 3); codewords[codeword_count] = block_value / 48; block_value = block_value - 48 * codewords[codeword_count]; @@ -165,11 +153,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng break; case 4: /* Rule (c) */ - block_value = 100000; - block_value += ctoi(intermediate[i]) * 1000; - block_value += ctoi(intermediate[i + 1]) * 100; - block_value += ctoi(intermediate[i + 2]) * 10; - block_value += ctoi(intermediate[i + 3]); + block_value = 100000 + z_to_int(ZCUCP(intermediate + i), 4); codewords[codeword_count] = block_value / (48 * 48); block_value = block_value - (48 * 48) * codewords[codeword_count]; @@ -188,12 +172,12 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng codeword_count++; } } else { - codewords[codeword_count] = posn(C49_INSET, intermediate[i]); + codewords[codeword_count] = z_posn(C49_INSET, intermediate[i]); codeword_count++; i++; } } else { - codewords[codeword_count] = posn(C49_INSET, intermediate[i]); + codewords[codeword_count] = z_posn(C49_INSET, intermediate[i]); codeword_count++; i++; } @@ -215,7 +199,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng } if (codeword_count > 49) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 432, "Input too long, requires %d codewords (maximum 49)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 432, "Input too long, requires %d codewords (maximum 49)", codeword_count); } @@ -251,7 +235,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng } } } else if (symbol->option_1 >= 1) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 433, "Minimum number of rows out of range (2 to 8)"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 433, "Minimum number of rows out of range (2 to 8)"); } /* Feedback options */ @@ -329,7 +313,7 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump_int(symbol, (int *)c_grid, rows * 8); + z_debug_test_codeword_dump_int(symbol, (int *)c_grid, rows * 8); } #endif @@ -342,27 +326,27 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng for (i = 0; i < rows; i++) { bp = 0; - bp = bin_append_posn(2, 2, pattern, bp); /* Start character "10" */ + bp = z_bin_append_posn(2, 2, pattern, bp); /* Start character "10" */ for (j = 0; j < 4; j++) { if (i != (rows - 1)) { if (c49_table4[i][j] == 'E') { /* Even Parity */ - bp = bin_append_posn(c49_even_bitpattern[w_grid[i][j]], 16, pattern, bp); + bp = z_bin_append_posn(c49_even_bitpattern[w_grid[i][j]], 16, pattern, bp); } else { /* Odd Parity */ - bp = bin_append_posn(c49_odd_bitpattern[w_grid[i][j]], 16, pattern, bp); + bp = z_bin_append_posn(c49_odd_bitpattern[w_grid[i][j]], 16, pattern, bp); } } else { /* Last row uses all even parity */ - bp = bin_append_posn(c49_even_bitpattern[w_grid[i][j]], 16, pattern, bp); + bp = z_bin_append_posn(c49_even_bitpattern[w_grid[i][j]], 16, pattern, bp); } } - bp = bin_append_posn(15, 4, pattern, bp); /* Stop character "1111" */ + bp = z_bin_append_posn(15, 4, pattern, bp); /* Stop character "1111" */ /* Expand into symbol */ for (j = 0; j < bp; j++) { if (pattern[j] == '1') { - set_module(symbol, i, j); + z_set_module(symbol, i, j); } } } @@ -375,12 +359,12 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng Formula 2 H = ((h + g)r + g)X = rows * row_height + (rows - 1) * separator as borders not included in symbol->height (added on) */ const int separator = symbol->option_3 >= 1 && symbol->option_3 <= 4 ? symbol->option_3 : 1; - const float min_row_height = stripf((8.0f * rows + separator * (rows - 1)) / rows); + const float min_row_height = z_stripf((8.0f * rows + separator * (rows - 1)) / rows); const float default_height = 10.0f * rows + separator * (rows - 1); - error_number = set_height(symbol, min_row_height, default_height, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, min_row_height, default_height, 0.0f, 0 /*no_errtxt*/); symbol->option_3 = separator; /* Feedback options */ } else { - (void) set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 10.0f * rows, 0.0f, 1 /*no_errtxt*/); } symbol->output_options |= BARCODE_BIND; @@ -389,8 +373,8 @@ INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int leng symbol->border_width = 1; /* ANSI/AIM BC6-2000 Section 2.1 (note change from previous default 2) */ } - if (!gs1 && raw_text && rt_cpy(symbol, source, length)) { /* GS1 dealt with by `ZBarcode_Encode_Segs()` */ - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (!gs1 && raw_text && z_rt_cpy(symbol, source, length)) { /* GS1 dealt with by `ZBarcode_Encode_Segs()` */ + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; diff --git a/backend/common.c b/backend/common.c index 79b4b647..10ee46d9 100644 --- a/backend/common.c +++ b/backend/common.c @@ -36,7 +36,7 @@ #include "common.h" /* Converts a character 0-9, A-F to its equivalent integer value */ -INTERNAL int ctoi(const char source) { +INTERNAL int z_ctoi(const char source) { if (z_isdigit(source)) return (source - '0'); if ((source >= 'A') && (source <= 'F')) @@ -47,7 +47,7 @@ INTERNAL int ctoi(const char source) { } /* Converts decimal string of length <= 9 to integer value. Returns -1 if not numeric */ -INTERNAL int to_int(const unsigned char source[], const int length) { +INTERNAL int z_to_int(const unsigned char source[], const int length) { int val = 0; int non_digit = 0; int i; @@ -62,7 +62,7 @@ INTERNAL int to_int(const unsigned char source[], const int length) { } /* Converts lower case characters to upper case in string `source` */ -INTERNAL void to_upper(unsigned char source[], const int length) { +INTERNAL void z_to_upper(unsigned char source[], const int length) { int i; for (i = 0; i < length; i++) { @@ -71,7 +71,7 @@ INTERNAL void to_upper(unsigned char source[], const int length) { } /* Returns the number of times a character occurs in `source` */ -INTERNAL int chr_cnt(const unsigned char source[], const int length, const unsigned char c) { +INTERNAL int z_chr_cnt(const unsigned char source[], const int length, const unsigned char c) { int count = 0; int i; for (i = 0; i < length; i++) { @@ -80,7 +80,7 @@ INTERNAL int chr_cnt(const unsigned char source[], const int length, const unsig return count; } -/* Flag table for `is_chr()` and `not_sane()` */ +/* Flag table for `is_chr()` and `z_not_sane()` */ #define IS_CLS_F (IS_CLI_F | IS_SIL_F) static const unsigned short flgs[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*00-1F*/ @@ -115,12 +115,12 @@ static const unsigned short flgs[256] = { }; /* Whether a character matches `flg` */ -INTERNAL int is_chr(const unsigned int flg, const unsigned int c) { +INTERNAL int z_is_chr(const unsigned int flg, const unsigned int c) { return z_isascii(c) && (flgs[c] & flg); } /* Verifies if a string only uses valid characters, returning 1-based position in `source` if not, 0 for success */ -INTERNAL int not_sane(const unsigned int flg, const unsigned char source[], const int length) { +INTERNAL int z_not_sane(const unsigned int flg, const unsigned char source[], const int length) { int i; for (i = 0; i < length; i++) { @@ -134,7 +134,7 @@ INTERNAL int not_sane(const unsigned int flg, const unsigned char source[], cons /* Replaces huge switch statements for looking up in tables */ /* Verifies if a string only uses valid characters as above, but also returns `test_string` position of each in `posns` array */ -INTERNAL int not_sane_lookup(const char test_string[], const int test_length, const unsigned char source[], +INTERNAL int z_not_sane_lookup(const char test_string[], const int test_length, const unsigned char source[], const int length, int *posns) { int i, j; @@ -155,7 +155,7 @@ INTERNAL int not_sane_lookup(const char test_string[], const int test_length, co } /* Returns the position of `data` in `set_string`, or -1 if not found */ -INTERNAL int posn(const char set_string[], const char data) { +INTERNAL int z_posn(const char set_string[], const char data) { const char *s; for (s = set_string; *s; s++) { @@ -168,7 +168,7 @@ INTERNAL int posn(const char set_string[], const char data) { /* Converts `arg` to a string representing its binary equivalent of length `length` and places in `binary` at `bin_posn`. Returns `bin_posn` + `length` */ -INTERNAL int bin_append_posn(const int arg, const int length, char *binary, const int bin_posn) { +INTERNAL int z_bin_append_posn(const int arg, const int length, char *binary, const int bin_posn) { int i; const int end = length - 1; @@ -181,34 +181,35 @@ INTERNAL int bin_append_posn(const int arg, const int length, char *binary, cons #ifndef Z_COMMON_INLINE /* Returns true (1) if a module is dark/black, otherwise false (0) */ -INTERNAL int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) { +INTERNAL int z_module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) { return (symbol->encoded_data[y_coord][x_coord >> 3] >> (x_coord & 0x07)) & 1; } /* Sets a module to dark/black */ -INTERNAL void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) { +INTERNAL void z_set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) { symbol->encoded_data[y_coord][x_coord >> 3] |= 1 << (x_coord & 0x07); } /* Returns true (1-8) if a module is colour, otherwise false (0) */ -INTERNAL int module_colour_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) { +INTERNAL int z_module_colour_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord) { return symbol->encoded_data[y_coord][x_coord]; } /* Sets a module to a colour */ -INTERNAL void set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord, const int colour) { +INTERNAL void z_set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord, + const int colour) { symbol->encoded_data[y_coord][x_coord] = colour; } /* Sets a dark/black module to white (i.e. unsets) */ -INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) { +INTERNAL void z_unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) { symbol->encoded_data[y_coord][x_coord >> 3] &= ~(1 << (x_coord & 0x07)); } #endif /* Z_COMMON_INLINE */ /* Expands from a width pattern to a bit pattern */ -INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int length) { +INTERNAL void z_expand(struct zint_symbol *symbol, const char data[], const int length) { int reader; int writer = 0; @@ -223,7 +224,7 @@ INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int le assert(num >= 0); for (i = 0; i < num; i++) { if (latch) { - set_module(symbol, row, writer); + z_set_module(symbol, row, writer); } writer++; } @@ -236,7 +237,7 @@ INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int le } } -/* Helper for `errtxt()` & `errtxtf()` to set "err_id: " part of error message, returning length */ +/* Helper for `z_errtxt()` & `z_errtxtf()` to set "err_id: " part of error message, returning length */ static int errtxt_id_str(char *errtxt, int num) { int len = 0; if (num == -1) { @@ -262,7 +263,7 @@ static int errtxt_id_str(char *errtxt, int num) { /* Set `symbol->errtxt` to "err_id: msg", returning `error_number`. If `err_id` is -1, the "err_id: " prefix is omitted */ -INTERNAL int errtxt(const int error_number, struct zint_symbol *symbol, const int err_id, const char *msg) { +INTERNAL int z_errtxt(const int error_number, struct zint_symbol *symbol, const int err_id, const char *msg) { const int max_len = ARRAY_SIZE(symbol->errtxt) - 1; const int id_len = errtxt_id_str(symbol->errtxt, err_id); int msg_len = (int) strlen(msg); @@ -280,7 +281,7 @@ INTERNAL int errtxt(const int error_number, struct zint_symbol *symbol, const in static int errtxtf_dpad(const char *fmt); /* Forward reference */ -/* Helper for `errtxtf()` to parse numbered specifier "n$" (where "n" 1-9), returning `fmt` advance increment */ +/* Helper for `z_errtxtf()` to parse numbered specifier "n$" (where "n" 1-9), returning `fmt` advance increment */ static int errtxtf_num_arg(const char *fmt, int *p_arg) { int ret = 0; int arg = -2; @@ -294,7 +295,7 @@ static int errtxtf_num_arg(const char *fmt, int *p_arg) { return ret; } -/* Helper for `errtxtf()` to parse length precision for "%s", returning `fmt` advance increment */ +/* Helper for `z_errtxtf()` to parse length precision for "%s", returning `fmt` advance increment */ static int errtxtf_slen(const char *fmt, const int arg, int *p_arg_cnt, int *p_len) { int ret = 0; int len = -1; @@ -328,7 +329,7 @@ static int errtxtf_slen(const char *fmt, const int arg, int *p_arg_cnt, int *p_l return ret; } -/* Helper for `errtxtf()` to parse zero-padded minimum field length for "%d", returning `fmt` advance increment */ +/* Helper for `z_errtxtf()` to parse zero-padded minimum field length for "%d", returning `fmt` advance increment */ static int errtxtf_dpad(const char *fmt) { /* Allow one leading zero plus one or two digits only */ if (fmt[0] == '0' && z_isdigit(fmt[1])) { @@ -342,7 +343,7 @@ static int errtxtf_dpad(const char *fmt) { return 0; } -/* Helper for `errtxtf()` to parse conversion precision for "%f"/"%g", returning `fmt` advance increment */ +/* Helper for `z_errtxtf()` to parse conversion precision for "%f"/"%g", returning `fmt` advance increment */ static int errtxtf_fprec(const char *fmt) { /* Allow one digit only */ if (fmt[0] == '.' && z_isdigit(fmt[1]) && (fmt[2] == 'f' || fmt[2] == 'g')) { @@ -357,7 +358,7 @@ static int errtxtf_fprec(const char *fmt) { be numbered, "%s" with length precisions: "%.*s", "%$.*$s", "%.

s" and "%$.

s", "%d" with zero-padded minimum field lengths: "%0d" or %$0d" ("" 1-99), and "%f"/"%g" with single-digit precision: "%.f" or "%$.f" */ -INTERNAL int errtxtf(const int error_number, struct zint_symbol *symbol, const int err_id, const char *fmt, ...) { +INTERNAL int z_errtxtf(const int error_number, struct zint_symbol *symbol, const int err_id, const char *fmt, ...) { const int max_len = ARRAY_SIZE(symbol->errtxt) - 1; int p = errtxt_id_str(symbol->errtxt, err_id); const char *f; @@ -385,12 +386,12 @@ INTERNAL int errtxtf(const int error_number, struct zint_symbol *symbol, const i if ((inc = errtxtf_num_arg(f, &arg))) { if (arg == -1) { if (!(symbol->debug & ZINT_DEBUG_TEST)) assert(0); - return errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, + return z_errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, "Internal error: invalid numbered format specifer"); } if (i >= 9) { if (!(symbol->debug & ZINT_DEBUG_TEST)) assert(0); - return errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, + return z_errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, "Internal error: too many format specifiers (9 maximum)"); } f += inc; @@ -399,7 +400,7 @@ INTERNAL int errtxtf(const int error_number, struct zint_symbol *symbol, const i } else { if (i >= 9) { if (!(symbol->debug & ZINT_DEBUG_TEST)) assert(0); - return errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, + return z_errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, "Internal error: too many format specifiers (9 maximum)"); } have_unnum_arg = 1; @@ -413,7 +414,8 @@ INTERNAL int errtxtf(const int error_number, struct zint_symbol *symbol, const i if ((inc = errtxtf_slen(f, arg, &arg_cnt, &len))) { if (len == -1) { if (!(symbol->debug & ZINT_DEBUG_TEST)) assert(0); - return errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, "Internal error: invalid length precision"); + return z_errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, + "Internal error: invalid length precision"); } slens[idxs[i]] = len == 0 ? -1 : len; /* TODO: keep `slens` separate else last mentioned trumps */ have_slens[idxs[i]] = 1; @@ -426,7 +428,7 @@ INTERNAL int errtxtf(const int error_number, struct zint_symbol *symbol, const i } if (*f != 'c' && *f != 'd' && *f != 'f' && *f != 'g' && *f != 's') { if (!(symbol->debug & ZINT_DEBUG_TEST)) assert(0); - return errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, + return z_errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, "Internal error: unknown format specifier ('%c','%d','%f','%g','%s' only)"); } specs[idxs[i++]] = *f; @@ -435,7 +437,7 @@ INTERNAL int errtxtf(const int error_number, struct zint_symbol *symbol, const i } if (have_num_arg && have_unnum_arg) { if (!(symbol->debug & ZINT_DEBUG_TEST)) assert(0); - return errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, + return z_errtxt(ZINT_ERROR_ENCODING_PROBLEM, symbol, 0, "Internal error: mixed numbered and unnumbered format specifiers"); } @@ -518,24 +520,25 @@ INTERNAL int errtxtf(const int error_number, struct zint_symbol *symbol, const i return error_number; } -/* Helper to prepend/append to existing `symbol->errtxt` by calling `errtxtf(fmt)` with 2 arguments (copy of `errtxt` - & `msg`) if `msg` not NULL, or 1 argument (just copy of `errtxt`) if `msg` NULL, returning `error_number` */ -INTERNAL int errtxt_adj(const int error_number, struct zint_symbol *symbol, const char *fmt, const char *msg) { +/* Helper to prepend/append to existing `symbol->errtxt` by calling `z_errtxtf(fmt)` with 2 arguments (copy of + `errtxt` & `msg`) if `msg` not NULL, or 1 argument (just copy of `errtxt`) if `msg` NULL, returning `error_number` +*/ +INTERNAL int z_errtxt_adj(const int error_number, struct zint_symbol *symbol, const char *fmt, const char *msg) { char err_buf[ARRAY_SIZE(symbol->errtxt)]; memcpy(err_buf, symbol->errtxt, strlen(symbol->errtxt) + 1); /* Include terminating NUL */ if (msg) { - errtxtf(0, symbol, -1, fmt, err_buf, msg); + z_errtxtf(0, symbol, -1, fmt, err_buf, msg); } else { - errtxtf(0, symbol, -1, fmt, err_buf); + z_errtxtf(0, symbol, -1, fmt, err_buf); } return error_number; } /* Whether `symbology` can have row binding */ -INTERNAL int is_bindable(const int symbology) { +INTERNAL int z_is_bindable(const int symbology) { if (symbology < BARCODE_PHARMA_TWO && symbology != BARCODE_POSTNET) { return 1; } @@ -567,7 +570,7 @@ INTERNAL int is_bindable(const int symbology) { } /* Whether `symbology` is EAN */ -INTERNAL int is_ean(const int symbology) { +INTERNAL int z_is_ean(const int symbology) { switch (symbology) { case BARCODE_EAN8: case BARCODE_EAN_2ADDON: @@ -587,8 +590,8 @@ INTERNAL int is_ean(const int symbology) { } /* Whether `symbology` is EAN/UPC */ -INTERNAL int is_upcean(const int symbology) { - if (is_ean(symbology)) { +INTERNAL int z_is_upcean(const int symbology) { + if (z_is_ean(symbology)) { return 1; } @@ -607,14 +610,14 @@ INTERNAL int is_upcean(const int symbology) { } /* Whether `symbology` can have composite 2D component data */ -INTERNAL int is_composite(const int symbology) { +INTERNAL int z_is_composite(const int symbology) { /* Note if change this must change "backend_qt/qzint.cpp" `takesGS1AIData()` also */ return (symbology >= BARCODE_EANX_CC && symbology <= BARCODE_DBAR_EXPSTK_CC) || symbology == BARCODE_EAN8_CC || symbology == BARCODE_EAN13_CC; } /* Whether `symbology` is a matrix design renderable as dots */ -INTERNAL int is_dotty(const int symbology) { +INTERNAL int z_is_dotty(const int symbology) { switch (symbology) { /* Note MAXICODE and ULTRA absent */ @@ -641,9 +644,9 @@ INTERNAL int is_dotty(const int symbology) { } /* Whether `symbology` has a fixed aspect ratio (matrix design) */ -INTERNAL int is_fixed_ratio(const int symbology) { +INTERNAL int z_is_fixed_ratio(const int symbology) { - if (is_dotty(symbology)) { + if (z_is_dotty(symbology)) { return 1; } @@ -658,7 +661,7 @@ INTERNAL int is_fixed_ratio(const int symbology) { } /* Whether next two characters are digits */ -INTERNAL int is_twodigits(const unsigned char source[], const int length, const int position) { +INTERNAL int z_is_twodigits(const unsigned char source[], const int length, const int position) { if ((position + 1 < length) && z_isdigit(source[position]) && z_isdigit(source[position + 1])) { return 1; } @@ -667,7 +670,7 @@ INTERNAL int is_twodigits(const unsigned char source[], const int length, const } /* Returns how many consecutive digits lie immediately ahead up to `max`, or all if `max` is -1 */ -INTERNAL int cnt_digits(const unsigned char source[], const int length, const int position, const int max) { +INTERNAL int z_cnt_digits(const unsigned char source[], const int length, const int position, const int max) { int i; const int max_length = max == -1 || position + max > length ? length : position + max; @@ -677,7 +680,7 @@ INTERNAL int cnt_digits(const unsigned char source[], const int length, const in } /* State machine to decode UTF-8 to Unicode codepoints (state 0 means done, state 12 means error) */ -INTERNAL unsigned int decode_utf8(unsigned int *state, unsigned int *codep, const unsigned char byte) { +INTERNAL unsigned int z_decode_utf8(unsigned int *state, unsigned int *codep, const unsigned char byte) { /* Copyright (c) 2008-2009 Bjoern Hoehrmann @@ -724,12 +727,12 @@ INTERNAL unsigned int decode_utf8(unsigned int *state, unsigned int *codep, cons } /* Is string valid UTF-8? */ -INTERNAL int is_valid_utf8(const unsigned char source[], const int length) { +INTERNAL int z_is_valid_utf8(const unsigned char source[], const int length) { int i; unsigned int codepoint, state = 0; for (i = 0; i < length; i++) { - if (decode_utf8(&state, &codepoint, source[i]) == 12) { + if (z_decode_utf8(&state, &codepoint, source[i]) == 12) { return 0; } } @@ -739,7 +742,7 @@ INTERNAL int is_valid_utf8(const unsigned char source[], const int length) { /* Converts UTF-8 to Unicode. If `disallow_4byte` unset, allows all values (UTF-32). If `disallow_4byte` set, * only allows codepoints <= U+FFFF (ie four-byte sequences not allowed) (UTF-16, no surrogates) */ -INTERNAL int utf8_to_unicode(struct zint_symbol *symbol, const unsigned char source[], unsigned int vals[], +INTERNAL int z_utf8_to_unicode(struct zint_symbol *symbol, const unsigned char source[], unsigned int vals[], int *length, const int disallow_4byte) { int bpos; int jpos; @@ -750,14 +753,14 @@ INTERNAL int utf8_to_unicode(struct zint_symbol *symbol, const unsigned char sou while (bpos < *length) { do { - decode_utf8(&state, &codepoint, source[bpos++]); + z_decode_utf8(&state, &codepoint, source[bpos++]); } while (bpos < *length && state != 0 && state != 12); if (state != 0) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 240, "Corrupt Unicode data"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 240, "Corrupt Unicode data"); } if (disallow_4byte && codepoint > 0xffff) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 242, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 242, "Unicode sequences of more than 3 bytes not supported"); } @@ -772,7 +775,7 @@ INTERNAL int utf8_to_unicode(struct zint_symbol *symbol, const unsigned char sou /* Treats source as ISO/IEC 8859-1 and copies into `symbol->text`, converting to UTF-8. Control chars (incl. DEL) and non-ISO/IEC 8859-1 (0x80-9F) are replaced with spaces. Returns warning if truncated, else 0 */ -INTERNAL int hrt_cpy_iso8859_1(struct zint_symbol *symbol, const unsigned char source[], const int length) { +INTERNAL int z_hrt_cpy_iso8859_1(struct zint_symbol *symbol, const unsigned char source[], const int length) { int i, j; int warn_number = 0; @@ -807,13 +810,13 @@ INTERNAL int hrt_cpy_iso8859_1(struct zint_symbol *symbol, const unsigned char s symbol->text[j] = '\0'; if (warn_number) { - errtxt(0, symbol, 249, "Human Readable Text truncated"); + z_errtxt(0, symbol, 249, "Human Readable Text truncated"); } return warn_number; } /* No-check as-is copy of ASCII into `symbol->text`, assuming `length` fits */ -INTERNAL void hrt_cpy_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length) { +INTERNAL void z_hrt_cpy_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length) { assert(length < ARRAY_SIZE(symbol->text)); memcpy(symbol->text, source, (size_t) length); @@ -823,7 +826,7 @@ INTERNAL void hrt_cpy_nochk(struct zint_symbol *symbol, const unsigned char sour /* No-check as-is copy of ASCII into `symbol->text`, appending `separator` (if ASCII - use `\xFF` for none) and then `cat`, assuming total length fits */ -INTERNAL void hrt_cpy_cat_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length, +INTERNAL void z_hrt_cpy_cat_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length, const char separator, const unsigned char cat[], const int cat_length) { unsigned char *t = symbol->text; const int total_length = (length > 0 ? length : 0) + z_isascii(separator) + (cat_length > 0 ? cat_length : 0); @@ -845,14 +848,14 @@ INTERNAL void hrt_cpy_cat_nochk(struct zint_symbol *symbol, const unsigned char } /* Copy a single ASCII character into `symbol->text` (i.e. replaces content) */ -INTERNAL void hrt_cpy_chr(struct zint_symbol *symbol, const char ch) { +INTERNAL void z_hrt_cpy_chr(struct zint_symbol *symbol, const char ch) { symbol->text[0] = ch; symbol->text_length = 1; symbol->text[1] = '\0'; } /* No-check as-is append of ASCII to `symbol->text`, assuming current `symbol->text_length` + `length` fits */ -INTERNAL void hrt_cat_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length) { +INTERNAL void z_hrt_cat_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length) { assert(symbol->text_length + length < ARRAY_SIZE(symbol->text)); memcpy(symbol->text + symbol->text_length, source, (size_t) length); @@ -861,7 +864,7 @@ INTERNAL void hrt_cat_nochk(struct zint_symbol *symbol, const unsigned char sour } /* No-check append of `ch` to `symbol->text`, assuming current `symbol->text_length` + 1 fits */ -INTERNAL void hrt_cat_chr_nochk(struct zint_symbol *symbol, const char ch) { +INTERNAL void z_hrt_cat_chr_nochk(struct zint_symbol *symbol, const char ch) { assert(symbol->text_length + 1 < ARRAY_SIZE(symbol->text)); symbol->text[symbol->text_length++] = (const unsigned char) ch; @@ -869,7 +872,7 @@ INTERNAL void hrt_cat_chr_nochk(struct zint_symbol *symbol, const char ch) { } /* No-check `sprintf()` into `symbol->text`, assuming it fits */ -INTERNAL void hrt_printf_nochk(struct zint_symbol *symbol, const char *fmt, ...) { +INTERNAL void z_hrt_printf_nochk(struct zint_symbol *symbol, const char *fmt, ...) { va_list ap; int size; @@ -886,7 +889,7 @@ INTERNAL void hrt_printf_nochk(struct zint_symbol *symbol, const char *fmt, ...) } /* No-check copy of `source` into `symbol->text`, converting GS1 square brackets into round ones. Assumes it fits */ -INTERNAL void hrt_conv_gs1_brackets_nochk(struct zint_symbol *symbol, const unsigned char source[], +INTERNAL void z_hrt_conv_gs1_brackets_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length) { int i; int bracket_level = 0; /* Non-compliant closing square brackets may be in text */ @@ -909,14 +912,14 @@ INTERNAL void hrt_conv_gs1_brackets_nochk(struct zint_symbol *symbol, const unsi } /* Initialize `raw_segs` for `seg_count` segments. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_init_segs(struct zint_symbol *symbol, const int seg_count) { +INTERNAL int z_rt_init_segs(struct zint_symbol *symbol, const int seg_count) { int i; if (symbol->raw_segs) { - rt_free_segs(symbol); + z_rt_free_segs(symbol); } if (!(symbol->raw_segs = (struct zint_seg *) calloc((size_t) seg_count, sizeof(struct zint_seg)))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 243, "Insufficient memory for raw segs buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 243, "Insufficient memory for raw segs buffer"); } for (i = 0; i < seg_count; i++) { symbol->raw_segs[i].source = NULL; @@ -927,7 +930,7 @@ INTERNAL int rt_init_segs(struct zint_symbol *symbol, const int seg_count) { } /* Free `raw_segs` along with any `source` buffers */ -INTERNAL void rt_free_segs(struct zint_symbol *symbol) { +INTERNAL void z_rt_free_segs(struct zint_symbol *symbol) { if (symbol->raw_segs) { int i; assert(symbol->raw_seg_count); @@ -943,23 +946,23 @@ INTERNAL void rt_free_segs(struct zint_symbol *symbol) { } /* Helper to initialize `raw_segs[seg_idx]` to receive text of `length` */ -static int rt_init_seg_source(struct zint_symbol *symbol, const int seg_idx, const int length) { +static int z_rt_init_seg_source(struct zint_symbol *symbol, const int seg_idx, const int length) { assert(symbol->raw_segs); assert(seg_idx >= 0 && seg_idx < symbol->raw_seg_count); assert(!symbol->raw_segs[seg_idx].source); assert(length > 0); if (!(symbol->raw_segs[seg_idx].source = (unsigned char *) malloc((size_t) length))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 245, "Insufficient memory for raw text source buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 245, "Insufficient memory for raw text source buffer"); } return 0; } /* Copy `seg` to raw seg `seg_idx`. If `seg->eci` not set, raw seg eci set to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_cpy_seg(struct zint_symbol *symbol, const int seg_idx, const struct zint_seg *seg) { - if (rt_init_seg_source(symbol, seg_idx, seg->length)) { - return ZINT_ERROR_MEMORY; /* `rt_init_seg_source()` only fails with OOM */ +INTERNAL int z_rt_cpy_seg(struct zint_symbol *symbol, const int seg_idx, const struct zint_seg *seg) { + if (z_rt_init_seg_source(symbol, seg_idx, seg->length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_init_seg_source()` only fails with OOM */ } memcpy(symbol->raw_segs[seg_idx].source, seg->source, (size_t) seg->length); symbol->raw_segs[seg_idx].length = seg->length; @@ -969,13 +972,13 @@ INTERNAL int rt_cpy_seg(struct zint_symbol *symbol, const int seg_idx, const str /* Copy `seg` to raw seg `seg_idx` using `ddata` converted to chars as source. If `eci` set, used instead of `seg->eci`, and if neither set, sets raw seg eci to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_cpy_seg_ddata(struct zint_symbol *symbol, const int seg_idx, const struct zint_seg *seg, +INTERNAL int z_rt_cpy_seg_ddata(struct zint_symbol *symbol, const int seg_idx, const struct zint_seg *seg, const int eci, const unsigned int *ddata) { unsigned char *s; int i; - if (rt_init_seg_source(symbol, seg_idx, seg->length * 2)) { - return ZINT_ERROR_MEMORY; /* `rt_init_seg_source()` only fails with OOM */ + if (z_rt_init_seg_source(symbol, seg_idx, seg->length * 2)) { + return ZINT_ERROR_MEMORY; /* `z_rt_init_seg_source()` only fails with OOM */ } for (i = 0, s = symbol->raw_segs[seg_idx].source; i < seg->length; i++) { if (ddata[i] & 0xFF00) { @@ -990,9 +993,9 @@ INTERNAL int rt_cpy_seg_ddata(struct zint_symbol *symbol, const int seg_idx, con /* Copy `source` to raw seg 0 buffer, setting raw seg ECI to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_cpy(struct zint_symbol *symbol, const unsigned char source[], const int length) { - if (rt_init_segs(symbol, 1 /*seg_count*/) || rt_init_seg_source(symbol, 0 /*seg_idx*/, length)) { - return ZINT_ERROR_MEMORY; /* `rt_init_segs()` & `rt_init_seg_source()` only fail with OOM */ +INTERNAL int z_rt_cpy(struct zint_symbol *symbol, const unsigned char source[], const int length) { + if (z_rt_init_segs(symbol, 1 /*seg_count*/) || z_rt_init_seg_source(symbol, 0 /*seg_idx*/, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_init_segs()` & `z_rt_init_seg_source()` only fail with OOM */ } memcpy(symbol->raw_segs[0].source, source, (size_t) length); symbol->raw_segs[0].length = length; @@ -1002,13 +1005,13 @@ INTERNAL int rt_cpy(struct zint_symbol *symbol, const unsigned char source[], co /* Copy `source` to raw seg 0 buffer, appending `separator` (if ASCII - use `\xFF` for none) and then `cat`, and setting raw seg ECI to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_cpy_cat(struct zint_symbol *symbol, const unsigned char source[], const int length, +INTERNAL int z_rt_cpy_cat(struct zint_symbol *symbol, const unsigned char source[], const int length, const char separator, const unsigned char cat[], const int cat_length) { unsigned char *s; const int total_length = (length > 0 ? length : 0) + z_isascii(separator) + (cat_length > 0 ? cat_length : 0); - if (rt_init_segs(symbol, 1 /*seg_count*/) || rt_init_seg_source(symbol, 0 /*seg_idx*/, total_length)) { - return ZINT_ERROR_MEMORY; /* `rt_init_segs()` & `rt_init_seg_source()` only fail with OOM */ + if (z_rt_init_segs(symbol, 1 /*seg_count*/) || z_rt_init_seg_source(symbol, 0 /*seg_idx*/, total_length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_init_segs()` & `z_rt_init_seg_source()` only fail with OOM */ } s = symbol->raw_segs[0].source; if (length > 0) { @@ -1028,12 +1031,12 @@ INTERNAL int rt_cpy_cat(struct zint_symbol *symbol, const unsigned char source[] /* `sprintf()` into raw seg 0 buffer, assuming formatted data less than 256 bytes. Sets raw seg ECI to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_printf_256(struct zint_symbol *symbol, const char *fmt, ...) { +INTERNAL int z_rt_printf_256(struct zint_symbol *symbol, const char *fmt, ...) { va_list ap; int size; - if (rt_init_segs(symbol, 1 /*seg_count*/) || rt_init_seg_source(symbol, 0 /*seg_idx*/, 256)) { - return ZINT_ERROR_MEMORY; /* `rt_init_segs()` & `rt_init_seg_source()` only fail with OOM */ + if (z_rt_init_segs(symbol, 1 /*seg_count*/) || z_rt_init_seg_source(symbol, 0 /*seg_idx*/, 256)) { + return ZINT_ERROR_MEMORY; /* `z_rt_init_segs()` & `z_rt_init_seg_source()` only fail with OOM */ } va_start(ap, fmt); @@ -1053,14 +1056,14 @@ INTERNAL int rt_printf_256(struct zint_symbol *symbol, const char *fmt, ...) { /* Sets symbol height, returning a warning if not within minimum and/or maximum if given. `default_height` does not include height of fixed-height rows (i.e. separators/composite data) */ -INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height, const float default_height, +INTERNAL int z_set_height(struct zint_symbol *symbol, const float min_row_height, const float default_height, const float max_height, const int no_errtxt) { int error_number = 0; float fixed_height = 0.0f; int zero_count = 0; float row_height; int i; - const int rows = symbol->rows ? symbol->rows : 1; /* Sometimes called before expand() */ + const int rows = symbol->rows ? symbol->rows : 1; /* Sometimes called before `z_expand()` */ const float epsilon = 0.00000095367431640625f; /* Allow some leeway in non-compliance checks */ for (i = 0; i < rows; i++) { @@ -1074,35 +1077,35 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height, if (zero_count) { if (symbol->height) { if (symbol->input_mode & HEIGHTPERROW_MODE) { - row_height = stripf(symbol->height); + row_height = z_stripf(symbol->height); } else { - row_height = stripf((symbol->height - fixed_height) / zero_count); + row_height = z_stripf((symbol->height - fixed_height) / zero_count); } } else if (default_height) { - row_height = stripf(default_height / zero_count); + row_height = z_stripf(default_height / zero_count); } else { - row_height = stripf(min_row_height); + row_height = z_stripf(min_row_height); } if (row_height < 0.5f) { /* Absolute minimum */ row_height = 0.5f; } if (min_row_height) { - if (stripf(row_height + epsilon) < stripf(min_row_height)) { + if (z_stripf(row_height + epsilon) < z_stripf(min_row_height)) { error_number = ZINT_WARN_NONCOMPLIANT; if (!no_errtxt) { - errtxt(0, symbol, 247, "Height not compliant with standards (too small)"); + z_errtxt(0, symbol, 247, "Height not compliant with standards (too small)"); } } } - symbol->height = stripf(row_height * zero_count + fixed_height); + symbol->height = z_stripf(row_height * zero_count + fixed_height); } else { - symbol->height = stripf(fixed_height); /* Ignore any given height */ + symbol->height = z_stripf(fixed_height); /* Ignore any given height */ } if (max_height) { - if (stripf(symbol->height) > stripf(max_height + epsilon)) { + if (z_stripf(symbol->height) > z_stripf(max_height + epsilon)) { error_number = ZINT_WARN_NONCOMPLIANT; if (!no_errtxt) { - ZEXT errtxtf(0, symbol, 248, "Height not compliant with standards (maximum %.4g)", max_height); + ZEXT z_errtxtf(0, symbol, 248, "Height not compliant with standards (maximum %.4g)", max_height); } } } @@ -1110,7 +1113,7 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height, return error_number; } -/* Prevent inlining of `stripf()` which can optimize away its effect */ +/* Prevent inlining of `z_stripf()` which can optimize away its effect */ #if defined(__GNUC__) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) #define ZINT_NOINLINE __attribute__((__noinline__)) #elif defined(_MSC_VER) && _MSC_VER >= 1310 /* MSVC 2003 (VC++ 7.1) */ @@ -1120,24 +1123,24 @@ INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height, #endif /* Removes excess precision from floats - see https://stackoverflow.com/q/503436 */ -INTERNAL ZINT_NOINLINE float stripf(const float arg) { +INTERNAL ZINT_NOINLINE float z_stripf(const float arg) { return *((volatile const float *) &arg); } /* Returns total length of segments */ -INTERNAL int segs_length(const struct zint_seg segs[], const int seg_count) { +INTERNAL int z_segs_length(const struct zint_seg segs[], const int seg_count) { int total_len = 0; int i; for (i = 0; i < seg_count; i++) { - total_len += segs[i].length == -1 ? (int) ustrlen(segs[i].source) : segs[i].length; + total_len += segs[i].length == -1 ? (int) z_ustrlen(segs[i].source) : segs[i].length; } return total_len; } /* Shallow copies segments, adjusting default ECIs */ -INTERNAL void segs_cpy(const struct zint_symbol *symbol, const struct zint_seg segs[], const int seg_count, +INTERNAL void z_segs_cpy(const struct zint_symbol *symbol, const struct zint_seg segs[], const int seg_count, struct zint_seg local_segs[]) { const int default_eci = symbol->symbology == BARCODE_GRIDMATRIX ? 29 : symbol->symbology == BARCODE_UPNQR ? 4 : 3; int i; @@ -1154,7 +1157,7 @@ INTERNAL void segs_cpy(const struct zint_symbol *symbol, const struct zint_seg s /* Helper for ZINT_DEBUG_PRINT to put all but graphical ASCII in hex escapes. Output to `buf` if non-NULL, else stdout */ -INTERNAL char *debug_print_escape(const unsigned char *source, const int first_len, char *buf) { +INTERNAL char *z_debug_print_escape(const unsigned char *source, const int first_len, char *buf) { int i; if (buf) { int j = 0; @@ -1187,7 +1190,8 @@ INTERNAL char *debug_print_escape(const unsigned char *source, const int first_l #pragma GCC diagnostic ignored "-Wformat-overflow=" #endif /* Dumps hex-formatted codewords in symbol->errtxt (for use in testing) */ -INTERNAL void debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *codewords, const int length) { +INTERNAL void z_debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *codewords, + const int length) { int i, max = length, cnt_len = 0; assert(ARRAY_SIZE(symbol->errtxt) >= 100); if (length > 30) { /* 30*3 < errtxt 92 (100 - "Warning ") chars */ @@ -1202,7 +1206,7 @@ INTERNAL void debug_test_codeword_dump(struct zint_symbol *symbol, const unsigne } /* Dumps decimal-formatted codewords in symbol->errtxt (for use in testing) */ -INTERNAL void debug_test_codeword_dump_short(struct zint_symbol *symbol, const short *codewords, const int length) { +INTERNAL void z_debug_test_codeword_dump_short(struct zint_symbol *symbol, const short *codewords, const int length) { int i, max = 0, cnt_len, errtxt_len; char temp[20]; assert(ARRAY_SIZE(symbol->errtxt) >= 100); @@ -1221,7 +1225,7 @@ INTERNAL void debug_test_codeword_dump_short(struct zint_symbol *symbol, const s } /* Dumps decimal-formatted codewords in symbol->errtxt (for use in testing) */ -INTERNAL void debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length) { +INTERNAL void z_debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length) { int i, max = 0, cnt_len, errtxt_len; char temp[20]; assert(ARRAY_SIZE(symbol->errtxt) >= 100); diff --git a/backend/common.h b/backend/common.h index 82641945..fda705ed 100644 --- a/backend/common.h +++ b/backend/common.h @@ -134,7 +134,7 @@ typedef unsigned __int64 uint64_t; #endif /* Is float integral value? (https://stackoverflow.com/a/40404149) */ -#define isfintf(arg) (fmodf(arg, 1.0f) == 0.0f) +#define z_isfintf(arg) (fmodf(arg, 1.0f) == 0.0f) /* Simple versions of functions with no dependence on locale */ #define z_isdigit(c) ((c) <= '9' && (c) >= '0') @@ -147,26 +147,26 @@ typedef unsigned __int64 uint64_t; #define ZUCP(p) ((unsigned char *) (p)) #define ZCUCP(p) ((const unsigned char *) (p)) #define ZCCP(p) ((const char *) (p)) -#define ustrlen(p) strlen(ZCCP(p)) +#define z_ustrlen(p) strlen(ZCCP(p)) /* Converts an integer value to its value + '0' (so >= 10 becomes ':', ';' etc) */ -#define itoc(i) ((i) + '0') +#define z_itoc(i) ((i) + '0') /* Converts an integer value to its hexadecimal digit */ -#define xtoc(i) ((i) < 10 ? itoc(i) : ((i) - 10) + 'A') +#define z_xtoc(i) ((i) < 10 ? z_itoc(i) : ((i) - 10) + 'A') /* Converts a character 0-9, A-F to its equivalent integer value */ -INTERNAL int ctoi(const char source); +INTERNAL int z_ctoi(const char source); /* Converts decimal string of length <= 9 to integer value. Returns -1 if not numeric */ -INTERNAL int to_int(const unsigned char source[], const int length); +INTERNAL int z_to_int(const unsigned char source[], const int length); /* Converts lower case characters to upper case in string `source` */ -INTERNAL void to_upper(unsigned char source[], const int length); +INTERNAL void z_to_upper(unsigned char source[], const int length); /* Returns the number of times a character occurs in `source` */ -INTERNAL int chr_cnt(const unsigned char source[], const int length, const unsigned char c); +INTERNAL int z_chr_cnt(const unsigned char source[], const int length, const unsigned char c); -/* `is_chr()` & `not_sane()` flags */ +/* `z_is_chr()` & `z_not_sane()` flags */ #define IS_SPC_F 0x0001 /* Space */ #define IS_HSH_F 0x0002 /* Hash sign # */ #define IS_AST_F 0x0004 /* Asterisk sign * */ @@ -191,65 +191,65 @@ INTERNAL int chr_cnt(const unsigned char source[], const int length, const unsig #define NEON_F IS_NUM_F /* NEON "0123456789" */ /* Whether a character matches `flg` */ -INTERNAL int is_chr(const unsigned int flg, const unsigned int c); +INTERNAL int z_is_chr(const unsigned int flg, const unsigned int c); /* Verifies if a string only uses valid characters, returning 1-based position in `source` if not, 0 for success */ -INTERNAL int not_sane(const unsigned int flg, const unsigned char source[], const int length); +INTERNAL int z_not_sane(const unsigned int flg, const unsigned char source[], const int length); /* Verifies if a string only uses valid characters as above, but also returns `test_string` position of each in `posns` array */ -INTERNAL int not_sane_lookup(const char test_string[], const int test_length, const unsigned char source[], +INTERNAL int z_not_sane_lookup(const char test_string[], const int test_length, const unsigned char source[], const int length, int *posns); /* Returns the position of `data` in `set_string`, or -1 if not found */ -INTERNAL int posn(const char set_string[], const char data); +INTERNAL int z_posn(const char set_string[], const char data); /* Converts `arg` to a string representing its binary equivalent of length `length` and places in `binary` at `bin_posn`. Returns `bin_posn` + `length` */ -INTERNAL int bin_append_posn(const int arg, const int length, char *binary, const int bin_posn); +INTERNAL int z_bin_append_posn(const int arg, const int length, char *binary, const int bin_posn); #define Z_COMMON_INLINE 1 #ifdef Z_COMMON_INLINE -# define module_is_set(s, y, x) (((s)->encoded_data[y][(x) >> 3] >> ((x) & 0x07)) & 1) -# define set_module(s, y, x) do { (s)->encoded_data[y][(x) >> 3] |= 1 << ((x) & 0x07); } while (0) -# define module_colour_is_set(s, y, x) ((s)->encoded_data[y][x]) -# define set_module_colour(s, y, x, c) do { (s)->encoded_data[y][x] = (c); } while (0) -# define unset_module(s, y, x) do { (s)->encoded_data[y][(x) >> 3] &= ~(1 << ((x) & 0x07)); } while (0) +# define z_module_is_set(s, y, x) (((s)->encoded_data[y][(x) >> 3] >> ((x) & 0x07)) & 1) +# define z_set_module(s, y, x) do { (s)->encoded_data[y][(x) >> 3] |= 1 << ((x) & 0x07); } while (0) +# define z_module_colour_is_set(s, y, x) ((s)->encoded_data[y][x]) +# define z_set_module_colour(s, y, x, c) do { (s)->encoded_data[y][x] = (c); } while (0) +# define z_unset_module(s, y, x) do { (s)->encoded_data[y][(x) >> 3] &= ~(1 << ((x) & 0x07)); } while (0) #else /* Z_COMMON_INLINE */ /* Returns true (1) if a module is dark/black, otherwise false (0) */ -INTERNAL int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord); +INTERNAL int z_module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord); /* Sets a module to dark/black */ -INTERNAL void set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord); +INTERNAL void z_set_module(struct zint_symbol *symbol, const int y_coord, const int x_coord); /* Returns true (1-8) if a module is colour, otherwise false (0) */ -INTERNAL int module_colour_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord); +INTERNAL int z_module_colour_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord); /* Sets a module to a colour */ -INTERNAL void set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord, +INTERNAL void z_set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord, const int colour); /* Sets a dark/black module to white (i.e. unsets) */ -INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord); +INTERNAL void z_unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord); #endif /* Z_COMMON_INLINE */ /* Expands from a width pattern to a bit pattern */ -INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int length); +INTERNAL void z_expand(struct zint_symbol *symbol, const char data[], const int length); /* Set `symbol->errtxt` to "err_id: msg", returning `error_number`. If `err_id` is -1, the "err_id: " prefix is omitted */ -INTERNAL int errtxt(const int error_number, struct zint_symbol *symbol, const int err_id, const char *msg); +INTERNAL int z_errtxt(const int error_number, struct zint_symbol *symbol, const int err_id, const char *msg); #if defined(__GNUC__) && !defined(__clang__) -#define ZEXT __extension__ /* Suppress gcc pedantic warnings including when using format "%$" with `errtxtf()` */ +#define ZEXT __extension__ /* Suppress gcc pedantic warnings including when using format "%$" with `z_errtxtf()` */ #else #define ZEXT #endif @@ -260,137 +260,140 @@ INTERNAL int errtxt(const int error_number, struct zint_symbol *symbol, const in be numbered, "%s" with length precisions: "%.*s", "%$.*$s", "%.

s" and "%$.

s", "%d" with zero-padded minimum field lengths: "%0d" or %$0d" ("" 1-99), and "%f"/"%g" with single-digit precision: "%.f" or "%$.f" */ -INTERNAL int errtxtf(const int error_number, struct zint_symbol *symbol, const int err_id, const char *fmt, ...) +INTERNAL int z_errtxtf(const int error_number, struct zint_symbol *symbol, const int err_id, const char *fmt, ...) ZINT_FORMAT_PRINTF(4, 5); -/* Helper to prepend/append to existing `symbol->errtxt` by calling `errtxtf(fmt)` with 2 arguments (copy of `errtxt` - & `msg`) if `msg` not NULL, or 1 argument (just copy of `errtxt`) if `msg` NULL, returning `error_number` */ -INTERNAL int errtxt_adj(const int error_number, struct zint_symbol *symbol, const char *fmt, const char *msg); +/* Helper to prepend/append to existing `symbol->errtxt` by calling `z_errtxtf(fmt)` with 2 arguments (copy of + `errtxt` & `msg`) if `msg` not NULL, or 1 argument (just copy of `errtxt`) if `msg` NULL, returning `error_number` +*/ +INTERNAL int z_errtxt_adj(const int error_number, struct zint_symbol *symbol, const char *fmt, const char *msg); /* Whether `symbology` can have row binding */ -INTERNAL int is_bindable(const int symbology); +INTERNAL int z_is_bindable(const int symbology); /* Whether `symbology` is EAN */ -INTERNAL int is_ean(const int symbology); +INTERNAL int z_is_ean(const int symbology); /* Whether `symbology` is EAN/UPC */ -INTERNAL int is_upcean(const int symbology); +INTERNAL int z_is_upcean(const int symbology); /* Whether `symbology` can have composite 2D component data */ -INTERNAL int is_composite(const int symbology); +INTERNAL int z_is_composite(const int symbology); /* Whether `symbology` is a matrix design renderable as dots */ -INTERNAL int is_dotty(const int symbology); +INTERNAL int z_is_dotty(const int symbology); /* Whether `symbology` has a fixed aspect ratio (matrix design) */ -INTERNAL int is_fixed_ratio(const int symbology); +INTERNAL int z_is_fixed_ratio(const int symbology); /* Whether next two characters are digits */ -INTERNAL int is_twodigits(const unsigned char source[], const int length, const int position); +INTERNAL int z_is_twodigits(const unsigned char source[], const int length, const int position); /* Returns how many consecutive digits lie immediately ahead up to `max`, or all if `max` is -1 */ -INTERNAL int cnt_digits(const unsigned char source[], const int length, const int position, const int max); +INTERNAL int z_cnt_digits(const unsigned char source[], const int length, const int position, const int max); /* State machine to decode UTF-8 to Unicode codepoints (state 0 means done, state 12 means error) */ -INTERNAL unsigned int decode_utf8(unsigned int *state, unsigned int *codep, const unsigned char byte); +INTERNAL unsigned int z_decode_utf8(unsigned int *state, unsigned int *codep, const unsigned char byte); /* Is string valid UTF-8? */ -INTERNAL int is_valid_utf8(const unsigned char source[], const int length); +INTERNAL int z_is_valid_utf8(const unsigned char source[], const int length); /* Converts UTF-8 to Unicode. If `disallow_4byte` unset, allows all values (UTF-32). If `disallow_4byte` set, * only allows codepoints <= U+FFFF (ie four-byte sequences not allowed) (UTF-16, no surrogates) */ -INTERNAL int utf8_to_unicode(struct zint_symbol *symbol, const unsigned char source[], unsigned int vals[], +INTERNAL int z_utf8_to_unicode(struct zint_symbol *symbol, const unsigned char source[], unsigned int vals[], int *length, const int disallow_4byte); /* Treats source as ISO/IEC 8859-1 and copies into `symbol->text`, converting to UTF-8. Control chars (incl. DEL) and non-ISO/IEC 8859-1 (0x80-9F) are replaced with spaces. Returns warning if truncated, else 0 */ -INTERNAL int hrt_cpy_iso8859_1(struct zint_symbol *symbol, const unsigned char source[], const int length); +INTERNAL int z_hrt_cpy_iso8859_1(struct zint_symbol *symbol, const unsigned char source[], const int length); /* No-check as-is copy of ASCII into `symbol->text`, assuming `length` fits */ -INTERNAL void hrt_cpy_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length); +INTERNAL void z_hrt_cpy_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length); /* No-check as-is copy of ASCII into `symbol->text`, appending `separator` (if ASCII - use `\xFF` for none) and then `cat`, assuming total length fits */ -INTERNAL void hrt_cpy_cat_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length, +INTERNAL void z_hrt_cpy_cat_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length, const char separator, const unsigned char cat[], const int cat_length); /* Copy a single ASCII character into `symbol->text` (i.e. replaces content) */ -INTERNAL void hrt_cpy_chr(struct zint_symbol *symbol, const char ch); +INTERNAL void z_hrt_cpy_chr(struct zint_symbol *symbol, const char ch); /* No-check as-is append of ASCII to `symbol->text`, assuming current `symbol->text_length` + `length` fits */ -INTERNAL void hrt_cat_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length); +INTERNAL void z_hrt_cat_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length); /* No-check append of `ch` to `symbol->text`, assuming current `symbol->text_length` + 1 fits */ -INTERNAL void hrt_cat_chr_nochk(struct zint_symbol *symbol, const char ch); +INTERNAL void z_hrt_cat_chr_nochk(struct zint_symbol *symbol, const char ch); /* No-check `sprintf()` into `symbol->text`, assuming it fits */ -INTERNAL void hrt_printf_nochk(struct zint_symbol *symbol, const char *fmt, ...) ZINT_FORMAT_PRINTF(2, 3); +INTERNAL void z_hrt_printf_nochk(struct zint_symbol *symbol, const char *fmt, ...) ZINT_FORMAT_PRINTF(2, 3); /* No-check copy of `source` into `symbol->text`, converting GS1 square brackets into round ones. Assumes it fits */ -INTERNAL void hrt_conv_gs1_brackets_nochk(struct zint_symbol *symbol, const unsigned char source[], const int length); +INTERNAL void z_hrt_conv_gs1_brackets_nochk(struct zint_symbol *symbol, const unsigned char source[], + const int length); /* Initialize `raw_segs` for `seg_count` segments. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_init_segs(struct zint_symbol *symbol, const int seg_count); +INTERNAL int z_rt_init_segs(struct zint_symbol *symbol, const int seg_count); /* Free `raw_segs` along with any `source` buffers */ -INTERNAL void rt_free_segs(struct zint_symbol *symbol); +INTERNAL void z_rt_free_segs(struct zint_symbol *symbol); /* Copy `seg` to raw seg `seg_idx`. If `seg->eci` not set, raw seg eci set to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_cpy_seg(struct zint_symbol *symbol, const int seg_idx, const struct zint_seg *seg); +INTERNAL int z_rt_cpy_seg(struct zint_symbol *symbol, const int seg_idx, const struct zint_seg *seg); /* Copy `seg` to raw seg `seg_idx` using `ddata` converted to chars as source. If `eci` set, used instead of `seg->eci`, and if neither set, sets raw seg eci to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_cpy_seg_ddata(struct zint_symbol *symbol, const int seg_idx, const struct zint_seg *seg, +INTERNAL int z_rt_cpy_seg_ddata(struct zint_symbol *symbol, const int seg_idx, const struct zint_seg *seg, const int eci, const unsigned int *ddata); /* Copy `source` to raw seg 0 buffer, setting raw seg ECI to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_cpy(struct zint_symbol *symbol, const unsigned char source[], const int length); +INTERNAL int z_rt_cpy(struct zint_symbol *symbol, const unsigned char source[], const int length); /* Copy `source` to raw seg 0 buffer, appending `separator` (if ASCII - use `\xFF` for none) and then `cat`, and setting raw seg ECI to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_cpy_cat(struct zint_symbol *symbol, const unsigned char source[], const int length, +INTERNAL int z_rt_cpy_cat(struct zint_symbol *symbol, const unsigned char source[], const int length, const char separator, const unsigned char cat[], const int cat_length); /* `sprintf()` into raw seg 0 buffer, assuming formatted data less than 256 bytes. Sets raw seg ECI to 3. On error sets `errtxt`, returning BARCODE_ERROR_MEMORY */ -INTERNAL int rt_printf_256(struct zint_symbol *symbol, const char *fmt, ...) ZINT_FORMAT_PRINTF(2, 3); +INTERNAL int z_rt_printf_256(struct zint_symbol *symbol, const char *fmt, ...) ZINT_FORMAT_PRINTF(2, 3); /* Sets symbol height, returning a warning if not within minimum and/or maximum if given. `default_height` does not include height of fixed-height rows (i.e. separators/composite data) */ -INTERNAL int set_height(struct zint_symbol *symbol, const float min_row_height, const float default_height, +INTERNAL int z_set_height(struct zint_symbol *symbol, const float min_row_height, const float default_height, const float max_height, const int no_errtxt); /* Removes excess precision from floats - see https://stackoverflow.com/q/503436 */ -INTERNAL float stripf(const float arg); +INTERNAL float z_stripf(const float arg); /* Returns total length of segments */ -INTERNAL int segs_length(const struct zint_seg segs[], const int seg_count); +INTERNAL int z_segs_length(const struct zint_seg segs[], const int seg_count); /* Shallow copies segments, adjusting default ECIs */ -INTERNAL void segs_cpy(const struct zint_symbol *symbol, const struct zint_seg segs[], const int seg_count, +INTERNAL void z_segs_cpy(const struct zint_symbol *symbol, const struct zint_seg segs[], const int seg_count, struct zint_seg local_segs[]); /* Helper for ZINT_DEBUG_PRINT to put all but graphical ASCII in hex escapes. Output to `buf` if non-NULL, else stdout */ -INTERNAL char *debug_print_escape(const unsigned char *source, const int first_len, char *buf); +INTERNAL char *z_debug_print_escape(const unsigned char *source, const int first_len, char *buf); #ifdef ZINT_TEST /* Dumps hex-formatted codewords in symbol->errtxt (for use in testing) */ -INTERNAL void debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *codewords, const int length); +INTERNAL void z_debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *codewords, + const int length); /* Dumps decimal-formatted codewords in symbol->errtxt (for use in testing) */ -INTERNAL void debug_test_codeword_dump_short(struct zint_symbol *symbol, const short *codewords, const int length); +INTERNAL void z_debug_test_codeword_dump_short(struct zint_symbol *symbol, const short *codewords, const int length); /* Dumps decimal-formatted codewords in symbol->errtxt (for use in testing) */ -INTERNAL void debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length); +INTERNAL void z_debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length); #endif #ifdef __cplusplus diff --git a/backend/composite.c b/backend/composite.c index 9641f670..c387fdcf 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -58,19 +58,19 @@ #include "composite.h" -INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_mode, +INTERNAL int zint_gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_mode, const int cc_rows); -INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); -INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char source[], const int length, +INTERNAL int zint_eanx_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); +INTERNAL int zint_ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char source[], const int length, unsigned char local_source[], int *p_with_addon, unsigned char *zfirst_part, unsigned char *zsecond_part); -INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_row); -INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); -INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); -INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); -INTERNAL int dbar_exp_date(const unsigned char source[], const int length, const int position); +INTERNAL int zint_dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_row); +INTERNAL int zint_dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); +INTERNAL int zint_dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); +INTERNAL int zint_dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows); +INTERNAL int zint_dbar_exp_date(const unsigned char source[], const int length, const int position); static int cc_min(const int first, const int second) { @@ -218,35 +218,35 @@ static void cc_a(struct zint_symbol *symbol, const char source[], const int cc_w k = i * cc_width; /* Copy the data into codebarre */ if (cc_width != 3) { - bp = bin_append_posn(pdf_rap_side[LeftRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_side[LeftRAP - 1], 10, pattern, bp); } - bp = bin_append_posn(pdf_bitpattern[offset + codeWords[k]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + codeWords[k]], 16, pattern, bp); pattern[bp++] = '0'; if (cc_width >= 2) { if (cc_width == 3) { - bp = bin_append_posn(pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); } - bp = bin_append_posn(pdf_bitpattern[offset + codeWords[k + 1]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + codeWords[k + 1]], 16, pattern, bp); pattern[bp++] = '0'; if (cc_width >= 3) { if (cc_width == 4) { - bp = bin_append_posn(pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); } - bp = bin_append_posn(pdf_bitpattern[offset + codeWords[k + 2]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + codeWords[k + 2]], 16, pattern, bp); pattern[bp++] = '0'; if (cc_width == 4) { - bp = bin_append_posn(pdf_bitpattern[offset + codeWords[k + 3]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + codeWords[k + 3]], 16, pattern, bp); pattern[bp++] = '0'; } } } - bp = bin_append_posn(pdf_rap_side[RightRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_side[RightRAP - 1], 10, pattern, bp); pattern[bp++] = '1'; /* Stop */ /* So now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ for (loop = 0; loop < bp; loop++) { if (pattern[loop] == '1') { - set_module(symbol, i, loop); + z_set_module(symbol, i, loop); } } symbol->row_height[i] = 2; @@ -307,7 +307,7 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w /* "the CC-B component shall have codeword 920 in the first symbol character position" (section 9a) */ chainemc[mclength++] = 920; - pdf_byteprocess(chainemc, &mclength, data_string, 0, length, 0); + zint_pdf_byteprocess(chainemc, &mclength, data_string, 0, length, 0); /* Now figure out which variant of the symbol to use and load values accordingly */ @@ -380,12 +380,12 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w /* Now we have the variant we can load the data - from here on the same as MicroPDF417 code */ variant--; assert(variant >= 0); - columns = pdf_MicroVariants[variant]; /* columns */ - symbol->rows = pdf_MicroVariants[variant + 34]; /* rows */ - k = pdf_MicroVariants[variant + 68]; /* Number of EC CWs */ + columns = zint_pdf_MicroVariants[variant]; /* columns */ + symbol->rows = zint_pdf_MicroVariants[variant + 34]; /* rows */ + k = zint_pdf_MicroVariants[variant + 68]; /* Number of EC CWs */ longueur = (columns * symbol->rows) - k; /* Number of non-EC CWs */ i = longueur - mclength; /* Amount of padding required */ - offset = pdf_MicroVariants[variant + 102]; /* Coefficient offset */ + offset = zint_pdf_MicroVariants[variant + 102]; /* Coefficient offset */ /* Binary input padded to target length so no padding should be necessary */ while (i > 0) { @@ -399,9 +399,10 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w total = (chainemc[i] + mccorrection[k - 1]) % 929; for (j = k - 1; j >= 0; j--) { if (j == 0) { - mccorrection[j] = (929 - (total * pdf_Microcoeffs[offset + j]) % 929) % 929; + mccorrection[j] = (929 - (total * zint_pdf_Microcoeffs[offset + j]) % 929) % 929; } else { - mccorrection[j] = (mccorrection[j - 1] + 929 - (total * pdf_Microcoeffs[offset + j]) % 929) % 929; + mccorrection[j] = (mccorrection[j - 1] + 929 - (total * zint_pdf_Microcoeffs[offset + j]) % 929) + % 929; } } } @@ -417,10 +418,10 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w } /* Now get the RAP (Row Address Pattern) start values */ - LeftRAPStart = pdf_RAPTable[variant]; - CentreRAPStart = pdf_RAPTable[variant + 34]; - RightRAPStart = pdf_RAPTable[variant + 68]; - StartCluster = pdf_RAPTable[variant + 102] / 3; + LeftRAPStart = zint_pdf_RAPTable[variant]; + CentreRAPStart = zint_pdf_RAPTable[variant + 34]; + RightRAPStart = zint_pdf_RAPTable[variant + 68]; + StartCluster = zint_pdf_RAPTable[variant + 102] / 3; /* That's all values loaded, get on with the encoding */ @@ -435,34 +436,34 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w offset = 929 * Cluster; k = i * columns; /* Copy the data into codebarre */ - bp = bin_append_posn(pdf_rap_side[LeftRAP - 1], 10, pattern, bp); - bp = bin_append_posn(pdf_bitpattern[offset + chainemc[k]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_side[LeftRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k]], 16, pattern, bp); pattern[bp++] = '0'; if (cc_width >= 2) { if (cc_width == 3) { - bp = bin_append_posn(pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); } - bp = bin_append_posn(pdf_bitpattern[offset + chainemc[k + 1]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 1]], 16, pattern, bp); pattern[bp++] = '0'; if (cc_width >= 3) { if (cc_width == 4) { - bp = bin_append_posn(pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); } - bp = bin_append_posn(pdf_bitpattern[offset + chainemc[k + 2]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 2]], 16, pattern, bp); pattern[bp++] = '0'; if (cc_width == 4) { - bp = bin_append_posn(pdf_bitpattern[offset + chainemc[k + 3]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 3]], 16, pattern, bp); pattern[bp++] = '0'; } } } - bp = bin_append_posn(pdf_rap_side[RightRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_side[RightRAP - 1], 10, pattern, bp); pattern[bp++] = '1'; /* Stop */ /* So now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ for (loop = 0; loop < bp; loop++) { if (pattern[loop] == '1') { - set_module(symbol, i, loop); + z_set_module(symbol, i, loop); } } symbol->row_height[i] = 2; @@ -521,7 +522,7 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w chainemc[mclength++] = 0; /* Space for length descriptor */ chainemc[mclength++] = 920; /* CC-C identifier */ - pdf_byteprocess(chainemc, &mclength, data_string, 0, length, 0); + zint_pdf_byteprocess(chainemc, &mclength, data_string, 0, length, 0); chainemc[0] = mclength; @@ -554,9 +555,9 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w total = (chainemc[i] + mccorrection[k - 1]) % 929; for (j = k - 1; j >= 0; j--) { if (j == 0) { - mccorrection[j] = (929 - (total * pdf_coefrs[offset + j]) % 929) % 929; + mccorrection[j] = (929 - (total * zint_pdf_coefrs[offset + j]) % 929) % 929; } else { - mccorrection[j] = (mccorrection[j - 1] + 929 - (total * pdf_coefrs[offset + j]) % 929) % 929; + mccorrection[j] = (mccorrection[j - 1] + 929 - (total * zint_pdf_coefrs[offset + j]) % 929) % 929; } } } @@ -601,17 +602,17 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w break; } bp = 0; - bp = bin_append_posn(0x1FEA8, 17, pattern, bp); /* Row start */ + bp = z_bin_append_posn(0x1FEA8, 17, pattern, bp); /* Row start */ for (j = 0; j <= cc_width + 1; j++) { - bp = bin_append_posn(pdf_bitpattern[offset + dummy[j]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + dummy[j]], 16, pattern, bp); pattern[bp++] = '0'; } - bp = bin_append_posn(0x3FA29, 18, pattern, bp); /* Row Stop */ + bp = z_bin_append_posn(0x3FA29, 18, pattern, bp); /* Row Stop */ for (loop = 0; loop < bp; loop++) { if (pattern[loop] == '1') { - set_module(symbol, i, loop); + z_set_module(symbol, i, loop); } } symbol->row_height[i] = 3; @@ -754,11 +755,11 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour alpha_pad = 0; *p_ecc_level = 0; target_bitsize = 0; - mode = NUMERIC; + mode = GF_NUMERIC; if (length > 1 && source[0] == '1' && (source[1] == '0' || source[1] == '1' || source[1] == '7')) { /* Source starts (10), (11) or (17) */ - if (source[1] == '0' || dbar_exp_date(source, length, 2) >= 0) { /* Check date valid if (11) or (17) */ + if (source[1] == '0' || zint_dbar_exp_date(source, length, 2) >= 0) { /* Check date valid if (11) or (17) */ encoding_method = 2; } } else if (length > 1 && source[0] == '9' && source[1] == '0') { @@ -773,17 +774,17 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour } else if (encoding_method == 2) { /* Encoding Method field "10" - date and lot number */ - bp = bin_append_posn(2, 2, binary_string, bp); /* "10" */ + bp = z_bin_append_posn(2, 2, binary_string, bp); /* "10" */ if (source[1] == '0') { /* No date data */ - bp = bin_append_posn(3, 2, binary_string, bp); /* "11" */ + bp = z_bin_append_posn(3, 2, binary_string, bp); /* "11" */ read_posn = 2; } else { /* Production Date (11) or Expiration Date (17) */ - assert(length >= 8); /* Due to `dbar_exp_date()` check above */ + assert(length >= 8); /* Due to `zint_dbar_exp_date()` check above */ - bp = bin_append_posn(dbar_exp_date(source, length, 2), 16, binary_string, bp); + bp = z_bin_append_posn(zint_dbar_exp_date(source, length, 2), 16, binary_string, bp); if (source[1] == '1') { /* Production Date AI 11 */ @@ -806,7 +807,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour /* So still need FNC1 character but can't do single FNC1 in numeric mode, so insert alphanumeric latch "0000" and alphanumeric FNC1 "01111" (this implementation detail taken from BWIPP https://github.com/bwipp/postscriptbarcode Copyright (c) 2004-2019 Terry Burton) */ - bp = bin_append_posn(15, 9, binary_string, bp); /* "000001111" */ + bp = z_bin_append_posn(15, 9, binary_string, bp); /* "000001111" */ /* Note an alphanumeric FNC1 is also a numeric latch, so now in numeric mode */ } } @@ -873,7 +874,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour int numeric_value; int table3_letter; /* Encodation method "11" can be used */ - bp = bin_append_posn(3, 2, binary_string, bp); /* "11" */ + bp = z_bin_append_posn(3, 2, binary_string, bp); /* "11" */ numeric -= alpha_posn; alpha--; @@ -883,11 +884,11 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour if (alphanum == 0 && alpha > numeric) { /* Alpha mode */ - bp = bin_append_posn(3, 2, binary_string, bp); /* "11" */ + bp = z_bin_append_posn(3, 2, binary_string, bp); /* "11" */ ai90_mode = 2; } else if (alphanum == 0 && alpha == 0) { /* Numeric mode */ - bp = bin_append_posn(2, 2, binary_string, bp); /* "10" */ + bp = z_bin_append_posn(2, 2, binary_string, bp); /* "10" */ ai90_mode = 3; } else { /* Note if first 4 are digits then it would be shorter to go into NUMERIC mode first; not @@ -895,7 +896,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour /* Alphanumeric mode */ binary_string[bp++] = '0'; ai90_mode = 1; - mode = ALPHANUMERIC; + mode = GF_ALPHANUMERIC; } next_ai_posn = 2 + ninety_len; @@ -918,37 +919,37 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour binary_string[bp++] = '0'; break; case 1: - bp = bin_append_posn(2, 2, binary_string, bp); /* "10" */ + bp = z_bin_append_posn(2, 2, binary_string, bp); /* "10" */ ai_crop_posn = next_ai_posn + 1; break; case 3: - bp = bin_append_posn(3, 2, binary_string, bp); /* "11" */ + bp = z_bin_append_posn(3, 2, binary_string, bp); /* "11" */ ai_crop_posn = next_ai_posn + 1; break; } - numeric_value = alpha_posn ? to_int(ninety, alpha_posn) : 0; + numeric_value = alpha_posn ? z_to_int(ninety, alpha_posn) : 0; table3_letter = -1; if (numeric_value < 31) { - table3_letter = posn("BDHIJKLNPQRSTVWZ", ninety[alpha_posn]); + table3_letter = z_posn("BDHIJKLNPQRSTVWZ", ninety[alpha_posn]); } if (table3_letter != -1) { /* Encoding can be done according to 5.3.2 c) 2) */ /* five bit binary string representing value before letter */ - bp = bin_append_posn(numeric_value, 5, binary_string, bp); + bp = z_bin_append_posn(numeric_value, 5, binary_string, bp); /* Followed by four bit representation of letter from Table 3 */ - bp = bin_append_posn(table3_letter, 4, binary_string, bp); + bp = z_bin_append_posn(table3_letter, 4, binary_string, bp); } else { /* Encoding is done according to 5.3.2 c) 3) */ - bp = bin_append_posn(31, 5, binary_string, bp); + bp = z_bin_append_posn(31, 5, binary_string, bp); /* ten bit representation of number */ - bp = bin_append_posn(numeric_value, 10, binary_string, bp); + bp = z_bin_append_posn(numeric_value, 10, binary_string, bp); /* five bit representation of ASCII character */ - bp = bin_append_posn(ninety[alpha_posn] - 65, 5, binary_string, bp); + bp = z_bin_append_posn(ninety[alpha_posn] - 65, 5, binary_string, bp); } read_posn = alpha_posn + 3; /* +2 for 90 and +1 to go beyond alpha position */ @@ -958,13 +959,13 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour /* Alpha encodation (section 5.3.3) */ do { if (z_isupper(source[read_posn])) { - bp = bin_append_posn(source[read_posn] - 65, 5, binary_string, bp); + bp = z_bin_append_posn(source[read_posn] - 65, 5, binary_string, bp); } else if (z_isdigit(source[read_posn])) { - bp = bin_append_posn(source[read_posn] + 4, 6, binary_string, bp); + bp = z_bin_append_posn(source[read_posn] + 4, 6, binary_string, bp); } else if (source[read_posn] == '\x1D') { - bp = bin_append_posn(31, 5, binary_string, bp); + bp = z_bin_append_posn(31, 5, binary_string, bp); } read_posn++; @@ -1008,16 +1009,16 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour if (debug_print) { printf("Mode %s, General Field: %.40s%s\n", - mode == NUMERIC ? "NUMERIC" : mode == ALPHANUMERIC ? "ALPHANUMERIC" : "ISO646", + mode == GF_NUMERIC ? "NUMERIC" : mode == GF_ALPHANUMERIC ? "ALPHANUMERIC" : "ISO646", general_field, j > 40 ? "..." : ""); } if (j != 0) { /* If general field not empty */ alpha_pad = 0; - if (!general_field_encode(general_field, j, &mode, &last_digit, binary_string, &bp)) { + if (!zint_general_field_encode(general_field, j, &mode, &last_digit, binary_string, &bp)) { /* Invalid character in input data */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 441, "Invalid character in input (2D component)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 441, "Invalid character in input (2D component)"); } } @@ -1034,7 +1035,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour } if (target_bitsize == 0) { - return errtxt(ZINT_ERROR_TOO_LONG, symbol, 442, "Input too long (2D component)"); + return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 442, "Input too long (2D component)"); } remainder = target_bitsize - bp; @@ -1045,14 +1046,14 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour if (remainder >= 4 && remainder <= 6) { /* ISO/IEC 24723:2010 5.4.1 c) 2) "If four to six bits remain, add 1 to the digit value and encode the result in the next four bits. ..." */ - bp = bin_append_posn(ctoi(last_digit) + 1, 4, binary_string, bp); + bp = z_bin_append_posn(z_ctoi(last_digit) + 1, 4, binary_string, bp); if (remainder > 4) { /* "... The fifth and sixth bits, if present, shall be “0”s." (Covered by adding truncated alphanumeric latch below but do explicitly anyway) */ - bp = bin_append_posn(0, remainder - 4, binary_string, bp); + bp = z_bin_append_posn(0, remainder - 4, binary_string, bp); } } else { - bp = bin_append_posn((11 * ctoi(last_digit)) + 18, 7, binary_string, bp); + bp = z_bin_append_posn(11 * z_ctoi(last_digit) + 18, 7, binary_string, bp); /* This may push the symbol up to the next size */ } } @@ -1064,22 +1065,22 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour } if (target_bitsize == 0) { - return errtxt(ZINT_ERROR_TOO_LONG, symbol, 444, "Input too long (2D component)"); + return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 444, "Input too long (2D component)"); } if (bp < target_bitsize) { /* Now add padding to binary string */ if (alpha_pad == 1) { - bp = bin_append_posn(31, 5, binary_string, bp); /* "11111" */ + bp = z_bin_append_posn(31, 5, binary_string, bp); /* "11111" */ /* Extra FNC1 character required after Alpha encodation (section 5.3.3) */ } - if (mode == NUMERIC) { - bp = bin_append_posn(0, 4, binary_string, bp); /* "0000" */ + if (mode == GF_NUMERIC) { + bp = z_bin_append_posn(0, 4, binary_string, bp); /* "0000" */ } while (bp < target_bitsize) { - bp = bin_append_posn(4, 5, binary_string, bp); /* "00100" */ + bp = z_bin_append_posn(4, 5, binary_string, bp); /* "00100" */ } } binary_string[target_bitsize] = '\0'; @@ -1102,20 +1103,21 @@ static int cc_linear_dummy_run(struct zint_symbol *symbol, unsigned char *source dummy.option_1 = -1; dummy.input_mode = symbol->input_mode; dummy.debug = symbol->debug; - error_number = gs1_128_cc(&dummy, source, *p_length, 3 /*cc_mode*/, 0 /*cc_rows*/); + error_number = zint_gs1_128_cc(&dummy, source, *p_length, 3 /*cc_mode*/, 0 /*cc_rows*/); linear_width = dummy.width; if (error_number >= ZINT_ERROR || (symbol->debug & ZINT_DEBUG_TEST)) { - (void) errtxt(0, symbol, -1, dummy.errtxt); + (void) z_errtxt(0, symbol, -1, dummy.errtxt); } if (error_number >= ZINT_ERROR) { return 0; } - *p_length = (int) ustrlen(source); /* May have changed if ESCAPE_MODE & GS1PARENS_MODE and escaped parentheses */ + /* May have changed if ESCAPE_MODE & GS1PARENS_MODE and escaped parentheses */ + *p_length = (int) z_ustrlen(source); return linear_width; } -INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_composite(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number = 0, warn_number = 0; int cc_mode, cc_width = 0, ecc_level = 0; int j, i, k; @@ -1135,21 +1137,21 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l /* Perform sanity checks on input options first */ primary_len = (int) strlen(symbol->primary); if (primary_len == 0) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 445, "No primary (linear component)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 445, "No primary (linear component)"); } if (primary_len >= (int) sizeof(symbol->primary)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 854, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 854, "Invalid primary (linear component), must be NUL-terminated"); } if (length > 2990) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 446, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 446, "2D component input too long, requires %d characters (maximum 2990)", length); } cc_mode = symbol->option_1; if (cc_mode == 3 && symbol->symbology != BARCODE_GS1_128_CC) { /* CC-C can only be used with a GS1-128 linear part */ - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 447, + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 447, "Invalid mode (CC-C only valid with GS1-128 linear component)"); } @@ -1160,7 +1162,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l /* Do a test run of encoding the linear component to establish its width */ linear_width = cc_linear_dummy_run(symbol, primary, &primary_len); /* Length can change */ if (linear_width == 0) { - return errtxt_adj(ZINT_ERROR_INVALID_DATA, symbol, "%1$s%2$s", " (linear component)"); + return z_errtxt_adj(ZINT_ERROR_INVALID_DATA, symbol, "%1$s%2$s", " (linear component)"); } if (debug_print) { printf("GS1-128 linear width: %d\n", linear_width); @@ -1176,10 +1178,10 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l int padded_primary_len; int with_addon; unsigned char padded_primary[21]; - if (!ean_leading_zeroes(symbol, primary, primary_len, padded_primary, &with_addon, NULL, NULL)) { - return errtxt_adj(ZINT_ERROR_TOO_LONG, symbol, "%1$s%2$s", " (linear component)"); + if (!zint_ean_leading_zeroes(symbol, primary, primary_len, padded_primary, &with_addon, NULL, NULL)) { + return z_errtxt_adj(ZINT_ERROR_TOO_LONG, symbol, "%1$s%2$s", " (linear component)"); } - padded_primary_len = (int) ustrlen(padded_primary); + padded_primary_len = (int) z_ustrlen(padded_primary); if (padded_primary_len <= 7 || symbol->symbology == BARCODE_EAN8_CC) { /* EAN-8 */ cc_width = 3; } else { @@ -1201,7 +1203,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l } } if (cc_width == 0) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 449, "Input length %d wrong (linear component)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 449, "Input length %d wrong (linear component)", primary_len); } break; @@ -1263,7 +1265,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l } if (symbol->option_1 >= 1 && symbol->option_1 <= 3 && symbol->option_1 != cc_mode) { - warn_number = ZEXT errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 443, + warn_number = ZEXT z_errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 443, "Composite type changed from CC-%1$c to CC-%2$c", 'A' + (symbol->option_1 - 1), 'A' + (cc_mode - 1)); } @@ -1293,40 +1295,40 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l case BARCODE_EANX_CC: case BARCODE_EAN8_CC: case BARCODE_EAN13_CC: - error_number = eanx_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_eanx_cc(linear, primary, primary_len, symbol->rows); break; case BARCODE_GS1_128_CC: /* GS1-128 needs to know which type of 2D component is used */ - error_number = gs1_128_cc(linear, primary, primary_len, cc_mode, symbol->rows); + error_number = zint_gs1_128_cc(linear, primary, primary_len, cc_mode, symbol->rows); break; case BARCODE_DBAR_OMN_CC: - error_number = dbar_omn_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_dbar_omn_cc(linear, primary, primary_len, symbol->rows); break; case BARCODE_DBAR_LTD_CC: - error_number = dbar_ltd_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_dbar_ltd_cc(linear, primary, primary_len, symbol->rows); break; case BARCODE_DBAR_EXP_CC: - error_number = dbar_exp_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_dbar_exp_cc(linear, primary, primary_len, symbol->rows); break; case BARCODE_UPCA_CC: - error_number = eanx_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_eanx_cc(linear, primary, primary_len, symbol->rows); break; case BARCODE_UPCE_CC: - error_number = eanx_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_eanx_cc(linear, primary, primary_len, symbol->rows); break; case BARCODE_DBAR_STK_CC: - error_number = dbar_omn_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_dbar_omn_cc(linear, primary, primary_len, symbol->rows); break; case BARCODE_DBAR_OMNSTK_CC: - error_number = dbar_omn_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_dbar_omn_cc(linear, primary, primary_len, symbol->rows); break; case BARCODE_DBAR_EXPSTK_CC: - error_number = dbar_exp_cc(linear, primary, primary_len, symbol->rows); + error_number = zint_dbar_exp_cc(linear, primary, primary_len, symbol->rows); break; } if (error_number) { - ZEXT errtxtf(0, symbol, -1, "%1$s%2$s", linear->errtxt, " (linear component)"); + ZEXT z_errtxtf(0, symbol, -1, "%1$s%2$s", linear->errtxt, " (linear component)"); if (error_number >= ZINT_ERROR) { ZBarcode_Delete(linear); return error_number; @@ -1395,7 +1397,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l } break; case BARCODE_DBAR_EXP_CC: - for (k = 1; !module_is_set(linear, 1, k - 1) && module_is_set(linear, 1, k); k++); + for (k = 1; !z_module_is_set(linear, 1, k - 1) && z_module_is_set(linear, 1, k); k++); top_shift = k; break; case BARCODE_UPCA_CC: @@ -1411,7 +1413,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l top_shift = 1; break; case BARCODE_DBAR_EXPSTK_CC: - for (k = 1; !module_is_set(linear, 1, k - 1) && module_is_set(linear, 1, k); k++); + for (k = 1; !z_module_is_set(linear, 1, k - 1) && z_module_is_set(linear, 1, k); k++); top_shift = k; break; } @@ -1424,14 +1426,14 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l /* Move the 2D component of the symbol horizontally */ for (i = 0; i < symbol->rows; i++) { for (j = (symbol->width + top_shift); j >= top_shift; j--) { - if (module_is_set(symbol, i, j - top_shift)) { - set_module(symbol, i, j); + if (z_module_is_set(symbol, i, j - top_shift)) { + z_set_module(symbol, i, j); } else { - unset_module(symbol, i, j); + z_unset_module(symbol, i, j); } } for (j = 0; j < top_shift; j++) { - unset_module(symbol, i, j); + z_unset_module(symbol, i, j); } } } @@ -1440,10 +1442,10 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l for (i = 0; i < linear->rows; i++) { symbol->row_height[symbol->rows + i] = linear->row_height[i]; for (j = 0; j <= linear->width; j++) { - if (module_is_set(linear, i, j)) { - set_module(symbol, i + symbol->rows, j + bottom_shift); + if (z_module_is_set(linear, i, j)) { + z_set_module(symbol, i + symbol->rows, j + bottom_shift); } else { - unset_module(symbol, i + symbol->rows, j + bottom_shift); + z_unset_module(symbol, i + symbol->rows, j + bottom_shift); } } } @@ -1456,43 +1458,43 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l if (symbol->output_options & COMPLIANT_HEIGHT) { if (symbol->symbology == BARCODE_DBAR_STK_CC) { /* Databar Stacked needs special treatment due to asymmetric rows */ - error_number = dbar_omnstk_set_height(symbol, symbol->rows - linear->rows + 1 /*first_row*/); + error_number = zint_dbar_omnstk_set_height(symbol, symbol->rows - linear->rows + 1 /*first_row*/); } else if (symbol->symbology == BARCODE_DBAR_EXP_CC || symbol->symbology == BARCODE_DBAR_EXPSTK_CC) { /* If symbol->height given then min row height was returned, else default height */ if (error_number == 0) { /* Avoid overwriting any `gs1_verify()` warning */ - error_number = set_height(symbol, symbol->height ? linear->height : 0.0f, + error_number = z_set_height(symbol, symbol->height ? linear->height : 0.0f, symbol->height ? 0.0f : linear->height, 0.0f, 0 /*no_errtxt*/); } else { - (void) set_height(symbol, symbol->height ? linear->height : 0.0f, + (void) z_set_height(symbol, symbol->height ? linear->height : 0.0f, symbol->height ? 0.0f : linear->height, 0.0f, 1 /*no_errtxt*/); } } else { /* If symbol->height given then min row height was returned, else default height */ if (error_number == 0) { /* Avoid overwriting any previous warning (e.g. EAN-8 with add-on) */ - error_number = set_height(symbol, symbol->height ? linear->height : 0.0f, + error_number = z_set_height(symbol, symbol->height ? linear->height : 0.0f, symbol->height ? 0.0f : linear->height, 0.0f, 0 /*no_errtxt*/); } else { - (void) set_height(symbol, symbol->height ? linear->height : 0.0f, + (void) z_set_height(symbol, symbol->height ? linear->height : 0.0f, symbol->height ? 0.0f : linear->height, 0.0f, 1 /*no_errtxt*/); } } } else { if (symbol->symbology == BARCODE_DBAR_STK_CC) { - (void) dbar_omnstk_set_height(symbol, symbol->rows - linear->rows + 1 /*first_row*/); + (void) zint_dbar_omnstk_set_height(symbol, symbol->rows - linear->rows + 1 /*first_row*/); } else { - (void) set_height(symbol, symbol->height ? linear->height : 0.0f, symbol->height ? 0.0f : linear->height, - 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, symbol->height ? linear->height : 0.0f, + symbol->height ? 0.0f : linear->height, 0.0f, 1 /*no_errtxt*/); } } - hrt_cpy_nochk(symbol, linear->text, linear->text_length); + z_hrt_cpy_nochk(symbol, linear->text, linear->text_length); if (raw_text) { assert(linear->raw_segs && linear->raw_segs[0].source); /* First linear, then pipe '|' separator (following BWIPP), then composite */ - if (rt_cpy_cat(symbol, linear->raw_segs[0].source, linear->raw_segs[0].length, '|', source, length)) { + if (z_rt_cpy_cat(symbol, linear->raw_segs[0].source, linear->raw_segs[0].length, '|', source, length)) { ZBarcode_Delete(linear); - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } } diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 1f1f14b7..e7639325 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -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 : */ diff --git a/backend/dotcode.c b/backend/dotcode.c index 8689705d..6913845f 100644 --- a/backend/dotcode.c +++ b/backend/dotcode.c @@ -42,9 +42,8 @@ #include "common.h" #include "gs1.h" -#define GF 113 -#define PM 3 -#define SCORE_UNLIT_EDGE -99999 +#define DC_GF 113 +#define DC_SCORE_UNLIT_EDGE -99999 /* DotCode symbol character dot patterns, from Annex C */ static const unsigned short dc_dot_patterns[113] = { @@ -62,20 +61,15 @@ static const unsigned short dc_dot_patterns[113] = { 0x1b8, 0x1c6, 0x1cc }; -/* Printed() routine from Annex A adapted to char array of ASCII 1's and 0's */ +/* `Printed()` routine from Annex A adapted to char array of ASCII 1's and 0's - is dot set? */ static int dc_get_dot(const char Dots[], const int Hgt, const int Wid, const int x, const int y) { - - if ((x >= 0) && (x < Wid) && (y >= 0) && (y < Hgt)) { - if (Dots[(y * Wid) + x] == '1') { - return 1; - } - } - - return 0; + return x >= 0 && x < Wid && y >= 0 && y < Hgt && Dots[(y * Wid) + x] == '1'; } +/* `ClrCol()` routine from Annex A - is column empty? */ static int dc_clr_col(const char *Dots, const int Hgt, const int Wid, const int x) { int y; + for (y = x & 1; y < Hgt; y += 2) { if (dc_get_dot(Dots, Hgt, Wid, x, y)) { return 0; @@ -85,8 +79,10 @@ static int dc_clr_col(const char *Dots, const int Hgt, const int Wid, const int return 1; } +/* `ClrRow()` routine from Annex A - is row empty? */ static int dc_clr_row(const char *Dots, const int Hgt, const int Wid, const int y) { int x; + for (x = y & 1; x < Wid; x += 2) { if (dc_get_dot(Dots, Hgt, Wid, x, y)) { return 0; @@ -96,7 +92,7 @@ static int dc_clr_row(const char *Dots, const int Hgt, const int Wid, const int return 1; } -/* calc penalty for empty interior columns */ +/* `ColPenalty()` routine from Annex A - calc penalty for empty interior columns */ static int dc_col_penalty(const char *Dots, const int Hgt, const int Wid) { int x, penalty = 0, penalty_local = 0; @@ -118,7 +114,7 @@ static int dc_col_penalty(const char *Dots, const int Hgt, const int Wid) { return penalty + penalty_local; } -/* calc penalty for empty interior rows */ +/* `RowPenalty()` routine from Annex A - calc penalty for empty interior rows */ static int dc_row_penalty(const char *Dots, const int Hgt, const int Wid) { int y, penalty = 0, penalty_local = 0; @@ -140,12 +136,12 @@ static int dc_row_penalty(const char *Dots, const int Hgt, const int Wid) { return penalty + penalty_local; } -/* Dot pattern scoring routine from Annex A */ +/* `ScoreArray()` routine from Annex A - dot pattern scoring */ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { int x, y, worstedge, first, last, sum; - int penalty = 0; + int penalty; - /* first, guard against "pathelogical" gaps in the array + /* First, guard against "pathelogical" gaps in the array subtract a penalty score for empty rows/columns from total code score for each mask, where the penalty is Sum(N ^ n), where N is the number of positions in a column/row, and n is the number of consecutive empty rows/columns */ @@ -155,7 +151,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { first = -1; last = -1; - /* across the top edge, count printed dots and measure their extent */ + /* Across the top edge, count printed dots and measure their extent */ for (x = 0; x < Wid; x += 2) { if (dc_get_dot(Dots, Hgt, Wid, x, 0)) { if (first < 0) { @@ -166,7 +162,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { } } if (sum == 0) { - return SCORE_UNLIT_EDGE; /* guard against empty top edge */ + return DC_SCORE_UNLIT_EDGE; /* Guard against empty top edge */ } worstedge = sum + last - first; @@ -176,7 +172,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { first = -1; last = -1; - /* across the bottom edge, ditto */ + /* Across the bottom edge, ditto */ for (x = Wid & 1; x < Wid; x += 2) { if (dc_get_dot(Dots, Hgt, Wid, x, Hgt - 1)) { if (first < 0) { @@ -187,7 +183,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { } } if (sum == 0) { - return SCORE_UNLIT_EDGE; /* guard against empty bottom edge */ + return DC_SCORE_UNLIT_EDGE; /* Guard against empty bottom edge */ } sum += last - first; @@ -200,7 +196,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { first = -1; last = -1; - /* down the left edge, ditto */ + /* Down the left edge, ditto */ for (y = 0; y < Hgt; y += 2) { if (dc_get_dot(Dots, Hgt, Wid, 0, y)) { if (first < 0) { @@ -211,7 +207,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { } } if (sum == 0) { - return SCORE_UNLIT_EDGE; /* guard against empty left edge */ + return DC_SCORE_UNLIT_EDGE; /* Guard against empty left edge */ } sum += last - first; @@ -224,7 +220,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { first = -1; last = -1; - /* down the right edge, ditto */ + /* Down the right edge, ditto */ for (y = Hgt & 1; y < Hgt; y += 2) { if (dc_get_dot(Dots, Hgt, Wid, Wid - 1, y)) { if (first < 0) { @@ -235,7 +231,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { } } if (sum == 0) { - return SCORE_UNLIT_EDGE; /* guard against empty right edge */ + return DC_SCORE_UNLIT_EDGE; /* Guard against empty right edge */ } sum += last - first; @@ -244,7 +240,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { worstedge = sum; } - /* throughout the array, count the # of unprinted 5-somes (cross patterns) + /* Throughout the array, count the # of unprinted 5-somes (cross patterns) plus the # of printed dots surrounded by 8 unprinted neighbors */ sum = 0; for (y = 0; y < Hgt; y++) { @@ -262,11 +258,9 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) { return (worstedge - sum * sum - penalty); } -/*------------------------------------------------------------------------- -// "rsencode(nd,nc)" adds "nc" R-S check words to "nd" data words in wd[] -// employing Galois Field GF, where GF is prime, with a prime modulus of PM -//-------------------------------------------------------------------------*/ - +/* `dc_rsencode(nd, nc, wd)` adds `nc` R-S check words to `nd` data words in `wd[]` + employing Galois Field `DC_GF`, where `DC_GF` is prime, with a prime modulus of 3 + - adapted from `rsencode()` routine from Annex B */ static void dc_rsencode(const int nd, const int nc, unsigned char *wd) { /* Pre-calculated coefficients for GF(113) of generator polys of degree 3 to 39. To generate run "backend/tests/test_dotcode -f generate -g" and place result below */ @@ -336,7 +330,7 @@ static void dc_rsencode(const int nd, const int nc, unsigned char *wd) { /* Here we compute how many interleaved R-S blocks will be needed */ nw = nd + nc; - step = (nw + GF - 2) / (GF - 1); + step = (nw + DC_GF - 2) / (DC_GF - 1); /* ...& then for each such block: */ for (start = 0; start < step; start++) { @@ -345,24 +339,24 @@ static void dc_rsencode(const int nd, const int nc, unsigned char *wd) { const int NC = NW - ND; unsigned char *const e = wd + start + ND * step; - /* first set the generator polynomial "c" of order "NC": */ + /* First set the generator polynomial `c` of order `NC`: */ c = coefs + cinds[NC - 3]; - /* & then compute the corresponding checkword values into wd[] - ... (a) starting at wd[start] & (b) stepping by step */ + /* & then compute the corresponding checkword values into `wd[]` + ... (a) starting at `wd[start]` & (b) stepping by step */ for (i = 0; i < NC; i++) { e[i * step] = 0; } for (i = 0; i < ND; i++) { - k = (wd[start + i * step] + e[0]) % GF; + k = (wd[start + i * step] + e[0]) % DC_GF; for (j = 0; j < NC - 1; j++) { - e[j * step] = (GF - ((c[j + 1] * k) % GF) + e[(j + 1) * step]) % GF; + e[j * step] = (DC_GF - ((c[j + 1] * k) % DC_GF) + e[(j + 1) * step]) % DC_GF; } - e[(NC - 1) * step] = (GF - ((c[NC] * k) % GF)) % GF; + e[(NC - 1) * step] = (DC_GF - ((c[NC] * k) % DC_GF)) % DC_GF; } for (i = 0; i < NC; i++) { if (e[i * step]) { - e[i * step] = GF - e[i * step]; + e[i * step] = DC_GF - e[i * step]; } } } @@ -370,20 +364,15 @@ static void dc_rsencode(const int nd, const int nc, unsigned char *wd) { /* Check if the next character is directly encodable in code set A (Annex F.II.D) */ static int dc_datum_a(const unsigned char source[], const int length, const int position) { - - if (position < length && source[position] <= 95) { - return 1; - } - - return 0; + return position < length && source[position] <= 95; } /* Check if the next character is directly encodable in code set B (Annex F.II.D). - * Note changed to return 2 if CR/LF */ + Note changed to return 2 if CR/LF */ static int dc_datum_b(const unsigned char source[], const int length, const int position) { if (position < length) { - if ((source[position] >= 32) && (source[position] <= 127)) { + if (source[position] >= 32 && source[position] <= 127) { return 1; } @@ -396,7 +385,7 @@ static int dc_datum_b(const unsigned char source[], const int length, const int break; } - if ((position + 1 < length) && (source[position] == 13) && (source[position + 1] == 10)) { /* CRLF */ + if (position + 1 < length && source[position] == 13 && source[position + 1] == 10) { /* CRLF */ return 2; } } @@ -406,7 +395,7 @@ static int dc_datum_b(const unsigned char source[], const int length, const int /* Check if the next characters are directly encodable in code set C (Annex F.II.D) */ static int dc_datum_c(const unsigned char source[], const int length, const int position) { - return is_twodigits(source, length, position); + return z_is_twodigits(source, length, position); } /* Checks ahead for 10 or more digits starting "17xxxxxx10..." (Annex F.II.B) */ @@ -414,16 +403,15 @@ static int dc_seventeen_ten(const unsigned char source[], const int length, cons if (position + 9 < length && source[position] == '1' && source[position + 1] == '7' && source[position + 8] == '1' && source[position + 9] == '0' - && cnt_digits(source, length, position + 2, 6) >= 6) { + && z_cnt_digits(source, length, position + 2, 6) >= 6) { return 1; } return 0; } -/* Checks how many characters ahead can be reached while dc_datum_c is true, - * returning the resulting number of codewords (Annex F.II.E) - */ +/* Checks how many characters ahead can be reached while dc_datum_c is true, + returning the resulting number of codewords (Annex F.II.E) */ static int dc_ahead_c(const unsigned char source[], const int length, const int position) { int count = 0; int i; @@ -438,7 +426,7 @@ static int dc_ahead_c(const unsigned char source[], const int length, const int /* Annex F.II.F */ static int dc_try_c(const unsigned char source[], const int length, const int position) { - if (position < length && z_isdigit(source[position])) { /* cnt_digits(position) > 0 */ + if (position < length && z_isdigit(source[position])) { /* z_cnt_digits(position) > 0 */ const int ahead_c_position = dc_ahead_c(source, length, position); if (ahead_c_position > dc_ahead_c(source, length, position + 1)) { return ahead_c_position; @@ -479,12 +467,7 @@ static int dc_ahead_b(const unsigned char source[], const int length, const int /* Checks if the next character is in the range 128 to 255 (Annex F.II.I) */ static int dc_binary(const unsigned char source[], const int length, const int position) { - - if (position < length && source[position] >= 128) { - return 1; - } - - return 0; + return position < length && source[position] >= 128; } /* Empty binary buffer */ @@ -549,10 +532,10 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou if (symbol->output_options & READER_INIT) { codeword_array[ap++] = 109; /* FNC3 */ - } else if (!gs1 && eci == 0 && length > 2 && is_twodigits(source, length, 0)) { + } else if (!gs1 && eci == 0 && length > 2 && z_is_twodigits(source, length, 0)) { codeword_array[ap++] = 107; /* FNC1 */ - } else if (posn(lead_specials, source[0]) != -1) { + } else if (z_posn(lead_specials, source[0]) != -1) { /* Prevent encodation as a macro if a special character is in first position */ codeword_array[ap++] = 101; /* Latch A */ codeword_array[ap++] = source[0] + 64; @@ -573,7 +556,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou } else { inside_macro = 99; } - } else if (!format_050612 && is_twodigits(source, length, 4) ) { + } else if (!format_050612 && z_is_twodigits(source, length, 4) ) { inside_macro = 100; /* Note no longer using for malformed 05/06/12 */ } if (inside_macro) { @@ -581,8 +564,8 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou encoding_mode = 'B'; codeword_array[ap++] = inside_macro; /* Macro */ if (inside_macro == 100) { - codeword_array[ap++] = ctoi(source[4]) + 16; - codeword_array[ap++] = ctoi(source[5]) + 16; + codeword_array[ap++] = z_ctoi(source[4]) + 16; + codeword_array[ap++] = z_ctoi(source[5]) + 16; position += 6; } else { position += 7; @@ -614,7 +597,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou if (eci <= 39) { codeword_array[ap++] = eci; } else { - /* the next three codewords valued A, B & C encode the ECI value of + /* The next three codewords valued A, B & C encode the ECI value of (A - 40) * 12769 + B * 113 + C + 40 (Section 5.2.1) */ int a, b, c; a = (eci - 40) / 12769; @@ -650,9 +633,9 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou /* Step C2 */ if (dc_seventeen_ten(source, length, position)) { codeword_array[ap++] = 100; /* (17)...(10) */ - codeword_array[ap++] = to_int(source + position + 2, 2); - codeword_array[ap++] = to_int(source + position + 4, 2); - codeword_array[ap++] = to_int(source + position + 6, 2); + codeword_array[ap++] = z_to_int(source + position + 2, 2); + codeword_array[ap++] = z_to_int(source + position + 4, 2); + codeword_array[ap++] = z_to_int(source + position + 6, 2); position += 10; if (debug_print) fputs("C2/1 ", stdout); continue; @@ -663,7 +646,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou codeword_array[ap++] = 107; /* FNC1 */ position++; } else { - codeword_array[ap++] = to_int(source + position, 2); + codeword_array[ap++] = z_to_int(source + position, 2); position += 2; } if (debug_print) fputs("C2/2 ", stdout); @@ -672,7 +655,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou /* Step C3 */ if (dc_binary(source, length, position)) { - /* cnt_digits(position + 1) > 0 */ + /* z_cnt_digits(position + 1) > 0 */ if (position + 1 < length && z_isdigit(source[position + 1])) { if ((source[position] - 128) < 32) { codeword_array[ap++] = 110; /* Upper Shift A */ @@ -735,7 +718,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou if (n <= 4) { codeword_array[ap++] = 103 + (n - 2); /* nx Shift C */ for (i = 0; i < n; i++) { - codeword_array[ap++] = to_int(source + position, 2); + codeword_array[ap++] = z_to_int(source + position, 2); position += 2; } } else { @@ -829,7 +812,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou if (n <= 4) { codeword_array[ap++] = 103 + (n - 2); /* nx Shift C */ for (i = 0; i < n; i++) { - codeword_array[ap++] = to_int(source + position, 2); + codeword_array[ap++] = z_to_int(source + position, 2); position += 2; } } else { @@ -917,7 +900,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou if (n <= 7) { codeword_array[ap++] = 101 + n; /* Interrupt for nx Shift C */ for (i = 0; i < n; i++) { - codeword_array[ap++] = to_int(source + position, 2); + codeword_array[ap++] = z_to_int(source + position, 2); position += 2; } } else { @@ -1021,16 +1004,16 @@ static int dc_encode_message_segs(struct zint_symbol *symbol, const struct zint_ last_RSEOT = last_seg->source[last_seg->length - 2] == 30; /* RS */ } - 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++) { ap = dc_encode_message(symbol, segs[i].source, segs[i].length, segs[i].eci, i == seg_count - 1 /*last_seg*/, last_EOT, last_RSEOT, ap, codeword_array, &encoding_mode, &inside_macro, &bin_buf, &bin_buf_size, structapp_array, p_structapp_size); - 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 */ } } @@ -1046,19 +1029,18 @@ static int dc_make_dotstream(const unsigned char masked_array[], const int array int bp = 0; /* Mask value is encoded as two dots */ - bp = bin_append_posn(masked_array[0], 2, dot_stream, bp); + bp = z_bin_append_posn(masked_array[0], 2, dot_stream, bp); /* The rest of the data uses 9-bit dot patterns from Annex C */ for (i = 1; i < array_length; i++) { - bp = bin_append_posn(dc_dot_patterns[masked_array[i]], 9, dot_stream, bp); + bp = z_bin_append_posn(dc_dot_patterns[masked_array[i]], 9, dot_stream, bp); } return bp; } /* Determines if a given dot is a reserved corner dot - * to be used by one of the last six bits - */ + to be used by one of the last six bits */ static int dc_is_corner(const int column, const int row, const int width, const int height) { /* Top Left */ @@ -1193,6 +1175,7 @@ static void dc_apply_mask(const int mask, const int data_length, unsigned char * dc_rsencode(data_length + 1, ecc_length, masked_codeword_array); } +/* Ensure corners are "lit" */ static void dc_force_corners(const int width, const int height, char *dot_array) { if (width & 1) { /* "Vertical" symbol */ @@ -1213,7 +1196,7 @@ static void dc_force_corners(const int width, const int height, char *dot_array) } } -INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int warn_number = 0; int i, j, k; int jc, n_dots; @@ -1231,22 +1214,22 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i const int gs1 = (symbol->input_mode & 0x07) == GS1_MODE; const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT); /* Allow 4 codewords per input + 2 (FNC) + seg_count * 4 (ECI) + 2 (special char 1st position) - + 5 (Structured Append) + 10 (PAD) */ - const int codeword_array_len = segs_length(segs, seg_count) * 4 + 2 + seg_count * 4 + 2 + 5 + 10; + + 5 (Structured Append) + 52 (PAD - maximum probably 35, allowing for 468 dots / 9 == 52) */ + const int codeword_array_len = z_segs_length(segs, seg_count) * 4 + 2 + seg_count * 4 + 2 + 5 + 52; unsigned char *codeword_array = (unsigned char *) z_alloca(codeword_array_len); char *dot_stream; char *dot_array; unsigned char *masked_codeword_array; if (symbol->eci > 811799) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 525, "ECI code '%d' out of range (0 to 811799)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 525, "ECI code '%d' out of range (0 to 811799)", symbol->eci); } if (symbol->option_2 > 0) { if (symbol->option_2 < 5 || symbol->option_2 > 200) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 527, - "Number of columns '%d' is out of range (5 to 200)", symbol->option_2); + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 527, + "Number of columns '%d' is out of range (5 to 200)", symbol->option_2); } width = symbol->option_2; } @@ -1258,38 +1241,38 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i if (symbol->structapp.count) { if (symbol->structapp.count < 2 || symbol->structapp.count > 35) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 730, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 730, "Structured Append count '%d' out of range (2 to 35)", symbol->structapp.count); } if (symbol->structapp.index < 1 || symbol->structapp.index > symbol->structapp.count) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 731, - "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, 731, + "Structured Append index '%1$d' out of range (1 to count %2$d)", + symbol->structapp.index, symbol->structapp.count); } if (symbol->structapp.id[0]) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 732, "Structured Append ID not available for DotCode"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 732, "Structured Append ID not available for DotCode"); } } /* GS1 General Specifications 22.0 section 5.8.2 says Structured Append and ECIs not supported for GS1 DotCode so check and return ZINT_WARN_NONCOMPLIANT if either true */ - if (gs1 && warn_number == 0) { + if (gs1) { for (i = 0; i < seg_count; i++) { if (segs[i].eci) { - warn_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 733, + warn_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 733, "Using ECI in GS1 mode not supported by GS1 standards"); break; } } if (warn_number == 0 && symbol->structapp.count) { - warn_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 734, + warn_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 734, "Using Structured Append in GS1 mode not supported by GS1 standards"); } } if (dc_encode_message_segs(symbol, segs, seg_count, codeword_array, &binary_finish, &data_length, structapp_array, &structapp_size)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg()` etc. only fail with OOM */ + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg()` etc. only fail with OOM */ } /* Suppresses clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult/uninitialized.ArraySubscript @@ -1355,22 +1338,27 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i printf("Width %d, Height %d\n", width, height); } - if ((height > 200) || (width > 200)) { + if (height > 200 || width > 200) { if (height > 200 && width > 200) { - ZEXT errtxtf(0, symbol, 526, "Resulting symbol size '%1$dx%2$d' (HxW) is too large (maximum 200x200)", - height, width); + ZEXT z_errtxtf(0, symbol, 526, "Resulting symbol size '%1$dx%2$d' (HxW) is too large (maximum 200x200)", + height, width); + } else if (width > 200) { + z_errtxtf(0, symbol, 528, "Resulting symbol width '%d' is too large (maximum 200)", width); } else { - ZEXT errtxtf(0, symbol, 528, "Resulting symbol %1$s '%2$d' is too large (maximum 200)", - width > 200 ? "width" : "height", width > 200 ? width : height); + z_errtxtf(0, symbol, 735, "Resulting symbol height '%d' is too large (maximum 200)", height); } return ZINT_ERROR_INVALID_OPTION; } - if ((height < 5) || (width < 5)) { + if (height < 5 || width < 5) { + /* Note: this branch probably no longer reached */ assert(height >= 5 || width >= 5); /* If width < 5, min height is 19 */ - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 529, - "Resulting symbol %1$s '%2$d' is too small (minimum 5)", - width < 5 ? "width" : "height", width < 5 ? width : height); + if (width < 5) { + z_errtxtf(0, symbol, 529, "Resulting symbol width '%d' is too small (minimum 5)", width); + } else { + z_errtxtf(0, symbol, 736, "Resulting symbol height '%d' is too small (minimum 5)", height); + } + return ZINT_ERROR_INVALID_OPTION; } n_dots = (height * width) / 2; @@ -1379,10 +1367,12 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i dot_array = (char *) z_alloca(width * height); /* Add pad characters */ - padding_dots = n_dots - min_dots; /* get the number of free dots available for padding */ + padding_dots = n_dots - min_dots; /* Get the number of free dots available for padding */ + + if (debug_print) printf("Padding dots: %d\n", padding_dots); if (padding_dots >= 9) { - int is_first = 1; /* first padding character flag */ + int is_first = 1; /* First padding character flag */ int padp = data_length - structapp_size; while (padding_dots >= 9) { if (padding_dots < 18 && (data_length & 1) == 0) { @@ -1394,7 +1384,7 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i padding_dots -= 18; } } else { - break; /* not enough padding dots left for padding */ + break; /* Not enough padding dots left for padding */ } if (is_first && binary_finish) { codeword_array[padp++] = 109; @@ -1430,7 +1420,7 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump(symbol, codeword_array, data_length); + z_debug_test_codeword_dump(symbol, codeword_array, data_length); } #endif @@ -1558,7 +1548,7 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i for (k = 0; k < height; k++) { for (j = 0; j < width; j++) { if (dot_array[(k * width) + j] == '1') { - set_module(symbol, k, j); + z_set_module(symbol, k, j); } } symbol->row_height[k] = 1; diff --git a/backend/dxfilmedge.c b/backend/dxfilmedge.c index dc88330d..b43bfd9a 100644 --- a/backend/dxfilmedge.c +++ b/backend/dxfilmedge.c @@ -69,32 +69,32 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source /* All codes should start with a digit*/ if (!z_isdigit(source[0])) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 970, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 970, "Invalid first character \"%c\", DX code should start with a number", source[0]); } /* Check if there is the '/' separator, which indicates the frame number is present. */ - dx_length = posn((const char *) source, '/'); + dx_length = z_posn(ZCCP(source), '/'); if (dx_length != -1) { /* Split the DX information from the frame number */ const char *frame_start; int frame_info_len; if (dx_length > DX_MAX_DX_INFO_LENGTH) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 971, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 971, "DX information length %d too long (maximum " DX_MAX_DX_INFO_MAX_STR ")", dx_length); } memcpy(dx_info, source, dx_length); - frame_start = (const char *) source + dx_length + 1; + frame_start = ZCCP(source + dx_length + 1); frame_info_len = (int) strlen(frame_start); if (frame_info_len > DX_MAX_FRAME_INFO_LENGTH) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 972, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 972, "Frame number part length %d too long (maximum " DX_MAX_FRAME_INFO_MAX_STR ")", frame_info_len); } memcpy(frame_info, frame_start, frame_info_len); *has_frame_info = 1; - to_upper((unsigned char *) frame_info, frame_info_len); - if (not_sane(IS_UPR_F | IS_NUM_F | IS_MNS_F, (const unsigned char *) frame_info, frame_info_len)) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 973, + z_to_upper(ZUCP(frame_info), frame_info_len); + if (z_not_sane(IS_UPR_F | IS_NUM_F | IS_MNS_F, ZCUCP(frame_info), frame_info_len)) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 973, "Frame number \"%s\" is invalid (expected digits, optionally followed by a single \"A\")", frame_info); } @@ -102,14 +102,14 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source /* No "/" found, store the entire input in dx_info */ dx_length = length; if (dx_length > DX_MAX_DX_INFO_LENGTH) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 974, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 974, "DX information length %d too long (maximum " DX_MAX_DX_INFO_MAX_STR ")", dx_length); } memcpy(dx_info, source, dx_length); } - if ((i = not_sane(IS_NUM_F | IS_MNS_F, (const unsigned char *) dx_info, dx_length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 975, + if ((i = z_not_sane(IS_NUM_F | IS_MNS_F, ZCUCP(dx_info), dx_length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 975, "Invalid character at position %d in DX info (digits and \"-\" character only)", i); } @@ -118,20 +118,20 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source if (strchr(dx_info, '-')) { /* DX code parts 1 and 2 are given directly, separated by a '-'. Eg: "79-7" */ if (debug_print) printf("DX code 1 and 2 are separated by a dash \"-\"\n"); - if (chr_cnt((const unsigned char *) dx_info, dx_length, '-') > 1) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 976, + if (z_chr_cnt(ZCUCP(dx_info), dx_length, '-') > 1) { + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 976, "The \"-\" is used to separate DX parts 1 and 2, and should be used no more than once"); } if (sscanf(dx_info, "%d-%d", &dx_code_1, &dx_code_2) < 2) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 977, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 977, "Wrong format for DX parts 1 and 2 (expected format: NNN-NN, digits)"); } if (dx_code_1 <= 0 || dx_code_1 > 127) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 978, "DX part 1 \"%d\" out of range (1 to 127)", + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 978, "DX part 1 \"%d\" out of range (1 to 127)", dx_code_1); } if (dx_code_2 < 0 || dx_code_2 > 15) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 979, "DX part 2 \"%d\" out of range (0 to 15)", + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 979, "DX part 2 \"%d\" out of range (0 to 15)", dx_code_2); } } else { @@ -140,8 +140,9 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source if (debug_print) printf("No \"-\" separator, computing from DX Extract (4 digits) or DX Full (6 digits)\n"); assert(dx_length <= 6); /* I.e. DX_MAX_DX_INFO_LENGTH, guaranteed above */ if (dx_length == 5) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 980, - "DX number \"%s\" is incorrect; expected 4 digits (DX extract) or 6 digits (DX full)", dx_info); + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 980, + "DX number \"%s\" is incorrect; expected 4 digits (DX extract) or 6 digits (DX full)", + dx_info); } if (dx_length == 6) { if (debug_print) { @@ -154,10 +155,10 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source dx_length = 4; } /* Compute the DX parts 1 and 2 from the DX extract */ - dx_extract = to_int((const unsigned char *) dx_info, dx_length); + dx_extract = z_to_int(ZCUCP(dx_info), dx_length); assert(dx_extract != -1); /* All digits (no hyphen) & length 6 max - can't fail */ if (dx_extract < 16 || dx_extract > 2047) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 981, "DX extract \"%d\" out of range (16 to 2047)", + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 981, "DX extract \"%d\" out of range (16 to 2047)", dx_extract); } if (debug_print) printf("Computed DX extract: %04d\n", dx_extract); @@ -173,7 +174,7 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source if (*has_frame_info) { int ret_sscanf, n; if (strlen(frame_info) < 1) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 982, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 982, "Frame number indicator \"/\" at position %d, but frame number is empty", dx_length + 1); } @@ -194,12 +195,12 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source ret_sscanf = sscanf(frame_info, "%d%c%n", &frame_number, &half_frame_flag, &n); if (ret_sscanf < 1 || (ret_sscanf == 2 && frame_info[n] != '\0')) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 983, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 983, "Frame number \"%s\" is invalid (expected digits, optionally followed by a single \"A\")", frame_info); } if (frame_number < 0 || frame_number > 63) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 984, "Frame number \"%d\" out of range (0 to 63)", + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 984, "Frame number \"%d\" out of range (0 to 63)", frame_number); } if (debug_print) { @@ -209,18 +210,18 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source /* Build the binary output */ memcpy(binary_output, "101010", 6); /* Start pattern */ - bp = bin_append_posn(dx_code_1, 7, binary_output, 6); + bp = z_bin_append_posn(dx_code_1, 7, binary_output, 6); binary_output[bp++] = '0'; /* Separator between DX part 1 and DX part 2 */ - bp = bin_append_posn(dx_code_2, 4, binary_output, bp); + bp = z_bin_append_posn(dx_code_2, 4, binary_output, bp); if (*has_frame_info) { - bp = bin_append_posn(frame_number, 6, binary_output, bp); - to_upper((unsigned char *) &half_frame_flag, 1); + bp = z_bin_append_posn(frame_number, 6, binary_output, bp); + z_to_upper(ZUCP(&half_frame_flag), 1); if (half_frame_flag == 'A') { if (debug_print) printf("%-*s'%c'\t-> 1\n", DX_DEBUG_STR_LEN, "Half frame flag:", half_frame_flag); binary_output[bp++] = '1'; /* Half-frame is set */ } else { if (half_frame_flag) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 985, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 985, "Frame number \"%s\" is invalid (expected digits, optionally followed by a single \"A\")", frame_info); } @@ -246,15 +247,15 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source *output_length = bp; - if (raw_text && rt_printf_256(symbol, (*has_frame_info ? "%d-%d%s%s" : "%d-%d"), dx_code_1, dx_code_2, "/", + if (raw_text && z_rt_printf_256(symbol, (*has_frame_info ? "%d-%d%s%s" : "%d-%d"), dx_code_1, dx_code_2, "/", frame_info)) { - return ZINT_ERROR_MEMORY; /* `rt_printf_256()` only fails with OOM */ + return ZINT_ERROR_MEMORY; /* `z_rt_printf_256()` only fails with OOM */ } return 0; } -INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int length) { int i; int writer = 0; int error_number; @@ -269,7 +270,7 @@ INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; if (length > 10) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 986, "Input length %d too long (maximum 10)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 986, "Input length %d too long (maximum 10)", length); } error_number = dx_parse_code(symbol, source, length, binary_output, &output_length, &has_frame_info); @@ -290,9 +291,9 @@ INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int /* First row: clock pattern */ for (i = 0; i < output_length; i++) { if (clock_pattern[i] == '1') { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } else if (clock_pattern[i] == '0') { - unset_module(symbol, 0, writer); + z_unset_module(symbol, 0, writer); } writer++; } @@ -303,9 +304,9 @@ INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int /* Second row: data signal */ for (i = 0; i < output_length; i++) { if (binary_output[i] == '1') { - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); } else if (binary_output[i] == '0') { - unset_module(symbol, 1, writer); + z_unset_module(symbol, 1, writer); } writer++; } @@ -319,11 +320,11 @@ INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int /* AFAIK There is no standard on minimum and maximum height, so we stay close to the measurements */ const float min_row_height = 2.2f; const float max_height = 7.5f; - error_number = set_height(symbol, min_row_height, default_height, max_height, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, min_row_height, default_height, max_height, 0 /*no_errtxt*/); } else { /* Using compliant height as default as no backwards compatibility to consider */ const float default_height = 6.0f; - (void) set_height(symbol, 0.0f, default_height, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, default_height, 0.0f, 1 /*no_errtxt*/); } return error_number; diff --git a/backend/eci.c b/backend/eci.c index 8d8e6b0a..d653811a 100644 --- a/backend/eci.c +++ b/backend/eci.c @@ -290,12 +290,12 @@ static int u_sjis_int(const unsigned int u, unsigned int *d) { } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int u_sjis_int_test(const unsigned int u, unsigned int *d) { +INTERNAL int zint_test_u_sjis_int(const unsigned int u, unsigned int *d) { return u_sjis_int(u, d); } #endif -/* Version of `u_sjis_int()` taking unsigned char destination, for use by `utf8_to_eci()` */ +/* Version of `u_sjis_int()` taking unsigned char destination, for use by `zint_utf8_to_eci()` */ static int u_sjis(const unsigned int u, unsigned char *dest) { unsigned int d; int ret = u_sjis_int(u, &d); @@ -346,7 +346,7 @@ static int u_big5(const unsigned int u, unsigned char *dest) { } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int u_big5_test(const unsigned int u, unsigned char *dest) { +INTERNAL int zint_test_u_big5(const unsigned int u, unsigned char *dest) { return u_big5(u, dest); } #endif @@ -387,7 +387,7 @@ static int u_ksx1001(const unsigned int u, unsigned char *dest) { } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int u_ksx1001_test(const unsigned int u, unsigned char *dest) { +INTERNAL int zint_test_u_ksx1001(const unsigned int u, unsigned char *dest) { return u_ksx1001(u, dest); } #endif @@ -426,12 +426,12 @@ static int u_gb2312_int(const unsigned int u, unsigned int *d) { } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int u_gb2312_int_test(const unsigned int u, unsigned int *d) { +INTERNAL int zint_test_u_gb2312_int(const unsigned int u, unsigned int *d) { return u_gb2312_int(u, d); } #endif -/* Version of `u_gb2312_int()` taking unsigned char destination, for use by `utf8_to_eci()` */ +/* Version of `u_gb2312_int()` taking unsigned char destination, for use by `zint_utf8_to_eci()` */ static int u_gb2312(const unsigned int u, unsigned char *dest) { unsigned int d; int ret = u_gb2312_int(u, &d); @@ -495,12 +495,12 @@ static int u_gbk_int(const unsigned int u, unsigned int *d) { } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int u_gbk_int_test(const unsigned int u, unsigned int *d) { +INTERNAL int zint_test_u_gbk_int(const unsigned int u, unsigned int *d) { return u_gbk_int(u, d); } #endif -/* Version of `u_gbk_int()` taking unsigned char destination, for use by `utf8_to_eci()` */ +/* Version of `u_gbk_int()` taking unsigned char destination, for use by `zint_utf8_to_eci()` */ static int u_gbk(const unsigned int u, unsigned char *dest) { unsigned int d; int ret = u_gbk_int(u, &d); @@ -624,12 +624,12 @@ static int u_gb18030_int(const unsigned int u, unsigned int *d1, unsigned int *d } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int u_gb18030_int_test(const unsigned int u, unsigned int *d1, unsigned int *d2) { +INTERNAL int zint_test_u_gb18030_int(const unsigned int u, unsigned int *d1, unsigned int *d2) { return u_gb18030_int(u, d1, d2); } #endif -/* Version of `u_gb18030_int()` taking unsigned char destination, for use by `utf8_to_eci()` */ +/* Version of `u_gb18030_int()` taking unsigned char destination, for use by `zint_utf8_to_eci()` */ static int u_gb18030(const unsigned int u, unsigned char *dest) { unsigned int d1, d2; int ret = u_gb18030_int(u, &d1, &d2); @@ -672,7 +672,7 @@ static int chr_range_cnt(const unsigned char string[], const int length, const u } /* Is ECI convertible from UTF-8? */ -INTERNAL int is_eci_convertible(const int eci) { +INTERNAL int zint_is_eci_convertible(const int eci) { if (eci == 26 || (eci > 35 && eci != 170)) { /* Exclude ECI 170 - ASCII Invariant */ /* UTF-8 (26) or 8-bit binary data (899) or undefined (> 35 and < 899) or not character set (> 899) */ return 0; @@ -682,21 +682,21 @@ INTERNAL int is_eci_convertible(const int eci) { /* Are any of the ECIs in the segments convertible from UTF-8? Sets `convertible[]` for each, which must be at least `seg_count` in size */ -INTERNAL int is_eci_convertible_segs(const struct zint_seg segs[], const int seg_count, int convertible[]) { +INTERNAL int zint_is_eci_convertible_segs(const struct zint_seg segs[], const int seg_count, int convertible[]) { int ret = 0; int i; for (i = 0; i < seg_count; i++) { - convertible[i] = is_eci_convertible(segs[i].eci); + convertible[i] = zint_is_eci_convertible(segs[i].eci); ret |= convertible[i]; } return ret; } /* Calculate length required to convert UTF-8 to (double-byte) encoding */ -INTERNAL int get_eci_length(const int eci, const unsigned char source[], int length) { +INTERNAL int zint_get_eci_length(const int eci, const unsigned char source[], int length) { if (eci == 20) { /* Shift JIS */ /* Only ASCII backslash (reverse solidus) exceeds UTF-8 length */ - length += chr_cnt(source, length, '\\'); + length += z_chr_cnt(source, length, '\\'); } else if (eci == 25 || eci == 33) { /* UTF-16 */ /* All ASCII chars take 2 bytes */ @@ -717,13 +717,13 @@ INTERNAL int get_eci_length(const int eci, const unsigned char source[], int len return length; } -/* Call `get_eci_length()` for each segment, returning total */ -INTERNAL int get_eci_length_segs(const struct zint_seg segs[], const int seg_count) { +/* Call `zint_get_eci_length()` for each segment, returning total */ +INTERNAL int zint_get_eci_length_segs(const struct zint_seg segs[], const int seg_count) { int length = 0; int i; for (i = 0; i < seg_count; i++) { - length += get_eci_length(segs[i].eci, segs[i].source, segs[i].length); + length += zint_get_eci_length(segs[i].eci, segs[i].source, segs[i].length); } return length; @@ -731,7 +731,7 @@ INTERNAL int get_eci_length_segs(const struct zint_seg segs[], const int seg_cou /* Convert UTF-8 to other character encodings */ typedef int (*eci_func_t)(const unsigned int u, unsigned char *dest); -INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned char dest[], int *p_length) { +INTERNAL int zint_utf8_to_eci(const int eci, const unsigned char source[], unsigned char dest[], int *p_length) { static const eci_func_t eci_funcs[36] = { NULL, NULL, u_cp437, NULL, u_iso8859_2, /*0-4*/ @@ -754,7 +754,7 @@ INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned c if (eci == 0 || eci == 3 || eci == 1) { while (in_posn < length) { do { - decode_utf8(&state, &codepoint, source[in_posn++]); + z_decode_utf8(&state, &codepoint, source[in_posn++]); } while (in_posn < length && state != 0 && state != 12); if (state != 0) { return ZINT_ERROR_INVALID_DATA; @@ -783,7 +783,7 @@ INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned c while (in_posn < length) { int incr; do { - decode_utf8(&state, &codepoint, source[in_posn++]); + z_decode_utf8(&state, &codepoint, source[in_posn++]); } while (in_posn < length && state != 0 && state != 12); if (state != 0) { return ZINT_ERROR_INVALID_DATA; @@ -801,9 +801,9 @@ INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned c } /* Find the lowest single-byte ECI mode which will encode a given set of Unicode text, assuming valid UTF-8 */ -INTERNAL int get_best_eci(const unsigned char source[], int length) { +INTERNAL int zint_get_best_eci(const unsigned char source[], int length) { int eci = 3; - /* Note: attempting single-byte conversions only, so get_eci_length() unnecessary */ + /* Note: attempting single-byte conversions only, so `zint_get_eci_length()` unnecessary */ unsigned char *local_source = (unsigned char *) z_alloca(length + 1); do { @@ -812,26 +812,27 @@ INTERNAL int get_best_eci(const unsigned char source[], int length) { } else if (eci == 19) { /* Reserved */ eci = 21; /* Skip 20 Shift JIS */ } - if (utf8_to_eci(eci, source, local_source, &length) == 0) { + if (zint_utf8_to_eci(eci, source, local_source, &length) == 0) { return eci; } eci++; } while (eci < 25); - assert(is_valid_utf8(source, length)); + assert(z_is_valid_utf8(source, length)); return 26; /* If all of these fail, use UTF-8! */ } -/* Call `get_best_eci()` for each segment, assuming valid UTF-8. Returns 0 on failure, first ECI set on success */ -INTERNAL int get_best_eci_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +/* Call `zint_get_best_eci()` for each segment, assuming valid UTF-8. Returns 0 on failure, first ECI set on success +*/ +INTERNAL int zint_get_best_eci_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { const int default_eci = symbol->symbology == BARCODE_GRIDMATRIX ? 29 : symbol->symbology == BARCODE_UPNQR ? 4 : 3; int first_eci_set = 0; int i; for (i = 0; i < seg_count; i++) { if (segs[i].eci == 0) { - const int eci = get_best_eci(segs[i].source, segs[i].length); + const int eci = zint_get_best_eci(segs[i].source, segs[i].length); if (eci == default_eci) { if (i != 0 && segs[i - 1].eci != 0 && segs[i - 1].eci != default_eci) { segs[i].eci = eci; @@ -857,20 +858,20 @@ INTERNAL int get_best_eci_segs(struct zint_symbol *symbol, struct zint_seg segs[ /* QRCODE Shift JIS helpers */ /* Convert UTF-8 string to Shift JIS and place in array of ints */ -INTERNAL int sjis_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, +INTERNAL int zint_sjis_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, unsigned int *ddata) { int error_number; unsigned int i, length; unsigned int *utfdata = (unsigned int *) z_alloca(sizeof(unsigned int) * (*p_length + 1)); - error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/); + error_number = z_utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/); if (error_number != 0) { return error_number; } for (i = 0, length = *p_length; i < length; i++) { if (!u_sjis_int(utfdata[i], ddata + i)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 800, "Invalid character in input"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 800, "Invalid character in input"); } } @@ -879,7 +880,8 @@ INTERNAL int sjis_utf8(struct zint_symbol *symbol, const unsigned char source[], /* If `full_multibyte` set, copy byte input stream to array of ints, putting double-bytes that match QR Kanji mode in * a single entry. If `full_multibyte` not set, do a straight copy */ -INTERNAL void sjis_cpy(const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte) { +INTERNAL void zint_sjis_cpy(const unsigned char source[], int *p_length, unsigned int *ddata, + const int full_multibyte) { unsigned int i, j, length; unsigned char c1, c2; @@ -910,41 +912,41 @@ INTERNAL void sjis_cpy(const unsigned char source[], int *p_length, unsigned int } } -/* Call `sjis_cpy()` for each segment */ -INTERNAL int sjis_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, +/* Call `zint_sjis_cpy()` for each segment */ +INTERNAL int zint_sjis_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, unsigned int *ddata, const int full_multibyte) { int i; unsigned int *dd = ddata; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; /* Note only called for DATA_MODE */ for (i = 0; i < seg_count; i++) { - sjis_cpy(segs[i].source, &segs[i].length, dd, full_multibyte); - if (raw_text && rt_cpy_seg_ddata(symbol, i, &segs[i], 0 /*eci*/, dd)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg_ddata()` only fails with OOM */ + zint_sjis_cpy(segs[i].source, &segs[i].length, dd, full_multibyte); + if (raw_text && z_rt_cpy_seg_ddata(symbol, i, &segs[i], 0 /*eci*/, dd)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg_ddata()` only fails with OOM */ } dd += segs[i].length; } return 0; } -/* Convert UTF-8 string to ECI and place in array of ints using `sjis_cpy()` */ -INTERNAL int sjis_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, +/* Convert UTF-8 string to ECI and place in array of ints using `zint_sjis_cpy()` */ +INTERNAL int zint_sjis_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte) { - if (is_eci_convertible(eci)) { + if (zint_is_eci_convertible(eci)) { int error_number; - const int eci_length = get_eci_length(eci, source, *p_length); + const int eci_length = zint_get_eci_length(eci, source, *p_length); unsigned char *converted = (unsigned char *) z_alloca(eci_length + 1); - error_number = utf8_to_eci(eci, source, converted, p_length); + error_number = zint_utf8_to_eci(eci, source, converted, p_length); if (error_number != 0) { /* Note not setting `symbol->errtxt`, up to caller */ return error_number; } - sjis_cpy(converted, p_length, ddata, full_multibyte || eci == 20); + zint_sjis_cpy(converted, p_length, ddata, full_multibyte || eci == 20); } else { - sjis_cpy(source, p_length, ddata, full_multibyte); + zint_sjis_cpy(source, p_length, ddata, full_multibyte); } return 0; @@ -953,13 +955,13 @@ INTERNAL int sjis_utf8_to_eci(const int eci, const unsigned char source[], int * /* GRIDMATRIX GB 2312 helpers */ /* Convert UTF-8 string to GB 2312 (EUC-CN) and place in array of ints */ -INTERNAL int gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, +INTERNAL int zint_gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, unsigned int *ddata) { int error_number; unsigned int i, length; unsigned int *utfdata = (unsigned int *) z_alloca(sizeof(unsigned int) * (*p_length + 1)); - error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/); + error_number = z_utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/); if (error_number != 0) { return error_number; } @@ -969,7 +971,7 @@ INTERNAL int gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[ ddata[i] = utfdata[i]; } else { if (!u_gb2312_int(utfdata[i], ddata + i)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 810, "Invalid character in input"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 810, "Invalid character in input"); } } } @@ -1011,24 +1013,24 @@ static void gb2312_cpy(const unsigned char source[], int *p_length, unsigned int } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL void gb2312_cpy_test(const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL void zint_test_gb2312_cpy(const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte) { gb2312_cpy(source, p_length, ddata, full_multibyte); } #endif /* Call `gb2312_cpy()` for each segment */ -INTERNAL int gb2312_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, +INTERNAL int zint_gb2312_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, unsigned int *ddata, const int full_multibyte) { int i; unsigned int *dd = ddata; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; for (i = 0; i < seg_count; i++) { - const int eci = segs[i].eci ? segs[i].eci : 29; /* Need to set as `rt_cpy_seg_ddata()` defaults to 3 */ + const int eci = segs[i].eci ? segs[i].eci : 29; /* Need to set as `z_rt_cpy_seg_ddata()` defaults to 3 */ gb2312_cpy(segs[i].source, &segs[i].length, dd, full_multibyte); - if (raw_text && rt_cpy_seg_ddata(symbol, i, &segs[i], eci, dd)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg_ddata()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg_ddata(symbol, i, &segs[i], eci, dd)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg_ddata()` only fails with OOM */ } dd += segs[i].length; } @@ -1036,15 +1038,15 @@ INTERNAL int gb2312_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], } /* Convert UTF-8 string to ECI and place in array of ints using `gb2312_cpy()` */ -INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL int zint_gb2312_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte) { - if (is_eci_convertible(eci)) { + if (zint_is_eci_convertible(eci)) { int error_number; - const int eci_length = get_eci_length(eci, source, *p_length); + const int eci_length = zint_get_eci_length(eci, source, *p_length); unsigned char *converted = (unsigned char *) z_alloca(eci_length + 1); - error_number = utf8_to_eci(eci, source, converted, p_length); + error_number = zint_utf8_to_eci(eci, source, converted, p_length); if (error_number != 0) { /* Note not setting `symbol->errtxt`, up to caller */ return error_number; @@ -1061,13 +1063,13 @@ INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int /* HANXIN GB 18030 helpers */ /* Convert UTF-8 string to GB 18030 and place in array of ints */ -INTERNAL int gb18030_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, +INTERNAL int zint_gb18030_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, unsigned int *ddata) { int error_number, ret; unsigned int i, j, length; unsigned int *utfdata = (unsigned int *) z_alloca(sizeof(unsigned int) * (*p_length + 1)); - error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 0 /*disallow_4byte*/); + error_number = z_utf8_to_unicode(symbol, source, utfdata, p_length, 0 /*disallow_4byte*/); if (error_number != 0) { return error_number; } @@ -1078,7 +1080,7 @@ INTERNAL int gb18030_utf8(struct zint_symbol *symbol, const unsigned char source } else { ret = u_gb18030_int(utfdata[i], ddata + j, ddata + j + 1); if (ret == 0) { /* Should never happen, as GB 18030 is a UTF i.e. maps all Unicode codepoints */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 820, "Invalid character in input"); /* Not reached */ + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 820, "Invalid character in input"); /* Not reached */ } if (ret == 4) { j++; @@ -1136,14 +1138,14 @@ static void gb18030_cpy(const unsigned char source[], int *p_length, unsigned in } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL void gb18030_cpy_test(const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL void zint_test_gb18030_cpy(const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte) { gb18030_cpy(source, p_length, ddata, full_multibyte); } #endif /* Call `gb18030_cpy()` for each segment */ -INTERNAL int gb18030_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, +INTERNAL int zint_gb18030_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, unsigned int *ddata, const int full_multibyte) { int i; unsigned int *dd = ddata; @@ -1151,8 +1153,8 @@ INTERNAL int gb18030_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[] for (i = 0; i < seg_count; i++) { gb18030_cpy(segs[i].source, &segs[i].length, dd, full_multibyte); - if (raw_text && rt_cpy_seg_ddata(symbol, i, &segs[i], 0 /*eci*/, dd)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg_ddata()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg_ddata(symbol, i, &segs[i], 0 /*eci*/, dd)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg_ddata()` only fails with OOM */ } dd += segs[i].length; } @@ -1160,15 +1162,15 @@ INTERNAL int gb18030_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[] } /* Convert UTF-8 string to ECI and place in array of ints using `gb18030_cpy()` */ -INTERNAL int gb18030_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL int zint_gb18030_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte) { - if (is_eci_convertible(eci)) { + if (zint_is_eci_convertible(eci)) { int error_number; - const int eci_length = get_eci_length(eci, source, *p_length); + const int eci_length = zint_get_eci_length(eci, source, *p_length); unsigned char *converted = (unsigned char *) z_alloca(eci_length + 1); - error_number = utf8_to_eci(eci, source, converted, p_length); + error_number = zint_utf8_to_eci(eci, source, converted, p_length); if (error_number != 0) { /* Note not setting `symbol->errtxt`, up to caller */ return error_number; diff --git a/backend/eci.h b/backend/eci.h index 73c94f54..0d05b491 100644 --- a/backend/eci.h +++ b/backend/eci.h @@ -1,7 +1,7 @@ /* eci.c - Extended Channel Interpretations to Unicode tables */ /* libzint - the open source barcode library - Copyright (C) 2009-2024 Robin Stuart + Copyright (C) 2009-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -37,40 +37,41 @@ extern "C" { #endif /* __cplusplus */ -INTERNAL int is_eci_convertible(const int eci); -INTERNAL int is_eci_convertible_segs(const struct zint_seg segs[], const int seg_count, int convertible[]); +INTERNAL int zint_is_eci_convertible(const int eci); +INTERNAL int zint_is_eci_convertible_segs(const struct zint_seg segs[], const int seg_count, int convertible[]); -INTERNAL int get_eci_length(const int eci, const unsigned char source[], int length); -INTERNAL int get_eci_length_segs(const struct zint_seg segs[], const int seg_count); +INTERNAL int zint_get_eci_length(const int eci, const unsigned char source[], int length); +INTERNAL int zint_get_eci_length_segs(const struct zint_seg segs[], const int seg_count); -INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned char dest[], int *p_length); +INTERNAL int zint_utf8_to_eci(const int eci, const unsigned char source[], unsigned char dest[], int *p_length); -INTERNAL int get_best_eci(const unsigned char source[], int length); -INTERNAL int get_best_eci_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); +INTERNAL int zint_get_best_eci(const unsigned char source[], int length); +INTERNAL int zint_get_best_eci_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* QRCODE Shift JIS helpers */ -INTERNAL int sjis_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, +INTERNAL int zint_sjis_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, unsigned int *ddata); -INTERNAL void sjis_cpy(const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte); -INTERNAL int sjis_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, +INTERNAL void zint_sjis_cpy(const unsigned char source[], int *p_length, unsigned int *ddata, + const int full_multibyte); +INTERNAL int zint_sjis_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, unsigned int *ddata, const int full_multibyte); -INTERNAL int sjis_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL int zint_sjis_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte); /* GRIDMATRIX GB 2312 helpers */ -INTERNAL int gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, +INTERNAL int zint_gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, unsigned int *ddata); -INTERNAL int gb2312_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, +INTERNAL int zint_gb2312_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, unsigned int *ddata, const int full_multibyte); -INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL int zint_gb2312_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte); /* HANXIN GB 18030 helpers */ -INTERNAL int gb18030_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, +INTERNAL int zint_gb18030_utf8(struct zint_symbol *symbol, const unsigned char source[], int *p_length, unsigned int *ddata); -INTERNAL int gb18030_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, +INTERNAL int zint_gb18030_cpy_segs(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count, unsigned int *ddata, const int full_multibyte); -INTERNAL int gb18030_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL int zint_gb18030_utf8_to_eci(const int eci, const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte); #ifdef __cplusplus diff --git a/backend/emf.c b/backend/emf.c index b5c3ed58..31980f54 100644 --- a/backend/emf.c +++ b/backend/emf.c @@ -43,7 +43,7 @@ #include "emf.h" /* Multiply truncating to 3 decimal places (avoids rounding differences on various platforms) */ -#define emf_mul3dpf(m, arg) stripf(roundf((m) * (arg) * 1000.0f) / 1000.0f) +#define emf_mul3dpf(m, arg) z_stripf(roundf((m) * (arg) * 1000.0f) / 1000.0f) static int emf_count_rectangles(const struct zint_symbol *symbol) { int rectangles = 0; @@ -159,7 +159,7 @@ static int emf_utfle_length(const unsigned char *input, const int length) { return result; } -INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { +INTERNAL int zint_emf_plot(struct zint_symbol *symbol, int rotate_angle) { int i; struct filemem fm; struct filemem *const fmp = &fm; @@ -181,14 +181,14 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { int device_pxx, device_pxy; /* Pixels */ int mmx, mmy; /* Millimeters */ int micronx, microny; /* Micrometers */ - const float dpmm = symbol->dpmm ? stripf(symbol->dpmm) + const float dpmm = symbol->dpmm ? z_stripf(symbol->dpmm) : ZBarcode_XdimDp_From_Scale(symbol->symbology, symbol->scale, ZBarcode_Default_Xdim(symbol->symbology), "EMF"); const int sideways = rotate_angle == 90 || rotate_angle == 270; int draw_background = 1; int bold; - const int upcean = is_upcean(symbol->symbology); + const int is_upcean = z_is_upcean(symbol->symbology); struct zint_vector_rect *rect; struct zint_vector_circle *circ; @@ -239,11 +239,11 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { const int ih_ultra_offset = symbol->symbology == BARCODE_ULTRA ? 8 : 0; if (symbol->vector == NULL) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 643, "Vector header NULL"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 643, "Vector header NULL"); } - (void) out_colour_get_rgb(symbol->fgcolour, &fgred, &fggrn, &fgblu, NULL /*alpha*/); - (void) out_colour_get_rgb(symbol->bgcolour, &bgred, &bggrn, &bgblu, &bgalpha); + (void) zint_out_colour_get_rgb(symbol->fgcolour, &fgred, &fggrn, &fgblu, NULL /*alpha*/); + (void) zint_out_colour_get_rgb(symbol->bgcolour, &bgred, &bggrn, &bgblu, &bgalpha); if (bgalpha == 0) { draw_background = 0; } @@ -287,150 +287,151 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { device_pxy = height; if (dpmm) { - frame_cmmx = (int) roundf(stripf(width * 100.0f / dpmm)) - 1; /* frame also "inclusive-inclusive" */ - frame_cmmy = (int) roundf(stripf(height * 100.0f / dpmm)) - 1; - mmx = (int) roundf(stripf(width / dpmm)); /* millimeters */ - mmy = (int) roundf(stripf(height / dpmm)); - micronx = (int) roundf(stripf(width * 1000.0f / dpmm)); /* micrometers */ - microny = (int) roundf(stripf(height * 1000.0f / dpmm)); + frame_cmmx = (int) roundf(z_stripf(width * 100.0f / dpmm)) - 1; /* frame also "inclusive-inclusive" */ + frame_cmmy = (int) roundf(z_stripf(height * 100.0f / dpmm)) - 1; + mmx = (int) roundf(z_stripf(width / dpmm)); /* millimeters */ + mmy = (int) roundf(z_stripf(height / dpmm)); + micronx = (int) roundf(z_stripf(width * 1000.0f / dpmm)); /* micrometers */ + microny = (int) roundf(z_stripf(height * 1000.0f / dpmm)); } else { /* Should only happen if `symbol->scale` zero. */ - frame_cmmx = (int) roundf(stripf(width * 100.0f)) - 1; - frame_cmmy = (int) roundf(stripf(height * 100.0f)) - 1; - mmx = (int) roundf(stripf(width)); - mmy = (int) roundf(stripf(height)); - micronx = (int) roundf(stripf(width * 1000.0f)); - microny = (int) roundf(stripf(height * 1000.0f)); + frame_cmmx = (int) roundf(z_stripf(width * 100.0f)) - 1; + frame_cmmy = (int) roundf(z_stripf(height * 100.0f)) - 1; + mmx = (int) roundf(z_stripf(width)); + mmy = (int) roundf(z_stripf(height)); + micronx = (int) roundf(z_stripf(width * 1000.0f)); + microny = (int) roundf(z_stripf(height * 1000.0f)); } /* Header */ - out_le_u32(emr_header.type, 0x00000001); /* EMR_HEADER */ - out_le_u32(emr_header.size, 108); /* Including extensions */ - out_le_i32(emr_header.emf_header.bounds.left, 0); - out_le_i32(emr_header.emf_header.bounds.top, 0); - out_le_i32(emr_header.emf_header.bounds.right, sideways ? bounds_pxy : bounds_pxx); - out_le_i32(emr_header.emf_header.bounds.bottom, sideways ? bounds_pxx : bounds_pxy); - out_le_i32(emr_header.emf_header.frame.left, 0); - out_le_i32(emr_header.emf_header.frame.top, 0); - out_le_i32(emr_header.emf_header.frame.right, sideways ? frame_cmmy : frame_cmmx); - out_le_i32(emr_header.emf_header.frame.bottom, sideways ? frame_cmmx : frame_cmmy); - out_le_u32(emr_header.emf_header.record_signature, 0x464d4520); /* ENHMETA_SIGNATURE */ - out_le_u32(emr_header.emf_header.version, 0x00010000); - out_le_u16(emr_header.emf_header.handles, (fsize2 != 0.0f ? 5 : 4) + ih_ultra_offset); /* No. of graphics objs */ - out_le_u16(emr_header.emf_header.reserved, 0x0000); - out_le_u32(emr_header.emf_header.n_description, 0); - out_le_u32(emr_header.emf_header.off_description, 0); - out_le_u32(emr_header.emf_header.n_pal_entries, 0); - out_le_u32(emr_header.emf_header.device.cx, sideways ? device_pxy : device_pxx); - out_le_u32(emr_header.emf_header.device.cy, sideways ? device_pxx : device_pxy); - out_le_u32(emr_header.emf_header.millimeters.cx, sideways ? mmy : mmx); - out_le_u32(emr_header.emf_header.millimeters.cy, sideways ? mmx : mmy); + zint_out_le_u32(emr_header.type, 0x00000001); /* EMR_HEADER */ + zint_out_le_u32(emr_header.size, 108); /* Including extensions */ + zint_out_le_i32(emr_header.emf_header.bounds.left, 0); + zint_out_le_i32(emr_header.emf_header.bounds.top, 0); + zint_out_le_i32(emr_header.emf_header.bounds.right, sideways ? bounds_pxy : bounds_pxx); + zint_out_le_i32(emr_header.emf_header.bounds.bottom, sideways ? bounds_pxx : bounds_pxy); + zint_out_le_i32(emr_header.emf_header.frame.left, 0); + zint_out_le_i32(emr_header.emf_header.frame.top, 0); + zint_out_le_i32(emr_header.emf_header.frame.right, sideways ? frame_cmmy : frame_cmmx); + zint_out_le_i32(emr_header.emf_header.frame.bottom, sideways ? frame_cmmx : frame_cmmy); + zint_out_le_u32(emr_header.emf_header.record_signature, 0x464d4520); /* ENHMETA_SIGNATURE */ + zint_out_le_u32(emr_header.emf_header.version, 0x00010000); + /* No. of graphics objs */ + zint_out_le_u16(emr_header.emf_header.handles, (fsize2 != 0.0f ? 5 : 4) + ih_ultra_offset); + zint_out_le_u16(emr_header.emf_header.reserved, 0x0000); + zint_out_le_u32(emr_header.emf_header.n_description, 0); + zint_out_le_u32(emr_header.emf_header.off_description, 0); + zint_out_le_u32(emr_header.emf_header.n_pal_entries, 0); + zint_out_le_u32(emr_header.emf_header.device.cx, sideways ? device_pxy : device_pxx); + zint_out_le_u32(emr_header.emf_header.device.cy, sideways ? device_pxx : device_pxy); + zint_out_le_u32(emr_header.emf_header.millimeters.cx, sideways ? mmy : mmx); + zint_out_le_u32(emr_header.emf_header.millimeters.cy, sideways ? mmx : mmy); /* HeaderExtension1 */ - out_le_u32(emr_header.emf_header.cb_pixel_format, 0x0000); /* None set */ - out_le_u32(emr_header.emf_header.off_pixel_format, 0x0000); /* None set */ - out_le_u32(emr_header.emf_header.b_open_gl, 0x0000); /* OpenGL not present */ + zint_out_le_u32(emr_header.emf_header.cb_pixel_format, 0x0000); /* None set */ + zint_out_le_u32(emr_header.emf_header.off_pixel_format, 0x0000); /* None set */ + zint_out_le_u32(emr_header.emf_header.b_open_gl, 0x0000); /* OpenGL not present */ /* HeaderExtension2 */ - out_le_u32(emr_header.emf_header.micrometers.cx, sideways ? microny : micronx); - out_le_u32(emr_header.emf_header.micrometers.cy, sideways ? micronx : microny); + zint_out_le_u32(emr_header.emf_header.micrometers.cx, sideways ? microny : micronx); + zint_out_le_u32(emr_header.emf_header.micrometers.cy, sideways ? micronx : microny); bytecount = 108; recordcount = 1; - out_le_u32(emr_mapmode.type, 0x00000011); /* EMR_SETMAPMODE */ - out_le_u32(emr_mapmode.size, 12); - out_le_u32(emr_mapmode.mapmode, 0x01); /* MM_TEXT */ + zint_out_le_u32(emr_mapmode.type, 0x00000011); /* EMR_SETMAPMODE */ + zint_out_le_u32(emr_mapmode.size, 12); + zint_out_le_u32(emr_mapmode.mapmode, 0x01); /* MM_TEXT */ bytecount += 12; recordcount++; if (rotate_angle) { - out_le_u32(emr_setworldtransform.type, 0x00000023); /* EMR_SETWORLDTRANSFORM */ - out_le_u32(emr_setworldtransform.size, 32); - out_le_float(emr_setworldtransform.m11, rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? -1.0f : 0.0f); - out_le_float(emr_setworldtransform.m12, rotate_angle == 90 ? 1.0f : rotate_angle == 180 ? 0.0f : -1.0f); - out_le_float(emr_setworldtransform.m21, rotate_angle == 90 ? -1.0f : rotate_angle == 180 ? 0.0f : 1.0f); - out_le_float(emr_setworldtransform.m22, rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? -1.0f : 0.0f); - out_le_float(emr_setworldtransform.dx, rotate_angle == 90 ? height : rotate_angle == 180 ? width : 0.0f); - out_le_float(emr_setworldtransform.dy, rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? height : width); + zint_out_le_u32(emr_setworldtransform.type, 0x00000023); /* EMR_SETWORLDTRANSFORM */ + zint_out_le_u32(emr_setworldtransform.size, 32); + zint_out_le_float(emr_setworldtransform.m11, rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? -1.0f : 0.0f); + zint_out_le_float(emr_setworldtransform.m12, rotate_angle == 90 ? 1.0f : rotate_angle == 180 ? 0.0f : -1.0f); + zint_out_le_float(emr_setworldtransform.m21, rotate_angle == 90 ? -1.0f : rotate_angle == 180 ? 0.0f : 1.0f); + zint_out_le_float(emr_setworldtransform.m22, rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? -1.0f : 0.0f); + zint_out_le_float(emr_setworldtransform.dx, rotate_angle == 90 ? height : rotate_angle == 180 ? width : 0.0f); + zint_out_le_float(emr_setworldtransform.dy, rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? height : width); bytecount += 32; recordcount++; } /* Create Brushes */ - out_le_u32(emr_createbrushindirect_bg.type, 0x00000027); /* EMR_CREATEBRUSHINDIRECT */ - out_le_u32(emr_createbrushindirect_bg.size, 24); - out_le_u32(emr_createbrushindirect_bg.ih_brush, 0); - out_le_u32(emr_createbrushindirect_bg.log_brush.brush_style, 0x0000); /* BS_SOLID */ + zint_out_le_u32(emr_createbrushindirect_bg.type, 0x00000027); /* EMR_CREATEBRUSHINDIRECT */ + zint_out_le_u32(emr_createbrushindirect_bg.size, 24); + zint_out_le_u32(emr_createbrushindirect_bg.ih_brush, 0); + zint_out_le_u32(emr_createbrushindirect_bg.log_brush.brush_style, 0x0000); /* BS_SOLID */ emr_createbrushindirect_bg.log_brush.color.red = bgred; emr_createbrushindirect_bg.log_brush.color.green = bggrn; emr_createbrushindirect_bg.log_brush.color.blue = bgblu; emr_createbrushindirect_bg.log_brush.color.reserved = 0; - out_le_u32(emr_createbrushindirect_bg.log_brush.brush_hatch, 0x0006); /* HS_SOLIDCLR */ + zint_out_le_u32(emr_createbrushindirect_bg.log_brush.brush_hatch, 0x0006); /* HS_SOLIDCLR */ bytecount += 24; recordcount++; if (symbol->symbology == BARCODE_ULTRA) { static const unsigned char ultra_chars[9] = { '0', 'C', 'B', 'M', 'R', 'Y', 'G', 'K', 'W' }; for (i = 0; i < 9; i++) { - out_le_u32(emr_createbrushindirect_colour[i].type, 0x00000027); /* EMR_CREATEBRUSHINDIRECT */ - out_le_u32(emr_createbrushindirect_colour[i].size, 24); - out_le_u32(emr_createbrushindirect_colour[i].ih_brush, 1 + i); - out_le_u32(emr_createbrushindirect_colour[i].log_brush.brush_style, 0x0000); /* BS_SOLID */ + zint_out_le_u32(emr_createbrushindirect_colour[i].type, 0x00000027); /* EMR_CREATEBRUSHINDIRECT */ + zint_out_le_u32(emr_createbrushindirect_colour[i].size, 24); + zint_out_le_u32(emr_createbrushindirect_colour[i].ih_brush, 1 + i); + zint_out_le_u32(emr_createbrushindirect_colour[i].log_brush.brush_style, 0x0000); /* BS_SOLID */ if (i == 0) { emr_createbrushindirect_colour[i].log_brush.color.red = fgred; emr_createbrushindirect_colour[i].log_brush.color.green = fggrn; emr_createbrushindirect_colour[i].log_brush.color.blue = fgblu; } else { - out_colour_char_to_rgb(ultra_chars[i], + zint_out_colour_char_to_rgb(ultra_chars[i], &emr_createbrushindirect_colour[i].log_brush.color.red, &emr_createbrushindirect_colour[i].log_brush.color.green, &emr_createbrushindirect_colour[i].log_brush.color.blue); } emr_createbrushindirect_colour[i].log_brush.color.reserved = 0; - out_le_u32(emr_createbrushindirect_colour[i].log_brush.brush_hatch, 0x0006); /* HS_SOLIDCLR */ + zint_out_le_u32(emr_createbrushindirect_colour[i].log_brush.brush_hatch, 0x0006); /* HS_SOLIDCLR */ } bytecount += colours_used * 24; recordcount += colours_used; } else { - out_le_u32(emr_createbrushindirect_fg.type, 0x00000027); /* EMR_CREATEBRUSHINDIRECT */ - out_le_u32(emr_createbrushindirect_fg.size, 24); - out_le_u32(emr_createbrushindirect_fg.ih_brush, 1); - out_le_u32(emr_createbrushindirect_fg.log_brush.brush_style, 0x0000); /* BS_SOLID */ + zint_out_le_u32(emr_createbrushindirect_fg.type, 0x00000027); /* EMR_CREATEBRUSHINDIRECT */ + zint_out_le_u32(emr_createbrushindirect_fg.size, 24); + zint_out_le_u32(emr_createbrushindirect_fg.ih_brush, 1); + zint_out_le_u32(emr_createbrushindirect_fg.log_brush.brush_style, 0x0000); /* BS_SOLID */ emr_createbrushindirect_fg.log_brush.color.red = fgred; emr_createbrushindirect_fg.log_brush.color.green = fggrn; emr_createbrushindirect_fg.log_brush.color.blue = fgblu; emr_createbrushindirect_fg.log_brush.color.reserved = 0; - out_le_u32(emr_createbrushindirect_fg.log_brush.brush_hatch, 0x0006); /* HS_SOLIDCLR */ + zint_out_le_u32(emr_createbrushindirect_fg.log_brush.brush_hatch, 0x0006); /* HS_SOLIDCLR */ bytecount += 24; recordcount++; } - out_le_u32(emr_selectobject_bgbrush.type, 0x00000025); /* EMR_SELECTOBJECT */ - out_le_u32(emr_selectobject_bgbrush.size, 12); + zint_out_le_u32(emr_selectobject_bgbrush.type, 0x00000025); /* EMR_SELECTOBJECT */ + zint_out_le_u32(emr_selectobject_bgbrush.size, 12); emr_selectobject_bgbrush.ih_object = emr_createbrushindirect_bg.ih_brush; bytecount += 12; recordcount++; if (symbol->symbology == BARCODE_ULTRA) { for (i = 0; i < 9; i++) { - out_le_u32(emr_selectobject_colour[i].type, 0x00000025); /* EMR_SELECTOBJECT */ - out_le_u32(emr_selectobject_colour[i].size, 12); + zint_out_le_u32(emr_selectobject_colour[i].type, 0x00000025); /* EMR_SELECTOBJECT */ + zint_out_le_u32(emr_selectobject_colour[i].size, 12); emr_selectobject_colour[i].ih_object = emr_createbrushindirect_colour[i].ih_brush; } bytecount += colours_used * 12; recordcount += colours_used; } else { - out_le_u32(emr_selectobject_fgbrush.type, 0x00000025); /* EMR_SELECTOBJECT */ - out_le_u32(emr_selectobject_fgbrush.size, 12); + zint_out_le_u32(emr_selectobject_fgbrush.type, 0x00000025); /* EMR_SELECTOBJECT */ + zint_out_le_u32(emr_selectobject_fgbrush.size, 12); emr_selectobject_fgbrush.ih_object = emr_createbrushindirect_fg.ih_brush; bytecount += 12; recordcount++; } /* Create Pens */ - out_le_u32(emr_createpen.type, 0x00000026); /* EMR_CREATEPEN */ - out_le_u32(emr_createpen.size, 28); - out_le_u32(emr_createpen.ih_pen, 2 + ih_ultra_offset); - out_le_u32(emr_createpen.log_pen.pen_style, 0x00000005); /* PS_NULL */ - out_le_i32(emr_createpen.log_pen.width.x, 1); - out_le_i32(emr_createpen.log_pen.width.y, 0); /* ignored */ + zint_out_le_u32(emr_createpen.type, 0x00000026); /* EMR_CREATEPEN */ + zint_out_le_u32(emr_createpen.size, 28); + zint_out_le_u32(emr_createpen.ih_pen, 2 + ih_ultra_offset); + zint_out_le_u32(emr_createpen.log_pen.pen_style, 0x00000005); /* PS_NULL */ + zint_out_le_i32(emr_createpen.log_pen.width.x, 1); + zint_out_le_i32(emr_createpen.log_pen.width.y, 0); /* ignored */ emr_createpen.log_pen.color_ref.red = 0; emr_createpen.log_pen.color_ref.green = 0; emr_createpen.log_pen.color_ref.blue = 0; @@ -438,20 +439,20 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { bytecount += 28; recordcount++; - out_le_u32(emr_selectobject_pen.type, 0x00000025); /* EMR_SELECTOBJECT */ - out_le_u32(emr_selectobject_pen.size, 12); + zint_out_le_u32(emr_selectobject_pen.type, 0x00000025); /* EMR_SELECTOBJECT */ + zint_out_le_u32(emr_selectobject_pen.size, 12); emr_selectobject_pen.ih_object = emr_createpen.ih_pen; bytecount += 12; recordcount++; if (draw_background) { /* Make background from a rectangle */ - out_le_u32(background.type, 0x0000002b); /* EMR_RECTANGLE */ - out_le_u32(background.size, 24); - out_le_i32(background.box.top, 0); - out_le_i32(background.box.left, 0); - out_le_i32(background.box.right, width); - out_le_i32(background.box.bottom, height); + zint_out_le_u32(background.type, 0x0000002b); /* EMR_RECTANGLE */ + zint_out_le_u32(background.size, 24); + zint_out_le_i32(background.box.top, 0); + zint_out_le_i32(background.box.left, 0); + zint_out_le_i32(background.box.right, width); + zint_out_le_i32(background.box.bottom, height); bytecount += 24; recordcount++; } @@ -460,12 +461,12 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { rect = symbol->vector->rectangles; this_rectangle = 0; while (rect) { - out_le_u32(rectangle[this_rectangle].type, 0x0000002b); /* EMR_RECTANGLE */ - out_le_u32(rectangle[this_rectangle].size, 24); - out_le_i32(rectangle[this_rectangle].box.top, rect->y); - out_le_i32(rectangle[this_rectangle].box.bottom, stripf(rect->y + rect->height)); - out_le_i32(rectangle[this_rectangle].box.left, rect->x); - out_le_i32(rectangle[this_rectangle].box.right, stripf(rect->x + rect->width)); + zint_out_le_u32(rectangle[this_rectangle].type, 0x0000002b); /* EMR_RECTANGLE */ + zint_out_le_u32(rectangle[this_rectangle].size, 24); + zint_out_le_i32(rectangle[this_rectangle].box.top, rect->y); + zint_out_le_i32(rectangle[this_rectangle].box.bottom, z_stripf(rect->y + rect->height)); + zint_out_le_i32(rectangle[this_rectangle].box.left, rect->x); + zint_out_le_i32(rectangle[this_rectangle].box.right, z_stripf(rect->x + rect->width)); this_rectangle++; bytecount += 24; recordcount++; @@ -483,24 +484,24 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { previous_diameter = circ->diameter + circ->width; radius = emf_mul3dpf(0.5f, previous_diameter); } - out_le_u32(circle[this_circle].type, 0x0000002a); /* EMR_ELLIPSE */ - out_le_u32(circle[this_circle].size, 24); - out_le_i32(circle[this_circle].box.top, stripf(circ->y - radius)); - out_le_i32(circle[this_circle].box.bottom, stripf(circ->y + radius)); - out_le_i32(circle[this_circle].box.left, stripf(circ->x - radius)); - out_le_i32(circle[this_circle].box.right, stripf(circ->x + radius)); + zint_out_le_u32(circle[this_circle].type, 0x0000002a); /* EMR_ELLIPSE */ + zint_out_le_u32(circle[this_circle].size, 24); + zint_out_le_i32(circle[this_circle].box.top, z_stripf(circ->y - radius)); + zint_out_le_i32(circle[this_circle].box.bottom, z_stripf(circ->y + radius)); + zint_out_le_i32(circle[this_circle].box.left, z_stripf(circ->x - radius)); + zint_out_le_i32(circle[this_circle].box.right, z_stripf(circ->x + radius)); this_circle++; bytecount += 24; recordcount++; if (symbol->symbology == BARCODE_MAXICODE) { /* Drawing MaxiCode bullseye using overlayed discs */ float inner_radius = radius - circ->width; - out_le_u32(circle[this_circle].type, 0x0000002a); /* EMR_ELLIPSE */ - out_le_u32(circle[this_circle].size, 24); - out_le_i32(circle[this_circle].box.top, stripf(circ->y - inner_radius)); - out_le_i32(circle[this_circle].box.bottom, stripf(circ->y + inner_radius)); - out_le_i32(circle[this_circle].box.left, stripf(circ->x - inner_radius)); - out_le_i32(circle[this_circle].box.right, stripf(circ->x + inner_radius)); + zint_out_le_u32(circle[this_circle].type, 0x0000002a); /* EMR_ELLIPSE */ + zint_out_le_u32(circle[this_circle].size, 24); + zint_out_le_i32(circle[this_circle].box.top, z_stripf(circ->y - inner_radius)); + zint_out_le_i32(circle[this_circle].box.bottom, z_stripf(circ->y + inner_radius)); + zint_out_le_i32(circle[this_circle].box.left, z_stripf(circ->x - inner_radius)); + zint_out_le_i32(circle[this_circle].box.right, z_stripf(circ->x + inner_radius)); this_circle++; bytecount += 24; recordcount++; @@ -514,9 +515,9 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { hex = symbol->vector->hexagons; this_hexagon = 0; while (hex) { - out_le_u32(hexagon[this_hexagon].type, 0x00000003); /* EMR_POLYGON */ - out_le_u32(hexagon[this_hexagon].size, 76); - out_le_u32(hexagon[this_hexagon].count, 6); + zint_out_le_u32(hexagon[this_hexagon].type, 0x00000003); /* EMR_POLYGON */ + zint_out_le_u32(hexagon[this_hexagon].size, 76); + zint_out_le_u32(hexagon[this_hexagon].count, 6); if (previous_diameter != hex->diameter) { previous_diameter = hex->diameter; @@ -526,18 +527,18 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { } /* Note rotation done via world transform */ - out_le_i32(hexagon[this_hexagon].a_points_a.x, hex->x); - out_le_i32(hexagon[this_hexagon].a_points_a.y, stripf(hex->y + radius)); - out_le_i32(hexagon[this_hexagon].a_points_b.x, stripf(hex->x + half_sqrt3_radius)); - out_le_i32(hexagon[this_hexagon].a_points_b.y, stripf(hex->y + half_radius)); - out_le_i32(hexagon[this_hexagon].a_points_c.x, stripf(hex->x + half_sqrt3_radius)); - out_le_i32(hexagon[this_hexagon].a_points_c.y, stripf(hex->y - half_radius)); - out_le_i32(hexagon[this_hexagon].a_points_d.x, hex->x); - out_le_i32(hexagon[this_hexagon].a_points_d.y, stripf(hex->y - radius)); - out_le_i32(hexagon[this_hexagon].a_points_e.x, stripf(hex->x - half_sqrt3_radius)); - out_le_i32(hexagon[this_hexagon].a_points_e.y, stripf(hex->y - half_radius)); - out_le_i32(hexagon[this_hexagon].a_points_f.x, stripf(hex->x - half_sqrt3_radius)); - out_le_i32(hexagon[this_hexagon].a_points_f.y, stripf(hex->y + half_radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_a.x, hex->x); + zint_out_le_i32(hexagon[this_hexagon].a_points_a.y, z_stripf(hex->y + radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_b.x, z_stripf(hex->x + half_sqrt3_radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_b.y, z_stripf(hex->y + half_radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_c.x, z_stripf(hex->x + half_sqrt3_radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_c.y, z_stripf(hex->y - half_radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_d.x, hex->x); + zint_out_le_i32(hexagon[this_hexagon].a_points_d.y, z_stripf(hex->y - radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_e.x, z_stripf(hex->x - half_sqrt3_radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_e.y, z_stripf(hex->y - half_radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_f.x, z_stripf(hex->x - half_sqrt3_radius)); + zint_out_le_i32(hexagon[this_hexagon].a_points_f.y, z_stripf(hex->y + half_radius)); hexagon[this_hexagon].bounds.top = hexagon[this_hexagon].a_points_d.y; hexagon[this_hexagon].bounds.bottom = hexagon[this_hexagon].a_points_a.y; @@ -551,14 +552,14 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { /* Create font records, alignment records and text color */ if (symbol->vector->strings) { - bold = (symbol->output_options & BOLD_TEXT) && !is_upcean(symbol->symbology); + bold = (symbol->output_options & BOLD_TEXT) && !z_is_upcean(symbol->symbology); memset(&emr_extcreatefontindirectw, 0, sizeof(emr_extcreatefontindirectw)); - out_le_u32(emr_extcreatefontindirectw.type, 0x00000052); /* EMR_EXTCREATEFONTINDIRECTW */ - out_le_u32(emr_extcreatefontindirectw.size, 104); - out_le_u32(emr_extcreatefontindirectw.ih_fonts, 3 + ih_ultra_offset); - out_le_i32(emr_extcreatefontindirectw.elw.height, fsize); - out_le_i32(emr_extcreatefontindirectw.elw.width, 0); /* automatic */ - out_le_i32(emr_extcreatefontindirectw.elw.weight, bold ? 700 : 400); + zint_out_le_u32(emr_extcreatefontindirectw.type, 0x00000052); /* EMR_EXTCREATEFONTINDIRECTW */ + zint_out_le_u32(emr_extcreatefontindirectw.size, 104); + zint_out_le_u32(emr_extcreatefontindirectw.ih_fonts, 3 + ih_ultra_offset); + zint_out_le_i32(emr_extcreatefontindirectw.elw.height, fsize); + zint_out_le_i32(emr_extcreatefontindirectw.elw.width, 0); /* automatic */ + zint_out_le_i32(emr_extcreatefontindirectw.elw.weight, bold ? 700 : 400); emr_extcreatefontindirectw.elw.char_set = 0x00; /* ANSI_CHARSET */ emr_extcreatefontindirectw.elw.out_precision = 0x00; /* OUT_DEFAULT_PRECIS */ emr_extcreatefontindirectw.elw.clip_precision = 0x00; /* CLIP_DEFAULT_PRECIS */ @@ -567,21 +568,21 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { bytecount += 104; recordcount++; - out_le_u32(emr_selectobject_font.type, 0x00000025); /* EMR_SELECTOBJECT */ - out_le_u32(emr_selectobject_font.size, 12); + zint_out_le_u32(emr_selectobject_font.type, 0x00000025); /* EMR_SELECTOBJECT */ + zint_out_le_u32(emr_selectobject_font.size, 12); emr_selectobject_font.ih_object = emr_extcreatefontindirectw.ih_fonts; bytecount += 12; recordcount++; if (fsize2) { memcpy(&emr_extcreatefontindirectw2, &emr_extcreatefontindirectw, sizeof(emr_extcreatefontindirectw)); - out_le_u32(emr_extcreatefontindirectw2.ih_fonts, 4 + ih_ultra_offset); - out_le_i32(emr_extcreatefontindirectw2.elw.height, fsize2); + zint_out_le_u32(emr_extcreatefontindirectw2.ih_fonts, 4 + ih_ultra_offset); + zint_out_le_i32(emr_extcreatefontindirectw2.elw.height, fsize2); bytecount += 104; recordcount++; - out_le_u32(emr_selectobject_font2.type, 0x00000025); /* EMR_SELECTOBJECT */ - out_le_u32(emr_selectobject_font2.size, 12); + zint_out_le_u32(emr_selectobject_font2.type, 0x00000025); /* EMR_SELECTOBJECT */ + zint_out_le_u32(emr_selectobject_font2.size, 12); emr_selectobject_font2.ih_object = emr_extcreatefontindirectw2.ih_fonts; bytecount += 12; recordcount++; @@ -589,22 +590,22 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { /* Note select aligns counted below in strings loop */ - out_le_u32(emr_settextalign_centre.type, 0x00000016); /* EMR_SETTEXTALIGN */ - out_le_u32(emr_settextalign_centre.size, 12); - out_le_u32(emr_settextalign_centre.text_alignment_mode, 0x0006 | 0x0018); /* TA_CENTER | TA_BASELINE */ + zint_out_le_u32(emr_settextalign_centre.type, 0x00000016); /* EMR_SETTEXTALIGN */ + zint_out_le_u32(emr_settextalign_centre.size, 12); + zint_out_le_u32(emr_settextalign_centre.text_alignment_mode, 0x0006 | 0x0018); /* TA_CENTER | TA_BASELINE */ if (halign_left) { - out_le_u32(emr_settextalign_left.type, 0x00000016); /* EMR_SETTEXTALIGN */ - out_le_u32(emr_settextalign_left.size, 12); - out_le_u32(emr_settextalign_left.text_alignment_mode, 0x0000 | 0x0018); /* TA_LEFT | TA_BASELINE */ + zint_out_le_u32(emr_settextalign_left.type, 0x00000016); /* EMR_SETTEXTALIGN */ + zint_out_le_u32(emr_settextalign_left.size, 12); + zint_out_le_u32(emr_settextalign_left.text_alignment_mode, 0x0000 | 0x0018); /* TA_LEFT | TA_BASELINE */ } if (halign_right) { - out_le_u32(emr_settextalign_right.type, 0x00000016); /* EMR_SETTEXTALIGN */ - out_le_u32(emr_settextalign_right.size, 12); - out_le_u32(emr_settextalign_right.text_alignment_mode, 0x0002 | 0x0018); /* TA_RIGHT | TA_BASELINE */ + zint_out_le_u32(emr_settextalign_right.type, 0x00000016); /* EMR_SETTEXTALIGN */ + zint_out_le_u32(emr_settextalign_right.size, 12); + zint_out_le_u32(emr_settextalign_right.text_alignment_mode, 0x0002 | 0x0018); /* TA_RIGHT | TA_BASELINE */ } - out_le_u32(emr_settextcolor.type, 0x0000018); /* EMR_SETTEXTCOLOR */ - out_le_u32(emr_settextcolor.size, 12); + zint_out_le_u32(emr_settextcolor.type, 0x0000018); /* EMR_SETTEXTCOLOR */ + zint_out_le_u32(emr_settextcolor.size, 12); emr_settextcolor.color.red = fgred; emr_settextcolor.color.green = fggrn; emr_settextcolor.color.blue = fgblu; @@ -639,37 +640,37 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { for (i = 0; i < this_text; i++) { free(this_string[i]); } - return errtxt(ZINT_ERROR_MEMORY, symbol, 641, "Insufficient memory for EMF string buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 641, "Insufficient memory for EMF string buffer"); } memset(this_string[this_text], 0, text_bumped_lens[this_text]); - out_le_u32(text[this_text].type, 0x00000054); /* EMR_EXTTEXTOUTW */ - out_le_u32(text[this_text].size, 76 + text_bumped_lens[this_text]); - out_le_i32(text[this_text].bounds.top, 0); /* ignored */ - out_le_i32(text[this_text].bounds.left, 0); /* ignored */ - out_le_i32(text[this_text].bounds.right, 0xffffffff); /* ignored */ - out_le_i32(text[this_text].bounds.bottom, 0xffffffff); /* ignored */ - out_le_u32(text[this_text].i_graphics_mode, 0x00000002); /* GM_ADVANCED */ - out_le_float(text[this_text].ex_scale, 1.0f); - out_le_float(text[this_text].ey_scale, 1.0f); + zint_out_le_u32(text[this_text].type, 0x00000054); /* EMR_EXTTEXTOUTW */ + zint_out_le_u32(text[this_text].size, 76 + text_bumped_lens[this_text]); + zint_out_le_i32(text[this_text].bounds.top, 0); /* ignored */ + zint_out_le_i32(text[this_text].bounds.left, 0); /* ignored */ + zint_out_le_i32(text[this_text].bounds.right, 0xffffffff); /* ignored */ + zint_out_le_i32(text[this_text].bounds.bottom, 0xffffffff); /* ignored */ + zint_out_le_u32(text[this_text].i_graphics_mode, 0x00000002); /* GM_ADVANCED */ + zint_out_le_float(text[this_text].ex_scale, 1.0f); + zint_out_le_float(text[this_text].ey_scale, 1.0f); /* Unhack the guard whitespace `gws_left_fudge`/`gws_right_fudge` hack */ - if (upcean && string->halign == 1 && string->text[0] == '<') { + if (is_upcean && string->halign == 1 && string->text[0] == '<') { const float gws_left_fudge = symbol->scale < 0.1f ? 0.1f : symbol->scale; /* 0.5 * 2 * scale */ - out_le_i32(text[this_text].w_emr_text.reference.x, string->x + gws_left_fudge); - } else if (upcean && string->halign == 2 && string->text[0] == '>') { + zint_out_le_i32(text[this_text].w_emr_text.reference.x, string->x + gws_left_fudge); + } else if (is_upcean && string->halign == 2 && string->text[0] == '>') { const float gws_right_fudge = symbol->scale < 0.1f ? 0.1f : symbol->scale; /* 0.5 * 2 * scale */ - out_le_i32(text[this_text].w_emr_text.reference.x, string->x - gws_right_fudge); + zint_out_le_i32(text[this_text].w_emr_text.reference.x, string->x - gws_right_fudge); } else { - out_le_i32(text[this_text].w_emr_text.reference.x, string->x); + zint_out_le_i32(text[this_text].w_emr_text.reference.x, string->x); } - out_le_i32(text[this_text].w_emr_text.reference.y, string->y); - out_le_u32(text[this_text].w_emr_text.chars, utfle_len); - out_le_u32(text[this_text].w_emr_text.off_string, 76); - out_le_u32(text[this_text].w_emr_text.options, 0); - out_le_i32(text[this_text].w_emr_text.rectangle.top, 0); - out_le_i32(text[this_text].w_emr_text.rectangle.left, 0); - out_le_i32(text[this_text].w_emr_text.rectangle.right, 0xffffffff); - out_le_i32(text[this_text].w_emr_text.rectangle.bottom, 0xffffffff); - out_le_u32(text[this_text].w_emr_text.off_dx, 0); + zint_out_le_i32(text[this_text].w_emr_text.reference.y, string->y); + zint_out_le_u32(text[this_text].w_emr_text.chars, utfle_len); + zint_out_le_u32(text[this_text].w_emr_text.off_string, 76); + zint_out_le_u32(text[this_text].w_emr_text.options, 0); + zint_out_le_i32(text[this_text].w_emr_text.rectangle.top, 0); + zint_out_le_i32(text[this_text].w_emr_text.rectangle.left, 0); + zint_out_le_i32(text[this_text].w_emr_text.rectangle.right, 0xffffffff); + zint_out_le_i32(text[this_text].w_emr_text.rectangle.bottom, 0xffffffff); + zint_out_le_u32(text[this_text].w_emr_text.off_dx, 0); emf_utfle_copy(this_string[this_text], string->text, string->length); bytecount += 76 + text_bumped_lens[this_text]; recordcount++; @@ -682,10 +683,10 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { assert(this_text == string_count); /* Create EOF record */ - out_le_u32(emr_eof.type, 0x0000000e); /* EMR_EOF */ - out_le_u32(emr_eof.size, 20); /* Assuming no palette entries */ - out_le_u32(emr_eof.n_pal_entries, 0); - out_le_u32(emr_eof.off_pal_entries, 0); + zint_out_le_u32(emr_eof.type, 0x0000000e); /* EMR_EOF */ + zint_out_le_u32(emr_eof.size, 20); /* Assuming no palette entries */ + zint_out_le_u32(emr_eof.n_pal_entries, 0); + zint_out_le_u32(emr_eof.off_pal_entries, 0); emr_eof.size_last = emr_eof.size; bytecount += 20; recordcount++; @@ -696,60 +697,60 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { } /* Put final counts in header */ - out_le_u32(emr_header.emf_header.bytes, bytecount); - out_le_u32(emr_header.emf_header.records, recordcount); + zint_out_le_u32(emr_header.emf_header.bytes, bytecount); + zint_out_le_u32(emr_header.emf_header.records, recordcount); /* Send EMF data to file */ - if (!fm_open(fmp, symbol, "wb")) { - return ZEXT errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 640, "Could not open EMF output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_open(fmp, symbol, "wb")) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 640, "Could not open EMF output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } - fm_write(&emr_header, sizeof(emr_header_t), 1, fmp); + zint_fm_write(&emr_header, sizeof(emr_header_t), 1, fmp); - fm_write(&emr_mapmode, sizeof(emr_mapmode_t), 1, fmp); + zint_fm_write(&emr_mapmode, sizeof(emr_mapmode_t), 1, fmp); if (rotate_angle) { - fm_write(&emr_setworldtransform, sizeof(emr_setworldtransform_t), 1, fmp); + zint_fm_write(&emr_setworldtransform, sizeof(emr_setworldtransform_t), 1, fmp); } - fm_write(&emr_createbrushindirect_bg, sizeof(emr_createbrushindirect_t), 1, fmp); + zint_fm_write(&emr_createbrushindirect_bg, sizeof(emr_createbrushindirect_t), 1, fmp); if (symbol->symbology == BARCODE_ULTRA) { for (i = 0; i < 9; i++) { if (rectangle_bycolour[i]) { - fm_write(&emr_createbrushindirect_colour[i], sizeof(emr_createbrushindirect_t), 1, fmp); + zint_fm_write(&emr_createbrushindirect_colour[i], sizeof(emr_createbrushindirect_t), 1, fmp); } } } else { - fm_write(&emr_createbrushindirect_fg, sizeof(emr_createbrushindirect_t), 1, fmp); + zint_fm_write(&emr_createbrushindirect_fg, sizeof(emr_createbrushindirect_t), 1, fmp); } - fm_write(&emr_createpen, sizeof(emr_createpen_t), 1, fmp); + zint_fm_write(&emr_createpen, sizeof(emr_createpen_t), 1, fmp); if (symbol->vector->strings) { - fm_write(&emr_extcreatefontindirectw, sizeof(emr_extcreatefontindirectw_t), 1, fmp); + zint_fm_write(&emr_extcreatefontindirectw, sizeof(emr_extcreatefontindirectw_t), 1, fmp); if (fsize2) { - fm_write(&emr_extcreatefontindirectw2, sizeof(emr_extcreatefontindirectw_t), 1, fmp); + zint_fm_write(&emr_extcreatefontindirectw2, sizeof(emr_extcreatefontindirectw_t), 1, fmp); } } - fm_write(&emr_selectobject_bgbrush, sizeof(emr_selectobject_t), 1, fmp); - fm_write(&emr_selectobject_pen, sizeof(emr_selectobject_t), 1, fmp); + zint_fm_write(&emr_selectobject_bgbrush, sizeof(emr_selectobject_t), 1, fmp); + zint_fm_write(&emr_selectobject_pen, sizeof(emr_selectobject_t), 1, fmp); if (draw_background) { - fm_write(&background, sizeof(emr_rectangle_t), 1, fmp); + zint_fm_write(&background, sizeof(emr_rectangle_t), 1, fmp); } if (symbol->symbology == BARCODE_ULTRA) { for (i = 0; i < 9; i++) { if (rectangle_bycolour[i]) { - fm_write(&emr_selectobject_colour[i], sizeof(emr_selectobject_t), 1, fmp); + zint_fm_write(&emr_selectobject_colour[i], sizeof(emr_selectobject_t), 1, fmp); rect = symbol->vector->rectangles; this_rectangle = 0; while (rect) { if ((i == 0 && rect->colour == -1) || rect->colour == i) { - fm_write(&rectangle[this_rectangle], sizeof(emr_rectangle_t), 1, fmp); + zint_fm_write(&rectangle[this_rectangle], sizeof(emr_rectangle_t), 1, fmp); } this_rectangle++; rect = rect->next; @@ -757,42 +758,42 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { } } } else { - fm_write(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, fmp); + zint_fm_write(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, fmp); /* Rectangles */ for (i = 0; i < rectangle_count; i++) { - fm_write(&rectangle[i], sizeof(emr_rectangle_t), 1, fmp); + zint_fm_write(&rectangle[i], sizeof(emr_rectangle_t), 1, fmp); } } /* Hexagons */ for (i = 0; i < hexagon_count; i++) { - fm_write(&hexagon[i], sizeof(emr_polygon_t), 1, fmp); + zint_fm_write(&hexagon[i], sizeof(emr_polygon_t), 1, fmp); } /* Circles */ if (symbol->symbology == BARCODE_MAXICODE) { /* Bullseye needed */ for (i = 0; i < circle_count; i++) { - fm_write(&circle[i], sizeof(emr_ellipse_t), 1, fmp); + zint_fm_write(&circle[i], sizeof(emr_ellipse_t), 1, fmp); if (i < circle_count - 1) { if (i % 2) { - fm_write(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, fmp); + zint_fm_write(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, fmp); } else { - fm_write(&emr_selectobject_bgbrush, sizeof(emr_selectobject_t), 1, fmp); + zint_fm_write(&emr_selectobject_bgbrush, sizeof(emr_selectobject_t), 1, fmp); } } } } else { for (i = 0; i < circle_count; i++) { - fm_write(&circle[i], sizeof(emr_ellipse_t), 1, fmp); + zint_fm_write(&circle[i], sizeof(emr_ellipse_t), 1, fmp); } } /* Text */ if (string_count > 0) { - fm_write(&emr_selectobject_font, sizeof(emr_selectobject_t), 1, fmp); - fm_write(&emr_settextcolor, sizeof(emr_settextcolor_t), 1, fmp); + zint_fm_write(&emr_selectobject_font, sizeof(emr_selectobject_t), 1, fmp); + zint_fm_write(&emr_settextcolor, sizeof(emr_settextcolor_t), 1, fmp); } current_fsize = fsize; @@ -800,34 +801,34 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) { for (i = 0; i < string_count; i++) { if (text_fsizes[i] != current_fsize) { current_fsize = text_fsizes[i]; - fm_write(&emr_selectobject_font2, sizeof(emr_selectobject_t), 1, fmp); + zint_fm_write(&emr_selectobject_font2, sizeof(emr_selectobject_t), 1, fmp); } if (text_haligns[i] != current_halign) { current_halign = text_haligns[i]; if (current_halign == 0) { - fm_write(&emr_settextalign_centre, sizeof(emr_settextalign_t), 1, fmp); + zint_fm_write(&emr_settextalign_centre, sizeof(emr_settextalign_t), 1, fmp); } else if (current_halign == 1) { - fm_write(&emr_settextalign_left, sizeof(emr_settextalign_t), 1, fmp); + zint_fm_write(&emr_settextalign_left, sizeof(emr_settextalign_t), 1, fmp); } else { - fm_write(&emr_settextalign_right, sizeof(emr_settextalign_t), 1, fmp); + zint_fm_write(&emr_settextalign_right, sizeof(emr_settextalign_t), 1, fmp); } } - fm_write(&text[i], sizeof(emr_exttextoutw_t), 1, fmp); - fm_write(this_string[i], text_bumped_lens[i], 1, fmp); + zint_fm_write(&text[i], sizeof(emr_exttextoutw_t), 1, fmp); + zint_fm_write(this_string[i], text_bumped_lens[i], 1, fmp); free(this_string[i]); } - fm_write(&emr_eof, sizeof(emr_eof_t), 1, fmp); + zint_fm_write(&emr_eof, sizeof(emr_eof_t), 1, fmp); - if (fm_error(fmp)) { - ZEXT errtxtf(0, symbol, 644, "Incomplete write of EMF output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); - (void) fm_close(fmp, symbol); + if (zint_fm_error(fmp)) { + ZEXT z_errtxtf(0, symbol, 644, "Incomplete write of EMF output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); + (void) zint_fm_close(fmp, symbol); return ZINT_ERROR_FILE_WRITE; } - if (!fm_close(fmp, symbol)) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 941, "Failure on closing EMF output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_close(fmp, symbol)) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 941, "Failure on closing EMF output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } return error_number; } diff --git a/backend/filemem.c b/backend/filemem.c index 1f408e87..5ce112f1 100644 --- a/backend/filemem.c +++ b/backend/filemem.c @@ -93,7 +93,7 @@ static void fm_clear_mem(struct filemem *restrict const fmp) { } /* `fopen()` if file, setup memory buffer if BARCODE_MEMORY_FILE, returning 1 on success, 0 on failure */ -INTERNAL int fm_open(struct filemem *restrict const fmp, struct zint_symbol *symbol, const char *mode) { +INTERNAL int zint_fm_open(struct filemem *restrict const fmp, struct zint_symbol *symbol, const char *mode) { assert(fmp && symbol && mode); fmp->fp = NULL; fmp->mem = NULL; @@ -128,7 +128,7 @@ INTERNAL int fm_open(struct filemem *restrict const fmp, struct zint_symbol *sym fmp->fp = stdout; return 1; } - if (!(fmp->fp = out_fopen(symbol->outfile, mode))) { + if (!(fmp->fp = zint_out_fopen(symbol->outfile, mode))) { return fm_seterr(fmp, errno); } return 1; @@ -172,7 +172,7 @@ static int fm_mem_expand(struct filemem *restrict const fmp, const size_t size) } /* `fwrite()` to file or memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_write(const void *restrict ptr, const size_t size, const size_t nitems, +INTERNAL int zint_fm_write(const void *restrict ptr, const size_t size, const size_t nitems, struct filemem *restrict const fmp) { assert(fmp && ptr); if (fmp->err) { @@ -200,7 +200,7 @@ INTERNAL int fm_write(const void *restrict ptr, const size_t size, const size_t } /* `fputc()` to file or memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_putc(const int ch, struct filemem *restrict const fmp) { +INTERNAL int zint_fm_putc(const int ch, struct filemem *restrict const fmp) { assert(fmp); if (fmp->err) { return 0; @@ -220,7 +220,7 @@ INTERNAL int fm_putc(const int ch, struct filemem *restrict const fmp) { } /* `fputs()` to file or memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_puts(const char *str, struct filemem *restrict const fmp) { +INTERNAL int zint_fm_puts(const char *str, struct filemem *restrict const fmp) { assert(fmp); if (fmp->err) { return 0; @@ -294,7 +294,7 @@ static int fm_vprintf(struct filemem *restrict const fmp, const char *fmt, va_li } /* `fprintf()` to file or memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_printf(struct filemem *restrict const fmp, const char *fmt, ...) { +INTERNAL int zint_fm_printf(struct filemem *restrict const fmp, const char *fmt, ...) { va_list ap; int ret; @@ -316,7 +316,7 @@ INTERNAL int fm_printf(struct filemem *restrict const fmp, const char *fmt, ...) /* Output float without trailing zeroes to `fmp` with decimal pts `dp` (precision), returning 1 on success, 0 on failure */ -INTERNAL int fm_putsf(const char *prefix, const int dp, const float arg, struct filemem *restrict const fmp) { +INTERNAL int zint_fm_putsf(const char *prefix, const int dp, const float arg, struct filemem *restrict const fmp) { int i, end; char buf[256]; /* Assuming `dp` reasonable */ const int len = sprintf(buf, "%.*f", dp, arg); @@ -326,7 +326,7 @@ INTERNAL int fm_putsf(const char *prefix, const int dp, const float arg, struct return 0; } if (prefix && *prefix) { - if (!fm_puts(prefix, fmp)) { + if (!zint_fm_puts(prefix, fmp)) { return 0; } } @@ -348,12 +348,12 @@ INTERNAL int fm_putsf(const char *prefix, const int dp, const float arg, struct } } - return fm_puts(buf, fmp); + return zint_fm_puts(buf, fmp); } /* `fclose()` if file, set `symbol->memfile` & `symbol->memfile_size` if memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_close(struct filemem *restrict const fmp, struct zint_symbol *symbol) { +INTERNAL int zint_fm_close(struct filemem *restrict const fmp, struct zint_symbol *symbol) { assert(fmp && symbol); if (fmp->flags & BARCODE_MEMORY_FILE) { if (fmp->err || !fmp->mem) { @@ -393,7 +393,7 @@ INTERNAL int fm_close(struct filemem *restrict const fmp, struct zint_symbol *sy } /* `fseek()` to file/memory offset, returning 1 if successful, 0 on failure */ -INTERNAL int fm_seek(struct filemem *restrict const fmp, const long offset, const int whence) { +INTERNAL int zint_fm_seek(struct filemem *restrict const fmp, const long offset, const int whence) { assert(fmp); if (fmp->err) { return 0; @@ -417,7 +417,7 @@ INTERNAL int fm_seek(struct filemem *restrict const fmp, const long offset, cons } /* `ftell()` returns current file/memory offset if successful, -1 on failure */ -INTERNAL long fm_tell(struct filemem *restrict const fmp) { +INTERNAL long zint_fm_tell(struct filemem *restrict const fmp) { long ret; assert(fmp); if (fmp->err) { @@ -440,7 +440,7 @@ INTERNAL long fm_tell(struct filemem *restrict const fmp) { } /* Return `err`, which uses `errno` values; if file and `err` not set, test `ferror()` also */ -INTERNAL int fm_error(struct filemem *restrict const fmp) { +INTERNAL int zint_fm_error(struct filemem *restrict const fmp) { assert(fmp); if (fmp->err == 0 && !(fmp->flags & BARCODE_MEMORY_FILE) && ferror(fmp->fp)) { (void) fm_seterr(fmp, EIO); @@ -450,7 +450,7 @@ INTERNAL int fm_error(struct filemem *restrict const fmp) { /* `fflush()` if file, no-op (apart from error checking) if memory, returning 1 on success, 0 on failure NOTE: don't use, included only for libpng compatibility */ -INTERNAL int fm_flush(struct filemem *restrict const fmp) { +INTERNAL int zint_fm_flush(struct filemem *restrict const fmp) { assert(fmp); if (fmp->err) { return 0; diff --git a/backend/filemem.h b/backend/filemem.h index caccd5ae..8509ae36 100644 --- a/backend/filemem.h +++ b/backend/filemem.h @@ -1,7 +1,7 @@ /* filemem.h - write to file/memory abstraction */ /* libzint - the open source barcode library - Copyright (C) 2023-2024 Robin Stuart + Copyright (C) 2023-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -50,50 +50,50 @@ struct filemem { unsigned char *mem; size_t memsize; /* Size of `mem` buffer (capacity) */ size_t mempos; /* Current position */ - size_t memend; /* For use by `fm_seek()`, points to highest `mempos` reached */ + size_t memend; /* For use by `zint_fm_seek()`, points to highest `mempos` reached */ int flags; /* BARCODE_MEMORY_FILE or BARCODE_STDOUT */ - int err; /* `errno` values, reset only on `fm_open()` */ + int err; /* `errno` values, reset only on `zint_fm_open()` */ #ifdef FM_NO_VSNPRINTF FILE *fp_null; /* Only used for BARCODE_MEMORY_FILE */ #endif }; /* `fopen()` if file, setup memory buffer if BARCODE_MEMORY_FILE, returning 1 on success, 0 on failure */ -INTERNAL int fm_open(struct filemem *restrict const fmp, struct zint_symbol *symbol, const char *mode); +INTERNAL int zint_fm_open(struct filemem *restrict const fmp, struct zint_symbol *symbol, const char *mode); /* `fwrite()` to file or memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_write(const void *restrict ptr, const size_t size, const size_t nitems, +INTERNAL int zint_fm_write(const void *restrict ptr, const size_t size, const size_t nitems, struct filemem *restrict const fmp); /* `fputc()` to file or memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_putc(const int ch, struct filemem *restrict const fmp); +INTERNAL int zint_fm_putc(const int ch, struct filemem *restrict const fmp); /* `fputs()` to file or memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_puts(const char *str, struct filemem *restrict const fmp); +INTERNAL int zint_fm_puts(const char *str, struct filemem *restrict const fmp); /* `fprintf()` to file or memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_printf(struct filemem *restrict const fmp, const char *format, ...) ZINT_FORMAT_PRINTF(2, 3); +INTERNAL int zint_fm_printf(struct filemem *restrict const fmp, const char *format, ...) ZINT_FORMAT_PRINTF(2, 3); /* Output float without trailing zeroes to `fmp` with decimal pts `dp` (precision), returning 1 on success, 0 on failure */ -INTERNAL int fm_putsf(const char *prefix, const int dp, const float arg, struct filemem *restrict const fmp); +INTERNAL int zint_fm_putsf(const char *prefix, const int dp, const float arg, struct filemem *restrict const fmp); /* `fclose()` if file, set `symbol->memfile` & `symbol->memfile_size` if memory, returning 1 on success, 0 on failure */ -INTERNAL int fm_close(struct filemem *restrict const fmp, struct zint_symbol *symbol); +INTERNAL int zint_fm_close(struct filemem *restrict const fmp, struct zint_symbol *symbol); /* `fseek()` to file/memory offset, returning 1 on success, 0 on failure */ -INTERNAL int fm_seek(struct filemem *restrict const fmp, const long offset, const int whence); +INTERNAL int zint_fm_seek(struct filemem *restrict const fmp, const long offset, const int whence); /* `ftell()` returns current file/memory offset if successful, -1 on failure */ -INTERNAL long fm_tell(struct filemem *restrict const fmp); +INTERNAL long zint_fm_tell(struct filemem *restrict const fmp); /* Return `err`, which uses `errno` values; if file and `err` not set, test `ferror()` also */ -INTERNAL int fm_error(struct filemem *restrict const fmp); +INTERNAL int zint_fm_error(struct filemem *restrict const fmp); /* `fflush()` if file, no-op if memory, returning 1 on success, 0 on failure NOTE: don't use, included only for libpng compatibility */ -INTERNAL int fm_flush(struct filemem *restrict const fmp); +INTERNAL int zint_fm_flush(struct filemem *restrict const fmp); #ifdef __cplusplus } diff --git a/backend/general_field.c b/backend/general_field.c index 9c862b72..3ef14e13 100644 --- a/backend/general_field.c +++ b/backend/general_field.c @@ -1,7 +1,7 @@ /* general_field.c - Handles general field compaction (GS1 DataBar and composites) */ /* libzint - the open source barcode library - Copyright (C) 2019-2024 Robin Stuart + Copyright (C) 2019-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -33,32 +33,32 @@ #include "common.h" #include "general_field.h" -static const char alphanum_puncs[] = "*,-./"; -static const char isoiec_puncs[] = "!\"%&'()*+,-./:;<=>?_ "; /* Note contains space, not in cset82 */ +static const char gf_alphanum_puncs[] = "*,-./"; +static const char gf_isoiec_puncs[] = "!\"%&'()*+,-./:;<=>?_ "; /* Note contains space, not in cset82 */ #define IS_ISOIEC_F (IS_LWR_F | IS_C82_F | IS_AST_F | IS_PLS_F | IS_MNS_F | IS_SPC_F) /* Returns type of char at `i`. FNC1 counted as NUMERIC. Returns 0 if invalid char */ -static int general_field_type(const char *general_field, const int i) { +static int gf_type(const char *general_field, const int i) { if (general_field[i] == '\x1D' || z_isdigit(general_field[i])) { - return NUMERIC; + return GF_NUMERIC; } - if (z_isupper(general_field[i]) || posn(alphanum_puncs, general_field[i]) != -1) { - return ALPHANUMERIC; + if (z_isupper(general_field[i]) || z_posn(gf_alphanum_puncs, general_field[i]) != -1) { + return GF_ALPHANUMERIC; } - if (!not_sane(IS_ISOIEC_F, (const unsigned char *) general_field + i, 1)) { - return ISOIEC; + if (!z_not_sane(IS_ISOIEC_F, ZCUCP(general_field + i), 1)) { + return GF_ISOIEC; } return 0; } /* Returns true if next (including `i`) `num` chars of type `type`, or if given (non-zero), `type2` */ -static int general_field_next(const char *general_field, int i, const int general_field_len, int num, const int type, +static int gf_next(const char *general_field, int i, const int general_field_len, int num, const int type, const int type2) { if (i + num > general_field_len) { return 0; } for (; i < general_field_len && num; i++, num--) { - int type_i = general_field_type(general_field, i); + const int type_i = gf_type(general_field, i); if ((type_i != type && !type2) || (type_i != type && type_i != type2)) { return 0; } @@ -67,13 +67,13 @@ static int general_field_next(const char *general_field, int i, const int genera } /* Returns true if next (including `i`) `num` up to `max_num` chars of type `type` and occur at end */ -static int general_field_next_terminate(const char *general_field, int i, const int general_field_len, int num, +static int gf_next_terminate(const char *general_field, int i, const int general_field_len, int num, const int max_num, const int type) { if (i + max_num < general_field_len) { return 0; } for (; i < general_field_len; i++, num--) { - if (general_field_type(general_field, i) != type) { + if (gf_type(general_field, i) != type) { return 0; } } @@ -81,10 +81,10 @@ static int general_field_next_terminate(const char *general_field, int i, const } /* Returns true if none of the next (including `i`) `num` chars (or end occurs) of type `type` */ -static int general_field_next_none(const char *general_field, int i, const int general_field_len, int num, +static int gf_next_none(const char *general_field, int i, const int general_field_len, int num, const int type) { for (; i < general_field_len && num; i++, num--) { - if (general_field_type(general_field, i) == type) { + if (gf_type(general_field, i) == type) { return 0; } } @@ -93,36 +93,36 @@ static int general_field_next_none(const char *general_field, int i, const int g /* Attempts to apply encoding rules from sections 7.2.5.5.1 to 7.2.5.5.3 * of ISO/IEC 24724:2011 (same as sections 5.4.1 to 5.4.3 of ISO/IEC 24723:2010) */ -INTERNAL int general_field_encode(const char *general_field, const int general_field_len, int *p_mode, +INTERNAL int zint_general_field_encode(const char *general_field, const int general_field_len, int *p_mode, char *p_last_digit, char binary_string[], int *p_bp) { - int i, d1, d2; + int i; int mode = *p_mode; char last_digit = '\0'; /* Set to odd remaining digit at end if any */ int bp = *p_bp; for (i = 0; i < general_field_len; ) { - int type = general_field_type(general_field, i); + const int type = gf_type(general_field, i); if (!type) { return 0; } switch (mode) { - case NUMERIC: + case GF_NUMERIC: if (i < general_field_len - 1) { /* If at least 2 characters remain */ - if (type != NUMERIC || general_field_type(general_field, i + 1) != NUMERIC) { + if (type != GF_NUMERIC || gf_type(general_field, i + 1) != GF_NUMERIC) { /* 7.2.5.5.1/5.4.1 a) */ - bp = bin_append_posn(0, 4, binary_string, bp); /* Alphanumeric latch "0000" */ - mode = ALPHANUMERIC; + bp = z_bin_append_posn(0, 4, binary_string, bp); /* Alphanumeric latch "0000" */ + mode = GF_ALPHANUMERIC; } else { - d1 = general_field[i] == '\x1D' ? 10 : ctoi(general_field[i]); - d2 = general_field[i + 1] == '\x1D' ? 10 : ctoi(general_field[i + 1]); - bp = bin_append_posn((11 * d1) + d2 + 8, 7, binary_string, bp); + const int d1 = general_field[i] == '\x1D' ? 10 : z_ctoi(general_field[i]); + const int d2 = general_field[i + 1] == '\x1D' ? 10 : z_ctoi(general_field[i + 1]); + bp = z_bin_append_posn((11 * d1) + d2 + 8, 7, binary_string, bp); i += 2; } } else { /* If 1 character remains */ - if (type != NUMERIC) { + if (type != GF_NUMERIC) { /* 7.2.5.5.1/5.4.1 b) */ - bp = bin_append_posn(0, 4, binary_string, bp); /* Alphanumeric latch "0000" */ - mode = ALPHANUMERIC; + bp = z_bin_append_posn(0, 4, binary_string, bp); /* Alphanumeric latch "0000" */ + mode = GF_ALPHANUMERIC; } else { /* Ending with single digit. * 7.2.5.5.1 c) and 5.4.1 c) dealt with separately outside this procedure */ @@ -131,66 +131,65 @@ INTERNAL int general_field_encode(const char *general_field, const int general_f } } break; - case ALPHANUMERIC: + case GF_ALPHANUMERIC: if (general_field[i] == '\x1D') { /* 7.2.5.5.2/5.4.2 a) */ - bp = bin_append_posn(15, 5, binary_string, bp); /* "01111" */ - mode = NUMERIC; + bp = z_bin_append_posn(15, 5, binary_string, bp); /* "01111" */ + mode = GF_NUMERIC; i++; - } else if (type == ISOIEC) { + } else if (type == GF_ISOIEC) { /* 7.2.5.5.2/5.4.2 b) */ - bp = bin_append_posn(4, 5, binary_string, bp); /* ISO/IEC 646 latch "00100" */ - mode = ISOIEC; - } else if (general_field_next(general_field, i, general_field_len, 6, NUMERIC, 0)) { + bp = z_bin_append_posn(4, 5, binary_string, bp); /* ISO/IEC 646 latch "00100" */ + mode = GF_ISOIEC; + } else if (gf_next(general_field, i, general_field_len, 6, GF_NUMERIC, 0)) { /* 7.2.5.5.2/5.4.2 c) */ - bp = bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */ - mode = NUMERIC; - } else if (general_field_next_terminate(general_field, i, general_field_len, 4, - 5 /*Can limit to 5 max due to above*/, NUMERIC)) { + bp = z_bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */ + mode = GF_NUMERIC; + } else if (gf_next_terminate(general_field, i, general_field_len, 4, + 5 /*Can limit to 5 max due to above*/, GF_NUMERIC)) { /* 7.2.5.5.2/5.4.2 d) */ - bp = bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */ - mode = NUMERIC; + bp = z_bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */ + mode = GF_NUMERIC; } else if (z_isdigit(general_field[i])) { - bp = bin_append_posn(general_field[i] - 43, 5, binary_string, bp); + bp = z_bin_append_posn(general_field[i] - 43, 5, binary_string, bp); i++; } else if (z_isupper(general_field[i])) { - bp = bin_append_posn(general_field[i] - 33, 6, binary_string, bp); + bp = z_bin_append_posn(general_field[i] - 33, 6, binary_string, bp); i++; } else { - bp = bin_append_posn(posn(alphanum_puncs, general_field[i]) + 58, 6, binary_string, bp); + bp = z_bin_append_posn(z_posn(gf_alphanum_puncs, general_field[i]) + 58, 6, binary_string, bp); i++; } break; - case ISOIEC: + case GF_ISOIEC: if (general_field[i] == '\x1D') { /* 7.2.5.5.3/5.4.3 a) */ - bp = bin_append_posn(15, 5, binary_string, bp); /* "01111" */ - mode = NUMERIC; + bp = z_bin_append_posn(15, 5, binary_string, bp); /* "01111" */ + mode = GF_NUMERIC; i++; } else { - int next_10_not_isoiec = general_field_next_none(general_field, i, general_field_len, 10, ISOIEC); - if (next_10_not_isoiec && general_field_next(general_field, i, general_field_len, 4, - NUMERIC, 0)) { + const int next_10_not_isoiec = gf_next_none(general_field, i, general_field_len, 10, GF_ISOIEC); + if (next_10_not_isoiec && gf_next(general_field, i, general_field_len, 4, GF_NUMERIC, 0)) { /* 7.2.5.5.3/5.4.3 b) */ - bp = bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */ - mode = NUMERIC; - } else if (next_10_not_isoiec && general_field_next(general_field, i, general_field_len, 5, - ALPHANUMERIC, NUMERIC)) { + bp = z_bin_append_posn(0, 3, binary_string, bp); /* Numeric latch "000" */ + mode = GF_NUMERIC; + } else if (next_10_not_isoiec && gf_next(general_field, i, general_field_len, 5, + GF_ALPHANUMERIC, GF_NUMERIC)) { /* 7.2.5.5.3/5.4.3 c) */ /* Note this rule can produce longer bitstreams if most of the alphanumerics are numeric */ - bp = bin_append_posn(4, 5, binary_string, bp); /* Alphanumeric latch "00100" */ - mode = ALPHANUMERIC; + bp = z_bin_append_posn(4, 5, binary_string, bp); /* Alphanumeric latch "00100" */ + mode = GF_ALPHANUMERIC; } else if (z_isdigit(general_field[i])) { - bp = bin_append_posn(general_field[i] - 43, 5, binary_string, bp); + bp = z_bin_append_posn(general_field[i] - 43, 5, binary_string, bp); i++; } else if (z_isupper(general_field[i])) { - bp = bin_append_posn(general_field[i] - 1, 7, binary_string, bp); + bp = z_bin_append_posn(general_field[i] - 1, 7, binary_string, bp); i++; } else if (z_islower(general_field[i])) { - bp = bin_append_posn(general_field[i] - 7, 7, binary_string, bp); + bp = z_bin_append_posn(general_field[i] - 7, 7, binary_string, bp); i++; } else { - bp = bin_append_posn(posn(isoiec_puncs, general_field[i]) + 232, 8, binary_string, bp); + bp = z_bin_append_posn(z_posn(gf_isoiec_puncs, general_field[i]) + 232, 8, binary_string, bp); i++; } } diff --git a/backend/general_field.h b/backend/general_field.h index f4b3af7c..19df9537 100644 --- a/backend/general_field.h +++ b/backend/general_field.h @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2019-2022 Robin Stuart + Copyright (C) 2019-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -32,15 +32,15 @@ #ifndef Z_GENERAL_FIELD_H #define Z_GENERAL_FIELD_H -#define NUMERIC 110 -#define ALPHANUMERIC 97 -#define ISOIEC 105 +#define GF_NUMERIC 110 +#define GF_ALPHANUMERIC 97 +#define GF_ISOIEC 105 #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -INTERNAL int general_field_encode(const char *general_field, const int general_field_len, int *p_mode, +INTERNAL int zint_general_field_encode(const char *general_field, const int general_field_len, int *p_mode, char *p_last_digit, char binary_string[], int *p_bp); #ifdef __cplusplus diff --git a/backend/gif.c b/backend/gif.c index 675fefb3..673c05ce 100644 --- a/backend/gif.c +++ b/backend/gif.c @@ -62,7 +62,7 @@ static void gif_BufferNextByte(struct gif_state *pState) { pState->OutPosCur++; if (pState->fOutPaged && pState->OutPosCur + 2 >= pState->OutLength) { /* Keep last 256 bytes so `OutByteCountPos` within range */ - fm_write(pState->pOut, 1, pState->OutPosCur - 256, pState->fmp); + zint_fm_write(pState->pOut, 1, pState->OutPosCur - 256, pState->fmp); memmove(pState->pOut, pState->pOut + pState->OutPosCur - 256, 256); pState->OutByteCountPos -= pState->OutPosCur - 256; pState->OutPosCur = 256; @@ -237,7 +237,7 @@ static int gif_lzw(struct gif_state *pState, unsigned char paletteBitSize) { /* * Called function to save in gif format */ -INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) { +INTERNAL int zint_gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) { struct filemem fm; unsigned char outbuf[10]; unsigned char paletteRGB[10][3]; @@ -256,8 +256,8 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) const size_t bitmapSize = (size_t) symbol->bitmap_height * symbol->bitmap_width; - (void) out_colour_get_rgb(symbol->fgcolour, &RGBfg[0], &RGBfg[1], &RGBfg[2], &fgalpha); - (void) out_colour_get_rgb(symbol->bgcolour, &RGBbg[0], &RGBbg[1], &RGBbg[2], &bgalpha); + (void) zint_out_colour_get_rgb(symbol->fgcolour, &RGBfg[0], &RGBfg[1], &RGBfg[2], &fgalpha); + (void) zint_out_colour_get_rgb(symbol->bgcolour, &RGBbg[0], &RGBbg[1], &RGBbg[2], &bgalpha); /* Prepare state array */ State.pIn = pixelbuf; @@ -269,7 +269,7 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) State.OutLength = GIF_LZW_PAGE_SIZE; } if (!(State.pOut = (unsigned char *) malloc(State.OutLength))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 614, "Insufficient memory for GIF LZW buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 614, "Insufficient memory for GIF LZW buffer"); } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ memset(State.pOut, 0, State.OutLength); @@ -278,9 +278,9 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) State.fmp = &fm; /* Open output file in binary mode */ - if (!fm_open(State.fmp, symbol, "wb")) { - ZEXT errtxtf(0, symbol, 611, "Could not open GIF output file (%1$d: %2$s)", State.fmp->err, - strerror(State.fmp->err)); + if (!zint_fm_open(State.fmp, symbol, "wb")) { + ZEXT z_errtxtf(0, symbol, 611, "Could not open GIF output file (%1$d: %2$s)", State.fmp->err, + strerror(State.fmp->err)); free(State.pOut); return ZINT_ERROR_FILE_ACCESS; } @@ -305,7 +305,7 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) static const unsigned char ultra_chars[8] = { 'W', 'C', 'B', 'M', 'R', 'Y', 'G', 'K' }; for (i = 0; i < 8; i++) { State.map[ultra_chars[i]] = (unsigned char) i; - out_colour_char_to_rgb(ultra_chars[i], &paletteRGB[i][0], &paletteRGB[i][1], &paletteRGB[i][2]); + zint_out_colour_char_to_rgb(ultra_chars[i], &paletteRGB[i][0], &paletteRGB[i][1], &paletteRGB[i][2]); } paletteCount = 8; paletteBitSize = 3; @@ -360,7 +360,7 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) paletteSize = 1 << paletteBitSize; /* GIF signature (6) */ - fm_write(transparent_index == -1 ? "GIF87a" : "GIF89a", 1, 6, State.fmp); + zint_fm_write(transparent_index == -1 ? "GIF87a" : "GIF89a", 1, 6, State.fmp); /* Screen Descriptor (7) */ /* Screen Width */ outbuf[0] = (unsigned char) (0xff & symbol->bitmap_width); @@ -385,12 +385,12 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) outbuf[5] = (unsigned char) (bgindex == -1 ? 0 : bgindex); /* Byte 7 must be 0x00 */ outbuf[6] = 0x00; - fm_write(outbuf, 1, 7, State.fmp); + zint_fm_write(outbuf, 1, 7, State.fmp); /* Global Color Table (paletteSize*3) */ - fm_write(paletteRGB, 1, 3 * paletteCount, State.fmp); + zint_fm_write(paletteRGB, 1, 3 * paletteCount, State.fmp); /* Add unused palette items to fill palette size */ for (i = paletteCount; i < paletteSize; i++) { - fm_write(RGBUnused, 1, 3, State.fmp); + zint_fm_write(RGBUnused, 1, 3, State.fmp); } /* Graphic control extension (8) */ @@ -418,7 +418,7 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) outbuf[6] = (unsigned char) transparent_index; /* Block Terminator */ outbuf[7] = 0; - fm_write(outbuf, 1, 8, State.fmp); + zint_fm_write(outbuf, 1, 8, State.fmp); } /* Image Descriptor */ /* Image separator character = ',' */ @@ -441,30 +441,30 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) * There is no local color table if its most significant bit is reset. */ outbuf[9] = 0x00; - fm_write(outbuf, 1, 10, State.fmp); + zint_fm_write(outbuf, 1, 10, State.fmp); /* Call lzw encoding */ if (!gif_lzw(&State, paletteBitSize)) { free(State.pOut); - (void) fm_close(State.fmp, symbol); - return errtxt(ZINT_ERROR_MEMORY, symbol, 613, "Insufficient memory for GIF LZW buffer"); + (void) zint_fm_close(State.fmp, symbol); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 613, "Insufficient memory for GIF LZW buffer"); } - fm_write(State.pOut, 1, State.OutPosCur, State.fmp); + zint_fm_write(State.pOut, 1, State.OutPosCur, State.fmp); free(State.pOut); /* GIF terminator */ - fm_putc(';', State.fmp); + zint_fm_putc(';', State.fmp); - if (fm_error(State.fmp)) { - ZEXT errtxtf(0, symbol, 615, "Incomplete write of GIF output (%1$d: %2$s)", State.fmp->err, - strerror(State.fmp->err)); - (void) fm_close(State.fmp, symbol); + if (zint_fm_error(State.fmp)) { + ZEXT z_errtxtf(0, symbol, 615, "Incomplete write of GIF output (%1$d: %2$s)", State.fmp->err, + strerror(State.fmp->err)); + (void) zint_fm_close(State.fmp, symbol); return ZINT_ERROR_FILE_WRITE; } - if (!fm_close(State.fmp, symbol)) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 617, "Failure on closing GIF output file (%1$d: %2$s)", - State.fmp->err, strerror(State.fmp->err)); + if (!zint_fm_close(State.fmp, symbol)) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 617, "Failure on closing GIF output file (%1$d: %2$s)", + State.fmp->err, strerror(State.fmp->err)); } return 0; diff --git a/backend/gridmtx.c b/backend/gridmtx.c index 41185327..d695a100 100644 --- a/backend/gridmtx.c +++ b/backend/gridmtx.c @@ -69,7 +69,7 @@ static int gm_in_numeral(const unsigned int ddata[], const int length, const int i++) { if (z_isdigit(ddata[i])) { digit_cnt++; - } else if (posn(gm_numeral_nondigits, (const char) ddata[i]) != -1) { + } else if (z_posn(gm_numeral_nondigits, (const char) ddata[i]) != -1) { if (nondigit) { break; } @@ -279,7 +279,7 @@ static void gm_define_mode(char *mode, const unsigned int ddata[], const int len /* Get optimal mode for each code point by tracing backwards */ for (i = length - 1; i >= 0; i--) { - j = posn(mode_types, cur_mode); + j = z_posn(mode_types, cur_mode); cur_mode = char_modes[i][j]; mode[i] = cur_mode; } @@ -293,7 +293,7 @@ static void gm_define_mode(char *mode, const unsigned int ddata[], const int len static void gm_add_byte_count(char binary[], const int byte_count_posn, const int byte_count) { /* AIMD014 6.3.7: "Let L be the number of bytes of input data to be encoded in the 8-bit binary data set. * First output (L-1) as a 9-bit binary prefix to record the number of bytes..." */ - bin_append_posn(byte_count - 1, 9, binary, byte_count_posn); + z_bin_append_posn(byte_count - 1, 9, binary, byte_count_posn); } /* Add a control character to the data stream */ @@ -316,7 +316,7 @@ static int gm_add_shift_char(char binary[], int bp, int shifty, const int debug_ printf("SHIFT [%d] ", glyph); } - bp = bin_append_posn(glyph, 6, binary, bp); + bp = z_bin_append_posn(glyph, 6, binary, bp); return bp; } @@ -342,15 +342,15 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons if (eci != 0) { /* ECI assignment according to Table 8 */ - bp = bin_append_posn(12, 4, binary, bp); /* ECI */ + bp = z_bin_append_posn(12, 4, binary, bp); /* ECI */ if (eci <= 1023) { - bp = bin_append_posn(eci, 11, binary, bp); + bp = z_bin_append_posn(eci, 11, binary, bp); } else if (eci <= 32767) { - bp = bin_append_posn(2, 2, binary, bp); - bp = bin_append_posn(eci, 15, binary, bp); + bp = z_bin_append_posn(2, 2, binary, bp); + bp = z_bin_append_posn(eci, 15, binary, bp); } else { - bp = bin_append_posn(3, 2, binary, bp); - bp = bin_append_posn(eci, 20, binary, bp); + bp = z_bin_append_posn(3, 2, binary, bp); + bp = z_bin_append_posn(eci, 20, binary, bp); } } @@ -363,21 +363,21 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons switch (current_mode) { case 0: switch (next_mode) { - case GM_CHINESE: bp = bin_append_posn(1, 4, binary, bp); break; - case GM_NUMBER: bp = bin_append_posn(2, 4, binary, bp); break; - case GM_LOWER: bp = bin_append_posn(3, 4, binary, bp); break; - case GM_UPPER: bp = bin_append_posn(4, 4, binary, bp); break; - case GM_MIXED: bp = bin_append_posn(5, 4, binary, bp); break; - case GM_BYTE: bp = bin_append_posn(6, 4, binary, bp); break; + case GM_CHINESE: bp = z_bin_append_posn(1, 4, binary, bp); break; + case GM_NUMBER: bp = z_bin_append_posn(2, 4, binary, bp); break; + case GM_LOWER: bp = z_bin_append_posn(3, 4, binary, bp); break; + case GM_UPPER: bp = z_bin_append_posn(4, 4, binary, bp); break; + case GM_MIXED: bp = z_bin_append_posn(5, 4, binary, bp); break; + case GM_BYTE: bp = z_bin_append_posn(6, 4, binary, bp); break; } break; case GM_CHINESE: switch (next_mode) { - case GM_NUMBER: bp = bin_append_posn(8161, 13, binary, bp); break; - case GM_LOWER: bp = bin_append_posn(8162, 13, binary, bp); break; - case GM_UPPER: bp = bin_append_posn(8163, 13, binary, bp); break; - case GM_MIXED: bp = bin_append_posn(8164, 13, binary, bp); break; - case GM_BYTE: bp = bin_append_posn(8165, 13, binary, bp); break; + case GM_NUMBER: bp = z_bin_append_posn(8161, 13, binary, bp); break; + case GM_LOWER: bp = z_bin_append_posn(8162, 13, binary, bp); break; + case GM_UPPER: bp = z_bin_append_posn(8163, 13, binary, bp); break; + case GM_MIXED: bp = z_bin_append_posn(8164, 13, binary, bp); break; + case GM_BYTE: bp = z_bin_append_posn(8165, 13, binary, bp); break; } break; case GM_NUMBER: @@ -397,33 +397,33 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons break; /* 0 pad digits */ } switch (next_mode) { - case GM_CHINESE: bp = bin_append_posn(1019, 10, binary, bp); break; - case GM_LOWER: bp = bin_append_posn(1020, 10, binary, bp); break; - case GM_UPPER: bp = bin_append_posn(1021, 10, binary, bp); break; - case GM_MIXED: bp = bin_append_posn(1022, 10, binary, bp); break; - case GM_BYTE: bp = bin_append_posn(1023, 10, binary, bp); break; + case GM_CHINESE: bp = z_bin_append_posn(1019, 10, binary, bp); break; + case GM_LOWER: bp = z_bin_append_posn(1020, 10, binary, bp); break; + case GM_UPPER: bp = z_bin_append_posn(1021, 10, binary, bp); break; + case GM_MIXED: bp = z_bin_append_posn(1022, 10, binary, bp); break; + case GM_BYTE: bp = z_bin_append_posn(1023, 10, binary, bp); break; } break; case GM_LOWER: case GM_UPPER: switch (next_mode) { - case GM_CHINESE: bp = bin_append_posn(28, 5, binary, bp); break; - case GM_NUMBER: bp = bin_append_posn(29, 5, binary, bp); break; + case GM_CHINESE: bp = z_bin_append_posn(28, 5, binary, bp); break; + case GM_NUMBER: bp = z_bin_append_posn(29, 5, binary, bp); break; case GM_LOWER: case GM_UPPER: - bp = bin_append_posn(30, 5, binary, bp); + bp = z_bin_append_posn(30, 5, binary, bp); break; - case GM_MIXED: bp = bin_append_posn(124, 7, binary, bp); break; - case GM_BYTE: bp = bin_append_posn(126, 7, binary, bp); break; + case GM_MIXED: bp = z_bin_append_posn(124, 7, binary, bp); break; + case GM_BYTE: bp = z_bin_append_posn(126, 7, binary, bp); break; } break; case GM_MIXED: switch (next_mode) { - case GM_CHINESE: bp = bin_append_posn(1009, 10, binary, bp); break; - case GM_NUMBER: bp = bin_append_posn(1010, 10, binary, bp); break; - case GM_LOWER: bp = bin_append_posn(1011, 10, binary, bp); break; - case GM_UPPER: bp = bin_append_posn(1012, 10, binary, bp); break; - case GM_BYTE: bp = bin_append_posn(1015, 10, binary, bp); break; + case GM_CHINESE: bp = z_bin_append_posn(1009, 10, binary, bp); break; + case GM_NUMBER: bp = z_bin_append_posn(1010, 10, binary, bp); break; + case GM_LOWER: bp = z_bin_append_posn(1011, 10, binary, bp); break; + case GM_UPPER: bp = z_bin_append_posn(1012, 10, binary, bp); break; + case GM_BYTE: bp = z_bin_append_posn(1015, 10, binary, bp); break; } break; case GM_BYTE: @@ -431,11 +431,11 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons gm_add_byte_count(binary, byte_count_posn, byte_count); byte_count = 0; switch (next_mode) { - case GM_CHINESE: bp = bin_append_posn(1, 4, binary, bp); break; - case GM_NUMBER: bp = bin_append_posn(2, 4, binary, bp); break; - case GM_LOWER: bp = bin_append_posn(3, 4, binary, bp); break; - case GM_UPPER: bp = bin_append_posn(4, 4, binary, bp); break; - case GM_MIXED: bp = bin_append_posn(5, 4, binary, bp); break; + case GM_CHINESE: bp = z_bin_append_posn(1, 4, binary, bp); break; + case GM_NUMBER: bp = z_bin_append_posn(2, 4, binary, bp); break; + case GM_LOWER: bp = z_bin_append_posn(3, 4, binary, bp); break; + case GM_UPPER: bp = z_bin_append_posn(4, 4, binary, bp); break; + case GM_MIXED: bp = z_bin_append_posn(5, 4, binary, bp); break; } break; } @@ -498,7 +498,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons printf("[%d] ", (int) glyph); } - bp = bin_append_posn(glyph, 13, binary, bp); + bp = z_bin_append_posn(glyph, 13, binary, bp); sp++; break; @@ -506,7 +506,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons if (last_mode != current_mode) { /* Reserve a space for numeric digit padding value (2 bits) */ number_pad_posn = bp; - bp = bin_append_posn(0, 2, binary, bp); + bp = z_bin_append_posn(0, 2, binary, bp); } p = 0; ppos = -1; @@ -521,7 +521,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons if (z_isdigit(ddata[sp])) { numbuf[p] = ddata[sp]; p++; - } else if (posn(gm_numeral_nondigits, (const char) ddata[sp]) != -1) { + } else if (z_posn(gm_numeral_nondigits, (const char) ddata[sp]) != -1) { if (ppos != -1) { break; } @@ -557,7 +557,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons printf("[%d] ", (int) glyph); } - bp = bin_append_posn(glyph, 10, binary, bp); + bp = z_bin_append_posn(glyph, 10, binary, bp); } glyph = (100 * (numbuf[0] - '0')) + (10 * (numbuf[1] - '0')) + (numbuf[2] - '0'); @@ -565,34 +565,34 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons printf("[%d] ", (int) glyph); } - bp = bin_append_posn(glyph, 10, binary, bp); + bp = z_bin_append_posn(glyph, 10, binary, bp); break; case GM_BYTE: if (last_mode != current_mode) { /* Reserve space for byte block length indicator (9 bits) */ byte_count_posn = bp; - bp = bin_append_posn(0, 9, binary, bp); + bp = z_bin_append_posn(0, 9, binary, bp); } glyph = ddata[sp]; if (byte_count == 512 || (glyph > 0xFF && byte_count == 511)) { /* Maximum byte block size is 512 bytes. If longer is needed then start a new block */ if (glyph > 0xFF && byte_count == 511) { /* Split double-byte */ - bp = bin_append_posn(glyph >> 8, 8, binary, bp); + bp = z_bin_append_posn(glyph >> 8, 8, binary, bp); glyph &= 0xFF; byte_count++; } gm_add_byte_count(binary, byte_count_posn, byte_count); - bp = bin_append_posn(7, 4, binary, bp); + bp = z_bin_append_posn(7, 4, binary, bp); byte_count_posn = bp; - bp = bin_append_posn(0, 9, binary, bp); + bp = z_bin_append_posn(0, 9, binary, bp); byte_count = 0; } if (debug_print) { printf("[%d] ", (int) glyph); } - bp = bin_append_posn(glyph, glyph > 0xFF ? 16 : 8, binary, bp); + bp = z_bin_append_posn(glyph, glyph > 0xFF ? 16 : 8, binary, bp); sp++; byte_count++; if (glyph > 0xFF) { @@ -614,15 +614,15 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons if (shift == 0) { /* Mixed Mode character */ - glyph = posn(EUROPIUM, (const char) ddata[sp]); + glyph = z_posn(EUROPIUM, (const char) ddata[sp]); if (debug_print) { printf("[%d] ", (int) glyph); } - bp = bin_append_posn(glyph, 6, binary, bp); + bp = z_bin_append_posn(glyph, 6, binary, bp); } else { /* Shift Mode character */ - bp = bin_append_posn(1014, 10, binary, bp); /* shift indicator */ + bp = z_bin_append_posn(1014, 10, binary, bp); /* shift indicator */ bp = gm_add_shift_char(binary, bp, ddata[sp], debug_print); } @@ -639,15 +639,15 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons if (shift == 0) { /* Upper Case character */ - glyph = posn(EUROPIUM_UPR, (const char) ddata[sp]); + glyph = z_posn(EUROPIUM_UPR, (const char) ddata[sp]); if (debug_print) { printf("[%d] ", (int) glyph); } - bp = bin_append_posn(glyph, 5, binary, bp); + bp = z_bin_append_posn(glyph, 5, binary, bp); } else { /* Shift Mode character */ - bp = bin_append_posn(125, 7, binary, bp); /* shift indicator */ + bp = z_bin_append_posn(125, 7, binary, bp); /* shift indicator */ bp = gm_add_shift_char(binary, bp, ddata[sp], debug_print); } @@ -664,15 +664,15 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons if (shift == 0) { /* Lower Case character */ - glyph = posn(EUROPIUM_LWR, (const char) ddata[sp]); + glyph = z_posn(EUROPIUM_LWR, (const char) ddata[sp]); if (debug_print) { printf("[%d] ", (int) glyph); } - bp = bin_append_posn(glyph, 5, binary, bp); + bp = z_bin_append_posn(glyph, 5, binary, bp); } else { /* Shift Mode character */ - bp = bin_append_posn(125, 7, binary, bp); /* shift indicator */ + bp = z_bin_append_posn(125, 7, binary, bp); /* shift indicator */ bp = gm_add_shift_char(binary, bp, ddata[sp], debug_print); } @@ -710,14 +710,14 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons /* Add "end of data" character */ switch (current_mode) { - case GM_CHINESE: bp = bin_append_posn(8160, 13, binary, bp); break; - case GM_NUMBER: bp = bin_append_posn(1018, 10, binary, bp); break; + case GM_CHINESE: bp = z_bin_append_posn(8160, 13, binary, bp); break; + case GM_NUMBER: bp = z_bin_append_posn(1018, 10, binary, bp); break; case GM_LOWER: case GM_UPPER: - bp = bin_append_posn(27, 5, binary, bp); + bp = z_bin_append_posn(27, 5, binary, bp); break; - case GM_MIXED: bp = bin_append_posn(1008, 10, binary, bp); break; - case GM_BYTE: bp = bin_append_posn(0, 4, binary, bp); break; + case GM_MIXED: bp = z_bin_append_posn(1008, 10, binary, bp); break; + case GM_BYTE: bp = z_bin_append_posn(0, 4, binary, bp); break; } if (bp > 9191) { @@ -741,15 +741,15 @@ static int gm_encode_segs(unsigned int ddata[], const struct zint_seg segs[], co int p; if (reader && (!p_structapp || p_structapp->index == 1)) { /* Appears only in 1st symbol if Structured Append */ - bp = bin_append_posn(10, 4, binary, bp); /* FNC3 - Reader Initialisation */ + bp = z_bin_append_posn(10, 4, binary, bp); /* FNC3 - Reader Initialisation */ } if (p_structapp) { - bp = bin_append_posn(9, 4, binary, bp); /* FNC2 - Structured Append */ - bp = bin_append_posn(to_int((const unsigned char *) p_structapp->id, (int) strlen(p_structapp->id)), 8, + bp = z_bin_append_posn(9, 4, binary, bp); /* FNC2 - Structured Append */ + bp = z_bin_append_posn(z_to_int(ZCUCP( p_structapp->id), (int) strlen(p_structapp->id)), 8, binary, bp); /* File signature */ - bp = bin_append_posn(p_structapp->count - 1, 4, binary, bp); - bp = bin_append_posn(p_structapp->index - 1, 4, binary, bp); + bp = z_bin_append_posn(p_structapp->count - 1, 4, binary, bp); + bp = z_bin_append_posn(p_structapp->index - 1, 4, binary, bp); } for (i = 0; i < seg_count; i++) { @@ -763,7 +763,7 @@ static int gm_encode_segs(unsigned int ddata[], const struct zint_seg segs[], co /* Add padding bits if required */ p = 7 - (bp % 7); if (p % 7) { - bp = bin_append_posn(0, p, binary, bp); + bp = z_bin_append_posn(0, p, binary, bp); } /* Note bit-padding can't tip `bp` over max 9191 (1313 * 7) */ @@ -819,7 +819,7 @@ static void gm_add_ecc(const char binary[], const int data_posn, const int layer b3 = gm_ebeb[((layers - 1) * 20) + ((ecc_level - 1) * 4) + 1]; e2 = gm_ebeb[((layers - 1) * 20) + ((ecc_level - 1) * 4) + 2]; - rs_init_gf(&rs, 0x89); + zint_rs_init_gf(&rs, 0x89); /* Split the data into blocks */ wp = 0; @@ -843,8 +843,8 @@ static void gm_add_ecc(const char binary[], const int data_posn, const int layer } /* Calculate ECC data for this block */ - rs_init_code(&rs, ecc_size, 1); - rs_encode(&rs, data_size, data_block, ecc_block); + zint_rs_init_code(&rs, ecc_size, 1); + zint_rs_encode(&rs, data_size, data_block, ecc_block); /* Add error correction data */ for (j = 0; j < data_size; j++) { @@ -973,7 +973,7 @@ static void gm_place_layer_id(char *grid, int size, int layers, int modules, int } } -INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int warn_number = 0; int size, modules, error_number; int auto_layers, min_layers, layers, auto_ecc_level, min_ecc_level, ecc_level; @@ -988,23 +988,23 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons int bin_len; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; - const int eci_length_segs = get_eci_length_segs(segs, seg_count); + const int eci_length_segs = zint_get_eci_length_segs(segs, seg_count); struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count); unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * eci_length_segs); char *grid; - segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs & protect lengths) */ + z_segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs & protect lengths) */ /* If ZINT_FULL_MULTIBYTE set use Hanzi mode in DATA_MODE or for non-GB 2312 in UNICODE_MODE */ full_multibyte = (symbol->option_3 & 0xFF) == ZINT_FULL_MULTIBYTE; - 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 */ } if ((symbol->input_mode & 0x07) == DATA_MODE) { - if (gb2312_cpy_segs(symbol, local_segs, seg_count, ddata, full_multibyte)) { - return ZINT_ERROR_MEMORY; /* `gb18030_cpy_segs()` only fails with OOM */ + if (zint_gb2312_cpy_segs(symbol, local_segs, seg_count, ddata, full_multibyte)) { + return ZINT_ERROR_MEMORY; /* `zint_gb18030_cpy_segs()` only fails with OOM */ } } else { unsigned int *dd = ddata; @@ -1012,25 +1012,25 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons int eci = 0; if (local_segs[i].eci != 0 && local_segs[i].eci != 29) { /* Unless default or ECI 29 (GB 2312) */ /* Try other conversions */ - error_number = gb2312_utf8_to_eci(local_segs[i].eci, local_segs[i].source, &local_segs[i].length, - dd, full_multibyte); + error_number = zint_gb2312_utf8_to_eci(local_segs[i].eci, local_segs[i].source, &local_segs[i].length, + dd, full_multibyte); if (error_number == 0) { eci = local_segs[i].eci; } else { - return errtxtf(error_number, symbol, 535, "Invalid character in input for ECI '%d'", + return z_errtxtf(error_number, symbol, 535, "Invalid character in input for ECI '%d'", local_segs[i].eci); } } if (!eci) { /* Try GB 2312 (EUC-CN) */ - error_number = gb2312_utf8(symbol, local_segs[i].source, &local_segs[i].length, dd); + error_number = zint_gb2312_utf8(symbol, local_segs[i].source, &local_segs[i].length, dd); if (error_number != 0) { return error_number; } eci = 29; } - if (raw_text && rt_cpy_seg_ddata(symbol, i, &local_segs[i], eci, dd)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg_ddata()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg_ddata(symbol, i, &local_segs[i], eci, dd)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg_ddata()` only fails with OOM */ } dd += local_segs[i].length; } @@ -1040,13 +1040,13 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons if (symbol->structapp.count) { if (symbol->structapp.count < 2 || symbol->structapp.count > 16) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 536, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 536, "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, 537, - "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, 537, + "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; @@ -1054,16 +1054,16 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons for (id_len = 1; id_len < 4 && symbol->structapp.id[id_len]; id_len++); if (id_len > 3) { /* 255 (8 bits) */ - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 538, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 538, "Structured Append ID length %d too long (3 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, 539, "Invalid Structured Append ID (digits only)"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 539, "Invalid Structured Append ID (digits only)"); } if (id > 255) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 530, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 530, "Structured Append ID value '%d' out of range (0 to 255)", id); } } @@ -1071,13 +1071,13 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons } if (symbol->eci > 811799) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 533, "ECI code '%d' out of range (0 to 811799)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 533, "ECI code '%d' out of range (0 to 811799)", symbol->eci); } error_number = gm_encode_segs(ddata, local_segs, seg_count, binary, reader, p_structapp, &bin_len, debug_print); if (error_number != 0) { - return errtxt(error_number, symbol, 531, "Input too long, requires too many codewords (maximum 1313)"); + return z_errtxt(error_number, symbol, 531, "Input too long, requires too many codewords (maximum 1313)"); } /* Determine the size of the symbol */ @@ -1102,9 +1102,9 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons if (symbol->option_2 >= min_layers) { layers = symbol->option_2; } else { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 534, - "Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)", - symbol->option_2, data_cw, gm_max_cw[symbol->option_2 - 1]); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 534, + "Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)", + symbol->option_2, data_cw, gm_max_cw[symbol->option_2 - 1]); } } @@ -1156,9 +1156,9 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons } if (data_cw > data_max) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 532, - "Input too long for ECC level %1$d, requires %2$d codewords (maximum %3$d)", ecc_level, - data_cw, data_max); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 532, + "Input too long for ECC level %1$d, requires %2$d codewords (maximum %3$d)", + ecc_level, data_cw, data_max); } if (debug_print) { printf("Layers: %d, ECC level: %d, Data Codewords: %d\n", layers, ecc_level, data_cw); @@ -1170,7 +1170,7 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons gm_add_ecc(binary, data_cw, layers, ecc_level, word); #ifdef ZINT_TEST - if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, word, data_cw); + if (symbol->debug & ZINT_DEBUG_TEST) z_debug_test_codeword_dump(symbol, word, data_cw); #endif size = 6 + (layers * 12); modules = 1 + (layers * 2); @@ -1208,7 +1208,7 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons for (x = 0; x < size; x++) { for (y = 0; y < size; y++) { if (grid[(y * size) + x] == '1') { - set_module(symbol, y, x); + z_set_module(symbol, y, x); } } symbol->row_height[x] = 1; diff --git a/backend/gs1.c b/backend/gs1.c index 0677ac20..734b098a 100644 --- a/backend/gs1.c +++ b/backend/gs1.c @@ -342,14 +342,14 @@ static int gs1_yyyymmd0(const unsigned char *data, int data_len, int offset, int if (!length_only && data_len) { int month, day; - month = to_int(data + offset + 4, 2); + month = z_to_int(data + offset + 4, 2); if (month == 0 || month > 12) { *p_err_no = 3; *p_err_posn = offset + 4 + 1; return gs1_err_msg_printf_nochk(err_msg, "Invalid month '%.2s'", data + offset + 4); } - day = to_int(data + offset + 6, 2); + day = z_to_int(data + offset + 6, 2); if (day && day > days_in_month[month]) { *p_err_no = 3; *p_err_posn = offset + 6 + 1; @@ -357,7 +357,7 @@ static int gs1_yyyymmd0(const unsigned char *data, int data_len, int offset, int } /* Leap year check */ if (month == 2 && day == 29) { - const int year = to_int(data + offset, 4); + const int year = z_to_int(data + offset, 4); if ((year & 3) || (year % 100 == 0 && year % 400 != 0)) { *p_err_no = 3; *p_err_posn = offset + 6 + 1; @@ -380,7 +380,7 @@ static int gs1_yyyymmdd(const unsigned char *data, int data_len, int offset, int data_len = data_len < offset ? 0 : data_len - offset; if (!length_only && data_len) { - const int day = to_int(data + offset + 6, 2); + const int day = z_to_int(data + offset + 6, 2); if (day == 0) { *p_err_no = 3; *p_err_posn = offset + 6 + 1; @@ -427,7 +427,7 @@ static int gs1_yymmdd(const unsigned char *data, int data_len, int offset, int m data_len = data_len < offset ? 0 : data_len - offset; if (!length_only && data_len) { - const int day = to_int(data + offset + 4, 2); + const int day = z_to_int(data + offset + 4, 2); if (day == 0) { *p_err_no = 3; *p_err_posn = offset + 4 + 1; @@ -452,13 +452,13 @@ static int gs1_hhmi(const unsigned char *data, int data_len, int offset, int min if (!length_only && data_len) { int hour, mins; - hour = to_int(data + offset, 2); + hour = z_to_int(data + offset, 2); if (hour > 23) { *p_err_no = 3; *p_err_posn = offset + 1; return gs1_err_msg_printf_nochk(err_msg, "Invalid hour of day '%.2s'", data + offset); } - mins = to_int(data + offset + 2, 2); + mins = z_to_int(data + offset + 2, 2); if (mins > 59) { *p_err_no = 3; *p_err_posn = offset + 2 + 1; @@ -481,7 +481,7 @@ static int gs1_hh(const unsigned char *data, int data_len, int offset, int min, } if (!length_only && data_len) { - const int hour = to_int(data + offset, 2); + const int hour = z_to_int(data + offset, 2); if (hour > 23) { *p_err_no = 3; *p_err_posn = offset + 1; @@ -504,7 +504,7 @@ static int gs1_mi(const unsigned char *data, int data_len, int offset, int min, } if (!length_only && data_len) { - const int mins = to_int(data + offset, 2); + const int mins = z_to_int(data + offset, 2); if (mins > 59) { *p_err_no = 3; *p_err_posn = offset + 1; @@ -527,7 +527,7 @@ static int gs1_ss(const unsigned char *data, int data_len, int offset, int min, } if (!length_only && data_len) { - const int secs = to_int(data + offset, 2); + const int secs = z_to_int(data + offset, 2); if (secs > 59) { *p_err_no = 3; *p_err_posn = offset + 1; @@ -557,7 +557,7 @@ static int gs1_iso3166(const unsigned char *data, int data_len, int offset, int } if (!length_only && data_len) { - if (!iso3166_numeric(to_int(data + offset, 3))) { + if (!iso3166_numeric(z_to_int(data + offset, 3))) { *p_err_no = 3; *p_err_posn = offset + 1; return gs1_err_msg_printf_nochk(err_msg, "Unknown country code '%.3s'", data + offset); @@ -579,7 +579,7 @@ static int gs1_iso3166999(const unsigned char *data, int data_len, int offset, i } if (!length_only && data_len) { - const int cc = to_int(data + offset, 3); + const int cc = z_to_int(data + offset, 3); if (cc != 999 && !iso3166_numeric(cc)) { *p_err_no = 3; *p_err_posn = offset + 1; @@ -627,7 +627,7 @@ static int gs1_iso4217(const unsigned char *data, int data_len, int offset, int } if (!length_only && data_len) { - if (!iso4217_numeric(to_int(data + offset, 3))) { + if (!iso4217_numeric(z_to_int(data + offset, 3))) { *p_err_no = 3; *p_err_posn = offset + 1; return gs1_err_msg_printf_nochk(err_msg, "Unknown currency code '%.3s'", data + offset); @@ -730,7 +730,7 @@ static int gs1_nonzero(const unsigned char *data, int data_len, int offset, int } if (!length_only && data_len) { - const int val = to_int(data + offset, data_len > max ? max : data_len); + const int val = z_to_int(data + offset, data_len > max ? max : data_len); if (val == 0) { *p_err_no = 3; @@ -800,13 +800,13 @@ static int gs1_pieceoftotal(const unsigned char *data, int data_len, int offset, if (!length_only && data_len) { int pieces, total; - pieces = to_int(data + offset, 2); + pieces = z_to_int(data + offset, 2); if (pieces == 0) { *p_err_no = 3; *p_err_posn = offset + 1; return gs1_err_msg_cpy_nochk(err_msg, "Piece number cannot be zero"); } - total = to_int(data + offset + 2, 2); + total = z_to_int(data + offset + 2, 2); if (total == 0) { *p_err_no = 3; *p_err_posn = offset + 1; @@ -862,7 +862,7 @@ static int gs1_iban(const unsigned char *data, int data_len, int offset, int min *p_err_posn = d - data + 1; return gs1_err_msg_printf_nochk(err_msg, "Non-numeric IBAN checksum '%.2s'", d); } - given_checksum = to_int(d, 2); + given_checksum = z_to_int(d, 2); d += 2; for (; d < de; d++) { /* 0-9, A-Z */ @@ -937,7 +937,7 @@ static const unsigned char *gs1_coupon_vli(const unsigned char *data, const int (void) gs1_err_msg_printf_nochk(err_msg, "%s VLI missing", name); return NULL; } - vli = to_int(d, 1); + vli = z_to_int(d, 1); if ((vli < vli_min || vli > vli_max) && (vli != 9 || !vli_nine)) { *p_err_no = 3; *p_err_posn = d - data + 1; @@ -981,7 +981,7 @@ static const unsigned char *gs1_coupon_val(const unsigned char *data, const int (void) gs1_err_msg_printf_nochk(err_msg, "%s incomplete", name); return NULL; } - val = to_int(d, val_len); + val = z_to_int(d, val_len); if (val < 0) { *p_err_no = 3; *p_err_posn = d - data + 1; @@ -1058,7 +1058,7 @@ static int gs1_couponcode(const unsigned char *data, int data_len, int offset, i /* Optional fields */ while (d - data < data_len) { - const int data_field = to_int(d, 1); + const int data_field = z_to_int(d, 1); d++; if (data_field == 1) { @@ -1435,13 +1435,13 @@ static int gs1_posinseqslash(const unsigned char *data, int data_len, int offset *p_err_posn = offset + 1; return gs1_err_msg_cpy_nochk(err_msg, "No sequence separator ('/')"); } - pos = to_int(data + offset, slash - (data + offset)); + pos = z_to_int(data + offset, slash - (data + offset)); if (pos == 0) { *p_err_no = 3; *p_err_posn = offset + 1; return gs1_err_msg_cpy_nochk(err_msg, "Sequence position cannot be zero"); } - tot = to_int(slash + 1, de - (slash + 1)); + tot = z_to_int(slash + 1, de - (slash + 1)); if (tot == 0) { *p_err_no = 3; *p_err_posn = slash + 1 - data + 1; @@ -1612,8 +1612,8 @@ static int gs1_packagetype(const unsigned char *data, int data_len, int offset, #define GS1_PARENS_PLACEHOLDER_MASK 0x20 /* Mask `(` or `)` by this if escaped (get BS (\x08) or HT (\x09)) */ /* Verify a GS1 input string */ -INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int *p_length, unsigned char reduced[], - int *p_reduced_length) { +INTERNAL int zint_gs1_verify(struct zint_symbol *symbol, unsigned char source[], int *p_length, + unsigned char reduced[], int *p_reduced_length) { int i, j; int error_value = 0; int bracket_level = 0, max_bracket_level = 0; @@ -1625,7 +1625,7 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int int length = *p_length; const char obracket = symbol->input_mode & GS1PARENS_MODE ? '(' : '['; const char cbracket = symbol->input_mode & GS1PARENS_MODE ? ')' : ']'; - const int ai_max = chr_cnt(source, length, obracket) + 1; /* Plus 1 so non-zero */ + const int ai_max = z_chr_cnt(source, length, obracket) + 1; /* Plus 1 so non-zero */ int *ai_value = (int *) z_alloca(sizeof(int) * ai_max); int *ai_location = (int *) z_alloca(sizeof(int) * ai_max); int *data_location = (int *) z_alloca(sizeof(int) * ai_max); @@ -1636,21 +1636,22 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int /* Detect control and extended ASCII characters */ for (i = 0; i < length; i++) { if (source[i] >= 128) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 250, "Extended ASCII characters are not supported by GS1"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 250, + "Extended ASCII characters are not supported by GS1"); } if (source[i] == '\0') { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 262, "NUL characters not permitted in GS1 mode"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 262, "NUL characters not permitted in GS1 mode"); } if (source[i] < 32) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 251, "Control characters are not supported by GS1"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 251, "Control characters are not supported by GS1"); } if (source[i] == 127) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 263, "DEL characters are not supported by GS1"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 263, "DEL characters are not supported by GS1"); } } if (source[0] != obracket) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 252, "Data does not start with an AI"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 252, "Data does not start with an AI"); } if ((symbol->input_mode & (ESCAPE_MODE | GS1PARENS_MODE)) == (ESCAPE_MODE | GS1PARENS_MODE)) { @@ -1713,18 +1714,18 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int if (bracket_level != 0) { /* Not all brackets are closed */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 253, "Malformed AI in input (brackets don\'t match)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 253, "Malformed AI in input (brackets don\'t match)"); } if (max_bracket_level > 1) { /* Nested brackets */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 254, "Found nested brackets in input"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 254, "Found nested brackets in input"); } if (max_ai_length > 4) { /* AI is too long */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 255, "Invalid AI at position %d in input (AI too long)", - max_ai_pos); + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 255, + "Invalid AI at position %d in input (AI too long)", max_ai_pos); } if (min_ai_length <= 1) { @@ -1732,14 +1733,14 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int - permits dummy "[]" workaround for ticket #204 data with no valid AI */ if (!(symbol->input_mode & GS1NOCHECK_MODE) || ai_single_digit || ai_zero_len_no_data) { /* AI is too short */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 256, "Invalid AI at position %d in input (AI too short)", - min_ai_pos); + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 256, + "Invalid AI at position %d in input (AI too short)", min_ai_pos); } } if (ai_nonnumeric) { /* Non-numeric data in AI */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 257, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 257, "Invalid AI at position %d in input (non-numeric characters in AI)", ai_nonnumeric_pos); } @@ -1751,7 +1752,7 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int if (source[i - 1] == obracket) { ai_location[ai_count] = i; for (j = 1; source[i + j] != cbracket; j++); - ai_value[ai_count] = to_int(source + i, j); + ai_value[ai_count] = z_to_int(source + i, j); ai_count++; i += j; } @@ -1772,7 +1773,7 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int } if (data_length[i] == 0) { /* No data for given AI */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 258, "Empty data field in input"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 258, "Empty data field in input"); } } @@ -1795,11 +1796,11 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int if (!gs1_lint(ai_value[i], local_source + data_location[i], data_length[i], &err_no, &err_posn, err_msg)) { if (err_no == 1) { - errtxtf(0, symbol, 260, "Invalid AI (%02d)", ai_value[i]); + z_errtxtf(0, symbol, 260, "Invalid AI (%02d)", ai_value[i]); } else if (err_no == 2 || err_no == 4) { /* 4 is backward-incompatible bad length */ - errtxtf(0, symbol, 259, "Invalid data length for AI (%02d)", ai_value[i]); + z_errtxtf(0, symbol, 259, "Invalid data length for AI (%02d)", ai_value[i]); } else { - ZEXT errtxtf(0, symbol, 261, "AI (%1$02d) position %2$d: %3$s", ai_value[i], err_posn, err_msg); + ZEXT z_errtxtf(0, symbol, 261, "AI (%1$02d) position %2$d: %3$s", ai_value[i], err_posn, err_msg); } /* For backward compatibility only error on unknown AI or bad length */ if (err_no == 1 || err_no == 2) { @@ -1821,7 +1822,7 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int reduced[j++] = '\x1D'; } if (i + 1 != length) { - int last_ai = to_int(source + i + 1, 2); + int last_ai = z_to_int(source + i + 1, 2); ai_latch = 0; /* The following values from GS1 General Specifications Release 25.0 Figure 7.8.5-2 "Element strings with predefined length using GS1 Application Identifiers" */ @@ -1863,21 +1864,21 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int } /* Helper to return standard GS1 check digit (GS1 General Specifications 7.9.1) */ -INTERNAL char gs1_check_digit(const unsigned char source[], const int length) { +INTERNAL char zint_gs1_check_digit(const unsigned char source[], const int length) { int i; int count = 0; int factor = length & 1 ? 3 : 1; for (i = 0; i < length; i++) { - count += factor * ctoi(source[i]); + count += factor * z_ctoi(source[i]); factor ^= 0x02; /* Toggles 1 and 3 */ } - return itoc((10 - (count % 10)) % 10); + return z_itoc((10 - (count % 10)) % 10); } /* Helper to expose `iso3166_alpha2()` */ -INTERNAL int gs1_iso3166_alpha2(const unsigned char *cc) { +INTERNAL int zint_gs1_iso3166_alpha2(const unsigned char *cc) { return iso3166_alpha2((const char *) cc); } diff --git a/backend/gs1.h b/backend/gs1.h index 872bbfec..b4f36d38 100644 --- a/backend/gs1.h +++ b/backend/gs1.h @@ -37,10 +37,10 @@ extern "C" { #endif /* __cplusplus */ -INTERNAL int gs1_verify(struct zint_symbol *symbol, unsigned char source[], int *p_length, unsigned char reduced[], - int *p_reduced_length); -INTERNAL char gs1_check_digit(const unsigned char source[], const int length); -INTERNAL int gs1_iso3166_alpha2(const unsigned char *cc); +INTERNAL int zint_gs1_verify(struct zint_symbol *symbol, unsigned char source[], int *p_length, + unsigned char reduced[], int *p_reduced_length); +INTERNAL char zint_gs1_check_digit(const unsigned char source[], const int length); +INTERNAL int zint_gs1_iso3166_alpha2(const unsigned char *cc); #ifdef __cplusplus } diff --git a/backend/hanxin.c b/backend/hanxin.c index da6b850d..0991c2ba 100644 --- a/backend/hanxin.c +++ b/backend/hanxin.c @@ -482,7 +482,7 @@ static void hx_define_mode(char *mode, const unsigned int ddata[], const int len /* Get optimal mode for each code point by tracing backwards */ for (i = length - 1; i >= 0; i--) { - j = posn(mode_types, cur_mode); + j = z_posn(mode_types, cur_mode); cur_mode = char_modes[i][j]; mode[i] = cur_mode; } @@ -519,15 +519,15 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned if (eci != 0) { /* Encoding ECI assignment number, according to Table 5 */ - bp = bin_append_posn(8, 4, binary, bp); /* ECI */ + bp = z_bin_append_posn(8, 4, binary, bp); /* ECI */ if (eci <= 127) { - bp = bin_append_posn(eci, 8, binary, bp); + bp = z_bin_append_posn(eci, 8, binary, bp); } else if (eci <= 16383) { - bp = bin_append_posn(2, 2, binary, bp); - bp = bin_append_posn(eci, 14, binary, bp); + bp = z_bin_append_posn(2, 2, binary, bp); + bp = z_bin_append_posn(eci, 14, binary, bp); } else { - bp = bin_append_posn(6, 3, binary, bp); - bp = bin_append_posn(eci, 21, binary, bp); + bp = z_bin_append_posn(6, 3, binary, bp); + bp = z_bin_append_posn(eci, 21, binary, bp); } } @@ -545,7 +545,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned case 'n': /* Numeric mode */ /* Mode indicator */ - bp = bin_append_posn(1, 4, binary, bp); + bp = z_bin_append_posn(1, 4, binary, bp); if (debug_print) { printf("Numeric (N%d): ", block_length); @@ -555,23 +555,23 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned i = 0; while (i < block_length) { - const int first = ctoi((const char) ddata[position + i]); + const int first = z_ctoi((const char) ddata[position + i]); count = 1; encoding_value = first; if (i + 1 < block_length && mode[position + i + 1] == 'n') { - const int second = ctoi((const char) ddata[position + i + 1]); + const int second = z_ctoi((const char) ddata[position + i + 1]); count = 2; encoding_value = (encoding_value * 10) + second; if (i + 2 < block_length && mode[position + i + 2] == 'n') { - const int third = ctoi((const char) ddata[position + i + 2]); + const int third = z_ctoi((const char) ddata[position + i + 2]); count = 3; encoding_value = (encoding_value * 10) + third; } } - bp = bin_append_posn(encoding_value, 10, binary, bp); + bp = z_bin_append_posn(encoding_value, 10, binary, bp); if (debug_print) { printf(" 0x%3x(%d)", encoding_value, encoding_value); @@ -583,13 +583,13 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned /* Mode terminator depends on number of characters in last group (Table 2) */ switch (count) { case 1: - bp = bin_append_posn(1021, 10, binary, bp); + bp = z_bin_append_posn(1021, 10, binary, bp); break; case 2: - bp = bin_append_posn(1022, 10, binary, bp); + bp = z_bin_append_posn(1022, 10, binary, bp); break; case 3: - bp = bin_append_posn(1023, 10, binary, bp); + bp = z_bin_append_posn(1023, 10, binary, bp); break; } @@ -601,7 +601,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned case 't': /* Text mode */ /* Mode indicator */ - bp = bin_append_posn(2, 4, binary, bp); + bp = z_bin_append_posn(2, 4, binary, bp); if (debug_print) { printf("Text (T%d):", block_length); @@ -615,7 +615,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned if (hx_getsubmode(ddata[i + position]) != submode) { /* Change submode */ - bp = bin_append_posn(62, 6, binary, bp); + bp = z_bin_append_posn(62, 6, binary, bp); submode = hx_getsubmode(ddata[i + position]); if (debug_print) { fputs(" SWITCH", stdout); @@ -628,7 +628,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned encoding_value = hx_lookup_text2(ddata[i + position]); } - bp = bin_append_posn(encoding_value, 6, binary, bp); + bp = z_bin_append_posn(encoding_value, 6, binary, bp); if (debug_print) { printf(" %.2x[ASC %.2x]", encoding_value, ddata[i + position]); @@ -637,7 +637,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned } /* Terminator */ - bp = bin_append_posn(63, 6, binary, bp); + bp = z_bin_append_posn(63, 6, binary, bp); if (debug_print) { fputs("\n", stdout); @@ -646,10 +646,10 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned case 'b': /* Binary Mode */ /* Mode indicator */ - bp = bin_append_posn(3, 4, binary, bp); + bp = z_bin_append_posn(3, 4, binary, bp); /* Count indicator */ - bp = bin_append_posn(block_length + double_byte, 13, binary, bp); + bp = z_bin_append_posn(block_length + double_byte, 13, binary, bp); if (debug_print) { printf("Binary Mode (B%d):", block_length + double_byte); @@ -660,7 +660,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned while (i < block_length) { /* 8-bit bytes with no conversion */ - bp = bin_append_posn(ddata[i + position], ddata[i + position] > 0xFF ? 16 : 8, binary, bp); + bp = z_bin_append_posn(ddata[i + position], ddata[i + position] > 0xFF ? 16 : 8, binary, bp); if (debug_print) { printf(" %02x", (int) ddata[i + position]); @@ -677,7 +677,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned /* Region One encoding */ /* Mode indicator */ if (position == 0 || mode[position - 1] != '2') { /* Unless previous mode Region Two */ - bp = bin_append_posn(4, 4, binary, bp); + bp = z_bin_append_posn(4, 4, binary, bp); } if (debug_print) { @@ -710,13 +710,13 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned printf(" %.3x[GB %.4x]", glyph, ddata[i + position]); } - bp = bin_append_posn(glyph, 12, binary, bp); + bp = z_bin_append_posn(glyph, 12, binary, bp); i++; } /* Terminator */ - bp = bin_append_posn(position + block_length == length || mode[position + block_length] != '2' - ? 4095 : 4094, 12, binary, bp); + bp = z_bin_append_posn(position + block_length == length || mode[position + block_length] != '2' + ? 4095 : 4094, 12, binary, bp); if (debug_print) { printf(" (TERM %x)\n", position + block_length == length || mode[position + block_length] != '2' @@ -728,7 +728,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned /* Region Two encoding */ /* Mode indicator */ if (position == 0 || mode[position - 1] != '1') { /* Unless previous mode Region One */ - bp = bin_append_posn(5, 4, binary, bp); + bp = z_bin_append_posn(5, 4, binary, bp); } if (debug_print) { @@ -748,13 +748,13 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned printf(" %.3x[GB %.4x]", glyph, ddata[i + position]); } - bp = bin_append_posn(glyph, 12, binary, bp); + bp = z_bin_append_posn(glyph, 12, binary, bp); i++; } /* Terminator */ - bp = bin_append_posn(position + block_length == length || mode[position + block_length] != '1' - ? 4095 : 4094, 12, binary, bp); + bp = z_bin_append_posn(position + block_length == length || mode[position + block_length] != '1' + ? 4095 : 4094, 12, binary, bp); if (debug_print) { printf(" (TERM %x)\n", position + block_length == length || mode[position + block_length] != '1' @@ -765,7 +765,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned case 'd': /* Double byte encoding */ /* Mode indicator */ - bp = bin_append_posn(6, 4, binary, bp); + bp = z_bin_append_posn(6, 4, binary, bp); if (debug_print) { printf("Double byte (H(d)%d):", block_length); @@ -787,12 +787,12 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned printf("%.4x ", glyph); } - bp = bin_append_posn(glyph, 15, binary, bp); + bp = z_bin_append_posn(glyph, 15, binary, bp); i++; } /* Terminator */ - bp = bin_append_posn(32767, 15, binary, bp); + bp = z_bin_append_posn(32767, 15, binary, bp); /* Terminator sequence of length 12 is a mistake - confirmed by Wang Yi */ @@ -811,7 +811,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned while (i < block_length) { /* Mode indicator */ - bp = bin_append_posn(7, 4, binary, bp); + bp = z_bin_append_posn(7, 4, binary, bp); first_byte = (ddata[i + position] & 0xff00) >> 8; second_byte = ddata[i + position] & 0xff; @@ -825,7 +825,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned printf(" %d", glyph); } - bp = bin_append_posn(glyph, 21, binary, bp); + bp = z_bin_append_posn(glyph, 21, binary, bp); i += 2; } @@ -1123,14 +1123,14 @@ static void hx_add_ecc(unsigned char fullstream[], const unsigned char datastrea const int table_d1_pos = ((version - 1) * 36) + ((ecc_level - 1) * 9); rs_t rs; - rs_init_gf(&rs, 0x163); /* x^8 + x^6 + x^5 + x + 1 = 0 */ + zint_rs_init_gf(&rs, 0x163); /* x^8 + x^6 + x^5 + x + 1 = 0 */ for (i = 0; i < 3; i++) { const int batch_size = hx_table_d1[table_d1_pos + (3 * i)]; const int data_length = hx_table_d1[table_d1_pos + (3 * i) + 1]; const int ecc_length = hx_table_d1[table_d1_pos + (3 * i) + 2]; - rs_init_code(&rs, ecc_length, 1); + zint_rs_init_code(&rs, ecc_length, 1); for (block = 0; block < batch_size; block++) { for (j = 0; j < data_length; j++) { @@ -1139,7 +1139,7 @@ static void hx_add_ecc(unsigned char fullstream[], const unsigned char datastrea input_position++; } - rs_encode(&rs, data_length, data_block, ecc_block); + zint_rs_encode(&rs, data_length, data_block, ecc_block); for (j = 0; j < ecc_length; j++) { fullstream[output_position++] = ecc_block[j]; @@ -1159,9 +1159,9 @@ static void hx_set_function_info(unsigned char *grid, const int size, const int /* Form function information string */ - bp = bin_append_posn(version + 20, 8, function_information, bp); - bp = bin_append_posn(ecc_level - 1, 2, function_information, bp); - bp = bin_append_posn(bitmask, 2, function_information, bp); + bp = z_bin_append_posn(version + 20, 8, function_information, bp); + bp = z_bin_append_posn(ecc_level - 1, 2, function_information, bp); + bp = z_bin_append_posn(bitmask, 2, function_information, bp); for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) { @@ -1171,12 +1171,12 @@ static void hx_set_function_info(unsigned char *grid, const int size, const int } } - rs_init_gf(&rs, 0x13); - rs_init_code(&rs, 4, 1); - rs_encode(&rs, 3, fi_cw, fi_ecc); + zint_rs_init_gf(&rs, 0x13); + zint_rs_init_code(&rs, 4, 1); + zint_rs_encode(&rs, 3, fi_cw, fi_ecc); for (i = 0; i < 4; i++) { - bp = bin_append_posn(fi_ecc[i], 4, function_information, bp); + bp = z_bin_append_posn(fi_ecc[i], 4, function_information, bp); } /* Previously added alternating filler pattern here (as does BWIPP) but not mentioned in ISO/IEC 20830:2021 and @@ -1477,7 +1477,7 @@ static int hx_apply_bitmask(unsigned char *grid, const int size, const int versi } /* Han Xin Code - main */ -INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int warn_number = 0; int est_binlen; int ecc_level = symbol->option_1; @@ -1490,7 +1490,7 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in int bin_len; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; - const int eci_length_segs = get_eci_length_segs(segs, seg_count); + const int eci_length_segs = zint_get_eci_length_segs(segs, seg_count); struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count); unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * eci_length_segs); char *mode = (char *) z_alloca(eci_length_segs); @@ -1500,7 +1500,7 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in unsigned char *picket_fence; unsigned char *grid; - segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECI & protect lengths) */ + z_segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECI & protect lengths) */ /* If ZINT_FULL_MULTIBYTE set use Hanzi mode in DATA_MODE or for non-GB 18030 in UNICODE_MODE */ full_multibyte = (symbol->option_3 & 0xFF) == ZINT_FULL_MULTIBYTE; @@ -1509,13 +1509,13 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in user_mask = 0; /* Ignore */ } - 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 */ } if ((symbol->input_mode & 0x07) == DATA_MODE) { - if (gb18030_cpy_segs(symbol, local_segs, seg_count, ddata, full_multibyte)) { - return ZINT_ERROR_MEMORY; /* `gb18030_cpy_segs()` only fails with OOM */ + if (zint_gb18030_cpy_segs(symbol, local_segs, seg_count, ddata, full_multibyte)) { + return ZINT_ERROR_MEMORY; /* `zint_gb18030_cpy_segs()` only fails with OOM */ } } else { unsigned int *dd = ddata; @@ -1523,29 +1523,29 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in int done = 0, eci = local_segs[i].eci; if (local_segs[i].eci != 32 || seg_count > 1) { /* Unless ECI 32 (GB 18030) or have multiple segments */ /* Try other conversions (ECI 0 defaults to ISO/IEC 8859-1) */ - int error_number = gb18030_utf8_to_eci(local_segs[i].eci, local_segs[i].source, &local_segs[i].length, - dd, full_multibyte); + int error_number = zint_gb18030_utf8_to_eci(local_segs[i].eci, local_segs[i].source, + &local_segs[i].length, dd, full_multibyte); if (error_number == 0) { done = 1; } else if (local_segs[i].eci || seg_count > 1) { - return errtxtf(error_number, symbol, 545, "Invalid character in input for ECI '%d'", + return z_errtxtf(error_number, symbol, 545, "Invalid character in input for ECI '%d'", local_segs[i].eci); } } if (!done) { /* Try GB 18030 */ - int error_number = gb18030_utf8(symbol, local_segs[i].source, &local_segs[i].length, dd); + int error_number = zint_gb18030_utf8(symbol, local_segs[i].source, &local_segs[i].length, dd); if (error_number != 0) { return error_number; } if (local_segs[i].eci != 32) { - warn_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 543, + warn_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 543, "Converted to GB 18030 but no ECI specified"); } eci = 32; } - if (raw_text && rt_cpy_seg_ddata(symbol, i, &local_segs[i], eci, dd)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg_ddata()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg_ddata(symbol, i, &local_segs[i], eci, dd)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg_ddata()` only fails with OOM */ } dd += local_segs[i].length; } @@ -1583,7 +1583,7 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in if (version == 85) { free(binary); - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 541, "Input too long, requires %d codewords (maximum 3264)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 541, "Input too long, requires %d codewords (maximum 3264)", codewords); } @@ -1598,14 +1598,15 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in if ((symbol->option_2 != 0) && (symbol->option_2 < version)) { free(binary); if (ecc_level == 1) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 542, - "Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)", - symbol->option_2, codewords, hx_data_codewords[ecc_level - 1][symbol->option_2 - 1]); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 542, + "Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)", + symbol->option_2, codewords, + hx_data_codewords[ecc_level - 1][symbol->option_2 - 1]); } - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 542, - "Input too long for Version %1$d, ECC %2$d, requires %3$d codewords (maximum %4$d)", - symbol->option_2, ecc_level, codewords, - hx_data_codewords[ecc_level - 1][symbol->option_2 - 1]); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 542, + "Input too long for Version %1$d, ECC %2$d, requires %3$d codewords (maximum %4$d)", + symbol->option_2, ecc_level, codewords, + hx_data_codewords[ecc_level - 1][symbol->option_2 - 1]); } /* If there is spare capacity, increase the level of ECC */ @@ -1653,7 +1654,7 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in fputc('\n', stdout); } #ifdef ZINT_TEST - if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, datastream, data_codewords); + if (symbol->debug & ZINT_DEBUG_TEST) z_debug_test_codeword_dump(symbol, datastream, data_codewords); #endif hx_setup_grid(grid, size, version); @@ -1700,7 +1701,7 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in const int r = i * size; for (j = 0; j < size; j++) { if (grid[r + j] & 0x01) { - set_module(symbol, i, j); + z_set_module(symbol, i, j); } } symbol->row_height[i] = 1; diff --git a/backend/imail.c b/backend/imail.c index 000d3252..61df7596 100644 --- a/backend/imail.c +++ b/backend/imail.c @@ -245,9 +245,9 @@ static unsigned short USPS_MSB_Math_CRC11GenerateFrameCheckSequence(unsigned cha return FrameCheckSequence; } -INTERNAL int daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height); +INTERNAL int zint_daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height); -INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_usps_imail(struct zint_symbol *symbol, unsigned char source[], int length) { char data_pattern[200]; int error_number = 0; int i, j, read; @@ -264,10 +264,10 @@ INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 32) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 450, "Input length %d too long (maximum 32)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 450, "Input length %d too long (maximum 32)", length); } - if ((i = not_sane(SODIUM_MNS_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 451, + if ((i = z_not_sane(SODIUM_MNS_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 451, "Invalid character at position %d in input (digits and \"-\" only)", i); } @@ -300,17 +300,17 @@ INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int } if (strlen(tracker) != 20) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 452, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 452, "Invalid length for tracking code (20 characters required)"); } if (tracker[1] > '4') { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 454, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 454, "Barcode Identifier (second character) out of range (0 to 4)"); } zip_len = (int) strlen(zip); if (zip_len != 0 && zip_len != 5 && zip_len != 9 && zip_len != 11) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 453, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 453, "Invalid length for ZIP code (5, 9 or 11 characters required)"); } @@ -318,62 +318,62 @@ INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int /* Routing code first */ - large_load_str_u64(&accum, (const unsigned char *) zip, zip_len); + zint_large_load_str_u64(&accum, ZCUCP(zip), zip_len); /* add weight to routing code */ if (zip_len > 9) { - large_add_u64(&accum, 1000100001); + zint_large_add_u64(&accum, 1000100001); } else if (zip_len > 5) { - large_add_u64(&accum, 100001); + zint_large_add_u64(&accum, 100001); } else if (zip_len > 0) { - large_add_u64(&accum, 1); + zint_large_add_u64(&accum, 1); } /* tracking code */ /* multiply by 10 */ - large_mul_u64(&accum, 10); + zint_large_mul_u64(&accum, 10); /* add first digit of tracker */ - large_add_u64(&accum, ctoi(tracker[0])); + zint_large_add_u64(&accum, z_ctoi(tracker[0])); /* multiply by 5 */ - large_mul_u64(&accum, 5); + zint_large_mul_u64(&accum, 5); /* add second digit */ - large_add_u64(&accum, ctoi(tracker[1])); + zint_large_add_u64(&accum, z_ctoi(tracker[1])); /* and then the rest */ for (read = 2; read < 20; read++) { - large_mul_u64(&accum, 10); - large_add_u64(&accum, ctoi(tracker[read])); + zint_large_mul_u64(&accum, 10); + zint_large_add_u64(&accum, z_ctoi(tracker[read])); } /* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */ - large_load(&byte_array_reg, &accum); + zint_large_load(&byte_array_reg, &accum); - large_unset_bit(&byte_array_reg, 102); - large_unset_bit(&byte_array_reg, 103); + zint_large_unset_bit(&byte_array_reg, 102); + zint_large_unset_bit(&byte_array_reg, 103); - large_uchar_array(&byte_array_reg, byte_array, 13, 8 /*bits*/); + zint_large_uchar_array(&byte_array_reg, byte_array, 13, 8 /*bits*/); usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array); /* *** Step 3 - Conversion from Binary Data to Codewords *** */ /* start with codeword J which is base 636 */ - codeword[9] = (unsigned int) large_div_u64(&accum, 636); + codeword[9] = (unsigned int) zint_large_div_u64(&accum, 636); /* then codewords I to B with base 1365 */ for (j = 8; j > 0; j--) { - codeword[j] = (unsigned int) large_div_u64(&accum, 1365); + codeword[j] = (unsigned int) zint_large_div_u64(&accum, 1365); } - codeword[0] = (unsigned int) large_lo(&accum); + codeword[0] = (unsigned int) zint_large_lo(&accum); /* *** Step 4 - Inserting Additional Information into Codewords *** */ @@ -412,18 +412,18 @@ INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int j += 1; if (bar_map[i + 65] == 0) j += 2; - data_pattern[i] = itoc(j); + data_pattern[i] = z_itoc(j); } /* Translate 4-state data pattern to symbol */ read = 0; for (i = 0; i < 65; i++) { if ((data_pattern[i] == '1') || (data_pattern[i] == '0')) { - set_module(symbol, 0, read); + z_set_module(symbol, 0, read); } - set_module(symbol, 1, read); + z_set_module(symbol, 1, read); if ((data_pattern[i] == '2') || (data_pattern[i] == '0')) { - set_module(symbol, 2, read); + z_set_module(symbol, 2, read); } read += 2; } @@ -440,17 +440,17 @@ INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int symbol->row_height[0] = 2.0855f; /* 0.0485 * 43 */ symbol->row_height[1] = 2.06399989f; /* 0.048 * 43 */ /* Note using max X for minimum and min X for maximum */ - error_number = daft_set_height(symbol, min_height, max_height); + error_number = zint_daft_set_height(symbol, min_height, max_height); } else { symbol->row_height[0] = 3.0f; symbol->row_height[1] = 2.0f; - (void) daft_set_height(symbol, 0.0f, 0.0f); + (void) zint_daft_set_height(symbol, 0.0f, 0.0f); } symbol->rows = 3; symbol->width = read - 1; - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; diff --git a/backend/large.c b/backend/large.c index 4b011cbc..d0413619 100644 --- a/backend/large.c +++ b/backend/large.c @@ -1,7 +1,7 @@ /* large.c - Handles binary manipulation of large numbers */ /* libzint - the open source barcode library - Copyright (C) 2008-2023 Robin Stuart + Copyright (C) 2008-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -30,7 +30,7 @@ */ /* SPDX-License-Identifier: BSD-3-Clause */ -/* `large_mul_u64()` and `large_div_u64()` are adapted from articles by F. W. Jacob +/* `zint_large_mul_u64()` and `zint_large_div_u64()` are adapted from articles by F. W. Jacob * https://www.codeproject.com/Tips/618570/UInt-Multiplication-Squaring * "This article, along with any associated source code and files, is licensed under The BSD License" * http://www.codeproject.com/Tips/785014/UInt-Division-Modulus @@ -40,7 +40,7 @@ * "You are free to use, copy, and distribute any of the code on this web site, whether modified by you or not." * https://web.archive.org/web/20190716204559/http://www.hackersdelight.org/permissions.htm * - * `clz_u64()` and other bits and pieces are adapted from r128.h by Alan Hickman (fahickman) + * `zint_clz_u64()` and other bits and pieces are adapted from r128.h by Alan Hickman (fahickman) * https://github.com/fahickman/r128/blob/master/r128.h * "R128 is released into the public domain. See LICENSE for details." LICENSE is The Unlicense. */ @@ -52,7 +52,7 @@ #define MASK32 0xFFFFFFFF /* Convert decimal string `s` of (at most) length `length` to 64-bit and place in 128-bit `t` */ -INTERNAL void large_load_str_u64(large_uint *t, const unsigned char *s, const int length) { +INTERNAL void zint_large_load_str_u64(large_uint *t, const unsigned char *s, const int length) { uint64_t val = 0; const unsigned char *const se = s + length; for (; s < se && z_isdigit(*s); s++) { @@ -64,13 +64,13 @@ INTERNAL void large_load_str_u64(large_uint *t, const unsigned char *s, const in } /* Add 128-bit `s` to 128-bit `t` */ -INTERNAL void large_add(large_uint *t, const large_uint *s) { +INTERNAL void zint_large_add(large_uint *t, const large_uint *s) { t->lo += s->lo; t->hi += s->hi + (t->lo < s->lo); } /* Add 64-bit `s` to 128-bit `t` */ -INTERNAL void large_add_u64(large_uint *t, const uint64_t s) { +INTERNAL void zint_large_add_u64(large_uint *t, const uint64_t s) { t->lo += s; if (t->lo < s) { t->hi++; @@ -78,7 +78,7 @@ INTERNAL void large_add_u64(large_uint *t, const uint64_t s) { } /* Subtract 64-bit `s` from 128-bit `t` */ -INTERNAL void large_sub_u64(large_uint *t, const uint64_t s) { +INTERNAL void zint_large_sub_u64(large_uint *t, const uint64_t s) { uint64_t r = t->lo - s; if (r > t->lo) { t->hi--; @@ -107,7 +107,7 @@ INTERNAL void large_sub_u64(large_uint *t, const uint64_t s) { * p10 * p11 + k10 */ -INTERNAL void large_mul_u64(large_uint *t, const uint64_t s) { +INTERNAL void zint_large_mul_u64(large_uint *t, const uint64_t s) { uint64_t thi = t->hi; uint64_t tlo0 = t->lo & MASK32; uint64_t tlo1 = t->lo >> 32; @@ -141,7 +141,7 @@ static int clz_u64(uint64_t x) { } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int clz_u64_test(uint64_t x) { +INTERNAL int zint_test_clz_u64(uint64_t x) { return clz_u64(x); } #endif @@ -149,7 +149,7 @@ INTERNAL int clz_u64_test(uint64_t x) { /* Divide 128-bit dividend `t` by 64-bit divisor `v`, returning 64-bit remainder * See Jacob `divmod128by128/64()` and Warren Section 9–2 (divmu64.c.txt) * Note digits are 32-bit parts */ -INTERNAL uint64_t large_div_u64(large_uint *t, uint64_t v) { +INTERNAL uint64_t zint_large_div_u64(large_uint *t, uint64_t v) { const uint64_t b = 0x100000000; /* Number base (2**32) */ uint64_t qhi = 0; /* High digit of returned quotient */ @@ -241,7 +241,7 @@ INTERNAL uint64_t large_div_u64(large_uint *t, uint64_t v) { } /* Unset a bit (zero-based) */ -INTERNAL void large_unset_bit(large_uint *t, const int bit) { +INTERNAL void zint_large_unset_bit(large_uint *t, const int bit) { if (bit < 64) { t->lo &= ~(((uint64_t) 1) << bit); } else if (bit < 128) { @@ -250,7 +250,7 @@ INTERNAL void large_unset_bit(large_uint *t, const int bit) { } /* Output large_uint into an unsigned int array of size `size`, each element containing `bits` bits */ -INTERNAL void large_uint_array(const large_uint *t, unsigned int *uint_array, const int size, int bits) { +INTERNAL void zint_large_uint_array(const large_uint *t, unsigned int *uint_array, const int size, int bits) { int i, j; uint64_t mask; if (bits <= 0) { @@ -280,12 +280,12 @@ INTERNAL void large_uint_array(const large_uint *t, unsigned int *uint_array, co } } -/* As `large_uint_array()` above, except output to unsigned char array */ -INTERNAL void large_uchar_array(const large_uint *t, unsigned char *uchar_array, const int size, int bits) { +/* As `zint_large_uint_array()` above, except output to unsigned char array */ +INTERNAL void zint_large_uchar_array(const large_uint *t, unsigned char *uchar_array, const int size, int bits) { int i; unsigned int *uint_array = (unsigned int *) z_alloca(sizeof(unsigned int) * (size ? size : 1)); - large_uint_array(t, uint_array, size, bits); + zint_large_uint_array(t, uint_array, size, bits); for (i = 0; i < size; i++) { uchar_array[i] = (unsigned char) uint_array[i]; @@ -293,11 +293,11 @@ INTERNAL void large_uchar_array(const large_uint *t, unsigned char *uchar_array, } /* Format large_uint into buffer, which should be at least 35 chars in size */ -INTERNAL char *large_dump(const large_uint *t, char *buf) { - unsigned int tlo1 = (unsigned int) (large_lo(t) >> 32); - unsigned int tlo0 = (unsigned int) (large_lo(t) & MASK32); - unsigned int thi1 = (unsigned int) (large_hi(t) >> 32); - unsigned int thi0 = (unsigned int) (large_hi(t) & MASK32); +INTERNAL char *zint_large_dump(const large_uint *t, char *buf) { + unsigned int tlo1 = (unsigned int) (zint_large_lo(t) >> 32); + unsigned int tlo0 = (unsigned int) (zint_large_lo(t) & MASK32); + unsigned int thi1 = (unsigned int) (zint_large_hi(t) >> 32); + unsigned int thi0 = (unsigned int) (zint_large_hi(t) & MASK32); if (thi1) { sprintf(buf, "0x%X%08X%08X%08X", thi1, thi0, tlo1, tlo0); @@ -312,10 +312,10 @@ INTERNAL char *large_dump(const large_uint *t, char *buf) { } /* Output formatted large_uint to stdout */ -INTERNAL void large_print(const large_uint *t) { +INTERNAL void zint_large_print(const large_uint *t) { char buf[35]; /* 2 (0x) + 32 (hex) + 1 */ - puts(large_dump(t, buf)); + puts(zint_large_dump(t, buf)); } /* vim: set ts=4 sw=4 et : */ diff --git a/backend/large.h b/backend/large.h index b28c08d8..1f9d0ff0 100644 --- a/backend/large.h +++ b/backend/large.h @@ -2,7 +2,7 @@ /* libzint - the open source barcode library - Copyright (C) 2008-2023 Robin Stuart + Copyright (C) 2008-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -40,44 +40,44 @@ extern "C" { typedef struct { uint64_t lo; uint64_t hi; } large_uint; -#define large_lo(s) ((s)->lo) -#define large_hi(s) ((s)->hi) +#define zint_large_lo(s) ((s)->lo) +#define zint_large_hi(s) ((s)->hi) /* Set 128-bit `t` from 128-bit `s` */ -#define large_load(t, s) do { *(t) = *(s); } while (0) +#define zint_large_load(t, s) do { *(t) = *(s); } while (0) /* Set 128-bit `t` from 64-bit `s` */ -#define large_load_u64(t, s) do { (t)->lo = (s); (t)->hi = 0; } while (0) +#define zint_large_load_u64(t, s) do { (t)->lo = (s); (t)->hi = 0; } while (0) /* Convert decimal string `s` of (at most) length `length` to 64-bit and place in 128-bit `t` */ -INTERNAL void large_load_str_u64(large_uint *t, const unsigned char *s, const int length); +INTERNAL void zint_large_load_str_u64(large_uint *t, const unsigned char *s, const int length); /* Add 128-bit `s` to 128-bit `t` */ -INTERNAL void large_add(large_uint *t, const large_uint *s); +INTERNAL void zint_large_add(large_uint *t, const large_uint *s); /* Add 64-bit `s` to 128-bit `t` */ -INTERNAL void large_add_u64(large_uint *t, const uint64_t s); +INTERNAL void zint_large_add_u64(large_uint *t, const uint64_t s); /* Subtract 64-bit `s` from 128-bit `t` */ -INTERNAL void large_sub_u64(large_uint *t, const uint64_t s); +INTERNAL void zint_large_sub_u64(large_uint *t, const uint64_t s); /* Multiply 128-bit `t` by 64-bit `s` */ -INTERNAL void large_mul_u64(large_uint *t, const uint64_t s); +INTERNAL void zint_large_mul_u64(large_uint *t, const uint64_t s); /* Divide 128-bit dividend `t` by 64-bit divisor `v`, returning 64-bit remainder */ -INTERNAL uint64_t large_div_u64(large_uint *t, uint64_t v); +INTERNAL uint64_t zint_large_div_u64(large_uint *t, uint64_t v); /* Unset a bit (zero-based) */ -INTERNAL void large_unset_bit(large_uint *t, const int bit); +INTERNAL void zint_large_unset_bit(large_uint *t, const int bit); /* Output large_uint into an unsigned int array of size `size`, each element containing `bits` bits */ -INTERNAL void large_uint_array(const large_uint *t, unsigned int *uint_array, const int size, int bits); +INTERNAL void zint_large_uint_array(const large_uint *t, unsigned int *uint_array, const int size, int bits); /* As `large_uint_array()` above, except output to unsigned char array */ -INTERNAL void large_uchar_array(const large_uint *t, unsigned char *uchar_array, const int size, int bits); +INTERNAL void zint_large_uchar_array(const large_uint *t, unsigned char *uchar_array, const int size, int bits); /* Format large_uint into buffer, which should be at least 35 chars in size */ -INTERNAL char *large_dump(const large_uint *t, char *buf); +INTERNAL char *zint_large_dump(const large_uint *t, char *buf); /* Output formatted large_uint to stdout */ -INTERNAL void large_print(const large_uint *t); +INTERNAL void zint_large_print(const large_uint *t); #ifdef __cplusplus } diff --git a/backend/library.c b/backend/library.c index 989dbcfe..fbcfc3b7 100644 --- a/backend/library.c +++ b/backend/library.c @@ -91,7 +91,7 @@ struct zint_symbol *ZBarcode_Create(void) { return symbol; } -INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */ +INTERNAL void zint_vector_free(struct zint_symbol *symbol); /* Free vector structures */ /* Free any output buffers that may have been created and initialize output fields */ void ZBarcode_Clear(struct zint_symbol *symbol) { @@ -126,10 +126,10 @@ void ZBarcode_Clear(struct zint_symbol *symbol) { } symbol->memfile_size = 0; - rt_free_segs(symbol); + z_rt_free_segs(symbol); /* If there is a rendered version, ensure its memory is released */ - vector_free(symbol); + zint_vector_free(symbol); } /* Free any output buffers that may have been created and reset all fields to defaults */ @@ -143,8 +143,8 @@ void ZBarcode_Reset(struct zint_symbol *symbol) { if (symbol->memfile != NULL) free(symbol->memfile); - rt_free_segs(symbol); - vector_free(symbol); + z_rt_free_segs(symbol); + zint_vector_free(symbol); memset(symbol, 0, sizeof(*symbol)); set_symbol_defaults(symbol); @@ -161,102 +161,98 @@ void ZBarcode_Delete(struct zint_symbol *symbol) { if (symbol->memfile != NULL) free(symbol->memfile); - rt_free_segs(symbol); - vector_free(symbol); + z_rt_free_segs(symbol); + zint_vector_free(symbol); free(symbol); } /* Symbology handlers */ -INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN system barcodes */ -INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 3 from 9 (or Code 39) */ -INTERNAL int pzn(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmazentral Nummer (PZN) */ -/* Extended Code 3 from 9 (or Code 39+) */ -INTERNAL int excode39(struct zint_symbol *symbol, unsigned char source[], int length); -/* Codabar - a simple substitution cipher */ -INTERNAL int codabar(struct zint_symbol *symbol, unsigned char source[], int length); -/* Code 2 of 5 Standard (& Matrix) */ -INTERNAL int c25standard(struct zint_symbol *symbol, unsigned char source[], int length); -INTERNAL int c25ind(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Industrial */ -INTERNAL int c25iata(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 IATA */ -INTERNAL int c25inter(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Interleaved */ -INTERNAL int c25logic(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Data Logic */ -INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int length); /* ITF-14 */ -INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Leitcode */ -INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Identcode */ -/* Code 93 - a re-working of Code 39+, generates 2 check digits */ -INTERNAL int code93(struct zint_symbol *symbol, unsigned char source[], int length); -INTERNAL int code128(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 128 and NVE-18 */ -INTERNAL int gs1_128(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-128 (GS1-128) */ -INTERNAL int code11(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 11 */ -INTERNAL int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length); /* MSI Plessey */ -INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen ASCII */ -INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen Numeric */ -INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int length); /* Plessey Code */ -INTERNAL int pharma(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode One Track */ -INTERNAL int flat(struct zint_symbol *symbol, unsigned char source[], int length); /* Flattermarken */ -INTERNAL int fim(struct zint_symbol *symbol, unsigned char source[], int length); /* Facing Identification Mark */ -INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode Two Track */ -INTERNAL int postnet(struct zint_symbol *symbol, unsigned char source[], int length); /* Postnet */ -INTERNAL int planet(struct zint_symbol *symbol, unsigned char source[], int length); /* PLANET */ -/* Intelligent Mail (aka USPS OneCode) */ -INTERNAL int usps_imail(struct zint_symbol *symbol, unsigned char source[], int length); -INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int length); /* RM4SCC */ -INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int length); /* Australia Post 4-state */ -INTERNAL int code16k(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 16k */ -INTERNAL int pdf417(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* PDF417 */ -INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* Micro PDF417 */ -INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* Maxicode */ -INTERNAL int dbar_omn(struct zint_symbol *symbol, unsigned char source[], int length); /* DataBar Omnidirectional */ -INTERNAL int dbar_ltd(struct zint_symbol *symbol, unsigned char source[], int length); /* DataBar Limited */ -INTERNAL int dbar_exp(struct zint_symbol *symbol, unsigned char source[], int length); /* DataBar Expanded */ -INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int length); /* Composite Symbology */ -INTERNAL int kix(struct zint_symbol *symbol, unsigned char source[], int length); /* TNT KIX Code */ -INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* Aztec Code */ -INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int length); /* Italian Pharmacode */ -INTERNAL int daft(struct zint_symbol *symbol, unsigned char source[], int length); /* DAFT Code */ -INTERNAL int ean14(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-14 */ -INTERNAL int nve18(struct zint_symbol *symbol, unsigned char source[], int length); /* NVE-18 */ -INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int length); /* Micro QR Code */ -INTERNAL int azrune(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Runes */ -INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int length); /* Korea Post */ -INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int length); /* Japanese Post */ -INTERNAL int code49(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 49 */ -INTERNAL int channel(struct zint_symbol *symbol, unsigned char source[], int length); /* Channel Code */ -INTERNAL int codeone(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* Code One */ -INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* Grid Matrix */ -INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* Han Xin */ -INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* DotCode */ -INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int length); /* Codablock */ -INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int length); /* UPNQR */ -INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* QR Code */ -/* Data Matrix (IEC16022) */ -INTERNAL int datamatrix(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); -/* VIN Code (Vehicle Identification Number) */ -INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length); -/* Royal Mail 2D Mailmark */ -INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int length); -/* Royal Mail 4-state Mailmark */ -INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int length); -INTERNAL int upu_s10(struct zint_symbol *symbol, unsigned char source[], int length); /* Universal Postal Union S10 */ -INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* Ultracode */ -INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); /* rMQR */ -INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length); /* DPD Code */ -INTERNAL int bc412(struct zint_symbol *symbol, unsigned char source[], int length); /* BC412 */ -INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int length); /* DX Film Edge Barcode */ + +/* Declaration shorthands (adapted from ZXing-C++ "core/src/libzint/stubs.c") */ +#define LIB_DECL_FUNC_SRC(fn) int fn(struct zint_symbol *symbol, unsigned char source[], int length) +#define LIB_DECL_FUNC_SEG(fn) int fn(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) + +INTERNAL LIB_DECL_FUNC_SRC(zint_code11); /* Code 11 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_c25standard); /* Code 2 of 5 Standard (& Matrix) */ +INTERNAL LIB_DECL_FUNC_SRC(zint_c25inter); /* Code 2 of 5 Interleaved */ +INTERNAL LIB_DECL_FUNC_SRC(zint_c25iata); /* Code 2 of 5 IATA */ +INTERNAL LIB_DECL_FUNC_SRC(zint_c25logic); /* Code 2 of 5 Data Logic */ +INTERNAL LIB_DECL_FUNC_SRC(zint_c25ind); /* Code 2 of 5 Industrial */ +INTERNAL LIB_DECL_FUNC_SRC(zint_code39); /* Code 3 from 9 (or Code 39) */ +INTERNAL LIB_DECL_FUNC_SRC(zint_excode39); /* Extended Code 3 from 9 (or Code 39+) */ +INTERNAL LIB_DECL_FUNC_SRC(zint_eanx); /* EAN system barcodes */ +INTERNAL LIB_DECL_FUNC_SRC(zint_gs1_128); /* EAN-128 (GS1-128) */ +INTERNAL LIB_DECL_FUNC_SRC(zint_codabar); /* Codabar - a simple substitution cipher */ +INTERNAL LIB_DECL_FUNC_SRC(zint_code128); /* Code 128 and NVE-18 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_dpleit); /* Deutsche Post Leitcode */ +INTERNAL LIB_DECL_FUNC_SRC(zint_dpident); /* Deutsche Post Identcode */ +INTERNAL LIB_DECL_FUNC_SRC(zint_code16k); /* Code 16k */ +INTERNAL LIB_DECL_FUNC_SRC(zint_code49); /* Code 49 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_code93); /* Code 93 - a re-working of Code 39+, generates 2 check digits */ +INTERNAL LIB_DECL_FUNC_SRC(zint_flat); /* Flattermarken */ +INTERNAL LIB_DECL_FUNC_SRC(zint_dbar_omn); /* DataBar Omnidirectional */ +INTERNAL LIB_DECL_FUNC_SRC(zint_dbar_ltd); /* DataBar Limited */ +INTERNAL LIB_DECL_FUNC_SRC(zint_dbar_exp); /* DataBar Expanded */ +INTERNAL LIB_DECL_FUNC_SRC(zint_telepen); /* Telepen ASCII */ +INTERNAL LIB_DECL_FUNC_SRC(zint_postnet); /* Postnet */ +INTERNAL LIB_DECL_FUNC_SRC(zint_msi_plessey); /* MSI Plessey */ +INTERNAL LIB_DECL_FUNC_SRC(zint_fim); /* Facing Identification Mark */ +INTERNAL LIB_DECL_FUNC_SRC(zint_pharma); /* Pharmacode One Track */ +INTERNAL LIB_DECL_FUNC_SRC(zint_pzn); /* Pharmazentral Nummer (PZN) */ +INTERNAL LIB_DECL_FUNC_SRC(zint_pharma_two); /* Pharmacode Two Track */ +INTERNAL LIB_DECL_FUNC_SEG(zint_pdf417); /* PDF417 */ +INTERNAL LIB_DECL_FUNC_SEG(zint_maxicode); /* Maxicode */ +INTERNAL LIB_DECL_FUNC_SEG(zint_qrcode); /* QR Code */ +INTERNAL LIB_DECL_FUNC_SRC(zint_auspost); /* Australia Post 4-state */ +INTERNAL LIB_DECL_FUNC_SRC(zint_rm4scc); /* RM4SCC */ +INTERNAL LIB_DECL_FUNC_SEG(zint_datamatrix); /* Data Matrix (IEC16022) */ +INTERNAL LIB_DECL_FUNC_SRC(zint_ean14); /* EAN-14 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_vin); /* VIN Code (Vehicle Identification Number) */ +INTERNAL LIB_DECL_FUNC_SRC(zint_codablockf); /* Codablock */ +INTERNAL LIB_DECL_FUNC_SRC(zint_nve18); /* NVE-18 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_japanpost); /* Japanese Post */ +INTERNAL LIB_DECL_FUNC_SRC(zint_koreapost); /* Korea Post */ +INTERNAL LIB_DECL_FUNC_SRC(zint_planet); /* PLANET */ +INTERNAL LIB_DECL_FUNC_SEG(zint_micropdf417); /* Micro PDF417 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_usps_imail); /* Intelligent Mail (aka USPS OneCode) */ +INTERNAL LIB_DECL_FUNC_SRC(zint_plessey); /* Plessey Code */ +INTERNAL LIB_DECL_FUNC_SRC(zint_telepen_num); /* Telepen Numeric */ +INTERNAL LIB_DECL_FUNC_SRC(zint_itf14); /* ITF-14 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_kix); /* TNT KIX Code */ +INTERNAL LIB_DECL_FUNC_SEG(zint_aztec); /* Aztec Code */ +INTERNAL LIB_DECL_FUNC_SRC(zint_daft); /* DAFT Code */ +INTERNAL LIB_DECL_FUNC_SRC(zint_dpd); /* DPD Code */ +INTERNAL LIB_DECL_FUNC_SRC(zint_microqr); /* Micro QR Code */ +INTERNAL LIB_DECL_FUNC_SEG(zint_dotcode); /* DotCode */ +INTERNAL LIB_DECL_FUNC_SEG(zint_hanxin); /* Han Xin */ +INTERNAL LIB_DECL_FUNC_SRC(zint_mailmark_2d); /* Royal Mail 2D Mailmark */ +INTERNAL LIB_DECL_FUNC_SRC(zint_upu_s10); /* Universal Postal Union S10 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_mailmark_4s); /* Royal Mail 4-state Mailmark */ +INTERNAL LIB_DECL_FUNC_SRC(zint_azrune); /* Aztec Runes */ +INTERNAL LIB_DECL_FUNC_SRC(zint_code32); /* Italian Pharmacode */ +INTERNAL LIB_DECL_FUNC_SRC(zint_composite); /* Composite Symbology */ +INTERNAL LIB_DECL_FUNC_SRC(zint_channel); /* Channel Code */ +INTERNAL LIB_DECL_FUNC_SEG(zint_codeone); /* Code One */ +INTERNAL LIB_DECL_FUNC_SEG(zint_gridmatrix); /* Grid Matrix */ +INTERNAL LIB_DECL_FUNC_SRC(zint_upnqr); /* UPNQR */ +INTERNAL LIB_DECL_FUNC_SEG(zint_ultra); /* Ultracode */ +INTERNAL LIB_DECL_FUNC_SEG(zint_rmqr); /* rMQR */ +INTERNAL LIB_DECL_FUNC_SRC(zint_bc412); /* BC412 */ +INTERNAL LIB_DECL_FUNC_SRC(zint_dxfilmedge); /* DX Film Edge Barcode */ /* Output handlers */ /* Plot to BMP/GIF/PCX/PNG/TIF */ -INTERNAL int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); +INTERNAL int zint_plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Plot to EMF/EPS/SVG */ -INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type); +INTERNAL int zint_plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type); /* Prefix error message with Error/Warning */ static int error_tag(int error_number, struct zint_symbol *symbol, const int err_id, const char *error_string) { if (error_number != 0) { if (error_string) { - errtxt(0, symbol, err_id, error_string); + z_errtxt(0, symbol, err_id, error_string); } if (error_number < ZINT_ERROR && symbol->warn_level == WARN_FAIL_ALL) { /* Convert to error equivalent */ @@ -274,9 +270,9 @@ static int error_tag(int error_number, struct zint_symbol *symbol, const int err } } if (error_number >= ZINT_ERROR) { - errtxt_adj(0, symbol, "Error %s", NULL); + z_errtxt_adj(0, symbol, "Error %s", NULL); } else { - errtxt_adj(0, symbol, "Warning %s", NULL); + z_errtxt_adj(0, symbol, "Warning %s", NULL); } } @@ -284,7 +280,7 @@ static int error_tag(int error_number, struct zint_symbol *symbol, const int err } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int error_tag_test(int error_number, struct zint_symbol *symbol, const int err_id, +INTERNAL int zint_test_error_tag(int error_number, struct zint_symbol *symbol, const int err_id, const char *error_string) { return error_tag(error_number, symbol, err_id, error_string); } @@ -302,12 +298,12 @@ static int dump_plot(struct zint_symbol *symbol) { f = stdout; } else { #ifdef _WIN32 - f = out_win_fopen(symbol->outfile, "w"); + f = zint_out_win_fopen(symbol->outfile, "w"); #else f = fopen(symbol->outfile, "w"); #endif if (!f) { - return errtxt(ZINT_ERROR_FILE_ACCESS, symbol, 201, "Could not open output file"); + return z_errtxt(ZINT_ERROR_FILE_ACCESS, symbol, 201, "Could not open output file"); } } @@ -316,11 +312,11 @@ static int dump_plot(struct zint_symbol *symbol) { for (i = 0; i < symbol->width; i++) { byt = byt << 1; if (symbol->symbology == BARCODE_ULTRA) { - if (module_colour_is_set(symbol, r, i)) { + if (z_module_colour_is_set(symbol, r, i)) { byt += 1; } } else { - if (module_is_set(symbol, r, i)) { + if (z_module_is_set(symbol, r, i)) { byt += 1; } } @@ -344,7 +340,7 @@ static int dump_plot(struct zint_symbol *symbol) { } if (ferror(f)) { - ZEXT errtxtf(0, symbol, 795, "Incomplete write to output (%1$d: %2$s)", errno, strerror(errno)); + ZEXT z_errtxtf(0, symbol, 795, "Incomplete write to output (%1$d: %2$s)", errno, strerror(errno)); if (!output_to_stdout) { (void) fclose(f); } @@ -353,13 +349,13 @@ static int dump_plot(struct zint_symbol *symbol) { if (output_to_stdout) { if (fflush(f) != 0) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 796, "Incomplete flush to output (%1$d: %2$s)", - errno, strerror(errno)); + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 796, "Incomplete flush to output (%1$d: %2$s)", + errno, strerror(errno)); } } else { if (fclose(f) != 0) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 792, "Failure on closing output file (%1$d: %2$s)", - errno, strerror(errno)); + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 792, "Failure on closing output file (%1$d: %2$s)", + errno, strerror(errno)); } } @@ -381,12 +377,12 @@ static int hibc(struct zint_symbol *symbol, struct zint_seg segs[], const int se /* without "+" and check: max 110 characters in HIBC 2.6 */ if (length > 110) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 202, "Input length %d too long for HIBC LIC (maximum 110)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 202, "Input length %d too long for HIBC LIC (maximum 110)", length); } - to_upper(source, length); - if ((i = not_sane_lookup(TECHNETIUM, sizeof(TECHNETIUM) - 1, source, length, posns))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 203, + z_to_upper(source, length); + if ((i = z_not_sane_lookup(TECHNETIUM, sizeof(TECHNETIUM) - 1, source, length, posns))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 203, "Invalid character at position %d in input (alphanumerics, space and \"-.$/+%%\" only)", i); } @@ -409,35 +405,35 @@ static int hibc(struct zint_symbol *symbol, struct zint_seg segs[], const int se /* HIBC uses same `raw_text` as base symbologies */ switch (symbol->symbology) { case BARCODE_HIBC_128: - error_number = code128(symbol, segs[0].source, segs[0].length); - hrt_cpy_chr(symbol, '*'); - hrt_cat_nochk(symbol, segs[0].source, segs[0].length); - hrt_cat_chr_nochk(symbol, '*'); + error_number = zint_code128(symbol, segs[0].source, segs[0].length); + z_hrt_cpy_chr(symbol, '*'); + z_hrt_cat_nochk(symbol, segs[0].source, segs[0].length); + z_hrt_cat_chr_nochk(symbol, '*'); break; case BARCODE_HIBC_39: symbol->option_2 = 0; - error_number = code39(symbol, segs[0].source, segs[0].length); - hrt_cpy_chr(symbol, '*'); - hrt_cat_nochk(symbol, segs[0].source, segs[0].length); - hrt_cat_chr_nochk(symbol, '*'); + error_number = zint_code39(symbol, segs[0].source, segs[0].length); + z_hrt_cpy_chr(symbol, '*'); + z_hrt_cat_nochk(symbol, segs[0].source, segs[0].length); + z_hrt_cat_chr_nochk(symbol, '*'); break; case BARCODE_HIBC_DM: - error_number = datamatrix(symbol, segs, seg_count); + error_number = zint_datamatrix(symbol, segs, seg_count); break; case BARCODE_HIBC_QR: - error_number = qrcode(symbol, segs, seg_count); + error_number = zint_qrcode(symbol, segs, seg_count); break; case BARCODE_HIBC_PDF: - error_number = pdf417(symbol, segs, seg_count); + error_number = zint_pdf417(symbol, segs, seg_count); break; case BARCODE_HIBC_MICPDF: - error_number = micropdf417(symbol, segs, seg_count); + error_number = zint_micropdf417(symbol, segs, seg_count); break; case BARCODE_HIBC_AZTEC: - error_number = aztec(symbol, segs, seg_count); + error_number = zint_aztec(symbol, segs, seg_count); break; case BARCODE_HIBC_BLOCKF: - error_number = codablockf(symbol, segs[0].source, segs[0].length); + error_number = zint_codablockf(symbol, segs[0].source, segs[0].length); break; } @@ -457,7 +453,7 @@ static int check_force_gs1(const int symbology) { break; } - return is_composite(symbology); + return z_is_composite(symbology); } /* Returns 1 if symbology supports GS1 data */ @@ -510,7 +506,7 @@ static int supports_eci(const int symbology) { /* Returns 1 if symbology supports HRT */ static int has_hrt(const int symbology) { - if (is_fixed_ratio(symbology)) { + if (z_is_fixed_ratio(symbology)) { return 0; } @@ -562,61 +558,61 @@ typedef int (*barcode_seg_func_t)(struct zint_symbol *, struct zint_seg[], const /* Used for dispatching `barcode_src_func_t` barcodes */ /* Also used, with `barcode_seg_funcs` below, for testing whether symbol id valid in `ZBarcode_ValidID()` */ static const barcode_src_func_t barcode_src_funcs[BARCODE_LAST + 1] = { - NULL, code11, c25standard, c25inter, c25iata, /*0-4*/ - NULL, c25logic, c25ind, code39, excode39, /*5-9*/ - eanx, eanx, eanx, eanx, eanx, /*10-14*/ - eanx, gs1_128, NULL, codabar, NULL, /*15-19*/ - code128, dpleit, dpident, code16k, code49, /*20-24*/ - code93, NULL, NULL, flat, dbar_omn, /*25-29*/ - dbar_ltd, dbar_exp, telepen, NULL, eanx, /*30-34*/ - eanx, NULL, eanx, eanx, NULL, /*35-39*/ - postnet, NULL, NULL, NULL, NULL, /*40-44*/ - NULL, NULL, msi_plessey, NULL, fim, /*45-49*/ - code39, pharma, pzn, pharma_two, postnet, /*50-54*/ - NULL, NULL, NULL, NULL, NULL, /*55-59*/ - code128, NULL, NULL, auspost, NULL, /*60-64*/ - NULL, auspost, auspost, auspost, eanx, /*65-69*/ - rm4scc, NULL, ean14, vin, codablockf, /*70-74*/ - nve18, japanpost, koreapost, NULL, dbar_omn, /*75-79*/ - dbar_omn, dbar_exp, planet, NULL, NULL, /*80-84*/ - usps_imail, plessey, telepen_num, NULL, itf14, /*85-89*/ - kix, NULL, NULL, daft, NULL, /*90-94*/ - NULL, dpd, microqr, NULL, NULL, /*95-99*/ - NULL, NULL, NULL, NULL, NULL, /*100-104*/ - NULL, NULL, NULL, NULL, NULL, /*105-109*/ - NULL, NULL, NULL, NULL, NULL, /*110-114*/ - NULL, NULL, NULL, NULL, mailmark_2d, /*115-119*/ - upu_s10, mailmark_4s, NULL, NULL, NULL, /*120-124*/ - NULL, NULL, NULL, azrune, code32, /*125-129*/ - composite, composite, composite, composite, composite, /*130-134*/ - composite, composite, composite, composite, composite, /*135-139*/ - channel, NULL, NULL, upnqr, NULL, /*140-144*/ - NULL, bc412, dxfilmedge, composite, composite, /*145-149*/ + NULL, zint_code11, zint_c25standard, zint_c25inter, zint_c25iata, /*0-4*/ + NULL, zint_c25logic, zint_c25ind, zint_code39, zint_excode39, /*5-9*/ + zint_eanx, zint_eanx, zint_eanx, zint_eanx, zint_eanx, /*10-14*/ + zint_eanx, zint_gs1_128, NULL, zint_codabar, NULL, /*15-19*/ + zint_code128, zint_dpleit, zint_dpident, zint_code16k, zint_code49, /*20-24*/ + zint_code93, NULL, NULL, zint_flat, zint_dbar_omn, /*25-29*/ + zint_dbar_ltd, zint_dbar_exp, zint_telepen, NULL, zint_eanx, /*30-34*/ + zint_eanx, NULL, zint_eanx, zint_eanx, NULL, /*35-39*/ + zint_postnet, NULL, NULL, NULL, NULL, /*40-44*/ + NULL, NULL, zint_msi_plessey, NULL, zint_fim, /*45-49*/ + zint_code39, zint_pharma, zint_pzn, zint_pharma_two, zint_postnet, /*50-54*/ + NULL, NULL, NULL, NULL, NULL, /*55-59*/ + zint_code128, NULL, NULL, zint_auspost, NULL, /*60-64*/ + NULL, zint_auspost, zint_auspost, zint_auspost, zint_eanx, /*65-69*/ + zint_rm4scc, NULL, zint_ean14, zint_vin, zint_codablockf, /*70-74*/ + zint_nve18, zint_japanpost, zint_koreapost, NULL, zint_dbar_omn, /*75-79*/ + zint_dbar_omn, zint_dbar_exp, zint_planet, NULL, NULL, /*80-84*/ + zint_usps_imail, zint_plessey, zint_telepen_num, NULL, zint_itf14, /*85-89*/ + zint_kix, NULL, NULL, zint_daft, NULL, /*90-94*/ + NULL, zint_dpd, zint_microqr, NULL, NULL, /*95-99*/ + NULL, NULL, NULL, NULL, NULL, /*100-104*/ + NULL, NULL, NULL, NULL, NULL, /*105-109*/ + NULL, NULL, NULL, NULL, NULL, /*110-114*/ + NULL, NULL, NULL, NULL, zint_mailmark_2d, /*115-119*/ + zint_upu_s10, zint_mailmark_4s, NULL, NULL, NULL, /*120-124*/ + NULL, NULL, NULL, zint_azrune, zint_code32, /*125-129*/ + zint_composite, zint_composite, zint_composite, zint_composite, zint_composite, /*130-134*/ + zint_composite, zint_composite, zint_composite, zint_composite, zint_composite, /*135-139*/ + zint_channel, NULL, NULL, zint_upnqr, NULL, /*140-144*/ + NULL, zint_bc412, zint_dxfilmedge, zint_composite, zint_composite, /*145-149*/ }; #define LIB_SEG_FUNCS_START 55 /* Used for dispatching `barcode_seg_func_t` barcodes */ static const barcode_seg_func_t barcode_seg_funcs[BARCODE_LAST + 1 - LIB_SEG_FUNCS_START] = { - pdf417, pdf417, maxicode, qrcode, NULL, /*55-59*/ - NULL, NULL, NULL, NULL, NULL, /*60-64*/ - NULL, NULL, NULL, NULL, NULL, /*65-69*/ - NULL, datamatrix, NULL, NULL, NULL, /*70-74*/ - NULL, NULL, NULL, NULL, NULL, /*75-79*/ - NULL, NULL, NULL, NULL, micropdf417, /*80-84*/ - NULL, NULL, NULL, NULL, NULL, /*85-89*/ - NULL, NULL, aztec, NULL, NULL, /*90-94*/ - NULL, NULL, NULL, hibc, hibc, /*95-99*/ - NULL, NULL, hibc, NULL, hibc, /*100-104*/ - NULL, hibc, NULL, hibc, NULL, /*105-109*/ - hibc, NULL, hibc, NULL, NULL, /*110-114*/ - dotcode, hanxin, NULL, NULL, NULL, /*115-119*/ - NULL, NULL, NULL, NULL, NULL, /*120-124*/ - NULL, NULL, NULL, NULL, NULL, /*125-129*/ - NULL, NULL, NULL, NULL, NULL, /*130-134*/ - NULL, NULL, NULL, NULL, NULL, /*135-139*/ - NULL, codeone, gridmatrix, NULL, ultra, /*140-144*/ - rmqr, NULL, NULL, NULL, NULL, /*145-149*/ + zint_pdf417, zint_pdf417, zint_maxicode, zint_qrcode, NULL, /*55-59*/ + NULL, NULL, NULL, NULL, NULL, /*60-64*/ + NULL, NULL, NULL, NULL, NULL, /*65-69*/ + NULL, zint_datamatrix, NULL, NULL, NULL, /*70-74*/ + NULL, NULL, NULL, NULL, NULL, /*75-79*/ + NULL, NULL, NULL, NULL, zint_micropdf417, /*80-84*/ + NULL, NULL, NULL, NULL, NULL, /*85-89*/ + NULL, NULL, zint_aztec, NULL, NULL, /*90-94*/ + NULL, NULL, NULL, hibc, hibc, /*95-99*/ + NULL, NULL, hibc, NULL, hibc, /*100-104*/ + NULL, hibc, NULL, hibc, NULL, /*105-109*/ + hibc, NULL, hibc, NULL, NULL, /*110-114*/ + zint_dotcode, zint_hanxin, NULL, NULL, NULL, /*115-119*/ + NULL, NULL, NULL, NULL, NULL, /*120-124*/ + NULL, NULL, NULL, NULL, NULL, /*125-129*/ + NULL, NULL, NULL, NULL, NULL, /*130-134*/ + NULL, NULL, NULL, NULL, NULL, /*135-139*/ + NULL, zint_codeone, zint_gridmatrix, NULL, zint_ultra, /*140-144*/ + zint_rmqr, NULL, NULL, NULL, NULL, /*145-149*/ }; static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); @@ -653,24 +649,24 @@ static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], c struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count); int *convertible = (int *) z_alloca(sizeof(int) * seg_count); - if ((symbol->input_mode & 0x07) == UNICODE_MODE && is_eci_convertible_segs(segs, seg_count, convertible)) { + if ((symbol->input_mode & 0x07) == UNICODE_MODE && zint_is_eci_convertible_segs(segs, seg_count, convertible)) { unsigned char *preprocessed; - const int eci_length_segs = get_eci_length_segs(segs, seg_count); + const int eci_length_segs = zint_get_eci_length_segs(segs, seg_count); unsigned char *preprocessed_buf = (unsigned char *) z_alloca(eci_length_segs + seg_count); /* Prior check ensures ECI only set for those that support it */ - segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs) */ + z_segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs) */ preprocessed = preprocessed_buf; for (i = 0; i < seg_count; i++) { if (convertible[i]) { - error_number = utf8_to_eci(local_segs[i].eci, local_segs[i].source, preprocessed, + error_number = zint_utf8_to_eci(local_segs[i].eci, local_segs[i].source, preprocessed, &local_segs[i].length); if (error_number != 0) { if (local_segs[i].eci) { - return errtxtf(error_number, symbol, 244, "Invalid character in input for ECI '%d'", + return z_errtxtf(error_number, symbol, 244, "Invalid character in input for ECI '%d'", local_segs[i].eci); } - return errtxt(error_number, symbol, 204, "Invalid character in input (ISO/IEC 8859-1 only)"); + return z_errtxt(error_number, symbol, 204, "Invalid character in input (ISO/IEC 8859-1 only)"); } local_segs[i].source = preprocessed; preprocessed += local_segs[i].length + 1; @@ -689,7 +685,7 @@ static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], c } else { assert(symbol->symbology >= LIB_SEG_FUNCS_START); /* Suppress clang-tidy-19 warning */ assert(barcode_seg_funcs[symbol->symbology - LIB_SEG_FUNCS_START]); /* Suppress clang-tidy-19 warning */ - segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs) */ + z_segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs) */ error_number = barcode_seg_funcs[symbol->symbology - LIB_SEG_FUNCS_START](symbol, local_segs, seg_count); } } @@ -712,7 +708,7 @@ static void strip_bom(unsigned char *source, int *input_length) { } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL void strip_bom_test(unsigned char *source, int *input_length) { +INTERNAL void zint_test_strip_bom(unsigned char *source, int *input_length) { strip_bom(source, input_length); } #endif @@ -725,17 +721,17 @@ static int esc_base(struct zint_symbol *symbol, const unsigned char *input_strin int val = -1; if (in_posn + min_len > length) { - return errtxtf(-1, symbol, 232, "Incomplete '\\%c' escape sequence in input", base); + return z_errtxtf(-1, symbol, 232, "Incomplete '\\%c' escape sequence in input", base); } - c1 = ctoi(input_string[in_posn]); - c2 = ctoi(input_string[in_posn + 1]); + c1 = z_ctoi(input_string[in_posn]); + c2 = z_ctoi(input_string[in_posn + 1]); if (base == 'd') { - c3 = ctoi(input_string[in_posn + 2]); + c3 = z_ctoi(input_string[in_posn + 2]); if ((c1 >= 0 && c1 <= 9) && (c2 >= 0 && c2 <= 9) && (c3 >= 0 && c3 <= 9)) { val = c1 * 100 + c2 * 10 + c3; } } else if (base == 'o') { - c3 = ctoi(input_string[in_posn + 2]); + c3 = z_ctoi(input_string[in_posn + 2]); if ((c1 >= 0 && c1 <= 7) && (c2 >= 0 && c2 <= 7) && (c3 >= 0 && c3 <= 7)) { val = (c1 << 6) | (c2 << 3) | c3; } @@ -746,16 +742,16 @@ static int esc_base(struct zint_symbol *symbol, const unsigned char *input_strin } if (val == -1) { - return ZEXT errtxtf(-1, symbol, 238, - "Invalid character in escape sequence '%2$.*1$s' in input (%3$s only)", - base == 'x' ? 4 : 5, input_string + in_posn - 2, - base == 'd' ? "decimal" : base == 'o' ? "octal" : "hexadecimal"); + return ZEXT z_errtxtf(-1, symbol, 238, + "Invalid character in escape sequence '%2$.*1$s' in input (%3$s only)", + base == 'x' ? 4 : 5, input_string + in_posn - 2, + base == 'd' ? "decimal" : base == 'o' ? "octal" : "hexadecimal"); } if (val > 255) { assert(base != 'x'); - return ZEXT errtxtf(-1, symbol, 237, - "Value of escape sequence '%1$.5s' in input out of range (000 to %2$s)", - input_string + in_posn - 2, base == 'd' ? "255" : "377"); + return ZEXT z_errtxtf(-1, symbol, 237, + "Value of escape sequence '%1$.5s' in input out of range (000 to %2$s)", + input_string + in_posn - 2, base == 'd' ? "255" : "377"); } return val; @@ -780,7 +776,7 @@ static int escape_char_process(struct zint_symbol *symbol, const unsigned char * do { if (input_string[in_posn] == '\\') { if (in_posn + 1 >= length) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 236, "Incomplete escape character in input"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 236, "Incomplete escape character in input"); } ch = input_string[in_posn + 1]; /* NOTE: if add escape character, must also update regex in "frontend_qt/datawindow.php" */ @@ -798,12 +794,12 @@ static int escape_char_process(struct zint_symbol *symbol, const unsigned char * case 'G': case 'R': case '\\': - if (escaped_string) escaped_string[out_posn] = vals[posn(escs, ch)]; + if (escaped_string) escaped_string[out_posn] = vals[z_posn(escs, ch)]; in_posn += 2; break; case '^': /* CODE128 specific */ if (!extra_escape_mode) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 798, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 798, "Escape '\\^' only valid for Code 128 in extra escape mode"); } /* Pass thru unaltered */ @@ -826,7 +822,7 @@ static int escape_char_process(struct zint_symbol *symbol, const unsigned char * case '(': case ')': if (!escape_parens) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 853, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 853, "Escaped parentheses only valid in GS1 mode with GS1 parentheses flag"); } /* Pass through unaltered */ @@ -850,15 +846,15 @@ static int escape_char_process(struct zint_symbol *symbol, const unsigned char * case 'u': case 'U': if (in_posn + 6 > length || (ch == 'U' && in_posn + 8 > length)) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 209, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 209, "Incomplete '\\%c' escape sequence in input", ch); } unicode = 0; for (i = 0; i < 6; i++) { - if ((val = ctoi(input_string[in_posn + i + 2])) == -1) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 211, - "Invalid character for '\\%c' escape sequence in input (hexadecimal only)", - ch); + if ((val = z_ctoi(input_string[in_posn + i + 2])) == -1) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 211, + "Invalid character for '\\%c' escape sequence in input (hexadecimal only)", + ch); } unicode = (unicode << 4) | val; if (i == 3 && ch == 'u') { @@ -867,7 +863,7 @@ static int escape_char_process(struct zint_symbol *symbol, const unsigned char * } /* Exclude reversed BOM and surrogates and out-of-range */ if (unicode == 0xfffe || (unicode >= 0xd800 && unicode < 0xe000) || unicode > 0x10ffff) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 246, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 246, "Value of escape sequence '%.*s' in input out of range", ch == 'u' ? 6 : 8, input_string + in_posn); } @@ -901,7 +897,7 @@ static int escape_char_process(struct zint_symbol *symbol, const unsigned char * in_posn += 6 + (ch == 'U') * 2; break; default: - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 234, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 234, "Unrecognised escape character '\\%c' in input", ch); break; } @@ -921,8 +917,8 @@ static int escape_char_process(struct zint_symbol *symbol, const unsigned char * } #ifdef ZINT_TEST /* Wrapper for direct testing (also used by `testUtilZXingCPPCmp()` in "tests/testcommon.c") */ -INTERNAL int escape_char_process_test(struct zint_symbol *symbol, const unsigned char *input_string, int *p_length, - unsigned char *escaped_string) { +INTERNAL int zint_test_escape_char_process(struct zint_symbol *symbol, const unsigned char *input_string, + int *p_length, unsigned char *escaped_string) { return escape_char_process(symbol, input_string, p_length, escaped_string); } #endif @@ -1052,24 +1048,24 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ for (i = 0; i < seg_count; i++) { local_segs[i] = segs[i]; if (local_segs[i].source == NULL) { - errtxtf(0, symbol, 772, "Input segment %d source NULL", i); + z_errtxtf(0, symbol, 772, "Input segment %d source NULL", i); return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL); } if (local_segs[i].length <= 0) { - local_segs[i].length = (int) ustrlen(local_segs[i].source); + local_segs[i].length = (int) z_ustrlen(local_segs[i].source); } if (local_segs[i].length <= 0) { if (i == 0) { - if (is_composite(symbol->symbology) + if (z_is_composite(symbol->symbology) && ((symbol->input_mode & 0x07) == GS1_MODE || check_force_gs1(symbol->symbology))) { - errtxt(0, symbol, 779, "No composite data (2D component)"); + z_errtxt(0, symbol, 779, "No composite data (2D component)"); } else if (supports_eci(symbol->symbology)) { - errtxt(0, symbol, 228, "No input data (segment 0 empty)"); + z_errtxt(0, symbol, 228, "No input data (segment 0 empty)"); } else { - errtxt(0, symbol, 778, "No input data"); + z_errtxt(0, symbol, 778, "No input data"); } } else { - errtxtf(0, symbol, 773, "Input segment %d empty", i); + z_errtxtf(0, symbol, 773, "Input segment %d empty", i); } return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL); } @@ -1102,8 +1098,8 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ char name[32]; char source[151], primary[151]; /* 30*5 + 1 = 151 */ (void) ZBarcode_BarcodeName(symbol->symbology, name); - debug_print_escape(local_segs[0].source, len > 30 ? 30 : len, source); - debug_print_escape(ZCUCP(symbol->primary), primary_len > 30 ? 30 : primary_len, primary); + z_debug_print_escape(local_segs[0].source, len > 30 ? 30 : len, source); + z_debug_print_escape(ZCUCP(symbol->primary), primary_len > 30 ? 30 : primary_len, primary); printf("\nZBarcode_Encode_Segs: %s (%d), input_mode: 0x%X, ECI: %d, option_1/2/3: (%d, %d, %d)\n" " scale: %g, output_options: 0x%X, fg: %s, bg: %s, seg_count: %d,\n" " %ssource%s (%d): \"%s\",\n" @@ -1122,8 +1118,8 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ /* Reconcile symbol ECI and first segment ECI if both set */ if (symbol->eci != local_segs[0].eci) { if (symbol->eci && local_segs[0].eci) { - ZEXT errtxtf(0, symbol, 774, "Symbol ECI '%1$d' must match segment zero ECI '%2$d'", - symbol->eci, local_segs[0].eci); + ZEXT z_errtxtf(0, symbol, 774, "Symbol ECI '%1$d' must match segment zero ECI '%2$d'", + symbol->eci, local_segs[0].eci); return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, -1, NULL); } if (symbol->eci) { @@ -1145,8 +1141,8 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ } if (local_segs[i].eci < 0 || local_segs[i].eci == 1 || local_segs[i].eci == 2 || local_segs[i].eci == 14 || local_segs[i].eci == 19 || local_segs[i].eci > 999999) { - errtxtf(0, symbol, 218, "ECI code '%d' out of range (0 to 999999, excluding 1, 2, 14 and 19)", - local_segs[i].eci); + z_errtxtf(0, symbol, 218, "ECI code '%d' out of range (0 to 999999, excluding 1, 2, 14 and 19)", + local_segs[i].eci); return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, -1, NULL); } } else { @@ -1228,7 +1224,7 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ if ((symbol->input_mode & 0x07) == UNICODE_MODE) { for (i = 0; i < seg_count; i++) { - if (!is_valid_utf8(local_segs[i].source, local_segs[i].length)) { + if (!z_is_valid_utf8(local_segs[i].source, local_segs[i].length)) { return error_tag(ZINT_ERROR_INVALID_DATA, symbol, 245, "Invalid UTF-8 in input"); } } @@ -1240,15 +1236,16 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ if (gs1_compliant(symbol->symbology)) { /* Reduce input for composite and non-forced symbologies, others (GS1_128 and DBAR_EXP based) will handle it themselves */ - const int have_composite = is_composite(symbol->symbology); + const int have_composite = z_is_composite(symbol->symbology); if (have_composite || !check_force_gs1(symbol->symbology)) { const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; unsigned char *reduced = (unsigned char *) z_alloca(local_segs[0].length + 1); int source_len = local_segs[0].length; - error_number = gs1_verify(symbol, local_segs[0].source, &source_len, reduced, &local_segs[0].length); + error_number = zint_gs1_verify(symbol, local_segs[0].source, &source_len, reduced, + &local_segs[0].length); if (error_number) { if (have_composite) { - errtxt_adj(0, symbol, "%1$s%2$s", " (2D component)"); + z_errtxt_adj(0, symbol, "%1$s%2$s", " (2D component)"); } error_number = error_tag(error_number, symbol, -1, NULL); if (error_number >= ZINT_ERROR) { @@ -1258,8 +1255,8 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ } memcpy(local_segs[0].source, reduced, local_segs[0].length + 1); /* Include terminating NUL */ /* Set raw text for non-composites (composites set their own raw text) */ - if (!have_composite && raw_text && rt_cpy(symbol, reduced, local_segs[0].length)) { - return error_tag(ZINT_ERROR_MEMORY, symbol, -1, NULL); /* `rt_cpy()` only fails with OOM */ + if (!have_composite && raw_text && z_rt_cpy(symbol, reduced, local_segs[0].length)) { + return error_tag(ZINT_ERROR_MEMORY, symbol, -1, NULL); /* `z_rt_cpy()` only fails with OOM */ } } } else { @@ -1272,13 +1269,13 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ if ((error_number == ZINT_ERROR_INVALID_DATA) && have_zero_eci && supports_eci(symbol->symbology) && (symbol->input_mode & 0x07) == UNICODE_MODE) { /* Try another ECI mode */ - const int first_eci_set = get_best_eci_segs(symbol, local_segs, seg_count); + const int first_eci_set = zint_get_best_eci_segs(symbol, local_segs, seg_count); error_number = extended_or_reduced_charset(symbol, local_segs, seg_count); /* Inclusion of ECI more noteworthy than other warnings, so overwrite (if any) */ if (error_number < ZINT_ERROR) { error_number = ZINT_WARN_USES_ECI; if (!(symbol->debug & ZINT_DEBUG_TEST)) { - errtxtf(0, symbol, 222, "Encoded data includes ECI %d", first_eci_set); + z_errtxtf(0, symbol, 222, "Encoded data includes ECI %d", first_eci_set); } if (symbol->debug & ZINT_DEBUG_PRINT) printf("Added ECI %d\n", first_eci_set); } @@ -1292,7 +1289,7 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[ if (error_number < ZINT_ERROR) { if (symbol->height < 0.5f) { /* Absolute minimum */ - (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*/); } assert(!(symbol->output_options & BARCODE_RAW_TEXT) || (symbol->raw_segs && symbol->raw_seg_count)); } @@ -1316,7 +1313,7 @@ static int check_output_args(struct zint_symbol *symbol, int rotate_angle) { break; } - if ((symbol->output_options & BARCODE_DOTTY_MODE) && !(is_dotty(symbol->symbology))) { + if ((symbol->output_options & BARCODE_DOTTY_MODE) && !z_is_dotty(symbol->symbology)) { return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 224, "Selected symbology cannot be rendered as dots"); } @@ -1338,7 +1335,7 @@ static int filetype_idx(const char *extension) { return -1; } memcpy(uc_extension, extension, 3); - to_upper(ZUCP(uc_extension), 3); + z_to_upper(ZUCP(uc_extension), 3); for (i = 0; i < ARRAY_SIZE(filetypes); i++) { if (strcmp(uc_extension, filetypes[i].extension) == 0) { @@ -1367,9 +1364,9 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) { if (i >= 0) { if (filetypes[i].filetype) { if (filetypes[i].is_raster) { - error_number = plot_raster(symbol, rotate_angle, filetypes[i].filetype); + error_number = zint_plot_raster(symbol, rotate_angle, filetypes[i].filetype); } else { - error_number = plot_vector(symbol, rotate_angle, filetypes[i].filetype); + error_number = zint_plot_vector(symbol, rotate_angle, filetypes[i].filetype); } } else { error_number = dump_plot(symbol); @@ -1392,7 +1389,7 @@ int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) { return error_number; /* Already tagged */ } - error_number = plot_raster(symbol, rotate_angle, OUT_BUFFER); + error_number = zint_plot_raster(symbol, rotate_angle, OUT_BUFFER); return error_tag(error_number, symbol, -1, NULL); } @@ -1404,7 +1401,7 @@ int ZBarcode_Buffer_Vector(struct zint_symbol *symbol, int rotate_angle) { return error_number; /* Already tagged */ } - error_number = plot_vector(symbol, rotate_angle, OUT_BUFFER); + error_number = zint_plot_vector(symbol, rotate_angle, OUT_BUFFER); return error_tag(error_number, symbol, -1, NULL); } @@ -1518,19 +1515,19 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, const char *filename) { fileLen = ZINT_MAX_DATA_LEN; } else { #ifdef _WIN32 - file = out_win_fopen(filename, "rb"); + file = zint_out_win_fopen(filename, "rb"); #else file = fopen(filename, "rb"); #endif if (!file) { - ZEXT errtxtf(0, symbol, 229, "Unable to read input file (%1$d: %2$s)", errno, strerror(errno)); + ZEXT z_errtxtf(0, symbol, 229, "Unable to read input file (%1$d: %2$s)", errno, strerror(errno)); return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL); } file_opened = 1; /* Get file length */ if (fseek(file, 0, SEEK_END) != 0) { - ZEXT errtxtf(0, symbol, 797, "Unable to seek input file (%1$d: %2$s)", errno, strerror(errno)); + ZEXT z_errtxtf(0, symbol, 797, "Unable to seek input file (%1$d: %2$s)", errno, strerror(errno)); (void) fclose(file); return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL); } @@ -1548,7 +1545,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, const char *filename) { } if (fseek(file, 0, SEEK_SET) != 0) { - ZEXT errtxtf(0, symbol, 793, "Unable to seek input file (%1$d: %2$s)", errno, strerror(errno)); + ZEXT z_errtxtf(0, symbol, 793, "Unable to seek input file (%1$d: %2$s)", errno, strerror(errno)); (void) fclose(file); return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL); } @@ -1568,7 +1565,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, const char *filename) { do { n = fread(buffer + nRead, 1, fileLen - nRead, file); if (ferror(file)) { - ZEXT errtxtf(0, symbol, 241, "Input file read error (%1$d: %2$s)", errno, strerror(errno)); + ZEXT z_errtxtf(0, symbol, 241, "Input file read error (%1$d: %2$s)", errno, strerror(errno)); free(buffer); if (file_opened) { (void) fclose(file); @@ -1580,7 +1577,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, const char *filename) { if (file_opened) { if (fclose(file) != 0) { - ZEXT errtxtf(0, symbol, 794, "Failure on closing input file (%1$d: %2$s)", errno, strerror(errno)); + ZEXT z_errtxtf(0, symbol, 794, "Failure on closing input file (%1$d: %2$s)", errno, strerror(errno)); free(buffer); return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL); } @@ -1706,7 +1703,7 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) { if ((cap_flag & ZINT_CAP_HRT) && has_hrt(symbol_id)) { result |= ZINT_CAP_HRT; } - if ((cap_flag & ZINT_CAP_STACKABLE) && is_bindable(symbol_id)) { + if ((cap_flag & ZINT_CAP_STACKABLE) && z_is_bindable(symbol_id)) { switch (symbol_id) { case BARCODE_CODE16K: /* Stacked are not stackable */ case BARCODE_CODE49: @@ -1718,10 +1715,10 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) { break; } } - if ((cap_flag & ZINT_CAP_EANUPC) && is_upcean(symbol_id)) { + if ((cap_flag & ZINT_CAP_EANUPC) && z_is_upcean(symbol_id)) { result |= ZINT_CAP_EANUPC; } - if ((cap_flag & ZINT_CAP_COMPOSITE) && is_composite(symbol_id)) { + if ((cap_flag & ZINT_CAP_COMPOSITE) && z_is_composite(symbol_id)) { result |= ZINT_CAP_COMPOSITE; } if ((cap_flag & ZINT_CAP_ECI) && supports_eci(symbol_id)) { @@ -1730,7 +1727,7 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) { if ((cap_flag & ZINT_CAP_GS1) && gs1_compliant(symbol_id)) { result |= ZINT_CAP_GS1; } - if ((cap_flag & ZINT_CAP_DOTTY) && is_dotty(symbol_id)) { + if ((cap_flag & ZINT_CAP_DOTTY) && z_is_dotty(symbol_id)) { result |= ZINT_CAP_DOTTY; } if (cap_flag & ZINT_CAP_QUIET_ZONES) { @@ -1760,7 +1757,7 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) { break; } } - if ((cap_flag & ZINT_CAP_FIXED_RATIO) && is_fixed_ratio(symbol_id)) { + if ((cap_flag & ZINT_CAP_FIXED_RATIO) && z_is_fixed_ratio(symbol_id)) { result |= ZINT_CAP_FIXED_RATIO; } if (cap_flag & ZINT_CAP_READER_INIT) { @@ -1828,7 +1825,7 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) { break; } } - if ((cap_flag & ZINT_CAP_COMPLIANT_HEIGHT) && !is_fixed_ratio(symbol_id)) { + if ((cap_flag & ZINT_CAP_COMPLIANT_HEIGHT) && !z_is_fixed_ratio(symbol_id)) { switch (symbol_id) { /* These don't have a compliant height defined */ case BARCODE_CODE11: /* TODO: Find doc */ @@ -1858,7 +1855,7 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) { break; } } - if ((cap_flag & ZINT_CAP_BINDABLE) && is_bindable(symbol_id)) { + if ((cap_flag & ZINT_CAP_BINDABLE) && z_is_bindable(symbol_id)) { result |= ZINT_CAP_BINDABLE; } @@ -1997,7 +1994,7 @@ float ZBarcode_Default_Xdim(int symbol_id) { /* Application defined (and hence pretty arbitrary) */ default: - if (is_fixed_ratio(symbol_id)) { + if (z_is_fixed_ratio(symbol_id)) { /* GS1 General Standards 22.0 Section 5.12.3 Table 1 (general retail) */ x_dim_mm = 0.625f; } else { @@ -2035,7 +2032,7 @@ float ZBarcode_Scale_From_XdimDp(int symbol_id, float x_dim_mm, float dpmm, cons i = filetype_idx("GIF"); /* Default to raster */ } - scale = stripf(stripf(x_dim_mm) * stripf(dpmm)); + scale = z_stripf(z_stripf(x_dim_mm) * z_stripf(dpmm)); if (symbol_id == BARCODE_MAXICODE) { if (filetypes[i].is_raster) { @@ -2052,7 +2049,7 @@ float ZBarcode_Scale_From_XdimDp(int symbol_id, float x_dim_mm, float dpmm, cons scale /= 2.0f; } } - scale = stripf(scale); + scale = z_stripf(scale); if (scale > 200.0f) { scale = 200.0f; @@ -2109,7 +2106,7 @@ float ZBarcode_XdimDp_From_Scale(int symbol_id, float scale, float xdim_mm_or_dp scale *= 2.0f; } - xdim_mm_or_dpmm = stripf(stripf(scale) / stripf(xdim_mm_or_dpmm)); + xdim_mm_or_dpmm = z_stripf(z_stripf(scale) / z_stripf(xdim_mm_or_dpmm)); if (xdim_mm_or_dpmm > 1000.0f) { /* Note if X-dimension sought needs to be further bound to <= 10 on return */ xdim_mm_or_dpmm = 1000.0f; @@ -2138,9 +2135,9 @@ int ZBarcode_UTF8_To_ECI(int eci, const unsigned char *source, int length, unsig return ZINT_ERROR_INVALID_OPTION; } if (length <= 0) { - length = (int) ustrlen(source); /* Note `zueci_utf8_to_eci()` doesn't do this */ + length = (int) z_ustrlen(source); /* Note `zueci_utf8_to_eci()` doesn't do this */ } - if (!is_valid_utf8(source, length)) { + if (!z_is_valid_utf8(source, length)) { return ZINT_ERROR_INVALID_DATA; } @@ -2151,7 +2148,7 @@ int ZBarcode_UTF8_To_ECI(int eci, const unsigned char *source, int length, unsig } /* Only set `p_dest_length` on success, for libzueci compatibility */ - if ((error_number = utf8_to_eci(eci, source, dest, &length)) == 0) { + if ((error_number = zint_utf8_to_eci(eci, source, dest, &length)) == 0) { *p_dest_length = length; } return error_number; /* 0 or ZINT_ERROR_INVALID_DATA */ @@ -2169,12 +2166,12 @@ int ZBarcode_Dest_Len_ECI(int eci, const unsigned char *source, int length, int return ZINT_ERROR_INVALID_OPTION; } if (length <= 0) { - length = (int) ustrlen(source); /* Note `zueci_dest_len_eci()` doesn't do this */ + length = (int) z_ustrlen(source); /* Note `zueci_dest_len_eci()` doesn't do this */ } - if (!is_valid_utf8(source, length)) { + if (!z_is_valid_utf8(source, length)) { return ZINT_ERROR_INVALID_DATA; } - *p_dest_length = get_eci_length(eci, source, length); + *p_dest_length = zint_get_eci_length(eci, source, length); return 0; } diff --git a/backend/mailmark.c b/backend/mailmark.c index 4e5af017..605244b1 100644 --- a/backend/mailmark.c +++ b/backend/mailmark.c @@ -86,17 +86,17 @@ static int mailmark_verify_character(const char input, const char type, const in switch (type) { case 'A': - val = posn(SET_A, input); + val = z_posn(SET_A, input); break; case 'L': /* Limited only applies to 4-state (ticket #334, props Milton Neal) */ - val = posn(is_2d ? SET_A : SET_L, input); + val = z_posn(is_2d ? SET_A : SET_L, input); break; case 'N': - val = posn(SET_N, input); + val = z_posn(SET_N, input); break; case 'S': - val = posn(SET_S, input); + val = z_posn(SET_S, input); break; } @@ -167,10 +167,10 @@ static int mailmark_verify_postcode(const char postcode[10], const int length, i return 0; } -INTERNAL int daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height); +INTERNAL int zint_daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height); /* Royal Mail 4-state Mailmark */ -INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int length) { unsigned char local_source[28]; int format; int version_id; @@ -195,14 +195,14 @@ INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 26) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 580, "Input length %d too long (maximum 26)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 580, "Input length %d too long (maximum 26)", length); } memcpy(local_source, source, length); if (length < 22) { if (length < 14) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 588, "Input length %d too short (minimum 14)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 588, "Input length %d too short (minimum 14)", length); } memset(local_source + length, ' ', 22 - length); length = 22; @@ -211,33 +211,34 @@ INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int length = 26; } - to_upper(local_source, length); + z_to_upper(local_source, length); if (symbol->debug & ZINT_DEBUG_PRINT) { printf("Producing 4-state Mailmark (%d): %.*s\n", length, length, local_source); } - if ((i = not_sane(RUBIDIUM_F, local_source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 581, + if ((i = z_not_sane(RUBIDIUM_F, local_source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 581, "Invalid character at position %d in input (alphanumerics and space only)", i); } /* Format is in the range 0-4 */ - format = ctoi(local_source[0]); + format = z_ctoi(local_source[0]); if ((format < 0) || (format > 4)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 582, "Format (1st character) out of range (0 to 4)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 582, "Format (1st character) out of range (0 to 4)"); } /* Version ID is in the range 1-4 */ - version_id = ctoi(local_source[1]) - 1; + version_id = z_ctoi(local_source[1]) - 1; if ((version_id < 0) || (version_id > 3)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 583, "Version ID (2nd character) out of range (1 to 4)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 583, "Version ID (2nd character) out of range (1 to 4)"); } /* Class is in the range 0-9,A-E */ - mail_class = ctoi(local_source[2]); + mail_class = z_ctoi(local_source[2]); if ((mail_class < 0) || (mail_class > 14)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 584, "Class (3rd character) out of range (0 to 9 and A to E)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 584, + "Class (3rd character) out of range (0 to 9 and A to E)"); } /* Supply Chain ID is 2 digits for barcode C and 6 digits for barcode L */ @@ -245,9 +246,9 @@ INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int for (i = 3; i < (length - 17); i++) { if (z_isdigit(local_source[i])) { supply_chain_id *= 10; - supply_chain_id += ctoi(local_source[i]); + supply_chain_id += z_ctoi(local_source[i]); } else { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 585, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 585, "Invalid Supply Chain ID at character %d (digits only)", i); } } @@ -257,9 +258,10 @@ INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int for (i = length - 17; i < (length - 9); i++) { if (z_isdigit(local_source[i])) { item_id *= 10; - item_id += ctoi(local_source[i]); + item_id += z_ctoi(local_source[i]); } else { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 586, "Invalid Item ID at character %d (digits only)", i); + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 586, + "Invalid Item ID at character %d (digits only)", i); } } @@ -268,111 +270,111 @@ INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int postcode[i] = local_source[(length - 9) + i]; } if (mailmark_verify_postcode(postcode, 9, &postcode_type) != 0) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 587, "Invalid postcode \"%.9s\"", postcode); + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 587, "Invalid postcode \"%.9s\"", postcode); } /* Convert postcode to internal user field */ - large_load_u64(&destination_postcode, 0); + zint_large_load_u64(&destination_postcode, 0); if (postcode_type != 7) { const char *const pattern = mailmark_postcode_format[postcode_type - 1]; - large_load_u64(&b, 0); + zint_large_load_u64(&b, 0); for (i = 0; i < 9; i++) { switch (pattern[i]) { case 'A': - large_mul_u64(&b, 26); - large_add_u64(&b, posn(SET_A, postcode[i])); + zint_large_mul_u64(&b, 26); + zint_large_add_u64(&b, z_posn(SET_A, postcode[i])); break; case 'L': - large_mul_u64(&b, 20); - large_add_u64(&b, posn(SET_L, postcode[i])); + zint_large_mul_u64(&b, 20); + zint_large_add_u64(&b, z_posn(SET_L, postcode[i])); break; case 'N': - large_mul_u64(&b, 10); - large_add_u64(&b, posn(SET_N, postcode[i])); + zint_large_mul_u64(&b, 10); + zint_large_add_u64(&b, z_posn(SET_N, postcode[i])); break; /* case 'S' ignored as value is 0 */ } } - large_load(&destination_postcode, &b); + zint_large_load(&destination_postcode, &b); /* destination_postcode = a + b */ - large_load_u64(&b, 1); + zint_large_load_u64(&b, 1); if (postcode_type == 1) { - large_add(&destination_postcode, &b); + zint_large_add(&destination_postcode, &b); } - large_add_u64(&b, 5408000000); + zint_large_add_u64(&b, 5408000000); if (postcode_type == 2) { - large_add(&destination_postcode, &b); + zint_large_add(&destination_postcode, &b); } - large_add_u64(&b, 5408000000); + zint_large_add_u64(&b, 5408000000); if (postcode_type == 3) { - large_add(&destination_postcode, &b); + zint_large_add(&destination_postcode, &b); } - large_add_u64(&b, 54080000000); + zint_large_add_u64(&b, 54080000000); if (postcode_type == 4) { - large_add(&destination_postcode, &b); + zint_large_add(&destination_postcode, &b); } - large_add_u64(&b, 140608000000); + zint_large_add_u64(&b, 140608000000); if (postcode_type == 5) { - large_add(&destination_postcode, &b); + zint_large_add(&destination_postcode, &b); } - large_add_u64(&b, 208000000); + zint_large_add_u64(&b, 208000000); if (postcode_type == 6) { - large_add(&destination_postcode, &b); + zint_large_add(&destination_postcode, &b); } } /* Conversion from Internal User Fields to Consolidated Data Value */ /* Set CDV to 0 */ - large_load_u64(&cdv, 0); + zint_large_load_u64(&cdv, 0); /* Add Destination Post Code plus DPS */ - large_add(&cdv, &destination_postcode); + zint_large_add(&cdv, &destination_postcode); /* Multiply by 100,000,000 */ - large_mul_u64(&cdv, 100000000); + zint_large_mul_u64(&cdv, 100000000); /* Add Item ID */ - large_add_u64(&cdv, item_id); + zint_large_add_u64(&cdv, item_id); if (length == 22) { /* Barcode C - Multiply by 100 */ - large_mul_u64(&cdv, 100); + zint_large_mul_u64(&cdv, 100); } else { /* Barcode L - Multiply by 1,000,000 */ - large_mul_u64(&cdv, 1000000); + zint_large_mul_u64(&cdv, 1000000); } /* Add Supply Chain ID */ - large_add_u64(&cdv, supply_chain_id); + zint_large_add_u64(&cdv, supply_chain_id); /* Multiply by 15 */ - large_mul_u64(&cdv, 15); + zint_large_mul_u64(&cdv, 15); /* Add Class */ - large_add_u64(&cdv, mail_class); + zint_large_add_u64(&cdv, mail_class); /* Multiply by 5 */ - large_mul_u64(&cdv, 5); + zint_large_mul_u64(&cdv, 5); /* Add Format */ - large_add_u64(&cdv, format); + zint_large_add_u64(&cdv, format); /* Multiply by 4 */ - large_mul_u64(&cdv, 4); + zint_large_mul_u64(&cdv, 4); /* Add Version ID */ - large_add_u64(&cdv, version_id); + zint_large_add_u64(&cdv, version_id); if (symbol->debug & ZINT_DEBUG_PRINT) { printf("DPC type %d\n", postcode_type); fputs("CDV: ", stdout); - large_print(&cdv); + zint_large_print(&cdv); } if (length == 22) { @@ -388,18 +390,18 @@ INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int /* Conversion from Consolidated Data Value to Data Numbers */ for (j = data_top; j >= (data_step + 1); j--) { - data[j] = (unsigned char) large_div_u64(&cdv, 32); + data[j] = (unsigned char) zint_large_div_u64(&cdv, 32); } for (j = data_step; j >= 0; j--) { - data[j] = (unsigned char) large_div_u64(&cdv, 30); + data[j] = (unsigned char) zint_large_div_u64(&cdv, 30); } /* Generation of Reed-Solomon Check Numbers */ - rs_init_gf(&rs, 0x25); - rs_init_code(&rs, check_count, 1); + zint_rs_init_gf(&rs, 0x25); + zint_rs_init_code(&rs, check_count, 1); data_top++; - rs_encode(&rs, data_top, data, check); + zint_rs_encode(&rs, data_top, data, check); /* Append check digits to data */ memcpy(data + data_top, check, check_count); @@ -467,11 +469,11 @@ INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int j = 0; for (i = 0, len = d - bar; i < len; i++) { if ((bar[i] == 'F') || (bar[i] == 'A')) { - set_module(symbol, 0, j); + z_set_module(symbol, 0, j); } - set_module(symbol, 1, j); + z_set_module(symbol, 1, j); if ((bar[i] == 'F') || (bar[i] == 'D')) { - set_module(symbol, 2, j); + z_set_module(symbol, 2, j); } j += 2; } @@ -490,27 +492,27 @@ INTERNAL int mailmark_4s(struct zint_symbol *symbol, unsigned char source[], int symbol->row_height[0] = 3.16417313f; /* (1.9 * 42.3) / 25.4 */ symbol->row_height[1] = 2.16496062f; /* (1.3 * 42.3) / 25.4 */ /* Note using max X for minimum and min X for maximum */ - error_number = daft_set_height(symbol, min_height, max_height); + error_number = zint_daft_set_height(symbol, min_height, max_height); } else { symbol->row_height[0] = 4.0f; symbol->row_height[1] = 2.0f; - (void) daft_set_height(symbol, 0.0f, 0.0f); + (void) zint_daft_set_height(symbol, 0.0f, 0.0f); } symbol->rows = 3; symbol->width = j - 1; - if (raw_text && rt_cpy(symbol, local_source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, local_source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } 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); /* Royal Mail 2D Mailmark (CMDM) (Data Matrix) */ /* https://www.royalmailtechnical.com/rmt_docs/User_Guides_2021/Mailmark_Barcode_definition_document_20210215.pdf */ -INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int length) { static const char spaces[9] = " "; unsigned char local_source[90 + 1]; char postcode[10]; @@ -518,19 +520,19 @@ INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int struct zint_seg segs[1]; if (length > 90) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 589, "Input length %d too long (maximum 90)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 589, "Input length %d too long (maximum 90)", length); } if (length < 28) { /* After adding prefix (4), blank Return to Sender Post Code (7), Reserved (6): 28 + 17 = 45 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 860, "Input length %d too short (minimum 28)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 860, "Input length %d too short (minimum 28)", length); } /* Add prefix if missing */ memcpy(local_source, source, 4); - to_upper(local_source, 3); + z_to_upper(local_source, 3); if (memcmp(local_source, "JGB ", 4) != 0) { if (length > 86) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 861, "Input length %d too long (maximum 86)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 861, "Input length %d too long (maximum 86)", length); } memcpy(local_source, "JGB ", 4); memcpy(local_source + 4, source, length); @@ -540,13 +542,13 @@ INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int } if (length < 32) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 862, "Input length %d too short (minimum 32)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 862, "Input length %d too short (minimum 32)", length); } if (length < 39) { /* Space-pad Return to Sender Post Code */ memset(local_source + length, ' ', 39 - length); length = 39; } - to_upper(local_source, 39); + z_to_upper(local_source, 39); if (length < 45) { /* Space-pad Reserved */ memset(local_source + length, ' ', 45 - length); @@ -557,17 +559,17 @@ INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int /* 8: 24 x 24, 10: 32 x 32, 30: 16 x 48 */ if (symbol->option_2) { if (symbol->option_2 != 8 && symbol->option_2 != 10 && symbol->option_2 != 30) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 863, "Invalid Version '%d' (8, 10 or 30 only)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 863, "Invalid Version '%d' (8, 10 or 30 only)", symbol->option_2); } if (symbol->option_2 == 8) { if (length > 51) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 864, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 864, "Input length %d too long for Version 8 (maximum 51)", length); } } else if (symbol->option_2 == 30) { if (length > 70) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 865, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 865, "Input length %d too long for Version 30 (maximum 70)", length); } } @@ -585,8 +587,8 @@ INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int printf("Producing 2D Mailmark %d (%d): %s\n", symbol->option_2, length, local_source); } - if ((i = not_sane(RUBIDIUM_F, local_source, 45))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 866, + if ((i = z_not_sane(RUBIDIUM_F, local_source, 45))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 866, "Invalid character at position %d in input (alphanumerics and space only in first 45)", i); } @@ -594,23 +596,23 @@ INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int /* Not checking that matches values listed in Mailmark Definition Document as contradicted by Mailmark Mailing Requirements Section 5.7 which says 'P' for poll card is valid, which isn't listed */ if (local_source[4] == ' ') { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 867, "Invalid Information Type ID (cannot be space)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 867, "Invalid Information Type ID (cannot be space)"); } /* Version ID */ if (local_source[5] != '1') { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 868, "Invalid Version ID (\"1\" only)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 868, "Invalid Version ID (\"1\" only)"); } /* Class */ if (local_source[6] == ' ') { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 869, "Invalid Class (cannot be space)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 869, "Invalid Class (cannot be space)"); } /* Supply Chain ID */ - if (cnt_digits(local_source, length, 7, 7) != 7) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 870, "Invalid Supply Chain ID (7 digits only)"); + if (z_cnt_digits(local_source, length, 7, 7) != 7) { + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 870, "Invalid Supply Chain ID (7 digits only)"); } /* Item ID */ - if (cnt_digits(local_source, length, 14, 8) != 8) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 871, "Invalid Item ID (8 digits only)"); + if (z_cnt_digits(local_source, length, 14, 8) != 8) { + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 871, "Invalid Item ID (8 digits only)"); } /* Destination Post Code plus DPS field */ @@ -622,13 +624,13 @@ INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int i++; /* If not 2 to 4 non-spaces left, check full post code */ if (mailmark_verify_postcode(postcode, i >= 2 && i <= 4 ? i : 9, NULL /*p_postcode_type*/) != 0) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 872, "Invalid Destination Post Code plus DPS"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 872, "Invalid Destination Post Code plus DPS"); } } /* Service Type */ if (local_source[31] < '0' || local_source[31] > '6') { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 873, "Invalid Service Type (\"0\" to \"6\" only)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 873, "Invalid Service Type (\"0\" to \"6\" only)"); } /* Return to Sender Post Code */ @@ -645,20 +647,20 @@ INTERNAL int mailmark_2d(struct zint_symbol *symbol, unsigned char source[], int postcode[i++] = ' '; } if (mailmark_verify_postcode(postcode, 9, NULL /*p_postcode_type*/) != 0) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 874, "Invalid Return to Sender Post Code"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 874, "Invalid Return to Sender Post Code"); } } /* Reserved */ if (memcmp(local_source + 39, spaces, 6) != 0) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 875, "Invalid Reserved field (must be spaces only)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 875, "Invalid Reserved field (must be spaces only)"); } segs[0].eci = 0; segs[0].source = local_source; segs[0].length = length; - return datamatrix(symbol, segs, 1); + return zint_datamatrix(symbol, segs, 1); } /* vim: set ts=4 sw=4 et : */ diff --git a/backend/maxicode.c b/backend/maxicode.c index 08dbab3d..ade9d9e3 100644 --- a/backend/maxicode.c +++ b/backend/maxicode.c @@ -141,7 +141,7 @@ static int mx_symbol_ch(const unsigned char op, const unsigned char ch) { return maxiSymbolChar[ch]; } if (op & MX_OP_SETB) { - const int p = posn(" ,./:", ch); + const int p = z_posn(" ,./:", ch); if (p >= 0) { return 47 + p; } @@ -288,7 +288,7 @@ static int mx_text_process_segs(unsigned char codewords[144], const int mode, st int ci, ci_top; /* Backtracking information */ - const int segs_len = segs_length(segs, seg_count); + const int segs_len = z_segs_length(segs, seg_count); char (*prior_code_sets)[MX_STATES] = (char (*)[MX_STATES]) z_alloca(sizeof(*prior_code_sets) * (segs_len + 9)); unsigned char (*path_ops)[MX_STATES] = (unsigned char (*)[MX_STATES]) z_alloca(sizeof(*path_ops) * (segs_len + 9)); @@ -466,10 +466,10 @@ static void mx_do_primary_ecc(unsigned char codewords[144]) { int j; rs_t rs; - rs_init_gf(&rs, 0x43); - rs_init_code(&rs, eclen, 1); + zint_rs_init_gf(&rs, 0x43); + zint_rs_init_code(&rs, eclen, 1); - rs_encode(&rs, datalen, codewords, ecc); + zint_rs_encode(&rs, datalen, codewords, ecc); for (j = 0; j < eclen; j++) { codewords[datalen + j] = ecc[j]; @@ -483,15 +483,15 @@ static void mx_do_secondary_ecc(unsigned char codewords[144], const int datalen, int j; rs_t rs; - rs_init_gf(&rs, 0x43); - rs_init_code(&rs, eclen, 1); + zint_rs_init_gf(&rs, 0x43); + zint_rs_init_code(&rs, eclen, 1); /* Even */ for (j = 0; j < datalen; j += 2) { data[j >> 1] = codewords[j + 20]; } - rs_encode(&rs, datalen >> 1, data, ecc); + zint_rs_encode(&rs, datalen >> 1, data, ecc); for (j = 0; j < eclen; j++) { codewords[datalen + (j << 1) + 20] = ecc[j]; @@ -502,7 +502,7 @@ static void mx_do_secondary_ecc(unsigned char codewords[144], const int datalen, data[j >> 1] = codewords[j + 1 + 20]; } - rs_encode(&rs, datalen >> 1, data, ecc); + zint_rs_encode(&rs, datalen >> 1, data, ecc); for (j = 0; j < eclen; j++) { codewords[datalen + (j << 1) + 1 + 20] = ecc[j]; @@ -513,7 +513,7 @@ static void mx_do_secondary_ecc(unsigned char codewords[144], const int datalen, static void mx_do_primary_2(unsigned char codewords[144], const unsigned char postcode[], const int postcode_length, const int country, const int service) { - const int postcode_num = to_int(postcode, postcode_length); + const int postcode_num = z_to_int(postcode, postcode_length); codewords[0] = ((postcode_num & 0x03) << 4) | 2; codewords[1] = ((postcode_num & 0xFC) >> 2); @@ -549,7 +549,7 @@ static void mx_do_primary_3(unsigned char codewords[144], unsigned char postcode codewords[9] = ((service & 0x3F0) >> 4); } -INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int i, j, mode, lp = 0; int error_number; unsigned char codewords[144]; @@ -564,7 +564,7 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const lp = (int) strlen(symbol->primary); if (lp == 0) { if (mode == 0) { /* Require primary message to auto-determine between 2 and 3 */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 554, "Primary Message empty"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 554, "Primary Message empty"); } mode = 4; } else { @@ -579,7 +579,7 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const } if (mode < 2 || mode > 6) { /* Only codes 2 to 6 supported */ - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 550, "Mode '%d' out of range (2 to 6)", mode); + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 550, "Mode '%d' out of range (2 to 6)", mode); } if (mode <= 3) { /* Modes 2 and 3 need data in symbol->primary */ @@ -592,18 +592,18 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const } if (lp < 7 || lp > 15) { /* 1 to 9 character postcode + 3 digit country code + 3 digit service class */ if (lp == 0) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 548, "Primary Message empty"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 548, "Primary Message empty"); } - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 551, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 551, "Primary Message length %d wrong (7 to 15 characters required)", lp); } postcode_len = lp - 6; - countrycode = to_int((const unsigned char *) (symbol->primary + postcode_len), 3); - service = to_int((const unsigned char *) (symbol->primary + postcode_len + 3), 3); + countrycode = z_to_int(ZCUCP(symbol->primary + postcode_len), 3); + service = z_to_int(ZCUCP(symbol->primary + postcode_len + 3), 3); if (countrycode == -1 || service == -1) { /* Check that country code and service are numeric */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 552, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 552, "Non-numeric country code or service class in Primary Message"); } @@ -618,7 +618,7 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const break; } if (!z_isdigit(postcode[i])) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 555, "Non-numeric postcode in Primary Message"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 555, "Non-numeric postcode in Primary Message"); } } if (countrycode == 840 && postcode_len == 5) { @@ -635,11 +635,11 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const postcode[i] = ' '; } /* Upper-case and check for Code Set A characters only */ - to_upper(postcode, postcode_len); + z_to_upper(postcode, postcode_len); for (i = 0; i < 6; i++) { /* Don't allow control chars (CR FS GS RS for Code Set A) */ if (postcode[i] < ' ' || !(maxiCodeSet[postcode[i]] & MX_OP_SETA)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 556, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 556, "Invalid character in postcode in Primary Message"); } } @@ -648,11 +648,11 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const if (symbol->option_2) { /* Check for option_2 = vv + 1, where vv is version of SCM prefix "[)>\R01\Gvv" */ if (symbol->option_2 < 0 || symbol->option_2 > 100) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 557, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 557, "SCM prefix version '%d' out of range (1 to 100)", symbol->option_2); } if (symbol->eci == 25 || (symbol->eci >= 33 && symbol->eci <= 35)) { /* UTF-16/32 */ - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 547, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 547, "SCM prefix can not be used with ECI %d (ECI must be ASCII compatible)", symbol->eci); } scm_vv = symbol->option_2 - 1; @@ -674,32 +674,33 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const if (symbol->structapp.count) { if (symbol->structapp.count < 2 || symbol->structapp.count > 8) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 558, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 558, "Structured Append count '%d' out of range (2 to 8)", symbol->structapp.count); } if (symbol->structapp.index < 1 || symbol->structapp.index > symbol->structapp.count) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 559, - "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, 559, + "Structured Append index '%1$d' out of range (1 to count %2$d)", + symbol->structapp.index, symbol->structapp.count); } if (symbol->structapp.id[0]) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 549, "Structured Append ID not available for MaxiCode"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 549, + "Structured Append ID not available for MaxiCode"); } structapp_cw = (symbol->structapp.count - 1) | ((symbol->structapp.index - 1) << 3); } error_number = mx_text_process_segs(codewords, mode, segs, seg_count, structapp_cw, scm_vv, debug_print); if (error_number == ZINT_ERROR_TOO_LONG) { - return errtxt(error_number, symbol, 553, "Input too long, requires too many codewords (maximum 144)"); + return z_errtxt(error_number, symbol, 553, "Input too long, requires too many codewords (maximum 144)"); } if (raw_text) { - if (rt_init_segs(symbol, seg_count)) { - return ZINT_ERROR_MEMORY; /* `rt_init_segs()` only fails with OOM */ + if (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++) { - if (rt_cpy_seg(symbol, i, &segs[i])) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg()` only fails with OOM */ + if (z_rt_cpy_seg(symbol, i, &segs[i])) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg()` only fails with OOM */ } } } @@ -722,7 +723,7 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump(symbol, codewords, 144); + z_debug_test_codeword_dump(symbol, codewords, 144); } #endif @@ -734,32 +735,32 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const if (block != 0) { if ((codewords[block - 1] >> (5 - (mod_seq % 6))) & 1) { - set_module(symbol, i, j); + z_set_module(symbol, i, j); } } } } /* Add orientation markings */ - set_module(symbol, 0, 28); /* Top right filler */ - set_module(symbol, 0, 29); - set_module(symbol, 9, 10); /* Top left marker */ - set_module(symbol, 9, 11); - set_module(symbol, 10, 11); - set_module(symbol, 15, 7); /* Left hand marker */ - set_module(symbol, 16, 8); - set_module(symbol, 16, 20); /* Right hand marker */ - set_module(symbol, 17, 20); - set_module(symbol, 22, 10); /* Bottom left marker */ - set_module(symbol, 23, 10); - set_module(symbol, 22, 17); /* Bottom right marker */ - set_module(symbol, 23, 17); + z_set_module(symbol, 0, 28); /* Top right filler */ + z_set_module(symbol, 0, 29); + z_set_module(symbol, 9, 10); /* Top left marker */ + z_set_module(symbol, 9, 11); + z_set_module(symbol, 10, 11); + z_set_module(symbol, 15, 7); /* Left hand marker */ + z_set_module(symbol, 16, 8); + z_set_module(symbol, 16, 20); /* Right hand marker */ + z_set_module(symbol, 17, 20); + z_set_module(symbol, 22, 10); /* Bottom left marker */ + z_set_module(symbol, 23, 10); + z_set_module(symbol, 22, 17); /* Bottom right marker */ + z_set_module(symbol, 23, 17); symbol->width = 30; symbol->rows = 33; /* Note MaxiCode fixed size so symbol height ignored but set anyway */ - (void) set_height(symbol, 5.0f, 0.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 5.0f, 0.0f, 0.0f, 1 /*no_errtxt*/); return error_number; } diff --git a/backend/medical.c b/backend/medical.c index 8e1bf567..569d4ab0 100644 --- a/backend/medical.c +++ b/backend/medical.c @@ -34,10 +34,10 @@ #include #include "common.h" -INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int length); +INTERNAL int zint_code39(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode One-Track */ -INTERNAL int pharma(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_pharma(struct zint_symbol *symbol, unsigned char source[], int length) { /* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other commonly used one-dimensional barcode schemes, pharmacode does not store the data in a form corresponding to the human-readable digits; the number is encoded in binary, rather @@ -61,16 +61,16 @@ INTERNAL int pharma(struct zint_symbol *symbol, unsigned char source[], int leng const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 6) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 350, "Input length %d too long (maximum 6)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 350, "Input length %d too long (maximum 6)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 351, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 351, "Invalid character at position %d in input (digits only)", i); } - tester = to_int(source, length); + tester = z_to_int(source, length); if ((tester < 3) || (tester > 131070)) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 352, "Input value '%d' out of range (3 to 131070)", tester); + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 352, "Input value '%d' out of range (3 to 131070)", tester); } do { @@ -90,17 +90,17 @@ INTERNAL int pharma(struct zint_symbol *symbol, unsigned char source[], int leng } *--d = '\0'; /* Chop off final bar */ - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (symbol->output_options & COMPLIANT_HEIGHT) { /* Laetus Pharmacode Guide 1.2 Standard one-track height 8mm / 0.5mm (X) */ - error_number = set_height(symbol, 16.0f, 0.0f, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 16.0f, 0.0f, 0.0f, 0 /*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*/); } - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; @@ -143,7 +143,7 @@ static int pharma_two_calc(int tester, char *d) { } /* Pharmacode Two-Track */ -INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) { /* Draws the patterns for two track pharmacode */ int i; int tester; @@ -154,26 +154,27 @@ INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 8) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 354, "Input length %d too long (maximum 8)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 354, "Input length %d too long (maximum 8)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 355, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 355, "Invalid character at position %d in input (digits only)", i); } - tester = to_int(source, length); + tester = z_to_int(source, length); if ((tester < 4) || (tester > 64570080)) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 353, "Input value '%d' out of range (4 to 64570080)", tester); + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 353, "Input value '%d' out of range (4 to 64570080)", + tester); } h = pharma_two_calc(tester, height_pattern); writer = 0; for (loopey = 0; loopey < h; loopey++) { if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3')) { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3')) { - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); } writer += 2; } @@ -184,20 +185,20 @@ INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int /* Laetus Pharmacode Guide 1.4 Two-track height min 8mm / 2mm (X max) = 4X (2X per row), standard 8mm / 1mm = 8X, max 12mm / 0.8mm (X min) = 15X */ - error_number = set_height(symbol, 2.0f, 8.0f, 15.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 2.0f, 8.0f, 15.0f, 0 /*no_errtxt*/); } else { - (void) set_height(symbol, 0.0f, 10.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 10.0f, 0.0f, 1 /*no_errtxt*/); } - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; } /* Italian Pharmacode */ -INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_code32(struct zint_symbol *symbol, unsigned char source[], int length) { static const unsigned char TABELLA[] = "0123456789BCDFGHJKLMNPQRSTUVWXYZ"; int i, zeroes, checksum, checkpart, checkdigit; unsigned char local_source[10], risultante[7]; @@ -208,10 +209,10 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng /* Validate the input */ if (length > 8) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 360, "Input length %d too long (maximum 8)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 360, "Input length %d too long (maximum 8)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 361, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 361, "Invalid character at position %d in input (digits only)", i); } @@ -223,9 +224,9 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng /* Calculate the check digit */ checksum = 0; for (i = 0; i < 4; i++) { - checkpart = ctoi(local_source[i * 2]); + checkpart = z_ctoi(local_source[i * 2]); checksum += checkpart; - checkpart = 2 * (ctoi(local_source[(i * 2) + 1])); + checkpart = 2 * (z_ctoi(local_source[(i * 2) + 1])); if (checkpart >= 10) { checksum += (checkpart - 10) + 1; } else { @@ -235,10 +236,10 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng /* Add check digit to data string */ checkdigit = checksum % 10; - local_source[8] = itoc(checkdigit); + local_source[8] = z_itoc(checkdigit); /* Convert string into an integer value */ - pharmacode = to_int(local_source, 9); + pharmacode = z_to_int(local_source, 9); /* Convert from decimal to base-32 */ devisor = 33554432; @@ -256,11 +257,11 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng } if (symbol->option_2 == 1 || symbol->option_2 == 2) { - symbol->option_2 = 0; /* Need to overwrite this so `code39()` doesn't add a check digit itself */ + symbol->option_2 = 0; /* Need to overwrite this so `zint_code39()` doesn't add a check digit itself */ } /* Plot the barcode using Code 39 */ - if ((error_number = code39(symbol, risultante, 6))) { + if ((error_number = zint_code39(symbol, risultante, 6))) { assert(error_number == ZINT_ERROR_MEMORY); /* Only error that can occur */ return error_number; } @@ -276,16 +277,16 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng &art.tiposerie=SG) X given as 0.250mm; height (and quiet zones) left to ISO/IEC 16388:2007 (Code 39) So min height 5mm = 5mm / 0.25mm = 20 > 15% of width, i.e. (10 * 8 + 19) * 0.15 = 14.85 */ - error_number = set_height(symbol, 20.0f, 20.0f, 0.0f, 0 /*no_errtxt*/); /* Use as default also */ + error_number = z_set_height(symbol, 20.0f, 20.0f, 0.0f, 0 /*no_errtxt*/); /* Use as default also */ } 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*/); } /* Override the normal text output with the Pharmacode number */ - hrt_cpy_chr(symbol, 'A'); - hrt_cat_nochk(symbol, local_source, 9); + z_hrt_cpy_chr(symbol, 'A'); + z_hrt_cat_nochk(symbol, local_source, 9); - /* Use `raw_text` set by `code39()` */ + /* Use `raw_text` set by `zint_code39()` */ return error_number; } @@ -294,7 +295,7 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng /* PZN https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/IFA_Info_Code_39_EN.pdf */ /* PZN https://www.ifaffm.de/mandanten/1/documents/04_ifa_coding_system/ IFA-Info_Check_Digit_Calculations_PZN_PPN_UDI_EN.pdf */ -INTERNAL int pzn(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_pzn(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number, zeroes; int count, check_digit; @@ -304,15 +305,15 @@ INTERNAL int pzn(struct zint_symbol *symbol, unsigned char source[], int length) const int saved_option_2 = symbol->option_2; if (length > 8 - pzn7) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 325, "Input length %1$d too long (maximum %2$d)", length, - 8 - pzn7); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 325, "Input length %1$d too long (maximum %2$d)", length, + 8 - pzn7); } if (length == 8 - pzn7) { have_check_digit = source[7 - pzn7]; length--; } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 326, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 326, "Invalid character at position %d in input (digits only)", i); } @@ -324,7 +325,7 @@ INTERNAL int pzn(struct zint_symbol *symbol, unsigned char source[], int length) count = 0; for (i = 1; i < 8 - pzn7; i++) { - count += (i + pzn7) * ctoi(local_source[i]); + count += (i + pzn7) * z_ctoi(local_source[i]); } check_digit = count % 11; @@ -334,20 +335,20 @@ INTERNAL int pzn(struct zint_symbol *symbol, unsigned char source[], int length) } if (check_digit == 10) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 327, "Invalid PZN, check digit is '10'"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 327, "Invalid PZN, check digit is '10'"); } - if (have_check_digit && ctoi(have_check_digit) != check_digit) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 890, "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, 890, "Invalid check digit '%1$c', expecting '%2$c'", + have_check_digit, z_itoc(check_digit)); } - local_source[8 - pzn7] = itoc(check_digit); + local_source[8 - pzn7] = z_itoc(check_digit); if (symbol->option_2 == 1 || symbol->option_2 == 2) { - symbol->option_2 = 0; /* Need to overwrite this so `code39()` doesn't add a check digit itself */ + symbol->option_2 = 0; /* Need to overwrite this so `zint_code39()` doesn't add a check digit itself */ } - error_number = code39(symbol, local_source, 9 - pzn7); + error_number = zint_code39(symbol, local_source, 9 - pzn7); if (symbol->option_2 == 1 || symbol->option_2 == 2) { symbol->option_2 = saved_option_2; /* Restore */ @@ -361,18 +362,18 @@ INTERNAL int pzn(struct zint_symbol *symbol, unsigned char source[], int length) if (error_number < ZINT_ERROR) { const float min_height = 17.7777786f; /* 8.0 / 0.45 */ const float max_height = 106.951874f; /* 20.0 / 0.187 */ - error_number = set_height(symbol, min_height, 40.0f, max_height, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, min_height, 40.0f, max_height, 0 /*no_errtxt*/); } } else { if (error_number < ZINT_ERROR) { - (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*/); } } - hrt_cpy_nochk(symbol, (const unsigned char *) "PZN - ", 6); /* Note changed to put space after hyphen */ - hrt_cat_nochk(symbol, local_source + 1, 9 - pzn7 - 1); + z_hrt_cpy_nochk(symbol, (const unsigned char *) "PZN - ", 6); /* Note changed to put space after hyphen */ + z_hrt_cat_nochk(symbol, local_source + 1, 9 - pzn7 - 1); - /* Use `raw_text` set by `code39()` */ + /* Use `raw_text` set by `zint_code39()` */ return error_number; } diff --git a/backend/output.c b/backend/output.c index e98d952d..9bb7ffcf 100644 --- a/backend/output.c +++ b/backend/output.c @@ -52,12 +52,12 @@ static int out_check_colour(struct zint_symbol *symbol, const char *colour, cons if ((comma1 = strchr(colour, ',')) == NULL) { const int len = (int) strlen(colour); if (len != 6 && len != 8) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 880, "Malformed %s RGB colour (6 or 8 characters only)", - name); + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 880, + "Malformed %s RGB colour (6 or 8 characters only)", name); } - if (not_sane(OUT_SSET_F, ZCUCP(colour), len)) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 881, - "Malformed %1$s RGB colour '%2$s' (hexadecimal only)", name, colour); + if (z_not_sane(OUT_SSET_F, ZCUCP(colour), len)) { + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 881, + "Malformed %1$s RGB colour '%2$s' (hexadecimal only)", name, colour); } return 0; @@ -66,28 +66,28 @@ static int out_check_colour(struct zint_symbol *symbol, const char *colour, cons /* CMYK comma-separated percentages */ if ((comma2 = strchr(comma1 + 1, ',')) == NULL || (comma3 = strchr(comma2 + 1, ',')) == NULL || strchr(comma3 + 1, ',') != NULL) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 882, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 882, "Malformed %s CMYK colour (4 decimal numbers, comma-separated)", name); } if (comma1 - colour > 3 || comma2 - (comma1 + 1) > 3 || comma3 - (comma2 + 1) > 3 || strlen(comma3 + 1) > 3) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 883, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 883, "Malformed %s CMYK colour (3 digit maximum per number)", name); } - if ((val = to_int(ZCUCP(colour), (int) (comma1 - colour))) == -1 || val > 100) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 884, "Malformed %s CMYK colour C (decimal 0 to 100 only)", + if ((val = z_to_int(ZCUCP(colour), (int) (comma1 - colour))) == -1 || val > 100) { + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 884, "Malformed %s CMYK colour C (decimal 0 to 100 only)", name); } - if ((val = to_int(ZCUCP(comma1 + 1), (int) (comma2 - (comma1 + 1)))) == -1 || val > 100) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 885, "Malformed %s CMYK colour M (decimal 0 to 100 only)", + if ((val = z_to_int(ZCUCP(comma1 + 1), (int) (comma2 - (comma1 + 1)))) == -1 || val > 100) { + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 885, "Malformed %s CMYK colour M (decimal 0 to 100 only)", name); } - if ((val = to_int(ZCUCP(comma2 + 1), (int) (comma3 - (comma2 + 1)))) == -1 || val > 100) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 886, "Malformed %s CMYK colour Y (decimal 0 to 100 only)", + if ((val = z_to_int(ZCUCP(comma2 + 1), (int) (comma3 - (comma2 + 1)))) == -1 || val > 100) { + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 886, "Malformed %s CMYK colour Y (decimal 0 to 100 only)", name); } - if ((val = to_int(ZCUCP(comma3 + 1), (int) strlen(comma3 + 1))) == -1 || val > 100) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 887, "Malformed %s CMYK colour K (decimal 0 to 100 only)", + if ((val = z_to_int(ZCUCP(comma3 + 1), (int) strlen(comma3 + 1))) == -1 || val > 100) { + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 887, "Malformed %s CMYK colour K (decimal 0 to 100 only)", name); } @@ -95,7 +95,7 @@ static int out_check_colour(struct zint_symbol *symbol, const char *colour, cons } /* Check colour options are good (`symbol->fgcolour`, `symbol->bgcolour`) */ -INTERNAL int out_check_colour_options(struct zint_symbol *symbol) { +INTERNAL int zint_out_check_colour_options(struct zint_symbol *symbol) { if (out_check_colour(symbol, symbol->fgcolour, "foreground") != 0) { return ZINT_ERROR_INVALID_OPTION; @@ -108,17 +108,17 @@ INTERNAL int out_check_colour_options(struct zint_symbol *symbol) { } /* Return RGB(A) from (well-formed) colour string. Returns 0 if RGB or converted CMYK, 1 if RGBA */ -INTERNAL int out_colour_get_rgb(const char *colour, unsigned char *red, unsigned char *green, unsigned char *blue, - unsigned char *alpha) { +INTERNAL int zint_out_colour_get_rgb(const char *colour, unsigned char *red, unsigned char *green, + unsigned char *blue, unsigned char *alpha) { const char *comma1, *comma2, *comma3; int black, val; if ((comma1 = strchr(colour, ',')) == NULL) { - *red = (unsigned char) (16 * ctoi(colour[0]) + ctoi(colour[1])); - *green = (unsigned char) (16 * ctoi(colour[2]) + ctoi(colour[3])); - *blue = (unsigned char) (16 * ctoi(colour[4]) + ctoi(colour[5])); + *red = (unsigned char) (16 * z_ctoi(colour[0]) + z_ctoi(colour[1])); + *green = (unsigned char) (16 * z_ctoi(colour[2]) + z_ctoi(colour[3])); + *blue = (unsigned char) (16 * z_ctoi(colour[4]) + z_ctoi(colour[5])); if (alpha) { - *alpha = (unsigned char) (colour[6] ? 16 * ctoi(colour[6]) + ctoi(colour[7]) : 0xFF); + *alpha = (unsigned char) (colour[6] ? 16 * z_ctoi(colour[6]) + z_ctoi(colour[7]) : 0xFF); return colour[6] ? 1 : 0; } return 0; @@ -126,15 +126,15 @@ INTERNAL int out_colour_get_rgb(const char *colour, unsigned char *red, unsigned comma2 = strchr(comma1 + 1, ','); comma3 = strchr(comma2 + 1, ','); - black = 100 - to_int(ZCUCP(comma3 + 1), (int) strlen(comma3 + 1)); + black = 100 - z_to_int(ZCUCP(comma3 + 1), (int) strlen(comma3 + 1)); - val = 100 - to_int(ZCUCP(colour), (int) (comma1 - colour)); /* Cyan */ + val = 100 - z_to_int(ZCUCP(colour), (int) (comma1 - colour)); /* Cyan */ *red = (unsigned char) round((0xFF * val * black) / 10000.0); - val = 100 - to_int(ZCUCP(comma1 + 1), (int) (comma2 - (comma1 + 1))); /* Magenta */ + val = 100 - z_to_int(ZCUCP(comma1 + 1), (int) (comma2 - (comma1 + 1))); /* Magenta */ *green = (unsigned char) round((0xFF * val * black) / 10000.0); - val = 100 - to_int(ZCUCP(comma2 + 1), (int) (comma3 - (comma2 + 1))); /* Yellow */ + val = 100 - z_to_int(ZCUCP(comma2 + 1), (int) (comma3 - (comma2 + 1))); /* Yellow */ *blue = (unsigned char) round((0xFF * val * black) / 10000.0); if (alpha) { @@ -145,7 +145,7 @@ INTERNAL int out_colour_get_rgb(const char *colour, unsigned char *red, unsigned } /* Return CMYK from (well-formed) colour string. Returns 0 if CMYK, 1 if converted RBG, 2 if converted RGBA */ -INTERNAL int out_colour_get_cmyk(const char *colour, int *cyan, int *magenta, int *yellow, int *black, +INTERNAL int zint_out_colour_get_cmyk(const char *colour, int *cyan, int *magenta, int *yellow, int *black, unsigned char *rgb_alpha) { const char *comma1; unsigned char red, green, blue, alpha; @@ -154,16 +154,16 @@ INTERNAL int out_colour_get_cmyk(const char *colour, int *cyan, int *magenta, in if ((comma1 = strchr(colour, ',')) != NULL) { const char *const comma2 = strchr(comma1 + 1, ','); const char *const comma3 = strchr(comma2 + 1, ','); - *cyan = to_int(ZCUCP(colour), (int) (comma1 - colour)); - *magenta = to_int(ZCUCP(comma1 + 1), (int) (comma2 - (comma1 + 1))); - *yellow = to_int(ZCUCP(comma2 + 1), (int) (comma3 - (comma2 + 1))); - *black = to_int(ZCUCP(comma3 + 1), (int) strlen(comma3 + 1)); + *cyan = z_to_int(ZCUCP(colour), (int) (comma1 - colour)); + *magenta = z_to_int(ZCUCP(comma1 + 1), (int) (comma2 - (comma1 + 1))); + *yellow = z_to_int(ZCUCP(comma2 + 1), (int) (comma3 - (comma2 + 1))); + *black = z_to_int(ZCUCP(comma3 + 1), (int) strlen(comma3 + 1)); if (rgb_alpha) { *rgb_alpha = 0xFF; } return 0; } - have_alpha = out_colour_get_rgb(colour, &red, &green, &blue, &alpha); + have_alpha = zint_out_colour_get_rgb(colour, &red, &green, &blue, &alpha); k = red; if (green > k) { @@ -190,7 +190,7 @@ INTERNAL int out_colour_get_cmyk(const char *colour, int *cyan, int *magenta, in } /* Convert internal colour chars "WCBMRYGK" to RGB */ -INTERNAL int out_colour_char_to_rgb(const unsigned char ch, unsigned char *red, unsigned char *green, +INTERNAL int zint_out_colour_char_to_rgb(const unsigned char ch, unsigned char *red, unsigned char *green, unsigned char *blue) { static const char chars[] = "WCBMRYGK"; static const unsigned char colours[8][3] = { @@ -203,7 +203,7 @@ INTERNAL int out_colour_char_to_rgb(const unsigned char ch, unsigned char *red, { 0, 0xff, 0, }, /* Green */ { 0, 0, 0, }, /* Black */ }; - int i = posn(chars, (const char) ch); + int i = z_posn(chars, (const char) ch); int ret = i != -1; if (i == -1) { @@ -411,11 +411,11 @@ static int out_quiet_zones(const struct zint_symbol *symbol, const int hide_text int comp_roffset = 0; /* Right offset of linear */ int min_qz; /* Minimum quiet zone - 1X for CC-A/B, 2X for CC-C */ int x; - for (x = symbol->width - 1; x >= 0 && !module_is_set(symbol, symbol->rows - 1, x); x--) { + for (x = symbol->width - 1; x >= 0 && !z_module_is_set(symbol, symbol->rows - 1, x); x--) { comp_roffset++; } /* Determine if CC-C by counting initial start pattern */ - for (x = 0; x < 8 && module_is_set(symbol, 0, x); x++); + for (x = 0; x < 8 && z_module_is_set(symbol, 0, x); x++); min_qz = x == 8 ? 2 : 1; *left = comp_xoffset >= 10 - min_qz ? min_qz : 10.0f - comp_xoffset; *right = comp_roffset >= 10 - min_qz ? min_qz : 10.0f - comp_roffset; @@ -693,14 +693,14 @@ static int out_quiet_zones(const struct zint_symbol *symbol, const int hide_text } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL int out_quiet_zones_test(const struct zint_symbol *symbol, const int hide_text, const int comp_xoffset, +INTERNAL int zint_test_out_quiet_zones(const struct zint_symbol *symbol, const int hide_text, const int comp_xoffset, float *left, float *right, float *top, float *bottom) { return out_quiet_zones(symbol, hide_text, comp_xoffset, left, right, top, bottom); } #endif /* Set left (x), top (y), right and bottom offsets for whitespace, also right quiet zone */ -INTERNAL void out_set_whitespace_offsets(const struct zint_symbol *symbol, const int hide_text, +INTERNAL void zint_out_set_whitespace_offsets(const struct zint_symbol *symbol, const int hide_text, const int comp_xoffset, float *p_xoffset, float *p_yoffset, float *p_roffset, float *p_boffset, float *p_qz_right, const float scaler, int *p_xoffset_si, int *p_yoffset_si, int *p_roffset_si, int *p_boffset_si, int *p_qz_right_si) { @@ -749,7 +749,7 @@ INTERNAL void out_set_whitespace_offsets(const struct zint_symbol *symbol, const /* Set composite offset and main width excluding add-on (for start of add-on calc) and add-on text, returning EAN/UPC type */ -INTERNAL int out_process_upcean(const struct zint_symbol *symbol, const int comp_xoffset, int *p_main_width, +INTERNAL int zint_out_process_upcean(const struct zint_symbol *symbol, const int comp_xoffset, int *p_main_width, unsigned char addon[6], int *p_addon_len, int *p_addon_gap) { int main_width; /* Width of main linear symbol, excluding add-on */ int upceanflag; /* EAN/UPC type flag */ @@ -769,7 +769,7 @@ INTERNAL int out_process_upcean(const struct zint_symbol *symbol, const int comp } addon[j] = '\0'; if (latch) { - *p_addon_len = (int) ustrlen(addon); + *p_addon_len = (int) z_ustrlen(addon); if (symbol->symbology == BARCODE_UPCA || symbol->symbology == BARCODE_UPCA_CHK || symbol->symbology == BARCODE_UPCA_CC) { *p_addon_gap = symbol->option_2 >= 9 && symbol->option_2 <= 12 ? symbol->option_2 : 9; @@ -780,7 +780,7 @@ INTERNAL int out_process_upcean(const struct zint_symbol *symbol, const int comp upceanflag = 0; main_width = symbol->width; - if (is_ean(symbol->symbology)) { + if (z_is_ean(symbol->symbology)) { switch (symbol->text_length) { case 13: /* EAN-13 */ case 16: /* EAN-13 + EAN-2 */ @@ -819,7 +819,7 @@ INTERNAL int out_process_upcean(const struct zint_symbol *symbol, const int comp /* Calculate large bar height i.e. linear bars with zero row height that respond to the symbol height. If scaler `si` non-zero (raster), then large_bar_height if non-zero or else row heights will be rounded to nearest pixel and symbol height adjusted */ -INTERNAL float out_large_bar_height(struct zint_symbol *symbol, const int si, int *row_heights_si, +INTERNAL float zint_out_large_bar_height(struct zint_symbol *symbol, const int si, int *row_heights_si, int *symbol_height_si) { float fixed_height = 0.0f; int zero_count = 0; @@ -831,7 +831,7 @@ INTERNAL float out_large_bar_height(struct zint_symbol *symbol, const int si, in for (i = 0; i < symbol->rows; i++) { if (symbol->row_height[i]) { fixed_height += symbol->row_height[i]; - if (!round_rows && !isfintf(symbol->row_height[i] * si)) { + if (!round_rows && !z_isfintf(symbol->row_height[i] * si)) { round_rows = 1; } } else { @@ -840,23 +840,23 @@ INTERNAL float out_large_bar_height(struct zint_symbol *symbol, const int si, in } if (zero_count) { - large_bar_height = stripf((symbol->height - fixed_height) / zero_count); - assert(large_bar_height >= 0.5f); /* Min row height as set by `set_height()` */ - if (!isfintf(large_bar_height * si)) { - large_bar_height = stripf(roundf(large_bar_height * si) / si); + large_bar_height = z_stripf((symbol->height - fixed_height) / zero_count); + assert(large_bar_height >= 0.5f); /* Min row height as set by `z_set_height()` */ + if (!z_isfintf(large_bar_height * si)) { + large_bar_height = z_stripf(roundf(large_bar_height * si) / si); } - symbol->height = stripf(large_bar_height * zero_count + fixed_height); + symbol->height = z_stripf(large_bar_height * zero_count + fixed_height); /* Note should never happen that have both zero_count and round_rows */ } else { if (round_rows) { float total_height = 0.0f; for (i = 0; i < symbol->rows; i++) { - if (!isfintf(symbol->row_height[i] * si)) { + if (!z_isfintf(symbol->row_height[i] * si)) { symbol->row_height[i] = roundf(symbol->row_height[i] * si) / si; } total_height += symbol->row_height[i]; } - symbol->height = stripf(total_height); + symbol->height = z_stripf(total_height); } } @@ -881,9 +881,9 @@ INTERNAL float out_large_bar_height(struct zint_symbol *symbol, const int si, in } } if (zero_count) { - large_bar_height = stripf((symbol->height - fixed_height) / zero_count); - assert(large_bar_height >= 0.5f); /* Min row height as set by `set_height()` */ - symbol->height = stripf(large_bar_height * zero_count + fixed_height); + large_bar_height = z_stripf((symbol->height - fixed_height) / zero_count); + assert(large_bar_height >= 0.5f); /* Min row height as set by `z_set_height()` */ + symbol->height = z_stripf(large_bar_height * zero_count + fixed_height); } } @@ -901,7 +901,7 @@ INTERNAL float out_large_bar_height(struct zint_symbol *symbol, const int si, in } /* Do `fopen()` on Windows, assuming `filename` is UTF-8 encoded. Ticket #288, props Marcel */ -INTERNAL FILE *out_win_fopen(const char *filename, const char *mode) { +INTERNAL FILE *zint_out_win_fopen(const char *filename, const char *mode) { wchar_t *filenameW, *modeW; utf8_to_wide(filename, filenameW, NULL /*fail return*/); @@ -955,11 +955,11 @@ static int out_maybe_mkdir(const char *path) { } /* Create output file, creating sub-directories if necessary. Returns `fopen()` FILE pointer */ -INTERNAL FILE *out_fopen(const char filename[256], const char *mode) { +INTERNAL FILE *zint_out_fopen(const char filename[256], const char *mode) { FILE *outfile; #ifdef _WIN32 - if (!(outfile = out_win_fopen(filename, mode))) { + if (!(outfile = zint_out_win_fopen(filename, mode))) { #else if (!(outfile = fopen(filename, mode))) { #endif @@ -999,7 +999,7 @@ INTERNAL FILE *out_fopen(const char filename[256], const char *mode) { } } #ifdef _WIN32 - outfile = out_win_fopen(filename, mode); + outfile = zint_out_win_fopen(filename, mode); #else outfile = fopen(filename, mode); #endif diff --git a/backend/output.h b/backend/output.h index 3787e8c4..1f95e12b 100644 --- a/backend/output.h +++ b/backend/output.h @@ -40,53 +40,53 @@ extern "C" { #include /* For FILE */ /* Check colour options are good (`symbol->fgcolour`, `symbol->bgcolour`) */ -INTERNAL int out_check_colour_options(struct zint_symbol *symbol); +INTERNAL int zint_out_check_colour_options(struct zint_symbol *symbol); /* Return RGB(A) from (well-formed) colour string. Returns 0 if RGB or converted CMYK, 1 if RGBA */ -INTERNAL int out_colour_get_rgb(const char *colour, unsigned char *red, unsigned char *green, unsigned char *blue, - unsigned char *alpha); +INTERNAL int zint_out_colour_get_rgb(const char *colour, unsigned char *red, unsigned char *green, + unsigned char *blue, unsigned char *alpha); /* Return CMYK from (well-formed) colour string. Returns 0 if CMYK, 1 if converted RBG, 2 if converted RGBA */ -INTERNAL int out_colour_get_cmyk(const char *colour, int *cyan, int *magenta, int *yellow, int *black, +INTERNAL int zint_out_colour_get_cmyk(const char *colour, int *cyan, int *magenta, int *yellow, int *black, unsigned char *rgb_alpha); /* Convert internal colour chars "WCBMRYGK" to RGB */ -INTERNAL int out_colour_char_to_rgb(const unsigned char ch, unsigned char *red, unsigned char *green, +INTERNAL int zint_out_colour_char_to_rgb(const unsigned char ch, unsigned char *red, unsigned char *green, unsigned char *blue); /* Set left (x), top (y), right and bottom offsets for whitespace, also right quiet zone */ -INTERNAL void out_set_whitespace_offsets(const struct zint_symbol *symbol, const int hide_text, +INTERNAL void zint_out_set_whitespace_offsets(const struct zint_symbol *symbol, const int hide_text, const int comp_xoffset, float *p_xoffset, float *p_yoffset, float *p_roffset, float *p_boffset, float *p_qz_right, const float scaler, int *p_xoffset_si, int *p_yoffset_si, int *p_roffset_si, int *p_boffset_si, int *p_qz_right_si); /* Set composite offset and main width excluding add-on (for start of add-on calc) and add-on text, returning EAN/UPC type */ -INTERNAL int out_process_upcean(const struct zint_symbol *symbol, const int comp_xoffset, int *p_main_width, +INTERNAL int zint_out_process_upcean(const struct zint_symbol *symbol, const int comp_xoffset, int *p_main_width, unsigned char addon[6], int *p_addon_len, int *p_addon_gap); /* Calculate large bar height i.e. linear bars with zero row height that respond to the symbol height. If scaler `si` non-zero (raster), then large_bar_height if non-zero or else row heights will be rounded to nearest pixel and symbol height adjusted */ -INTERNAL float out_large_bar_height(struct zint_symbol *symbol, const int si, int *row_heights_si, +INTERNAL float zint_out_large_bar_height(struct zint_symbol *symbol, const int si, int *row_heights_si, int *symbol_height_si); /* Create output file, creating sub-directories if necessary. Returns `fopen()` FILE pointer */ -INTERNAL FILE *out_fopen(const char filename[256], const char *mode); +INTERNAL FILE *zint_out_fopen(const char filename[256], const char *mode); #ifdef _WIN32 /* Do `fopen()` on Windows, assuming `filename` is UTF-8 encoded. Props Marcel, ticket #288 */ -INTERNAL FILE *out_win_fopen(const char *filename, const char *mode); +INTERNAL FILE *zint_out_win_fopen(const char *filename, const char *mode); #endif /* Little-endian output */ -#define out_le_u16(b, n) do { \ +#define zint_out_le_u16(b, n) do { \ unsigned char *bp = (unsigned char *) &(b); \ uint16_t u16 = (uint16_t) (n); \ bp[0] = (unsigned char) (u16 & 0xFF); \ bp[1] = (unsigned char) ((u16 >> 8) & 0xFF); \ } while (0) -#define out_le_u32(b, n) do { \ +#define zint_out_le_u32(b, n) do { \ unsigned char *bp = (unsigned char *) &(b); \ uint32_t u32 = (uint32_t) (n); \ bp[0] = (unsigned char) (u32 & 0xFF); \ @@ -95,7 +95,7 @@ INTERNAL FILE *out_win_fopen(const char *filename, const char *mode); bp[3] = (unsigned char) ((u32 >> 24) & 0xFF); \ } while (0) -#define out_le_i32(b, n) do { \ +#define zint_out_le_i32(b, n) do { \ unsigned char *bp = (unsigned char *) &(b); \ int32_t i32 = (int32_t) (n); \ bp[0] = (unsigned char) (i32 & 0xFF); \ @@ -104,7 +104,7 @@ INTERNAL FILE *out_win_fopen(const char *filename, const char *mode); bp[3] = (unsigned char) ((i32 >> 24) & 0xFF); \ } while (0) -#define out_le_float(b, n) do { \ +#define zint_out_le_float(b, n) do { \ unsigned char *bp = (unsigned char *) &(b); \ float f = (float) (n); \ uint32_t *p_u32 = (uint32_t *) &f; \ diff --git a/backend/pcx.c b/backend/pcx.c index 2b7117d8..357f1633 100644 --- a/backend/pcx.c +++ b/backend/pcx.c @@ -39,7 +39,7 @@ #include "pcx.h" /* PCX header structure */ /* ZSoft PCX File Format Technical Reference Manual http://bespin.org/~qz/pc-gpe/pcx.txt */ -INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) { +INTERNAL int zint_pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) { unsigned char fgred, fggrn, fgblu, fgalpha, bgred, bggrn, bgblu, bgalpha; int row, column, i, colour; int run_count; @@ -53,18 +53,18 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix rle_row[bytes_per_line - 1] = 0; /* Will remain zero if bitmap_width odd */ - (void) out_colour_get_rgb(symbol->fgcolour, &fgred, &fggrn, &fgblu, &fgalpha); - (void) out_colour_get_rgb(symbol->bgcolour, &bgred, &bggrn, &bgblu, &bgalpha); + (void) zint_out_colour_get_rgb(symbol->fgcolour, &fgred, &fggrn, &fgblu, &fgalpha); + (void) zint_out_colour_get_rgb(symbol->bgcolour, &bgred, &bggrn, &bgblu, &bgalpha); header.manufacturer = 10; /* ZSoft */ header.version = 5; /* Version 3.0 */ header.encoding = 1; /* Run length encoding */ header.bits_per_pixel = 8; /* TODO: 1-bit monochrome black/white */ - out_le_u16(header.window_xmin, 0); - out_le_u16(header.window_ymin, 0); - out_le_u16(header.window_xmax, symbol->bitmap_width - 1); - out_le_u16(header.window_ymax, symbol->bitmap_height - 1); - out_le_u16(header.horiz_dpi, symbol->dpmm ? roundf(stripf(symbol->dpmm * 25.4f)) : 300); + zint_out_le_u16(header.window_xmin, 0); + zint_out_le_u16(header.window_ymin, 0); + zint_out_le_u16(header.window_xmax, symbol->bitmap_width - 1); + zint_out_le_u16(header.window_ymax, symbol->bitmap_height - 1); + zint_out_le_u16(header.horiz_dpi, symbol->dpmm ? roundf(z_stripf(symbol->dpmm * 25.4f)) : 300); header.vert_dpi = header.horiz_dpi; for (i = 0; i < 48; i++) { @@ -74,23 +74,23 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix header.reserved = 0; header.number_of_planes = 3 + (fgalpha != 0xFF || bgalpha != 0xFF); /* TODO: 1-bit monochrome black/white */ - out_le_u16(header.bytes_per_line, bytes_per_line); + zint_out_le_u16(header.bytes_per_line, bytes_per_line); - out_le_u16(header.palette_info, 1); /* Colour */ - out_le_u16(header.horiz_screen_size, 0); - out_le_u16(header.vert_screen_size, 0); + zint_out_le_u16(header.palette_info, 1); /* Colour */ + zint_out_le_u16(header.horiz_screen_size, 0); + zint_out_le_u16(header.vert_screen_size, 0); for (i = 0; i < 54; i++) { header.filler[i] = 0x00; } /* Open output file in binary mode */ - if (!fm_open(fmp, symbol, "wb")) { - return ZEXT errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 621, "Could not open PCX output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_open(fmp, symbol, "wb")) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 621, "Could not open PCX output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } - fm_write(&header, sizeof(pcx_header_t), 1, fmp); + zint_fm_write(&header, sizeof(pcx_header_t), 1, fmp); for (row = 0, pb = pixelbuf; row < symbol->bitmap_height; row++, pb += symbol->bitmap_width) { for (colour = 0; colour < header.number_of_planes; colour++) { @@ -101,21 +101,21 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix if (ch == '0' || ch == '1') { rle_row[column] = ch != '0' ? fgred : bgred; } else { - out_colour_char_to_rgb(ch, &rle_row[column], NULL, NULL); + zint_out_colour_char_to_rgb(ch, &rle_row[column], NULL, NULL); } break; case 1: if (ch == '0' || ch == '1') { rle_row[column] = ch != '0' ? fggrn : bggrn; } else { - out_colour_char_to_rgb(ch, NULL, &rle_row[column], NULL); + zint_out_colour_char_to_rgb(ch, NULL, &rle_row[column], NULL); } break; case 2: if (ch == '0' || ch == '1') { rle_row[column] = ch != '0' ? fgblu : bgblu; } else { - out_colour_char_to_rgb(ch, NULL, NULL, &rle_row[column]); + zint_out_colour_char_to_rgb(ch, NULL, NULL, &rle_row[column]); } break; case 3: @@ -134,9 +134,9 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } else { if (run_count > 1 || (previous & 0xc0) == 0xc0) { run_count += 0xc0; - fm_putc(run_count, fmp); + zint_fm_putc(run_count, fmp); } - fm_putc(previous, fmp); + zint_fm_putc(previous, fmp); previous = rle_row[column]; run_count = 1; } @@ -144,21 +144,21 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix if (run_count > 1 || (previous & 0xc0) == 0xc0) { run_count += 0xc0; - fm_putc(run_count, fmp); + zint_fm_putc(run_count, fmp); } - fm_putc(previous, fmp); + zint_fm_putc(previous, fmp); } } - if (fm_error(fmp)) { - ZEXT errtxtf(0, symbol, 622, "Incomplete write of PCX output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); - (void) fm_close(fmp, symbol); + if (zint_fm_error(fmp)) { + ZEXT z_errtxtf(0, symbol, 622, "Incomplete write of PCX output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); + (void) zint_fm_close(fmp, symbol); return ZINT_ERROR_FILE_WRITE; } - if (!fm_close(fmp, symbol)) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 624, "Failure on closing PCX output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_close(fmp, symbol)) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 624, "Failure on closing PCX output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } return 0; diff --git a/backend/pdf417.c b/backend/pdf417.c index 058fadbc..11512c3d 100644 --- a/backend/pdf417.c +++ b/backend/pdf417.c @@ -564,7 +564,7 @@ static void pdf_textprocess_minimal(short *chainemc, int *p_mclength, const unsi /* 671 */ /* Byte compaction */ -INTERNAL void pdf_byteprocess(short *chainemc, int *p_mclength, const unsigned char chaine[], int start, +INTERNAL void zint_pdf_byteprocess(short *chainemc, int *p_mclength, const unsigned char chaine[], int start, const int length, const int lastmode) { const int real_lastmode = PDF_REAL_MODE(lastmode); @@ -636,7 +636,7 @@ static void pdf_numbprocess(short *chainemc, int *p_mclength, const unsigned cha len = longueur + 1; chainemod[0] = 1; for (loop = 1; loop < len; loop++) { - chainemod[loop] = ctoi(chaine[start + loop + j - 1]); + chainemod[loop] = z_ctoi(chaine[start + loop + j - 1]); } do { /* 877 - gosub Modulo */ @@ -667,8 +667,8 @@ static void pdf_numbprocess(short *chainemc, int *p_mclength, const unsigned cha } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL void pdf_numbprocess_test(short *chainemc, int *p_mclength, const unsigned char chaine[], const int start, - const int length) { +INTERNAL void zint_test_pdf_numbprocess(short *chainemc, int *p_mclength, const unsigned char chaine[], + const int start, const int length) { pdf_numbprocess(chainemc, p_mclength, chaine, start, length); } #endif @@ -912,7 +912,7 @@ static void pdf_addEdges(const unsigned char source[], const int length, const i } if (z_isdigit(c)) { - const int len = cnt_digits(source, length, from, -1 /*all*/); + const int len = z_cnt_digits(source, length, from, -1 /*all*/); pdf_addEdge(source, length, edges, PDF_NUM, from, len, 0 /*t_table*/, lastmode, previous); } @@ -1041,7 +1041,7 @@ static int pdf_initial(struct zint_symbol *symbol, const unsigned char chaine[], pdf_appendix_d_encode(chaine, liste, &indexliste); } else { if (!pdf_define_mode(liste, &indexliste, chaine, length, *p_lastmode, debug_print)) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 749, "Insufficient memory for mode buffers"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 749, "Insufficient memory for mode buffers"); } } @@ -1067,7 +1067,7 @@ static int pdf_initial(struct zint_symbol *symbol, const unsigned char chaine[], if (eci != 0) { if (eci > 811799) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 472, "ECI code '%d' out of range (0 to 811799)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 472, "ECI code '%d' out of range (0 to 811799)", symbol->eci); } /* Encoding ECI assignment number, according to Table 8 */ @@ -1101,7 +1101,7 @@ static int pdf_initial(struct zint_symbol *symbol, const unsigned char chaine[], } break; case PDF_BYT: /* 670 - octet stream mode */ - pdf_byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], *p_lastmode); + zint_pdf_byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], *p_lastmode); /* Don't switch mode on single byte shift from text mode */ if (PDF_REAL_MODE(*p_lastmode) != PDF_TEX || liste[0][i] != 1) { *p_lastmode = PDF_BYT; @@ -1142,13 +1142,13 @@ static int pdf_initial_segs(struct zint_symbol *symbol, struct zint_seg segs[], int id_cnt = 0, ids[10]; if (symbol->structapp.count < 2 || symbol->structapp.count > 99999) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 740, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 740, "Structured Append count '%d' out of range (2 to 99999)", symbol->structapp.count); } if (symbol->structapp.index < 1 || symbol->structapp.index > symbol->structapp.count) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 741, - "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, 741, + "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_len; @@ -1156,19 +1156,19 @@ static int pdf_initial_segs(struct zint_symbol *symbol, struct zint_seg segs[], for (id_len = 1; id_len < 31 && symbol->structapp.id[id_len]; id_len++); if (id_len > 30) { /* 10 triplets */ - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 742, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 742, "Structured Append ID length %d too long (30 digit maximum)", id_len); } for (i = 0; i < id_len; i += 3, id_cnt++) { const int triplet_len = i + 3 < id_len ? 3 : id_len - i; - ids[id_cnt] = to_int((const unsigned char *) (symbol->structapp.id + i), triplet_len); + ids[id_cnt] = z_to_int(ZCUCP(symbol->structapp.id + i), triplet_len); if (ids[id_cnt] == -1) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 743, + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 743, "Invalid Structured Append ID (digits only)"); } if (ids[id_cnt] > 899) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 744, + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 744, "Structured Append ID triplet %1$d value '%2$03d' out of range (000 to 899)", id_cnt + 1, ids[id_cnt]); } @@ -1196,8 +1196,8 @@ static int pdf_initial_segs(struct zint_symbol *symbol, struct zint_seg segs[], /* Start in upper alpha - tracked across calls to `pdf_textprocess()` to allow for interleaving byte shifts */ curtable = T_ALPHA; - 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++) { @@ -1206,8 +1206,8 @@ static int pdf_initial_segs(struct zint_symbol *symbol, struct zint_seg segs[], assert(error_number >= ZINT_ERROR); return error_number; } - if (raw_text && rt_cpy_seg(symbol, i, &segs[i])) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg(symbol, i, &segs[i])) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg()` only fails with OOM */ } } @@ -1228,8 +1228,8 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int int error_number; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; - if ((i = segs_length(segs, seg_count)) > PDF_MAX_LEN) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 463, "Input length %d too long (maximum " PDF_MAX_LEN_S ")", i); + if ((i = z_segs_length(segs, seg_count)) > PDF_MAX_LEN) { + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 463, "Input length %d too long (maximum " PDF_MAX_LEN_S ")", i); } if ((error_number = pdf_initial_segs(symbol, segs, seg_count, 0 /*is_micro*/, chainemc, &mclength, structapp_cws, @@ -1274,7 +1274,8 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int if (longueur > 928) { /* Enforce maximum codeword limit */ - return errtxt(ZINT_ERROR_TOO_LONG, symbol, 464, "Input too long, requires too many codewords (maximum 928)"); + return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 464, + "Input too long, requires too many codewords (maximum 928)"); } cols = symbol->option_2; @@ -1291,7 +1292,7 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int /* Increase rows if multiple too big */ for (; cols >= 1 && rows < 90 && rows * cols > 928; rows++, cols = (longueur + rows - 1) / rows); if (rows * cols > 928) { - return errtxt(ZINT_ERROR_TOO_LONG, symbol, 465, + return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 465, "Input too long, requires too many codewords (maximum 928)"); } } @@ -1299,12 +1300,12 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int /* Increase rows if multiple too big */ for (; rows <= 90 && rows * cols < longueur; rows++); if (rows > 90 || rows * cols > 928) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 745, "Input too long for number of columns '%d'", cols); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 745, "Input too long for number of columns '%d'", cols); } } if (rows != symbol->option_3) { - error_number = ZEXT errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 746, - "Number of rows increased from %1$d to %2$d", symbol->option_3, rows); + error_number = ZEXT z_errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 746, + "Number of rows increased from %1$d to %2$d", symbol->option_3, rows); } } else { /* Rows automatic, cols automatic or given */ if (cols < 1) { /* Cols automatic */ @@ -1321,11 +1322,11 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int /* Increase cols if multiple too big */ for (; rows >= 3 && cols < 30 && rows * cols > 928; cols++, rows = (longueur + cols - 1) / cols); if (rows * cols > 928) { - return errtxt(ZINT_ERROR_TOO_LONG, symbol, 747, + return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 747, "Input too long, requires too many codewords (maximum 928)"); } if (symbol->option_2 && cols != symbol->option_2) { /* Note previously did not warn if cols auto-upped */ - error_number = ZEXT errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 748, + error_number = ZEXT z_errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 748, "Number of columns increased from %1$d to %2$d", symbol->option_2, cols); } } @@ -1372,9 +1373,9 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int for (i = 0; i < mclength; i++) { total = (chainemc[i] + mccorrection[ecc_cws - 1]) % 929; for (j = ecc_cws - 1; j > 0; j--) { - mccorrection[j] = (mccorrection[j - 1] + 929 - (total * pdf_coefrs[offset + j]) % 929) % 929; + mccorrection[j] = (mccorrection[j - 1] + 929 - (total * zint_pdf_coefrs[offset + j]) % 929) % 929; } - mccorrection[0] = (929 - (total * pdf_coefrs[offset]) % 929) % 929; + mccorrection[0] = (929 - (total * zint_pdf_coefrs[offset]) % 929) % 929; } /* We add these codes to the string */ @@ -1391,7 +1392,7 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump_short(symbol, chainemc, mclength); + z_debug_test_codeword_dump_short(symbol, chainemc, mclength); } #endif @@ -1427,24 +1428,24 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int offset = 1858; /* cluster(6) */ break; } - bp = bin_append_posn(0x1FEA8, 17, pattern, bp); /* Row start */ + bp = z_bin_append_posn(0x1FEA8, 17, pattern, bp); /* Row start */ for (j = 0; j <= cols; j++) { - bp = bin_append_posn(pdf_bitpattern[offset + dummy[j]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + dummy[j]], 16, pattern, bp); pattern[bp++] = '0'; } if (symbol->symbology != BARCODE_PDF417COMP) { - bp = bin_append_posn(pdf_bitpattern[offset + dummy[j]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + dummy[j]], 16, pattern, bp); pattern[bp++] = '0'; - bp = bin_append_posn(0x3FA29, 18, pattern, bp); /* Row Stop */ + bp = z_bin_append_posn(0x3FA29, 18, pattern, bp); /* Row Stop */ } else { pattern[bp++] = '1'; /* Compact PDF417 Stop pattern */ } for (loop = 0; loop < bp; loop++) { if (pattern[loop] == '1') { - set_module(symbol, i, loop); + z_set_module(symbol, i, loop); } } } @@ -1453,9 +1454,9 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int /* ISO/IEC 15438:2015 Section 5.8.2 3X minimum row height */ if (error_number) { - (void) set_height(symbol, 3.0f, 0.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 3.0f, 0.0f, 0.0f, 1 /*no_errtxt*/); } else { - error_number = set_height(symbol, 3.0f, 0.0f, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 3.0f, 0.0f, 0.0f, 0 /*no_errtxt*/); } /* 843 */ @@ -1463,33 +1464,33 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int } /* 345 */ -INTERNAL int pdf417(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_pdf417(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int codeerr, error_number; error_number = 0; if ((symbol->option_1 < -1) || (symbol->option_1 > 8)) { - errtxtf(0, symbol, 460, "Error correction level '%d' out of range (0 to 8)", symbol->option_1); + z_errtxtf(0, symbol, 460, "Error correction level '%d' out of range (0 to 8)", symbol->option_1); if (symbol->warn_level == WARN_FAIL_ALL) { return ZINT_ERROR_INVALID_OPTION; } - error_number = errtxt_adj(ZINT_WARN_INVALID_OPTION, symbol, "%1$s%2$s", ", ignoring"); + error_number = z_errtxt_adj(ZINT_WARN_INVALID_OPTION, symbol, "%1$s%2$s", ", ignoring"); symbol->option_1 = -1; } if ((symbol->option_2 < 0) || (symbol->option_2 > 30)) { - errtxtf(0, symbol, 461, "Number of columns '%d' out of range (1 to 30)", symbol->option_2); + z_errtxtf(0, symbol, 461, "Number of columns '%d' out of range (1 to 30)", symbol->option_2); if (symbol->warn_level == WARN_FAIL_ALL) { return ZINT_ERROR_INVALID_OPTION; } - error_number = errtxt_adj(ZINT_WARN_INVALID_OPTION, symbol, "%1$s%2$s", ", ignoring"); + error_number = z_errtxt_adj(ZINT_WARN_INVALID_OPTION, symbol, "%1$s%2$s", ", ignoring"); symbol->option_2 = 0; } if (symbol->option_3 && (symbol->option_3 < 3 || symbol->option_3 > 90)) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 466, "Number of rows '%d' out of range (3 to 90)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 466, "Number of rows '%d' out of range (3 to 90)", symbol->option_3); } if (symbol->option_2 && symbol->option_3 && symbol->option_2 * symbol->option_3 > 928) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 475, "Columns x rows value '%d' out of range (1 to 928)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 475, "Columns x rows value '%d' out of range (1 to 928)", symbol->option_2 * symbol->option_3); } @@ -1506,7 +1507,7 @@ INTERNAL int pdf417(struct zint_symbol *symbol, struct zint_seg segs[], const in } /* Like PDF417 only much smaller! */ -INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int i, k, j, longueur, mccorrection[50] = {0}, offset; int ecc_cwds; int total, mclength, error_number = 0; @@ -1521,12 +1522,12 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con /* From ISO/IEC 24728:2006 Table 1 — MicroPDF417 version characteristics */ static char col_max_codewords[5] = { 0, 20, 37, 82, 126 }; - if ((i = segs_length(segs, seg_count)) > MICRO_PDF_MAX_LEN) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 474, "Input length %d too long (maximum " MICRO_PDF_MAX_LEN_S ")", - i); + if ((i = z_segs_length(segs, seg_count)) > MICRO_PDF_MAX_LEN) { + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 474, + "Input length %d too long (maximum " MICRO_PDF_MAX_LEN_S ")", i); } if (symbol->option_3) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 476, "Cannot specify rows for MicroPDF417"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 476, "Cannot specify rows for MicroPDF417"); } /* Encoding starts out the same as PDF417, so use the same code */ @@ -1540,15 +1541,15 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con /* This is where it all changes! */ if (mclength + structapp_cp > 126) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 467, "Input too long, requires %d codewords (maximum 126)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 467, "Input too long, requires %d codewords (maximum 126)", mclength + structapp_cp); } if (symbol->option_2 > 4) { if (symbol->warn_level == WARN_FAIL_ALL) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 471, "Number of columns '%d' out of range (1 to 4)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 471, "Number of columns '%d' out of range (1 to 4)", symbol->option_2); } - error_number = errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 468, + error_number = z_errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 468, "Number of columns '%d' out of range (1 to 4), ignoring", symbol->option_2); symbol->option_2 = 0; } @@ -1568,11 +1569,11 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con if (symbol->option_2 >= 1 && mclength + structapp_cp > col_max_codewords[symbol->option_2]) { /* The user specified the column but the data doesn't fit - go to automatic */ if (symbol->warn_level == WARN_FAIL_ALL) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 469, + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 469, "Input too long for number of columns '%1$d', requires %2$d codewords (maximum %3$d)", symbol->option_2, mclength + structapp_cp, col_max_codewords[symbol->option_2]); } - error_number = errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 470, + error_number = z_errtxtf(ZINT_WARN_INVALID_OPTION, symbol, 470, "Input too long for number of columns '%d', ignoring", symbol->option_2); symbol->option_2 = 0; } @@ -1672,16 +1673,16 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con /* Now we have the variant we can load the data */ variant--; - symbol->option_2 = pdf_MicroVariants[variant]; /* Columns */ - symbol->rows = pdf_MicroVariants[variant + 34]; /* Rows */ - ecc_cwds = pdf_MicroVariants[variant + 68]; /* Number of EC CWs */ + symbol->option_2 = zint_pdf_MicroVariants[variant]; /* Columns */ + symbol->rows = zint_pdf_MicroVariants[variant + 34]; /* Rows */ + ecc_cwds = zint_pdf_MicroVariants[variant + 68]; /* Number of EC CWs */ longueur = (symbol->option_2 * symbol->rows) - ecc_cwds; /* Number of non-EC CWs */ i = longueur - (mclength + structapp_cp); /* Amount of padding required */ - offset = pdf_MicroVariants[variant + 102]; /* Coefficient offset */ + offset = zint_pdf_MicroVariants[variant + 102]; /* Coefficient offset */ /* Feedback options */ /* Place in top byte, leaving bottom one for maybe future use - also compatible with AZTEC */ - symbol->option_1 = ((int) stripf(roundf(stripf(ecc_cwds * 100.0f / (longueur + ecc_cwds))))) << 8; + symbol->option_1 = ((int) z_stripf(roundf(z_stripf(ecc_cwds * 100.0f / (longueur + ecc_cwds))))) << 8; if (debug_print) { fputs("\nChoose symbol size:\n", stdout); @@ -1708,9 +1709,10 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con total = (chainemc[i] + mccorrection[ecc_cwds - 1]) % 929; for (j = ecc_cwds - 1; j >= 0; j--) { if (j == 0) { - mccorrection[j] = (929 - (total * pdf_Microcoeffs[offset + j]) % 929) % 929; + mccorrection[j] = (929 - (total * zint_pdf_Microcoeffs[offset + j]) % 929) % 929; } else { - mccorrection[j] = (mccorrection[j - 1] + 929 - (total * pdf_Microcoeffs[offset + j]) % 929) % 929; + mccorrection[j] = (mccorrection[j - 1] + 929 - (total * zint_pdf_Microcoeffs[offset + j]) % 929) + % 929; } } } @@ -1734,15 +1736,15 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump_short(symbol, chainemc, mclength); + z_debug_test_codeword_dump_short(symbol, chainemc, mclength); } #endif /* Now get the RAP (Row Address Pattern) start values */ - LeftRAP = pdf_RAPTable[variant]; - CentreRAP = pdf_RAPTable[variant + 34]; - RightRAP = pdf_RAPTable[variant + 68]; - Cluster = pdf_RAPTable[variant + 102] / 3; + LeftRAP = zint_pdf_RAPTable[variant]; + CentreRAP = zint_pdf_RAPTable[variant + 34]; + RightRAP = zint_pdf_RAPTable[variant + 68]; + Cluster = zint_pdf_RAPTable[variant + 102] / 3; /* That's all values loaded, get on with the encoding */ @@ -1757,35 +1759,35 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con k = i * symbol->option_2; /* Copy the data into codebarre */ - bp = bin_append_posn(pdf_rap_side[LeftRAP - 1], 10, pattern, bp); - bp = bin_append_posn(pdf_bitpattern[offset + chainemc[k]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_side[LeftRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k]], 16, pattern, bp); pattern[bp++] = '0'; if (symbol->option_2 >= 2) { if (symbol->option_2 == 3) { - bp = bin_append_posn(pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); } - bp = bin_append_posn(pdf_bitpattern[offset + chainemc[k + 1]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 1]], 16, pattern, bp); pattern[bp++] = '0'; if (symbol->option_2 >= 3) { if (symbol->option_2 == 4) { - bp = bin_append_posn(pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_centre[CentreRAP - 1], 10, pattern, bp); } - bp = bin_append_posn(pdf_bitpattern[offset + chainemc[k + 2]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 2]], 16, pattern, bp); pattern[bp++] = '0'; if (symbol->option_2 == 4) { - bp = bin_append_posn(pdf_bitpattern[offset + chainemc[k + 3]], 16, pattern, bp); + bp = z_bin_append_posn(zint_pdf_bitpattern[offset + chainemc[k + 3]], 16, pattern, bp); pattern[bp++] = '0'; } } } - bp = bin_append_posn(pdf_rap_side[RightRAP - 1], 10, pattern, bp); + bp = z_bin_append_posn(zint_pdf_rap_side[RightRAP - 1], 10, pattern, bp); pattern[bp++] = '1'; /* Stop */ if (debug_print) printf("%.*s\n", bp, pattern); /* So now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ for (loop = 0; loop < bp; loop++) { if (pattern[loop] == '1') { - set_module(symbol, i, loop); + z_set_module(symbol, i, loop); } } @@ -1812,9 +1814,9 @@ INTERNAL int micropdf417(struct zint_symbol *symbol, struct zint_seg segs[], con /* ISO/IEC 24728:2006 Section 5.8.2 2X minimum row height */ if (error_number) { - (void) set_height(symbol, 2.0f, 0.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 2.0f, 0.0f, 0.0f, 1 /*no_errtxt*/); } else { - error_number = set_height(symbol, 2.0f, 0.0f, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 2.0f, 0.0f, 0.0f, 0 /*no_errtxt*/); } return error_number; diff --git a/backend/pdf417.h b/backend/pdf417.h index 748ac7a2..adc72589 100644 --- a/backend/pdf417.h +++ b/backend/pdf417.h @@ -1,7 +1,7 @@ /* pdf417.h - PDF417 tables and coefficients declarations */ /* libzint - the open source barcode library - Copyright (C) 2008-2024 Robin Stuart + Copyright (C) 2008-2025 Robin Stuart Portions Copyright (C) 2004 Grandzebu Redistribution and use in source and binary forms, with or without @@ -41,26 +41,26 @@ extern "C" { #endif /* __cplusplus */ /* PDF417 error correction coefficients from Grand Zebu */ -INTERNAL_DATA_EXTERN const unsigned short pdf_coefrs[1022]; +INTERNAL_DATA_EXTERN const unsigned short zint_pdf_coefrs[1022]; -INTERNAL_DATA_EXTERN const unsigned short pdf_bitpattern[2787]; +INTERNAL_DATA_EXTERN const unsigned short zint_pdf_bitpattern[2787]; /* MicroPDF417 coefficients from ISO/IEC 24728:2006 Annex F */ -INTERNAL_DATA_EXTERN const unsigned short pdf_Microcoeffs[344]; +INTERNAL_DATA_EXTERN const unsigned short zint_pdf_Microcoeffs[344]; /* rows, columns, error codewords, k-offset of valid MicroPDF417 sizes from ISO/IEC 24728:2006 */ -INTERNAL_DATA_EXTERN const unsigned short pdf_MicroVariants[136]; +INTERNAL_DATA_EXTERN const unsigned short zint_pdf_MicroVariants[136]; /* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 tables 10, 11 and 12 */ -INTERNAL_DATA_EXTERN const char pdf_RAPTable[136]; +INTERNAL_DATA_EXTERN const char zint_pdf_RAPTable[136]; /* Left and Right Row Address Pattern from Table 2 */ -INTERNAL_DATA_EXTERN const unsigned short pdf_rap_side[52]; +INTERNAL_DATA_EXTERN const unsigned short zint_pdf_rap_side[52]; /* Centre Row Address Pattern from Table 2 */ -INTERNAL_DATA_EXTERN const unsigned short pdf_rap_centre[52]; +INTERNAL_DATA_EXTERN const unsigned short zint_pdf_rap_centre[52]; -INTERNAL void pdf_byteprocess(short *chainemc, int *p_mclength, const unsigned char chaine[], int start, +INTERNAL void zint_pdf_byteprocess(short *chainemc, int *p_mclength, const unsigned char chaine[], int start, const int length, const int lastmode); #ifdef __cplusplus diff --git a/backend/pdf417_tabs.h b/backend/pdf417_tabs.h index 5a049e48..8c6fd447 100644 --- a/backend/pdf417_tabs.h +++ b/backend/pdf417_tabs.h @@ -1,7 +1,7 @@ /* pdf417_tabs.h - PDF417 tables and coefficients */ /* libzint - the open source barcode library - Copyright (C) 2008-2024 Robin Stuart + Copyright (C) 2008-2025 Robin Stuart Portions Copyright (C) 2004 Grandzebu Redistribution and use in source and binary forms, with or without @@ -44,7 +44,7 @@ extern "C" { #endif /* __cplusplus */ /* PDF417 error correction coefficients from Grand Zebu */ -INTERNAL_DATA const unsigned short pdf_coefrs[1022] = { +INTERNAL_DATA const unsigned short zint_pdf_coefrs[1022] = { /* k = 2 */ 27, 917, @@ -130,7 +130,7 @@ INTERNAL_DATA const unsigned short pdf_coefrs[1022] = { 63, 310, 863, 251, 366, 304, 282, 738, 675, 410, 389, 244, 31, 121, 303, 263 }; -INTERNAL_DATA const unsigned short pdf_bitpattern[2787] = { +INTERNAL_DATA const unsigned short zint_pdf_bitpattern[2787] = { 0xEAE0, 0xF578, 0xFABE, 0xEA70, 0xF53C, 0xFA9F, 0xD460, 0xEA38, 0xD430, 0xA820, 0xD418, 0xA810, 0xD6E0, 0xEB78, 0xF5BE, 0xD670, 0xEB3C, 0xF59F, 0xAC60, 0xD638, 0xAC30, 0xAEE0, 0xD778, 0xEBBE, 0xAE70, 0xD73C, 0xEB9F, 0xAE38, 0xD71E, 0xAF78, @@ -413,7 +413,7 @@ INTERNAL_DATA const unsigned short pdf_bitpattern[2787] = { }; /* MicroPDF417 coefficients from ISO/IEC 24728:2006 Annex F */ -INTERNAL_DATA const unsigned short pdf_Microcoeffs[344] = { +INTERNAL_DATA const unsigned short zint_pdf_Microcoeffs[344] = { /* k = 7 */ 76, 925, 537, 597, 784, 691, 437, @@ -478,7 +478,7 @@ INTERNAL_DATA const unsigned short pdf_Microcoeffs[344] = { }; /* rows, columns, error codewords, k-offset of valid MicroPDF417 sizes from ISO/IEC 24728:2006 */ -INTERNAL_DATA const unsigned short pdf_MicroVariants[136] = { /*34*4*/ +INTERNAL_DATA const unsigned short zint_pdf_MicroVariants[136] = { /*34*4*/ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 11, 14, 17, 20, 24, 28, 8, 11, 14, 17, 20, 23, 26, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 4, 6, 8, 10, 12, 15, 20, 26, 32, 38, 44, 7, 7, 7, 8, 8, 8, 8, 9, 9, 10, 11, 13, 15, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, 8, 12, 14, 16, 18, 21, 26, 32, 38, 44, 50, @@ -487,7 +487,7 @@ INTERNAL_DATA const unsigned short pdf_MicroVariants[136] = { /*34*4*/ /* rows, columns, error codewords, k-offset */ /* following is Left RAP, Centre RAP, Right RAP and Start Cluster from ISO/IEC 24728:2006 tables 10, 11 and 12 */ -INTERNAL_DATA const char pdf_RAPTable[136] = { /*34*4*/ +INTERNAL_DATA const char zint_pdf_RAPTable[136] = { /*34*4*/ 1, 8, 36, 19, 9, 25, 1, 1, 8, 36, 19, 9, 27, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 47, 1, 7, 15, 25, 37, 1, 1, 21, 15, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 19, 1, 7, 15, 25, 37, 17, 9, 29, 31, 25, 9, 8, 36, 19, 17, 33, 1, 9, 8, 36, 19, 17, 35, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, 43, 1, 7, 15, 25, 37, 33, 17, 37, 47, 49, @@ -495,7 +495,7 @@ INTERNAL_DATA const char pdf_RAPTable[136] = { /*34*4*/ }; /* Left and Right Row Address Pattern from Table 2 */ -INTERNAL_DATA const unsigned short pdf_rap_side[52] = { +INTERNAL_DATA const unsigned short zint_pdf_rap_side[52] = { 0x322, 0x3A2, 0x3B2, 0x332, 0x372, 0x37A, 0x33A, 0x3BA, 0x39A, 0x3DA, 0x3CA, 0x38A, 0x30A, 0x31A, 0x312, 0x392, 0x3D2, 0x3D6, 0x3D4, 0x394, 0x3B4, 0x3A4, 0x3A6, 0x3AE, 0x3AC, 0x3A8, 0x328, 0x32C, 0x32E, 0x326, @@ -505,7 +505,7 @@ INTERNAL_DATA const unsigned short pdf_rap_side[52] = { }; /* Centre Row Address Pattern from Table 2 */ -INTERNAL_DATA const unsigned short pdf_rap_centre[52] = { +INTERNAL_DATA const unsigned short zint_pdf_rap_centre[52] = { 0x2CE, 0x24E, 0x26E, 0x22E, 0x226, 0x236, 0x216, 0x212, 0x21A, 0x23A, 0x232, 0x222, 0x262, 0x272, 0x27A, 0x2FA, 0x2F2, 0x2F6, 0x276, 0x274, 0x264, 0x266, 0x246, 0x242, 0x2C2, 0x2E2, 0x2E6, 0x2E4, 0x2EC, 0x26C, diff --git a/backend/plessey.c b/backend/plessey.c index d3660333..69f3755c 100644 --- a/backend/plessey.c +++ b/backend/plessey.c @@ -52,7 +52,7 @@ static const char MSITable[10][8] = { }; /* Not MSI/Plessey but the older Plessey standard */ -INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_plessey(struct zint_symbol *symbol, unsigned char source[], int length) { int i; unsigned char checkptr[67 * 4 + 8] = {0}; @@ -65,10 +65,10 @@ INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int len const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 67) { /* 16 + 67 * 16 + 4 * 8 + 19 = 1139 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 370, "Input length %d too long (maximum 67)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 370, "Input length %d too long (maximum 67)", length); } - if ((i = not_sane(SSET_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 371, + if ((i = z_not_sane(SSET_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 371, "Invalid character at position %d in input (digits and \"ABCDEF\" only)", i); } @@ -115,21 +115,21 @@ INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int len memcpy(d, "331311313", 9); d += 9; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); /* TODO: Find documentation on BARCODE_PLESSEY dimensions/height */ - c1 = (char) xtoc(check_digits & 0xF); - c2 = (char) xtoc(check_digits >> 4); + c1 = (char) z_xtoc(check_digits & 0xF); + c2 = (char) z_xtoc(check_digits >> 4); - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); if (symbol->option_2 == 1) { - hrt_cat_chr_nochk(symbol, c1); - hrt_cat_chr_nochk(symbol, c2); + z_hrt_cat_chr_nochk(symbol, c1); + z_hrt_cat_chr_nochk(symbol, c2); } - if (raw_text && rt_printf_256(symbol, "%.*s%c%c", length, source, c1, c2)) { - return ZINT_ERROR_MEMORY; /* `rt_printf_256()` only fails with OOM */ + if (raw_text && z_rt_printf_256(symbol, "%.*s%c%c", length, source, c1, c2)) { + return ZINT_ERROR_MEMORY; /* `z_rt_printf_256()` only fails with OOM */ } return error_number; @@ -146,11 +146,11 @@ static char msi_check_digit_mod10(const unsigned char source[], const int length for (i = length - 1; i >= 0; i--) { /* Note overflow impossible for max length 92 * max weight 9 * max val 15 == 12420 */ - x += vals[undoubled][ctoi(source[i])]; + x += vals[undoubled][z_ctoi(source[i])]; undoubled = !undoubled; } - return itoc((10 - x % 10) % 10); + return z_itoc((10 - x % 10) % 10); } /* Modulo 11 check digit - IBM weight system wrap = 7, NCR system wrap = 9 @@ -160,14 +160,14 @@ static char msi_check_digit_mod11(const unsigned char source[], const int length for (i = length - 1; i >= 0; i--) { /* Note overflow impossible for max length 92 * max weight 9 * max val 15 == 12420 */ - x += weight * ctoi(source[i]); + x += weight * z_ctoi(source[i]); weight++; if (weight > wrap) { weight = 2; } } - return itoc((11 - x % 11) % 11); /* Will return ':' for 10 */ + return z_itoc((11 - x % 11) % 11); /* Will return ':' for 10 */ } /* Plain MSI Plessey - does not calculate any check character */ @@ -180,10 +180,10 @@ static char *msi_plessey_nomod(struct zint_symbol *symbol, const unsigned char s memcpy(d, MSITable[source[i] - '0'], 8); } - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); - if (raw_text && rt_cpy(symbol, source, length)) { - return NULL; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return NULL; /* `z_rt_cpy()` only fails with OOM */ } return d; @@ -207,13 +207,13 @@ static char *msi_plessey_mod10(struct zint_symbol *symbol, const unsigned char s memcpy(d, MSITable[check_digit - '0'], 8); d += 8; - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); if (!no_checktext) { - hrt_cat_chr_nochk(symbol, check_digit); + z_hrt_cat_chr_nochk(symbol, check_digit); } - if (raw_text && rt_cpy_cat(symbol, source, length, check_digit, NULL /*cat*/, 0)) { - return NULL; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, source, length, check_digit, NULL /*cat*/, 0)) { + return NULL; /* `z_rt_cpy_cat()` only fails with OOM */ } return d; @@ -236,13 +236,13 @@ static char *msi_plessey_mod1010(struct zint_symbol *symbol, const unsigned char } if (no_checktext) { - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); } else { - hrt_cpy_nochk(symbol, local_source, length + 2); + z_hrt_cpy_nochk(symbol, local_source, length + 2); } - if (raw_text && rt_cpy(symbol, local_source, length + 2)) { - return NULL; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, local_source, length + 2)) { + return NULL; /* `z_rt_cpy()` only fails with OOM */ } return d; } @@ -271,12 +271,13 @@ static char *msi_plessey_mod11(struct zint_symbol *symbol, const unsigned char s memcpy(d, MSITable[check_digits[i] - '0'], 8); } - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); if (!no_checktext) { - hrt_cat_nochk(symbol, check_digits, check_digits_len); + z_hrt_cat_nochk(symbol, check_digits, check_digits_len); } - if (raw_text && rt_cpy_cat(symbol, source, length, '\xFF' /*separator (none)*/, check_digits, check_digits_len)) { + if (raw_text && z_rt_cpy_cat(symbol, source, length, '\xFF' /*separator (none)*/, check_digits, + check_digits_len)) { return NULL; /* `check_digits_len()` only fails with OOM */ } return d; @@ -312,19 +313,19 @@ static char *msi_plessey_mod1110(struct zint_symbol *symbol, const unsigned char } if (no_checktext) { - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); } else { - hrt_cpy_nochk(symbol, local_source, local_length); + z_hrt_cpy_nochk(symbol, local_source, local_length); } - if (raw_text && rt_cpy(symbol, local_source, local_length)) { - return NULL; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, local_source, local_length)) { + return NULL; /* `z_rt_cpy()` only fails with OOM */ } return d; } -INTERNAL int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number = 0; int i; char dest[766]; /* 2 + 92 * 8 + 3 * 8 + 3 + 1 = 766 */ @@ -334,10 +335,10 @@ INTERNAL int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 92) { /* 3 (Start) + 92 * 12 + 3 * 12 + 4 (Stop) = 1147 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 372, "Input length %d too long (maximum 92)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 372, "Input length %d too long (maximum 92)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 377, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 377, "Invalid character at position %d in input (digits only)", i); } @@ -364,14 +365,14 @@ INTERNAL int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int } if (!d) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` etc. only fail with OOM */ + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` etc. only fail with OOM */ } /* Stop character */ memcpy(d, "121", 3); d += 3; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); /* TODO: Find documentation on BARCODE_MSI_PLESSEY dimensions/height */ diff --git a/backend/png.c b/backend/png.c index 8a420840..7282162b 100644 --- a/backend/png.c +++ b/backend/png.c @@ -42,7 +42,7 @@ #include "filemem.h" #include "output.h" -/* Note using "wpng_" prefix not "png_" (except for `png_pixel_plot()`) to avoid clashing with libpng */ +/* Note using "wpng_" prefix not "png_" to avoid clashing with libpng */ /* Note if change this need to change "backend/tests/test_png.c" definition also */ struct wpng_error_type { @@ -61,12 +61,12 @@ static void wpng_error_handler(png_structp png_ptr, png_const_charp msg) { fflush(stderr); return; /* libpng will call abort() */ } - errtxtf(0, wpng_error_ptr->symbol, 635, "libpng error: %s", msg ? msg : ""); + z_errtxtf(0, wpng_error_ptr->symbol, 635, "libpng error: %s", msg ? msg : ""); longjmp(wpng_error_ptr->jmpbuf, 1); } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL void wpng_error_handler_test(png_structp png_ptr, png_const_charp msg) { +INTERNAL void zint_test_wpng_error_handler(png_structp png_ptr, png_const_charp msg) { wpng_error_handler(png_ptr, msg); } #endif @@ -74,13 +74,13 @@ INTERNAL void wpng_error_handler_test(png_structp png_ptr, png_const_charp msg) /* libpng write callback */ static void wpng_write(png_structp png_ptr, png_bytep ptr, size_t size) { struct filemem *fmp = (struct filemem *) png_get_io_ptr(png_ptr); - (void) fm_write(ptr, 1, size, fmp); + (void) zint_fm_write(ptr, 1, size, fmp); } /* libpng flush callback */ static void wpng_flush(png_structp png_ptr) { struct filemem *fmp = (struct filemem *) png_get_io_ptr(png_ptr); - (void) fm_flush(fmp); + (void) zint_fm_flush(fmp); } /* Guestimate best compression strategy */ @@ -103,7 +103,7 @@ static int wpng_guess_compression_strategy(struct zint_symbol *symbol, const uns return Z_FILTERED; } -INTERNAL int png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) { +INTERNAL int zint_png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) { struct wpng_error_type wpng_error; struct filemem fm; struct filemem *const fmp = &fm; @@ -125,15 +125,15 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix wpng_error.symbol = symbol; - (void) out_colour_get_rgb(symbol->fgcolour, &fg.red, &fg.green, &fg.blue, &fg_alpha); - (void) out_colour_get_rgb(symbol->bgcolour, &bg.red, &bg.green, &bg.blue, &bg_alpha); + (void) zint_out_colour_get_rgb(symbol->fgcolour, &fg.red, &fg.green, &fg.blue, &fg_alpha); + (void) zint_out_colour_get_rgb(symbol->bgcolour, &bg.red, &bg.green, &bg.blue, &bg_alpha); num_trans = 0; if (symbol->symbology == BARCODE_ULTRA) { static const unsigned char ultra_chars[8] = { 'W', 'C', 'B', 'M', 'R', 'Y', 'G', 'K' }; for (i = 0; i < 8; i++) { map[ultra_chars[i]] = i; - out_colour_char_to_rgb(ultra_chars[i], &palette[i].red, &palette[i].green, &palette[i].blue); + zint_out_colour_char_to_rgb(ultra_chars[i], &palette[i].red, &palette[i].green, &palette[i].blue); if (fg_alpha != 0xff) { trans_alpha[i] = fg_alpha; } @@ -211,29 +211,29 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } /* Open output file in binary mode */ - if (!fm_open(fmp, symbol, "wb")) { - return ZEXT errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 632, "Could not open PNG output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_open(fmp, symbol, "wb")) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 632, "Could not open PNG output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } /* Set up error handling routine as proc() above */ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, &wpng_error, wpng_error_handler, NULL); if (!png_ptr) { - (void) fm_close(fmp, symbol); - return errtxt(ZINT_ERROR_MEMORY, symbol, 633, "Insufficient memory for PNG write structure buffer"); + (void) zint_fm_close(fmp, symbol); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 633, "Insufficient memory for PNG write structure buffer"); } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, NULL); - (void) fm_close(fmp, symbol); - return errtxt(ZINT_ERROR_MEMORY, symbol, 634, "Insufficient memory for PNG info structure buffer"); + (void) zint_fm_close(fmp, symbol); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 634, "Insufficient memory for PNG info structure buffer"); } /* catch jumping here */ if (setjmp(wpng_error.jmpbuf)) { png_destroy_write_struct(&png_ptr, &info_ptr); - (void) fm_close(fmp, symbol); + (void) zint_fm_close(fmp, symbol); return ZINT_ERROR_MEMORY; } @@ -250,7 +250,7 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } if (symbol->dpmm) { - int resolution = (int) roundf(stripf(symbol->dpmm * 1000.0f)); /* pixels per metre */ + int resolution = (int) roundf(z_stripf(symbol->dpmm * 1000.0f)); /* pixels per metre */ png_set_pHYs(png_ptr, info_ptr, resolution, resolution, PNG_RESOLUTION_METER); } @@ -311,15 +311,15 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix /* make sure we have disengaged */ png_destroy_write_struct(&png_ptr, &info_ptr); - if (fm_error(fmp)) { - ZEXT errtxtf(0, symbol, 638, "Incomplete write of PNG output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); - (void) fm_close(fmp, symbol); + if (zint_fm_error(fmp)) { + ZEXT z_errtxtf(0, symbol, 638, "Incomplete write of PNG output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); + (void) zint_fm_close(fmp, symbol); return ZINT_ERROR_FILE_WRITE; } - if (!fm_close(fmp, symbol)) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 960, "Failure on closing PNG output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_close(fmp, symbol)) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 960, "Failure on closing PNG output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } return 0; diff --git a/backend/postal.c b/backend/postal.c index cc40ede4..238608de 100644 --- a/backend/postal.c +++ b/backend/postal.c @@ -111,21 +111,21 @@ static int usps_set_height(struct zint_symbol *symbol, const int no_errtxt) { if (symbol->height) { /* Half ratio */ const float h_ratio = symbol->row_height[1] / (symbol->row_height[0] + symbol->row_height[1]); /* 0.4 */ - symbol->row_height[1] = stripf(symbol->height * h_ratio); + symbol->row_height[1] = z_stripf(symbol->height * h_ratio); if (symbol->row_height[1] < 0.5f) { /* Absolute minimum */ symbol->row_height[1] = 0.5f; - symbol->row_height[0] = stripf(0.5f / h_ratio - 0.5f); /* 0.75 */ + symbol->row_height[0] = z_stripf(0.5f / h_ratio - 0.5f); /* 0.75 */ } else { - symbol->row_height[0] = stripf(symbol->height - symbol->row_height[1]); + symbol->row_height[0] = z_stripf(symbol->height - symbol->row_height[1]); } } - symbol->height = stripf(symbol->row_height[0] + symbol->row_height[1]); + symbol->height = z_stripf(symbol->row_height[0] + symbol->row_height[1]); if (symbol->output_options & COMPLIANT_HEIGHT) { if (symbol->height < 4.6f || symbol->height > 9.0f) { error_number = ZINT_WARN_NONCOMPLIANT; if (!no_errtxt) { - errtxt(0, symbol, 498, "Height not compliant with standards"); + z_errtxt(0, symbol, 498, "Height not compliant with standards"); } } } @@ -144,22 +144,22 @@ static int postnet_enc(struct zint_symbol *symbol, const unsigned char source[], const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 38) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 480, "Input length %d too long (maximum 38)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 480, "Input length %d too long (maximum 38)", length); } if (symbol->symbology == BARCODE_CEPNET) { if (length != 8) { - error_number = errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 780, "Input length %d wrong (should be 8 digits)", - length); + error_number = z_errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 780, + "Input length %d wrong (should be 8 digits)", length); } } else { if (length != 5 && length != 9 && length != 11) { - error_number = errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 479, + error_number = z_errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 479, "Input length %d is not standard (should be 5, 9 or 11 digits)", length); } } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 481, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 481, "Invalid character at position %d in input (digits only)", i); } sum = 0; @@ -182,15 +182,15 @@ static int postnet_enc(struct zint_symbol *symbol, const unsigned char source[], /* Stop character */ memcpy(d, "L", 2); /* Include terminating NUL */ - if (raw_text && rt_cpy_cat(symbol, source, length, itoc(check_digit), NULL /*cat*/, 0)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, source, length, z_itoc(check_digit), NULL /*cat*/, 0)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; } /* Puts POSTNET barcodes into the pattern matrix */ -INTERNAL int postnet(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_postnet(struct zint_symbol *symbol, unsigned char source[], int length) { /* Suppress clang-tidy-20 garbage value false positive by initializing (see "vector.c" `vection_add_rect()`) */ char height_pattern[256] = {0}; /* 5 + 38 * 5 + 5 + 5 + 1 = 206 */ unsigned int loopey, h; @@ -206,9 +206,9 @@ INTERNAL int postnet(struct zint_symbol *symbol, unsigned char source[], int len h = (int) strlen(height_pattern); for (loopey = 0; loopey < h; loopey++) { if (height_pattern[loopey] == 'L') { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); writer += 2; } warn_number = usps_set_height(symbol, error_number /*no_errtxt*/); @@ -225,14 +225,14 @@ static int planet_enc(struct zint_symbol *symbol, const unsigned char source[], const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 38) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 482, "Input length %d too long (maximum 38)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 482, "Input length %d too long (maximum 38)", length); } if (length != 11 && length != 13) { - error_number = errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 478, + error_number = z_errtxtf(ZINT_WARN_NONCOMPLIANT, symbol, 478, "Input length %d is not standard (should be 11 or 13 digits)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 483, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 483, "Invalid character at position %d in input (digits only)", i); } sum = 0; @@ -255,15 +255,15 @@ static int planet_enc(struct zint_symbol *symbol, const unsigned char source[], /* Stop character */ memcpy(d, "L", 2); /* Include terminating NUL */ - if (raw_text && rt_cpy_cat(symbol, source, length, itoc(check_digit), NULL /*cat*/, 0)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, source, length, z_itoc(check_digit), NULL /*cat*/, 0)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; } /* Puts PLANET barcodes into the pattern matrix */ -INTERNAL int planet(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_planet(struct zint_symbol *symbol, unsigned char source[], int length) { /* Suppress clang-tidy-20 garbage value false positive by initializing (see "vector.c" `vection_add_rect()`) */ char height_pattern[256] = {0}; /* 5 + 38 * 5 + 5 + 5 + 1 = 206 */ unsigned int loopey, h; @@ -279,9 +279,9 @@ INTERNAL int planet(struct zint_symbol *symbol, unsigned char source[], int leng h = (int) strlen(height_pattern); for (loopey = 0; loopey < h; loopey++) { if (height_pattern[loopey] == 'L') { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); writer += 2; } warn_number = usps_set_height(symbol, error_number /*no_errtxt*/); @@ -292,7 +292,7 @@ INTERNAL int planet(struct zint_symbol *symbol, unsigned char source[], int leng } /* Korean Postal Authority */ -INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_koreapost(struct zint_symbol *symbol, unsigned char source[], int length) { int total, i, check, zeroes, error_number = 0; unsigned char local_source[8]; char dest[80]; @@ -301,10 +301,10 @@ INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int l const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 6) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 484, "Input length %d too long (maximum 6)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 484, "Input length %d too long (maximum 6)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 485, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 485, "Invalid character at position %d in input (digits only)", i); } zeroes = 6 - length; @@ -313,14 +313,14 @@ INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int l total = 0; for (i = 0; i < 6; i++) { - posns[i] = ctoi(local_source[i]); + posns[i] = z_ctoi(local_source[i]); total += posns[i]; } check = 10 - (total % 10); if (check == 10) { check = 0; } - local_source[6] = itoc(check); + local_source[6] = z_itoc(check); for (i = 5; i >= 0; i--) { const char *const entry = KoreaTable[posns[i]]; @@ -330,14 +330,14 @@ INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int l memcpy(d, KoreaTable[check], 10); d += KoreaTable[check][8] ? 10 : 8; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); /* TODO: Find documentation on BARCODE_KOREAPOST dimensions/height */ - hrt_cpy_nochk(symbol, local_source, 7); + z_hrt_cpy_nochk(symbol, local_source, 7); - if (raw_text && rt_cpy(symbol, local_source, 7)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, local_source, 7)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; @@ -345,34 +345,34 @@ INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int l /* The simplest barcode symbology ever! Supported by MS Word, so here it is! glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */ -INTERNAL int fim(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_fim(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number = 0; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 1) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 486, "Input length %d too long (maximum 1)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 486, "Input length %d too long (maximum 1)", length); } - to_upper(source, length); + z_to_upper(source, length); switch ((char) source[0]) { case 'A': - expand(symbol, "111515111", 9); + z_expand(symbol, "111515111", 9); break; case 'B': - expand(symbol, "13111311131", 11); + z_expand(symbol, "13111311131", 11); break; case 'C': - expand(symbol, "11131313111", 11); + z_expand(symbol, "11131313111", 11); break; case 'D': - expand(symbol, "1111131311111", 13); + z_expand(symbol, "1111131311111", 13); break; case 'E': - expand(symbol, "1317131", 7); + z_expand(symbol, "1317131", 7); break; default: - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 487, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 487, "Invalid character in input (\"A\", \"B\", \"C\", \"D\" or \"E\" only)"); break; } @@ -383,13 +383,13 @@ INTERNAL int fim(struct zint_symbol *symbol, unsigned char source[], int length) const float min_height = 12.7388535f; /* 0.5 / 0.03925 */ const float default_height = 20.0f; /* 0.625 / 0.03125 */ const float max_height = 31.0559006f; /* 0.75 / 0.02415 */ - error_number = set_height(symbol, min_height, default_height, max_height, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, min_height, default_height, max_height, 0 /*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*/); } - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; @@ -397,31 +397,31 @@ INTERNAL int fim(struct zint_symbol *symbol, unsigned char source[], int length) /* Set height for DAFT-type codes, maintaining ratio. Expects row_height[0] & row_height[1] to be set */ /* Used by auspost.c also */ -INTERNAL int daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height) { +INTERNAL int zint_daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height) { int error_number = 0; if (symbol->height) { /* Tracker ratio */ - const float t_ratio = stripf(symbol->row_height[1] / stripf(symbol->row_height[0] * 2 + const float t_ratio = z_stripf(symbol->row_height[1] / z_stripf(symbol->row_height[0] * 2 + symbol->row_height[1])); - symbol->row_height[1] = stripf(symbol->height * t_ratio); + symbol->row_height[1] = z_stripf(symbol->height * t_ratio); if (symbol->row_height[1] < 0.5f) { /* Absolute minimum */ symbol->row_height[1] = 0.5f; - symbol->row_height[0] = stripf(0.25f / t_ratio - 0.25f); + symbol->row_height[0] = z_stripf(0.25f / t_ratio - 0.25f); } else { - symbol->row_height[0] = stripf(stripf(symbol->height - symbol->row_height[1]) / 2.0f); + symbol->row_height[0] = z_stripf(z_stripf(symbol->height - symbol->row_height[1]) / 2.0f); } if (symbol->row_height[0] < 0.5f) { symbol->row_height[0] = 0.5f; - symbol->row_height[1] = stripf(t_ratio / (1.0f - t_ratio)); + symbol->row_height[1] = z_stripf(t_ratio / (1.0f - t_ratio)); } } symbol->row_height[2] = symbol->row_height[0]; - symbol->height = stripf(stripf(symbol->row_height[0] + symbol->row_height[1]) + symbol->row_height[2]); + symbol->height = z_stripf(z_stripf(symbol->row_height[0] + symbol->row_height[1]) + symbol->row_height[2]); if (symbol->output_options & COMPLIANT_HEIGHT) { if ((min_height && symbol->height < min_height) || (max_height && symbol->height > max_height)) { - error_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 499, "Height not compliant with standards"); + error_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 499, "Height not compliant with standards"); } } @@ -468,7 +468,7 @@ static int rm4scc_enc(struct zint_symbol *symbol, const int *posns, char *d, con } /* Puts RM4SCC into the data matrix */ -INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_rm4scc(struct zint_symbol *symbol, unsigned char source[], int length) { int i; char height_pattern[210]; int posns[50]; @@ -479,11 +479,11 @@ INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int leng const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 50) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 488, "Input length %d too long (maximum 50)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 488, "Input length %d too long (maximum 50)", length); } - to_upper(source, length); - if ((i = not_sane_lookup(KRSET, 36, source, length, posns))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 489, + z_to_upper(source, length); + if ((i = z_not_sane_lookup(KRSET, 36, source, length, posns))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 489, "Invalid character at position %d in input (alphanumerics only)", i); } @@ -493,11 +493,11 @@ INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int leng h = (int) strlen(height_pattern); for (loopey = 0; loopey < h; loopey++) { if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) { - set_module(symbol, 2, writer); + z_set_module(symbol, 2, writer); } writer += 2; } @@ -514,17 +514,17 @@ INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int leng symbol->row_height[0] = 3.16417313f; /* (1.9 * 42.3) / 25.4 */ symbol->row_height[1] = 2.16496062f; /* (1.3 * 42.3) / 25.4 */ /* Note using max X for minimum and min X for maximum */ - error_number = daft_set_height(symbol, min_height, max_height); + error_number = zint_daft_set_height(symbol, min_height, max_height); } else { symbol->row_height[0] = 3.0f; symbol->row_height[1] = 2.0f; - (void) daft_set_height(symbol, 0.0f, 0.0f); + (void) zint_daft_set_height(symbol, 0.0f, 0.0f); } symbol->rows = 3; symbol->width = writer - 1; - if (raw_text && rt_cpy_cat(symbol, source, length, check_digit, NULL /*cat*/, 0)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, source, length, check_digit, NULL /*cat*/, 0)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; @@ -533,7 +533,7 @@ INTERNAL int rm4scc(struct zint_symbol *symbol, unsigned char source[], int leng /* Handles Dutch Post TNT KIX symbols The same as RM4SCC but without check digit or stop/start chars Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */ -INTERNAL int kix(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_kix(struct zint_symbol *symbol, unsigned char source[], int length) { char height_pattern[75]; char *d = height_pattern; int posns[18]; @@ -543,11 +543,11 @@ INTERNAL int kix(struct zint_symbol *symbol, unsigned char source[], int length) const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 18) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 490, "Input length %d too long (maximum 18)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 490, "Input length %d too long (maximum 18)", length); } - to_upper(source, length); - if ((i = not_sane_lookup(KRSET, 36, source, length, posns))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 491, + z_to_upper(source, length); + if ((i = z_not_sane_lookup(KRSET, 36, source, length, posns))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 491, "Invalid character at position %d in input (alphanumerics only)", i); } @@ -560,11 +560,11 @@ INTERNAL int kix(struct zint_symbol *symbol, unsigned char source[], int length) h = d - height_pattern; for (loopey = 0; loopey < h; loopey++) { if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) { - set_module(symbol, 2, writer); + z_set_module(symbol, 2, writer); } writer += 2; } @@ -576,24 +576,24 @@ INTERNAL int kix(struct zint_symbol *symbol, unsigned char source[], int length) symbol->row_height[0] = 3.16417313f; /* (1.9 * 42.3) / 25.4 */ symbol->row_height[1] = 2.16496062f; /* (1.3 * 42.3) / 25.4 */ /* Note using max X for minimum and min X for maximum */ - error_number = daft_set_height(symbol, min_height, max_height); + error_number = zint_daft_set_height(symbol, min_height, max_height); } else { symbol->row_height[0] = 3.0f; symbol->row_height[1] = 2.0f; - (void) daft_set_height(symbol, 0.0f, 0.0f); + (void) zint_daft_set_height(symbol, 0.0f, 0.0f); } symbol->rows = 3; symbol->width = writer - 1; - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; } /* Handles DAFT Code symbols */ -INTERNAL int daft(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_daft(struct zint_symbol *symbol, unsigned char source[], int length) { int i; int posns[576]; int loopey; @@ -601,23 +601,23 @@ INTERNAL int daft(struct zint_symbol *symbol, unsigned char source[], int length const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 576) { /* 576 * 2 = 1152 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 492, "Input length %d too long (maximum 576)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 492, "Input length %d too long (maximum 576)", length); } - to_upper(source, length); + z_to_upper(source, length); - if ((i = not_sane_lookup(DAFTSET, 4, source, length, posns))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 493, + if ((i = z_not_sane_lookup(DAFTSET, 4, source, length, posns))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 493, "Invalid character at position %d in input (\"D\", \"A\", \"F\" and \"T\" only)", i); } writer = 0; for (loopey = 0; loopey < length; loopey++) { if ((posns[loopey] == 1) || (posns[loopey] == 0)) { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); if ((posns[loopey] == 2) || (posns[loopey] == 0)) { - set_module(symbol, 2, writer); + z_set_module(symbol, 2, writer); } writer += 2; } @@ -628,37 +628,37 @@ INTERNAL int daft(struct zint_symbol *symbol, unsigned char source[], int length if (symbol->height < 0.5f) { symbol->height = 8.0f; } - symbol->row_height[1] = stripf(symbol->height * t_ratio); - symbol->row_height[0] = stripf((symbol->height - symbol->row_height[1]) / 2.0f); + symbol->row_height[1] = z_stripf(symbol->height * t_ratio); + symbol->row_height[0] = z_stripf((symbol->height - symbol->row_height[1]) / 2.0f); } else { symbol->row_height[0] = 3.0f; symbol->row_height[1] = 2.0f; } /* DAFT generic barcode so no dimensions/height specification */ - (void) daft_set_height(symbol, 0.0f, 0.0f); + (void) zint_daft_set_height(symbol, 0.0f, 0.0f); symbol->rows = 3; symbol->width = writer - 1; - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return 0; } /* Flattermarken - Not really a barcode symbology! */ -INTERNAL int flat(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_flat(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number = 0; char dest[512]; /* 128 * 4 = 512 */ char *d = dest; const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 128) { /* 128 * 9 = 1152 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 494, "Input length %d too long (maximum 128)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 494, "Input length %d too long (maximum 128)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 495, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 495, "Invalid character at position %d in input (digits only)", i); } @@ -668,19 +668,19 @@ INTERNAL int flat(struct zint_symbol *symbol, unsigned char source[], int length d += entry[2] ? 4 : 2; } - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); /* TODO: Find documentation on BARCODE_FLAT dimensions/height */ - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; } /* Japanese Postal Code (Kasutama Barcode) */ -INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_japanpost(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number = 0, h; char pattern[69]; char *d = pattern; @@ -690,13 +690,13 @@ INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int l const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 20) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 496, "Input length %d too long (maximum 20)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 496, "Input length %d too long (maximum 20)", length); } - to_upper(source, length); + z_to_upper(source, length); - if ((i = not_sane(SHKASUTSET_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 497, + if ((i = z_not_sane(SHKASUTSET_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 497, "Invalid character at position %d in input (alphanumerics and \"-\" only)", i); } memset(inter, 'd', 20); /* Pad character CC4 */ @@ -725,7 +725,7 @@ INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int l } while ((i < length) && (inter_posn < 20)); if (i != length || inter[20] != '\0') { - return errtxt(ZINT_ERROR_TOO_LONG, symbol, 477, + return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 477, "Input too long, requires too many symbol characters (maximum 20)"); } @@ -734,8 +734,8 @@ INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int l sum = 0; for (i = 0; i < 20; i++, d += 3) { - memcpy(d, JapanTable[posn(KASUTSET, inter[i])], 3); - sum += posn(CHKASUTSET, inter[i]); + memcpy(d, JapanTable[z_posn(KASUTSET, inter[i])], 3); + sum += z_posn(CHKASUTSET, inter[i]); } /* Calculate check digit */ @@ -750,7 +750,7 @@ INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int l } else { check_char = (check - 11) + 'a'; } - memcpy(d, JapanTable[posn(KASUTSET, check_char)], 3); + memcpy(d, JapanTable[z_posn(KASUTSET, check_char)], 3); d += 3; if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check: %d, char: %c\n", check, check_char); @@ -763,11 +763,11 @@ INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int l h = d - pattern; for (loopey = 0; loopey < h; loopey++) { if ((pattern[loopey] == '2') || (pattern[loopey] == '1')) { - set_module(symbol, 0, writer); + z_set_module(symbol, 0, writer); } - set_module(symbol, 1, writer); + z_set_module(symbol, 1, writer); if ((pattern[loopey] == '3') || (pattern[loopey] == '1')) { - set_module(symbol, 2, writer); + z_set_module(symbol, 2, writer); } writer += 2; } @@ -784,16 +784,16 @@ INTERNAL int japanpost(struct zint_symbol *symbol, unsigned char source[], int l const float max_height = 7.19999981f; /* 3.6 / 0.5 */ symbol->row_height[0] = 2.0f; symbol->row_height[1] = 2.0f; - error_number = daft_set_height(symbol, min_height, max_height); + error_number = zint_daft_set_height(symbol, min_height, max_height); } else { symbol->row_height[0] = 3.0f; symbol->row_height[1] = 2.0f; - (void) daft_set_height(symbol, 0.0f, 0.0f); + (void) zint_daft_set_height(symbol, 0.0f, 0.0f); } /* Note: check char is in KASUTSET and not truly representable in raw text's SHKASUTSET_F */ - if (raw_text && rt_cpy(symbol, source, length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, source, length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } return error_number; diff --git a/backend/ps.c b/backend/ps.c index ce92881f..bf264006 100644 --- a/backend/ps.c +++ b/backend/ps.c @@ -53,8 +53,8 @@ static void ps_put_colour(const int is_rgb, const int colour, struct filemem *co "0 0 0", /* 6: Black (7) */ "1 1 1", /* 7: White (8) */ }; - fm_puts(ps_rgbs[idx], fmp); - fm_puts(" setrgbcolor\n", fmp); + zint_fm_puts(ps_rgbs[idx], fmp); + zint_fm_puts(" setrgbcolor\n", fmp); } else { static const char ps_cmyks[8][8] = { "1 0 0 0", /* 0: Cyan (1) */ @@ -66,8 +66,8 @@ static void ps_put_colour(const int is_rgb, const int colour, struct filemem *co "0 0 0 1", /* 6: Black (7) */ "0 0 0 0", /* 7: White (8) */ }; - fm_puts(ps_cmyks[idx], fmp); - fm_puts(" setcmykcolor\n", fmp); + zint_fm_puts(ps_cmyks[idx], fmp); + zint_fm_puts(" setcmykcolor\n", fmp); } } @@ -102,7 +102,7 @@ static void ps_convert(const unsigned char *string, unsigned char *ps_string) { } #ifdef ZINT_TEST /* Wrapper for direct testing */ -INTERNAL void ps_convert_test(const unsigned char *string, unsigned char *ps_string) { +INTERNAL void zint_test_ps_convert(const unsigned char *string, unsigned char *ps_string) { ps_convert(string, ps_string); } #endif @@ -110,50 +110,50 @@ INTERNAL void ps_convert_test(const unsigned char *string, unsigned char *ps_str /* Helper to output RGB colour */ static void ps_put_rgbcolor(const float red, const float green, const float blue, struct filemem *const fmp) { - fm_putsf("", 2, red, fmp); - fm_putsf(" ", 2, green, fmp); - fm_putsf(" ", 2, blue, fmp); - fm_puts(" setrgbcolor\n", fmp); + zint_fm_putsf("", 2, red, fmp); + zint_fm_putsf(" ", 2, green, fmp); + zint_fm_putsf(" ", 2, blue, fmp); + zint_fm_puts(" setrgbcolor\n", fmp); } /* Helper to output CMYK colour */ static void ps_put_cmykcolor(const float cyan, const float magenta, const float yellow, const float black, struct filemem *const fmp) { - fm_putsf("", 2, cyan, fmp); - fm_putsf(" ", 2, magenta, fmp); - fm_putsf(" ", 2, yellow, fmp); - fm_putsf(" ", 2, black, fmp); - fm_puts(" setcmykcolor\n", fmp); + zint_fm_putsf("", 2, cyan, fmp); + zint_fm_putsf(" ", 2, magenta, fmp); + zint_fm_putsf(" ", 2, yellow, fmp); + zint_fm_putsf(" ", 2, black, fmp); + zint_fm_puts(" setcmykcolor\n", fmp); } /* Helper to output rectangle */ static void ps_put_rect(const struct zint_symbol *symbol, const struct zint_vector_rect *rect, const int type, struct filemem *const fmp) { if (type == 0 || type == 1) { - fm_putsf("", 2, rect->height, fmp); - fm_putsf(" ", 2, (symbol->vector->height - rect->y) - rect->height, fmp); + zint_fm_putsf("", 2, rect->height, fmp); + zint_fm_putsf(" ", 2, (symbol->vector->height - rect->y) - rect->height, fmp); } - fm_putsf(type == 0 ? " " : type == 1 ? " I " : type == 2 ? "I " : "", 2, rect->x, fmp); - fm_putsf(" ", 2, rect->width, fmp); - fm_puts(" R\n", fmp); + zint_fm_putsf(type == 0 ? " " : type == 1 ? " I " : type == 2 ? "I " : "", 2, rect->x, fmp); + zint_fm_putsf(" ", 2, rect->width, fmp); + zint_fm_puts(" R\n", fmp); } /* Helper to output circle/disc */ static void ps_put_circle(const struct zint_symbol *symbol, const struct zint_vector_circle *circle, const float radius, const int type, struct filemem *const fmp) { if (circle->width) { - fm_putsf("", 2, circle->x, fmp); - fm_putsf(" ", 2, symbol->vector->height - circle->y, fmp); - fm_putsf(" ", 4, radius, fmp); - fm_putsf(" ", 4, circle->width, fmp); - fm_puts(" C\n", fmp); + zint_fm_putsf("", 2, circle->x, fmp); + zint_fm_putsf(" ", 2, symbol->vector->height - circle->y, fmp); + zint_fm_putsf(" ", 4, radius, fmp); + zint_fm_putsf(" ", 4, circle->width, fmp); + zint_fm_puts(" C\n", fmp); } else { if (type == 0 || type == 1) { - fm_putsf("", 2, symbol->vector->height - circle->y, fmp); - fm_putsf(" ", 4, radius, fmp); + zint_fm_putsf("", 2, symbol->vector->height - circle->y, fmp); + zint_fm_putsf(" ", 4, radius, fmp); } - fm_putsf(type == 0 ? " " : type == 1 ? " I " : type == 2 ? "I " : "", 2, circle->x, fmp); - fm_puts(" D\n", fmp); + zint_fm_putsf(type == 0 ? " " : type == 1 ? " I " : type == 2 ? "I " : "", 2, circle->x, fmp); + zint_fm_puts(" D\n", fmp); } } @@ -169,7 +169,7 @@ static int ps_count_rectangles(const struct zint_symbol *symbol) { return rectangles; } -INTERNAL int ps_plot(struct zint_symbol *symbol) { +INTERNAL int zint_ps_plot(struct zint_symbol *symbol) { struct filemem fm; struct filemem *const fmp = &fm; unsigned char fgred, fggrn, fgblu, bgred, bggrn, bgblu, bgalpha; @@ -191,35 +191,36 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { int ps_len = 0; int iso_latin1 = 0; int have_circles_with_width = 0, have_circles_without_width = 0; - const int upcean = is_upcean(symbol->symbology); + const int is_upcean = z_is_upcean(symbol->symbology); const int is_rgb = (symbol->output_options & CMYK_COLOUR) == 0; if (symbol->vector == NULL) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 646, "Vector header NULL"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 646, "Vector header NULL"); } - if (!fm_open(fmp, symbol, "w")) { - return ZEXT errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 645, "Could not open EPS output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_open(fmp, symbol, "w")) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 645, "Could not open EPS output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } if (is_rgb) { - (void) out_colour_get_rgb(symbol->fgcolour, &fgred, &fggrn, &fgblu, NULL /*alpha*/); + (void) zint_out_colour_get_rgb(symbol->fgcolour, &fgred, &fggrn, &fgblu, NULL /*alpha*/); red_ink = fgred / 255.0f; green_ink = fggrn / 255.0f; blue_ink = fgblu / 255.0f; - (void) out_colour_get_rgb(symbol->bgcolour, &bgred, &bggrn, &bgblu, &bgalpha); + (void) zint_out_colour_get_rgb(symbol->bgcolour, &bgred, &bggrn, &bgblu, &bgalpha); red_paper = bgred / 255.0f; green_paper = bggrn / 255.0f; blue_paper = bgblu / 255.0f; } else { - (void) out_colour_get_cmyk(symbol->fgcolour, &fgcyan, &fgmagenta, &fgyellow, &fgblack, NULL /*rgb_alpha*/); + (void) zint_out_colour_get_cmyk(symbol->fgcolour, &fgcyan, &fgmagenta, &fgyellow, &fgblack, + NULL /*rgb_alpha*/); cyan_ink = fgcyan / 100.0f; magenta_ink = fgmagenta / 100.0f; yellow_ink = fgyellow / 100.0f; black_ink = fgblack / 100.0f; - (void) out_colour_get_cmyk(symbol->bgcolour, &bgcyan, &bgmagenta, &bgyellow, &bgblack, &bgalpha); + (void) zint_out_colour_get_cmyk(symbol->bgcolour, &bgcyan, &bgmagenta, &bgyellow, &bgblack, &bgalpha); cyan_paper = bgcyan / 100.0f; magenta_paper = bgmagenta / 100.0f; yellow_paper = bgyellow / 100.0f; @@ -261,52 +262,53 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { } /* Start writing the header */ - fm_puts("%!PS-Adobe-3.0 EPSF-3.0\n" - "%%Creator: Zint ", fmp); + zint_fm_puts("%!PS-Adobe-3.0 EPSF-3.0\n" + "%%Creator: Zint ", fmp); #if ZINT_VERSION_BUILD - fm_printf(fmp, "%d.%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD); + zint_fm_printf(fmp, "%d.%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, + ZINT_VERSION_BUILD); #else - fm_printf(fmp, "%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE); + zint_fm_printf(fmp, "%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE); #endif - fm_puts("%%Title: Zint Generated Symbol\n" - "%%Pages: 0\n" - "%%BoundingBox: 0 0 ", fmp); - fm_printf(fmp, "%d %d\n", (int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height)); - fm_puts("%%EndComments\n", fmp); + zint_fm_puts("%%Title: Zint Generated Symbol\n" + "%%Pages: 0\n" + "%%BoundingBox: 0 0 ", fmp); + zint_fm_printf(fmp, "%d %d\n", (int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height)); + zint_fm_puts("%%EndComments\n", fmp); /* Definitions */ if (have_circles_without_width) { /* Disc: y radius x D */ - fm_puts("/D { newpath 3 1 roll 0 360 arc fill } bind def\n", fmp); + zint_fm_puts("/D { newpath 3 1 roll 0 360 arc fill } bind def\n", fmp); } if (have_circles_with_width) { /* Circle (ring): x y radius width C (adapted from BWIPP renmaxicode.ps) */ - fm_puts("/C { newpath 4 1 roll 3 copy 0 360 arc closepath 4 -1 roll add 360 0 arcn closepath fill }" - " bind def\n", fmp); + zint_fm_puts("/C { newpath 4 1 roll 3 copy 0 360 arc closepath 4 -1 roll add 360 0 arcn closepath fill }" + " bind def\n", fmp); } if (symbol->vector->hexagons) { /* Hexagon: radius half_radius half_sqrt3_radius x y */ if (symbol->vector->hexagons->rotation == 0 || symbol->vector->hexagons->rotation == 180) { - fm_puts("/H { newpath moveto 2 copy exch neg exch rmoveto 2 index neg 0 exch rlineto 2 copy neg rlineto" - " 2 copy rlineto 3 -1 roll 0 exch rlineto exch neg exch rlineto closepath fill }" - " bind def\n", fmp); + zint_fm_puts("/H { newpath moveto 2 copy exch neg exch rmoveto 2 index neg 0 exch rlineto" + " 2 copy neg rlineto 2 copy rlineto 3 -1 roll 0 exch rlineto exch neg exch rlineto" + " closepath fill } bind def\n", fmp); } else { - fm_puts("/H { newpath moveto 2 copy neg exch neg rmoveto 2 index 0 rlineto 2 copy exch rlineto" - " 2 copy neg exch rlineto 3 -1 roll neg 0 rlineto neg exch neg rlineto closepath fill }" - " bind def\n", fmp); + zint_fm_puts("/H { newpath moveto 2 copy neg exch neg rmoveto 2 index 0 rlineto 2 copy exch rlineto" + " 2 copy neg exch rlineto 3 -1 roll neg 0 rlineto neg exch neg rlineto" + " closepath fill } bind def\n", fmp); } /* Copy r hr hsr for repeat use without having to specify them subsequently */ - fm_puts("/J { 3 copy } bind def\n", fmp); + zint_fm_puts("/J { 3 copy } bind def\n", fmp); /* TODO: Save repeating x also */ } if (symbol->vector->rectangles || draw_background) { /* Rectangle: h y x w */ - fm_puts("/R { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill }" - " bind def\n", fmp); + zint_fm_puts("/R { newpath 4 1 roll exch moveto 1 index 0 rlineto 0 exch rlineto neg 0 rlineto" + " closepath fill } bind def\n", fmp); } if (symbol->vector->rectangles || have_circles_without_width) { /* Copy h y (rect) or y r (disc) for repeat use without having to specify them subsequently */ - fm_puts("/I { 2 copy } bind def\n", fmp); + zint_fm_puts("/I { 2 copy } bind def\n", fmp); } /* Now the actual representation */ @@ -319,9 +321,9 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { ps_put_cmykcolor(cyan_paper, magenta_paper, yellow_paper, black_paper, fmp); } - fm_putsf("", 2, symbol->vector->height, fmp); - fm_putsf(" 0 0 ", 2, symbol->vector->width, fmp); /* y x w */ - fm_puts(" R\n", fmp); + zint_fm_putsf("", 2, symbol->vector->height, fmp); + zint_fm_putsf(" 0 0 ", 2, symbol->vector->width, fmp); /* y x w */ + zint_fm_puts(" R\n", fmp); } if (symbol->symbology != BARCODE_ULTRA) { @@ -395,18 +397,18 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { float hy = symbol->vector->height - hex->y; if (previous_diameter != hex->diameter) { previous_diameter = hex->diameter; - fm_putsf("", 4, 0.5f * previous_diameter /*radius*/, fmp); - fm_putsf(" ", 4, 0.43301270189221932338f * previous_diameter /*half_sqrt3_radius*/, fmp); - fm_putsf(" ", 4, 0.25f * previous_diameter /*half_radius*/, fmp); - fm_putc('\n', fmp); + zint_fm_putsf("", 4, 0.5f * previous_diameter /*radius*/, fmp); + zint_fm_putsf(" ", 4, 0.43301270189221932338f * previous_diameter /*half_sqrt3_radius*/, fmp); + zint_fm_putsf(" ", 4, 0.25f * previous_diameter /*half_radius*/, fmp); + zint_fm_putc('\n', fmp); } if (hex->next) { - fm_putsf("J ", 2, hex->x, fmp); + zint_fm_putsf("J ", 2, hex->x, fmp); } else { - fm_putsf("", 2, hex->x, fmp); + zint_fm_putsf("", 2, hex->x, fmp); } - fm_putsf(" ", 2, hy, fmp); - fm_puts(" H\n", fmp); + zint_fm_putsf(" ", 2, hy, fmp); + zint_fm_puts(" H\n", fmp); } /* Circles */ @@ -453,68 +455,68 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) { const char *font; unsigned char *ps_string = (unsigned char *) z_alloca(ps_len + 1); - if ((symbol->output_options & BOLD_TEXT) && !upcean) { + if ((symbol->output_options & BOLD_TEXT) && !is_upcean) { font = "Helvetica-Bold"; } else { font = "Helvetica"; } if (iso_latin1) { /* Change encoding to ISO 8859-1, see Postscript Language Reference Manual 2nd Edition Example 5.6 */ - fm_printf(fmp, "/%s findfont\n", font); - fm_puts("dup length dict begin\n" - "{1 index /FID ne {def} {pop pop} ifelse} forall\n" - "/Encoding ISOLatin1Encoding def\n" - "currentdict\n" - "end\n" - "/Helvetica-ISOLatin1 exch definefont pop\n", fmp); + zint_fm_printf(fmp, "/%s findfont\n", font); + zint_fm_puts("dup length dict begin\n" + "{1 index /FID ne {def} {pop pop} ifelse} forall\n" + "/Encoding ISOLatin1Encoding def\n" + "currentdict\n" + "end\n" + "/Helvetica-ISOLatin1 exch definefont pop\n", fmp); font = "Helvetica-ISOLatin1"; } do { ps_convert(string->text, ps_string); if (string->fsize != previous_fsize) { - fm_printf(fmp, "/%s findfont", font); + zint_fm_printf(fmp, "/%s findfont", font); /* Compensate for Helvetica being smaller than Zint's OCR-B */ - fm_putsf( " ", 2, upcean ? string->fsize * 1.07f : string->fsize, fmp); - fm_puts(" scalefont setfont\n", fmp); + zint_fm_putsf( " ", 2, is_upcean ? string->fsize * 1.07f : string->fsize, fmp); + zint_fm_puts(" scalefont setfont\n", fmp); previous_fsize = string->fsize; } /* Unhack the guard whitespace `gws_left_fudge`/`gws_right_fudge` hack */ - if (upcean && string->halign == 1 && string->text[0] == '<') { + if (is_upcean && string->halign == 1 && string->text[0] == '<') { const float gws_left_fudge = symbol->scale < 0.1f ? 0.1f : symbol->scale; /* 0.5 * 2 * scale */ - fm_putsf(" ", 2, string->x + gws_left_fudge, fmp); - } else if (upcean && string->halign == 2 && string->text[0] == '>') { + zint_fm_putsf(" ", 2, string->x + gws_left_fudge, fmp); + } else if (is_upcean && string->halign == 2 && string->text[0] == '>') { const float gws_right_fudge = symbol->scale < 0.1f ? 0.1f : symbol->scale; /* 0.5 * 2 * scale */ - fm_putsf(" ", 2, string->x - gws_right_fudge, fmp); + zint_fm_putsf(" ", 2, string->x - gws_right_fudge, fmp); } else { - fm_putsf(" ", 2, string->x, fmp); + zint_fm_putsf(" ", 2, string->x, fmp); } - fm_putsf(" ", 2, symbol->vector->height - string->y, fmp); - fm_puts(" moveto\n", fmp); + zint_fm_putsf(" ", 2, symbol->vector->height - string->y, fmp); + zint_fm_puts(" moveto\n", fmp); if (string->rotation != 0) { - fm_puts(" gsave\n", fmp); - fm_printf(fmp, " %d rotate\n", 360 - string->rotation); + zint_fm_puts(" gsave\n", fmp); + zint_fm_printf(fmp, " %d rotate\n", 360 - string->rotation); } if (string->halign == 0 || string->halign == 2) { /* Need width for middle or right align */ - fm_printf(fmp, " (%s) stringwidth pop" /* Returns "width height" - discard "height" */ + zint_fm_printf(fmp, " (%s) stringwidth pop" /* Returns "width height" - discard "height" */ " %s 0 rmoveto\n", ps_string, string->halign == 2 ? "neg" : "-2 div"); } - fm_printf(fmp, " (%s) show\n", ps_string); + zint_fm_printf(fmp, " (%s) show\n", ps_string); if (string->rotation != 0) { - fm_puts(" grestore\n", fmp); + zint_fm_puts(" grestore\n", fmp); } string = string->next; } while (string); } - if (fm_error(fmp)) { - ZEXT errtxtf(0, symbol, 647, "Incomplete write of EPS output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); - (void) fm_close(fmp, symbol); + if (zint_fm_error(fmp)) { + ZEXT z_errtxtf(0, symbol, 647, "Incomplete write of EPS output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); + (void) zint_fm_close(fmp, symbol); return ZINT_ERROR_FILE_WRITE; } - if (!fm_close(fmp, symbol)) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 649, "Failure on closing EPS output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_close(fmp, symbol)) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 649, "Failure on closing EPS output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } return 0; diff --git a/backend/qr.c b/backend/qr.c index a2f0bda2..51301bf2 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -54,7 +54,7 @@ static const char qr_ecc_level_names[] = { 'L', 'M', 'Q', 'H' }; /* Returns true if input glyph is in the Alphanumeric set or is GS1 FNC1 */ static int qr_is_alpha(const unsigned int glyph, const int gs1) { - if (is_chr(QR_ALPHA, glyph)) { + if (z_is_chr(QR_ALPHA, glyph)) { return 1; } if (gs1 && glyph == '\x1D') { @@ -327,7 +327,7 @@ static void qr_define_mode(char mode[], const unsigned int ddata[], const int le /* Get optimal mode for each code point by tracing backwards */ for (i = length - 1; i >= 0; i--) { - j = posn(qr_mode_types, cur_mode); + j = z_posn(qr_mode_types, cur_mode); cur_mode = char_modes[i][j]; mode[i] = cur_mode; } @@ -349,7 +349,7 @@ static int qr_mode_indicator(const int version, const int mode) { { 0, 1, 2, 3, }, }; - int mode_index = posn(qr_mode_types, (const char) mode); + int mode_index = z_posn(qr_mode_types, (const char) mode); if (version < RMQR_VERSION) { return mode_indicators[0][mode_index]; /* QRCODE */ @@ -386,7 +386,7 @@ static int qr_cci_bits(const int version, const int mode) { static const unsigned char *const rmqr_ccis[QR_NUM_MODES] = { rmqr_numeric_cci, rmqr_alphanum_cci, rmqr_byte_cci, rmqr_kanji_cci, }; - int mode_index = posn(qr_mode_types, (const char) mode); + int mode_index = z_posn(qr_mode_types, (const char) mode); if (version < RMQR_VERSION) { /* QRCODE */ if (version < 10) { @@ -425,13 +425,13 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] int percent_count; if (eci != 0) { /* Not applicable to MICROQR */ - bp = bin_append_posn(7, version < RMQR_VERSION ? 4 : 3, binary, bp); /* ECI (Table 4) */ + bp = z_bin_append_posn(7, version < RMQR_VERSION ? 4 : 3, binary, bp); /* ECI (Table 4) */ if (eci <= 127) { - bp = bin_append_posn(eci, 8, binary, bp); /* 000000 to 000127 */ + bp = z_bin_append_posn(eci, 8, binary, bp); /* 000000 to 000127 */ } else if (eci <= 16383) { - bp = bin_append_posn(0x8000 + eci, 16, binary, bp); /* 000128 to 016383 */ + bp = z_bin_append_posn(0x8000 + eci, 16, binary, bp); /* 000128 to 016383 */ } else { - bp = bin_append_posn(0xC00000 + eci, 24, binary, bp); /* 016384 to 999999 */ + bp = z_bin_append_posn(0xC00000 + eci, 24, binary, bp); /* 016384 to 999999 */ } } @@ -451,7 +451,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] /* Mode indicator */ if (modebits) { - bp = bin_append_posn(qr_mode_indicator(version, data_block), modebits, binary, bp); + bp = z_bin_append_posn(qr_mode_indicator(version, data_block), modebits, binary, bp); } switch (data_block) { @@ -459,7 +459,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] /* Kanji mode */ /* Character count indicator */ - bp = bin_append_posn(short_data_block_length, qr_cci_bits(version, data_block), binary, bp); + bp = z_bin_append_posn(short_data_block_length, qr_cci_bits(version, data_block), binary, bp); if (debug_print) { printf("Kanji block (length %d)\n\t", short_data_block_length); @@ -478,7 +478,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] prod = ((jis >> 8) * 0xc0) + (jis & 0xff); - bp = bin_append_posn(prod, 13, binary, bp); + bp = z_bin_append_posn(prod, 13, binary, bp); if (debug_print) { printf("0x%04X ", prod); @@ -494,8 +494,8 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] /* Byte mode */ /* Character count indicator */ - bp = bin_append_posn(short_data_block_length + double_byte, qr_cci_bits(version, data_block), binary, - bp); + bp = z_bin_append_posn(short_data_block_length + double_byte, qr_cci_bits(version, data_block), + binary, bp); if (debug_print) { printf("Byte block (length %d)\n\t", short_data_block_length + double_byte); @@ -505,7 +505,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] for (i = 0; i < short_data_block_length; i++) { unsigned int byte = ddata[position + i]; - bp = bin_append_posn(byte, byte > 0xFF ? 16 : 8, binary, bp); + bp = z_bin_append_posn(byte, byte > 0xFF ? 16 : 8, binary, bp); if (debug_print) { printf("0x%02X(%d) ", byte, (int) byte); @@ -530,8 +530,8 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] } /* Character count indicator */ - bp = bin_append_posn(short_data_block_length + percent_count, qr_cci_bits(version, data_block), - binary, bp); + bp = z_bin_append_posn(short_data_block_length + percent_count, qr_cci_bits(version, data_block), + binary, bp); if (debug_print) { printf("Alpha block (length %d)\n\t", short_data_block_length + percent_count); @@ -604,7 +604,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] } } - bp = bin_append_posn(prod, 1 + (5 * count), binary, bp); + bp = z_bin_append_posn(prod, 1 + (5 * count), binary, bp); if (debug_print) { printf("0x%X ", prod); @@ -620,7 +620,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] /* Numeric mode */ /* Character count indicator */ - bp = bin_append_posn(short_data_block_length, qr_cci_bits(version, data_block), binary, bp); + bp = z_bin_append_posn(short_data_block_length, qr_cci_bits(version, data_block), binary, bp); if (debug_print) { printf("Number block (length %d)\n\t", short_data_block_length); @@ -632,23 +632,23 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[] int count; int first = 0, prod; - first = ctoi((const char) ddata[position + i]); + first = z_ctoi((const char) ddata[position + i]); count = 1; prod = first; if (i + 1 < short_data_block_length && mode[position + i + 1] == 'N') { - int second = ctoi((const char) ddata[position + i + 1]); + int second = z_ctoi((const char) ddata[position + i + 1]); count = 2; prod = (prod * 10) + second; if (i + 2 < short_data_block_length && mode[position + i + 2] == 'N') { - int third = ctoi((const char) ddata[position + i + 2]); + int third = z_ctoi((const char) ddata[position + i + 2]); count = 3; prod = (prod * 10) + third; } } - bp = bin_append_posn(prod, 1 + (3 * count), binary, bp); + bp = z_bin_append_posn(prod, 1 + (3 * count), binary, bp); if (debug_print) { printf("0x%X(%d) ", prod, prod); @@ -686,18 +686,18 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i *binary = '\0'; if (p_structapp) { - bp = bin_append_posn(3, 4, binary, bp); /* Structured Append indicator */ - bp = bin_append_posn(p_structapp->index - 1, 4, binary, bp); - bp = bin_append_posn(p_structapp->count - 1, 4, binary, bp); - bp = bin_append_posn(to_int((const unsigned char *) p_structapp->id, (int) strlen(p_structapp->id)), 8, - binary, bp); /* Parity */ + bp = z_bin_append_posn(3, 4, binary, bp); /* Structured Append indicator */ + bp = z_bin_append_posn(p_structapp->index - 1, 4, binary, bp); + bp = z_bin_append_posn(p_structapp->count - 1, 4, binary, bp); + bp = z_bin_append_posn(z_to_int(ZCUCP(p_structapp->id), (int) strlen(p_structapp->id)), 8, binary, + bp); /* Parity */ } if (gs1) { /* Not applicable to MICROQR */ if (version < RMQR_VERSION) { - bp = bin_append_posn(5, 4, binary, bp); /* FNC1 */ + bp = z_bin_append_posn(5, 4, binary, bp); /* FNC1 */ } else { - bp = bin_append_posn(5, 3, binary, bp); + bp = z_bin_append_posn(5, 3, binary, bp); } } @@ -722,7 +722,7 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i if (termbits || current_bytes < target_codewords) { int max_termbits = qr_terminator_bits(version); termbits = termbits < max_termbits && current_bytes == target_codewords ? termbits : max_termbits; - bp = bin_append_posn(0, termbits, binary, bp); + bp = z_bin_append_posn(0, termbits, binary, bp); } /* Padding bits */ @@ -732,7 +732,7 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i } if (padbits) { current_bytes = (bp + padbits) / 8; - (void) bin_append_posn(0, padbits, binary, bp); /* Last use so not setting bp */ + (void) z_bin_append_posn(0, padbits, binary, bp); /* Last use so not setting bp */ } if (debug_print) printf("Terminated binary (%d): %.*s (padbits %d)\n", bp, bp, binary, padbits); @@ -810,8 +810,8 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea interleaved_data = (unsigned char *) z_alloca(data_cw); interleaved_ecc = (unsigned char *) z_alloca(ecc_cw); - rs_init_gf(&rs, 0x11d); - rs_init_code(&rs, ecc_block_length, 0); + zint_rs_init_gf(&rs, 0x11d); + zint_rs_init_code(&rs, ecc_block_length, 0); in_posn = 0; @@ -827,7 +827,7 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea data_block[j] = datastream[in_posn + j]; /* NOLINT(clang-analyzer-core.uninitialized.Assign) */ } - rs_encode(&rs, length_this_block, data_block, ecc_block); + zint_rs_encode(&rs, length_this_block, data_block, ecc_block); if (debug_print) { printf("Block %d: ", i + 1); @@ -1599,39 +1599,41 @@ static int qr_prep_data(struct zint_symbol *symbol, struct zint_seg segs[], cons /* GS1 raw text dealt with by `ZBarcode_Encode_Segs()` */ const int raw_text = (symbol->input_mode & 0x07) != GS1_MODE && (symbol->output_options & BARCODE_RAW_TEXT); - 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 */ } if ((symbol->input_mode & 0x07) == DATA_MODE) { - warn_number = sjis_cpy_segs(symbol, segs, seg_count, ddata, full_multibyte); + warn_number = zint_sjis_cpy_segs(symbol, segs, seg_count, ddata, full_multibyte); } else { unsigned int *dd = ddata; for (i = 0; i < seg_count; i++) { int done = 0, eci = segs[i].eci; if (segs[i].eci != 20 || seg_count > 1) { /* Unless ECI 20 (Shift JIS) or have multiple segments */ /* Try other encodings (ECI 0 defaults to ISO/IEC 8859-1) */ - int error_number = sjis_utf8_to_eci(segs[i].eci, segs[i].source, &segs[i].length, dd, full_multibyte); + int error_number = zint_sjis_utf8_to_eci(segs[i].eci, segs[i].source, &segs[i].length, dd, + full_multibyte); if (error_number == 0) { done = 1; } else if (segs[i].eci || seg_count > 1) { - return errtxtf(error_number, symbol, 575, "Invalid character in input for ECI '%d'", segs[i].eci); + return z_errtxtf(error_number, symbol, 575, "Invalid character in input for ECI '%d'", + segs[i].eci); } } if (!done) { /* Try Shift-JIS */ - int error_number = sjis_utf8(symbol, segs[i].source, &segs[i].length, dd); + int error_number = zint_sjis_utf8(symbol, segs[i].source, &segs[i].length, dd); if (error_number != 0) { return error_number; } if (segs[i].eci != 20) { - warn_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 760, + warn_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 760, "Converted to Shift JIS but no ECI specified"); } eci = 20; } - if (raw_text && rt_cpy_seg_ddata(symbol, i, &segs[i], eci, dd)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg_ddata()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg_ddata(symbol, i, &segs[i], eci, dd)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg_ddata()` only fails with OOM */ } dd += segs[i].length; } @@ -1640,7 +1642,7 @@ static int qr_prep_data(struct zint_symbol *symbol, struct zint_seg segs[], cons return warn_number; } -INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int warn_number; int i, j, est_binlen, prev_est_binlen; int ecc_level, autosize, version, max_cw, target_codewords, blocks, size; @@ -1652,7 +1654,7 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in const int gs1 = ((symbol->input_mode & 0x07) == GS1_MODE); const int fast_encode = symbol->input_mode & FAST_MODE; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; - const int eci_length_segs = get_eci_length_segs(segs, seg_count); + const int eci_length_segs = zint_get_eci_length_segs(segs, seg_count); struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count); unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * eci_length_segs); char *mode = (char *) z_alloca(eci_length_segs); @@ -1666,7 +1668,7 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in user_mask = 0; /* Ignore */ } - segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs & protect lengths) */ + z_segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs & protect lengths) */ warn_number = qr_prep_data(symbol, local_segs, seg_count, ddata); if (warn_number >= ZINT_ERROR) { @@ -1675,13 +1677,13 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in if (symbol->structapp.count) { if (symbol->structapp.count < 2 || symbol->structapp.count > 16) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 750, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 750, "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, 751, - "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, 751, + "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; @@ -1689,16 +1691,16 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in for (id_len = 1; id_len < 4 && symbol->structapp.id[id_len]; id_len++); if (id_len > 3) { /* Max value 255 */ - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 752, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 752, "Structured Append ID length %d too long (3 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, 753, "Invalid Structured Append ID (digits only)"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 753, "Invalid Structured Append ID (digits only)"); } if (id > 255) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 754, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 754, "Structured Append ID value '%d' out of range (0 to 255)", id); } } @@ -1710,13 +1712,13 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in if (gs1 && warn_number == 0) { for (i = 0; i < seg_count; i++) { if (local_segs[i].eci) { - warn_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 755, + warn_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 755, "Using ECI in GS1 mode not supported by GS1 standards"); break; } } if (warn_number == 0 && p_structapp) { - warn_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 756, + warn_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 756, "Using Structured Append in GS1 mode not supported by GS1 standards"); } } @@ -1733,13 +1735,13 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in if (est_binlen > (8 * max_cw)) { if (ecc_level == QR_LEVEL_L) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 567, - "Input too long, requires %1$d codewords (maximum %2$d)", (est_binlen + 7) / 8, - max_cw); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 567, + "Input too long, requires %1$d codewords (maximum %2$d)", (est_binlen + 7) / 8, + max_cw); } - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 561, - "Input too long for ECC level %1$c, requires %2$d codewords (maximum %3$d)", - qr_ecc_level_names[ecc_level], (est_binlen + 7) / 8, max_cw); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 561, + "Input too long for ECC level %1$c, requires %2$d codewords (maximum %3$d)", + qr_ecc_level_names[ecc_level], (est_binlen + 7) / 8, max_cw); } autosize = 40; @@ -1804,10 +1806,10 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in } if (symbol->option_2 < version) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 569, - "Input too long for Version %1$d-%2$c, requires %3$d codewords (maximum %4$d)", - symbol->option_2, qr_ecc_level_names[ecc_level], (est_binlen + 7) / 8, - qr_data_codewords[ecc_level][symbol->option_2 - 1]); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 569, + "Input too long for Version %1$d-%2$c, requires %3$d codewords (maximum %4$d)", + symbol->option_2, qr_ecc_level_names[ecc_level], (est_binlen + 7) / 8, + qr_data_codewords[ecc_level][symbol->option_2 - 1]); } } @@ -1839,7 +1841,7 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in (void) qr_binary_segs(datastream, version, target_codewords, mode, ddata, local_segs, seg_count, p_structapp, gs1, est_binlen, debug_print); #ifdef ZINT_TEST - if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, datastream, target_codewords); + if (symbol->debug & ZINT_DEBUG_TEST) z_debug_test_codeword_dump(symbol, datastream, target_codewords); #endif qr_add_ecc(fullstream, datastream, version, target_codewords, blocks, debug_print); @@ -1872,7 +1874,7 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in int r = i * size; for (j = 0; j < size; j++) { if (grid[r + j] & 0x01) { - set_module(symbol, i, j); + z_set_module(symbol, i, j); } } symbol->row_height[i] = 1; @@ -1901,11 +1903,11 @@ static int microqr_end(struct zint_symbol *symbol, char binary_data[], int bp, c bits_left = bits_total - bp; if (bits_left <= terminator_bits) { if (bits_left) { - bp = bin_append_posn(0, bits_left, binary_data, bp); + bp = z_bin_append_posn(0, bits_left, binary_data, bp); bits_left = 0; } } else { - bp = bin_append_posn(0, terminator_bits, binary_data, bp); + bp = z_bin_append_posn(0, terminator_bits, binary_data, bp); bits_left -= terminator_bits; } @@ -1915,7 +1917,7 @@ static int microqr_end(struct zint_symbol *symbol, char binary_data[], int bp, c /* Manage last (4-bit) block */ if (bits_end == 4 && bits_left && bits_left <= 4) { - bp = bin_append_posn(0, bits_left, binary_data, bp); + bp = z_bin_append_posn(0, bits_left, binary_data, bp); bits_left = 0; } @@ -1923,7 +1925,7 @@ static int microqr_end(struct zint_symbol *symbol, char binary_data[], int bp, c /* Complete current byte */ int remainder = 8 - (bp % 8); if (remainder != 8) { - bp = bin_append_posn(0, remainder, binary_data, bp); + bp = z_bin_append_posn(0, remainder, binary_data, bp); bits_left -= remainder; } @@ -1933,10 +1935,10 @@ static int microqr_end(struct zint_symbol *symbol, char binary_data[], int bp, c } remainder = bits_left / 8; for (i = 0; i < remainder; i++) { - bp = bin_append_posn(i & 1 ? 0x11 : 0xEC, 8, binary_data, bp); + bp = z_bin_append_posn(i & 1 ? 0x11 : 0xEC, 8, binary_data, bp); } if (bits_end == 4) { - bp = bin_append_posn(0, 4, binary_data, bp); + bp = z_bin_append_posn(0, 4, binary_data, bp); } } assert((bp & 0x07) == 8 - bits_end); @@ -1955,20 +1957,20 @@ static int microqr_end(struct zint_symbol *symbol, char binary_data[], int bp, c #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { char bp_buf[10]; - debug_test_codeword_dump(symbol, data_blocks, data_codewords); + z_debug_test_codeword_dump(symbol, data_blocks, data_codewords); sprintf(bp_buf, "%d", bp); /* Append `bp` to detect padding errors */ - errtxt_adj(0, symbol, "%s (%s)", bp_buf); + z_errtxt_adj(0, symbol, "%s (%s)", bp_buf); } #endif /* Calculate Reed-Solomon error codewords */ - rs_init_gf(&rs, 0x11d); - rs_init_code(&rs, ecc_codewords, 0); - rs_encode(&rs, data_codewords, data_blocks, ecc_blocks); + zint_rs_init_gf(&rs, 0x11d); + zint_rs_init_code(&rs, ecc_codewords, 0); + zint_rs_encode(&rs, data_codewords, data_blocks, ecc_blocks); /* Add Reed-Solomon codewords to binary data */ for (i = 0; i < ecc_codewords; i++) { - bp = bin_append_posn(ecc_blocks[i], 8, binary_data, bp); + bp = z_bin_append_posn(ecc_blocks[i], 8, binary_data, bp); } return bp; @@ -2167,7 +2169,7 @@ static int microqr_apply_bitmask(unsigned char *grid, const int size, const int return best_pattern; } -INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_microqr(struct zint_symbol *symbol, unsigned char source[], int length) { int i, size, j; char full_stream[200]; int bp; @@ -2190,22 +2192,23 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; if (length > 35) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 562, "Input length %d too long (maximum 35)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 562, "Input length %d too long (maximum 35)", length); } /* Check option 1 in combination with option 2 */ ecc_level = QR_LEVEL_L; if (symbol->option_1 >= 1 && symbol->option_1 <= 4) { if (symbol->option_1 == 4) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 566, "Error correction level H not available"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 566, "Error correction level H not available"); } if (symbol->option_2 >= 1 && symbol->option_2 <= 4) { if (symbol->option_2 == 1 && symbol->option_1 != 1) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 574, + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 574, "Version M1 supports error correction level L only"); } if (symbol->option_2 != 4 && symbol->option_1 == 3) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 563, "Error correction level Q requires Version M4"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 563, + "Error correction level Q requires Version M4"); } } ecc_level = symbol->option_1 - 1; @@ -2219,13 +2222,13 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len } if ((symbol->input_mode & 0x07) == DATA_MODE) { - sjis_cpy(source, &length, ddata, full_multibyte); + zint_sjis_cpy(source, &length, ddata, full_multibyte); } else { /* Try ISO 8859-1 conversion first */ - int error_number = sjis_utf8_to_eci(3, source, &length, ddata, full_multibyte); + int error_number = zint_sjis_utf8_to_eci(3, source, &length, ddata, full_multibyte); if (error_number != 0) { /* Try Shift-JIS */ - error_number = sjis_utf8(symbol, source, &length, ddata); + error_number = zint_sjis_utf8(symbol, source, &length, ddata); if (error_number != 0) { return error_number; } @@ -2269,8 +2272,8 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len segs[0].length = length; segs[0].eci = 0; - if (raw_text && (rt_init_segs(symbol, seg_count) || rt_cpy_seg_ddata(symbol, 0, &segs[0], eci, ddata))) { - return ZINT_ERROR_MEMORY; /* `rt_init_segs()` & `rt_cpy_seg_ddata()` only fail with OOM */ + if (raw_text && (z_rt_init_segs(symbol, seg_count) || z_rt_cpy_seg_ddata(symbol, 0, &segs[0], eci, ddata))) { + return ZINT_ERROR_MEMORY; /* `z_rt_init_segs()` & `z_rt_cpy_seg_ddata()` only fail with OOM */ } /* Determine length of binary data */ @@ -2285,9 +2288,10 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len /* Eliminate possible versions depending on binary length and error correction level specified */ if (binary_count[3] > microqr_data[ecc_level][3][0]) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 565, - "Input too long for Version M4-%1$c, requires %2$d codewords (maximum %3$d)", - qr_ecc_level_names[ecc_level], (binary_count[3] + 7) / 8, microqr_data[ecc_level][3][1]); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 565, + "Input too long for Version M4-%1$c, requires %2$d codewords (maximum %3$d)", + qr_ecc_level_names[ecc_level], (binary_count[3] + 7) / 8, + microqr_data[ecc_level][3][1]); } for (i = 0; i < 3; i++) { if (binary_count[i] > microqr_data[ecc_level][i][0]) { @@ -2309,20 +2313,20 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len /* Get version from user */ if ((symbol->option_2 >= 1) && (symbol->option_2 <= 4)) { - if (symbol->option_2 == 1 && (i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 758, + if (symbol->option_2 == 1 && (i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 758, "Invalid character at position %d in input for Version M1 (digits only)", i); - } else if (symbol->option_2 == 2 && not_sane(QR_ALPHA, source, length)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 759, + } else if (symbol->option_2 == 2 && z_not_sane(QR_ALPHA, source, length)) { + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 759, "Invalid character in input for Version M2 (digits, A-Z, space and \"$%*+-./:\" only)"); } if (symbol->option_2 - 1 >= version) { version = symbol->option_2 - 1; } else { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 570, - "Input too long for Version M%1$d-%2$c, requires %3$d codewords (maximum %4$d)", - symbol->option_2, qr_ecc_level_names[ecc_level], (binary_count[version] + 7) / 8, - microqr_data[ecc_level][symbol->option_2 - 1][1]); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 570, + "Input too long for Version M%1$d-%2$c, requires %3$d codewords (maximum %4$d)", + symbol->option_2, qr_ecc_level_names[ecc_level], (binary_count[version] + 7) / 8, + microqr_data[ecc_level][symbol->option_2 - 1][1]); } } @@ -2382,7 +2386,7 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len for (i = 0; i < size; i++) { for (j = 0; j < size; j++) { if (grid[(i * size) + j] & 0x01) { - set_module(symbol, i, j); + z_set_module(symbol, i, j); } } symbol->row_height[i] = 1; @@ -2393,7 +2397,7 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len } /* For UPNQR the symbol size and error correction capacity is fixed */ -INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_upnqr(struct zint_symbol *symbol, unsigned char source[], int length) { int i, j, r, est_binlen; int ecc_level, version, target_codewords, blocks, size; int bitmask, error_number; @@ -2425,13 +2429,13 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt } break; case GS1_MODE: /* Should never happen as checked before being called */ - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 571, + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 571, "UPNQR does not support GS1 data"); /* Not reached */ break; case UNICODE_MODE: - error_number = utf8_to_eci(4, source, preprocessed, &length); + error_number = zint_utf8_to_eci(4, source, preprocessed, &length); if (error_number != 0) { - return errtxt(error_number, symbol, 572, "Invalid character in input for ECI '4'"); + return z_errtxt(error_number, symbol, 572, "Invalid character in input for ECI '4'"); } for (i = 0; i < length; i++) { ddata[i] = preprocessed[i]; @@ -2444,8 +2448,9 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt segs[0].length = length; segs[0].eci = 4; - if (raw_text && (rt_init_segs(symbol, seg_count) || rt_cpy_seg_ddata(symbol, 0, &segs[0], 0 /*eci*/, ddata))) { - return ZINT_ERROR_MEMORY; /* `rt_init_segs()` & `rt_cpy_seg_ddata()` only fail with OOM */ + if (raw_text + && (z_rt_init_segs(symbol, seg_count) || z_rt_cpy_seg_ddata(symbol, 0, &segs[0], 0 /*eci*/, ddata))) { + return ZINT_ERROR_MEMORY; /* `z_rt_init_segs()` & `z_rt_cpy_seg_ddata()` only fail with OOM */ } est_binlen = qr_calc_binlen_segs(15, mode, ddata, segs, seg_count, NULL /*p_structapp*/, 1 /*mode_preset*/, @@ -2454,7 +2459,7 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt ecc_level = QR_LEVEL_M; if (est_binlen > 3320) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 573, "Input too long, requires %d codewords (maximum 415)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 573, "Input too long, requires %d codewords (maximum 415)", (est_binlen + 7) / 8); } @@ -2469,7 +2474,7 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt (void) qr_binary_segs(datastream, version, target_codewords, mode, ddata, segs, seg_count, NULL /*p_structapp*/, 0 /*gs1*/, est_binlen, debug_print); #ifdef ZINT_TEST - if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, datastream, target_codewords); + if (symbol->debug & ZINT_DEBUG_TEST) z_debug_test_codeword_dump(symbol, datastream, target_codewords); #endif qr_add_ecc(fullstream, datastream, version, target_codewords, blocks, debug_print); @@ -2500,7 +2505,7 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt r = i * size; for (j = 0; j < size; j++) { if (grid[r + j] & 0x01) { - set_module(symbol, i, j); + z_set_module(symbol, i, j); } } symbol->row_height[i] = 1; @@ -2633,7 +2638,7 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s } /* rMQR according to 2018 draft standard */ -INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int warn_number; int i, j, est_binlen; int ecc_level, autosize, version, max_cw, target_codewords, blocks, h_size, v_size; @@ -2641,7 +2646,7 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int unsigned int left_format_info, right_format_info; const int gs1 = ((symbol->input_mode & 0x07) == GS1_MODE); const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; - const int eci_length_segs = get_eci_length_segs(segs, seg_count); + const int eci_length_segs = zint_get_eci_length_segs(segs, seg_count); struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count); unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * eci_length_segs); char *mode = (char *) z_alloca(eci_length_segs); @@ -2650,18 +2655,18 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int unsigned char *grid; if (symbol->option_1 == 1) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 576, "Error correction level L not available in rMQR"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 576, "Error correction level L not available in rMQR"); } if (symbol->option_1 == 3) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 577, "Error correction level Q not available in rMQR"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 577, "Error correction level Q not available in rMQR"); } if ((symbol->option_2 < 0) || (symbol->option_2 > 38)) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 579, "Version '%d' out of range (1 to 38)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 579, "Version '%d' out of range (1 to 38)", symbol->option_2); } - segs_cpy(symbol, segs, seg_count, local_segs); + z_segs_cpy(symbol, segs, seg_count, local_segs); warn_number = qr_prep_data(symbol, local_segs, seg_count, ddata); if (warn_number >= ZINT_ERROR) { @@ -2673,7 +2678,7 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int if (gs1 && warn_number == 0) { for (i = 0; i < seg_count; i++) { if (local_segs[i].eci) { - warn_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 757, + warn_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 757, "Using ECI in GS1 mode not supported by GS1 standards"); break; } @@ -2687,9 +2692,9 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int max_cw = rmqr_data_codewords[ecc_level >> 1][31]; if (est_binlen > (8 * max_cw)) { - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 578, - "Input too long for ECC level %1$c, requires %2$d codewords (maximum %3$d)", - qr_ecc_level_names[ecc_level], (est_binlen + 7) / 8, max_cw); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 578, + "Input too long for ECC level %1$c, requires %2$d codewords (maximum %3$d)", + qr_ecc_level_names[ecc_level], (est_binlen + 7) / 8, max_cw); } version = 31; /* Set default to keep compiler happy */ @@ -2748,10 +2753,10 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int if (est_binlen > (target_codewords * 8)) { /* User has selected a symbol too small for the data */ assert(symbol->option_2 > 0); - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 560, - "Input too long for Version %1$d %2$s-%3$c, requires %4$d codewords (maximum %5$d)", - symbol->option_2, rmqr_version_names[symbol->option_2 - 1], qr_ecc_level_names[ecc_level], - (est_binlen + 7) / 8, target_codewords); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 560, + "Input too long for Version %1$d %2$s-%3$c, requires %4$d codewords (maximum %5$d)", + symbol->option_2, rmqr_version_names[symbol->option_2 - 1], + qr_ecc_level_names[ecc_level], (est_binlen + 7) / 8, target_codewords); } /* Feedback options */ @@ -2772,7 +2777,7 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int (void) qr_binary_segs(datastream, RMQR_VERSION + version, target_codewords, mode, ddata, local_segs, seg_count, NULL /*p_structapp*/, gs1, est_binlen, debug_print); #ifdef ZINT_TEST - if (symbol->debug & ZINT_DEBUG_TEST) debug_test_codeword_dump(symbol, datastream, target_codewords); + if (symbol->debug & ZINT_DEBUG_TEST) z_debug_test_codeword_dump(symbol, datastream, target_codewords); #endif qr_add_ecc(fullstream, datastream, RMQR_VERSION + version, target_codewords, blocks, debug_print); @@ -2828,7 +2833,7 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int int r = i * h_size; for (j = 0; j < h_size; j++) { if (grid[r + j] & 0x01) { - set_module(symbol, i, j); + z_set_module(symbol, i, j); } } symbol->row_height[i] = 1; diff --git a/backend/raster.c b/backend/raster.c index 851d56cc..d0689028 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -54,12 +54,12 @@ #define ZFONT_UPCEAN_TEXT 4 /* Helper flag to indicate dealing with EAN/UPC */ #ifndef ZINT_NO_PNG -INTERNAL int png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); +INTERNAL int zint_png_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); #endif /* ZINT_NO_PNG */ -INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); -INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); -INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); -INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); +INTERNAL int zint_bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); +INTERNAL int zint_pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); +INTERNAL int zint_gif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); +INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); static const char ultra_colour[] = "0CBMRYGKW"; @@ -93,12 +93,12 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf const size_t bm_bitmap_width = (size_t) symbol->bitmap_width * 3; const size_t bm_bitmap_size = bm_bitmap_width * symbol->bitmap_height; - if (out_colour_get_rgb(symbol->fgcolour, &map[DEFAULT_INK][0], &map[DEFAULT_INK][1], &map[DEFAULT_INK][2], + if (zint_out_colour_get_rgb(symbol->fgcolour, &map[DEFAULT_INK][0], &map[DEFAULT_INK][1], &map[DEFAULT_INK][2], &alpha[0])) { plot_alpha = 1; } - if (out_colour_get_rgb(symbol->bgcolour, &map[DEFAULT_PAPER][0], &map[DEFAULT_PAPER][1], &map[DEFAULT_PAPER][2], - &alpha[1])) { + if (zint_out_colour_get_rgb(symbol->bgcolour, &map[DEFAULT_PAPER][0], &map[DEFAULT_PAPER][1], + &map[DEFAULT_PAPER][2], &alpha[1])) { plot_alpha = 1; } @@ -113,7 +113,7 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf } if (!(symbol->bitmap = (unsigned char *) raster_malloc(bm_bitmap_size, 0 /*prev_size*/))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 661, "Insufficient memory for bitmap buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 661, "Insufficient memory for bitmap buffer"); } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ memset(symbol->bitmap, 0, bm_bitmap_size); @@ -122,7 +122,7 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf if (plot_alpha) { const size_t alpha_size = (size_t) symbol->bitmap_width * symbol->bitmap_height; if (!(symbol->alphamap = (unsigned char *) raster_malloc(alpha_size, bm_bitmap_size))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 662, "Insufficient memory for alphamap buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 662, "Insufficient memory for alphamap buffer"); } for (row = 0; row < symbol->bitmap_height; row++) { size_t p = (size_t) symbol->bitmap_width * row; @@ -183,7 +183,7 @@ static int save_raster_image_to_file(struct zint_symbol *symbol, const int image if (rotate_angle) { size_t image_size = (size_t) image_width * image_height; if (!(rotated_pixbuf = (unsigned char *) raster_malloc((size_t) image_size, 0 /*prev_size*/))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 650, "Insufficient memory for pixel buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 650, "Insufficient memory for pixel buffer"); } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ memset(rotated_pixbuf, DEFAULT_PAPER, image_size); @@ -244,7 +244,7 @@ static int save_raster_image_to_file(struct zint_symbol *symbol, const int image break; case OUT_PNG_FILE: #ifndef ZINT_NO_PNG - error_number = png_pixel_plot(symbol, rotated_pixbuf); + error_number = zint_png_pixel_plot(symbol, rotated_pixbuf); #else error_number = ZINT_ERROR_INVALID_OPTION; #endif @@ -255,16 +255,16 @@ static int save_raster_image_to_file(struct zint_symbol *symbol, const int image #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif case OUT_PCX_FILE: - error_number = pcx_pixel_plot(symbol, rotated_pixbuf); + error_number = zint_pcx_pixel_plot(symbol, rotated_pixbuf); break; case OUT_GIF_FILE: - error_number = gif_pixel_plot(symbol, rotated_pixbuf); + error_number = zint_gif_pixel_plot(symbol, rotated_pixbuf); break; case OUT_TIF_FILE: - error_number = tif_pixel_plot(symbol, rotated_pixbuf); + error_number = zint_tif_pixel_plot(symbol, rotated_pixbuf); break; default: - error_number = bmp_pixel_plot(symbol, rotated_pixbuf); + error_number = zint_bmp_pixel_plot(symbol, rotated_pixbuf); break; #if defined(__GNUC__) && !defined(__clang__) && defined(NDEBUG) && defined(ZINT_NO_PNG) #pragma GCC diagnostic pop @@ -460,7 +460,7 @@ static void draw_string(unsigned char *pixelbuf, const unsigned char input_strin letter_width += letter_gap; if (length == -1) { - length = (int) ustrlen(input_string); + length = (int) z_ustrlen(input_string); } if (textflags & ZFONT_HALIGN_LEFT) { @@ -688,7 +688,7 @@ static void draw_bind_box(const struct zint_symbol *symbol, unsigned char *pixel if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND | BARCODE_BIND_TOP))) { const int no_extend = symbol->symbology == BARCODE_CODABLOCKF || symbol->symbology == BARCODE_HIBC_BLOCKF || symbol->symbology == BARCODE_DPD; - const int horz_outside = is_fixed_ratio(symbol->symbology); + const int horz_outside = z_is_fixed_ratio(symbol->symbology); const int bwidth_si = symbol->border_width * si; int ybind_top = yoffset_si - bwidth_si; int ybind_bot = yoffset_si + symbol_height_si + dot_overspill_si; @@ -757,8 +757,9 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang } scaler *= 10.0f; - out_set_whitespace_offsets(symbol, 0 /*hide_text*/, 0 /*comp_xoffset*/, &xoffset, &yoffset, &roffset, &boffset, - NULL /*qz_right*/, scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, NULL /*qz_right_si*/); + zint_out_set_whitespace_offsets(symbol, 0 /*hide_text*/, 0 /*comp_xoffset*/, &xoffset, &yoffset, &roffset, + &boffset, NULL /*qz_right*/, scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, + NULL /*qz_right_si*/); hex_width = (int) roundf(scaler); /* Short diameter, X in ISO/IEC 16023:2000 Figure 8 (same as W) */ hex_height = (int) roundf(scaler * two_div_sqrt3); /* Long diameter, V in Figure 8 */ @@ -786,14 +787,14 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang image_size = (size_t) image_width * image_height; if (!(pixelbuf = (unsigned char *) raster_malloc(image_size, 0 /*prev_size*/))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 655, "Insufficient memory for pixel buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 655, "Insufficient memory for pixel buffer"); } memset(pixelbuf, DEFAULT_PAPER, image_size); hex_size = (size_t) hex_width * hex_height; if (!(scaled_hexagon = (unsigned char *) raster_malloc(hex_size, image_size))) { free(pixelbuf); - return errtxt(ZINT_ERROR_MEMORY, symbol, 656, "Insufficient memory for pixel buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 656, "Insufficient memory for pixel buffer"); } memset(scaled_hexagon, DEFAULT_PAPER, hex_size); @@ -805,7 +806,7 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang const int xposn_offset = (odd_row ? hex_width / 2 : 0) + xoffset_si - hx_start; for (column = 0; column < symbol->width - odd_row; column++) { const int xposn = column * hex_width + xposn_offset; - if (module_is_set(symbol, row, column)) { + if (z_module_is_set(symbol, row, column)) { draw_hexagon(pixelbuf, image_width, image_height, scaled_hexagon, hex_width, hex_height, xposn, yposn); } @@ -829,7 +830,7 @@ static int plot_raster_maxicode(struct zint_symbol *symbol, const int rotate_ang const float max_ratio = 1.177984f; /* 27.93 / 23.71 */ const float size_ratio = (float) hex_image_width / hex_image_height; if (size_ratio < min_ratio || size_ratio > max_ratio) { - return errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 663, "Size not within the minimum/maximum ranges"); + return z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 663, "Size not within the minimum/maximum ranges"); } } return error_number; @@ -857,8 +858,9 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle, dot_radius_s = (symbol->dot_size * scaler) / 2.0f; dot_radius_si = (int) dot_radius_s; - out_set_whitespace_offsets(symbol, 0 /*hide_text*/, 0 /*comp_xoffset*/, &xoffset, &yoffset, &roffset, &boffset, - NULL /*qz_right*/, scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, NULL /*qz_right_si*/); + zint_out_set_whitespace_offsets(symbol, 0 /*hide_text*/, 0 /*comp_xoffset*/, &xoffset, &yoffset, &roffset, + &boffset, NULL /*qz_right*/, scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, + NULL /*qz_right_si*/); /* TODO: Revisit this overspill stuff, it's hacky */ if (symbol->dot_size < 1.0f) { @@ -879,7 +881,7 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle, /* Apply scale options by creating pixel buffer */ if (!(scaled_pixelbuf = (unsigned char *) raster_malloc(scale_size, 0 /*prev_size*/))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 657, "Insufficient memory for pixel buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 657, "Insufficient memory for pixel buffer"); } memset(scaled_pixelbuf, DEFAULT_PAPER, scale_size); @@ -887,7 +889,7 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle, for (r = 0; r < symbol->rows; r++) { int row_si = (int) (r * scaler + yoffset_si + dot_offset_s); for (i = 0; i < symbol->width; i++) { - if (module_is_set(symbol, r, i)) { + if (z_module_is_set(symbol, r, i)) { draw_circle(scaled_pixelbuf, scale_width, scale_height, (int) (i * scaler + xoffset_si + dot_offset_s), row_si, dot_radius_si, DEFAULT_INK); @@ -911,7 +913,7 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle, static void to_iso8859_1(const unsigned char source[], unsigned char preprocessed[]) { int j, i, input_length; - input_length = (int) ustrlen(source); + input_length = (int) z_ustrlen(source); j = 0; i = 0; @@ -985,29 +987,29 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl scaler = 0.5f; } /* If half-integer scaling, then set integer scaler `si` to avoid scaling at end */ - half_int_scaling = isfintf(scaler * 2.0f); + half_int_scaling = z_isfintf(scaler * 2.0f); if (half_int_scaling) { si = (int) (scaler * 2.0f); } else { si = 2; } - (void) out_large_bar_height(symbol, si /*(scale and round)*/, row_heights_si, &symbol_height_si); + (void) zint_out_large_bar_height(symbol, si /*(scale and round)*/, row_heights_si, &symbol_height_si); main_width = symbol->width; - if (is_composite(symbol->symbology)) { - while (!module_is_set(symbol, symbol->rows - 1, comp_xoffset)) { + if (z_is_composite(symbol->symbology)) { + while (!z_module_is_set(symbol, symbol->rows - 1, comp_xoffset)) { comp_xoffset++; } } - if (is_upcean(symbol->symbology)) { - upceanflag = out_process_upcean(symbol, comp_xoffset, &main_width, addon, &addon_len, &addon_gap); + if (z_is_upcean(symbol->symbology)) { + upceanflag = zint_out_process_upcean(symbol, comp_xoffset, &main_width, addon, &addon_len, &addon_gap); } hide_text = !symbol->show_hrt || symbol->text_length == 0 || scaler < 1.0f; - out_set_whitespace_offsets(symbol, hide_text, comp_xoffset, &xoffset, &yoffset, &roffset, &boffset, + zint_out_set_whitespace_offsets(symbol, hide_text, comp_xoffset, &xoffset, &yoffset, &roffset, &boffset, NULL /*qz_right*/, si, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, &qz_right_si); xoffset_comp_si = xoffset_si + comp_xoffset * si; @@ -1044,7 +1046,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl image_size = (size_t) image_width * image_height; if (!(pixelbuf = (unsigned char *) raster_malloc(image_size, 0 /*prev_size*/))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 658, "Insufficient memory for pixel buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 658, "Insufficient memory for pixel buffer"); } memset(pixelbuf, DEFAULT_PAPER, image_size); @@ -1056,9 +1058,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl const int row_height_si = row_heights_si[r]; for (i = 0; i < symbol->width; i += block_width) { - const int fill = module_colour_is_set(symbol, r, i); + const int fill = z_module_colour_is_set(symbol, r, i); for (block_width = 1; (i + block_width < symbol->width) - && module_colour_is_set(symbol, r, i + block_width) == fill; block_width++); + && z_module_colour_is_set(symbol, r, i + block_width) == fill; block_width++); if (fill) { /* a colour block */ draw_bar_line(pixelbuf, i * si + xoffset_si, block_width * si, yposn_si, image_width, @@ -1075,9 +1077,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl int row_height_si = row_heights_si[r]; for (i = 0; i < symbol->width; i += block_width) { - const int fill = module_is_set(symbol, r, i); + const int fill = z_module_is_set(symbol, r, i); for (block_width = 1; (i + block_width < symbol->width) - && module_is_set(symbol, r, i + block_width) == fill; block_width++); + && z_module_is_set(symbol, r, i + block_width) == fill; block_width++); if ((r == (symbol->rows - 1)) && (i > main_width) && (addon_latch == 0)) { int addon_row_height_si; const int addon_row_adj_si = (int) ceilf((font_height + symbol->text_gap) * si); @@ -1123,9 +1125,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl } for (i = 0; i < symbol->width; i += block_width) { - const int fill = module_is_set(symbol, r, i); + const int fill = z_module_is_set(symbol, r, i); for (block_width = 1; (i + block_width < symbol->width) - && module_is_set(symbol, r, i + block_width) == fill; block_width++); + && z_module_is_set(symbol, r, i + block_width) == fill; block_width++); if (fill) { /* a bar */ draw_bar_line(pixelbuf, i * si + xoffset_si, block_width * si, yposn_si, image_width, @@ -1160,9 +1162,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl } else if (upceanflag == 12) { /* UPC-A */ for (i = 0 + comp_xoffset; i < 11 + comp_xoffset; i += block_width) { - const int fill = module_is_set(symbol, symbol->rows - 1, i); + const int fill = z_module_is_set(symbol, symbol->rows - 1, i); for (block_width = 1; (i + block_width < symbol->width) - && module_is_set(symbol, symbol->rows - 1, i + block_width) == fill; + && z_module_is_set(symbol, symbol->rows - 1, i + block_width) == fill; block_width++); if (fill) { draw_bar_line(pixelbuf, i * si + xoffset_si, block_width * si, guard_yoffset_si, image_width, @@ -1172,9 +1174,9 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl draw_bar_line(pixelbuf, 46 * si + xoffset_comp_si, 1 * si, guard_yoffset_si, image_width, DEFAULT_INK); draw_bar_line(pixelbuf, 48 * si + xoffset_comp_si, 1 * si, guard_yoffset_si, image_width, DEFAULT_INK); for (i = 85 + comp_xoffset; i < 96 + comp_xoffset; i += block_width) { - const int fill = module_is_set(symbol, symbol->rows - 1, i); + const int fill = z_module_is_set(symbol, symbol->rows - 1, i); for (block_width = 1; (i + block_width < symbol->width) - && module_is_set(symbol, symbol->rows - 1, i + block_width) == fill; + && z_module_is_set(symbol, symbol->rows - 1, i + block_width) == fill; block_width++); if (fill) { draw_bar_line(pixelbuf, i * si + xoffset_si, block_width * si, guard_yoffset_si, image_width, @@ -1341,7 +1343,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl } /* Separator binding for stacked barcodes */ - if ((symbol->output_options & BARCODE_BIND) && symbol->rows > 1 && is_bindable(symbol->symbology)) { + if ((symbol->output_options & BARCODE_BIND) && symbol->rows > 1 && z_is_bindable(symbol->symbology)) { int sep_xoffset_si = xoffset_si; int sep_width_si = symbol->width * si; int sep_height_si, sep_yoffset_si; @@ -1369,26 +1371,26 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl if (!half_int_scaling) { size_t prev_image_row; unsigned char *scaled_pixelbuf; - const int scale_width = (int) stripf(image_width * scaler); - const int scale_height = (int) stripf(image_height * scaler); + const int scale_width = (int) z_stripf(image_width * scaler); + const int scale_height = (int) z_stripf(image_height * scaler); /* Apply scale options by creating another pixel buffer */ if (!(scaled_pixelbuf = (unsigned char *) raster_malloc((size_t) scale_width * scale_height, image_size))) { free(pixelbuf); - return errtxt(ZINT_ERROR_MEMORY, symbol, 659, "Insufficient memory for scaled pixel buffer"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 659, "Insufficient memory for scaled pixel buffer"); } memset(scaled_pixelbuf, DEFAULT_PAPER, (size_t) scale_width * scale_height); /* Interpolate */ for (r = 0; r < scale_height; r++) { size_t scaled_row = (size_t) scale_width * r; - size_t image_row = (size_t) stripf(r / scaler) * image_width; + size_t image_row = (size_t) z_stripf(r / scaler) * image_width; if (r && (image_row == prev_image_row || memcmp(pixelbuf + image_row, pixelbuf + prev_image_row, image_width) == 0)) { memcpy(scaled_pixelbuf + scaled_row, scaled_pixelbuf + scaled_row - scale_width, scale_width); } else { for (i = 0; i < scale_width; i++) { - *(scaled_pixelbuf + scaled_row + i) = *(pixelbuf + image_row + (int) stripf(i / scaler)); + *(scaled_pixelbuf + scaled_row + i) = *(pixelbuf + image_row + (int) z_stripf(i / scaler)); } } prev_image_row = image_row; @@ -1410,21 +1412,21 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl return error_number ? error_number : warn_number; } -INTERNAL int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type) { +INTERNAL int zint_plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_type) { int error; #ifdef ZINT_NO_PNG if (file_type == OUT_PNG_FILE) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 660, "PNG format disabled at compile time"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 660, "PNG format disabled at compile time"); } #endif /* ZINT_NO_PNG */ - error = out_check_colour_options(symbol); + error = zint_out_check_colour_options(symbol); if (error != 0) { return error; } if (symbol->rows <= 0) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 664, "No rows"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 664, "No rows"); } if (symbol->symbology == BARCODE_MAXICODE) { diff --git a/backend/reedsol.c b/backend/reedsol.c index de8e47df..73e2c0e0 100644 --- a/backend/reedsol.c +++ b/backend/reedsol.c @@ -1,6 +1,10 @@ -/* This is a simple Reed-Solomon encoder */ /* - (C) Cliff Hones 2004 + This is a simple Reed-Solomon encoder + (C) Cliff Hones 2004 +*/ +/* + libzint - the open source barcode library + Copyright (C) 2009-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -30,24 +34,24 @@ /* SPDX-License-Identifier: BSD-3-Clause */ /* It is not written with high efficiency in mind, so is probably -// not suitable for real-time encoding. The aim was to keep it -// simple, general and clear. -// -// + not suitable for real-time encoding. The aim was to keep it + simple, general and clear. -// Usage: -// First call rs_init_gf(&rs, prime_poly) to set up the Galois Field parameters. -// Then call rs_init_code(&rs, nsym, index) to set the encoding size -// Then call rs_encode(&rs, datalen, data, out) to encode the data. -// -// These can be called repeatedly as required - but note that -// rs_init_code must be called following any rs_init_gf call. -// -// If the parameters are fixed, some of the statics below can be -// replaced with constants in the obvious way, and additionally -// malloc/free can be avoided by using static arrays of a suitable -// size. -// Note: use of statics has been done for (up to) 8-bit tables. + + + Usage: + First call rs_init_gf(&rs, prime_poly) to set up the Galois Field parameters. + Then call rs_init_code(&rs, nsym, index) to set the encoding size + Then call rs_encode(&rs, datalen, data, out) to encode the data. + + These can be called repeatedly as required - but note that + rs_init_code must be called following any rs_init_gf call. + + If the parameters are fixed, some of the statics below can be + replaced with constants in the obvious way, and additionally + malloc/free can be avoided by using static arrays of a suitable + size. + Note: use of statics has been done for (up to) 8-bit tables. */ #include "common.h" @@ -55,16 +59,16 @@ #include "reedsol_logs.h" /* rs_init_gf(&rs, prime_poly) initialises the parameters for the Galois Field. -// The symbol size is determined from the highest bit set in poly -// This implementation will support sizes up to 8 bits (see rs_uint_init_gf() -// for sizes > 8 bits and <= 30 bits) - bit sizes of 8 or 4 are typical -// -// The poly is the bit pattern representing the GF characteristic -// polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is -// a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d. + The symbol size is determined from the highest bit set in poly + This implementation will support sizes up to 8 bits (see rs_uint_init_gf() + for sizes > 8 bits and <= 30 bits) - bit sizes of 8 or 4 are typical + + The poly is the bit pattern representing the GF characteristic + polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is + a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d. */ -INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly) { +INTERNAL void zint_rs_init_gf(rs_t *rs, const unsigned int prime_poly) { struct item { const unsigned char *logt; const unsigned char *alog; @@ -96,14 +100,14 @@ INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly) { } /* rs_init_code(&rs, nsym, index) initialises the Reed-Solomon encoder -// nsym is the number of symbols to be generated (to be appended -// to the input data). index is usually 1 - it is the index of -// the constant in the first term (i) of the RS generator polynomial: -// (x + 2**i)*(x + 2**(i+1))*... [nsym terms] -// For ECC200, index is 1. + nsym is the number of symbols to be generated (to be appended + to the input data). index is usually 1 - it is the index of + the constant in the first term (i) of the RS generator polynomial: + (x + 2**i)*(x + 2**(i+1))*... [nsym terms] + For ECC200, index is 1. */ -INTERNAL void rs_init_code(rs_t *rs, const int nsym, int index) { +INTERNAL void zint_rs_init_code(rs_t *rs, const int nsym, int index) { int i, k; const unsigned char *const logt = rs->logt; const unsigned char *const alog = rs->alog; @@ -133,7 +137,7 @@ INTERNAL void rs_init_code(rs_t *rs, const int nsym, int index) { } /* rs_encode(&rs, datalen, data, res) generates nsym Reed-Solomon codes (nsym as given in rs_init_code()) */ -INTERNAL void rs_encode(const rs_t *rs, const int datalen, const unsigned char *data, unsigned char *res) { +INTERNAL void zint_rs_encode(const rs_t *rs, const int datalen, const unsigned char *data, unsigned char *res) { int i, k; const unsigned char *const logt = rs->logt; const unsigned char *const alog = rs->alog; @@ -185,7 +189,7 @@ INTERNAL void rs_encode(const rs_t *rs, const int datalen, const unsigned char * /* The same as above but for unsigned int data and result - Aztec code compatible */ -INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res) { +INTERNAL void zint_rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res) { int i, k; const unsigned char *const logt = rs->logt; const unsigned char *const alog = rs->alog; @@ -238,14 +242,14 @@ INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned i /* Versions of the above for bitlengths > 8 and <= 30 and unsigned int data and results - Aztec code compatible */ /* Usage: -// First call rs_uint_init_gf(&rs_uint, prime_poly, logmod) to set up the Galois Field parameters. -// Then call rs_uint_init_code(&rs_uint, nsym, index) to set the encoding size -// Then call rs_uint_encode(&rs_uint, datalen, data, out) to encode the data. -// Then call rs_uint_free(&rs_uint) to free the log tables. + First call rs_uint_init_gf(&rs_uint, prime_poly, logmod) to set up the Galois Field parameters. + Then call rs_uint_init_code(&rs_uint, nsym, index) to set the encoding size + Then call rs_uint_encode(&rs_uint, datalen, data, out) to encode the data. + Then call rs_uint_free(&rs_uint) to free the log tables. */ /* `logmod` (field characteristic) will be 2**bitlength - 1, eg 1023 for bitlength 10, 4095 for bitlength 12 */ -INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod) { +INTERNAL int zint_rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod) { int b, p, v; unsigned int *logt, *alog; @@ -276,7 +280,7 @@ INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, return 1; } -INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) { +INTERNAL void zint_rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) { int i, k; const unsigned int *const logt = rs_uint->logt; const unsigned int *const alog = rs_uint->alog; @@ -308,7 +312,7 @@ INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) { } } -INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data, +INTERNAL void zint_rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data, unsigned int *res) { int i, k; const unsigned int *const logt = rs_uint->logt; @@ -362,7 +366,7 @@ INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const } } -INTERNAL void rs_uint_free(rs_uint_t *rs_uint) { +INTERNAL void zint_rs_uint_free(rs_uint_t *rs_uint) { if (rs_uint->logt) { free(rs_uint->logt); rs_uint->logt = NULL; diff --git a/backend/reedsol.h b/backend/reedsol.h index 066ccaa8..5b4c5488 100644 --- a/backend/reedsol.h +++ b/backend/reedsol.h @@ -4,7 +4,7 @@ */ /* libzint - the open source barcode library - Copyright (C) 2009-2022 Robin Stuart + Copyright (C) 2009-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -59,17 +59,17 @@ typedef struct { int zero; /* Set if poly has a zero coeff */ } rs_uint_t; -INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly); -INTERNAL void rs_init_code(rs_t *rs, const int nsym, int index); -INTERNAL void rs_encode(const rs_t *rs, const int datalen, const unsigned char *data, unsigned char *res); -INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res); +INTERNAL void zint_rs_init_gf(rs_t *rs, const unsigned int prime_poly); +INTERNAL void zint_rs_init_code(rs_t *rs, const int nsym, int index); +INTERNAL void zint_rs_encode(const rs_t *rs, const int datalen, const unsigned char *data, unsigned char *res); +INTERNAL void zint_rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res); /* No free needed as log tables static */ -INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod); -INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index); -INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data, +INTERNAL int zint_rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod); +INTERNAL void zint_rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index); +INTERNAL void zint_rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data, unsigned int *res); -INTERNAL void rs_uint_free(rs_uint_t *rs_uint); +INTERNAL void zint_rs_uint_free(rs_uint_t *rs_uint); #ifdef __cplusplus } diff --git a/backend/rss.c b/backend/rss.c index 429abdc5..70ce78eb 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -186,7 +186,7 @@ static unsigned char *dbar_gtin14(const unsigned char *source, const int length, assert(zeroes >= 0); memset(buf, '0', zeroes); memcpy(buf + zeroes, source, length); - buf[zeroes + length] = gs1_check_digit(buf, 13); + buf[zeroes + length] = zint_gs1_check_digit(buf, 13); return buf; } @@ -195,8 +195,8 @@ static unsigned char *dbar_gtin14(const unsigned char *source, const int length, static void dbar_set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *source, const int length) { unsigned char buf[14]; - hrt_cpy_nochk(symbol, ZCUCP("(01)"), 4); - hrt_cat_nochk(symbol, dbar_gtin14(source, length, buf), 14); + z_hrt_cpy_nochk(symbol, ZCUCP("(01)"), 4); + z_hrt_cat_nochk(symbol, dbar_gtin14(source, length, buf), 14); } /* Expand from a width pattern to a bit pattern */ @@ -208,12 +208,12 @@ static int dbar_expand(struct zint_symbol *symbol, int writer, int latch, const const int width = widths[i]; if (latch) { for (j = 0; j < width; j++) { - set_module(symbol, symbol->rows, writer); + z_set_module(symbol, symbol->rows, writer); writer++; } } else { for (j = 0; j < width; j++) { - unset_module(symbol, symbol->rows, writer); + z_unset_module(symbol, symbol->rows, writer); writer++; } } @@ -235,16 +235,16 @@ static void dbar_omn_finder_adjust(struct zint_symbol *symbol, const int separat /* Alternation is always left-to-right for Omnidirectional separators (unlike for Expanded) */ latch = 1; for (i = finder_start, finder_end = finder_start + 13; i < finder_end; i++) { - if (!module_is_set(symbol, module_row, i)) { + if (!z_module_is_set(symbol, module_row, i)) { if (latch) { - set_module(symbol, separator_row, i); + z_set_module(symbol, separator_row, i); latch = 0; } else { - unset_module(symbol, separator_row, i); + z_unset_module(symbol, separator_row, i); latch = 1; } } else { - unset_module(symbol, separator_row, i); + z_unset_module(symbol, separator_row, i); latch = 1; } } @@ -257,8 +257,8 @@ static void dbar_omn_separator(struct zint_symbol *symbol, int width, const int int module_row = separator_row + above_below; for (i = 4, width -= 4; i < width; i++) { - if (!module_is_set(symbol, module_row, i)) { - set_module(symbol, separator_row, i); + if (!z_module_is_set(symbol, module_row, i)) { + z_set_module(symbol, separator_row, i); } } if (bottom_finder_value_3) { @@ -267,9 +267,9 @@ static void dbar_omn_separator(struct zint_symbol *symbol, int width, const int finder_value_3_set = finder_start + 10; for (i = finder_start, finder_end = finder_start + 13; i < finder_end; i++) { if (i == finder_value_3_set) { - set_module(symbol, separator_row, i); + z_set_module(symbol, separator_row, i); } else { - unset_module(symbol, separator_row, i); + z_unset_module(symbol, separator_row, i); } } } else { @@ -283,7 +283,7 @@ static void dbar_omn_separator(struct zint_symbol *symbol, int width, const int } /* Set Databar Stacked height, maintaining 5:7 ratio of the 2 main row heights */ -INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_row) { +INTERNAL int zint_dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_row) { float fixed_height = 0.0f; const int second_row = first_row + 2; /* 2 row separator */ int i; @@ -294,23 +294,24 @@ INTERNAL int dbar_omnstk_set_height(struct zint_symbol *symbol, const int first_ } } if (symbol->height) { - symbol->row_height[first_row] = stripf((symbol->height - fixed_height) * symbol->row_height[first_row] / + symbol->row_height[first_row] = z_stripf((symbol->height - fixed_height) * symbol->row_height[first_row] / (symbol->row_height[first_row] + symbol->row_height[second_row])); if (symbol->row_height[first_row] < 0.5f) { /* Absolute minimum */ symbol->row_height[first_row] = 0.5f; symbol->row_height[second_row] = 0.7f; } else { - symbol->row_height[second_row] = stripf(symbol->height - fixed_height - symbol->row_height[first_row]); + symbol->row_height[second_row] = z_stripf(symbol->height - fixed_height - symbol->row_height[first_row]); if (symbol->row_height[second_row] < 0.7f) { symbol->row_height[second_row] = 0.7f; } } } - symbol->height = stripf(stripf(symbol->row_height[first_row] + symbol->row_height[second_row]) + fixed_height); + symbol->height = z_stripf(z_stripf(symbol->row_height[first_row] + symbol->row_height[second_row]) + + fixed_height); if (symbol->output_options & COMPLIANT_HEIGHT) { if (symbol->row_height[first_row] < 5.0f || symbol->row_height[second_row] < 7.0f) { - return errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 379, "Height not compliant with standards"); + return z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 379, "Height not compliant with standards"); } } @@ -330,7 +331,7 @@ static int dbar_omn_group(const int val, const int outside) { } /* GS1 DataBar Omnidirectional/Truncated/Stacked/Stacked Omnidirectional, allowing for composite if `cc_rows` set */ -INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { +INTERNAL int zint_dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { int error_number = 0, i, j; uint64_t val; int left_pair, right_pair; @@ -349,17 +350,18 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int length -= 2; } if (length > 14) { /* Allow check digit to be specified (will be verified and ignored) */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 380, "Input length %d too long (maximum 14)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 380, "Input length %d too long (maximum 14)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 381, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 381, "Invalid character at position %d in input (digits only)", i); } if (length == 14) { /* Verify check digit */ - if (gs1_check_digit(source, 13) != source[13]) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 388, "Invalid check digit '%1$c', expecting '%2$c'", - source[13], gs1_check_digit(source, 13)); + if (zint_gs1_check_digit(source, 13) != source[13]) { + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 388, + "Invalid check digit '%1$c', expecting '%2$c'", + source[13], zint_gs1_check_digit(source, 13)); } length--; /* Ignore */ } @@ -471,46 +473,46 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int if (symbol->symbology == BARCODE_DBAR_OMN_CC) { symbol->height = symbol->height ? 13.0f : 33.0f; /* Pass back min row or default height */ } else { - error_number = set_height(symbol, 13.0f, 33.0f, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 13.0f, 33.0f, 0.0f, 0 /*no_errtxt*/); } } else { if (symbol->symbology == BARCODE_DBAR_OMN_CC) { symbol->height = 14.0f; /* 14X truncated min row height used (should be 13X) */ } 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*/); } } } else if (symbol->symbology == BARCODE_DBAR_STK || symbol->symbology == BARCODE_DBAR_STK_CC) { /* Top row */ writer = dbar_expand(symbol, 0 /*writer*/, 0 /*latch*/, total_widths, 0 /*start*/, 23 /*end*/); - set_module(symbol, symbol->rows, writer); - unset_module(symbol, symbol->rows, writer + 1); + z_set_module(symbol, symbol->rows, writer); + z_unset_module(symbol, symbol->rows, writer + 1); symbol->row_height[symbol->rows] = 5.0f; /* ISO/IEC 24724:2011 5.3.2.1 set to 5X */ /* Bottom row */ symbol->rows += 2; - set_module(symbol, symbol->rows, 0); - unset_module(symbol, symbol->rows, 1); + z_set_module(symbol, symbol->rows, 0); + z_unset_module(symbol, symbol->rows, 1); (void) dbar_expand(symbol, 2 /*writer*/, 1 /*latch*/, total_widths, 23 /*start*/, 46 /*end*/); symbol->row_height[symbol->rows] = 7.0f; /* ISO/IEC 24724:2011 5.3.2.1 set to 7X */ /* Separator pattern */ /* See #183 for this interpretation of ISO/IEC 24724:2011 5.3.2.1 */ for (i = 1; i < 46; i++) { - if (module_is_set(symbol, symbol->rows - 2, i) == module_is_set(symbol, symbol->rows, i)) { - if (!(module_is_set(symbol, symbol->rows - 2, i))) { - set_module(symbol, symbol->rows - 1, i); + if (z_module_is_set(symbol, symbol->rows - 2, i) == z_module_is_set(symbol, symbol->rows, i)) { + if (!(z_module_is_set(symbol, symbol->rows - 2, i))) { + z_set_module(symbol, symbol->rows - 1, i); } } else { - if (!(module_is_set(symbol, symbol->rows - 1, i - 1))) { - set_module(symbol, symbol->rows - 1, i); + if (!(z_module_is_set(symbol, symbol->rows - 1, i - 1))) { + z_set_module(symbol, symbol->rows - 1, i); } } } - unset_module(symbol, symbol->rows - 1, 1); - unset_module(symbol, symbol->rows - 1, 2); - unset_module(symbol, symbol->rows - 1, 3); + z_unset_module(symbol, symbol->rows - 1, 1); + z_unset_module(symbol, symbol->rows - 1, 2); + z_unset_module(symbol, symbol->rows - 1, 3); symbol->row_height[symbol->rows - 1] = 1; if (symbol->symbology == BARCODE_DBAR_STK_CC) { @@ -522,25 +524,25 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int symbol->width = 50; } - if (symbol->symbology != BARCODE_DBAR_STK_CC) { /* Composite calls dbar_omnstk_set_height() itself */ - error_number = dbar_omnstk_set_height(symbol, 0 /*first_row*/); + if (symbol->symbology != BARCODE_DBAR_STK_CC) { /* Composite calls `zint_dbar_omnstk_set_height()` itself */ + error_number = zint_dbar_omnstk_set_height(symbol, 0 /*first_row*/); } } else if (symbol->symbology == BARCODE_DBAR_OMNSTK || symbol->symbology == BARCODE_DBAR_OMNSTK_CC) { /* Top row */ writer = dbar_expand(symbol, 0 /*writer*/, 0 /*latch*/, total_widths, 0 /*start*/, 23 /*end*/); - set_module(symbol, symbol->rows, writer); - unset_module(symbol, symbol->rows, writer + 1); + z_set_module(symbol, symbol->rows, writer); + z_unset_module(symbol, symbol->rows, writer + 1); /* Bottom row */ symbol->rows += 4; - set_module(symbol, symbol->rows, 0); - unset_module(symbol, symbol->rows, 1); + z_set_module(symbol, symbol->rows, 0); + z_unset_module(symbol, symbol->rows, 1); (void) dbar_expand(symbol, 2 /*writer*/, 1 /*latch*/, total_widths, 23 /*start*/, 46 /*end*/); /* Middle separator */ for (i = 5; i < 46; i += 2) { - set_module(symbol, symbol->rows - 2, i); + z_set_module(symbol, symbol->rows - 2, i); } symbol->row_height[symbol->rows - 2] = 1; @@ -567,17 +569,17 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int symbol->height = symbol->height ? 33.0f : 66.0f; /* Pass back min row or default height */ } else { if (symbol->output_options & COMPLIANT_HEIGHT) { - error_number = set_height(symbol, 33.0f, 66.0f, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 33.0f, 66.0f, 0.0f, 0 /*no_errtxt*/); } else { - (void) set_height(symbol, 0.0f, 66.0f, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 66.0f, 0.0f, 1 /*no_errtxt*/); } } } if (raw_text) { unsigned char buf[14]; - if (rt_cpy_cat(symbol, ZCUCP("01"), 2, '\xFF' /*none*/, dbar_gtin14(source, length, buf), 14)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (z_rt_cpy_cat(symbol, ZCUCP("01"), 2, '\xFF' /*none*/, dbar_gtin14(source, length, buf), 14)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } } @@ -585,8 +587,8 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int } /* GS1 DataBar Omnidirectional/Truncated/Stacked */ -INTERNAL int dbar_omn(struct zint_symbol *symbol, unsigned char source[], int length) { - return dbar_omn_cc(symbol, source, length, 0 /*cc_rows*/); +INTERNAL int zint_dbar_omn(struct zint_symbol *symbol, unsigned char source[], int length) { + return zint_dbar_omn_cc(symbol, source, length, 0 /*cc_rows*/); } /* DataBar Limited stuff */ @@ -607,7 +609,7 @@ static int dbar_ltd_group(int *p_val) { } /* GS1 DataBar Limited, allowing for composite if `cc_rows` set */ -INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { +INTERNAL int zint_dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { int error_number = 0, i; uint64_t val; int pair_vals[2]; @@ -627,24 +629,25 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int length -= 2; } if (length > 14) { /* Allow check digit to be specified (will be verified and ignored) */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 382, "Input length %d too long (maximum 14)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 382, "Input length %d too long (maximum 14)", length); } - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 383, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 383, "Invalid character at position %d in input (digits only)", i); } if (length == 14) { /* Verify check digit */ - if (gs1_check_digit(source, 13) != source[13]) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 389, "Invalid check digit '%1$c', expecting '%2$c'", - source[13], gs1_check_digit(source, 13)); + if (zint_gs1_check_digit(source, 13) != source[13]) { + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 389, + "Invalid check digit '%1$c', expecting '%2$c'", + source[13], zint_gs1_check_digit(source, 13)); } length--; /* Ignore */ } if (length == 13) { if (source[0] != '0' && source[0] != '1') { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 384, "Input value out of range (0 to 1999999999999)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 384, "Input value out of range (0 to 1999999999999)"); } } @@ -707,8 +710,8 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int /* Add separator pattern if composite symbol */ if (symbol->symbology == BARCODE_DBAR_LTD_CC) { for (i = 4; i < 70; i++) { - if (!module_is_set(symbol, separator_row + 1, i)) { - set_module(symbol, separator_row, i); + if (!z_module_is_set(symbol, separator_row + 1, i)) { + z_set_module(symbol, separator_row, i); } } } @@ -718,8 +721,8 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int if (raw_text) { unsigned char buf[14]; - if (rt_cpy_cat(symbol, ZCUCP("01"), 2, '\xFF' /*none*/, dbar_gtin14(source, length, buf), 14)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (z_rt_cpy_cat(symbol, ZCUCP("01"), 2, '\xFF' /*none*/, dbar_gtin14(source, length, buf), 14)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } } @@ -728,9 +731,9 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int symbol->height = 10.0f; /* Pass back min row == default height */ } else { if (symbol->output_options & COMPLIANT_HEIGHT) { - error_number = set_height(symbol, 10.0f, 10.0f, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, 10.0f, 10.0f, 0.0f, 0 /*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*/); } } @@ -738,22 +741,22 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int } /* GS1 DataBar Limited */ -INTERNAL int dbar_ltd(struct zint_symbol *symbol, unsigned char source[], int length) { - return dbar_ltd_cc(symbol, source, length, 0 /*cc_rows*/); +INTERNAL int zint_dbar_ltd(struct zint_symbol *symbol, unsigned char source[], int length) { + return zint_dbar_ltd_cc(symbol, source, length, 0 /*cc_rows*/); } /* DataBar Expanded stuff */ /* Check and convert date to DataBar Expanded date value */ -INTERNAL int dbar_exp_date(const unsigned char source[], const int length, const int position) { +INTERNAL int zint_dbar_exp_date(const unsigned char source[], const int length, const int position) { int yy, mm, dd; if (position + 4 + 2 > length) { return -1; } - yy = to_int(source + position, 2); - mm = to_int(source + position + 2, 2); - dd = to_int(source + position + 4, 2); + yy = z_to_int(source + position, 2); + mm = z_to_int(source + position + 2, 2); + dd = z_to_int(source + position + 4, 2); /* Month can't be zero but day can (means last day of month, GS1 General Specifications Sections 3.4.2 to 3.4.7) */ @@ -766,7 +769,7 @@ INTERNAL int dbar_exp_date(const unsigned char source[], const int length, const /* Handles all data encodation for DataBar Expanded, section 7.2.5 of ISO/IEC 24724:2011 */ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned char source[], const int length, char binary_string[], int *p_cols_per_row, const int max_rows, int *p_bp) { - int encoding_method, i, j, read_posn, mode = NUMERIC; + int encoding_method, i, j, read_posn, mode = GF_NUMERIC; char last_digit = '\0'; int symbol_characters, characters_per_row = *p_cols_per_row * 2; int min_cols_per_row = 0; @@ -778,7 +781,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha if (length > 77) { /* ISO/IEC 24724:2011 4.2.d.2 */ /* Caught below anyway but catch here also for better feedback */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 378, "Processed input length %d too long (maximum 77)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 378, "Processed input length %d too long (maximum 77)", length); } /* Decide whether a compressed data field is required and if so what @@ -803,7 +806,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha /* Methods 3, 7, 9, 11 and 13 */ /* (01) and (310x) */ - int weight = to_int(source + 20, 6); + int weight = z_to_int(source + 20, 6); /* Maximum weight = 99999 for 7 to 14 (ISO/IEC 24724:2011 7.2.5.4.4) */ if (weight >= 0 && weight <= 99999) { @@ -819,7 +822,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha } else if (length == 34 && source[26] == '1' && (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') - && dbar_exp_date(source, length, 28) >= 0) { + && zint_dbar_exp_date(source, length, 28) >= 0) { /* (01), (310x) and (11) - metric weight and production date */ /* (01), (310x) and (13) - metric weight and packaging date */ @@ -833,7 +836,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha /* Methods 4, 8, 10, 12 and 14 */ /* (01) and (320x) */ - int weight = to_int(source + 20, 6); + int weight = z_to_int(source + 20, 6); /* Maximum weight = 99999 for 7 to 14 (ISO/IEC 24724:2011 7.2.5.4.4) */ if (weight >= 0 && weight <= 99999) { @@ -850,7 +853,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha } else if (length == 34 && source[26] == '1' && (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') - && dbar_exp_date(source, length, 28) >= 0) { + && zint_dbar_exp_date(source, length, 28) >= 0) { /* (01), (320x) and (11) - English weight and production date */ /* (01), (320x) and (13) - English weight and packaging date */ @@ -865,7 +868,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha if (source[18] == '2') { /* (01) and (392x) */ encoding_method = 5; - } else if (source[18] == '3' && to_int(source + 20, 3) >= 0) { /* Check 3-digit currency string */ + } else if (source[18] == '3' && z_to_int(source + 20, 3) >= 0) { /* Check 3-digit currency string */ /* (01) and (393x) */ encoding_method = 6; } @@ -876,28 +879,28 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha switch (encoding_method) { /* Encoding method - Table 10 */ case 1: - bp = bin_append_posn(4, 3, binary_string, bp); /* "1XX" */ + bp = z_bin_append_posn(4, 3, binary_string, bp); /* "1XX" */ read_posn = 16; break; case 2: - bp = bin_append_posn(0, 4, binary_string, bp); /* "00XX" */ + bp = z_bin_append_posn(0, 4, binary_string, bp); /* "00XX" */ read_posn = 0; break; case 3: /* 0100 */ case 4: /* 0101 */ - bp = bin_append_posn(4 + (encoding_method - 3), 4, binary_string, bp); + bp = z_bin_append_posn(4 + (encoding_method - 3), 4, binary_string, bp); read_posn = 26; break; case 5: - bp = bin_append_posn(0x30, 7, binary_string, bp); /* "01100XX" */ + bp = z_bin_append_posn(0x30, 7, binary_string, bp); /* "01100XX" */ read_posn = 20; break; case 6: - bp = bin_append_posn(0x34, 7, binary_string, bp); /* "01101XX" */ + bp = z_bin_append_posn(0x34, 7, binary_string, bp); /* "01101XX" */ read_posn = 23; break; default: /* Modes 7 to 14 */ - bp = bin_append_posn(56 + (encoding_method - 7), 7, binary_string, bp); + bp = z_bin_append_posn(56 + (encoding_method - 7), 7, binary_string, bp); read_posn = length; /* 34 or 26 */ break; } @@ -910,7 +913,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha for (i = 0; i < read_posn; i++) { if (!z_isdigit(source[i]) && source[i] != '\x1D') { /* Something is wrong */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 385, + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 385, "Invalid character in Compressed Field data (digits only)"); } } @@ -923,10 +926,10 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha if (encoding_method == 1) { /* Encoding method field "1" - general item identification data */ - bp = bin_append_posn(ctoi(source[2]), 4, binary_string, bp); /* Leading digit after stripped "01" */ + bp = z_bin_append_posn(z_ctoi(source[2]), 4, binary_string, bp); /* Leading digit after stripped "01" */ for (i = 3; i < 15; i += 3) { /* Next 12 digits, excluding final check digit */ - bp = bin_append_posn(to_int(source + i, 3), 10, binary_string, bp); + bp = z_bin_append_posn(z_to_int(source + i, 3), 10, binary_string, bp); } } else if (encoding_method == 3 || encoding_method == 4) { @@ -934,13 +937,13 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha /* Encoding method field "0101" - variable weight item (0,01 or 0,001 pound increment) */ for (i = 3; i < 15; i += 3) { /* Leading "019" stripped, and final check digit excluded */ - bp = bin_append_posn(to_int(source + i, 3), 10, binary_string, bp); + bp = z_bin_append_posn(z_to_int(source + i, 3), 10, binary_string, bp); } if (encoding_method == 4 && source[19] == '3') { - bp = bin_append_posn(to_int(source + 20, 6) + 10000, 15, binary_string, bp); + bp = z_bin_append_posn(z_to_int(source + 20, 6) + 10000, 15, binary_string, bp); } else { - bp = bin_append_posn(to_int(source + 20, 6), 15, binary_string, bp); + bp = z_bin_append_posn(z_to_int(source + 20, 6), 15, binary_string, bp); } } else if (encoding_method == 5 || encoding_method == 6) { @@ -948,13 +951,13 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha /* Encoding method "01101" - variable measure item and price with ISO 4217 Currency Code */ for (i = 3; i < 15; i += 3) { /* Leading "019" stripped, and final check digit excluded */ - bp = bin_append_posn(to_int(source + i, 3), 10, binary_string, bp); + bp = z_bin_append_posn(z_to_int(source + i, 3), 10, binary_string, bp); } - bp = bin_append_posn(source[19] - '0', 2, binary_string, bp); /* 0-3 x of 392x/393x */ + bp = z_bin_append_posn(source[19] - '0', 2, binary_string, bp); /* 0-3 x of 392x/393x */ if (encoding_method == 6) { - bp = bin_append_posn(to_int(source + 20, 3), 10, binary_string, bp); /* 3-digit currency */ + bp = z_bin_append_posn(z_to_int(source + 20, 3), 10, binary_string, bp); /* 3-digit currency */ } } else if (encoding_method >= 7 && encoding_method <= 14) { @@ -963,7 +966,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha unsigned char weight_str[7]; for (i = 3; i < 15; i += 3) { /* Leading "019" stripped, and final check digit excluded */ - bp = bin_append_posn(to_int(source + i, 3), 10, binary_string, bp); + bp = z_bin_append_posn(z_to_int(source + i, 3), 10, binary_string, bp); } weight_str[0] = source[19]; /* 0-9 x of 310x/320x */ @@ -973,16 +976,16 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha } weight_str[6] = '\0'; - bp = bin_append_posn(to_int(weight_str, 6), 20, binary_string, bp); + bp = z_bin_append_posn(z_to_int(weight_str, 6), 20, binary_string, bp); if (length == 34) { /* Date information is included */ - group_val = dbar_exp_date(source, length, 28); + group_val = zint_dbar_exp_date(source, length, 28); } else { group_val = 38400; } - bp = bin_append_posn((int) group_val, 16, binary_string, bp); + bp = z_bin_append_posn((int) group_val, 16, binary_string, bp); } if (debug_print && bp > cdf_bp_start) { @@ -1002,9 +1005,9 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha if (j != 0) { /* If general field not empty */ general_field[j] = '\0'; - if (!general_field_encode(general_field, j, &mode, &last_digit, binary_string, &bp)) { + if (!zint_general_field_encode(general_field, j, &mode, &last_digit, binary_string, &bp)) { /* Will happen if character not in CSET 82 + space */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 386, "Invalid character in General Field data"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 386, "Invalid character in General Field data"); } } @@ -1038,10 +1041,10 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha if (debug_print) fputs("Adding extra (odd) numeric digit\n", stdout); if (remainder >= 4 && remainder <= 6) { - bp = bin_append_posn(ctoi(last_digit) + 1, 4, binary_string, bp); /* 7.2.5.5.1 (c) (2) */ + bp = z_bin_append_posn(z_ctoi(last_digit) + 1, 4, binary_string, bp); /* 7.2.5.5.1 (c) (2) */ } else { /* 7.2.5.5.1 (c) (1) */ - bp = bin_append_posn(ctoi(last_digit) * 11 + 10 /*FNC1*/ + 8, 7, binary_string, bp); + bp = z_bin_append_posn(z_ctoi(last_digit) * 11 + 10 /*FNC1*/ + 8, 7, binary_string, bp); } remainder = 12 - (bp % 12); @@ -1071,7 +1074,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha } if (bp > 252) { /* 252 = (21 * 12) */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 387, /* TODO: Better error message */ + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 387, /* TODO: Better error message */ "Input too long, requires %d symbol characters (maximum 21)", (bp + 11) / 12); } @@ -1081,12 +1084,12 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha /* Now add padding to binary string (7.2.5.5.4) */ i = remainder; - if (mode == NUMERIC) { - bp = bin_append_posn(0, 4, binary_string, bp); /* "0000" */ + if (mode == GF_NUMERIC) { + bp = z_bin_append_posn(0, 4, binary_string, bp); /* "0000" */ i -= 4; } for (; i > 0; i -= 5) { - bp = bin_append_posn(4, 5, binary_string, bp); /* "00100" */ + bp = z_bin_append_posn(4, 5, binary_string, bp); /* "00100" */ } if (encoding_method == 1 || encoding_method == 2 || encoding_method == 5 || encoding_method == 6) { @@ -1126,10 +1129,10 @@ static void dbar_exp_separator(struct zint_symbol *symbol, int width, const int int space_latch = 0; for (j = 4 + special_case_row, width -= 4; j < width; j++) { - if (module_is_set(symbol, module_row, j)) { - unset_module(symbol, separator_row, j); + if (z_module_is_set(symbol, module_row, j)) { + z_unset_module(symbol, separator_row, j); } else { - set_module(symbol, separator_row, j); + z_set_module(symbol, separator_row, j); } } @@ -1142,14 +1145,14 @@ static void dbar_exp_separator(struct zint_symbol *symbol, int width, const int i_start = v2_latch ? 2 : 0; i_end = v2_latch ? 15 : 13; for (i = i_start; i < i_end; i++) { - if (module_is_set(symbol, module_row, i + k)) { - unset_module(symbol, separator_row, i + k); + if (z_module_is_set(symbol, module_row, i + k)) { + z_unset_module(symbol, separator_row, i + k); space_latch = 0; } else { if (space_latch) { - unset_module(symbol, separator_row, i + k); + z_unset_module(symbol, separator_row, i + k); } else { - set_module(symbol, separator_row, i + k); + z_set_module(symbol, separator_row, i + k); } space_latch = !space_latch; } @@ -1162,14 +1165,14 @@ static void dbar_exp_separator(struct zint_symbol *symbol, int width, const int i_start = v2_latch ? 14 : 12; i_end = v2_latch ? 2 : 0; for (i = i_start; i >= i_end; i--) { - if (module_is_set(symbol, module_row, i + k)) { - unset_module(symbol, separator_row, i + k); + if (z_module_is_set(symbol, module_row, i + k)) { + z_unset_module(symbol, separator_row, i + k); space_latch = 0; } else { if (space_latch) { - unset_module(symbol, separator_row, i + k); + z_unset_module(symbol, separator_row, i + k); } else { - set_module(symbol, separator_row, i + k); + z_set_module(symbol, separator_row, i + k); } space_latch = !space_latch; } @@ -1188,9 +1191,9 @@ static void dbar_exp_hrt(struct zint_symbol *symbol, unsigned char source[], con /* Max possible length is 77 digits so will fit */ if (symbol->input_mode & GS1PARENS_MODE) { - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); } else { - hrt_conv_gs1_brackets_nochk(symbol, source, length); + z_hrt_conv_gs1_brackets_nochk(symbol, source, length); } } @@ -1206,7 +1209,7 @@ static int dbar_exp_group(const int val) { } /* GS1 DataBar Expanded, setting linkage for composite if `cc_rows` set */ -INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { +INTERNAL int zint_dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { int error_number, warn_number; int i, j, p, codeblocks, data_chars, symbol_chars, group; int char_widths[21][8], checksum, check_widths[8]; @@ -1223,7 +1226,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; - error_number = gs1_verify(symbol, source, &length, reduced, &reduced_length); + error_number = zint_gs1_verify(symbol, source, &length, reduced, &reduced_length); if (error_number >= ZINT_ERROR) { return error_number; } @@ -1377,8 +1380,8 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int dbar_exp_hrt(symbol, source, length); - if (raw_text && rt_cpy(symbol, reduced, reduced_length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, reduced, reduced_length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } } else { @@ -1465,7 +1468,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int /* Middle separator pattern (above current row) */ for (j = 5; j < (49 * cols_per_row); j += 2) { - set_module(symbol, symbol->rows - 2, j); + z_set_module(symbol, symbol->rows - 2, j); } symbol->row_height[symbol->rows - 2] = 1; @@ -1486,8 +1489,8 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int } symbol->rows -= 3; - if (raw_text && rt_cpy(symbol, reduced, reduced_length)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (raw_text && z_rt_cpy(symbol, reduced, reduced_length)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } } @@ -1504,12 +1507,12 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int } else { if (symbol->output_options & COMPLIANT_HEIGHT) { if (warn_number == 0) { - warn_number = set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/); + warn_number = z_set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/); } else { - (void) set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/); } } else { - (void) set_height(symbol, 0.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/); } } @@ -1517,8 +1520,8 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int } /* GS1 DataBar Expanded */ -INTERNAL int dbar_exp(struct zint_symbol *symbol, unsigned char source[], int length) { - return dbar_exp_cc(symbol, source, length, 0 /*cc_rows*/); +INTERNAL int zint_dbar_exp(struct zint_symbol *symbol, unsigned char source[], int length) { + return zint_dbar_exp_cc(symbol, source, length, 0 /*cc_rows*/); } /* vim: set ts=4 sw=4 et : */ diff --git a/backend/svg.c b/backend/svg.c index 048e6fb8..3967957f 100644 --- a/backend/svg.c +++ b/backend/svg.c @@ -97,8 +97,8 @@ static void svg_make_html_friendly(const unsigned char *string, char *html_versi /* Helper to output floating point attribute */ static void svg_put_fattrib(const char *prefix, const int dp, const float val, struct filemem *fmp) { - fm_putsf(prefix, dp, val, fmp); - fm_putc('"', fmp); + zint_fm_putsf(prefix, dp, val, fmp); + zint_fm_putc('"', fmp); } /* Helper to output opacity attribute attribute and close tag (maybe) */ @@ -107,12 +107,12 @@ static void svg_put_opacity_close(const unsigned char alpha, const float val, co svg_put_fattrib(" opacity=\"", 3, val, fmp); } if (close) { - fm_putc('/', fmp); + zint_fm_putc('/', fmp); } - fm_puts(">\n", fmp); + zint_fm_puts(">\n", fmp); } -INTERNAL int svg_plot(struct zint_symbol *symbol) { +INTERNAL int zint_svg_plot(struct zint_symbol *symbol) { static const char normal_font_family[] = "Arimo"; static const char upcean_font_family[] = "OCRB"; struct filemem fm; @@ -135,15 +135,15 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { char colour_code[7]; int html_len; - const int upcean = is_upcean(symbol->symbology); + const int is_upcean = z_is_upcean(symbol->symbology); char *html_string; - (void) out_colour_get_rgb(symbol->fgcolour, &fgred, &fggreen, &fgblue, &fg_alpha); + (void) zint_out_colour_get_rgb(symbol->fgcolour, &fgred, &fggreen, &fgblue, &fg_alpha); if (fg_alpha != 0xff) { fg_alpha_opacity = fg_alpha / 255.0f; } sprintf(fgcolour_string, "%02X%02X%02X", fgred, fggreen, fgblue); - (void) out_colour_get_rgb(symbol->bgcolour, &bgred, &bggreen, &bgblue, &bg_alpha); + (void) zint_out_colour_get_rgb(symbol->bgcolour, &bgred, &bggreen, &bgblue, &bg_alpha); if (bg_alpha != 0xff) { bg_alpha_opacity = bg_alpha / 255.0f; } @@ -171,62 +171,62 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { /* Check for no created vector set */ /* E-Mail Christian Schmitz 2019-09-10: reason unknown Ticket #164 */ if (symbol->vector == NULL) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 681, "Vector header NULL"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 681, "Vector header NULL"); } - if (!fm_open(fmp, symbol, "w")) { - return ZEXT errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 680, "Could not open SVG output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_open(fmp, symbol, "w")) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 680, "Could not open SVG output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } /* Start writing the header */ - fm_puts("\n" + zint_fm_puts("\n" "\n", fmp); - fm_printf(fmp, "\n", - (int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height)); - fm_puts(" Zint Generated Symbol\n", fmp); + zint_fm_printf(fmp, "\n", + (int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height)); + zint_fm_puts(" Zint Generated Symbol\n", fmp); if ((symbol->output_options & EMBED_VECTOR_FONT) && symbol->vector->strings) { /* Split into `puts()` rather than one very large `printf()` */ - fm_printf(fmp, " \n", fmp); + zint_fm_printf(fmp, " \n", fmp); } - fm_printf(fmp, " \n", fgcolour_string); + zint_fm_printf(fmp, " \n", fgcolour_string); if (bg_alpha != 0) { - fm_printf(fmp, " vector->width), (int) ceilf(symbol->vector->height), bgcolour_string); + zint_fm_printf(fmp, " vector->width), (int) ceilf(symbol->vector->height), bgcolour_string); svg_put_opacity_close(bg_alpha, bg_alpha_opacity, 1 /*close*/, fmp); } if (symbol->vector->rectangles) { int current_colour = 0; rect = symbol->vector->rectangles; - fm_puts(" colour != current_colour) { - fm_putc('"', fmp); + zint_fm_putc('"', fmp); if (current_colour != -1) { svg_pick_colour(current_colour, colour_code); - fm_printf(fmp, " fill=\"#%s\"", colour_code); + zint_fm_printf(fmp, " fill=\"#%s\"", colour_code); } svg_put_opacity_close(fg_alpha, fg_alpha_opacity, 1 /*close*/, fmp); - fm_puts(" colour; - fm_putsf("M", 2, rect->x, fmp); - fm_putsf(" ", 2, rect->y, fmp); - fm_putsf("h", 2, rect->width, fmp); - fm_putsf("v", 2, rect->height, fmp); - fm_putsf("h-", 2, rect->width, fmp); - fm_puts("Z", fmp); + zint_fm_putsf("M", 2, rect->x, fmp); + zint_fm_putsf(" ", 2, rect->y, fmp); + zint_fm_putsf("h", 2, rect->width, fmp); + zint_fm_putsf("v", 2, rect->height, fmp); + zint_fm_putsf("h-", 2, rect->width, fmp); + zint_fm_puts("Z", fmp); rect = rect->next; } - fm_putc('"', fmp); + zint_fm_putc('"', fmp); if (current_colour != -1) { svg_pick_colour(current_colour, colour_code); - fm_printf(fmp, " fill=\"#%s\"", colour_code); + zint_fm_printf(fmp, " fill=\"#%s\"", colour_code); } svg_put_opacity_close(fg_alpha, fg_alpha_opacity, 1 /*close*/, fmp); } @@ -234,7 +234,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { if (symbol->vector->hexagons) { previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f; hex = symbol->vector->hexagons; - fm_puts(" diameter) { previous_diameter = hex->diameter; @@ -243,36 +243,36 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { half_sqrt3_radius = 0.43301270189221932338f * previous_diameter; } if ((hex->rotation == 0) || (hex->rotation == 180)) { - fm_putsf("M", 2, hex->x, fmp); - fm_putsf(" ", 2, hex->y + radius, fmp); - fm_putsf("L", 2, hex->x + half_sqrt3_radius, fmp); - fm_putsf(" ", 2, hex->y + half_radius, fmp); - fm_putsf("L", 2, hex->x + half_sqrt3_radius, fmp); - fm_putsf(" ", 2, hex->y - half_radius, fmp); - fm_putsf("L", 2, hex->x, fmp); - fm_putsf(" ", 2, hex->y - radius, fmp); - fm_putsf("L", 2, hex->x - half_sqrt3_radius, fmp); - fm_putsf(" ", 2, hex->y - half_radius, fmp); - fm_putsf("L", 2, hex->x - half_sqrt3_radius, fmp); - fm_putsf(" ", 2, hex->y + half_radius, fmp); + zint_fm_putsf("M", 2, hex->x, fmp); + zint_fm_putsf(" ", 2, hex->y + radius, fmp); + zint_fm_putsf("L", 2, hex->x + half_sqrt3_radius, fmp); + zint_fm_putsf(" ", 2, hex->y + half_radius, fmp); + zint_fm_putsf("L", 2, hex->x + half_sqrt3_radius, fmp); + zint_fm_putsf(" ", 2, hex->y - half_radius, fmp); + zint_fm_putsf("L", 2, hex->x, fmp); + zint_fm_putsf(" ", 2, hex->y - radius, fmp); + zint_fm_putsf("L", 2, hex->x - half_sqrt3_radius, fmp); + zint_fm_putsf(" ", 2, hex->y - half_radius, fmp); + zint_fm_putsf("L", 2, hex->x - half_sqrt3_radius, fmp); + zint_fm_putsf(" ", 2, hex->y + half_radius, fmp); } else { - fm_putsf("M", 2, hex->x - radius, fmp); - fm_putsf(" ", 2, hex->y, fmp); - fm_putsf("L", 2, hex->x - half_radius, fmp); - fm_putsf(" ", 2, hex->y + half_sqrt3_radius, fmp); - fm_putsf("L", 2, hex->x + half_radius, fmp); - fm_putsf(" ", 2, hex->y + half_sqrt3_radius, fmp); - fm_putsf("L", 2, hex->x + radius, fmp); - fm_putsf(" ", 2, hex->y, fmp); - fm_putsf("L", 2, hex->x + half_radius, fmp); - fm_putsf(" ", 2, hex->y - half_sqrt3_radius, fmp); - fm_putsf("L", 2, hex->x - half_radius, fmp); - fm_putsf(" ", 2, hex->y - half_sqrt3_radius, fmp); + zint_fm_putsf("M", 2, hex->x - radius, fmp); + zint_fm_putsf(" ", 2, hex->y, fmp); + zint_fm_putsf("L", 2, hex->x - half_radius, fmp); + zint_fm_putsf(" ", 2, hex->y + half_sqrt3_radius, fmp); + zint_fm_putsf("L", 2, hex->x + half_radius, fmp); + zint_fm_putsf(" ", 2, hex->y + half_sqrt3_radius, fmp); + zint_fm_putsf("L", 2, hex->x + radius, fmp); + zint_fm_putsf(" ", 2, hex->y, fmp); + zint_fm_putsf("L", 2, hex->x + half_radius, fmp); + zint_fm_putsf(" ", 2, hex->y - half_sqrt3_radius, fmp); + zint_fm_putsf("L", 2, hex->x - half_radius, fmp); + zint_fm_putsf(" ", 2, hex->y - half_sqrt3_radius, fmp); } - fm_putc('Z', fmp); + zint_fm_putc('Z', fmp); hex = hex->next; } - fm_putc('"', fmp); + zint_fm_putc('"', fmp); svg_put_opacity_close(fg_alpha, fg_alpha_opacity, 1 /*close*/, fmp); } @@ -283,74 +283,74 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) { previous_diameter = circle->diameter; radius = 0.5f * previous_diameter; } - fm_puts(" x, fmp); svg_put_fattrib(" cy=\"", 2, circle->y, fmp); svg_put_fattrib(" r=\"", circle->width ? 3 : 2, radius, fmp); if (circle->colour) { /* Legacy - no longer used */ if (circle->width) { - fm_printf(fmp, " stroke=\"#%s\"", bgcolour_string); + zint_fm_printf(fmp, " stroke=\"#%s\"", bgcolour_string); svg_put_fattrib(" stroke-width=\"", 3, circle->width, fmp); - fm_puts(" fill=\"none\"", fmp); + zint_fm_puts(" fill=\"none\"", fmp); } else { - fm_printf(fmp, " fill=\"#%s\"", bgcolour_string); + zint_fm_printf(fmp, " fill=\"#%s\"", bgcolour_string); } /* This doesn't work how the user is likely to expect - more work needed! */ svg_put_opacity_close(bg_alpha, bg_alpha_opacity, 1 /*close*/, fmp); } else { if (circle->width) { - fm_printf(fmp, " stroke=\"#%s\"", fgcolour_string); + zint_fm_printf(fmp, " stroke=\"#%s\"", fgcolour_string); svg_put_fattrib(" stroke-width=\"", 3, circle->width, fmp); - fm_puts(" fill=\"none\"", fmp); + zint_fm_puts(" fill=\"none\"", fmp); } svg_put_opacity_close(fg_alpha, fg_alpha_opacity, 1 /*close*/, fmp); } circle = circle->next; } - bold = (symbol->output_options & BOLD_TEXT) && !upcean; + bold = (symbol->output_options & BOLD_TEXT) && !is_upcean; string = symbol->vector->strings; while (string) { const char *const halign = string->halign == 2 ? "end" : string->halign == 1 ? "start" : "middle"; - fm_puts(" x, fmp); svg_put_fattrib(" y=\"", 2, string->y, fmp); - fm_printf(fmp, " text-anchor=\"%s\"", halign); - if (upcean) { - fm_printf(fmp, " font-family=\"%s, monospace\"", upcean_font_family); + zint_fm_printf(fmp, " text-anchor=\"%s\"", halign); + if (is_upcean) { + zint_fm_printf(fmp, " font-family=\"%s, monospace\"", upcean_font_family); } else { - fm_printf(fmp, " font-family=\"%s, Arial, sans-serif\"", normal_font_family); + zint_fm_printf(fmp, " font-family=\"%s, Arial, sans-serif\"", normal_font_family); } svg_put_fattrib(" font-size=\"", 1, string->fsize, fmp); if (bold) { - fm_puts(" font-weight=\"bold\"", fmp); + zint_fm_puts(" font-weight=\"bold\"", fmp); } if (string->rotation != 0) { - fm_printf(fmp, " transform=\"rotate(%d", string->rotation); - fm_putsf(",", 2, string->x, fmp); - fm_putsf(",", 2, string->y, fmp); - fm_puts(")\"", fmp); + zint_fm_printf(fmp, " transform=\"rotate(%d", string->rotation); + zint_fm_putsf(",", 2, string->x, fmp); + zint_fm_putsf(",", 2, string->y, fmp); + zint_fm_puts(")\"", fmp); } svg_put_opacity_close(fg_alpha, fg_alpha_opacity, 0 /*close*/, fmp); svg_make_html_friendly(string->text, html_string); - fm_printf(fmp, " %s\n", html_string); - fm_puts(" \n", fmp); + zint_fm_printf(fmp, " %s\n", html_string); + zint_fm_puts(" \n", fmp); string = string->next; } - fm_puts(" \n" + zint_fm_puts(" \n" "\n", fmp); - if (fm_error(fmp)) { - ZEXT errtxtf(0, symbol, 682, "Incomplete write to SVG output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); - (void) fm_close(fmp, symbol); + if (zint_fm_error(fmp)) { + ZEXT z_errtxtf(0, symbol, 682, "Incomplete write to SVG output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); + (void) zint_fm_close(fmp, symbol); return ZINT_ERROR_FILE_WRITE; } - if (!fm_close(fmp, symbol)) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 684, "Failure on closing SVG output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_close(fmp, symbol)) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 684, "Failure on closing SVG output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } return 0; diff --git a/backend/telepen.c b/backend/telepen.c index d7dfda2e..5a7b4f13 100644 --- a/backend/telepen.c +++ b/backend/telepen.c @@ -86,7 +86,7 @@ static const char TeleLens[128] = { 12, 10, 8, 14, 10, 12, 12, 12, 10, 14, 12, 12, 14, 12, 12, 16 }; -INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_telepen(struct zint_symbol *symbol, unsigned char source[], int length) { int i, count, check_digit; int error_number; char dest[1145]; /* 12 (Start) + 69 * 16 (max for DELs) + 16 (Check) + 12 (stop) + 1 = 1145 */ @@ -98,7 +98,7 @@ INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int len count = 0; if (length > 69) { /* 16 (Start) + 69 * 16 + 16 (Check) + 16 (Stop) = 1152 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 390, "Input length %d too long (maximum 69)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 390, "Input length %d too long (maximum 69)", length); } /* Start character */ memcpy(d, TeleTable['_'], 12); @@ -107,7 +107,7 @@ INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int len for (i = 0; i < length; i++) { if (source[i] > 127) { /* Cannot encode extended ASCII */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 391, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 391, "Invalid character at position %d in input, extended ASCII not allowed", i + 1); } memcpy(d, TeleTable[source[i]], TeleLens[source[i]]); @@ -128,26 +128,26 @@ INTERNAL int telepen(struct zint_symbol *symbol, unsigned char source[], int len memcpy(d, TeleTable['z'], 12); d += 12; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (symbol->output_options & COMPLIANT_HEIGHT) { /* Default height from various Telepen docs is based on default 26pt at X 0.01125" (average of 0.01" - 0.0125") = (26 / 72) / 0.01125 ~ 32; no min height specified */ - (void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/); } else { - (void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/); } - hrt_cpy_iso8859_1(symbol, source, length); + z_hrt_cpy_iso8859_1(symbol, source, length); - if (raw_text && rt_cpy_cat(symbol, source, length, check_digit, NULL /*cat*/, 0)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, source, length, check_digit, NULL /*cat*/, 0)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; } -INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int length) { +INTERNAL int zint_telepen_num(struct zint_symbol *symbol, unsigned char source[], int length) { int count, check_digit, glyph; int error_number = 0; int i; @@ -159,10 +159,10 @@ INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int count = 0; if (length > 136) { /* 68*2 */ - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 392, "Input length %d too long (maximum 136)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 392, "Input length %d too long (maximum 136)", length); } - if ((i = not_sane(SODIUM_X_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 393, + if ((i = z_not_sane(SODIUM_X_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 393, "Invalid character at position %d in input (digits and \"X\" only)", i); } @@ -173,7 +173,7 @@ INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int } else { memcpy(local_source, source, length); } - to_upper(local_source, length); + z_to_upper(local_source, length); /* Start character */ memcpy(d, TeleTable['_'], 12); @@ -181,15 +181,15 @@ INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int for (i = 0; i < length; i += 2) { if (local_source[i] == 'X') { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 394, "Invalid odd position %d of \"X\" in Telepen data", + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 394, "Invalid odd position %d of \"X\" in Telepen data", i + 1); } if (local_source[i + 1] == 'X') { - glyph = ctoi(local_source[i]) + 17; + glyph = z_ctoi(local_source[i]) + 17; count += glyph; } else { - glyph = (10 * ctoi(local_source[i])) + ctoi(local_source[i + 1]); + glyph = 10 * z_ctoi(local_source[i]) + z_ctoi(local_source[i + 1]); glyph += 27; count += glyph; } @@ -210,18 +210,18 @@ INTERNAL int telepen_num(struct zint_symbol *symbol, unsigned char source[], int memcpy(d, TeleTable['z'], 12); d += 12; - expand(symbol, dest, d - dest); + z_expand(symbol, dest, d - dest); if (symbol->output_options & COMPLIANT_HEIGHT) { - (void) set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/); /* Same as alphanumeric Telepen */ + (void) z_set_height(symbol, 0.0f, 32.0f, 0, 1 /*no_errtxt*/); /* Same as alphanumeric Telepen */ } else { - (void) set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, 50.0f, 0, 1 /*no_errtxt*/); } - hrt_cpy_nochk(symbol, local_source, length); + z_hrt_cpy_nochk(symbol, local_source, length); - if (raw_text && rt_cpy_cat(symbol, local_source, length, check_digit, NULL /*cat*/, 0)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (raw_text && z_rt_cpy_cat(symbol, local_source, length, check_digit, NULL /*cat*/, 0)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } return error_number; diff --git a/backend/tests/fuzz/fuzz.h b/backend/tests/fuzz/fuzz.h index 9b2d48e6..ae8ea36c 100644 --- a/backend/tests/fuzz/fuzz.h +++ b/backend/tests/fuzz/fuzz.h @@ -51,7 +51,7 @@ | COMPLIANT_HEIGHT | EANUPC_GUARD_WHITESPACE | EMBED_VECTOR_FONT) #endif -/* Based on `is_sane()` flags in "backend/common.h") */ +/* Based on `z_not_sane()` flags in "backend/common.h") */ #define IS_CTL_F (0x00000001) /* ASCII control (incl. DEL) */ #define IS_PRT_F (0x00000002) /* ASCII printable (incl. space) */ #define IS_SPC_F (0x00000004 | IS_PRT_F) /* Space */ @@ -84,7 +84,7 @@ #define IS_UPR_F (IS_UPO_F | IS_UHX_F | IS_UT__F | IS_UX__F) /* Uppercase letters */ #define IS_LWR_F (IS_LWO_F | IS_LHX_F | IS_LT__F | IS_LX__F) /* Lowercase letters */ -/* Flag table for `is_chr()` and `is_sane()` (taken from "backend/common.c") */ +/* Flag table for `z_is_chr()` and `z_not_sane()` (adapted from "backend/common.c") */ #define IS_CLS_F (IS_CLI_F | IS_SIL_F) static const unsigned int flgs[256] = { IS_CTL_F, IS_CTL_F, IS_CTL_F, IS_CTL_F, IS_CTL_F, IS_CTL_F, IS_CTL_F, IS_CTL_F, /*00-07*/ @@ -121,16 +121,16 @@ static const unsigned int flgs[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*E0-FF*/ }; -/* Verifies that a string only uses valid characters */ -static int is_sane(const unsigned int flg, const unsigned char source[], const int length) { +/* Verifies if a string only uses valid characters, returning 1-based position in `source` if not, 0 for success */ +static int not_sane(const unsigned int flg, const unsigned char source[], const int length) { int i; for (i = 0; i < length; i++) { if (!(flgs[source[i]] & flg)) { - return 0; + return i + 1; } } - return 1; + return 0; } #define NEON_F (IS_NUM_F) /* NEON "0123456789" */ @@ -397,7 +397,7 @@ static int set_symbol(struct zint_symbol *symbol, const int idx, const int chk_s if (length > si->len_max) { return 0; } - if (chk_sane && si->sane_flag && !is_sane(si->sane_flag, input, length)) { + if (chk_sane && si->sane_flag && not_sane(si->sane_flag, input, length)) { return 0; } diff --git a/backend/tests/test_aztec.c b/backend/tests/test_aztec.c index f5fe97be..f4fef011 100644 --- a/backend/tests/test_aztec.c +++ b/backend/tests/test_aztec.c @@ -3100,9 +3100,9 @@ static void test_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %s, %d, %d, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n", i, testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), data[i].option_1, data[i].option_2, diff --git a/backend/tests/test_big5.c b/backend/tests/test_big5.c index f7818d92..84867611 100644 --- a/backend/tests/test_big5.c +++ b/backend/tests/test_big5.c @@ -39,12 +39,12 @@ #include "../just_say_gno/big5_gnu.h" #endif -INTERNAL int u_big5_test(const unsigned int u, unsigned char *dest); +INTERNAL int zint_test_u_big5(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] = {0}; /* Suppress clang -fsanitize=memory false positive */ - int ret = u_big5_test(u, dest); + int ret = zint_test_u_big5(u, dest); if (ret) { *d = ret == 1 ? dest[0] : ((dest[0] << 8) | dest[1]); } @@ -111,7 +111,8 @@ static void test_u_big5_int(const testCtx *const p_ctx) { val = val2 = 0; 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); + 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); } @@ -133,7 +134,8 @@ static void test_u_big5_int(const testCtx *const p_ctx) { } } - 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); + 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); } @@ -159,7 +161,7 @@ static int big5_utf8(struct zint_symbol *symbol, const unsigned char source[], i memset(utfdata, 0, sizeof(unsigned int) * (*p_length + 1)); /* Suppress clang -fsanitize=memory false positive */ - error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 0 /*disallow_4byte*/); + error_number = z_utf8_to_unicode(symbol, source, utfdata, p_length, 0 /*disallow_4byte*/); if (error_number != 0) { return error_number; } @@ -213,9 +215,11 @@ static void test_big5_utf8(const testCtx *const p_ctx) { assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); if (ret == 0) { int j; - assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); + assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", + i, ret_length, data[i].ret_length); for (j = 0; j < ret_length; j++) { - assert_equal(b5data[j], data[i].expected_b5data[j], "i:%d b5data[%d] %04X != %04X\n", i, j, b5data[j], data[i].expected_b5data[j]); + assert_equal(b5data[j], data[i].expected_b5data[j], "i:%d b5data[%d] %04X != %04X\n", + i, j, b5data[j], data[i].expected_b5data[j]); } } } diff --git a/backend/tests/test_bmp.c b/backend/tests/test_bmp.c index 914c2df5..1279d022 100644 --- a/backend/tests/test_bmp.c +++ b/backend/tests/test_bmp.c @@ -32,7 +32,7 @@ #include "testcommon.h" #include -INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); +INTERNAL int zint_bmp_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf); static void test_pixel_plot(const testCtx *const p_ctx) { int debug = p_ctx->debug; @@ -84,7 +84,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) { symbol->debug |= debug; size = data[i].width * data[i].height; - assert_nonzero(size < (int) sizeof(data_buf), "i:%d bmp_pixel_plot size %d < sizeof(data_buf) %d\n", + assert_nonzero(size < (int) sizeof(data_buf), "i:%d zint_bmp_pixel_plot size %d < sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf)); if (data[i].repeat) { @@ -92,7 +92,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) { } else { strcpy(data_buf, data[i].pattern); } - assert_equal(size, (int) strlen(data_buf), "i:%d bmp_pixel_plot size %d != strlen(data_buf) %d\n", + assert_equal(size, (int) strlen(data_buf), "i:%d zint_bmp_pixel_plot size %d != strlen(data_buf) %d\n", i, size, (int) strlen(data_buf)); if (*data_buf > '9') { @@ -101,8 +101,8 @@ static void test_pixel_plot(const testCtx *const p_ctx) { symbol->bitmap = (unsigned char *) data_buf; - ret = bmp_pixel_plot(symbol, TCU(data_buf)); - assert_equal(ret, data[i].ret, "i:%d bmp_pixel_plot ret %d != %d (%s)\n", + ret = zint_bmp_pixel_plot(symbol, TCU(data_buf)); + assert_equal(ret, data[i].ret, "i:%d zint_bmp_pixel_plot ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); if (ret < ZINT_ERROR) { @@ -286,13 +286,13 @@ static void test_outfile(const testCtx *const p_ctx) { (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ assert_nonzero(testUtilCreateROFile(symbol.outfile), - "bmp_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", + "zint_bmp_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = bmp_pixel_plot(&symbol, data); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "bmp_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", + ret = zint_bmp_pixel_plot(&symbol, data); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "zint_bmp_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "bmp_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", + assert_zero(testUtilRmROFile(symbol.outfile), "zint_bmp_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); @@ -300,9 +300,9 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.output_options |= BARCODE_STDOUT; - ret = bmp_pixel_plot(&symbol, data); + ret = zint_bmp_pixel_plot(&symbol, data); printf(" - ignore (BMP to stdout)\n"); fflush(stdout); - assert_zero(ret, "bmp_pixel_plot ret %d != 0 (%s)\n", ret, symbol.errtxt); + assert_zero(ret, "zint_bmp_pixel_plot ret %d != 0 (%s)\n", ret, symbol.errtxt); testFinish(); } diff --git a/backend/tests/test_bwipp.c b/backend/tests/test_bwipp.c index 73e4da0a..bd824470 100644 --- a/backend/tests/test_bwipp.c +++ b/backend/tests/test_bwipp.c @@ -394,7 +394,7 @@ static void test_aztec_bwipjs_354(const testCtx *const p_ctx) { assert_nonzero(length, "i:%d cnv_hex_data length zero\n", i); #if 0 - debug_print_escape(TCU(data_buf), length, NULL); + z_debug_print_escape(TCU(data_buf), length, NULL); printf("\n"); #endif @@ -484,7 +484,7 @@ static void test_codablockf_fnc4_digit(const testCtx *const p_ctx) { assert_nonzero(length, "i:%d cnv_hex_data length zero\n", i); #if 0 - debug_print_escape(TCU(data_buf), length, NULL); + z_debug_print_escape(TCU(data_buf), length, NULL); printf("\n"); #endif diff --git a/backend/tests/test_code1.c b/backend/tests/test_code1.c index df67a171..29ad5c5d 100644 --- a/backend/tests/test_code1.c +++ b/backend/tests/test_code1.c @@ -3314,9 +3314,9 @@ static void test_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %d, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n", i, testUtilInputModeName(data[i].input_mode), data[i].option_2, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, diff --git a/backend/tests/test_code128.c b/backend/tests/test_code128.c index 3c70a7a9..fd7b4ae7 100644 --- a/backend/tests/test_code128.c +++ b/backend/tests/test_code128.c @@ -341,7 +341,7 @@ static void test_hrt(const testCtx *const p_ctx) { if (do_bwipp && testUtilCanBwipp(i, symbol, -1, data[i].option_2, -1, debug)) { if (data[i].symbology == BARCODE_HIBC_128 - && not_sane(IS_NUM_F | IS_UPR_F | IS_SPC_F | IS_PLS_F | IS_MNS_F | IS_SIL_F, (const unsigned char *) data[i].data, length)) { + && z_not_sane(IS_NUM_F | IS_UPR_F | IS_SPC_F | IS_PLS_F | IS_MNS_F | IS_SIL_F, ZCUCP(data[i].data), length)) { if (debug & ZINT_DEBUG_TEST_PRINT) { printf("i:%d %s not BWIPP compatible (%s)\n", i, testUtilBarcodeName(symbol->symbology), "BWIPP does not uppercase input"); @@ -835,14 +835,14 @@ static void test_gs1_128_input(const testCtx *const p_ctx) { assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d (%s)\n", i, symbol->width, data[i].expected_width, data[i].data); if (ret == ZINT_WARN_HRT_TRUNCATED) { - assert_nonzero((int) ustrlen(symbol->text) < (int) strlen(data[i].data), + assert_nonzero((int) z_ustrlen(symbol->text) < (int) strlen(data[i].data), "i:%d len symbol->text(%s) %d >= %d (%s) (%s)\n", - i, symbol->text, (int) ustrlen(symbol->text), (int) strlen(data[i].data), data[i].data, + i, symbol->text, (int) z_ustrlen(symbol->text), (int) strlen(data[i].data), data[i].data, symbol->errtxt); } else { - assert_equal((int) ustrlen(symbol->text), (int) strlen(data[i].data), + assert_equal((int) z_ustrlen(symbol->text), (int) strlen(data[i].data), "i:%d len symbol->text(%s) %d != %d (%s, %s) (%s)\n", - i, symbol->text, (int) ustrlen(symbol->text), (int) strlen(data[i].data), + i, symbol->text, (int) z_ustrlen(symbol->text), (int) strlen(data[i].data), testUtilErrorName(ret), data[i].data, symbol->errtxt); } diff --git a/backend/tests/test_common.c b/backend/tests/test_common.c index 9f3b3fd0..63eb4701 100644 --- a/backend/tests/test_common.c +++ b/backend/tests/test_common.c @@ -78,7 +78,7 @@ static void test_to_int(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - ret = to_int((const unsigned char *) data[i].data, length); + ret = z_to_int(ZCUCP(data[i].data), length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); } @@ -116,7 +116,7 @@ static void test_to_upper(const testCtx *const p_ctx) { memcpy(buf, data[i].data, length); buf[length] = '\0'; - to_upper(buf, length); + z_to_upper(buf, length); assert_zero(strcmp((const char *) buf, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, buf, data[i].expected); } @@ -149,7 +149,7 @@ static void test_chr_cnt(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - ret = chr_cnt((const unsigned char *) data[i].data, length, data[i].c); + ret = z_chr_cnt(ZCUCP(data[i].data), length, data[i].c); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); } @@ -183,7 +183,7 @@ static void test_is_chr(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - ret = is_chr(data[i].flg, data[i].c); + ret = z_is_chr(data[i].flg, data[i].c); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); } @@ -299,7 +299,7 @@ static void test_not_sane(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - ret = not_sane(data[i].flg, (const unsigned char *) data[i].data, length); + ret = z_not_sane(data[i].flg, (const unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (data[i].orig_test[0]) { @@ -313,12 +313,12 @@ static void test_not_sane(const testCtx *const p_ctx) { ret = 0; for (j = 0; j < length; j++) { - if (!is_chr(data[i].flg, data[i].data[j])) { + if (!z_is_chr(data[i].flg, data[i].data[j])) { ret = j + 1; break; } } - assert_equal(ret, data[i].ret, "i:%d is_chr() ret %d != %d\n", i, ret, data[i].ret); + assert_equal(ret, data[i].ret, "i:%d z_is_chr() ret %d != %d\n", i, ret, data[i].ret); } testFinish(); @@ -354,7 +354,8 @@ static void test_not_sane_lookup(const testCtx *const p_ctx) { test_length = data[i].test_length == -1 ? (int) strlen(data[i].test_string) : data[i].test_length; length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - ret = not_sane_lookup(data[i].test_string, test_length, (const unsigned char *) data[i].data, length, posns); + ret = z_not_sane_lookup(data[i].test_string, test_length, (const unsigned char *) data[i].data, length, + posns); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { @@ -407,7 +408,7 @@ static void test_errtxt(const testCtx *const p_ctx) { memset(symbol, 0, sizeof(*symbol)); if (data[i].debug_test) symbol->debug |= ZINT_DEBUG_TEST; - ret = errtxt(data[i].error_number, symbol, data[i].err_id, data[i].msg); + ret = z_errtxt(data[i].error_number, symbol, data[i].err_id, data[i].msg); assert_equal(ret, data[i].error_number, "i:%d ret %d != %d\n", i, ret, data[i].error_number); assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); @@ -542,37 +543,37 @@ static void test_errtxtf(const testCtx *const p_ctx) { if (data[i].debug_test) symbol->debug |= ZINT_DEBUG_TEST; if (data[i].num_args == 0) { - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, NULL /*suppress -Wformat-security*/); } else if (data[i].num_args == 1) { if (data[i].i_arg != -1) { - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg); + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg); } else if (data[i].s_arg != NULL) { - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].s_arg); + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].s_arg); } else { - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].f_arg); + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].f_arg); } } else if (data[i].num_args == 2) { if (data[i].i_arg != -1) { if (data[i].s_arg != NULL) { - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, data[i].s_arg); } else { - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, data[i].f_arg); } } else { assert_nonnull(data[i].s_arg, "i:%d num_args:%d data[i].s_arg NULL", i, data[i].num_args); - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].s_arg, + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].s_arg, data[i].f_arg); } } else if (data[i].num_args == 3) { assert_nonnull(data[i].s_arg, "i:%d num_args:%d data[i].s_arg NULL", i, data[i].num_args); - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, data[i].s_arg, + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, data[i].i_arg, data[i].s_arg, data[i].f_arg); } else if (data[i].num_args == 9) { /* Special case max, assuming 4th arg "%d", 5th arg "%s" */ assert_nonnull(data[i].s_arg, "i:%d num_args:%d data[i].s_arg NULL", i, data[i].num_args); - ret = errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, 2100000001, 2100000002, 3333, + ret = z_errtxtf(data[i].error_number, symbol, data[i].err_id, data[i].fmt, 2100000001, 2100000002, 3333, data[i].i_arg, data[i].s_arg, 2100000006, 2100000007, 2100000008, 2100000009); } else { assert_nonnull(NULL, "i:%d num_args:%d > 3 && != 9\n", i, data[i].num_args); @@ -619,7 +620,7 @@ static void test_cnt_digits(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - ret = cnt_digits((const unsigned char *) data[i].data, length, data[i].position, data[i].max); + ret = z_cnt_digits((const unsigned char *) data[i].data, length, data[i].position, data[i].max); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); } @@ -658,7 +659,7 @@ static void test_is_valid_utf8(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - ret = is_valid_utf8((const unsigned char *) data[i].data, length); + ret = z_is_valid_utf8((const unsigned char *) data[i].data, length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); } @@ -707,7 +708,7 @@ static void test_utf8_to_unicode(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - ret = utf8_to_unicode(symbol, (unsigned char *) data[i].data, vals, &ret_length, data[i].disallow_4byte); + ret = z_utf8_to_unicode(symbol, (unsigned char *) data[i].data, vals, &ret_length, data[i].disallow_4byte); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { int j; @@ -787,14 +788,14 @@ static void test_hrt_cpy_iso8859_1(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; expected_length = (int) strlen(data[i].expected); - ret = hrt_cpy_iso8859_1(symbol, (unsigned char *) data[i].data, length); + ret = z_hrt_cpy_iso8859_1(symbol, (unsigned char *) data[i].data, length); if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { for (j = 0; j < symbol->text_length; j++) { fprintf(stderr, "symbol->text[%d] %2X\n", j, symbol->text[j]); } } assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); - assert_nonzero(testUtilIsValidUTF8(symbol->text, (int) ustrlen(symbol->text)), + assert_nonzero(testUtilIsValidUTF8(symbol->text, (int) z_ustrlen(symbol->text)), "i:%d testUtilIsValidUTF8(%s) != 1\n", i, symbol->text); assert_equal(symbol->text_length, expected_length, "i:%d text_length %d != expected_length %d\n", i, symbol->text_length, expected_length); @@ -809,16 +810,16 @@ static void test_hrt_cpy_nochk(const testCtx *const p_ctx) { int debug = p_ctx->debug; struct item { - const char *cpy; /* hrt_cpy_nochk() */ + const char *cpy; /* z_hrt_cpy_nochk() */ int cpy_length; - const char cpy_chr; /* hrt_cpy_chr() */ + const char cpy_chr; /* z_hrt_cpy_chr() */ int cpy_chr_length; - const char *cat; /* hrt_cat_nochk() */ + const char *cat; /* z_hrt_cat_nochk() */ int cat_length; - char cat_chr; /* hrt_cat_chr_nochk() */ + char cat_chr; /* z_hrt_cat_chr_nochk() */ int cat_chr_length; const char *expected; @@ -827,15 +828,15 @@ static void test_hrt_cpy_nochk(const testCtx *const p_ctx) { /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ static const struct item data[] = { /* 0*/ { "", -1, 0, 0, "", -1, 0, 0, "", -1 }, /* All zero */ - /* 1*/ { "AB\000C", 4, 0, 0, "", -1, 0, 0, "AB\000C", 4 }, /* hrt_cpy_nochk() */ - /* 2*/ { "", -1, '\000', 1, "", -1, 0, 0, "\000", 1 }, /* hrt_chr() (NUL char) */ - /* 3*/ { "", -1, '\000', 1, "XYZ", -1, 0, 0, "\000XYZ", 4 }, /* hrt_chr() + hrt_cat_nochk() */ - /* 4*/ { "", -1, '\000', 1, "", -1, '\000', 1, "\000\000", 2 }, /* hrt_chr() + hrt_cat_chr_nochk() (both NULL char) */ - /* 5*/ { "", -1, '\000', 1, "XYZ", -1, '\001', 1, "\000XYZ\001", 5 }, /* hrt_chr() + hrt_cat_chr_nochk() + hrt_cat_nochk() */ - /* 6*/ { "ABC\000", 4, 0, 0, "\000XYZ\177", 5, 0, 0, "ABC\000\000XYZ\177", 9 }, /* hrt_cpy_nochk() + hrt_cat_nochk() */ - /* 7*/ { "ABC\000", 4, 0, 0, "", -1, '\177', 1, "ABC\000\177", 5 }, /* hrt_cpy_nochk() + hrt_cat_chr_nochk() */ - /* 8*/ { "ABC\000", 4, 0, 0, "X\001Y\002Z", 5, '\003', 1, "ABC\000X\001Y\002Z\003", 10 }, /* hrt_cpy_nochk() + hrt_cat_chr_nochk() + hrt_cat_chr_nochk() */ - /* 9*/ { "1234567890123456789012345678901234567890123456789012345", -1, 0, 0, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", -1, 0, 0, "123456789012345678901234567890123456789012345678901234512345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", -1 }, /* hrt_cpy_nochk() + hrt_cat_nochk() - max 255 */ + /* 1*/ { "AB\000C", 4, 0, 0, "", -1, 0, 0, "AB\000C", 4 }, /* z_hrt_cpy_nochk() */ + /* 2*/ { "", -1, '\000', 1, "", -1, 0, 0, "\000", 1 }, /* z_hrt_chr() (NUL char) */ + /* 3*/ { "", -1, '\000', 1, "XYZ", -1, 0, 0, "\000XYZ", 4 }, /* z_hrt_chr() + z_hrt_cat_nochk() */ + /* 4*/ { "", -1, '\000', 1, "", -1, '\000', 1, "\000\000", 2 }, /* z_hrt_chr() + z_hrt_cat_chr_nochk() (both NULL char) */ + /* 5*/ { "", -1, '\000', 1, "XYZ", -1, '\001', 1, "\000XYZ\001", 5 }, /* z_hrt_chr() + z_hrt_cat_chr_nochk() + z_hrt_cat_nochk() */ + /* 6*/ { "ABC\000", 4, 0, 0, "\000XYZ\177", 5, 0, 0, "ABC\000\000XYZ\177", 9 }, /* z_hrt_cpy_nochk() + z_hrt_cat_nochk() */ + /* 7*/ { "ABC\000", 4, 0, 0, "", -1, '\177', 1, "ABC\000\177", 5 }, /* z_hrt_cpy_nochk() + z_hrt_cat_chr_nochk() */ + /* 8*/ { "ABC\000", 4, 0, 0, "X\001Y\002Z", 5, '\003', 1, "ABC\000X\001Y\002Z\003", 10 }, /* z_hrt_cpy_nochk() + z_hrt_cat_chr_nochk() + z_hrt_cat_chr_nochk() */ + /* 9*/ { "1234567890123456789012345678901234567890123456789012345", -1, 0, 0, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", -1, 0, 0, "123456789012345678901234567890123456789012345678901234512345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", -1 }, /* z_hrt_cpy_nochk() + z_hrt_cat_nochk() - max 255 */ }; const int data_size = ARRAY_SIZE(data); int i, length; @@ -858,16 +859,16 @@ static void test_hrt_cpy_nochk(const testCtx *const p_ctx) { expected_length = data[i].expected_length == -1 ? (int) strlen(data[i].expected) : data[i].expected_length; if ((length = data[i].cpy_length == -1 ? (int) strlen(data[i].cpy) : data[i].cpy_length)) { - hrt_cpy_nochk(symbol, TCU(data[i].cpy), length); + z_hrt_cpy_nochk(symbol, TCU(data[i].cpy), length); } if (data[i].cpy_chr_length) { - hrt_cpy_chr(symbol, data[i].cpy_chr); + z_hrt_cpy_chr(symbol, data[i].cpy_chr); } if ((length = data[i].cat_length == -1 ? (int) strlen(data[i].cat) : data[i].cat_length)) { - hrt_cat_nochk(symbol, TCU(data[i].cat), length); + z_hrt_cat_nochk(symbol, TCU(data[i].cat), length); } if (data[i].cat_chr_length) { - hrt_cat_chr_nochk(symbol, data[i].cat_chr); + z_hrt_cat_chr_nochk(symbol, data[i].cat_chr); } if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { @@ -876,7 +877,7 @@ static void test_hrt_cpy_nochk(const testCtx *const p_ctx) { } } - assert_nonzero(testUtilIsValidUTF8(symbol->text, (int) ustrlen(symbol->text)), + assert_nonzero(testUtilIsValidUTF8(symbol->text, (int) z_ustrlen(symbol->text)), "i:%d testUtilIsValidUTF8(%s) != 1\n", i, symbol->text); assert_equal(symbol->text_length, expected_length, "i:%d text_length %d != expected_length %d\n", i, symbol->text_length, expected_length); @@ -933,7 +934,7 @@ static void test_hrt_cpy_cat_nochk(const testCtx *const p_ctx) { expected_length = data[i].expected_length == -1 ? (int) strlen(data[i].expected) : data[i].expected_length; - hrt_cpy_cat_nochk(symbol, TCU(data[i].source), data[i].length, data[i].separator, TCU(data[i].cat), + z_hrt_cpy_cat_nochk(symbol, TCU(data[i].source), data[i].length, data[i].separator, TCU(data[i].cat), data[i].cat_length); if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { @@ -942,7 +943,7 @@ static void test_hrt_cpy_cat_nochk(const testCtx *const p_ctx) { } } - assert_nonzero(testUtilIsValidUTF8(symbol->text, (int) ustrlen(symbol->text)), + assert_nonzero(testUtilIsValidUTF8(symbol->text, (int) z_ustrlen(symbol->text)), "i:%d testUtilIsValidUTF8(%s) != 1\n", i, symbol->text); assert_equal(symbol->text_length, expected_length, "i:%d text_length %d != expected_length %d\n", i, symbol->text_length, expected_length); @@ -987,9 +988,9 @@ static void test_hrt_printf_nochk(const testCtx *const p_ctx) { memset(symbol, 0, sizeof(*symbol)); if (data[i].num_args == 1) { - hrt_printf_nochk(symbol, data[i].fmt, data[i].data1); + z_hrt_printf_nochk(symbol, data[i].fmt, data[i].data1); } else if (data[i].num_args == 2) { - hrt_printf_nochk(symbol, data[i].fmt, data[i].data1, data[i].data2); + z_hrt_printf_nochk(symbol, data[i].fmt, data[i].data1, data[i].data2); } else { assert_zero(1, "i:%d, bad num_args\n", i); } @@ -1043,7 +1044,7 @@ static void test_hrt_conv_gs1_brackets_nochk(const testCtx *const p_ctx) { length = (int) strlen(data[i].data); - hrt_conv_gs1_brackets_nochk(symbol, TCU(data[i].data), length); + z_hrt_conv_gs1_brackets_nochk(symbol, TCU(data[i].data), length); assert_zero(strcmp((const char *) symbol->text, data[i].expected), "i:%d strcmp(\"%s\", \"%s\") != 0\n", i, symbol->text, data[i].expected); @@ -1097,8 +1098,8 @@ static void test_rt_cpy_seg(const testCtx *const p_ctx) { assert_nonzero(data[i].seg_count, "i:%d seg_count zero\n", i); - ret = rt_init_segs(symbol, data[i].seg_count); - assert_zero(ret, "i:%d rt_init_segs(%d) %d != 0\n", i, data[i].seg_count, ret); + ret = z_rt_init_segs(symbol, data[i].seg_count); + assert_zero(ret, "i:%d z_rt_init_segs(%d) %d != 0\n", i, data[i].seg_count, ret); seg_idx = data[i].seg_idx; assert_nonzero(seg_idx >= 0, "i:%d seg_idx %d < 0\n", i, seg_idx); @@ -1108,10 +1109,10 @@ static void test_rt_cpy_seg(const testCtx *const p_ctx) { if (data[i].ddata_size > 0) { assert_equal(data[i].seg.length, data[i].ddata_size, "i:%d seg_length %d != ddata_size %d\n", i, data[i].seg.length, data[i].ddata_size); - ret = rt_cpy_seg_ddata(symbol, seg_idx, &data[i].seg, data[i].ddata_eci, data[i].ddata); + ret = z_rt_cpy_seg_ddata(symbol, seg_idx, &data[i].seg, data[i].ddata_eci, data[i].ddata); assert_zero(ret, "i:%d rt_cpy_seg_ddata %d != 0\n", i, ret); } else { - ret = rt_cpy_seg(symbol, seg_idx, &data[i].seg); + ret = z_rt_cpy_seg(symbol, seg_idx, &data[i].seg); assert_zero(ret, "i:%d rt_cpy_segs %d != 0\n", i, ret); } @@ -1181,16 +1182,16 @@ static void test_rt_cpy(const testCtx *const p_ctx) { expected_length = data[i].expected_length == -1 ? (int) strlen(data[i].expected) : data[i].expected_length; - ret = rt_init_segs(symbol, 1); + ret = z_rt_init_segs(symbol, 1); assert_zero(ret, "i:%d rt_init_segs %d != 0\n", i, ret); length = data[i].length == -1 ? (int) strlen(data[i].source) : data[i].length; if ((cat_length = data[i].cat_length == -1 ? (int) strlen(data[i].cat) : data[i].cat_length)) { - ret = rt_cpy_cat(symbol, TCU(data[i].source), length, data[i].separator, TCU(data[i].cat), cat_length); + ret = z_rt_cpy_cat(symbol, TCU(data[i].source), length, data[i].separator, TCU(data[i].cat), cat_length); assert_zero(ret, "i:%d rt_cpy_cat %d != 0\n", i, ret); } else { - ret = rt_cpy(symbol, TCU(data[i].source), length); + ret = z_rt_cpy(symbol, TCU(data[i].source), length); assert_zero(ret, "i:%d rt_cpy %d != 0\n", i, ret); } @@ -1252,14 +1253,14 @@ static void test_rt_printf_256(const testCtx *const p_ctx) { expected_length = (int) strlen(data[i].expected); - ret = rt_init_segs(symbol, 1); + ret = z_rt_init_segs(symbol, 1); assert_zero(ret, "i:%d rt_init_segs %d != 0\n", i, ret); if (data[i].num_args == 1) { - ret = rt_printf_256(symbol, data[i].fmt, data[i].data1); + ret = z_rt_printf_256(symbol, data[i].fmt, data[i].data1); assert_zero(ret, "i:%d rt_printf_256 1 arg ret %d != 0\n", i, ret); } else if (data[i].num_args == 2) { - ret = rt_printf_256(symbol, data[i].fmt, data[i].data1, data[i].data2); + ret = z_rt_printf_256(symbol, data[i].fmt, data[i].data1, data[i].data2); assert_zero(ret, "i:%d rt_printf_256 2 args ret %d != 0\n", i, ret); } else { assert_zero(1, "i:%d, bad num_args\n", i); @@ -1339,8 +1340,8 @@ static void test_set_height(const testCtx *const p_ctx) { } symbol->height = data[i].height; - ret = set_height(symbol, data[i].min_row_height, data[i].default_height, data[i].max_height, - data[i].no_errtxt); + ret = z_set_height(symbol, data[i].min_row_height, data[i].default_height, data[i].max_height, + data[i].no_errtxt); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_equal(symbol->height, data[i].expected_height, "i:%d symbol->height %g != %g\n", i, symbol->height, data[i].expected_height); @@ -1351,7 +1352,7 @@ static void test_set_height(const testCtx *const p_ctx) { testFinish(); } -INTERNAL void debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length); +INTERNAL void z_debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length); static void test_debug_test_codeword_dump_int(const testCtx *const p_ctx) { int debug = p_ctx->debug; @@ -1380,7 +1381,7 @@ static void test_debug_test_codeword_dump_int(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - debug_test_codeword_dump_int(symbol, data[i].codewords, data[i].length); + z_debug_test_codeword_dump_int(symbol, data[i].codewords, data[i].length); assert_nonzero(strlen(symbol->errtxt) < 92, "i:%d strlen(%s) >= 92 (%d)\n", i, symbol->errtxt, (int) strlen(symbol->errtxt)); assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0 (%d, %d)\n", diff --git a/backend/tests/test_dmatrix.c b/backend/tests/test_dmatrix.c index 56c05052..13d191f7 100644 --- a/backend/tests/test_dmatrix.c +++ b/backend/tests/test_dmatrix.c @@ -925,8 +925,8 @@ static void test_reader_init(const testCtx *const p_ctx) { #define ZINT_TEST_ENCODING #ifdef ZINT_TEST_ENCODING -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); #endif static void test_input(const testCtx *const p_ctx) { @@ -1320,8 +1320,8 @@ static void test_input(const testCtx *const p_ctx) { if ((data[i].input_mode & 0x07) == GS1_MODE) { int data_len = length; - ret = gs1_verify(symbol, ZUCP(data[i].data), &data_len, reduced, &length); - assert_zero(ret, "i:%d gs1_verify() ret %d != 0 (%s)\n", i, ret, symbol->errtxt); + ret = zint_gs1_verify(symbol, ZUCP(data[i].data), &data_len, reduced, &length); + assert_zero(ret, "i:%d zint_gs1_verify() ret %d != 0 (%s)\n", i, ret, symbol->errtxt); text = reduced; } else { text = ZCUCP(data[i].data); @@ -1331,7 +1331,7 @@ static void test_input(const testCtx *const p_ctx) { symbol->option_2 = data[i].option_2 != -1 ? data[i].option_2 : 0; /* Restore option_2 */ gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1; - ret = dm_encode_test(symbol, text, length, symbol->eci, last_seg, gs1, binary[0], &binlen); + ret = zint_test_dm_encode(symbol, text, length, symbol->eci, last_seg, gs1, binary[0], &binlen); assert_zero(ret, "i:%d dm_encode() FAST_MODE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); binlens[0] = binlen; @@ -1341,7 +1341,7 @@ static void test_input(const testCtx *const p_ctx) { gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1; symbol->option_2 = data[i].option_2 != -1 ? data[i].option_2 : 0; /* Restore option_2 */ - ret = dm_encode_test(symbol, text, length, symbol->eci, last_seg, gs1, binary[1], &binlen); + ret = zint_test_dm_encode(symbol, text, length, symbol->eci, last_seg, gs1, binary[1], &binlen); assert_zero(ret, "i:%d dm_encode() minimal ret %d != 0 (%s)\n", i, ret, symbol->errtxt); binlens[1] = binlen; @@ -5917,7 +5917,7 @@ static void test_encode(const testCtx *const p_ctx) { symbol->input_mode = data[i - 1].input_mode; gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1; - ret = dm_encode_test(symbol, ZCUCP(data[i].data), length, symbol->eci, last_seg, gs1, + ret = zint_test_dm_encode(symbol, ZCUCP(data[i].data), length, symbol->eci, last_seg, gs1, binary[0], &binlen); assert_zero(ret, "i:%d dm_encode() FAST_MODE ret %d != 0 (%s)\n", i, ret, symbol->errtxt); @@ -5927,7 +5927,7 @@ static void test_encode(const testCtx *const p_ctx) { symbol->input_mode = data[i].input_mode; gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1; - ret = dm_encode_test(symbol, ZCUCP(data[i].data), length, symbol->eci, last_seg, gs1, + ret = zint_test_dm_encode(symbol, ZCUCP(data[i].data), length, symbol->eci, last_seg, gs1, binary[1], &binlen); assert_zero(ret, "i:%d dm_encode() minimal ret %d != 0 (%s)\n", i, ret, symbol->errtxt); @@ -6314,9 +6314,9 @@ static void test_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %s, %s, %d, %s, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n", i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), testUtilOutputOptionsName(data[i].output_options), @@ -7637,7 +7637,8 @@ static void test_minimalenc(const testCtx *const p_ctx) { binlen = 0; symbol->input_mode |= FAST_MODE; gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1; - ret = dm_encode_test(symbol, ZCUCP(data[i].data), length, symbol->eci, last_seg, gs1, binary[0], &binlen); + ret = zint_test_dm_encode(symbol, ZCUCP(data[i].data), length, symbol->eci, last_seg, gs1, binary[0], + &binlen); assert_equal(ret, data[i].ret, "i:%d dm_encode() FAST_MODE ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -7646,7 +7647,8 @@ static void test_minimalenc(const testCtx *const p_ctx) { binlen = 0; symbol->input_mode &= ~FAST_MODE; gs1 = (symbol->input_mode & 0x07) != GS1_MODE ? 0 : (symbol->output_options & GS1_GS_SEPARATOR) ? 2 : 1; - ret = dm_encode_test(symbol, ZCUCP(data[i].data), length, symbol->eci, last_seg, gs1, binary[1], &binlen); + ret = zint_test_dm_encode(symbol, ZCUCP(data[i].data), length, symbol->eci, last_seg, gs1, binary[1], + &binlen); assert_equal(ret, data[i].ret, "i:%d dm_encode() minimal ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); diff --git a/backend/tests/test_dotcode.c b/backend/tests/test_dotcode.c index 07f3b7e8..2d7aa4ae 100644 --- a/backend/tests/test_dotcode.c +++ b/backend/tests/test_dotcode.c @@ -44,14 +44,22 @@ static void test_large(const testCtx *const p_ctx) { /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ static const struct item data[] = { /* 0*/ { 200, '0', 2940, 0, "" }, /* 2940 largest Code Set C data that fits in 200x199 HxW */ - /* 1*/ { 200, '0', 2941, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol height '201' is too large (maximum 200)" }, + /* 1*/ { 200, '0', 2941, ZINT_ERROR_INVALID_OPTION, "Error 735: Resulting symbol height '201' is too large (maximum 200)" }, /* 2*/ { 200, '9', 200, 0, "" }, /* Changes a number of mask scores re pre-Rev. 4 version, but best score still the same (7) */ - /* 3*/ { 200, '0', 2974, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol height '203' is too large (maximum 200)" }, /* Width > 200 also */ + /* 3*/ { 200, '0', 2974, ZINT_ERROR_INVALID_OPTION, "Error 735: Resulting symbol height '203' is too large (maximum 200)" }, /* Width > 200 also */ /* 4*/ { 200, 'A', 1470, 0, "" }, - /* 5*/ { 200, 'A', 1471, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol height '201' is too large (maximum 200)" }, + /* 5*/ { 200, 'A', 1471, ZINT_ERROR_INVALID_OPTION, "Error 735: Resulting symbol height '201' is too large (maximum 200)" }, /* 6*/ { 200, '\240', 1225, 0, "" }, - /* 7*/ { 200, '\240', 1226, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol height '201' is too large (maximum 200)" }, - /* 8*/ { 30, '\001', 71, 0, "" }, /* Codeword length 72, ECC length 39, for ND + 1 == 112 */ + /* 7*/ { 200, '\240', 1226, ZINT_ERROR_INVALID_OPTION, "Error 735: Resulting symbol height '201' is too large (maximum 200)" }, + /* 8*/ { 200, '0', 1, 0, "" }, /* Padding codewords 35 - probably max */ + /* 9*/ { 200, '0', 2, 0, "" }, /* Padding codewords 35 */ + /* 10*/ { 30, '\001', 71, 0, "" }, /* Codeword length 72, ECC length 39, for ND + 1 == 112 */ + /* 11*/ { -1, '0', 1968, 0, "" }, + /* 12*/ { -1, '0', 1969, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol width '201' is too large (maximum 200)" }, + /* 13*/ { -1, 'A', 984, 0, "" }, + /* 14*/ { -1, 'A', 985, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol width '201' is too large (maximum 200)" }, + /* 15*/ { -1, '\240', 820, 0, "" }, + /* 16*/ { -1, '\240', 821, ZINT_ERROR_INVALID_OPTION, "Error 528: Resulting symbol width '201' is too large (maximum 200)" }, }; const int data_size = ARRAY_SIZE(data); int i, length, ret; @@ -1523,9 +1531,9 @@ static void test_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %d, %s, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, %d, \"%s\",\n", i, testUtilInputModeName(data[i].input_mode), data[i].option_2, testUtilOption3Name(BARCODE_DOTCODE, data[i].option_3), diff --git a/backend/tests/test_eci.c b/backend/tests/test_eci.c index a6c79db7..dd344e49 100644 --- a/backend/tests/test_eci.c +++ b/backend/tests/test_eci.c @@ -394,13 +394,17 @@ static void test_reduced_charset_input(const testCtx *const p_ctx) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, data[i].eci, + -1 /*option_1*/, -1, -1, -1 /*output_options*/, + data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, TCU(data[i].data), length); - assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); + assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", + i, ret, data[i].ret, symbol->errtxt); if (data[i].expected_eci != -1) { - assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n", i, symbol->eci, data[i].expected_eci); + assert_equal(symbol->eci, data[i].expected_eci, "i:%d eci %d != %d\n", + i, symbol->eci, data[i].expected_eci); } ZBarcode_Delete(symbol); @@ -707,13 +711,14 @@ static void test_utf8_to_eci_sb(const testCtx *const p_ctx) { if (data[i].tab[j]) { length = to_utf8(data[i].tab[j], source); assert_nonzero(length, "i:%d to_utf8 length %d == 0\n", i, length); - ret = utf8_to_eci(data[i].eci, source, dest, &length); - assert_zero(ret, "i:%d utf8_to_eci ret %d != 0\n", i, ret); - assert_equal(*dest, k, "i:%d j:%d eci:%d codepoint:0x%x *dest 0x%X (%d) != 0x%X (%d)\n", i, j, data[i].eci, data[i].tab[j], *dest, *dest, k, k); + ret = zint_utf8_to_eci(data[i].eci, source, dest, &length); + assert_zero(ret, "i:%d zint_utf8_to_eci ret %d != 0\n", i, ret); + assert_equal(*dest, k, "i:%d j:%d eci:%d codepoint:0x%x *dest 0x%X (%d) != 0x%X (%d)\n", + i, j, data[i].eci, data[i].tab[j], *dest, *dest, k, k); } else { length = to_utf8(k, source); assert_nonzero(length, "i:%d to_utf8 length %d == 0\n", i, length); - ret = utf8_to_eci(data[i].eci, source, dest, &length); + ret = zint_utf8_to_eci(data[i].eci, source, dest, &length); if (ret == 0) { /* Should be mapping for this codepoint in another entry */ int found = 0; int m; @@ -723,9 +728,13 @@ static void test_utf8_to_eci_sb(const testCtx *const p_ctx) { break; } } - assert_nonzero(found, "i:%d j:%d eci:%d codepoint:0x%x source:%s not found utf8_to_eci ret %d == 0\n", i, j, data[i].eci, k, source, ret); + assert_nonzero(found, + "i:%d j:%d eci:%d codepoint:0x%x source:%s not found zint_utf8_to_eci ret %d == 0\n", + i, j, data[i].eci, k, source, ret); } else { - assert_equal(ret, ZINT_ERROR_INVALID_DATA, "i:%d j:%d eci:%d codepoint:0x%x source:%s utf8_to_eci ret %d != ZINT_ERROR_INVALID_DATA\n", i, j, data[i].eci, k, source, ret); + assert_equal(ret, ZINT_ERROR_INVALID_DATA, + "i:%d j:%d eci:%d codepoint:0x%x source:%s zint_utf8_to_eci ret %d != ZINT_ERROR_INVALID_DATA\n", + i, j, data[i].eci, k, source, ret); } } } @@ -783,8 +792,9 @@ static void test_utf8_to_eci_ascii(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - ret = utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, + &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { assert_equal(length, out_length, "i:%d length %d != %d\n", i, length, out_length); assert_zero(memcmp(data[i].data, dest, length), "i:%d memcmp != 0\n", i); @@ -835,14 +845,16 @@ static void test_utf8_to_eci_utf16be(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); if (data[i].expected) { ret = memcmp(dest, data[i].expected, data[i].expected_length); assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret); @@ -850,7 +862,8 @@ static void test_utf8_to_eci_utf16be(const testCtx *const p_ctx) { int j; for (j = 0; j < length; j++) { assert_zero(dest[j * 2], "i:%d dest[%d] %d != 0\n", i, j * 2, dest[j * 2]); - assert_equal(dest[j * 2 + 1], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", i, j * 2 + 1, dest[j * 2 + 1], j, data[i].data[j]); + assert_equal(dest[j * 2 + 1], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", + i, j * 2 + 1, dest[j * 2 + 1], j, data[i].data[j]); } } } @@ -900,21 +913,24 @@ static void test_utf8_to_eci_utf16le(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); if (data[i].expected) { ret = memcmp(dest, data[i].expected, data[i].expected_length); assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret); } else { int j; for (j = 0; j < length; j++) { - assert_equal(dest[j * 2], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", i, j * 2, dest[j * 2], j, data[i].data[j]); + assert_equal(dest[j * 2], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", + i, j * 2, dest[j * 2], j, data[i].data[j]); assert_zero(dest[j * 2 + 1], "i:%d dest[%d] %d != 0\n", i, j * 2 + 1, dest[j * 2 + 1]); } } @@ -962,14 +978,16 @@ static void test_utf8_to_eci_utf32be(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); if (data[i].expected) { ret = memcmp(dest, data[i].expected, data[i].expected_length); assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret); @@ -979,7 +997,8 @@ static void test_utf8_to_eci_utf32be(const testCtx *const p_ctx) { assert_zero(dest[j * 4], "i:%d dest[%d] %d != 0\n", i, j * 4, dest[j * 4]); assert_zero(dest[j * 4 + 1], "i:%d dest[%d] %d != 0\n", i, j * 4 + 1, dest[j * 4 + 1]); assert_zero(dest[j * 4 + 2], "i:%d dest[%d] %d != 0\n", i, j * 4 + 2, dest[j * 4 + 2]); - assert_equal(dest[j * 4 + 3], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", i, j * 4 + 3, dest[j * 4 + 3], j, data[i].data[j]); + assert_equal(dest[j * 4 + 3], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", + i, j * 4 + 3, dest[j * 4 + 3], j, data[i].data[j]); } } } @@ -1026,21 +1045,24 @@ static void test_utf8_to_eci_utf32le(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); if (data[i].expected) { ret = memcmp(dest, data[i].expected, data[i].expected_length); assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret); } else { int j; for (j = 0; j < length; j++) { - assert_equal(dest[j * 4], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", i, j * 4, dest[j * 4], j, data[i].data[j]); + assert_equal(dest[j * 4], data[i].data[j], "i:%d dest[%d] %d != data[%d] %d\n", + i, j * 4, dest[j * 4], j, data[i].data[j]); assert_zero(dest[j * 4 + 1], "i:%d dest[%d] %d != 0\n", i, j * 4 + 1, dest[j * 4 + 1]); assert_zero(dest[j * 4 + 2], "i:%d dest[%d] %d != 0\n", i, j * 4 + 2, dest[j * 4 + 2]); assert_zero(dest[j * 4 + 3], "i:%d dest[%d] %d != 0\n", i, j * 4 + 3, dest[j * 4 + 3]); @@ -1094,14 +1116,16 @@ static void test_utf8_to_eci_sjis(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); } } @@ -1140,14 +1164,16 @@ static void test_utf8_to_eci_big5(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); } } @@ -1186,14 +1212,16 @@ static void test_utf8_to_eci_gb2312(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); } } @@ -1232,14 +1260,16 @@ static void test_utf8_to_eci_euc_kr(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); } } @@ -1278,14 +1308,16 @@ static void test_utf8_to_eci_gbk(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); } } @@ -1324,14 +1356,16 @@ static void test_utf8_to_eci_gb18030(const testCtx *const p_ctx) { length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data); out_length = length; - eci_length = get_eci_length(eci, (const unsigned char *) data[i].data, length); + eci_length = zint_get_eci_length(eci, (const unsigned char *) data[i].data, length); assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length); - ret = utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); - assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_utf8_to_eci(eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length); + assert_equal(ret, data[i].ret, "i:%d zint_utf8_to_eci ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { - assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", i, out_length, data[i].expected_length); - assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", i, out_length, eci_length); + assert_equal(out_length, data[i].expected_length, "i:%d length %d != %d\n", + i, out_length, data[i].expected_length); + assert_nonzero(out_length <= eci_length, "i:%d out_length %d > eci_length %d\n", + i, out_length, eci_length); } } @@ -1376,10 +1410,12 @@ static void test_is_eci_convertible_segs(const testCtx *const p_ctx) { for (j = 0; j < 3; j++) convertible[j] = -1; - ret = is_eci_convertible_segs(data[i].segs, seg_count, convertible); - assert_equal(ret, data[i].ret, "i:%d is_eci_convertible_segs ret %d != %d\n", i, ret, data[i].ret); + ret = zint_is_eci_convertible_segs(data[i].segs, seg_count, convertible); + assert_equal(ret, data[i].ret, "i:%d zint_is_eci_convertible_segs ret %d != %d\n", i, ret, data[i].ret); for (j = 0; j < 3; j++) { - assert_equal(convertible[j], data[i].expected_convertible[j], "i:%d is_eci_convertible_segs convertible[%d] %d != %d\n", i, j, convertible[j], data[i].expected_convertible[j]); + assert_equal(convertible[j], data[i].expected_convertible[j], + "i:%d zint_is_eci_convertible_segs convertible[%d] %d != %d\n", + i, j, convertible[j], data[i].expected_convertible[j]); } } @@ -1413,8 +1449,8 @@ static void test_get_best_eci(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; - ret = get_best_eci((const unsigned char *) data[i].data, length); - assert_equal(ret, data[i].ret, "i:%d get_best_eci ret %d != %d\n", i, ret, data[i].ret); + ret = zint_get_best_eci((const unsigned char *) data[i].data, length); + assert_equal(ret, data[i].ret, "i:%d zint_get_best_eci ret %d != %d\n", i, ret, data[i].ret); } testFinish(); @@ -1454,12 +1490,13 @@ static void test_get_best_eci_segs(const testCtx *const p_ctx) { for (j = 0, seg_count = 0; j < 3 && data[i].segs[j].length; j++, seg_count++); for (j = 0; j < seg_count; j++) { - if (data[i].segs[j].length < 0) data[i].segs[j].length = (int) ustrlen(data[i].segs[j].source); + if (data[i].segs[j].length < 0) data[i].segs[j].length = (int) z_ustrlen(data[i].segs[j].source); } - ret = get_best_eci_segs(symbol, data[i].segs, seg_count); - assert_equal(ret, data[i].ret, "i:%d get_best_eci_segs ret %d != %d\n", i, ret, data[i].ret); - assert_equal(symbol->eci, data[i].expected_symbol_eci, "i:%d get_best_eci_segs symbol->eci %d != %d\n", i, symbol->eci, data[i].expected_symbol_eci); + ret = zint_get_best_eci_segs(symbol, data[i].segs, seg_count); + assert_equal(ret, data[i].ret, "i:%d zint_get_best_eci_segs ret %d != %d\n", i, ret, data[i].ret); + assert_equal(symbol->eci, data[i].expected_symbol_eci, "i:%d zint_get_best_eci_segs symbol->eci %d != %d\n", + i, symbol->eci, data[i].expected_symbol_eci); ZBarcode_Delete(symbol); } diff --git a/backend/tests/test_emf.c b/backend/tests/test_emf.c index 31940d25..a7eb0964 100644 --- a/backend/tests/test_emf.c +++ b/backend/tests/test_emf.c @@ -233,7 +233,7 @@ static void test_print(const testCtx *const p_ctx) { testFinish(); } -INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle); +INTERNAL int zint_emf_plot(struct zint_symbol *symbol, int rotate_angle); static void test_outfile(const testCtx *const p_ctx) { int ret; @@ -257,13 +257,13 @@ static void test_outfile(const testCtx *const p_ctx) { static char expected_errtxt[] = "640: Could not open EMF output file ("; (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "emf_plot testUtilCreateROFile(%s) fail (%d: %s)\n", + assert_nonzero(testUtilCreateROFile(symbol.outfile), "zint_emf_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = emf_plot(&symbol, 0); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "emf_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", + ret = zint_emf_plot(&symbol, 0); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "zint_emf_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "emf_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", + assert_zero(testUtilRmROFile(symbol.outfile), "zint_emf_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); @@ -272,13 +272,13 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.output_options |= BARCODE_STDOUT; printf("<<output_options |= BARCODE_MEMORY_FILE; } - assert_nonzero(fm_open(fmp, symbol, "w"), "i:%d: fm_open fail (%d, %s)\n", + assert_nonzero(zint_fm_open(fmp, symbol, "w"), "i:%d: zint_fm_open fail (%d, %s)\n", i, fmp->err, strerror(fmp->err)); if (j == 1) { #ifndef ZINT_TEST_NO_FMEMOPEN @@ -197,9 +197,9 @@ static void test_putsf(const testCtx *const p_ctx) { } } - fm_putsf(data[i].prefix, data[i].dp, data[i].arg, fmp); + zint_fm_putsf(data[i].prefix, data[i].dp, data[i].arg, fmp); - assert_nonzero(fm_close(fmp, symbol), "i:%d: fm_close fail (%d, %s)\n", i, fmp->err, strerror(fmp->err)); + assert_nonzero(zint_fm_close(fmp, symbol), "i:%d: zint_fm_close fail (%d, %s)\n", i, fmp->err, strerror(fmp->err)); if (locale) { assert_nonnull(setlocale(LC_ALL, locale), "i:%d: setlocale(%s) restore fail (%d, %s)\n", @@ -263,14 +263,14 @@ static void test_printf(const testCtx *const p_ctx) { } else { symbol->output_options |= BARCODE_MEMORY_FILE; } - ret = fm_open(fmp, symbol, "wb"); - assert_equal(ret, 1, "fm_open ret %d != 1\n", ret); + ret = zint_fm_open(fmp, symbol, "wb"); + assert_equal(ret, 1, "zint_fm_open ret %d != 1\n", ret); - ret = fm_printf(fmp, fmt1, "gosh", 123, "gee"); - assert_equal(ret, 1, "fm_printf ret %d != 1\n", ret); + ret = zint_fm_printf(fmp, fmt1, "gosh", 123, "gee"); + assert_equal(ret, 1, "zint_fm_printf ret %d != 1\n", ret); - ret = fm_close(fmp, symbol); - assert_equal(ret, 1, "fm_close ret %d != 1\n", ret); + ret = zint_fm_close(fmp, symbol); + assert_equal(ret, 1, "zint_fm_close ret %d != 1\n", ret); expected_size = (int) strlen(expected); @@ -301,14 +301,14 @@ static void test_printf(const testCtx *const p_ctx) { } else { symbol->output_options |= BARCODE_MEMORY_FILE; } - ret = fm_open(fmp, symbol, "w"); - assert_equal(ret, 1, "fm_open ret %d != 1\n", ret); + ret = zint_fm_open(fmp, symbol, "w"); + assert_equal(ret, 1, "zint_fm_open ret %d != 1\n", ret); - ret = fm_printf(fmp, fmt1, "gosh", 123, "gee"); - assert_equal(ret, 1, "fm_printf ret %d != 1\n", ret); + ret = zint_fm_printf(fmp, fmt1, "gosh", 123, "gee"); + assert_equal(ret, 1, "zint_fm_printf ret %d != 1\n", ret); - ret = fm_close(fmp, symbol); - assert_equal(ret, 1, "fm_close ret %d != 1\n", ret); + ret = zint_fm_close(fmp, symbol); + assert_equal(ret, 1, "zint_fm_close ret %d != 1\n", ret); expected_size = (int) strlen(expected); @@ -358,63 +358,63 @@ static void test_seek(const testCtx *const p_ctx) { } else { symbol->output_options |= BARCODE_MEMORY_FILE; } - ret = fm_open(fmp, symbol, "wb"); - assert_equal(ret, 1, "j:%d fm_open ret %d != 1\n", j, ret); + ret = zint_fm_open(fmp, symbol, "wb"); + assert_equal(ret, 1, "j:%d zint_fm_open ret %d != 1\n", j, ret); - ret = fm_puts("1234567890", fmp); - assert_equal(ret, 1, "j:%d fm_puts ret %d != 1\n", j, ret); + ret = zint_fm_puts("1234567890", fmp); + assert_equal(ret, 1, "j:%d zint_fm_puts ret %d != 1\n", j, ret); if (j != 1) { assert_nonnull(fmp->mem, "mem NULL (%d: %s)\n", fmp->err, strerror(fmp->err)); assert_equal(fmp->mempos, 10, "mempos %d != 10\n", (int) fmp->mempos); assert_zero(memcmp(fmp->mem, "1234567890", fmp->mempos), "memcmp fail\n"); } - ret = fm_seek(fmp, -10, SEEK_CUR); - assert_equal(ret, 1, "j:%d fm_seek ret %d != 1 (%d: %s)\n", j, ret, fmp->err, strerror(fmp->err)); - ret = fm_error(fmp); - assert_zero(ret, "j:%d fm_error ret %d != 0\n", j, ret); - ret = (int) fm_tell(fmp); - assert_zero(ret, "j:%d fm_tell ret %d != 0\n", j, ret); + ret = zint_fm_seek(fmp, -10, SEEK_CUR); + assert_equal(ret, 1, "j:%d zint_fm_seek ret %d != 1 (%d: %s)\n", j, ret, fmp->err, strerror(fmp->err)); + ret = zint_fm_error(fmp); + assert_zero(ret, "j:%d zint_fm_error ret %d != 0\n", j, ret); + ret = (int) zint_fm_tell(fmp); + assert_zero(ret, "j:%d zint_fm_tell ret %d != 0\n", j, ret); - ret = fm_seek(fmp, 0, SEEK_END); - assert_equal(ret, 1, "j:%d fm_seek ret %d != 1\n", j, ret); - ret = fm_error(fmp); - assert_zero(ret, "j:%d fm_error ret %d != 0\n", j, ret); - ret = (int) fm_tell(fmp); - assert_equal(ret, 10, "j:%d fm_tell ret %d != 10\n", j, ret); + ret = zint_fm_seek(fmp, 0, SEEK_END); + assert_equal(ret, 1, "j:%d zint_fm_seek ret %d != 1\n", j, ret); + ret = zint_fm_error(fmp); + assert_zero(ret, "j:%d zint_fm_error ret %d != 0\n", j, ret); + ret = (int) zint_fm_tell(fmp); + assert_equal(ret, 10, "j:%d zint_fm_tell ret %d != 10\n", j, ret); - ret = fm_seek(fmp, -1, SEEK_SET); - assert_zero(ret, "j:%d fm_seek ret %d != 1\n", j, ret); + ret = zint_fm_seek(fmp, -1, SEEK_SET); + assert_zero(ret, "j:%d zint_fm_seek ret %d != 1\n", j, ret); assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err)); - ret = fm_close(fmp, symbol); - assert_zero(ret, "j:%d fm_close ret %d != 0\n", j, ret); + ret = zint_fm_close(fmp, symbol); + assert_zero(ret, "j:%d zint_fm_close ret %d != 0\n", j, ret); assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err)); if (j == 1) { assert_zero(testUtilRemove(symbol->outfile), "testUtilRemove(%s) != 0\n", symbol->outfile); } - ret = fm_open(fmp, symbol, "wb"); - assert_equal(ret, 1, "j:%d fm_open ret %d != 1\n", j, ret); + ret = zint_fm_open(fmp, symbol, "wb"); + assert_equal(ret, 1, "j:%d zint_fm_open ret %d != 1\n", j, ret); - ret = fm_seek(fmp, LONG_MAX, SEEK_CUR); + ret = zint_fm_seek(fmp, LONG_MAX, SEEK_CUR); if (j == 1) { /* May work on some file systems */ if (ret == 0) { assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err)); } } else { - assert_zero(ret, "j:%d fm_seek ret %d != 0\n", j, ret); + assert_zero(ret, "j:%d zint_fm_seek ret %d != 0\n", j, ret); assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err)); } - ret = fm_close(fmp, symbol); + ret = zint_fm_close(fmp, symbol); if (j == 1) { /* See above */ if (ret == 0) { assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err)); } } else { - assert_zero(ret, "j:%d fm_close ret %d != 0\n", j, ret); + assert_zero(ret, "j:%d zint_fm_close ret %d != 0\n", j, ret); assert_equal(fmp->err, EINVAL, "j:%d fmp->err %d (%s) != EINVAL\n", j, fmp->err, strerror(fmp->err)); } diff --git a/backend/tests/test_gb18030.c b/backend/tests/test_gb18030.c index 02dd571e..5193e5d6 100644 --- a/backend/tests/test_gb18030.c +++ b/backend/tests/test_gb18030.c @@ -42,7 +42,7 @@ #include "../just_say_gno/gb2312_gnu.c" #endif -INTERNAL int u_gb18030_int_test(const unsigned int u, unsigned int *dest1, unsigned int *dest2); +INTERNAL int zint_test_u_gb18030_int(const unsigned int u, unsigned int *dest1, unsigned int *dest2); /* As control convert to GB 18030 using table generated from GB18030.TXT plus simple processing. The version of GB18030.TXT is jdk-1.4.2/GB18030.TXT taken from @@ -187,9 +187,11 @@ static void test_u_gb18030_int(const testCtx *const p_ctx) { } if (testContinue(p_ctx, i)) continue; val1_1 = val1_2 = val2_1 = val2_2 = 0; - ret = u_gb18030_int_test(i, &val1_1, &val1_2); + ret = zint_test_u_gb18030_int(i, &val1_1, &val1_2); ret2 = u_gb18030_int2(i, &val2_1, &val2_2); - assert_equal(ret, ret2, "i:%d 0x%04X ret %d != ret2 %d, val1_1 0x%04X, val2_1 0x%04X, val1_2 0x%04X, val2_2 0x%04X\n", (int) i, i, ret, ret2, val1_1, val2_1, val1_2, val2_2); + assert_equal(ret, ret2, + "i:%d 0x%04X ret %d != ret2 %d, val1_1 0x%04X, val2_1 0x%04X, val1_2 0x%04X, val2_2 0x%04X\n", + (int) i, i, ret, ret2, val1_1, val2_1, val1_2, val2_2); if (ret2) { assert_equal(val1_1, val2_1, "i:%d 0x%04X val1_1 0x%04X != val2_1 0x%04X\n", (int) i, i, val1_1, val2_1); assert_equal(val1_2, val2_2, "i:%d 0x%04X val1_2 0x%04X != val2_2 0x%04X\n", (int) i, i, val1_2, val2_2); @@ -203,7 +205,7 @@ static void test_u_gb18030_int(const testCtx *const p_ctx) { val1_1 = val1_2 = val2_1 = val2_2 = 0; start = clock(); - ret = u_gb18030_int_test(i, &val1_1, &val1_2); + ret = zint_test_u_gb18030_int(i, &val1_1, &val1_2); total += clock() - start; start = clock(); @@ -212,7 +214,9 @@ static void test_u_gb18030_int(const testCtx *const p_ctx) { } } - assert_equal(ret, ret2, "i:%d 0x%04X ret %d != ret2 %d, val1_1 0x%04X, val2_1 0x%04X, val1_2 0x%04X, val2_2 0x%04X\n", (int) i, i, ret, ret2, val1_1, val2_1, val1_2, val2_2); + assert_equal(ret, ret2, + "i:%d 0x%04X ret %d != ret2 %d, val1_1 0x%04X, val2_1 0x%04X, val1_2 0x%04X, val2_2 0x%04X\n", + (int) i, i, ret, ret2, val1_1, val2_1, val1_2, val2_2); if (ret2) { assert_equal(val1_1, val2_1, "i:%d 0x%04X val1_1 0x%04X != val2_1 0x%04X\n", (int) i, i, val1_1, val2_1); assert_equal(val1_2, val2_2, "i:%d 0x%04X val1_2 0x%04X != val2_2 0x%04X\n", (int) i, i, val1_2, val2_2); @@ -222,14 +226,16 @@ static void test_u_gb18030_int(const testCtx *const p_ctx) { /* u_gb18030() assumes valid Unicode so now returns a nonsense value here */ val1_1 = val1_2 = 0; - ret = u_gb18030_int_test(0x110000, &val1_1, &val1_2); /* Invalid Unicode codepoint */ + ret = zint_test_u_gb18030_int(0x110000, &val1_1, &val1_2); /* Invalid Unicode codepoint */ assert_equal(ret, 4, "0x110000 ret %d != 4, val1_1 0x%04X, val1_2 0x%04X\n", ret, val1_1, val1_2); for (i = 0; i < ARRAY_SIZE(nonpua_nonbmp); i++) { val1_1 = val1_2 = 0; - ret = u_gb18030_int_test(nonpua_nonbmp[i], &val1_1, &val1_2); - assert_equal(ret, 2, "i:%d 0x%04X ret %d != 2, val1_1 0x%04X, val1_2 0x%04X\n", (int) i, nonpua_nonbmp[i], ret, val1_1, val1_2); - assert_equal(val1_1, nonpua_nonbmp_vals[i], "i:%d 0x%04X val1_1 0x%04X != 0x%04X\n", (int) i, nonpua_nonbmp[i], val1_1, nonpua_nonbmp_vals[i]); + ret = zint_test_u_gb18030_int(nonpua_nonbmp[i], &val1_1, &val1_2); + assert_equal(ret, 2, "i:%d 0x%04X ret %d != 2, val1_1 0x%04X, val1_2 0x%04X\n", + (int) i, nonpua_nonbmp[i], ret, val1_1, val1_2); + assert_equal(val1_1, nonpua_nonbmp_vals[i], "i:%d 0x%04X val1_1 0x%04X != 0x%04X\n", + (int) i, nonpua_nonbmp[i], val1_1, nonpua_nonbmp_vals[i]); assert_zero(val1_2, "i:%d 0x%04X val1_2 0x%04X != 0\n", (int) i, nonpua_nonbmp[i], val1_2); } @@ -294,13 +300,15 @@ static void test_gb18030_utf8(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - ret = gb18030_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, gbdata); + ret = zint_gb18030_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, gbdata); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); if (ret == 0) { int j; - assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); + assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", + i, ret_length, data[i].ret_length); for (j = 0; j < (int) ret_length; j++) { - assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] 0x%04X != 0x%04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); + assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] 0x%04X != 0x%04X\n", + i, j, gbdata[j], data[i].expected_gbdata[j]); } } } @@ -411,13 +419,16 @@ static void test_gb18030_utf8_to_eci(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - ret = gb18030_utf8_to_eci(data[i].eci, (unsigned char *) data[i].data, &ret_length, gbdata, data[i].full_multibyte); + ret = zint_gb18030_utf8_to_eci(data[i].eci, (unsigned char *) data[i].data, &ret_length, gbdata, + data[i].full_multibyte); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { int j; - assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); + assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", + i, ret_length, data[i].ret_length); for (j = 0; j < (int) ret_length; j++) { - assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] 0x%04X != 0x%04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); + assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] 0x%04X != 0x%04X\n", + i, j, gbdata[j], data[i].expected_gbdata[j]); } } } @@ -425,7 +436,7 @@ static void test_gb18030_utf8_to_eci(const testCtx *const p_ctx) { testFinish(); } -INTERNAL void gb18030_cpy_test(const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL void zint_test_gb18030_cpy(const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte); static void test_gb18030_cpy(const testCtx *const p_ctx) { @@ -468,17 +479,18 @@ static void test_gb18030_cpy(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - gb18030_cpy_test((unsigned char *) data[i].data, &ret_length, gbdata, data[i].full_multibyte); + zint_test_gb18030_cpy((unsigned char *) data[i].data, &ret_length, gbdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); for (j = 0; j < (int) ret_length; j++) { - assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); + assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", + i, j, gbdata[j], data[i].expected_gbdata[j]); } } testFinish(); } -INTERNAL int u_gbk_int_test(const unsigned int u, unsigned int *dest); +INTERNAL int zint_test_u_gbk_int(const unsigned int u, unsigned int *dest); /* Control for GBK */ static int u_gbk_int2(unsigned int u, unsigned int *dest) { @@ -517,9 +529,10 @@ static void test_u_gbk_int(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; val = val2 = 0; - ret = u_gbk_int_test(i, &val); + ret = zint_test_u_gbk_int(i, &val); ret2 = u_gbk_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); + 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); } @@ -574,7 +587,9 @@ static void test_perf(const testCtx *const p_ctx) { return; } - for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment); + 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); @@ -591,7 +606,7 @@ static void test_perf(const testCtx *const p_ctx) { ret_length = length; start = clock(); - ret = gb18030_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, ddata); + ret = zint_gb18030_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, ddata); diff += clock() - start; #ifdef TEST_JUST_SAY_GNO @@ -603,20 +618,22 @@ static void test_perf(const testCtx *const p_ctx) { ret_length = length; start = clock(); - (void)utf8_to_eci(32, (unsigned char *) data[i].data, dest, &ret_length); + (void)zint_utf8_to_eci(32, (unsigned char *) data[i].data, dest, &ret_length); diff_eci += clock() - start; } assert_equal(ret, ret2, "i:%d ret %d != ret2 %d\n", (int) i, ret, ret2); printf("%*s: new % 8gms, gno % 8gms ratio % 9g, eci %gms\n", comment_max, data[i].comment, - TEST_PERF_TIME(diff), TEST_PERF_TIME(diff_gno), TEST_PERF_RATIO(diff, diff_gno), TEST_PERF_TIME(diff_eci)); + TEST_PERF_TIME(diff), TEST_PERF_TIME(diff_gno), TEST_PERF_RATIO(diff, diff_gno), + TEST_PERF_TIME(diff_eci)); total += diff; total_gno += diff_gno; } if (p_ctx->index == -1) { printf("%*s: new % 8gms, gno % 8gms ratio % 9g, eci %gms\n", comment_max, "totals", - TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno), TEST_PERF_TIME(total_eci)); + TEST_PERF_TIME(total), TEST_PERF_TIME(total_gno), TEST_PERF_RATIO(total, total_gno), + TEST_PERF_TIME(total_eci)); } } diff --git a/backend/tests/test_gb2312.c b/backend/tests/test_gb2312.c index d4aa9abf..083f477c 100644 --- a/backend/tests/test_gb2312.c +++ b/backend/tests/test_gb2312.c @@ -40,7 +40,7 @@ #include "../just_say_gno/gb2312_gnu.c" #endif -INTERNAL int u_gb2312_int_test(const unsigned int u, unsigned int *d); +INTERNAL int zint_test_u_gb2312_int(const unsigned int u, unsigned int *d); /* As control convert to GB 2312 using simple table generated from unicode.org GB2312.TXT plus simple processing */ /* GB2312.TXT no longer on unicode.org site but available from https://haible.de/bruno/charsets/conversion-tables/GB2312.html */ @@ -106,9 +106,10 @@ static void test_u_gb2312_int(const testCtx *const p_ctx) { } if (testContinue(p_ctx, i)) continue; val = val2 = 0; - ret = u_gb2312_int_test(i, &val); + ret = zint_test_u_gb2312_int(i, &val); ret2 = u_gb2312_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); + 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); } @@ -123,7 +124,7 @@ static void test_u_gb2312_int(const testCtx *const p_ctx) { val = val2 = 0; start = clock(); - ret = u_gb2312_int_test(i, &val); + ret = zint_test_u_gb2312_int(i, &val); total += clock() - start; start = clock(); @@ -132,7 +133,8 @@ static void test_u_gb2312_int(const testCtx *const p_ctx) { } } - 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); + 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); } @@ -200,13 +202,15 @@ static void test_gb2312_utf8(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - ret = gb2312_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, gbdata); + ret = zint_gb2312_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, gbdata); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); if (ret == 0) { int j; - assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); + assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", + i, ret_length, data[i].ret_length); for (j = 0; j < (int) ret_length; j++) { - assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); + assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", + i, j, gbdata[j], data[i].expected_gbdata[j]); } } } @@ -302,13 +306,16 @@ static void test_gb2312_utf8_to_eci(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - ret = gb2312_utf8_to_eci(data[i].eci, (unsigned char *) data[i].data, &ret_length, gbdata, data[i].full_multibyte); + ret = zint_gb2312_utf8_to_eci(data[i].eci, (unsigned char *) data[i].data, &ret_length, gbdata, + data[i].full_multibyte); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { int j; - assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); + assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", + i, ret_length, data[i].ret_length); for (j = 0; j < (int) ret_length; j++) { - assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] 0x%04X != 0x%04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); + assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] 0x%04X != 0x%04X\n", + i, j, gbdata[j], data[i].expected_gbdata[j]); } } } @@ -316,7 +323,7 @@ static void test_gb2312_utf8_to_eci(const testCtx *const p_ctx) { testFinish(); } -INTERNAL void gb2312_cpy_test(const unsigned char source[], int *p_length, unsigned int *ddata, +INTERNAL void zint_test_gb2312_cpy(const unsigned char source[], int *p_length, unsigned int *ddata, const int full_multibyte); static void test_gb2312_cpy(const testCtx *const p_ctx) { @@ -359,10 +366,11 @@ static void test_gb2312_cpy(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - gb2312_cpy_test((unsigned char *) data[i].data, &ret_length, gbdata, data[i].full_multibyte); + zint_test_gb2312_cpy((unsigned char *) data[i].data, &ret_length, gbdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); for (j = 0; j < (int) ret_length; j++) { - assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", i, j, gbdata[j], data[i].expected_gbdata[j]); + assert_equal(gbdata[j], data[i].expected_gbdata[j], "i:%d gbdata[%d] %04X != %04X\n", + i, j, gbdata[j], data[i].expected_gbdata[j]); } } @@ -413,7 +421,9 @@ static void test_perf(const testCtx *const p_ctx) { return; } - for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment); + 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); @@ -430,7 +440,7 @@ static void test_perf(const testCtx *const p_ctx) { ret_length = length; start = clock(); - ret = gb2312_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, ddata); + ret = zint_gb2312_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, ddata); diff += clock() - start; #ifdef TEST_JUST_SAY_GNO @@ -443,19 +453,20 @@ static void test_perf(const testCtx *const p_ctx) { ret_length = length; start = clock(); - (void)utf8_to_eci(29, (unsigned char *) data[i].data, dest, &ret_length); + (void)zint_utf8_to_eci(29, (unsigned char *) data[i].data, dest, &ret_length); diff_eci += clock() - start; #ifdef TEST_JUST_SAY_GNO ret_length2 = length; start = clock(); - (void)utf8_to_eci_wctomb(29, (unsigned char *) data[i].data, dest2, &ret_length2); + (void)zint_utf8_to_eci_wctomb(29, (unsigned char *) data[i].data, dest2, &ret_length2); diff_eci_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 % 9g | eci % 8gms, gno % 8gms ratio %g\n", comment_max, data[i].comment, + printf("%*s: new % 8gms, gno % 8gms ratio % 9g | eci % 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), TEST_PERF_TIME(diff_eci), TEST_PERF_TIME(diff_eci_gno), TEST_PERF_RATIO(diff_eci, diff_eci_gno)); diff --git a/backend/tests/test_gif.c b/backend/tests/test_gif.c index ce276d01..cbcc19e2 100644 --- a/backend/tests/test_gif.c +++ b/backend/tests/test_gif.c @@ -31,7 +31,7 @@ #include "testcommon.h" -INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); +INTERNAL int zint_gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); static void test_pixel_plot(const testCtx *const p_ctx) { int debug = p_ctx->debug; @@ -86,20 +86,21 @@ static void test_pixel_plot(const testCtx *const p_ctx) { symbol->debug |= debug; size = data[i].width * data[i].height; - assert_nonzero(size < (int) sizeof(data_buf), "i:%d gif_pixel_plot size %d < sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf)); + assert_nonzero(size < (int) sizeof(data_buf), "i:%d zint_gif_pixel_plot size %d < sizeof(data_buf) %d\n", + i, size, (int) sizeof(data_buf)); if (data[i].repeat) { testUtilStrCpyRepeat(data_buf, data[i].pattern, size); } else { strcpy(data_buf, data[i].pattern); } - assert_equal(size, (int) strlen(data_buf), "i:%d gif_pixel_plot size %d != strlen(data_buf) %d\n", + assert_equal(size, (int) strlen(data_buf), "i:%d zint_gif_pixel_plot size %d != strlen(data_buf) %d\n", i, size, (int) strlen(data_buf)); symbol->bitmap = (unsigned char *) data_buf; - ret = gif_pixel_plot(symbol, (unsigned char *) data_buf); - assert_equal(ret, data[i].ret, "i:%d gif_pixel_plot ret %d != %d (%s)\n", + ret = zint_gif_pixel_plot(symbol, (unsigned char *) data_buf); + assert_equal(ret, data[i].ret, "i:%d zint_gif_pixel_plot ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); if (ret < ZINT_ERROR) { @@ -335,13 +336,13 @@ static void test_outfile(const testCtx *const p_ctx) { (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ assert_nonzero(testUtilCreateROFile(symbol.outfile), - "gif_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", + "zint_gif_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = gif_pixel_plot(&symbol, data); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "gif_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", + ret = zint_gif_pixel_plot(&symbol, data); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "zint_gif_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "gif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", + assert_zero(testUtilRmROFile(symbol.outfile), "zint_gif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); @@ -349,9 +350,9 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.output_options |= BARCODE_STDOUT; - ret = gif_pixel_plot(&symbol, data); + ret = zint_gif_pixel_plot(&symbol, data); printf(" - ignore (GIF to stdout)\n"); fflush(stdout); - assert_zero(ret, "gif_pixel_plot ret %d != 0 (%s)\n", ret, symbol.errtxt); + assert_zero(ret, "zint_gif_pixel_plot ret %d != 0 (%s)\n", ret, symbol.errtxt); testFinish(); } diff --git a/backend/tests/test_gridmtx.c b/backend/tests/test_gridmtx.c index 470758cb..4ce771d0 100644 --- a/backend/tests/test_gridmtx.c +++ b/backend/tests/test_gridmtx.c @@ -877,9 +877,9 @@ static void test_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[8192]; char escaped2[8192]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, \"%s\",\n", i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, diff --git a/backend/tests/test_gs1.c b/backend/tests/test_gs1.c index c8ae4704..a0215f5a 100644 --- a/backend/tests/test_gs1.c +++ b/backend/tests/test_gs1.c @@ -1584,7 +1584,7 @@ static void test_gs1_verify(const testCtx *const p_ctx) { length = (int) strlen(data[i].data); - ret = gs1_verify(symbol, ZUCP(data[i].data), &length, ZUCP(reduced), &reduced_length); + ret = zint_gs1_verify(symbol, ZUCP(data[i].data), &length, ZUCP(reduced), &reduced_length); if (p_ctx->generate) { printf(" /*%3d*/ { \"%s\", %s, \"%s\", \"%s\" },\n", @@ -2294,7 +2294,7 @@ static void test_gs1_lint(const testCtx *const p_ctx) { length = (int) strlen(data[i].data); - ret = gs1_verify(symbol, ZUCP(data[i].data), &length, ZUCP(reduced), &reduced_length); + ret = zint_gs1_verify(symbol, ZUCP(data[i].data), &length, ZUCP(reduced), &reduced_length); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (length %d \"%s\") (%s)\n", i, ret, data[i].ret, length, data[i].data, symbol->errtxt); diff --git a/backend/tests/test_hanxin.c b/backend/tests/test_hanxin.c index 34c2f49e..ac9a0da1 100644 --- a/backend/tests/test_hanxin.c +++ b/backend/tests/test_hanxin.c @@ -3549,9 +3549,9 @@ static void test_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[8192]; char escaped2[8192]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %d, %d, %s, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, \"%s\",\n", i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(BARCODE_HANXIN, data[i].option_3), @@ -3580,7 +3580,7 @@ static void test_encode_segs(const testCtx *const p_ctx) { i, testUtilBarcodeName(symbol->symbology)); } } else { - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; if (testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source, length, debug)) { int cmp_len, ret_len; char modules_dump[49152]; diff --git a/backend/tests/test_ksx1001.c b/backend/tests/test_ksx1001.c index e8015e84..b23de042 100644 --- a/backend/tests/test_ksx1001.c +++ b/backend/tests/test_ksx1001.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2021-2022 Robin Stuart + Copyright (C) 2021-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -40,12 +40,12 @@ #include "../just_say_gno/ksx1001_gnu.h" #endif -INTERNAL int u_ksx1001_test(const unsigned int u, unsigned char *dest); +INTERNAL int zint_test_u_ksx1001(const unsigned int u, unsigned char *dest); /* Version of `u_ksx1001()` taking unsigned int destination for backward-compatible testing */ static int u_ksx1001_int(const unsigned int u, unsigned int *d) { unsigned char dest[2] = {0}; /* Suppress clang -fsanitize=memory false positive */ - int ret = u_ksx1001_test(u, dest); + int ret = zint_test_u_ksx1001(u, dest); if (ret) { *d = ret == 1 ? dest[0] : ((dest[0] << 8) | dest[1]); } @@ -127,7 +127,8 @@ static void test_u_ksx1001_int(const testCtx *const p_ctx) { val = val2 = 0; ret = u_ksx1001_int(i, &val); ret2 = u_ksx1001_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); + 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); } @@ -150,7 +151,8 @@ static void test_u_ksx1001_int(const testCtx *const p_ctx) { } } - 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); + 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) { val2 += 0x8080; /* `ksx1001_wctomb_zint()` returns pure KS X 1001 values, convert to EUC-KR */ assert_equal(val, val2, "i:%d 0x%04X val 0x%04X != val2 0x%04X\n", (int) i, i, val, val2); diff --git a/backend/tests/test_large.c b/backend/tests/test_large.c index afdf8ae1..777f4da9 100644 --- a/backend/tests/test_large.c +++ b/backend/tests/test_large.c @@ -56,7 +56,7 @@ #define LI(l, h) { l, h } -INTERNAL int clz_u64_test(uint64_t x); +INTERNAL int zint_test_clz_u64(uint64_t x); static void test_clz_u64(const testCtx *const p_ctx) { @@ -202,7 +202,7 @@ static void test_clz_u64(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - ret = clz_u64_test(data[i].s); + ret = zint_test_clz_u64(data[i].s); assert_equal(ret, data[i].ret, "i:%d 0x%" LX_FMT "X ret %d != %d\n", i, data[i].s, ret, data[i].ret); } @@ -235,12 +235,16 @@ static void test_load(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - large_load(&data[i].t, &data[i].s); + zint_large_load(&data[i].t, &data[i].s); - assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", - i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", - i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.lo, data[i].expected.lo, + "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + i, data[i].t.lo, zint_large_dump(&data[i].t, t_dump), data[i].expected.lo, + zint_large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.hi, data[i].expected.hi, + "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + i, data[i].t.hi, zint_large_dump(&data[i].t, t_dump), data[i].expected.hi, + zint_large_dump(&data[i].expected, expected_dump)); } testFinish(); @@ -276,12 +280,17 @@ static void test_load_str_u64(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - large_load_str_u64(&data[i].t, (unsigned char *) data[i].s, data[i].length == -1 ? (int) strlen(data[i].s) : data[i].length); + zint_large_load_str_u64(&data[i].t, ZCUCP(data[i].s), + data[i].length == -1 ? (int) strlen(data[i].s) : data[i].length); - assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", - i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", - i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.lo, data[i].expected.lo, + "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + i, data[i].t.lo, zint_large_dump(&data[i].t, t_dump), data[i].expected.lo, + zint_large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.hi, data[i].expected.hi, + "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + i, data[i].t.hi, zint_large_dump(&data[i].t, t_dump), data[i].expected.hi, + zint_large_dump(&data[i].expected, expected_dump)); } testFinish(); @@ -320,12 +329,16 @@ static void test_add_u64(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - large_add_u64(&data[i].t, data[i].s); + zint_large_add_u64(&data[i].t, data[i].s); - assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", - i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", - i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.lo, data[i].expected.lo, + "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + i, data[i].t.lo, zint_large_dump(&data[i].t, t_dump), data[i].expected.lo, + zint_large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.hi, data[i].expected.hi, + "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + i, data[i].t.hi, zint_large_dump(&data[i].t, t_dump), data[i].expected.hi, + zint_large_dump(&data[i].expected, expected_dump)); } testFinish(); @@ -364,12 +377,16 @@ static void test_sub_u64(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - large_sub_u64(&data[i].t, data[i].s); + zint_large_sub_u64(&data[i].t, data[i].s); - assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", - i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", - i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.lo, data[i].expected.lo, + "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + i, data[i].t.lo, zint_large_dump(&data[i].t, t_dump), data[i].expected.lo, + zint_large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.hi, data[i].expected.hi, + "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + i, data[i].t.hi, zint_large_dump(&data[i].t, t_dump), data[i].expected.hi, + zint_large_dump(&data[i].expected, expected_dump)); } testFinish(); @@ -421,12 +438,16 @@ static void test_mul_u64(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - large_mul_u64(&data[i].t, data[i].s); + zint_large_mul_u64(&data[i].t, data[i].s); - assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", - i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", - i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.lo, data[i].expected.lo, + "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + i, data[i].t.lo, zint_large_dump(&data[i].t, t_dump), data[i].expected.lo, + zint_large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.hi, data[i].expected.hi, + "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + i, data[i].t.hi, zint_large_dump(&data[i].t, t_dump), data[i].expected.hi, + zint_large_dump(&data[i].expected, expected_dump)); } testFinish(); @@ -546,14 +567,19 @@ static void test_div_u64(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - r = large_div_u64(&data[i].t, data[i].s); + r = zint_large_div_u64(&data[i].t, data[i].s); - assert_equalu64(r, data[i].expected_r, "i:%d r %" LX_FMT "u (0x%" LX_FMT "X) != expected_r %" LX_FMT "u (0x%" LX_FMT "X)\n", + assert_equalu64(r, data[i].expected_r, + "i:%d r %" LX_FMT "u (0x%" LX_FMT "X) != expected_r %" LX_FMT "u (0x%" LX_FMT "X)\n", i, r, r, data[i].expected_r, data[i].expected_r); - assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", - i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", - i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.lo, data[i].expected.lo, + "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + i, data[i].t.lo, zint_large_dump(&data[i].t, t_dump), data[i].expected.lo, + zint_large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.hi, data[i].expected.hi, + "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + i, data[i].t.hi, zint_large_dump(&data[i].t, t_dump), data[i].expected.hi, + zint_large_dump(&data[i].expected, expected_dump)); } testFinish(); @@ -712,12 +738,16 @@ static void test_unset_bit(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - large_unset_bit(&data[i].t, data[i].s); + zint_large_unset_bit(&data[i].t, data[i].s); - assert_equalu64(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", - i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump)); - assert_equalu64(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", - i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.lo, data[i].expected.lo, + "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n", + i, data[i].t.lo, zint_large_dump(&data[i].t, t_dump), data[i].expected.lo, + zint_large_dump(&data[i].expected, expected_dump)); + assert_equalu64(data[i].t.hi, data[i].expected.hi, + "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n", + i, data[i].t.hi, zint_large_dump(&data[i].t, t_dump), data[i].expected.hi, + zint_large_dump(&data[i].expected, expected_dump)); } testFinish(); @@ -788,11 +818,13 @@ static void test_uint_array(const testCtx *const p_ctx) { memset(uint_array, 0, sizeof(uint_array)); - large_uint_array(&data[i].t, uint_array, data[i].size, data[i].bits); + zint_large_uint_array(&data[i].t, uint_array, data[i].size, data[i].bits); - assert_zero(memcmp(uint_array, data[i].expected, data[i].size * sizeof(unsigned int)), "i:%d %s uint memcmp != 0\n actual: %s\nexpected: %s\n", - i, large_dump(&data[i].t, t_dump), testUtilUIntArrayDump(uint_array, data[i].size, uint_dump, sizeof(uint_dump)), - testUtilUIntArrayDump(data[i].expected, data[i].size, uint_expected_dump, sizeof(uint_expected_dump))); + assert_zero(memcmp(uint_array, data[i].expected, data[i].size * sizeof(unsigned int)), + "i:%d %s uint memcmp != 0\n actual: %s\nexpected: %s\n", + i, zint_large_dump(&data[i].t, t_dump), + testUtilUIntArrayDump(uint_array, data[i].size, uint_dump, sizeof(uint_dump)), + testUtilUIntArrayDump(data[i].expected, data[i].size, uint_expected_dump, sizeof(uint_expected_dump))); if (data[i].bits <= 8) { int j; @@ -801,11 +833,13 @@ static void test_uint_array(const testCtx *const p_ctx) { uchar_expected_array[j] = data[i].expected[j]; } - large_uchar_array(&data[i].t, uchar_array, data[i].size, data[i].bits); + zint_large_uchar_array(&data[i].t, uchar_array, data[i].size, data[i].bits); - assert_zero(memcmp(uchar_array, uchar_expected_array, data[i].size), "i:%d %s uchar memcmp != 0\n actual: %s\nexpected: %s\n", - i, large_dump(&data[i].t, t_dump), testUtilUCharArrayDump(uchar_array, data[i].size, uchar_dump, sizeof(uchar_dump)), - testUtilUCharArrayDump(uchar_expected_array, data[i].size, uchar_expected_dump, sizeof(uchar_expected_dump))); + assert_zero(memcmp(uchar_array, uchar_expected_array, data[i].size), + "i:%d %s uchar memcmp != 0\n actual: %s\nexpected: %s\n", + i, zint_large_dump(&data[i].t, t_dump), + testUtilUCharArrayDump(uchar_array, data[i].size, uchar_dump, sizeof(uchar_dump)), + testUtilUCharArrayDump(uchar_expected_array, data[i].size, uchar_expected_dump, sizeof(uchar_expected_dump))); } } @@ -879,7 +913,7 @@ static void test_dump(const testCtx *const p_ctx) { memset(dump, 0, sizeof(dump)); - large_dump(&data[i].t, dump); + zint_large_dump(&data[i].t, dump); assert_zero(strcmp(dump, data[i].expected), "i:%d { %" LX_FMT "X, %" LX_FMT "X } strcmp(%s, %s) != 0\n", i, data[i].t.lo, data[i].t.hi, dump, data[i].expected); diff --git a/backend/tests/test_library.c b/backend/tests/test_library.c index ffb88a19..c919e64c 100644 --- a/backend/tests/test_library.c +++ b/backend/tests/test_library.c @@ -383,7 +383,7 @@ static void test_input_data(const testCtx *const p_ctx) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - if (is_composite(data[i].symbology)) { + if (z_is_composite(data[i].symbology)) { text = data[i].composite; strcpy(symbol->primary, data[i].data); } else { @@ -777,7 +777,7 @@ static void test_escape_char_process(const testCtx *const p_ctx) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - if (is_composite(data[i].symbology)) { + if (z_is_composite(data[i].symbology)) { text = data[i].composite; strcpy(symbol->primary, data[i].data); } else { @@ -859,8 +859,8 @@ static void test_escape_char_process(const testCtx *const p_ctx) { testFinish(); } -INTERNAL int escape_char_process_test(struct zint_symbol *symbol, unsigned char *input_string, int *p_length, - unsigned char *escaped_string); +INTERNAL int zint_test_escape_char_process(struct zint_symbol *symbol, const unsigned char *input_string, + int *p_length, unsigned char *escaped_string); static void test_escape_char_process_test(const testCtx *const p_ctx) { @@ -899,8 +899,8 @@ static void test_escape_char_process_test(const testCtx *const p_ctx) { length = (int) strlen(data[i].data); escaped_len = length; - ret = escape_char_process_test(symbol, (unsigned char *) data[i].data, &escaped_len, NULL); - assert_equal(ret, data[i].ret, "i:%d escape_char_process_test(NULL) ret %d != %d (%s)\n", + ret = zint_test_escape_char_process(symbol, (unsigned char *) data[i].data, &escaped_len, NULL); + assert_equal(ret, data[i].ret, "i:%d zint_test_escape_char_process(NULL) ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(escaped_len, data[i].expected_len, "i:%d NULL escaped_len %d != %d\n", i, escaped_len, data[i].expected_len); @@ -908,9 +908,9 @@ static void test_escape_char_process_test(const testCtx *const p_ctx) { memset(escaped, 0xDD, sizeof(escaped)); escaped_len = length; - ret = escape_char_process_test(symbol, (unsigned char *) data[i].data, &escaped_len, + ret = zint_test_escape_char_process(symbol, (unsigned char *) data[i].data, &escaped_len, (unsigned char *) escaped); - assert_equal(ret, data[i].ret, "i:%d escape_char_process_test(escaped) ret %d != %d (%s)\n", + assert_equal(ret, data[i].ret, "i:%d zint_test_escape_char_process(escaped) ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(escaped_len, data[i].expected_len, "i:%d escaped escaped_len %d != %d\n", i, escaped_len, data[i].expected_len); @@ -1200,7 +1200,7 @@ static void test_cap_stackable(const testCtx *const p_ctx) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - if (is_composite(data[i].symbology)) { + if (z_is_composite(data[i].symbology)) { text = "[20]01"; strcpy(symbol->primary, data[i].data); } else { @@ -1277,7 +1277,7 @@ static void test_bindable(const testCtx *const p_ctx) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - if (is_composite(data[i].symbology)) { + if (z_is_composite(data[i].symbology)) { text = "[20]01"; strcpy(symbol->primary, data[i].data); } else { @@ -1310,7 +1310,7 @@ static void test_bindable(const testCtx *const p_ctx) { ZBarcode_Reset(symbol); - if (is_composite(data[i].symbology)) { + if (z_is_composite(data[i].symbology)) { text = "[20]01"; strcpy(symbol->primary, data[i].data); } else { @@ -2105,7 +2105,7 @@ static void test_barcode_name(const testCtx *const p_ctx) { testFinish(); } -INTERNAL int error_tag_test(int error_number, struct zint_symbol *symbol, const int err_id, const char *error_string); +INTERNAL int zint_test_error_tag(int error_number, struct zint_symbol *symbol, const int err_id, const char *error_string); static void test_error_tag(const testCtx *const p_ctx) { @@ -2154,14 +2154,14 @@ static void test_error_tag(const testCtx *const p_ctx) { if (data[i].debug_test) symbol->debug |= ZINT_DEBUG_TEST; symbol->warn_level = data[i].warn_level; - ret = error_tag_test(data[i].error_number, symbol, -1, data[i].data); + ret = zint_test_error_tag(data[i].error_number, symbol, -1, data[i].data); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); if ((int) strlen(data[i].data) < 100) { strcpy(symbol->errtxt, data[i].data); - ret = error_tag_test(data[i].error_number, symbol, -1, NULL); + ret = zint_test_error_tag(data[i].error_number, symbol, -1, NULL); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected); @@ -2171,7 +2171,7 @@ static void test_error_tag(const testCtx *const p_ctx) { testFinish(); } -INTERNAL void strip_bom_test(unsigned char *source, int *input_length); +INTERNAL void zint_test_strip_bom(unsigned char *source, int *input_length); static void test_strip_bom(const testCtx *const p_ctx) { @@ -2186,7 +2186,7 @@ static void test_strip_bom(const testCtx *const p_ctx) { strcpy(buf, data); length = (int) strlen(buf); - strip_bom_test(TU(buf), &length); + zint_test_strip_bom(TU(buf), &length); assert_equal(length, 1, "length %d != 1\n", length); assert_zero(buf[1], "buf[1] %d != 0\n", buf[1]); @@ -2194,7 +2194,7 @@ static void test_strip_bom(const testCtx *const p_ctx) { strcpy(buf, bom_only); length = (int) strlen(buf); - strip_bom_test(TU(buf), &length); + zint_test_strip_bom(TU(buf), &length); assert_equal(length, 3, "BOM only length %d != 3\n", length); ret = strcmp(buf, bom_only); assert_zero(ret, "BOM only strcmp ret %d != 0\n", ret); @@ -2615,7 +2615,7 @@ static void test_scale_from_xdimdp(const testCtx *const p_ctx) { data[i].expected); if (ret) { - dpmm_from_dpi = stripf(roundf(data[i].dpi / 25.4f)); + dpmm_from_dpi = z_stripf(roundf(data[i].dpi / 25.4f)); ret = ZBarcode_Scale_From_XdimDp(data[i].symbology, data[i].x_dim, dpmm_from_dpi, data[i].filetype); assert_equal(ret, data[i].expected, "i:%d ZBarcode_Scale_From_XdimDp(%s, %g (dpi %d), %g, %s) %.8g != %.8g\n", @@ -2626,7 +2626,7 @@ static void test_scale_from_xdimdp(const testCtx *const p_ctx) { /* Non-MAXICODE raster rounds to half-increments */ && (data[i].symbology == BARCODE_MAXICODE || strcmp(data[i].filetype, "gif") != 0)) { x_dim_from_scale = ZBarcode_XdimDp_From_Scale(data[i].symbology, ret, data[i].dpmm, data[i].filetype); - x_dim_from_scale = stripf(stripf(roundf(x_dim_from_scale * 100.0f)) / 100.0f); + x_dim_from_scale = z_stripf(z_stripf(roundf(x_dim_from_scale * 100.0f)) / 100.0f); assert_equal(x_dim_from_scale, data[i].x_dim, "i:%d ZBarcode_XdimDp_From_Scale(%s, %g, %g, %s) %.8g != x_dim %.8g\n", i, testUtilBarcodeName(data[i].symbology), ret, data[i].x_dim, data[i].filetype, @@ -2697,7 +2697,7 @@ static void test_xdimdp_from_scale(const testCtx *const p_ctx) { data[i].expected); if (ret) { - dpmm_from_dpi = stripf(roundf(data[i].dpi / 25.4f)); + dpmm_from_dpi = z_stripf(roundf(data[i].dpi / 25.4f)); ret = ZBarcode_XdimDp_From_Scale(data[i].symbology, data[i].scale, dpmm_from_dpi, data[i].filetype); assert_equal(ret, data[i].expected, "i:%d ZBarcode_XdimDp_From_Scale(%s, %g (dpi %d), %g, %s) %.8g != %.8g\n", @@ -2808,7 +2808,7 @@ static void test_utf8_to_eci(const testCtx *const p_ctx) { "i:%d ZBarcode_UTF8_To_ECI dest_length %d != expected_length %d\n", i, dest_length, expected_length); #if 0 - printf("dest_length %d\n", dest_length); debug_print_escape(TCU(dest), dest_length, NULL); + printf("dest_length %d\n", dest_length); z_debug_print_escape(TCU(dest), dest_length, NULL); printf("\n"); #endif assert_zero(memcmp(dest, data[i].expected, expected_length), @@ -2966,7 +2966,7 @@ static void test_raw_text(const testCtx *const p_ctx) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - if (is_composite(data[i].symbology)) { + if (z_is_composite(data[i].symbology)) { text = "[20]01"; strcpy(symbol->primary, data[i].data); } else { diff --git a/backend/tests/test_maxicode.c b/backend/tests/test_maxicode.c index 9944bc2e..77cec798 100644 --- a/backend/tests/test_maxicode.c +++ b/backend/tests/test_maxicode.c @@ -1831,9 +1831,9 @@ static void test_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %d, %d, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, \"%s\", %s, %d, %d, %d, \"%s\",\n", i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, data[i].structapp.index, data[i].structapp.count, data[i].structapp.id, diff --git a/backend/tests/test_output.c b/backend/tests/test_output.c index 7f07e31a..79b9eb52 100644 --- a/backend/tests/test_output.c +++ b/backend/tests/test_output.c @@ -80,7 +80,7 @@ static void test_check_colour_options(const testCtx *const p_ctx) { strcpy(symbol.bgcolour, data[i].bgcolour); symbol.errtxt[0] = '\0'; - ret = out_check_colour_options(&symbol); + ret = zint_out_check_colour_options(&symbol); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); assert_zero(strcmp(symbol.errtxt, data[i].expected), "i:%d symbol.errtxt (%s) != expected (%s)\n", i, symbol.errtxt, data[i].expected); } @@ -128,7 +128,7 @@ static void test_colour_get_rgb(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - ret = out_colour_get_rgb(data[i].colour, &red, &green, &blue, &alpha); + ret = zint_out_colour_get_rgb(data[i].colour, &red, &green, &blue, &alpha); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_equal(red, data[i].red, "i:%d red 0x%02X (%d) != 0x%02X (%d) (green 0x%02X, blue 0x%02X)\n", i, red, red, data[i].red, data[i].red, green, blue); assert_equal(green, data[i].green, "i:%d green %d (0x%02X) != %d (0x%02X)\n", i, green, green, data[i].green, data[i].green); @@ -141,8 +141,8 @@ static void test_colour_get_rgb(const testCtx *const p_ctx) { } else { sprintf(rgb, "%02X%02X%02X", red, green, blue); } - ret = out_colour_get_cmyk(rgb, &cyan, &magenta, &yellow, &black, &rgb_alpha); - assert_equal(ret, 1 + have_alpha, "i:%d out_colour_get_cmyk(%s) ret %d != %d\n", i, rgb, ret, 1 + have_alpha); + ret = zint_out_colour_get_cmyk(rgb, &cyan, &magenta, &yellow, &black, &rgb_alpha); + assert_equal(ret, 1 + have_alpha, "i:%d zint_out_colour_get_cmyk(%s) ret %d != %d\n", i, rgb, ret, 1 + have_alpha); assert_equal(rgb_alpha, alpha, "i:%d rgb_alpha %d (0x%02X) != %d (0x%02X)\n", i, rgb_alpha, rgb_alpha, alpha, alpha); sprintf(cmyk, "%d,%d,%d,%d", cyan, magenta, yellow, black); @@ -186,15 +186,15 @@ static void test_colour_get_cmyk(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - ret = out_colour_get_cmyk(data[i].colour, &cyan, &magenta, &yellow, &black, &alpha); + ret = zint_out_colour_get_cmyk(data[i].colour, &cyan, &magenta, &yellow, &black, &alpha); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_equal(cyan, data[i].cyan, "i:%d cyan %d != %d (magenta %d, yellow %d, black %d)\n", i, cyan, data[i].cyan, magenta, yellow, black); assert_equal(magenta, data[i].magenta, "i:%d magenta %d != %d\n", i, magenta, data[i].magenta); assert_equal(yellow, data[i].yellow, "i:%d yellow %d != %d\n", i, yellow, data[i].yellow); assert_equal(alpha, data[i].alpha, "i:%d alpha %d != %d\n", i, alpha, data[i].alpha); - ret = out_colour_get_rgb(data[i].colour, &red, &green, &blue, &rgb_alpha); - assert_equal(ret, data[i].ret_rgb, "i:%d out_colour_get_rgb(%s) ret %d != %d\n", i, rgb, ret, data[i].ret_rgb); + ret = zint_out_colour_get_rgb(data[i].colour, &red, &green, &blue, &rgb_alpha); + assert_equal(ret, data[i].ret_rgb, "i:%d zint_out_colour_get_rgb(%s) ret %d != %d\n", i, rgb, ret, data[i].ret_rgb); assert_equal(rgb_alpha, alpha, "i:%d rgb_alpha %d != %d\n", i, rgb_alpha, alpha); sprintf(rgb, "%02X%02X%02X%02X", red, green, blue, rgb_alpha); @@ -204,7 +204,7 @@ static void test_colour_get_cmyk(const testCtx *const p_ctx) { testFinish(); } -INTERNAL int out_quiet_zones_test(const struct zint_symbol *symbol, const int hide_text, const int comp_xoffset, +INTERNAL int zint_test_out_quiet_zones(const struct zint_symbol *symbol, const int hide_text, const int comp_xoffset, float *left, float *right, float *top, float *bottom); static void test_quiet_zones(const testCtx *const p_ctx) { @@ -223,7 +223,7 @@ static void test_quiet_zones(const testCtx *const p_ctx) { symbol->symbology = i; symbol->output_options = BARCODE_QUIET_ZONES; - ret = out_quiet_zones_test(symbol, hide_text, comp_xoffset, &left, &right, &top, &bottom); + ret = zint_test_out_quiet_zones(symbol, hide_text, comp_xoffset, &left, &right, &top, &bottom); if (i != BARCODE_FLAT && i != BARCODE_BC412) { /* Only two which aren't marked as done */ assert_nonzero(ret, "i:%d %s not done\n", i, testUtilBarcodeName(i)); } @@ -284,7 +284,7 @@ static void test_set_whitespace_offsets(const testCtx *const p_ctx) { symbol.whitespace_height = data[i].whitespace_height; symbol.border_width = data[i].border_width; symbol.output_options = data[i].output_options; - out_set_whitespace_offsets(&symbol, data[i].hide_text, data[i].comp_xoffset, + zint_out_set_whitespace_offsets(&symbol, data[i].hide_text, data[i].comp_xoffset, &xoffset, &yoffset, &roffset, &boffset, &qz_right, data[i].scaler, &xoffset_si, &yoffset_si, &roffset_si, &boffset_si, &qz_right_si); assert_equal(xoffset, data[i].expected_xoffset, "i:%d xoffset %g != %g\n", i, xoffset, data[i].expected_xoffset); @@ -389,9 +389,9 @@ static void test_fopen(const testCtx *const p_ctx) { } strcat(outfile, data[i].filename); - ret = out_fopen(outfile, "w"); + ret = zint_out_fopen(outfile, "w"); if (data[i].succeed) { - assert_nonnull(ret, "i:%d out_fopen(%s) == NULL (%d: %s)\n", i, outfile, errno, strerror(errno)); + assert_nonnull(ret, "i:%d zint_out_fopen(%s) == NULL (%d: %s)\n", i, outfile, errno, strerror(errno)); assert_zero(fclose(ret), "i:%d fclose(%s) != 0 (%d: %s)\n", i, outfile, errno, strerror(errno)); assert_nonzero(testUtilExists(outfile), "i:%d testUtilExists(%s) != 0 (%d: %s)\n", i, outfile, errno, strerror(errno)); if (data[i].dir[0]) { @@ -407,7 +407,7 @@ static void test_fopen(const testCtx *const p_ctx) { } } } else { - assert_null(ret, "i:%d out_fopen(%s) == NULL (%d: %s)\n", i, outfile, errno, strerror(errno)); + assert_null(ret, "i:%d zint_out_fopen(%s) == NULL (%d: %s)\n", i, outfile, errno, strerror(errno)); /* TODO: may have left junk around */ } } diff --git a/backend/tests/test_pcx.c b/backend/tests/test_pcx.c index ed889c79..29c69dbe 100644 --- a/backend/tests/test_pcx.c +++ b/backend/tests/test_pcx.c @@ -174,7 +174,7 @@ static void test_print(const testCtx *const p_ctx) { testFinish(); } -INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); +INTERNAL int zint_pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); static void test_outfile(const testCtx *const p_ctx) { int ret; @@ -200,13 +200,13 @@ static void test_outfile(const testCtx *const p_ctx) { (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ assert_nonzero(testUtilCreateROFile(symbol.outfile), - "pcx_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", + "zint_pcx_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = pcx_pixel_plot(&symbol, data); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "pcx_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", + ret = zint_pcx_pixel_plot(&symbol, data); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "zint_pcx_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "pcx_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", + assert_zero(testUtilRmROFile(symbol.outfile), "zint_pcx_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); @@ -214,9 +214,9 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.output_options |= BARCODE_STDOUT; - ret = pcx_pixel_plot(&symbol, data); + ret = zint_pcx_pixel_plot(&symbol, data); printf(" - ignore (PCX to stdout)\n"); fflush(stdout); - assert_zero(ret, "pcx_pixel_plot ret %d != 0 (%s)\n", ret, symbol.errtxt); + assert_zero(ret, "zint_pcx_pixel_plot ret %d != 0 (%s)\n", ret, symbol.errtxt); testFinish(); } diff --git a/backend/tests/test_pdf417.c b/backend/tests/test_pdf417.c index ca3a3c8b..5d5439f0 100644 --- a/backend/tests/test_pdf417.c +++ b/backend/tests/test_pdf417.c @@ -4788,9 +4788,9 @@ static void test_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %s, %d, %d, %d, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n", i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, data[i].option_3, @@ -5959,8 +5959,8 @@ static void test_fuzz(const testCtx *const p_ctx) { } -INTERNAL void pdf_numbprocess_test(short *chainemc, int *p_mclength, const unsigned char chaine[], const int start, - const int length); +INTERNAL void zint_test_pdf_numbprocess(short *chainemc, int *p_mclength, const unsigned char chaine[], + const int start, const int length); #include "../large.h" @@ -6011,17 +6011,17 @@ static int annex_d_decode_dump(short chainemc[], int mclength, unsigned char *ch return -1; } - large_load_u64(&t, 0); + zint_large_load_u64(&t, 0); for (i = 1; i < mclength; i++) { - large_load(&s, &pow900s[mclength - i - 1]); - large_mul_u64(&s, chainemc[i]); - large_add(&t, &s); + zint_large_load(&s, &pow900s[mclength - i - 1]); + zint_large_mul_u64(&s, chainemc[i]); + zint_large_add(&t, &s); } - large_dump(&t, buf1); + zint_large_dump(&t, buf1); - large_load_str_u64(&e, chaine, length); - large_add(&e, &pow10s[length]); /* Add "1" prefix */ - large_dump(&e, buf2); + zint_large_load_str_u64(&e, chaine, length); + zint_large_add(&e, &pow10s[length]); /* Add "1" prefix */ + zint_large_dump(&e, buf2); return 0; } @@ -6101,9 +6101,9 @@ static void test_numbprocess(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - length = (int) ustrlen(data[i].chaine); + length = (int) z_ustrlen(data[i].chaine); mclength = 0; - pdf_numbprocess_test(chainemc, &mclength, data[i].chaine, 0, length); + zint_test_pdf_numbprocess(chainemc, &mclength, data[i].chaine, 0, length); assert_nonzero(mclength < ARRAY_SIZE(chainemc), "i:%d mclength %d >= ARRAY_SIZE(chainemc) %d\n", i, mclength, ARRAY_SIZE(chainemc)); #if 0 diff --git a/backend/tests/test_perf.c b/backend/tests/test_perf.c index 36d66ad8..ab6ce2dd 100644 --- a/backend/tests/test_perf.c +++ b/backend/tests/test_perf.c @@ -92,7 +92,7 @@ static void test_perf(const testCtx *const p_ctx, const int default_iterations, assert_nonnull(symbol, "Symbol not created\n"); if (strlen(data[i].composite_primary)) { - if (is_composite(data[i].symbology)) { + if (z_is_composite(data[i].symbology)) { text = data[i].composite_primary; assert_nonzero((int) strlen(data[i].data) < ARRAY_SIZE(symbol->primary), "i:%d composite length %d >= %d\n", diff --git a/backend/tests/test_png.c b/backend/tests/test_png.c index 6fff69d0..b3e32422 100644 --- a/backend/tests/test_png.c +++ b/backend/tests/test_png.c @@ -34,7 +34,7 @@ #include /* For ZLIBNG_VERSION define (if any) */ #include -INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); +INTERNAL int zint_png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); static void test_pixel_plot(const testCtx *const p_ctx) { int debug = p_ctx->debug; @@ -83,7 +83,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) { symbol->debug |= debug; size = data[i].width * data[i].height; - assert_nonzero(size < (int) sizeof(data_buf), "i:%d png_pixel_plot size %d < sizeof(data_buf) %d\n", + assert_nonzero(size < (int) sizeof(data_buf), "i:%d zint_png_pixel_plot size %d < sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf)); if (data[i].repeat) { @@ -91,13 +91,13 @@ static void test_pixel_plot(const testCtx *const p_ctx) { } else { strcpy(data_buf, data[i].pattern); } - assert_equal(size, (int) strlen(data_buf), "i:%d png_pixel_plot size %d != strlen(data_buf) %d\n", + assert_equal(size, (int) strlen(data_buf), "i:%d zint_png_pixel_plot size %d != strlen(data_buf) %d\n", i, size, (int) strlen(data_buf)); symbol->bitmap = (unsigned char *) data_buf; - ret = png_pixel_plot(symbol, (unsigned char *) data_buf); - assert_equal(ret, data[i].ret, "i:%d png_pixel_plot ret %d != %d (%s)\n", + ret = zint_png_pixel_plot(symbol, (unsigned char *) data_buf); + assert_equal(ret, data[i].ret, "i:%d zint_png_pixel_plot ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); if (ret < ZINT_ERROR) { @@ -438,13 +438,13 @@ static void test_outfile(const testCtx *const p_ctx) { (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ assert_nonzero(testUtilCreateROFile(symbol.outfile), - "png_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", + "zint_png_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = png_pixel_plot(&symbol, data); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "png_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", + ret = zint_png_pixel_plot(&symbol, data); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "zint_png_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "png_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", + assert_zero(testUtilRmROFile(symbol.outfile), "zint_png_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); @@ -453,9 +453,9 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.output_options |= BARCODE_STDOUT; printf(">>>Begin ignore (PNG to stdout)\n"); fflush(stdout); - ret = png_pixel_plot(&symbol, data); + ret = zint_png_pixel_plot(&symbol, data); printf("\n<<generate) { char data_dir_path[1024]; - assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), "testUtilDataPath(%s) == 0\n", data_dir); + assert_nonzero(testUtilDataPath(data_dir_path, sizeof(data_dir_path), data_dir, NULL), + "testUtilDataPath(%s) == 0\n", data_dir); if (!testUtilDirExists(data_dir_path)) { ret = testUtilMkDir(data_dir_path); assert_zero(ret, "testUtilMkDir(%s) ret %d != 0 (%d: %s)\n", data_dir_path, ret, errno, strerror(errno)); @@ -153,7 +154,9 @@ static void test_print(const testCtx *const p_ctx) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, data[i].option_1, data[i].option_2, -1, data[i].output_options, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode, -1 /*eci*/, + data[i].option_1, data[i].option_2, -1, data[i].output_options, + data[i].data, -1, debug); if (data[i].border_width != -1) { symbol->border_width = data[i].border_width; } @@ -177,39 +180,47 @@ static void test_print(const testCtx *const p_ctx) { } ret = ZBarcode_Encode(symbol, TCU(data[i].data), length); - assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); + assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", + i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); strcpy(symbol->outfile, eps); ret = ZBarcode_Print(symbol, data[i].rotate_angle); - assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); + assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0\n", + i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret); - assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), "i:%d testUtilDataPath == 0\n", i); + assert_nonzero(testUtilDataPath(expected_file, sizeof(expected_file), data_dir, data[i].expected_file), + "i:%d testUtilDataPath == 0\n", i); if (p_ctx->generate) { printf(" /*%3d*/ { %s, %s, %d, %s, %d, %d, %d, %d, %.5g, %.5g, \"%s\", \"%s\", %d, \"%s\", \"%s\"},\n", - i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].border_width, - testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, data[i].whitespace_height, data[i].option_1, data[i].option_2, + i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), + data[i].border_width, + testUtilOutputOptionsName(data[i].output_options), data[i].whitespace_width, + data[i].whitespace_height, data[i].option_1, data[i].option_2, data[i].scale, data[i].dot_size, data[i].fgcolour, data[i].bgcolour, data[i].rotate_angle, testUtilEscape(data[i].data, length, escaped, escaped_size), data[i].expected_file); ret = testUtilRename(symbol->outfile, expected_file); assert_zero(ret, "i:%d testUtilRename(%s, %s) ret %d != 0\n", i, symbol->outfile, expected_file, ret); if (have_ghostscript) { ret = testUtilVerifyGhostscript(expected_file, debug); - assert_zero(ret, "i:%d %s ghostscript %s ret %d != 0\n", i, testUtilBarcodeName(data[i].symbology), expected_file, ret); + assert_zero(ret, "i:%d %s ghostscript %s ret %d != 0\n", + i, testUtilBarcodeName(data[i].symbology), expected_file, ret); } } else { assert_nonzero(testUtilExists(symbol->outfile), "i:%d testUtilExists(%s) == 0\n", i, symbol->outfile); assert_nonzero(testUtilExists(expected_file), "i:%d testUtilExists(%s) == 0\n", i, expected_file); ret = testUtilCmpEpss(symbol->outfile, expected_file); - assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); + assert_zero(ret, "i:%d %s testUtilCmpEpss(%s, %s) %d != 0\n", + i, testUtilBarcodeName(data[i].symbology), symbol->outfile, expected_file, ret); symbol->output_options |= BARCODE_MEMORY_FILE; ret = ZBarcode_Print(symbol, data[i].rotate_angle); assert_zero(ret, "i:%d %s ZBarcode_Print %s ret %d != 0 (%s)\n", - i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt); + i, testUtilBarcodeName(data[i].symbology), symbol->outfile, ret, symbol->errtxt); assert_nonnull(symbol->memfile, "i:%d %s memfile NULL\n", i, testUtilBarcodeName(data[i].symbology)); - assert_nonzero(symbol->memfile_size, "i:%d %s memfile_size 0\n", i, testUtilBarcodeName(data[i].symbology)); + assert_nonzero(symbol->memfile_size, "i:%d %s memfile_size 0\n", + i, testUtilBarcodeName(data[i].symbology)); ret = testUtilWriteFile(memfile, symbol->memfile, symbol->memfile_size, "wb"); assert_zero(ret, "%d: testUtilWriteFile(%s) fail ret %d != 0\n", i, memfile, ret); @@ -230,7 +241,7 @@ static void test_print(const testCtx *const p_ctx) { testFinish(); } -INTERNAL void ps_convert_test(const unsigned char *string, unsigned char *ps_string); +INTERNAL void zint_test_ps_convert(const unsigned char *string, unsigned char *ps_string); static void test_ps_convert(const testCtx *const p_ctx) { @@ -252,14 +263,15 @@ static void test_ps_convert(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - ps_convert_test((unsigned char *) data[i].data, converted); - assert_zero(strcmp((char *) converted, data[i].expected), "i:%d ps_convert(%s) %s != %s\n", i, data[i].data, converted, data[i].expected); + zint_test_ps_convert((unsigned char *) data[i].data, converted); + assert_zero(strcmp((char *) converted, data[i].expected), "i:%d ps_convert(%s) %s != %s\n", + i, data[i].data, converted, data[i].expected); } testFinish(); } -INTERNAL int ps_plot(struct zint_symbol *symbol, int rotate_angle); +INTERNAL int zint_ps_plot(struct zint_symbol *symbol, int rotate_angle); static void test_outfile(const testCtx *const p_ctx) { int ret; @@ -282,24 +294,29 @@ static void test_outfile(const testCtx *const p_ctx) { static char expected_errtxt[] = "645: Could not open EPS output file ("; /* Excluding OS-dependent `errno` stuff */ (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "ps_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); + assert_nonzero(testUtilCreateROFile(symbol.outfile), "zint_ps_plot testUtilCreateROFile(%s) fail (%d: %s)\n", + symbol.outfile, errno, strerror(errno)); - ret = ps_plot(&symbol, 0); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "ps_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "ps_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); + ret = zint_ps_plot(&symbol, 0); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "zint_ps_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", + ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); + assert_zero(testUtilRmROFile(symbol.outfile), "zint_ps_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", + symbol.outfile, errno, strerror(errno)); + assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", + symbol.errtxt, expected_errtxt); } symbol.output_options |= BARCODE_STDOUT; printf(">>>Begin ignore (EPS to stdout)\n"); fflush(stdout); - ret = ps_plot(&symbol, 0); + ret = zint_ps_plot(&symbol, 0); printf("<<generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %s, %d, %d, %s, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n", i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(data[i].symbology, data[i].option_3), @@ -4824,7 +4824,7 @@ static void test_qr_encode_segs(const testCtx *const p_ctx) { i, testUtilBarcodeName(symbol->symbology)); } } else { - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; if (testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source, length, debug)) { int cmp_len, ret_len; char modules_dump[32768]; @@ -9424,9 +9424,9 @@ static void test_rmqr_encode_segs(const testCtx *const p_ctx) { if (p_ctx->generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %d, %d, %d, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n", i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, data[i].option_3, @@ -9477,7 +9477,7 @@ static void test_rmqr_encode_segs(const testCtx *const p_ctx) { i, testUtilBarcodeName(symbol->symbology)); } } else { - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; if (testUtilCanZXingCPP(i, symbol, (const char *) data[i].segs[0].source, length, debug)) { int cmp_len, ret_len; char modules_dump[32768]; diff --git a/backend/tests/test_raster.c b/backend/tests/test_raster.c index 32d5c265..24d4a8fd 100644 --- a/backend/tests/test_raster.c +++ b/backend/tests/test_raster.c @@ -1975,7 +1975,7 @@ static void test_quiet_zones(const testCtx *const p_ctx) { symbol->show_hrt = data[i].show_hrt; } - if (is_composite(symbol->symbology)) { + if (z_is_composite(symbol->symbology)) { text = *(data[i].composite) ? data[i].composite : composite; length = (int) strlen(text); assert_nonzero(strlen(data[i].data) < 128, "i:%d linear data length %d >= 128\n", i, (int) strlen(data[i].data)); diff --git a/backend/tests/test_reedsol.c b/backend/tests/test_reedsol.c index e703996d..6597465e 100644 --- a/backend/tests/test_reedsol.c +++ b/backend/tests/test_reedsol.c @@ -156,17 +156,20 @@ static void test_encoding(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - rs_init_gf(&rs, data[i].prime_poly); - rs_init_code(&rs, data[i].nsym, data[i].index); - rs_encode(&rs, data[i].datalen, data[i].data, res); + zint_rs_init_gf(&rs, data[i].prime_poly); + zint_rs_init_code(&rs, data[i].nsym, data[i].index); + zint_rs_encode(&rs, data[i].datalen, data[i].data, res); if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { - fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n"); - fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n"); + fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); + fprintf(stderr, "\n"); + fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); + fprintf(stderr, "\n"); } for (j = 0; j < data[i].nsym; j++) { int k = data[i].nsym - 1 - j; - assert_equal(res[k], data[i].expected[j], "i:%d res[%d] %d != expected[%d] %d\n", i, k, res[k], j, data[i].expected[j]); + assert_equal(res[k], data[i].expected[j], "i:%d res[%d] %d != expected[%d] %d\n", + i, k, res[k], j, data[i].expected[j]); } } @@ -219,17 +222,20 @@ static void test_encoding_uint(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - rs_init_gf(&rs, data[i].prime_poly); - rs_init_code(&rs, data[i].nsym, data[i].index); - rs_encode_uint(&rs, data[i].datalen, data[i].data, res); + zint_rs_init_gf(&rs, data[i].prime_poly); + zint_rs_init_code(&rs, data[i].nsym, data[i].index); + zint_rs_encode_uint(&rs, data[i].datalen, data[i].data, res); if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { - fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n"); - fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n"); + fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); + fprintf(stderr, "\n"); + fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); + fprintf(stderr, "\n"); } for (j = 0; j < data[i].nsym; j++) { int k = data[i].nsym - 1 - j; - assert_equal(res[k], data[i].expected[j], "i:%d res[%d] %d != expected[%d] %d\n", i, k, res[k], j, data[i].expected[j]); + assert_equal(res[k], data[i].expected[j], "i:%d res[%d] %d != expected[%d] %d\n", + i, k, res[k], j, data[i].expected[j]); } } @@ -268,30 +274,36 @@ static void test_uint_encoding(const testCtx *const p_ctx) { if (testContinue(p_ctx, i)) continue; - assert_nonzero(rs_uint_init_gf(&rs_uint, data[i].prime_poly, data[i].logmod), "i:%d rs_uint_init_gf() == 0\n", i); - rs_uint_init_code(&rs_uint, data[i].nsym, data[i].index); - rs_uint_encode(&rs_uint, data[i].datalen, data[i].data, res); - rs_uint_free(&rs_uint); + assert_nonzero(zint_rs_uint_init_gf(&rs_uint, data[i].prime_poly, data[i].logmod), + "i:%d zint_rs_uint_init_gf() == 0\n", i); + zint_rs_uint_init_code(&rs_uint, data[i].nsym, data[i].index); + zint_rs_uint_encode(&rs_uint, data[i].datalen, data[i].data, res); + zint_rs_uint_free(&rs_uint); if (p_ctx->index != -1 && (debug & ZINT_DEBUG_TEST_PRINT)) { - fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); fprintf(stderr, "\n"); - fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); fprintf(stderr, "\n"); + fprintf(stderr, "res "); for (j = data[i].nsym - 1; j >= 0; j--) fprintf(stderr, "%d, ", res[j]); + fprintf(stderr, "\n"); + fprintf(stderr, "exp "); for (j = 0; j < data[i].nsym; j++) fprintf(stderr, "%d, ", data[i].expected[j]); + fprintf(stderr, "\n"); } for (j = 0; j < data[i].nsym; j++) { int k = data[i].nsym - 1 - j; - assert_equal(res[k], data[i].expected[j], "i:%d res[%d] %d != expected[%d] %d\n", i, k, (int) res[k], j, (int) data[i].expected[j]); + assert_equal(res[k], data[i].expected[j], "i:%d res[%d] %d != expected[%d] %d\n", + i, k, (int) res[k], j, (int) data[i].expected[j]); } - /* Simulate rs_uint_init_gf() malloc() failure and rs_uint_init_gf()'s return val not being checked */ - assert_nonzero(rs_uint_init_gf(&rs_uint, data[i].prime_poly, data[i].logmod), "i:%d rs_uint_init_gf() == 0\n", i); + /* Simulate zint_rs_uint_init_gf() malloc() failure and zint_rs_uint_init_gf()'s return val not being + checked */ + assert_nonzero(zint_rs_uint_init_gf(&rs_uint, data[i].prime_poly, data[i].logmod), + "i:%d zint_rs_uint_init_gf() == 0\n", i); free(rs_uint.logt); rs_uint.logt = NULL; free(rs_uint.alog); rs_uint.alog = NULL; - rs_uint_init_code(&rs_uint, data[i].nsym, data[i].index); - rs_uint_encode(&rs_uint, data[i].datalen, data[i].data, res); - rs_uint_free(&rs_uint); + zint_rs_uint_init_code(&rs_uint, data[i].nsym, data[i].index); + zint_rs_uint_encode(&rs_uint, data[i].datalen, data[i].data, res); + zint_rs_uint_free(&rs_uint); for (j = 0; j < data[i].nsym; j++) { int k = data[i].nsym - 1 - j; diff --git a/backend/tests/test_sjis.c b/backend/tests/test_sjis.c index 98e311c1..ab424610 100644 --- a/backend/tests/test_sjis.c +++ b/backend/tests/test_sjis.c @@ -40,7 +40,7 @@ #include "../just_say_gno/sjis_gnu.c" #endif -INTERNAL int u_sjis_int_test(const unsigned int u, unsigned int *dest); +INTERNAL int zint_test_u_sjis_int(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 @@ -53,7 +53,8 @@ static int u_sjis_int2(unsigned int u, unsigned int *dest) { return 1; } /* Shortcut */ - if ((u > 0x00F7 && u < 0x0391) || (u > 0x0451 && u < 0x2010) || (u > 0x9FA0 && u < 0xE000) || (u > 0xE757 && u < 0xFF01) || u > 0xFFE5) { + if ((u > 0x00F7 && u < 0x0391) || (u > 0x0451 && u < 0x2010) || (u > 0x9FA0 && u < 0xE000) + || (u > 0xE757 && u < 0xFF01) || u > 0xFFE5) { return 0; } if (u >= 0xE000 && u <= 0xE757) { /* PUA mappings, not in SHIFTJIS.TXT */ @@ -130,9 +131,10 @@ static void test_u_sjis_int(const testCtx *const p_ctx) { } if (testContinue(p_ctx, i)) continue; val = val2 = 0; - ret = u_sjis_int_test(i, &val); + ret = zint_test_u_sjis_int(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); + 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); } @@ -146,7 +148,7 @@ static void test_u_sjis_int(const testCtx *const p_ctx) { val = val2 = 0; start = clock(); - ret = u_sjis_int_test(i, &val); + ret = zint_test_u_sjis_int(i, &val); total += clock() - start; start = clock(); @@ -155,7 +157,8 @@ static void test_u_sjis_int(const testCtx *const p_ctx) { } } - 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); + 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); } @@ -222,13 +225,15 @@ static void test_sjis_utf8(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - ret = sjis_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, jisdata); + ret = zint_sjis_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, jisdata); assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt); if (ret == 0) { int j; - assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); + assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", + i, ret_length, data[i].ret_length); for (j = 0; j < ret_length; j++) { - assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); + assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", + i, j, jisdata[j], data[i].expected_jisdata[j]); } } } @@ -314,13 +319,16 @@ static void test_sjis_utf8_to_eci(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - ret = sjis_utf8_to_eci(data[i].eci, (unsigned char *) data[i].data, &ret_length, jisdata, data[i].full_multibyte); + ret = zint_sjis_utf8_to_eci(data[i].eci, (unsigned char *) data[i].data, &ret_length, jisdata, + data[i].full_multibyte); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); if (ret == 0) { int j; - assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); + assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", + i, ret_length, data[i].ret_length); for (j = 0; j < ret_length; j++) { - assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] 0x%04X != 0x%04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); + assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] 0x%04X != 0x%04X\n", + i, j, jisdata[j], data[i].expected_jisdata[j]); } } } @@ -367,10 +375,11 @@ static void test_sjis_cpy(const testCtx *const p_ctx) { length = data[i].length == -1 ? (int) strlen(data[i].data) : data[i].length; ret_length = length; - sjis_cpy((unsigned char *) data[i].data, &ret_length, jisdata, data[i].full_multibyte); + zint_sjis_cpy((unsigned char *) data[i].data, &ret_length, jisdata, data[i].full_multibyte); assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length); for (j = 0; j < ret_length; j++) { - assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", i, j, jisdata[j], data[i].expected_jisdata[j]); + assert_equal(jisdata[j], data[i].expected_jisdata[j], "i:%d jisdata[%d] %04X != %04X\n", + i, j, jisdata[j], data[i].expected_jisdata[j]); } } @@ -420,7 +429,9 @@ static void test_perf(const testCtx *const p_ctx) { return; } - for (i = 0; i < data_size; i++) if ((int) strlen(data[i].comment) > comment_max) comment_max = (int) strlen(data[i].comment); + 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); @@ -437,7 +448,7 @@ static void test_perf(const testCtx *const p_ctx) { ret_length = length; start = clock(); - ret = sjis_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, ddata); + ret = zint_sjis_utf8(&symbol, (unsigned char *) data[i].data, &ret_length, ddata); diff += clock() - start; #ifdef TEST_JUST_SAY_GNO diff --git a/backend/tests/test_svg.c b/backend/tests/test_svg.c index a1d89aa9..fe75f3fe 100644 --- a/backend/tests/test_svg.c +++ b/backend/tests/test_svg.c @@ -310,7 +310,7 @@ static void test_print(const testCtx *const p_ctx) { testFinish(); } -INTERNAL int svg_plot(struct zint_symbol *symbol, int rotate_angle); +INTERNAL int zint_svg_plot(struct zint_symbol *symbol, int rotate_angle); static void test_outfile(const testCtx *const p_ctx) { int ret; @@ -334,13 +334,13 @@ static void test_outfile(const testCtx *const p_ctx) { static char expected_errtxt[] = "680: Could not open SVG output file ("; (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ - assert_nonzero(testUtilCreateROFile(symbol.outfile), "svg_plot testUtilCreateROFile(%s) fail (%d: %s)\n", + assert_nonzero(testUtilCreateROFile(symbol.outfile), "zint_svg_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = svg_plot(&symbol, 0); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "svg_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", + ret = zint_svg_plot(&symbol, 0); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "zint_svg_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "svg_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", + assert_zero(testUtilRmROFile(symbol.outfile), "zint_svg_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); @@ -349,13 +349,13 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.output_options |= BARCODE_STDOUT; printf(">>>Begin ignore (SVG to stdout)\n"); fflush(stdout); - ret = svg_plot(&symbol, 0); + ret = zint_svg_plot(&symbol, 0); printf("<< -INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); +INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf); /* For overview when debugging: ./test_tiff -f pixel_plot -d 5 */ static void test_pixel_plot(const testCtx *const p_ctx) { @@ -117,7 +117,7 @@ static void test_pixel_plot(const testCtx *const p_ctx) { symbol->debug |= debug; size = data[i].width * data[i].height; - assert_nonzero(size < (int) sizeof(data_buf), "i:%d tif_pixel_plot size %d >= sizeof(data_buf) %d\n", + assert_nonzero(size < (int) sizeof(data_buf), "i:%d zint_tif_pixel_plot size %d >= sizeof(data_buf) %d\n", i, size, (int) sizeof(data_buf)); if (data[i].repeat) { @@ -125,13 +125,13 @@ static void test_pixel_plot(const testCtx *const p_ctx) { } else { strcpy(data_buf, data[i].pattern); } - assert_equal(size, (int) strlen(data_buf), "i:%d tif_pixel_plot size %d != strlen(data_buf) %d\n", + assert_equal(size, (int) strlen(data_buf), "i:%d zint_tif_pixel_plot size %d != strlen(data_buf) %d\n", i, size, (int) strlen(data_buf)); symbol->bitmap = (unsigned char *) data_buf; - ret = tif_pixel_plot(symbol, (unsigned char *) data_buf); - assert_equal(ret, data[i].ret, "i:%d tif_pixel_plot ret %d != %d (%s)\n", + ret = zint_tif_pixel_plot(symbol, (unsigned char *) data_buf); + assert_equal(ret, data[i].ret, "i:%d zint_tif_pixel_plot ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); if (ret < ZINT_ERROR) { @@ -372,13 +372,13 @@ static void test_outfile(const testCtx *const p_ctx) { (void) testUtilRmROFile(symbol.outfile); /* In case lying around from previous fail */ assert_nonzero(testUtilCreateROFile(symbol.outfile), - "tif_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", + "zint_tif_pixel_plot testUtilCreateROFile(%s) fail (%d: %s)\n", symbol.outfile, errno, strerror(errno)); - ret = tif_pixel_plot(&symbol, data); - assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "tif_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", + ret = zint_tif_pixel_plot(&symbol, data); + assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "zint_tif_pixel_plot ret %d != ZINT_ERROR_FILE_ACCESS (%d) (%s)\n", ret, ZINT_ERROR_FILE_ACCESS, symbol.errtxt); - assert_zero(testUtilRmROFile(symbol.outfile), "tif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", + assert_zero(testUtilRmROFile(symbol.outfile), "zint_tif_pixel_plot testUtilRmROFile(%s) != 0 (%d: %s)\n", symbol.outfile, errno, strerror(errno)); assert_zero(strncmp(symbol.errtxt, expected_errtxt, sizeof(expected_errtxt) - 1), "strncmp(%s, %s) != 0\n", symbol.errtxt, expected_errtxt); @@ -387,9 +387,9 @@ static void test_outfile(const testCtx *const p_ctx) { symbol.output_options |= BARCODE_STDOUT; printf("<<generate) { char escaped1[4096]; char escaped2[4096]; - int length = data[i].segs[0].length == -1 ? (int) ustrlen(data[i].segs[0].source) : data[i].segs[0].length; - int length1 = data[i].segs[1].length == -1 ? (int) ustrlen(data[i].segs[1].source) : data[i].segs[1].length; - int length2 = data[i].segs[2].length == -1 ? (int) ustrlen(data[i].segs[2].source) : data[i].segs[2].length; + int length = data[i].segs[0].length == -1 ? (int) z_ustrlen(data[i].segs[0].source) : data[i].segs[0].length; + int length1 = data[i].segs[1].length == -1 ? (int) z_ustrlen(data[i].segs[1].source) : data[i].segs[1].length; + int length2 = data[i].segs[2].length == -1 ? (int) z_ustrlen(data[i].segs[2].source) : data[i].segs[2].length; printf(" /*%3d*/ { %s, %d, %d, %s, { %d, %d, \"%s\" }, { { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d }, { TU(\"%s\"), %d, %d } }, %s, %d, %d, %d, \"%s\",\n", i, testUtilInputModeName(data[i].input_mode), data[i].option_1, data[i].option_2, testUtilOption3Name(BARCODE_ULTRA, data[i].option_3), diff --git a/backend/tests/test_upcean.c b/backend/tests/test_upcean.c index 86ff96b3..0c66714e 100644 --- a/backend/tests/test_upcean.c +++ b/backend/tests/test_upcean.c @@ -1437,6 +1437,8 @@ static void test_hrt(const testCtx *const p_ctx) { testFinish(); } +INTERNAL void zint_vector_free(struct zint_symbol *symbol); /* Free vector structures */ + static void test_vector_same(const testCtx *const p_ctx) { int debug = p_ctx->debug; @@ -1494,7 +1496,7 @@ static void test_vector_same(const testCtx *const p_ctx) { for (j = 0; j < vectors_size; j++) { struct zint_symbol symbol_vector = {0}; /* Suppress clang -fsanitize=memory false positive */ symbol_vector.vector = vectors[j]; - vector_free(&symbol_vector); + zint_vector_free(&symbol_vector); } } diff --git a/backend/tests/test_vector.c b/backend/tests/test_vector.c index 011f87cd..c2b6a81d 100644 --- a/backend/tests/test_vector.c +++ b/backend/tests/test_vector.c @@ -33,7 +33,7 @@ #include "testcommon.h" /* Round to 3 decimal places (avoids rounding differences on various platforms) */ -#define rnd3dpf(m) stripf(roundf((m) * 1000) / 1000) +#define rnd3dpf(m) z_stripf(roundf((m) * 1000) / 1000) static struct zint_vector_rect *find_rect(struct zint_symbol *symbol, float x, float y, float width, float height) { struct zint_vector_rect *rect; @@ -161,7 +161,7 @@ static int check_vector_strings(const struct zint_symbol *symbol, char errmsg[12 sprintf(errmsg, "string[%d]->text NULL", i); return 0; } - length = (int) ustrlen(string->text); + length = (int) z_ustrlen(string->text); if (string->length != length) { sprintf(errmsg, "string[%d]->length != %d", string->length, length); return 0; @@ -170,7 +170,7 @@ static int check_vector_strings(const struct zint_symbol *symbol, char errmsg[12 if ((ZBarcode_Cap(symbol->symbology, ZINT_CAP_EANUPC) & ZINT_CAP_EANUPC) == ZINT_CAP_EANUPC) { const unsigned char *addon = (const unsigned char *) strchr((const char *) symbol->text, '+'); const int has_addon = addon != NULL; - const int text_len = has_addon ? (int) (addon - symbol->text) : (int) ustrlen(symbol->text); + const int text_len = has_addon ? (int) (addon - symbol->text) : (int) z_ustrlen(symbol->text); int num = -1; switch (symbol->symbology) { case BARCODE_EANX: @@ -231,7 +231,7 @@ static int check_vector_rectangles(const struct zint_symbol *symbol, char errmsg const struct zint_vector *vector = symbol->vector; const struct zint_vector_rect *rect; const int have_border = symbol->border_width && (symbol->output_options & (BARCODE_BIND | BARCODE_BOX | BARCODE_BIND_TOP)); - const int dotty = is_dotty(symbol->symbology) && (symbol->output_options & BARCODE_DOTTY_MODE); + const int dotty = z_is_dotty(symbol->symbology) && (symbol->output_options & BARCODE_DOTTY_MODE); int i; if (!vector) { @@ -283,7 +283,7 @@ static int check_vector_rectangles(const struct zint_symbol *symbol, char errmsg sprintf(errmsg, "rect[%d]->width %g > vector->width %g", i, rect->width, vector->width); return 0; } - if (stripf(rect->x + rect->width) > vector->width) { + if (z_stripf(rect->x + rect->width) > vector->width) { sprintf(errmsg, "rect[%d]->x + width %g > vector->width %g", i, rect->x + rect->width, vector->width); return 0; } @@ -295,7 +295,7 @@ static int check_vector_rectangles(const struct zint_symbol *symbol, char errmsg sprintf(errmsg, "rect[%d]->height %g > vector->height %g", i, rect->height, vector->height); return 0; } - if (stripf(rect->y + rect->height) > vector->height) { + if (z_stripf(rect->y + rect->height) > vector->height) { sprintf(errmsg, "rect[%d]->y + height %g > vector->height %g", i, rect->y + rect->height, vector->height); return 0; } @@ -319,7 +319,7 @@ static int check_vector_rectangles(const struct zint_symbol *symbol, char errmsg static int check_vector_circles(const struct zint_symbol *symbol, char errmsg[128]) { const struct zint_vector *vector = symbol->vector; const struct zint_vector_circle *circle; - const int dotty = is_dotty(symbol->symbology) && (symbol->output_options & BARCODE_DOTTY_MODE); + const int dotty = z_is_dotty(symbol->symbology) && (symbol->output_options & BARCODE_DOTTY_MODE); int i; if (!vector) { @@ -373,11 +373,11 @@ static int check_vector_circles(const struct zint_symbol *symbol, char errmsg[12 sprintf(errmsg, "circle[%d]->diameter %g > vector->height %g", i, circle->diameter, vector->height); return 0; } - if (stripf(circle->x + circle->diameter / 2) > vector->width) { + if (z_stripf(circle->x + circle->diameter / 2) > vector->width) { sprintf(errmsg, "circle[%d]->x + diameter / 2 %g > vector->width %g", i, circle->x + circle->diameter / 2, vector->width); return 0; } - if (stripf(circle->y + circle->diameter / 2) > vector->height) { + if (z_stripf(circle->y + circle->diameter / 2) > vector->height) { sprintf(errmsg, "circle[%d]->y + diameter / 2 %g > vector->height %g", i, circle->y + circle->diameter / 2, vector->height); return 0; } @@ -440,11 +440,11 @@ static int check_vector_hexagons(const struct zint_symbol *symbol, char errmsg[1 sprintf(errmsg, "hex[%d]->diameter %g > vector->height %g", i, hex->diameter, vector->height); return 0; } - if (stripf(hex->x + hex->diameter / 2) > vector->width) { + if (z_stripf(hex->x + hex->diameter / 2) > vector->width) { sprintf(errmsg, "hex[%d]->x + diameter / 2 %g > vector->width %g", i, hex->x + hex->diameter / 2, vector->width); return 0; } - if (stripf(hex->y + hex->diameter / 2) > vector->height) { + if (z_stripf(hex->y + hex->diameter / 2) > vector->height) { sprintf(errmsg, "hex[%d]->y + diameter / 2 %g > vector->height %g", i, hex->y + hex->diameter / 2, vector->height); return 0; } @@ -2181,7 +2181,7 @@ static void test_quiet_zones(const testCtx *const p_ctx) { symbol->show_hrt = data[i].show_hrt; } - if (is_composite(symbol->symbology)) { + if (z_is_composite(symbol->symbology)) { text = *(data[i].composite) ? data[i].composite : composite; length = (int) strlen(text); assert_nonzero(strlen(data[i].data) < 128, "i:%d linear data length %d >= 128\n", i, (int) strlen(data[i].data)); diff --git a/backend/tests/testcommon.c b/backend/tests/testcommon.c index 66dc8ae7..c13d1b0f 100644 --- a/backend/tests/testcommon.c +++ b/backend/tests/testcommon.c @@ -737,11 +737,11 @@ int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, const in char *b = buffer; *b = '\0'; for (i = 0; i < symbol->width && b < buffer + buffer_size; i += 2) { - if (module_is_set(symbol, 0, i) && module_is_set(symbol, 2, i)) { + if (z_module_is_set(symbol, 0, i) && z_module_is_set(symbol, 2, i)) { *b++ = 'F'; - } else if (module_is_set(symbol, 0, i)) { + } else if (z_module_is_set(symbol, 0, i)) { *b++ = 'A'; - } else if (module_is_set(symbol, 2, i)) { + } else if (z_module_is_set(symbol, 2, i)) { *b++ = 'D'; } else { *b++ = 'T'; @@ -760,7 +760,7 @@ int testUtilIsValidUTF8(const unsigned char str[], const int length) { unsigned int codepoint, state = 0; for (i = 0; i < length; i++) { - if (decode_utf8(&state, &codepoint, str[i]) == 12) { + if (z_decode_utf8(&state, &codepoint, str[i]) == 12) { return 0; } } @@ -905,7 +905,7 @@ int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b) if (a->symbology == BARCODE_ULTRA) { for (i = 0; i < a->rows; i++) { for (j = 0; j < a->width; j++) { - if (module_colour_is_set(a, i, j) != module_colour_is_set(b, i, j)) { + if (z_module_colour_is_set(a, i, j) != z_module_colour_is_set(b, i, j)) { return 4; } } @@ -913,7 +913,7 @@ int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b) } else { for (i = 0; i < a->rows; i++) { for (j = 0; j < a->width; j++) { - if (module_is_set(a, i, j) != module_is_set(b, i, j)) { + if (z_module_is_set(a, i, j) != z_module_is_set(b, i, j)) { return 4; } } @@ -981,7 +981,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) { *outstring = malloc(sizeof(struct zint_vector_string)); assert(*outstring != NULL); memcpy(*outstring, string, sizeof(struct zint_vector_string)); - (*outstring)->text = malloc(ustrlen(string->text) + 1); + (*outstring)->text = malloc(z_ustrlen(string->text) + 1); assert((*outstring)->text != NULL); ustrcpy((*outstring)->text, string->text); outstring = &((*outstring)->next); @@ -1086,7 +1086,7 @@ int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b) if (astring->length != bstring->length) { return 26; } - if (ustrlen(astring->text) != ustrlen(bstring->text)) { + if (z_ustrlen(astring->text) != z_ustrlen(bstring->text)) { return 27; } if (strcmp((const char *) astring->text, (const char *) bstring->text) != 0) { @@ -1160,11 +1160,11 @@ int testUtilModulesDump(const struct zint_symbol *symbol, char dump[], int dump_ for (r = 0; r < symbol->rows && d < de; r++) { if (symbol->symbology == BARCODE_ULTRA) { for (w = 0; w < symbol->width && d < de; w++) { - *d++ = module_colour_is_set(symbol, r, w) + '0'; + *d++ = z_module_colour_is_set(symbol, r, w) + '0'; } } else { for (w = 0; w < symbol->width && d < de; w++) { - *d++ = module_is_set(symbol, r, w) + '0'; + *d++ = z_module_is_set(symbol, r, w) + '0'; } } } @@ -1193,11 +1193,11 @@ void testUtilModulesPrintRow(const struct zint_symbol *symbol, int row, const ch putchar('"'); if (symbol->symbology == BARCODE_ULTRA) { for (w = 0; w < symbol->width; w++) { - putchar(module_colour_is_set(symbol, row, w) + '0'); + putchar(z_module_colour_is_set(symbol, row, w) + '0'); } } else { for (w = 0; w < symbol->width; w++) { - putchar(module_is_set(symbol, row, w) + '0'); + putchar(z_module_is_set(symbol, row, w) + '0'); } } putchar('"'); @@ -1214,7 +1214,7 @@ int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, i if (symbol->symbology == BARCODE_ULTRA) { for (r = 0; r < symbol->rows && e < ep; r++) { for (w = 0; w < symbol->width && e < ep; w++) { - if (module_colour_is_set(symbol, r, w) + '0' != *e) { + if (z_module_colour_is_set(symbol, r, w) + '0' != *e) { *row = r; *width = w; return 1 /*fail*/; @@ -1225,7 +1225,7 @@ int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, i } else { for (r = 0; r < symbol->rows && e < ep; r++) { for (w = 0; w < symbol->width && e < ep; w++) { - if (module_is_set(symbol, r, w) + '0' != *e) { + if (z_module_is_set(symbol, r, w) + '0' != *e) { *row = r; *width = w; return 1 /*fail*/; @@ -1246,7 +1246,7 @@ int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char int w; if (symbol->symbology == BARCODE_ULTRA) { for (w = 0; w < symbol->width && e < ep; w++) { - if (module_colour_is_set(symbol, row, w) + '0' != *e) { + if (z_module_colour_is_set(symbol, row, w) + '0' != *e) { *width = w; return 1 /*fail*/; } @@ -1254,7 +1254,7 @@ int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char } } else { for (w = 0; w < symbol->width && e < ep; w++) { - if (module_is_set(symbol, row, w) + '0' != *e) { + if (z_module_is_set(symbol, row, w) + '0' != *e) { *width = w; return 1 /*fail*/; } @@ -1540,7 +1540,7 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch /* Open a file (Windows compatibility) */ FILE *testUtilOpen(const char *filename, const char *mode) { #ifdef _WIN32 - FILE *fp = out_win_fopen(filename, mode); + FILE *fp = zint_out_win_fopen(filename, mode); #else FILE *fp = fopen(filename, mode); #endif @@ -2690,26 +2690,27 @@ static char *testUtilBwippEscape(char *bwipp_data, const int bwipp_data_size, co case 'G': val = 0x1d; /* Group Separator */ break; case 'R': val = 0x1e; /* Record Separator */ break; case 'x': - val = d + 2 < de && z_isxdigit(d[1]) && z_isxdigit(d[2]) ? (ctoi(d[1]) << 4) | ctoi(d[2]) : -1; + val = d + 2 < de && z_isxdigit(d[1]) && z_isxdigit(d[2]) + ? (z_ctoi(d[1]) << 4) | z_ctoi(d[2]) : -1; if (val != -1) d += 2; break; case 'd': - val = d + 3 < de ? to_int(d + 1, 3) : -1; + val = d + 3 < de ? z_to_int(d + 1, 3) : -1; if (val > 255) val = -1; if (val != -1) d += 3; break; case 'o': val = d + 3 < de && z_isodigit(d[1]) && z_isodigit(d[2]) && z_isodigit(d[3]) - ? (ctoi(d[1]) << 6) | (ctoi(d[2]) << 3) | ctoi(d[3]) : -1; + ? (z_ctoi(d[1]) << 6) | (z_ctoi(d[2]) << 3) | z_ctoi(d[3]) : -1; if (val > 255) val = -1; if (val != -1) d += 3; break; case '\\': val = '\\'; break; case 'u': /* For convenience, only handles ISO/IEC 8859-1 */ val = d + 4 < de && z_isxdigit(d[1]) && z_isxdigit(d[2]) && z_isxdigit(d[3]) && z_isxdigit(d[4]) - ? (ctoi(d[1]) << 4) | ctoi(d[2]) : -1; + ? (z_ctoi(d[1]) << 4) | z_ctoi(d[2]) : -1; if (val == 0) { /* Only handling Latin-1 so must be zero */ - val = (ctoi(d[3]) << 4) | ctoi(d[4]); + val = (z_ctoi(d[3]) << 4) | z_ctoi(d[4]); d += 4; } break; @@ -2793,15 +2794,15 @@ static char *testUtilBwippUtf8Convert(const int index, const int symbology, cons && (symbology == BARCODE_QRCODE || symbology == BARCODE_MICROQR || symbology == BARCODE_RMQR || symbology == BARCODE_UPNQR)) { if (symbology == BARCODE_UPNQR) { /* Note need to add "force binary mode" to BWIPP for this to work */ - if (utf8_to_eci(4, data, converted, p_data_len) != 0) { + if (zint_utf8_to_eci(4, data, converted, p_data_len) != 0) { fprintf(stderr, "i:%d testUtilBwippUtf8Convert: failed to convert UTF-8 data for %s, ECI 4\n", index, testUtilBarcodeName(symbology)); return NULL; } *p_eci = 4; } else { - if (utf8_to_eci(0, data, converted, p_data_len) != 0) { - if (utf8_to_eci(20, data, converted, p_data_len) != 0) { + if (zint_utf8_to_eci(0, data, converted, p_data_len) != 0) { + if (zint_utf8_to_eci(20, data, converted, p_data_len) != 0) { fprintf(stderr, "i:%d testUtilBwippUtf8Convert: failed to convert UTF-8 data for %s, ECI 0/20\n", index, testUtilBarcodeName(symbology)); return NULL; @@ -2812,14 +2813,14 @@ static char *testUtilBwippUtf8Convert(const int index, const int symbology, cons return (char *) converted; } if (ZBarcode_Cap(symbology, ZINT_CAP_ECI)) { - if (utf8_to_eci(eci, data, converted, p_data_len) != 0) { + if (zint_utf8_to_eci(eci, data, converted, p_data_len) != 0) { if (eci != 0) { fprintf(stderr, "i:%d testUtilBwippUtf8Convert: failed to convert UTF-8 data for %s, ECI %d\n", index, testUtilBarcodeName(symbology), eci); return NULL; } - *p_eci = eci = get_best_eci(data, *p_data_len); - if (utf8_to_eci(eci, data, converted, p_data_len) != 0) { + *p_eci = eci = zint_get_best_eci(data, *p_data_len); + if (zint_utf8_to_eci(eci, data, converted, p_data_len) != 0) { fprintf(stderr, "i:%d testUtilBwippUtf8Convert: failed to convert UTF-8 data for %s, ECI %d\n", index, testUtilBarcodeName(symbology), eci); return NULL; @@ -2832,7 +2833,7 @@ static char *testUtilBwippUtf8Convert(const int index, const int symbology, cons index, eci, testUtilBarcodeName(symbology)); return NULL; } - if (utf8_to_eci(eci, data, converted, p_data_len) != 0) { + if (zint_utf8_to_eci(eci, data, converted, p_data_len) != 0) { fprintf(stderr, "i:%d testUtilBwippUtf8Convert: failed to convert UTF-8 data for %s, default ECI %d\n", index, testUtilBarcodeName(symbology), eci); return NULL; @@ -2872,7 +2873,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int /* 4 AI prefix + primary + '|' + leading zero + escaped data + fudge */ int max_data_len = 4 + primary_len + 1 + 1 + data_len * 4 + 64; - int eci_length = get_eci_length(symbol->eci, (const unsigned char *) data, data_len); + int eci_length = zint_get_eci_length(symbol->eci, (const unsigned char *) data, data_len); char *converted = (char *) z_alloca(eci_length + 1); char *cmd = (char *) z_alloca(max_data_len + 1024); const char *bwipp_barcode = NULL; @@ -2927,7 +2928,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int eci = symbol->eci >= 3 && ZBarcode_Cap(symbology, ZINT_CAP_ECI) ? symbol->eci : 0; - if ((symbol->input_mode & 0x07) == UNICODE_MODE && is_eci_convertible(eci) + if ((symbol->input_mode & 0x07) == UNICODE_MODE && zint_is_eci_convertible(eci) && (data = testUtilBwippUtf8Convert(index, symbology, 1 /*try_sjis*/, &eci, (const unsigned char *) data, &data_len, (unsigned char *) converted)) == NULL) { fprintf(stderr, "i:%d testUtilBwipp: failed to convert UTF-8 data for %s\n", @@ -2935,7 +2936,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int return -1; } - if (is_composite(symbology)) { + if (z_is_composite(symbology)) { if (!primary) { fprintf(stderr, "i:%d testUtilBwipp: no primary data given %s\n", index, testUtilBarcodeName(symbology)); return -1; @@ -3150,7 +3151,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int for (r = 0; r < symbol->rows; r++) bwipp_row_height[r] = 1; /* Zap */ if (symbology == BARCODE_RM4SCC || symbology == BARCODE_KIX || symbology == BARCODE_JAPANPOST || symbology == BARCODE_DAFT) { - to_upper((unsigned char *) bwipp_data, (int) strlen(bwipp_data)); + z_to_upper(ZUCP(bwipp_data), (int) strlen(bwipp_data)); } else if (symbology == BARCODE_USPS_IMAIL) { char *dash = strchr(bwipp_data, '-'); if (dash) { @@ -3251,7 +3252,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int if (ai_latch == 0) { bwipp_data[j++] = '\x1D'; } - last_ai = to_int((unsigned char *) (bwipp_data + i + 1), 2); + last_ai = z_to_int(ZCUCP(bwipp_data + i + 1), 2); if ((last_ai >= 0 && last_ai <= 4) || (last_ai >= 11 && last_ai <= 20) || last_ai == 23 || (last_ai >= 31 && last_ai <= 36) || last_ai == 41) { ai_latch = 1; @@ -3374,12 +3375,12 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } if (symbol->structapp.count) { sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%ssam=%c%c", - strlen(bwipp_opts_buf) ? " " : "", itoc(symbol->structapp.index), - itoc(symbol->structapp.count)); + strlen(bwipp_opts_buf) ? " " : "", z_itoc(symbol->structapp.index), + z_itoc(symbol->structapp.count)); bwipp_opts = bwipp_opts_buf; } } else if (symbology == BARCODE_BC412) { - to_upper((unsigned char *) bwipp_data, (int) strlen(bwipp_data)); + z_to_upper(ZUCP(bwipp_data), (int) strlen(bwipp_data)); sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%ssemi", strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } else if (symbology == BARCODE_MAILMARK_2D) { @@ -3697,10 +3698,10 @@ int testUtilBwippSegs(int index, struct zint_symbol *symbol, int option_1, int o for (i = 0; i < seg_count; i++) { local_segs[i] = segs[i]; if (local_segs[i].length == -1) { - local_segs[i].length = (int) ustrlen(local_segs[i].source); + local_segs[i].length = (int) z_ustrlen(local_segs[i].source); } if (unicode_mode) { - total_len += get_eci_length(local_segs[i].eci, local_segs[i].source, local_segs[i].length); + total_len += zint_get_eci_length(local_segs[i].eci, local_segs[i].source, local_segs[i].length); } else { total_len += local_segs[i].length; } @@ -3709,7 +3710,7 @@ int testUtilBwippSegs(int index, struct zint_symbol *symbol, int option_1, int o d = data = (char *) z_alloca(total_len + 1); for (i = 0; i < seg_count; i++) { - if (unicode_mode && is_eci_convertible(local_segs[i].eci)) { + if (unicode_mode && zint_is_eci_convertible(local_segs[i].eci)) { char *converted = testUtilBwippUtf8Convert(index, symbology, 0 /*try_sjis*/, &local_segs[i].eci, local_segs[i].source, &local_segs[i].length, (unsigned char *) d); if (converted == NULL) { @@ -4161,10 +4162,11 @@ int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source, testutil_pclose(fp); - if ((data_mode && zxingcpp_cmp > 1 && (zxingcpp_cmp == 899 || is_eci_convertible(zxingcpp_cmp))) || symbol->eci >= 899) { + if ((data_mode && zxingcpp_cmp > 1 && (zxingcpp_cmp == 899 || zint_is_eci_convertible(zxingcpp_cmp))) + || symbol->eci >= 899) { const int eci = symbol->eci > 899 ? 3 : zxingcpp_cmp; int error_number; - const int eci_length = get_eci_length(eci, (const unsigned char *) buffer, cnt); + const int eci_length = zint_get_eci_length(eci, (const unsigned char *) buffer, cnt); unsigned char *preprocessed = (unsigned char *) z_alloca(eci_length + 1); if (eci_length >= buffer_size) { @@ -4172,19 +4174,21 @@ int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source, index, buffer_size, eci_length, cmd); return -1; } - error_number = utf8_to_eci(eci, (const unsigned char *) buffer, preprocessed, &cnt); + error_number = zint_utf8_to_eci(eci, (const unsigned char *) buffer, preprocessed, &cnt); if (error_number == 0) { memcpy(buffer, preprocessed, cnt); } else { if (eci != 0 && symbol->eci < 899) { - fprintf(stderr, "i:%d testUtilZXingCPP: utf8_to_eci(%d) == %d (%s)\n", index, eci, error_number, cmd); + fprintf(stderr, "i:%d testUtilZXingCPP: zint_utf8_to_eci(%d) == %d (%s)\n", index, eci, error_number, + cmd); return -1; } else { int i; unsigned int *vals = (unsigned int *) z_alloca(sizeof(int) * (cnt + 1)); - error_number = utf8_to_unicode(symbol, (const unsigned char *) buffer, vals, &cnt, 1); + error_number = z_utf8_to_unicode(symbol, (const unsigned char *) buffer, vals, &cnt, 1); if (error_number != 0) { - fprintf(stderr, "i:%d testUtilZXingCPP: utf8_to_unicode == %d (%s)\n", index, error_number, cmd); + fprintf(stderr, "i:%d testUtilZXingCPP: z_utf8_to_unicode == %d (%s)\n", index, error_number, + cmd); return -1; } for (i = 0; i < cnt; i++) { @@ -4200,8 +4204,8 @@ int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source, return 0; } -INTERNAL int escape_char_process_test(struct zint_symbol *symbol, const unsigned char *input_string, int *length, - unsigned char *escaped_string); +INTERNAL int zint_test_escape_char_process(struct zint_symbol *symbol, const unsigned char *input_string, + int *length, unsigned char *escaped_string); #include "../gs1.h" @@ -4220,10 +4224,10 @@ static int textUtilZXingCPPDX(const char *expected, const int expected_len, cons const char *stripped; if (strchr(expected, '-') == NULL) { if (expected_len == 6) { - const int dx = to_int((const unsigned char *) expected + 1, expected_len - 2); + const int dx = z_to_int(ZCUCP(expected + 1), expected_len - 2); sprintf(out, "%d-%d", dx / 16, dx % 16); } else { - const int dx = to_int((const unsigned char *) expected, expected_len); + const int dx = z_to_int(ZCUCP(expected), expected_len); sprintf(out, "%d-%d", dx / 16, dx % 16); } return 1; @@ -4304,7 +4308,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in } if (is_escaped) { - ret = escape_char_process_test(symbol, (unsigned char *) expected, &expected_len, + ret = zint_test_escape_char_process(symbol, (unsigned char *) expected, &expected_len, (unsigned char *) escaped); if (ret != 0) { sprintf(msg, "escape_char_process %d != 0", ret); @@ -4348,9 +4352,9 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in } if (gs1 && symbology != BARCODE_EAN14 && symbology != BARCODE_NVE18) { int len = expected_len; - ret = gs1_verify(symbol, ZUCP(expected), &len, ZUCP(reduced), &expected_len); + ret = zint_gs1_verify(symbol, ZUCP(expected), &len, ZUCP(reduced), &expected_len); if (ret >= ZINT_ERROR) { - sprintf(msg, "gs1_verify %d != 0", ret); + sprintf(msg, "zint_gs1_verify %d != 0", ret); return 3; } expected = reduced; @@ -4362,9 +4366,10 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in int posns[110]; hibc[0] = '+'; memcpy(hibc + 1, expected, expected_len); - to_upper((unsigned char *) (hibc + 1), expected_len); - if (not_sane_lookup(TECHNETIUM, sizeof(TECHNETIUM) - 1, (unsigned char *) (hibc + 1), expected_len, posns)) { - sprintf(msg, "HIBC not_sane_lookup(TECHNETIUM) failed"); + z_to_upper(ZUCP(hibc + 1), expected_len); + if (z_not_sane_lookup(TECHNETIUM, sizeof(TECHNETIUM) - 1, (unsigned char *) (hibc + 1), expected_len, + posns)) { + sprintf(msg, "HIBC z_not_sane_lookup(TECHNETIUM) failed"); return 4; } counter = 41; @@ -4445,7 +4450,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in memcpy(c25inter, expected, expected_len); } if (have_c25checkdigit) { - c25inter[expected_len] = gs1_check_digit((const unsigned char *) c25inter, expected_len); + c25inter[expected_len] = zint_gs1_check_digit((const unsigned char *) c25inter, expected_len); expected_len++; } c25inter[expected_len] = '\0'; @@ -4462,10 +4467,10 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in memcpy(c25inter + zeroes, expected, expected_len); expected_len += zeroes; for (i = len - 1; i >= 0; i--) { - count += factor * ctoi(c25inter[i]); + count += factor * z_ctoi(c25inter[i]); factor ^= 0x0D; /* Toggles 4 and 9 */ } - c25inter[expected_len] = itoc((10 - (count % 10)) % 10); + c25inter[expected_len] = z_itoc((10 - (count % 10)) % 10); c25inter[++expected_len] = '\0'; expected = c25inter; } else if (symbology == BARCODE_ITF14) { @@ -4475,7 +4480,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in } memcpy(c25inter + zeroes, expected, expected_len); expected_len += zeroes; - c25inter[expected_len] = gs1_check_digit((const unsigned char *) c25inter, 13); + c25inter[expected_len] = zint_gs1_check_digit((const unsigned char *) c25inter, 13); c25inter[++expected_len] = '\0'; expected = c25inter; } @@ -4494,7 +4499,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in assert(expected_len >= 11); upcean[0] = '0'; memcpy(upcean + 1, expected, 11); - upcean[12] = gs1_check_digit(ZCUCP(upcean), 12); + upcean[12] = zint_gs1_check_digit(ZCUCP(upcean), 12); expected_len = textUtilZXingCPPEAN13AddOn(expected, expected_len, upcean); upcean[expected_len] = '\0'; expected = upcean; @@ -4529,7 +4534,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in } upcean[0] = '0'; memcpy(upcean + 1, equivalent, 11); - upcean[12] = gs1_check_digit(ZCUCP(upcean), 12); + upcean[12] = zint_gs1_check_digit(ZCUCP(upcean), 12); expected_len = textUtilZXingCPPEAN13AddOn(expected, expected_len, upcean); upcean[expected_len] = '\0'; expected = upcean; @@ -4540,7 +4545,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in const int ean7_len = sep - expected < 7 ? (int) (sep - expected) : 7; memset(upcean, '0', 12 - ean7_len); memcpy(upcean + (12 - ean7_len), expected, ean7_len); - upcean[12] = gs1_check_digit(ZCUCP(upcean), 12); + upcean[12] = zint_gs1_check_digit(ZCUCP(upcean), 12); expected_len = textUtilZXingCPPEAN13AddOn(expected, expected_len, upcean); upcean[expected_len] = '\0'; expected = upcean; @@ -4548,7 +4553,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in && (expected_len == 7 || expected_len == 8)) { if (expected_len == 7) { memcpy(upcean, expected, 7); - upcean[7] = gs1_check_digit(ZCUCP(expected), 7); + upcean[7] = zint_gs1_check_digit(ZCUCP(expected), 7); } expected_len = 8; upcean[expected_len] = '\0'; @@ -4556,7 +4561,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in } else if ((symbology == BARCODE_EAN13 || symbology == BARCODE_EANX || symbology == BARCODE_EANX_CHK || symbology == BARCODE_ISBNX) && expected_len >= 12) { memcpy(upcean, expected, 12); - upcean[12] = gs1_check_digit(ZCUCP(upcean), 12); + upcean[12] = zint_gs1_check_digit(ZCUCP(upcean), 12); expected_len = textUtilZXingCPPEAN13AddOn(expected, expected_len, upcean); upcean[expected_len] = '\0'; expected = upcean; @@ -4569,7 +4574,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in ean14_nve18[1] = symbology == BARCODE_NVE18 ? '0' : '1'; memset(ean14_nve18 + 2, '0', zeroes); memcpy(ean14_nve18 + 2 + zeroes, expected, expected_len); - ean14_nve18[len + 2] = gs1_check_digit((unsigned char *) (ean14_nve18 + 2), len); + ean14_nve18[len + 2] = zint_gs1_check_digit((unsigned char *) (ean14_nve18 + 2), len); expected = ean14_nve18; expected_len = len + 3; @@ -4590,12 +4595,12 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in expected_len++; } else if (symbology == BARCODE_DXFILMEDGE) { - const int dx_info_len = posn(expected, '/'); + const int dx_info_len = z_posn(expected, '/'); if (dx_info_len != -1) { char frame_info[20]; assert(strlen(expected + dx_info_len + 1) < sizeof(frame_info)); strcpy(frame_info, expected + dx_info_len + 1); - to_upper((unsigned char *) frame_info, (int) strlen(frame_info)); + z_to_upper(ZUCP(frame_info), (int) strlen(frame_info)); if (!textUtilZXingCPPDX(expected, dx_info_len, cmp_buf, dxfe)) { memcpy(dxfe, expected, dx_info_len); dxfe[dx_info_len] = '\0'; @@ -4623,7 +4628,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in } expected = dxfe; expected_len = (int) strlen(expected); - to_upper((unsigned char *) expected, expected_len); + z_to_upper(ZUCP(expected), expected_len); } else { if (textUtilZXingCPPDX(expected, expected_len, cmp_buf, dxfe)) { expected = dxfe; @@ -4633,7 +4638,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in } else if (symbology == BARCODE_AZRUNE) { if (expected_len != 3) { - sprintf(azrune, "%03d", to_int((const unsigned char *) expected, expected_len)); + sprintf(azrune, "%03d", z_to_int(ZCUCP(expected), expected_len)); expected = azrune; expected_len = 3; } @@ -4666,13 +4671,13 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in int testUtilZXingCPPCmpSegs(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len, const struct zint_seg segs[], const int seg_count, const char *primary, char *ret_buf, int *p_ret_len) { - int expected_len = segs_length(segs, seg_count); + int expected_len = z_segs_length(segs, seg_count); char *expected = (char *) z_alloca(expected_len + 1); char *s = expected; int i; for (i = 0; i < seg_count; i++) { - int len = segs[i].length == -1 ? (int) ustrlen(segs[i].source) : segs[i].length; + int len = segs[i].length == -1 ? (int) z_ustrlen(segs[i].source) : segs[i].length; memcpy(s, segs[i].source, len); s += len; } diff --git a/backend/tif.c b/backend/tif.c index 3fdf6210..ef1fd998 100644 --- a/backend/tif.c +++ b/backend/tif.c @@ -61,7 +61,7 @@ static void to_cmyk(const char *colour, unsigned char *cmyk) { int cyan, magenta, yellow, black; unsigned char alpha; - (void) out_colour_get_cmyk(colour, &cyan, &magenta, &yellow, &black, &alpha); + (void) zint_out_colour_get_cmyk(colour, &cyan, &magenta, &yellow, &black, &alpha); cmyk[0] = (unsigned char) roundf(cyan * 0xFF / 100.0f); cmyk[1] = (unsigned char) roundf(magenta * 0xFF / 100.0f); cmyk[2] = (unsigned char) roundf(yellow * 0xFF / 100.0f); @@ -70,7 +70,7 @@ static void to_cmyk(const char *colour, unsigned char *cmyk) { } /* TIFF Revision 6.0 https://www.adobe.io/content/dam/udp/en/open/standards/tiff/TIFF6.pdf */ -INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) { +INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf) { unsigned char fg[4], bg[4]; int i; int pmi; /* PhotometricInterpretation */ @@ -111,8 +111,8 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix uint32_t temp32; uint16_t temp16; - (void) out_colour_get_rgb(symbol->fgcolour, &fg[0], &fg[1], &fg[2], &fg[3]); - (void) out_colour_get_rgb(symbol->bgcolour, &bg[0], &bg[1], &bg[2], &bg[3]); + (void) zint_out_colour_get_rgb(symbol->fgcolour, &fg[0], &fg[1], &fg[2], &fg[3]); + (void) zint_out_colour_get_rgb(symbol->bgcolour, &bg[0], &bg[1], &bg[2], &bg[3]); if (symbol->symbology == BARCODE_ULTRA) { static const unsigned char ultra_chars[8] = { 'W', 'C', 'B', 'M', 'R', 'Y', 'G', 'K' }; @@ -305,13 +305,13 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } if (free_memory > 0xffff0000) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 670, "TIF output file size too big"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 670, "TIF output file size too big"); } /* Open output file in binary mode */ - if (!fm_open(fmp, symbol, "wb")) { - return ZEXT errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 672, "Could not open TIF output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_open(fmp, symbol, "wb")) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 672, "Could not open TIF output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } if (!output_to_stdout) { compression = TIF_LZW; @@ -319,11 +319,11 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } /* Header */ - out_le_u16(header.byte_order, 0x4949); /* "II" little-endian */ - out_le_u16(header.identity, 42); - out_le_u32(header.offset, free_memory); + zint_out_le_u16(header.byte_order, 0x4949); /* "II" little-endian */ + zint_out_le_u16(header.identity, 42); + zint_out_le_u32(header.offset, free_memory); - fm_write(&header, sizeof(tiff_header_t), 1, fmp); + zint_fm_write(&header, sizeof(tiff_header_t), 1, fmp); total_bytes_put = sizeof(tiff_header_t); /* Pixel data */ @@ -369,13 +369,13 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix if (strip_row == rows_per_strip || (strip == strip_count - 1 && strip_row == rows_last_strip)) { /* End of strip */ if (compression == TIF_LZW) { - file_pos = fm_tell(fmp); + file_pos = zint_fm_tell(fmp); if (!tif_lzw_encode(&lzw_state, fmp, strip_buf, bytes_put)) { /* Only fails if can't malloc */ tif_lzw_cleanup(&lzw_state); - (void) fm_close(fmp, symbol); - return errtxt(ZINT_ERROR_MEMORY, symbol, 673, "Insufficient memory for TIF LZW hash table"); + (void) zint_fm_close(fmp, symbol); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 673, "Insufficient memory for TIF LZW hash table"); } - bytes_put = fm_tell(fmp) - file_pos; + bytes_put = zint_fm_tell(fmp) - file_pos; if (bytes_put != strip_bytes[strip]) { const int diff = bytes_put - strip_bytes[strip]; strip_bytes[strip] = bytes_put; @@ -384,7 +384,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } } } else { - fm_write(strip_buf, 1, bytes_put, fmp); + zint_fm_write(strip_buf, 1, bytes_put, fmp); } strip++; total_bytes_put += bytes_put; @@ -396,46 +396,46 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } if (total_bytes_put & 1) { - fm_putc(0, fmp); /* IFD must be on word boundary */ + zint_fm_putc(0, fmp); /* IFD must be on word boundary */ total_bytes_put++; } if (compression == TIF_LZW) { tif_lzw_cleanup(&lzw_state); - file_pos = fm_tell(fmp); - fm_seek(fmp, 4, SEEK_SET); + file_pos = zint_fm_tell(fmp); + zint_fm_seek(fmp, 4, SEEK_SET); free_memory = file_pos; temp32 = (uint32_t) free_memory; /* Shouldn't happen as `free_memory` checked above to be <= 0xffff0000 & should only decrease */ if (free_memory != temp32 || (long) free_memory != file_pos) { - (void) fm_close(fmp, symbol); - return errtxt(ZINT_ERROR_MEMORY, symbol, 982, "TIF output file size too big"); + (void) zint_fm_close(fmp, symbol); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 982, "TIF output file size too big"); } - out_le_u32(temp32, temp32); - fm_write(&temp32, 4, 1, fmp); - fm_seek(fmp, file_pos, SEEK_SET); + zint_out_le_u32(temp32, temp32); + zint_fm_write(&temp32, 4, 1, fmp); + zint_fm_seek(fmp, file_pos, SEEK_SET); } /* Image File Directory */ - out_le_u16(tags[entries].tag, 0x0100); /* ImageWidth */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, 1); - out_le_u32(tags[entries++].offset, symbol->bitmap_width); + zint_out_le_u16(tags[entries].tag, 0x0100); /* ImageWidth */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, 1); + zint_out_le_u32(tags[entries++].offset, symbol->bitmap_width); - out_le_u16(tags[entries].tag, 0x0101); /* ImageLength - number of rows */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, 1); - out_le_u32(tags[entries++].offset, symbol->bitmap_height); + zint_out_le_u16(tags[entries].tag, 0x0101); /* ImageLength - number of rows */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, 1); + zint_out_le_u32(tags[entries++].offset, symbol->bitmap_height); if (samples_per_pixel != 1 || bits_per_sample != 1) { - out_le_u16(tags[entries].tag, 0x0102); /* BitsPerSample */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, samples_per_pixel); + zint_out_le_u16(tags[entries].tag, 0x0102); /* BitsPerSample */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, samples_per_pixel); if (samples_per_pixel == 1) { - out_le_u32(tags[entries++].offset, bits_per_sample); + zint_out_le_u32(tags[entries++].offset, bits_per_sample); } else if (samples_per_pixel == 2) { /* 2 SHORTS fit into LONG offset so packed into offset */ - out_le_u32(tags[entries++].offset, (bits_per_sample << 16) | bits_per_sample); + zint_out_le_u32(tags[entries++].offset, (bits_per_sample << 16) | bits_per_sample); } else { update_offsets[offsets++] = entries; tags[entries++].offset = (uint32_t) free_memory; @@ -443,21 +443,21 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } } - out_le_u16(tags[entries].tag, 0x0103); /* Compression */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, 1); - out_le_u32(tags[entries++].offset, compression); + zint_out_le_u16(tags[entries].tag, 0x0103); /* Compression */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, 1); + zint_out_le_u32(tags[entries++].offset, compression); - out_le_u16(tags[entries].tag, 0x0106); /* PhotometricInterpretation */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, 1); - out_le_u32(tags[entries++].offset, pmi); + zint_out_le_u16(tags[entries].tag, 0x0106); /* PhotometricInterpretation */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, 1); + zint_out_le_u32(tags[entries++].offset, pmi); - out_le_u16(tags[entries].tag, 0x0111); /* StripOffsets */ - out_le_u16(tags[entries].type, 4); /* LONG */ - out_le_u32(tags[entries].count, strip_count); + zint_out_le_u16(tags[entries].tag, 0x0111); /* StripOffsets */ + zint_out_le_u16(tags[entries].type, 4); /* LONG */ + zint_out_le_u32(tags[entries].count, strip_count); if (strip_count == 1) { - out_le_u32(tags[entries++].offset, strip_offset[0]); + zint_out_le_u32(tags[entries++].offset, strip_offset[0]); } else { update_offsets[offsets++] = entries; tags[entries++].offset = (uint32_t) free_memory; @@ -465,83 +465,83 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix } if (samples_per_pixel > 1) { - out_le_u16(tags[entries].tag, 0x0115); /* SamplesPerPixel */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, 1); - out_le_u32(tags[entries++].offset, samples_per_pixel); + zint_out_le_u16(tags[entries].tag, 0x0115); /* SamplesPerPixel */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, 1); + zint_out_le_u32(tags[entries++].offset, samples_per_pixel); } - out_le_u16(tags[entries].tag, 0x0116); /* RowsPerStrip */ - out_le_u16(tags[entries].type, 4); /* LONG */ - out_le_u32(tags[entries].count, 1); - out_le_u32(tags[entries++].offset, rows_per_strip); + zint_out_le_u16(tags[entries].tag, 0x0116); /* RowsPerStrip */ + zint_out_le_u16(tags[entries].type, 4); /* LONG */ + zint_out_le_u32(tags[entries].count, 1); + zint_out_le_u32(tags[entries++].offset, rows_per_strip); - out_le_u16(tags[entries].tag, 0x0117); /* StripByteCounts */ - out_le_u16(tags[entries].type, 4); /* LONG */ - out_le_u32(tags[entries].count, strip_count); + zint_out_le_u16(tags[entries].tag, 0x0117); /* StripByteCounts */ + zint_out_le_u16(tags[entries].type, 4); /* LONG */ + zint_out_le_u32(tags[entries].count, strip_count); if (strip_count == 1) { - out_le_u32(tags[entries++].offset, strip_bytes[0]); + zint_out_le_u32(tags[entries++].offset, strip_bytes[0]); } else { update_offsets[offsets++] = entries; tags[entries++].offset = (uint32_t) free_memory; free_memory += strip_count * 4; } - out_le_u16(tags[entries].tag, 0x011a); /* XResolution */ - out_le_u16(tags[entries].type, 5); /* RATIONAL */ - out_le_u32(tags[entries].count, 1); + zint_out_le_u16(tags[entries].tag, 0x011a); /* XResolution */ + zint_out_le_u16(tags[entries].type, 5); /* RATIONAL */ + zint_out_le_u32(tags[entries].count, 1); update_offsets[offsets++] = entries; tags[entries++].offset = (uint32_t) free_memory; free_memory += 8; - out_le_u16(tags[entries].tag, 0x011b); /* YResolution */ - out_le_u16(tags[entries].type, 5); /* RATIONAL */ - out_le_u32(tags[entries].count, 1); + zint_out_le_u16(tags[entries].tag, 0x011b); /* YResolution */ + zint_out_le_u16(tags[entries].type, 5); /* RATIONAL */ + zint_out_le_u32(tags[entries].count, 1); update_offsets[offsets++] = entries; tags[entries++].offset = (uint32_t) free_memory; free_memory += 8; - out_le_u16(tags[entries].tag, 0x0128); /* ResolutionUnit */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, 1); + zint_out_le_u16(tags[entries].tag, 0x0128); /* ResolutionUnit */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, 1); if (symbol->dpmm) { - out_le_u32(tags[entries++].offset, 3); /* Centimetres */ + zint_out_le_u32(tags[entries++].offset, 3); /* Centimetres */ } else { - out_le_u32(tags[entries++].offset, 2); /* Inches */ + zint_out_le_u32(tags[entries++].offset, 2); /* Inches */ } if (color_map_size) { - out_le_u16(tags[entries].tag, 0x0140); /* ColorMap */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, color_map_size * 3); + zint_out_le_u16(tags[entries].tag, 0x0140); /* ColorMap */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, color_map_size * 3); update_offsets[offsets++] = entries; tags[entries++].offset = (uint32_t) free_memory; /* free_memory += color_map_size * 3 * 2; Unnecessary as long as last use */ } if (extra_samples) { - out_le_u16(tags[entries].tag, 0x0152); /* ExtraSamples */ - out_le_u16(tags[entries].type, 3); /* SHORT */ - out_le_u32(tags[entries].count, 1); - out_le_u32(tags[entries++].offset, extra_samples); + zint_out_le_u16(tags[entries].tag, 0x0152); /* ExtraSamples */ + zint_out_le_u16(tags[entries].type, 3); /* SHORT */ + zint_out_le_u32(tags[entries].count, 1); + zint_out_le_u32(tags[entries++].offset, extra_samples); } ifd_size = sizeof(entries) + sizeof(tiff_tag_t) * entries + sizeof(offset); for (i = 0; i < offsets; i++) { - out_le_u32(tags[update_offsets[i]].offset, tags[update_offsets[i]].offset + ifd_size); + zint_out_le_u32(tags[update_offsets[i]].offset, tags[update_offsets[i]].offset + ifd_size); } - out_le_u16(temp16, entries); - fm_write(&temp16, sizeof(entries), 1, fmp); - fm_write(&tags, sizeof(tiff_tag_t), entries, fmp); - out_le_u32(offset, offset); - fm_write(&offset, sizeof(offset), 1, fmp); + zint_out_le_u16(temp16, entries); + zint_fm_write(&temp16, sizeof(entries), 1, fmp); + zint_fm_write(&tags, sizeof(tiff_tag_t), entries, fmp); + zint_out_le_u32(offset, offset); + zint_fm_write(&offset, sizeof(offset), 1, fmp); total_bytes_put += ifd_size; if (samples_per_pixel > 2) { - out_le_u16(bits_per_sample, bits_per_sample); + zint_out_le_u16(bits_per_sample, bits_per_sample); for (i = 0; i < samples_per_pixel; i++) { - fm_write(&bits_per_sample, sizeof(bits_per_sample), 1, fmp); + zint_fm_write(&bits_per_sample, sizeof(bits_per_sample), 1, fmp); } total_bytes_put += sizeof(bits_per_sample) * samples_per_pixel; } @@ -549,60 +549,60 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, const unsigned char *pix if (strip_count != 1) { /* Strip offsets */ for (i = 0; i < strip_count; i++) { - out_le_u32(temp32, strip_offset[i]); - fm_write(&temp32, 4, 1, fmp); + zint_out_le_u32(temp32, strip_offset[i]); + zint_fm_write(&temp32, 4, 1, fmp); } /* Strip byte lengths */ for (i = 0; i < strip_count; i++) { - out_le_u32(temp32, strip_bytes[i]); - fm_write(&temp32, 4, 1, fmp); + zint_out_le_u32(temp32, strip_bytes[i]); + zint_fm_write(&temp32, 4, 1, fmp); } total_bytes_put += strip_count * 8; } /* XResolution */ - out_le_u32(temp32, symbol->dpmm ? symbol->dpmm : 72); - fm_write(&temp32, 4, 1, fmp); - out_le_u32(temp32, symbol->dpmm ? 10 /*cm*/ : 1); - fm_write(&temp32, 4, 1, fmp); + zint_out_le_u32(temp32, symbol->dpmm ? symbol->dpmm : 72); + zint_fm_write(&temp32, 4, 1, fmp); + zint_out_le_u32(temp32, symbol->dpmm ? 10 /*cm*/ : 1); + zint_fm_write(&temp32, 4, 1, fmp); total_bytes_put += 8; /* YResolution */ - out_le_u32(temp32, symbol->dpmm ? symbol->dpmm : 72); - fm_write(&temp32, 4, 1, fmp); - out_le_u32(temp32, symbol->dpmm ? 10 /*cm*/ : 1); - fm_write(&temp32, 4, 1, fmp); + zint_out_le_u32(temp32, symbol->dpmm ? symbol->dpmm : 72); + zint_fm_write(&temp32, 4, 1, fmp); + zint_out_le_u32(temp32, symbol->dpmm ? 10 /*cm*/ : 1); + zint_fm_write(&temp32, 4, 1, fmp); total_bytes_put += 8; if (color_map_size) { for (i = 0; i < color_map_size; i++) { - fm_write(&color_map[i].red, 2, 1, fmp); + zint_fm_write(&color_map[i].red, 2, 1, fmp); } for (i = 0; i < color_map_size; i++) { - fm_write(&color_map[i].green, 2, 1, fmp); + zint_fm_write(&color_map[i].green, 2, 1, fmp); } for (i = 0; i < color_map_size; i++) { - fm_write(&color_map[i].blue, 2, 1, fmp); + zint_fm_write(&color_map[i].blue, 2, 1, fmp); } total_bytes_put += 6 * color_map_size; } - if (fm_error(fmp)) { - ZEXT errtxtf(0, symbol, 679, "Incomplete write of TIF output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); - (void) fm_close(fmp, symbol); + if (zint_fm_error(fmp)) { + ZEXT z_errtxtf(0, symbol, 679, "Incomplete write of TIF output (%1$d: %2$s)", fmp->err, strerror(fmp->err)); + (void) zint_fm_close(fmp, symbol); return ZINT_ERROR_FILE_WRITE; } if (!output_to_stdout) { - if (fm_tell(fmp) != total_bytes_put) { - (void) fm_close(fmp, symbol); - return errtxt(ZINT_ERROR_FILE_WRITE, symbol, 674, "Failed to write all TIF output"); + if (zint_fm_tell(fmp) != total_bytes_put) { + (void) zint_fm_close(fmp, symbol); + return z_errtxt(ZINT_ERROR_FILE_WRITE, symbol, 674, "Failed to write all TIF output"); } } - if (!fm_close(fmp, symbol)) { - return ZEXT errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 981, "Failure on closing TIF output file (%1$d: %2$s)", - fmp->err, strerror(fmp->err)); + if (!zint_fm_close(fmp, symbol)) { + return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 981, "Failure on closing TIF output file (%1$d: %2$s)", + fmp->err, strerror(fmp->err)); } return 0; diff --git a/backend/tif_lzw.h b/backend/tif_lzw.h index a8eaf51b..02e74615 100644 --- a/backend/tif_lzw.h +++ b/backend/tif_lzw.h @@ -1,7 +1,7 @@ /* tif_lzw.h - LZW compression for TIFF */ /* libzint - the open source barcode library - Copyright (C) 2021-2024 Robin Stuart + Copyright (C) 2021-2025 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -168,10 +168,10 @@ static void tif_lzw_cl_hash(tif_lzw_state *sp) { #define PutNextCode(op_fmp, c) { \ nextdata = (nextdata << nbits) | c; \ nextbits += nbits; \ - fm_putc((nextdata >> (nextbits - 8)) & 0xff, op_fmp); \ + zint_fm_putc((nextdata >> (nextbits - 8)) & 0xff, op_fmp); \ nextbits -= 8; \ if (nextbits >= 8) { \ - fm_putc((nextdata >> (nextbits - 8)) & 0xff, op_fmp); \ + zint_fm_putc((nextdata >> (nextbits - 8)) & 0xff, op_fmp); \ nextbits -= 8; \ } \ outcount += nbits; \ @@ -358,7 +358,7 @@ static int tif_lzw_encode(tif_lzw_state *sp, struct filemem *op_fmp, const unsig PutNextCode(op_fmp, CODE_EOI); /* Explicit 0xff masking to make icc -check=conversions happy */ if (nextbits > 0) { - fm_putc((nextdata << (8 - nextbits)) & 0xff, op_fmp); + zint_fm_putc((nextdata << (8 - nextbits)) & 0xff, op_fmp); } return 1; diff --git a/backend/ultra.c b/backend/ultra.c index 4254a044..bb9257b9 100644 --- a/backend/ultra.c +++ b/backend/ultra.c @@ -306,8 +306,8 @@ static float ult_look_ahead_ascii(unsigned char source[], const int length, cons /* Check for double digits */ done = 0; if (i + 1 < length) { - first_digit = posn(ult_digit, source[i]); - second_digit = posn(ult_digit, source[i + 1]); + first_digit = z_posn(ult_digit, source[i]); + second_digit = z_posn(ult_digit, source[i + 1]); if ((first_digit != -1) && (second_digit != -1)) { /* Double digit can be encoded */ if ((first_digit >= 0) && (first_digit <= 9) && (second_digit >= 0) && (second_digit <= 9)) { @@ -395,10 +395,10 @@ static int ult_c43_should_latch_other(const unsigned char source[], const int le } i += fraglen - 1; } else { - if (posn(set, source[i]) != -1) { + if (z_posn(set, source[i]) != -1) { cnt++; } - if (posn(alt_set, source[i]) != -1) { + if (z_posn(alt_set, source[i]) != -1) { alt_cnt++; } } @@ -416,21 +416,21 @@ static int ult_get_subset(const unsigned char source[], const int length, const if ((fragno != -1) && (fragno != 26)) { subset = 3; } else if (current_subset == 2) { - if (posn(ult_c43_set2, source[in_locn]) != -1) { + if (z_posn(ult_c43_set2, source[in_locn]) != -1) { subset = 2; - } else if (posn(ult_c43_set1, source[in_locn]) != -1) { + } else if (z_posn(ult_c43_set1, source[in_locn]) != -1) { subset = 1; } } else { - if (posn(ult_c43_set1, source[in_locn]) != -1) { + if (z_posn(ult_c43_set1, source[in_locn]) != -1) { subset = 1; - } else if (posn(ult_c43_set2, source[in_locn]) != -1) { + } else if (z_posn(ult_c43_set2, source[in_locn]) != -1) { subset = 2; } } if (subset == 0) { - if (posn(ult_c43_set3, source[in_locn]) != -1) { + if (z_posn(ult_c43_set3, source[in_locn]) != -1) { subset = 3; } } @@ -537,7 +537,7 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length, } else { subcw[subcodeword_count] = 40; /* Shift to other C43 set for 1 char */ subcodeword_count++; - subcw[subcodeword_count] = posn(new_subset == 1 ? ult_c43_set1 : ult_c43_set2, source[sublocn]); + subcw[subcodeword_count] = z_posn(new_subset == 1 ? ult_c43_set1 : ult_c43_set2, source[sublocn]); subcodeword_count++; sublocn++; continue; @@ -547,11 +547,11 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length, subset = new_subset; if (subset == 1) { - subcw[subcodeword_count] = posn(ult_c43_set1, source[sublocn]); + subcw[subcodeword_count] = z_posn(ult_c43_set1, source[sublocn]); subcodeword_count++; sublocn++; } else if (subset == 2) { - subcw[subcodeword_count] = posn(ult_c43_set2, source[sublocn]); + subcw[subcodeword_count] = z_posn(ult_c43_set2, source[sublocn]); subcodeword_count++; sublocn++; } else if (subset == 3) { @@ -571,7 +571,7 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length, } } else { /* C43 Set 3 codewords 19 to 35 */ - subcw[subcodeword_count] = posn(ult_c43_set3, source[sublocn]) + 19; + subcw[subcodeword_count] = z_posn(ult_c43_set3, source[sublocn]) + 19; subcodeword_count++; sublocn++; } @@ -906,15 +906,15 @@ static int ult_generate_codewords_segs(struct zint_symbol *symbol, struct zint_s codeword_count = ult_generate_codewords(symbol, source, length, 0 /*eci*/, gs1, symbol_mode, ¤t_mode, codewords, codeword_count); - if (raw_text && (rt_init_segs(symbol, seg_count) || rt_cpy_seg(symbol, 0, &segs[0]))) { - return ZINT_ERROR_MEMORY; /* `rt_init_segs()` & `rt_cpy_seg()` only fail with OOM */ + if (raw_text && (z_rt_init_segs(symbol, seg_count) || z_rt_cpy_seg(symbol, 0, &segs[0]))) { + return ZINT_ERROR_MEMORY; /* `z_rt_init_segs()` & `z_rt_cpy_seg()` only fail with OOM */ } for (i = 1; i < seg_count; i++) { codeword_count = ult_generate_codewords(symbol, segs[i].source, segs[i].length, segs[i].eci, gs1, symbol_mode, ¤t_mode, codewords, codeword_count); - if (raw_text && rt_cpy_seg(symbol, i, &segs[i])) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_seg()` only fails with OOM */ + if (raw_text && z_rt_cpy_seg(symbol, i, &segs[i])) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_seg()` only fails with OOM */ } } @@ -923,7 +923,7 @@ static int ult_generate_codewords_segs(struct zint_symbol *symbol, struct zint_s return 0; } -INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { +INTERNAL int zint_ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { int data_cw_count = 0; int acc, qcc; int scr[3] = {0}, scr_cw_count = 0; /* Symbol Control Region (only if have Structured Append) */ @@ -946,7 +946,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int char *pattern; if (symbol->eci > 811799) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 590, "ECI code '%d' out of range (0 to 811799)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 590, "ECI code '%d' out of range (0 to 811799)", symbol->eci); } @@ -954,13 +954,13 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int int link2 = 2; /* Draft Table 7, Structured Append Group (SAG) with no File Number */ if (symbol->structapp.count < 2 || symbol->structapp.count > 8) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 596, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 596, "Structured Append count '%d' out of range (2 to 8)", symbol->structapp.count); } if (symbol->structapp.index < 1 || symbol->structapp.index > symbol->structapp.count) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 597, - "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, 597, + "Structured Append index '%1$d' out of range (1 to count %2$d)", + symbol->structapp.index, symbol->structapp.count); } scr_cw_count = 1; @@ -970,16 +970,16 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int for (id_len = 1; id_len < 6 && symbol->structapp.id[id_len]; id_len++); if (id_len > 5) { /* 282 * 283 + 282 = 80088 */ - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 593, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 593, "Structured Append ID length %d too long (5 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, 594, "Invalid Structured Append ID (digits only)"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 594, "Invalid Structured Append ID (digits only)"); } if (id > 80088) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 595, + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 595, "Structured Append ID value '%d' out of range (1 to 80088)", id); } if (id) { @@ -993,7 +993,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int scr[0] = link2 * 70 + (symbol->structapp.count - 1) * 8 + symbol->structapp.index - 1; } - cw_alloc = segs_length(segs, seg_count) * 2; + cw_alloc = z_segs_length(segs, seg_count) * 2; if (cw_alloc < 283) { cw_alloc = 283; } @@ -1016,7 +1016,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int if (symbol->option_2 > 0) { if (symbol->option_2 > 2) { - return errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 592, "Revision '%d' out of range (1 or 2 only)", + return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 592, "Revision '%d' out of range (1 or 2 only)", symbol->option_2); } if (symbol->option_2 == 2) { /* Revision 2, swop and inversion of DCCU/DCCL tiles */ @@ -1068,9 +1068,9 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int total_cws = data_cw_count + qcc + 3; /* 3 == TCC pattern + RSEC pattern + QCC pattern */ if (total_cws - 3 > 282) { static const int max_data_cws_by_ecc[6] = { 279, 266, 255, 237, 223, 205 }; - return ZEXT errtxtf(ZINT_ERROR_TOO_LONG, symbol, 591, - "Input too long for ECC level EC%1$d, requires %2$d codewords (maximum %3$d)", - ecc_level, data_cw_count, max_data_cws_by_ecc[ecc_level]); + return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 591, + "Input too long for ECC level EC%1$d, requires %2$d codewords (maximum %3$d)", + ecc_level, data_cw_count, max_data_cws_by_ecc[ecc_level]); } rows = 5; @@ -1147,7 +1147,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int } #ifdef ZINT_TEST if (symbol->debug & ZINT_DEBUG_TEST) { - debug_test_codeword_dump_int(symbol, codeword, locn); + z_debug_test_codeword_dump_int(symbol, codeword, locn); } #endif @@ -1256,7 +1256,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int for (i = 0; i < total_height; i++) { symbol->row_height[i] = 1; for (j = 0; j < total_width; j++) { - set_module_colour(symbol, i, j, posn(ult_colour, pattern[(i * total_width) + j])); + z_set_module_colour(symbol, i, j, z_posn(ult_colour, pattern[(i * total_width) + j])); } } symbol->height = total_height; diff --git a/backend/upcean.c b/backend/upcean.c index 452317ea..a8a4bcc7 100644 --- a/backend/upcean.c +++ b/backend/upcean.c @@ -115,14 +115,15 @@ static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int const unsigned char *gtin = symbol->text; int error_number = 0; - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); if (length == 11) { - hrt_cat_chr_nochk(symbol, gs1_check_digit(gtin, 11)); + z_hrt_cat_chr_nochk(symbol, zint_gs1_check_digit(gtin, 11)); } else { - if (source[length - 1] != gs1_check_digit(gtin, 11)) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 270, "Invalid check digit '%1$c', expecting '%2$c'", - source[length - 1], gs1_check_digit(gtin, 11)); + if (source[length - 1] != zint_gs1_check_digit(gtin, 11)) { + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 270, + "Invalid check digit '%1$c', expecting '%2$c'", + source[length - 1], zint_gs1_check_digit(gtin, 11)); } } if (symbol->debug & ZINT_DEBUG_PRINT) { @@ -138,14 +139,14 @@ static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int if (symbol->symbology == BARCODE_UPCA_CC) { symbol->height = height; /* Pass back min row == default height */ } else { - error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); } } else { const float height = 50.0f; if (symbol->symbology == BARCODE_UPCA_CC) { symbol->height = height - cc_rows * 2 - 6.0f; } else { - (void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); } } @@ -177,16 +178,16 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt if (length == 7) { switch (source[0]) { case '0': - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); break; case '1': num_system = 1; - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); break; default: /* Overwrite HRT first char with '0' and ignore first source char */ - hrt_cpy_cat_nochk(symbol, NULL, 0, '0', source + 1, length - 1); - error_number = errtxt(ZINT_WARN_INVALID_OPTION, symbol, 851, + z_hrt_cpy_cat_nochk(symbol, NULL, 0, '0', source + 1, length - 1); + error_number = z_errtxt(ZINT_WARN_INVALID_OPTION, symbol, 851, "Ignoring first digit which is not '0' or '1'"); break; } @@ -196,7 +197,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt length--; } else { /* Length 6, insert leading zero */ - hrt_cpy_cat_nochk(symbol, NULL, 0, '0', source, length); + z_hrt_cpy_cat_nochk(symbol, NULL, 0, '0', source, length); } /* Expand the zero-compressed UPC-E code to make a UPC-A equivalent (Table 5) */ @@ -223,7 +224,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt equivalent[10] = source[4]; if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) { /* Note 1 - "X3 shall not be equal to 0, 1 or 2" */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 271, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 271, "For this UPC-E zero suppression, 3rd character cannot be \"0\", \"1\" or \"2\" (%.*s)", length, source); } @@ -234,7 +235,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt equivalent[10] = source[4]; if (source[3] == '0') { /* Note 2 - "X4 shall not be equal to 0" */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 272, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 272, "For this UPC-E zero suppression, 4th character cannot be \"0\" (%.*s)", length, source); } @@ -250,7 +251,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt equivalent[10] = emode; if (source[4] == '0') { /* Note 3 - "X5 shall not be equal to 0" */ - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 273, + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 273, "For this UPC-E zero suppression, 5th character cannot be \"0\" (%.*s)", length, source); } @@ -259,19 +260,19 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt /* Get the check digit from the expanded UPC-A code */ - check_digit = gs1_check_digit(equivalent, 11); + check_digit = zint_gs1_check_digit(equivalent, 11); if (src_check_digit && src_check_digit != check_digit) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 274, "Invalid check digit '%1$c', expecting '%2$c'", - src_check_digit, check_digit); + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 274, "Invalid check digit '%1$c', expecting '%2$c'", + src_check_digit, check_digit); } equivalent[11] = check_digit; /* Use the number system and check digit information to choose a parity scheme */ if (num_system == 1) { - parity = UPCParity1[ctoi(check_digit)]; + parity = UPCParity1[z_ctoi(check_digit)]; } else { - parity = UPCParity0[ctoi(check_digit)]; + parity = UPCParity0[z_ctoi(check_digit)]; } /* Take all this information and make the barcode pattern */ @@ -294,7 +295,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt /* Stop character */ memcpy(d, "111111", 7); /* Include terminating NUL */ - hrt_cat_chr_nochk(symbol, check_digit); + z_hrt_cat_chr_nochk(symbol, check_digit); if (symbol->debug & ZINT_DEBUG_PRINT) { printf("UPC-E: %s, equivalent: %.11s, hrt: %.8s, Check digit: %c\n", source, equivalent, hrt, check_digit); @@ -307,7 +308,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt if (symbol->symbology == BARCODE_UPCE_CC) { symbol->height = height; /* Pass back min row == default height */ } else { - int warn_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); + int warn_number = z_set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); if (warn_number) { error_number = warn_number; /* Trump first char not '0' or '1' warning if any */ } @@ -317,7 +318,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt if (symbol->symbology == BARCODE_UPCE_CC) { symbol->height = height - cc_rows * 2 - 6.0f; } else { - (void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); } } @@ -338,7 +339,7 @@ static void ean_add_on(const unsigned char source[], const int length, char dest /* If an add-on then append with space */ if (addon_gap != 0) { - *d++ = itoc(addon_gap); + *d++ = z_itoc(addon_gap); } /* Start character */ @@ -349,14 +350,14 @@ static void ean_add_on(const unsigned char source[], const int length, char dest if (length == 2) { /* EAN-2 */ int code_value, parity_bit; - code_value = (10 * ctoi(source[0])) + ctoi(source[1]); + code_value = 10 * z_ctoi(source[0]) + z_ctoi(source[1]); parity_bit = code_value % 4; parity = EAN2Parity[parity_bit]; } else { /* EAN-5 */ int values[6], parity_sum, parity_bit; for (i = 0; i < 6; i++) { - values[i] = ctoi(source[i]); + values[i] = z_ctoi(source[i]); } parity_sum = (3 * (values[0] + values[2] + values[4])); @@ -397,16 +398,17 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in const unsigned char *gtin = symbol->text; int error_number = 0; - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); /* Add the appropriate check digit */ if (length == 12) { - hrt_cat_chr_nochk(symbol, gs1_check_digit(gtin, 12)); + z_hrt_cat_chr_nochk(symbol, zint_gs1_check_digit(gtin, 12)); } else { - if (source[length - 1] != gs1_check_digit(gtin, 12)) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 275, "Invalid check digit '%1$c', expecting '%2$c'", - source[length - 1], gs1_check_digit(gtin, 12)); + if (source[length - 1] != zint_gs1_check_digit(gtin, 12)) { + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 275, + "Invalid check digit '%1$c', expecting '%2$c'", + source[length - 1], zint_gs1_check_digit(gtin, 12)); } } if (symbol->debug & ZINT_DEBUG_PRINT) { @@ -448,7 +450,7 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in || symbol->symbology == BARCODE_EAN13_CC) { symbol->height = height; /* Pass back min row == default height */ } else { - error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); } } else { const float height = 50.0f; @@ -456,7 +458,7 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in || symbol->symbology == BARCODE_EAN13_CC) { symbol->height = height - cc_rows * 2 - 6.0f; } else { - (void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); } } @@ -475,15 +477,15 @@ static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int const unsigned char *gtin = symbol->text; int error_number = 0; - hrt_cpy_nochk(symbol, source, length); + z_hrt_cpy_nochk(symbol, source, length); if (length == 7) { - hrt_cat_chr_nochk(symbol, gs1_check_digit(gtin, 7)); + z_hrt_cat_chr_nochk(symbol, zint_gs1_check_digit(gtin, 7)); } else { - if (source[length - 1] != gs1_check_digit(gtin, 7)) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 276, - "Invalid EAN-8 check digit '%1$c', expecting '%2$c'", - source[length - 1], gs1_check_digit(gtin, 7)); + if (source[length - 1] != zint_gs1_check_digit(gtin, 7)) { + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 276, + "Invalid EAN-8 check digit '%1$c', expecting '%2$c'", + source[length - 1], zint_gs1_check_digit(gtin, 7)); } } if (symbol->debug & ZINT_DEBUG_PRINT) { @@ -501,7 +503,7 @@ static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int || symbol->symbology == BARCODE_EAN13_CC) { symbol->height = height; /* Pass back min row == default height */ } else { - error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); } } else { const float height = 50.0f; @@ -509,7 +511,7 @@ static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int || symbol->symbology == BARCODE_EAN13_CC) { symbol->height = height - cc_rows * 2 - 6.0f; } else { - (void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); + (void) z_set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); } } @@ -530,12 +532,12 @@ static char isbnx_check(const unsigned char source[], const int length) { weight = 1; for (i = 0; i < length; i++) { /* Length will always be 9 */ - sum += ctoi(source[i]) * weight; + sum += z_ctoi(source[i]) * weight; weight++; } check = sum % 11; - check_char = itoc(check); + check_char = z_itoc(check); if (check == 10) { check_char = 'X'; } @@ -547,32 +549,33 @@ static int isbnx(struct zint_symbol *symbol, unsigned char source[], const int l int i; char check_digit; - to_upper(source, length); - if (not_sane(ISBNX_SANE_F, source, length)) { /* As source has been zero-padded, don't report position */ - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 277, "Invalid character in input (digits and \"X\" only)"); + z_to_upper(source, length); + if (z_not_sane(ISBNX_SANE_F, source, length)) { /* As source has been zero-padded, don't report position */ + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 277, "Invalid character in input (digits and \"X\" only)"); } /* Input must be 9, 10 or 13 characters */ if (length != 9 && length != 10 && length != 13) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 278, "Input length %d wrong (9, 10, or 13 characters required)", + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 278, "Input length %d wrong (9, 10, or 13 characters required)", length); } if (length == 13) /* Using 13 character ISBN */ { if (!(((source[0] == '9') && (source[1] == '7')) && ((source[2] == '8') || (source[2] == '9')))) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 279, "Invalid ISBN (must begin with \"978\" or \"979\")"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 279, + "Invalid ISBN (must begin with \"978\" or \"979\")"); } /* "X" cannot occur */ - if (not_sane(NEON_F, source, 13)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 282, + if (z_not_sane(NEON_F, source, 13)) { + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 282, "Invalid character in input, \"X\" not allowed in ISBN-13"); } - check_digit = gs1_check_digit(source, 12); + check_digit = zint_gs1_check_digit(source, 12); if (source[12] != check_digit) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 280, + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 280, "Invalid ISBN check digit '%1$c', expecting '%2$c'", source[12], check_digit); } source[12] = '\0'; @@ -587,16 +590,16 @@ static int isbnx(struct zint_symbol *symbol, unsigned char source[], const int l } /* "X" can only occur in last position */ - if (not_sane(NEON_F, source, 9)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 296, + if (z_not_sane(NEON_F, source, 9)) { + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 296, "Invalid character in input, \"X\" allowed in last position only"); } check_digit = isbnx_check(source, 9); if (check_digit != source[9]) { - return ZEXT errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 281, - "Invalid %1$s check digit '%2$c', expecting '%3$c'", length == 9 ? "SBN" : "ISBN", - source[9], check_digit); + return ZEXT z_errtxtf(ZINT_ERROR_INVALID_CHECK, symbol, 281, + "Invalid %1$s check digit '%2$c', expecting '%3$c'", length == 9 ? "SBN" : "ISBN", + source[9], check_digit); } for (i = 11; i > 2; i--) { /* This drops the check digit */ source[i] = source[i - 3]; @@ -649,7 +652,7 @@ static int ean_is_upce(const unsigned char source[], unsigned char *out) { } /* Add leading zeroes to EAN and UPC strings and split into parts (second part add-on if any) */ -INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char source[], const int length, +INTERNAL int zint_ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char source[], const int length, unsigned char local_source[], int *p_with_addon, unsigned char *zfirst_part, unsigned char *zsecond_part) { unsigned char first_part[14], second_part[6]; @@ -660,8 +663,8 @@ INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char symbology == BARCODE_EAN_2ADDON ? 2 : symbology == BARCODE_EAN_5ADDON ? 5 : 13; /* Accept GINT-13 with correct check digit, with or without 2/5-digit (no separator) */ - if ((length == 13 || length == 15 || length == 18) && !not_sane(NEON_F, source, length) - && gs1_check_digit(ZCUCP(source), 12) == source[12]) { + if ((length == 13 || length == 15 || length == 18) && !z_not_sane(NEON_F, source, length) + && zint_gs1_check_digit(ZCUCP(source), 12) == source[12]) { int local_length = 0; if (symbology == BARCODE_EAN13 || symbology == BARCODE_EAN13_CC || symbology == BARCODE_EANX || symbology == BARCODE_EANX_CHK || symbology == BARCODE_EANX_CC) { @@ -718,12 +721,12 @@ INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char if (first_len > max || second_len > 5) { if (first_len > max) { if (!second_len || symbology == BARCODE_EAN_2ADDON || symbology == BARCODE_EAN_5ADDON) { - ZEXT errtxtf(0, symbol, 294, "Input length %1$d too long (maximum %2$d)", first_len, max); + ZEXT z_errtxtf(0, symbol, 294, "Input length %1$d too long (maximum %2$d)", first_len, max); } else { - ZEXT errtxtf(0, symbol, 298, "Input EAN length %1$d too long (maximum %2$d)", first_len, max); + ZEXT z_errtxtf(0, symbol, 298, "Input EAN length %1$d too long (maximum %2$d)", first_len, max); } } else { - errtxtf(0, symbol, 297, "Input add-on length %d too long (maximum 5)", second_len); + z_errtxtf(0, symbol, 297, "Input add-on length %d too long (maximum 5)", second_len); } if (p_with_addon) { *p_with_addon = with_addon; @@ -839,18 +842,18 @@ INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char } memcpy(local_source + i, first_part, first_len + 1); /* Include terminating NUL */ if (zfirst_part) { - memcpy(zfirst_part, local_source, ustrlen(local_source) + 1); + memcpy(zfirst_part, local_source, z_ustrlen(local_source) + 1); } if (with_addon) { - int h = (int) ustrlen(local_source); + int h = (int) z_ustrlen(local_source); local_source[h++] = '+'; for (i = 0; i < (zsecond_len - second_len); i++) { local_source[h + i] = '0'; } memcpy(local_source + h + i, second_part, second_len + 1); /* Include terminating NUL */ if (zsecond_part) { - memcpy(zsecond_part, local_source + h, ustrlen(local_source + h) + 1); + memcpy(zsecond_part, local_source + h, z_ustrlen(local_source + h) + 1); } } else if (zsecond_part) { *zsecond_part = '\0'; @@ -864,7 +867,7 @@ INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char } /* Make EAN/UPC and ISBN, allowing for composite if `cc_rows` set */ -INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { +INTERNAL int zint_eanx_cc(struct zint_symbol *symbol, unsigned char source[], int length, const int cc_rows) { unsigned char first_part[14], second_part[6]; unsigned char local_source[20]; /* Allow 13 + "+" + 5 + 1 */ unsigned char equivalent[12] = {0}; /* For UPC-E - GTIN-12 equivalent */ @@ -876,23 +879,23 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; if (length > 19) { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 283, "Input length %d too long (maximum 19)", length); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 283, "Input length %d too long (maximum 19)", length); } if (symbol->symbology == BARCODE_ISBNX) { /* ISBN has its own sanity routine */ - if ((i = not_sane(ISBNX_ADDON_SANE_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 285, + if ((i = z_not_sane(ISBNX_ADDON_SANE_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 285, "Invalid character at position %d in input (digits, \"X\" and \"+\" or space only)", i); } /* Add-on will be checked separately to be numeric only below */ } else if (symbol->symbology == BARCODE_EAN_2ADDON || symbol->symbology == BARCODE_EAN_5ADDON) { - if ((i = not_sane(NEON_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 852, + if ((i = z_not_sane(NEON_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 852, "Invalid character at position %d in input (digits only)", i); } } else { - if ((i = not_sane(SODIUM_PLS_SPC_F, source, length))) { - return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 284, + if ((i = z_not_sane(SODIUM_PLS_SPC_F, source, length))) { + return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 284, "Invalid character at position %d in input (digits and \"+\" or space only)", i); } } @@ -902,14 +905,15 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len for (i = 0; i < length; i++) { if (source[i] == '+' || source[i] == ' ') { if (++sep_count > 1) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 293, "Invalid add-on data (one \"+\" or space only)"); + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 293, + "Invalid add-on data (one \"+\" or space only)"); } } } /* Add leading zeroes, checking max lengths of parts */ - if (!ean_leading_zeroes(symbol, source, length, local_source, &with_addon, first_part, second_part)) { - return ZINT_ERROR_TOO_LONG; /* `ean_leading_zeroes()` sets `errtxt` */ + if (!zint_ean_leading_zeroes(symbol, source, length, local_source, &with_addon, first_part, second_part)) { + return ZINT_ERROR_TOO_LONG; /* `zint_ean_leading_zeroes()` sets `errtxt` */ } if (with_addon) { @@ -921,7 +925,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len } } - first_part_len = (int) ustrlen(first_part); + first_part_len = (int) z_ustrlen(first_part); switch (symbol->symbology) { case BARCODE_EAN8: @@ -934,13 +938,13 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len case 2: case 5: ean_add_on(first_part, first_part_len, dest, 0); - hrt_cpy_nochk(symbol, first_part, first_part_len); + z_hrt_cpy_nochk(symbol, first_part, first_part_len); if (symbol->output_options & COMPLIANT_HEIGHT) { /* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-6 */ const float height = 66.3636398f; /* 21.9 / 0.33 */ - error_number = set_height(symbol, height, height, 0.0f, 0 /*no_errtxt*/); + error_number = z_set_height(symbol, height, height, 0.0f, 0 /*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*/); } break; case 7: @@ -953,8 +957,9 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len break; default: assert(symbol->symbology == BARCODE_EANX || symbol->symbology == BARCODE_EANX_CHK); - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 286, - "Input length %d wrong (2, 5, 7, 8, 12 or 13 characters required)", first_part_len); + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 286, + "Input length %d wrong (2, 5, 7, 8, 12 or 13 characters required)", + first_part_len); break; } break; @@ -964,12 +969,12 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len switch (first_part_len) { /* Adds vertical separator bars according to ISO/IEC 24723 section 11.4 */ case 7: case 8: - set_module(symbol, symbol->rows, 1); - set_module(symbol, symbol->rows, 67); - set_module(symbol, symbol->rows + 1, 0); - set_module(symbol, symbol->rows + 1, 68); - set_module(symbol, symbol->rows + 2, 1); - set_module(symbol, symbol->rows + 2, 67); + z_set_module(symbol, symbol->rows, 1); + z_set_module(symbol, symbol->rows, 67); + z_set_module(symbol, symbol->rows + 1, 0); + z_set_module(symbol, symbol->rows + 1, 68); + z_set_module(symbol, symbol->rows + 2, 1); + z_set_module(symbol, symbol->rows + 2, 67); symbol->row_height[symbol->rows] = 2; symbol->row_height[symbol->rows + 1] = 2; symbol->row_height[symbol->rows + 2] = 2; @@ -978,12 +983,12 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len break; case 12: case 13: - set_module(symbol, symbol->rows, 1); - set_module(symbol, symbol->rows, 95); - set_module(symbol, symbol->rows + 1, 0); - set_module(symbol, symbol->rows + 1, 96); - set_module(symbol, symbol->rows + 2, 1); - set_module(symbol, symbol->rows + 2, 95); + z_set_module(symbol, symbol->rows, 1); + z_set_module(symbol, symbol->rows, 95); + z_set_module(symbol, symbol->rows + 1, 0); + z_set_module(symbol, symbol->rows + 1, 96); + z_set_module(symbol, symbol->rows + 2, 1); + z_set_module(symbol, symbol->rows + 2, 95); symbol->row_height[symbol->rows] = 2; symbol->row_height[symbol->rows + 1] = 2; symbol->row_height[symbol->rows + 2] = 2; @@ -992,7 +997,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len break; default: assert(symbol->symbology == BARCODE_EANX_CC); - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 287, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 287, "Input length %d wrong (7, 12 or 13 characters required)", first_part_len); break; } @@ -1002,25 +1007,25 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len if (first_part_len <= 12) { error_number = upca(symbol, first_part, first_part_len, dest); } else { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 288, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 288, "Input length %d too long (maximum 12)", first_part_len); } break; case BARCODE_UPCA_CC: if (first_part_len <= 12) { - set_module(symbol, symbol->rows, 1); - set_module(symbol, symbol->rows, 95); - set_module(symbol, symbol->rows + 1, 0); - set_module(symbol, symbol->rows + 1, 96); - set_module(symbol, symbol->rows + 2, 1); - set_module(symbol, symbol->rows + 2, 95); + z_set_module(symbol, symbol->rows, 1); + z_set_module(symbol, symbol->rows, 95); + z_set_module(symbol, symbol->rows + 1, 0); + z_set_module(symbol, symbol->rows + 1, 96); + z_set_module(symbol, symbol->rows + 2, 1); + z_set_module(symbol, symbol->rows + 2, 95); symbol->row_height[symbol->rows] = 2; symbol->row_height[symbol->rows + 1] = 2; symbol->row_height[symbol->rows + 2] = 2; symbol->rows += 3; error_number = upca_cc(symbol, first_part, first_part_len, dest, cc_rows); } else { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 289, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 289, "Input length %d too long (maximum 12)", first_part_len); } break; @@ -1029,25 +1034,25 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len if (first_part_len <= 8) { error_number = upce(symbol, first_part, first_part_len, dest, equivalent); } else { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 290, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 290, "Input length %d too long (maximum 8)", first_part_len); } break; case BARCODE_UPCE_CC: if (first_part_len <= 8) { - set_module(symbol, symbol->rows, 1); - set_module(symbol, symbol->rows, 51); - set_module(symbol, symbol->rows + 1, 0); - set_module(symbol, symbol->rows + 1, 52); - set_module(symbol, symbol->rows + 2, 1); - set_module(symbol, symbol->rows + 2, 51); + z_set_module(symbol, symbol->rows, 1); + z_set_module(symbol, symbol->rows, 51); + z_set_module(symbol, symbol->rows + 1, 0); + z_set_module(symbol, symbol->rows + 1, 52); + z_set_module(symbol, symbol->rows + 2, 1); + z_set_module(symbol, symbol->rows + 2, 51); symbol->row_height[symbol->rows] = 2; symbol->row_height[symbol->rows + 1] = 2; symbol->row_height[symbol->rows + 2] = 2; symbol->rows += 3; error_number = upce_cc(symbol, first_part, first_part_len, dest, cc_rows, equivalent); } else { - return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 291, + return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 291, "Input length %d too long (maximum 8)", first_part_len); } break; @@ -1060,36 +1065,36 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len return error_number; } - second_part_len = (int) ustrlen(second_part); + second_part_len = (int) z_ustrlen(second_part); if (symbol->symbology == BARCODE_ISBNX) { /* Need to further check that add-on numeric only */ - if (not_sane(NEON_F, second_part, second_part_len)) { - return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 295, "Invalid add-on data (digits only)"); + if (z_not_sane(NEON_F, second_part, second_part_len)) { + return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 295, "Invalid add-on data (digits only)"); } } if (second_part_len) { ean_add_on(second_part, second_part_len, dest, addon_gap); - hrt_cat_chr_nochk(symbol, '+'); - hrt_cat_nochk(symbol, second_part, second_part_len); + z_hrt_cat_chr_nochk(symbol, '+'); + z_hrt_cat_nochk(symbol, second_part, second_part_len); if (first_part_len <= 8 && (symbol->symbology == BARCODE_EAN8 || symbol->symbology == BARCODE_EANX || symbol->symbology == BARCODE_EANX_CHK || symbol->symbology == BARCODE_EANX_CC || symbol->symbology == BARCODE_EAN8_CC)) { - error_number = errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 292, "EAN-8 with add-on is non-standard"); + error_number = z_errtxt(ZINT_WARN_NONCOMPLIANT, symbol, 292, "EAN-8 with add-on is non-standard"); } } if (raw_text) { - const int ean = is_ean(symbol->symbology); + const int is_ean = z_is_ean(symbol->symbology); /* EAN-8 with no add-on, EAN-2, EAN-5 */ - if (ean && symbol->text_length <= 8 && !second_part_len) { - if (rt_cpy(symbol, symbol->text, symbol->text_length)) { /* Just use the HRT */ - return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */ + if (is_ean && symbol->text_length <= 8 && !second_part_len) { + if (z_rt_cpy(symbol, symbol->text, symbol->text_length)) { /* Just use the HRT */ + return ZINT_ERROR_MEMORY; /* `z_rt_cpy()` only fails with OOM */ } } else { /* Expand to GTIN-13 (UPC-A, UPC-E, EAN-8 with add-on) */ unsigned char gtin13[13]; /* EAN-13, ISBNX */ - if (ean && symbol->text_length >= 13) { + if (is_ean && symbol->text_length >= 13) { memcpy(gtin13, symbol->text, 13); /* UPC-E */ } else if (*equivalent) { @@ -1102,13 +1107,13 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len memset(gtin13, '0', zeroes); memcpy(gtin13 + zeroes, symbol->text, 13 - zeroes); } - if (rt_cpy_cat(symbol, gtin13, 13, '\xFF' /*none*/, second_part, second_part_len)) { - return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */ + if (z_rt_cpy_cat(symbol, gtin13, 13, '\xFF' /*none*/, second_part, second_part_len)) { + return ZINT_ERROR_MEMORY; /* `z_rt_cpy_cat()` only fails with OOM */ } } } - expand(symbol, dest, (int) strlen(dest)); + z_expand(symbol, dest, (int) strlen(dest)); switch (symbol->symbology) { case BARCODE_EANX_CC: @@ -1118,13 +1123,13 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len case BARCODE_UPCE_CC: /* Shift the symbol to the right one space to allow for separator bars */ for (i = (symbol->width + 1); i >= 1; i--) { - if (module_is_set(symbol, symbol->rows - 1, i - 1)) { - set_module(symbol, symbol->rows - 1, i); + if (z_module_is_set(symbol, symbol->rows - 1, i - 1)) { + z_set_module(symbol, symbol->rows - 1, i); } else { - unset_module(symbol, symbol->rows - 1, i); + z_unset_module(symbol, symbol->rows - 1, i); } } - unset_module(symbol, symbol->rows - 1, 0); + z_unset_module(symbol, symbol->rows - 1, 0); symbol->width += 1 + (second_part_len == 0); /* Only need right space if no add-on */ break; } @@ -1133,8 +1138,8 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int len } /* Handle UPC (UPC-A/E), EAN (EAN-13, EAN-8, EAN 2-digit add-on, EAN 5-digit add-on), ISBN */ -INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int length) { - return eanx_cc(symbol, source, length, 0 /*cc_rows*/); +INTERNAL int zint_eanx(struct zint_symbol *symbol, unsigned char source[], int length) { + return zint_eanx_cc(symbol, source, length, 0 /*cc_rows*/); } /* vim: set ts=4 sw=4 et : */ diff --git a/backend/vector.c b/backend/vector.c index 319c3e95..c966e172 100644 --- a/backend/vector.c +++ b/backend/vector.c @@ -34,9 +34,9 @@ #include "output.h" #include "zfiletypes.h" -INTERNAL int ps_plot(struct zint_symbol *symbol); -INTERNAL int svg_plot(struct zint_symbol *symbol); -INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle); +INTERNAL int zint_ps_plot(struct zint_symbol *symbol); +INTERNAL int zint_svg_plot(struct zint_symbol *symbol); +INTERNAL int zint_emf_plot(struct zint_symbol *symbol, int rotate_angle); static int vector_add_rect(struct zint_symbol *symbol, const float x, const float y, const float width, const float height, struct zint_vector_rect **last_rect) { @@ -45,7 +45,7 @@ static int vector_add_rect(struct zint_symbol *symbol, const float x, const floa if (!(rect = (struct zint_vector_rect *) malloc(sizeof(struct zint_vector_rect)))) { /* NOTE: clang-tidy-20 gets confused about return value of function returning a function unfortunately, so put on 2 lines (see also "postal.c" `postnet_enc()` & `planet_enc()`, same issue) */ - errtxt(0, symbol, 691, "Insufficient memory for vector rectangle"); + z_errtxt(0, symbol, 691, "Insufficient memory for vector rectangle"); return 0; } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ @@ -74,7 +74,7 @@ static int vector_add_hexagon(struct zint_symbol *symbol, const float x, const f struct zint_vector_hexagon *hexagon; if (!(hexagon = (struct zint_vector_hexagon *) malloc(sizeof(struct zint_vector_hexagon)))) { - return errtxt(0, symbol, 692, "Insufficient memory for vector hexagon"); + return z_errtxt(0, symbol, 692, "Insufficient memory for vector hexagon"); } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ memset(hexagon, 0, sizeof(struct zint_vector_hexagon)); @@ -100,7 +100,7 @@ static int vector_add_circle(struct zint_symbol *symbol, const float x, const fl struct zint_vector_circle *circle; if (!(circle = (struct zint_vector_circle *) malloc(sizeof(struct zint_vector_circle)))) { - return errtxt(0, symbol, 693, "Insufficient memory for vector circle"); + return z_errtxt(0, symbol, 693, "Insufficient memory for vector circle"); } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ memset(circle, 0, sizeof(struct zint_vector_circle)); @@ -128,7 +128,7 @@ static int vector_add_string(struct zint_symbol *symbol, const unsigned char *te struct zint_vector_string *string; if (!(string = (struct zint_vector_string *) malloc(sizeof(struct zint_vector_string)))) { - return errtxt(0, symbol, 694, "Insufficient memory for vector string"); + return z_errtxt(0, symbol, 694, "Insufficient memory for vector string"); } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ memset(string, 0, sizeof(struct zint_vector_string)); @@ -138,12 +138,12 @@ static int vector_add_string(struct zint_symbol *symbol, const unsigned char *te string->y = y; string->width = width; string->fsize = fsize; - string->length = length == -1 ? (int) ustrlen(text) : length; + string->length = length == -1 ? (int) z_ustrlen(text) : length; string->rotation = 0; string->halign = halign; if (!(string->text = (unsigned char *) malloc(string->length + 1))) { free(string); - return errtxt(0, symbol, 695, "Insufficient memory for vector string text"); + return z_errtxt(0, symbol, 695, "Insufficient memory for vector string text"); } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ memset(string->text, 0, string->length + 1); @@ -161,7 +161,7 @@ static int vector_add_string(struct zint_symbol *symbol, const unsigned char *te return 1; } -INTERNAL void vector_free(struct zint_symbol *symbol) { +INTERNAL void zint_vector_free(struct zint_symbol *symbol) { if (symbol->vector != NULL) { struct zint_vector_rect *rect; struct zint_vector_hexagon *hex; @@ -223,41 +223,41 @@ static void vector_scale(struct zint_symbol *symbol, const int file_type) { scale *= 20; } - symbol->vector->width = stripf(symbol->vector->width * scale); - symbol->vector->height = stripf(symbol->vector->height * scale); + symbol->vector->width = z_stripf(symbol->vector->width * scale); + symbol->vector->height = z_stripf(symbol->vector->height * scale); rect = symbol->vector->rectangles; while (rect) { - rect->x = stripf(rect->x * scale); - rect->y = stripf(rect->y * scale); - rect->height = stripf(rect->height * scale); - rect->width = stripf(rect->width * scale); + rect->x = z_stripf(rect->x * scale); + rect->y = z_stripf(rect->y * scale); + rect->height = z_stripf(rect->height * scale); + rect->width = z_stripf(rect->width * scale); rect = rect->next; } hex = symbol->vector->hexagons; while (hex) { - hex->x = stripf(hex->x * scale); - hex->y = stripf(hex->y * scale); - hex->diameter = stripf(hex->diameter * scale); + hex->x = z_stripf(hex->x * scale); + hex->y = z_stripf(hex->y * scale); + hex->diameter = z_stripf(hex->diameter * scale); hex = hex->next; } circle = symbol->vector->circles; while (circle) { - circle->x = stripf(circle->x * scale); - circle->y = stripf(circle->y * scale); - circle->diameter = stripf(circle->diameter * scale); - circle->width = stripf(circle->width * scale); + circle->x = z_stripf(circle->x * scale); + circle->y = z_stripf(circle->y * scale); + circle->diameter = z_stripf(circle->diameter * scale); + circle->width = z_stripf(circle->width * scale); circle = circle->next; } string = symbol->vector->strings; while (string) { - string->x = stripf(string->x * scale); - string->y = stripf(string->y * scale); - string->width = stripf(string->width * scale); - string->fsize = stripf(string->fsize * scale); + string->x = z_stripf(string->x * scale); + string->y = z_stripf(string->y * scale); + string->width = z_stripf(string->width * scale); + string->fsize = z_stripf(string->fsize * scale); string = string->next; } } @@ -279,18 +279,18 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) { while (rect) { if (rotate_angle == 90) { temp = rect->x; - rect->x = stripf(symbol->vector->height - (rect->y + rect->height)); + rect->x = z_stripf(symbol->vector->height - (rect->y + rect->height)); rect->y = temp; temp = rect->width; rect->width = rect->height; rect->height = temp; } else if (rotate_angle == 180) { - rect->x = stripf(symbol->vector->width - (rect->x + rect->width)); - rect->y = stripf(symbol->vector->height - (rect->y + rect->height)); + rect->x = z_stripf(symbol->vector->width - (rect->x + rect->width)); + rect->y = z_stripf(symbol->vector->height - (rect->y + rect->height)); } else if (rotate_angle == 270) { temp = rect->x; rect->x = rect->y; - rect->y = stripf(symbol->vector->width - (temp + rect->width)); + rect->y = z_stripf(symbol->vector->width - (temp + rect->width)); temp = rect->width; rect->width = rect->height; rect->height = temp; @@ -302,17 +302,17 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) { while (hex) { if (rotate_angle == 90) { temp = hex->x; - hex->x = stripf(symbol->vector->height - hex->y); + hex->x = z_stripf(symbol->vector->height - hex->y); hex->y = temp; hex->rotation = 90; } else if (rotate_angle == 180) { - hex->x = stripf(symbol->vector->width - hex->x); - hex->y = stripf(symbol->vector->height - hex->y); + hex->x = z_stripf(symbol->vector->width - hex->x); + hex->y = z_stripf(symbol->vector->height - hex->y); hex->rotation = 180; } else if (rotate_angle == 270) { temp = hex->x; hex->x = hex->y; - hex->y = stripf(symbol->vector->width - temp); + hex->y = z_stripf(symbol->vector->width - temp); hex->rotation = 270; } hex = hex->next; @@ -322,15 +322,15 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) { while (circle) { if (rotate_angle == 90) { temp = circle->x; - circle->x = stripf(symbol->vector->height - circle->y); + circle->x = z_stripf(symbol->vector->height - circle->y); circle->y = temp; } else if (rotate_angle == 180) { - circle->x = stripf(symbol->vector->width - circle->x); - circle->y = stripf(symbol->vector->height - circle->y); + circle->x = z_stripf(symbol->vector->width - circle->x); + circle->y = z_stripf(symbol->vector->height - circle->y); } else if (rotate_angle == 270) { temp = circle->x; circle->x = circle->y; - circle->y = stripf(symbol->vector->width - temp); + circle->y = z_stripf(symbol->vector->width - temp); } circle = circle->next; } @@ -339,17 +339,17 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) { while (string) { if (rotate_angle == 90) { temp = string->x; - string->x = stripf(symbol->vector->height - string->y); + string->x = z_stripf(symbol->vector->height - string->y); string->y = temp; string->rotation = 90; } else if (rotate_angle == 180) { - string->x = stripf(symbol->vector->width - string->x); - string->y = stripf(symbol->vector->height - string->y); + string->x = z_stripf(symbol->vector->width - string->x); + string->y = z_stripf(symbol->vector->height - string->y); string->rotation = 180; } else if (rotate_angle == 270) { temp = string->x; string->x = string->y; - string->y = stripf(symbol->vector->width - temp); + string->y = z_stripf(symbol->vector->width - temp); string->rotation = 270; } string = string->next; @@ -373,7 +373,7 @@ static void vector_reduce_rectangles(struct zint_symbol *symbol) { while (target) { if ((rect->x == target->x) && (rect->width == target->width) - && (stripf(rect->y + rect->height) == target->y) && (rect->colour == target->colour)) { + && (z_stripf(rect->y + rect->height) == target->y) && (rect->colour == target->colour)) { rect->height += target->height; prev->next = target->next; free(target); @@ -387,7 +387,7 @@ static void vector_reduce_rectangles(struct zint_symbol *symbol) { } } -INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) { +INTERNAL int zint_plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_type) { int error_number, warn_number = 0; int main_width; int comp_xoffset = 0; @@ -444,20 +444,20 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ memset(first_row_rects, 0, sizeof(struct zint_vector_rect *) * (symbol->rows + 1)); /* Free any previous rendering structures */ - vector_free(symbol); + zint_vector_free(symbol); /* Sanity check colours */ - error_number = out_check_colour_options(symbol); + error_number = zint_out_check_colour_options(symbol); if (error_number != 0) { return error_number; } if (symbol->rows <= 0) { - return errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 697, "No rows"); + return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 697, "No rows"); } /* Allocate memory */ if (!(vector = symbol->vector = (struct zint_vector *) malloc(sizeof(struct zint_vector)))) { - return errtxt(ZINT_ERROR_MEMORY, symbol, 696, "Insufficient memory for vector header"); + return z_errtxt(ZINT_ERROR_MEMORY, symbol, 696, "Insufficient memory for vector header"); } #ifdef ZINT_SANITIZEM /* Suppress clang -fsanitize=memory false positive */ memset(vector, 0, sizeof(struct zint_vector)); @@ -467,28 +467,28 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ vector->circles = NULL; vector->strings = NULL; - large_bar_height = out_large_bar_height(symbol, 0 /*si (scale and round)*/, NULL /*row_heights_si*/, + large_bar_height = zint_out_large_bar_height(symbol, 0 /*si (scale and round)*/, NULL /*row_heights_si*/, NULL /*symbol_height_si*/); main_width = symbol->width; - if (is_composite(symbol->symbology)) { - while (!module_is_set(symbol, symbol->rows - 1, comp_xoffset)) { + if (z_is_composite(symbol->symbology)) { + while (!z_module_is_set(symbol, symbol->rows - 1, comp_xoffset)) { comp_xoffset++; } } - if (is_upcean(symbol->symbology)) { - upceanflag = out_process_upcean(symbol, comp_xoffset, &main_width, addon, &addon_len, &addon_gap); - } else if (is_composite(symbol->symbology)) { + if (z_is_upcean(symbol->symbology)) { + upceanflag = zint_out_process_upcean(symbol, comp_xoffset, &main_width, addon, &addon_len, &addon_gap); + } else if (z_is_composite(symbol->symbology)) { int x; - for (x = symbol->width - 1; x && !module_is_set(symbol, symbol->rows - 1, x); comp_roffset++, x--); + for (x = symbol->width - 1; x && !z_module_is_set(symbol, symbol->rows - 1, x); comp_roffset++, x--); main_width -= comp_xoffset + comp_roffset; } hide_text = !symbol->show_hrt || symbol->text_length == 0; - out_set_whitespace_offsets(symbol, hide_text, comp_xoffset, &xoffset, &yoffset, &roffset, &boffset, &qz_right, - 0 /*scaler*/, NULL, NULL, NULL, NULL, NULL); + zint_out_set_whitespace_offsets(symbol, hide_text, comp_xoffset, &xoffset, &yoffset, &roffset, &boffset, + &qz_right, 0 /*scaler*/, NULL, NULL, NULL, NULL, NULL); xoffset_comp = xoffset + comp_xoffset; @@ -528,7 +528,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ if (hide_text) { textoffset = guard_descent; } else { - textoffset = font_height + stripf(text_gap + antialias_fudge); + textoffset = font_height + z_stripf(text_gap + antialias_fudge); if (upceanflag) { if (textoffset < guard_descent) { textoffset = guard_descent; @@ -575,7 +575,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ const float hex_yposn = r * yposn_offset + hex_yradius + yoffset; const float xposn_offset = (odd_row ? hex_diameter : hex_radius) + xoffset; for (i = 0; i < symbol->width - odd_row; i++) { - if (module_is_set(symbol, r, i)) { + if (z_module_is_set(symbol, r, i)) { const float hex_xposn = i * hex_diameter + xposn_offset; if (!vector_add_hexagon(symbol, hex_xposn, hex_yposn, hex_diameter, &last_hexagon)) return ZINT_ERROR_MEMORY; @@ -586,7 +586,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ } else if (symbol->output_options & BARCODE_DOTTY_MODE) { for (r = 0; r < symbol->rows; r++) { for (i = 0; i < symbol->width; i++) { - if (module_is_set(symbol, r, i)) { + if (z_module_is_set(symbol, r, i)) { if (!vector_add_circle(symbol, i + dot_offset + xoffset, r + dot_offset + yoffset, symbol->dot_size, 0, 0, &last_circle)) return ZINT_ERROR_MEMORY; } @@ -599,14 +599,14 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ const float row_height = symbol->row_height[r]; for (i = 0; i < symbol->width; i += block_width) { - const int fill = module_colour_is_set(symbol, r, i); + const int fill = z_module_colour_is_set(symbol, r, i); for (block_width = 1; (i + block_width < symbol->width) - && module_colour_is_set(symbol, r, i + block_width) == fill; block_width++); + && z_module_colour_is_set(symbol, r, i + block_width) == fill; block_width++); if (fill) { /* a colour block */ if (!vector_add_rect(symbol, i + xoffset, yposn, block_width, row_height, &last_rect)) return ZINT_ERROR_MEMORY; - last_rect->colour = module_colour_is_set(symbol, r, i); + last_rect->colour = z_module_colour_is_set(symbol, r, i); } } yposn += row_height; @@ -619,9 +619,9 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ last_row_start = rect_count; for (i = 0; i < symbol->width; i += block_width) { - const int fill = module_is_set(symbol, r, i); + const int fill = z_module_is_set(symbol, r, i); for (block_width = 1; (i + block_width < symbol->width) - && module_is_set(symbol, r, i + block_width) == fill; block_width++); + && z_module_is_set(symbol, r, i + block_width) == fill; block_width++); if ((r == (symbol->rows - 1)) && (i > main_width) && (addon_latch == 0)) { addon_text_yposn = yposn + font_height - digit_ascender; @@ -662,9 +662,9 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ const float row_height = symbol->row_height[r] ? symbol->row_height[r] : large_bar_height; for (i = 0; i < symbol->width; i += block_width) { - const int fill = module_is_set(symbol, r, i); + const int fill = z_module_is_set(symbol, r, i); for (block_width = 1; (i + block_width < symbol->width) - && module_is_set(symbol, r, i + block_width) == fill; block_width++); + && z_module_is_set(symbol, r, i + block_width) == fill; block_width++); if (fill) { /* a bar */ if (!vector_add_rect(symbol, i + xoffset, yposn, block_width, row_height, &last_rect)) @@ -921,7 +921,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ } /* Separator binding for stacked barcodes */ - if ((symbol->output_options & BARCODE_BIND) && symbol->rows > 1 && is_bindable(symbol->symbology)) { + if ((symbol->output_options & BARCODE_BIND) && symbol->rows > 1 && z_is_bindable(symbol->symbology)) { float sep_xoffset = xoffset; float sep_width = symbol->width; float sep_height = 1.0f, sep_yoffset, sep_half_height; @@ -967,7 +967,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ /* Bind/box */ if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND | BARCODE_BIND_TOP))) { - const int horz_outside = is_fixed_ratio(symbol->symbology); + const int horz_outside = z_is_fixed_ratio(symbol->symbology); float ybind_top = yoffset - symbol->border_width; /* Following equivalent to yoffset + symbol->height + dot_overspill except for BARCODE_MAXICODE */ float ybind_bot = vector->height - textoffset - boffset; @@ -1027,13 +1027,13 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_ switch (file_type) { case OUT_EPS_FILE: - error_number = ps_plot(symbol); + error_number = zint_ps_plot(symbol); break; case OUT_SVG_FILE: - error_number = svg_plot(symbol); + error_number = zint_svg_plot(symbol); break; case OUT_EMF_FILE: - error_number = emf_plot(symbol, rotate_angle); + error_number = zint_emf_plot(symbol, rotate_angle); break; /* case OUT_BUFFER: No more work needed */ } diff --git a/frontend/tests/test_args.c b/frontend/tests/test_args.c index 26962edd..f6042d14 100644 --- a/frontend/tests/test_args.c +++ b/frontend/tests/test_args.c @@ -42,7 +42,7 @@ static int utf8_to_wchar(const char *str, wchar_t *out) { while (*str) { do { - decode_utf8(&state, &codepoint, *str++); + z_decode_utf8(&state, &codepoint, *str++); } while (*str && state != 0 && state != 12); if (state != 0) { return 0;