GS1: update to latest gs1-syntax-dictionary, new AI 8014 (GSCN

21-283) MUDI, and AI 03 MTO GTIN);
  hhmm -> hh,mm, mmoptss -> mm,ss, yymmddhh obsolete
This commit is contained in:
gitlost 2024-07-30 13:11:15 +01:00
parent 3c7a702169
commit 7f4ccccb98
3 changed files with 1125 additions and 1058 deletions

View File

@ -394,33 +394,6 @@ static int yymmdd(const unsigned char *data, int data_len, int offset, int min,
return 1; return 1;
} }
/* Check for a date and hours YYMMDDHH */
static int yymmddhh(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 (data_len < min || (data_len && data_len < 8)) {
return 0;
}
if (!yymmdd(data, data_len, offset, min, max, p_err_no, p_err_posn, err_msg, length_only)) {
return 0;
}
data_len = data_len < offset ? 0 : data_len - offset;
if (!length_only && data_len) {
const int hour = to_int(data + offset + 6, 2);
if (hour > 23) {
*p_err_no = 3;
*p_err_posn = offset + 6 + 1;
sprintf(err_msg, "Invalid hour of day '%.2s'", data + offset + 6);
return 0;
}
}
return 1;
}
/* Check for a time HHMM */ /* Check for a time HHMM */
static int hhmm(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int hhmm(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) { int *p_err_posn, char err_msg[50], const int length_only) {
@ -454,15 +427,38 @@ static int hhmm(const unsigned char *data, int data_len, int offset, int min, in
return 1; return 1;
} }
/* Check for a time MMSS with seconds optional */ /* Check for a time HH (hours) */
static int mmoptss(const unsigned char *data, int data_len, int offset, int min, int max, int *p_err_no, static int hh(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) { int *p_err_posn, char err_msg[50], const int length_only) {
(void)max; (void)max;
data_len = data_len < offset ? 0 : data_len - offset; data_len = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 2) if (data_len < min || (data_len && data_len < 2)) {
|| (data_len > 2 && data_len < 4)) { return 0;
}
if (!length_only && data_len) {
const int hour = to_int(data + offset, 2);
if (hour > 23) {
*p_err_no = 3;
*p_err_posn = offset + 1;
sprintf(err_msg, "Invalid hour of day '%.2s'", data + offset);
return 0;
}
}
return 1;
}
/* Check for a time MM (minutes) */
static int mm(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 = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 2)) {
return 0; return 0;
} }
@ -474,14 +470,29 @@ static int mmoptss(const unsigned char *data, int data_len, int offset, int min,
sprintf(err_msg, "Invalid minutes in the hour '%.2s'", data + offset); sprintf(err_msg, "Invalid minutes in the hour '%.2s'", data + offset);
return 0; return 0;
} }
if (data_len > 2) { }
const int secs = to_int(data + offset + 2, 2);
if (secs > 59) { return 1;
*p_err_no = 3; }
*p_err_posn = offset + 2 + 1;
sprintf(err_msg, "Invalid seconds in the minute '%.2s'", data + offset + 2); /* Check for a time SS (seconds) */
static int ss(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 = data_len < offset ? 0 : data_len - offset;
if (data_len < min || (data_len && data_len < 2)) {
return 0; return 0;
} }
if (!length_only && data_len) {
const int secs = to_int(data + offset, 2);
if (secs > 59) {
*p_err_no = 3;
*p_err_posn = offset + 1;
sprintf(err_msg, "Invalid seconds in the minute '%.2s'", data + offset);
return 0;
} }
} }
@ -1455,6 +1466,34 @@ static int posinseqslash(const unsigned char *data, int data_len, int offset, in
return 1; return 1;
} }
/* Check that input contains non-digit (GSCN 21-283) */
static int hasnondigit(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 = data_len < offset ? 0 : data_len - offset;
if (data_len < min) {
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);
for (; d < de && z_isdigit(*d); d++);
if (d == de) {
*p_err_no = 3;
*p_err_posn = offset + 1;
strcpy(err_msg, "A non-digit character is required");
return 0;
}
}
return 1;
}
/* Generated by "php backend/tools/gen_gs1_linter.php > backend/gs1_lint.h" */ /* Generated by "php backend/tools/gen_gs1_linter.php > backend/gs1_lint.h" */
#include "gs1_lint.h" #include "gs1_lint.h"

View File

