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
This commit is contained in:
gitlost 2021-06-27 11:47:55 +01:00
parent 33ebcea30c
commit 52c00e59ba
30 changed files with 739 additions and 715 deletions

View File

@ -74,12 +74,16 @@ if(ZINT_SANITIZE AND NOT MSVC)
COMPILE_DEFINITIONS ${sanitizer_flag} COMPILE_DEFINITIONS ${sanitizer_flag}
LINK_OPTIONS ${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) if(RESULT_VAR)
set(SANITIZER_FLAGS ${SANITIZER_FLAGS} ${sanitizer_flag}) set(SANITIZER_FLAGS ${SANITIZER_FLAGS} ${sanitizer_flag})
endif() endif()
endforeach() endforeach()
message(STATUS "Sanitizer flags: ${SANITIZER_FLAGS}") 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() endif()
if(APPLE) if(APPLE)

View File

@ -33,6 +33,8 @@
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
#include "gs1.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#define inline _inline #define inline _inline
#endif #endif
@ -62,18 +64,6 @@ static inline char check_digit(const unsigned int count) {
return itoc((10 - (count % 10)) % 10); 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 */ /* 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, 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) { 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) { if (have_checkdigit) {
/* Add standard GS1 check digit */ /* Add standard GS1 check digit */
temp[length] = check_digit(gs1_checksum(source, length)); temp[length] = gs1_check_digit(source, length);
temp[++length] = '\0'; temp[++length] = '\0';
} }
@ -173,7 +163,7 @@ static int c25inter_common(struct zint_symbol *symbol, unsigned char source[], i
if (have_checkdigit) { if (have_checkdigit) {
/* Add standard GS1 check digit */ /* Add standard GS1 check digit */
temp[length] = check_digit(gs1_checksum(temp, length)); temp[length] = gs1_check_digit(temp, length);
temp[++length] = '\0'; temp[++length] = '\0';
} }
@ -258,7 +248,7 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt
ustrcpy(localstr + zeroes, source); ustrcpy(localstr + zeroes, source);
/* Calculate the check digit - the same method used for EAN-13 */ /* 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'; localstr[14] = '\0';
error_number = c25inter_common(symbol, localstr, 14, 1 /*dont_set_height*/); error_number = c25inter_common(symbol, localstr, 14, 1 /*dont_set_height*/);
ustrcpy(symbol->text, localstr); ustrcpy(symbol->text, localstr);

View File

@ -111,17 +111,17 @@ INTERNAL int code_11(struct zint_symbol *symbol, unsigned char source[], int len
assert(length > 0); assert(length > 0);
if (length > 121) { 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; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(SODIUM, source, length); error_number = is_sane(SODIUM, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) { 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; return error_number;
} }
if (symbol->option_2 < 0 || symbol->option_2 > 2) { 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; return ZINT_ERROR_INVALID_OPTION;
} }
if (symbol->option_2 == 2) { 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 */ 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; return ZINT_ERROR_TOO_LONG;
/* Prevent encoded_data out-of-bounds >= 143 for BARCODE_HIBC_39 due to wider 'wide' bars */ /* 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)) { } 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; return ZINT_ERROR_TOO_LONG;
} else if (length > 85) { } 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; return ZINT_ERROR_TOO_LONG;
} }
to_upper(source); to_upper(source);
error_number = is_sane(SILVER, source, length); error_number = is_sane(SILVER, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) { 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; return error_number;
} }
@ -356,12 +357,12 @@ INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], i
char localstr[11]; char localstr[11];
if (length > 7) { 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; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) { 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; return error_number;
} }
@ -383,7 +384,7 @@ INTERNAL int pharmazentral(struct zint_symbol *symbol, unsigned char source[], i
} }
if (check_digit == 10) { 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; return ZINT_ERROR_INVALID_DATA;
} }
localstr[8] = itoc(check_digit); localstr[8] = itoc(check_digit);
@ -417,7 +418,7 @@ INTERNAL int ec39(struct zint_symbol *symbol, unsigned char source[], int length
int error_number; int error_number;
if (length > 85) { 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; 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++) { for (i = 0; i < length; i++) {
if (source[i] > 127) { if (source[i] > 127) {
/* Cannot encode extended ASCII */ /* 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; return ZINT_ERROR_INVALID_DATA;
} }
ustrcat(buffer, EC39Ctrl[source[i]]); ustrcat(buffer, EC39Ctrl[source[i]]);
@ -458,7 +459,7 @@ INTERNAL int c93(struct zint_symbol *symbol, unsigned char source[], int length)
strcpy(buffer, ""); strcpy(buffer, "");
if (length > 107) { 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; 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++) { for (i = 0; i < length; i++) {
if (source[i] > 127) { if (source[i] > 127) {
/* Cannot encode extended ASCII */ /* 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; return ZINT_ERROR_INVALID_DATA;
} }
strcat(buffer, C93Ctrl[source[i]]); 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 */ /* Now we can check the true length of the barcode */
h = (int) strlen(buffer); h = (int) strlen(buffer);
if (h > 107) { 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; 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 */ /* Channel Code - According to ANSI/AIM BC12-1998 */
INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) { 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}; int S[8] = {0}, B[8] = {0};
long target_value = 0; long target_value = 0;
char pattern[30]; char pattern[30];
int channels, i; int channels, i;
int error_number, range = 0, zeroes; int error_number, zeroes;
char hrt[9]; char hrt[9];
float height; float height;
if (length > 7) { 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; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, length); error_number = is_sane(NEON, source, length);
if (error_number == ZINT_ERROR_INVALID_DATA) { 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; return error_number;
} }
@ -721,34 +723,8 @@ INTERNAL int channel_code(struct zint_symbol *symbol, unsigned char source[], in
channels = 3; channels = 3;
} }
switch (channels) { if (target_value > max_ranges[channels]) {
case 3: if (target_value > 26) { sprintf(symbol->errtxt, "335: Value out of range (0 to %d) for %d channels", max_ranges[channels], channels);
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");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
@ -804,13 +780,13 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length)
// Check length // Check length
if (length != 17) { 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; return ZINT_ERROR_TOO_LONG;
} }
// Check input characters, I, O and Q are not allowed // Check input characters, I, O and Q are not allowed
if (is_sane(ARSENIC, source, length) == ZINT_ERROR_INVALID_DATA) { 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; 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) { if (input_check != output_check) {
strcpy(symbol->errtxt, "338: Invalid check digit in input data"); sprintf(symbol->errtxt, "338: Invalid check digit '%c', expecting '%c'", input_check, output_check);
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_CHECK;
} }
} }

View File

