CLI: Handle UTF-8 args on Windows; -b <barcode name>

This commit is contained in:
gitlost 2021-01-20 21:15:03 +00:00
parent 4efbd46f86
commit 484bd6e19a
12 changed files with 2101 additions and 1568 deletions

View File

@ -667,7 +667,7 @@ static int gm_encode(unsigned int gbdata[], const int length, char binary[], con
if (shift == 0) { if (shift == 0) {
/* Mixed Mode character */ /* Mixed Mode character */
glyph = posn(EUROPIUM, gbdata[sp]); glyph = posn(EUROPIUM, (const char) gbdata[sp]);
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
@ -692,7 +692,7 @@ static int gm_encode(unsigned int gbdata[], const int length, char binary[], con
if (shift == 0) { if (shift == 0) {
/* Upper Case character */ /* Upper Case character */
glyph = posn("ABCDEFGHIJKLMNOPQRSTUVWXYZ ", gbdata[sp]); glyph = posn("ABCDEFGHIJKLMNOPQRSTUVWXYZ ", (const char) gbdata[sp]);
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
@ -717,7 +717,7 @@ static int gm_encode(unsigned int gbdata[], const int length, char binary[], con
if (shift == 0) { if (shift == 0) {
/* Lower Case character */ /* Lower Case character */
glyph = posn("abcdefghijklmnopqrstuvwxyz ", gbdata[sp]); glyph = posn("abcdefghijklmnopqrstuvwxyz ", (const char) gbdata[sp]);
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }

View File

@ -1307,6 +1307,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
} }
return error_tag(symbol->errtxt, error_number); return error_tag(symbol->errtxt, error_number);
} }
if (error_number && warn_number == 0) {
warn_number = error_number;
}
ustrcpy(local_source, reduced); // Cannot contain nul char ustrcpy(local_source, reduced); // Cannot contain nul char
in_length = (int) ustrlen(local_source); in_length = (int) ustrlen(local_source);
} }

View File

@ -2,7 +2,7 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -36,6 +36,10 @@
#include <malloc.h> #include <malloc.h>
#include <fcntl.h> #include <fcntl.h>
#include <io.h> #include <io.h>
/* For Visual C++ 6 suppress conversion from int to float warning */
#if _MSC_VER == 1200
#pragma warning(disable: 4244)
#endif
#endif #endif
#include <math.h> #include <math.h>
#include <assert.h> #include <assert.h>

View File

@ -1608,7 +1608,7 @@ static void test_ean128_cc_width(int index, int generate, int debug) {
/* 8*/ { "[91]123A1234A", "[02]13012345678909", 0, 5, 174, "" }, /* 8*/ { "[91]123A1234A", "[02]13012345678909", 0, 5, 174, "" },
/* 9*/ { "[91]123A1234A1", "[02]13012345678909", 0, 5, 188, "" }, /* 9*/ { "[91]123A1234A1", "[02]13012345678909", 0, 5, 188, "" },
/*10*/ { "[91]123A1234A12", "[02]13012345678909", 0, 5, 205, "" }, /*10*/ { "[91]123A1234A12", "[02]13012345678909", 0, 5, 205, "" },
/*11*/ { "[00]123456789012345675", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345678[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[91]1234567890", 0, 32, 579, "With composite 2372 digits == max" }, /*11*/ { "[00]123456789012345675", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[91]1234567890", 0, 32, 579, "With composite 2372 digits == max" },
/*12*/ { "[00]123456789012345675", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[91]12345678901", ZINT_ERROR_TOO_LONG, 0, 0, "With composite 2373 digits > max" }, /*12*/ { "[00]123456789012345675", "[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[00]123456789012345675[91]12345678901", ZINT_ERROR_TOO_LONG, 0, 0, "With composite 2373 digits > max" },
}; };
int data_size = sizeof(data) / sizeof(struct item); int data_size = sizeof(data) / sizeof(struct item);

View File

@ -69,7 +69,7 @@ static void test_input(int index, int generate, int debug) {
/* 20*/ { UNICODE_MODE, -1, "[)>\03606A\004", -1, 0, "6A 64 10 16 21", "[)>RS 06 A EOT; LatchB (0x6A) Macro100 (0x64) 0 6 A" }, /* 20*/ { UNICODE_MODE, -1, "[)>\03606A\004", -1, 0, "6A 64 10 16 21", "[)>RS 06 A EOT; LatchB (0x6A) Macro100 (0x64) 0 6 A" },
/* 21*/ { UNICODE_MODE, -1, "[)>\036991\036\004", -1, 0, "6A 64 19 19 11 64", "[)>RS 99 1 RS EOT; LatchB (0x6A) Macro100 (0x64) 9 9 1 RS" }, /* 21*/ { UNICODE_MODE, -1, "[)>\036991\036\004", -1, 0, "6A 64 19 19 11 64", "[)>RS 99 1 RS EOT; LatchB (0x6A) Macro100 (0x64) 9 9 1 RS" },
/* 22*/ { UNICODE_MODE, -1, "1712345610", -1, 0, "6B 64 0C 22 38", "FNC1 (0x6B) 17..10 12 34 56" }, /* 22*/ { UNICODE_MODE, -1, "1712345610", -1, 0, "6B 64 0C 22 38", "FNC1 (0x6B) 17..10 12 34 56" },
/* 23*/ { GS1_MODE, -1, "[17]123456[10]123", -1, 0, "64 0C 22 38 0C 66 13", "17..10 12 34 56 12 ShiftB (0x66) 3" }, /* 23*/ { GS1_MODE, -1, "[17]123456[10]123", -1, ZINT_WARN_NONCOMPLIANT, "Warning 64 0C 22 38 0C 66 13", "17..10 12 34 56 12 ShiftB (0x66) 3" },
/* 24*/ { GS1_MODE, -1, "[90]ABC[90]abc[90]123", -1, 0, "5A 6A 21 22 23 6B 19 10 41 42 43 6B 19 67 01 17", "90 LatchB (0x6A) A B C FNC1 (0x6B) 9 0 a b c FNC1 (0x6B) 9 2xShitfC (0x67) 01 23" }, /* 24*/ { GS1_MODE, -1, "[90]ABC[90]abc[90]123", -1, 0, "5A 6A 21 22 23 6B 19 10 41 42 43 6B 19 67 01 17", "90 LatchB (0x6A) A B C FNC1 (0x6B) 9 0 a b c FNC1 (0x6B) 9 2xShitfC (0x67) 01 23" },
/* 25*/ { UNICODE_MODE, -1, "99aA[{00\000", 9, 0, "6B 63 6A 41 21 3B 5B 10 10 65 40", "FNC1 (0x6B) 99 LatchB (0x6A) a A [ { 0 0 ShiftA (0x65) NUL" }, /* 25*/ { UNICODE_MODE, -1, "99aA[{00\000", 9, 0, "6B 63 6A 41 21 3B 5B 10 10 65 40", "FNC1 (0x6B) 99 LatchB (0x6A) a A [ { 0 0 ShiftA (0x65) NUL" },
/* 26*/ { UNICODE_MODE, -1, "\015\012", -1, 0, "66 60", "ShiftB (0x66) CR/LF" }, /* 26*/ { UNICODE_MODE, -1, "\015\012", -1, 0, "66 60", "ShiftB (0x66) CR/LF" },

File diff suppressed because it is too large Load Diff

View File

@ -99,7 +99,7 @@ static void test_checks(int index, int debug) {
/* 41*/ { 146, "1", -1, -1, -1, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 216: Symbology out of range", -1 }, /* 41*/ { 146, "1", -1, -1, -1, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 216: Symbology out of range", -1 },
/* 42*/ { BARCODE_CODE128, "\200", -1, UNICODE_MODE, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8", -1 }, /* 42*/ { BARCODE_CODE128, "\200", -1, UNICODE_MODE, -1, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8", -1 },
}; };
int data_size = sizeof(data) / sizeof(struct item); int data_size = ARRAY_SIZE(data);
for (int i = 0; i < data_size; i++) { for (int i = 0; i < data_size; i++) {
@ -152,8 +152,8 @@ static void test_input_mode(int index, int debug) {
/* 1*/ { "1234", DATA_MODE | ESCAPE_MODE, 0, DATA_MODE | ESCAPE_MODE }, /* 1*/ { "1234", DATA_MODE | ESCAPE_MODE, 0, DATA_MODE | ESCAPE_MODE },
/* 2*/ { "1234", UNICODE_MODE, 0, UNICODE_MODE }, /* 2*/ { "1234", UNICODE_MODE, 0, UNICODE_MODE },
/* 3*/ { "1234", UNICODE_MODE | ESCAPE_MODE, 0, UNICODE_MODE | ESCAPE_MODE }, /* 3*/ { "1234", UNICODE_MODE | ESCAPE_MODE, 0, UNICODE_MODE | ESCAPE_MODE },
/* 4*/ { "[01]12345678901234", GS1_MODE, 0, GS1_MODE }, /* 4*/ { "[01]12345678901231", GS1_MODE, 0, GS1_MODE },
/* 5*/ { "[01]12345678901234", GS1_MODE | ESCAPE_MODE, 0, GS1_MODE | ESCAPE_MODE }, /* 5*/ { "[01]12345678901231", GS1_MODE | ESCAPE_MODE, 0, GS1_MODE | ESCAPE_MODE },
/* 6*/ { "1234", 4 | ESCAPE_MODE, 0, DATA_MODE }, // Unknown mode reset to bare DATA_MODE /* 6*/ { "1234", 4 | ESCAPE_MODE, 0, DATA_MODE }, // Unknown mode reset to bare DATA_MODE
/* 7*/ { "1234", -1, 0, DATA_MODE }, /* 7*/ { "1234", -1, 0, DATA_MODE },
/* 8*/ { "1234", DATA_MODE | 0x10, 0, DATA_MODE | 0x10 }, // Unknown flags kept (but ignored) /* 8*/ { "1234", DATA_MODE | 0x10, 0, DATA_MODE | 0x10 }, // Unknown flags kept (but ignored)

View File

@ -322,7 +322,7 @@ static void test_qr_gs1(int index, int generate, int debug) {
char *comment; char *comment;
}; };
struct item data[] = { struct item data[] = {
/* 0*/ { "[01]12345678901234", 0, "51 04 00 B3 AA 37 DE 87 B4", "N16" }, /* 0*/ { "[01]12345678901231", 0, "51 04 00 B3 AA 37 DE 87 B1", "N16" },
/* 1*/ { "[01]04912345123459[15]970331[30]128[10]ABC123", 0, "51 07 40 A7 AC EA 80 15 9E 4F CA 52 D2 D3 84 09 D5 E0 28 FD 82 F0 C0 EC 11 EC 11 EC", "N29 A9" }, /* 1*/ { "[01]04912345123459[15]970331[30]128[10]ABC123", 0, "51 07 40 A7 AC EA 80 15 9E 4F CA 52 D2 D3 84 09 D5 E0 28 FD 82 F0 C0 EC 11 EC 11 EC", "N29 A9" },
/* 2*/ { "[91]12%[20]12", 0, "52 05 99 60 5F B5 35 80 01 08 00 EC 11", "A10(11)" }, /* 2*/ { "[91]12%[20]12", 0, "52 05 99 60 5F B5 35 80 01 08 00 EC 11", "A10(11)" },
/* 3*/ { "[91]123%[20]12", 0, "52 06 19 60 5E 2B 76 A0 5A 05 E0 EC 11", "A11(12)" }, /* 3*/ { "[91]123%[20]12", 0, "52 06 19 60 5E 2B 76 A0 5A 05 E0 EC 11", "A11(12)" },
@ -2528,7 +2528,7 @@ static void test_rmqr_gs1(int index, int generate, int debug) {
char *comment; char *comment;
}; };
struct item data[] = { struct item data[] = {
/* 0*/ { "[01]12345678901234", 0, "A6 00 59 D5 1B EF 43 DA 00 EC 11 EC", "N16" }, /* 0*/ { "[01]12345678901231", 0, "A6 00 59 D5 1B EF 43 D8 80 EC 11 EC", "N16" },
/* 1*/ { "[01]04912345123459[15]970331[30]128[10]ABC123", 0, "A5 D0 29 EB 3A A0 05 67 93 F2 94 B4 B4 E2 4E AF 01 47 EC 17 86", "N29 A9" }, /* 1*/ { "[01]04912345123459[15]970331[30]128[10]ABC123", 0, "A5 D0 29 EB 3A A0 05 67 93 F2 94 B4 B4 E2 4E AF 01 47 EC 17 86", "N29 A9" },
/* 2*/ { "[91]12%[20]12", 0, "A4 9C 79 32 25 1D 24 32 48 00 EC 11", "N4 B2 N4" }, /* 2*/ { "[91]12%[20]12", 0, "A4 9C 79 32 25 1D 24 32 48 00 EC 11", "N4 B2 N4" },
/* 3*/ { "[91]123%[20]12", 0, "A4 BC 79 74 3D A9 31 21 92 40 EC 11", "N5 A2 N4" }, /* 3*/ { "[91]123%[20]12", 0, "A4 BC 79 74 3D A9 31 21 92 40 EC 11", "N5 A2 N4" },

View File

@ -1,7 +1,7 @@
/* vector.c - Creates vector image objects /* vector.c - Creates vector image objects
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2018 - 2020 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2018 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -35,6 +35,10 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h> #include <malloc.h>
/* For Visual C++ 6 suppress conversion from int to float warning */
#if _MSC_VER == 1200
#pragma warning(disable: 4244)
#endif
#endif #endif
#include "common.h" #include "common.h"
@ -252,7 +256,7 @@ static void vector_rotate(struct zint_symbol *symbol, int rotate_angle) {
struct zint_vector_hexagon *hex; struct zint_vector_hexagon *hex;
struct zint_vector_circle *circle; struct zint_vector_circle *circle;
struct zint_vector_string *string; struct zint_vector_string *string;
int temp; float temp;
if (rotate_angle == 0) { if (rotate_angle == 0) {
// No rotation needed // No rotation needed

View File

@ -194,10 +194,10 @@ Code 128, and output to the default file out.png in the current directory.
Alternatively, if libpng was not present when Zint was built, the default Alternatively, if libpng was not present when Zint was built, the default
output file will be out.gif. output file will be out.gif.
The data input to Zint is assumed to be encoded in Unicode (UTF-8) format. If The data input to Zint is assumed to be encoded in Unicode (UTF-8) format (Zint
you are encoding characters beyond the 7-bit ASCII set using a scheme other than will correctly handle UTF-8 data on Windows). If you are encoding characters
UTF-8 then you will need to set the appropriate input options as shown in beyond the 7-bit ASCII set using a scheme other than UTF-8 then you will need to
section 4.10 below. set the appropriate input options as shown in section 4.10 below.
Non-printing characters can be entered on the command line using the backslash Non-printing characters can be entered on the command line using the backslash
(\) as an escape character in combination with the --esc switch. Permissible (\) as an escape character in combination with the --esc switch. Permissible
@ -255,110 +255,122 @@ zint -o there.eps -d "This Text"
Selecting which type of barcode you wish to produce (i.e. which symbology to Selecting which type of barcode you wish to produce (i.e. which symbology to
use) can be done at the command line using the -b or --barcode= switch followed use) can be done at the command line using the -b or --barcode= switch followed
by the appropriate integer value in the following table. For example to create by the appropriate integer value in the following table. For example to create
a Data Matrix symbol you could use: by the appropriate integer value or name in the following table. For example to
create a Data Matrix symbol you could use:
zint -o datamatrix.png -b 71 -d "Data to encode" zint -b 71 -o datamatrix.png -d "Data to encode"
or
zint -b DATAMATRIX -o datamatrix.png -d "Data to encode"
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Numeric Value | Barcode Name Numeric | Name (case- | Barcode Name
Value | insensitive) |
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
1 | Code 11 1 | CODE11 | Code 11
2 | Standard Code 2 of 5 2 | C25STANDARD | Standard Code 2 of 5
3 | Interleaved 2 of 5 3 | C25INTER | Interleaved 2 of 5
4 | Code 2 of 5 IATA 4 | C25IATA | Code 2 of 5 IATA
6 | Code 2 of 5 Data Logic 6 | C25LOGIC | Code 2 of 5 Data Logic
7 | Code 2 of 5 Industrial 7 | C25IND | Code 2 of 5 Industrial
8 | Code 3 of 9 (Code 39) 8 | CODE39 | Code 3 of 9 (Code 39)
9 | Extended Code 3 of 9 (Code 39+) 9 | EXCODE39 | Extended Code 3 of 9 (Code 39+)
13 | EAN (including EAN-8 and EAN-13) 13 | EANX | EAN (including EAN-8 and EAN-13)
14 | EAN + Check Digit 14 | EANX_CHK | EAN + Check Digit
16 | GS1-128 (UCC.EAN-128) 16 | GS1_128 | GS1-128 (UCC.EAN-128)
18 | Codabar 18 | CODABAR | Codabar
20 | Code 128 (automatic subset switching) 20 | CODE128 | Code 128 (automatic subset switching)
21 | Deutshe Post Leitcode 21 | DPLEIT | Deutshe Post Leitcode
22 | Deutshe Post Identcode 22 | DPIDENT | Deutshe Post Identcode
23 | Code 16K 23 | CODE16K | Code 16K
24 | Code 49 24 | CODE49 | Code 49
25 | Code 93 25 | CODE93 | Code 93
28 | Flattermarken 28 | FLAT | Flattermarken
29 | GS1 DataBar Omnidirectional (including GS1 DataBar Truncated) 29 | DBAR_OMN | GS1 DataBar Omnidirectional (including GS1
30 | GS1 DataBar Limited | | DataBar Truncated)
31 | GS1 DataBar Expanded 30 | DBAR_LTD | GS1 DataBar Limited
32 | Telepen Alpha 31 | DBAR_EXP | GS1 DataBar Expanded
34 | UPC-A 32 | TELEPEN | Telepen Alpha
35 | UPC-A + Check Digit 34 | UPCA | UPC-A
37 | UPC-E 35 | UPCA_CHK | UPC-A + Check Digit
38 | UPC-E + Check Digit 37 | UPCE | UPC-E
40 | POSTNET 38 | UPCE_CHK | UPC-E + Check Digit
47 | MSI Plessey 40 | POSTNET | POSTNET
49 | FIM 47 | MSI_PLESSEY | MSI Plessey
50 | LOGMARS 49 | FIM | FIM
51 | Pharmacode One-Track 50 | LOGMARS | LOGMARS
52 | PZN 51 | PHARMA | Pharmacode One-Track
53 | Pharmacode Two-Track 52 | PZN | PZN
55 | PDF417 53 | PHARMA_TWO | Pharmacode Two-Track
56 | Compact PDF417 (Truncated PDF417) 55 | PDF417 | PDF417
57 | MaxiCode 56 | PDF417COMP | Compact PDF417 (Truncated PDF417)
58 | QR Code 57 | MAXICODE | MaxiCode
60 | Code 128 (Subset B) 58 | QRCODE | QR Code
63 | Australia Post Standard Customer 60 | CODE128B | Code 128 (Subset B)
66 | Australia Post Reply Paid 63 | AUSPOST | Australia Post Standard Customer
67 | Australia Post Routing 66 | AUSREPLY | Australia Post Reply Paid
68 | Australia Post Redirection 67 | AUSROUTE | Australia Post Routing
69 | ISBN (EAN-13 with verification stage) 68 | AUSREDIRECT | Australia Post Redirection
70 | Royal Mail 4 State (RM4SCC) 69 | ISBNX | ISBN (EAN-13 with verification stage)
71 | Data Matrix (ECC200) 70 | RM4SCC | Royal Mail 4 State (RM4SCC)
72 | EAN-14 71 | DATAMATRIX | Data Matrix (ECC200)
73 | Vehicle Identification Number 72 | EAN14 | EAN-14
74 | Codablock-F 73 | VIN | Vehicle Identification Number
75 | NVE-18 (SSCC-18) 74 | CODABLOCKF | Codablock-F
76 | Japanese Postal Code 75 | NVE18 | NVE-18 (SSCC-18)
77 | Korea Post 76 | JAPANPOST | Japanese Postal Code
79 | GS1 DataBar Stacked (stacked version of GS1 DataBar Truncated) 77 | KOREAPOST | Korea Post
80 | GS1 DataBar Stacked Omnidirectional 79 | DBAR_STK | GS1 DataBar Stacked (stacked version of GS1
81 | GS1 DataBar Expanded Stacked | | DataBar Truncated)
82 | PLANET 80 | DBAR_OMNSTK | GS1 DataBar Stacked Omnidirectional
84 | MicroPDF417 81 | DBAR_EXPSTK | GS1 DataBar Expanded Stacked
85 | USPS Intelligent Mail (OneCode) 82 | PLANET | PLANET
86 | Plessey Code 84 | MICROPDF417 | MicroPDF417
87 | Telepen Numeric 85 | USPS_IMAIL | USPS Intelligent Mail (OneCode)
89 | ITF-14 86 | PLESSEY | Plessey Code
90 | Dutch Post KIX Code 87 | TELEPEN_NUM | Telepen Numeric
92 | Aztec Code 89 | ITF14 | ITF-14
93 | DAFT Code 90 | KIX | Dutch Post KIX Code
96 | DPD Code 92 | AZTEC | Aztec Code
97 | Micro QR Code 93 | DAFT | DAFT Code
98 | HIBC Code 128 96 | DPD | DPD Code
99 | HIBC Code 39 97 | MICROQR | Micro QR Code
102 | HIBC Data Matrix ECC200 98 | HIBC_128 | HIBC Code 128
104 | HIBC QR Code 99 | HIBC_39 | HIBC Code 39
106 | HIBC PDF417 102 | HIBC_DM | HIBC Data Matrix ECC200
108 | HIBC MicroPDF417 104 | HIBC_QR | HIBC QR Code
110 | HIBC Codablock-F 106 | HIBC_PDF | HIBC PDF417
112 | HIBC Aztec Code 108 | HIBC_MICPDF | HIBC MicroPDF417
115 | DotCode 110 | HIBC_BLOCKF | HIBC Codablock-F
116 | Han Xin (Chinese Sensible) Code 112 | HIBC_AZTEC | HIBC Aztec Code
121 | Royal Mail 4-state Mailmark 115 | DOTCODE | DotCode
128 | Aztec Runes 116 | HANXIN | Han Xin (Chinese Sensible) Code
129 | Code 32 121 | MAILMARK | Royal Mail 4-state Mailmark
130 | Composite Symbol with EAN linear component 128 | AZRUNE | Aztec Runes
131 | Composite Symbol with GS1-128 linear component 129 | CODE32 | Code 32
132 | Composite Symbol with GS1 DataBar Omnidirectional linear 130 | EANX_CC | Composite Symbol with EAN linear component
| component 131 | GS1_128_CC | Composite Symbol with GS1-128 linear component
133 | Composite Symbol with GS1 DataBar Limited linear component 132 | DBAR_OMN_CC | Composite Symbol with GS1 DataBar Omnidirectional
134 | Composite Symbol with GS1 DataBar Expanded linear component | | linear component
135 | Composite Symbol with UPC-A linear component 133 | DBAR_LTD_CC | Composite Symbol with GS1 DataBar Limited linear
136 | Composite Symbol with UPC-E linear component | | component
137 | Composite Symbol with GS1 DataBar Stacked component 134 | DBAR_EXP_CC | Composite Symbol with GS1 DataBar Expanded linear
138 | Composite Symbol with GS1 DataBar Stacked Omnidirectional | | component
| component 135 | UPCA_CC | Composite Symbol with UPC-A linear component
139 | Composite Symbol with GS1 DataBar Expanded Stacked component 136 | UPCE_CC | Composite Symbol with UPC-E linear component
140 | Channel Code 137 | DBAR_STK_CC | Composite Symbol with GS1 DataBar Stacked
141 | Code One | | component
142 | Grid Matrix 138 | DBAR_OMNSTK_CC | Composite Symbol with GS1 DataBar Stacked
143 | UPNQR (Univerzalnega Plačilnega Naloga QR) | | Omnidirectional component
144 | Ultracode 139 | DBAR_EXPSTK_CC | Composite Symbol with GS1 DataBar Expanded
145 | Rectangular Micro QR Code (rMQR) | | Stacked component
140 | CHANNEL | Channel Code
141 | CODEONE | Code One
142 | GRIDMATRIX | Grid Matrix
143 | UPNQR | UPNQR (Univerzalnega Plačilnega Naloga QR)
144 | ULTRA | Ultracode
145 | RMQR | Rectangular Micro QR Code (rMQR)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
4.4 Adjusting height 4.4 Adjusting height
@ -566,6 +578,10 @@ zint -b 71 --square --scale 10 --eci 17 --esc -d "\xE2\x82\xAC"
zint -b 71 --square --scale 10 --eci 17 --esc -d "\u20AC" zint -b 71 --square --scale 10 --eci 17 --esc -d "\u20AC"
and to the command:
zint -b 71 --square --scale 10 --eci 17 -d "€"
Ex2: The Chinese character with Unicode codepoint U+5E38 can be encoded in Big5 Ex2: The Chinese character with Unicode codepoint U+5E38 can be encoded in Big5
encoding. The Big5 representation of this character is the two hex bytes: B1 60 encoding. The Big5 representation of this character is the two hex bytes: B1 60
(contained in the file big5char.txt). The generation command for Data Matrix is: (contained in the file big5char.txt). The generation command for Data Matrix is:
@ -576,10 +592,12 @@ This is equivalent to the command (using the --esc switch):
zint -b 71 --square --scale 10 --eci 28 --binary --esc -d "\xB1\x60" zint -b 71 --square --scale 10 --eci 28 --binary --esc -d "\xB1\x60"
and to the command (no --binary switch so conversion occurs): and to the commands (no --binary switch so conversion occurs):
zint -b 71 --square --scale 10 --eci 28 --esc -d "\u5E38" zint -b 71 --square --scale 10 --eci 28 --esc -d "\u5E38"
zint -b 71 --square --scale 10 --eci 28 -d "常"
Ex3: Some decoders (in particular mobile app ones) for QR Code assume UTF-8 Ex3: Some decoders (in particular mobile app ones) for QR Code assume UTF-8
encoding by default and do not support ECI. In this case supply UTF-8 data and encoding by default and do not support ECI. In this case supply UTF-8 data and
use the --binary switch so that the data will be encoded as UTF-8 without use the --binary switch so that the data will be encoded as UTF-8 without
@ -685,7 +703,7 @@ command line. The -h or --help option will display a list of all of the valid
options available, and also gives the exact version of the software. options available, and also gives the exact version of the software.
The -t or --types option gives the table of symbologies along with the symbol The -t or --types option gives the table of symbologies along with the symbol
ID numbers. ID numbers and names.
The -e or --ecinos option gives a list of the ECI codes. The -e or --ecinos option gives a list of the ECI codes.
@ -1393,7 +1411,7 @@ EAN-2 and EAN-5 add-on symbols can be added using the + character. For example,
to draw a UPC-A symbol with the data 72527270270 with an EAN-5 add-on showing to draw a UPC-A symbol with the data 72527270270 with an EAN-5 add-on showing
the data 12345 use the command: the data 12345 use the command:
zint --barcode=34 -d 72527270270+12345 zint --barcode=UPCA -d 72527270270+12345
or encode a data string with the + character included: or encode a data string with the + character included:
@ -1418,7 +1436,7 @@ character as with UPC-A. In addition Zint also supports Number System 1
encoding by entering a 7-digit article number stating with the digit 1. For encoding by entering a 7-digit article number stating with the digit 1. For
example: example:
zint --barcode=37 -d 1123456 zint --barcode=UPCE -d 1123456
or or
@ -1444,11 +1462,11 @@ numbers respectively. Zint will decide which symbology to use depending on the
length of the input data. In addition EAN-2 and EAN-5 add-on symbols can be length of the input data. In addition EAN-2 and EAN-5 add-on symbols can be
added using the + symbol as with UPC symbols. For example: added using the + symbol as with UPC symbols. For example:
zint --barcode=13 -d 54321 zint --barcode=EANX -d 54321
will encode a stand-alone EAN-5, whereas will encode a stand-alone EAN-5, whereas
zint --barcode=13 -d 7432365+54321 zint --barcode=EANX -d 7432365+54321
will encode an EAN-8 symbol with an EAN-5 add-on. As before these results can will encode an EAN-8 symbol with an EAN-5 add-on. As before these results can
be achieved using the API: be achieved using the API:
@ -1865,7 +1883,7 @@ entered into a primary string with the data for the 2D component being entered
in the normal way. To do this at the command prompt use the --primary= command. in the normal way. To do this at the command prompt use the --primary= command.
For example: For example:
zint -b 130 --mode=1 --primary=331234567890 -d "[99]1234-abcd" zint -b EANX_CC --mode=1 --primary=331234567890 -d "[99]1234-abcd"
This creates an EAN-13 linear component with the data "331234567890" and a 2D This creates an EAN-13 linear component with the data "331234567890" and a 2D
CC-A (see below) component with the data "(99)1234-abcd". The same results can CC-A (see below) component with the data "(99)1234-abcd". The same results can

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -329,6 +329,7 @@ static void test_input(int index, int debug) {
for (int i = 0; i < data_size; i++) { for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (index != -1 && i != index) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
strcpy(cmd, "zint"); strcpy(cmd, "zint");
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
@ -490,6 +491,7 @@ static void test_batch_large(int index, int debug) {
for (int i = 0; i < data_size; i++) { for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue; if (index != -1 && i != index) continue;
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
strcpy(cmd, "zint --batch"); strcpy(cmd, "zint --batch");
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {
@ -535,6 +537,7 @@ static void test_checks(int index, int debug) {
int rotate; int rotate;
int rows; int rows;
double scale; double scale;
int scmvv;
int secure; int secure;
int separator; int separator;
int vers; int vers;
@ -544,35 +547,38 @@ 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, "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, "Error 139: Invalid add-on gap value" },
/* 1*/ { 6, -1, -1, -1, -1, NULL, -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, "Warning 140: Invalid add-on gap value" },
/* 2*/ { -1, -2, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 107: Invalid border width value" }, /* 2*/ { 13, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 140: Invalid add-on gap value" },
/* 3*/ { -1, 1001, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 108: Border width out of range" }, /* 3*/ { -1, -2, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 107: Invalid border width value" },
/* 4*/ { -1, -1, -1, 0.009, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 106: Invalid dot radius value" }, /* 4*/ { -1, 1001, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 108: Border width out of range" },
/* 5*/ { -1, -1, -2, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 131: Invalid columns value" }, /* 5*/ { -1, -1, -1, 0.009, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 106: Invalid dot radius value" },
/* 6*/ { -1, -1, 68, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 111: Number of columns out of range" }, /* 6*/ { -1, -1, -2, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 131: Invalid columns value" },
/* 7*/ { -1, -1, -1, -1, -2, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 138: Invalid ECI value" }, /* 7*/ { -1, -1, 68, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 111: Number of columns out of range" },
/* 8*/ { -1, -1, -1, -1, 1000000, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 118: Invalid ECI code" }, /* 8*/ { -1, -1, -1, -1, -2, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 138: Invalid ECI value" },
/* 9*/ { -1, -1, -1, -1, -1, "jpg", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 142: File type 'jpg' not supported, ignoring" }, /* 9*/ { -1, -1, -1, -1, 1000000, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 118: Invalid ECI code" },
/* 10*/ { -1, -1, -1, -1, -1, NULL, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 109: Invalid symbol height value" }, /* 10*/ { -1, -1, -1, -1, -1, "jpg", -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, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 110: Symbol height out of range" }, /* 11*/ { -1, -1, -1, -1, -1, NULL, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 109: Invalid symbol height value" },
/* 12*/ { -1, -1, -1, -1, -1, NULL, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, "Error 148: Invalid mask value" }, /* 12*/ { -1, -1, -1, -1, -1, NULL, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 110: Symbol height out of range" },
/* 13*/ { -1, -1, -1, -1, -1, NULL, -1, 8, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 147: Invalid mask value" }, /* 13*/ { -1, -1, -1, -1, -1, NULL, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Error 148: Invalid mask value" },
/* 14*/ { -1, -1, -1, -1, -1, NULL, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, "Warning 116: Invalid mode" }, /* 14*/ { -1, -1, -1, -1, -1, NULL, -1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 147: Invalid mask value" },
/* 15*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, "Error 117: Invalid rotation value" }, /* 15*/ { -1, -1, -1, -1, -1, NULL, -1, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, "Warning 116: Invalid mode" },
/* 16*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, "Warning 137: Invalid rotation parameter" }, /* 16*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, "Error 117: Invalid rotation value" },
/* 17*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, "Error 132: Invalid rows value" }, /* 17*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, -1, "Warning 137: Invalid rotation parameter" },
/* 18*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, 45, -1, -1, -1, -1, -1, "Warning 112: Number of rows out of range" }, /* 18*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, "Error 132: Invalid rows value" },
/* 19*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, "Warning 105: Invalid scale value" }, /* 19*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, 45, -1, -1, -1, -1, -1, -1, "Warning 112: Number of rows out of range" },
/* 20*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, 0.49, -1, -1, -1, -1, "Warning 146: Scaling less than 0.5 will be set to 0.5 for 'png' output" }, /* 20*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, -1, "Warning 105: Invalid scale value" },
/* 21*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, "Error 134: Invalid ECC value" }, /* 21*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, 0.49, -1, -1, -1, -1, -1, "Warning 146: Scaling less than 0.5 will be set to 0.5 for 'png' output" },
/* 22*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, 9, -1, -1, -1, "Warning 114: ECC level out of range" }, /* 22*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, -1, "Error 149: Invalid Structured Carrier Message version value" },
/* 23*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, "Error 128: Invalid separator value" }, /* 22*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, 100, -1, -1, -1, -1, "Warning 150: Invalid version (vv) for Structured Carrier Message, ignoring" },
/* 24*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, 5, -1, -1, "Warning 127: Invalid separator value" }, /* 22*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, -1, "Error 134: Invalid ECC value" },
/* 25*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, "Error 133: Invalid version value" }, /* 23*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, 9, -1, -1, -1, "Warning 114: ECC level out of range" },
/* 26*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, 85, -1, "Warning 113: Invalid version" }, /* 24*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, -1, "Error 128: Invalid separator value" },
/* 27*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, "Error 120: Invalid whitespace value '-2'" }, /* 25*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, 5, -1, -1, "Warning 127: Invalid separator value" },
/* 28*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, "Warning 121: Whitespace value out of range" }, /* 26*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -1, "Error 133: Invalid version value" },
/* 27*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, 85, -1, "Warning 113: Invalid version" },
/* 28*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, "Error 120: Invalid whitespace value '-2'" },
/* 29*/ { -1, -1, -1, -1, -1, NULL, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1001, "Warning 121: Whitespace value out of range" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -601,6 +607,7 @@ static void test_checks(int index, int debug) {
arg_int(cmd, "--rotate=", data[i].rotate); arg_int(cmd, "--rotate=", data[i].rotate);
arg_int(cmd, "--rows=", data[i].rows); arg_int(cmd, "--rows=", data[i].rows);
arg_double(cmd, "--scale=", data[i].scale); arg_double(cmd, "--scale=", data[i].scale);
arg_int(cmd, "--scmvv=", data[i].scmvv);
arg_int(cmd, "--secure=", data[i].secure); arg_int(cmd, "--secure=", data[i].secure);
arg_int(cmd, "--separator=", data[i].separator); arg_int(cmd, "--separator=", data[i].separator);
arg_int(cmd, "--vers=", data[i].vers); arg_int(cmd, "--vers=", data[i].vers);
@ -619,6 +626,231 @@ static void test_checks(int index, int debug) {
testFinish(); testFinish();
} }
static void test_barcode_symbology(int index, int debug) {
testStart("");
struct item {
const char *bname;
const char *data;
const char *primary;
int fail;
const char *expected;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
static const struct item data[] = {
/* 0*/ { "_", "1", NULL, 1, "Error 119: Invalid barcode type '_'" },
/* 1*/ { "a", "1", NULL, 1, "Error 119: Invalid barcode type 'a'" },
/* 2*/ { "code128", "1", NULL, 0, "symbology: 20," },
/* 3*/ { "code218", "1", NULL, 1, "Error 119: Invalid barcode type 'code218'" },
/* 4*/ { "code12", "1", NULL, 1, "Error 119: Invalid barcode type 'code12'" },
/* 5*/ { "BARCODE_CODE11", "1", NULL, 0, "symbology: 1," },
/* 6*/ { "C25 Standard", "1", NULL, 0, "symbology: 2," },
/* 7*/ { "c25matrix", "1", NULL, 1, "Error 119: Invalid barcode type 'c25matrix'" }, // Legacy not supported
/* 8*/ { "C25INTER", "1", NULL, 0, "symbology: 3," },
/* 9*/ { "c25IATA", "1", NULL, 0, "symbology: 4," },
/* 10*/ { "c25 Logic", "1", NULL, 0, "symbology: 6," },
/* 11*/ { "c25 Ind", "1", NULL, 0, "symbology: 7," },
/* 12*/ { "code39", "1", NULL, 0, "symbology: 8," },
/* 13*/ { "excode 39", "1", NULL, 0, "symbology: 9," },
/* 14*/ { "eanx", "1", NULL, 0, "symbology: 13," },
/* 15*/ { "eanx chk", "1", NULL, 0, "symbology: 14," },
/* 16*/ { "eanxchk", "1", NULL, 0, "symbology: 14," },
/* 17*/ { "GS1128", "[01]12345678901231", NULL, 0, "symbology: 16," },
/* 18*/ { "coda bar", "A1B", NULL, 0, "symbology: 18," },
/* 19*/ { "DPLEIT", "1", NULL, 0, "symbology: 21," },
/* 20*/ { "DPIDENT", "1", NULL, 0, "symbology: 22," },
/* 21*/ { "code16k", "1", NULL, 0, "symbology: 23," },
/* 22*/ { "CODE49", "1", NULL, 0, "symbology: 24," },
/* 23*/ { "CODE93", "1", NULL, 0, "symbology: 25," },
/* 24*/ { "flat", "1", NULL, 0, "symbology: 28," },
/* 25*/ { "dbar omn", "1", NULL, 0, "symbology: 29," },
/* 26*/ { "dbar ltd", "1", NULL, 0, "symbology: 30," },
/* 27*/ { "dbarexp", "[10]12", NULL, 0, "symbology: 31," },
/* 28*/ { "telepen", "1", NULL, 0, "symbology: 32," },
/* 29*/ { "upc", "1", NULL, 1, "Error 119: Invalid barcode type 'upc'" },
/* 30*/ { "upca", "1", NULL, 0, "symbology: 34," },
/* 31*/ { "upca_chk", "123456789012", NULL, 0, "symbology: 35," },
/* 33*/ { "upce", "1", NULL, 0, "symbology: 37," },
/* 34*/ { "upce chk", "12345670", NULL, 0, "symbology: 38," },
/* 36*/ { "POSTNET ", "12345678901", NULL, 0, "symbology: 40," },
/* 37*/ { "MSI Plessey ", "1", NULL, 0, "symbology: 47," },
/* 38*/ { "fim ", "A", NULL, 0, "symbology: 49," },
/* 39*/ { "LOGMARS", "123456", NULL, 0, "symbology: 50," },
/* 40*/ { " pharma", "123456", NULL, 0, "symbology: 51," },
/* 41*/ { " pzn ", "1", NULL, 0, "symbology: 52," },
/* 42*/ { "pharma two", "4", NULL, 0, "symbology: 53," },
/* 43*/ { "BARCODE_PDF417", "1", NULL, 0, "symbology: 55," },
/* 44*/ { "barcodepdf417comp", "1", NULL, 0, "symbology: 56," },
/* 45*/ { "MaxiCode", "1", NULL, 0, "symbology: 57," },
/* 46*/ { "QR CODE", "1", NULL, 0, "symbology: 58," },
/* 47*/ { "qr", "1", NULL, 0, "symbology: 58," }, // Synonym
/* 48*/ { "Code 128 B", "1", NULL, 0, "symbology: 60," },
/* 49*/ { "AUS POST", "12345678901234567890123", NULL, 0, "symbology: 63," },
/* 50*/ { "AusReply", "12345678", NULL, 0, "symbology: 66," },
/* 51*/ { "AUSROUTE", "12345678", NULL, 0, "symbology: 67," },
/* 52*/ { "AUS REDIRECT", "12345678", NULL, 0, "symbology: 68," },
/* 53*/ { "isbnx", "123456789", NULL, 0, "symbology: 69," },
/* 54*/ { "rm4scc", "1", NULL, 0, "symbology: 70," },
/* 55*/ { "DataMatrix", "1", NULL, 0, "symbology: 71," },
/* 56*/ { "EAN14", "1", NULL, 0, "symbology: 72," },
/* 57*/ { "vin", "12345678701234567", NULL, 0, "symbology: 73," },
/* 58*/ { "CodaBlock-F", "1", NULL, 0, "symbology: 74," },
/* 59*/ { "NVE18", "1", NULL, 0, "symbology: 75," },
/* 60*/ { "Japan Post", "1", NULL, 0, "symbology: 76," },
/* 61*/ { "Korea Post", "1", NULL, 0, "symbology: 77," },
/* 62*/ { "DBar Stk", "1", NULL, 0, "symbology: 79," },
/* 63*/ { "DBar Omn Stk", "1", NULL, 0, "symbology: 80," },
/* 64*/ { "DBar Exp Stk", "[20]01", NULL, 0, "symbology: 81," },
/* 65*/ { "planet", "12345678901", NULL, 0, "symbology: 82," },
/* 66*/ { "MicroPDF417", "1", NULL, 0, "symbology: 84," },
/* 67*/ { "USPS IMail", "12345678901234567890", NULL, 0, "symbology: 85," },
/* 68*/ { "plessey", "1", NULL, 0, "symbology: 86," },
/* 69*/ { "telepen num", "1", NULL, 0, "symbology: 87," },
/* 70*/ { "ITF14", "1", NULL, 0, "symbology: 89," },
/* 71*/ { "KIX", "1", NULL, 0, "symbology: 90," },
/* 72*/ { "Aztec", "1", NULL, 0, "symbology: 92," },
/* 73*/ { "daft", "D", NULL, 0, "symbology: 93," },
/* 74*/ { "DPD", "0123456789012345678901234567", NULL, 0, "symbology: 96," },
/* 75*/ { "Micro QR", "1", NULL, 0, "symbology: 97," },
/* 76*/ { "hibc128", "1", NULL, 0, "symbology: 98," },
/* 76*/ { "hibccode128", "1", NULL, 0, "symbology: 98," }, // Synonym
/* 77*/ { "hibc39", "1", NULL, 0, "symbology: 99," },
/* 77*/ { "hibccode39", "1", NULL, 0, "symbology: 99," }, // Synonym
/* 78*/ { "hibcdatamatrix", "1", NULL, 0, "symbology: 102," }, // Synonym
/* 78*/ { "hibcdm", "1", NULL, 0, "symbology: 102," },
/* 79*/ { "HIBC qr", "1", NULL, 0, "symbology: 104," },
/* 79*/ { "HIBC QR Code", "1", NULL, 0, "symbology: 104," }, // Synonym
/* 80*/ { "HIBCPDF", "1", NULL, 0, "symbology: 106," },
/* 80*/ { "HIBCPDF417", "1", NULL, 0, "symbology: 106," }, // Synonym
/* 81*/ { "HIBCMICPDF", "1", NULL, 0, "symbology: 108," },
/* 81*/ { "HIBC Micro PDF", "1", NULL, 0, "symbology: 108," }, // Synonym
/* 81*/ { "HIBC Micro PDF417", "1", NULL, 0, "symbology: 108," }, // Synonym
/* 81*/ { "HIBC BlockF", "1", NULL, 0, "symbology: 110," },
/* 81*/ { "HIBC CodaBlock-F", "1", NULL, 0, "symbology: 110," }, // Synonym
/* 82*/ { "HIBC Aztec", "1", NULL, 0, "symbology: 112," },
/* 83*/ { "DotCode", "1", NULL, 0, "symbology: 115," },
/* 84*/ { "Han Xin", "1", NULL, 0, "symbology: 116," },
/* 85*/ { "Mailmark", "01000000000000000AA00AA0A", NULL, 0, "symbology: 121," },
/* 86*/ { "azrune", "1", NULL, 0, "symbology: 128," },
/* 86*/ { "aztecrune", "1", NULL, 0, "symbology: 128," }, // Synonym
/* 86*/ { "aztecrunes", "1", NULL, 0, "symbology: 128," }, // Synonym
/* 87*/ { "code32", "1", NULL, 0, "symbology: 129," },
/* 88*/ { "eanx cc", "[20]01", "1234567890128", 0, "symbology: 130," },
/* 89*/ { "GS1 128 CC", "[01]12345678901231", "[20]01", 0, "symbology: 131," },
/* 90*/ { "dbaromncc", "[20]01", "1234567890123", 0, "symbology: 132," },
/* 91*/ { "dbarltdcc", "[20]01", "1234567890123", 0, "symbology: 133," },
/* 92*/ { "dbarexpcc", "[20]01", "[01]12345678901231", 0, "symbology: 134," },
/* 93*/ { "upcacc", "[20]01", "12345678901", 0, "symbology: 135," },
/* 94*/ { "upcecc", "[20]01", "1234567", 0, "symbology: 136," },
/* 95*/ { "dbar stk cc", "[20]01", "1234567890123", 0, "symbology: 137," },
/* 96*/ { "dbaromnstkcc", "[20]01", "1234567890123", 0, "symbology: 138," },
/* 97*/ { "dbarexpstkcc", "[20]01", "[01]12345678901231", 0, "symbology: 139," },
/* 98*/ { "Channel", "1", NULL, 0, "symbology: 140," },
/* 99*/ { "CodeOne", "1", NULL, 0, "symbology: 141," },
/*100*/ { "Grid Matrix", "1", NULL, 0, "symbology: 142," },
/*101*/ { "UPN QR", "1", NULL, 0, "symbology: 143," },
/*102*/ { "UPN QR Code", "1", NULL, 0, "symbology: 143," }, // Synonym
/*103*/ { "ultra", "1", NULL, 0, "symbology: 144," },
/*104*/ { "ultracode", "1", NULL, 0, "symbology: 144," }, // Synonym
/*105*/ { "rMQR", "1", NULL, 0, "symbology: 145," },
/*106*/ { "x", "1", NULL, 1, "Error 119: Invalid barcode type 'x'" },
/*107*/ { "\177", "1", NULL, 1, "Error 119: Invalid barcode type '\177'" },
};
int data_size = ARRAY_SIZE(data);
char cmd[4096];
char buf[8192];
char *outfilename = "out.png";
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
strcpy(cmd, "zint ");
strcat(cmd, " --verbose");
arg_data(cmd, "-b ", data[i].bname);
arg_data(cmd, "-d ", data[i].data);
arg_data(cmd, "--primary=", data[i].primary);
strcat(cmd, " 2>&1");
assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i), "i:%d exec(%s) NULL\n", i, cmd);
assert_nonnull(strstr(buf, data[i].expected), "i:%d strstr(%s, %s) == NULL\n", i, buf, data[i].expected);
if (!data[i].fail) {
assert_zero(remove(outfilename), "i:%d remove(%s) != 0 (%d)\n", i, outfilename, errno);
}
}
testFinish();
}
static void test_other_opts(int index, int debug) {
testStart("");
struct item {
int b;
char *data;
int input_mode;
char *opt;
char *opt_data;
char *expected;
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_CODE128, "1", -1, " --bg=", "EF9900", "" },
/* 1*/ { BARCODE_CODE128, "1", -1, " --bg=", "EF9900AA", "" },
/* 2*/ { BARCODE_CODE128, "1", -1, " --bg=", "GF9900", "Error 654: Malformed background colour target" },
/* 3*/ { BARCODE_CODE128, "1", -1, " --fg=", "000000", "" },
/* 4*/ { BARCODE_CODE128, "1", -1, " --fg=", "00000000", "" },
/* 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" },
/* 7*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "10", "" },
/* 8*/ { BARCODE_CODE128, "1", -1, " --fontsize=", "101", "Warning 126: Invalid font size" },
/* 9*/ { BARCODE_CODE128, "1", -1, " --nobackground", "", "" },
/* 10*/ { BARCODE_CODE128, "1", -1, " --notext", "", "" },
/* 11*/ { BARCODE_CODE128, "1", -1, " --reverse", "", "" },
/* 12*/ { BARCODE_CODE128, "1", -1, " --werror", NULL, "" },
/* 13*/ { 19, "1", -1, " --werror", NULL, "Error 207: Codabar 18 not supported" },
/* 14*/ { BARCODE_GS1_128, "[01]12345678901231", -1, "", NULL, "" },
/* 15*/ { BARCODE_GS1_128, "0112345678901231", -1, "", NULL, "Error 252: Data does not start with an AI" },
/* 16*/ { BARCODE_GS1_128, "0112345678901231", -1, " --wzpl", NULL, "Warning 252: Data does not start with an AI" },
/* 17*/ { BARCODE_GS1_128, "[00]376104250021234569", -1, "", NULL, "" },
/* 18*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, "", NULL, "Warning 261: AI (00) position 18: Bad checksum '8', expected '9'" },
/* 19*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --wzpl", NULL, "Warning 261: AI (00) position 18: Bad checksum '8', expected '9'" },
/* 20*/ { BARCODE_GS1_128, "[00]376104250021234568", -1, " --werror", NULL, "Warning 261: AI (00) position 18: Bad checksum '8', expected '9'" },
};
int data_size = ARRAY_SIZE(data);
char cmd[4096];
char buf[8192];
for (int i = 0; i < data_size; i++) {
if (index != -1 && i != index) continue;
strcpy(cmd, "zint");
arg_int(cmd, "-b ", data[i].b);
arg_input_mode(cmd, data[i].input_mode);
arg_data(cmd, "-d ", data[i].data);
if (data[i].opt_data != NULL) {
arg_data(cmd, data[i].opt, data[i].opt_data);
} else {
strcat(cmd, data[i].opt);
}
strcat(cmd, " 2>&1");
assert_nonnull(exec(cmd, buf, sizeof(buf) - 1, debug, i), "i:%d exec(%s) NULL\n", i, cmd);
assert_zero(strcmp(buf, data[i].expected), "i:%d buf (%s) != expected (%s) (%s)\n", i, buf, data[i].expected, cmd);
}
testFinish();
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */ testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
@ -628,6 +860,8 @@ int main(int argc, char *argv[]) {
{ "test_batch_input", test_batch_input, 1, 0, 1 }, { "test_batch_input", test_batch_input, 1, 0, 1 },
{ "test_batch_large", test_batch_large, 1, 0, 1 }, { "test_batch_large", test_batch_large, 1, 0, 1 },
{ "test_checks", test_checks, 1, 0, 1 }, { "test_checks", test_checks, 1, 0, 1 },
{ "test_barcode_symbology", test_barcode_symbology, 1, 0, 1 },
{ "test_other_opts", test_other_opts, 1, 0, 1 },
}; };
testRun(argc, argv, funcs, ARRAY_SIZE(funcs)); testRun(argc, argv, funcs, ARRAY_SIZE(funcs));