CODABAR: fix [69c1b4] errtxt; CLI: _WIN32, fuller error messages; win32/README: Administrat-or

This commit is contained in:
gitlost 2021-06-12 16:01:16 +01:00
parent 69c1b4cbf0
commit 8ff15d805a
6 changed files with 118 additions and 112 deletions

View File

@ -67,12 +67,12 @@ INTERNAL int pharma_one(struct zint_symbol *symbol, unsigned char source[], int
char dest[64]; /* 17 * 2 + 1 */ char dest[64]; /* 17 * 2 + 1 */
if (length > 6) { if (length > 6) {
strcpy(symbol->errtxt, "350: Input too long (6 character maximum"); strcpy(symbol->errtxt, "350: Input too long (6 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, "351: Invalid characters in data"); strcpy(symbol->errtxt, "351: Invalid characters in data (digits only)");
return error_number; return error_number;
} }
@ -167,7 +167,7 @@ INTERNAL int pharma_two(struct zint_symbol *symbol, unsigned char source[], int
} }
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, "355: Invalid characters in data"); strcpy(symbol->errtxt, "355: Invalid characters in data (digits only)");
return error_number; return error_number;
} }
error_number = pharma_two_calc(symbol, source, height_pattern); error_number = pharma_two_calc(symbol, source, height_pattern);
@ -277,7 +277,7 @@ INTERNAL int code32(struct zint_symbol *symbol, unsigned char source[], int leng
} }
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, "361: Invalid characters in data"); strcpy(symbol->errtxt, "361: Invalid characters in data (digits only)");
return error_number; return error_number;
} }

View File

@ -345,7 +345,9 @@ static void test_encode_file_empty(void) {
(void)remove(filename); // In case junk hanging around (void)remove(filename); // In case junk hanging around
fstream = fopen(filename, "w+"); fstream = fopen(filename, "w+");
fclose(fstream); assert_nonnull(fstream, "fopen(%s) failed (%d)\n", filename, ferror(fstream));
ret = fclose(fstream);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
ret = ZBarcode_Encode_File(symbol, filename); ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File empty ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt); assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File empty ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
@ -372,9 +374,11 @@ static void test_encode_file_too_large(void) {
(void)remove(filename); // In case junk hanging around (void)remove(filename); // In case junk hanging around
fstream = fopen(filename, "w+"); fstream = fopen(filename, "w+");
assert_nonnull(fstream, "fopen(%s) failed (%d)\n", filename, ferror(fstream));
ret = fwrite(buf, 1, sizeof(buf), fstream); ret = fwrite(buf, 1, sizeof(buf), fstream);
assert_equal(ret, sizeof(buf), "fwrite retun value: %d != %d\n", ret, (int)sizeof(buf)); assert_equal(ret, sizeof(buf), "fwrite return value: %d != %d\n", ret, (int)sizeof(buf));
fclose(fstream); ret = fclose(fstream);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
ret = ZBarcode_Encode_File(symbol, filename); ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_File too large ret %d != ZINT_ERROR_TOO_LONG (%s)\n", ret, symbol->errtxt); assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_File too large ret %d != ZINT_ERROR_TOO_LONG (%s)\n", ret, symbol->errtxt);

View File

