backend: define z_alloca() and use for both Unix and Windows;

replace double-slash comments with old-skool slash asterisk ones;
  define uint16_t etc for Windows ourselves and remove ms_stdint.h &
  stdint_msvc.h as no longer used;
  (backend (excepting test suite) now C89 compatible)
LICENSE: move from backend to root and move COPYING to frontend, with
  copies in frontend_qt & backend_qt, so in where it applies;
  add LICENSE section from manual to root README
This commit is contained in:
gitlost 2022-07-14 16:01:30 +01:00
parent 5ee3895bca
commit 930f458979
70 changed files with 2650 additions and 2038 deletions

View File

@ -20,6 +20,7 @@ Changes
- frontend: batch: for @ use + instead of * on Windows as * not allowed - frontend: batch: for @ use + instead of * on Windows as * not allowed
in filenames in filenames
- Add symbology BC412 (beta) - Add symbology BC412 (beta)
- backend: use alloca() (z_alloca()) for both Unix and Windows
Bugs Bugs
---- ----

10
README
View File

@ -29,6 +29,16 @@ PROJECT HISTORY
Please see "ChangeLog" in the project root directory. Please see "ChangeLog" in the project root directory.
LICENSE
-------
Zint, libzint and Zint Barcode Studio are Copyright © 2022 Robin Stuart. All
historical versions are distributed under the GNU General Public License
version 3 or later. Versions 2.5 and later are released under a dual license:
the encoding library is released under the BSD (3 clause) license whereas the
GUI, Zint Barcode Studio, and the CLI are released under the GNU General Public
License version 3 or later.
CONTACT US CONTACT US
---------- ----------
The home of Zint is: The home of Zint is:

View File

@ -1,3 +1,5 @@
% Tested on Ubuntu 20.04.4 LTS, Ubuntu 22.04 LTS and Fedora Linux 36 (Workstation Edition)
1. Prerequisites for building zint 1. Prerequisites for building zint
================================== ==================================

View File

@ -1,8 +1,7 @@
/* 2of5.c - Handles Code 2 of 5 barcodes */ /* 2of5.c - Handles Code 2 of 5 barcodes */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,7 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
@ -259,7 +258,7 @@ INTERNAL int itf14(struct zint_symbol *symbol, unsigned char source[], int lengt
ustrcpy(symbol->text, localstr); ustrcpy(symbol->text, localstr);
if (!((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND))) { if (!((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND))) {
// If no option has been selected then uses default box option /* If no option has been selected then uses default box option */
symbol->output_options |= BARCODE_BOX; symbol->output_options |= BARCODE_BOX;
if (symbol->border_width == 0) { /* Allow override if non-zero */ if (symbol->border_width == 0) { /* Allow override if non-zero */
/* GS1 General Specifications 21.0.1 Sections 5.3.2.4 & 5.3.6 (4.83 / 1.016 ~ 4.75) */ /* GS1 General Specifications 21.0.1 Sections 5.3.2.4 & 5.3.6 (4.83 / 1.016 ~ 4.75) */
@ -314,7 +313,7 @@ INTERNAL int dpleit(struct zint_symbol *symbol, unsigned char source[], int leng
error_number = c25_inter_common(symbol, localstr, 14, 1 /*dont_set_height*/); error_number = c25_inter_common(symbol, localstr, 14, 1 /*dont_set_height*/);
ustrcpy(symbol->text, localstr); ustrcpy(symbol->text, localstr);
// TODO: Find documentation on BARCODE_DPLEIT dimensions/height /* TODO: Find documentation on BARCODE_DPLEIT dimensions/height */
return error_number; return error_number;
} }
@ -351,7 +350,9 @@ INTERNAL int dpident(struct zint_symbol *symbol, unsigned char source[], int len
error_number = c25_inter_common(symbol, localstr, 12, 1 /*dont_set_height*/); error_number = c25_inter_common(symbol, localstr, 12, 1 /*dont_set_height*/);
ustrcpy(symbol->text, localstr); ustrcpy(symbol->text, localstr);
// TODO: Find documentation on BARCODE_DPIDENT dimensions/height /* TODO: Find documentation on BARCODE_DPIDENT dimensions/height */
return error_number; return error_number;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,5 +1,4 @@
/* aztec.c - Handles Aztec 2D Symbols */ /* aztec.c - Handles Aztec 2D Symbols */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
@ -29,12 +28,10 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "aztec.h" #include "aztec.h"
#include "reedsol.h" #include "reedsol.h"
@ -108,16 +105,9 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
char next_mode; char next_mode;
int reduced_length; int reduced_length;
int byte_mode = 0; int byte_mode = 0;
char *encode_mode = (char *) z_alloca(src_len + 1);
#ifndef _MSC_VER unsigned char *reduced_source = (unsigned char *) z_alloca(src_len + 1);
char encode_mode[src_len + 1]; char *reduced_encode_mode = (char *) z_alloca(src_len + 1);
unsigned char reduced_source[src_len + 1];
char reduced_encode_mode[src_len + 1];
#else
char *encode_mode = (char *) _alloca(src_len + 1);
unsigned char *reduced_source = (unsigned char *) _alloca(src_len + 1);
char *reduced_encode_mode = (char *) _alloca(src_len + 1);
#endif
for (i = 0; i < src_len; i++) { for (i = 0; i < src_len; i++) {
if (source[i] >= 128) { if (source[i] >= 128) {
@ -127,20 +117,20 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} }
} }
// Deal first with letter combinations which can be combined to one codeword /* Deal first with letter combinations which can be combined to one codeword
// Combinations are (CR LF) (. SP) (, SP) (: SP) in Punct mode Combinations are (CR LF) (. SP) (, SP) (: SP) in Punct mode */
current_mode = initial_mode; current_mode = initial_mode;
for (i = 0; i + 1 < src_len; i++) { for (i = 0; i + 1 < src_len; i++) {
// Combination (CR LF) should always be in Punct mode /* Combination (CR LF) should always be in Punct mode */
if ((source[i] == 13) && (source[i + 1] == 10)) { if ((source[i] == 13) && (source[i + 1] == 10)) {
encode_mode[i] = 'P'; encode_mode[i] = 'P';
encode_mode[i + 1] = 'P'; encode_mode[i + 1] = 'P';
// Combination (: SP) should always be in Punct mode /* Combination (: SP) should always be in Punct mode */
} else if ((source[i] == ':') && (source[i + 1] == ' ')) { } else if ((source[i] == ':') && (source[i + 1] == ' ')) {
encode_mode[i + 1] = 'P'; encode_mode[i + 1] = 'P';
// Combinations (. SP) and (, SP) sometimes use fewer bits in Digit mode /* Combinations (. SP) and (, SP) sometimes use fewer bits in Digit mode */
} else if (((source[i] == '.') || (source[i] == ',')) && (source[i + 1] == ' ') && (encode_mode[i] == 'X')) { } else if (((source[i] == '.') || (source[i] == ',')) && (source[i + 1] == ' ') && (encode_mode[i] == 'X')) {
count = az_count_doubles(source, i, src_len); count = az_count_doubles(source, i, src_len);
next_mode = az_get_next_mode(encode_mode, src_len, i); next_mode = az_get_next_mode(encode_mode, src_len, i);
@ -177,7 +167,7 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} }
} }
// Default is Punct mode /* Default is Punct mode */
if (encode_mode[i] == 'X') { if (encode_mode[i] == 'X') {
encode_mode[i] = 'P'; encode_mode[i] = 'P';
encode_mode[i + 1] = 'P'; encode_mode[i + 1] = 'P';
@ -194,12 +184,12 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
printf("%.*s\n", src_len, encode_mode); printf("%.*s\n", src_len, encode_mode);
} }
// Reduce two letter combinations to one codeword marked as [abcd] in Punct mode /* Reduce two letter combinations to one codeword marked as [abcd] in Punct mode */
i = 0; i = 0;
j = 0; j = 0;
while (i < src_len) { while (i < src_len) {
if (i + 1 < src_len) { if (i + 1 < src_len) {
if ((source[i] == 13) && (source[i + 1] == 10)) { // CR LF if ((source[i] == 13) && (source[i + 1] == 10)) { /* CR LF */
reduced_source[j] = 'a'; reduced_source[j] = 'a';
reduced_encode_mode[j] = encode_mode[i]; reduced_encode_mode[j] = encode_mode[i];
i += 2; i += 2;
@ -232,7 +222,7 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
current_mode = initial_mode; current_mode = initial_mode;
for (i = 0; i < reduced_length; i++) { for (i = 0; i < reduced_length; i++) {
// Resolve Carriage Return (CR) which can be Punct or Mixed mode /* Resolve Carriage Return (CR) which can be Punct or Mixed mode */
if (reduced_source[i] == 13) { if (reduced_source[i] == 13) {
count = az_count_chr(reduced_source, i, reduced_length, 13); count = az_count_chr(reduced_source, i, reduced_length, 13);
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i); next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
@ -258,12 +248,12 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} }
} }
// Default is Mixed mode /* Default is Mixed mode */
if (reduced_encode_mode[i] == 'X') { if (reduced_encode_mode[i] == 'X') {
reduced_encode_mode[i] = 'M'; reduced_encode_mode[i] = 'M';
} }
// Resolve full stop and comma which can be in Punct or Digit mode /* Resolve full stop and comma which can be in Punct or Digit mode */
} else if ((reduced_source[i] == '.') || (reduced_source[i] == ',')) { } else if ((reduced_source[i] == '.') || (reduced_source[i] == ',')) {
count = az_count_dotcomma(reduced_source, i, reduced_length); count = az_count_dotcomma(reduced_source, i, reduced_length);
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i); next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
@ -301,12 +291,12 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} }
} }
// Default is Digit mode /* Default is Digit mode */
if (reduced_encode_mode[i] == 'X') { if (reduced_encode_mode[i] == 'X') {
reduced_encode_mode[i] = 'D'; reduced_encode_mode[i] = 'D';
} }
// Resolve Space (SP) which can be any mode except Punct /* Resolve Space (SP) which can be any mode except Punct */
} else if (reduced_source[i] == ' ') { } else if (reduced_source[i] == ' ') {
count = az_count_chr(reduced_source, i, reduced_length, ' '); count = az_count_chr(reduced_source, i, reduced_length, ' ');
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i); next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
@ -374,7 +364,7 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} }
} }
// Default is Digit mode /* Default is Digit mode */
if (reduced_encode_mode[i] == 'X') { if (reduced_encode_mode[i] == 'X') {
reduced_encode_mode[i] = 'D'; reduced_encode_mode[i] = 'D';
} }
@ -385,7 +375,7 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} }
} }
// Decide when to use P/S instead of P/L and U/S instead of U/L /* Decide when to use P/S instead of P/L and U/S instead of U/L */
current_mode = initial_mode; current_mode = initial_mode;
for (i = 0; i < reduced_length; i++) { for (i = 0; i < reduced_length; i++) {
@ -460,41 +450,41 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} }
if (bp == 0 && gs1) { if (bp == 0 && gs1) {
bp = bin_append_posn(0, 5, binary_string, bp); // P/S bp = bin_append_posn(0, 5, binary_string, bp); /* P/S */
bp = bin_append_posn(0, 5, binary_string, bp); // FLG(n) bp = bin_append_posn(0, 5, binary_string, bp); /* FLG(n) */
bp = bin_append_posn(0, 3, binary_string, bp); // FLG(0) bp = bin_append_posn(0, 3, binary_string, bp); /* FLG(0) */
} }
if (eci != 0) { if (eci != 0) {
bp = bin_append_posn(0, initial_mode == 'D' ? 4 : 5, binary_string, bp); // P/S bp = bin_append_posn(0, initial_mode == 'D' ? 4 : 5, binary_string, bp); /* P/S */
bp = bin_append_posn(0, 5, binary_string, bp); // FLG(n) bp = bin_append_posn(0, 5, binary_string, bp); /* FLG(n) */
if (eci < 10) { if (eci < 10) {
bp = bin_append_posn(1, 3, binary_string, bp); // FLG(1) bp = bin_append_posn(1, 3, binary_string, bp); /* FLG(1) */
bp = bin_append_posn(2 + eci, 4, binary_string, bp); bp = bin_append_posn(2 + eci, 4, binary_string, bp);
} else if (eci <= 99) { } else if (eci <= 99) {
bp = bin_append_posn(2, 3, binary_string, bp); // FLG(2) bp = bin_append_posn(2, 3, binary_string, bp); /* FLG(2) */
bp = bin_append_posn(2 + (eci / 10), 4, binary_string, bp); bp = bin_append_posn(2 + (eci / 10), 4, binary_string, bp);
bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp);
} else if (eci <= 999) { } else if (eci <= 999) {
bp = bin_append_posn(3, 3, binary_string, bp); // FLG(3) bp = bin_append_posn(3, 3, binary_string, bp); /* FLG(3) */
bp = bin_append_posn(2 + (eci / 100), 4, binary_string, bp); bp = bin_append_posn(2 + (eci / 100), 4, binary_string, bp);
bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp);
bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp);
} else if (eci <= 9999) { } else if (eci <= 9999) {
bp = bin_append_posn(4, 3, binary_string, bp); // FLG(4) bp = bin_append_posn(4, 3, binary_string, bp); /* FLG(4) */
bp = bin_append_posn(2 + (eci / 1000), 4, binary_string, bp); bp = bin_append_posn(2 + (eci / 1000), 4, binary_string, bp);
bp = bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp); bp = bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp);
bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp);
bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp);
} else if (eci <= 99999) { } else if (eci <= 99999) {
bp = bin_append_posn(5, 3, binary_string, bp); // FLG(5) bp = bin_append_posn(5, 3, binary_string, bp); /* FLG(5) */
bp = bin_append_posn(2 + (eci / 10000), 4, binary_string, bp); bp = bin_append_posn(2 + (eci / 10000), 4, binary_string, bp);
bp = bin_append_posn(2 + ((eci % 10000) / 1000), 4, binary_string, bp); bp = bin_append_posn(2 + ((eci % 10000) / 1000), 4, binary_string, bp);
bp = bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp); bp = bin_append_posn(2 + ((eci % 1000) / 100), 4, binary_string, bp);
bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp); bp = bin_append_posn(2 + ((eci % 100) / 10), 4, binary_string, bp);
bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp); bp = bin_append_posn(2 + (eci % 10), 4, binary_string, bp);
} else { } else {
bp = bin_append_posn(6, 3, binary_string, bp); // FLG(6) bp = bin_append_posn(6, 3, binary_string, bp); /* FLG(6) */
bp = bin_append_posn(2 + (eci / 100000), 4, binary_string, bp); bp = bin_append_posn(2 + (eci / 100000), 4, binary_string, bp);
bp = bin_append_posn(2 + ((eci % 100000) / 10000), 4, binary_string, bp); bp = bin_append_posn(2 + ((eci % 100000) / 10000), 4, binary_string, bp);
bp = bin_append_posn(2 + ((eci % 10000) / 1000), 4, binary_string, bp); bp = bin_append_posn(2 + ((eci % 10000) / 1000), 4, binary_string, bp);
@ -512,133 +502,133 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} }
if ((reduced_encode_mode[i] != current_mode) && (!byte_mode)) { if ((reduced_encode_mode[i] != current_mode) && (!byte_mode)) {
// Change mode /* Change mode */
if (current_mode == 'U') { if (current_mode == 'U') {
switch (reduced_encode_mode[i]) { switch (reduced_encode_mode[i]) {
case 'L': case 'L':
if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; // L/L if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; /* L/L */
break; break;
case 'M': case 'M':
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // M/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* M/L */
break; break;
case 'P': case 'P':
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // M/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* M/L */
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // P/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* P/L */
break; break;
case 'p': case 'p':
if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; // P/S if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; /* P/S */
break; break;
case 'D': case 'D':
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // D/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* D/L */
break; break;
case 'B': case 'B':
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // B/S if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* B/S */
break; break;
} }
} else if (current_mode == 'L') { } else if (current_mode == 'L') {
switch (reduced_encode_mode[i]) { switch (reduced_encode_mode[i]) {
case 'U': case 'U':
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // D/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* D/L */
if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; /* U/L */
break; break;
case 'u': case 'u':
if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; // U/S if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; /* U/S */
break; break;
case 'M': case 'M':
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // M/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* M/L */
break; break;
case 'P': case 'P':
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // M/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* M/L */
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // P/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* P/L */
break; break;
case 'p': case 'p':
if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; // P/S if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; /* P/S */
break; break;
case 'D': case 'D':
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // D/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* D/L */
break; break;
case 'B': case 'B':
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // B/S if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* B/S */
break; break;
} }
} else if (current_mode == 'M') { } else if (current_mode == 'M') {
switch (reduced_encode_mode[i]) { switch (reduced_encode_mode[i]) {
case 'U': case 'U':
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* U/L */
break; break;
case 'L': case 'L':
if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; // L/L if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; /* L/L */
break; break;
case 'P': case 'P':
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // P/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* P/L */
break; break;
case 'p': case 'p':
if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; // P/S if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; /* P/S */
break; break;
case 'D': case 'D':
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* U/L */
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // D/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* D/L */
break; break;
case 'B': case 'B':
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // B/S if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* B/S */
break; break;
} }
} else if (current_mode == 'P') { } else if (current_mode == 'P') {
switch (reduced_encode_mode[i]) { switch (reduced_encode_mode[i]) {
case 'U': case 'U':
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* U/L */
break; break;
case 'L': case 'L':
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* U/L */
if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; // L/L if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; /* L/L */
break; break;
case 'M': case 'M':
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* U/L */
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // M/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* M/L */
break; break;
case 'D': case 'D':
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* U/L */
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // D/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* D/L */
break; break;
case 'B': case 'B':
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* U/L */
current_mode = 'U'; current_mode = 'U';
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // B/S if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* B/S */
break; break;
} }
} else if (current_mode == 'D') { } else if (current_mode == 'D') {
switch (reduced_encode_mode[i]) { switch (reduced_encode_mode[i]) {
case 'U': case 'U':
if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; /* U/L */
break; break;
case 'u': case 'u':
if (!(bp = az_bin_append_posn(15, 4, binary_string, bp))) return 0; // U/S if (!(bp = az_bin_append_posn(15, 4, binary_string, bp))) return 0; /* U/S */
break; break;
case 'L': case 'L':
if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; /* U/L */
if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; // L/L if (!(bp = az_bin_append_posn(28, 5, binary_string, bp))) return 0; /* L/L */
break; break;
case 'M': case 'M':
if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; /* U/L */
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // M/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* M/L */
break; break;
case 'P': case 'P':
if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; /* U/L */
if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; // M/L if (!(bp = az_bin_append_posn(29, 5, binary_string, bp))) return 0; /* M/L */
if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; // P/L if (!(bp = az_bin_append_posn(30, 5, binary_string, bp))) return 0; /* P/L */
break; break;
case 'p': case 'p':
if (!(bp = az_bin_append_posn(0, 4, binary_string, bp))) return 0; // P/S if (!(bp = az_bin_append_posn(0, 4, binary_string, bp))) return 0; /* P/S */
break; break;
case 'B': case 'B':
if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; // U/L if (!(bp = az_bin_append_posn(14, 4, binary_string, bp))) return 0; /* U/L */
current_mode = 'U'; current_mode = 'U';
if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; // B/S if (!(bp = az_bin_append_posn(31, 5, binary_string, bp))) return 0; /* B/S */
break; break;
} }
} }
// Byte mode length descriptor /* Byte mode length descriptor */
if ((reduced_encode_mode[i] == 'B') && (!byte_mode)) { if ((reduced_encode_mode[i] == 'B') && (!byte_mode)) {
for (count = 0; ((i + count) < reduced_length) && (reduced_encode_mode[i + count] == 'B'); count++); for (count = 0; ((i + count) < reduced_length) && (reduced_encode_mode[i + count] == 'B'); count++);
@ -665,56 +655,56 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
if ((reduced_encode_mode[i] == 'U') || (reduced_encode_mode[i] == 'u')) { if ((reduced_encode_mode[i] == 'U') || (reduced_encode_mode[i] == 'u')) {
if (reduced_source[i] == ' ') { if (reduced_source[i] == ' ') {
if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; // SP if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; /* SP */
} else { } else {
if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 5, binary_string, bp))) if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 5, binary_string, bp)))
return 0; return 0;
} }
} else if (reduced_encode_mode[i] == 'L') { } else if (reduced_encode_mode[i] == 'L') {
if (reduced_source[i] == ' ') { if (reduced_source[i] == ' ') {
if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; // SP if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; /* SP */
} else { } else {
if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 5, binary_string, bp))) if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 5, binary_string, bp)))
return 0; return 0;
} }
} else if (reduced_encode_mode[i] == 'M') { } else if (reduced_encode_mode[i] == 'M') {
if (reduced_source[i] == ' ') { if (reduced_source[i] == ' ') {
if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; // SP if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; /* SP */
} else if (reduced_source[i] == 13) { } else if (reduced_source[i] == 13) {
if (!(bp = az_bin_append_posn(14, 5, binary_string, bp))) return 0; // CR if (!(bp = az_bin_append_posn(14, 5, binary_string, bp))) return 0; /* CR */
} else { } else {
if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 5, binary_string, bp))) if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 5, binary_string, bp)))
return 0; return 0;
} }
} else if ((reduced_encode_mode[i] == 'P') || (reduced_encode_mode[i] == 'p')) { } else if ((reduced_encode_mode[i] == 'P') || (reduced_encode_mode[i] == 'p')) {
if (gs1 && (reduced_source[i] == '[')) { if (gs1 && (reduced_source[i] == '[')) {
if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; // FLG(n) if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; /* FLG(n) */
if (!(bp = az_bin_append_posn(0, 3, binary_string, bp))) return 0; // FLG(0) = FNC1 if (!(bp = az_bin_append_posn(0, 3, binary_string, bp))) return 0; /* FLG(0) = FNC1 */
} else if (reduced_source[i] == 13) { } else if (reduced_source[i] == 13) {
if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; // CR if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; /* CR */
} else if (reduced_source[i] == 'a') { } else if (reduced_source[i] == 'a') {
if (!(bp = az_bin_append_posn(2, 5, binary_string, bp))) return 0; // CR LF if (!(bp = az_bin_append_posn(2, 5, binary_string, bp))) return 0; /* CR LF */
} else if (reduced_source[i] == 'b') { } else if (reduced_source[i] == 'b') {
if (!(bp = az_bin_append_posn(3, 5, binary_string, bp))) return 0; // . SP if (!(bp = az_bin_append_posn(3, 5, binary_string, bp))) return 0; /* . SP */
} else if (reduced_source[i] == 'c') { } else if (reduced_source[i] == 'c') {
if (!(bp = az_bin_append_posn(4, 5, binary_string, bp))) return 0; // , SP if (!(bp = az_bin_append_posn(4, 5, binary_string, bp))) return 0; /* , SP */
} else if (reduced_source[i] == 'd') { } else if (reduced_source[i] == 'd') {
if (!(bp = az_bin_append_posn(5, 5, binary_string, bp))) return 0; // : SP if (!(bp = az_bin_append_posn(5, 5, binary_string, bp))) return 0; /* : SP */
} else if (reduced_source[i] == ',') { } else if (reduced_source[i] == ',') {
if (!(bp = az_bin_append_posn(17, 5, binary_string, bp))) return 0; // Comma if (!(bp = az_bin_append_posn(17, 5, binary_string, bp))) return 0; /* Comma */
} else if (reduced_source[i] == '.') { } else if (reduced_source[i] == '.') {
if (!(bp = az_bin_append_posn(19, 5, binary_string, bp))) return 0; // Full stop if (!(bp = az_bin_append_posn(19, 5, binary_string, bp))) return 0; /* Full stop */
} else { } else {
if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 5, binary_string, bp))) if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 5, binary_string, bp)))
return 0; return 0;
} }
} else if (reduced_encode_mode[i] == 'D') { } else if (reduced_encode_mode[i] == 'D') {
if (reduced_source[i] == ' ') { if (reduced_source[i] == ' ') {
if (!(bp = az_bin_append_posn(1, 4, binary_string, bp))) return 0; // SP if (!(bp = az_bin_append_posn(1, 4, binary_string, bp))) return 0; /* SP */
} else if (reduced_source[i] == ',') { } else if (reduced_source[i] == ',') {
if (!(bp = az_bin_append_posn(12, 4, binary_string, bp))) return 0; // Comma if (!(bp = az_bin_append_posn(12, 4, binary_string, bp))) return 0; /* Comma */
} else if (reduced_source[i] == '.') { } else if (reduced_source[i] == '.') {
if (!(bp = az_bin_append_posn(13, 4, binary_string, bp))) return 0; // Full stop if (!(bp = az_bin_append_posn(13, 4, binary_string, bp))) return 0; /* Full stop */
} else { } else {
if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 4, binary_string, bp))) if (!(bp = az_bin_append_posn(AztecSymbolChar[(int) reduced_source[i]], 4, binary_string, bp)))
return 0; return 0;
@ -859,11 +849,8 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT); const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT);
rs_t rs; rs_t rs;
rs_uint_t rs_uint; rs_uint_t rs_uint;
#ifdef _MSC_VER
unsigned int *data_part; unsigned int *data_part;
unsigned int *ecc_part; unsigned int *ecc_part;
#endif
if (symbol->output_options & READER_INIT) { if (symbol->output_options & READER_INIT) {
reader = 1; reader = 1;
@ -896,8 +883,8 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
} }
bp = bin_append_posn(29, 5, binary_string, bp); // M/L bp = bin_append_posn(29, 5, binary_string, bp); /* M/L */
bp = bin_append_posn(29, 5, binary_string, bp); // U/L bp = bin_append_posn(29, 5, binary_string, bp); /* U/L */
sa_len = 0; sa_len = 0;
if (id_len) { /* ID has a space on either side */ if (id_len) { /* ID has a space on either side */
@ -1032,12 +1019,12 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
count = 0; count = 0;
for (i = 0; i < data_length; i++) { for (i = 0; i < data_length; i++) {
if ((j + 1) % codeword_size == 0) { if ((j + 1) % codeword_size == 0) {
// Last bit of codeword /* Last bit of codeword */
/* 7.3.1.2 "whenever the first B-1 bits ... are all “0”s, then a dummy “1” is inserted..." /* 7.3.1.2 "whenever the first B-1 bits ... are all “0”s, then a dummy “1” is inserted..."
* "Similarly a message codeword that starts with B-1 “1”s has a dummy “0” inserted..." */ "Similarly a message codeword that starts with B-1 “1”s has a dummy “0” inserted..." */
if (count == 0 || count == (codeword_size - 1)) { if (count == 0 || count == (codeword_size - 1)) {
// Codeword of B-1 '0's or B-1 '1's /* Codeword of B-1 '0's or B-1 '1's */
adjusted_string[j] = count == 0 ? '1' : '0'; adjusted_string[j] = count == 0 ? '1' : '0';
j++; j++;
count = binary_string[i] == '1' ? 1 : 0; count = binary_string[i] == '1' ? 1 : 0;
@ -1126,10 +1113,10 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
for (i = 0; i < data_length; i++) { for (i = 0; i < data_length; i++) {
if ((j + 1) % codeword_size == 0) { if ((j + 1) % codeword_size == 0) {
// Last bit of codeword /* Last bit of codeword */
if (count == 0 || count == (codeword_size - 1)) { if (count == 0 || count == (codeword_size - 1)) {
// Codeword of B-1 '0's or B-1 '1's /* Codeword of B-1 '0's or B-1 '1's */
adjusted_string[j] = count == 0 ? '1' : '0'; adjusted_string[j] = count == 0 ? '1' : '0';
j++; j++;
count = binary_string[i] == '1' ? 1 : 0; count = binary_string[i] == '1' ? 1 : 0;
@ -1210,12 +1197,9 @@ INTERNAL int aztec(struct zint_symbol *symbol, struct zint_seg segs[], const int
printf(" (%d data words, %d ecc words)\n", data_blocks, ecc_blocks); printf(" (%d data words, %d ecc words)\n", data_blocks, ecc_blocks);
} }
#ifndef _MSC_VER data_part = (unsigned int *) z_alloca(sizeof(unsigned int) * data_blocks);
unsigned int data_part[data_blocks], ecc_part[ecc_blocks]; ecc_part = (unsigned int *) z_alloca(sizeof(unsigned int) * ecc_blocks);
#else
data_part = (unsigned int *) _alloca(sizeof(unsigned int) * data_blocks);
ecc_part = (unsigned int *) _alloca(sizeof(unsigned int) * ecc_blocks);
#endif
/* Copy across data into separate integers */ /* Copy across data into separate integers */
memset(data_part, 0, sizeof(unsigned int) * data_blocks); memset(data_part, 0, sizeof(unsigned int) * data_blocks);
memset(ecc_part, 0, sizeof(unsigned int) * ecc_blocks); memset(ecc_part, 0, sizeof(unsigned int) * ecc_blocks);

View File

@ -1,5 +1,4 @@
/* aztec.h - Handles Aztec 2D Symbols */ /* aztec.h - Handles Aztec 2D Symbols */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
@ -29,40 +28,41 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef Z_AZTEC_H #ifndef Z_AZTEC_H
#define Z_AZTEC_H #define Z_AZTEC_H
static const short AztecCompactMap[] = { static const short AztecCompactMap[] = {
/* 27 x 27 data grid */ /* 27 x 27 data grid */
609, 608, 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, // 0 609, 608, 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, /* 0 */
607, 606, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, // 1 607, 606, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, /* 1 */
605, 604, 409, 408, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 460, 461, // 2 605, 604, 409, 408, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 460, 461, /* 2 */
603, 602, 407, 406, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 462, 463, // 3 603, 602, 407, 406, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272, 274, 276, 278, 280, 282, 462, 463, /* 3 */
601, 600, 405, 404, 241, 240, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 284, 285, 464, 465, // 4 601, 600, 405, 404, 241, 240, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 284, 285, 464, 465, /* 4 */
599, 598, 403, 402, 239, 238, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 286, 287, 466, 467, // 5 599, 598, 403, 402, 239, 238, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 286, 287, 466, 467, /* 5 */
597, 596, 401, 400, 237, 236, 105, 104, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 140, 141, 288, 289, 468, 469, // 6 597, 596, 401, 400, 237, 236, 105, 104, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 140, 141, 288, 289, 468, 469, /* 6 */
595, 594, 399, 398, 235, 234, 103, 102, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 142, 143, 290, 291, 470, 471, // 7 595, 594, 399, 398, 235, 234, 103, 102, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 142, 143, 290, 291, 470, 471, /* 7 */
593, 592, 397, 396, 233, 232, 101, 100, 1, 1, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 0, 1, 28, 29, 144, 145, 292, 293, 472, 473, // 8 593, 592, 397, 396, 233, 232, 101, 100, 1, 1, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 0, 1, 28, 29, 144, 145, 292, 293, 472, 473, /* 8 */
591, 590, 395, 394, 231, 230, 99, 98, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 30, 31, 146, 147, 294, 295, 474, 475, // 9 591, 590, 395, 394, 231, 230, 99, 98, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 30, 31, 146, 147, 294, 295, 474, 475, /* 9 */
589, 588, 393, 392, 229, 228, 97, 96, 2027, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2007, 32, 33, 148, 149, 296, 297, 476, 477, // 10 589, 588, 393, 392, 229, 228, 97, 96, 2027, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2007, 32, 33, 148, 149, 296, 297, 476, 477, /* 10 */
587, 586, 391, 390, 227, 226, 95, 94, 2026, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2008, 34, 35, 150, 151, 298, 299, 478, 479, // 11 587, 586, 391, 390, 227, 226, 95, 94, 2026, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2008, 34, 35, 150, 151, 298, 299, 478, 479, /* 11 */
585, 584, 389, 388, 225, 224, 93, 92, 2025, 1, 0, 1, 0, 0, 0, 1, 0, 1, 2009, 36, 37, 152, 153, 300, 301, 480, 481, // 12 585, 584, 389, 388, 225, 224, 93, 92, 2025, 1, 0, 1, 0, 0, 0, 1, 0, 1, 2009, 36, 37, 152, 153, 300, 301, 480, 481, /* 12 */
583, 582, 387, 386, 223, 222, 91, 90, 2024, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2010, 38, 39, 154, 155, 302, 303, 482, 483, // 13 583, 582, 387, 386, 223, 222, 91, 90, 2024, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2010, 38, 39, 154, 155, 302, 303, 482, 483, /* 13 */
581, 580, 385, 384, 221, 220, 89, 88, 2023, 1, 0, 1, 0, 0, 0, 1, 0, 1, 2011, 40, 41, 156, 157, 304, 305, 484, 485, // 14 581, 580, 385, 384, 221, 220, 89, 88, 2023, 1, 0, 1, 0, 0, 0, 1, 0, 1, 2011, 40, 41, 156, 157, 304, 305, 484, 485, /* 14 */
579, 578, 383, 382, 219, 218, 87, 86, 2022, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2012, 42, 43, 158, 159, 306, 307, 486, 487, // 15 579, 578, 383, 382, 219, 218, 87, 86, 2022, 1, 0, 1, 1, 1, 1, 1, 0, 1, 2012, 42, 43, 158, 159, 306, 307, 486, 487, /* 15 */
577, 576, 381, 380, 217, 216, 85, 84, 2021, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2013, 44, 45, 160, 161, 308, 309, 488, 489, // 16 577, 576, 381, 380, 217, 216, 85, 84, 2021, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2013, 44, 45, 160, 161, 308, 309, 488, 489, /* 16 */
575, 574, 379, 378, 215, 214, 83, 82, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46, 47, 162, 163, 310, 311, 490, 491, // 17 575, 574, 379, 378, 215, 214, 83, 82, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 46, 47, 162, 163, 310, 311, 490, 491, /* 17 */
573, 572, 377, 376, 213, 212, 81, 80, 0, 0, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 0, 0, 48, 49, 164, 165, 312, 313, 492, 493, // 18 573, 572, 377, 376, 213, 212, 81, 80, 0, 0, 2020, 2019, 2018, 2017, 2016, 2015, 2014, 0, 0, 48, 49, 164, 165, 312, 313, 492, 493, /* 18 */
571, 570, 375, 374, 211, 210, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 50, 51, 166, 167, 314, 315, 494, 495, // 19 571, 570, 375, 374, 211, 210, 78, 76, 74, 72, 70, 68, 66, 64, 62, 60, 58, 56, 54, 50, 51, 166, 167, 314, 315, 494, 495, /* 19 */
569, 568, 373, 372, 209, 208, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59, 57, 55, 52, 53, 168, 169, 316, 317, 496, 497, // 20 569, 568, 373, 372, 209, 208, 79, 77, 75, 73, 71, 69, 67, 65, 63, 61, 59, 57, 55, 52, 53, 168, 169, 316, 317, 496, 497, /* 20 */
567, 566, 371, 370, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 170, 171, 318, 319, 498, 499, // 21 567, 566, 371, 370, 206, 204, 202, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 170, 171, 318, 319, 498, 499, /* 21 */
565, 564, 369, 368, 207, 205, 203, 201, 199, 197, 195, 193, 191, 189, 187, 185, 183, 181, 179, 177, 175, 172, 173, 320, 321, 500, 501, // 22 565, 564, 369, 368, 207, 205, 203, 201, 199, 197, 195, 193, 191, 189, 187, 185, 183, 181, 179, 177, 175, 172, 173, 320, 321, 500, 501, /* 22 */
563, 562, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 322, 323, 502, 503, // 23 563, 562, 366, 364, 362, 360, 358, 356, 354, 352, 350, 348, 346, 344, 342, 340, 338, 336, 334, 332, 330, 328, 326, 322, 323, 502, 503, /* 23 */
561, 560, 367, 365, 363, 361, 359, 357, 355, 353, 351, 349, 347, 345, 343, 341, 339, 337, 335, 333, 331, 329, 327, 324, 325, 504, 505, // 24 561, 560, 367, 365, 363, 361, 359, 357, 355, 353, 351, 349, 347, 345, 343, 341, 339, 337, 335, 333, 331, 329, 327, 324, 325, 504, 505, /* 24 */
558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 506, 507, // 25 558, 556, 554, 552, 550, 548, 546, 544, 542, 540, 538, 536, 534, 532, 530, 528, 526, 524, 522, 520, 518, 516, 514, 512, 510, 506, 507, /* 25 */
559, 557, 555, 553, 551, 549, 547, 545, 543, 541, 539, 537, 535, 533, 531, 529, 527, 525, 523, 521, 519, 517, 515, 513, 511, 508, 509, // 26 559, 557, 555, 553, 551, 549, 547, 545, 543, 541, 539, 537, 535, 533, 531, 529, 527, 525, 523, 521, 519, 517, 515, 513, 511, 508, 509, /* 26 */
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 */
}; };
/* Pre-calculated finder, descriptor, orientation mappings for full-range symbol */ /* Pre-calculated finder, descriptor, orientation mappings for full-range symbol */

View File

@ -1,8 +1,7 @@
/* bmp.c - Handles output to Windows Bitmap file */ /* bmp.c - Handles output to Windows Bitmap file */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,7 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
@ -103,31 +102,31 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
for (column = 0; column < symbol->bitmap_width; column++) { for (column = 0; column < symbol->bitmap_width; column++) {
i = (column / 2) + (row * row_size); i = (column / 2) + (row * row_size);
switch (*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) { switch (*(pixelbuf + (symbol->bitmap_width * (symbol->bitmap_height - row - 1)) + column)) {
case 'C': // Cyan case 'C': /* Cyan */
bitmap[i] += 1 << (4 * (1 - (column % 2))); bitmap[i] += 1 << (4 * (1 - (column % 2)));
break; break;
case 'B': // Blue case 'B': /* Blue */
bitmap[i] += 2 << (4 * (1 - (column % 2))); bitmap[i] += 2 << (4 * (1 - (column % 2)));
break; break;
case 'M': // Magenta case 'M': /* Magenta */
bitmap[i] += 3 << (4 * (1 - (column % 2))); bitmap[i] += 3 << (4 * (1 - (column % 2)));
break; break;
case 'R': // Red case 'R': /* Red */
bitmap[i] += 4 << (4 * (1 - (column % 2))); bitmap[i] += 4 << (4 * (1 - (column % 2)));
break; break;
case 'Y': // Yellow case 'Y': /* Yellow */
bitmap[i] += 5 << (4 * (1 - (column % 2))); bitmap[i] += 5 << (4 * (1 - (column % 2)));
break; break;
case 'G': // Green case 'G': /* Green */
bitmap[i] += 6 << (4 * (1 - (column % 2))); bitmap[i] += 6 << (4 * (1 - (column % 2)));
break; break;
case 'K': // Black case 'K': /* Black */
bitmap[i] += 7 << (4 * (1 - (column % 2))); bitmap[i] += 7 << (4 * (1 - (column % 2)));
break; break;
case 'W': // White case 'W': /* White */
bitmap[i] += 8 << (4 * (1 - (column % 2))); bitmap[i] += 8 << (4 * (1 - (column % 2)));
break; break;
case '1': // Foreground case '1': /* Foreground */
bitmap[i] += ultra_fg_index << (4 * (1 - (column % 2))); bitmap[i] += ultra_fg_index << (4 * (1 - (column % 2)));
break; break;
} }
@ -146,7 +145,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
symbol->bitmap_byte_length = data_size; symbol->bitmap_byte_length = data_size;
file_header.header_field = 0x4d42; // "BM" file_header.header_field = 0x4d42; /* "BM" */
file_header.file_size = file_size; file_header.file_size = file_size;
file_header.reserved = 0; file_header.reserved = 0;
file_header.data_offset = data_offset; file_header.data_offset = data_offset;
@ -156,7 +155,7 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
info_header.height = symbol->bitmap_height; info_header.height = symbol->bitmap_height;
info_header.colour_planes = 1; info_header.colour_planes = 1;
info_header.bits_per_pixel = bits_per_pixel; info_header.bits_per_pixel = bits_per_pixel;
info_header.compression_method = 0; // BI_RGB info_header.compression_method = 0; /* BI_RGB */
info_header.image_size = 0; info_header.image_size = 0;
info_header.horiz_res = 0; info_header.horiz_res = 0;
info_header.vert_res = 0; info_header.vert_res = 0;
@ -213,3 +212,5 @@ INTERNAL int bmp_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
free(bitmap_file_start); free(bitmap_file_start);
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,7 +1,7 @@
/* bmp.h - header structure for Windows bitmap files /* bmp.h - header structure for Windows bitmap files */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,21 +28,15 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef BMP_H #ifndef Z_BMP_H
#define BMP_H #define Z_BMP_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef _MSC_VER
#include <windows.h>
#include "stdint_msvc.h"
#else
#include <stdint.h>
#endif
#pragma pack (1) #pragma pack (1)
typedef struct bitmap_file_header { typedef struct bitmap_file_header {
@ -79,6 +73,5 @@ extern "C" {
} }
#endif #endif
#endif /* BMP_H */ /* vim: set ts=4 sw=4 et : */
#endif /* Z_BMP_H */

View File

@ -32,9 +32,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include <assert.h> #include <assert.h>
#include "common.h" #include "common.h"
#include "code128.h" #include "code128.h"
@ -423,11 +420,7 @@ static int Rows2Columns(struct zint_symbol *symbol, CharacterSetTable *T, const
int testColumns; /* To enter into Width2Rows */ int testColumns; /* To enter into Width2Rows */
int testListSize = 0; int testListSize = 0;
int pTestList[62 + 1]; int pTestList[62 + 1];
#ifndef _MSC_VER int *pBackupSet = (int *) z_alloca(sizeof(int) * dataLength);
int *pBackupSet[dataLength];
#else
int *pBackupSet = (int *)_alloca(dataLength*sizeof(int));
#endif
rowsRequested=*pRows; rowsRequested=*pRows;
columnsRequested = *pUseColumns >= 4 ? *pUseColumns : 0; columnsRequested = *pUseColumns >= 4 ? *pUseColumns : 0;
@ -594,12 +587,10 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
int emptyColumns; int emptyColumns;
char dest[1000]; char dest[1000];
int r, c; int r, c;
#ifdef _MSC_VER
CharacterSetTable *T; CharacterSetTable *T;
unsigned char *data; unsigned char *data;
int *pSet; int *pSet;
uchar *pOutput; uchar *pOutput;
#endif
/* Suppresses clang-analyzer-core.VLASize warning */ /* Suppresses clang-analyzer-core.VLASize warning */
assert(length > 0); assert(length > 0);
@ -635,11 +626,7 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
} }
#ifndef _MSC_VER data = (unsigned char *) z_alloca(length * 2 + 1);
unsigned char data[length*2+1];
#else
data = (unsigned char *) _alloca(length * 2+1);
#endif
dataLength = 0; dataLength = 0;
if (symbol->output_options & READER_INIT) { if (symbol->output_options & READER_INIT) {
@ -659,13 +646,8 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
} }
/* Build character set table */ /* Build character set table */
#ifndef _MSC_VER T = (CharacterSetTable *) z_alloca(sizeof(CharacterSetTable) * dataLength);
CharacterSetTable T[dataLength]; pSet = (int *) z_alloca(sizeof(int) * dataLength);
int pSet[dataLength];
#else
T=(CharacterSetTable *)_alloca(dataLength*sizeof(CharacterSetTable));
pSet = (int *)_alloca(dataLength*sizeof(int));
#endif
CreateCharacterSetTable(T,data,dataLength); CreateCharacterSetTable(T,data,dataLength);
/* Find final row and column count */ /* Find final row and column count */
@ -739,11 +721,7 @@ INTERNAL int codablockf(struct zint_symbol *symbol, unsigned char source[], int
/* >>> Build C128 code numbers */ /* >>> Build C128 code numbers */
/* The C128 column count contains Start (2CW), Row ID, Checksum, Stop */ /* The C128 column count contains Start (2CW), Row ID, Checksum, Stop */
#ifndef _MSC_VER pOutput = (unsigned char *) z_alloca(columns * rows);
uchar pOutput[columns * rows];
#else
pOutput = (unsigned char *) _alloca(columns * rows);
#endif
pOutPos = pOutput; pOutPos = pOutput;
charCur=0; charCur=0;
/* >> Loop over rows */ /* >> Loop over rows */

View File

@ -1,8 +1,7 @@
/* code.c - Handles Code 11, 39, 39+, 93, PZN, Channel and VIN */ /* code.c - Handles Code 11, 39, 39+, 93, PZN, Channel and VIN */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,12 +28,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
/* In version 0.5 this file was 1,553 lines long! */ /* In version 0.5 this file was 1,553 lines long! */
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "common.h" #include "common.h"
#define SODIUM_MNS_F (IS_NUM_F | IS_MNS_F) /* SODIUM "0123456789-" */ #define SODIUM_MNS_F (IS_NUM_F | IS_MNS_F) /* SODIUM "0123456789-" */
@ -228,7 +227,7 @@ INTERNAL int code11(struct zint_symbol *symbol, unsigned char source[], int leng
expand(symbol, dest, d - dest); expand(symbol, dest, d - dest);
// TODO: Find documentation on BARCODE_CODE11 dimensions/height /* TODO: Find documentation on BARCODE_CODE11 dimensions/height */
ustrcpy(symbol->text, source); ustrcpy(symbol->text, source);
if (num_check_digits) { if (num_check_digits) {
@ -336,7 +335,7 @@ INTERNAL int code39(struct zint_symbol *symbol, unsigned char source[], int leng
error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f, error_number = set_height(symbol, min_height, min_height > 50.0f ? min_height : 50.0f, 0.0f,
0 /*no_errtxt*/); 0 /*no_errtxt*/);
} }
// PZN and CODE32 set their own heights /* PZN and CODE32 set their own heights */
} else { } else {
(void) set_height(symbol, 0.0f, 50.f, 0.0f, 1 /*no_errtxt*/); (void) set_height(symbol, 0.0f, 50.f, 0.0f, 1 /*no_errtxt*/);
} }
@ -569,7 +568,7 @@ typedef const struct s_channel_precalc {
long value; unsigned char B[8]; unsigned char S[8]; unsigned char bmax[7]; unsigned char smax[7]; long value; unsigned char B[8]; unsigned char S[8]; unsigned char bmax[7]; unsigned char smax[7];
} channel_precalc; } channel_precalc;
//#define CHANNEL_GENERATE_PRECALCS /*#define CHANNEL_GENERATE_PRECALCS*/
#ifdef CHANNEL_GENERATE_PRECALCS #ifdef CHANNEL_GENERATE_PRECALCS
/* To generate precalc tables uncomment CHANNEL_GENERATE_PRECALCS define and run /* To generate precalc tables uncomment CHANNEL_GENERATE_PRECALCS define and run
@ -803,13 +802,13 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length)
int i; int i;
static const int weight[17] = {8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2}; static const int weight[17] = {8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2};
// Check length /* Check length */
if (length != 17) { if (length != 17) {
strcpy(symbol->errtxt, "336: Input wrong length (17 characters required)"); strcpy(symbol->errtxt, "336: Input wrong length (17 characters required)");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
// Check input characters, I, O and Q are not allowed /* Check input characters, I, O and Q are not allowed */
if (!is_sane(ARSENIC_F, source, length)) { if (!is_sane(ARSENIC_F, source, length)) {
strcpy(symbol->errtxt, strcpy(symbol->errtxt,
"337: Invalid character in data (alphanumerics only, excluding \"I\", \"O\" and \"Q\")"); "337: Invalid character in data (alphanumerics only, excluding \"I\", \"O\" and \"Q\")");
@ -818,7 +817,7 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length)
to_upper(source, length); to_upper(source, length);
// Check digit only valid for North America /* Check digit only valid for North America */
if (source[0] >= '1' && source[0] <= '5') { if (source[0] >= '1' && source[0] <= '5') {
input_check = source[8]; input_check = source[8];
@ -840,7 +839,7 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length)
output_check = '0' + (sum % 11); output_check = '0' + (sum % 11);
if (output_check == ':') { if (output_check == ':') {
// Check digit was 10 /* Check digit was 10 */
output_check = 'X'; output_check = 'X';
} }
@ -866,7 +865,7 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length)
d += 10; d += 10;
} }
// Copy glyphs to symbol /* Copy glyphs to symbol */
for (i = 0; i < 17; i++, d += 10) { for (i = 0; i < 17; i++, d += 10) {
memcpy(d, C39Table[posn(SILVER, source[i])], 10); memcpy(d, C39Table[posn(SILVER, source[i])], 10);
} }
@ -883,3 +882,5 @@ INTERNAL int vin(struct zint_symbol *symbol, unsigned char source[], int length)
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -30,15 +30,12 @@
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <math.h>
#include <stdio.h>
#include "common.h" #include "common.h"
#include "code1.h" #include "code1.h"
#include "reedsol.h" #include "reedsol.h"
#include "large.h" #include "large.h"
#include <stdio.h>
#include <math.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
/* Add solid bar */ /* Add solid bar */
static void c1_horiz(struct zint_symbol *symbol, const int row_no, const int full) { static void c1_horiz(struct zint_symbol *symbol, const int row_no, const int full) {
@ -486,13 +483,8 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len
int byte_start = 0; int byte_start = 0;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
const int eci_length = length + 7 + chr_cnt(source, length, '\\'); const int eci_length = length + 7 + chr_cnt(source, length, '\\');
#ifndef _MSC_VER unsigned char *eci_buf = (unsigned char *) z_alloca(eci_length + 1);
unsigned char eci_buf[eci_length + 1]; int *num_digits = (int *) z_alloca(sizeof(int) * (eci_length + 1));
int num_digits[eci_length + 1];
#else
unsigned char *eci_buf = (unsigned char *) _alloca(eci_length + 1);
int *num_digits = (int *) _alloca(sizeof(int) * (eci_length + 1));
#endif
memset(num_digits, 0, sizeof(int) * (eci_length + 1)); memset(num_digits, 0, sizeof(int) * (eci_length + 1));

View File

@ -1,5 +1,4 @@
/* code128.c - Handles Code 128 and derivatives */ /* code128.c - Handles Code 128 and derivatives */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
@ -32,11 +31,8 @@
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include <assert.h> #include <assert.h>
#include <stdio.h>
#include "common.h" #include "common.h"
#include "code128.h" #include "code128.h"
#include "gs1.h" #include "gs1.h"
@ -746,11 +742,7 @@ INTERNAL int gs1_128_cc(struct zint_symbol *symbol, unsigned char source[], int
char *d = dest; char *d = dest;
int separator_row, linkage_flag; int separator_row, linkage_flag;
int reduced_length; int reduced_length;
#ifndef _MSC_VER unsigned char *reduced = (unsigned char *) z_alloca(length + 1);
unsigned char reduced[length + 1];
#else
unsigned char *reduced = (unsigned char *) _alloca(length + 1);
#endif
linkage_flag = 0; linkage_flag = 0;
@ -1078,7 +1070,7 @@ INTERNAL int dpd(struct zint_symbol *symbol, unsigned char source[], int length)
int i, p; int i, p;
unsigned char identifier; unsigned char identifier;
const int mod = 36; const int mod = 36;
int cd; // Check digit int cd; /* Check digit */
if (length != 28) { if (length != 28) {
strcpy(symbol->errtxt, "349: DPD input wrong length (28 characters required)"); strcpy(symbol->errtxt, "349: DPD input wrong length (28 characters required)");

View File

@ -34,9 +34,6 @@
#ifdef ZINT_TEST #ifdef ZINT_TEST
#include <stdio.h> #include <stdio.h>
#endif #endif
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
/* Converts a character 0-9, A-F to its equivalent integer value */ /* Converts a character 0-9, A-F to its equivalent integer value */
@ -548,10 +545,10 @@ INTERNAL int colour_to_red(const int colour) {
int return_val = 0; int return_val = 0;
switch (colour) { switch (colour) {
case 8: // White case 8: /* White */
case 3: // Magenta case 3: /* Magenta */
case 4: // Red case 4: /* Red */
case 5: // Yellow case 5: /* Yellow */
return_val = 255; return_val = 255;
break; break;
} }
@ -564,10 +561,10 @@ INTERNAL int colour_to_green(const int colour) {
int return_val = 0; int return_val = 0;
switch (colour) { switch (colour) {
case 8: // White case 8: /* White */
case 1: // Cyan case 1: /* Cyan */
case 5: // Yellow case 5: /* Yellow */
case 6: // Green case 6: /* Green */
return_val = 255; return_val = 255;
break; break;
} }
@ -580,10 +577,10 @@ INTERNAL int colour_to_blue(const int colour) {
int return_val = 0; int return_val = 0;
switch (colour) { switch (colour) {
case 8: // White case 8: /* White */
case 1: // Cyan case 1: /* Cyan */
case 2: // Blue case 2: /* Blue */
case 3: // Magenta case 3: /* Magenta */
return_val = 255; return_val = 255;
break; break;
} }

View File

@ -45,6 +45,26 @@
#define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0]))) #define ARRAY_SIZE(x) ((int) (sizeof(x) / sizeof((x)[0])))
#endif #endif
#ifdef _MSC_VER
# include <malloc.h>
# define z_alloca(nmemb) _alloca(nmemb)
#else
# if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L /* C89 */
# include <alloca.h>
# endif
# define z_alloca(nmemb) alloca(nmemb)
#endif
#ifdef _MSC_VER
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#else
#include <stdint.h>
#endif
/* `is_sane()` flags */ /* `is_sane()` flags */
#define IS_SPC_F 0x0001 /* Space */ #define IS_SPC_F 0x0001 /* Space */
#define IS_HSH_F 0x0002 /* Hash sign # */ #define IS_HSH_F 0x0002 /* Hash sign # */
@ -85,16 +105,19 @@
#define ustrcat(target, source) strcat((char *) (target), (const char *) (source)) #define ustrcat(target, source) strcat((char *) (target), (const char *) (source))
#define ustrncat(target, source, count) strncat((char *) (target), (const char *) (source), (count)) #define ustrncat(target, source, count) strncat((char *) (target), (const char *) (source), (count))
#ifdef _MSC_VER /* VC6 or C89 */
# if _MSC_VER == 1200 /* VC6 */ #if (defined(_MSC_VER) && _MSC_VER == 1200) || (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L)
# define ceilf (float) ceil # define ceilf (float) ceil
# define floorf (float) floor # define floorf (float) floor
# define fmodf (float) fmod # define fmodf (float) fmod
#endif #endif
# if _MSC_VER < 1800 /* round (C99) not before MSVC 2013 (C++ 12.0) */ /* `round()` (C99) not before MSVC 2013 (C++ 12.0) */
#if (defined(_MSC_VER) && _MSC_VER < 1800) || (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199000L)
# define round(arg) floor((arg) + 0.5) # define round(arg) floor((arg) + 0.5)
# define roundf(arg) floorf((arg) + 0.5f) # define roundf(arg) floorf((arg) + 0.5f)
#endif #endif
#ifdef _MSC_VER
# pragma warning(disable: 4244) /* conversion from int to float */ # pragma warning(disable: 4244) /* conversion from int to float */
# if _MSC_VER != 1200 /* VC6 */ # if _MSC_VER != 1200 /* VC6 */
# pragma warning(disable: 4996) /* function or variable may be unsafe */ # pragma warning(disable: 4996) /* function or variable may be unsafe */

View File

@ -48,12 +48,9 @@
The date of publication for these functions is 31 May 2006 The date of publication for these functions is 31 May 2006
*/ */
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#ifdef _MSC_VER #include <stdio.h>
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "pdf417.h" #include "pdf417.h"
#include "gs1.h" #include "gs1.h"
@ -303,11 +300,7 @@ static void cc_a(struct zint_symbol *symbol, const char source[], const int cc_w
static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_width) { static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_width) {
const int length = (int) strlen(source) / 8; const int length = (int) strlen(source) / 8;
int i; int i;
#ifndef _MSC_VER unsigned char *data_string = (unsigned char *) z_alloca(length + 3);
unsigned char data_string[length + 3];
#else
unsigned char *data_string = (unsigned char *) _alloca(length + 3);
#endif
int chainemc[180], mclength; int chainemc[180], mclength;
int k, j, p, longueur, mccorrection[50] = {0}, offset; int k, j, p, longueur, mccorrection[50] = {0}, offset;
int total; int total;
@ -528,11 +521,7 @@ static void cc_b(struct zint_symbol *symbol, const char source[], const int cc_w
static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_width, const int ecc_level) { static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_width, const int ecc_level) {
const int length = (int) strlen(source) / 8; const int length = (int) strlen(source) / 8;
int i, p; int i, p;
#ifndef _MSC_VER unsigned char *data_string = (unsigned char *) z_alloca(length + 4);
unsigned char data_string[length + 4];
#else
unsigned char *data_string = (unsigned char *) _alloca(length + 4);
#endif
int chainemc[1000], mclength, k; int chainemc[1000], mclength, k;
int offset, longueur, loop, total, j, mccorrection[520] = {0}; int offset, longueur, loop, total, j, mccorrection[520] = {0};
int c1, c2, c3, dummy[35]; int c1, c2, c3, dummy[35];
@ -871,11 +860,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
int ai90_mode, remainder; int ai90_mode, remainder;
char last_digit = '\0'; char last_digit = '\0';
int mode; int mode;
#ifndef _MSC_VER char *general_field = (char *) z_alloca(source_len + 1);
char general_field[source_len + 1];
#else
char *general_field = (char *) _alloca(source_len + 1);
#endif
int target_bitsize; int target_bitsize;
int bp = 0; int bp = 0;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
@ -950,11 +935,7 @@ static int cc_binary_string(struct zint_symbol *symbol, const unsigned char sour
} else if (encoding_method == 3) { } else if (encoding_method == 3) {
/* Encodation Method field of "11" - AI 90 */ /* Encodation Method field of "11" - AI 90 */
#ifndef _MSC_VER char *ninety = (char *) z_alloca(source_len + 1);
char ninety[source_len + 1];
#else
char *ninety = (char *) _alloca(source_len + 1);
#endif
int ninety_len, alpha, alphanum, numeric, test1, test2, test3; int ninety_len, alpha, alphanum, numeric, test1, test2, test3;
/* "This encodation method may be used if an element string with an AI /* "This encodation method may be used if an element string with an AI
@ -1282,11 +1263,7 @@ INTERNAL int composite(struct zint_symbol *symbol, unsigned char source[], int l
int j, i, k; int j, i, k;
/* Allow for 8 bits + 5-bit latch per char + 1000 bits overhead/padding */ /* Allow for 8 bits + 5-bit latch per char + 1000 bits overhead/padding */
const unsigned int bs = 13 * length + 1000 + 1; const unsigned int bs = 13 * length + 1000 + 1;
#ifndef _MSC_VER char *binary_string = (char *) z_alloca(bs);
char binary_string[bs];
#else
char *binary_string = (char *) _alloca(bs);
#endif
unsigned int pri_len; unsigned int pri_len;
struct zint_symbol *linear; struct zint_symbol *linear;
int top_shift, bottom_shift; int top_shift, bottom_shift;

View File

@ -1,5 +1,4 @@
/* dmatrix.c Handles Data Matrix ECC 200 symbols */ /* dmatrix.c Handles Data Matrix ECC 200 symbols */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
@ -39,13 +38,9 @@
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "reedsol.h" #include "reedsol.h"
#include "dmatrix.h" #include "dmatrix.h"
@ -60,14 +55,14 @@ static void dm_placementbit(int *array, const int NR, const int NC, int r, int c
c += NC; c += NC;
r += 4 - ((NC + 4) % 8); r += 4 - ((NC + 4) % 8);
} }
// Necessary for DMRE (ISO/IEC 21471:2020 Annex E) /* Necessary for DMRE (ISO/IEC 21471:2020 Annex E) */
if (r >= NR) { if (r >= NR) {
r -= NR; r -= NR;
} }
// Check index limits /* Check index limits */
assert(r < NR); assert(r < NR);
assert(c < NC); assert(c < NC);
// Check double-assignment /* Check double-assignment */
assert(0 == array[r * NC + c]); assert(0 == array[r * NC + c]);
array[r * NC + c] = (p << 3) + b; array[r * NC + c] = (p << 3) + b;
} }
@ -131,12 +126,12 @@ static void dm_placementcornerD(int *array, const int NR, const int NC, const in
/* Annex F placement algorithm main function */ /* Annex F placement algorithm main function */
static void dm_placement(int *array, const int NR, const int NC) { static void dm_placement(int *array, const int NR, const int NC) {
int r, c, p; int r, c, p;
// start /* start */
p = 1; p = 1;
r = 4; r = 4;
c = 0; c = 0;
do { do {
// check corner /* check corner */
if (r == NR && !c) if (r == NR && !c)
dm_placementcornerA(array, NR, NC, p++); dm_placementcornerA(array, NR, NC, p++);
if (r == NR - 2 && !c && NC % 4) if (r == NR - 2 && !c && NC % 4)
@ -145,7 +140,7 @@ static void dm_placement(int *array, const int NR, const int NC) {
dm_placementcornerC(array, NR, NC, p++); dm_placementcornerC(array, NR, NC, p++);
if (r == NR + 4 && c == 2 && !(NC % 8)) if (r == NR + 4 && c == 2 && !(NC % 8))
dm_placementcornerD(array, NR, NC, p++); dm_placementcornerD(array, NR, NC, p++);
// up/right /* up/right */
do { do {
if (r < NR && c >= 0 && !array[r * NC + c]) if (r < NR && c >= 0 && !array[r * NC + c])
dm_placementblock(array, NR, NC, r, c, p++); dm_placementblock(array, NR, NC, r, c, p++);
@ -154,7 +149,7 @@ static void dm_placement(int *array, const int NR, const int NC) {
} while (r >= 0 && c < NC); } while (r >= 0 && c < NC);
r++; r++;
c += 3; c += 3;
// down/left /* down/left */
do { do {
if (r >= 0 && c < NC && !array[r * NC + c]) if (r >= 0 && c < NC && !array[r * NC + c])
dm_placementblock(array, NR, NC, r, c, p++); dm_placementblock(array, NR, NC, r, c, p++);
@ -164,7 +159,7 @@ static void dm_placement(int *array, const int NR, const int NC) {
r += 3; r += 3;
c++; c++;
} while (r < NR || c < NC); } while (r < NR || c < NC);
// unfilled corner /* unfilled corner */
if (!array[NR * NC - 1]) if (!array[NR * NC - 1])
array[NR * NC - 1] = array[NR * NC - NC - 2] = 1; array[NR * NC - 1] = array[NR * NC - NC - 2] = 1;
} }
@ -184,7 +179,7 @@ static void dm_ecc(unsigned char *binary, const int bytes, const int datablock,
for (n = b; n < bytes; n += blocks) for (n = b; n < bytes; n += blocks)
buf[p++] = binary[n]; buf[p++] = binary[n];
rs_encode(&rs, p, buf, ecc); rs_encode(&rs, p, buf, ecc);
p = rsblock - 1; // comes back reversed p = rsblock - 1; /* comes back reversed */
for (n = b; n < rsblocks; n += blocks) { for (n = b; n < rsblocks; n += blocks) {
if (skew) { if (skew) {
/* Rotate ecc data to make 144x144 size symbols acceptable */ /* Rotate ecc data to make 144x144 size symbols acceptable */
@ -329,65 +324,65 @@ static int dm_look_ahead_test(const unsigned char source[], const int length, co
/* ascii ... step (l) */ /* ascii ... step (l) */
if (z_isdigit(c)) { if (z_isdigit(c)) {
ascii_count += DM_MULT_1_DIV_2; // (l)(1) ascii_count += DM_MULT_1_DIV_2; /* (l)(1) */
} else { } else {
if (is_extended) { if (is_extended) {
ascii_count = DM_MULT_CEIL(ascii_count) + DM_MULT_2; // (l)(2) ascii_count = DM_MULT_CEIL(ascii_count) + DM_MULT_2; /* (l)(2) */
} else { } else {
ascii_count = DM_MULT_CEIL(ascii_count) + DM_MULT_1; // (l)(3) ascii_count = DM_MULT_CEIL(ascii_count) + DM_MULT_1; /* (l)(3) */
} }
} }
/* c40 ... step (m) */ /* c40 ... step (m) */
if (dm_isc40(c)) { if (dm_isc40(c)) {
c40_count += DM_MULT_2_DIV_3; // (m)(1) c40_count += DM_MULT_2_DIV_3; /* (m)(1) */
} else { } else {
if (is_extended) { if (is_extended) {
c40_count += DM_MULT_8_DIV_3; // (m)(2) c40_count += DM_MULT_8_DIV_3; /* (m)(2) */
} else { } else {
c40_count += DM_MULT_4_DIV_3; // (m)(3) c40_count += DM_MULT_4_DIV_3; /* (m)(3) */
} }
} }
/* text ... step (n) */ /* text ... step (n) */
if (dm_istext(c)) { if (dm_istext(c)) {
text_count += DM_MULT_2_DIV_3; // (n)(1) text_count += DM_MULT_2_DIV_3; /* (n)(1) */
} else { } else {
if (is_extended) { if (is_extended) {
text_count += DM_MULT_8_DIV_3; // (n)(2) text_count += DM_MULT_8_DIV_3; /* (n)(2) */
} else { } else {
text_count += DM_MULT_4_DIV_3; // (n)(3) text_count += DM_MULT_4_DIV_3; /* (n)(3) */
} }
} }
/* x12 ... step (o) */ /* x12 ... step (o) */
if (dm_isX12(c)) { if (dm_isX12(c)) {
x12_count += DM_MULT_2_DIV_3; // (o)(1) x12_count += DM_MULT_2_DIV_3; /* (o)(1) */
} else { } else {
if (is_extended) { if (is_extended) {
x12_count += DM_MULT_13_DIV_3; // (o)(2) x12_count += DM_MULT_13_DIV_3; /* (o)(2) */
} else { } else {
x12_count += DM_MULT_10_DIV_3; // (o)(3) x12_count += DM_MULT_10_DIV_3; /* (o)(3) */
} }
} }
/* edifact ... step (p) */ /* edifact ... step (p) */
if (dm_isedifact(c, gs1)) { if (dm_isedifact(c, gs1)) {
edf_count += DM_MULT_3_DIV_4; // (p)(1) edf_count += DM_MULT_3_DIV_4; /* (p)(1) */
} else { } else {
if (is_extended) { if (is_extended) {
edf_count += DM_MULT_17_DIV_4; // (p)(2) edf_count += DM_MULT_17_DIV_4; /* (p)(2) */
} else { } else {
edf_count += DM_MULT_13_DIV_4; // (p)(3) edf_count += DM_MULT_13_DIV_4; /* (p)(3) */
} }
} }
/* base 256 ... step (q) */ /* base 256 ... step (q) */
if ((gs1 == 1) && (c == '[')) { if ((gs1 == 1) && (c == '[')) {
/* FNC1 separator */ /* FNC1 separator */
b256_count += DM_MULT_4; // (q)(1) b256_count += DM_MULT_4; /* (q)(1) */
} else { } else {
b256_count += DM_MULT_1; // (q)(2) b256_count += DM_MULT_1; /* (q)(2) */
} }
if (sp >= position + 3) { if (sp >= position + 3) {
@ -763,7 +758,7 @@ static int dm_getEndMode(struct zint_symbol *symbol, const unsigned char *source
return mode; return mode;
} }
//#define DM_TRACE /*#define DM_TRACE*/
#include "dmatrix_trace.h" #include "dmatrix_trace.h"
/* Return number of C40/TEXT codewords needed to encode characters in full batches of 3 (or less if EOD). /* Return number of C40/TEXT codewords needed to encode characters in full batches of 3 (or less if EOD).
@ -1056,11 +1051,7 @@ static int dm_minimalenc(struct zint_symbol *symbol, const unsigned char source[
int current_mode = *p_current_mode; int current_mode = *p_current_mode;
int last_ascii, symbols_left; int last_ascii, symbols_left;
int i; int i;
#ifndef _MSC_VER char *modes = (char *) z_alloca(length);
char modes[length];
#else
char *modes = (char *) _alloca(length);
#endif
assert(length <= 10921); /* Can only handle (10921 + 1) * 6 = 65532 < 65536 (2*16) due to sizeof(previous) */ assert(length <= 10921); /* Can only handle (10921 + 1) * 6 = 65532 < 65536 (2*16) due to sizeof(previous) */
@ -1205,7 +1196,7 @@ static int dm_minimalenc(struct zint_symbol *symbol, const unsigned char source[
int value = source[sp]; int value = source[sp];
if (value >= 64) { // '@' if (value >= 64) { /* '@' */
value -= 64; value -= 64;
} }
@ -1413,7 +1404,7 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
} else { } else {
int value = source[sp]; int value = source[sp];
if (value >= 64) { // '@' if (value >= 64) { /* '@' */
value -= 64; value -= 64;
} }
@ -1531,20 +1522,20 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
if (debug_print) printf("%s ", current_mode == DM_C40 ? "C40" : "TEX"); if (debug_print) printf("%s ", current_mode == DM_C40 ? "C40" : "TEX");
if (process_p == 0) { if (process_p == 0) {
if (symbols_left > 0) { if (symbols_left > 0) {
target[tp++] = 254; // Unlatch target[tp++] = 254; /* Unlatch */
if (debug_print) printf("ASC "); if (debug_print) printf("ASC ");
} }
} else { } else {
if (process_p == 2 && symbols_left == 2) { if (process_p == 2 && symbols_left == 2) {
/* 5.2.5.2 (b) */ /* 5.2.5.2 (b) */
process_buffer[process_p++] = 0; // Shift 1 process_buffer[process_p++] = 0; /* Shift 1 */
(void) dm_ctx_buffer_xfer(process_buffer, process_p, target, &tp, debug_print); (void) dm_ctx_buffer_xfer(process_buffer, process_p, target, &tp, debug_print);
} else if (process_p == 1 && symbols_left <= 2 && dm_isc40text(current_mode, source[length - 1])) { } else if (process_p == 1 && symbols_left <= 2 && dm_isc40text(current_mode, source[length - 1])) {
/* 5.2.5.2 (c)/(d) */ /* 5.2.5.2 (c)/(d) */
if (symbols_left > 1) { if (symbols_left > 1) {
/* 5.2.5.2 (c) */ /* 5.2.5.2 (c) */
target[tp++] = 254; // Unlatch and encode remaining data in ascii. target[tp++] = 254; /* Unlatch and encode remaining data in ascii. */
if (debug_print) printf("ASC "); if (debug_print) printf("ASC ");
} }
target[tp++] = source[length - 1] + 1; target[tp++] = source[length - 1] + 1;
@ -1562,7 +1553,7 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
if (debug_print) printf("Mode %d, backtracked %d\n", current_mode, (total_cnt / 3) * 2); if (debug_print) printf("Mode %d, backtracked %d\n", current_mode, (total_cnt / 3) * 2);
tp -= (total_cnt / 3) * 2; tp -= (total_cnt / 3) * 2;
target[tp++] = 254; // Unlatch target[tp++] = 254; /* Unlatch */
if (debug_print) printf("ASC "); if (debug_print) printf("ASC ");
for (; sp < length; sp++) { for (; sp < length; sp++) {
if (is_twodigits(source, length, sp)) { if (is_twodigits(source, length, sp)) {
@ -1592,12 +1583,12 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
} else if (current_mode == DM_X12) { } else if (current_mode == DM_X12) {
if (debug_print) printf("X12 "); if (debug_print) printf("X12 ");
if ((symbols_left == 1) && (process_p == 1)) { if ((symbols_left == 1) && (process_p == 1)) {
// Unlatch not required! /* Unlatch not required! */
target[tp++] = source[length - 1] + 1; target[tp++] = source[length - 1] + 1;
if (debug_print) printf("A%02X ", target[tp - 1] - 1); if (debug_print) printf("A%02X ", target[tp - 1] - 1);
} else { } else {
if (symbols_left > 0) { if (symbols_left > 0) {
target[tp++] = (254); // Unlatch. target[tp++] = (254); /* Unlatch. */
if (debug_print) printf("ASC "); if (debug_print) printf("ASC ");
} }
@ -1613,7 +1604,7 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
} else if (current_mode == DM_EDIFACT) { } else if (current_mode == DM_EDIFACT) {
if (debug_print) printf("EDI "); if (debug_print) printf("EDI ");
if (symbols_left <= 2 && process_p <= symbols_left) { // Unlatch not required! if (symbols_left <= 2 && process_p <= symbols_left) { /* Unlatch not required! */
if (process_p == 1) { if (process_p == 1) {
target[tp++] = source[length - 1] + 1; target[tp++] = source[length - 1] + 1;
if (debug_print) printf("A%02X ", target[tp - 1] - 1); if (debug_print) printf("A%02X ", target[tp - 1] - 1);
@ -1623,7 +1614,7 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
if (debug_print) printf("A%02X A%02X ", target[tp - 2] - 1, target[tp - 1] - 1); if (debug_print) printf("A%02X A%02X ", target[tp - 2] - 1, target[tp - 1] - 1);
} }
} else { } else {
// Append edifact unlatch value (31) and empty buffer /* Append edifact unlatch value (31) and empty buffer */
if (process_p <= 3) { if (process_p <= 3) {
process_buffer[process_p++] = 31; process_buffer[process_p++] = 31;
} }
@ -1844,7 +1835,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
if (binlen > dm_matrixbytes[symbolsize]) { if (binlen > dm_matrixbytes[symbolsize]) {
if ((symbol->option_2 >= 1) && (symbol->option_2 <= DMSIZESCOUNT)) { if ((symbol->option_2 >= 1) && (symbol->option_2 <= DMSIZESCOUNT)) {
// The symbol size was given by --ver (option_2) /* The symbol size was given by --ver (option_2) */
strcpy(symbol->errtxt, "522: Input too long for selected symbol size"); strcpy(symbol->errtxt, "522: Input too long for selected symbol size");
} else { } else {
strcpy(symbol->errtxt, "523: Data too long to fit in symbol"); strcpy(symbol->errtxt, "523: Data too long to fit in symbol");
@ -1871,7 +1862,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
printf("\n"); printf("\n");
} }
// ecc code /* ecc code */
if (symbolsize == INTSYMBOL144) { if (symbolsize == INTSYMBOL144) {
skew = 1; skew = 1;
} }
@ -1887,7 +1878,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
debug_test_codeword_dump(symbol, binary, skew ? 1558 + 620 : bytes + rsblock * (bytes / datablock)); debug_test_codeword_dump(symbol, binary, skew ? 1558 + 620 : bytes + rsblock * (bytes / datablock));
} }
#endif #endif
{ // placement { /* placement */
const int NC = W - 2 * (W / FW); const int NC = W - 2 * (W / FW);
const int NR = H - 2 * (H / FH); const int NR = H - 2 * (H / FH);
int x, y, *places; int x, y, *places;
@ -1909,7 +1900,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
set_module(symbol, (H - y) - 1, x + FW - 1); set_module(symbol, (H - y) - 1, x + FW - 1);
} }
#ifdef DM_DEBUG #ifdef DM_DEBUG
// Print position matrix as in standard /* Print position matrix as in standard */
for (y = NR - 1; y >= 0; y--) { for (y = NR - 1; y >= 0; y--) {
for (x = 0; x < NC; x++) { for (x = 0; x < NC; x++) {
const int v = places[(NR - y - 1) * NC + x]; const int v = places[(NR - y - 1) * NC + x];

View File

@ -1,8 +1,7 @@
/* dmatrix.h - Handles Data Matrix ECC 200 */ /* dmatrix.h - Handles Data Matrix ECC 200 */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,7 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
/* /*
Contains Extended Rectangular Data Matrix (DMRE) Contains Extended Rectangular Data Matrix (DMRE)
@ -75,10 +74,10 @@ static const char dm_text_value[] = {
22, 23, 24, 25, 26, 0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 27, 28, 29, 30, 31 22, 23, 24, 25, 26, 0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 27, 28, 29, 30, 31
}; };
// Position in option array [symbol option value - 1] /* Position in option array [symbol option value - 1]
// The position in the option array is by increasing total data codewords with square first // The position in the option array is by increasing total data codewords with square first
// The last comment value is the total data codewords value. // The last comment value is the total data codewords value.
// The index of this array is the --vers parameter value -1 and is given as first comment value // The index of this array is the --vers parameter value -1 and is given as first comment value */
static const unsigned short int dm_intsymbol[] = { static const unsigned short int dm_intsymbol[] = {
/* Standard DM */ /* Standard DM */
@ -98,13 +97,13 @@ static const unsigned short int dm_intsymbol[] = {
32, /* 47: 26x48 , 90*/ 35, /* 48: 26x64 ,118*/ 32, /* 47: 26x48 , 90*/ 35, /* 48: 26x64 ,118*/
}; };
// Number of DM Sizes /* Number of DM Sizes */
#define DMSIZESCOUNT 48 #define DMSIZESCOUNT 48
// Number of 144x144 for special interlace /* Number of 144x144 for special interlace */
#define INTSYMBOL144 47 #define INTSYMBOL144 47
// Is the current code a DMRE code ? /* Is the current code a DMRE code ?
// This is the case, if dm_intsymbol index >= 30 This is the case, if dm_intsymbol index >= 30 */
static const char dm_isDMRE[] = { static const char dm_isDMRE[] = {
/* 0*/ 0, /* 10x10, 3*/ 0, /* 12x12 , 5*/ 0, /* 8x18 , 5*/ 0, /* 14x14 , 8*/ /* 0*/ 0, /* 10x10, 3*/ 0, /* 12x12 , 5*/ 0, /* 8x18 , 5*/ 0, /* 14x14 , 8*/
@ -121,7 +120,7 @@ static const char dm_isDMRE[] = {
/*44*/ 0, /*104x104,816*/ 0, /*120x120,1050*/0, /*132x132,1304*/0 /*144x144,1558*/ /*44*/ 0, /*104x104,816*/ 0, /*120x120,1050*/0, /*132x132,1304*/0 /*144x144,1558*/
}; };
// Horizontal matrix size /* Horizontal matrix size */
static const unsigned short int dm_matrixH[] = { static const unsigned short int dm_matrixH[] = {
/* 0*/ 10, /* 10x10 , 3*/ 12, /* 12x12 , 5 */ 8, /* 8x18 , 5*/ 14, /* 14x14 , 8*/ /* 0*/ 10, /* 10x10 , 3*/ 12, /* 12x12 , 5 */ 8, /* 8x18 , 5*/ 14, /* 14x14 , 8*/
@ -138,7 +137,7 @@ static const unsigned short int dm_matrixH[] = {
/*44*/104, /*104x104,816*/ 120,/*120x120,1050*/132,/*132x132,1304*/144 /*144x144,1558*/ /*44*/104, /*104x104,816*/ 120,/*120x120,1050*/132,/*132x132,1304*/144 /*144x144,1558*/
}; };
// Vertical matrix sizes /* Vertical matrix sizes */
static const unsigned short int dm_matrixW[] = { static const unsigned short int dm_matrixW[] = {
/* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */ /* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
@ -156,7 +155,7 @@ static const unsigned short int dm_matrixW[] = {
}; };
// Horizontal submodule size (including subfinder) /* Horizontal submodule size (including subfinder) */
static const unsigned short int dm_matrixFH[] = { static const unsigned short int dm_matrixFH[] = {
/* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 8, /* 8x18 */ 14, /* 14x14 */ /* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 8, /* 8x18 */ 14, /* 14x14 */
@ -173,7 +172,7 @@ static const unsigned short int dm_matrixFH[] = {
/*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/ /*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/
}; };
// Vertical submodule size (including subfinder) /* Vertical submodule size (including subfinder) */
static const unsigned short int dm_matrixFW[] = { static const unsigned short int dm_matrixFW[] = {
/* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */ /* 0*/ 10, /* 10x10 */ 12, /* 12x12 */ 18, /* 8x18 */ 14, /* 14x14 */
@ -190,7 +189,7 @@ static const unsigned short int dm_matrixFW[] = {
/*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/ /*44*/ 26, /*104x104*/ 20, /*120x120*/ 22, /*132x132*/ 24 /*144x144*/
}; };
// Total Data Codewords /* Total Data Codewords */
static const unsigned short int dm_matrixbytes[] = { static const unsigned short int dm_matrixbytes[] = {
/* 0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */ /* 0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
@ -207,7 +206,7 @@ static const unsigned short int dm_matrixbytes[] = {
/*44*/ 816, /*104x104*/1050, /*120x120*/1304, /*132x132*/1558 /*144x144*/ /*44*/ 816, /*104x104*/1050, /*120x120*/1304, /*132x132*/1558 /*144x144*/
}; };
// Data Codewords per RS-Block /* Data Codewords per RS-Block */
static const unsigned short int dm_matrixdatablock[] = { static const unsigned short int dm_matrixdatablock[] = {
/* 0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */ /* 0*/ 3, /* 10x10 */ 5, /* 12x12 */ 5, /* 8x18 */ 8, /* 14x14 */
@ -224,7 +223,7 @@ static const unsigned short int dm_matrixdatablock[] = {
/*44*/ 136, /*104x104*/ 175, /*120x120*/ 163, /*132x132*/ 156 /* 144x144*/ /*44*/ 136, /*104x104*/ 175, /*120x120*/ 163, /*132x132*/ 156 /* 144x144*/
}; };
// ECC Codewords per RS-Block /* ECC Codewords per RS-Block */
static const unsigned short int dm_matrixrsblock[] = { static const unsigned short int dm_matrixrsblock[] = {
/* 0*/ 5, /* 10x10 */ 7, /* 12x12 */ 7, /* 8x18 */ 10, /* 14x14 */ /* 0*/ 5, /* 10x10 */ 7, /* 12x12 */ 7, /* 8x18 */ 10, /* 14x14 */
@ -241,4 +240,5 @@ static const unsigned short int dm_matrixrsblock[] = {
/*44*/ 56, /*104x104*/ 68, /*120x120*/ 62, /*132x132*/ 62 /*144x144*/ /*44*/ 56, /*104x104*/ 68, /*120x120*/ 62, /*132x132*/ 62 /*144x144*/
}; };
/* vim: set ts=4 sw=4 et : */
#endif /* Z_DMATRIX_H */ #endif /* Z_DMATRIX_H */

View File

@ -36,15 +36,9 @@
* Incorporating suggestions from Terry Burton at BWIPP * Incorporating suggestions from Terry Burton at BWIPP
*/ */
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#ifndef _MSC_VER #include <stdio.h>
#include <stdint.h>
#else
#include "ms_stdint.h"
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "gs1.h" #include "gs1.h"
@ -68,7 +62,7 @@ static const unsigned short dc_dot_patterns[113] = {
0x1b8, 0x1c6, 0x1cc 0x1b8, 0x1c6, 0x1cc
}; };
// Printed() routine from Annex A adapted to char array of ASCII 1's and 0's /* Printed() routine from Annex A adapted to char array of ASCII 1's and 0's */
static int dc_get_dot(const char Dots[], const int Hgt, const int Wid, const int x, const int y) { static int dc_get_dot(const char Dots[], const int Hgt, const int Wid, const int x, const int y) {
if ((x >= 0) && (x < Wid) && (y >= 0) && (y < Hgt)) { if ((x >= 0) && (x < Wid) && (y >= 0) && (y < Hgt)) {
@ -102,7 +96,7 @@ static int dc_clr_row(const char *Dots, const int Hgt, const int Wid, const int
return 1; return 1;
} }
// calc penalty for empty interior columns /* calc penalty for empty interior columns */
static int dc_col_penalty(const char *Dots, const int Hgt, const int Wid) { static int dc_col_penalty(const char *Dots, const int Hgt, const int Wid) {
int x, penalty = 0, penalty_local = 0; int x, penalty = 0, penalty_local = 0;
@ -124,7 +118,7 @@ static int dc_col_penalty(const char *Dots, const int Hgt, const int Wid) {
return penalty + penalty_local; return penalty + penalty_local;
} }
// calc penalty for empty interior rows /* calc penalty for empty interior rows */
static int dc_row_penalty(const char *Dots, const int Hgt, const int Wid) { static int dc_row_penalty(const char *Dots, const int Hgt, const int Wid) {
int y, penalty = 0, penalty_local = 0; int y, penalty = 0, penalty_local = 0;
@ -151,17 +145,17 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
int x, y, worstedge, first, last, sum; int x, y, worstedge, first, last, sum;
int penalty = 0; int penalty = 0;
// first, guard against "pathelogical" gaps in the array /* first, guard against "pathelogical" gaps in the array
// subtract a penalty score for empty rows/columns from total code score for each mask, subtract a penalty score for empty rows/columns from total code score for each mask,
// where the penalty is Sum(N ^ n), where N is the number of positions in a column/row, where the penalty is Sum(N ^ n), where N is the number of positions in a column/row,
// and n is the number of consecutive empty rows/columns and n is the number of consecutive empty rows/columns */
penalty = dc_row_penalty(Dots, Hgt, Wid) + dc_col_penalty(Dots, Hgt, Wid); penalty = dc_row_penalty(Dots, Hgt, Wid) + dc_col_penalty(Dots, Hgt, Wid);
sum = 0; sum = 0;
first = -1; first = -1;
last = -1; last = -1;
// across the top edge, count printed dots and measure their extent /* across the top edge, count printed dots and measure their extent */
for (x = 0; x < Wid; x += 2) { for (x = 0; x < Wid; x += 2) {
if (dc_get_dot(Dots, Hgt, Wid, x, 0)) { if (dc_get_dot(Dots, Hgt, Wid, x, 0)) {
if (first < 0) { if (first < 0) {
@ -172,7 +166,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
} }
} }
if (sum == 0) { if (sum == 0) {
return SCORE_UNLIT_EDGE; // guard against empty top edge return SCORE_UNLIT_EDGE; /* guard against empty top edge */
} }
worstedge = sum + last - first; worstedge = sum + last - first;
@ -182,7 +176,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
first = -1; first = -1;
last = -1; last = -1;
// across the bottom edge, ditto /* across the bottom edge, ditto */
for (x = Wid & 1; x < Wid; x += 2) { for (x = Wid & 1; x < Wid; x += 2) {
if (dc_get_dot(Dots, Hgt, Wid, x, Hgt - 1)) { if (dc_get_dot(Dots, Hgt, Wid, x, Hgt - 1)) {
if (first < 0) { if (first < 0) {
@ -193,7 +187,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
} }
} }
if (sum == 0) { if (sum == 0) {
return SCORE_UNLIT_EDGE; // guard against empty bottom edge return SCORE_UNLIT_EDGE; /* guard against empty bottom edge */
} }
sum += last - first; sum += last - first;
@ -206,7 +200,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
first = -1; first = -1;
last = -1; last = -1;
// down the left edge, ditto /* down the left edge, ditto */
for (y = 0; y < Hgt; y += 2) { for (y = 0; y < Hgt; y += 2) {
if (dc_get_dot(Dots, Hgt, Wid, 0, y)) { if (dc_get_dot(Dots, Hgt, Wid, 0, y)) {
if (first < 0) { if (first < 0) {
@ -217,7 +211,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
} }
} }
if (sum == 0) { if (sum == 0) {
return SCORE_UNLIT_EDGE; // guard against empty left edge return SCORE_UNLIT_EDGE; /* guard against empty left edge */
} }
sum += last - first; sum += last - first;
@ -230,7 +224,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
first = -1; first = -1;
last = -1; last = -1;
// down the right edge, ditto /* down the right edge, ditto */
for (y = Hgt & 1; y < Hgt; y += 2) { for (y = Hgt & 1; y < Hgt; y += 2) {
if (dc_get_dot(Dots, Hgt, Wid, Wid - 1, y)) { if (dc_get_dot(Dots, Hgt, Wid, Wid - 1, y)) {
if (first < 0) { if (first < 0) {
@ -241,7 +235,7 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
} }
} }
if (sum == 0) { if (sum == 0) {
return SCORE_UNLIT_EDGE; // guard against empty right edge return SCORE_UNLIT_EDGE; /* guard against empty right edge */
} }
sum += last - first; sum += last - first;
@ -250,8 +244,8 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
worstedge = sum; worstedge = sum;
} }
// throughout the array, count the # of unprinted 5-somes (cross patterns) /* throughout the array, count the # of unprinted 5-somes (cross patterns)
// plus the # of printed dots surrounded by 8 unprinted neighbors plus the # of printed dots surrounded by 8 unprinted neighbors */
sum = 0; sum = 0;
for (y = 0; y < Hgt; y++) { for (y = 0; y < Hgt; y++) {
for (x = y & 1; x < Wid; x += 2) { for (x = y & 1; x < Wid; x += 2) {
@ -268,10 +262,10 @@ static int dc_score_array(const char Dots[], const int Hgt, const int Wid) {
return (worstedge - sum * sum - penalty); return (worstedge - sum * sum - penalty);
} }
//------------------------------------------------------------------------- /*-------------------------------------------------------------------------
// "rsencode(nd,nc)" adds "nc" R-S check words to "nd" data words in wd[] // "rsencode(nd,nc)" adds "nc" R-S check words to "nd" data words in wd[]
// employing Galois Field GF, where GF is prime, with a prime modulus of PM // employing Galois Field GF, where GF is prime, with a prime modulus of PM
//------------------------------------------------------------------------- //-------------------------------------------------------------------------*/
static void dc_rsencode(const int nd, const int nc, unsigned char *wd) { static void dc_rsencode(const int nd, const int nc, unsigned char *wd) {
/* Pre-calculated coefficients for GF(113) of generator polys of degree 3 to 39. To generate run /* Pre-calculated coefficients for GF(113) of generator polys of degree 3 to 39. To generate run
@ -340,22 +334,22 @@ static void dc_rsencode(const int nd, const int nc, unsigned char *wd) {
int i, j, k, nw, start, step; int i, j, k, nw, start, step;
const char *c; const char *c;
// Here we compute how many interleaved R-S blocks will be needed /* Here we compute how many interleaved R-S blocks will be needed */
nw = nd + nc; nw = nd + nc;
step = (nw + GF - 2) / (GF - 1); step = (nw + GF - 2) / (GF - 1);
// ...& then for each such block: /* ...& then for each such block: */
for (start = 0; start < step; start++) { for (start = 0; start < step; start++) {
const int ND = (nd - start + step - 1) / step; const int ND = (nd - start + step - 1) / step;
const int NW = (nw - start + step - 1) / step; const int NW = (nw - start + step - 1) / step;
const int NC = NW - ND; const int NC = NW - ND;
unsigned char *const e = wd + start + ND * step; unsigned char *const e = wd + start + ND * step;
// first set the generator polynomial "c" of order "NC": /* first set the generator polynomial "c" of order "NC": */
c = coefs + cinds[NC - 3]; c = coefs + cinds[NC - 3];
// & then compute the corresponding checkword values into wd[] /* & then compute the corresponding checkword values into wd[]
// ... (a) starting at wd[start] & (b) stepping by step ... (a) starting at wd[start] & (b) stepping by step */
for (i = 0; i < NC; i++) { for (i = 0; i < NC; i++) {
e[i * step] = 0; e[i * step] = 0;
} }
@ -394,15 +388,15 @@ static int dc_datum_b(const unsigned char source[], const int length, const int
} }
switch (source[position]) { switch (source[position]) {
case 9: // HT case 9: /* HT */
case 28: // FS case 28: /* FS */
case 29: // GS case 29: /* GS */
case 30: // RS case 30: /* RS */
return 1; return 1;
break; break;
} }
if ((position + 1 < length) && (source[position] == 13) && (source[position + 1] == 10)) { // CRLF if ((position + 1 < length) && (source[position] == 13) && (source[position + 1] == 10)) { /* CRLF */
return 2; return 2;
} }
} }
@ -505,7 +499,7 @@ static int dc_binary(const unsigned char source[], const int length, const int p
/* Empty binary buffer */ /* Empty binary buffer */
static int dc_empty_bin_buf(unsigned char *codeword_array, int ap, uint64_t *p_bin_buf, int *p_bin_buf_size) { static int dc_empty_bin_buf(unsigned char *codeword_array, int ap, uint64_t *p_bin_buf, int *p_bin_buf_size) {
int i; int i;
int lawrencium[6]; // Reversed radix 103 values int lawrencium[6]; /* Reversed radix 103 values */
uint64_t bin_buf = *p_bin_buf; uint64_t bin_buf = *p_bin_buf;
int bin_buf_size = *p_bin_buf_size; int bin_buf_size = *p_bin_buf_size;
@ -546,7 +540,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
const int eci, const int last_seg, const int last_EOT, const int last_RSEOT, const int eci, const int last_seg, const int last_EOT, const int last_RSEOT,
int ap, unsigned char *codeword_array, char *p_encoding_mode, int *p_inside_macro, int ap, unsigned char *codeword_array, char *p_encoding_mode, int *p_inside_macro,
uint64_t *p_bin_buf, int *p_bin_buf_size, unsigned char structapp_array[], int *p_structapp_size) { uint64_t *p_bin_buf, int *p_bin_buf_size, unsigned char structapp_array[], int *p_structapp_size) {
static const char lead_specials[] = "\x09\x1C\x1D\x1E"; // HT, FS, GS, RS static const char lead_specials[] = "\x09\x1C\x1D\x1E"; /* HT, FS, GS, RS */
int i; int i;
int position = 0; int position = 0;
@ -562,19 +556,19 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
if (first_seg) { if (first_seg) {
if (symbol->output_options & READER_INIT) { if (symbol->output_options & READER_INIT) {
codeword_array[ap++] = 109; // FNC3 codeword_array[ap++] = 109; /* FNC3 */
} else if (!gs1 && eci == 0 && length > 2 && is_twodigits(source, length, 0)) { } else if (!gs1 && eci == 0 && length > 2 && is_twodigits(source, length, 0)) {
codeword_array[ap++] = 107; // FNC1 codeword_array[ap++] = 107; /* FNC1 */
} else if (posn(lead_specials, source[0]) != -1) { } else if (posn(lead_specials, source[0]) != -1) {
// Prevent encodation as a macro if a special character is in first position /* Prevent encodation as a macro if a special character is in first position */
codeword_array[ap++] = 101; // Latch A codeword_array[ap++] = 101; /* Latch A */
codeword_array[ap++] = source[0] + 64; codeword_array[ap++] = source[0] + 64;
encoding_mode = 'A'; encoding_mode = 'A';
position++; position++;
} else if (length > 5) { // Note assuming macro headers don't straddle segments } else if (length > 5) { /* Note assuming macro headers don't straddle segments */
/* Step C1 */ /* Step C1 */
if (source[0] == '[' && source[1] == ')' && source[2] == '>' && source[3] == 30 /*RS*/ && last_EOT) { if (source[0] == '[' && source[1] == ')' && source[2] == '>' && source[3] == 30 /*RS*/ && last_EOT) {
int format_050612 = (source[4] == '0' && (source[5] == '5' || source[5] == '6')) int format_050612 = (source[4] == '0' && (source[5] == '5' || source[5] == '6'))
@ -592,9 +586,9 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
inside_macro = 100; /* Note no longer using for malformed 05/06/12 */ inside_macro = 100; /* Note no longer using for malformed 05/06/12 */
} }
if (inside_macro) { if (inside_macro) {
codeword_array[ap++] = 106; // Latch B codeword_array[ap++] = 106; /* Latch B */
encoding_mode = 'B'; encoding_mode = 'B';
codeword_array[ap++] = inside_macro; // Macro codeword_array[ap++] = inside_macro; /* Macro */
if (inside_macro == 100) { if (inside_macro == 100) {
codeword_array[ap++] = ctoi(source[4]) + 16; codeword_array[ap++] = ctoi(source[4]) + 16;
codeword_array[ap++] = ctoi(source[5]) + 16; codeword_array[ap++] = ctoi(source[5]) + 16;
@ -625,12 +619,12 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
ap = dc_append_to_bin_buf(codeword_array, ap, eci & 0xFF, &bin_buf, &bin_buf_size); ap = dc_append_to_bin_buf(codeword_array, ap, eci & 0xFF, &bin_buf, &bin_buf_size);
} }
} else { } else {
codeword_array[ap++] = 108; // FNC2 codeword_array[ap++] = 108; /* FNC2 */
if (eci <= 39) { if (eci <= 39) {
codeword_array[ap++] = eci; codeword_array[ap++] = eci;
} else { } else {
// the next three codewords valued A, B & C encode the ECI value of /* the next three codewords valued A, B & C encode the ECI value of
// (A - 40) * 12769 + B * 113 + C + 40 (Section 5.2.1) (A - 40) * 12769 + B * 113 + C + 40 (Section 5.2.1) */
int a, b, c; int a, b, c;
a = (eci - 40) / 12769; a = (eci - 40) / 12769;
b = ((eci - 40) - (12769 * a)) / 113; b = ((eci - 40) - (12769 * a)) / 113;
@ -646,7 +640,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
while (position < length) { while (position < length) {
/* Step A */ /* Step A */
if (last_seg && (position == length - 2) && (inside_macro != 0) && (inside_macro != 100)) { if (last_seg && (position == length - 2) && (inside_macro != 0) && (inside_macro != 100)) {
// inside_macro only gets set to 97, 98 or 99 if the last two characters are RS/EOT /* inside_macro only gets set to 97, 98 or 99 if the last two characters are RS/EOT */
position += 2; position += 2;
if (debug_print) printf("A "); if (debug_print) printf("A ");
continue; continue;
@ -654,7 +648,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step B */ /* Step B */
if (last_seg && (position == length - 1) && (inside_macro == 100)) { if (last_seg && (position == length - 1) && (inside_macro == 100)) {
// inside_macro only gets set to 100 if the last character is EOT /* inside_macro only gets set to 100 if the last character is EOT */
position++; position++;
if (debug_print) printf("B "); if (debug_print) printf("B ");
continue; continue;
@ -664,7 +658,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step C2 */ /* Step C2 */
if (dc_seventeen_ten(source, length, position)) { if (dc_seventeen_ten(source, length, position)) {
codeword_array[ap++] = 100; // (17)...(10) codeword_array[ap++] = 100; /* (17)...(10) */
codeword_array[ap++] = to_int(source + position + 2, 2); codeword_array[ap++] = to_int(source + position + 2, 2);
codeword_array[ap++] = to_int(source + position + 4, 2); codeword_array[ap++] = to_int(source + position + 4, 2);
codeword_array[ap++] = to_int(source + position + 6, 2); codeword_array[ap++] = to_int(source + position + 6, 2);
@ -675,7 +669,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
if (dc_datum_c(source, length, position) || (source[position] == '[' && gs1)) { if (dc_datum_c(source, length, position) || (source[position] == '[' && gs1)) {
if (source[position] == '[') { if (source[position] == '[') {
codeword_array[ap++] = 107; // FNC1 codeword_array[ap++] = 107; /* FNC1 */
position++; position++;
} else { } else {
codeword_array[ap++] = to_int(source + position, 2); codeword_array[ap++] = to_int(source + position, 2);
@ -690,15 +684,15 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* dc_n_digits(position + 1) > 0 */ /* dc_n_digits(position + 1) > 0 */
if (position + 1 < length && z_isdigit(source[position + 1])) { if (position + 1 < length && z_isdigit(source[position + 1])) {
if ((source[position] - 128) < 32) { if ((source[position] - 128) < 32) {
codeword_array[ap++] = 110; // Upper Shift A codeword_array[ap++] = 110; /* Upper Shift A */
codeword_array[ap++] = source[position] - 128 + 64; codeword_array[ap++] = source[position] - 128 + 64;
} else { } else {
codeword_array[ap++] = 111; // Upper Shift B codeword_array[ap++] = 111; /* Upper Shift B */
codeword_array[ap++] = source[position] - 128 - 32; codeword_array[ap++] = source[position] - 128 - 32;
} }
position++; position++;
} else { } else {
codeword_array[ap++] = 112; // Bin Latch codeword_array[ap++] = 112; /* Bin Latch */
encoding_mode = 'X'; encoding_mode = 'X';
} }
if (debug_print) printf("C3 "); if (debug_print) printf("C3 ");
@ -710,30 +704,30 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
const int m = dc_ahead_a(source, length, position); const int m = dc_ahead_a(source, length, position);
const int n = dc_ahead_b(source, length, position, &nx); const int n = dc_ahead_b(source, length, position, &nx);
if (m > n) { if (m > n) {
codeword_array[ap++] = 101; // Latch A codeword_array[ap++] = 101; /* Latch A */
encoding_mode = 'A'; encoding_mode = 'A';
} else { } else {
if (nx >= 1 && nx <= 4) { if (nx >= 1 && nx <= 4) {
codeword_array[ap++] = 101 + nx; // nx Shift B codeword_array[ap++] = 101 + nx; /* nx Shift B */
for (i = 0; i < nx; i++) { for (i = 0; i < nx; i++) {
if (source[position] >= 32) { if (source[position] >= 32) {
codeword_array[ap++] = source[position] - 32; codeword_array[ap++] = source[position] - 32;
} else if (source[position] == 13) { // CR/LF } else if (source[position] == 13) { /* CR/LF */
codeword_array[ap++] = 96; codeword_array[ap++] = 96;
position++; position++;
} else { } else {
switch (source[position]) { switch (source[position]) {
case 9: codeword_array[ap++] = 97; break; // HT case 9: codeword_array[ap++] = 97; break; /* HT */
case 28: codeword_array[ap++] = 98; break; // FS case 28: codeword_array[ap++] = 98; break; /* FS */
case 29: codeword_array[ap++] = 99; break; // GS case 29: codeword_array[ap++] = 99; break; /* GS */
case 30: codeword_array[ap++] = 100; break; // RS case 30: codeword_array[ap++] = 100; break; /* RS */
} }
} }
position++; position++;
} }
} else { } else {
codeword_array[ap++] = 106; // Latch B codeword_array[ap++] = 106; /* Latch B */
encoding_mode = 'B'; encoding_mode = 'B';
} }
} }
@ -748,13 +742,13 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
if (n >= 2) { if (n >= 2) {
if (n <= 4) { if (n <= 4) {
codeword_array[ap++] = 103 + (n - 2); // nx Shift C codeword_array[ap++] = 103 + (n - 2); /* nx Shift C */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
codeword_array[ap++] = to_int(source + position, 2); codeword_array[ap++] = to_int(source + position, 2);
position += 2; position += 2;
} }
} else { } else {
codeword_array[ap++] = 106; // Latch C codeword_array[ap++] = 106; /* Latch C */
encoding_mode = 'C'; encoding_mode = 'C';
} }
if (debug_print) printf("D1 "); if (debug_print) printf("D1 ");
@ -763,7 +757,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step D2 */ /* Step D2 */
if ((source[position] == '[') && gs1) { if ((source[position] == '[') && gs1) {
codeword_array[ap++] = 107; // FNC1 codeword_array[ap++] = 107; /* FNC1 */
position++; position++;
if (debug_print) printf("D2/1 "); if (debug_print) printf("D2/1 ");
continue; continue;
@ -786,10 +780,10 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* HT, FS, GS and RS in the first data position would be interpreted as a macro /* HT, FS, GS and RS in the first data position would be interpreted as a macro
* (see table 2) */ * (see table 2) */
switch (source[position]) { switch (source[position]) {
case 9: codeword_array[ap++] = 97; break; // HT case 9: codeword_array[ap++] = 97; break; /* HT */
case 28: codeword_array[ap++] = 98; break; // FS case 28: codeword_array[ap++] = 98; break; /* FS */
case 29: codeword_array[ap++] = 99; break; // GS case 29: codeword_array[ap++] = 99; break; /* GS */
case 30: codeword_array[ap++] = 100; break; // RS case 30: codeword_array[ap++] = 100; break; /* RS */
} }
done = 1; done = 1;
} }
@ -805,15 +799,15 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
if (dc_binary(source, length, position)) { if (dc_binary(source, length, position)) {
if (dc_datum_b(source, length, position + 1)) { if (dc_datum_b(source, length, position + 1)) {
if ((source[position] - 128) < 32) { if ((source[position] - 128) < 32) {
codeword_array[ap++] = 110; // Bin Shift A codeword_array[ap++] = 110; /* Bin Shift A */
codeword_array[ap++] = source[position] - 128 + 64; codeword_array[ap++] = source[position] - 128 + 64;
} else { } else {
codeword_array[ap++] = 111; // Bin Shift B codeword_array[ap++] = 111; /* Bin Shift B */
codeword_array[ap++] = source[position] - 128 - 32; codeword_array[ap++] = source[position] - 128 - 32;
} }
position++; position++;
} else { } else {
codeword_array[ap++] = 112; // Bin Latch codeword_array[ap++] = 112; /* Bin Latch */
encoding_mode = 'X'; encoding_mode = 'X';
} }
if (debug_print) printf("D3 "); if (debug_print) printf("D3 ");
@ -822,7 +816,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step D4 */ /* Step D4 */
if (dc_ahead_a(source, length, position) == 1) { if (dc_ahead_a(source, length, position) == 1) {
codeword_array[ap++] = 101; // Shift A codeword_array[ap++] = 101; /* Shift A */
if (source[position] < 32) { if (source[position] < 32) {
codeword_array[ap++] = source[position] + 64; codeword_array[ap++] = source[position] + 64;
} else { } else {
@ -830,7 +824,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
} }
position++; position++;
} else { } else {
codeword_array[ap++] = 102; // Latch A codeword_array[ap++] = 102; /* Latch A */
encoding_mode = 'A'; encoding_mode = 'A';
} }
if (debug_print) printf("D4 "); if (debug_print) printf("D4 ");
@ -842,13 +836,13 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
const int n = dc_try_c(source, length, position); const int n = dc_try_c(source, length, position);
if (n >= 2) { if (n >= 2) {
if (n <= 4) { if (n <= 4) {
codeword_array[ap++] = 103 + (n - 2); // nx Shift C codeword_array[ap++] = 103 + (n - 2); /* nx Shift C */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
codeword_array[ap++] = to_int(source + position, 2); codeword_array[ap++] = to_int(source + position, 2);
position += 2; position += 2;
} }
} else { } else {
codeword_array[ap++] = 106; // Latch C codeword_array[ap++] = 106; /* Latch C */
encoding_mode = 'C'; encoding_mode = 'C';
} }
if (debug_print) printf("E1 "); if (debug_print) printf("E1 ");
@ -857,8 +851,8 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step E2 */ /* Step E2 */
if ((source[position] == '[') && gs1) { if ((source[position] == '[') && gs1) {
// Note: this branch probably never reached as no reason to be in Code Set A for GS1 data /* Note: this branch probably never reached as no reason to be in Code Set A for GS1 data */
codeword_array[ap++] = 107; // FNC1 codeword_array[ap++] = 107; /* FNC1 */
position++; position++;
if (debug_print) printf("E2/1 "); if (debug_print) printf("E2/1 ");
continue; continue;
@ -878,15 +872,15 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
if (dc_binary(source, length, position)) { if (dc_binary(source, length, position)) {
if (dc_datum_a(source, length, position + 1)) { if (dc_datum_a(source, length, position + 1)) {
if ((source[position] - 128) < 32) { if ((source[position] - 128) < 32) {
codeword_array[ap++] = 110; // Bin Shift A codeword_array[ap++] = 110; /* Bin Shift A */
codeword_array[ap++] = source[position] - 128 + 64; codeword_array[ap++] = source[position] - 128 + 64;
} else { } else {
codeword_array[ap++] = 111; // Bin Shift B codeword_array[ap++] = 111; /* Bin Shift B */
codeword_array[ap++] = source[position] - 128 - 32; codeword_array[ap++] = source[position] - 128 - 32;
} }
position++; position++;
} else { } else {
codeword_array[ap++] = 112; // Bin Latch codeword_array[ap++] = 112; /* Bin Latch */
encoding_mode = 'X'; encoding_mode = 'X';
} }
if (debug_print) printf("E3 "); if (debug_print) printf("E3 ");
@ -897,25 +891,25 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
dc_ahead_b(source, length, position, &nx); dc_ahead_b(source, length, position, &nx);
if (nx >= 1 && nx <= 6) { if (nx >= 1 && nx <= 6) {
codeword_array[ap++] = 95 + nx; // nx Shift B codeword_array[ap++] = 95 + nx; /* nx Shift B */
for (i = 0; i < nx; i++) { for (i = 0; i < nx; i++) {
if (source[position] >= 32) { if (source[position] >= 32) {
codeword_array[ap++] = source[position] - 32; codeword_array[ap++] = source[position] - 32;
} else if (source[position] == 13) { // CR/LF } else if (source[position] == 13) { /* CR/LF */
codeword_array[ap++] = 96; codeword_array[ap++] = 96;
position++; position++;
} else { } else {
switch (source[position]) { switch (source[position]) {
case 9: codeword_array[ap++] = 97; break; // HT case 9: codeword_array[ap++] = 97; break; /* HT */
case 28: codeword_array[ap++] = 98; break; // FS case 28: codeword_array[ap++] = 98; break; /* FS */
case 29: codeword_array[ap++] = 99; break; // GS case 29: codeword_array[ap++] = 99; break; /* GS */
case 30: codeword_array[ap++] = 100; break; // RS case 30: codeword_array[ap++] = 100; break; /* RS */
} }
} }
position++; position++;
} }
} else { } else {
codeword_array[ap++] = 102; // Latch B codeword_array[ap++] = 102; /* Latch B */
encoding_mode = 'B'; encoding_mode = 'B';
} }
if (debug_print) printf("E4 "); if (debug_print) printf("E4 ");
@ -930,13 +924,13 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
ap = dc_empty_bin_buf(codeword_array, ap, &bin_buf, &bin_buf_size); ap = dc_empty_bin_buf(codeword_array, ap, &bin_buf, &bin_buf_size);
if (n <= 7) { if (n <= 7) {
codeword_array[ap++] = 101 + n; // Interrupt for nx Shift C codeword_array[ap++] = 101 + n; /* Interrupt for nx Shift C */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
codeword_array[ap++] = to_int(source + position, 2); codeword_array[ap++] = to_int(source + position, 2);
position += 2; position += 2;
} }
} else { } else {
codeword_array[ap++] = 111; // Terminate with Latch to C codeword_array[ap++] = 111; /* Terminate with Latch to C */
encoding_mode = 'C'; encoding_mode = 'C';
} }
if (debug_print) printf("F1 "); if (debug_print) printf("F1 ");
@ -962,10 +956,10 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
ap = dc_empty_bin_buf(codeword_array, ap, &bin_buf, &bin_buf_size); /* Empty binary buffer */ ap = dc_empty_bin_buf(codeword_array, ap, &bin_buf, &bin_buf_size); /* Empty binary buffer */
if (dc_ahead_a(source, length, position) > dc_ahead_b(source, length, position, NULL)) { if (dc_ahead_a(source, length, position) > dc_ahead_b(source, length, position, NULL)) {
codeword_array[ap++] = 109; // Terminate with Latch to A codeword_array[ap++] = 109; /* Terminate with Latch to A */
encoding_mode = 'A'; encoding_mode = 'A';
} else { } else {
codeword_array[ap++] = 110; // Terminate with Latch to B codeword_array[ap++] = 110; /* Terminate with Latch to B */
encoding_mode = 'B'; encoding_mode = 'B';
} }
if (debug_print) printf("F3 "); if (debug_print) printf("F3 ");
@ -1029,9 +1023,9 @@ static int dc_encode_message_segs(struct zint_symbol *symbol, const struct zint_
const struct zint_seg *last_seg = &segs[seg_count - 1]; const struct zint_seg *last_seg = &segs[seg_count - 1];
last_EOT = last_seg->source[last_seg->length - 1] == 4; // EOT last_EOT = last_seg->source[last_seg->length - 1] == 4; /* EOT */
if (last_EOT && last_seg->length > 1) { if (last_EOT && last_seg->length > 1) {
last_RSEOT = last_seg->source[last_seg->length - 2] == 30; // RS last_RSEOT = last_seg->source[last_seg->length - 2] == 30; /* RS */
} }
for (i = 0; i < seg_count; i++) { for (i = 0; i < seg_count; i++) {
@ -1120,7 +1114,7 @@ static void dc_fold_dotstream(const char dot_stream[], const int width, const in
dot_array[((height - row - 1) * width) + column] = dot_stream[position++]; dot_array[((height - row - 1) * width) + column] = dot_stream[position++];
} }
} else { } else {
dot_array[((height - row - 1) * width) + column] = ' '; // Non-data position dot_array[((height - row - 1) * width) + column] = ' '; /* Non-data position */
} }
} }
} }
@ -1143,7 +1137,7 @@ static void dc_fold_dotstream(const char dot_stream[], const int width, const in
dot_array[(row * width) + column] = dot_stream[position++]; dot_array[(row * width) + column] = dot_stream[position++];
} }
} else { } else {
dot_array[(row * width) + column] = ' '; // Non-data position dot_array[(row * width) + column] = ' '; /* Non-data position */
} }
} }
} }
@ -1200,7 +1194,7 @@ static void dc_apply_mask(const int mask, const int data_length, unsigned char *
static void dc_force_corners(const int width, const int height, char *dot_array) { static void dc_force_corners(const int width, const int height, char *dot_array) {
if (width & 1) { if (width & 1) {
// "Vertical" symbol /* "Vertical" symbol */
dot_array[0] = '1'; dot_array[0] = '1';
dot_array[width - 1] = '1'; dot_array[width - 1] = '1';
dot_array[(height - 2) * width] = '1'; dot_array[(height - 2) * width] = '1';
@ -1208,7 +1202,7 @@ static void dc_force_corners(const int width, const int height, char *dot_array)
dot_array[((height - 1) * width) + 1] = '1'; dot_array[((height - 1) * width) + 1] = '1';
dot_array[(height * width) - 2] = '1'; dot_array[(height * width) - 2] = '1';
} else { } else {
// "Horizontal" symbol /* "Horizontal" symbol */
dot_array[0] = '1'; dot_array[0] = '1';
dot_array[width - 2] = '1'; dot_array[width - 2] = '1';
dot_array[(2 * width) - 1] = '1'; dot_array[(2 * width) - 1] = '1';
@ -1236,15 +1230,10 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i
/* Allow 4 codewords per input + 2 (FNC) + seg_count * 4 (ECI) + 2 (special char 1st position) /* Allow 4 codewords per input + 2 (FNC) + seg_count * 4 (ECI) + 2 (special char 1st position)
+ 5 (Structured Append) + 10 (PAD) */ + 5 (Structured Append) + 10 (PAD) */
const int codeword_array_len = segs_length(segs, seg_count) * 4 + 2 + seg_count * 4 + 2 + 5 + 10; const int codeword_array_len = segs_length(segs, seg_count) * 4 + 2 + seg_count * 4 + 2 + 5 + 10;
unsigned char *codeword_array = (unsigned char *) z_alloca(codeword_array_len);
#ifndef _MSC_VER
unsigned char codeword_array[codeword_array_len];
#else
unsigned char *codeword_array = (unsigned char *) _alloca(codeword_array_len);
char *dot_stream; char *dot_stream;
char *dot_array; char *dot_array;
unsigned char *masked_codeword_array; unsigned char *masked_codeword_array;
#endif /* _MSC_VER */
if (symbol->eci > 811799) { if (symbol->eci > 811799) {
strcpy(symbol->errtxt, "525: Invalid ECI"); strcpy(symbol->errtxt, "525: Invalid ECI");
@ -1362,13 +1351,8 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i
n_dots = (height * width) / 2; n_dots = (height * width) / 2;
#ifndef _MSC_VER dot_stream = (char *) z_alloca(height * width * 3);
char dot_stream[height * width * 3]; dot_array = (char *) z_alloca(width * height);
char dot_array[width * height];
#else
dot_stream = (char *) _alloca(height * width * 3);
dot_array = (char *) _alloca(width * height);
#endif
/* Add pad characters */ /* Add pad characters */
padding_dots = n_dots - min_dots; /* get the number of free dots available for padding */ padding_dots = n_dots - min_dots; /* get the number of free dots available for padding */
@ -1428,11 +1412,7 @@ INTERNAL int dotcode(struct zint_symbol *symbol, struct zint_seg segs[], const i
ecc_length = 3 + (data_length / 2); ecc_length = 3 + (data_length / 2);
#ifndef _MSC_VER masked_codeword_array = (unsigned char *) z_alloca(data_length + 1 + ecc_length);
unsigned char masked_codeword_array[data_length + 1 + ecc_length];
#else
masked_codeword_array = (unsigned char *) _alloca(data_length + 1 + ecc_length);
#endif /* _MSC_VER */
if (user_mask) { if (user_mask) {
best_mask = user_mask - 1; best_mask = user_mask - 1;

View File

@ -1,5 +1,5 @@
/* eci.c - Extended Channel Interpretations /* eci.c - Extended Channel Interpretations */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
@ -31,9 +31,6 @@
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <assert.h> #include <assert.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "eci.h" #include "eci.h"
#include "eci_sb.h" #include "eci_sb.h"
@ -770,13 +767,8 @@ INTERNAL int utf8_to_eci(const int eci, const unsigned char source[], unsigned c
/* Find the lowest single-byte ECI mode which will encode a given set of Unicode text */ /* Find the lowest single-byte ECI mode which will encode a given set of Unicode text */
INTERNAL int get_best_eci(const unsigned char source[], int length) { INTERNAL int get_best_eci(const unsigned char source[], int length) {
int eci = 3; int eci = 3;
/* Note: attempting single-byte conversions only, so get_eci_length() unnecessary */ /* Note: attempting single-byte conversions only, so get_eci_length() unnecessary */
#ifndef _MSC_VER unsigned char *local_source = (unsigned char *) z_alloca(length + 1);
unsigned char local_source[length + 1];
#else
unsigned char *local_source = (unsigned char *) _alloca(length + 1);
#endif
do { do {
if (eci == 14) { /* Reserved */ if (eci == 14) { /* Reserved */
@ -794,7 +786,7 @@ INTERNAL int get_best_eci(const unsigned char source[], int length) {
return 0; return 0;
} }
return 26; // If all of these fail, use UTF-8! return 26; /* If all of these fail, use UTF-8! */
} }
/* Call `get_best_eci()` for each segment. Returns 0 on failure, first ECI set on success */ /* Call `get_best_eci()` for each segment. Returns 0 on failure, first ECI set on success */
@ -838,11 +830,7 @@ INTERNAL int sjis_utf8(struct zint_symbol *symbol, const unsigned char source[],
unsigned int *ddata) { unsigned int *ddata) {
int error_number; int error_number;
unsigned int i, length; unsigned int i, length;
#ifndef _MSC_VER unsigned int *utfdata = (unsigned int *) z_alloca(sizeof(unsigned int) * (*p_length + 1));
unsigned int utfdata[*p_length + 1];
#else
unsigned int *utfdata = (unsigned int *) _alloca((*p_length + 1) * sizeof(unsigned int));
#endif
error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/); error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/);
if (error_number != 0) { if (error_number != 0) {
@ -911,11 +899,7 @@ INTERNAL int sjis_utf8_to_eci(const int eci, const unsigned char source[], int *
if (is_eci_convertible(eci)) { if (is_eci_convertible(eci)) {
int error_number; int error_number;
const int eci_length = get_eci_length(eci, source, *p_length); const int eci_length = get_eci_length(eci, source, *p_length);
#ifndef _MSC_VER unsigned char *converted = (unsigned char *) z_alloca(eci_length + 1);
unsigned char converted[eci_length + 1];
#else
unsigned char *converted = (unsigned char *) _alloca(eci_length + 1);
#endif
error_number = utf8_to_eci(eci, source, converted, p_length); error_number = utf8_to_eci(eci, source, converted, p_length);
if (error_number != 0) { if (error_number != 0) {
@ -938,11 +922,7 @@ INTERNAL int gb2312_utf8(struct zint_symbol *symbol, const unsigned char source[
unsigned int *ddata) { unsigned int *ddata) {
int error_number; int error_number;
unsigned int i, length; unsigned int i, length;
#ifndef _MSC_VER unsigned int *utfdata = (unsigned int *) z_alloca(sizeof(unsigned int) * (*p_length + 1));
unsigned int utfdata[*p_length + 1];
#else
unsigned int *utfdata = (unsigned int *) _alloca((*p_length + 1) * sizeof(unsigned int));
#endif
error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/); error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 1 /*disallow_4byte*/);
if (error_number != 0) { if (error_number != 0) {
@ -1022,11 +1002,7 @@ INTERNAL int gb2312_utf8_to_eci(const int eci, const unsigned char source[], int
if (is_eci_convertible(eci)) { if (is_eci_convertible(eci)) {
int error_number; int error_number;
const int eci_length = get_eci_length(eci, source, *p_length); const int eci_length = get_eci_length(eci, source, *p_length);
#ifndef _MSC_VER unsigned char *converted = (unsigned char *) z_alloca(eci_length + 1);
unsigned char converted[eci_length + 1];
#else
unsigned char *converted = (unsigned char *) _alloca(eci_length + 1);
#endif
error_number = utf8_to_eci(eci, source, converted, p_length); error_number = utf8_to_eci(eci, source, converted, p_length);
if (error_number != 0) { if (error_number != 0) {
@ -1049,11 +1025,7 @@ INTERNAL int gb18030_utf8(struct zint_symbol *symbol, const unsigned char source
unsigned int *ddata) { unsigned int *ddata) {
int error_number, ret; int error_number, ret;
unsigned int i, j, length; unsigned int i, j, length;
#ifndef _MSC_VER unsigned int *utfdata = (unsigned int *) z_alloca(sizeof(unsigned int) * (*p_length + 1));
unsigned int utfdata[*p_length + 1];
#else
unsigned int *utfdata = (unsigned int *) _alloca((*p_length + 1) * sizeof(unsigned int));
#endif
error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 0 /*disallow_4byte*/); error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 0 /*disallow_4byte*/);
if (error_number != 0) { if (error_number != 0) {
@ -1150,11 +1122,7 @@ INTERNAL int gb18030_utf8_to_eci(const int eci, const unsigned char source[], in
if (is_eci_convertible(eci)) { if (is_eci_convertible(eci)) {
int error_number; int error_number;
const int eci_length = get_eci_length(eci, source, *p_length); const int eci_length = get_eci_length(eci, source, *p_length);
#ifndef _MSC_VER unsigned char *converted = (unsigned char *) z_alloca(eci_length + 1);
unsigned char converted[eci_length + 1];
#else
unsigned char *converted = (unsigned char *) _alloca(eci_length + 1);
#endif
error_number = utf8_to_eci(eci, source, converted, p_length); error_number = utf8_to_eci(eci, source, converted, p_length);
if (error_number != 0) { if (error_number != 0) {

View File

@ -1,7 +1,7 @@
/* emf.c - Support for Microsoft Enhanced Metafile Format /* emf.c - Support for Microsoft Enhanced Metafile Format */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2016 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2016-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
/* Developed according to [MS-EMF] - v20160714, Released July 14, 2016 /* Developed according to [MS-EMF] - v20160714, Released July 14, 2016
* and [MS-WMF] - v20160714, Released July 14, 2016 */ * and [MS-WMF] - v20160714, Released July 14, 2016 */
@ -40,7 +40,6 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#include <malloc.h>
#endif #endif
#include "common.h" #include "common.h"
#include "emf.h" #include "emf.h"
@ -202,10 +201,10 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
emr_setworldtransform_t emr_setworldtransform; emr_setworldtransform_t emr_setworldtransform;
emr_createbrushindirect_t emr_createbrushindirect_fg; emr_createbrushindirect_t emr_createbrushindirect_fg;
emr_createbrushindirect_t emr_createbrushindirect_bg; emr_createbrushindirect_t emr_createbrushindirect_bg;
emr_createbrushindirect_t emr_createbrushindirect_colour[9]; // Used for colour symbols only emr_createbrushindirect_t emr_createbrushindirect_colour[9]; /* Used for colour symbols only */
emr_selectobject_t emr_selectobject_fgbrush; emr_selectobject_t emr_selectobject_fgbrush;
emr_selectobject_t emr_selectobject_bgbrush; emr_selectobject_t emr_selectobject_bgbrush;
emr_selectobject_t emr_selectobject_colour[9]; // Used for colour symbols only emr_selectobject_t emr_selectobject_colour[9]; /* Used for colour symbols only */
emr_createpen_t emr_createpen; emr_createpen_t emr_createpen;
emr_selectobject_t emr_selectobject_pen; emr_selectobject_t emr_selectobject_pen;
emr_rectangle_t background; emr_rectangle_t background;
@ -227,11 +226,9 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
float current_fsize; float current_fsize;
int current_halign; int current_halign;
#ifdef _MSC_VER
emr_rectangle_t *rectangle; emr_rectangle_t *rectangle;
emr_ellipse_t *circle; emr_ellipse_t *circle;
emr_polygon_t *hexagon; emr_polygon_t *hexagon;
#endif
if (symbol->vector == NULL) { if (symbol->vector == NULL) {
strcpy(symbol->errtxt, "643: Vector header NULL"); strcpy(symbol->errtxt, "643: Vector header NULL");
@ -256,18 +253,12 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
hexagon_count = count_hexagons(symbol); hexagon_count = count_hexagons(symbol);
string_count = count_strings(symbol, &fsize, &fsize2, &halign, &halign1, &halign2); string_count = count_strings(symbol, &fsize, &fsize2, &halign, &halign1, &halign2);
#ifndef _MSC_VER /* Avoid sanitize runtime error by making always non-zero */
// Avoid sanitize runtime error by making always non-zero rectangle = (emr_rectangle_t *) z_alloca(sizeof(emr_rectangle_t) * (rectangle_count ? rectangle_count : 1));
emr_rectangle_t rectangle[rectangle_count ? rectangle_count : 1]; circle = (emr_ellipse_t *) z_alloca(sizeof(emr_ellipse_t) * (circle_count ? circle_count : 1));
emr_ellipse_t circle[circle_count ? circle_count : 1]; hexagon = (emr_polygon_t *) z_alloca(sizeof(emr_polygon_t) * (hexagon_count ? hexagon_count : 1));
emr_polygon_t hexagon[hexagon_count ? hexagon_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));
#endif
// Calculate how many coloured rectangles /* Calculate how many coloured rectangles */
if (symbol->symbology == BARCODE_ULTRA) { if (symbol->symbology == BARCODE_ULTRA) {
rect = symbol->vector->rectangles; rect = symbol->vector->rectangles;
@ -291,8 +282,8 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
height = (int) ceilf(symbol->vector->height); height = (int) ceilf(symbol->vector->height);
/* Header */ /* Header */
emr_header.type = 0x00000001; // EMR_HEADER emr_header.type = 0x00000001; /* EMR_HEADER */
emr_header.size = 108; // Including extensions emr_header.size = 108; /* Including extensions */
emr_header.emf_header.bounds.left = 0; emr_header.emf_header.bounds.left = 0;
emr_header.emf_header.bounds.right = rotate_angle == 90 || rotate_angle == 270 ? height : width; emr_header.emf_header.bounds.right = rotate_angle == 90 || rotate_angle == 270 ? height : width;
emr_header.emf_header.bounds.bottom = rotate_angle == 90 || rotate_angle == 270 ? width : height; emr_header.emf_header.bounds.bottom = rotate_angle == 90 || rotate_angle == 270 ? width : height;
@ -301,10 +292,10 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
emr_header.emf_header.frame.right = emr_header.emf_header.bounds.right * 30; emr_header.emf_header.frame.right = emr_header.emf_header.bounds.right * 30;
emr_header.emf_header.frame.top = 0; emr_header.emf_header.frame.top = 0;
emr_header.emf_header.frame.bottom = emr_header.emf_header.bounds.bottom * 30; emr_header.emf_header.frame.bottom = emr_header.emf_header.bounds.bottom * 30;
emr_header.emf_header.record_signature = 0x464d4520; // ENHMETA_SIGNATURE emr_header.emf_header.record_signature = 0x464d4520; /* ENHMETA_SIGNATURE */
emr_header.emf_header.version = 0x00010000; emr_header.emf_header.version = 0x00010000;
if (symbol->symbology == BARCODE_ULTRA) { if (symbol->symbology == BARCODE_ULTRA) {
emr_header.emf_header.handles = 12; // Number of graphics objects emr_header.emf_header.handles = 12; /* Number of graphics objects */
} else { } else {
emr_header.emf_header.handles = fsize2 != 0.0f ? 5 : 4; emr_header.emf_header.handles = fsize2 != 0.0f ? 5 : 4;
} }
@ -317,23 +308,23 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
emr_header.emf_header.millimeters.cx = 300; emr_header.emf_header.millimeters.cx = 300;
emr_header.emf_header.millimeters.cy = 300; emr_header.emf_header.millimeters.cy = 300;
/* HeaderExtension1 */ /* HeaderExtension1 */
emr_header.emf_header.cb_pixel_format = 0x0000; // None set emr_header.emf_header.cb_pixel_format = 0x0000; /* None set */
emr_header.emf_header.off_pixel_format = 0x0000; // None set emr_header.emf_header.off_pixel_format = 0x0000; /* None set */
emr_header.emf_header.b_open_gl = 0x0000; // OpenGL not present emr_header.emf_header.b_open_gl = 0x0000; /* OpenGL not present */
/* HeaderExtension2 */ /* HeaderExtension2 */
emr_header.emf_header.micrometers.cx = 0; emr_header.emf_header.micrometers.cx = 0;
emr_header.emf_header.micrometers.cy = 0; emr_header.emf_header.micrometers.cy = 0;
bytecount = 108; bytecount = 108;
recordcount = 1; recordcount = 1;
emr_mapmode.type = 0x00000011; // EMR_SETMAPMODE emr_mapmode.type = 0x00000011; /* EMR_SETMAPMODE */
emr_mapmode.size = 12; emr_mapmode.size = 12;
emr_mapmode.mapmode = 0x01; // MM_TEXT emr_mapmode.mapmode = 0x01; /* MM_TEXT */
bytecount += 12; bytecount += 12;
recordcount++; recordcount++;
if (rotate_angle) { if (rotate_angle) {
emr_setworldtransform.type = 0x00000023; // EMR_SETWORLDTRANSFORM emr_setworldtransform.type = 0x00000023; /* EMR_SETWORLDTRANSFORM */
emr_setworldtransform.size = 32; emr_setworldtransform.size = 32;
emr_setworldtransform.m11 = rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? -1.0f : 0.0f; emr_setworldtransform.m11 = rotate_angle == 90 ? 0.0f : rotate_angle == 180 ? -1.0f : 0.0f;
emr_setworldtransform.m12 = rotate_angle == 90 ? 1.0f : rotate_angle == 180 ? 0.0f : -1.0f; emr_setworldtransform.m12 = rotate_angle == 90 ? 1.0f : rotate_angle == 180 ? 0.0f : -1.0f;
@ -346,24 +337,24 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
} }
/* Create Brushes */ /* Create Brushes */
emr_createbrushindirect_bg.type = 0x00000027; // EMR_CREATEBRUSHINDIRECT emr_createbrushindirect_bg.type = 0x00000027; /* EMR_CREATEBRUSHINDIRECT */
emr_createbrushindirect_bg.size = 24; emr_createbrushindirect_bg.size = 24;
emr_createbrushindirect_bg.ih_brush = 1; emr_createbrushindirect_bg.ih_brush = 1;
emr_createbrushindirect_bg.log_brush.brush_style = 0x0000; // BS_SOLID emr_createbrushindirect_bg.log_brush.brush_style = 0x0000; /* BS_SOLID */
emr_createbrushindirect_bg.log_brush.color.red = bgred; emr_createbrushindirect_bg.log_brush.color.red = bgred;
emr_createbrushindirect_bg.log_brush.color.green = bggrn; emr_createbrushindirect_bg.log_brush.color.green = bggrn;
emr_createbrushindirect_bg.log_brush.color.blue = bgblu; emr_createbrushindirect_bg.log_brush.color.blue = bgblu;
emr_createbrushindirect_bg.log_brush.color.reserved = 0; emr_createbrushindirect_bg.log_brush.color.reserved = 0;
emr_createbrushindirect_bg.log_brush.brush_hatch = 0x0006; // HS_SOLIDCLR emr_createbrushindirect_bg.log_brush.brush_hatch = 0x0006; /* HS_SOLIDCLR */
bytecount += 24; bytecount += 24;
recordcount++; recordcount++;
if (symbol->symbology == BARCODE_ULTRA) { if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
emr_createbrushindirect_colour[i].type = 0x00000027; // EMR_CREATEBRUSHINDIRECT emr_createbrushindirect_colour[i].type = 0x00000027; /* EMR_CREATEBRUSHINDIRECT */
emr_createbrushindirect_colour[i].size = 24; emr_createbrushindirect_colour[i].size = 24;
emr_createbrushindirect_colour[i].ih_brush = 2 + i; emr_createbrushindirect_colour[i].ih_brush = 2 + i;
emr_createbrushindirect_colour[i].log_brush.brush_style = 0x0000; // BS_SOLID emr_createbrushindirect_colour[i].log_brush.brush_style = 0x0000; /* BS_SOLID */
if (i == 0) { if (i == 0) {
emr_createbrushindirect_colour[i].log_brush.color.red = fgred; emr_createbrushindirect_colour[i].log_brush.color.red = fgred;
emr_createbrushindirect_colour[i].log_brush.color.green = fggrn; emr_createbrushindirect_colour[i].log_brush.color.green = fggrn;
@ -374,25 +365,25 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
emr_createbrushindirect_colour[i].log_brush.color.blue = colour_to_blue(i); emr_createbrushindirect_colour[i].log_brush.color.blue = colour_to_blue(i);
} }
emr_createbrushindirect_colour[i].log_brush.color.reserved = 0; emr_createbrushindirect_colour[i].log_brush.color.reserved = 0;
emr_createbrushindirect_colour[i].log_brush.brush_hatch = 0x0006; // HS_SOLIDCLR emr_createbrushindirect_colour[i].log_brush.brush_hatch = 0x0006; /* HS_SOLIDCLR */
} }
bytecount += colours_used * 24; bytecount += colours_used * 24;
recordcount += colours_used; recordcount += colours_used;
} else { } else {
emr_createbrushindirect_fg.type = 0x00000027; // EMR_CREATEBRUSHINDIRECT emr_createbrushindirect_fg.type = 0x00000027; /* EMR_CREATEBRUSHINDIRECT */
emr_createbrushindirect_fg.size = 24; emr_createbrushindirect_fg.size = 24;
emr_createbrushindirect_fg.ih_brush = 2; emr_createbrushindirect_fg.ih_brush = 2;
emr_createbrushindirect_fg.log_brush.brush_style = 0x0000; // BS_SOLID emr_createbrushindirect_fg.log_brush.brush_style = 0x0000; /* BS_SOLID */
emr_createbrushindirect_fg.log_brush.color.red = fgred; emr_createbrushindirect_fg.log_brush.color.red = fgred;
emr_createbrushindirect_fg.log_brush.color.green = fggrn; emr_createbrushindirect_fg.log_brush.color.green = fggrn;
emr_createbrushindirect_fg.log_brush.color.blue = fgblu; emr_createbrushindirect_fg.log_brush.color.blue = fgblu;
emr_createbrushindirect_fg.log_brush.color.reserved = 0; emr_createbrushindirect_fg.log_brush.color.reserved = 0;
emr_createbrushindirect_fg.log_brush.brush_hatch = 0x0006; // HS_SOLIDCLR emr_createbrushindirect_fg.log_brush.brush_hatch = 0x0006; /* HS_SOLIDCLR */
bytecount += 24; bytecount += 24;
recordcount++; recordcount++;
} }
emr_selectobject_bgbrush.type = 0x00000025; // EMR_SELECTOBJECT emr_selectobject_bgbrush.type = 0x00000025; /* EMR_SELECTOBJECT */
emr_selectobject_bgbrush.size = 12; emr_selectobject_bgbrush.size = 12;
emr_selectobject_bgbrush.ih_object = 1; emr_selectobject_bgbrush.ih_object = 1;
bytecount += 12; bytecount += 12;
@ -400,14 +391,14 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
if (symbol->symbology == BARCODE_ULTRA) { if (symbol->symbology == BARCODE_ULTRA) {
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
emr_selectobject_colour[i].type = 0x00000025; // EMR_SELECTOBJECT emr_selectobject_colour[i].type = 0x00000025; /* EMR_SELECTOBJECT */
emr_selectobject_colour[i].size = 12; emr_selectobject_colour[i].size = 12;
emr_selectobject_colour[i].ih_object = 2 + i; emr_selectobject_colour[i].ih_object = 2 + i;
} }
bytecount += colours_used * 12; bytecount += colours_used * 12;
recordcount += colours_used; recordcount += colours_used;
} else { } else {
emr_selectobject_fgbrush.type = 0x00000025; // EMR_SELECTOBJECT emr_selectobject_fgbrush.type = 0x00000025; /* EMR_SELECTOBJECT */
emr_selectobject_fgbrush.size = 12; emr_selectobject_fgbrush.size = 12;
emr_selectobject_fgbrush.ih_object = 2; emr_selectobject_fgbrush.ih_object = 2;
bytecount += 12; bytecount += 12;
@ -415,12 +406,12 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
} }
/* Create Pens */ /* Create Pens */
emr_createpen.type = 0x00000026; // EMR_CREATEPEN emr_createpen.type = 0x00000026; /* EMR_CREATEPEN */
emr_createpen.size = 28; emr_createpen.size = 28;
emr_createpen.ih_pen = 11; emr_createpen.ih_pen = 11;
emr_createpen.log_pen.pen_style = 0x00000005; // PS_NULL emr_createpen.log_pen.pen_style = 0x00000005; /* PS_NULL */
emr_createpen.log_pen.width.x = 1; emr_createpen.log_pen.width.x = 1;
emr_createpen.log_pen.width.y = 0; // ignored emr_createpen.log_pen.width.y = 0; /* ignored */
emr_createpen.log_pen.color_ref.red = 0; emr_createpen.log_pen.color_ref.red = 0;
emr_createpen.log_pen.color_ref.green = 0; emr_createpen.log_pen.color_ref.green = 0;
emr_createpen.log_pen.color_ref.blue = 0; emr_createpen.log_pen.color_ref.blue = 0;
@ -428,7 +419,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
bytecount += 28; bytecount += 28;
recordcount++; recordcount++;
emr_selectobject_pen.type = 0x00000025; // EMR_SELECTOBJECT emr_selectobject_pen.type = 0x00000025; /* EMR_SELECTOBJECT */
emr_selectobject_pen.size = 12; emr_selectobject_pen.size = 12;
emr_selectobject_pen.ih_object = 11; emr_selectobject_pen.ih_object = 11;
bytecount += 12; bytecount += 12;
@ -436,7 +427,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
if (draw_background) { if (draw_background) {
/* Make background from a rectangle */ /* Make background from a rectangle */
background.type = 0x0000002b; // EMR_RECTANGLE background.type = 0x0000002b; /* EMR_RECTANGLE */
background.size = 24; background.size = 24;
background.box.top = 0; background.box.top = 0;
background.box.left = 0; background.box.left = 0;
@ -446,11 +437,11 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
recordcount++; recordcount++;
} }
// Rectangles /* Rectangles */
rect = symbol->vector->rectangles; rect = symbol->vector->rectangles;
this_rectangle = 0; this_rectangle = 0;
while (rect) { while (rect) {
rectangle[this_rectangle].type = 0x0000002b; // EMR_RECTANGLE rectangle[this_rectangle].type = 0x0000002b; /* EMR_RECTANGLE */
rectangle[this_rectangle].size = 24; rectangle[this_rectangle].size = 24;
rectangle[this_rectangle].box.top = (int32_t) rect->y; rectangle[this_rectangle].box.top = (int32_t) rect->y;
rectangle[this_rectangle].box.bottom = (int32_t) stripf(rect->y + rect->height); rectangle[this_rectangle].box.bottom = (int32_t) stripf(rect->y + rect->height);
@ -462,7 +453,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
rect = rect->next; rect = rect->next;
} }
// Circles /* Circles */
previous_diameter = radius = 0.0f; previous_diameter = radius = 0.0f;
circ = symbol->vector->circles; circ = symbol->vector->circles;
this_circle = 0; this_circle = 0;
@ -473,7 +464,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
previous_diameter = circ->diameter + circ->width; previous_diameter = circ->diameter + circ->width;
radius = mul3dpf(0.5, previous_diameter); radius = mul3dpf(0.5, previous_diameter);
} }
circle[this_circle].type = 0x0000002a; // EMR_ELLIPSE circle[this_circle].type = 0x0000002a; /* EMR_ELLIPSE */
circle[this_circle].size = 24; circle[this_circle].size = 24;
circle[this_circle].box.top = (int32_t) stripf(circ->y - radius); circle[this_circle].box.top = (int32_t) stripf(circ->y - radius);
circle[this_circle].box.bottom = (int32_t) stripf(circ->y + radius); circle[this_circle].box.bottom = (int32_t) stripf(circ->y + radius);
@ -485,7 +476,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
if (symbol->symbology == BARCODE_MAXICODE) { /* Drawing MaxiCode bullseye using overlayed discs */ if (symbol->symbology == BARCODE_MAXICODE) { /* Drawing MaxiCode bullseye using overlayed discs */
float inner_radius = radius - circ->width; float inner_radius = radius - circ->width;
circle[this_circle].type = 0x0000002a; // EMR_ELLIPSE circle[this_circle].type = 0x0000002a; /* EMR_ELLIPSE */
circle[this_circle].size = 24; circle[this_circle].size = 24;
circle[this_circle].box.top = (int32_t) stripf(circ->y - inner_radius); circle[this_circle].box.top = (int32_t) stripf(circ->y - inner_radius);
circle[this_circle].box.bottom = (int32_t) stripf(circ->y + inner_radius); circle[this_circle].box.bottom = (int32_t) stripf(circ->y + inner_radius);
@ -499,12 +490,12 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
circ = circ->next; circ = circ->next;
} }
// Hexagons /* Hexagons */
previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f; previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f;
hex = symbol->vector->hexagons; hex = symbol->vector->hexagons;
this_hexagon = 0; this_hexagon = 0;
while (hex) { while (hex) {
hexagon[this_hexagon].type = 0x00000003; // EMR_POLYGON hexagon[this_hexagon].type = 0x00000003; /* EMR_POLYGON */
hexagon[this_hexagon].size = 76; hexagon[this_hexagon].size = 76;
hexagon[this_hexagon].count = 6; hexagon[this_hexagon].count = 6;
@ -544,21 +535,21 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
bold = (symbol->output_options & BOLD_TEXT) && bold = (symbol->output_options & BOLD_TEXT) &&
(!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT)); (!is_extendable(symbol->symbology) || (symbol->output_options & SMALL_TEXT));
memset(&emr_extcreatefontindirectw, 0, sizeof(emr_extcreatefontindirectw)); memset(&emr_extcreatefontindirectw, 0, sizeof(emr_extcreatefontindirectw));
emr_extcreatefontindirectw.type = 0x00000052; // EMR_EXTCREATEFONTINDIRECTW emr_extcreatefontindirectw.type = 0x00000052; /* EMR_EXTCREATEFONTINDIRECTW */
emr_extcreatefontindirectw.size = 104; emr_extcreatefontindirectw.size = 104;
emr_extcreatefontindirectw.ih_fonts = 12; emr_extcreatefontindirectw.ih_fonts = 12;
emr_extcreatefontindirectw.elw.height = (int32_t) fsize; emr_extcreatefontindirectw.elw.height = (int32_t) fsize;
emr_extcreatefontindirectw.elw.width = 0; // automatic emr_extcreatefontindirectw.elw.width = 0; /* automatic */
emr_extcreatefontindirectw.elw.weight = bold ? 700 : 400; emr_extcreatefontindirectw.elw.weight = bold ? 700 : 400;
emr_extcreatefontindirectw.elw.char_set = 0x00; // ANSI_CHARSET emr_extcreatefontindirectw.elw.char_set = 0x00; /* ANSI_CHARSET */
emr_extcreatefontindirectw.elw.out_precision = 0x00; // OUT_DEFAULT_PRECIS emr_extcreatefontindirectw.elw.out_precision = 0x00; /* OUT_DEFAULT_PRECIS */
emr_extcreatefontindirectw.elw.clip_precision = 0x00; // CLIP_DEFAULT_PRECIS emr_extcreatefontindirectw.elw.clip_precision = 0x00; /* CLIP_DEFAULT_PRECIS */
emr_extcreatefontindirectw.elw.pitch_and_family = 0x02 | (0x02 << 6); // FF_SWISS | VARIABLE_PITCH emr_extcreatefontindirectw.elw.pitch_and_family = 0x02 | (0x02 << 6); /* FF_SWISS | VARIABLE_PITCH */
utfle_copy(emr_extcreatefontindirectw.elw.facename, (unsigned char *) "sans-serif", 10); utfle_copy(emr_extcreatefontindirectw.elw.facename, (unsigned char *) "sans-serif", 10);
bytecount += 104; bytecount += 104;
recordcount++; recordcount++;
emr_selectobject_font.type = 0x00000025; // EMR_SELECTOBJECT emr_selectobject_font.type = 0x00000025; /* EMR_SELECTOBJECT */
emr_selectobject_font.size = 12; emr_selectobject_font.size = 12;
emr_selectobject_font.ih_object = 12; emr_selectobject_font.ih_object = 12;
bytecount += 12; bytecount += 12;
@ -571,7 +562,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
bytecount += 104; bytecount += 104;
recordcount++; recordcount++;
emr_selectobject_font2.type = 0x00000025; // EMR_SELECTOBJECT emr_selectobject_font2.type = 0x00000025; /* EMR_SELECTOBJECT */
emr_selectobject_font2.size = 12; emr_selectobject_font2.size = 12;
emr_selectobject_font2.ih_object = 13; emr_selectobject_font2.ih_object = 13;
bytecount += 12; bytecount += 12;
@ -580,21 +571,21 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
/* Note select aligns counted below in strings loop */ /* Note select aligns counted below in strings loop */
emr_settextalign.type = 0x00000016; // EMR_SETTEXTALIGN emr_settextalign.type = 0x00000016; /* EMR_SETTEXTALIGN */
emr_settextalign.size = 12; emr_settextalign.size = 12;
emr_settextalign.text_alignment_mode = 0x0006 | 0x0018; // TA_CENTER | TA_BASELINE emr_settextalign.text_alignment_mode = 0x0006 | 0x0018; /* TA_CENTER | TA_BASELINE */
if (halign1) { if (halign1) {
emr_settextalign1.type = 0x00000016; // EMR_SETTEXTALIGN emr_settextalign1.type = 0x00000016; /* EMR_SETTEXTALIGN */
emr_settextalign1.size = 12; emr_settextalign1.size = 12;
emr_settextalign1.text_alignment_mode = 0x0000 | 0x0018; // TA_LEFT | TA_BASELINE emr_settextalign1.text_alignment_mode = 0x0000 | 0x0018; /* TA_LEFT | TA_BASELINE */
} }
if (halign2) { if (halign2) {
emr_settextalign2.type = 0x00000016; // EMR_SETTEXTALIGN emr_settextalign2.type = 0x00000016; /* EMR_SETTEXTALIGN */
emr_settextalign2.size = 12; emr_settextalign2.size = 12;
emr_settextalign2.text_alignment_mode = 0x0002 | 0x0018; // TA_RIGHT | TA_BASELINE emr_settextalign2.text_alignment_mode = 0x0002 | 0x0018; /* TA_RIGHT | TA_BASELINE */
} }
emr_settextcolor.type = 0x0000018; // EMR_SETTEXTCOLOR emr_settextcolor.type = 0x0000018; /* EMR_SETTEXTCOLOR */
emr_settextcolor.size = 12; emr_settextcolor.size = 12;
emr_settextcolor.color.red = fgred; emr_settextcolor.color.red = fgred;
emr_settextcolor.color.green = fggrn; emr_settextcolor.color.green = fggrn;
@ -604,9 +595,9 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
recordcount++; recordcount++;
} }
// Text /* Text */
this_text = 0; this_text = 0;
// Loop over font sizes so that they're grouped together, so only have to select font twice at most /* Loop over font sizes so that they're grouped together, so only have to select font twice at most */
for (i = 0, current_fsize = fsize; i < 2 && current_fsize; i++, current_fsize = fsize2) { for (i = 0, current_fsize = fsize; i < 2 && current_fsize; i++, current_fsize = fsize2) {
str = symbol->vector->strings; str = symbol->vector->strings;
current_halign = -1; current_halign = -1;
@ -635,13 +626,13 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
return ZINT_ERROR_MEMORY; return ZINT_ERROR_MEMORY;
} }
memset(this_string[this_text], 0, bumped_len); memset(this_string[this_text], 0, bumped_len);
text[this_text].type = 0x00000054; // EMR_EXTTEXTOUTW text[this_text].type = 0x00000054; /* EMR_EXTTEXTOUTW */
text[this_text].size = 76 + bumped_len; text[this_text].size = 76 + bumped_len;
text[this_text].bounds.top = 0; // ignored text[this_text].bounds.top = 0; /* ignored */
text[this_text].bounds.left = 0; // ignored text[this_text].bounds.left = 0; /* ignored */
text[this_text].bounds.right = 0xffffffff; // ignored text[this_text].bounds.right = 0xffffffff; /* ignored */
text[this_text].bounds.bottom = 0xffffffff; // ignored text[this_text].bounds.bottom = 0xffffffff; /* ignored */
text[this_text].i_graphics_mode = 0x00000002; // GM_ADVANCED text[this_text].i_graphics_mode = 0x00000002; /* GM_ADVANCED */
text[this_text].ex_scale = 1.0f; text[this_text].ex_scale = 1.0f;
text[this_text].ey_scale = 1.0f; text[this_text].ey_scale = 1.0f;
text[this_text].w_emr_text.reference.x = (int32_t) str->x; text[this_text].w_emr_text.reference.x = (int32_t) str->x;
@ -666,8 +657,8 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
assert(this_text == string_count); assert(this_text == string_count);
/* Create EOF record */ /* Create EOF record */
emr_eof.type = 0x0000000e; // EMR_EOF emr_eof.type = 0x0000000e; /* EMR_EOF */
emr_eof.size = 20; // Assuming no palette entries emr_eof.size = 20; /* Assuming no palette entries */
emr_eof.n_pal_entries = 0; emr_eof.n_pal_entries = 0;
emr_eof.off_pal_entries = 0; emr_eof.off_pal_entries = 0;
emr_eof.size_last = emr_eof.size; emr_eof.size_last = emr_eof.size;
@ -753,20 +744,20 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
} else { } else {
fwrite(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, emf_file); fwrite(&emr_selectobject_fgbrush, sizeof(emr_selectobject_t), 1, emf_file);
// Rectangles /* Rectangles */
for (i = 0; i < rectangle_count; i++) { 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 /* Hexagons */
for (i = 0; i < hexagon_count; i++) { 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 /* Circles */
if (symbol->symbology == BARCODE_MAXICODE) { if (symbol->symbology == BARCODE_MAXICODE) {
// Bullseye needed /* Bullseye needed */
for (i = 0; i < circle_count; i++) { 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 < circle_count - 1) {
@ -783,7 +774,7 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
} }
} }
// Text /* Text */
if (string_count > 0) { if (string_count > 0) {
fwrite(&emr_selectobject_font, sizeof(emr_selectobject_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); fwrite(&emr_settextcolor, sizeof(emr_settextcolor_t), 1, emf_file);
@ -820,3 +811,5 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
} }
return error_number; return error_number;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,7 +1,7 @@
/* emf.h - header structure for Microsoft EMF /* emf.h - header structure for Microsoft EMF */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2016-2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2016-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,22 +28,15 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#ifndef EMF_H #ifndef Z_EMF_H
#define EMF_H #define Z_EMF_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef _MSC_VER
#include <windows.h>
#include "stdint_msvc.h"
#else
#include <stdint.h>
#endif
#pragma pack(1) #pragma pack(1)
typedef struct rect_l { typedef struct rect_l {
@ -122,11 +115,11 @@ extern "C" {
uint32_t n_pal_entries; uint32_t n_pal_entries;
size_l_t device; size_l_t device;
size_l_t millimeters; size_l_t millimeters;
// HeaderExtension1 Object /* HeaderExtension1 Object */
uint32_t cb_pixel_format; uint32_t cb_pixel_format;
uint32_t off_pixel_format; uint32_t off_pixel_format;
uint32_t b_open_gl; uint32_t b_open_gl;
// HeaderExtension2 Object /* HeaderExtension2 Object */
size_l_t micrometers; size_l_t micrometers;
} emf_header_t; } emf_header_t;
@ -248,4 +241,5 @@ extern "C" {
} }
#endif #endif
#endif /* EMF_H */ /* vim: set ts=4 sw=4 et : */
#endif /* Z_EMF_H */

View File

@ -1,8 +1,7 @@
/* gif.c - Handles output to gif file */ /* gif.c - Handles output to gif file */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,16 +28,14 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
#include <math.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#include <malloc.h>
#endif #endif
/* Limit initial LZW buffer size to this in expectation that compressed data will fit for typical scalings */ /* Limit initial LZW buffer size to this in expectation that compressed data will fit for typical scalings */
@ -197,7 +194,7 @@ static int gif_lzw(statestruct *pState, int paletteBitSize) {
unsigned char CodeBits; unsigned char CodeBits;
unsigned short Pos; unsigned short Pos;
// > Get first data byte /* > Get first data byte */
if (pState->InLen == 0) if (pState->InLen == 0)
return 0; return 0;
PixelValueCur = NextPaletteIndex(pState); PixelValueCur = NextPaletteIndex(pState);
@ -243,7 +240,7 @@ static int gif_lzw(statestruct *pState, int paletteBitSize) {
Res = NextCode(pState, &PixelValueCur, CodeBits); Res = NextCode(pState, &PixelValueCur, CodeBits);
if (Res < 0) if (Res < 0)
return 0; return 0;
//* Check for end of data stream */ /* Check for end of data stream */
if (!Res) { if (!Res) {
/* submit 'eoi' as the last item of the code stream */ /* submit 'eoi' as the last item of the code stream */
if (AddCodeToBuffer(pState, (unsigned short) (pState->ClearCode + 1), CodeBits)) if (AddCodeToBuffer(pState, (unsigned short) (pState->ClearCode + 1), CodeBits))
@ -253,7 +250,7 @@ static int gif_lzw(statestruct *pState, int paletteBitSize) {
if (BufferNextByte(pState)) if (BufferNextByte(pState))
return 0; return 0;
} }
// > Update last bytecount byte; /* > Update last bytecount byte; */
if (pState->OutByteCountPos < pState->OutPosCur) { if (pState->OutByteCountPos < pState->OutPosCur) {
(pState->pOut)[pState->OutByteCountPos] (pState->pOut)[pState->OutByteCountPos]
= (unsigned char) (pState->OutPosCur - pState->OutByteCountPos - 1); = (unsigned char) (pState->OutPosCur - pState->OutByteCountPos - 1);
@ -440,13 +437,13 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
transparent_index = -1; transparent_index = -1;
if (strlen(symbol->fgcolour) > 6) { if (strlen(symbol->fgcolour) > 6) {
if ((symbol->fgcolour[6] == '0') && (symbol->fgcolour[7] == '0')) { if ((symbol->fgcolour[6] == '0') && (symbol->fgcolour[7] == '0')) {
// Transparent foreground /* Transparent foreground */
transparent_index = fgindex; transparent_index = fgindex;
} }
} }
if (strlen(symbol->bgcolour) > 6) { if (strlen(symbol->bgcolour) > 6) {
if ((symbol->bgcolour[6] == '0') && (symbol->bgcolour[7] == '0')) { if ((symbol->bgcolour[6] == '0') && (symbol->bgcolour[7] == '0')) {
// Transparent background /* Transparent background */
transparent_index = bgindex; transparent_index = bgindex;
} }
} }
@ -616,3 +613,5 @@ INTERNAL int gif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,5 +1,5 @@
/* gridmtx.c - Grid Matrix /* gridmtx.c - Grid Matrix */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
@ -34,9 +34,6 @@
AIM Global Document Number AIMD014 Rev. 1.63 Revised 9 Dec 2008 */ AIM Global Document Number AIMD014 Rev. 1.63 Revised 9 Dec 2008 */
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "reedsol.h" #include "reedsol.h"
#include "gridmtx.h" #include "gridmtx.h"
@ -164,11 +161,7 @@ static void gm_define_mode(char *mode, const unsigned int ddata[], const int len
char cur_mode; char cur_mode;
unsigned int prev_costs[GM_NUM_MODES]; unsigned int prev_costs[GM_NUM_MODES];
unsigned int cur_costs[GM_NUM_MODES]; unsigned int cur_costs[GM_NUM_MODES];
#ifndef _MSC_VER char *char_modes = (char *) z_alloca(length * GM_NUM_MODES);
char char_modes[length * GM_NUM_MODES];
#else
char *char_modes = (char *) _alloca(length * GM_NUM_MODES);
#endif
/* char_modes[i * GM_NUM_MODES + j] represents the mode to encode the code point at index i such that the final /* char_modes[i * GM_NUM_MODES + j] represents the mode to encode the code point at index i such that the final
* segment ends in mode_types[j] and the total number of bits is minimized over all possible choices */ * segment ends in mode_types[j] and the total number of bits is minimized over all possible choices */
@ -345,11 +338,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
int byte_count = 0; int byte_count = 0;
int shift; int shift;
int bp = *p_bp; int bp = *p_bp;
#ifndef _MSC_VER char *mode = (char *) z_alloca(length);
char mode[length];
#else
char *mode = (char *) _alloca(length);
#endif
if (eci != 0) { if (eci != 0) {
/* ECI assignment according to Table 8 */ /* ECI assignment according to Table 8 */
@ -407,13 +396,13 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
switch (p) { switch (p) {
case 1: binary[number_pad_posn] = '1'; case 1: binary[number_pad_posn] = '1';
binary[number_pad_posn + 1] = '0'; binary[number_pad_posn + 1] = '0';
break; // 2 pad digits break; /* 2 pad digits */
case 2: binary[number_pad_posn] = '0'; case 2: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '1'; binary[number_pad_posn + 1] = '1';
break; // 1 pad digits break; /* 1 pad digits */
case 3: binary[number_pad_posn] = '0'; case 3: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '0'; binary[number_pad_posn + 1] = '0';
break; // 0 pad digits break; /* 0 pad digits */
} }
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: bp = bin_append_posn(1019, 10, binary, bp); case GM_CHINESE: bp = bin_append_posn(1019, 10, binary, bp);
@ -739,13 +728,13 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
switch (p) { switch (p) {
case 1: binary[number_pad_posn] = '1'; case 1: binary[number_pad_posn] = '1';
binary[number_pad_posn + 1] = '0'; binary[number_pad_posn + 1] = '0';
break; // 2 pad digits break; /* 2 pad digits */
case 2: binary[number_pad_posn] = '0'; case 2: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '1'; binary[number_pad_posn + 1] = '1';
break; // 1 pad digit break; /* 1 pad digit */
case 3: binary[number_pad_posn] = '0'; case 3: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '0'; binary[number_pad_posn + 1] = '0';
break; // 0 pad digits break; /* 0 pad digits */
} }
} }
@ -979,14 +968,8 @@ static void gm_place_data_in_grid(unsigned char word[], char grid[], int modules
/* Place the layer ID into each macromodule */ /* Place the layer ID into each macromodule */
static void gm_place_layer_id(char *grid, int size, int layers, int modules, int ecc_level) { static void gm_place_layer_id(char *grid, int size, int layers, int modules, int ecc_level) {
int i, j, layer, start, stop; int i, j, layer, start, stop;
int *layerid = (int *) z_alloca(sizeof(int) * (layers + 1));
#ifndef _MSC_VER int *id = (int *) z_alloca(sizeof(int) * (modules * modules));
int layerid[layers + 1];
int id[modules * modules];
#else
int *layerid = (int *) _alloca((layers + 1) * sizeof(int));
int *id = (int *) _alloca((modules * modules) * sizeof(int));
#endif
/* Calculate Layer IDs */ /* Calculate Layer IDs */
for (i = 0; i <= layers; i++) { for (i = 0; i <= layers; i++) {
@ -1045,15 +1028,9 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons
int bin_len; int bin_len;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
const int eci_length_segs = get_eci_length_segs(segs, seg_count); const int eci_length_segs = get_eci_length_segs(segs, seg_count);
struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count);
#ifndef _MSC_VER unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * eci_length_segs);
struct zint_seg local_segs[seg_count];
unsigned int ddata[eci_length_segs];
#else
struct zint_seg *local_segs = (struct zint_seg *) _alloca(sizeof(struct zint_seg) * seg_count);
unsigned int *ddata = (unsigned int *) _alloca(sizeof(unsigned int) * eci_length_segs);
char *grid; char *grid;
#endif
segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs & protect lengths) */ segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs & protect lengths) */
@ -1224,12 +1201,7 @@ INTERNAL int gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[], cons
modules = 1 + (layers * 2); modules = 1 + (layers * 2);
size_squared = size * size; size_squared = size * size;
#ifndef _MSC_VER grid = (char *) z_alloca(size_squared);
char grid[size_squared];
#else
grid = (char *) _alloca(size_squared);
#endif
memset(grid, '0', size_squared); memset(grid, '0', size_squared);
gm_place_data_in_grid(word, grid, modules, size); gm_place_data_in_grid(word, grid, modules, size);

View File

@ -1,5 +1,5 @@
/* gridmtx.h - definitions for Grid Matrix /* gridmtx.h - definitions for Grid Matrix */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
@ -28,6 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef Z_GRIDMTX_H #ifndef Z_GRIDMTX_H
#define Z_GRIDMTX_H #define Z_GRIDMTX_H
@ -79,67 +80,67 @@ static const char gm_b2[] = {
/* Values from table A.1 */ /* Values from table A.1 */
static const char gm_ebeb[] = { static const char gm_ebeb[] = {
/* E1 B3 E2 B4 */ /* E1 B3 E2 B4 */
0, 0, 0, 0, // version 1 0, 0, 0, 0, /* version 1 */
3, 1, 0, 0, 3, 1, 0, 0,
5, 1, 0, 0, 5, 1, 0, 0,
7, 1, 0, 0, 7, 1, 0, 0,
9, 1, 0, 0, 9, 1, 0, 0,
5, 1, 0, 0, // version 2 5, 1, 0, 0, /* version 2 */
10, 1, 0, 0, 10, 1, 0, 0,
15, 1, 0, 0, 15, 1, 0, 0,
20, 1, 0, 0, 20, 1, 0, 0,
25, 1, 0, 0, 25, 1, 0, 0,
9, 1, 0, 0, // version 3 9, 1, 0, 0, /* version 3 */
19, 1, 0, 0, 19, 1, 0, 0,
29, 1, 0, 0, 29, 1, 0, 0,
39, 1, 0, 0, 39, 1, 0, 0,
49, 1, 0, 0, 49, 1, 0, 0,
8, 2, 0, 0, // version 4 8, 2, 0, 0, /* version 4 */
16, 2, 0, 0, 16, 2, 0, 0,
24, 2, 0, 0, 24, 2, 0, 0,
32, 2, 0, 0, 32, 2, 0, 0,
41, 1, 40, 1, 41, 1, 40, 1,
12, 2, 0, 0, // version 5 12, 2, 0, 0, /* version 5 */
24, 2, 0, 0, 24, 2, 0, 0,
36, 2, 0, 0, 36, 2, 0, 0,
48, 2, 0, 0, 48, 2, 0, 0,
61, 1, 60, 1, 61, 1, 60, 1,
11, 3, 0, 0, // version 6 11, 3, 0, 0, /* version 6 */
23, 1, 22, 2, 23, 1, 22, 2,
34, 2, 33, 1, 34, 2, 33, 1,
45, 3, 0, 0, 45, 3, 0, 0,
57, 1, 56, 2, 57, 1, 56, 2,
12, 1, 11, 3, // version 7 12, 1, 11, 3, /* version 7 */
23, 2, 22, 2, 23, 2, 22, 2,
34, 3, 33, 1, 34, 3, 33, 1,
45, 4, 0, 0, 45, 4, 0, 0,
57, 1, 56, 3, 57, 1, 56, 3,
12, 2, 11, 3, // version 8 12, 2, 11, 3, /* version 8 */
23, 5, 0, 0, 23, 5, 0, 0,
35, 3, 34, 2, 35, 3, 34, 2,
47, 1, 46, 4, 47, 1, 46, 4,
58, 4, 57, 1, 58, 4, 57, 1,
12, 6, 0, 0, // version 9 12, 6, 0, 0, /* version 9 */
24, 6, 0, 0, 24, 6, 0, 0,
36, 6, 0, 0, 36, 6, 0, 0,
48, 6, 0, 0, 48, 6, 0, 0,
61, 1, 60, 5, 61, 1, 60, 5,
13, 4, 12, 3, // version 10 13, 4, 12, 3, /* version 10 */
26, 1, 25, 6, 26, 1, 25, 6,
38, 5, 37, 2, 38, 5, 37, 2,
51, 2, 50, 5, 51, 2, 50, 5,
63, 7, 0, 0, 63, 7, 0, 0,
12, 6, 11, 3, // version 11 12, 6, 11, 3, /* version 11 */
24, 4, 23, 5, 24, 4, 23, 5,
36, 2, 35, 7, 36, 2, 35, 7,
47, 9, 0, 0, 47, 9, 0, 0,
59, 7, 58, 2, 59, 7, 58, 2,
13, 5, 12, 5, // version 12 13, 5, 12, 5, /* version 12 */
25, 10, 0, 0, 25, 10, 0, 0,
38, 5, 37, 5, 38, 5, 37, 5,
50, 10, 0, 0, 50, 10, 0, 0,
63, 5, 62, 5, 63, 5, 62, 5,
13, 1, 12, 11, //version 13 13, 1, 12, 11, /* version 13 */
25, 3, 24, 9, 25, 3, 24, 9,
37, 5, 36, 7, 37, 5, 36, 7,
49, 7, 48, 5, 49, 7, 48, 5,

View File

@ -31,9 +31,6 @@
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "gs1.h" #include "gs1.h"
@ -1189,14 +1186,10 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
char obracket = symbol->input_mode & GS1PARENS_MODE ? '(' : '['; char obracket = symbol->input_mode & GS1PARENS_MODE ? '(' : '[';
char cbracket = symbol->input_mode & GS1PARENS_MODE ? ')' : ']'; char cbracket = symbol->input_mode & GS1PARENS_MODE ? ')' : ']';
int ai_max = chr_cnt(source, src_len, obracket) + 1; /* Plus 1 so non-zero */ int ai_max = chr_cnt(source, src_len, obracket) + 1; /* Plus 1 so non-zero */
#ifndef _MSC_VER int *ai_value = (int *) z_alloca(sizeof(int) * ai_max);
int ai_value[ai_max], ai_location[ai_max], data_location[ai_max], data_length[ai_max]; int *ai_location = (int *) z_alloca(sizeof(int) * ai_max);
#else int *data_location = (int *) z_alloca(sizeof(int) * ai_max);
int *ai_value = (int *) _alloca(ai_max * sizeof(int)); int *data_length = (int *) z_alloca(sizeof(int) * ai_max);
int *ai_location = (int *) _alloca(ai_max * sizeof(int));
int *data_location = (int *) _alloca(ai_max * sizeof(int));
int *data_length = (int *) _alloca(ai_max * sizeof(int));
#endif
/* Detect extended ASCII characters */ /* Detect extended ASCII characters */
for (i = 0; i < src_len; i++) { for (i = 0; i < src_len; i++) {
@ -1327,8 +1320,8 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
} }
} }
// Check for valid AI values and data lengths according to GS1 General /* Check for valid AI values and data lengths according to GS1 General
// Specifications Release 21.0.1, January 2021 Specifications Release 21.0.1, January 2021 */
for (i = 0; i < ai_count; i++) { for (i = 0; i < ai_count; i++) {
int err_no, err_posn; int err_no, err_posn;
char err_msg[50]; char err_msg[50];

View File

@ -34,9 +34,6 @@
* (previously ISO/IEC 20830 (draft 2019-10-10) and AIMD-015:2010 (Rev 0.8)) */ * (previously ISO/IEC 20830 (draft 2019-10-10) and AIMD-015:2010 (Rev 0.8)) */
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "reedsol.h" #include "reedsol.h"
#include "hanxin.h" #include "hanxin.h"
@ -392,11 +389,7 @@ static void hx_define_mode(char *mode, const unsigned int ddata[], const int len
char cur_mode; char cur_mode;
unsigned int prev_costs[HX_NUM_MODES]; unsigned int prev_costs[HX_NUM_MODES];
unsigned int cur_costs[HX_NUM_MODES]; unsigned int cur_costs[HX_NUM_MODES];
#ifndef _MSC_VER char *char_modes = (char *) z_alloca(length * HX_NUM_MODES);
char char_modes[length * HX_NUM_MODES];
#else
char *char_modes = (char *) _alloca(length * HX_NUM_MODES);
#endif
/* char_modes[i * HX_NUM_MODES + j] represents the mode to encode the code point at index i such that the final /* char_modes[i * HX_NUM_MODES + j] represents the mode to encode the code point at index i such that the final
* segment ends in mode_types[j] and the total number of bits is minimized over all possible choices */ * segment ends in mode_types[j] and the total number of bits is minimized over all possible choices */
@ -526,7 +519,7 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
if (eci != 0) { if (eci != 0) {
/* Encoding ECI assignment number, according to Table 5 */ /* Encoding ECI assignment number, according to Table 5 */
bp = bin_append_posn(8, 4, binary, bp); // ECI bp = bin_append_posn(8, 4, binary, bp); /* ECI */
if (eci <= 127) { if (eci <= 127) {
bp = bin_append_posn(eci, 8, binary, bp); bp = bin_append_posn(eci, 8, binary, bp);
} else if (eci <= 16383) { } else if (eci <= 16383) {
@ -1128,7 +1121,7 @@ static void hx_add_ecc(unsigned char fullstream[], const unsigned char datastrea
const int table_d1_pos = ((version - 1) * 36) + ((ecc_level - 1) * 9); const int table_d1_pos = ((version - 1) * 36) + ((ecc_level - 1) * 9);
rs_t rs; rs_t rs;
rs_init_gf(&rs, 0x163); // x^8 + x^6 + x^5 + x + 1 = 0 rs_init_gf(&rs, 0x163); /* x^8 + x^6 + x^5 + x + 1 = 0 */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
const int batch_size = hx_table_d1[table_d1_pos + (3 * i)]; const int batch_size = hx_table_d1[table_d1_pos + (3 * i)];
@ -1393,14 +1386,8 @@ static void hx_apply_bitmask(unsigned char *grid, const int size, const int vers
int best_pattern; int best_pattern;
int bit; int bit;
const int size_squared = size * size; const int size_squared = size * size;
unsigned char *mask = (unsigned char *) z_alloca(size_squared);
#ifndef _MSC_VER unsigned char *local = (unsigned char *) z_alloca(size_squared);
unsigned char mask[size_squared];
unsigned char local[size_squared];
#else
unsigned char *mask = (unsigned char *) _alloca(size_squared);
unsigned char *local = (unsigned char *) _alloca(size_squared);
#endif
/* Perform data masking */ /* Perform data masking */
memset(mask, 0, size_squared); memset(mask, 0, size_squared);
@ -1428,7 +1415,7 @@ static void hx_apply_bitmask(unsigned char *grid, const int size, const int vers
if (user_mask) { if (user_mask) {
best_pattern = user_mask - 1; best_pattern = user_mask - 1;
} else { } else {
// apply data masks to grid, result in local /* apply data masks to grid, result in local */
/* Do null pattern 00 separately first */ /* Do null pattern 00 separately first */
pattern = 0; pattern = 0;
@ -1501,21 +1488,14 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in
int bin_len; int bin_len;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
const int eci_length_segs = get_eci_length_segs(segs, seg_count); const int eci_length_segs = get_eci_length_segs(segs, seg_count);
struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count);
#ifndef _MSC_VER unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * eci_length_segs);
struct zint_seg local_segs[seg_count]; char *mode = (char *) z_alloca(eci_length_segs);
unsigned int ddata[eci_length_segs];
char mode[eci_length_segs];
#else
struct zint_seg *local_segs = (struct zint_seg *) _alloca(sizeof(struct zint_seg) * seg_count);
unsigned int *ddata = (unsigned int *) _alloca(sizeof(unsigned int) * eci_length_segs);
char *mode = (char *) _alloca(eci_length_segs);
char *binary; char *binary;
unsigned char *datastream; unsigned char *datastream;
unsigned char *fullstream; unsigned char *fullstream;
unsigned char *picket_fence; unsigned char *picket_fence;
unsigned char *grid; unsigned char *grid;
#endif
segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECI & protect lengths) */ segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECI & protect lengths) */
@ -1562,11 +1542,7 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in
est_binlen = hx_calc_binlen_segs(mode, ddata, local_segs, seg_count); est_binlen = hx_calc_binlen_segs(mode, ddata, local_segs, seg_count);
#ifndef _MSC_VER binary = (char *) z_alloca((est_binlen + 1));
char binary[est_binlen + 1];
#else
binary = (char *) _alloca((est_binlen + 1));
#endif
if ((ecc_level <= 0) || (ecc_level >= 5)) { if ((ecc_level <= 0) || (ecc_level >= 5)) {
ecc_level = 1; ecc_level = 1;
@ -1655,17 +1631,10 @@ INTERNAL int hanxin(struct zint_symbol *symbol, struct zint_seg segs[], const in
size = (version * 2) + 21; size = (version * 2) + 21;
size_squared = size * size; size_squared = size * size;
#ifndef _MSC_VER datastream = (unsigned char *) z_alloca(data_codewords);
unsigned char datastream[data_codewords]; fullstream = (unsigned char *) z_alloca(hx_total_codewords[version - 1]);
unsigned char fullstream[hx_total_codewords[version - 1]]; picket_fence = (unsigned char *) z_alloca(hx_total_codewords[version - 1]);
unsigned char picket_fence[hx_total_codewords[version - 1]]; grid = (unsigned char *) z_alloca(size_squared);
unsigned char grid[size_squared];
#else
datastream = (unsigned char *) _alloca(data_codewords);
fullstream = (unsigned char *) _alloca(hx_total_codewords[version - 1]);
picket_fence = (unsigned char *) _alloca(hx_total_codewords[version - 1]);
grid = (unsigned char *) _alloca(size_squared);
#endif
memset(datastream, 0, data_codewords); memset(datastream, 0, data_codewords);

View File

@ -1,5 +1,5 @@
/* hanxin.h - definitions for Han Xin code /* hanxin.h - definitions for Han Xin code */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2016 Zoe Stuart Copyright (C) 2016 Zoe Stuart
@ -29,6 +29,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef Z_HANXIN_H #ifndef Z_HANXIN_H
#define Z_HANXIN_H #define Z_HANXIN_H
@ -124,339 +125,339 @@ static const char hx_module_m[] = {
/* Error correction block sizes from Table D1 */ /* Error correction block sizes from Table D1 */
static const unsigned char hx_table_d1[] = { static const unsigned char hx_table_d1[] = {
/* #blocks, k, 2t, #blocks, k, 2t, #blocks, k, 2t */ /* #blocks, k, 2t, #blocks, k, 2t, #blocks, k, 2t */
1, 21, 4, 0, 0, 0, 0, 0, 0, // version 1 1, 21, 4, 0, 0, 0, 0, 0, 0, /* version 1 */
1, 17, 8, 0, 0, 0, 0, 0, 0, 1, 17, 8, 0, 0, 0, 0, 0, 0,
1, 13, 12, 0, 0, 0, 0, 0, 0, 1, 13, 12, 0, 0, 0, 0, 0, 0,
1, 9, 16, 0, 0, 0, 0, 0, 0, 1, 9, 16, 0, 0, 0, 0, 0, 0,
1, 31, 6, 0, 0, 0, 0, 0, 0, // version 2 1, 31, 6, 0, 0, 0, 0, 0, 0, /* version 2 */
1, 25, 12, 0, 0, 0, 0, 0, 0, 1, 25, 12, 0, 0, 0, 0, 0, 0,
1, 19, 18, 0, 0, 0, 0, 0, 0, 1, 19, 18, 0, 0, 0, 0, 0, 0,
1, 15, 22, 0, 0, 0, 0, 0, 0, 1, 15, 22, 0, 0, 0, 0, 0, 0,
1, 42, 8, 0, 0, 0, 0, 0, 0, // version 3 1, 42, 8, 0, 0, 0, 0, 0, 0, /* version 3 */
1, 34, 16, 0, 0, 0, 0, 0, 0, 1, 34, 16, 0, 0, 0, 0, 0, 0,
1, 26, 24, 0, 0, 0, 0, 0, 0, 1, 26, 24, 0, 0, 0, 0, 0, 0,
1, 20, 30, 0, 0, 0, 0, 0, 0, 1, 20, 30, 0, 0, 0, 0, 0, 0,
1, 46, 8, 0, 0, 0, 0, 0, 0, // version 4 1, 46, 8, 0, 0, 0, 0, 0, 0, /* version 4 */
1, 38, 16, 0, 0, 0, 0, 0, 0, 1, 38, 16, 0, 0, 0, 0, 0, 0,
1, 30, 24, 0, 0, 0, 0, 0, 0, 1, 30, 24, 0, 0, 0, 0, 0, 0,
1, 22, 32, 0, 0, 0, 0, 0, 0, 1, 22, 32, 0, 0, 0, 0, 0, 0,
1, 57, 12, 0, 0, 0, 0, 0, 0, // version 5 1, 57, 12, 0, 0, 0, 0, 0, 0, /* version 5 */
1, 49, 20, 0, 0, 0, 0, 0, 0, 1, 49, 20, 0, 0, 0, 0, 0, 0,
1, 37, 32, 0, 0, 0, 0, 0, 0, 1, 37, 32, 0, 0, 0, 0, 0, 0,
1, 14, 20, 1, 13, 22, 0, 0, 0, 1, 14, 20, 1, 13, 22, 0, 0, 0,
1, 70, 14, 0, 0, 0, 0, 0, 0, // version 6 1, 70, 14, 0, 0, 0, 0, 0, 0, /* version 6 */
1, 58, 26, 0, 0, 0, 0, 0, 0, 1, 58, 26, 0, 0, 0, 0, 0, 0,
1, 24, 20, 1, 22, 18, 0, 0, 0, 1, 24, 20, 1, 22, 18, 0, 0, 0,
1, 16, 24, 1, 18, 26, 0, 0, 0, 1, 16, 24, 1, 18, 26, 0, 0, 0,
1, 84, 16, 0, 0, 0, 0, 0, 0, // version 7 1, 84, 16, 0, 0, 0, 0, 0, 0, /* version 7 */
1, 70, 30, 0, 0, 0, 0, 0, 0, 1, 70, 30, 0, 0, 0, 0, 0, 0,
1, 26, 22, 1, 28, 24, 0, 0, 0, 1, 26, 22, 1, 28, 24, 0, 0, 0,
2, 14, 20, 1, 12, 20, 0, 0, 0, 2, 14, 20, 1, 12, 20, 0, 0, 0,
1, 99, 18, 0, 0, 0, 0, 0, 0, // version 8 1, 99, 18, 0, 0, 0, 0, 0, 0, /* version 8 */
1, 40, 18, 1, 41, 18, 0, 0, 0, 1, 40, 18, 1, 41, 18, 0, 0, 0,
1, 31, 26, 1, 32, 28, 0, 0, 0, 1, 31, 26, 1, 32, 28, 0, 0, 0,
2, 16, 24, 1, 15, 22, 0, 0, 0, 2, 16, 24, 1, 15, 22, 0, 0, 0,
1, 114, 22, 0, 0, 0, 0, 0, 0, // version 9 1, 114, 22, 0, 0, 0, 0, 0, 0, /* version 9 */
2, 48, 20, 0, 0, 0, 0, 0, 0, 2, 48, 20, 0, 0, 0, 0, 0, 0,
2, 24, 20, 1, 26, 22, 0, 0, 0, 2, 24, 20, 1, 26, 22, 0, 0, 0,
2, 18, 28, 1, 18, 26, 0, 0, 0, 2, 18, 28, 1, 18, 26, 0, 0, 0,
1, 131, 24, 0, 0, 0, 0, 0, 0, // version 10 1, 131, 24, 0, 0, 0, 0, 0, 0, /* version 10 */
1, 52, 22, 1, 57, 24, 0, 0, 0, 1, 52, 22, 1, 57, 24, 0, 0, 0,
2, 27, 24, 1, 29, 24, 0, 0, 0, 2, 27, 24, 1, 29, 24, 0, 0, 0,
2, 21, 32, 1, 19, 30, 0, 0, 0, 2, 21, 32, 1, 19, 30, 0, 0, 0,
1, 135, 26, 0, 0, 0, 0, 0, 0, // version 11 1, 135, 26, 0, 0, 0, 0, 0, 0, /* version 11 */
1, 56, 24, 1, 57, 24, 0, 0, 0, 1, 56, 24, 1, 57, 24, 0, 0, 0,
2, 28, 24, 1, 31, 26, 0, 0, 0, 2, 28, 24, 1, 31, 26, 0, 0, 0,
2, 22, 32, 1, 21, 32, 0, 0, 0, 2, 22, 32, 1, 21, 32, 0, 0, 0,
1, 153, 28, 0, 0, 0, 0, 0, 0, // version 12 1, 153, 28, 0, 0, 0, 0, 0, 0, /* version 12 */
1, 62, 26, 1, 65, 28, 0, 0, 0, 1, 62, 26, 1, 65, 28, 0, 0, 0,
2, 32, 28, 1, 33, 28, 0, 0, 0, 2, 32, 28, 1, 33, 28, 0, 0, 0,
3, 17, 26, 1, 22, 30, 0, 0, 0, 3, 17, 26, 1, 22, 30, 0, 0, 0,
1, 86, 16, 1, 85, 16, 0, 0, 0, // version 13 1, 86, 16, 1, 85, 16, 0, 0, 0, /* version 13 */
1, 71, 30, 1, 72, 30, 0, 0, 0, 1, 71, 30, 1, 72, 30, 0, 0, 0,
2, 37, 32, 1, 35, 30, 0, 0, 0, 2, 37, 32, 1, 35, 30, 0, 0, 0,
3, 20, 30, 1, 21, 32, 0, 0, 0, 3, 20, 30, 1, 21, 32, 0, 0, 0,
1, 94, 18, 1, 95, 18, 0, 0, 0, // version 14 1, 94, 18, 1, 95, 18, 0, 0, 0, /* version 14 */
2, 51, 22, 1, 55, 24, 0, 0, 0, 2, 51, 22, 1, 55, 24, 0, 0, 0,
3, 30, 26, 1, 31, 26, 0, 0, 0, 3, 30, 26, 1, 31, 26, 0, 0, 0,
4, 18, 28, 1, 17, 24, 0, 0, 0, 4, 18, 28, 1, 17, 24, 0, 0, 0,
1, 104, 20, 1, 105, 20, 0, 0, 0, // version 15 1, 104, 20, 1, 105, 20, 0, 0, 0, /* version 15 */
2, 57, 24, 1, 61, 26, 0, 0, 0, 2, 57, 24, 1, 61, 26, 0, 0, 0,
3, 33, 28, 1, 36, 30, 0, 0, 0, 3, 33, 28, 1, 36, 30, 0, 0, 0,
4, 20, 30, 1, 19, 30, 0, 0, 0, 4, 20, 30, 1, 19, 30, 0, 0, 0,
1, 115, 22, 1, 114, 22, 0, 0, 0, // version 16 1, 115, 22, 1, 114, 22, 0, 0, 0, /* version 16 */
2, 65, 28, 1, 61, 26, 0, 0, 0, 2, 65, 28, 1, 61, 26, 0, 0, 0,
3, 38, 32, 1, 33, 30, 0, 0, 0, 3, 38, 32, 1, 33, 30, 0, 0, 0,
5, 19, 28, 1, 14, 24, 0, 0, 0, 5, 19, 28, 1, 14, 24, 0, 0, 0,
1, 126, 24, 1, 125, 24, 0, 0, 0, // version 17 1, 126, 24, 1, 125, 24, 0, 0, 0, /* version 17 */
2, 70, 30, 1, 69, 30, 0, 0, 0, 2, 70, 30, 1, 69, 30, 0, 0, 0,
4, 33, 28, 1, 29, 26, 0, 0, 0, 4, 33, 28, 1, 29, 26, 0, 0, 0,
5, 20, 30, 1, 19, 30, 0, 0, 0, 5, 20, 30, 1, 19, 30, 0, 0, 0,
1, 136, 26, 1, 137, 26, 0, 0, 0, //version 18 1, 136, 26, 1, 137, 26, 0, 0, 0, /* version 18 */
3, 56, 24, 1, 59, 26, 0, 0, 0, 3, 56, 24, 1, 59, 26, 0, 0, 0,
5, 35, 30, 0, 0, 0, 0, 0, 0, 5, 35, 30, 0, 0, 0, 0, 0, 0,
6, 18, 28, 1, 21, 28, 0, 0, 0, 6, 18, 28, 1, 21, 28, 0, 0, 0,
1, 148, 28, 1, 149, 28, 0, 0, 0, // version 19 1, 148, 28, 1, 149, 28, 0, 0, 0, /* version 19 */
3, 61, 26, 1, 64, 28, 0, 0, 0, 3, 61, 26, 1, 64, 28, 0, 0, 0,
7, 24, 20, 1, 23, 22, 0, 0, 0, 7, 24, 20, 1, 23, 22, 0, 0, 0,
6, 20, 30, 1, 21, 32, 0, 0, 0, 6, 20, 30, 1, 21, 32, 0, 0, 0,
3, 107, 20, 0, 0, 0, 0, 0, 0, // version 20 3, 107, 20, 0, 0, 0, 0, 0, 0, /* version 20 */
3, 65, 28, 1, 72, 30, 0, 0, 0, 3, 65, 28, 1, 72, 30, 0, 0, 0,
7, 26, 22, 1, 23, 22, 0, 0, 0, 7, 26, 22, 1, 23, 22, 0, 0, 0,
7, 19, 28, 1, 20, 32, 0, 0, 0, 7, 19, 28, 1, 20, 32, 0, 0, 0,
3, 115, 22, 0, 0, 0, 0, 0, 0, // version 21 3, 115, 22, 0, 0, 0, 0, 0, 0, /* version 21 */
4, 56, 24, 1, 63, 28, 0, 0, 0, 4, 56, 24, 1, 63, 28, 0, 0, 0,
7, 28, 24, 1, 25, 22, 0, 0, 0, 7, 28, 24, 1, 25, 22, 0, 0, 0,
8, 18, 28, 1, 21, 22, 0, 0, 0, 8, 18, 28, 1, 21, 22, 0, 0, 0,
2, 116, 22, 1, 122, 24, 0, 0, 0, // version 22 2, 116, 22, 1, 122, 24, 0, 0, 0, /* version 22 */
4, 56, 24, 1, 72, 30, 0, 0, 0, 4, 56, 24, 1, 72, 30, 0, 0, 0,
7, 28, 24, 1, 32, 26, 0, 0, 0, 7, 28, 24, 1, 32, 26, 0, 0, 0,
8, 18, 28, 1, 24, 30, 0, 0, 0, 8, 18, 28, 1, 24, 30, 0, 0, 0,
3, 127, 24, 0, 0, 0, 0, 0, 0, // version 23 3, 127, 24, 0, 0, 0, 0, 0, 0, /* version 23 */
5, 51, 22, 1, 62, 26, 0, 0, 0, 5, 51, 22, 1, 62, 26, 0, 0, 0,
7, 30, 26, 1, 35, 26, 0, 0, 0, 7, 30, 26, 1, 35, 26, 0, 0, 0,
8, 20, 30, 1, 21, 32, 0, 0, 0, 8, 20, 30, 1, 21, 32, 0, 0, 0,
2, 135, 26, 1, 137, 26, 0, 0, 0, // version 24 2, 135, 26, 1, 137, 26, 0, 0, 0, /* version 24 */
5, 56, 24, 1, 59, 26, 0, 0, 0, 5, 56, 24, 1, 59, 26, 0, 0, 0,
7, 33, 28, 1, 30, 28, 0, 0, 0, 7, 33, 28, 1, 30, 28, 0, 0, 0,
11, 16, 24, 1, 19, 26, 0, 0, 0, 11, 16, 24, 1, 19, 26, 0, 0, 0,
3, 105, 20, 1, 121, 22, 0, 0, 0, // version 25 3, 105, 20, 1, 121, 22, 0, 0, 0, /* version 25 */
5, 61, 26, 1, 57, 26, 0, 0, 0, 5, 61, 26, 1, 57, 26, 0, 0, 0,
9, 28, 24, 1, 28, 22, 0, 0, 0, 9, 28, 24, 1, 28, 22, 0, 0, 0,
10, 19, 28, 1, 18, 30, 0, 0, 0, 10, 19, 28, 1, 18, 30, 0, 0, 0,
2, 157, 30, 1, 150, 28, 0, 0, 0, // version 26 2, 157, 30, 1, 150, 28, 0, 0, 0, /* version 26 */
5, 65, 28, 1, 61, 26, 0, 0, 0, 5, 65, 28, 1, 61, 26, 0, 0, 0,
8, 33, 28, 1, 34, 30, 0, 0, 0, 8, 33, 28, 1, 34, 30, 0, 0, 0,
10, 19, 28, 2, 15, 26, 0, 0, 0, 10, 19, 28, 2, 15, 26, 0, 0, 0,
3, 126, 24, 1, 115, 22, 0, 0, 0, // version 27 3, 126, 24, 1, 115, 22, 0, 0, 0, /* version 27 */
7, 51, 22, 1, 54, 22, 0, 0, 0, 7, 51, 22, 1, 54, 22, 0, 0, 0,
8, 35, 30, 1, 37, 30, 0, 0, 0, 8, 35, 30, 1, 37, 30, 0, 0, 0,
15, 15, 22, 1, 10, 22, 0, 0, 0, 15, 15, 22, 1, 10, 22, 0, 0, 0,
4, 105, 20, 1, 103, 20, 0, 0, 0, // version 28 4, 105, 20, 1, 103, 20, 0, 0, 0, /* version 28 */
7, 56, 24, 1, 45, 18, 0, 0, 0, 7, 56, 24, 1, 45, 18, 0, 0, 0,
10, 31, 26, 1, 27, 26, 0, 0, 0, 10, 31, 26, 1, 27, 26, 0, 0, 0,
10, 17, 26, 3, 20, 28, 1, 21, 28, 10, 17, 26, 3, 20, 28, 1, 21, 28,
3, 139, 26, 1, 137, 28, 0, 0, 0, // version 29 3, 139, 26, 1, 137, 28, 0, 0, 0, /* version 29 */
6, 66, 28, 1, 66, 30, 0, 0, 0, 6, 66, 28, 1, 66, 30, 0, 0, 0,
9, 36, 30, 1, 34, 32, 0, 0, 0, 9, 36, 30, 1, 34, 32, 0, 0, 0,
13, 19, 28, 1, 17, 32, 0, 0, 0, 13, 19, 28, 1, 17, 32, 0, 0, 0,
6, 84, 16, 1, 82, 16, 0, 0, 0, // version 30 6, 84, 16, 1, 82, 16, 0, 0, 0, /* version 30 */
6, 70, 30, 1, 68, 30, 0, 0, 0, 6, 70, 30, 1, 68, 30, 0, 0, 0,
7, 35, 30, 3, 33, 28, 1, 32, 28, 7, 35, 30, 3, 33, 28, 1, 32, 28,
13, 20, 30, 1, 20, 28, 0, 0, 0, 13, 20, 30, 1, 20, 28, 0, 0, 0,
5, 105, 20, 1, 94, 18, 0, 0, 0, // version 31 5, 105, 20, 1, 94, 18, 0, 0, 0, /* version 31 */
6, 74, 32, 1, 71, 30, 0, 0, 0, 6, 74, 32, 1, 71, 30, 0, 0, 0,
11, 33, 28, 1, 34, 32, 0, 0, 0, 11, 33, 28, 1, 34, 32, 0, 0, 0,
13, 19, 28, 3, 16, 26, 0, 0, 0, 13, 19, 28, 3, 16, 26, 0, 0, 0,
4, 127, 24, 1, 126, 24, 0, 0, 0, // version 32 4, 127, 24, 1, 126, 24, 0, 0, 0, /* version 32 */
7, 66, 28, 1, 66, 30, 0, 0, 0, 7, 66, 28, 1, 66, 30, 0, 0, 0,
12, 30, 24, 1, 24, 28, 1, 24, 30, 12, 30, 24, 1, 24, 28, 1, 24, 30,
15, 19, 28, 1, 17, 32, 0, 0, 0, 15, 19, 28, 1, 17, 32, 0, 0, 0,
7, 84, 16, 1, 78, 16, 0, 0, 0, // version 33 7, 84, 16, 1, 78, 16, 0, 0, 0, /* version 33 */
7, 70, 30, 1, 66, 28, 0, 0, 0, 7, 70, 30, 1, 66, 28, 0, 0, 0,
12, 33, 28, 1, 32, 30, 0, 0, 0, 12, 33, 28, 1, 32, 30, 0, 0, 0,
14, 21, 32, 1, 24, 28, 0, 0, 0, 14, 21, 32, 1, 24, 28, 0, 0, 0,
5, 117, 22, 1, 117, 24, 0, 0, 0, // version 34 5, 117, 22, 1, 117, 24, 0, 0, 0, /* version 34 */
8, 66, 28, 1, 58, 26, 0, 0, 0, 8, 66, 28, 1, 58, 26, 0, 0, 0,
11, 38, 32, 1, 34, 32, 0, 0, 0, 11, 38, 32, 1, 34, 32, 0, 0, 0,
15, 20, 30, 2, 17, 26, 0, 0, 0, 15, 20, 30, 2, 17, 26, 0, 0, 0,
4, 148, 28, 1, 146, 28, 0, 0, 0, // version 35 4, 148, 28, 1, 146, 28, 0, 0, 0, /* version 35 */
8, 68, 30, 1, 70, 24, 0, 0, 0, 8, 68, 30, 1, 70, 24, 0, 0, 0,
10, 36, 32, 3, 38, 28, 0, 0, 0, 10, 36, 32, 3, 38, 28, 0, 0, 0,
16, 19, 28, 3, 16, 26, 0, 0, 0, 16, 19, 28, 3, 16, 26, 0, 0, 0,
4, 126, 24, 2, 135, 26, 0, 0, 0, // version 36 4, 126, 24, 2, 135, 26, 0, 0, 0, /* version 36 */
8, 70, 28, 2, 43, 26, 0, 0, 0, 8, 70, 28, 2, 43, 26, 0, 0, 0,
13, 32, 28, 2, 41, 30, 0, 0, 0, 13, 32, 28, 2, 41, 30, 0, 0, 0,
17, 19, 28, 3, 15, 26, 0, 0, 0, 17, 19, 28, 3, 15, 26, 0, 0, 0,
5, 136, 26, 1, 132, 24, 0, 0, 0, // version 37 5, 136, 26, 1, 132, 24, 0, 0, 0, /* version 37 */
5, 67, 30, 4, 68, 28, 1, 69, 28, 5, 67, 30, 4, 68, 28, 1, 69, 28,
14, 35, 30, 1, 32, 24, 0, 0, 0, 14, 35, 30, 1, 32, 24, 0, 0, 0,
18, 18, 26, 3, 16, 28, 1, 14, 28, 18, 18, 26, 3, 16, 28, 1, 14, 28,
3, 142, 26, 3, 141, 28, 0, 0, 0, // version 38 3, 142, 26, 3, 141, 28, 0, 0, 0, /* version 38 */
8, 70, 30, 1, 73, 32, 1, 74, 32, 8, 70, 30, 1, 73, 32, 1, 74, 32,
12, 34, 30, 3, 34, 26, 1, 35, 28, 12, 34, 30, 3, 34, 26, 1, 35, 28,
18, 21, 32, 1, 27, 30, 0, 0, 0, 18, 21, 32, 1, 27, 30, 0, 0, 0,
5, 116, 22, 2, 103, 20, 1, 102, 20, // version 39 5, 116, 22, 2, 103, 20, 1, 102, 20, /* version 39 */
9, 74, 32, 1, 74, 30, 0, 0, 0, 9, 74, 32, 1, 74, 30, 0, 0, 0,
14, 34, 28, 2, 32, 32, 1, 32, 30, 14, 34, 28, 2, 32, 32, 1, 32, 30,
19, 21, 32, 1, 25, 26, 0, 0, 0, 19, 21, 32, 1, 25, 26, 0, 0, 0,
7, 116, 22, 1, 117, 22, 0, 0, 0, // version 40 7, 116, 22, 1, 117, 22, 0, 0, 0, /* version 40 */
11, 65, 28, 1, 58, 24, 0, 0, 0, 11, 65, 28, 1, 58, 24, 0, 0, 0,
15, 38, 32, 1, 27, 28, 0, 0, 0, 15, 38, 32, 1, 27, 28, 0, 0, 0,
20, 20, 30, 1, 20, 32, 1, 21, 32, 20, 20, 30, 1, 20, 32, 1, 21, 32,
6, 136, 26, 1, 130, 24, 0, 0, 0, // version 41 6, 136, 26, 1, 130, 24, 0, 0, 0, /* version 41 */
11, 66, 28, 1, 62, 30, 0, 0, 0, 11, 66, 28, 1, 62, 30, 0, 0, 0,
14, 34, 28, 3, 34, 32, 1, 30, 30, 14, 34, 28, 3, 34, 32, 1, 30, 30,
18, 20, 30, 3, 20, 28, 2, 15, 26, 18, 20, 30, 3, 20, 28, 2, 15, 26,
5, 105, 20, 2, 115, 22, 2, 116, 22, // version 42 5, 105, 20, 2, 115, 22, 2, 116, 22, /* version 42 */
10, 75, 32, 1, 73, 32, 0, 0, 0, 10, 75, 32, 1, 73, 32, 0, 0, 0,
16, 38, 32, 1, 27, 28, 0, 0, 0, 16, 38, 32, 1, 27, 28, 0, 0, 0,
22, 19, 28, 2, 16, 30, 1, 19, 30, 22, 19, 28, 2, 16, 30, 1, 19, 30,
6, 147, 28, 1, 146, 28, 0, 0, 0, // version 43 6, 147, 28, 1, 146, 28, 0, 0, 0, /* version 43 */
11, 66, 28, 2, 65, 30, 0, 0, 0, 11, 66, 28, 2, 65, 30, 0, 0, 0,
18, 33, 28, 2, 33, 30, 0, 0, 0, 18, 33, 28, 2, 33, 30, 0, 0, 0,
22, 21, 32, 1, 28, 30, 0, 0, 0, 22, 21, 32, 1, 28, 30, 0, 0, 0,
6, 116, 22, 3, 125, 24, 0, 0, 0, // version 44 6, 116, 22, 3, 125, 24, 0, 0, 0, /* version 44 */
11, 75, 32, 1, 68, 30, 0, 0, 0, 11, 75, 32, 1, 68, 30, 0, 0, 0,
13, 35, 28, 6, 34, 32, 1, 30, 30, 13, 35, 28, 6, 34, 32, 1, 30, 30,
23, 21, 32, 1, 26, 30, 0, 0, 0, 23, 21, 32, 1, 26, 30, 0, 0, 0,
7, 105, 20, 4, 95, 18, 0, 0, 0, // version 45 7, 105, 20, 4, 95, 18, 0, 0, 0, /* version 45 */
12, 67, 28, 1, 63, 30, 1, 62, 32, 12, 67, 28, 1, 63, 30, 1, 62, 32,
21, 31, 26, 2, 33, 32, 0, 0, 0, 21, 31, 26, 2, 33, 32, 0, 0, 0,
23, 21, 32, 2, 24, 30, 0, 0, 0, 23, 21, 32, 2, 24, 30, 0, 0, 0,
10, 116, 22, 0, 0, 0, 0, 0, 0, // version 46 10, 116, 22, 0, 0, 0, 0, 0, 0, /* version 46 */
12, 74, 32, 1, 78, 30, 0, 0, 0, 12, 74, 32, 1, 78, 30, 0, 0, 0,
18, 37, 32, 1, 39, 30, 1, 41, 28, 18, 37, 32, 1, 39, 30, 1, 41, 28,
25, 21, 32, 1, 27, 28, 0, 0, 0, 25, 21, 32, 1, 27, 28, 0, 0, 0,
5, 126, 24, 4, 115, 22, 1, 114, 22, // version 47 5, 126, 24, 4, 115, 22, 1, 114, 22, /* version 47 */
12, 67, 28, 2, 66, 32, 1, 68, 30, 12, 67, 28, 2, 66, 32, 1, 68, 30,
21, 35, 30, 1, 39, 30, 0, 0, 0, 21, 35, 30, 1, 39, 30, 0, 0, 0,
26, 21, 32, 1, 28, 28, 0, 0, 0, 26, 21, 32, 1, 28, 28, 0, 0, 0,
9, 126, 24, 1, 117, 22, 0, 0, 0, // version 48 9, 126, 24, 1, 117, 22, 0, 0, 0, /* version 48 */
13, 75, 32, 1, 68, 30, 0, 0, 0, 13, 75, 32, 1, 68, 30, 0, 0, 0,
20, 35, 30, 3, 35, 28, 0, 0, 0, 20, 35, 30, 3, 35, 28, 0, 0, 0,
27, 21, 32, 1, 28, 30, 0, 0, 0, 27, 21, 32, 1, 28, 30, 0, 0, 0,
9, 126, 24, 1, 137, 26, 0, 0, 0, // version 49 9, 126, 24, 1, 137, 26, 0, 0, 0, /* version 49 */
13, 71, 30, 2, 68, 32, 0, 0, 0, 13, 71, 30, 2, 68, 32, 0, 0, 0,
20, 37, 32, 1, 39, 28, 1, 38, 28, 20, 37, 32, 1, 39, 28, 1, 38, 28,
24, 20, 32, 5, 25, 28, 0, 0, 0, 24, 20, 32, 5, 25, 28, 0, 0, 0,
8, 147, 28, 1, 141, 28, 0, 0, 0, // version 50 8, 147, 28, 1, 141, 28, 0, 0, 0, /* version 50 */
10, 73, 32, 4, 74, 30, 1, 73, 30, 10, 73, 32, 4, 74, 30, 1, 73, 30,
16, 36, 32, 6, 39, 30, 1, 37, 30, 16, 36, 32, 6, 39, 30, 1, 37, 30,
27, 21, 32, 3, 20, 26, 0, 0, 0, 27, 21, 32, 3, 20, 26, 0, 0, 0,
9, 137, 26, 1, 135, 26, 0, 0, 0, // version 51 9, 137, 26, 1, 135, 26, 0, 0, 0, /* version 51 */
12, 70, 30, 4, 75, 32, 0, 0, 0, 12, 70, 30, 4, 75, 32, 0, 0, 0,
24, 35, 30, 1, 40, 28, 0, 0, 0, 24, 35, 30, 1, 40, 28, 0, 0, 0,
23, 20, 32, 8, 24, 30, 0, 0, 0, 23, 20, 32, 8, 24, 30, 0, 0, 0,
14, 95, 18, 1, 86, 18, 0, 0, 0, // version 52 14, 95, 18, 1, 86, 18, 0, 0, 0, /* version 52 */
13, 73, 32, 3, 77, 30, 0, 0, 0, 13, 73, 32, 3, 77, 30, 0, 0, 0,
24, 35, 30, 2, 35, 28, 0, 0, 0, 24, 35, 30, 2, 35, 28, 0, 0, 0,
26, 21, 32, 5, 21, 30, 1, 23, 30, 26, 21, 32, 5, 21, 30, 1, 23, 30,
9, 147, 28, 1, 142, 28, 0, 0, 0, // version 53 9, 147, 28, 1, 142, 28, 0, 0, 0, /* version 53 */
10, 73, 30, 6, 70, 32, 1, 71, 32, 10, 73, 30, 6, 70, 32, 1, 71, 32,
25, 35, 30, 2, 34, 26, 0, 0, 0, 25, 35, 30, 2, 34, 26, 0, 0, 0,
29, 21, 32, 4, 22, 30, 0, 0, 0, 29, 21, 32, 4, 22, 30, 0, 0, 0,
11, 126, 24, 1, 131, 24, 0, 0, 0, // version 54 11, 126, 24, 1, 131, 24, 0, 0, 0, /* version 54 */
16, 74, 32, 1, 79, 30, 0, 0, 0, 16, 74, 32, 1, 79, 30, 0, 0, 0,
25, 38, 32, 1, 25, 30, 0, 0, 0, 25, 38, 32, 1, 25, 30, 0, 0, 0,
33, 21, 32, 1, 28, 28, 0, 0, 0, 33, 21, 32, 1, 28, 28, 0, 0, 0,
14, 105, 20, 1, 99, 18, 0, 0, 0, // version 55 14, 105, 20, 1, 99, 18, 0, 0, 0, /* version 55 */
19, 65, 28, 1, 72, 28, 0, 0, 0, 19, 65, 28, 1, 72, 28, 0, 0, 0,
24, 37, 32, 2, 40, 30, 1, 41, 30, 24, 37, 32, 2, 40, 30, 1, 41, 30,
31, 21, 32, 4, 24, 32, 0, 0, 0, 31, 21, 32, 4, 24, 32, 0, 0, 0,
10, 147, 28, 1, 151, 28, 0, 0, 0, // version 56 10, 147, 28, 1, 151, 28, 0, 0, 0, /* version 56 */
15, 71, 30, 3, 71, 32, 1, 73, 32, 15, 71, 30, 3, 71, 32, 1, 73, 32,
24, 37, 32, 3, 38, 30, 1, 39, 30, 24, 37, 32, 3, 38, 30, 1, 39, 30,
36, 19, 30, 3, 29, 26, 0, 0, 0, 36, 19, 30, 3, 29, 26, 0, 0, 0,
15, 105, 20, 1, 99, 18, 0, 0, 0, // version 57 15, 105, 20, 1, 99, 18, 0, 0, 0, /* version 57 */
19, 70, 30, 1, 64, 28, 0, 0, 0, 19, 70, 30, 1, 64, 28, 0, 0, 0,
27, 38, 32, 2, 25, 26, 0, 0, 0, 27, 38, 32, 2, 25, 26, 0, 0, 0,
38, 20, 30, 2, 18, 28, 0, 0, 0, 38, 20, 30, 2, 18, 28, 0, 0, 0,
14, 105, 20, 1, 113, 22, 1, 114, 22, // version 58 14, 105, 20, 1, 113, 22, 1, 114, 22, /* version 58 */
17, 67, 30, 3, 92, 32, 0, 0, 0, 17, 67, 30, 3, 92, 32, 0, 0, 0,
30, 35, 30, 1, 41, 30, 0, 0, 0, 30, 35, 30, 1, 41, 30, 0, 0, 0,
36, 21, 32, 1, 26, 30, 1, 27, 30, 36, 21, 32, 1, 26, 30, 1, 27, 30,
11, 146, 28, 1, 146, 26, 0, 0, 0, // version 59 11, 146, 28, 1, 146, 26, 0, 0, 0, /* version 59 */
20, 70, 30, 1, 60, 26, 0, 0, 0, 20, 70, 30, 1, 60, 26, 0, 0, 0,
29, 38, 32, 1, 24, 32, 0, 0, 0, 29, 38, 32, 1, 24, 32, 0, 0, 0,
40, 20, 30, 2, 17, 26, 0, 0, 0, 40, 20, 30, 2, 17, 26, 0, 0, 0,
3, 137, 26, 1, 136, 26, 10, 126, 24, // version 60 3, 137, 26, 1, 136, 26, 10, 126, 24, /* version 60 */
22, 65, 28, 1, 75, 30, 0, 0, 0, 22, 65, 28, 1, 75, 30, 0, 0, 0,
30, 37, 32, 1, 51, 30, 0, 0, 0, 30, 37, 32, 1, 51, 30, 0, 0, 0,
42, 20, 30, 1, 21, 30, 0, 0, 0, 42, 20, 30, 1, 21, 30, 0, 0, 0,
12, 126, 24, 2, 118, 22, 1, 116, 22, // version 61 12, 126, 24, 2, 118, 22, 1, 116, 22, /* version 61 */
19, 74, 32, 1, 74, 30, 1, 72, 28, 19, 74, 32, 1, 74, 30, 1, 72, 28,
30, 38, 32, 2, 29, 30, 0, 0, 0, 30, 38, 32, 2, 29, 30, 0, 0, 0,
39, 20, 32, 2, 37, 26, 1, 38, 26, 39, 20, 32, 2, 37, 26, 1, 38, 26,
12, 126, 24, 3, 136, 26, 0, 0, 0, // version 62 12, 126, 24, 3, 136, 26, 0, 0, 0, /* version 62 */
21, 70, 30, 2, 65, 28, 0, 0, 0, 21, 70, 30, 2, 65, 28, 0, 0, 0,
34, 35, 30, 1, 44, 32, 0, 0, 0, 34, 35, 30, 1, 44, 32, 0, 0, 0,
42, 20, 30, 2, 19, 28, 2, 18, 28, 42, 20, 30, 2, 19, 28, 2, 18, 28,
12, 126, 24, 3, 117, 22, 1, 116, 22, // version 63 12, 126, 24, 3, 117, 22, 1, 116, 22, /* version 63 */
25, 61, 26, 2, 62, 28, 0, 0, 0, 25, 61, 26, 2, 62, 28, 0, 0, 0,
34, 35, 30, 1, 40, 32, 1, 41, 32, 34, 35, 30, 1, 40, 32, 1, 41, 32,
45, 20, 30, 1, 20, 32, 1, 21, 32, 45, 20, 30, 1, 20, 32, 1, 21, 32,
15, 105, 20, 2, 115, 22, 2, 116, 22, // version 64 15, 105, 20, 2, 115, 22, 2, 116, 22, /* version 64 */
25, 65, 28, 1, 72, 28, 0, 0, 0, 25, 65, 28, 1, 72, 28, 0, 0, 0,
18, 35, 30, 17, 37, 32, 1, 50, 32, 18, 35, 30, 17, 37, 32, 1, 50, 32,
42, 20, 30, 6, 19, 28, 1, 15, 28, 42, 20, 30, 6, 19, 28, 1, 15, 28,
19, 105, 20, 1, 101, 20, 0, 0, 0, // version 65 19, 105, 20, 1, 101, 20, 0, 0, 0, /* version 65 */
33, 51, 22, 1, 65, 22, 0, 0, 0, 33, 51, 22, 1, 65, 22, 0, 0, 0,
40, 33, 28, 1, 28, 28, 0, 0, 0, 40, 33, 28, 1, 28, 28, 0, 0, 0,
49, 20, 30, 1, 18, 28, 0, 0, 0, 49, 20, 30, 1, 18, 28, 0, 0, 0,
18, 105, 20, 2, 117, 22, 0, 0, 0, // version 66 18, 105, 20, 2, 117, 22, 0, 0, 0, /* version 66 */
26, 65, 28, 1, 80, 30, 0, 0, 0, 26, 65, 28, 1, 80, 30, 0, 0, 0,
35, 35, 30, 3, 35, 28, 1, 36, 28, 35, 35, 30, 3, 35, 28, 1, 36, 28,
52, 18, 28, 2, 38, 30, 0, 0, 0, 52, 18, 28, 2, 38, 30, 0, 0, 0,
26, 84, 16, 0, 0, 0, 0, 0, 0, // version 67 26, 84, 16, 0, 0, 0, 0, 0, 0, /* version 67 */
26, 70, 30, 0, 0, 0, 0, 0, 0, 26, 70, 30, 0, 0, 0, 0, 0, 0,
45, 31, 26, 1, 9, 26, 0, 0, 0, 45, 31, 26, 1, 9, 26, 0, 0, 0,
52, 20, 30, 0, 0, 0, 0, 0, 0, 52, 20, 30, 0, 0, 0, 0, 0, 0,
16, 126, 24, 1, 114, 22, 1, 115, 22, // version 68 16, 126, 24, 1, 114, 22, 1, 115, 22, /* version 68 */
23, 70, 30, 3, 65, 28, 1, 66, 28, 23, 70, 30, 3, 65, 28, 1, 66, 28,
40, 35, 30, 1, 43, 30, 0, 0, 0, 40, 35, 30, 1, 43, 30, 0, 0, 0,
46, 20, 30, 7, 19, 28, 1, 16, 28, 46, 20, 30, 7, 19, 28, 1, 16, 28,
19, 116, 22, 1, 105, 22, 0, 0, 0, // version 69 19, 116, 22, 1, 105, 22, 0, 0, 0, /* version 69 */
20, 70, 30, 7, 66, 28, 1, 63, 28, 20, 70, 30, 7, 66, 28, 1, 63, 28,
40, 35, 30, 1, 42, 32, 1, 43, 32, 40, 35, 30, 1, 42, 32, 1, 43, 32,
54, 20, 30, 1, 19, 30, 0, 0, 0, 54, 20, 30, 1, 19, 30, 0, 0, 0,
17, 126, 24, 2, 115, 22, 0, 0, 0, // version 70 17, 126, 24, 2, 115, 22, 0, 0, 0, /* version 70 */
24, 70, 30, 4, 74, 32, 0, 0, 0, 24, 70, 30, 4, 74, 32, 0, 0, 0,
48, 31, 26, 2, 18, 26, 0, 0, 0, 48, 31, 26, 2, 18, 26, 0, 0, 0,
54, 19, 28, 6, 15, 26, 1, 14, 26, 54, 19, 28, 6, 15, 26, 1, 14, 26,
29, 84, 16, 0, 0, 0, 0, 0, 0, // version 71 29, 84, 16, 0, 0, 0, 0, 0, 0, /* version 71 */
29, 70, 30, 0, 0, 0, 0, 0, 0, 29, 70, 30, 0, 0, 0, 0, 0, 0,
6, 34, 30, 3, 36, 30, 38, 33, 28, 6, 34, 30, 3, 36, 30, 38, 33, 28,
58, 20, 30, 0, 0, 0, 0, 0, 0, 58, 20, 30, 0, 0, 0, 0, 0, 0,
16, 147, 28, 1, 149, 28, 0, 0, 0, // version 72 16, 147, 28, 1, 149, 28, 0, 0, 0, /* version 72 */
31, 66, 28, 1, 37, 26, 0, 0, 0, 31, 66, 28, 1, 37, 26, 0, 0, 0,
48, 33, 28, 1, 23, 26, 0, 0, 0, 48, 33, 28, 1, 23, 26, 0, 0, 0,
53, 20, 30, 6, 19, 28, 1, 17, 28, 53, 20, 30, 6, 19, 28, 1, 17, 28,
20, 115, 22, 2, 134, 24, 0, 0, 0, // verdion 73 20, 115, 22, 2, 134, 24, 0, 0, 0, /* verdion 73 */
29, 66, 28, 2, 56, 26, 2, 57, 26, 29, 66, 28, 2, 56, 26, 2, 57, 26,
45, 36, 30, 2, 15, 28, 0, 0, 0, 45, 36, 30, 2, 15, 28, 0, 0, 0,
59, 20, 30, 2, 21, 32, 0, 0, 0, 59, 20, 30, 2, 21, 32, 0, 0, 0,
17, 147, 28, 1, 134, 26, 0, 0, 0, // version 74 17, 147, 28, 1, 134, 26, 0, 0, 0, /* version 74 */
26, 70, 30, 5, 75, 32, 0, 0, 0, 26, 70, 30, 5, 75, 32, 0, 0, 0,
47, 35, 30, 1, 48, 32, 0, 0, 0, 47, 35, 30, 1, 48, 32, 0, 0, 0,
64, 18, 28, 2, 33, 30, 1, 35, 30, 64, 18, 28, 2, 33, 30, 1, 35, 30,
22, 115, 22, 1, 133, 24, 0, 0, 0, // version 75 22, 115, 22, 1, 133, 24, 0, 0, 0, /* version 75 */
33, 65, 28, 1, 74, 28, 0, 0, 0, 33, 65, 28, 1, 74, 28, 0, 0, 0,
43, 36, 30, 5, 27, 28, 1, 30, 28, 43, 36, 30, 5, 27, 28, 1, 30, 28,
57, 20, 30, 5, 21, 32, 1, 24, 32, 57, 20, 30, 5, 21, 32, 1, 24, 32,
18, 136, 26, 2, 142, 26, 0, 0, 0, // version 76 18, 136, 26, 2, 142, 26, 0, 0, 0, /* version 76 */
33, 66, 28, 2, 49, 26, 0, 0, 0, 33, 66, 28, 2, 49, 26, 0, 0, 0,
48, 35, 30, 2, 38, 28, 0, 0, 0, 48, 35, 30, 2, 38, 28, 0, 0, 0,
64, 20, 30, 1, 20, 32, 0, 0, 0, 64, 20, 30, 1, 20, 32, 0, 0, 0,
19, 126, 24, 2, 135, 26, 1, 136, 26, // version 77 19, 126, 24, 2, 135, 26, 1, 136, 26, /* version 77 */
32, 66, 28, 2, 55, 26, 2, 56, 26, 32, 66, 28, 2, 55, 26, 2, 56, 26,
49, 36, 30, 2, 18, 32, 0, 0, 0, 49, 36, 30, 2, 18, 32, 0, 0, 0,
65, 18, 28, 5, 27, 30, 1, 29, 30, 65, 18, 28, 5, 27, 30, 1, 29, 30,
20, 137, 26, 1, 130, 26, 0, 0, 0, // version 78 20, 137, 26, 1, 130, 26, 0, 0, 0, /* version 78 */
30, 75, 32, 2, 71, 32, 0, 0, 0, 30, 75, 32, 2, 71, 32, 0, 0, 0,
46, 35, 30, 6, 39, 32, 0, 0, 0, 46, 35, 30, 6, 39, 32, 0, 0, 0,
3, 12, 30, 70, 19, 28, 0, 0, 0, 3, 12, 30, 70, 19, 28, 0, 0, 0,
20, 147, 28, 0, 0, 0, 0, 0, 0, // version 79 20, 147, 28, 0, 0, 0, 0, 0, 0, /* version 79 */
35, 70, 30, 0, 0, 0, 0, 0, 0, 35, 70, 30, 0, 0, 0, 0, 0, 0,
49, 35, 30, 5, 35, 28, 0, 0, 0, 49, 35, 30, 5, 35, 28, 0, 0, 0,
70, 20, 30, 0, 0, 0, 0, 0, 0, 70, 20, 30, 0, 0, 0, 0, 0, 0,
21, 136, 26, 1, 155, 28, 0, 0, 0, // version 80 21, 136, 26, 1, 155, 28, 0, 0, 0, /* version 80 */
34, 70, 30, 1, 64, 28, 1, 65, 28, 34, 70, 30, 1, 64, 28, 1, 65, 28,
54, 35, 30, 1, 45, 30, 0, 0, 0, 54, 35, 30, 1, 45, 30, 0, 0, 0,
68, 20, 30, 3, 18, 28, 1, 19, 28, 68, 20, 30, 3, 18, 28, 1, 19, 28,
19, 126, 24, 5, 115, 22, 1, 114, 22, // version 81 19, 126, 24, 5, 115, 22, 1, 114, 22, /* version 81 */
33, 70, 30, 3, 65, 28, 1, 64, 28, 33, 70, 30, 3, 65, 28, 1, 64, 28,
52, 35, 30, 3, 41, 32, 1, 40, 32, 52, 35, 30, 3, 41, 32, 1, 40, 32,
67, 20, 30, 5, 21, 32, 1, 24, 32, 67, 20, 30, 5, 21, 32, 1, 24, 32,
2, 150, 28, 21, 136, 26, 0, 0, 0, // version 82 2, 150, 28, 21, 136, 26, 0, 0, 0, /* version 82 */
32, 70, 30, 6, 65, 28, 0, 0, 0, 32, 70, 30, 6, 65, 28, 0, 0, 0,
52, 38, 32, 2, 27, 32, 0, 0, 0, 52, 38, 32, 2, 27, 32, 0, 0, 0,
73, 20, 30, 2, 22, 32, 0, 0, 0, 73, 20, 30, 2, 22, 32, 0, 0, 0,
21, 126, 24, 4, 136, 26, 0, 0, 0, // version 83 21, 126, 24, 4, 136, 26, 0, 0, 0, /* version 83 */
30, 74, 32, 6, 73, 30, 0, 0, 0, 30, 74, 32, 6, 73, 30, 0, 0, 0,
54, 35, 30, 4, 40, 32, 0, 0, 0, 54, 35, 30, 4, 40, 32, 0, 0, 0,
75, 20, 30, 1, 20, 28, 0, 0, 0, 75, 20, 30, 1, 20, 28, 0, 0, 0,
30, 105, 20, 1, 114, 22, 0, 0, 0, // version 84 30, 105, 20, 1, 114, 22, 0, 0, 0, /* version 84 */
3, 45, 22, 55, 47, 20, 0, 0, 0, 3, 45, 22, 55, 47, 20, 0, 0, 0,
2, 26, 26, 62, 33, 28, 0, 0, 0, 2, 26, 26, 62, 33, 28, 0, 0, 0,
79, 18, 28, 4, 33, 30, 0, 0, 0 79, 18, 28, 4, 33, 30, 0, 0, 0

View File

@ -46,9 +46,6 @@
*/ */
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "large.h" #include "large.h"
@ -286,11 +283,7 @@ INTERNAL void large_uint_array(const large_int *t, unsigned int *uint_array, con
/* As `large_uint_array()` above, except output to unsigned char array */ /* As `large_uint_array()` above, except output to unsigned char array */
INTERNAL void large_uchar_array(const large_int *t, unsigned char *uchar_array, const int size, int bits) { INTERNAL void large_uchar_array(const large_int *t, unsigned char *uchar_array, const int size, int bits) {
int i; int i;
#ifndef _MSC_VER unsigned int *uint_array = (unsigned int *) z_alloca(sizeof(unsigned int) * (size ? size : 1));
unsigned int uint_array[size ? size : 1]; /* Avoid run-time warning if size is 0 */
#else
unsigned int *uint_array = (unsigned int *) _alloca(sizeof(unsigned int) * (size ? size : 1));
#endif
large_uint_array(t, uint_array, size, bits); large_uint_array(t, uint_array, size, bits);

View File

@ -34,12 +34,6 @@
#ifndef Z_LARGE_H #ifndef Z_LARGE_H
#define Z_LARGE_H #define Z_LARGE_H
#ifndef _MSC_VER
#include <stdint.h>
#else
#include "ms_stdint.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -1,5 +1,5 @@
/* library.c - external functions of libzint /* library.c - external functions of libzint */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
@ -33,9 +33,6 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
#include "eci.h" #include "eci.h"
@ -44,7 +41,12 @@
/* It's assumed that int is at least 32 bits, the following will compile-time fail if not /* It's assumed that int is at least 32 bits, the following will compile-time fail if not
* https://stackoverflow.com/a/1980056 */ * https://stackoverflow.com/a/1980056 */
typedef int static_assert_int_at_least_32bits[CHAR_BIT != 8 || sizeof(int) < 4 ? -1 : 1]; typedef char static_assert_int_at_least_32bits[CHAR_BIT != 8 || sizeof(int) < 4 ? -1 : 1];
typedef char static_assert_uint16_is_16bits[sizeof(uint16_t) != 2 ? -1 : 1];
typedef char static_assert_int32_is_32bits[sizeof(int32_t) != 4 ? -1 : 1];
typedef char static_assert_uint32_is_32bits[sizeof(uint32_t) != 4 ? -1 : 1];
typedef char static_assert_uint64_at_least_64bits[sizeof(uint64_t) < 8 ? -1 : 1];
/* Create and initialize a symbol structure */ /* Create and initialize a symbol structure */
struct zint_symbol *ZBarcode_Create(void) { struct zint_symbol *ZBarcode_Create(void) {
@ -65,10 +67,10 @@ struct zint_symbol *ZBarcode_Create(void) {
strcpy(symbol->outfile, "out.png"); strcpy(symbol->outfile, "out.png");
#endif #endif
symbol->option_1 = -1; symbol->option_1 = -1;
symbol->show_hrt = 1; // Show human readable text symbol->show_hrt = 1; /* Show human readable text */
symbol->fontsize = 8; symbol->fontsize = 8;
symbol->input_mode = DATA_MODE; symbol->input_mode = DATA_MODE;
symbol->eci = 0; // Default 0 uses ECI 3 symbol->eci = 0; /* Default 0 uses ECI 3 */
symbol->dot_size = 4.0f / 5.0f; symbol->dot_size = 4.0f / 5.0f;
symbol->guard_descent = 5.0f; symbol->guard_descent = 5.0f;
symbol->warn_level = WARN_DEFAULT; symbol->warn_level = WARN_DEFAULT;
@ -107,7 +109,7 @@ void ZBarcode_Clear(struct zint_symbol *symbol) {
symbol->bitmap_height = 0; symbol->bitmap_height = 0;
symbol->bitmap_byte_length = 0; symbol->bitmap_byte_length = 0;
// If there is a rendered version, ensure its memory is released /* If there is a rendered version, ensure its memory is released */
vector_free(symbol); vector_free(symbol);
} }
@ -120,7 +122,7 @@ void ZBarcode_Delete(struct zint_symbol *symbol) {
if (symbol->alphamap != NULL) if (symbol->alphamap != NULL)
free(symbol->alphamap); free(symbol->alphamap);
// If there is a rendered version, ensure its memory is released /* If there is a rendered version, ensure its memory is released */
vector_free(symbol); vector_free(symbol);
free(symbol); free(symbol);
@ -400,9 +402,9 @@ static int gs1_compliant(const int symbology) {
case BARCODE_CODEONE: case BARCODE_CODEONE:
case BARCODE_ULTRA: case BARCODE_ULTRA:
case BARCODE_RMQR: case BARCODE_RMQR:
// TODO: case BARCODE_CODABLOCKF: /* TODO: case BARCODE_CODABLOCKF: */
// TODO: case BARCODE_HANXIN: /* TODO: case BARCODE_HANXIN: */
// TODO: case BARCODE_GRIDMATRIX: /* TODO: case BARCODE_GRIDMATRIX: */
return 1; return 1;
break; break;
} }
@ -573,23 +575,13 @@ static int extended_or_reduced_charset(struct zint_symbol *symbol, struct zint_s
static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) { static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], const int seg_count) {
int error_number = 0; int error_number = 0;
int i; int i;
struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count);
#ifndef _MSC_VER int *convertible = (int *) z_alloca(sizeof(int) * seg_count);
struct zint_seg local_segs[seg_count];
int convertible[seg_count];
#else
struct zint_seg *local_segs = (struct zint_seg *) _alloca(sizeof(struct zint_seg) * seg_count);
int *convertible = (int *) _alloca(sizeof(int) * seg_count);
#endif
if ((symbol->input_mode & 0x07) == UNICODE_MODE && is_eci_convertible_segs(segs, seg_count, convertible)) { if ((symbol->input_mode & 0x07) == UNICODE_MODE && is_eci_convertible_segs(segs, seg_count, convertible)) {
unsigned char *preprocessed; unsigned char *preprocessed;
const int eci_length_segs = get_eci_length_segs(segs, seg_count); const int eci_length_segs = get_eci_length_segs(segs, seg_count);
#ifndef _MSC_VER unsigned char *preprocessed_buf = (unsigned char *) z_alloca(eci_length_segs + seg_count);
unsigned char preprocessed_buf[eci_length_segs + seg_count];
#else
unsigned char *preprocessed_buf = (unsigned char *) _alloca(eci_length_segs + seg_count);
#endif
/* Prior check ensures ECI only set for those that support it */ /* Prior check ensures ECI only set for those that support it */
segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs) */ segs_cpy(symbol, segs, seg_count, local_segs); /* Shallow copy (needed to set default ECIs) */
@ -693,12 +685,7 @@ static int escape_char_process(struct zint_symbol *symbol, unsigned char *input_
int val; int val;
int i; int i;
unsigned long unicode; unsigned long unicode;
unsigned char *escaped_string = (unsigned char *) z_alloca(length + 1);
#ifndef _MSC_VER
unsigned char escaped_string[length + 1];
#else
unsigned char *escaped_string = (unsigned char *) _alloca(length + 1);
#endif
in_posn = 0; in_posn = 0;
out_posn = 0; out_posn = 0;
@ -847,13 +834,9 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
int have_zero_eci = 0; int have_zero_eci = 0;
int i; int i;
unsigned char *local_source; unsigned char *local_source;
#ifndef _MSC_VER
struct zint_seg local_segs[seg_count > 0 ? seg_count : 1];
#else
struct zint_seg *local_segs; struct zint_seg *local_segs;
unsigned char *local_sources; unsigned char *local_sources;
local_segs = (struct zint_seg *) _alloca(sizeof(struct zint_seg) * (seg_count > 0 ? seg_count : 1)); local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * (seg_count > 0 ? seg_count : 1));
#endif
if (!symbol) return ZINT_ERROR_INVALID_DATA; if (!symbol) return ZINT_ERROR_INVALID_DATA;
@ -1109,11 +1092,7 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
} }
} }
#ifndef _MSC_VER local_sources = (unsigned char *) z_alloca(total_len + seg_count);
unsigned char local_sources[total_len + seg_count];
#else
local_sources = (unsigned char *) _alloca(total_len + seg_count);
#endif
for (i = 0, local_source = local_sources; i < seg_count; i++) { for (i = 0, local_source = local_sources; i < seg_count; i++) {
local_segs[i].source = local_source; local_segs[i].source = local_source;
@ -1146,14 +1125,10 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
if (((symbol->input_mode & 0x07) == GS1_MODE) || (check_force_gs1(symbol->symbology))) { if (((symbol->input_mode & 0x07) == GS1_MODE) || (check_force_gs1(symbol->symbology))) {
if (gs1_compliant(symbol->symbology)) { if (gs1_compliant(symbol->symbology)) {
// Reduce input for composite and non-forced symbologies, others (EAN128 and RSS_EXP based) will /* Reduce input for composite and non-forced symbologies, others (EAN128 and RSS_EXP based) will
// handle it themselves handle it themselves */
if (is_composite(symbol->symbology) || !check_force_gs1(symbol->symbology)) { if (is_composite(symbol->symbology) || !check_force_gs1(symbol->symbology)) {
#ifndef _MSC_VER unsigned char *reduced = (unsigned char *) z_alloca(local_segs[0].length + 1);
unsigned char reduced[local_segs[0].length + 1];
#else
unsigned char *reduced = (unsigned char *) _alloca(local_segs[0].length + 1);
#endif
error_number = gs1_verify(symbol, local_segs[0].source, local_segs[0].length, reduced); error_number = gs1_verify(symbol, local_segs[0].source, local_segs[0].length, reduced);
if (error_number) { if (error_number) {
static const char in_2d_comp[] = " in 2D component"; static const char in_2d_comp[] = " in 2D component";
@ -1167,7 +1142,7 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
} }
warn_number = error_number; /* Override any previous warning (errtxt has been overwritten) */ warn_number = error_number; /* Override any previous warning (errtxt has been overwritten) */
} }
ustrcpy(local_segs[0].source, reduced); // Cannot contain NUL char ustrcpy(local_segs[0].source, reduced); /* Cannot contain NUL char */
local_segs[0].length = (int) ustrlen(reduced); local_segs[0].length = (int) ustrlen(reduced);
} }
} else { } else {
@ -1805,8 +1780,8 @@ unsigned int ZBarcode_Cap(int symbol_id, unsigned int cap_flag) {
switch (symbol_id) { switch (symbol_id) {
case BARCODE_QRCODE: case BARCODE_QRCODE:
case BARCODE_MICROQR: case BARCODE_MICROQR:
//case BARCODE_HIBC_QR: Note character set restricted to ASCII subset /* case BARCODE_HIBC_QR: Note character set restricted to ASCII subset */
//case BARCODE_UPNQR: Note does not use Kanji mode /* case BARCODE_UPNQR: Note does not use Kanji mode */
case BARCODE_RMQR: case BARCODE_RMQR:
case BARCODE_HANXIN: case BARCODE_HANXIN:
case BARCODE_GRIDMATRIX: case BARCODE_GRIDMATRIX:

View File

@ -41,16 +41,13 @@
*/ */
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "large.h" #include "large.h"
#include "reedsol.h" #include "reedsol.h"
#define RUBIDIUM_F (IS_NUM_F | IS_UPR_F | IS_SPC_F) /* RUBIDIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ " */ #define RUBIDIUM_F (IS_NUM_F | IS_UPR_F | IS_SPC_F) /* RUBIDIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ " */
// Allowed character values from Table 3 /* Allowed character values from Table 3 */
#define SET_F "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define SET_F "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define SET_L "ABDEFGHJLNPQRSTUWXYZ" #define SET_L "ABDEFGHJLNPQRSTUWXYZ"
#define SET_N "0123456789" #define SET_N "0123456789"
@ -62,7 +59,7 @@ static const char postcode_format[6][9] = {
{'F','N','N','L','L','N','L','S','S'}, {'F','N','N','N','L','L','N','L','S'} {'F','N','N','L','L','N','L','S','S'}, {'F','N','N','N','L','L','N','L','S'}
}; };
// Data/Check Symbols from Table 5 /* Data/Check Symbols from Table 5 */
static const unsigned char data_symbol_odd[32] = { static const unsigned char data_symbol_odd[32] = {
0x01, 0x02, 0x04, 0x07, 0x08, 0x0B, 0x0D, 0x0E, 0x10, 0x13, 0x15, 0x16, 0x01, 0x02, 0x04, 0x07, 0x08, 0x0B, 0x0D, 0x0E, 0x10, 0x13, 0x15, 0x16,
0x19, 0x1A, 0x1C, 0x1F, 0x20, 0x23, 0x25, 0x26, 0x29, 0x2A, 0x2C, 0x2F, 0x19, 0x1A, 0x1C, 0x1F, 0x20, 0x23, 0x25, 0x26, 0x29, 0x2A, 0x2C, 0x2F,
@ -181,28 +178,28 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
// Format is in the range 0-4 /* Format is in the range 0-4 */
format = ctoi(local_source[0]); format = ctoi(local_source[0]);
if ((format < 0) || (format > 4)) { if ((format < 0) || (format > 4)) {
strcpy(symbol->errtxt, "582: Format (1st character) out of range (0 to 4)"); strcpy(symbol->errtxt, "582: Format (1st character) out of range (0 to 4)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
// Version ID is in the range 1-4 /* Version ID is in the range 1-4 */
version_id = ctoi(local_source[1]) - 1; version_id = ctoi(local_source[1]) - 1;
if ((version_id < 0) || (version_id > 3)) { if ((version_id < 0) || (version_id > 3)) {
strcpy(symbol->errtxt, "583: Version ID (2nd character) out of range (1 to 4)"); strcpy(symbol->errtxt, "583: Version ID (2nd character) out of range (1 to 4)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
// Class is in the range 0-9,A-E /* Class is in the range 0-9,A-E */
mail_class = ctoi(local_source[2]); mail_class = ctoi(local_source[2]);
if ((mail_class < 0) || (mail_class > 14)) { if ((mail_class < 0) || (mail_class > 14)) {
strcpy(symbol->errtxt, "584: Class (3rd character) out of range (0 to 9 and A to E)"); strcpy(symbol->errtxt, "584: Class (3rd character) out of range (0 to 9 and A to E)");
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
// Supply Chain ID is 2 digits for barcode C and 6 digits for barcode L /* Supply Chain ID is 2 digits for barcode C and 6 digits for barcode L */
supply_chain_id = 0; supply_chain_id = 0;
for (i = 3; i < (length - 17); i++) { for (i = 3; i < (length - 17); i++) {
if (z_isdigit(local_source[i])) { if (z_isdigit(local_source[i])) {
@ -214,7 +211,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
} }
} }
// Item ID is 8 digits /* Item ID is 8 digits */
item_id = 0; item_id = 0;
for (i = length - 17; i < (length - 9); i++) { for (i = length - 17; i < (length - 9); i++) {
if (z_isdigit(local_source[i])) { if (z_isdigit(local_source[i])) {
@ -226,13 +223,13 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
} }
} }
// Separate Destination Post Code plus DPS field /* Separate Destination Post Code plus DPS field */
for (i = 0; i < 9; i++) { for (i = 0; i < 9; i++) {
postcode[i] = local_source[(length - 9) + i]; postcode[i] = local_source[(length - 9) + i];
} }
postcode[9] = '\0'; postcode[9] = '\0';
// Detect postcode type /* 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 * 1 = FNFNLLNLS
@ -251,7 +248,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
postcode_type = 5; postcode_type = 5;
} else { } else {
if (postcode[8] == ' ') { if (postcode[8] == ' ') {
// Types 1, 2 and 6 /* Types 1, 2 and 6 */
if (z_isdigit(postcode[1])) { if (z_isdigit(postcode[1])) {
if (z_isdigit(postcode[2])) { if (z_isdigit(postcode[2])) {
postcode_type = 6; postcode_type = 6;
@ -262,7 +259,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
postcode_type = 2; postcode_type = 2;
} }
} else { } else {
// Types 3 and 4 /* Types 3 and 4 */
if (z_isdigit(postcode[3])) { if (z_isdigit(postcode[3])) {
postcode_type = 3; postcode_type = 3;
} else { } else {
@ -272,7 +269,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
} }
} }
// Verify postcode type /* Verify postcode type */
if (postcode_type != 7) { if (postcode_type != 7) {
if (verify_postcode(postcode, postcode_type) != 0) { if (verify_postcode(postcode, postcode_type) != 0) {
sprintf(symbol->errtxt, "587: Invalid postcode \"%s\"", postcode); sprintf(symbol->errtxt, "587: Invalid postcode \"%s\"", postcode);
@ -280,7 +277,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
} }
} }
// Convert postcode to internal user field /* Convert postcode to internal user field */
large_load_u64(&destination_postcode, 0); large_load_u64(&destination_postcode, 0);
@ -303,13 +300,13 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
large_mul_u64(&b, 10); large_mul_u64(&b, 10);
large_add_u64(&b, posn(SET_N, postcode[i])); large_add_u64(&b, posn(SET_N, postcode[i]));
break; break;
// case 'S' ignored as value is 0 /* case 'S' ignored as value is 0 */
} }
} }
large_load(&destination_postcode, &b); large_load(&destination_postcode, &b);
// destination_postcode = a + b /* destination_postcode = a + b */
large_load_u64(&b, 1); large_load_u64(&b, 1);
if (postcode_type == 1) { if (postcode_type == 1) {
large_add(&destination_postcode, &b); large_add(&destination_postcode, &b);
@ -336,46 +333,46 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
} }
} }
// Conversion from Internal User Fields to Consolidated Data Value /* Conversion from Internal User Fields to Consolidated Data Value */
// Set CDV to 0 /* Set CDV to 0 */
large_load_u64(&cdv, 0); large_load_u64(&cdv, 0);
// Add Destination Post Code plus DPS /* Add Destination Post Code plus DPS */
large_add(&cdv, &destination_postcode); large_add(&cdv, &destination_postcode);
// Multiply by 100,000,000 /* Multiply by 100,000,000 */
large_mul_u64(&cdv, 100000000); large_mul_u64(&cdv, 100000000);
// Add Item ID /* Add Item ID */
large_add_u64(&cdv, item_id); large_add_u64(&cdv, item_id);
if (length == 22) { if (length == 22) {
// Barcode C - Multiply by 100 /* Barcode C - Multiply by 100 */
large_mul_u64(&cdv, 100); large_mul_u64(&cdv, 100);
} else { } else {
// Barcode L - Multiply by 1,000,000 /* Barcode L - Multiply by 1,000,000 */
large_mul_u64(&cdv, 1000000); large_mul_u64(&cdv, 1000000);
} }
// Add Supply Chain ID /* Add Supply Chain ID */
large_add_u64(&cdv, supply_chain_id); large_add_u64(&cdv, supply_chain_id);
// Multiply by 15 /* Multiply by 15 */
large_mul_u64(&cdv, 15); large_mul_u64(&cdv, 15);
// Add Class /* Add Class */
large_add_u64(&cdv, mail_class); large_add_u64(&cdv, mail_class);
// Multiply by 5 /* Multiply by 5 */
large_mul_u64(&cdv, 5); large_mul_u64(&cdv, 5);
// Add Format /* Add Format */
large_add_u64(&cdv, format); large_add_u64(&cdv, format);
// Multiply by 4 /* Multiply by 4 */
large_mul_u64(&cdv, 4); large_mul_u64(&cdv, 4);
// Add Version ID /* Add Version ID */
large_add_u64(&cdv, version_id); large_add_u64(&cdv, version_id);
if (symbol->debug & ZINT_DEBUG_PRINT) { if (symbol->debug & ZINT_DEBUG_PRINT) {
@ -394,7 +391,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
check_count = 7; check_count = 7;
} }
// Conversion from Consolidated Data Value to Data Numbers /* Conversion from Consolidated Data Value to Data Numbers */
for (j = data_top; j >= (data_step + 1); j--) { for (j = data_top; j >= (data_step + 1); j--) {
data[j] = (unsigned char) large_div_u64(&cdv, 32); data[j] = (unsigned char) large_div_u64(&cdv, 32);
@ -404,12 +401,12 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
data[j] = (unsigned char) large_div_u64(&cdv, 30); data[j] = (unsigned char) large_div_u64(&cdv, 30);
} }
// Generation of Reed-Solomon Check Numbers /* Generation of Reed-Solomon Check Numbers */
rs_init_gf(&rs, 0x25); rs_init_gf(&rs, 0x25);
rs_init_code(&rs, check_count, 1); rs_init_code(&rs, check_count, 1);
rs_encode(&rs, (data_top + 1), data, check); rs_encode(&rs, (data_top + 1), data, check);
// Append check digits to data /* Append check digits to data */
for (i = 1; i <= check_count; i++) { for (i = 1; i <= check_count; i++) {
data[data_top + i] = check[check_count - i]; data[data_top + i] = check[check_count - i];
} }
@ -422,7 +419,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
printf("\n"); printf("\n");
} }
// Conversion from Data Numbers and Check Numbers to Data Symbols and Check Symbols /* Conversion from Data Numbers and Check Numbers to Data Symbols and Check Symbols */
for (i = 0; i <= data_step; i++) { for (i = 0; i <= data_step; i++) {
data[i] = data_symbol_even[data[i]]; data[i] = data_symbol_even[data[i]];
} }
@ -430,7 +427,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
data[i] = data_symbol_odd[data[i]]; data[i] = data_symbol_odd[data[i]];
} }
// Conversion from Data Symbols and Check Symbols to Extender Groups /* Conversion from Data Symbols and Check Symbols to Extender Groups */
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (length == 22) { if (length == 22) {
extender[extender_group_c[i]] = data[i]; extender[extender_group_c[i]] = data[i];
@ -439,7 +436,7 @@ INTERNAL int mailmark(struct zint_symbol *symbol, unsigned char source[], int le
} }
} }
// Conversion from Extender Groups to Bar Identifiers /* Conversion from Extender Groups to Bar Identifiers */
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {

View File

@ -32,9 +32,6 @@
/* Includes corrections thanks to Monica Swanson @ Source Technologies */ /* Includes corrections thanks to Monica Swanson @ Source Technologies */
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "maxicode.h" #include "maxicode.h"
#include "reedsol.h" #include "reedsol.h"
@ -129,7 +126,7 @@ static int maxi_bestSurroundingSet(const int index, const int length, const unsi
int badValue = -1; int badValue = -1;
int option1 = maxi_value_in_array(set[sp + index - 1], setval, badValue, setLength); int option1 = maxi_value_in_array(set[sp + index - 1], setval, badValue, setLength);
if (index + 1 < length) { if (index + 1 < length) {
// we have two options to check (previous & next) /* we have two options to check (previous & next) */
int option2 = maxi_value_in_array(set[sp + index + 1], setval, badValue, setLength); int option2 = maxi_value_in_array(set[sp + index + 1], setval, badValue, setLength);
if (option2 != badValue && option1 > option2) { if (option2 != badValue && option1 > option2) {
return option2; return option2;
@ -155,11 +152,7 @@ static int maxi_text_process(unsigned char set[144], unsigned char character[144
static const unsigned char set12345[5] = { 1, 2, 3, 4, 5 }; static const unsigned char set12345[5] = { 1, 2, 3, 4, 5 };
const unsigned char *source = in_source; const unsigned char *source = in_source;
#ifndef _MSC_VER unsigned char *source_buf = (unsigned char *) z_alloca(length + 9); /* For prefixing 9-character SCM sequence */
unsigned char source_buf[length + 9]; /* For prefixing 9-character SCM sequence */
#else
unsigned char *source_buf = (unsigned char *) _alloca(length + 9);
#endif
if (sp + length > 144) { if (sp + length > 144) {
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
@ -169,7 +162,7 @@ static int maxi_text_process(unsigned char set[144], unsigned char character[144
/* Encode ECI assignment numbers according to table 3 */ /* Encode ECI assignment numbers according to table 3 */
if (eci != 0) { if (eci != 0) {
if (sp + 1 + length > 144) return ZINT_ERROR_TOO_LONG; if (sp + 1 + length > 144) return ZINT_ERROR_TOO_LONG;
character[sp++] = 27; // ECI character[sp++] = 27; /* ECI */
if (eci <= 31) { if (eci <= 31) {
if (sp + 1 + length > 144) return ZINT_ERROR_TOO_LONG; if (sp + 1 + length > 144) return ZINT_ERROR_TOO_LONG;
character[sp++] = eci; character[sp++] = eci;
@ -470,7 +463,7 @@ static int maxi_text_process_segs(unsigned char maxi_codeword[144], const int mo
/* Insert Structured Append at beginning if needed */ /* Insert Structured Append at beginning if needed */
if (structapp_cw) { if (structapp_cw) {
character[sp++] = 33; // PAD character[sp++] = 33; /* PAD */
character[sp++] = structapp_cw; character[sp++] = structapp_cw;
} }
@ -684,12 +677,12 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const
maxi_do_primary_check(maxi_codeword); /* always EEC */ maxi_do_primary_check(maxi_codeword); /* always EEC */
if (mode == 5) if (mode == 5)
eclen = 56; // 68 data codewords , 56 error corrections eclen = 56; /* 68 data codewords , 56 error corrections */
else else
eclen = 40; // 84 data codewords, 40 error corrections eclen = 40; /* 84 data codewords, 40 error corrections */
maxi_do_secondary_chk_even(maxi_codeword, eclen / 2); // do error correction of even maxi_do_secondary_chk_even(maxi_codeword, eclen / 2); /* do error correction of even */
maxi_do_secondary_chk_odd(maxi_codeword, eclen / 2); // do error correction of odd maxi_do_secondary_chk_odd(maxi_codeword, eclen / 2); /* do error correction of odd */
if (debug_print) { if (debug_print) {
printf("Codewords:"); printf("Codewords:");
@ -718,18 +711,18 @@ INTERNAL int maxicode(struct zint_symbol *symbol, struct zint_seg segs[], const
} }
/* Add orientation markings */ /* Add orientation markings */
set_module(symbol, 0, 28); // Top right filler set_module(symbol, 0, 28); /* Top right filler */
set_module(symbol, 0, 29); set_module(symbol, 0, 29);
set_module(symbol, 9, 10); // Top left marker set_module(symbol, 9, 10); /* Top left marker */
set_module(symbol, 9, 11); set_module(symbol, 9, 11);
set_module(symbol, 10, 11); set_module(symbol, 10, 11);
set_module(symbol, 15, 7); // Left hand marker set_module(symbol, 15, 7); /* Left hand marker */
set_module(symbol, 16, 8); set_module(symbol, 16, 8);
set_module(symbol, 16, 20); // Right hand marker set_module(symbol, 16, 20); /* Right hand marker */
set_module(symbol, 17, 20); set_module(symbol, 17, 20);
set_module(symbol, 22, 10); // Bottom left marker set_module(symbol, 22, 10); /* Bottom left marker */
set_module(symbol, 23, 10); set_module(symbol, 23, 10);
set_module(symbol, 22, 17); // Bottom right marker set_module(symbol, 22, 17); /* Bottom right marker */
set_module(symbol, 23, 17); set_module(symbol, 23, 17);
symbol->width = 30; symbol->width = 30;

View File

@ -1,235 +0,0 @@
// ISO C9x compliant stdint.h for Microsoft Visual Studio
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
//
// Copyright (c) 2006-2008 Alexander Chemeris
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. The name of the author may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
/* @(#) $Id: ms_stdint.h,v 1.1 2009/09/19 08:16:21 hooper114 Exp $ */
#ifndef _MSC_VER // [
#error "Use this header only with Microsoft Visual C++ compilers!"
#endif // _MSC_VER ]
#ifndef _MSC_STDINT_H_ // [
#define _MSC_STDINT_H_
#if _MSC_VER > 1000
#pragma once
#endif
#include <limits.h>
// For Visual Studio 6 in C++ mode wrap <wchar.h> include with 'extern "C++" {}'
// or compiler give many errors like this:
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
#if (_MSC_VER < 1300) && defined(__cplusplus)
extern "C++" {
#endif
# include <wchar.h>
#if (_MSC_VER < 1300) && defined(__cplusplus)
}
#endif
// Define _W64 macros to mark types changing their size, like intptr_t.
#ifndef _W64
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
# define _W64 __w64
# else
# define _W64
# endif
#endif
// 7.18.1 Integer types
// 7.18.1.1 Exact-width integer types
typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
// 7.18.1.2 Minimum-width integer types
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;
// 7.18.1.3 Fastest minimum-width integer types
typedef int8_t int_fast8_t;
typedef int16_t int_fast16_t;
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
typedef uint16_t uint_fast16_t;
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;
// 7.18.1.4 Integer types capable of holding object pointers
#ifdef _WIN64 // [
typedef __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else // _WIN64 ][
typedef _W64 int intptr_t;
typedef _W64 unsigned int uintptr_t;
#endif // _WIN64 ]
// 7.18.1.5 Greatest-width integer types
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
// 7.18.2 Limits of specified-width integer types
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
// 7.18.2.1 Limits of exact-width integer types
#define INT8_MIN ((int8_t)_I8_MIN)
#define INT8_MAX _I8_MAX
#define INT16_MIN ((int16_t)_I16_MIN)
#define INT16_MAX _I16_MAX
#define INT32_MIN ((int32_t)_I32_MIN)
#define INT32_MAX _I32_MAX
#define INT64_MIN ((int64_t)_I64_MIN)
#define INT64_MAX _I64_MAX
#define UINT8_MAX _UI8_MAX
#define UINT16_MAX _UI16_MAX
#define UINT32_MAX _UI32_MAX
#define UINT64_MAX _UI64_MAX
// 7.18.2.2 Limits of minimum-width integer types
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
// 7.18.2.3 Limits of fastest minimum-width integer types
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
// 7.18.2.4 Limits of integer types capable of holding object pointers
#ifdef _WIN64 // [
# define INTPTR_MIN INT64_MIN
# define INTPTR_MAX INT64_MAX
# define UINTPTR_MAX UINT64_MAX
#else // _WIN64 ][
# define INTPTR_MIN INT32_MIN
# define INTPTR_MAX INT32_MAX
# define UINTPTR_MAX UINT32_MAX
#endif // _WIN64 ]
// 7.18.2.5 Limits of greatest-width integer types
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
// 7.18.3 Limits of other integer types
#ifdef _WIN64 // [
# define PTRDIFF_MIN _I64_MIN
# define PTRDIFF_MAX _I64_MAX
#else // _WIN64 ][
# define PTRDIFF_MIN _I32_MIN
# define PTRDIFF_MAX _I32_MAX
#endif // _WIN64 ]
#define SIG_ATOMIC_MIN INT_MIN
#define SIG_ATOMIC_MAX INT_MAX
#ifndef SIZE_MAX // [
# ifdef _WIN64 // [
# define SIZE_MAX _UI64_MAX
# else // _WIN64 ][
# define SIZE_MAX _UI32_MAX
# endif // _WIN64 ]
#endif // SIZE_MAX ]
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
#ifndef WCHAR_MIN // [
# define WCHAR_MIN 0
#endif // WCHAR_MIN ]
#ifndef WCHAR_MAX // [
# define WCHAR_MAX _UI16_MAX
#endif // WCHAR_MAX ]
#define WINT_MIN 0
#define WINT_MAX _UI16_MAX
#endif // __STDC_LIMIT_MACROS ]
// 7.18.4 Limits of other integer types
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
// 7.18.4.1 Macros for minimum-width integer constants
#define INT8_C(val) val##i8
#define INT16_C(val) val##i16
#define INT32_C(val) val##i32
#define INT64_C(val) val##i64
#define UINT8_C(val) val##ui8
#define UINT16_C(val) val##ui16
#define UINT32_C(val) val##ui32
#define UINT64_C(val) val##ui64
// 7.18.4.2 Macros for greatest-width integer constants
#define INTMAX_C INT64_C
#define UINTMAX_C UINT64_C
#endif // __STDC_CONSTANT_MACROS ]
#endif // _MSC_STDINT_H_ ]

View File

@ -1,9 +1,7 @@
/* pcx.c - Handles output to ZSoft PCX file */ /* pcx.c - Handles output to ZSoft PCX file */
/* ZSoft PCX File Format Technical Reference Manual http://bespin.org/~qz/pc-gpe/pcx.txt */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -30,39 +28,30 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
#include "pcx.h" /* PCX header structure */ #include "pcx.h" /* PCX header structure */
#include <math.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#include <malloc.h>
#endif #endif
/* ZSoft PCX File Format Technical Reference Manual http://bespin.org/~qz/pc-gpe/pcx.txt */
INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) { INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) {
int fgred, fggrn, fgblu, bgred, bggrn, bgblu; int fgred, fggrn, fgblu, bgred, bggrn, bgblu;
int row, column, i, colour; int row, column, i, colour;
int run_count; int run_count;
FILE *pcx_file; FILE *pcx_file;
pcx_header_t header; pcx_header_t header;
int bytes_per_line = symbol->bitmap_width + (symbol->bitmap_width & 1); // Must be even int bytes_per_line = symbol->bitmap_width + (symbol->bitmap_width & 1); /* Must be even */
unsigned char previous; unsigned char previous;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; /* Suppress gcc -fanalyzer warning */ const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; /* Suppress gcc -fanalyzer warning */
#ifdef _MSC_VER unsigned char *rle_row = (unsigned char *) z_alloca(bytes_per_line);
unsigned char *rle_row;
#endif
#ifndef _MSC_VER rle_row[bytes_per_line - 1] = 0; /* Will remain zero if bitmap_width odd */
unsigned char rle_row[bytes_per_line];
#else
rle_row = (unsigned char *) _alloca(bytes_per_line);
#endif /* _MSC_VER */
rle_row[bytes_per_line - 1] = 0; // Will remain zero if bitmap_width odd
fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]);
fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]);
@ -71,9 +60,9 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]);
bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]);
header.manufacturer = 10; // ZSoft header.manufacturer = 10; /* ZSoft */
header.version = 5; // Version 3.0 header.version = 5; /* Version 3.0 */
header.encoding = 1; // Run length encoding header.encoding = 1; /* Run length encoding */
header.bits_per_pixel = 8; header.bits_per_pixel = 8;
header.window_xmin = 0; header.window_xmin = 0;
header.window_ymin = 0; header.window_ymin = 0;
@ -91,7 +80,7 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
header.bytes_per_line = bytes_per_line; header.bytes_per_line = bytes_per_line;
header.palette_info = 1; // Colour header.palette_info = 1; /* Colour */
header.horiz_screen_size = 0; header.horiz_screen_size = 0;
header.vert_screen_size = 0; header.vert_screen_size = 0;
@ -123,16 +112,16 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
switch (colour) { switch (colour) {
case 0: case 0:
switch (pixelbuf[(row * symbol->bitmap_width) + column]) { switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White case 'W': /* White */
case 'M': // Magenta case 'M': /* Magenta */
case 'R': // Red case 'R': /* Red */
case 'Y': // Yellow case 'Y': /* Yellow */
rle_row[column] = 255; rle_row[column] = 255;
break; break;
case 'C': // Cyan case 'C': /* Cyan */
case 'B': // Blue case 'B': /* Blue */
case 'G': // Green case 'G': /* Green */
case 'K': // Black case 'K': /* Black */
rle_row[column] = 0; rle_row[column] = 0;
break; break;
case '1': case '1':
@ -145,16 +134,16 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
break; break;
case 1: case 1:
switch (pixelbuf[(row * symbol->bitmap_width) + column]) { switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White case 'W': /* White */
case 'C': // Cyan case 'C': /* Cyan */
case 'Y': // Yellow case 'Y': /* Yellow */
case 'G': // Green case 'G': /* Green */
rle_row[column] = 255; rle_row[column] = 255;
break; break;
case 'B': // Blue case 'B': /* Blue */
case 'M': // Magenta case 'M': /* Magenta */
case 'R': // Red case 'R': /* Red */
case 'K': // Black case 'K': /* Black */
rle_row[column] = 0; rle_row[column] = 0;
break; break;
case '1': case '1':
@ -167,16 +156,16 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
break; break;
case 2: case 2:
switch (pixelbuf[(row * symbol->bitmap_width) + column]) { switch (pixelbuf[(row * symbol->bitmap_width) + column]) {
case 'W': // White case 'W': /* White */
case 'C': // Cyan case 'C': /* Cyan */
case 'B': // Blue case 'B': /* Blue */
case 'M': // Magenta case 'M': /* Magenta */
rle_row[column] = 255; rle_row[column] = 255;
break; break;
case 'R': // Red case 'R': /* Red */
case 'Y': // Yellow case 'Y': /* Yellow */
case 'G': // Green case 'G': /* Green */
case 'K': // Black case 'K': /* Black */
rle_row[column] = 0; rle_row[column] = 0;
break; break;
case '1': case '1':
@ -194,7 +183,7 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
* Copyright 1999-2020 ImageMagick Studio LLC */ * Copyright 1999-2020 ImageMagick Studio LLC */
previous = rle_row[0]; previous = rle_row[0];
run_count = 1; run_count = 1;
for (column = 1; column < bytes_per_line; column++) { // Note going up to bytes_per_line for (column = 1; column < bytes_per_line; column++) { /* Note going up to bytes_per_line */
if ((previous == rle_row[column]) && (run_count < 63)) { if ((previous == rle_row[column]) && (run_count < 63)) {
run_count++; run_count++;
} else { } else {
@ -224,3 +213,5 @@ INTERNAL int pcx_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,7 +1,7 @@
/* pcx.h - header structure for ZSoft PCX files /* pcx.h - header structure for ZSoft PCX files */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2016-2017 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2016-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,21 +28,15 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef PCX_H #ifndef Z_PCX_H
#define PCX_H #define Z_PCX_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef _MSC_VER
#include <windows.h>
#include "stdint_msvc.h"
#else
#include <stdint.h>
#endif
#pragma pack (1) #pragma pack (1)
typedef struct pcx_header { typedef struct pcx_header {
@ -72,6 +66,5 @@ extern "C" {
} }
#endif #endif
#endif /* PCX_H */ /* vim: set ts=4 sw=4 et : */
#endif /* Z_PCX_H */

View File

@ -44,14 +44,9 @@
symbol->option_3 is used to adjust the rows of the resulting symbol */ symbol->option_3 is used to adjust the rows of the resulting symbol */
#include <stdio.h>
#include <math.h>
#ifndef _MSC_VER
#include <stdint.h>
#else
#include "ms_stdint.h"
#endif
#include <assert.h> #include <assert.h>
#include <math.h>
#include <stdio.h>
#include "common.h" #include "common.h"
#include "pdf417.h" #include "pdf417.h"
#include "pdf417_tabs.h" #include "pdf417_tabs.h"

View File

@ -1,8 +1,7 @@
/* plessey.c - Handles Plessey and MSI Plessey */ /* plessey.c - Handles Plessey and MSI Plessey */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,7 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
@ -113,7 +112,7 @@ INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int len
expand(symbol, dest, d - dest); expand(symbol, dest, d - dest);
// TODO: Find documentation on BARCODE_PLESSEY dimensions/height /* TODO: Find documentation on BARCODE_PLESSEY dimensions/height */
symbol->text[0] = '\0'; symbol->text[0] = '\0';
ustrncat(symbol->text, source, length); ustrncat(symbol->text, source, length);
@ -358,7 +357,9 @@ INTERNAL int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int
expand(symbol, dest, d - dest); expand(symbol, dest, d - dest);
// TODO: Find documentation on BARCODE_MSI_PLESSEY dimensions/height /* TODO: Find documentation on BARCODE_MSI_PLESSEY dimensions/height */
return error_number; return error_number;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -37,7 +37,6 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#include <fcntl.h> #include <fcntl.h>
#include <io.h> #include <io.h>
#include <malloc.h>
#endif #endif
#include "common.h" #include "common.h"
@ -110,12 +109,7 @@ INTERNAL int png_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
int compression_strategy; int compression_strategy;
unsigned char *pb; unsigned char *pb;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
unsigned char *outdata = (unsigned char *) z_alloca(symbol->bitmap_width);
#ifndef _MSC_VER
unsigned char outdata[symbol->bitmap_width];
#else
unsigned char *outdata = (unsigned char *) _alloca(symbol->bitmap_width);
#endif
wpng_error.symbol = symbol; wpng_error.symbol = symbol;

View File

@ -32,9 +32,6 @@
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
static const char DAFTSET[] = "FADT"; static const char DAFTSET[] = "FADT";
@ -309,7 +306,7 @@ INTERNAL int koreapost(struct zint_symbol *symbol, unsigned char source[], int l
ustrcpy(symbol->text, localstr); ustrcpy(symbol->text, localstr);
// TODO: Find documentation on BARCODE_KOREAPOST dimensions/height /* TODO: Find documentation on BARCODE_KOREAPOST dimensions/height */
return error_number; return error_number;
} }
@ -614,7 +611,7 @@ INTERNAL int flat(struct zint_symbol *symbol, unsigned char source[], int length
expand(symbol, dest, d - dest); expand(symbol, dest, d - dest);
// TODO: Find documentation on BARCODE_FLAT dimensions/height /* TODO: Find documentation on BARCODE_FLAT dimensions/height */
return error_number; return error_number;
} }

View File

@ -32,69 +32,66 @@
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include <stdio.h>
#include <math.h> #include <math.h>
#ifdef _MSC_VER #include <stdio.h>
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
static void colour_to_pscolor(int option, int colour, char *output) { static void colour_to_pscolor(int option, int colour, char *output) {
*output = '\0'; *output = '\0';
if ((option & CMYK_COLOUR) == 0) { if ((option & CMYK_COLOUR) == 0) {
// Use RGB colour space /* Use RGB colour space */
switch (colour) { switch (colour) {
case 1: // Cyan case 1: /* Cyan */
strcat(output, "0.00 1.00 1.00"); strcat(output, "0.00 1.00 1.00");
break; break;
case 2: // Blue case 2: /* Blue */
strcat(output, "0.00 0.00 1.00"); strcat(output, "0.00 0.00 1.00");
break; break;
case 3: // Magenta case 3: /* Magenta */
strcat(output, "1.00 0.00 1.00"); strcat(output, "1.00 0.00 1.00");
break; break;
case 4: // Red case 4: /* Red */
strcat(output, "1.00 0.00 0.00"); strcat(output, "1.00 0.00 0.00");
break; break;
case 5: // Yellow case 5: /* Yellow */
strcat(output, "1.00 1.00 0.00"); strcat(output, "1.00 1.00 0.00");
break; break;
case 6: // Green case 6: /* Green */
strcat(output, "0.00 1.00 0.00"); strcat(output, "0.00 1.00 0.00");
break; break;
case 8: // White case 8: /* White */
strcat(output, "1.00 1.00 1.00"); strcat(output, "1.00 1.00 1.00");
break; break;
default: // Black default: /* Black */
strcat(output, "0.00 0.00 0.00"); strcat(output, "0.00 0.00 0.00");
break; break;
} }
strcat(output, " setrgbcolor"); strcat(output, " setrgbcolor");
} else { } else {
// Use CMYK colour space /* Use CMYK colour space */
switch (colour) { switch (colour) {
case 1: // Cyan case 1: /* Cyan */
strcat(output, "1.00 0.00 0.00 0.00"); strcat(output, "1.00 0.00 0.00 0.00");
break; break;
case 2: // Blue case 2: /* Blue */
strcat(output, "1.00 1.00 0.00 0.00"); strcat(output, "1.00 1.00 0.00 0.00");
break; break;
case 3: // Magenta case 3: /* Magenta */
strcat(output, "0.00 1.00 0.00 0.00"); strcat(output, "0.00 1.00 0.00 0.00");
break; break;
case 4: // Red case 4: /* Red */
strcat(output, "0.00 1.00 1.00 0.00"); strcat(output, "0.00 1.00 1.00 0.00");
break; break;
case 5: // Yellow case 5: /* Yellow */
strcat(output, "0.00 0.00 1.00 0.00"); strcat(output, "0.00 0.00 1.00 0.00");
break; break;
case 6: // Green case 6: /* Green */
strcat(output, "1.00 0.00 1.00 0.00"); strcat(output, "1.00 0.00 1.00 0.00");
break; break;
case 8: // White case 8: /* White */
strcat(output, "0.00 0.00 0.00 0.00"); strcat(output, "0.00 0.00 0.00 0.00");
break; break;
default: // Black default: /* Black */
strcat(output, "0.00 0.00 0.00 1.00"); strcat(output, "0.00 0.00 0.00 1.00");
break; break;
} }
@ -161,9 +158,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
int iso_latin1 = 0; int iso_latin1 = 0;
int have_circles_with_width = 0, have_circles_without_width = 0; int have_circles_with_width = 0, have_circles_without_width = 0;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
#ifdef _MSC_VER
unsigned char *ps_string; unsigned char *ps_string;
#endif
if (symbol->vector == NULL) { if (symbol->vector == NULL) {
strcpy(symbol->errtxt, "646: Vector header NULL"); strcpy(symbol->errtxt, "646: Vector header NULL");
@ -263,11 +258,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
} }
} }
#ifndef _MSC_VER ps_string = (unsigned char *) z_alloca(ps_len + 1);
unsigned char ps_string[ps_len + 1];
#else
ps_string = (unsigned char *) _alloca(ps_len + 1);
#endif
/* Check for circle widths */ /* Check for circle widths */
for (circle = symbol->vector->circles; circle; circle = circle->next) { for (circle = symbol->vector->circles; circle; circle = circle->next) {
@ -314,7 +305,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
/* Now the actual representation */ /* Now the actual representation */
// Background /* Background */
if (draw_background) { if (draw_background) {
if ((symbol->output_options & CMYK_COLOUR) == 0) { if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
@ -334,14 +325,14 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
} }
} }
// Rectangles /* Rectangles */
if (symbol->symbology == BARCODE_ULTRA) { if (symbol->symbology == BARCODE_ULTRA) {
colour_rect_flag = 0; colour_rect_flag = 0;
rect = symbol->vector->rectangles; rect = symbol->vector->rectangles;
while (rect) { while (rect) {
if (rect->colour == -1) { // Foreground if (rect->colour == -1) { /* Foreground */
if (colour_rect_flag == 0) { if (colour_rect_flag == 0) {
// Set foreground colour /* Set foreground colour */
if ((symbol->output_options & CMYK_COLOUR) == 0) { if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink);
} else { } else {
@ -362,7 +353,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
while (rect) { while (rect) {
if (rect->colour == colour_index) { if (rect->colour == colour_index) {
if (colour_rect_flag == 0) { if (colour_rect_flag == 0) {
// Set new colour /* Set new colour */
colour_to_pscolor(symbol->output_options, colour_index, ps_color); colour_to_pscolor(symbol->output_options, colour_index, ps_color);
fprintf(feps, "%s\n", ps_color); fprintf(feps, "%s\n", ps_color);
colour_rect_flag = 1; colour_rect_flag = 1;
@ -384,7 +375,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
} }
} }
// Hexagons /* Hexagons */
previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f; previous_diameter = radius = half_radius = half_sqrt3_radius = 0.0f;
hex = symbol->vector->hexagons; hex = symbol->vector->hexagons;
while (hex) { while (hex) {
@ -426,7 +417,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
hex = hex->next; hex = hex->next;
} }
// Circles /* Circles */
previous_diameter = radius = 0.0f; previous_diameter = radius = 0.0f;
circle = symbol->vector->circles; circle = symbol->vector->circles;
while (circle) { while (circle) {
@ -435,7 +426,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
radius = (float) (0.5 * previous_diameter); radius = (float) (0.5 * previous_diameter);
} }
if (circle->colour) { if (circle->colour) {
// A 'white' circle /* A 'white' circle */
if ((symbol->output_options & CMYK_COLOUR) == 0) { if ((symbol->output_options & CMYK_COLOUR) == 0) {
fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper); fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_paper, green_paper, blue_paper);
} else { } else {
@ -456,7 +447,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
} }
} }
} else { } else {
// A 'black' circle /* A 'black' circle */
if (circle->width) { if (circle->width) {
fprintf(feps, "%.2f %.2f %.3f %.3f TC\n", fprintf(feps, "%.2f %.2f %.3f %.3f TC\n",
circle->x, (symbol->vector->height - circle->y), radius, circle->width); circle->x, (symbol->vector->height - circle->y), radius, circle->width);
@ -467,7 +458,7 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
circle = circle->next; circle = circle->next;
} }
// Text /* Text */
string = symbol->vector->strings; string = symbol->vector->strings;

View File

@ -1,5 +1,5 @@
/* qr.c Handles QR Code, Micro QR Code, UPNQR and rMQR /* qr.c Handles QR Code, Micro QR Code, UPNQR and rMQR */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
@ -30,16 +30,13 @@
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <assert.h>
#include <math.h> #include <math.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h"
#include <stdio.h> #include <stdio.h>
#include "common.h"
#include "eci.h" #include "eci.h"
#include "qr.h" #include "qr.h"
#include "reedsol.h" #include "reedsol.h"
#include <assert.h>
#define QR_ALPHA (IS_NUM_F | IS_UPR_F | IS_SPC_F | IS_AST_F | IS_PLS_F | IS_MNS_F | IS_SIL_F | IS_CLI_F) #define QR_ALPHA (IS_NUM_F | IS_UPR_F | IS_SPC_F | IS_AST_F | IS_PLS_F | IS_MNS_F | IS_SIL_F | IS_CLI_F)
@ -211,7 +208,7 @@ static void qr_define_mode(char mode[], const unsigned int ddata[], const int le
*/ */
unsigned int state[10] = { unsigned int state[10] = {
0 /*N*/, 0 /*A*/, 0 /*B*/, 0 /*K*/, /* Head/switch costs */ 0 /*N*/, 0 /*A*/, 0 /*B*/, 0 /*K*/, /* Head/switch costs */
(unsigned int) version, 0 /*version*/,
0 /*numeric_end*/, 0 /*numeric_cost*/, 0 /*alpha_end*/, 0 /*alpha_cost*/, 0 /*alpha_pcent*/ 0 /*numeric_end*/, 0 /*numeric_cost*/, 0 /*alpha_end*/, 0 /*alpha_cost*/, 0 /*alpha_pcent*/
}; };
int m1, m2; int m1, m2;
@ -221,11 +218,9 @@ static void qr_define_mode(char mode[], const unsigned int ddata[], const int le
char cur_mode; char cur_mode;
unsigned int prev_costs[QR_NUM_MODES]; unsigned int prev_costs[QR_NUM_MODES];
unsigned int cur_costs[QR_NUM_MODES]; unsigned int cur_costs[QR_NUM_MODES];
#ifndef _MSC_VER char *char_modes = (char *) z_alloca(length * QR_NUM_MODES);
char char_modes[length * QR_NUM_MODES];
#else state[QR_VER] = (unsigned int) version;
char *char_modes = (char *) _alloca(length * QR_NUM_MODES);
#endif
/* char_modes[i * QR_NUM_MODES + j] represents the mode to encode the code point at index i such that the final /* char_modes[i * QR_NUM_MODES + j] represents the mode to encode the code point at index i such that the final
* segment ends in qr_mode_types[j] and the total number of bits is minimized over all possible choices */ * segment ends in qr_mode_types[j] and the total number of bits is minimized over all possible choices */
@ -646,11 +641,7 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i
int termbits, padbits; int termbits, padbits;
int current_bytes; int current_bytes;
int toggle; int toggle;
#ifndef _MSC_VER char *binary = (char *) z_alloca(est_binlen + 12);
char binary[est_binlen + 12];
#else
char *binary = (char *) _alloca(est_binlen + 12);
#endif
*binary = '\0'; *binary = '\0';
@ -751,12 +742,10 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
int ecc_block_length; int ecc_block_length;
int i, j, length_this_block, in_posn; int i, j, length_this_block, in_posn;
rs_t rs; rs_t rs;
#ifdef _MSC_VER
unsigned char *data_block; unsigned char *data_block;
unsigned char *ecc_block; unsigned char *ecc_block;
unsigned char *interleaved_data; unsigned char *interleaved_data;
unsigned char *interleaved_ecc; unsigned char *interleaved_ecc;
#endif
if (version < RMQR_VERSION) { if (version < RMQR_VERSION) {
ecc_cw = qr_total_codewords[version - 1] - data_cw; ecc_cw = qr_total_codewords[version - 1] - data_cw;
@ -775,17 +764,10 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
assert(short_data_block_length > 0); assert(short_data_block_length > 0);
assert(ecc_block_length * blocks == ecc_cw); assert(ecc_block_length * blocks == ecc_cw);
#ifndef _MSC_VER data_block = (unsigned char *) z_alloca(short_data_block_length + 1);
unsigned char data_block[short_data_block_length + 1]; ecc_block = (unsigned char *) z_alloca(ecc_block_length);
unsigned char ecc_block[ecc_block_length]; interleaved_data = (unsigned char *) z_alloca(data_cw);
unsigned char interleaved_data[data_cw]; interleaved_ecc = (unsigned char *) z_alloca(ecc_cw);
unsigned char interleaved_ecc[ecc_cw];
#else
data_block = (unsigned char *) _alloca(short_data_block_length + 1);
ecc_block = (unsigned char *) _alloca(ecc_block_length);
interleaved_data = (unsigned char *) _alloca(data_cw);
interleaved_ecc = (unsigned char *) _alloca(ecc_cw);
#endif
rs_init_gf(&rs, 0x11d); rs_init_gf(&rs, 0x11d);
rs_init_code(&rs, ecc_block_length, 0); rs_init_code(&rs, ecc_block_length, 0);
@ -804,7 +786,7 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
} }
for (j = 0; j < length_this_block; j++) { for (j = 0; j < length_this_block; j++) {
data_block[j] = datastream[in_posn + j]; // NOLINT false-positive popped up with clang-tidy 14.0.1 data_block[j] = datastream[in_posn + j]; /* NOLINT false-positive popped up with clang-tidy 14.0.1 */
} }
rs_encode(&rs, length_this_block, data_block, ecc_block); rs_encode(&rs, length_this_block, data_block, ecc_block);
@ -825,7 +807,7 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
} }
for (j = 0; j < short_data_block_length; j++) { for (j = 0; j < short_data_block_length; j++) {
interleaved_data[(j * blocks) + i] = data_block[j]; interleaved_data[(j * blocks) + i] = data_block[j]; /* NOLINT and another with clang-tidy 14.0.6 */
} }
if (i >= qty_short_blocks) { if (i >= qty_short_blocks) {
@ -844,7 +826,7 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
fullstream[j] = interleaved_data[j]; fullstream[j] = interleaved_data[j];
} }
for (j = 0; j < ecc_cw; j++) { for (j = 0; j < ecc_cw; j++) {
fullstream[j + data_cw] = interleaved_ecc[j]; fullstream[j + data_cw] = interleaved_ecc[j]; /* NOLINT ditto clang-tidy 14.0.6 */
} }
if (debug_print) { if (debug_print) {
@ -1064,7 +1046,7 @@ static int qr_evaluate(unsigned char *local, const int size) {
assert(size > 0); assert(size > 0);
#ifdef ZINTLOG #ifdef ZINTLOG
//bitmask output /* bitmask output */
for (y = 0; y < size; y++) { for (y = 0; y < size; y++) {
strcpy(str, ""); strcpy(str, "");
for (x = 0; x < size; x++) { for (x = 0; x < size; x++) {
@ -1306,14 +1288,8 @@ static int qr_apply_bitmask(unsigned char *grid, const int size, const int ecc_l
int pattern, penalty[8]; int pattern, penalty[8];
int best_pattern; int best_pattern;
int size_squared = size * size; int size_squared = size * size;
unsigned char *mask = (unsigned char *) z_alloca(size_squared);
#ifndef _MSC_VER unsigned char *local = (unsigned char *) z_alloca(size_squared);
unsigned char mask[size_squared];
unsigned char local[size_squared];
#else
unsigned char *mask = (unsigned char *) _alloca(size_squared);
unsigned char *local = (unsigned char *) _alloca(size_squared);
#endif
/* Perform data masking */ /* Perform data masking */
memset(mask, 0, size_squared); memset(mask, 0, size_squared);
@ -1321,8 +1297,8 @@ static int qr_apply_bitmask(unsigned char *grid, const int size, const int ecc_l
r = y * size; r = y * size;
for (x = 0; x < size; x++) { for (x = 0; x < size; x++) {
// all eight bitmask variants are encoded in the 8 bits of the bytes that make up the mask array. /* all eight bitmask variants are encoded in the 8 bits of the bytes that make up the mask array. */
if (!(grid[r + x] & 0xf0)) { // exclude areas not to be masked. if (!(grid[r + x] & 0xf0)) { /* exclude areas not to be masked. */
if (((y + x) & 1) == 0) { if (((y + x) & 1) == 0) {
mask[r + x] |= 0x01; mask[r + x] |= 0x01;
} }
@ -1451,7 +1427,7 @@ static int qr_calc_binlen(const int version, char mode[], const unsigned int dda
qr_define_mode(mode, ddata, length, gs1, version, debug_print); qr_define_mode(mode, ddata, length, gs1, version, debug_print);
} }
currentMode = ' '; // Null currentMode = ' '; /* Null */
if (eci != 0) { /* Not applicable to MICROQR */ if (eci != 0) { /* Not applicable to MICROQR */
count += 4; count += 4;
@ -1484,7 +1460,7 @@ static int qr_calc_binlen(const int version, char mode[], const unsigned int dda
case 'A': case 'A':
alphalength = blocklength; alphalength = blocklength;
if (gs1) { if (gs1) {
// In alphanumeric mode % becomes %% /* In alphanumeric mode % becomes %% */
for (j = i; j < (i + blocklength); j++) { for (j = i; j < (i + blocklength); j++) {
if (ddata[j] == '%') { if (ddata[j] == '%') {
alphalength++; alphalength++;
@ -1611,21 +1587,13 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in
const struct zint_structapp *p_structapp = NULL; const struct zint_structapp *p_structapp = NULL;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
const int eci_length_segs = get_eci_length_segs(segs, seg_count); const int eci_length_segs = get_eci_length_segs(segs, seg_count);
struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count);
#ifndef _MSC_VER unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * eci_length_segs);
struct zint_seg local_segs[seg_count]; char *mode = (char *) z_alloca(eci_length_segs);
unsigned int ddata[eci_length_segs]; char *prev_mode = (char *) z_alloca(eci_length_segs);
char mode[eci_length_segs];
char prev_mode[eci_length_segs];
#else
struct zint_seg *local_segs = (struct zint_seg *) _alloca(sizeof(struct zint_seg) * seg_count);
unsigned int *ddata = (unsigned int *) _alloca(sizeof(unsigned int) * eci_length_segs);
char *mode = (char *) _alloca(eci_length_segs);
char *prev_mode = (char *) _alloca(eci_length_segs);
unsigned char *datastream; unsigned char *datastream;
unsigned char *fullstream; unsigned char *fullstream;
unsigned char *grid; unsigned char *grid;
#endif
gs1 = ((symbol->input_mode & 0x07) == GS1_MODE); gs1 = ((symbol->input_mode & 0x07) == GS1_MODE);
@ -1732,7 +1700,7 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in
gs1, debug_print); gs1, debug_print);
} }
// Now see if the optimised binary will fit in a smaller symbol. /* Now see if the optimised binary will fit in a smaller symbol. */
canShrink = 1; canShrink = 1;
do { do {
@ -1768,10 +1736,10 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in
} }
if (canShrink == 1) { if (canShrink == 1) {
// Optimisation worked - data will fit in a smaller symbol /* Optimisation worked - data will fit in a smaller symbol */
autosize--; autosize--;
} else { } else {
// Data did not fit in the smaller symbol, revert to original size /* Data did not fit in the smaller symbol, revert to original size */
est_binlen = prev_est_binlen; est_binlen = prev_est_binlen;
memcpy(mode, prev_mode, eci_length_segs); memcpy(mode, prev_mode, eci_length_segs);
} }
@ -1832,13 +1800,8 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in
printf("Number of ECC blocks: %d\n", blocks); printf("Number of ECC blocks: %d\n", blocks);
} }
#ifndef _MSC_VER datastream = (unsigned char *) z_alloca(target_codewords + 1);
unsigned char datastream[target_codewords + 1]; fullstream = (unsigned char *) z_alloca(qr_total_codewords[version - 1] + 1);
unsigned char fullstream[qr_total_codewords[version - 1] + 1];
#else
datastream = (unsigned char *) _alloca(target_codewords + 1);
fullstream = (unsigned char *) _alloca(qr_total_codewords[version - 1] + 1);
#endif
(void) qr_binary_segs(datastream, version, target_codewords, mode, ddata, local_segs, seg_count, p_structapp, gs1, (void) qr_binary_segs(datastream, version, target_codewords, mode, ddata, local_segs, seg_count, p_structapp, gs1,
est_binlen, debug_print); est_binlen, debug_print);
@ -1849,12 +1812,8 @@ INTERNAL int qrcode(struct zint_symbol *symbol, struct zint_seg segs[], const in
size = qr_sizes[version - 1]; size = qr_sizes[version - 1];
size_squared = size * size; size_squared = size * size;
#ifndef _MSC_VER
unsigned char grid[size_squared];
#else
grid = (unsigned char *) _alloca(size_squared);
#endif
grid = (unsigned char *) z_alloca(size_squared);
memset(grid, 0, size_squared); memset(grid, 0, size_squared);
qr_setup_grid(grid, size, version); qr_setup_grid(grid, size, version);
@ -2392,14 +2351,8 @@ static int micro_apply_bitmask(unsigned char *grid, const int size, const int us
int pattern, value[4]; int pattern, value[4];
int best_pattern; int best_pattern;
int size_squared = size * size; int size_squared = size * size;
unsigned char *mask = (unsigned char *) z_alloca(size_squared);
#ifndef _MSC_VER unsigned char *eval = (unsigned char *) z_alloca(size_squared);
unsigned char mask[size_squared];
unsigned char eval[size_squared];
#else
unsigned char *mask = (unsigned char *) _alloca(size_squared);
unsigned char *eval = (unsigned char *) _alloca(size_squared);
#endif
/* Perform data masking */ /* Perform data masking */
memset(mask, 0, size_squared); memset(mask, 0, size_squared);
@ -2490,9 +2443,7 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len
struct zint_seg segs[1]; struct zint_seg segs[1];
const int seg_count = 1; const int seg_count = 1;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
#ifdef _MSC_VER
unsigned char *grid; unsigned char *grid;
#endif
if (length > 35) { if (length > 35) {
strcpy(symbol->errtxt, "562: Input data too long"); strcpy(symbol->errtxt, "562: Input data too long");
@ -2690,12 +2641,8 @@ INTERNAL int microqr(struct zint_symbol *symbol, unsigned char source[], int len
size = micro_qr_sizes[version]; size = micro_qr_sizes[version];
size_squared = size * size; size_squared = size * size;
#ifndef _MSC_VER
unsigned char grid[size_squared];
#else
grid = (unsigned char *) _alloca(size_squared);
#endif
grid = (unsigned char *) z_alloca(size_squared);
memset(grid, 0, size_squared); memset(grid, 0, size_squared);
micro_setup_grid(grid, size); micro_setup_grid(grid, size);
@ -2809,23 +2756,12 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt
struct zint_seg segs[1]; struct zint_seg segs[1];
const int seg_count = 1; const int seg_count = 1;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
#ifndef _MSC_VER
unsigned int ddata[length + 1];
char mode[length + 1];
#else
unsigned char *datastream; unsigned char *datastream;
unsigned char *fullstream; unsigned char *fullstream;
unsigned char *grid; unsigned char *grid;
unsigned int *ddata = (unsigned int *) _alloca(sizeof(unsigned int) * length); unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * length);
char *mode = (char *) _alloca(length + 1); char *mode = (char *) z_alloca(length + 1);
#endif unsigned char *preprocessed = (unsigned char *) z_alloca(length + 1);
#ifndef _MSC_VER
unsigned char preprocessed[length + 1];
#else
unsigned char *preprocessed = (unsigned char *) _alloca(length + 1);
#endif
symbol->eci = 4; /* Set before any processing */ symbol->eci = 4; /* Set before any processing */
@ -2873,17 +2809,13 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
version = 15; // 77 x 77 version = 15; /* 77 x 77 */
target_codewords = qr_data_codewords_M[version - 1]; target_codewords = qr_data_codewords_M[version - 1];
blocks = qr_blocks_M[version - 1]; blocks = qr_blocks_M[version - 1];
#ifndef _MSC_VER
unsigned char datastream[target_codewords + 1]; datastream = (unsigned char *) z_alloca(target_codewords + 1);
unsigned char fullstream[qr_total_codewords[version - 1] + 1]; fullstream = (unsigned char *) z_alloca(qr_total_codewords[version - 1] + 1);
#else
datastream = (unsigned char *) _alloca(target_codewords + 1);
fullstream = (unsigned char *) _alloca(qr_total_codewords[version - 1] + 1);
#endif
(void) qr_binary_segs(datastream, version, target_codewords, mode, ddata, segs, seg_count, NULL /*p_structapp*/, (void) qr_binary_segs(datastream, version, target_codewords, mode, ddata, segs, seg_count, NULL /*p_structapp*/,
0 /*gs1*/, est_binlen, debug_print); 0 /*gs1*/, est_binlen, debug_print);
@ -2894,12 +2826,8 @@ INTERNAL int upnqr(struct zint_symbol *symbol, unsigned char source[], int lengt
size = qr_sizes[version - 1]; size = qr_sizes[version - 1];
size_squared = size * size; size_squared = size * size;
#ifndef _MSC_VER
unsigned char grid[size_squared];
#else
grid = (unsigned char *) _alloca(size_squared);
#endif
grid = (unsigned char *) z_alloca(size_squared);
memset(grid, 0, size_squared); memset(grid, 0, size_squared);
qr_setup_grid(grid, size, version); qr_setup_grid(grid, size, version);
@ -2956,7 +2884,7 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s
} }
/* Add finder pattern */ /* Add finder pattern */
qr_place_finder(grid, h_size, 0, 0); // This works because finder is always top left qr_place_finder(grid, h_size, 0, 0); /* This works because finder is always top left */
/* Add finder sub-pattern to bottom right */ /* Add finder sub-pattern to bottom right */
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
@ -2984,7 +2912,7 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s
grid[(i * h_size) + 7] = 0x20; grid[(i * h_size) + 7] = 0x20;
} }
if (v_size > 7) { if (v_size > 7) {
// Note for v_size = 9 this overrides the bottom right corner finder pattern /* Note for v_size = 9 this overrides the bottom right corner finder pattern */
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
grid[(7 * h_size) + i] = 0x20; grid[(7 * h_size) + i] = 0x20;
} }
@ -2992,7 +2920,7 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s
/* Add alignment patterns */ /* Add alignment patterns */
if (h_size > 27) { if (h_size > 27) {
h_version = 0; // Suppress compiler warning [-Wmaybe-uninitialized] h_version = 0; /* Suppress compiler warning [-Wmaybe-uninitialized] */
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
if (h_size == rmqr_width[i]) { if (h_size == rmqr_width[i]) {
h_version = i; h_version = i;
@ -3012,13 +2940,13 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s
} }
} }
// Top square /* Top square */
grid[h_size + finder_position - 1] = 0x11; grid[h_size + finder_position - 1] = 0x11;
grid[(h_size * 2) + finder_position - 1] = 0x11; grid[(h_size * 2) + finder_position - 1] = 0x11;
grid[h_size + finder_position + 1] = 0x11; grid[h_size + finder_position + 1] = 0x11;
grid[(h_size * 2) + finder_position + 1] = 0x11; grid[(h_size * 2) + finder_position + 1] = 0x11;
// Bottom square /* Bottom square */
grid[(h_size * (v_size - 3)) + finder_position - 1] = 0x11; grid[(h_size * (v_size - 3)) + finder_position - 1] = 0x11;
grid[(h_size * (v_size - 2)) + finder_position - 1] = 0x11; grid[(h_size * (v_size - 2)) + finder_position - 1] = 0x11;
grid[(h_size * (v_size - 3)) + finder_position + 1] = 0x11; grid[(h_size * (v_size - 3)) + finder_position + 1] = 0x11;
@ -3052,19 +2980,12 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int
unsigned int left_format_info, right_format_info; unsigned int left_format_info, right_format_info;
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT; const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
const int eci_length_segs = get_eci_length_segs(segs, seg_count); const int eci_length_segs = get_eci_length_segs(segs, seg_count);
struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count);
#ifndef _MSC_VER unsigned int *ddata = (unsigned int *) z_alloca(sizeof(unsigned int) * eci_length_segs);
struct zint_seg local_segs[seg_count]; char *mode = (char *) z_alloca(eci_length_segs);
unsigned int ddata[eci_length_segs];
char mode[eci_length_segs];
#else
struct zint_seg *local_segs = (struct zint_seg *) _alloca(sizeof(struct zint_seg) * seg_count);
unsigned int *ddata = (unsigned int *) _alloca(sizeof(unsigned int) * eci_length_segs);
char *mode = (char *) _alloca(eci_length_segs);
unsigned char *datastream; unsigned char *datastream;
unsigned char *fullstream; unsigned char *fullstream;
unsigned char *grid; unsigned char *grid;
#endif
gs1 = ((symbol->input_mode & 0x07) == GS1_MODE); gs1 = ((symbol->input_mode & 0x07) == GS1_MODE);
@ -3105,10 +3026,10 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
} }
version = 31; // Set default to keep compiler happy version = 31; /* Set default to keep compiler happy */
if (symbol->option_2 == 0) { if (symbol->option_2 == 0) {
// Automatic symbol size /* Automatic symbol size */
autosize = 31; autosize = 31;
best_footprint = rmqr_height[31] * rmqr_width[31]; best_footprint = rmqr_height[31] * rmqr_width[31];
for (version = 30; version >= 0; version--) { for (version = 30; version >= 0; version--) {
@ -3137,14 +3058,14 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int
} }
if ((symbol->option_2 >= 1) && (symbol->option_2 <= 32)) { if ((symbol->option_2 >= 1) && (symbol->option_2 <= 32)) {
// User specified symbol size /* User specified symbol size */
version = symbol->option_2 - 1; version = symbol->option_2 - 1;
est_binlen = qr_calc_binlen_segs(RMQR_VERSION + version, mode, ddata, local_segs, seg_count, est_binlen = qr_calc_binlen_segs(RMQR_VERSION + version, mode, ddata, local_segs, seg_count,
NULL /*p_structapp*/, 0 /*mode_preset*/, gs1, debug_print); NULL /*p_structapp*/, 0 /*mode_preset*/, gs1, debug_print);
} }
if (symbol->option_2 >= 33) { if (symbol->option_2 >= 33) {
// User has specified symbol height only /* User has specified symbol height only */
version = rmqr_fixed_height_upper_bound[symbol->option_2 - 32]; version = rmqr_fixed_height_upper_bound[symbol->option_2 - 32];
for (i = version - 1; i > rmqr_fixed_height_upper_bound[symbol->option_2 - 33]; i--) { for (i = version - 1; i > rmqr_fixed_height_upper_bound[symbol->option_2 - 33]; i--) {
est_binlen = qr_calc_binlen_segs(RMQR_VERSION + i, mode, ddata, local_segs, seg_count, est_binlen = qr_calc_binlen_segs(RMQR_VERSION + i, mode, ddata, local_segs, seg_count,
@ -3164,7 +3085,7 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int
} }
if (symbol->option_1 == -1) { if (symbol->option_1 == -1) {
// Detect if there is enough free space to increase ECC level /* Detect if there is enough free space to increase ECC level */
if (est_binlen < (rmqr_data_codewords_H[version] * 8)) { if (est_binlen < (rmqr_data_codewords_H[version] * 8)) {
ecc_level = QR_LEVEL_H; ecc_level = QR_LEVEL_H;
} }
@ -3179,7 +3100,7 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int
} }
if (est_binlen > (target_codewords * 8)) { if (est_binlen > (target_codewords * 8)) {
// User has selected a symbol too small for the data /* User has selected a symbol too small for the data */
strcpy(symbol->errtxt, "560: Input too long for selected symbol size"); strcpy(symbol->errtxt, "560: Input too long for selected symbol size");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
@ -3192,13 +3113,8 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int
printf("Number of ECC blocks: %d\n", blocks); printf("Number of ECC blocks: %d\n", blocks);
} }
#ifndef _MSC_VER datastream = (unsigned char *) z_alloca(target_codewords + 1);
unsigned char datastream[target_codewords + 1]; fullstream = (unsigned char *) z_alloca(rmqr_total_codewords[version] + 1);
unsigned char fullstream[rmqr_total_codewords[version] + 1];
#else
datastream = (unsigned char *) _alloca(target_codewords + 1);
fullstream = (unsigned char *) _alloca(rmqr_total_codewords[version] + 1);
#endif
(void) qr_binary_segs(datastream, RMQR_VERSION + version, target_codewords, mode, ddata, local_segs, seg_count, (void) qr_binary_segs(datastream, RMQR_VERSION + version, target_codewords, mode, ddata, local_segs, seg_count,
NULL /*p_structapp*/, gs1, est_binlen, debug_print); NULL /*p_structapp*/, gs1, est_binlen, debug_print);
@ -3210,12 +3126,7 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int
h_size = rmqr_width[version]; h_size = rmqr_width[version];
v_size = rmqr_height[version]; v_size = rmqr_height[version];
#ifndef _MSC_VER grid = (unsigned char *) z_alloca(h_size * v_size);
unsigned char grid[h_size * v_size];
#else
grid = (unsigned char *) _alloca(h_size * v_size);
#endif
memset(grid, 0, h_size * v_size); memset(grid, 0, h_size * v_size);
rmqr_setup_grid(grid, h_size, v_size); rmqr_setup_grid(grid, h_size, v_size);
@ -3226,9 +3137,9 @@ INTERNAL int rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const int
int r = i * h_size; int r = i * h_size;
for (j = 0; j < h_size; j++) { for (j = 0; j < h_size; j++) {
if ((grid[r + j] & 0xf0) == 0) { if ((grid[r + j] & 0xf0) == 0) {
// This is a data module /* This is a data module */
if (((i / 2) + (j / 3)) % 2 == 0) { // < This is the data mask from section 7.8.2 if (((i / 2) + (j / 3)) % 2 == 0) { /* < This is the data mask from section 7.8.2 */
// This module needs to be changed /* This module needs to be changed */
if (grid[r + j] == 0x01) { if (grid[r + j] == 0x01) {
grid[r + j] = 0x00; grid[r + j] = 0x00;
} else { } else {

View File

@ -1,5 +1,5 @@
/* qr.h Data for QR Code, Micro QR Code and rMQR /* qr.h Data for QR Code, Micro QR Code and rMQR */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2006 Kentaro Fukuchi <fukuchi@megaui.net> Copyright (C) 2006 Kentaro Fukuchi <fukuchi@megaui.net>
@ -92,21 +92,21 @@ static const unsigned short rmqr_width[] = {
}; };
static const unsigned short rmqr_data_codewords_M[] = { static const unsigned short rmqr_data_codewords_M[] = {
6, 12, 20, 28, 44, // R7x 6, 12, 20, 28, 44, /* R7x */
12, 21, 31, 42, 63, // R9x 12, 21, 31, 42, 63, /* R9x */
7, 19, 31, 43, 57, 84, // R11x 7, 19, 31, 43, 57, 84, /* R11x */
12, 27, 38, 53, 73, 106, // R13x 12, 27, 38, 53, 73, 106, /* R13x */
33, 48, 67, 88, 127, // R15x 33, 48, 67, 88, 127, /* R15x */
39, 56, 78, 100, 152 // R17x 39, 56, 78, 100, 152 /* R17x */
}; };
static const unsigned short rmqr_data_codewords_H[] = { static const unsigned short rmqr_data_codewords_H[] = {
3, 7, 10, 14, 24, // R7x 3, 7, 10, 14, 24, /* R7x */
7, 11, 17, 22, 33, // R9x 7, 11, 17, 22, 33, /* R9x */
5, 11, 15, 23, 29, 42, // R11x 5, 11, 15, 23, 29, 42, /* R11x */
7, 13, 20, 29, 35, 54, // R13x 7, 13, 20, 29, 35, 54, /* R13x */
15, 26, 31, 48, 69, // R15x 15, 26, 31, 48, 69, /* R15x */
21, 28, 38, 56, 76 // R17x 21, 28, 38, 56, 76 /* R17x */
}; };
static const short rmqr_fixed_height_upper_bound[] = { static const short rmqr_fixed_height_upper_bound[] = {
@ -114,12 +114,12 @@ static const short rmqr_fixed_height_upper_bound[] = {
}; };
static const unsigned short rmqr_total_codewords[] = { static const unsigned short rmqr_total_codewords[] = {
13, 21, 32, 44, 68, // R7x 13, 21, 32, 44, 68, /* R7x */
21, 33, 49, 66, 99, // R9x 21, 33, 49, 66, 99, /* R9x */
15, 31, 47, 67, 89, 132, // R11x 15, 31, 47, 67, 89, 132, /* R11x */
21, 41, 60, 85, 113, 166, // R13x 21, 41, 60, 85, 113, 166, /* R13x */
51, 74, 103, 136, 199, // R15x 51, 74, 103, 136, 199, /* R15x */
61, 88, 122, 160, 232 // R17x 61, 88, 122, 160, 232 /* R17x */
}; };
@ -180,21 +180,21 @@ static const char qr_blocks_H[] = {
}; };
static const char rmqr_blocks_M[] = { static const char rmqr_blocks_M[] = {
1, 1, 1, 1, 1, // R7x 1, 1, 1, 1, 1, /* R7x */
1, 1, 1, 1, 2, // R9x 1, 1, 1, 1, 2, /* R9x */
1, 1, 1, 1, 2, 2, // R11x 1, 1, 1, 1, 2, 2, /* R11x */
1, 1, 1, 2, 2, 3, // R13x 1, 1, 1, 2, 2, 3, /* R13x */
1, 1, 2, 2, 3, // R15x 1, 1, 2, 2, 3, /* R15x */
1, 2, 2, 3, 4 // R17x 1, 2, 2, 3, 4 /* R17x */
}; };
static const char rmqr_blocks_H[] = { static const char rmqr_blocks_H[] = {
1, 1, 1, 1, 2, // R7x 1, 1, 1, 1, 2, /* R7x */
1, 1, 2, 2, 3, // R9x 1, 1, 2, 2, 3, /* R9x */
1, 1, 2, 2, 2, 3, // R11x 1, 1, 2, 2, 2, 3, /* R11x */
1, 1, 2, 2, 3, 4, // R13x 1, 1, 2, 2, 3, 4, /* R13x */
2, 2, 3, 4, 5, // R15x 2, 2, 3, 4, 5, /* R15x */
2, 2, 3, 4, 6 // R17x 2, 2, 3, 4, 6 /* R17x */
}; };
static const unsigned short qr_sizes[] = { static const unsigned short qr_sizes[] = {
@ -210,7 +210,7 @@ static const char qr_align_loopsize[] = {
0, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7 0, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7
}; };
// Table E1 - Row/column coordinates of center module of alignment patterns /* Table E1 - Row/column coordinates of center module of alignment patterns */
static const unsigned short qr_table_e1[] = { static const unsigned short qr_table_e1[] = {
6, 18, 0, 0, 0, 0, 0, 6, 18, 0, 0, 0, 0, 0,
6, 22, 0, 0, 0, 0, 0, 6, 22, 0, 0, 0, 0, 0,
@ -253,7 +253,7 @@ static const unsigned short qr_table_e1[] = {
6, 30, 58, 86, 114, 142, 170 6, 30, 58, 86, 114, 142, 170
}; };
// Table D1 - Column coordinates of centre module of alignment patterns /* Table D1 - Column coordinates of centre module of alignment patterns */
static const unsigned short rmqr_table_d1[] = { static const unsigned short rmqr_table_d1[] = {
21, 0, 0, 0, 21, 0, 0, 0,
19, 39, 0, 0, 19, 39, 0, 0,

View File

@ -1,8 +1,7 @@
/* raster.c - Handles output to raster files */ /* raster.c - Handles output to raster files */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,13 +28,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h>
#include <fcntl.h> #include <fcntl.h>
#include <io.h> #include <io.h>
#endif /* _MSC_VER */ #endif /* _MSC_VER */
@ -287,7 +285,7 @@ static void copy_bar_line(unsigned char *pixelbuf, const int xpos, const int xle
const int ye = ypos + ylen > image_height ? image_height : ypos + ylen; /* Defensive, should never happen */ const int ye = ypos + ylen > image_height ? image_height : ypos + ylen; /* Defensive, should never happen */
unsigned char *pb = pixelbuf + ((size_t) image_width * ypos) + xpos; unsigned char *pb = pixelbuf + ((size_t) image_width * ypos) + xpos;
assert(ypos + ylen <= image_height); // Trigger assert if "should never happen" happens assert(ypos + ylen <= image_height); /* Trigger assert if "should never happen" happens */
for (y = ypos + 1; y < ye; y++) { for (y = ypos + 1; y < ye; y++) {
memcpy(pixelbuf + ((size_t) image_width * y) + xpos, pb, xlen); memcpy(pixelbuf + ((size_t) image_width * y) + xpos, pb, xlen);
@ -301,7 +299,7 @@ static void draw_bar(unsigned char *pixelbuf, const int xpos, const int xlen, co
const int ye = ypos + ylen > image_height ? image_height : ypos + ylen; /* Defensive, should never happen */ const int ye = ypos + ylen > image_height ? image_height : ypos + ylen; /* Defensive, should never happen */
unsigned char *pb = pixelbuf + ((size_t) image_width * ypos) + xpos; unsigned char *pb = pixelbuf + ((size_t) image_width * ypos) + xpos;
assert(ypos + ylen <= image_height); // Trigger assert if "should never happen" happens assert(ypos + ylen <= image_height); /* Trigger assert if "should never happen" happens */
for (y = ypos; y < ye; y++, pb += image_width) { for (y = ypos; y < ye; y++, pb += image_width) {
memset(pb, fill, xlen); memset(pb, fill, xlen);
@ -361,17 +359,17 @@ static void draw_letter(unsigned char *pixelbuf, const unsigned char letter, int
max_y = UPCEAN_FONT_HEIGHT; max_y = UPCEAN_FONT_HEIGHT;
} }
glyph_no = letter - '0'; glyph_no = letter - '0';
} else if (textflags & SMALL_TEXT) { // small font 5x9 } else if (textflags & SMALL_TEXT) { /* small font 5x9 */
/* No bold for small */ /* No bold for small */
max_x = SMALL_FONT_WIDTH; max_x = SMALL_FONT_WIDTH;
max_y = SMALL_FONT_HEIGHT; max_y = SMALL_FONT_HEIGHT;
font_table = small_font; font_table = small_font;
} else if (textflags & BOLD_TEXT) { // bold font -> regular font + 1 } else if (textflags & BOLD_TEXT) { /* bold font -> regular font + 1 */
max_x = NORMAL_FONT_WIDTH + 1; max_x = NORMAL_FONT_WIDTH + 1;
max_y = NORMAL_FONT_HEIGHT; max_y = NORMAL_FONT_HEIGHT;
font_table = ascii_font; font_table = ascii_font;
bold = 1; bold = 1;
} else { // regular font 7x14 } else { /* regular font 7x14 */
max_x = NORMAL_FONT_WIDTH; max_x = NORMAL_FONT_WIDTH;
max_y = NORMAL_FONT_HEIGHT; max_y = NORMAL_FONT_HEIGHT;
font_table = ascii_font; font_table = ascii_font;
@ -437,14 +435,14 @@ static void draw_string(unsigned char *pixbuf, const unsigned char input_string[
/* No bold for UPCEAN */ /* No bold for UPCEAN */
letter_width = textflags & SMALL_TEXT ? UPCEAN_SMALL_FONT_WIDTH : UPCEAN_FONT_WIDTH; letter_width = textflags & SMALL_TEXT ? UPCEAN_SMALL_FONT_WIDTH : UPCEAN_FONT_WIDTH;
letter_gap = 4; letter_gap = 4;
} else if (textflags & SMALL_TEXT) { // small font 5x9 } else if (textflags & SMALL_TEXT) { /* small font 5x9 */
/* No bold for small */ /* No bold for small */
letter_width = SMALL_FONT_WIDTH; letter_width = SMALL_FONT_WIDTH;
letter_gap = 0; letter_gap = 0;
} else if (textflags & BOLD_TEXT) { // bold font -> width of the regular font + 1 extra dot + 1 extra space } else if (textflags & BOLD_TEXT) { /* bold font -> width of the regular font + 1 extra dot + 1 extra space */
letter_width = NORMAL_FONT_WIDTH + 1; letter_width = NORMAL_FONT_WIDTH + 1;
letter_gap = 1; letter_gap = 1;
} else { // regular font 7x15 } else { /* regular font 7x15 */
letter_width = NORMAL_FONT_WIDTH; letter_width = NORMAL_FONT_WIDTH;
letter_gap = 0; letter_gap = 0;
} }
@ -1257,7 +1255,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
} }
} }
// Separator binding for stacked barcodes /* Separator binding for stacked barcodes */
if ((symbol->output_options & BARCODE_BIND) && (symbol->rows > 1) && is_stackable(symbol->symbology)) { if ((symbol->output_options & BARCODE_BIND) && (symbol->rows > 1) && is_stackable(symbol->symbology)) {
int sep_xoffset_si = xoffset_si; int sep_xoffset_si = xoffset_si;
int sep_width_si = symbol->width * si; int sep_width_si = symbol->width * si;
@ -1353,3 +1351,5 @@ INTERNAL int plot_raster(struct zint_symbol *symbol, int rotate_angle, int file_
return error; return error;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,6 +1,5 @@
/** /* This is a simple Reed-Solomon encoder */
/*
This is a simple Reed-Solomon encoder
(C) Cliff Hones 2004 (C) Cliff Hones 2004
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -28,9 +27,9 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
// It is not written with high efficiency in mind, so is probably /* It is not written with high efficiency in mind, so is probably
// not suitable for real-time encoding. The aim was to keep it // not suitable for real-time encoding. The aim was to keep it
// simple, general and clear. // simple, general and clear.
// //
@ -49,15 +48,13 @@
// malloc/free can be avoided by using static arrays of a suitable // malloc/free can be avoided by using static arrays of a suitable
// size. // size.
// Note: use of statics has been done for (up to) 8-bit tables. // Note: use of statics has been done for (up to) 8-bit tables.
*/
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "reedsol.h" #include "reedsol.h"
#include "reedsol_logs.h" #include "reedsol_logs.h"
// rs_init_gf(&rs, prime_poly) initialises the parameters for the Galois Field. /* rs_init_gf(&rs, prime_poly) initialises the parameters for the Galois Field.
// The symbol size is determined from the highest bit set in poly // The symbol size is determined from the highest bit set in poly
// This implementation will support sizes up to 8 bits (see rs_uint_init_gf() // This implementation will support sizes up to 8 bits (see rs_uint_init_gf()
// for sizes > 8 bits and <= 30 bits) - bit sizes of 8 or 4 are typical // for sizes > 8 bits and <= 30 bits) - bit sizes of 8 or 4 are typical
@ -65,6 +62,7 @@
// The poly is the bit pattern representing the GF characteristic // The poly is the bit pattern representing the GF characteristic
// polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is // polynomial. e.g. for ECC200 (8-bit symbols) the polynomial is
// a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d. // a**8 + a**5 + a**3 + a**2 + 1, which translates to 0x12d.
*/
INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly) { INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly) {
struct item { struct item {
@ -97,12 +95,13 @@ INTERNAL void rs_init_gf(rs_t *rs, const unsigned int prime_poly) {
rs->alog = data[hash].alog; rs->alog = data[hash].alog;
} }
// rs_init_code(&rs, nsym, index) initialises the Reed-Solomon encoder /* rs_init_code(&rs, nsym, index) initialises the Reed-Solomon encoder
// nsym is the number of symbols to be generated (to be appended // nsym is the number of symbols to be generated (to be appended
// to the input data). index is usually 1 - it is the index of // to the input data). index is usually 1 - it is the index of
// the constant in the first term (i) of the RS generator polynomial: // the constant in the first term (i) of the RS generator polynomial:
// (x + 2**i)*(x + 2**(i+1))*... [nsym terms] // (x + 2**i)*(x + 2**(i+1))*... [nsym terms]
// For ECC200, index is 1. // For ECC200, index is 1.
*/
INTERNAL void rs_init_code(rs_t *rs, const int nsym, int index) { INTERNAL void rs_init_code(rs_t *rs, const int nsym, int index) {
int i, k; int i, k;
@ -225,11 +224,12 @@ INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned i
/* Versions of the above for bitlengths > 8 and <= 30 and unsigned int data and results - Aztec code compatible */ /* Versions of the above for bitlengths > 8 and <= 30 and unsigned int data and results - Aztec code compatible */
// Usage: /* Usage:
// First call rs_uint_init_gf(&rs_uint, prime_poly, logmod) to set up the Galois Field parameters. // First call rs_uint_init_gf(&rs_uint, prime_poly, logmod) to set up the Galois Field parameters.
// Then call rs_uint_init_code(&rs_uint, nsym, index) to set the encoding size // Then call rs_uint_init_code(&rs_uint, nsym, index) to set the encoding size
// Then call rs_uint_encode(&rs_uint, datalen, data, out) to encode the data. // Then call rs_uint_encode(&rs_uint, datalen, data, out) to encode the data.
// Then call rs_uint_free(&rs_uint) to free the log tables. // Then call rs_uint_free(&rs_uint) to free the log tables.
*/
/* `logmod` (field characteristic) will be 2**bitlength - 1, eg 1023 for bitlength 10, 4095 for bitlength 12 */ /* `logmod` (field characteristic) will be 2**bitlength - 1, eg 1023 for bitlength 10, 4095 for bitlength 12 */
INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod) { INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod) {
@ -249,7 +249,7 @@ INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly,
return 0; return 0;
} }
// Calculate the log/alog tables /* Calculate the log/alog tables */
for (p = 1, v = 0; v < logmod; v++) { for (p = 1, v = 0; v < logmod; v++) {
alog[v] = p; alog[v] = p;
alog[logmod + v] = p; /* Double up, avoids mod */ alog[logmod + v] = p; /* Double up, avoids mod */
@ -352,3 +352,5 @@ INTERNAL void rs_uint_free(rs_uint_t *rs_uint) {
rs_uint->alog = NULL; rs_uint->alog = NULL;
} }
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -63,9 +63,6 @@
*/ */
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "large.h" #include "large.h"
#include "rss.h" #include "rss.h"
@ -835,11 +832,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
int min_cols_per_row = 0; int min_cols_per_row = 0;
int length = (int) ustrlen(source); int length = (int) ustrlen(source);
const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT); const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT);
#ifndef _MSC_VER char *general_field = (char *) z_alloca(length + 1);
char general_field[length + 1];
#else
char *general_field = (char *) _alloca(length + 1);
#endif
int bp = *p_bp; int bp = *p_bp;
int remainder, d1, d2; int remainder, d1, d2;
int cdf_bp_start; /* Compressed data field start - debug only */ int cdf_bp_start; /* Compressed data field start - debug only */
@ -944,8 +937,8 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
case 2: bp = bin_append_posn(0, 4, binary_string, bp); /* "00XX" */ case 2: bp = bin_append_posn(0, 4, binary_string, bp); /* "00XX" */
read_posn = 0; read_posn = 0;
break; break;
case 3: // 0100 case 3: /* 0100 */
case 4: // 0101 case 4: /* 0101 */
bp = bin_append_posn(4 + (encoding_method - 3), 4, binary_string, bp); bp = bin_append_posn(4 + (encoding_method - 3), 4, binary_string, bp);
read_posn = 26; read_posn = 26;
break; break;
@ -1091,7 +1084,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
} }
} }
if (characters_per_row && (symbol_characters % characters_per_row) == 1) { // DBAR_EXPSTK if (characters_per_row && (symbol_characters % characters_per_row) == 1) { /* DBAR_EXPSTK */
symbol_characters++; symbol_characters++;
} }
@ -1127,7 +1120,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
} }
} }
if (characters_per_row && (symbol_characters % characters_per_row) == 1) { // DBAR_EXPSTK if (characters_per_row && (symbol_characters % characters_per_row) == 1) { /* DBAR_EXPSTK */
symbol_characters++; symbol_characters++;
} }
@ -1141,7 +1134,7 @@ static int dbar_exp_binary_string(struct zint_symbol *symbol, const unsigned cha
} }
if (bp > 252) { /* 252 = (21 * 12) */ if (bp > 252) { /* 252 = (21 * 12) */
strcpy(symbol->errtxt, "387: Input too long"); // TODO: Better error message strcpy(symbol->errtxt, "387: Input too long"); /* TODO: Better error message */
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
} }
@ -1286,13 +1279,8 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
int max_rows = 0; int max_rows = 0;
int stack_rows = 1; int stack_rows = 1;
const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT); const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT);
#ifndef _MSC_VER unsigned char *reduced = (unsigned char *) z_alloca(length + 1);
unsigned char reduced[length + 1]; char *binary_string = (char *) z_alloca(bin_len);
char binary_string[bin_len];
#else
unsigned char *reduced = (unsigned char *) _alloca(length + 1);
char *binary_string = (char *) _alloca(bin_len);
#endif
separator_row = 0; separator_row = 0;
@ -1461,10 +1449,10 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
if ((symbol->symbology == BARCODE_DBAR_EXP) || (symbol->symbology == BARCODE_DBAR_EXP_CC)) { if ((symbol->symbology == BARCODE_DBAR_EXP) || (symbol->symbology == BARCODE_DBAR_EXP_CC)) {
/* Copy elements into symbol */ /* Copy elements into symbol */
elements[0] = 1; // left guard elements[0] = 1; /* left guard */
elements[1] = 1; elements[1] = 1;
elements[pattern_width - 2] = 1; // right guard elements[pattern_width - 2] = 1; /* right guard */
elements[pattern_width - 1] = 1; elements[pattern_width - 1] = 1;
writer = 0; writer = 0;
@ -1509,7 +1497,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
} }
/* Row Start */ /* Row Start */
sub_elements[0] = 1; // left guard sub_elements[0] = 1; /* left guard */
sub_elements[1] = 1; sub_elements[1] = 1;
elements_in_sub = 2; elements_in_sub = 2;
@ -1556,7 +1544,7 @@ INTERNAL int dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[], int
} while ((reader < cols_per_row) && (current_block < codeblocks)); } while ((reader < cols_per_row) && (current_block < codeblocks));
/* Row Stop */ /* Row Stop */
sub_elements[elements_in_sub] = 1; // right guard sub_elements[elements_in_sub] = 1; /* right guard */
sub_elements[elements_in_sub + 1] = 1; sub_elements[elements_in_sub + 1] = 1;
elements_in_sub += 2; elements_in_sub += 2;

View File

@ -1,54 +0,0 @@
/* stdint_msvc.h - definitions for libzint
libzint - the open source barcode library
Copyright (C) 2009-2017 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the project nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifndef STDINT_MSVC_H
#define STDINT_MSVC_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef _MSC_VER
typedef BYTE uint8_t;
typedef WORD uint16_t;
typedef DWORD uint32_t;
typedef INT32 int32_t;
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* STDINT_MSVC_H */

View File

@ -1,8 +1,7 @@
/* svg.c - Scalable Vector Graphics */ /* svg.c - Scalable Vector Graphics */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,42 +28,39 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include <stdio.h>
#include <math.h> #include <math.h>
#ifdef _MSC_VER #include <stdio.h>
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
static void pick_colour(int colour, char colour_code[]) { static void pick_colour(int colour, char colour_code[]) {
switch (colour) { switch (colour) {
case 1: // Cyan case 1: /* Cyan */
strcpy(colour_code, "00ffff"); strcpy(colour_code, "00ffff");
break; break;
case 2: // Blue case 2: /* Blue */
strcpy(colour_code, "0000ff"); strcpy(colour_code, "0000ff");
break; break;
case 3: // Magenta case 3: /* Magenta */
strcpy(colour_code, "ff00ff"); strcpy(colour_code, "ff00ff");
break; break;
case 4: // Red case 4: /* Red */
strcpy(colour_code, "ff0000"); strcpy(colour_code, "ff0000");
break; break;
case 5: // Yellow case 5: /* Yellow */
strcpy(colour_code, "ffff00"); strcpy(colour_code, "ffff00");
break; break;
case 6: // Green case 6: /* Green */
strcpy(colour_code, "00ff00"); strcpy(colour_code, "00ff00");
break; break;
case 8: // White case 8: /* White */
strcpy(colour_code, "ffffff"); strcpy(colour_code, "ffffff");
break; break;
default: // Black default: /* Black */
strcpy(colour_code, "000000"); strcpy(colour_code, "000000");
break; break;
} }
@ -139,9 +135,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
char colour_code[7]; char colour_code[7];
int len, html_len; int len, html_len;
#ifdef _MSC_VER
char *html_string; char *html_string;
#endif
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
fgcolour_string[i] = symbol->fgcolour[i]; fgcolour_string[i] = symbol->fgcolour[i];
@ -178,11 +172,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
} }
} }
#ifndef _MSC_VER html_string = (char *) z_alloca(html_len);
char html_string[html_len];
#else
html_string = (char *) _alloca(html_len);
#endif
/* Check for no created vector set */ /* Check for no created vector set */
/* E-Mail Christian Schmitz 2019-09-10: reason unknown Ticket #164*/ /* E-Mail Christian Schmitz 2019-09-10: reason unknown Ticket #164*/
@ -298,7 +288,7 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
fprintf(fsvg, " fill=\"#%s\"", bgcolour_string); fprintf(fsvg, " fill=\"#%s\"", bgcolour_string);
} }
if (bg_alpha != 0xff) { if (bg_alpha != 0xff) {
// This doesn't work how the user is likely to expect - more work needed! /* This doesn't work how the user is likely to expect - more work needed! */
fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity); fprintf(fsvg, " opacity=\"%.3f\"", bg_alpha_opacity);
} }
} else { } else {
@ -350,3 +340,5 @@ INTERNAL int svg_plot(struct zint_symbol *symbol) {
return error_number; return error_number;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -27,18 +27,19 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
#include "testcommon.h" #include "testcommon.h"
#include "test_big5_tab.h" #include "test_big5_tab.h"
/* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */ /* For local "private" testing using previous libiconv adaptation, not included for licensing reasons */
//#define TEST_JUST_SAY_GNO /* #define TEST_JUST_SAY_GNO */
#ifdef TEST_JUST_SAY_GNO #ifdef TEST_JUST_SAY_GNO
#include "../just_say_gno/big5_gnu.h" #include "../just_say_gno/big5_gnu.h"
#endif #endif
INTERNAL int u_big5_test(const unsigned int u, unsigned char *dest); INTERNAL int u_big5_test(const unsigned int u, unsigned char *dest);
// Version of `u_big5()` taking unsigned int destination for backward-compatible testing /* Version of `u_big5()` taking unsigned int destination for backward-compatible testing */
static int u_big5_int(unsigned int u, unsigned int *d) { static int u_big5_int(unsigned int u, unsigned int *d) {
unsigned char dest[2]; unsigned char dest[2];
int ret = u_big5_test(u, dest); int ret = u_big5_test(u, dest);
@ -48,7 +49,8 @@ static int u_big5_int(unsigned int u, unsigned int *d) {
return ret; return ret;
} }
// As control convert to Big5 using simple table generated from https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/OTHER/BIG5.TXT plus simple processing /* As control convert to Big5 using simple table generated from
https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/OTHER/BIG5.TXT plus simple processing */
static int u_big5_int2(unsigned int u, unsigned int *dest) { static int u_big5_int2(unsigned int u, unsigned int *dest) {
int tab_length = ARRAY_SIZE(test_big5_tab); int tab_length = ARRAY_SIZE(test_big5_tab);
int start_i = test_big5_tab_ind[u >> 10]; int start_i = test_big5_tab_ind[u >> 10];
@ -99,7 +101,7 @@ static void test_u_big5_int(int debug) {
#endif #endif
for (i = 0; i < 0xFFFE; i++) { for (i = 0; i < 0xFFFE; i++) {
if (i >= 0xD800 && i < 0xE000) { // UTF-16 surrogates if (i >= 0xD800 && i < 0xE000) { /* UTF-16 surrogates */
continue; continue;
} }
val = val2 = 0; val = val2 = 0;
@ -149,11 +151,7 @@ static int big5_utf8(struct zint_symbol *symbol, const unsigned char source[], i
unsigned int *b5data) { unsigned int *b5data) {
int error_number; int error_number;
unsigned int i, length; unsigned int i, length;
#ifndef _MSC_VER unsigned int *utfdata = (unsigned int *) z_alloca(sizeof(unsigned int) * (*p_length + 1));
unsigned int utfdata[*p_length + 1];
#else
unsigned int *utfdata = (unsigned int *) _alloca((*p_length + 1) * sizeof(unsigned int));
#endif
error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 0 /*disallow_4byte*/); error_number = utf8_to_unicode(symbol, source, utfdata, p_length, 0 /*disallow_4byte*/);
if (error_number != 0) { if (error_number != 0) {
@ -179,9 +177,9 @@ static void test_big5_utf8(int index) {
unsigned int expected_b5data[20]; unsigned int expected_b5data[20];
char *comment; char *comment;
}; };
// _ U+FF3F fullwidth low line, not in ISO/Win, in Big5 0xA1C4, UTF-8 EFBCBF /* _ U+FF3F fullwidth low line, not in ISO/Win, in Big5 0xA1C4, UTF-8 EFBCBF */
// ╴ U+2574 drawings box light left, not in ISO/Win, not in original Big5 but in "Big5-2003" as 0xA15A, UTF-8 E295B4 /* ╴ U+2574 drawings box light left, not in ISO/Win, not in original Big5 but in "Big5-2003" as 0xA15A, UTF-8 E295B4 */
// s/\/\*[ 0-9]*\*\//\=printf("\/*%3d*\/", line(".") - line("'<")) /* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
struct item data[] = { struct item data[] = {
/* 0*/ { "_", -1, 0, 1, { 0xA1C4 }, "" }, /* 0*/ { "_", -1, 0, 1, { 0xA1C4 }, "" },
/* 1*/ { "", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" }, /* 1*/ { "", -1, ZINT_ERROR_INVALID_DATA, -1, {0}, "" },

View File

@ -36,13 +36,6 @@
#include "testcommon.h" #include "testcommon.h"
#ifdef _MSC_VER
#include <malloc.h>
#define testutil_alloca(nmemb) _alloca(nmemb)
#else
#define testutil_alloca(nmemb) alloca(nmemb)
#endif
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#include <direct.h> #include <direct.h>
@ -366,7 +359,7 @@ const char *testUtilErrorName(int error_number) {
if (error_number < 0 || error_number >= data_size) { if (error_number < 0 || error_number >= data_size) {
return ""; return "";
} }
// Self-check /* Self-check */
if (data[error_number].val != error_number if (data[error_number].val != error_number
|| (data[error_number].define != -1 && data[error_number].define != error_number)) { || (data[error_number].define != -1 && data[error_number].define != error_number)) {
fprintf(stderr, "testUtilErrorName: data table out of sync (%d)\n", error_number); fprintf(stderr, "testUtilErrorName: data table out of sync (%d)\n", error_number);
@ -408,7 +401,7 @@ const char *testUtilInputModeName(int input_mode) {
set = DATA_MODE; set = DATA_MODE;
} }
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (data[i].define != data[i].val) { // Self-check if (data[i].define != data[i].val) { /* Self-check */
fprintf(stderr, "testUtilInputModeName: data table out of sync (%d)\n", i); fprintf(stderr, "testUtilInputModeName: data table out of sync (%d)\n", i);
abort(); abort();
} }
@ -508,7 +501,7 @@ const char *testUtilOutputOptionsName(int output_options) {
} }
buf[0] = '\0'; buf[0] = '\0';
for (i = 0; i < data_size; i++) { for (i = 0; i < data_size; i++) {
if (data[i].define != data[i].val) { // Self-check if (data[i].define != data[i].val) { /* Self-check */
fprintf(stderr, "testUtilOutputOptionsName: data table out of sync (%d)\n", i); fprintf(stderr, "testUtilOutputOptionsName: data table out of sync (%d)\n", i);
abort(); abort();
} }
@ -574,8 +567,8 @@ char *testUtilEscape(const char *buffer, const int length, char *escaped, const
int chunk = -1; int chunk = -1;
for (i = 0; b < be && i < escaped_size; b++) { for (i = 0; b < be && i < escaped_size; b++) {
// For VC6-compatibility need to split literal strings into <= 2K chunks /* For VC6-compatibility need to split literal strings into <= 2K chunks */
if (i > 2040 && i / 2040 != chunk && (*b & 0xC0) != 0x80) { // Avoid UTF-8 continuations if (i > 2040 && i / 2040 != chunk && (*b & 0xC0) != 0x80) { /* Avoid UTF-8 continuations */
chunk = i / 2040; chunk = i / 2040;
if (i + 3 < escaped_size) { if (i + 3 < escaped_size) {
escaped[i] = '"'; escaped[i] = '"';
@ -714,7 +707,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
out->circles = NULL; out->circles = NULL;
out->hexagons = NULL; out->hexagons = NULL;
// Copy rectangles /* Copy rectangles */
rect = in->rectangles; rect = in->rectangles;
outrect = &(out->rectangles); outrect = &(out->rectangles);
while (rect) { while (rect) {
@ -726,7 +719,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
} }
*outrect = NULL; *outrect = NULL;
// Copy Strings /* Copy Strings */
string = in->strings; string = in->strings;
outstring = &(out->strings); outstring = &(out->strings);
while (string) { while (string) {
@ -741,7 +734,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
} }
*outstring = NULL; *outstring = NULL;
// Copy Circles /* Copy Circles */
circle = in->circles; circle = in->circles;
outcircle = &(out->circles); outcircle = &(out->circles);
while (circle) { while (circle) {
@ -753,7 +746,7 @@ struct zint_vector *testUtilVectorCpy(const struct zint_vector *in) {
} }
*outcircle = NULL; *outcircle = NULL;
// Copy Hexagons /* Copy Hexagons */
hexagon = in->hexagons; hexagon = in->hexagons;
outhexagon = &(out->hexagons); outhexagon = &(out->hexagons);
while (hexagon) { while (hexagon) {
@ -787,7 +780,7 @@ int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b)
return 2; return 2;
} }
// Compare rectangles /* Compare rectangles */
arect = a->rectangles; arect = a->rectangles;
brect = b->rectangles; brect = b->rectangles;
while (arect) { while (arect) {
@ -816,7 +809,7 @@ int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b)
return 10; return 10;
} }
// Compare strings /* Compare strings */
astring = a->strings; astring = a->strings;
bstring = b->strings; bstring = b->strings;
while (astring) { while (astring) {
@ -851,7 +844,7 @@ int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b)
return 20; return 20;
} }
// Compare circles /* Compare circles */
acircle = a->circles; acircle = a->circles;
bcircle = b->circles; bcircle = b->circles;
while (acircle) { while (acircle) {
@ -877,7 +870,7 @@ int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b)
return 30; return 30;
} }
// Compare hexagons /* Compare hexagons */
ahexagon = a->hexagons; ahexagon = a->hexagons;
bhexagon = b->hexagons; bhexagon = b->hexagons;
while (ahexagon) { while (ahexagon) {
@ -1197,26 +1190,26 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch
} }
if ((s = strstr(buffer, "/tests")) != NULL) { if ((s = strstr(buffer, "/tests")) != NULL) {
while ((s2 = strstr(s + 1, "/tests")) != NULL) { // Find rightmost while ((s2 = strstr(s + 1, "/tests")) != NULL) { /* Find rightmost */
s = s2; s = s2;
} }
*s = '\0'; *s = '\0';
len = s - buffer; len = s - buffer;
} }
if ((s = strstr(buffer, "/backend")) != NULL) { if ((s = strstr(buffer, "/backend")) != NULL) {
while ((s2 = strstr(s + 1, "/backend")) != NULL) { // Find rightmost while ((s2 = strstr(s + 1, "/backend")) != NULL) { /* Find rightmost */
s = s2; s = s2;
} }
*s = '\0'; *s = '\0';
len = s - buffer; len = s - buffer;
} else if ((s = strstr(buffer, "/frontend")) != NULL) { } else if ((s = strstr(buffer, "/frontend")) != NULL) {
while ((s2 = strstr(s + 1, "/frontend")) != NULL) { // Find rightmost while ((s2 = strstr(s + 1, "/frontend")) != NULL) { /* Find rightmost */
s = s2; s = s2;
} }
*s = '\0'; *s = '\0';
len = s - buffer; len = s - buffer;
} }
if (cmake_src_dir == NULL && (s = strrchr(buffer, '/')) != NULL) { // Remove "build" dir if (cmake_src_dir == NULL && (s = strrchr(buffer, '/')) != NULL) { /* Remove "build" dir */
*s = '\0'; *s = '\0';
len = s - buffer; len = s - buffer;
} }
@ -1622,7 +1615,7 @@ int testUtilCmpEpss(const char *eps1, const char *eps2) {
return 3; return 3;
} }
// Preprocess the 1st 2 lines to avoid comparing changeable Zint version in 2nd line /* Preprocess the 1st 2 lines to avoid comparing changeable Zint version in 2nd line */
if (fgets(buf1, sizeof(buf1), fp1) == NULL || strcmp(buf1, first_line) != 0 if (fgets(buf1, sizeof(buf1), fp1) == NULL || strcmp(buf1, first_line) != 0
|| fgets(buf2, sizeof(buf2), fp2) == NULL || strcmp(buf2, first_line) != 0) { || fgets(buf2, sizeof(buf2), fp2) == NULL || strcmp(buf2, first_line) != 0) {
ret = 10; ret = 10;
@ -1687,9 +1680,9 @@ int testUtilVerifyIdentify(const char *filename, int debug) {
if (strlen(filename) > 512) { if (strlen(filename) > 512) {
return -1; return -1;
} }
// Verbose option does a more thorough check /* Verbose option does a more thorough check */
if (debug & ZINT_DEBUG_TEST_PRINT) { if (debug & ZINT_DEBUG_TEST_PRINT) {
// Verbose very noisy though so for quick check just return default output /* Verbose very noisy though so for quick check just return default output */
if (debug & ZINT_DEBUG_TEST_LESS_NOISY) { if (debug & ZINT_DEBUG_TEST_LESS_NOISY) {
sprintf(cmd, "magick identify %s", filename); sprintf(cmd, "magick identify %s", filename);
} else { } else {
@ -1799,7 +1792,7 @@ int testUtilVerifyGhostscript(const char *filename, int debug) {
return -1; return -1;
} }
if (debug & ZINT_DEBUG_TEST_PRINT) { if (debug & ZINT_DEBUG_TEST_PRINT) {
// Prints nothing of interest with or without -q unless bad /* Prints nothing of interest with or without -q unless bad */
sprintf(cmd, GS_FILENAME " -dNOPAUSE -dBATCH -dNODISPLAY -q %s", filename); sprintf(cmd, GS_FILENAME " -dNOPAUSE -dBATCH -dNODISPLAY -q %s", filename);
printf("%s\n", cmd); printf("%s\n", cmd);
} else { } else {
@ -2024,7 +2017,7 @@ static const char *testUtilBwippName(int index, const struct zint_symbol *symbol
fprintf(stderr, "testUtilBwippName: unknown symbology (%d)\n", symbology); fprintf(stderr, "testUtilBwippName: unknown symbology (%d)\n", symbology);
abort(); abort();
} }
// Self-check /* Self-check */
if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) {
fprintf(stderr, "testUtilBwippName: data table out of sync (%d)\n", symbology); fprintf(stderr, "testUtilBwippName: data table out of sync (%d)\n", symbology);
abort(); abort();
@ -2195,9 +2188,9 @@ static char *testUtilBwippEscape(char *bwipp_data, int bwipp_data_size, const ch
case 'e': val = 0x1b; /* Escape */ break; case 'e': val = 0x1b; /* Escape */ break;
case 'G': val = 0x1d; /* Group Separator */ break; case 'G': val = 0x1d; /* Group Separator */ break;
case 'R': val = 0x1e; /* Record Separator */ break; case 'R': val = 0x1e; /* Record Separator */ break;
//case 'x': val = 0; /* TODO: implement */ break; /*case 'x': val = 0; TODO: implement break; */
case '\\': val = '\\'; break; case '\\': val = '\\'; break;
//case 'u': val = 0; /* TODO: implement */ break; /*case 'u': val = 0; TODO: implement break; */
default: fprintf(stderr, "testUtilBwippEscape: unknown escape %c\n", *d); return NULL; break; default: fprintf(stderr, "testUtilBwippEscape: unknown escape %c\n", *d); return NULL; break;
} }
if (b + 4 >= be) { if (b + 4 >= be) {
@ -2248,7 +2241,7 @@ static char *testUtilBwippUtf8Convert(const int index, const int symbology, cons
if (eci == 0 && try_sjis if (eci == 0 && try_sjis
&& (symbology == BARCODE_QRCODE || symbology == BARCODE_MICROQR || symbology == BARCODE_RMQR || symbology == BARCODE_UPNQR)) { && (symbology == BARCODE_QRCODE || symbology == BARCODE_MICROQR || symbology == BARCODE_RMQR || symbology == BARCODE_UPNQR)) {
if (symbology == BARCODE_UPNQR) { // Note need to add "force binary mode" to BWIPP for this to work if (symbology == BARCODE_UPNQR) { /* Note need to add "force binary mode" to BWIPP for this to work */
if (utf8_to_eci(4, data, converted, p_data_len) != 0) { if (utf8_to_eci(4, data, converted, p_data_len) != 0) {
fprintf(stderr, "i:%d testUtilBwippUtf8Convert: failed to convert UTF-8 data for %s, ECI 4\n", fprintf(stderr, "i:%d testUtilBwippUtf8Convert: failed to convert UTF-8 data for %s, ECI 4\n",
index, testUtilBarcodeName(symbology)); index, testUtilBarcodeName(symbology));
@ -2262,7 +2255,7 @@ static char *testUtilBwippUtf8Convert(const int index, const int symbology, cons
index, testUtilBarcodeName(symbology)); index, testUtilBarcodeName(symbology));
return NULL; return NULL;
} }
// NOTE: not setting *p_eci = 20 /* NOTE: not setting *p_eci = 20 */
} }
} }
return (char *) converted; return (char *) converted;
@ -2301,7 +2294,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
" backend/tests/tools/bwipp_dump.ps"; " backend/tests/tools/bwipp_dump.ps";
static const char cmd_opts_fmt[] = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' -so='%s'" static const char cmd_opts_fmt[] = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%s' -so='%s'"
" backend/tests/tools/bwipp_dump.ps"; " backend/tests/tools/bwipp_dump.ps";
// If data > 2K /* If data > 2K */
static const char cmd_fmt2[] = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s'" static const char cmd_fmt2[] = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s'"
" backend/tests/tools/bwipp_dump.ps"; " backend/tests/tools/bwipp_dump.ps";
static const char cmd_opts_fmt2[] = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' -so='%s'" static const char cmd_opts_fmt2[] = "gs -dNOPAUSE -dBATCH -dNODISPLAY -q -sb=%s -sd='%.2043s' -sd2='%s' -so='%s'"
@ -2314,14 +2307,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; int max_data_len = 4 + primary_len + 1 + 1 + data_len * 4 + 64;
int eci_length = get_eci_length(symbol->eci, (const unsigned char *) data, data_len); int eci_length = get_eci_length(symbol->eci, (const unsigned char *) data, data_len);
char *converted = (char *) testutil_alloca(eci_length + 1); char *converted = (char *) z_alloca(eci_length + 1);
char *cmd = (char *) testutil_alloca(max_data_len + 1024); char *cmd = (char *) z_alloca(max_data_len + 1024);
const char *bwipp_barcode = NULL; const char *bwipp_barcode = NULL;
char *bwipp_opts = NULL; char *bwipp_opts = NULL;
int bwipp_data_size = max_data_len + 1; int bwipp_data_size = max_data_len + 1;
char *bwipp_data = (char *) testutil_alloca(bwipp_data_size); char *bwipp_data = (char *) z_alloca(bwipp_data_size);
char bwipp_opts_buf[512]; char bwipp_opts_buf[512];
int *bwipp_row_height = (int *) testutil_alloca(sizeof(int) * symbol->rows); int *bwipp_row_height = (int *) z_alloca(sizeof(int) * symbol->rows);
int linear_row_height; int linear_row_height;
int gs1_cvt; int gs1_cvt;
int user_mask; int user_mask;
@ -2465,7 +2458,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
if (symbology == BARCODE_C25STANDARD || symbology == BARCODE_C25INTER || symbology == BARCODE_C25IATA if (symbology == BARCODE_C25STANDARD || symbology == BARCODE_C25INTER || symbology == BARCODE_C25IATA
|| symbology == BARCODE_C25LOGIC || symbology == BARCODE_C25IND) { || symbology == BARCODE_C25LOGIC || symbology == BARCODE_C25IND) {
if (option_2 == 1 || option_2 == 2) { // Add check digit without or with HRT suppression if (option_2 == 1 || option_2 == 2) { /* Add check digit without or with HRT suppression */
sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sincludecheck", sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sincludecheck",
strlen(bwipp_opts_buf) ? " " : ""); strlen(bwipp_opts_buf) ? " " : "");
bwipp_opts = bwipp_opts_buf; bwipp_opts = bwipp_opts_buf;
@ -2478,7 +2471,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%spzn8", strlen(bwipp_opts_buf) ? " " : ""); sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%spzn8", strlen(bwipp_opts_buf) ? " " : "");
bwipp_opts = bwipp_opts_buf; bwipp_opts = bwipp_opts_buf;
} else if (symbology == BARCODE_TELEPEN_NUM) { } else if (symbology == BARCODE_TELEPEN_NUM) {
if (data_len & 1) { // Add leading zero if (data_len & 1) { /* Add leading zero */
memmove(bwipp_data + 1, bwipp_data, strlen(bwipp_data) + 1); memmove(bwipp_data + 1, bwipp_data, strlen(bwipp_data) + 1);
*bwipp_data = '0'; *bwipp_data = '0';
} }
@ -2680,7 +2673,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
if (option_2 == 9) { if (option_2 == 9) {
codeone_version = length <= 6 ? "S-10" : length <= 12 ? "S-20" : "S-30"; codeone_version = length <= 6 ? "S-10" : length <= 12 ? "S-20" : "S-30";
} else if (option_2 == 10) { } else if (option_2 == 10) {
// TODO: Properly allow for different T sizes /* TODO: Properly allow for different T sizes */
codeone_version = length <= 22 ? "T-16" : length <= 34 ? "T-32" : "T-48"; codeone_version = length <= 22 ? "T-16" : length <= 34 ? "T-32" : "T-48";
} else { } else {
codeone_version = codeone_versions[option_2 - 1]; codeone_version = codeone_versions[option_2 - 1];
@ -2765,7 +2758,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
bwipp_opts = bwipp_opts_buf; bwipp_opts = bwipp_opts_buf;
} }
} else if (symbology == BARCODE_BC412) { } else if (symbology == BARCODE_BC412) {
// TODO: /* TODO: */
} }
} }
@ -2793,7 +2786,7 @@ int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int
if ((option_3 & 0x7F) != DM_SQUARE && symbol->width != symbol->height) { if ((option_3 & 0x7F) != DM_SQUARE && symbol->width != symbol->height) {
if ((option_3 & 0x7F) == DM_DMRE && !added_dmre) { if ((option_3 & 0x7F) == DM_DMRE && !added_dmre) {
sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sdmre", strlen(bwipp_opts_buf) ? " " : ""); sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sdmre", strlen(bwipp_opts_buf) ? " " : "");
//added_dmre = 1; /*added_dmre = 1; */
} }
sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sformat=rectangle", sprintf(bwipp_opts_buf + strlen(bwipp_opts_buf), "%sformat=rectangle",
strlen(bwipp_opts_buf) ? " " : ""); strlen(bwipp_opts_buf) ? " " : "");
@ -3022,7 +3015,7 @@ int testUtilBwippSegs(int index, struct zint_symbol *symbol, int option_1, int o
const int symbology = symbol->symbology; const int symbology = symbol->symbology;
const int unicode_mode = (symbol->input_mode & 0x7) == UNICODE_MODE; const int unicode_mode = (symbol->input_mode & 0x7) == UNICODE_MODE;
const int symbol_eci = symbol->eci; const int symbol_eci = symbol->eci;
struct zint_seg *local_segs = (struct zint_seg *) testutil_alloca(sizeof(struct zint_seg) * seg_count); struct zint_seg *local_segs = (struct zint_seg *) z_alloca(sizeof(struct zint_seg) * seg_count);
int total_len = 0; int total_len = 0;
char *data, *d; char *data, *d;
int parsefnc = 1; int parsefnc = 1;
@ -3043,7 +3036,7 @@ int testUtilBwippSegs(int index, struct zint_symbol *symbol, int option_1, int o
} }
} }
total_len += 10 * seg_count; total_len += 10 * seg_count;
d = data = (char *) testutil_alloca(total_len + 1); d = data = (char *) z_alloca(total_len + 1);
for (i = 0; i < seg_count; i++) { for (i = 0; i < seg_count; i++) {
if (unicode_mode && is_eci_convertible(local_segs[i].eci)) { if (unicode_mode && is_eci_convertible(local_segs[i].eci)) {
@ -3201,7 +3194,7 @@ static const char *testUtilZXingCPPName(int index, const struct zint_symbol *sym
{ "", BARCODE_C25LOGIC, 6, }, { "", BARCODE_C25LOGIC, 6, },
{ "", BARCODE_C25IND, 7, }, { "", BARCODE_C25IND, 7, },
{ "Code39", BARCODE_CODE39, 8, }, { "Code39", BARCODE_CODE39, 8, },
{ "Code39", BARCODE_EXCODE39, 9, }, // TODO: Code39 with specially encoded chars { "Code39", BARCODE_EXCODE39, 9, }, /* TODO: Code39 with specially encoded chars */
{ "", -1, 10, }, { "", -1, 10, },
{ "", -1, 11, }, { "", -1, 11, },
{ "", -1, 12, }, { "", -1, 12, },
@ -3244,7 +3237,7 @@ static const char *testUtilZXingCPPName(int index, const struct zint_symbol *sym
{ "", BARCODE_FIM, 49, }, { "", BARCODE_FIM, 49, },
{ "Code39", BARCODE_LOGMARS, 50, }, { "Code39", BARCODE_LOGMARS, 50, },
{ "", BARCODE_PHARMA, 51, }, { "", BARCODE_PHARMA, 51, },
{ "", BARCODE_PZN, 52, }, // TODO: Code39 with prefix and mod-11 checksum { "", BARCODE_PZN, 52, }, /* TODO: Code39 with prefix and mod-11 checksum */
{ "", BARCODE_PHARMA_TWO, 53, }, { "", BARCODE_PHARMA_TWO, 53, },
{ "", -1, 54, }, { "", -1, 54, },
{ "PDF417", BARCODE_PDF417, 55, }, { "PDF417", BARCODE_PDF417, 55, },
@ -3321,7 +3314,7 @@ static const char *testUtilZXingCPPName(int index, const struct zint_symbol *sym
{ "", -1, 126, }, { "", -1, 126, },
{ "", -1, 127, }, { "", -1, 127, },
{ "", BARCODE_AZRUNE, 128, }, { "", BARCODE_AZRUNE, 128, },
{ "", BARCODE_CODE32, 129, }, // Code39 based { "", BARCODE_CODE32, 129, }, /* Code39 based */
{ "", BARCODE_EANX_CC, 130, }, { "", BARCODE_EANX_CC, 130, },
{ "", BARCODE_GS1_128_CC, 131, }, { "", BARCODE_GS1_128_CC, 131, },
{ "", BARCODE_DBAR_OMN_CC, 132, }, { "", BARCODE_DBAR_OMN_CC, 132, },
@ -3347,7 +3340,7 @@ static const char *testUtilZXingCPPName(int index, const struct zint_symbol *sym
fprintf(stderr, "testUtilZXingCPPName: unknown symbology (%d)\n", symbology); fprintf(stderr, "testUtilZXingCPPName: unknown symbology (%d)\n", symbology);
abort(); abort();
} }
// Self-check /* Self-check */
if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) { if (data[symbology].val != symbology || (data[symbology].define != -1 && data[symbology].define != symbology)) {
fprintf(stderr, "testUtilZXingCPPName: data table out of sync (%d)\n", symbology); fprintf(stderr, "testUtilZXingCPPName: data table out of sync (%d)\n", symbology);
abort(); abort();
@ -3362,7 +3355,7 @@ static const char *testUtilZXingCPPName(int index, const struct zint_symbol *sym
if (symbology == BARCODE_QRCODE || symbology == BARCODE_HIBC_QR || symbology == BARCODE_MICROQR if (symbology == BARCODE_QRCODE || symbology == BARCODE_HIBC_QR || symbology == BARCODE_MICROQR
|| symbology == BARCODE_RMQR) { || symbology == BARCODE_RMQR) {
const int full_multibyte = (symbol->option_3 & 0xFF) == ZINT_FULL_MULTIBYTE; const int full_multibyte = (symbol->option_3 & 0xFF) == ZINT_FULL_MULTIBYTE;
if (full_multibyte) { // TODO: Support in ZXing-C++ if (full_multibyte) { /* TODO: Support in ZXing-C++ */
printf("i:%d %s not ZXing-C++ compatible, ZINT_FULL_MULTIBYTE not supported\n", printf("i:%d %s not ZXing-C++ compatible, ZINT_FULL_MULTIBYTE not supported\n",
index, testUtilBarcodeName(symbology)); index, testUtilBarcodeName(symbology));
return NULL; return NULL;
@ -3401,7 +3394,7 @@ int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source,
const int bits_len = (int) strlen(bits); const int bits_len = (int) strlen(bits);
const int width = symbol->width; const int width = symbol->width;
const int symbology = symbol->symbology; const int symbology = symbol->symbology;
char *cmd = (char *) testutil_alloca(bits_len + 1024); char *cmd = (char *) z_alloca(bits_len + 1024);
const char *zxingcpp_barcode = NULL; const char *zxingcpp_barcode = NULL;
const int data_mode = (symbol->input_mode & 0x07) == DATA_MODE; const int data_mode = (symbol->input_mode & 0x07) == DATA_MODE;
int set_charset = 0; int set_charset = 0;
@ -3431,7 +3424,7 @@ int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source,
if ((symbol->input_mode & 0x07) == UNICODE_MODE && symbol->eci == 0 if ((symbol->input_mode & 0x07) == UNICODE_MODE && symbol->eci == 0
&& (symbology == BARCODE_QRCODE || symbology == BARCODE_MICROQR || symbology == BARCODE_HANXIN)) { && (symbology == BARCODE_QRCODE || symbology == BARCODE_MICROQR || symbology == BARCODE_HANXIN)) {
int converted_len = length; int converted_len = length;
unsigned char *converted_buf = (unsigned char *) testutil_alloca(converted_len + 1); unsigned char *converted_buf = (unsigned char *) z_alloca(converted_len + 1);
if (symbology == BARCODE_HANXIN) { if (symbology == BARCODE_HANXIN) {
set_charset = utf8_to_eci(0, (const unsigned char *) source, converted_buf, &converted_len) != 0; set_charset = utf8_to_eci(0, (const unsigned char *) source, converted_buf, &converted_len) != 0;
} else { } else {
@ -3482,7 +3475,7 @@ int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source,
const int eci = symbol->eci >= 899 ? 3 : symbol->eci; const int eci = symbol->eci >= 899 ? 3 : symbol->eci;
int error_number; int error_number;
const int eci_length = get_eci_length(eci, (const unsigned char *) buffer, cnt); const int eci_length = get_eci_length(eci, (const unsigned char *) buffer, cnt);
unsigned char *preprocessed = (unsigned char *) testutil_alloca(eci_length + 1); unsigned char *preprocessed = (unsigned char *) z_alloca(eci_length + 1);
if (eci_length >= buffer_size) { if (eci_length >= buffer_size) {
fprintf(stderr, "i:%d testUtilZXingCPP: buffer too small, %d bytes, eci_length %d (%s)\n", fprintf(stderr, "i:%d testUtilZXingCPP: buffer too small, %d bytes, eci_length %d (%s)\n",
@ -3498,7 +3491,7 @@ int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source,
return -1; return -1;
} else { } else {
int i; int i;
unsigned int *vals = (unsigned int *) testutil_alloca(sizeof(int) * (cnt + 1)); unsigned int *vals = (unsigned int *) z_alloca(sizeof(int) * (cnt + 1));
error_number = utf8_to_unicode(symbol, (const unsigned char *) buffer, vals, &cnt, 1); error_number = utf8_to_unicode(symbol, (const unsigned char *) buffer, vals, &cnt, 1);
if (error_number != 0) { if (error_number != 0) {
fprintf(stderr, "i:%d testUtilZXingCPP: utf8_to_unicode == %d (%s)\n", index, error_number, cmd); fprintf(stderr, "i:%d testUtilZXingCPP: utf8_to_unicode == %d (%s)\n", index, error_number, cmd);
@ -3537,17 +3530,17 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
const int is_dbar_exp = symbology == BARCODE_DBAR_EXP || symbology == BARCODE_DBAR_EXPSTK; const int is_dbar_exp = symbology == BARCODE_DBAR_EXP || symbology == BARCODE_DBAR_EXPSTK;
const int is_upcean = is_extendable(symbology); const int is_upcean = is_extendable(symbology);
char *reduced = gs1 ? (char *) testutil_alloca(expected_len + 1) : NULL; char *reduced = gs1 ? (char *) z_alloca(expected_len + 1) : NULL;
char *escaped = is_escaped ? (char *) testutil_alloca(expected_len + 1) : NULL; char *escaped = is_escaped ? (char *) z_alloca(expected_len + 1) : NULL;
char *hibc = is_hibc ? (char *) testutil_alloca(expected_len + 2 + 1) : NULL; char *hibc = is_hibc ? (char *) z_alloca(expected_len + 2 + 1) : NULL;
char *maxi = symbology == BARCODE_MAXICODE && primary char *maxi = symbology == BARCODE_MAXICODE && primary
? (char *) testutil_alloca(expected_len + strlen(primary) + 6 + 9 + 1) : NULL; ? (char *) z_alloca(expected_len + strlen(primary) + 6 + 9 + 1) : NULL;
char *vin = symbology == BARCODE_VIN && (symbol->option_2 & 1) ? (char *) testutil_alloca(expected_len + 1 + 1) : NULL; char *vin = symbology == BARCODE_VIN && (symbol->option_2 & 1) ? (char *) z_alloca(expected_len + 1 + 1) : NULL;
char *c25inter = have_c25inter ? (char *) testutil_alloca(expected_len + 13 + 1 + 1) : NULL; char *c25inter = have_c25inter ? (char *) z_alloca(expected_len + 13 + 1 + 1) : NULL;
char *dbar_exp = is_dbar_exp ? (char *) testutil_alloca(expected_len + 1) : NULL; char *dbar_exp = is_dbar_exp ? (char *) z_alloca(expected_len + 1) : NULL;
char *upcean = is_upcean ? (char *) testutil_alloca(expected_len + 1 + 1) : NULL; char *upcean = is_upcean ? (char *) z_alloca(expected_len + 1 + 1) : NULL;
char *ean14_nve18 = symbology == BARCODE_EAN14 || symbology == BARCODE_NVE18 char *ean14_nve18 = symbology == BARCODE_EAN14 || symbology == BARCODE_NVE18
? (char *) testutil_alloca(expected_len + 3 + 1) : NULL; ? (char *) z_alloca(expected_len + 3 + 1) : NULL;
int ret; int ret;
int ret_memcmp; int ret_memcmp;
@ -3583,7 +3576,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
} }
expected = reduced; expected = reduced;
if (primary) { if (primary) {
// TODO: /* TODO: */
} }
} else if (is_hibc) { } else if (is_hibc) {
int counter; int counter;
@ -3630,11 +3623,11 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
expected_len += maxi_len; expected_len += maxi_len;
} }
} else if (symbology == BARCODE_CODABAR) { } else if (symbology == BARCODE_CODABAR) {
// Start A/B/C/D and stop A/B/C/D chars not returned by ZXing-C++ /* Start A/B/C/D and stop A/B/C/D chars not returned by ZXing-C++ */
expected++; expected++;
expected_len -= 2; expected_len -= 2;
if (symbol->option_2 == 1 || symbol->option_2 == 2) { if (symbol->option_2 == 1 || symbol->option_2 == 2) {
cmp_len--; // Too messy to calc the check digit so ignore cmp_len--; /* Too messy to calc the check digit so ignore */
} }
} else if (symbology == BARCODE_VIN) { } else if (symbology == BARCODE_VIN) {
if (symbol->option_2 & 1) { if (symbol->option_2 & 1) {
@ -3691,7 +3684,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
} }
} else if (symbology == BARCODE_DBAR_OMN || symbology == BARCODE_DBAR_OMNSTK) { } else if (symbology == BARCODE_DBAR_OMN || symbology == BARCODE_DBAR_OMNSTK) {
if (expected_len == 13) { if (expected_len == 13) {
cmp_len--; // Too messy to calc the check digit so ignore cmp_len--; /* Too messy to calc the check digit so ignore */
} }
} else if (is_dbar_exp) { } else if (is_dbar_exp) {
for (i = 0; i < expected_len; i++) { for (i = 0; i < expected_len; i++) {
@ -3850,7 +3843,7 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in
int testUtilZXingCPPCmpSegs(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len, int testUtilZXingCPPCmpSegs(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len,
const struct zint_seg segs[], const int seg_count, const char *primary, char *ret_buf, int *p_ret_len) { const struct zint_seg segs[], const int seg_count, const char *primary, char *ret_buf, int *p_ret_len) {
int expected_len = segs_length(segs, seg_count); int expected_len = segs_length(segs, seg_count);
char *expected = (char *) testutil_alloca(expected_len + 1); char *expected = (char *) z_alloca(expected_len + 1);
char *s = expected; char *s = expected;
int i; int i;

View File

@ -44,6 +44,10 @@
#define ZINT_DEBUG_TEST_PERFORMANCE 256 #define ZINT_DEBUG_TEST_PERFORMANCE 256
#define ZINT_DEBUG_TEST_ZXINGCPP 512 #define ZINT_DEBUG_TEST_ZXINGCPP 512
#include <errno.h>
#include <stdio.h>
#include "../common.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#define testutil_popen(command, mode) _popen(command, mode) #define testutil_popen(command, mode) _popen(command, mode)
#define testutil_pclose(stream) _pclose(stream) #define testutil_pclose(stream) _pclose(stream)
@ -53,14 +57,7 @@
#define testutil_pclose(stream) pclose(stream) #define testutil_pclose(stream) pclose(stream)
#endif #endif
#include <stdio.h> #if defined(__clang__) || defined(__GNUC__)
#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 "-Wpedantic"
# pragma GCC diagnostic ignored "-Woverlength-strings" # pragma GCC diagnostic ignored "-Woverlength-strings"
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
@ -91,7 +88,6 @@ typedef struct s_testFunction {
void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size); void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
#if _MSC_VER == 1200 /* VC6 */ #if _MSC_VER == 1200 /* VC6 */
#include "../ms_stdint.h"
void assert_zero(int exp, const char *fmt, ...); void assert_zero(int exp, const char *fmt, ...);
void assert_nonzero(int exp, const char *fmt, ...); void assert_nonzero(int exp, const char *fmt, ...);
void assert_null(const void *exp, const char *fmt, ...); void assert_null(const void *exp, const char *fmt, ...);

View File

@ -1,9 +1,7 @@
/* tif.c - Aldus Tagged Image File Format support */ /* tif.c - Aldus Tagged Image File Format support */
/* TIFF Revision 6.0 https://www.adobe.io/content/dam/udp/en/open/standards/tiff/TIFF6.pdf */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2016 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2016-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -30,20 +28,17 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <math.h>
#include <assert.h>
#include <limits.h>
#include "common.h" #include "common.h"
#include "tif.h" #include "tif.h"
#include "tif_lzw.h" #include "tif_lzw.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#include <io.h> #include <io.h>
#include <fcntl.h> #include <fcntl.h>
#include <malloc.h>
#endif #endif
/* PhotometricInterpretation */ /* PhotometricInterpretation */
@ -83,6 +78,7 @@ static int is_big_endian(void) {
return (*((const uint16_t *)"\x11\x22") == 0x1122); return (*((const uint16_t *)"\x11\x22") == 0x1122);
} }
/* TIFF Revision 6.0 https://www.adobe.io/content/dam/udp/en/open/standards/tiff/TIFF6.pdf */
INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) { INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf) {
unsigned char fg[4], bg[4]; unsigned char fg[4], bg[4];
int i; int i;
@ -109,11 +105,9 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
tif_lzw_state lzw_state; tif_lzw_state lzw_state;
long file_pos; long file_pos;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT; const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
#ifdef _MSC_VER
uint32_t *strip_offset; uint32_t *strip_offset;
uint32_t *strip_bytes; uint32_t *strip_bytes;
unsigned char *strip_buf; unsigned char *strip_buf;
#endif
tiff_header_t header; tiff_header_t header;
uint16_t entries = 0; uint16_t entries = 0;
@ -297,15 +291,10 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
bytes_per_strip = rows_per_strip * ((symbol->bitmap_width + pixels_per_sample - 1) / pixels_per_sample) bytes_per_strip = rows_per_strip * ((symbol->bitmap_width + pixels_per_sample - 1) / pixels_per_sample)
* samples_per_pixel; * samples_per_pixel;
#ifndef _MSC_VER strip_offset = (uint32_t *) z_alloca(sizeof(uint32_t) * strip_count);
uint32_t strip_offset[strip_count]; strip_bytes = (uint32_t *) z_alloca(sizeof(uint32_t) * strip_count);
uint32_t strip_bytes[strip_count]; strip_buf = (unsigned char *) z_alloca(bytes_per_strip + 1);
unsigned char strip_buf[bytes_per_strip + 1];
#else
strip_offset = (uint32_t *) _alloca(strip_count * sizeof(uint32_t));
strip_bytes = (uint32_t *) _alloca(strip_count * sizeof(uint32_t));
strip_buf = (unsigned char *) _alloca(bytes_per_strip + 1);
#endif
free_memory = sizeof(tiff_header_t); free_memory = sizeof(tiff_header_t);
for (i = 0; i < strip_count; i++) { for (i = 0; i < strip_count; i++) {
@ -324,7 +313,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
free_memory += strip_bytes[i]; free_memory += strip_bytes[i];
} }
if (free_memory & 1) { if (free_memory & 1) {
free_memory++; // IFD must be on word boundary free_memory++; /* IFD must be on word boundary */
} }
if (free_memory > 0xffff0000) { if (free_memory > 0xffff0000) {
@ -352,9 +341,9 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
/* Header */ /* Header */
if (is_big_endian()) { if (is_big_endian()) {
header.byte_order = 0x4D4D; // "MM" big-endian header.byte_order = 0x4D4D; /* "MM" big-endian */
} else { } else {
header.byte_order = 0x4949; // "II" little-endian header.byte_order = 0x4949; /* "II" little-endian */
} }
header.identity = 42; header.identity = 42;
header.offset = free_memory; header.offset = free_memory;
@ -403,7 +392,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
strip_row++; strip_row++;
if (strip_row == rows_per_strip || (strip == strip_count - 1 && strip_row == rows_last_strip)) { if (strip_row == rows_per_strip || (strip == strip_count - 1 && strip_row == rows_last_strip)) {
// End of strip /* End of strip */
if (compression == TIF_LZW) { if (compression == TIF_LZW) {
file_pos = ftell(tif_file); file_pos = ftell(tif_file);
if (!tif_lzw_encode(&lzw_state, tif_file, strip_buf, bytes_put)) { /* Only fails if can't malloc */ if (!tif_lzw_encode(&lzw_state, tif_file, strip_buf, bytes_put)) { /* Only fails if can't malloc */
@ -433,7 +422,7 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
} }
if (total_bytes_put & 1) { if (total_bytes_put & 1) {
putc(0, tif_file); // IFD must be on word boundary putc(0, tif_file); /* IFD must be on word boundary */
total_bytes_put++; total_bytes_put++;
} }
@ -448,19 +437,19 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
} }
/* Image File Directory */ /* Image File Directory */
tags[entries].tag = 0x0100; // ImageWidth tags[entries].tag = 0x0100; /* ImageWidth */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = 1; tags[entries].count = 1;
tags[entries++].offset = symbol->bitmap_width; tags[entries++].offset = symbol->bitmap_width;
tags[entries].tag = 0x0101; // ImageLength - number of rows tags[entries].tag = 0x0101; /* ImageLength - number of rows */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = 1; tags[entries].count = 1;
tags[entries++].offset = symbol->bitmap_height; tags[entries++].offset = symbol->bitmap_height;
if (samples_per_pixel != 1 || bits_per_sample != 1) { if (samples_per_pixel != 1 || bits_per_sample != 1) {
tags[entries].tag = 0x0102; // BitsPerSample tags[entries].tag = 0x0102; /* BitsPerSample */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = samples_per_pixel; tags[entries].count = samples_per_pixel;
if (samples_per_pixel == 1) { if (samples_per_pixel == 1) {
tags[entries++].offset = bits_per_sample; tags[entries++].offset = bits_per_sample;
@ -473,18 +462,18 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
} }
} }
tags[entries].tag = 0x0103; // Compression tags[entries].tag = 0x0103; /* Compression */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = 1; tags[entries].count = 1;
tags[entries++].offset = compression; tags[entries++].offset = compression;
tags[entries].tag = 0x0106; // PhotometricInterpretation tags[entries].tag = 0x0106; /* PhotometricInterpretation */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = 1; tags[entries].count = 1;
tags[entries++].offset = pmi; tags[entries++].offset = pmi;
tags[entries].tag = 0x0111; // StripOffsets tags[entries].tag = 0x0111; /* StripOffsets */
tags[entries].type = 4; // LONG tags[entries].type = 4; /* LONG */
tags[entries].count = strip_count; tags[entries].count = strip_count;
if (strip_count == 1) { if (strip_count == 1) {
tags[entries++].offset = strip_offset[0]; tags[entries++].offset = strip_offset[0];
@ -495,19 +484,19 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
} }
if (samples_per_pixel > 1) { if (samples_per_pixel > 1) {
tags[entries].tag = 0x0115; // SamplesPerPixel tags[entries].tag = 0x0115; /* SamplesPerPixel */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = 1; tags[entries].count = 1;
tags[entries++].offset = samples_per_pixel; tags[entries++].offset = samples_per_pixel;
} }
tags[entries].tag = 0x0116; // RowsPerStrip tags[entries].tag = 0x0116; /* RowsPerStrip */
tags[entries].type = 4; // LONG tags[entries].type = 4; /* LONG */
tags[entries].count = 1; tags[entries].count = 1;
tags[entries++].offset = rows_per_strip; tags[entries++].offset = rows_per_strip;
tags[entries].tag = 0x0117; // StripByteCounts tags[entries].tag = 0x0117; /* StripByteCounts */
tags[entries].type = 4; // LONG tags[entries].type = 4; /* LONG */
tags[entries].count = strip_count; tags[entries].count = strip_count;
if (strip_count == 1) { if (strip_count == 1) {
tags[entries++].offset = strip_bytes[0]; tags[entries++].offset = strip_bytes[0];
@ -517,37 +506,37 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
free_memory += strip_count * 4; free_memory += strip_count * 4;
} }
tags[entries].tag = 0x011a; // XResolution tags[entries].tag = 0x011a; /* XResolution */
tags[entries].type = 5; // RATIONAL tags[entries].type = 5; /* RATIONAL */
tags[entries].count = 1; tags[entries].count = 1;
update_offsets[offsets++] = entries; update_offsets[offsets++] = entries;
tags[entries++].offset = free_memory; tags[entries++].offset = free_memory;
free_memory += 8; free_memory += 8;
tags[entries].tag = 0x011b; // YResolution tags[entries].tag = 0x011b; /* YResolution */
tags[entries].type = 5; // RATIONAL tags[entries].type = 5; /* RATIONAL */
tags[entries].count = 1; tags[entries].count = 1;
update_offsets[offsets++] = entries; update_offsets[offsets++] = entries;
tags[entries++].offset = free_memory; tags[entries++].offset = free_memory;
free_memory += 8; free_memory += 8;
tags[entries].tag = 0x0128; // ResolutionUnit tags[entries].tag = 0x0128; /* ResolutionUnit */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = 1; tags[entries].count = 1;
tags[entries++].offset = 2; // Inches tags[entries++].offset = 2; /* Inches */
if (color_map_size) { if (color_map_size) {
tags[entries].tag = 0x0140; // ColorMap tags[entries].tag = 0x0140; /* ColorMap */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = color_map_size * 3; tags[entries].count = color_map_size * 3;
update_offsets[offsets++] = entries; update_offsets[offsets++] = entries;
tags[entries++].offset = free_memory; tags[entries++].offset = free_memory;
//free_memory += color_map_size * 3 * 2; /* Unnecessary as long as last use */ /* free_memory += color_map_size * 3 * 2; Unnecessary as long as last use */
} }
if (extra_samples) { if (extra_samples) {
tags[entries].tag = 0x0152; // ExtraSamples tags[entries].tag = 0x0152; /* ExtraSamples */
tags[entries].type = 3; // SHORT tags[entries].type = 3; /* SHORT */
tags[entries].count = 1; tags[entries].count = 1;
tags[entries++].offset = extra_samples; tags[entries++].offset = extra_samples;
} }
@ -622,3 +611,5 @@ INTERNAL int tif_pixel_plot(struct zint_symbol *symbol, unsigned char *pixelbuf)
return 0; return 0;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,8 +1,7 @@
/* tif.h - Aldus Tagged Image File Format */ /* tif.h - Aldus Tagged Image File Format */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2016-2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2016-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -29,22 +28,15 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#ifndef TIF_H #ifndef Z_TIF_H
#define TIF_H #define Z_TIF_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef _MSC_VER
#include <windows.h>
#include "stdint_msvc.h"
#else
#include <stdint.h>
#endif
#pragma pack(1) #pragma pack(1)
typedef struct tiff_header { typedef struct tiff_header {
@ -72,4 +64,5 @@ extern "C" {
} }
#endif #endif
#endif /* TIF_H */ /* vim: set ts=4 sw=4 et : */
#endif /* Z_TIF_H */

View File

@ -1,5 +1,5 @@
/* ultra.c - Ultracode /* ultra.c - Ultracode */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2020-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2020-2022 Robin Stuart <rstuart114@gmail.com>
@ -28,12 +28,10 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */
/* This version was developed using AIMD/TSC15032-43 v0.99c Edit 60, dated 4th Nov 2015 */ /* This version was developed using AIMD/TSC15032-43 v0.99c Edit 60, dated 4th Nov 2015 */
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
@ -45,10 +43,12 @@
#define ULT_GFMUL(i, j) ((((i) == 0)||((j) == 0)) ? 0 : gfPwr[(gfLog[i] + gfLog[j])]) #define ULT_GFMUL(i, j) ((((i) == 0)||((j) == 0)) ? 0 : gfPwr[(gfLog[i] + gfLog[j])])
static const char ult_fragment[27][13] = {"http://", "https://", "http://www.", "https://www.", static const char *const ult_fragment[27] = {
"http://", "https://", "http://www.", "https://www.",
"ftp://", "www.", ".com", ".edu", ".gov", ".int", ".mil", ".net", ".org", "ftp://", "www.", ".com", ".edu", ".gov", ".int", ".mil", ".net", ".org",
".mobi", ".coop", ".biz", ".info", "mailto:", "tel:", ".cgi", ".asp", ".mobi", ".coop", ".biz", ".info", "mailto:", "tel:", ".cgi", ".asp",
".aspx", ".php", ".htm", ".html", ".shtml", "file:"}; ".aspx", ".php", ".htm", ".html", ".shtml", "file:"
};
static const char ult_c43_set1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .,%"; static const char ult_c43_set1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .,%";
static const char ult_c43_set2[] = "abcdefghijklmnopqrstuvwxyz:/?#[]@=_~!.,-"; static const char ult_c43_set2[] = "abcdefghijklmnopqrstuvwxyz:/?#[]@=_~!.,-";
@ -56,75 +56,75 @@ static const char ult_c43_set3[] = "{}`()\"+'<>|$;&\\^*";
static const char ult_digit[] = "0123456789,/"; static const char ult_digit[] = "0123456789,/";
static const char ult_colour[] = "0CBMRYGKW"; static const char ult_colour[] = "0CBMRYGKW";
// Max size and min cols adjusted to BWIPP values as updated 2021-07-14 /* Max size and min cols adjusted to BWIPP values as updated 2021-07-14
// https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc https://github.com/bwipp/postscriptbarcode/commit/4255810845fa8d45c6192dd30aee1fdad1aaf0cc */
static const int ult_maxsize[] = {37, 84, 161, 282}; static const int ult_maxsize[] = {37, 84, 161, 282};
static const int ult_mincols[] = {5, 13, 22, 29}; static const int ult_mincols[] = {5, 13, 22, 29};
static const int ult_kec[] = {0, 1, 2, 4, 6, 8}; // Value K(EC) from Table 12 static const int ult_kec[] = {0, 1, 2, 4, 6, 8}; /* Value K(EC) from Table 12 */
/* Taken from BWIPP - change in DCCU/DCCL tiles for revision 2 2021-09-28 */ /* Taken from BWIPP - change in DCCU/DCCL tiles for revision 2 2021-09-28 */
static const unsigned short ult_dccu[2][32] = { static const unsigned short ult_dccu[2][32] = {
{ // Revision 1 { /* Revision 1 */
051363, 051563, 051653, 053153, 053163, 053513, 053563, 053613, // 0-7 051363, 051563, 051653, 053153, 053163, 053513, 053563, 053613, /* 0-7 */
053653, 056153, 056163, 056313, 056353, 056363, 056513, 056563, // 8-15 053653, 056153, 056163, 056313, 056353, 056363, 056513, 056563, /* 8-15 */
051316, 051356, 051536, 051616, 053156, 053516, 053536, 053616, // 16-23 051316, 051356, 051536, 051616, 053156, 053516, 053536, 053616, /* 16-23 */
053636, 053656, 056136, 056156, 056316, 056356, 056516, 056536 // 24-31 053636, 053656, 056136, 056156, 056316, 056356, 056516, 056536 /* 24-31 */
}, },
{ // Revision 2 (inversion of DCCL Revision 1) { /* Revision 2 (inversion of DCCL Revision 1) */
015316, 016316, 013516, 016516, 013616, 015616, 013136, 015136, // 0-7 015316, 016316, 013516, 016516, 013616, 015616, 013136, 015136, /* 0-7 */
016136, 013536, 016536, 013636, 013156, 016156, 015356, 013656, // 8-15 016136, 013536, 016536, 013636, 013156, 016156, 015356, 013656, /* 8-15 */
015313, 016313, 013513, 016513, 013613, 015613, 013153, 015153, // 16-23 015313, 016313, 013513, 016513, 013613, 015613, 013153, 015153, /* 16-23 */
016153, 016353, 013653, 015653, 013163, 015163, 015363, 013563 // 24-31 016153, 016353, 013653, 015653, 013163, 015163, 015363, 013563 /* 24-31 */
}, },
}; };
static const unsigned short ult_dccl[2][32] = { static const unsigned short ult_dccl[2][32] = {
{ // Revision 1 { /* Revision 1 */
061351, 061361, 061531, 061561, 061631, 061651, 063131, 063151, // 0-7 061351, 061361, 061531, 061561, 061631, 061651, 063131, 063151, /* 0-7 */
063161, 063531, 063561, 063631, 065131, 065161, 065351, 065631, // 8-15 063161, 063531, 063561, 063631, 065131, 065161, 065351, 065631, /* 8-15 */
031351, 031361, 031531, 031561, 031631, 031651, 035131, 035151, // 16-23 031351, 031361, 031531, 031561, 031631, 031651, 035131, 035151, /* 16-23 */
035161, 035361, 035631, 035651, 036131, 036151, 036351, 036531 // 24-31 035161, 035361, 035631, 035651, 036131, 036151, 036351, 036531 /* 24-31 */
}, },
{ // Revision 2 (inversion of DCCU Revision 1) { /* Revision 2 (inversion of DCCU Revision 1) */
036315, 036515, 035615, 035135, 036135, 031535, 036535, 031635, // 0-7 036315, 036515, 035615, 035135, 036135, 031535, 036535, 031635, /* 0-7 */
035635, 035165, 036165, 031365, 035365, 036365, 031565, 036565, // 8-15 035635, 035165, 036165, 031365, 035365, 036365, 031565, 036565, /* 8-15 */
061315, 065315, 063515, 061615, 065135, 061535, 063535, 061635, // 16-23 061315, 065315, 063515, 061615, 065135, 061535, 063535, 061635, /* 16-23 */
063635, 065635, 063165, 065165, 061365, 065365, 061565, 063565 // 24-31 063635, 065635, 063165, 065165, 061365, 065365, 061565, 063565 /* 24-31 */
}, },
}; };
static const int ult_tiles[] = { static const int ult_tiles[] = {
013135, 013136, 013153, 013156, 013163, 013165, 013513, 013515, 013516, 013531, // 0-9 013135, 013136, 013153, 013156, 013163, 013165, 013513, 013515, 013516, 013531, /* 0-9 */
013535, 013536, 013561, 013563, 013565, 013613, 013615, 013616, 013631, 013635, // 10-19 013535, 013536, 013561, 013563, 013565, 013613, 013615, 013616, 013631, 013635, /* 10-19 */
013636, 013651, 013653, 013656, 015135, 015136, 015153, 015163, 015165, 015313, // 20-29 013636, 013651, 013653, 013656, 015135, 015136, 015153, 015163, 015165, 015313, /* 20-29 */
015315, 015316, 015351, 015353, 015356, 015361, 015363, 015365, 015613, 015615, // 30-39 015315, 015316, 015351, 015353, 015356, 015361, 015363, 015365, 015613, 015615, /* 30-39 */
015616, 015631, 015635, 015636, 015651, 015653, 015656, 016135, 016136, 016153, // 40-49 015616, 015631, 015635, 015636, 015651, 015653, 015656, 016135, 016136, 016153, /* 40-49 */
016156, 016165, 016313, 016315, 016316, 016351, 016353, 016356, 016361, 016363, // 50-59 016156, 016165, 016313, 016315, 016316, 016351, 016353, 016356, 016361, 016363, /* 50-59 */
016365, 016513, 016515, 016516, 016531, 016535, 016536, 016561, 016563, 016565, // 60-69 016365, 016513, 016515, 016516, 016531, 016535, 016536, 016561, 016563, 016565, /* 60-69 */
031315, 031316, 031351, 031356, 031361, 031365, 031513, 031515, 031516, 031531, // 70-79 031315, 031316, 031351, 031356, 031361, 031365, 031513, 031515, 031516, 031531, /* 70-79 */
031535, 031536, 031561, 031563, 031565, 031613, 031615, 031631, 031635, 031636, // 80-89 031535, 031536, 031561, 031563, 031565, 031613, 031615, 031631, 031635, 031636, /* 80-89 */
031651, 031653, 031656, 035131, 035135, 035136, 035151, 035153, 035156, 035161, // 90-99 031651, 031653, 031656, 035131, 035135, 035136, 035151, 035153, 035156, 035161, /* 90-99 */
035163, 035165, 035315, 035316, 035351, 035356, 035361, 035365, 035613, 035615, // 100-109 035163, 035165, 035315, 035316, 035351, 035356, 035361, 035365, 035613, 035615, /* 100-109 */
035616, 035631, 035635, 035636, 035651, 035653, 035656, 036131, 036135, 036136, // 110-119 035616, 035631, 035635, 035636, 035651, 035653, 035656, 036131, 036135, 036136, /* 110-119 */
036151, 036153, 036156, 036163, 036165, 036315, 036316, 036351, 036356, 036361, // 120-129 036151, 036153, 036156, 036163, 036165, 036315, 036316, 036351, 036356, 036361, /* 120-129 */
036365, 036513, 036515, 036516, 036531, 036535, 036536, 036561, 036563, 036565, // 130-139 036365, 036513, 036515, 036516, 036531, 036535, 036536, 036561, 036563, 036565, /* 130-139 */
051313, 051315, 051316, 051351, 051353, 051356, 051361, 051363, 051365, 051513, // 140-149 051313, 051315, 051316, 051351, 051353, 051356, 051361, 051363, 051365, 051513, /* 140-149 */
051516, 051531, 051536, 051561, 051563, 051613, 051615, 051616, 051631, 051635, // 150-159 051516, 051531, 051536, 051561, 051563, 051613, 051615, 051616, 051631, 051635, /* 150-159 */
051636, 051651, 051653, 051656, 053131, 053135, 053136, 053151, 053153, 053156, // 160-169 051636, 051651, 051653, 051656, 053131, 053135, 053136, 053151, 053153, 053156, /* 160-169 */
053161, 053163, 053165, 053513, 053516, 053531, 053536, 053561, 053563, 053613, // 170-179 053161, 053163, 053165, 053513, 053516, 053531, 053536, 053561, 053563, 053613, /* 170-179 */
053615, 053616, 053631, 053635, 053636, 053651, 053653, 053656, 056131, 056135, // 180-189 053615, 053616, 053631, 053635, 053636, 053651, 053653, 053656, 056131, 056135, /* 180-189 */
056136, 056151, 056153, 056156, 056161, 056163, 056165, 056313, 056315, 056316, // 190-199 056136, 056151, 056153, 056156, 056161, 056163, 056165, 056313, 056315, 056316, /* 190-199 */
056351, 056353, 056356, 056361, 056363, 056365, 056513, 056516, 056531, 056536, // 200-209 056351, 056353, 056356, 056361, 056363, 056365, 056513, 056516, 056531, 056536, /* 200-209 */
056561, 056563, 061313, 061315, 061316, 061351, 061353, 061356, 061361, 061363, // 210-219 056561, 056563, 061313, 061315, 061316, 061351, 061353, 061356, 061361, 061363, /* 210-219 */
061365, 061513, 061515, 061516, 061531, 061535, 061536, 061561, 061563, 061565, // 220-229 061365, 061513, 061515, 061516, 061531, 061535, 061536, 061561, 061563, 061565, /* 220-229 */
061615, 061631, 061635, 061651, 061653, 063131, 063135, 063136, 063151, 063153, // 230-239 061615, 061631, 061635, 061651, 061653, 063131, 063135, 063136, 063151, 063153, /* 230-239 */
063156, 063161, 063163, 063165, 063513, 063515, 063516, 063531, 063535, 063536, // 240-249 063156, 063161, 063163, 063165, 063513, 063515, 063516, 063531, 063535, 063536, /* 240-249 */
063561, 063563, 063565, 063613, 063615, 063631, 063635, 063651, 063653, 065131, // 250-259 063561, 063563, 063565, 063613, 063615, 063631, 063635, 063651, 063653, 065131, /* 250-259 */
065135, 065136, 065151, 065153, 065156, 065161, 065163, 065165, 065313, 065315, // 260-269 065135, 065136, 065151, 065153, 065156, 065161, 065163, 065165, 065313, 065315, /* 260-269 */
065316, 065351, 065353, 065356, 065361, 065363, 065365, 065613, 065615, 065631, // 270-279 065316, 065351, 065353, 065356, 065361, 065363, 065365, 065613, 065615, 065631, /* 270-279 */
065635, 065651, 065653, 056565, 051515 // 280-284 065635, 065651, 065653, 056565, 051515 /* 280-284 */
}; };
/* The following adapted from ECC283.C "RSEC codeword generator" /* The following adapted from ECC283.C "RSEC codeword generator"
@ -253,14 +253,14 @@ static float ult_look_ahead_eightbit(const unsigned char source[], const int len
int letters_encoded = 0; int letters_encoded = 0;
if (current_mode != ULT_EIGHTBIT_MODE) { if (current_mode != ULT_EIGHTBIT_MODE) {
cw[codeword_count] = 282; // Unlatch cw[codeword_count] = 282; /* Unlatch */
codeword_count += 1; codeword_count += 1;
} }
i = in_locn; i = in_locn;
while ((i < length) && (i < end_char)) { while ((i < length) && (i < end_char)) {
if ((source[i] == '[') && gs1) { if ((source[i] == '[') && gs1) {
cw[codeword_count] = 268; // FNC1 cw[codeword_count] = 268; /* FNC1 */
} else { } else {
cw[codeword_count] = source[i]; cw[codeword_count] = source[i];
} }
@ -288,15 +288,15 @@ static float ult_look_ahead_ascii(unsigned char source[], const int length, cons
int letters_encoded = 0; int letters_encoded = 0;
if (current_mode == ULT_EIGHTBIT_MODE) { if (current_mode == ULT_EIGHTBIT_MODE) {
cw[codeword_count] = 267; // Latch ASCII Submode cw[codeword_count] = 267; /* Latch ASCII Submode */
codeword_count++; codeword_count++;
} }
if (current_mode == ULT_C43_MODE) { if (current_mode == ULT_C43_MODE) {
cw[codeword_count] = 282; // Unlatch cw[codeword_count] = 282; /* Unlatch */
codeword_count++; codeword_count++;
if (symbol_mode == ULT_EIGHTBIT_MODE) { if (symbol_mode == ULT_EIGHTBIT_MODE) {
cw[codeword_count] = 267; // Latch ASCII Submode cw[codeword_count] = 267; /* Latch ASCII Submode */
codeword_count++; codeword_count++;
} }
} }
@ -346,7 +346,7 @@ static float ult_look_ahead_ascii(unsigned char source[], const int length, cons
if (!done && source[i] < 0x80) { if (!done && source[i] < 0x80) {
if ((source[i] == '[') && gs1) { if ((source[i] == '[') && gs1) {
cw[codeword_count] = 272; // FNC1 cw[codeword_count] = 272; /* FNC1 */
} else { } else {
cw[codeword_count] = source[i]; cw[codeword_count] = source[i];
} }
@ -452,60 +452,55 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
int base43_value; int base43_value;
int letters_encoded = 0; int letters_encoded = 0;
int pad; int pad;
int *subcw = (int *) z_alloca(sizeof(int) * (length + 3) * 2);
#ifndef _MSC_VER
int subcw[(length + 3) * 2];
#else
int *subcw = (int *) _alloca((length + 3) * 2 * sizeof(int));
#endif /* _MSC_VER */
if (current_mode == ULT_EIGHTBIT_MODE) { if (current_mode == ULT_EIGHTBIT_MODE) {
/* Check for permissable URL C43 macro sequences, otherwise encode directly */ /* Check for permissable URL C43 macro sequences, otherwise encode directly */
fragno = ult_find_fragment(source, length, sublocn); fragno = ult_find_fragment(source, length, sublocn);
if ((fragno == 2) || (fragno == 3)) { if ((fragno == 2) || (fragno == 3)) {
// http://www. > http:// /* http://www. > http:// */
// https://www. > https:// /* https://www. > https:// */
fragno -= 2; fragno -= 2;
} }
switch (fragno) { switch (fragno) {
case 17: // mailto: case 17: /* mailto: */
cw[codeword_count] = 276; cw[codeword_count] = 276;
sublocn += (int) strlen(ult_fragment[fragno]); sublocn += (int) strlen(ult_fragment[fragno]);
codeword_count++; codeword_count++;
break; break;
case 18: // tel: case 18: /* tel: */
cw[codeword_count] = 277; cw[codeword_count] = 277;
sublocn += (int) strlen(ult_fragment[fragno]); sublocn += (int) strlen(ult_fragment[fragno]);
codeword_count++; codeword_count++;
break; break;
case 26: // file: case 26: /* file: */
cw[codeword_count] = 278; cw[codeword_count] = 278;
sublocn += (int) strlen(ult_fragment[fragno]); sublocn += (int) strlen(ult_fragment[fragno]);
codeword_count++; codeword_count++;
break; break;
case 0: // http:// case 0: /* http:// */
cw[codeword_count] = 279; cw[codeword_count] = 279;
sublocn += (int) strlen(ult_fragment[fragno]); sublocn += (int) strlen(ult_fragment[fragno]);
codeword_count++; codeword_count++;
break; break;
case 1: // https:// case 1: /* https:// */
cw[codeword_count] = 280; cw[codeword_count] = 280;
sublocn += (int) strlen(ult_fragment[fragno]); sublocn += (int) strlen(ult_fragment[fragno]);
codeword_count++; codeword_count++;
break; break;
case 4: // ftp:// case 4: /* ftp:// */
cw[codeword_count] = 281; cw[codeword_count] = 281;
sublocn += (int) strlen(ult_fragment[fragno]); sublocn += (int) strlen(ult_fragment[fragno]);
codeword_count++; codeword_count++;
break; break;
default: default:
if (subset == 1) { if (subset == 1) {
cw[codeword_count] = 260; // C43 Compaction Submode C1 cw[codeword_count] = 260; /* C43 Compaction Submode C1 */
codeword_count++; codeword_count++;
} else if ((subset == 2) || (subset == 3)) { } else if ((subset == 2) || (subset == 3)) {
cw[codeword_count] = 266; // C43 Compaction Submode C2 cw[codeword_count] = 266; /* C43 Compaction Submode C2 */
codeword_count++; codeword_count++;
} }
break; break;
@ -513,10 +508,10 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
} else if (current_mode == ULT_ASCII_MODE) { } else if (current_mode == ULT_ASCII_MODE) {
if (subset == 1) { if (subset == 1) {
cw[codeword_count] = 278; // C43 Compaction Submode C1 cw[codeword_count] = 278; /* C43 Compaction Submode C1 */
codeword_count++; codeword_count++;
} else if ((subset == 2) || (subset == 3)) { } else if ((subset == 2) || (subset == 3)) {
cw[codeword_count] = 280; // C43 Compaction Submode C2 cw[codeword_count] = 280; /* C43 Compaction Submode C2 */
codeword_count++; codeword_count++;
} }
} }
@ -536,11 +531,11 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
if ((new_subset != subset) && ((new_subset == 1) || (new_subset == 2))) { if ((new_subset != subset) && ((new_subset == 1) || (new_subset == 2))) {
if (ult_c43_should_latch_other(source, length, sublocn, subset, gs1)) { if (ult_c43_should_latch_other(source, length, sublocn, subset, gs1)) {
subcw[subcodeword_count] = 42; // Latch to other C43 set subcw[subcodeword_count] = 42; /* Latch to other C43 set */
subcodeword_count++; subcodeword_count++;
unshift_set = new_subset; unshift_set = new_subset;
} else { } else {
subcw[subcodeword_count] = 40; // Shift to other C43 set for 1 char subcw[subcodeword_count] = 40; /* Shift to other C43 set for 1 char */
subcodeword_count++; subcodeword_count++;
subcw[subcodeword_count] = posn(new_subset == 1 ? ult_c43_set1 : ult_c43_set2, source[sublocn]); subcw[subcodeword_count] = posn(new_subset == 1 ? ult_c43_set1 : ult_c43_set2, source[sublocn]);
subcodeword_count++; subcodeword_count++;
@ -560,22 +555,23 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
subcodeword_count++; subcodeword_count++;
sublocn++; sublocn++;
} else if (subset == 3) { } else if (subset == 3) {
subcw[subcodeword_count] = 41; // Shift to set 3 subcw[subcodeword_count] = 41; /* Shift to set 3 */
subcodeword_count++; subcodeword_count++;
fragno = ult_find_fragment(source, length, sublocn); fragno = ult_find_fragment(source, length, sublocn);
if (fragno != -1 && fragno != 26) { if (fragno != -1 && fragno != 26) {
if (fragno <= 18) { if (fragno <= 18) {
subcw[subcodeword_count] = fragno; // C43 Set 3 codewords 0 to 18 subcw[subcodeword_count] = fragno; /* C43 Set 3 codewords 0 to 18 */
subcodeword_count++; subcodeword_count++;
sublocn += (int) strlen(ult_fragment[fragno]); sublocn += (int) strlen(ult_fragment[fragno]);
} else { } else {
subcw[subcodeword_count] = fragno + 17; // C43 Set 3 codewords 36 to 42 subcw[subcodeword_count] = fragno + 17; /* C43 Set 3 codewords 36 to 42 */
subcodeword_count++; subcodeword_count++;
sublocn += (int) strlen(ult_fragment[fragno]); sublocn += (int) strlen(ult_fragment[fragno]);
} }
} else { } else {
subcw[subcodeword_count] = posn(ult_c43_set3, source[sublocn]) + 19; // C43 Set 3 codewords 19 to 35 /* C43 Set 3 codewords 19 to 35 */
subcw[subcodeword_count] = posn(ult_c43_set3, source[sublocn]) + 19;
subcodeword_count++; subcodeword_count++;
sublocn++; sublocn++;
} }
@ -589,7 +585,7 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
} }
for (i = 0; i < pad; i++) { for (i = 0; i < pad; i++) {
subcw[subcodeword_count] = 42; // Latch to other C43 set used as pad subcw[subcodeword_count] = 42; /* Latch to other C43 set used as pad */
subcodeword_count++; subcodeword_count++;
} }
@ -637,16 +633,9 @@ static int ult_generate_codewords(struct zint_symbol *symbol, const unsigned cha
int fragment_length; int fragment_length;
int ascii_encoded, c43_encoded; int ascii_encoded, c43_encoded;
const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT); const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT);
unsigned char *crop_source = (unsigned char *) z_alloca(length + 1);
#ifndef _MSC_VER char *mode = (char *) z_alloca(length + 1);
unsigned char crop_source[length + 1]; int *cw_fragment = (int *) z_alloca(sizeof(int) * (length * 2 + 1));
char mode[length + 1];
int cw_fragment[length * 2 + 1];
#else
unsigned char *crop_source = (unsigned char *) _alloca(length + 1);
char *mode = (char *) _alloca(length + 1);
int *cw_fragment = (int *) _alloca((length * 2 + 1) * sizeof(int));
#endif /* _MSC_VER */
/* Check for 06 Macro Sequence and crop accordingly */ /* Check for 06 Macro Sequence and crop accordingly */
if (length >= 9 if (length >= 9
@ -655,9 +644,9 @@ static int ult_generate_codewords(struct zint_symbol *symbol, const unsigned cha
&& source[length - 2] == '\x1e' && source[length - 1] == '\x04') { && source[length - 2] == '\x1e' && source[length - 1] == '\x04') {
if (symbol_mode == ULT_EIGHTBIT_MODE) { if (symbol_mode == ULT_EIGHTBIT_MODE) {
codewords[codeword_count] = 271; // 06 Macro codewords[codeword_count] = 271; /* 06 Macro */
} else { } else {
codewords[codeword_count] = 273; // 06 Macro codewords[codeword_count] = 273; /* 06 Macro */
} }
codeword_count++; codeword_count++;
@ -714,7 +703,7 @@ static int ult_generate_codewords(struct zint_symbol *symbol, const unsigned cha
} }
} while (input_locn < crop_length); } while (input_locn < crop_length);
} else { } else {
// Force eight-bit mode /* Force eight-bit mode */
for (input_locn = 0; input_locn < crop_length; input_locn++) { for (input_locn = 0; input_locn < crop_length; input_locn++) {
mode[input_locn] = '8'; mode[input_locn] = '8';
} }
@ -726,7 +715,7 @@ static int ult_generate_codewords(struct zint_symbol *symbol, const unsigned cha
} }
if (symbol_mode == ULT_EIGHTBIT_MODE && *p_current_mode != ULT_EIGHTBIT_MODE) { if (symbol_mode == ULT_EIGHTBIT_MODE && *p_current_mode != ULT_EIGHTBIT_MODE) {
codewords[codeword_count++] = 282; // Unlatch to 8-bit mode codewords[codeword_count++] = 282; /* Unlatch to 8-bit mode */
} }
if (eci) { if (eci) {
@ -822,10 +811,10 @@ static int ult_generate_codewords_segs(struct zint_symbol *symbol, struct zint_s
} }
if (have_eci || (symbol->option_3 != ULTRA_COMPRESSION && !gs1)) { if (have_eci || (symbol->option_3 != ULTRA_COMPRESSION && !gs1)) {
// Force eight-bit mode by default as other modes are poorly documented /* Force eight-bit mode by default as other modes are poorly documented */
symbol_mode = ULT_EIGHTBIT_MODE; symbol_mode = ULT_EIGHTBIT_MODE;
} else { } else {
// Decide start character codeword (from Table 5) /* Decide start character codeword (from Table 5) */
symbol_mode = ULT_ASCII_MODE; symbol_mode = ULT_ASCII_MODE;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
if (source[i] >= 0x80) { if (source[i] >= 0x80) {
@ -839,11 +828,11 @@ static int ult_generate_codewords_segs(struct zint_symbol *symbol, struct zint_s
/* Reader Initialisation mode */ /* Reader Initialisation mode */
codeword_count = 2; codeword_count = 2;
if (symbol_mode == ULT_ASCII_MODE) { if (symbol_mode == ULT_ASCII_MODE) {
codewords[0] = 272; // 7-bit ASCII mode codewords[0] = 272; /* 7-bit ASCII mode */
codewords[1] = 271; // FNC3 codewords[1] = 271; /* FNC3 */
} else { } else {
codewords[0] = 257; // 8859-1 codewords[0] = 257; /* 8859-1 */
codewords[1] = 269; // FNC3 codewords[1] = 269; /* FNC3 */
} }
} else { } else {
/* Calculate start character codeword */ /* Calculate start character codeword */
@ -856,52 +845,52 @@ static int ult_generate_codewords_segs(struct zint_symbol *symbol, struct zint_s
} }
} else { } else {
if ((eci >= 3) && (eci <= 18) && (eci != 14)) { if ((eci >= 3) && (eci <= 18) && (eci != 14)) {
// ECI indicates use of character set within ISO/IEC 8859 /* ECI indicates use of character set within ISO/IEC 8859 */
codewords[0] = 257 + (eci - 3); codewords[0] = 257 + (eci - 3);
if (codewords[0] > 267) { if (codewords[0] > 267) {
// Avoids ECI 14 for non-existant ISO/IEC 8859-12 /* Avoids ECI 14 for non-existant ISO/IEC 8859-12 */
codewords[0]--; codewords[0]--;
} }
} else if ((eci > 18) && (eci <= 898)) { } else if ((eci > 18) && (eci <= 898)) {
// ECI indicates use of character set outside ISO/IEC 8859 /* ECI indicates use of character set outside ISO/IEC 8859 */
codewords[0] = 275 + (eci / 256); codewords[0] = 275 + (eci / 256);
codewords[1] = eci % 256; codewords[1] = eci % 256;
codeword_count = 2; codeword_count = 2;
} else if (eci == 899) { } else if (eci == 899) {
// Non-language byte data /* Non-language byte data */
codewords[0] = 280; codewords[0] = 280;
} else if ((eci > 899) && (eci <= 9999)) { } else if ((eci > 899) && (eci <= 9999)) {
// ECI beyond 899 needs to use fixed length encodable ECI invocation (section 7.6.2) /* ECI beyond 899 needs to use fixed length encodable ECI invocation (section 7.6.2) */
// Encode as 3 codewords /* Encode as 3 codewords */
codewords[0] = 257; // ISO/IEC 8859-1 used to enter 8-bit mode codewords[0] = 257; /* ISO/IEC 8859-1 used to enter 8-bit mode */
codewords[1] = 274; // Encode ECI as 3 codewords codewords[1] = 274; /* Encode ECI as 3 codewords */
codewords[2] = (eci / 100) + 128; codewords[2] = (eci / 100) + 128;
codewords[3] = (eci % 100) + 128; codewords[3] = (eci % 100) + 128;
codeword_count = 4; codeword_count = 4;
} else if (eci >= 10000) { } else if (eci >= 10000) {
// Encode as 4 codewords /* Encode as 4 codewords */
codewords[0] = 257; // ISO/IEC 8859-1 used to enter 8-bit mode codewords[0] = 257; /* ISO/IEC 8859-1 used to enter 8-bit mode */
codewords[1] = 275; // Encode ECI as 4 codewords codewords[1] = 275; /* Encode ECI as 4 codewords */
codewords[2] = (eci / 10000) + 128; codewords[2] = (eci / 10000) + 128;
codewords[3] = ((eci % 10000) / 100) + 128; codewords[3] = ((eci % 10000) / 100) + 128;
codewords[4] = (eci % 100) + 128; codewords[4] = (eci % 100) + 128;
codeword_count = 5; codeword_count = 5;
} else { } else {
codewords[0] = 257; // Default is assumed to be ISO/IEC 8859-1 (ECI 3) codewords[0] = 257; /* Default is assumed to be ISO/IEC 8859-1 (ECI 3) */
} }
} }
if ((codewords[0] == 257) || (codewords[0] == 272)) { if ((codewords[0] == 257) || (codewords[0] == 272)) {
int fragno = ult_find_fragment(source, length, 0); int fragno = ult_find_fragment(source, length, 0);
// Check for http:// at start of input /* Check for http:// at start of input */
if ((fragno == 0) || (fragno == 2)) { if ((fragno == 0) || (fragno == 2)) {
codewords[0] = 281; codewords[0] = 281;
source += 7; source += 7;
length -= 7; length -= 7;
symbol_mode = ULT_EIGHTBIT_MODE; symbol_mode = ULT_EIGHTBIT_MODE;
// Check for https:// at start of input /* Check for https:// at start of input */
} else if ((fragno == 1) || (fragno == 3)) { } else if ((fragno == 1) || (fragno == 3)) {
codewords[0] = 282; codewords[0] = 282;
source += 8; source += 8;
@ -933,7 +922,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
int total_cws; int total_cws;
int pads; int pads;
int cw_memalloc; int cw_memalloc;
// 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 codeword[282 + 3];
int i, j, locn; int i, j, locn;
int total_height, total_width; int total_height, total_width;
@ -942,10 +931,8 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
int dcc; int dcc;
int revision_idx = 0; int revision_idx = 0;
const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT); const int debug_print = (symbol->debug & ZINT_DEBUG_PRINT);
#ifdef _MSC_VER
int *data_codewords; int *data_codewords;
char *pattern; char *pattern;
#endif /* _MSC_VER */
(void)seg_count; (void)seg_count;
@ -1002,11 +989,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
cw_memalloc = 283; cw_memalloc = 283;
} }
#ifndef _MSC_VER data_codewords = (int *) z_alloca(sizeof(int) * cw_memalloc);
int data_codewords[cw_memalloc];
#else
data_codewords = (int *) _alloca(cw_memalloc * sizeof(int));
#endif /* _MSC_VER */
data_cw_count = ult_generate_codewords_segs(symbol, segs, seg_count, data_codewords); data_cw_count = ult_generate_codewords_segs(symbol, segs, seg_count, data_codewords);
@ -1023,7 +1006,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
} }
#endif #endif
data_cw_count += 2 + scr_cw_count; // 2 == MCC + ACC (data codeword count includes start char) data_cw_count += 2 + scr_cw_count; /* 2 == MCC + ACC (data codeword count includes start char) */
if (symbol->option_2 > 0) { if (symbol->option_2 > 0) {
if (symbol->option_2 > 2) { if (symbol->option_2 > 2) {
@ -1073,7 +1056,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
} }
/* Maximum capacity is 282 codewords */ /* Maximum capacity is 282 codewords */
total_cws = data_cw_count + qcc + 3; // 3 == TCC pattern + RSEC pattern + QCC pattern total_cws = data_cw_count + qcc + 3; /* 3 == TCC pattern + RSEC pattern + QCC pattern */
if (total_cws - 3 > 282) { if (total_cws - 3 > 282) {
strcpy(symbol->errtxt, "591: Data too long for selected error correction capacity"); strcpy(symbol->errtxt, "591: Data too long for selected error correction capacity");
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;
@ -1081,7 +1064,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
rows = 5; rows = 5;
for (i = 2; i >= 0; i--) { for (i = 2; i >= 0; i--) {
// Total codewords less 6 (+ SCR) overhead (Start + MCC + ACC (+ SCR) + 3 TCC/RSEC/QCC patterns) /* Total codewords less 6 (+ SCR) overhead (Start + MCC + ACC (+ SCR) + 3 TCC/RSEC/QCC patterns) */
if (total_cws - (6 + scr_cw_count) <= ult_maxsize[i]) { if (total_cws - (6 + scr_cw_count) <= ult_maxsize[i]) {
rows--; rows--;
} }
@ -1094,7 +1077,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
pads = rows - (total_cws % rows); pads = rows - (total_cws % rows);
columns = (total_cws / rows) + 1; columns = (total_cws / rows) + 1;
} }
columns += columns / 15; // Secondary vertical clock tracks columns += columns / 15; /* Secondary vertical clock tracks */
if (debug_print) { if (debug_print) {
printf("Calculated size is %d rows by %d columns (pads %d)\n", rows, columns, pads); printf("Calculated size is %d rows by %d columns (pads %d)\n", rows, columns, pads);
@ -1104,9 +1087,9 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
for (i = 282; i > 2 + scr_cw_count; i--) { for (i = 282; i > 2 + scr_cw_count; i--) {
data_codewords[i] = data_codewords[i - (2 + scr_cw_count)]; data_codewords[i] = data_codewords[i - (2 + scr_cw_count)];
} }
data_codewords[1] = data_cw_count; // MCC data_codewords[1] = data_cw_count; /* MCC */
data_codewords[2] = acc; // ACC data_codewords[2] = acc; /* ACC */
for (i = 0; i < scr_cw_count; i++) { // SCR for (i = 0; i < scr_cw_count; i++) { /* SCR */
data_codewords[3 + i] = scr[i]; data_codewords[3 + i] = scr[i];
} }
@ -1124,25 +1107,25 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
/* Rearrange to make final codeword sequence */ /* Rearrange to make final codeword sequence */
locn = 0; locn = 0;
codeword[locn++] = data_codewords[282 - (data_cw_count + qcc)]; // Start Character codeword[locn++] = data_codewords[282 - (data_cw_count + qcc)]; /* Start Character */
codeword[locn++] = data_cw_count; // MCC codeword[locn++] = data_cw_count; /* MCC */
for (i = 0; i < qcc; i++) { for (i = 0; i < qcc; i++) {
codeword[locn++] = data_codewords[(282 - qcc) + i]; // RSEC Region codeword[locn++] = data_codewords[(282 - qcc) + i]; /* RSEC Region */
} }
codeword[locn++] = data_cw_count + qcc; // TCC = C + Q - section 6.11.4 codeword[locn++] = data_cw_count + qcc; /* TCC = C + Q - section 6.11.4 */
codeword[locn++] = 283; // Separator codeword[locn++] = 283; /* Separator */
codeword[locn++] = acc; // ACC codeword[locn++] = acc; /* ACC */
for (i = 0; i < scr_cw_count; i++) { // SCR for (i = 0; i < scr_cw_count; i++) { /* SCR */
codeword[locn++] = scr[i]; codeword[locn++] = scr[i];
} }
dr_count = data_cw_count - (3 + scr_cw_count); dr_count = data_cw_count - (3 + scr_cw_count);
for (i = 0; i < dr_count; i++) { for (i = 0; i < dr_count; i++) {
codeword[locn++] = data_codewords[(282 - (dr_count + qcc)) + i]; // Data Region codeword[locn++] = data_codewords[(282 - (dr_count + qcc)) + i]; /* Data Region */
} }
for (i = 0; i < pads; i++) { for (i = 0; i < pads; i++) {
codeword[locn++] = 284; // Pad pattern codeword[locn++] = 284; /* Pad pattern */
} }
codeword[locn++] = qcc; // QCC codeword[locn++] = qcc; /* QCC */
if (debug_print) { if (debug_print) {
printf("Rearranged codewords with ECC:\n"); printf("Rearranged codewords with ECC:\n");
@ -1156,11 +1139,7 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
total_width = columns + 6; total_width = columns + 6;
/* Build symbol */ /* Build symbol */
#ifndef _MSC_VER pattern = (char *) z_alloca(total_height * total_width);
char pattern[total_height * total_width];
#else
pattern = (char *) _alloca(total_height * total_width);
#endif /* _MSC_VER */
for (i = 0; i < (total_height * total_width); i++) { for (i = 0; i < (total_height * total_width); i++) {
pattern[i] = 'W'; pattern[i] = 'W';
@ -1168,31 +1147,31 @@ INTERNAL int ultra(struct zint_symbol *symbol, struct zint_seg segs[], const int
/* Border */ /* Border */
for (i = 0; i < total_width; i++) { for (i = 0; i < total_width; i++) {
pattern[i] = 'K'; // Top pattern[i] = 'K'; /* Top */
pattern[(total_height * total_width) - i - 1] = 'K'; // Bottom pattern[(total_height * total_width) - i - 1] = 'K'; /* Bottom */
} }
for (i = 0; i < total_height; i++) { for (i = 0; i < total_height; i++) {
pattern[total_width * i] = 'K'; // Left pattern[total_width * i] = 'K'; /* Left */
pattern[(total_width * i) + 3] = 'K'; pattern[(total_width * i) + 3] = 'K';
pattern[(total_width * i) + (total_width - 1)] = 'K'; // Right pattern[(total_width * i) + (total_width - 1)] = 'K'; /* Right */
} }
/* Clock tracks */ /* Clock tracks */
for (i = 0; i < total_height; i += 2) { for (i = 0; i < total_height; i += 2) {
pattern[(total_width * i) + 1] = 'K'; // Primary vertical clock track pattern[(total_width * i) + 1] = 'K'; /* Primary vertical clock track */
if (total_width > 20) { if (total_width > 20) {
pattern[(total_width * i) + 19] = 'K'; // Secondary vertical clock track pattern[(total_width * i) + 19] = 'K'; /* Secondary vertical clock track */
} }
if (total_width > 36) { if (total_width > 36) {
pattern[(total_width * i) + 35] = 'K'; // Secondary vertical clock track pattern[(total_width * i) + 35] = 'K'; /* Secondary vertical clock track */
} }
if (total_width > 52) { if (total_width > 52) {
pattern[(total_width * i) + 51] = 'K'; // Secondary vertical clock track pattern[(total_width * i) + 51] = 'K'; /* Secondary vertical clock track */
} }
} }
for (i = 6; i < total_height; i += 6) { for (i = 6; i < total_height; i += 6) {
for (j = 5; j < total_width; j += 2) { for (j = 5; j < total_width; j += 2) {
pattern[(total_width * i) + j] = 'K'; // Horizontal clock track pattern[(total_width * i) + j] = 'K'; /* Horizontal clock track */
} }
} }

View File

@ -1,7 +1,7 @@
/* upcean.c - Handles UPC, EAN and ISBN /* upcean.c - Handles UPC, EAN and ISBN */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2008 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2008-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,7 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#define SODIUM_PLS_F (IS_NUM_F | IS_PLS_F) /* SODIUM "0123456789+" */ #define SODIUM_PLS_F (IS_NUM_F | IS_PLS_F) /* SODIUM "0123456789+" */
#define ISBNX_SANE_F (IS_NUM_F | IS_UX__F) /* ISBNX_SANE "0123456789X" */ #define ISBNX_SANE_F (IS_NUM_F | IS_UX__F) /* ISBNX_SANE "0123456789X" */
@ -228,7 +228,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
equivalent[10] = source[4]; equivalent[10] = source[4];
if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) { if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) {
/* Note 1 - "X3 shall not be equal to 0, 1 or 2" */ /* Note 1 - "X3 shall not be equal to 0, 1 or 2" */
strcpy(symbol->errtxt, "271: Invalid UPC-E data"); // TODO: Better error message strcpy(symbol->errtxt, "271: Invalid UPC-E data"); /* TODO: Better error message */
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
break; break;
@ -238,7 +238,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
equivalent[10] = source[4]; equivalent[10] = source[4];
if (source[3] == '0') { if (source[3] == '0') {
/* Note 2 - "X4 shall not be equal to 0" */ /* Note 2 - "X4 shall not be equal to 0" */
strcpy(symbol->errtxt, "272: Invalid UPC-E data"); // TODO: Better error message strcpy(symbol->errtxt, "272: Invalid UPC-E data"); /* TODO: Better error message */
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
break; break;
@ -253,7 +253,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
equivalent[10] = emode; equivalent[10] = emode;
if (source[4] == '0') { if (source[4] == '0') {
/* Note 3 - "X5 shall not be equal to 0" */ /* Note 3 - "X5 shall not be equal to 0" */
strcpy(symbol->errtxt, "273: Invalid UPC-E data"); // TODO: Better error message strcpy(symbol->errtxt, "273: Invalid UPC-E data"); /* TODO: Better error message */
return ZINT_ERROR_INVALID_DATA; return ZINT_ERROR_INVALID_DATA;
} }
break; break;
@ -984,3 +984,5 @@ INTERNAL int eanx_cc(struct zint_symbol *symbol, unsigned char source[], int src
INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) { INTERNAL int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len) {
return eanx_cc(symbol, source, src_len, 0 /*cc_rows*/); return eanx_cc(symbol, source, src_len, 0 /*cc_rows*/);
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,7 +1,7 @@
/* vector.c - Creates vector image objects /* vector.c - Creates vector image objects */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2018 - 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2018-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,11 +28,7 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#ifdef _MSC_VER
#include <malloc.h>
#endif
#include "common.h" #include "common.h"
#include "output.h" #include "output.h"
@ -57,7 +53,7 @@ static struct zint_vector_rect *vector_plot_create_rect(struct zint_symbol *symb
rect->y = y; rect->y = y;
rect->width = width; rect->width = width;
rect->height = height; rect->height = height;
rect->colour = -1; // Default colour rect->colour = -1; /* Default colour */
return rect; return rect;
} }
@ -67,7 +63,7 @@ static void vector_plot_add_rect(struct zint_symbol *symbol, struct zint_vector_
if (*last_rect) if (*last_rect)
(*last_rect)->next = rect; (*last_rect)->next = rect;
else else
symbol->vector->rectangles = rect; // first rectangle symbol->vector->rectangles = rect; /* first rectangle */
*last_rect = rect; *last_rect = rect;
} }
@ -95,7 +91,7 @@ static void vector_plot_add_hexagon(struct zint_symbol *symbol, struct zint_vect
if (*last_hexagon) if (*last_hexagon)
(*last_hexagon)->next = hexagon; (*last_hexagon)->next = hexagon;
else else
symbol->vector->hexagons = hexagon; // first hexagon symbol->vector->hexagons = hexagon; /* first hexagon */
*last_hexagon = hexagon; *last_hexagon = hexagon;
} }
@ -125,7 +121,7 @@ static void vector_plot_add_circle(struct zint_symbol *symbol, struct zint_vecto
if (*last_circle) if (*last_circle)
(*last_circle)->next = circle; (*last_circle)->next = circle;
else else
symbol->vector->circles = circle; // first circle symbol->vector->circles = circle; /* first circle */
*last_circle = circle; *last_circle = circle;
} }
@ -159,7 +155,7 @@ static int vector_plot_add_string(struct zint_symbol *symbol, const unsigned cha
if (*last_string) if (*last_string)
(*last_string)->next = string; (*last_string)->next = string;
else else
symbol->vector->strings = string; // First text portion symbol->vector->strings = string; /* First text portion */
*last_string = string; *last_string = string;
return 1; return 1;
@ -172,7 +168,7 @@ INTERNAL void vector_free(struct zint_symbol *symbol) {
struct zint_vector_circle *circle; struct zint_vector_circle *circle;
struct zint_vector_string *string; struct zint_vector_string *string;
// Free Rectangles /* Free Rectangles */
rect = symbol->vector->rectangles; rect = symbol->vector->rectangles;
while (rect) { while (rect) {
struct zint_vector_rect *r = rect; struct zint_vector_rect *r = rect;
@ -180,7 +176,7 @@ INTERNAL void vector_free(struct zint_symbol *symbol) {
free(r); free(r);
} }
// Free Hexagons /* Free Hexagons */
hex = symbol->vector->hexagons; hex = symbol->vector->hexagons;
while (hex) { while (hex) {
struct zint_vector_hexagon *h = hex; struct zint_vector_hexagon *h = hex;
@ -188,7 +184,7 @@ INTERNAL void vector_free(struct zint_symbol *symbol) {
free(h); free(h);
} }
// Free Circles /* Free Circles */
circle = symbol->vector->circles; circle = symbol->vector->circles;
while (circle) { while (circle) {
struct zint_vector_circle *c = circle; struct zint_vector_circle *c = circle;
@ -196,7 +192,7 @@ INTERNAL void vector_free(struct zint_symbol *symbol) {
free(c); free(c);
} }
// Free Strings /* Free Strings */
string = symbol->vector->strings; string = symbol->vector->strings;
while (string) { while (string) {
struct zint_vector_string *s = string; struct zint_vector_string *s = string;
@ -205,7 +201,7 @@ INTERNAL void vector_free(struct zint_symbol *symbol) {
free(s); free(s);
} }
// Free vector /* Free vector */
free(symbol->vector); free(symbol->vector);
symbol->vector = NULL; symbol->vector = NULL;
} }
@ -218,12 +214,12 @@ static void vector_scale(struct zint_symbol *symbol, const int file_type) {
struct zint_vector_string *string; struct zint_vector_string *string;
float scale = symbol->scale * 2.0f; float scale = symbol->scale * 2.0f;
if (scale < 0.2f) { // Minimum vector scale 0.1 if (scale < 0.2f) { /* Minimum vector scale 0.1 */
scale = 0.2f; scale = 0.2f;
} }
if ((file_type == OUT_EMF_FILE) && (symbol->symbology == BARCODE_MAXICODE)) { if ((file_type == OUT_EMF_FILE) && (symbol->symbology == BARCODE_MAXICODE)) {
// Increase size to overcome limitations in EMF file format /* Increase size to overcome limitations in EMF file format */
scale *= 20; scale *= 20;
} }
@ -267,7 +263,7 @@ static void vector_scale(struct zint_symbol *symbol, const int file_type) {
} }
static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) { static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
// Rotates the image /* Rotates the image */
struct zint_vector_rect *rect; struct zint_vector_rect *rect;
struct zint_vector_hexagon *hex; struct zint_vector_hexagon *hex;
struct zint_vector_circle *circle; struct zint_vector_circle *circle;
@ -275,7 +271,7 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
float temp; float temp;
if (rotate_angle == 0) { if (rotate_angle == 0) {
// No rotation needed /* No rotation needed */
return; return;
} }
@ -367,7 +363,7 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
} }
static void vector_reduce_rectangles(struct zint_symbol *symbol) { static void vector_reduce_rectangles(struct zint_symbol *symbol) {
// Looks for vertically aligned rectangles and merges them together /* Looks for vertically aligned rectangles and merges them together */
struct zint_vector_rect *rect, *target, *prev; struct zint_vector_rect *rect, *target, *prev;
rect = symbol->vector->rectangles; rect = symbol->vector->rectangles;
@ -425,16 +421,16 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
struct zint_vector_string *last_string = NULL; struct zint_vector_string *last_string = NULL;
struct zint_vector_circle *circle, *last_circle = NULL; struct zint_vector_circle *circle, *last_circle = NULL;
// Free any previous rendering structures /* Free any previous rendering structures */
vector_free(symbol); vector_free(symbol);
// Sanity check colours /* Sanity check colours */
error_number = out_check_colour_options(symbol); error_number = out_check_colour_options(symbol);
if (error_number != 0) { if (error_number != 0) {
return error_number; return error_number;
} }
// Allocate memory /* 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) { if (!vector) {
strcpy(symbol->errtxt, "696: Insufficient memory for vector header"); strcpy(symbol->errtxt, "696: Insufficient memory for vector header");
@ -503,7 +499,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
vector->width = symbol->width + dot_overspill + (xoffset + roffset); vector->width = symbol->width + dot_overspill + (xoffset + roffset);
vector->height = symbol->height + textoffset + dot_overspill + (yoffset + boffset); vector->height = symbol->height + textoffset + dot_overspill + (yoffset + boffset);
// Plot Maxicode symbols /* Plot Maxicode symbols */
if (symbol->symbology == BARCODE_MAXICODE) { if (symbol->symbology == BARCODE_MAXICODE) {
float bull_x, bull_y, bull_d_incr, bull_width; float bull_x, bull_y, bull_d_incr, bull_width;
const float two_div_sqrt3 = 1.1547f; /* 2 / √3 */ const float two_div_sqrt3 = 1.1547f; /* 2 / √3 */
@ -520,7 +516,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
/* 32 rows drawn yposn_offset apart + final hexagon */ /* 32 rows drawn yposn_offset apart + final hexagon */
vector->height = 32 * yposn_offset + hex_ydiameter + (yoffset + boffset); vector->height = 32 * yposn_offset + hex_ydiameter + (yoffset + boffset);
// Bullseye (ISO/IEC 16023:2000 4.2.1.1 and 4.11.4) /* Bullseye (ISO/IEC 16023:2000 4.2.1.1 and 4.11.4) */
bull_x = 14.5f * hex_diameter + xoffset; /* 14W right from leftmost centre = 14.5X */ bull_x = 14.5f * hex_diameter + xoffset; /* 14W right from leftmost centre = 14.5X */
bull_y = vector->height / 2.0f; /* 16Y above bottom-most centre = halfway */ bull_y = vector->height / 2.0f; /* 16Y above bottom-most centre = halfway */
/* Total finder diameter is 9X, so diametric increment for 5 diameters d2 to d6 is (9X - d1) / 5 */ /* Total finder diameter is 9X, so diametric increment for 5 diameters d2 to d6 is (9X - d1) / 5 */
@ -554,7 +550,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
} }
} }
} }
// Dotty mode /* Dotty mode */
} else if (symbol->output_options & BARCODE_DOTTY_MODE) { } else if (symbol->output_options & BARCODE_DOTTY_MODE) {
for (r = 0; r < symbol->rows; r++) { for (r = 0; r < symbol->rows; r++) {
for (i = 0; i < symbol->width; i++) { for (i = 0; i < symbol->width; i++) {
@ -566,7 +562,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
} }
} }
} }
// Plot rectangles - most symbols created here /* Plot rectangles - most symbols created here */
} else if (symbol->symbology == BARCODE_ULTRA) { } else if (symbol->symbology == BARCODE_ULTRA) {
yposn = yoffset; yposn = yoffset;
for (r = 0; r < symbol->rows; r++) { for (r = 0; r < symbol->rows; r++) {
@ -845,16 +841,16 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
} }
} else { } else {
/* Put normal human readable text at the bottom (and centered) */ /* Put normal human readable text at the bottom (and centered) */
// calculate start xoffset to center text /* calculate start xoffset to center text */
text_xposn = main_width / 2.0f + xoffset; text_xposn = main_width / 2.0f + xoffset;
if (!vector_plot_add_string(symbol, symbol->text, text_xposn, text_yposn, if (!vector_plot_add_string(symbol, symbol->text, text_xposn, text_yposn,
text_height, symbol->width, 0, &last_string)) return ZINT_ERROR_MEMORY; text_height, symbol->width, 0, &last_string)) return ZINT_ERROR_MEMORY;
} }
xoffset -= comp_xoffset; // Restore xoffset xoffset -= comp_xoffset; /* Restore xoffset */
} }
// Separator binding for stacked barcodes /* Separator binding for stacked barcodes */
if ((symbol->output_options & BARCODE_BIND) && (symbol->rows > 1) && is_stackable(symbol->symbology)) { if ((symbol->output_options & BARCODE_BIND) && (symbol->rows > 1) && is_stackable(symbol->symbology)) {
float sep_xoffset = xoffset; float sep_xoffset = xoffset;
float sep_width = symbol->width; float sep_width = symbol->width;
@ -877,17 +873,17 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
} }
} }
// Bind/box /* Bind/box */
if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND))) { if (symbol->border_width > 0 && (symbol->output_options & (BARCODE_BOX | BARCODE_BIND))) {
const int horz_outside = is_fixed_ratio(symbol->symbology); const int horz_outside = is_fixed_ratio(symbol->symbology);
float ybind_top = yoffset - symbol->border_width; float ybind_top = yoffset - symbol->border_width;
// Following equivalent to yoffset + symbol->height + dot_overspill except for BARCODE_MAXICODE /* Following equivalent to yoffset + symbol->height + dot_overspill except for BARCODE_MAXICODE */
float ybind_bot = vector->height - textoffset - boffset; float ybind_bot = vector->height - textoffset - boffset;
if (horz_outside) { if (horz_outside) {
ybind_top = 0; ybind_top = 0;
ybind_bot = vector->height - symbol->border_width; ybind_bot = vector->height - symbol->border_width;
} }
// Top /* Top */
rect = vector_plot_create_rect(symbol, 0.0f, ybind_top, vector->width, symbol->border_width); rect = vector_plot_create_rect(symbol, 0.0f, ybind_top, vector->width, symbol->border_width);
if (!rect) return ZINT_ERROR_MEMORY; if (!rect) return ZINT_ERROR_MEMORY;
if (!(symbol->output_options & BARCODE_BOX) if (!(symbol->output_options & BARCODE_BOX)
@ -897,7 +893,7 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
rect->width -= xoffset + roffset; rect->width -= xoffset + roffset;
} }
vector_plot_add_rect(symbol, rect, &last_rectangle); vector_plot_add_rect(symbol, rect, &last_rectangle);
// Bottom /* Bottom */
rect = vector_plot_create_rect(symbol, 0.0f, ybind_bot, vector->width, symbol->border_width); rect = vector_plot_create_rect(symbol, 0.0f, ybind_bot, vector->width, symbol->border_width);
if (!rect) return ZINT_ERROR_MEMORY; if (!rect) return ZINT_ERROR_MEMORY;
if (!(symbol->output_options & BARCODE_BOX) if (!(symbol->output_options & BARCODE_BOX)
@ -910,17 +906,17 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
if (symbol->output_options & BARCODE_BOX) { if (symbol->output_options & BARCODE_BOX) {
const float xbox_right = vector->width - symbol->border_width; const float xbox_right = vector->width - symbol->border_width;
float box_top = yoffset; float box_top = yoffset;
// Following equivalent to symbol->height except for BARCODE_MAXICODE /* Following equivalent to symbol->height except for BARCODE_MAXICODE */
float box_height = vector->height - textoffset - dot_overspill - yoffset - boffset; float box_height = vector->height - textoffset - dot_overspill - yoffset - boffset;
if (horz_outside) { if (horz_outside) {
box_top = symbol->border_width; box_top = symbol->border_width;
box_height = vector->height - symbol->border_width * 2; box_height = vector->height - symbol->border_width * 2;
} }
// Left /* Left */
rect = vector_plot_create_rect(symbol, 0.0f, box_top, symbol->border_width, box_height); rect = vector_plot_create_rect(symbol, 0.0f, box_top, symbol->border_width, box_height);
if (!rect) return ZINT_ERROR_MEMORY; if (!rect) return ZINT_ERROR_MEMORY;
vector_plot_add_rect(symbol, rect, &last_rectangle); vector_plot_add_rect(symbol, rect, &last_rectangle);
// Right /* Right */
rect = vector_plot_create_rect(symbol, xbox_right, box_top, symbol->border_width, box_height); rect = vector_plot_create_rect(symbol, xbox_right, box_top, symbol->border_width, box_height);
if (!rect) return ZINT_ERROR_MEMORY; if (!rect) return ZINT_ERROR_MEMORY;
vector_plot_add_rect(symbol, rect, &last_rectangle); vector_plot_add_rect(symbol, rect, &last_rectangle);
@ -951,3 +947,5 @@ INTERNAL int plot_vector(struct zint_symbol *symbol, int rotate_angle, int file_
return error_number; return error_number;
} }
/* vim: set ts=4 sw=4 et : */

View File

@ -1,7 +1,7 @@
/* filetypes.h - file type flags /* filetypes.h - file type flags */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2021 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2021-2022 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -28,12 +28,12 @@
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* vim: set ts=4 sw=4 et : */ /* SPDX-License-Identifier: BSD-3-Clause */
#ifndef ZFILETYPES_H #ifndef Z_ZFILETYPES_H
#define ZFILETYPES_H #define Z_ZFILETYPES_H
// File types /* File types */
#define OUT_BUFFER 0 #define OUT_BUFFER 0
#define OUT_SVG_FILE 10 #define OUT_SVG_FILE 10
#define OUT_EPS_FILE 20 #define OUT_EPS_FILE 20
@ -45,4 +45,5 @@
#define OUT_JPG_FILE 180 #define OUT_JPG_FILE 180
#define OUT_TIF_FILE 200 #define OUT_TIF_FILE 200
#endif /* ZFILETYPES_H */ /* vim: set ts=4 sw=4 et : */
#endif /* Z_ZFILETYPES_H */

View File

@ -1,5 +1,5 @@
/* zint.h - definitions for libzint /* zint.h - definitions for libzint */
/*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2009-2022 Robin Stuart <rstuart114@gmail.com>
@ -29,6 +29,7 @@
SUCH DAMAGE. SUCH DAMAGE.
*/ */
/* SPDX-License-Identifier: BSD-3-Clause */ /* SPDX-License-Identifier: BSD-3-Clause */
/* /*
* For version, see "zintconfig.h" * For version, see "zintconfig.h"
* For documentation, see "../docs/manual.txt" * For documentation, see "../docs/manual.txt"

View File

@ -52,7 +52,6 @@ HEADERS += ../backend/aztec.h \
../backend/ksx1001.h \ ../backend/ksx1001.h \
../backend/large.h \ ../backend/large.h \
../backend/maxicode.h \ ../backend/maxicode.h \
../backend/ms_stdint.h \
../backend/output.h \ ../backend/output.h \
../backend/pcx.h \ ../backend/pcx.h \
../backend/pdf417.h \ ../backend/pdf417.h \
@ -62,7 +61,6 @@ HEADERS += ../backend/aztec.h \
../backend/reedsol_logs.h \ ../backend/reedsol_logs.h \
../backend/rss.h \ ../backend/rss.h \
../backend/sjis.h \ ../backend/sjis.h \
../backend/stdint_msvc.h \
../backend/tif.h \ ../backend/tif.h \
../backend/tif_lzw.h \ ../backend/tif_lzw.h \
../backend/zfiletypes.h \ ../backend/zfiletypes.h \

View File

@ -39,7 +39,6 @@ HEADERS += ../backend/aztec.h \
../backend/hanxin.h \ ../backend/hanxin.h \
../backend/large.h \ ../backend/large.h \
../backend/maxicode.h \ ../backend/maxicode.h \
../backend/ms_stdint.h \
../backend/output.h \ ../backend/output.h \
../backend/pcx.h \ ../backend/pcx.h \
../backend/pdf417.h \ ../backend/pdf417.h \

674
frontend/COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -29,6 +29,9 @@
*/ */
#include "testcommon.h" #include "testcommon.h"
#ifndef _WIN32
#include <sys/wait.h>
#endif
#ifdef _WIN32 #ifdef _WIN32
/* Hacks to stop popen() mangling input on Windows */ /* Hacks to stop popen() mangling input on Windows */

674
frontend_qt/COPYING Normal file
View File

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -199,7 +199,6 @@
<ClInclude Include="..\backend\ksx1001.h" /> <ClInclude Include="..\backend\ksx1001.h" />
<ClInclude Include="..\backend\large.h" /> <ClInclude Include="..\backend\large.h" />
<ClInclude Include="..\backend\maxicode.h" /> <ClInclude Include="..\backend\maxicode.h" />
<ClInclude Include="..\backend\ms_stdint.h" />
<ClInclude Include="..\backend\output.h" /> <ClInclude Include="..\backend\output.h" />
<ClInclude Include="..\backend\pcx.h" /> <ClInclude Include="..\backend\pcx.h" />
<ClInclude Include="..\backend\pdf417.h" /> <ClInclude Include="..\backend\pdf417.h" />
@ -209,7 +208,6 @@
<ClInclude Include="..\backend\reedsol_logs.h" /> <ClInclude Include="..\backend\reedsol_logs.h" />
<ClInclude Include="..\backend\rss.h" /> <ClInclude Include="..\backend\rss.h" />
<ClInclude Include="..\backend\sjis.h" /> <ClInclude Include="..\backend\sjis.h" />
<ClInclude Include="..\backend\stdint_msvc.h" />
<ClInclude Include="..\backend\tif.h" /> <ClInclude Include="..\backend\tif.h" />
<ClInclude Include="..\backend\tif_lzw.h" /> <ClInclude Include="..\backend\tif_lzw.h" />
<ClInclude Include="..\backend\zfiletypes.h" /> <ClInclude Include="..\backend\zfiletypes.h" />

View File

@ -573,10 +573,6 @@
RelativePath="..\backend\maxicode.h" RelativePath="..\backend\maxicode.h"
> >
</File> </File>
<File
RelativePath="..\backend\ms_stdint.h"
>
</File>
<File <File
RelativePath="..\backend\output.h" RelativePath="..\backend\output.h"
> >
@ -613,10 +609,6 @@
RelativePath="..\backend\sjis.h" RelativePath="..\backend\sjis.h"
> >
</File> </File>
<File
RelativePath="..\backend\stdint_msvc.h"
>
</File>
<File <File
RelativePath="..\backend\tif.h" RelativePath="..\backend\tif.h"
> >

View File

@ -380,7 +380,6 @@
<ClInclude Include="..\..\backend\ksx1001.h" /> <ClInclude Include="..\..\backend\ksx1001.h" />
<ClInclude Include="..\..\backend\large.h" /> <ClInclude Include="..\..\backend\large.h" />
<ClInclude Include="..\..\backend\maxicode.h" /> <ClInclude Include="..\..\backend\maxicode.h" />
<ClInclude Include="..\..\backend\ms_stdint.h" />
<ClInclude Include="..\..\backend\output.h" /> <ClInclude Include="..\..\backend\output.h" />
<ClInclude Include="..\..\backend\pcx.h" /> <ClInclude Include="..\..\backend\pcx.h" />
<ClInclude Include="..\..\backend\pdf417.h" /> <ClInclude Include="..\..\backend\pdf417.h" />
@ -390,7 +389,6 @@
<ClInclude Include="..\..\backend\reedsol_logs.h" /> <ClInclude Include="..\..\backend\reedsol_logs.h" />
<ClInclude Include="..\..\backend\rss.h" /> <ClInclude Include="..\..\backend\rss.h" />
<ClInclude Include="..\..\backend\sjis.h" /> <ClInclude Include="..\..\backend\sjis.h" />
<ClInclude Include="..\..\backend\stdint_msvc.h" />
<ClInclude Include="..\..\backend\tif.h" /> <ClInclude Include="..\..\backend\tif.h" />
<ClInclude Include="..\..\backend\tif_lzw.h" /> <ClInclude Include="..\..\backend\tif_lzw.h" />
<ClInclude Include="..\..\backend\zfiletypes.h" /> <ClInclude Include="..\..\backend\zfiletypes.h" />

View File

@ -146,7 +146,6 @@
<ClInclude Include="..\..\backend\ksx1001.h" /> <ClInclude Include="..\..\backend\ksx1001.h" />
<ClInclude Include="..\..\backend\large.h" /> <ClInclude Include="..\..\backend\large.h" />
<ClInclude Include="..\..\backend\maxicode.h" /> <ClInclude Include="..\..\backend\maxicode.h" />
<ClInclude Include="..\..\backend\ms_stdint.h" />
<ClInclude Include="..\..\backend\output.h" /> <ClInclude Include="..\..\backend\output.h" />
<ClInclude Include="..\..\backend\pcx.h" /> <ClInclude Include="..\..\backend\pcx.h" />
<ClInclude Include="..\..\backend\pdf417.h" /> <ClInclude Include="..\..\backend\pdf417.h" />
@ -156,7 +155,6 @@
<ClInclude Include="..\..\backend\reedsol_logs.h" /> <ClInclude Include="..\..\backend\reedsol_logs.h" />
<ClInclude Include="..\..\backend\rss.h" /> <ClInclude Include="..\..\backend\rss.h" />
<ClInclude Include="..\..\backend\sjis.h" /> <ClInclude Include="..\..\backend\sjis.h" />
<ClInclude Include="..\..\backend\stdint_msvc.h" />
<ClInclude Include="..\..\backend\tif.h" /> <ClInclude Include="..\..\backend\tif.h" />
<ClInclude Include="..\..\backend\tif_lzw.h" /> <ClInclude Include="..\..\backend\tif_lzw.h" />
<ClInclude Include="..\..\backend\zfiletypes.h" /> <ClInclude Include="..\..\backend\zfiletypes.h" />

View File

@ -199,7 +199,6 @@
<ClInclude Include="..\..\backend\ksx1001.h" /> <ClInclude Include="..\..\backend\ksx1001.h" />
<ClInclude Include="..\..\backend\large.h" /> <ClInclude Include="..\..\backend\large.h" />
<ClInclude Include="..\..\backend\maxicode.h" /> <ClInclude Include="..\..\backend\maxicode.h" />
<ClInclude Include="..\..\backend\ms_stdint.h" />
<ClInclude Include="..\..\backend\output.h" /> <ClInclude Include="..\..\backend\output.h" />
<ClInclude Include="..\..\backend\pcx.h" /> <ClInclude Include="..\..\backend\pcx.h" />
<ClInclude Include="..\..\backend\pdf417.h" /> <ClInclude Include="..\..\backend\pdf417.h" />
@ -209,7 +208,6 @@
<ClInclude Include="..\..\backend\reedsol_logs.h" /> <ClInclude Include="..\..\backend\reedsol_logs.h" />
<ClInclude Include="..\..\backend\rss.h" /> <ClInclude Include="..\..\backend\rss.h" />
<ClInclude Include="..\..\backend\sjis.h" /> <ClInclude Include="..\..\backend\sjis.h" />
<ClInclude Include="..\..\backend\stdint_msvc.h" />
<ClInclude Include="..\..\backend\tif.h" /> <ClInclude Include="..\..\backend\tif.h" />
<ClInclude Include="..\..\backend\tif_lzw.h" /> <ClInclude Include="..\..\backend\tif_lzw.h" />
<ClInclude Include="..\..\backend\zfiletypes.h" /> <ClInclude Include="..\..\backend\zfiletypes.h" />

View File

@ -72,11 +72,8 @@ C library and header files needed to develop applications using %{name}-qt.
%setup -q %setup -q
%patch0 -p1 %patch0 -p1
# remove BSD-licensed file required for Windows only (just to ensure that this package is plain GPLv3+)
rm -f backend/ms_stdint.h
# remove bundled getopt sources (we use the corresponding Fedora package instead) # remove bundled getopt sources (we use the corresponding Fedora package instead)
rm -f frontend/getopt*.* rm -rf getopt
%build %build
%cmake CMakeLists.txt %cmake CMakeLists.txt