gs1: update to latest gs1-syntax-dictionary (new lint keyoff1());

in `key()` (& hence `keyoff1()`) check for GS1 Company Prefix
  length >= 4 (same as gs1-syntax-dictionary lints)
manual: update some standard years
This commit is contained in:
gitlost 2025-01-31 21:20:43 +00:00
parent 53cb29dbc6
commit 3f7cfd47c7
10 changed files with 879 additions and 839 deletions

View file

@ -245,6 +245,8 @@ static int csumalpha(const unsigned char *data, int data_len, int offset, int mi
return 1;
}
#define GS1_GCP_MIN_LENGTH 4 /* Minimum length of GS1 Company Prefix */
/* Check for a GS1 Prefix (GS1 General Specifications GS1 1.4.2) */
static int key(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) {
@ -262,14 +264,37 @@ static int key(const unsigned char *data, int data_len, int offset, int min, int
}
if (!length_only && data_len) {
data += offset;
int i;
if (!z_isdigit(data[0]) || !z_isdigit(data[1])) {
if (data_len < GS1_GCP_MIN_LENGTH) {
*p_err_no = 3;
*p_err_posn = offset + z_isdigit(data[0]) + 1;
sprintf(err_msg, "Non-numeric company prefix '%c'", data[z_isdigit(data[0])]);
*p_err_posn = offset + 1;
sprintf(err_msg, "GS1 Company Prefix length %d too short (minimum 4)", data_len);
return 0;
}
data += offset;
for (i = 0; i < GS1_GCP_MIN_LENGTH; i++) {
if (!z_isdigit(data[i])) {
*p_err_no = 3;
*p_err_posn = offset + i + 1;
sprintf(err_msg, "Non-numeric company prefix '%c'", data[i]);
return 0;
}
}
}
return 1;
}
/* Check for a GS1 Prefix at offset 1 (2nd position) */
static int keyoff1(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) {
if (!key(data, data_len, offset + 1, min - 1, max - 1, p_err_no, p_err_posn, err_msg, length_only)) {
(*p_err_posn)--;
return 0;
}
return 1;

View file

@ -4,7 +4,7 @@
*/
/*
libzint - the open source barcode library
Copyright (C) 2021-2024 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2021-2025 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,26 +36,26 @@
#ifndef Z_GS1_LINT_H
#define Z_GS1_LINT_H
/* N18,csum,key (Used by SSCC, GSRN - PROVIDER, GSRN - RECIPIENT) */
static int n18_csum_key(const unsigned char *data,
/* N18,csum,keyoff1 (Used by SSCC) */
static int n18_csum_keyoff1(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*/)
&& key(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& keyoff1(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)
&& key(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 0);
&& keyoff1(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 0);
}
/* N14,csum,key (Used by GTIN, CONTENT, MTO GTIN) */
static int n14_csum_key(const unsigned char *data,
/* N14,csum,keyoff1 (Used by GTIN, CONTENT, MTO GTIN) */
static int n14_csum_keyoff1(const unsigned char *data,
const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 14
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& keyoff1(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg)
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 0);
&& keyoff1(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 0);
}
/* X..20 (Used by BATCH/LOT, SERIAL, CPV, PCN, GLN EXTENSION COMPONENT, SHIP TO POST, RTN TO POST, REFURB LOT, ...) */
@ -626,6 +626,17 @@ static int x__25_csumalpha_key_hasnondigit(const unsigned char *data,
&& hasnondigit(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0);
}
/* N18,csum,key (Used by 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
&& csum(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& 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)
&& key(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]) {
@ -682,10 +693,10 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai < 100) {
if (ai == 0) {
return n18_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
return n18_csum_keyoff1(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 1 && ai <= 3) {
return n14_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
return n14_csum_keyoff1(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 10 || ai == 21 || ai == 22) {
return x__20(data, data_len, p_err_no, p_err_posn, err_msg);

View file

@ -2784,45 +2784,45 @@ static void test_encodation_11(const testCtx *const p_ctx) {
"0001000000000000000000000000000000000000000000000000010"
"0001010010011011110101000110111001000010100100010101010"
},
/*19*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]A12[8004]12", 0, 9, 55, "Mode '11', numeric [90], with [8004]",
/*19*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]A12[8004]1234", 0, 9, 55, "Mode '11', numeric [90], with [8004]",
"1101100110110001111010011001000001101101111011110101001"
"1101101110110100100000110001011100111101100011100101001"
"1101101100110100000111010001100100001110001011101101001"
"1101101000101110001001100001101111001011000011101001001"
"1101001000100100110000110001101000010000110011101001101"
"1101101100111101000010000101000100011111011011101101001"
"1101101000100001100010011101011010001110000011101001001"
"1101001000101010000001000001101001000011000011101001101"
"0001000000000000000000000000000000000000000000000000010"
"0010000000000000000000000000000000000000000000000000001"
"0001000000000000000000000000000000000000000000000000010"
"0001010010011011110101000110111001000010100100010101010"
},
/*20*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]AB[8004]12", 0, 9, 55, "Mode '11', alpha [90], with [8004]",
/*20*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]AB[8004]1234", 0, 9, 55, "Mode '11', alpha [90], with [8004]",
"1101100110100111110011001001100101111110010011110101001"
"1101101110101000100000100001011000111001100011100101001"
"1101101100100111110100011101111000100001001011101101001"
"1101101000101000110011111001010001110111111011101001001"
"1101001000110011101100001001111011100001011011101001101"
"1101101100100111111010110001011111011001111011101101001"
"1101101000101100110111100001101001001111100011101001001"
"1101001000110110010001000001111001111001001011101001101"
"0001000000000000000000000000000000000000000000000000010"
"0010000000000000000000000000000000000000000000000000001"
"0001000000000000000000000000000000000000000000000000010"
"0001010010011011110101000110111001000010100100010101010"
},
/*21*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]A.[8004]12", 0, 9, 55, "Mode '11', alphanumeric [90], with [8004]",
/*21*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]A.[8004]1234", 0, 9, 55, "Mode '11', alphanumeric [90], with [8004]",
"1101100110110111110011001101111110100110001011110101001"
"1101101110100010001001000001100101100011100011100101001"
"1101101100100001011110001001100001100111101011101101001"
"1101101000100111100100001001011110001110111011101001001"
"1101001000101101111100111101100011010100000011101001101"
"1101101100111000010011101101111010000100100011101101001"
"1101101000101001011110000001110011011111101011101001001"
"1101001000110010000100110001101010000011000011101001101"
"0001000000000000000000000000000000000000000000000000010"
"0010000000000000000000000000000000000000000000000000001"
"0001000000000000000000000000000000000000000000000000010"
"0001010010011011110101000110111001000010100100010101010"
},
/*22*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]A+[8004]12", 0, 9, 55, "Mode '11', ISO-646 [90], with [8004]",
/*22*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]A+[8004]1234", 0, 9, 55, "Mode '11', ISO-646 [90], with [8004]",
"1101100110110111110011001101111110100110001011110101001"
"1101101110111100110010111001001110001110100011100101001"
"1101101100111001011100011001101001110000010011101101001"
"1101101000101100000110111101000110001001110011101001001"
"1101001000100011000110000101111100110101111011101001101"
"1101101100111001011100011001111001001010000011101101001"
"1101101000110111101100111001011110100010000011101001001"
"1101001000111001101011000001101100010001000011101001101"
"0001000000000000000000000000000000000000000000000000010"
"0010000000000000000000000000000000000000000000000000001"
"0001000000000000000000000000000000000000000000000000010"
@ -2888,13 +2888,13 @@ static void test_encodation_11(const testCtx *const p_ctx) {
"0001000000000000000000000000000000000000000000000000010"
"0001010010011011110101000110111001000010100100010101010"
},
/*28*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]AB[8004]12[10]12", 0, 10, 55, "Mode '11', alpha [90], with [8004], other data",
/*28*/ { BARCODE_UPCE_CC, 1, "1234567", "[90]AB[8004]1234[10]12", 0, 10, 55, "Mode '11', alpha [90], with [8004], other data",
"1100100010110000110000101001101111011101000011100101101"
"1110100010110100011110001101001110001011111011000101101"
"1110110010100011100110111001011101101110000011000101001"
"1100110010100000100010001001010000010000100011001101001"
"1101110010111010000110000101101011100010000011011101001"
"1101111010110011110010001101000111101100110011011001001"
"1110110010100001101101111001100011110010110011000101001"
"1100110010100001100111001101111010101111000011001101001"
"1101110010111110100010001101001101011111100011011101001"
"1101111010100111110110010001001011101111110011011001001"
"0001000000000000000000000000000000000000000000000000010"
"0010000000000000000000000000000000000000000000000000001"
"0001000000000000000000000000000000000000000000000000010"

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-2024 <rstuart114@gmail.com>
Copyright (C) 2021-2025 <rstuart114@gmail.com>
*/
/* SPDX-License-Identifier: BSD-3-Clause */
@ -243,7 +243,7 @@ if ($print_copyright) {
print <<<'EOD'
/*
libzint - the open source barcode library
Copyright (C) 2021-2024 Robin Stuart <rstuart114@gmail.com>
Copyright (C) 2021-2025 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

@ -8005,8 +8005,8 @@ can be encoded.</p>
<p>Revision 2 of Ultracode (2023) may be specified using
<code>--vers=2</code> (API <code>option_2 = 2</code>).</p>
<hr />
<p>WARNING: Revision 2 of Ultracode was only finalized December 2023 and
Zint has not yet been updated to support it. Do not use.</p>
<p>WARNING: Revision 2 of Ultracode was finalized December 2023 and Zint
has not yet been updated to support it. Do not use.</p>
<hr />
<p>Ultracode supports Structured Append of up to 8 symbols and an
optional numeric ID (File Number), which can be set by using the
@ -8166,7 +8166,7 @@ and data capture techniques - Code 128 bar code symbology
specification</li>
<li>BS EN 12323:2005 AIDC technologies - Symbology specifications - Code
16K</li>
<li>ISO/IEC 16388:2007 Information technology - Automatic identification
<li>ISO/IEC 16388:2023 Information technology - Automatic identification
and data capture techniques - Code 39 bar code symbology
specification</li>
<li>ANSI/AIM BC6-2000 - Uniform Symbology Specification Code 49</li>
@ -8207,7 +8207,7 @@ specification</li>
<li>ISO/IEC 15438:2015 Information technology - Automatic identification
and data capture techniques - PDF417 bar code symbology
specification</li>
<li>ISO/IEC 18004:2015 Information technology - Automatic identification
<li>ISO/IEC 18004:2024 Information technology - Automatic identification
and data capture techniques - QR Code bar code symbology
specification</li>
<li>ISO/IEC 23941:2022 Information technology - Automatic identification
@ -9451,12 +9451,12 @@ from</p>
<p>Zint is designed to be compliant with a number of international
standards, including:</p>
<p>ISO/IEC 24778:2024, ANSI/AIM BC12-1998, EN 798:1996, AIM ISS-X-24
(1995), ISO/IEC 15417:2007, EN 12323:2005, ISO/IEC 16388:2007, ANSI/AIM
(1995), ISO/IEC 15417:2007, EN 12323:2005, ISO/IEC 16388:2023, ANSI/AIM
BC6-2000, ANSI/AIM BC5-1995, AIM USS Code One (1994), ISO/IEC
16022:2024, ISO/IEC 21471:2019, ISO/IEC 15420:2009, AIMD014 (v 1.63)
(2008), ISO/IEC 24723:2010, ISO/IEC 24724:2011, ISO/IEC 20830:2021,
ISO/IEC 16390:2007, ISO/IEC 16023:2000, ISO/IEC 24728:2006, ISO/IEC
15438:2015, ISO/IEC 18004:2015, ISO/IEC 23941:2022, AIM ITS/04-023
15438:2015, ISO/IEC 18004:2024, ISO/IEC 23941:2022, AIM ITS/04-023
(2022)</p>
<h2 id="copyright">COPYRIGHT</h2>
<p>Copyright © 2025 Robin Stuart. Released under GNU GPL 3.0 or

View file

@ -4714,8 +4714,8 @@ Revision 2 of Ultracode (2023) may be specified using `--vers=2` (API
`option_2 = 2`).
* * *
WARNING: Revision 2 of Ultracode was only finalized December 2023 and Zint has
not yet been updated to support it. Do not use.
WARNING: Revision 2 of Ultracode was finalized December 2023 and Zint has not
yet been updated to support it. Do not use.
* * *
@ -4847,7 +4847,7 @@ international standards:
- ISO/IEC 15417:2007 Information technology - Automatic identification and data
capture techniques - Code 128 bar code symbology specification
- BS EN 12323:2005 AIDC technologies - Symbology specifications - Code 16K
- ISO/IEC 16388:2007 Information technology - Automatic identification and data
- ISO/IEC 16388:2023 Information technology - Automatic identification and data
capture techniques - Code 39 bar code symbology specification
- ANSI/AIM BC6-2000 - Uniform Symbology Specification Code 49
- ANSI/AIM BC5-1995 - Uniform Symbology Specification Code 93
@ -4879,7 +4879,7 @@ international standards:
capture techniques - MicroPDF417 bar code symbology specification
- ISO/IEC 15438:2015 Information technology - Automatic identification and data
capture techniques - PDF417 bar code symbology specification
- ISO/IEC 18004:2015 Information technology - Automatic identification and data
- ISO/IEC 18004:2024 Information technology - Automatic identification and data
capture techniques - QR Code bar code symbology specification
- ISO/IEC 23941:2022 Information technology - Automatic identification and data
capture techniques - Rectangular Micro QR Code (rMQR) bar code symbology

View file

@ -4527,8 +4527,8 @@ option_2 = 2).
--------------------------------------------------------------------------------
WARNING: Revision 2 of Ultracode was only finalized December 2023 and Zint has
not yet been updated to support it. Do not use.
WARNING: Revision 2 of Ultracode was finalized December 2023 and Zint has not
yet been updated to support it. Do not use.
--------------------------------------------------------------------------------
@ -4657,7 +4657,7 @@ international standards:
- ISO/IEC 15417:2007 Information technology - Automatic identification and
data capture techniques - Code 128 bar code symbology specification
- BS EN 12323:2005 AIDC technologies - Symbology specifications - Code 16K
- ISO/IEC 16388:2007 Information technology - Automatic identification and
- ISO/IEC 16388:2023 Information technology - Automatic identification and
data capture techniques - Code 39 bar code symbology specification
- ANSI/AIM BC6-2000 - Uniform Symbology Specification Code 49
- ANSI/AIM BC5-1995 - Uniform Symbology Specification Code 93
@ -4690,7 +4690,7 @@ international standards:
data capture techniques - MicroPDF417 bar code symbology specification
- ISO/IEC 15438:2015 Information technology - Automatic identification and
data capture techniques - PDF417 bar code symbology specification
- ISO/IEC 18004:2015 Information technology - Automatic identification and
- ISO/IEC 18004:2024 Information technology - Automatic identification and
data capture techniques - QR Code bar code symbology specification
- ISO/IEC 23941:2022 Information technology - Automatic identification and
data capture techniques - Rectangular Micro QR Code (rMQR) bar code
@ -5554,11 +5554,11 @@ Zint is designed to be compliant with a number of international standards,
including:
ISO/IEC 24778:2024, ANSI/AIM BC12-1998, EN 798:1996, AIM ISS-X-24 (1995),
ISO/IEC 15417:2007, EN 12323:2005, ISO/IEC 16388:2007, ANSI/AIM BC6-2000,
ISO/IEC 15417:2007, EN 12323:2005, ISO/IEC 16388:2023, ANSI/AIM BC6-2000,
ANSI/AIM BC5-1995, AIM USS Code One (1994), ISO/IEC 16022:2024, ISO/IEC
21471:2019, ISO/IEC 15420:2009, AIMD014 (v 1.63) (2008), ISO/IEC 24723:2010,
ISO/IEC 24724:2011, ISO/IEC 20830:2021, ISO/IEC 16390:2007, ISO/IEC 16023:2000,
ISO/IEC 24728:2006, ISO/IEC 15438:2015, ISO/IEC 18004:2015, ISO/IEC 23941:2022,
ISO/IEC 24728:2006, ISO/IEC 15438:2015, ISO/IEC 18004:2024, ISO/IEC 23941:2022,
AIM ITS/04-023 (2022)
COPYRIGHT

View file

@ -723,12 +723,12 @@ Zint is designed to be compliant with a number of international
standards, including:
.PP
ISO/IEC 24778:2024, ANSI/AIM BC12\-1998, EN 798:1996, AIM ISS\-X\-24
(1995), ISO/IEC 15417:2007, EN 12323:2005, ISO/IEC 16388:2007, ANSI/AIM
(1995), ISO/IEC 15417:2007, EN 12323:2005, ISO/IEC 16388:2023, ANSI/AIM
BC6\-2000, ANSI/AIM BC5\-1995, AIM USS Code One (1994), ISO/IEC
16022:2024, ISO/IEC 21471:2019, ISO/IEC 15420:2009, AIMD014 (v 1.63)
(2008), ISO/IEC 24723:2010, ISO/IEC 24724:2011, ISO/IEC 20830:2021,
ISO/IEC 16390:2007, ISO/IEC 16023:2000, ISO/IEC 24728:2006, ISO/IEC
15438:2015, ISO/IEC 18004:2015, ISO/IEC 23941:2022, AIM ITS/04\-023
15438:2015, ISO/IEC 18004:2024, ISO/IEC 23941:2022, AIM ITS/04\-023
(2022)
.SH COPYRIGHT
Copyright © 2025 Robin Stuart.

View file

@ -648,12 +648,12 @@ Zint is designed to be compliant with a number of international standards, inclu
ISO/IEC 24778:2024, ANSI/AIM BC12-1998, EN 798:1996,
AIM ISS-X-24 (1995), ISO/IEC 15417:2007, EN 12323:2005,
ISO/IEC 16388:2007, ANSI/AIM BC6-2000, ANSI/AIM BC5-1995,
ISO/IEC 16388:2023, ANSI/AIM BC6-2000, ANSI/AIM BC5-1995,
AIM USS Code One (1994), ISO/IEC 16022:2024, ISO/IEC 21471:2019,
ISO/IEC 15420:2009, AIMD014 (v 1.63) (2008), ISO/IEC 24723:2010,
ISO/IEC 24724:2011, ISO/IEC 20830:2021, ISO/IEC 16390:2007,
ISO/IEC 16023:2000, ISO/IEC 24728:2006, ISO/IEC 15438:2015,
ISO/IEC 18004:2015, ISO/IEC 23941:2022, AIM ITS/04-023 (2022)
ISO/IEC 18004:2024, ISO/IEC 23941:2022, AIM ITS/04-023 (2022)
# COPYRIGHT