Update gen_gs1_lint.php, gs1_lint.h re fixed length * position in gs1-format-spec.txt

This commit is contained in:
gitlost 2021-02-20 22:38:20 +00:00
parent 9d023a806a
commit 7bdb7cd8c2
2 changed files with 36 additions and 36 deletions

View File

@ -35,8 +35,8 @@
#ifndef GS1_LINT_H
#define GS1_LINT_H
/* N18*,csum,key (Used by SSCC) */
static int n18__csum_key(const unsigned char *data, const int data_len,
/* N18,csum,key (Used by SSCC) */
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*/)
@ -46,8 +46,8 @@ static int n18__csum_key(const unsigned char *data, const int data_len,
&& key(data, data_len, 0, 18, 18, p_err_no, p_err_posn, err_msg, 0);
}
/* N14*,csum,key (Used by GTIN, CONTENT) */
static int n14__csum_key(const unsigned char *data, const int data_len,
/* N14,csum,key (Used by GTIN, CONTENT) */
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]) {
return data_len == 14
&& csum(data, data_len, 0, 14, 14, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -64,8 +64,8 @@ static int x__20(const unsigned char *data, const int data_len,
&& cset82(data, data_len, 0, 1, 20, p_err_no, p_err_posn, err_msg);
}
/* N6*,yymmd0 (Used by PROD DATE, DUE DATE, PACK DATE, BEST BEFORE or BEST BY...) */
static int n6__yymmd0(const unsigned char *data, const int data_len,
/* N6,yymmd0 (Used by PROD DATE, DUE DATE, PACK DATE, BEST BEFORE or BEST BY...) */
static int n6_yymmd0(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6
&& yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -73,8 +73,8 @@ static int n6__yymmd0(const unsigned char *data, const int data_len,
&& yymmd0(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg, 0);
}
/* N2* (Used by VARIANT) */
static int n2_(const unsigned char *data, const int data_len,
/* N2 (Used by VARIANT) */
static int n2(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 2
&& numeric(data, data_len, 0, 2, 2, p_err_no, p_err_posn, err_msg);
@ -132,8 +132,8 @@ static int n__8(const unsigned char *data, const int data_len,
&& numeric(data, data_len, 0, 1, 8, p_err_no, p_err_posn, err_msg);
}
/* N6* (Used by NET WEIGHT (kg), LENGTH (m), WIDTH (m), HEIGHT (m)...) */
static int n6_(const unsigned char *data, const int data_len,
/* N6 (Used by NET WEIGHT (kg), LENGTH (m), WIDTH (m), HEIGHT (m)...) */
static int n6(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg);
@ -163,13 +163,6 @@ static int n4(const unsigned char *data, const int data_len,
&& numeric(data, data_len, 0, 4, 4, p_err_no, p_err_posn, err_msg);
}
/* N6 (Used by PRICE/UoM, PRICE PER UNIT) */
static int n6(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
return data_len == 6
&& numeric(data, data_len, 0, 6, 6, p_err_no, p_err_posn, err_msg);
}
/* X..30,key (Used by GINC, GIAI - ASSEMBLY, GIAI) */
static int x__30_key(const unsigned char *data, const int data_len,
int *p_err_no, int *p_err_posn, char err_msg[50]) {
@ -190,8 +183,8 @@ static int n17_csum_key(const unsigned char *data, const int data_len,
&& key(data, data_len, 0, 17, 17, p_err_no, p_err_posn, err_msg, 0);
}
/* N13*,csum,key (Used by SHIP TO LOC, BILL TO, PURCHASE FROM, SHIP FOR LOC...) */
static int n13__csum_key(const unsigned char *data, const int data_len,
/* N13,csum,key (Used by SHIP TO LOC, BILL TO, PURCHASE FROM, SHIP FOR LOC...) */
static int n13_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 == 13
&& csum(data, data_len, 0, 13, 13, p_err_no, p_err_posn, err_msg, 1 /*length_only*/)
@ -550,19 +543,19 @@ 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_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 1 || ai == 2) {
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) {
return x__20(data, data_len, p_err_no, p_err_posn, err_msg);
}
if ((ai >= 11 && ai <= 13) || (ai >= 15 && ai <= 17)) {
return n6__yymmd0(data, data_len, p_err_no, p_err_posn, err_msg);
return n6_yymmd0(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 20) {
return n2_(data, data_len, p_err_no, p_err_posn, err_msg);
return n2(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 30 || ai == 37) {
return n__8(data, data_len, p_err_no, p_err_posn, err_msg);
@ -607,7 +600,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
return n17_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai >= 410 && ai <= 417) {
return n13__csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
return n13_csum_key(data, data_len, p_err_no, p_err_posn, err_msg);
}
if (ai == 420) {
return x__20(data, data_len, p_err_no, p_err_posn, err_msg);
@ -636,7 +629,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if ((ai >= 3100 && ai <= 3105) || (ai >= 3110 && ai <= 3115) || (ai >= 3120 && ai <= 3125)
|| (ai >= 3130 && ai <= 3135) || (ai >= 3140 && ai <= 3145) || (ai >= 3150 && ai <= 3155)
|| (ai >= 3160 && ai <= 3165)) {
return n6_(data, data_len, p_err_no, p_err_posn, err_msg);
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3300) {
@ -644,7 +637,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai <= 3205 || (ai >= 3210 && ai <= 3215) || (ai >= 3220 && ai <= 3225) || (ai >= 3230 && ai <= 3235)
|| (ai >= 3240 && ai <= 3245) || (ai >= 3250 && ai <= 3255) || (ai >= 3260 && ai <= 3265)
|| (ai >= 3270 && ai <= 3275) || (ai >= 3280 && ai <= 3285) || (ai >= 3290 && ai <= 3295)) {
return n6_(data, data_len, p_err_no, p_err_posn, err_msg);
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3400) {
@ -652,7 +645,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai <= 3305 || (ai >= 3310 && ai <= 3315) || (ai >= 3320 && ai <= 3325) || (ai >= 3330 && ai <= 3335)
|| (ai >= 3340 && ai <= 3345) || (ai >= 3350 && ai <= 3355) || (ai >= 3360 && ai <= 3365)
|| (ai >= 3370 && ai <= 3375)) {
return n6_(data, data_len, p_err_no, p_err_posn, err_msg);
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3500) {
@ -660,7 +653,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai <= 3405 || (ai >= 3410 && ai <= 3415) || (ai >= 3420 && ai <= 3425) || (ai >= 3430 && ai <= 3435)
|| (ai >= 3440 && ai <= 3445) || (ai >= 3450 && ai <= 3455) || (ai >= 3460 && ai <= 3465)
|| (ai >= 3470 && ai <= 3475) || (ai >= 3480 && ai <= 3485) || (ai >= 3490 && ai <= 3495)) {
return n6_(data, data_len, p_err_no, p_err_posn, err_msg);
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3600) {
@ -668,7 +661,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai <= 3505 || (ai >= 3510 && ai <= 3515) || (ai >= 3520 && ai <= 3525) || (ai >= 3530 && ai <= 3535)
|| (ai >= 3540 && ai <= 3545) || (ai >= 3550 && ai <= 3555) || (ai >= 3560 && ai <= 3565)
|| (ai >= 3570 && ai <= 3575)) {
return n6_(data, data_len, p_err_no, p_err_posn, err_msg);
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 3700) {
@ -676,7 +669,7 @@ static int gs1_lint(const int ai, const unsigned char *data, const int data_len,
if (ai <= 3605 || (ai >= 3610 && ai <= 3615) || (ai >= 3620 && ai <= 3625) || (ai >= 3630 && ai <= 3635)
|| (ai >= 3640 && ai <= 3645) || (ai >= 3650 && ai <= 3655) || (ai >= 3660 && ai <= 3665)
|| (ai >= 3670 && ai <= 3675) || (ai >= 3680 && ai <= 3685) || (ai >= 3690 && ai <= 3695)) {
return n6_(data, data_len, p_err_no, p_err_posn, err_msg);
return n6(data, data_len, p_err_no, p_err_posn, err_msg);
}
} else if (ai < 4000) {

View File

@ -34,7 +34,7 @@ if (($get = file_get_contents($file)) === false) {
$lines = explode("\n", $get);
$spec_ais = $spec_parts = $spec_funcs = $spec_comments = array();
$spec_ais = $spec_parts = $spec_funcs = $spec_comments = $fixed_ais = array();
$batches = array_fill(0, 100, array());
// Parse the lines into AIs and specs
@ -44,12 +44,13 @@ foreach ($lines as $line) {
if ($line === '' || $line[0] === '#') {
continue;
}
if (!preg_match('/^([0-9]+(?:-[0-9]+)?) +([NXC][0-9.][ NXC0-9.*,a-z]*)(?:# (.+))?$/', $line, $matches)) {
if (!preg_match('/^([0-9]+(?:-[0-9]+)?) +([ *] )([NXC][0-9.][ NXC0-9.,a-z]*)(?:# (.+))?$/', $line, $matches)) {
exit("$basename:" . __LINE__ . " ERROR: Could not parse line $line_no" . PHP_EOL);
}
$ai = $matches[1];
$spec = trim($matches[2]);
$comment = isset($matches[3]) ? trim($matches[3]) : '';
$fixed = trim($matches[2]);
$spec = trim($matches[3]);
$comment = isset($matches[4]) ? trim($matches[4]) : '';
if (isset($spec_ais[$spec])) {
$ais = $spec_ais[$spec];
@ -58,6 +59,9 @@ foreach ($lines as $line) {
}
if (($hyphen = strpos($ai, '-')) !== false) {
if ($fixed !== '') {
$fixed_ais[substr($ai, 0, 2)] = true;
}
$ai_s = (int) substr($ai, 0, $hyphen);
$ai_e = (int) substr($ai, $hyphen + 1);
$ais[] = array($ai_s, $ai_e);
@ -77,6 +81,9 @@ foreach ($lines as $line) {
}
}
} else {
if ($fixed !== '') {
$fixed_ais[substr($ai, 0, 2)] = true;
}
$ai = (int) $ai;
$ais[] = $ai;
$batch_idx = (int) ($ai / 100);
@ -101,7 +108,7 @@ foreach ($lines as $line) {
foreach ($parts as $part) {
$checkers = explode(',', $part);
$validator = array_shift($checkers);
if (!preg_match('/^([NXC])([0-9]+\*?)?(\.\.[0-9|]+)?$/', $validator, $matches)) {
if (!preg_match('/^([NXC])([0-9]+)?(\.\.[0-9|]+)?$/', $validator, $matches)) {
exit("$basename:" . __LINE__ . " ERROR: Could not parse validator \"$validator\" line $line_no" . PHP_EOL);
}
if (count($matches) === 3) {
@ -242,7 +249,7 @@ EOD;
// Print the spec validator/checkers functions
foreach ($spec_parts as $spec => $spec_part) {
$spec_funcs[$spec] = $spec_func = str_replace(array(' ', '.', ',', '*'), '_', strtolower($spec));
$spec_funcs[$spec] = $spec_func = str_replace(array(' ', '.', ','), '_', strtolower($spec));
$comment = '';
if (isset($spec_comments[$spec])) {
$comment = ' (Used by';