1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-07-31 10:29:52 +00:00

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
+29 -4
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;
+22 -11
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);
+21 -21
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"
+785 -781
View File
File diff suppressed because it is too large Load Diff
+2 -2
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