@ -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 */ /* 'look ahead test' from Annex P */
static int look_ahead_test(const unsigned char inputData[], const int sourcelen, const int position, 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; 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; int ascii_rnded, c40_rnded, text_rnded, x12_rnded, edf_rnded, b256_rnded;
float cnt_1; float cnt_1;
@ -379,6 +379,12 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen,
text_count = stripf(text_count); text_count = stripf(text_count);
x12_count = stripf(x12_count); x12_count = stripf(x12_count);
c40_count = stripf(c40_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; cnt_1 = ascii_count + 1.0f;
if (cnt_1 <= b256_count && cnt_1 <= edf_count && cnt_1 <= text_count && cnt_1 <= x12_count 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)); text_rnded = (int) ceilf(stripf(text_count));
x12_rnded = (int) ceilf(stripf(x12_count)); x12_rnded = (int) ceilf(stripf(x12_count));
c40_rnded = (int) ceilf(stripf(c40_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 if (ascii_rnded <= b256_rnded && ascii_rnded <= edf_rnded && ascii_rnded <= text_rnded && ascii_rnded <= x12_rnded
&& ascii_rnded <= c40_rnded) { && ascii_rnded <= c40_rnded) {
@ -695,7 +707,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
tp++; tp++;
sp += 2; sp += 2;
} else { } 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) { if (next_mode != DM_ASCII) {
switch (next_mode) { switch (next_mode) {
@ -753,7 +765,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
next_mode = current_mode; next_mode = current_mode;
if (process_p == 0) { 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) { if (next_mode != current_mode) {
@ -809,7 +821,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
next_mode = DM_X12; next_mode = DM_X12;
if (process_p == 0) { 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) { if (next_mode != DM_X12) {
@ -844,7 +856,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[],
if (process_p == 3) { if (process_p == 3) {
/* Note different then spec Step (f)(1), which suggests checking when 0, but this seems to work /* Note different then spec Step (f)(1), which suggests checking when 0, but this seems to work
better in many cases. */ 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) { 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 */ /* step (g) Base 256 encodation */
} else if (current_mode == DM_BASE256) { } 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) { if (next_mode == DM_BASE256) {
target[tp] = source[sp]; target[tp] = source[sp];

View File

@ -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 */ /* the character '[' in the reduced string refers to the FNC1 character */
return error_value; 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);
}

View File

@ -39,6 +39,7 @@ extern "C" {
INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const int src_len, INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const int src_len,
unsigned char reduced[]); unsigned char reduced[]);
INTERNAL char gs1_check_digit(const unsigned char source[], const int src_len);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1286,33 +1286,18 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) {
to_upper((unsigned char *) output); to_upper((unsigned char *) output);
if (!(strcmp(output, "PNG"))) { if (!(strcmp(output, "PNG"))) {
if (symbol->scale < 1.0f) {
symbol->text[0] = '\0';
}
error_number = plot_raster(symbol, rotate_angle, OUT_PNG_FILE); error_number = plot_raster(symbol, rotate_angle, OUT_PNG_FILE);
} else if (!(strcmp(output, "BMP"))) { } else if (!(strcmp(output, "BMP"))) {
if (symbol->scale < 1.0f) {
symbol->text[0] = '\0';
}
error_number = plot_raster(symbol, rotate_angle, OUT_BMP_FILE); error_number = plot_raster(symbol, rotate_angle, OUT_BMP_FILE);
} else if (!(strcmp(output, "PCX"))) { } else if (!(strcmp(output, "PCX"))) {
if (symbol->scale < 1.0f) {
symbol->text[0] = '\0';
}
error_number = plot_raster(symbol, rotate_angle, OUT_PCX_FILE); error_number = plot_raster(symbol, rotate_angle, OUT_PCX_FILE);
} else if (!(strcmp(output, "GIF"))) { } else if (!(strcmp(output, "GIF"))) {
if (symbol->scale < 1.0f) {
symbol->text[0] = '\0';
}
error_number = plot_raster(symbol, rotate_angle, OUT_GIF_FILE); error_number = plot_raster(symbol, rotate_angle, OUT_GIF_FILE);
} else if (!(strcmp(output, "TIF"))) { } else if (!(strcmp(output, "TIF"))) {
if (symbol->scale < 1.0f) {
symbol->text[0] = '\0';
}
error_number = plot_raster(symbol, rotate_angle, OUT_TIF_FILE); error_number = plot_raster(symbol, rotate_angle, OUT_TIF_FILE);
} else if (!(strcmp(output, "TXT"))) { } else if (!(strcmp(output, "TXT"))) {
@ -1522,7 +1507,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) {
if (file_opened) { if (file_opened) {
fclose(file); fclose(file);
} }
ret = ZBarcode_Encode(symbol, buffer, nRead); ret = ZBarcode_Encode(symbol, buffer, (int) nRead);
free(buffer); free(buffer);
return ret; return ret;
} }

View File

@ -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); unsigned char addon[6], int *p_addon_gap);
INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si); INTERNAL float output_large_bar_height(struct zint_symbol *symbol, int si);
INTERNAL void output_upcean_split_text(int upceanflag, unsigned char text[], INTERNAL void output_upcean_split_text(int upceanflag, unsigned char text[],
unsigned char textpart1[], unsigned char textpart2[], unsigned char textpart3[], unsigned char textpart1[5], unsigned char textpart2[7], unsigned char textpart3[7],
unsigned char textpart4[]); unsigned char textpart4[2]);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -31,7 +31,7 @@
*/ */
/* vim: set ts=4 sw=4 et : */ /* 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: released with permission under the following terms:
"Copyright subsists in all BSI publications. BSI also holds the copyright, in the "Copyright subsists in all BSI publications. BSI also holds the copyright, in the
@ -73,11 +73,11 @@
#include "gs1.h" #include "gs1.h"
#include "general_field.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!) * 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 i, j;
int maxDenom, minDenom; int maxDenom, minDenom;
int val; int val;
@ -128,11 +128,11 @@ static void getRSSwidths(int widths[], int val, int n, const int elements, const
; ;
elmWidth++, narrowMask &= ~(1 << bar)) { elmWidth++, narrowMask &= ~(1 << bar)) {
/* get all combinations */ /* 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 */ /* less combinations with no single-module element */
if ((!noNarrow) && (!narrowMask) && if ((!noNarrow) && (!narrowMask)
(n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) { && (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
subVal -= combins(n - elmWidth - (elements - bar), elements - bar - 2); subVal -= rss_combins(n - elmWidth - (elements - bar), elements - bar - 2);
} }
/* less combinations with elements > maxVal */ /* less combinations with elements > maxVal */
if (elements - bar - 1 > 1) { 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); for (mxwElement = n - elmWidth - (elements - bar - 2);
mxwElement > maxWidth; mxwElement > maxWidth;
mxwElement--) { 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); subVal -= lessVal * (elements - 1 - bar);
} else if (n - elmWidth > maxWidth) { } else if (n - elmWidth > maxWidth) {
@ -157,24 +157,8 @@ static void getRSSwidths(int widths[], int val, int n, const int elements, const
return; 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 */ /* 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; int i;
unsigned char hrt[15]; 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[12 - i] = source[src_len - i - 1];
} }
hrt[13] = itoc(calc_check_digit(hrt)); hrt[13] = gs1_check_digit(hrt, 13);
hrt[14] = '\0'; hrt[14] = '\0';
ustrcat(symbol->text, hrt); ustrcat(symbol->text, hrt);
@ -319,18 +303,19 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
separator_row = 0; separator_row = 0;
if (src_len > 14) { /* Allow check digit to be specified (will be verified and ignored) */ 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; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, src_len); error_number = is_sane(NEON, source, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) { 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; return error_number;
} }
if (src_len == 14) { /* Verify check digit */ if (src_len == 14) { /* Verify check digit */
if (calc_check_digit(source) != ctoi(source[13])) { if (gs1_check_digit(source, 13) != source[13]) {
strcpy(symbol->errtxt, "388: Invalid check digit"); sprintf(symbol->errtxt, "388: Invalid check digit '%c', expecting '%c'",
source[13], gs1_check_digit(source, 13));
return ZINT_ERROR_INVALID_CHECK; return ZINT_ERROR_INVALID_CHECK;
} }
src_len--; /* Ignore */ 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_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]]; v_even[2] = (data_character[2] - g_sum_table[data_group[2]]) % t_table[data_group[2]];
/* Use RSS subset width algorithm */ /* Use RSS subset width algorithm */
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if ((i == 0) || (i == 2)) { if ((i == 0) || (i == 2)) {
@ -450,7 +434,6 @@ INTERNAL int rss14_cc(struct zint_symbol *symbol, unsigned char source[], int sr
} }
} }
checksum = 0; checksum = 0;
/* Calculate the checksum */ /* Calculate the checksum */
for (i = 0; i < 8; i++) { 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; symbol->rows = symbol->rows + 1;
/* Set human readable text */ /* Set human readable text */
set_gtin14_hrt(symbol, source, src_len); rss_set_gtin14_hrt(symbol, source, src_len);
#ifdef COMPLIANT_HEIGHTS #ifdef COMPLIANT_HEIGHTS
/* Minimum height is 13X for truncated symbol ISO/IEC 24724:2011 5.3.1 /* 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; separator_row = 0;
if (src_len > 14) { /* Allow check digit to be specified (will be verified and ignored) */ 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; return ZINT_ERROR_TOO_LONG;
} }
error_number = is_sane(NEON, source, src_len); error_number = is_sane(NEON, source, src_len);
if (error_number == ZINT_ERROR_INVALID_DATA) { 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; return error_number;
} }
if (src_len == 14) { /* Verify check digit */ if (src_len == 14) { /* Verify check digit */
if (calc_check_digit(source) != ctoi(source[13])) { if (gs1_check_digit(source, 13) != source[13]) {
strcpy(symbol->errtxt, "389: Invalid check digit"); sprintf(symbol->errtxt, "389: Invalid check digit '%c', expecting '%c'",
source[13], gs1_check_digit(source, 13));
return ZINT_ERROR_INVALID_CHECK; return ZINT_ERROR_INVALID_CHECK;
} }
src_len--; /* Ignore */ src_len--; /* Ignore */
@ -677,7 +661,7 @@ INTERNAL int rsslimited_cc(struct zint_symbol *symbol, unsigned char source[], i
if (src_len == 13) { if (src_len == 13) {
if ((source[0] != '0') && (source[0] != '1')) { 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; 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 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 */ /* ISO/IEC 24724:2011 6.2 10X minimum height, use as default also */
if (symbol->symbology == BARCODE_DBAR_LTD_CC) { 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 */ /* 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[], static int rssexp_binary_string(struct zint_symbol *symbol, const unsigned char source[], char binary_string[],
int *p_bp) { int cols_per_row, int *p_bp) {
int encoding_method, i, j, read_posn, debug = (symbol->debug & ZINT_DEBUG_PRINT), mode = NUMERIC; int encoding_method, i, j, read_posn, debug = (symbol->debug & ZINT_DEBUG_PRINT), mode = NUMERIC;
char last_digit = '\0'; 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); int length = (int) ustrlen(source);
#ifndef _MSC_VER #ifndef _MSC_VER
char general_field[length + 1]; 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; encoding_method = 7;
} }
} else if ((length == 34) && (source[26] == '1') && } else if ((length == 34) && (source[26] == '1')
(source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') && && (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7')
rss_date(source, 28) >= 0) { && rss_date(source, 28) >= 0) {
/* (01), (310x) and (11) - metric weight and production date */ /* (01), (310x) and (11) - metric weight and production date */
/* (01), (310x) and (13) - metric weight and packaging 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; encoding_method = 8;
} }
} else if ((length == 34) && (source[26] == '1') && } else if ((length == 34) && (source[26] == '1')
(source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7') && && (source[27] == '1' || source[27] == '3' || source[27] == '5' || source[27] == '7')
rss_date(source, 28) >= 0) { && rss_date(source, 28) >= 0) {
/* (01), (320x) and (11) - English weight and production date */ /* (01), (320x) and (11) - English weight and production date */
/* (01), (320x) and (13) - English weight and packaging 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] < '0') || (source[i] > '9')) {
if (source[i] != '[') { if (source[i] != '[') {
/* Something is wrong */ /* 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; 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)) { if (!general_field_encode(general_field, j, &mode, &last_digit, binary_string, &bp)) {
/* Invalid characters in input data */ /* 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; return ZINT_ERROR_INVALID_DATA;
} }
} }
@ -1102,17 +1086,9 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou
} }
symbol_characters = ((bp + remainder) / 12) + 1; symbol_characters = ((bp + remainder) / 12) + 1;
if ((symbol->symbology == BARCODE_DBAR_EXPSTK) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) { if (characters_per_row && (symbol_characters % characters_per_row) == 1) { // DBAR_EXPSTK
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++; symbol_characters++;
} }
}
if (symbol_characters < 4) { if (symbol_characters < 4) {
symbol_characters = 4; symbol_characters = 4;
@ -1139,17 +1115,9 @@ static int rss_binary_string(struct zint_symbol *symbol, const unsigned char sou
} }
symbol_characters = ((bp + remainder) / 12) + 1; symbol_characters = ((bp + remainder) / 12) + 1;
if ((symbol->symbology == BARCODE_DBAR_EXPSTK) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) { if (characters_per_row && (symbol_characters % characters_per_row) == 1) { // DBAR_EXPSTK
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++; symbol_characters++;
} }
}
if (symbol_characters < 4) { if (symbol_characters < 4) {
symbol_characters = 4; 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) */ 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; 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; unsigned int bin_len = 13 * src_len + 200 + 1;
int widths[4]; int widths[4];
int bp = 0; int bp = 0;
int cols_per_row = 0;
int stack_rows = 1; int stack_rows = 1;
#ifndef _MSC_VER #ifndef _MSC_VER
unsigned char reduced[src_len + 1]; 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) { if (error_number >= ZINT_ERROR) {
return error_number; return error_number;
} }
warn_number = error_number;
if (symbol->debug & ZINT_DEBUG_PRINT) { if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Reduced (%d): %s\n", (int) ustrlen(reduced), reduced); 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'; binary_string[bp++] = '0';
} }
i = rss_binary_string(symbol, reduced, binary_string, &bp); if ((symbol->symbology == BARCODE_DBAR_EXPSTK) || (symbol->symbology == BARCODE_DBAR_EXPSTK_CC)) {
if (i != 0) { cols_per_row = 2; /* Default */
return i; 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; data_chars = bp / 12;
@ -1479,18 +1462,8 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[],
* Patch by Daniel Frede * Patch by Daniel Frede
*/ */
if ((symbol->option_2 < 1) || (symbol->option_2 > 11)) { stack_rows = codeblocks / cols_per_row;
symbol->option_2 = 2; if (codeblocks % cols_per_row > 0) {
}
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++; stack_rows++;
} }
@ -1502,10 +1475,10 @@ INTERNAL int rssexpanded_cc(struct zint_symbol *symbol, unsigned char source[],
int num_columns; int num_columns;
/* Number of columns in current row */ /* 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; num_columns = codeblocks - current_block;
} else { } else {
num_columns = symbol->option_2; num_columns = cols_per_row;
} }
/* Row Start */ /* 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), /* If last row and is partial and even-numbered, and have even columns (segment pairs),
* and odd number of finders (== odd number of columns) */ * and odd number of finders (== odd number of columns) */
if ((current_row == stack_rows) && (num_columns != symbol->option_2) && if ((current_row == stack_rows) && (num_columns != cols_per_row) && !(current_row & 1)
!(current_row & 1) && !(symbol->option_2 & 1) && (num_columns & 1)) { && !(cols_per_row & 1) && (num_columns & 1)) {
/* Special case bottom row */ /* Special case bottom row */
special_case_row = 1; special_case_row = 1;
sub_elements[0] = 2; /* Extra space (latch set below) */ 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, /* If odd number of columns or current row odd-numbered or special case last row then left-to-right,
* else right-to-left */ * 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; left_to_right = 1;
} else { } else {
left_to_right = 0; 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 (symbol->debug & ZINT_DEBUG_PRINT) {
if (current_row == stack_rows) { if (current_row == stack_rows) {
printf("Last row: number of columns: %d / %d, left to right: %d, special case: %d\n", 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++; reader++;
current_block++; current_block++;
} while ((reader < symbol->option_2) && (current_block < codeblocks)); } while ((reader < cols_per_row) && (current_block < codeblocks));
/* Row Stop */ /* Row Stop */
sub_elements[elements_in_sub] = 1; // right guard 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); int odd_last_row = (current_row == stack_rows) && (data_chars % 2 == 0);
/* middle separator pattern (above current row) */ /* 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); set_module(symbol, symbol->rows - 2, j);
} }
symbol->row_height[symbol->rows - 2] = 1; 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 */ symbol->height = symbol->height ? 34.0f : 34.0f * stack_rows; /* Pass back min row or default height */
} else { } else {
#ifdef COMPLIANT_HEIGHTS #ifdef COMPLIANT_HEIGHTS
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*/); warn_number = set_height(symbol, 34.0f, 34.0f * stack_rows, 0.0f, 0 /*no_errtxt*/);
}
#else #else
(void) set_height(symbol, 0.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/); (void) set_height(symbol, 0.0f, 34.0f * stack_rows, 0.0f, 1 /*no_errtxt*/);
#endif #endif

View File

@ -205,11 +205,12 @@ static void test_input(int index, int debug) {
/* 20*/ { BARCODE_PZN, -1, "A", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 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 /* 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 }, /* 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 /* 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 /* 25*/ { BARCODE_VIN, -1, "WPOZZZ99ZTS392124", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, // O not allowed
/* 26*/ { BARCODE_HIBC_39, -1, ",", -1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 26*/ { BARCODE_HIBC_39, -1, "a", -1, 0, 1, 79 }, // Converts to upper
/* 27*/ { BARCODE_HIBC_39, -1, "\000", 1, ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 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 data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;

View File

@ -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, 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_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); assert_zero(strcmp((char *) symbol.text, data[i].expected), "i:%d symbol.text (%s) != expected (%s)\n", i, symbol.text, data[i].expected);
} }

View File

@ -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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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_data[1024];
char esc_composite[4096]; char esc_composite[4096];
testUtilEscape(data, strlen(data), esc_data, sizeof(esc_data)); testUtilEscape(data, (int) strlen(data), esc_data, sizeof(esc_data));
testUtilEscape(composite, strlen(composite), esc_composite, sizeof(esc_composite)); testUtilEscape(composite, (int) strlen(composite), esc_composite, sizeof(esc_composite));
if (ret == 0) { if (ret == 0) {
if (bwipp_cmp == -1) { 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); 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); 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); 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); assert_zero(length >= 128, "i:%d length %d >= 128\n", i, length);
strcpy(symbol->primary, data[i].data); strcpy(symbol->primary, data[i].data);
composite_length = strlen(data[i].composite); composite_length = (int) strlen(data[i].composite);
start = clock(); start = clock();
ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length); ret = ZBarcode_Encode(symbol, (const unsigned char *) data[i].composite, composite_length);

View File

@ -1325,7 +1325,7 @@ static void test_gs1_verify(int index, int debug) {
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); 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); 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); 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(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); 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); 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); 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);

View File

@ -109,7 +109,7 @@ static void test_csv(int index, int debug) {
symbol->symbology = BARCODE_USPS_IMAIL; symbol->symbology = BARCODE_USPS_IMAIL;
symbol->debug |= debug; 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) { if (strcmp(return_code, "00") == 0) {

View File

@ -33,13 +33,17 @@
#include "../large.h" #include "../large.h"
#if defined(__MINGW32__) #if defined(__MINGW32__)
# if __WORDSIZE == 32
# define LX_FMT "I32"
# else
# define LX_FMT "I64" # define LX_FMT "I64"
# endif
# if defined(__clang__) # if defined(__clang__)
# pragma GCC diagnostic ignored "-Wformat-non-iso" # pragma GCC diagnostic ignored "-Wformat-non-iso"
# elif defined(__GNUC__) # elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wformat" /* Unfortunately doesn't seem to be way to only avoid non-ISO warnings */ # pragma GCC diagnostic ignored "-Wformat" /* Unfortunately doesn't seem to be way to only avoid non-ISO warnings */
# endif # endif
#elif defined(_MSC_VER) #elif defined(_MSC_VER) || __WORDSIZE == 32
# define LX_FMT "ll" # define LX_FMT "ll"
#else #else
# define LX_FMT "l" # define LX_FMT "l"

View File

@ -379,7 +379,7 @@ static void test_encode_file_too_large(void) {
fstream = fopen(filename, "w+"); fstream = fopen(filename, "w+");
assert_nonnull(fstream, "fopen(%s) failed (%d)\n", filename, ferror(fstream)); 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)); assert_equal(ret, sizeof(buf), "fwrite return value: %d != %d\n", ret, (int)sizeof(buf));
ret = fclose(fstream); ret = fclose(fstream);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret); assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);

View File

@ -93,7 +93,7 @@ static void test_pcx(int index, int debug) {
} }
symbol->debug |= 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); 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); assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);

View File

@ -1074,7 +1074,7 @@ static void test_fuzz(int index, int debug) {
length = data[i].length; length = data[i].length;
if (length == -1) { if (length == -1) {
length = strlen(data[i].data); length = (int) strlen(data[i].data);
} }
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);

View File

@ -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 = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
symbol->debug |= 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); 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); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);

