41#include "zintconfig.h"
47# if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L
53typedef unsigned __int8 uint8_t;
54typedef unsigned __int16 uint16_t;
55typedef __int32 int32_t;
56typedef unsigned __int32 uint32_t;
57typedef unsigned __int64 uint64_t;
64#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
68# define z_alloca(nmemb) _alloca(nmemb)
69#elif defined(__COMPCERT__)
70# define z_alloca(nmemb) malloc(nmemb)
72# if (defined(__GNUC__) && !defined(alloca) && !defined(__NetBSD__)) || defined(__NuttX__) || defined(_AIX) \
73 || (defined(__sun) && defined(__SVR4) )
76# define z_alloca(nmemb) alloca(nmemb)
82# pragma warning(disable: 4125)
83# pragma warning(disable: 4244)
85# pragma warning(disable: 4996)
87#elif defined(__MINGW64__) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 3
88# pragma GCC diagnostic ignored "-Wlong-long"
91#if defined(__GNUC__) && __GNUC__ >= 3
92# define ZINT_FORMAT_PRINTF(fmt_idx, first_idx) __attribute__((__format__(printf, fmt_idx, first_idx)))
94# define ZINT_FORMAT_PRINTF(fmt_idx, first_idx)
97#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(ZINT_TEST) && !defined(__MINGW32__)
98# define INTERNAL __attribute__((__visibility__("hidden")))
99#elif defined(ZINT_TEST)
100# define INTERNAL ZINT_EXTERN
105#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
106# define INTERNAL_DATA_EXTERN __attribute__((__visibility__("hidden"))) extern
107# define INTERNAL_DATA __attribute__((__visibility__("hidden")))
109# define INTERNAL_DATA_EXTERN extern
110# define INTERNAL_DATA
115# define restrict __restrict
125#if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(ZINT_IS_C89)
126# define ceilf (float) ceil
127# define floorf (float) floor
128# define fmodf (float) fmod
131#if (defined(_MSC_VER) && _MSC_VER < 1800) || defined(ZINT_IS_C89)
132# define round(arg) floor((arg) + 0.5)
133# define roundf(arg) floorf((arg) + 0.5f)
137#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(ZINT_IS_C89)
138#define Z_NO_VSNPRINTF
142#define z_isfintf(arg) (fmodf(arg, 1.0f) == 0.0f)
145#define z_isdigit(ch) ((ch) <= '9' && (ch) >= '0')
146#define z_isupper(ch) ((ch) >= 'A' && (ch) <= 'Z')
147#define z_islower(ch) ((ch) >= 'a' && (ch) <= 'z')
148#define z_isalpha(ch) (z_isupper(ch) || z_islower(ch))
149#define z_isascii(ch) (!((ch) & ~0x7F))
150#define z_iscntrl(ch) (!((ch) & ~0x1F) || (ch) == 127)
153#define ZUCP(p) ((unsigned char *) (p))
154#define ZCUCP(p) ((const unsigned char *) (p))
155#define ZCCP(p) ((const char *) (p))
156#define z_ustrlen(p) strlen(ZCCP(p))
159#define z_itoc(i) ((i) + '0')
161#define z_xtoc(i) ((i) < 10 ? z_itoc(i) : ((i) - 10) + 'A')
164INTERNAL
int z_ctoi(
const char ch);
167INTERNAL
int z_to_int(
const unsigned char source[],
const int length);
170INTERNAL
void z_to_upper(
unsigned char source[],
const int length);
173INTERNAL
int z_chr_cnt(
const unsigned char source[],
const int length,
const unsigned char ch);
176INTERNAL
int z_zero_fill(
const unsigned char source[],
const int length,
unsigned char *dest,
const int dest_length);
179#define IS_SPC_F 0x0001
180#define IS_HSH_F 0x0002
181#define IS_AST_F 0x0004
182#define IS_PLS_F 0x0008
183#define IS_MNS_F 0x0010
184#define IS_NUM_F 0x0020
185#define IS_UPO_F 0x0040
186#define IS_UHX_F 0x0080
187#define IS_UX__F 0x0100
188#define IS_LWO_F 0x0200
189#define IS_LHX_F 0x0400
190#define IS_LX__F 0x0800
191#define IS_C82_F 0x1000
192#define IS_SIL_F 0x2000
193#define IS_CLI_F 0x4000
194#define IS_ARS_F 0x8000
196#define IS_UPR_F (IS_UPO_F | IS_UHX_F | IS_UX__F)
197#define IS_LWR_F (IS_LWO_F | IS_LHX_F | IS_LX__F)
200#define NEON_F IS_NUM_F
203INTERNAL
int z_is_chr(
const unsigned int flag,
const unsigned int ch);
206INTERNAL
int z_not_sane(
const unsigned int flag,
const unsigned char source[],
const int length);
210INTERNAL
int z_not_sane_lookup(
const char test_string[],
const int test_length,
const unsigned char source[],
211 const int length,
int *posns);
214INTERNAL
int z_posn(
const char set_string[],
const char data);
219INTERNAL
int z_bin_append_posn(
const int arg,
const int length,
char *binary,
const int bin_posn);
221#define Z_COMMON_INLINE 1
223#ifdef Z_COMMON_INLINE
225# define z_module_is_set(s, y, x) (((s)->encoded_data[y][(x) >> 3] >> ((x) & 0x07)) & 1)
226# define z_set_module(s, y, x) do { (s)->encoded_data[y][(x) >> 3] |= 1 << ((x) & 0x07); } while (0)
227# define z_module_colour_is_set(s, y, x) ((s)->encoded_data[y][x])
228# define z_set_module_colour(s, y, x, c) do { (s)->encoded_data[y][x] = (c); } while (0)
229# define z_unset_module(s, y, x) do { (s)->encoded_data[y][(x) >> 3] &= ~(1 << ((x) & 0x07)); } while (0)
234INTERNAL
int z_module_is_set(
const struct zint_symbol *symbol,
const int y_coord,
const int x_coord);
237INTERNAL
void z_set_module(
struct zint_symbol *symbol,
const int y_coord,
const int x_coord);
240INTERNAL
int z_module_colour_is_set(
const struct zint_symbol *symbol,
const int y_coord,
const int x_coord);
243INTERNAL
void z_set_module_colour(
struct zint_symbol *symbol,
const int y_coord,
const int x_coord,
247INTERNAL
void z_unset_module(
struct zint_symbol *symbol,
const int y_coord,
const int x_coord);
253INTERNAL
void z_expand(
struct zint_symbol *symbol,
const char data[],
const int length);
258INTERNAL
int z_errtxt(
const int error_number,
struct zint_symbol *symbol,
const int err_id,
const char *msg);
260#if defined(__GNUC__) && !defined(__clang__)
261#define ZEXT __extension__
272INTERNAL
int z_errtxtf(
const int error_number,
struct zint_symbol *symbol,
const int err_id,
const char *fmt, ...)
273 ZINT_FORMAT_PRINTF(4, 5);
278INTERNAL
int z_errtxt_adj(const
int error_number, struct
zint_symbol *symbol, const
char *fmt, const
char *msg);
282INTERNAL
int z_is_bindable(const
int symbology);
285INTERNAL
int z_is_ean(const
int symbology);
288INTERNAL
int z_is_upcean(const
int symbology);
291INTERNAL
int z_is_composite(const
int symbology);
294INTERNAL
int z_is_dotty(const
int symbology);
297INTERNAL
int z_is_fixed_ratio(const
int symbology);
301INTERNAL
int z_is_twodigits(const
unsigned char source[], const
int length, const
int position);
304INTERNAL
int z_cnt_digits(const
unsigned char source[], const
int length, const
int position, const
int max);
308INTERNAL
unsigned int z_decode_utf8(
unsigned int *state,
unsigned int *codep, const
unsigned char byte);
311INTERNAL
int z_is_valid_utf8(const
unsigned char source[], const
int length);
315INTERNAL
int z_utf8_to_unicode(struct
zint_symbol *symbol, const
unsigned char source[],
unsigned int vals[],
316 int *length, const
int disallow_4byte);
321INTERNAL
int z_extra_escape_position_fnc1(const
unsigned char source[], const
int length);
326INTERNAL
int z_extra_escapes(struct
zint_symbol *symbol, const
unsigned char source[],
int *p_length, const
int eci,
327 unsigned char *dest,
char *fncs,
int *p_have_extra_escapes);
332INTERNAL
int z_hrt_cpy_iso8859_1(struct
zint_symbol *symbol, const
unsigned char source[], const
int length);
335INTERNAL
void z_hrt_cpy_nochk(struct
zint_symbol *symbol, const
unsigned char source[], const
int length);
339INTERNAL
void z_hrt_cpy_cat_nochk(struct
zint_symbol *symbol, const
unsigned char source[], const
int length,
340 const
char separator, const
unsigned char cat[], const
int cat_length);
343INTERNAL
void z_hrt_cpy_chr(struct
zint_symbol *symbol, const
char ch);
346INTERNAL
void z_hrt_cat_nochk(struct
zint_symbol *symbol, const
unsigned char source[], const
int length);
349INTERNAL
void z_hrt_cat_chr_nochk(struct
zint_symbol *symbol, const
char ch);
352INTERNAL
void z_hrt_printf_nochk(struct
zint_symbol *symbol, const
char *fmt, ...) ZINT_FORMAT_PRINTF(2, 3);
355INTERNAL
void z_hrt_conv_gs1_brackets_nochk(struct
zint_symbol *symbol, const
unsigned char source[],
360INTERNAL
int z_ct_init_segs(struct
zint_symbol *symbol, const
int seg_count);
363INTERNAL
void z_ct_free_segs(struct
zint_symbol *symbol);
367INTERNAL
int z_ct_cpy_segs(struct
zint_symbol *symbol, const struct
zint_seg segs[], const
int seg_count);
371INTERNAL
void z_ct_set_seg_extra_escapes_eci(struct
zint_symbol *symbol, const
int seg_idx, const
int eci);
374INTERNAL
void z_ct_set_seg_eci(struct
zint_symbol *symbol, const
int seg_idx, const
int eci);
378INTERNAL
int z_ct_cpy(struct
zint_symbol *symbol, const
unsigned char source[], const
int length);
382INTERNAL
int z_ct_cpy_cat(struct
zint_symbol *symbol, const
unsigned char source[], const
int length,
383 const
char separator, const
unsigned char cat[], const
int cat_length);
387INTERNAL
int z_ct_cpy_iso8859_1(struct
zint_symbol *symbol, const
unsigned char source[], const
int length);
391INTERNAL
int z_ct_printf_256(struct
zint_symbol *symbol, const
char *fmt, ...) ZINT_FORMAT_PRINTF(2, 3);
396INTERNAL
int z_set_height(struct
zint_symbol *symbol, const
float min_row_height, const
float default_height,
397 const
float max_height, const
int no_errtxt);
401INTERNAL
float z_stripf(const
float arg);
405INTERNAL
int z_segs_length(const struct
zint_seg segs[], const
int seg_count);
408INTERNAL
void z_segs_cpy(const struct
zint_symbol *symbol, const struct
zint_seg segs[], const
int seg_count,
414INTERNAL
char *z_debug_print_escape(const
unsigned char *source, const
int first_len,
char *buf);
418INTERNAL
void z_debug_test_codeword_dump(
struct zint_symbol *symbol,
const unsigned char *codewords,
421INTERNAL
void z_debug_test_codeword_dump_short(
struct zint_symbol *symbol,
const short *codewords,
const int length);
423INTERNAL
void z_debug_test_codeword_dump_int(
struct zint_symbol *symbol,
const int *codewords,
const int length);