mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Add corrections from tgotic
This commit is contained in:
parent
de9984a346
commit
1ff9c0d472
123
backend/2of5.c
123
backend/2of5.c
@ -39,26 +39,25 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int l
|
||||
{ /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */
|
||||
|
||||
int i, error_number;
|
||||
char dest[1000];
|
||||
char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 80) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat (dest, "411111");
|
||||
strcpy(dest, "411111");
|
||||
|
||||
for(i = 0; i <= length; i++) {
|
||||
lookup(NESET, C25MatrixTable, source[i], dest);
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
@ -73,26 +72,25 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i
|
||||
{ /* Code 2 of 5 Industrial */
|
||||
|
||||
int i, error_number;
|
||||
char dest[1000];
|
||||
char dest[512]; /* 6 + 40 * 10 + 6 + 1 */
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 45) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid character in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat (dest, "313111");
|
||||
strcpy(dest, "313111");
|
||||
|
||||
for(i = 0; i <= length; i++) {
|
||||
lookup(NESET, C25IndustTable, source[i], dest);
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
@ -106,26 +104,25 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i
|
||||
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];
|
||||
char dest[512]; /* 4 + 45 * 10 + 3 + 1 */
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 45) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start */
|
||||
concat (dest, "1111");
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(NESET, C25IndustTable, source[i], dest);
|
||||
lookup(NEON, C25IndustTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* stop */
|
||||
@ -140,26 +137,25 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int le
|
||||
{ /* Code 2 of 5 Data Logic */
|
||||
|
||||
int i, error_number;
|
||||
char dest[1000];
|
||||
char dest[512]; /* 4 + 80 * 6 + 3 + 1 */
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 80) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat (dest, "1111");
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for(i = 0; i <= length; i++) {
|
||||
lookup(NESET, C25MatrixTable, source[i], dest);
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(NEON, C25MatrixTable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
@ -175,15 +171,16 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
|
||||
|
||||
int i, j, k, error_number;
|
||||
char bars[7], spaces[7], mixed[14], dest[1000];
|
||||
unsigned char *temp = source;
|
||||
unsigned int temp_len = length;
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 90) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if (error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
@ -191,31 +188,28 @@ 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 ((length%2) != 0)
|
||||
if ((length % 2) != 0)
|
||||
{
|
||||
/* there are an odd number of input characters */
|
||||
char temp[100];
|
||||
|
||||
strcpy(temp, (char*)source);
|
||||
source[0] = '0';
|
||||
|
||||
for(i = 0; i <= length; i++)
|
||||
if (NULL == (temp = (unsigned char*)malloc(++temp_len)))
|
||||
{
|
||||
source[i + 1] = temp[i];
|
||||
strcpy(symbol->errtxt, "Memory allocation failed");
|
||||
return ERROR_MEMORY;
|
||||
}
|
||||
length++;
|
||||
temp[0] = '0';
|
||||
ustrcpy(temp + 1, source);
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat(dest, "1111");
|
||||
strcpy(dest, "1111");
|
||||
|
||||
for(i = 0; i < length; i+=2 )
|
||||
for(i = 0; i < temp_len; i+=2 )
|
||||
{
|
||||
/* look up the bars and the spaces and put them in two strings */
|
||||
strcpy(bars, "");
|
||||
lookup(NESET, C25InterTable, source[i], bars);
|
||||
lookup(NEON, C25InterTable, temp[i], bars);
|
||||
strcpy(spaces, "");
|
||||
lookup(NESET, C25InterTable, source[i + 1], spaces);
|
||||
lookup(NEON, C25InterTable, temp[i + 1], spaces);
|
||||
|
||||
/* then merge (interlace) the strings together */
|
||||
k = 0;
|
||||
@ -232,7 +226,9 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[],
|
||||
concat (dest, "311");
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
ustrcpy(symbol->text, temp);
|
||||
if (temp != source)
|
||||
free(source);
|
||||
return error_number;
|
||||
|
||||
}
|
||||
@ -241,8 +237,7 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count, check_digit;
|
||||
char localstr[15];
|
||||
char checkstr[3];
|
||||
char localstr[16];
|
||||
|
||||
error_number = 0;
|
||||
|
||||
@ -253,19 +248,18 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid character in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Add leading zeros as required */
|
||||
strcpy(localstr, "");
|
||||
zeroes = 13 - length;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
concat(localstr, "0");
|
||||
localstr[i] = '0';
|
||||
}
|
||||
concat(localstr, (char *)source);
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
|
||||
/* Calculate the check digit - the same method used for EAN-13 */
|
||||
|
||||
@ -280,9 +274,8 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
checkstr[0] = itoc(check_digit);
|
||||
checkstr[1] = '\0';
|
||||
concat(localstr, checkstr);
|
||||
localstr[13] = itoc(check_digit);
|
||||
localstr[14] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
return error_number;
|
||||
@ -292,7 +285,7 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Deutshe Post Leitcode */
|
||||
int i, error_number;
|
||||
unsigned int count, check_digit;
|
||||
char localstr[15], checkstr[3];
|
||||
char localstr[16];
|
||||
int zeroes;
|
||||
|
||||
error_number = 0;
|
||||
@ -301,17 +294,16 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
strcpy(localstr, "");
|
||||
zeroes = 13 - length;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
concat(localstr, "0");
|
||||
concat(localstr, (char *)source);
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
|
||||
for (i = 12; i >= 0; i--)
|
||||
{
|
||||
@ -324,11 +316,9 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
checkstr[0] = itoc(check_digit);
|
||||
checkstr[1] = '\0';
|
||||
concat(localstr, checkstr);
|
||||
length = strlen(localstr);
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, length);
|
||||
localstr[13] = itoc(check_digit);
|
||||
localstr[14] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
return error_number;
|
||||
}
|
||||
@ -337,24 +327,23 @@ int dpident(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Deutsche Post Identcode */
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count, check_digit;
|
||||
char localstr[13], checkstr[3];
|
||||
char localstr[16];
|
||||
|
||||
count = 0;
|
||||
if(length > 11) {
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
strcpy(localstr, "");
|
||||
zeroes = 11 - length;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
concat(localstr, "0");
|
||||
concat(localstr, (char *)source);
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
|
||||
for (i = 10; i >= 0; i--)
|
||||
{
|
||||
@ -367,11 +356,9 @@ int dpident(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
checkstr[0] = itoc(check_digit);
|
||||
checkstr[1] = '\0';
|
||||
concat(localstr, checkstr);
|
||||
length = strlen(localstr);
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, length);
|
||||
localstr[11] = itoc(check_digit);
|
||||
localstr[12] = '\0';
|
||||
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
return error_number;
|
||||
}
|
||||
|
@ -3,12 +3,11 @@
|
||||
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 shiftjis.c)
|
||||
set(zint_COMMON_SRCS common.c library.c ps.c large.c reedsol.c gs1.c svg.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 gridmtx.c)
|
||||
set(zint_TWODIM_SRCS code16k.c blockf.c dmatrix.c dm200.c pdf417.c qr.c qrrs.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)
|
||||
@ -18,18 +17,12 @@ else(PNG_FOUND)
|
||||
add_definitions (-DNO_PNG)
|
||||
endif(PNG_FOUND)
|
||||
|
||||
if(QR_FOUND)
|
||||
include_directories( ${QR_INCLUDES} )
|
||||
else(QR_FOUND)
|
||||
add_definitions (-DNO_QR)
|
||||
endif(QR_FOUND)
|
||||
|
||||
add_library(zint SHARED ${zint_SRCS})
|
||||
|
||||
set_target_properties(zint PROPERTIES SOVERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}"
|
||||
VERSION ${ZINT_VERSION})
|
||||
|
||||
target_link_libraries(zint ${PNG_LIBRARIES} ${QR_LIBRARIES} )
|
||||
target_link_libraries(zint ${PNG_LIBRARIES} )
|
||||
|
||||
install(TARGETS zint ${INSTALL_TARGETS_DEFAULT_ARGS} )
|
||||
install(FILES zint.h DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel)
|
||||
|
@ -1,7 +1,6 @@
|
||||
# Linux makefile for libzint
|
||||
#
|
||||
# make compiles with QR Code support
|
||||
# make libzint_noqr compiles without QR Code support
|
||||
# make compiles
|
||||
# make install copies to /usr/local/lib
|
||||
# make uninstall removes library
|
||||
# make clean cleans up a previous compilation and any object or editor files
|
||||
@ -19,29 +18,22 @@ includedir := $(prefix)/include
|
||||
libdir := $(prefix)/lib
|
||||
DESTDIR :=
|
||||
|
||||
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
|
||||
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
|
||||
ONEDIM:= code.c code128.c 2of5.c upcean.c telepen.c medical.c plessey.c rss.c qrrs.c
|
||||
ONEDIM_OBJ:= code.o code128.o 2of5.o upcean.o telepen.o medical.o plessey.o rss.o qrrs.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 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)
|
||||
DEFINES:= -DNO_QR
|
||||
else
|
||||
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 gridmtx.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 qrrs.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)
|
||||
$(CC) -Wall -fPIC $(CFLAGS) $(ZINT_VERSION) -c $(TWODIM)
|
||||
$(CC) -Wall -fPIC $(CFLAGS) $(ZINT_VERSION) -c $(COMMON)
|
||||
$(CC) $(CFLAGS) $(ZINT_VERSION) -shared -Wl,-soname,libzint.so -o libzint.so.2.2.1 $(INCLUDE) $(COMMON_OBJ) $(ONEDIM_OBJ) $(TWODIM_OBJ) $(POSTAL_OBJ) $(LIBS)
|
||||
$(CC) $(CFLAGS) $(ZINT_VERSION) -shared -Wl,-soname,libzint.so -o libzint.so.2.2.2 $(INCLUDE) $(COMMON_OBJ) $(ONEDIM_OBJ) $(TWODIM_OBJ) $(POSTAL_OBJ) $(LIBS)
|
||||
ln -s libzint.so.* libzint.so
|
||||
|
||||
.PHONY: install uninstall clean dist
|
||||
|
@ -25,20 +25,14 @@ 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 shiftjis.o
|
||||
ONEDIM_OBJ:= code.o code128.o 2of5.o upcean.o telepen.o medical.o plessey.o rss.o
|
||||
COMMON_OBJ:= common.o png.o library.o ps.o large.o reedsol.o gs1.o svg.o
|
||||
ONEDIM_OBJ:= code.o code128.o 2of5.o upcean.o telepen.o medical.o plessey.o rss.o qrrs.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 code1.o gridmtx.o
|
||||
|
||||
LIB_OBJ:= $(COMMON_OBJ) $(ONEDIM_OBJ) $(TWODIM_OBJ) $(POSTAL_OBJ)
|
||||
DLL_OBJ:= $(LIB_OBJ:.o=.lo) dllversion.lo
|
||||
|
||||
ifeq ($(NO_QR),true)
|
||||
DEFINES+= -DNO_QR
|
||||
else
|
||||
DEFINES_DLL+= -DQRENCODE_DLL
|
||||
LIBS+= -lqrencode
|
||||
endif
|
||||
|
||||
ifeq ($(NO_PNG),true)
|
||||
DEFINES+= -DNO_PNG
|
||||
|
@ -107,15 +107,14 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
2 = Tracker and Descender
|
||||
3 = Tracker only */
|
||||
int error_number, zeroes;
|
||||
int writer, i;
|
||||
unsigned int loopey, reader;
|
||||
int writer;
|
||||
unsigned int loopey, reader, h;
|
||||
|
||||
char data_pattern[200];
|
||||
char fcc[3], dpid[10];
|
||||
char localstr[30];
|
||||
|
||||
error_number = 0;
|
||||
strcpy (data_pattern, "");
|
||||
strcpy(localstr, "");
|
||||
|
||||
/* Do all of the length checking first to avoid stack smashing */
|
||||
@ -125,9 +124,9 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
{
|
||||
case 8: strcpy(fcc, "11"); break;
|
||||
case 13: strcpy(fcc, "59"); break;
|
||||
case 16: strcpy(fcc, "59"); error_number = is_sane(NESET, source, length); break;
|
||||
case 16: strcpy(fcc, "59"); error_number = is_sane(NEON, source, length); break;
|
||||
case 18: strcpy(fcc, "62"); break;
|
||||
case 23: strcpy(fcc, "62"); error_number = is_sane(NESET, source, length); break;
|
||||
case 23: strcpy(fcc, "62"); error_number = is_sane(NEON, source, length); break;
|
||||
default: strcpy(symbol->errtxt, "Auspost input is wrong length");
|
||||
return ERROR_TOO_LONG;
|
||||
break;
|
||||
@ -137,7 +136,7 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
return error_number;
|
||||
}
|
||||
} else {
|
||||
if(ustrlen(source) > 8) {
|
||||
if(length > 8) {
|
||||
strcpy(symbol->errtxt, "Auspost input is too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
@ -149,36 +148,34 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
|
||||
/* Add leading zeros as required */
|
||||
zeroes = 8 - length;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
concat(localstr, "0");
|
||||
}
|
||||
memset(localstr, '0', zeroes);
|
||||
localstr[8] = '\0';
|
||||
}
|
||||
|
||||
concat(localstr, (char*)source);
|
||||
error_number = is_sane(GDSET, (unsigned char *)localstr, length);
|
||||
h = strlen(localstr);
|
||||
error_number = is_sane(GDSET, (unsigned char *)localstr, h);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Verifiy that the first 8 characters are numbers */
|
||||
for(loopey = 0; loopey < 8; loopey++) {
|
||||
dpid[loopey] = localstr[loopey];
|
||||
}
|
||||
memcpy(dpid, localstr, 8);
|
||||
dpid[8] = '\0';
|
||||
error_number = is_sane(NESET, (unsigned char *)dpid, 8);
|
||||
error_number = is_sane(NEON, (unsigned char *)dpid, strlen(dpid));
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in DPID");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Start character */
|
||||
concat(data_pattern, "13");
|
||||
strcpy(data_pattern, "13");
|
||||
|
||||
/* Encode the FCC */
|
||||
for(reader = 0; reader < 2; reader++)
|
||||
{
|
||||
lookup(NESET, AusNTable, fcc[reader], data_pattern);
|
||||
lookup(NEON, AusNTable, fcc[reader], data_pattern);
|
||||
}
|
||||
|
||||
/* printf("AUSPOST FCC: %s ", fcc); */
|
||||
@ -186,32 +183,33 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
/* Delivery Point Identifier (DPID) */
|
||||
for(reader = 0; reader < 8; reader++)
|
||||
{
|
||||
lookup(NESET, AusNTable, dpid[reader], data_pattern);
|
||||
lookup(NEON, AusNTable, dpid[reader], data_pattern);
|
||||
}
|
||||
|
||||
/* Customer Information */
|
||||
if(strlen(localstr) > 8)
|
||||
if(h > 8)
|
||||
{
|
||||
if((strlen(localstr) == 13) || (strlen(localstr) == 18)) {
|
||||
for(reader = 8; reader < strlen(localstr); reader++) {
|
||||
if((h == 13) || (h == 18)) {
|
||||
for(reader = 8; reader < h; reader++) {
|
||||
lookup(GDSET, AusCTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
if((strlen(localstr) == 16) || (strlen(localstr) == 23)) {
|
||||
for(reader = 8; reader < strlen(localstr); reader++) {
|
||||
lookup(NESET, AusNTable, localstr[reader], data_pattern);
|
||||
if((h == 16) || (h == 23)) {
|
||||
for(reader = 8; reader < h; reader++) {
|
||||
lookup(NEON, AusNTable, localstr[reader], data_pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Filler bar */
|
||||
if(strlen(data_pattern) == 22) {
|
||||
h = strlen(data_pattern);
|
||||
if(h == 22) {
|
||||
concat(data_pattern, "3");
|
||||
}
|
||||
if(strlen(data_pattern) == 37) {
|
||||
else if(h == 37) {
|
||||
concat(data_pattern, "3");
|
||||
}
|
||||
if(strlen(data_pattern) == 52) {
|
||||
else if(h == 52) {
|
||||
concat(data_pattern, "3");
|
||||
}
|
||||
|
||||
@ -223,7 +221,8 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt
|
||||
|
||||
/* Turn the symbol into a bar pattern ready for plotting */
|
||||
writer = 0;
|
||||
for(loopey = 0; loopey < strlen(data_pattern); loopey++)
|
||||
h = strlen(data_pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0'))
|
||||
{
|
||||
|
@ -31,12 +31,9 @@
|
||||
|
||||
void mapshorten(int *charmap, int *typemap, int start, int length)
|
||||
{ /* Shorten the string by one character */
|
||||
int i;
|
||||
|
||||
for(i = start + 1; i < (length - 1); i++) {
|
||||
charmap[i] = charmap[i + 1];
|
||||
typemap[i] = typemap[i + 1];
|
||||
}
|
||||
memmove(charmap + start + 1 , charmap + start + 2, (length - 1) * sizeof(int));
|
||||
memmove(typemap + start + 1 , typemap + start + 2, (length - 1) * sizeof(int));
|
||||
}
|
||||
|
||||
void insert(char binary_string[], int posn, char newbit)
|
||||
@ -50,51 +47,47 @@ void insert(char binary_string[], int posn, char newbit)
|
||||
binary_string[posn] = newbit;
|
||||
}
|
||||
|
||||
int aztec_text_process(unsigned char source[], char binary_string[], int gs1)
|
||||
int aztec_text_process(unsigned char source[], const unsigned int src_len, char binary_string[], int gs1)
|
||||
{ /* Encode input data into a binary string */
|
||||
int i, j, k, bytes;
|
||||
int curtable, newtable, lasttable, chartype, maplength, blocks, debug;
|
||||
#ifndef _MSC_VER
|
||||
int charmap[ustrlen(source) * 2], typemap[ustrlen(source) * 2];
|
||||
int blockmap[2][ustrlen(source)];
|
||||
int charmap[src_len * 2], typemap[src_len * 2];
|
||||
int blockmap[2][src_len];
|
||||
#else
|
||||
int* charmap = (int*)_alloca((ustrlen(source) * 2) * sizeof(int));
|
||||
int* typemap = (int*)_alloca((ustrlen(source) * 2) * sizeof(int));
|
||||
int* charmap = (int*)_alloca(src_len * 2 * sizeof(int));
|
||||
int* typemap = (int*)_alloca(src_len * 2 * sizeof(int));
|
||||
int* blockmap[2];
|
||||
blockmap[0] = (int*)_alloca(ustrlen(source) * sizeof(int));
|
||||
blockmap[1] = (int*)_alloca(ustrlen(source) * sizeof(int));
|
||||
blockmap[0] = (int*)_alloca(src_len * sizeof(int));
|
||||
blockmap[1] = (int*)_alloca(src_len * sizeof(int));
|
||||
#endif
|
||||
/* Lookup input string in encoding table */
|
||||
maplength = 0;
|
||||
debug = 0;
|
||||
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if(gs1 && (i == 0)) {
|
||||
/* Add FNC1 to beginning of GS1 messages */
|
||||
charmap[maplength] = 0;
|
||||
typemap[maplength] = PUNC;
|
||||
maplength++;
|
||||
typemap[maplength++] = PUNC;
|
||||
charmap[maplength] = 400;
|
||||
typemap[maplength] = PUNC;
|
||||
maplength++;
|
||||
typemap[maplength++] = PUNC;
|
||||
}
|
||||
if((gs1) && (source[i] == '[')) {
|
||||
/* FNC1 represented by FLG(0) */
|
||||
charmap[maplength] = 0;
|
||||
typemap[maplength] = PUNC;
|
||||
maplength++;
|
||||
typemap[maplength++] = PUNC;
|
||||
charmap[maplength] = 400;
|
||||
typemap[maplength] = PUNC;
|
||||
typemap[maplength++] = PUNC;
|
||||
} else {
|
||||
if(source[i] > 127) {
|
||||
charmap[maplength] = source[i];
|
||||
typemap[maplength] = BINARY;
|
||||
typemap[maplength++] = BINARY;
|
||||
} else {
|
||||
charmap[maplength] = AztecSymbolChar[source[i]];
|
||||
typemap[maplength] = AztecCodeSet[source[i]];
|
||||
typemap[maplength++] = AztecCodeSet[source[i]];
|
||||
}
|
||||
}
|
||||
maplength++;
|
||||
}
|
||||
|
||||
/* Look for double character encoding possibilities */
|
||||
@ -245,10 +238,7 @@ int aztec_text_process(unsigned char source[], char binary_string[], int gs1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < 20000; i++) {
|
||||
binary_string[i] = '\0';
|
||||
}
|
||||
*binary_string = '\0';
|
||||
|
||||
curtable = UPPER; /* start with UPPER table */
|
||||
lasttable = UPPER;
|
||||
@ -664,15 +654,11 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int err_code, ecc_level, compact, data_length, data_maxsize, codeword_size, adjusted_length;
|
||||
int remainder, padbits, count, gs1, adjustment_size;
|
||||
int debug = 0;
|
||||
#ifdef _MSC_VER
|
||||
unsigned int* data_part;
|
||||
unsigned int* ecc_part;
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
unsigned char local_source[length];
|
||||
unsigned char local_source[length + 1];
|
||||
#else
|
||||
unsigned char local_source = (unsigned char*)_alloca(length);
|
||||
unsigned char* local_source = (unsigned char*)_alloca(length + 1);
|
||||
#endif
|
||||
|
||||
memset(binary_string,0,20000);
|
||||
@ -682,9 +668,8 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* 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];
|
||||
}
|
||||
case GS1_MODE:
|
||||
memcpy(local_source, source, length);
|
||||
local_source[length] = '\0';
|
||||
break;
|
||||
case UNICODE_MODE:
|
||||
@ -701,7 +686,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
|
||||
err_code = aztec_text_process(local_source, binary_string, gs1);
|
||||
err_code = aztec_text_process(local_source, length, binary_string, gs1);
|
||||
|
||||
if(err_code != 0) {
|
||||
strcpy(symbol->errtxt, "Input too long or too many extended ASCII characters");
|
||||
@ -985,8 +970,8 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
#ifndef _MSC_VER
|
||||
unsigned int data_part[data_blocks + 3], ecc_part[ecc_blocks + 3];
|
||||
#else
|
||||
data_part = (unsigned int*)_alloca((data_blocks + 3) * sizeof(unsigned int));
|
||||
ecc_part = (unsigned int*)_alloca((ecc_blocks + 3) * sizeof(unsigned int));
|
||||
unsigned int* data_part = (unsigned int*)_alloca((data_blocks + 3) * sizeof(unsigned int));
|
||||
unsigned int* ecc_part = (unsigned int*)_alloca((ecc_blocks + 3) * sizeof(unsigned int));
|
||||
#endif
|
||||
/* Copy across data into separate integers */
|
||||
memset(data_part,0,(data_blocks + 2)*sizeof(int));
|
||||
@ -1249,7 +1234,7 @@ int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Input too large");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number != 0) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in input");
|
||||
return ERROR_INVALID_DATA;
|
||||
|
@ -59,7 +59,6 @@ static char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322",
|
||||
"411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232",
|
||||
"2331112"};
|
||||
|
||||
int parunmodd(unsigned char llyth);
|
||||
void grwp(int *indexliste);
|
||||
void dxsmooth(int *indexliste);
|
||||
|
||||
@ -94,16 +93,15 @@ int character_subset_select(unsigned char source[], int input_position) {
|
||||
return MODEB;
|
||||
}
|
||||
|
||||
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 data_encode_blockf(unsigned char source[], int input_length, 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 i, j, input_position, current_mode, current_row, error_number;
|
||||
int column_position, c, done, exit_status;
|
||||
|
||||
error_number = 0;
|
||||
exit_status = 0;
|
||||
current_row = 0;
|
||||
current_mode = MODEA;
|
||||
input_length = ustrlen(source);
|
||||
column_position = 0;
|
||||
input_position = 0;
|
||||
done = 0;
|
||||
@ -303,7 +301,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])== 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
|
||||
@ -570,7 +568,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
|
||||
|
||||
int codablock(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int error_number, input_length, i, j, k;
|
||||
int error_number, input_length, i, j, k, h;
|
||||
int rows_needed, columns_needed;
|
||||
int min_module_height;
|
||||
int last_mode, this_mode, final_mode;
|
||||
@ -624,7 +622,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Encode the data */
|
||||
error_number = data_encode_blockf(source, subset_selector, blockmatrix, &columns_needed, &rows_needed, &final_mode, gs1);
|
||||
error_number = data_encode_blockf(source, input_length, 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");
|
||||
@ -728,7 +726,8 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Write the information into the symbol */
|
||||
writer = 0;
|
||||
flip_flop = 1;
|
||||
for (j = 0; j < strlen(row_pattern); j++) {
|
||||
h = strlen(row_pattern);
|
||||
for (j = 0; j < h; j++) {
|
||||
for(k = 0; k < ctoi(row_pattern[j]); k++) {
|
||||
if(flip_flop == 1) {
|
||||
set_module(symbol, i, writer);
|
||||
|
222
backend/code.c
222
backend/code.c
@ -26,15 +26,15 @@
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
|
||||
#define SODIUM "0123456789-"
|
||||
#define SILVER "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd"
|
||||
|
||||
#define NASET "0123456789-"
|
||||
static char *C11Table[11] = {"111121", "211121", "121121", "221111", "112121", "212111", "122111",
|
||||
"111221", "211211", "211111", "112111"};
|
||||
|
||||
|
||||
/* Code 39 tables checked against ISO/IEC 16388:2007 */
|
||||
|
||||
#define TCSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd"
|
||||
/* Incorporates Table A1 */
|
||||
|
||||
static char *C39Table[43] = { "1112212111", "2112111121", "1122111121", "2122111111", "1112211121",
|
||||
@ -90,18 +90,17 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
unsigned int i;
|
||||
int h, c_digit, c_weight, c_count, k_digit, k_weight, k_count;
|
||||
int weight[125], error_number;
|
||||
char dest[1230];
|
||||
int weight[128], error_number;
|
||||
char dest[1024]; /* 6 + 121 * 6 + 2 * 6 + 5 + 1 ~ 1024*/
|
||||
char checkstr[3];
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 121) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NASET, source, length);
|
||||
error_number = is_sane(SODIUM, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
@ -112,11 +111,11 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
k_count = 0;
|
||||
|
||||
/* start character */
|
||||
concat (dest, "112211");
|
||||
strcpy(dest, "112211");
|
||||
|
||||
/* Draw main body of barcode */
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(NASET, C11Table, source[i], dest);
|
||||
lookup(SODIUM, C11Table, source[i], dest);
|
||||
if(source[i] == '-')
|
||||
weight[i] = 10;
|
||||
else
|
||||
@ -124,7 +123,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Calculate C checksum */
|
||||
for(h = (length - 1); h >= 0; h--) {
|
||||
for(h = length - 1; h >= 0; h--) {
|
||||
c_count += (c_weight * weight[h]);
|
||||
c_weight++;
|
||||
|
||||
@ -132,7 +131,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
c_weight = 1;
|
||||
}
|
||||
}
|
||||
c_digit = c_count%11;
|
||||
c_digit = c_count % 11;
|
||||
|
||||
weight[length] = c_digit;
|
||||
|
||||
@ -145,15 +144,15 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
k_weight = 1;
|
||||
}
|
||||
}
|
||||
k_digit = k_count%11;
|
||||
k_digit = k_count % 11;
|
||||
|
||||
checkstr[0] = itoc(c_digit);
|
||||
checkstr[1] = itoc(k_digit);
|
||||
if(checkstr[0] == 'A') { checkstr[0] = '-'; }
|
||||
if(checkstr[1] == 'A') { checkstr[1] = '-'; }
|
||||
checkstr[2] = '\0';
|
||||
lookup(NASET, C11Table, checkstr[0], dest);
|
||||
lookup(NASET, C11Table, checkstr[1], dest);
|
||||
lookup(SODIUM, C11Table, checkstr[0], dest);
|
||||
lookup(SODIUM, C11Table, checkstr[1], dest);
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "11221");
|
||||
@ -172,45 +171,35 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
char check_digit;
|
||||
int error_number;
|
||||
char dest[775];
|
||||
char localstr[3];
|
||||
unsigned char local_source[75];
|
||||
char localstr[2] = { 0 };
|
||||
|
||||
error_number = 0;
|
||||
counter = 0;
|
||||
strcpy(dest, "");
|
||||
strcpy(localstr, "");
|
||||
|
||||
if((symbol->option_2 < 0) || (symbol->option_2 > 1)) {
|
||||
symbol->option_2 = 0;
|
||||
}
|
||||
|
||||
if(symbol->symbology == BARCODE_LOGMARS) {
|
||||
if(length > 59) {
|
||||
if((symbol->symbology == BARCODE_LOGMARS) && (length > 59)) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
} else if(length > 74) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
} else {
|
||||
if(length > 74) {
|
||||
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(TCSET , local_source, length);
|
||||
to_upper(source);
|
||||
error_number = is_sane(SILVER , source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Start character */
|
||||
concat(dest, "1211212111");
|
||||
strcpy(dest, "1211212111");
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
lookup(TCSET, C39Table, local_source[i], dest);
|
||||
counter += posn(TCSET, local_source[i]);
|
||||
lookup(SILVER, C39Table, source[i], dest);
|
||||
counter += posn(SILVER, source[i]);
|
||||
}
|
||||
|
||||
if((symbol->symbology == BARCODE_LOGMARS) || (symbol->option_2 == 1)) {
|
||||
@ -234,7 +223,7 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
}
|
||||
lookup(TCSET, C39Table, check_digit, dest);
|
||||
lookup(SILVER, C39Table, check_digit, dest);
|
||||
|
||||
/* Display a space check digit as _, otherwise it looks like an error */
|
||||
if(check_digit == ' ') {
|
||||
@ -250,7 +239,8 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
if((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
|
||||
/* LOGMARS uses wider 'wide' bars than normal Code 39 */
|
||||
for(i = 0; i < strlen(dest); i++) {
|
||||
counter = strlen(dest);
|
||||
for(i = 0; i < counter; i++) {
|
||||
if(dest[i] == '2') {
|
||||
dest[i] = '3';
|
||||
}
|
||||
@ -261,11 +251,11 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
if(symbol->symbology == BARCODE_CODE39) {
|
||||
ustrcpy(symbol->text, (unsigned char*)"*");
|
||||
uconcat(symbol->text, local_source);
|
||||
uconcat(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*)localstr);
|
||||
uconcat(symbol->text, (unsigned char*)"*");
|
||||
} else {
|
||||
ustrcpy(symbol->text, local_source);
|
||||
ustrcpy(symbol->text, source);
|
||||
uconcat(symbol->text, (unsigned char*)localstr);
|
||||
}
|
||||
return error_number;
|
||||
@ -274,10 +264,9 @@ int c39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Pharmazentral Nummer (PZN) */
|
||||
|
||||
int i, error_number;
|
||||
int i, error_number, zeroes;
|
||||
unsigned int count, check_digit;
|
||||
char localstr[10], checkstr[3];
|
||||
int zeroes;
|
||||
char localstr[10];
|
||||
|
||||
error_number = 0;
|
||||
|
||||
@ -286,34 +275,31 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
strcpy(localstr, "-");
|
||||
zeroes = 6 - length;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
concat(localstr, "0");
|
||||
concat(localstr, (char *)source);
|
||||
localstr[0] = '-';
|
||||
zeroes = 6 - length + 1;
|
||||
for(i = 1; i < zeroes; i++)
|
||||
localstr[i] = '0';
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
|
||||
for (i = 1; i < 7; i++)
|
||||
{
|
||||
for (i = 1; i < 7; i++) {
|
||||
count += (i + 1) * ctoi(localstr[i]);
|
||||
}
|
||||
|
||||
check_digit = count%11;
|
||||
if (check_digit == 11) { check_digit = 0; }
|
||||
checkstr[0] = itoc(check_digit);
|
||||
checkstr[1] = '\0';
|
||||
if(checkstr[0] == 'A') {
|
||||
localstr[7] = itoc(check_digit);
|
||||
localstr[8] = '\0';
|
||||
if(localstr[7] == 'A') {
|
||||
strcpy(symbol->errtxt, "Invalid PZN Data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
concat(localstr, checkstr);
|
||||
length = strlen(localstr);
|
||||
error_number = c39(symbol, (unsigned char *)localstr, length);
|
||||
error_number = c39(symbol, (unsigned char *)localstr, strlen(localstr));
|
||||
ustrcpy(symbol->text, (unsigned char *)"PZN");
|
||||
uconcat(symbol->text, (unsigned char *)localstr);
|
||||
return error_number;
|
||||
@ -325,11 +311,10 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length
|
||||
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 char buffer[150] = { 0 };
|
||||
unsigned int i;
|
||||
int error_number;
|
||||
|
||||
memset(buffer,0,150);
|
||||
error_number = 0;
|
||||
|
||||
if(length > 74) {
|
||||
@ -337,31 +322,23 @@ int ec39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
|
||||
/* Creates a buffer string and places control characters into it */
|
||||
for(i = 0; i < length; i++) {
|
||||
if(source[i] > 127) {
|
||||
/* Cannot encode extended ASCII */
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
/* Creates a buffer string and places control characters into it */
|
||||
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, ustrlen(buffer));
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
if(source[i] == '\0') {
|
||||
symbol->text[i] = ' ';
|
||||
} else {
|
||||
symbol->text[i] = source[i];
|
||||
}
|
||||
}
|
||||
for(i = 0; i < length; i++)
|
||||
symbol->text[i] = source[i] ? source[i] : ' ';
|
||||
symbol->text[length] = '\0';
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
@ -370,119 +347,89 @@ int ec39(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
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
|
||||
/* SILVER includes the extra characters a, b, c and d to represent Code 93 specific
|
||||
shift characters 1, 2, 3 and 4 respectively. These characters are never used by
|
||||
c39() and ec39() */
|
||||
|
||||
unsigned int i;
|
||||
int h, weight, c, k, values[100], error_number;
|
||||
char buffer[220], temp[2];
|
||||
char set_copy[] = TCSET;
|
||||
int i;
|
||||
int h, weight, c, k, values[128], error_number;
|
||||
char buffer[220];
|
||||
char dest[670];
|
||||
unsigned char local_source[110];
|
||||
char set_copy[] = SILVER;
|
||||
|
||||
error_number = 0;
|
||||
strcpy(buffer, "");
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 107) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
local_source[i] = source[i];
|
||||
}
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
if(local_source[i] > 127) {
|
||||
/* Message Content */
|
||||
for (i = 0; i < length; i++) {
|
||||
if (source[i] > 127) {
|
||||
/* Cannot encode extended ASCII */
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start character */
|
||||
concat(dest, "111141");
|
||||
|
||||
/* Message Content */
|
||||
for(i = 0; i < length; i++) {
|
||||
concat(buffer, C93Ctrl[local_source[i]]);
|
||||
concat(buffer, C93Ctrl[source[i]]);
|
||||
symbol->text[i] = source[i] ? source[i] : ' ';
|
||||
}
|
||||
|
||||
/* Now we can check the true length of the barcode */
|
||||
if(strlen(buffer) > 107) {
|
||||
h = strlen(buffer);
|
||||
if (h > 107) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
for(i = 0; i < strlen(buffer); i++) {
|
||||
values[i] = posn(TCSET, buffer[i]);
|
||||
for (i = 0; i < h; i++) {
|
||||
values[i] = posn(SILVER, buffer[i]);
|
||||
}
|
||||
|
||||
/* Putting the data into dest[] is not done until after check digits are calculated */
|
||||
|
||||
/* Check digit C */
|
||||
|
||||
c = 0;
|
||||
weight = 1;
|
||||
for(h = strlen(buffer) - 1; h >= 0; h--)
|
||||
{
|
||||
c += values[h] * weight;
|
||||
weight ++;
|
||||
if(weight == 21)
|
||||
{
|
||||
for (i = h - 1; i >= 0; i--) {
|
||||
c += values[i] * weight;
|
||||
weight++;
|
||||
if (weight == 21)
|
||||
weight = 1;
|
||||
}
|
||||
}
|
||||
c = c % 47;
|
||||
|
||||
/* Because concat() requires a string as its second argument the check digit is converted
|
||||
to a character which is then put in temp[] before being added to buffer[] - its
|
||||
a bit long winded but avoids putting yet another function into common.c */
|
||||
|
||||
values[strlen(buffer)] = c;
|
||||
temp[0] = set_copy[c];
|
||||
temp[1] = '\0';
|
||||
concat(buffer, temp);
|
||||
values[h] = c;
|
||||
buffer[h] = set_copy[c];
|
||||
|
||||
/* Check digit K */
|
||||
k = 0;
|
||||
weight = 1;
|
||||
for(h = strlen(buffer) - 1; h >= 0; h--)
|
||||
{
|
||||
k += values[h] * weight;
|
||||
weight ++;
|
||||
for (i = h; i >= 0; i--) {
|
||||
k += values[i] * weight;
|
||||
weight++;
|
||||
if(weight == 16)
|
||||
{
|
||||
weight = 1;
|
||||
}
|
||||
}
|
||||
k = k % 47;
|
||||
temp[0] = set_copy[k];
|
||||
temp[1] = '\0';
|
||||
concat(buffer, temp);
|
||||
buffer[++h] = set_copy[k];
|
||||
buffer[++h] = '\0';
|
||||
|
||||
for(i = 0; i < strlen(buffer); i++) {
|
||||
lookup(TCSET, C93Table, buffer[i], dest);
|
||||
/* Start character */
|
||||
strcpy(dest, "111141");
|
||||
|
||||
for(i = 0; i < h; i++) {
|
||||
lookup(SILVER, C93Table, buffer[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
concat(dest, "1111411");
|
||||
|
||||
local_source[length] = set_copy[c];
|
||||
local_source[length + 1] = set_copy[k];
|
||||
local_source[length + 2] = '\0';
|
||||
length += 2;
|
||||
expand(symbol, dest);
|
||||
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';
|
||||
|
||||
symbol->text[length] = set_copy[c];
|
||||
symbol->text[length + 1] = set_copy[k];
|
||||
symbol->text[length + 2] = '\0';
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
@ -550,7 +497,7 @@ int channel_code(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
@ -584,12 +531,9 @@ int channel_code(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
value = 0;
|
||||
NextS(channels,3,channels,channels);
|
||||
|
||||
strcpy(hrt, "");
|
||||
zeroes = channels - 1 - length;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
concat(hrt, "0");
|
||||
}
|
||||
concat(hrt, (char *)source);
|
||||
memset(hrt, '0', zeroes);
|
||||
strcpy(hrt + zeroes, (char *)source);
|
||||
ustrcpy(symbol->text, (unsigned char *)hrt);
|
||||
|
||||
expand(symbol, pattern);
|
||||
|
@ -1027,20 +1027,20 @@ int code_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int stream[30];
|
||||
int block_width;
|
||||
|
||||
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(length > 18) {
|
||||
strcpy(symbol->errtxt, "Input data too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
if(is_sane(NEON, source, length) == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid input data (Version S encodes numeric input only)");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
sub_version = 3; codewords = 12; block_width = 6; /* Version S-30 */
|
||||
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);
|
||||
binary_load(elreg, (char *)source, length);
|
||||
hex_dump(elreg);
|
||||
|
||||
for(i = 0; i < 15; i++) {
|
||||
|
@ -67,12 +67,12 @@ int parunmodd(unsigned char llyth)
|
||||
modd = 0;
|
||||
|
||||
if(llyth <= 31) { modd = SHIFTA; }
|
||||
if((llyth >= 32) && (llyth <= 95)) { modd = AORB; }
|
||||
if((llyth >= 48) && (llyth <= 57)) { modd = ABORC; }
|
||||
if((llyth >= 96) && (llyth <= 127)) { modd = SHIFTB; }
|
||||
if((llyth >= 128) && (llyth <= 159)) { modd = SHIFTA; }
|
||||
if((llyth >= 160) && (llyth <= 223)) { modd = AORB; }
|
||||
if(llyth >= 224) { modd = SHIFTB; }
|
||||
else if((llyth >= 48) && (llyth <= 57)) { modd = ABORC; }
|
||||
else if(llyth <= 95) { modd = AORB; }
|
||||
else if(llyth <= 127) { modd = SHIFTB; }
|
||||
else if(llyth <= 159) { modd = SHIFTA; }
|
||||
else if(llyth <= 223) { modd = AORB; }
|
||||
else { modd = SHIFTB; }
|
||||
|
||||
return modd;
|
||||
}
|
||||
@ -191,9 +191,9 @@ void c128_set_c(unsigned char source_a, unsigned char source_b, char dest[], int
|
||||
|
||||
int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Handle Code 128 and NVE-18 */
|
||||
int i, j, k, e_count, values[170], bar_characters, read, total_sum, nve_check;
|
||||
int i, j, k, e_count, values[170] = { 0 }, bar_characters, read, total_sum, nve_check;
|
||||
int error_number, indexchaine, indexliste, sourcelen, f_state;
|
||||
char set[170], fset[170], mode, last_set, last_fset, current_set = ' ';
|
||||
char set[170] = { ' ' }, fset[170] = { ' ' }, mode, last_set, last_fset, current_set = ' ';
|
||||
float glyph_count;
|
||||
char dest[1000];
|
||||
|
||||
@ -208,12 +208,6 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
nve_check = 0;
|
||||
f_state = 0;
|
||||
|
||||
for(i = 0; i < 170; i++) {
|
||||
values[i] = 0;
|
||||
set[i] = ' ';
|
||||
fset[i] = ' ';
|
||||
}
|
||||
|
||||
if(sourcelen > 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 */
|
||||
@ -223,11 +217,8 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Detect extended ASCII characters */
|
||||
for(i = 0; i < sourcelen; i++) {
|
||||
if(source[i] >= 128) {
|
||||
if(source[i] >= 128)
|
||||
fset[i] = 'f';
|
||||
} else {
|
||||
fset[i] = ' ';
|
||||
}
|
||||
}
|
||||
fset[i] = '\0';
|
||||
|
||||
@ -254,7 +245,6 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Decide if it is worth reverting to 646 encodation for a few characters as described in 4.3.4.2 (d) */
|
||||
if(sourcelen > 1) {
|
||||
for(i = 1; i < sourcelen; i++) {
|
||||
if((fset[i - 1] == 'F') && (fset[i] == ' ')) {
|
||||
/* Detected a change from 8859-1 to 646 - count how long for */
|
||||
@ -268,7 +258,6 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */
|
||||
indexliste = 0;
|
||||
@ -564,12 +553,9 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Stop character */
|
||||
concat(dest, C128Table[106]);
|
||||
expand(symbol, dest);
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
if(source[i] == '\0') {
|
||||
symbol->text[i] = ' ';
|
||||
} else {
|
||||
symbol->text[i] = source[i];
|
||||
}
|
||||
symbol->text[i] = source[i] ? source[i] : ' ';
|
||||
}
|
||||
symbol->text[length] = '\0';
|
||||
return error_number;
|
||||
@ -584,9 +570,9 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
char dest[1000];
|
||||
int separator_row, linkage_flag, c_count;
|
||||
#ifndef _MSC_VER
|
||||
char reduced[length];
|
||||
char reduced[length + 1];
|
||||
#else
|
||||
char* reduced = (char*)_alloca(length);
|
||||
char* reduced = (char*)_alloca(length + 1);
|
||||
#endif
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
@ -597,10 +583,8 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
bar_characters = 0;
|
||||
separator_row = 0;
|
||||
|
||||
for(i = 0; i < 170; i++) {
|
||||
values[i] = 0;
|
||||
set[i] = ' ';
|
||||
}
|
||||
memset(values, 0, sizeof(values));
|
||||
memset(set, ' ', sizeof(set));
|
||||
|
||||
if(length > 160) {
|
||||
/* This only blocks rediculously long input - the actual length of the
|
||||
@ -625,7 +609,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
if(symbol->input_mode != GS1_MODE) {
|
||||
/* GS1 data has not been checked yet */
|
||||
error_number = gs1_verify(symbol, source, reduced);
|
||||
error_number = gs1_verify(symbol, source, length, reduced);
|
||||
if(error_number != 0) { return error_number; }
|
||||
}
|
||||
|
||||
@ -884,7 +868,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i <= length; i++) {
|
||||
for(i = 0; i < length; i++) {
|
||||
if((source[i] != '[') && (source[i] != ']')) {
|
||||
symbol->text[i] = source[i];
|
||||
}
|
||||
@ -902,7 +886,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
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;
|
||||
int error_number, zeroes, i, nve_check, total_sum, sourcelen;
|
||||
unsigned char ean128_equiv[25];
|
||||
|
||||
memset(ean128_equiv, 0, 25);
|
||||
@ -913,20 +897,15 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
concat((char *)ean128_equiv, "[00]");
|
||||
zeroes = 17 - sourcelen;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
j = ustrlen(ean128_equiv);
|
||||
ean128_equiv[j] = '0';
|
||||
ean128_equiv[j + 1] = '\0';
|
||||
}
|
||||
concat((char*)ean128_equiv, (char*)source);
|
||||
strcpy((char *)ean128_equiv, "[00]");
|
||||
memset(ean128_equiv + 4, '0', zeroes);
|
||||
strcpy((char*)ean128_equiv + 4 + zeroes, (char*)source);
|
||||
|
||||
total_sum = 0;
|
||||
for(i = sourcelen - 1; i >= 0; i--)
|
||||
@ -937,7 +916,7 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
total_sum += 2 * ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
nve_check = 10 - total_sum%10;
|
||||
nve_check = 10 - total_sum % 10;
|
||||
if(nve_check == 10) { nve_check = 0; }
|
||||
ean128_equiv[21] = itoc(nve_check);
|
||||
ean128_equiv[22] = '\0';
|
||||
@ -950,43 +929,37 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int ean_14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
/* EAN-14 - A version of EAN-128 */
|
||||
int i, j, count, check_digit;
|
||||
int i, count, check_digit;
|
||||
int error_number, zeroes;
|
||||
unsigned char ean128_equiv[20];
|
||||
|
||||
memset(ean128_equiv, 0, 20);
|
||||
|
||||
if(length > 13) {
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, 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 - length;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
j = ustrlen(ean128_equiv);
|
||||
ean128_equiv[j] = '0';
|
||||
ean128_equiv[j + 1] = '\0';
|
||||
}
|
||||
concat((char*)ean128_equiv, (char*)source);
|
||||
strcpy((char*)ean128_equiv, "[01]");
|
||||
memset(ean128_equiv + 4, '0', zeroes);
|
||||
ustrcpy(ean128_equiv + 4 + zeroes, source);
|
||||
|
||||
count = 0;
|
||||
for (i = length - 1; i >= 0; i--)
|
||||
{
|
||||
count += ctoi(source[i]);
|
||||
|
||||
if (!((i%2) == 1))
|
||||
if (!((i % 2) == 1))
|
||||
{
|
||||
count += 2 * ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
check_digit = 10 - (count%10);
|
||||
check_digit = 10 - (count % 10);
|
||||
if (check_digit == 10) { check_digit = 0; }
|
||||
ean128_equiv[17] = itoc(check_digit);
|
||||
ean128_equiv[18] = '\0';
|
||||
|
@ -65,8 +65,6 @@ 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);
|
||||
|
||||
void grwp16(int *indexliste)
|
||||
{
|
||||
int i, j;
|
||||
@ -172,9 +170,9 @@ 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;
|
||||
int indexliste, indexchaine, pads_needed, f_state;
|
||||
char set[160], fset[160], mode, last_set, last_fset, current_set;
|
||||
char set[160] = { ' ' }, fset[160] = { ' ' }, mode, last_set, last_fset, current_set;
|
||||
unsigned int i, j, k, m, e_count, read, mx_reader, writer;
|
||||
unsigned int values[160];
|
||||
unsigned int values[160] = { 0 };
|
||||
unsigned int bar_characters;
|
||||
float glyph_count;
|
||||
int errornum, first_sum, second_sum;
|
||||
@ -195,12 +193,6 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
e_count = 0;
|
||||
bar_characters = 0;
|
||||
|
||||
for(i = 0; i < 160; i++) {
|
||||
values[i] = 0;
|
||||
set[i] = ' ';
|
||||
fset[i] = ' ';
|
||||
}
|
||||
|
||||
/* Detect extended ASCII characters */
|
||||
for(i = 0; i < input_length; i++) {
|
||||
if(source[i] >=128) {
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
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;
|
||||
int i, j, rows, M, x_count, y_count, z_count, posn_val, local_value, h;
|
||||
char intermediate[170];
|
||||
int codewords[170], codeword_count;
|
||||
int c_grid[8][8]; /* Refers to table 3 */
|
||||
@ -45,25 +45,21 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }
|
||||
|
||||
strcpy(intermediate, "");
|
||||
strcpy(intermediate, gs1 ? "*" : ""); /* FNC1 */
|
||||
for(i = 0; i < length; i++) {
|
||||
if(source[i] > 127) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
if(gs1 && (i == 0)) {
|
||||
if(gs1 && (source[i] == '['))
|
||||
concat(intermediate, "*"); /* FNC1 */
|
||||
}
|
||||
|
||||
if(gs1 && (source[i] == '[')) {
|
||||
concat(intermediate, "*"); /* FNC1 */
|
||||
} else {
|
||||
else
|
||||
concat(intermediate, c49_table7[source[i]]);
|
||||
}
|
||||
}
|
||||
|
||||
codeword_count = 0;
|
||||
i = 0;
|
||||
h = strlen(intermediate);
|
||||
do {
|
||||
if((intermediate[i] >= '0') && (intermediate[i] <= '9')) {
|
||||
/* Numeric data */
|
||||
@ -166,7 +162,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
i += 4;
|
||||
break;
|
||||
}
|
||||
if(i < strlen(intermediate)) {
|
||||
if(i < h) {
|
||||
/* There is more to add */
|
||||
codewords[codeword_count] = 48; /* Numeric Shift */
|
||||
codeword_count++;
|
||||
@ -181,7 +177,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
codeword_count++;
|
||||
i++;
|
||||
}
|
||||
} while(i < strlen(intermediate));
|
||||
} while(i < h);
|
||||
|
||||
switch(codewords[0]) { /* Set starting mode value */
|
||||
case 48: M = 2;
|
||||
|
124
backend/common.c
124
backend/common.c
@ -23,8 +23,6 @@
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
|
||||
#define SSET "0123456789ABCDEF"
|
||||
|
||||
const int ustrlen(unsigned char data[]) {
|
||||
/* Local replacement for strlen() with unsigned char strings */
|
||||
int i;
|
||||
@ -46,10 +44,11 @@ void ustrcpy(unsigned char target[], unsigned char source[]) {
|
||||
|
||||
void concat(char dest[], char source[])
|
||||
{ /* Concatinates dest[] with the contents of source[], copying /0 as well */
|
||||
unsigned int i, j;
|
||||
unsigned int i, j, n;
|
||||
|
||||
j = strlen(dest);
|
||||
for(i = 0; i <= strlen(source); i++) {
|
||||
n = strlen(source);
|
||||
for(i = 0; i <= n; i++) {
|
||||
dest[i + j] = source[i]; }
|
||||
}
|
||||
|
||||
@ -80,9 +79,9 @@ char itoc(int source)
|
||||
|
||||
void to_upper(unsigned char source[])
|
||||
{ /* Converts lower case characters to upper case in a string source[] */
|
||||
unsigned int i;
|
||||
unsigned int i, src_len = ustrlen(source);
|
||||
|
||||
for (i = 0; i < ustrlen(source); i++) {
|
||||
for (i = 0; i < src_len; i++) {
|
||||
if ((source[i] >= 'a') && (source[i] <= 'z')) {
|
||||
source [i] = (source[i] - 'a') + 'A'; }
|
||||
}
|
||||
@ -91,13 +90,19 @@ void to_upper(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;
|
||||
unsigned int lt = strlen(test_string);
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
latch = FALSE;
|
||||
for(j = 0; j < strlen(test_string); j++) {
|
||||
if (source[i] == test_string[j]) { latch = TRUE; } }
|
||||
for(j = 0; j < lt; j++) {
|
||||
if (source[i] == test_string[j]) {
|
||||
latch = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!(latch)) {
|
||||
return ERROR_INVALID_DATA; }
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -105,29 +110,25 @@ int is_sane(char test_string[], unsigned char source[], int length)
|
||||
|
||||
int posn(char set_string[], char data)
|
||||
{ /* Returns the position of data in set_string */
|
||||
unsigned int i;
|
||||
unsigned int i, n = strlen(set_string);
|
||||
|
||||
for(i = 0; i < strlen(set_string); i++) {
|
||||
for(i = 0; i < n; i++) {
|
||||
if (data == set_string[i]) { return i; } }
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lookup(char set_string[], char *table[], char data, char dest[])
|
||||
{ /* Replaces huge switch statements for looking up in tables */
|
||||
unsigned int i;
|
||||
unsigned int i, n = strlen(set_string);
|
||||
|
||||
for(i = 0; i < strlen(set_string); i++) {
|
||||
for(i = 0; i < n; i++) {
|
||||
if (data == set_string[i]) { concat(dest, table[i]); } }
|
||||
}
|
||||
|
||||
int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord)
|
||||
{
|
||||
int x_char, x_sub, result;
|
||||
|
||||
x_char = x_coord / 7;
|
||||
x_sub = x_coord % 7;
|
||||
result = 0;
|
||||
|
||||
return (symbol->encoded_data[y_coord][x_coord / 7] & (1 << (x_coord % 7))) ? 1 : 0;
|
||||
#if 0
|
||||
switch(x_sub) {
|
||||
case 0: if((symbol->encoded_data[y_coord][x_char] & 0x01) != 0) { result = 1; } break;
|
||||
case 1: if((symbol->encoded_data[y_coord][x_char] & 0x02) != 0) { result = 1; } break;
|
||||
@ -139,12 +140,15 @@ int module_is_set(struct zint_symbol *symbol, int y_coord, int x_coord)
|
||||
}
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
void set_module(struct zint_symbol *symbol, int y_coord, int x_coord)
|
||||
{
|
||||
int x_char, x_sub;
|
||||
if(module_is_set(symbol, y_coord, x_coord)) { return; }
|
||||
symbol->encoded_data[y_coord][x_coord / 7] += 1 << (x_coord % 7);
|
||||
#if 0
|
||||
int x_char, x_sub;
|
||||
|
||||
|
||||
x_char = x_coord / 7;
|
||||
@ -159,12 +163,15 @@ void set_module(struct zint_symbol *symbol, int y_coord, int x_coord)
|
||||
case 5: symbol->encoded_data[y_coord][x_char] += 0x20; break;
|
||||
case 6: symbol->encoded_data[y_coord][x_char] += 0x40; break;
|
||||
} /* The last binary digit is reserved for colour barcodes */
|
||||
#endif
|
||||
}
|
||||
|
||||
void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord)
|
||||
{
|
||||
int x_char, x_sub;
|
||||
if(!(module_is_set(symbol, y_coord, x_coord))) { return; }
|
||||
symbol->encoded_data[y_coord][x_coord / 7] -= 1 << (x_coord % 7);
|
||||
#if 0
|
||||
int x_char, x_sub;
|
||||
|
||||
x_char = x_coord / 7;
|
||||
x_sub = x_coord % 7;
|
||||
@ -178,18 +185,20 @@ void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord)
|
||||
case 5: symbol->encoded_data[y_coord][x_char] -= 0x20; break;
|
||||
case 6: symbol->encoded_data[y_coord][x_char] -= 0x40; break;
|
||||
} /* The last binary digit is reserved for colour barcodes */
|
||||
#endif
|
||||
}
|
||||
|
||||
void expand(struct zint_symbol *symbol, char data[])
|
||||
{ /* Expands from a width pattern to a bit pattern */
|
||||
|
||||
int reader, writer, i;
|
||||
unsigned int reader, n = strlen(data);
|
||||
int writer, i;
|
||||
char latch;
|
||||
|
||||
writer = 0;
|
||||
latch = '1';
|
||||
|
||||
for(reader = 0; reader < strlen(data); reader++) {
|
||||
for(reader = 0; reader < n; reader++) {
|
||||
for(i = 0; i < ctoi(data[reader]); i++) {
|
||||
if(latch == '1') { set_module(symbol, symbol->rows, writer); }
|
||||
writer++;
|
||||
@ -316,4 +325,73 @@ int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned
|
||||
return 0;
|
||||
}
|
||||
|
||||
int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length)
|
||||
{
|
||||
int bpos, jpos, error_number, done;
|
||||
int next;
|
||||
|
||||
bpos = 0;
|
||||
jpos = 0;
|
||||
error_number = 0;
|
||||
next = 0;
|
||||
|
||||
do {
|
||||
done = 0;
|
||||
|
||||
if(source[bpos] <= 0x7f) {
|
||||
/* 1 byte mode (7-bit ASCII) */
|
||||
vals[jpos] = source[bpos];
|
||||
next = bpos + 1;
|
||||
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 */
|
||||
vals[jpos] = ((source[bpos] & 0x1f) << 6) + (source[bpos + 1] & 0x3f);
|
||||
next = bpos + 2;
|
||||
jpos++;
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(done == 0) {
|
||||
if((source[bpos] >= 0xe0) && (source[bpos] <= 0xef)) {
|
||||
/* 3 byte mode */
|
||||
vals[jpos] = ((source[bpos] & 0x0f) << 12) + ((source[bpos + 1] & 0x3f) << 6) + (source[bpos + 2] & 0x3f);
|
||||
next = bpos + 3;
|
||||
jpos ++;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
#endif
|
||||
|
||||
/* The most commonly used set */
|
||||
#define NESET "0123456789"
|
||||
#define NEON "0123456789"
|
||||
|
||||
#include "zint.h"
|
||||
|
||||
@ -60,7 +60,9 @@ 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 parunmodd(unsigned char llyth);
|
||||
extern int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned char preprocessed[], int *length);
|
||||
extern int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], int *length);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
@ -52,12 +52,12 @@
|
||||
|
||||
#define UINT unsigned short
|
||||
|
||||
int general_rules(char field[], char type[]);
|
||||
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);
|
||||
extern int general_rules(char field[], char type[]);
|
||||
extern int eanx(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
extern int ean_128(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
extern int rss14(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
extern int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
extern int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
|
||||
static UINT pwr928[69][7];
|
||||
|
||||
@ -1694,14 +1694,12 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar
|
||||
|
||||
void add_leading_zeroes(struct zint_symbol *symbol)
|
||||
{
|
||||
char source[100];
|
||||
char first_part[20], second_part[20], zfirst_part[20], zsecond_part[20];
|
||||
int with_addon = 0;
|
||||
int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i;
|
||||
int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i, h, n = 0;
|
||||
|
||||
strcpy(source, symbol->primary);
|
||||
for(i = 0; i < strlen(source); i++) {
|
||||
if(source[i] == '+') {
|
||||
h = strlen(symbol->primary);
|
||||
for(i = 0; i < h; i++) {
|
||||
if(symbol->primary[i] == '+') {
|
||||
with_addon = 1;
|
||||
} else {
|
||||
if(with_addon == 0) {
|
||||
@ -1712,22 +1710,6 @@ void add_leading_zeroes(struct zint_symbol *symbol)
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(first_part, "");
|
||||
strcpy(second_part, "");
|
||||
strcpy(zfirst_part, "");
|
||||
strcpy(zsecond_part, "");
|
||||
|
||||
/* Split input into two strings */
|
||||
for(i = 0; i < first_len; i++) {
|
||||
first_part[i] = source[i];
|
||||
first_part[i + 1] = '\0';
|
||||
}
|
||||
|
||||
for(i = 0; i < second_len; i++) {
|
||||
second_part[i] = source[i + first_len + 1];
|
||||
second_part[i + 1] = '\0';
|
||||
}
|
||||
|
||||
/* Calculate target lengths */
|
||||
if(first_len <= 12) { zfirst_len = 12; }
|
||||
if(first_len <= 7) { zfirst_len = 7; }
|
||||
@ -1736,48 +1718,47 @@ void add_leading_zeroes(struct zint_symbol *symbol)
|
||||
if(second_len == 0) { zsecond_len = 0; }
|
||||
|
||||
/* Add leading zeroes */
|
||||
for(i = 0; i < (zfirst_len - first_len); i++) {
|
||||
concat(zfirst_part, "0");
|
||||
n = zfirst_len - first_len;
|
||||
if (n > 0)
|
||||
{
|
||||
memmove(symbol->primary + n, symbol->primary, h);
|
||||
memset(symbol->primary, '0', n);
|
||||
}
|
||||
concat(zfirst_part, first_part);
|
||||
for(i = 0; i < (zsecond_len - second_len); i++) {
|
||||
concat(zsecond_part, "0");
|
||||
}
|
||||
concat(zsecond_part, second_part);
|
||||
|
||||
strcpy(symbol->primary, zfirst_part);
|
||||
if(zsecond_len != 0) {
|
||||
concat(symbol->primary, "+");
|
||||
concat(symbol->primary, zsecond_part);
|
||||
n += first_len + 1;
|
||||
if (zsecond_len)
|
||||
{
|
||||
memmove(symbol->primary + n + zsecond_len, symbol->primary + n, second_len);
|
||||
memset(symbol->primary + n , '0', zsecond_len);
|
||||
n += zsecond_len + second_len;
|
||||
}
|
||||
symbol->primary[n] = '\0';
|
||||
}
|
||||
|
||||
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;
|
||||
unsigned int rs = length + 1;
|
||||
unsigned int bs = 20 * rs;
|
||||
unsigned int pri_len;
|
||||
#ifndef _MSC_VER
|
||||
char reduced[ustrlen(source)];
|
||||
char binary_string[10 * length];
|
||||
char reduced[rs];
|
||||
char binary_string[bs];
|
||||
#else
|
||||
char* reduced = (char*)_alloca(length + 1);
|
||||
char* binary_string = (char*)_alloca(20 * (length + 1));
|
||||
char* reduced = (char*)_alloca(rs);
|
||||
char* binary_string = (char*)_alloca(bs);
|
||||
#endif
|
||||
struct zint_symbol *linear;
|
||||
int top_shift, bottom_shift;
|
||||
|
||||
error_number = 0;
|
||||
separator_row = 0;
|
||||
|
||||
if(strlen(symbol->primary) == 0) {
|
||||
pri_len = strlen(symbol->primary);
|
||||
if(pri_len == 0) {
|
||||
strcpy(symbol->errtxt, "No primary (linear) message in 2D composite");
|
||||
return ERROR_INVALID_OPTION;
|
||||
}
|
||||
|
||||
if(symbol->symbology == BARCODE_EANX_CC) {
|
||||
add_leading_zeroes(symbol);
|
||||
}
|
||||
|
||||
if(length > 2990) {
|
||||
strcpy(symbol->errtxt, "2D component input data too long");
|
||||
return ERROR_TOO_LONG;
|
||||
@ -1785,7 +1766,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
linear = ZBarcode_Create(); /* Symbol contains the 2D component and Linear contains the rest */
|
||||
|
||||
error_number = gs1_verify(symbol, source, reduced);
|
||||
error_number = gs1_verify(symbol, source, length, reduced);
|
||||
if(error_number != 0) { return error_number; }
|
||||
|
||||
cc_mode = symbol->option_1;
|
||||
@ -1807,16 +1788,16 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
switch(symbol->symbology) {
|
||||
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;
|
||||
case BARCODE_EANX_CC: error_number = eanx(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_EAN128_CC: error_number = ean_128(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_RSS14_CC: error_number = rss14(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_RSS_LTD_CC: error_number = rsslimited(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_RSS_EXP_CC: error_number = rssexpanded(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_UPCA_CC: error_number = eanx(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_UPCE_CC: error_number = eanx(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_RSS14STACK_CC: error_number = rss14(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_RSS14_OMNI_CC: error_number = rss14(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
case BARCODE_RSS_EXPSTACK_CC: error_number = rssexpanded(linear, (unsigned char *)symbol->primary, pri_len); break;
|
||||
}
|
||||
|
||||
if(error_number != 0) {
|
||||
@ -1828,7 +1809,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
switch(symbol->symbology) {
|
||||
/* Determine width of 2D component according to ISO/IEC 24723 Table 1 */
|
||||
case BARCODE_EANX_CC:
|
||||
switch(strlen(symbol->primary)) {
|
||||
switch(pri_len) {
|
||||
case 7: /* EAN-8 */
|
||||
case 10: /* EAN-8 + 2 */
|
||||
case 13: /* EAN-8 + 5 */
|
||||
@ -1852,7 +1833,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
case BARCODE_RSS_EXPSTACK_CC: cc_width = 4; break;
|
||||
}
|
||||
|
||||
memset(binary_string, 0, sizeof(binary_string));
|
||||
memset(binary_string, 0, bs);
|
||||
|
||||
if(cc_mode < 1 || cc_mode > 3) { cc_mode = 1; }
|
||||
|
||||
@ -1900,7 +1881,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
switch(symbol->symbology) {
|
||||
/* Determine horizontal alignment (according to section 12.3) */
|
||||
case BARCODE_EANX_CC:
|
||||
switch(strlen(symbol->primary)) {
|
||||
switch(pri_len) {
|
||||
case 7: /* EAN-8 */
|
||||
case 10: /* EAN-8 + 2 */
|
||||
case 13: /* EAN-8 + 5 */
|
||||
@ -1967,10 +1948,6 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
symbol->rows += linear->rows;
|
||||
ustrcpy(symbol->text, (unsigned char *)linear->text);
|
||||
|
||||
//#ifdef _MSC_VER
|
||||
// free(reduced);
|
||||
// free(binary_string);
|
||||
//#endif
|
||||
ZBarcode_Delete(linear);
|
||||
|
||||
return error_number;
|
||||
|
@ -344,6 +344,7 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha
|
||||
#else
|
||||
char* binary = (char*)_alloca(2 * inputlen);
|
||||
#endif
|
||||
|
||||
sp = 0;
|
||||
tp = 0;
|
||||
memset(c40_buffer, 0, 6);
|
||||
@ -772,26 +773,6 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng
|
||||
unsigned char *grid = 0;
|
||||
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);
|
||||
|
||||
if(binlen == 0) {
|
||||
|
@ -26,16 +26,16 @@
|
||||
#endif
|
||||
#include "dmatrix.h"
|
||||
#include "common.h"
|
||||
#ifdef _MSC_VER
|
||||
#ifdef __cplusplus
|
||||
#include "dm200.h"
|
||||
#else
|
||||
extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
#endif
|
||||
|
||||
#define B11SET " 0123456789"
|
||||
#define B27SET " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
#define B37SET " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
#define B41SET " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-/"
|
||||
#define SODIUM " 0123456789"
|
||||
#define COBALT " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
#define RUBIDIUM " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
#define NIOBIUM " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-/"
|
||||
|
||||
void crc_machine(char data_prefix_bitstream[], int scheme, unsigned char source[], int length)
|
||||
{
|
||||
@ -43,10 +43,6 @@ void crc_machine(char data_prefix_bitstream[], int scheme, unsigned char source[
|
||||
char xor_register[17];
|
||||
int machine_cycles;
|
||||
char input_bit, out1, out2, out3;
|
||||
#ifdef _MSC_VER
|
||||
char* precrc_bitstream;
|
||||
char* precrc_bitstream_reversed;
|
||||
#endif
|
||||
|
||||
input_length = length;
|
||||
|
||||
@ -54,8 +50,8 @@ void crc_machine(char data_prefix_bitstream[], int scheme, unsigned char source[
|
||||
char precrc_bitstream[(input_length * 8) + 18];
|
||||
char precrc_bitstream_reversed[(input_length * 8) + 18];
|
||||
#else
|
||||
precrc_bitstream = (char*)_alloca((input_length * 8) + 18);
|
||||
precrc_bitstream_reversed = (char*)_alloca((input_length * 8) + 18);
|
||||
char* precrc_bitstream = (char*)_alloca((input_length * 8) + 18);
|
||||
char* precrc_bitstream_reversed = (char*)_alloca((input_length * 8) + 18);
|
||||
#endif
|
||||
|
||||
switch(scheme) {
|
||||
@ -155,7 +151,7 @@ void i1_base11(char binary_string[], unsigned char source[], int length)
|
||||
block_value = 0;
|
||||
binary_posn = strlen(binary_string);
|
||||
for(j = 0; j < 6; j++) {
|
||||
c[j] = posn(B11SET, source[(i * 6) + j]);
|
||||
c[j] = posn(SODIUM, source[(i * 6) + j]);
|
||||
c[j] *= weight[j];
|
||||
block_value += c[j];
|
||||
}
|
||||
@ -193,7 +189,7 @@ void i1_base11(char binary_string[], unsigned char source[], int length)
|
||||
block_value = 0;
|
||||
binary_posn = strlen(binary_string);
|
||||
for(j = 0; j < remainder; j++) {
|
||||
c[j] = posn(B11SET, source[(i * 6) + j]);
|
||||
c[j] = posn(SODIUM, source[(i * 6) + j]);
|
||||
c[j] *= weight[j];
|
||||
block_value += c[j];
|
||||
}
|
||||
@ -257,7 +253,7 @@ void i2_base27(char binary_string[], unsigned char source[], int length)
|
||||
strcpy(block_binary, "");
|
||||
block_value = 0;
|
||||
for(j = 0; j < 5; j++) {
|
||||
c[j] = posn(B27SET, source[(i * 5) + j]);
|
||||
c[j] = posn(COBALT, source[(i * 5) + j]);
|
||||
c[j] *= weight[j];
|
||||
block_value += c[j];
|
||||
}
|
||||
@ -297,7 +293,7 @@ void i2_base27(char binary_string[], unsigned char source[], int length)
|
||||
strcpy(block_binary, "");
|
||||
block_value = 0;
|
||||
for(j = 0; j < remainder; j++) {
|
||||
c[j] = posn(B27SET, source[(i * 5) + j]);
|
||||
c[j] = posn(COBALT, source[(i * 5) + j]);
|
||||
c[j] *= weight[j];
|
||||
block_value += c[j];
|
||||
}
|
||||
@ -361,7 +357,7 @@ void i3_base37(char binary_string[], unsigned char source[], int length)
|
||||
strcpy(block_binary, "");
|
||||
block_value = 0;
|
||||
for(j = 0; j < 4; j++) {
|
||||
c[j] = posn(B37SET, source[(i * 4) + j]);
|
||||
c[j] = posn(RUBIDIUM, source[(i * 4) + j]);
|
||||
c[j] *= weight[j];
|
||||
block_value += c[j];
|
||||
}
|
||||
@ -398,7 +394,7 @@ void i3_base37(char binary_string[], unsigned char source[], int length)
|
||||
strcpy(block_binary, "");
|
||||
block_value = 0;
|
||||
for(j = 0; j < remainder; j++) {
|
||||
c[j] = posn(B37SET, source[(i * 4) + j]);
|
||||
c[j] = posn(RUBIDIUM, source[(i * 4) + j]);
|
||||
c[j] *= weight[j];
|
||||
block_value += c[j];
|
||||
}
|
||||
@ -457,7 +453,7 @@ void i4_base41(char binary_string[], unsigned char source[], int length)
|
||||
strcpy(block_binary, "");
|
||||
block_value = 0;
|
||||
for(j = 0; j < 4; j++) {
|
||||
c[j] = posn(B41SET, source[(i * 4) + j]);
|
||||
c[j] = posn(NIOBIUM, source[(i * 4) + j]);
|
||||
c[j] *= weight[j];
|
||||
block_value += c[j];
|
||||
}
|
||||
@ -495,7 +491,7 @@ void i4_base41(char binary_string[], unsigned char source[], int length)
|
||||
strcpy(block_binary, "");
|
||||
block_value = 0;
|
||||
for(j = 0; j < remainder; j++) {
|
||||
c[j] = posn(B41SET, source[(i * 4) + j]);
|
||||
c[j] = posn(NIOBIUM, source[(i * 4) + j]);
|
||||
c[j] *= weight[j];
|
||||
block_value += c[j];
|
||||
}
|
||||
@ -1104,10 +1100,10 @@ int matrix89(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Decide which encoding scheme to use */
|
||||
scheme = 128;
|
||||
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; }
|
||||
if(!(is_sane(NIOBIUM, source, length))) { scheme = 41; }
|
||||
if(!(is_sane(RUBIDIUM, source, length))) { scheme = 37; }
|
||||
if(!(is_sane(COBALT, source, length))) { scheme = 27; }
|
||||
if(!(is_sane(SODIUM, source, length))) { scheme = 11; }
|
||||
|
||||
/* Data Prefix Bit Stream = Format ID + CRC + Data Length */
|
||||
|
||||
|
7468
backend/gb2312.h
Normal file
7468
backend/gb2312.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -31,7 +31,7 @@
|
||||
#include "reedsol.h"
|
||||
#include "gridmtx.h"
|
||||
|
||||
int grid_matrix(struct zint_symbol *symbol, unsigned char source[])
|
||||
int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
|
||||
strcpy(symbol->errtxt, "Grid Matrix not yet implemented");
|
||||
|
@ -53,7 +53,7 @@ void itostr(char ai_string[], int ai_value)
|
||||
concat(ai_string, ")");
|
||||
}
|
||||
|
||||
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[])
|
||||
int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[])
|
||||
{
|
||||
int i, j, last_ai, ai_latch;
|
||||
char ai_string[6];
|
||||
@ -62,7 +62,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[
|
||||
int error_latch;
|
||||
|
||||
/* Detect extended ASCII characters */
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if(source[i] >=128) {
|
||||
strcpy(symbol->errtxt, "Extended ASCII characters are not supported by GS1");
|
||||
return ERROR_INVALID_DATA;
|
||||
@ -86,7 +86,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[
|
||||
min_ai_length = 5;
|
||||
j = 0;
|
||||
ai_latch = 0;
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
for(i = 0; i < src_len; i++) {
|
||||
ai_length += j;
|
||||
if(((j == 1) && (source[i] != ']')) && ((source[i] < '0') || (source[i] > '9'))) { ai_latch = 1; }
|
||||
if(source[i] == '[') { bracket_level++; j = 1; }
|
||||
@ -94,7 +94,8 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[
|
||||
bracket_level--;
|
||||
if(ai_length < min_ai_length) { min_ai_length = ai_length; }
|
||||
j = 0;
|
||||
ai_length = 0; }
|
||||
ai_length = 0;
|
||||
}
|
||||
if(bracket_level > max_bracket_level) { max_bracket_level = bracket_level; }
|
||||
if(ai_length > max_ai_length) { max_ai_length = ai_length; }
|
||||
}
|
||||
@ -131,7 +132,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[
|
||||
}
|
||||
|
||||
ai_count = 0;
|
||||
for(i = 1; i < ustrlen(source); i++) {
|
||||
for(i = 1; i < src_len; i++) {
|
||||
if(source[i - 1] == '[') {
|
||||
ai_location[ai_count] = i;
|
||||
j = 0;
|
||||
@ -226,16 +227,14 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[
|
||||
j = 0;
|
||||
last_ai = 0;
|
||||
ai_latch = 1;
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if((source[i] != '[') && (source[i] != ']')) {
|
||||
reduced[j] = source[i];
|
||||
j++;
|
||||
reduced[j++] = source[i];
|
||||
}
|
||||
if(source[i] == '[') {
|
||||
/* Start of an AI string */
|
||||
if(ai_latch == 0) {
|
||||
reduced[j] = '[';
|
||||
j++;
|
||||
reduced[j++] = '[';
|
||||
}
|
||||
ai_string[0] = source[i + 1];
|
||||
ai_string[1] = source[i + 2];
|
||||
@ -258,22 +257,23 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], unsigned char reduced[])
|
||||
int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[])
|
||||
{
|
||||
/* Only to keep the compiler happy */
|
||||
#ifndef _MSC_VER
|
||||
char temp[ustrlen(source) + 5];
|
||||
char temp[src_len + 5];
|
||||
#else
|
||||
char* temp = (char*)_alloca(ustrlen(source) + 5);
|
||||
char* temp = (char*)_alloca(src_len + 5);
|
||||
#endif
|
||||
int error_number, i;
|
||||
int error_number;
|
||||
|
||||
error_number = gs1_verify(symbol, source, temp);
|
||||
error_number = gs1_verify(symbol, source, src_len, temp);
|
||||
if(error_number != 0) { return error_number; }
|
||||
|
||||
for(i = 0; i <= strlen(temp); i++) {
|
||||
reduced[i] = (unsigned char)temp[i];
|
||||
}
|
||||
|
||||
if (strlen(temp) < src_len + 5) {
|
||||
ustrcpy(reduced, (unsigned char*)temp);
|
||||
return 0;
|
||||
}
|
||||
strcpy(symbol->errtxt, "ugs1_verify overflow");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
@ -25,8 +25,8 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern int gs1_verify(struct zint_symbol *symbol, unsigned char source[], char reduced[]);
|
||||
extern int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], unsigned char reduced[]);
|
||||
extern int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char reduced[]);
|
||||
extern int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, unsigned char reduced[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ static short int BCD[40] = {
|
||||
#include "common.h"
|
||||
#include "large.h"
|
||||
|
||||
#define NASET "0123456789-"
|
||||
#define SODIUM "0123456789-"
|
||||
|
||||
/* The following lookup tables were generated using the code in Appendix C */
|
||||
|
||||
@ -325,7 +325,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NASET, source, length);
|
||||
error_number = is_sane(SODIUM, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
|
@ -155,16 +155,16 @@ short int islarger(short int accum[], short int reg[])
|
||||
return larger;
|
||||
}
|
||||
|
||||
void binary_load(short int reg[], char data[])
|
||||
void binary_load(short int reg[], char data[], const unsigned int src_len)
|
||||
{
|
||||
int read, i;
|
||||
short int temp[112];
|
||||
short int temp[112] = { 0 };
|
||||
|
||||
for(i = 0; i < 112; i++) {
|
||||
reg[i] = 0;
|
||||
}
|
||||
|
||||
for(read = 0; read < strlen(data); read++) {
|
||||
for(read = 0; read < src_len; read++) {
|
||||
|
||||
for(i = 0; i < 112; i++) {
|
||||
temp[i] = reg[i];
|
||||
|
@ -25,7 +25,7 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern void binary_load(short int reg[], char data[]);
|
||||
extern void binary_load(short int reg[], char data[], const unsigned int src_len);
|
||||
extern void binary_add(short int accumulator[], short int input_buffer[]);
|
||||
extern void binary_subtract(short int accumulator[], short int input_buffer[]);
|
||||
extern void shiftdown(short int buffer[]);
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "common.h"
|
||||
#include "gs1.h"
|
||||
|
||||
#define HIBCSET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
|
||||
#define TECHNETIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
|
||||
|
||||
struct zint_symbol *ZBarcode_Create()
|
||||
{
|
||||
@ -61,7 +61,6 @@ struct zint_symbol *ZBarcode_Create()
|
||||
symbol->row_height[i] = 0;
|
||||
}
|
||||
return symbol;
|
||||
symbol->nullchar = 0x00;
|
||||
}
|
||||
|
||||
|
||||
@ -154,26 +153,14 @@ void error_tag(char error_string[], int error_number)
|
||||
int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int counter, error_number, i;
|
||||
char to_process[40], temp[3], check_digit;
|
||||
|
||||
strcpy(temp, "");
|
||||
|
||||
#ifndef _MSC_VER
|
||||
unsigned char local_source[length];
|
||||
#else
|
||||
unsigned char local_source = (unsigned char*)_alloca(length);
|
||||
#endif
|
||||
char to_process[40], temp[2], check_digit;
|
||||
|
||||
if(length > 36) {
|
||||
strcpy(symbol->errtxt, "Data too long for HIBC LIC");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
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);
|
||||
to_upper(source);
|
||||
error_number = is_sane(TECHNETIUM , source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
@ -182,7 +169,7 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(to_process, "+");
|
||||
counter = 41;
|
||||
for(i = 0; i < length; i++) {
|
||||
counter += posn(HIBCSET, local_source[i]);
|
||||
counter += posn(TECHNETIUM, source[i]);
|
||||
}
|
||||
counter = counter % 43;
|
||||
|
||||
@ -199,7 +186,7 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
case 39: check_digit = '$'; break;
|
||||
case 40: check_digit = '/'; break;
|
||||
case 41: check_digit = '+'; break;
|
||||
case 42: check_digit = 37; break;
|
||||
case 42: check_digit = '%'; break;
|
||||
default: check_digit = ' '; break; /* Keep compiler happy */
|
||||
}
|
||||
}
|
||||
@ -208,7 +195,7 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
temp[0] = check_digit;
|
||||
temp[1] = '\0';
|
||||
|
||||
concat(to_process, (char *)local_source);
|
||||
concat(to_process, (char *)source);
|
||||
concat(to_process, temp);
|
||||
length = strlen(to_process);
|
||||
|
||||
@ -272,7 +259,7 @@ int gs1_compliant(int symbology)
|
||||
case BARCODE_CODABLOCKF:
|
||||
case BARCODE_CODEONE:
|
||||
case BARCODE_CODE49:
|
||||
/* case BARCODE_QRCODE: for future expansion */
|
||||
case BARCODE_QRCODE:
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
@ -321,9 +308,7 @@ int ZBarcode_ValidID(int symbol_id)
|
||||
case BARCODE_PDF417:
|
||||
case BARCODE_PDF417TRUNC:
|
||||
case BARCODE_MAXICODE:
|
||||
#ifndef NO_QR
|
||||
case BARCODE_QRCODE:
|
||||
#endif
|
||||
case BARCODE_CODE128B:
|
||||
case BARCODE_AUSPOST:
|
||||
case BARCODE_AUSREPLY:
|
||||
@ -383,15 +368,9 @@ int extended_charset(struct zint_symbol *symbol, unsigned char *source, int leng
|
||||
{
|
||||
int error_number = 0;
|
||||
|
||||
/* These are the "elite" standards which can support multiple languages */
|
||||
/* These are the "elite" standards which can support multiple character sets */
|
||||
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;
|
||||
}
|
||||
@ -402,15 +381,12 @@ int extended_charset(struct zint_symbol *symbol, unsigned char *source, int leng
|
||||
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;
|
||||
int error_number = 0;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
unsigned char* preprocessed;
|
||||
#endif
|
||||
#ifndef _MSC_VER
|
||||
unsigned char preprocessed[length];
|
||||
unsigned char preprocessed[length + 1];
|
||||
#else
|
||||
preprocessed = (unsigned char*)_alloca(length + 1);
|
||||
unsigned char* preprocessed = (unsigned char*)_alloca(length + 1);
|
||||
#endif
|
||||
|
||||
if(symbol->symbology == BARCODE_CODE16K) {
|
||||
@ -427,9 +403,8 @@ int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int lengt
|
||||
|
||||
switch(symbol->input_mode) {
|
||||
case DATA_MODE:
|
||||
for(i = 0; i < length; i++) {
|
||||
preprocessed[i] = source[i];
|
||||
}
|
||||
case GS1_MODE:
|
||||
memcpy(preprocessed, source, length);
|
||||
preprocessed[length] = '\0';
|
||||
break;
|
||||
case UNICODE_MODE:
|
||||
@ -513,10 +488,12 @@ int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int lengt
|
||||
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);
|
||||
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_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;
|
||||
}
|
||||
|
||||
return error_number;
|
||||
@ -527,20 +504,20 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
|
||||
int error_number, error_buffer, i;
|
||||
error_number = 0;
|
||||
|
||||
if(ustrlen(source) == 0) {
|
||||
if(length == 0) {
|
||||
length = ustrlen(source);
|
||||
}
|
||||
if(length == 0) {
|
||||
strcpy(symbol->errtxt, "No input data");
|
||||
error_tag(symbol->errtxt, ERROR_INVALID_DATA);
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(length == 0) {
|
||||
length = ustrlen(source);
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
unsigned char local_source[length];
|
||||
unsigned char local_source[length + 1];
|
||||
#else
|
||||
unsigned char local_source = (unsigned char*)_alloca(length);
|
||||
unsigned char* local_source = (unsigned char*)_alloca(length + 1);
|
||||
#endif
|
||||
|
||||
/* First check the symbology field */
|
||||
@ -598,27 +575,20 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt
|
||||
}
|
||||
}
|
||||
if(gs1_compliant(symbol->symbology) == 1) {
|
||||
error_number = ugs1_verify(symbol, source, local_source);
|
||||
error_number = ugs1_verify(symbol, source, length, local_source);
|
||||
if(error_number != 0) { return error_number; }
|
||||
length = ustrlen(local_source);
|
||||
} 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];
|
||||
}
|
||||
memcpy(local_source, source, length);
|
||||
local_source[length] = '\0';
|
||||
}
|
||||
|
||||
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);
|
||||
@ -718,7 +688,6 @@ int ZBarcode_Encode_and_Print_Rotated(struct zint_symbol *symbol, unsigned char
|
||||
int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename)
|
||||
{
|
||||
FILE *file;
|
||||
unsigned char *buffer;
|
||||
unsigned long fileLen, result;
|
||||
|
||||
file = fopen(filename, "rb");
|
||||
@ -740,15 +709,14 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename)
|
||||
}
|
||||
|
||||
/* Allocate memory */
|
||||
buffer = (unsigned char *)malloc((fileLen + 1)*sizeof(unsigned char));
|
||||
if(!buffer) {
|
||||
strcpy(symbol->errtxt, "Internal memory error");
|
||||
fclose(file);
|
||||
return ERROR_MEMORY;
|
||||
}
|
||||
#ifndef _MSC_VER
|
||||
unsigned char buffer[fileLen + 1];
|
||||
#else
|
||||
unsigned char buffer = (unsigned char *)_alloca(fileLen + 1);
|
||||
#endif
|
||||
|
||||
/* Read file contents into buffer */
|
||||
result = fread(buffer, fileLen, 1, file);
|
||||
result = fread(&buffer, fileLen, 1, file);
|
||||
if(result != fileLen) {
|
||||
strcpy(symbol->errtxt, "File read error");
|
||||
fclose(file);
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "reedsol.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
|
||||
int maxi_codeword[144];
|
||||
|
||||
@ -299,7 +300,7 @@ int maxi_text_process(int mode, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
|
||||
for(i = ustrlen(source); i < 144; i++) {
|
||||
for(i = length; i < 144; i++) {
|
||||
/* Add the padding */
|
||||
if(set[length - 1] == 2) {
|
||||
set[i] = 2;
|
||||
@ -493,7 +494,7 @@ void maxi_do_primary_2(char postcode[], int country, int service)
|
||||
int postcode_length, postcode_num, i;
|
||||
|
||||
for(i = 0; i < 10; i++) {
|
||||
if((postcode[i] <= '0') || (postcode[i] >= '9')) {
|
||||
if((postcode[i] < '0') || (postcode[i] > '9')) {
|
||||
postcode[i] = '\0';
|
||||
}
|
||||
}
|
||||
@ -516,13 +517,14 @@ void maxi_do_primary_2(char postcode[], int country, int service)
|
||||
void maxi_do_primary_3(char postcode[], int country, int service)
|
||||
{
|
||||
/* Format structured primary for Mode 3 */
|
||||
int i;
|
||||
int i, h;
|
||||
|
||||
h = strlen(postcode);
|
||||
to_upper((unsigned char*)postcode);
|
||||
for(i = 0; i < strlen(postcode); i++) {
|
||||
if((postcode[i] >= 65) && (postcode[i] <= 90)) {
|
||||
for(i = 0; i < h; i++) {
|
||||
if((postcode[i] >= 'A') && (postcode[i] <= 'Z')) {
|
||||
/* (Capital) letters shifted to Code Set A values */
|
||||
postcode[i] = postcode[i] - 64;
|
||||
postcode[i] -= 64;
|
||||
}
|
||||
if(((postcode[i] == 27) || (postcode[i] == 31)) || ((postcode[i] == 33) || (postcode[i] >= 59))) {
|
||||
/* Not a valid postcode character */
|
||||
@ -546,14 +548,14 @@ void maxi_do_primary_3(char postcode[], int country, int service)
|
||||
|
||||
int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
int i, j, block, bit, mode, countrycode = 0, service = 0;
|
||||
int i, j, block, bit, mode, countrycode = 0, service = 0, lp = 0;
|
||||
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];
|
||||
unsigned char local_source[length + 1];
|
||||
#else
|
||||
unsigned char local_source = (unsigned char*)_alloca(length);
|
||||
unsigned char* local_source = (unsigned char*)_alloca(length + 1);
|
||||
#endif
|
||||
|
||||
mode = symbol->option_1;
|
||||
@ -564,9 +566,8 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* 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];
|
||||
}
|
||||
case GS1_MODE:
|
||||
memcpy(local_source, source, length);
|
||||
local_source[length] = '\0';
|
||||
break;
|
||||
case UNICODE_MODE:
|
||||
@ -574,19 +575,18 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
if(error_number != 0) { return error_number; }
|
||||
break;
|
||||
}
|
||||
|
||||
for(i = 0; i < 145; i++) {
|
||||
maxi_codeword[i] = 0;
|
||||
}
|
||||
memset(maxi_codeword, 0, sizeof(maxi_codeword));
|
||||
|
||||
if(mode == -1) { /* If mode is unspecified */
|
||||
if(strlen(symbol->primary) == 0) {
|
||||
lp = strlen(symbol->primary);
|
||||
if(lp == 0) {
|
||||
mode = 4;
|
||||
} else {
|
||||
mode = 2;
|
||||
for(i = 0; i < 10; i++) {
|
||||
for(i = 0; i < 10 && i < lp; i++) {
|
||||
if((symbol->primary[i] < 48) || (symbol->primary[i] > 57)) {
|
||||
mode = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -598,19 +598,19 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
if((mode == 2) || (mode == 3)) { /* Modes 2 and 3 need data in symbol->primary */
|
||||
if(strlen(symbol->primary) != 15) {
|
||||
if(lp != 15) {
|
||||
strcpy(symbol->errtxt, "Invalid Primary String");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
for(i = 9; i < 15; i++) { /* check that country code and service are numeric */
|
||||
if((symbol->primary[i] < 48) || (symbol->primary[i] > 57)) {
|
||||
if((symbol->primary[i] < '0') || (symbol->primary[i] > '9')) {
|
||||
strcpy(symbol->errtxt, "Invalid Primary String");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
strncpy(postcode, symbol->primary, 9);
|
||||
memcpy(postcode, symbol->primary, 9);
|
||||
postcode[9] = '\0';
|
||||
|
||||
if(mode == 2) {
|
||||
@ -620,8 +620,7 @@ int maxicode(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mode == 3) { postcode[6] = '\0'; }
|
||||
else if(mode == 3) { postcode[6] = '\0'; }
|
||||
|
||||
countrystr[0] = symbol->primary[9];
|
||||
countrystr[1] = symbol->primary[10];
|
||||
|
@ -24,16 +24,15 @@
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
|
||||
extern int c39(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
/* Codabar table checked against EN 798:1995 */
|
||||
|
||||
#define CASET "0123456789-$:/.+ABCD"
|
||||
#define CALCIUM "0123456789-$:/.+ABCD"
|
||||
|
||||
static char *CodaTable[20] = {"11111221", "11112211", "11121121", "22111111", "11211211", "21111211",
|
||||
"12111121", "12112111", "12211111", "21121111", "11122111", "11221111", "21112121", "21211121",
|
||||
"21212111", "11212121", "11221211", "12121121", "11121221", "11122211"};
|
||||
|
||||
int c39(struct zint_symbol *symbol, unsigned char source[], int length);
|
||||
|
||||
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
|
||||
@ -49,25 +48,22 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
the specification at http://www.laetus.com/laetus.php?request=file&id=69 */
|
||||
|
||||
unsigned long int tester;
|
||||
int counter;
|
||||
char inter[17];
|
||||
int error_number;
|
||||
char dest[1000];
|
||||
int counter, error_number, h;
|
||||
char inter[18] = { 0 }; /* 131070 -> 17 bits */
|
||||
char dest[64]; /* 17 * 2 + 1 */
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 6) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
strcpy(inter, "");
|
||||
tester = atoi((char*)source);
|
||||
|
||||
if((tester < 3) || (tester > 131070)) {
|
||||
@ -77,7 +73,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
do
|
||||
{
|
||||
if(tester%2 == 0) {
|
||||
if(tester % 2 == 0) {
|
||||
concat(inter, "W");
|
||||
tester = (tester - 2) / 2;
|
||||
} else {
|
||||
@ -87,7 +83,9 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
while(tester != 0);
|
||||
|
||||
for(counter = (strlen(inter) - 1); counter >= 0; counter--) {
|
||||
h = strlen(inter) - 1;
|
||||
*dest = '\0';
|
||||
for(counter = h; counter >= 0; counter--) {
|
||||
if(inter[counter] == 'W') {
|
||||
concat(dest, "32");
|
||||
} else {
|
||||
@ -108,14 +106,10 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
|
||||
from 4 to 64570080. */
|
||||
|
||||
unsigned long int tester;
|
||||
int counter;
|
||||
int counter, h;
|
||||
char inter[17];
|
||||
int error_number;
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
strcpy(inter, "");
|
||||
tester = atoi((char*)source);
|
||||
|
||||
if((tester < 4) || (tester > 64570080))
|
||||
@ -123,6 +117,8 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
|
||||
strcpy(symbol->errtxt, "Data out of range");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
error_number = 0;
|
||||
strcpy(inter, "");
|
||||
do
|
||||
{
|
||||
switch(tester%3) {
|
||||
@ -142,11 +138,12 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des
|
||||
}
|
||||
while(tester != 0);
|
||||
|
||||
for(counter = (strlen(inter) - 1); counter >= 0; counter--)
|
||||
h = strlen(inter) - 1;
|
||||
for(counter = h; counter >= 0; counter--)
|
||||
{
|
||||
dest[(strlen(inter) - 1) - counter] = inter[counter];
|
||||
dest[h - counter] = inter[counter];
|
||||
}
|
||||
dest[strlen(inter)] = '\0';
|
||||
dest[h + 1] = '\0';
|
||||
|
||||
return error_number;
|
||||
}
|
||||
@ -155,7 +152,7 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
/* Draws the patterns for two track pharmacode */
|
||||
char height_pattern[200];
|
||||
unsigned int loopey;
|
||||
unsigned int loopey, h;
|
||||
int writer;
|
||||
int error_number = 0;
|
||||
strcpy(height_pattern, "");
|
||||
@ -164,7 +161,7 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
@ -175,7 +172,8 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
writer = 0;
|
||||
for(loopey = 0; loopey < strlen(height_pattern); loopey++)
|
||||
h = strlen(height_pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3'))
|
||||
{
|
||||
@ -198,12 +196,7 @@ 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
|
||||
char dest[512];
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
@ -212,26 +205,21 @@ int codabar(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
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(CASET, local_source, length);
|
||||
to_upper(source);
|
||||
error_number = is_sane(CALCIUM, 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(((local_source[0] != 'A') && (local_source[0] != 'B')) &&
|
||||
((local_source[0] != 'C') && (local_source[0] != 'D')))
|
||||
if((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C') && (source[0] != 'D'))
|
||||
{
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
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')))
|
||||
if((source[length - 1] != 'A') && (source[length - 1] != 'B') &&
|
||||
(source[length - 1] != 'C') && (source[length - 1] != 'D'))
|
||||
{
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return ERROR_INVALID_DATA;
|
||||
@ -239,18 +227,18 @@ int codabar(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
lookup(CASET, CodaTable, local_source[i], dest);
|
||||
lookup(CALCIUM, CodaTable, source[i], dest);
|
||||
}
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, local_source);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
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];
|
||||
char localstr[10], risultante[7];
|
||||
long int pharmacode, remainder, devisor;
|
||||
int codeword[6];
|
||||
char tabella[34];
|
||||
@ -260,19 +248,16 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Add leading zeros as required */
|
||||
strcpy(localstr, "");
|
||||
zeroes = 8 - length;
|
||||
for(i = 0; i < zeroes; i++) {
|
||||
concat(localstr, "0");
|
||||
}
|
||||
concat(localstr, (char*)source);
|
||||
memset(localstr, '0', zeroes);
|
||||
strcpy(localstr + zeroes, (char*)source);
|
||||
|
||||
/* Calculate the check digit */
|
||||
checksum = 0;
|
||||
@ -290,16 +275,11 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Add check digit to data string */
|
||||
checkdigit = checksum % 10;
|
||||
tempstr[0] = itoc(checkdigit);
|
||||
tempstr[1] = '\0';
|
||||
concat(localstr, tempstr);
|
||||
localstr[8] = itoc(checkdigit);
|
||||
localstr[9] = '\0';
|
||||
|
||||
/* Convert string into an integer value */
|
||||
pharmacode = 0;
|
||||
for(i = 0; i < 9; i++) {
|
||||
pharmacode *= 10;
|
||||
pharmacode += ctoi(localstr[i]);
|
||||
}
|
||||
pharmacode = atoi(localstr);
|
||||
|
||||
/* Convert from decimal to base-32 */
|
||||
devisor = 33554432;
|
||||
@ -312,12 +292,10 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Look up values in 'Tabella di conversione' */
|
||||
strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ");
|
||||
strcpy(risultante, "");
|
||||
for(i = 5; i >= 0; i--) {
|
||||
tempstr[0] = tabella[codeword[i]];
|
||||
concat(risultante, tempstr);
|
||||
risultante[5 - i] = tabella[codeword[i]];
|
||||
}
|
||||
|
||||
risultante[6] = '\0';
|
||||
/* Plot the barcode using Code 39 */
|
||||
error_number = c39(symbol, (unsigned char*)risultante, strlen(risultante));
|
||||
if(error_number != 0) { return error_number; }
|
||||
|
105
backend/micqr.c
105
backend/micqr.c
@ -22,27 +22,26 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
#include "common.h"
|
||||
#include "reedsol.h"
|
||||
#include "micqr.h"
|
||||
#include "shiftjis.h"
|
||||
|
||||
#define NUMERIC 1
|
||||
#define ALPHANUM 2
|
||||
#define BYTE 3
|
||||
#define KANJI 4
|
||||
|
||||
#define QRSET "0123456789ABCDEFGHIJKLNMOPQRSTUVWXYZ $%*+-./:"
|
||||
#define RHODIUM "0123456789ABCDEFGHIJKLNMOPQRSTUVWXYZ $%*+-./:"
|
||||
|
||||
void qrnumeric_encode(char binary[], unsigned char source[])
|
||||
void qrnumeric_encode(char binary[], unsigned char source[], int length)
|
||||
{ /* Encodes numeric data according to section 6.4.3 */
|
||||
|
||||
int length, blocks, remainder, i;
|
||||
int blocks, remainder, i;
|
||||
char block_binary[11];
|
||||
int block_value;
|
||||
|
||||
block_value = 0;
|
||||
length = ustrlen(source);
|
||||
blocks = length / 3;
|
||||
remainder = length % 3;
|
||||
|
||||
@ -91,20 +90,19 @@ void qrnumeric_encode(char binary[], unsigned char source[])
|
||||
return;
|
||||
}
|
||||
|
||||
void qralpha_encode(char binary[], unsigned char source[])
|
||||
void qralpha_encode(char binary[], unsigned char source[], int length)
|
||||
{ /* Encodes alphanumeric data according to 6.4.4 */
|
||||
|
||||
int length, blocks, remainder, i;
|
||||
int blocks, remainder, i;
|
||||
char block_binary[12];
|
||||
int block_value;
|
||||
|
||||
length = ustrlen(source);
|
||||
blocks = length / 2;
|
||||
remainder = length % 2;
|
||||
|
||||
for(i = 0; i < blocks; i++) {
|
||||
block_value = posn(QRSET, source[i * 2]) * 45;
|
||||
block_value += posn(QRSET, source[(i * 2) + 1]);
|
||||
block_value = posn(RHODIUM, source[i * 2]) * 45;
|
||||
block_value += posn(RHODIUM, source[(i * 2) + 1]);
|
||||
|
||||
strcpy(block_binary, "");
|
||||
if(block_value & 0x400) { concat(block_binary, "1"); } else { concat(block_binary, "0"); }
|
||||
@ -122,7 +120,7 @@ void qralpha_encode(char binary[], unsigned char source[])
|
||||
}
|
||||
|
||||
if(remainder == 1) {
|
||||
block_value = posn(QRSET, source[i * 2]);
|
||||
block_value = posn(RHODIUM, source[i * 2]);
|
||||
|
||||
strcpy(block_binary, "");
|
||||
if(block_value & 0x20) { concat(block_binary, "1"); } else { concat(block_binary, "0"); }
|
||||
@ -137,12 +135,10 @@ void qralpha_encode(char binary[], unsigned char source[])
|
||||
return;
|
||||
}
|
||||
|
||||
void qrbyte_encode(char binary[], unsigned char source[])
|
||||
void qrbyte_encode(char binary[], unsigned char source[], int length)
|
||||
{ /* Encodes byte mode data according to 6.4.5 */
|
||||
|
||||
int length, i;
|
||||
|
||||
length = ustrlen(source);
|
||||
int i;
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
if(source[i] & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
@ -158,14 +154,13 @@ void qrbyte_encode(char binary[], unsigned char source[])
|
||||
return;
|
||||
}
|
||||
|
||||
int qrkanji_encode(char binary[], unsigned char source[])
|
||||
int qrkanji_encode(char binary[], unsigned char source[], int length)
|
||||
{ /* Assumes input is in Shift-JIS format */
|
||||
int i, len, h, val, count;
|
||||
int i, h, val, count;
|
||||
|
||||
len = ustrlen(source);
|
||||
count = 0;
|
||||
|
||||
for(i=0; i<len; i+=2) {
|
||||
for(i = 0; i < length; i += 2) {
|
||||
val = (source[i] << 8) | source[i+1];
|
||||
if(val <= 0x9ffc) {
|
||||
val -= 0x8140;
|
||||
@ -194,14 +189,13 @@ int qrkanji_encode(char binary[], unsigned char source[])
|
||||
return count;
|
||||
}
|
||||
|
||||
void versionm1(char binary_data[], unsigned char source[])
|
||||
void versionm1(char binary_data[], unsigned char source[], int length)
|
||||
{
|
||||
int length, i, latch;
|
||||
int i, latch;
|
||||
int bits_total, bits_left, remainder;
|
||||
int data_codewords, ecc_codewords;
|
||||
unsigned char data_blocks[4], ecc_blocks[3];
|
||||
|
||||
length = ustrlen(source);
|
||||
bits_total = 20;
|
||||
latch = 0;
|
||||
|
||||
@ -210,7 +204,7 @@ void versionm1(char binary_data[], unsigned char source[])
|
||||
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);
|
||||
qrnumeric_encode(binary_data, source, length);
|
||||
|
||||
/* Add terminator */
|
||||
bits_left = bits_total - strlen(binary_data);
|
||||
@ -296,14 +290,13 @@ void versionm1(char binary_data[], unsigned char source[])
|
||||
return;
|
||||
}
|
||||
|
||||
void versionm2(char binary_data[], unsigned char source[], int char_system, int ecc_mode)
|
||||
void versionm2(char binary_data[], unsigned char source[], int length, int char_system, int ecc_mode)
|
||||
{
|
||||
int length, i, latch;
|
||||
int i, latch;
|
||||
int bits_total, bits_left, remainder;
|
||||
int data_codewords, ecc_codewords;
|
||||
unsigned char data_blocks[6], ecc_blocks[7];
|
||||
|
||||
length = ustrlen(source);
|
||||
latch = 0;
|
||||
|
||||
if(ecc_mode == 1) { bits_total = 40; }
|
||||
@ -321,8 +314,8 @@ void versionm2(char binary_data[], unsigned char source[], int char_system, int
|
||||
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); }
|
||||
if(char_system == NUMERIC) { qrnumeric_encode(binary_data, source, length); }
|
||||
if(char_system == ALPHANUM) { qralpha_encode(binary_data, source, length); }
|
||||
|
||||
/* Add terminator */
|
||||
bits_left = bits_total - strlen(binary_data);
|
||||
@ -389,15 +382,14 @@ void versionm2(char binary_data[], unsigned char source[], int char_system, int
|
||||
return;
|
||||
}
|
||||
|
||||
void versionm3(char binary_data[], unsigned char source[], int char_system, int ecc_mode)
|
||||
void versionm3(char binary_data[], unsigned char source[], int length, int char_system, int ecc_mode)
|
||||
{
|
||||
int length, i, latch;
|
||||
int i, latch;
|
||||
int bits_total, bits_left, remainder;
|
||||
int data_codewords, ecc_codewords;
|
||||
unsigned char data_blocks[12], ecc_blocks[9];
|
||||
int sjis_count;
|
||||
|
||||
length = ustrlen(source);
|
||||
latch = 0;
|
||||
|
||||
if(ecc_mode == 1) { bits_total = 84; }
|
||||
@ -422,10 +414,10 @@ void versionm3(char binary_data[], unsigned char source[], int char_system, int
|
||||
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); }
|
||||
if(char_system == BYTE) { qrbyte_encode(binary_data, source); }
|
||||
if(char_system == KANJI) { sjis_count = qrkanji_encode(binary_data, source); }
|
||||
if(char_system == NUMERIC) { qrnumeric_encode(binary_data, source, length); }
|
||||
if(char_system == ALPHANUM) { qralpha_encode(binary_data, source, length); }
|
||||
if(char_system == BYTE) { qrbyte_encode(binary_data, source, length); }
|
||||
if(char_system == KANJI) { sjis_count = qrkanji_encode(binary_data, source, length); }
|
||||
|
||||
if(char_system == KANJI) {
|
||||
if(sjis_count & 0x04) { binary_data[2] = '1'; } else { binary_data[2] = '0'; }
|
||||
@ -528,15 +520,14 @@ void versionm3(char binary_data[], unsigned char source[], int char_system, int
|
||||
return;
|
||||
}
|
||||
|
||||
void versionm4(char binary_data[], unsigned char source[], int char_system, int ecc_mode)
|
||||
void versionm4(char binary_data[], unsigned char source[], int length, int char_system, int ecc_mode)
|
||||
{
|
||||
int length, i, latch;
|
||||
int i, latch;
|
||||
int bits_total, bits_left, remainder;
|
||||
int data_codewords, ecc_codewords;
|
||||
unsigned char data_blocks[17], ecc_blocks[15];
|
||||
int sjis_count;
|
||||
|
||||
length = ustrlen(source);
|
||||
latch = 0;
|
||||
|
||||
if(ecc_mode == 1) { bits_total = 128; }
|
||||
@ -563,10 +554,10 @@ void versionm4(char binary_data[], unsigned char source[], int char_system, int
|
||||
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); }
|
||||
if(char_system == BYTE) { qrbyte_encode(binary_data, source); }
|
||||
if(char_system == KANJI) { sjis_count = qrkanji_encode(binary_data, source); }
|
||||
if(char_system == NUMERIC) { qrnumeric_encode(binary_data, source, length); }
|
||||
if(char_system == ALPHANUM) { qralpha_encode(binary_data, source, length); }
|
||||
if(char_system == BYTE) { qrbyte_encode(binary_data, source, length); }
|
||||
if(char_system == KANJI) { sjis_count = qrkanji_encode(binary_data, source, length); }
|
||||
|
||||
if(char_system == KANJI) {
|
||||
if(sjis_count & 0x08) { binary_data[3] = '1'; } else { binary_data[3] = '0'; }
|
||||
@ -653,13 +644,12 @@ int microqr(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
char pattern_bit;
|
||||
int width, i, j, pattern_no;
|
||||
int sum1, sum2, evaluation[4], format, format_full, kanji;
|
||||
int error_number;
|
||||
char formatstr[16];
|
||||
|
||||
#ifndef _MSC_VER
|
||||
unsigned char local_source[length];
|
||||
unsigned char local_source[length + 1];
|
||||
#else
|
||||
unsigned char local_source = (unsigned char*)_alloca(length);
|
||||
unsigned char* local_source = (unsigned char*)_alloca(length + 1);
|
||||
#endif
|
||||
|
||||
/* Analise input data and select encoding method - zint does not attempt to
|
||||
@ -676,25 +666,12 @@ int microqr(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
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; }
|
||||
if(is_sane(RHODIUM, local_source, length) == 0) { char_system = ALPHANUM; }
|
||||
if(is_sane(NEON, local_source, length) == 0) { char_system = NUMERIC; }
|
||||
}
|
||||
width = 0;
|
||||
format = 0;
|
||||
@ -799,10 +776,10 @@ int microqr(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
strcpy(binary_data, "");
|
||||
switch(symbol_size) {
|
||||
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;
|
||||
case 1: versionm1(binary_data, local_source, length); break;
|
||||
case 2: versionm2(binary_data, local_source, length, char_system, symbol->option_1); break;
|
||||
case 3: versionm3(binary_data, local_source, length, char_system, symbol->option_1); break;
|
||||
case 4: versionm4(binary_data, local_source, length, char_system, symbol->option_1); break;
|
||||
}
|
||||
|
||||
switch(symbol_size) {
|
||||
|
1173
backend/pdf417.c
1173
backend/pdf417.c
File diff suppressed because it is too large
Load Diff
@ -40,11 +40,10 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
unsigned int i, check;
|
||||
unsigned char *checkptr;
|
||||
static char grid[9] = {1,1,1,1,0,1,0,0,1};
|
||||
char dest[1000];
|
||||
char dest[1024]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 ~ 1024 */
|
||||
int error_number;
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 65) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
@ -58,10 +57,10 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
checkptr = (unsigned char *)calloc (1, length * 4 + 8);
|
||||
|
||||
/* Start character */
|
||||
concat(dest, "31311331");
|
||||
strcpy(dest, "31311331");
|
||||
|
||||
/* Data area */
|
||||
for(i = 0; i <= length; i++)
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
check = posn(SSET, source[i]);
|
||||
lookup(SSET, PlessTable, source[i], dest);
|
||||
@ -98,27 +97,23 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int msi_plessey(struct zint_symbol *symbol, unsigned char source[])
|
||||
int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Plain MSI Plessey - does not calculate any check character */
|
||||
|
||||
unsigned int i;
|
||||
int error_number;
|
||||
char dest[1000];
|
||||
char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(ustrlen(source) > 55) {
|
||||
if(length > 55) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat (dest, "21");
|
||||
strcpy(dest, "21");
|
||||
|
||||
for(i = 0; i <= ustrlen(source); i++)
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
lookup(NESET, MSITable, source[i], dest);
|
||||
lookup(NEON, MSITable, source[i], dest);
|
||||
}
|
||||
|
||||
/* Stop character */
|
||||
@ -126,176 +121,134 @@ int msi_plessey(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
return error_number;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[])
|
||||
int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* MSI Plessey with Modulo 10 check digit - algorithm from Barcode Island
|
||||
http://www.barcodeisland.com/ */
|
||||
|
||||
unsigned int i, wright, dau, pedwar, pump;
|
||||
char un[200], tri[200];
|
||||
unsigned long i, wright, dau, pedwar, pump, n;
|
||||
char un[200], tri[32];
|
||||
int error_number, h;
|
||||
char dest[1000];
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(ustrlen(source) > 55) {
|
||||
if(length > 18) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat (dest, "21");
|
||||
strcpy(dest, "21");
|
||||
|
||||
/* draw data section */
|
||||
for(i = 0; i < ustrlen(source); i++)
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
lookup(NESET, MSITable, source[i], dest);
|
||||
lookup(NEON, MSITable, source[i], dest);
|
||||
}
|
||||
|
||||
/* caluculate check digit */
|
||||
wright = 0;
|
||||
if((ustrlen(source)%2) == 0)
|
||||
n = ((length % 2) == 0) ? 1 : 0;
|
||||
for(i = n; i < length; i += 2)
|
||||
{
|
||||
for(i = 1; i < ustrlen(source); i+=2)
|
||||
{
|
||||
un[wright] = source[i];
|
||||
wright ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < ustrlen(source); i+=2)
|
||||
{
|
||||
un[wright] = source[i];
|
||||
wright ++;
|
||||
}
|
||||
un[wright++] = source[i];
|
||||
}
|
||||
un[wright] = '\0';
|
||||
|
||||
dau = atoi(un);
|
||||
dau = strtoul(un, NULL, 10);
|
||||
dau *= 2;
|
||||
|
||||
sprintf(tri,"%d",dau);
|
||||
sprintf(tri, "%ld", dau);
|
||||
|
||||
pedwar = 0;
|
||||
for(i = 0; i < strlen(tri); i++)
|
||||
h = strlen(tri);
|
||||
for(i = 0; i < h; i++)
|
||||
{
|
||||
pedwar += ctoi(tri[i]);
|
||||
}
|
||||
|
||||
|
||||
if((ustrlen(source)%2) == 0)
|
||||
{
|
||||
for(i = 0; i < ustrlen(source); i+=2)
|
||||
n = length % 2;
|
||||
for(i = n; i < length; i+=2)
|
||||
{
|
||||
pedwar += ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 1; i < ustrlen(source); i+=2)
|
||||
{
|
||||
pedwar += ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pump = (10 - pedwar%10);
|
||||
pump = (10 - pedwar % 10);
|
||||
if(pump == 10)
|
||||
{
|
||||
pump = 0;
|
||||
}
|
||||
|
||||
/* draw check digit */
|
||||
lookup(NESET, MSITable, itoc(pump), dest);
|
||||
lookup(NEON, MSITable, itoc(pump), dest);
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "121");
|
||||
|
||||
h = ustrlen(source);
|
||||
source[h] = itoc(pump);
|
||||
source[h + 1] = '\0';
|
||||
expand(symbol, dest);
|
||||
|
||||
ustrcpy(symbol->text, source);
|
||||
symbol->text[length] = itoc(pump);
|
||||
symbol->text[length + 1] = '\0';
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[])
|
||||
int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len)
|
||||
{ /* MSI Plessey with two Modulo 10 check digits - algorithm from
|
||||
Barcode Island http://www.barcodeisland.com/ */
|
||||
|
||||
unsigned int i, wright, dau, pedwar, pump, chwech;
|
||||
char un[200], tri[200];
|
||||
unsigned long i, n, wright, dau, pedwar, pump, chwech;
|
||||
char un[16], tri[32];
|
||||
int error_number, h;
|
||||
char dest[1000];
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(ustrlen(source) > 55) { /* No Entry Stack Smashers! */
|
||||
if(src_len > 18) { /* No Entry Stack Smashers! limit because of str->number conversion*/
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat (dest, "21");
|
||||
strcpy(dest, "21");
|
||||
|
||||
/* draw data section */
|
||||
for(i = 0; i < ustrlen(source); i++)
|
||||
for(i = 0; i < src_len; i++)
|
||||
{
|
||||
lookup(NESET, MSITable, source[i], dest);
|
||||
lookup(NEON, MSITable, source[i], dest);
|
||||
}
|
||||
|
||||
/* calculate first check digit */
|
||||
wright = 0;
|
||||
if((ustrlen(source)%2) == 0)
|
||||
|
||||
n = ((src_len %2) == 0) ? 1 : 0;
|
||||
for(i = n; i < src_len; i += 2)
|
||||
{
|
||||
for(i = 1; i < ustrlen(source); i+=2)
|
||||
{
|
||||
un[wright] = source[i];
|
||||
wright ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < ustrlen(source); i+=2)
|
||||
{
|
||||
un[wright] = source[i];
|
||||
wright ++;
|
||||
}
|
||||
un[wright++] = source[i];
|
||||
}
|
||||
un[wright] = '\0';
|
||||
|
||||
dau = atoi(un);
|
||||
dau = strtoul(un, NULL, 10);
|
||||
dau *= 2;
|
||||
|
||||
sprintf(tri,"%d",dau);
|
||||
sprintf(tri, "%ld", dau);
|
||||
|
||||
pedwar = 0;
|
||||
for(i = 0; i < strlen(tri); i++)
|
||||
h = strlen(tri);
|
||||
for(i = 0; i < h; i++)
|
||||
{
|
||||
pedwar += ctoi(tri[i]);
|
||||
}
|
||||
|
||||
|
||||
if((ustrlen(source)%2) == 0)
|
||||
{
|
||||
for(i = 0; i < ustrlen(source); i+=2)
|
||||
n = src_len % 2;
|
||||
for(i = n; i < src_len; i += 2)
|
||||
{
|
||||
pedwar += ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 1; i < ustrlen(source); i+=2)
|
||||
{
|
||||
pedwar += ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pump = (10 - pedwar%10);
|
||||
pump = 10 - pedwar % 10;
|
||||
if(pump == 10)
|
||||
{
|
||||
pump = 0;
|
||||
@ -303,107 +256,87 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
||||
/* calculate second check digit */
|
||||
wright = 0;
|
||||
if((ustrlen(source)%2) == 0)
|
||||
n = src_len % 2;
|
||||
for(i = n; i < src_len; i += 2)
|
||||
{
|
||||
for(i = 0; i < ustrlen(source); i+=2)
|
||||
{
|
||||
un[wright] = source[i];
|
||||
wright ++;
|
||||
un[wright++] = source[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 1; i < ustrlen(source); i+=2)
|
||||
{
|
||||
un[wright] = source[i];
|
||||
wright ++;
|
||||
}
|
||||
}
|
||||
un[wright] = itoc(pump);
|
||||
wright++;
|
||||
un[wright++] = itoc(pump);
|
||||
un[wright] = '\0';
|
||||
|
||||
dau = atoi(un);
|
||||
dau = strtoul(un, NULL, 10);
|
||||
dau *= 2;
|
||||
|
||||
sprintf(tri,"%d",dau);
|
||||
sprintf(tri, "%ld", dau);
|
||||
|
||||
pedwar = 0;
|
||||
for(i = 0; i < strlen(tri); i++)
|
||||
h = strlen(tri);
|
||||
for(i = 0; i < h; i++)
|
||||
{
|
||||
pedwar += ctoi(tri[i]);
|
||||
}
|
||||
|
||||
|
||||
if((ustrlen(source)%2) == 0)
|
||||
{
|
||||
for(i = 1; i < ustrlen(source); i+=2)
|
||||
i = ((src_len % 2) == 0) ? 1 : 0;
|
||||
for(; i < src_len; i += 2)
|
||||
{
|
||||
pedwar += ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < ustrlen(source); i+=2)
|
||||
{
|
||||
pedwar += ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
|
||||
chwech = (10 - pedwar%10);
|
||||
chwech = 10 - pedwar % 10;
|
||||
if(chwech == 10)
|
||||
{
|
||||
chwech = 0;
|
||||
}
|
||||
|
||||
/* Draw check digits */
|
||||
lookup(NESET, MSITable, itoc(pump), dest);
|
||||
lookup(NESET, MSITable, itoc(chwech), dest);
|
||||
lookup(NEON, MSITable, itoc(pump), dest);
|
||||
lookup(NEON, MSITable, itoc(chwech), dest);
|
||||
|
||||
/* Stop character */
|
||||
concat (dest, "121");
|
||||
|
||||
h = ustrlen(source);
|
||||
source[h] = itoc(pump);
|
||||
source[h + 1] = itoc(chwech);
|
||||
source[h + 2] = '\0';
|
||||
expand(symbol, dest);
|
||||
|
||||
ustrcpy(symbol->text, source);
|
||||
symbol->text[src_len] = itoc(pump);
|
||||
symbol->text[src_len + 1] = itoc(chwech);
|
||||
symbol->text[src_len + 2] = '\0';
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
||||
int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[])
|
||||
int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len)
|
||||
{
|
||||
/* Calculate a Modulo 11 check digit using the system discussed on Wikipedia -
|
||||
see http://en.wikipedia.org/wiki/Talk:MSI_Barcode */
|
||||
/* uses the IBM weight system */
|
||||
|
||||
int i, weight, x, check, h;
|
||||
int i, weight, x, check;
|
||||
int error_number;
|
||||
char dest[1000];
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(ustrlen(source) > 55) {
|
||||
if(src_len > 55) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat (dest, "21");
|
||||
strcpy(dest, "21");
|
||||
|
||||
/* draw data section */
|
||||
for(i = 0; i < ustrlen(source); i++)
|
||||
for(i = 0; i < src_len; i++)
|
||||
{
|
||||
lookup(NESET, MSITable, source[i], dest);
|
||||
lookup(NEON, MSITable, source[i], dest);
|
||||
}
|
||||
|
||||
/* calculate check digit */
|
||||
x = 0;
|
||||
weight = 2;
|
||||
for(i = (ustrlen(source) - 1); i >= 0; i--) {
|
||||
for(i = src_len - 1; i >= 0; i--) {
|
||||
x += weight * ctoi(source[i]);
|
||||
weight++;
|
||||
if(weight > 7) {
|
||||
@ -413,63 +346,61 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[])
|
||||
|
||||
check = (11 - (x % 11)) % 11;
|
||||
if(check == 10) {
|
||||
lookup(NESET, MSITable, '1', dest);
|
||||
lookup(NESET, MSITable, '0', dest);
|
||||
lookup(NEON, MSITable, '1', dest);
|
||||
lookup(NEON, MSITable, '0', dest);
|
||||
} else {
|
||||
lookup(NESET, MSITable, itoc(check), dest);
|
||||
}
|
||||
|
||||
h = ustrlen(source);
|
||||
if(check == 10) {
|
||||
source[h] = '1';
|
||||
source[h + 1] = '0';
|
||||
source[h + 2] = '\0';
|
||||
} else {
|
||||
source[h] = itoc(check);
|
||||
source[h + 1] = '\0';
|
||||
lookup(NEON, MSITable, itoc(check), dest);
|
||||
}
|
||||
|
||||
/* stop character */
|
||||
concat (dest, "121");
|
||||
|
||||
expand(symbol, dest);
|
||||
|
||||
ustrcpy(symbol->text, source);
|
||||
if(check == 10) {
|
||||
concat((char* )symbol->text, "10");
|
||||
} else {
|
||||
symbol->text[src_len] = itoc(check);
|
||||
symbol->text[src_len + 1] = '\0';
|
||||
}
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[])
|
||||
int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len)
|
||||
{
|
||||
/* Combining the Barcode Island and Wikipedia code */
|
||||
/* Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */
|
||||
/* Weighted using the IBM system */
|
||||
|
||||
int i, weight, x, check, wright, dau, pedwar, pump, h;
|
||||
char un[200], tri[200];
|
||||
unsigned long i, weight, x, check, wright, dau, pedwar, pump, h;
|
||||
char un[16], tri[16];
|
||||
int error_number;
|
||||
char dest[1000];
|
||||
unsigned char temp[32];
|
||||
unsigned int temp_len;
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(ustrlen(source) > 55) {
|
||||
if(src_len > 18) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
/* start character */
|
||||
concat (dest, "21");
|
||||
strcpy(dest, "21");
|
||||
|
||||
/* draw data section */
|
||||
for(i = 0; i < ustrlen(source); i++)
|
||||
for(i = 0; i < src_len; i++)
|
||||
{
|
||||
lookup(NESET, MSITable, source[i], dest);
|
||||
lookup(NEON, MSITable, source[i], dest);
|
||||
}
|
||||
|
||||
/* calculate first (mod 11) digit */
|
||||
wright = ustrlen(source);
|
||||
x = 0;
|
||||
weight = 2;
|
||||
for(i = (ustrlen(source) - 1); i >= 0; i--) {
|
||||
for(i = src_len - 1; i >= 0; i--) {
|
||||
x += weight * ctoi(source[i]);
|
||||
weight++;
|
||||
if(weight > 7) {
|
||||
@ -478,105 +409,87 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[])
|
||||
}
|
||||
|
||||
check = (11 - (x % 11)) % 11;
|
||||
ustrcpy(temp, source);
|
||||
temp_len = src_len;
|
||||
if(check == 10) {
|
||||
lookup(NESET, MSITable, '1', dest);
|
||||
lookup(NESET, MSITable, '0', dest);
|
||||
source[wright] = '1';
|
||||
source[wright + 1] = '0';
|
||||
source[wright + 2] = '\0';
|
||||
lookup(NEON, MSITable, '1', dest);
|
||||
lookup(NEON, MSITable, '0', dest);
|
||||
uconcat(temp, (unsigned char *)"10");
|
||||
temp_len += 2;
|
||||
} else {
|
||||
lookup(NESET, MSITable, itoc(check), dest);
|
||||
source[wright] = itoc(check);
|
||||
source[wright + 1] = '\0';
|
||||
lookup(NEON, MSITable, itoc(check), dest);
|
||||
temp[temp_len++] = itoc(check);
|
||||
temp[temp_len] = '\0';
|
||||
}
|
||||
|
||||
/* caluculate second (mod 10) check digit */
|
||||
wright = 0;
|
||||
if((ustrlen(source)%2) == 0)
|
||||
i = ((temp_len % 2) == 0) ? 1 : 0;
|
||||
for(; i < temp_len; i += 2)
|
||||
{
|
||||
for(i = 1; i < ustrlen(source); i+=2)
|
||||
{
|
||||
un[wright] = source[i];
|
||||
wright ++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < ustrlen(source); i+=2)
|
||||
{
|
||||
un[wright] = source[i];
|
||||
wright ++;
|
||||
}
|
||||
un[wright++] = temp[i];
|
||||
}
|
||||
un[wright] = '\0';
|
||||
|
||||
dau = atoi(un);
|
||||
dau = strtoul(un, NULL, 10);
|
||||
dau *= 2;
|
||||
|
||||
sprintf(tri,"%d",dau);
|
||||
sprintf(tri, "%ld", dau);
|
||||
|
||||
pedwar = 0;
|
||||
for(i = 0; i < strlen(tri); i++)
|
||||
h = strlen(tri);
|
||||
for(i = 0; i < h; i++)
|
||||
{
|
||||
pedwar += ctoi(tri[i]);
|
||||
}
|
||||
|
||||
|
||||
if((ustrlen(source)%2) == 0)
|
||||
i = temp_len % 2;
|
||||
for(; i < temp_len; i+=2)
|
||||
{
|
||||
for(i = 0; i < ustrlen(source); i+=2)
|
||||
{
|
||||
pedwar += ctoi(source[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 1; i < ustrlen(source); i+=2)
|
||||
{
|
||||
pedwar += ctoi(source[i]);
|
||||
}
|
||||
pedwar += ctoi(temp[i]);
|
||||
}
|
||||
|
||||
pump = (10 - pedwar%10);
|
||||
pump = 10 - pedwar % 10;
|
||||
if(pump == 10)
|
||||
{
|
||||
pump = 0;
|
||||
}
|
||||
|
||||
/* draw check digit */
|
||||
lookup(NESET, MSITable, itoc(pump), dest);
|
||||
lookup(NEON, MSITable, itoc(pump), dest);
|
||||
|
||||
/* stop character */
|
||||
concat (dest, "121");
|
||||
|
||||
h = ustrlen(source);
|
||||
source[h] = itoc(pump);
|
||||
source[h + 1] = '\0';
|
||||
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, source);
|
||||
|
||||
temp[temp_len++] = itoc(pump);
|
||||
temp[temp_len] = '\0';
|
||||
|
||||
|
||||
ustrcpy(symbol->text, temp);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int error_number;
|
||||
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, 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;
|
||||
}
|
||||
|
||||
switch(symbol->option_2) {
|
||||
case 0: error_number = msi_plessey(symbol, source); break;
|
||||
case 1: error_number = msi_plessey_mod10(symbol, source); break;
|
||||
case 2: error_number = msi_plessey_mod1010(symbol, source); break;
|
||||
case 3: error_number = msi_plessey_mod11(symbol, source); break;
|
||||
case 4: error_number = msi_plessey_mod1110(symbol, source); break;
|
||||
case 0: error_number = msi_plessey(symbol, source, length); break;
|
||||
case 1: error_number = msi_plessey_mod10(symbol, source, length); break;
|
||||
case 2: error_number = msi_plessey_mod1010(symbol, source, length); break;
|
||||
case 3: error_number = msi_plessey_mod11(symbol, source, length); break;
|
||||
case 4: error_number = msi_plessey_mod1110(symbol, source, length); break;
|
||||
}
|
||||
|
||||
return error_number;
|
||||
|
@ -104,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, 6);
|
||||
errno = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
|
||||
if (errno == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Malformed foreground colour target");
|
||||
return ERROR_INVALID_OPTION;
|
||||
}
|
||||
errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, 6);
|
||||
errno = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
|
||||
if (errno == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||
return ERROR_INVALID_OPTION;
|
||||
|
149
backend/postal.c
149
backend/postal.c
@ -70,7 +70,7 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
@ -78,15 +78,15 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
|
||||
sum = 0;
|
||||
|
||||
/* start character */
|
||||
concat (dest, "L");
|
||||
strcpy(dest, "L");
|
||||
|
||||
for (i=0; i < length; i++)
|
||||
{
|
||||
lookup(NESET, PNTable, source[i], dest);
|
||||
lookup(NEON, PNTable, source[i], dest);
|
||||
sum += ctoi(source[i]);
|
||||
}
|
||||
|
||||
check_digit = (10 - (sum%10))%10;
|
||||
check_digit = (10 - (sum % 10)) % 10;
|
||||
concat(dest, PNTable[check_digit]);
|
||||
|
||||
/* stop character */
|
||||
@ -98,11 +98,10 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
|
||||
int post_plot(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
/* Puts PostNet barcodes into the pattern matrix */
|
||||
char height_pattern[200];
|
||||
unsigned int loopey;
|
||||
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */
|
||||
unsigned int loopey, h;
|
||||
int writer;
|
||||
int error_number;
|
||||
strcpy(height_pattern, "");
|
||||
|
||||
error_number = 0;
|
||||
|
||||
@ -112,7 +111,8 @@ int post_plot(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
writer = 0;
|
||||
for(loopey = 0; loopey < strlen(height_pattern); loopey++)
|
||||
h = strlen(height_pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if(height_pattern[loopey] == 'L')
|
||||
{
|
||||
@ -141,7 +141,7 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
@ -149,15 +149,15 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
|
||||
sum = 0;
|
||||
|
||||
/* start character */
|
||||
concat (dest, "L");
|
||||
strcpy(dest, "L");
|
||||
|
||||
for (i=0; i < length; i++)
|
||||
{
|
||||
lookup(NESET, PLTable, source[i], dest);
|
||||
lookup(NEON, PLTable, source[i], dest);
|
||||
sum += ctoi(source[i]);
|
||||
}
|
||||
|
||||
check_digit = (10 - (sum%10))%10;
|
||||
check_digit = (10 - (sum % 10)) % 10;
|
||||
concat(dest, PLTable[check_digit]);
|
||||
|
||||
/* stop character */
|
||||
@ -169,11 +169,10 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int
|
||||
int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
/* Puts PLANET barcodes into the pattern matrix */
|
||||
char height_pattern[200];
|
||||
unsigned int loopey;
|
||||
char height_pattern[256]; /* 5 + 38 * 5 + 5 + 5 + 1 ~ 256 */
|
||||
unsigned int loopey, h;
|
||||
int writer;
|
||||
int error_number;
|
||||
strcpy(height_pattern, "");
|
||||
|
||||
error_number = 0;
|
||||
|
||||
@ -183,7 +182,8 @@ int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
writer = 0;
|
||||
for(loopey = 0; loopey < strlen(height_pattern); loopey++)
|
||||
h = strlen(height_pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if(height_pattern[loopey] == 'L')
|
||||
{
|
||||
@ -203,23 +203,21 @@ int korea_post(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Korean Postal Authority */
|
||||
|
||||
int total, loop, check, zeroes, error_number;
|
||||
char localstr[8], checkstr[3], dest[80];
|
||||
char localstr[8], dest[80];
|
||||
|
||||
error_number = 0;
|
||||
if(length > 6) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
strcpy(localstr, "");
|
||||
zeroes = 6 - length;
|
||||
for(loop = 0; loop < zeroes; loop++)
|
||||
concat(localstr, "0");
|
||||
concat(localstr, (char *)source);
|
||||
memset(localstr, '0', zeroes);
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
|
||||
total = 0;
|
||||
for(loop = 0; loop < 6; loop++) {
|
||||
@ -227,15 +225,13 @@ int korea_post(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
check = 10 - (total % 10);
|
||||
if(check == 10) { check = 0; }
|
||||
checkstr[0] = itoc(check);
|
||||
checkstr[1] = '\0';
|
||||
concat(localstr, checkstr);
|
||||
|
||||
strcpy(dest, "");
|
||||
localstr[6] = itoc(check);
|
||||
localstr[7] = '\0';
|
||||
*dest = '\0';
|
||||
for(loop = 5; loop >= 0; loop--) {
|
||||
lookup(NESET, KoreaTable, localstr[loop], dest);
|
||||
lookup(NEON, KoreaTable, localstr[loop], dest);
|
||||
}
|
||||
lookup(NESET, KoreaTable, localstr[6], dest);
|
||||
lookup(NEON, KoreaTable, localstr[6], dest);
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, (unsigned char*)localstr);
|
||||
return error_number;
|
||||
@ -245,7 +241,8 @@ 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 */
|
||||
char dest[17];
|
||||
|
||||
char dest[16] = { 0 };
|
||||
|
||||
if(length > 1) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
@ -279,21 +276,20 @@ int fim(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char rm4scc(char source[], unsigned char dest[])
|
||||
char rm4scc(char source[], unsigned char dest[], int length)
|
||||
{
|
||||
/* Handles the 4 State barcodes used in the UK by Royal Mail */
|
||||
unsigned int i;
|
||||
int top, bottom, row, column, check_digit;
|
||||
char values[3], set_copy[38];
|
||||
strcpy(set_copy, KRSET);
|
||||
char values[3], set_copy[] = KRSET;
|
||||
|
||||
top = 0;
|
||||
bottom = 0;
|
||||
|
||||
/* start character */
|
||||
concat ((char*)dest, "1");
|
||||
strcpy((char*)dest, "1");
|
||||
|
||||
for (i=0; i < strlen(source); i++) {
|
||||
for (i = 0; i < length; i++) {
|
||||
lookup(KRSET, RoyalTable, source[i], (char*)dest);
|
||||
strcpy(values, RoyalValues[posn(KRSET, source[i])]);
|
||||
top += ctoi(values[0]);
|
||||
@ -318,11 +314,10 @@ 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, i;
|
||||
unsigned int loopey, h;
|
||||
int writer;
|
||||
int error_number;
|
||||
strcpy(height_pattern, "");
|
||||
unsigned char local_source[120];
|
||||
|
||||
error_number = 0;
|
||||
|
||||
@ -330,19 +325,17 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
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(KRSET, local_source, length);
|
||||
to_upper(source);
|
||||
error_number = is_sane(KRSET, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
check = rm4scc((char*)local_source, (unsigned char*)height_pattern);
|
||||
check = rm4scc((char*)source, (unsigned char*)height_pattern, length);
|
||||
|
||||
writer = 0;
|
||||
for(loopey = 0; loopey < strlen(height_pattern); loopey++)
|
||||
h = strlen(height_pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
|
||||
{
|
||||
@ -372,10 +365,9 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
/* Specification at http://www.tntpost.nl/zakelijk/klantenservice/downloads/kIX_code/download.aspx */
|
||||
char height_pattern[50], localstr[13];
|
||||
unsigned int loopey;
|
||||
int writer, i;
|
||||
int writer, i, h;
|
||||
int error_number, zeroes;
|
||||
strcpy(height_pattern, "");
|
||||
unsigned char local_source[13];
|
||||
|
||||
error_number = 0;
|
||||
|
||||
@ -383,22 +375,17 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
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(KRSET, local_source, length);
|
||||
to_upper(source);
|
||||
error_number = is_sane(KRSET, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Add leading zeroes */
|
||||
strcpy(localstr, "");
|
||||
zeroes = 11 - length;
|
||||
for(i = 0; i < zeroes; i++)
|
||||
concat(localstr, "0");
|
||||
concat(localstr, (char *)local_source);
|
||||
memset(localstr, '0', zeroes);
|
||||
strcpy(localstr + zeroes, (char *)source);
|
||||
|
||||
/* Encode data */
|
||||
for (i = 0; i < 11; i++) {
|
||||
@ -406,7 +393,8 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
writer = 0;
|
||||
for(loopey = 0; loopey < strlen(height_pattern); loopey++)
|
||||
h = strlen(height_pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
|
||||
{
|
||||
@ -433,8 +421,8 @@ 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! */
|
||||
char height_pattern[100], local_source[55];
|
||||
unsigned int loopey;
|
||||
char height_pattern[100];
|
||||
unsigned int loopey, h;
|
||||
int writer, i, error_number;
|
||||
strcpy(height_pattern, "");
|
||||
|
||||
@ -443,25 +431,24 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
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, length);
|
||||
to_upper((unsigned char*)source);
|
||||
error_number = is_sane(DAFTSET, (unsigned char*)source, length);
|
||||
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
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"); }
|
||||
if(local_source[i] == 'T') { concat(height_pattern, "3"); }
|
||||
if(source[i] == 'D') { concat(height_pattern, "2"); }
|
||||
if(source[i] == 'A') { concat(height_pattern, "1"); }
|
||||
if(source[i] == 'F') { concat(height_pattern, "0"); }
|
||||
if(source[i] == 'T') { concat(height_pattern, "3"); }
|
||||
}
|
||||
|
||||
writer = 0;
|
||||
for(loopey = 0; loopey < strlen(height_pattern); loopey++)
|
||||
h = strlen(height_pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0'))
|
||||
{
|
||||
@ -488,23 +475,22 @@ 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;
|
||||
char dest[1000];
|
||||
char dest[512]; /* 90 * 4 + 1 ~ */
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
if(length > 90) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
*dest = '\0';
|
||||
for(loop = 0; loop < length; loop++) {
|
||||
lookup(NESET, FlatTable, source[loop], dest);
|
||||
lookup(NEON, FlatTable, source[loop], dest);
|
||||
}
|
||||
|
||||
expand(symbol, dest);
|
||||
@ -513,19 +499,16 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length
|
||||
|
||||
int japan_post(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{ /* Japanese Postal Code (Kasutama Barcode) */
|
||||
int error_number;
|
||||
int error_number, h;
|
||||
char pattern[69];
|
||||
int writer, loopey, inter_posn, i, sum, check;
|
||||
char check_char;
|
||||
char inter[23];
|
||||
#ifdef _MSC_VER
|
||||
char* local_source;
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
char local_source[length + 1];
|
||||
#else
|
||||
local_source = (char*)_alloca(length + 1);
|
||||
char* local_source = (char*)_alloca(length + 1);
|
||||
#endif
|
||||
|
||||
inter_posn = 0;
|
||||
@ -542,10 +525,7 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
for(i = 0; i < 20; i++) {
|
||||
inter[i] = 'd'; /* Pad character CC4 */
|
||||
}
|
||||
memset(inter, 'd', 20);/* Pad character CC4 */
|
||||
inter[20] = '\0';
|
||||
|
||||
i = 0;
|
||||
@ -597,7 +577,8 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
/* Resolve pattern to 4-state symbols */
|
||||
writer = 0;
|
||||
for(loopey = 0; loopey < strlen(pattern); loopey++)
|
||||
h = strlen(pattern);
|
||||
for(loopey = 0; loopey < h; loopey++)
|
||||
{
|
||||
if((pattern[loopey] == '2') || (pattern[loopey] == '1'))
|
||||
{
|
||||
|
@ -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, 6);
|
||||
error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
|
||||
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, 6);
|
||||
error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
|
||||
if (error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||
return ERROR_INVALID_OPTION;
|
||||
|
804
backend/qr.c
804
backend/qr.c
@ -1,9 +1,8 @@
|
||||
/* qr.c Handles QR Code by utilising libqrencode */
|
||||
/* qr.c Handles QR Code */
|
||||
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
||||
Copyright (C) 2006 Kentaro Fukuchi <fukuchi@megaui.net>
|
||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
||||
|
||||
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
|
||||
@ -22,123 +21,760 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "common.h"
|
||||
|
||||
#ifndef NO_QR
|
||||
#include <qrencode.h>
|
||||
#include <stdio.h>
|
||||
#include "shiftjis.h"
|
||||
#include "sjis.h"
|
||||
#include "qr.h"
|
||||
#include "qrrs.h"
|
||||
|
||||
QRcode *encode(int security, int size, const unsigned char *intext, int kanji, int gs1, int input_length)
|
||||
int in_alpha(int glyph) {
|
||||
/* Returns true if input glyph is in the Alphanumeric set */
|
||||
int retval = 0;
|
||||
char cglyph = (char) glyph;
|
||||
|
||||
if((cglyph >= '0') && (cglyph <= '9')) {
|
||||
retval = 1;
|
||||
}
|
||||
if((cglyph >= 'A') && (cglyph <= 'Z')) {
|
||||
retval = 1;
|
||||
}
|
||||
switch (cglyph) {
|
||||
case ' ':
|
||||
case '$':
|
||||
case '%':
|
||||
case '*':
|
||||
case '+':
|
||||
case '-':
|
||||
case '.':
|
||||
case '/':
|
||||
case ':':
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void define_mode(char mode[], int jisdata[], int length)
|
||||
{
|
||||
int version;
|
||||
QRecLevel level;
|
||||
QRencodeMode hint;
|
||||
QRcode *code;
|
||||
/* Values placed into mode[] are: K = Kanji, B = Binary, A = Alphanumeric, N = Numeric */
|
||||
int i, mlen, j;
|
||||
|
||||
hint = 0;
|
||||
|
||||
if(kanji) {
|
||||
hint = QR_MODE_KANJI;
|
||||
}
|
||||
/* if(gs1) {
|
||||
hint = QR_MODE_GS1;
|
||||
} - for future expansion */
|
||||
if(hint == 0) {
|
||||
hint = QR_MODE_8;
|
||||
}
|
||||
|
||||
level = QR_ECLEVEL_L;
|
||||
if((security >= 1) && (security <= 4)) {
|
||||
switch (security) {
|
||||
case 1: level = QR_ECLEVEL_L; break;
|
||||
case 2: level = QR_ECLEVEL_M; break;
|
||||
case 3: level = QR_ECLEVEL_Q; break;
|
||||
case 4: level = QR_ECLEVEL_H; break;
|
||||
}
|
||||
}
|
||||
|
||||
if((size >= 1) && (size <= 40)) {
|
||||
version = size;
|
||||
for(i = 0; i < length; i++) {
|
||||
if(jisdata[i] > 0xff) {
|
||||
mode[i] = 'K';
|
||||
} else {
|
||||
version = 0;
|
||||
mode[i] = 'B';
|
||||
if(in_alpha(jisdata[i])) { mode[i] = 'A'; }
|
||||
if((jisdata[i] >= '0') && (jisdata[i] <= '9')) { mode[i] = 'N'; }
|
||||
}
|
||||
}
|
||||
|
||||
code = QRcode_encodeString((char*)intext, version, level, hint, 1);
|
||||
/* If less than 6 numeric digits together then don't use numeric mode */
|
||||
for(i = 0; i < length; i++) {
|
||||
if(mode[i] == 'N') {
|
||||
if(((i != 0) && (mode[i - 1] != 'N')) || (i == 0)) {
|
||||
mlen = 0;
|
||||
while (((mlen + i) < length) && (mode[mlen + i] == 'N')) {
|
||||
mlen++;
|
||||
};
|
||||
if(mlen < 6) {
|
||||
for(j = 0; j < mlen; j++) {
|
||||
mode[i + j] = 'A';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
/* If less than 4 alphanumeric characters together then don't use alphanumeric mode */
|
||||
for(i = 0; i < length; i++) {
|
||||
if(mode[i] == 'A') {
|
||||
if(((i != 0) && (mode[i - 1] != 'A')) || (i == 0)) {
|
||||
mlen = 0;
|
||||
while (((mlen + i) < length) && (mode[mlen + i] == 'A')) {
|
||||
mlen++;
|
||||
};
|
||||
if(mlen < 6) {
|
||||
for(j = 0; j < mlen; j++) {
|
||||
mode[i + j] = 'B';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int estimate_binary_length(char mode[], int length)
|
||||
{
|
||||
/* Make an estimate (worst case scenario) of how long the binary string will be */
|
||||
int i, count = 0;
|
||||
char current = 0;
|
||||
int a_count = 0;
|
||||
int n_count = 0;
|
||||
|
||||
switch(mode[0]) {
|
||||
case 'K': count = 12 + 4; current = 'K'; break;
|
||||
case 'B': count = 16 + 4; current = 'B'; break;
|
||||
case 'A': count = 13 + 4; current = 'A'; break;
|
||||
case 'N': count = 14 + 4; current = 'N'; break;
|
||||
}
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
if(mode[i] != current) {
|
||||
if(current == 'N') {
|
||||
switch(n_count) {
|
||||
case 1: count += 4; break;
|
||||
case 2: count += 7; break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(mode[i]) {
|
||||
case 'K': count += 12 + 4; current = 'K'; break;
|
||||
case 'B': count += 16 + 4; current = 'B'; break;
|
||||
case 'A': count += 13 + 4; current = 'A'; break;
|
||||
case 'N': count += 14 + 4; current = 'N'; break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(mode[i]) {
|
||||
case 'K': count += 13; break;
|
||||
case 'B': count += 8; break;
|
||||
case 'A': a_count++; if((a_count % 2) == 0) { count += 11; a_count = 0; } break;
|
||||
case 'N': n_count++; if((n_count % 3) == 0) { count += 10; n_count = 0; } break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void qr_binary(int datastream[], int version, int target_binlen, char mode[], int jisdata[], int length)
|
||||
{
|
||||
/* Convert input data to a binary stream and add padding */
|
||||
int position = 0, debug = 1;
|
||||
int short_data_block_length, i, scheme;
|
||||
char data_block, padbits;
|
||||
int current_binlen, current_bytes;
|
||||
int toggle;
|
||||
|
||||
#ifndef _MSC_VER
|
||||
char binary[target_binlen * 8];
|
||||
#else
|
||||
char binary = (char *)_alloca(target_binlen * 8);
|
||||
#endif
|
||||
strcpy(binary, "");
|
||||
|
||||
if(version <= 9) {
|
||||
scheme = 1;
|
||||
}
|
||||
if((version >= 10) && (version <= 26)) {
|
||||
scheme = 2;
|
||||
}
|
||||
if(version >= 27) {
|
||||
scheme = 3;
|
||||
}
|
||||
|
||||
if(debug) {
|
||||
for(i = 0; i < length; i++) {
|
||||
printf("%c", mode[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
do {
|
||||
data_block = mode[position];
|
||||
short_data_block_length = 0;
|
||||
do {
|
||||
short_data_block_length++;
|
||||
} while (((short_data_block_length + position) < length) && (mode[position + short_data_block_length] == data_block));
|
||||
|
||||
switch(data_block) {
|
||||
case 'K':
|
||||
/* Kanji mode */
|
||||
/* Mode indicator */
|
||||
concat(binary, "1000");
|
||||
|
||||
/* Character count indicator */
|
||||
switch(scheme) {
|
||||
case 3:
|
||||
if(short_data_block_length & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 2:
|
||||
if(short_data_block_length & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 1:
|
||||
if(short_data_block_length & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
break;
|
||||
}
|
||||
|
||||
if(debug) { printf("Kanji block (length %d)\n\t", short_data_block_length); }
|
||||
|
||||
/* Character representation */
|
||||
for(i = 0; i < short_data_block_length; i++) {
|
||||
int jis = jisdata[position + i];
|
||||
int msb, lsb, prod;
|
||||
|
||||
if(jis > 0x9fff) { jis -= 0xc140; }
|
||||
msb = (jis & 0xff00) >> 4;
|
||||
lsb = (jis & 0xff);
|
||||
prod = (msb * 0xc0) + lsb;
|
||||
|
||||
if(prod & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
|
||||
if(debug) { printf("0x%4X ", prod); }
|
||||
}
|
||||
|
||||
if(debug) { printf("\n"); }
|
||||
|
||||
break;
|
||||
case 'B':
|
||||
/* Byte mode */
|
||||
/* Mode indicator */
|
||||
concat(binary, "0100");
|
||||
|
||||
/* Character count indicator */
|
||||
switch (scheme) {
|
||||
case 3:
|
||||
case 2:
|
||||
if(short_data_block_length & 0x8000) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x4000) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x2000) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 1:
|
||||
if(short_data_block_length & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
break;
|
||||
}
|
||||
|
||||
if(debug) { printf("Byte block (length %d)\n\t", short_data_block_length); }
|
||||
|
||||
/* Character representation */
|
||||
for(i = 0; i < short_data_block_length; i++) {
|
||||
int byte = jisdata[position + i];
|
||||
|
||||
if(byte & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(byte & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(byte & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(byte & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(byte & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(byte & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(byte & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(byte & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
|
||||
if(debug) { printf("0x%4X ", byte); }
|
||||
}
|
||||
|
||||
if(debug) { printf("\n"); }
|
||||
|
||||
break;
|
||||
case 'A':
|
||||
/* Alphanumeric mode */
|
||||
/* Mode indicator */
|
||||
concat(binary, "0010");
|
||||
|
||||
/* Character count indicator */
|
||||
switch (scheme) {
|
||||
case 3:
|
||||
if(short_data_block_length & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 2:
|
||||
if(short_data_block_length & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 1:
|
||||
if(short_data_block_length & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
break;
|
||||
}
|
||||
|
||||
if(debug) { printf("Alpha block (length %d)\n\t", short_data_block_length); }
|
||||
|
||||
/* Character representation */
|
||||
i = 0;
|
||||
while ( i < short_data_block_length ) {
|
||||
int count;
|
||||
int first = 0, second = 0, prod;
|
||||
|
||||
first = posn(RHODIUM, (char) jisdata[position + i]);
|
||||
count = 1;
|
||||
prod = first;
|
||||
|
||||
if(mode[position + i + 1] == 'A') {
|
||||
second = posn(RHODIUM, (char) jisdata[position + i + 1]);
|
||||
count = 2;
|
||||
prod = (first * 45) + second;
|
||||
}
|
||||
|
||||
switch(count) {
|
||||
case 2:
|
||||
if(prod & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 1:
|
||||
if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
break;
|
||||
}
|
||||
|
||||
if(debug) { printf("0x%4X ", prod); }
|
||||
|
||||
i += 2;
|
||||
};
|
||||
|
||||
if(debug) { printf("\n"); }
|
||||
|
||||
break;
|
||||
case 'N':
|
||||
/* Numeric mode */
|
||||
/* Mode indicator */
|
||||
concat(binary, "0001");
|
||||
|
||||
/* Character count indicator */
|
||||
switch (scheme) {
|
||||
case 3:
|
||||
if(short_data_block_length & 0x2000) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 2:
|
||||
if(short_data_block_length & 0x800) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x400) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 1:
|
||||
if(short_data_block_length & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(short_data_block_length & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
break;
|
||||
}
|
||||
|
||||
if(debug) { printf("Number block (length %d)\n\t", short_data_block_length); }
|
||||
|
||||
/* Character representation */
|
||||
i = 0;
|
||||
while ( i < short_data_block_length ) {
|
||||
int count;
|
||||
int first = 0, second = 0, third = 0, prod;
|
||||
|
||||
first = posn(NEON, (char) jisdata[position + i]);
|
||||
count = 1;
|
||||
prod = first;
|
||||
|
||||
if(mode[position + i + 1] == 'N') {
|
||||
second = posn(NEON, (char) jisdata[position + i + 1]);
|
||||
count = 2;
|
||||
prod = (prod * 10) + second;
|
||||
}
|
||||
|
||||
if(mode[position + i + 2] == 'N') {
|
||||
third = posn(NEON, (char) jisdata[position + i + 2]);
|
||||
count = 3;
|
||||
prod = (prod * 10) + third;
|
||||
}
|
||||
|
||||
switch(count) {
|
||||
case 3:
|
||||
if(prod & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x100) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 2:
|
||||
if(prod & 0x40) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x10) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
case 1:
|
||||
if(prod & 0x08) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x04) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
if(prod & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); }
|
||||
break;
|
||||
}
|
||||
|
||||
if(debug) { printf("0x%4X (%d)", prod, prod); }
|
||||
|
||||
i += 3;
|
||||
};
|
||||
|
||||
if(debug) { printf("\n"); }
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
position += short_data_block_length;
|
||||
} while (position < length - 1) ;
|
||||
|
||||
/* Terminator */
|
||||
concat(binary, "0000");
|
||||
|
||||
current_binlen = strlen(binary);
|
||||
padbits = 8 - (current_binlen % 8);
|
||||
if(padbits == 8) { padbits = 0; }
|
||||
current_bytes = (current_binlen + padbits) / 8;
|
||||
|
||||
/* Padding bits */
|
||||
for(i = 0; i < padbits; i++) {
|
||||
concat(binary, "0");
|
||||
}
|
||||
|
||||
/* Put data into 8-bit codewords */
|
||||
for(i = 0; i < current_bytes; i++) {
|
||||
datastream[i] = 0x00;
|
||||
if(binary[i * 8] == '1') { datastream[i] += 0x80; }
|
||||
if(binary[i * 8 + 1] == '1') { datastream[i] += 0x40; }
|
||||
if(binary[i * 8 + 2] == '1') { datastream[i] += 0x20; }
|
||||
if(binary[i * 8 + 3] == '1') { datastream[i] += 0x10; }
|
||||
if(binary[i * 8 + 4] == '1') { datastream[i] += 0x08; }
|
||||
if(binary[i * 8 + 5] == '1') { datastream[i] += 0x04; }
|
||||
if(binary[i * 8 + 6] == '1') { datastream[i] += 0x02; }
|
||||
if(binary[i * 8 + 7] == '1') { datastream[i] += 0x01; }
|
||||
}
|
||||
|
||||
/* Add pad codewords */
|
||||
toggle = 0;
|
||||
for(i = current_bytes; i < target_binlen; i++) {
|
||||
if(toggle == 0) {
|
||||
datastream[i] = 0xec;
|
||||
toggle = 1;
|
||||
} else {
|
||||
datastream[i] = 0x11;
|
||||
toggle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(debug) {
|
||||
for(i = 0; i < target_binlen; i++) {
|
||||
printf("0x%2X ", datastream[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void add_ecc(int fullstream[], int datastream[], int version, int data_cw, int blocks)
|
||||
{
|
||||
/* Split data into blocks, add error correction and then interleave the blocks and error correction data */
|
||||
int ecc_cw = qr_total_codewords[version - 1] - data_cw;
|
||||
int short_data_block_length = data_cw / blocks;
|
||||
int qty_long_blocks = data_cw % blocks;
|
||||
int qty_short_blocks = blocks - qty_long_blocks;
|
||||
int ecc_block_length = ecc_cw / blocks;
|
||||
int i, j, length_this_block, posn, debug = 1;
|
||||
RS *rs;
|
||||
|
||||
|
||||
#ifndef _MSC_VER
|
||||
unsigned char data_block[short_data_block_length + 2];
|
||||
unsigned char ecc_block[ecc_block_length + 2];
|
||||
int interleaved_data[data_cw + 2];
|
||||
int interleaved_ecc[ecc_cw + 2];
|
||||
#else
|
||||
unsigned char data_block = (unsigned char *)_alloca(short_data_block_length + 2);
|
||||
unsigned char ecc_block = (unsigned char *)_alloca(ecc_block_length + 2);
|
||||
int interleaved_data = (int *)_alloca(data_cw + 2);
|
||||
int interleaved_ecc = (int *)_alloca(ecc_cw + 2);
|
||||
#endif
|
||||
|
||||
posn = 0;
|
||||
|
||||
for(i = 0; i < blocks; i++) {
|
||||
if(i < qty_short_blocks) { length_this_block = short_data_block_length; } else { length_this_block = short_data_block_length + 1; }
|
||||
|
||||
for(j = 0; j < ecc_block_length; j++) {
|
||||
ecc_block[j] = 0;
|
||||
}
|
||||
|
||||
for(j = 0; j < length_this_block; j++) {
|
||||
data_block[j] = (unsigned char) datastream[posn + j];
|
||||
}
|
||||
|
||||
rs = init_rs(8, 0x11d, 0, 1, ecc_block_length, 255 - length_this_block - ecc_block_length);
|
||||
encode_rs_char(rs, data_block, ecc_block);
|
||||
|
||||
if(debug) {
|
||||
printf("Block %d: ", i + 1);
|
||||
for(j = 0; j < length_this_block; j++) {
|
||||
printf("%2X ", data_block[j]);
|
||||
}
|
||||
if(i < qty_short_blocks) {
|
||||
printf(" ");
|
||||
}
|
||||
printf(" // ");
|
||||
for(j = 0; j < ecc_block_length; j++) {
|
||||
printf("%2X ", ecc_block[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
for(j = 0; j < short_data_block_length; j++) {
|
||||
interleaved_data[(j * blocks) + i] = (int) data_block[j];
|
||||
}
|
||||
|
||||
if(i >= qty_short_blocks){
|
||||
interleaved_data[(short_data_block_length * blocks) + (i - qty_short_blocks)] = (int) data_block[short_data_block_length];
|
||||
}
|
||||
|
||||
for(j = 0; j < ecc_block_length; j++) {
|
||||
interleaved_ecc[(j * blocks) + i] = (int) ecc_block[j];
|
||||
}
|
||||
|
||||
posn += length_this_block;
|
||||
}
|
||||
free_rs_cache();
|
||||
|
||||
for(j = 0; j < data_cw; j++) {
|
||||
fullstream[j] = interleaved_data[j];
|
||||
}
|
||||
for(j = 0; j < ecc_cw; j++) {
|
||||
fullstream[j + data_cw] = interleaved_ecc[j];
|
||||
}
|
||||
|
||||
if(debug) {
|
||||
printf("\nData Stream: \n");
|
||||
for(j = 0; j < (data_cw + ecc_cw); j++) {
|
||||
printf("%2X ", fullstream[j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void place_finder(unsigned char grid[], int size, int x, int y)
|
||||
{
|
||||
int xp, yp;
|
||||
|
||||
int finder[] = {
|
||||
1, 1, 1, 1, 1, 1, 1,
|
||||
1, 0, 0, 0, 0, 0, 1,
|
||||
1, 0, 1, 1, 1, 0, 1,
|
||||
1, 0, 1, 1, 1, 0, 1,
|
||||
1, 0, 1, 1, 1, 0, 1,
|
||||
1, 0, 0, 0, 0, 0, 1,
|
||||
1, 1, 1, 1, 1, 1, 1
|
||||
};
|
||||
|
||||
for(xp = 0; xp < 7; xp++) {
|
||||
for(yp = 0; yp < 7; yp++) {
|
||||
if (finder[xp + (7 * yp)] == 1) {
|
||||
grid[((yp + y) * size) + (xp + x)] = 0x11;
|
||||
} else {
|
||||
grid[((yp + y) * size) + (xp + x)] = 0x10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup_grid(unsigned char* grid, int size)
|
||||
{
|
||||
int i, toggle = 1;
|
||||
|
||||
for(i = 0; i < size; i++) {
|
||||
if(toggle == 1) {
|
||||
grid[(6 * size) + i] = 0x11;
|
||||
grid[(i * size) + 6] = 0x11;
|
||||
toggle = 0;
|
||||
} else {
|
||||
grid[(6 * size) + i] = 0x10;
|
||||
grid[(i * size) + 6] = 0x10;
|
||||
toggle = 1;
|
||||
}
|
||||
}
|
||||
|
||||
place_finder(grid, size, 0, 0);
|
||||
place_finder(grid, size, 0, size - 7);
|
||||
place_finder(grid, size, size - 7, 0);
|
||||
}
|
||||
|
||||
int qr_code(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
{
|
||||
QRcode *code;
|
||||
int i, j;
|
||||
int kanji, gs1;
|
||||
int error_number;
|
||||
int error_number, i, j, glyph, est_binlen;
|
||||
int ecc_level, autosize, version, max_cw, target_binlen, blocks, size;
|
||||
|
||||
#ifndef _MSC_VER
|
||||
unsigned char local_source[length];
|
||||
int utfdata[length + 1];
|
||||
int jisdata[length + 1];
|
||||
char mode[length + 1];
|
||||
#else
|
||||
unsigned char local_source = (unsigned char*)_alloca(length);
|
||||
int utfdata = (int *)_alloca((length + 1) * sizeof(int));
|
||||
int jisdata = (int *)_alloca((length + 1) * sizeof(int));
|
||||
char mode = (char *)_alloca((length + 1) * sizeof(int));
|
||||
#endif
|
||||
|
||||
if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; }
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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];
|
||||
jisdata[i] = (int)source[i];
|
||||
}
|
||||
local_source[length] = '\0';
|
||||
kanji = 0;
|
||||
break;
|
||||
case UNICODE_MODE:
|
||||
error_number = shiftJIS(symbol, source, local_source, &length, &kanji);
|
||||
default:
|
||||
/* Convert Unicode input to Shift-JIS */
|
||||
error_number = utf8toutf16(symbol, source, utfdata, &length);
|
||||
if(error_number != 0) { return error_number; }
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
if(utfdata[i] <= 0xff) {
|
||||
jisdata[i] = utfdata[i];
|
||||
} else {
|
||||
j = 0;
|
||||
glyph = 0;
|
||||
do {
|
||||
if(sjis_lookup[j * 2] == utfdata[i]) {
|
||||
glyph = sjis_lookup[(j * 2) + 1];
|
||||
}
|
||||
j++;
|
||||
} while ((j < 6843) && (glyph == 0));
|
||||
if(glyph == 0) {
|
||||
strcpy(symbol->errtxt, "Invalid character in input data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
jisdata[i] = glyph;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
define_mode(mode, jisdata, length);
|
||||
est_binlen = estimate_binary_length(mode, length);
|
||||
|
||||
ecc_level = LEVEL_L;
|
||||
max_cw = 2956;
|
||||
if((symbol->option_1 >= 1) && (symbol->option_1 <= 4)) {
|
||||
switch (symbol->option_1) {
|
||||
case 1: ecc_level = LEVEL_L; max_cw = 2956; break;
|
||||
case 2: ecc_level = LEVEL_M; max_cw = 2334; break;
|
||||
case 3: ecc_level = LEVEL_Q; max_cw = 1666; break;
|
||||
case 4: ecc_level = LEVEL_H; max_cw = 1276; break;
|
||||
}
|
||||
}
|
||||
|
||||
symbol->width = code->width;
|
||||
symbol->rows = code->width;
|
||||
if(est_binlen > (8 * max_cw)) {
|
||||
strcpy(symbol->errtxt, "Input too long for selected error correction level");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
for(i = 0; i < code->width; i++) {
|
||||
for(j = 0; j < code->width; j++) {
|
||||
if((*(code->data + (i * code->width) + j) & 0x01) != 0) {
|
||||
autosize = 40;
|
||||
for(i = 39; i >= 0; i--) {
|
||||
switch(ecc_level) {
|
||||
case LEVEL_L:
|
||||
if ((8 * qr_data_codewords_L[i]) >= est_binlen) {
|
||||
autosize = i + 1;
|
||||
}
|
||||
break;
|
||||
case LEVEL_M:
|
||||
if ((8 * qr_data_codewords_M[i]) >= est_binlen) {
|
||||
autosize = i + 1;
|
||||
}
|
||||
break;
|
||||
case LEVEL_Q:
|
||||
if ((8 * qr_data_codewords_Q[i]) >= est_binlen) {
|
||||
autosize = i + 1;
|
||||
}
|
||||
break;
|
||||
case LEVEL_H:
|
||||
if ((8 * qr_data_codewords_H[i]) >= est_binlen) {
|
||||
autosize = i + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if((symbol->option_2 >= 1) && (symbol->option_2 <= 40)) {
|
||||
if (symbol->option_2 > autosize) {
|
||||
version = symbol->option_2;
|
||||
} else {
|
||||
version = autosize;
|
||||
}
|
||||
} else {
|
||||
version = autosize;
|
||||
}
|
||||
|
||||
target_binlen = qr_data_codewords_L[version - 1]; blocks = qr_blocks_L[version - 1];
|
||||
switch(ecc_level) {
|
||||
case LEVEL_M: target_binlen = qr_data_codewords_M[version - 1]; blocks = qr_blocks_M[version - 1]; break;
|
||||
case LEVEL_Q: target_binlen = qr_data_codewords_Q[version - 1]; blocks = qr_blocks_Q[version - 1]; break;
|
||||
case LEVEL_H: target_binlen = qr_data_codewords_H[version - 1]; blocks = qr_blocks_H[version - 1]; break;
|
||||
}
|
||||
|
||||
#ifndef _MSC_VER
|
||||
int datastream[target_binlen + 1];
|
||||
int fullstream[qr_total_codewords[version - 1] + 1];
|
||||
#else
|
||||
int datastream = (int *)_alloca((target_binlen + 1) * sizeof(int));
|
||||
int fullstream = (int *)_alloca((qr_total_codewords[version - 1] + 1) * sizeof(int));
|
||||
#endif
|
||||
|
||||
qr_binary(datastream, version, target_binlen, mode, jisdata, length);
|
||||
add_ecc(fullstream, datastream, version, target_binlen, blocks);
|
||||
|
||||
size = qr_sizes[version - 1];
|
||||
#ifndef _MSC_VER
|
||||
unsigned char grid[size * size];
|
||||
#else
|
||||
unsigned char grid = (unsigned char *)_alloca((size * size) * sizeof(unsigned char));
|
||||
#endif
|
||||
|
||||
for(i = 0; i < size; i++) {
|
||||
for(j = 0; j < size; j++) {
|
||||
grid[(i * size) + j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
setup_grid(grid, size);
|
||||
|
||||
symbol->width = size;
|
||||
symbol->rows = size;
|
||||
|
||||
for(i = 0; i < size; i++) {
|
||||
for(j = 0; j < size; j++) {
|
||||
if(grid[(i * size) + j] & 0x01) {
|
||||
set_module(symbol, i, j);
|
||||
}
|
||||
}
|
||||
symbol->row_height[i] = 1;
|
||||
}
|
||||
|
||||
QRcode_free(code);
|
||||
printf("Version %d: target %d bytes\n", version, target_binlen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
/* Handler if no QR Encode library is available */
|
||||
int qr_code(struct zint_symbol *symbol, unsigned char source[])
|
||||
{
|
||||
strcpy(symbol->errtxt, "QR Code library <qrencode> not available");
|
||||
return ERROR_INVALID_OPTION;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
84
backend/qr.h
Normal file
84
backend/qr.h
Normal file
@ -0,0 +1,84 @@
|
||||
/* qr.h Data for QR Code */
|
||||
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2008 Robin Stuart <robin@zint.org.uk>
|
||||
Copyright (C) 2006 Kentaro Fukuchi <fukuchi@megaui.net>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#define LEVEL_L 1
|
||||
#define LEVEL_M 2
|
||||
#define LEVEL_Q 3
|
||||
#define LEVEL_H 4
|
||||
|
||||
#define RHODIUM "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
|
||||
|
||||
/* From ISO/IEC 18004:2006 Table 7 */
|
||||
static int qr_data_codewords_L[] = {
|
||||
19, 34, 55, 80, 108, 136, 156, 194, 232, 274, 324, 370, 428, 461, 523, 589, 647,
|
||||
721, 795, 861, 932, 1006, 1094, 1174, 1276, 1370, 1468, 1531, 1631,
|
||||
1735, 1843, 1955, 2071, 2191, 2306, 2434, 2566, 2702, 2812, 2956
|
||||
};
|
||||
|
||||
static int qr_data_codewords_M[] = {
|
||||
16, 28, 44, 64, 86, 108, 124, 154, 182, 216, 254, 290, 334, 365, 415, 453, 507,
|
||||
563, 627, 669, 714, 782, 860, 914, 1000, 1062, 1128, 1193, 1267,
|
||||
1373, 1455, 1541, 1631, 1725, 1812, 1914, 1992, 2102, 2216, 2334
|
||||
};
|
||||
|
||||
static int qr_data_codewords_Q[] = {
|
||||
13, 22, 34, 48, 62, 76, 88, 110, 132, 154, 180, 206, 244, 261, 295, 325, 367,
|
||||
397, 445, 485, 512, 568, 614, 664, 718, 754, 808, 871, 911,
|
||||
985, 1033, 1115, 1171, 1231, 1286, 1354, 1426, 1502, 1582, 1666
|
||||
};
|
||||
|
||||
static int qr_data_codewords_H[] = {
|
||||
9, 16, 26, 36, 46, 60, 66, 86, 100, 122, 140, 158, 180, 197, 223, 253, 283,
|
||||
313, 341, 385, 406, 442, 464, 514, 538, 596, 628, 661, 701,
|
||||
745, 793, 845, 901, 961, 986, 1054, 1096, 1142, 1222, 1276
|
||||
};
|
||||
|
||||
static int qr_total_codewords[] = {
|
||||
26, 44, 70, 100, 134, 172, 196, 242, 292, 346, 404, 466, 532, 581, 655, 733, 815,
|
||||
901, 991, 1085, 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051,
|
||||
2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
|
||||
};
|
||||
|
||||
static int qr_blocks_L[] = {
|
||||
1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25
|
||||
};
|
||||
|
||||
static int qr_blocks_M[] = {
|
||||
1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20,
|
||||
21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49
|
||||
};
|
||||
|
||||
static int qr_blocks_Q[] = {
|
||||
1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25,
|
||||
27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68
|
||||
};
|
||||
|
||||
static int qr_blocks_H[] = {
|
||||
1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30,
|
||||
32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81
|
||||
};
|
||||
|
||||
static int qr_sizes[] = {
|
||||
21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97,
|
||||
101, 105, 109, 113, 117, 121, 125, 129, 133, 137, 141, 145, 149, 153, 157, 161, 165, 169, 173, 177
|
||||
};
|
310
backend/qrrs.c
Normal file
310
backend/qrrs.c
Normal file
@ -0,0 +1,310 @@
|
||||
/* qrrs.c - Reed Solomon routines for QR Code
|
||||
|
||||
This file pinched wholesale from libqrencode and unchanged hence
|
||||
original copyright and license applies as below
|
||||
*/
|
||||
|
||||
/*
|
||||
* qrencode - QR Code encoder
|
||||
*
|
||||
* Reed solomon encoder. This code is taken from Phil Karn's libfec then
|
||||
* editted and packed into a pair of .c and .h files.
|
||||
*
|
||||
* Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
|
||||
* (libfec is released under the GNU Lesser General Public License.)
|
||||
*
|
||||
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "qrrs.h"
|
||||
|
||||
/* Stuff specific to the 8-bit symbol version of the general purpose RS codecs
|
||||
*
|
||||
*/
|
||||
typedef unsigned char data_t;
|
||||
|
||||
|
||||
/**
|
||||
* Reed-Solomon codec control block
|
||||
*/
|
||||
struct _RS {
|
||||
int mm; /* Bits per symbol */
|
||||
int nn; /* Symbols per block (= (1<<mm)-1) */
|
||||
data_t *alpha_to; /* log lookup table */
|
||||
data_t *index_of; /* Antilog lookup table */
|
||||
data_t *genpoly; /* Generator polynomial */
|
||||
int nroots; /* Number of generator roots = number of parity symbols */
|
||||
int fcr; /* First consecutive root, index form */
|
||||
int prim; /* Primitive element, index form */
|
||||
int iprim; /* prim-th root of 1, index form */
|
||||
int pad; /* Padding bytes in shortened block */
|
||||
int gfpoly;
|
||||
struct _RS *next;
|
||||
};
|
||||
|
||||
static RS *rslist = NULL;
|
||||
|
||||
static inline int modnn(RS *rs, int x){
|
||||
while (x >= rs->nn) {
|
||||
x -= rs->nn;
|
||||
x = (x >> rs->mm) + (x & rs->nn);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
#define MODNN(x) modnn(rs,x)
|
||||
|
||||
#define MM (rs->mm)
|
||||
#define NN (rs->nn)
|
||||
#define ALPHA_TO (rs->alpha_to)
|
||||
#define INDEX_OF (rs->index_of)
|
||||
#define GENPOLY (rs->genpoly)
|
||||
#define NROOTS (rs->nroots)
|
||||
#define FCR (rs->fcr)
|
||||
#define PRIM (rs->prim)
|
||||
#define IPRIM (rs->iprim)
|
||||
#define PAD (rs->pad)
|
||||
#define A0 (NN)
|
||||
|
||||
|
||||
/* Initialize a Reed-Solomon codec
|
||||
* symsize = symbol size, bits
|
||||
* gfpoly = Field generator polynomial coefficients
|
||||
* fcr = first root of RS code generator polynomial, index form
|
||||
* prim = primitive element to generate polynomial roots
|
||||
* nroots = RS code generator polynomial degree (number of roots)
|
||||
* pad = padding bytes at front of shortened block
|
||||
*/
|
||||
static RS *init_rs_char(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad)
|
||||
{
|
||||
RS *rs;
|
||||
|
||||
|
||||
/* Common code for intializing a Reed-Solomon control block (char or int symbols)
|
||||
* Copyright 2004 Phil Karn, KA9Q
|
||||
* May be used under the terms of the GNU Lesser General Public License (LGPL)
|
||||
*/
|
||||
//#undef NULL
|
||||
//#define NULL ((void *)0)
|
||||
|
||||
int i, j, sr,root,iprim;
|
||||
|
||||
rs = NULL;
|
||||
/* Check parameter ranges */
|
||||
if(symsize < 0 || symsize > (int)(8*sizeof(data_t))){
|
||||
goto done;
|
||||
}
|
||||
|
||||
if(fcr < 0 || fcr >= (1<<symsize))
|
||||
goto done;
|
||||
if(prim <= 0 || prim >= (1<<symsize))
|
||||
goto done;
|
||||
if(nroots < 0 || nroots >= (1<<symsize))
|
||||
goto done; /* Can't have more roots than symbol values! */
|
||||
if(pad < 0 || pad >= ((1<<symsize) -1 - nroots))
|
||||
goto done; /* Too much padding */
|
||||
|
||||
rs = (RS *)calloc(1,sizeof(RS));
|
||||
if(rs == NULL)
|
||||
goto done;
|
||||
|
||||
rs->mm = symsize;
|
||||
rs->nn = (1<<symsize)-1;
|
||||
rs->pad = pad;
|
||||
|
||||
rs->alpha_to = (data_t *)malloc(sizeof(data_t)*(rs->nn+1));
|
||||
if(rs->alpha_to == NULL){
|
||||
free(rs);
|
||||
rs = NULL;
|
||||
goto done;
|
||||
}
|
||||
rs->index_of = (data_t *)malloc(sizeof(data_t)*(rs->nn+1));
|
||||
if(rs->index_of == NULL){
|
||||
free(rs->alpha_to);
|
||||
free(rs);
|
||||
rs = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Generate Galois field lookup tables */
|
||||
rs->index_of[0] = A0; /* log(zero) = -inf */
|
||||
rs->alpha_to[A0] = 0; /* alpha**-inf = 0 */
|
||||
sr = 1;
|
||||
for(i=0;i<rs->nn;i++){
|
||||
rs->index_of[sr] = i;
|
||||
rs->alpha_to[i] = sr;
|
||||
sr <<= 1;
|
||||
if(sr & (1<<symsize))
|
||||
sr ^= gfpoly;
|
||||
sr &= rs->nn;
|
||||
}
|
||||
if(sr != 1){
|
||||
/* field generator polynomial is not primitive! */
|
||||
free(rs->alpha_to);
|
||||
free(rs->index_of);
|
||||
free(rs);
|
||||
rs = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Form RS code generator polynomial from its roots */
|
||||
rs->genpoly = (data_t *)malloc(sizeof(data_t)*(nroots+1));
|
||||
if(rs->genpoly == NULL){
|
||||
free(rs->alpha_to);
|
||||
free(rs->index_of);
|
||||
free(rs);
|
||||
rs = NULL;
|
||||
goto done;
|
||||
}
|
||||
rs->fcr = fcr;
|
||||
rs->prim = prim;
|
||||
rs->nroots = nroots;
|
||||
rs->gfpoly = gfpoly;
|
||||
|
||||
/* Find prim-th root of 1, used in decoding */
|
||||
for(iprim=1;(iprim % prim) != 0;iprim += rs->nn)
|
||||
;
|
||||
rs->iprim = iprim / prim;
|
||||
|
||||
rs->genpoly[0] = 1;
|
||||
for (i = 0,root=fcr*prim; i < nroots; i++,root += prim) {
|
||||
rs->genpoly[i+1] = 1;
|
||||
|
||||
/* Multiply rs->genpoly[] by @**(root + x) */
|
||||
for (j = i; j > 0; j--){
|
||||
if (rs->genpoly[j] != 0)
|
||||
rs->genpoly[j] = rs->genpoly[j-1] ^ rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[j]] + root)];
|
||||
else
|
||||
rs->genpoly[j] = rs->genpoly[j-1];
|
||||
}
|
||||
/* rs->genpoly[0] can never be zero */
|
||||
rs->genpoly[0] = rs->alpha_to[modnn(rs,rs->index_of[rs->genpoly[0]] + root)];
|
||||
}
|
||||
/* convert rs->genpoly[] to index form for quicker encoding */
|
||||
for (i = 0; i <= nroots; i++)
|
||||
rs->genpoly[i] = rs->index_of[rs->genpoly[i]];
|
||||
done:;
|
||||
|
||||
return rs;
|
||||
}
|
||||
|
||||
RS *init_rs(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad)
|
||||
{
|
||||
RS *rs;
|
||||
|
||||
for(rs = rslist; rs != NULL; rs = rs->next) {
|
||||
if(rs->pad != pad) continue;
|
||||
if(rs->nroots != nroots) continue;
|
||||
if(rs->mm != symsize) continue;
|
||||
if(rs->gfpoly != gfpoly) continue;
|
||||
if(rs->fcr != fcr) continue;
|
||||
if(rs->prim != prim) continue;
|
||||
|
||||
goto DONE;
|
||||
}
|
||||
|
||||
rs = init_rs_char(symsize, gfpoly, fcr, prim, nroots, pad);
|
||||
if(rs == NULL) goto DONE;
|
||||
rs->next = rslist;
|
||||
rslist = rs;
|
||||
|
||||
DONE:
|
||||
return rs;
|
||||
}
|
||||
|
||||
|
||||
void free_rs_char(RS *rs)
|
||||
{
|
||||
free(rs->alpha_to);
|
||||
free(rs->index_of);
|
||||
free(rs->genpoly);
|
||||
free(rs);
|
||||
}
|
||||
|
||||
void free_rs_cache(void)
|
||||
{
|
||||
RS *rs, *next;
|
||||
|
||||
rs = rslist;
|
||||
while(rs != NULL) {
|
||||
next = rs->next;
|
||||
free_rs_char(rs);
|
||||
rs = next;
|
||||
}
|
||||
}
|
||||
|
||||
/* The guts of the Reed-Solomon encoder, meant to be #included
|
||||
* into a function body with the following typedefs, macros and variables supplied
|
||||
* according to the code parameters:
|
||||
|
||||
* data_t - a typedef for the data symbol
|
||||
* data_t data[] - array of NN-NROOTS-PAD and type data_t to be encoded
|
||||
* data_t parity[] - an array of NROOTS and type data_t to be written with parity symbols
|
||||
* NROOTS - the number of roots in the RS code generator polynomial,
|
||||
* which is the same as the number of parity symbols in a block.
|
||||
Integer variable or literal.
|
||||
*
|
||||
* NN - the total number of symbols in a RS block. Integer variable or literal.
|
||||
* PAD - the number of pad symbols in a block. Integer variable or literal.
|
||||
* ALPHA_TO - The address of an array of NN elements to convert Galois field
|
||||
* elements in index (log) form to polynomial form. Read only.
|
||||
* INDEX_OF - The address of an array of NN elements to convert Galois field
|
||||
* elements in polynomial form to index (log) form. Read only.
|
||||
* MODNN - a function to reduce its argument modulo NN. May be inline or a macro.
|
||||
* GENPOLY - an array of NROOTS+1 elements containing the generator polynomial in index form
|
||||
|
||||
* The memset() and memmove() functions are used. The appropriate header
|
||||
* file declaring these functions (usually <string.h>) must be included by the calling
|
||||
* program.
|
||||
|
||||
* Copyright 2004, Phil Karn, KA9Q
|
||||
* May be used under the terms of the GNU Lesser General Public License (LGPL)
|
||||
*/
|
||||
|
||||
#undef A0
|
||||
#define A0 (NN) /* Special reserved value encoding zero in index form */
|
||||
|
||||
void encode_rs_char(RS *rs, const data_t *data, data_t *parity)
|
||||
{
|
||||
int i, j;
|
||||
data_t feedback;
|
||||
|
||||
memset(parity,0,NROOTS*sizeof(data_t));
|
||||
|
||||
for(i=0;i<NN-NROOTS-PAD;i++){
|
||||
feedback = INDEX_OF[data[i] ^ parity[0]];
|
||||
if(feedback != A0){ /* feedback term is non-zero */
|
||||
#ifdef UNNORMALIZED
|
||||
/* This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
|
||||
* always be for the polynomials constructed by init_rs()
|
||||
*/
|
||||
feedback = MODNN(NN - GENPOLY[NROOTS] + feedback);
|
||||
#endif
|
||||
for(j=1;j<NROOTS;j++)
|
||||
parity[j] ^= ALPHA_TO[MODNN(feedback + GENPOLY[NROOTS-j])];
|
||||
}
|
||||
/* Shift */
|
||||
memmove(&parity[0],&parity[1],sizeof(data_t)*(NROOTS-1));
|
||||
if(feedback != A0)
|
||||
parity[NROOTS-1] = ALPHA_TO[MODNN(feedback + GENPOLY[0])];
|
||||
else
|
||||
parity[NROOTS-1] = 0;
|
||||
}
|
||||
}
|
48
backend/qrrs.h
Normal file
48
backend/qrrs.h
Normal file
@ -0,0 +1,48 @@
|
||||
/* qrrs.h - Reed Solomon routines for QR Code
|
||||
|
||||
This file pinched wholesale from libqrencode and unchanged hence
|
||||
original copyright and license applies as below
|
||||
*/
|
||||
|
||||
/*
|
||||
* qrencode - QR Code encoder
|
||||
*
|
||||
* Reed solomon encoder. This code is taken from Phil Karn's libfec then
|
||||
* editted and packed into a pair of .c and .h files.
|
||||
*
|
||||
* Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
|
||||
* (libfec is released under the GNU Lesser General Public License.)
|
||||
*
|
||||
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __QRRS_H__
|
||||
#define __QRRS_H__
|
||||
|
||||
/*
|
||||
* General purpose RS codec, 8-bit symbols.
|
||||
*/
|
||||
|
||||
typedef struct _RS RS;
|
||||
|
||||
/* WARNING: Thread unsafe!!! */
|
||||
extern RS *init_rs(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad);
|
||||
extern void encode_rs_char(RS *rs, const unsigned char *data, unsigned char *parity);
|
||||
extern void free_rs_char(RS *rs);
|
||||
extern void free_rs_cache(void);
|
||||
|
||||
#endif /* __QRRS_H__ */
|
@ -22,10 +22,19 @@
|
||||
#ifndef __REEDSOL_H
|
||||
#define __REEDSOL_H
|
||||
|
||||
void rs_init_gf(int poly);
|
||||
void rs_init_code(int nsym, int index);
|
||||
void rs_encode(int len, unsigned char *data, unsigned char *res);
|
||||
void rs_encode_long(int len, unsigned int *data, unsigned int *res);
|
||||
void rs_free();
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern void rs_init_gf(int poly);
|
||||
extern void rs_init_code(int nsym, int index);
|
||||
extern void rs_encode(int len, unsigned char *data, unsigned char *res);
|
||||
extern void rs_encode_long(int len, unsigned int *data, unsigned int *res);
|
||||
extern void rs_free(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __REEDSOL_H */
|
||||
|
134
backend/rss.c
134
backend/rss.c
@ -142,22 +142,22 @@ void getRSSwidths(int val, int n, int elements, int maxWidth, int noNarrow)
|
||||
return;
|
||||
}
|
||||
|
||||
int rss14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int rss14(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
||||
{ /* 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];
|
||||
int data_character[4], data_group[4], v_odd[4], v_even[4];
|
||||
int data_widths[8][4], checksum, c_left, c_right, total_widths[46], writer;
|
||||
char latch, hrt[15];
|
||||
char latch, hrt[15], temp[32];
|
||||
int check_digit, count, separator_row;
|
||||
|
||||
separator_row = 0;
|
||||
|
||||
if(length > 13) {
|
||||
if(src_len > 13) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, src_len);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
@ -185,11 +185,11 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
data_group[i] = 0;
|
||||
}
|
||||
|
||||
binary_load(accum, (char*)source);
|
||||
|
||||
binary_load(accum, (char*)source, src_len);
|
||||
strcpy(temp, "10000000000000");
|
||||
if(symbol->option_1 == 2) {
|
||||
/* Add symbol linkage flag */
|
||||
binary_load(y_reg, "10000000000000");
|
||||
binary_load(y_reg, temp, strlen(temp));
|
||||
binary_add(accum, y_reg);
|
||||
for(i = 0; i < 112; i++) {
|
||||
y_reg[i] = 0;
|
||||
@ -197,7 +197,8 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Calculate left and right pair values */
|
||||
binary_load(x_reg, "4537077");
|
||||
strcpy(temp, "4537077");
|
||||
binary_load(x_reg, temp, strlen(temp));
|
||||
|
||||
for(i = 0; i < 24; i++) {
|
||||
shiftup(x_reg);
|
||||
@ -217,7 +218,8 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Calculate four data characters */
|
||||
binary_load(x_reg, "1597");
|
||||
strcpy(temp, "1597");
|
||||
binary_load(x_reg, temp, strlen(temp));
|
||||
for(i = 0; i < 112; i++) {
|
||||
accum[i] = left_reg[i];
|
||||
}
|
||||
@ -246,8 +248,8 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
mask = mask >> 1;
|
||||
}
|
||||
|
||||
binary_load(x_reg, "1597");
|
||||
strcpy(temp, "1597");
|
||||
binary_load(x_reg, temp, strlen(temp));
|
||||
for(i = 0; i < 112; i++) {
|
||||
accum[i] = right_reg[i];
|
||||
}
|
||||
@ -431,8 +433,8 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
for(i = 0; i < 14; i++) {
|
||||
hrt[i] = '0';
|
||||
}
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
hrt[12 - i] = source[ustrlen(source) - i - 1];
|
||||
for(i = 0; i < src_len; i++) {
|
||||
hrt[12 - i] = source[src_len - i - 1];
|
||||
}
|
||||
hrt[14] = '\0';
|
||||
|
||||
@ -651,28 +653,28 @@ int rss14(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int rsslimited(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
||||
{ /* 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];
|
||||
int left_group, right_group, left_odd, left_even, right_odd, right_even;
|
||||
int left_character, right_character, left_widths[14], right_widths[14];
|
||||
int checksum, check_elements[14], total_widths[46], writer, j, check_digit, count;
|
||||
char latch, hrt[15];
|
||||
char latch, hrt[15], temp[32];
|
||||
int separator_row;
|
||||
|
||||
separator_row = 0;
|
||||
|
||||
if(length > 13) {
|
||||
if(src_len > 13) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
error_number = is_sane(NESET, source, length);
|
||||
error_number = is_sane(NEON, source, src_len);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
if(length == 13) {
|
||||
if(src_len == 13) {
|
||||
if((source[0] != '0') && (source[0] != '1')) {
|
||||
strcpy(symbol->errtxt, "Input out of range");
|
||||
return ERROR_INVALID_DATA;
|
||||
@ -692,10 +694,11 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
y_reg[i] = 0;
|
||||
}
|
||||
|
||||
binary_load(accum, (char*)source);
|
||||
binary_load(accum, (char*)source, src_len);
|
||||
if(symbol->option_1 == 2) {
|
||||
/* Add symbol linkage flag */
|
||||
binary_load(y_reg, "2015133531096");
|
||||
strcpy(temp, "2015133531096");
|
||||
binary_load(y_reg, temp, strlen(temp));
|
||||
binary_add(accum, y_reg);
|
||||
for(i = 0; i < 112; i++) {
|
||||
y_reg[i] = 0;
|
||||
@ -703,7 +706,8 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Calculate left and right pair values */
|
||||
binary_load(x_reg, "2013571");
|
||||
strcpy(temp, "2013571");
|
||||
binary_load(x_reg, temp, strlen(temp));
|
||||
|
||||
for(i = 0; i < 24; i++) {
|
||||
shiftup(x_reg);
|
||||
@ -723,70 +727,94 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
left_group = 0;
|
||||
binary_load(accum, "183063");
|
||||
strcpy(temp, "183063");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(left_reg, accum)) { left_group = 1; }
|
||||
binary_load(accum, "820063");
|
||||
strcpy(temp, "820063");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(left_reg, accum)) { left_group = 2; }
|
||||
binary_load(accum, "1000775");
|
||||
strcpy(temp, "1000775");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(left_reg, accum)) { left_group = 3; }
|
||||
binary_load(accum, "1491020");
|
||||
strcpy(temp, "1491020");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(left_reg, accum)) { left_group = 4; }
|
||||
binary_load(accum, "1979844");
|
||||
strcpy(temp, "1979844");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(left_reg, accum)) { left_group = 5; }
|
||||
binary_load(accum, "1996938");
|
||||
strcpy(temp, "1996938");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(left_reg, accum)) { left_group = 6; }
|
||||
right_group = 0;
|
||||
binary_load(accum, "183063");
|
||||
strcpy(temp, "183063");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(right_reg, accum)) { right_group = 1; }
|
||||
binary_load(accum, "820063");
|
||||
strcpy(temp, "820063");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(right_reg, accum)) { right_group = 2; }
|
||||
binary_load(accum, "1000775");
|
||||
strcpy(temp, "1000775");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(right_reg, accum)) { right_group = 3; }
|
||||
binary_load(accum, "1491020");
|
||||
strcpy(temp, "1491020");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(right_reg, accum)) { right_group = 4; }
|
||||
binary_load(accum, "1979844");
|
||||
strcpy(temp, "1979844");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(right_reg, accum)) { right_group = 5; }
|
||||
binary_load(accum, "1996938");
|
||||
strcpy(temp, "1996938");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
if(islarger(right_reg, accum)) { right_group = 6; }
|
||||
|
||||
switch(left_group) {
|
||||
case 1: binary_load(accum, "183064");
|
||||
case 1: strcpy(temp, "183064");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(left_reg, accum);
|
||||
break;
|
||||
case 2: binary_load(accum, "820064");
|
||||
case 2: strcpy(temp, "820064");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(left_reg, accum);
|
||||
break;
|
||||
case 3: binary_load(accum, "1000776");
|
||||
case 3: strcpy(temp, "1000776");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(left_reg, accum);
|
||||
break;
|
||||
case 4: binary_load(accum, "1491021");
|
||||
case 4: strcpy(temp, "1491021");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(left_reg, accum);
|
||||
break;
|
||||
case 5: binary_load(accum, "1979845");
|
||||
case 5: strcpy(temp, "1979845");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(left_reg, accum);
|
||||
break;
|
||||
case 6: binary_load(accum, "1996939");
|
||||
case 6: strcpy(temp, "1996939");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(left_reg, accum);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(right_group) {
|
||||
case 1: binary_load(accum, "183064");
|
||||
case 1: strcpy(temp, "183064");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(right_reg, accum);
|
||||
break;
|
||||
case 2: binary_load(accum, "820064");
|
||||
case 2: strcpy(temp, "820064");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(right_reg, accum);
|
||||
break;
|
||||
case 3: binary_load(accum, "1000776");
|
||||
case 3: strcpy(temp, "1000776");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(right_reg, accum);
|
||||
break;
|
||||
case 4: binary_load(accum, "1491021");
|
||||
case 4: strcpy(temp, "1491021");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(right_reg, accum);
|
||||
break;
|
||||
case 5: binary_load(accum, "1979845");
|
||||
case 5: strcpy(temp, "1979845");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(right_reg, accum);
|
||||
break;
|
||||
case 6: binary_load(accum, "1996939");
|
||||
case 6: strcpy(temp, "1996939");
|
||||
binary_load(accum, temp, strlen(temp));
|
||||
binary_subtract(right_reg, accum);
|
||||
break;
|
||||
}
|
||||
@ -898,8 +926,8 @@ int rsslimited(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
for(i = 0; i < 14; i++) {
|
||||
hrt[i] = '0';
|
||||
}
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
hrt[12 - i] = source[ustrlen(source) - i - 1];
|
||||
for(i = 0; i < src_len; i++) {
|
||||
hrt[12 - i] = source[src_len - i - 1];
|
||||
}
|
||||
|
||||
for (i = 0; i < 13; i++)
|
||||
@ -1858,7 +1886,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 length)
|
||||
int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
||||
{ /* 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 +1896,10 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int codeblocks, sub_elements[235], stack_rows, current_row, current_block;
|
||||
int separator_row;
|
||||
#ifndef _MSC_VER
|
||||
char reduced[length], binary_string[7 * length];
|
||||
char reduced[src_len], binary_string[7 * src_len];
|
||||
#else
|
||||
char* reduced = (char*)_alloca(length);
|
||||
char* binary_string = (char*)_alloca(7 * length);
|
||||
char* reduced = (char*)_alloca(src_len);
|
||||
char* binary_string = (char*)_alloca(7 * src_len);
|
||||
#endif
|
||||
|
||||
separator_row = 0;
|
||||
@ -1879,7 +1907,7 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
|
||||
if(symbol->input_mode != GS1_MODE) {
|
||||
/* GS1 data has not been verified yet */
|
||||
i = gs1_verify(symbol, source, reduced);
|
||||
i = gs1_verify(symbol, source, src_len, reduced);
|
||||
if(i != 0) { return i; }
|
||||
}
|
||||
|
||||
@ -2060,7 +2088,7 @@ int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
|
||||
/* Add human readable text */
|
||||
for(i = 0; i <= ustrlen(source); i++) {
|
||||
for(i = 0; i <= src_len; i++) {
|
||||
if((source[i] != '[') && (source[i] != ']')) {
|
||||
symbol->text[i] = source[i];
|
||||
} else {
|
||||
|
@ -1,118 +0,0 @@
|
||||
/* shiftjis.c - Handle conversion to Shift-JIS */
|
||||
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
||||
|
||||
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 <string.h>
|
||||
#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;
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/* shiftjis.h - Handle conversion to Shift-JIS */
|
||||
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2009 Robin Stuart <robin@zint.org.uk>
|
||||
|
||||
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
|
@ -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, 6);
|
||||
error_number = is_sane(SSET, (unsigned char*)symbol->fgcolour, strlen(symbol->fgcolour));
|
||||
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, 6);
|
||||
error_number = is_sane(SSET, (unsigned char*)symbol->bgcolour, strlen(symbol->bgcolour));
|
||||
if (error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Malformed background colour target");
|
||||
return ERROR_INVALID_OPTION;
|
||||
|
@ -19,65 +19,55 @@
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#define NASET "0123456789X"
|
||||
#define SODIUM "0123456789X"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
|
||||
static char *TeleTable[] = { "1111111111111111", "1131313111", "33313111", "1111313131",
|
||||
"3111313111", "11333131", "13133131", "111111313111", "31333111", "1131113131", "33113131",
|
||||
"1111333111", "3111113131", "1113133111", "1311133111", "111111113131", "3131113111",
|
||||
"11313331", "333331", "111131113111", "31113331", "1133113111", "1313113111", "1111113331",
|
||||
"31131331", "113111113111", "3311113111", "1111131331", "311111113111", "1113111331",
|
||||
"1311111331", "11111111113111", "31313311", "1131311131", "33311131", "1111313311",
|
||||
"3111311131", "11333311", "13133311", "111111311131", "31331131", "1131113311", "33113311",
|
||||
"1111331131", "3111113311", "1113131131", "1311131131", "111111113311", "3131111131",
|
||||
"1131131311", "33131311", "111131111131", "3111131311", "1133111131", "1313111131",
|
||||
"111111131311", "3113111311", "113111111131", "3311111131", "111113111311", "311111111131",
|
||||
"111311111311", "131111111311", "11111111111131", "3131311111", "11313133", "333133",
|
||||
"111131311111", "31113133", "1133311111", "1313311111", "1111113133", "313333",
|
||||
"113111311111", "3311311111", "11113333", "311111311111", "11131333", "13111333",
|
||||
"11111111311111", "31311133", "1131331111", "33331111", "1111311133", "3111331111",
|
||||
"11331133", "13131133", "111111331111", "3113131111", "1131111133", "33111133",
|
||||
"111113131111", "3111111133", "111311131111", "131111131111", "111111111133", "31311313",
|
||||
"113131111111", "3331111111", "1111311313", "311131111111", "11331313", "13131313",
|
||||
"11111131111111", "3133111111", "1131111313", "33111313", "111133111111", "3111111313",
|
||||
"111313111111", "131113111111", "111111111313", "313111111111", "1131131113", "33131113",
|
||||
"11113111111111", "3111131113", "113311111111", "131311111111", "111111131113", "3113111113",
|
||||
"11311111111111", "331111111111", "111113111113", "31111111111111", "111311111113",
|
||||
"131111111113"};
|
||||
static char *TeleTable[] =
|
||||
{
|
||||
"1111111111111111", "1131313111", "33313111", "1111313131", "3111313111", "11333131", "13133131", "111111313111",
|
||||
"31333111", "1131113131", "33113131", "1111333111", "3111113131", "1113133111", "1311133111", "111111113131",
|
||||
"3131113111", "11313331", "333331", "111131113111", "31113331", "1133113111", "1313113111", "1111113331",
|
||||
"31131331", "113111113111", "3311113111", "1111131331", "311111113111", "1113111331", "1311111331", "11111111113111",
|
||||
"31313311", "1131311131", "33311131", "1111313311", "3111311131", "11333311", "13133311", "111111311131",
|
||||
"31331131", "1131113311", "33113311", "1111331131", "3111113311", "1113131131", "1311131131", "111111113311",
|
||||
"3131111131", "1131131311", "33131311", "111131111131", "3111131311", "1133111131", "1313111131", "111111131311",
|
||||
"3113111311", "113111111131", "3311111131", "111113111311", "311111111131", "111311111311", "131111111311", "11111111111131",
|
||||
"3131311111", "11313133", "333133", "111131311111", "31113133", "1133311111", "1313311111", "1111113133",
|
||||
"313333", "113111311111", "3311311111", "11113333", "311111311111", "11131333", "13111333", "11111111311111",
|
||||
"31311133", "1131331111", "33331111", " 1111311133", "3111331111", "11331133", "13131133", "111111331111",
|
||||
"3113131111", "1131111133", "33111133", "111113131111", "3111111133", "111311131111", "131111131111", "111111111133",
|
||||
"31311313", "113131111111", "3331111111", "1111311313", "311131111111", "11331313", "13131313", "11111131111111",
|
||||
"3133111111", "1131111313", "33111313", "111133111111", "3111111313", "111313111111", "131113111111", "111111111313",
|
||||
"313111111111", "1131131113", "33131113", "11113111111111","3111131113", "113311111111", "131311111111", "111111131113",
|
||||
"3113111113", "11311111111111","331111111111","111113111113", "31111111111111","111311111113","131111111113"};
|
||||
|
||||
int telepen(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int telepen(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
||||
{
|
||||
unsigned int i, count, check_digit;
|
||||
int error_number;
|
||||
char dest[1000];
|
||||
char dest[512]; /*14 + 30 * 14 + 14 + 14 + 1 ~ 512 */
|
||||
|
||||
error_number = 0;
|
||||
strcpy(dest, "");
|
||||
|
||||
count = 0;
|
||||
|
||||
if(length > 30) {
|
||||
if(src_len > 30) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
/* Start character */
|
||||
strcpy(dest, TeleTable['_']);
|
||||
|
||||
for(i = 0; i < length; i++) {
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if(source[i] > 127) {
|
||||
/* Cannot encode extended ASCII */
|
||||
strcpy(symbol->errtxt, "Invalid characters in input data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start character */
|
||||
concat(dest, TeleTable['_']);
|
||||
|
||||
for (i=0; i < length; i++)
|
||||
{
|
||||
concat(dest, TeleTable[source[i]]);
|
||||
count += source[i];
|
||||
}
|
||||
@ -90,89 +80,78 @@ int telepen(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
concat(dest, TeleTable['z']);
|
||||
|
||||
expand(symbol, dest);
|
||||
for(i = 0; i < length; i++) {
|
||||
for(i = 0; i < src_len; i++) {
|
||||
if(source[i] == '\0') {
|
||||
symbol->text[i] = ' ';
|
||||
} else {
|
||||
symbol->text[i] = source[i];
|
||||
}
|
||||
}
|
||||
symbol->text[length] = '\0';
|
||||
symbol->text[src_len] = '\0';
|
||||
return error_number;
|
||||
}
|
||||
|
||||
int telepen_num(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int telepen_num(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
||||
{
|
||||
unsigned int i, count, check_digit, glyph;
|
||||
int error_number;
|
||||
unsigned char dest[1000];
|
||||
unsigned char local_source[100];
|
||||
int error_number, temp_length = src_len;
|
||||
char dest[1024]; /* 14 + 60 * 14 + 14 + 14 + 1 ~ 1024 */
|
||||
unsigned char temp[64];
|
||||
|
||||
error_number = 0;
|
||||
memset(dest, 0, 1000);
|
||||
memset(local_source, 0, 100);
|
||||
|
||||
count = 0;
|
||||
|
||||
if(length > 60) {
|
||||
if(temp_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, length);
|
||||
ustrcpy(temp, source);
|
||||
to_upper(temp);
|
||||
error_number = is_sane(NEON, temp, temp_length);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Add a leading zero if required */
|
||||
if ((length % 2) != 0)
|
||||
if ((temp_length % 2) != 0)
|
||||
{
|
||||
char temp[200];
|
||||
memmove(temp + 1, temp, temp_length);
|
||||
temp[0] = '0';
|
||||
|
||||
strcpy(temp, (char*)local_source);
|
||||
local_source[0] = '0';
|
||||
|
||||
for(i = 0; i <= length; i++)
|
||||
{
|
||||
local_source[i + 1] = temp[i];
|
||||
}
|
||||
length++;
|
||||
temp[++temp_length] = '\0';
|
||||
}
|
||||
|
||||
/* Start character */
|
||||
concat((char*)dest, TeleTable['_']);
|
||||
strcpy(dest, TeleTable['_']);
|
||||
|
||||
for (i=0; i < length; i+=2)
|
||||
for (i = 0; i < temp_length; i += 2)
|
||||
{
|
||||
if(local_source[i] == 'X') {
|
||||
if(temp[i] == 'X') {
|
||||
strcpy(symbol->errtxt, "Invalid position of X in Telepen data");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
if(local_source[i + 1] == 'X') {
|
||||
glyph = ctoi(local_source[i]) + 17;
|
||||
if(temp[i + 1] == 'X') {
|
||||
glyph = ctoi(temp[i]) + 17;
|
||||
count += glyph;
|
||||
} else {
|
||||
glyph = (10 * ctoi(local_source[i])) + ctoi(local_source[i + 1]);
|
||||
glyph = (10 * ctoi(temp[i])) + ctoi(temp[i + 1]);
|
||||
glyph += 27;
|
||||
count += glyph;
|
||||
}
|
||||
concat((char*)dest, TeleTable[glyph]);
|
||||
concat(dest, TeleTable[glyph]);
|
||||
}
|
||||
|
||||
check_digit = 127 - (count % 127);
|
||||
if(check_digit == 127) { check_digit = 0; }
|
||||
concat((char*)dest, TeleTable[check_digit]);
|
||||
concat(dest, TeleTable[check_digit]);
|
||||
|
||||
/* Stop character */
|
||||
concat((char*)dest, TeleTable['z']);
|
||||
concat(dest, TeleTable['z']);
|
||||
|
||||
expand(symbol, (char*)dest);
|
||||
ustrcpy(symbol->text, local_source);
|
||||
expand(symbol, dest);
|
||||
ustrcpy(symbol->text, temp);
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#define NASET "0123456789+"
|
||||
#define SODIUM "0123456789+"
|
||||
#define EAN2 102
|
||||
#define EAN5 105
|
||||
|
||||
@ -82,7 +82,7 @@ void upca_draw(char source[], char dest[])
|
||||
concat(dest, "11111");
|
||||
}
|
||||
|
||||
lookup(NESET, EANsetA, source[i], dest);
|
||||
lookup(NEON, EANsetA, source[i], dest);
|
||||
}
|
||||
|
||||
/* stop character */
|
||||
@ -200,8 +200,8 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
||||
|
||||
for(i = 0; i <= ustrlen(source); i++) {
|
||||
switch(parity[i]) {
|
||||
case 'A': lookup(NESET, EANsetA, source[i], dest); break;
|
||||
case 'B': lookup(NESET, EANsetB, source[i], dest); break;
|
||||
case 'A': lookup(NEON, EANsetA, source[i], dest); break;
|
||||
case 'B': lookup(NEON, EANsetB, source[i], dest); break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,8 +267,8 @@ void add_on(unsigned char source[], char dest[], int mode)
|
||||
for(i = 0; i < ustrlen(source); i++)
|
||||
{
|
||||
switch(parity[i]) {
|
||||
case 'A': lookup(NESET, EANsetA, source[i], dest); break;
|
||||
case 'B': lookup(NESET, EANsetB, source[i], dest); break;
|
||||
case 'A': lookup(NEON, EANsetA, source[i], dest); break;
|
||||
case 'B': lookup(NEON, EANsetB, source[i], dest); break;
|
||||
}
|
||||
|
||||
/* Glyph separator */
|
||||
@ -319,15 +319,15 @@ void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
||||
gtin[length + 1] = '\0';
|
||||
|
||||
/* Get parity for first half of the symbol */
|
||||
lookup(NASET, EAN13Parity, gtin[0], parity);
|
||||
lookup(SODIUM, EAN13Parity, gtin[0], parity);
|
||||
|
||||
/* Now get on with the cipher */
|
||||
half_way = 7;
|
||||
|
||||
/* start character */
|
||||
concat (dest, "111");
|
||||
|
||||
for(i = 1; i <= strlen(gtin); i++)
|
||||
length = strlen(gtin);
|
||||
for(i = 1; i <= length; i++)
|
||||
{
|
||||
if (i == half_way)
|
||||
{
|
||||
@ -338,11 +338,11 @@ void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
||||
|
||||
if(((i > 1) && (i < 7)) && (parity[i - 2] == 'B'))
|
||||
{
|
||||
lookup(NESET, EANsetB, gtin[i], dest);
|
||||
lookup(NEON, EANsetB, gtin[i], dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
lookup(NESET, EANsetA, gtin[i], dest);
|
||||
lookup(NEON, EANsetA, gtin[i], dest);
|
||||
}
|
||||
}
|
||||
|
||||
@ -368,12 +368,13 @@ void ean8(struct zint_symbol *symbol, unsigned char source[], char dest[])
|
||||
|
||||
char isbn13_check(unsigned char source[]) /* For ISBN(13) only */
|
||||
{
|
||||
unsigned int i, weight, sum, check;
|
||||
unsigned int i, weight, sum, check, h;
|
||||
|
||||
sum = 0;
|
||||
weight = 1;
|
||||
h = ustrlen(source) - 1;
|
||||
|
||||
for(i = 0; i < (ustrlen(source) - 1); i++)
|
||||
for(i = 0; i < h; i++)
|
||||
{
|
||||
sum += ctoi(source[i]) * weight;
|
||||
if(weight == 1) weight = 3; else weight = 1;
|
||||
@ -386,11 +387,13 @@ char isbn13_check(unsigned char source[]) /* For ISBN(13) only */
|
||||
|
||||
char isbn_check(unsigned char source[]) /* For ISBN(10) and SBN only */
|
||||
{
|
||||
unsigned int i, weight, sum, check;
|
||||
unsigned int i, weight, sum, check, h;
|
||||
|
||||
sum = 0;
|
||||
weight = 1;
|
||||
for(i = 0; i < (ustrlen(source) - 1); i++)
|
||||
h = ustrlen(source) - 1;
|
||||
|
||||
for(i = 0; i < h; i++)
|
||||
{
|
||||
sum += ctoi(source[i]) * weight;
|
||||
weight++;
|
||||
@ -400,19 +403,26 @@ char isbn_check(unsigned char source[]) /* For ISBN(10) and SBN only */
|
||||
return itoc(check);
|
||||
}
|
||||
|
||||
int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Make an EAN-13 barcode from an SBN or ISBN */
|
||||
int isbn(struct zint_symbol *symbol, unsigned char source[], const unsigned int src_len, char dest[]) /* Make an EAN-13 barcode from an SBN or ISBN */
|
||||
{
|
||||
int i;
|
||||
int i, error_number;
|
||||
char check_digit;
|
||||
|
||||
to_upper(source);
|
||||
error_number = is_sane("0123456789X", source, src_len);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in input");
|
||||
return error_number;
|
||||
}
|
||||
|
||||
/* Input must be 9, 10 or 13 characters */
|
||||
if(((ustrlen(source) < 9) || (ustrlen(source) > 13)) || ((ustrlen(source) > 10) && (ustrlen(source) < 13)))
|
||||
if(((src_len < 9) || (src_len > 13)) || ((src_len > 10) && (src_len < 13)))
|
||||
{
|
||||
strcpy(symbol->errtxt, "Input wrong length");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
|
||||
if(ustrlen(source) == 13) /* Using 13 character ISBN */
|
||||
if(src_len == 13) /* Using 13 character ISBN */
|
||||
{
|
||||
if(!(((source[0] == '9') && (source[1] == '7')) &&
|
||||
((source[2] == '8') || (source[2] == '9'))))
|
||||
@ -422,7 +432,7 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Mak
|
||||
}
|
||||
|
||||
check_digit = isbn13_check(source);
|
||||
if (source[ustrlen(source) - 1] != check_digit)
|
||||
if (source[src_len - 1] != check_digit)
|
||||
{
|
||||
strcpy(symbol->errtxt, "Incorrect ISBN check");
|
||||
return ERROR_INVALID_CHECK;
|
||||
@ -432,10 +442,10 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Mak
|
||||
ean13(symbol, source, dest);
|
||||
}
|
||||
|
||||
if(ustrlen(source) == 10) /* Using 10 digit ISBN */
|
||||
if(src_len == 10) /* Using 10 digit ISBN */
|
||||
{
|
||||
check_digit = isbn_check(source);
|
||||
if(check_digit != source[ustrlen(source) - 1])
|
||||
if(check_digit != source[src_len - 1])
|
||||
{
|
||||
strcpy(symbol->errtxt, "Incorrect ISBN check");
|
||||
return ERROR_INVALID_CHECK;
|
||||
@ -452,7 +462,7 @@ int isbn(struct zint_symbol *symbol, unsigned char source[], char dest[]) /* Mak
|
||||
ean13(symbol, source, dest);
|
||||
}
|
||||
|
||||
if(ustrlen(source) == 9) /* Using 9 digit SBN */
|
||||
if(src_len == 9) /* Using 9 digit SBN */
|
||||
{
|
||||
/* Add leading zero */
|
||||
for(i = 10; i > 0; i--)
|
||||
@ -489,9 +499,10 @@ void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsi
|
||||
/* Add leading zeroes to EAN and UPC strings */
|
||||
unsigned char first_part[20], second_part[20], zfirst_part[20], zsecond_part[20];
|
||||
int with_addon = 0;
|
||||
int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i;
|
||||
int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i, h;
|
||||
|
||||
for(i = 0; i < ustrlen(source); i++) {
|
||||
h = ustrlen(source);
|
||||
for(i = 0; i < h; i++) {
|
||||
if(source[i] == '+') {
|
||||
with_addon = 1;
|
||||
} else {
|
||||
@ -566,36 +577,32 @@ void ean_leading_zeroes(struct zint_symbol *symbol, unsigned char source[], unsi
|
||||
}
|
||||
}
|
||||
|
||||
int eanx(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
int eanx(struct zint_symbol *symbol, unsigned char source[], int src_len)
|
||||
{
|
||||
/* splits string to parts before and after '+' parts */
|
||||
unsigned char first_part[20], second_part[20], dest[1000];
|
||||
unsigned char local_source[20];
|
||||
unsigned char first_part[20] = { 0 }, second_part[20] = { 0 }, dest[1000] = { 0 };
|
||||
unsigned char local_source[20] = { 0 };
|
||||
unsigned int latch, reader, writer, with_addon;
|
||||
int error_number, i;
|
||||
|
||||
error_number = 0;
|
||||
memset(dest,0,1000);
|
||||
memset(first_part,0,20);
|
||||
memset(second_part,0,20);
|
||||
|
||||
with_addon = FALSE;
|
||||
latch = FALSE;
|
||||
writer = 0;
|
||||
|
||||
if(length > 19) {
|
||||
if(src_len > 19) {
|
||||
strcpy(symbol->errtxt, "Input too long");
|
||||
return ERROR_TOO_LONG;
|
||||
}
|
||||
if(symbol->symbology != BARCODE_ISBNX) {
|
||||
/* ISBN has it's own checking routine */
|
||||
error_number = is_sane(NASET, source, length);
|
||||
error_number = is_sane(NEON, source, src_len);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in data");
|
||||
return error_number;
|
||||
}
|
||||
} else {
|
||||
error_number = is_sane("0123456789Xx", source, length);
|
||||
error_number = is_sane("0123456789Xx", source, src_len);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
strcpy(symbol->errtxt, "Invalid characters in input");
|
||||
return error_number;
|
||||
@ -734,7 +741,7 @@ int eanx(struct zint_symbol *symbol, unsigned char source[], int length)
|
||||
}
|
||||
break;
|
||||
case BARCODE_ISBNX:
|
||||
error_number = isbn(symbol, first_part, (char*)dest);
|
||||
error_number = isbn(symbol, first_part, ustrlen(first_part), (char*)dest);
|
||||
if(error_number > 4) {
|
||||
return error_number;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
//#define ZINT_VERSION "2.0.A"
|
||||
|
||||
struct zint_symbol {
|
||||
int symbology;
|
||||
@ -40,14 +39,13 @@ struct zint_symbol {
|
||||
int option_2;
|
||||
int option_3;
|
||||
int input_mode;
|
||||
unsigned char text[100];
|
||||
unsigned char text[128];
|
||||
int rows;
|
||||
int width;
|
||||
char primary[100];
|
||||
char primary[128];
|
||||
unsigned char encoded_data[178][143];
|
||||
int row_height[178]; /* Largest symbol is 177x177 QR Code */
|
||||
char errtxt[100];
|
||||
char nullchar;
|
||||
};
|
||||
|
||||
/* Tbarcode 7 codes */
|
||||
|
@ -92,7 +92,6 @@ void usage(void)
|
||||
" --secure=NUMBER (PDF417 and QR Code) Error correction level.\n"
|
||||
" --primary=STRING (Maxicode and Composite) Structured primary message.\n"
|
||||
" --mode=NUMBER (Maxicode and Composite) Set encoding mode.\n"
|
||||
" --null=NUMBER Character to represent NULL.\n"
|
||||
" --gs1 Treat input as GS1 data\n"
|
||||
" --kanji Treat input as Kanji characters in Unicode\n"
|
||||
" --sjis Treat input as Shift-JIS\n"
|
||||
@ -161,7 +160,6 @@ int main(int argc, char **argv)
|
||||
{"mode", 1, 0, 0},
|
||||
{"primary", 1, 0, 0},
|
||||
{"scale", 1, 0, 0},
|
||||
{"null", 1, 0, 0},
|
||||
{"gs1", 0, 0, 0},
|
||||
{"kanji", 0, 0, 0},
|
||||
{"sjis", 0, 0, 0},
|
||||
@ -229,18 +227,6 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "Border width out of range\n");
|
||||
}
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "null")) {
|
||||
error_number = validator(NESET, optarg);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
fprintf(stderr, "Invalid NULL replacement\n");
|
||||
exit(1);
|
||||
}
|
||||
if((atoi(optarg) >= 1) && (atoi(optarg) <= 128)) {
|
||||
my_symbol->nullchar = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "Invalid NULL replacement\n");
|
||||
}
|
||||
}
|
||||
if(!strcmp(long_options[option_index].name, "height")) {
|
||||
error_number = validator(NESET, optarg);
|
||||
if(error_number == ERROR_INVALID_DATA) {
|
||||
|
Loading…
Reference in New Issue
Block a user