View File

@ -274,7 +274,7 @@ static void test_buffer(int index, int generate, int debug) {
} else { } else {
text = data[i].data; text = data[i].data;
} }
length = strlen(text); length = (int) strlen(text);
ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); 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); 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; 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); 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); 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); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_zero(ret, "i:%d ret %d != zero\n", i, ret); 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); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data2, length2);
assert_zero(ret, "i:%d ret %d != zero\n", i, ret); assert_zero(ret, "i:%d ret %d != zero\n", i, ret);
@ -995,7 +995,7 @@ static void test_scale(int index, int debug) {
} else { } else {
text = data[i].data; text = data[i].data;
} }
length = strlen(text); length = (int) strlen(text);
ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); 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); 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); 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); 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); fg_len = (int) strlen(data[i].fgcolour);
bg_len = strlen(data[i].bgcolour); bg_len = (int) strlen(data[i].bgcolour);
if (fg_len > 6 || bg_len > 6) { if (fg_len > 6 || bg_len > 6) {
assert_nonnull(symbol->alphamap, "i:%d ZBarcode_Buffer(%s) alphamap NULL\n", i, testUtilBarcodeName(data[i].symbology)); assert_nonnull(symbol->alphamap, "i:%d ZBarcode_Buffer(%s) alphamap NULL\n", i, testUtilBarcodeName(data[i].symbology));
// TODO: check alphamap // TODO: check alphamap
@ -1674,7 +1674,7 @@ static void test_height(int index, int generate, int debug) {
} else { } else {
text = data[i].data; text = data[i].data;
} }
length = strlen(text); length = (int) strlen(text);
ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); 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); 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);

