diff --git a/backend/2of5.c b/backend/2of5.c index 59411214..1f336a97 100644 --- a/backend/2of5.c +++ b/backend/2of5.c @@ -59,7 +59,7 @@ static inline char check_digit(unsigned int count) { } /* Code 2 of 5 Standard (Code 2 of 5 Matrix) */ -int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { +int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number; char dest[512]; /* 6 + 80 * 6 + 6 + 1 ~ 512*/ @@ -84,7 +84,7 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int l } /* Stop character */ - strcat(dest, "41111"); + strcat(dest, "41111"); expand(symbol, dest); ustrcpy(symbol->text, source); @@ -92,7 +92,7 @@ int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int l } /* Code 2 of 5 Industrial */ -int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { +int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number; char dest[512]; /* 6 + 40 * 10 + 6 + 1 */ @@ -117,7 +117,7 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i } /* Stop character */ - strcat(dest, "31113"); + strcat(dest, "31113"); expand(symbol, dest); ustrcpy(symbol->text, source); @@ -125,7 +125,7 @@ int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], i } /* Code 2 of 5 IATA */ -int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { +int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number; char dest[512]; /* 4 + 45 * 10 + 3 + 1 */ @@ -149,7 +149,7 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int len } /* stop */ - strcat(dest, "311"); + strcat(dest, "311"); expand(symbol, dest); ustrcpy(symbol->text, source); @@ -157,7 +157,7 @@ int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int len } /* Code 2 of 5 Data Logic */ -int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { +int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number; char dest[512]; /* 4 + 80 * 6 + 3 + 1 */ @@ -182,7 +182,7 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int le } /* Stop character */ - strcat(dest, "311"); + strcat(dest, "311"); expand(symbol, dest); ustrcpy(symbol->text, source); @@ -190,7 +190,7 @@ int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int le } /* Code 2 of 5 Interleaved */ -int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length) { +int interleaved_two_of_five(struct zint_symbol *symbol, const unsigned char source[], size_t length) { int i, j, k, error_number; char bars[7], spaces[7], mixed[14], dest[1000]; @@ -219,7 +219,7 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], ustrcpy(temp, (unsigned char *) "0"); length++; } - strcat((char*)temp, (char*)source); + strcat((char*) temp, (char*) source); /* start character */ strcpy(dest, "1111"); @@ -240,11 +240,11 @@ int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], k++; } mixed[k] = '\0'; - strcat(dest, mixed); + strcat(dest, mixed); } /* Stop character */ - strcat(dest, "311"); + strcat(dest, "311"); expand(symbol, dest); ustrcpy(symbol->text, temp); @@ -296,7 +296,7 @@ int itf14(struct zint_symbol *symbol, unsigned char source[], int length) { } /* Deutshe Post Leitcode */ -int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) { +int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number; unsigned int count; char localstr[16]; @@ -334,7 +334,7 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[], int length) { } /* Deutsche Post Identcode */ -int dpident(struct zint_symbol *symbol, unsigned char source[], int length) { +int dpident(struct zint_symbol *symbol, unsigned char source[], int length) { int i, error_number, zeroes; unsigned int count; char localstr[16]; diff --git a/backend/auspost.c b/backend/auspost.c index b6477099..c1808b68 100644 --- a/backend/auspost.c +++ b/backend/auspost.c @@ -106,7 +106,8 @@ int australia_post(struct zint_symbol *symbol, unsigned char source[], int lengt 3 = Tracker only */ int error_number, zeroes; int writer; - unsigned int loopey, reader, h; + unsigned int loopey, reader; + size_t h; char data_pattern[200]; char fcc[3] = {0, 0, 0}, dpid[10]; diff --git a/backend/aztec.c b/backend/aztec.c index 0e1a529a..239938d9 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -40,10 +40,12 @@ #include "aztec.h" #include "reedsol.h" +static int AztecMap[22801]; + /** * Shorten the string by one character */ -void mapshorten(int *charmap, int *typemap, int start, int length) { +static void mapshorten(int *charmap, int *typemap, const int start, const int length) { memmove(charmap + start + 1, charmap + start + 2, (length - 1) * sizeof (int)); memmove(typemap + start + 1, typemap + start + 2, (length - 1) * sizeof (int)); } @@ -51,7 +53,7 @@ void mapshorten(int *charmap, int *typemap, int start, int length) { /** * Insert a character into the middle of a string at position posn */ -void insert(char binary_string[], int posn, char newbit) { +static void insert(char binary_string[], const size_t posn, const char newbit) { size_t i, end; end = strlen(binary_string); @@ -64,7 +66,7 @@ void insert(char binary_string[], int posn, char newbit) { /** * Encode input data into a binary string */ -int aztec_text_process(unsigned char source[], const unsigned int src_len, char binary_string[], int gs1, int eci) { +static int aztec_text_process(const unsigned char source[], const unsigned int src_len, char binary_string[], const int gs1, const int eci) { int i, j, k, p, bytes; int curtable, newtable, lasttable, chartype, maplength, blocks, debug; #ifndef _MSC_VER @@ -723,10 +725,8 @@ int aztec_text_process(unsigned char source[], const unsigned int src_len, char } /* Prevent data from obscuring reference grid */ -int avoidReferenceGrid(int input) { - int output; +static int avoidReferenceGrid(int output) { - output = input; if (output > 10) { output++; } @@ -759,7 +759,7 @@ int avoidReferenceGrid(int input) { } /* Calculate the position of the bits in the grid */ -void populate_map() { +static void populate_map() { int layer, start, length, n, i; int x, y; @@ -930,7 +930,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length) { ecc_level = 2; } - data_length = strlen(binary_string); + data_length = (int) strlen(binary_string); layers = 0; /* Keep compiler happy! */ data_maxsize = 0; /* Keep compiler happy! */ @@ -1059,7 +1059,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length) { i++; } while (i <= (data_length + 1)); adjusted_string[j] = '\0'; - adjusted_length = strlen(adjusted_string); + adjusted_length = (int) strlen(adjusted_string); adjustment_size = adjusted_length - data_length; /* Add padding */ @@ -1073,7 +1073,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length) { for (i = 0; i < padbits; i++) { strcat(adjusted_string, "1"); } - adjusted_length = strlen(adjusted_string); + adjusted_length = (int) strlen(adjusted_string); count = 0; for (i = (adjusted_length - codeword_size); i < adjusted_length; i++) { @@ -1167,7 +1167,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length) { i++; } while (i <= (data_length + 1)); adjusted_string[j] = '\0'; - adjusted_length = strlen(adjusted_string); + adjusted_length = (int) strlen(adjusted_string); remainder = adjusted_length % codeword_size; @@ -1179,7 +1179,7 @@ int aztec(struct zint_symbol *symbol, unsigned char source[], int length) { for (i = 0; i < padbits; i++) { strcat(adjusted_string, "1"); } - adjusted_length = strlen(adjusted_string); + adjusted_length = (int) strlen(adjusted_string); count = 0; for (i = (adjusted_length - codeword_size); i < adjusted_length; i++) { diff --git a/backend/aztec.h b/backend/aztec.h index 87d4c579..aa2cc4e6 100644 --- a/backend/aztec.h +++ b/backend/aztec.h @@ -37,8 +37,6 @@ #define DIGIT 16 #define BINARY 32 -static int AztecMap[22801]; - static const int CompactAztecMap[] = { /* 27 x 27 data grid */ 609, 608, 411, 413, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, diff --git a/backend/bmp.c b/backend/bmp.c index 31aa8499..72803ec4 100644 --- a/backend/bmp.c +++ b/backend/bmp.c @@ -68,8 +68,8 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width if (symbol->bitmap != NULL) free(symbol->bitmap); - - row_size = 4 * floor((24 * symbol->bitmap_width + 31) / 32); + + row_size = 4 * floor((24.0 * symbol->bitmap_width + 31) / 32); symbol->bitmap = (char *) malloc(row_size * symbol->bitmap_height); /* sort out colour options */ @@ -189,13 +189,13 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width data_size = symbol->bitmap_height * row_size; symbol->bitmap_byte_length = data_size; - - file_header.header_field = 0x4d42; // "BM" - file_header.file_size = sizeof(bitmap_file_header_t) + sizeof(bitmap_info_header_t) + data_size; - file_header.reserved = 0; - file_header.data_offset = sizeof(bitmap_file_header_t) + sizeof(bitmap_info_header_t); - info_header.header_size = sizeof(bitmap_info_header_t); + file_header.header_field = 0x4d42; // "BM" + file_header.file_size = sizeof (bitmap_file_header_t) + sizeof (bitmap_info_header_t) + data_size; + file_header.reserved = 0; + file_header.data_offset = sizeof (bitmap_file_header_t) + sizeof (bitmap_info_header_t); + + info_header.header_size = sizeof (bitmap_info_header_t); info_header.width = symbol->bitmap_width; info_header.height = symbol->bitmap_height; info_header.colour_planes = 1; @@ -206,17 +206,17 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width info_header.vert_res = 0; info_header.colours = 0; info_header.important_colours = 0; - - bitmap_file_start = (unsigned char*)malloc(file_header.file_size); + + bitmap_file_start = (unsigned char*) malloc(file_header.file_size); memset(bitmap_file_start, 0xff, file_header.file_size); - + bmp_posn = bitmap_file_start; - memcpy( bitmap_file_start, &file_header, sizeof(bitmap_file_header_t)); - bmp_posn += sizeof(bitmap_file_header_t); - memcpy(bmp_posn, &info_header, sizeof(bitmap_info_header_t) ); - bmp_posn += sizeof(bitmap_info_header_t); + memcpy(bitmap_file_start, &file_header, sizeof (bitmap_file_header_t)); + bmp_posn += sizeof (bitmap_file_header_t); + memcpy(bmp_posn, &info_header, sizeof (bitmap_info_header_t)); + bmp_posn += sizeof (bitmap_info_header_t); memcpy(bmp_posn, symbol->bitmap, data_size); - + /* Open output file in binary mode */ if ((symbol->output_options & BARCODE_STDOUT) != 0) { #ifdef _MSC_VER @@ -232,10 +232,10 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width return ZINT_ERROR_FILE_ACCESS; } } - + fwrite(bitmap_file_start, file_header.file_size, 1, bmp_file); fclose(bmp_file); - + free(bitmap_file_start); return 0; } \ No newline at end of file diff --git a/backend/bmp.h b/backend/bmp.h index ea20b47d..2ab22bf3 100644 --- a/backend/bmp.h +++ b/backend/bmp.h @@ -36,11 +36,11 @@ extern "C" { #endif -#ifdef _MSC_VER -#include -#include "stdint_msvc.h" -#else -#include +#ifdef _MSC_VER +#include +#include "stdint_msvc.h" +#else +#include #endif typedef struct bitmap_file_header { @@ -48,12 +48,12 @@ extern "C" { uint32_t file_size; uint32_t reserved; uint32_t data_offset; - } -#ifdef __GNUC__ - __attribute__((__packed__ )) -#endif - bitmap_file_header_t; - + } +#ifdef __GNUC__ + __attribute__((__packed__)) +#endif + bitmap_file_header_t; + typedef struct bitmap_info_header { uint32_t header_size; int32_t width; @@ -66,11 +66,11 @@ extern "C" { int32_t vert_res; uint32_t colours; uint32_t important_colours; - } -#ifdef __GNUC__ - __attribute__((__packed__ )) -#endif - bitmap_info_header_t; + } +#ifdef __GNUC__ + __attribute__((__packed__)) +#endif + bitmap_info_header_t; #ifdef __cplusplus } diff --git a/backend/codablock.c b/backend/codablock.c index f6ce4716..25dd1033 100644 --- a/backend/codablock.c +++ b/backend/codablock.c @@ -703,7 +703,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) { rows = 1; } else { /* use 3/1 aspect/ratio Codablock */ - rows = ((int)floor(sqrt(dataLength)))/3; + rows = ((int)floor(sqrt(1.0*dataLength)))/3; if (rows < 1) rows = 1; else if (rows > 44) @@ -771,7 +771,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) { #ifndef _MSC_VER uchar pOutput[columns * rows]; #else - pOutput = (char *)_alloca(columns * rows * sizeof(char)); + pOutput = (unsigned char *)_alloca(columns * rows * sizeof(char)); #endif pOutPos = pOutput; charCur=0; @@ -782,7 +782,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[], int length) { /* >> Empty line with StartCCodeBCodeC */ characterSetCur=CodeC; /* CDB Start C*/ - pOutPos+=sprintf(pOutPos,"\x67\x63"); + pOutPos+=sprintf((char*)pOutPos,"\x67\x63"); SummeASCII(&pOutPos,rowCur+42,CodeC); emptyColumns=useColumns-2; while (emptyColumns>0) diff --git a/backend/code.c b/backend/code.c index 5561ff85..26cd37ae 100644 --- a/backend/code.c +++ b/backend/code.c @@ -187,7 +187,7 @@ int code_11(struct zint_symbol *symbol, unsigned char source[], int length) { /* } /* Code 39 */ -int c39(struct zint_symbol *symbol, unsigned char source[], int length) { +int c39(struct zint_symbol *symbol, unsigned char source[], const size_t length) { unsigned int i; unsigned int counter; char check_digit; @@ -269,7 +269,7 @@ 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 */ - counter = strlen(dest); + counter = (unsigned int) strlen(dest); for (i = 0; i < counter; i++) { if (dest[i] == '2') { dest[i] = '3'; @@ -404,7 +404,7 @@ int c93(struct zint_symbol *symbol, unsigned char source[], int length) { } /* Now we can check the true length of the barcode */ - h = strlen(buffer); + h = (int) strlen(buffer); if (h > 107) { strcpy(symbol->errtxt, "Input too long"); return ZINT_ERROR_TOO_LONG; diff --git a/backend/code1.c b/backend/code1.c index ea1d2239..cf67e87c 100644 --- a/backend/code1.c +++ b/backend/code1.c @@ -140,7 +140,7 @@ int dq4bi(unsigned char source[], int sourcelen, int position) { return 0; } -int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int current_mode, int gs1) { +static int c1_look_ahead_test(unsigned char source[], int sourcelen, int position, int current_mode, int gs1) { float ascii_count, c40_count, text_count, edi_count, byte_count; char reduced_char; int done, best_scheme, best_count, sp; @@ -861,7 +861,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } if (decimal_count != 3) { - int bits_left_in_byte, target_count; + size_t bits_left_in_byte, target_count; int sub_target; /* Finish Decimal mode and go back to ASCII */ @@ -1150,7 +1150,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t } if (current_mode == C1_DECIMAL) { - int bits_left_in_byte, target_count; + size_t bits_left_in_byte, target_count; int sub_target; /* Finish Decimal mode and go back to ASCII */ diff --git a/backend/code128.c b/backend/code128.c index def9babd..1f81af9e 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -681,7 +681,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) { } /* Handle EAN-128 (Now known as GS1-128) */ -int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) { +int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t length) { int i, j, values[170], bar_characters, read, total_sum; int error_number, indexchaine, indexliste; char set[170], mode, last_set; diff --git a/backend/common.c b/backend/common.c index b593fcfe..e14588ec 100644 --- a/backend/common.c +++ b/backend/common.c @@ -35,16 +35,10 @@ #include "common.h" /* Local replacement for strlen() with unsigned char strings */ -int ustrlen(const unsigned char data[]) { +size_t ustrlen(const unsigned char data[]) { return strlen((const char*) data); } -/* Local replacement for strcpy() with unsigned char strings */ - -void ustrcpy(unsigned char target[], const unsigned char source[]) { - strcpy((char *) target, (const char*) source); -} - /* Converts a character 0-9 to its equivalent integer value */ int ctoi(const char source) { if ((source >= '0') && (source <= '9')) @@ -63,7 +57,7 @@ char itoc(const int source) { /* Converts lower case characters to upper case in a string source[] */ void to_upper(unsigned char source[]) { - unsigned int i, src_len = ustrlen(source); + size_t i, src_len = ustrlen(source); for (i = 0; i < src_len; i++) { if ((source[i] >= 'a') && (source[i] <= 'z')) { @@ -73,9 +67,9 @@ void to_upper(unsigned char source[]) { } /* Verifies that a string only uses valid characters */ -int is_sane(const char test_string[], const unsigned char source[], const int length) { - unsigned int i, j, latch; - unsigned int lt = strlen(test_string); +int is_sane(const char test_string[], const unsigned char source[], const size_t length) { + unsigned int j, latch; + size_t i, lt = strlen(test_string); for (i = 0; i < length; i++) { latch = FALSE; @@ -95,7 +89,7 @@ int is_sane(const char test_string[], const unsigned char source[], const int le /* Returns the position of data in set_string */ int posn(const char set_string[], const char data) { - unsigned int i, n = strlen(set_string); + size_t i, n = strlen(set_string); for (i = 0; i < n; i++) { if (data == set_string[i]) { @@ -107,7 +101,7 @@ int posn(const char set_string[], const char data) { /* Replaces huge switch statements for looking up in tables */ void lookup(const char set_string[], const char *table[], const char data, char dest[]) { - unsigned int i, n = strlen(set_string); + size_t i, n = strlen(set_string); for (i = 0; i < n; i++) { if (data == set_string[i]) { @@ -134,7 +128,7 @@ void unset_module(struct zint_symbol *symbol, const int y_coord, const int x_coo /* Expands from a width pattern to a bit pattern */ void expand(struct zint_symbol *symbol, const char data[]) { - unsigned int reader, n = strlen(data); + size_t reader, n = strlen(data); int writer, i; char latch; @@ -168,11 +162,11 @@ void expand(struct zint_symbol *symbol, const char data[]) { /* Indicates which symbologies can have row binding */ int is_stackable(const int symbology) { int retval = 0; - + if (symbology < BARCODE_PDF417) { retval = 1; } - + switch (symbology) { case BARCODE_CODE128B: case BARCODE_ISBNX: diff --git a/backend/common.h b/backend/common.h index 20981a0c..03554ad4 100644 --- a/backend/common.h +++ b/backend/common.h @@ -46,17 +46,19 @@ #define NEON "0123456789" #include "zint.h" +#include + +#define ustrcpy(target,source) strcpy((char*)target,(const char*)source) #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ - extern int ustrlen(const unsigned char source[]); - extern void ustrcpy(unsigned char target[], const unsigned char source[]); + extern size_t ustrlen(const unsigned char source[]); extern int ctoi(const char source); extern char itoc(const int source); extern void to_upper(unsigned char source[]); - extern int is_sane(const char test_string[], const unsigned char source[], const int length); + extern int is_sane(const char test_string[], const unsigned char source[], const size_t length); extern void lookup(const char set_string[], const char *table[], const char data, char dest[]); extern int posn(const char set_string[], const char data); extern void expand(struct zint_symbol *symbol, const char data[]); diff --git a/backend/composite.c b/backend/composite.c index c71981e3..f06756d7 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -65,7 +65,7 @@ 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 ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t 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); diff --git a/backend/dmatrix.c b/backend/dmatrix.c index be024e73..5f22b9d0 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -306,31 +306,31 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, /* step (j) */ if (current_mode == DM_ASCII) { - ascii_count = 0.0; - c40_count = 1.0; - text_count = 1.0; - x12_count = 1.0; - edf_count = 1.0; - b256_count = 1.25; + ascii_count = 0.0F; + c40_count = 1.0F; + text_count = 1.0F; + x12_count = 1.0F; + edf_count = 1.0F; + b256_count = 1.25F; } else { - ascii_count = 1.0; - c40_count = 2.0; - text_count = 2.0; - x12_count = 2.0; - edf_count = 2.0; - b256_count = 2.25; + ascii_count = 1.0F; + c40_count = 2.0F; + text_count = 2.0F; + x12_count = 2.0F; + edf_count = 2.0F; + b256_count = 2.25F; } switch (current_mode) { - case DM_C40: c40_count = 0.0; + case DM_C40: c40_count = 0.0F; break; - case DM_TEXT: text_count = 0.0; + case DM_TEXT: text_count = 0.0F; break; - case DM_X12: x12_count = 0.0; + case DM_X12: x12_count = 0.0F; break; - case DM_EDIFACT: edf_count = 0.0; + case DM_EDIFACT: edf_count = 0.0F; break; - case DM_BASE256: b256_count = 0.0; + case DM_BASE256: b256_count = 0.0F; break; } @@ -339,12 +339,12 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, do { if (sp == (sourcelen - 1)) { /* At the end of data ... step (k) */ - ascii_count = ceil(ascii_count); - b256_count = ceil(b256_count); - edf_count = ceil(edf_count); - text_count = ceil(text_count); - x12_count = ceil(x12_count); - c40_count = ceil(c40_count); + ascii_count = ceilf(ascii_count); + b256_count = ceilf(b256_count); + edf_count = ceilf(edf_count); + text_count = ceilf(text_count); + x12_count = ceilf(x12_count); + c40_count = ceilf(c40_count); best_count = c40_count; best_scheme = DM_C40; // (k)(7) @@ -379,9 +379,9 @@ static int look_ahead_test(const unsigned char inputData[], const int sourcelen, ascii_count += 0.5F; // (l)(1) } else { if (inputData[sp] > 127) { - ascii_count = ceil(ascii_count) + 2.0F; // (l)(2) + ascii_count = ceilf(ascii_count) + 2.0F; // (l)(2) } else { - ascii_count = ceil(ascii_count) + 1.0F; // (l)(3) + ascii_count = ceilf(ascii_count) + 1.0F; // (l)(3) } } @@ -568,11 +568,11 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], if (debug) printf("RP "); } } - + if (symbol->eci > 3) { target[tp] = 241; /* ECI Character */ tp++; - target[tp] = symbol->eci + 1; + target[tp] = (unsigned char) (symbol->eci + 1); tp++; if (debug) printf("ECI %d ", symbol->eci + 1); } @@ -718,7 +718,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], int iv; iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1; - target[tp] = iv / 256; + target[tp] = (unsigned char) (iv / 256); tp++; target[tp] = iv % 256; tp++; @@ -781,7 +781,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], int iv; iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1; - target[tp] = iv / 256; + target[tp] = (unsigned char) (iv / 256); tp++; target[tp] = iv % 256; tp++; @@ -842,7 +842,7 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], int iv; iv = (1600 * process_buffer[0]) + (40 * process_buffer[1]) + (process_buffer[2]) + 1; - target[tp] = iv / 256; + target[tp] = (unsigned char) (iv / 256); tp++; target[tp] = iv % 256; tp++; @@ -889,11 +889,11 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], } if (*process_p >= 4) { - target[tp] = (process_buffer[0] << 2) + ((process_buffer[1] & 0x30) >> 4); + target[tp] = (unsigned char) ((process_buffer[0] << 2) + ((process_buffer[1] & 0x30) >> 4)); tp++; target[tp] = ((process_buffer[1] & 0x0f) << 4) + ((process_buffer[2] & 0x3c) >> 2); tp++; - target[tp] = ((process_buffer[2] & 0x03) << 6) + process_buffer[3]; + target[tp] = (unsigned char) (((process_buffer[2] & 0x03) << 6) + process_buffer[3]); tp++; strcat(binary, " "); if (debug) printf("[%d %d %d %d] ", process_buffer[0], process_buffer[1], process_buffer[2], process_buffer[3]); @@ -966,9 +966,9 @@ static int dm200encode(struct zint_symbol *symbol, const unsigned char source[], prn = ((149 * (i + 1)) % 255) + 1; temp = target[i] + prn; if (temp <= 255) { - target[i] = temp; + target[i] = (unsigned char) (temp); } else { - target[i] = temp - 256; + target[i] = (unsigned char) (temp - 256); } } } @@ -1074,7 +1074,7 @@ static int dm200encode_remainder(unsigned char target[], int target_length, cons if (process_p == 1) { target[target_length] = (unsigned char) ((process_buffer[0] << 2) + ((31 & 0x30) >> 4)); target_length++; - target[target_length] = (unsigned char) ((31 & 0x0f) << 4) ; + target[target_length] = (unsigned char) ((31 & 0x0f) << 4); target_length++; target[target_length] = (unsigned char) 0; target_length++; @@ -1126,18 +1126,18 @@ static void add_tail(unsigned char target[], int tp, const int tail_length) { prn = ((149 * (tp + 1)) % 253) + 1; temp = 129 + prn; if (temp <= 254) { - target[tp] = temp; + target[tp] = (unsigned char) (temp); tp++; } else { - target[tp] = temp - 254; + target[tp] = (unsigned char) (temp - 254); tp++; } } } } -int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], const int length) { - int inputlen, i, skew = 0; +int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], const int in_length) { + int i, inputlen = in_length, skew = 0; unsigned char binary[2200]; int binlen; int process_buffer[8]; /* holds remaining data to finalised */ @@ -1148,7 +1148,6 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], const in int last_mode = DM_ASCII; unsigned char *grid = 0; int symbols_left; - inputlen = length; /* inputlen may be decremented by 2 if macro character is used */ binlen = dm200encode(symbol, source, binary, &last_mode, &inputlen, process_buffer, &process_p); @@ -1291,12 +1290,12 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], const in return error_number; } -int dmatrix(struct zint_symbol *symbol, unsigned char source[], const int length) { +int dmatrix(struct zint_symbol *symbol, const unsigned char source[], const int in_length) { int error_number; if (symbol->option_1 <= 1) { /* ECC 200 */ - error_number = data_matrix_200(symbol, source, length); + error_number = data_matrix_200(symbol, source, in_length); } else { /* ECC 000 - 140 */ strcpy(symbol->errtxt, "Older Data Matrix standards are no longer supported"); diff --git a/backend/dmatrix.h b/backend/dmatrix.h index ae9fb4f2..ace161b9 100644 --- a/backend/dmatrix.h +++ b/backend/dmatrix.h @@ -44,7 +44,7 @@ extern "C" { #endif /* __cplusplus */ - extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], const int length); + extern int data_matrix_200(struct zint_symbol *symbol, const unsigned char source[], const int length); #ifdef __cplusplus } diff --git a/backend/dotcode.c b/backend/dotcode.c index 993506ea..a3a6c8dd 100644 --- a/backend/dotcode.c +++ b/backend/dotcode.c @@ -38,11 +38,11 @@ #include #include #include +#include #ifndef _MSC_VER #include #else #include -#include "ms_stdint.h" #endif #include "common.h" #include "gs1.h" @@ -160,7 +160,7 @@ int score_array(char Dots[], int Hgt, int Wid) { if ((!get_dot(Dots, Hgt, Wid, x - 1, y - 1)) && (!get_dot(Dots, Hgt, Wid, x + 1, y - 1)) && (!get_dot(Dots, Hgt, Wid, x - 1, y + 1)) - &&(!get_dot(Dots, Hgt, Wid, x + 1, y + 1)) + && (!get_dot(Dots, Hgt, Wid, x + 1, y + 1)) && ((!get_dot(Dots, Hgt, Wid, x, y)) || ((!get_dot(Dots, Hgt, Wid, x - 2, y)) && (!get_dot(Dots, Hgt, Wid, x, y - 2)) @@ -223,7 +223,7 @@ void rsencode(int nd, int nc, unsigned char *wd) { } /* Check if the next character is directly encodable in code set A (Annex F.II.D) */ -int datum_a(unsigned char source[], int position, int length) { +int datum_a(const unsigned char source[], int position, int length) { int retval = 0; if (position < length) { @@ -236,7 +236,7 @@ int datum_a(unsigned char source[], int position, int length) { } /* Check if the next character is directly encodable in code set B (Annex F.II.D) */ -int datum_b(unsigned char source[], int position, int length) { +int datum_b(const unsigned char source[], int position, int length) { int retval = 0; if (position < length) { @@ -263,7 +263,7 @@ int datum_b(unsigned char source[], int position, int length) { } /* Check if the next characters are directly encodable in code set C (Annex F.II.D) */ -int datum_c(unsigned char source[], int position, int length) { +int datum_c(const unsigned char source[], int position, int length) { int retval = 0; if (position < length - 2) { @@ -276,7 +276,7 @@ int datum_c(unsigned char source[], int position, int length) { } /* Returns how many consecutive digits lie immediately ahead (Annex F.II.A) */ -int n_digits(unsigned char source[], int position, int length) { +int n_digits(const unsigned char source[], int position, int length) { int i; for (i = position; ((source[i] >= '0') && (source[i] <= '9')) && (i < length); i++); @@ -285,7 +285,7 @@ int n_digits(unsigned char source[], int position, int length) { } /* checks ahead for 10 or more digits starting "17xxxxxx10..." (Annex F.II.B) */ -int seventeen_ten(unsigned char source[], int position, int length) { +int seventeen_ten(const unsigned char source[], int position, int length) { int found = 0; if (n_digits(source, position, length) >= 10) { @@ -301,9 +301,9 @@ int seventeen_ten(unsigned char source[], int position, int length) { /* checks how many characters ahead can be reached while datum_c is true, * returning the resulting number of codewords (Annex F.II.E) */ -int ahead_c(unsigned char source[], int position, int length) { +int ahead_c(const unsigned char source[], int position, int length) { int count = 0; - int i; + int i; for (i = position; (i < length) && datum_c(source, i, length); i += 2) { count++; @@ -313,7 +313,7 @@ int ahead_c(unsigned char source[], int position, int length) { } /* Annex F.II.F */ -int try_c(unsigned char source[], int position, int length) { +int try_c(const unsigned char source[], int position, int length) { int retval = 0; if (n_digits(source, position, length) > 0) { @@ -326,9 +326,9 @@ int try_c(unsigned char source[], int position, int length) { } /* Annex F.II.G */ -int ahead_a(unsigned char source[], int position, int length) { +int ahead_a(const unsigned char source[], int position, int length) { int count = 0; - int i; + int i; for (i = position; ((i < length) && datum_a(source, i, length)) && (try_c(source, i, length) < 2); i++) { @@ -339,9 +339,9 @@ int ahead_a(unsigned char source[], int position, int length) { } /* Annex F.II.H */ -int ahead_b(unsigned char source[], int position, int length) { +int ahead_b(const unsigned char source[], int position, int length) { int count = 0; - int i; + int i; for (i = position; ((i < length) && datum_b(source, i, length)) && (try_c(source, i, length) < 2); i++) { @@ -352,7 +352,7 @@ int ahead_b(unsigned char source[], int position, int length) { } /* checks if the next character is in the range 128 to 255 (Annex F.II.I) */ -int binary(unsigned char source[], int position, int length) { +int binary(const unsigned char source[], int position, int length) { int retval = 0; if (source[position] >= 128) { @@ -363,7 +363,7 @@ int binary(unsigned char source[], int position, int length) { } /* Analyse input data stream and encode using algorithm from Annex F */ -int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], int length, unsigned char *codeword_array) { +int dotcode_encode_message(struct zint_symbol *symbol, const unsigned char source[], int length, unsigned char *codeword_array) { int input_position, array_length, i; char encoding_mode; int inside_macro, done; @@ -391,7 +391,7 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i codeword_array[array_length] = 107; // FNC1 array_length++; } - + if (symbol->eci > 3) { codeword_array[array_length] = 108; // FNC2 array_length++; @@ -889,7 +889,7 @@ int dotcode_encode_message(struct zint_symbol *symbol, unsigned char source[], i } /* Convert codewords to binary data stream */ -int make_dotstream(unsigned char masked_array[], int array_length, char dot_stream[]) { +static size_t make_dotstream(unsigned char masked_array[], int array_length, char dot_stream[]) { int i, j; int mask = 0x100; @@ -1035,14 +1035,15 @@ void fold_dotstream(char dot_stream[], int width, int height, char dot_array[]) } } -int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) { +int dotcode(struct zint_symbol *symbol, const unsigned char source[], int length) { int i, j, k; + size_t jc; int data_length, ecc_length; int min_dots, n_dots; int height, width, pad_chars; int mask_score[4]; int weight; - int dot_stream_length; + size_t dot_stream_length; int high_score, best_mask; int debug = 0; @@ -1065,10 +1066,10 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) { } min_dots = 9 * (data_length + 3 + (data_length / 2)) + 2; - + if (symbol->option_2 == 0) { - height = sqrt(2 * min_dots); + height = (int) sqrt(2.0 * min_dots); if (height % 2) { height++; } @@ -1092,16 +1093,19 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) { strcpy(symbol->errtxt, "Specified symbol size is too large"); return ZINT_ERROR_INVALID_OPTION; } - + n_dots = (height * width) / 2; #ifndef _MSC_VER - char dot_stream[n_dots + 3]; - char dot_array[width * height]; + char dot_stream[height * width * 3]; + char dot_array[width * height * sizeof (char) ]; #else - dot_stream = (char *) _alloca((n_dots + 3) * sizeof (char)); + dot_stream = (char *) _alloca(height * width * 3); + if (!dot_stream) return ZINT_ERROR_MEMORY; + dot_array = (char *) _alloca(width * height * sizeof (char)); -#endif /* _MSC_VER */ + if (!dot_array) return ZINT_ERROR_MEMORY; +#endif /* Add pad characters */ for (pad_chars = 0; 9 * ((data_length + pad_chars + 3 + ((data_length + pad_chars) / 2)) + 2) < n_dots; pad_chars++); @@ -1116,7 +1120,7 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) { codeword_array[data_length] = 106; // Pad data_length++; } - + if (data_length > 450) { // Larger data sets than this cause rsencode() to throw SIGSEGV // This should probably be fixed by somebody who understands what rsencode() does... @@ -1125,7 +1129,7 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) { } ecc_length = 3 + (data_length / 2); - + /* Evaluate data mask options */ for (i = 0; i < 4; i++) { switch (i) { @@ -1160,16 +1164,16 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) { } break; } - + rsencode(data_length + 1, ecc_length, masked_codeword_array); dot_stream_length = make_dotstream(masked_codeword_array, (data_length + ecc_length + 1), dot_stream); - + /* Add pad bits */ - for (j = dot_stream_length; j < n_dots; j++) { + for (jc = dot_stream_length; jc < n_dots; jc++) { strcat(dot_stream, "1"); } - + fold_dotstream(dot_stream, width, height, dot_array); mask_score[i] = score_array(dot_array, height, width); @@ -1220,7 +1224,7 @@ int dotcode(struct zint_symbol *symbol, unsigned char source[], int length) { dot_stream_length = make_dotstream(masked_codeword_array, (data_length + ecc_length + 1), dot_stream); /* Add pad bits */ - for (j = dot_stream_length; j < n_dots; j++) { + for (jc = dot_stream_length; jc < n_dots; jc++) { strcat(dot_stream, "1"); } diff --git a/backend/eci.c b/backend/eci.c index d4e6ca75..9248341d 100644 --- a/backend/eci.c +++ b/backend/eci.c @@ -31,8 +31,12 @@ #include #include +#include #include "eci.h" #include "zint.h" +#ifdef _MSC_VER +#include +#endif /* Convert Unicode to other character encodings */ int utf_to_eci(int eci, const unsigned char source[], unsigned char dest[], int *length) { @@ -51,19 +55,19 @@ int utf_to_eci(int eci, const unsigned char source[], unsigned char dest[], int dest[*length] = '\0'; return 0; } - + in_posn = 0; out_posn = 0; do { /* Single byte (ASCII) character */ bytelen = 1; - glyph = (int)source[in_posn]; - + glyph = (int) source[in_posn]; + if ((source[in_posn] >= 0x80) && (source[in_posn] < 0xc0)) { /* Something has gone wrong, abort */ return ZINT_ERROR_INVALID_DATA; } - + if ((source[in_posn] >= 0xc0) && (source[in_posn] < 0xe0)) { /* Two-byte character */ bytelen = 2; @@ -72,78 +76,78 @@ int utf_to_eci(int eci, const unsigned char source[], unsigned char dest[], int if (*length < (in_posn + 2)) { return ZINT_ERROR_INVALID_DATA; } - + if (source[in_posn + 1] > 0xc0) { return ZINT_ERROR_INVALID_DATA; } - + glyph += (source[in_posn + 1] & 0x3f); } - + if ((source[in_posn] >= 0xe0) && (source[in_posn] < 0xf0)) { /* Three-byte character */ bytelen = 3; glyph = (source[in_posn] & 0x0f) << 12; - + if (*length < (in_posn + 2)) { return ZINT_ERROR_INVALID_DATA; } - + if (*length < (in_posn + 3)) { return ZINT_ERROR_INVALID_DATA; } - + if (source[in_posn + 1] > 0xc0) { return ZINT_ERROR_INVALID_DATA; } - + if (source[in_posn + 2] > 0xc0) { return ZINT_ERROR_INVALID_DATA; } - + glyph += (source[in_posn + 1] & 0x3f) << 6; glyph += (source[in_posn + 2] & 0x3f); } - + if ((source[in_posn] >= 0xf0) && (source[in_posn] < 0xf7)) { /* Four-byte character */ bytelen = 4; glyph = (source[in_posn] & 0x07) << 18; - + if (*length < (in_posn + 2)) { return ZINT_ERROR_INVALID_DATA; } - + if (*length < (in_posn + 3)) { return ZINT_ERROR_INVALID_DATA; } - + if (*length < (in_posn + 4)) { return ZINT_ERROR_INVALID_DATA; } - + if (source[in_posn + 1] > 0xc0) { return ZINT_ERROR_INVALID_DATA; } - + if (source[in_posn + 2] > 0xc0) { return ZINT_ERROR_INVALID_DATA; } - + if (source[in_posn + 3] > 0xc0) { return ZINT_ERROR_INVALID_DATA; } - + glyph += (source[in_posn + 1] & 0x3f) << 12; glyph += (source[in_posn + 2] & 0x3f) << 6; glyph += (source[in_posn + 3] & 0x3f); } - + if (source[in_posn] >= 0xf7) { /* More than 4 bytes not supported */ return ZINT_ERROR_INVALID_DATA; } - + if (glyph < 128) { dest[out_posn] = glyph; } else { @@ -268,12 +272,12 @@ int utf_to_eci(int eci, const unsigned char source[], unsigned char dest[], int break; } } - + if (!(done)) { return ZINT_ERROR_INVALID_DATA; } } - + in_posn += bytelen; out_posn++; } while (in_posn < *length); @@ -292,14 +296,14 @@ int get_best_eci(unsigned char source[], int length) { #else unsigned char *local_source = (unsigned char*) _alloca(length + 1); #endif - + do { if (utf_to_eci(eci, source, local_source, &length) == 0) { return eci; - } + } eci++; } while (eci < 25); - + return 26; // If all of these fail, use Unicode! } diff --git a/backend/eci.h b/backend/eci.h index 9cd2e708..ac098287 100644 --- a/backend/eci.h +++ b/backend/eci.h @@ -35,214 +35,214 @@ #ifdef __cplusplus extern "C" { #endif - -static int iso_8859_1[] = { // Latin alphabet No. 1 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, - 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, - 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff -}; -static int iso_8859_2[] = { // Latin alphabet No. 2 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, - 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, - 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, - 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, - 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, - 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 -}; + static const int iso_8859_1[] = {// Latin alphabet No. 1 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, + 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, + 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, + 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, + 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff + }; -static int iso_8859_3[] = { // Latin alphabet No. 3 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7, 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b, - 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7, 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0x0000, 0x017c, - 0x00c0, 0x00c1, 0x00c2, 0x0000, 0x00c4, 0x010a, 0x0108, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0x0000, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7, 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df, - 0x00e0, 0x00e1, 0x00e2, 0x0000, 0x00e4, 0x010b, 0x0109, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9 -}; + static const int iso_8859_2[] = {// Latin alphabet No. 2 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, + 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, + 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, + 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, + 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, + 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 + }; -static int iso_8859_4[] = { // Latin alphabet No. 4 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x012b, 0x013b, 0x00a7, 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, - 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, - 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, - 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, - 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b, - 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9 -}; + static const int iso_8859_3[] = {// Latin alphabet No. 3 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, 0x0000, 0x0124, 0x00a7, 0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, 0x0000, 0x017b, + 0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7, 0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, 0x0000, 0x017c, + 0x00c0, 0x00c1, 0x00c2, 0x0000, 0x00c4, 0x010a, 0x0108, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, + 0x0000, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7, 0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df, + 0x00e0, 0x00e1, 0x00e2, 0x0000, 0x00e4, 0x010b, 0x0109, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, + 0x0000, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7, 0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9 + }; -static int iso_8859_5[] = { // Latin/Cyrillic alphabet - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f, - 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, - 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, - 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, - 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, - 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f -}; + static const int iso_8859_4[] = {// Latin alphabet No. 4 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x012b, 0x013b, 0x00a7, 0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af, + 0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7, 0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b, + 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a, + 0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df, + 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b, + 0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9 + }; -static int iso_8859_6[] = { // Latin/Arabic alphabet - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0000, 0x0000, 0x0000, 0x00a4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x060c, 0x00ad, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x061b, 0x0000, 0x0000, 0x0000, 0x061f, - 0x0000, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, - 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, 0x0638, 0x0639, 0x063a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f, - 0x0650, 0x0651, 0x0652, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 -}; + static const int iso_8859_5[] = {// Latin/Cyrillic alphabet + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f, + 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, + 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, + 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, + 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, + 0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457, 0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f + }; -static int iso_8859_7[] = { // Latin/Greek alphabet - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7, 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f, - 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, - 0x03a0, 0x03a1, 0x0000, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, - 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, - 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000 -}; + static const int iso_8859_6[] = {// Latin/Arabic alphabet + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0000, 0x0000, 0x0000, 0x00a4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x060c, 0x00ad, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x061b, 0x0000, 0x0000, 0x0000, 0x061f, + 0x0000, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, + 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, 0x0638, 0x0639, 0x063a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f, + 0x0650, 0x0651, 0x0652, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 + }; -static int iso_8859_8[] = { // Latin/Hebrew alphabet - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0000, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00f7, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2017, - 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, - 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x0000, 0x0000, 0x200e, 0x200f, 0x0000 -}; + static const int iso_8859_7[] = {// Latin/Greek alphabet + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x2018, 0x2019, 0x00a3, 0x20ac, 0x20af, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x037a, 0x00ab, 0x00ac, 0x00ad, 0x0000, 0x2015, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7, 0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f, + 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, + 0x03a0, 0x03a1, 0x0000, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af, + 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, + 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, 0x0000 + }; -static int iso_8859_9[] = { // Latin alphabet No. 5 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, - 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df, - 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff -}; + static const int iso_8859_8[] = {// Latin/Hebrew alphabet + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0000, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00f7, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2017, + 0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, + 0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x0000, 0x0000, 0x200e, 0x200f, 0x0000 + }; -static int iso_8859_10[] = { // Latin alphabet No. 6 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x012b, 0x0136, 0x00a7, 0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a, - 0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7, 0x013c, 0x0111, 0x0161, 0x0167, 0x017e, 0x2015, 0x016b, 0x014b, - 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf, - 0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, - 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x00ef, - 0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138 -}; + static const int iso_8859_9[] = {// Latin alphabet No. 5 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, + 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, + 0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df, + 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, + 0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff + }; -static int iso_8859_11[] = { // Latin/Thai alphabet - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, - 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, - 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, - 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e36, 0x0e36, 0x0e37, 0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0e3f, - 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f, - 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0x0000, 0x0000, 0x0000, 0x0000 -}; + static const int iso_8859_10[] = {// Latin alphabet No. 6 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x012b, 0x0136, 0x00a7, 0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a, + 0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7, 0x013c, 0x0111, 0x0161, 0x0167, 0x017e, 0x2015, 0x016b, 0x014b, + 0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf, + 0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168, 0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, + 0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x00ef, + 0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169, 0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138 + }; -static int iso_8859_13[] = { // Latin alphabet No. 7 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x201d, 0x00a2, 0x00a3, 0x00a4, 0x201e, 0x00a6, 0x00a7, 0x00d8, 0x00a9, 0x0156, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00c6, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x201c, 0x00b5, 0x00b6, 0x00b7, 0x00f8, 0x00b9, 0x0157, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00e6, - 0x0104, 0x012e, 0x0100, 0x0106, 0x00c4, 0x00c5, 0x0118, 0x0112, 0x010c, 0x00c9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012a, 0x013b, - 0x0160, 0x0143, 0x0145, 0x00d3, 0x014c, 0x00d5, 0x00d6, 0x00d7, 0x0172, 0x0141, 0x015a, 0x016a, 0x00dc, 0x017b, 0x017d, 0x00df, - 0x0105, 0x012f, 0x0101, 0x0107, 0x00e4, 0x00e5, 0x0119, 0x0113, 0x010d, 0x00e9, 0x017a, 0x0117, 0x0123, 0x0137, 0x012b, 0x013c, - 0x0161, 0x0144, 0x0146, 0x00f3, 0x014d, 0x00f5, 0x00f6, 0x00f7, 0x0173, 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x2019 -}; + static const int iso_8859_11[] = {// Latin/Thai alphabet + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0e01, 0x0e02, 0x0e03, 0x0e04, 0x0e05, 0x0e06, 0x0e07, 0x0e08, 0x0e09, 0x0e0a, 0x0e0b, 0x0e0c, 0x0e0d, 0x0e0e, 0x0e0f, + 0x0e10, 0x0e11, 0x0e12, 0x0e13, 0x0e14, 0x0e15, 0x0e16, 0x0e17, 0x0e18, 0x0e19, 0x0e1a, 0x0e1b, 0x0e1c, 0x0e1d, 0x0e1e, 0x0e1f, + 0x0e20, 0x0e21, 0x0e22, 0x0e23, 0x0e24, 0x0e25, 0x0e26, 0x0e27, 0x0e28, 0x0e29, 0x0e2a, 0x0e2b, 0x0e2c, 0x0e2d, 0x0e2e, 0x0e2f, + 0x0e30, 0x0e31, 0x0e32, 0x0e33, 0x0e34, 0x0e36, 0x0e36, 0x0e37, 0x0e38, 0x0e39, 0x0e3a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0e3f, + 0x0e40, 0x0e41, 0x0e42, 0x0e43, 0x0e44, 0x0e45, 0x0e46, 0x0e47, 0x0e48, 0x0e49, 0x0e4a, 0x0e4b, 0x0e4c, 0x0e4d, 0x0e4e, 0x0e4f, + 0x0e50, 0x0e51, 0x0e52, 0x0e53, 0x0e54, 0x0e55, 0x0e56, 0x0e57, 0x0e58, 0x0e59, 0x0e5a, 0x0e5b, 0x0000, 0x0000, 0x0000, 0x0000 + }; -static int iso_8859_14[] = { // Latin alphabet No. 8 (Celtic) - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178, - 0x1e1e, 0x1e1f, 0x0120, 0x0121, 0x1e40, 0x1e41, 0x00b6, 0x1e56, 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, - 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0x0174, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x1e6a, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0176, 0x00df, - 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff -}; + static const int iso_8859_13[] = {// Latin alphabet No. 7 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x201d, 0x00a2, 0x00a3, 0x00a4, 0x201e, 0x00a6, 0x00a7, 0x00d8, 0x00a9, 0x0156, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00c6, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x201c, 0x00b5, 0x00b6, 0x00b7, 0x00f8, 0x00b9, 0x0157, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00e6, + 0x0104, 0x012e, 0x0100, 0x0106, 0x00c4, 0x00c5, 0x0118, 0x0112, 0x010c, 0x00c9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012a, 0x013b, + 0x0160, 0x0143, 0x0145, 0x00d3, 0x014c, 0x00d5, 0x00d6, 0x00d7, 0x0172, 0x0141, 0x015a, 0x016a, 0x00dc, 0x017b, 0x017d, 0x00df, + 0x0105, 0x012f, 0x0101, 0x0107, 0x00e4, 0x00e5, 0x0119, 0x0113, 0x010d, 0x00e9, 0x017a, 0x0117, 0x0123, 0x0137, 0x012b, 0x013c, + 0x0161, 0x0144, 0x0146, 0x00f3, 0x014d, 0x00f5, 0x00f6, 0x00f7, 0x0173, 0x0142, 0x015b, 0x016b, 0x00fc, 0x017c, 0x017e, 0x2019 + }; -static int iso_8859_15[] = { // Latin alphabet No. 9 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x017d, 0x00b5, 0x00b6, 0x00b7, 0x017e, 0x00b9, 0x00ba, 0x00bb, 0x0152, 0x0153, 0x0178, 0x00bf, - 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, - 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff -}; + static const int iso_8859_14[] = {// Latin alphabet No. 8 (Celtic) + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x1e02, 0x1e03, 0x00a3, 0x010a, 0x010b, 0x1e0a, 0x00a7, 0x1e80, 0x00a9, 0x1e82, 0x1e0b, 0x1ef2, 0x00ad, 0x00ae, 0x0178, + 0x1e1e, 0x1e1f, 0x0120, 0x0121, 0x1e40, 0x1e41, 0x00b6, 0x1e56, 0x1e81, 0x1e57, 0x1e83, 0x1e60, 0x1ef3, 0x1e84, 0x1e85, 0x1e61, + 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, + 0x0174, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x1e6a, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x0176, 0x00df, + 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, + 0x0175, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x1e6b, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x0177, 0x00ff + }; -static int iso_8859_16[] = { // Latin alphabet No. 10 - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x00a0, 0x0104, 0x0105, 0x0141, 0x20ac, 0x201e, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x0218, 0x00ab, 0x0179, 0x00ad, 0x017a, 0x017b, - 0x00b0, 0x00b1, 0x010c, 0x0142, 0x017d, 0x201d, 0x00b6, 0x00b7, 0x017e, 0x010d, 0x0219, 0x00bb, 0x0152, 0x0153, 0x0178, 0x017c, - 0x00c0, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0106, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0x00e0, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x0107, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0x0111, 0x0144, 0x00f2, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x015b, 0x0171, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0119, 0x021b, 0x00ff -}; + static const int iso_8859_15[] = {// Latin alphabet No. 9 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x017d, 0x00b5, 0x00b6, 0x00b7, 0x017e, 0x00b9, 0x00ba, 0x00bb, 0x0152, 0x0153, 0x0178, 0x00bf, + 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, + 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, + 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, + 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff + }; -static int windows_1250[] = { - 0x20ac, 0x0000, 0x201a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021, 0x0000, 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179, - 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0000, 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a, - 0x00a0, 0x02c7, 0x02db, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, - 0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c, - 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, - 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, - 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, - 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 -}; + static const int iso_8859_16[] = {// Latin alphabet No. 10 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x00a0, 0x0104, 0x0105, 0x0141, 0x20ac, 0x201e, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x0218, 0x00ab, 0x0179, 0x00ad, 0x017a, 0x017b, + 0x00b0, 0x00b1, 0x010c, 0x0142, 0x017d, 0x201d, 0x00b6, 0x00b7, 0x017e, 0x010d, 0x0219, 0x00bb, 0x0152, 0x0153, 0x0178, 0x017c, + 0x00c0, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0106, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, + 0x00e0, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x0107, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, + 0x0111, 0x0144, 0x00f2, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x015b, 0x0171, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0119, 0x021b, 0x00ff + }; -static int windows_1251[] = { - 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac, 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f, - 0x0452, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0000, 0x2122, 0x0459, 0x203a, 0x045a, 0x045c, 0x045b, 0x045f, - 0x00a0, 0x040e, 0x045e, 0x0408, 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x0407, - 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5, 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455, 0x0457, - 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, - 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, - 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, - 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f -}; + static const int windows_1250[] = { + 0x20ac, 0x0000, 0x201a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021, 0x0000, 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179, + 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0000, 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a, + 0x00a0, 0x02c7, 0x02db, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, + 0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c, + 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, + 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, + 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, + 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 + }; -static int windows_1252[] = { - 0x20ac, 0x0000, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017d, 0x0000, - 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x0000, 0x017e, 0x0178, - 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, - 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, - 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, - 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, - 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff -}; + static const int windows_1251[] = { + 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac, 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f, + 0x0452, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0000, 0x2122, 0x0459, 0x203a, 0x045a, 0x045c, 0x045b, 0x045f, + 0x00a0, 0x040e, 0x045e, 0x0408, 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x0407, + 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5, 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455, 0x0457, + 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, + 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, + 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, + 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f + }; -static int windows_1256[] = { - 0x20ac, 0x067e, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688, - 0x06af, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x06a9, 0x2122, 0x0691, 0x203a, 0x0153, 0x200c, 0x200d, 0x06ba, - 0x00a0, 0x060c, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x06be, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, - 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x061b, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x061f, - 0x06c1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, - 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00d7, 0x0637, 0x0638, 0x0639, 0x063a, 0x0640, 0x0641, 0x0642, 0x0643, - 0x00e0, 0x0644, 0x00e2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x0649, 0x064a, 0x00ee, 0x00ef, - 0x064b, 0x064c, 0x064d, 0x064e, 0x00f4, 0x064f, 0x0650, 0x00f7, 0x0651, 0x00f9, 0x0652, 0x00fb, 0x00fc, 0x200e, 0x200f, 0x06d2 -}; + static const int windows_1252[] = { + 0x20ac, 0x0000, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017d, 0x0000, + 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x0000, 0x017e, 0x0178, + 0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, + 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, + 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, + 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, + 0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff + }; + + static const int windows_1256[] = { + 0x20ac, 0x067e, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688, + 0x06af, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x06a9, 0x2122, 0x0691, 0x203a, 0x0153, 0x200c, 0x200d, 0x06ba, + 0x00a0, 0x060c, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x06be, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, + 0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x061b, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x061f, + 0x06c1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f, + 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00d7, 0x0637, 0x0638, 0x0639, 0x063a, 0x0640, 0x0641, 0x0642, 0x0643, + 0x00e0, 0x0644, 0x00e2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x0649, 0x064a, 0x00ee, 0x00ef, + 0x064b, 0x064c, 0x064d, 0x064e, 0x00f4, 0x064f, 0x0650, 0x00f7, 0x0651, 0x00f9, 0x0652, 0x00fb, 0x00fc, 0x200e, 0x200f, 0x06d2 + }; #ifdef __cplusplus } diff --git a/backend/gif.c b/backend/gif.c index 757242f6..c0741f2a 100644 --- a/backend/gif.c +++ b/backend/gif.c @@ -34,11 +34,11 @@ #include #include #include "common.h" -#include "pcx.h" /* PCX header structure */ #include #ifdef _MSC_VER #include #include +#include #endif #define SSET "0123456789ABCDEF" @@ -53,232 +53,211 @@ #include typedef struct s_statestruct { - unsigned char * pOut; - unsigned char *pIn; - unsigned int InLen; - unsigned int OutLength; - unsigned int OutPosCur; - unsigned int OutByteCountPos; - unsigned short ClearCode; - unsigned short FreeCode; - char fByteCountByteSet; - unsigned char OutBitsFree; - unsigned short NodeAxon[4096]; - unsigned short NodeNext[4096]; - unsigned char NodePix[4096]; + unsigned char * pOut; + unsigned char *pIn; + unsigned int InLen; + unsigned int OutLength; + unsigned int OutPosCur; + unsigned int OutByteCountPos; + unsigned short ClearCode; + unsigned short FreeCode; + char fByteCountByteSet; + unsigned char OutBitsFree; + unsigned short NodeAxon[4096]; + unsigned short NodeNext[4096]; + unsigned char NodePix[4096]; } statestruct; -static char BufferNextByte(statestruct *pState) -{ - (pState->OutPosCur)++; - /* Check if this position is a byte count position - * fg_f_bytecountbyte_set indicates, if byte count position bytes should be - * inserted in general. - * If this is true, and the distance to the last byte count position is 256 - * (e.g. 255 bytes in between), a byte count byte is inserted, and the value - * of the last one is set to 255. - * */ - if ( pState->fByteCountByteSet && ( pState->OutByteCountPos + 256 == pState->OutPosCur ) ) - { - (pState->pOut)[pState->OutByteCountPos] = 255; - pState->OutByteCountPos = pState->OutPosCur; - (pState->OutPosCur)++; - } - if ( pState->OutPosCur >= pState->OutLength ) - return 1; - (pState->pOut)[pState->OutPosCur]=0x00; - return 0; +static char BufferNextByte(statestruct *pState) { + (pState->OutPosCur)++; + /* Check if this position is a byte count position + * fg_f_bytecountbyte_set indicates, if byte count position bytes should be + * inserted in general. + * If this is true, and the distance to the last byte count position is 256 + * (e.g. 255 bytes in between), a byte count byte is inserted, and the value + * of the last one is set to 255. + * */ + if (pState->fByteCountByteSet && (pState->OutByteCountPos + 256 == pState->OutPosCur)) { + (pState->pOut)[pState->OutByteCountPos] = 255; + pState->OutByteCountPos = pState->OutPosCur; + (pState->OutPosCur)++; + } + if (pState->OutPosCur >= pState->OutLength) + return 1; + (pState->pOut)[pState->OutPosCur] = 0x00; + return 0; } -static char AddCodeToBuffer(statestruct *pState, unsigned short CodeIn,unsigned char CodeBits) -{ - /* Check, if we may fill up the current byte completely */ - if (CodeBits >= pState->OutBitsFree) - { - (pState->pOut)[pState->OutPosCur] |= (unsigned char) - ( CodeIn << ( 8 - pState->OutBitsFree ) ); - if ( BufferNextByte(pState) ) - return -1; - CodeIn = (unsigned short) ( CodeIn >> pState->OutBitsFree ); - CodeBits -= pState->OutBitsFree; - pState->OutBitsFree = 8; - /* Write a full byte if there are at least 8 code bits left */ - if (CodeBits >= pState->OutBitsFree) - { - (pState->pOut)[pState->OutPosCur] = (unsigned char) CodeIn; - if ( BufferNextByte(pState) ) - return -1; - CodeIn = (unsigned short) ( CodeIn >> 8 ); - CodeBits -= 8; - } - } - /* The remaining bits of CodeIn fit in the current byte. */ - if( CodeBits > 0 ) - { - (pState->pOut)[pState->OutPosCur] |= (unsigned char) - ( CodeIn << ( 8 - pState->OutBitsFree ) ); - pState->OutBitsFree -= CodeBits; - } - return 0; +static char AddCodeToBuffer(statestruct *pState, unsigned short CodeIn, unsigned char CodeBits) { + /* Check, if we may fill up the current byte completely */ + if (CodeBits >= pState->OutBitsFree) { + (pState->pOut)[pState->OutPosCur] |= (unsigned char) + (CodeIn << (8 - pState->OutBitsFree)); + if (BufferNextByte(pState)) + return -1; + CodeIn = (unsigned short) (CodeIn >> pState->OutBitsFree); + CodeBits -= pState->OutBitsFree; + pState->OutBitsFree = 8; + /* Write a full byte if there are at least 8 code bits left */ + if (CodeBits >= pState->OutBitsFree) { + (pState->pOut)[pState->OutPosCur] = (unsigned char) CodeIn; + if (BufferNextByte(pState)) + return -1; + CodeIn = (unsigned short) (CodeIn >> 8); + CodeBits -= 8; + } + } + /* The remaining bits of CodeIn fit in the current byte. */ + if (CodeBits > 0) { + (pState->pOut)[pState->OutPosCur] |= (unsigned char) + (CodeIn << (8 - pState->OutBitsFree)); + pState->OutBitsFree -= CodeBits; + } + return 0; } -static void FlushStringTable(statestruct *pState) -{ - unsigned short Pos; - for( Pos = 0; Pos < pState->ClearCode; Pos++ ) - { - (pState->NodeAxon)[Pos] = 0; - } +static void FlushStringTable(statestruct *pState) { + unsigned short Pos; + for (Pos = 0; Pos < pState->ClearCode; Pos++) { + (pState->NodeAxon)[Pos] = 0; + } } +unsigned short FindPixelOutlet(statestruct *pState, unsigned short HeadNode, unsigned char Byte) { + unsigned short Outlet; -unsigned short FindPixelOutlet( statestruct *pState, unsigned short HeadNode, unsigned char Byte ) -{ - unsigned short Outlet; - - Outlet = (pState->NodeAxon)[HeadNode]; - while( Outlet ) - { - if ( (pState->NodePix)[Outlet] == Byte ) - return Outlet; - Outlet = (pState->NodeNext)[Outlet]; - } - return 0; + Outlet = (pState->NodeAxon)[HeadNode]; + while (Outlet) { + if ((pState->NodePix)[Outlet] == Byte) + return Outlet; + Outlet = (pState->NodeNext)[Outlet]; + } + return 0; } -static char NextCode ( statestruct *pState, unsigned char * pPixelValueCur, unsigned char CodeBits ) -{ - unsigned short UpNode; - unsigned short DownNode; - /* start with the root node for last pixel chain */ - UpNode = *pPixelValueCur; - if ( (pState->InLen) == 0 ) - return AddCodeToBuffer(pState, UpNode, CodeBits ); - - *pPixelValueCur = (*(pState->pIn))-'0'; - (pState->pIn)++; - (pState->InLen)--; - /* Follow the string table and the data stream to the end of the longest string that has a code */ - while( 0 != ( DownNode = FindPixelOutlet(pState, UpNode, *pPixelValueCur ) ) ) - { - UpNode = DownNode; - if ( (pState->InLen) == 0 ) - return AddCodeToBuffer(pState, UpNode, CodeBits); - - *pPixelValueCur = (*(pState->pIn)) - '0'; - (pState->pIn)++; - (pState->InLen)--; - } - /* Submit 'UpNode' which is the code of the longest string */ - if ( AddCodeToBuffer(pState, UpNode, CodeBits ) ) - return -1; - /* ... and extend the string by appending 'PixelValueCur' */ - /* Create a successor node for 'PixelValueCur' whose code is 'freecode' */ - (pState->NodePix)[pState->FreeCode] = *pPixelValueCur; - (pState->NodeAxon)[pState->FreeCode] = (pState->NodeNext)[pState->FreeCode]=0; - /* ...and link it to the end of the chain emanating from fg_axon[UpNode]. */ - DownNode = (pState->NodeAxon)[UpNode]; - if( ! DownNode ) - { - (pState->NodeAxon)[UpNode] = pState->FreeCode; - } else { - while( (pState->NodeNext)[DownNode] ) - { - DownNode = (pState->NodeNext)[DownNode]; - } - (pState->NodeNext)[DownNode] = pState->FreeCode; - } - return 1; +static char NextCode(statestruct *pState, unsigned char * pPixelValueCur, unsigned char CodeBits) { + unsigned short UpNode; + unsigned short DownNode; + /* start with the root node for last pixel chain */ + UpNode = *pPixelValueCur; + if ((pState->InLen) == 0) + return AddCodeToBuffer(pState, UpNode, CodeBits); + + *pPixelValueCur = (*(pState->pIn)) - '0'; + (pState->pIn)++; + (pState->InLen)--; + /* Follow the string table and the data stream to the end of the longest string that has a code */ + while (0 != (DownNode = FindPixelOutlet(pState, UpNode, *pPixelValueCur))) { + UpNode = DownNode; + if ((pState->InLen) == 0) + return AddCodeToBuffer(pState, UpNode, CodeBits); + + *pPixelValueCur = (*(pState->pIn)) - '0'; + (pState->pIn)++; + (pState->InLen)--; + } + /* Submit 'UpNode' which is the code of the longest string */ + if (AddCodeToBuffer(pState, UpNode, CodeBits)) + return -1; + /* ... and extend the string by appending 'PixelValueCur' */ + /* Create a successor node for 'PixelValueCur' whose code is 'freecode' */ + (pState->NodePix)[pState->FreeCode] = *pPixelValueCur; + (pState->NodeAxon)[pState->FreeCode] = (pState->NodeNext)[pState->FreeCode] = 0; + /* ...and link it to the end of the chain emanating from fg_axon[UpNode]. */ + DownNode = (pState->NodeAxon)[UpNode]; + if (!DownNode) { + (pState->NodeAxon)[UpNode] = pState->FreeCode; + } else { + while ((pState->NodeNext)[DownNode]) { + DownNode = (pState->NodeNext)[DownNode]; + } + (pState->NodeNext)[DownNode] = pState->FreeCode; + } + return 1; } -int gif_lzw(unsigned char *pOut, int OutLength, unsigned char *pIn, int InLen) -{ - unsigned char PixelValueCur; - unsigned char CodeBits; - unsigned short Pos; - statestruct State; - - State.pIn = pIn; - State.InLen = InLen; - State.pOut = pOut; - State.OutLength = OutLength; - // > Get first data byte - if (State.InLen == 0) - return 0; - - PixelValueCur = (unsigned char) ((*(State.pIn)) - '0'); - (State.pIn)++; - (State.InLen)--; - CodeBits = 3; - State.ClearCode = 4; - State.FreeCode = 6; - State.OutBitsFree = 8; - State.OutPosCur = -1; - State.fByteCountByteSet = 0; - - if ( BufferNextByte(&State) ) - return 0; - - for ( Pos = 0; Pos < State.ClearCode; Pos++) - State.NodePix[Pos] = (unsigned char) Pos; - - FlushStringTable(&State); - - /* Write what the GIF specification calls the "code size". */ - (State.pOut)[State.OutPosCur] = 2; - /* Reserve first bytecount byte */ - if ( BufferNextByte(&State) ) - return 0; - State.OutByteCountPos = State.OutPosCur; - if ( BufferNextByte(&State) ) - return 0; - State.fByteCountByteSet = 1; - /* Submit one 'ClearCode' as the first code */ - if ( AddCodeToBuffer(&State, State.ClearCode, CodeBits) ) - return 0; - - for(;;) - { - char Res; - /* generate and save the next code, which may consist of multiple input pixels. */ - Res = NextCode(&State, &PixelValueCur, CodeBits); - if ( Res < 0) - return 0; - //* Check for end of data stream */ - if( ! Res ) - { - /* submit 'eoi' as the last item of the code stream */ - if ( AddCodeToBuffer(&State, (unsigned short)(State.ClearCode + 1), CodeBits ) ) - return 0; - State.fByteCountByteSet = 0; - if( State.OutBitsFree < 8 ) - { - if ( BufferNextByte(&State) ) - return 0; - } - // > Update last bytecount byte; - if ( State.OutByteCountPos < State.OutPosCur ) - { - (State.pOut)[State.OutByteCountPos] = (unsigned char) (State.OutPosCur - State.OutByteCountPos - 1); - } - State.OutPosCur++; - return State.OutPosCur; - } - /* Check for currently last code */ - if( State.FreeCode == ( 1U << CodeBits ) ) - CodeBits++; - State.FreeCode++; - /* Check for full stringtable */ - if( State.FreeCode == 0xfff ) - { - FlushStringTable(&State); - if ( AddCodeToBuffer(&State, State.ClearCode, CodeBits ) ) - return 0; - - CodeBits=(unsigned char)( 1 + 2 ); - State.FreeCode=(unsigned short)( State.ClearCode + 2 ); - } - } +int gif_lzw(unsigned char *pOut, int OutLength, unsigned char *pIn, int InLen) { + unsigned char PixelValueCur; + unsigned char CodeBits; + unsigned short Pos; + statestruct State; + + State.pIn = pIn; + State.InLen = InLen; + State.pOut = pOut; + State.OutLength = OutLength; + // > Get first data byte + if (State.InLen == 0) + return 0; + + PixelValueCur = (unsigned char) ((*(State.pIn)) - '0'); + (State.pIn)++; + (State.InLen)--; + CodeBits = 3; + State.ClearCode = 4; + State.FreeCode = 6; + State.OutBitsFree = 8; + State.OutPosCur = -1; + State.fByteCountByteSet = 0; + + if (BufferNextByte(&State)) + return 0; + + for (Pos = 0; Pos < State.ClearCode; Pos++) + State.NodePix[Pos] = (unsigned char) Pos; + + FlushStringTable(&State); + + /* Write what the GIF specification calls the "code size". */ + (State.pOut)[State.OutPosCur] = 2; + /* Reserve first bytecount byte */ + if (BufferNextByte(&State)) + return 0; + State.OutByteCountPos = State.OutPosCur; + if (BufferNextByte(&State)) + return 0; + State.fByteCountByteSet = 1; + /* Submit one 'ClearCode' as the first code */ + if (AddCodeToBuffer(&State, State.ClearCode, CodeBits)) + return 0; + + for (;;) { + char Res; + /* generate and save the next code, which may consist of multiple input pixels. */ + Res = NextCode(&State, &PixelValueCur, CodeBits); + if (Res < 0) + return 0; + //* Check for end of data stream */ + if (!Res) { + /* submit 'eoi' as the last item of the code stream */ + if (AddCodeToBuffer(&State, (unsigned short) (State.ClearCode + 1), CodeBits)) + return 0; + State.fByteCountByteSet = 0; + if (State.OutBitsFree < 8) { + if (BufferNextByte(&State)) + return 0; + } + // > Update last bytecount byte; + if (State.OutByteCountPos < State.OutPosCur) { + (State.pOut)[State.OutByteCountPos] = (unsigned char) (State.OutPosCur - State.OutByteCountPos - 1); + } + State.OutPosCur++; + return State.OutPosCur; + } + /* Check for currently last code */ + if (State.FreeCode == (1U << CodeBits)) + CodeBits++; + State.FreeCode++; + /* Check for full stringtable */ + if (State.FreeCode == 0xfff) { + FlushStringTable(&State); + if (AddCodeToBuffer(&State, State.ClearCode, CodeBits)) + return 0; + + CodeBits = (unsigned char) (1 + 2); + State.FreeCode = (unsigned short) (State.ClearCode + 2); + } + } } int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) { @@ -286,21 +265,21 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width int errno; int row, column; FILE *gif_file; - unsigned short ImageWidth = image_width; - unsigned short ImageHeight = image_height; - unsigned short usTemp; + unsigned short ImageWidth = image_width; + unsigned short ImageHeight = image_height; + unsigned short usTemp; int byte_out; #ifdef _MSC_VER - char* rotated_bitmap; + char* rotated_bitmap; char * lzwoutbuf; #endif - + #ifndef _MSC_VER char rotated_bitmap[image_height * image_width]; char lzwoutbuf[image_height * image_width]; #else - rotated_bitmap = (char *) _alloca((image_height * image_width) * sizeof(char)); - lzwoutbuf = (char *) _alloca((image_height * image_width) * sizeof(char)); + rotated_bitmap = (char *) _alloca((image_height * image_width) * sizeof (char)); + lzwoutbuf = (char *) _alloca((image_height * image_width) * sizeof (char)); #endif /* _MSC_VER */ switch (rotate_angle) { @@ -376,9 +355,9 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width } break; } - - - + + + /* Open output file in binary mode */ if ((symbol->output_options & BARCODE_STDOUT) != 0) { #ifdef _MSC_VER @@ -400,26 +379,26 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width rotated_bitmap[1] = 1; rotated_bitmap[2] = 0; rotated_bitmap[3] = 0; - */ + */ /* GIF signature (6) */ - memcpy(outbuf,"GIF87a",6); - if ( TRANSPARENT_INDEX != -1 ) - outbuf[4]='9'; + memcpy(outbuf, "GIF87a", 6); + if (TRANSPARENT_INDEX != -1) + outbuf[4] = '9'; fwrite(outbuf, 6, 1, gif_file); /* Screen Descriptor (7) */ /* Screen Width */ - usTemp=(unsigned short)ImageWidth; - outbuf[0] = (unsigned char)(0xff & usTemp); - outbuf[1] = (unsigned char)( (0xff00 & usTemp) / 0x100 ); + usTemp = (unsigned short) ImageWidth; + outbuf[0] = (unsigned char) (0xff & usTemp); + outbuf[1] = (unsigned char) ((0xff00 & usTemp) / 0x100); /* Screen Height */ - usTemp=(unsigned short)ImageHeight; - outbuf[2] = (unsigned char)( 0xff & usTemp ); - outbuf[3] = (unsigned char)( (0xff00 & usTemp) / 0x100 ); + usTemp = (unsigned short) ImageHeight; + outbuf[2] = (unsigned char) (0xff & usTemp); + outbuf[3] = (unsigned char) ((0xff00 & usTemp) / 0x100); /* write ImageBits-1 to the three least significant bits of byte 5 of * the Screen Descriptor */ - outbuf[4] = (unsigned char)( 0xf0 | (0x7&(DESTINATION_IMAGE_BITS-1)) ); + outbuf[4] = (unsigned char) (0xf0 | (0x7 & (DESTINATION_IMAGE_BITS - 1))); /* Background color = colortable index 0 */ outbuf[5] = 0x00; /* Byte 7 must be 0x00 */ @@ -427,21 +406,20 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width fwrite(outbuf, 7, 1, gif_file); /* Global Color Table (6) */ /* RGB 0 color */ - outbuf[0] = (unsigned char)(16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); - outbuf[1] = (unsigned char)(16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); - outbuf[2] = (unsigned char)(16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); + outbuf[0] = (unsigned char) (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); + outbuf[1] = (unsigned char) (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); + outbuf[2] = (unsigned char) (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); /* RGB 1 color */ - outbuf[3] = (unsigned char)(16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); - outbuf[4] = (unsigned char)(16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); - outbuf[5] = (unsigned char)(16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); + outbuf[3] = (unsigned char) (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); + outbuf[4] = (unsigned char) (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); + outbuf[5] = (unsigned char) (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); fwrite(outbuf, 6, 1, gif_file); /* Graphic control extension (8) */ /* A graphic control extension block is used for overlay gifs. * This is necessary to define a transparent color. */ - if (TRANSPARENT_INDEX != -1) - { + if (TRANSPARENT_INDEX != -1) { /* Extension Introducer = '!' */ outbuf[0] = '\x21'; /* Graphic Control Label */ @@ -459,7 +437,7 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width outbuf[4] = 0; outbuf[5] = 0; /* Transparent Color Index */ - outbuf[6] = (unsigned char)TRANSPARENT_INDEX; + outbuf[6] = (unsigned char) TRANSPARENT_INDEX; /* Block Terminator */ outbuf[7] = 0; fwrite(outbuf, 8, 1, gif_file); @@ -474,35 +452,34 @@ int gif_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width outbuf[3] = 0x00; outbuf[4] = 0x00; /* Image Width (low byte first) */ - outbuf[5] = (unsigned char)(0xff & ImageWidth); - outbuf[6] = (unsigned char)((0xff00 & ImageWidth) / 0x100); + outbuf[5] = (unsigned char) (0xff & ImageWidth); + outbuf[6] = (unsigned char) ((0xff00 & ImageWidth) / 0x100); /* Image Height */ - outbuf[7] = (unsigned char)(0xff & ImageHeight); - outbuf[8] = (unsigned char)((0xff00 & ImageHeight) / 0x100); - + outbuf[7] = (unsigned char) (0xff & ImageHeight); + outbuf[8] = (unsigned char) ((0xff00 & ImageHeight) / 0x100); + /* Byte 10 contains the interlaced flag and * information on the local color table. * There is no local color table if its most significant bit is reset. */ - outbuf[9] = (unsigned char)(0|(0x7 & (DESTINATION_IMAGE_BITS-1))); + outbuf[9] = (unsigned char) (0 | (0x7 & (DESTINATION_IMAGE_BITS - 1))); fwrite(outbuf, 10, 1, gif_file); /* call lzw encoding */ byte_out = gif_lzw( - (unsigned char *) lzwoutbuf, - image_height * image_width, - (unsigned char *) rotated_bitmap, - image_height * image_width); - if (byte_out <= 0) - { + (unsigned char *) lzwoutbuf, + image_height * image_width, + (unsigned char *) rotated_bitmap, + image_height * image_width); + if (byte_out <= 0) { fclose(gif_file); return ZINT_ERROR_MEMORY; } fwrite(lzwoutbuf, byte_out, 1, gif_file); - - /* GIF terminator */ + + /* GIF terminator */ fputc('\x3b', gif_file); fclose(gif_file); - + return 0; } \ No newline at end of file diff --git a/backend/gs1.c b/backend/gs1.c index af70d1f7..6102584a 100644 --- a/backend/gs1.c +++ b/backend/gs1.c @@ -69,7 +69,7 @@ void itostr(char ai_string[], int ai_value) { strcat(ai_string, ")"); } -int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const unsigned int src_len, char reduced[]) { +int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const size_t src_len, char reduced[]) { int i, j, last_ai, ai_latch; char ai_string[6]; int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length; diff --git a/backend/gs1.h b/backend/gs1.h index e097d564..f633bb5c 100644 --- a/backend/gs1.h +++ b/backend/gs1.h @@ -36,7 +36,7 @@ extern "C" { #endif /* __cplusplus */ - extern int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const unsigned int src_len, char reduced[]); + extern int gs1_verify(struct zint_symbol *symbol, const unsigned char source[], const size_t src_len, char reduced[]); extern int ugs1_verify(struct zint_symbol *symbol, const unsigned char source[], const unsigned int src_len, unsigned char reduced[]); #ifdef __cplusplus diff --git a/backend/hanxin.c b/backend/hanxin.c index 89c02f5b..8125d1fb 100644 --- a/backend/hanxin.c +++ b/backend/hanxin.c @@ -41,23 +41,24 @@ #include "reedsol.h" #include "hanxin.h" #include "gb18030.h" +#include "assert.h" /* Find which submode to use for a text character */ int getsubmode(char input) { int submode = 2; - + if ((input >= '0') && (input <= '9')) { submode = 1; } - + if ((input >= 'A') && (input <= 'Z')) { submode = 1; } - + if ((input >= 'a') && (input <= 'z')) { submode = 1; } - + return submode; } @@ -67,11 +68,11 @@ int calculate_binlength(char mode[], int source[], int length, int eci) { char lastmode = 't'; int est_binlen = 0; int submode = 1; - + if (eci != 3) { est_binlen += 12; } - + i = 0; do { switch (mode[i]) { @@ -133,69 +134,69 @@ int calculate_binlength(char mode[], int source[], int length, int eci) { } i++; } while (i < length); - + return est_binlen; } int isRegion1(int glyph) { int first_byte, second_byte; int valid = 0; - + first_byte = (glyph & 0xff00) >> 8; second_byte = glyph & 0xff; - + if ((first_byte >= 0xb0) && (first_byte <= 0xd7)) { if ((second_byte >= 0xa1) && (second_byte <= 0xfe)) { valid = 1; } } - + if ((first_byte >= 0xa1) && (first_byte <= 0xa3)) { if ((second_byte >= 0xa1) && (second_byte <= 0xfe)) { valid = 1; } } - + if ((glyph >= 0xa8a1) && (glyph <= 0xa8c0)) { valid = 1; } - + return valid; } int isRegion2(int glyph) { int first_byte, second_byte; int valid = 0; - + first_byte = (glyph & 0xff00) >> 8; second_byte = glyph & 0xff; - + if ((first_byte >= 0xd8) && (first_byte <= 0xf7)) { if ((second_byte >= 0xa1) && (second_byte <= 0xfe)) { valid = 1; } } - + return valid; } int isDoubleByte(int glyph) { int first_byte, second_byte; int valid = 0; - + first_byte = (glyph & 0xff00) >> 8; second_byte = glyph & 0xff; - + if ((first_byte >= 0x81) && (first_byte <= 0xfe)) { if ((second_byte >= 0x40) && (second_byte <= 0x7e)) { valid = 1; } - + if ((second_byte >= 0x80) && (second_byte <= 0xfe)) { valid = 1; } } - + return valid; } @@ -203,12 +204,12 @@ int isFourByte(int glyph, int glyph2) { int first_byte, second_byte; int third_byte, fourth_byte; int valid = 0; - + first_byte = (glyph & 0xff00) >> 8; second_byte = glyph & 0xff; third_byte = (glyph2 & 0xff00) >> 8; fourth_byte = glyph2 & 0xff; - + if ((first_byte >= 0x81) && (first_byte <= 0xfe)) { if ((second_byte >= 0x30) && (second_byte <= 0x39)) { if ((third_byte >= 0x81) && (third_byte <= 0xfe)) { @@ -218,7 +219,7 @@ int isFourByte(int glyph, int glyph2) { } } } - + return valid; } @@ -227,29 +228,29 @@ void hx_define_mode(char mode[], int source[], int length) { int i; char lastmode = 't'; int done; - + i = 0; do { done = 0; - + if (isRegion1(source[i])) { mode[i] = '1'; done = 1; i++; } - + if ((done == 0) && (isRegion2(source[i]))) { mode[i] = '2'; done = 1; i++; } - + if ((done == 0) && (isDoubleByte(source[i]))) { mode[i] = 'd'; done = 1; i++; } - + if ((done == 0) && (i < length - 1)) { if (isFourByte(source[i], source[i + 1])) { mode[i] = 'f'; @@ -258,7 +259,7 @@ void hx_define_mode(char mode[], int source[], int length) { i += 2; } } - + if (done == 0) { if ((source[i] >= '0') && (source[i] <= '9')) { mode[i] = 'n'; @@ -278,7 +279,7 @@ void hx_define_mode(char mode[], int source[], int length) { } } } - i++; + i++; } } while (i < length); mode[length] = '\0'; @@ -287,42 +288,42 @@ void hx_define_mode(char mode[], int source[], int length) { /* Convert Text 1 sub-mode character to encoding value, as given in table 3 */ int lookup_text1(char input) { int encoding_value = 0; - + if ((input >= '0') && (input <= '9')) { encoding_value = input - '0'; } - + if ((input >= 'A') && (input <= 'Z')) { encoding_value = input - 'A' + 10; } - + if ((input >= 'a') && (input <= 'z')) { encoding_value = input - 'a' + 36; } - + return encoding_value; } /* Convert Text 2 sub-mode character to encoding value, as given in table 4 */ int lookup_text2(char input) { int encoding_value = 0; - + if ((input >= 0) && (input <= 27)) { encoding_value = input; } - + if ((input >= ' ') && (input <= '/')) { encoding_value = input - ' ' + 28; } - + if ((input >= '[') && (input <= 96)) { encoding_value = input - '[' + 51; } - + if ((input >= '{') && (input <= 127)) { encoding_value = input - '{' + 57; } - + return encoding_value; } @@ -336,7 +337,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int int third_byte, fourth_byte; int glyph; int submode; - + if (eci != 3) { strcat(binary, "1000"); // ECI for (p = 0; p < 8; p++) { @@ -347,44 +348,44 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int } } } - + do { block_length = 0; do { block_length++; } while (mode[position + block_length] == mode[position]); - - switch(mode[position]) { + + switch (mode[position]) { case 'n': /* Numeric mode */ /* Mode indicator */ strcat(binary, "0001"); - + if (debug) { printf("Numeric\n"); } - + i = 0; - + while (i < block_length) { int first = 0, second = 0, third = 0; - + first = posn(NEON, (char) source[position + i]); count = 1; encoding_value = first; - + if (i + 1 < block_length && mode[position + i + 1] == 'n') { second = posn(NEON, (char) source[position + i + 1]); count = 2; encoding_value = (encoding_value * 10) + second; - + if (i + 2 < block_length && mode[position + i + 2] == 'n') { third = posn(NEON, (char) source[position + i + 2]); count = 3; encoding_value = (encoding_value * 10) + third; } } - + for (p = 0; p < 10; p++) { if (encoding_value & (0x200 >> p)) { strcat(binary, "1"); @@ -392,14 +393,14 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "0"); } } - + if (debug) { printf("0x%4x (%d)", encoding_value, encoding_value); } - + i += count; } - + /* Mode terminator depends on number of characters in last group (Table 2) */ switch (count) { case 1: @@ -412,29 +413,29 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "1111111111"); break; } - + if (debug) { printf(" (TERM %d)\n", count); } - + break; case 't': /* Text mode */ if (position != 0) { /* Mode indicator */ strcat(binary, "0010"); - + if (debug) { printf("Text\n"); } } - + submode = 1; - + i = 0; - + while (i < block_length) { - + if (getsubmode((char) source[i + position]) != submode) { /* Change submode */ strcat(binary, "111110"); @@ -443,13 +444,13 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int printf("SWITCH "); } } - + if (submode == 1) { encoding_value = lookup_text1((char) source[i + position]); } else { encoding_value = lookup_text2((char) source[i + position]); } - + for (p = 0; p < 6; p++) { if (encoding_value & (0x20 >> p)) { strcat(binary, "1"); @@ -457,16 +458,16 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "0"); } } - + if (debug) { printf("%c (%d) ", (char) source[i], encoding_value); } i++; } - + /* Terminator */ strcat(binary, "111111"); - + if (debug) { printf("\n"); } @@ -475,7 +476,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int /* Binary Mode */ /* Mode indicator */ strcat(binary, "0011"); - + /* Count indicator */ for (p = 0; p < 13; p++) { if (block_length & (0x1000 >> p)) { @@ -484,15 +485,15 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "0"); } } - + if (debug) { printf("Binary (length %d)\n", block_length); } - + i = 0; - + while (i < block_length) { - + /* 8-bit bytes with no conversion */ for (p = 0; p < 8; p++) { if (source[i + position] & (0x80 >> p)) { @@ -501,14 +502,14 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "0"); } } - + if (debug) { printf("%d ", source[i + position]); } - + i++; } - + if (debug) { printf("\n"); } @@ -517,13 +518,13 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int /* Region 1 encoding */ /* Mode indicator */ strcat(binary, "0100"); - + if (debug) { printf("Region 1\n"); } - + i = 0; - + while (i < block_length) { first_byte = (source[i + position] & 0xff00) >> 8; second_byte = source[i + position] & 0xff; @@ -542,11 +543,11 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int if ((source[i + position] >= 0xa8a1) && (source[i + position] <= 0xa8c0)) { glyph = (second_byte - 0xa1) + 0xfca; } - + if (debug) { printf("%d ", glyph); } - + for (p = 0; p < 12; p++) { if (glyph & (0x800 >> p)) { strcat(binary, "1"); @@ -554,39 +555,39 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "0"); } } - + i++; } - + /* Terminator */ strcat(binary, "111111111111"); - + if (debug) { printf("\n"); } - + break; case '2': /* Region 2 encoding */ /* Mode indicator */ strcat(binary, "0101"); - + if (debug) { printf("Region 2\n"); } - + i = 0; - + while (i < block_length) { first_byte = (source[i + position] & 0xff00) >> 8; second_byte = source[i + position] & 0xff; - + glyph = (0x5e * (first_byte - 0xd8)) + (second_byte - 0xa1); - + if (debug) { printf("%d ", glyph); } - + for (p = 0; p < 12; p++) { if (glyph & (0x800 >> p)) { strcat(binary, "1"); @@ -594,42 +595,42 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "0"); } } - + i++; } - + /* Terminator */ strcat(binary, "111111111111"); - + if (debug) { printf("\n"); - } + } break; case 'd': /* Double byte encoding */ /* Mode indicator */ strcat(binary, "0110"); - + if (debug) { printf("Double byte\n"); } - + i = 0; - + while (i < block_length) { first_byte = (source[i + position] & 0xff00) >> 8; second_byte = source[i + position] & 0xff; - + if (second_byte <= 0x7e) { glyph = (0xbe * (first_byte - 0x81)) + (second_byte - 0x40); } else { glyph = (0xbe * (first_byte - 0x81)) + (second_byte - 0x41); } - + if (debug) { printf("%d ", glyph); } - + for (p = 0; p < 15; p++) { if (glyph & (0x4000 >> p)) { strcat(binary, "1"); @@ -637,43 +638,43 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "0"); } } - + i++; } - + /* Terminator */ strcat(binary, "111111111111111"); /* Terminator sequence of length 12 is assumed to be a mistake */ - + if (debug) { printf("\n"); - } + } break; case 'f': /* Four-byte encoding */ if (debug) { printf("Four byte\n"); } - + i = 0; - + while (i < block_length) { - + /* Mode indicator */ strcat(binary, "0111"); - + first_byte = (source[i + position] & 0xff00) >> 8; second_byte = source[i + position] & 0xff; third_byte = (source[i + position + 1] & 0xff00) >> 8; fourth_byte = source[i + position + 1] & 0xff; - + glyph = (0x3138 * (first_byte - 0x81)) + (0x04ec * (second_byte - 0x30)) + (0x0a * (third_byte - 0x81)) + (fourth_byte - 0x30); - + if (debug) { printf("%d ", glyph); } - + for (p = 0; p < 15; p++) { if (glyph & (0x4000 >> p)) { strcat(binary, "1"); @@ -681,21 +682,21 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int strcat(binary, "0"); } } - + i += 2; } - + /* No terminator */ - + if (debug) { printf("\n"); } break; - + } - + position += block_length; - + } while (position < length); } @@ -703,7 +704,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int void hx_place_finder_top_left(unsigned char* grid, int size) { int xp, yp; int x = 0, y = 0; - + int finder[] = { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, @@ -713,7 +714,7 @@ void hx_place_finder_top_left(unsigned char* grid, int size) { 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1 }; - + for (xp = 0; xp < 7; xp++) { for (yp = 0; yp < 7; yp++) { if (finder[xp + (7 * yp)] == 1) { @@ -728,7 +729,7 @@ void hx_place_finder_top_left(unsigned char* grid, int size) { /* Finder pattern for top right and bottom left of symbol */ void hx_place_finder(unsigned char* grid, int size, int x, int y) { int xp, yp; - + int finder[] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, @@ -738,7 +739,7 @@ void hx_place_finder(unsigned char* grid, int size, int x, int y) { 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1 }; - + for (xp = 0; xp < 7; xp++) { for (yp = 0; yp < 7; yp++) { if (finder[xp + (7 * yp)] == 1) { @@ -754,7 +755,7 @@ void hx_place_finder(unsigned char* grid, int size, int x, int y) { void hx_place_finder_bottom_right(unsigned char* grid, int size) { int xp, yp; int x = size - 7, y = size - 7; - + int finder[] = { 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, @@ -764,7 +765,7 @@ void hx_place_finder_bottom_right(unsigned char* grid, int size) { 0, 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) { @@ -792,13 +793,13 @@ void hx_plot_alignment(unsigned char *grid, int size, int x, int y, int w, int h int i; hx_safe_plot(grid, size, x, y, 0x11); hx_safe_plot(grid, size, x - 1, y + 1, 0x10); - + for (i = 1; i <= w; i++) { /* Top */ hx_safe_plot(grid, size, x - i, y, 0x11); hx_safe_plot(grid, size, x - i - 1, y + 1, 0x10); } - + for (i = 1; i < h; i++) { /* Right */ hx_safe_plot(grid, size, x, y + i, 0x11); @@ -816,63 +817,63 @@ void hx_plot_assistant(unsigned char *grid, int size, int x, int y) { hx_safe_plot(grid, size, x + 1, y, 0x10); hx_safe_plot(grid, size, x - 1, y + 1, 0x10); hx_safe_plot(grid, size, x, y + 1, 0x10); - hx_safe_plot(grid, size, x + 1, y + 1, 0x10); + hx_safe_plot(grid, size, x + 1, y + 1, 0x10); } /* Put static elements in the grid */ void hx_setup_grid(unsigned char* grid, int size, int version) { int i, j; - + for (i = 0; i < size; i++) { for (j = 0; j < size; j++) { grid[(i * size) + j] = 0; } } - + /* Add finder patterns */ hx_place_finder_top_left(grid, size); hx_place_finder(grid, size, 0, size - 7); hx_place_finder(grid, size, size - 7, 0); hx_place_finder_bottom_right(grid, size); - + /* Add finder pattern separator region */ for (i = 0; i < 8; i++) { /* Top left */ grid[(7 * size) + i] = 0x10; grid[(i * size) + 7] = 0x10; - - /* Top right */ - grid[(7 * size) + (size - i - 1)] = 0x10; + + /* Top right */ + grid[(7 * size) + (size - i - 1)] = 0x10; grid[((size - i - 1) * size) + 7] = 0x10; - + /* Bottom left */ grid[(i * size) + (size - 8)] = 0x10; grid[((size - 8) * size) + i] = 0x10; - + /* Bottom right */ grid[((size - 8) * size) + (size - i - 1)] = 0x10; grid[((size - i - 1) * size) + (size - 8)] = 0x10; } - + /* Reserve function information region */ for (i = 0; i < 9; i++) { /* Top left */ grid[(8 * size) + i] = 0x10; grid[(i * size) + 8] = 0x10; - - /* Top right */ - grid[(8 * size) + (size - i - 1)] = 0x10; + + /* Top right */ + grid[(8 * size) + (size - i - 1)] = 0x10; grid[((size - i - 1) * size) + 8] = 0x10; - + /* Bottom left */ grid[(i * size) + (size - 9)] = 0x10; grid[((size - 9) * size) + i] = 0x10; - + /* Bottom right */ grid[((size - 9) * size) + (size - i - 1)] = 0x10; grid[((size - i - 1) * size) + (size - 9)] = 0x10; } - + if (version > 3) { int k = hx_module_k[version - 1]; int r = hx_module_r[version - 1]; @@ -880,7 +881,7 @@ void hx_setup_grid(unsigned char* grid, int size, int version) { int x, y, row_switch, column_switch; int module_height, module_width; int mod_x, mod_y; - + /* Add assistant alignment patterns to left and right */ y = 0; mod_y = 0; @@ -890,7 +891,7 @@ void hx_setup_grid(unsigned char* grid, int size, int version) { } else { module_height = r - 1; } - + if ((mod_y % 2) == 0) { if ((m % 2) == 1) { hx_plot_assistant(grid, size, 0, y); @@ -901,11 +902,11 @@ void hx_setup_grid(unsigned char* grid, int size, int version) { } hx_plot_assistant(grid, size, size - 1, y); } - + mod_y++; y += module_height; } while (y < size); - + /* Add assistant alignment patterns to top and bottom */ x = (size - 1); mod_x = 0; @@ -915,7 +916,7 @@ void hx_setup_grid(unsigned char* grid, int size, int version) { } else { module_width = r - 1; } - + if ((mod_x % 2) == 0) { if ((m % 2) == 1) { hx_plot_assistant(grid, size, x, (size - 1)); @@ -926,22 +927,22 @@ void hx_setup_grid(unsigned char* grid, int size, int version) { } hx_plot_assistant(grid, size, x, 0); } - + mod_x++; x -= module_width; } while (x >= 0); - + /* Add alignment pattern */ column_switch = 1; y = 0; - mod_y = 0; + mod_y = 0; do { if (mod_y < m) { module_height = k; } else { module_height = r - 1; } - + if (column_switch == 1) { row_switch = 1; column_switch = 0; @@ -949,7 +950,7 @@ void hx_setup_grid(unsigned char* grid, int size, int version) { row_switch = 0; column_switch = 1; } - + x = (size - 1); mod_x = 0; do { @@ -958,7 +959,7 @@ void hx_setup_grid(unsigned char* grid, int size, int version) { } else { module_width = r - 1; } - + if (row_switch == 1) { if (!(y == 0 && x == (size - 1))) { hx_plot_alignment(grid, size, x, y, module_width, module_height); @@ -970,7 +971,7 @@ void hx_setup_grid(unsigned char* grid, int size, int version) { mod_x++; x -= module_width; } while (x >= 0); - + mod_y++; y += module_height; } while (y < size); @@ -985,25 +986,25 @@ void hx_add_ecc(unsigned char fullstream[], unsigned char datastream[], int vers int batch_size, data_length, ecc_length; int input_position = -1; int output_position = -1; - + for (i = 0; i < 3; i++) { batch_size = hx_table_d1[(((version - 1) + (ecc_level - 1)) * 9) + (3 * i)]; data_length = hx_table_d1[(((version - 1) + (ecc_level - 1)) * 9) + (3 * i) + 1]; ecc_length = hx_table_d1[(((version - 1) + (ecc_level - 1)) * 9) + (3 * i) + 2]; - - for(block = 0; block < batch_size; block++) { + + for (block = 0; block < batch_size; block++) { for (j = 0; j < data_length; j++) { input_position++; output_position++; data_block[j] = datastream[input_position]; fullstream[output_position] = datastream[input_position]; } - + rs_init_gf(0x163); // x^8 + x^6 + x^5 + x + 1 = 0 rs_init_code(ecc_length, 1); rs_encode(data_length, data_block, ecc_block); rs_free(); - + for (j = 0; j < ecc_length; j++) { output_position++; fullstream[output_position] = ecc_block[ecc_length - j - 1]; @@ -1016,7 +1017,7 @@ void hx_add_ecc(unsigned char fullstream[], unsigned char datastream[], int vers void make_picket_fence(unsigned char fullstream[], unsigned char picket_fence[], int streamsize) { int i, start; int output_position = 0; - + for (start = 0; start < 13; start++) { for (i = start; i < streamsize; i += 13) { if (i < streamsize) { @@ -1145,13 +1146,13 @@ int hx_evaluate(unsigned char *eval, int size, int pattern) { } } } - + /* Test 2: Adjacent modules in row/column in same colour */ /* In AIMD-15 section 5.8.3.2 it is stated... “In Table 9 below, i refers to the row * position of the module.” - however i being the length of the run of the * same colour (i.e. "block" below) in the same fashion as ISO/IEC 18004 * makes more sense. The implementation below matches AIMD-015.*/ - + /* Vertical */ for (x = 0; x < size; x++) { state = local[x]; @@ -1205,7 +1206,7 @@ int hx_apply_bitmask(unsigned char *grid, int size) { int best_pattern, best_val; int bit; unsigned char p; - + #ifndef _MSC_VER unsigned char mask[size * size]; unsigned char eval[size * size]; @@ -1213,14 +1214,14 @@ int hx_apply_bitmask(unsigned char *grid, int size) { unsigned char* mask = (unsigned char *) _alloca((size * size) * sizeof (unsigned char)); unsigned char* eval = (unsigned char *) _alloca((size * size) * sizeof (unsigned char)); #endif - + /* Perform data masking */ for (x = 0; x < size; x++) { for (y = 0; y < size; y++) { mask[(y * size) + x] = 0x00; j = x + 1; i = y + 1; - + if (!(grid[(y * size) + x] & 0xf0)) { if ((i + j) % 2 == 0) { mask[(y * size) + x] += 0x02; @@ -1234,7 +1235,7 @@ int hx_apply_bitmask(unsigned char *grid, int size) { } } } - + // apply data masks to grid, result in eval for (x = 0; x < size; x++) { for (y = 0; y < size; y++) { @@ -1247,12 +1248,12 @@ int hx_apply_bitmask(unsigned char *grid, int size) { eval[(y * size) + x] = mask[(y * size) + x] ^ p; } } - + /* Evaluate result */ for (pattern = 0; pattern < 4; pattern++) { penalty[pattern] = hx_evaluate(eval, size, pattern); } - + best_pattern = 0; best_val = penalty[0]; for (pattern = 1; pattern < 4; pattern++) { @@ -1261,7 +1262,7 @@ int hx_apply_bitmask(unsigned char *grid, int size) { best_val = penalty[pattern]; } } - + /* Apply mask */ for (x = 0; x < size; x++) { for (y = 0; y < size; y++) { @@ -1293,7 +1294,7 @@ int hx_apply_bitmask(unsigned char *grid, int size) { } } } - + return best_pattern; } @@ -1309,7 +1310,7 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length char function_information[36]; unsigned char fi_cw[3] = {0, 0, 0}; unsigned char fi_ecc[4]; - + #ifndef _MSC_VER int utfdata[length + 1]; int gbdata[(length + 1) * 2]; @@ -1319,12 +1320,12 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length int* gbdata = (int *) _alloca(((length + 1) * 2) * sizeof (int)); char* mode = (char *) _alloca((length + 1) * sizeof (char)); char* binary; - unsigned char *datastream; + unsigned char *datastream; unsigned char *fullstream; unsigned char *picket_fence; unsigned char *grid; #endif - + if ((symbol->input_mode == DATA_MODE) || (symbol->eci != 3)) { for (i = 0; i < length; i++) { gbdata[i] = (int) source[i]; @@ -1376,39 +1377,35 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length } } } + length = posn; } - length = posn; hx_define_mode(mode, gbdata, length); - + est_binlen = calculate_binlength(mode, gbdata, length, symbol->eci); est_codewords = est_binlen / 8; if (est_binlen % 8 != 0) { est_codewords++; } - + #ifndef _MSC_VER char binary[est_binlen + 1]; #else - binary = (char *) _alloca((est_binlen + 1) * sizeof (char));; + binary = (char *) _alloca((est_binlen + 10) * sizeof (char)); #endif - for (i = 0; i < est_binlen + 1; i++) { - binary[i] = '\0'; - } - - binary[0] = '\0'; - + memset(binary, 0, (est_binlen + 1) * sizeof (char)); + if ((ecc_level <= 0) || (ecc_level >= 5)) { ecc_level = 1; } - + calculate_binary(binary, mode, gbdata, length, symbol->eci); - + version = 85; for (i = 84; i > 0; i--) { switch (ecc_level) { case 1: - if (hx_data_codewords_L1[i - 1] > est_codewords ) { + if (hx_data_codewords_L1[i - 1] > est_codewords) { version = i; data_codewords = hx_data_codewords_L1[i - 1]; } @@ -1431,24 +1428,27 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length data_codewords = hx_data_codewords_L4[i - 1]; } break; + default: + assert(0); + break; } } - + if (version == 85) { strcpy(symbol->errtxt, "Input too long for selected error correction level"); return ZINT_ERROR_TOO_LONG; } - + if ((symbol->option_2 < 0) || (symbol->option_2 > 84)) { symbol->option_2 = 0; } - + if (symbol->option_2 > version) { version = symbol->option_2; } - + /* If there is spare capacity, increase the level of ECC */ - + if ((ecc_level == 1) && (est_codewords < hx_data_codewords_L2[version - 1])) { ecc_level = 2; data_codewords = hx_data_codewords_L2[version - 1]; @@ -1463,9 +1463,9 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length ecc_level = 4; data_codewords = hx_data_codewords_L4[version - 1]; } - + //printf("Version %d, ECC %d\n", version, ecc_level); - + size = (version * 2) + 21; #ifndef _MSC_VER @@ -1483,19 +1483,19 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length for (i = 0; i < data_codewords; i++) { datastream[i] = 0; } - - for(i = 0; i < est_binlen; i++) { + + for (i = 0; i < est_binlen; i++) { if (binary[i] == '1') { datastream[i / 8] += 0x80 >> (i % 8); } } hx_setup_grid(grid, size, version); - + hx_add_ecc(fullstream, datastream, version, ecc_level); - + make_picket_fence(fullstream, picket_fence, hx_total_codewords[version - 1]); - + /* Populate grid */ j = 0; for (i = 0; i < (size * size); i++) { @@ -1508,9 +1508,9 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length } } } - + bitmask = hx_apply_bitmask(grid, size); - + /* Form function information string */ for (i = 0; i < 34; i++) { if (i % 2) { @@ -1520,7 +1520,7 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length } } function_information[34] = '\0'; - + for (i = 0; i < 8; i++) { if ((version + 20) & (0x80 >> i)) { function_information[i] = '1'; @@ -1528,7 +1528,7 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length function_information[i] = '0'; } } - + for (i = 0; i < 2; i++) { if (ecc_level & (0x02 >> i)) { function_information[i + 8] = '1'; @@ -1536,7 +1536,7 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length function_information[i + 8] = '0'; } } - + for (i = 0; i < 2; i++) { if (bitmask & (0x02 >> i)) { function_information[i + 10] = '1'; @@ -1544,9 +1544,9 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length function_information[i + 10] = '0'; } } - - - + + + for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) { if (function_information[(i * 4) + j] == '1') { @@ -1554,12 +1554,12 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length } } } - + rs_init_gf(0x13); rs_init_code(4, 1); rs_encode(3, fi_cw, fi_ecc); rs_free(); - + for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { if (fi_ecc[3 - i] & (0x08 >> j)) { @@ -1569,7 +1569,7 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length } } } - + /* Add function information to symbol */ for (i = 0; i < 9; i++) { if (function_information[i] == '1') { @@ -1589,7 +1589,7 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length grid[((size - 1 - 8) * size) + (8 - i)] = 0x01; } } - + symbol->width = size; symbol->rows = size; @@ -1603,4 +1603,4 @@ int han_xin(struct zint_symbol *symbol, const unsigned char source[], int length } return 0; -} \ No newline at end of file +} diff --git a/backend/hanxin.h b/backend/hanxin.h index 3436e6c8..94eb1279 100644 --- a/backend/hanxin.h +++ b/backend/hanxin.h @@ -31,7 +31,7 @@ */ /* Data from table B1: Data capacity of Han Xin Code */ -static int hx_total_codewords[] = { +static const int hx_total_codewords[] = { 25, 37, 50, 54, 69, 84, 100, 117, 136, 155, 161, 181, 203, 225, 249, 273, 299, 325, 353, 381, 411, 422, 453, 485, 518, 552, 587, 623, 660, 698, 737, 754, 794, 836, 878, 922, 966, 1011, 1058, 1105, 1126, 1175, @@ -41,7 +41,7 @@ static int hx_total_codewords[] = { 3500, 3585, 3671, 3758, 3798, 3886 }; -static int hx_data_codewords_L1[] = { +static const int hx_data_codewords_L1[] = { 21, 31, 42, 46, 57, 70, 84, 99, 114, 131, 135, 153, 171, 189, 209, 229, 251, 273, 297, 321, 345, 354, 381, 407, 436, 464, 493, 523, 554, 586, 619, 634, 666, 702, 738, 774, 812, 849, 888, 929, 946, 987, 1028, 1071, 1115, @@ -51,8 +51,8 @@ static int hx_data_codewords_L1[] = { 3083, 3156, 3190, 3264 }; -static int hx_data_codewords_L2[] = { - 17, 25, 34, 38, 49, 58, 70, 81, 96, 109, 113, 127, 143, 157, 175,191, 209, +static const int hx_data_codewords_L2[] = { + 17, 25, 34, 38, 49, 58, 70, 81, 96, 109, 113, 127, 143, 157, 175, 191, 209, 227, 247, 267, 287, 296, 317, 339, 362, 386, 411, 437, 462, 488, 515, 528, 556, 586, 614, 646, 676, 707, 740, 773, 788, 823, 856, 893, 929, 966, 1004, 1043, 1059, 1099, 1140, 1180, 1221, 1263, 1307, 1351, 1394, 1415, 1460, @@ -61,16 +61,16 @@ static int hx_data_codewords_L2[] = { 2720 }; -static int hx_data_codewords_L3[] = { +static const int hx_data_codewords_L3[] = { 13, 19, 26, 30, 37, 46, 54, 63, 74, 83, 87, 97, 109, 121, 135, 147, 161, 175, 191, 205, 221, 228, 245, 261, 280, 298, 317, 337, 358, 376, 397, 408, 428, 452, 474, 498, 522, 545, 572, 597, 608, 635, 660, 689, 717, 746, 774, 805, 817, 847, 880, 910, 943, 975, 1009, 1041, 1076, 1091, 1126, 1161, 1198, - 1234, 1271, 1309, 1348, 1366, 1404, 1443, 1485, 1524, 1566, 1607,1650, 1693, + 1234, 1271, 1309, 1348, 1366, 1404, 1443, 1485, 1524, 1566, 1607, 1650, 1693, 1713, 1756, 1800, 1844, 1890, 1935, 1983, 2030, 2050, 2098 }; -static int hx_data_codewords_L4[] = { +static const int hx_data_codewords_L4[] = { 9, 15, 20, 22, 27, 34, 40, 47, 54, 61, 65, 73, 81, 89, 99, 109, 119, 129, 141, 153, 165, 168, 181, 195, 208, 220, 235, 251, 264, 280, 295, 302, 318, 334, 352, 368, 386, 405, 424, 441, 450, 469, 490, 509, 531, 552, 574, 595, 605, @@ -80,8 +80,8 @@ static int hx_data_codewords_L4[] = { }; /* Value 'k' from Annex A */ -static int hx_module_k[] = { - 0, 0, 0, 14, 16, 16, 17, 18, 19, 20, +static const int hx_module_k[] = { + 0, 0, 0, 14, 16, 16, 17, 18, 19, 20, 14, 15, 16, 16, 17, 17, 18, 19, 20, 20, 21, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 17, 17, 18, 18, 19, 19, 19, 20, 20, @@ -93,8 +93,8 @@ static int hx_module_k[] = { }; /* Value 'r' from Annex A */ -static int hx_module_r[] = { - 0, 0, 0, 15, 15, 17, 18, 19, 20, 21, +static const int hx_module_r[] = { + 0, 0, 0, 15, 15, 17, 18, 19, 20, 21, 15, 15, 15, 17, 17, 19, 19, 19, 19, 21, 21, 17, 16, 18, 17, 19, 18, 20, 19, 21, 20, 17, 19, 17, 19, 17, 19, 21, 19, 21, @@ -106,7 +106,7 @@ static int hx_module_r[] = { }; /* Value of 'm' from Annex A */ -static int hx_module_m[] = { +static const int hx_module_m[] = { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, @@ -119,7 +119,7 @@ static int hx_module_m[] = { }; /* Error correction block sizes from Table D1 */ -static int hx_table_d1[] = { +static const int hx_table_d1[] = { /* #blocks, k, 2t, #blocks, k, 2t, #blocks, k, 2t */ 1, 21, 4, 0, 0, 0, 0, 0, 0, // version 1 1, 17, 8, 0, 0, 0, 0, 0, 0, @@ -247,7 +247,7 @@ static int hx_table_d1[] = { 13, 19, 28, 3, 16, 26, 0, 0, 0, 4, 127, 24, 1, 126, 24, 0, 0, 0, // version 32 7, 66, 28, 1, 66, 30, 0, 0, 0, - 12, 30,24, 1, 24, 28, 1, 24, 30, + 12, 30, 24, 1, 24, 28, 1, 24, 30, 15, 19, 28, 1, 17, 32, 0, 0, 0, 7, 84, 16, 1, 78, 16, 0, 0, 0, // version 33 7, 70, 30, 1, 66, 28, 0, 0, 0, diff --git a/backend/library.c b/backend/library.c index bebd9cff..13c4fe70 100644 --- a/backend/library.c +++ b/backend/library.c @@ -123,7 +123,7 @@ void ZBarcode_Delete(struct zint_symbol *symbol) { free(s->text); free(s); } - + // Free Rings ring = symbol->rendered->rings; while (ring) { @@ -131,7 +131,7 @@ void ZBarcode_Delete(struct zint_symbol *symbol) { ring = ring->next; free(r); } - + // Free Hexagons hexagon = symbol->rendered->hexagons; while (hexagon) { @@ -150,21 +150,21 @@ extern int get_best_eci(unsigned char source[], int length); /* Calculate suitab extern int utf_to_eci(int eci, const unsigned char source[], unsigned char dest[], int *length); /* Convert Unicode to other encodings */ extern int eanx(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN system barcodes */ -extern int c39(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 3 from 9 (or Code 39) */ +extern int c39(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Code 3 from 9 (or Code 39) */ extern int pharmazentral(struct zint_symbol *symbol, unsigned char source[], int length); /* Pharmazentral Nummer (PZN) */ extern int ec39(struct zint_symbol *symbol, unsigned char source[], int length); /* Extended Code 3 from 9 (or Code 39+) */ extern int codabar(struct zint_symbol *symbol, unsigned char source[], int length); /* Codabar - a simple substitution cipher */ extern int matrix_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Standard (& Matrix) */ extern int industrial_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Industrial */ extern int iata_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 IATA */ -extern int interleaved_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Interleaved */ +extern int interleaved_two_of_five(struct zint_symbol *symbol, const unsigned char source[], size_t length); /* Code 2 of 5 Interleaved */ extern int logic_two_of_five(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 2 of 5 Data Logic */ extern int itf14(struct zint_symbol *symbol, unsigned char source[], int length); /* ITF-14 */ extern int dpleit(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Leitcode */ extern int dpident(struct zint_symbol *symbol, unsigned char source[], int length); /* Deutsche Post Identcode */ extern int c93(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 93 - a re-working of Code 39+, generates 2 check digits */ extern int code_128(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 128 and NVE-18 */ -extern int ean_128(struct zint_symbol *symbol, unsigned char source[], int length); /* EAN-128 (GS1-128) */ +extern int ean_128(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* EAN-128 (GS1-128) */ extern int code_11(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 11 */ extern int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length); /* MSI Plessey */ extern int telepen(struct zint_symbol *symbol, unsigned char source[], int length); /* Telepen ASCII */ @@ -181,7 +181,7 @@ extern int royal_plot(struct zint_symbol *symbol, unsigned char source[], int le extern int australia_post(struct zint_symbol *symbol, unsigned char source[], int length); /* Australia Post 4-state */ extern int code16k(struct zint_symbol *symbol, unsigned char source[], int length); /* Code 16k */ extern int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length); /* PDF417 */ -extern int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length); /* Data Matrix (IEC16022) */ +extern int dmatrix(struct zint_symbol *symbol, const unsigned char source[], int length); /* Data Matrix (IEC16022) */ extern int qr_code(struct zint_symbol *symbol, const unsigned char source[], int length); /* QR Code */ extern int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length); /* Micro PDF417 */ extern int maxicode(struct zint_symbol *symbol, unsigned char source[], int length); /* Maxicode */ @@ -236,7 +236,7 @@ int dump_plot(struct zint_symbol *symbol) { char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; int space = 0; - + if (symbol->output_options & BARCODE_STDOUT) { f = stdout; } else { @@ -283,7 +283,7 @@ int dump_plot(struct zint_symbol *symbol) { } /* Process health industry bar code data */ -int hibc(struct zint_symbol *symbol, unsigned char source[], int length) { +static int hibc(struct zint_symbol *symbol, unsigned char source[], size_t length) { int counter, error_number, i; char to_process[40], temp[2], check_digit; @@ -412,9 +412,9 @@ static int gs1_compliant(const int symbology) { static int is_matrix(const int symbology) { /* Returns 1 if symbology is a matrix design */ - + int result = 0; - + switch (symbology) { case BARCODE_QRCODE: case BARCODE_DATAMATRIX: @@ -431,15 +431,15 @@ static int is_matrix(const int symbology) { result = 1; break; } - + return result; } static int supports_eci(const int symbology) { /* Returns 1 if symbology can encode the ECI character */ - + int result = 0; - + switch (symbology) { case BARCODE_AZTEC: case BARCODE_DATAMATRIX: @@ -454,7 +454,7 @@ static int supports_eci(const int symbology) { result = 1; break; } - + return result; } @@ -575,14 +575,14 @@ static int extended_charset(struct zint_symbol *symbol, const unsigned char *sou return error_number; } -static int reduced_charset(struct zint_symbol *symbol, const unsigned char *source, int length) { +static int reduced_charset(struct zint_symbol *symbol, const unsigned char *source, int in_length) { /* These are the "norm" standards which only support Latin-1 at most */ int error_number = 0; #ifndef _MSC_VER - unsigned char preprocessed[length + 1]; + unsigned char preprocessed[in_length + 1]; #else - unsigned char* preprocessed = (unsigned char*) _alloca(length + 1); + unsigned char* preprocessed = (unsigned char*) _alloca(in_length + 1); #endif if (symbol->symbology == BARCODE_CODE16K) { @@ -592,8 +592,8 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour symbol->output_options += BARCODE_BIND; } } - - if (symbol->symbology == BARCODE_ITF14) { + else + if (symbol->symbology == BARCODE_ITF14) { symbol->whitespace_width = 20; symbol->border_width = 8; if (!(symbol->output_options & BARCODE_BOX)) { @@ -604,11 +604,11 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour switch (symbol->input_mode) { case DATA_MODE: case GS1_MODE: - memcpy(preprocessed, source, length); - preprocessed[length] = '\0'; + memcpy(preprocessed, source, in_length); + preprocessed[in_length] = '\0'; break; case UNICODE_MODE: - error_number = utf_to_eci(symbol->eci, source, preprocessed, &length); + error_number = utf_to_eci(symbol->eci, source, preprocessed, &in_length); if (error_number != 0) { strcpy(symbol->errtxt, "Invalid characters in input data"); return error_number; @@ -617,186 +617,186 @@ static int reduced_charset(struct zint_symbol *symbol, const unsigned char *sour } switch (symbol->symbology) { - case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, length); + case BARCODE_C25MATRIX: error_number = matrix_two_of_five(symbol, preprocessed, in_length); break; - case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, length); + case BARCODE_C25IND: error_number = industrial_two_of_five(symbol, preprocessed, in_length); break; - case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, length); + case BARCODE_C25INTER: error_number = interleaved_two_of_five(symbol, preprocessed, in_length); break; - case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, length); + case BARCODE_C25IATA: error_number = iata_two_of_five(symbol, preprocessed, in_length); break; - case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, length); + case BARCODE_C25LOGIC: error_number = logic_two_of_five(symbol, preprocessed, in_length); break; - case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, length); + case BARCODE_DPLEIT: error_number = dpleit(symbol, preprocessed, in_length); break; - case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, length); + case BARCODE_DPIDENT: error_number = dpident(symbol, preprocessed, in_length); break; - case BARCODE_UPCA: error_number = eanx(symbol, preprocessed, length); + case BARCODE_UPCA: error_number = eanx(symbol, preprocessed, in_length); break; - case BARCODE_UPCE: error_number = eanx(symbol, preprocessed, length); + case BARCODE_UPCE: error_number = eanx(symbol, preprocessed, in_length); break; - case BARCODE_EANX: error_number = eanx(symbol, preprocessed, length); + case BARCODE_EANX: error_number = eanx(symbol, preprocessed, in_length); break; - case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, length); + case BARCODE_EAN128: error_number = ean_128(symbol, preprocessed, in_length); break; - case BARCODE_CODE39: error_number = c39(symbol, preprocessed, length); + case BARCODE_CODE39: error_number = c39(symbol, preprocessed, in_length); break; - case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, length); + case BARCODE_PZN: error_number = pharmazentral(symbol, preprocessed, in_length); break; - case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, length); + case BARCODE_EXCODE39: error_number = ec39(symbol, preprocessed, in_length); break; - case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, length); + case BARCODE_CODABAR: error_number = codabar(symbol, preprocessed, in_length); break; - case BARCODE_CODE93: error_number = c93(symbol, preprocessed, length); + case BARCODE_CODE93: error_number = c93(symbol, preprocessed, in_length); break; - case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, length); + case BARCODE_LOGMARS: error_number = c39(symbol, preprocessed, in_length); break; - case BARCODE_CODE128: error_number = code_128(symbol, preprocessed, length); + case BARCODE_CODE128: error_number = code_128(symbol, preprocessed, in_length); break; - case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed, length); + case BARCODE_CODE128B: error_number = code_128(symbol, preprocessed, in_length); break; - case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, length); + case BARCODE_NVE18: error_number = nve_18(symbol, preprocessed, in_length); break; - case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, length); + case BARCODE_CODE11: error_number = code_11(symbol, preprocessed, in_length); break; - case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, length); + case BARCODE_MSI_PLESSEY: error_number = msi_handle(symbol, preprocessed, in_length); break; - case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, length); + case BARCODE_TELEPEN: error_number = telepen(symbol, preprocessed, in_length); break; - case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, length); + case BARCODE_TELEPEN_NUM: error_number = telepen_num(symbol, preprocessed, in_length); break; - case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, length); + case BARCODE_PHARMA: error_number = pharma_one(symbol, preprocessed, in_length); break; - case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, length); + case BARCODE_PLESSEY: error_number = plessey(symbol, preprocessed, in_length); break; - case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, length); + case BARCODE_ITF14: error_number = itf14(symbol, preprocessed, in_length); break; - case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, length); + case BARCODE_FLAT: error_number = flattermarken(symbol, preprocessed, in_length); break; - case BARCODE_FIM: error_number = fim(symbol, preprocessed, length); + case BARCODE_FIM: error_number = fim(symbol, preprocessed, in_length); break; - case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, length); + case BARCODE_POSTNET: error_number = post_plot(symbol, preprocessed, in_length); break; - case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, length); + case BARCODE_PLANET: error_number = planet_plot(symbol, preprocessed, in_length); break; - case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, length); + case BARCODE_RM4SCC: error_number = royal_plot(symbol, preprocessed, in_length); break; - case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed, length); + case BARCODE_AUSPOST: error_number = australia_post(symbol, preprocessed, in_length); break; - case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed, length); + case BARCODE_AUSREPLY: error_number = australia_post(symbol, preprocessed, in_length); break; - case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed, length); + case BARCODE_AUSROUTE: error_number = australia_post(symbol, preprocessed, in_length); break; - case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed, length); + case BARCODE_AUSREDIRECT: error_number = australia_post(symbol, preprocessed, in_length); break; - case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, length); + case BARCODE_CODE16K: error_number = code16k(symbol, preprocessed, in_length); break; - case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, length); + case BARCODE_PHARMA_TWO: error_number = pharma_two(symbol, preprocessed, in_length); break; - case BARCODE_ONECODE: error_number = imail(symbol, preprocessed, length); + case BARCODE_ONECODE: error_number = imail(symbol, preprocessed, in_length); break; - case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, length); + case BARCODE_ISBNX: error_number = eanx(symbol, preprocessed, in_length); break; - case BARCODE_RSS14: error_number = rss14(symbol, preprocessed, length); + case BARCODE_RSS14: error_number = rss14(symbol, preprocessed, in_length); break; - case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed, length); + case BARCODE_RSS14STACK: error_number = rss14(symbol, preprocessed, in_length); break; - case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed, length); + case BARCODE_RSS14STACK_OMNI: error_number = rss14(symbol, preprocessed, in_length); break; - case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, length); + case BARCODE_RSS_LTD: error_number = rsslimited(symbol, preprocessed, in_length); break; - case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed, length); + case BARCODE_RSS_EXP: error_number = rssexpanded(symbol, preprocessed, in_length); break; - case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed, length); + case BARCODE_RSS_EXPSTACK: error_number = rssexpanded(symbol, preprocessed, in_length); break; - case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_EANX_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_EAN128_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_RSS14_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_RSS_LTD_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_RSS_EXP_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_UPCA_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_UPCE_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_RSS14STACK_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_RSS14_OMNI_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed, length); + case BARCODE_RSS_EXPSTACK_CC: error_number = composite(symbol, preprocessed, in_length); break; - case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, length); + case BARCODE_KIX: error_number = kix_code(symbol, preprocessed, in_length); break; - case BARCODE_CODE32: error_number = code32(symbol, preprocessed, length); + case BARCODE_CODE32: error_number = code32(symbol, preprocessed, in_length); break; - case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, length); + case BARCODE_DAFT: error_number = daft_code(symbol, preprocessed, in_length); break; - case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed, length); + case BARCODE_EAN14: error_number = ean_14(symbol, preprocessed, in_length); break; - case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, length); + case BARCODE_AZRUNE: error_number = aztec_runes(symbol, preprocessed, in_length); break; - case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, length); + case BARCODE_KOREAPOST: error_number = korea_post(symbol, preprocessed, in_length); break; - case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed, length); + case BARCODE_HIBC_128: error_number = hibc(symbol, preprocessed, in_length); break; - case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed, length); + case BARCODE_HIBC_39: error_number = hibc(symbol, preprocessed, in_length); break; - case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed, length); + case BARCODE_HIBC_DM: error_number = hibc(symbol, preprocessed, in_length); break; - case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed, length); + case BARCODE_HIBC_QR: error_number = hibc(symbol, preprocessed, in_length); break; - case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed, length); + case BARCODE_HIBC_PDF: error_number = hibc(symbol, preprocessed, in_length); break; - case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed, length); + case BARCODE_HIBC_MICPDF: error_number = hibc(symbol, preprocessed, in_length); break; - case BARCODE_HIBC_AZTEC: error_number = hibc(symbol, preprocessed, length); + case BARCODE_HIBC_AZTEC: error_number = hibc(symbol, preprocessed, in_length); break; - case BARCODE_HIBC_BLOCKF: error_number = hibc(symbol, preprocessed, length); + case BARCODE_HIBC_BLOCKF: error_number = hibc(symbol, preprocessed, in_length); break; - case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, length); + case BARCODE_JAPANPOST: error_number = japan_post(symbol, preprocessed, in_length); break; - case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, length); + case BARCODE_CODE49: error_number = code_49(symbol, preprocessed, in_length); break; - case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, length); + case BARCODE_CHANNEL: error_number = channel_code(symbol, preprocessed, in_length); break; - case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, length); + case BARCODE_CODEONE: error_number = code_one(symbol, preprocessed, in_length); break; - case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, length); + case BARCODE_DATAMATRIX: error_number = dmatrix(symbol, preprocessed, in_length); break; - case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed, length); + case BARCODE_PDF417: error_number = pdf417enc(symbol, preprocessed, in_length); break; - case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed, length); + case BARCODE_PDF417TRUNC: error_number = pdf417enc(symbol, preprocessed, in_length); break; - case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, length); + case BARCODE_MICROPDF417: error_number = micro_pdf417(symbol, preprocessed, in_length); break; - case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, length); + case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, in_length); break; - case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, length); + case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, in_length); break; - case BARCODE_DOTCODE: error_number = dotcode(symbol, preprocessed, length); + case BARCODE_DOTCODE: error_number = dotcode(symbol, preprocessed, in_length); break; - case BARCODE_CODABLOCK: error_number = codablock(symbol, preprocessed, length); + case BARCODE_CODABLOCK: error_number = codablock(symbol, preprocessed, in_length); break; } return error_number; } -int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int length) { +int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int in_length) { int error_number, error_buffer, i; #ifdef _MSC_VER unsigned char* local_source; #endif error_number = 0; - if (length == 0) { - length = ustrlen(source); + if (in_length == 0) { + in_length = (int) ustrlen(source); } - if (length == 0) { + if (in_length == 0) { strcpy(symbol->errtxt, "No input data"); error_tag(symbol->errtxt, ZINT_ERROR_INVALID_DATA); return ZINT_ERROR_INVALID_DATA; @@ -810,9 +810,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt #endif } #ifndef _MSC_VER - unsigned char local_source[length + 1]; + unsigned char local_source[in_length + 1]; #else - local_source = (unsigned char*) _alloca(length + 1); + local_source = (unsigned char*) _alloca(in_length + 1); #endif /* First check the symbology field */ @@ -949,12 +949,12 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt } else { error_buffer = error_number; } - + if ((!(supports_eci(symbol->symbology))) && (symbol->eci != 3)) { strcpy(symbol->errtxt, "Symbology does not support ECI switching"); error_number = ZINT_ERROR_INVALID_OPTION; } - + if ((symbol->eci < 3) || (symbol->eci > 26) || (symbol->eci == 14) || (symbol->eci == 19) || (symbol->eci == 25)) { strcpy(symbol->errtxt, "Invalid or unsupported ECI mode"); error_number = ZINT_ERROR_INVALID_OPTION; @@ -965,25 +965,25 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt } if (symbol->input_mode == GS1_MODE) { - for (i = 0; i < length; i++) { + for (i = 0; i < in_length; i++) { if (source[i] == '\0') { strcpy(symbol->errtxt, "NULL characters not permitted in GS1 mode"); return ZINT_ERROR_INVALID_DATA; } } if (gs1_compliant(symbol->symbology) == 1) { - error_number = ugs1_verify(symbol, source, length, local_source); + error_number = ugs1_verify(symbol, source, in_length, local_source); if (error_number != 0) { return error_number; } - length = ustrlen(local_source); + in_length = ustrlen(local_source); } else { strcpy(symbol->errtxt, "Selected symbology does not support GS1 mode"); return ZINT_ERROR_INVALID_OPTION; } } else { - memcpy(local_source, source, length); - local_source[length] = '\0'; + memcpy(local_source, source, in_length); + local_source[in_length] = '\0'; } switch (symbol->symbology) { @@ -991,39 +991,39 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt case BARCODE_MICROQR: case BARCODE_GRIDMATRIX: case BARCODE_HANXIN: - error_number = extended_charset(symbol, local_source, length); + error_number = extended_charset(symbol, local_source, in_length); break; default: - error_number = reduced_charset(symbol, local_source, length); + error_number = reduced_charset(symbol, local_source, in_length); break; } - + if ((error_number == ZINT_ERROR_INVALID_DATA) && (supports_eci(symbol->symbology) && (symbol->input_mode == UNICODE_MODE))) { /* Try another ECI mode */ - symbol->eci = get_best_eci(local_source, length); - + symbol->eci = get_best_eci(local_source, in_length); + if (symbol->eci >= 3) { - + //printf("Data will encode with ECI %d\n", symbol->eci); - + switch (symbol->symbology) { case BARCODE_QRCODE: case BARCODE_MICROQR: case BARCODE_GRIDMATRIX: case BARCODE_HANXIN: - error_number = utf_to_eci(symbol->eci, source, local_source, &length); - error_number = extended_charset(symbol, local_source, length); + error_number = utf_to_eci(symbol->eci, source, local_source, &in_length); + error_number = extended_charset(symbol, local_source, in_length); break; default: - error_number = reduced_charset(symbol, local_source, length); + error_number = reduced_charset(symbol, local_source, in_length); break; } } } if ((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { - for (i = 0; i < length; i++) { + for (i = 0; i < in_length; i++) { if (local_source[i] == '\0') { symbol->text[i] = ' '; } else { @@ -1060,7 +1060,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) { return ZINT_ERROR_INVALID_OPTION; } } - + if (strlen(symbol->outfile) > 3) { output[0] = symbol->outfile[strlen(symbol->outfile) - 3]; output[1] = symbol->outfile[strlen(symbol->outfile) - 2]; @@ -1084,7 +1084,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) { if (symbol->scale < 1.0) { symbol->text[0] = '\0'; } - error_number = plot_raster(symbol, rotate_angle, OUT_PCX_FILE); + error_number = plot_raster(symbol, rotate_angle, OUT_PCX_FILE); } else if (!(strcmp(output, "GIF"))) { if (symbol->scale < 1.0) { @@ -1115,7 +1115,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) { /* If libpng is not installed */ strcpy(symbol->errtxt, "Unknown output format"); } - + error_tag(symbol->errtxt, error_number); return error_number; } diff --git a/backend/medical.c b/backend/medical.c index dbe484d7..50aa432b 100644 --- a/backend/medical.c +++ b/backend/medical.c @@ -35,7 +35,7 @@ #include #include "common.h" -extern int c39(struct zint_symbol *symbol, unsigned char source[], int length); +extern int c39(struct zint_symbol *symbol, unsigned char source[], const size_t length); /* Codabar table checked against EN 798:1995 */ #define CALCIUM "0123456789-$:/.+ABCD" diff --git a/backend/pcx.c b/backend/pcx.c index 4525f804..08b4e4ce 100644 --- a/backend/pcx.c +++ b/backend/pcx.c @@ -1,251 +1,252 @@ -/* pcx.c - Handles output to ZSoft PCX file */ - -/* - libzint - the open source barcode library - Copyright (C) 2009-2016 Robin Stuart - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the project nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - SUCH DAMAGE. - */ - -#include -#include -#include -#include "common.h" -#include "pcx.h" /* PCX header structure */ -#include -#ifdef _MSC_VER -#include -#include -#endif - -#define SSET "0123456789ABCDEF" - -int pcx_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) { - int fgred, fggrn, fgblu, bgred, bggrn, bgblu; - int errno; - int row, column, i, colour; - int run_count; - FILE *pcx_file; - pcx_header_t header; -#ifdef _MSC_VER - char* rotated_bitmap; - unsigned char* rle_row; -#endif - -#ifndef _MSC_VER - char rotated_bitmap[image_height * image_width]; -#else - rotated_bitmap = (char *) _alloca((image_height * image_width) * sizeof(char)); -#endif /* _MSC_VER */ - - switch (rotate_angle) { - case 0: - case 180: - symbol->bitmap_width = image_width; - symbol->bitmap_height = image_height; - break; - case 90: - case 270: - symbol->bitmap_width = image_height; - symbol->bitmap_height = image_width; - break; - } - -#ifndef _MSC_VER - unsigned char rle_row[symbol->bitmap_width]; -#else - rle_row = (unsigned char *) _alloca((symbol->bitmap_width * 6) * sizeof(unsigned char)); -#endif /* _MSC_VER */ - - /* sort out colour options */ - to_upper((unsigned char*) symbol->fgcolour); - to_upper((unsigned char*) symbol->bgcolour); - - if (strlen(symbol->fgcolour) != 6) { - strcpy(symbol->errtxt, "Malformed foreground colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - if (strlen(symbol->bgcolour) != 6) { - strcpy(symbol->errtxt, "Malformed background colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour)); - if (errno == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Malformed foreground colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour)); - if (errno == ZINT_ERROR_INVALID_DATA) { - strcpy(symbol->errtxt, "Malformed background colour target"); - return ZINT_ERROR_INVALID_OPTION; - } - - fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); - fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); - fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); - bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); - bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); - bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); - - /* Rotate image before plotting */ - switch (rotate_angle) { - case 0: /* Plot the right way up */ - for (row = 0; row < image_height; row++) { - for (column = 0; column < image_width; column++) { - rotated_bitmap[(row * image_width) + column] = - *(pixelbuf + (image_width * row) + column); - } - } - break; - case 90: /* Plot 90 degrees clockwise */ - for (row = 0; row < image_width; row++) { - for (column = 0; column < image_height; column++) { - rotated_bitmap[(row * image_height) + column] = - *(pixelbuf + (image_width * (image_height - column - 1)) + row); - } - } - break; - case 180: /* Plot upside down */ - for (row = 0; row < image_height; row++) { - for (column = 0; column < image_width; column++) { - rotated_bitmap[(row * image_width) + column] = - *(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1)); - } - } - break; - case 270: /* Plot 90 degrees anti-clockwise */ - for (row = 0; row < image_width; row++) { - for (column = 0; column < image_height; column++) { - rotated_bitmap[(row * image_height) + column] = - *(pixelbuf + (image_width * column) + (image_width - row - 1)); - } - } - break; - } - - - header.manufacturer = 10; // ZSoft - header.version = 5; // Version 3.0 - header.encoding = 1; // Run length encoding - header.bits_per_pixel = 8; - header.window_xmin = 0; - header.window_ymin = 0; - header.window_xmax = symbol->bitmap_width - 1; - header.window_ymax = symbol->bitmap_height - 1; - header.horiz_dpi = 300; - header.vert_dpi = 300; - - for(i = 0; i < 48; i++) { - header.colourmap[i] = 0x00; - } - - header.reserved = 0; - header.number_of_planes = 3; - - if (symbol->bitmap_width % 2) { - header.bytes_per_line = symbol->bitmap_width + 1; - } else { - header.bytes_per_line = symbol->bitmap_width; - } - - header.palette_info = 1; // Colour - header.horiz_screen_size = 0; - header.vert_screen_size = 0; - - for(i = 0; i < 54; i++) { - header.filler[i] = 0x00; - } - - /* Open output file in binary mode */ - if (symbol->output_options & BARCODE_STDOUT) { -#ifdef _MSC_VER - if (-1 == _setmode(_fileno(stdout), _O_BINARY)) { - strcpy(symbol->errtxt, "Can't open output file"); - return ZINT_ERROR_FILE_ACCESS; - } -#endif - pcx_file = stdout; - } else { - if (!(pcx_file = fopen(symbol->outfile, "wb"))) { - strcpy(symbol->errtxt, "Can't open output file"); - return ZINT_ERROR_FILE_ACCESS; - } - } - - fwrite(&header, sizeof(pcx_header_t), 1, pcx_file); - - for(row = 0; row < symbol->bitmap_height; row++) { - for (colour = 0; colour < 3; colour++) { - for (column = 0; column < symbol->bitmap_width; column++) { - switch(colour) { - case 0: - if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { - rle_row[column] = fgred; - } else { - rle_row[column] = bgred; - } - break; - case 1: - if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { - rle_row[column] = fggrn; - } else { - rle_row[column] = bggrn; - } - break; - case 2: - if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { - rle_row[column] = fgblu; - } else { - rle_row[column] = bgblu; - } - break; - } - } - - run_count = 1; - for (column = 1; column < symbol->bitmap_width; column++) { - if ((rle_row[column - 1] == rle_row[column]) && (run_count < 63)) { - run_count++; - } else { - run_count += 0xc0; - fputc(run_count, pcx_file); - fputc(rle_row[column - 1], pcx_file); - run_count = 1; - } - } - - if (run_count > 1) { - run_count += 0xc0; - fputc(run_count, pcx_file); - fputc(rle_row[column - 1], pcx_file); - } - } - } - - fclose(pcx_file); - - return 0; +/* pcx.c - Handles output to ZSoft PCX file */ + +/* + libzint - the open source barcode library + Copyright (C) 2009-2016 Robin Stuart + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the project nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + */ + +#include +#include +#include +#include "common.h" +#include "pcx.h" /* PCX header structure */ +#include +#include +#ifdef _MSC_VER +#include +#include +#endif + +#define SSET "0123456789ABCDEF" + +int pcx_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width, char *pixelbuf, int rotate_angle) { + int fgred, fggrn, fgblu, bgred, bggrn, bgblu; + int errno; + int row, column, i, colour; + int run_count; + FILE *pcx_file; + pcx_header_t header; +#ifdef _MSC_VER + char* rotated_bitmap; + unsigned char* rle_row; +#endif + +#ifndef _MSC_VER + char rotated_bitmap[image_height * image_width]; +#else + rotated_bitmap = (char *) _alloca((image_height * image_width) * sizeof (char)); +#endif /* _MSC_VER */ + + switch (rotate_angle) { + case 0: + case 180: + symbol->bitmap_width = image_width; + symbol->bitmap_height = image_height; + break; + case 90: + case 270: + symbol->bitmap_width = image_height; + symbol->bitmap_height = image_width; + break; + } + +#ifndef _MSC_VER + unsigned char rle_row[symbol->bitmap_width]; +#else + rle_row = (unsigned char *) _alloca((symbol->bitmap_width * 6) * sizeof (unsigned char)); +#endif /* _MSC_VER */ + + /* sort out colour options */ + to_upper((unsigned char*) symbol->fgcolour); + to_upper((unsigned char*) symbol->bgcolour); + + if (strlen(symbol->fgcolour) != 6) { + strcpy(symbol->errtxt, "Malformed foreground colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + if (strlen(symbol->bgcolour) != 6) { + strcpy(symbol->errtxt, "Malformed background colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + errno = is_sane(SSET, (unsigned char*) symbol->fgcolour, strlen(symbol->fgcolour)); + if (errno == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Malformed foreground colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + errno = is_sane(SSET, (unsigned char*) symbol->bgcolour, strlen(symbol->fgcolour)); + if (errno == ZINT_ERROR_INVALID_DATA) { + strcpy(symbol->errtxt, "Malformed background colour target"); + return ZINT_ERROR_INVALID_OPTION; + } + + fgred = (16 * ctoi(symbol->fgcolour[0])) + ctoi(symbol->fgcolour[1]); + fggrn = (16 * ctoi(symbol->fgcolour[2])) + ctoi(symbol->fgcolour[3]); + fgblu = (16 * ctoi(symbol->fgcolour[4])) + ctoi(symbol->fgcolour[5]); + bgred = (16 * ctoi(symbol->bgcolour[0])) + ctoi(symbol->bgcolour[1]); + bggrn = (16 * ctoi(symbol->bgcolour[2])) + ctoi(symbol->bgcolour[3]); + bgblu = (16 * ctoi(symbol->bgcolour[4])) + ctoi(symbol->bgcolour[5]); + + /* Rotate image before plotting */ + switch (rotate_angle) { + case 0: /* Plot the right way up */ + for (row = 0; row < image_height; row++) { + for (column = 0; column < image_width; column++) { + rotated_bitmap[(row * image_width) + column] = + *(pixelbuf + (image_width * row) + column); + } + } + break; + case 90: /* Plot 90 degrees clockwise */ + for (row = 0; row < image_width; row++) { + for (column = 0; column < image_height; column++) { + rotated_bitmap[(row * image_height) + column] = + *(pixelbuf + (image_width * (image_height - column - 1)) + row); + } + } + break; + case 180: /* Plot upside down */ + for (row = 0; row < image_height; row++) { + for (column = 0; column < image_width; column++) { + rotated_bitmap[(row * image_width) + column] = + *(pixelbuf + (image_width * (image_height - row - 1)) + (image_width - column - 1)); + } + } + break; + case 270: /* Plot 90 degrees anti-clockwise */ + for (row = 0; row < image_width; row++) { + for (column = 0; column < image_height; column++) { + rotated_bitmap[(row * image_height) + column] = + *(pixelbuf + (image_width * column) + (image_width - row - 1)); + } + } + break; + } + + + header.manufacturer = 10; // ZSoft + header.version = 5; // Version 3.0 + header.encoding = 1; // Run length encoding + header.bits_per_pixel = 8; + header.window_xmin = 0; + header.window_ymin = 0; + header.window_xmax = symbol->bitmap_width - 1; + header.window_ymax = symbol->bitmap_height - 1; + header.horiz_dpi = 300; + header.vert_dpi = 300; + + for (i = 0; i < 48; i++) { + header.colourmap[i] = 0x00; + } + + header.reserved = 0; + header.number_of_planes = 3; + + if (symbol->bitmap_width % 2) { + header.bytes_per_line = symbol->bitmap_width + 1; + } else { + header.bytes_per_line = symbol->bitmap_width; + } + + header.palette_info = 1; // Colour + header.horiz_screen_size = 0; + header.vert_screen_size = 0; + + for (i = 0; i < 54; i++) { + header.filler[i] = 0x00; + } + + /* Open output file in binary mode */ + if (symbol->output_options & BARCODE_STDOUT) { +#ifdef _MSC_VER + if (-1 == _setmode(_fileno(stdout), _O_BINARY)) { + strcpy(symbol->errtxt, "Can't open output file"); + return ZINT_ERROR_FILE_ACCESS; + } +#endif + pcx_file = stdout; + } else { + if (!(pcx_file = fopen(symbol->outfile, "wb"))) { + strcpy(symbol->errtxt, "Can't open output file"); + return ZINT_ERROR_FILE_ACCESS; + } + } + + fwrite(&header, sizeof (pcx_header_t), 1, pcx_file); + + for (row = 0; row < symbol->bitmap_height; row++) { + for (colour = 0; colour < 3; colour++) { + for (column = 0; column < symbol->bitmap_width; column++) { + switch (colour) { + case 0: + if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { + rle_row[column] = fgred; + } else { + rle_row[column] = bgred; + } + break; + case 1: + if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { + rle_row[column] = fggrn; + } else { + rle_row[column] = bggrn; + } + break; + case 2: + if (rotated_bitmap[(row * symbol->bitmap_width) + column] == '1') { + rle_row[column] = fgblu; + } else { + rle_row[column] = bgblu; + } + break; + } + } + + run_count = 1; + for (column = 1; column < symbol->bitmap_width; column++) { + if ((rle_row[column - 1] == rle_row[column]) && (run_count < 63)) { + run_count++; + } else { + run_count += 0xc0; + fputc(run_count, pcx_file); + fputc(rle_row[column - 1], pcx_file); + run_count = 1; + } + } + + if (run_count > 1) { + run_count += 0xc0; + fputc(run_count, pcx_file); + fputc(rle_row[column - 1], pcx_file); + } + } + } + + fclose(pcx_file); + + return 0; } \ No newline at end of file diff --git a/backend/ps.c b/backend/ps.c index c04db70e..e0b8d6eb 100644 --- a/backend/ps.c +++ b/backend/ps.c @@ -58,7 +58,7 @@ int ps_plot(struct zint_symbol *symbol) { #ifndef _MSC_VER unsigned char local_text[ustrlen(symbol->text) + 1]; #else - unsigned char* local_text = (unsigned char*) _alloca(ustrlen(symbol->text) + 1); + unsigned char* local_text = (unsigned char*) malloc(ustrlen(symbol->text) + 1); #endif row_height = 0; @@ -67,7 +67,7 @@ int ps_plot(struct zint_symbol *symbol) { strcpy(addon, ""); comp_offset = 0; addon_text_posn = 0.0; - + if (symbol->show_hrt != 0) { /* Copy text from symbol */ ustrcpy(local_text, symbol->text); @@ -97,7 +97,7 @@ int ps_plot(struct zint_symbol *symbol) { local_text[0] = '\0'; break; } - } + } if (symbol->output_options & BARCODE_STDOUT) { feps = stdout; @@ -149,7 +149,7 @@ int ps_plot(struct zint_symbol *symbol) { red_paper = bgred / 256.0; green_paper = bggrn / 256.0; blue_paper = bgblu / 256.0; - + /* Convert RGB to CMYK */ if (red_ink > green_ink) { if (blue_ink > red_ink) { @@ -173,7 +173,7 @@ int ps_plot(struct zint_symbol *symbol) { magenta_ink = 0.0; yellow_ink = 0.0; } - + if (red_paper > green_paper) { if (blue_paper > red_paper) { black_paper = 1 - blue_paper; @@ -284,9 +284,9 @@ int ps_plot(struct zint_symbol *symbol) { } fprintf(feps, "%%%%Pages: 0\n"); if (symbol->symbology != BARCODE_MAXICODE) { - fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", (int)ceil((symbol->width + xoffset + xoffset) * scaler), (int)ceil((symbol->height + textoffset + yoffset + yoffset) * scaler)); + fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", (int) ceil((symbol->width + xoffset + xoffset) * scaler), (int) ceil((symbol->height + textoffset + yoffset + yoffset) * scaler)); } else { - fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", (int)ceil((74.0F + xoffset + xoffset) * scaler), (int)ceil((72.0F + yoffset + yoffset) * scaler)); + fprintf(feps, "%%%%BoundingBox: 0 0 %d %d\n", (int) ceil((74.0F + xoffset + xoffset) * scaler), (int) ceil((72.0F + yoffset + yoffset) * scaler)); } fprintf(feps, "%%%%EndComments\n"); @@ -385,7 +385,7 @@ int ps_plot(struct zint_symbol *symbol) { if (symbol->symbology != BARCODE_MAXICODE) { /* everything else uses rectangles (or squares) */ /* Works from the bottom of the symbol up */ - + int addon_latch = 0; for (r = 0; r < symbol->rows; r++) { @@ -405,19 +405,19 @@ int ps_plot(struct zint_symbol *symbol) { } row_posn += (textoffset + yoffset); - if ((symbol->output_options & BARCODE_DOTTY_MODE) != 0) { + if ((symbol->output_options & BARCODE_DOTTY_MODE) != 0) { if ((symbol->output_options & CMYK_COLOUR) == 0) { fprintf(feps, "%.2f %.2f %.2f setrgbcolor\n", red_ink, green_ink, blue_ink); } else { fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink); } - + /* Use dots instead of squares */ for (i = 0; i < symbol->width; i++) { if (module_is_set(symbol, this_row, i)) { fprintf(feps, "%.2f %.2f %.2f TD\n", ((i + xoffset) * scaler) + (scaler / 2.0), (row_posn * scaler) + (scaler / 2.0), (2.0 / 5.0) * scaler); } - } + } } else { /* Normal mode, with rectangles */ @@ -427,7 +427,7 @@ int ps_plot(struct zint_symbol *symbol) { } else { fprintf(feps, "%.2f %.2f %.2f %.2f setcmykcolor\n", cyan_ink, magenta_ink, yellow_ink, black_ink); } - + fprintf(feps, "%.2f %.2f ", row_height * scaler, row_posn * scaler); i = 0; if (module_is_set(symbol, this_row, 0)) { diff --git a/backend/svg.c b/backend/svg.c index 081d7406..9a823fd8 100644 --- a/backend/svg.c +++ b/backend/svg.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "common.h" #define SSET "0123456789ABCDEF" @@ -63,7 +64,7 @@ int svg_plot(struct zint_symbol *symbol) { strcpy(addon, ""); comp_offset = 0; addon_text_posn = 0.0; - + if (symbol->show_hrt != 0) { /* Copy text from symbol */ ustrcpy(local_text, symbol->text); @@ -215,9 +216,9 @@ int svg_plot(struct zint_symbol *symbol) { fprintf(fsvg, "\n"); if (symbol->symbology != BARCODE_MAXICODE) { - fprintf(fsvg, "width + xoffset + xoffset) * scaler), (int)ceil((symbol->height + textoffset + yoffset + yoffset) * scaler)); + fprintf(fsvg, "width + xoffset + xoffset) * scaler), (int) ceil((symbol->height + textoffset + yoffset + yoffset) * scaler)); } else { - fprintf(fsvg, "\n"); if ((ustrlen(local_text) != 0) && (symbol->show_hrt != 0)) { @@ -229,9 +230,9 @@ int svg_plot(struct zint_symbol *symbol) { fprintf(fsvg, "\n \n", symbol->fgcolour); if (symbol->symbology != BARCODE_MAXICODE) { - fprintf(fsvg, " \n", (int)ceil((symbol->width + xoffset + xoffset) * scaler), (int)ceil((symbol->height + textoffset + yoffset + yoffset) * scaler), symbol->bgcolour); + fprintf(fsvg, " \n", (int) ceil((symbol->width + xoffset + xoffset) * scaler), (int) ceil((symbol->height + textoffset + yoffset + yoffset) * scaler), symbol->bgcolour); } else { - fprintf(fsvg, " \n", (int)ceil((74.0F + xoffset + xoffset) * scaler), (int)ceil((72.0F + yoffset + yoffset) * scaler), symbol->bgcolour); + fprintf(fsvg, " \n", (int) ceil((74.0F + xoffset + xoffset) * scaler), (int) ceil((72.0F + yoffset + yoffset) * scaler), symbol->bgcolour); } if ((symbol->output_options & BARCODE_BOX) || (symbol->output_options & BARCODE_BIND)) { @@ -310,8 +311,8 @@ int svg_plot(struct zint_symbol *symbol) { } } row_posn += yoffset; - - if (symbol->output_options & BARCODE_DOTTY_MODE) { + + if (symbol->output_options & BARCODE_DOTTY_MODE) { /* Use (currently undocumented) dot mode - see SF ticket #29 */ for (i = 0; i < symbol->width; i++) { if (module_is_set(symbol, this_row, i)) { @@ -326,7 +327,7 @@ int svg_plot(struct zint_symbol *symbol) { } else { latch = 0; } - + do { block_width = 0; do { diff --git a/win32/libzint.vcxproj b/win32/libzint.vcxproj new file mode 100644 index 00000000..d1c4c86b --- /dev/null +++ b/win32/libzint.vcxproj @@ -0,0 +1,236 @@ + + + + + Debug + Win32 + + + Release_LIB + Win32 + + + Release + Win32 + + + + {5C08DC40-8F7D-475E-AA3C-814DED735A4B} + libzint_png_qr + Win32Proj + + + + StaticLibrary + v120 + MultiByte + false + + + DynamicLibrary + v120 + MultiByte + false + + + DynamicLibrary + MultiByte + v110 + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + true + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + false + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + + + + Disabled + ..\..\..\support\lpng169;..\..\zlib128-dll\include;%(AdditionalIncludeDirectories) + NO_PNG;WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;ZINT_VERSION="2.4.4";BUILD_ZINT_DLL;ZLIB_DLL;PNG_DLL;DEBUG;%(PreprocessorDefinitions) + true + + EnableFastChecks + true + MultiThreadedDebugDLL + false + + Level3 + EditAndContinue + CompileAsCpp + 4018;4244;4305;%(DisableSpecificWarnings) + + + _DEBUG;%(PreprocessorDefinitions) + + + false + + + %(AdditionalDependencies) + $(OutDir)zintd.dll + ..\..\..\support\lpng169\projects\visualc71\Win32_LIB_Debug;..\..\..\support\lpng169\projects\visualc71\Win32_LIB_Debug\ZLib;%(AdditionalLibraryDirectories) + libcmtd.lib;%(IgnoreSpecificDefaultLibraries) + true + Windows + MachineX86 + + + + + MaxSpeed + false + ..\..\..\support\lpng169;..\..\zlib128-dll\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;ZINT_VERSION="2.4.4";BUILD_ZINT_DLL;ZLIB_DLL;PNG_DLL;%(PreprocessorDefinitions) + true + + MultiThreadedDLL + false + false + + Level3 + + CompileAsCpp + 4018;4244;4305;%(DisableSpecificWarnings) + + + NDEBUG;%(PreprocessorDefinitions) + + + false + + + libpng.lib;zlib.lib;%(AdditionalDependencies) + $(OutDir)zint.dll + ..\..\..\support\lpng169\projects\visualc71\Win32_LIB_Release;..\..\..\support\lpng169\projects\visualc71\Win32_LIB_Release\ZLib;%(AdditionalLibraryDirectories) + false + Windows + true + true + MachineX86 + + + + + MaxSpeed + false + d:\opt\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;ZINT_VERSION="2.4.4";%(PreprocessorDefinitions) + true + + MultiThreadedDLL + false + false + + Level3 + + CompileAsCpp + 4018;4244;4305;%(DisableSpecificWarnings) + + + NDEBUG;%(PreprocessorDefinitions) + + + $(OutDir)libzintMD.lib + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + \ No newline at end of file diff --git a/win32/zint.sln b/win32/zint.sln index cb918305..0860b22d 100644 --- a/win32/zint.sln +++ b/win32/zint.sln @@ -1,12 +1,11 @@  -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zint", "zint.vcproj", "{3169C7FA-E52C-4BFC-B7BB-E55EBA133770}" - ProjectSection(ProjectDependencies) = postProject - {5C08DC40-8F7D-475E-AA3C-814DED735A4B} = {5C08DC40-8F7D-475E-AA3C-814DED735A4B} - EndProjectSection +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zint", "zint.vcxproj", "{3169C7FA-E52C-4BFC-B7BB-E55EBA133770}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzint", "libzint.vcproj", "{5C08DC40-8F7D-475E-AA3C-814DED735A4B}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzint", "libzint.vcxproj", "{5C08DC40-8F7D-475E-AA3C-814DED735A4B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/win32/zint.vcxproj b/win32/zint.vcxproj new file mode 100644 index 00000000..920e8b32 --- /dev/null +++ b/win32/zint.vcxproj @@ -0,0 +1,145 @@ + + + + + Debug + Win32 + + + Release_LIB + Win32 + + + Release + Win32 + + + + {3169C7FA-E52C-4BFC-B7BB-E55EBA133770} + zint + Win32Proj + + + + Application + v120 + MultiByte + false + + + Application + v120 + MultiByte + false + + + Application + v120 + MultiByte + + + + + + + + + + + + + + + + <_ProjectFileVersion>12.0.30501.0 + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + + + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + + + + Disabled + ..\backend;%(AdditionalIncludeDirectories) + WIN32;_WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;ZINT_VERSION="2.3.0";ZINT_DLL;%(PreprocessorDefinitions) + true + + EnableFastChecks + true + MultiThreadedDebugDLL + true + + Level3 + EditAndContinue + + + true + + + + + MaxSpeed + ..\backend;%(AdditionalIncludeDirectories) + WIN32;_WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;ZINT_VERSION="2.3.0";ZINT_DLL;%(PreprocessorDefinitions) + true + + MultiThreaded + false + false + + Level3 + + + + d:\opt\lib;%(AdditionalLibraryDirectories) + + + + + MaxSpeed + ..\backend;%(AdditionalIncludeDirectories) + WIN32;_WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;ZINT_VERSION="2.3.0";%(PreprocessorDefinitions) + true + + MultiThreadedDLL + false + false + + Level3 + + + + libpngMD.lib;zlibMD.lib;%(AdditionalDependencies) + d:\opt\lib;%(AdditionalLibraryDirectories) + + + + + + + + + + + + + + + + + {5c08dc40-8f7d-475e-aa3c-814ded735a4b} + false + + + + + + \ No newline at end of file