gs1: update to latest gs1-syntax-dictionary (cset64, separate

latitude/longitude, mediatype, new AIs 7241, 7242, 8030)
  TODO: integrate gs1-syntax-engine
BWIPP: update to latest (bwipp_dump.ps)
manual: README: pandoc latest
This commit is contained in:
gitlost 2023-07-05 21:26:16 +01:00
parent a324fe90f6
commit 6733e76be4
10 changed files with 727 additions and 597 deletions

View File

@ -129,6 +129,39 @@ static int cset39(const unsigned char *data, int data_len, int offset, int min,
return 1;
}
/* Validate of character set 64 (GSCN 21-307 Figure 7.11-3) */
static int cset64(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50]) {
data_len -= offset;
if (data_len < min) {
return 0;
}
if (data_len) {
const unsigned char *d = data + offset;
const unsigned char *const de = d + (data_len > max ? max : data_len);
for (; d < de; d++) {
/* 0-9, A-Z, a-z and "-", "_" */
if ((*d < '0' && *d != '-') || (*d > '9' && *d < 'A') || (*d > 'Z' && *d < 'a' && *d != '_')
|| *d > 'z') {
/* One or two "="s can be used as padding to mod 3 length */
if (*d == '=' && (d + 1 == de || (d + 2 == de && *(d + 1) == '=')) && data_len % 3 == 0) {
break;
}
*p_err_no = 3;
*p_err_posn = d - data + 1;
sprintf(err_msg, "Invalid CSET 64 character '%c'", *d);
return 0;
}
}
}
return 1;
}
/* Check a check digit (GS1 General Specifications 7.9.1) */
static int csum(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) {
@ -167,7 +200,6 @@ static int csum(const unsigned char *data, int data_len, int offset, int min, in
/* Check alphanumeric check characters (GS1 General Specifications 7.9.5) */
static int csumalpha(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) {
(void)max;
data_len -= offset;
@ -1179,35 +1211,89 @@ static int couponposoffer(const unsigned char *data, int data_len, int offset, i
return 1;
}
/* Check WSG 84 latitude, longitude */
static int latlong(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
/* Check WSG 84 latitude */
static int latitude(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) {
(void)max;
data_len -= offset;
if (data_len < min || (data_len && data_len < 20)) {
if (data_len < min || (data_len && data_len < 10)) {
return 0;
}
if (!length_only && data_len) {
const unsigned char *d = data + offset;
const unsigned char *const de = d + (data_len > max ? max : data_len);
uint64_t lat = 0, lng = 0;
uint64_t lat = 0;
for (; d < de; d++) {
if (de - d > 10) {
lat *= 10;
lat += *d - '0';
} else {
lng *= 10;
lng += *d - '0';
}
lat *= 10;
lat += *d - '0';
}
if (lat > 1800000000 || lng > 3600000000) {
if (lat > 1800000000) {
*p_err_no = 3;
*p_err_posn = d - 1 - data + 1 - 10 * (lat > 1800000000);
sprintf(err_msg, "Invalid %s", lat > 1800000000 ? "latitude" : "longitude");
*p_err_posn = d - 1 - data + 1;
strcpy(err_msg, "Invalid latitude");
return 0;
}
}
return 1;
}
/* Check WSG 84 longitude */
static int longitude(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset;
if (data_len < min || (data_len && data_len < 10)) {
return 0;
}
if (!length_only && data_len) {
const unsigned char *d = data + offset;
const unsigned char *const de = d + (data_len > max ? max : data_len);
uint64_t lng = 0;
for (; d < de; d++) {
lng *= 10;
lng += *d - '0';
}
if (lng > 3600000000) {
*p_err_no = 3;
*p_err_posn = d - 1 - data + 1;
strcpy(err_msg, "Invalid longitude");
return 0;
}
}
return 1;
}
/* Check AIDC media type (GSCN-22-345 Figure 3.8.22-2) */
static int mediatype(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no,
int *p_err_posn, char err_msg[50], const int length_only) {
data_len -= offset;
if (data_len < min || (data_len && data_len < 2)) {
return 0;
}
if (!length_only && data_len) {
const unsigned char *d = data + offset;
const unsigned char *const de = d + (data_len > max ? max : data_len);
unsigned int val = 0;
for (; d < de; d++) {
val *= 10;
val += *d - '0';
}
if (val == 0 || (val > 10 && val < 80)) {
*p_err_no = 3;
*p_err_posn = d - data + 1;
strcpy(err_msg, "Invalid AIDC media type");
return 0;
}
}

View File

@ -1,10 +1,10 @@
/*
* GS1 AI checker generated by "backend/tools/gen_gs1_lint.php" from
* https://ref.gs1.org/tools/gs1-barcode-syntax-resource/syntax-dictionary/
* https://raw.githubusercontent.com/gs1/gs1-syntax-dictionary/main/gs1-syntax-dictionary.txt
*/
/*
libzint - the open source barcode library
Copyright (C) 2021-2022 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2021-2023 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@ -36,7 +36,7 @@
#ifndef Z_GS1_LINT_H
#define Z_GS1_LINT_H
/* N18,csum,key (Used by SSCC) */
/* N18,csum,key (Used by SSCC, GSRN - PROVIDER, GSRN - RECIPIENT) */
static int n18_csum_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 18
@ -88,7 +88,7 @@ static int x__28(const unsigned char *data, const int data_len,
&& cset82(data, data_len, 0, 1, 28, p_err_no, p_err_posn, err_msg);
}
/* X..30 (Used by ADDITIONAL ID, CUST. PART NO., SECONDARY SERIAL, REF. TO SOURCE...) */
/* X..30 (Used by ADDITIONAL ID, CUST. PART No., SECONDARY SERIAL, REF. TO SOURCE...) */
static int x__30(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 30
@ -257,13 +257,16 @@ static int x2_iso3166alpha2(const unsigned char *data, const int data_len,
&& iso3166alpha2(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 0);
}
/* N20,latlong (Used by SHIP TO GEO) */
static int n20_latlong(const unsigned char *data, const int data_len,
/* N10,latitude N10,longitude (Used by SHIP TO GEO) */
static int n10_latitude_n10_longitude(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 20
&& latlong(data, data_len, 0, 20, 20, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 20, 20, p_err_no, p_err_posn, err_msg)
&& latlong(data, data_len, 0, 20, 20, p_err_no, p_err_posn, err_msg, 0);
&& latitude(data, data_len, 0, 10, 10, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& longitude(data, data_len, 10, 10, 10, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 10, 10, p_err_no, p_err_posn, err_msg)
&& latitude(data, data_len, 0, 10, 10, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 10, 10, 10, p_err_no, p_err_posn, err_msg)
&& longitude(data, data_len, 10, 10, 10, p_err_no, p_err_posn, err_msg, 0);
}
/* N1,yesno (Used by DANGEROUS GOODS, AUTH TO LEAVE, SIG REQUIRED) */
@ -397,6 +400,22 @@ static int x2_x__28(const unsigned char *data, const int data_len,
&& cset82(data, data_len, 2, 1, 28, p_err_no, p_err_posn, err_msg);
}
/* N2,mediatype (Used by AIDC MEDIA TYPE) */
static int n2_mediatype(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 2
&& mediatype(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg)
&& mediatype(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg, 0);
}
/* X..25 (Used by VCN, REF No.) */
static int x__25(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 25
&& cset82(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg);
}
/* N4,nonzero N5,nonzero N3,nonzero N1,winding N1 (Used by DIMENSIONS) */
static int n4_nonzero_n5_nonzero_n3_nonzero_n1_winding_n1(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
@ -500,15 +519,6 @@ static int x__25_csumalpha_key(const unsigned char *data, const int data_len,
&& key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0);
}
/* N18,csum (Used by GSRN - PROVIDER, GSRN - RECIPIENT) */
static int n18_csum(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 18
&& csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 0);
}
/* N..10 (Used by SRIN) */
static int n__10(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
@ -516,11 +526,11 @@ static int n__10(const unsigned char *data, const int data_len,
&& numeric(data, data_len, 0, 1, 10, p_err_no, p_err_posn, err_msg);
}
/* X..25 (Used by REF NO.) */
static int x__25(const unsigned char *data, const int data_len,
/* Z..90 (Used by DIGSIG) */
static int z__90(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 1 && data_len <= 25
&& cset82(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg);
return data_len >= 1 && data_len <= 90
&& cset64(data, data_len, 0, 1, 90, p_err_no, p_err_posn, err_msg);
}
/* X..70,couponcode */
@ -724,7 +734,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
return x__30(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 4309) {
return n20_latlong(data, data_len, p_err_no, p_err_posn, err_msg);
return n10_latitude_n10_longitude(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 4318) {
return x__20(data, data_len, p_err_no, p_err_posn, err_msg);
@ -795,6 +805,12 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai == 7240) {
return x__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7241) {
return n2_mediatype(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 7242) {
return x__25(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 8100) {
@ -835,7 +851,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
return x__25_csumalpha_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8017 || ai == 8018) {
return n18_csum(data, data_len, p_err_no, p_err_posn, err_msg);
return n18_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8019) {
return n__10(data, data_len, p_err_no, p_err_posn, err_msg);
@ -843,6 +859,9 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai == 8020) {
return x__25(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8030) {
return z__90(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 8200) {

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
/* Generate GS1 verify include "backend/gs1_lint.h" for "backend/gs1.c" */
/*
libzint - the open source barcode library
Copyright (C) 2021-2022 <rstuart114@gmail.com>
Copyright (C) 2021-2023 <rstuart114@gmail.com>
*/
/* SPDX-License-Identifier: BSD-3-Clause */
@ -15,7 +15,7 @@
* php backend/tools/gen_gs1_lint.php -f <local-path>/gs1-syntax-dictionary.txt backend/gs1_lint.h
*
*************************************************************************************************
* NOTE: up-to-update version requires syntax dictionary available from
* NOTE: up-to-date version requires syntax dictionary available from
* https://ref.gs1.org/tools/gs1-barcode-syntax-resource/syntax-dictionary/
*************************************************************************************************
*/
@ -27,7 +27,7 @@ $dirdirname = basename(dirname($dirname)) . '/' . basename($dirname);
$opts = getopt('c:f:h:l:t:');
$print_copyright = isset($opts['c']) ? (bool) $opts['c'] : true;
$file = isset($opts['f']) ? $opts['f'] : 'https://ref.gs1.org/tools/gs1-barcode-syntax-resource/syntax-dictionary/';
$file = isset($opts['f']) ? $opts['f'] : 'https://raw.githubusercontent.com/gs1/gs1-syntax-dictionary/main/gs1-syntax-dictionary.txt';
$print_h_guard = isset($opts['h']) ? (bool) $opts['h'] : true;
$use_length_only = isset($opts['l']) ? (bool) $opts['l'] : true;
$tab = isset($opts['t']) ? $opts['t'] : ' ';
@ -55,7 +55,8 @@ foreach ($lines as $line) {
if ($line === '' || $line[0] === '#') {
continue;
}
if (!preg_match('/^([0-9]+(?:-[0-9]+)?) +([ *] )([NXYC][0-9.][ NXYC0-9.,a-z=|\[\]]*)(?:# (.+))?$/', $line, $matches)) {
if (!preg_match('/^([0-9]+(?:-[0-9]+)?) +([ *] )([NXYZ][0-9.][ NXYZ0-9.,a-z=|\[\]]*)(?:# (.+))?$/', $line, $matches)) {
print $line . PHP_EOL;
exit("$basename:" . __LINE__ . " ERROR: Could not parse line $line_no" . PHP_EOL);
}
$ai = $matches[1];
@ -121,7 +122,7 @@ foreach ($lines as $line) {
foreach ($parts as $part) {
$checkers = explode(',', $part);
$validator = array_shift($checkers);
if (preg_match('/^([NXYC])([0-9]+)?(\.\.[0-9|]+)?$/', $validator, $matches)) {
if (preg_match('/^([NXYZ])([0-9]+)?(\.\.[0-9|]+)?$/', $validator, $matches)) {
if (count($matches) === 3) {
$min = $max = (int) $matches[2];
} else {
@ -132,10 +133,12 @@ foreach ($lines as $line) {
$validator = "numeric";
} elseif ($matches[1] === 'X') {
$validator = "cset82";
} else {
} elseif ($matches[1] === 'Y') {
$validator = "cset39";
} else { // 'Z'
$validator = "cset64";
}
} else if (preg_match('/^\[([NXYC])([1-9]+)?(\.\.[0-9|]+)?\]$/', $validator, $matches)) {
} else if (preg_match('/^\[([NXYZ])([1-9]+)?(\.\.[0-9|]+)?\]$/', $validator, $matches)) {
if (count($matches) === 3) {
$min = 0;
$max = (int) $matches[2];
@ -147,8 +150,10 @@ foreach ($lines as $line) {
$validator = "numeric";
} elseif ($matches[1] === 'X') {
$validator = "cset82";
} else {
} elseif ($matches[1] === 'Y') {
$validator = "cset39";
} else { // 'Z'
$validator = "cset64";
}
} else {
exit("$basename:" . __LINE__ . " ERROR: Could not parse validator \"$validator\" line $line_no" . PHP_EOL);
@ -234,7 +239,7 @@ if ($print_copyright) {
print <<<'EOD'
/*
libzint - the open source barcode library
Copyright (C) 2021-2022 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2021-2023 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions

View File

@ -2,8 +2,8 @@ For generation of "docs/manual.pdf" and "docs/manual.txt" from "manual.pmd" usin
On Ubuntu/Debian (tested on Ubuntu 22.04)
wget https://github.com/jgm/pandoc/releases/download/3.1.3/pandoc-3.1.3-1-amd64.deb
sudo dpkg -i pandoc-3.1.3-1-amd64.deb
wget https://github.com/jgm/pandoc/releases/download/3.1.4/pandoc-3.1.4-1-amd64.deb
sudo dpkg -i pandoc-3.1.4-1-amd64.deb
sudo apt install python3-pip
pip install pandoc-tablenos --user
export PATH=~/.local/bin:"$PATH"
@ -18,9 +18,9 @@ On Ubuntu/Debian (tested on Ubuntu 22.04)
On Fedora (tested on Fedora Linux 38 (Workstation Edition))
wget https://github.com/jgm/pandoc/releases/download/3.1.3/pandoc-3.1.3-linux-amd64.tar.gz
tar xf pandoc-3.1.3-linux-amd64.tar.gz
sudo mv -i pandoc-3.1.3/bin/pandoc /usr/local/bin
wget https://github.com/jgm/pandoc/releases/download/3.1.4/pandoc-3.1.4-linux-amd64.tar.gz
tar xf pandoc-3.1.4-linux-amd64.tar.gz
sudo mv -i pandoc-3.1.4/bin/pandoc /usr/local/bin
sudo dnf install python3-pip
pip install pandoc-tablenos --user
export PATH=~/.local/bin:"$PATH"

View File

@ -1,6 +1,6 @@
% Zint Barcode Generator and Zint Barcode Studio User Manual
% Version 2.12.0.9
% June 2023
% July 2023
# 1. Introduction

View File

@ -1,6 +1,6 @@
Zint Barcode Generator and Zint Barcode Studio User Manual
Version 2.12.0.9
June 2023
July 2023
*******************************************************************************
* For reference the following is a text-only version of the Zint manual, *
@ -4494,7 +4494,7 @@ defined.
Annex B. Man Page ZINT(1)
% ZINT(1) Version 2.12.0.9 % % June 2023
% ZINT(1) Version 2.12.0.9 % % July 2023
NAME

View File

@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 3.1.3
.\" Automatically generated by Pandoc 3.1.4
.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.
@ -14,7 +14,7 @@
. ftr VB CB
. ftr VBI CBI
.\}
.TH "ZINT" "1" "June 2023" "Version 2.12.0.9" ""
.TH "ZINT" "1" "July 2023" "Version 2.12.0.9" ""
.hy
.SH NAME
.PP

View File

@ -1,6 +1,6 @@
% ZINT(1) Version 2.12.0.9
%
% June 2023
% July 2023
# NAME