View File

@ -794,7 +794,8 @@ static void test_examples(int index, int generate, int debug) {
if (generate) { if (generate) {
printf(" /*%3d*/ { %s, %d, \"%s\", %d, %d, %d, %d, \"%s\",\n", 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"); testUtilModulesPrint(symbol, " ", "\n");
printf(" },\n"); printf(" },\n");
} else { } else {
@ -1228,6 +1229,7 @@ static void test_input(int index, int debug) {
struct item { struct item {
int symbology; int symbology;
int option_2;
char *data; char *data;
int ret; int ret;
int expected_rows; int expected_rows;
@ -1235,32 +1237,33 @@ static void test_input(int index, int debug) {
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_DBAR_OMN, "1234567890123", 0, 1, 96 }, /* 0*/ { BARCODE_DBAR_OMN, -1, "1234567890123", 0, 1, 96 },
/* 1*/ { BARCODE_DBAR_OMN, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 1*/ { BARCODE_DBAR_OMN, -1, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 2*/ { BARCODE_DBAR_OMN, "12345678901234", ZINT_ERROR_INVALID_CHECK, -1, -1 }, /* 2*/ { BARCODE_DBAR_OMN, -1, "12345678901234", ZINT_ERROR_INVALID_CHECK, -1, -1 },
/* 3*/ { BARCODE_DBAR_OMN, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 3*/ { BARCODE_DBAR_OMN, -1, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { BARCODE_DBAR_LTD, "1234567890123", 0, 1, 79 }, /* 4*/ { BARCODE_DBAR_LTD, -1, "1234567890123", 0, 1, 79 },
/* 5*/ { BARCODE_DBAR_LTD, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 5*/ { BARCODE_DBAR_LTD, -1, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 6*/ { BARCODE_DBAR_LTD, "12345678901235", ZINT_ERROR_INVALID_CHECK, -1, -1 }, /* 6*/ { BARCODE_DBAR_LTD, -1, "12345678901235", ZINT_ERROR_INVALID_CHECK, -1, -1 },
/* 7*/ { BARCODE_DBAR_LTD, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 7*/ { BARCODE_DBAR_LTD, -1, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 },
/* 8*/ { BARCODE_DBAR_LTD, "2234567890123", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 8*/ { BARCODE_DBAR_LTD, -1, "2234567890123", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 9*/ { BARCODE_DBAR_LTD, "22345678901238", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 9*/ { BARCODE_DBAR_LTD, -1, "22345678901238", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 10*/ { BARCODE_DBAR_EXP, "[01]12345678901234", ZINT_WARN_NONCOMPLIANT, 1, 134 }, /* 10*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901234", ZINT_WARN_NONCOMPLIANT, 1, 134 },
/* 11*/ { BARCODE_DBAR_EXP, "[01]12345678901231", 0, 1, 134 }, /* 11*/ { BARCODE_DBAR_EXP, -1, "[01]12345678901231", 0, 1, 134 },
/* 12*/ { BARCODE_DBAR_EXP, "[01]1234567890123A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 12*/ { BARCODE_DBAR_EXP, -1, "[01]1234567890123A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 13*/ { BARCODE_DBAR_EXP, "[01]123456789012315", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 13*/ { BARCODE_DBAR_EXP, -1, "[01]123456789012315", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 14*/ { BARCODE_DBAR_STK, "1234567890123", 0, 3, 50 }, /* 14*/ { BARCODE_DBAR_STK, -1, "1234567890123", 0, 3, 50 },
/* 15*/ { BARCODE_DBAR_STK, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 15*/ { BARCODE_DBAR_STK, -1, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 16*/ { BARCODE_DBAR_STK, "12345678901235", ZINT_ERROR_INVALID_CHECK, -1, -1 }, /* 16*/ { BARCODE_DBAR_STK, -1, "12345678901235", ZINT_ERROR_INVALID_CHECK, -1, -1 },
/* 17*/ { BARCODE_DBAR_STK, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 17*/ { BARCODE_DBAR_STK, -1, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 },
/* 18*/ { BARCODE_DBAR_OMNSTK, "1234567890123", 0, 5, 50 }, /* 18*/ { BARCODE_DBAR_OMNSTK, -1, "1234567890123", 0, 5, 50 },
/* 19*/ { BARCODE_DBAR_OMNSTK, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 19*/ { BARCODE_DBAR_OMNSTK, -1, "123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 20*/ { BARCODE_DBAR_OMNSTK, "12345678901236", ZINT_ERROR_INVALID_CHECK, -1, -1 }, /* 20*/ { BARCODE_DBAR_OMNSTK, -1, "12345678901236", ZINT_ERROR_INVALID_CHECK, -1, -1 },
/* 21*/ { BARCODE_DBAR_OMNSTK, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 21*/ { BARCODE_DBAR_OMNSTK, -1, "123456789012315", ZINT_ERROR_TOO_LONG, -1, -1 },
/* 22*/ { BARCODE_DBAR_EXPSTK, "[01]12345678901234", ZINT_WARN_NONCOMPLIANT, 5, 102 }, /* 22*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901234", ZINT_WARN_NONCOMPLIANT, 5, 102 },
/* 22*/ { BARCODE_DBAR_EXPSTK, "[01]12345678901231", 0, 5, 102 }, /* 23*/ { BARCODE_DBAR_EXPSTK, -1, "[01]12345678901231", 0, 5, 102 },
/* 23*/ { BARCODE_DBAR_EXPSTK, "[01]123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 24*/ { BARCODE_DBAR_EXPSTK, -1, "[01]123456789012A", ZINT_ERROR_INVALID_DATA, -1, -1 },
/* 24*/ { BARCODE_DBAR_EXPSTK, "[01]123456789012315", 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 data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -1275,7 +1278,7 @@ static void test_input(int index, int debug) {
symbol = ZBarcode_Create(); symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n"); 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); 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); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);

View File

@ -155,7 +155,7 @@ static void test_print(int index, int generate, int debug) {
} else { } else {
text = data[i].data; text = data[i].data;
} }
text_length = strlen(text); text_length = (int) strlen(text);
ret = ZBarcode_Encode(symbol, (unsigned char *) text, text_length); 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); 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);

View File

@ -238,7 +238,7 @@ static void test_print(int index, int generate, int debug) {
} else { } else {
text = data[i].data; text = data[i].data;
} }
text_length = strlen(text); text_length = (int) strlen(text);
ret = ZBarcode_Encode(symbol, (unsigned char *) text, text_length); 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); assert_zero(ret, "i:%d %s ZBarcode_Encode ret %d != 0 %s\n", i, testUtilBarcodeName(data[i].symbology), ret, symbol->errtxt);

View File

@ -290,7 +290,7 @@ static void test_buffer_vector(int index, int generate, int debug) {
} else { } else {
text = data[i].data; text = data[i].data;
} }
length = strlen(text); length = (int) strlen(text);
ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); 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); 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; symbol->debug |= debug;
length = strlen(data[i].data); length = (int) strlen(data[i].data);
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length); 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); 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); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
assert_zero(ret, "i:%d ret %d != zero\n", i, ret); 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); ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data2, length2);
assert_zero(ret, "i:%d ret %d != zero\n", i, ret); 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->input_mode = UNICODE_MODE;
symbol->debug |= 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); 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); 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->whitespace_width = data[i].whitespace_width;
symbol->debug |= 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); 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); 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 { } else {
text = data[i].data; text = data[i].data;
} }
length = strlen(text); length = (int) strlen(text);
ret = ZBarcode_Encode(symbol, (unsigned char *) text, length); 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); 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);

File diff suppressed because it is too large Load Diff

View File

@ -70,20 +70,19 @@ extern "C" {
#endif #endif
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
#endif #endif
extern int assertionFailed; extern int assertionFailed;
extern int assertionNum; extern int assertionNum;
extern const char *assertionFilename;
#if _MSC_VER == 1200 /* VC6 */ #if _MSC_VER == 1200 /* VC6 */
#define testStart(__arg__) (testStartReal("", __arg__)) #define testStart(__arg__) (testStartReal("", __arg__))
#else #else
#define testStart(__arg__) (testStartReal(__func__, __arg__)) #define testStart(__arg__) (testStartReal(__func__, __arg__))
#endif #endif
#define testEndExp(__arg__) (testEnd(!(__arg__)))
void testStartReal(const char *func, const char *name); void testStartReal(const char *func, const char *name);
void testEnd(int result);
void testFinish(void); void testFinish(void);
void testSkip(const char *msg); void testSkip(const char *msg);
void testReport(); 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, ...); void assert_notequal(int e1, int e2, ...);
#else #else
#define assert_exp(__exp__, ...) \ #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_zero(__exp__, ...) assert_exp((__exp__) == 0, __VA_ARGS__)
#define assert_nonzero(__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 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); 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 *testUtilBarcodeName(int symbology);
const char *testUtilErrorName(int error_number); const char *testUtilErrorName(int error_number);
const char *testUtilInputModeName(int input_mode); const char *testUtilInputModeName(int input_mode);
const char *testUtilOption3Name(int option_3); const char *testUtilOption3Name(int option_3);
const char *testUtilOutputOptionsName(int output_options); const char *testUtilOutputOptionsName(int output_options);
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size); int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size);
int testUtilIsValidUTF8(const unsigned char str[], const int length); int testUtilIsValidUTF8(const unsigned char str[], const int length);
char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size); char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size);
char *testUtilReadCSVField(char *buffer, char *field, int field_size); char *testUtilReadCSVField(char *buffer, char *field, int field_size);
void testUtilStrCpyRepeat(char *buffer, char *repeat, int size); void testUtilStrCpyRepeat(char *buffer, char *repeat, int size);
int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b); int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b);
struct zint_vector *testUtilVectorCpy(const struct zint_vector *in); struct zint_vector *testUtilVectorCpy(const struct zint_vector *in);
int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b); int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b);
int testUtilModulesDump(const struct zint_symbol *symbol, char dump[], int dump_size); 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 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); 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 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 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 *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_size);
char *testUtilUCharArrayDump(unsigned char *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); 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 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 testUtilExists(const char *filename);
int testUtilDirExists(const char *dirname); int testUtilDirExists(const char *dirname);
int testUtilMkDir(const char *dirname); int testUtilMkDir(const char *dirname);
int testUtilRmDir(const char *dirname); int testUtilRmDir(const char *dirname);
int testUtilRename(const char *oldpath, const char *newpath); int testUtilRename(const char *oldpath, const char *newpath);
int testUtilCmpPngs(const char *file1, const char *file2); int testUtilCmpPngs(const char *file1, const char *file2);
int testUtilCmpTxts(const char *txt1, const char *txt2); int testUtilCmpTxts(const char *txt1, const char *txt2);
int testUtilCmpBins(const char *bin1, const char *bin2); int testUtilCmpBins(const char *bin1, const char *bin2);
int testUtilCmpSvgs(const char *svg1, const char *svg2); int testUtilCmpSvgs(const char *svg1, const char *svg2);
int testUtilCmpEpss(const char *eps1, const char *eps2); int testUtilCmpEpss(const char *eps1, const char *eps2);
int testUtilHaveIdentify(); int testUtilHaveIdentify();
int testUtilVerifyIdentify(const char *filename, int debug); int testUtilVerifyIdentify(const char *filename, int debug);
int testUtilHaveLibreOffice(); int testUtilHaveLibreOffice();
@ -163,6 +170,7 @@ int testUtilHaveVnu();
int testUtilVerifyVnu(const char *filename, int debug); int testUtilVerifyVnu(const char *filename, int debug);
int testUtilHaveTiffInfo(); int testUtilHaveTiffInfo();
int testUtilVerifyTiffInfo(const char *filename, int debug); 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 testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,
int debug); int debug);
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,

