mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
C25/DBAR: use new func gs1_check_digit() for common GS1 check digit calc
CODE11/CODE39/EXCODE39/CODE93/PZN/CHANNEL/VIN/DBAR/UPCEAN: fuller error messages DATAMATRIX: look_ahead_test debug counts DBAR: consolidate option_2 cols_per_row CMakeLists.txt: restore -fno-var-tracking-assignments for gcc no DEBUG overall: suppress various warnings on various configs testcommon.c: clean-up
This commit is contained in:
@ -1386,3 +1386,17 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
|
||||
/* the character '[' in the reduced string refers to the FNC1 character */
|
||||
return error_value;
|
||||
}
|
||||
|
||||
/* Helper to return standard GS1 check digit (GS1 General Specifications 7.9.1) */
|
||||
INTERNAL char gs1_check_digit(const unsigned char source[], const int length) {
|
||||
int i;
|
||||
int count = 0;
|
||||
int factor = length & 1 ? 3 : 1;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
count += factor * ctoi(source[i]);
|
||||
factor = factor == 1 ? 3 : 1;
|
||||
}
|
||||
|
||||
return itoc((10 - (count % 10)) % 10);
|
||||
}
|
||||
|
Reference in New Issue
Block a user