Simplify conversion to binary with common function

No change to functionality
This commit is contained in:
Robin Stuart 2017-05-14 08:15:08 +01:00
parent 19ba8a34c4
commit 19c3755ed0
9 changed files with 321 additions and 733 deletions

View File

@ -69,7 +69,7 @@ static void insert(char binary_string[], const size_t posn, const char newbit) {
* Encode input data into a binary string * Encode input data into a binary string
*/ */
static int aztec_text_process(const unsigned char source[], const unsigned int src_len, char binary_string[], const int gs1, const int eci, int debug) { static int aztec_text_process(const unsigned char source[], const unsigned int src_len, char binary_string[], const int gs1, const int eci, int debug) {
int i, j, k, p, bytes; int i, j, k, bytes;
int curtable, newtable, lasttable, chartype, maplength, blocks; int curtable, newtable, lasttable, chartype, maplength, blocks;
#ifndef _MSC_VER #ifndef _MSC_VER
int charmap[src_len * 2], typemap[src_len * 2]; int charmap[src_len * 2], typemap[src_len * 2];
@ -333,21 +333,21 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case (64 + UPPER): /* To UPPER */ case (64 + UPPER): /* To UPPER */
switch (curtable) { switch (curtable) {
case LOWER: /* US */ case LOWER: /* US */
strcat(binary_string, pentbit[28]); bin_append(28, 5, binary_string);
if (debug) printf("US "); if (debug) printf("US ");
break; break;
case MIXED: /* UL */ case MIXED: /* UL */
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
newtable = UPPER; newtable = UPPER;
break; break;
case PUNC: /* UL */ case PUNC: /* UL */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
newtable = UPPER; newtable = UPPER;
break; break;
case DIGIT: /* US */ case DIGIT: /* US */
strcat(binary_string, quadbit[15]); bin_append(15, 4, binary_string);
if (debug) printf("US "); if (debug) printf("US ");
break; break;
} }
@ -355,26 +355,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case (64 + LOWER): /* To LOWER */ case (64 + LOWER): /* To LOWER */
switch (curtable) { switch (curtable) {
case UPPER: /* LL */ case UPPER: /* LL */
strcat(binary_string, pentbit[28]); case MIXED:
if (debug) printf("LL "); bin_append(28, 5, binary_string);
newtable = LOWER;
break;
case MIXED: /* LL */
strcat(binary_string, pentbit[28]);
if (debug) printf("LL "); if (debug) printf("LL ");
newtable = LOWER; newtable = LOWER;
break; break;
case PUNC: /* UL LL */ case PUNC: /* UL LL */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[28]); bin_append(28, 5, binary_string);
if (debug) printf("LL "); if (debug) printf("LL ");
newtable = LOWER; newtable = LOWER;
break; break;
case DIGIT: /* UL LL */ case DIGIT: /* UL LL */
strcat(binary_string, quadbit[14]); bin_append(14, 4, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[28]); bin_append(28, 5, binary_string);
if (debug) printf("LL "); if (debug) printf("LL ");
newtable = LOWER; newtable = LOWER;
break; break;
@ -383,26 +379,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case (64 + MIXED): /* To MIXED */ case (64 + MIXED): /* To MIXED */
switch (curtable) { switch (curtable) {
case UPPER: /* ML */ case UPPER: /* ML */
strcat(binary_string, pentbit[29]); case LOWER:
if (debug) printf("ML "); bin_append(29, 5, binary_string);
newtable = MIXED;
break;
case LOWER: /* ML */
strcat(binary_string, pentbit[29]);
if (debug) printf("ML "); if (debug) printf("ML ");
newtable = MIXED; newtable = MIXED;
break; break;
case PUNC: /* UL ML */ case PUNC: /* UL ML */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("ML "); if (debug) printf("ML ");
newtable = MIXED; newtable = MIXED;
break; break;
case DIGIT: /* UL ML */ case DIGIT: /* UL ML */
strcat(binary_string, quadbit[14]); bin_append(14, 4, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("ML "); if (debug) printf("ML ");
newtable = MIXED; newtable = MIXED;
break; break;
@ -411,19 +403,10 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case (64 + PUNC): /* To PUNC */ case (64 + PUNC): /* To PUNC */
switch (curtable) { switch (curtable) {
case UPPER: /* PS */ case UPPER: /* PS */
strcat(binary_string, pentbit[0]); case LOWER:
if (debug) printf("PS "); case MIXED:
break; case DIGIT:
case LOWER: /* PS */ bin_append(0, 5, binary_string);
strcat(binary_string, pentbit[0]);
if (debug) printf("PS ");
break;
case MIXED: /* PS */
strcat(binary_string, pentbit[0]);
if (debug) printf("PS ");
break;
case DIGIT: /* PS */
strcat(binary_string, quadbit[0]);
if (debug) printf("PS "); if (debug) printf("PS ");
break; break;
} }
@ -431,26 +414,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case (64 + DIGIT): /* To DIGIT */ case (64 + DIGIT): /* To DIGIT */
switch (curtable) { switch (curtable) {
case UPPER: /* DL */ case UPPER: /* DL */
strcat(binary_string, pentbit[30]); case LOWER:
if (debug) printf("DL "); bin_append(30, 5, binary_string);
newtable = DIGIT;
break;
case LOWER: /* DL */
strcat(binary_string, pentbit[30]);
if (debug) printf("DL "); if (debug) printf("DL ");
newtable = DIGIT; newtable = DIGIT;
break; break;
case MIXED: /* UL DL */ case MIXED: /* UL DL */
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[30]); bin_append(30, 5, binary_string);
if (debug) printf("DL "); if (debug) printf("DL ");
newtable = DIGIT; newtable = DIGIT;
break; break;
case PUNC: /* UL DL */ case PUNC: /* UL DL */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[30]); bin_append(30, 5, binary_string);
if (debug) printf("DL "); if (debug) printf("DL ");
newtable = DIGIT; newtable = DIGIT;
break; break;
@ -463,24 +442,24 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case UPPER: /* To UPPER */ case UPPER: /* To UPPER */
switch (curtable) { switch (curtable) {
case LOWER: /* ML UL */ case LOWER: /* ML UL */
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("ML "); if (debug) printf("ML ");
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
newtable = UPPER; newtable = UPPER;
break; break;
case MIXED: /* UL */ case MIXED: /* UL */
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
newtable = UPPER; newtable = UPPER;
break; break;
case PUNC: /* UL */ case PUNC: /* UL */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
newtable = UPPER; newtable = UPPER;
break; break;
case DIGIT: /* UL */ case DIGIT: /* UL */
strcat(binary_string, quadbit[14]); bin_append(14, 4, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
newtable = UPPER; newtable = UPPER;
break; break;
@ -489,26 +468,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case LOWER: /* To LOWER */ case LOWER: /* To LOWER */
switch (curtable) { switch (curtable) {
case UPPER: /* LL */ case UPPER: /* LL */
strcat(binary_string, pentbit[28]); case MIXED:
if (debug) printf("LL "); bin_append(28, 5, binary_string);
newtable = LOWER;
break;
case MIXED: /* LL */
strcat(binary_string, pentbit[28]);
if (debug) printf("LL "); if (debug) printf("LL ");
newtable = LOWER; newtable = LOWER;
break; break;
case PUNC: /* UL LL */ case PUNC: /* UL LL */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[28]); bin_append(28, 5, binary_string);
if (debug) printf("LL "); if (debug) printf("LL ");
newtable = LOWER; newtable = LOWER;
break; break;
case DIGIT: /* UL LL */ case DIGIT: /* UL LL */
strcat(binary_string, quadbit[14]); bin_append(14, 4, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[28]); bin_append(28, 5, binary_string);
if (debug) printf("LL "); if (debug) printf("LL ");
newtable = LOWER; newtable = LOWER;
break; break;
@ -517,26 +492,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case MIXED: /* To MIXED */ case MIXED: /* To MIXED */
switch (curtable) { switch (curtable) {
case UPPER: /* ML */ case UPPER: /* ML */
strcat(binary_string, pentbit[29]); case LOWER:
if (debug) printf("ML "); bin_append(29, 5, binary_string);
newtable = MIXED;
break;
case LOWER: /* ML */
strcat(binary_string, pentbit[29]);
if (debug) printf("ML "); if (debug) printf("ML ");
newtable = MIXED; newtable = MIXED;
break; break;
case PUNC: /* UL ML */ case PUNC: /* UL ML */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("ML "); if (debug) printf("ML ");
newtable = MIXED; newtable = MIXED;
break; break;
case DIGIT: /* UL ML */ case DIGIT: /* UL ML */
strcat(binary_string, quadbit[14]); bin_append(14, 4, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("ML "); if (debug) printf("ML ");
newtable = MIXED; newtable = MIXED;
break; break;
@ -545,30 +516,24 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case PUNC: /* To PUNC */ case PUNC: /* To PUNC */
switch (curtable) { switch (curtable) {
case UPPER: /* ML PL */ case UPPER: /* ML PL */
strcat(binary_string, pentbit[29]); case LOWER:
bin_append(29, 5, binary_string);
if (debug) printf("ML "); if (debug) printf("ML ");
strcat(binary_string, pentbit[30]); bin_append(30, 5, binary_string);
if (debug) printf("PL ");
newtable = PUNC;
break;
case LOWER: /* ML PL */
strcat(binary_string, pentbit[29]);
if (debug) printf("ML ");
strcat(binary_string, pentbit[30]);
if (debug) printf("PL "); if (debug) printf("PL ");
newtable = PUNC; newtable = PUNC;
break; break;
case MIXED: /* PL */ case MIXED: /* PL */
strcat(binary_string, pentbit[30]); bin_append(30, 5, binary_string);
if (debug) printf("PL "); if (debug) printf("PL ");
newtable = PUNC; newtable = PUNC;
break; break;
case DIGIT: /* UL ML PL */ case DIGIT: /* UL ML PL */
strcat(binary_string, quadbit[14]); bin_append(14, 4, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("ML "); if (debug) printf("ML ");
strcat(binary_string, pentbit[30]); bin_append(30, 5, binary_string);
if (debug) printf("PL "); if (debug) printf("PL ");
newtable = PUNC; newtable = PUNC;
break; break;
@ -577,26 +542,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case DIGIT: /* To DIGIT */ case DIGIT: /* To DIGIT */
switch (curtable) { switch (curtable) {
case UPPER: /* DL */ case UPPER: /* DL */
strcat(binary_string, pentbit[30]); case LOWER:
if (debug) printf("DL "); bin_append(30, 5, binary_string);
newtable = DIGIT;
break;
case LOWER: /* DL */
strcat(binary_string, pentbit[30]);
if (debug) printf("DL "); if (debug) printf("DL ");
newtable = DIGIT; newtable = DIGIT;
break; break;
case MIXED: /* UL DL */ case MIXED: /* UL DL */
strcat(binary_string, pentbit[29]); bin_append(29, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[30]); bin_append(30, 5, binary_string);
if (debug) printf("DL "); if (debug) printf("DL ");
newtable = DIGIT; newtable = DIGIT;
break; break;
case PUNC: /* UL DL */ case PUNC: /* UL DL */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[30]); bin_append(30, 5, binary_string);
if (debug) printf("DL "); if (debug) printf("DL ");
newtable = DIGIT; newtable = DIGIT;
break; break;
@ -606,32 +567,24 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
lasttable = curtable; lasttable = curtable;
switch (curtable) { switch (curtable) {
case UPPER: /* BS */ case UPPER: /* BS */
strcat(binary_string, pentbit[31]); case LOWER:
if (debug) printf("BS "); case MIXED:
newtable = BINARY; bin_append(31, 5, binary_string);
break;
case LOWER: /* BS */
strcat(binary_string, pentbit[31]);
if (debug) printf("BS ");
newtable = BINARY;
break;
case MIXED: /* BS */
strcat(binary_string, pentbit[31]);
if (debug) printf("BS "); if (debug) printf("BS ");
newtable = BINARY; newtable = BINARY;
break; break;
case PUNC: /* UL BS */ case PUNC: /* UL BS */
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("BS "); if (debug) printf("BS ");
lasttable = UPPER; lasttable = UPPER;
newtable = BINARY; newtable = BINARY;
break; break;
case DIGIT: /* UL BS */ case DIGIT: /* UL BS */
strcat(binary_string, quadbit[14]); bin_append(14, 4, binary_string);
if (debug) printf("UL "); if (debug) printf("UL ");
strcat(binary_string, pentbit[31]); bin_append(31, 5, binary_string);
if (debug) printf("BS "); if (debug) printf("BS ");
lasttable = UPPER; lasttable = UPPER;
newtable = BINARY; newtable = BINARY;
@ -650,24 +603,11 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
if (bytes > 31) { if (bytes > 31) {
/* Put 00000 followed by 11-bit number of bytes less 31 */ /* Put 00000 followed by 11-bit number of bytes less 31 */
strcat(binary_string, "00000"); bin_append(0, 5, binary_string);
bin_append(bytes - 31, 11, binary_string);
for (p = 0; p < 11; p++) {
if ((bytes - 31) & (0x400 >> p)) {
strcat(binary_string, "1");
} else {
strcat(binary_string, "0");
}
}
} else { } else {
/* Put 5-bit number of bytes */ /* Put 5-bit number of bytes */
for (p = 0; p < 5; p++) { bin_append(bytes, 5, binary_string);
if (bytes & (0x10 >> p)) {
strcat(binary_string, "1");
} else {
strcat(binary_string, "0");
}
}
} }
if (debug) printf("(%d bytes) ", bytes); if (debug) printf("(%d bytes) ", bytes);
@ -687,29 +627,23 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
case MIXED: case MIXED:
case PUNC: case PUNC:
if ((charmap[i] >= 400) && (charmap[i] < 500)) { if ((charmap[i] >= 400) && (charmap[i] < 500)) {
strcat(binary_string, tribit[charmap[i] - 400]); bin_append(charmap[i] - 400, 3, binary_string);
if (debug) printf("FLG(%d) ", charmap[i] - 400); if (debug) printf("FLG(%d) ", charmap[i] - 400);
} else if (charmap[i] >= 500) { } else if (charmap[i] >= 500) {
strcat(binary_string, quadbit[charmap[i] - 500]); bin_append(charmap[i] - 500, 4, binary_string);
if (debug) printf("[%d] ", charmap[i] - 500); if (debug) printf("[%d] ", charmap[i] - 500);
} else { } else {
strcat(binary_string, pentbit[charmap[i]]); bin_append(charmap[i], 5, binary_string);
if (!((chartype == PUNC) && (charmap[i] == 0))) if (!((chartype == PUNC) && (charmap[i] == 0)))
if (debug) printf("%d ", charmap[i]); if (debug) printf("%d ", charmap[i]);
} }
break; break;
case DIGIT: case DIGIT:
strcat(binary_string, quadbit[charmap[i]]); bin_append(charmap[i], 4, binary_string);
if (debug) printf("%d ", charmap[i]); if (debug) printf("%d ", charmap[i]);
break; break;
case BINARY: case BINARY:
for (p = 0; p < 8; p++) { bin_append(charmap[i], 8, binary_string);
if (charmap[i] & (0x80 >> p)) {
strcat(binary_string, "1");
} else {
strcat(binary_string, "0");
}
}
if (debug) printf("%d ", charmap[i]); if (debug) printf("%d ", charmap[i]);
break; break;
} }

View File

@ -96,21 +96,6 @@ const int AztecSymbolChar[128] = {
302: Full Stop (ASCII 46) 302: Full Stop (ASCII 46)
*/ */
static const char *pentbit[32] = {
"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001",
"01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101",
"10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"
};
static const char *quadbit[16] = {
"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001",
"1010", "1011", "1100", "1101", "1110", "1111"
};
static const char *tribit[8] = {
"000", "001", "010", "011", "100", "101", "110", "111"
};
static const int AztecSizes[32] = { static const int AztecSizes[32] = {
/* Codewords per symbol */ /* Codewords per symbol */
21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790, 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790,

View File

@ -424,7 +424,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
if (j == 21) { if (j == 21) {
next_mode = C1_DECIMAL; next_mode = C1_DECIMAL;
strcpy(decimal_binary, "1111"); bin_append(15, 4, decimal_binary);
} }
} }
@ -448,7 +448,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
if (!(latch)) { if (!(latch)) {
next_mode = C1_DECIMAL; next_mode = C1_DECIMAL;
strcpy(decimal_binary, "1111"); bin_append(15, 4, decimal_binary);
} }
} }
} }
@ -837,7 +837,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
if (current_mode == C1_DECIMAL) { if (current_mode == C1_DECIMAL) {
/* Step F - Decimal encodation */ /* Step F - Decimal encodation */
int value, decimal_count, data_left; int decimal_count, data_left;
next_mode = C1_DECIMAL; next_mode = C1_DECIMAL;
@ -865,7 +865,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
int sub_target; int sub_target;
/* Finish Decimal mode and go back to ASCII */ /* Finish Decimal mode and go back to ASCII */
strcat(decimal_binary, "111111"); /* Unlatch */ bin_append(63, 6, decimal_binary); /* Unlatch */
target_count = 3; target_count = 3;
if (strlen(decimal_binary) <= 16) { if (strlen(decimal_binary) <= 16) {
@ -880,29 +880,20 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
} }
if (bits_left_in_byte == 2) { if (bits_left_in_byte == 2) {
strcat(decimal_binary, "01"); bin_append(1, 2, decimal_binary);
} }
if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) { if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
if (decimal_count >= 1) { if (decimal_count >= 1) {
int sub_value = ctoi(source[sp]) + 1; bin_append(ctoi(source[sp]) + 1, 4, decimal_binary);
for (i = 0x08; i > 0; i = i >> 1) {
if (sub_value & i) {
strcat(decimal_binary, "1");
} else {
strcat(decimal_binary, "0");
}
}
sp++; sp++;
} else { } else {
strcat(decimal_binary, "1111"); bin_append(15, 4, decimal_binary);
} }
} }
if (bits_left_in_byte == 6) { if (bits_left_in_byte == 6) {
strcat(decimal_binary, "01"); bin_append(1, 2, decimal_binary);
} }
/* Binary buffer is full - transfer to target */ /* Binary buffer is full - transfer to target */
@ -943,16 +934,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
next_mode = C1_ASCII; next_mode = C1_ASCII;
} else { } else {
/* There are three digits - convert the value to binary */ /* There are three digits - convert the value to binary */
value = (100 * ctoi(source[sp])) + (10 * ctoi(source[sp + 1])) + ctoi(source[sp + 2]) + 1; bin_append((100 * ctoi(source[sp])) + (10 * ctoi(source[sp + 1])) + ctoi(source[sp + 2]) + 1, 10, decimal_binary);
for (p = 0; p < 10; p++) {
if (value & (0x200 >> p)) {
strcat(decimal_binary, "1");
} else {
strcat(decimal_binary, "0");
}
}
sp += 3; sp += 3;
} }
@ -1088,7 +1070,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
int sub_target; int sub_target;
/* Finish Decimal mode and go back to ASCII */ /* Finish Decimal mode and go back to ASCII */
strcat(decimal_binary, "111111"); /* Unlatch */ bin_append(63, 6, decimal_binary); /* Unlatch */
target_count = 3; target_count = 3;
if (strlen(decimal_binary) <= 16) { if (strlen(decimal_binary) <= 16) {
@ -1103,15 +1085,15 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
} }
if (bits_left_in_byte == 2) { if (bits_left_in_byte == 2) {
strcat(decimal_binary, "01"); bin_append(1, 2, decimal_binary);
} }
if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) { if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
strcat(decimal_binary, "1111"); bin_append(15, 4, decimal_binary);
} }
if (bits_left_in_byte == 6) { if (bits_left_in_byte == 6) {
strcat(decimal_binary, "01"); bin_append(1, 2, decimal_binary);
} }
/* Binary buffer is full - transfer to target */ /* Binary buffer is full - transfer to target */

View File

@ -55,6 +55,25 @@ char itoc(const int source) {
} }
} }
/* Convert an integer value to a string representing its binary equivalent */
void bin_append(const int arg, const int length, char *binary) {
int i;
int start;
int posn = strlen(binary);
start = 0x01 << (length - 1);
for (i = 0; i < length; i++) {
binary[posn + i] = '0';
if (arg & (start >> i)) {
binary[posn + i] = '1';
}
}
binary[posn + length] = '\0';
return;
}
/* Converts lower case characters to upper case in a string source[] */ /* Converts lower case characters to upper case in a string source[] */
void to_upper(unsigned char source[]) { void to_upper(unsigned char source[]) {
size_t i, src_len = ustrlen(source); size_t i, src_len = ustrlen(source);

View File

@ -57,6 +57,7 @@ extern "C" {
extern size_t ustrlen(const unsigned char source[]); extern size_t ustrlen(const unsigned char source[]);
extern int ctoi(const char source); extern int ctoi(const char source);
extern char itoc(const int source); extern char itoc(const int source);
extern void bin_append(const int arg, const int length, char *binary);
extern void to_upper(unsigned char source[]); extern void to_upper(unsigned char source[]);
extern int is_sane(const char test_string[], const unsigned char source[], const size_t length); extern int is_sane(const char test_string[], const unsigned char source[], const size_t length);
extern void lookup(const char set_string[], const char *table[], const char data, char dest[]); extern void lookup(const char set_string[], const char *table[], const char data, char dest[]);

View File

@ -924,36 +924,16 @@ int dotcode_encode_message(struct zint_symbol *symbol, const unsigned char sourc
/* Convert codewords to binary data stream */ /* Convert codewords to binary data stream */
static size_t make_dotstream(unsigned char masked_array[], int array_length, char dot_stream[]) { static size_t make_dotstream(unsigned char masked_array[], int array_length, char dot_stream[]) {
int i, j; int i;
int mask = 0x100;
dot_stream[0] = '\0'; dot_stream[0] = '\0';
/* Mask value is encoded as two dots */ /* Mask value is encoded as two dots */
switch (masked_array[0]) { bin_append(masked_array[0], 2, dot_stream);
case 0:
strcat(dot_stream, "00");
break;
case 1:
strcat(dot_stream, "01");
break;
case 2:
strcat(dot_stream, "10");
break;
case 3:
strcat(dot_stream, "11");
break;
}
/* The rest of the data uses 9-bit dot patterns from Annex C */ /* The rest of the data uses 9-bit dot patterns from Annex C */
for (i = 1; i < array_length; i++) { for (i = 1; i < array_length; i++) {
for (j = 0; j < 9; j++) { bin_append(dot_patterns[masked_array[i]], 9, dot_stream);
if (dot_patterns[masked_array[i]] & (mask >> j)) {
strcat(dot_stream, "1");
} else {
strcat(dot_stream, "0");
}
}
} }
return strlen(dot_stream); return strlen(dot_stream);

View File

@ -314,7 +314,7 @@ int seek_forward(int gbdata[], int length, int position, int current_mode) {
/* Add the length indicator for byte encoded blocks */ /* Add the length indicator for byte encoded blocks */
static void add_byte_count(char binary[], const size_t byte_count_posn, const int byte_count) { static void add_byte_count(char binary[], const size_t byte_count_posn, const int byte_count) {
int p; int p;
for (p = 0; p < 8; p++) { for (p = 0; p < 8; p++) {
if (byte_count & (0x100 >> p)) { if (byte_count & (0x100 >> p)) {
binary[byte_count_posn + p] = '0'; binary[byte_count_posn + p] = '0';
@ -326,7 +326,7 @@ static void add_byte_count(char binary[], const size_t byte_count_posn, const in
/* Add a control character to the data stream */ /* Add a control character to the data stream */
void add_shift_char(char binary[], int shifty) { void add_shift_char(char binary[], int shifty) {
int i, p, debug = 0; int i, debug = 0;
int glyph = 0; int glyph = 0;
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
@ -339,26 +339,20 @@ void add_shift_char(char binary[], int shifty) {
printf("SHIFT [%d] ", glyph); printf("SHIFT [%d] ", glyph);
} }
for (p = 0; p < 6; p++) { bin_append(glyph, 6, binary);
if (glyph & (0x20 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
} }
int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int debug) { int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int debug) {
/* Create a binary stream representation of the input data. /* Create a binary stream representation of the input data.
7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters, 7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters,
Mixed numerals and latters, Control characters and 8-bit binary data */ Mixed numerals and latters, Control characters and 8-bit binary data */
int sp, current_mode, next_mode, last_mode, glyph = 0, q; int sp, current_mode, next_mode, last_mode, glyph = 0;
int c1, c2, done; int c1, c2, done;
int p = 0, ppos; int p = 0, ppos;
int numbuf[3], punt = 0; int numbuf[3], punt = 0;
size_t number_pad_posn, byte_count_posn = 0; size_t number_pad_posn, byte_count_posn = 0;
int byte_count = 0; int byte_count = 0;
int shift, i; int shift;
strcpy(binary, ""); strcpy(binary, "");
@ -368,18 +362,12 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
number_pad_posn = 0; number_pad_posn = 0;
if (reader) { if (reader) {
strcat(binary, "1010"); /* FNC3 - Reader Initialisation */ bin_append(10, 4, binary); /* FNC3 - Reader Initialisation */
} }
if (eci != 3) { if (eci != 3) {
strcat(binary, "11000"); /* ECI */ bin_append(24, 5, binary); /* ECI */
for (q = 0; q < 10; q++) { bin_append(eci, 10, binary);
if (eci & (0x100 >> q)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
} }
do { do {
@ -389,32 +377,32 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
switch (current_mode) { switch (current_mode) {
case 0: case 0:
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: strcat(binary, "0001"); case GM_CHINESE: bin_append(1, 4, binary);
break; break;
case GM_NUMBER: strcat(binary, "0010"); case GM_NUMBER: bin_append(2, 4, binary);
break; break;
case GM_LOWER: strcat(binary, "0011"); case GM_LOWER: bin_append(3, 4, binary);
break; break;
case GM_UPPER: strcat(binary, "0100"); case GM_UPPER: bin_append(4, 4, binary);
break; break;
case GM_MIXED: strcat(binary, "0101"); case GM_MIXED: bin_append(5, 4, binary);
break; break;
case GM_BYTE: strcat(binary, "0111"); case GM_BYTE: bin_append(6, 4, binary);
break; break;
} }
break; break;
case GM_CHINESE: case GM_CHINESE:
switch (next_mode) { switch (next_mode) {
case GM_NUMBER: strcat(binary, "1111111100001"); case GM_NUMBER: bin_append(8161, 13, binary);
break; // 8161 break;
case GM_LOWER: strcat(binary, "1111111100010"); case GM_LOWER: bin_append(8162, 13, binary);
break; // 8162 break;
case GM_UPPER: strcat(binary, "1111111100011"); case GM_UPPER: bin_append(8163, 13, binary);
break; // 8163 break;
case GM_MIXED: strcat(binary, "1111111100100"); case GM_MIXED: bin_append(8164, 13, binary);
break; // 8164 break;
case GM_BYTE: strcat(binary, "1111111100101"); case GM_BYTE: bin_append(8165, 13, binary);
break; // 8165 break;
} }
break; break;
case GM_NUMBER: case GM_NUMBER:
@ -425,52 +413,52 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
break; // 2 pad digits break; // 2 pad digits
case 2: binary[number_pad_posn] = '0'; case 2: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '1'; binary[number_pad_posn + 1] = '1';
break; // 1 pad digit break; // 1 pad digits
case 3: binary[number_pad_posn] = '0'; case 3: binary[number_pad_posn] = '0';
binary[number_pad_posn + 1] = '0'; binary[number_pad_posn + 1] = '0';
break; // 0 pad digits break; // 0 pad digits
} }
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: strcat(binary, "1111111011"); case GM_CHINESE: bin_append(1019, 10, binary);
break; // 1019 break;
case GM_LOWER: strcat(binary, "1111111100"); case GM_LOWER: bin_append(1020, 10, binary);
break; // 1020 break;
case GM_UPPER: strcat(binary, "1111111101"); case GM_UPPER: bin_append(1021, 10, binary);
break; // 1021 break;
case GM_MIXED: strcat(binary, "1111111110"); case GM_MIXED: bin_append(1022, 10, binary);
break; // 1022 break;
case GM_BYTE: strcat(binary, "1111111111"); case GM_BYTE: bin_append(1023, 10, binary);
break; // 1023 break;
} }
break; break;
case GM_LOWER: case GM_LOWER:
case GM_UPPER: case GM_UPPER:
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: strcat(binary, "11100"); case GM_CHINESE: bin_append(28, 5, binary);
break; // 28 break;
case GM_NUMBER: strcat(binary, "11101"); case GM_NUMBER: bin_append(29, 5, binary);
break; // 29 break;
case GM_LOWER: case GM_LOWER:
case GM_UPPER: strcat(binary, "11110"); case GM_UPPER: bin_append(30, 5, binary);
break; // 30 break;
case GM_MIXED: strcat(binary, "1111100"); case GM_MIXED: bin_append(124, 7, binary);
break; // 124 break;
case GM_BYTE: strcat(binary, "1111110"); case GM_BYTE: bin_append(126, 7, binary);
break; // 126 break;
} }
break; break;
case GM_MIXED: case GM_MIXED:
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: strcat(binary, "1111110001"); case GM_CHINESE: bin_append(1009, 10, binary);
break; // 1009 break;
case GM_NUMBER: strcat(binary, "1111110010"); case GM_NUMBER: bin_append(1010, 10, binary);
break; // 1010 break;
case GM_LOWER: strcat(binary, "1111110011"); case GM_LOWER: bin_append(1011, 10, binary);
break; // 1011 break;
case GM_UPPER: strcat(binary, "1111110100"); case GM_UPPER: bin_append(1012, 10, binary);
break; // 1012 break;
case GM_BYTE: strcat(binary, "1111110111"); case GM_BYTE: bin_append(1015, 10, binary);
break; // 1015 break;
} }
break; break;
case GM_BYTE: case GM_BYTE:
@ -478,16 +466,16 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
add_byte_count(binary, byte_count_posn, byte_count); add_byte_count(binary, byte_count_posn, byte_count);
byte_count = 0; byte_count = 0;
switch (next_mode) { switch (next_mode) {
case GM_CHINESE: strcat(binary, "0001"); case GM_CHINESE: bin_append(1, 4, binary);
break; // 1 break;
case GM_NUMBER: strcat(binary, "0010"); case GM_NUMBER: bin_append(2, 4, binary);
break; // 2 break;
case GM_LOWER: strcat(binary, "0011"); case GM_LOWER: bin_append(3, 4, binary);
break; // 3 break;
case GM_UPPER: strcat(binary, "0100"); case GM_UPPER: bin_append(4, 4, binary);
break; // 4 break;
case GM_MIXED: strcat(binary, "0101"); case GM_MIXED: bin_append(5, 4, binary);
break; // 5 break;
} }
break; break;
} }
@ -556,13 +544,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
for (q = 0; q < 13; q++) { bin_append(glyph, 13, binary);
if (glyph & (0x1000 >> q)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
sp++; sp++;
break; break;
@ -630,13 +612,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
for (q = 0; q < 10; q++) { bin_append(glyph, 10, binary);
if (glyph & (0x200 >> q)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
} }
glyph = (100 * (numbuf[0] - '0')) + (10 * (numbuf[1] - '0')) + (numbuf[2] - '0'); glyph = (100 * (numbuf[0] - '0')) + (10 * (numbuf[1] - '0')) + (numbuf[2] - '0');
@ -644,13 +620,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
for (q = 0; q < 10; q++) { bin_append(glyph, 10, binary);
if (glyph & (0x200 >> q)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
break; break;
case GM_BYTE: case GM_BYTE:
@ -662,7 +632,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
if (byte_count == 512) { if (byte_count == 512) {
/* Maximum byte block size is 512 bytes. If longer is needed then start a new block */ /* Maximum byte block size is 512 bytes. If longer is needed then start a new block */
add_byte_count(binary, byte_count_posn, byte_count); add_byte_count(binary, byte_count_posn, byte_count);
strcat(binary, "0111"); bin_append(7, 4, binary);
byte_count_posn = strlen(binary); byte_count_posn = strlen(binary);
strcat(binary, "LLLLLLLLL"); strcat(binary, "LLLLLLLLL");
byte_count = 0; byte_count = 0;
@ -672,13 +642,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
if (debug) { if (debug) {
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
for (q = 0; q < 8; q++) { bin_append(glyph, 8, binary);
if (glyph & (0x80 >> q)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
sp++; sp++;
byte_count++; byte_count++;
break; break;
@ -705,16 +669,10 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
for (q = 0; q < 6; q++) { bin_append(glyph, 6, binary);
if (glyph & (0x20 >> q)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
} else { } else {
/* Shift Mode character */ /* Shift Mode character */
strcat(binary, "1111110110"); /* 1014 - shift indicator */ bin_append(1014, 10, binary); /* shift indicator */
add_shift_char(binary, gbdata[sp]); add_shift_char(binary, gbdata[sp]);
} }
@ -737,16 +695,10 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
for (q = 0; q < 5; q++) { bin_append(glyph, 5, binary);
if (glyph & (0x10 >> q)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
} else { } else {
/* Shift Mode character */ /* Shift Mode character */
strcat(binary, "1111101"); /* 127 - shift indicator */ bin_append(125, 7, binary); /* shift indicator */
add_shift_char(binary, gbdata[sp]); add_shift_char(binary, gbdata[sp]);
} }
@ -768,17 +720,11 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
if (debug) { if (debug) {
printf("[%d] ", glyph); printf("[%d] ", glyph);
} }
for (q = 0; q < 5; q++) { bin_append(glyph, 5, binary);
if (glyph & (0x10 >> q)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
} else { } else {
/* Shift Mode character */ /* Shift Mode character */
strcat(binary, "1111101"); /* 127 - shift indicator */ bin_append(125, 7, binary); /* shift indicator */
add_shift_char(binary, gbdata[sp]); add_shift_char(binary, gbdata[sp]);
} }
@ -813,17 +759,17 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
/* Add "end of data" character */ /* Add "end of data" character */
switch (current_mode) { switch (current_mode) {
case GM_CHINESE: strcat(binary, "1111111100000"); case GM_CHINESE: bin_append(8160, 13, binary);
break; // 8160 break;
case GM_NUMBER: strcat(binary, "1111111010"); case GM_NUMBER: bin_append(1018, 10, binary);
break; // 1018 break;
case GM_LOWER: case GM_LOWER:
case GM_UPPER: strcat(binary, "11011"); case GM_UPPER: bin_append(27, 5, binary);
break; // 27 break;
case GM_MIXED: strcat(binary, "1111110000"); case GM_MIXED: bin_append(1008, 10, binary);
break; // 1008 break;
case GM_BYTE: strcat(binary, "0000"); case GM_BYTE: bin_append(0, 4, binary);
break; // 0 break;
} }
/* Add padding bits if required */ /* Add padding bits if required */
@ -831,9 +777,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
if (p == 7) { if (p == 7) {
p = 0; p = 0;
} }
for (i = 0; i < p; i++) { bin_append(0, p, binary);
strcat(binary, "0");
}
if (strlen(binary) > 9191) { if (strlen(binary) > 9191) {
return ZINT_ERROR_TOO_LONG; return ZINT_ERROR_TOO_LONG;

View File

@ -331,21 +331,15 @@ int lookup_text2(char input) {
void calculate_binary(char binary[], char mode[], int source[], int length, int eci, int debug) { void calculate_binary(char binary[], char mode[], int source[], int length, int eci, int debug) {
int block_length; int block_length;
int position = 0; int position = 0;
int i, p, count, encoding_value; int i, count, encoding_value;
int first_byte, second_byte; int first_byte, second_byte;
int third_byte, fourth_byte; int third_byte, fourth_byte;
int glyph; int glyph;
int submode; int submode;
if (eci != 3) { if (eci != 3) {
strcat(binary, "1000"); // ECI bin_append(8, 4, binary); // ECI
for (p = 0; p < 8; p++) { bin_append(eci, 8, binary);
if (eci & (0x80 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
} }
do { do {
@ -358,7 +352,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
case 'n': case 'n':
/* Numeric mode */ /* Numeric mode */
/* Mode indicator */ /* Mode indicator */
strcat(binary, "0001"); bin_append(1, 4, binary);
if (debug) { if (debug) {
printf("Numeric\n"); printf("Numeric\n");
@ -385,13 +379,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
} }
} }
for (p = 0; p < 10; p++) { bin_append(encoding_value, 10, binary);
if (encoding_value & (0x200 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
if (debug) { if (debug) {
printf("0x%4x (%d)", encoding_value, encoding_value); printf("0x%4x (%d)", encoding_value, encoding_value);
@ -403,13 +391,13 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
/* Mode terminator depends on number of characters in last group (Table 2) */ /* Mode terminator depends on number of characters in last group (Table 2) */
switch (count) { switch (count) {
case 1: case 1:
strcat(binary, "1111111101"); bin_append(1021, 10, binary);
break; break;
case 2: case 2:
strcat(binary, "1111111110"); bin_append(1022, 10, binary);
break; break;
case 3: case 3:
strcat(binary, "1111111111"); bin_append(1023, 10, binary);
break; break;
} }
@ -422,7 +410,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
/* Text mode */ /* Text mode */
if (position != 0) { if (position != 0) {
/* Mode indicator */ /* Mode indicator */
strcat(binary, "0010"); bin_append(2, 4, binary);
if (debug) { if (debug) {
printf("Text\n"); printf("Text\n");
@ -437,7 +425,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
if (getsubmode((char) source[i + position]) != submode) { if (getsubmode((char) source[i + position]) != submode) {
/* Change submode */ /* Change submode */
strcat(binary, "111110"); bin_append(62, 6, binary);
submode = getsubmode((char) source[i + position]); submode = getsubmode((char) source[i + position]);
if (debug) { if (debug) {
printf("SWITCH "); printf("SWITCH ");
@ -450,13 +438,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
encoding_value = lookup_text2((char) source[i + position]); encoding_value = lookup_text2((char) source[i + position]);
} }
for (p = 0; p < 6; p++) { bin_append(encoding_value, 6, binary);
if (encoding_value & (0x20 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
if (debug) { if (debug) {
printf("%c (%d) ", (char) source[i], encoding_value); printf("%c (%d) ", (char) source[i], encoding_value);
@ -465,7 +447,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
} }
/* Terminator */ /* Terminator */
strcat(binary, "111111"); bin_append(63, 6, binary);
if (debug) { if (debug) {
printf("\n"); printf("\n");
@ -474,16 +456,10 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
case 'b': case 'b':
/* Binary Mode */ /* Binary Mode */
/* Mode indicator */ /* Mode indicator */
strcat(binary, "0011"); bin_append(3, 4, binary);
/* Count indicator */ /* Count indicator */
for (p = 0; p < 13; p++) { bin_append(block_length, 13, binary);
if (block_length & (0x1000 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
if (debug) { if (debug) {
printf("Binary (length %d)\n", block_length); printf("Binary (length %d)\n", block_length);
@ -494,13 +470,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
while (i < block_length) { while (i < block_length) {
/* 8-bit bytes with no conversion */ /* 8-bit bytes with no conversion */
for (p = 0; p < 8; p++) { bin_append(source[i + position], 8, binary);
if (source[i + position] & (0x80 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
if (debug) { if (debug) {
printf("%d ", source[i + position]); printf("%d ", source[i + position]);
@ -516,7 +486,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
case '1': case '1':
/* Region 1 encoding */ /* Region 1 encoding */
/* Mode indicator */ /* Mode indicator */
strcat(binary, "0100"); bin_append(4, 4, binary);
if (debug) { if (debug) {
printf("Region 1\n"); printf("Region 1\n");
@ -547,19 +517,12 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
printf("%d ", glyph); printf("%d ", glyph);
} }
for (p = 0; p < 12; p++) { bin_append(glyph, 12, binary);
if (glyph & (0x800 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
i++; i++;
} }
/* Terminator */ /* Terminator */
strcat(binary, "111111111111"); bin_append(4095, 12, binary);
if (debug) { if (debug) {
printf("\n"); printf("\n");
@ -569,7 +532,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
case '2': case '2':
/* Region 2 encoding */ /* Region 2 encoding */
/* Mode indicator */ /* Mode indicator */
strcat(binary, "0101"); bin_append(5, 4, binary);
if (debug) { if (debug) {
printf("Region 2\n"); printf("Region 2\n");
@ -587,19 +550,12 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
printf("%d ", glyph); printf("%d ", glyph);
} }
for (p = 0; p < 12; p++) { bin_append(glyph, 12, binary);
if (glyph & (0x800 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
i++; i++;
} }
/* Terminator */ /* Terminator */
strcat(binary, "111111111111"); bin_append(4095, 12, binary);
if (debug) { if (debug) {
printf("\n"); printf("\n");
@ -608,7 +564,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
case 'd': case 'd':
/* Double byte encoding */ /* Double byte encoding */
/* Mode indicator */ /* Mode indicator */
strcat(binary, "0110"); bin_append(6, 4, binary);
if (debug) { if (debug) {
printf("Double byte\n"); printf("Double byte\n");
@ -630,19 +586,12 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
printf("%d ", glyph); printf("%d ", glyph);
} }
for (p = 0; p < 15; p++) { bin_append(glyph, 15, binary);
if (glyph & (0x4000 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
i++; i++;
} }
/* Terminator */ /* Terminator */
strcat(binary, "111111111111111"); bin_append(32767, 15, binary);
/* Terminator sequence of length 12 is a mistake /* Terminator sequence of length 12 is a mistake
- confirmed by Wang Yi */ - confirmed by Wang Yi */
@ -661,7 +610,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
while (i < block_length) { while (i < block_length) {
/* Mode indicator */ /* Mode indicator */
strcat(binary, "0111"); bin_append(7, 4, binary);
first_byte = (source[i + position] & 0xff00) >> 8; first_byte = (source[i + position] & 0xff00) >> 8;
second_byte = source[i + position] & 0xff; second_byte = source[i + position] & 0xff;
@ -675,14 +624,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
printf("%d ", glyph); printf("%d ", glyph);
} }
for (p = 0; p < 15; p++) { bin_append(glyph, 15, binary);
if (glyph & (0x4000 >> p)) {
strcat(binary, "1");
} else {
strcat(binary, "0");
}
}
i += 2; i += 2;
} }

View File

@ -1169,7 +1169,7 @@ int general_rules(char field[], char type[]) {
/* Handles all data encodation from section 7.2.5 of ISO/IEC 24724 */ /* Handles all data encodation from section 7.2.5 of ISO/IEC 24724 */
int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_string[]) { int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_string[]) {
int encoding_method, i, mask, j, read_posn, latch, debug = symbol->debug, last_mode = ISOIEC; int encoding_method, i, j, read_posn, latch, debug = symbol->debug, last_mode = ISOIEC;
int symbol_characters, characters_per_row; int symbol_characters, characters_per_row;
#ifndef _MSC_VER #ifndef _MSC_VER
char general_field[strlen(source) + 1], general_field_type[strlen(source) + 1]; char general_field[strlen(source) + 1], general_field_type[strlen(source) + 1];
@ -1177,11 +1177,10 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
char* general_field = (char*) _alloca(strlen(source) + 1); char* general_field = (char*) _alloca(strlen(source) + 1);
char* general_field_type = (char*) _alloca(strlen(source) + 1); char* general_field_type = (char*) _alloca(strlen(source) + 1);
#endif #endif
int remainder, d1, d2, value; int remainder, d1, d2;
char padstring[40]; char padstring[40];
read_posn = 0; read_posn = 0;
value = 0;
/* Decide whether a compressed data field is required and if so what /* Decide whether a compressed data field is required and if so what
method to use - method 2 = no compressed data field */ method to use - method 2 = no compressed data field */
@ -1335,10 +1334,9 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
case 2: strcat(binary_string, "00XX"); case 2: strcat(binary_string, "00XX");
read_posn = 0; read_posn = 0;
break; break;
case 3: strcat(binary_string, "0100"); case 3: // 0100
read_posn = strlen(source); case 4: // 0101
break; bin_append(4 + (encoding_method - 3), 4, binary_string);
case 4: strcat(binary_string, "0101");
read_posn = strlen(source); read_posn = strlen(source);
break; break;
case 5: strcat(binary_string, "01100XX"); case 5: strcat(binary_string, "01100XX");
@ -1347,28 +1345,8 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
case 6: strcat(binary_string, "01101XX"); case 6: strcat(binary_string, "01101XX");
read_posn = 23; read_posn = 23;
break; break;
case 7: strcat(binary_string, "0111000"); default: /* modes 7 to 14 */
read_posn = strlen(source); bin_append(56 + (encoding_method - 7), 7, binary_string);
break;
case 8: strcat(binary_string, "0111001");
read_posn = strlen(source);
break;
case 9: strcat(binary_string, "0111010");
read_posn = strlen(source);
break;
case 10: strcat(binary_string, "0111011");
read_posn = strlen(source);
break;
case 11: strcat(binary_string, "0111100");
read_posn = strlen(source);
break;
case 12: strcat(binary_string, "0111101");
read_posn = strlen(source);
break;
case 13: strcat(binary_string, "0111110");
read_posn = strlen(source);
break;
case 14: strcat(binary_string, "0111111");
read_posn = strlen(source); read_posn = strlen(source);
break; break;
} }
@ -1395,73 +1373,28 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
if (encoding_method == 1) { if (encoding_method == 1) {
/* Encoding method field "1" - general item identification data */ /* Encoding method field "1" - general item identification data */
char group[4]; char group[4];
int group_val;
group[0] = source[2]; group[0] = source[2];
group[1] = '\0'; group[1] = '\0';
group_val = atoi(group);
mask = 0x08; bin_append(atoi(group), 4, binary_string);
for (j = 0; j < 4; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
for (i = 1; i < 5; i++) { for (i = 1; i < 5; i++) {
group[0] = source[(i * 3)]; group[0] = source[(i * 3)];
group[1] = source[(i * 3) + 1]; group[1] = source[(i * 3) + 1];
group[2] = source[(i * 3) + 2]; group[2] = source[(i * 3) + 2];
group[3] = '\0'; group[3] = '\0';
group_val = atoi(group);
mask = 0x200; bin_append(atoi(group), 10, binary_string);
for (j = 0; j < 10; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
} }
if ((encoding_method == 3) || (encoding_method == 4)) {
if (encoding_method == 3) {
/* Encoding method field "0100" - variable weight item /* Encoding method field "0100" - variable weight item
(0,001 kilogram icrements) */ (0,001 kilogram icrements) */
char group[4];
int group_val;
char weight_str[7];
for (i = 1; i < 5; i++) {
group[0] = source[(i * 3)];
group[1] = source[(i * 3) + 1];
group[2] = source[(i * 3) + 2];
group[3] = '\0';
group_val = atoi(group);
mask = 0x200;
for (j = 0; j < 10; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
}
for (i = 0; i < 6; i++) {
weight_str[i] = source[20 + i];
}
weight_str[6] = '\0';
group_val = atoi(weight_str);
mask = 0x4000;
for (j = 0; j < 15; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
}
if (encoding_method == 4) {
/* Encoding method field "0101" - variable weight item (0,01 or /* Encoding method field "0101" - variable weight item (0,01 or
0,001 pound increment) */ 0,001 pound increment) */
char group[4]; char group[4];
int group_val;
char weight_str[7]; char weight_str[7];
for (i = 1; i < 5; i++) { for (i = 1; i < 5; i++) {
@ -1469,32 +1402,51 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
group[1] = source[(i * 3) + 1]; group[1] = source[(i * 3) + 1];
group[2] = source[(i * 3) + 2]; group[2] = source[(i * 3) + 2];
group[3] = '\0'; group[3] = '\0';
group_val = atoi(group);
mask = 0x200; bin_append(atoi(group), 10, binary_string);
for (j = 0; j < 10; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
weight_str[i] = source[20 + i]; weight_str[i] = source[20 + i];
} }
weight_str[6] = '\0'; weight_str[6] = '\0';
group_val = atoi(weight_str);
if (source[19] == '3') { if ((encoding_method == 4) && (source[19] == '3')) {
group_val = group_val + 10000; bin_append(atoi(weight_str) + 10000, 15, binary_string);
} } else {
bin_append(atoi(weight_str), 15, binary_string);
mask = 0x4000;
for (j = 0; j < 15; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
} }
} }
if ((encoding_method == 5) || (encoding_method == 6)) {
/* Encoding method "01100" - variable measure item and price */
/* Encoding method "01101" - variable measure item and price with ISO 4217
Currency Code */
char group[4];
for (i = 1; i < 5; i++) {
group[0] = source[(i * 3)];
group[1] = source[(i * 3) + 1];
group[2] = source[(i * 3) + 2];
group[3] = '\0';
bin_append(atoi(group), 10, binary_string);
}
bin_append(source[19] - '0', 2, binary_string);
if (encoding_method == 6) {
char currency_str[5];
for (i = 0; i < 3; i++) {
currency_str[i] = source[20 + i];
}
currency_str[3] = '\0';
bin_append(atoi(currency_str), 10, binary_string);
}
}
if ((encoding_method >= 7) && (encoding_method <= 14)) { if ((encoding_method >= 7) && (encoding_method <= 14)) {
/* Encoding method fields "0111000" through "0111111" - variable /* Encoding method fields "0111000" through "0111111" - variable
@ -1509,13 +1461,8 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
group[1] = source[(i * 3) + 1]; group[1] = source[(i * 3) + 1];
group[2] = source[(i * 3) + 2]; group[2] = source[(i * 3) + 2];
group[3] = '\0'; group[3] = '\0';
group_val = atoi(group);
bin_append(atoi(group), 10, binary_string);
mask = 0x200;
for (j = 0; j < 10; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
weight_str[0] = source[19]; weight_str[0] = source[19];
@ -1524,13 +1471,8 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
weight_str[i + 1] = source[21 + i]; weight_str[i + 1] = source[21 + i];
} }
weight_str[6] = '\0'; weight_str[6] = '\0';
group_val = atoi(weight_str);
bin_append(atoi(weight_str), 20, binary_string);
mask = 0x80000;
for (j = 0; j < 20; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
if (strlen(source) == 34) { if (strlen(source) == 34) {
/* Date information is included */ /* Date information is included */
@ -1550,88 +1492,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
group_val = 38400; group_val = 38400;
} }
mask = 0x8000; bin_append(group_val, 16, binary_string);
for (j = 0; j < 16; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
}
if (encoding_method == 5) {
/* Encoding method field "01100" - variable measure item and price */
char group[4];
int group_val;
for (i = 1; i < 5; i++) {
group[0] = source[(i * 3)];
group[1] = source[(i * 3) + 1];
group[2] = source[(i * 3) + 2];
group[3] = '\0';
group_val = atoi(group);
mask = 0x200;
for (j = 0; j < 10; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
}
switch (source[19]) {
case '0': strcat(binary_string, "00");
break;
case '1': strcat(binary_string, "01");
break;
case '2': strcat(binary_string, "10");
break;
case '3': strcat(binary_string, "11");
break;
}
}
if (encoding_method == 6) {
/* Encoding method "01101" - variable measure item and price with ISO 4217
Currency Code */
char group[4];
int group_val;
char currency_str[5];
for (i = 1; i < 5; i++) {
group[0] = source[(i * 3)];
group[1] = source[(i * 3) + 1];
group[2] = source[(i * 3) + 2];
group[3] = '\0';
group_val = atoi(group);
mask = 0x200;
for (j = 0; j < 10; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
}
switch (source[19]) {
case '0': strcat(binary_string, "00");
break;
case '1': strcat(binary_string, "01");
break;
case '2': strcat(binary_string, "10");
break;
case '3': strcat(binary_string, "11");
break;
}
for (i = 0; i < 3; i++) {
currency_str[i] = source[20 + i];
}
currency_str[3] = '\0';
group_val = atoi(currency_str);
mask = 0x200;
for (j = 0; j < 10; j++) {
strcat(binary_string, (group_val & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
/* The compressed data field has been processed if appropriate - the /* The compressed data field has been processed if appropriate - the
@ -1738,12 +1599,12 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
/* Set initial mode if not NUMERIC */ /* Set initial mode if not NUMERIC */
if (general_field_type[0] == ALPHA) { if (general_field_type[0] == ALPHA) {
strcat(binary_string, "0000"); /* Alphanumeric latch */ bin_append(0, 4, binary_string); /* Alphanumeric latch */
last_mode = ALPHA; last_mode = ALPHA;
} }
if (general_field_type[0] == ISOIEC) { if (general_field_type[0] == ISOIEC) {
strcat(binary_string, "0000"); /* Alphanumeric latch */ bin_append(0, 4, binary_string); /* Alphanumeric latch */
strcat(binary_string, "00100"); /* ISO/IEC 646 latch */ bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */
last_mode = ISOIEC; last_mode = ISOIEC;
} }
@ -1755,7 +1616,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
if (debug) printf("as NUMERIC:"); if (debug) printf("as NUMERIC:");
if (last_mode != NUMERIC) { if (last_mode != NUMERIC) {
strcat(binary_string, "000"); /* Numeric latch */ bin_append(0, 3, binary_string); /* Numeric latch */
if (debug) printf("<NUMERIC LATCH>\n"); if (debug) printf("<NUMERIC LATCH>\n");
} }
@ -1772,16 +1633,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
d2 = 10; d2 = 10;
} }
value = (11 * d1) + d2 + 8; bin_append((11 * d1) + d2 + 8, 7, binary_string);
mask = 0x40;
for (j = 0; j < 7; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
if (debug) {
printf("%d", !!(value & mask));
}
mask = mask >> 1;
}
i += 2; i += 2;
if (debug) printf("\n"); if (debug) printf("\n");
@ -1792,45 +1644,33 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
if (debug) printf("as ALPHA\n"); if (debug) printf("as ALPHA\n");
if (i != 0) { if (i != 0) {
if (last_mode == NUMERIC) { if (last_mode == NUMERIC) {
strcat(binary_string, "0000"); /* Alphanumeric latch */ bin_append(0, 4, binary_string); /* Alphanumeric latch */
} }
if (last_mode == ISOIEC) { if (last_mode == ISOIEC) {
strcat(binary_string, "00100"); /* Alphanumeric latch */ bin_append(4, 5, binary_string); /* Alphanumeric latch */
} }
} }
if ((general_field[i] >= '0') && (general_field[i] <= '9')) { if ((general_field[i] >= '0') && (general_field[i] <= '9')) {
bin_append(general_field[i] - 43, 5, binary_string);
value = general_field[i] - 43;
mask = 0x10;
for (j = 0; j < 5; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) { if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
bin_append(general_field[i] - 33, 6, binary_string);
value = general_field[i] - 33;
mask = 0x20;
for (j = 0; j < 6; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
last_mode = ALPHA; last_mode = ALPHA;
if (general_field[i] == '[') { if (general_field[i] == '[') {
strcat(binary_string, "01111"); bin_append(15, 5, binary_string);
last_mode = NUMERIC; last_mode = NUMERIC;
} /* FNC1/Numeric latch */ } /* FNC1/Numeric latch */
if (general_field[i] == '*') strcat(binary_string, "111010"); /* asterisk */
if (general_field[i] == ',') strcat(binary_string, "111011"); /* comma */ if (general_field[i] == '*') bin_append(58, 6, binary_string); /* asterisk */
if (general_field[i] == '-') strcat(binary_string, "111100"); /* minus or hyphen */ if (general_field[i] == ',') bin_append(59, 6, binary_string); /* comma */
if (general_field[i] == '.') strcat(binary_string, "111101"); /* period or full stop */ if (general_field[i] == '-') bin_append(60, 6, binary_string); /* minus or hyphen */
if (general_field[i] == '/') strcat(binary_string, "111110"); /* slash or solidus */ if (general_field[i] == '.') bin_append(61, 6, binary_string); /* period or full stop */
if (general_field[i] == '/') bin_append(62, 6, binary_string); /* slash or solidus */
i++; i++;
break; break;
@ -1839,73 +1679,53 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
if (debug) printf("as ISOIEC\n"); if (debug) printf("as ISOIEC\n");
if (i != 0) { if (i != 0) {
if (last_mode == NUMERIC) { if (last_mode == NUMERIC) {
strcat(binary_string, "0000"); /* Alphanumeric latch */ bin_append(0, 4, binary_string); /* Alphanumeric latch */
strcat(binary_string, "00100"); /* ISO/IEC 646 latch */ bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */
} }
if (last_mode == ALPHA) { if (last_mode == ALPHA) {
strcat(binary_string, "00100"); /* ISO/IEC 646 latch */ bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */
} }
} }
if ((general_field[i] >= '0') && (general_field[i] <= '9')) { if ((general_field[i] >= '0') && (general_field[i] <= '9')) {
bin_append(general_field[i] - 43, 5, binary_string);
value = general_field[i] - 43;
mask = 0x10;
for (j = 0; j < 5; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) { if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
bin_append(general_field[i] - 1, 7, binary_string);
value = general_field[i] - 1;
mask = 0x40;
for (j = 0; j < 7; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
if ((general_field[i] >= 'a') && (general_field[i] <= 'z')) { if ((general_field[i] >= 'a') && (general_field[i] <= 'z')) {
bin_append(general_field[i] - 7, 7, binary_string);
value = general_field[i] - 7;
mask = 0x40;
for (j = 0; j < 7; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
last_mode = ISOIEC; last_mode = ISOIEC;
if (general_field[i] == '[') { if (general_field[i] == '[') {
strcat(binary_string, "01111"); bin_append(15, 5, binary_string);
last_mode = NUMERIC; last_mode = NUMERIC;
} /* FNC1/Numeric latch */ } /* FNC1/Numeric latch */
if (general_field[i] == '!') strcat(binary_string, "11101000"); /* exclamation mark */
if (general_field[i] == 34) strcat(binary_string, "11101001"); /* quotation mark */ if (general_field[i] == '!') bin_append(232, 8, binary_string); /* exclamation mark */
if (general_field[i] == 37) strcat(binary_string, "11101010"); /* percent sign */ if (general_field[i] == 34) bin_append(233, 8, binary_string); /* quotation mark */
if (general_field[i] == '&') strcat(binary_string, "11101011"); /* ampersand */ if (general_field[i] == 37) bin_append(234, 8, binary_string); /* percent sign */
if (general_field[i] == 39) strcat(binary_string, "11101100"); /* apostrophe */ if (general_field[i] == '&') bin_append(235, 8, binary_string); /* ampersand */
if (general_field[i] == '(') strcat(binary_string, "11101101"); /* left parenthesis */ if (general_field[i] == 39) bin_append(236, 8, binary_string); /* apostrophe */
if (general_field[i] == ')') strcat(binary_string, "11101110"); /* right parenthesis */ if (general_field[i] == '(') bin_append(237, 8, binary_string); /* left parenthesis */
if (general_field[i] == '*') strcat(binary_string, "11101111"); /* asterisk */ if (general_field[i] == ')') bin_append(238, 8, binary_string); /* right parenthesis */
if (general_field[i] == '+') strcat(binary_string, "11110000"); /* plus sign */ if (general_field[i] == '*') bin_append(239, 8, binary_string); /* asterisk */
if (general_field[i] == ',') strcat(binary_string, "11110001"); /* comma */ if (general_field[i] == '+') bin_append(240, 8, binary_string); /* plus sign */
if (general_field[i] == '-') strcat(binary_string, "11110010"); /* minus or hyphen */ if (general_field[i] == ',') bin_append(241, 8, binary_string); /* comma */
if (general_field[i] == '.') strcat(binary_string, "11110011"); /* period or full stop */ if (general_field[i] == '-') bin_append(242, 8, binary_string); /* minus or hyphen */
if (general_field[i] == '/') strcat(binary_string, "11110100"); /* slash or solidus */ if (general_field[i] == '.') bin_append(243, 8, binary_string); /* period or full stop */
if (general_field[i] == ':') strcat(binary_string, "11110101"); /* colon */ if (general_field[i] == '/') bin_append(244, 8, binary_string); /* slash or solidus */
if (general_field[i] == ';') strcat(binary_string, "11110110"); /* semicolon */ if (general_field[i] == ':') bin_append(245, 8, binary_string); /* colon */
if (general_field[i] == '<') strcat(binary_string, "11110111"); /* less-than sign */ if (general_field[i] == ';') bin_append(246, 8, binary_string); /* semicolon */
if (general_field[i] == '=') strcat(binary_string, "11111000"); /* equals sign */ if (general_field[i] == '<') bin_append(247, 8, binary_string); /* less-than sign */
if (general_field[i] == '>') strcat(binary_string, "11111001"); /* greater-than sign */ if (general_field[i] == '=') bin_append(248, 8, binary_string); /* equals sign */
if (general_field[i] == '?') strcat(binary_string, "11111010"); /* question mark */ if (general_field[i] == '>') bin_append(249, 8, binary_string); /* greater-than sign */
if (general_field[i] == '_') strcat(binary_string, "11111011"); /* underline or low line */ if (general_field[i] == '?') bin_append(250, 8, binary_string); /* question mark */
if (general_field[i] == ' ') strcat(binary_string, "11111100"); /* space */ if (general_field[i] == '_') bin_append(251, 8, binary_string); /* underline or low line */
if (general_field[i] == ' ') bin_append(252, 8, binary_string); /* space */
i++; i++;
break; break;
@ -1948,34 +1768,15 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
if (last_mode == NUMERIC) { if (last_mode == NUMERIC) {
if ((remainder >= 4) && (remainder <= 6)) { if ((remainder >= 4) && (remainder <= 6)) {
value = ctoi(general_field[i]); bin_append(ctoi(general_field[i]) + 1, 4, binary_string);
value++;
mask = 0x08;
for (j = 0; j < 4; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
mask = mask >> 1;
}
} else { } else {
d1 = ctoi(general_field[i]); d1 = ctoi(general_field[i]);
d2 = 10; d2 = 10;
value = (11 * d1) + d2 + 8; bin_append((11 * d1) + d2 + 8, 7, binary_string);
mask = 0x40;
for (j = 0; j < 7; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
} else { } else {
value = general_field[i] - 43; bin_append(general_field[i] - 43, 5, binary_string);
mask = 0x10;
for (j = 0; j < 5; j++) {
strcat(binary_string, (value & mask) ? "1" : "0");
mask = mask >> 1;
}
} }
remainder = 12 - (strlen(binary_string) % 12); remainder = 12 - (strlen(binary_string) % 12);