View File

@ -31,11 +31,15 @@
/* vim: set ts=4 sw=4 et : */ /* 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 EAN2 102
#define EAN5 105 #define EAN5 105
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
#include "gs1.h"
/* UPC and EAN tables checked against EN 797:1996 */ /* 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" "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 */ /* 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; int i, half_way;
half_way = length / 2; half_way = length / 2;
/* start character */ /* start character */
ustrcat(dest, "111"); strcat(dest, "111");
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (i == half_way) { if (i == half_way) {
/* middle character - separates manufacturer no. from product no. */ /* middle character - separates manufacturer no. from product no. */
/* also inverts right hand characters */ /* 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 */ /* stop character */
ustrcat(dest, "111"); strcat(dest, "111");
} }
/* Make a UPC-A barcode, allowing for composite if `cc_rows` set */ /* 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[], static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) {
int cc_rows) { unsigned char gtin[13];
char gtin[13];
float height; float height;
int error_number = 0; int error_number = 0;
ustrcpy(gtin, source); ustrcpy(gtin, source);
if (length == 11) { if (length == 11) {
gtin[length++] = upc_check(gtin, 11); gtin[length++] = gs1_check_digit(gtin, 11);
gtin[length] = '\0'; gtin[length] = '\0';
} else { } else {
if (source[length - 1] != upc_check(gtin, 11)) { if (source[length - 1] != gs1_check_digit(gtin, 11)) {
if (symbol->debug & ZINT_DEBUG_PRINT) { sprintf(symbol->errtxt, "270: Invalid check digit '%c', expecting '%c'",
printf("UPC-A: Invalid check digit %s, gtin: %s, Check digit: %c\n", source, gtin, source[length - 1], gs1_check_digit(gtin, 11));
upc_check(gtin, 11));
}
strcpy(symbol->errtxt, "270: Invalid check digit");
return ZINT_ERROR_INVALID_CHECK; return ZINT_ERROR_INVALID_CHECK;
} }
} }
@ -170,15 +153,15 @@ static int upca_cc(struct zint_symbol *symbol, const unsigned char source[], int
} }
/* UPC-A */ /* 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*/); return upca_cc(symbol, source, length, dest, 0 /*cc_rows*/);
} }
/* UPC-E, allowing for composite if `cc_rows` set */ /* 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[], static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int length, char dest[], int cc_rows) {
int cc_rows) {
int i, num_system; 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]; char hrt[9];
float height; float height;
int error_number = 0; 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]; equivalent[10] = source[4];
if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) { if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) {
/* Note 1 - "X3 shall not be equal to 0, 1 or 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; return ZINT_ERROR_INVALID_DATA;
} }
break; break;
@ -244,7 +227,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
equivalent[10] = source[4]; equivalent[10] = source[4];
if (source[3] == '0') { if (source[3] == '0') {
/* Note 2 - "X4 shall not be equal to 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; return ZINT_ERROR_INVALID_DATA;
} }
break; break;
@ -259,7 +242,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
equivalent[10] = emode; equivalent[10] = emode;
if (source[4] == '0') { if (source[4] == '0') {
/* Note 3 - "X5 shall not be equal to 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; return ZINT_ERROR_INVALID_DATA;
} }
break; 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 */ /* 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 */ /* Use the number system and check digit information to choose a parity scheme */
if (num_system == 1) { 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 */ /* Take all this information and make the barcode pattern */
/* start character */ /* start character */
ustrcat(dest, "111"); strcat(dest, "111");
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
switch (parity[i]) { switch (parity[i]) {
case 'A': lookup(NEON, EANsetA, source[i], (char *) dest); case 'A': lookup(NEON, EANsetA, source[i], dest);
break; break;
case 'B': lookup(NEON, EANsetB, source[i], (char *) dest); case 'B': lookup(NEON, EANsetB, source[i], dest);
break; break;
} }
} }
/* stop character */ /* stop character */
ustrcat(dest, "111111"); strcat(dest, "111111");
if (symbol->symbology != BARCODE_UPCE_CHK) { if (symbol->symbology != BARCODE_UPCE_CHK) {
hrt[7] = check_digit; hrt[7] = check_digit;
hrt[8] = '\0'; hrt[8] = '\0';
} else { } else {
if (hrt[7] != check_digit) { if (hrt[7] != check_digit) {
if (symbol->debug & ZINT_DEBUG_PRINT) { sprintf(symbol->errtxt, "274: Invalid check digit '%c', expecting '%c'", hrt[7], check_digit);
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");
return ZINT_ERROR_INVALID_CHECK; 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 */ /* 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*/); return upce_cc(symbol, source, length, dest, 0 /*cc_rows*/);
} }
/* EAN-2 and EAN-5 add-on codes */ /* 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]; char parity[6];
int i, code_type; int i, code_type;
/* If an add-on then append with space */ /* If an add-on then append with space */
if (addon_gap != 0) { if (addon_gap != 0) {
i = (int) ustrlen(dest); i = (int) strlen(dest);
dest[i] = itoc(addon_gap); dest[i] = itoc(addon_gap);
dest[i + 1] = '\0'; dest[i + 1] = '\0';
} }
/* Start character */ /* Start character */
ustrcat(dest, "112"); strcat(dest, "112");
/* Determine EAN2 or EAN5 add-on */ /* Determine EAN2 or EAN5 add-on */
if (length == 2) { 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++) { for (i = 0; i < length; i++) {
switch (parity[i]) { switch (parity[i]) {
case 'A': lookup(NEON, EANsetA, source[i], (char *) dest); case 'A': lookup(NEON, EANsetA, source[i], dest);
break; break;
case 'B': lookup(NEON, EANsetB, source[i], (char *) dest); case 'B': lookup(NEON, EANsetB, source[i], dest);
break; break;
} }
/* Glyph separator */ /* Glyph separator */
if (i != (length - 1)) { if (i != (length - 1)) {
ustrcat(dest, "11"); strcat(dest, "11");
} }
} }
} }
/* ************************ EAN-13 ****************** */ /* ************************ EAN-13 ****************** */
/* Calculate the correct check digit for a EAN-13 barcode (including ISBN(13)) */ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[],
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[],
int cc_rows) { int cc_rows) {
int i, half_way; int i, half_way;
char parity[6]; char parity[6];
char gtin[14]; unsigned char gtin[14];
float height; float height;
int error_number = 0; 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 */ /* Add the appropriate check digit */
if (length == 12) { if (length == 12) {
gtin[length++] = ean_check(gtin, 12); gtin[length++] = gs1_check_digit(gtin, 12);
gtin[length] = '\0'; gtin[length] = '\0';
} else { } else {
if (source[length - 1] != ean_check(gtin, 12)) { if (source[length - 1] != gs1_check_digit(gtin, 12)) {
if (symbol->debug & ZINT_DEBUG_PRINT) { sprintf(symbol->errtxt, "275: Invalid check digit '%c', expecting '%c'",
printf("EAN-13 Invalid check digit: %s, gtin: %s, Check digit: %c\n", source, gtin, source[length - 1], gs1_check_digit(gtin, 12));
ean_check(gtin, 12));
}
strcpy(symbol->errtxt, "275: Invalid check digit");
return ZINT_ERROR_INVALID_CHECK; 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; half_way = 7;
/* start character */ /* start character */
ustrcat(dest, "111"); strcat(dest, "111");
for (i = 1; i < length; i++) { for (i = 1; i < length; i++) {
if (i == half_way) { if (i == half_way) {
/* middle character - separates manufacturer no. from product no. */ /* middle character - separates manufacturer no. from product no. */
/* also inverses right hand characters */ /* also inverses right hand characters */
ustrcat(dest, "11111"); strcat(dest, "11111");
} }
if (((i > 1) && (i < 7)) && (parity[i - 2] == 'B')) { if (((i > 1) && (i < 7)) && (parity[i - 2] == 'B')) {
lookup(NEON, EANsetB, gtin[i], (char *) dest); lookup(NEON, EANsetB, gtin[i], dest);
} else { } else {
lookup(NEON, EANsetA, gtin[i], (char *) dest); lookup(NEON, EANsetA, gtin[i], dest);
} }
} }
/* stop character */ /* stop character */
ustrcat(dest, "111"); strcat(dest, "111");
ustrcpy(symbol->text, gtin); ustrcpy(symbol->text, gtin);
#ifdef COMPLIANT_HEIGHTS #ifdef COMPLIANT_HEIGHTS
@ -494,29 +453,25 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in
return error_number; 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*/); 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[], static int ean8_cc(struct zint_symbol *symbol, const unsigned char source[], int length, char dest[], int cc_rows) {
int cc_rows) {
/* EAN-8 is basically the same as UPC-A but with fewer digits */ /* EAN-8 is basically the same as UPC-A but with fewer digits */
char gtin[10]; unsigned char gtin[10];
float height; float height;
int error_number = 0; int error_number = 0;
ustrcpy(gtin, source); ustrcpy(gtin, source);
if (length == 7) { if (length == 7) {
gtin[length++] = upc_check(gtin, 7); gtin[length++] = gs1_check_digit(gtin, 7);
gtin[length] = '\0'; gtin[length] = '\0';
} else { } else {
if (source[length - 1] != upc_check(gtin, 7)) { if (source[length - 1] != gs1_check_digit(gtin, 7)) {
if (symbol->debug & ZINT_DEBUG_PRINT) { sprintf(symbol->errtxt, "276: Invalid check digit '%c', expecting '%c'",
printf("EAN-8: Invalid check digit %s, gtin: %s, Check digit: %c\n", source, gtin, source[length - 1], gs1_check_digit(gtin, 7));
upc_check(gtin, 7));
}
strcpy(symbol->errtxt, "276: Invalid check digit");
return ZINT_ERROR_INVALID_CHECK; 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 */ /* 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*/); 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 */ /* 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; int i, error_number;
char check_digit; char check_digit;
to_upper(source); 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) { 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; return error_number;
} }
/* Input must be 9, 10 or 13 characters */ /* Input must be 9, 10 or 13 characters */
if (src_len != 9 && src_len != 10 && src_len != 13) { 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; return ZINT_ERROR_TOO_LONG;
} }
if (src_len == 13) /* Using 13 character ISBN */ { if (src_len == 13) /* Using 13 character ISBN */ {
if (!(((source[0] == '9') && (source[1] == '7')) && if (!(((source[0] == '9') && (source[1] == '7')) &&
((source[2] == '8') || (source[2] == '9')))) { ((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; 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 (source[src_len - 1] != check_digit) {
if (symbol->debug & ZINT_DEBUG_PRINT) { sprintf(symbol->errtxt, "280: Incorrect ISBN check '%c', expecting '%c'",
printf("ISBN: Invalid check digit %s, Check digit: %c\n", source, check_digit); source[src_len - 1], check_digit);
}
strcpy(symbol->errtxt, "280: Incorrect ISBN check");
return ZINT_ERROR_INVALID_CHECK; return ZINT_ERROR_INVALID_CHECK;
} }
source[12] = '\0'; 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 */ { 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); check_digit = isbn_check(source, 9);
if (check_digit != source[9]) { if (check_digit != source[9]) {
if (symbol->debug & ZINT_DEBUG_PRINT) { sprintf(symbol->errtxt, "281: Incorrect %s check '%c', expecting '%c'", src_len == 9 ? "SBN" : "ISBN",
printf("ISBN(10)/SBN: Invalid check digit %s, Check digit: %c\n", source, check_digit); source[9], check_digit);
}
strcpy(symbol->errtxt, src_len == 9 ? "281: Incorrect SBN check" : "281: Incorrect ISBN check");
return ZINT_ERROR_INVALID_CHECK; return ZINT_ERROR_INVALID_CHECK;
} }
for (i = 11; i > 2; i--) { 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) { 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 */ unsigned char local_source[20] = {0}; /* Allow 13 + "+" + 5 + 1 */
char dest[1000] = {0};
int latch, reader, writer; int latch, reader, writer;
int with_addon; int with_addon;
int error_number, i, plus_count; 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; writer = 0;
if (src_len > 19) { 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; return ZINT_ERROR_TOO_LONG;
} }
if (symbol->symbology != BARCODE_ISBNX) { if (symbol->symbology != BARCODE_ISBNX) {
/* ISBN has its own checking routine */ /* 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) { 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; return error_number;
} }
} else { } 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) { 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; 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++) { for (i = 0; i < src_len; i++) {
if (source[i] == '+') { if (source[i] == '+') {
plus_count++; plus_count++;
}
}
if (plus_count > 1) { if (plus_count > 1) {
strcpy(symbol->errtxt, "293: Invalid add-on data"); strcpy(symbol->errtxt, "293: Invalid add-on data (one \"+\" only)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
}
}
/* Add leading zeroes, checking max lengths of parts */ /* Add leading zeroes, checking max lengths of parts */
if (!ean_leading_zeroes(symbol, source, local_source, &with_addon)) { 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; 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:
case BARCODE_EANX_CHK: case BARCODE_EANX_CHK:
switch (first_part_len) { 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); ustrcpy(symbol->text, first_part);
#ifdef COMPLIANT_HEIGHTS #ifdef COMPLIANT_HEIGHTS
/* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-5 */ /* 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*/); (void) set_height(symbol, 0.0f, height, 0.0f, 1 /*no_errtxt*/);
#endif #endif
break; 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); ustrcpy(symbol->text, first_part);
#ifdef COMPLIANT_HEIGHTS #ifdef COMPLIANT_HEIGHTS
/* 21.9mm from GS1 General Specifications 5.2.6.6, Figure 5.2.6.6-6 */ /* 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 12:
case 13: error_number = ean13(symbol, first_part, first_part_len, dest); case 13: error_number = ean13(symbol, first_part, first_part_len, dest);
break; 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; return ZINT_ERROR_TOO_LONG;
} }
break; break;
@ -928,7 +880,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
symbol->rows += 3; symbol->rows += 3;
error_number = ean13_cc(symbol, first_part, first_part_len, dest, cc_rows); error_number = ean13_cc(symbol, first_part, first_part_len, dest, cc_rows);
break; 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; return ZINT_ERROR_TOO_LONG;
} }
break; 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)) { if ((first_part_len == 11) || (first_part_len == 12)) {
error_number = upca(symbol, first_part, first_part_len, dest); error_number = upca(symbol, first_part, first_part_len, dest);
} else { } else {
strcpy(symbol->errtxt, "288: Input wrong length"); strcpy(symbol->errtxt, "288: Input wrong length"); // TODO: Better error message
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
break; break;
@ -955,7 +907,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
symbol->rows += 3; symbol->rows += 3;
error_number = upca_cc(symbol, first_part, first_part_len, dest, cc_rows); error_number = upca_cc(symbol, first_part, first_part_len, dest, cc_rows);
} else { } else {
strcpy(symbol->errtxt, "289: Input wrong length"); strcpy(symbol->errtxt, "289: Input wrong length"); // TODO: Better error message
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
break; 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))) { if ((first_part_len >= 6) && (first_part_len <= (symbol->symbology == BARCODE_UPCE ? 7 : 8))) {
error_number = upce(symbol, first_part, first_part_len, dest); error_number = upce(symbol, first_part, first_part_len, dest);
} else { } else {
strcpy(symbol->errtxt, "290: Input wrong length"); strcpy(symbol->errtxt, "290: Input wrong length"); // TODO: Better error message
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
break; break;
@ -982,7 +934,7 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
symbol->rows += 3; symbol->rows += 3;
error_number = upce_cc(symbol, first_part, first_part_len, dest, cc_rows); error_number = upce_cc(symbol, first_part, first_part_len, dest, cc_rows);
} else { } else {
strcpy(symbol->errtxt, "291: Input wrong length"); strcpy(symbol->errtxt, "291: Input wrong length"); // TODO: Better error message
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
break; break;
@ -1000,17 +952,17 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
switch (second_part_len) { switch (second_part_len) {
case 0: break; case 0: break;
case 2: 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, "+");
ustrcat(symbol->text, second_part); ustrcat(symbol->text, second_part);
break; break;
case 5: 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, "+");
ustrcat(symbol->text, second_part); ustrcat(symbol->text, second_part);
break; break;
default: 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; return ZINT_ERROR_TOO_LONG;
} }

View File

@ -1114,7 +1114,7 @@ ZINT_ERROR_INVALID_DATA | The data to be encoded includes characters which
| are not permitted by the selected symbology | are not permitted by the selected symbology
| (e.g. alphabetic characters in an EAN | (e.g. alphabetic characters in an EAN
| symbol). No symbol has been generated. | 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. | entered. No symbol has been generated.
ZINT_ERROR_INVALID_OPTION | One of the values in zint_struct was set ZINT_ERROR_INVALID_OPTION | One of the values in zint_struct was set
| incorrectly and Zint was unable to guess what | 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. | problem with legacy systems.
ZINT_ERROR_FILE_WRITE | Zint failed to write all contents to the ZINT_ERROR_FILE_WRITE | Zint failed to write all contents to the
| requested output file. This should only occur | 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: To catch errors use an integer variable as shown in the code below:

View File

@ -41,7 +41,7 @@
typedef int static_assert_int_at_least_32bits[CHAR_BIT != 8 || sizeof(int) < 4 ? -1 : 1]; typedef int static_assert_int_at_least_32bits[CHAR_BIT != 8 || sizeof(int) < 4 ? -1 : 1];
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
#endif #endif
/* Print list of supported symbologies */ /* 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" " --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" " --fullmultibyte Use multibyte for binary/Latin (QR/Han Xin/Grid Matrix)\n"
" --gs1 Treat input as GS1 compatible data\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" " --gssep Use separator GS for GS1 (Data Matrix)\n"
" -h, --help Display help message\n" " -h, --help Display help message\n"
" --height=NUMBER Set height of symbol in multiples of X-dimension\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" " --rotate=NUMBER Rotate symbol by NUMBER degrees\n"
" --rows=NUMBER Set number of rows (Codablock-F)\n" " --rows=NUMBER Set number of rows (Codablock-F)\n"
" --scale=NUMBER Adjust size of X-dimension\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" " --secure=NUMBER Set error correction level (ECC)\n"
" --separator=NUMBER Set height of row separator bars (stacked symbologies)\n" " --separator=NUMBER Set height of row separator bars (stacked symbologies)\n"
" --small Use small text\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; 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) { if (strcmp(lc_filetype, filetypes[i]) == 0) {
return 1; return 1;
} }
@ -486,7 +486,7 @@ static int is_raster(const char *filetype, const int no_png) {
return 0; 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) { if (strcmp(lc_filetype, raster_filetypes[i]) == 0) {
return 1; return 1;
} }

View File

@ -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); fprintf(stderr, "exec: failed to run '%s'\n", cmd);
return NULL; return NULL;
} }
cnt = fread(buf, 1, buf_size, fp); cnt = (int) fread(buf, 1, buf_size, fp);
if (fgetc(fp) != EOF) { if (fgetc(fp) != EOF) {
fprintf(stderr, "exec: failed to read full stream (%s)\n", cmd); fprintf(stderr, "exec: failed to read full stream (%s)\n", cmd);
testutil_pclose(fp); 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); fprintf(stderr, "arg_input: failed to open '%s' for writing\n", filename);
return 0; return 0;
} }
cnt = fwrite(input, 1, strlen(input), fp); cnt = (int) fwrite(input, 1, strlen(input), fp);
if (cnt != (int) strlen(input)) { if (cnt != (int) strlen(input)) {
fprintf(stderr, "arg_input: failed to write %d bytes, cnt %d written (%s)\n", (int) strlen(input), cnt, filename); fprintf(stderr, "arg_input: failed to write %d bytes, cnt %d written (%s)\n", (int) strlen(input), cnt, filename);
fclose(fp); fclose(fp);