@ -47,7 +47,7 @@ static int n18_csum_key(const unsigned char *data,
&& key(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);
} }
/* N14,csum,key (Used by GTIN, CONTENT) */ /* N14,csum,key (Used by GTIN, CONTENT, MTO GTIN) */
static int n14_csum_key(const unsigned char *data, static int n14_csum_key(const unsigned char *data,
const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 14 return data_len == 14
@ -550,16 +550,22 @@ static int x__34_iban(const unsigned char *data,
&& iban(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg, 0); && iban(data, data_len, 0, 1, 34, p_err_no, p_err_posn, err_msg, 0);
} }
/* N8,yymmddhh [N..4],mmoptss (Used by PROD TIME) */ /* N6,yymmdd N2,hh [N2],mm [N2],ss (Used by PROD TIME) */
static int n8_yymmddhh__n__4__mmoptss(const unsigned char *data, static int n6_yymmdd_n2_hh__n2__mm__n2__ss(const unsigned char *data,
const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len >= 8 && data_len <= 12 return data_len >= 8 && data_len <= 12
&& yymmddhh(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& mmoptss(data, data_len, 8, 0, 4, p_err_no, p_err_posn, err_msg, 1 /*length_only*/) && hh(data, data_len, 6, 2, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg) && mm(data, data_len, 8, 0, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& yymmddhh(data, data_len, 0, 8, 8, p_err_no, p_err_posn, err_msg, 0) && ss(data, data_len, 10, 0, 2, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& numeric(data, data_len, 8, 0, 4, p_err_no, p_err_posn, err_msg) && numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg)
&& mmoptss(data, data_len, 8, 0, 4, p_err_no, p_err_posn, err_msg, 0); && yymmdd(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 6, 2, 2, p_err_no, p_err_posn, err_msg)
&& hh(data, data_len, 6, 2, 2, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 8, 0, 2, p_err_no, p_err_posn, err_msg)
&& mm(data, data_len, 8, 0, 2, p_err_no, p_err_posn, err_msg, 0)
&& numeric(data, data_len, 10, 0, 2, p_err_no, p_err_posn, err_msg)
&& ss(data, data_len, 10, 0, 2, p_err_no, p_err_posn, err_msg, 0);
} }
/* X..50 (Used by OPTSEN) */ /* X..50 (Used by OPTSEN) */
@ -598,6 +604,19 @@ static int x__25_csumalpha_key(const unsigned char *data,
&& key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0); && key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0);
} }
/* X..25,csumalpha,key,hasnondigit (Used by MUDI) */
static int x__25_csumalpha_key_hasnondigit(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
&& csumalpha(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& hasnondigit(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
&& cset82(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg)
&& csumalpha(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0)
&& key(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0)
&& hasnondigit(data, data_len, 0, 1, 25, p_err_no, p_err_posn, err_msg, 0);
}
/* N..10 (Used by SRIN) */ /* N..10 (Used by SRIN) */
static int n__10(const unsigned char *data, static int n__10(const unsigned char *data,
const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) { const int data_len, int *p_err_no, int *p_err_posn, char err_msg[50]) {
@ -656,7 +675,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai == 0) { if (ai == 0) {
return n18_csum_key(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 == 1 || ai == 2) { if (ai >= 1 && ai <= 3) {
return n14_csum_key(data, data_len, p_err_no, p_err_posn, err_msg); return n14_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
} }
if (ai == 10 || ai == 21 || ai == 22) { if (ai == 10 || ai == 21 || ai == 22) {
@ -942,7 +961,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
return x__34_iban(data, data_len, p_err_no, p_err_posn, err_msg); return x__34_iban(data, data_len, p_err_no, p_err_posn, err_msg);
} }
if (ai == 8008) { if (ai == 8008) {
return n8_yymmddhh__n__4__mmoptss(data, data_len, p_err_no, p_err_posn, err_msg); return n6_yymmdd_n2_hh__n2__mm__n2__ss(data, data_len, p_err_no, p_err_posn, err_msg);
} }
if (ai == 8009) { if (ai == 8009) {
return x__50(data, data_len, p_err_no, p_err_posn, err_msg); return x__50(data, data_len, p_err_no, p_err_posn, err_msg);
@ -956,6 +975,9 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai == 8013) { if (ai == 8013) {
return x__25_csumalpha_key(data, data_len, p_err_no, p_err_posn, err_msg); return x__25_csumalpha_key(data, data_len, p_err_no, p_err_posn, err_msg);
} }
if (ai == 8014) {
return x__25_csumalpha_key_hasnondigit(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 8017 || ai == 8018) { if (ai == 8017 || ai == 8018) {
return n18_csum_key(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);
} }

File diff suppressed because it is too large Load Diff