@ -143,35 +143,36 @@ static void test_input(int index, int debug) {
int ret; int ret;
int expected_rows; int expected_rows;
int expected_width; int expected_width;
const char *expected_errtxt;
}; };
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) // s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = { struct item data[] = {
/* 0*/ { BARCODE_CODABAR, "A1234B", 0, 1, 62 }, /* 0*/ { BARCODE_CODABAR, "A1234B", 0, 1, 62, "" },
/* 1*/ { BARCODE_CODABAR, "1234B", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 1*/ { BARCODE_CODABAR, "1234B", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 358: Does not begin with \"A\", \"B\", \"C\" or \"D\"" },
/* 2*/ { BARCODE_CODABAR, "A1234", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 2*/ { BARCODE_CODABAR, "A1234", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 359: Does not end with \"A\", \"B\", \"C\" or \"D\"" },
/* 3*/ { BARCODE_CODABAR, "A1234E", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 3*/ { BARCODE_CODABAR, "A1234E", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 359: Does not end with \"A\", \"B\", \"C\" or \"D\"" },
/* 4*/ { BARCODE_CODABAR, "C123.D", 0, 1, 63 }, /* 4*/ { BARCODE_CODABAR, "C123.D", 0, 1, 63, "" },
/* 5*/ { BARCODE_CODABAR, "C123,D", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 5*/ { BARCODE_CODABAR, "C123,D", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 357: Invalid characters in data" },
/* 6*/ { BARCODE_CODABAR, "D:C", 0, 1, 33 }, /* 6*/ { BARCODE_CODABAR, "D:C", 0, 1, 33, "" },
/* 7*/ { BARCODE_CODABAR, "DCC", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 7*/ { BARCODE_CODABAR, "DCC", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 363: Cannot contain \"A\", \"B\", \"C\" or \"D\"" },
/* 8*/ { BARCODE_CODABAR, "AB", ZINT_ERROR_TOO_LONG, -1, -1 }, /* 8*/ { BARCODE_CODABAR, "AB", ZINT_ERROR_TOO_LONG, -1, -1, "Error 362: Input too short (3 character minimum)" },
/* 9*/ { BARCODE_PHARMA, "131070", 0, 1, 78 }, /* 9*/ { BARCODE_PHARMA, "131070", 0, 1, 78, "" },
/* 10*/ { BARCODE_PHARMA, "131071", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 10*/ { BARCODE_PHARMA, "131071", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 352: Data out of range (3 to 131070)" },
/* 11*/ { BARCODE_PHARMA, "3", 0, 1, 4 }, /* 11*/ { BARCODE_PHARMA, "3", 0, 1, 4, "" },
/* 12*/ { BARCODE_PHARMA, "2", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 12*/ { BARCODE_PHARMA, "2", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 352: Data out of range (3 to 131070)" },
/* 13*/ { BARCODE_PHARMA, "1", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 13*/ { BARCODE_PHARMA, "1", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 352: Data out of range (3 to 131070)" },
/* 14*/ { BARCODE_PHARMA, "12A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 14*/ { BARCODE_PHARMA, "12A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 351: Invalid characters in data (digits only)" },
/* 15*/ { BARCODE_PHARMA_TWO, "64570080", 0, 2, 31 }, /* 15*/ { BARCODE_PHARMA_TWO, "64570080", 0, 2, 31, "" },
/* 16*/ { BARCODE_PHARMA_TWO, "64570081", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 16*/ { BARCODE_PHARMA_TWO, "64570081", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 353: Data out of range (4 to 64570080)" },
/* 17*/ { BARCODE_PHARMA_TWO, "4", 0, 2, 3 }, /* 17*/ { BARCODE_PHARMA_TWO, "4", 0, 2, 3, "" },
/* 18*/ { BARCODE_PHARMA_TWO, "3", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 18*/ { BARCODE_PHARMA_TWO, "3", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 353: Data out of range (4 to 64570080)" },
/* 19*/ { BARCODE_PHARMA_TWO, "2", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 19*/ { BARCODE_PHARMA_TWO, "2", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 353: Data out of range (4 to 64570080)" },
/* 20*/ { BARCODE_PHARMA_TWO, "1", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 20*/ { BARCODE_PHARMA_TWO, "1", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 353: Data out of range (4 to 64570080)" },
/* 21*/ { BARCODE_PHARMA_TWO, "123A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 21*/ { BARCODE_PHARMA_TWO, "123A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 355: Invalid characters in data (digits only)" },
/* 22*/ { BARCODE_CODE32, "12345678", 0, 1, 103 }, /* 22*/ { BARCODE_CODE32, "12345678", 0, 1, 103, "" },
/* 22*/ { BARCODE_CODE32, "9", 0, 1, 103 }, /* 23*/ { BARCODE_CODE32, "9", 0, 1, 103, "" },
/* 22*/ { BARCODE_CODE32, "0", 0, 1, 103 }, /* 24*/ { BARCODE_CODE32, "0", 0, 1, 103, "" },
/* 22*/ { BARCODE_CODE32, "A", ZINT_ERROR_INVALID_DATA, -1, -1 }, /* 25*/ { BARCODE_CODE32, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 361: Invalid characters in data (digits only)" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -191,6 +192,7 @@ static void test_input(int index, int debug) {
assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows); assert_equal(symbol->rows, data[i].expected_rows, "i:%d symbol->rows %d != %d\n", i, symbol->rows, data[i].expected_rows);
assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width); assert_equal(symbol->width, data[i].expected_width, "i:%d symbol->width %d != %d\n", i, symbol->width, data[i].expected_width);
} }
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d symbol->errtxt %s != %s\n", i, symbol->errtxt, data[i].expected_errtxt);
ZBarcode_Delete(symbol); ZBarcode_Delete(symbol);
} }

View File

@ -98,7 +98,6 @@ static void types(void) {
} }
/* Output usage information */ /* Output usage information */
static void usage(void) { static void usage(void) {
int zint_version = ZBarcode_Version(); int zint_version = ZBarcode_Version();
int version_major = zint_version / 10000; int version_major = zint_version / 10000;
@ -391,13 +390,12 @@ static int get_barcode_name(const char *barcode_name) {
while (s <= e) { while (s <= e) {
int m = (s + e) / 2; int m = (s + e) / 2;
int cmp = strcmp(names[m].n, n); int cmp = strcmp(names[m].n, n);
if (cmp == 0) {
return names[m].symbology;
}
if (cmp < 0) { if (cmp < 0) {
s = m + 1; s = m + 1;
} else { } else if (cmp > 0) {
e = m - 1; e = m - 1;
} else {
return names[m].symbology;
} }
} }
@ -680,10 +678,10 @@ static int batch_process(struct zint_symbol *symbol, const char *filename, const
} }
/* Stuff to convert args on Windows command line to UTF-8 */ /* Stuff to convert args on Windows command line to UTF-8 */
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(_MSC_VER) #ifdef _WIN32
#define ZINT_WIN
#include <windows.h> #include <windows.h>
#include <shellapi.h> #include <shellapi.h>
#ifndef WC_ERR_INVALID_CHARS #ifndef WC_ERR_INVALID_CHARS
#define WC_ERR_INVALID_CHARS 0x00000080 #define WC_ERR_INVALID_CHARS 0x00000080
#endif #endif
@ -738,11 +736,11 @@ static void win_args(int *p_argc, char ***p_argv) {
} }
} }
} }
#endif #endif /* _WIN32 */
/* Helper to free Windows args on exit */ /* Helper to free Windows args on exit */
static int do_exit(int error_number) { static int do_exit(int error_number) {
#ifdef ZINT_WIN #ifdef _WIN32
win_free_args(); win_free_args();
#endif #endif
exit(error_number); exit(error_number);
@ -791,7 +789,7 @@ int main(int argc, char **argv) {
no_png = strcmp(my_symbol->outfile, "out.gif") == 0; no_png = strcmp(my_symbol->outfile, "out.gif") == 0;
my_symbol->input_mode = UNICODE_MODE; my_symbol->input_mode = UNICODE_MODE;
#ifdef ZINT_WIN #ifdef _WIN32
win_args(&argc, &argv); win_args(&argc, &argv);
#endif #endif
@ -869,13 +867,13 @@ int main(int argc, char **argv) {
switch (c) { switch (c) {
case OPT_ADDONGAP: case OPT_ADDONGAP:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 139: Invalid add-on gap value\n"); fprintf(stderr, "Error 139: Invalid add-on gap value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val >= 7 && val <= 12) { if (val >= 7 && val <= 12) {
addon_gap = val; addon_gap = val;
} else { } else {
fprintf(stderr, "Warning 140: Invalid add-on gap value\n"); fprintf(stderr, "Warning 140: Add-on gap out of range (7 to 12), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -902,13 +900,13 @@ int main(int argc, char **argv) {
break; break;
case OPT_BORDER: case OPT_BORDER:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 107: Invalid border width value\n"); fprintf(stderr, "Error 107: Invalid border width value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val <= 1000) { /* `val` >= 0 always */ if (val <= 1000) { /* `val` >= 0 always */
my_symbol->border_width = val; my_symbol->border_width = val;
} else { } else {
fprintf(stderr, "Warning 108: Border width out of range\n"); fprintf(stderr, "Warning 108: Border width out of range (0 to 1000), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -920,13 +918,13 @@ int main(int argc, char **argv) {
break; break;
case OPT_COLS: case OPT_COLS:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 131: Invalid columns value\n"); fprintf(stderr, "Error 131: Invalid columns value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if ((val >= 1) && (val <= 200)) { if ((val >= 1) && (val <= 200)) {
my_symbol->option_2 = val; my_symbol->option_2 = val;
} else { } else {
fprintf(stderr, "Warning 111: Number of columns out of range\n"); fprintf(stderr, "Warning 111: Number of columns out of range (1 to 200), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -943,7 +941,7 @@ int main(int argc, char **argv) {
my_symbol->dot_size = (float) (atof(optarg)); my_symbol->dot_size = (float) (atof(optarg));
if (my_symbol->dot_size < 0.01f) { if (my_symbol->dot_size < 0.01f) {
/* Zero and negative values are not permitted */ /* Zero and negative values are not permitted */
fprintf(stderr, "Warning 106: Invalid dot radius value\n"); fprintf(stderr, "Warning 106: Invalid dot radius value (less than 0.01), ignoring\n");
fflush(stderr); fflush(stderr);
my_symbol->dot_size = 4.0f / 5.0f; my_symbol->dot_size = 4.0f / 5.0f;
} }
@ -957,13 +955,13 @@ int main(int argc, char **argv) {
break; break;
case OPT_ECI: case OPT_ECI:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 138: Invalid ECI value\n"); fprintf(stderr, "Error 138: Invalid ECI value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val <= 999999) { /* `val` >= 0 always */ if (val <= 999999) { /* `val` >= 0 always */
my_symbol->eci = val; my_symbol->eci = val;
} else { } else {
fprintf(stderr, "Warning 118: Invalid ECI code\n"); fprintf(stderr, "Warning 118: ECI code out of range (0 to 999999), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -988,13 +986,13 @@ int main(int argc, char **argv) {
break; break;
case OPT_FONTSIZE: case OPT_FONTSIZE:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 130: Invalid font size value\n"); fprintf(stderr, "Error 130: Invalid font size value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val <= 100) { /* `val` >= 0 always */ if (val <= 100) { /* `val` >= 0 always */
my_symbol->fontsize = val; my_symbol->fontsize = val;
} else { } else {
fprintf(stderr, "Warning 126: Invalid font size\n"); fprintf(stderr, "Warning 126: Font size out of range (0 to 100), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -1012,13 +1010,13 @@ int main(int argc, char **argv) {
break; break;
case OPT_HEIGHT: case OPT_HEIGHT:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 109: Invalid symbol height value\n"); fprintf(stderr, "Error 109: Invalid symbol height value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if ((val >= 1) && (val <= 1000)) { if ((val >= 1) && (val <= 1000)) {
my_symbol->height = val; my_symbol->height = val;
} else { } else {
fprintf(stderr, "Warning 110: Symbol height out of range\n"); fprintf(stderr, "Warning 110: Symbol height out of range (1 to 1000), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -1031,12 +1029,12 @@ int main(int argc, char **argv) {
break; break;
case OPT_MASK: case OPT_MASK:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 148: Invalid mask value\n"); fprintf(stderr, "Error 148: Invalid mask value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val > 7) { /* `val` >= 0 always */ if (val > 7) { /* `val` >= 0 always */
/* mask pattern >= 0 and <= 7 (i.e. values >= 1 and <= 8) only permitted */ /* mask pattern >= 0 and <= 7 (i.e. values >= 1 and <= 8) only permitted */
fprintf(stderr, "Warning 147: Invalid mask value\n"); fprintf(stderr, "Warning 147: Mask value out of range (0 to 7), ignoring\n");
fflush(stderr); fflush(stderr);
} else { } else {
mask = val + 1; mask = val + 1;
@ -1044,13 +1042,13 @@ int main(int argc, char **argv) {
break; break;
case OPT_MODE: case OPT_MODE:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 136: Invalid mode value\n"); fprintf(stderr, "Error 136: Invalid mode value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val <= 6) { /* `val` >= 0 always */ if (val <= 6) { /* `val` >= 0 always */
my_symbol->option_1 = val; my_symbol->option_1 = val;
} else { } else {
fprintf(stderr, "Warning 116: Invalid mode\n"); fprintf(stderr, "Warning 116: Mode value out of range (0 to 6), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -1064,14 +1062,14 @@ int main(int argc, char **argv) {
if (strlen(optarg) <= 127) { if (strlen(optarg) <= 127) {
strcpy(my_symbol->primary, optarg); strcpy(my_symbol->primary, optarg);
} else { } else {
fprintf(stderr, "Warning 115: Primary data string too long, ignoring\n"); fprintf(stderr, "Warning 115: Primary data string too long (127 character maximum), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
case OPT_ROTATE: case OPT_ROTATE:
/* Only certain inputs allowed */ /* Only certain inputs allowed */
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 117: Invalid rotation value\n"); fprintf(stderr, "Error 117: Invalid rotation value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
switch (val) { switch (val) {
@ -1084,20 +1082,21 @@ int main(int argc, char **argv) {
case 0: rotate_angle = 0; case 0: rotate_angle = 0;
break; break;
default: default:
fprintf(stderr, "Warning 137: Invalid rotation parameter\n"); fprintf(stderr,
"Warning 137: Invalid rotation parameter (0, 90, 180 or 270 only), ignoring\n");
fflush(stderr); fflush(stderr);
break; break;
} }
break; break;
case OPT_ROWS: case OPT_ROWS:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 132: Invalid rows value\n"); fprintf(stderr, "Error 132: Invalid rows value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if ((val >= 1) && (val <= 44)) { if ((val >= 1) && (val <= 44)) {
my_symbol->option_1 = val; my_symbol->option_1 = val;
} else { } else {
fprintf(stderr, "Warning 112: Number of rows out of range\n"); fprintf(stderr, "Warning 112: Number of rows out of range (1 to 44), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -1105,46 +1104,47 @@ int main(int argc, char **argv) {
my_symbol->scale = (float) (atof(optarg)); my_symbol->scale = (float) (atof(optarg));
if (my_symbol->scale < 0.01f) { if (my_symbol->scale < 0.01f) {
/* Zero and negative values are not permitted */ /* Zero and negative values are not permitted */
fprintf(stderr, "Warning 105: Invalid scale value\n"); fprintf(stderr, "Warning 105: Invalid scale value (less than 0.01), ignoring\n");
fflush(stderr); fflush(stderr);
my_symbol->scale = 1.0f; my_symbol->scale = 1.0f;
} }
break; break;
case OPT_SCMVV: case OPT_SCMVV:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 149: Invalid Structured Carrier Message version value\n"); fprintf(stderr, "Error 149: Invalid Structured Carrier Message version value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val <= 99) { /* `val` >= 0 always */ if (val <= 99) { /* `val` >= 0 always */
my_symbol->option_2 = val + 1; my_symbol->option_2 = val + 1;
} else { } else {
/* Version 00-99 only */ /* Version 00-99 only */
fprintf(stderr, "Warning 150: Invalid version (vv) for Structured Carrier Message, ignoring\n"); fprintf(stderr,
"Warning 150: Structured Carrier Message version out of range (0 to 99), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
case OPT_SECURE: case OPT_SECURE:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 134: Invalid ECC value\n"); fprintf(stderr, "Error 134: Invalid ECC value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val <= 8) { /* `val` >= 0 always */ if (val <= 8) { /* `val` >= 0 always */
my_symbol->option_1 = val; my_symbol->option_1 = val;
} else { } else {
fprintf(stderr, "Warning 114: ECC level out of range\n"); fprintf(stderr, "Warning 114: ECC level out of range (0 to 8), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
case OPT_SEPARATOR: case OPT_SEPARATOR:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 128: Invalid separator value\n"); fprintf(stderr, "Error 128: Invalid separator value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if (val <= 4) { /* `val` >= 0 always */ if (val <= 4) { /* `val` >= 0 always */
separator = val; separator = val;
} else { } else {
/* Greater than 4 values are not permitted */ /* Greater than 4 values are not permitted */
fprintf(stderr, "Warning 127: Invalid separator value\n"); fprintf(stderr, "Warning 127: Separator value out of range (0 to 4), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -1159,25 +1159,25 @@ int main(int argc, char **argv) {
break; break;
case OPT_VERS: case OPT_VERS:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 133: Invalid version value\n"); fprintf(stderr, "Error 133: Invalid version value (digits only)\n");
return do_exit(1); return do_exit(1);
} }
if ((val >= 1) && (val <= 84)) { if ((val >= 1) && (val <= 84)) {
my_symbol->option_2 = val; my_symbol->option_2 = val;
} else { } else {
fprintf(stderr, "Warning 113: Invalid version\n"); fprintf(stderr, "Warning 113: Version value out of range (1 to 84), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
case OPT_VWHITESP: case OPT_VWHITESP:
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 153: Invalid vertical whitespace value '%s'\n", optarg); fprintf(stderr, "Error 153: Invalid vertical whitespace value '%s' (digits only)\n", optarg);
return do_exit(1); return do_exit(1);
} }
if (val <= 1000) { /* `val` >= 0 always */ if (val <= 1000) { /* `val` >= 0 always */
my_symbol->whitespace_height = val; my_symbol->whitespace_height = val;
} else { } else {
fprintf(stderr, "Warning 154: Vertical whitespace value out of range\n"); fprintf(stderr, "Warning 154: Vertical whitespace value out of range (0 to 1000), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;
@ -1213,13 +1213,13 @@ int main(int argc, char **argv) {
case 'w': case 'w':
if (!validate_int(optarg, &val)) { if (!validate_int(optarg, &val)) {
fprintf(stderr, "Error 120: Invalid horizontal whitespace value '%s'\n", optarg); fprintf(stderr, "Error 120: Invalid horizontal whitespace value '%s' (digits only)\n", optarg);
return do_exit(1); return do_exit(1);
} }
if (val <= 1000) { /* `val` >= 0 always */ if (val <= 1000) { /* `val` >= 0 always */
my_symbol->whitespace_width = val; my_symbol->whitespace_width = val;
} else { } else {
fprintf(stderr, "Warning 121: Horizontal whitespace value out of range\n"); fprintf(stderr, "Warning 121: Horizontal whitespace value out of range (0 to 1000), ignoring\n");
fflush(stderr); fflush(stderr);
} }
break; break;

View File

@ -625,40 +625,40 @@ static void test_checks(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*/ { -2, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 139: Invalid add-on gap value" }, /* 0*/ { -2, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 139: Invalid add-on gap value (digits only)" },
/* 1*/ { 6, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 140: Invalid add-on gap value" }, /* 1*/ { 6, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 140: Add-on gap out of range (7 to 12), ignoring" },
/* 2*/ { 13, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 140: Invalid add-on gap value" }, /* 2*/ { 13, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 140: Add-on gap out of range (7 to 12), ignoring" },
/* 3*/ { -1, -2, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 107: Invalid border width value" }, /* 3*/ { -1, -2, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 107: Invalid border width value (digits only)" },
/* 4*/ { -1, 1001, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 108: Border width out of range" }, /* 4*/ { -1, 1001, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 108: Border width out of range (0 to 1000), ignoring" },
/* 5*/ { -1, -1, -1, 0.009, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 106: Invalid dot radius value" }, /* 5*/ { -1, -1, -1, 0.009, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 106: Invalid dot radius value (less than 0.01), ignoring" },
/* 6*/ { -1, -1, -2, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 131: Invalid columns value" }, /* 6*/ { -1, -1, -2, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 131: Invalid columns value (digits only)" },
/* 7*/ { -1, -1, 201, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 111: Number of columns out of range" }, /* 7*/ { -1, -1, 201, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 111: Number of columns out of range (1 to 200), ignoring" },
/* 8*/ { -1, -1, -1, -1, -2, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 138: Invalid ECI value" }, /* 8*/ { -1, -1, -1, -1, -2, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 138: Invalid ECI value (digits only)" },
/* 9*/ { -1, -1, -1, -1, 1000000, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 118: Invalid ECI code" }, /* 9*/ { -1, -1, -1, -1, 1000000, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 118: ECI code out of range (0 to 999999), ignoring" },
/* 10*/ { -1, -1, -1, -1, -1, "jpg", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 142: File type 'jpg' not supported, ignoring" }, /* 10*/ { -1, -1, -1, -1, -1, "jpg", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 142: File type 'jpg' not supported, ignoring" },
/* 11*/ { -1, -1, -1, -1, -1, NULL, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 109: Invalid symbol height value" }, /* 11*/ { -1, -1, -1, -1, -1, NULL, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 109: Invalid symbol height value (digits only)" },
/* 12*/ { -1, -1, -1, -1, -1, NULL, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 110: Symbol height out of range" }, /* 12*/ { -1, -1, -1, -1, -1, NULL, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 110: Symbol height out of range (1 to 1000), ignoring" },
/* 13*/ { -1, -1, -1, -1, -1, NULL, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 148: Invalid mask value" }, /* 13*/ { -1, -1, -1, -1, -1, NULL, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 148: Invalid mask value (digits only)" },
/* 14*/ { -1, -1, -1, -1, -1, NULL, -1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 147: Invalid mask value" }, /* 14*/ { -1, -1, -1, -1, -1, NULL, -1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 147: Mask value out of range (0 to 7), ignoring" },
/* 15*/ { -1, -1, -1, -1, -1, NULL, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 116: Invalid mode" }, /* 15*/ { -1, -1, -1, -1, -1, NULL, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 116: Mode value out of range (0 to 6), ignoring" },
/* 16*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, "Error 117: Invalid rotation value" }, /* 16*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, "Error 117: Invalid rotation value (digits only)" },
/* 17*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 137: Invalid rotation parameter" }, /* 17*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 137: Invalid rotation parameter (0, 90, 180 or 270 only), ignoring" },
/* 18*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, "Error 132: Invalid rows value" }, /* 18*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, "Error 132: Invalid rows value (digits only)" },
/* 19*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, -1, "Warning 112: Number of rows out of range" }, /* 19*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, -1, "Warning 112: Number of rows out of range (1 to 44), ignoring" },
/* 20*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, "Warning 105: Invalid scale value" }, /* 20*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, "Warning 105: Invalid scale value (less than 0.01), ignoring" },
/* 21*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, 0.49, -1, -1, -1, -1, -1, -1, "Warning 146: Scaling less than 0.5 will be set to 0.5 for 'gif' output" }, /* 21*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, 0.49, -1, -1, -1, -1, -1, -1, "Warning 146: Scaling less than 0.5 will be set to 0.5 for 'gif' output" },
/* 22*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, "Error 149: Invalid Structured Carrier Message version value" }, /* 22*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, "Error 149: Invalid Structured Carrier Message version value (digits only)" },
/* 23*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, 100, -1, -1, -1, -1, -1, "Warning 150: Invalid version (vv) for Structured Carrier Message, ignoring" }, /* 23*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, 100, -1, -1, -1, -1, -1, "Warning 150: Structured Carrier Message version out of range (0 to 99), ignoring" },
/* 24*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, "Error 134: Invalid ECC value" }, /* 24*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, "Error 134: Invalid ECC value (digits only)" },
/* 25*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, 9, -1, -1, -1, -1, "Warning 114: ECC level out of range" }, /* 25*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, 9, -1, -1, -1, -1, "Warning 114: ECC level out of range (0 to 8), ignoring" },
/* 26*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, "Error 128: Invalid separator value" }, /* 26*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, "Error 128: Invalid separator value (digits only)" },
/* 27*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, 5, -1, -1, -1, "Warning 127: Invalid separator value" }, /* 27*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, 5, -1, -1, -1, "Warning 127: Separator value out of range (0 to 4), ignoring" },
/* 28*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, "Error 133: Invalid version value" }, /* 28*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, "Error 133: Invalid version value (digits only)" },
/* 29*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, 85, -1, -1, "Warning 113: Invalid version" }, /* 29*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, 85, -1, -1, "Warning 113: Version value out of range (1 to 84), ignoring" },
/* 30*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, "Error 153: Invalid vertical whitespace value '-2'" }, /* 30*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, "Error 153: Invalid vertical whitespace value '-2' (digits only)" },
/* 31*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, -1, "Warning 154: Vertical whitespace value out of range" }, /* 31*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, -1, "Warning 154: Vertical whitespace value out of range (0 to 1000), ignoring" },
/* 32*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, "Error 120: Invalid horizontal whitespace value '-2'" }, /* 32*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, "Error 120: Invalid horizontal whitespace value '-2' (digits only)" },
/* 33*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, "Warning 121: Horizontal whitespace value out of range" }, /* 33*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, "Warning 121: Horizontal whitespace value out of range (0 to 1000), ignoring" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -894,7 +894,7 @@ static void test_other_opts(int index, int debug) {
/* 5*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000F", "Error 651: Malformed foreground colour target" }, /* 5*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000F", "Error 651: Malformed foreground colour target" },
/* 6*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000FG", "Error 653: Malformed foreground colour target" }, /* 6*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000FG", "Error 653: Malformed foreground colour target" },
/* 7*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "10", "" }, /* 7*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "10", "" },
/* 8*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "101", "Warning 126: Invalid font size" }, /* 8*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "101", "Warning 126: Font size out of range (0 to 100), ignoring" },
/* 9*/ { BARCODE_CODE128, "1", -1, " --nobackground", "", "" }, /* 9*/ { BARCODE_CODE128, "1", -1, " --nobackground", "", "" },
/* 10*/ { BARCODE_CODE128, "1", -1, " --notext", "", "" }, /* 10*/ { BARCODE_CODE128, "1", -1, " --notext", "", "" },
/* 11*/ { BARCODE_CODE128, "1", -1, " --reverse", "", "" }, /* 11*/ { BARCODE_CODE128, "1", -1, " --reverse", "", "" },

View File

@ -150,7 +150,7 @@ zint using CMake)
cd .. cd ..
CMake needs to be able to find zlib and lpng. One way to do this (requires CMake needs to be able to find zlib and lpng. One way to do this (requires
Administration privileges) is to create two sub-directories in Administrator privileges) is to create two sub-directories in
"C:\Program Files (x86)" called "include" and "lib", and then copy "C:\Program Files (x86)" called "include" and "lib", and then copy
"zlib\zlib.h", "zlib\zconf.h", "lpng\png.h", "lpng\pngconf.h" and "zlib\zlib.h", "zlib\zconf.h", "lpng\png.h", "lpng\pngconf.h" and