gs1/gs1_lint: update to latest gs1-syntax-dictionary, removing

`iso3166list` linter and adjusting all others to allow for
  multiple optional linters (by checking `data_len` vs `offset`)
library: change invalid `input_mode` reset to return warning;
  split func table into 2 - func declarations without prototype
  will be error in C23;
  make invalid symbology check a separate function using a table
  and call near beginning of `ZBarcode_Encode_Segs()`;
  in `ZBarcode_BarcodeName()` save some bytes by simplifying
  name table and removing "BARCODE_" prefix from entries
output: fix pack logic to use pragma by default (actually more
  portable than `__attribute__`)
common.h: remove C99 detection which was artifice of specifying
  "-std=", and rejig layout to be more logical
BWIPP: update to latest version
general: change `ZINT_VERSION_BUILD` tests to `#if`s
general: further fiddling with some tables to save a few bytes
CLI: change function arg `optarg` -> `arg` so doesn't shadow
  global
general: library now compilable with Comp Cert C (though as it
  doesn't support `alloca()` will have multiple memory leaks)
This commit is contained in:
gitlost 2024-06-27 23:00:13 +01:00
parent d70edce067
commit 7246d67175
33 changed files with 1579 additions and 1434 deletions

View File

@ -5,6 +5,7 @@ Version 2.13.0.9 (dev) not released yet
------------------------ ------------------------
- New `memfile` & `memfile_size` fields in `symbol` for use with new output - New `memfile` & `memfile_size` fields in `symbol` for use with new output
option `BARCODE_MEMORY_FILE` option `BARCODE_MEMORY_FILE`
- Invalid `input_mode` now returns warning
Changes Changes
------- -------
@ -14,6 +15,12 @@ Changes
in-memory buffer `symbol->memfile` instead of to file `symbol->outfile`, in-memory buffer `symbol->memfile` instead of to file `symbol->outfile`,
ticket #301 ticket #301
- CODE128: improve encodation on A/B shifting, props Daniel Gredler (Okapi) - CODE128: improve encodation on A/B shifting, props Daniel Gredler (Okapi)
- library: return warning on invalid `input_mode` reset
- GS1: new AIs 7250-7259 (GSCN 22-246), new linters `yyyymmdd()`, `iso5218()`,
`posinseqslash()`; remove old linter `iso3166list`;
iso4217: new ISO 4217 currency code 924
- AZTEC: workaround MSVC 2022 optimizer bug in `az_populate_map()` loops,
ticket #317, props Andre Maute
Bugs Bugs
---- ----
@ -26,6 +33,9 @@ Bugs
written as little-endian - simplifies testing) written as little-endian - simplifies testing)
- ITF14/DPLEIT/DPIDENT: ignore `option_2` (check digit options) - ITF14/DPLEIT/DPIDENT: ignore `option_2` (check digit options)
- GUI: scalewindow: fix cropping of initial resolution and bound X-dim <= 10 - GUI: scalewindow: fix cropping of initial resolution and bound X-dim <= 10
- GUI: factory reset: reset preview background colour also
- QZint: fix legacy width and security level getters/setters, MR #158, props
Philip Ye
Version 2.13.0 (2023-12-18) Version 2.13.0 (2023-12-18)

View File

