diff --git a/backend/code1.h b/backend/code1.h index 532dc771..b3c498ad 100644 --- a/backend/code1.h +++ b/backend/code1.h @@ -3,55 +3,41 @@ /* libzint - the open source barcode library Copyright (C) 2009 Robin Stuart - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -static int c40_shift[] = { +static const int c40_shift[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; - -static int c40_value[] = { + +static const int c40_value[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, 15,16,17,18,19,20,21,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39, 22,23,24,25,26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; - -static int text_shift[] = { + +static const int text_shift[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3 }; -static int text_value[] = { +static const int text_value[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, 15,16,17,18,19,20,21,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26, 22,23,24,25,26,0,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,27,28,29,30,31 }; -static int c1_height[] = { 16, 22, 28, 40, 52, 70, 104, 148 }; -static int c1_width[] = { 18, 22, 32, 42, 54, 76, 98, 134 }; -static int c1_data_length[] = { 10, 19, 44, 91, 182, 370, 732, 1480 }; -static int c1_ecc_length[] = { 10, 16, 26, 44, 70, 140, 280, 560 }; -static int c1_blocks[] = { 1, 1, 1, 1, 1, 2, 4, 8 }; -static int c1_data_blocks[] = { 10, 19, 44, 91, 182, 185, 183, 185 }; -static int c1_ecc_blocks[] = { 10, 16, 26, 44, 70, 70, 70, 70 }; -static int c1_grid_width[] = { 4, 5, 7, 9, 12, 17, 22, 30 }; -static int c1_grid_height[] = { 5, 7, 10, 15, 21, 30, 46, 68 }; +static const int c1_height[] = { 16, 22, 28, 40, 52, 70, 104, 148 }; +static const int c1_width[] = { 18, 22, 32, 42, 54, 76, 98, 134 }; +static const int c1_data_length[] = { 10, 19, 44, 91, 182, 370, 732, 1480 }; +static const int c1_ecc_length[] = { 10, 16, 26, 44, 70, 140, 280, 560 }; +static const int c1_blocks[] = { 1, 1, 1, 1, 1, 2, 4, 8 }; +static const int c1_data_blocks[] = { 10, 19, 44, 91, 182, 185, 183, 185 }; +static const int c1_ecc_blocks[] = { 10, 16, 26, 44, 70, 70, 70, 70 }; +static const int c1_grid_width[] = { 4, 5, 7, 9, 12, 17, 22, 30 }; +static const int c1_grid_height[] = { 5, 7, 10, 15, 21, 30, 46, 68 }; #define C1_ASCII 1 #define C1_C40 2 diff --git a/backend/code128.c b/backend/code128.c index b1e156e6..4e327d1f 100644 --- a/backend/code128.c +++ b/backend/code128.c @@ -32,7 +32,7 @@ static int list[2][170]; /* Code 128 tables checked against ISO/IEC 15417:2007 */ -static char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322", "131222", "122213", +static const char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322", "131222", "122213", "122312", "132212", "221213", "221312", "231212", "112232", "122132", "122231", "113222", "123122", "123221", "223211", "221132", "221231", "213212", "223112", "312131", "311222", "321122", "321221", "312212", "322112", "322211", "212123", "212321", "232121", "111323", @@ -63,6 +63,9 @@ int parunmodd(unsigned char llyth) return modd; } +/** + * bring together same type blocks + */ void grwp(int *indexliste) { int i, j; @@ -90,6 +93,9 @@ void grwp(int *indexliste) } } +/** + * Implements rules from ISO 15417 Annex E + */ void dxsmooth(int *indexliste) { /* Implements rules from ISO 15417 Annex E */ int i, current, last, next, length; @@ -128,6 +134,10 @@ void dxsmooth(int *indexliste) } +/** + * Translate Code 128 Set A characters into barcodes. + * This set handles all control characters NULL to US. + */ void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars) { /* Translate Code 128 Set A characters into barcodes */ /* This set handles all control characters NULL to US */ @@ -152,10 +162,13 @@ void c128_set_a(unsigned char source, char dest[], int values[], int *bar_chars) (*bar_chars)++; } +/** + * Translate Code 128 Set B characters into barcodes. + * This set handles all characters which are not part of long numbers and not + * control characters. + */ void c128_set_b(unsigned char source, char dest[], int values[], int *bar_chars) -{ /* Translate Code 128 Set B characters into barcodes */ - /* This set handles all characters which are not part of long numbers and not control characters */ - +{ if(source > 127) { concat(dest, C128Table[source - 32 - 128]); values[(*bar_chars)] = source - 32 - 128; @@ -184,10 +197,10 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) char set[170] = { ' ' }, fset[170] = { ' ' }, mode, last_set, current_set = ' '; float glyph_count; char dest[1000]; - + error_number = 0; strcpy(dest, ""); - + sourcelen = length; j = 0; @@ -200,7 +213,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + /* Detect extended ASCII characters */ for(i = 0; i < sourcelen; i++) { if(source[i] >= 128) @@ -216,13 +229,13 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) } else { j = 0; } - + if(j >= 5) { for(k = i; k > (i - 5); k--) { fset[k] = 'F'; } } - + if((j >= 3) && (i == (sourcelen - 1))) { for(k = i; k > (i - 3); k--) { fset[k] = 'F'; @@ -248,7 +261,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) /* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */ indexliste = 0; indexchaine = 0; - + mode = parunmodd(source[indexchaine]); if((symbol->symbology == BARCODE_CODE128B) && (mode == ABORC)) { mode = AORB; @@ -270,7 +283,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) } indexliste++; } while (indexchaine < sourcelen); - + dxsmooth(&indexliste); /* Resolve odd length LATCHC blocks */ @@ -295,7 +308,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) } /* Put set data into set[] */ - + read = 0; for(i = 0; i < indexliste; i++) { for(j = 0; j < list[0][i]; j++) { @@ -356,7 +369,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) glyph_count = glyph_count + 2.0; } } - + if(set[i] == 'C') { glyph_count = glyph_count + 0.5; } else { @@ -367,8 +380,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - - + /* So now we know what start character to use - we can get on with it! */ if(symbol->output_options & READER_INIT) { /* Reader Initialisation mode */ @@ -422,7 +434,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) } bar_characters++; last_set = set[0]; - + if(fset[0] == 'F') { switch(current_set) { case 'A': @@ -441,7 +453,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) bar_characters += 2; f_state = 1; } - + /* Encode the data */ read = 0; do { @@ -545,7 +557,7 @@ int code_128(struct zint_symbol *symbol, unsigned char source[], int length) read += 2; break; } - + } while (read < sourcelen); /* check digit calculation */ @@ -593,7 +605,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) memset(values, 0, sizeof(values)); memset(set, ' ', sizeof(set)); - + if(length > 160) { /* This only blocks rediculously long input - the actual length of the resulting barcode depends on the type of data, so this is trapped later */ @@ -607,7 +619,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) return ERROR_INVALID_DATA; } } - + /* if part of a composite symbol make room for the separator pattern */ if(symbol->symbology == BARCODE_EAN128_CC) { separator_row = symbol->rows; @@ -620,11 +632,11 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) error_number = gs1_verify(symbol, source, length, reduced); if(error_number != 0) { return error_number; } } - + /* Decide on mode using same system as PDF417 and rules of ISO 15417 Annex E */ indexliste = 0; indexchaine = 0; - + mode = parunmodd(reduced[indexchaine]); if(reduced[indexchaine] == '[') { mode = ABORC; @@ -644,9 +656,9 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) } indexliste++; } while (indexchaine < strlen(reduced)); - + dxsmooth(&indexliste); - + /* Put set data into set[] */ read = 0; for(i = 0; i < indexliste; i++) { @@ -720,7 +732,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) glyph_count = glyph_count + 1.0; } } - + if((set[i] == 'C') && (reduced[i] != '[')) { glyph_count = glyph_count + 0.5; } else { @@ -731,7 +743,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + /* So now we know what start character to use - we can get on with it! */ switch(set[0]) { @@ -749,7 +761,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) break; } bar_characters++; - + concat(dest, C128Table[102]); values[1] = 102; bar_characters++; @@ -776,7 +788,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) break; } } - + if((set[read] == 'a') || (set[read] == 'b')) { /* Insert shift character */ concat(dest, C128Table[98]); @@ -809,7 +821,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) read++; } } while (read < strlen(reduced)); - + /* "...note that the linkage flag is an extra code set character between the last data character and the Symbol Check Character" (GS1 Specification) */ @@ -834,7 +846,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) } break; } - + if(linkage_flag != 0) { concat(dest, C128Table[linkage_flag]); values[bar_characters] = linkage_flag; @@ -860,13 +872,13 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) concat(dest, C128Table[total_sum%103]); values[bar_characters] = total_sum % 103; bar_characters++; - + /* Stop character */ concat(dest, C128Table[106]); values[bar_characters] = 106; bar_characters++; expand(symbol, dest); - + /* Add the separator pattern for composite symbols */ if(symbol->symbology == BARCODE_EAN128_CC) { for(i = 0; i < symbol->width; i++) { @@ -887,7 +899,7 @@ int ean_128(struct zint_symbol *symbol, unsigned char source[], int length) symbol->text[i] = ')'; } } - + return error_number; } @@ -896,15 +908,15 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length) /* Add check digit if encoding an NVE18 symbol */ int error_number, zeroes, i, nve_check, total_sum, sourcelen; unsigned char ean128_equiv[25]; - + memset(ean128_equiv, 0, 25); sourcelen = length; - + if(sourcelen > 17) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + error_number = is_sane(NEON, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid characters in data"); @@ -914,12 +926,12 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length) strcpy((char *)ean128_equiv, "[00]"); memset(ean128_equiv + 4, '0', zeroes); strcpy((char*)ean128_equiv + 4 + zeroes, (char*)source); - + total_sum = 0; for(i = sourcelen - 1; i >= 0; i--) { total_sum += ctoi(source[i]); - + if(!(i & 1)) { total_sum += 2 * ctoi(source[i]); } @@ -930,7 +942,7 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[], int length) ean128_equiv[22] = '\0'; error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv)); - + return error_number; } @@ -940,23 +952,23 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[], int length) int i, count, check_digit; int error_number, zeroes; unsigned char ean128_equiv[20]; - + if(length > 13) { strcpy(symbol->errtxt, "Input wrong length"); return ERROR_TOO_LONG; } - + error_number = is_sane(NEON, source, length); if(error_number == ERROR_INVALID_DATA) { strcpy(symbol->errtxt, "Invalid character in data"); return error_number; } - + zeroes = 13 - length; strcpy((char*)ean128_equiv, "[01]"); memset(ean128_equiv + 4, '0', zeroes); ustrcpy(ean128_equiv + 4 + zeroes, source); - + count = 0; for (i = length - 1; i >= 0; i--) { count += ctoi(source[i]); @@ -969,8 +981,8 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[], int length) if (check_digit == 10) { check_digit = 0; } ean128_equiv[17] = itoc(check_digit); ean128_equiv[18] = '\0'; - + error_number = ean_128(symbol, ean128_equiv, ustrlen(ean128_equiv)); - + return error_number; } diff --git a/backend/code16k.c b/backend/code16k.c index 324e7874..d9601b3b 100644 --- a/backend/code16k.c +++ b/backend/code16k.c @@ -170,16 +170,16 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) errornum = 0; strcpy(width_pattern, ""); input_length = length; - + if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } - + if(input_length > 157) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } bar_characters = 0; - + /* Detect extended ASCII characters */ for(i = 0; i < input_length; i++) { if(source[i] >=128) { @@ -187,7 +187,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) } } fset[i] = '\0'; - + /* Decide when to latch to extended mode */ for(i = 0; i < input_length; i++) { j = 0; @@ -202,7 +202,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) } } } - + /* Decide if it is worth reverting to 646 encodation for a few characters */ if(input_length > 1) { for(i = 1; i < input_length; i++) { @@ -221,14 +221,14 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) /* Detect mode A, B and C characters */ indexliste = 0; indexchaine = 0; - + mode = parunmodd(source[indexchaine]); if((gs1) && (source[indexchaine] == '[')) { mode = ABORC; } /* FNC1 */ - + for(i = 0; i < 160; i++) { list[0][i] = 0; } - + do { list[1][indexliste] = mode; while ((list[1][indexliste] == mode) && (indexchaine < input_length)) { @@ -239,9 +239,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) } indexliste++; } while (indexchaine < input_length); - + dxsmooth16(&indexliste); - + /* Put set data into set[] */ read = 0; for(i = 0; i < indexliste; i++) { @@ -256,7 +256,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) read++; } } - + /* Adjust for strings which start with shift characters - make them latch instead */ if(set[0] == 'a') { i = 0; @@ -265,7 +265,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) i++; } while (set[i] == 'a'); } - + if(set[0] == 'b') { i = 0; do { @@ -273,7 +273,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) i++; } while (set[i] == 'b'); } - + /* Watch out for odd-length Mode C blocks */ c_count = 0; for(i = 0; i < read; i++) { @@ -313,7 +313,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) set[i] = 'B'; } } - + /* Make sure the data will fit in the symbol */ last_set = ' '; glyph_count = 0.0; @@ -350,34 +350,34 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) glyph_count = glyph_count + 2.0; } } - + if((set[i] == 'C') && (!((gs1) && (source[i] == '[')))) { glyph_count = glyph_count + 0.5; } else { glyph_count = glyph_count + 1.0; } } - + if((gs1) && (set[0] != 'A')) { /* FNC1 can be integrated with mode character */ glyph_count--; } - + if(glyph_count > 77.0) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + /* Calculate how tall the symbol will be */ glyph_count = glyph_count + 2.0; i = glyph_count; rows_needed = (i/5); if(i%5 > 0) { rows_needed++; } - + if(rows_needed == 1) { rows_needed = 2; } - + /* start with the mode character - Table 2 */ m = 0; switch(set[0]) { @@ -385,7 +385,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) case 'B': m = 1; break; case 'C': m = 2; break; } - + if(symbol->output_options & READER_INIT) { if(m == 2) { m = 5; } if(gs1) { @@ -429,9 +429,9 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) bar_characters += 2; f_state = 1; } - + read = 0; - + /* Encode the data */ do { @@ -494,7 +494,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) f_state = 0; } } - + if((fset[i] == 'f') || (fset[i] == 'n')) { /* Shift extended mode */ switch(current_set) { @@ -507,13 +507,13 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) } bar_characters++; } - + if((set[i] == 'a') || (set[i] == 'b')) { /* Insert shift character */ values[bar_characters] = 98; bar_characters++; } - + if(!((gs1) && (source[read] == '['))) { switch(set[read]) { /* Encode data characters */ @@ -538,7 +538,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) } /* printf("tp9 read=%d surrent set=%c\n", read, set[read]); */ } while (read < ustrlen(source)); - + pads_needed = 5 - ((bar_characters + 2) % 5); if(pads_needed == 5) { pads_needed = 0; @@ -550,7 +550,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) values[bar_characters] = 106; bar_characters++; } - + /* Calculate check digits */ first_sum = 0; second_sum = 0; @@ -565,16 +565,16 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) values[bar_characters] = first_check; values[bar_characters + 1] = second_check; bar_characters += 2; - + for(current_row = 0; current_row < rows_needed; current_row++) { - + strcpy(width_pattern, ""); concat(width_pattern, C16KStartStop[C16KStartValues[current_row]]); concat(width_pattern, "1"); for(i = 0; i < 5; i++) { concat(width_pattern, C16KTable[values[(current_row * 5) + i]]); /* printf("[%d] ", values[(current_row * 5) + i]); */ - + } concat(width_pattern, C16KStartStop[C16KStopValues[current_row]]); /* printf("\n"); */ @@ -594,7 +594,7 @@ int code16k(struct zint_symbol *symbol, unsigned char source[], int length) } symbol->row_height[current_row] = 10; } - + symbol->rows = rows_needed; symbol->width = 70; return errornum; diff --git a/backend/code49.c b/backend/code49.c index 0457fdeb..f93b6d9b 100644 --- a/backend/code49.c +++ b/backend/code49.c @@ -69,13 +69,13 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) int block_count, c; int block_remain; int block_value; - + codewords[codeword_count] = 48; /* Numeric Shift */ codeword_count++; - + block_count = j / 5; block_remain = j % 5; - + for(c = 0; c < block_count; c++) { if((c == block_count - 1) && (block_remain == 2)) { /* Rule (d) */ @@ -84,7 +84,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) block_value += ctoi(intermediate[i + 1]) * 100; block_value += ctoi(intermediate[i + 2]) * 10; block_value += ctoi(intermediate[i + 3]); - + codewords[codeword_count] = block_value / (48 * 48); block_value = block_value - (48 * 48) * codewords[codeword_count]; codeword_count++; @@ -97,20 +97,20 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) block_value = ctoi(intermediate[i]) * 100; block_value += ctoi(intermediate[i + 1]) * 10; block_value += ctoi(intermediate[i + 2]); - + codewords[codeword_count] = block_value / 48; block_value = block_value - 48 * codewords[codeword_count]; codeword_count++; codewords[codeword_count] = block_value; codeword_count++; i += 3; - } else { + } else { block_value = ctoi(intermediate[i]) * 10000; block_value += ctoi(intermediate[i + 1]) * 1000; block_value += ctoi(intermediate[i + 2]) * 100; block_value += ctoi(intermediate[i + 3]) * 10; block_value += ctoi(intermediate[i + 4]); - + codewords[codeword_count] = block_value / (48 * 48); block_value = block_value - (48 * 48) * codewords[codeword_count]; codeword_count++; @@ -122,7 +122,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) i += 5; } } - + switch(block_remain) { case 1: /* Rule (a) */ @@ -135,7 +135,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) block_value = ctoi(intermediate[i]) * 100; block_value += ctoi(intermediate[i + 1]) * 10; block_value += ctoi(intermediate[i + 2]); - + codewords[codeword_count] = block_value / 48; block_value = block_value - 48 * codewords[codeword_count]; codeword_count++; @@ -150,7 +150,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) block_value += ctoi(intermediate[i + 1]) * 100; block_value += ctoi(intermediate[i + 2]) * 10; block_value += ctoi(intermediate[i + 3]); - + codewords[codeword_count] = block_value / (48 * 48); block_value = block_value - (48 * 48) * codewords[codeword_count]; codeword_count++; @@ -178,26 +178,26 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) i++; } } while(i < h); - + switch(codewords[0]) { /* Set starting mode value */ case 48: M = 2; break; case 43: M = 4; break; case 44: M = 5; break; default: M = 0; break; } - + if(M != 0) { for(i = 0; i < codeword_count; i++) { codewords[i] = codewords[i + 1]; } codeword_count--; } - + if(codeword_count > 49) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + /* Place codewords in code character array (c grid) */ rows = 0; do{ @@ -211,7 +211,7 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) } rows++; } while ((rows * 7) < codeword_count); - + if((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) { /* Add a row */ for(i = 0; i < 7; i++) { @@ -219,20 +219,20 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) } rows++; } - + /* Add row count and mode character */ c_grid[rows - 1][6] = (7 * (rows - 2)) + M; - + /* Add row check character */ for(i = 0; i < rows - 1; i++) { int row_sum = 0; - + for(j = 0; j < 7; j++) { row_sum += c_grid[i][j]; } c_grid[i][7] = row_sum % 49; } - + /* Calculate Symbol Check Characters */ posn_val = 0; x_count = c_grid[rows - 1][6] * 20; @@ -247,43 +247,43 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) posn_val++; } } - + if(rows > 6) { /* Add Z Symbol Check */ c_grid[rows - 1][0] = (z_count % 2401) / 49; c_grid[rows - 1][1] = (z_count % 2401) % 49; } - + local_value = (c_grid[rows - 1][0] * 49) + c_grid[rows - 1][1]; x_count += c49_x_weight[posn_val] * local_value; y_count += c49_y_weight[posn_val] * local_value; posn_val++; - + /* Add Y Symbol Check */ c_grid[rows - 1][2] = (y_count % 2401) / 49; c_grid[rows - 1][3] = (y_count % 2401) % 49; - + local_value = (c_grid[rows - 1][2] * 49) + c_grid[rows - 1][3]; x_count += c49_x_weight[posn_val] * local_value; - + /* Add X Symbol Check */ c_grid[rows - 1][4] = (x_count % 2401) / 49; c_grid[rows - 1][5] = (x_count % 2401) % 49; - + /* Add last row check character */ j = 0; for(i = 0; i < 7; i++) { j += c_grid[rows - 1][i]; } c_grid[rows - 1][7] = j % 49; - + /* Transfer data to symbol character array (w grid) */ for(i = 0; i < rows; i++) { for(j = 0; j < 4; j ++) { w_grid[i][j] = (c_grid[i][2 * j] * 49) + c_grid[i][(2 * j) + 1]; } } - + for(i = 0; i < rows; i++) { strcpy(pattern, "11"); /* Start character */ for(j = 0; j < 4; j++) { @@ -301,12 +301,12 @@ int code_49(struct zint_symbol *symbol, unsigned char source[], int length) } } concat(pattern, "4"); /* Stop character */ - + /* Expand into symbol */ symbol->row_height[i] = 10; expand(symbol, pattern); } - + symbol->whitespace_width = 10; symbol->output_options = BARCODE_BIND; symbol->border_width = 2; diff --git a/backend/code49.h b/backend/code49.h index 2b27bc1b..96ac85a2 100644 --- a/backend/code49.h +++ b/backend/code49.h @@ -21,7 +21,7 @@ /* This data set taken from ANSI/AIM-BC6-2000, 4th April 2000 */ -static char *c49_table7[128] = { +static const char *c49_table7[128] = { /* Table 7: Code 49 ASCII Chart */ "! ", "!A", "!B", "!C", "!D", "!E", "!F", "!G", "!H", "!I", "!J", "!K", "!L", "!M", "!N", "!O", "!P", "!Q", "!R", "!S", "!T", "!U", "!V", "!W", "!X", "!Y", @@ -36,27 +36,27 @@ static char *c49_table7[128] = { }; /* Table 5: Check Character Weighting Values */ -int c49_x_weight[] = { +static const int c49_x_weight[] = { 1, 9, 31, 26, 2, 12, 17, 23, 37, 18, 22, 6, 27, 44, 15, 43, 39, 11, 13, 5, 41, 33, 36, 8, 4, 32, 3, 19, 40, 25, 29, 10 }; -int c49_y_weight[] = { +static const int c49_y_weight[] = { 9, 31, 26, 2, 12, 17, 23, 37, 18, 22, 6, 27, 44, 15, 43, 39, 11, 13, 5, 41, 33, 36, 8, 4, 32, 3, 19, 40, 25, 29, 10, 24 }; -int c49_z_weight[] = { +static const int c49_z_weight[] = { 31, 26, 2, 12, 17, 23, 37, 18, 22, 6, 27, 44, 15, 43, 39, 11, 13, 5, 41, 33, 36, 8, 4, 32, 3, 19, 40, 25, 29, 10, 24, 30 }; -static char *c49_table4[8] = { +static const char *c49_table4[8] = { /* Table 4: Row Parity Pattern for Code 49 Symbols */ "OEEO", "EOEO", "OOEE", "EEOO", "OEOE", "EOOE", "OOOO", "EEEE" }; -static char *c49_appxe_even[2401] = { +static const char *c49_appxe_even[2401] = { /* Appendix E - Code 49 Encodation Patterns (Even Symbol Character Parity) */ /* Column 1 */ "11521132", @@ -615,7 +615,7 @@ static char *c49_appxe_even[2401] = { "31412311", "15121132", "24221131", "13321132", "22421131" }; -static char *c49_appxe_odd[2401] = { +static const char *c49_appxe_odd[2401] = { /* Appendix E - Code 49 Encodation Patterns (Odd Symbol Character Parity) */ /* Column 1 */ "22121116", diff --git a/backend/common.c b/backend/common.c index 28d2990a..dfcc9c19 100644 --- a/backend/common.c +++ b/backend/common.c @@ -23,7 +23,7 @@ #include #include "common.h" -int ustrlen(unsigned char data[]) { +int ustrlen(const unsigned char data[]) { /* Local replacement for strlen() with unsigned char strings */ int i; for (i=0;data[i];i++); @@ -31,7 +31,7 @@ int ustrlen(unsigned char data[]) { return i; } -void ustrcpy(unsigned char target[], unsigned char source[]) { +void ustrcpy(unsigned char target[],const unsigned char source[]) { /* Local replacement for strcpy() with unsigned char strings */ int i, len; @@ -52,7 +52,7 @@ void concat(char dest[],const char source[]) dest[i + j] = source[i]; } } -void uconcat(unsigned char dest[], unsigned char source[]) +void uconcat(unsigned char dest[], const unsigned char source[]) { /* Concatinates dest[] with the contents of source[], copying /0 as well */ unsigned int i, j; @@ -104,7 +104,7 @@ int is_sane(char test_string[], unsigned char source[], int length) return ERROR_INVALID_DATA; } } - + return 0; } @@ -188,14 +188,14 @@ void unset_module(struct zint_symbol *symbol, int y_coord, int x_coord) void expand(struct zint_symbol *symbol, char data[]) { /* Expands from a width pattern to a bit pattern */ - + unsigned int reader, n = strlen(data); int writer, i; char latch; - + writer = 0; latch = '1'; - + for(reader = 0; reader < n; reader++) { for(i = 0; i < ctoi(data[reader]); i++) { if(latch == '1') { set_module(symbol, symbol->rows, writer); } @@ -204,7 +204,7 @@ void expand(struct zint_symbol *symbol, char data[]) latch = (latch == '1' ? '0' : '1'); } - + if(symbol->symbology != BARCODE_PHARMA) { if(writer > symbol->width) { symbol->width = writer; @@ -230,7 +230,7 @@ int is_stackable(int symbology) { if(symbology == BARCODE_TELEPEN_NUM) { return 1; } if(symbology == BARCODE_ITF14) { return 1; } if(symbology == BARCODE_CODE32) { return 1; } - + return 0; } @@ -243,7 +243,7 @@ int is_extendable(int symbology) { if(symbology == BARCODE_UPCA_CC) { return 1; } if(symbology == BARCODE_UPCE_CC) { return 1; } if(symbology == BARCODE_EANX_CC) { return 1; } - + return 0; } @@ -251,14 +251,14 @@ int roundup(float input) { float remainder; int integer_part; - + integer_part = (int)input; remainder = input - integer_part; - + if(remainder > 0.1) { integer_part++; } - + return integer_part; } @@ -269,17 +269,17 @@ int istwodigits(unsigned char source[], int position) return 1; } } - + return 0; } float froundup(float input) { float fraction, output = 0.0; - + fraction = input - (int)input; if(fraction > 0.01) { output = (input - fraction) + 1.0; } else { output = input; } - + return output; } @@ -316,7 +316,7 @@ int latin1_process(struct zint_symbol *symbol, unsigned char source[], unsigned } while(i < *length); preprocessed[j] = '\0'; *length = j; - + return 0; } @@ -324,12 +324,12 @@ int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], { int bpos, jpos, error_number; int next; - + bpos = 0; jpos = 0; error_number = 0; next = 0; - + do { if(source[bpos] <= 0x7f) { /* 1 byte mode (7-bit ASCII) */ @@ -363,12 +363,12 @@ int utf8toutf16(struct zint_symbol *symbol, unsigned char source[], int vals[], return ERROR_INVALID_DATA; } } - + bpos = next; - + } while(bpos < *length); *length = jpos; - + return error_number; } diff --git a/backend/common.h b/backend/common.h index 08f336e9..2f4f2d07 100644 --- a/backend/common.h +++ b/backend/common.h @@ -27,10 +27,10 @@ extern "C" { #endif /* __cplusplus */ -extern int ustrlen(unsigned char source[]); -extern void ustrcpy(unsigned char target[], unsigned char source[]); -extern void concat(char dest[],const char source[]); -extern void uconcat(unsigned char dest[], unsigned char source[]); +extern int ustrlen(const unsigned char source[]); +extern void ustrcpy(unsigned char target[], const unsigned char source[]); +extern void concat(char dest[], const char source[]); +extern void uconcat(unsigned char dest[], const unsigned char source[]); extern int ctoi(char source); extern char itoc(int source); extern void to_upper(unsigned char source[]); diff --git a/backend/composite.c b/backend/composite.c index eaaaf5f8..33a19772 100644 --- a/backend/composite.c +++ b/backend/composite.c @@ -7,19 +7,19 @@ /* The functions "getBit", "init928" and "encode928" are copyright BSI and are released with permission under the following terms: - + "Copyright subsists in all BSI publications. BSI also holds the copyright, in the UK, of the international standardisation bodies. Except as permitted under the Copyright, Designs and Patents Act 1988 no extract may be reproduced, stored in a retrieval system or transmitted in any form or by any means - electronic, photocopying, recording or otherwise - without prior written permission from BSI. - + "This does not preclude the free use, in the course of implementing the standard, of necessary details such as symbols, and size, type or grade designations. If these details are to be used for any other purpose than implementation then the prior written permission of BSI must be obtained." - + The date of publication for these functions is 31 May 2006 */ @@ -67,7 +67,7 @@ void init928(void) { cw[6] = 1L; for (i = 5; i >= 0; i--) cw[i] = 0; - + for (i = 0; i < 7; i++) pwr928[0][i] = cw[i]; for (j = 1; j < 69; j++) { @@ -119,13 +119,13 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) for(i = 0; i < 13; i++) { bitStr[i] = 0; } for(i = 0; i < 28; i++) { codeWords[i] = 0; } - + bitlen = strlen(source); - + for(i = 0; i < 208; i++) { local_source[i] = '0'; } for(i = 0; i < bitlen; i++) { local_source[i] = source[i]; } local_source[208] = '\0'; - + for(segment = 0; segment < 13; segment++) { strpos = segment * 16; if(local_source[strpos] == '1') { bitStr[segment] += 0x8000; } @@ -145,11 +145,11 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) if(local_source[strpos + 14] == '1') { bitStr[segment] += 0x02; } if(local_source[strpos + 15] == '1') { bitStr[segment] += 0x01; } } - + init928(); /* encode codeWords from bitStr */ cwCnt = encode928(bitStr, codeWords, bitlen); - + switch(cc_width) { case 2: switch(cwCnt) { @@ -181,11 +181,11 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) } break; } - + rows = ccaVariants[variant]; k = ccaVariants[17 + variant]; offset = ccaVariants[34 + variant]; - + /* Reed-Solomon error correction */ for(i = 0; i < 8; i++) { @@ -202,27 +202,27 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) } } } - + for(j = 0; j < k; j++) { if(rsCodeWords[j] != 0) { rsCodeWords[j] = 929 - rsCodeWords[j]; } } - + for(i = k - 1; i >= 0; i--) { codeWords[cwCnt] = rsCodeWords[i]; cwCnt++; } - + /* Place data into table */ LeftRAPStart = aRAPTable[variant]; CentreRAPStart = aRAPTable[variant + 17]; RightRAPStart = aRAPTable[variant + 34]; StartCluster = aRAPTable[variant + 51] / 3; - + LeftRAP = LeftRAPStart; CentreRAP = CentreRAPStart; RightRAP = RightRAPStart; Cluster = StartCluster; /* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */ - + for(i = 0; i < rows; i++) { strcpy(codebarre, ""); offset = 929 * Cluster; @@ -260,9 +260,9 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) } concat(codebarre, RAPLR[RightRAP]); concat(codebarre, "1"); /* stop */ - + /* Now codebarre is a mixture of letters and numbers */ - + writer = 0; flip = 1; strcpy(pattern, ""); @@ -288,20 +288,20 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) } } symbol->width = writer; - + /* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ for(loop = 0; loop < strlen(pattern); loop++) { if(pattern[loop] == '1') { set_module(symbol, i, loop); } } symbol->row_height[i] = 2; symbol->rows++; - + /* Set up RAPs and Cluster for next row */ LeftRAP++; CentreRAP++; RightRAP++; Cluster++; - + if(LeftRAP == 53) { LeftRAP = 1; } @@ -315,7 +315,7 @@ int cc_a(struct zint_symbol *symbol, char source[], int cc_width) Cluster = 0; } } - + return 0; } @@ -333,12 +333,12 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) char codebarre[100], pattern[580]; int variant, LeftRAPStart, CentreRAPStart, RightRAPStart, StartCluster; int LeftRAP, CentreRAP, RightRAP, Cluster, writer, flip, loop; - + length = strlen(source) / 8; - + for(i = 0; i < length; i++) { binloc = i * 8; - + data_string[i] = 0; if(source[binloc] == '1') { data_string[i] += 0x80; } if(source[binloc + 1] == '1') { data_string[i] += 0x40; } @@ -349,20 +349,20 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) if(source[binloc + 6] == '1') { data_string[i] += 0x02; } if(source[binloc + 7] == '1') { data_string[i] += 0x01; } } - - + + mclength = 0; - + /* "the CC-B component shall have codeword 920 in the first symbol character position" (section 9a) */ chainemc[mclength] = 920; mclength++; - + byteprocess(chainemc, &mclength, data_string, 0, length, 0); - + /* Now figure out which variant of the symbol to use and load values accordingly */ - + variant = 0; - + if(cc_width == 2) { variant = 13; if(mclength <= 33) { variant = 12; } @@ -408,14 +408,14 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) longueur = (symbol->option_2 * symbol->rows) - k; /* number of non-EC CWs */ i = longueur - mclength; /* amount of padding required */ offset = MicroVariants[variant + 102]; /* coefficient offset */ - + /* We add the padding */ while (i > 0) { chainemc[mclength] = 900; mclength++; i--; } - + /* Reed-Solomon error correction */ longueur = mclength; for(loop = 0; loop < 50; loop++) { @@ -432,7 +432,7 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) } } } - + for(j = 0; j < k; j++) { if(mccorrection[j] != 0) { mccorrection[j] = 929 - mccorrection[j]; } } @@ -441,20 +441,20 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) chainemc[mclength] = mccorrection[i]; mclength++; } - + /* Now get the RAP (Row Address Pattern) start values */ LeftRAPStart = RAPTable[variant]; CentreRAPStart = RAPTable[variant + 34]; RightRAPStart = RAPTable[variant + 68]; StartCluster = RAPTable[variant + 102] / 3; - + /* That's all values loaded, get on with the encoding */ - + LeftRAP = LeftRAPStart; CentreRAP = CentreRAPStart; RightRAP = RightRAPStart; Cluster = StartCluster; /* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */ - + for(i = 0; i < symbol->rows; i++) { strcpy(codebarre, ""); offset = 929 * Cluster; @@ -492,9 +492,9 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) } concat(codebarre, RAPLR[RightRAP]); concat(codebarre, "1"); /* stop */ - + /* Now codebarre is a mixture of letters and numbers */ - + writer = 0; flip = 1; strcpy(pattern, ""); @@ -520,19 +520,19 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) } } symbol->width = writer; - + /* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ for(loop = 0; loop < strlen(pattern); loop++) { if(pattern[loop] == '1') { set_module(symbol, i, loop); } } symbol->row_height[i] = 2; - + /* Set up RAPs and Cluster for next row */ LeftRAP++; CentreRAP++; RightRAP++; Cluster++; - + if(LeftRAP == 53) { LeftRAP = 1; } @@ -546,7 +546,7 @@ int cc_b(struct zint_symbol *symbol, char source[], int cc_width) Cluster = 0; } } - + return 0; } @@ -562,12 +562,12 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) int offset, longueur, loop, total, j, mccorrection[520]; int c1, c2, c3, dummy[35]; char codebarre[100], pattern[580]; - + length = strlen(source) / 8; - + for(i = 0; i < length; i++) { binloc = i * 8; - + data_string[i] = 0; if(source[binloc] == '1') { data_string[i] += 0x80; } if(source[binloc + 1] == '1') { data_string[i] += 0x40; } @@ -578,24 +578,24 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) if(source[binloc + 6] == '1') { data_string[i] += 0x02; } if(source[binloc + 7] == '1') { data_string[i] += 0x01; } } - + mclength = 0; - + chainemc[mclength] = 0; /* space for length descriptor */ mclength++; chainemc[mclength] = 920; /* CC-C identifier */ mclength++; - + byteprocess(chainemc, &mclength, data_string, 0, length, 0); - + chainemc[0] = mclength; - + k = 1; for(i = 1; i <= (ecc_level + 1); i++) { k *= 2; } - + /* 796 - we now take care of the Reed Solomon codes */ switch(ecc_level) { case 1: offset = 2; break; @@ -624,7 +624,7 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) } } } - + for(j = 0; j < k; j++) { if(mccorrection[j] != 0) { mccorrection[j] = 929 - mccorrection[j]; } } @@ -633,12 +633,12 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) chainemc[mclength] = mccorrection[i]; mclength++; } - + /* 818 - The CW string is finished */ c1 = (mclength / cc_width - 1) / 3; c2 = ecc_level * 3 + (mclength / cc_width - 1) % 3; c3 = cc_width - 1; - + /* we now encode each row */ for(i = 0; i <= (mclength / cc_width) - 1; i++) { for(j = 0; j < cc_width ; j++) { @@ -677,7 +677,7 @@ int cc_c(struct zint_symbol *symbol, char source[], int cc_width, int ecc_level) concat(codebarre, "*"); } concat(codebarre, "-"); - + strcpy(pattern, ""); for(loop = 0; loop < strlen(codebarre); loop++) { lookup(BRSET, PDFttf, codebarre[loop], pattern); @@ -707,7 +707,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar char* general_field_type = (char*)_alloca(strlen(source) + 1); #endif int target_bitsize; - + encoding_method = 1; read_posn = 0; ai_crop = 0; @@ -722,7 +722,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar /* Source starts (10), (11) or (17) */ encoding_method = 2; } - + if((source[0] == '9') && (source[1] == '0')) { /* Source starts (90) */ encoding_method = 3; @@ -731,12 +731,12 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar if(encoding_method == 1) { concat(binary_string, "0"); } - + if(encoding_method == 2) { /* Encoding Method field "10" - date and lot number */ - + concat(binary_string, "10"); - + if(source[1] == '0') { /* No date data */ concat(binary_string, "11"); @@ -747,15 +747,15 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar date_str[1] = source[3]; date_str[2] = '\0'; group_val = atoi(date_str) * 384; - + date_str[0] = source[4]; date_str[1] = source[5]; group_val += (atoi(date_str) - 1) * 32; - + date_str[0] = source[6]; date_str[1] = source[7]; group_val += atoi(date_str); - + mask = 0x8000; for(j = 0; j < 16; j++) { if((group_val & mask) == 0x00) { @@ -765,7 +765,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } mask = mask >> 1; } - + if(source[1] == '1') { /* Production Date AI 11 */ concat(binary_string, "0"); @@ -775,7 +775,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } read_posn = 8; } - + if((source[read_posn] == '1') && (source[read_posn + 1] == '0')) { /* Followed by AI 10 - strip this from general field */ read_posn += 2; @@ -795,37 +795,37 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar char numeric_part[4]; int alpha, alphanum, numeric, test1, test2, test3, next_ai_posn; int numeric_value, table3_letter, mask; - + /* "This encodation method may be used if an element string with an AI 90 occurs at the start of the data message, and if the data field following the two-digit AI 90 starts with an alphanumeric string which complies with a specific format." (para 5.2.2) */ - + i = 0; do { ninety[i] = source[i + 2]; i++; } while ((strlen(source) > i + 2) && ('[' != source[i + 2])); ninety[i] = '\0'; - + /* Find out if the AI 90 data is alphabetic or numeric or both */ - + alpha = 0; alphanum = 0; numeric = 0; - + for(i = 0; i < strlen(ninety); i++) { - + if ((ninety[i] >= 'A') && (ninety[i] <= 'Z')) { /* Character is alphabetic */ alpha += 1; } - + if ((ninety[i] >= '0') && (ninety[i] <= '9')) { /* Character is numeric */ numeric += 1; } - + switch(ninety[i]) { case '*': case ',': @@ -833,7 +833,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar case '.': case '/': alphanum += 1; break; } - + if (!(((ninety[i] >= '0') && (ninety[i] <= '9')) || ((ninety[i] >= 'A') && (ninety[i] <= 'Z')))) { if((ninety[i] != '*') && (ninety[i] != ',') && (ninety[i] != '-') && (ninety[i] != '.') && (ninety[i] != '/')) { /* An Invalid AI 90 character */ @@ -842,7 +842,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } } } - + /* must start with 0, 1, 2 or 3 digits followed by an uppercase character */ test1 = -1; for(i = 3; i >= 0; i--) { @@ -850,28 +850,28 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar test1 = i; } } - + test2 = 0; for(i = 0; i < test1; i++) { if (!((ninety[i] >= '0') && (ninety[i] <= '9'))) { test2 = 1; } } - + /* leading zeros are not permitted */ test3 = 0; if((test1 >= 1) && (ninety[0] == '0')) { test3 = 1; } - + if((test1 != -1) && (test2 != 1) && (test3 == 0)) { /* Encodation method "11" can be used */ concat(binary_string, "11"); - + numeric -= test1; alpha --; - + /* Decide on numeric, alpha or alphanumeric mode */ /* Alpha mode is a special mode for AI 90 */ - + if(alphanum > 0) { /* Alphanumeric mode */ concat(binary_string, "0"); @@ -889,20 +889,20 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } next_ai_posn = 2 + strlen(ninety); - + if(source[next_ai_posn] == '[') { /* There are more AIs afterwords */ if((source[next_ai_posn + 1] == '2') && (source[next_ai_posn + 2] == '1')) { /* AI 21 follows */ ai_crop = 1; } - + if((source[next_ai_posn + 1] == '8') && (source[next_ai_posn + 2] == '0') && (source[next_ai_posn + 3] == '0') && (source[next_ai_posn + 4] == '4')) { /* AI 8004 follows */ ai_crop = 2; } } - + switch(ai_crop) { case 0: concat(binary_string, "0"); break; case 1: concat(binary_string, "10"); break; @@ -917,9 +917,9 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } numeric_part[i] = '\0'; } - + numeric_value = atoi(numeric_part); - + table3_letter = -1; if(numeric_value < 31) { switch(ninety[test1]) { @@ -941,7 +941,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar case 'Z': table3_letter = 15; break; } } - + if(table3_letter != -1) { /* Encoding can be done according to 5.2.2 c) 2) */ /* five bit binary string representing value before letter */ @@ -998,7 +998,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar read_posn = 0; } } - + /* Now encode the rest of the AI 90 data field */ if(ai90_mode == 2) { /* Alpha encodation (section 5.2.3) */ @@ -1014,7 +1014,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + if((source[read_posn] >= 'A') && (source[read_posn] <= 'Z')) { mask = 0x20; for(j = 0; j < 6; j++) { @@ -1026,16 +1026,16 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + if(source[read_posn] == '[') { concat(binary_string, "11111"); } - + read_posn++; } while ((source[read_posn - 1] != '[') && (source[read_posn - 1] != '\0')); alpha_pad = 1; /* This is overwritten if a general field is encoded */ } - + if(ai90_mode == 1) { /* Alphanumeric mode */ do { @@ -1050,7 +1050,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + if((source[read_posn] >= 'A') && (source[read_posn] <= 'Z')) { mask = 0x20; for(j = 0; j < 6; j++) { @@ -1062,7 +1062,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + switch(source[read_posn]) { case '[': concat(binary_string, "01111"); break; case '*': concat(binary_string, "111010"); break; @@ -1071,16 +1071,16 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar case '.': concat(binary_string, "111101"); break; case '/': concat(binary_string, "111110"); break; } - + read_posn++; } while ((source[read_posn - 1] != '[') && (source[read_posn - 1] != '\0')); } read_posn += (2 * ai_crop); - + /* The compressed data field has been processed if appropriate - the rest of the data (if any) goes into a general-purpose data compaction field */ - + j = 0; if(fnc1_latch == 1) { /* Encodation method "10" has been used but it is not followed by @@ -1088,7 +1088,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar general_field[j] = '['; j++; } - + for(i = read_posn; i < strlen(source); i++) { general_field[j] = source[i]; j++; @@ -1096,7 +1096,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar general_field[j] = '\0'; if(strlen(general_field) != 0) { alpha_pad = 0; } - + latch = 0; for(i = 0; i < strlen(general_field); i++) { /* Table 13 - ISO/IEC 646 encodation */ @@ -1105,7 +1105,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } else { general_field_type[i] = ISOIEC; } - + if(general_field[i] == '#') { general_field_type[i] = INVALID_CHAR; latch = 1; } @@ -1155,9 +1155,9 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } } - + general_field_type[strlen(general_field)] = '\0'; - + if(latch == 1) { /* Invalid characters in input data */ strcpy(symbol->errtxt, "Invalid characters in input data"); @@ -1169,40 +1169,40 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar general_field_type[i + 1] = ISOIEC; } } - + for(i = 0; i < strlen(general_field); i++) { if((general_field_type[i] == ALPHA_OR_ISO) && (general_field[i + 1] == '[')) { general_field_type[i + 1] = ALPHA_OR_ISO; } } - + latch = general_rules(general_field, general_field_type); - + i = 0; do { switch(general_field_type[i]) { case NUMERIC: - + if(i != 0) { if((general_field_type[i - 1] != NUMERIC) && (general_field[i - 1] != '[')) { concat(binary_string, "000"); /* Numeric latch */ } } - + if(general_field[i] != '[') { d1 = ctoi(general_field[i]); } else { d1 = 10; } - + if(general_field[i + 1] != '[') { d2 = ctoi(general_field[i + 1]); } else { d2 = 10; } - + value = (11 * d1) + d2 + 8; - + mask = 0x40; for(j = 0; j < 7; j++) { if((value & mask) == 0x00) { @@ -1212,12 +1212,12 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } mask = mask >> 1; } - + i += 2; break; - + case ALPHA: - + if(i != 0) { if((general_field_type[i - 1] == NUMERIC) || (general_field[i - 1] == '[')) { concat(binary_string, "0000"); /* Alphanumeric latch */ @@ -1226,11 +1226,11 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar concat(binary_string, "00100"); /* ISO/IEC 646 latch */ } } - + if((general_field[i] >= '0') && (general_field[i] <= '9')) { - + value = general_field[i] - 43; - + mask = 0x10; for(j = 0; j < 5; j++) { if((value & mask) == 0x00) { @@ -1241,11 +1241,11 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + if((general_field[i] >= 'A') && (general_field[i] <= 'Z')) { - + value = general_field[i] - 33; - + mask = 0x20; for(j = 0; j < 6; j++) { if((value & mask) == 0x00) { @@ -1256,19 +1256,19 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + if(general_field[i] == '[') concat(binary_string, "01111"); /* FNC1/Numeric latch */ if(general_field[i] == '*') concat(binary_string, "111010"); /* asterisk */ if(general_field[i] == ',') concat(binary_string, "111011"); /* comma */ if(general_field[i] == '-') concat(binary_string, "111100"); /* minus or hyphen */ if(general_field[i] == '.') concat(binary_string, "111101"); /* period or full stop */ if(general_field[i] == '/') concat(binary_string, "111110"); /* slash or solidus */ - + i++; break; - + case ISOIEC: - + if(i != 0) { if((general_field_type[i - 1] == NUMERIC) || (general_field[i - 1] == '[')) { concat(binary_string, "0000"); /* Alphanumeric latch */ @@ -1278,11 +1278,11 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar concat(binary_string, "00100"); /* ISO/IEC 646 latch */ } } - + if((general_field[i] >= '0') && (general_field[i] <= '9')) { - + value = general_field[i] - 43; - + mask = 0x10; for(j = 0; j < 5; j++) { if((value & mask) == 0x00) { @@ -1293,11 +1293,11 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + if((general_field[i] >= 'A') && (general_field[i] <= 'Z')) { - + value = general_field[i] - 1; - + mask = 0x40; for(j = 0; j < 7; j++) { if((value & mask) == 0x00) { @@ -1308,11 +1308,11 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + if((general_field[i] >= 'a') && (general_field[i] <= 'z')) { - + value = general_field[i] - 7; - + mask = 0x40; for(j = 0; j < 7; j++) { if((value & mask) == 0x00) { @@ -1323,7 +1323,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar mask = mask >> 1; } } - + if(general_field[i] == '[') concat(binary_string, "01111"); /* FNC1/Numeric latch */ if(general_field[i] == '!') concat(binary_string, "11101000"); /* exclamation mark */ if(general_field[i] == 34) concat(binary_string, "11101001"); /* quotation mark */ @@ -1346,7 +1346,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar if(general_field[i] == '?') concat(binary_string, "11111010"); /* question mark */ if(general_field[i] == '_') concat(binary_string, "11111011"); /* underline or low line */ if(general_field[i] == ' ') concat(binary_string, "11111100"); /* space */ - + i++; break; } @@ -1384,7 +1384,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar break; } } - + if(cc_mode == 2) { /* CC-B 2D component - calculated from ISO/IEC 24728 Table 1 */ switch(*(cc_width)) { @@ -1427,18 +1427,18 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar break; } } - + if (cc_mode == 3) { /* CC-C 2D Component is a bit more complex! */ int byte_length, codewords_used, ecc_level, ecc_codewords, rows; int codewords_total, target_codewords, target_bytesize; - + byte_length = binary_length / 8; if(binary_length % 8 != 0) { byte_length++; } - + codewords_used = (byte_length / 6) * 5; codewords_used += byte_length % 6; - + ecc_level = 7; if(codewords_used <= 1280) { ecc_level = 6; } if(codewords_used <= 640) { ecc_level = 5; } @@ -1450,10 +1450,10 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar for(i = 1; i <= (ecc_level + 1); i++){ ecc_codewords *= 2; } - + codewords_used += ecc_codewords; codewords_used += 3; - + if(codewords_used > symbol->option_3) { return ERROR_TOO_LONG; } @@ -1463,33 +1463,33 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar /* stop the symbol from becoming too high */ *(cc_width) = *(cc_width) + 1; } - + rows = codewords_used / *(cc_width); if(codewords_used % *(cc_width) != 0) { rows++; } - + codewords_total = *(cc_width) * rows; - + target_codewords = codewords_total - ecc_codewords; target_codewords -= 3; - + target_bytesize = 6 * (target_codewords / 5); target_bytesize += target_codewords % 5; - + target_bitsize = 8 * target_bytesize; } - + remainder = binary_length - target_bitsize; - + if(latch == 1) { i = 0; /* There is still one more numeric digit to encode */ - + if((remainder >= 4) && (remainder <= 6)) { d1 = ctoi(general_field[i]); d1++; - + mask = 0x08; for(j = 0; j < 4; j++) { if((value & mask) == 0x00) { @@ -1502,9 +1502,9 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar } else { d1 = ctoi(general_field[i]); d2 = 10; - + value = (11 * d1) + d2 + 8; - + mask = 0x40; for(j = 0; j < 7; j++) { if((value & mask) == 0x00) { @@ -1517,15 +1517,15 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar /* This may push the symbol up to the next size */ } } - + if(strlen(binary_string) > 11805) { /* (2361 * 5) */ strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + /* all the code below is repeated from above - it needs to be calculated again because the size of the symbol may have changed when adding data in the above sequence */ - + binary_length = strlen(binary_string); if(cc_mode == 1) { /* CC-A 2D component - calculate padding required */ @@ -1558,7 +1558,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar break; } } - + if(cc_mode == 2) { /* CC-B 2D component */ switch(*(cc_width)) { @@ -1601,18 +1601,18 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar break; } } - + if (cc_mode == 3) { /* CC-C 2D Component is a bit more complex! */ int byte_length, codewords_used, ecc_level, ecc_codewords, rows; int codewords_total, target_codewords, target_bytesize; - + byte_length = binary_length / 8; if(binary_length % 8 != 0) { byte_length++; } - + codewords_used = (byte_length / 6) * 5; codewords_used += byte_length % 6; - + ecc_level = 7; if(codewords_used <= 1280) { ecc_level = 6; } if(codewords_used <= 640) { ecc_level = 5; } @@ -1624,10 +1624,10 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar for(i = 1; i <= (ecc_level + 1); i++){ ecc_codewords *= 2; } - + codewords_used += ecc_codewords; codewords_used += 3; - + if(codewords_used > symbol->option_3) { return ERROR_TOO_LONG; } @@ -1637,23 +1637,23 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar /* stop the symbol from becoming too high */ *(cc_width) = *(cc_width) + 1; } - + rows = codewords_used / *(cc_width); if(codewords_used % *(cc_width) != 0) { rows++; } - + codewords_total = *(cc_width) * rows; - + target_codewords = codewords_total - ecc_codewords; target_codewords -= 3; - + target_bytesize = 6 * (target_codewords / 5); target_bytesize += target_codewords % 5; - + target_bitsize = 8 * target_bytesize; } - + if(binary_length < target_bitsize) { /* Now add padding to binary string */ if (alpha_pad == 1) { @@ -1661,7 +1661,7 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar alpha_pad = 0; /* Extra FNC1 character required after Alpha encodation (section 5.2.3) */ } - + if ((strlen(general_field) != 0) && (general_field_type[strlen(general_field) - 1] == NUMERIC)) { concat(binary_string, "0000"); } @@ -1669,12 +1669,12 @@ int cc_binary_string(struct zint_symbol *symbol, const char source[], char binar while (strlen(binary_string) < target_bitsize) { concat(binary_string, "00100"); } - + if(strlen(binary_string) > target_bitsize) { binary_string[target_bitsize] = '\0'; } } - + return 0; } @@ -1682,7 +1682,7 @@ void add_leading_zeroes(struct zint_symbol *symbol) { int with_addon = 0; int first_len = 0, second_len = 0, zfirst_len = 0, zsecond_len = 0, i, h, n = 0; - + h = strlen(symbol->primary); for(i = 0; i < h; i++) { if(symbol->primary[i] == '+') { @@ -1695,14 +1695,14 @@ void add_leading_zeroes(struct zint_symbol *symbol) } } } - + /* Calculate target lengths */ if(first_len <= 12) { zfirst_len = 12; } if(first_len <= 7) { zfirst_len = 7; } if(second_len <= 5) { zsecond_len = 5; } if(second_len <= 2) { zsecond_len = 2; } if(second_len == 0) { zsecond_len = 0; } - + /* Add leading zeroes */ n = zfirst_len - first_len; if (n > 0) @@ -1748,22 +1748,22 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "2D component input data too long"); return ERROR_TOO_LONG; } - + linear = ZBarcode_Create(); /* Symbol contains the 2D component and Linear contains the rest */ - + error_number = gs1_verify(symbol, source, length, reduced); if(error_number != 0) { return error_number; } - + cc_mode = symbol->option_1; - + if((cc_mode == 3) && (symbol->symbology != BARCODE_EAN128_CC)) { /* CC-C can only be used with a GS1-128 linear part */ strcpy(symbol->errtxt, "Invalid mode (CC-C only valid with GS1-128 linear component)"); return ERROR_INVALID_OPTION; } - + linear->symbology = symbol->symbology; - + if(linear->symbology != BARCODE_EAN128_CC) { /* Set the "component linkage" flag in the linear component */ linear->option_1 = 2; @@ -1771,7 +1771,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) /* GS1-128 needs to know which type of 2D component is used */ linear->option_1 = cc_mode; } - + switch(symbol->symbology) { case BARCODE_EANX_CC: error_number = eanx(linear, (unsigned char *)symbol->primary, pri_len); break; case BARCODE_EAN128_CC: error_number = ean_128(linear, (unsigned char *)symbol->primary, pri_len); break; @@ -1817,9 +1817,9 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) case BARCODE_RSS14_OMNI_CC: cc_width = 2; break; case BARCODE_RSS_EXPSTACK_CC: cc_width = 4; break; } - + memset(binary_string, 0, bs); - + if(cc_mode < 1 || cc_mode > 3) { cc_mode = 1; } if(cc_mode == 1) { @@ -1828,7 +1828,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) cc_mode = 2; } } - + if(cc_mode == 2) { /* If the data didn't fit into CC-A it is recalculated for CC-B */ i = cc_binary_string(symbol, reduced, binary_string, cc_mode, &cc_width, &ecc_level, linear->width); if (i == ERROR_TOO_LONG) { @@ -1839,7 +1839,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) } } } - + if(cc_mode == 3) { /* If the data didn't fit in CC-B (and linear part is GS1-128) it is recalculated for CC-C */ i = cc_binary_string(symbol, reduced, binary_string, cc_mode, &cc_width, &ecc_level, linear->width); @@ -1857,12 +1857,12 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) if(error_number != 0) { return ERROR_ENCODING_PROBLEM; } - + /* Merge the linear component with the 2D component */ - + top_shift = 0; bottom_shift = 0; - + switch(symbol->symbology) { /* Determine horizontal alignment (according to section 12.3) */ case BARCODE_EANX_CC: @@ -1915,7 +1915,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) unset_module(symbol, i, j); } } - } + } /* Merge linear and 2D components into one structure */ for(i = 0; i <= linear->rows; i++) { @@ -1932,7 +1932,7 @@ int composite(struct zint_symbol *symbol, unsigned char source[], int length) } symbol->rows += linear->rows; ustrcpy(symbol->text, (unsigned char *)linear->text); - + ZBarcode_Delete(linear); return error_number; diff --git a/backend/dmatrix.c b/backend/dmatrix.c index 0592e4c8..686c695c 100644 --- a/backend/dmatrix.c +++ b/backend/dmatrix.c @@ -201,14 +201,14 @@ int isx12(unsigned char source) if(source == 32) { return 1; } if((source >= '0') && (source <= '9')) { return 1; } if((source >= 'A') && (source <= 'Z')) { return 1; } - + return 0; } void dminsert(char binary_string[], int posn, char newbit) { /* Insert a character into the middle of a string at position posn */ int i, end; - + end = strlen(binary_string); for(i = end; i > posn; i--) { binary_string[i] = binary_string[i - 1]; @@ -219,7 +219,7 @@ void dminsert(char binary_string[], int posn, char newbit) void insert_value(unsigned char binary_stream[], int posn, int streamlen, char newbit) { int i; - + for(i = streamlen; i > posn; i--) { binary_stream[i] = binary_stream[i - 1]; } @@ -230,11 +230,11 @@ int look_ahead_test(unsigned char source[], int sourcelen, int position, int cur { /* A custom version of the 'look ahead test' from Annex P */ /* This version is deliberately very reluctant to end a data stream with EDIFACT encoding */ - + float ascii_count, c40_count, text_count, x12_count, edf_count, b256_count, best_count; int sp, done, best_scheme; char reduced_char; - + /* step (j) */ if(current_mode == DM_ASCII) { ascii_count = 0.0; @@ -251,7 +251,7 @@ int look_ahead_test(unsigned char source[], int sourcelen, int position, int cur edf_count = 2.0; b256_count = 2.25; } - + switch(current_mode) { case DM_C40: c40_count = 0.0; break; case DM_TEXT: text_count = 0.0; break; @@ -259,71 +259,71 @@ int look_ahead_test(unsigned char source[], int sourcelen, int position, int cur case DM_EDIFACT: edf_count = 0.0; break; case DM_BASE256: b256_count = 0.0; break; } - + for(sp = position; (sp < sourcelen) && (sp <= (position + 8)); sp++) { - + if(source[sp] <= 127) { reduced_char = source[sp]; } else { reduced_char = source[sp] - 127; } - + if((source[sp] >= '0') && (source[sp] <= '9')) { ascii_count += 0.5; } else { ascii_count += 1.0; } if(source[sp] > 127) { ascii_count += 1.0; } - + done = 0; if(reduced_char == ' ') { c40_count += (2.0 / 3.0); done = 1; } if((reduced_char >= '0') && (reduced_char <= '9')) { c40_count += (2.0 / 3.0); done = 1; } if((reduced_char >= 'A') && (reduced_char <= 'Z')) { c40_count += (2.0 / 3.0); done = 1; } if(source[sp] > 127) { c40_count += (4.0 / 3.0); } if(done == 0) { c40_count += (4.0 / 3.0); } - + done = 0; if(reduced_char == ' ') { text_count += (2.0 / 3.0); done = 1; } if((reduced_char >= '0') && (reduced_char <= '9')) { text_count += (2.0 / 3.0); done = 1; } if((reduced_char >= 'a') && (reduced_char <= 'z')) { text_count += (2.0 / 3.0); done = 1; } if(source[sp] > 127) { text_count += (4.0 / 3.0); } if(done == 0) { text_count += (4.0 / 3.0); } - + if(isx12(source[sp])) { x12_count += (2.0 / 3.0); } else { x12_count += 4.0; } - + /* step (p) */ done = 0; if((source[sp] >= ' ') && (source[sp] <= '^')) { edf_count += (3.0 / 4.0); } else { edf_count += 6.0; } if(gs1 && (source[sp] == '[')) { edf_count += 6.0; } if(sp >= (sourcelen - 5)) { edf_count += 6.0; } /* MMmmm fudge! */ - + /* step (q) */ if(gs1 && (source[sp] == '[')) { b256_count += 4.0; } else { b256_count += 1.0; } - + /* printf("%c lat a%.2f c%.2f t%.2f x%.2f e%.2f b%.2f\n", source[sp], ascii_count, c40_count, text_count, x12_count, edf_count, b256_count); */ - + } best_count = ascii_count; best_scheme = DM_ASCII; - + if(b256_count <= best_count) { best_count = b256_count; best_scheme = DM_BASE256; } - + if(edf_count <= best_count) { best_count = edf_count; best_scheme = DM_EDIFACT; } - + if(text_count <= best_count) { best_count = text_count; best_scheme = DM_TEXT; } - + if(x12_count <= best_count) { best_count = x12_count; best_scheme = DM_X12; } - + if(c40_count <= best_count) { best_count = c40_count; best_scheme = DM_C40; } - + return best_scheme; } @@ -331,7 +331,7 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha { /* Encodes data using ASCII, C40, Text, X12, EDIFACT or Base 256 modes as appropriate */ /* Supports encoding FNC1 in supporting systems */ - + int sp, tp, i, gs1; int current_mode, next_mode; int inputlen = length; @@ -357,19 +357,19 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha memset(edifact_buffer, 0, 8); edifact_p = 0; strcpy(binary, ""); - + /* step (a) */ current_mode = DM_ASCII; next_mode = DM_ASCII; - + if(symbol->input_mode == GS1_MODE) { gs1 = 1; } else { gs1 = 0; } - + if(gs1) { target[tp] = 232; tp++; concat(binary, " "); if(debug) printf("FN1 "); } /* FNC1 */ - + if(symbol->output_options & READER_INIT) { if(gs1) { strcpy(symbol->errtxt, "Cannot encode in GS1 mode and Reader Initialisation at the same time"); @@ -380,15 +380,15 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha if(debug) printf("RP "); } } - + while (sp < inputlen) { - + current_mode = next_mode; - + /* step (b) - ASCII encodation */ if(current_mode == DM_ASCII) { next_mode = DM_ASCII; - + if(istwodigits(source, sp) && ((sp + 1) != inputlen)) { target[tp] = (10 * ctoi(source[sp])) + ctoi(source[sp + 1]) + 130; if(debug) printf("N%d ", target[tp] - 130); @@ -396,7 +396,7 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha sp += 2; } else { next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); - + if(next_mode != DM_ASCII) { switch(next_mode) { case DM_C40: target[tp] = 230; tp++; concat(binary, " "); @@ -432,18 +432,18 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha sp++; } } - + } - + /* step (c) C40 encodation */ if(current_mode == DM_C40) { int shift_set, value; - + next_mode = DM_C40; if(c40_p == 0) { next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); } - + if(next_mode != DM_C40) { target[tp] = 254; tp++; concat(binary, " ");/* Unlatch */ next_mode = DM_ASCII; @@ -458,26 +458,26 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha shift_set = c40_shift[source[sp]]; value = c40_value[source[sp]]; } - + if(gs1 && (source[sp] == '[')) { shift_set = 2; value = 27; /* FNC1 */ } - + if(shift_set != 0) { c40_buffer[c40_p] = shift_set - 1; c40_p++; } c40_buffer[c40_p] = value; c40_p++; - + if(c40_p >= 3) { int iv; - + iv = (1600 * c40_buffer[0]) + (40 * c40_buffer[1]) + (c40_buffer[2]) + 1; target[tp] = iv / 256; tp++; target[tp] = iv % 256; tp++; concat(binary, " "); if (debug) printf("[%d %d %d] ", c40_buffer[0], c40_buffer[1], c40_buffer[2]); - + c40_buffer[0] = c40_buffer[3]; c40_buffer[1] = c40_buffer[4]; c40_buffer[2] = c40_buffer[5]; @@ -489,16 +489,16 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha sp++; } } - + /* step (d) Text encodation */ if(current_mode == DM_TEXT) { int shift_set, value; - + next_mode = DM_TEXT; if(text_p == 0) { next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); } - + if(next_mode != DM_TEXT) { target[tp] = 254; tp++; concat(binary, " ");/* Unlatch */ next_mode = DM_ASCII; @@ -513,26 +513,26 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha shift_set = text_shift[source[sp]]; value = text_value[source[sp]]; } - + if(gs1 && (source[sp] == '[')) { shift_set = 2; value = 27; /* FNC1 */ } - + if(shift_set != 0) { text_buffer[text_p] = shift_set - 1; text_p++; } text_buffer[text_p] = value; text_p++; - + if(text_p >= 3) { int iv; - + iv = (1600 * text_buffer[0]) + (40 * text_buffer[1]) + (text_buffer[2]) + 1; target[tp] = iv / 256; tp++; target[tp] = iv % 256; tp++; concat(binary, " "); if (debug) printf("[%d %d %d] ", text_buffer[0], text_buffer[1], text_buffer[2]); - + text_buffer[0] = text_buffer[3]; text_buffer[1] = text_buffer[4]; text_buffer[2] = text_buffer[5]; @@ -544,16 +544,16 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha sp++; } } - + /* step (e) X12 encodation */ if(current_mode == DM_X12) { int value = 0; - + next_mode = DM_X12; if(text_p == 0) { next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); } - + if(next_mode != DM_X12) { target[tp] = 254; tp++; concat(binary, " ");/* Unlatch */ next_mode = DM_ASCII; @@ -565,18 +565,18 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha if(source[sp] == ' ') { value = 3; } if((source[sp] >= '0') && (source[sp] <= '9')) { value = (source[sp] - '0') + 4; } if((source[sp] >= 'A') && (source[sp] <= 'Z')) { value = (source[sp] - 'A') + 14; } - + x12_buffer[x12_p] = value; x12_p++; - + if(x12_p >= 3) { int iv; - + iv = (1600 * x12_buffer[0]) + (40 * x12_buffer[1]) + (x12_buffer[2]) + 1; target[tp] = iv / 256; tp++; target[tp] = iv % 256; tp++; concat(binary, " "); if (debug) printf("[%d %d %d] ", x12_buffer[0], x12_buffer[1], x12_buffer[2]); - + x12_buffer[0] = x12_buffer[3]; x12_buffer[1] = x12_buffer[4]; x12_buffer[2] = x12_buffer[5]; @@ -588,34 +588,34 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha sp++; } } - + /* step (f) EDIFACT encodation */ if(current_mode == DM_EDIFACT) { int value = 0; - + next_mode = DM_EDIFACT; if(edifact_p == 3) { next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); } - + if(next_mode != DM_EDIFACT) { edifact_buffer[edifact_p] = 31; edifact_p++; next_mode = DM_ASCII; } else { if((source[sp] >= '@') && (source[sp] <= '^')) { value = source[sp] - '@'; } if((source[sp] >= ' ') && (source[sp] <= '?')) { value = source[sp]; } - + edifact_buffer[edifact_p] = value; edifact_p++; sp++; } - + if(edifact_p >= 4) { target[tp] = (edifact_buffer[0] << 2) + ((edifact_buffer[1] & 0x30) >> 4); tp++; target[tp] = ((edifact_buffer[1] & 0x0f) << 4) + ((edifact_buffer[2] & 0x3c) >> 2); tp++; target[tp] = ((edifact_buffer[2] & 0x03) << 6) + edifact_buffer[3]; tp++; concat(binary, " "); if (debug) printf("[%d %d %d %d] ", edifact_buffer[0], edifact_buffer[1], edifact_buffer[2], edifact_buffer[3]); - + edifact_buffer[0] = edifact_buffer[4]; edifact_buffer[1] = edifact_buffer[5]; edifact_buffer[2] = edifact_buffer[6]; @@ -627,11 +627,11 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha edifact_p -= 4; } } - + /* step (g) Base 256 encodation */ if(current_mode == DM_BASE256) { next_mode = look_ahead_test(source, inputlen, sp, current_mode, gs1); - + if(next_mode == DM_BASE256) { target[tp] = source[sp]; if(debug) printf("B%02X ", target[tp]); @@ -643,13 +643,13 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha if(debug) printf("ASC "); } } - + if(tp > 1558) { return 0; } - + } /* while */ - + /* Empty buffers */ if(c40_p == 2) { target[tp] = 254; tp++; /* unlatch */ @@ -666,7 +666,7 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha if(debug) printf("ASC A%02X ", target[tp - 1] - 1); current_mode = DM_ASCII; } - + if(text_p == 2) { target[tp] = 254; tp++; /* unlatch */ target[tp] = source[inputlen - 2] + 1; tp++; @@ -682,7 +682,7 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha if(debug) printf("ASC A%02X ", target[tp - 1] - 1); current_mode = DM_ASCII; } - + if(x12_p == 2) { target[tp] = 254; tp++; /* unlatch */ target[tp] = source[inputlen - 2] + 1; tp++; @@ -706,9 +706,9 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha if((i == 0) || ((i != 0) && (binary[i - 1] != 'b'))) { /* start of binary data */ int binary_count; /* length of b256 data */ - + for(binary_count = 0; binary[binary_count + i] == 'b'; binary_count++); - + if(binary_count <= 249) { dminsert(binary, i, 'b'); insert_value(target, i, tp, binary_count); tp++; @@ -722,17 +722,17 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha } i++; } - + for(i = 0; i < tp; i++) { if(binary[i] == 'b') { int prn, temp; - + prn = ((149 * (i + 1)) % 255) + 1; temp = target[i] + prn; if (temp <= 255) { target[i] = temp; } else { target[i] = temp - 256; } } } - + if(debug) { printf("\n\n"); for(i = 0; i < tp; i++){ @@ -740,7 +740,7 @@ int dm200encode(struct zint_symbol *symbol, unsigned char source[], unsigned cha } printf("\n"); } - + *(last_mode) = current_mode; return tp; } @@ -749,7 +749,7 @@ void add_tail(unsigned char target[], int tp, int tail_length, int last_mode) { /* adds unlatch and pad bits */ int i, prn, temp; - + switch(last_mode) { case DM_C40: case DM_TEXT: @@ -757,7 +757,7 @@ void add_tail(unsigned char target[], int tp, int tail_length, int last_mode) target[tp] = 254; tp++; /* Unlatch */ tail_length--; } - + for(i = tail_length; i > 0; i--) { if(i == tail_length) { target[tp] = 129; tp++; /* Pad */ @@ -783,20 +783,20 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng int H, W, FH, FW, datablock, bytes, rsblock; int last_mode; unsigned char *grid = 0; - + binlen = dm200encode(symbol, source, binary, &last_mode, length); - + if(binlen == 0) { strcpy(symbol->errtxt, "Data too long to fit in symbol"); return ERROR_TOO_LONG; } - + if((symbol->option_2 >= 1) && (symbol->option_2 <= 30)) { optionsize = intsymbol[symbol->option_2 - 1]; } else { optionsize = -1; } - + calcsize = 29; for(i = 29; i > -1; i--) { if(matrixbytes[i] >= binlen) { @@ -816,7 +816,7 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng calcsize++; } } - + symbolsize = optionsize; if(calcsize > optionsize) { symbolsize = calcsize; @@ -826,7 +826,7 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng strcpy(symbol->errtxt, "Data does not fit in selected symbol size"); } } - + H = matrixH[symbolsize]; W = matrixW[symbolsize]; FH = matrixFH[symbolsize]; @@ -834,13 +834,13 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng bytes = matrixbytes[symbolsize]; datablock = matrixdatablock[symbolsize]; rsblock = matrixrsblock[symbolsize]; - + taillength = bytes - binlen; - + if(taillength != 0) { add_tail(binary, binlen, taillength, last_mode); } - + // ecc code if(symbolsize == 29) { skew = 1; } ecc200(binary, bytes, datablock, rsblock, skew); @@ -885,17 +885,17 @@ int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], int leng free(grid); free(places); } - + symbol->rows = H; symbol->width = W; - + return error_number; } int dmatrix(struct zint_symbol *symbol, unsigned char source[], int length) { int error_number; - + if(symbol->option_1 <= 1) { /* ECC 200 */ error_number = data_matrix_200(symbol, source, length); diff --git a/backend/dmatrix.h b/backend/dmatrix.h index 79d11434..22de33e7 100644 --- a/backend/dmatrix.h +++ b/backend/dmatrix.h @@ -3,20 +3,6 @@ /* libzint - the open source barcode library Copyright (C) 2009 Robin Stuart - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "common.h" @@ -43,58 +29,58 @@ extern int data_matrix_200(struct zint_symbol *symbol, unsigned char source[], i #define DM_EDIFACT 5 #define DM_BASE256 6 -static int c40_shift[] = { +static const int c40_shift[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; -static int c40_value[] = { +static const int c40_value[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, 15,16,17,18,19,20,21,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39, 22,23,24,25,26,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; -static int text_shift[] = { +static const int text_shift[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3 }; -static int text_value[] = { +static const int text_value[] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 3,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,4,5,6,7,8,9,10,11,12,13, 15,16,17,18,19,20,21,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26, 22,23,24,25,26,0,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,27,28,29,30,31 }; -static int intsymbol[] = { +static const int intsymbol[] = { 0,1,3,5,7,8,10,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,2,4,6,9,11,14 }; -static int matrixH[] = { +static const int matrixH[] = { 10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 32, 36, 40, 44, 48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144 }; -static int matrixW[] = { +static const int matrixW[] = { 10, 12, 18, 14, 32, 16, 26, 18, 20, 36, 22, 36, 24, 26, 48, 32, 36, 40, 44, 48, 52, 64, 72, 80, 88, 96, 104, 120, 132, 144 }; -static int matrixFH[] = { +static const int matrixFH[] = { 10, 12, 8, 14, 8, 16, 12, 18, 20, 12, 22, 16, 24, 26, 16, 16, 18, 20, 22, 24, 26, 16, 18, 20, 22, 24, 26, 20, 22, 24 }; -static int matrixFW[] = { +static const int matrixFW[] = { 10, 12, 18, 14, 16, 16, 26, 18, 20, 18, 22, 18, 24, 26, 24, 16, 18, 20, 22, 24, 26, 16, 18, 20, 22, 24, 26, 20, 22, 24 }; -static int matrixbytes[] = { +static const int matrixbytes[] = { 3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144, 174, 204, 280, 368, 456, 576, 696, 816, 1050, 1304, 1558 }; -static int matrixdatablock[] = { +static const int matrixdatablock[] = { 3, 5, 5, 8, 10, 12, 16, 18, 22, 22, 30, 32, 36, 44, 49, 62, 86, 114, 144, 174, 102, 140, 92, 114, 144, 174, 136, 175, 163, 156 }; -static int matrixrsblock[] = { +static const int matrixrsblock[] = { 5, 7, 7, 10, 11, 12, 14, 14, 18, 18, 20, 24, 24, 28, 28, 36, 42, 48, 56, 68, 42, 56, 36, 48, 56, 68, 56, 68, 62, 62 }; diff --git a/backend/font.h b/backend/font.h index 2c32b5e6..9bd15928 100644 --- a/backend/font.h +++ b/backend/font.h @@ -3,26 +3,12 @@ /* libzint - the open source barcode library Copyright (C) 2008 Robin Stuart - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* This file contains the pixel-by-pixel representation of the "Misc Fixed" font at 10 point size processed by the Gimp */ -static int ascii_font[9310] = { +static const int ascii_font[9310] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -613,7 +599,7 @@ static int ascii_font[9310] = { 0,0,0,0,0,0,0,0,0 }; -static int ascii_ext_font[9310] = { +static const int ascii_ext_font[9310] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -1204,7 +1190,7 @@ static int ascii_ext_font[9310] = { 0,0,1,1,0,0,0,0,0 }; -static int small_font[] = { +static const int small_font[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -1447,7 +1433,7 @@ static int small_font[] = { 0,0,0,0,0,0,0,0,0,0,0 }; -static int small_font_extended[] = { +static const int small_font_extended[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/backend/gb2312.h b/backend/gb2312.h index eca1c502..293f16d6 100644 --- a/backend/gb2312.h +++ b/backend/gb2312.h @@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -unsigned long int gb2312_lookup[] = { +static const unsigned long int gb2312_lookup[] = { 0x00A4, 0xA1E8, 0x00A7, 0xA1EC, 0x00A8, 0xA1A7, diff --git a/backend/gridmtx.c b/backend/gridmtx.c index ad377923..182df9c9 100644 --- a/backend/gridmtx.c +++ b/backend/gridmtx.c @@ -41,12 +41,12 @@ int number_lat(int gbdata[], int length, int position) int sp; int numb = 0, nonum = 0, done; int tally = 0; - + sp = position; - + do { done = 0; - + if((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) { numb++; done = 1; } switch(gbdata[sp]) { case ' ': @@ -64,7 +64,7 @@ int number_lat(int gbdata[], int length, int position) sp++; } } - + if(done == 0) { tally += 80; } else { @@ -82,14 +82,14 @@ int number_lat(int gbdata[], int length, int position) nonum = 0; } } - + sp++; } while ((sp < length) && (sp <= (position + 8))); if(numb == 0) { tally += 80; } - + if(numb > 1) { if(nonum == 0) { tally += 10; @@ -101,7 +101,7 @@ int number_lat(int gbdata[], int length, int position) tally += 80; } } - + return tally; } @@ -111,14 +111,14 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) code uses a look-ahead test in the same manner as Data Matrix. This decision was made because the "official" algorithm does not provide clear methods for dealing with all possible combinations of input data */ - + int number_count, byte_count, mixed_count, upper_count, lower_count, chinese_count; int sp, best_mode, done; int best_count, last = -1; int debug = 0; - + if(gbdata[position] > 0xff) { return GM_CHINESE; } - + switch(current_mode) { case GM_CHINESE: number_count = 13; @@ -176,11 +176,11 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) lower_count = 4; chinese_count = 4; } - + for(sp = position; (sp < length) && (sp <= (position + 8)); sp++) { - + done = 0; - + if(gbdata[sp] >= 0xff) { byte_count += 17; mixed_count += 23; @@ -189,7 +189,7 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) chinese_count += 13; done = 1; } - + if((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) { byte_count += 8; mixed_count += 6; @@ -198,7 +198,7 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) chinese_count += 13; done = 1; } - + if((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) { byte_count += 8; mixed_count += 6; @@ -207,7 +207,7 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) chinese_count += 13; done = 1; } - + if((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) { byte_count += 8; mixed_count += 6; @@ -216,7 +216,7 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) chinese_count += 13; done = 1; } - + if(gbdata[sp] == ' ') { byte_count += 8; mixed_count += 6; @@ -225,7 +225,7 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) chinese_count += 13; done = 1; } - + if(done == 0) { /* Control character */ byte_count += 8; @@ -234,21 +234,21 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) lower_count += 13; chinese_count += 13; } - + if(gbdata[sp] >= 0x7f) { mixed_count += 20; upper_count += 20; lower_count += 20; } } - + /* Adjust for */ for(sp = position; (sp < (length - 1)) && (sp <= (position + 7)); sp++) { if((gbdata[sp] == 0x13) && (gbdata[sp] == 0x10)) { chinese_count -= 13; } } - + /* Adjust for double digits */ for(sp = position; (sp < (length - 1)) && (sp <= (position + 7)); sp++) { if(sp != last) { @@ -258,40 +258,40 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) } } } - + /* Numeric mode is more complex */ number_count += number_lat(gbdata, length, position); - + if(debug) { printf("C %d / B %d / M %d / U %d / L %d / N %d\n", chinese_count, byte_count, mixed_count, upper_count, lower_count, number_count); } - + best_count = chinese_count; best_mode = GM_CHINESE; - + if(byte_count <= best_count) { best_count = byte_count; best_mode = GM_BYTE; } - + if(mixed_count <= best_count) { best_count = mixed_count; best_mode = GM_MIXED; } - + if(upper_count <= best_count) { best_count = upper_count; best_mode = GM_UPPER; } - + if(lower_count <= best_count) { best_count = lower_count; best_mode = GM_LOWER; } - + if(number_count <= best_count) { best_count = number_count; best_mode = GM_NUMBER; } - + return best_mode; } @@ -314,13 +314,13 @@ void add_shift_char(char binary[], int shifty) /* Add a control character to the data stream */ int i, debug = 0; int glyph = 0; - + for(i = 0; i < 64; i++) { if(shift_set[i] == shifty) { glyph = i; } } - + if(debug) { printf("SHIFT [%d] ", glyph); } if(glyph & 0x20) { concat(binary, "1"); } else { concat(binary, "0"); } @@ -343,21 +343,21 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) int number_pad_posn, debug = 0; int byte_count_posn = 0, byte_count = 0; int shift, i; - + strcpy(binary, ""); - + sp = 0; current_mode = 0; last_mode = 0; number_pad_posn = 0; - + if(reader) { concat(binary, "1010"); /* FNC3 - Reader Initialisation */ } - + do { next_mode = seek_forward(gbdata, length, sp, current_mode); - + if(next_mode != current_mode) { switch(current_mode) { case 0: @@ -440,7 +440,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) } last_mode = current_mode; current_mode = next_mode; - + switch(current_mode) { case GM_CHINESE: done = 0; @@ -448,7 +448,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) /* GB2312 character */ c1 = (gbdata[sp] & 0xff00) >> 8; c2 = gbdata[sp] & 0xff; - + if((c1 >= 0xa0) && (c1 <= 0xa9)) { glyph = (0x60 * (c1 - 0xa1)) + (c2 - 0xa0); } @@ -481,7 +481,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) /* Byte value */ glyph = 7777 + gbdata[sp]; } - + if(debug) { printf("[%d] ", glyph); } if(glyph & 0x1000) { concat(binary, "1"); } else { concat(binary, "0"); } @@ -499,7 +499,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } sp++; break; - + case GM_NUMBER: if(last_mode != current_mode) { /* Reserve a space for numeric digit padding value (2 bits) */ @@ -508,10 +508,10 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) } p = 0; ppos = -1; - + /* Numeric compression can also include certain combinations of non-numeric character */ - + numbuf[0] = '0'; numbuf[1] = '0'; numbuf[2] = '0'; @@ -541,7 +541,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) } } } while ((p < 3) && (sp < length)); - + if(ppos != -1) { switch(punt) { case ' ': glyph = 0; break; @@ -553,7 +553,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) } glyph += ppos; glyph += 1000; - + if(debug) { printf("[%d] ", glyph); } if(glyph & 0x200) { concat(binary, "1"); } else { concat(binary, "0"); } @@ -567,7 +567,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } } - + glyph = (100 * (numbuf[0] - '0')) + (10 * (numbuf[1] - '0')) + (numbuf[2] - '0'); if(debug) { printf("[%d] ", glyph); } @@ -582,7 +582,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) if(glyph & 0x02) { concat(binary, "1"); } else { concat(binary, "0"); } if(glyph & 0x01) { concat(binary, "1"); } else { concat(binary, "0"); } break; - + case GM_BYTE: if(last_mode != current_mode) { /* Reserve space for byte block length indicator (9 bits) */ @@ -597,7 +597,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) concat(binary, "LLLLLLLLL"); byte_count = 0; } - + glyph = gbdata[sp]; if(debug) { printf("[%d] ", glyph); } if(glyph & 0x80) { concat(binary, "1"); } else { concat(binary, "0"); } @@ -611,14 +611,14 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) sp++; byte_count++; break; - + case GM_MIXED: shift = 1; if((gbdata[sp] >= '0') && (gbdata[sp] <= '9')) { shift = 0; } if((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) { shift = 0; } if((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) { shift = 0; } if(gbdata[sp] == ' ') { shift = 0; } - + if(shift == 0) { /* Mixed Mode character */ glyph = posn(EUROPIUM, gbdata[sp]); @@ -635,15 +635,15 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) concat(binary, "1111110110"); /* 1014 - shift indicator */ add_shift_char(binary, gbdata[sp]); } - + sp++; break; - + case GM_UPPER: shift = 1; if((gbdata[sp] >= 'A') && (gbdata[sp] <= 'Z')) { shift = 0; } if(gbdata[sp] == ' ') { shift = 0; } - + if(shift == 0) { /* Upper Case character */ glyph = posn("ABCDEFGHIJKLMNOPQRSTUVWXYZ ", gbdata[sp]); @@ -659,7 +659,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) concat(binary, "1111101"); /* 127 - shift indicator */ add_shift_char(binary, gbdata[sp]); } - + sp++; break; @@ -667,7 +667,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) shift = 1; if((gbdata[sp] >= 'a') && (gbdata[sp] <= 'z')) { shift = 0; } if(gbdata[sp] == ' ') { shift = 0; } - + if(shift == 0) { /* Lower Case character */ glyph = posn("abcdefghijklmnopqrstuvwxyz ", gbdata[sp]); @@ -683,16 +683,16 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) concat(binary, "1111101"); /* 127 - shift indicator */ add_shift_char(binary, gbdata[sp]); } - + sp++; break; } if(strlen(binary) > 9191) { return ERROR_TOO_LONG; } - + } while(sp < length); - + if(current_mode == GM_NUMBER) { /* add numeric block padding value */ switch(p) { @@ -701,12 +701,12 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) case 3: binary[number_pad_posn] = '0'; binary[number_pad_posn + 1] = '0'; break; // 0 pad digits } } - + if(current_mode == GM_BYTE) { /* Add byte block length indicator */ add_byte_count(binary, byte_count_posn, byte_count); } - + /* Add "end of data" character */ switch(current_mode) { case GM_CHINESE: concat(binary, "1111111100000"); break; // 8160 @@ -716,14 +716,14 @@ int gm_encode(int gbdata[], int length, char binary[], int reader) case GM_MIXED: concat(binary, "1111110000"); break; // 1008 case GM_BYTE: concat(binary, "0000"); break; // 0 } - + /* Add padding bits if required */ p = 7 - (strlen(binary) % 7); if(p == 7) { p = 0; } for(i = 0; i < p; i++) { concat(binary, "0"); } - + if(strlen(binary) > 9191) { return ERROR_TOO_LONG; } @@ -814,10 +814,10 @@ void gm_add_ecc(char binary[], int data_posn, int layers, int ecc_level, int wor void place_macromodule(char grid[], int x, int y, int word1, int word2, int size) { int i, j; - + i = (x * 6) + 1; j = (y * 6) + 1; - + if(word2 & 0x40) { grid[(j * size) + i + 2] = '1'; } if(word2 & 0x20) { grid[(j * size) + i + 3] = '1'; } if(word2 & 0x10) { grid[((j + 1) * size) + i] = '1'; } @@ -837,7 +837,7 @@ void place_macromodule(char grid[], int x, int y, int word1, int word2, int size void place_data_in_grid(int word[], char grid[], int modules, int size) { int x, y, macromodule, offset; - + offset = 13 - ((modules - 1) / 2); for(y = 0; y < modules; y++) { for(x = 0; x < modules; x++) { @@ -850,7 +850,7 @@ void place_data_in_grid(int word[], char grid[], int modules, int size) void place_layer_id(char* grid, int size, int layers, int modules, int ecc_level) { /* Place the layer ID into each macromodule */ - + int i, j, layer, start, stop; #ifndef _MSC_VER @@ -869,13 +869,13 @@ void place_layer_id(char* grid, int size, int layers, int modules, int ecc_level layerid[i] = (i + 5 - ecc_level) % 4; } } - + for(i = 0; i < modules; i++) { for(j = 0; j < modules; j++) { id[(i * modules) + j] = 0; } } - + /* Calculate which value goes in each macromodule */ start = modules / 2; stop = modules / 2; @@ -889,7 +889,7 @@ void place_layer_id(char* grid, int size, int layers, int modules, int ecc_level start--; stop++; } - + /* Place the data in the grid */ for(i = 0; i < modules; i++) { for(j = 0; j < modules; j++) { @@ -934,7 +934,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) /* Convert Unicode input to GB-2312 */ error_number = utf8toutf16(symbol, source, utfdata, &length); if(error_number != 0) { return error_number; } - + for(i = 0; i < length; i++) { if(utfdata[i] <= 0xff) { gbdata[i] = utfdata[i]; @@ -964,10 +964,10 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Input data too long"); return error_number; } - + /* Determine the size of the symbol */ data_cw = strlen(binary) / 7; - + auto_layers = 13; for(i = 12; i > 0; i--) { if(gm_recommend_cw[(i - 1)] >= data_cw) { auto_layers = i; } @@ -984,7 +984,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) if(layers == 1) { min_ecc_level = 4; } if((layers == 2) || (layers == 3)) { min_ecc_level = 2; } ecc_level = auto_ecc_level; - + if((symbol->option_2 >= 1) && (symbol->option_2 <= 13)) { input_latch = 1; if(symbol->option_2 > min_layers) { @@ -993,7 +993,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) layers = min_layers; } } - + if(input_latch == 1) { auto_ecc_level = 3; if(layers == 1) { auto_ecc_level = 5; } @@ -1003,7 +1003,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) layers++; } } - + if(input_latch == 0) { if((symbol->option_1 >= 1) && (symbol->option_1 <= 5)) { if(symbol->option_1 > min_ecc_level) { @@ -1018,7 +1018,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) } while ((data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) && (layers <= 13)); } } - + data_max = 1313; switch(ecc_level) { case 2: data_max = 1167; break; @@ -1026,7 +1026,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) case 4: data_max = 875; break; case 5: data_max = 729; break; } - + if(data_cw > data_max) { strcpy(symbol->errtxt, "Input data too long"); return ERROR_TOO_LONG; @@ -1047,10 +1047,10 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) grid[(y * size) + x] = '0'; } } - + place_data_in_grid(word, grid, modules, size); place_layer_id(grid, size, layers, modules, ecc_level); - + /* Add macromodule frames */ for(x = 0; x < modules; x++) { dark = 1 - (x & 1); @@ -1073,7 +1073,7 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) /* Copy values to symbol */ symbol->width = size; symbol->rows = size; - + for(x = 0; x < size; x++) { for(y = 0; y < size; y++) { if(grid[(y * size) + x] == '1') { @@ -1082,6 +1082,6 @@ int grid_matrix(struct zint_symbol *symbol, unsigned char source[], int length) } symbol->row_height[x] = 1; } - + return 0; } diff --git a/backend/gridmtx.h b/backend/gridmtx.h index 9c89c4b2..35673cb3 100644 --- a/backend/gridmtx.h +++ b/backend/gridmtx.h @@ -18,7 +18,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define GM_NUMBER 1 +#define GM_NUMBER 1 #define GM_LOWER 2 #define GM_UPPER 3 #define GM_MIXED 4 diff --git a/backend/gs1.c b/backend/gs1.c index e8b6240e..fa1c1155 100644 --- a/backend/gs1.c +++ b/backend/gs1.c @@ -36,13 +36,13 @@ void itostr(char ai_string[], int ai_value) { int thou, hund, ten, unit; char temp[2]; - + strcpy(ai_string, "("); thou = ai_value / 1000; hund = (ai_value - (1000 * thou)) / 100; ten = (ai_value - ((1000 * thou) + (100 * hund))) / 10; unit = ai_value - ((1000 * thou) + (100 * hund) + (10 * ten)); - + temp[1] = '\0'; if(ai_value >= 1000) { temp[0] = itoc(thou); concat(ai_string, temp); } if(ai_value >= 100) { temp[0] = itoc(hund); concat(ai_string, temp); } @@ -60,7 +60,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne int bracket_level, max_bracket_level, ai_length, max_ai_length, min_ai_length; int ai_value[100], ai_location[100], ai_count, data_location[100], data_length[100]; int error_latch; - + /* Detect extended ASCII characters */ for(i = 0; i < src_len; i++) { if(source[i] >=128) { @@ -72,12 +72,12 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne return ERROR_INVALID_DATA; } } - + if(source[0] != '[') { strcpy(symbol->errtxt, "Data does not start with an AI"); return ERROR_INVALID_DATA; } - + /* Check the position of the brackets */ bracket_level = 0; max_bracket_level = 0; @@ -100,37 +100,37 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne if(ai_length > max_ai_length) { max_ai_length = ai_length; } } min_ai_length--; - + if(bracket_level != 0) { /* Not all brackets are closed */ strcpy(symbol->errtxt, "Malformed AI in input data (brackets don\'t match)"); return ERROR_INVALID_DATA; } - + if(max_bracket_level > 1) { /* Nested brackets */ strcpy(symbol->errtxt, "Found nested brackets in input data"); return ERROR_INVALID_DATA; } - + if(max_ai_length > 4) { /* AI is too long */ strcpy(symbol->errtxt, "Invalid AI in input data (AI too long)"); return ERROR_INVALID_DATA; } - + if(min_ai_length <= 1) { /* AI is too short */ strcpy(symbol->errtxt, "Invalid AI in input data (AI too short)"); return ERROR_INVALID_DATA; } - + if(ai_latch == 1) { /* Non-numeric data in AI */ strcpy(symbol->errtxt, "Invalid AI in input data (non-numeric characters in AI)"); return ERROR_INVALID_DATA; } - + ai_count = 0; for(i = 1; i < src_len; i++) { if(source[i - 1] == '[') { @@ -145,7 +145,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne ai_count++; } } - + for(i = 0; i < ai_count; i++) { data_location[i] = ai_location[i] + 3; if(ai_value[i] >= 100) { data_location[i]++; } @@ -156,7 +156,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne } while ((source[data_location[i] + data_length[i] - 1] != '[') && (source[data_location[i] + data_length[i] - 1] != '\0')); data_length[i]--; } - + for(i = 0; i < ai_count; i++) { if(data_length[i] == 0) { /* No data for given AI */ @@ -164,7 +164,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne return ERROR_INVALID_DATA; } } - + error_latch = 0; strcpy(ai_string, ""); for(i = 0; i < ai_count; i++) { @@ -238,13 +238,13 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne error_latch += 4; } } - + if(error_latch == 5) { strcpy(symbol->errtxt, "Invalid data length for AI "); concat(symbol->errtxt, ai_string); return ERROR_INVALID_DATA; } - + if(error_latch == 6) { strcpy(symbol->errtxt, "Invalid AI value "); concat(symbol->errtxt, ai_string); @@ -284,7 +284,7 @@ int gs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsigne /* The ']' character is simply dropped from the input */ } reduced[j] = '\0'; - + /* the character '[' in the reduced string refers to the FNC1 character */ return 0; } @@ -298,10 +298,10 @@ int ugs1_verify(struct zint_symbol *symbol, unsigned char source[], const unsign char* temp = (char*)_alloca(src_len + 5); #endif int error_number; - + error_number = gs1_verify(symbol, source, src_len, temp); if(error_number != 0) { return error_number; } - + if (strlen(temp) < src_len + 5) { ustrcpy(reduced, (unsigned char*)temp); return 0; diff --git a/backend/imail.c b/backend/imail.c index 859b5b5e..26c7ab5a 100644 --- a/backend/imail.c +++ b/backend/imail.c @@ -3,26 +3,12 @@ /* libzint - the open source barcode library Copyright (C) 2008 Robin Stuart - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* The function "USPS_MSB_Math_CRC11GenerateFrameCheckSequence" is Copyright (C) 2006 United States Postal Service */ -static short int BCD[40] = { +static const short int BCD[40] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, @@ -45,7 +31,7 @@ static short int BCD[40] = { /* The following lookup tables were generated using the code in Appendix C */ -static unsigned short AppxD_I[1287] = { /* Appendix D Table 1 - 5 of 13 characters */ +static const unsigned short AppxD_I[1287] = { /* Appendix D Table 1 - 5 of 13 characters */ 0x001F, 0x1F00, 0x002F, 0x1E80, 0x0037, 0x1D80, 0x003B, 0x1B80, 0x003D, 0x1780, 0x003E, 0x0F80, 0x004F, 0x1E40, 0x0057, 0x1D40, 0x005B, 0x1B40, 0x005D, 0x1740, 0x005E, 0x0F40, 0x0067, 0x1CC0, 0x006B, 0x1AC0, 0x006D, 0x16C0, 0x006E, 0x0EC0, @@ -176,7 +162,7 @@ static unsigned short AppxD_I[1287] = { /* Appendix D Table 1 - 5 of 13 characte 0x1823, 0x1883, 0x1843, 0x1445, 0x1249, 0x1151, 0x10E1, 0x0C46, 0x0A4A, 0x0952, 0x08E2, 0x064C, 0x0554, 0x04E4, 0x0358, 0x02E8, 0x01F0 }; -static unsigned short AppxD_II[78] = { /* Appendix D Table II - 2 of 13 characters */ +static const unsigned short AppxD_II[78] = { /* Appendix D Table II - 2 of 13 characters */ 0x0003, 0x1800, 0x0005, 0x1400, 0x0006, 0x0C00, 0x0009, 0x1200, 0x000A, 0x0A00, 0x000C, 0x0600, 0x0011, 0x1100, 0x0012, 0x0900, 0x0014, 0x0500, 0x0018, 0x0300, 0x0021, 0x1080, 0x0022, 0x0880, 0x0024, 0x0480, 0x0028, 0x0280, 0x0030, 0x0180, @@ -186,14 +172,14 @@ static unsigned short AppxD_II[78] = { /* Appendix D Table II - 2 of 13 characte 0x0201, 0x1008, 0x0202, 0x0808, 0x0204, 0x0408, 0x0401, 0x1004, 0x0402, 0x0804, 0x0801, 0x1002, 0x1001, 0x0802, 0x0404, 0x0208, 0x0110, 0x00A0 }; -static int AppxD_IV[130] = { /* Appendix D Table IV - Bar-to-Character Mapping (reverse lookup) */ +static const int AppxD_IV[130] = { /* Appendix D Table IV - Bar-to-Character Mapping (reverse lookup) */ 67, 6, 78, 16, 86, 95, 34, 40, 45, 113, 117, 121, 62, 87, 18, 104, 41, 76, 57, 119, 115, 72, 97, 2, 127, 26, 105, 35, 122, 52, 114, 7, 24, 82, 68, 63, 94, 44, 77, 112, 70, 100, 39, 30, 107, 15, 125, 85, 10, 65, 54, 88, 20, 106, 46, 66, 8, 116, 29, 61, 99, 80, 90, 37, 123, 51, 25, 84, 129, 56, 4, 109, 96, 28, 36, 47, 11, 71, 33, 102, 21, 9, 17, 49, 124, 79, 64, 91, 42, 69, 53, 60, 14, 1, 27, 103, 126, 75, 89, 50, 120, 19, 32, 110, 92, 111, 130, 59, 31, 12, 81, 43, 55, 5, 74, 22, 101, 128, 58, 118, 48, 108, 38, 98, 93, 23, 83, 13, 73, 3 }; - + /*************************************************************************** ** USPS_MSB_Math_CRC11GenerateFrameCheckSequence ** @@ -248,11 +234,11 @@ extern unsigned short void breakup(short int fcs_bit[], unsigned short usps_crc) { int i; - + for(i = 0; i < 13; i++) { fcs_bit[i] = 0; } - + if(usps_crc >= 4096) { fcs_bit[12] = 1; usps_crc -= 4096; @@ -330,12 +316,12 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - + strcpy(zip, ""); strcpy(tracker, ""); /* separate the tracking code from the routing code */ - + read = 0; j = 0; for(i = 0; i < length; i++) { @@ -360,7 +346,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) } else { zip[read] = '\0'; } - + if(strlen(tracker) != 20) { strcpy(symbol->errtxt, "Invalid length tracking code"); return ERROR_INVALID_DATA; @@ -369,25 +355,25 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Invalid ZIP code"); return ERROR_INVALID_DATA; } - + /* *** Step 1 - Conversion of Data Fields into Binary Data *** */ - + /* Routing code first */ - + for(i = 0; i < 112; i++) { accum[i] = 0; } - + for(read = 0; read < strlen(zip); read++) { for(i = 0; i < 112; i++) { x_reg[i] = accum[i]; } - + for(i = 0; i < 9; i++) { binary_add(accum, x_reg); } - + x_reg[0] = BCD[ctoi(zip[read]) * 4]; x_reg[1] = BCD[(ctoi(zip[read]) * 4) + 1]; x_reg[2] = BCD[(ctoi(zip[read]) * 4) + 2]; @@ -395,16 +381,16 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) for(i = 4; i < 112; i++) { x_reg[i] = 0; } - + binary_add(accum, x_reg); } - + /* add weight to routing code */ - + for(i = 0; i < 112; i++) { x_reg[i] = accum[i]; } - + if(strlen(zip) > 9) { strcpy(zip_adder, "1000100001"); } else { @@ -418,21 +404,21 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) } } } - + for(i = 0; i < 112; i++) { accum[i] = 0; } - + for(read = 0; read < strlen(zip_adder); read++) { for(i = 0; i < 112; i++) { y_reg[i] = accum[i]; } - + for(i = 0; i < 9; i++) { binary_add(accum, y_reg); } - + y_reg[0] = BCD[ctoi(zip_adder[read]) * 4]; y_reg[1] = BCD[(ctoi(zip_adder[read]) * 4) + 1]; y_reg[2] = BCD[(ctoi(zip_adder[read]) * 4) + 2]; @@ -440,23 +426,23 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) for(i = 4; i < 112; i++) { y_reg[i] = 0; } - + binary_add(accum, y_reg); } binary_add(accum, x_reg); - + /* tracking code */ /* multiply by 10 */ for(i = 0; i < 112; i++) { y_reg[i] = accum[i]; } - + for(i = 0; i < 9; i++) { binary_add(accum, y_reg); } - + /* add first digit of tracker */ y_reg[0] = BCD[ctoi(tracker[0]) * 4]; y_reg[1] = BCD[(ctoi(tracker[0]) * 4) + 1]; @@ -465,18 +451,18 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) for(i = 4; i < 112; i++) { y_reg[i] = 0; } - + binary_add(accum, y_reg); - + /* multiply by 5 */ for(i = 0; i < 112; i++) { y_reg[i] = accum[i]; } - + for(i = 0; i < 4; i++) { binary_add(accum, y_reg); } - + /* add second digit */ y_reg[0] = BCD[ctoi(tracker[1]) * 4]; y_reg[1] = BCD[(ctoi(tracker[1]) * 4) + 1]; @@ -485,9 +471,9 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) for(i = 4; i < 112; i++) { y_reg[i] = 0; } - + binary_add(accum, y_reg); - + /* and then the rest */ for(read = 2; read < strlen(tracker); read++) { @@ -495,11 +481,11 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) for(i = 0; i < 112; i++) { y_reg[i] = accum[i]; } - + for(i = 0; i < 9; i++) { binary_add(accum, y_reg); } - + y_reg[0] = BCD[ctoi(tracker[read]) * 4]; y_reg[1] = BCD[(ctoi(tracker[read]) * 4) + 1]; y_reg[2] = BCD[(ctoi(tracker[read]) * 4) + 2]; @@ -507,18 +493,18 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) for(i = 4; i < 112; i++) { y_reg[i] = 0; } - + binary_add(accum, y_reg); } /* printf("Binary data 1: "); hex_dump(accum); */ - + /* *** Step 2 - Generation of 11-bit CRC on Binary Data *** */ accum[103] = 0; accum[102] = 0; - + memset(byte_array, 0, 13); for(j = 0; j < 13; j++) { i = 96 - (8 * j); @@ -532,25 +518,25 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) byte_array[j] += 64 * accum[i + 6]; byte_array[j] += 128 * accum[i + 7]; } - + usps_crc = USPS_MSB_Math_CRC11GenerateFrameCheckSequence(byte_array); /* printf("FCS 2: %4.4X\n", usps_crc); */ - + /* *** Step 3 - Conversion from Binary Data to Codewords *** */ - + /* start with codeword J which is base 636 */ for(i = 0; i < 112; i++) { x_reg[i] = 0; y_reg[i] = 0; } - + x_reg[101] = 1; x_reg[98] = 1; x_reg[97] = 1; x_reg[96] = 1; x_reg[95] = 1; x_reg[94] = 1; - + for(i = 92; i >= 0; i--) { y_reg[i] = islarger(accum, x_reg); if(y_reg[i] == 1) { @@ -558,13 +544,13 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) } shiftdown(x_reg); } - + codeword[9] = (accum[9] * 512) + (accum[8] * 256) + (accum[7] * 128) + (accum[6] * 64) + (accum[5] * 32) + (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) + (accum[1] * 2) + accum[0]; - + /* then codewords I to B with base 1365 */ - + for(j = 8; j > 0; j--) { for(i = 0; i < 112; i++) { accum[i] = y_reg[i]; @@ -584,18 +570,18 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) } shiftdown(x_reg); } - + codeword[j] = (accum[10] * 1024) + (accum[9] * 512) + (accum[8] * 256) + (accum[7] * 128) + (accum[6] * 64) + (accum[5] * 32) + (accum[4] * 16) + (accum[3] * 8) + (accum[2] * 4) + (accum[1] * 2) + accum[0]; } - + codeword[0] = (y_reg[10] * 1024) + (y_reg[9] * 512) + (y_reg[8] * 256) + (y_reg[7] * 128) + (y_reg[6] * 64) + (y_reg[5] * 32) + (y_reg[4] * 16) + (y_reg[3] * 8) + (y_reg[2] * 4) + (y_reg[1] * 2) + y_reg[0]; - + for(i = 0; i < 8; i++) { if(codeword[i] == 1365) { codeword[i] = 0; @@ -608,23 +594,23 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) printf("%d ", codeword[i]); } printf("\n"); */ - + /* *** Step 4 - Inserting Additional Information into Codewords *** */ - + codeword[9] = codeword[9] * 2; - + if(usps_crc >= 1024) { codeword[0] += 659; } - + /* printf("Codewords 4b: "); for(i = 0; i < 10; i++) { printf("%d ", codeword[i]); } printf("\n"); */ - + /* *** Step 5 - Conversion from Codewords to Characters *** */ - + for(i = 0; i < 10; i++) { if(codeword[i] < 1287) { characters[i] = AppxD_I[codeword[i]]; @@ -632,7 +618,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) characters[i] = AppxD_II[codeword[i] - 1287]; } } - + /* printf("Characters 5a: "); for(i = 0; i < 10; i++) { printf("%4.4X ", characters[i]); @@ -646,7 +632,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) characters[i] = 0x1FFF - characters[i]; } } - + /* printf("Characters 5b: "); for(i = 0; i < 10; i++) { printf("%4.4X ", characters[i]); @@ -654,14 +640,14 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) printf("\n"); */ /* *** Step 6 - Conversion from Characters to the Intelligent Mail Barcode *** */ - + for(i = 0; i < 10; i++) { breakup(bit_pattern, characters[i]); for(j = 0; j < 13; j++) { bar_map[AppxD_IV[(13 * i) + j] - 1] = bit_pattern[j]; } } - + strcpy(data_pattern, ""); temp[1] = '\0'; for(i = 0; i < 65; i++) { @@ -673,7 +659,7 @@ int imail(struct zint_symbol *symbol, unsigned char source[], int length) temp[0] = itoc(j); concat(data_pattern, temp); } - + /* Translate 4-state data pattern to symbol */ read = 0; for(i = 0; i < strlen(data_pattern); i++) diff --git a/backend/large.c b/backend/large.c index fbd7aeb7..01a2d285 100644 --- a/backend/large.c +++ b/backend/large.c @@ -24,7 +24,7 @@ #include "common.h" #include "large.h" -static short int BCD[40] = { +static const short int BCD[40] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, @@ -91,7 +91,7 @@ void binary_subtract(short int accumulator[], short int input_buffer[]) /* take input_buffer from accumulator and put answer in accumulator */ int i; short int sub_buffer[112]; - + for(i = 0; i < 112; i++) { if(input_buffer[i] == 0) { sub_buffer[i] = 1; @@ -100,9 +100,9 @@ void binary_subtract(short int accumulator[], short int input_buffer[]) } } binary_add(accumulator, sub_buffer); - + sub_buffer[0] = 1; - + for(i = 1; i < 112; i++) { sub_buffer[i] = 0; } @@ -112,7 +112,7 @@ void binary_subtract(short int accumulator[], short int input_buffer[]) void shiftdown(short int buffer[]) { int i; - + buffer[102] = 0; buffer[103] = 0; @@ -124,11 +124,11 @@ void shiftdown(short int buffer[]) void shiftup(short int buffer[]) { int i; - + for(i = 102; i > 0; i--) { buffer[i] = buffer[i - 1]; } - + buffer[0] = 0; } @@ -139,8 +139,8 @@ short int islarger(short int accum[], short int reg[]) latch = 0; i = 103; larger = 0; - - + + do { if((accum[i] == 1) && (reg[i] == 0)) { latch = 1; @@ -151,7 +151,7 @@ short int islarger(short int accum[], short int reg[]) } i--; } while ((latch == 0) && (i >= -1)); - + return larger; } @@ -159,21 +159,21 @@ void binary_load(short int reg[], char data[], const unsigned int src_len) { int read, i; short int temp[112] = { 0 }; - + for(i = 0; i < 112; i++) { reg[i] = 0; } - + for(read = 0; read < src_len; read++) { for(i = 0; i < 112; i++) { temp[i] = reg[i]; } - + for(i = 0; i < 9; i++) { binary_add(reg, temp); } - + temp[0] = BCD[ctoi(data[read]) * 4]; temp[1] = BCD[(ctoi(data[read]) * 4) + 1]; temp[2] = BCD[(ctoi(data[read]) * 4) + 2]; @@ -181,12 +181,12 @@ void binary_load(short int reg[], char data[], const unsigned int src_len) for(i = 4; i < 112; i++) { temp[i] = 0; } - + binary_add(reg, temp); } } -void hex_dump(short int input_buffer[]) +void hex_dump(short int input_buffer[]) { int i, digit, byte_space; diff --git a/backend/library.c b/backend/library.c index af3be0b5..bb11a91d 100644 --- a/backend/library.c +++ b/backend/library.c @@ -34,7 +34,7 @@ struct zint_symbol *ZBarcode_Create() { struct zint_symbol *symbol; int i; - + symbol = (struct zint_symbol*)malloc(sizeof(*symbol)); if (!symbol) return NULL; @@ -69,7 +69,7 @@ struct zint_symbol *ZBarcode_Create() void ZBarcode_Clear(struct zint_symbol *symbol) { int i, j; - + for(i = 0; i < symbol->rows; i++) { for(j = 0; j < symbol->width; j++) { unset_module(symbol, i, j); @@ -188,16 +188,16 @@ extern int svg_plot(struct zint_symbol *symbol); void error_tag(char error_string[], int error_number) { char error_buffer[100]; - + if(error_number != 0) { strcpy(error_buffer, error_string); - + if(error_number > 4) { strcpy(error_string, "error: "); } else { strcpy(error_string, "warning: "); } - + concat(error_string, error_buffer); } } @@ -240,7 +240,7 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length) { int counter, error_number, i; char to_process[40], temp[2], check_digit; - + if(length > 36) { strcpy(symbol->errtxt, "Data too long for HIBC LIC"); return ERROR_TOO_LONG; @@ -251,14 +251,14 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - + strcpy(to_process, "+"); counter = 41; for(i = 0; i < length; i++) { counter += posn(TECHNETIUM, source[i]); } counter = counter % 43; - + if(counter < 10) { check_digit = itoc(counter); } else { @@ -277,14 +277,14 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length) } } } - + temp[0] = check_digit; temp[1] = '\0'; - + concat(to_process, (char *)source); concat(to_process, temp); length = strlen(to_process); - + switch(symbol->symbology) { case BARCODE_HIBC_128: error_number = code_128(symbol, (unsigned char *)to_process, length); @@ -315,16 +315,16 @@ int hibc(struct zint_symbol *symbol, unsigned char source[], int length) error_number = aztec(symbol, (unsigned char *)to_process, length); break; } - + return error_number; } int gs1_compliant(int symbology) { /* Returns 1 if symbology supports GS1 data */ - + int result = 0; - + switch(symbology) { case BARCODE_EAN128: case BARCODE_RSS_EXP: @@ -348,14 +348,14 @@ int gs1_compliant(int symbology) result = 1; break; } - + return result; } int ZBarcode_ValidID(int symbol_id) { /* Checks whether a symbology is supported */ - + int result = 0; switch(symbol_id) { @@ -444,14 +444,14 @@ int ZBarcode_ValidID(int symbol_id) result = 1; break; } - + return result; } int extended_charset(struct zint_symbol *symbol, unsigned char *source, int length) { int error_number = 0; - + /* These are the "elite" standards which can support multiple character sets */ switch(symbol->symbology) { case BARCODE_QRCODE: error_number = qr_code(symbol, source, length); break; @@ -478,13 +478,13 @@ int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int lengt symbol->border_width = 2; symbol->output_options = BARCODE_BIND; } - + if(symbol->symbology == BARCODE_ITF14) { symbol->whitespace_width = 20; symbol->border_width = 8; symbol->output_options = BARCODE_BOX; } - + switch(symbol->input_mode) { case DATA_MODE: case GS1_MODE: @@ -578,7 +578,7 @@ int reduced_charset(struct zint_symbol *symbol, unsigned char *source, int lengt case BARCODE_MAXICODE: error_number = maxicode(symbol, preprocessed, length); break; case BARCODE_AZTEC: error_number = aztec(symbol, preprocessed, length); break; } - + return error_number; } @@ -650,9 +650,9 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt } else { error_buffer = error_number; } - + if((symbol->input_mode < 0) || (symbol->input_mode > 2)) { symbol->input_mode = DATA_MODE; } - + if(symbol->input_mode == GS1_MODE) { for(i = 0; i < length; i++) { if(source[i] == '\0') { @@ -672,7 +672,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt memcpy(local_source, source, length); local_source[length] = '\0'; } - + switch(symbol->symbology) { case BARCODE_QRCODE: case BARCODE_MICROQR: @@ -683,7 +683,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt error_number = reduced_charset(symbol, local_source, length); break; } - + if((symbol->symbology == BARCODE_CODE128) || (symbol->symbology == BARCODE_CODE128B)) { for(i = 0; i < length; i++) { if(local_source[i] == '\0') { @@ -693,7 +693,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, unsigned char *source, int lengt } } } - + if(error_number == 0) { error_number = error_buffer; } @@ -706,7 +706,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) { int error_number; char output[4]; - + switch(rotate_angle) { case 0: case 90: @@ -718,7 +718,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) return ERROR_INVALID_OPTION; break; } - + if(strlen(symbol->outfile) > 3) { output[0] = symbol->outfile[strlen(symbol->outfile) - 3]; output[1] = symbol->outfile[strlen(symbol->outfile) - 2]; @@ -759,7 +759,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) { int error_number; - + switch(rotate_angle) { case 0: case 90: @@ -771,7 +771,7 @@ int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) return ERROR_INVALID_OPTION; break; } - + error_number = bmp_handle(symbol, rotate_angle); error_tag(symbol->errtxt, error_number); return error_number; @@ -780,9 +780,9 @@ int ZBarcode_Buffer(struct zint_symbol *symbol, int rotate_angle) int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) { int error_number; - + error_number = 0; - + error_number = ZBarcode_Encode(symbol, input, length); if(error_number != 0) { return error_number; @@ -795,9 +795,9 @@ int ZBarcode_Encode_and_Print(struct zint_symbol *symbol, unsigned char *input, int ZBarcode_Encode_and_Buffer(struct zint_symbol *symbol, unsigned char *input, int length, int rotate_angle) { int error_number; - + error_number = 0; - + error_number = ZBarcode_Encode(symbol, input, length); if(error_number != 0) { return error_number; @@ -824,12 +824,12 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) strcpy(symbol->errtxt, "Unable to read input file"); return ERROR_INVALID_DATA; } - + /* Get file length */ fseek(file, 0, SEEK_END); fileLen = ftell(file); fseek(file, 0, SEEK_SET); - + if(fileLen > 7100) { /* The largest amount of data that can be encoded is 7089 numeric digits in QR Code */ strcpy(symbol->errtxt, "Input file too long"); @@ -837,7 +837,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) return ERROR_INVALID_DATA; } } - + /* Allocate memory */ buffer = (unsigned char *)malloc(fileLen * sizeof(unsigned char)); if(!buffer) { @@ -846,7 +846,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) fclose(file); return ERROR_MEMORY; } - + /* Read file contents into buffer */ do @@ -860,7 +860,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) } nRead += n; } while (!feof(file) && (0 < n) && (nRead < fileLen)); - + fclose(file); ret = ZBarcode_Encode(symbol, buffer, nRead); free(buffer); @@ -870,28 +870,28 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, char *filename) int ZBarcode_Encode_File_and_Print(struct zint_symbol *symbol, char *filename, int rotate_angle) { int error_number; - + error_number = 0; - + error_number = ZBarcode_Encode_File(symbol, filename); if(error_number != 0) { return error_number; } - + return ZBarcode_Print(symbol, rotate_angle); } int ZBarcode_Encode_File_and_Buffer(struct zint_symbol *symbol, char *filename, int rotate_angle) { int error_number; - + error_number = 0; - + error_number = ZBarcode_Encode_File(symbol, filename); if(error_number != 0) { return error_number; } - + return ZBarcode_Buffer(symbol, rotate_angle); } diff --git a/backend/maxicode.h b/backend/maxicode.h index f03a902b..1312a1c4 100644 --- a/backend/maxicode.h +++ b/backend/maxicode.h @@ -19,7 +19,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -static int MaxiGrid[] = { /* ISO/IEC 16023 Figure 5 - MaxiCode Module Sequence */ /* 30 x 33 data grid */ +static const int MaxiGrid[] = { /* ISO/IEC 16023 Figure 5 - MaxiCode Module Sequence */ /* 30 x 33 data grid */ 122, 121, 128, 127, 134, 133, 140, 139, 146, 145, 152, 151, 158, 157, 164, 163, 170, 169, 176, 175, 182, 181, 188, 187, 194, 193, 200, 199, 0, 0, 124, 123, 130, 129, 136, 135, 142, 141, 148, 147, 154, 153, 160, 159, 166, 165, 172, 171, 178, 177, 184, 183, 190, 189, 196, 195, 202, 201, 817, 0, 126, 125, 132, 131, 138, 137, 144, 143, 150, 149, 156, 155, 162, 161, 168, 167, 174, 173, 180, 179, 186, 185, 192, 191, 198, 197, 204, 203, 819, 818, @@ -55,7 +55,7 @@ static int MaxiGrid[] = { /* ISO/IEC 16023 Figure 5 - MaxiCode Module Sequence * 738, 737, 744, 743, 750, 749, 756, 755, 762, 761, 768, 767, 774, 773, 780, 779, 786, 785, 792, 791, 798, 797, 804, 803, 810, 809, 816, 815, 864, 863 }; -int maxiCodeSet[256] = { /* from Appendix A - ASCII character to Code Set (e.g. 2 = Set B) */ +static const int maxiCodeSet[256] = { /* from Appendix A - ASCII character to Code Set (e.g. 2 = Set B) */ /* set 0 refers to special characters that fit into more than one set (e.g. GS) */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 5, 0, 2, 1, 1, 1, 1, 1, 1, @@ -72,7 +72,7 @@ int maxiCodeSet[256] = { /* from Appendix A - ASCII character to Code Set (e.g. 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; -int maxiSymbolChar[256] = { /* from Appendix A - ASCII character to symbol value */ +static const int maxiSymbolChar[256] = { /* from Appendix A - ASCII character to symbol value */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 30, 28, 29, 30, 35, 32, 53, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 37, diff --git a/backend/maxipng.h b/backend/maxipng.h index d7beb6c9..0e9f7301 100644 --- a/backend/maxipng.h +++ b/backend/maxipng.h @@ -25,7 +25,7 @@ #define SSET "0123456789ABCDEF" -static int hexagon[120] = { +static const int hexagon[120] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, @@ -40,7 +40,7 @@ static int hexagon[120] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static unsigned int bullseye_compressed[] = { +static const unsigned int bullseye_compressed[] = { 0,0,0,0,0,255,248,0,0,0,0,0, 0,0,0,0,31,255,255,192,0,0,0,0, 0,0,0,1,255,255,255,252,0,0,0,0, diff --git a/backend/medical.c b/backend/medical.c index 2f45d803..09f14350 100644 --- a/backend/medical.c +++ b/backend/medical.c @@ -37,7 +37,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) int counter, error_number, h; char inter[18] = { 0 }; /* 131070 -> 17 bits */ char dest[64]; /* 17 * 2 + 1 */ - + error_number = 0; if(length > 6) { @@ -78,7 +78,7 @@ int pharma_one(struct zint_symbol *symbol, unsigned char source[], int length) concat(dest, "12"); } } - + expand(symbol, dest); return error_number; @@ -95,7 +95,7 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des int counter, h; char inter[17]; int error_number; - + tester = atoi((char*)source); if((tester < 4) || (tester > 64570080)) @@ -130,7 +130,7 @@ int pharma_two_calc(struct zint_symbol *symbol, unsigned char source[], char des dest[h - counter] = inter[counter]; } dest[h + 1] = '\0'; - + return error_number; } @@ -173,7 +173,7 @@ int pharma_two(struct zint_symbol *symbol, unsigned char source[], int length) } symbol->rows = 2; symbol->width = writer - 1; - + return error_number; } @@ -183,7 +183,7 @@ int codabar(struct zint_symbol *symbol, unsigned char source[], int length) int i, error_number; char dest[512]; - + error_number = 0; strcpy(dest, ""); @@ -215,7 +215,7 @@ int codabar(struct zint_symbol *symbol, unsigned char source[], int length) { lookup(CALCIUM, CodaTable, source[i], dest); } - + expand(symbol, dest); ustrcpy(symbol->text, source); return error_number; @@ -228,7 +228,7 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length) long int pharmacode, remainder, devisor; int codeword[6]; char tabella[34]; - + /* Validate the input */ if(length > 8) { strcpy(symbol->errtxt, "Input too long"); @@ -239,12 +239,12 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - + /* Add leading zeros as required */ zeroes = 8 - length; memset(localstr, '0', zeroes); strcpy(localstr + zeroes, (char*)source); - + /* Calculate the check digit */ checksum = 0; checkpart = 0; @@ -258,12 +258,12 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length) checksum += checkpart; } } - + /* Add check digit to data string */ checkdigit = checksum % 10; localstr[8] = itoc(checkdigit); localstr[9] = '\0'; - + /* Convert string into an integer value */ pharmacode = atoi(localstr); @@ -275,7 +275,7 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length) pharmacode = remainder; devisor /= 32; } - + /* Look up values in 'Tabella di conversione' */ strcpy(tabella, "0123456789BCDFGHJKLMNPQRSTUVWXYZ"); for(i = 5; i >= 0; i--) { @@ -285,10 +285,10 @@ int code32(struct zint_symbol *symbol, unsigned char source[], int length) /* Plot the barcode using Code 39 */ error_number = c39(symbol, (unsigned char*)risultante, strlen(risultante)); if(error_number != 0) { return error_number; } - + /* Override the normal text output with the Pharmacode number */ ustrcpy(symbol->text, (unsigned char*)"A"); uconcat(symbol->text, (unsigned char*)localstr); - + return error_number; } diff --git a/backend/pdf417.c b/backend/pdf417.c index 93cb6da8..ae2f4353 100644 --- a/backend/pdf417.c +++ b/backend/pdf417.c @@ -74,7 +74,7 @@ int quelmode(char codeascii) void regroupe(int *indexliste) { int i, j; - + /* bring together same type blocks */ if(*(indexliste) > 1) { i = 1; @@ -83,7 +83,7 @@ void regroupe(int *indexliste) /* bring together */ liste[0][i - 1] = liste[0][i - 1] + liste[0][i]; j = i + 1; - + /* decreace the list */ while(j < *(indexliste)) { liste[0][j - 1] = liste[0][j]; @@ -103,13 +103,13 @@ void regroupe(int *indexliste) void pdfsmooth(int *indexliste) { int i, crnt, last, next, length; - + for(i = 0; i < *(indexliste); i++) { crnt = liste[1][i]; length = liste[0][i]; if(i != 0) { last = liste[1][i - 1]; } else { last = FALSE; } if(i != *(indexliste) - 1) { next = liste[1][i + 1]; } else { next = FALSE; } - + if(crnt == NUM) { if(i == 0) { /* first block */ if(*(indexliste) > 1) { /* and there are others */ @@ -136,7 +136,7 @@ void pdfsmooth(int *indexliste) length = liste[0][i]; if(i != 0) { last = liste[1][i - 1]; } else { last = FALSE; } if(i != *(indexliste) - 1) { next = liste[1][i + 1]; } else { next = FALSE; } - + if((crnt == TEX) && (i > 0)) { /* not the first */ if(i == *(indexliste) - 1) { /* the last one */ if((last == BYT) && (length == 1)) { liste[1][i] = BYT; } @@ -157,10 +157,10 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len { int j, indexlistet, curtable, listet[2][5000], chainet[5000], wnet; char codeascii; - + codeascii = 0; wnet = 0; - + for(j = 0; j < 1000; j++) { listet[0][j] = 0; } @@ -189,7 +189,7 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len } else { if(!(listet[0][j] & listet[0][j + 1])) { flag = TRUE; } } - + if (flag) { /* we change only one character - look for temporary switch */ if((listet[0][j] & 1) && (curtable == 2)) { /* T_UPP */ chainet[wnet] = 27; @@ -206,11 +206,11 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len flag = FALSE; } } - + /* 599 */ if (!(flag)) { int newtable; - + if(j == (length - 1)) { newtable = listet[0][j]; } else { @@ -220,7 +220,7 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len newtable = listet[0][j] & listet[0][j + 1]; } } - + /* Maintain the first if several tables are possible */ switch (newtable) { case 3: @@ -238,16 +238,16 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len case 12: newtable = 4; break; } - + /* 619 - select the switch */ switch (curtable) { - case 1: + case 1: switch (newtable) { case 2: chainet[wnet] = 27; wnet++; break; case 4: chainet[wnet] = 28; wnet++; break; case 8: chainet[wnet] = 28; wnet++; chainet[wnet] = 25; wnet++; break; } break; - case 2: + case 2: switch (newtable) { case 1: chainet[wnet] = 28; wnet++; chainet[wnet] = 28; wnet++; break; case 4: chainet[wnet] = 28; wnet++; break; @@ -273,7 +273,7 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len } } } - + /* 663 */ if (wnet & 1) { chainet[wnet] = 29; @@ -282,14 +282,14 @@ void textprocess(int *chainemc, int *mclength, char chaine[], int start, int len /* Now translate the string chainet into codewords */ chainemc[*(mclength)] = 900; *(mclength) = *(mclength) + 1; - + for(j = 0; j < wnet; j+= 2) { int cw_number; - + cw_number = (30 * chainet[j]) + chainet[j + 1]; chainemc[*(mclength)] = cw_number; *(mclength) = *(mclength) + 1; - + } } @@ -301,7 +301,7 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start unsigned int chunkLen = 0; uint64_t mantisa = 0ULL; uint64_t total = 0ULL; - + if(debug) printf("\nEntering byte mode at position %d\n", start); if(length == 1) { @@ -317,7 +317,7 @@ void byteprocess(int *chainemc, int *mclength, unsigned char chaine[], int start chainemc[(*mclength)++] = 901; if(debug) printf("901 "); } - + while (len < length) { chunkLen = length - len; @@ -359,12 +359,12 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len { int j, loop, longueur, dummy[100], dumlength, diviseur, nombre; char chainemod[50], chainemult[100], temp; - + strcpy(chainemod, ""); for(loop = 0; loop <= 50; loop++) { dummy[loop] = 0; } - + chainemc[*(mclength)] = 902; *(mclength) = *(mclength) + 1; @@ -381,7 +381,7 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len chainemod[longueur + 1] = '\0'; do { diviseur = 900; - + /* 877 - gosub Modulo */ strcpy(chainemult, ""); nombre = 0; @@ -402,7 +402,7 @@ void numbprocess(int *chainemc, int *mclength, char chaine[], int start, int len } diviseur = nombre; /* return to 723 */ - + for(loop = dumlength; loop > 0; loop--) { dummy[loop] = dummy[loop - 1]; } @@ -431,13 +431,13 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) /* 456 */ indexliste = 0; indexchaine = 0; - + mode = quelmode(chaine[indexchaine]); - + for(i = 0; i < 1000; i++) { liste[0][i] = 0; } - + /* 463 */ do { liste[1][indexliste] = mode; @@ -448,7 +448,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } indexliste++; } while (indexchaine < length); - + /* 474 */ pdfsmooth(&indexliste); @@ -464,7 +464,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } } } - + /* 541 - now compress the data */ indexchaine = 0; mclength = 0; @@ -517,16 +517,16 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) /* stop the symbol from becoming too high */ symbol->option_2 = symbol->option_2 + 1; } - + if(longueur + k > 928) { /* Enforce maximum codeword limit */ return 2; } - + if(((longueur + k) / symbol->option_2) > 90) { return 4; } - + /* 781 - Padding calculation */ longueur = mclength + 1 + k; i = 0; @@ -573,17 +573,17 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } mccorrection[0] = (929 - (total * coefrs[offset + j]) % 929) % 929; } - + /* we add these codes to the string */ for(i = k - 1; i >= 0; i--) { chainemc[mclength++] = mccorrection[i] ? 929 - mccorrection[i] : 0; } - + /* 818 - The CW string is finished */ c1 = (mclength / symbol->option_2 - 1) / 3; c2 = symbol->option_1 * 3 + (mclength / symbol->option_2 - 1) % 3; c3 = symbol->option_2 - 1; - + /* we now encode each row */ for(i = 0; i <= (mclength / symbol->option_2) - 1; i++) { for(j = 0; j < symbol->option_2 ; j++) { @@ -635,7 +635,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } concat(codebarre, "-"); } - + strcpy(pattern, ""); for(loop = 0; loop < strlen(codebarre); loop++) { lookup(BRSET, PDFttf, codebarre[loop], pattern); @@ -649,7 +649,7 @@ int pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } symbol->rows = (mclength / symbol->option_2); symbol->width = strlen(pattern); - + /* 843 */ return codeerr; } @@ -660,7 +660,7 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) int codeerr, error_number; error_number = 0; - + if((symbol->option_1 < -1) || (symbol->option_1 > 8)) { strcpy(symbol->errtxt, "Security value out of range"); symbol->option_1 = -1; @@ -674,7 +674,7 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) /* 349 */ codeerr = pdf417(symbol, source, length); - + /* 352 */ if(codeerr != 0) { switch(codeerr) { @@ -700,7 +700,7 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) break; } } - + /* 364 */ return error_number; } @@ -708,27 +708,27 @@ int pdf417enc(struct zint_symbol *symbol, unsigned char source[], int length) int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) { /* like PDF417 only much smaller! */ - + int i, k, j, indexchaine, indexliste, mode, longueur, mccorrection[50], offset; int total, chainemc[2700], mclength, dummy[5], codeerr; char codebarre[100], pattern[580]; int variant, LeftRAPStart, CentreRAPStart, RightRAPStart, StartCluster; int LeftRAP, CentreRAP, RightRAP, Cluster, writer, flip, loop; int debug = 0; - + /* Encoding starts out the same as PDF417, so use the same code */ codeerr = 0; - + /* 456 */ indexliste = 0; indexchaine = 0; - + mode = quelmode(chaine[indexchaine]); - + for(i = 0; i < 1000; i++) { liste[0][i] = 0; } - + /* 463 */ do { liste[1][indexliste] = mode; @@ -755,7 +755,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } } } - + /* 541 - now compress the data */ indexchaine = 0; mclength = 0; @@ -779,7 +779,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } /* This is where it all changes! */ - + if(mclength > 126) { strcpy(symbol->errtxt, "Input data too long"); return ERROR_TOO_LONG; @@ -797,32 +797,32 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } printf("\n"); } - + /* Now figure out which variant of the symbol to use and load values accordingly */ - + variant = 0; - + if((symbol->option_2 == 1) && (mclength > 20)) { /* the user specified 1 column but the data doesn't fit - go to automatic */ symbol->option_2 = 0; strcpy(symbol->errtxt, "Specified symbol size too small for data"); codeerr = WARN_INVALID_OPTION; } - + if((symbol->option_2 == 2) && (mclength > 37)) { /* the user specified 2 columns but the data doesn't fit - go to automatic */ symbol->option_2 = 0; strcpy(symbol->errtxt, "Specified symbol size too small for data"); codeerr = WARN_INVALID_OPTION; } - + if((symbol->option_2 == 3) && (mclength > 82)) { /* the user specified 3 columns but the data doesn't fit - go to automatic */ symbol->option_2 = 0; strcpy(symbol->errtxt, "Specified symbol size too small for data"); codeerr = WARN_INVALID_OPTION; } - + if(symbol->option_2 == 1) { /* the user specified 1 column and the data does fit */ variant = 6; @@ -876,7 +876,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) if(variant == 0) { /* Zint can choose automatically from all available variations */ for(i = 27; i >= 0; i--) { - + if(MicroAutosize[i] >= mclength) { variant = MicroAutosize[i + 28]; } @@ -905,7 +905,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) mclength++; i--; } - + /* Reed-Solomon error correction */ longueur = mclength; for(loop = 0; loop < 50; loop++) { @@ -922,7 +922,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } } } - + for(j = 0; j < k; j++) { if(mccorrection[j] != 0) { mccorrection[j] = 929 - mccorrection[j]; } } @@ -939,20 +939,20 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } printf("\n"); } - + /* Now get the RAP (Row Address Pattern) start values */ LeftRAPStart = RAPTable[variant]; CentreRAPStart = RAPTable[variant + 34]; RightRAPStart = RAPTable[variant + 68]; StartCluster = RAPTable[variant + 102] / 3; - + /* That's all values loaded, get on with the encoding */ - + LeftRAP = LeftRAPStart; CentreRAP = CentreRAPStart; RightRAP = RightRAPStart; Cluster = StartCluster; /* Cluster can be 0, 1 or 2 for Cluster(0), Cluster(3) and Cluster(6) */ - + if(debug) printf("\nInternal row representation:\n"); for(i = 0; i < symbol->rows; i++) { if(debug) printf("row %d: ", i); @@ -965,7 +965,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) dummy[j + 1] = chainemc[i * symbol->option_2 + j]; if(debug) printf("[%d] ", dummy[j + 1]); } - + /* Copy the data into codebarre */ concat(codebarre, RAPLR[LeftRAP]); concat(codebarre, "1"); @@ -995,9 +995,9 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) concat(codebarre, RAPLR[RightRAP]); concat(codebarre, "1"); /* stop */ if(debug) printf("%s\n", codebarre); - + /* Now codebarre is a mixture of letters and numbers */ - + writer = 0; flip = 1; strcpy(pattern, ""); @@ -1023,19 +1023,19 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) } } symbol->width = writer; - + /* so now pattern[] holds the string of '1's and '0's. - copy this to the symbol */ for(loop = 0; loop < strlen(pattern); loop++) { if(pattern[loop] == '1') { set_module(symbol, i, loop); } } symbol->row_height[i] = 2; - + /* Set up RAPs and Cluster for next row */ LeftRAP++; CentreRAP++; RightRAP++; Cluster++; - + if(LeftRAP == 53) { LeftRAP = 1; } @@ -1049,7 +1049,7 @@ int micro_pdf417(struct zint_symbol *symbol, unsigned char chaine[], int length) Cluster = 0; } } - + return codeerr; } diff --git a/backend/plessey.c b/backend/plessey.c index 27d05838..58ae32e7 100644 --- a/backend/plessey.c +++ b/backend/plessey.c @@ -39,12 +39,12 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length) unsigned int i, check; unsigned char *checkptr; - static char grid[9] = {1,1,1,1,0,1,0,0,1}; + static const char grid[9] = {1,1,1,1,0,1,0,0,1}; char dest[1024]; /* 8 + 65 * 8 + 8 * 2 + 9 + 1 ~ 1024 */ int error_number; - + error_number = 0; - + if(length > 65) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; @@ -90,7 +90,7 @@ int plessey(struct zint_symbol *symbol, unsigned char source[], int length) /* Stop character */ concat(dest, "331311313"); - + expand(symbol, dest); ustrcpy(symbol->text, source); free(checkptr); @@ -102,7 +102,7 @@ int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) unsigned int i; char dest[512]; /* 2 + 55 * 8 + 3 + 1 ~ 512 */ - + if(length > 55) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; @@ -118,7 +118,7 @@ int msi_plessey(struct zint_symbol *symbol, unsigned char source[], int length) /* Stop character */ concat (dest, "121"); - + expand(symbol, dest); ustrcpy(symbol->text, source); return 0; @@ -132,7 +132,7 @@ int msi_plessey_mod10(struct zint_symbol *symbol, unsigned char source[], int le char un[200], tri[32]; int error_number, h; char dest[1000]; - + error_number = 0; if(length > 18) { @@ -203,9 +203,9 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons char un[16], tri[32]; int error_number, h; char dest[1000]; - + error_number = 0; - + if(src_len > 18) { /* No Entry Stack Smashers! limit because of str->number conversion*/ strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; @@ -295,7 +295,7 @@ int msi_plessey_mod1010(struct zint_symbol *symbol, unsigned char source[], cons /* Stop character */ concat (dest, "121"); - + expand(symbol, dest); ustrcpy(symbol->text, source); @@ -312,21 +312,21 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const /* Calculate a Modulo 11 check digit using the system discussed on Wikipedia - see http://en.wikipedia.org/wiki/Talk:MSI_Barcode */ /* uses the IBM weight system */ - + int i, weight, x, check; int error_number; char dest[1000]; - + error_number = 0; if(src_len > 55) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + /* start character */ strcpy(dest, "21"); - + /* draw data section */ for(i = 0; i < src_len; i++) { @@ -343,7 +343,7 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const weight = 2; } } - + check = (11 - (x % 11)) % 11; if(check == 10) { lookup(NEON, MSITable, '1', dest); @@ -351,10 +351,10 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const } else { lookup(NEON, MSITable, itoc(check), dest); } - + /* stop character */ concat (dest, "121"); - + expand(symbol, dest); ustrcpy(symbol->text, source); @@ -364,7 +364,7 @@ int msi_plessey_mod11(struct zint_symbol *symbol, unsigned char source[], const symbol->text[src_len] = itoc(check); symbol->text[src_len + 1] = '\0'; } - + return error_number; } @@ -373,24 +373,24 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons /* Combining the Barcode Island and Wikipedia code */ /* Verified against http://www.bokai.com/BarcodeJSP/applet/BarcodeSampleApplet.htm */ /* Weighted using the IBM system */ - + unsigned long i, weight, x, check, wright, dau, pedwar, pump, h; char un[16], tri[16]; int error_number; char dest[1000]; unsigned char temp[32]; unsigned int temp_len; - + error_number = 0; if(src_len > 18) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + /* start character */ strcpy(dest, "21"); - + /* draw data section */ for(i = 0; i < src_len; i++) { @@ -407,7 +407,7 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons weight = 2; } } - + check = (11 - (x % 11)) % 11; ustrcpy(temp, source); temp_len = src_len; @@ -421,7 +421,7 @@ int msi_plessey_mod1110(struct zint_symbol *symbol, unsigned char source[], cons temp[temp_len++] = itoc(check); temp[temp_len] = '\0'; } - + /* caluculate second (mod 10) check digit */ wright = 0; i = !(temp_len & 1); @@ -478,7 +478,7 @@ int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) { strcpy(symbol->errtxt, "Invalid characters in input data"); return ERROR_INVALID_DATA; } - + if((symbol->option_2 < 0) || (symbol->option_2 > 4)) { symbol->option_2 = 0; @@ -491,6 +491,6 @@ int msi_handle(struct zint_symbol *symbol, unsigned char source[], int length) { case 3: error_number = msi_plessey_mod11(symbol, source, length); break; case 4: error_number = msi_plessey_mod1110(symbol, source, length); break; } - + return error_number; } diff --git a/backend/png.c b/backend/png.c index 28be18b8..71ab464b 100644 --- a/backend/png.c +++ b/backend/png.c @@ -85,7 +85,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width unsigned char *image_data; int i, row, column, errno; int fgred, fggrn, fgblu, bgred, bggrn, bgblu; - + switch(rotate_angle) { case 0: case 180: @@ -98,11 +98,11 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width graphic->height = image_width; break; } - + /* 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 ERROR_INVALID_OPTION; @@ -121,14 +121,14 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width strcpy(symbol->errtxt, "Malformed background colour target"); return 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]); - + /* Open output file in binary mode */ if((symbol->output_options & BARCODE_STDOUT) != 0) { #ifdef _MSC_VER @@ -144,7 +144,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width return ERROR_FILE_ACCESS; } } - + /* Set up error handling routine as proc() above */ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, graphic, writepng_error_handler, NULL); if (!png_ptr) { @@ -203,7 +203,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width outdata[i + 1] = bggrn; outdata[i + 2] = bgblu; break; - + } } /* write row contents to file */ @@ -227,10 +227,10 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width outdata[i + 1] = bggrn; outdata[i + 2] = bgblu; break; - + } } - + /* write row contents to file */ image_data = outdata; png_write_row(png_ptr, image_data); @@ -252,10 +252,10 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width outdata[i + 1] = bggrn; outdata[i + 2] = bgblu; break; - + } } - + /* write row contents to file */ image_data = outdata; png_write_row(png_ptr, image_data); @@ -277,7 +277,7 @@ int png_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width outdata[i + 1] = bggrn; outdata[i + 2] = bgblu; break; - + } } @@ -302,7 +302,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width { int i, row, column, errno; int fgred, fggrn, fgblu, bgred, bggrn, bgblu; - + switch(rotate_angle) { case 0: case 180: @@ -315,17 +315,17 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width symbol->bitmap_height = image_width; break; } - + if (symbol->bitmap != NULL) free(symbol->bitmap); symbol->bitmap = (char *) malloc(image_width * image_height * 3); - + /* 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 ERROR_INVALID_OPTION; @@ -344,7 +344,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width strcpy(symbol->errtxt, "Malformed background colour target"); return 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]); @@ -370,7 +370,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width symbol->bitmap[i++] = bggrn; symbol->bitmap[i++] = bgblu; break; - + } } } @@ -390,7 +390,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width symbol->bitmap[i++] = bggrn; symbol->bitmap[i++] = bgblu; break; - + } } } @@ -410,7 +410,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width symbol->bitmap[i++] = bggrn; symbol->bitmap[i++] = bgblu; break; - + } } } @@ -430,7 +430,7 @@ int bmp_pixel_plot(struct zint_symbol *symbol, int image_height, int image_width symbol->bitmap[i++] = bggrn; symbol->bitmap[i++] = bgblu; break; - + } } } @@ -447,11 +447,11 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c char *scaled_pixelbuf; int horiz, vert, i; int scale_width, scale_height; - + if(scaler == 0) { scaler = 0.5; } scale_width = image_width * scaler; scale_height = image_height * scaler; - + /* Apply scale options by creating another pixel buffer */ if (!(scaled_pixelbuf = (char *) malloc(scale_width * scale_height))) { printf("Insufficient memory for pixel buffer"); @@ -461,13 +461,13 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c *(scaled_pixelbuf + i) = '0'; } } - + for(vert = 0; vert < scale_height; vert++) { for(horiz = 0; horiz < scale_width; horiz++) { *(scaled_pixelbuf + (vert * scale_width) + horiz) = *(pixelbuf + ((int)(vert / scaler) * image_width) + (int)(horiz / scaler)); } } - + if(image_type == PNG_DATA) { #ifndef NO_PNG error_number = png_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle); @@ -477,9 +477,9 @@ int png_to_file(struct zint_symbol *symbol, int image_height, int image_width, c } else { error_number = bmp_pixel_plot(symbol, scale_height, scale_width, scaled_pixelbuf, rotate_angle); } - + free(scaled_pixelbuf); - + return error_number; } @@ -487,11 +487,11 @@ void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_ { /* Draw a rectangle */ int i, j, png_ypos; - + png_ypos = image_height - ypos - ylen; /* This fudge is needed because EPS measures height from the bottom up but PNG measures y position from the top down */ - + for(i = (xpos); i < (xpos + xlen); i++) { for( j = (png_ypos); j < (png_ypos + ylen); j++) { *(pixelbuf + (image_width * j) + i) = '1'; @@ -501,11 +501,11 @@ void draw_bar(char *pixelbuf, int xpos, int xlen, int ypos, int ylen, int image_ int bullseye_pixel(int row, int col) { int block_val, block_pos, return_val; - + block_val = bullseye_compressed[(row * 12) + (col / 8)]; return_val = 0; block_pos = col % 8; - + switch(block_pos) { case 0: if((block_val & 0x80) != 0) { return_val = 1; } break; case 1: if((block_val & 0x40) != 0) { return_val = 1; } break; @@ -516,7 +516,7 @@ int bullseye_pixel(int row, int col) { case 6: if((block_val & 0x02) != 0) { return_val = 1; } break; case 7: if((block_val & 0x01) != 0) { return_val = 1; } break; } - + return return_val; } @@ -524,7 +524,7 @@ void draw_bullseye(char *pixelbuf, int image_width, int xoffset, int yoffset) { /* Central bullseye in Maxicode symbols */ int i, j; - + for(j = 103; j < 196; j++) { for(i = 0; i < 93; i++) { if(bullseye_pixel(j - 103, i)) { @@ -539,7 +539,7 @@ void draw_hexagon(char *pixelbuf, int image_width, int xposn, int yposn) { /* Put a hexagon into the pixel buffer */ int i, j; - + for(i = 0; i < 12; i++) { for(j = 0; j < 10; j++) { if(hexagon[(i * 10) + j] == 1) { @@ -553,13 +553,13 @@ void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int { /* Put a letter into a position */ int skip, i, j, glyph_no, alphabet; - + skip = 0; alphabet = 0; - + if(letter < 33) { skip = 1; } if((letter > 127) && (letter < 161)) { skip = 1; } - + if(skip == 0) { if(letter > 128) { alphabet = 1; @@ -567,7 +567,7 @@ void draw_letter(char *pixelbuf, unsigned char letter, int xposn, int yposn, int } else { glyph_no = letter - 33; } - + if(smalltext) { for(i = 0; i <= 8; i++) { for(j = 0; j < 5; j++) { @@ -604,14 +604,14 @@ void draw_string(char *pixbuf, char input_string[], int xposn, int yposn, int sm { /* Plot a string into the pixel buffer */ int i, string_length, string_left_hand; - + string_length = strlen(input_string); string_left_hand = xposn - ((7 * string_length) / 2); - + for(i = 0; i < string_length; i++) { draw_letter(pixbuf, input_string[i], string_left_hand + (i * 7), yposn, smalltext, image_width, image_height); } - + } int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) @@ -626,7 +626,7 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) yoffset = symbol->border_width; image_width = 300 + (2 * xoffset * 2); image_height = 300 + (2 * yoffset * 2); - + if (!(pixelbuf = (char *) malloc(image_width * image_height))) { printf("Insifficient memory for pixel buffer"); return ERROR_ENCODING_PROBLEM; @@ -635,9 +635,9 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) *(pixelbuf + i) = '0'; } } - + draw_bullseye(pixelbuf, image_width, (2 * xoffset), (2 * yoffset)); - + for(row = 0; row < symbol->rows; row++) { yposn = row * 9; for(column = 0; column < symbol->width; column++) { @@ -660,13 +660,13 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) draw_bar(pixelbuf, 0, image_width, 0, symbol->border_width * 2, image_width, image_height); draw_bar(pixelbuf, 0, image_width, 300 + (symbol->border_width * 2), symbol->border_width * 2, image_width, image_height); } - + if((symbol->output_options & BARCODE_BOX) != 0) { /* side bars */ draw_bar(pixelbuf, 0, symbol->border_width * 2, 0, image_height, image_width, image_height); draw_bar(pixelbuf, 300 + ((symbol->border_width + symbol->whitespace_width + symbol->whitespace_width) * 2), symbol->border_width * 2, 0, image_height, image_width, image_height); } - + error_number=png_to_file(symbol, image_height, image_width, pixelbuf, rotate_angle, data_type); free(pixelbuf); return error_number; @@ -675,9 +675,9 @@ int maxi_png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) void to_latin1(unsigned char source[], unsigned char preprocessed[]) { int j, i, input_length; - + input_length = ustrlen(source); - + j = 0; i = 0; do { @@ -699,7 +699,7 @@ void to_latin1(unsigned char source[], unsigned char preprocessed[]) } } while (i < input_length); preprocessed[j] = '\0'; - + return; } @@ -757,7 +757,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) } else { large_bar_height = (symbol->height - preset_height) / large_bar_count; } - + while(!(module_is_set(symbol, symbol->rows - 1, comp_offset))) { comp_offset++; } @@ -785,14 +785,14 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) main_width = 96 + comp_offset; } } - + if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { if(symbol->whitespace_width == 0) { symbol->whitespace_width = 10; main_width = 51 + comp_offset; } } - + latch = 0; r = 0; /* Isolate add-on text */ @@ -818,7 +818,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) yoffset = symbol->border_width; image_width = 2 * (symbol->width + xoffset + xoffset); image_height = 2 * (symbol->height + textoffset + yoffset + yoffset); - + if (!(pixelbuf = (char *) malloc(image_width * image_height))) { printf("Insufficient memory for pixel buffer"); return ERROR_ENCODING_PROBLEM; @@ -850,14 +850,14 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) } next_yposn = (int)(row_posn + row_height); plot_height = next_yposn - plot_yposn; - + i = 0; if(module_is_set(symbol, this_row, 0)) { latch = 1; } else { latch = 0; } - + do { block_width = 0; do { @@ -878,10 +878,10 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) latch = 1; } i += block_width; - + } while (i < symbol->width); } - + xoffset += comp_offset; if ((((symbol->symbology == BARCODE_EANX) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_EANX_CC)) || (symbol->symbology == BARCODE_ISBNX)) { @@ -901,7 +901,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) } textpart[4] = '\0'; textpos = 2 * (17 + xoffset); - + draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); for(i = 0; i < 4; i++) { textpart[i] = symbol->text[i + 4]; @@ -911,7 +911,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); textdone = 1; switch(strlen(addon)) { - case 2: + case 2: textpos = 2 * (xoffset + 86); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); break; @@ -950,7 +950,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); textdone = 1; switch(strlen(addon)) { - case 2: + case 2: textpos = 2 * (xoffset + 114); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); break; @@ -962,12 +962,12 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) break; } - } + } if (((symbol->symbology == BARCODE_UPCA) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCA_CC)) { /* guard bar extensions and text formatting for UPCA */ latch = 1; - + i = 0 + comp_offset; do { block_width = 0; @@ -1025,7 +1025,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); textdone = 1; switch(strlen(addon)) { - case 2: + case 2: textpos = 2 * (xoffset + 116); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); break; @@ -1035,7 +1035,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) break; } - } + } if (((symbol->symbology == BARCODE_UPCE) && (symbol->rows == 1)) || (symbol->symbology == BARCODE_UPCE_CC)) { /* guard bar extensions and text formatting for UPCE */ @@ -1061,7 +1061,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) draw_string(pixelbuf, textpart, textpos, default_text_posn, smalltext, image_width, image_height); textdone = 1; switch(strlen(addon)) { - case 2: + case 2: textpos = 2 * (xoffset + 70); draw_string(pixelbuf, addon, textpos, image_height - (addon_text_posn * 2) - 13, smalltext, image_width, image_height); break; @@ -1074,7 +1074,7 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) } xoffset -= comp_offset; - + /* Put boundary bars or box around symbol */ if(((symbol->output_options & BARCODE_BOX) != 0) || ((symbol->output_options & BARCODE_BIND) != 0)) { /* boundary bars */ @@ -1089,13 +1089,13 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) } } } - + if((symbol->output_options & BARCODE_BOX) != 0) { /* side bars */ draw_bar(pixelbuf, 0, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height); draw_bar(pixelbuf, (symbol->width + xoffset + xoffset - symbol->border_width) * 2, symbol->border_width * 2, textoffset * 2, (symbol->height + (2 * symbol->border_width)) * 2, image_width, image_height); } - + /* Put the human readable text at the bottom */ if((textdone == 0) && (ustrlen(local_text) != 0)) { textpos = (image_width / 2); @@ -1111,14 +1111,14 @@ int png_plot(struct zint_symbol *symbol, int rotate_angle, int data_type) int png_handle(struct zint_symbol *symbol, int rotate_angle) { int error; - + if(symbol->symbology == BARCODE_MAXICODE) { error = maxi_png_plot(symbol, rotate_angle, PNG_DATA); } else { error = png_plot(symbol, rotate_angle, PNG_DATA); } - + return error; } #endif /* NO_PNG */ @@ -1126,13 +1126,13 @@ int png_handle(struct zint_symbol *symbol, int rotate_angle) int bmp_handle(struct zint_symbol *symbol, int rotate_angle) { int error; - + if(symbol->symbology == BARCODE_MAXICODE) { error = maxi_png_plot(symbol, rotate_angle, BMP_DATA); } else { error = png_plot(symbol, rotate_angle, BMP_DATA); } - + return error; } diff --git a/backend/postal.c b/backend/postal.c index 4e0bdf24..69924b8f 100644 --- a/backend/postal.c +++ b/backend/postal.c @@ -43,13 +43,13 @@ static const char *KoreaTable[10] = {"1313150613", "0713131313", "0417131313", " static const char *JapanTable[19] = {"114", "132", "312", "123", "141", "321", "213", "231", "411", "144", "414", "324", "342", "234", "432", "243", "423", "441", "111"}; - + int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int length) { /* Handles the PostNet system used for Zip codes in the US */ unsigned int i, sum, check_digit; int error_number; - + error_number = 0; if(length > 38) { @@ -77,10 +77,10 @@ int postnet(struct zint_symbol *symbol, unsigned char source[], char dest[], int /* stop character */ concat (dest, "L"); - + return error_number; } - + int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) { /* Puts PostNet barcodes into the pattern matrix */ @@ -88,7 +88,7 @@ int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) unsigned int loopey, h; int writer; int error_number; - + error_number = 0; error_number = postnet(symbol, source, height_pattern, length); @@ -111,7 +111,7 @@ int post_plot(struct zint_symbol *symbol, unsigned char source[], int length) symbol->row_height[1] = 6; symbol->rows = 2; symbol->width = writer - 1; - + return error_number; } @@ -120,9 +120,9 @@ int planet(struct zint_symbol *symbol, unsigned char source[], char dest[], int /* Handles the PLANET system used for item tracking in the US */ unsigned int i, sum, check_digit; int error_number; - + error_number = 0; - + if(length > 38) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; @@ -159,7 +159,7 @@ int planet_plot(struct zint_symbol *symbol, unsigned char source[], int length) unsigned int loopey, h; int writer; int error_number; - + error_number = 0; error_number = planet(symbol, source, height_pattern, length); @@ -227,14 +227,14 @@ int fim(struct zint_symbol *symbol, unsigned char source[], int length) { /* The simplest barcode symbology ever! Supported by MS Word, so here it is! */ /* glyphs from http://en.wikipedia.org/wiki/Facing_Identification_Mark */ - + char dest[16] = { 0 }; - + if(length > 1) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; } - + switch((char)source[0]) { case 'a': case 'A': @@ -257,7 +257,7 @@ int fim(struct zint_symbol *symbol, unsigned char source[], int length) return ERROR_INVALID_DATA; break; } - + expand(symbol, dest); return 0; } @@ -292,7 +292,7 @@ char rm4scc(char source[], unsigned char dest[], int length) /* stop character */ concat ((char*)dest, "0"); - + return set_copy[check_digit]; } @@ -306,7 +306,7 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(height_pattern, ""); error_number = 0; - + if(length > 120) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; @@ -340,7 +340,7 @@ int royal_plot(struct zint_symbol *symbol, unsigned char source[], int length) symbol->row_height[2] = 3; symbol->rows = 3; symbol->width = writer - 1; - + return error_number; } @@ -356,7 +356,7 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(height_pattern, ""); error_number = 0; - + if(length > 18) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; @@ -367,18 +367,18 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - + /* Add leading zeroes */ /* zeroes = 11 - length; memset(localstr, '0', zeroes); strcpy(localstr + zeroes, (char *)source);*/ strcpy(localstr, (char *)source); - + /* Encode data */ for (i = 0; i < 18; i++) { lookup(KRSET, RoyalTable, localstr[i], height_pattern); } - + writer = 0; h = strlen(height_pattern); for(loopey = 0; loopey < h; loopey++) @@ -400,7 +400,7 @@ int kix_code(struct zint_symbol *symbol, unsigned char source[], int length) symbol->row_height[2] = 3; symbol->rows = 3; symbol->width = writer - 1; - + return error_number; } @@ -412,7 +412,7 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) unsigned int loopey, h; int writer, i, error_number; strcpy(height_pattern, ""); - + error_number = 0; if(length > 50) { strcpy(symbol->errtxt, "Input too long"); @@ -425,14 +425,14 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) strcpy(symbol->errtxt, "Invalid characters in data"); return error_number; } - + for (i = 0; i < length; i++) { if(source[i] == 'D') { concat(height_pattern, "2"); } if(source[i] == 'A') { concat(height_pattern, "1"); } if(source[i] == 'F') { concat(height_pattern, "0"); } if(source[i] == 'T') { concat(height_pattern, "3"); } } - + writer = 0; h = strlen(height_pattern); for(loopey = 0; loopey < h; loopey++) @@ -448,13 +448,13 @@ int daft_code(struct zint_symbol *symbol, unsigned char source[], int length) } writer += 2; } - + symbol->row_height[0] = 3; symbol->row_height[1] = 2; symbol->row_height[2] = 3; symbol->rows = 3; symbol->width = writer - 1; - + return error_number; } @@ -463,9 +463,9 @@ int flattermarken(struct zint_symbol *symbol, unsigned char source[], int length but it's supported by TBarCode so it's supported by Zint! */ int loop, error_number; char dest[512]; /* 90 * 4 + 1 ~ */ - + error_number = 0; - + if(length > 90) { strcpy(symbol->errtxt, "Input too long"); return ERROR_TOO_LONG; @@ -543,7 +543,7 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) inter[20] = '\0'; strcpy(pattern, "13"); /* Start */ - + sum = 0; for(i = 0; i < 20; i++) { concat(pattern, JapanTable[posn(KASUTSET, inter[i])]); @@ -559,9 +559,9 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) if(check >= 11) { check_char = (check - 11) + 'a'; } concat(pattern, JapanTable[posn(KASUTSET, check_char)]); /* printf("check %c (%d)\n", check_char, check); */ - + concat(pattern, "31"); /* Stop */ - + /* Resolve pattern to 4-state symbols */ writer = 0; h = strlen(pattern); @@ -578,12 +578,12 @@ int japan_post(struct zint_symbol *symbol, unsigned char source[], int length) } writer += 2; } - + symbol->row_height[0] = 3; symbol->row_height[1] = 2; symbol->row_height[2] = 3; symbol->rows = 3; symbol->width = writer - 1; - + return error_number; } diff --git a/backend/qr.c b/backend/qr.c index c7eb1271..e5ea8a18 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -33,7 +33,7 @@ int in_alpha(int glyph) { /* Returns true if input glyph is in the Alphanumeric set */ int retval = 0; char cglyph = (char) glyph; - + if((cglyph >= '0') && (cglyph <= '9')) { retval = 1; } @@ -53,7 +53,7 @@ int in_alpha(int glyph) { retval = 1; break; } - + return retval; } @@ -61,9 +61,9 @@ void define_mode(char mode[], int jisdata[], int length, int gs1) { /* Values placed into mode[] are: K = Kanji, B = Binary, A = Alphanumeric, N = Numeric */ int i, mlen, j; - + for(i = 0; i < length; i++) { - if(jisdata[i] > 0xff) { + if(jisdata[i] > 0xff) { mode[i] = 'K'; } else { mode[i] = 'B'; @@ -72,7 +72,7 @@ void define_mode(char mode[], int jisdata[], int length, int gs1) if((jisdata[i] >= '0') && (jisdata[i] <= '9')) { mode[i] = 'N'; } } } - + /* If less than 6 numeric digits together then don't use numeric mode */ for(i = 0; i < length; i++) { if(mode[i] == 'N') { @@ -89,7 +89,7 @@ void define_mode(char mode[], int jisdata[], int length, int gs1) } } } - + /* If less than 4 alphanumeric characters together then don't use alphanumeric mode */ for(i = 0; i < length; i++) { if(mode[i] == 'A') { @@ -117,7 +117,7 @@ int estimate_binary_length(char mode[], int length, int gs1) int n_count = 0; if(gs1) { count += 4; } - + for(i = 0; i < length; i++) { if(mode[i] != current) { switch(mode[i]) { @@ -157,7 +157,7 @@ int estimate_binary_length(char mode[], int length, int gs1) return count; } -static inline void qr_bscan(char *binary, int data, int h) +static void qr_bscan(char *binary, int data, int h) { for (; h; h>>=1) { concat(binary, data & h ? "1" : "0"); @@ -179,11 +179,11 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in char* binary = (char *)_alloca(est_binlen + 12); #endif strcpy(binary, ""); - + if(gs1) { concat(binary, "0101"); /* FNC1 */ } - + if(version <= 9) { scheme = 1; } else if((version >= 10) && (version <= 26)) { @@ -191,39 +191,39 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in } else if(version >= 27) { scheme = 3; } - - if(debug) { + + if(debug) { for(i = 0; i < length; i++) { printf("%c", mode[i]); } printf("\n"); } - + percent = 0; - + do { data_block = mode[position]; short_data_block_length = 0; do { short_data_block_length++; } while (((short_data_block_length + position) < length) && (mode[position + short_data_block_length] == data_block)); - + switch(data_block) { case 'K': /* Kanji mode */ /* Mode indicator */ concat(binary, "1000"); - + /* Character count indicator */ qr_bscan(binary, short_data_block_length, 0x20 << (scheme*2)); /* scheme = 1..3 */ if(debug) { printf("Kanji block (length %d)\n\t", short_data_block_length); } - + /* Character representation */ for(i = 0; i < short_data_block_length; i++) { int jis = jisdata[position + i]; int msb, lsb, prod; - + if(jis > 0x9fff) { jis -= 0xc140; } msb = (jis & 0xff00) >> 4; lsb = (jis & 0xff); @@ -233,24 +233,24 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in if(debug) { printf("0x%4X ", prod); } } - + if(debug) { printf("\n"); } - + break; case 'B': /* Byte mode */ /* Mode indicator */ concat(binary, "0100"); - + /* Character count indicator */ qr_bscan(binary, short_data_block_length, scheme > 1 ? 0x8000 : 0x80); /* scheme = 1..3 */ if(debug) { printf("Byte block (length %d)\n\t", short_data_block_length); } - + /* Character representation */ for(i = 0; i < short_data_block_length; i++) { int byte = jisdata[position + i]; - + if(gs1 && (byte == '[')) { byte = 0x1d; /* FNC1 */ } @@ -259,26 +259,26 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in if(debug) { printf("0x%2X(%d) ", byte, byte); } } - + if(debug) { printf("\n"); } - + break; case 'A': /* Alphanumeric mode */ /* Mode indicator */ concat(binary, "0010"); - + /* Character count indicator */ qr_bscan(binary, short_data_block_length, 0x40 << (2 * scheme)); /* scheme = 1..3 */ if(debug) { printf("Alpha block (length %d)\n\t", short_data_block_length); } - + /* Character representation */ - i = 0; + i = 0; while ( i < short_data_block_length ) { int count; int first = 0, second = 0, prod; - + if(percent == 0) { if(gs1 && (jisdata[position + i] == '%')) { first = posn(RHODIUM, '%'); @@ -295,7 +295,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in count = 1; i++; prod = first; - + if(mode[position + i] == 'A') { if(gs1 && (jisdata[position + i] == '%')) { second = posn(RHODIUM, '%'); @@ -320,7 +320,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in i++; prod = first; percent = 0; - + if(mode[position + i] == 'A') { if(gs1 && (jisdata[position + i] == '%')) { second = posn(RHODIUM, '%'); @@ -344,35 +344,35 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in if(debug) { printf("0x%4X ", prod); } }; - + if(debug) { printf("\n"); } - + break; case 'N': /* Numeric mode */ /* Mode indicator */ concat(binary, "0001"); - + /* Character count indicator */ qr_bscan(binary, short_data_block_length, 0x80 << (2 * scheme)); /* scheme = 1..3 */ if(debug) { printf("Number block (length %d)\n\t", short_data_block_length); } - + /* Character representation */ - i = 0; + i = 0; while ( i < short_data_block_length ) { int count; int first = 0, second = 0, third = 0, prod; - + first = posn(NEON, (char) jisdata[position + i]); count = 1; prod = first; - + if(mode[position + i + 1] == 'N') { second = posn(NEON, (char) jisdata[position + i + 1]); count = 2; prod = (prod * 10) + second; - + if(mode[position + i + 2] == 'N') { third = posn(NEON, (char) jisdata[position + i + 2]); count = 3; @@ -383,18 +383,18 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in qr_bscan(binary, prod, 1 << (3 * count)); /* count = 1..3 */ if(debug) { printf("0x%4X (%d)", prod, prod); } - + i += count; }; - + if(debug) { printf("\n"); } - + break; } - + position += short_data_block_length; } while (position < length) ; - + /* Terminator */ concat(binary, "0000"); @@ -402,7 +402,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in padbits = 8 - (current_binlen % 8); if(padbits == 8) { padbits = 0; } current_bytes = (current_binlen + padbits) / 8; - + /* Padding bits */ for(i = 0; i < padbits; i++) { concat(binary, "0"); @@ -420,7 +420,7 @@ void qr_binary(int datastream[], int version, int target_binlen, char mode[], in if(binary[i * 8 + 6] == '1') { datastream[i] += 0x02; } if(binary[i * 8 + 7] == '1') { datastream[i] += 0x01; } } - + /* Add pad codewords */ toggle = 0; for(i = current_bytes; i < target_binlen; i++) { @@ -466,23 +466,23 @@ void add_ecc(int fullstream[], int datastream[], int version, int data_cw, int b #endif posn = 0; - + for(i = 0; i < blocks; i++) { if(i < qty_short_blocks) { length_this_block = short_data_block_length; } else { length_this_block = short_data_block_length + 1; } - + for(j = 0; j < ecc_block_length; j++) { ecc_block[j] = 0; } - + for(j = 0; j < length_this_block; j++) { data_block[j] = (unsigned char) datastream[posn + j]; } - + rs_init_gf(0x11d); rs_init_code(ecc_block_length, 0); rs_encode(length_this_block, data_block, ecc_block); rs_free(); - + if(debug) { printf("Block %d: ", i + 1); for(j = 0; j < length_this_block; j++) { @@ -497,29 +497,29 @@ void add_ecc(int fullstream[], int datastream[], int version, int data_cw, int b } printf("\n"); } - + for(j = 0; j < short_data_block_length; j++) { interleaved_data[(j * blocks) + i] = (int) data_block[j]; } - + if(i >= qty_short_blocks){ interleaved_data[(short_data_block_length * blocks) + (i - qty_short_blocks)] = (int) data_block[short_data_block_length]; } - + for(j = 0; j < ecc_block_length; j++) { interleaved_ecc[(j * blocks) + i] = (int) ecc_block[ecc_block_length - j - 1]; } - + posn += length_this_block; } - + for(j = 0; j < data_cw; j++) { fullstream[j] = interleaved_data[j]; } for(j = 0; j < ecc_cw; j++) { fullstream[j + data_cw] = interleaved_ecc[j]; } - + if(debug) { printf("\nData Stream: \n"); for(j = 0; j < (data_cw + ecc_cw); j++) { @@ -532,7 +532,7 @@ void add_ecc(int fullstream[], int datastream[], int version, int data_cw, int b void place_finder(unsigned char grid[], int size, int x, int y) { int xp, yp; - + int finder[] = { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, @@ -542,7 +542,7 @@ void place_finder(unsigned char grid[], int size, int x, int y) 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 }; - + for(xp = 0; xp < 7; xp++) { for(yp = 0; yp < 7; yp++) { if (finder[xp + (7 * yp)] == 1) { @@ -557,7 +557,7 @@ void place_finder(unsigned char grid[], int size, int x, int y) void place_align(unsigned char grid[], int size, int x, int y) { int xp, yp; - + int alignment[] = { 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, @@ -565,10 +565,10 @@ void place_align(unsigned char grid[], int size, int x, int y) 1, 0, 0, 0, 1, 1, 1, 1, 1, 1 }; - + x -= 2; y -= 2; /* Input values represent centre of pattern */ - + for(xp = 0; xp < 5; xp++) { for(yp = 0; yp < 5; yp++) { if (alignment[xp + (5 * yp)] == 1) { @@ -597,12 +597,12 @@ void setup_grid(unsigned char* grid, int size, int version) toggle = 1; } } - + /* Add finder patterns */ place_finder(grid, size, 0, 0); place_finder(grid, size, 0, size - 7); place_finder(grid, size, size - 7, 0); - + /* Add separators */ for(i = 0; i < 7; i++) { grid[(7 * size) + i] = 0x10; @@ -615,24 +615,24 @@ void setup_grid(unsigned char* grid, int size, int version) grid[(7 * size) + 7] = 0x10; grid[(7 * size) + (size - 8)] = 0x10; grid[((size - 8) * size) + 7] = 0x10; - + /* Add alignment patterns */ if(version != 1) { /* Version 1 does not have alignment patterns */ - + loopsize = qr_align_loopsize[version - 1]; for(x = 0; x < loopsize; x++) { for(y = 0; y < loopsize; y++) { xcoord = qr_table_e1[((version - 2) * 7) + x]; ycoord = qr_table_e1[((version - 2) * 7) + y]; - + if(!(grid[(ycoord * size) + xcoord] & 0x10)) { place_align(grid, size, xcoord, ycoord); } } } } - + /* Reserve space for format information */ for(i = 0; i < 8; i++) { grid[(8 * size) + i] += 0x20; @@ -642,7 +642,7 @@ void setup_grid(unsigned char* grid, int size, int version) } grid[(8 * size) + 8] += 20; grid[((size - 1 - 7) * size) + 8] = 0x21; /* Dark Module from Figure 25 */ - + /* Reserve space for version information */ if(version >= 7) { for(i = 0; i < 6; i++) { @@ -679,9 +679,9 @@ void populate_grid(unsigned char* grid, int size, int* datastream, int cw) { int direction = 1; /* up */ int row = 0; /* right hand side */ - + int i, n, x, y; - + n = cw * 8; y = size - 1; i = 0; @@ -698,7 +698,7 @@ void populate_grid(unsigned char* grid, int size, int* datastream, int cw) } i++; } - + if(i < n) { if(!(grid[(y * size) + x] & 0xf0)) { if (cwbit(datastream, i)) { @@ -709,7 +709,7 @@ void populate_grid(unsigned char* grid, int size, int* datastream, int cw) i++; } } - + if(direction) { y--; } else { y++; } if(y == -1) { /* reached the top */ @@ -755,7 +755,7 @@ int evaluate(unsigned char *grid, int size, int pattern) } } } - + /* Test 1: Adjacent modules in row/column in same colour */ /* Vertical */ for(x = 0; x < size; x++) { @@ -776,7 +776,7 @@ int evaluate(unsigned char *grid, int size, int pattern) result += (3 + block); } } - + /* Horizontal */ for(y = 0; y < size; y++) { state = local[y * size]; @@ -796,9 +796,9 @@ int evaluate(unsigned char *grid, int size, int pattern) result += (3 + block); } } - + /* Test 2 is not implimented */ - + /* Test 3: 1:1:3:1:1 ratio pattern in row/column */ /* Vertical */ for(x = 0; x < size; x++) { @@ -816,7 +816,7 @@ int evaluate(unsigned char *grid, int size, int pattern) } } } - + /* Horizontal */ for(y = 0; y < size; y++) { for(x = 0; x < (size - 7); x++) { @@ -833,7 +833,7 @@ int evaluate(unsigned char *grid, int size, int pattern) } } } - + /* Test 4: Proportion of dark modules in entire symbol */ dark_mods = 0; for(x = 0; x < size; x++) { @@ -849,9 +849,9 @@ int evaluate(unsigned char *grid, int size, int pattern) } else { k = (percentage - 50) / 5; } - + result += 10 * k; - + return result; } @@ -876,7 +876,7 @@ int apply_bitmask(unsigned char *grid, int size) for(x = 0; x < size; x++) { for(y = 0; y < size; y++) { mask[(y * size) + x] = 0x00; - + if (!(grid[(y * size) + x] & 0xf0)) { if(((y + x) & 1) == 0) { mask[(y * size) + x] += 0x01; } if((y & 1) == 0) { mask[(y * size) + x] += 0x02; } @@ -889,21 +889,21 @@ int apply_bitmask(unsigned char *grid, int size) } } } - + for(x = 0; x < size; x++) { for(y = 0; y < size; y++) { if(grid[(y * size) + x] & 0x01) { p = 0xff; } else { p = 0x00; } - + eval[(y * size) + x] = mask[(y * size) + x] ^ p; } } - - + + /* Evaluate result */ for(pattern = 0; pattern < 8; pattern++) { penalty[pattern] = evaluate(eval, size, pattern); } - + best_pattern = 0; best_val = penalty[0]; for(pattern = 1; pattern < 8; pattern++) { @@ -912,7 +912,7 @@ int 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++) { @@ -936,18 +936,18 @@ int apply_bitmask(unsigned char *grid, int size) } } } - + return best_pattern; } void add_format_info(unsigned char *grid, int size, int ecc_level, int pattern) { /* Add format information to grid */ - + int format = pattern; unsigned int seq; int i; - + switch(ecc_level) { case LEVEL_L: format += 0x08; break; case LEVEL_Q: format += 0x18; break; @@ -955,23 +955,23 @@ void add_format_info(unsigned char *grid, int size, int ecc_level, int pattern) } seq = qr_annex_c[format]; - + for(i = 0; i < 6; i++) { grid[(i * size) + 8] += (seq >> i) & 0x01; } - + for(i = 0; i < 8; i++) { grid[(8 * size) + (size - i - 1)] += (seq >> i) & 0x01; } - + for(i = 0; i < 6; i++) { grid[(8 * size) + (5 - i)] += (seq >> (i + 9)) & 0x01; } - + for(i = 0; i < 7; i++) { grid[(((size - 7) + i) * size) + 8] += (seq >> (i + 8)) & 0x01; } - + grid[(7 * size) + 8] += (seq >> 6) & 0x01; grid[(8 * size) + 8] += (seq >> 7) & 0x01; grid[(8 * size) + 7] += (seq >> 8) & 0x01; @@ -981,7 +981,7 @@ void add_version_info(unsigned char *grid, int size, int version) { /* Add version information */ int i; - + long int version_data = qr_annex_d[version - 7]; for(i = 0; i < 6; i++) { grid[((size - 11) * size) + i] += (version_data >> (i * 3)) & 0x01; @@ -1010,7 +1010,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) #endif gs1 = (symbol->input_mode == GS1_MODE); - + switch(symbol->input_mode) { case DATA_MODE: for(i = 0; i < length; i++) { @@ -1043,10 +1043,10 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) } break; } - + define_mode(mode, jisdata, length, gs1); est_binlen = estimate_binary_length(mode, length, gs1); - + ecc_level = LEVEL_L; max_cw = 2956; if((symbol->option_1 >= 1) && (symbol->option_1 <= 4)) { @@ -1057,12 +1057,12 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) case 4: ecc_level = LEVEL_H; max_cw = 1276; break; } } - + if(est_binlen > (8 * max_cw)) { strcpy(symbol->errtxt, "Input too long for selected error correction level"); return ERROR_TOO_LONG; } - + autosize = 40; for(i = 39; i >= 0; i--) { switch(ecc_level) { @@ -1088,7 +1088,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) break; } } - + if((symbol->option_2 >= 1) && (symbol->option_2 <= 40)) { if (symbol->option_2 > autosize) { version = symbol->option_2; @@ -1098,7 +1098,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) } else { version = autosize; } - + /* Ensure maxium error correction capacity */ if(est_binlen <= qr_data_codewords_M[version - 1]) { ecc_level = LEVEL_M; } if(est_binlen <= qr_data_codewords_Q[version - 1]) { ecc_level = LEVEL_Q; } @@ -1121,7 +1121,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) qr_binary(datastream, version, target_binlen, mode, jisdata, length, gs1, est_binlen); add_ecc(fullstream, datastream, version, target_binlen, blocks); - + size = qr_sizes[version - 1]; #ifndef _MSC_VER unsigned char grid[size * size]; @@ -1134,7 +1134,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) grid[(i * size) + j] = 0; } } - + setup_grid(grid, size, version); populate_grid(grid, size, fullstream, qr_total_codewords[version - 1]); bitmask = apply_bitmask(grid, size); @@ -1142,7 +1142,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) if(version >= 7) { add_version_info(grid, size, version); } - + symbol->width = size; symbol->rows = size; @@ -1154,7 +1154,7 @@ int qr_code(struct zint_symbol *symbol, unsigned char source[], int length) } symbol->row_height[i] = 1; } - + return 0; } @@ -1168,7 +1168,7 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, int short_data_block_length, i; char data_block; char buffer[2]; - + strcpy(binary, ""); if(debug) { @@ -1177,37 +1177,37 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, } printf("\n"); } - + do { if(strlen(binary) > 128) { return ERROR_TOO_LONG; } - + data_block = mode[position]; short_data_block_length = 0; do { short_data_block_length++; } while (((short_data_block_length + position) < length) && (mode[position + short_data_block_length] == data_block)); - + switch(data_block) { case 'K': /* Kanji mode */ /* Mode indicator */ concat(binary, "K"); *kanji_used = 1; - + /* Character count indicator */ buffer[0] = short_data_block_length; buffer[1] = '\0'; concat(binary, buffer); - + if(debug) { printf("Kanji block (length %d)\n\t", short_data_block_length); } - + /* Character representation */ for(i = 0; i < short_data_block_length; i++) { int jis = jisdata[position + i]; int msb, lsb, prod; - + if(jis > 0x9fff) { jis -= 0xc140; } msb = (jis & 0xff00) >> 4; lsb = (jis & 0xff); @@ -1216,28 +1216,28 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, qr_bscan(binary, prod, 0x1000); if(debug) { printf("0x%4X ", prod); } - + if(strlen(binary) > 128) { return ERROR_TOO_LONG; } } - + if(debug) { printf("\n"); } - + break; case 'B': /* Byte mode */ /* Mode indicator */ concat(binary, "B"); *byte_used = 1; - + /* Character count indicator */ buffer[0] = short_data_block_length; buffer[1] = '\0'; concat(binary, buffer); - + if(debug) { printf("Byte block (length %d)\n\t", short_data_block_length); } - + /* Character representation */ for(i = 0; i < short_data_block_length; i++) { int byte = jisdata[position + i]; @@ -1245,38 +1245,38 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, qr_bscan(binary, byte, 0x80); if(debug) { printf("0x%4X ", byte); } - + if(strlen(binary) > 128) { return ERROR_TOO_LONG; } } - + if(debug) { printf("\n"); } - + break; case 'A': /* Alphanumeric mode */ /* Mode indicator */ concat(binary, "A"); *alphanum_used = 1; - + /* Character count indicator */ buffer[0] = short_data_block_length; buffer[1] = '\0'; concat(binary, buffer); - + if(debug) { printf("Alpha block (length %d)\n\t", short_data_block_length); } - + /* Character representation */ i = 0; while ( i < short_data_block_length ) { int count; int first = 0, second = 0, prod; - + first = posn(RHODIUM, (char) jisdata[position + i]); count = 1; prod = first; - + if(mode[position + i + 1] == 'A') { second = posn(RHODIUM, (char) jisdata[position + i + 1]); count = 2; @@ -1286,45 +1286,45 @@ int micro_qr_intermediate(char binary[], int jisdata[], char mode[], int length, qr_bscan(binary, prod, 1 << (5 * count)); /* count = 1..2 */ if(debug) { printf("0x%4X ", prod); } - + if(strlen(binary) > 128) { return ERROR_TOO_LONG; } - + i += 2; }; - + if(debug) { printf("\n"); } - + break; case 'N': /* Numeric mode */ /* Mode indicator */ concat(binary, "N"); - + /* Character count indicator */ buffer[0] = short_data_block_length; buffer[1] = '\0'; concat(binary, buffer); - + if(debug) { printf("Number block (length %d)\n\t", short_data_block_length); } - + /* Character representation */ - i = 0; + i = 0; while ( i < short_data_block_length ) { int count; int first = 0, second = 0, third = 0, prod; - + first = posn(NEON, (char) jisdata[position + i]); count = 1; prod = first; - + if(mode[position + i + 1] == 'N') { second = posn(NEON, (char) jisdata[position + i + 1]); count = 2; prod = (prod * 10) + second; } - + if(mode[position + i + 2] == 'N') { third = posn(NEON, (char) jisdata[position + i + 2]); count = 3;