From 52c00e59ba894392d3a7a87cbc95930b9f3fd8ea Mon Sep 17 00:00:00 2001 From: gitlost Date: Sun, 27 Jun 2021 11:47:55 +0100 Subject: [PATCH] C25/DBAR: use new func gs1_check_digit() for common GS1 check digit calc CODE11/CODE39/EXCODE39/CODE93/PZN/CHANNEL/VIN/DBAR/UPCEAN: fuller error messages DATAMATRIX: look_ahead_test debug counts DBAR: consolidate option_2 cols_per_row CMakeLists.txt: restore -fno-var-tracking-assignments for gcc no DEBUG overall: suppress various warnings on various configs testcommon.c: clean-up --- CMakeLists.txt | 6 +- backend/2of5.c | 20 +- backend/code.c | 76 ++-- backend/dmatrix.c | 24 +- backend/gs1.c | 14 + backend/gs1.h | 1 + backend/library.c | 17 +- backend/output.h | 4 +- backend/rss.c | 171 ++++---- backend/tests/test_code.c | 9 +- backend/tests/test_code128.c | 2 +- backend/tests/test_composite.c | 28 +- backend/tests/test_gs1.c | 4 +- backend/tests/test_imail.c | 2 +- backend/tests/test_large.c | 8 +- backend/tests/test_library.c | 2 +- backend/tests/test_pcx.c | 2 +- backend/tests/test_pdf417.c | 2 +- backend/tests/test_qr.c | 2 +- backend/tests/test_raster.c | 14 +- backend/tests/test_rss.c | 59 +-- backend/tests/test_svg.c | 2 +- backend/tests/test_tif.c | 2 +- backend/tests/test_vector.c | 12 +- backend/tests/testcommon.c | 709 +++++++++++++++++++-------------- backend/tests/testcommon.h | 20 +- backend/upcean.c | 224 ++++------- docs/manual.txt | 4 +- frontend/main.c | 10 +- frontend/tests/test_args.c | 4 +- 30 files changed, 739 insertions(+), 715 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd08dcc2..835759e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,12 +74,16 @@ if(ZINT_SANITIZE AND NOT MSVC) COMPILE_DEFINITIONS ${sanitizer_flag} LINK_OPTIONS ${sanitizer_flag} ) - message (STATUS "Support for ${sanitizer_flag} available ... ${RESULT_VAR}") + message(STATUS "Support for ${sanitizer_flag} available ... ${RESULT_VAR}") if(RESULT_VAR) set(SANITIZER_FLAGS ${SANITIZER_FLAGS} ${sanitizer_flag}) endif() endforeach() message(STATUS "Sanitizer flags: ${SANITIZER_FLAGS}") + if(NOT ZINT_DEBUG AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") + # Gives warning on MainWindow::setupUI() and retries (& takes forever) if var-tracking-assignments enabled + add_compile_options(-fno-var-tracking-assignments) + endif() endif() if(APPLE) diff --git a/backend/2of5.c b/backend/2of5.c index 860b0ba8..4c8d5d60 100644 --- a/backend/2of5.c +++ b/backend/2of5.c @@ -33,6 +33,8 @@ #include #include "common.h" +#include "gs1.h" + #ifdef _MSC_VER #define inline _inline #endif @@ -62,18 +64,6 @@ static inline char check_digit(const unsigned int count) { return itoc((10 - (count % 10)) % 10); } -/* Calculate the check digit - the same method used for EAN-13 (GS1 General Specifications 7.9.1) */ -static unsigned int gs1_checksum(const unsigned char source[], const int length) { - int i; - unsigned int count = 0; - int factor = length & 1 ? 3 : 1; - for (i = 0; i < length; i++) { - count += factor * ctoi(source[i]); - factor = factor == 1 ? 3 : 1; - } - return count; -} - /* Common to Standard (Matrix), Industrial, IATA, and Data Logic */ static int c25_common(struct zint_symbol *symbol, const unsigned char source[], int length, const int max, const char *table[10], const char *start_stop[2], const int error_base) { @@ -97,7 +87,7 @@ static int c25_common(struct zint_symbol *symbol, const unsigned char source[], if (have_checkdigit) { /* Add standard GS1 check digit */ - temp[length] = check_digit(gs1_checksum(source, length)); + temp[length] = gs1_check_digit(source, length); temp[++length] = '\0'; } @@ -173,7 +163,7 @@ static int c25inter_common(struct zint_symbol *symbol, unsigned char source[], i if (have_checkdigit) { /* Add standard GS1 check digit */ - temp[length] = check_digit(gs1_checksum(temp, length)); + temp[length] = gs1_check_digit(temp, length); temp[++length] = '\0'; } @@ -258,7 +248,7 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt ustrcpy(localstr + zeroes, source); /* Calculate the check digit - the same method used for EAN-13 */ - localstr[13] = check_digit(gs1_checksum(localstr, 13)); + localstr[13] = gs1_check_digit(localstr, 13); localstr[14] = '\0'; error_number = c25inter_common(symbol, localstr, 14, 1 /*dont_set_height*/); ustrcpy(symbol->text, localstr); diff --git a/backend/code.c b/backend/code.c index 3f764f89..d84d6d79 100644 --- a/backend/code.c +++ b/backend/code.c @@ -111,17 +111,17 @@ INTERNAL int code_11(struct zint_symbol *symbol, unsigned char source[], int len assert(length > 0); if (length > 121) { - strcpy(symbol->errtxt, "320: Input too long"); + strcpy(symbol->errtxt, "320: Input too long (121 character maximum)"); return ZINT_ERROR_TOO_LONG; } error_number = is_sane(SODIUM, source, length); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "321: Invalid characters in data"); + sprintf(symbol->errtxt, "321: Invalid characters in data (\"%s\" only)", SODIUM); return error_number; } if (symbol->option_2 < 0 || symbol->option_2 > 2) { - strcpy(symbol->errtxt, "339: Invalid check digit version"); + strcpy(symbol->errtxt, "339: Invalid check digit version (1, 2 only)"); return ZINT_ERROR_INVALID_OPTION; } if (symbol->option_2 == 2) { @@ -230,20 +230,21 @@ INTERNAL int c39(struct zint_symbol *symbol, unsigned char source[], int length) } if ((symbol->symbology == BARCODE_LOGMARS) && (length > 30)) { /* MIL-STD-1189 Rev. B Section 5.2.6.2 */ - strcpy(symbol->errtxt, "322: Input too long"); + strcpy(symbol->errtxt, "322: Input too long (30 character maximum)"); return ZINT_ERROR_TOO_LONG; /* Prevent encoded_data out-of-bounds >= 143 for BARCODE_HIBC_39 due to wider 'wide' bars */ } else if ((symbol->symbology == BARCODE_HIBC_39) && (length > 68)) { - strcpy(symbol->errtxt, "319: Input too long"); /* Note use 319 (2of5 range) as 340 taken by CODE128 */ + /* Note use 319 (2of5 range) as 340 taken by CODE128 */ + strcpy(symbol->errtxt, "319: Input too long (68 character maximum)"); return ZINT_ERROR_TOO_LONG; } else if (length > 85) { - strcpy(symbol->errtxt, "323: Input too long"); + strcpy(symbol->errtxt, "323: Input too long (85 character maximum)"); return ZINT_ERROR_TOO_LONG; } to_upper(source); error_number = is_sane(SILVER, source, length); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "324: Invalid characters in data"); + strcpy(symbol->errtxt, "324: Invalid characters in data (alphanumerics and \"-. $/+%\" only)"); return error_number; } @@ -356,12 +357,12 @@ INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], i char localstr[11]; if (length > 7) { - strcpy(symbol->errtxt, "325: Input wrong length"); + strcpy(symbol->errtxt, "325: Input wrong length (7 character maximum)"); return ZINT_ERROR_TOO_LONG; } error_number = is_sane(NEON, source, length); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "326: Invalid characters in data"); + strcpy(symbol->errtxt, "326: Invalid characters in data (digits only)"); return error_number; } @@ -383,7 +384,7 @@ INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], i } if (check_digit == 10) { - strcpy(symbol->errtxt, "327: Invalid PZN Data"); + strcpy(symbol->errtxt, "327: Invalid PZN, check digit is '10'"); return ZINT_ERROR_INVALID_DATA; } localstr[8] = itoc(check_digit); @@ -417,7 +418,7 @@ INTERNAL int ec39(struct zint_symbol *symbol, unsigned char source[], int length int error_number; if (length > 85) { - strcpy(symbol->errtxt, "328: Input too long"); + strcpy(symbol->errtxt, "328: Input too long (85 character maximum)"); return ZINT_ERROR_TOO_LONG; } @@ -425,7 +426,7 @@ INTERNAL int ec39(struct zint_symbol *symbol, unsigned char source[], int length for (i = 0; i < length; i++) { if (source[i] > 127) { /* Cannot encode extended ASCII */ - strcpy(symbol->errtxt, "329: Invalid characters in input data"); + strcpy(symbol->errtxt, "329: Invalid characters in data, extended ASCII not allowed"); return ZINT_ERROR_INVALID_DATA; } ustrcat(buffer, EC39Ctrl[source[i]]); @@ -458,7 +459,7 @@ INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(buffer, ""); if (length > 107) { - strcpy(symbol->errtxt, "330: Input too long"); + strcpy(symbol->errtxt, "330: Input too long (107 character maximum)"); return ZINT_ERROR_TOO_LONG; } @@ -466,7 +467,7 @@ INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length) for (i = 0; i < length; i++) { if (source[i] > 127) { /* Cannot encode extended ASCII */ - strcpy(symbol->errtxt, "331: Invalid characters in input data"); + strcpy(symbol->errtxt, "331: Invalid characters in data, extended ASCII not allowed"); return ZINT_ERROR_INVALID_DATA; } strcat(buffer, C93Ctrl[source[i]]); @@ -476,7 +477,7 @@ INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length) /* Now we can check the true length of the barcode */ h = (int) strlen(buffer); if (h > 107) { - strcpy(symbol->errtxt, "332: Input too long"); + strcpy(symbol->errtxt, "332: Input too long"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } @@ -674,21 +675,22 @@ nb0: if (++B[0] <= bmax[0]) goto lb0; /* Channel Code - According to ANSI/AIM BC12-1998 */ INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) { + static int max_ranges[] = { -1, -1, -1, 26, 292, 3493, 44072, 576688, 7742862 }; int S[8] = {0}, B[8] = {0}; long target_value = 0; char pattern[30]; int channels, i; - int error_number, range = 0, zeroes; + int error_number, zeroes; char hrt[9]; float height; if (length > 7) { - strcpy(symbol->errtxt, "333: Input too long"); + strcpy(symbol->errtxt, "333: Input too long (7 character maximum)"); return ZINT_ERROR_TOO_LONG; } error_number = is_sane(NEON, source, length); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "334: Invalid characters in data"); + strcpy(symbol->errtxt, "334: Invalid characters in data (digits only)"); return error_number; } @@ -721,34 +723,8 @@ INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], in channels = 3; } - switch (channels) { - case 3: if (target_value > 26) { - range = 1; - } - break; - case 4: if (target_value > 292) { - range = 1; - } - break; - case 5: if (target_value > 3493) { - range = 1; - } - break; - case 6: if (target_value > 44072) { - range = 1; - } - break; - case 7: if (target_value > 576688) { - range = 1; - } - break; - case 8: if (target_value > 7742862) { - range = 1; - } - break; - } - if (range) { - strcpy(symbol->errtxt, "335: Value out of range"); + if (target_value > max_ranges[channels]) { + sprintf(symbol->errtxt, "335: Value out of range (0 to %d) for %d channels", max_ranges[channels], channels); return ZINT_ERROR_INVALID_DATA; } @@ -804,13 +780,13 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length) // Check length if (length != 17) { - strcpy(symbol->errtxt, "336: Input wrong length, 17 characters required"); + strcpy(symbol->errtxt, "336: Input wrong length (17 characters required)"); return ZINT_ERROR_TOO_LONG; } // Check input characters, I, O and Q are not allowed if (is_sane(ARSENIC, source, length) == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "337: Invalid characters in input data"); + sprintf(symbol->errtxt, "337: Invalid characters in data (\"%s\" only)", ARSENIC); return ZINT_ERROR_INVALID_DATA; } @@ -852,8 +828,8 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length) } if (input_check != output_check) { - strcpy(symbol->errtxt, "338: Invalid check digit in input data"); - return ZINT_ERROR_INVALID_DATA; + sprintf(symbol->errtxt, "338: Invalid check digit '%c', expecting '%c'", input_check, output_check); + return ZINT_ERROR_INVALID_CHECK; } } diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 413913fa..c2f5880f 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -269,7 +269,7 @@ static int p_r_6_2_1(const unsigned char inputData[], const int position, const /* 'look ahead test' from Annex P */ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, const int position, - const int current_mode, const int gs1) { + const int current_mode, const int gs1, const int debug) { float ascii_count, c40_count, text_count, x12_count, edf_count, b256_count; int ascii_rnded, c40_rnded, text_rnded, x12_rnded, edf_rnded, b256_rnded; float cnt_1; @@ -379,6 +379,12 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, text_count = stripf(text_count); x12_count = stripf(x12_count); c40_count = stripf(c40_count); + if (debug) { + printf("\n(%d, %d, %d): ascii_count %.8g, b256_count %.8g, edf_count %.8g, text_count %.8g" + ", x12_count %.8g, c40_count %.8g", + current_mode, position, sp, ascii_count, b256_count, edf_count, text_count, + x12_count, c40_count); + } cnt_1 = ascii_count + 1.0f; if (cnt_1 <= b256_count && cnt_1 <= edf_count && cnt_1 <= text_count && cnt_1 <= x12_count @@ -428,6 +434,12 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, text_rnded = (int) ceilf(stripf(text_count)); x12_rnded = (int) ceilf(stripf(x12_count)); c40_rnded = (int) ceilf(stripf(c40_count)); + if (debug) { + printf("\nEOD(%d, %d): ascii_rnded %d, b256_rnded %d, edf_rnded %d, text_rnded %d, x12_rnded %d (%g)" + ", c40_rnded %d (%g)\n", + current_mode, position, ascii_rnded, b256_rnded, edf_rnded, text_rnded, x12_rnded, x12_count, + c40_rnded, c40_count); + } if (ascii_rnded <= b256_rnded && ascii_rnded <= edf_rnded && ascii_rnded <= text_rnded && ascii_rnded <= x12_rnded && ascii_rnded <= c40_rnded) { @@ -695,7 +707,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], tp++; sp += 2; } else { - next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1, debug); if (next_mode != DM_ASCII) { switch (next_mode) { @@ -753,7 +765,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], next_mode = current_mode; if (process_p == 0) { - next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1, debug); } if (next_mode != current_mode) { @@ -809,7 +821,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], next_mode = DM_X12; if (process_p == 0) { - next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1, debug); } if (next_mode != DM_X12) { @@ -844,7 +856,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], if (process_p == 3) { /* Note different then spec Step (f)(1), which suggests checking when 0, but this seems to work better in many cases. */ - next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1, debug); } if (next_mode != DM_EDIFACT) { @@ -868,7 +880,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], /* step (g) Base 256 encodation */ } else if (current_mode == DM_BASE256) { - next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1, debug); if (next_mode == DM_BASE256) { target[tp] = source[sp]; diff --git a/backend/gs1.c b/backend/gs1.c index 1fadecdf..5e98b823 100644 --- a/backend/gs1.c +++ b/backend/gs1.c @@ -1386,3 +1386,17 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[] /* the character '[' in the reduced string refers to the FNC1 character */ return error_value; } + +/* 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) { + int i; + int count = 0; + int factor = length & 1 ? 3 : 1; + + for (i = 0; i < length; i++) { + count += factor * ctoi(source[i]); + factor = factor == 1 ? 3 : 1; + } + + return itoc((10 - (count % 10)) % 10); +} diff --git a/backend/gs1.h b/backend/gs1.h index db96f722..d7f2c658 100644 --- a/backend/gs1.h +++ b/backend/gs1.h @@ -39,6 +39,7 @@ extern "C" { INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const int src_len, unsigned char reduced[]); +INTERNAL char gs1_check_digit(const unsigned char source[], const int src_len); #ifdef __cplusplus } diff --git a/backend/library.c b/backend/library.c index e356a099..a39bf5fa 100644 --- a/backend/library.c +++ b/backend/library.c @@ -1286,33 +1286,18 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) { to_upper((unsigned char *) output); if (!(strcmp(output, "PNG"))) { - if (symbol->scale < 1.0f) { - symbol->text[0] = '\0'; - } error_number = plot_raster(symbol, rotate_angle, OUT_PNG_FILE); } else if (!(strcmp(output, "BMP"))) { - if (symbol->scale < 1.0f) { - symbol->text[0] = '\0'; - } error_number = plot_raster(symbol, rotate_angle, OUT_BMP_FILE); } else if (!(strcmp(output, "PCX"))) { - if (symbol->scale < 1.0f) { - symbol->text[0] = '\0'; - } error_number = plot_raster(symbol, rotate_angle, OUT_PCX_FILE); } else if (!(strcmp(output, "GIF"))) { - if (symbol->scale < 1.0f) { - symbol->text[0] = '\0'; - } error_number = plot_raster(symbol, rotate_angle, OUT_GIF_FILE); } else if (!(strcmp(output, "TIF"))) { - if (symbol->scale < 1.0f) { - symbol->text[0] = '\0'; - } error_number = plot_raster(symbol, rotate_angle, OUT_TIF_FILE); } else if (!(strcmp(output, "TXT"))) { @@ -1522,7 +1507,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) { if (file_opened) { fclose(file); } - ret = ZBarcode_Encode(symbol, buffer, nRead); + ret = ZBarcode_Encode(symbol, buffer, (int) nRead); free(buffer); return ret; } diff --git a/backend/output.h b/backend/output.h index 25d66e10..8a626b13 100644 --- a/backend/output.h +++ b/backend/output.h @@ -44,8 +44,8 @@ INTERNAL int output_process_upcean(struct zint_symbol *symbol, int *p_main_width unsigned char addon[6], int *p_addon_gap); INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si); INTERNAL void output_upcean_split_text(int upceanflag, unsigned char text[], - unsigned char textpart1[], unsigned char textpart2[], unsigned char textpart3[], - unsigned char textpart4[]); + unsigned char textpart1[5], unsigned char textpart2[7], unsigned char textpart3[7], + unsigned char textpart4[2]); #ifdef __cplusplus } diff --git a/backend/rss.c b/backend/rss.c index b25dc316..8ea2cb4a 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -31,7 +31,7 @@ */ /* vim: set ts=4 sw=4 et : */ -/* The functions "combins" and "getRSSwidths" are copyright BSI and are +/* The functions "rss_combins" and "getRSSwidths" are copyright BSI and are released with permission under the following terms: "Copyright subsists in all BSI publications. BSI also holds the copyright, in the @@ -73,11 +73,11 @@ #include "gs1.h" #include "general_field.h" -/********************************************************************** - * combins(n,r): returns the number of Combinations of r selected from n: +/**************************************************************************** + * rss_combins(n,r): returns the number of Combinations of r selected from n: * Combinations = n! / ((n - r)! * r!) - **********************************************************************/ -static int combins(const int n, const int r) { + ****************************************************************************/ +static int rss_combins(const int n, const int r) { int i, j; int maxDenom, minDenom; int val; @@ -128,11 +128,11 @@ static void getRSSwidths(int widths[], int val, int n, const int elements, const ; elmWidth++, narrowMask &= ~(1 << bar)) { /* get all combinations */ - subVal = combins(n - elmWidth - 1, elements - bar - 2); + subVal = rss_combins(n - elmWidth - 1, elements - bar - 2); /* less combinations with no single-module element */ - if ((!noNarrow) && (!narrowMask) && - (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) { - subVal -= combins(n - elmWidth - (elements - bar), elements - bar - 2); + if ((!noNarrow) && (!narrowMask) + && (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) { + subVal -= rss_combins(n - elmWidth - (elements - bar), elements - bar - 2); } /* less combinations with elements > maxVal */ if (elements - bar - 1 > 1) { @@ -140,7 +140,7 @@ static void getRSSwidths(int widths[], int val, int n, const int elements, const for (mxwElement = n - elmWidth - (elements - bar - 2); mxwElement > maxWidth; mxwElement--) { - lessVal += combins(n - elmWidth - mxwElement - 1, elements - bar - 3); + lessVal += rss_combins(n - elmWidth - mxwElement - 1, elements - bar - 3); } subVal -= lessVal * (elements - 1 - bar); } else if (n - elmWidth > maxWidth) { @@ -157,24 +157,8 @@ static void getRSSwidths(int widths[], int val, int n, const int elements, const return; } -/* Calculate check digit from Annex A */ -static int calc_check_digit(const unsigned char *src) { - int i, check_digit; - int count = 0; - - for (i = 0; i < 13; i++) { - count += (i & 1) ? ctoi(src[i]) : 3 * ctoi(src[i]); - } - check_digit = 10 - (count % 10); - if (check_digit == 10) { - check_digit = 0; - } - - return check_digit; -} - /* Set GTIN-14 human readable text */ -static void set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *source, const int src_len) { +static void rss_set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *source, const int src_len) { int i; unsigned char hrt[15]; @@ -186,7 +170,7 @@ static void set_gtin14_hrt(struct zint_symbol *symbol, const unsigned char *sour hrt[12 - i] = source[src_len - i - 1]; } - hrt[13] = itoc(calc_check_digit(hrt)); + hrt[13] = gs1_check_digit(hrt, 13); hrt[14] = '\0'; ustrcat(symbol->text, hrt); @@ -319,18 +303,19 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr separator_row = 0; if (src_len > 14) { /* Allow check digit to be specified (will be verified and ignored) */ - strcpy(symbol->errtxt, "380: Input too long"); + strcpy(symbol->errtxt, "380: Input too long (14 character maximum)"); return ZINT_ERROR_TOO_LONG; } error_number = is_sane(NEON, source, src_len); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "381: Invalid characters in data"); + strcpy(symbol->errtxt, "381: Invalid characters in data (digits only)"); return error_number; } if (src_len == 14) { /* Verify check digit */ - if (calc_check_digit(source) != ctoi(source[13])) { - strcpy(symbol->errtxt, "388: Invalid check digit"); + if (gs1_check_digit(source, 13) != source[13]) { + sprintf(symbol->errtxt, "388: Invalid check digit '%c', expecting '%c'", + source[13], gs1_check_digit(source, 13)); return ZINT_ERROR_INVALID_CHECK; } src_len--; /* Ignore */ @@ -422,7 +407,6 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr v_odd[2] = (data_character[2] - g_sum_table[data_group[2]]) / t_table[data_group[2]]; v_even[2] = (data_character[2] - g_sum_table[data_group[2]]) % t_table[data_group[2]]; - /* Use RSS subset width algorithm */ for (i = 0; i < 4; i++) { if ((i == 0) || (i == 2)) { @@ -450,7 +434,6 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr } } - checksum = 0; /* Calculate the checksum */ for (i = 0; i < 8; i++) { @@ -508,7 +491,7 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr symbol->rows = symbol->rows + 1; /* Set human readable text */ - set_gtin14_hrt(symbol, source, src_len); + rss_set_gtin14_hrt(symbol, source, src_len); #ifdef COMPLIANT_HEIGHTS /* Minimum height is 13X for truncated symbol ISO/IEC 24724:2011 5.3.1 @@ -658,18 +641,19 @@ INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], i separator_row = 0; if (src_len > 14) { /* Allow check digit to be specified (will be verified and ignored) */ - strcpy(symbol->errtxt, "382: Input too long"); + strcpy(symbol->errtxt, "382: Input too long (14 character maximum)"); return ZINT_ERROR_TOO_LONG; } error_number = is_sane(NEON, source, src_len); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "383: Invalid characters in data"); + strcpy(symbol->errtxt, "383: Invalid characters in data (digits only)"); return error_number; } if (src_len == 14) { /* Verify check digit */ - if (calc_check_digit(source) != ctoi(source[13])) { - strcpy(symbol->errtxt, "389: Invalid check digit"); + if (gs1_check_digit(source, 13) != source[13]) { + sprintf(symbol->errtxt, "389: Invalid check digit '%c', expecting '%c'", + source[13], gs1_check_digit(source, 13)); return ZINT_ERROR_INVALID_CHECK; } src_len--; /* Ignore */ @@ -677,7 +661,7 @@ INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], i if (src_len == 13) { if ((source[0] != '0') && (source[0] != '1')) { - strcpy(symbol->errtxt, "384: Input out of range"); + strcpy(symbol->errtxt, "384: Input out of range (0 to 1999999999999)"); return ZINT_ERROR_INVALID_DATA; } } @@ -810,7 +794,7 @@ INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], i } /* Set human readable text */ - set_gtin14_hrt(symbol, source, src_len); + rss_set_gtin14_hrt(symbol, source, src_len); /* ISO/IEC 24724:2011 6.2 10X minimum height, use as default also */ if (symbol->symbology == BARCODE_DBAR_LTD_CC) { @@ -846,11 +830,11 @@ INTERNAL int rss_date(const unsigned char source[], const int src_posn) { } /* Handles all data encodation from section 7.2.5 of ISO/IEC 24724 */ -static int rss_binary_string(struct zint_symbol *symbol, const unsigned char source[], char binary_string[], - int *p_bp) { +static int rssexp_binary_string(struct zint_symbol *symbol, const unsigned char source[], char binary_string[], + int cols_per_row, int *p_bp) { int encoding_method, i, j, read_posn, debug = (symbol->debug & ZINT_DEBUG_PRINT), mode = NUMERIC; char last_digit = '\0'; - int symbol_characters, characters_per_row; + int symbol_characters, characters_per_row = cols_per_row * 2; int length = (int) ustrlen(source); #ifndef _MSC_VER char general_field[length + 1]; @@ -897,9 +881,9 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou encoding_method = 7; } - } else if ((length == 34) && (source[26] == '1') && - (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') && - rss_date(source, 28) >= 0) { + } else if ((length == 34) && (source[26] == '1') + && (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') + && rss_date(source, 28) >= 0) { /* (01), (310x) and (11) - metric weight and production date */ /* (01), (310x) and (13) - metric weight and packaging date */ @@ -928,9 +912,9 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou encoding_method = 8; } - } else if ((length == 34) && (source[26] == '1') && - (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') && - rss_date(source, 28) >= 0) { + } else if ((length == 34) && (source[26] == '1') + && (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') + && rss_date(source, 28) >= 0) { /* (01), (320x) and (11) - English weight and production date */ /* (01), (320x) and (13) - English weight and packaging date */ @@ -988,7 +972,7 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou if ((source[i] < '0') || (source[i] > '9')) { if (source[i] != '[') { /* Something is wrong */ - strcpy(symbol->errtxt, "385: Invalid characters in input data"); + strcpy(symbol->errtxt, "385: Invalid characters in input data"); // TODO: Better error message return ZINT_ERROR_INVALID_DATA; } } @@ -1089,7 +1073,7 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou if (!general_field_encode(general_field, j, &mode, &last_digit, binary_string, &bp)) { /* Invalid characters in input data */ - strcpy(symbol->errtxt, "386: Invalid characters in input data"); + strcpy(symbol->errtxt, "386: Invalid characters in input data"); // TODO: Better error message return ZINT_ERROR_INVALID_DATA; } } @@ -1102,16 +1086,8 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou } symbol_characters = ((bp + remainder) / 12) + 1; - if ((symbol->symbology == BARCODE_DBAR_EXPSTK) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) { - characters_per_row = symbol->option_2 * 2; - - if ((characters_per_row < 2) || (characters_per_row > 20)) { - characters_per_row = 4; - } - - if ((symbol_characters % characters_per_row) == 1) { - symbol_characters++; - } + if (characters_per_row && (symbol_characters % characters_per_row) == 1) { // DBAR_EXPSTK + symbol_characters++; } if (symbol_characters < 4) { @@ -1139,16 +1115,8 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou } symbol_characters = ((bp + remainder) / 12) + 1; - if ((symbol->symbology == BARCODE_DBAR_EXPSTK) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) { - characters_per_row = symbol->option_2 * 2; - - if ((characters_per_row < 2) || (characters_per_row > 20)) { - characters_per_row = 4; - } - - if ((symbol_characters % characters_per_row) == 1) { - symbol_characters++; - } + if (characters_per_row && (symbol_characters % characters_per_row) == 1) { // DBAR_EXPSTK + symbol_characters++; } if (symbol_characters < 4) { @@ -1161,7 +1129,7 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou } if (bp > 252) { /* 252 = (21 * 12) */ - strcpy(symbol->errtxt, "387: Input too long"); + strcpy(symbol->errtxt, "387: Input too long"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } @@ -1282,6 +1250,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], unsigned int bin_len = 13 * src_len + 200 + 1; int widths[4]; int bp = 0; + int cols_per_row = 0; int stack_rows = 1; #ifndef _MSC_VER unsigned char reduced[src_len + 1]; @@ -1297,6 +1266,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], if (error_number >= ZINT_ERROR) { return error_number; } + warn_number = error_number; if (symbol->debug & ZINT_DEBUG_PRINT) { printf("Reduced (%d): %s\n", (int) ustrlen(reduced), reduced); @@ -1315,9 +1285,22 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], binary_string[bp++] = '0'; } - i = rss_binary_string(symbol, reduced, binary_string, &bp); - if (i != 0) { - return i; + if ((symbol->symbology == BARCODE_DBAR_EXPSTK) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) { + cols_per_row = 2; /* Default */ + if (symbol->option_2 >= 1 && symbol->option_2 <= 11) { + cols_per_row = symbol->option_2; + if (cc_rows && (cols_per_row == 1)) { + /* "There shall be a minimum of four symbol characters in the + first row of an RSS Expanded Stacked symbol when it is the linear + component of an EAN.UCC Composite symbol." */ + cols_per_row = 2; + } + } + } + + error_number = rssexp_binary_string(symbol, reduced, binary_string, cols_per_row, &bp); + if (error_number != 0) { + return error_number; } data_chars = bp / 12; @@ -1479,18 +1462,8 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], * Patch by Daniel Frede */ - if ((symbol->option_2 < 1) || (symbol->option_2 > 11)) { - symbol->option_2 = 2; - } - if (cc_rows && (symbol->option_2 == 1)) { - /* "There shall be a minimum of four symbol characters in the - first row of an RSS Expanded Stacked symbol when it is the linear - component of an EAN.UCC Composite symbol." */ - symbol->option_2 = 2; - } - - stack_rows = codeblocks / symbol->option_2; - if (codeblocks % symbol->option_2 > 0) { + stack_rows = codeblocks / cols_per_row; + if (codeblocks % cols_per_row > 0) { stack_rows++; } @@ -1502,10 +1475,10 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], int num_columns; /* Number of columns in current row */ - if (current_row * symbol->option_2 > codeblocks) { + if (current_row * cols_per_row > codeblocks) { num_columns = codeblocks - current_block; } else { - num_columns = symbol->option_2; + num_columns = cols_per_row; } /* Row Start */ @@ -1515,8 +1488,8 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], /* If last row and is partial and even-numbered, and have even columns (segment pairs), * and odd number of finders (== odd number of columns) */ - if ((current_row == stack_rows) && (num_columns != symbol->option_2) && - !(current_row & 1) && !(symbol->option_2 & 1) && (num_columns & 1)) { + if ((current_row == stack_rows) && (num_columns != cols_per_row) && !(current_row & 1) + && !(cols_per_row & 1) && (num_columns & 1)) { /* Special case bottom row */ special_case_row = 1; sub_elements[0] = 2; /* Extra space (latch set below) */ @@ -1524,7 +1497,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], /* If odd number of columns or current row odd-numbered or special case last row then left-to-right, * else right-to-left */ - if ((symbol->option_2 & 1) || (current_row & 1) || special_case_row) { + if ((cols_per_row & 1) || (current_row & 1) || special_case_row) { left_to_right = 1; } else { left_to_right = 0; @@ -1533,7 +1506,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], if (symbol->debug & ZINT_DEBUG_PRINT) { if (current_row == stack_rows) { printf("Last row: number of columns: %d / %d, left to right: %d, special case: %d\n", - num_columns, symbol->option_2, left_to_right, special_case_row); + num_columns, cols_per_row, left_to_right, special_case_row); } } @@ -1553,7 +1526,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], } reader++; current_block++; - } while ((reader < symbol->option_2) && (current_block < codeblocks)); + } while ((reader < cols_per_row) && (current_block < codeblocks)); /* Row Stop */ sub_elements[elements_in_sub] = 1; // right guard @@ -1574,7 +1547,7 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], int odd_last_row = (current_row == stack_rows) && (data_chars % 2 == 0); /* middle separator pattern (above current row) */ - for (j = 5; j < (49 * symbol->option_2); j += 2) { + for (j = 5; j < (49 * cols_per_row); j += 2) { set_module(symbol, symbol->rows - 2, j); } symbol->row_height[symbol->rows - 2] = 1; @@ -1609,7 +1582,11 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[], symbol->height = symbol->height ? 34.0f : 34.0f * stack_rows; /* Pass back min row or default height */ } else { #ifdef COMPLIANT_HEIGHTS - warn_number = set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/); + if (warn_number) { + (void) set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/); + } else { + warn_number = set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/); + } #else (void) set_height(symbol, 0.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/); #endif diff --git a/backend/tests/test_code.c b/backend/tests/test_code.c index b256e2d7..67ef34d3 100644 --- a/backend/tests/test_code.c +++ b/backend/tests/test_code.c @@ -205,11 +205,12 @@ static void test_input(int index, int debug) { /* 20*/ { BARCODE_PZN, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 21*/ { BARCODE_PZN, -1, "1000006", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // Check digit == 10 so can't be used /* 22*/ { BARCODE_VIN, -1, "5GZCZ43D13S812715", -1, 0, 1, 246 }, - /* 23*/ { BARCODE_VIN, -1, "5GZCZ43D23S812715", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // North American with invalid check character + /* 23*/ { BARCODE_VIN, -1, "5GZCZ43D23S812715", -1, ZINT_ERROR_INVALID_CHECK, -1, -1 }, // North American with invalid check character /* 24*/ { BARCODE_VIN, -1, "WP0ZZZ99ZTS392124", -1, 0, 1, 246 }, // Not North American so no check - /* 25*/ { BARCODE_HIBC_39, -1, "a", -1, 0, 1, 79 }, // Converts to upper - /* 26*/ { BARCODE_HIBC_39, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 27*/ { BARCODE_HIBC_39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 25*/ { BARCODE_VIN, -1, "WPOZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // O not allowed + /* 26*/ { BARCODE_HIBC_39, -1, "a", -1, 0, 1, 79 }, // Converts to upper + /* 27*/ { BARCODE_HIBC_39, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 28*/ { BARCODE_HIBC_39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 }, }; int data_size = ARRAY_SIZE(data); int i, length, ret; diff --git a/backend/tests/test_code128.c b/backend/tests/test_code128.c index bbb2ad0b..7b5e43e1 100644 --- a/backend/tests/test_code128.c +++ b/backend/tests/test_code128.c @@ -153,7 +153,7 @@ static void test_hrt_cpy_iso8859_1(int index, int debug) { } assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); assert_equal(ret, (int) ustrlen(symbol.text), "i:%d ret %d != strlen %d\n", i, ret, (int) ustrlen(symbol.text)); - assert_nonzero(testUtilIsValidUTF8(symbol.text, ustrlen(symbol.text)), "i:%d testUtilIsValidUTF8(%s) != 1\n", i, symbol.text); + assert_nonzero(testUtilIsValidUTF8(symbol.text, (int) ustrlen(symbol.text)), "i:%d testUtilIsValidUTF8(%s) != 1\n", i, symbol.text); assert_zero(strcmp((char *) symbol.text, data[i].expected), "i:%d symbol.text (%s) != expected (%s)\n", i, symbol.text, data[i].expected); } diff --git a/backend/tests/test_composite.c b/backend/tests/test_composite.c index 46422c4e..c44119f9 100644 --- a/backend/tests/test_composite.c +++ b/backend/tests/test_composite.c @@ -89,7 +89,7 @@ static void test_eanx_leading_zeroes(int index, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -109,8 +109,8 @@ static void test_helper_generate(const struct zint_symbol *symbol, int ret, int char esc_data[1024]; char esc_composite[4096]; - testUtilEscape(data, strlen(data), esc_data, sizeof(esc_data)); - testUtilEscape(composite, strlen(composite), esc_composite, sizeof(esc_composite)); + testUtilEscape(data, (int) strlen(data), esc_data, sizeof(esc_data)); + testUtilEscape(composite, (int) strlen(composite), esc_composite, sizeof(esc_composite)); if (ret == 0) { if (bwipp_cmp == -1) { @@ -1245,7 +1245,7 @@ static void test_examples(int index, int generate, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -1409,7 +1409,7 @@ static void test_odd_numbered_numeric(int index, int generate, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -1537,7 +1537,7 @@ static void test_ean128_cc_shift(int index, int generate, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -1617,7 +1617,7 @@ static void test_ean128_cc_width(int index, int generate, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2083,7 +2083,7 @@ static void test_encodation_0(int index, int generate, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2220,7 +2220,7 @@ static void test_encodation_10(int index, int generate, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2601,7 +2601,7 @@ static void test_encodation_11(int index, int generate, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2753,7 +2753,7 @@ static void test_addongap(int index, int generate, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(composite); + composite_length = (int) strlen(composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2843,7 +2843,7 @@ static void test_gs1parens(int index, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2894,7 +2894,7 @@ static void test_fuzz(int index, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); @@ -2966,7 +2966,7 @@ static void test_perf(int index, int debug) { assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length); strcpy(symbol->primary, data[i].data); - composite_length = strlen(data[i].composite); + composite_length = (int) strlen(data[i].composite); start = clock(); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); diff --git a/backend/tests/test_gs1.c b/backend/tests/test_gs1.c index 2f84fd08..038b324a 100644 --- a/backend/tests/test_gs1.c +++ b/backend/tests/test_gs1.c @@ -1325,7 +1325,7 @@ static void test_gs1_verify(int index, int debug) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - length = strlen(data[i].data); + length = (int) strlen(data[i].data); ret = gs1_verify(symbol, (unsigned char *) data[i].data, length, (unsigned char *) reduced); 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); @@ -1730,7 +1730,7 @@ static void test_gs1_lint(int index, int debug) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - length = strlen(data[i].data); + length = (int) strlen(data[i].data); ret = gs1_verify(symbol, (unsigned char *) data[i].data, length, (unsigned char *) reduced); 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_imail.c b/backend/tests/test_imail.c index 2d5f60f5..52e5b636 100644 --- a/backend/tests/test_imail.c +++ b/backend/tests/test_imail.c @@ -109,7 +109,7 @@ static void test_csv(int index, int debug) { symbol->symbology = BARCODE_USPS_IMAIL; symbol->debug |= debug; - ret = ZBarcode_Encode(symbol, (unsigned char *) data, strlen(data)); + ret = ZBarcode_Encode(symbol, (unsigned char *) data, (int) strlen(data)); if (strcmp(return_code, "00") == 0) { diff --git a/backend/tests/test_large.c b/backend/tests/test_large.c index 81f76cff..cf766080 100644 --- a/backend/tests/test_large.c +++ b/backend/tests/test_large.c @@ -33,13 +33,17 @@ #include "../large.h" #if defined(__MINGW32__) -# define LX_FMT "I64" +# if __WORDSIZE == 32 +# define LX_FMT "I32" +# else +# define LX_FMT "I64" +# endif # if defined(__clang__) # pragma GCC diagnostic ignored "-Wformat-non-iso" # elif defined(__GNUC__) # pragma GCC diagnostic ignored "-Wformat" /* Unfortunately doesn't seem to be way to only avoid non-ISO warnings */ # endif -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) || __WORDSIZE == 32 # define LX_FMT "ll" #else # define LX_FMT "l" diff --git a/backend/tests/test_library.c b/backend/tests/test_library.c index aaac5907..1d94a39d 100644 --- a/backend/tests/test_library.c +++ b/backend/tests/test_library.c @@ -379,7 +379,7 @@ static void test_encode_file_too_large(void) { fstream = fopen(filename, "w+"); assert_nonnull(fstream, "fopen(%s) failed (%d)\n", filename, ferror(fstream)); - ret = fwrite(buf, 1, sizeof(buf), fstream); + ret = (int) fwrite(buf, 1, sizeof(buf), fstream); assert_equal(ret, sizeof(buf), "fwrite return value: %d != %d\n", ret, (int)sizeof(buf)); ret = fclose(fstream); assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret); diff --git a/backend/tests/test_pcx.c b/backend/tests/test_pcx.c index a9885621..63448986 100644 --- a/backend/tests/test_pcx.c +++ b/backend/tests/test_pcx.c @@ -93,7 +93,7 @@ static void test_pcx(int index, int debug) { } symbol->debug |= debug; - length = strlen(data[i].data); + length = (int) strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); diff --git a/backend/tests/test_pdf417.c b/backend/tests/test_pdf417.c index c48a35f7..81010624 100644 --- a/backend/tests/test_pdf417.c +++ b/backend/tests/test_pdf417.c @@ -1074,7 +1074,7 @@ static void test_fuzz(int index, int debug) { length = data[i].length; if (length == -1) { - length = strlen(data[i].data); + length = (int) strlen(data[i].data); } ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); diff --git a/backend/tests/test_qr.c b/backend/tests/test_qr.c index 1ab82f3b..0b2632b6 100644 --- a/backend/tests/test_qr.c +++ b/backend/tests/test_qr.c @@ -1656,7 +1656,7 @@ static void test_microqr_padding(int index, int generate, int debug) { symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt symbol->debug |= debug; - length = strlen(data[i].data); + length = (int) strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) 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); diff --git a/backend/tests/test_raster.c b/backend/tests/test_raster.c index 35eacb3f..ffd57ab2 100644 --- a/backend/tests/test_raster.c +++ b/backend/tests/test_raster.c @@ -274,7 +274,7 @@ static void test_buffer(int index, int generate, int debug) { } else { text = data[i].data; } - length = strlen(text); + length = (int) strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_zero(ret, "i:%d ZBarcode_Encode(%s) ret %d != 0 (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); @@ -380,7 +380,7 @@ static void test_upcean_hrt(int index, int debug) { } symbol->debug |= debug; - length = strlen(data[i].data); + length = (int) strlen(data[i].data); ret = ZBarcode_Encode_and_Buffer(symbol, (unsigned char *) data[i].data, length, 0); assert_equal(ret, data[i].ret, "i:%d ret %d != %d\n", i, ret, data[i].ret); @@ -574,7 +574,7 @@ static void test_stacking(int index, int debug) { ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ret %d != zero\n", i, ret); - length2 = strlen(data[i].data2); + length2 = (int) strlen(data[i].data2); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data2, length2); assert_zero(ret, "i:%d ret %d != zero\n", i, ret); @@ -995,7 +995,7 @@ static void test_scale(int index, int debug) { } else { text = data[i].data; } - length = strlen(text); + length = (int) strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -1207,8 +1207,8 @@ static void test_buffer_plot(int index, int generate, int debug) { ret = testUtilBitmapCmp(symbol, data[i].expected_bitmap, &row, &column); assert_zero(ret, "i:%d (%s) testUtilBitmapCmp ret %d != 0 column %d row %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, column, row, data[i].data); - fg_len = strlen(data[i].fgcolour); - bg_len = strlen(data[i].bgcolour); + fg_len = (int) strlen(data[i].fgcolour); + bg_len = (int) strlen(data[i].bgcolour); if (fg_len > 6 || bg_len > 6) { assert_nonnull(symbol->alphamap, "i:%d ZBarcode_Buffer(%s) alphamap NULL\n", i, testUtilBarcodeName(data[i].symbology)); // TODO: check alphamap @@ -1674,7 +1674,7 @@ static void test_height(int index, int generate, int debug) { } else { text = data[i].data; } - length = strlen(text); + length = (int) strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%s) ret %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, data[i].ret, symbol->errtxt); diff --git a/backend/tests/test_rss.c b/backend/tests/test_rss.c index 08a9adca..36d4c806 100644 --- a/backend/tests/test_rss.c +++ b/backend/tests/test_rss.c @@ -794,7 +794,8 @@ static void test_examples(int index, int generate, int debug) { if (generate) { printf(" /*%3d*/ { %s, %d, \"%s\", %d, %d, %d, %d, \"%s\",\n", - i, testUtilBarcodeName(symbol->symbology), data[i].option_2, data[i].data, data[i].ret, symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); + i, testUtilBarcodeName(symbol->symbology), data[i].option_2, + data[i].data, data[i].ret, symbol->rows, symbol->width, data[i].bwipp_cmp, data[i].comment); testUtilModulesPrint(symbol, " ", "\n"); printf(" },\n"); } else { @@ -1228,6 +1229,7 @@ static void test_input(int index, int debug) { struct item { int symbology; + int option_2; char *data; int ret; int expected_rows; @@ -1235,32 +1237,33 @@ static void test_input(int index, int debug) { }; // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) struct item data[] = { - /* 0*/ { BARCODE_DBAR_OMN, "1234567890123", 0, 1, 96 }, - /* 1*/ { BARCODE_DBAR_OMN, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 2*/ { BARCODE_DBAR_OMN, "12345678901234", ZINT_ERROR_INVALID_CHECK, -1, -1 }, - /* 3*/ { BARCODE_DBAR_OMN, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, - /* 4*/ { BARCODE_DBAR_LTD, "1234567890123", 0, 1, 79 }, - /* 5*/ { BARCODE_DBAR_LTD, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 6*/ { BARCODE_DBAR_LTD, "12345678901235", ZINT_ERROR_INVALID_CHECK, -1, -1 }, - /* 7*/ { BARCODE_DBAR_LTD, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, - /* 8*/ { BARCODE_DBAR_LTD, "2234567890123", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 9*/ { BARCODE_DBAR_LTD, "22345678901238", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 10*/ { BARCODE_DBAR_EXP, "[01]12345678901234", ZINT_WARN_NONCOMPLIANT, 1, 134 }, - /* 11*/ { BARCODE_DBAR_EXP, "[01]12345678901231", 0, 1, 134 }, - /* 12*/ { BARCODE_DBAR_EXP, "[01]1234567890123A", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 13*/ { BARCODE_DBAR_EXP, "[01]123456789012315", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 14*/ { BARCODE_DBAR_STK, "1234567890123", 0, 3, 50 }, - /* 15*/ { BARCODE_DBAR_STK, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 16*/ { BARCODE_DBAR_STK, "12345678901235", ZINT_ERROR_INVALID_CHECK, -1, -1 }, - /* 17*/ { BARCODE_DBAR_STK, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, - /* 18*/ { BARCODE_DBAR_OMNSTK, "1234567890123", 0, 5, 50 }, - /* 19*/ { BARCODE_DBAR_OMNSTK, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 20*/ { BARCODE_DBAR_OMNSTK, "12345678901236", ZINT_ERROR_INVALID_CHECK, -1, -1 }, - /* 21*/ { BARCODE_DBAR_OMNSTK, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, - /* 22*/ { BARCODE_DBAR_EXPSTK, "[01]12345678901234", ZINT_WARN_NONCOMPLIANT, 5, 102 }, - /* 22*/ { BARCODE_DBAR_EXPSTK, "[01]12345678901231", 0, 5, 102 }, - /* 23*/ { BARCODE_DBAR_EXPSTK, "[01]123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, - /* 24*/ { BARCODE_DBAR_EXPSTK, "[01]123456789012315", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 0*/ { BARCODE_DBAR_OMN, -1, "1234567890123", 0, 1, 96 }, + /* 1*/ { BARCODE_DBAR_OMN, -1, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 2*/ { BARCODE_DBAR_OMN, -1, "12345678901234", ZINT_ERROR_INVALID_CHECK, -1, -1 }, + /* 3*/ { BARCODE_DBAR_OMN, -1, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, + /* 4*/ { BARCODE_DBAR_LTD, -1, "1234567890123", 0, 1, 79 }, + /* 5*/ { BARCODE_DBAR_LTD, -1, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 6*/ { BARCODE_DBAR_LTD, -1, "12345678901235", ZINT_ERROR_INVALID_CHECK, -1, -1 }, + /* 7*/ { BARCODE_DBAR_LTD, -1, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, + /* 8*/ { BARCODE_DBAR_LTD, -1, "2234567890123", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 9*/ { BARCODE_DBAR_LTD, -1, "22345678901238", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 10*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901234", ZINT_WARN_NONCOMPLIANT, 1, 134 }, + /* 11*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901231", 0, 1, 134 }, + /* 12*/ { BARCODE_DBAR_EXP, -1, "[01]1234567890123A", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 13*/ { BARCODE_DBAR_EXP, -1, "[01]123456789012315", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 14*/ { BARCODE_DBAR_STK, -1, "1234567890123", 0, 3, 50 }, + /* 15*/ { BARCODE_DBAR_STK, -1, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 16*/ { BARCODE_DBAR_STK, -1, "12345678901235", ZINT_ERROR_INVALID_CHECK, -1, -1 }, + /* 17*/ { BARCODE_DBAR_STK, -1, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, + /* 18*/ { BARCODE_DBAR_OMNSTK, -1, "1234567890123", 0, 5, 50 }, + /* 19*/ { BARCODE_DBAR_OMNSTK, -1, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 20*/ { BARCODE_DBAR_OMNSTK, -1, "12345678901236", ZINT_ERROR_INVALID_CHECK, -1, -1 }, + /* 21*/ { BARCODE_DBAR_OMNSTK, -1, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, + /* 22*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901234", ZINT_WARN_NONCOMPLIANT, 5, 102 }, + /* 23*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901231", 0, 5, 102 }, + /* 24*/ { BARCODE_DBAR_EXPSTK, -1, "[01]123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 25*/ { BARCODE_DBAR_EXPSTK, -1, "[01]123456789012315", ZINT_ERROR_INVALID_DATA, -1, -1 }, + /* 26*/ { BARCODE_DBAR_EXPSTK, 1, "[01]12345678901231", 0, 9, 53 }, }; int data_size = ARRAY_SIZE(data); int i, length, ret; @@ -1275,7 +1278,7 @@ static void test_input(int index, int debug) { symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); - length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug); + length = testUtilSetSymbol(symbol, data[i].symbology, -1 /*input_mode*/, -1 /*eci*/, -1 /*option_1*/, data[i].option_2, -1, -1 /*output_options*/, data[i].data, -1, debug); ret = ZBarcode_Encode(symbol, (const unsigned char *) 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); diff --git a/backend/tests/test_svg.c b/backend/tests/test_svg.c index f0abf2dc..92c0d969 100644 --- a/backend/tests/test_svg.c +++ b/backend/tests/test_svg.c @@ -155,7 +155,7 @@ static void test_print(int index, int generate, int debug) { } else { text = data[i].data; } - text_length = strlen(text); + text_length = (int) strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, text_length); assert_equal(ret, data[i].ret, "i:%d %s ZBarcode_Encode ret %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, data[i].ret, symbol->errtxt); diff --git a/backend/tests/test_tif.c b/backend/tests/test_tif.c index 5c51c6cd..6036235c 100644 --- a/backend/tests/test_tif.c +++ b/backend/tests/test_tif.c @@ -238,7 +238,7 @@ static void test_print(int index, int generate, int debug) { } else { text = data[i].data; } - text_length = strlen(text); + text_length = (int) strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, text_length); assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt); diff --git a/backend/tests/test_vector.c b/backend/tests/test_vector.c index e90699b4..e847d34d 100644 --- a/backend/tests/test_vector.c +++ b/backend/tests/test_vector.c @@ -290,7 +290,7 @@ static void test_buffer_vector(int index, int generate, int debug) { } else { text = data[i].data; } - length = strlen(text); + length = (int) strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -397,7 +397,7 @@ static void test_upcean_hrt(int index, int debug) { } symbol->debug |= debug; - length = strlen(data[i].data); + length = (int) strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -554,7 +554,7 @@ static void test_stacking(int index, int debug) { ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ret %d != zero\n", i, ret); - length2 = strlen(data[i].data2); + length2 = (int) strlen(data[i].data2); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data2, length2); assert_zero(ret, "i:%d ret %d != zero\n", i, ret); @@ -754,7 +754,7 @@ static void test_noncomposite_string_x(int index, int debug) { symbol->input_mode = UNICODE_MODE; symbol->debug |= debug; - length = strlen(data[i].data); + length = (int) strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -815,7 +815,7 @@ static void test_upcean_whitespace_width(int index, int debug) { symbol->whitespace_width = data[i].whitespace_width; symbol->debug |= debug; - length = strlen(data[i].data); + length = (int) strlen(data[i].data); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); assert_zero(ret, "i:%d ZBarcode_Encode(%d) ret %d != 0 %s\n", i, data[i].symbology, ret, symbol->errtxt); @@ -1298,7 +1298,7 @@ static void test_height(int index, int generate, int debug) { } else { text = data[i].data; } - length = strlen(text); + length = (int) strlen(text); ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode(%s) ret %d != %d (%s)\n", i, testUtilBarcodeName(data[i].symbology), ret, data[i].ret, symbol->errtxt); diff --git a/backend/tests/testcommon.c b/backend/tests/testcommon.c index 9be31689..707b651e 100644 --- a/backend/tests/testcommon.c +++ b/backend/tests/testcommon.c @@ -64,10 +64,13 @@ static int failed = 0; static int skipped = 0; int assertionFailed = 0; int assertionNum = 0; +const char *assertionFilename = ""; static const char *testName = NULL; static const char *testFunc = NULL; -#if _MSC_VER == 1200 +/* Visual C++ 6 doesn't support variadic args to macros, so make do with functions, which have inferior behaviour, + e.g. don't exit on failure, `assert_equal()` type-specific */ +#if _MSC_VER == 1200 /* VC6 */ #include void assert_zero(int exp, const char *fmt, ...) { assertionNum++; @@ -113,9 +116,10 @@ void assert_notequal(int e1, int e2, const char *fmt, ...) { } #endif +/* Begin individual test function */ void testStartReal(const char *func, const char *name) { tests++; - if (*func && name && *name && strcmp(func, name) == 0) { + if (func && *func && name && *name && strcmp(func, name) == 0) { testName = ""; } else { testName = name; @@ -126,22 +130,9 @@ void testStartReal(const char *func, const char *name) { printf("_____%d: %s: %s...\n", tests, testFunc, testName ? testName : ""); } -void testEnd(int result) { - if (testName && testName[0]) { - printf(".....%d: %s: %s ", tests, testFunc, testName); - } else { - printf(".....%d: %s: ", tests, testFunc); - } - if (result) { - puts("FAILED."); - failed++; - } else { - puts("PASSED."); - } -} - +/* End individual test function */ void testFinish(void) { - if (testName && testName[0]) { + if (testName && *testName) { printf(".....%d: %s: %s ", tests, testFunc, testName); } else { printf(".....%d: %s: ", tests, testFunc); @@ -154,9 +145,10 @@ void testFinish(void) { } } +/* Skip (and end) individual test function */ void testSkip(const char *msg) { skipped++; - if (testName && testName[0]) { + if (testName && *testName) { printf(".....%d: %s: %s ", tests, testFunc, testName); } else { printf(".....%d: %s: ", tests, testFunc); @@ -169,6 +161,7 @@ void testSkip(const char *msg) { } } +/* End test program */ void testReport() { if (failed && skipped) { printf("Total %d tests, %d skipped, %d fails.\n", tests, skipped, failed); @@ -187,6 +180,7 @@ void testReport() { } } +/* Begin test program, parse args */ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) { int i, opt, ran; long long_opt; @@ -206,6 +200,20 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) { typedef void (*func_index_generate)(int index, int generate); typedef void (*func_index_generate_debug)(int index, int generate, int debug); + if (argc) { + char *filename = strrchr(argv[0], '/'); +#ifdef _WIN32 + if (filename == NULL) { + filename = strrchr(argv[0], '\\'); + } +#endif + if (filename) { + assertionFilename = filename + 1; + } else { + assertionFilename = argv[0]; + } + } + while ((opt = getopt(argc, argv, "d:f:gi:")) != -1) { switch (opt) { case 'd': @@ -290,6 +298,37 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size) { } } +/* Helper to set common symbol fields */ +int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci, int option_1, int option_2, + int option_3, int output_options, char *data, int length, int debug) { + symbol->symbology = symbology; + if (input_mode != -1) { + symbol->input_mode = input_mode; + } + if (eci != -1) { + symbol->eci = eci; + } + if (option_1 != -1) { + symbol->option_1 = option_1; + } + if (option_2 != -1) { + symbol->option_2 = option_2; + } + if (option_3 != -1) { + symbol->option_3 = option_3; + } + if (output_options != -1) { + symbol->output_options = output_options; + } + symbol->debug |= debug; + if (length == -1) { + length = (int) strlen(data); + } + + return length; +} + +/* Pretty name for symbology */ const char *testUtilBarcodeName(int symbology) { struct item { const char *name; @@ -449,41 +488,15 @@ const char *testUtilBarcodeName(int symbology) { if (symbology < 0 || symbology >= data_size) { return ""; } - if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { // Self-check + // Self-check + if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { fprintf(stderr, "testUtilBarcodeName: data table out of sync (%d)\n", symbology); abort(); } return data[symbology].name; } -int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci, int option_1, int option_2, int option_3, int output_options, char *data, int length, int debug) { - symbol->symbology = symbology; - if (input_mode != -1) { - symbol->input_mode = input_mode; - } - if (eci != -1) { - symbol->eci = eci; - } - if (option_1 != -1) { - symbol->option_1 = option_1; - } - if (option_2 != -1) { - symbol->option_2 = option_2; - } - if (option_3 != -1) { - symbol->option_3 = option_3; - } - if (output_options != -1) { - symbol->output_options = output_options; - } - symbol->debug |= debug; - if (length == -1) { - length = strlen(data); - } - - return length; -} - +/* Pretty name for error/warning */ const char *testUtilErrorName(int error_number) { struct item { const char *name; @@ -509,13 +522,16 @@ const char *testUtilErrorName(int error_number) { if (error_number < 0 || error_number >= data_size) { return ""; } - if (data[error_number].val != error_number || (data[error_number].define != -1 && data[error_number].define != error_number)) { // Self-check + // Self-check + if (data[error_number].val != error_number + || (data[error_number].define != -1 && data[error_number].define != error_number)) { fprintf(stderr, "testUtilErrorName: data table out of sync (%d)\n", error_number); abort(); } return data[error_number].name; } +/* Pretty name for input mode */ const char *testUtilInputModeName(int input_mode) { static char buf[512]; @@ -564,6 +580,7 @@ const char *testUtilInputModeName(int input_mode) { return buf; } +/* Pretty name for option 3 */ const char *testUtilOption3Name(int option_3) { static char buffer[64]; @@ -604,6 +621,7 @@ const char *testUtilOption3Name(int option_3) { return name; } +/* Pretty name for output options */ const char *testUtilOutputOptionsName(int output_options) { static char buf[512]; @@ -650,12 +668,14 @@ const char *testUtilOutputOptionsName(int output_options) { } } if (set != output_options) { - fprintf(stderr, "testUtilOutputOptionsName: unknown output option(s) %d (%d)\n", output_options & set, output_options); + fprintf(stderr, "testUtilOutputOptionsName: unknown output option(s) %d (%d)\n", + output_options & set, output_options); abort(); } return buf; } +/* Convert modules spanning 3 rows to DAFT equivalents */ int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size) { int i; char *b = buffer; @@ -692,6 +712,7 @@ int testUtilIsValidUTF8(const unsigned char str[], const int length) { return state == 0; } +/* Escape data for printing on generate test. Has a number of issues, e.g. need to use octal escapes */ char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size) { int i; unsigned char *b = (unsigned char *) buffer; @@ -727,6 +748,7 @@ char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size) return escaped; } +/* Helper to read a CSV field */ char *testUtilReadCSVField(char *buffer, char *field, int field_size) { int i; char *b = buffer; @@ -740,9 +762,10 @@ char *testUtilReadCSVField(char *buffer, char *field, int field_size) { return b; } +/* Helper to fill a buffer (for "large" tests) - single-byte filler only */ void testUtilStrCpyRepeat(char *buffer, char *repeat, int size) { int i; - int len = strlen(repeat); + int len = (int) strlen(repeat); int max = size - len; if (len == 0) { fprintf(stderr, "testUtilStrCpyRepeat: only use non-empty, non-NUL single-byte data for repeat pattern\n"); @@ -755,6 +778,7 @@ void testUtilStrCpyRepeat(char *buffer, char *repeat, int size) { buffer[size] = '\0'; } +/* Compare some "important" symbol fields for equality */ int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b) { int i, j; if (a->symbology != b->symbology) { @@ -802,6 +826,7 @@ int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b) return 0; } +/* Copy a full vector structure (for later comparison) */ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) { struct zint_vector_rect *rect; struct zint_vector_string *string; @@ -876,6 +901,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) { return out; } +/* Compare 2 full vector structures */ int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b) { struct zint_vector_rect *arect; struct zint_vector_string *astring; @@ -1010,6 +1036,7 @@ int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b) return 0; } +/* Dump modules into buffer as '0'/'1' (or colours 'W', 'C', 'B' etc if Ultra) */ int testUtilModulesDump(const struct zint_symbol *symbol, char dump[], int dump_size) { int r, w; char *d = dump; @@ -1033,6 +1060,7 @@ int testUtilModulesDump(const struct zint_symbol *symbol, char dump[], int dump_ return d - dump; } +/* Print out module dump (for generate tests) */ void testUtilModulesPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix) { int r; for (r = 0; r < symbol->rows; r++) { @@ -1040,6 +1068,8 @@ void testUtilModulesPrint(const struct zint_symbol *symbol, const char *prefix, } } +/* Print out a single row of a module dump (for generate tests where rows all the same, to avoid large dumps of + duplicate data) */ void testUtilModulesPrintRow(const struct zint_symbol *symbol, int row, const char *prefix, const char *postfix) { int w; if (*prefix) { @@ -1061,6 +1091,7 @@ void testUtilModulesPrintRow(const struct zint_symbol *symbol, int row, const ch } } +/* Whether 2 module dumps are the same */ int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, int *width, int *row) { const char *e = expected; const char *ep = expected + strlen(expected); @@ -1093,6 +1124,7 @@ int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, i return e != ep || r != symbol->rows || w != symbol->width ? 1 /*fail*/ : 0 /*success*/; } +/* Whether 2 module row dumps are the same */ int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char *expected, int *width) { const char *e = expected; const char *ep = expected + strlen(expected); @@ -1118,50 +1150,7 @@ int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char return e != ep || w != symbol->width ? 1 /*fail*/ : 0 /*success*/; } -int testUtilModulesDumpHex(const struct zint_symbol *symbol, char dump[], int dump_size) { - int i, r; - char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', - '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - int space = 0; - char *d = dump; - char *de = dump + dump_size; - - for (r = 0; r < symbol->rows && d < de; r++) { - int byt = 0; - for (i = 0; i < symbol->width && d < de; i++) { - if (space == 2) { - *d++ = ' '; - space = 0; - } - byt = byt << 1; - if (symbol->symbology == BARCODE_ULTRA) { - if (module_colour_is_set(symbol, r, i)) { - byt += 1; - } - } else { - if (module_is_set(symbol, r, i)) { - byt += 1; - } - } - if (d < de && ((i + 1) % 4) == 0) { - *d++ = hex[byt]; - space++; - byt = 0; - } - } - if (d < de && (symbol->width % 4) != 0) { - byt = byt << (4 - (symbol->width % 4)); - *d++ = hex[byt]; - space++; - } - } - if (d == de) { - return -1; - } - *d = '\0'; - return d - dump; -} - +/* Dump an unsigned int array as hex */ char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_size) { int i, cnt_len = 0; @@ -1175,6 +1164,7 @@ char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_ return dump; } +/* Dump an unsigned char array as hex */ char *testUtilUCharArrayDump(unsigned char *array, int size, char *dump, int dump_size) { int i, cnt_len = 0; @@ -1188,6 +1178,110 @@ char *testUtilUCharArrayDump(unsigned char *array, int size, char *dump, int dum return dump; } +/* Dump a bitmap to stdout, for generate tests. Also useful for debugging */ +void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix) { + static const char colour[] = { '0', 'C', 'M', 'B', 'Y', 'G', 'R', '1' }; + int row, column, i, j; + + if (!prefix) { + fputs(" ", stdout); + for (column = 0; column < symbol->bitmap_width; column += 10) printf("%-3d ", column); + fputs("\n ", stdout); + for (column = 0; column < symbol->bitmap_width; column++) printf("%d", column % 10); + putchar('\n'); + } + + for (row = 0; row < symbol->bitmap_height; row++) { + if (!prefix) { + printf("%3d: ", row); + } else { + if (*prefix) { + fputs(prefix, stdout); + } + putchar('"'); + } + for (column = 0; column < symbol->bitmap_width; column++) { + if (symbol->output_options & OUT_BUFFER_INTERMEDIATE) { + putchar(symbol->bitmap[(row * symbol->bitmap_width) + column]); + } else { + i = ((row * symbol->bitmap_width) + column) * 3; + if ((symbol->bitmap[i] == 0 || symbol->bitmap[i] == 0xff) + && (symbol->bitmap[i + 1] == 0 || symbol->bitmap[i + 1] == 0xff) + && (symbol->bitmap[i + 2] == 0 || symbol->bitmap[i + 2] == 0xff)) { + j = !symbol->bitmap[i] + !symbol->bitmap[i + 1] * 2 + !symbol->bitmap[i + 2] * 4; + putchar(colour[j]); + } else { + printf("%02X%02X%02X", symbol->bitmap[i], symbol->bitmap[i + 1], symbol->bitmap[i + 2]); + } + } + } + if (!postfix) { + putchar('\n'); + } else { + putchar('"'); + if (*postfix) { + fputs(postfix, stdout); + } + } + } + + if (!postfix) { + fputs(" ", stdout); + for (column = 0; column < symbol->bitmap_width; column++) printf("%d", column % 10); + fputs("\n ", stdout); + for (column = 0; column < symbol->bitmap_width; column += 10) printf("%-3d ", column); + putchar('\n'); + } +} + +/* Compare a bitmap to a dump */ +int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column) { + static const char colour[] = { '0', 'C', 'M', 'B', 'Y', 'G', 'R', '1' }; + int r, c = -1, i, j; + const char *e = expected; + const char *ep = expected + strlen(expected); + char buf[7]; + + for (r = 0; r < symbol->bitmap_height; r++) { + for (c = 0; c < symbol->bitmap_width; c++) { + if (symbol->output_options & OUT_BUFFER_INTERMEDIATE) { + if (*e != symbol->bitmap[(r * symbol->bitmap_width) + c]) { + *row = r; + *column = c; + return 1 /*fail*/; + } + e++; + } else { + i = ((r * symbol->bitmap_width) + c) * 3; + if ((symbol->bitmap[i] == 0 || symbol->bitmap[i] == 0xff) + && (symbol->bitmap[i + 1] == 0 || symbol->bitmap[i + 1] == 0xff) + && (symbol->bitmap[i + 2] == 0 || symbol->bitmap[i + 2] == 0xff)) { + j = !symbol->bitmap[i] + !symbol->bitmap[i + 1] * 2 + !symbol->bitmap[i + 2] * 4; + if (*e != colour[j]) { + *row = r; + *column = c; + return 1 /*fail*/; + } + e++; + } else { + sprintf(buf, "%02X%02X%02X", symbol->bitmap[i], symbol->bitmap[i + 1], symbol->bitmap[i + 2]); + if (strncmp(buf, e, 6) != 0) { + *row = r; + *column = c; + return 1 /*fail*/; + } + e += 6; + } + } + } + } + + *row = r; + *column = c; + return e != ep || r != symbol->bitmap_height || c != symbol->bitmap_width ? 1 /*fail*/ : 0 /*success*/; +} + +/* Determine the location of test data relative to where the test is being run */ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const char *filename) { int subdir_len = subdir ? (int) strlen(subdir) : 0; int filename_len = filename ? (int) strlen(filename) : 0; @@ -1277,105 +1371,7 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch return 1; } -void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix) { - static const char colour[] = { '0', 'C', 'M', 'B', 'Y', 'G', 'R', '1' }; - int row, column, i, j; - - if (!prefix) { - fputs(" ", stdout); - for (column = 0; column < symbol->bitmap_width; column += 10) printf("%-3d ", column); - fputs("\n ", stdout); - for (column = 0; column < symbol->bitmap_width; column++) printf("%d", column % 10); - putchar('\n'); - } - - for (row = 0; row < symbol->bitmap_height; row++) { - if (!prefix) { - printf("%3d: ", row); - } else { - if (*prefix) { - fputs(prefix, stdout); - } - putchar('"'); - } - for (column = 0; column < symbol->bitmap_width; column++) { - if (symbol->output_options & OUT_BUFFER_INTERMEDIATE) { - putchar(symbol->bitmap[(row * symbol->bitmap_width) + column]); - } else { - i = ((row * symbol->bitmap_width) + column) * 3; - if ((symbol->bitmap[i] == 0 || symbol->bitmap[i] == 0xff) && (symbol->bitmap[i + 1] == 0 || symbol->bitmap[i + 1] == 0xff) - && (symbol->bitmap[i + 2] == 0 || symbol->bitmap[i + 2] == 0xff)) { - j = (symbol->bitmap[i] == 0) + (symbol->bitmap[i + 1] == 0) * 2 + (symbol->bitmap[i + 2] == 0) * 4; - putchar(colour[j]); - } else { - printf("%02X%02X%02X", symbol->bitmap[i], symbol->bitmap[i + 1], symbol->bitmap[i + 2]); - } - } - } - if (!postfix) { - putchar('\n'); - } else { - putchar('"'); - if (*postfix) { - fputs(postfix, stdout); - } - } - } - - if (!postfix) { - fputs(" ", stdout); - for (column = 0; column < symbol->bitmap_width; column++) printf("%d", column % 10); - fputs("\n ", stdout); - for (column = 0; column < symbol->bitmap_width; column += 10) printf("%-3d ", column); - putchar('\n'); - } -} - -int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column) { - static const char colour[] = { '0', 'C', 'M', 'B', 'Y', 'G', 'R', '1' }; - int r, c = -1, i, j; - const char *e = expected; - const char *ep = expected + strlen(expected); - char buf[7]; - - for (r = 0; r < symbol->bitmap_height; r++) { - for (c = 0; c < symbol->bitmap_width; c++) { - if (symbol->output_options & OUT_BUFFER_INTERMEDIATE) { - if (*e != symbol->bitmap[(r * symbol->bitmap_width) + c]) { - *row = r; - *column = c; - return 1 /*fail*/; - } - e++; - } else { - i = ((r * symbol->bitmap_width) + c) * 3; - if ((symbol->bitmap[i] == 0 || symbol->bitmap[i] == 0xff) && (symbol->bitmap[i + 1] == 0 || symbol->bitmap[i + 1] == 0xff) - && (symbol->bitmap[i + 2] == 0 || symbol->bitmap[i + 2] == 0xff)) { - j = (symbol->bitmap[i] == 0) + (symbol->bitmap[i + 1] == 0) * 2 + (symbol->bitmap[i + 2] == 0) * 4; - if (*e != colour[j]) { - *row = r; - *column = c; - return 1 /*fail*/; - } - e++; - } else { - sprintf(buf, "%02X%02X%02X", symbol->bitmap[i], symbol->bitmap[i + 1], symbol->bitmap[i + 2]); - if (strncmp(buf, e, 6) != 0) { - *row = r; - *column = c; - return 1 /*fail*/; - } - e += 6; - } - } - } - } - - *row = r; - *column = c; - return e != ep || r != symbol->bitmap_height || c != symbol->bitmap_width ? 1 /*fail*/ : 0 /*success*/; -} - +/* Does file exist? */ int testUtilExists(const char *filename) { FILE *fp = fopen(filename, "r"); if (fp == NULL) { @@ -1385,6 +1381,7 @@ int testUtilExists(const char *filename) { return 1; } +/* Does directory exist? (Windows compatibility) */ int testUtilDirExists(const char *dirname) { #ifdef _WIN32 DWORD dwAttrib = GetFileAttributes(dirname); @@ -1394,7 +1391,7 @@ int testUtilDirExists(const char *dirname) { #endif } -// Returns 0 if successful, non-zero if not +/* Make a directory (Windows compatibility). Returns 0 if successful, non-zero if not */ int testUtilMkDir(const char *dirname) { #ifdef _WIN32 return CreateDirectory(dirname, NULL) == 0; @@ -1403,7 +1400,7 @@ int testUtilMkDir(const char *dirname) { #endif } -// Returns 0 if successful, non-zero if not +/* Remove a directory (Windows compatibility). Returns 0 if successful, non-zero if not */ int testUtilRmDir(const char *dirname) { #ifdef _WIN32 return RemoveDirectory(dirname) == 0; @@ -1412,6 +1409,7 @@ int testUtilRmDir(const char *dirname) { #endif } +/* Rename a file (Windows compatibility). */ int testUtilRename(const char *oldpath, const char *newpath) { #ifdef _MSVC int ret = remove(newpath); @@ -1420,6 +1418,7 @@ int testUtilRename(const char *oldpath, const char *newpath) { return rename(oldpath, newpath); } +/* Compare 2 PNG files */ int testUtilCmpPngs(const char *png1, const char *png2) { int ret = -1; #ifdef NO_PNG @@ -1446,7 +1445,7 @@ int testUtilCmpPngs(const char *png1, const char *png2) { return 3; } - png_ptr1 = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL); + png_ptr1 = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp) NULL, NULL, NULL); if (!png_ptr1) { fclose(fp1); fclose(fp2); @@ -1454,23 +1453,23 @@ int testUtilCmpPngs(const char *png1, const char *png2) { } info_ptr1 = png_create_info_struct(png_ptr1); if (!info_ptr1) { - png_destroy_read_struct(&png_ptr1, (png_infopp)NULL, (png_infopp)NULL); + png_destroy_read_struct(&png_ptr1, (png_infopp) NULL, (png_infopp) NULL); fclose(fp1); fclose(fp2); return 5; } - png_ptr2 = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, NULL, NULL); + png_ptr2 = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp) NULL, NULL, NULL); if (!png_ptr2) { - png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp)NULL); + png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp) NULL); fclose(fp1); fclose(fp2); return 6; } info_ptr2 = png_create_info_struct(png_ptr2); if (!info_ptr2) { - png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp)NULL); - png_destroy_read_struct(&png_ptr2, (png_infopp)NULL, (png_infopp)NULL); + png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp) NULL); + png_destroy_read_struct(&png_ptr2, (png_infopp) NULL, (png_infopp) NULL); fclose(fp1); fclose(fp2); return 7; @@ -1483,8 +1482,8 @@ int testUtilCmpPngs(const char *png1, const char *png2) { if (row2) { free(row2); } - png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp)NULL); - png_destroy_read_struct(&png_ptr2, &info_ptr2, (png_infopp)NULL); + png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp) NULL); + png_destroy_read_struct(&png_ptr2, &info_ptr2, (png_infopp) NULL); fclose(fp1); fclose(fp2); return 8; @@ -1496,8 +1495,8 @@ int testUtilCmpPngs(const char *png1, const char *png2) { if (row2) { free(row2); } - png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp)NULL); - png_destroy_read_struct(&png_ptr2, &info_ptr2, (png_infopp)NULL); + png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp) NULL); + png_destroy_read_struct(&png_ptr2, &info_ptr2, (png_infopp) NULL); fclose(fp1); fclose(fp2); return 9; @@ -1516,8 +1515,8 @@ int testUtilCmpPngs(const char *png1, const char *png2) { if (width1 != width2 || height1 != height2) { printf("width1 %d, width2 %d, height1 %d, height2 %d\n", width1, width2, height1, height2); - png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp)NULL); - png_destroy_read_struct(&png_ptr2, &info_ptr2, (png_infopp)NULL); + png_destroy_read_struct(&png_ptr1, &info_ptr1, (png_infopp) NULL); + png_destroy_read_struct(&png_ptr2, &info_ptr2, (png_infopp) NULL); fclose(fp1); fclose(fp2); return 10; @@ -1537,7 +1536,8 @@ int testUtilCmpPngs(const char *png1, const char *png2) { if (png_get_valid(png_ptr1, info_ptr1, PNG_INFO_tRNS)) { png_set_tRNS_to_alpha(png_ptr1); } - if (color_type1 == PNG_COLOR_TYPE_RGB || color_type1 == PNG_COLOR_TYPE_GRAY || color_type1 == PNG_COLOR_TYPE_PALETTE) { + if (color_type1 == PNG_COLOR_TYPE_RGB || color_type1 == PNG_COLOR_TYPE_GRAY + || color_type1 == PNG_COLOR_TYPE_PALETTE) { png_set_filler(png_ptr1, 0xFF, PNG_FILLER_AFTER); } if (color_type1 == PNG_COLOR_TYPE_GRAY || color_type1 == PNG_COLOR_TYPE_GRAY_ALPHA) { @@ -1558,7 +1558,8 @@ int testUtilCmpPngs(const char *png1, const char *png2) { if (png_get_valid(png_ptr2, info_ptr2, PNG_INFO_tRNS)) { png_set_tRNS_to_alpha(png_ptr2); } - if (color_type2 == PNG_COLOR_TYPE_RGB || color_type2 == PNG_COLOR_TYPE_GRAY || color_type2 == PNG_COLOR_TYPE_PALETTE) { + if (color_type2 == PNG_COLOR_TYPE_RGB || color_type2 == PNG_COLOR_TYPE_GRAY + || color_type2 == PNG_COLOR_TYPE_PALETTE) { png_set_filler(png_ptr2, 0xFF, PNG_FILLER_AFTER); } if (color_type2 == PNG_COLOR_TYPE_GRAY || color_type2 == PNG_COLOR_TYPE_GRAY_ALPHA) { @@ -1615,6 +1616,7 @@ int testUtilCmpPngs(const char *png1, const char *png2) { return ret; } +/* Compare 2 TXT files */ int testUtilCmpTxts(const char *txt1, const char *txt2) { int ret = -1; FILE *fp1; @@ -1665,6 +1667,7 @@ int testUtilCmpTxts(const char *txt1, const char *txt2) { return ret; } +/* Compare 2 binary files */ int testUtilCmpBins(const char *bin1, const char *bin2) { int ret = -1; FILE *fp1; @@ -1705,10 +1708,12 @@ int testUtilCmpBins(const char *bin1, const char *bin2) { return ret; } +/* Compare 2 SVG files */ int testUtilCmpSvgs(const char *svg1, const char *svg2) { return testUtilCmpTxts(svg1, svg2); } +/* Compare 2 EPS files */ int testUtilCmpEpss(const char *eps1, const char *eps2) { int ret = -1; FILE *fp1; @@ -1733,8 +1738,10 @@ int testUtilCmpEpss(const char *eps1, const char *eps2) { if (fgets(buf1, sizeof(buf1), fp1) == NULL || strcmp(buf1, first_line) != 0 || fgets(buf2, sizeof(buf2), fp2) == NULL || strcmp(buf2, first_line) != 0) { ret = 10; - } else if (fgets(buf1, sizeof(buf1), fp1) == NULL || strncmp(buf1, second_line_start, sizeof(second_line_start) - 1) != 0 - || fgets(buf2, sizeof(buf2), fp2) == NULL || strncmp(buf2, second_line_start, sizeof(second_line_start) - 1) != 0) { + } else if (fgets(buf1, sizeof(buf1), fp1) == NULL + || strncmp(buf1, second_line_start, sizeof(second_line_start) - 1) != 0 + || fgets(buf2, sizeof(buf2), fp2) == NULL + || strncmp(buf2, second_line_start, sizeof(second_line_start) - 1) != 0) { ret = 11; } @@ -1780,10 +1787,12 @@ int testUtilCmpEpss(const char *eps1, const char *eps2) { #define DEV_NULL_STDERR "> /dev/null 2>&1" #endif +/* Whether ImageMagick's identify utility available on system */ int testUtilHaveIdentify() { return system("magick -version " DEV_NULL) == 0; } +/* Check raster files */ int testUtilVerifyIdentify(const char *filename, int debug) { char cmd[512 + 128]; @@ -1805,10 +1814,12 @@ int testUtilVerifyIdentify(const char *filename, int debug) { return system(cmd); } +/* Whether Libre Office available on system */ int testUtilHaveLibreOffice() { return system("libreoffice --version " DEV_NULL) == 0; } +/* Check SVG files, very hacky to evoke. Will fail if Libre package that is not LibreOffice Draw is running */ int testUtilVerifyLibreOffice(const char *filename, int debug) { char cmd[512 + 128]; char svg[512]; @@ -1818,7 +1829,8 @@ int testUtilVerifyLibreOffice(const char *filename, int debug) { FILE *fp; int len; - /* Hack to read SVG produced by LibreOffice and search for 'x="-32767"' which indicates it didn't load barcode file */ + /* Hack to read SVG produced by LibreOffice and search for 'x="-32767"' which indicates it didn't load barcode + file */ if (strlen(filename) > 512) { return -1; } @@ -1886,10 +1898,12 @@ int testUtilVerifyLibreOffice(const char *filename, int debug) { #define GS_FILENAME "gs" #endif +/* Whether Ghostscript available on system */ int testUtilHaveGhostscript() { return system(GS_FILENAME " -v " DEV_NULL) == 0; } +/* Check EPS files */ int testUtilVerifyGhostscript(const char *filename, int debug) { char cmd[512 + 128]; @@ -1897,7 +1911,8 @@ int testUtilVerifyGhostscript(const char *filename, int debug) { return -1; } if (debug & ZINT_DEBUG_TEST_PRINT) { - sprintf(cmd, GS_FILENAME " -dNOPAUSE -dBATCH -dNODISPLAY -q %s", filename); // Prints nothing of interest with or without -q unless bad + // Prints nothing of interest with or without -q unless bad + sprintf(cmd, GS_FILENAME " -dNOPAUSE -dBATCH -dNODISPLAY -q %s", filename); printf("%s\n", cmd); } else { sprintf(cmd, GS_FILENAME " -dNOPAUSE -dBATCH -dNODISPLAY -q %s", filename); @@ -1906,12 +1921,13 @@ int testUtilVerifyGhostscript(const char *filename, int debug) { return system(cmd); } -/* v.Nu https://github.com/validator/validator - * Needs "$INSTALL_DIR/vnu-runtime-image/bin" in PATH */ +/* Whether vnu validator available on system. v.Nu https://github.com/validator/validator + Needs "$INSTALL_DIR/vnu-runtime-image/bin" in PATH */ int testUtilHaveVnu() { return system("vnu --version " DEV_NULL_STDERR) == 0; } +/* Check SVG files, very full but very slow */ int testUtilVerifyVnu(const char *filename, int debug) { char buf[512 + 128]; @@ -1928,11 +1944,12 @@ int testUtilVerifyVnu(const char *filename, int debug) { return system(buf); } -/* Requires libtiff 4.2.0 http://www.libtiff.org to be installed */ +/* Whether tiffinfo available on system. Requires libtiff 4.2.0 http://www.libtiff.org to be installed */ int testUtilHaveTiffInfo() { return system("tiffinfo -h " DEV_NULL) == 0; } +/* Check TIF files */ int testUtilVerifyTiffInfo(const char *filename, int debug) { char cmd[512 + 128]; @@ -1948,7 +1965,9 @@ int testUtilVerifyTiffInfo(const char *filename, int debug) { return system(cmd); } -static const char *testUtilBwippName(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug, int *linear_row_height, int *gs1_cvt) { +/* Map Zint symbology to BWIPP routine */ +static const char *testUtilBwippName(int index, const struct zint_symbol *symbol, int option_1, int option_2, + int option_3, int debug, int *linear_row_height, int *gs1_cvt) { struct item { const char *name; int define; @@ -2116,7 +2135,8 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol fprintf(stderr, "testUtilBwippName: unknown symbology (%d)\n", symbology); abort(); } - if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { // Self-check + // Self-check + if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { fprintf(stderr, "testUtilBwippName: data table out of sync (%d)\n", symbology); abort(); } @@ -2129,7 +2149,8 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol if ((option_1 != -1 && !data[symbology].can_option_1) || (option_2 != -1 && !data[symbology].can_option_2) || (option_3 != -1 && !data[symbology].can_option_3)) { if (debug & ZINT_DEBUG_TEST_PRINT) { - printf("i:%d %s not BWIPP compatible, options not supported, option_1 %d, option_2 %d, option_3 %d\n", index, testUtilBarcodeName(symbology), option_1, option_2, option_3); + printf("i:%d %s not BWIPP compatible, options not supported, option_1 %d, option_2 %d, option_3 %d\n", + index, testUtilBarcodeName(symbology), option_1, option_2, option_3); } return NULL; } @@ -2137,14 +2158,16 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol if (symbology == BARCODE_CODE11) { if (option_2 != 1 && option_2 != 2) { /* 2 check digits (Zint default) not supported */ if (debug & ZINT_DEBUG_TEST_PRINT) { - printf("i:%d %s not BWIPP compatible, 2 check digits not supported, option_1 %d, option_2 %d\n", index, testUtilBarcodeName(symbology), option_1, option_2); + printf("i:%d %s not BWIPP compatible, 2 check digits not supported, option_1 %d, option_2 %d\n", + index, testUtilBarcodeName(symbology), option_1, option_2); } return NULL; } } else if (symbology == BARCODE_CODABLOCKF || symbology == BARCODE_HIBC_BLOCKF) { if (option_1 == 1) { /* Single row i.e. CODE128 not supported */ if (debug & ZINT_DEBUG_TEST_PRINT) { - printf("i:%d %s not BWIPP compatible, single row not supported, option_1 %d\n", index, testUtilBarcodeName(symbology), option_1); + printf("i:%d %s not BWIPP compatible, single row not supported, option_1 %d\n", + index, testUtilBarcodeName(symbology), option_1); } return NULL; } @@ -2164,7 +2187,8 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol return "gs1datamatrix"; } else if (symbology == BARCODE_AZTEC) { if (debug & ZINT_DEBUG_TEST_PRINT) { - printf("i:%d %s not BWIPP compatible, GS1_MODE not supported\n", index, testUtilBarcodeName(symbology)); + printf("i:%d %s not BWIPP compatible, GS1_MODE not supported\n", + index, testUtilBarcodeName(symbology)); } return NULL; } else if (symbology == BARCODE_DOTCODE) { @@ -2178,10 +2202,13 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol return data[symbology].name; } -int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug) { +/* Whether can use BWIPP to check a symbology with given options */ +int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, + int debug) { return testUtilBwippName(index, symbol, option_1, option_2, option_3, debug, NULL, NULL) != NULL; } +/* Convert Zint GS1 and add-on format to BWIPP's */ static void testUtilBwippCvtGS1Data(char *bwipp_data, int upcean, int *addon_posn) { char *b; int pipe = 0; @@ -2202,7 +2229,9 @@ static void testUtilBwippCvtGS1Data(char *bwipp_data, int upcean, int *addon_pos } } -static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const char *data, int length, int zint_escape_mode, int eci, int *parse, int *parsefnc) { +/* Convert data to Ghostscript format for passing to bwipp_dump.ps */ +static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const char *data, int length, + int zint_escape_mode, int eci, int *parse, int *parsefnc) { char *b = bwipp_data; char *be = b + bwipp_data_size; unsigned char *d = (unsigned char *) data; @@ -2269,10 +2298,11 @@ static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const ch return bwipp_data; } +/* Convert ISBN to BWIPP format */ static void testUtilISBNHyphenate(char *bwipp_data, int addon_posn) { /* Hack in 4 hyphens in fixed format, wrong for many ISBNs */ char temp[13 + 4 + 1 + 5 + 1]; - int len = strlen(bwipp_data); + int len = (int) strlen(bwipp_data); int i, j; if (len < 13 || (addon_posn && addon_posn < 13 ) || len >= (int) sizeof(temp)) { @@ -2289,16 +2319,23 @@ static void testUtilISBNHyphenate(char *bwipp_data, int addon_posn) { #define GS_INITIAL_LEN 35 /* Length of cmd up to -q */ -int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size) { +/* Create bwipp_dump.ps command and run */ +int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, + const char *data, int length, const char *primary, char *buffer, int buffer_size) { const char *cmd_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' backend/tests/tools/bwipp_dump.ps"; - const char *cmd_opts_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' -so='%s' backend/tests/tools/bwipp_dump.ps"; - const char *cmd_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' backend/tests/tools/bwipp_dump.ps"; // If data > 2K - const char *cmd_opts_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' -so='%s' backend/tests/tools/bwipp_dump.ps"; + const char *cmd_opts_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' -so='%s'" + " backend/tests/tools/bwipp_dump.ps"; + // If data > 2K + const char *cmd_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s'" + " backend/tests/tools/bwipp_dump.ps"; + const char *cmd_opts_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' -so='%s'" + " backend/tests/tools/bwipp_dump.ps"; int symbology = symbol->symbology; int data_len = length == -1 ? (int) strlen(data) : length; int primary_len = primary ? (int) strlen(primary) : 0; - int max_data_len = 4 + primary_len + 1 + 1 + data_len * 4 + 64; /* 4 AI prefix + primary + '|' + leading zero + escaped data + fudge */ + /* 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); char *converted = (char *) testutil_alloca(eci_length + 1); @@ -2333,7 +2370,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int bwipp_barcode = testUtilBwippName(index, symbol, option_1, option_2, option_3, 0, &linear_row_height, &gs1_cvt); if (!bwipp_barcode) { - fprintf(stderr, "i:%d testUtilBwipp: no mapping for %s, option_1 %d, option_2 %d, option_3 %d\n", index, testUtilBarcodeName(symbology), option_1, option_2, option_3); + fprintf(stderr, "i:%d testUtilBwipp: no mapping for %s, option_1 %d, option_2 %d, option_3 %d\n", + index, testUtilBarcodeName(symbology), option_1, option_2, option_3); return -1; } @@ -2343,21 +2381,25 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } else { bwipp_row_height[r] = symbol->row_height[r] ? symbol->row_height[r] : linear_row_height; } - //fprintf(stderr, "bwipp_row_height[%d] %d, symbol->row_height[%d] %d\n", r, bwipp_row_height[r], r, symbol->row_height[r]); + /*fprintf(stderr, "bwipp_row_height[%d] %d, symbol->row_height[%d] %d\n", + r, bwipp_row_height[r], r, symbol->row_height[r]);*/ } - if ((symbol->input_mode & 0x07) == UNICODE_MODE && ZBarcode_Cap(symbology, ZINT_CAP_ECI) && is_eci_convertible(symbol->eci)) { + if ((symbol->input_mode & 0x07) == UNICODE_MODE && ZBarcode_Cap(symbology, ZINT_CAP_ECI) + && is_eci_convertible(symbol->eci)) { if (utf8_to_eci(symbol->eci, (const unsigned char *) data, (unsigned char *) converted, &data_len) == 0) { eci = symbol->eci; } else { if (symbol->eci != 0) { eci = get_best_eci((const unsigned char *) data, data_len); if (utf8_to_eci(eci, (const unsigned char *) data, (unsigned char *) converted, &data_len) != 0) { - fprintf(stderr, "i:%d testUtilBwipp: failed to convert Unicode data for %s\n", index, testUtilBarcodeName(symbology)); + fprintf(stderr, "i:%d testUtilBwipp: failed to convert Unicode data for %s\n", + index, testUtilBarcodeName(symbology)); return -1; } } else { - fprintf(stderr, "i:%d testUtilBwipp: failed to convert Unicode data for %s\n", index, testUtilBarcodeName(symbology)); + fprintf(stderr, "i:%d testUtilBwipp: failed to convert Unicode data for %s\n", + index, testUtilBarcodeName(symbology)); return -1; } } @@ -2384,18 +2426,21 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int bwipp_barcode = "ean8composite"; } if (addon_posn) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%saddongap=%d", strlen(bwipp_opts_buf) ? " " : "", option_2 > 0 ? option_2 : upca ? 9 : 7); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%saddongap=%d", + strlen(bwipp_opts_buf) ? " " : "", option_2 > 0 ? option_2 : upca ? 9 : 7); bwipp_opts = bwipp_opts_buf; } bwipp_row_height[symbol->rows - 1] = 72; } if (option_1 > 0) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sccversion=%c", strlen(bwipp_opts_buf) ? " " : "", option_1 == 1 ? 'a' : option_1 == 2 ? 'b' : 'c'); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sccversion=%c", + strlen(bwipp_opts_buf) ? " " : "", option_1 == 1 ? 'a' : option_1 == 2 ? 'b' : 'c'); bwipp_opts = bwipp_opts_buf; } if (option_2 > 0) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%ssegments=%d", strlen(bwipp_opts_buf) ? " " : "", option_2 * 2); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%ssegments=%d", + strlen(bwipp_opts_buf) ? " " : "", option_2 * 2); bwipp_opts = bwipp_opts_buf; } } else { @@ -2407,51 +2452,58 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int testUtilBwippCvtGS1Data(bwipp_data, upcean, &addon_posn); if (upcean) { - if ((symbology == BARCODE_EANX || symbology == BARCODE_EANX_CHK) && (data_len <= 8 || (addon_posn && addon_posn <= 8))) { + if ((symbology == BARCODE_EANX || symbology == BARCODE_EANX_CHK) + && (data_len <= 8 || (addon_posn && addon_posn <= 8))) { bwipp_barcode = data_len <= 3 ? "ean2" : data_len <= 5 ? "ean5" : "ean8"; } if (symbology == BARCODE_ISBNX) { testUtilISBNHyphenate(bwipp_data, addon_posn); } if (addon_posn) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%saddongap=%d", strlen(bwipp_opts_buf) ? " " : "", option_2 > 0 ? option_2 : upca ? 9 : 7); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%saddongap=%d", + strlen(bwipp_opts_buf) ? " " : "", option_2 > 0 ? option_2 : upca ? 9 : 7); bwipp_opts = bwipp_opts_buf; } } if (option_2 > 0) { if (symbology == BARCODE_DBAR_EXP || symbology == BARCODE_DBAR_EXPSTK) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%ssegments=%d", strlen(bwipp_opts_buf) ? " " : "", option_2 * 2); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%ssegments=%d", + strlen(bwipp_opts_buf) ? " " : "", option_2 * 2); bwipp_opts = bwipp_opts_buf; } } } else { - if (testUtilBwippEscape(bwipp_data, bwipp_data_size, data, data_len, symbol->input_mode & ESCAPE_MODE, eci, &parse, &parsefnc) == NULL) { + if (testUtilBwippEscape(bwipp_data, bwipp_data_size, data, data_len, symbol->input_mode & ESCAPE_MODE, + eci, &parse, &parsefnc) == NULL) { return -1; } if (parse) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sparse", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sparse", strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } if (parsefnc) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sparsefnc", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sparsefnc", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } if (symbology == BARCODE_C25STANDARD || symbology == BARCODE_C25INTER || symbology == BARCODE_C25IATA || symbology == BARCODE_C25LOGIC || symbology == BARCODE_C25IND) { if (option_2 == 1 || option_2 == 2) { // Add check digit without or with HRT suppression - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sincludecheck", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } } else if (symbology == BARCODE_CODE93) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sincludecheck", + strlen(bwipp_opts_buf) ? " " : ""); if (parse) { bwipp_barcode = "code93ext"; } bwipp_opts = bwipp_opts_buf; } else if (symbology == BARCODE_PZN) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%spzn8", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%spzn8", strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } else if (symbology == BARCODE_TELEPEN_NUM) { if (data_len & 1) { // Add leading zero @@ -2459,30 +2511,36 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int *bwipp_data = '0'; } } else if (symbology == BARCODE_CODABLOCKF || symbology == BARCODE_HIBC_BLOCKF) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%ssepheight=0", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%ssepheight=0", strlen(bwipp_opts_buf) ? " " : ""); if (option_1 > 0) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%srows=%d", strlen(bwipp_opts_buf) ? " " : "", option_1); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%srows=%d", + strlen(bwipp_opts_buf) ? " " : "", option_1); } if (option_2 > 0) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%scolumns=%d", strlen(bwipp_opts_buf) ? " " : "", option_2 - 5); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%scolumns=%d", + strlen(bwipp_opts_buf) ? " " : "", option_2 - 5); } else { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%scolumns=%d", strlen(bwipp_opts_buf) ? " " : "", (symbol->width - 57) / 11); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%scolumns=%d", + strlen(bwipp_opts_buf) ? " " : "", (symbol->width - 57) / 11); } bwipp_opts = bwipp_opts_buf; - } else if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39 || symbology == BARCODE_LOGMARS || symbology == BARCODE_CODABAR) { + } else if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39 + || symbology == BARCODE_LOGMARS || symbology == BARCODE_CODABAR) { if (option_2 > 0) { if (option_2 == 1) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sincludecheck", + strlen(bwipp_opts_buf) ? " " : ""); } bwipp_opts = bwipp_opts_buf; /* Set always as option_2 == 2 is bwipp default */ } } else if (symbology == BARCODE_PLESSEY) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } else if (symbology == BARCODE_MSI_PLESSEY) { if (option_2 > 0) { const char *checktype = NULL; - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sincludecheck", + strlen(bwipp_opts_buf) ? " " : ""); if (option_2 >= 11 && option_2 <= 16) { option_2 -= 10; /* Remove no-check indicator */ @@ -2499,23 +2557,28 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int checktype = "ncrmod1110 badmod11"; } if (checktype) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%schecktype=%s", strlen(bwipp_opts_buf) ? " " : "", checktype); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%schecktype=%s", + strlen(bwipp_opts_buf) ? " " : "", checktype); } bwipp_opts = bwipp_opts_buf; } } else if (symbology == BARCODE_PDF417 || symbology == BARCODE_PDF417COMP || symbology == BARCODE_HIBC_PDF - || symbology == BARCODE_MICROPDF417 || symbology == BARCODE_HIBC_MICPDF) { + || symbology == BARCODE_MICROPDF417 || symbology == BARCODE_HIBC_MICPDF) { for (r = 0; r < symbol->rows; r++) bwipp_row_height[r] = 1; /* Change from 3 */ if (option_1 >= 0) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%seclevel=%d", strlen(bwipp_opts_buf) ? " " : "", option_1); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%seclevel=%d", + strlen(bwipp_opts_buf) ? " " : "", option_1); bwipp_opts = bwipp_opts_buf; } if (option_2 > 0) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%scolumns=%d", strlen(bwipp_opts_buf) ? " " : "", option_2); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%scolumns=%d", + strlen(bwipp_opts_buf) ? " " : "", option_2); bwipp_opts = bwipp_opts_buf; } - } else if (symbology == BARCODE_POSTNET || symbology == BARCODE_PLANET || symbology == BARCODE_RM4SCC || symbology == BARCODE_JAPANPOST || symbology == BARCODE_KIX - || symbology == BARCODE_DAFT || symbology == BARCODE_USPS_IMAIL || symbology == BARCODE_AUSPOST || symbology == BARCODE_PHARMA_TWO) { + } else if (symbology == BARCODE_POSTNET || symbology == BARCODE_PLANET || symbology == BARCODE_RM4SCC + || symbology == BARCODE_JAPANPOST || symbology == BARCODE_KIX || symbology == BARCODE_DAFT + || symbology == BARCODE_USPS_IMAIL || symbology == BARCODE_AUSPOST + || symbology == BARCODE_PHARMA_TWO) { for (r = 0; r < symbol->rows; r++) bwipp_row_height[r] = 1; /* Zap */ if (symbology == BARCODE_KIX) { to_upper((unsigned char *) bwipp_data); @@ -2531,13 +2594,15 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } else if (data_len == 13 || data_len == 16) { prefix = "59"; if (data_len == 16) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%scustinfoenc=numeric", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%scustinfoenc=numeric", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } } else { prefix = "62"; if (data_len == 23) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%scustinfoenc=numeric", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%scustinfoenc=numeric", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } } @@ -2548,7 +2613,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int strcpy(bwipp_data, "fima"); bwipp_data[3] = data[0] - 'A' + 'a'; } else if (symbology == BARCODE_CODE16K || symbology == BARCODE_CODE49) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%ssepheight=0", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%ssepheight=0", strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } else if (symbology == BARCODE_AZTEC || symbology == BARCODE_HIBC_AZTEC) { int compact = 0, full = 0; @@ -2563,7 +2628,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } else { eclevel = 50; } - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%seclevel=%d", strlen(bwipp_opts_buf) ? " " : "", eclevel); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%seclevel=%d", + strlen(bwipp_opts_buf) ? " " : "", eclevel); bwipp_opts = bwipp_opts_buf; } if (option_2 >= 1) { @@ -2575,37 +2641,43 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int layers = option_2 - 4; full = layers <= 4; } - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%slayers=%d", strlen(bwipp_opts_buf) ? " " : "", layers); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%slayers=%d", + strlen(bwipp_opts_buf) ? " " : "", layers); bwipp_opts = bwipp_opts_buf; } if (symbol->output_options & READER_INIT) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sreaderinit", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sreaderinit", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } if (symbology == BARCODE_HIBC_AZTEC) { compact = 1; } if (compact || full) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sformat=%s", strlen(bwipp_opts_buf) ? " " : "", compact ? "compact" : "full"); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sformat=%s", + strlen(bwipp_opts_buf) ? " " : "", compact ? "compact" : "full"); bwipp_opts = bwipp_opts_buf; } } else if (symbology == BARCODE_CODEONE) { if ((symbol->input_mode & 0x07) == GS1_MODE) { /* Hack pseudo-GS1 support */ int last_ai, ai_latch = 0; - for (i = 0, j = 0, len = (int) strlen(bwipp_data); i <= len; i++) { /* Reduce square brackets (include NUL) */ + /* Reduce square brackets (include NUL) */ + for (i = 0, j = 0, len = (int) strlen(bwipp_data); i <= len; i++) { if (bwipp_data[i] == obracket) { if (ai_latch == 0) { bwipp_data[j++] = '['; } last_ai = atoi(bwipp_data + i + 1); - 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) { + 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; } } else if (bwipp_data[i] != cbracket) { bwipp_data[j++] = bwipp_data[i]; } } - for (len = (int) strlen(bwipp_data), i = len - 1; i >= 0; i--) { /* Replace square brackets with ^FNC1 */ + /* Replace square brackets with ^FNC1 */ + for (len = (int) strlen(bwipp_data), i = len - 1; i >= 0; i--) { if (bwipp_data[i] == '[') { memmove(bwipp_data + i + 5, bwipp_data + i + 1, len - i); memcpy(bwipp_data + i, "^FNC1", 5); @@ -2613,7 +2685,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } } if (symbol->eci == 0) { /* If not already done for ECI */ - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sparsefnc", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sparsefnc", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } } @@ -2623,11 +2696,13 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int if (option_2 == 9) { codeone_version = length <= 6 ? "S-10" : length <= 12 ? "S-20" : "S-30"; } else if (option_2 == 10) { - codeone_version = length <= 22 ? "T-16" : length <= 34 ? "T-32" : "T-48"; // TODO: Properly allow for different T sizes + // TODO: Properly allow for different T sizes + codeone_version = length <= 22 ? "T-16" : length <= 34 ? "T-32" : "T-48"; } else { codeone_version = codeone_versions[option_2 - 1]; } - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sversion=%s", strlen(bwipp_opts_buf) ? " " : "", codeone_version); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sversion=%s", + strlen(bwipp_opts_buf) ? " " : "", codeone_version); bwipp_opts = bwipp_opts_buf; } } else if (symbology == BARCODE_MAXICODE) { @@ -2638,7 +2713,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int mode = 4; } else { for (i = 0; i < primary_len - 6; i++) { - if (((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) && (symbol->primary[i] != ' ')) { + if (((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) + && (symbol->primary[i] != ' ')) { mode = 3; break; } @@ -2646,7 +2722,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } } if (mode > 0) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%smode=%d", strlen(bwipp_opts_buf) ? " " : "", mode); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%smode=%d", + strlen(bwipp_opts_buf) ? " " : "", mode); bwipp_opts = bwipp_opts_buf; } if (primary_len) { @@ -2669,7 +2746,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int postcode[i] = ' '; } } - sprintf(prefix_buf, "%s^029%.3s^029%.3s^029", postcode, primary + primary_len - 6, primary + primary_len - 3); + sprintf(prefix_buf, "%s^029%.3s^029%.3s^029", + postcode, primary + primary_len - 6, primary + primary_len - 3); prefix_len = (int) strlen(prefix_buf); if (have_scm) { memmove(bwipp_data + 15 + prefix_len, bwipp_data, strlen(bwipp_data) - 15 + 1); @@ -2679,7 +2757,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int memcpy(bwipp_data, prefix_buf, prefix_len); } if (!parse) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sparse", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sparse", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; parse = 1; } @@ -2690,7 +2769,8 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int memmove(bwipp_data + 15, bwipp_data, strlen(bwipp_data) + 1); memcpy(bwipp_data, scm_vv_buf, 15); if (!parse) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sparse", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sparse", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; parse = 1; } @@ -2705,24 +2785,26 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int (void)isDMRE; (void)text_value; (void)text_shift; (void)c40_value; (void)c40_shift; if (symbol->output_options & GS1_GS_SEPARATOR) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sgssep", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sgssep", strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } if (option_2 >= 1 && option_2 <= (int) sizeof(intsymbol)) { int idx = intsymbol[option_2 - 1]; - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%srows=%d columns=%d", strlen(bwipp_opts_buf) ? " " : "", matrixH[idx], matrixW[idx]); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%srows=%d columns=%d", + strlen(bwipp_opts_buf) ? " " : "", matrixH[idx], matrixW[idx]); bwipp_opts = bwipp_opts_buf; if (option_2 >= 31) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sdmre", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sdmre", strlen(bwipp_opts_buf) ? " " : ""); added_dmre = 1; } } if (option_3 != DM_SQUARE && symbol->width != symbol->height) { if (option_3 == DM_DMRE && !added_dmre) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sdmre", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sdmre", strlen(bwipp_opts_buf) ? " " : ""); added_dmre = 1; } - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sformat=rectangle", strlen(bwipp_opts_buf) ? " " : ""); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sformat=rectangle", + strlen(bwipp_opts_buf) ? " " : ""); bwipp_opts = bwipp_opts_buf; } if (option_3 != -1) { @@ -2730,13 +2812,15 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } } else if (symbology == BARCODE_DOTCODE) { if (option_2 > 0) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%scolumns=%d", strlen(bwipp_opts_buf) ? " " : "", symbol->option_2); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%scolumns=%d", + strlen(bwipp_opts_buf) ? " " : "", symbol->option_2); bwipp_opts = bwipp_opts_buf; } if (option_3 != -1) { user_mask = (option_3 >> 8) & 0x0F; /* User mask is pattern + 1, so >= 1 and <= 8 */ if (user_mask >= 1 && user_mask <= 8) { - sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%smask=%d", strlen(bwipp_opts_buf) ? " " : "", (user_mask - 1) % 4); + sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%smask=%d", + strlen(bwipp_opts_buf) ? " " : "", (user_mask - 1) % 4); bwipp_opts = bwipp_opts_buf; } } @@ -2744,7 +2828,9 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int } if ((option_1 != -1 || option_2 != -1 || option_3 != -1) && !bwipp_opts) { - fprintf(stderr, "i:%d testUtilBwipp: no BWIPP options set option_1 %d, option_2 %d, option_3 %d for symbology %s\n", index, option_1, option_2, option_3, testUtilBarcodeName(symbology)); + fprintf(stderr, + "i:%d testUtilBwipp: no BWIPP options set option_1 %d, option_2 %d, option_3 %d for symbology %s\n", + index, option_1, option_2, option_3, testUtilBarcodeName(symbology)); return -1; } @@ -2769,14 +2855,16 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); } - if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39 || symbology == BARCODE_CODABAR - || symbology == BARCODE_PHARMA || symbology == BARCODE_PZN || symbology == BARCODE_CODE32 || symbology == BARCODE_VIN) { + if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39 + || symbology == BARCODE_CODABAR || symbology == BARCODE_PHARMA || symbology == BARCODE_PZN + || symbology == BARCODE_CODE32 || symbology == BARCODE_VIN) { /* Ratio 3 width bar/space -> 2 width */ char adj[8] = " -sr=0.6"; memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); } - if (symbology == BARCODE_C25INTER || symbology == BARCODE_DPLEIT || symbology == BARCODE_DPIDENT || symbology == BARCODE_ITF14) { + if (symbology == BARCODE_C25INTER || symbology == BARCODE_DPLEIT || symbology == BARCODE_DPIDENT + || symbology == BARCODE_ITF14) { /* Ratio 2 width bar/space -> 3 width */ char adj[8] = " -sr=1.3"; memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); @@ -2794,10 +2882,11 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); } - if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39 || symbology == BARCODE_HIBC_39 - || symbology == BARCODE_LOGMARS || symbology == BARCODE_PHARMA || symbology == BARCODE_PZN || symbology == BARCODE_CODE32 || symbology == BARCODE_VIN - || symbology == BARCODE_C25INTER || symbology == BARCODE_DPLEIT || symbology == BARCODE_DPIDENT || symbology == BARCODE_ITF14 - || symbology == BARCODE_PHARMA_TWO) { + if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39 + || symbology == BARCODE_HIBC_39 || symbology == BARCODE_LOGMARS || symbology == BARCODE_PHARMA + || symbology == BARCODE_PZN || symbology == BARCODE_CODE32 || symbology == BARCODE_VIN + || symbology == BARCODE_C25INTER || symbology == BARCODE_DPLEIT || symbology == BARCODE_DPIDENT + || symbology == BARCODE_ITF14 || symbology == BARCODE_PHARMA_TWO) { /* End sbs loop on bar */ char adj[6] = " -selb"; memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); @@ -2809,8 +2898,9 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); } - if (symbology == BARCODE_POSTNET || symbology == BARCODE_PLANET || symbology == BARCODE_RM4SCC || symbology == BARCODE_JAPANPOST || symbology == BARCODE_KIX - || symbology == BARCODE_DAFT || symbology == BARCODE_USPS_IMAIL || symbology == BARCODE_AUSPOST || symbology == BARCODE_PHARMA_TWO) { + if (symbology == BARCODE_POSTNET || symbology == BARCODE_PLANET || symbology == BARCODE_RM4SCC + || symbology == BARCODE_JAPANPOST || symbology == BARCODE_KIX || symbology == BARCODE_DAFT + || symbology == BARCODE_USPS_IMAIL || symbology == BARCODE_AUSPOST || symbology == BARCODE_PHARMA_TWO) { /* Emulate rows with BWIPP heights. */ char adj[5] = " -shs"; memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); @@ -2834,21 +2924,25 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int for (r = 0; r < symbol->rows; r++) { if (b + symbol->width > be) { - fprintf(stderr, "i:%d testUtilBwipp: row %d, width %d, row width iteration overrun (%s)\n", index, r, symbol->width, cmd); + fprintf(stderr, "i:%d testUtilBwipp: row %d, width %d, row width iteration overrun (%s)\n", + index, r, symbol->width, cmd); testutil_pclose(fp); return -1; } - cnt = fread(b, 1, symbol->width, fp); + cnt = (int) fread(b, 1, symbol->width, fp); if (cnt != symbol->width) { - fprintf(stderr, "i:%d testUtilBwipp: failed to read symbol->width %d bytes, cnt %d (%s)\n", index, symbol->width, cnt, cmd); + fprintf(stderr, "i:%d testUtilBwipp: failed to read symbol->width %d bytes, cnt %d (%s)\n", + index, symbol->width, cnt, cmd); testutil_pclose(fp); return -1; } b += cnt; for (h = bwipp_row_height[r]; h > 1; h--) { /* Ignore row copies if any */ - cnt = fread(b, 1, symbol->width, fp); + cnt = (int) fread(b, 1, symbol->width, fp); if (cnt != symbol->width) { - fprintf(stderr, "i:%d testUtilBwipp: failed to read/ignore symbol->width %d bytes, cnt %d, h %d, bwipp_row_height[%d] %d, symbol->row_height[%d] %g (%s)\n", + fprintf(stderr, + "i:%d testUtilBwipp: failed to read/ignore symbol->width %d bytes, cnt %d, h %d" + ", bwipp_row_height[%d] %d, symbol->row_height[%d] %g (%s)\n", index, symbol->width, cnt, h, r, bwipp_row_height[r], r, symbol->row_height[r], cmd); testutil_pclose(fp); return -1; @@ -2868,9 +2962,10 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int return 0; } +/* Compare bwipp_dump.ps output to test suite module dump */ int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, const char *bwipp_buf, const char *expected) { - int bwipp_len = strlen(bwipp_buf); - int expected_len = strlen(expected); + int bwipp_len = (int) strlen(bwipp_buf); + int expected_len = (int) strlen(expected); int ret_memcmp; int i; @@ -2895,9 +2990,11 @@ int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, const char *bw return 0; } -int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *bwipp_buf, const char *expected) { - int bwipp_len = strlen(bwipp_buf); - int expected_len = strlen(expected); +/* Compare bwipp_dump.ps output to single row module dump (see testUtilModulesPrintRow) */ +int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *bwipp_buf, + const char *expected) { + int bwipp_len = (int) strlen(bwipp_buf); + int expected_len = (int) strlen(expected); int ret_memcmp; int i, j; diff --git a/backend/tests/testcommon.h b/backend/tests/testcommon.h index b508d49d..3e017770 100644 --- a/backend/tests/testcommon.h +++ b/backend/tests/testcommon.h @@ -70,20 +70,19 @@ extern "C" { #endif #ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0]))) #endif extern int assertionFailed; extern int assertionNum; +extern const char *assertionFilename; #if _MSC_VER == 1200 /* VC6 */ #define testStart(__arg__) (testStartReal("", __arg__)) #else #define testStart(__arg__) (testStartReal(__func__, __arg__)) #endif -#define testEndExp(__arg__) (testEnd(!(__arg__))) void testStartReal(const char *func, const char *name); -void testEnd(int result); void testFinish(void); void testSkip(const char *msg); void testReport(); @@ -104,7 +103,8 @@ void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...); void assert_notequal(int e1, int e2, ...); #else #define assert_exp(__exp__, ...) \ -{assertionNum++; if (!(__exp__)) {assertionFailed++; printf(__VA_ARGS__); testFinish(); return;}} + { assertionNum++; if (!(__exp__)) { assertionFailed++; printf("%s:%d ", assertionFilename, __LINE__); \ + printf(__VA_ARGS__); testFinish(); return; } } #define assert_zero(__exp__, ...) assert_exp((__exp__) == 0, __VA_ARGS__) #define assert_nonzero(__exp__, ...) assert_exp((__exp__) != 0, __VA_ARGS__) @@ -119,40 +119,47 @@ INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci, int option_1, int option_2, int option_3, int output_options, char *data, int length, int debug); + const char *testUtilBarcodeName(int symbology); const char *testUtilErrorName(int error_number); const char *testUtilInputModeName(int input_mode); const char *testUtilOption3Name(int option_3); const char *testUtilOutputOptionsName(int output_options); + int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size); int testUtilIsValidUTF8(const unsigned char str[], const int length); char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size); char *testUtilReadCSVField(char *buffer, char *field, int field_size); void testUtilStrCpyRepeat(char *buffer, char *repeat, int size); + int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b); struct zint_vector *testUtilVectorCpy(const struct zint_vector *in); int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b); + int testUtilModulesDump(const struct zint_symbol *symbol, char dump[], int dump_size); void testUtilModulesPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix); void testUtilModulesPrintRow(const struct zint_symbol *symbol, int row, const char *prefix, const char *postfix); int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, int *width, int *row); int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char *expected, int *width); -int testUtilModulesDumpHex(const struct zint_symbol *symbol, char dump[], int dump_size); char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_size); char *testUtilUCharArrayDump(unsigned char *array, int size, char *dump, int dump_size); -int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const char *filename); + void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix); int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column); + +int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const char *filename); int testUtilExists(const char *filename); int testUtilDirExists(const char *dirname); int testUtilMkDir(const char *dirname); int testUtilRmDir(const char *dirname); int testUtilRename(const char *oldpath, const char *newpath); + int testUtilCmpPngs(const char *file1, const char *file2); int testUtilCmpTxts(const char *txt1, const char *txt2); int testUtilCmpBins(const char *bin1, const char *bin2); int testUtilCmpSvgs(const char *svg1, const char *svg2); int testUtilCmpEpss(const char *eps1, const char *eps2); + int testUtilHaveIdentify(); int testUtilVerifyIdentify(const char *filename, int debug); int testUtilHaveLibreOffice(); @@ -163,6 +170,7 @@ int testUtilHaveVnu(); int testUtilVerifyVnu(const char *filename, int debug); int testUtilHaveTiffInfo(); int testUtilVerifyTiffInfo(const char *filename, int debug); + int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug); int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, diff --git a/backend/upcean.c b/backend/upcean.c index 800e533e..4e51e625 100644 --- a/backend/upcean.c +++ b/backend/upcean.c @@ -30,12 +30,16 @@ */ /* vim: set ts=4 sw=4 et : */ -#define SODIUM "0123456789+" +#define SODIUM "0123456789+" +#define ISBN_SANE "0123456789X" +#define ISBN_CC_SANE "0123456789Xx+" + #define EAN2 102 #define EAN5 105 #include #include "common.h" +#include "gs1.h" /* UPC and EAN tables checked against EN 797:1996 */ @@ -78,65 +82,44 @@ static const char *EANsetB[10] = { "1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121", "2113" }; -/* Calculate the correct check digit for a UPC barcode */ -static char upc_check(const char source[], const int length) { - int i, count, check_digit; - - count = 0; - - for (i = 0; i < length; i++) { - count += (i & 1) ? ctoi(source[i]) : 3 * ctoi(source[i]); - } - - check_digit = 10 - (count % 10); - if (check_digit == 10) { - check_digit = 0; - } - return itoc(check_digit); -} - /* UPC A is usually used for 12 digit numbers, but this function takes a source of any length */ -static void upca_draw(const char source[], const int length, unsigned char dest[]) { +static void upca_draw(const unsigned char source[], const int length, char dest[]) { int i, half_way; half_way = length / 2; /* start character */ - ustrcat(dest, "111"); + strcat(dest, "111"); for (i = 0; i < length; i++) { if (i == half_way) { /* middle character - separates manufacturer no. from product no. */ /* also inverts right hand characters */ - ustrcat(dest, "11111"); + strcat(dest, "11111"); } - lookup(NEON, EANsetA, source[i], (char *) dest); + lookup(NEON, EANsetA, source[i], dest); } /* stop character */ - ustrcat(dest, "111"); + strcat(dest, "111"); } /* Make a UPC-A barcode, allowing for composite if `cc_rows` set */ -static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[], - int cc_rows) { - char gtin[13]; +static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) { + unsigned char gtin[13]; float height; int error_number = 0; ustrcpy(gtin, source); if (length == 11) { - gtin[length++] = upc_check(gtin, 11); + gtin[length++] = gs1_check_digit(gtin, 11); gtin[length] = '\0'; } else { - if (source[length - 1] != upc_check(gtin, 11)) { - if (symbol->debug & ZINT_DEBUG_PRINT) { - printf("UPC-A: Invalid check digit %s, gtin: %s, Check digit: %c\n", source, gtin, - upc_check(gtin, 11)); - } - strcpy(symbol->errtxt, "270: Invalid check digit"); + if (source[length - 1] != gs1_check_digit(gtin, 11)) { + sprintf(symbol->errtxt, "270: Invalid check digit '%c', expecting '%c'", + source[length - 1], gs1_check_digit(gtin, 11)); return ZINT_ERROR_INVALID_CHECK; } } @@ -170,15 +153,15 @@ static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int } /* UPC-A */ -static int upca(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[]) { +static int upca(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[]) { return upca_cc(symbol, source, length, dest, 0 /*cc_rows*/); } /* UPC-E, allowing for composite if `cc_rows` set */ -static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int length, unsigned char dest[], - int cc_rows) { +static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int length, char dest[], int cc_rows) { int i, num_system; - char emode, equivalent[12], check_digit, parity[8]; + char emode, check_digit, parity[8]; + unsigned char equivalent[12]; char hrt[9]; float height; int error_number = 0; @@ -234,7 +217,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" */ - strcpy(symbol->errtxt, "271: Invalid UPC-E data"); + strcpy(symbol->errtxt, "271: Invalid UPC-E data"); // TODO: Better error message return ZINT_ERROR_INVALID_DATA; } break; @@ -244,7 +227,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" */ - strcpy(symbol->errtxt, "272: Invalid UPC-E data"); + strcpy(symbol->errtxt, "272: Invalid UPC-E data"); // TODO: Better error message return ZINT_ERROR_INVALID_DATA; } break; @@ -259,7 +242,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" */ - strcpy(symbol->errtxt, "273: Invalid UPC-E data"); + strcpy(symbol->errtxt, "273: Invalid UPC-E data"); // TODO: Better error message return ZINT_ERROR_INVALID_DATA; } break; @@ -267,7 +250,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt /* Get the check digit from the expanded UPCA code */ - check_digit = upc_check(equivalent, 11); + check_digit = gs1_check_digit(equivalent, 11); /* Use the number system and check digit information to choose a parity scheme */ if (num_system == 1) { @@ -279,30 +262,26 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt /* Take all this information and make the barcode pattern */ /* start character */ - ustrcat(dest, "111"); + strcat(dest, "111"); for (i = 0; i < length; i++) { switch (parity[i]) { - case 'A': lookup(NEON, EANsetA, source[i], (char *) dest); + case 'A': lookup(NEON, EANsetA, source[i], dest); break; - case 'B': lookup(NEON, EANsetB, source[i], (char *) dest); + case 'B': lookup(NEON, EANsetB, source[i], dest); break; } } /* stop character */ - ustrcat(dest, "111111"); + strcat(dest, "111111"); if (symbol->symbology != BARCODE_UPCE_CHK) { hrt[7] = check_digit; hrt[8] = '\0'; } else { if (hrt[7] != check_digit) { - if (symbol->debug & ZINT_DEBUG_PRINT) { - printf("UPC-E: Invalid check digit %s, equivalent: %s, hrt: %s, Check digit: %c\n", source, - equivalent, hrt, check_digit); - } - strcpy(symbol->errtxt, "274: Invalid check digit"); + sprintf(symbol->errtxt, "274: Invalid check digit '%c', expecting '%c'", hrt[7], check_digit); return ZINT_ERROR_INVALID_CHECK; } } @@ -334,24 +313,24 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt } /* UPC-E is a zero-compressed version of UPC-A */ -static int upce(struct zint_symbol *symbol, unsigned char source[], int length, unsigned char dest[]) { +static int upce(struct zint_symbol *symbol, unsigned char source[], int length, char dest[]) { return upce_cc(symbol, source, length, dest, 0 /*cc_rows*/); } /* EAN-2 and EAN-5 add-on codes */ -static void add_on(const unsigned char source[], const int length, unsigned char dest[], const int addon_gap) { +static void ean_add_on(const unsigned char source[], const int length, char dest[], const int addon_gap) { char parity[6]; int i, code_type; /* If an add-on then append with space */ if (addon_gap != 0) { - i = (int) ustrlen(dest); + i = (int) strlen(dest); dest[i] = itoc(addon_gap); dest[i + 1] = '\0'; } /* Start character */ - ustrcat(dest, "112"); + strcat(dest, "112"); /* Determine EAN2 or EAN5 add-on */ if (length == 2) { @@ -385,43 +364,26 @@ static void add_on(const unsigned char source[], const int length, unsigned char for (i = 0; i < length; i++) { switch (parity[i]) { - case 'A': lookup(NEON, EANsetA, source[i], (char *) dest); + case 'A': lookup(NEON, EANsetA, source[i], dest); break; - case 'B': lookup(NEON, EANsetB, source[i], (char *) dest); + case 'B': lookup(NEON, EANsetB, source[i], dest); break; } /* Glyph separator */ if (i != (length - 1)) { - ustrcat(dest, "11"); + strcat(dest, "11"); } } } /* ************************ EAN-13 ****************** */ -/* Calculate the correct check digit for a EAN-13 barcode (including ISBN(13)) */ -static char ean_check(const char source[], const int length) { - int i; - int count, check_digit; - - count = 0; - - for (i = 0; i < length; i++) { - count += (i & 1) ? 3 * ctoi(source[i]) : ctoi(source[i]); - } - check_digit = 10 - (count % 10); - if (check_digit == 10) { - check_digit = 0; - } - return itoc(check_digit); -} - -static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[], +static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) { int i, half_way; char parity[6]; - char gtin[14]; + unsigned char gtin[14]; float height; int error_number = 0; @@ -431,15 +393,12 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in /* Add the appropriate check digit */ if (length == 12) { - gtin[length++] = ean_check(gtin, 12); + gtin[length++] = gs1_check_digit(gtin, 12); gtin[length] = '\0'; } else { - if (source[length - 1] != ean_check(gtin, 12)) { - if (symbol->debug & ZINT_DEBUG_PRINT) { - printf("EAN-13 Invalid check digit: %s, gtin: %s, Check digit: %c\n", source, gtin, - ean_check(gtin, 12)); - } - strcpy(symbol->errtxt, "275: Invalid check digit"); + if (source[length - 1] != gs1_check_digit(gtin, 12)) { + sprintf(symbol->errtxt, "275: Invalid check digit '%c', expecting '%c'", + source[length - 1], gs1_check_digit(gtin, 12)); return ZINT_ERROR_INVALID_CHECK; } } @@ -454,23 +413,23 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in half_way = 7; /* start character */ - ustrcat(dest, "111"); + strcat(dest, "111"); for (i = 1; i < length; i++) { if (i == half_way) { /* middle character - separates manufacturer no. from product no. */ /* also inverses right hand characters */ - ustrcat(dest, "11111"); + strcat(dest, "11111"); } if (((i > 1) && (i < 7)) && (parity[i - 2] == 'B')) { - lookup(NEON, EANsetB, gtin[i], (char *) dest); + lookup(NEON, EANsetB, gtin[i], dest); } else { - lookup(NEON, EANsetA, gtin[i], (char *) dest); + lookup(NEON, EANsetA, gtin[i], dest); } } /* stop character */ - ustrcat(dest, "111"); + strcat(dest, "111"); ustrcpy(symbol->text, gtin); #ifdef COMPLIANT_HEIGHTS @@ -494,29 +453,25 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in return error_number; } -static int ean13(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[]) { +static int ean13(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[]) { return ean13_cc(symbol, source, length, dest, 0 /*cc_rows*/); } -static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[], - int cc_rows) { +static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) { /* EAN-8 is basically the same as UPC-A but with fewer digits */ - char gtin[10]; + unsigned char gtin[10]; float height; int error_number = 0; ustrcpy(gtin, source); if (length == 7) { - gtin[length++] = upc_check(gtin, 7); + gtin[length++] = gs1_check_digit(gtin, 7); gtin[length] = '\0'; } else { - if (source[length - 1] != upc_check(gtin, 7)) { - if (symbol->debug & ZINT_DEBUG_PRINT) { - printf("EAN-8: Invalid check digit %s, gtin: %s, Check digit: %c\n", source, gtin, - upc_check(gtin, 7)); - } - strcpy(symbol->errtxt, "276: Invalid check digit"); + if (source[length - 1] != gs1_check_digit(gtin, 7)) { + sprintf(symbol->errtxt, "276: Invalid check digit '%c', expecting '%c'", + source[length - 1], gs1_check_digit(gtin, 7)); return ZINT_ERROR_INVALID_CHECK; } } @@ -550,7 +505,7 @@ static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int } /* Make an EAN-8 barcode when we haven't been given the check digit */ -static int ean8(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char dest[]) { +static int ean8(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[]) { return ean8_cc(symbol, source, length, dest, 0 /*cc_rows*/); } @@ -576,36 +531,34 @@ static char isbn_check(const unsigned char source[], const int length) { } /* Make an EAN-13 barcode from an SBN or ISBN */ -static int isbn(struct zint_symbol *symbol, unsigned char source[], const int src_len, unsigned char dest[]) { +static int isbn(struct zint_symbol *symbol, unsigned char source[], const int src_len, char dest[]) { int i, error_number; char check_digit; to_upper(source); - error_number = is_sane("0123456789X", source, src_len); + error_number = is_sane(ISBN_SANE, source, src_len); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "277: Invalid characters in input"); + sprintf(symbol->errtxt, "277: Invalid characters in data (\"%s\" only)", ISBN_SANE); return error_number; } /* Input must be 9, 10 or 13 characters */ if (src_len != 9 && src_len != 10 && src_len != 13) { - strcpy(symbol->errtxt, "278: Input wrong length"); + strcpy(symbol->errtxt, "278: Input wrong length (9, 10, or 13 characters only)"); return ZINT_ERROR_TOO_LONG; } if (src_len == 13) /* Using 13 character ISBN */ { if (!(((source[0] == '9') && (source[1] == '7')) && ((source[2] == '8') || (source[2] == '9')))) { - strcpy(symbol->errtxt, "279: Invalid ISBN"); + strcpy(symbol->errtxt, "279: Invalid ISBN (must begin with \"978\" or \"979\")"); return ZINT_ERROR_INVALID_DATA; } - check_digit = ean_check((const char *) source, 12); + check_digit = gs1_check_digit(source, 12); if (source[src_len - 1] != check_digit) { - if (symbol->debug & ZINT_DEBUG_PRINT) { - printf("ISBN: Invalid check digit %s, Check digit: %c\n", source, check_digit); - } - strcpy(symbol->errtxt, "280: Incorrect ISBN check"); + sprintf(symbol->errtxt, "280: Incorrect ISBN check '%c', expecting '%c'", + source[src_len - 1], check_digit); return ZINT_ERROR_INVALID_CHECK; } source[12] = '\0'; @@ -622,10 +575,8 @@ static int isbn(struct zint_symbol *symbol, unsigned char source[], const int sr if (src_len == 9 || src_len == 10) /* Using 10 digit ISBN or 9 digit SBN padded with leading zero */ { check_digit = isbn_check(source, 9); if (check_digit != source[9]) { - if (symbol->debug & ZINT_DEBUG_PRINT) { - printf("ISBN(10)/SBN: Invalid check digit %s, Check digit: %c\n", source, check_digit); - } - strcpy(symbol->errtxt, src_len == 9 ? "281: Incorrect SBN check" : "281: Incorrect ISBN check"); + sprintf(symbol->errtxt, "281: Incorrect %s check '%c', expecting '%c'", src_len == 9 ? "SBN" : "ISBN", + source[9], check_digit); return ZINT_ERROR_INVALID_CHECK; } for (i = 11; i > 2; i--) { @@ -782,8 +733,9 @@ INTERNAL int ean_leading_zeroes(struct zint_symbol *symbol, const unsigned char } INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src_len, int cc_rows) { - unsigned char first_part[14] = {0}, second_part[6] = {0}, dest[1000] = {0}; + unsigned char first_part[14] = {0}, second_part[6] = {0}; unsigned char local_source[20] = {0}; /* Allow 13 + "+" + 5 + 1 */ + char dest[1000] = {0}; int latch, reader, writer; int with_addon; int error_number, i, plus_count; @@ -795,20 +747,20 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src writer = 0; if (src_len > 19) { - strcpy(symbol->errtxt, "283: Input too long"); + strcpy(symbol->errtxt, "283: Input too long"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } if (symbol->symbology != BARCODE_ISBNX) { /* ISBN has its own checking routine */ - error_number = is_sane("0123456789+", source, src_len); + error_number = is_sane(SODIUM, source, src_len); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "284: Invalid characters in data"); + sprintf(symbol->errtxt, "284: Invalid characters in data (\"%s\" only)", SODIUM); return error_number; } } else { - error_number = is_sane("0123456789Xx+", source, src_len); + error_number = is_sane(ISBN_CC_SANE, source, src_len); if (error_number == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "285: Invalid characters in input"); + sprintf(symbol->errtxt, "285: Invalid characters in data (\"%s\" only)", ISBN_CC_SANE); return error_number; } } @@ -818,16 +770,16 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src for (i = 0; i < src_len; i++) { if (source[i] == '+') { plus_count++; + if (plus_count > 1) { + strcpy(symbol->errtxt, "293: Invalid add-on data (one \"+\" only)"); + return ZINT_ERROR_INVALID_DATA; + } } } - if (plus_count > 1) { - strcpy(symbol->errtxt, "293: Invalid add-on data"); - return ZINT_ERROR_INVALID_DATA; - } /* Add leading zeroes, checking max lengths of parts */ if (!ean_leading_zeroes(symbol, source, local_source, &with_addon)) { - strcpy(symbol->errtxt, "294: Input too long"); + strcpy(symbol->errtxt, "294: Input too long"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } @@ -869,7 +821,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src case BARCODE_EANX: case BARCODE_EANX_CHK: switch (first_part_len) { - case 2: add_on(first_part, first_part_len, dest, 0); + case 2: ean_add_on(first_part, first_part_len, dest, 0); ustrcpy(symbol->text, first_part); #ifdef COMPLIANT_HEIGHTS /* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-5 */ @@ -880,7 +832,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src (void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/); #endif break; - case 5: add_on(first_part, first_part_len, dest, 0); + case 5: ean_add_on(first_part, first_part_len, dest, 0); ustrcpy(symbol->text, first_part); #ifdef COMPLIANT_HEIGHTS /* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-6 */ @@ -897,7 +849,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src case 12: case 13: error_number = ean13(symbol, first_part, first_part_len, dest); break; - default: strcpy(symbol->errtxt, "286: Input wrong length"); + default: strcpy(symbol->errtxt, "286: Input wrong length"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } break; @@ -928,7 +880,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src symbol->rows += 3; error_number = ean13_cc(symbol, first_part, first_part_len, dest, cc_rows); break; - default: strcpy(symbol->errtxt, "287: Input wrong length"); + default: strcpy(symbol->errtxt, "287: Input wrong length"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } break; @@ -937,7 +889,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src if ((first_part_len == 11) || (first_part_len == 12)) { error_number = upca(symbol, first_part, first_part_len, dest); } else { - strcpy(symbol->errtxt, "288: Input wrong length"); + strcpy(symbol->errtxt, "288: Input wrong length"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } break; @@ -955,7 +907,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src symbol->rows += 3; error_number = upca_cc(symbol, first_part, first_part_len, dest, cc_rows); } else { - strcpy(symbol->errtxt, "289: Input wrong length"); + strcpy(symbol->errtxt, "289: Input wrong length"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } break; @@ -964,7 +916,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src if ((first_part_len >= 6) && (first_part_len <= (symbol->symbology == BARCODE_UPCE ? 7 : 8))) { error_number = upce(symbol, first_part, first_part_len, dest); } else { - strcpy(symbol->errtxt, "290: Input wrong length"); + strcpy(symbol->errtxt, "290: Input wrong length"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } break; @@ -982,7 +934,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src symbol->rows += 3; error_number = upce_cc(symbol, first_part, first_part_len, dest, cc_rows); } else { - strcpy(symbol->errtxt, "291: Input wrong length"); + strcpy(symbol->errtxt, "291: Input wrong length"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } break; @@ -1000,17 +952,17 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src switch (second_part_len) { case 0: break; case 2: - add_on(second_part, second_part_len, dest, addon_gap); + ean_add_on(second_part, second_part_len, dest, addon_gap); ustrcat(symbol->text, "+"); ustrcat(symbol->text, second_part); break; case 5: - add_on(second_part, second_part_len, dest, addon_gap); + ean_add_on(second_part, second_part_len, dest, addon_gap); ustrcat(symbol->text, "+"); ustrcat(symbol->text, second_part); break; default: - strcpy(symbol->errtxt, "292: Add-on input wrong length"); + strcpy(symbol->errtxt, "292: Add-on input wrong length"); // TODO: Better error message return ZINT_ERROR_TOO_LONG; } diff --git a/docs/manual.txt b/docs/manual.txt index 2c302e2e..b42d77cb 100644 --- a/docs/manual.txt +++ b/docs/manual.txt @@ -1114,7 +1114,7 @@ ZINT_ERROR_INVALID_DATA | The data to be encoded includes characters which | are not permitted by the selected symbology | (e.g. alphabetic characters in an EAN | symbol). No symbol has been generated. -ZINT_ERROR_INVALID_CHECK | An ISBN with an incorrect check digit has been +ZINT_ERROR_INVALID_CHECK | Data with an incorrect check digit has been | entered. No symbol has been generated. ZINT_ERROR_INVALID_OPTION | One of the values in zint_struct was set | incorrectly and Zint was unable to guess what @@ -1131,7 +1131,7 @@ ZINT_ERROR_MEMORY | Zint ran out of memory. This should only be a | problem with legacy systems. ZINT_ERROR_FILE_WRITE | Zint failed to write all contents to the | requested output file. This should only occur - | if the output disk becomes full. + | if the output device becomes full. -------------------------------------------------------------------------------- To catch errors use an integer variable as shown in the code below: diff --git a/frontend/main.c b/frontend/main.c index 95fb00a0..d28dc8d8 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -41,7 +41,7 @@ typedef int static_assert_int_at_least_32bits[CHAR_BIT != 8 || sizeof(int) < 4 ? -1 : 1]; #ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0]))) #endif /* Print list of supported symbologies */ @@ -140,7 +140,7 @@ static void usage(void) { " --filetype=TYPE Set output file type BMP/EMF/EPS/GIF/PCX/PNG/SVG/TIF/TXT\n" " --fullmultibyte Use multibyte for binary/Latin (QR/Han Xin/Grid Matrix)\n" " --gs1 Treat input as GS1 compatible data\n" - " --gs1parens GS1 AIs in parentheses instead of square brackets\n" + " --gs1parens Process parentheses \"()\" as GS1 AI delimiters, not \"[]\"\n" " --gssep Use separator GS for GS1 (Data Matrix)\n" " -h, --help Display help message\n" " --height=NUMBER Set height of symbol in multiples of X-dimension\n" @@ -157,7 +157,7 @@ static void usage(void) { " --rotate=NUMBER Rotate symbol by NUMBER degrees\n" " --rows=NUMBER Set number of rows (Codablock-F)\n" " --scale=NUMBER Adjust size of X-dimension\n" - " --scmvv=NUMBER Prefix SCM with [)>\\R01\\Gvv (vv is NUMBER) (MaxiCode)\n" + " --scmvv=NUMBER Prefix SCM with \"[)>\\R01\\Gvv\" (vv is NUMBER) (MaxiCode)\n" " --secure=NUMBER Set error correction level (ECC)\n" " --separator=NUMBER Set height of row separator bars (stacked symbologies)\n" " --small Use small text\n" @@ -423,7 +423,7 @@ static int supported_filetype(const char *filetype, const int no_png, int *png_r return 0; } - for (i = 0; i < (int) ARRAY_SIZE(filetypes); i++) { + for (i = 0; i < ARRAY_SIZE(filetypes); i++) { if (strcmp(lc_filetype, filetypes[i]) == 0) { return 1; } @@ -486,7 +486,7 @@ static int is_raster(const char *filetype, const int no_png) { return 0; } - for (i = 0; i < (int) ARRAY_SIZE(raster_filetypes); i++) { + for (i = 0; i < ARRAY_SIZE(raster_filetypes); i++) { if (strcmp(lc_filetype, raster_filetypes[i]) == 0) { return 1; } diff --git a/frontend/tests/test_args.c b/frontend/tests/test_args.c index 71c009bc..9605e983 100644 --- a/frontend/tests/test_args.c +++ b/frontend/tests/test_args.c @@ -107,7 +107,7 @@ static char *exec(const char *cmd, char *buf, int buf_size, int debug, int index fprintf(stderr, "exec: failed to run '%s'\n", cmd); return NULL; } - cnt = fread(buf, 1, buf_size, fp); + cnt = (int) fread(buf, 1, buf_size, fp); if (fgetc(fp) != EOF) { fprintf(stderr, "exec: failed to read full stream (%s)\n", cmd); testutil_pclose(fp); @@ -161,7 +161,7 @@ static int arg_input(char *cmd, const char *filename, const char *input) { fprintf(stderr, "arg_input: failed to open '%s' for writing\n", filename); return 0; } - cnt = fwrite(input, 1, strlen(input), fp); + cnt = (int) fwrite(input, 1, strlen(input), fp); if (cnt != (int) strlen(input)) { fprintf(stderr, "arg_input: failed to write %d bytes, cnt %d written (%s)\n", (int) strlen(input), cnt, filename); fclose(fp);