From 04b9a99241464a01c05bb2fdc20d6b9a4ff26d67 Mon Sep 17 00:00:00 2001 From: hooper114 Date: Tue, 29 Sep 2009 09:45:46 +0000 Subject: [PATCH] API overhaul part 1: removal of nullchar --- backend/2of5.c | 87 ++-- backend/CMakeLists.txt | 4 +- backend/Makefile | 10 +- backend/Makefile.mingw | 4 +- backend/auspost.c | 14 +- backend/aztec.c | 44 +- backend/blockf.c | 83 ++-- backend/code.c | 132 +++--- backend/code1.c | 75 ++-- backend/code128.c | 79 ++-- backend/code16k.c | 20 +- backend/code49.c | 17 +- backend/common.c | 42 +- backend/common.h | 3 +- backend/composite.c | 44 +- backend/dm200.c | 39 +- backend/dm200.h | 2 +- backend/dmatrix.c | 56 +-- backend/gridmtx.c | 39 ++ backend/gridmtx.h | 19 + backend/imail.c | 27 +- backend/library.c | 859 ++++++++++++++++-------------------- backend/maxicode.c | 42 +- backend/medical.c | 58 +-- backend/micqr.c | 180 ++++---- backend/pdf417.c | 98 ++-- backend/pdf417.h | 2 +- backend/plessey.c | 49 +- backend/png.c | 9 +- backend/postal.c | 148 ++++--- backend/ps.c | 4 +- backend/qr.c | 64 +-- backend/rss.c | 22 +- backend/shiftjis.c | 118 +++++ backend/shiftjis.h | 27 ++ backend/svg.c | 4 +- backend/telepen.c | 46 +- backend/upcean.c | 50 ++- backend/zint.h | 18 +- backend_qt4/qzint.cpp | 4 +- frontend/main.c | 8 +- frontend_qt4/mainwindow.cpp | 2 +- 42 files changed, 1458 insertions(+), 1194 deletions(-) create mode 100644 backend/gridmtx.c create mode 100644 backend/gridmtx.h create mode 100644 backend/shiftjis.c create mode 100644 backend/shiftjis.h diff --git a/backend/2of5.c b/backend/2of5.c index ba82d87e..1b02ae49 100644 --- a/backend/2of5.c +++ b/backend/2of5.c @@ -35,7 +35,7 @@ static char *C25InterTable[10] = {"11331", "31113", "13113", "33111", "11313", " "31131", "13131"}; -int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[]) +int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */ int i, error_number; @@ -44,11 +44,11 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 80) { + if(length > 80) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -57,7 +57,7 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[]) /* start character */ concat (dest, "411111"); - for(i = 0; i <= ustrlen(source); i++) { + for(i = 0; i <= length; i++) { lookup(NESET, C25MatrixTable, source[i], dest); } @@ -69,7 +69,7 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[]) +int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 2 of 5 Industrial */ int i, error_number; @@ -78,11 +78,11 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 45) { + if(length > 45) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid character in data"); return error_number; @@ -91,7 +91,7 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[]) /* start character */ concat (dest, "313111"); - for(i = 0; i <= ustrlen(source); i++) { + for(i = 0; i <= length; i++) { lookup(NESET, C25IndustTable, source[i], dest); } @@ -103,7 +103,7 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[]) +int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 2 of 5 IATA */ int i, error_number; char dest[1000]; @@ -111,11 +111,11 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 45) { + if(length > 45) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -124,7 +124,7 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[]) /* start */ concat (dest, "1111"); - for(i = 0; i < ustrlen(source); i++) { + for(i = 0; i < length; i++) { lookup(NESET, C25IndustTable, source[i], dest); } @@ -136,7 +136,7 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[]) +int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 2 of 5 Data Logic */ int i, error_number; @@ -145,11 +145,11 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 80) { + if(length > 80) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -158,7 +158,7 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[]) /* start character */ concat (dest, "1111"); - for(i = 0; i <= ustrlen(source); i++) { + for(i = 0; i <= length; i++) { lookup(NESET, C25MatrixTable, source[i], dest); } @@ -170,7 +170,7 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[]) +int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 2 of 5 Interleaved */ int i, j, k, error_number; @@ -179,11 +179,11 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 90) { + if(length > 90) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if (error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -191,14 +191,11 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[]) /* Input must be an even number of characters for Interlaced 2 of 5 to work: if an odd number of characters has been entered then add a leading zero */ - if ((ustrlen(source)%2) != 0) + if ((length%2) != 0) { /* there are an odd number of input characters */ - unsigned int length; char temp[100]; - length = ustrlen(source); - strcpy(temp, (char*)source); source[0] = '0'; @@ -206,12 +203,13 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[]) { source[i + 1] = temp[i]; } + length++; } /* start character */ concat(dest, "1111"); - for(i = 0; i < ustrlen(source); i+=2 ) + for(i = 0; i < length; i+=2 ) { /* look up the bars and the spaces and put them in two strings */ strcpy(bars, ""); @@ -239,9 +237,9 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[]) } -int itf14(struct zint_symbol *symbol, unsigned char source[]) +int itf14(struct zint_symbol *symbol, unsigned char source[], int length) { - int i, error_number, h, zeroes; + int i, error_number, zeroes; unsigned int count, check_digit; char localstr[15]; char checkstr[3]; @@ -249,14 +247,13 @@ int itf14(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; count = 0; - h = ustrlen(source); - if(h > 13) { + if(length > 13) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid character in data"); return error_number; @@ -264,7 +261,7 @@ int itf14(struct zint_symbol *symbol, unsigned char source[]) /* Add leading zeros as required */ strcpy(localstr, ""); - zeroes = 13 - ustrlen(source); + zeroes = 13 - length; for(i = 0; i < zeroes; i++) { concat(localstr, "0"); } @@ -286,33 +283,32 @@ int itf14(struct zint_symbol *symbol, unsigned char source[]) checkstr[0] = itoc(check_digit); checkstr[1] = '\0'; concat(localstr, checkstr); - error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr); + error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr)); ustrcpy(symbol->text, (unsigned char*)localstr); return error_number; } -int dpleit(struct zint_symbol *symbol, unsigned char source[]) +int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) { /* Deutshe Post Leitcode */ int i, error_number; - unsigned int h, count, check_digit; + unsigned int count, check_digit; char localstr[15], checkstr[3]; int zeroes; error_number = 0; count = 0; - h = ustrlen(source); - if(h > 13) { + if(length > 13) { strcpy(symbol->errtxt, "Input wrong length"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } strcpy(localstr, ""); - zeroes = 13 - h; + zeroes = 13 - length; for(i = 0; i < zeroes; i++) concat(localstr, "0"); concat(localstr, (char *)source); @@ -331,31 +327,31 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[]) checkstr[0] = itoc(check_digit); checkstr[1] = '\0'; concat(localstr, checkstr); - error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr); + length = strlen(localstr); + error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, length); ustrcpy(symbol->text, (unsigned char*)localstr); return error_number; } -int dpident(struct zint_symbol *symbol, unsigned char source[]) +int dpident(struct zint_symbol *symbol, unsigned char source[], int length) { /* Deutsche Post Identcode */ int i, error_number, zeroes; - unsigned int h, count, check_digit; + unsigned int count, check_digit; char localstr[13], checkstr[3]; count = 0; - h = ustrlen(source); - if(h > 11) { + if(length > 11) { strcpy(symbol->errtxt, "Input wrong length"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } strcpy(localstr, ""); - zeroes = 11 - h; + zeroes = 11 - length; for(i = 0; i < zeroes; i++) concat(localstr, "0"); concat(localstr, (char *)source); @@ -374,7 +370,8 @@ int dpident(struct zint_symbol *symbol, unsigned char source[]) checkstr[0] = itoc(check_digit); checkstr[1] = '\0'; concat(localstr, checkstr); - error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr); + length = strlen(localstr); + error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, length); ustrcpy(symbol->text, (unsigned char*)localstr); return error_number; } diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt index 68c4f149..d7351f01 100644 --- a/backend/CMakeLists.txt +++ b/backend/CMakeLists.txt @@ -5,10 +5,10 @@ project(zint) find_package(PNG) find_package(Qr) -set(zint_COMMON_SRCS common.c library.c ps.c large.c reedsol.c gs1.c svg.c) +set(zint_COMMON_SRCS common.c library.c ps.c large.c reedsol.c gs1.c svg.c shiftjis.c) set(zint_ONEDIM_SRCS code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c) set(zint_POSTAL_SRCS postal.c auspost.c imail.c) -set(zint_TWODIM_SRCS code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c micqr.c maxicode.c composite.c aztec.c code49.c code1.c) +set(zint_TWODIM_SRCS code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c micqr.c maxicode.c composite.c aztec.c code49.c code1.c gridmtx.c) set(zint_SRCS ${zint_COMMON_SRCS} ${zint_ONEDIM_SRCS} ${zint_POSTAL_SRCS} ${zint_TWODIM_SRCS} ) if(PNG_FOUND) diff --git a/backend/Makefile b/backend/Makefile index a7fddf42..11858db9 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -19,14 +19,14 @@ includedir := $(prefix)/include libdir := $(prefix)/lib DESTDIR := -COMMON:= common.c png.c library.c ps.c large.c reedsol.c gs1.c svg.c -COMMON_OBJ:= common.o png.o library.o ps.o large.o reedsol.o gs1.o svg.o +COMMON:= common.c png.c library.c ps.c large.c reedsol.c gs1.c svg.c shiftjis.c +COMMON_OBJ:= common.o png.o library.o ps.o large.o reedsol.o gs1.o svg.o shiftjis.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 POSTAL_OBJ:= postal.o auspost.o imail.o -TWODIM:= code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c maxicode.c composite.c aztec.c micqr.c code49.c code1.c -TWODIM_OBJ:= code16k.o blockf.o dmatrix.o dm200.o pdf417.o qr.o maxicode.o composite.o aztec.o micqr.o code49.o code1.o +TWODIM:= code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c maxicode.c composite.c aztec.c micqr.c code49.c code1.c gridmtx.c +TWODIM_OBJ:= code16k.o blockf.o dmatrix.o dm200.o pdf417.o qr.o maxicode.o composite.o aztec.o micqr.o code49.o code1.o gridmtx.o LIBS:= `libpng12-config --I_opts --L_opts --ldflags` -lz -lm ifeq ($(NO_QR),true) @@ -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 gs1.c svg.c code49.c code1.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 svg.c code49.c code1.c gridmtx.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/Makefile.mingw b/backend/Makefile.mingw index 55988970..51a98cf2 100644 --- a/backend/Makefile.mingw +++ b/backend/Makefile.mingw @@ -25,10 +25,10 @@ APP:=zint DLL:=$(APP).dll STATLIB:=lib$(APP).a -COMMON_OBJ:= common.o png.o library.o ps.o large.o reedsol.o gs1.o svg.o +COMMON_OBJ:= common.o png.o library.o ps.o large.o reedsol.o gs1.o svg.o shiftjis.o ONEDIM_OBJ:= code.o code128.o 2of5.o upcean.o telepen.o medical.o plessey.o rss.o POSTAL_OBJ:= postal.o auspost.o imail.o -TWODIM_OBJ:= code16k.o blockf.o dmatrix.o dm200.o pdf417.o qr.o maxicode.o composite.o aztec.o micqr.o code49.o +TWODIM_OBJ:= code16k.o blockf.o dmatrix.o dm200.o pdf417.o qr.o maxicode.o composite.o aztec.o micqr.o code49.o code1.o gridmtx.o LIB_OBJ:= $(COMMON_OBJ) $(ONEDIM_OBJ) $(TWODIM_OBJ) $(POSTAL_OBJ) DLL_OBJ:= $(LIB_OBJ:.o=.lo) dllversion.lo diff --git a/backend/auspost.c b/backend/auspost.c index 1aa40a69..9edfb39a 100644 --- a/backend/auspost.c +++ b/backend/auspost.c @@ -94,7 +94,7 @@ void rs_error(char data_pattern[]) rs_free(); } -int australia_post(struct zint_symbol *symbol, unsigned char source[]) +int australia_post(struct zint_symbol *symbol, unsigned char source[], int length) { /* Handles Australia Posts's 4 State Codes */ /* Customer Standard Barcode, Barcode 2 or Barcode 3 system determined automatically @@ -121,13 +121,13 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[]) /* Do all of the length checking first to avoid stack smashing */ if(symbol->symbology == BARCODE_AUSPOST) { /* Format control code (FCC) */ - switch(ustrlen(source)) + switch(length) { case 8: strcpy(fcc, "11"); break; case 13: strcpy(fcc, "59"); break; - case 16: strcpy(fcc, "59"); error_number = is_sane(NESET, source); break; + case 16: strcpy(fcc, "59"); error_number = is_sane(NESET, source, length); break; case 18: strcpy(fcc, "62"); break; - case 23: strcpy(fcc, "62"); error_number = is_sane(NESET, source); break; + case 23: strcpy(fcc, "62"); error_number = is_sane(NESET, source, length); break; default: strcpy(symbol->errtxt, "Auspost input is wrong length"); return ERROR_TOO_LONG; break; @@ -148,14 +148,14 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[]) } /* Add leading zeros as required */ - zeroes = 8 - ustrlen(source); + zeroes = 8 - length; for(i = 0; i < zeroes; i++) { concat(localstr, "0"); } } concat(localstr, (char*)source); - error_number = is_sane(GDSET, (unsigned char *)localstr); + error_number = is_sane(GDSET, (unsigned char *)localstr, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -166,7 +166,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[]) dpid[loopey] = localstr[loopey]; } dpid[8] = '\0'; - error_number = is_sane(NESET, (unsigned char *)dpid); + error_number = is_sane(NESET, (unsigned char *)dpid, 8); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in DPID"); return error_number; diff --git a/backend/aztec.c b/backend/aztec.c index 38b1c8d3..5825bac3 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -655,7 +655,7 @@ int aztec_text_process(unsigned char source[], char binary_string[], int gs1) return 0; } -int aztec(struct zint_symbol *symbol, unsigned char source[]) +int aztec(struct zint_symbol *symbol, unsigned char source[], int length) { int x, y, i, j, data_blocks, ecc_blocks, layers, total_bits; char binary_string[20000], bit_pattern[20045], descriptor[42]; @@ -669,11 +669,39 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) unsigned int* ecc_part; #endif +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif + memset(binary_string,0,20000); memset(adjusted_string,0,20000); if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } - err_code = aztec_text_process(source, binary_string, gs1); + /* The following to be replaced by ECI handling */ + switch(symbol->input_mode) { + case DATA_MODE: + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + local_source[length] = '\0'; + break; + case UNICODE_MODE: + err_code = latin1_process(symbol, source, local_source, &length); + if(err_code != 0) { return err_code; } + break; + } + + /* Aztec code can't handle NULL characters */ + for(i = 0; i < length; i++) { + if(local_source[i] == '\0') { + strcpy(symbol->errtxt, "Invalid character (NULL) in input data"); + return ERROR_INVALID_DATA; + } + } + + err_code = aztec_text_process(local_source, binary_string, gs1); if(err_code != 0) { strcpy(symbol->errtxt, "Input too long or too many extended ASCII characters"); @@ -1209,26 +1237,24 @@ int aztec(struct zint_symbol *symbol, unsigned char source[]) return err_code; } -int aztec_runes(struct zint_symbol *symbol, unsigned char source[]) +int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length) { - int input_length, error_number, i, y, x; - int input_value; + int input_value, error_number, i, y, x; char binary_string[28]; unsigned char data_codewords[3], ecc_codewords[6]; error_number = 0; input_value = 0; - input_length = ustrlen(source); - if(input_length > 3) { + if(length > 3) { strcpy(symbol->errtxt, "Input too large"); return ERROR_INVALID_DATA; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number != 0) { strcpy(symbol->errtxt, "Invalid characters in input"); return ERROR_INVALID_DATA; } - switch(input_length) { + switch(length) { case 3: input_value = 100 * ctoi(source[0]); input_value += 10 * ctoi(source[1]); input_value += ctoi(source[2]); diff --git a/backend/blockf.c b/backend/blockf.c index 10d2c32b..31a895b3 100644 --- a/backend/blockf.c +++ b/backend/blockf.c @@ -59,13 +59,12 @@ static char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322", "411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232", "2331112"}; -int parunmodd(unsigned char llyth, char nullchar); +int parunmodd(unsigned char llyth); void grwp(int *indexliste); void dxsmooth(int *indexliste); -int a3_convert(unsigned char source, char nullchar) { +int a3_convert(unsigned char source) { /* Annex A section 3 */ - if(source == nullchar) { return 64; } if(source < 32) { return source + 64; } if((source >= 32) && (source <= 127)) { return source - 32; } if((source >= 128) && (source <= 159)) { return (source - 128) + 64; } @@ -73,12 +72,8 @@ int a3_convert(unsigned char source, char nullchar) { return (source - 128) - 32; } -int character_subset_select(unsigned char source[], int input_position, char nullchar) { +int character_subset_select(unsigned char source[], int input_position) { /* Section 4.5.2 - Determining the Character Subset Selector in a Row */ - if(source[input_position] == nullchar) { - /* NULL character */ - return MODEA; - } if((source[input_position] >= '0') && (source[input_position + 1] <= '9')) { /* Rule 1 */ @@ -99,7 +94,7 @@ int character_subset_select(unsigned char source[], int input_position, char nul return MODEB; } -int data_encode_blockf(unsigned char source[], int subset_selector[], int blockmatrix[][62], int *columns_needed, int *rows_needed, int *final_mode, char nullchar, int gs1) +int data_encode_blockf(unsigned char source[], int subset_selector[], int blockmatrix[][62], int *columns_needed, int *rows_needed, int *final_mode, int gs1) { int i, j, input_position, input_length, current_mode, current_row, error_number; int column_position, c, done, exit_status; @@ -120,7 +115,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm if(column_position == 0) { /* The Beginning of a row */ c = (*columns_needed); - current_mode = character_subset_select(source, input_position, nullchar); + current_mode = character_subset_select(source, input_position); subset_selector[current_row] = current_mode; if((current_row == 0) && gs1) { /* Section 4.4.7.1 */ @@ -144,15 +139,15 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm /* Ensure that there is sufficient encodation capacity to continue (using the rules of Annex B.2). */ switch(current_mode) { case MODEA: /* Table B1 applies */ - if(parunmodd(source[input_position], nullchar) == ABORC) { - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + if(parunmodd(source[input_position]) == ABORC) { + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; done = 1; } - if((parunmodd(source[input_position], nullchar) == SHIFTB) && (c == 1)) { + if((parunmodd(source[input_position]) == SHIFTB) && (c == 1)) { /* Needs two symbols */ blockmatrix[current_row][column_position] = 100; /* Code B */ column_position++; @@ -184,15 +179,15 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } break; case MODEB: /* Table B2 applies */ - if(parunmodd(source[input_position], nullchar) == ABORC) { - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + if(parunmodd(source[input_position]) == ABORC) { + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; done = 1; } - if((parunmodd(source[input_position], nullchar) == SHIFTA) && (c == 1)) { + if((parunmodd(source[input_position]) == SHIFTA) && (c == 1)) { /* Needs two symbols */ blockmatrix[current_row][column_position] = 101; /* Code A */ column_position++; @@ -224,7 +219,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } break; case MODEC: /* Table B3 applies */ - if((parunmodd(source[input_position], nullchar) != ABORC) && (c == 1)) { + if((parunmodd(source[input_position]) != ABORC) && (c == 1)) { /* Needs two symbols */ blockmatrix[current_row][column_position] = 101; /* Code A */ column_position++; @@ -232,7 +227,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm done = 1; } - if(((parunmodd(source[input_position], nullchar) == ABORC) && (parunmodd(source[input_position + 1], nullchar) != ABORC)) + if(((parunmodd(source[input_position]) == ABORC) && (parunmodd(source[input_position + 1]) != ABORC)) && (c == 1)) { /* Needs two symbols */ blockmatrix[current_row][column_position] = 101; /* Code A */ @@ -258,7 +253,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } if(done == 0) { - if(((parunmodd(source[input_position], nullchar) == AORB) || (parunmodd(source[input_position], nullchar) == SHIFTA)) && (current_mode == MODEA)) { + if(((parunmodd(source[input_position]) == AORB) || (parunmodd(source[input_position]) == SHIFTA)) && (current_mode == MODEA)) { /* Annex B section 1 rule 2 */ /* If in Code Subset A and the next data character can be encoded in Subset A encode the next character. */ @@ -268,7 +263,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm column_position++; c--; } - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -277,7 +272,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } if(done == 0) { - if(((parunmodd(source[input_position], nullchar) == AORB) || (parunmodd(source[input_position], nullchar) == SHIFTB)) && (current_mode == MODEB)) { + if(((parunmodd(source[input_position]) == AORB) || (parunmodd(source[input_position]) == SHIFTB)) && (current_mode == MODEB)) { /* Annex B section 1 rule 3 */ /* If in Code Subset B and the next data character can be encoded in subset B, encode the next character. */ @@ -287,7 +282,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm column_position++; c--; } - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -296,7 +291,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } if(done == 0) { - if(((parunmodd(source[input_position], nullchar) == ABORC) && (parunmodd(source[input_position + 1], nullchar) == ABORC)) && (current_mode == MODEC)) { + if(((parunmodd(source[input_position]) == ABORC) && (parunmodd(source[input_position + 1]) == ABORC)) && (current_mode == MODEC)) { /* Annex B section 1 rule 4 */ /* If in Code Subset C and the next data are 2 digits, encode them. */ blockmatrix[current_row][column_position] = (ctoi(source[input_position]) * 10) + ctoi(source[input_position + 1]); @@ -308,7 +303,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } if(done == 0) { - if(((current_mode == MODEA) || (current_mode == MODEB)) && ((parunmodd(source[input_position], nullchar) == ABORC) || (gs1 && (source[input_position] == '[')))) { + if(((current_mode == MODEA) || (current_mode == MODEB)) && ((parunmodd(source[input_position])== ABORC) || (gs1 && (source[input_position] == '[')))) { /* Count the number of numeric digits */ /* If 4 or more numeric data characters occur together when in subsets A or B: a. If there is an even number of numeric data characters, insert a Code C character before the @@ -321,7 +316,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm i++; if(gs1 && (source[input_position + j] == '[')) { i++; } j++; - } while((parunmodd(source[input_position + j], nullchar) == ABORC) || (gs1 && (source[input_position + j] == '['))); + } while((parunmodd(source[input_position + j]) == ABORC) || (gs1 && (source[input_position + j] == '['))); i--; if(i >= 4) { @@ -338,14 +333,14 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm current_mode = MODEC; } else { /* Annex B section 1 rule 5b */ - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; } done = 1; } else { - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -355,7 +350,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } if(done == 0) { - if((current_mode == MODEB) && (parunmodd(source[input_position], nullchar) == SHIFTA)) { + if((current_mode == MODEB) && (parunmodd(source[input_position]) == SHIFTA)) { /* Annex B section 1 rule 6 */ /* When in subset B and an ASCII control character occurs in the data: a. If there is a lower case character immediately following the control character, insert a Shift @@ -372,7 +367,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm column_position++; c--; } - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -387,7 +382,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm column_position++; c--; } - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -398,14 +393,14 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } if(done == 0) { - if((current_mode == MODEA) && (parunmodd(source[input_position], nullchar) == SHIFTB)) { + if((current_mode == MODEA) && (parunmodd(source[input_position]) == SHIFTB)) { /* Annex B section 1 rule 7 */ /* When in subset A and a lower case character occurs in the data: a. If following that character, a control character occurs in the data before the occurrence of another lower case character, insert a Shift character before the lower case character. b. Otherwise, insert a Code B character before the lower case character to change to subset B. */ - if((parunmodd(source[input_position + 1], nullchar) == SHIFTA) && - (parunmodd(source[input_position + 2], nullchar) == SHIFTB)) { + if((parunmodd(source[input_position + 1]) == SHIFTA) && + (parunmodd(source[input_position + 2]) == SHIFTB)) { /* Annex B section 1 rule 7a */ blockmatrix[current_row][column_position] = 98; /* Shift */ column_position++; @@ -416,7 +411,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm column_position++; c--; } - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -431,7 +426,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm column_position++; c--; } - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -442,8 +437,8 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm } if(done == 0) { - if((current_mode == MODEC) && ((parunmodd(source[input_position], nullchar) != ABORC) || - (parunmodd(source[input_position + 1], nullchar) != ABORC))) { + if((current_mode == MODEC) && ((parunmodd(source[input_position]) != ABORC) || + (parunmodd(source[input_position + 1]) != ABORC))) { /* Annex B section 1 rule 8 */ /* When in subset C and a non-numeric character (or a single digit) occurs in the data, insert a Code A or Code B character before that character, following rules 8a and 8b to determine between code @@ -451,7 +446,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm a. If an ASCII control character (eg NUL) occurs in the data before any lower case character, use Code A. b. Otherwise use Code B. */ - if(parunmodd(source[input_position], nullchar) == SHIFTA) { + if(parunmodd(source[input_position]) == SHIFTA) { /* Annex B section 1 rule 8a */ blockmatrix[current_row][column_position] = 101; /* Code A */ column_position++; @@ -462,7 +457,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm column_position++; c--; } - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -478,7 +473,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm column_position++; c--; } - blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar); + blockmatrix[current_row][column_position] = a3_convert(source[input_position]); column_position++; c--; input_position++; @@ -573,7 +568,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm return error_number; } -int codablock(struct zint_symbol *symbol, unsigned char source[]) +int codablock(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number, input_length, i, j, k; int rows_needed, columns_needed; @@ -588,7 +583,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[]) int gs1; error_number = 0; - input_length = ustrlen(source); + input_length = length; final_mode = MODEA; if(input_length > 5450) { @@ -602,7 +597,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[]) estimate_codelength = 0.0; last_mode = AORB; /* Codablock always starts with Code A */ for(i = 0; i < input_length; i++) { - this_mode = parunmodd(source[i], symbol->nullchar); + this_mode = parunmodd(source[i]); if(this_mode != last_mode) { estimate_codelength += 1.0; } @@ -629,7 +624,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[]) } /* Encode the data */ - error_number = data_encode_blockf(source, subset_selector, blockmatrix, &columns_needed, &rows_needed, &final_mode, symbol->nullchar, gs1); + error_number = data_encode_blockf(source, subset_selector, blockmatrix, &columns_needed, &rows_needed, &final_mode, gs1); if(error_number > 0) { if(error_number == ERROR_TOO_LONG) { strcpy(symbol->errtxt, "Input data too long"); diff --git a/backend/code.c b/backend/code.c index b7557f77..8fd2ec42 100644 --- a/backend/code.c +++ b/backend/code.c @@ -85,7 +85,7 @@ void NextB(int Chan, int i, int MaxB, int MaxS); /* *********************** CODE 11 ******************** */ -int code_11(struct zint_symbol *symbol, unsigned char source[]) +int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 11 */ unsigned int i; @@ -97,11 +97,11 @@ int code_11(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 121) { + if(length > 121) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NASET, source); + error_number = is_sane(NASET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -115,7 +115,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[]) concat (dest, "112211"); /* Draw main body of barcode */ - for(i = 0; i < ustrlen(source); i++) { + for(i = 0; i < length; i++) { lookup(NASET, C11Table, source[i], dest); if(source[i] == '-') weight[i] = 10; @@ -124,7 +124,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[]) } /* Calculate C checksum */ - for(h = (ustrlen(source) - 1); h >= 0; h--) { + for(h = (length - 1); h >= 0; h--) { c_count += (c_weight * weight[h]); c_weight++; @@ -134,10 +134,10 @@ int code_11(struct zint_symbol *symbol, unsigned char source[]) } c_digit = c_count%11; - weight[ustrlen(source)] = c_digit; + weight[length] = c_digit; /* Calculate K checksum */ - for(h = ustrlen(source); h >= 0; h--) { + for(h = length; h >= 0; h--) { k_count += (k_weight * weight[h]); k_weight++; @@ -165,14 +165,15 @@ int code_11(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int c39(struct zint_symbol *symbol, unsigned char source[]) +int c39(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 39 */ unsigned int i; unsigned int counter; char check_digit; - int h, error_number; + int error_number; char dest[775]; char localstr[3]; + unsigned char local_source[75]; error_number = 0; counter = 0; @@ -183,19 +184,22 @@ int c39(struct zint_symbol *symbol, unsigned char source[]) symbol->option_2 = 0; } - to_upper(source); if(symbol->symbology == BARCODE_LOGMARS) { - if(ustrlen(source) > 59) { + if(length > 59) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } } else { - if(ustrlen(source) > 74) { + if(length > 74) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } } - error_number = is_sane(TCSET , source); + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + to_upper(local_source); + error_number = is_sane(TCSET , local_source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -204,9 +208,9 @@ int c39(struct zint_symbol *symbol, unsigned char source[]) /* Start character */ concat(dest, "1211212111"); - for(i = 0; i < ustrlen(source); i++) { - lookup(TCSET, C39Table, source[i], dest); - counter += posn(TCSET, source[i]); + for(i = 0; i < length; i++) { + lookup(TCSET, C39Table, local_source[i], dest); + counter += posn(TCSET, local_source[i]); } if((symbol->symbology == BARCODE_LOGMARS) || (symbol->option_2 == 1)) { @@ -237,7 +241,6 @@ int c39(struct zint_symbol *symbol, unsigned char source[]) check_digit = '_'; } - h = ustrlen(source); localstr[0] = check_digit; localstr[1] = '\0'; } @@ -258,40 +261,39 @@ int c39(struct zint_symbol *symbol, unsigned char source[]) if(symbol->symbology == BARCODE_CODE39) { ustrcpy(symbol->text, (unsigned char*)"*"); - uconcat(symbol->text, source); + uconcat(symbol->text, local_source); uconcat(symbol->text, (unsigned char*)localstr); uconcat(symbol->text, (unsigned char*)"*"); } else { - ustrcpy(symbol->text, source); + ustrcpy(symbol->text, local_source); uconcat(symbol->text, (unsigned char*)localstr); } return error_number; } -int pharmazentral(struct zint_symbol *symbol, unsigned char source[]) +int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length) { /* Pharmazentral Nummer (PZN) */ int i, error_number; - unsigned int h, count, check_digit; + unsigned int count, check_digit; char localstr[10], checkstr[3]; int zeroes; error_number = 0; count = 0; - h = ustrlen(source); - if(h > 6) { + if(length > 6) { strcpy(symbol->errtxt, "Input wrong length"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } strcpy(localstr, "-"); - zeroes = 6 - h; + zeroes = 6 - length; for(i = 0; i < zeroes; i++) concat(localstr, "0"); concat(localstr, (char *)source); @@ -310,7 +312,8 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[]) return ERROR_INVALID_DATA; } concat(localstr, checkstr); - error_number = c39(symbol, (unsigned char *)localstr); + length = strlen(localstr); + error_number = c39(symbol, (unsigned char *)localstr, length); ustrcpy(symbol->text, (unsigned char *)"PZN"); uconcat(symbol->text, (unsigned char *)localstr); return error_number; @@ -319,24 +322,23 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[]) /* ************** EXTENDED CODE 39 *************** */ -int ec39(struct zint_symbol *symbol, unsigned char source[]) +int ec39(struct zint_symbol *symbol, unsigned char source[], int length) { /* Extended Code 39 - ISO/IEC 16388:2007 Annex A */ unsigned char buffer[150]; unsigned int i; - int ascii_value; int error_number; memset(buffer,0,150); error_number = 0; - if(ustrlen(source) > 74) { + if(length > 74) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - for(i = 0; i < ustrlen(source); i++) { + for(i = 0; i < length; i++) { if(source[i] > 127) { /* Cannot encode extended ASCII */ strcpy(symbol->errtxt, "Invalid characters in input data"); @@ -345,30 +347,27 @@ int ec39(struct zint_symbol *symbol, unsigned char source[]) } /* Creates a buffer string and places control characters into it */ - for(i = 0; i < ustrlen(source); i++) { - ascii_value = source[i]; - if(ascii_value == symbol->nullchar) { - concat((char*)buffer, EC39Ctrl[0]); - } else { - concat((char*)buffer, EC39Ctrl[ascii_value]); - } + for(i = 0; i < length; i++) { + concat((char*)buffer, EC39Ctrl[source[i]]); } /* Then sends the buffer to the C39 function */ - error_number = c39(symbol, buffer); + error_number = c39(symbol, buffer, ustrlen(buffer)); - ustrcpy(symbol->text, source); - for(i = 0; i < ustrlen(symbol->text); i++) { - if(symbol->text[i] == symbol->nullchar) { + for(i = 0; i < length; i++) { + if(source[i] == '\0') { symbol->text[i] = ' '; + } else { + symbol->text[i] = source[i]; } } + symbol->text[length] = '\0'; return error_number; } /* ******************** CODE 93 ******************* */ -int c93(struct zint_symbol *symbol, unsigned char source[]) +int c93(struct zint_symbol *symbol, unsigned char source[], int length) { /* Code 93 is an advancement on Code 39 and the definition is a lot tighter */ /* TCSET includes the extra characters a, b, c and d to represent Code 93 specific @@ -379,7 +378,6 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) int h, weight, c, k, values[100], error_number; char buffer[220], temp[2]; char set_copy[] = TCSET; - int ascii_value; char dest[670]; unsigned char local_source[110]; @@ -387,14 +385,16 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) strcpy(buffer, ""); strcpy(dest, ""); - if(ustrlen(source) > 107) { + if(length > 107) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - ustrcpy(local_source, source); + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } - for(i = 0; i < ustrlen(local_source); i++) { + for(i = 0; i < length; i++) { if(local_source[i] > 127) { /* Cannot encode extended ASCII */ strcpy(symbol->errtxt, "Invalid characters in input data"); @@ -406,13 +406,8 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) concat(dest, "111141"); /* Message Content */ - for(i = 0; i < ustrlen(local_source); i++) { - ascii_value = local_source[i]; - if(ascii_value == symbol->nullchar) { - concat(buffer, C93Ctrl[0]); - } else { - concat(buffer, C93Ctrl[ascii_value]); - } + for(i = 0; i < length; i++) { + concat(buffer, C93Ctrl[local_source[i]]); } /* Now we can check the true length of the barcode */ @@ -475,17 +470,19 @@ int c93(struct zint_symbol *symbol, unsigned char source[]) /* Stop character */ concat(dest, "1111411"); - h = ustrlen(local_source); - local_source[h] = set_copy[c]; - local_source[h + 1] = set_copy[k]; - local_source[h + 2] = '\0'; + local_source[length] = set_copy[c]; + local_source[length + 1] = set_copy[k]; + local_source[length + 2] = '\0'; + length += 2; expand(symbol, dest); - ustrcpy(symbol->text, local_source); - for(i = 0; i < ustrlen(symbol->text); i++) { - if(symbol->text[i] == symbol->nullchar) { + for(i = 0; i < length; i++) { + if(local_source[i] == '\0') { symbol->text[i] = ' '; + } else { + symbol->text[i] = local_source[i]; } } + symbol->text[length] = '\0'; return error_number; } @@ -540,31 +537,30 @@ void NextS(int Chan, int i, int MaxS, int MaxB) { } } -int channel_code(struct zint_symbol *symbol, unsigned char source[]) { +int channel_code(struct zint_symbol *symbol, unsigned char source[], int length) { /* Channel Code - According to ANSI/AIM BC12-1998 */ - int input_length, channels, i; + int channels, i; int error_number = 0, range = 0, zeroes; char hrt[9]; - input_length = ustrlen(source); target_value = 0; - if(input_length > 7) { + if(length > 7) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } if((symbol->option_2 < 3) || (symbol->option_2 > 8)) { channels = 0; } else { channels = symbol->option_2; } - if(channels == 0) { channels = input_length + 1; } + if(channels == 0) { channels = length + 1; } if(channels == 2) { channels = 3; } - for(i = 0; i < input_length; i++) { + for(i = 0; i < length; i++) { target_value *= 10; target_value += ctoi((char) source[i]); } @@ -589,7 +585,7 @@ int channel_code(struct zint_symbol *symbol, unsigned char source[]) { NextS(channels,3,channels,channels); strcpy(hrt, ""); - zeroes = channels - 1 - input_length; + zeroes = channels - 1 - length; for(i = 0; i < zeroes; i++) { concat(hrt, "0"); } diff --git a/backend/code1.c b/backend/code1.c index f2953189..119363c1 100644 --- a/backend/code1.c +++ b/backend/code1.c @@ -273,9 +273,8 @@ int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int return best_scheme; } -int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int target[]) +int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int target[], int length) { - int inputlen = ustrlen(source); int current_mode, next_mode; int sp, tp, gs1, i, j, latch; int c40_buffer[6], c40_p; @@ -284,14 +283,6 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t char decimal_binary[40]; int byte_start = 0; - if(symbol->nullchar != 0x00) { - for(i = 0; i < inputlen; i++) { - if(source[i] == symbol->nullchar) { - source[i] = 0x00; - } - } - } - sp = 0; tp = 0; latch = 0; @@ -327,7 +318,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t if(current_mode == C1_ASCII) { /* Step B - ASCII encodation */ next_mode = C1_ASCII; - if((inputlen - sp) >= 21) { /* Step B1 */ + if((length - sp) >= 21) { /* Step B1 */ j = 0; for(i = 0; i < 21; i++) { @@ -340,7 +331,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } } - if((next_mode == C1_ASCII) && ((inputlen - sp) >= 13)) { /* Step B2 */ + if((next_mode == C1_ASCII) && ((length - sp) >= 13)) { /* Step B2 */ j = 0; for(i = 0; i < 13; i++) { @@ -349,7 +340,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t if (j == 13) { latch = 0; - for(i = sp + 13; i < inputlen; i++) { + for(i = sp + 13; i < length; i++) { if(!((source[sp + i] >= '0') && (source[sp + i] <= '9'))) { latch = 1; } } @@ -361,13 +352,13 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } if(next_mode == C1_ASCII) { /* Step B3 */ - if(istwodigits(source, sp) && ((sp + 1) != inputlen)) { + if(istwodigits(source, sp) && ((sp + 1) != length)) { target[tp] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130; tp++; sp += 2; } else { if((gs1) && (source[sp] == '[')) { - if((inputlen - sp) >= 15) { /* Step B4 */ + if((length - sp) >= 15) { /* Step B4 */ j = 0; for(i = 0; i < 15; i++) { @@ -381,7 +372,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } } - if((inputlen - sp) >= 7) { /* Step B5 */ + if((length - sp) >= 7) { /* Step B5 */ j = 0; for(i = 0; i < 7; i++) { @@ -390,7 +381,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t if (j == 7) { latch = 0; - for(i = sp + 7; i < inputlen; i++) { + for(i = sp + 7; i < length; i++) { if(!((source[sp + i] >= '0') && (source[sp + i] <= '9'))) { latch = 1; } } @@ -406,7 +397,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t if(next_mode == C1_ASCII) { /* Step B6 */ - next_mode = c1_look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1); if(next_mode == C1_ASCII) { if(source[sp] > 127) { @@ -432,7 +423,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t next_mode = C1_C40; if(c40_p == 0) { - if((inputlen - sp) >= 12) { + if((length - sp) >= 12) { j = 0; for(i = 0; i < 12; i++) { @@ -444,18 +435,18 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } } - if((inputlen - sp) >= 8) { + if((length - sp) >= 8) { j = 0; for(i = 0; i < 8; i++) { if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } } - if((inputlen - sp) == 8) { + if((length - sp) == 8) { latch = 1; } else { latch = 1; - for(j = sp + 8; j < inputlen; j++) { + for(j = sp + 8; j < length; j++) { if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; } } } @@ -466,7 +457,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } if(!(done)) { - next_mode = c1_look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1); } } @@ -517,7 +508,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t next_mode = C1_TEXT; if(text_p == 0) { - if((inputlen - sp) >= 12) { + if((length - sp) >= 12) { j = 0; for(i = 0; i < 12; i++) { @@ -529,18 +520,18 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } } - if((inputlen - sp) >= 8) { + if((length - sp) >= 8) { j = 0; for(i = 0; i < 8; i++) { if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } } - if((inputlen - sp) == 8) { + if((length - sp) == 8) { latch = 1; } else { latch = 1; - for(j = sp + 8; j < inputlen; j++) { + for(j = sp + 8; j < length; j++) { if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; } } } @@ -551,7 +542,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } if(!(done)) { - next_mode = c1_look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1); } } @@ -602,7 +593,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t next_mode = C1_EDI; if(edi_p == 0) { - if((inputlen - sp) >= 12) { + if((length - sp) >= 12) { j = 0; for(i = 0; i < 12; i++) { @@ -614,18 +605,18 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } } - if((inputlen - sp) >= 8) { + if((length - sp) >= 8) { j = 0; for(i = 0; i < 8; i++) { if((source[sp + i] >= '0') && (source[sp + i] <= '9')) { j++; } } - if((inputlen - sp) == 8) { + if((length - sp) == 8) { latch = 1; } else { latch = 1; - for(j = sp + 8; j < inputlen; j++) { + for(j = sp + 8; j < length; j++) { if((source[j] <= '0') || (source[j] >= '9')) { latch = 0; } } } @@ -676,7 +667,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t next_mode = C1_DECIMAL; - data_left = inputlen - sp; + data_left = length - sp; decimal_count = 0; if(data_left >= 1) { @@ -831,7 +822,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t next_mode = C1_ASCII; } else { if(source[sp] <= 127) { - next_mode = c1_look_ahead_test(source, inputlen, sp, current_mode, gs1); + next_mode = c1_look_ahead_test(source, length, sp, current_mode, gs1); } } @@ -863,7 +854,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t strcpy(symbol->errtxt, "Input data too long"); return 0; } - } while (sp < inputlen); + } while (sp < length); /* Empty buffers */ if(c40_p == 2) { @@ -1015,7 +1006,7 @@ void block_copy(struct zint_symbol *symbol, char grid[][120], int start_row, int } } -int code_one(struct zint_symbol *symbol, unsigned char source[]) +int code_one(struct zint_symbol *symbol, unsigned char source[], int length) { int size = 1, i, j, data_blocks; @@ -1036,18 +1027,18 @@ int code_one(struct zint_symbol *symbol, unsigned char source[]) int stream[30]; int block_width; - if(is_sane(NESET, source) == ERROR_INVALID_DATA) { + if(is_sane(NESET, source, length) == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid input data (Version S encodes numeric input only)"); return ERROR_INVALID_DATA; } - if(ustrlen(source) > 18) { + if(length > 18) { strcpy(symbol->errtxt, "Input data too long"); return ERROR_TOO_LONG; } sub_version = 3; codewords = 12; block_width = 6; /* Version S-30 */ - if(ustrlen(source) <= 12) { sub_version = 2; codewords = 8; block_width = 4; } /* Version S-20 */ - if(ustrlen(source) <= 6) { sub_version = 1; codewords = 4; block_width = 2; } /* Version S-10 */ + if(length <= 12) { sub_version = 2; codewords = 8; block_width = 4; } /* Version S-20 */ + if(length <= 6) { sub_version = 1; codewords = 4; block_width = 2; } /* Version S-10 */ binary_load(elreg, (char *)source); hex_dump(elreg); @@ -1111,7 +1102,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[]) int data_cw, ecc_cw, block_width; for(i = 0; i < 40; i++) { data[i] = 0; } - data_length = c1_encode(symbol, source, data); + data_length = c1_encode(symbol, source, data, length); if(data_length == 0) { return ERROR_TOO_LONG; @@ -1178,7 +1169,7 @@ int code_one(struct zint_symbol *symbol, unsigned char source[]) int data_length; for(i = 0; i < 1500; i++) { data[i] = 0; } - data_length = c1_encode(symbol, source, data); + data_length = c1_encode(symbol, source, data, length); if(data_length == 0) { return ERROR_TOO_LONG; diff --git a/backend/code128.c b/backend/code128.c index 1dde8880..0ff9d5e6 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -61,12 +61,11 @@ static char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322", "2331112"}; /* Code 128 character encodation - Table 1 */ -int parunmodd(unsigned char llyth, char nullchar) +int parunmodd(unsigned char llyth) { int modd; modd = 0; - if(llyth == nullchar) { return SHIFTA; } if(llyth <= 31) { modd = SHIFTA; } if((llyth >= 32) && (llyth <= 95)) { modd = AORB; } if((llyth >= 48) && (llyth <= 57)) { modd = ABORC; } @@ -141,17 +140,10 @@ void dxsmooth(int *indexliste) } -void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars, char nullchr) +void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars) { /* Translate Code 128 Set A characters into barcodes */ /* This set handles all control characters NULL to US */ - if(source == nullchr) { /* Handle NULL character substitution */ - concat(dest, C128Table[64]); - values[(*bar_chars)] = 64; - (*bar_chars)++; - return; - } - if(source > 127) { if(source < 160) { concat(dest, C128Table[(source - 128) + 64]); @@ -197,7 +189,7 @@ void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int (*bar_chars)++; } -int code_128(struct zint_symbol *symbol, unsigned char source[]) +int code_128(struct zint_symbol *symbol, unsigned char source[], int length) { /* Handle Code 128 and NVE-18 */ int i, j, k, e_count, values[170], bar_characters, read, total_sum, nve_check; int error_number, indexchaine, indexliste, sourcelen, f_state; @@ -208,7 +200,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - sourcelen = ustrlen(source); + sourcelen = length; j = 0; e_count = 0; @@ -282,7 +274,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) indexliste = 0; indexchaine = 0; - mode = parunmodd(source[indexchaine], symbol->nullchar); + mode = parunmodd(source[indexchaine]); if((symbol->symbology == BARCODE_CODE128B) && (mode == ABORC)) { mode = AORB; } @@ -296,7 +288,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) while ((list[1][indexliste] == mode) && (indexchaine < sourcelen)) { list[0][indexliste]++; indexchaine++; - mode = parunmodd(source[indexchaine], symbol->nullchar); + mode = parunmodd(source[indexchaine]); if((symbol->symbology == BARCODE_CODE128B) && (mode == ABORC)) { mode = AORB; } @@ -539,7 +531,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) switch(set[read]) { /* Encode data characters */ case 'a': - case 'A': c128_set_a(source[read], dest, values, &bar_characters, symbol->nullchar); + case 'A': c128_set_a(source[read], dest, values, &bar_characters); read++; break; case 'b': @@ -572,32 +564,33 @@ int code_128(struct zint_symbol *symbol, unsigned char source[]) /* Stop character */ concat(dest, C128Table[106]); expand(symbol, dest); - ustrcpy(symbol->text, source); - for(i = 0; i < ustrlen(symbol->text); i++) { - if(symbol->text[i] == symbol->nullchar) { + for(i = 0; i < length; i++) { + if(source[i] == '\0') { symbol->text[i] = ' '; + } else { + symbol->text[i] = source[i]; } } + symbol->text[length] = '\0'; return error_number; } -int ean_128(struct zint_symbol *symbol, unsigned char source[]) +int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) { /* Handle EAN-128 (Now known as GS1-128) */ int i, j, e_count, values[170], bar_characters, read, total_sum; - int error_number, indexchaine, indexliste, sourcelen; + int error_number, indexchaine, indexliste; char set[170], mode, last_set; float glyph_count; char dest[1000]; int separator_row, linkage_flag, c_count; #ifndef _MSC_VER - char reduced[ustrlen(source)]; + char reduced[length]; #else - char* reduced = (char*)_alloca(ustrlen(source)); + char* reduced = (char*)_alloca(length); #endif error_number = 0; strcpy(dest, ""); linkage_flag = 0; - sourcelen = ustrlen(source); j = 0; e_count = 0; @@ -609,12 +602,19 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) set[i] = ' '; } - if(sourcelen > 160) { + if(length > 160) { /* This only blocks rediculously long input - the actual length of the resulting barcode depends on the type of data, so this is trapped later */ strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } + for(i = 0; i < length; i++) { + if(source[i] == '\0') { + /* Null characters not allowed! */ + strcpy(symbol->errtxt, "NULL character in input data"); + return ERROR_INVALID_DATA; + } + } /* if part of a composite symbol make room for the separator pattern */ if(symbol->symbology == BARCODE_EAN128_CC) { @@ -633,7 +633,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) indexliste = 0; indexchaine = 0; - mode = parunmodd(reduced[indexchaine], 0x00); + mode = parunmodd(reduced[indexchaine]); if(reduced[indexchaine] == '[') { mode = ABORC; } @@ -647,7 +647,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) while ((list[1][indexliste] == mode) && (indexchaine < strlen(reduced))) { list[0][indexliste]++; indexchaine++; - mode = parunmodd(reduced[indexchaine], 0x00); + mode = parunmodd(reduced[indexchaine]); if(reduced[indexchaine] == '[') { mode = ABORC; } } indexliste++; @@ -797,7 +797,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) { /* Encode data characters */ case 'A': case 'a': - c128_set_a(reduced[read], dest, values, &bar_characters, 0x00); + c128_set_a(reduced[read], dest, values, &bar_characters); read++; break; case 'B': @@ -884,7 +884,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) } } - for(i = 0; i <= sourcelen; i++) { + for(i = 0; i <= length; i++) { if((source[i] != '[') && (source[i] != ']')) { symbol->text[i] = source[i]; } @@ -899,21 +899,21 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int nve_18(struct zint_symbol *symbol, unsigned char source[]) +int nve_18(struct zint_symbol *symbol, unsigned char source[], int length) { /* Add check digit if encoding an NVE18 symbol */ int error_number, zeroes, i, j, nve_check, total_sum, sourcelen; unsigned char ean128_equiv[25]; memset(ean128_equiv, 0, 25); - sourcelen = ustrlen(source); + sourcelen = length; if(sourcelen > 17) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -942,34 +942,33 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[]) ean128_equiv[21] = itoc(nve_check); ean128_equiv[22] = '\0'; - error_number = ean_128(symbol, ean128_equiv); + error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv)); return error_number; } -int ean_14(struct zint_symbol *symbol, unsigned char source[]) +int ean_14(struct zint_symbol *symbol, unsigned char source[], int length) { /* EAN-14 - A version of EAN-128 */ - int input_length, i, j, count, check_digit; + int i, j, count, check_digit; int error_number, zeroes; unsigned char ean128_equiv[20]; memset(ean128_equiv, 0, 20); - input_length = ustrlen(source); - if(input_length > 13) { + if(length > 13) { strcpy(symbol->errtxt, "Input wrong length"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid character in data"); return error_number; } concat((char*)ean128_equiv, "[01]"); - zeroes = 13 - input_length; + zeroes = 13 - length; for(i = 0; i < zeroes; i++) { j = ustrlen(ean128_equiv); ean128_equiv[j] = '0'; @@ -978,7 +977,7 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[]) concat((char*)ean128_equiv, (char*)source); count = 0; - for (i = input_length - 1; i >= 0; i--) + for (i = length - 1; i >= 0; i--) { count += ctoi(source[i]); @@ -992,7 +991,7 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[]) ean128_equiv[17] = itoc(check_digit); ean128_equiv[18] = '\0'; - error_number = ean_128(symbol, ean128_equiv); + error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv)); return error_number; } diff --git a/backend/code16k.c b/backend/code16k.c index 5fc68055..b360af6a 100644 --- a/backend/code16k.c +++ b/backend/code16k.c @@ -65,7 +65,7 @@ static char *C16KStartStop[8] = {"3211", "2221", "2122", "1411", "1132", "1231", static int C16KStartValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7}; static int C16KStopValues[16] = {0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3}; -int parunmodd(unsigned char llyth, char nullchar); +int parunmodd(unsigned char llyth); void grwp16(int *indexliste) { @@ -130,14 +130,8 @@ void dxsmooth16(int *indexliste) } -void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars, char nullchar) +void c16k_set_a(unsigned char source, unsigned int values[], unsigned int *bar_chars) { - if(source == nullchar) { - values[(*bar_chars)] = 64; - (*bar_chars)++; - return; - } - if(source > 127) { if(source < 160) { values[(*bar_chars)] = source + 64 - 128; @@ -173,7 +167,7 @@ void c16k_set_c(unsigned char source_a, unsigned char source_b, unsigned int val (*bar_chars)++; } -int code16k(struct zint_symbol *symbol, unsigned char source[]) +int code16k(struct zint_symbol *symbol, unsigned char source[], int length) { char width_pattern[100]; int current_row, rows_needed, flip_flop, looper, first_check, second_check; @@ -189,7 +183,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) errornum = 0; strcpy(width_pattern, ""); - input_length = ustrlen(source); + input_length = length; if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } @@ -249,7 +243,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) indexliste = 0; indexchaine = 0; - mode = parunmodd(source[indexchaine], symbol->nullchar); + mode = parunmodd(source[indexchaine]); if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */ for(i = 0; i < 160; i++) { @@ -261,7 +255,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) while ((list[1][indexliste] == mode) && (indexchaine < input_length)) { list[0][indexliste]++; indexchaine++; - mode = parunmodd(source[indexchaine], symbol->nullchar); + mode = parunmodd(source[indexchaine]); if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */ } indexliste++; @@ -537,7 +531,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[]) { /* Encode data characters */ case 'A': case 'a': - c16k_set_a(source[read], values, &bar_characters, symbol->nullchar); + c16k_set_a(source[read], values, &bar_characters); read++; break; case 'B': diff --git a/backend/code49.c b/backend/code49.c index 277a29cc..8b259d56 100644 --- a/backend/code49.c +++ b/backend/code49.c @@ -28,7 +28,7 @@ #define INSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%!&*" /* "!" represents Shift 1 and "&" represents Shift 2, "*" represents FNC1 */ -int code_49(struct zint_symbol *symbol, unsigned char source[]) +int code_49(struct zint_symbol *symbol, unsigned char source[], int length) { int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value; char intermediate[170]; @@ -39,14 +39,14 @@ int code_49(struct zint_symbol *symbol, unsigned char source[]) char pattern[40]; int gs1; - if(ustrlen(source) > 81) { + if(length > 81) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } strcpy(intermediate, ""); - for(i = 0; i < ustrlen(source); i++) { + for(i = 0; i < length; i++) { if(source[i] > 127) { strcpy(symbol->errtxt, "Invalid characters in input data"); return ERROR_INVALID_DATA; @@ -54,14 +54,11 @@ int code_49(struct zint_symbol *symbol, unsigned char source[]) if(gs1 && (i == 0)) { concat(intermediate, "*"); /* FNC1 */ } - if(source[i] == symbol->nullchar) { - concat(intermediate, c49_table7[0]); + + if(gs1 && (source[i] == '[')) { + concat(intermediate, "*"); /* FNC1 */ } else { - if(gs1 && (source[i] == '[')) { - concat(intermediate, "*"); /* FNC1 */ - } else { - concat(intermediate, c49_table7[source[i]]); - } + concat(intermediate, c49_table7[source[i]]); } } diff --git a/backend/common.c b/backend/common.c index 2c4a548a..733818b0 100644 --- a/backend/common.c +++ b/backend/common.c @@ -88,11 +88,11 @@ void to_upper(unsigned char source[]) } } -int is_sane(char test_string[], unsigned char source[]) +int is_sane(char test_string[], unsigned char source[], int length) { /* Verifies that a string only uses valid characters */ unsigned int i, j, latch; - for(i = 0; i < ustrlen(source); i++) { + for(i = 0; i < length; i++) { latch = FALSE; for(j = 0; j < strlen(test_string); j++) { if (source[i] == test_string[j]) { latch = TRUE; } } @@ -279,3 +279,41 @@ float froundup(float input) return output; } +int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length) +{ + int j, i, next; + + /* Convert Unicode to Latin-1 for those symbologies which only support Latin-1 */ + j = 0; + i = 0; + do { + next = -1; + if(source[i] < 128) { + preprocessed[j] = source[i]; + j++; + next = i + 1; + } else { + if(source[i] == 0xC2) { + preprocessed[j] = source[i + 1]; + j++; + next = i + 2; + } + if(source[i] == 0xC3) { + preprocessed[j] = source[i + 1] + 64; + j++; + next = i + 2; + } + } + if(next == -1) { + strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)"); + return ERROR_INVALID_DATA; + } + i = next; + } while(i < *length); + preprocessed[j] = '\0'; + *length = j; + + return 0; +} + + diff --git a/backend/common.h b/backend/common.h index d4200c14..611688cb 100644 --- a/backend/common.h +++ b/backend/common.h @@ -48,7 +48,7 @@ extern void uconcat(unsigned char dest[], unsigned char source[]); extern int ctoi(char source); extern char itoc(int source); extern void to_upper(unsigned char source[]); -extern int is_sane(char test_string[], unsigned char source[]); +extern int is_sane(char test_string[], unsigned char source[], int length); extern void lookup(char set_string[], char *table[], char data, char dest[]); extern int posn(char set_string[], char data); extern void expand(struct zint_symbol *symbol, char data[]); @@ -60,6 +60,7 @@ extern void set_module(struct zint_symbol *symbol, int y_coord, int x_coord); extern void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord); extern int istwodigits(unsigned char source[], int position); extern float froundup(float input); +extern int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/backend/composite.c b/backend/composite.c index 411e0c1e..8e6378a5 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -53,11 +53,11 @@ #define UINT unsigned short int general_rules(char field[], char type[]); -int eanx(struct zint_symbol *symbol, unsigned char source[]); -int ean_128(struct zint_symbol *symbol, unsigned char source[]); -int rss14(struct zint_symbol *symbol, unsigned char source[]); -int rsslimited(struct zint_symbol *symbol, unsigned char source[]); -int rssexpanded(struct zint_symbol *symbol, unsigned char source[]); +int eanx(struct zint_symbol *symbol, unsigned char source[], int length); +int ean_128(struct zint_symbol *symbol, unsigned char source[], int length); +int rss14(struct zint_symbol *symbol, unsigned char source[], int length); +int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length); +int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length); static UINT pwr928[69][7]; @@ -368,7 +368,7 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) chainemc[mclength] = 920; mclength++; - byteprocess(chainemc, &mclength, data_string, 0, length, 0, 0x00); + byteprocess(chainemc, &mclength, data_string, 0, length, 0); /* Now figure out which variant of the symbol to use and load values accordingly */ @@ -597,7 +597,7 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) chainemc[mclength] = 920; /* CC-C identifier */ mclength++; - byteprocess(chainemc, &mclength, data_string, 0, length, 0, 0x00); + byteprocess(chainemc, &mclength, data_string, 0, length, 0); chainemc[0] = mclength; @@ -1752,16 +1752,16 @@ void add_leading_zeroes(struct zint_symbol *symbol) } } -int composite(struct zint_symbol *symbol, unsigned char source[]) +int composite(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number, cc_mode, cc_width, ecc_level; int j, i, k, separator_row; #ifndef _MSC_VER char reduced[ustrlen(source)]; - char binary_string[10 * ustrlen(source)]; + char binary_string[10 * length]; #else - char* reduced = (char*)_alloca(ustrlen(source) + 1); - char* binary_string = (char*)_alloca(20 * (ustrlen(source) + 1)); + char* reduced = (char*)_alloca(length + 1); + char* binary_string = (char*)_alloca(20 * (length + 1)); #endif struct zint_symbol *linear; int top_shift, bottom_shift; @@ -1778,7 +1778,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) add_leading_zeroes(symbol); } - if(ustrlen(source) > 2990) { + if(length > 2990) { strcpy(symbol->errtxt, "2D component input data too long"); return ERROR_TOO_LONG; } @@ -1807,16 +1807,16 @@ int composite(struct zint_symbol *symbol, unsigned char source[]) } switch(symbol->symbology) { - 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; + case BARCODE_EANX_CC: error_number = eanx(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_EAN128_CC: error_number = ean_128(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_RSS14_CC: error_number = rss14(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_RSS_LTD_CC: error_number = rsslimited(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_RSS_EXP_CC: error_number = rssexpanded(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_UPCA_CC: error_number = eanx(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_UPCE_CC: error_number = eanx(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_RSS14STACK_CC: error_number = rss14(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_RSS14_OMNI_CC: error_number = rss14(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; + case BARCODE_RSS_EXPSTACK_CC: error_number = rssexpanded(linear, (unsigned char *)symbol->primary, strlen(symbol->primary)); break; } if(error_number != 0) { diff --git a/backend/dm200.c b/backend/dm200.c index 0620ba7d..1c8a8d17 100644 --- a/backend/dm200.c +++ b/backend/dm200.c @@ -326,14 +326,14 @@ int look_ahead_test(unsigned char source[], int sourcelen, int position, int cur return best_scheme; } -int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned char target[], int *last_mode) +int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned char target[], int *last_mode, int length) { /* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate */ /* Supports encoding FNC1 in supporting systems */ int sp, tp, i, gs1; int current_mode, next_mode; - int inputlen = ustrlen(source); + int inputlen = length; int c40_buffer[6], c40_p; int text_buffer[6], text_p; int x12_buffer[6], x12_p; @@ -356,14 +356,6 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha edifact_p = 0; strcpy(binary, ""); - if(symbol->nullchar != 0x00) { - for(i = 0; i < inputlen; i++) { - if(source[i] == symbol->nullchar) { - source[i] = 0x00; - } - } - } - /* step (a) */ current_mode = DM_ASCII; next_mode = DM_ASCII; @@ -768,7 +760,7 @@ void add_tail(unsigned char target[], int tp, int tail_length, int last_mode) } } -int data_matrix_200(struct zint_symbol *symbol, unsigned char source[]) +int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length) { int inputlen, i; unsigned char binary[2000]; @@ -778,9 +770,30 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[]) int H, W, FH, FW, datablock, bytes, rsblock; int last_mode; unsigned char *grid = 0; - inputlen = ustrlen(source); + inputlen = length; + +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif + + /* The following to be replaced by ECI handling */ + switch(symbol->input_mode) { + case DATA_MODE: + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + local_source[length] = '\0'; + break; + case UNICODE_MODE: + error_number = latin1_process(symbol, source, local_source, &length); + if(error_number != 0) { return error_number; } + break; + } + + binlen = dm200encode(symbol, source, binary, &last_mode, length); - binlen = dm200encode(symbol, source, binary, &last_mode); if(binlen == 0) { strcpy(symbol->errtxt, "Data too long to fit in symbol"); return ERROR_TOO_LONG; diff --git a/backend/dm200.h b/backend/dm200.h index d10d3539..75de6072 100644 --- a/backend/dm200.h +++ b/backend/dm200.h @@ -28,7 +28,7 @@ extern "C" { #endif /* __cplusplus */ -extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[]); +extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length); #ifdef __cplusplus } diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 10dfdc75..ad9b8667 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -29,7 +29,7 @@ #ifdef _MSC_VER #include "dm200.h" #else -extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[]); +extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length); #endif #define B11SET " 0123456789" @@ -37,7 +37,7 @@ extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[]); #define B37SET " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" #define B41SET " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-/" -void crc_machine(char data_prefix_bitstream[], int scheme, unsigned char source[]) +void crc_machine(char data_prefix_bitstream[], int scheme, unsigned char source[], int length) { int input_length, i; char xor_register[17]; @@ -48,7 +48,7 @@ void crc_machine(char data_prefix_bitstream[], int scheme, unsigned char source[ char* precrc_bitstream_reversed; #endif - input_length = ustrlen(source); + input_length = length; #ifndef _MSC_VER char precrc_bitstream[(input_length * 8) + 18]; @@ -131,14 +131,14 @@ void crc_machine(char data_prefix_bitstream[], int scheme, unsigned char source[ return; } -void i1_base11(char binary_string[], unsigned char source[]) +void i1_base11(char binary_string[], unsigned char source[], int length) { int input_length, blocks, remainder, i, j; char block_binary[22]; int block_value, c[6], weight[6]; int binary_posn; - input_length = ustrlen(source); + input_length = length; binary_posn = strlen(binary_string); blocks = input_length / 6; remainder = input_length % 6; @@ -235,14 +235,14 @@ void i1_base11(char binary_string[], unsigned char source[]) return; } -void i2_base27(char binary_string[], unsigned char source[]) +void i2_base27(char binary_string[], unsigned char source[], int length) { int input_length, blocks, remainder, i, j; char block_binary[25]; int block_value, c[5], weight[5]; int binary_posn; - input_length = ustrlen(source); + input_length = length; blocks = input_length / 5; remainder = input_length % 5; binary_posn = strlen(binary_string); @@ -340,14 +340,14 @@ void i2_base27(char binary_string[], unsigned char source[]) return; } -void i3_base37(char binary_string[], unsigned char source[]) +void i3_base37(char binary_string[], unsigned char source[], int length) { int input_length, blocks, remainder, i, j; char block_binary[22]; int block_value, c[6], weight[6]; int binary_posn; - input_length = ustrlen(source); + input_length = length; blocks = input_length / 4; remainder = input_length % 4; binary_posn = strlen(binary_string); @@ -436,14 +436,14 @@ void i3_base37(char binary_string[], unsigned char source[]) return; } -void i4_base41(char binary_string[], unsigned char source[]) +void i4_base41(char binary_string[], unsigned char source[], int length) { int input_length, blocks, remainder, i, j; char block_binary[23]; int block_value, c[6], weight[6]; int binary_posn; - input_length = ustrlen(source); + input_length = length; blocks = input_length / 4; remainder = input_length % 4; binary_posn = strlen(binary_string); @@ -534,13 +534,13 @@ void i4_base41(char binary_string[], unsigned char source[]) return; } -void base128(char binary_string[], unsigned char source[]) +void base128(char binary_string[], unsigned char source[], int length) { int i, j, input_length; char block_binary[9]; int binary_posn; - input_length = ustrlen(source); + input_length = length; binary_posn = strlen(binary_string); for(i = 0; i < input_length; i++) { @@ -1078,7 +1078,7 @@ void protect_ecc140(char protected_stream[], char unprotected_stream[]) } -int matrix89(struct zint_symbol *symbol, unsigned char source[]) +int matrix89(struct zint_symbol *symbol, unsigned char source[], int length) { int i, j, input_length, scheme; char unprotected_stream[2210]; @@ -1091,7 +1091,7 @@ int matrix89(struct zint_symbol *symbol, unsigned char source[]) int symbol_size, hex_segment, width; int error_number; - input_length = ustrlen(source); + input_length = length; error_number = 0; symbol_size = 0; @@ -1104,10 +1104,10 @@ int matrix89(struct zint_symbol *symbol, unsigned char source[]) /* Decide which encoding scheme to use */ scheme = 128; - if(!(is_sane(B41SET, source))) { scheme = 41; } - if(!(is_sane(B37SET, source))) { scheme = 37; } - if(!(is_sane(B27SET, source))) { scheme = 27; } - if(!(is_sane(B11SET, source))) { scheme = 11; } + if(!(is_sane(B41SET, source, length))) { scheme = 41; } + if(!(is_sane(B37SET, source, length))) { scheme = 37; } + if(!(is_sane(B27SET, source, length))) { scheme = 27; } + if(!(is_sane(B11SET, source, length))) { scheme = 11; } /* Data Prefix Bit Stream = Format ID + CRC + Data Length */ @@ -1121,7 +1121,7 @@ int matrix89(struct zint_symbol *symbol, unsigned char source[]) } /* CRC Value (16 bit) */ - crc_machine(data_prefix_bitstream, scheme, source); + crc_machine(data_prefix_bitstream, scheme, source, length); /* Data length (9 bit) */ if(input_length & 0x01) { concat(data_prefix_bitstream, "1"); } else { concat(data_prefix_bitstream, "0"); } @@ -1167,11 +1167,11 @@ int matrix89(struct zint_symbol *symbol, unsigned char source[]) } switch(scheme) { - case 11: i1_base11(unprotected_stream, source); break; - case 27: i2_base27(unprotected_stream, source); break; - case 37: i3_base37(unprotected_stream, source); break; - case 41: i4_base41(unprotected_stream, source); break; - default: base128(unprotected_stream, source); break; + case 11: i1_base11(unprotected_stream, source, length); break; + case 27: i2_base27(unprotected_stream, source, length); break; + case 37: i3_base37(unprotected_stream, source, length); break; + case 41: i4_base41(unprotected_stream, source, length); break; + default: base128(unprotected_stream, source, length); break; } /* Header (ECC Bit field) LSB first */ @@ -1307,16 +1307,16 @@ int matrix89(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int dmatrix(struct zint_symbol *symbol, unsigned char source[]) +int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number; if(symbol->option_1 <= 1) { /* ECC 200 */ - error_number = data_matrix_200(symbol, source); + error_number = data_matrix_200(symbol, source, length); } else { /* ECC 000 - 140 */ - error_number = matrix89(symbol, source); + error_number = matrix89(symbol, source, length); } return error_number; diff --git a/backend/gridmtx.c b/backend/gridmtx.c new file mode 100644 index 00000000..847a2592 --- /dev/null +++ b/backend/gridmtx.c @@ -0,0 +1,39 @@ +/* gridmtx.c - Grid Matrix + + 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. +*/ + +/* This file impliments Grid Matrix as specified in + AIM Global Document Number AIMD014 Rev. 1.63 Revised 9 Dec 2008 */ + +#include +#include +#include +#ifdef _MSC_VER +#include +#endif +#include "common.h" +#include "reedsol.h" +#include "gridmtx.h" + +int grid_matrix(struct zint_symbol *symbol, unsigned char source[]) +{ + + strcpy(symbol->errtxt, "Grid Matrix not yet implemented"); + return ERROR_INVALID_OPTION; +} \ No newline at end of file diff --git a/backend/gridmtx.h b/backend/gridmtx.h new file mode 100644 index 00000000..9824a3d1 --- /dev/null +++ b/backend/gridmtx.h @@ -0,0 +1,19 @@ +/* gridmtx.h - definitions for Grid Matrix + + 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. +*/ \ No newline at end of file diff --git a/backend/imail.c b/backend/imail.c index 3824d92b..bd2b01b1 100644 --- a/backend/imail.c +++ b/backend/imail.c @@ -24,15 +24,16 @@ static short int BCD[40] = { 0, 0, 0, 0, - 1, 0, 0, 0, - 0, 1, 0, 0, - 1, 1, 0, 0, - 0, 0, 1, 0, - 1, 0, 1, 0, - 0, 1, 1, 0, - 1, 1, 1, 0, - 0, 0, 0, 1, - 1, 0, 0, 1 }; + 1, 0, 0, 0, + 0, 1, 0, 0, + 1, 1, 0, 0, + 0, 0, 1, 0, + 1, 0, 1, 0, + 0, 1, 1, 0, + 1, 1, 1, 0, + 0, 0, 0, 1, + 1, 0, 0, 1 +}; #include #include @@ -305,7 +306,7 @@ void breakup(short int fcs_bit[], unsigned short usps_crc) } } -int imail(struct zint_symbol *symbol, unsigned char source[]) +int imail(struct zint_symbol *symbol, unsigned char source[], int length) { char data_pattern[200]; int error_number; @@ -320,11 +321,11 @@ int imail(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; - if(ustrlen(source) > 32) { + if(length > 32) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NASET, source); + error_number = is_sane(NASET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -337,7 +338,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[]) read = 0; j = 0; - for(i = 0; i < ustrlen(source); i++) { + for(i = 0; i < length; i++) { if(source[i] == '-') { tracker[read] = '\0'; j = 1; diff --git a/backend/library.c b/backend/library.c index c25b6f9c..a7299e93 100644 --- a/backend/library.c +++ b/backend/library.c @@ -26,7 +26,6 @@ #endif #include "common.h" #include "gs1.h" -#include "sjis.h" #define HIBCSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%" @@ -72,60 +71,61 @@ int ZBarcode_Delete(struct zint_symbol *symbol) return 0; } -extern int eanx(struct zint_symbol *symbol, unsigned char source[]); /* EAN system barcodes */ -extern int c39(struct zint_symbol *symbol, unsigned char source[]); /* Code 3 from 9 (or Code 39) */ -extern int pharmazentral(struct zint_symbol *symbol, unsigned char source[]); /* Pharmazentral Nummer (PZN) */ -extern int ec39(struct zint_symbol *symbol, unsigned char source[]); /* Extended Code 3 from 9 (or Code 39+) */ -extern int codabar(struct zint_symbol *symbol, unsigned char source[]); /* Codabar - a simple substitution cipher */ -extern int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[]); /* Code 2 of 5 Standard (& Matrix) */ -extern int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[]); /* Code 2 of 5 Industrial */ -extern int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[]); /* Code 2 of 5 IATA */ -extern int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[]); /* Code 2 of 5 Interleaved */ -extern int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[]); /* Code 2 of 5 Data Logic */ -extern int itf14(struct zint_symbol *symbol, unsigned char source[]); /* ITF-14 */ -extern int dpleit(struct zint_symbol *symbol, unsigned char source[]); /* Deutsche Post Leitcode */ -extern int dpident(struct zint_symbol *symbol, unsigned char source[]); /* Deutsche Post Identcode */ -extern int c93(struct zint_symbol *symbol, unsigned char source[]); /* Code 93 - a re-working of Code 39+, generates 2 check digits */ -extern int code_128(struct zint_symbol *symbol, unsigned char source[]); /* Code 128 and NVE-18 */ -extern int ean_128(struct zint_symbol *symbol, unsigned char source[]); /* EAN-128 (GS1-128) */ -extern int code_11(struct zint_symbol *symbol, unsigned char source[]); /* Code 11 */ -extern int msi_handle(struct zint_symbol *symbol, unsigned char source[]); /* MSI Plessey */ -extern int telepen(struct zint_symbol *symbol, unsigned char source[]); /* Telepen ASCII */ -extern int telepen_num(struct zint_symbol *symbol, unsigned char source[]); /* Telepen Numeric */ -extern int plessey(struct zint_symbol *symbol, unsigned char source[]); /* Plessey Code */ -extern int pharma_one(struct zint_symbol *symbol, unsigned char source[]); /* Pharmacode One Track */ -extern int flattermarken(struct zint_symbol *symbol, unsigned char source[]); /* Flattermarken */ -extern int fim(struct zint_symbol *symbol, unsigned char source[]); /* Facing Identification Mark */ -extern int pharma_two(struct zint_symbol *symbol, unsigned char source[]); /* Pharmacode Two Track */ -extern int post_plot(struct zint_symbol *symbol, unsigned char source[]); /* Postnet */ -extern int planet_plot(struct zint_symbol *symbol, unsigned char source[]); /* PLANET */ -extern int imail(struct zint_symbol *symbol, unsigned char source[]); /* Intelligent Mail (aka USPS OneCode) */ -extern int royal_plot(struct zint_symbol *symbol, unsigned char source[]); /* RM4SCC */ -extern int australia_post(struct zint_symbol *symbol, unsigned char source[]); /* Australia Post 4-state */ -extern int code16k(struct zint_symbol *symbol, unsigned char source[]); /* Code 16k */ -extern int pdf417enc(struct zint_symbol *symbol, unsigned char source[]); /* PDF417 */ -extern int dmatrix(struct zint_symbol *symbol, unsigned char source[]); /* Data Matrix (IEC16022) */ -extern int qr_code(struct zint_symbol *symbol, unsigned char source[]); /* QR Code */ -extern int micro_pdf417(struct zint_symbol *symbol, unsigned char source[]); /* Micro PDF417 */ -extern int maxicode(struct zint_symbol *symbol, unsigned char source[]); /* Maxicode */ -extern int rss14(struct zint_symbol *symbol, unsigned char source[]); /* RSS-14 */ -extern int rsslimited(struct zint_symbol *symbol, unsigned char source[]); /* RSS Limited */ -extern int rssexpanded(struct zint_symbol *symbol, unsigned char source[]); /* RSS Expanded */ -extern int composite(struct zint_symbol *symbol, unsigned char source[]); /* Composite Symbology */ -extern int kix_code(struct zint_symbol *symbol, unsigned char source[]); /* TNT KIX Code */ -extern int aztec(struct zint_symbol *symbol, unsigned char source[]); /* Aztec Code */ -extern int code32(struct zint_symbol *symbol, unsigned char source[]); /* Italian Pharmacode */ -extern int codablock(struct zint_symbol *symbol, unsigned char source[]); /* Codablock F */ -extern int daft_code(struct zint_symbol *symbol, unsigned char source[]); /* DAFT Code */ -extern int ean_14(struct zint_symbol *symbol, unsigned char source[]); /* EAN-14 */ -extern int nve_18(struct zint_symbol *symbol, unsigned char source[]); /* NVE-18 */ -extern int microqr(struct zint_symbol *symbol, unsigned char source[]); /* Micro QR Code */ -extern int aztec_runes(struct zint_symbol *symbol, unsigned char source[]); /* Aztec Runes */ -extern int korea_post(struct zint_symbol *symbol, unsigned char source[]); /* Korea Post */ -extern int japan_post(struct zint_symbol *symbol, unsigned char source[]); /* Japanese Post */ -extern int code_49(struct zint_symbol *symbol, unsigned char source[]); /* Code 49 */ -extern int channel_code(struct zint_symbol *symbol, unsigned char source[]); /* Channel Code */ -extern int code_one(struct zint_symbol *symbol, unsigned char source[]); /* Code One */ +extern int eanx(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN system barcodes */ +extern int c39(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 3 from 9 (or Code 39) */ +extern int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmazentral Nummer (PZN) */ +extern int ec39(struct zint_symbol *symbol, unsigned char source[], int length); /* Extended Code 3 from 9 (or Code 39+) */ +extern int codabar(struct zint_symbol *symbol, unsigned char source[], int length); /* Codabar - a simple substitution cipher */ +extern int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Standard (& Matrix) */ +extern int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Industrial */ +extern int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 IATA */ +extern int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Interleaved */ +extern int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Data Logic */ +extern int itf14(struct zint_symbol *symbol, unsigned char source[], int length); /* ITF-14 */ +extern int dpleit(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Leitcode */ +extern int dpident(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Identcode */ +extern int c93(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 93 - a re-working of Code 39+, generates 2 check digits */ +extern int code_128(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 128 and NVE-18 */ +extern int ean_128(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-128 (GS1-128) */ +extern int code_11(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 11 */ +extern int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length); /* MSI Plessey */ +extern int telepen(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen ASCII */ +extern int telepen_num(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen Numeric */ +extern int plessey(struct zint_symbol *symbol, unsigned char source[], int length); /* Plessey Code */ +extern int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode One Track */ +extern int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length); /* Flattermarken */ +extern int fim(struct zint_symbol *symbol, unsigned char source[], int length); /* Facing Identification Mark */ +extern int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmacode Two Track */ +extern int post_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* Postnet */ +extern int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* PLANET */ +extern int imail(struct zint_symbol *symbol, unsigned char source[], int length); /* Intelligent Mail (aka USPS OneCode) */ +extern int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length); /* RM4SCC */ +extern int australia_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Australia Post 4-state */ +extern int code16k(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 16k */ +extern int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length); /* PDF417 */ +extern int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Data Matrix (IEC16022) */ +extern int qr_code(struct zint_symbol *symbol, unsigned char source[], int length); /* QR Code */ +extern int micro_pdf417(struct zint_symbol *symbol, unsigned char source[], int length); /* Micro PDF417 */ +extern int maxicode(struct zint_symbol *symbol, unsigned char source[], int length); /* Maxicode */ +extern int rss14(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS-14 */ +extern int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Limited */ +extern int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length); /* RSS Expanded */ +extern int composite(struct zint_symbol *symbol, unsigned char source[], int length); /* Composite Symbology */ +extern int kix_code(struct zint_symbol *symbol, unsigned char source[], int length); /* TNT KIX Code */ +extern int aztec(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Code */ +extern int code32(struct zint_symbol *symbol, unsigned char source[], int length); /* Italian Pharmacode */ +extern int codablock(struct zint_symbol *symbol, unsigned char source[], int length); /* Codablock F */ +extern int daft_code(struct zint_symbol *symbol, unsigned char source[], int length); /* DAFT Code */ +extern int ean_14(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-14 */ +extern int nve_18(struct zint_symbol *symbol, unsigned char source[], int length); /* NVE-18 */ +extern int microqr(struct zint_symbol *symbol, unsigned char source[], int length); /* Micro QR Code */ +extern int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length); /* Aztec Runes */ +extern int korea_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Korea Post */ +extern int japan_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Japanese Post */ +extern int code_49(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 49 */ +extern int channel_code(struct zint_symbol *symbol, unsigned char source[], int length); /* Channel Code */ +extern int code_one(struct zint_symbol *symbol, unsigned char source[], int length); /* Code One */ +extern int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Grid Matrix */ #ifndef NO_PNG int png_handle(struct zint_symbol *symbol, int rotate_angle); @@ -151,20 +151,29 @@ void error_tag(char error_string[], int error_number) } } -int hibc(struct zint_symbol *symbol, unsigned char source[]) +int hibc(struct zint_symbol *symbol, unsigned char source[], int length) { - int counter, srclen, error_number, i; + int counter, error_number, i; char to_process[40], temp[3], check_digit; - srclen = ustrlen(source); strcpy(temp, ""); - to_upper(source); - if(srclen > 36) { +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif + + if(length > 36) { strcpy(symbol->errtxt, "Data too long for HIBC LIC"); return ERROR_TOO_LONG; } - error_number = is_sane(HIBCSET , source); + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + local_source[length] = '\0'; + to_upper(local_source); + error_number = is_sane(HIBCSET , local_source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -172,8 +181,8 @@ int hibc(struct zint_symbol *symbol, unsigned char source[]) strcpy(to_process, "+"); counter = 41; - for(i = 0; i < ustrlen(source); i++) { - counter += posn(HIBCSET, source[i]); + for(i = 0; i < length; i++) { + counter += posn(HIBCSET, local_source[i]); } counter = counter % 43; @@ -199,159 +208,44 @@ int hibc(struct zint_symbol *symbol, unsigned char source[]) temp[0] = check_digit; temp[1] = '\0'; - concat(to_process, (char *)source); + concat(to_process, (char *)local_source); concat(to_process, temp); + length = strlen(to_process); switch(symbol->symbology) { case BARCODE_HIBC_128: - error_number = code_128(symbol, (unsigned char *)to_process); + error_number = code_128(symbol, (unsigned char *)to_process, length); ustrcpy(symbol->text, (unsigned char*)"*"); uconcat(symbol->text, (unsigned char*)to_process); uconcat(symbol->text, (unsigned char*)"*"); break; case BARCODE_HIBC_39: symbol->option_2 = 0; - error_number = c39(symbol, (unsigned char *)to_process); + error_number = c39(symbol, (unsigned char *)to_process, length); ustrcpy(symbol->text, (unsigned char*)"*"); uconcat(symbol->text, (unsigned char*)to_process); uconcat(symbol->text, (unsigned char*)"*"); break; case BARCODE_HIBC_DM: - error_number = dmatrix(symbol, (unsigned char *)to_process); + error_number = dmatrix(symbol, (unsigned char *)to_process, length); break; case BARCODE_HIBC_QR: - error_number = qr_code(symbol, (unsigned char *)to_process); + error_number = qr_code(symbol, (unsigned char *)to_process, length); break; case BARCODE_HIBC_PDF: - error_number = pdf417enc(symbol, (unsigned char *)to_process); + error_number = pdf417enc(symbol, (unsigned char *)to_process, length); break; case BARCODE_HIBC_MICPDF: - error_number = micro_pdf417(symbol, (unsigned char *)to_process); + error_number = micro_pdf417(symbol, (unsigned char *)to_process, length); break; case BARCODE_HIBC_BLOCKF: - error_number = codablock(symbol, (unsigned char *)to_process); + error_number = codablock(symbol, (unsigned char *)to_process, length); break; } return error_number; } - -int eci_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[]) -{ - int j, i, next, input_length; - - input_length = ustrlen(source); - - /* Supports UTF-8 input by converting it to Latin-1 Extended ASCII */ - /* Currently only supports Latin-1 characters but expect this to be expanded - to the full ECI spectrum */ - j = 0; - i = 0; - do { - next = -1; - if(source[i] < 128) { - preprocessed[j] = source[i]; - j++; - next = i + 1; - } else { - if(source[i] == 0xC2) { - preprocessed[j] = source[i + 1]; - j++; - next = i + 2; - } - if(source[i] == 0xC3) { - preprocessed[j] = source[i + 1] + 64; - j++; - next = i + 2; - } - } - if(next == -1) { - strcpy(symbol->errtxt, "error: Invalid character in input string (only Latin-1 characters supported)"); - return ERROR_INVALID_DATA; - } - i = next; - } while(i < input_length); - preprocessed[j] = '\0'; - - return 0; -} - -int unicode2shift_jis(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[]) -{ /* QR Code supports compression of Shift-JIS data using "Kanji" mode - this function - attempts to convert Unicode characters to Shift-JIS to allow this */ - int bpos, jpos, len, error_number, i; - int next; - unsigned long int uval, jval; - - len = ustrlen(source); - - bpos = 0; - jpos = 0; - error_number = 0; - next = 0; - - do { - uval = 0; - jval = 0; - - if(source[bpos] <= 0x7f) { - /* 1 byte mode */ - uval = source[bpos]; - next = bpos + 1; - } - - if((source[bpos] >= 0x80) && (source[bpos] <= 0xbf)) { - strcpy(symbol->errtxt, "Corrupt Unicode data"); - return ERROR_INVALID_DATA; - } - - if((source[bpos] >= 0xc0) && (source[bpos] <= 0xc1)) { - strcpy(symbol->errtxt, "Overlong encoding not supported"); - return ERROR_INVALID_DATA; - } - - if((source[bpos] >= 0xc2) && (source[bpos] <= 0xdf)) { - /* 2 byte mode */ - uval = ((source[bpos] & 0x1f) << 6) + (source[bpos + 1] & 0x3f); - next = bpos + 2; - } - - if((source[bpos] >= 0xe0) && (source[bpos] <= 0xef)) { - /* 3 byte mode */ - uval = ((source[bpos] & 0x0f) << 12) + ((source[bpos + 1] & 0x3f) << 6) + (source[bpos + 2] & 0x3f); - next = bpos + 3; - } - - if(source[bpos] >= 0xf0) { - strcpy(symbol->errtxt, "Unicode sequences of more than 3 bytes not supported"); - return ERROR_INVALID_DATA; - } - - for(i = 0; i < 6843; i++) { - if(sjis_lookup[i * 2] == uval) { - jval = sjis_lookup[(i * 2) + 1]; - } - } - - if(jval == 0) { - strcpy(symbol->errtxt, "Invalid Shift JIS character"); - return ERROR_INVALID_DATA; - } - - preprocessed[jpos] = (jval & 0xff00) >> 8; - preprocessed[jpos + 1] = (jval & 0xff); - - /* printf("Unicode value U+%04X = Shift JIS value 0x%04X\n", uval, jval); */ - - jpos += 2; - bpos = next; - - } while(bpos < len); - - return error_number; -} - int gs1_compliant(int symbology) { /* Returns 1 if symbology supports GS1 data */ @@ -386,78 +280,252 @@ int gs1_compliant(int symbology) return result; } -int ZBarcode_Check_Supported(int symbol_id) +int ZBarcode_ValidID(int symbol_id) { /* Checks whether a symbology is supported */ - int value; - + int result = 0; + switch(symbol_id) { - case 5: - case 10: - case 11: - case 12: - case 14: - case 15: - case 17: - case 19: - case 26: - case 27: - case 33: - case 35: - case 36: - case 38: - case 39: - case 48: - case 54: -#ifdef NO_QR - case 58: + case BARCODE_CODE11: + case BARCODE_C25MATRIX: + case BARCODE_C25INTER: + case BARCODE_C25IATA: + case BARCODE_C25LOGIC: + case BARCODE_C25IND: + case BARCODE_CODE39: + case BARCODE_EXCODE39: + case BARCODE_EANX: + case BARCODE_EAN128: + case BARCODE_CODABAR: + case BARCODE_CODE128: + case BARCODE_DPLEIT: + case BARCODE_DPIDENT: + case BARCODE_CODE16K: + case BARCODE_CODE49: + case BARCODE_CODE93: + case BARCODE_FLAT: + case BARCODE_RSS14: + case BARCODE_RSS_LTD: + case BARCODE_RSS_EXP: + case BARCODE_TELEPEN: + case BARCODE_UPCA: + case BARCODE_UPCE: + case BARCODE_POSTNET: + case BARCODE_MSI_PLESSEY: + case BARCODE_FIM: + case BARCODE_LOGMARS: + case BARCODE_PHARMA: + case BARCODE_PZN: + case BARCODE_PHARMA_TWO: + case BARCODE_PDF417: + case BARCODE_PDF417TRUNC: + case BARCODE_MAXICODE: +#ifndef NO_QR + case BARCODE_QRCODE: #endif - case 59: - case 61: - case 62: - case 64: - case 65: - case 73: - case 78: - case 83: - case 88: - case 91: - case 100: - case 101: - case 103: - case 105: - case 107: - case 109: - value = 0; break; - default: - value = 1; break; + case BARCODE_CODE128B: + case BARCODE_AUSPOST: + case BARCODE_AUSREPLY: + case BARCODE_AUSROUTE: + case BARCODE_AUSREDIRECT: + case BARCODE_ISBNX: + case BARCODE_RM4SCC: + case BARCODE_DATAMATRIX: + case BARCODE_EAN14: + case BARCODE_CODABLOCKF: + case BARCODE_NVE18: + case BARCODE_JAPANPOST: + case BARCODE_KOREAPOST: + case BARCODE_RSS14STACK: + case BARCODE_RSS14STACK_OMNI: + case BARCODE_RSS_EXPSTACK: + case BARCODE_PLANET: + case BARCODE_MICROPDF417: + case BARCODE_ONECODE: + case BARCODE_PLESSEY: + case BARCODE_TELEPEN_NUM: + case BARCODE_ITF14: + case BARCODE_KIX: + case BARCODE_AZTEC: + case BARCODE_DAFT: + case BARCODE_MICROQR: + case BARCODE_HIBC_128: + case BARCODE_HIBC_39: + case BARCODE_HIBC_DM: + case BARCODE_HIBC_QR: + case BARCODE_HIBC_PDF: + case BARCODE_HIBC_MICPDF: + case BARCODE_HIBC_BLOCKF: + case BARCODE_AZRUNE: + case BARCODE_CODE32: + case BARCODE_EANX_CC: + case BARCODE_EAN128_CC: + case BARCODE_RSS14_CC: + case BARCODE_RSS_LTD_CC: + case BARCODE_RSS_EXP_CC: + case BARCODE_UPCA_CC: + case BARCODE_UPCE_CC: + case BARCODE_RSS14STACK_CC: + case BARCODE_RSS14_OMNI_CC: + case BARCODE_RSS_EXPSTACK_CC: + case BARCODE_CHANNEL: + case BARCODE_CODEONE: + /* case BARCODE_GRIDMATRIX: */ + result = 1; + break; } - if(symbol_id < 1) { value = 0; } - if(symbol_id > 141) { value = 0; } - if((symbol_id >= 41) && (symbol_id <= 46)) { value = 0; } - if((symbol_id >= 94) && (symbol_id <= 96)) { value = 0; } - if((symbol_id >= 111) && (symbol_id <= 127)) { value = 0; } - - return value; + return result; } -int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) +int extended_charset(struct zint_symbol *symbol, unsigned char *source, int length) { - int error_number, error_buffer; - int input_length; + int error_number = 0; + + /* These are the "elite" standards which can support multiple languages */ + switch(symbol->symbology) { + case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, source, length); break; + case BARCODE_PDF417: error_number = pdf417enc(symbol, source, length); break; + case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, source, length); break; + case BARCODE_QRCODE: error_number = qr_code(symbol, source, length); break; + case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, source, length); break; + case BARCODE_MAXICODE: error_number = maxicode(symbol, source, length); break; + case BARCODE_AZTEC: error_number = aztec(symbol, source, length); break; + case BARCODE_MICROQR: error_number = microqr(symbol, source, length); break; + case BARCODE_GRIDMATRIX: error_number = grid_matrix(symbol, source, length); break; + } + + return error_number; +} + +int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int length) +{ + /* These are the "norm" standards which only support Latin-1 at most */ + int error_number = 0, i; + #ifdef _MSC_VER unsigned char* preprocessed; #endif - input_length = ustrlen(source); - error_number = 0; - #ifndef _MSC_VER - unsigned char preprocessed[input_length]; + unsigned char preprocessed[length]; #else - preprocessed = (unsigned char*)_alloca(input_length + 1); + preprocessed = (unsigned char*)_alloca(length + 1); #endif + + if(symbol->symbology == BARCODE_CODE16K) { + symbol->whitespace_width = 16; + symbol->border_width = 2; + symbol->output_options = BARCODE_BIND; + } + + if(symbol->symbology == BARCODE_ITF14) { + symbol->whitespace_width = 20; + symbol->border_width = 8; + symbol->output_options = BARCODE_BOX; + } + + switch(symbol->input_mode) { + case DATA_MODE: + for(i = 0; i < length; i++) { + preprocessed[i] = source[i]; + } + preprocessed[length] = '\0'; + break; + case UNICODE_MODE: + error_number = latin1_process(symbol, source, preprocessed, &length); + if(error_number != 0) { return error_number; } + break; + } + + switch(symbol->symbology) { + case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, length); break; + case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, length); break; + case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, length); break; + case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, length); break; + case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, length); break; + case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, length); break; + case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, length); break; + case BARCODE_UPCA: error_number = eanx(symbol, preprocessed, length); break; + case BARCODE_UPCE: error_number = eanx(symbol, preprocessed, length); break; + case BARCODE_EANX: error_number = eanx(symbol, preprocessed, length); break; + case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, length); break; + case BARCODE_CODE39: error_number = c39(symbol, preprocessed, length); break; + case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, length); break; + case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, length); break; + case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, length); break; + case BARCODE_CODE93: error_number = c93(symbol, preprocessed, length); break; + case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, length); break; + case BARCODE_CODE128: error_number = code_128(symbol, preprocessed, length); break; + case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed, length); break; + case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, length); break; + case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, length); break; + case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, length); break; + case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, length); break; + case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, length); break; + case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, length); break; + case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, length); break; + case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, length); break; + case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, length); break; + case BARCODE_FIM: error_number = fim(symbol, preprocessed, length); break; + case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, length); break; + case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, length); break; + case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, length); break; + case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed, length); break; + case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed, length); break; + case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed, length); break; + case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed, length); break; + case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, length); break; + case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, length); break; + case BARCODE_ONECODE: error_number = imail(symbol, preprocessed, length); break; + case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, length); break; + case BARCODE_RSS14: error_number = rss14(symbol, preprocessed, length); break; + case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed, length); break; + case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed, length); break; + case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, length); break; + case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed, length); break; + case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed, length); break; + case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed, length); break; + case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, length); break; + case BARCODE_CODE32: error_number = code32(symbol, preprocessed, length); break; + case BARCODE_CODABLOCKF: error_number = codablock(symbol, preprocessed, length); break; + case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, length); break; + case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed, length); break; + case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, length); break; + case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, length); break; + case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed, length); break; + case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed, length); break; + case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed, length); break; + case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed, length); break; + case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed, length); break; + case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed, length); break; + case BARCODE_HIBC_BLOCKF: error_number = hibc(symbol, preprocessed, length); break; + case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, length); break; + case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, length); break; + case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, length); break; + case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, length); break; + } + + if((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { + ustrcpy(symbol->text, source); + } + + return error_number; +} + +int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int length) +{ + int error_number, error_buffer, i; + error_number = 0; if(ustrlen(source) == 0) { strcpy(symbol->errtxt, "No input data"); @@ -465,6 +533,16 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) return ERROR_INVALID_DATA; } + if(length == 0) { + length = ustrlen(source); + } + +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif + /* First check the symbology field */ if(symbol->symbology < 1) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } @@ -501,7 +579,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) if(symbol->symbology == 111) { symbol->symbology = BARCODE_HIBC_BLOCKF; } if((symbol->symbology >= 112) && (symbol->symbology <= 127)) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } /* Everything from 128 up is Zint-specific */ - if(symbol->symbology >= 142) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } + if(symbol->symbology >= 143) { strcpy(symbol->errtxt, "Symbology out of range, using Code 128"); symbol->symbology = BARCODE_CODE128; error_number = WARN_INVALID_OPTION; } if(error_number > 4) { error_tag(symbol->errtxt, error_number); @@ -510,140 +588,47 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) error_buffer = error_number; } - if((symbol->input_mode < 0) || (symbol->input_mode > 3)) { symbol->input_mode = DATA_MODE; } - switch(symbol->input_mode) { - case DATA_MODE: - ustrcpy(preprocessed, source); break; - case UNICODE_MODE: - error_number = eci_process(symbol, source, preprocessed); + if((symbol->input_mode < 0) || (symbol->input_mode > 2)) { symbol->input_mode = DATA_MODE; } + + if(symbol->input_mode == GS1_MODE) { + for(i = 0; i < length; i++) { + if(source[i] == '\0') { + strcpy(symbol->errtxt, "NULL characters not permitted in GS1 mode"); + return ERROR_INVALID_DATA; + } + } + if(gs1_compliant(symbol->symbology) == 1) { + error_number = ugs1_verify(symbol, source, local_source); if(error_number != 0) { return error_number; } - break; - case GS1_MODE: - if(gs1_compliant(symbol->symbology) == 1) { - error_number = ugs1_verify(symbol, source, preprocessed); - if(error_number != 0) { return error_number; } - } else { - strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode"); - return ERROR_INVALID_OPTION; - } - break; - case KANJI_MODE: - if((symbol->symbology != BARCODE_QRCODE) && (symbol->symbology != BARCODE_MICROQR)) { - strcpy(symbol->errtxt, "Selected symbology does not support Kanji mode"); - return ERROR_INVALID_OPTION; - } - error_number = unicode2shift_jis(symbol, source, preprocessed); - if(error_number != 0) { return error_number; } - break; - case SJIS_MODE: - if((symbol->symbology != BARCODE_QRCODE) && (symbol->symbology != BARCODE_MICROQR)) { - strcpy(symbol->errtxt, "Selected symbology does not support Kanji mode"); - return ERROR_INVALID_OPTION; - } - ustrcpy(preprocessed, source); - break; + } else { + strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode"); + return ERROR_INVALID_OPTION; + } + } else { + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + local_source[length] = '\0'; } - if(symbol->symbology == BARCODE_CODE16K) { - symbol->whitespace_width = 16; - symbol->border_width = 2; - symbol->output_options = BARCODE_BIND; - } - - if(symbol->symbology == BARCODE_ITF14) { - symbol->whitespace_width = 20; - symbol->border_width = 8; - symbol->output_options = BARCODE_BOX; + switch(symbol->symbology) { + case BARCODE_DATAMATRIX: + case BARCODE_PDF417: + case BARCODE_PDF417TRUNC: + case BARCODE_QRCODE: + case BARCODE_MICROPDF417: + case BARCODE_MAXICODE: + case BARCODE_AZTEC: + case BARCODE_MICROQR: + case BARCODE_GRIDMATRIX: + error_number = extended_charset(symbol, local_source, length); + break; + default: + error_number = reduced_charset(symbol, local_source, length); + break; } - switch(symbol->symbology) { - case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed); break; - case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed); break; - case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed); break; - case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed); break; - case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed); break; - case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed); break; - case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed); break; - case BARCODE_UPCA: error_number = eanx(symbol, preprocessed); break; - case BARCODE_UPCE: error_number = eanx(symbol, preprocessed); break; - case BARCODE_EANX: error_number = eanx(symbol, preprocessed); break; - case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed); break; - case BARCODE_CODE39: error_number = c39(symbol, preprocessed); break; - case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed); break; - case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed); break; - case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed); break; - case BARCODE_CODE93: error_number = c93(symbol, preprocessed); break; - case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed); break; - case BARCODE_CODE128: error_number = code_128(symbol, preprocessed); break; - case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed); break; - case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed); break; - case BARCODE_CODE11: error_number = code_11(symbol, preprocessed); break; - case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed); break; - case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed); break; - case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed); break; - case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed); break; - case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed); break; - case BARCODE_ITF14: error_number = itf14(symbol, preprocessed); break; - case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed); break; - case BARCODE_FIM: error_number = fim(symbol, preprocessed); break; - case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed); break; - case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed); break; - case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed); break; - case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed); break; - case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed); break; - case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed); break; - case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed); break; - case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed); break; - case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed); break; - case BARCODE_ONECODE: error_number = imail(symbol, preprocessed); break; - case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed); break; - case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed); break; - case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed); break; - case BARCODE_QRCODE: error_number = qr_code(symbol, preprocessed); break; - case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed); break; - case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed); break; - case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed); break; - case BARCODE_RSS14: error_number = rss14(symbol, preprocessed); break; - case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed); break; - case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed); break; - case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed); break; - case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed); break; - case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed); break; - case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed); break; - case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed); break; - case BARCODE_KIX: error_number = kix_code(symbol, preprocessed); break; - case BARCODE_CODE32: error_number = code32(symbol, preprocessed); break; - case BARCODE_CODABLOCKF: error_number = codablock(symbol, preprocessed); break; - case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed); break; - case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed); break; - case BARCODE_MICROQR: error_number = microqr(symbol, preprocessed); break; - case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed); break; - case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed); break; - case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed); break; - case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed); break; - case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed); break; - case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed); break; - case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed); break; - case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed); break; - case BARCODE_HIBC_BLOCKF: error_number = hibc(symbol, preprocessed); break; - case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed); break; - case BARCODE_CODE49: error_number = code_49(symbol, preprocessed); break; - case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed); break; - case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed); break; - } - if((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { - ustrcpy(symbol->text, source); - } if(error_number == 0) { error_number = error_buffer; } @@ -652,59 +637,22 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source) return error_number; } -int ZBarcode_Print(struct zint_symbol *symbol) +int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) { int error_number; char output[4]; - - /*int i, j; - for(i = 0; i < symbol->rows; i++) { - for(j = 0; j <= symbol->width / 7; j++) { - printf("%2.2X ", symbol->encoded_data[i][j]); - } - printf("\n"); - }*/ - - if(strlen(symbol->outfile) > 3) { - output[0] = symbol->outfile[strlen(symbol->outfile) - 3]; - output[1] = symbol->outfile[strlen(symbol->outfile) - 2]; - output[2] = symbol->outfile[strlen(symbol->outfile) - 1]; - output[3] = '\0'; - to_upper((unsigned char*)output); -#ifndef NO_PNG - if(!(strcmp(output, "PNG"))) { - error_number = png_handle(symbol, 0); - } else { -#endif - if(!(strcmp(output, "EPS"))) { - error_number = ps_plot(symbol); - } else { - if(!(strcmp(output, "SVG"))) { - error_number = svg_plot(symbol); - } else { - strcpy(symbol->errtxt, "Unknown output format"); - error_tag(symbol->errtxt, ERROR_INVALID_OPTION); - return ERROR_INVALID_OPTION; - } - } -#ifndef NO_PNG - } -#endif - } else { - strcpy(symbol->errtxt, "Unknown output format"); - error_tag(symbol->errtxt, ERROR_INVALID_OPTION); - return ERROR_INVALID_OPTION; + switch(rotate_angle) { + case 0: + case 90: + case 180: + case 270: + break; + default: + strcpy(symbol->errtxt, "Invalid rotation angle"); + return ERROR_INVALID_OPTION; + break; } - - error_tag(symbol->errtxt, error_number); - return error_number; -} - -int ZBarcode_Print_Rotated(struct zint_symbol *symbol, int rotate_angle) -{ - int error_number; - char output[4]; if(strlen(symbol->outfile) > 3) { output[0] = symbol->outfile[strlen(symbol->outfile) - 3]; @@ -742,43 +690,36 @@ int ZBarcode_Print_Rotated(struct zint_symbol *symbol, int rotate_angle) return error_number; } -int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input) +int ZBarcode_Print_Rotated(struct zint_symbol *symbol, int rotate_angle) { + /* Depreciated - will be removed in later version */ + return ZBarcode_Print(symbol, rotate_angle); +} + +int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) { int error_number; error_number = 0; - error_number = ZBarcode_Encode(symbol, input); + error_number = ZBarcode_Encode(symbol, input, length); if(error_number != 0) { return error_number; } - error_number = ZBarcode_Print(symbol); + error_number = ZBarcode_Print(symbol, rotate_angle); return error_number; } -int ZBarcode_Encode_and_Print_Rotated(struct zint_symbol *symbol, unsigned char *input, int rotate_angle) -{ - int error_number; - - error_number = 0; - - error_number = ZBarcode_Encode(symbol, input); - if(error_number != 0) { - return error_number; - } - - error_number = ZBarcode_Print_Rotated(symbol, rotate_angle); - return error_number; +int ZBarcode_Encode_and_Print_Rotated(struct zint_symbol *symbol, unsigned char *input, int rotate_angle) { + /* Depreciated - will be removed in later version */ + return ZBarcode_Encode_and_Print(symbol, input, rotate_angle, strlen((char *)input)); } -int ZBarcode_Encode_from_File(struct zint_symbol *symbol, char *filename) +int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) { - int i; FILE *file; unsigned char *buffer; unsigned long fileLen, result; - unsigned char used_characters[256]; file = fopen(filename, "rb"); if (!file) { @@ -816,50 +757,20 @@ int ZBarcode_Encode_from_File(struct zint_symbol *symbol, char *filename) fclose(file); - if(symbol->input_mode == DATA_MODE) { - /* Look for and correctly handle NULL characters */ - - for (i = 0; i <= 255; i++) { used_characters[i] = 0;} - for (i = 0; i < (int)fileLen; i++) { used_characters[(int)buffer[i]] = 1;} - - if (used_characters[0] == 1) { /* only if data contains a NULL */ - - /* determine first unused character > 0 */ - i = 1; - while (i < 255) { - if (used_characters[i] == 0) { - symbol->nullchar = (char)i; - break; - } - i++; - } - if(symbol->nullchar == 0x00) { - /* No candidate character could be found. Quit */ - strcpy(symbol->errtxt, "Could not encode NULL character"); - return ERROR_INVALID_OPTION; - } - - for(i = 0; i < fileLen; i++) { - if(buffer[i] == 0x00) { - buffer[i] = symbol->nullchar; - } - } - } - } - - return ZBarcode_Encode(symbol, buffer); + return ZBarcode_Encode(symbol, buffer, fileLen); } -int ZBarcode_Encode_from_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle) +int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle) { int error_number; error_number = 0; - error_number = ZBarcode_Encode_from_File(symbol, filename); + error_number = ZBarcode_Encode_File(symbol, filename); if(error_number != 0) { return error_number; } - return ZBarcode_Print_Rotated(symbol, rotate_angle); + return ZBarcode_Print(symbol, rotate_angle); } + diff --git a/backend/maxicode.c b/backend/maxicode.c index f6f4e8c4..17e5c93a 100644 --- a/backend/maxicode.c +++ b/backend/maxicode.c @@ -112,7 +112,7 @@ void maxi_bump(int set[], int character[], int bump_posn) } } -int maxi_text_process(int mode, unsigned char source[], char nullchar) +int maxi_text_process(int mode, unsigned char source[], int length) { /* Format text according to Appendix A */ @@ -120,9 +120,7 @@ int maxi_text_process(int mode, unsigned char source[], char nullchar) and [Lock in E] and so is not always the most efficient at compressing data, but should suffice for most applications */ - int set[144], character[144], i, j, done, count, length, current_set; - - length = ustrlen(source); + int set[144], character[144], i, j, done, count, current_set; if(length > 138) { return ERROR_TOO_LONG; @@ -136,13 +134,8 @@ int maxi_text_process(int mode, unsigned char source[], char nullchar) for (i = 0; i < length; i++) { /* Look up characters in table from Appendix A - this gives value and code set for most characters */ - if(source[i] == nullchar) { - set[i] = maxiCodeSet[0]; - character[i] = maxiSymbolChar[0]; - } else { - set[i] = maxiCodeSet[source[i]]; - character[i] = maxiSymbolChar[source[i]]; - } + set[i] = maxiCodeSet[source[i]]; + character[i] = maxiSymbolChar[source[i]]; } /* If a character can be represented in more than one code set, @@ -551,16 +544,37 @@ void maxi_do_primary_3(char postcode[], int country, int service) maxi_codeword[9] = ((service & 0x3f0) >> 4); } -int maxicode(struct zint_symbol *symbol, unsigned char source[]) +int maxicode(struct zint_symbol *symbol, unsigned char source[], int length) { int i, j, block, bit, mode, countrycode = 0, service = 0; - int bit_pattern[7], internal_error = 0, eclen; + int bit_pattern[7], internal_error = 0, eclen, error_number; char postcode[12], countrystr[4], servicestr[4]; + +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif + mode = symbol->option_1; strcpy(postcode, ""); strcpy(countrystr, ""); strcpy(servicestr, ""); + /* The following to be replaced by ECI handling */ + switch(symbol->input_mode) { + case DATA_MODE: + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + local_source[length] = '\0'; + break; + case UNICODE_MODE: + error_number = latin1_process(symbol, source, local_source, &length); + if(error_number != 0) { return error_number; } + break; + } + for(i = 0; i < 145; i++) { maxi_codeword[i] = 0; } @@ -628,7 +642,7 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[]) maxi_codeword[0] = mode; } - i = maxi_text_process(mode, source, symbol->nullchar); + i = maxi_text_process(mode, local_source, length); if(i == ERROR_TOO_LONG ) { strcpy(symbol->errtxt, "Input data too long"); return i; diff --git a/backend/medical.c b/backend/medical.c index a1d5c28e..206a1c3b 100644 --- a/backend/medical.c +++ b/backend/medical.c @@ -32,9 +32,9 @@ static char *CodaTable[20] = {"11111221", "11112211", "11121121", "22111111", "1 "12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121", "21212111", "11212121", "11221211", "12121121", "11121221", "11122211"}; -int c39(struct zint_symbol *symbol, unsigned char source[]); +int c39(struct zint_symbol *symbol, unsigned char source[], int length); -int pharma_one(struct zint_symbol *symbol, unsigned char source[]) +int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) { /* "Pharmacode can represent only a single integer from 3 to 131070. Unlike other commonly used one-dimensional barcode schemes, pharmacode does not store the data in a @@ -57,11 +57,11 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 6) { + if(length > 6) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -151,7 +151,7 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des return error_number; } -int pharma_two(struct zint_symbol *symbol, unsigned char source[]) +int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) { /* Draws the patterns for two track pharmacode */ char height_pattern[200]; @@ -160,11 +160,11 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[]) int error_number = 0; strcpy(height_pattern, ""); - if(ustrlen(source) > 8) { + if(length > 8) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -194,52 +194,60 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int codabar(struct zint_symbol *symbol, unsigned char source[]) +int codabar(struct zint_symbol *symbol, unsigned char source[], int length) { /* The Codabar system consisting of simple substitution */ int i, error_number; char dest[1000]; +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 60) { /* No stack smashing please */ + if(length > 60) { /* No stack smashing please */ strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - to_upper(source); - error_number = is_sane(CASET, source); + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + to_upper(local_source); + error_number = is_sane(CASET, local_source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } /* Codabar must begin and end with the characters A, B, C or D */ - if(((source[0] != 'A') && (source[0] != 'B')) && - ((source[0] != 'C') && (source[0] != 'D'))) + if(((local_source[0] != 'A') && (local_source[0] != 'B')) && + ((local_source[0] != 'C') && (local_source[0] != 'D'))) { strcpy(symbol->errtxt, "Invalid characters in data"); - return 6; + return ERROR_INVALID_DATA; } - if(((source[ustrlen(source) - 1] != 'A') && (source[ustrlen(source) - 1] != 'B')) && - ((source[ustrlen(source) - 1] != 'C') && (source[ustrlen(source) - 1] != 'D'))) + if(((local_source[ustrlen(local_source) - 1] != 'A') && (local_source[ustrlen(local_source) - 1] != 'B')) && + ((local_source[ustrlen(local_source) - 1] != 'C') && (local_source[ustrlen(local_source) - 1] != 'D'))) { strcpy(symbol->errtxt, "Invalid characters in data"); - return 6; + return ERROR_INVALID_DATA; } - for(i = 0; i <= ustrlen(source); i++) + for(i = 0; i < length; i++) { - lookup(CASET, CodaTable, source[i], dest); + lookup(CASET, CodaTable, local_source[i], dest); } expand(symbol, dest); - ustrcpy(symbol->text, source); + ustrcpy(symbol->text, local_source); return error_number; } -int code32(struct zint_symbol *symbol, unsigned char source[]) +int code32(struct zint_symbol *symbol, unsigned char source[], int length) { /* Italian Pharmacode */ int i, zeroes, error_number, checksum, checkpart, checkdigit; char localstr[10], tempstr[2], risultante[7]; @@ -248,11 +256,11 @@ int code32(struct zint_symbol *symbol, unsigned char source[]) char tabella[34]; /* Validate the input */ - if(ustrlen(source) > 8) { + if(length > 8) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -260,7 +268,7 @@ int code32(struct zint_symbol *symbol, unsigned char source[]) /* Add leading zeros as required */ strcpy(localstr, ""); - zeroes = 8 - ustrlen(source); + zeroes = 8 - length; for(i = 0; i < zeroes; i++) { concat(localstr, "0"); } @@ -311,7 +319,7 @@ int code32(struct zint_symbol *symbol, unsigned char source[]) } /* Plot the barcode using Code 39 */ - error_number = c39(symbol, (unsigned char*)risultante); + error_number = c39(symbol, (unsigned char*)risultante, strlen(risultante)); if(error_number != 0) { return error_number; } /* Override the normal text output with the Pharmacode number */ diff --git a/backend/micqr.c b/backend/micqr.c index b40f9559..9bcd41ef 100644 --- a/backend/micqr.c +++ b/backend/micqr.c @@ -25,6 +25,7 @@ #include "common.h" #include "reedsol.h" #include "micqr.h" +#include "shiftjis.h" #define NUMERIC 1 #define ALPHANUM 2 @@ -36,14 +37,14 @@ void qrnumeric_encode(char binary[], unsigned char source[]) { /* Encodes numeric data according to section 6.4.3 */ - int input_length, blocks, remainder, i; + int length, blocks, remainder, i; char block_binary[11]; int block_value; block_value = 0; - input_length = ustrlen(source); - blocks = input_length / 3; - remainder = input_length % 3; + length = ustrlen(source); + blocks = length / 3; + remainder = length % 3; for(i = 0; i < blocks; i++) { block_value = ctoi(source[(i * 3)]) * 100; @@ -93,13 +94,13 @@ void qrnumeric_encode(char binary[], unsigned char source[]) void qralpha_encode(char binary[], unsigned char source[]) { /* Encodes alphanumeric data according to 6.4.4 */ - int input_length, blocks, remainder, i; + int length, blocks, remainder, i; char block_binary[12]; int block_value; - input_length = ustrlen(source); - blocks = input_length / 2; - remainder = input_length % 2; + length = ustrlen(source); + blocks = length / 2; + remainder = length % 2; for(i = 0; i < blocks; i++) { block_value = posn(QRSET, source[i * 2]) * 45; @@ -139,11 +140,11 @@ void qralpha_encode(char binary[], unsigned char source[]) void qrbyte_encode(char binary[], unsigned char source[]) { /* Encodes byte mode data according to 6.4.5 */ - int input_length, i; + int length, i; - input_length = ustrlen(source); + length = ustrlen(source); - for(i = 0; i < input_length; i++) { + for(i = 0; i < length; i++) { if(source[i] & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } if(source[i] & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); } if(source[i] & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } @@ -195,19 +196,19 @@ int qrkanji_encode(char binary[], unsigned char source[]) void versionm1(char binary_data[], unsigned char source[]) { - int input_length, i, latch; + int length, i, latch; int bits_total, bits_left, remainder; int data_codewords, ecc_codewords; unsigned char data_blocks[4], ecc_blocks[3]; - input_length = ustrlen(source); + length = ustrlen(source); bits_total = 20; latch = 0; /* Character count indicator */ - if(input_length & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } qrnumeric_encode(binary_data, source); @@ -297,12 +298,12 @@ void versionm1(char binary_data[], unsigned char source[]) void versionm2(char binary_data[], unsigned char source[], int char_system, int ecc_mode) { - int input_length, i, latch; + int length, i, latch; int bits_total, bits_left, remainder; int data_codewords, ecc_codewords; unsigned char data_blocks[6], ecc_blocks[7]; - input_length = ustrlen(source); + length = ustrlen(source); latch = 0; if(ecc_mode == 1) { bits_total = 40; } @@ -314,11 +315,11 @@ void versionm2(char binary_data[], unsigned char source[], int char_system, int /* Character count indicator */ if(char_system == NUMERIC) { - if(input_length & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } } - if(input_length & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } if(char_system == NUMERIC) { qrnumeric_encode(binary_data, source); } if(char_system == ALPHANUM) { qralpha_encode(binary_data, source); } @@ -390,13 +391,13 @@ void versionm2(char binary_data[], unsigned char source[], int char_system, int void versionm3(char binary_data[], unsigned char source[], int char_system, int ecc_mode) { - int input_length, i, latch; + int length, i, latch; int bits_total, bits_left, remainder; int data_codewords, ecc_codewords; unsigned char data_blocks[12], ecc_blocks[9]; int sjis_count; - input_length = ustrlen(source); + length = ustrlen(source); latch = 0; if(ecc_mode == 1) { bits_total = 84; } @@ -413,12 +414,12 @@ void versionm3(char binary_data[], unsigned char source[], int char_system, int concat(binary_data, "XXX"); /* Place holder */ } else { if(char_system == NUMERIC) { - if(input_length & 0x10) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x10) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } } - if(input_length & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } } if(char_system == NUMERIC) { qrnumeric_encode(binary_data, source); } @@ -529,13 +530,13 @@ void versionm3(char binary_data[], unsigned char source[], int char_system, int void versionm4(char binary_data[], unsigned char source[], int char_system, int ecc_mode) { - int input_length, i, latch; + int length, i, latch; int bits_total, bits_left, remainder; int data_codewords, ecc_codewords; unsigned char data_blocks[17], ecc_blocks[15]; int sjis_count; - input_length = ustrlen(source); + length = ustrlen(source); latch = 0; if(ecc_mode == 1) { bits_total = 128; } @@ -553,13 +554,13 @@ void versionm4(char binary_data[], unsigned char source[], int char_system, int concat(binary_data, "XXXX"); /* Place holder */ } else { if(char_system == NUMERIC) { - if(input_length & 0x20) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x20) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } } - if(input_length & 0x10) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } - if(input_length & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x10) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x08) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x04) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x02) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } + if(length & 0x01) { concat(binary_data, "1"); } else { concat(binary_data, "0"); } } if(char_system == NUMERIC) { qrnumeric_encode(binary_data, source); } @@ -640,10 +641,10 @@ void versionm4(char binary_data[], unsigned char source[], int char_system, int return; } -int microqr(struct zint_symbol *symbol, unsigned char source[]) +int microqr(struct zint_symbol *symbol, unsigned char source[], int length) { int symbol_size; - int char_system, input_length; + int char_system; char binary_data[200]; int latch; char bitmask[17][17]; @@ -651,19 +652,50 @@ int microqr(struct zint_symbol *symbol, unsigned char source[]) char candidate[17][17]; char pattern_bit; int width, i, j, pattern_no; - int sum1, sum2, evaluation[4], format, format_full; + int sum1, sum2, evaluation[4], format, format_full, kanji; + int error_number; char formatstr[16]; +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif + /* Analise input data and select encoding method - zint does not attempt to optimise the symbol by switching encoding method part way through the symbol, but merely chooses an encoding method for the whole symbol */ - input_length = ustrlen(source); char_system = BYTE; symbol_size = 0; - if(is_sane(QRSET, source) == 0) { char_system = ALPHANUM; } - if(is_sane(NESET, source) == 0) { char_system = NUMERIC; } - if(symbol->input_mode == KANJI_MODE) { char_system = KANJI; } - if(symbol->input_mode == SJIS_MODE) { char_system = KANJI; } + + for(i = 0; i < length; i++) { + if(source[i] == '\0') { + strcpy(symbol->errtxt, "QR Code not yet able to handle NULL characters"); + return ERROR_INVALID_DATA; + } + } + + kanji = 0; + /* The following to be replaced by ECI handling */ + switch(symbol->input_mode) { + case DATA_MODE: + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + local_source[length] = '\0'; + break; + case UNICODE_MODE: + error_number = shiftJIS(symbol, source, local_source, &length, &kanji); + if(error_number != 0) { return error_number; } + break; + } + + if(kanji) { + char_system = KANJI; + } else { + if(is_sane(QRSET, local_source, length) == 0) { char_system = ALPHANUM; } + if(is_sane(NESET, local_source, length) == 0) { char_system = NUMERIC; } + } width = 0; format = 0; @@ -683,27 +715,27 @@ int microqr(struct zint_symbol *symbol, unsigned char source[]) switch(symbol->option_1) { case 1: /* ECC Level L */ switch(char_system) { - case NUMERIC: if(input_length > 35) latch = 1; break; - case ALPHANUM: if(input_length > 21) latch = 1; break; - case BYTE: if(input_length > 15) latch = 1; break; - case KANJI: if(input_length > 18) latch = 1; break; + case NUMERIC: if(length > 35) latch = 1; break; + case ALPHANUM: if(length > 21) latch = 1; break; + case BYTE: if(length > 15) latch = 1; break; + case KANJI: if(length > 18) latch = 1; break; } break; case 2: /* ECC Level M */ switch(char_system) { - case NUMERIC: if(input_length > 30) latch = 1; break; - case ALPHANUM: if(input_length > 18) latch = 1; break; - case BYTE: if(input_length > 13) latch = 1; break; - case KANJI: if(input_length > 16) latch = 1; break; + case NUMERIC: if(length > 30) latch = 1; break; + case ALPHANUM: if(length > 18) latch = 1; break; + case BYTE: if(length > 13) latch = 1; break; + case KANJI: if(length > 16) latch = 1; break; } break; case 3: /* ECC Level Q */ symbol_size = 4; /* Only size M4 supports level Q */ switch(char_system) { - case NUMERIC: if(input_length > 21) latch = 1; break; - case ALPHANUM: if(input_length > 13) latch = 1; break; - case BYTE: if(input_length > 9) latch = 1; break; - case KANJI: if(input_length > 10) latch = 1; break; + case NUMERIC: if(length > 21) latch = 1; break; + case ALPHANUM: if(length > 13) latch = 1; break; + case BYTE: if(length > 9) latch = 1; break; + case KANJI: if(length > 10) latch = 1; break; } break; } @@ -725,52 +757,52 @@ int microqr(struct zint_symbol *symbol, unsigned char source[]) switch(char_system) { case NUMERIC: symbol_size = 4; - if(input_length <= 23) { symbol_size = 3; } - if(input_length <= 10) { symbol_size = 2; } - if(input_length <= 5) { symbol_size = 1; } + if(length <= 23) { symbol_size = 3; } + if(length <= 10) { symbol_size = 2; } + if(length <= 5) { symbol_size = 1; } break; case ALPHANUM: symbol_size = 4; - if(input_length <= 14) { symbol_size = 3; } - if(input_length <= 6) { symbol_size = 2; } + if(length <= 14) { symbol_size = 3; } + if(length <= 6) { symbol_size = 2; } break; case BYTE: symbol_size = 4; - if(input_length <= 9) { symbol_size = 3; } + if(length <= 9) { symbol_size = 3; } break; case KANJI: symbol_size = 4; - if(input_length <= 12) { symbol_size = 3; } + if(length <= 12) { symbol_size = 3; } } } else { /* ECC Level M */ switch(char_system) { case NUMERIC: symbol_size = 4; - if(input_length <= 18) { symbol_size = 3; } - if(input_length <= 8) { symbol_size = 2; } + if(length <= 18) { symbol_size = 3; } + if(length <= 8) { symbol_size = 2; } break; case ALPHANUM: symbol_size = 4; - if(input_length <= 11) { symbol_size = 3; } - if(input_length <= 5) { symbol_size = 2; } + if(length <= 11) { symbol_size = 3; } + if(length <= 5) { symbol_size = 2; } break; case BYTE: symbol_size = 4; - if(input_length <= 7) { symbol_size = 3; } + if(length <= 7) { symbol_size = 3; } break; case KANJI: symbol_size = 4; - if(input_length <= 8) { symbol_size = 3; } + if(length <= 8) { symbol_size = 3; } } } } strcpy(binary_data, ""); switch(symbol_size) { - case 1: versionm1(binary_data, source); break; - case 2: versionm2(binary_data, source, char_system, symbol->option_1); break; - case 3: versionm3(binary_data, source, char_system, symbol->option_1); break; - case 4: versionm4(binary_data, source, char_system, symbol->option_1); break; + case 1: versionm1(binary_data, local_source); break; + case 2: versionm2(binary_data, local_source, char_system, symbol->option_1); break; + case 3: versionm3(binary_data, local_source, char_system, symbol->option_1); break; + case 4: versionm4(binary_data, local_source, char_system, symbol->option_1); break; } switch(symbol_size) { diff --git a/backend/pdf417.c b/backend/pdf417.c index 3eef9e5e..82daa828 100644 --- a/backend/pdf417.c +++ b/backend/pdf417.c @@ -30,7 +30,7 @@ symbol->option_2 is used to adjust the width of the resulting symbol (i.e. the number of codeword columns not including row start and end data) */ -/* @(#) $Id: pdf417.c,v 1.12 2009/09/19 08:16:21 hooper114 Exp $ */ +/* @(#) $Id: pdf417.c,v 1.13 2009/09/29 09:45:47 hooper114 Exp $ */ #include #include @@ -70,15 +70,11 @@ static int MicroAutosize[56] = int liste[2][1000]; /* global - okay, so I got _almost_ everything local! */ /* 866 */ -int quelmode(char codeascii, char nullchar) +int quelmode(char codeascii) { int mode; mode = BYT; - if(codeascii == nullchar) { - return BYT; - } - if((codeascii >= ' ') && (codeascii <= '~')) { mode = TEX; } if(codeascii == '\t') { mode = TEX; } if(codeascii == '\n') { mode = TEX; } @@ -315,7 +311,7 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len } /* 671 */ -void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block, char nullchar) +void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block) { int debug = 0; int len = 0; @@ -441,7 +437,7 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len } /* 366 */ -int pdf417(struct zint_symbol *symbol, unsigned char chaine[]) +int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) { int i, k, j, indexchaine, indexliste, mode, longueur, loop, mccorrection[520], offset; int total, chainemc[2700], mclength, c1, c2, c3, dummy[35], codeerr; @@ -454,7 +450,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[]) indexliste = 0; indexchaine = 0; - mode = quelmode(chaine[indexchaine], symbol->nullchar); + mode = quelmode(chaine[indexchaine]); for(i = 0; i < 1000; i++) { liste[0][i] = 0; @@ -463,13 +459,13 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[]) /* 463 */ do { liste[1][indexliste] = mode; - while ((liste[1][indexliste] == mode) && (indexchaine < ustrlen(chaine))) { + while ((liste[1][indexliste] == mode) && (indexchaine < length)) { liste[0][indexliste]++; indexchaine++; - mode = quelmode(chaine[indexchaine], symbol->nullchar); + mode = quelmode(chaine[indexchaine]); } indexliste++; - } while (indexchaine < ustrlen(chaine)); + } while (indexchaine < length); /* 474 */ pdfsmooth(&indexliste); @@ -496,7 +492,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[]) textprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i); break; case BYT: /* 670 - octet stream mode */ - byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i, symbol->nullchar); + byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i); break; case NUM: /* 712 - numeric mode */ numbprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i); @@ -686,58 +682,78 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[]) } /* 345 */ -int pdf417enc(struct zint_symbol *symbol, unsigned char source[]) +int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) { - int codeerr, errno; + int codeerr, error_number, i; + +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif - errno = 0; + error_number = 0; if((symbol->option_1 < -1) || (symbol->option_1 > 8)) { strcpy(symbol->errtxt, "Security value out of range"); symbol->option_1 = -1; - errno = WARN_INVALID_OPTION; + error_number = WARN_INVALID_OPTION; } if((symbol->option_2 < 0) || (symbol->option_2 > 30)) { strcpy(symbol->errtxt, "Number of columns out of range"); symbol->option_2 = 0; - errno = WARN_INVALID_OPTION; + error_number = WARN_INVALID_OPTION; + } + + /* The following to be replaced by ECI handling */ + switch(symbol->input_mode) { + case DATA_MODE: + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + local_source[length] = '\0'; + break; + case UNICODE_MODE: + error_number = latin1_process(symbol, source, local_source, &length); + if(error_number != 0) { return error_number; } + break; } /* 349 */ - codeerr = pdf417(symbol, source); + codeerr = pdf417(symbol, local_source, length); /* 352 */ if(codeerr != 0) { switch(codeerr) { case 1: strcpy(symbol->errtxt, "No such file or file unreadable"); - errno = ERROR_INVALID_OPTION; + error_number = ERROR_INVALID_OPTION; break; case 2: strcpy(symbol->errtxt, "Input string too long"); - errno = ERROR_TOO_LONG; + error_number = ERROR_TOO_LONG; break; case 3: strcpy(symbol->errtxt, "Number of codewords per row too small"); - errno = WARN_INVALID_OPTION; + error_number = WARN_INVALID_OPTION; break; case 4: strcpy(symbol->errtxt, "Data too long for specified number of columns"); - errno = ERROR_TOO_LONG; + error_number = ERROR_TOO_LONG; break; default: strcpy(symbol->errtxt, "Something strange happened"); - errno = ERROR_ENCODING_PROBLEM; + error_number = ERROR_ENCODING_PROBLEM; break; } } /* 364 */ - return errno; + return error_number; } -int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[]) +int micro_pdf417(struct zint_symbol *symbol, unsigned char source[], int length) { /* like PDF417 only much smaller! */ int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset; @@ -747,6 +763,12 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[]) int LeftRAP, CentreRAP, RightRAP, Cluster, writer, flip, loop; int debug = 0; +#ifndef _MSC_VER + unsigned char chaine[length]; +#else + unsigned char chaine = (unsigned char*)_alloca(length); +#endif + /* Encoding starts out the same as PDF417, so use the same code */ codeerr = 0; @@ -754,7 +776,21 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[]) indexliste = 0; indexchaine = 0; - mode = quelmode(chaine[indexchaine], symbol->nullchar); + /* The following to be replaced by ECI handling */ + switch(symbol->input_mode) { + case DATA_MODE: + for(i = 0; i < length; i++) { + chaine[i] = source[i]; + } + chaine[length] = '\0'; + break; + case UNICODE_MODE: + codeerr = latin1_process(symbol, source, chaine, &length); + if(codeerr != 0) { return codeerr; } + break; + } + + mode = quelmode(chaine[indexchaine]); for(i = 0; i < 1000; i++) { liste[0][i] = 0; @@ -763,13 +799,13 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[]) /* 463 */ do { liste[1][indexliste] = mode; - while ((liste[1][indexliste] == mode) && (indexchaine < ustrlen(chaine))) { + while ((liste[1][indexliste] == mode) && (indexchaine < length)) { liste[0][indexliste]++; indexchaine++; - mode = quelmode(chaine[indexchaine], symbol->nullchar); + mode = quelmode(chaine[indexchaine]); } indexliste++; - } while (indexchaine < ustrlen(chaine)); + } while (indexchaine < length); /* 474 */ pdfsmooth(&indexliste); @@ -796,7 +832,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[]) textprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i); break; case BYT: /* 670 - octet stream mode */ - byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i, symbol->nullchar); + byteprocess(chainemc, &mclength, chaine, indexchaine, liste[0][i], i); break; case NUM: /* 712 - numeric mode */ numbprocess(chainemc, &mclength, (char*)chaine, indexchaine, liste[0][i], i); diff --git a/backend/pdf417.h b/backend/pdf417.h index e23c881c..4e65ecf2 100644 --- a/backend/pdf417.h +++ b/backend/pdf417.h @@ -435,4 +435,4 @@ static char *RAPC[53] = {"", "112231", "121231", "122131", "131131", "131221", " "112213", "112222", "112312", "112321", "111421", "111331", "111322", "111232", "111223", "111133", "111124", "111214", "112114", "121114", "121123", "121132", "112132", "112141" }; -void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block, char nullchar); \ No newline at end of file +void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start, int length, int block); \ No newline at end of file diff --git a/backend/plessey.c b/backend/plessey.c index 8e94eac9..f1ab8007 100644 --- a/backend/plessey.c +++ b/backend/plessey.c @@ -34,7 +34,7 @@ static char *MSITable[10] = {"12121212", "12121221", "12122112", "12122121", "12 "12212112", "12212121", "21121212", "21121221"}; -int plessey(struct zint_symbol *symbol, unsigned char source[]) +int plessey(struct zint_symbol *symbol, unsigned char source[], int length) { /* Not MSI/Plessey but the older Plessey standard */ unsigned int i, check; @@ -46,22 +46,22 @@ int plessey(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 65) { + if(length > 65) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(SSET, source); + error_number = is_sane(SSET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - checkptr = (unsigned char *)calloc (1, ustrlen(source) * 4 + 8); + checkptr = (unsigned char *)calloc (1, length * 4 + 8); /* Start character */ concat(dest, "31311331"); /* Data area */ - for(i = 0; i <= ustrlen(source); i++) + for(i = 0; i <= length; i++) { check = posn(SSET, source[i]); lookup(SSET, PlessTable, source[i], dest); @@ -74,7 +74,7 @@ int plessey(struct zint_symbol *symbol, unsigned char source[]) /* CRC check digit code adapted from code by Leonid A. Broukhis used in GNU Barcode */ - for (i=0; i < 4*ustrlen(source); i++) { + for (i = 0; i < (4 * length); i++) { int j; if (checkptr[i]) for (j = 0; j < 9; j++) @@ -82,7 +82,7 @@ int plessey(struct zint_symbol *symbol, unsigned char source[]) } for (i = 0; i < 8; i++) { - switch(checkptr[ustrlen(source) * 4 + i]) + switch(checkptr[length * 4 + i]) { case 0: concat(dest, "13"); break; case 1: concat(dest, "31"); break; @@ -112,11 +112,6 @@ int msi_plessey(struct zint_symbol *symbol, unsigned char source[]) strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); - if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } /* start character */ concat (dest, "21"); @@ -150,11 +145,6 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[]) strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); - if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } /* start character */ concat (dest, "21"); @@ -248,11 +238,6 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[]) strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); - if (error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } /* start character */ concat (dest, "21"); @@ -405,11 +390,6 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[]) strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); - if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } /* start character */ concat (dest, "21"); @@ -475,11 +455,6 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[]) strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); - if (error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; - } /* start character */ concat (dest, "21"); @@ -583,11 +558,15 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int msi_handle(struct zint_symbol *symbol, unsigned char source[]) { +int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number; - error_number=0; - + error_number = is_sane(NESET, source, length); + if(error_number != 0) { + strcpy(symbol->errtxt, "Invalid characters in input data"); + return ERROR_INVALID_DATA; + } + if((symbol->option_2 < 0) || (symbol->option_2 > 4)) { symbol->option_2 = 0; } diff --git a/backend/png.c b/backend/png.c index c92a698d..ba84119d 100644 --- a/backend/png.c +++ b/backend/png.c @@ -65,6 +65,7 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c { struct mainprog_info_type wpng_info; struct mainprog_info_type *graphic; + #ifndef _MSC_VER unsigned char outdata[image_width * 3]; #else @@ -103,12 +104,12 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c strcpy(symbol->errtxt, "Malformed background colour target"); return ERROR_INVALID_OPTION; } - errno = is_sane(SSET, (unsigned char*)symbol->fgcolour); + errno = is_sane(SSET, (unsigned char*)symbol->fgcolour, 6); if (errno == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Malformed foreground colour target"); return ERROR_INVALID_OPTION; } - errno = is_sane(SSET, (unsigned char*)symbol->bgcolour); + errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, 6); if (errno == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Malformed background colour target"); return ERROR_INVALID_OPTION; @@ -533,10 +534,12 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle) large_bar_count++; } } - large_bar_height = (symbol->height - preset_height) / large_bar_count; if (large_bar_count == 0) { symbol->height = preset_height; + large_bar_height = 10; + } else { + large_bar_height = (symbol->height - preset_height) / large_bar_count; } while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) { diff --git a/backend/postal.c b/backend/postal.c index 0e2c8acd..19d2c6a5 100644 --- a/backend/postal.c +++ b/backend/postal.c @@ -27,7 +27,6 @@ #endif #include "common.h" -#define BESET "ABCD" #define DAFTSET "DAFT" #define KRSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define KASUTSET "1234567890-abcdefgh" @@ -40,8 +39,6 @@ static char *PNTable[10] = {"LLSSS", "SSSLL", "SSLSL", "SSLLS", "SLSSL", "SLSLS" static char *PLTable[10] = {"SSLLL", "LLLSS", "LLSLS", "LLSSL", "LSLLS", "LSLSL", "LSSLL", "SLLLS", "SLLSL", "SLSLL"}; -static char *FIMTable[4] = {"111515111", "13111311131", "11131313111", "1111131311111"}; - static char *RoyalValues[36] = {"11", "12", "13", "14", "15", "10", "21", "22", "23", "24", "25", "20", "31", "32", "33", "34", "35", "30", "41", "42", "43", "44", "45", "40", "51", "52", "53", "54", "55", "50", "01", "02", "03", "04", "05", "00"}; @@ -61,7 +58,7 @@ static char *KoreaTable[10] = {"1313150613", "0713131313", "0417131313", "150613 static char *JapanTable[19] = {"114", "132", "312", "123", "141", "321", "213", "231", "411", "144", "414", "324", "342", "234", "432", "243", "423", "441", "111"}; -int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[]) +int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) { /* Handles the PostNet system used for Zip codes in the US */ unsigned int i, sum, check_digit; @@ -69,11 +66,11 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[]) error_number = 0; - if(ustrlen(source) > 38) { + if(length > 38) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -83,7 +80,7 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* start character */ concat (dest, "L"); - for (i=0; i < ustrlen(source); i++) + for (i=0; i < length; i++) { lookup(NESET, PNTable, source[i], dest); sum += ctoi(source[i]); @@ -98,7 +95,7 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[]) return error_number; } -int post_plot(struct zint_symbol *symbol, unsigned char source[]) +int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) { /* Puts PostNet barcodes into the pattern matrix */ char height_pattern[200]; @@ -109,7 +106,7 @@ int post_plot(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; - error_number = postnet(symbol, source, height_pattern); + error_number = postnet(symbol, source, height_pattern, length); if(error_number != 0) { return error_number; } @@ -132,7 +129,7 @@ int post_plot(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int planet(struct zint_symbol *symbol, unsigned char source[], char dest[]) +int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) { /* Handles the PLANET system used for item tracking in the US */ unsigned int i, sum, check_digit; @@ -140,11 +137,11 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[]) error_number = 0; - if(ustrlen(source) > 38) { + if(length > 38) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -154,7 +151,7 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* start character */ concat (dest, "L"); - for (i=0; i < ustrlen(source); i++) + for (i=0; i < length; i++) { lookup(NESET, PLTable, source[i], dest); sum += ctoi(source[i]); @@ -169,7 +166,7 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[]) return error_number; } -int planet_plot(struct zint_symbol *symbol, unsigned char source[]) +int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) { /* Puts PLANET barcodes into the pattern matrix */ char height_pattern[200]; @@ -180,7 +177,7 @@ int planet_plot(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; - error_number = planet(symbol, source, height_pattern); + error_number = planet(symbol, source, height_pattern, length); if(error_number != 0) { return error_number; } @@ -202,25 +199,24 @@ int planet_plot(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int korea_post(struct zint_symbol *symbol, unsigned char source[]) +int korea_post(struct zint_symbol *symbol, unsigned char source[], int length) { /* Korean Postal Authority */ - int total, h, loop, check, zeroes, error_number; + int total, loop, check, zeroes, error_number; char localstr[8], checkstr[3], dest[80]; error_number = 0; - h = ustrlen(source); - if(h > 6) { + if(length > 6) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } strcpy(localstr, ""); - zeroes = 6 - h; + zeroes = 6 - length; for(loop = 0; loop < zeroes; loop++) concat(localstr, "0"); concat(localstr, (char *)source); @@ -245,31 +241,42 @@ int korea_post(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int fim(struct zint_symbol *symbol, unsigned char source[]) +int fim(struct zint_symbol *symbol, unsigned char source[], int length) { /* The simplest barcode symbology ever! Supported by MS Word, so here it is! */ /* glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */ - - int error_number; char dest[17]; - error_number = 0; - strcpy(dest, ""); - - to_upper(source); - if(ustrlen(source) > 1) { + if(length > 1) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(BESET, source); - if(error_number == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in data"); - return error_number; + + switch((char)source[0]) { + case 'a': + case 'A': + strcpy(dest, "111515111"); + break; + case 'b': + case 'B': + strcpy(dest, "13111311131"); + break; + case 'c': + case 'C': + strcpy(dest, "11131313111"); + break; + case 'd': + case 'D': + strcpy(dest, "1111131311111"); + break; + default: + strcpy(symbol->errtxt, "Invalid characters in data"); + return ERROR_INVALID_DATA; + break; } - lookup(BESET, FIMTable, source[0], dest); expand(symbol, dest); - return error_number; + return 0; } char rm4scc(char source[], unsigned char dest[]) @@ -307,28 +314,32 @@ char rm4scc(char source[], unsigned char dest[]) return set_copy[check_digit]; } -int royal_plot(struct zint_symbol *symbol, unsigned char source[]) +int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) { /* Puts RM4SCC into the data matrix */ char height_pattern[200], check; unsigned int loopey; - int writer; + int writer, i; int error_number; strcpy(height_pattern, ""); + unsigned char local_source[120]; error_number = 0; - to_upper(source); - if(ustrlen(source) > 120) { + if(length > 120) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(KRSET, source); + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + to_upper(local_source); + error_number = is_sane(KRSET, local_source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - check = rm4scc((char*)source, (unsigned char*)height_pattern); + check = rm4scc((char*)local_source, (unsigned char*)height_pattern); writer = 0; for(loopey = 0; loopey < strlen(height_pattern); loopey++) @@ -354,7 +365,7 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int kix_code(struct zint_symbol *symbol, unsigned char source[]) +int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) { /* Handles Dutch Post TNT KIX symbols */ /* The same as RM4SCC but without check digit */ @@ -364,15 +375,19 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[]) int writer, i; int error_number, zeroes; strcpy(height_pattern, ""); + unsigned char local_source[13]; error_number = 0; - to_upper(source); - if(ustrlen(source) > 11) { + if(length > 11) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(KRSET, source); + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + to_upper(local_source); + error_number = is_sane(KRSET, local_source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -380,10 +395,10 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[]) /* Add leading zeroes */ strcpy(localstr, ""); - zeroes = 11 - ustrlen(source); + zeroes = 11 - length; for(i = 0; i < zeroes; i++) concat(localstr, "0"); - concat(localstr, (char *)source); + concat(localstr, (char *)local_source); /* Encode data */ for (i = 0; i < 11; i++) { @@ -414,31 +429,31 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int daft_code(struct zint_symbol *symbol, unsigned char source[]) +int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) { /* Handles DAFT Code symbols */ /* Presumably 'daft' doesn't mean the same thing in Germany as it does in the UK! */ - int input_length; char height_pattern[100], local_source[55]; unsigned int loopey; int writer, i, error_number; strcpy(height_pattern, ""); error_number = 0; - input_length = ustrlen(source); - strcpy(local_source, (char*)source); - if(input_length > 50) { + if(length > 50) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } to_upper((unsigned char*)local_source); - error_number = is_sane(DAFTSET, (unsigned char*)local_source); + error_number = is_sane(DAFTSET, (unsigned char*)local_source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - for (i = 0; i < input_length; i++) { + for (i = 0; i < length; i++) { if(local_source[i] == 'D') { concat(height_pattern, "2"); } if(local_source[i] == 'A') { concat(height_pattern, "1"); } if(local_source[i] == 'F') { concat(height_pattern, "0"); } @@ -469,7 +484,7 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int flattermarken(struct zint_symbol *symbol, unsigned char source[]) +int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length) { /* Flattermarken - Not really a barcode symbology and (in my opinion) probably not much use but it's supported by TBarCode so it's supported by Zint! */ int loop, error_number; @@ -478,17 +493,17 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[]) error_number = 0; strcpy(dest, ""); - if(ustrlen(source) > 90) { + if(length > 90) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - for(loop = 0; loop < ustrlen(source); loop++) { + for(loop = 0; loop < length; loop++) { lookup(NESET, FlatTable, source[loop], dest); } @@ -496,9 +511,9 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int japan_post(struct zint_symbol *symbol, unsigned char source[]) +int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) { /* Japanese Postal Code (Kasutama Barcode) */ - int input_length, error_number; + int error_number; char pattern[69]; int writer, loopey, inter_posn, i, sum, check; char check_char; @@ -506,19 +521,22 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[]) #ifdef _MSC_VER char* local_source; #endif - input_length = ustrlen(source); + #ifndef _MSC_VER - char local_source[input_length + 1]; + char local_source[length + 1]; #else - local_source = (char*)_alloca(input_length + 1); + local_source = (char*)_alloca(length + 1); #endif inter_posn = 0; error_number = 0; strcpy(local_source, (char*)source); + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } to_upper((unsigned char*)local_source); - error_number = is_sane(SHKASUTSET, (unsigned char*)local_source); + error_number = is_sane(SHKASUTSET, (unsigned char*)local_source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); @@ -554,7 +572,7 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[]) } } i++; - }while((i < input_length) && (inter_posn < 20)); + }while((i < length) && (inter_posn < 20)); inter[20] = '\0'; strcpy(pattern, "13"); /* Start */ diff --git a/backend/ps.c b/backend/ps.c index 174a5415..ce7fcb8b 100644 --- a/backend/ps.c +++ b/backend/ps.c @@ -74,12 +74,12 @@ int ps_plot(struct zint_symbol *symbol) strcpy(symbol->errtxt, "Malformed background colour target"); return ERROR_INVALID_OPTION; } - error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour); + error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour, 6); if (error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Malformed foreground colour target"); return ERROR_INVALID_OPTION; } - error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour); + error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour, 6); if (error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Malformed background colour target"); return ERROR_INVALID_OPTION; diff --git a/backend/qr.c b/backend/qr.c index a9e72713..4b4c3f3a 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -26,8 +26,9 @@ #ifndef NO_QR #include #include +#include "shiftjis.h" -QRcode *encode(int security, int size, const unsigned char *intext, int kanji, int gs1, char nullchar, int input_length) +QRcode *encode(int security, int size, const unsigned char *intext, int kanji, int gs1, int input_length) { int version; QRecLevel level; @@ -62,49 +63,54 @@ QRcode *encode(int security, int size, const unsigned char *intext, int kanji, i version = 0; } - if(nullchar == '\0') { - /* No NULL characters in data */ - code = QRcode_encodeString((char*)intext, version, level, hint, 1); - } else { - /* NULL characters in data */ - code = QRcode_encodeString8bit((char*)intext, version, level); - /* code = QRcode_encodeString8bit((char*)intext, version, level, input_length); */ - } + code = QRcode_encodeString((char*)intext, version, level, hint, 1); return code; } -int qr_code(struct zint_symbol *symbol, unsigned char source[]) +int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) { QRcode *code; - /*int errno = 0;*/ int i, j; int kanji, gs1; - int input_length; - char nullify; + int error_number; + +#ifndef _MSC_VER + unsigned char local_source[length]; +#else + unsigned char local_source = (unsigned char*)_alloca(length); +#endif - input_length = ustrlen(source); - nullify = symbol->nullchar; - if((symbol->input_mode == KANJI_MODE) || (symbol->input_mode == SJIS_MODE)) { kanji = 1; } else { kanji = 0; } if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } - /* Null character handling */ - j = 0; - if(nullify != '\0') { - for(i = 0; i < input_length; i++) { - if(source[i] == nullify) { - source[i] = '\0'; - j++; - } + if(gs1) { + strcpy(symbol->errtxt, "GS1 mode not yet supported in QR Code"); + return ERROR_INVALID_OPTION; + } + + for(i = 0; i < length; i++) { + if(source[i] == '\0') { + strcpy(symbol->errtxt, "QR Code not yet able to handle NULL characters"); + return ERROR_INVALID_DATA; } } - - if(j == 0) { - /* nullchar was set but there are no NULL characters in the input data */ - nullify = '\0'; + + /* The following to be replaced by ECI handling */ + switch(symbol->input_mode) { + case DATA_MODE: + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } + local_source[length] = '\0'; + kanji = 0; + break; + case UNICODE_MODE: + error_number = shiftJIS(symbol, source, local_source, &length, &kanji); + if(error_number != 0) { return error_number; } + break; } - code = encode(symbol->option_1, symbol->option_2, source, kanji, gs1, nullify, input_length); + code = encode(symbol->option_1, symbol->option_2, local_source, kanji, gs1, length); if(code == NULL) { strcpy(symbol->errtxt, "libqrencode failed to encode the input data"); return ERROR_ENCODING_PROBLEM; diff --git a/backend/rss.c b/backend/rss.c index b3ca2c81..866ce2f4 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -142,7 +142,7 @@ void getRSSwidths(int val, int n, int elements, int maxWidth, int noNarrow) return; } -int rss14(struct zint_symbol *symbol, unsigned char source[]) +int rss14(struct zint_symbol *symbol, unsigned char source[], int length) { /* GS1 DataBar-14 */ int error_number = 0, i, j, mask; short int accum[112], left_reg[112], right_reg[112], x_reg[112], y_reg[112]; @@ -153,11 +153,11 @@ int rss14(struct zint_symbol *symbol, unsigned char source[]) separator_row = 0; - if(ustrlen(source) > 13) { + if(length > 13) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; @@ -651,7 +651,7 @@ int rss14(struct zint_symbol *symbol, unsigned char source[]) return error_number; } -int rsslimited(struct zint_symbol *symbol, unsigned char source[]) +int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length) { /* GS1 DataBar Limited */ int error_number = 0, i, mask; short int accum[112], left_reg[112], right_reg[112], x_reg[112], y_reg[112]; @@ -663,16 +663,16 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[]) separator_row = 0; - if(ustrlen(source) > 13) { + if(length > 13) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - error_number = is_sane(NESET, source); + error_number = is_sane(NESET, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - if(ustrlen(source) == 13) { + if(length == 13) { if((source[0] != '0') && (source[0] != '1')) { strcpy(symbol->errtxt, "Input out of range"); return ERROR_INVALID_DATA; @@ -1858,7 +1858,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str return 0; } -int rssexpanded(struct zint_symbol *symbol, unsigned char source[]) +int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length) { /* GS1 DataBar Expanded */ int i, j, k, l, data_chars, vs[21], group[21], v_odd[21], v_even[21]; char substring[21][14], latch; @@ -1868,10 +1868,10 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[]) int codeblocks, sub_elements[235], stack_rows, current_row, current_block; int separator_row; #ifndef _MSC_VER - char reduced[ustrlen(source)], binary_string[7 * ustrlen(source)]; + char reduced[length], binary_string[7 * length]; #else - char* reduced = (char*)_alloca(ustrlen(source)); - char* binary_string = (char*)_alloca(7 * ustrlen(source)); + char* reduced = (char*)_alloca(length); + char* binary_string = (char*)_alloca(7 * length); #endif separator_row = 0; diff --git a/backend/shiftjis.c b/backend/shiftjis.c new file mode 100644 index 00000000..2c8a7e5b --- /dev/null +++ b/backend/shiftjis.c @@ -0,0 +1,118 @@ +/* shiftjis.c - Handle conversion to Shift-JIS */ + +/* + 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 "common.h" +#include "sjis.h" + +int shiftJIS(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length, int *kanji) +{ /* QR Code supports compression of Shift-JIS data using "Kanji" mode - this function + attempts to convert Unicode characters to Shift-JIS to allow this */ + int bpos, jpos, error_number, i, done; + int next; + unsigned long int uval, jval; + + bpos = 0; + jpos = 0; + error_number = 0; + next = 0; + + do { + uval = 0; + jval = 0; + done = 0; + + if(source[bpos] <= 0x7f) { + /* 1 byte mode (7-bit ASCII) */ + uval = source[bpos]; + next = bpos + 1; + preprocessed[jpos] = uval; + jpos++; + done = 1; + } + + if(done == 0) { + if((source[bpos] >= 0x80) && (source[bpos] <= 0xbf)) { + strcpy(symbol->errtxt, "Corrupt Unicode data"); + return ERROR_INVALID_DATA; + } + } + + if(done == 0) { + if((source[bpos] >= 0xc0) && (source[bpos] <= 0xc1)) { + strcpy(symbol->errtxt, "Overlong encoding not supported"); + return ERROR_INVALID_DATA; + } + } + + if(done == 0) { + if((source[bpos] >= 0xc2) && (source[bpos] <= 0xdf)) { + /* 2 byte mode (Latin 1) */ + uval = ((source[bpos] & 0x1f) << 6) + (source[bpos + 1] & 0x3f); + next = bpos + 2; + preprocessed[jpos] = uval; + jpos++; + done = 1; + } + } + + if(done == 0) { + if((source[bpos] >= 0xe0) && (source[bpos] <= 0xef)) { + /* 3 byte mode (Japanese) */ + uval = ((source[bpos] & 0x0f) << 12) + ((source[bpos + 1] & 0x3f) << 6) + (source[bpos + 2] & 0x3f); + next = bpos + 3; + *kanji = 1; + + for(i = 0; i < 6843; i++) { + if(sjis_lookup[i * 2] == uval) { + jval = sjis_lookup[(i * 2) + 1]; + } + } + + if(jval == 0) { + strcpy(symbol->errtxt, "Invalid Shift JIS character"); + return ERROR_INVALID_DATA; + } + + preprocessed[jpos] = (jval & 0xff00) >> 8; + preprocessed[jpos + 1] = (jval & 0xff); + + /* printf("Unicode value U+%04X = Shift JIS value 0x%04X\n", uval, jval); */ + + jpos += 2; + done = 1; + } + } + + if(done == 0) { + if(source[bpos] >= 0xf0) { + strcpy(symbol->errtxt, "Unicode sequences of more than 3 bytes not supported"); + return ERROR_INVALID_DATA; + } + } + + bpos = next; + + } while(bpos < *length); + *length = jpos; + + return error_number; +} diff --git a/backend/shiftjis.h b/backend/shiftjis.h new file mode 100644 index 00000000..f3e3f5b4 --- /dev/null +++ b/backend/shiftjis.h @@ -0,0 +1,27 @@ +/* shiftjis.h - Handle conversion to Shift-JIS */ + +/* + 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. +*/ + +#ifndef __SHIFTJIS_H +#define __SHIFTJIS_H + +int shiftJIS(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length, int *kanji); + +#endif diff --git a/backend/svg.c b/backend/svg.c index a17540c3..f67fea41 100644 --- a/backend/svg.c +++ b/backend/svg.c @@ -70,12 +70,12 @@ int svg_plot(struct zint_symbol *symbol) strcpy(symbol->errtxt, "Malformed background colour target"); return ERROR_INVALID_OPTION; } - error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour); + error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour, 6); if (error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Malformed foreground colour target"); return ERROR_INVALID_OPTION; } - error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour); + error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour, 6); if (error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Malformed background colour target"); return ERROR_INVALID_OPTION; diff --git a/backend/telepen.c b/backend/telepen.c index 744c102f..8cced800 100644 --- a/backend/telepen.c +++ b/backend/telepen.c @@ -49,10 +49,9 @@ static char *TeleTable[] = { "1111111111111111", "1131313111", "33313111", "1111 "11311111111111", "331111111111", "111113111113", "31111111111111", "111311111113", "131111111113"}; -int telepen(struct zint_symbol *symbol, unsigned char source[]) +int telepen(struct zint_symbol *symbol, unsigned char source[], int length) { unsigned int i, count, check_digit; - int ascii_value; int error_number; char dest[1000]; @@ -61,12 +60,12 @@ int telepen(struct zint_symbol *symbol, unsigned char source[]) count = 0; - if(ustrlen(source) > 30) { + if(length > 30) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - for(i = 0; i < ustrlen(source); i++) { + for(i = 0; i < length; i++) { if(source[i] > 127) { /* Cannot encode extended ASCII */ strcpy(symbol->errtxt, "Invalid characters in input data"); @@ -77,14 +76,9 @@ int telepen(struct zint_symbol *symbol, unsigned char source[]) /* Start character */ concat(dest, TeleTable['_']); - for (i=0; i < ustrlen(source); i++) + for (i=0; i < length; i++) { - ascii_value = source[i]; - if(ascii_value == symbol->nullchar) { - concat(dest, TeleTable[0]); - } else { - concat(dest, TeleTable[ascii_value]); - } + concat(dest, TeleTable[source[i]]); count += source[i]; } @@ -96,55 +90,63 @@ int telepen(struct zint_symbol *symbol, unsigned char source[]) concat(dest, TeleTable['z']); expand(symbol, dest); - ustrcpy(symbol->text, source); + for(i = 0; i < length; i++) { + if(source[i] == '\0') { + symbol->text[i] = ' '; + } else { + symbol->text[i] = source[i]; + } + } + symbol->text[length] = '\0'; return error_number; } -int telepen_num(struct zint_symbol *symbol, unsigned char source[]) +int telepen_num(struct zint_symbol *symbol, unsigned char source[], int length) { unsigned int i, count, check_digit, glyph; - int error_number, input_length; + int error_number; unsigned char dest[1000]; unsigned char local_source[100]; error_number = 0; memset(dest, 0, 1000); memset(local_source, 0, 100); - strcpy((char*)local_source, (char*)source); - input_length = ustrlen(source); count = 0; - if(input_length > 60) { + if(length > 60) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } + for(i = 0; i < length; i++) { + local_source[i] = source[i]; + } to_upper(local_source); - error_number = is_sane(NASET, local_source); + error_number = is_sane(NASET, local_source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } /* Add a leading zero if required */ - if ((input_length % 2) != 0) + if ((length % 2) != 0) { char temp[200]; strcpy(temp, (char*)local_source); local_source[0] = '0'; - for(i = 0; i <= input_length; i++) + for(i = 0; i <= length; i++) { local_source[i + 1] = temp[i]; } - input_length++; + length++; } /* Start character */ concat((char*)dest, TeleTable['_']); - for (i=0; i < input_length; i+=2) + for (i=0; i < length; i+=2) { if(local_source[i] == 'X') { strcpy(symbol->errtxt, "Invalid position of X in Telepen data"); diff --git a/backend/upcean.c b/backend/upcean.c index cb503103..7a810045 100644 --- a/backend/upcean.c +++ b/backend/upcean.c @@ -402,18 +402,9 @@ char isbn_check(unsigned char source[]) /* For ISBN(10) and SBN only */ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Make an EAN-13 barcode from an SBN or ISBN */ { - int i, errno; + int i; char check_digit; - - errno = 0; - to_upper(source); - errno = is_sane("0123456789X", source); - if(errno == ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Invalid characters in input"); - return errno; - } - /* Input must be 9, 10 or 13 characters */ if(((ustrlen(source) < 9) || (ustrlen(source) > 13)) || ((ustrlen(source) > 10) && (ustrlen(source) < 13))) { @@ -491,7 +482,7 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Mak ean13(symbol, source, dest); } - return errno; + return 0; } void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsigned char local_source[]) { @@ -575,15 +566,15 @@ void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsi } } -int eanx(struct zint_symbol *symbol, unsigned char source[]) +int eanx(struct zint_symbol *symbol, unsigned char source[], int length) { /* splits string to parts before and after '+' parts */ unsigned char first_part[20], second_part[20], dest[1000]; unsigned char local_source[20]; unsigned int latch, reader, writer, with_addon; - int errno, i; + int error_number, i; - errno = 0; + error_number = 0; memset(dest,0,1000); memset(first_part,0,20); memset(second_part,0,20); @@ -592,21 +583,32 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) latch = FALSE; writer = 0; - if(ustrlen(source) > 19) { + if(length > 19) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } if(symbol->symbology != BARCODE_ISBNX) { /* ISBN has it's own checking routine */ - errno = is_sane(NASET, source); - if(errno == ERROR_INVALID_DATA) { + error_number = is_sane(NASET, source, length); + if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); - return errno; + return error_number; + } + } else { + error_number = is_sane("0123456789Xx", source, length); + if(error_number == ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Invalid characters in input"); + return error_number; } } + /* Add leading zeroes */ ustrcpy(local_source, (unsigned char *)""); + if(symbol->symbology == BARCODE_ISBNX) { + to_upper(local_source); + } + ean_leading_zeroes(symbol, source, local_source); for(reader = 0; reader <= ustrlen(local_source); reader++) @@ -732,9 +734,9 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) } break; case BARCODE_ISBNX: - errno = isbn(symbol, first_part, (char*)dest); - if(errno > 4) { - return errno; + error_number = isbn(symbol, first_part, (char*)dest); + if(error_number > 4) { + return error_number; } break; } @@ -777,10 +779,10 @@ int eanx(struct zint_symbol *symbol, unsigned char source[]) } - if((symbol->errtxt[0] == 'w') && (errno == 0)) { - errno = 1; /* flag UPC-E warnings */ + if((symbol->errtxt[0] == 'w') && (error_number == 0)) { + error_number = 1; /* flag UPC-E warnings */ } - return errno; + return error_number; } diff --git a/backend/zint.h b/backend/zint.h index 12a16fff..a276f555 100644 --- a/backend/zint.h +++ b/backend/zint.h @@ -139,6 +139,7 @@ struct zint_symbol { #define BARCODE_RSS_EXPSTACK_CC 139 #define BARCODE_CHANNEL 140 #define BARCODE_CODEONE 141 +#define BARCODE_GRIDMATRIX 142 #define BARCODE_NO_ASCII 1 #define BARCODE_BIND 2 @@ -176,13 +177,18 @@ struct zint_symbol { ZINT_EXTERN struct zint_symbol *ZBarcode_Create(void); ZINT_EXTERN int ZBarcode_Delete(struct zint_symbol *symbol); -ZINT_EXTERN int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input); -ZINT_EXTERN int ZBarcode_Encode_from_File(struct zint_symbol *symbol, char *filename); -ZINT_EXTERN int ZBarcode_Print(struct zint_symbol *symbol); -ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input); + +ZINT_EXTERN int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *input, int length); +ZINT_EXTERN int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename); +ZINT_EXTERN int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle); +ZINT_EXTERN int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle); +ZINT_EXTERN int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle); + +ZINT_EXTERN int ZBarcode_ValidID(int symbol_id); + +/* Depreciated */ +ZINT_EXTERN int ZBarcode_Print_Rotated(struct zint_symbol *symbol, int rotate_angle); ZINT_EXTERN int ZBarcode_Encode_and_Print_Rotated(struct zint_symbol *symbol, unsigned char *input, int rotate_angle); -ZINT_EXTERN int ZBarcode_Encode_from_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle); -ZINT_EXTERN int ZBarcode_Check_Supported(int symbol_id); #ifdef __cplusplus } diff --git a/backend_qt4/qzint.cpp b/backend_qt4/qzint.cpp index 9a7d8cbd..954f531a 100644 --- a/backend_qt4/qzint.cpp +++ b/backend_qt4/qzint.cpp @@ -67,7 +67,7 @@ void QZint::encode() QByteArray bstr=m_text.toAscii(); QByteArray pstr=m_primaryMessage.left(99).toAscii(); strcpy(m_zintSymbol->primary,pstr.data()); - int error = ZBarcode_Encode(m_zintSymbol, (unsigned char*)bstr.data()); + int error = ZBarcode_Encode(m_zintSymbol, (unsigned char*)bstr.data(), bstr.length()); if (error > WARN_INVALID_OPTION) m_lastError=m_zintSymbol->errtxt; @@ -251,7 +251,7 @@ bool QZint::save_to_file(QString filename) QByteArray bgcol=bg_colour_hash.right(6).toAscii(); strcpy(m_zintSymbol->fgcolour,fgcol.data()); strcpy(m_zintSymbol->bgcolour,bgcol.data()); - int error = ZBarcode_Encode_and_Print(m_zintSymbol, (unsigned char*)bstr.data()); + int error = ZBarcode_Encode_and_Print(m_zintSymbol, (unsigned char*)bstr.data(), bstr.length(), 0); if (error > WARN_INVALID_OPTION) m_lastError=m_zintSymbol->errtxt; if(error == 0) { return true; } else { return false; } diff --git a/frontend/main.c b/frontend/main.c index c4de2782..c5e062a3 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -338,11 +338,7 @@ int main(int argc, char **argv) break; case 'd': /* we have some data! */ - if(rotate_angle == 0) { - error_number = ZBarcode_Encode_and_Print(my_symbol, (unsigned char*)optarg); - } else { - error_number = ZBarcode_Encode_and_Print_Rotated(my_symbol, (unsigned char*)optarg, rotate_angle); - } + error_number = ZBarcode_Encode_and_Print(my_symbol, (unsigned char*)optarg, strlen(optarg), rotate_angle); generated = 1; if(error_number != 0) { fprintf(stderr, "%s\n", my_symbol->errtxt); @@ -352,7 +348,7 @@ int main(int argc, char **argv) break; case 'i': /* Take data from file */ - error_number = ZBarcode_Encode_from_File_and_Print(my_symbol, optarg, rotate_angle); + error_number = ZBarcode_Encode_File_and_Print(my_symbol, optarg, rotate_angle); generated = 1; if(error_number != 0) { fprintf(stderr, "%s\n", my_symbol->errtxt); diff --git a/frontend_qt4/mainwindow.cpp b/frontend_qt4/mainwindow.cpp index 177055f0..b01a21fa 100644 --- a/frontend_qt4/mainwindow.cpp +++ b/frontend_qt4/mainwindow.cpp @@ -158,7 +158,7 @@ bool MainWindow::save() QString fileName = QFileDialog::getSaveFileName(this, tr("Save Barcode Image"), ".", - tr("Barcode Images (*.png *.eps *.svg)")); + tr("Portable Network Graphic (*.png);;Encapsulated Post Script (*.eps);;Scalable Vector Graphic (*.svg)")); if (fileName.isEmpty()) return false;