@ -49,9 +49,9 @@ static const char C25IndustTable[10][10] = {
}; };
/* Note `c25_common()` assumes Stop string length one less than Start */ /* Note `c25_common()` assumes Stop string length one less than Start */
static const char *C25MatrixStartStop[2] = { "411111", "41111" }; static const char C25MatrixStartStop[2][6] = { {'4', '1', '1', '1', '1', '1'}, {'4', '1', '1', '1', '1'} };
static const char *C25IndustStartStop[2] = { "313111", "31113" }; static const char C25IndustStartStop[2][6] = { {'3', '1', '3', '1', '1', '1'}, {'3', '1', '1', '1', '3'} };
static const char *C25IataLogicStartStop[2] = { "1111", "311" }; static const char C25IataLogicStartStop[2][6] = { {'1', '1', '1', '1'}, {'3', '1', '1'} };
static const char C25InterTable[10][5] = { static const char C25InterTable[10][5] = {
{'1','1','3','3','1'}, {'3','1','1','1','3'}, {'1','3','1','1','3'}, {'3','3','1','1','1'}, {'1','1','3','1','3'}, {'1','1','3','3','1'}, {'3','1','1','1','3'}, {'1','3','1','1','3'}, {'3','3','1','1','1'}, {'1','1','3','1','3'},
@ -64,7 +64,7 @@ static char c25_check_digit(const unsigned int count) {
/* Common to Standard (Matrix), Industrial, IATA, and Data Logic */ /* Common to Standard (Matrix), Industrial, IATA, and Data Logic */
static int c25_common(struct zint_symbol *symbol, const unsigned char source[], int length, const int max, static int c25_common(struct zint_symbol *symbol, const unsigned char source[], int length, const int max,
const int is_matrix, const char *start_stop[2], const int start_length, const int error_base) { const int is_matrix, const char start_stop[2][6], const int start_length, const int error_base) {
int i; int i;
char dest[818]; /* Largest destination 4 + (80 + 1) * 10 + 3 + 1 = 818 */ char dest[818]; /* Largest destination 4 + (80 + 1) * 10 + 3 + 1 = 818 */

View File

@ -185,32 +185,25 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
i = 0; i = 0;
j = 0; j = 0;
while (i < src_len) { while (i < src_len) {
reduced_encode_mode[j] = encode_mode[i];
if (i + 1 < src_len) { if (i + 1 < src_len) {
if ((source[i] == 13) && (source[i + 1] == 10)) { /* CR LF */ if ((source[i] == 13) && (source[i + 1] == 10)) { /* CR LF */
reduced_source[j] = 'a'; reduced_source[j] = 'a';
reduced_encode_mode[j] = encode_mode[i];
i += 2; i += 2;
} else if ((source[i] == '.') && (source[i + 1] == ' ') && (encode_mode[i] == 'P')) { } else if ((source[i] == '.') && (source[i + 1] == ' ') && (encode_mode[i] == 'P')) {
reduced_source[j] = 'b'; reduced_source[j] = 'b';
reduced_encode_mode[j] = encode_mode[i];
i += 2; i += 2;
} else if ((source[i] == ',') && (source[i + 1] == ' ') && (encode_mode[i] == 'P')) { } else if ((source[i] == ',') && (source[i + 1] == ' ') && (encode_mode[i] == 'P')) {
reduced_source[j] = 'c'; reduced_source[j] = 'c';
reduced_encode_mode[j] = encode_mode[i];
i += 2; i += 2;
} else if ((source[i] == ':') && (source[i + 1] == ' ')) { } else if ((source[i] == ':') && (source[i + 1] == ' ')) {
reduced_source[j] = 'd'; reduced_source[j] = 'd';
reduced_encode_mode[j] = encode_mode[i];
i += 2; i += 2;
} else { } else {
reduced_source[j] = source[i]; reduced_source[j] = source[i++];
reduced_encode_mode[j] = encode_mode[i];
i++;
} }
} else { } else {
reduced_source[j] = source[i]; reduced_source[j] = source[i++];
reduced_encode_mode[j] = encode_mode[i];
i++;
} }
j++; j++;
} }
@ -950,10 +943,10 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
data_maxsize = 0; /* Keep compiler happy! */ data_maxsize = 0; /* Keep compiler happy! */
adjustment_size = 0; adjustment_size = 0;
if (symbol->option_2 == 0) { /* The size of the symbol can be determined by Zint */ if (symbol->option_2 == 0) { /* The size of the symbol can be determined by Zint */
static const short *full_sizes[5] = { static const short *const full_sizes[5] = {
NULL, Aztec10DataSizes, Aztec23DataSizes, Aztec36DataSizes, Aztec50DataSizes NULL, Aztec10DataSizes, Aztec23DataSizes, Aztec36DataSizes, Aztec50DataSizes
}; };
static const short *comp_sizes[5] = { static const short *const comp_sizes[5] = {
NULL, AztecCompact10DataSizes, AztecCompact23DataSizes, AztecCompact36DataSizes, AztecCompact50DataSizes NULL, AztecCompact10DataSizes, AztecCompact23DataSizes, AztecCompact36DataSizes, AztecCompact50DataSizes
}; };
int ecc_level = symbol->option_1; int ecc_level = symbol->option_1;
@ -1230,15 +1223,13 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
/* Plot all of the data into the symbol in pre-defined spiral pattern */ /* Plot all of the data into the symbol in pre-defined spiral pattern */
if (compact) { if (compact) {
int offset = AztecCompactOffset[layers - 1]; const int offset = AztecCompactOffset[layers - 1];
int end_offset = 27 - offset; const int end_offset = 27 - offset;
for (y = offset; y < end_offset; y++) { for (y = offset; y < end_offset; y++) {
int y_map = y * 27; const int y_map = y * 27;
for (x = offset; x < end_offset; x++) { for (x = offset; x < end_offset; x++) {
int map = AztecCompactMap[y_map + x]; const int map = AztecCompactMap[y_map + x];
if (map == 1) { if (map == 1 || (map >= 2 && bit_pattern[map - 2] == '1')) {
set_module(symbol, y - offset, x - offset);
} else if (map >= 2 && bit_pattern[map - 2] == '1') {
set_module(symbol, y - offset, x - offset); set_module(symbol, y - offset, x - offset);
} }
} }
@ -1248,16 +1239,14 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
symbol->rows = 27 - (2 * offset); symbol->rows = 27 - (2 * offset);
symbol->width = 27 - (2 * offset); symbol->width = 27 - (2 * offset);
} else { } else {
int offset = AztecOffset[layers - 1]; const int offset = AztecOffset[layers - 1];
int end_offset = 151 - offset; const int end_offset = 151 - offset;
az_populate_map(AztecMap, layers); az_populate_map(AztecMap, layers);
for (y = offset; y < end_offset; y++) { for (y = offset; y < end_offset; y++) {
int y_map = y * 151; const int y_map = y * 151;
for (x = offset; x < end_offset; x++) { for (x = offset; x < end_offset; x++) {
int map = AztecMap[y_map + x]; const int map = AztecMap[y_map + x];
if (map == 1) { if (map == 1 || (map >= 2 && bit_pattern[map - 2] == '1')) {
set_module(symbol, y - offset, x - offset);
} else if (map >= 2 && bit_pattern[map - 2] == '1') {
set_module(symbol, y - offset, x - offset); set_module(symbol, y - offset, x - offset);
} }
} }

View File

@ -37,7 +37,7 @@
extern "C" { extern "C" {
#endif #endif
#ifdef _MSC_VER #ifdef OUT_USE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
@ -69,7 +69,7 @@ extern "C" {
uint8_t reserved; uint8_t reserved;
} OUT_PACK color_ref_t; } OUT_PACK color_ref_t;
#ifdef _MSC_VER #ifdef OUT_USE_PRAGMA_PACK
#pragma pack() #pragma pack()
#endif #endif

View File

@ -204,12 +204,12 @@ INTERNAL int module_colour_is_set(const struct zint_symbol *symbol, const int y_
INTERNAL void set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord, const int colour) { INTERNAL void set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord, const int colour) {
symbol->encoded_data[y_coord][x_coord] = colour; symbol->encoded_data[y_coord][x_coord] = colour;
} }
#endif
/* Sets a dark/black module to white (i.e. unsets) */ /* Sets a dark/black module to white (i.e. unsets) */
INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) { INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord) {
symbol->encoded_data[y_coord][x_coord >> 3] &= ~(1 << (x_coord & 0x07)); symbol->encoded_data[y_coord][x_coord >> 3] &= ~(1 << (x_coord & 0x07));
} }
#endif
/* Expands from a width pattern to a bit pattern */ /* Expands from a width pattern to a bit pattern */
INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int length) { INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int length) {

View File

@ -37,29 +37,68 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#ifndef ARRAY_SIZE #include "zint.h"
#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0]))) #include "zintconfig.h"
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif #endif
/* Determine if C89 or C99 (excluding MSVC, which doesn't define __STDC_VERSION__) */ /* Note if change following must also change "frontend/main.c" copy */
#ifndef _MSC_VER #define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
# if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L
# define ZINT_IS_C89
# elif __STDC_VERSION__ <= 199901L /* Actually includes pseudo-standards "C94/C95" as well */
# define ZINT_IS_C99
# endif
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
# include <malloc.h> # include <malloc.h>
# define z_alloca(nmemb) _alloca(nmemb) # define z_alloca(nmemb) _alloca(nmemb)
#elif defined(__COMPCERT__)
# define z_alloca(nmemb) malloc(nmemb) /* So links - leads to loads of leaks obs */
#else #else
# if defined(ZINT_IS_C89) || defined(ZINT_IS_C99) || defined(__NuttX__) || defined(_AIX) \ # if (defined(__GNUC__) && !defined(alloca) && !defined(__NetBSD__)) || defined(__NuttX__) || defined(_AIX) \
|| (defined(__sun) && defined(__SVR4) /*Solaris*/) || (defined(__sun) && defined(__SVR4) /*Solaris*/)
# include <alloca.h> # include <alloca.h>
# endif # endif
# define z_alloca(nmemb) alloca(nmemb) # define z_alloca(nmemb) alloca(nmemb)
#endif #endif
/* End of "frontend/main.c" copy */
#ifdef _MSC_VER
# pragma warning(disable: 4125) /* decimal digit terminates octal escape sequence */
# pragma warning(disable: 4244) /* conversion from int to float */
# if _MSC_VER > 1200 /* VC6 */
# pragma warning(disable: 4996) /* function or variable may be unsafe */
# endif
#endif
#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(ZINT_TEST) && !defined(__MINGW32__)
# define INTERNAL __attribute__((__visibility__("hidden")))
#elif defined(ZINT_TEST)
# define INTERNAL ZINT_EXTERN /* The test suite references INTERNAL functions, so they need to be exported */
#else
# define INTERNAL
#endif
#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
# define INTERNAL_DATA_EXTERN __attribute__((__visibility__("hidden"))) extern
# define INTERNAL_DATA __attribute__((__visibility__("hidden")))
#else
# define INTERNAL_DATA_EXTERN extern
# define INTERNAL_DATA
#endif
/* Determine if C89 (excluding MSVC, which doesn't define __STDC_VERSION__) */
#ifndef _MSC_VER
# if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L
# define ZINT_IS_C89
# endif
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
# if _MSC_VER >= 1400 /* MSVC 2005 (C++ 8.0) */ # if _MSC_VER >= 1400 /* MSVC 2005 (C++ 8.0) */
@ -73,17 +112,47 @@ extern "C" {
# endif # endif
#endif #endif
#ifdef _MSC_VER #if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(ZINT_IS_C89) /* VC6 or C89 */
typedef unsigned __int8 uint8_t; # define ceilf (float) ceil
typedef unsigned __int16 uint16_t; # define floorf (float) floor
typedef __int32 int32_t; # define fmodf (float) fmod
typedef unsigned __int32 uint32_t; #endif
typedef unsigned __int64 uint64_t; /* `round()` (C99) not before MSVC 2013 (C++ 12.0) */
#else #if (defined(_MSC_VER) && _MSC_VER < 1800) || defined(ZINT_IS_C89)
#include <stdint.h> # define round(arg) floor((arg) + 0.5)
# define roundf(arg) floorf((arg) + 0.5f)
#endif #endif
/* `is_sane()` flags */ /* Is float integral value? (https://stackoverflow.com/a/40404149) */
#define isfintf(arg) (fmodf(arg, 1.0f) == 0.0f)
/* Simple versions of <ctype.h> functions with no dependence on locale */
#define z_isdigit(c) ((c) <= '9' && (c) >= '0')
#define z_isupper(c) ((c) >= 'A' && (c) <= 'Z')
#define z_islower(c) ((c) >= 'a' && (c) <= 'z')
/* Helpers to cast away char pointer signedness */
#define ustrlen(source) strlen((const char *) (source))
#define ustrcpy(target, source) strcpy((char *) (target), (const char *) (source))
#define ustrcat(target, source) strcat((char *) (target), (const char *) (source))
#define ustrncat(target, source, count) strncat((char *) (target), (const char *) (source), (count))
/* Converts a character 0-9, A-F to its equivalent integer value */
INTERNAL int ctoi(const char source);
/* Converts an integer value to its hexadecimal character */
INTERNAL char itoc(const int source);
/* Converts decimal string of length <= 9 to integer value. Returns -1 if not numeric */
INTERNAL int to_int(const unsigned char source[], const int length);
/* Converts lower case characters to upper case in string `source` */
INTERNAL void to_upper(unsigned char source[], const int length);
/* Returns the number of times a character occurs in `source` */
INTERNAL int chr_cnt(const unsigned char source[], const int length, const unsigned char c);
/* `is_chr()` & `is_sane()` flags */
#define IS_SPC_F 0x0001 /* Space */ #define IS_SPC_F 0x0001 /* Space */
#define IS_HSH_F 0x0002 /* Hash sign # */ #define IS_HSH_F 0x0002 /* Hash sign # */
#define IS_AST_F 0x0004 /* Asterisk sign * */ #define IS_AST_F 0x0004 /* Asterisk sign * */
@ -107,91 +176,6 @@ typedef unsigned __int64 uint64_t;
/* The most commonly used set */ /* The most commonly used set */
#define NEON_F IS_NUM_F /* NEON "0123456789" */ #define NEON_F IS_NUM_F /* NEON "0123456789" */
/* Simple versions of <ctype.h> functions with no dependence on locale */
#define z_isdigit(c) ((c) <= '9' && (c) >= '0')
#define z_isupper(c) ((c) >= 'A' && (c) <= 'Z')
#define z_islower(c) ((c) >= 'a' && (c) <= 'z')
#include "zint.h"
#include "zintconfig.h"
#include <stdlib.h>
#include <string.h>
/* Helpers to cast away char pointer signedness */
#define ustrlen(source) strlen((const char *) (source))
#define ustrcpy(target, source) strcpy((char *) (target), (const char *) (source))
#define ustrcat(target, source) strcat((char *) (target), (const char *) (source))
#define ustrncat(target, source, count) strncat((char *) (target), (const char *) (source), (count))
#if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(ZINT_IS_C89) /* VC6 or C89 */
# define ceilf (float) ceil
# define floorf (float) floor
# define fmodf (float) fmod
#endif
/* `round()` (C99) not before MSVC 2013 (C++ 12.0) */
#if (defined(_MSC_VER) && _MSC_VER < 1800) || defined(ZINT_IS_C89)
# define round(arg) floor((arg) + 0.5)
# define roundf(arg) floorf((arg) + 0.5f)
#endif
#ifdef _MSC_VER
# pragma warning(disable: 4244) /* conversion from int to float */
# if _MSC_VER > 1200 /* VC6 */
# pragma warning(disable: 4996) /* function or variable may be unsafe */
# endif
#endif
/* Is float integral value? (https://stackoverflow.com/a/40404149) */
#define isfintf(arg) (fmodf(arg, 1.0f) == 0.0f)
#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(ZINT_TEST) && !defined(__MINGW32__)
# define INTERNAL __attribute__((__visibility__("hidden")))
#elif defined(ZINT_TEST)
# define INTERNAL ZINT_EXTERN /* The test suite references INTERNAL functions, so they need to be exported */
#else
# define INTERNAL
#endif
#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
# define INTERNAL_DATA_EXTERN __attribute__((__visibility__("hidden"))) extern
# define INTERNAL_DATA __attribute__((__visibility__("hidden")))
#else
# define INTERNAL_DATA_EXTERN extern
# define INTERNAL_DATA
#endif
#define Z_COMMON_INLINE 1
#ifdef Z_COMMON_INLINE
/* Returns true (1) if a module is dark/black, otherwise false (0) */
# define module_is_set(s, y, x) (((s)->encoded_data[(y)][(x) >> 3] >> ((x) & 0x07)) & 1)
/* Sets a module to dark/black */
# define set_module(s, y, x) do { (s)->encoded_data[(y)][(x) >> 3] |= 1 << ((x) & 0x07); } while (0)
/* Returns true (1-8) if a module is colour, otherwise false (0) */
# define module_colour_is_set(s, y, x) ((s)->encoded_data[(y)][(x)])
/* Sets a module to a colour */
# define set_module_colour(s, y, x, c) do { (s)->encoded_data[(y)][(x)] = (c); } while (0)
#endif
/* Converts a character 0-9, A-F to its equivalent integer value */
INTERNAL int ctoi(const char source);
/* Converts an integer value to its hexadecimal character */
INTERNAL char itoc(const int source);
/* Converts decimal string of length <= 9 to integer value. Returns -1 if not numeric */
INTERNAL int to_int(const unsigned char source[], const int length);
/* Converts lower case characters to upper case in string `source` */
INTERNAL void to_upper(unsigned char source[], const int length);
/* Returns the number of times a character occurs in `source` */
INTERNAL int chr_cnt(const unsigned char source[], const int length, const unsigned char c);
/* Whether a character matches `flg` */ /* Whether a character matches `flg` */
INTERNAL int is_chr(const unsigned int flg, const unsigned int c); INTERNAL int is_chr(const unsigned int flg, const unsigned int c);
@ -211,7 +195,15 @@ INTERNAL int posn(const char set_string[], const char data);
INTERNAL int bin_append_posn(const int arg, const int length, char *binary, const int bin_posn); INTERNAL int bin_append_posn(const int arg, const int length, char *binary, const int bin_posn);
#ifndef Z_COMMON_INLINE #define Z_COMMON_INLINE 1
#ifdef Z_COMMON_INLINE
# define module_is_set(s, y, x) (((s)->encoded_data[y][(x) >> 3] >> ((x) & 0x07)) & 1)
# define set_module(s, y, x) do { (s)->encoded_data[y][(x) >> 3] |= 1 << ((x) & 0x07); } while (0)
# define module_colour_is_set(s, y, x) ((s)->encoded_data[y][x])
# define set_module_colour(s, y, x, c) do { (s)->encoded_data[y][x] = (c); } while (0)
# define unset_module(s, y, x) do { (s)->encoded_data[y][(x) >> 3] &= ~(1 << ((x) & 0x07)); } while (0)
#else
/* Returns true (1) if a module is dark/black, otherwise false (0) */ /* Returns true (1) if a module is dark/black, otherwise false (0) */
INTERNAL int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord); INTERNAL int module_is_set(const struct zint_symbol *symbol, const int y_coord, const int x_coord);
@ -224,9 +216,10 @@ INTERNAL int module_colour_is_set(const struct zint_symbol *symbol, const int y_
/* Sets a module to a colour */ /* Sets a module to a colour */
INTERNAL void set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord, INTERNAL void set_module_colour(struct zint_symbol *symbol, const int y_coord, const int x_coord,
const int colour); const int colour);
#endif
/* Sets a dark/black module to white (i.e. unsets) */ /* Sets a dark/black module to white (i.e. unsets) */
INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord); INTERNAL void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coord);
#endif /* Z_COMMON_INLINE */
/* Expands from a width pattern to a bit pattern */ /* Expands from a width pattern to a bit pattern */
INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int length); INTERNAL void expand(struct zint_symbol *symbol, const char data[], const int length);

View File

@ -683,7 +683,7 @@ static int dm_switch_mode(const int next_mode, unsigned char target[], int tp, i
#define DM_NUM_MODES 6 #define DM_NUM_MODES 6
static const char *dm_smodes[] = { "?", "ASCII", "C40", "TEXT", "X12", "EDF", "B256" }; static const char dm_smodes[DM_NUM_MODES + 1][6] = { "?", "ASCII", "C40", "TEXT", "X12", "EDF", "B256" };
/* The size of this structure could be significantly reduced using techniques pointed out by Alex Geller, /* The size of this structure could be significantly reduced using techniques pointed out by Alex Geller,
but not done currently to avoid the processing overhead */ but not done currently to avoid the processing overhead */

View File

@ -37,7 +37,7 @@
extern "C" { extern "C" {
#endif #endif
#ifdef _MSC_VER #ifdef OUT_USE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
@ -237,7 +237,7 @@ extern "C" {
emr_rectangle_t right; emr_rectangle_t right;
} OUT_PACK box_t; } OUT_PACK box_t;
#ifdef _MSC_VER #ifdef OUT_USE_PRAGMA_PACK
#pragma pack() #pragma pack()
#endif #endif

View File

@ -40,7 +40,7 @@
static int numeric(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int numeric(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50]) { int *p_err_posn, char err_msg[50]) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -78,7 +78,7 @@ static const char c82[] = {
static int cset82(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int cset82(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50]) { int *p_err_posn, char err_msg[50]) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -105,7 +105,7 @@ static int cset82(const unsigned char *data, int data_len, int offset, int min,
static int cset39(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int cset39(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50]) { int *p_err_posn, char err_msg[50]) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -133,7 +133,7 @@ static int cset39(const unsigned char *data, int data_len, int offset, int min,
static int cset64(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int cset64(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50]) { int *p_err_posn, char err_msg[50]) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -166,7 +166,7 @@ static int cset64(const unsigned char *data, int data_len, int offset, int min,
static int csum(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int csum(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -201,7 +201,7 @@ static int csum(const unsigned char *data, int data_len, int offset, int min, in
static int csumalpha(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int csumalpha(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -249,7 +249,7 @@ static int key(const unsigned char *data, int data_len, int offset, int min, int
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -284,7 +284,7 @@ static int yyyymmd0(const unsigned char *data, int data_len, int offset, int min
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 8)) { if (data_len < min || (data_len && data_len < 8)) {
return 0; return 0;
@ -331,7 +331,7 @@ static int yyyymmdd(const unsigned char *data, int data_len, int offset, int min
return 0; return 0;
} }
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (!length_only && data_len) { if (!length_only && data_len) {
const int day = to_int(data + offset + 6, 2); const int day = to_int(data + offset + 6, 2);
@ -350,7 +350,7 @@ static int yyyymmdd(const unsigned char *data, int data_len, int offset, int min
static int yymmd0(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int yymmd0(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 6)) { if (data_len < min || (data_len && data_len < 6)) {
return 0; return 0;
@ -379,7 +379,7 @@ static int yymmdd(const unsigned char *data, int data_len, int offset, int min,
return 0; return 0;
} }
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (!length_only && data_len) { if (!length_only && data_len) {
const int day = to_int(data + offset + 4, 2); const int day = to_int(data + offset + 4, 2);
@ -406,7 +406,7 @@ static int yymmddhh(const unsigned char *data, int data_len, int offset, int min
return 0; return 0;
} }
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (!length_only && data_len) { if (!length_only && data_len) {
const int hour = to_int(data + offset + 6, 2); const int hour = to_int(data + offset + 6, 2);
@ -426,7 +426,7 @@ static int hhmm(const unsigned char *data, int data_len, int offset, int min, in
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 4)) { if (data_len < min || (data_len && data_len < 4)) {
return 0; return 0;
@ -459,7 +459,7 @@ static int mmoptss(const unsigned char *data, int data_len, int offset, int min,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 2) if (data_len < min || (data_len && data_len < 2)
|| (data_len > 2 && data_len < 4)) { || (data_len > 2 && data_len < 4)) {
@ -496,9 +496,13 @@ static int iso3166(const unsigned char *data, int data_len, int offset, int min,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 3)) { if (data_len < min || (data_len && data_len < 3)) {
if (offset) {
/* For backward compatibility only warn if not first */
*p_err_no = 4;
}
return 0; return 0;
} }
@ -514,42 +518,12 @@ static int iso3166(const unsigned char *data, int data_len, int offset, int min,
return 1; return 1;
} }
/* Check for a list of ISO 3166-1 numeric country codes */
static int iso3166list(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) {
int data_len_max;
data_len -= offset;
data_len_max = data_len > max ? max : data_len;
if (data_len < min || (data_len && data_len < 3)) {
return 0;
}
/* Do this check separately for backward compatibility */
if (data_len && data_len_max % 3) {
*p_err_no = 4;
return 0;
}
if (!length_only && data_len) {
int i;
for (i = 0; i < data_len_max; i += 3) {
if (!iso3166(data, offset + data_len, offset + i, 3, 3, p_err_no, p_err_posn, err_msg, length_only)) {
return 0;
}
}
}
return 1;
}
/* Check for an ISO 3166-1 numeric country code allowing "999" */ /* Check for an ISO 3166-1 numeric country code allowing "999" */
static int iso3166999(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int iso3166999(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 3)) { if (data_len < min || (data_len && data_len < 3)) {
return 0; return 0;
@ -573,7 +547,7 @@ static int iso3166alpha2(const unsigned char *data, int data_len, int offset, in
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 2)) { if (data_len < min || (data_len && data_len < 2)) {
return 0; return 0;
@ -599,7 +573,7 @@ static int iso4217(const unsigned char *data, int data_len, int offset, int min,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 3)) { if (data_len < min || (data_len && data_len < 3)) {
return 0; return 0;
@ -623,7 +597,7 @@ static int pcenc(const unsigned char *data, int data_len, int offset, int min, i
static const char hex_chars[] = "0123456789ABCDEFabcdef"; static const char hex_chars[] = "0123456789ABCDEFabcdef";
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -659,7 +633,7 @@ static int yesno(const unsigned char *data, int data_len, int offset, int min, i
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -682,7 +656,7 @@ static int importeridx(const unsigned char *data, int data_len, int offset, int
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -707,7 +681,7 @@ static int importeridx(const unsigned char *data, int data_len, int offset, int
static int nonzero(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int nonzero(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -732,7 +706,7 @@ static int winding(const unsigned char *data, int data_len, int offset, int min,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -755,7 +729,7 @@ static int zero(const unsigned char *data, int data_len, int offset, int min, in
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -778,7 +752,7 @@ static int pieceoftotal(const unsigned char *data, int data_len, int offset, int
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 4)) { if (data_len < min || (data_len && data_len < 4)) {
return 0; return 0;
@ -816,7 +790,7 @@ static int pieceoftotal(const unsigned char *data, int data_len, int offset, int
static int iban(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int iban(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -897,7 +871,7 @@ static int nozeroprefix(const unsigned char *data, int data_len, int offset, int
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -1004,7 +978,7 @@ static int couponcode(const unsigned char *data, int data_len, int offset, int m
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -1222,7 +1196,7 @@ static int couponposoffer(const unsigned char *data, int data_len, int offset, i
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -1274,7 +1248,7 @@ static int couponposoffer(const unsigned char *data, int data_len, int offset, i
static int latitude(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int latitude(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 10)) { if (data_len < min || (data_len && data_len < 10)) {
return 0; return 0;
@ -1304,7 +1278,7 @@ static int latitude(const unsigned char *data, int data_len, int offset, int min
static int longitude(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int longitude(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 10)) { if (data_len < min || (data_len && data_len < 10)) {
return 0; return 0;
@ -1334,7 +1308,7 @@ static int longitude(const unsigned char *data, int data_len, int offset, int mi
static int mediatype(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int mediatype(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 2)) { if (data_len < min || (data_len && data_len < 2)) {
return 0; return 0;
@ -1364,7 +1338,7 @@ static int mediatype(const unsigned char *data, int data_len, int offset, int mi
static int hyphen(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int hyphen(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -1392,7 +1366,7 @@ static int iso5218(const unsigned char *data, int data_len, int offset, int min,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;
@ -1415,7 +1389,7 @@ static int iso5218(const unsigned char *data, int data_len, int offset, int min,
static int posinseqslash(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int posinseqslash(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) { int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min) { if (data_len < min) {
return 0; return 0;

View File

@ -37,8 +37,8 @@
#define Z_GS1_LINT_H #define Z_GS1_LINT_H
/* N18,csum,key (Used by SSCC, GSRN - PROVIDER, GSRN - RECIPIENT) */ /* N18,csum,key (Used by SSCC, GSRN - PROVIDER, GSRN - RECIPIENT) */
static int n18_csum_key(const unsigned char *data, const int data_len, static int n18_csum_key(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 18 return data_len == 18
&& csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -48,8 +48,8 @@ static int n18_csum_key(const unsigned char *data, const int data_len,
} }
/* N14,csum,key (Used by GTIN, CONTENT) */ /* N14,csum,key (Used by GTIN, CONTENT) */
static int n14_csum_key(const unsigned char *data, const int data_len, static int n14_csum_key(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 14 return data_len == 14
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -58,16 +58,16 @@ static int n14_csum_key(const unsigned char *data, const int data_len,
&& key(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 0); && key(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 0);
} }
/* X..20 (Used by BATCH/LOT, SERIAL, CPV, PCN...) */ /* X..20 (Used by BATCH/LOT, SERIAL, CPV, PCN, GLN EXTENSION COMPONENT, SHIP TO POST, RTN TO POST, REFURB LOT, ...) */
static int x__20(const unsigned char *data, const int data_len, static int x__20(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 20 return data_len >= 1 && data_len <= 20
&& cset82(data, data_len, 0, 1, 20, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 20, p_err_no, p_err_posn, err_msg);
} }
/* N6,yymmd0 (Used by PROD DATE, DUE DATE, PACK DATE, BEST BEFORE or BEST BY...) */ /* N6,yymmd0 (Used by PROD DATE, DUE DATE, PACK DATE, BEST BEFORE or BEST BY, SELL BY, USE BY or EXPIRY) */
static int n6_yymmd0(const unsigned char *data, const int data_len, static int n6_yymmd0(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6 return data_len == 6
&& yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
@ -75,36 +75,36 @@ static int n6_yymmd0(const unsigned char *data, const int data_len,
} }
/* N2 (Used by VARIANT) */ /* N2 (Used by VARIANT) */
static int n2(const unsigned char *data, const int data_len, static int n2(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 2 return data_len == 2
&& numeric(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg);
} }
/* X..28 (Used by TPX) */ /* X..28 (Used by TPX) */
static int x__28(const unsigned char *data, const int data_len, static int x__28(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 28 return data_len >= 1 && data_len <= 28
&& cset82(data, data_len, 0, 1, 28, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 28, p_err_no, p_err_posn, err_msg);
} }
/* X..30 (Used by ADDITIONAL ID, CUST. PART No., SECONDARY SERIAL, REF. TO SOURCE...) */ /* X..30 (Used by ADDITIONAL ID, CUST. PART No., SECONDARY SERIAL, REF. TO SOURCE, ORDER NUMBER, ROUTE, SHIP TO...) */
static int x__30(const unsigned char *data, const int data_len, static int x__30(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 30 return data_len >= 1 && data_len <= 30
&& cset82(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg);
} }
/* N..6 (Used by MTO VARIANT) */ /* N..6 (Used by MTO VARIANT) */
static int n__6(const unsigned char *data, const int data_len, static int n__6(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 6 return data_len >= 1 && data_len <= 6
&& numeric(data, data_len, 0, 1, 6, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 1, 6, p_err_no, p_err_posn, err_msg);
} }
/* N13,csum,key [X..17] (Used by GDTI) */ /* N13,csum,key [X..17] (Used by GDTI) */
static int n13_csum_key__x__17_(const unsigned char *data, const int data_len, static int n13_csum_key__x__17_(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 13 && data_len <= 30 return data_len >= 13 && data_len <= 30
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -115,8 +115,8 @@ static int n13_csum_key__x__17_(const unsigned char *data, const int data_len,
} }
/* N13,csum,key [N..12] (Used by GCN) */ /* N13,csum,key [N..12] (Used by GCN) */
static int n13_csum_key__n__12_(const unsigned char *data, const int data_len, static int n13_csum_key__n__12_(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 13 && data_len <= 25 return data_len >= 13 && data_len <= 25
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -127,29 +127,29 @@ static int n13_csum_key__n__12_(const unsigned char *data, const int data_len,
} }
/* N..8 (Used by VAR. COUNT, COUNT) */ /* N..8 (Used by VAR. COUNT, COUNT) */
static int n__8(const unsigned char *data, const int data_len, static int n__8(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 8 return data_len >= 1 && data_len <= 8
&& numeric(data, data_len, 0, 1, 8, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 1, 8, p_err_no, p_err_posn, err_msg);
} }
/* N6 (Used by NET WEIGHT (kg), LENGTH (m), WIDTH (m), HEIGHT (m)...) */ /* N6 (Used by NET WEIGHT (kg), LENGTH (m), WIDTH (m), HEIGHT (m), AREA (m²), NET VOLUME (l), NET VOLUME (m³)...) */
static int n6(const unsigned char *data, const int data_len, static int n6(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6 return data_len == 6
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg);
} }
/* N..15 (Used by AMOUNT, PRICE) */ /* N..15 (Used by AMOUNT, PRICE) */
static int n__15(const unsigned char *data, const int data_len, static int n__15(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 15 return data_len >= 1 && data_len <= 15
&& numeric(data, data_len, 0, 1, 15, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 1, 15, p_err_no, p_err_posn, err_msg);
} }
/* N3,iso4217 N..15 (Used by AMOUNT, PRICE) */ /* N3,iso4217 N..15 (Used by AMOUNT, PRICE) */
static int n3_iso4217_n__15(const unsigned char *data, const int data_len, static int n3_iso4217_n__15(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 4 && data_len <= 18 return data_len >= 4 && data_len <= 18
&& iso4217(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && iso4217(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
@ -158,15 +158,15 @@ static int n3_iso4217_n__15(const unsigned char *data, const int data_len,
} }
/* N4 (Used by PRCNT OFF, POINTS) */ /* N4 (Used by PRCNT OFF, POINTS) */
static int n4(const unsigned char *data, const int data_len, static int n4(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 4 return data_len == 4
&& numeric(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg);
} }
/* X..30,key (Used by GINC, GIAI - ASSEMBLY, GIAI) */ /* X..30,key (Used by GINC, GIAI - ASSEMBLY, GIAI) */
static int x__30_key(const unsigned char *data, const int data_len, static int x__30_key(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 30 return data_len >= 1 && data_len <= 30
&& key(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg)
@ -174,8 +174,8 @@ static int x__30_key(const unsigned char *data, const int data_len,
} }
/* N17,csum,key (Used by GSIN) */ /* N17,csum,key (Used by GSIN) */
static int n17_csum_key(const unsigned char *data, const int data_len, static int n17_csum_key(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 17 return data_len == 17
&& csum(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csum(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -184,9 +184,9 @@ static int n17_csum_key(const unsigned char *data, const int data_len,
&& key(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 0); && key(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 0);
} }
/* N13,csum,key (Used by SHIP TO LOC, BILL TO, PURCHASE FROM, SHIP FOR LOC...) */ /* N13,csum,key (Used by SHIP TO LOC, BILL TO, PURCHASE FROM, SHIP FOR LOC, LOC No., PAY TO, PROD/SERV LOC, PARTY) */
static int n13_csum_key(const unsigned char *data, const int data_len, static int n13_csum_key(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 13 return data_len == 13
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -196,8 +196,8 @@ static int n13_csum_key(const unsigned char *data, const int data_len,
} }
/* N3,iso3166 X..9 (Used by SHIP TO POST) */ /* N3,iso3166 X..9 (Used by SHIP TO POST) */
static int n3_iso3166_x__9(const unsigned char *data, const int data_len, static int n3_iso3166_x__9(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 4 && data_len <= 12 return data_len >= 4 && data_len <= 12
&& iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
@ -206,42 +206,54 @@ static int n3_iso3166_x__9(const unsigned char *data, const int data_len,
} }
/* N3,iso3166 (Used by ORIGIN, COUNTRY - PROCESS, COUNTRY - FULL PROCESS) */ /* N3,iso3166 (Used by ORIGIN, COUNTRY - PROCESS, COUNTRY - FULL PROCESS) */
static int n3_iso3166(const unsigned char *data, const int data_len, static int n3_iso3166(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 3 return data_len == 3
&& iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
&& iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 0); && iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 0);
} }
/* N..15,iso3166list (Used by COUNTRY - INITIAL PROCESS, COUNTRY - DISASSEMBLY) */ /* N3,iso3166 [N3],iso3166 [N3],iso3166 [N3],iso3166 [N3],iso3166 (Used by COUNTRY - INITIAL PROCESS, COUNTRY -...) */
static int n__15_iso3166list(const unsigned char *data, const int data_len, static int n3_iso3166__n3__iso3166__n3__iso3166__n3__iso3166__n3__iso3166(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 15 return data_len >= 3 && data_len <= 15
&& iso3166list(data, data_len, 0, 1, 15, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 15, p_err_no, p_err_posn, err_msg) && iso3166(data, data_len, 3, 0, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& iso3166list(data, data_len, 0, 1, 15, p_err_no, p_err_posn, err_msg, 0); && iso3166(data, data_len, 6, 0, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& iso3166(data, data_len, 9, 0, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& iso3166(data, data_len, 12, 0, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
&& iso3166(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 3, 0, 3, p_err_no, p_err_posn, err_msg)
&& iso3166(data, data_len, 3, 0, 3, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 6, 0, 3, p_err_no, p_err_posn, err_msg)
&& iso3166(data, data_len, 6, 0, 3, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 9, 0, 3, p_err_no, p_err_posn, err_msg)
&& iso3166(data, data_len, 9, 0, 3, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 12, 0, 3, p_err_no, p_err_posn, err_msg)
&& iso3166(data, data_len, 12, 0, 3, p_err_no, p_err_posn, err_msg, 0);
} }
/* X..3 (Used by ORIGIN SUBDIVISION, AQUATIC SPECIES) */ /* X..3 (Used by ORIGIN SUBDIVISION, AQUATIC SPECIES) */
static int x__3(const unsigned char *data, const int data_len, static int x__3(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 3 return data_len >= 1 && data_len <= 3
&& cset82(data, data_len, 0, 1, 3, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 3, p_err_no, p_err_posn, err_msg);
} }
/* X..35,pcenc (Used by SHIP TO COMP, SHIP TO NAME, RTN TO COMP, RTN TO NAME...) */ /* X..35,pcenc (Used by SHIP TO COMP, SHIP TO NAME, RTN TO COMP, RTN TO NAME, SRV DESCRIPTION) */
static int x__35_pcenc(const unsigned char *data, const int data_len, static int x__35_pcenc(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 35 return data_len >= 1 && data_len <= 35
&& pcenc(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && pcenc(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg)
&& pcenc(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg, 0); && pcenc(data, data_len, 0, 1, 35, p_err_no, p_err_posn, err_msg, 0);
} }
/* X..70,pcenc (Used by SHIP TO ADD1, SHIP TO ADD2, SHIP TO SUB, SHIP TO LOC...) */ /* X..70,pcenc (Used by SHIP TO ADD1, SHIP TO ADD2, SHIP TO SUB, SHIP TO LOC, SHIP TO REG, RTN TO ADD1, RTN TO ...) */
static int x__70_pcenc(const unsigned char *data, const int data_len, static int x__70_pcenc(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 70 return data_len >= 1 && data_len <= 70
&& pcenc(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && pcenc(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg)
@ -249,8 +261,8 @@ static int x__70_pcenc(const unsigned char *data, const int data_len,
} }
/* X2,iso3166alpha2 (Used by SHIP TO COUNTRY, RTN TO COUNTRY) */ /* X2,iso3166alpha2 (Used by SHIP TO COUNTRY, RTN TO COUNTRY) */
static int x2_iso3166alpha2(const unsigned char *data, const int data_len, static int x2_iso3166alpha2(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 2 return data_len == 2
&& iso3166alpha2(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && iso3166alpha2(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg)
@ -258,8 +270,8 @@ static int x2_iso3166alpha2(const unsigned char *data, const int data_len,
} }
/* N10,latitude N10,longitude (Used by SHIP TO GEO) */ /* N10,latitude N10,longitude (Used by SHIP TO GEO) */
static int n10_latitude_n10_longitude(const unsigned char *data, const int data_len, static int n10_latitude_n10_longitude(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 20 return data_len == 20
&& latitude(data, data_len, 0, 10, 10, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && latitude(data, data_len, 0, 10, 10, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& longitude(data, data_len, 10, 10, 10, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && longitude(data, data_len, 10, 10, 10, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -270,8 +282,8 @@ static int n10_latitude_n10_longitude(const unsigned char *data, const int data_
} }
/* N1,yesno (Used by DANGEROUS GOODS, AUTH TO LEAVE, SIG REQUIRED) */ /* N1,yesno (Used by DANGEROUS GOODS, AUTH TO LEAVE, SIG REQUIRED) */
static int n1_yesno(const unsigned char *data, const int data_len, static int n1_yesno(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 1 return data_len == 1
&& yesno(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yesno(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg)
@ -279,8 +291,8 @@ static int n1_yesno(const unsigned char *data, const int data_len,
} }
/* N6,yymmd0 N4,hhmm (Used by NOT BEF DEL DT, NOT AFT DEL DT) */ /* N6,yymmd0 N4,hhmm (Used by NOT BEF DEL DT, NOT AFT DEL DT) */
static int n6_yymmd0_n4_hhmm(const unsigned char *data, const int data_len, static int n6_yymmd0_n4_hhmm(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 10 return data_len == 10
&& yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& hhmm(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && hhmm(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -291,8 +303,8 @@ static int n6_yymmd0_n4_hhmm(const unsigned char *data, const int data_len,
} }
/* N6,yymmdd (Used by REL DATE, FIRST FREEZE DATE) */ /* N6,yymmdd (Used by REL DATE, FIRST FREEZE DATE) */
static int n6_yymmdd(const unsigned char *data, const int data_len, static int n6_yymmdd(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6 return data_len == 6
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
@ -300,8 +312,8 @@ static int n6_yymmdd(const unsigned char *data, const int data_len,
} }
/* N6 [X1],hyphen (Used by MAX TEMP F., MAX TEMP C., MIN TEMP F., MIN TEMP C.) */ /* N6 [X1],hyphen (Used by MAX TEMP F., MAX TEMP C., MIN TEMP F., MIN TEMP C.) */
static int n6__x1__hyphen(const unsigned char *data, const int data_len, static int n6__x1__hyphen(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 6 && data_len <= 7 return data_len >= 6 && data_len <= 7
&& hyphen(data, data_len, 6, 0, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && hyphen(data, data_len, 6, 0, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
@ -310,15 +322,15 @@ static int n6__x1__hyphen(const unsigned char *data, const int data_len,
} }
/* N13 (Used by NSN) */ /* N13 (Used by NSN) */
static int n13(const unsigned char *data, const int data_len, static int n13(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 13 return data_len == 13
&& numeric(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg);
} }
/* N6,yymmdd N4,hhmm (Used by EXPIRY TIME) */ /* N6,yymmdd N4,hhmm (Used by EXPIRY TIME) */
static int n6_yymmdd_n4_hhmm(const unsigned char *data, const int data_len, static int n6_yymmdd_n4_hhmm(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 10 return data_len == 10
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& hhmm(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && hhmm(data, data_len, 6, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -329,22 +341,22 @@ static int n6_yymmdd_n4_hhmm(const unsigned char *data, const int data_len,
} }
/* N..4 (Used by ACTIVE POTENCY) */ /* N..4 (Used by ACTIVE POTENCY) */
static int n__4(const unsigned char *data, const int data_len, static int n__4(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 4 return data_len >= 1 && data_len <= 4
&& numeric(data, data_len, 0, 1, 4, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 1, 4, p_err_no, p_err_posn, err_msg);
} }
/* X..12 (Used by CATCH AREA) */ /* X..12 (Used by CATCH AREA) */
static int x__12(const unsigned char *data, const int data_len, static int x__12(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 12 return data_len >= 1 && data_len <= 12
&& cset82(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg);
} }
/* N6,yymmdd [N6],yymmdd (Used by HARVEST DATE) */ /* N6,yymmdd [N6],yymmdd (Used by HARVEST DATE) */
static int n6_yymmdd__n6__yymmdd(const unsigned char *data, const int data_len, static int n6_yymmdd__n6__yymmdd(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 6 && data_len <= 12 return data_len >= 6 && data_len <= 12
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& yymmdd(data, data_len, 6, 0, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmdd(data, data_len, 6, 0, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -355,22 +367,22 @@ static int n6_yymmdd__n6__yymmdd(const unsigned char *data, const int data_len,
} }
/* X..10 (Used by FISHING GEAR TYPE, SUFFIX) */ /* X..10 (Used by FISHING GEAR TYPE, SUFFIX) */
static int x__10(const unsigned char *data, const int data_len, static int x__10(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 10 return data_len >= 1 && data_len <= 10
&& cset82(data, data_len, 0, 1, 10, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 10, p_err_no, p_err_posn, err_msg);
} }
/* X..2 (Used by PROD METHOD) */ /* X..2 (Used by PROD METHOD) */
static int x__2(const unsigned char *data, const int data_len, static int x__2(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 2 return data_len >= 1 && data_len <= 2
&& cset82(data, data_len, 0, 1, 2, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 2, p_err_no, p_err_posn, err_msg);
} }
/* N6,yymmdd [N4],hhmm (Used by TEST BY DATE) */ /* N6,yymmdd [N4],hhmm (Used by TEST BY DATE) */
static int n6_yymmdd__n4__hhmm(const unsigned char *data, const int data_len, static int n6_yymmdd__n4__hhmm(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 6 && data_len <= 10 return data_len >= 6 && data_len <= 10
&& yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& hhmm(data, data_len, 6, 0, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && hhmm(data, data_len, 6, 0, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -380,9 +392,9 @@ static int n6_yymmdd__n4__hhmm(const unsigned char *data, const int data_len,
&& hhmm(data, data_len, 6, 0, 4, p_err_no, p_err_posn, err_msg, 0); && hhmm(data, data_len, 6, 0, 4, p_err_no, p_err_posn, err_msg, 0);
} }
/* N3,iso3166999 X..27 (Used by PROCESSOR # 0, PROCESSOR # 1, PROCESSOR # 2, PROCESSOR # 3...) */ /* N3,iso3166999 X..27 (Used by PROCESSOR # 0, PROCESSOR # 1, PROCESSOR # 2, PROCESSOR # 3, PROCESSOR # 4, PROC...) */
static int n3_iso3166999_x__27(const unsigned char *data, const int data_len, static int n3_iso3166999_x__27(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 4 && data_len <= 30 return data_len >= 4 && data_len <= 30
&& iso3166999(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && iso3166999(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
@ -391,8 +403,8 @@ static int n3_iso3166999_x__27(const unsigned char *data, const int data_len,
} }
/* N1 X1 X1 X1,importeridx (Used by UIC+EXT) */ /* N1 X1 X1 X1,importeridx (Used by UIC+EXT) */
static int n1_x1_x1_x1_importeridx(const unsigned char *data, const int data_len, static int n1_x1_x1_x1_importeridx(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 4 return data_len == 4
&& importeridx(data, data_len, 3, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && importeridx(data, data_len, 3, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg)
@ -402,17 +414,17 @@ static int n1_x1_x1_x1_importeridx(const unsigned char *data, const int data_len
&& importeridx(data, data_len, 3, 1, 1, p_err_no, p_err_posn, err_msg, 0); && importeridx(data, data_len, 3, 1, 1, p_err_no, p_err_posn, err_msg, 0);
} }
/* X2 X..28 (Used by CERT # 1, CERT # 2, CERT # 3, CERT # 4...) */ /* X2 X..28 (Used by CERT # 1, CERT # 2, CERT # 3, CERT # 4, CERT # 5, CERT # 6, CERT # 7, CERT # 8, CERT # 9, ...) */
static int x2_x__28(const unsigned char *data, const int data_len, static int x2_x__28(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 3 && data_len <= 30 return data_len >= 3 && data_len <= 30
&& cset82(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg)
&& cset82(data, data_len, 2, 1, 28, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 2, 1, 28, p_err_no, p_err_posn, err_msg);
} }
/* N2,mediatype (Used by AIDC MEDIA TYPE) */ /* N2,mediatype (Used by AIDC MEDIA TYPE) */
static int n2_mediatype(const unsigned char *data, const int data_len, static int n2_mediatype(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 2 return data_len == 2
&& mediatype(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && mediatype(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg)
@ -420,15 +432,15 @@ static int n2_mediatype(const unsigned char *data, const int data_len,
} }
/* X..25 (Used by VCN, REF No.) */ /* X..25 (Used by VCN, REF No.) */
static int x__25(const unsigned char *data, const int data_len, static int x__25(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 25 return data_len >= 1 && data_len <= 25
&& cset82(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg);
} }
/* N8,yyyymmdd (Used by DOB) */ /* N8,yyyymmdd (Used by DOB) */
static int n8_yyyymmdd(const unsigned char *data, const int data_len, static int n8_yyyymmdd(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 8 return data_len == 8
&& yyyymmdd(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yyyymmdd(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg)
@ -436,8 +448,8 @@ static int n8_yyyymmdd(const unsigned char *data, const int data_len,
} }
/* N8,yyyymmdd N4,hhmm (Used by DOB TIME) */ /* N8,yyyymmdd N4,hhmm (Used by DOB TIME) */
static int n8_yyyymmdd_n4_hhmm(const unsigned char *data, const int data_len, static int n8_yyyymmdd_n4_hhmm(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 12 return data_len == 12
&& yyyymmdd(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yyyymmdd(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& hhmm(data, data_len, 8, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && hhmm(data, data_len, 8, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -448,8 +460,8 @@ static int n8_yyyymmdd_n4_hhmm(const unsigned char *data, const int data_len,
} }
/* N1,iso5218 (Used by BIO SEX) */ /* N1,iso5218 (Used by BIO SEX) */
static int n1_iso5218(const unsigned char *data, const int data_len, static int n1_iso5218(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 1 return data_len == 1
&& iso5218(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && iso5218(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg)
@ -457,8 +469,8 @@ static int n1_iso5218(const unsigned char *data, const int data_len,
} }
/* X..40,pcenc (Used by FAMILY NAME, GIVEN NAME, BABY) */ /* X..40,pcenc (Used by FAMILY NAME, GIVEN NAME, BABY) */
static int x__40_pcenc(const unsigned char *data, const int data_len, static int x__40_pcenc(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 40 return data_len >= 1 && data_len <= 40
&& pcenc(data, data_len, 0, 1, 40, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && pcenc(data, data_len, 0, 1, 40, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 40, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 1, 40, p_err_no, p_err_posn, err_msg)
@ -466,8 +478,8 @@ static int x__40_pcenc(const unsigned char *data, const int data_len,
} }
/* X..90,pcenc (Used by FULL NAME) */ /* X..90,pcenc (Used by FULL NAME) */
static int x__90_pcenc(const unsigned char *data, const int data_len, static int x__90_pcenc(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 90 return data_len >= 1 && data_len <= 90
&& pcenc(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && pcenc(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg)
@ -475,8 +487,8 @@ static int x__90_pcenc(const unsigned char *data, const int data_len,
} }
/* X3,posinseqslash (Used by BIRTH SEQUENCE) */ /* X3,posinseqslash (Used by BIRTH SEQUENCE) */
static int x3_posinseqslash(const unsigned char *data, const int data_len, static int x3_posinseqslash(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 3 return data_len == 3
&& posinseqslash(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && posinseqslash(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 3, 3, p_err_no, p_err_posn, err_msg)
@ -484,8 +496,8 @@ static int x3_posinseqslash(const unsigned char *data, const int data_len,
} }
/* N4,nonzero N5,nonzero N3,nonzero N1,winding N1 (Used by DIMENSIONS) */ /* N4,nonzero N5,nonzero N3,nonzero N1,winding N1 (Used by DIMENSIONS) */
static int n4_nonzero_n5_nonzero_n3_nonzero_n1_winding_n1(const unsigned char *data, const int data_len, static int n4_nonzero_n5_nonzero_n3_nonzero_n1_winding_n1(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 14 return data_len == 14
&& nonzero(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && nonzero(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& nonzero(data, data_len, 4, 5, 5, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && nonzero(data, data_len, 4, 5, 5, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -503,8 +515,8 @@ static int n4_nonzero_n5_nonzero_n3_nonzero_n1_winding_n1(const unsigned char *d
} }
/* N1,zero N13,csum,key [X..16] (Used by GRAI) */ /* N1,zero N13,csum,key [X..16] (Used by GRAI) */
static int n1_zero_n13_csum_key__x__16_(const unsigned char *data, const int data_len, static int n1_zero_n13_csum_key__x__16_(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 14 && data_len <= 30 return data_len >= 14 && data_len <= 30
&& zero(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && zero(data, data_len, 0, 1, 1, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& csum(data, data_len, 1, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csum(data, data_len, 1, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -518,8 +530,8 @@ static int n1_zero_n13_csum_key__x__16_(const unsigned char *data, const int dat
} }
/* N14,csum N4,pieceoftotal (Used by ITIP, ITIP CONTENT) */ /* N14,csum N4,pieceoftotal (Used by ITIP, ITIP CONTENT) */
static int n14_csum_n4_pieceoftotal(const unsigned char *data, const int data_len, static int n14_csum_n4_pieceoftotal(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 18 return data_len == 18
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& pieceoftotal(data, data_len, 14, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && pieceoftotal(data, data_len, 14, 4, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -530,8 +542,8 @@ static int n14_csum_n4_pieceoftotal(const unsigned char *data, const int data_le
} }
/* X..34,iban (Used by IBAN) */ /* X..34,iban (Used by IBAN) */
static int x__34_iban(const unsigned char *data, const int data_len, static int x__34_iban(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 34 return data_len >= 1 && data_len <= 34
&& iban(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && iban(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg)
@ -539,8 +551,8 @@ static int x__34_iban(const unsigned char *data, const int data_len,
} }
/* N8,yymmddhh [N..4],mmoptss (Used by PROD TIME) */ /* N8,yymmddhh [N..4],mmoptss (Used by PROD TIME) */
static int n8_yymmddhh__n__4__mmoptss(const unsigned char *data, const int data_len, static int n8_yymmddhh__n__4__mmoptss(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 8 && data_len <= 12 return data_len >= 8 && data_len <= 12
&& yymmddhh(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmddhh(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& mmoptss(data, data_len, 8, 0, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && mmoptss(data, data_len, 8, 0, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -551,15 +563,15 @@ static int n8_yymmddhh__n__4__mmoptss(const unsigned char *data, const int data_
} }
/* X..50 (Used by OPTSEN) */ /* X..50 (Used by OPTSEN) */
static int x__50(const unsigned char *data, const int data_len, static int x__50(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 50 return data_len >= 1 && data_len <= 50
&& cset82(data, data_len, 0, 1, 50, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 50, p_err_no, p_err_posn, err_msg);
} }
/* Y..30,key (Used by CPID) */ /* Y..30,key (Used by CPID) */
static int y__30_key(const unsigned char *data, const int data_len, static int y__30_key(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 30 return data_len >= 1 && data_len <= 30
&& key(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset39(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg) && cset39(data, data_len, 0, 1, 30, p_err_no, p_err_posn, err_msg)
@ -567,8 +579,8 @@ static int y__30_key(const unsigned char *data, const int data_len,
} }
/* N..12,nozeroprefix (Used by CPID SERIAL) */ /* N..12,nozeroprefix (Used by CPID SERIAL) */
static int n__12_nozeroprefix(const unsigned char *data, const int data_len, static int n__12_nozeroprefix(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 12 return data_len >= 1 && data_len <= 12
&& nozeroprefix(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && nozeroprefix(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 1, 12, p_err_no, p_err_posn, err_msg)
@ -576,8 +588,8 @@ static int n__12_nozeroprefix(const unsigned char *data, const int data_len,
} }
/* X..25,csumalpha,key (Used by GMN) */ /* X..25,csumalpha,key (Used by GMN) */
static int x__25_csumalpha_key(const unsigned char *data, const int data_len, static int x__25_csumalpha_key(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 25 return data_len >= 1 && data_len <= 25
&& csumalpha(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && csumalpha(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -587,22 +599,22 @@ static int x__25_csumalpha_key(const unsigned char *data, const int data_len,
} }
/* N..10 (Used by SRIN) */ /* N..10 (Used by SRIN) */
static int n__10(const unsigned char *data, const int data_len, static int n__10(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 10 return data_len >= 1 && data_len <= 10
&& numeric(data, data_len, 0, 1, 10, p_err_no, p_err_posn, err_msg); && numeric(data, data_len, 0, 1, 10, p_err_no, p_err_posn, err_msg);
} }
/* Z..90 (Used by DIGSIG) */ /* Z..90 (Used by DIGSIG) */
static int z__90(const unsigned char *data, const int data_len, static int z__90(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 90 return data_len >= 1 && data_len <= 90
&& cset64(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg); && cset64(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg);
} }
/* X..70,couponcode */ /* X..70,couponcode */
static int x__70_couponcode(const unsigned char *data, const int data_len, static int x__70_couponcode(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 70 return data_len >= 1 && data_len <= 70
&& couponcode(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && couponcode(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg)
@ -610,8 +622,8 @@ static int x__70_couponcode(const unsigned char *data, const int data_len,
} }
/* X..70,couponposoffer */ /* X..70,couponposoffer */
static int x__70_couponposoffer(const unsigned char *data, const int data_len, static int x__70_couponposoffer(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 70 return data_len >= 1 && data_len <= 70
&& couponposoffer(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && couponposoffer(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg) && cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg)
@ -619,15 +631,15 @@ static int x__70_couponposoffer(const unsigned char *data, const int data_len,
} }
/* X..70 (Used by PRODUCT URL) */ /* X..70 (Used by PRODUCT URL) */
static int x__70(const unsigned char *data, const int data_len, static int x__70(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 70 return data_len >= 1 && data_len <= 70
&& cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 70, p_err_no, p_err_posn, err_msg);
} }
/* X..90 (Used by INTERNAL) */ /* X..90 (Used by INTERNAL) */
static int x__90(const unsigned char *data, const int data_len, static int x__90(const unsigned char *data,
int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 90 return data_len >= 1 && data_len <= 90
&& cset82(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg); && cset82(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg);
} }
@ -711,7 +723,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
return n3_iso3166(data, data_len, p_err_no, p_err_posn, err_msg); return n3_iso3166(data, data_len, p_err_no, p_err_posn, err_msg);
} }
if (ai == 423 || ai == 425) { if (ai == 423 || ai == 425) {
return n__15_iso3166list(data, data_len, p_err_no, p_err_posn, err_msg); return n3_iso3166__n3__iso3166__n3__iso3166__n3__iso3166__n3__iso3166(data, data_len, p_err_no, p_err_posn, err_msg);
} }
if (ai == 427) { if (ai == 427) {
return x__3(data, data_len, p_err_no, p_err_posn, err_msg); return x__3(data, data_len, p_err_no, p_err_posn, err_msg);

View File

@ -498,25 +498,6 @@ static int supports_eci(const int symbology) {
return 0; return 0;
} }
/* Returns 1 if symbology is Health Industry Bar Code */
static int is_hibc(const int symbology) {
switch (symbology) {
case BARCODE_HIBC_128:
case BARCODE_HIBC_39:
case BARCODE_HIBC_DM:
case BARCODE_HIBC_QR:
case BARCODE_HIBC_PDF:
case BARCODE_HIBC_MICPDF:
case BARCODE_HIBC_BLOCKF:
case BARCODE_HIBC_AZTEC:
return 1;
break;
}
return 0;
}
/* Returns 1 if symbology supports HRT */ /* Returns 1 if symbology supports HRT */
static int has_hrt(const int symbology) { static int has_hrt(const int symbology) {
@ -565,15 +546,12 @@ static int has_hrt(const int symbology) {
return 1; return 1;
} }
/* Suppress clang warning: a function declaration without a prototype is deprecated in all versions of C typedef int (*barcode_src_func_t)(struct zint_symbol *, unsigned char[], int);
(not included in gcc's "-wpedantic") */ typedef int (*barcode_seg_func_t)(struct zint_symbol *, struct zint_seg[], const int);
#if defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
#endif
/* Used for dispatching barcodes and for whether symbol id valid */ /* Used for dispatching `barcode_src_func_t` barcodes */
static int (*const barcode_funcs[BARCODE_LAST + 1])() = { /* Also used, with `barcode_seg_funcs` below, for testing whether symbol id valid in `ZBarcode_ValidID()` */
static const barcode_src_func_t barcode_src_funcs[BARCODE_LAST + 1] = {
NULL, code11, c25standard, c25inter, c25iata, /*0-4*/ NULL, code11, c25standard, c25inter, c25iata, /*0-4*/
NULL, c25logic, c25ind, code39, excode39, /*5-9*/ NULL, c25logic, c25ind, code39, excode39, /*5-9*/
NULL, NULL, NULL, eanx, eanx, /*10-14*/ NULL, NULL, NULL, eanx, eanx, /*10-14*/
@ -585,33 +563,52 @@ static int (*const barcode_funcs[BARCODE_LAST + 1])() = {
postnet, NULL, NULL, NULL, NULL, /*40-44*/ postnet, NULL, NULL, NULL, NULL, /*40-44*/
NULL, NULL, msi_plessey, NULL, fim, /*45-49*/ NULL, NULL, msi_plessey, NULL, fim, /*45-49*/
code39, pharma, pzn, pharma_two, postnet, /*50-54*/ code39, pharma, pzn, pharma_two, postnet, /*50-54*/
pdf417, pdf417, maxicode, qrcode, NULL, /*55-59*/ NULL, NULL, NULL, NULL, NULL, /*55-59*/
code128, NULL, NULL, auspost, NULL, /*60-64*/ code128, NULL, NULL, auspost, NULL, /*60-64*/
NULL, auspost, auspost, auspost, eanx, /*65-69*/ NULL, auspost, auspost, auspost, eanx, /*65-69*/
rm4scc, datamatrix, ean14, vin, codablockf, /*70-74*/ rm4scc, NULL, ean14, vin, codablockf, /*70-74*/
nve18, japanpost, koreapost, NULL, dbar_omn, /*75-79*/ nve18, japanpost, koreapost, NULL, dbar_omn, /*75-79*/
dbar_omn, dbar_exp, planet, NULL, micropdf417, /*80-84*/ dbar_omn, dbar_exp, planet, NULL, NULL, /*80-84*/
usps_imail, plessey, telepen_num, NULL, itf14, /*85-89*/ usps_imail, plessey, telepen_num, NULL, itf14, /*85-89*/
kix, NULL, aztec, daft, NULL, /*90-94*/ kix, NULL, NULL, daft, NULL, /*90-94*/
NULL, dpd, microqr, hibc, hibc, /*95-99*/ NULL, dpd, microqr, NULL, NULL, /*95-99*/
NULL, NULL, hibc, NULL, hibc, /*100-104*/ NULL, NULL, NULL, NULL, NULL, /*100-104*/
NULL, hibc, NULL, hibc, NULL, /*105-109*/ NULL, NULL, NULL, NULL, NULL, /*105-109*/
hibc, NULL, hibc, NULL, NULL, /*110-114*/ NULL, NULL, NULL, NULL, NULL, /*110-114*/
dotcode, hanxin, NULL, NULL, mailmark_2d, /*115-119*/ NULL, NULL, NULL, NULL, mailmark_2d, /*115-119*/
upu_s10, mailmark_4s, NULL, NULL, NULL, /*120-124*/ upu_s10, mailmark_4s, NULL, NULL, NULL, /*120-124*/
NULL, NULL, NULL, azrune, code32, /*125-129*/ NULL, NULL, NULL, azrune, code32, /*125-129*/
composite, composite, composite, composite, composite, /*130-134*/ composite, composite, composite, composite, composite, /*130-134*/
composite, composite, composite, composite, composite, /*135-139*/ composite, composite, composite, composite, composite, /*135-139*/
channel, codeone, gridmatrix, upnqr, ultra, /*140-144*/ channel, NULL, NULL, upnqr, NULL, /*140-144*/
rmqr, bc412, NULL, bc412, /*145-146*/
}; };
#if defined(__clang__) #define LIB_SEG_FUNCS_START 55
#pragma GCC diagnostic pop
#endif /* Used for dispatching `barcode_seg_func_t` barcodes */
static const barcode_seg_func_t barcode_seg_funcs[BARCODE_LAST + 1 - LIB_SEG_FUNCS_START] = {
pdf417, pdf417, maxicode, qrcode, NULL, /*55-59*/
NULL, NULL, NULL, NULL, NULL, /*60-64*/
NULL, NULL, NULL, NULL, NULL, /*65-69*/
NULL, datamatrix, NULL, NULL, NULL, /*70-74*/
NULL, NULL, NULL, NULL, NULL, /*75-79*/
NULL, NULL, NULL, NULL, micropdf417, /*80-84*/
NULL, NULL, NULL, NULL, NULL, /*85-89*/
NULL, NULL, aztec, NULL, NULL, /*90-94*/
NULL, NULL, NULL, hibc, hibc, /*95-99*/
NULL, NULL, hibc, NULL, hibc, /*100-104*/
NULL, hibc, NULL, hibc, NULL, /*105-109*/
hibc, NULL, hibc, NULL, NULL, /*110-114*/
dotcode, hanxin, NULL, NULL, NULL, /*115-119*/
NULL, NULL, NULL, NULL, NULL, /*120-124*/
NULL, NULL, NULL, NULL, NULL, /*125-129*/
NULL, NULL, NULL, NULL, NULL, /*130-134*/
NULL, NULL, NULL, NULL, NULL, /*135-139*/
NULL, codeone, gridmatrix, NULL, ultra, /*140-144*/
rmqr, NULL, /*145-146*/
};
typedef int (*barcode_segs_func_t)(struct zint_symbol *, struct zint_seg[], const int);
typedef int (*barcode_func_t)(struct zint_symbol *, unsigned char[], int);
static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count); static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count);
/* Main dispatch, checking for barcodes which handle ECIs/character sets themselves, otherwise calling /* Main dispatch, checking for barcodes which handle ECIs/character sets themselves, otherwise calling
@ -625,13 +622,12 @@ static int extended_or_reduced_charset(struct zint_symbol *symbol, struct zint_s
case BARCODE_GRIDMATRIX: case BARCODE_GRIDMATRIX:
case BARCODE_HANXIN: case BARCODE_HANXIN:
case BARCODE_RMQR: case BARCODE_RMQR:
error_number = (*(barcode_segs_func_t)barcode_funcs[symbol->symbology])(symbol, segs, seg_count); error_number = barcode_seg_funcs[symbol->symbology - LIB_SEG_FUNCS_START](symbol, segs, seg_count);
break; break;
/* These are the standards which have support for specific character sets but not ECI */ /* These are the standards which have support for specific character sets but not ECI */
case BARCODE_MICROQR: case BARCODE_MICROQR:
case BARCODE_UPNQR: case BARCODE_UPNQR:
error_number = (*(barcode_func_t)barcode_funcs[symbol->symbology])(symbol, segs[0].source, error_number = barcode_src_funcs[symbol->symbology](symbol, segs[0].source, segs[0].length);
segs[0].length);
break; break;
default: error_number = reduced_charset(symbol, segs, seg_count); default: error_number = reduced_charset(symbol, segs, seg_count);
break; break;
@ -671,19 +667,19 @@ static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], c
preprocessed += local_segs[i].length + 1; preprocessed += local_segs[i].length + 1;
} }
} }
if (supports_eci(symbol->symbology) || is_hibc(symbol->symbology)) { if (barcode_src_funcs[symbol->symbology]) {
error_number = (*(barcode_segs_func_t)barcode_funcs[symbol->symbology])(symbol, local_segs, seg_count); error_number = barcode_src_funcs[symbol->symbology](symbol, local_segs[0].source, local_segs[0].length);
} else { } else {
error_number = (*(barcode_func_t)barcode_funcs[symbol->symbology])(symbol, local_segs[0].source, error_number = barcode_seg_funcs[symbol->symbology - LIB_SEG_FUNCS_START](symbol, local_segs, seg_count);
local_segs[0].length);
} }
} else { } else {
if (supports_eci(symbol->symbology) || is_hibc(symbol->symbology)) { if (barcode_src_funcs[symbol->symbology]) {
segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs) */ error_number = barcode_src_funcs[symbol->symbology](symbol, segs[0].source, segs[0].length);
error_number = (*(barcode_segs_func_t)barcode_funcs[symbol->symbology])(symbol, local_segs, seg_count);
} else { } else {
error_number = (*(barcode_func_t)barcode_funcs[symbol->symbology])(symbol, segs[0].source, assert(symbol->symbology >= LIB_SEG_FUNCS_START); /* Suppress clang-tidy-19 warning */
segs[0].length); assert(barcode_seg_funcs[symbol->symbology - LIB_SEG_FUNCS_START]); /* Suppress clang-tidy-19 warning */
segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs) */
error_number = barcode_seg_funcs[symbol->symbology - LIB_SEG_FUNCS_START](symbol, local_segs, seg_count);
} }
} }
@ -893,6 +889,72 @@ INTERNAL int escape_char_process_test(struct zint_symbol *symbol, const unsigned
} }
#endif #endif
/* For backward-compatibility, map certain invalid symbol ids to zint equivalents, some silently, some with warning */
static int map_invalid_symbology(struct zint_symbol *symbol) {
/* Symbol ids 1 to 126 are defined by tbarcode */
/* 26 allowed: UPC-A up to tbarcode 9, ISSN for tbarcode 10+, mapped to UPC-A */
/* 27 error: UPCD1 up to tbarcode 9, ISSN + 2 digit add-on for tbarcode 10+ */
/* 91 warning: BC412 up to tbarcode 9, Code 32 for tbarcode 10+, mapped to Code 128 */
/* Note: non-zero table entries map silently, i.e. do not produce a warning */
#define LIB_ID_MAP_LAST 111
static const unsigned char id_map[LIB_ID_MAP_LAST + 1] = {
0, 0, 0, 0, 0, /*0-4*/
BARCODE_C25STANDARD, 0, 0, 0, 0, /*5-9*/
BARCODE_EANX, BARCODE_EANX, BARCODE_EANX, 0, 0, /*10-14*/
BARCODE_EANX, 0, BARCODE_UPCA, 0, BARCODE_CODABAR, /*15-19*/
0, 0, 0, 0, 0, /*20-24*/
0, BARCODE_UPCA, 0, 0, 0, /*25-29*/
0, 0, 0, BARCODE_GS1_128, 0, /*30-34*/
0, BARCODE_UPCA, 0, 0, BARCODE_UPCE, /*35-39*/
0, BARCODE_POSTNET, BARCODE_POSTNET, BARCODE_POSTNET, BARCODE_POSTNET, /*40-44*/
BARCODE_POSTNET, BARCODE_PLESSEY, 0, BARCODE_NVE18, 0, /*45-49*/
0, 0, 0, 0, 0, /*50-54*/
0, 0, 0, 0, BARCODE_CODE128, /*55-59*/
0, BARCODE_CODE128, BARCODE_CODE93, 0, BARCODE_AUSPOST, /*60-64*/
BARCODE_AUSPOST, 0, 0, 0, 0, /*65-69*/
0, 0, 0, 0, 0, /*70-74*/
0, 0, 0, BARCODE_DBAR_OMN, 0, /*75-79*/
0, 0, 0, BARCODE_PLANET, 0, /*80-84*/
0, 0, 0, BARCODE_GS1_128, 0, /*85-89*/
0, 0, 0, 0, 0, /*90-94*/
0, 0, 0, 0, 0, /*95-99*/
BARCODE_HIBC_128, BARCODE_HIBC_39, 0, BARCODE_HIBC_DM, 0, /*100-104*/
BARCODE_HIBC_QR, 0, BARCODE_HIBC_PDF, 0, BARCODE_HIBC_MICPDF, /*105-109*/
0, BARCODE_HIBC_BLOCKF, /*110-111*/
};
const int orig_symbology = symbol->symbology; /* For self-check */
int warn_number = 0;
if (symbol->symbology == 19) {
/* Has specific error message */
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "207: Codabar 18 not supported");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODABAR;
} else if (symbol->symbology == 27) {
/* Not mapped */
return error_tag(symbol, ZINT_ERROR_INVALID_OPTION, "208: UPCD1 not supported");
} else if (symbol->symbology <= 0 || symbol->symbology > LIB_ID_MAP_LAST || id_map[symbol->symbology] == 0) {
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "206: Symbology out of range");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODE128;
} else {
symbol->symbology = id_map[symbol->symbology];
}
if (symbol->symbology == orig_symbology) { /* Should never happen */
assert(0); /* Not reached */
return error_tag(symbol, ZINT_ERROR_ENCODING_PROBLEM, "000: Internal error");
}
return warn_number;
}
/* Encode a barcode. If `length` is 0, `source` must be NUL-terminated */ /* Encode a barcode. If `length` is 0, `source` must be NUL-terminated */
int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int length) { int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int length) {
struct zint_seg segs[1]; struct zint_seg segs[1];
@ -925,12 +987,25 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
if (seg_count > ZINT_MAX_SEG_COUNT) { if (seg_count > ZINT_MAX_SEG_COUNT) {
return error_tag(symbol, ZINT_ERROR_INVALID_DATA, "771: Too many input segments (max 256)"); return error_tag(symbol, ZINT_ERROR_INVALID_DATA, "771: Too many input segments (max 256)");
} }
local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * (seg_count > 0 ? seg_count : 1));
if ((symbol->input_mode & 0x07) > 2) { if ((symbol->input_mode & 0x07) > 2) {
symbol->input_mode = DATA_MODE; /* Reset completely TODO: in future, warn/error */ symbol->input_mode = DATA_MODE; /* Reset completely */
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "212: Invalid input mode - reset to DATA_MODE");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
} }
/* Check the symbology field */
if (!ZBarcode_ValidID(symbol->symbology)) {
warn_number = map_invalid_symbology(symbol);
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
}
local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * (seg_count > 0 ? seg_count : 1));
/* Check segment lengths */ /* Check segment lengths */
for (i = 0; i < seg_count; i++) { for (i = 0; i < seg_count; i++) {
local_segs[i] = segs[i]; local_segs[i] = segs[i];
@ -943,9 +1018,8 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
} }
if (local_segs[i].length <= 0) { if (local_segs[i].length <= 0) {
if (i == 0) { if (i == 0) {
/* Note: should really be referencing the symbology only after the symbology check switch below */ if (is_composite(symbol->symbology)
if (is_composite(symbol->symbology) && && ((symbol->input_mode & 0x07) == GS1_MODE || check_force_gs1(symbol->symbology))) {
((symbol->input_mode & 0x07) == GS1_MODE || check_force_gs1(symbol->symbology))) {
strcpy(symbol->errtxt, "779: No composite data in 2D component"); strcpy(symbol->errtxt, "779: No composite data in 2D component");
} else { } else {
sprintf(symbol->errtxt, "778: No input data%s", sprintf(symbol->errtxt, "778: No input data%s",
@ -1015,111 +1089,6 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
} }
} }
/* Check the symbology field */
if (!ZBarcode_ValidID(symbol->symbology)) {
int orig_symbology = symbol->symbology; /* For self-check */
if (symbol->symbology < 1) {
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "206: Symbology out of range");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODE128;
/* symbol->symbologys 1 to 126 are defined by tbarcode */
} else if (symbol->symbology == 5) {
symbol->symbology = BARCODE_C25STANDARD;
} else if ((symbol->symbology >= 10) && (symbol->symbology <= 12)) {
symbol->symbology = BARCODE_EANX;
} else if (symbol->symbology == 15) {
symbol->symbology = BARCODE_EANX;
} else if (symbol->symbology == 17) {
symbol->symbology = BARCODE_UPCA;
} else if (symbol->symbology == 19) {
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "207: Codabar 18 not supported");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODABAR;
} else if (symbol->symbology == 26) { /* UPC-A up to tbarcode 9, ISSN for tbarcode 10+ */
symbol->symbology = BARCODE_UPCA;
} else if (symbol->symbology == 27) { /* UPCD1 up to tbarcode 9, ISSN + 2 digit add-on for tbarcode 10+ */
return error_tag(symbol, ZINT_ERROR_INVALID_OPTION, "208: UPCD1 not supported");
} else if (symbol->symbology == 33) {
symbol->symbology = BARCODE_GS1_128;
} else if (symbol->symbology == 36) {
symbol->symbology = BARCODE_UPCA;
} else if (symbol->symbology == 39) {
symbol->symbology = BARCODE_UPCE;
} else if ((symbol->symbology >= 41) && (symbol->symbology <= 45)) {
symbol->symbology = BARCODE_POSTNET;
} else if (symbol->symbology == 46) {
symbol->symbology = BARCODE_PLESSEY;
} else if (symbol->symbology == 48) {
symbol->symbology = BARCODE_NVE18;
} else if ((symbol->symbology == 59) || (symbol->symbology == 61)) {
symbol->symbology = BARCODE_CODE128;
} else if (symbol->symbology == 62) {
symbol->symbology = BARCODE_CODE93;
} else if ((symbol->symbology == 64) || (symbol->symbology == 65)) {
symbol->symbology = BARCODE_AUSPOST;
} else if (symbol->symbology == 78) {
symbol->symbology = BARCODE_DBAR_OMN;
} else if (symbol->symbology == 83) {
symbol->symbology = BARCODE_PLANET;
} else if (symbol->symbology == 88) {
symbol->symbology = BARCODE_GS1_128;
} else if (symbol->symbology == 91) { /* BC412 up to tbarcode 9, Code 32 for tbarcode 10+ */
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "212: Symbology out of range");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODE128;
} else if ((symbol->symbology >= 94) && (symbol->symbology <= 95)) {
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "213: Symbology out of range");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODE128;
} else if (symbol->symbology == 100) {
symbol->symbology = BARCODE_HIBC_128;
} else if (symbol->symbology == 101) {
symbol->symbology = BARCODE_HIBC_39;
} else if (symbol->symbology == 103) {
symbol->symbology = BARCODE_HIBC_DM;
} else if (symbol->symbology == 105) {
symbol->symbology = BARCODE_HIBC_QR;
} else if (symbol->symbology == 107) {
symbol->symbology = BARCODE_HIBC_PDF;
} else if (symbol->symbology == 109) {
symbol->symbology = BARCODE_HIBC_MICPDF;
} else if (symbol->symbology == 111) {
symbol->symbology = BARCODE_HIBC_BLOCKF;
} else if ((symbol->symbology == 113) || (symbol->symbology == 114)) {
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "214: Symbology out of range");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODE128;
} else if ((symbol->symbology >= 117) && (symbol->symbology <= 127)) {
if (symbol->symbology < 119 || symbol->symbology > 121) { /* BARCODE_MAILMARK_2D/4S/UPU_S10 */
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "215: Symbology out of range");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODE128;
}
/* Everything from 128 up is Zint-specific */
} else if (symbol->symbology > BARCODE_LAST) {
warn_number = error_tag(symbol, ZINT_WARN_INVALID_OPTION, "216: Symbology out of range");
if (warn_number >= ZINT_ERROR) {
return warn_number;
}
symbol->symbology = BARCODE_CODE128;
}
if (symbol->symbology == orig_symbology) { /* Should never happen */
return error_tag(symbol, ZINT_ERROR_ENCODING_PROBLEM, "000: Internal error"); /* Not reached */
}
}
if (seg_count > 1 && !supports_eci(symbol->symbology)) { if (seg_count > 1 && !supports_eci(symbol->symbology)) {
return error_tag(symbol, ZINT_ERROR_INVALID_OPTION, "775: Symbology does not support multiple segments"); return error_tag(symbol, ZINT_ERROR_INVALID_OPTION, "775: Symbology does not support multiple segments");
} }
@ -1624,165 +1593,44 @@ int ZBarcode_ValidID(int symbol_id) {
return 0; return 0;
} }
return barcode_funcs[symbol_id] != NULL; return barcode_src_funcs[symbol_id] != NULL
|| (symbol_id >= LIB_SEG_FUNCS_START && barcode_seg_funcs[symbol_id - LIB_SEG_FUNCS_START] != NULL);
} }
/* Copy BARCODE_XXX name of `symbol_id` into `name` buffer, NUL-terminated. /* Copy BARCODE_XXX name of `symbol_id` into `name` buffer, NUL-terminated.
Returns 0 if valid, non-zero (1 or -1) if not valid */ Returns 0 if valid, 1 if not valid */
int ZBarcode_BarcodeName(int symbol_id, char name[32]) { int ZBarcode_BarcodeName(int symbol_id, char name[32]) {
struct item { static const char *const names[] = {
const char *name; "", "CODE11", "C25STANDARD", "C25INTER", "C25IATA", /*0-4*/
int define; "", "C25LOGIC", "C25IND", "CODE39", "EXCODE39", /*5-9*/
int val; "", "", "", "EANX", "EANX_CHK", /*10-14*/
}; "", "GS1_128", "", "CODABAR", "", /*15-19*/
static const struct item data[] = { "CODE128", "DPLEIT", "DPIDENT", "CODE16K", "CODE49", /*20-24*/
{ "", -1, 0 }, "CODE93", "", "", "FLAT", "DBAR_OMN", /*25-29*/
{ "BARCODE_CODE11", BARCODE_CODE11, 1 }, "DBAR_LTD", "DBAR_EXP", "TELEPEN", "", "UPCA", /*30-34*/
{ "BARCODE_C25STANDARD", BARCODE_C25STANDARD, 2 }, "UPCA_CHK", "", "UPCE", "UPCE_CHK", "", /*35-39*/
{ "BARCODE_C25INTER", BARCODE_C25INTER, 3 }, "POSTNET", "", "", "", "", /*40-44*/
{ "BARCODE_C25IATA", BARCODE_C25IATA, 4 }, "", "", "MSI_PLESSEY", "", "FIM", /*45-49*/
{ "", -1, 5 }, "LOGMARS", "PHARMA", "PZN", "PHARMA_TWO", "CEPNET", /*50-54*/
{ "BARCODE_C25LOGIC", BARCODE_C25LOGIC, 6 }, "PDF417", "PDF417COMP", "MAXICODE", "QRCODE", "", /*55-59*/
{ "BARCODE_C25IND", BARCODE_C25IND, 7 }, "CODE128AB", "", "", "AUSPOST", "", /*60-64*/
{ "BARCODE_CODE39", BARCODE_CODE39, 8 }, "", "AUSREPLY", "AUSROUTE", "AUSREDIRECT", "ISBNX", /*65-69*/
{ "BARCODE_EXCODE39", BARCODE_EXCODE39, 9 }, "RM4SCC", "DATAMATRIX", "EAN14", "VIN", "CODABLOCKF", /*70-74*/
{ "", -1, 10 }, "NVE18", "JAPANPOST", "KOREAPOST", "", "DBAR_STK", /*75-79*/
{ "", -1, 11 }, "DBAR_OMNSTK", "DBAR_EXPSTK", "PLANET", "", "MICROPDF417", /*80-84*/
{ "", -1, 12 }, "USPS_IMAIL", "PLESSEY", "TELEPEN_NUM", "", "ITF14", /*85-89*/
{ "BARCODE_EANX", BARCODE_EANX, 13 }, "KIX", "", "AZTEC", "DAFT", "", /*90-94*/
{ "BARCODE_EANX_CHK", BARCODE_EANX_CHK, 14 }, "", "DPD", "MICROQR", "HIBC_128", "HIBC_39", /*95-99*/
{ "", -1, 15 }, "", "", "HIBC_DM", "", "HIBC_QR", /*100-104*/
{ "BARCODE_GS1_128", BARCODE_GS1_128, 16 }, "", "HIBC_PDF", "", "HIBC_MICPDF", "", /*105-109*/
{ "", -1, 17 }, "HIBC_BLOCKF", "", "HIBC_AZTEC", "", "", /*110-114*/
{ "BARCODE_CODABAR", BARCODE_CODABAR, 18 }, "DOTCODE", "HANXIN", "", "", "MAILMARK_2D", /*115-119*/
{ "", -1, 19 }, "UPU_S10", "MAILMARK_4S", "", "", "", /*120-124*/
{ "BARCODE_CODE128", BARCODE_CODE128, 20 }, "", "", "", "AZRUNE", "CODE32", /*125-129*/
{ "BARCODE_DPLEIT", BARCODE_DPLEIT, 21 }, "EANX_CC", "GS1_128_CC", "DBAR_OMN_CC", "DBAR_LTD_CC", "DBAR_EXP_CC", /*130-134*/
{ "BARCODE_DPIDENT", BARCODE_DPIDENT, 22 }, "UPCA_CC", "UPCE_CC", "DBAR_STK_CC", "DBAR_OMNSTK_CC", "DBAR_EXPSTK_CC", /*135-139*/
{ "BARCODE_CODE16K", BARCODE_CODE16K, 23 }, "CHANNEL", "CODEONE", "GRIDMATRIX", "UPNQR", "ULTRA", /*140-144*/
{ "BARCODE_CODE49", BARCODE_CODE49, 24 }, "RMQR", "BC412", /*145-146*/
{ "BARCODE_CODE93", BARCODE_CODE93, 25 },
{ "", -1, 26 },
{ "", -1, 27 },
{ "BARCODE_FLAT", BARCODE_FLAT, 28 },
{ "BARCODE_DBAR_OMN", BARCODE_DBAR_OMN, 29 },
{ "BARCODE_DBAR_LTD", BARCODE_DBAR_LTD, 30 },
{ "BARCODE_DBAR_EXP", BARCODE_DBAR_EXP, 31 },
{ "BARCODE_TELEPEN", BARCODE_TELEPEN, 32 },
{ "", -1, 33 },
{ "BARCODE_UPCA", BARCODE_UPCA, 34 },
{ "BARCODE_UPCA_CHK", BARCODE_UPCA_CHK, 35 },
{ "", -1, 36 },
{ "BARCODE_UPCE", BARCODE_UPCE, 37 },
{ "BARCODE_UPCE_CHK", BARCODE_UPCE_CHK, 38 },
{ "", -1, 39 },
{ "BARCODE_POSTNET", BARCODE_POSTNET, 40 },
{ "", -1, 41 },
{ "", -1, 42 },
{ "", -1, 43 },
{ "", -1, 44 },
{ "", -1, 45 },
{ "", -1, 46 },
{ "BARCODE_MSI_PLESSEY", BARCODE_MSI_PLESSEY, 47 },
{ "", -1, 48 },
{ "BARCODE_FIM", BARCODE_FIM, 49 },
{ "BARCODE_LOGMARS", BARCODE_LOGMARS, 50 },
{ "BARCODE_PHARMA", BARCODE_PHARMA, 51 },
{ "BARCODE_PZN", BARCODE_PZN, 52 },
{ "BARCODE_PHARMA_TWO", BARCODE_PHARMA_TWO, 53 },
{ "BARCODE_CEPNET", BARCODE_CEPNET, 54 },
{ "BARCODE_PDF417", BARCODE_PDF417, 55 },
{ "BARCODE_PDF417COMP", BARCODE_PDF417COMP, 56 },
{ "BARCODE_MAXICODE", BARCODE_MAXICODE, 57 },
{ "BARCODE_QRCODE", BARCODE_QRCODE, 58 },
{ "", -1, 59 },
{ "BARCODE_CODE128AB", BARCODE_CODE128AB, 60 },
{ "", -1, 61 },
{ "", -1, 62 },
{ "BARCODE_AUSPOST", BARCODE_AUSPOST, 63 },
{ "", -1, 64 },
{ "", -1, 65 },
{ "BARCODE_AUSREPLY", BARCODE_AUSREPLY, 66 },
{ "BARCODE_AUSROUTE", BARCODE_AUSROUTE, 67 },
{ "BARCODE_AUSREDIRECT", BARCODE_AUSREDIRECT, 68 },
{ "BARCODE_ISBNX", BARCODE_ISBNX, 69 },
{ "BARCODE_RM4SCC", BARCODE_RM4SCC, 70 },
{ "BARCODE_DATAMATRIX", BARCODE_DATAMATRIX, 71 },
{ "BARCODE_EAN14", BARCODE_EAN14, 72 },
{ "BARCODE_VIN", BARCODE_VIN, 73 },
{ "BARCODE_CODABLOCKF", BARCODE_CODABLOCKF, 74 },
{ "BARCODE_NVE18", BARCODE_NVE18, 75 },
{ "BARCODE_JAPANPOST", BARCODE_JAPANPOST, 76 },
{ "BARCODE_KOREAPOST", BARCODE_KOREAPOST, 77 },
{ "", -1, 78 },
{ "BARCODE_DBAR_STK", BARCODE_DBAR_STK, 79 },
{ "BARCODE_DBAR_OMNSTK", BARCODE_DBAR_OMNSTK, 80 },
{ "BARCODE_DBAR_EXPSTK", BARCODE_DBAR_EXPSTK, 81 },
{ "BARCODE_PLANET", BARCODE_PLANET, 82 },
{ "", -1, 83 },
{ "BARCODE_MICROPDF417", BARCODE_MICROPDF417, 84 },
{ "BARCODE_USPS_IMAIL", BARCODE_USPS_IMAIL, 85 },
{ "BARCODE_PLESSEY", BARCODE_PLESSEY, 86 },
{ "BARCODE_TELEPEN_NUM", BARCODE_TELEPEN_NUM, 87 },
{ "", -1, 88 },
{ "BARCODE_ITF14", BARCODE_ITF14, 89 },
{ "BARCODE_KIX", BARCODE_KIX, 90 },
{ "", -1, 91 },
{ "BARCODE_AZTEC", BARCODE_AZTEC, 92 },
{ "BARCODE_DAFT", BARCODE_DAFT, 93 },
{ "", -1, 94 },
{ "", -1, 95 },
{ "BARCODE_DPD", BARCODE_DPD, 96 },
{ "BARCODE_MICROQR", BARCODE_MICROQR, 97 },
{ "BARCODE_HIBC_128", BARCODE_HIBC_128, 98 },
{ "BARCODE_HIBC_39", BARCODE_HIBC_39, 99 },
{ "", -1, 100 },
{ "", -1, 101 },
{ "BARCODE_HIBC_DM", BARCODE_HIBC_DM, 102 },
{ "", -1, 103 },
{ "BARCODE_HIBC_QR", BARCODE_HIBC_QR, 104 },
{ "", -1, 105 },
{ "BARCODE_HIBC_PDF", BARCODE_HIBC_PDF, 106 },
{ "", -1, 107 },
{ "BARCODE_HIBC_MICPDF", BARCODE_HIBC_MICPDF, 108 },
{ "", -1, 109 },
{ "BARCODE_HIBC_BLOCKF", BARCODE_HIBC_BLOCKF, 110 },
{ "", -1, 111 },
{ "BARCODE_HIBC_AZTEC", BARCODE_HIBC_AZTEC, 112 },
{ "", -1, 113 },
{ "", -1, 114 },
{ "BARCODE_DOTCODE", BARCODE_DOTCODE, 115 },
{ "BARCODE_HANXIN", BARCODE_HANXIN, 116 },
{ "", -1, 117 },
{ "", -1, 118 },
{ "BARCODE_MAILMARK_2D", BARCODE_MAILMARK_2D, 119 },
{ "BARCODE_UPU_S10", BARCODE_UPU_S10, 120 },
{ "BARCODE_MAILMARK_4S", BARCODE_MAILMARK_4S, 121 },
{ "", -1, 122 },
{ "", -1, 123 },
{ "", -1, 124 },
{ "", -1, 125 },
{ "", -1, 126 },
{ "", -1, 127 },
{ "BARCODE_AZRUNE", BARCODE_AZRUNE, 128 },
{ "BARCODE_CODE32", BARCODE_CODE32, 129 },
{ "BARCODE_EANX_CC", BARCODE_EANX_CC, 130 },
{ "BARCODE_GS1_128_CC", BARCODE_GS1_128_CC, 131 },
{ "BARCODE_DBAR_OMN_CC", BARCODE_DBAR_OMN_CC, 132 },
{ "BARCODE_DBAR_LTD_CC", BARCODE_DBAR_LTD_CC, 133 },
{ "BARCODE_DBAR_EXP_CC", BARCODE_DBAR_EXP_CC, 134 },
{ "BARCODE_UPCA_CC", BARCODE_UPCA_CC, 135 },
{ "BARCODE_UPCE_CC", BARCODE_UPCE_CC, 136 },
{ "BARCODE_DBAR_STK_CC", BARCODE_DBAR_STK_CC, 137 },
{ "BARCODE_DBAR_OMNSTK_CC", BARCODE_DBAR_OMNSTK_CC, 138 },
{ "BARCODE_DBAR_EXPSTK_CC", BARCODE_DBAR_EXPSTK_CC, 139 },
{ "BARCODE_CHANNEL", BARCODE_CHANNEL, 140 },
{ "BARCODE_CODEONE", BARCODE_CODEONE, 141 },
{ "BARCODE_GRIDMATRIX", BARCODE_GRIDMATRIX, 142 },
{ "BARCODE_UPNQR", BARCODE_UPNQR, 143 },
{ "BARCODE_ULTRA", BARCODE_ULTRA, 144 },
{ "BARCODE_RMQR", BARCODE_RMQR, 145 },
{ "BARCODE_BC412", BARCODE_BC412, 146 },
}; };
name[0] = '\0'; name[0] = '\0';
@ -1790,15 +1638,10 @@ int ZBarcode_BarcodeName(int symbol_id, char name[32]) {
if (!ZBarcode_ValidID(symbol_id)) { if (!ZBarcode_ValidID(symbol_id)) {
return 1; return 1;
} }
assert(symbol_id >= 0 && symbol_id < ARRAY_SIZE(data) && data[symbol_id].name[0]); assert(symbol_id >= 0 && symbol_id < ARRAY_SIZE(names) && names[symbol_id][0]);
/* Self-check, shouldn't happen */ memcpy(name, "BARCODE_", 8);
if (data[symbol_id].val != symbol_id || (data[symbol_id].define != -1 && data[symbol_id].define != symbol_id)) { strcpy(name + 8, names[symbol_id]);
assert(0); /* Not reached */
return -1;
}
strcpy(name, data[symbol_id].name);
return 0; return 0;
} }
@ -2210,11 +2053,11 @@ int ZBarcode_NoPng(void) {
/* Return the version of Zint linked to */ /* Return the version of Zint linked to */
int ZBarcode_Version(void) { int ZBarcode_Version(void) {
if (ZINT_VERSION_BUILD) { #if ZINT_VERSION_BUILD
return (ZINT_VERSION_MAJOR * 10000) + (ZINT_VERSION_MINOR * 100) + ZINT_VERSION_RELEASE * 10 return (ZINT_VERSION_MAJOR * 10000) + (ZINT_VERSION_MINOR * 100) + ZINT_VERSION_RELEASE * 10 + ZINT_VERSION_BUILD;
+ ZINT_VERSION_BUILD; #else
}
return (ZINT_VERSION_MAJOR * 10000) + (ZINT_VERSION_MINOR * 100) + ZINT_VERSION_RELEASE; return (ZINT_VERSION_MAJOR * 10000) + (ZINT_VERSION_MINOR * 100) + ZINT_VERSION_RELEASE;
#endif
} }
/* vim: set ts=4 sw=4 et : */ /* vim: set ts=4 sw=4 et : */

View File

@ -113,11 +113,13 @@ INTERNAL FILE *out_win_fopen(const char *filename, const char *mode);
bp[3] = (unsigned char) ((*p_u32 >> 24) & 0xFF); \ bp[3] = (unsigned char) ((*p_u32 >> 24) & 0xFF); \
} while (0) } while (0)
/* For more portability, use `#pragma pack()` pair for MSCV, per-type packed attribute otherwise */ /* If `#pragma pack()` not supported, try per-type packed attribute */
#ifdef _MSC_VER #ifdef __COMPCERT__
# define OUT_PACK /* Can't use `__attribute__` as may be defined to be no-op by libc if not GNU C or Clang (e.g. glibc does this) */
# define OUT_PACK __attribute((__packed__)) /* CompCert C workaround extension `__attribute` */
#else #else
# define OUT_PACK __attribute__((__packed__)) # define OUT_USE_PRAGMA_PACK
# define OUT_PACK
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,7 +1,7 @@
/* pcx.h - header structure for ZSoft PCX files */ /* pcx.h - header structure for ZSoft PCX files */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2016-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2016-2024 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
@ -37,7 +37,7 @@
extern "C" { extern "C" {
#endif #endif
#ifdef _MSC_VER #ifdef OUT_USE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
@ -62,7 +62,7 @@ extern "C" {
uint8_t filler[54]; uint8_t filler[54];
} OUT_PACK pcx_header_t; } OUT_PACK pcx_header_t;
#ifdef _MSC_VER #ifdef OUT_USE_PRAGMA_PACK
#pragma pack() #pragma pack()
#endif #endif

View File

@ -68,7 +68,7 @@ static const char pdf_smodes[] = { '?', 'A', 'L', 'M', 'P', 'B', 'N' };
/* Return (real) mode text */ /* Return (real) mode text */
static const char *pdf_mode_str(const int mode) { static const char *pdf_mode_str(const int mode) {
static const char *modes[3] = { "Text", "Byte", "Number" }; static const char modes[3][7] = { "Text", "Byte", "Number" };
return mode >= PDF_TEX && mode <= PDF_NUM ? modes[mode - PDF_TEX] : "ERROR"; return mode >= PDF_TEX && mode <= PDF_NUM ? modes[mode - PDF_TEX] : "ERROR";
} }

View File

@ -1,7 +1,7 @@
/* ps.c - Post Script output */ /* ps.c - Post Script output */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2023 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2024 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
@ -265,12 +265,11 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
/* Start writing the header */ /* Start writing the header */
fm_puts("%!PS-Adobe-3.0 EPSF-3.0\n" fm_puts("%!PS-Adobe-3.0 EPSF-3.0\n"
"%%Creator: Zint ", fmp); "%%Creator: Zint ", fmp);
if (ZINT_VERSION_BUILD) { #if ZINT_VERSION_BUILD
fm_printf(fmp, "%d.%d.%d.%d\n", fm_printf(fmp, "%d.%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD);
ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD); #else
} else { fm_printf(fmp, "%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE);
fm_printf(fmp, "%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE); #endif
}
fm_puts("%%Title: Zint Generated Symbol\n" fm_puts("%%Title: Zint Generated Symbol\n"
"%%Pages: 0\n" "%%Pages: 0\n"
"%%BoundingBox: 0 0 ", fmp); "%%BoundingBox: 0 0 ", fmp);

View File

@ -383,7 +383,7 @@ static int qr_cci_bits(const int version, const int mode) {
{ 5, 4, 4, 3, }, { 5, 4, 4, 3, },
{ 6, 5, 5, 4, } { 6, 5, 5, 4, }
}; };
static const unsigned char *rmqr_ccis[QR_NUM_MODES] = { static const unsigned char *const rmqr_ccis[QR_NUM_MODES] = {
rmqr_numeric_cci, rmqr_alphanum_cci, rmqr_byte_cci, rmqr_kanji_cci, rmqr_numeric_cci, rmqr_alphanum_cci, rmqr_byte_cci, rmqr_kanji_cci,
}; };
int mode_index = posn(qr_mode_types, (const char) mode); int mode_index = posn(qr_mode_types, (const char) mode);

View File

@ -257,7 +257,7 @@ static void test_options(const testCtx *const p_ctx) {
/* 15*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 508: Invalid character in data (digits only)" }, /* 15*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "A", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 508: Invalid character in data (digits only)" },
/* 16*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "256", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 509: Input out of range (0 to 255)" }, /* 16*/ { BARCODE_AZRUNE, -1, -1, -1, -1, { 0, 0, "" }, "256", ZINT_ERROR_INVALID_DATA, -1, -1, "Error 509: Input out of range (0 to 255)" },
/* 17*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 1, 2, "" }, "1234567890", 0, 15, 15, "" }, /* 17*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 1, 2, "" }, "1234567890", 0, 15, 15, "" },
/* 18*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 1, 2, "12345678901234567890123456789012" }, "1234567890", 0, 23, 23, "" }, /* 18*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 1, 2, {'1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2'} }, "1234567890", 0, 23, 23, "" },
/* 19*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 1, 1, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 701: Structured Append count out of range (2-26)" }, /* 19*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 1, 1, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 701: Structured Append count out of range (2-26)" },
/* 20*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 0, 2, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 702: Structured Append index out of range (1-2)" }, /* 20*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 0, 2, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 702: Structured Append index out of range (1-2)" },
/* 21*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 3, 2, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 702: Structured Append index out of range (1-2)" }, /* 21*/ { BARCODE_AZTEC, -1, -1, -1, -1, { 3, 2, "" }, "1234567890", ZINT_ERROR_INVALID_OPTION, -1, -1, "Error 702: Structured Append index out of range (1-2)" },

View File

@ -151,12 +151,12 @@ static void test_checks(const testCtx *const p_ctx) {
/* 87*/ { 88, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 252: Data does not start with an AI", BARCODE_GS1_128 }, /* 87*/ { 88, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 252: Data does not start with an AI", BARCODE_GS1_128 },
/* 88*/ { 88, -1, "[10]12", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_GS1_128 }, /* 88*/ { 88, -1, "[10]12", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_GS1_128 },
/* 89*/ { 88, -1, "[10]12", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_GS1_128 }, /* 89*/ { 88, -1, "[10]12", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_GS1_128 },
/* 90*/ { 91, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 212: Symbology out of range", BARCODE_CODE128 }, /* 90*/ { 91, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/* 91*/ { 91, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 212: Symbology out of range", -1 }, /* 91*/ { 91, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/* 92*/ { 94, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 213: Symbology out of range", BARCODE_CODE128 }, /* 92*/ { 94, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/* 93*/ { 94, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 213: Symbology out of range", -1 }, /* 93*/ { 94, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/* 94*/ { 95, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 213: Symbology out of range", BARCODE_CODE128 }, /* 94*/ { 95, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/* 95*/ { 95, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 213: Symbology out of range", -1 }, /* 95*/ { 95, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/* 96*/ { 100, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_128 }, /* 96*/ { 100, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_128 },
/* 97*/ { 100, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_128 }, /* 97*/ { 100, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_128 },
/* 98*/ { 101, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_39 }, /* 98*/ { 101, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_39 },
@ -171,30 +171,30 @@ static void test_checks(const testCtx *const p_ctx) {
/*107*/ { 109, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_MICPDF }, /*107*/ { 109, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_MICPDF },
/*108*/ { 111, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_BLOCKF }, /*108*/ { 111, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, 0, "", BARCODE_HIBC_BLOCKF },
/*109*/ { 111, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_BLOCKF }, /*109*/ { 111, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, 0, "", BARCODE_HIBC_BLOCKF },
/*110*/ { 113, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 214: Symbology out of range", BARCODE_CODE128 }, /*110*/ { 113, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*111*/ { 113, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 214: Symbology out of range", -1 }, /*111*/ { 113, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*112*/ { 114, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 214: Symbology out of range", BARCODE_CODE128 }, /*112*/ { 114, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*113*/ { 114, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 214: Symbology out of range", -1 }, /*113*/ { 114, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*114*/ { 117, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 215: Symbology out of range", BARCODE_CODE128 }, /*114*/ { 117, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*115*/ { 117, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 215: Symbology out of range", -1 }, /*115*/ { 117, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*116*/ { 118, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 215: Symbology out of range", BARCODE_CODE128 }, /*116*/ { 118, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*117*/ { 118, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 215: Symbology out of range", -1 }, /*117*/ { 118, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*118*/ { 122, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 215: Symbology out of range", BARCODE_CODE128 }, /*118*/ { 122, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*119*/ { 122, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 215: Symbology out of range", -1 }, /*119*/ { 122, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*120*/ { 123, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 215: Symbology out of range", BARCODE_CODE128 }, /*120*/ { 123, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*121*/ { 123, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 215: Symbology out of range", -1 }, /*121*/ { 123, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*122*/ { 124, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 215: Symbology out of range", BARCODE_CODE128 }, /*122*/ { 124, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*123*/ { 124, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 215: Symbology out of range", -1 }, /*123*/ { 124, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*124*/ { 125, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 215: Symbology out of range", BARCODE_CODE128 }, /*124*/ { 125, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*125*/ { 125, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 215: Symbology out of range", -1 }, /*125*/ { 125, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*126*/ { 126, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 215: Symbology out of range", BARCODE_CODE128 }, /*126*/ { 126, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*127*/ { 126, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 215: Symbology out of range", -1 }, /*127*/ { 126, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*128*/ { 127, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 215: Symbology out of range", BARCODE_CODE128 }, /*128*/ { 127, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*129*/ { 127, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 215: Symbology out of range", -1 }, /*129*/ { 127, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*130*/ { 147, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 216: Symbology out of range", BARCODE_CODE128 }, /*130*/ { 147, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*131*/ { 147, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 216: Symbology out of range", -1 }, /*131*/ { 147, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*132*/ { BARCODE_LAST + 1, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 216: Symbology out of range", BARCODE_CODE128 }, /*132*/ { BARCODE_LAST + 1, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_INVALID_OPTION, "Warning 206: Symbology out of range", BARCODE_CODE128 },
/*133*/ { BARCODE_LAST + 1, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 216: Symbology out of range", -1 }, /*133*/ { BARCODE_LAST + 1, -1, "1", -1, -1, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_INVALID_OPTION, "Error 206: Symbology out of range", -1 },
/*134*/ { BARCODE_CODE128, -1, "\200", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8 in input data", -1 }, /*134*/ { BARCODE_CODE128, -1, "\200", -1, UNICODE_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_ERROR_INVALID_DATA, "Error 245: Invalid UTF-8 in input data", -1 },
/*135*/ { BARCODE_GS1_128, -1, "[01]12345678901234", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_NONCOMPLIANT, "Warning 261: AI (01) position 14: Bad checksum '4', expected '1'", -1 }, /*135*/ { BARCODE_GS1_128, -1, "[01]12345678901234", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, -1, ZINT_WARN_NONCOMPLIANT, "Warning 261: AI (01) position 14: Bad checksum '4', expected '1'", -1 },
/*136*/ { BARCODE_GS1_128, -1, "[01]12345678901234", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_NONCOMPLIANT, "Error 261: AI (01) position 14: Bad checksum '4', expected '1'", -1 }, /*136*/ { BARCODE_GS1_128, -1, "[01]12345678901234", -1, GS1_MODE, -1, 0, 0, 0, 0, -1, -1, 0, -1, WARN_FAIL_ALL, ZINT_ERROR_NONCOMPLIANT, "Error 261: AI (01) position 14: Bad checksum '4', expected '1'", -1 },
@ -394,6 +394,95 @@ static void test_input_data(const testCtx *const p_ctx) {
testFinish(); testFinish();
} }
static int test_prev_map_invalid_symbology(int *p_symbology) {
int symbology = *p_symbology;
int warn_number = 0;
if (symbology < 1) {
warn_number = ZINT_WARN_INVALID_OPTION;
symbology = BARCODE_CODE128;
/* symbol->symbologys 1 to 126 are defined by tbarcode */
} else if (symbology == 5) {
symbology = BARCODE_C25STANDARD;
} else if ((symbology >= 10) && (symbology <= 12)) {
symbology = BARCODE_EANX;
} else if (symbology == 15) {
symbology = BARCODE_EANX;
} else if (symbology == 17) {
symbology = BARCODE_UPCA;
} else if (symbology == 19) {
warn_number = ZINT_WARN_INVALID_OPTION;
symbology = BARCODE_CODABAR;
} else if (symbology == 26) { /* UPC-A up to tbarcode 9, ISSN for tbarcode 10+ */
symbology = BARCODE_UPCA;
} else if (symbology == 27) { /* UPCD1 up to tbarcode 9, ISSN + 2 digit add-on for tbarcode 10+ */
return ZINT_ERROR_INVALID_OPTION;
} else if (symbology == 33) {
symbology = BARCODE_GS1_128;
} else if (symbology == 36) {
symbology = BARCODE_UPCA;
} else if (symbology == 39) {
symbology = BARCODE_UPCE;
} else if ((symbology >= 41) && (symbology <= 45)) {
symbology = BARCODE_POSTNET;
} else if (symbology == 46) {
symbology = BARCODE_PLESSEY;
} else if (symbology == 48) {
symbology = BARCODE_NVE18;
} else if ((symbology == 59) || (symbology == 61)) {
symbology = BARCODE_CODE128;
} else if (symbology == 62) {
symbology = BARCODE_CODE93;
} else if ((symbology == 64) || (symbology == 65)) {
symbology = BARCODE_AUSPOST;
} else if (symbology == 78) {
symbology = BARCODE_DBAR_OMN;
} else if (symbology == 83) {
symbology = BARCODE_PLANET;
} else if (symbology == 88) {
symbology = BARCODE_GS1_128;
} else if (symbology == 91) { /* BC412 up to tbarcode 9, Code 32 for tbarcode 10+ */
warn_number = ZINT_WARN_INVALID_OPTION;
symbology = BARCODE_CODE128;
} else if ((symbology >= 94) && (symbology <= 95)) {
warn_number = ZINT_WARN_INVALID_OPTION;
symbology = BARCODE_CODE128;
} else if (symbology == 100) {
symbology = BARCODE_HIBC_128;
} else if (symbology == 101) {
symbology = BARCODE_HIBC_39;
} else if (symbology == 103) {
symbology = BARCODE_HIBC_DM;
} else if (symbology == 105) {
symbology = BARCODE_HIBC_QR;
} else if (symbology == 107) {
symbology = BARCODE_HIBC_PDF;
} else if (symbology == 109) {
symbology = BARCODE_HIBC_MICPDF;
} else if (symbology == 111) {
symbology = BARCODE_HIBC_BLOCKF;
} else if ((symbology == 113) || (symbology == 114)) {
warn_number = ZINT_WARN_INVALID_OPTION;
symbology = BARCODE_CODE128;
} else if ((symbology >= 117) && (symbology <= 127)) {
if (symbology < 119 || symbology > 121) { /* BARCODE_MAILMARK_2D/4S/UPU_S10 */
warn_number = ZINT_WARN_INVALID_OPTION;
symbology = BARCODE_CODE128;
}
/* Everything from 128 up is Zint-specific */
} else if (symbology > BARCODE_LAST) {
warn_number = ZINT_WARN_INVALID_OPTION;
symbology = BARCODE_CODE128;
}
if (symbology == *p_symbology) { /* Should never happen */
return ZINT_ERROR_ENCODING_PROBLEM;
}
*p_symbology = symbology;
return warn_number;
}
static void test_symbologies(const testCtx *const p_ctx) { static void test_symbologies(const testCtx *const p_ctx) {
int i, ret; int i, ret;
struct zint_symbol symbol = {0}; struct zint_symbol symbol = {0};
@ -404,8 +493,21 @@ static void test_symbologies(const testCtx *const p_ctx) {
if (testContinue(p_ctx, i)) continue; if (testContinue(p_ctx, i)) continue;
symbol.symbology = i; symbol.symbology = i;
ret = ZBarcode_Encode(&symbol, TU("1"), 0); ret = ZBarcode_Encode(&symbol, TU(""), 0);
assert_notequal(ret, ZINT_ERROR_ENCODING_PROBLEM, "i:%d Encoding problem (%s)\n", i, symbol.errtxt); assert_notequal(ret, ZINT_ERROR_ENCODING_PROBLEM, "i:%d Encoding problem (%s)\n", i, symbol.errtxt);
if (!ZBarcode_ValidID(i)) {
int prev_symbology = i;
int prev_ret = test_prev_map_invalid_symbology(&prev_symbology);
if (ret != ZINT_ERROR_INVALID_DATA) {
assert_equal(prev_ret, ret, "i:%d prev_ret (%d) != ret (%d)\n", i, prev_ret, ret);
}
assert_equal(prev_symbology, symbol.symbology, "i:%d prev_symbology (%d) != symbol.symbology (%d)\n",
i, prev_symbology, symbol.symbology);
} else {
/* No input data */
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "i:%d ret (%d) != ZINT_ERROR_INVALID_DATA\n", i, ret);
}
} }
testFinish(); testFinish();
@ -420,20 +522,21 @@ static void test_input_mode(const testCtx *const p_ctx) {
int ret; int ret;
int expected_input_mode; int expected_input_mode;
char *expected_errtxt;
}; };
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */ /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "1234", DATA_MODE, 0, DATA_MODE }, /* 0*/ { "1234", DATA_MODE, 0, DATA_MODE, "" },
/* 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]12345678901231", GS1_MODE, 0, GS1_MODE }, /* 4*/ { "[01]12345678901231", GS1_MODE, 0, GS1_MODE, "" },
/* 5*/ { "[01]12345678901231", 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, ZINT_WARN_INVALID_OPTION, DATA_MODE, "Warning 212: Invalid input mode - reset to DATA_MODE" }, /* Unknown mode reset to bare DATA_MODE. Note: now warns */
/* 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) */
/* 9*/ { "1234", UNICODE_MODE | 0x10, 0, UNICODE_MODE | 0x10 }, /* 9*/ { "1234", UNICODE_MODE | 0x10, 0, UNICODE_MODE | 0x10, "" },
/* 10*/ { "[01]12345678901231", GS1_MODE | 0x20, 0, GS1_MODE | 0x20 }, /* 10*/ { "[01]12345678901231", GS1_MODE | 0x20, 0, GS1_MODE | 0x20, "" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;
@ -453,6 +556,7 @@ static void test_input_mode(const testCtx *const p_ctx) {
ret = ZBarcode_Encode(symbol, TU(data[i].data), length); ret = ZBarcode_Encode(symbol, TU(data[i].data), length);
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt); assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
assert_equal(symbol->input_mode, data[i].expected_input_mode, "i:%d symbol->input_mode %d != %d\n", i, symbol->input_mode, data[i].expected_input_mode); assert_equal(symbol->input_mode, data[i].expected_input_mode, "i:%d symbol->input_mode %d != %d\n", i, symbol->input_mode, data[i].expected_input_mode);
assert_zero(strcmp(symbol->errtxt, data[i].expected_errtxt), "i:%d ZBarcode_Encode strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected_errtxt);
ZBarcode_Delete(symbol); ZBarcode_Delete(symbol);
} }
@ -725,7 +829,7 @@ static void test_cap(const testCtx *const p_ctx) {
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i; int i;
unsigned int ret; unsigned int uret;
testStart("test_cap"); testStart("test_cap");
@ -733,8 +837,8 @@ static void test_cap(const testCtx *const p_ctx) {
if (testContinue(p_ctx, i)) continue; if (testContinue(p_ctx, i)) continue;
ret = ZBarcode_Cap(data[i].symbology, data[i].cap_flag); uret = ZBarcode_Cap(data[i].symbology, data[i].cap_flag);
assert_equal(ret, data[i].expected, "i:%d ZBarcode_Cap(%s, 0x%X) 0x%X != 0x%X\n", i, testUtilBarcodeName(data[i].symbology), data[i].cap_flag, ret, data[i].expected); assert_equal(uret, data[i].expected, "i:%d ZBarcode_Cap(%s, 0x%X) 0x%X != 0x%X\n", i, testUtilBarcodeName(data[i].symbology), data[i].cap_flag, uret, data[i].expected);
} }
testFinish(); testFinish();
@ -742,7 +846,7 @@ static void test_cap(const testCtx *const p_ctx) {
static void test_cap_compliant_height(const testCtx *const p_ctx) { static void test_cap_compliant_height(const testCtx *const p_ctx) {
int symbol_id; int symbol_id;
int ret; unsigned int uret;
testStart("test_cap_compliant_height"); testStart("test_cap_compliant_height");
@ -750,7 +854,7 @@ static void test_cap_compliant_height(const testCtx *const p_ctx) {
if (!ZBarcode_ValidID(symbol_id)) continue; if (!ZBarcode_ValidID(symbol_id)) continue;
if (testContinue(p_ctx, symbol_id)) continue; if (testContinue(p_ctx, symbol_id)) continue;
ret = ZBarcode_Cap(symbol_id, ZINT_CAP_COMPLIANT_HEIGHT); uret = ZBarcode_Cap(symbol_id, ZINT_CAP_COMPLIANT_HEIGHT);
switch (symbol_id) { switch (symbol_id) {
/*case BARCODE_CODE11: TODO: Find doc */ /*case BARCODE_CODE11: TODO: Find doc */
@ -822,10 +926,10 @@ static void test_cap_compliant_height(const testCtx *const p_ctx) {
case BARCODE_DBAR_EXPSTK_CC: case BARCODE_DBAR_EXPSTK_CC:
case BARCODE_CHANNEL: case BARCODE_CHANNEL:
case BARCODE_BC412: case BARCODE_BC412:
assert_equal(ret, ZINT_CAP_COMPLIANT_HEIGHT, "symbol_id %d (%s) ret 0x%X != ZINT_CAP_COMPLIANT_HEIGHT\n", symbol_id, testUtilBarcodeName(symbol_id), ret); assert_equal(uret, ZINT_CAP_COMPLIANT_HEIGHT, "symbol_id %d (%s) uret 0x%X != ZINT_CAP_COMPLIANT_HEIGHT\n", symbol_id, testUtilBarcodeName(symbol_id), uret);
break; break;
default: default:
assert_zero(ret, "symbol_id %d (%s) ret 0x%X non-zero\n", symbol_id, testUtilBarcodeName(symbol_id), ret); assert_zero(uret, "symbol_id %d (%s) uret 0x%X non-zero\n", symbol_id, testUtilBarcodeName(symbol_id), uret);
break; break;
} }
} }
@ -849,7 +953,7 @@ static void test_encode_file_empty(const testCtx *const p_ctx) {
(void) testUtilRemove(filename); /* In case junk hanging around */ (void) testUtilRemove(filename); /* In case junk hanging around */
fstream = testUtilOpen(filename, "w+"); fstream = testUtilOpen(filename, "w+");
assert_nonnull(fstream, "testUtilOpen(%s) failed (%d)\n", filename, ferror(fstream)); assert_nonnull(fstream, "testUtilOpen(%s) failed (%d)\n", filename, errno);
ret = fclose(fstream); ret = fclose(fstream);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret); assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
@ -881,7 +985,7 @@ static void test_encode_file_too_large(const testCtx *const p_ctx) {
(void) testUtilRemove(filename); /* In case junk hanging around */ (void) testUtilRemove(filename); /* In case junk hanging around */
fstream = testUtilOpen(filename, "w+"); fstream = testUtilOpen(filename, "w+");
assert_nonnull(fstream, "testUtilOpen(%s) failed (%d)\n", filename, ferror(fstream)); assert_nonnull(fstream, "testUtilOpen(%s) failed (%d)\n", filename, errno);
ret = (int) fwrite(buf, 1, sizeof(buf), fstream); ret = (int) fwrite(buf, 1, sizeof(buf), fstream);
assert_equal(ret, sizeof(buf), "fwrite return value: %d != %d\n", ret, (int)sizeof(buf)); assert_equal(ret, sizeof(buf), "fwrite return value: %d != %d\n", ret, (int)sizeof(buf));
ret = fclose(fstream); ret = fclose(fstream);
@ -994,7 +1098,7 @@ static void test_encode_file(const testCtx *const p_ctx) {
(void) testUtilRemove(outfile); /* In case junk hanging around */ (void) testUtilRemove(outfile); /* In case junk hanging around */
fp = testUtilOpen(filename, "w+"); fp = testUtilOpen(filename, "w+");
assert_nonnull(fp, "testUtilOpen(%s) failed (%d)\n", filename, ferror(fp)); assert_nonnull(fp, "testUtilOpen(%s) failed (%d)\n", filename, errno);
assert_notequal(fputs(data, fp), EOF, "fputs(%s) failed == EOF (%d)\n", data, ferror(fp)); assert_notequal(fputs(data, fp), EOF, "fputs(%s) failed == EOF (%d)\n", data, ferror(fp));
ret = fclose(fp); ret = fclose(fp);
assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret); assert_zero(ret, "fclose(%s) %d != 0\n", filename, ret);
@ -1073,6 +1177,7 @@ static void test_encode_print_outfile_directory(const testCtx *const p_ctx) {
static void test_bad_args(const testCtx *const p_ctx) { static void test_bad_args(const testCtx *const p_ctx) {
int ret; int ret;
unsigned int uret;
struct zint_symbol *symbol; struct zint_symbol *symbol;
char *data = "1"; char *data = "1";
char *filename = "1.png"; char *filename = "1.png";
@ -1096,10 +1201,10 @@ static void test_bad_args(const testCtx *const p_ctx) {
assert_zero(ZBarcode_ValidID(0), "ZBarcode_ValidID(0) non-zero\n"); assert_zero(ZBarcode_ValidID(0), "ZBarcode_ValidID(0) non-zero\n");
assert_zero(ZBarcode_ValidID(10), "ZBarcode_ValidID(10) non-zero\n"); /* Note 10 remapped to BARCODE_EANX in ZBarcode_Encode() for tbarcode compat but not counted as valid */ assert_zero(ZBarcode_ValidID(10), "ZBarcode_ValidID(10) non-zero\n"); /* Note 10 remapped to BARCODE_EANX in ZBarcode_Encode() for tbarcode compat but not counted as valid */
ret = ZBarcode_Cap(0, ~0); uret = ZBarcode_Cap(0, ~0);
assert_zero(ret, "ZBarcode_Cap(0, ~0) ret 0x%X != 0\n", ret); assert_zero(uret, "ZBarcode_Cap(0, ~0) uret 0x%X != 0\n", uret);
ret = ZBarcode_Cap(10, ~0); uret = ZBarcode_Cap(10, ~0);
assert_zero(ret, "ZBarcode_Cap(10, ~0) ret 0x%X != 0\n", ret); assert_zero(uret, "ZBarcode_Cap(10, ~0) uret 0x%X != 0\n", uret);
/* NULL symbol */ /* NULL symbol */
assert_equal(ZBarcode_Encode(NULL, TU(data), 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode(NULL, data, 1) != ZINT_ERROR_INVALID_DATA\n"); assert_equal(ZBarcode_Encode(NULL, TU(data), 1), ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode(NULL, data, 1) != ZINT_ERROR_INVALID_DATA\n");
@ -1240,6 +1345,210 @@ static void test_valid_id(const testCtx *const p_ctx) {
testFinish(); testFinish();
} }
static int test_prev_ZBarcode_BarcodeName(int symbol_id, char name[32]) {
struct item {
const char *name;
int define;
int val;
};
static const struct item data[] = {
{ "", -1, 0 },
{ "BARCODE_CODE11", BARCODE_CODE11, 1 },
{ "BARCODE_C25STANDARD", BARCODE_C25STANDARD, 2 },
{ "BARCODE_C25INTER", BARCODE_C25INTER, 3 },
{ "BARCODE_C25IATA", BARCODE_C25IATA, 4 },
{ "", -1, 5 },
{ "BARCODE_C25LOGIC", BARCODE_C25LOGIC, 6 },
{ "BARCODE_C25IND", BARCODE_C25IND, 7 },
{ "BARCODE_CODE39", BARCODE_CODE39, 8 },
{ "BARCODE_EXCODE39", BARCODE_EXCODE39, 9 },
{ "", -1, 10 },
{ "", -1, 11 },
{ "", -1, 12 },
{ "BARCODE_EANX", BARCODE_EANX, 13 },
{ "BARCODE_EANX_CHK", BARCODE_EANX_CHK, 14 },
{ "", -1, 15 },
{ "BARCODE_GS1_128", BARCODE_GS1_128, 16 },
{ "", -1, 17 },
{ "BARCODE_CODABAR", BARCODE_CODABAR, 18 },
{ "", -1, 19 },
{ "BARCODE_CODE128", BARCODE_CODE128, 20 },
{ "BARCODE_DPLEIT", BARCODE_DPLEIT, 21 },
{ "BARCODE_DPIDENT", BARCODE_DPIDENT, 22 },
{ "BARCODE_CODE16K", BARCODE_CODE16K, 23 },
{ "BARCODE_CODE49", BARCODE_CODE49, 24 },
{ "BARCODE_CODE93", BARCODE_CODE93, 25 },
{ "", -1, 26 },
{ "", -1, 27 },
{ "BARCODE_FLAT", BARCODE_FLAT, 28 },
{ "BARCODE_DBAR_OMN", BARCODE_DBAR_OMN, 29 },
{ "BARCODE_DBAR_LTD", BARCODE_DBAR_LTD, 30 },
{ "BARCODE_DBAR_EXP", BARCODE_DBAR_EXP, 31 },
{ "BARCODE_TELEPEN", BARCODE_TELEPEN, 32 },
{ "", -1, 33 },
{ "BARCODE_UPCA", BARCODE_UPCA, 34 },
{ "BARCODE_UPCA_CHK", BARCODE_UPCA_CHK, 35 },
{ "", -1, 36 },
{ "BARCODE_UPCE", BARCODE_UPCE, 37 },
{ "BARCODE_UPCE_CHK", BARCODE_UPCE_CHK, 38 },
{ "", -1, 39 },
{ "BARCODE_POSTNET", BARCODE_POSTNET, 40 },
{ "", -1, 41 },
{ "", -1, 42 },
{ "", -1, 43 },
{ "", -1, 44 },
{ "", -1, 45 },
{ "", -1, 46 },
{ "BARCODE_MSI_PLESSEY", BARCODE_MSI_PLESSEY, 47 },
{ "", -1, 48 },
{ "BARCODE_FIM", BARCODE_FIM, 49 },
{ "BARCODE_LOGMARS", BARCODE_LOGMARS, 50 },
{ "BARCODE_PHARMA", BARCODE_PHARMA, 51 },
{ "BARCODE_PZN", BARCODE_PZN, 52 },
{ "BARCODE_PHARMA_TWO", BARCODE_PHARMA_TWO, 53 },
{ "BARCODE_CEPNET", BARCODE_CEPNET, 54 },
{ "BARCODE_PDF417", BARCODE_PDF417, 55 },
{ "BARCODE_PDF417COMP", BARCODE_PDF417COMP, 56 },
{ "BARCODE_MAXICODE", BARCODE_MAXICODE, 57 },
{ "BARCODE_QRCODE", BARCODE_QRCODE, 58 },
{ "", -1, 59 },
{ "BARCODE_CODE128AB", BARCODE_CODE128AB, 60 },
{ "", -1, 61 },
{ "", -1, 62 },
{ "BARCODE_AUSPOST", BARCODE_AUSPOST, 63 },
{ "", -1, 64 },
{ "", -1, 65 },
{ "BARCODE_AUSREPLY", BARCODE_AUSREPLY, 66 },
{ "BARCODE_AUSROUTE", BARCODE_AUSROUTE, 67 },
{ "BARCODE_AUSREDIRECT", BARCODE_AUSREDIRECT, 68 },
{ "BARCODE_ISBNX", BARCODE_ISBNX, 69 },
{ "BARCODE_RM4SCC", BARCODE_RM4SCC, 70 },
{ "BARCODE_DATAMATRIX", BARCODE_DATAMATRIX, 71 },
{ "BARCODE_EAN14", BARCODE_EAN14, 72 },
{ "BARCODE_VIN", BARCODE_VIN, 73 },
{ "BARCODE_CODABLOCKF", BARCODE_CODABLOCKF, 74 },
{ "BARCODE_NVE18", BARCODE_NVE18, 75 },
{ "BARCODE_JAPANPOST", BARCODE_JAPANPOST, 76 },
{ "BARCODE_KOREAPOST", BARCODE_KOREAPOST, 77 },
{ "", -1, 78 },
{ "BARCODE_DBAR_STK", BARCODE_DBAR_STK, 79 },
{ "BARCODE_DBAR_OMNSTK", BARCODE_DBAR_OMNSTK, 80 },
{ "BARCODE_DBAR_EXPSTK", BARCODE_DBAR_EXPSTK, 81 },
{ "BARCODE_PLANET", BARCODE_PLANET, 82 },
{ "", -1, 83 },
{ "BARCODE_MICROPDF417", BARCODE_MICROPDF417, 84 },
{ "BARCODE_USPS_IMAIL", BARCODE_USPS_IMAIL, 85 },
{ "BARCODE_PLESSEY", BARCODE_PLESSEY, 86 },
{ "BARCODE_TELEPEN_NUM", BARCODE_TELEPEN_NUM, 87 },
{ "", -1, 88 },
{ "BARCODE_ITF14", BARCODE_ITF14, 89 },
{ "BARCODE_KIX", BARCODE_KIX, 90 },
{ "", -1, 91 },
{ "BARCODE_AZTEC", BARCODE_AZTEC, 92 },
{ "BARCODE_DAFT", BARCODE_DAFT, 93 },
{ "", -1, 94 },
{ "", -1, 95 },
{ "BARCODE_DPD", BARCODE_DPD, 96 },
{ "BARCODE_MICROQR", BARCODE_MICROQR, 97 },
{ "BARCODE_HIBC_128", BARCODE_HIBC_128, 98 },
{ "BARCODE_HIBC_39", BARCODE_HIBC_39, 99 },
{ "", -1, 100 },
{ "", -1, 101 },
{ "BARCODE_HIBC_DM", BARCODE_HIBC_DM, 102 },
{ "", -1, 103 },
{ "BARCODE_HIBC_QR", BARCODE_HIBC_QR, 104 },
{ "", -1, 105 },
{ "BARCODE_HIBC_PDF", BARCODE_HIBC_PDF, 106 },
{ "", -1, 107 },
{ "BARCODE_HIBC_MICPDF", BARCODE_HIBC_MICPDF, 108 },
{ "", -1, 109 },
{ "BARCODE_HIBC_BLOCKF", BARCODE_HIBC_BLOCKF, 110 },
{ "", -1, 111 },
{ "BARCODE_HIBC_AZTEC", BARCODE_HIBC_AZTEC, 112 },
{ "", -1, 113 },
{ "", -1, 114 },
{ "BARCODE_DOTCODE", BARCODE_DOTCODE, 115 },
{ "BARCODE_HANXIN", BARCODE_HANXIN, 116 },
{ "", -1, 117 },
{ "", -1, 118 },
{ "BARCODE_MAILMARK_2D", BARCODE_MAILMARK_2D, 119 },
{ "BARCODE_UPU_S10", BARCODE_UPU_S10, 120 },
{ "BARCODE_MAILMARK_4S", BARCODE_MAILMARK_4S, 121 },
{ "", -1, 122 },
{ "", -1, 123 },
{ "", -1, 124 },
{ "", -1, 125 },
{ "", -1, 126 },
{ "", -1, 127 },
{ "BARCODE_AZRUNE", BARCODE_AZRUNE, 128 },
{ "BARCODE_CODE32", BARCODE_CODE32, 129 },
{ "BARCODE_EANX_CC", BARCODE_EANX_CC, 130 },
{ "BARCODE_GS1_128_CC", BARCODE_GS1_128_CC, 131 },
{ "BARCODE_DBAR_OMN_CC", BARCODE_DBAR_OMN_CC, 132 },
{ "BARCODE_DBAR_LTD_CC", BARCODE_DBAR_LTD_CC, 133 },
{ "BARCODE_DBAR_EXP_CC", BARCODE_DBAR_EXP_CC, 134 },
{ "BARCODE_UPCA_CC", BARCODE_UPCA_CC, 135 },
{ "BARCODE_UPCE_CC", BARCODE_UPCE_CC, 136 },
{ "BARCODE_DBAR_STK_CC", BARCODE_DBAR_STK_CC, 137 },
{ "BARCODE_DBAR_OMNSTK_CC", BARCODE_DBAR_OMNSTK_CC, 138 },
{ "BARCODE_DBAR_EXPSTK_CC", BARCODE_DBAR_EXPSTK_CC, 139 },
{ "BARCODE_CHANNEL", BARCODE_CHANNEL, 140 },
{ "BARCODE_CODEONE", BARCODE_CODEONE, 141 },
{ "BARCODE_GRIDMATRIX", BARCODE_GRIDMATRIX, 142 },
{ "BARCODE_UPNQR", BARCODE_UPNQR, 143 },
{ "BARCODE_ULTRA", BARCODE_ULTRA, 144 },
{ "BARCODE_RMQR", BARCODE_RMQR, 145 },
{ "BARCODE_BC412", BARCODE_BC412, 146 },
};
name[0] = '\0';
if (!ZBarcode_ValidID(symbol_id)) {
return 1;
}
if (!(symbol_id >= 0 && symbol_id < ARRAY_SIZE(data) && data[symbol_id].name[0])) {
return -1; /* Shouldn't happen */
}
/* Self-check, shouldn't happen */
if (data[symbol_id].val != symbol_id || (data[symbol_id].define != -1 && data[symbol_id].define != symbol_id)) {
return -1;
}
strcpy(name, data[symbol_id].name);
return 0;
}
static void test_barcode_name(const testCtx *const p_ctx) {
int ret;
char name[32];
int symbol_id;
(void)p_ctx;
testStart("test_barcode_name");
for (symbol_id = -1; symbol_id < 160; symbol_id++) {
int prev_ret;
char prev_name[32];
ret = ZBarcode_BarcodeName(symbol_id, name);
if (ZBarcode_ValidID(symbol_id)) {
assert_equal(ret, 0, "ZBarcode_BarcodeName(%d) != 0\n", symbol_id);
assert_nonzero(*name != '\0', "ZBarcode_BarcodeName(%d) empty when ZBarcode_Valid() true\n", symbol_id);
} else {
assert_equal(ret, 1, "ZBarcode_BarcodeName(%d) != 1\n", symbol_id);
assert_zero(*name, "ZBarcode_BarcodeName(%d) non-empty when ZBarcode_Valid() false\n", symbol_id);
}
prev_ret = test_prev_ZBarcode_BarcodeName(symbol_id, prev_name);
assert_equal(ret, prev_ret, "ZBarcode_BarcodeName(%d) ret %d != prev_ret %d\n", symbol_id, ret, prev_ret);
assert_zero(strcmp(name, prev_name), "ZBarcode_BarcodeName(%d) strcmp(%s, %s) != 0\n", symbol_id, name, prev_name);
}
testFinish();
}
INTERNAL int error_tag_test(struct zint_symbol *symbol, int error_number, const char *error_string); INTERNAL int error_tag_test(struct zint_symbol *symbol, int error_number, const char *error_string);
static void test_error_tag(const testCtx *const p_ctx) { static void test_error_tag(const testCtx *const p_ctx) {
@ -1826,6 +2135,7 @@ int main(int argc, char *argv[]) {
{ "test_encode_print_outfile_directory", test_encode_print_outfile_directory }, { "test_encode_print_outfile_directory", test_encode_print_outfile_directory },
{ "test_bad_args", test_bad_args }, { "test_bad_args", test_bad_args },
{ "test_valid_id", test_valid_id }, { "test_valid_id", test_valid_id },
{ "test_barcode_name", test_barcode_name },
{ "test_error_tag", test_error_tag }, { "test_error_tag", test_error_tag },
{ "test_strip_bom", test_strip_bom }, { "test_strip_bom", test_strip_bom },
{ "test_zero_outfile", test_zero_outfile }, { "test_zero_outfile", test_zero_outfile },

View File

@ -1,6 +1,6 @@
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2019-2023 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2019-2024 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
@ -406,21 +406,21 @@ static void test_qr_input(const testCtx *const p_ctx) {
/*126*/ { UNICODE_MODE, 16384, 4, 8 << 8, "é", 0, 16384, "7C 04 00 04 02 C3 A9 00 EC", 1, 1, "ECI-16384 B2 (no conversion)" }, /*126*/ { UNICODE_MODE, 16384, 4, 8 << 8, "é", 0, 16384, "7C 04 00 04 02 C3 A9 00 EC", 1, 1, "ECI-16384 B2 (no conversion)" },
/*127*/ { UNICODE_MODE, 3, 4, -1, "product:Google Pixel 4a - 128 GB of Storage - Black;price:$439.97", 0, 3, "(86) 70 34 39 70 72 6F 64 75 63 74 3A 47 6F 6F 67 6C 65 20 50 69 78 65 6C 20 34 61 20 2D", 0, 1, "ECI-3 B57 A8; BWIPP different encodation (B65)" }, /*127*/ { UNICODE_MODE, 3, 4, -1, "product:Google Pixel 4a - 128 GB of Storage - Black;price:$439.97", 0, 3, "(86) 70 34 39 70 72 6F 64 75 63 74 3A 47 6F 6F 67 6C 65 20 50 69 78 65 6C 20 34 61 20 2D", 0, 1, "ECI-3 B57 A8; BWIPP different encodation (B65)" },
/*128*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\176", 0, 0, "80 10 1F 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x817E)" }, /*128*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\176", 0, 0, "80 10 1F 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x817E)" },
/*129*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\177", 0, 0, "40 28 17 F0 EC 11 EC 11 EC", 0, 1, "B2 (0x817F previously used Kanji mode, now excludes trailing 0x7F); BWIPP TODO: exclude also" }, /*129*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\177", 0, 0, "40 28 17 F0 EC 11 EC 11 EC", 1, 1, "B2 (0x817F previously used Kanji mode, now excludes trailing 0x7F)" },
/*130*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\200", 0, 0, "80 10 20 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x8180)" }, /*130*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\200", 0, 0, "80 10 20 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x8180)" },
/*131*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\237\176", 0, 0, "80 1B 5F 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x9F7E)" }, /*131*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\237\176", 0, 0, "80 1B 5F 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x9F7E)" },
/*132*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\237\177", 0, 0, "40 29 F7 F0 EC 11 EC 11 EC", 0, 1, "B2 (0x9F7F previously used Kanji mode, now excludes trailing 0x7F); BWIPP TODO: exclude also" }, /*132*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (1 << 8), "\237\177", 0, 0, "40 29 F7 F0 EC 11 EC 11 EC", 1, 1, "B2 (0x9F7F previously used Kanji mode, now excludes trailing 0x7F)" },
/*133*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (5 << 8), "\340\176", 0, 0, "80 1B BF 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0xE07E)" }, /*133*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (5 << 8), "\340\176", 0, 0, "80 1B BF 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0xE07E)" },
/*134*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\340\177", 0, 0, "40 2E 07 F0 EC 11 EC 11 EC", 0, 1, "B2 (0xE07F previously used Kanji mode, now excludes trailing 0x7F); BWIPP TODO: exclude also" }, /*134*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\340\177", 0, 0, "40 2E 07 F0 EC 11 EC 11 EC", 1, 1, "B2 (0xE07F previously used Kanji mode, now excludes trailing 0x7F)" },
/*135*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (4 << 8), "\352\244", 0, 0, "80 1F 92 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0xEAA4, last valid codepoint)" }, /*135*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (4 << 8), "\352\244", 0, 0, "80 1F 92 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0xEAA4, last valid codepoint)" },
/*136*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\353\277", 0, 0, "80 1F FF 80 EC 11 EC 11 EC", 0, 1, "K1 (0xEBBF undefined in Shift JIS but not checked and uses Kanji mode); BWIPP TODO: exclude also" }, /*136*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (6 << 8), "\353\277", 0, 0, "80 1F FF 80 EC 11 EC 11 EC", 1, 1, "K1 (0xEBBF undefined in Shift JIS but not checked and uses Kanji mode)" },
/*137*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\353\300", 0, 0, "40 2E BC 00 EC 11 EC 11 EC", 1, 1, "B2 (0xEBC0 was always excluded)" }, /*137*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\353\300", 0, 0, "40 2E BC 00 EC 11 EC 11 EC", 1, 1, "B2 (0xEBC0 was always excluded)" },
/*138*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\300", 0, 0, "80 10 40 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x81C0)" }, /*138*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\300", 0, 0, "80 10 40 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x81C0)" },
/*139*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (2 << 8), "\201\374", 0, 0, "80 10 5E 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x81FC)" }, /*139*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (2 << 8), "\201\374", 0, 0, "80 10 5E 00 EC 11 EC 11 EC", 1, 1, "K1 (Shift JIS 0x81FC)" },
/*140*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\375", 0, 0, "40 28 1F D0 EC 11 EC 11 EC", 0, 1, "B2 (0x81FD previously used Kanji mode, now excludes trailing 0xFD); BWIPP TODO: exclude also" }, /*140*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (8 << 8), "\201\375", 0, 0, "40 28 1F D0 EC 11 EC 11 EC", 1, 1, "B2 (0x81FD previously used Kanji mode, now excludes trailing 0xFD)" },
/*141*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\376", 0, 0, "40 28 1F E0 EC 11 EC 11 EC", 0, 1, "B2 (0x81FE previously used Kanji mode, now excludes trailing 0xFE); BWIPP TODO: exclude also" }, /*141*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (4 << 8), "\201\376", 0, 0, "40 28 1F E0 EC 11 EC 11 EC", 1, 1, "B2 (0x81FE previously used Kanji mode, now excludes trailing 0xFE)" },
/*142*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\377", 0, 0, "40 28 1F F0 EC 11 EC 11 EC", 0, 1, "B2 (0x81FF previously used Kanji mode, now excludes trailing 0xFF); BWIPP TODO: exclude also" }, /*142*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (6 << 8), "\201\377", 0, 0, "40 28 1F F0 EC 11 EC 11 EC", 1, 1, "B2 (0x81FF previously used Kanji mode, now excludes trailing 0xFF)" },
/*143*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE, "\201\377", 0, 0, "40 28 1F F0 EC 11 EC 11 EC", 0, 1, "B2 (0x81FF previously used Kanji mode, now excludes trailing 0xFF); BWIPP TODO: exclude also" }, /*143*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (6 << 8), "\201\377", 0, 0, "40 28 1F F0 EC 11 EC 11 EC", 1, 1, "B2 (0x81FF previously used Kanji mode, now excludes trailing 0xFF)" },
/*144*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (7 << 8), "\201\255", 0, 0, "80 10 36 80 EC 11 EC 11 EC", 1, 1, "K1 (0x81AD undefined in Shift JIS but not checked and uses Kanji mode)" }, /*144*/ { DATA_MODE, 0, 4, ZINT_FULL_MULTIBYTE | (7 << 8), "\201\255", 0, 0, "80 10 36 80 EC 11 EC 11 EC", 1, 1, "K1 (0x81AD undefined in Shift JIS but not checked and uses Kanji mode)" },
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
@ -4251,6 +4251,29 @@ static void test_qr_encode(const testCtx *const p_ctx) {
"100000100100010011101" "100000100100010011101"
"111111100011110001100" "111111100011110001100"
}, },
/*128*/ { BARCODE_QRCODE, UNICODE_MODE, -1, 2, -1, 1 << 8, { 0, 0, "" }, "202404110011看看16", -1, ZINT_WARN_NONCOMPLIANT, 21, 21, 1, "Shift-JIS range (BWIPP via bwip-js issue #335)",
"111111100000101111111"
"100000101111101000001"
"101110100111001011101"
"101110100100001011101"
"101110101110101011101"
"100000100100101000001"
"111111101010101111111"
"000000000111100000000"
"101010100001000010010"
"110111010011011110011"
"000000111000101100000"
"010100000001011100010"
"111100101000100001110"
"000000001101000101010"
"111111100110010010101"
"100000100001000100001"
"101110101010001010001"
"101110100011000110110"
"101110101100111100001"
"100000100011010111000"
"111111101110111010101"
},
}; };
int data_size = ARRAY_SIZE(data); int data_size = ARRAY_SIZE(data);
int i, length, ret; int i, length, ret;

View File

@ -3263,36 +3263,36 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
/* Hack in various adjustments */ /* Hack in various adjustments */
if (symbology == BARCODE_DBAR_OMN || symbology == BARCODE_DBAR_LTD || symbology == BARCODE_DBAR_EXP) { if (symbology == BARCODE_DBAR_OMN || symbology == BARCODE_DBAR_LTD || symbology == BARCODE_DBAR_EXP) {
/* Begin with space */ /* Begin with space */
char adj[5] = " -sbs"; char adj[] = " -sbs";
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39 if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39
|| symbology == BARCODE_CODABAR || symbology == BARCODE_PHARMA || symbology == BARCODE_PZN || symbology == BARCODE_CODABAR || symbology == BARCODE_PHARMA || symbology == BARCODE_PZN
|| symbology == BARCODE_CODE32 || symbology == BARCODE_VIN) { || symbology == BARCODE_CODE32 || symbology == BARCODE_VIN) {
/* Ratio 3 width bar/space -> 2 width */ /* Ratio 3 width bar/space -> 2 width */
char adj[8] = " -sr=0.6"; char adj[] = " -sr=0.6";
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbology == BARCODE_C25INTER || symbology == BARCODE_DPLEIT || symbology == BARCODE_DPIDENT if (symbology == BARCODE_C25INTER || symbology == BARCODE_DPLEIT || symbology == BARCODE_DPIDENT
|| symbology == BARCODE_ITF14) { || symbology == BARCODE_ITF14) {
/* Ratio 2 width bar/space -> 3 width */ /* Ratio 2 width bar/space -> 3 width */
char adj[8] = " -sr=1.3"; char adj[] = " -sr=1.3";
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbology == BARCODE_FIM) { if (symbology == BARCODE_FIM) {
/* Ratio 2.25 width bar/space -> 1 width */ /* Ratio 2.25 width bar/space -> 1 width */
char adj[10] = " -sr=0.444"; char adj[] = " -sr=0.444";
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbology == BARCODE_PLESSEY) { if (symbology == BARCODE_PLESSEY) {
/* Ceiling ratio 3/4/5 width bar/space -> 2 width then round ratio 2 width bar/space -> 3 width */ /* Ceiling ratio 3/4/5 width bar/space -> 2 width then round ratio 2 width bar/space -> 3 width */
char adj[16] = " -sc=0.4 -sr=1.3"; char adj[] = " -sc=0.4 -sr=1.3";
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39 if (symbology == BARCODE_CODE11 || symbology == BARCODE_CODE39 || symbology == BARCODE_EXCODE39
|| symbology == BARCODE_HIBC_39 || symbology == BARCODE_LOGMARS || symbology == BARCODE_PHARMA || symbology == BARCODE_HIBC_39 || symbology == BARCODE_LOGMARS || symbology == BARCODE_PHARMA
@ -3300,28 +3300,28 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
|| symbology == BARCODE_C25INTER || symbology == BARCODE_DPLEIT || symbology == BARCODE_DPIDENT || symbology == BARCODE_C25INTER || symbology == BARCODE_DPLEIT || symbology == BARCODE_DPIDENT
|| symbology == BARCODE_ITF14 || symbology == BARCODE_PHARMA_TWO) { || symbology == BARCODE_ITF14 || symbology == BARCODE_PHARMA_TWO) {
/* End sbs loop on bar */ /* End sbs loop on bar */
char adj[6] = " -selb"; char adj[] = " -selb";
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbology == BARCODE_C25STANDARD) { if (symbology == BARCODE_C25STANDARD) {
/* Zint uses 4X start/stop wides while BWIPP uses 3X - convert */ /* Zint uses 4X start/stop wides while BWIPP uses 3X - convert */
char adj[91] = " -sp='i 0 eq i limit 4 sub eq or sbs i get 3 eq and { (1111) print true } { false } ifelse'"; char adj[] = " -sp='i 0 eq i limit 4 sub eq or sbs i get 3 eq and { (1111) print true } { false } ifelse'";
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbology == BARCODE_POSTNET || symbology == BARCODE_PLANET || symbology == BARCODE_RM4SCC if (symbology == BARCODE_POSTNET || symbology == BARCODE_PLANET || symbology == BARCODE_RM4SCC
|| symbology == BARCODE_JAPANPOST || symbology == BARCODE_KIX || symbology == BARCODE_DAFT || symbology == BARCODE_JAPANPOST || symbology == BARCODE_KIX || symbology == BARCODE_DAFT
|| symbology == BARCODE_USPS_IMAIL || symbology == BARCODE_AUSPOST || symbology == BARCODE_PHARMA_TWO) { || symbology == BARCODE_USPS_IMAIL || symbology == BARCODE_AUSPOST || symbology == BARCODE_PHARMA_TWO) {
/* Emulate rows with BWIPP heights. */ /* Emulate rows with BWIPP heights. */
char adj[5] = " -shs"; char adj[] = " -shs";
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbology == BARCODE_CODE16K || symbology == BARCODE_CODE49) { if (symbology == BARCODE_CODE16K || symbology == BARCODE_CODE49) {
char adj[15] = " -sxs=10 -sxe=1"; /* Strip first 10 and last zero */ char adj[] = " -sxs=10 -sxe=1"; /* Strip first 10 and last zero */
memmove(cmd + GS_INITIAL_LEN + sizeof(adj), cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN); memmove(cmd + GS_INITIAL_LEN + sizeof(adj) - 1, cmd + GS_INITIAL_LEN, strlen(cmd) + 1 - GS_INITIAL_LEN);
memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj)); memcpy(cmd + GS_INITIAL_LEN, adj, sizeof(adj) - 1);
} }
if (symbol->debug & ZINT_DEBUG_TEST_PRINT) { if (symbol->debug & ZINT_DEBUG_TEST_PRINT) {

View File

@ -57,10 +57,8 @@ extern "C" {
#define testutil_pclose(stream) _pclose(stream) #define testutil_pclose(stream) _pclose(stream)
#else #else
#include <unistd.h> #include <unistd.h>
# if defined(ZINT_IS_C89) || defined(ZINT_IS_C99) extern FILE *popen(const char *command, const char *type);
extern FILE *popen(const char *command, const char *type); extern int pclose(FILE *stream);
extern int pclose(FILE *stream);
# endif
#define testutil_popen(command, mode) popen(command, mode) #define testutil_popen(command, mode) popen(command, mode)
#define testutil_pclose(stream) pclose(stream) #define testutil_pclose(stream) pclose(stream)
#endif #endif
@ -70,6 +68,7 @@ extern "C" {
# pragma GCC diagnostic ignored "-Woverlength-strings" # pragma GCC diagnostic ignored "-Woverlength-strings"
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
# pragma warning(disable: 4305) /* truncation from 'double' to 'float' */ # pragma warning(disable: 4305) /* truncation from 'double' to 'float' */
# pragma warning(disable: 4702) /* unreachable code */
#endif #endif
extern int assertionFailed; extern int assertionFailed;

View File

@ -37,7 +37,7 @@
extern "C" { extern "C" {
#endif #endif
#ifdef _MSC_VER #ifdef OUT_USE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
@ -60,7 +60,7 @@ extern "C" {
uint16_t blue; uint16_t blue;
} OUT_PACK tiff_color_t; } OUT_PACK tiff_color_t;
#ifdef _MSC_VER #ifdef OUT_USE_PRAGMA_PACK
#pragma pack() #pragma pack()
#endif #endif

View File

@ -294,22 +294,21 @@ foreach ($spec_parts as $spec => $spec_part) {
$comment = ' (Used by'; $comment = ' (Used by';
foreach ($spec_comments[$spec] as $i => $spec_comment) { foreach ($spec_comments[$spec] as $i => $spec_comment) {
if ($i) { if ($i) {
if ($i > 3) {
$comment .= '...';
break;
}
$comment .= ', '; $comment .= ', ';
} else { } else {
$comment .= ' '; $comment .= ' ';
} }
$comment .= $spec_comment; $comment .= $spec_comment;
} }
if (strlen($comment) > 118 - 3 /*start comment*/ - 4 /*)end comment*/ - strlen($spec)) {
$comment = substr($comment, 0, 118 - 3 - 4 - strlen($spec) - 3) . '...';
}
$comment .= ')'; $comment .= ')';
} }
print <<<EOD print <<<EOD
/* $spec$comment */ /* $spec$comment */
static int $spec_func(const unsigned char *data, const int data_len, static int $spec_func(const unsigned char *data,
$tab$tab{$tab}int *p_err_no, int *p_err_posn, char err_msg[50]) { $tab$tab{$tab}const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
{$tab}return {$tab}return
EOD; EOD;

View File

@ -459,7 +459,7 @@ extern "C" {
ZINT_EXTERN int ZBarcode_ValidID(int symbol_id); ZINT_EXTERN int ZBarcode_ValidID(int symbol_id);
/* Copy BARCODE_XXX name of `symbol_id` into `name` buffer, NUL-terminated. /* Copy BARCODE_XXX name of `symbol_id` into `name` buffer, NUL-terminated.
Returns 0 if valid, non-zero (1 or -1) if not valid */ Returns 0 if valid, 1 if not valid */
ZINT_EXTERN int ZBarcode_BarcodeName(int symbol_id, char name[32]); ZINT_EXTERN int ZBarcode_BarcodeName(int symbol_id, char name[32]);
/* Return the capability flags for symbology `symbol_id` that match `cap_flag` */ /* Return the capability flags for symbology `symbol_id` that match `cap_flag` */

View File

@ -1,11 +1,11 @@
% docs/README 2024-05-27 % docs/README 2024-06-27
For generation of "docs/manual.pdf" and "docs/manual.txt" from "manual.pmd" using a recent version of pandoc For generation of "docs/manual.pdf" and "docs/manual.txt" from "manual.pmd" using a recent version of pandoc
On Ubuntu/Debian (tested on Ubuntu 22.04) On Ubuntu/Debian (tested on Ubuntu 22.04)
wget https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-1-amd64.deb wget https://github.com/jgm/pandoc/releases/download/3.2.1/pandoc-3.2.1-1-amd64.deb
sudo dpkg -i pandoc-3.2-1-amd64.deb sudo dpkg -i pandoc-3.2.1-1-amd64.deb
sudo apt install python3-pip sudo apt install python3-pip
pip install pandoc-tablenos --user pip install pandoc-tablenos --user
export PATH=~/.local/bin:"$PATH" export PATH=~/.local/bin:"$PATH"
@ -20,9 +20,9 @@ On Ubuntu/Debian (tested on Ubuntu 22.04)
On Fedora (tested on Fedora Linux 38 (Workstation Edition)) On Fedora (tested on Fedora Linux 38 (Workstation Edition))
wget https://github.com/jgm/pandoc/releases/download/3.2/pandoc-3.2-linux-amd64.tar.gz wget https://github.com/jgm/pandoc/releases/download/3.2.1/pandoc-3.2.1-linux-amd64.tar.gz
tar xf pandoc-3.2-linux-amd64.tar.gz tar xf pandoc-3.2.1-linux-amd64.tar.gz
sudo mv -i pandoc-3.2/bin/pandoc /usr/local/bin sudo mv -i pandoc-3.2.1/bin/pandoc /usr/local/bin
sudo dnf install python3-pip sudo dnf install python3-pip
pip install pandoc-tablenos --user pip install pandoc-tablenos --user
export PATH=~/.local/bin:"$PATH" export PATH=~/.local/bin:"$PATH"

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
% Zint Barcode Generator and Zint Barcode Studio User Manual % Zint Barcode Generator and Zint Barcode Studio User Manual
% Version 2.13.0.9 % Version 2.13.0.9
% May 2024 % June 2024
# 1. Introduction # 1. Introduction
@ -4246,7 +4246,7 @@ Slovenia). The size, error correction level and ECI are set by Zint and do not
need to be specified. UPNQR is unusual in that it uses Latin-2 (ISO/IEC 8859-2 need to be specified. UPNQR is unusual in that it uses Latin-2 (ISO/IEC 8859-2
plus ASCII) formatted data. Zint will accept UTF-8 data and convert it to plus ASCII) formatted data. Zint will accept UTF-8 data and convert it to
Latin-2, or if your data is already Latin-2 formatted use the `--binary` switch Latin-2, or if your data is already Latin-2 formatted use the `--binary` switch
(API `input_mode = DATA MODE`). (API `input_mode = DATA_MODE`).
The following example creates a symbol from data saved as a Latin-2 file: The following example creates a symbol from data saved as a Latin-2 file:

View File

@ -1,6 +1,6 @@
Zint Barcode Generator and Zint Barcode Studio User Manual Zint Barcode Generator and Zint Barcode Studio User Manual
Version 2.13.0.9 Version 2.13.0.9
May 2024 June 2024
******************************************************************************* *******************************************************************************
* For reference the following is a text-only version of the Zint manual, * * For reference the following is a text-only version of the Zint manual, *
@ -4082,7 +4082,7 @@ Slovenia). The size, error correction level and ECI are set by Zint and do not
need to be specified. UPNQR is unusual in that it uses Latin-2 (ISO/IEC 8859-2 need to be specified. UPNQR is unusual in that it uses Latin-2 (ISO/IEC 8859-2
plus ASCII) formatted data. Zint will accept UTF-8 data and convert it to plus ASCII) formatted data. Zint will accept UTF-8 data and convert it to
Latin-2, or if your data is already Latin-2 formatted use the --binary switch Latin-2, or if your data is already Latin-2 formatted use the --binary switch
(API input_mode = DATA MODE). (API input_mode = DATA_MODE).
The following example creates a symbol from data saved as a Latin-2 file: The following example creates a symbol from data saved as a Latin-2 file:
@ -4814,7 +4814,7 @@ configured barcode is displayed once the "Generate" button is pressed.
Annex D. Man Page ZINT(1) Annex D. Man Page ZINT(1)
% ZINT(1) Version 2.13.0.9 % % May 2024 % ZINT(1) Version 2.13.0.9 % % June 2024
NAME NAME

View File

@ -220,7 +220,7 @@ td {
tbody tr:first-child td { tbody tr:first-child td {
padding-top: 0.5em; padding-top: 0.5em;
} }
header { thead > tr {
margin-bottom: 4em; margin-bottom: 4em;
text-align: center; text-align: center;
} }

View File

@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.2 .\" Automatically generated by Pandoc 3.2
.\" .\"
.TH "ZINT" "1" "May 2024" "Version 2.13.0.9" "" .TH "ZINT" "1" "June 2024" "Version 2.13.0.9" ""
.SH NAME .SH NAME
\f[CR]zint\f[R] \- encode data as a barcode image \f[CR]zint\f[R] \- encode data as a barcode image
.SH SYNOPSIS .SH SYNOPSIS

View File

@ -1,6 +1,6 @@
% ZINT(1) Version 2.13.0.9 % ZINT(1) Version 2.13.0.9
% %
% May 2024 % June 2024
# NAME # NAME

View File

@ -48,24 +48,15 @@ typedef char static_assert_int_at_least_32bits[sizeof(int) * CHAR_BIT < 32 ? -1
/* Following copied from "backend/common.h" */ /* Following copied from "backend/common.h" */
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0]))) #define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
#endif
/* Determine if C89 or C99 (excluding MSVC, which doesn't define __STDC_VERSION__) */
#ifndef _MSC_VER
# if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L
# define ZINT_IS_C89
# elif __STDC_VERSION__ <= 199901L /* Actually includes pseudo-standards "C94/C95" as well */
# define ZINT_IS_C99
# endif
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
# include <malloc.h> # include <malloc.h>
# define z_alloca(nmemb) _alloca(nmemb) # define z_alloca(nmemb) _alloca(nmemb)
#elif defined(__COMPCERT__)
# define z_alloca(nmemb) malloc(nmemb) /* So links - leads to loads of leaks obs */
#else #else
# if defined(ZINT_IS_C89) || defined(ZINT_IS_C99) || defined(__NuttX__) || defined(_AIX) \ # if (defined(__GNUC__) && !defined(alloca) && !defined(__NetBSD__)) || defined(__NuttX__) || defined(_AIX) \
|| (defined(__sun) && defined(__SVR4) /*Solaris*/) || (defined(__sun) && defined(__SVR4) /*Solaris*/)
# include <alloca.h> # include <alloca.h>
# endif # endif
@ -749,20 +740,20 @@ static int validate_units(char *buf, const char units[][5], int units_size) {
} }
/* Parse and validate argument "xdim[,resolution]" to "--scalexdimdp" */ /* Parse and validate argument "xdim[,resolution]" to "--scalexdimdp" */
static int validate_scalexdimdp(const char *optarg, float *p_x_dim_mm, float *p_dpmm) { static int validate_scalexdimdp(const char *arg, float *p_x_dim_mm, float *p_dpmm) {
static const char x_units[][5] = { "mm", "in" }; static const char x_units[][5] = { "mm", "in" };
static const char r_units[][5] = { "dpmm", "dpi" }; static const char r_units[][5] = { "dpmm", "dpi" };
char x_buf[7 + 1 + 4 + 1] = {0}; /* Allow for 7 digits + dot + 4-char unit + NUL */ char x_buf[7 + 1 + 4 + 1] = {0}; /* Allow for 7 digits + dot + 4-char unit + NUL */
char r_buf[7 + 1 + 4 + 1] = {0}; /* As above */ char r_buf[7 + 1 + 4 + 1] = {0}; /* As above */
int units_i; /* For `validate_units()` */ int units_i; /* For `validate_units()` */
char errbuf[64]; /* For `validate_float()` */ char errbuf[64]; /* For `validate_float()` */
const char *comma = strchr(optarg, ','); const char *comma = strchr(arg, ',');
if (comma) { if (comma) {
if (comma == optarg || comma - optarg >= ARRAY_SIZE(x_buf)) { if (comma == arg || comma - arg >= ARRAY_SIZE(x_buf)) {
fprintf(stderr, "Error 174: scalexdimdp X-dim too %s\n", comma == optarg ? "short" : "long"); fprintf(stderr, "Error 174: scalexdimdp X-dim too %s\n", comma == arg ? "short" : "long");
return 0; return 0;
} }
strncpy(x_buf, optarg, comma - optarg); strncpy(x_buf, arg, comma - arg);
comma++; comma++;
if (!*comma || strlen(comma) >= ARRAY_SIZE(r_buf)) { if (!*comma || strlen(comma) >= ARRAY_SIZE(r_buf)) {
fprintf(stderr, "Error 175: scalexdimdp resolution too %s\n", !*comma ? "short" : "long"); fprintf(stderr, "Error 175: scalexdimdp resolution too %s\n", !*comma ? "short" : "long");
@ -770,11 +761,11 @@ static int validate_scalexdimdp(const char *optarg, float *p_x_dim_mm, float *p_
} }
strcpy(r_buf, comma); strcpy(r_buf, comma);
} else { } else {
if (!*optarg || strlen(optarg) >= ARRAY_SIZE(x_buf)) { if (!*arg || strlen(arg) >= ARRAY_SIZE(x_buf)) {
fprintf(stderr, "Error 176: scalexdimdp X-dim too %s\n", !*optarg ? "short" : "long"); fprintf(stderr, "Error 176: scalexdimdp X-dim too %s\n", !*arg ? "short" : "long");
return 0; return 0;
} }
strcpy(x_buf, optarg); strcpy(x_buf, arg);
} }
if ((units_i = validate_units(x_buf, x_units, ARRAY_SIZE(x_units))) == -2) { if ((units_i = validate_units(x_buf, x_units, ARRAY_SIZE(x_units))) == -2) {
fprintf(stderr, "Error 177: scalexdimdp X-dim units must occur at end\n"); fprintf(stderr, "Error 177: scalexdimdp X-dim units must occur at end\n");
@ -809,19 +800,19 @@ static int validate_scalexdimdp(const char *optarg, float *p_x_dim_mm, float *p_
} }
/* Parse and validate Structured Append argument "index,count[,ID]" to "--structapp" */ /* Parse and validate Structured Append argument "index,count[,ID]" to "--structapp" */
static int validate_structapp(const char *optarg, struct zint_structapp *structapp) { static int validate_structapp(const char *arg, struct zint_structapp *structapp) {
char index[10] = {0}, count[10] = {0}; char index[10] = {0}, count[10] = {0};
const char *comma = strchr(optarg, ','); const char *comma = strchr(arg, ',');
const char *comma2; const char *comma2;
if (!comma) { if (!comma) {
fprintf(stderr, "Error 155: Invalid Structured Append argument, expect \"index,count[,ID]\"\n"); fprintf(stderr, "Error 155: Invalid Structured Append argument, expect \"index,count[,ID]\"\n");
return 0; return 0;
} }
if (comma == optarg || comma - optarg > 9) { if (comma == arg || comma - arg > 9) {
fprintf(stderr, "Error 156: Structured Append index too %s\n", comma == optarg ? "short" : "long"); fprintf(stderr, "Error 156: Structured Append index too %s\n", comma == arg ? "short" : "long");
return 0; return 0;
} }
strncpy(index, optarg, comma - optarg); strncpy(index, arg, comma - arg);
comma++; comma++;
comma2 = strchr(comma, ','); comma2 = strchr(comma, ',');
if (comma2) { if (comma2) {
@ -864,14 +855,14 @@ static int validate_structapp(const char *optarg, struct zint_structapp *structa
} }
/* Parse and validate the segment argument "ECI,DATA" to "--segN" */ /* Parse and validate the segment argument "ECI,DATA" to "--segN" */
static int validate_seg(const char *optarg, const int N, struct zint_seg segs[10]) { static int validate_seg(const char *arg, const int N, struct zint_seg segs[10]) {
char eci[10] = {0}; char eci[10] = {0};
const char *comma = strchr(optarg, ','); const char *comma = strchr(arg, ',');
if (!comma || comma == optarg || comma - optarg > 9 || *(comma + 1) == '\0') { if (!comma || comma == arg || comma - arg > 9 || *(comma + 1) == '\0') {
fprintf(stderr, "Error 166: Invalid segment argument, expect \"ECI,DATA\"\n"); fprintf(stderr, "Error 166: Invalid segment argument, expect \"ECI,DATA\"\n");
return 0; return 0;
} }
strncpy(eci, optarg, comma - optarg); strncpy(eci, arg, comma - arg);
if (!validate_int(eci, -1 /*len*/, &segs[N].eci)) { if (!validate_int(eci, -1 /*len*/, &segs[N].eci)) {
fprintf(stderr, "Error 167: Invalid segment ECI (digits only)\n"); fprintf(stderr, "Error 167: Invalid segment ECI (digits only)\n");
return 0; return 0;
@ -902,6 +893,7 @@ static int batch_process(struct zint_symbol *symbol, const char *filename, const
char format_string[256], reversed_string[256], format_char; char format_string[256], reversed_string[256], format_char;
int format_len, i, o, mirror_start_o = 0; int format_len, i, o, mirror_start_o = 0;
char adjusted[2] = {0}; char adjusted[2] = {0};
const int from_stdin = strcmp(filename, "-") == 0; /* Suppress clang-19 warning clang-analyzer-unix.Stream */
if (mirror_mode) { if (mirror_mode) {
/* Use directory if any from outfile */ /* Use directory if any from outfile */
@ -936,7 +928,7 @@ static int batch_process(struct zint_symbol *symbol, const char *filename, const
} }
} }
if (strcmp(filename, "-") == 0) { if (from_stdin) {
file = stdin; file = stdin;
} else { } else {
#ifdef _WIN32 #ifdef _WIN32
@ -1113,7 +1105,7 @@ static int batch_process(struct zint_symbol *symbol, const char *filename, const
warn_number = ZINT_WARN_INVALID_OPTION; /* TODO: maybe new warning e.g. ZINT_WARN_INVALID_INPUT? */ warn_number = ZINT_WARN_INVALID_OPTION; /* TODO: maybe new warning e.g. ZINT_WARN_INVALID_INPUT? */
} }
if (file != stdin) { if (!from_stdin) {
if (fclose(file) != 0) { if (fclose(file) != 0) {
fprintf(stderr, "Warning 196: Failure on closing input file '%s' (%d: %s)\n", filename, errno, fprintf(stderr, "Warning 196: Failure on closing input file '%s' (%d: %s)\n", filename, errno,
strerror(errno)); strerror(errno));