From 9c2fbd9e11780703aa56c3ae9da5d13fcea72c24 Mon Sep 17 00:00:00 2001 From: hooper114 Date: Thu, 8 Jan 2009 08:43:25 +0000 Subject: [PATCH] Moved GS1 processing to gs1.c --- backend/Makefile | 6 +-- backend/code128.c | 69 +++++--------------------- backend/composite.c | 115 ++++++++++++-------------------------------- backend/gs1.c | 95 ++++++++++++++++++++++++++++++++++++ backend/gs1.h | 22 +++++++++ backend/rss.c | 111 +++++++++++------------------------------- 6 files changed, 190 insertions(+), 228 deletions(-) create mode 100644 backend/gs1.c create mode 100644 backend/gs1.h diff --git a/backend/Makefile b/backend/Makefile index b8f9900f..4031bdca 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -19,8 +19,8 @@ includedir := $(prefix)/include libdir := $(prefix)/lib DESTDIR := -COMMON:= common.c png.c library.c ps.c large.c reedsol.c -COMMON_OBJ:= common.o png.o library.o ps.o large.o reedsol.o +COMMON:= common.c png.c library.c ps.c large.c reedsol.c gs1.c +COMMON_OBJ:= common.o png.o library.o ps.o large.o reedsol.o gs1.o ONEDIM:= code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c ONEDIM_OBJ:= code.o code128.o 2of5.o upcean.o telepen.o medical.o plessey.o rss.o POSTAL:= postal.c auspost.c imail.c @@ -36,7 +36,7 @@ DEFINES:= LIBS+= -lqrencode endif -libzint: code.c code128.c 2of5.c upcean.c medical.c telepen.c plessey.c postal.c auspost.c imail.c code16k.c dmatrix.c dm200.c reedsol.c pdf417.c maxicode.c rss.c common.c png.c library.c ps.c qr.c large.c composite.c aztec.c blockf.c micqr.c +libzint: code.c code128.c 2of5.c upcean.c medical.c telepen.c plessey.c postal.c auspost.c imail.c code16k.c dmatrix.c dm200.c reedsol.c pdf417.c maxicode.c rss.c common.c png.c library.c ps.c qr.c large.c composite.c aztec.c blockf.c micqr.c gs1.c $(CC) -Wall -fPIC $(CFLAGS) $(ZINT_VERSION) -c $(ONEDIM) $(CC) -Wall -fPIC $(CFLAGS) $(ZINT_VERSION) -c $(POSTAL) $(CC) -Wall -fPIC $(DEFINES) $(CFLAGS) $(ZINT_VERSION) -c $(TWODIM) diff --git a/backend/code128.c b/backend/code128.c index 89b6d884..efc63651 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -24,6 +24,7 @@ #include #include #include "common.h" +#include "gs1.h" #define TRUE 1 #define FALSE 0 @@ -196,12 +197,12 @@ void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int int code_128(struct zint_symbol *symbol, unsigned char source[]) { /* Handle Code 128 and NVE-18 */ int i, j, k, e_count, values[170], bar_characters, read, total_sum, nve_check; - int errornum, indexchaine, indexliste, sourcelen; + int error_number, indexchaine, indexliste, sourcelen; char set[170], fset[170], mode, last_set, last_fset; float glyph_count; char dest[1000]; - errornum = 0; + error_number = 0; strcpy(dest, ""); sourcelen = ustrlen(source); @@ -554,19 +555,19 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) symbol->text[i] = ' '; } } - return errornum; + return error_number; } int ean_128(struct zint_symbol *symbol, unsigned char source[]) { /* Handle EAN-128 (Now known as GS1-128) */ int i, j, e_count, values[170], bar_characters, read, total_sum; - int errornum, indexchaine, indexliste, ai_latch, sourcelen; - char set[170], mode, last_set, reduced[170], ai_string[4]; + int error_number, indexchaine, indexliste, sourcelen; + char set[170], mode, last_set, reduced[ustrlen(source)]; float glyph_count; char dest[1000]; - int last_ai, separator_row, linkage_flag; + int separator_row, linkage_flag; - errornum = 0; + error_number = 0; strcpy(dest, ""); linkage_flag = 0; sourcelen = ustrlen(source); @@ -587,19 +588,6 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) strcpy(symbol->errtxt, "Input too long [161]"); return ERROR_TOO_LONG; } - - /* Detect extended ASCII characters */ - for(i = 0; i < sourcelen; i++) { - if(source[i] >=128) { - strcpy(symbol->errtxt, "Extended ASCII characters not supported by GS1-128 [162]"); - return ERROR_INVALID_DATA; - } - } - - if(source[0] != '[') { - strcpy(symbol->errtxt, "Input string doesn't start with AI [163]"); - return ERROR_INVALID_DATA; - } /* if part of a composite symbol make room for the separator pattern */ if(symbol->symbology == BARCODE_EAN128_CC) { @@ -608,43 +596,8 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) symbol->rows += 1; } - /* Resolve AI data - put resulting string in 'reduced' */ - j = 0; - last_ai = 0; - ai_latch = 1; - for(i = 0; i < sourcelen; i++) { - if((source[i] != '[') && (source[i] != ']')) { - reduced[j] = source[i]; - j++; - } - if(source[i] == '[') { - /* Start of an AI string */ - if(ai_latch == 0) { - reduced[j] = '['; - j++; - } - ai_string[0] = source[i + 1]; - ai_string[1] = source[i + 2]; - ai_string[2] = '\0'; - last_ai = atoi(ai_string); - ai_latch = 0; - /* The following values from GS1 specification figure 5.3.8.2.1 - 1 - "Element Strings with Pre-Defined Length Using Application Identifiers" */ - if((last_ai >= 0) && (last_ai <= 4)) { ai_latch = 1; } - if((last_ai >= 11) && (last_ai <= 20)) { ai_latch = 1; } - if(last_ai == 23) { ai_latch = 1; } /* legacy support - see 5.3.8.2.2 */ - if((last_ai >= 31) && (last_ai <= 36)) { ai_latch = 1; } - if(last_ai == 41) { ai_latch = 1; } - } - /* The ']' character is simply dropped from the input */ - } - reduced[j] = '\0'; - - /* the character '[' in the reduced string refers to the FNC1 character */ - - /* Note that no attempt is made to verify that the data to be encoded does - actually conform to the right data length - that is required of the person or - program inputting the data */ + error_number = gs1_verify(symbol, source, reduced); + if(error_number != 0) { return error_number; } /* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */ indexliste = 0; @@ -883,7 +836,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) } } - return errornum; + return error_number; } int nve_18(struct zint_symbol *symbol, unsigned char source[]) diff --git a/backend/composite.c b/backend/composite.c index d4c0aff0..e548ee83 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -45,6 +45,7 @@ #include "large.h" #include "composite.h" #include "pdf417.h" +#include "gs1.h" #define UINT unsigned short @@ -692,13 +693,13 @@ int cc_c(struct zint_symbol *symbol, unsigned char source[], int cc_width, int e return 0; } -int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char binary_string[], int cc_mode, int *cc_width, int *ecc, int lin_width) +int cc_binary_string(struct zint_symbol *symbol, char source[], char binary_string[], int cc_mode, int *cc_width, int *ecc, int lin_width) { /* Handles all data encodation from section 5 of ISO/IEC 24723 */ int encoding_method, read_posn, d1, d2, value, alpha_pad; int group_val, i, j, mask, ai_crop, ai_crop_posn, fnc1_latch; int ai90_mode, latch, remainder, binary_length; char date_str[4]; - char general_field[ustrlen(source)], general_field_type[ustrlen(source)]; + char general_field[strlen(source)], general_field_type[strlen(source)]; int target_bitsize; encoding_method = 1; @@ -712,7 +713,7 @@ int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char bi value = 0; target_bitsize = 0; - if((source[0] == '1') && ((source[1] == '0') || (source[1] == '1') || (source[1] == '7')) && (ustrlen(source) > 8)) { + if((source[0] == '1') && ((source[1] == '0') || (source[1] == '1') || (source[1] == '7')) && (strlen(source) > 8)) { /* Source starts (10), (11) or (17) */ encoding_method = 2; } @@ -781,7 +782,7 @@ int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char bi if (encoding_method == 3) { /* Encodation Method field of "11" - AI 90 */ - char ninety[ustrlen(source)], numeric_part[4]; + char ninety[strlen(source)], numeric_part[4]; int alpha, alphanum, numeric, test1, test2, test3, next_ai_posn; int numeric_value, table3_letter, mask; @@ -794,7 +795,7 @@ int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char bi do { ninety[i] = source[i + 2]; i++; - } while ((source[i + 2] != '[') && ((i + 2) < ustrlen(source))); + } while ((source[i + 2] != '[') && ((i + 2) < strlen(source))); ninety[i] = '\0'; /* Find out if the AI 90 data is alphabetic or numeric or both */ @@ -1080,7 +1081,7 @@ int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char bi j++; } - for(i = read_posn; i < ustrlen(source); i++) { + for(i = read_posn; i < strlen(source); i++) { general_field[j] = source[i]; j++; } @@ -1671,14 +1672,14 @@ int cc_binary_string(struct zint_symbol *symbol, unsigned char source[], char bi int composite(struct zint_symbol *symbol, unsigned char source[]) { - int errno, cc_mode, cc_width, ecc_level; - int j, last_ai, ai_latch, i, k, separator_row; - unsigned char reduced[3000]; - char binary_string[10 * ustrlen(source)], ai_string[4]; + int error_number, cc_mode, cc_width, ecc_level; + int j, i, k, separator_row; + char reduced[ustrlen(source)]; + char binary_string[10 * ustrlen(source)]; struct zint_symbol *linear; int top_shift, bottom_shift; - errno = 0; + error_number = 0; separator_row = 0; if(strlen(symbol->primary) == 0) { @@ -1691,64 +1692,10 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) return ERROR_TOO_LONG; } - if(source[0] != '[') { - strcpy(symbol->errtxt, "Data does not start with an AI [A6]"); - return ERROR_INVALID_DATA; - } - - for(i = 0; i < ustrlen(source) - 1; i++) { - if((source[i] == '[') && (source[i + 1] == '[')) { - /* Can't have nested brackets - Quit */ - strcpy(symbol->errtxt, "Nested AI detected (two or more open brackets) [A7]"); - return ERROR_INVALID_DATA; - } - } - - for(i = 0; i < ustrlen(source) - 1; i++) { - if((source[i] == ']') && (source[i + 1] == ']')) { - /* Can't have nested brackets - Quit */ - strcpy(symbol->errtxt, "Nested AI detected (two or more close brackets) [A8]"); - return ERROR_INVALID_DATA; - } - } - linear = ZBarcode_Create(); /* Symbol contains the 2D component and Linear contains the rest */ - /* Resolve AI data - put resulting string in 'reduced' */ - j = 0; - last_ai = 0; - ai_latch = 1; - for(i = 0; i < ustrlen(source); i++) { - if((source[i] != '[') && (source[i] != ']')) { - reduced[j] = source[i]; - j++; - } - if(source[i] == '[') { - /* Start of an AI string */ - if(ai_latch == 0) { - reduced[j] = '['; - j++; - } - ai_string[0] = source[i + 1]; - ai_string[1] = source[i + 2]; - ai_string[2] = '\0'; - last_ai = atoi(ai_string); - ai_latch = 0; - /* The following values from GS1 specification figure 5.3.8.2.1 - 1 - "Element Strings with Pre-Defined Length Using Application Identifiers" */ - if((last_ai >= 0) && (last_ai <= 4)) { ai_latch = 1; } - if((last_ai >= 11) && (last_ai <= 20)) { ai_latch = 1; } - if(last_ai == 23) { ai_latch = 1; } /* legacy support - see 5.3.8.2.2 */ - if((last_ai >= 31) && (last_ai <= 36)) { ai_latch = 1; } - if(last_ai == 41) { ai_latch = 1; } - } - /* The ']' character is simply dropped from the input */ - } - reduced[j] = '\0'; - - /* Note that no attempt is made to verify that the data to be encoded does - actually conform to the right data length - that is required of the person or - program inputting the data */ + error_number = gs1_verify(symbol, source, reduced); + if(error_number != 0) { return error_number; } cc_mode = symbol->option_1; @@ -1769,16 +1716,16 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) } switch(symbol->symbology) { - case BARCODE_EANX_CC: errno = eanx(linear, (unsigned char *)symbol->primary); break; - case BARCODE_EAN128_CC: errno = ean_128(linear, (unsigned char *)symbol->primary); break; - case BARCODE_RSS14_CC: errno = rss14(linear, (unsigned char *)symbol->primary); break; - case BARCODE_RSS_LTD_CC: errno = rsslimited(linear, (unsigned char *)symbol->primary); break; - case BARCODE_RSS_EXP_CC: errno = rssexpanded(linear, (unsigned char *)symbol->primary); break; - case BARCODE_UPCA_CC: errno = eanx(linear, (unsigned char *)symbol->primary); break; - case BARCODE_UPCE_CC: errno = eanx(linear, (unsigned char *)symbol->primary); break; - case BARCODE_RSS14STACK_CC: errno = rss14(linear, (unsigned char *)symbol->primary); break; - case BARCODE_RSS14_OMNI_CC: errno = rss14(linear, (unsigned char *)symbol->primary); break; - case BARCODE_RSS_EXPSTACK_CC: errno = rssexpanded(linear, (unsigned char *)symbol->primary); break; + case BARCODE_EANX_CC: error_number = eanx(linear, (unsigned char *)symbol->primary); break; + case BARCODE_EAN128_CC: error_number = ean_128(linear, (unsigned char *)symbol->primary); break; + case BARCODE_RSS14_CC: error_number = rss14(linear, (unsigned char *)symbol->primary); break; + case BARCODE_RSS_LTD_CC: error_number = rsslimited(linear, (unsigned char *)symbol->primary); break; + case BARCODE_RSS_EXP_CC: error_number = rssexpanded(linear, (unsigned char *)symbol->primary); break; + case BARCODE_UPCA_CC: error_number = eanx(linear, (unsigned char *)symbol->primary); break; + case BARCODE_UPCE_CC: error_number = eanx(linear, (unsigned char *)symbol->primary); break; + case BARCODE_RSS14STACK_CC: error_number = rss14(linear, (unsigned char *)symbol->primary); break; + case BARCODE_RSS14_OMNI_CC: error_number = rss14(linear, (unsigned char *)symbol->primary); break; + case BARCODE_RSS_EXPSTACK_CC: error_number = rssexpanded(linear, (unsigned char *)symbol->primary); break; } switch(symbol->symbology) { @@ -1810,8 +1757,8 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) strcpy(binary_string, ""); - if(errno != 0) { - return errno; + if(error_number != 0) { + return error_number; } if(cc_mode == 1) { @@ -1841,12 +1788,12 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) } switch(cc_mode) { /* Note that ecc_level is only relevant to CC-C */ - case 1: errno = cc_a(symbol, (unsigned char*)binary_string, cc_width); break; - case 2: errno = cc_b(symbol, (unsigned char*)binary_string, cc_width); break; - case 3: errno = cc_c(symbol, (unsigned char*)binary_string, cc_width, ecc_level); break; + case 1: error_number = cc_a(symbol, (unsigned char*)binary_string, cc_width); break; + case 2: error_number = cc_b(symbol, (unsigned char*)binary_string, cc_width); break; + case 3: error_number = cc_c(symbol, (unsigned char*)binary_string, cc_width, ecc_level); break; } - if(errno != 0) { + if(error_number != 0) { return ERROR_ENCODING_PROBLEM; } @@ -1924,5 +1871,5 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) ZBarcode_Delete(linear); - return errno; + return error_number; } diff --git a/backend/gs1.c b/backend/gs1.c new file mode 100644 index 00000000..d9794883 --- /dev/null +++ b/backend/gs1.c @@ -0,0 +1,95 @@ +/* gs1.c - Verifies GS1 data */ + +/* + libzint - the open source barcode library + Copyright (C) 2009 Robin Stuart + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include +#include +#include "common.h" + +int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[]) +{ + int i, j, last_ai, ai_latch; + char ai_string[4]; + + /* Detect extended ASCII characters */ + for(i = 0; i < sourcelen; i++) { + if(source[i] >=128) { + strcpy(symbol->errtxt, "Extended ASCII characters are not supported by GS1"); + return ERROR_INVALID_DATA; + } + } + + /* Start with basic tests */ + if(source[0] != '[') { + strcpy(symbol->errtxt, "Data does not start with an AI"); + return ERROR_INVALID_DATA; + } + + for(i = 0; i < ustrlen(source) - 1; i++) { + if((source[i] == '[') && (source[i + 1] == '[')) { + /* Can't have nested brackets - Quit */ + strcpy(symbol->errtxt, "Nested AI detected (two or more open brackets)"); + return ERROR_INVALID_DATA; + } + } + + for(i = 0; i < ustrlen(source) - 1; i++) { + if((source[i] == ']') && (source[i + 1] == ']')) { + /* Can't have nested brackets - Quit */ + strcpy(symbol->errtxt, "Nested AI detected (two or more close brackets)"); + return ERROR_INVALID_DATA; + } + } + + /* Resolve AI data - put resulting string in 'reduced' */ + j = 0; + last_ai = 0; + ai_latch = 1; + for(i = 0; i < ustrlen(source); i++) { + if((source[i] != '[') && (source[i] != ']')) { + reduced[j] = source[i]; + j++; + } + if(source[i] == '[') { + /* Start of an AI string */ + if(ai_latch == 0) { + reduced[j] = '['; + j++; + } + ai_string[0] = source[i + 1]; + ai_string[1] = source[i + 2]; + ai_string[2] = '\0'; + last_ai = atoi(ai_string); + ai_latch = 0; + /* The following values from GS1 specification figure 5.3.8.2.1 - 1 + "Element Strings with Pre-Defined Length Using Application Identifiers" */ + if((last_ai >= 0) && (last_ai <= 4)) { ai_latch = 1; } + if((last_ai >= 11) && (last_ai <= 20)) { ai_latch = 1; } + if(last_ai == 23) { ai_latch = 1; } /* legacy support - see 5.3.8.2.2 */ + if((last_ai >= 31) && (last_ai <= 36)) { ai_latch = 1; } + if(last_ai == 41) { ai_latch = 1; } + } + /* The ']' character is simply dropped from the input */ + } + reduced[j] = '\0'; + + /* the character '[' in the reduced string refers to the FNC1 character */ + return 0; +} \ No newline at end of file diff --git a/backend/gs1.h b/backend/gs1.h new file mode 100644 index 00000000..7d593716 --- /dev/null +++ b/backend/gs1.h @@ -0,0 +1,22 @@ +/* gs1.h - Verifies GS1 data */ + +/* + libzint - the open source barcode library + Copyright (C) 2009 Robin Stuart + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[]); \ No newline at end of file diff --git a/backend/rss.c b/backend/rss.c index 50cb9874..f923daaa 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -43,6 +43,7 @@ #include "common.h" #include "large.h" #include "rss.h" +#include "gs1.h" /********************************************************************** * combins(n,r): returns the number of Combinations of r selected from n: @@ -1016,10 +1017,10 @@ int general_rules(char field[], char type[]) } } -int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char binary_string[]) +int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_string[]) { /* Handles all data encodation from section 7.2.5 of ISO/IEC 24724 */ int encoding_method, i, mask, j, read_posn, latch; - char general_field[ustrlen(source)], general_field_type[ustrlen(source)]; + char general_field[strlen(source)], general_field_type[strlen(source)]; int remainder, d1, d2, value; char padstring[14]; @@ -1029,7 +1030,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b /* Decide whether a compressed data field is required and if so what method to use - method 2 = no compressed data field */ - if((ustrlen(source) >= 16) && ((source[0] == '0') && (source[1] == '1'))) { + if((strlen(source) >= 16) && ((source[0] == '0') && (source[1] == '1'))) { /* (01) and other AIs */ encoding_method = 1; } else { @@ -1037,10 +1038,10 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b encoding_method = 2; } - if(((ustrlen(source) >= 20) && (encoding_method == 1)) && ((source[2] == '9') && (source[16] == '3'))) { + if(((strlen(source) >= 20) && (encoding_method == 1)) && ((source[2] == '9') && (source[16] == '3'))) { /* Possibly encoding method > 2 */ - if((ustrlen(source) >= 26) && (source[17] == '1')) { + if((strlen(source) >= 26) && (source[17] == '1')) { /* Methods 3, 7, 9, 11 and 13 */ if(source[18] == '0') { @@ -1058,14 +1059,14 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b encoding_method = 7; - if((source[19] == '3') && (ustrlen(source) == 26)) { + if((source[19] == '3') && (strlen(source) == 26)) { /* (01) and (3103) */ weight = atof(weight_str) / 1000.0; if(weight <= 32.767) { encoding_method = 3; } } - if(ustrlen(source) == 34){ + if(strlen(source) == 34){ if((source[26] == '1') && (source[27] == '1')) { /* (01), (310x) and (11) - metric weight and production date */ encoding_method = 7; @@ -1090,7 +1091,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b } } - if((ustrlen(source) >= 26) && (source[17] == '2')) { + if((strlen(source) >= 26) && (source[17] == '2')) { /* Methods 4, 8, 10, 12 and 14 */ if(source[18] == '0') { @@ -1107,7 +1108,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b encoding_method = 8; - if(((source[19] == '2') || (source[19] == '3')) && (ustrlen(source) == 26)) { + if(((source[19] == '2') || (source[19] == '3')) && (strlen(source) == 26)) { /* (01) and (3202)/(3203) */ if(source[19] == '3') { @@ -1124,7 +1125,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b } - if(ustrlen(source) == 34){ + if(strlen(source) == 34){ if((source[26] == '1') && (source[27] == '1')) { /* (01), (320x) and (11) - English weight and production date */ encoding_method = 8; @@ -1166,18 +1167,18 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b switch(encoding_method) { /* Encoding method - Table 10 */ case 1: concat(binary_string, "1XX"); read_posn = 16; break; case 2: concat(binary_string, "00XX"); read_posn = 0; break; - case 3: concat(binary_string, "0100"); read_posn = ustrlen(source); break; - case 4: concat(binary_string, "0101"); read_posn = ustrlen(source); break; + case 3: concat(binary_string, "0100"); read_posn = strlen(source); break; + case 4: concat(binary_string, "0101"); read_posn = strlen(source); break; case 5: concat(binary_string, "01100XX"); read_posn = 20; break; case 6: concat(binary_string, "01101XX"); read_posn = 23; break; - case 7: concat(binary_string, "0111000"); read_posn = ustrlen(source); break; - case 8: concat(binary_string, "0111001"); read_posn = ustrlen(source); break; - case 9: concat(binary_string, "0111010"); read_posn = ustrlen(source); break; - case 10: concat(binary_string, "0111011"); read_posn = ustrlen(source); break; - case 11: concat(binary_string, "0111100"); read_posn = ustrlen(source); break; - case 12: concat(binary_string, "0111101"); read_posn = ustrlen(source); break; - case 13: concat(binary_string, "0111110"); read_posn = ustrlen(source); break; - case 14: concat(binary_string, "0111111"); read_posn = ustrlen(source); break; + case 7: concat(binary_string, "0111000"); read_posn = strlen(source); break; + case 8: concat(binary_string, "0111001"); read_posn = strlen(source); break; + case 9: concat(binary_string, "0111010"); read_posn = strlen(source); break; + case 10: concat(binary_string, "0111011"); read_posn = strlen(source); break; + case 11: concat(binary_string, "0111100"); read_posn = strlen(source); break; + case 12: concat(binary_string, "0111101"); read_posn = strlen(source); break; + case 13: concat(binary_string, "0111110"); read_posn = strlen(source); break; + case 14: concat(binary_string, "0111111"); read_posn = strlen(source); break; } /* Variable length symbol bit field is just given a place holder (XX) @@ -1374,7 +1375,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b mask = mask >> 1; } - if(ustrlen(source) == 34) { + if(strlen(source) == 34) { /* Date information is included */ date_str[0] = source[28]; date_str[1] = source[29]; @@ -1491,7 +1492,7 @@ int rss_binary_string(struct zint_symbol *symbol, unsigned char source[], char b rest of the data (if any) goes into a general-purpose data compaction field */ j = 0; - for(i = read_posn; i < ustrlen(source); i++) { + for(i = read_posn; i < strlen(source); i++) { general_field[j] = source[i]; j++; } @@ -1838,33 +1839,15 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[]) int check_char, c_odd, c_even, elements[235], pattern_width, reader, writer; int row, elements_in_sub, special_case_row, left_to_right; int codeblocks, sub_elements[235], stack_rows, current_row, current_block; - char reduced[170], ai_string[4]; - int last_ai, ai_latch, separator_row; + int separator_row; + char reduced[ustrlen(source)]; separator_row = 0; reader=0; - if(source[0] != '[') { - strcpy(symbol->errtxt, "Data does not start with an AI [311]"); - return ERROR_INVALID_DATA; - } + i = gs1_verify(symbol, source, reduced); + if(i != 0) { return i; } - for(i = 0; i < ustrlen(source) - 1; i++) { - if((source[i] == '[') && (source[i + 1] == '[')) { - /* Can't have nested brackets - Quit */ - strcpy(symbol->errtxt, "Nested AI detected (two or more open brackets) [312]"); - return ERROR_INVALID_DATA; - } - } - - for(i = 0; i < ustrlen(source) - 1; i++) { - if((source[i] == ']') && (source[i + 1] == ']')) { - /* Can't have nested brackets - Quit */ - strcpy(symbol->errtxt, "Nested AI detected (two or more close brackets) [313]"); - return ERROR_INVALID_DATA; - } - } - if((symbol->symbology == BARCODE_RSS_EXP_CC) || (symbol->symbology == BARCODE_RSS_EXPSTACK_CC)) { /* make space for a composite separator pattern */ separator_row = symbol->rows; @@ -1880,45 +1863,7 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[]) concat(binary_string, "0"); } - /* Resolve AI data - put resulting string in 'reduced' */ - j = 0; - last_ai = 0; - ai_latch = 1; - for(i = 0; i < ustrlen(source); i++) { - if((source[i] != '[') && (source[i] != ']')) { - reduced[j] = source[i]; - j++; - } - if(source[i] == '[') { - /* Start of an AI string */ - if(ai_latch == 0) { - reduced[j] = '['; - j++; - } - ai_string[0] = source[i + 1]; - ai_string[1] = source[i + 2]; - ai_string[2] = '\0'; - last_ai = atoi(ai_string); - ai_latch = 0; - /* The following values from GS1 specification figure 5.3.8.2.1 - 1 - "Element Strings with Pre-Defined Length Using Application Identifiers" */ - if((last_ai >= 0) && (last_ai <= 4)) { ai_latch = 1; } - if((last_ai >= 11) && (last_ai <= 20)) { ai_latch = 1; } - if(last_ai == 23) { ai_latch = 1; } /* legacy support - see 5.3.8.2.2 */ - if((last_ai >= 31) && (last_ai <= 36)) { ai_latch = 1; } - if(last_ai == 41) { ai_latch = 1; } - } - /* The ']' character is simply dropped from the input */ - } - reduced[j] = '\0'; - - /* the character '[' in the reduced string refers to the FNC1 character */ - - /* Note that no attempt is made to verify that the data to be encoded does - actually conform to the right data length - that is required of the person or - program inputting the data */ - - i = rss_binary_string(symbol, (unsigned char*)reduced, binary_string); + i = rss_binary_string(symbol, reduced, binary_string); if(i != 0) { return i; }