CODEONE/DATAMATRIX/MAILMARK/PLESSEY: fix some 32-bit/portability bugs

PLESSEY: add options NCR weighted mod-10, hide check digit(s) in HRT
test suite: now runnable under MSVC 2019, 2017, 2015, MinGW/MSYS
win32/README: update with MSVC 2019 and CMake instructions
This commit is contained in:
gitlost 2021-06-10 11:15:39 +01:00
parent f471bb6e50
commit 4a8cac2a5a
63 changed files with 1189 additions and 983 deletions

View file

@ -1,4 +1,5 @@
# (c) 2008 by BogDan Vatra < bogdan@licentia.eu >
# Copyright (C) 2008 by BogDan Vatra < bogdan@licentia.eu >
# Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
# vim: set ts=4 sw=4 et :
project(zint)
@ -63,4 +64,4 @@ install(FILES zint.h DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel)
if(ZINT_TEST)
add_subdirectory(tests)
endif(ZINT_TEST)
endif()

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,6 +31,7 @@
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <stdio.h>
#include "common.h"
#include "bmp.h" /* Bitmap header structure */
@ -63,8 +64,8 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
}
row_size = 4 * ((bits_per_pixel * symbol->bitmap_width + 31) / 32);
data_size = symbol->bitmap_height * row_size;
data_offset = sizeof (bitmap_file_header_t) + sizeof (bitmap_info_header_t);
data_offset += (colour_count * (sizeof(color_ref_t)));
data_offset = sizeof(bitmap_file_header_t) + sizeof(bitmap_info_header_t);
data_offset += colour_count * sizeof(color_ref_t);
file_size = data_offset + data_size;
bitmap_file_start = (unsigned char *) malloc(file_size);
@ -84,7 +85,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
bg_color_ref.green = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bg_color_ref.blue = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
bg_color_ref.reserved = 0x00;
for (i = 0; i < 8; i++) {
ultra_color_ref[i].red = colour_to_red(i + 1);
ultra_color_ref[i].green = colour_to_green(i + 1);
@ -143,7 +144,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
file_header.reserved = 0;
file_header.data_offset = data_offset;
info_header.header_size = sizeof (bitmap_info_header_t);
info_header.header_size = sizeof(bitmap_info_header_t);
info_header.width = symbol->bitmap_width;
info_header.height = symbol->bitmap_height;
info_header.colour_planes = 1;
@ -154,12 +155,12 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
info_header.vert_res = 0;
info_header.colours = colour_count;
info_header.important_colours = colour_count;
bmp_posn = bitmap_file_start;
memcpy(bitmap_file_start, &file_header, sizeof (bitmap_file_header_t));
bmp_posn += sizeof (bitmap_file_header_t);
memcpy(bmp_posn, &info_header, sizeof (bitmap_info_header_t));
memcpy(bitmap_file_start, &file_header, sizeof(bitmap_file_header_t));
bmp_posn += sizeof(bitmap_file_header_t);
memcpy(bmp_posn, &info_header, sizeof(bitmap_info_header_t));
bmp_posn += sizeof(bitmap_info_header_t);
memcpy(bmp_posn, &bg_color_ref, sizeof(color_ref_t));
if (symbol->symbology == BARCODE_ULTRA) {
@ -167,7 +168,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
bmp_posn += sizeof(color_ref_t);
memcpy(bmp_posn, &ultra_color_ref[i], sizeof(color_ref_t));
}
} else {
} else {
bmp_posn += sizeof(color_ref_t);
memcpy(bmp_posn, &fg_color_ref, sizeof(color_ref_t));
}
@ -176,7 +177,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "600: Can't open output file");
sprintf(symbol->errtxt, "600: Can't open output file (%d: %.30s)", errno, strerror(errno));
free(bitmap_file_start);
return ZINT_ERROR_FILE_ACCESS;
}
@ -185,7 +186,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
} else {
if (!(bmp_file = fopen(symbol->outfile, "wb"))) {
free(bitmap_file_start);
strcpy(symbol->errtxt, "601: Can't open output file");
sprintf(symbol->errtxt, "601: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}

View file

@ -39,10 +39,6 @@
#include <math.h>
#ifdef _MSC_VER
#include <malloc.h>
/* ceilf (C99) not before MSVC++2013 (C++ 12.0) */
#if _MSC_VER < 1800
#define ceilf (float) ceil
#endif
#endif
/* Add solid bar */
@ -237,11 +233,11 @@ static int c1_look_ahead_test(const unsigned char source[], const int sourcelen,
if (sp >= position + 3) {
/* Step Q */
float cnt;
ascii_rnded = (int) ceilf(ascii_count);
c40_rnded = (int) ceilf(c40_count);
text_rnded = (int) ceilf(text_count);
edi_rnded = (int) ceilf(edi_count);
byte_rnded = (int) ceilf(byte_count);
ascii_rnded = (int) ceilf(stripf(ascii_count));
c40_rnded = (int) ceilf(stripf(c40_count));
text_rnded = (int) ceilf(stripf(text_count));
edi_rnded = (int) ceilf(stripf(edi_count));
byte_rnded = (int) ceilf(stripf(byte_count));
cnt = byte_count + 1.0f;
if (cnt <= ascii_rnded && cnt <= c40_rnded && cnt <= text_rnded && cnt <= edi_rnded) {
@ -277,11 +273,11 @@ static int c1_look_ahead_test(const unsigned char source[], const int sourcelen,
}
/* Step K */
ascii_rnded = (int) ceilf(ascii_count);
c40_rnded = (int) ceilf(c40_count);
text_rnded = (int) ceilf(text_count);
edi_rnded = (int) ceilf(edi_count);
byte_rnded = (int) ceilf(byte_count);
ascii_rnded = (int) ceilf(stripf(ascii_count));
c40_rnded = (int) ceilf(stripf(c40_count));
text_rnded = (int) ceilf(stripf(text_count));
edi_rnded = (int) ceilf(stripf(edi_count));
byte_rnded = (int) ceilf(stripf(byte_count));
if (byte_count <= ascii_rnded && byte_count <= c40_rnded && byte_count <= text_rnded && byte_count <= edi_rnded) {
return C1_BYTE; /* Step K1 */
@ -1121,7 +1117,7 @@ INTERNAL int code_one(struct zint_symbol *symbol, unsigned char source[], int le
size = symbol->option_2;
}
if ((symbol-> option_2 != 0) && (symbol->option_2 < size)) {
if ((symbol->option_2 != 0) && (symbol->option_2 < size)) {
strcpy(symbol->errtxt, "518: Input too long for selected symbol size");
return ZINT_ERROR_TOO_LONG;
}

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -74,7 +74,7 @@ INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int len
codeword_count = 0;
i = 0;
h = strlen(intermediate);
h = (int) strlen(intermediate);
do {
if ((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
/* Numeric data */
@ -340,7 +340,7 @@ INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int len
/* Expand into symbol */
symbol->row_height[i] = 10;
for (j = 0, len = strlen(pattern); j < len; j++) {
for (j = 0, len = (int) strlen(pattern); j < len; j++) {
if (pattern[j] == '1') {
set_module(symbol, i, j);
}
@ -348,7 +348,7 @@ INTERNAL int code_49(struct zint_symbol *symbol, unsigned char source[], int len
}
symbol->rows = rows;
symbol->width = strlen(pattern);
symbol->width = (int) strlen(pattern);
symbol->output_options |= BARCODE_BIND;

View file

@ -462,7 +462,7 @@ void debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *c
int i, max = length, cnt_len = 0;
if (length > 30) { /* 30*3 < errtxt 92 (100 - "Warning ") chars */
sprintf(symbol->errtxt, "(%d) ", length); /* Place the number of codewords at the front */
cnt_len = strlen(symbol->errtxt);
cnt_len = (int) strlen(symbol->errtxt);
max = 30 - (cnt_len + 2) / 3;
}
for (i = 0; i < max; i++) {

View file

@ -31,7 +31,6 @@
*/
/* vim: set ts=4 sw=4 et : */
/* Used in some logic */
#ifndef __COMMON_H
#define __COMMON_H
@ -57,23 +56,31 @@
#define ustrcat(target, source) strcat((char *) (target), (const char *) (source))
#define ustrncat(target, source, count) strncat((char *) (target), (const char *) (source), (count))
#if defined(__GNUC__) && !defined(_WIN32) && !defined(ZINT_TEST)
# define INTERNAL __attribute__ ((visibility ("hidden")))
#else /* despite the name, the test cases are referencing the INTERNAL functions, so they need to be exported */
# if defined(ZINT_TEST)
# if defined(DLL_EXPORT) || defined(PIC) || defined(_USRDLL)
# define INTERNAL __declspec(dllexport)
# elif defined(ZINT_DLL)
# define INTERNAL __declspec(dllimport)
# endif
/* Removes excess precision from floats - see https://stackoverflow.com/q/503436/664741 */
#define stripf(arg) (*((volatile float *) &(arg)))
#ifdef _MSC_VER
# if _MSC_VER < 1800 /* ceilf, floorf, roundf (C99) not before MSVC 2013 (C++ 12.0) */
# define ceilf (float) ceil
# define floorf (float) floor
# define roundf(arg) ((float) floor((arg) + 0.5f))
# endif
# if !defined(INTERNAL)
# define INTERNAL
# pragma warning(disable: 4244) /* conversion from int to float */
# if _MSC_VER >= 1900 /* MSVC 2015 */
# pragma warning(disable: 4996) /* function or variable may be unsafe */
# endif
#endif
#if defined(ZINT_TEST)
#define STATIC_UNLESS_ZINT_TEST
#if (defined(__GNUC__) || defined(__clang__)) && !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
#ifdef ZINT_TEST
#define STATIC_UNLESS_ZINT_TEST INTERNAL
#else
#define STATIC_UNLESS_ZINT_TEST static
#endif
@ -82,16 +89,16 @@
#ifdef COMMON_INLINE
/* Return 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)
# define module_is_set(s, y, x) (((s)->encoded_data[(y)][(x) >> 3] >> ((x) & 0x07)) & 1)
/* Set a module to dark/black */
#define set_module(s, y, x) do { (s)->encoded_data[(y)][(x) >> 3] |= 1 << ((x) & 0x07); } while (0)
# define set_module(s, y, x) do { (s)->encoded_data[(y)][(x) >> 3] |= 1 << ((x) & 0x07); } while (0)
/* Return true (1-8) if a module is colour, otherwise false (0) */
#define module_colour_is_set(s, y, x) ((s)->encoded_data[(y)][(x)])
# define module_colour_is_set(s, y, x) ((s)->encoded_data[(y)][(x)])
/* Set a module to a colour */
#define set_module_colour(s, y, x, c) do { (s)->encoded_data[(y)][(x)] = (c); } while (0)
# define set_module_colour(s, y, x, c) do { (s)->encoded_data[(y)][(x)] = (c); } while (0)
#endif
#ifdef __cplusplus
@ -131,8 +138,8 @@ extern "C" {
INTERNAL int colour_to_blue(const int colour);
#ifdef ZINT_TEST
void debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *codewords, const int length);
void debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length);
INTERNAL void debug_test_codeword_dump(struct zint_symbol *symbol, const unsigned char *codewords, const int length);
INTERNAL void debug_test_codeword_dump_int(struct zint_symbol *symbol, const int *codewords, const int length);
#endif
#ifdef __cplusplus

View file

@ -44,10 +44,6 @@
#include <math.h>
#ifdef _MSC_VER
#include <malloc.h>
/* ceilf (C99) not before MSVC++2013 (C++ 12.0) */
#if _MSC_VER < 1800
#define ceilf (float) ceil
#endif
#endif
#include "common.h"
#include "reedsol.h"
@ -419,12 +415,12 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen,
/* At the end of data ... step (k) */
/* step (k)(1) */
ascii_rnded = (int) ceilf(ascii_count);
b256_rnded = (int) ceilf(b256_count);
edf_rnded = (int) ceilf(edf_count);
text_rnded = (int) ceilf(text_count);
x12_rnded = (int) ceilf(x12_count);
c40_rnded = (int) ceilf(c40_count);
ascii_rnded = (int) ceilf(stripf(ascii_count));
b256_rnded = (int) ceilf(stripf(b256_count));
edf_rnded = (int) ceilf(stripf(edf_count));
text_rnded = (int) ceilf(stripf(text_count));
x12_rnded = (int) ceilf(stripf(x12_count));
c40_rnded = (int) ceilf(stripf(c40_count));
if (ascii_rnded <= b256_rnded && ascii_rnded <= edf_rnded && ascii_rnded <= text_rnded && ascii_rnded <= x12_rnded
&& ascii_rnded <= c40_rnded) {

View file

@ -1,7 +1,7 @@
/* emf.c - Support for Microsoft Enhanced Metafile Format
libzint - the open source barcode library
Copyright (C) 2016 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2016 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -33,6 +33,7 @@
/* Developed according to [MS-EMF] - v20160714, Released July 14, 2016
* and [MS-WMF] - v20160714, Released July 14, 2016 */
#include <errno.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
@ -232,7 +233,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]);
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
if (strlen(symbol->bgcolour) > 6) {
if ((ctoi(symbol->bgcolour[6]) == 0) && (ctoi(symbol->bgcolour[7]) == 0)) {
draw_background = 0;
@ -253,12 +254,12 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
float text_fsizes[string_count ? string_count: 1];
int text_haligns[string_count ? string_count: 1];
#else
rectangle = (emr_rectangle_t*) _alloca(rectangle_count * sizeof (emr_rectangle_t));
circle = (emr_ellipse_t*) _alloca(circle_count * sizeof (emr_ellipse_t));
hexagon = (emr_polygon_t*) _alloca(hexagon_count * sizeof (emr_polygon_t));
text = (emr_exttextoutw_t*) _alloca(string_count * sizeof (emr_exttextoutw_t));
text_fsizes = (float *) _alloca(string_count * sizeof (float));
text_haligns = (int *) _alloca(string_count * sizeof (int));
rectangle = (emr_rectangle_t*) _alloca(rectangle_count * sizeof(emr_rectangle_t));
circle = (emr_ellipse_t*) _alloca(circle_count * sizeof(emr_ellipse_t));
hexagon = (emr_polygon_t*) _alloca(hexagon_count * sizeof(emr_polygon_t));
text = (emr_exttextoutw_t*) _alloca(string_count * sizeof(emr_exttextoutw_t));
text_fsizes = (float *) _alloca(string_count * sizeof(float));
text_haligns = (int *) _alloca(string_count * sizeof(int));
#endif
//Calculate how many coloured rectangles
@ -662,7 +663,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
recordcount++;
if (symbol->symbology == BARCODE_MAXICODE) {
bytecount += 5 * sizeof (emr_selectobject_t);
bytecount += 5 * sizeof(emr_selectobject_t);
recordcount += 5;
}
@ -677,55 +678,55 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
emf_file = fopen(symbol->outfile, "wb");
}
if (emf_file == NULL) {
strcpy(symbol->errtxt, "640: Could not open output file");
sprintf(symbol->errtxt, "640: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
fwrite(&emr_header, sizeof (emr_header_t), 1, emf_file);
fwrite(&emr_header, sizeof(emr_header_t), 1, emf_file);
fwrite(&emr_mapmode, sizeof (emr_mapmode_t), 1, emf_file);
fwrite(&emr_mapmode, sizeof(emr_mapmode_t), 1, emf_file);
if (rotate_angle) {
fwrite(&emr_setworldtransform, sizeof (emr_setworldtransform_t), 1, emf_file);
fwrite(&emr_setworldtransform, sizeof(emr_setworldtransform_t), 1, emf_file);
}
fwrite(&emr_createbrushindirect_bg, sizeof (emr_createbrushindirect_t), 1, emf_file);
fwrite(&emr_createbrushindirect_bg, sizeof(emr_createbrushindirect_t), 1, emf_file);
if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 8; i++) {
if (rectangle_count_bycolour[i + 1]) {
fwrite(&emr_createbrushindirect_colour[i], sizeof (emr_createbrushindirect_t), 1, emf_file);
fwrite(&emr_createbrushindirect_colour[i], sizeof(emr_createbrushindirect_t), 1, emf_file);
}
}
} else {
fwrite(&emr_createbrushindirect_fg, sizeof (emr_createbrushindirect_t), 1, emf_file);
fwrite(&emr_createbrushindirect_fg, sizeof(emr_createbrushindirect_t), 1, emf_file);
}
fwrite(&emr_createpen, sizeof (emr_createpen_t), 1, emf_file);
fwrite(&emr_createpen, sizeof(emr_createpen_t), 1, emf_file);
if (symbol->vector->strings) {
fwrite(&emr_extcreatefontindirectw, sizeof (emr_extcreatefontindirectw_t), 1, emf_file);
fwrite(&emr_extcreatefontindirectw, sizeof(emr_extcreatefontindirectw_t), 1, emf_file);
if (fsize2) {
fwrite(&emr_extcreatefontindirectw2, sizeof (emr_extcreatefontindirectw_t), 1, emf_file);
fwrite(&emr_extcreatefontindirectw2, sizeof(emr_extcreatefontindirectw_t), 1, emf_file);
}
}
fwrite(&emr_selectobject_bgbrush, sizeof (emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_pen, sizeof (emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_bgbrush, sizeof(emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_pen, sizeof(emr_selectobject_t), 1, emf_file);
if (draw_background) {
fwrite(&background, sizeof (emr_rectangle_t), 1, emf_file);
fwrite(&background, sizeof(emr_rectangle_t), 1, emf_file);
}
if (symbol->symbology == BARCODE_ULTRA) {
for(i = 0; i < 8; i++) {
if (rectangle_count_bycolour[i + 1]) {
fwrite(&emr_selectobject_colour[i], sizeof (emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_colour[i], sizeof(emr_selectobject_t), 1, emf_file);
rect = symbol->vector->rectangles;
this_rectangle = 0;
while (rect) {
if (rect->colour == i + 1) {
fwrite(&rectangle[this_rectangle], sizeof (emr_rectangle_t), 1, emf_file);
fwrite(&rectangle[this_rectangle], sizeof(emr_rectangle_t), 1, emf_file);
}
this_rectangle++;
rect = rect->next;
@ -733,42 +734,42 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
}
}
} else {
fwrite(&emr_selectobject_fgbrush, sizeof (emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, emf_file);
// Rectangles
for (i = 0; i < rectangle_count; i++) {
fwrite(&rectangle[i], sizeof (emr_rectangle_t), 1, emf_file);
fwrite(&rectangle[i], sizeof(emr_rectangle_t), 1, emf_file);
}
}
// Hexagons
for (i = 0; i < hexagon_count; i++) {
fwrite(&hexagon[i], sizeof (emr_polygon_t), 1, emf_file);
fwrite(&hexagon[i], sizeof(emr_polygon_t), 1, emf_file);
}
// Circles
if (symbol->symbology == BARCODE_MAXICODE) {
// Bullseye needed
for (i = 0; i < circle_count; i++) {
fwrite(&circle[i], sizeof (emr_ellipse_t), 1, emf_file);
fwrite(&circle[i], sizeof(emr_ellipse_t), 1, emf_file);
if (i < circle_count - 1) {
if (i % 2) {
fwrite(&emr_selectobject_fgbrush, sizeof (emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, emf_file);
} else {
fwrite(&emr_selectobject_bgbrush, sizeof (emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_bgbrush, sizeof(emr_selectobject_t), 1, emf_file);
}
}
}
} else {
for (i = 0; i < circle_count; i++) {
fwrite(&circle[i], sizeof (emr_ellipse_t), 1, emf_file);
fwrite(&circle[i], sizeof(emr_ellipse_t), 1, emf_file);
}
}
// Text
if (string_count > 0) {
fwrite(&emr_selectobject_font, sizeof (emr_selectobject_t), 1, emf_file);
fwrite(&emr_settextcolor, sizeof (emr_settextcolor_t), 1, emf_file);
fwrite(&emr_selectobject_font, sizeof(emr_selectobject_t), 1, emf_file);
fwrite(&emr_settextcolor, sizeof(emr_settextcolor_t), 1, emf_file);
}
current_fsize = fsize;
@ -776,24 +777,24 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
for (i = 0; i < string_count; i++) {
if (text_fsizes[i] != current_fsize) {
current_fsize = text_fsizes[i];
fwrite(&emr_selectobject_font2, sizeof (emr_selectobject_t), 1, emf_file);
fwrite(&emr_selectobject_font2, sizeof(emr_selectobject_t), 1, emf_file);
}
if (text_haligns[i] != current_halign) {
current_halign = text_haligns[i];
if (current_halign == 0) {
fwrite(&emr_settextalign, sizeof (emr_settextalign_t), 1, emf_file);
fwrite(&emr_settextalign, sizeof(emr_settextalign_t), 1, emf_file);
} else if (current_halign == 1) {
fwrite(&emr_settextalign1, sizeof (emr_settextalign_t), 1, emf_file);
fwrite(&emr_settextalign1, sizeof(emr_settextalign_t), 1, emf_file);
} else {
fwrite(&emr_settextalign2, sizeof (emr_settextalign_t), 1, emf_file);
fwrite(&emr_settextalign2, sizeof(emr_settextalign_t), 1, emf_file);
}
}
fwrite(&text[i], sizeof (emr_exttextoutw_t), 1, emf_file);
fwrite(&text[i], sizeof(emr_exttextoutw_t), 1, emf_file);
fwrite(this_string[i], bump_up(text[i].w_emr_text.chars) * 2, 1, emf_file);
free(this_string[i]);
}
fwrite(&emr_eof, sizeof (emr_eof_t), 1, emf_file);
fwrite(&emr_eof, sizeof(emr_eof_t), 1, emf_file);
if (symbol->output_options & BARCODE_STDOUT) {
fflush(emf_file);

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,8 +31,8 @@
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include <math.h>
#ifdef _MSC_VER
@ -398,7 +398,7 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
RGBCur[0] = 0; RGBCur[1] = 0; RGBCur[2] = 0;
break;
default: /* error case - return */
strcpy(symbol->errtxt, "611: unknown pixel colour");
strcpy(symbol->errtxt, "612: unknown pixel colour");
return ZINT_ERROR_INVALID_DATA;
}
/* Search, if RGB value is already present */
@ -469,14 +469,14 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
if ((symbol->output_options & BARCODE_STDOUT) != 0) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "610: Can't open output file");
sprintf(symbol->errtxt, "610: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
#endif
gif_file = stdout;
} else {
if (!(gif_file = fopen(symbol->outfile, "wb"))) {
strcpy(symbol->errtxt, "611: Can't open output file");
sprintf(symbol->errtxt, "611: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -305,7 +305,7 @@ INTERNAL int imail(struct zint_symbol *symbol, unsigned char source[], int lengt
return ZINT_ERROR_INVALID_DATA;
}
zip_len = strlen(zip);
zip_len = (int) strlen(zip);
if (zip_len != 0 && zip_len != 5 && zip_len != 9 && zip_len != 11) {
strcpy(symbol->errtxt, "453: Invalid ZIP code");
return ZINT_ERROR_INVALID_DATA;
@ -342,7 +342,7 @@ INTERNAL int imail(struct zint_symbol *symbol, unsigned char source[], int lengt
/* and then the rest */
for (read = 2, len = strlen(tracker); read < len; read++) {
for (read = 2, len = (int) strlen(tracker); read < len; read++) {
large_mul_u64(&accum, 10);
large_add_u64(&accum, ctoi(tracker[read]));
@ -421,7 +421,7 @@ INTERNAL int imail(struct zint_symbol *symbol, unsigned char source[], int lengt
/* Translate 4-state data pattern to symbol */
read = 0;
for (i = 0, len = strlen(data_pattern); i < len; i++) {
for (i = 0, len = (int) strlen(data_pattern); i < len; i++) {
if ((data_pattern[i] == '1') || (data_pattern[i] == '0')) {
set_module(symbol, 0, read);
}

View file

@ -1539,7 +1539,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) {
unsigned char *buffer;
long fileLen;
size_t n;
int nRead = 0;
size_t nRead = 0;
int ret;
if (!symbol) return ZINT_ERROR_INVALID_DATA;
@ -1555,7 +1555,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) {
} else {
file = fopen(filename, "rb");
if (!file) {
sprintf(symbol->errtxt, "229: Unable to read input file (%.30s)", strerror(errno));
sprintf(symbol->errtxt, "229: Unable to read input file (%d: %.30s)", errno, strerror(errno));
return error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA);
}
file_opened = 1;
@ -1593,7 +1593,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) {
do {
n = fread(buffer + nRead, 1, fileLen - nRead, file);
if (ferror(file)) {
sprintf(symbol->errtxt, "241: Input file read error (%.30s)", strerror(errno));
sprintf(symbol->errtxt, "241: Input file read error (%d: %.30s)", errno, strerror(errno));
if (file_opened) {
fclose(file);
}
@ -1601,7 +1601,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) {
return error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA);
}
nRead += n;
} while (!feof(file) && (0 < n) && (nRead < fileLen));
} while (!feof(file) && (0 < n) && ((long) nRead < fileLen));
if (file_opened) {
fclose(file);

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,12 +31,12 @@
*/
/* vim: set ts=4 sw=4 et : */
/*
/*
* Developed in accordance with "Royal Mail Mailmark barcode C encoding and deconding instructions"
* (https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-C-encoding-and-decoding-instructions-Sept-2015.pdf)
* and "Royal Mail Mailmark barcode L encoding and decoding"
* (https://www.royalmail.com/sites/default/files/Mailmark-4-state-barcode-L-encoding-and-decoding-instructions-Sept-2015.pdf)
*
*
*/
#include <stdio.h>
@ -82,7 +82,7 @@ static const unsigned short extender_group_l[26] = {
static int verify_character(char input, char type) {
int val = 0;
switch (type) {
case 'F':
val = posn(SET_F, input);
@ -97,7 +97,7 @@ static int verify_character(char input, char type) {
val = posn(SET_S, input);
break;
}
if (val == -1) {
return 0;
} else {
@ -108,7 +108,7 @@ static int verify_character(char input, char type) {
static int verify_postcode(char* postcode, int type) {
int i;
char pattern[11];
strcpy(pattern, postcode_format[type - 1]);
for (i = 0; i < 9; i++) {
@ -122,13 +122,13 @@ static int verify_postcode(char* postcode, int type) {
/* Royal Mail Mailmark */
INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int length) {
char local_source[28];
int format;
int version_id;
int mail_class;
int supply_chain_id;
long item_id;
unsigned int item_id;
char postcode[10];
int postcode_type;
char pattern[10];
@ -138,39 +138,39 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
unsigned char data[26];
int data_top, data_step;
unsigned char check[7];
short int extender[27];
unsigned int extender[27];
char bar[80];
int check_count;
int i, j, len;
rs_t rs;
if (length > 26) {
strcpy(symbol->errtxt, "580: Input too long");
return ZINT_ERROR_TOO_LONG;
}
strcpy(local_source, (char*) source);
if (length < 22) {
for (i = length; i <= 22; i++) {
strcat(local_source, " ");
}
length = 22;
}
if ((length > 22) && (length < 26)) {
for (i = length; i <= 26; i++) {
strcat(local_source, " ");
}
length = 26;
}
}
to_upper((unsigned char*) local_source);
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Producing Mailmark %s\n", local_source);
}
if (is_sane(RUBIDIUM, (unsigned char *) local_source, length) != 0) {
strcpy(symbol->errtxt, "581: Invalid characters in input data");
return ZINT_ERROR_INVALID_DATA;
@ -182,21 +182,21 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
strcpy(symbol->errtxt, "582: Invalid format");
return ZINT_ERROR_INVALID_DATA;
}
// Version ID is in the range 1-4
version_id = ctoi(local_source[1]) - 1;
if ((version_id < 0) || (version_id > 3)) {
strcpy(symbol->errtxt, "583: Invalid Version ID");
return ZINT_ERROR_INVALID_DATA;
}
// Class is in the range 0-9,A-E
mail_class = ctoi(local_source[2]);
if ((mail_class < 0) || (mail_class > 14)) {
strcpy(symbol->errtxt, "584: Invalid Class");
return ZINT_ERROR_INVALID_DATA;
}
// Supply Chain ID is 2 digits for barcode C and 6 digits for barcode L
supply_chain_id = 0;
for (i = 3; i < (length - 17); i++) {
@ -208,28 +208,28 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
return ZINT_ERROR_INVALID_DATA;
}
}
// Item ID is 8 digits
item_id = 0;
for (i = length - 17; i < (length - 9); i++) {
if ((local_source[i] >= '0') && (local_source[i] <= '9')) {
item_id *= 10;
item_id += (long) ctoi(local_source[i]);
item_id += ctoi(local_source[i]);
} else {
strcpy(symbol->errtxt, "586: Invalid Item ID");
return ZINT_ERROR_INVALID_DATA;
}
}
// Separate Destination Post Code plus DPS field
for (i = 0; i < 9; i++) {
postcode[i] = local_source[(length - 9) + i];
}
postcode[9] = '\0';
// Detect postcode type
/* postcode_type is used to select which format of postcode
*
/* postcode_type is used to select which format of postcode
*
* 1 = FNFNLLNLS
* 2 = FFNNLLNLS
* 3 = FFNNNLLNL
@ -238,7 +238,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
* 6 = FNNNLLNLS
* 7 = International designation
*/
if (strcmp(postcode, "XY11 ") == 0) {
postcode_type = 7;
} else {
@ -266,7 +266,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
}
}
}
// Verify postcode type
if (postcode_type != 7) {
if (verify_postcode(postcode, postcode_type) != 0) {
@ -274,7 +274,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
return ZINT_ERROR_INVALID_DATA;
}
}
// Convert postcode to internal user field
large_load_u64(&destination_postcode, 0);
@ -330,7 +330,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
large_add(&destination_postcode, &b);
}
}
// Conversion from Internal User Fields to Consolidated Data Value
// Set CDV to 0
large_load_u64(&cdv, 0);
@ -344,7 +344,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
// Add Item ID
large_add_u64(&cdv, item_id);
if (length == 22) {
if (length == 22) {
// Barcode C - Multiply by 100
large_mul_u64(&cdv, 100);
} else {
@ -378,8 +378,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
printf("CDV: ");
large_print(&cdv);
}
if (length == 22) {
data_top = 15;
data_step = 8;
@ -389,27 +388,27 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
data_step = 10;
check_count = 7;
}
// Conversion from Consolidated Data Value to Data Numbers
for (j = data_top; j >= (data_step + 1); j--) {
data[j] = (unsigned char) large_div_u64(&cdv, 32);
}
for (j = data_step; j >= 0; j--) {
data[j] = (unsigned char) large_div_u64(&cdv, 30);
}
// Generation of Reed-Solomon Check Numbers
rs_init_gf(&rs, 0x25);
rs_init_code(&rs, check_count, 1);
rs_encode(&rs, (data_top + 1), data, check);
// Append check digits to data
for (i = 1; i <= check_count; i++) {
data[data_top + i] = check[check_count - i];
}
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Codewords: ");
for (i = 0; i <= data_top + check_count; i++) {
@ -417,7 +416,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
}
printf("\n");
}
// Conversion from Data Numbers and Check Numbers to Data Symbols and Check Symbols
for (i = 0; i <= data_step; i++) {
data[i] = data_symbol_even[data[i]];
@ -425,7 +424,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
for (i = data_step + 1; i <= (data_top + check_count); i++) {
data[i] = data_symbol_odd[data[i]];
}
// Conversion from Data Symbols and Check Symbols to Extender Groups
for (i = 0; i < length; i++) {
if (length == 22) {
@ -434,13 +433,13 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
extender[extender_group_l[i]] = data[i];
}
}
// Conversion from Extender Groups to Bar Identifiers
strcpy(bar, "");
for (i = 0; i < length; i++) {
for (j = 0; j < 3; j++) {
switch(extender[i] & 0x24) {
switch (extender[i] & 0x24) {
case 0x24:
strcat(bar, "F");
break;
@ -465,13 +464,13 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
extender[i] = extender[i] << 1;
}
}
bar[(length * 3)] = '\0';
if (symbol->debug & ZINT_DEBUG_PRINT) {
printf("Bar pattern: %s\n", bar);
}
/* Translate 4-state data pattern to symbol */
j = 0;
for (i = 0, len = (int) strlen(bar); i < len; i++) {
@ -491,6 +490,6 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
symbol->rows = 3;
symbol->width = j - 1;
return 0;
}

View file

@ -51,13 +51,13 @@ INTERNAL int output_check_colour_options(struct zint_symbol *symbol) {
to_upper((unsigned char *) symbol->fgcolour);
to_upper((unsigned char *) symbol->bgcolour);
error_number = is_sane(SSET, (unsigned char *) symbol->fgcolour, strlen(symbol->fgcolour));
error_number = is_sane(SSET, (unsigned char *) symbol->fgcolour, (int) strlen(symbol->fgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "653: Malformed foreground colour target");
return ZINT_ERROR_INVALID_OPTION;
}
error_number = is_sane(SSET, (unsigned char *) symbol->bgcolour, strlen(symbol->bgcolour));
error_number = is_sane(SSET, (unsigned char *) symbol->bgcolour, (int) strlen(symbol->bgcolour));
if (error_number == ZINT_ERROR_INVALID_DATA) {
strcpy(symbol->errtxt, "654: Malformed background colour target");
return ZINT_ERROR_INVALID_OPTION;
@ -432,7 +432,7 @@ INTERNAL int output_process_upcean(struct zint_symbol *symbol, int *p_main_width
int comp_offset; /* Whitespace offset (if any) of main linear symbol due to having composite */
int upceanflag; /* UPC/EAN type flag */
int i, j, latch;
int text_length = ustrlen(symbol->text);
int text_length = (int) ustrlen(symbol->text);
latch = 0;
j = 0;

View file

@ -3,7 +3,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -32,8 +32,8 @@
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "common.h"
#include "pcx.h" /* PCX header structure */
#include <math.h>
@ -52,7 +52,7 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
int bytes_per_line = symbol->bitmap_width + (symbol->bitmap_width & 1); // Must be even
unsigned char previous;
#ifdef _MSC_VER
unsigned char* rle_row;
unsigned char *rle_row;
#endif
#ifndef _MSC_VER
@ -70,7 +70,6 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
header.manufacturer = 10; // ZSoft
header.version = 5; // Version 3.0
header.encoding = 1; // Run length encoding
@ -103,26 +102,26 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
if (symbol->output_options & BARCODE_STDOUT) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "620: Can't open output file");
sprintf(symbol->errtxt, "620: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
#endif
pcx_file = stdout;
} else {
if (!(pcx_file = fopen(symbol->outfile, "wb"))) {
strcpy(symbol->errtxt, "621: Can't open output file");
sprintf(symbol->errtxt, "621: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
fwrite(&header, sizeof (pcx_header_t), 1, pcx_file);
fwrite(&header, sizeof(pcx_header_t), 1, pcx_file);
for (row = 0; row < symbol->bitmap_height; row++) {
for (colour = 0; colour < 3; colour++) {
for (column = 0; column < symbol->bitmap_width; column++) {
switch (colour) {
case 0:
switch(pixelbuf[(row * symbol->bitmap_width) + column]) {
switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White
case 'M': // Magenta
case 'R': // Red
@ -144,7 +143,7 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
}
break;
case 1:
switch(pixelbuf[(row * symbol->bitmap_width) + column]) {
switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White
case 'C': // Cyan
case 'Y': // Yellow
@ -166,7 +165,7 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
}
break;
case 2:
switch(pixelbuf[(row * symbol->bitmap_width) + column]) {
switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White
case 'C': // Cyan
case 'B': // Blue

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -44,8 +44,8 @@ static const char *PlessTable[16] = {
};
static const char *MSITable[10] = {
"12121212", "12121221", "12122112", "12122121", "12211212", "12211221",
"12212112", "12212121", "21121212", "21121221"
"12121212", "12121221", "12122112", "12122121", "12211212",
"12211221", "12212112", "12212121", "21121212", "21121221"
};
/* Not MSI/Plessey but the older Plessey standard */
@ -54,7 +54,7 @@ INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int len
int i;
unsigned char *checkptr;
static const char grid[9] = {1, 1, 1, 1, 0, 1, 0, 0, 1};
char dest[1024]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 ~ 1024 */
char dest[554]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 = 554 */
int error_number;
if (length > 65) {
@ -105,56 +105,71 @@ INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int len
strcat(dest, "331311313");
expand(symbol, dest);
ustrcpy(symbol->text, source);
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
free(checkptr);
return error_number;
}
/* Modulo 10 check digit - Luhn algorithm
See https://en.wikipedia.org/wiki/Luhn_algorithm */
static char msi_check_digit_mod10(const unsigned char source[], const int length) {
static const int vals[2][10] = {
{ 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 }, /* Doubled and digits summed */
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, /* Single */
};
int i, x = 0, undoubled = 0;
for (i = length - 1; i >= 0; i--) {
x += vals[undoubled][ctoi(source[i])];
if (x > 32767 - 20) {
x %= 10; /* Prevent overflow */
}
undoubled = !undoubled;
}
return itoc((10 - x % 10) % 10);
}
/* Modulo 11 check digit - IBM weight system wrap = 7, NCR system wrap = 9
See https://en.wikipedia.org/wiki/MSI_Barcode */
static char msi_check_digit_mod11(const unsigned char source[], const int length, const int wrap) {
int i, x = 0, weight = 2;
for (i = length - 1; i >= 0; i--) {
x += weight * ctoi(source[i]);
if (x > 32767 - 200) {
x %= 11; /* Prevent overflow */
}
weight++;
if (weight > wrap) {
weight = 2;
}
}
return itoc((11 - x % 11) % 11); /* Will return 'A' for 10 */
}
/* Plain MSI Plessey - does not calculate any check character */
static int msi_plessey(struct zint_symbol *symbol, unsigned char source[], const int length) {
static void msi_plessey(struct zint_symbol *symbol, const unsigned char source[], const int length, char dest[]) {
int i;
char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */
if (length > 55) {
strcpy(symbol->errtxt, "372: Input too long");
return ZINT_ERROR_TOO_LONG;
}
/* start character */
strcpy(dest, "21");
for (i = 0; i < length; i++) {
lookup(NEON, MSITable, source[i], dest);
}
/* Stop character */
strcat(dest, "121");
expand(symbol, dest);
ustrcpy(symbol->text, source);
return 0;
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
}
/* MSI Plessey with Modulo 10 check digit - algorithm from Barcode Island
* http://www.barcodeisland.com/ */
static int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, wright, pump, n;
unsigned long dau, pedwar;
char un[32], tri[32];
int error_number, h;
char dest[1000];
error_number = 0;
if (length > 18) {
strcpy(symbol->errtxt, "373: Input too long");
return ZINT_ERROR_TOO_LONG;
}
/* start character */
strcpy(dest, "21");
/* MSI Plessey with Modulo 10 check digit */
static void msi_plessey_mod10(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int no_checktext, char dest[]) {
int i;
char check_digit;
/* draw data section */
for (i = 0; i < length; i++) {
@ -162,310 +177,122 @@ static int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[],
}
/* calculate check digit */
wright = 0;
n = !(length & 1);
for (i = n; i < length; i += 2) {
un[wright++] = source[i];
}
un[wright] = '\0';
dau = strtoul(un, NULL, 10);
dau *= 2;
sprintf(tri, "%lu", dau);
pedwar = 0;
h = (int) strlen(tri);
for (i = 0; i < h; i++) {
pedwar += ctoi(tri[i]);
}
n = length & 1;
for (i = n; i < length; i += 2) {
pedwar += ctoi(source[i]);
}
pump = (10 - pedwar % 10);
if (pump == 10) {
pump = 0;
}
check_digit = msi_check_digit_mod10(source, length);
/* draw check digit */
lookup(NEON, MSITable, itoc(pump), dest);
lookup(NEON, MSITable, check_digit, dest);
/* Stop character */
strcat(dest, "121");
expand(symbol, dest);
ustrcpy(symbol->text, source);
symbol->text[length] = itoc(pump);
symbol->text[length + 1] = '\0';
return error_number;
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
if (!no_checktext) {
symbol->text[length] = check_digit;
symbol->text[length + 1] = '\0';
}
}
/* MSI Plessey with two Modulo 10 check digits - algorithm from
* Barcode Island http://www.barcodeisland.com/ */
static int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], const int src_len) {
/* MSI Plessey with two Modulo 10 check digits */
static void msi_plessey_mod1010(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int no_checktext, char dest[]) {
int i, n, wright, pump;
unsigned long dau, pedwar, chwech;
char un[32], tri[32];
int error_number, h;
char dest[1000];
int i;
unsigned char temp[65 + 2 + 1];
error_number = 0;
if (src_len > 18) {
/* No Entry Stack Smashers! limit because of str->number conversion*/
strcpy(symbol->errtxt, "374: Input too long");
return ZINT_ERROR_TOO_LONG;
}
/* start character */
strcpy(dest, "21");
/* Append check digits */
temp[0] = '\0';
ustrncat(temp, source, length);
temp[length] = msi_check_digit_mod10(source, length);
temp[length + 1] = msi_check_digit_mod10(temp, length + 1);
temp[length + 2] = '\0';
/* draw data section */
for (i = 0; i < src_len; i++) {
for (i = 0; i < length + 2; i++) {
lookup(NEON, MSITable, temp[i], dest);
}
if (no_checktext) {
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
} else {
ustrcpy(symbol->text, temp);
}
}
/* MSI Plessey with Modulo 11 check digit */
static void msi_plessey_mod11(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int no_checktext, const int wrap, char dest[]) {
/* Uses the IBM weight system if wrap = 7, and the NCR system if wrap = 9 */
int i;
char check_digit;
/* draw data section */
for (i = 0; i < length; i++) {
lookup(NEON, MSITable, source[i], dest);
}
/* calculate first check digit */
wright = 0;
n = !(src_len & 1);
for (i = n; i < src_len; i += 2) {
un[wright++] = source[i];
}
un[wright] = '\0';
dau = strtoul(un, NULL, 10);
dau *= 2;
sprintf(tri, "%lu", dau);
pedwar = 0;
h = (int) strlen(tri);
for (i = 0; i < h; i++) {
pedwar += ctoi(tri[i]);
}
n = src_len & 1;
for (i = n; i < src_len; i += 2) {
pedwar += ctoi(source[i]);
}
pump = 10 - pedwar % 10;
if (pump == 10) {
pump = 0;
}
/* calculate second check digit */
wright = 0;
n = src_len & 1;
for (i = n; i < src_len; i += 2) {
un[wright++] = source[i];
}
un[wright++] = itoc(pump);
un[wright] = '\0';
dau = strtoul(un, NULL, 10);
dau *= 2;
sprintf(tri, "%lu", dau);
pedwar = 0;
h = (int) strlen(tri);
for (i = 0; i < h; i++) {
pedwar += ctoi(tri[i]);
}
i = !(src_len & 1);
for (; i < src_len; i += 2) {
pedwar += ctoi(source[i]);
}
chwech = 10 - pedwar % 10;
if (chwech == 10) {
chwech = 0;
}
/* Draw check digits */
lookup(NEON, MSITable, itoc(pump), dest);
lookup(NEON, MSITable, itoc(chwech), dest);
/* Stop character */
strcat(dest, "121");
expand(symbol, dest);
ustrcpy(symbol->text, source);
symbol->text[src_len] = itoc(pump);
symbol->text[src_len + 1] = itoc(chwech);
symbol->text[src_len + 2] = '\0';
return error_number;
}
/* Calculate a Modulo 11 check digit using the system discussed on Wikipedia -
see http://en.wikipedia.org/wiki/Talk:MSI_Barcode */
static int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const int src_len) {
/* uses the IBM weight system */
int i, weight, check;
unsigned long x;
int error_number;
char dest[1000];
error_number = 0;
if (src_len > 55) {
strcpy(symbol->errtxt, "375: Input too long");
return ZINT_ERROR_TOO_LONG;
}
/* start character */
strcpy(dest, "21");
/* draw data section */
for (i = 0; i < src_len; i++) {
lookup(NEON, MSITable, source[i], dest);
}
/* calculate check digit */
x = 0;
weight = 2;
for (i = src_len - 1; i >= 0; i--) {
x += (long) (weight * ctoi(source[i]));
weight++;
if (weight > 7) {
weight = 2;
}
}
check = (11 - (x % 11)) % 11;
if (check == 10) {
/* Append check digit */
check_digit = msi_check_digit_mod11(source, length, wrap);
if (check_digit == 'A') {
lookup(NEON, MSITable, '1', dest);
lookup(NEON, MSITable, '0', dest);
} else {
lookup(NEON, MSITable, itoc(check), dest);
lookup(NEON, MSITable, check_digit, dest);
}
/* stop character */
strcat(dest, "121");
expand(symbol, dest);
ustrcpy(symbol->text, source);
if (check == 10) {
strcat((char*) symbol->text, "10");
} else {
symbol->text[src_len] = itoc(check);
symbol->text[src_len + 1] = '\0';
}
return error_number;
}
/* Combining the Barcode Island and Wikipedia code
* Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */
static int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], const int src_len) {
/* Weighted using the IBM system */
int i, weight, check, wright, pump;
unsigned long x, dau, pedwar;
int h;
int si;
char un[32], tri[32];
int error_number;
char dest[1000];
unsigned char temp[32];
int temp_len;
error_number = 0;
if (src_len > 18) {
strcpy(symbol->errtxt, "376: Input too long");
return ZINT_ERROR_TOO_LONG;
}
/* start character */
strcpy(dest, "21");
/* draw data section */
for (i = 0; i < src_len; i++) {
lookup(NEON, MSITable, source[i], dest);
}
/* calculate first (mod 11) digit */
x = 0;
weight = 2;
for (si = src_len - 1; si >= 0; si--) {
x += (long) (weight * ctoi(source[si]));
weight++;
if (weight > 7) {
weight = 2;
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
if (!no_checktext) {
if (check_digit == 'A') {
ustrcat(symbol->text, "10");
} else {
symbol->text[length] = check_digit;
symbol->text[length + 1] = '\0';
}
}
}
check = (11 - (x % 11)) % 11;
ustrcpy(temp, source);
temp_len = src_len;
if (check == 10) {
lookup(NEON, MSITable, '1', dest);
lookup(NEON, MSITable, '0', dest);
strcat((char*) temp, "10");
temp_len += 2;
/* MSI Plessey with Modulo 11 check digit and Modulo 10 check digit */
static void msi_plessey_mod1110(struct zint_symbol *symbol, const unsigned char source[], const int length,
const int no_checktext, const int wrap, char dest[]) {
/* Uses the IBM weight system if wrap = 7, and the NCR system if wrap = 9 */
int i;
char check_digit;
unsigned char temp[65 + 3 + 1];
int temp_len = length;
temp[0] = '\0';
ustrncat(temp, source, length);
/* Append first (mod 11) digit */
check_digit = msi_check_digit_mod11(source, length, wrap);
if (check_digit == 'A') {
temp[temp_len++] = '1';
temp[temp_len++] = '0';
} else {
lookup(NEON, MSITable, itoc(check), dest);
temp[temp_len++] = itoc(check);
temp[temp_len] = '\0';
temp[temp_len++] = check_digit;
}
/* calculate second (mod 10) check digit */
wright = 0;
i = !(temp_len & 1);
for (; i < temp_len; i += 2) {
un[wright++] = temp[i];
}
un[wright] = '\0';
/* Append second (mod 10) check digit */
temp[temp_len] = msi_check_digit_mod10(temp, temp_len);
temp[++temp_len] = '\0';
dau = strtoul(un, NULL, 10);
dau *= 2;
sprintf(tri, "%lu", dau);
pedwar = 0;
h = (int) strlen(tri);
for (i = 0; i < h; i++) {
pedwar += ctoi(tri[i]);
/* draw data section */
for (i = 0; i < temp_len; i++) {
lookup(NEON, MSITable, temp[i], dest);
}
i = temp_len & 1;
for (; i < temp_len; i += 2) {
pedwar += ctoi(temp[i]);
if (no_checktext) {
symbol->text[0] = '\0';
ustrncat(symbol->text, source, length);
} else {
ustrcpy(symbol->text, temp);
}
pump = 10 - pedwar % 10;
if (pump == 10) {
pump = 0;
}
/* draw check digit */
lookup(NEON, MSITable, itoc(pump), dest);
/* stop character */
strcat(dest, "121");
expand(symbol, dest);
temp[temp_len++] = itoc(pump);
temp[temp_len] = '\0';
ustrcpy(symbol->text, temp);
return error_number;
}
INTERNAL int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) {
int error_number;
char dest[550]; /* 2 + 65 * 8 + 3 * 8 + 3 + 1 = 550 */
int check_option = symbol->option_2;
int no_checktext = 0;
error_number = is_sane(NEON, source, length);
if (error_number != 0) {
@ -473,23 +300,43 @@ INTERNAL int msi_handle(struct zint_symbol *symbol, unsigned char source[], int
return ZINT_ERROR_INVALID_DATA;
}
if ((symbol->option_2 < 0) || (symbol->option_2 > 4)) {
symbol->option_2 = 0;
if (length > 65) {
strcpy(symbol->errtxt, "372: Input too long");
return ZINT_ERROR_TOO_LONG;
}
switch (symbol->option_2) {
case 0: error_number = msi_plessey(symbol, source, length);
if (check_option >= 11 && check_option <= 16) { /* +10 means don't print check digits in HRT */
check_option -= 10;
no_checktext = 1;
}
if ((check_option < 0) || (check_option > 6)) {
check_option = 0;
}
/* Start character */
strcpy(dest, "21");
switch (check_option) {
case 0: msi_plessey(symbol, source, length, dest);
break;
case 1: error_number = msi_plessey_mod10(symbol, source, length);
case 1: msi_plessey_mod10(symbol, source, length, no_checktext, dest);
break;
case 2: error_number = msi_plessey_mod1010(symbol, source, length);
case 2: msi_plessey_mod1010(symbol, source, length, no_checktext, dest);
break;
case 3: error_number = msi_plessey_mod11(symbol, source, length);
case 3: msi_plessey_mod11(symbol, source, length, no_checktext, 7 /*IBM wrap*/, dest);
break;
case 4: error_number = msi_plessey_mod1110(symbol, source, length);
case 4: msi_plessey_mod1110(symbol, source, length, no_checktext, 7 /*IBM wrap*/, dest);
break;
case 5: msi_plessey_mod11(symbol, source, length, no_checktext, 9 /*NCR wrap*/, dest);
break;
case 6: msi_plessey_mod1110(symbol, source, length, no_checktext, 9 /*NCR wrap*/, dest);
break;
}
/* Stop character */
strcat(dest, "121");
expand(symbol, dest);
return error_number;
}

View file

@ -31,6 +31,9 @@
*/
/* vim: set ts=4 sw=4 et : */
#ifndef NO_PNG
#include <errno.h>
#include <stdio.h>
#ifdef _MSC_VER
#include <fcntl.h>
@ -39,7 +42,6 @@
#endif
#include "common.h"
#ifndef NO_PNG
#include <png.h>
#include <zlib.h>
#include <setjmp.h>
@ -233,14 +235,14 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
if (symbol->output_options & BARCODE_STDOUT) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "631: Can't open output file");
sprintf(symbol->errtxt, "631: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
#endif
graphic->outfile = stdout;
} else {
if (!(graphic->outfile = fopen(symbol->outfile, "wb"))) {
strcpy(symbol->errtxt, "632: Can't open output file");
sprintf(symbol->errtxt, "632: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
}
@ -343,4 +345,7 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
return 0;
}
#else
/* https://stackoverflow.com/a/26541331/664741 Suppresses gcc warning ISO C forbids an empty translation unit */
typedef int make_iso_compilers_happy;
#endif /* NO_PNG */

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2008 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com>
Including bug fixes by Bryan Hatton
Redistribution and use in source and binary forms, with or without
@ -129,7 +129,7 @@ INTERNAL int post_plot(struct zint_symbol *symbol, unsigned char source[], int l
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if (height_pattern[loopey] == 'L') {
set_module(symbol, 0, writer);
@ -191,7 +191,7 @@ INTERNAL int planet_plot(struct zint_symbol *symbol, unsigned char source[], int
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if (height_pattern[loopey] == 'L') {
set_module(symbol, 0, writer);
@ -342,7 +342,7 @@ INTERNAL int royal_plot(struct zint_symbol *symbol, unsigned char source[], int
/*check = */rm4scc(source, height_pattern, length);
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
set_module(symbol, 0, writer);
@ -392,7 +392,7 @@ INTERNAL int kix_code(struct zint_symbol *symbol, unsigned char source[], int le
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
set_module(symbol, 0, writer);
@ -448,7 +448,7 @@ INTERNAL int daft_code(struct zint_symbol *symbol, unsigned char source[], int l
}
writer = 0;
h = strlen(height_pattern);
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
set_module(symbol, 0, writer);
@ -577,7 +577,7 @@ INTERNAL int japan_post(struct zint_symbol *symbol, unsigned char source[], int
/* Resolve pattern to 4-state symbols */
writer = 0;
h = strlen(pattern);
h = (int) strlen(pattern);
for (loopey = 0; loopey < h; loopey++) {
if ((pattern[loopey] == '2') || (pattern[loopey] == '1')) {
set_module(symbol, 0, writer);

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009-2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,6 +31,7 @@
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <math.h>
@ -43,7 +44,7 @@ static void colour_to_pscolor(int option, int colour, char* output) {
strcpy(output, "");
if ((option & CMYK_COLOUR) == 0) {
// Use RGB colour space
switch(colour) {
switch (colour) {
case 1: // Cyan
strcat(output, "0.00 1.00 1.00");
break;
@ -72,7 +73,7 @@ static void colour_to_pscolor(int option, int colour, char* output) {
strcat(output, " setrgbcolor");
} else {
// Use CMYK colour space
switch(colour) {
switch (colour) {
case 1: // Cyan
strcat(output, "1.00 0.00 0.00 0.00");
break;
@ -169,7 +170,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
feps = fopen(symbol->outfile, "w");
}
if (feps == NULL) {
strcpy(symbol->errtxt, "645: Could not open output file");
sprintf(symbol->errtxt, "645: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
@ -260,13 +261,15 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
/* Start writing the header */
fprintf(feps, "%%!PS-Adobe-3.0 EPSF-3.0\n");
if (ZINT_VERSION_BUILD) {
fprintf(feps, "%%%%Creator: Zint %d.%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD);
fprintf(feps, "%%%%Creator: Zint %d.%d.%d.%d\n",
ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD);
} else {
fprintf(feps, "%%%%Creator: Zint %d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE);
}
fprintf(feps, "%%%%Title: Zint Generated Symbol\n");
fprintf(feps, "%%%%Pages: 0\n");
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", (int) ceil(symbol->vector->width), (int) ceil(symbol->vector->height));
fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n",
(int) ceil(symbol->vector->width), (int) ceil(symbol->vector->height));
fprintf(feps, "%%%%EndComments\n");
/* Definitions */
@ -314,7 +317,8 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
fprintf(feps, "%s\n", ps_color);
}
colour_rect_counter++;
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n",
rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "TE\n");
}
rect = rect->next;
@ -323,7 +327,8 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
} else {
rect = symbol->vector->rectangles;
while (rect) {
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n", rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "%.2f %.2f TB %.2f %.2f TR\n",
rect->height, (symbol->vector->height - rect->y) - rect->height, rect->x, rect->width);
fprintf(feps, "TE\n");
rect = rect->next;
}
@ -366,7 +371,8 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
ex = hex->x + half_radius;
fx = hex->x - half_radius;
}
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TH\n", ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy);
fprintf(feps, "%.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f TH\n",
ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy);
hex = hex->next;
}
@ -383,7 +389,8 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
} else {
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_paper, magenta_paper, yellow_paper, black_paper);
fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n",
cyan_paper, magenta_paper, yellow_paper, black_paper);
}
fprintf(feps, "%.2f %.2f %.2f TD\n", circle->x, (symbol->vector->height - circle->y), radius);
if (circle->next) {
@ -405,12 +412,14 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
string = symbol->vector->strings;
if (string) {
if ((symbol->output_options & BOLD_TEXT) && (!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT))) {
if ((symbol->output_options & BOLD_TEXT)
&& (!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT))) {
font = "Helvetica-Bold";
} else {
font = "Helvetica";
}
if (iso_latin1) { /* Change encoding to ISO 8859-1, see Postscript Language Reference Manual 2nd Edition Example 5.6 */
if (iso_latin1) {
/* Change encoding to ISO 8859-1, see Postscript Language Reference Manual 2nd Edition Example 5.6 */
fprintf(feps, "/%s findfont\n", font);
fprintf(feps, "dup length dict begin\n");
fprintf(feps, "{1 index /FID ne {def} {pop pop} ifelse} forall\n");
@ -425,7 +434,8 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
fprintf(feps, "matrix currentmatrix\n");
fprintf(feps, "/%s findfont\n", font);
fprintf(feps, "%.2f scalefont setfont\n", string->fsize);
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n", string->x, (symbol->vector->height - string->y));
fprintf(feps, " 0 0 moveto %.2f %.2f translate 0.00 rotate 0 0 moveto\n",
string->x, (symbol->vector->height - string->y));
if (string->halign == 0 || string->halign == 2) { /* Need width for middle or right align */
fprintf(feps, " (%s) stringwidth\n", ps_string);
}

View file

@ -2175,7 +2175,7 @@ static void micro_populate_grid(unsigned char *grid, const int size, const char
int n, i;
int y;
n = strlen(full_stream);
n = (int) strlen(full_stream);
y = size - 1;
i = 0;
do {

View file

@ -39,16 +39,6 @@
#include <malloc.h>
#include <fcntl.h>
#include <io.h>
/* ceilf, floorf, roundf not before MSVC++2013 (C++ 12.0) */
#if _MSC_VER < 1800
#define ceilf (float) ceil
#define floorf (float) floor
#define roundf(arg) (float) floor((arg) + 0.5f)
#endif
/* For Visual C++ 6 suppress conversion from int to float warning */
#if _MSC_VER == 1200
#pragma warning(disable: 4244)
#endif
#endif /* _MSC_VER */
#include "common.h"
@ -438,7 +428,7 @@ static void draw_string(unsigned char *pixbuf, const unsigned char input_string[
}
letter_width += letter_gap;
string_length = ustrlen(input_string);
string_length = (int) ustrlen(input_string);
string_left_hand = xposn - ((letter_width * string_length - letter_gap) * half_si) / 2;
if (odd_si) {
@ -872,7 +862,7 @@ static int plot_raster_dotty(struct zint_symbol *symbol, const int rotate_angle,
static void to_iso8859_1(const unsigned char source[], unsigned char preprocessed[]) {
int j, i, input_length;
input_length = ustrlen(source);
input_length = (int) ustrlen(source);
j = 0;
i = 0;

View file

@ -2,7 +2,7 @@
/*
libzint - the open source barcode library
Copyright (C) 2009 - 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -31,8 +31,8 @@
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <locale.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#ifdef _MSC_VER
@ -42,7 +42,7 @@
#include "common.h"
static void pick_colour(int colour, char colour_code[]) {
switch(colour) {
switch (colour) {
case 1: // Cyan
strcpy(colour_code, "00ffff");
break;
@ -70,16 +70,17 @@ static void pick_colour(int colour, char colour_code[]) {
}
}
static void make_html_friendly(unsigned char * string, char * html_version) {
static void make_html_friendly(unsigned char *string, char *html_version) {
/* Converts text to use HTML entity codes */
int i, html_pos;
int i, len, html_pos;
html_pos = 0;
html_version[html_pos] = '\0';
len = (int) ustrlen(string);
for (i = 0; i < (int) ustrlen(string); i++) {
switch(string[i]) {
for (i = 0; i < len; i++) {
switch (string[i]) {
case '>':
strcat(html_version, "&gt;");
html_pos += 4;
@ -136,10 +137,10 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
struct zint_vector_string *string;
char colour_code[7];
int html_len;
int len, html_len;
#ifdef _MSC_VER
char* html_string;
char *html_string;
#endif
for (i = 0; i < 6; i++) {
@ -148,7 +149,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
}
fgcolour_string[6] = '\0';
bgcolour_string[6] = '\0';
if (strlen(symbol->fgcolour) > 6) {
fg_alpha = (16 * ctoi(symbol->fgcolour[6])) + ctoi(symbol->fgcolour[7]);
if (fg_alpha != 0xff) {
@ -161,11 +162,12 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
bg_alpha_opacity = (float) (bg_alpha / 255.0);
}
}
html_len = strlen((char *)symbol->text) + 1;
for (i = 0; i < (int) strlen((char *)symbol->text); i++) {
switch(symbol->text[i]) {
len = (int) ustrlen(symbol->text);
html_len = len + 1;
for (i = 0; i < len; i++) {
switch (symbol->text[i]) {
case '>':
case '<':
case '"':
@ -179,7 +181,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
#ifndef _MSC_VER
char html_string[html_len];
#else
html_string = (char*) _alloca(html_len);
html_string = (char *) _alloca(html_len);
#endif
/* Check for no created vector set */
@ -193,7 +195,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
fsvg = fopen(symbol->outfile, "w");
}
if (fsvg == NULL) {
strcpy(symbol->errtxt, "680: Could not open output file");
sprintf(symbol->errtxt, "680: Could not open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
@ -203,14 +205,16 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
fprintf(fsvg, "<?xml version=\"1.0\" standalone=\"no\"?>\n");
fprintf(fsvg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
fprintf(fsvg, " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
fprintf(fsvg, "<svg width=\"%d\" height=\"%d\" version=\"1.1\"\n", (int) ceil(symbol->vector->width), (int) ceil(symbol->vector->height));
fprintf(fsvg, "<svg width=\"%d\" height=\"%d\" version=\"1.1\"\n",
(int) ceil(symbol->vector->width), (int) ceil(symbol->vector->height));
fprintf(fsvg, " xmlns=\"http://www.w3.org/2000/svg\">\n");
fprintf(fsvg, " <desc>Zint Generated Symbol\n");
fprintf(fsvg, " </desc>\n");
fprintf(fsvg, "\n <g id=\"barcode\" fill=\"#%s\">\n", fgcolour_string);
if (bg_alpha != 0) {
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\"", (int) ceil(symbol->vector->width), (int) ceil(symbol->vector->height), bgcolour_string);
fprintf(fsvg, " <rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" fill=\"#%s\"",
(int) ceil(symbol->vector->width), (int) ceil(symbol->vector->height), bgcolour_string);
if (bg_alpha != 0xff) {
fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity);
}
@ -219,7 +223,8 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
rect = symbol->vector->rectangles;
while (rect) {
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\"", rect->x, rect->y, rect->width, rect->height);
fprintf(fsvg, " <rect x=\"%.2f\" y=\"%.2f\" width=\"%.2f\" height=\"%.2f\"",
rect->x, rect->y, rect->width, rect->height);
if (rect->colour != -1) {
pick_colour(rect->colour, colour_code);
fprintf(fsvg, " fill=\"#%s\"", colour_code);
@ -267,7 +272,8 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
ex = hex->x + half_radius;
fx = hex->x - half_radius;
}
fprintf(fsvg, " <path d=\"M %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f Z\"", ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy);
fprintf(fsvg, " <path d=\"M %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f L %.2f %.2f Z\"",
ax, ay, bx, by, cx, cy, dx, dy, ex, ey, fx, fy);
if (fg_alpha != 0xff) {
fprintf(fsvg, " opacity=\"%.3f\"", fg_alpha_opacity);
}
@ -283,7 +289,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
radius = (float) (0.5 * previous_diameter);
}
fprintf(fsvg, " <circle cx=\"%.2f\" cy=\"%.2f\" r=\"%.2f\"", circle->x, circle->y, radius);
if (circle->colour) {
fprintf(fsvg, " fill=\"#%s\"", bgcolour_string);
if (bg_alpha != 0xff) {
@ -299,7 +305,8 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
circle = circle->next;
}
bold = (symbol->output_options & BOLD_TEXT) && (!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT));
bold = (symbol->output_options & BOLD_TEXT)
&& (!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT));
string = symbol->vector->strings;
while (string) {
const char *halign = string->halign == 2 ? "end" : string->halign == 1 ? "start" : "middle";

View file

@ -1,4 +1,4 @@
# Copyright (C) 2019 - 2021 Robin Stuart <rstuart114@gmail.com>
# Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com>
# Adapted from qrencode/tests/CMakeLists.txt
# Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
# vim: set ts=4 sw=4 et :
@ -22,6 +22,7 @@ if(NOT EXISTS ${BWIPP_PS})
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf ${BWIPP_TAR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tools)
endif()
configure_file(${BWIPP_PS} ${CMAKE_CURRENT_BINARY_DIR}/tools/bwipp_dump.ps COPYONLY)
set(testcommon_SRCS testcommon.c testcommon.h)

View file

@ -1,7 +1,7 @@
Zint backend test suite
-----------------------
In order to build the zint testsuite, zint has to be compiled with the
In order to build the zint test suite, zint has to be compiled with the
ZINT_TEST option enabled:
cd <project-dir>
@ -12,50 +12,53 @@ ZINT_TEST option enabled:
------------------------------------------------------------------------------
In order to run the testsuite, the path of the zint library needs to be
communicated to the runtime linker. On UNIX like systems, this is done
by exporting LD_LIBRARY_PATH to the path containing the zint library,
which is <build-dir>/backend:
In order to run the test suite, the path of the zint library may need to be
communicated to the runtime linker. On UNIX-like systems, this is done by
exporting LD_LIBRARY_PATH to the path containing the zint library, which is
<build-dir>/backend:
cd <project-dir>
cd build
export LD_LIBRARY_PATH=$(pwd)/backend
Setting LD_LIBRARY_PATH is not required if the zint library to be tested is
installed into a system library path ( /usr/lib for example ) prior to running
the tests.
To run all tests (within <build-dir>/backend/tests):
To run all tests (within <build-dir>):
ctest
To run individual tests, eg:
For various useful options, e.g. matching (-R) and excluding (-E) tests, see
https://cmake.org/cmake/help/latest/manual/ctest.1.html#options
./test_common
./test_vector
Tests can also be run individually, eg:
backend/tests/test_common
backend/tests/test_vector
To run a single test function within an individual test, use '-f <func-name>':
./test_common -f utf8_to_unicode
./test_dotcode -f input
backend/tests/test_common -f utf8_to_unicode
backend/tests/test_dotcode -f input
To run a single dataset item in a single test function, use '-i <index>':
./test_dotcode -f input -i 2
backend/tests/test_dotcode -f input -i 2
To show debug info (if any), use '-d <flag>':
./test_dotcode -f input -i 2 -d 1
backend/tests/test_dotcode -f input -i 2 -d 1
(for other flags see <project-dir>/backend/tests/testcommon.h)
To generate test data, use '-g':
./test_dotcode -f encode -g
backend/tests/test_dotcode -f encode -g
To run a test against BWIPP (if any), use '-d 128':
./test_composite -d 128
backend/tests/test_composite -d 128
(see also <project-dir>/backend/tests/tools/run_bwipp_tests.sh)
@ -64,13 +67,13 @@ To run a test against BWIPP (if any), use '-d 128':
If the zint library was built with static linkage support, i.e. ZINT_STATIC
is ON, an additional test executable, which uses the zint-static library, will
be built. The static variant of each test shares the test name, but has a
"-static" suffix. For example,
"-static" suffix. For example,
./test_dotcode
backend/tests/test_dotcode
would run the dotcode test that uses the shared zint library, while
./test_dotcode-static
backend/tests/test_dotcode-static
runs the same test built against the zint-static library.

View file

@ -116,7 +116,7 @@ static void test_big5_utf8(int index) {
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { "_", -1, 0, 1, { 0xA1C4 }, "" },
/* 1*/ { "", -1, ZINT_ERROR_INVALID_DATA, -1, {}, "" },
/* 1*/ { "", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" },
};
int data_size = sizeof(data) / sizeof(struct item);
@ -135,7 +135,7 @@ static void test_big5_utf8(int index) {
assert_equal(ret, data[i].ret, "i:%d ret %d != %d (%s)\n", i, ret, data[i].ret, symbol.errtxt);
if (ret == 0) {
assert_equal(ret_length, data[i].ret_length, "i:%d ret_length %d != %d\n", i, ret_length, data[i].ret_length);
for (int j = 0; j < (int) ret_length; j++) {
for (int j = 0; j < ret_length; j++) {
assert_equal(b5data[j], data[i].expected_b5data[j], "i:%d b5data[%d] %04X != %04X\n", i, j, b5data[j], data[i].expected_b5data[j]);
}
}

View file

@ -142,8 +142,8 @@ static void test_print(int index, int generate, int debug) {
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
}

View file

@ -780,8 +780,9 @@ static void test_utf8_to_eci_ucs2be(void) {
int length = data[i].length != -1 ? data[i].length : (int) strlen(data[i].data);
int out_length = length;
int eci_length = get_eci_length(data[i].eci, (const unsigned char *) data[i].data, length);
char *dest = alloca(eci_length + 1);
char dest[1024];
assert_nonzero(eci_length + 1 <= 1024, "i:%d eci_length %d + 1 > 1024\n", i, eci_length);
ret = utf8_to_eci(data[i].eci, (const unsigned char *) data[i].data, (unsigned char *) dest, &out_length);
assert_equal(ret, data[i].ret, "i:%d utf8_to_eci ret %d != %d\n", i, ret, data[i].ret);
if (ret == 0) {

View file

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -80,8 +80,8 @@ static void test_print(int index, int generate, int debug) {
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
}

View file

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -32,6 +32,19 @@
#include "testcommon.h"
#include "../large.h"
#if defined(__MINGW32__)
# define LX_FMT "I64"
# if defined(__clang__)
# pragma GCC diagnostic ignored "-Wformat-non-iso"
# elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wformat" /* Unfortunately doesn't seem to be way to only avoid non-ISO warnings */
# endif
#elif defined(_MSC_VER)
# define LX_FMT "ll"
#else
# define LX_FMT "l"
#endif
#define LI(l, h) { l, h }
int clz_u64(uint64_t x);
@ -181,7 +194,7 @@ static void test_clz_u64(int index) {
if (index != -1 && i != index) continue;
ret = clz_u64(data[i].s);
assert_equal(ret, data[i].ret, "i:%d 0x%lX ret %d != %d\n", i, data[i].s, ret, data[i].ret);
assert_equal(ret, data[i].ret, "i:%d 0x%" LX_FMT "X ret %d != %d\n", i, data[i].s, ret, data[i].ret);
}
testFinish();
@ -214,9 +227,9 @@ static void test_load(int index) {
large_load(&data[i].t, &data[i].s);
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
}
@ -254,9 +267,9 @@ static void test_load_str_u64(int index) {
large_load_str_u64(&data[i].t, (unsigned char *) data[i].s, data[i].length == -1 ? (int) strlen(data[i].s) : data[i].length);
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
}
@ -297,9 +310,9 @@ static void test_add_u64(int index) {
large_add_u64(&data[i].t, data[i].s);
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
}
@ -340,9 +353,9 @@ static void test_sub_u64(int index) {
large_sub_u64(&data[i].t, data[i].s);
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
}
@ -396,9 +409,9 @@ static void test_mul_u64(int index) {
large_mul_u64(&data[i].t, data[i].s);
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
}
@ -520,10 +533,11 @@ static void test_div_u64(int index) {
r = large_div_u64(&data[i].t, data[i].s);
assert_equal(r, data[i].expected_r, "i:%d r %lu (0x%lX) != expected_r %lu (0x%lX)\n", i, r, r, data[i].expected_r, data[i].expected_r);
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
assert_equal(r, data[i].expected_r, "i:%d r %" LX_FMT "u (0x%" LX_FMT "X) != expected_r %" LX_FMT "u (0x%" LX_FMT "X)\n",
i, r, r, data[i].expected_r, data[i].expected_r);
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
}
@ -684,9 +698,9 @@ static void test_unset_bit(int index) {
large_unset_bit(&data[i].t, data[i].s);
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%lX (%s) != expected lo 0x%lX (%s)\n",
assert_equal(data[i].t.lo, data[i].expected.lo, "i:%d lo 0x%" LX_FMT "X (%s) != expected lo 0x%" LX_FMT "X (%s)\n",
i, data[i].t.lo, large_dump(&data[i].t, t_dump), data[i].expected.lo, large_dump(&data[i].expected, expected_dump));
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%lX (%s) != expected hi 0x%lX (%s)\n",
assert_equal(data[i].t.hi, data[i].expected.hi, "i:%d hi 0x%" LX_FMT "X (%s) != expected hi 0x%" LX_FMT "X (%s)\n",
i, data[i].t.hi, large_dump(&data[i].t, t_dump), data[i].expected.hi, large_dump(&data[i].expected, expected_dump));
}
@ -848,8 +862,8 @@ static void test_dump(int index) {
large_dump(&data[i].t, dump);
assert_zero(strcmp(dump, data[i].expected), "i:%d { %lX, %lX } strcmp(%s, %s) != 0\n",
i, (unsigned long) data[i].t.lo, (unsigned long) data[i].t.hi, dump, data[i].expected);
assert_zero(strcmp(dump, data[i].expected), "i:%d { %" LX_FMT "X, %" LX_FMT "X } strcmp(%s, %s) != 0\n",
i, data[i].t.lo, data[i].t.hi, dump, data[i].expected);
}
testFinish();

View file

@ -32,7 +32,6 @@
#include "testcommon.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
static void test_checks(int index, int debug) {
@ -265,7 +264,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
FILE *fp;
fp = fopen(input_filename, "wb");
assert_nonnull(fp, "i:%d fopen(%s) failed\n", i, input_filename);
assert_nonzero(fputs(data[i].data, fp), "i%d fputs(%s) failed\n", i, data[i].data);
assert_notequal(fputs(data[i].data, fp), EOF, "i%d fputs(%s) failed == EOF (%d)\n", i, data[i].data, ferror(fp));
assert_zero(fclose(fp), "i%d fclose() failed\n", i);
struct zint_symbol *symbol2 = ZBarcode_Create();
@ -282,7 +281,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
ret = testUtilSymbolCmp(symbol2, symbol);
assert_zero(ret, "i:%d testUtilSymbolCmp symbol2 ret %d != 0\n", i, ret);
assert_zero(remove(input_filename), "i:%d remove(%s) != 0 (%d)\n", i, input_filename, errno);
assert_zero(remove(input_filename), "i:%d remove(%s) != 0 (%d: %s)\n", i, input_filename, errno, strerror(errno));
ZBarcode_Delete(symbol2);
}
@ -334,6 +333,10 @@ static void test_encode_file_length(void) {
testStart("");
#ifdef _WIN32
testSkip("Test not compatible with Windows");
return;
#else
int ret;
char filename[] = "in.bin";
char buf[ZINT_MAX_DATA_LEN + 1] = {0};
@ -346,41 +349,42 @@ static void test_encode_file_length(void) {
// Empty file
fd = creat(filename, S_IRUSR);
assert_nonzero(fd, "Empty input file not created\n");
assert_zero(close(fd), "Empty close(%s) != 0\n", filename);
assert_notequal(fd, -1, "Empty input file (%s) not created == -1 (%d: %s)\n", filename, errno, strerror(errno));
assert_zero(close(fd), "Empty close(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File empty ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
assert_zero(remove(filename), "remove(%s) != 0\n", filename);
assert_zero(remove(filename), "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
// Too large file
fd = creat(filename, S_IRUSR | S_IWUSR);
assert_nonzero(fd, "Too large input file not created\n");
assert_notequal(fd, -1, "Too large input file (%s) not created == -1 (%d: %s)\n", filename, errno, strerror(errno));
ret = write(fd, buf, sizeof(buf));
assert_equal(ret, sizeof(buf), "Too large write ret %d != %d\n", ret, (int) sizeof(buf));
assert_zero(close(fd), "Too large close(%s) != 0\n", filename);
assert_zero(close(fd), "Too large close(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_TOO_LONG, "ZBarcode_Encode_File too large ret %d != ZINT_ERROR_TOO_LONG (%s)\n", ret, symbol->errtxt);
assert_zero(remove(filename), "remove(%s) != 0\n", filename);
assert_zero(remove(filename), "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
// Unreadable file
fd = creat(filename, S_IWUSR);
assert_nonzero(fd, "Unreadable input file not created\n");
assert_notequal(fd, -1, "Unreadable input file (%s) not created == -1 (%d: %s)\n", filename, errno, strerror(errno));
ret = write(fd, buf, 1);
assert_equal(ret, 1, "Unreadable write ret %d != 1\n", ret);
assert_zero(close(fd), "Unreadable close(%s) != 0\n", filename);
assert_zero(close(fd), "Unreadable close(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ret = ZBarcode_Encode_File(symbol, filename);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ZBarcode_Encode_File unreadable ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
assert_zero(remove(filename), "remove(%s) != 0\n", filename);
assert_zero(remove(filename), "remove(%s) != 0 (%d: %s)\n", filename, errno, strerror(errno));
ZBarcode_Delete(symbol);
testFinish();
#endif /* _WIN32 */
}
// #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error) Note: unable to reproduce fread() error using this method
@ -394,13 +398,13 @@ static void test_encode_file_directory(void) {
struct zint_symbol *symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
(void)rmdir(dirname); // In case junk hanging around
assert_zero(mkdir(dirname, 0700), "mkdir(%s, 0700) != 0\n", dirname);
(void)testutil_rmdir(dirname); // In case junk hanging around
assert_zero(testutil_mkdir(dirname, 0700), "testutil_mkdir(%s, 0700) != 0 (%d: %s)\n", dirname, errno, strerror(errno));
ret = ZBarcode_Encode_File(symbol, dirname);
assert_equal(ret, ZINT_ERROR_INVALID_DATA, "ret %d != ZINT_ERROR_INVALID_DATA (%s)\n", ret, symbol->errtxt);
assert_zero(rmdir(dirname), "rmdir(%s) != 0\n", dirname);
assert_zero(testutil_rmdir(dirname), "testutil_rmdir(%s) != 0 (%d: %s)\n", dirname, errno, strerror(errno));
ZBarcode_Delete(symbol);

View file

@ -47,18 +47,26 @@ static void test_large(int index, int debug) {
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "9", 55, 0, 1, 667 },
/* 1*/ { BARCODE_MSI_PLESSEY, -1, "9", 56, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { BARCODE_MSI_PLESSEY, 1, "9", 18, 0, 1, 235 }, // 1 mod-10 check digit
/* 3*/ { BARCODE_MSI_PLESSEY, 1, "9", 19, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { BARCODE_MSI_PLESSEY, 2, "9", 18, 0, 1, 247 }, // 2 mod-10 check digits
/* 5*/ { BARCODE_MSI_PLESSEY, 2, "9", 19, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 6*/ { BARCODE_MSI_PLESSEY, 3, "9", 55, 0, 1, 679 }, // 1 mod-11 check digit
/* 7*/ { BARCODE_MSI_PLESSEY, 3, "9", 56, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 8*/ { BARCODE_MSI_PLESSEY, 4, "9", 18, 0, 1, 247 }, // 1 mod-11 and 1 mod-10 check digit
/* 9*/ { BARCODE_MSI_PLESSEY, 4, "9", 19, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 10*/ { BARCODE_PLESSEY, -1, "A", 65, 0, 1, 1107 },
/* 11*/ { BARCODE_PLESSEY, -1, "A", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "9", 65, 0, 1, 787 },
/* 1*/ { BARCODE_MSI_PLESSEY, -1, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 2*/ { BARCODE_MSI_PLESSEY, 1, "9", 65, 0, 1, 799 }, // 1 mod-10 check digit
/* 3*/ { BARCODE_MSI_PLESSEY, 1, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 4*/ { BARCODE_MSI_PLESSEY, 2, "9", 65, 0, 1, 811 }, // 2 mod-10 check digits
/* 5*/ { BARCODE_MSI_PLESSEY, 2, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 6*/ { BARCODE_MSI_PLESSEY, 3, "9", 65, 0, 1, 799 }, // 1 mod-11 check digit
/* 7*/ { BARCODE_MSI_PLESSEY, 3, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 8*/ { BARCODE_MSI_PLESSEY, 3, "3", 65, 0, 1, 811 }, // 1 mod-11 double check digit "10"
/* 9*/ { BARCODE_MSI_PLESSEY, 3, "3", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 10*/ { BARCODE_MSI_PLESSEY, 4, "9", 65, 0, 1, 811 }, // 1 mod-11 and 1 mod-10 check digit
/* 11*/ { BARCODE_MSI_PLESSEY, 4, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 12*/ { BARCODE_MSI_PLESSEY, 4, "3", 65, 0, 1, 823 }, // 1 mod-11 double check digit "10" and 1 mod-10 check digit
/* 13*/ { BARCODE_MSI_PLESSEY, 4, "3", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 14*/ { BARCODE_MSI_PLESSEY, 5, "9", 65, 0, 1, 799 }, // 1 NCR mod-11 check digit
/* 15*/ { BARCODE_MSI_PLESSEY, 5, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 16*/ { BARCODE_MSI_PLESSEY, 6, "9", 65, 0, 1, 811 }, // 1 NCR mod-11 and 1 mod-10 check digit
/* 17*/ { BARCODE_MSI_PLESSEY, 6, "9", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
/* 18*/ { BARCODE_PLESSEY, -1, "A", 65, 0, 1, 1107 },
/* 19*/ { BARCODE_PLESSEY, -1, "A", 66, ZINT_ERROR_TOO_LONG, -1, -1 },
};
int data_size = ARRAY_SIZE(data);
@ -107,16 +115,32 @@ static void test_hrt(int index, int debug) {
/* 0*/ { BARCODE_MSI_PLESSEY, -1, "1234567", "1234567" },
/* 1*/ { BARCODE_MSI_PLESSEY, 0, "1234567", "1234567" },
/* 2*/ { BARCODE_MSI_PLESSEY, 1, "1234567", "12345674" },
/* 3*/ { BARCODE_MSI_PLESSEY, 2, "1234567", "123456741" },
/* 4*/ { BARCODE_MSI_PLESSEY, 3, "1234567", "12345674" },
/* 5*/ { BARCODE_MSI_PLESSEY, 4, "1234567", "123456741" },
/* 6*/ { BARCODE_MSI_PLESSEY, 1, "123456", "1234566" },
/* 7*/ { BARCODE_MSI_PLESSEY, 2, "123456", "12345666" },
/* 8*/ { BARCODE_MSI_PLESSEY, 3, "123456", "1234560" },
/* 9*/ { BARCODE_MSI_PLESSEY, 4, "123456", "12345609" },
/* 10*/ { BARCODE_MSI_PLESSEY, 3, "2211", "221110" }, // Mod-11 check digit '10'
/* 11*/ { BARCODE_MSI_PLESSEY, 4, "2211", "2211100" },
/* 12*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", "0123456789ABCDEF" },
/* 3*/ { BARCODE_MSI_PLESSEY, 1 + 10, "1234567", "1234567" },
/* 4*/ { BARCODE_MSI_PLESSEY, 1, "9999999999", "99999999990" },
/* 5*/ { BARCODE_MSI_PLESSEY, 2, "1234567", "123456741" },
/* 6*/ { BARCODE_MSI_PLESSEY, 2 + 10, "1234567", "1234567" },
/* 7*/ { BARCODE_MSI_PLESSEY, 2, "9999999999", "999999999900" },
/* 8*/ { BARCODE_MSI_PLESSEY, 3, "1234567", "12345674" },
/* 9*/ { BARCODE_MSI_PLESSEY, 3 + 10, "1234567", "1234567" },
/* 10*/ { BARCODE_MSI_PLESSEY, 3, "9999999999", "99999999995" },
/* 11*/ { BARCODE_MSI_PLESSEY, 4, "1234567", "123456741" },
/* 12*/ { BARCODE_MSI_PLESSEY, 4 + 10, "1234567", "1234567" },
/* 13*/ { BARCODE_MSI_PLESSEY, 4, "9999999999", "999999999959" },
/* 14*/ { BARCODE_MSI_PLESSEY, 5, "1234567", "12345679" },
/* 15*/ { BARCODE_MSI_PLESSEY, 5 + 10, "1234567", "1234567" },
/* 16*/ { BARCODE_MSI_PLESSEY, 5, "9999999999", "999999999910" },
/* 17*/ { BARCODE_MSI_PLESSEY, 6, "1234567", "123456790" },
/* 18*/ { BARCODE_MSI_PLESSEY, 6 + 10, "1234567", "1234567" },
/* 19*/ { BARCODE_MSI_PLESSEY, 6, "9999999999", "9999999999109" },
/* 20*/ { BARCODE_MSI_PLESSEY, 1, "123456", "1234566" },
/* 21*/ { BARCODE_MSI_PLESSEY, 2, "123456", "12345666" },
/* 22*/ { BARCODE_MSI_PLESSEY, 3, "123456", "1234560" },
/* 23*/ { BARCODE_MSI_PLESSEY, 4, "123456", "12345609" },
/* 24*/ { BARCODE_MSI_PLESSEY, 3, "2211", "221110" }, // Mod-11 check digit '10'
/* 25*/ { BARCODE_MSI_PLESSEY, 3 + 10, "2211", "2211" }, // Mod-11 check digit '10'
/* 26*/ { BARCODE_MSI_PLESSEY, 4, "2211", "2211100" },
/* 27*/ { BARCODE_MSI_PLESSEY, 4 + 10, "2211", "2211" },
/* 28*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", "0123456789ABCDEF" },
};
int data_size = ARRAY_SIZE(data);
@ -219,16 +243,22 @@ static void test_encode(int index, int generate, int debug) {
/* 4*/ { BARCODE_MSI_PLESSEY, 4, "1234567890", 0, 1, 151, "",
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001101101001001001101001"
},
/* 5*/ { BARCODE_MSI_PLESSEY, 3, "2211", 0, 1, 79, "Produces mod-11 '10' check digit; BWIPP (badmod11)",
/* 5*/ { BARCODE_MSI_PLESSEY, 5, "1234567890", 0, 1, 139, "",
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001001001001"
},
/* 6*/ { BARCODE_MSI_PLESSEY, 6, "1234567890", 0, 1, 151, "",
"1101001001001101001001101001001001101101001101001001001101001101001101101001001101101101101001001001101001001101001001001001001001001001001101101101001"
},
/* 7*/ { BARCODE_MSI_PLESSEY, 3, "2211", 0, 1, 79, "Produces mod-11 '10' check digit; BWIPP (badmod11)",
"1101001001101001001001101001001001001101001001001101001001001101001001001001001"
},
/* 6*/ { BARCODE_MSI_PLESSEY, 4, "2211", 0, 1, 91, "BWIPP (badmod11)",
/* 8*/ { BARCODE_MSI_PLESSEY, 4, "2211", 0, 1, 91, "BWIPP (badmod11)",
"1101001001101001001001101001001001001101001001001101001001001101001001001001001001001001001"
},
/* 7*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", 0, 1, 323, "",
/* 9*/ { BARCODE_PLESSEY, -1, "0123456789ABCDEF", 0, 1, 323, "",
"11101110100011101000100010001000111010001000100010001110100010001110111010001000100010001110100011101000111010001000111011101000111011101110100010001000100011101110100010001110100011101000111011101110100011101000100011101110111010001110111010001110111011101110111011101110111010001000111010001000100010001110001000101110111"
},
/* 8*/ { BARCODE_MSI_PLESSEY, 4, "999999999999999999", 0, 1, 247, "Max value; #209 check buffer not overrun",
/* 10*/ { BARCODE_MSI_PLESSEY, 4, "999999999999999999", 0, 1, 247, "Max value (previously); #209 check buffer not overrun",
"1101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001101101001001001001001001101001"
},
};

View file

@ -196,8 +196,8 @@ static void test_print(int index, int generate, int debug) {
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
}

View file

@ -81,13 +81,13 @@ static void test_print(int index, int generate, int debug) {
if (generate) {
strcpy(data_dir, "data");
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
strcat(data_dir, "/print");
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
}
@ -100,8 +100,8 @@ static void test_print(int index, int generate, int debug) {
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
}

View file

@ -1,6 +1,6 @@
/*
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -71,8 +71,8 @@ static void test_print(int index, int generate, int debug) {
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
}

View file

@ -111,8 +111,8 @@ static void test_print(int index, int generate, int debug) {
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
}

View file

@ -190,8 +190,8 @@ static void test_print(int index, int generate, int debug) {
if (generate) {
if (!testUtilExists(data_dir)) {
ret = mkdir(data_dir, 0755);
assert_zero(ret, "mkdir(%s) ret %d != 0\n", data_dir, ret);
ret = testutil_mkdir(data_dir, 0755);
assert_zero(ret, "testutil_mkdir(%s) ret %d != 0 (%d: %s)\n", data_dir, ret, errno, strerror(errno));
}
}

View file

@ -529,9 +529,9 @@ static void test_stacking(int index, int debug) {
};
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<"))
struct item data[] = {
/* 0*/ { BARCODE_CODE128, -1, -1, -1, "A", "B", 50, 2, 46, 92, 116.1, -1, -1, -1 },
/* 1*/ { BARCODE_CODE128, BARCODE_BIND, -1, -1, "A", "B", 50, 2, 46, 92, 116.1, 49, 0, 2 },
/* 2*/ { BARCODE_CODE128, BARCODE_BIND, -1, 2, "A", "B", 50, 2, 46, 92, 116.1, 48, 0, 4 },
/* 0*/ { BARCODE_CODE128, -1, -1, -1, "A", "B", 50, 2, 46, 92, 116, -1, -1, -1 },
/* 1*/ { BARCODE_CODE128, BARCODE_BIND, -1, -1, "A", "B", 50, 2, 46, 92, 116, 49, 0, 2 },
/* 2*/ { BARCODE_CODE128, BARCODE_BIND, -1, 2, "A", "B", 50, 2, 46, 92, 116, 48, 0, 4 },
};
int data_size = ARRAY_SIZE(data);

View file

@ -34,6 +34,14 @@
*/
#include "testcommon.h"
#ifdef _MSC_VER
#include <malloc.h>
#define testutil_alloca(nmemb) _alloca(nmemb)
#else
#define testutil_alloca(nmemb) alloca(nmemb)
#endif
#include "../eci.h"
#ifndef NO_PNG
#include <png.h>
@ -1178,7 +1186,7 @@ void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, c
int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column) {
static char colour[] = { '0', 'C', 'M', 'B', 'Y', 'G', 'R', '1' };
int r, c, i, j;
int r, c = -1, i, j;
const char *e = expected;
const char *ep = expected + strlen(expected);
char buf[7];
@ -2017,7 +2025,7 @@ static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const ch
/* Escape single quote also to avoid having to do proper shell escaping TODO: proper shell escaping */
if (*d < 0x20 || *d >= 0x7F || *d == '^' || *d == '"' || *d == '\'') {
if (b + 4 >= be) {
fprintf(stderr, "testUtilBwippEscape: bwipp_data buffer full\n");
fprintf(stderr, "testUtilBwippEscape: double quote bwipp_data buffer full (%d)\n", bwipp_data_size);
return NULL;
}
sprintf(b, "^%03u", *d++);
@ -2044,7 +2052,7 @@ static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const ch
default: fprintf(stderr, "testUtilBwippEscape: unknown escape %c\n", *d); return NULL; break;
}
if (b + 4 >= be) {
fprintf(stderr, "testUtilBwippEscape: bwipp_data buffer full\n");
fprintf(stderr, "testUtilBwippEscape: loop bwipp_data buffer full (%d)\n", bwipp_data_size);
return NULL;
}
sprintf(b, "^%03d", val);
@ -2057,7 +2065,7 @@ static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const ch
}
if (b == be && d < de) {
fprintf(stderr, "testUtilBwippEscape: bwipp_data buffer full\n");
fprintf(stderr, "testUtilBwippEscape: end bwipp_data buffer full (%d)\n", bwipp_data_size);
return NULL;
}
*b = '\0';
@ -2086,10 +2094,10 @@ static void testUtilISBNHyphenate(char *bwipp_data, int addon_posn) {
#define GS_INITIAL_LEN 35 /* Length of cmd up to -q */
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size) {
const char *cmd_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' ../tools/bwipp_dump.ps";
const char *cmd_opts_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' -so='%s' ../tools/bwipp_dump.ps";
const char *cmd_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' ../tools/bwipp_dump.ps"; // If data > 2K
const char *cmd_opts_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' -so='%s' ../tools/bwipp_dump.ps";
const char *cmd_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' backend/tests/tools/bwipp_dump.ps";
const char *cmd_opts_fmt = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' -so='%s' backend/tests/tools/bwipp_dump.ps";
const char *cmd_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' backend/tests/tools/bwipp_dump.ps"; // If data > 2K
const char *cmd_opts_fmt2 = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' -so='%s' backend/tests/tools/bwipp_dump.ps";
int symbology = symbol->symbology;
int data_len = length == -1 ? (int) strlen(data) : length;
@ -2097,13 +2105,14 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
int max_data_len = 4 + primary_len + 1 + 1 + data_len * 4 + 64; /* 4 AI prefix + primary + '|' + leading zero + escaped data + fudge */
int eci_length = get_eci_length(symbol->eci, (const unsigned char *) data, data_len);
char *converted = alloca(eci_length + 1);
char *cmd = alloca(max_data_len + 1024);
char *converted = (char *) testutil_alloca(eci_length + 1);
char *cmd = (char *) testutil_alloca(max_data_len + 1024);
const char *bwipp_barcode = NULL;
char *bwipp_opts = NULL;
char *bwipp_data = alloca(max_data_len + 1);
int bwipp_data_size = max_data_len + 1;
char *bwipp_data = (char *) testutil_alloca(bwipp_data_size);
char bwipp_opts_buf[512];
int *bwipp_row_height = alloca(sizeof(int) * symbol->rows);
int *bwipp_row_height = (int *) testutil_alloca(sizeof(int) * symbol->rows);
int linear_row_height;
int gs1_cvt;
int user_mask;
@ -2227,7 +2236,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
}
}
} else {
if (testUtilBwippEscape(bwipp_data, sizeof(bwipp_data), data, data_len, symbol->input_mode & ESCAPE_MODE, eci, &parse, &parsefnc) == NULL) {
if (testUtilBwippEscape(bwipp_data, bwipp_data_size, data, data_len, symbol->input_mode & ESCAPE_MODE, eci, &parse, &parsefnc) == NULL) {
return -1;
}
if (parse) {
@ -2285,12 +2294,19 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%sincludecheck", strlen(bwipp_opts_buf) ? " " : "");
const char *checktype = NULL;
if (option_2 >= 11 && option_2 <= 16) {
option_2 -= 10; /* Remove no-check indicator */
}
if (option_2 == 2) {
checktype = "mod1010";
} else if (option_2 == 3) {
checktype = "mod11 badmod11";
} else if (option_2 == 4) {
checktype = "mod1110 badmod11";
} else if (option_2 == 5) {
checktype = "ncrmod11 badmod11";
} else if (option_2 == 6) {
checktype = "ncrmod1110 badmod11";
}
if (checktype) {
sprintf(bwipp_opts_buf + (int) strlen(bwipp_opts_buf), "%schecktype=%s", strlen(bwipp_opts_buf) ? " " : "", checktype);
@ -2480,7 +2496,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
}
}
if (option_2 > 0) {
char scm_vv_buf[16];
char scm_vv_buf[32];
sprintf(scm_vv_buf, "[)>^03001^029%02d", option_2); /* [)>\R01\Gvv */
memmove(bwipp_data + 15, bwipp_data, strlen(bwipp_data) + 1);
memcpy(bwipp_data, scm_vv_buf, 15);
@ -2621,7 +2637,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
printf("i:%d testUtilBwipp: cmd %s\n", index, cmd);
}
fp = popen(cmd, "r");
fp = testutil_popen(cmd, "r");
if (!fp) {
fprintf(stderr, "i:%d testUtilBwipp: failed to run '%s'\n", index, cmd);
return -1;
@ -2630,13 +2646,13 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
for (r = 0; r < symbol->rows; r++) {
if (b + symbol->width > be) {
fprintf(stderr, "i:%d testUtilBwipp: row %d, width %d, row width iteration overrun (%s)\n", index, r, symbol->width, cmd);
pclose(fp);
testutil_pclose(fp);
return -1;
}
cnt = fread(b, 1, symbol->width, fp);
if (cnt != symbol->width) {
fprintf(stderr, "i:%d testUtilBwipp: failed to read symbol->width %d bytes, cnt %d (%s)\n", index, symbol->width, cnt, cmd);
pclose(fp);
testutil_pclose(fp);
return -1;
}
b += cnt;
@ -2645,7 +2661,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
if (cnt != symbol->width) {
fprintf(stderr, "i:%d testUtilBwipp: failed to read/ignore symbol->width %d bytes, cnt %d, h %d, bwipp_row_height[%d] %d, symbol->row_height[%d] %d (%s)\n",
index, symbol->width, cnt, h, r, bwipp_row_height[r], r, symbol->row_height[r], cmd);
pclose(fp);
testutil_pclose(fp);
return -1;
}
}
@ -2654,11 +2670,11 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
if (fgetc(fp) != EOF) {
fprintf(stderr, "i:%d testUtilBwipp: failed to read full stream (%s)\n", index, cmd);
pclose(fp);
testutil_pclose(fp);
return -1;
}
pclose(fp);
testutil_pclose(fp);
return 0;
}

View file

@ -42,17 +42,38 @@
#define ZINT_DEBUG_TEST_BWIPP 128
#define ZINT_DEBUG_TEST_PERFORMANCE 256
#ifdef _WIN32
#include <malloc.h>
#define alloca(nmemb) _malloca(nmemb)
#define popen(command, mode) _popen(command, mode)
#define pclose(stream) _pclose(stream)
#ifdef _MSC_VER
#define testutil_popen(command, mode) _popen(command, mode)
#define testutil_pclose(stream) _pclose(stream)
#else
#include <unistd.h>
#define testutil_popen(command, mode) popen(command, mode)
#define testutil_pclose(stream) pclose(stream)
#endif
#ifdef _WIN32
#include <direct.h>
#define testutil_mkdir(path, mode) _mkdir(path)
#define testutil_rmdir(path) _rmdir(path)
#else
#define testutil_mkdir(path, mode) mkdir(path, mode)
#define testutil_rmdir(path) rmdir(path)
#endif
#include <stdio.h>
#include <errno.h>
#include "../common.h"
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wpedantic"
# pragma clang diagnostic ignored "-Woverlength-strings"
#elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wpedantic"
# pragma GCC diagnostic ignored "-Woverlength-strings"
#elif defined(_MSC_VER)
# pragma warning(disable: 4305) /* truncation from 'double' to 'float' */
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -72,7 +93,9 @@ void testFinish(void);
void testSkip(const char *msg);
void testReport();
typedef struct s_testFunction { const char *name; void *func; int has_index; int has_generate; int has_debug; } testFunction;
typedef struct s_testFunction {
const char *name; void *func; int has_index; int has_generate; int has_debug;
} testFunction;
void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
#define assert_exp(__exp__, ...) \
@ -89,7 +112,8 @@ void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */
int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci, int option_1, int option_2, int option_3, int output_options, char *data, int length, int debug);
int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci,
int option_1, int option_2, int option_3, int output_options, char *data, int length, int debug);
const char *testUtilBarcodeName(int symbology);
const char *testUtilErrorName(int error_number);
const char *testUtilInputModeName(int input_mode);
@ -129,10 +153,13 @@ int testUtilHaveVnu();
int testUtilVerifyVnu(char *filename, int debug);
int testUtilHaveTiffInfo();
int testUtilVerifyTiffInfo(char *filename, int debug);
int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug);
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size);
int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,
int debug);
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,
const char *data, int length, const char *primary, char *buffer, int buffer_size);
int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, const char *bwipp_buf, const char *expected);
int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *bwipp_buf, const char *expected);
int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *bwipp_buf,
const char *expected);
#ifdef __cplusplus
}

View file

@ -6,10 +6,10 @@ set -e
function run_bwipp_test() {
if [ -z "$2" ]; then
echo -e "\n$1"
./$1 -d $(expr 128 + 16 + 32) || exit 1
backend/tests/$1 -d $(expr 128 + 16 + 32) || exit 1
else
echo -e "\n$1 -f $2"
./$1 -f "$2" -d $(expr 128 + 16 + 32) || exit 1
backend/tests/$1 -f "$2" -d $(expr 128 + 16 + 32) || exit 1
fi
}

View file

@ -32,6 +32,7 @@
*/
/* vim: set ts=4 sw=4 et : */
#include <errno.h>
#include <stdio.h>
#include <math.h>
#include <assert.h>
@ -333,14 +334,14 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
if (symbol->output_options & BARCODE_STDOUT) {
#ifdef _MSC_VER
if (-1 == _setmode(_fileno(stdout), _O_BINARY)) {
strcpy(symbol->errtxt, "671: Can't open output file");
sprintf(symbol->errtxt, "671: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
#endif
tif_file = stdout;
} else {
if (!(tif_file = fopen(symbol->outfile, "wb+"))) {
strcpy(symbol->errtxt, "672: Can't open output file");
sprintf(symbol->errtxt, "672: Can't open output file (%d: %.30s)", errno, strerror(errno));
return ZINT_ERROR_FILE_ACCESS;
}
compression = TIF_LZW;

View file

@ -1,7 +1,7 @@
/* ultra.c - Ultracode
libzint - the open source barcode library
Copyright (C) 2020 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2020 - 2021 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -58,7 +58,8 @@ static const char ultra_digit[] = "0123456789,/";
static const char ultra_colour[] = "0CBMRYGKW";
//static const int ultra_maxsize[] = {34, 78, 158, 282}; // According to Table 1
static const int ultra_maxsize[] = {34, 81, 158, 282}; // Adjusted to allow 79-81 codeword range in 3-row symbols (only 1 secondary vertical clock track, not 2, so 3 extra)
// Adjusted to allow 79-81 codeword range in 3-row symbols (only 1 secondary vertical clock track, not 2, so 3 extra)
static const int ultra_maxsize[] = {34, 81, 158, 282};
static const int ultra_mincols[] = {5, 13, 23, 30}; // # Total Tile Columns from Table 1
@ -208,7 +209,7 @@ static int ultra_find_fragment(const unsigned char source[], int source_length,
for (j = 0; j < 27; j++) {
latch = 0;
fraglen = strlen(fragment[j]);
fraglen = (int) strlen(fragment[j]);
if ((position + fraglen) <= source_length) {
latch = 1;
for (k = 0; k < fraglen; k++) {
@ -228,8 +229,8 @@ static int ultra_find_fragment(const unsigned char source[], int source_length,
}
/* Encode characters in 8-bit mode */
static float look_ahead_eightbit(unsigned char source[], int in_length, int in_locn, char current_mode, int end_char, int cw[], int* cw_len, int gs1)
{
static float look_ahead_eightbit(unsigned char source[], int in_length, int in_locn, char current_mode, int end_char,
int cw[], int* cw_len, int gs1) {
int codeword_count = 0;
int i;
int letters_encoded = 0;
@ -262,7 +263,8 @@ static float look_ahead_eightbit(unsigned char source[], int in_length, int in_l
}
/* Encode character in the ASCII mode/submode (including numeric compression) */
static float look_ahead_ascii(unsigned char source[], int in_length, int in_locn, char current_mode, int symbol_mode, int end_char, int cw[], int* cw_len, int* encoded, int gs1) {
static float look_ahead_ascii(unsigned char source[], int in_length, int in_locn, char current_mode, int symbol_mode,
int end_char, int cw[], int* cw_len, int* encoded, int gs1) {
int codeword_count = 0;
int i;
int first_digit, second_digit, done;
@ -370,7 +372,7 @@ static int c43_should_latch_other(const unsigned char data[], const int length,
fragno = ultra_find_fragment(data, length, i);
if (fragno != -1 && fragno != 26) {
fraglen = strlen(fragment[fragno]);
fraglen = (int) strlen(fragment[fragno]);
predict_window += fraglen;
if (predict_window > length) {
predict_window = length;
@ -420,7 +422,8 @@ static int get_subset(unsigned char source[], int in_length, int in_locn, int cu
}
/* Encode characters in the C43 compaction submode */
static float look_ahead_c43(unsigned char source[], int in_length, int in_locn, char current_mode, int end_char, int subset, int cw[], int* cw_len, int* encoded, int gs1, int debug) {
static float look_ahead_c43(unsigned char source[], int in_length, int in_locn, char current_mode, int end_char,
int subset, int cw[], int* cw_len, int* encoded, int gs1, int debug) {
int codeword_count = 0;
int subcodeword_count = 0;
int i;
@ -435,7 +438,7 @@ static float look_ahead_c43(unsigned char source[], int in_length, int in_locn,
#ifndef _MSC_VER
int subcw[(in_length + 3) * 2];
#else
int * subcw = (int *) _alloca((in_length + 3) * 2 * sizeof (int));
int * subcw = (int *) _alloca((in_length + 3) * 2 * sizeof(int));
#endif /* _MSC_VER */
if (current_mode == EIGHTBIT_MODE) {
@ -451,32 +454,32 @@ static float look_ahead_c43(unsigned char source[], int in_length, int in_locn,
switch(fragno) {
case 17: // mailto:
cw[codeword_count] = 276;
sublocn += strlen(fragment[fragno]);
sublocn += (int) strlen(fragment[fragno]);
codeword_count++;
break;
case 18: // tel:
cw[codeword_count] = 277;
sublocn += strlen(fragment[fragno]);
sublocn += (int) strlen(fragment[fragno]);
codeword_count++;
break;
case 26: // file:
cw[codeword_count] = 278;
sublocn += strlen(fragment[fragno]);
sublocn += (int) strlen(fragment[fragno]);
codeword_count++;
break;
case 0: // http://
cw[codeword_count] = 279;
sublocn += strlen(fragment[fragno]);
sublocn += (int) strlen(fragment[fragno]);
codeword_count++;
break;
case 1: // https://
cw[codeword_count] = 280;
sublocn += strlen(fragment[fragno]);
sublocn += (int) strlen(fragment[fragno]);
codeword_count++;
break;
case 4: // ftp://
cw[codeword_count] = 281;
sublocn += strlen(fragment[fragno]);
sublocn += (int) strlen(fragment[fragno]);
codeword_count++;
break;
default:
@ -558,12 +561,12 @@ static float look_ahead_c43(unsigned char source[], int in_length, int in_locn,
if ((fragno >= 0) && (fragno <= 18)) {
subcw[subcodeword_count] = fragno; // C43 Set 3 codewords 0 to 18
subcodeword_count++;
sublocn += strlen(fragment[fragno]);
sublocn += (int) strlen(fragment[fragno]);
}
if ((fragno >= 19) && (fragno <= 25)) {
subcw[subcodeword_count] = fragno + 17; // C43 Set 3 codewords 36 to 42
subcodeword_count++;
sublocn += strlen(fragment[fragno]);
sublocn += (int) strlen(fragment[fragno]);
}
if (fragno == -1) {
subcw[subcodeword_count] = posn(ultra_c43_set3, source[sublocn]) + 19; // C43 Set 3 codewords 19 to 35
@ -637,9 +640,9 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c
char mode[in_length + 1];
int cw_fragment[in_length * 2 + 1];
#else
unsigned char * crop_source = (unsigned char *) _alloca((in_length + 1) * sizeof (unsigned char));
char * mode = (char *) _alloca((in_length + 1) * sizeof (char));
int * cw_fragment = (int *) _alloca((in_length * 2 + 1) * sizeof (int));
unsigned char * crop_source = (unsigned char *) _alloca(in_length + 1);
char * mode = (char *) _alloca(in_length + 1);
int * cw_fragment = (int *) _alloca((in_length * 2 + 1) * sizeof(int));
#endif /* _MSC_VER */
if ((symbol->input_mode & 0x07) == GS1_MODE) {
@ -769,10 +772,13 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c
input_locn = 0;
do {
end_char = input_locn + PREDICT_WINDOW;
eightbit_score = look_ahead_eightbit(crop_source, crop_length, input_locn, current_mode, end_char, cw_fragment, &fragment_length, gs1);
ascii_score = look_ahead_ascii(crop_source, crop_length, input_locn, current_mode, symbol_mode, end_char, cw_fragment, &fragment_length, &ascii_encoded, gs1);
eightbit_score = look_ahead_eightbit(crop_source, crop_length, input_locn, current_mode, end_char,
cw_fragment, &fragment_length, gs1);
ascii_score = look_ahead_ascii(crop_source, crop_length, input_locn, current_mode, symbol_mode,
end_char, cw_fragment, &fragment_length, &ascii_encoded, gs1);
subset = c43_should_latch_other(crop_source, crop_length, input_locn, 1 /*subset*/, gs1) ? 2 : 1;
c43_score = look_ahead_c43(crop_source, crop_length, input_locn, current_mode, end_char, subset, cw_fragment, &fragment_length, &c43_encoded, gs1, 0 /*debug*/);
c43_score = look_ahead_c43(crop_source, crop_length, input_locn, current_mode, end_char,
subset, cw_fragment, &fragment_length, &c43_encoded, gs1, 0 /*debug*/);
mode[input_locn] = 'a';
current_mode = ASCII_MODE;
@ -824,21 +830,26 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c
switch(mode[input_locn]) {
case 'a':
look_ahead_ascii(crop_source, crop_length, input_locn, current_mode, symbol_mode, input_locn + block_length, cw_fragment, &fragment_length, NULL, gs1);
look_ahead_ascii(crop_source, crop_length, input_locn, current_mode, symbol_mode,
input_locn + block_length, cw_fragment, &fragment_length, NULL, gs1);
current_mode = ASCII_MODE;
break;
case 'c':
subset = c43_should_latch_other(crop_source, crop_length, input_locn, 1 /*subset*/, gs1) ? 2 : 1;
look_ahead_c43(crop_source, crop_length, input_locn, current_mode, input_locn + block_length, subset, cw_fragment, &fragment_length, NULL, gs1, symbol->debug);
look_ahead_c43(crop_source, crop_length, input_locn, current_mode, input_locn + block_length, subset,
cw_fragment, &fragment_length, NULL, gs1, symbol->debug);
/* Substitute temporary latch if possible */
if ((current_mode == EIGHTBIT_MODE) && (cw_fragment[0] == 260) && (fragment_length >= 5) && (fragment_length <= 11)) {
if ((current_mode == EIGHTBIT_MODE) && (cw_fragment[0] == 260)
&& (fragment_length >= 5) && (fragment_length <= 11)) {
/* Temporary latch to submode 1 from Table 11 */
cw_fragment[0] = 256 + ((fragment_length - 5) / 2);
} else if ((current_mode == EIGHTBIT_MODE) && (cw_fragment[0] == 266) && (fragment_length >= 5) && (fragment_length <= 11)) {
} else if ((current_mode == EIGHTBIT_MODE) && (cw_fragment[0] == 266)
&& (fragment_length >= 5) && (fragment_length <= 11)) {
/* Temporary latch to submode 2 from Table 11 */
cw_fragment[0] = 262 + ((fragment_length - 5) / 2);
} else if ((current_mode == ASCII_MODE) && (cw_fragment[0] == 278) && (fragment_length >= 5) && (fragment_length <= 11)) {
} else if ((current_mode == ASCII_MODE) && (cw_fragment[0] == 278)
&& (fragment_length >= 5) && (fragment_length <= 11)) {
/* Temporary latch to submode 1 from Table 9 */
cw_fragment[0] = 274 + ((fragment_length - 5) / 2);
} else {
@ -846,7 +857,8 @@ static int ultra_generate_codewords(struct zint_symbol *symbol, const unsigned c
}
break;
case '8':
look_ahead_eightbit(crop_source, crop_length, input_locn, current_mode, input_locn + block_length, cw_fragment, &fragment_length, gs1);
look_ahead_eightbit(crop_source, crop_length, input_locn, current_mode, input_locn + block_length,
cw_fragment, &fragment_length, gs1);
current_mode = EIGHTBIT_MODE;
break;
}
@ -870,7 +882,8 @@ INTERNAL int ultracode(struct zint_symbol *symbol, unsigned char source[], int l
int total_cws;
int pads;
int cw_memalloc;
int codeword[282 + 3]; // Allow for 3 pads in final 57th (60th incl. clock tracks) column of 5-row symbol (57 * 5 == 285)
// Allow for 3 pads in final 57th (60th incl. clock tracks) column of 5-row symbol (57 * 5 == 285)
int codeword[282 + 3];
int i, j, locn;
int total_height, total_width;
char tilepat[6];
@ -894,7 +907,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, unsigned char source[], int l
#ifndef _MSC_VER
int data_codewords[cw_memalloc];
#else
data_codewords = (int *) _alloca(cw_memalloc * sizeof (int));
data_codewords = (int *) _alloca(cw_memalloc * sizeof(int));
#endif /* _MSC_VER */
data_cw_count = ultra_generate_codewords(symbol, source, length, data_codewords);
@ -943,7 +956,8 @@ INTERNAL int ultracode(struct zint_symbol *symbol, unsigned char source[], int l
rows = 5;
for (i = 2; i >= 0; i--) {
if (total_cws - 6 <= ultra_maxsize[i]) { // Total codewords less 6 overhead (Start + MCC + ACC + 3 TCC/RSEC/QCC patterns)
// Total codewords less 6 overhead (Start + MCC + ACC + 3 TCC/RSEC/QCC patterns)
if (total_cws - 6 <= ultra_maxsize[i]) {
rows--;
}
}
@ -1005,7 +1019,7 @@ INTERNAL int ultracode(struct zint_symbol *symbol, unsigned char source[], int l
#ifndef _MSC_VER
char pattern[total_height * total_width];
#else
pattern = (char *) _alloca(total_height * total_width * sizeof (char));
pattern = (char *) _alloca(total_height * total_width);
#endif /* _MSC_VER */
for (i = 0; i < (total_height * total_width); i++) {

View file

@ -52,7 +52,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle);
static struct zint_vector_rect *vector_plot_create_rect(float x, float y, float width, float height) {
struct zint_vector_rect *rect;
rect = (struct zint_vector_rect*) malloc(sizeof (struct zint_vector_rect));
rect = (struct zint_vector_rect *) malloc(sizeof(struct zint_vector_rect));
if (!rect) return NULL;
rect->next = NULL;
@ -79,7 +79,7 @@ static int vector_plot_add_rect(struct zint_symbol *symbol, struct zint_vector_r
static struct zint_vector_hexagon *vector_plot_create_hexagon(float x, float y, float diameter) {
struct zint_vector_hexagon *hexagon;
hexagon = (struct zint_vector_hexagon*) malloc(sizeof (struct zint_vector_hexagon));
hexagon = (struct zint_vector_hexagon *) malloc(sizeof(struct zint_vector_hexagon));
if (!hexagon) return NULL;
hexagon->next = NULL;
hexagon->x = x;
@ -104,7 +104,7 @@ static int vector_plot_add_hexagon(struct zint_symbol *symbol, struct zint_vecto
static struct zint_vector_circle *vector_plot_create_circle(float x, float y, float diameter, int colour) {
struct zint_vector_circle *circle;
circle = (struct zint_vector_circle *) malloc(sizeof (struct zint_vector_circle));
circle = (struct zint_vector_circle *) malloc(sizeof(struct zint_vector_circle));
if (!circle) return NULL;
circle->next = NULL;
circle->x = x;
@ -131,17 +131,17 @@ static int vector_plot_add_string(struct zint_symbol *symbol,
struct zint_vector_string **last_string) {
struct zint_vector_string *string;
string = (struct zint_vector_string*) malloc(sizeof (struct zint_vector_string));
string = (struct zint_vector_string *) malloc(sizeof(struct zint_vector_string));
if (!string) return 0;
string->next = NULL;
string->x = x;
string->y = y;
string->width = width;
string->fsize = fsize;
string->length = ustrlen(text);
string->length = (int) ustrlen(text);
string->rotation = 0;
string->halign = halign;
string->text = (unsigned char*) malloc(sizeof (unsigned char) * (ustrlen(text) + 1));
string->text = (unsigned char *) malloc(ustrlen(text) + 1);
if (!string->text) { free(string); return 0; }
ustrcpy(string->text, text);
@ -433,7 +433,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
}
// Allocate memory
vector = symbol->vector = (struct zint_vector *) malloc(sizeof (struct zint_vector));
vector = symbol->vector = (struct zint_vector *) malloc(sizeof(struct zint_vector));
if (!vector) return ZINT_ERROR_MEMORY;
vector->rectangles = NULL;
vector->hexagons = NULL;

View file

@ -305,16 +305,16 @@ extern "C" {
#define ZINT_DEBUG_PRINT 1
#define ZINT_DEBUG_TEST 2
#if defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(_MSC_VER)
#if defined (DLL_EXPORT) || defined(PIC) || defined(_USRDLL)
#define ZINT_EXTERN __declspec(dllexport)
#elif defined(ZINT_DLL)
#define ZINT_EXTERN __declspec(dllimport)
#ifdef _WIN32
# if defined(DLL_EXPORT) || defined(PIC) || defined(_USRDLL)
# define ZINT_EXTERN __declspec(dllexport)
# elif defined(ZINT_DLL)
# define ZINT_EXTERN __declspec(dllimport)
# else
# define ZINT_EXTERN extern
# endif
#else
#define ZINT_EXTERN extern
#endif
#else
#define ZINT_EXTERN extern
# define ZINT_EXTERN extern
#endif
ZINT_EXTERN struct zint_symbol *ZBarcode_Create(void);