mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
Simplify conversion to binary with common function
No change to functionality
This commit is contained in:
parent
19ba8a34c4
commit
19c3755ed0
210
backend/aztec.c
210
backend/aztec.c
@ -69,7 +69,7 @@ static void insert(char binary_string[], const size_t posn, const char newbit) {
|
||||
* 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) {
|
||||
int i, j, k, p, bytes;
|
||||
int i, j, k, bytes;
|
||||
int curtable, newtable, lasttable, chartype, maplength, blocks;
|
||||
#ifndef _MSC_VER
|
||||
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 */
|
||||
switch (curtable) {
|
||||
case LOWER: /* US */
|
||||
strcat(binary_string, pentbit[28]);
|
||||
bin_append(28, 5, binary_string);
|
||||
if (debug) printf("US ");
|
||||
break;
|
||||
case MIXED: /* UL */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
newtable = UPPER;
|
||||
break;
|
||||
case PUNC: /* UL */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
newtable = UPPER;
|
||||
break;
|
||||
case DIGIT: /* US */
|
||||
strcat(binary_string, quadbit[15]);
|
||||
bin_append(15, 4, binary_string);
|
||||
if (debug) printf("US ");
|
||||
break;
|
||||
}
|
||||
@ -355,26 +355,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case (64 + LOWER): /* To LOWER */
|
||||
switch (curtable) {
|
||||
case UPPER: /* LL */
|
||||
strcat(binary_string, pentbit[28]);
|
||||
if (debug) printf("LL ");
|
||||
newtable = LOWER;
|
||||
break;
|
||||
case MIXED: /* LL */
|
||||
strcat(binary_string, pentbit[28]);
|
||||
case MIXED:
|
||||
bin_append(28, 5, binary_string);
|
||||
if (debug) printf("LL ");
|
||||
newtable = LOWER;
|
||||
break;
|
||||
case PUNC: /* UL LL */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[28]);
|
||||
bin_append(28, 5, binary_string);
|
||||
if (debug) printf("LL ");
|
||||
newtable = LOWER;
|
||||
break;
|
||||
case DIGIT: /* UL LL */
|
||||
strcat(binary_string, quadbit[14]);
|
||||
bin_append(14, 4, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[28]);
|
||||
bin_append(28, 5, binary_string);
|
||||
if (debug) printf("LL ");
|
||||
newtable = LOWER;
|
||||
break;
|
||||
@ -383,26 +379,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case (64 + MIXED): /* To MIXED */
|
||||
switch (curtable) {
|
||||
case UPPER: /* ML */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
if (debug) printf("ML ");
|
||||
newtable = MIXED;
|
||||
break;
|
||||
case LOWER: /* ML */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
case LOWER:
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
newtable = MIXED;
|
||||
break;
|
||||
case PUNC: /* UL ML */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
newtable = MIXED;
|
||||
break;
|
||||
case DIGIT: /* UL ML */
|
||||
strcat(binary_string, quadbit[14]);
|
||||
bin_append(14, 4, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
newtable = MIXED;
|
||||
break;
|
||||
@ -411,19 +403,10 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case (64 + PUNC): /* To PUNC */
|
||||
switch (curtable) {
|
||||
case UPPER: /* PS */
|
||||
strcat(binary_string, pentbit[0]);
|
||||
if (debug) printf("PS ");
|
||||
break;
|
||||
case LOWER: /* PS */
|
||||
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]);
|
||||
case LOWER:
|
||||
case MIXED:
|
||||
case DIGIT:
|
||||
bin_append(0, 5, binary_string);
|
||||
if (debug) printf("PS ");
|
||||
break;
|
||||
}
|
||||
@ -431,26 +414,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case (64 + DIGIT): /* To DIGIT */
|
||||
switch (curtable) {
|
||||
case UPPER: /* DL */
|
||||
strcat(binary_string, pentbit[30]);
|
||||
if (debug) printf("DL ");
|
||||
newtable = DIGIT;
|
||||
break;
|
||||
case LOWER: /* DL */
|
||||
strcat(binary_string, pentbit[30]);
|
||||
case LOWER:
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("DL ");
|
||||
newtable = DIGIT;
|
||||
break;
|
||||
case MIXED: /* UL DL */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[30]);
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("DL ");
|
||||
newtable = DIGIT;
|
||||
break;
|
||||
case PUNC: /* UL DL */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[30]);
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("DL ");
|
||||
newtable = DIGIT;
|
||||
break;
|
||||
@ -463,24 +442,24 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case UPPER: /* To UPPER */
|
||||
switch (curtable) {
|
||||
case LOWER: /* ML UL */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
newtable = UPPER;
|
||||
break;
|
||||
case MIXED: /* UL */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
newtable = UPPER;
|
||||
break;
|
||||
case PUNC: /* UL */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
newtable = UPPER;
|
||||
break;
|
||||
case DIGIT: /* UL */
|
||||
strcat(binary_string, quadbit[14]);
|
||||
bin_append(14, 4, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
newtable = UPPER;
|
||||
break;
|
||||
@ -489,26 +468,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case LOWER: /* To LOWER */
|
||||
switch (curtable) {
|
||||
case UPPER: /* LL */
|
||||
strcat(binary_string, pentbit[28]);
|
||||
if (debug) printf("LL ");
|
||||
newtable = LOWER;
|
||||
break;
|
||||
case MIXED: /* LL */
|
||||
strcat(binary_string, pentbit[28]);
|
||||
case MIXED:
|
||||
bin_append(28, 5, binary_string);
|
||||
if (debug) printf("LL ");
|
||||
newtable = LOWER;
|
||||
break;
|
||||
case PUNC: /* UL LL */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[28]);
|
||||
bin_append(28, 5, binary_string);
|
||||
if (debug) printf("LL ");
|
||||
newtable = LOWER;
|
||||
break;
|
||||
case DIGIT: /* UL LL */
|
||||
strcat(binary_string, quadbit[14]);
|
||||
bin_append(14, 4, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[28]);
|
||||
bin_append(28, 5, binary_string);
|
||||
if (debug) printf("LL ");
|
||||
newtable = LOWER;
|
||||
break;
|
||||
@ -517,26 +492,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case MIXED: /* To MIXED */
|
||||
switch (curtable) {
|
||||
case UPPER: /* ML */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
if (debug) printf("ML ");
|
||||
newtable = MIXED;
|
||||
break;
|
||||
case LOWER: /* ML */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
case LOWER:
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
newtable = MIXED;
|
||||
break;
|
||||
case PUNC: /* UL ML */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
newtable = MIXED;
|
||||
break;
|
||||
case DIGIT: /* UL ML */
|
||||
strcat(binary_string, quadbit[14]);
|
||||
bin_append(14, 4, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
newtable = MIXED;
|
||||
break;
|
||||
@ -545,30 +516,24 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case PUNC: /* To PUNC */
|
||||
switch (curtable) {
|
||||
case UPPER: /* ML PL */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
case LOWER:
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
strcat(binary_string, pentbit[30]);
|
||||
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]);
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("PL ");
|
||||
newtable = PUNC;
|
||||
break;
|
||||
case MIXED: /* PL */
|
||||
strcat(binary_string, pentbit[30]);
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("PL ");
|
||||
newtable = PUNC;
|
||||
break;
|
||||
case DIGIT: /* UL ML PL */
|
||||
strcat(binary_string, quadbit[14]);
|
||||
bin_append(14, 4, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("ML ");
|
||||
strcat(binary_string, pentbit[30]);
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("PL ");
|
||||
newtable = PUNC;
|
||||
break;
|
||||
@ -577,26 +542,22 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
case DIGIT: /* To DIGIT */
|
||||
switch (curtable) {
|
||||
case UPPER: /* DL */
|
||||
strcat(binary_string, pentbit[30]);
|
||||
if (debug) printf("DL ");
|
||||
newtable = DIGIT;
|
||||
break;
|
||||
case LOWER: /* DL */
|
||||
strcat(binary_string, pentbit[30]);
|
||||
case LOWER:
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("DL ");
|
||||
newtable = DIGIT;
|
||||
break;
|
||||
case MIXED: /* UL DL */
|
||||
strcat(binary_string, pentbit[29]);
|
||||
bin_append(29, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[30]);
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("DL ");
|
||||
newtable = DIGIT;
|
||||
break;
|
||||
case PUNC: /* UL DL */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[30]);
|
||||
bin_append(30, 5, binary_string);
|
||||
if (debug) printf("DL ");
|
||||
newtable = DIGIT;
|
||||
break;
|
||||
@ -606,32 +567,24 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
lasttable = curtable;
|
||||
switch (curtable) {
|
||||
case UPPER: /* BS */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
if (debug) printf("BS ");
|
||||
newtable = BINARY;
|
||||
break;
|
||||
case LOWER: /* BS */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
if (debug) printf("BS ");
|
||||
newtable = BINARY;
|
||||
break;
|
||||
case MIXED: /* BS */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
case LOWER:
|
||||
case MIXED:
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("BS ");
|
||||
newtable = BINARY;
|
||||
break;
|
||||
case PUNC: /* UL BS */
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("BS ");
|
||||
lasttable = UPPER;
|
||||
newtable = BINARY;
|
||||
break;
|
||||
case DIGIT: /* UL BS */
|
||||
strcat(binary_string, quadbit[14]);
|
||||
bin_append(14, 4, binary_string);
|
||||
if (debug) printf("UL ");
|
||||
strcat(binary_string, pentbit[31]);
|
||||
bin_append(31, 5, binary_string);
|
||||
if (debug) printf("BS ");
|
||||
lasttable = UPPER;
|
||||
newtable = BINARY;
|
||||
@ -650,24 +603,11 @@ static int aztec_text_process(const unsigned char source[], const unsigned int s
|
||||
|
||||
if (bytes > 31) {
|
||||
/* Put 00000 followed by 11-bit number of bytes less 31 */
|
||||
strcat(binary_string, "00000");
|
||||
|
||||
for (p = 0; p < 11; p++) {
|
||||
if ((bytes - 31) & (0x400 >> p)) {
|
||||
strcat(binary_string, "1");
|
||||
} else {
|
||||
strcat(binary_string, "0");
|
||||
}
|
||||
}
|
||||
bin_append(0, 5, binary_string);
|
||||
bin_append(bytes - 31, 11, binary_string);
|
||||
} else {
|
||||
/* Put 5-bit number of bytes */
|
||||
for (p = 0; p < 5; p++) {
|
||||
if (bytes & (0x10 >> p)) {
|
||||
strcat(binary_string, "1");
|
||||
} else {
|
||||
strcat(binary_string, "0");
|
||||
}
|
||||
}
|
||||
bin_append(bytes, 5, binary_string);
|
||||
}
|
||||
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 PUNC:
|
||||
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);
|
||||
} 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);
|
||||
} else {
|
||||
strcat(binary_string, pentbit[charmap[i]]);
|
||||
bin_append(charmap[i], 5, binary_string);
|
||||
if (!((chartype == PUNC) && (charmap[i] == 0)))
|
||||
if (debug) printf("%d ", charmap[i]);
|
||||
}
|
||||
break;
|
||||
case DIGIT:
|
||||
strcat(binary_string, quadbit[charmap[i]]);
|
||||
bin_append(charmap[i], 4, binary_string);
|
||||
if (debug) printf("%d ", charmap[i]);
|
||||
break;
|
||||
case BINARY:
|
||||
for (p = 0; p < 8; p++) {
|
||||
if (charmap[i] & (0x80 >> p)) {
|
||||
strcat(binary_string, "1");
|
||||
} else {
|
||||
strcat(binary_string, "0");
|
||||
}
|
||||
}
|
||||
bin_append(charmap[i], 8, binary_string);
|
||||
if (debug) printf("%d ", charmap[i]);
|
||||
break;
|
||||
}
|
||||
|
@ -96,21 +96,6 @@ const int AztecSymbolChar[128] = {
|
||||
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] = {
|
||||
/* Codewords per symbol */
|
||||
21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790,
|
||||
|
@ -424,7 +424,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
|
||||
if (j == 21) {
|
||||
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)) {
|
||||
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) {
|
||||
/* Step F - Decimal encodation */
|
||||
int value, decimal_count, data_left;
|
||||
int decimal_count, data_left;
|
||||
|
||||
next_mode = C1_DECIMAL;
|
||||
|
||||
@ -865,7 +865,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
int sub_target;
|
||||
/* Finish Decimal mode and go back to ASCII */
|
||||
|
||||
strcat(decimal_binary, "111111"); /* Unlatch */
|
||||
bin_append(63, 6, decimal_binary); /* Unlatch */
|
||||
|
||||
target_count = 3;
|
||||
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) {
|
||||
strcat(decimal_binary, "01");
|
||||
bin_append(1, 2, decimal_binary);
|
||||
}
|
||||
|
||||
if ((bits_left_in_byte == 4) || (bits_left_in_byte == 6)) {
|
||||
if (decimal_count >= 1) {
|
||||
int sub_value = ctoi(source[sp]) + 1;
|
||||
|
||||
for (i = 0x08; i > 0; i = i >> 1) {
|
||||
if (sub_value & i) {
|
||||
strcat(decimal_binary, "1");
|
||||
} else {
|
||||
strcat(decimal_binary, "0");
|
||||
}
|
||||
}
|
||||
|
||||
bin_append(ctoi(source[sp]) + 1, 4, decimal_binary);
|
||||
sp++;
|
||||
} else {
|
||||
strcat(decimal_binary, "1111");
|
||||
bin_append(15, 4, decimal_binary);
|
||||
}
|
||||
}
|
||||
|
||||
if (bits_left_in_byte == 6) {
|
||||
strcat(decimal_binary, "01");
|
||||
bin_append(1, 2, decimal_binary);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
} else {
|
||||
/* There are three digits - convert the value to binary */
|
||||
value = (100 * ctoi(source[sp])) + (10 * ctoi(source[sp + 1])) + ctoi(source[sp + 2]) + 1;
|
||||
|
||||
for (p = 0; p < 10; p++) {
|
||||
if (value & (0x200 >> p)) {
|
||||
strcat(decimal_binary, "1");
|
||||
} else {
|
||||
strcat(decimal_binary, "0");
|
||||
}
|
||||
}
|
||||
|
||||
bin_append((100 * ctoi(source[sp])) + (10 * ctoi(source[sp + 1])) + ctoi(source[sp + 2]) + 1, 10, decimal_binary);
|
||||
sp += 3;
|
||||
}
|
||||
|
||||
@ -1088,7 +1070,7 @@ int c1_encode(struct zint_symbol *symbol, unsigned char source[], unsigned int t
|
||||
int sub_target;
|
||||
/* Finish Decimal mode and go back to ASCII */
|
||||
|
||||
strcat(decimal_binary, "111111"); /* Unlatch */
|
||||
bin_append(63, 6, decimal_binary); /* Unlatch */
|
||||
|
||||
target_count = 3;
|
||||
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) {
|
||||
strcat(decimal_binary, "01");
|
||||
bin_append(1, 2, decimal_binary);
|
||||
}
|
||||
|
||||
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) {
|
||||
strcat(decimal_binary, "01");
|
||||
bin_append(1, 2, decimal_binary);
|
||||
}
|
||||
|
||||
/* Binary buffer is full - transfer to target */
|
||||
|
@ -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[] */
|
||||
void to_upper(unsigned char source[]) {
|
||||
size_t i, src_len = ustrlen(source);
|
||||
|
@ -57,6 +57,7 @@ extern "C" {
|
||||
extern size_t ustrlen(const unsigned char source[]);
|
||||
extern int ctoi(const char 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 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[]);
|
||||
|
@ -924,36 +924,16 @@ int dotcode_encode_message(struct zint_symbol *symbol, const unsigned char sourc
|
||||
|
||||
/* Convert codewords to binary data stream */
|
||||
static size_t make_dotstream(unsigned char masked_array[], int array_length, char dot_stream[]) {
|
||||
int i, j;
|
||||
int mask = 0x100;
|
||||
int i;
|
||||
|
||||
dot_stream[0] = '\0';
|
||||
|
||||
/* Mask value is encoded as two dots */
|
||||
switch (masked_array[0]) {
|
||||
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;
|
||||
}
|
||||
bin_append(masked_array[0], 2, dot_stream);
|
||||
|
||||
/* The rest of the data uses 9-bit dot patterns from Annex C */
|
||||
for (i = 1; i < array_length; i++) {
|
||||
for (j = 0; j < 9; j++) {
|
||||
if (dot_patterns[masked_array[i]] & (mask >> j)) {
|
||||
strcat(dot_stream, "1");
|
||||
} else {
|
||||
strcat(dot_stream, "0");
|
||||
}
|
||||
}
|
||||
bin_append(dot_patterns[masked_array[i]], 9, dot_stream);
|
||||
}
|
||||
|
||||
return strlen(dot_stream);
|
||||
|
@ -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 */
|
||||
void add_shift_char(char binary[], int shifty) {
|
||||
int i, p, debug = 0;
|
||||
int i, debug = 0;
|
||||
int glyph = 0;
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
@ -339,26 +339,20 @@ void add_shift_char(char binary[], int shifty) {
|
||||
printf("SHIFT [%d] ", glyph);
|
||||
}
|
||||
|
||||
for (p = 0; p < 6; p++) {
|
||||
if (glyph & (0x20 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(glyph, 6, binary);
|
||||
}
|
||||
|
||||
int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int debug) {
|
||||
/* Create a binary stream representation of the input data.
|
||||
7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters,
|
||||
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 p = 0, ppos;
|
||||
int numbuf[3], punt = 0;
|
||||
size_t number_pad_posn, byte_count_posn = 0;
|
||||
int byte_count = 0;
|
||||
int shift, i;
|
||||
int shift;
|
||||
|
||||
strcpy(binary, "");
|
||||
|
||||
@ -368,18 +362,12 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
|
||||
number_pad_posn = 0;
|
||||
|
||||
if (reader) {
|
||||
strcat(binary, "1010"); /* FNC3 - Reader Initialisation */
|
||||
bin_append(10, 4, binary); /* FNC3 - Reader Initialisation */
|
||||
}
|
||||
|
||||
if (eci != 3) {
|
||||
strcat(binary, "11000"); /* ECI */
|
||||
for (q = 0; q < 10; q++) {
|
||||
if (eci & (0x100 >> q)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(24, 5, binary); /* ECI */
|
||||
bin_append(eci, 10, binary);
|
||||
}
|
||||
|
||||
do {
|
||||
@ -389,32 +377,32 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
|
||||
switch (current_mode) {
|
||||
case 0:
|
||||
switch (next_mode) {
|
||||
case GM_CHINESE: strcat(binary, "0001");
|
||||
case GM_CHINESE: bin_append(1, 4, binary);
|
||||
break;
|
||||
case GM_NUMBER: strcat(binary, "0010");
|
||||
case GM_NUMBER: bin_append(2, 4, binary);
|
||||
break;
|
||||
case GM_LOWER: strcat(binary, "0011");
|
||||
case GM_LOWER: bin_append(3, 4, binary);
|
||||
break;
|
||||
case GM_UPPER: strcat(binary, "0100");
|
||||
case GM_UPPER: bin_append(4, 4, binary);
|
||||
break;
|
||||
case GM_MIXED: strcat(binary, "0101");
|
||||
case GM_MIXED: bin_append(5, 4, binary);
|
||||
break;
|
||||
case GM_BYTE: strcat(binary, "0111");
|
||||
case GM_BYTE: bin_append(6, 4, binary);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GM_CHINESE:
|
||||
switch (next_mode) {
|
||||
case GM_NUMBER: strcat(binary, "1111111100001");
|
||||
break; // 8161
|
||||
case GM_LOWER: strcat(binary, "1111111100010");
|
||||
break; // 8162
|
||||
case GM_UPPER: strcat(binary, "1111111100011");
|
||||
break; // 8163
|
||||
case GM_MIXED: strcat(binary, "1111111100100");
|
||||
break; // 8164
|
||||
case GM_BYTE: strcat(binary, "1111111100101");
|
||||
break; // 8165
|
||||
case GM_NUMBER: bin_append(8161, 13, binary);
|
||||
break;
|
||||
case GM_LOWER: bin_append(8162, 13, binary);
|
||||
break;
|
||||
case GM_UPPER: bin_append(8163, 13, binary);
|
||||
break;
|
||||
case GM_MIXED: bin_append(8164, 13, binary);
|
||||
break;
|
||||
case GM_BYTE: bin_append(8165, 13, binary);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
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
|
||||
case 2: binary[number_pad_posn] = '0';
|
||||
binary[number_pad_posn + 1] = '1';
|
||||
break; // 1 pad digit
|
||||
break; // 1 pad digits
|
||||
case 3: binary[number_pad_posn] = '0';
|
||||
binary[number_pad_posn + 1] = '0';
|
||||
break; // 0 pad digits
|
||||
}
|
||||
switch (next_mode) {
|
||||
case GM_CHINESE: strcat(binary, "1111111011");
|
||||
break; // 1019
|
||||
case GM_LOWER: strcat(binary, "1111111100");
|
||||
break; // 1020
|
||||
case GM_UPPER: strcat(binary, "1111111101");
|
||||
break; // 1021
|
||||
case GM_MIXED: strcat(binary, "1111111110");
|
||||
break; // 1022
|
||||
case GM_BYTE: strcat(binary, "1111111111");
|
||||
break; // 1023
|
||||
case GM_CHINESE: bin_append(1019, 10, binary);
|
||||
break;
|
||||
case GM_LOWER: bin_append(1020, 10, binary);
|
||||
break;
|
||||
case GM_UPPER: bin_append(1021, 10, binary);
|
||||
break;
|
||||
case GM_MIXED: bin_append(1022, 10, binary);
|
||||
break;
|
||||
case GM_BYTE: bin_append(1023, 10, binary);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GM_LOWER:
|
||||
case GM_UPPER:
|
||||
switch (next_mode) {
|
||||
case GM_CHINESE: strcat(binary, "11100");
|
||||
break; // 28
|
||||
case GM_NUMBER: strcat(binary, "11101");
|
||||
break; // 29
|
||||
case GM_CHINESE: bin_append(28, 5, binary);
|
||||
break;
|
||||
case GM_NUMBER: bin_append(29, 5, binary);
|
||||
break;
|
||||
case GM_LOWER:
|
||||
case GM_UPPER: strcat(binary, "11110");
|
||||
break; // 30
|
||||
case GM_MIXED: strcat(binary, "1111100");
|
||||
break; // 124
|
||||
case GM_BYTE: strcat(binary, "1111110");
|
||||
break; // 126
|
||||
case GM_UPPER: bin_append(30, 5, binary);
|
||||
break;
|
||||
case GM_MIXED: bin_append(124, 7, binary);
|
||||
break;
|
||||
case GM_BYTE: bin_append(126, 7, binary);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case GM_MIXED:
|
||||
switch (next_mode) {
|
||||
case GM_CHINESE: strcat(binary, "1111110001");
|
||||
break; // 1009
|
||||
case GM_NUMBER: strcat(binary, "1111110010");
|
||||
break; // 1010
|
||||
case GM_LOWER: strcat(binary, "1111110011");
|
||||
break; // 1011
|
||||
case GM_UPPER: strcat(binary, "1111110100");
|
||||
break; // 1012
|
||||
case GM_BYTE: strcat(binary, "1111110111");
|
||||
break; // 1015
|
||||
case GM_CHINESE: bin_append(1009, 10, binary);
|
||||
break;
|
||||
case GM_NUMBER: bin_append(1010, 10, binary);
|
||||
break;
|
||||
case GM_LOWER: bin_append(1011, 10, binary);
|
||||
break;
|
||||
case GM_UPPER: bin_append(1012, 10, binary);
|
||||
break;
|
||||
case GM_BYTE: bin_append(1015, 10, binary);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
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);
|
||||
byte_count = 0;
|
||||
switch (next_mode) {
|
||||
case GM_CHINESE: strcat(binary, "0001");
|
||||
break; // 1
|
||||
case GM_NUMBER: strcat(binary, "0010");
|
||||
break; // 2
|
||||
case GM_LOWER: strcat(binary, "0011");
|
||||
break; // 3
|
||||
case GM_UPPER: strcat(binary, "0100");
|
||||
break; // 4
|
||||
case GM_MIXED: strcat(binary, "0101");
|
||||
break; // 5
|
||||
case GM_CHINESE: bin_append(1, 4, binary);
|
||||
break;
|
||||
case GM_NUMBER: bin_append(2, 4, binary);
|
||||
break;
|
||||
case GM_LOWER: bin_append(3, 4, binary);
|
||||
break;
|
||||
case GM_UPPER: bin_append(4, 4, binary);
|
||||
break;
|
||||
case GM_MIXED: bin_append(5, 4, binary);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -556,13 +544,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
|
||||
printf("[%d] ", glyph);
|
||||
}
|
||||
|
||||
for (q = 0; q < 13; q++) {
|
||||
if (glyph & (0x1000 >> q)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(glyph, 13, binary);
|
||||
sp++;
|
||||
break;
|
||||
|
||||
@ -630,13 +612,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
|
||||
printf("[%d] ", glyph);
|
||||
}
|
||||
|
||||
for (q = 0; q < 10; q++) {
|
||||
if (glyph & (0x200 >> q)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(glyph, 10, binary);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
for (q = 0; q < 10; q++) {
|
||||
if (glyph & (0x200 >> q)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(glyph, 10, binary);
|
||||
break;
|
||||
|
||||
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) {
|
||||
/* 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);
|
||||
strcat(binary, "0111");
|
||||
bin_append(7, 4, binary);
|
||||
byte_count_posn = strlen(binary);
|
||||
strcat(binary, "LLLLLLLLL");
|
||||
byte_count = 0;
|
||||
@ -672,13 +642,7 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
|
||||
if (debug) {
|
||||
printf("[%d] ", glyph);
|
||||
}
|
||||
for (q = 0; q < 8; q++) {
|
||||
if (glyph & (0x80 >> q)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(glyph, 8, binary);
|
||||
sp++;
|
||||
byte_count++;
|
||||
break;
|
||||
@ -705,16 +669,10 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
|
||||
printf("[%d] ", glyph);
|
||||
}
|
||||
|
||||
for (q = 0; q < 6; q++) {
|
||||
if (glyph & (0x20 >> q)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(glyph, 6, binary);
|
||||
} else {
|
||||
/* Shift Mode character */
|
||||
strcat(binary, "1111110110"); /* 1014 - shift indicator */
|
||||
bin_append(1014, 10, binary); /* shift indicator */
|
||||
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);
|
||||
}
|
||||
|
||||
for (q = 0; q < 5; q++) {
|
||||
if (glyph & (0x10 >> q)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(glyph, 5, binary);
|
||||
} else {
|
||||
/* Shift Mode character */
|
||||
strcat(binary, "1111101"); /* 127 - shift indicator */
|
||||
bin_append(125, 7, binary); /* shift indicator */
|
||||
add_shift_char(binary, gbdata[sp]);
|
||||
}
|
||||
|
||||
@ -769,16 +721,10 @@ int gm_encode(int gbdata[], int length, char binary[], int reader, int eci, int
|
||||
printf("[%d] ", glyph);
|
||||
}
|
||||
|
||||
for (q = 0; q < 5; q++) {
|
||||
if (glyph & (0x10 >> q)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(glyph, 5, binary);
|
||||
} else {
|
||||
/* Shift Mode character */
|
||||
strcat(binary, "1111101"); /* 127 - shift indicator */
|
||||
bin_append(125, 7, binary); /* shift indicator */
|
||||
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 */
|
||||
switch (current_mode) {
|
||||
case GM_CHINESE: strcat(binary, "1111111100000");
|
||||
break; // 8160
|
||||
case GM_NUMBER: strcat(binary, "1111111010");
|
||||
break; // 1018
|
||||
case GM_CHINESE: bin_append(8160, 13, binary);
|
||||
break;
|
||||
case GM_NUMBER: bin_append(1018, 10, binary);
|
||||
break;
|
||||
case GM_LOWER:
|
||||
case GM_UPPER: strcat(binary, "11011");
|
||||
break; // 27
|
||||
case GM_MIXED: strcat(binary, "1111110000");
|
||||
break; // 1008
|
||||
case GM_BYTE: strcat(binary, "0000");
|
||||
break; // 0
|
||||
case GM_UPPER: bin_append(27, 5, binary);
|
||||
break;
|
||||
case GM_MIXED: bin_append(1008, 10, binary);
|
||||
break;
|
||||
case GM_BYTE: bin_append(0, 4, binary);
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
p = 0;
|
||||
}
|
||||
for (i = 0; i < p; i++) {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
bin_append(0, p, binary);
|
||||
|
||||
if (strlen(binary) > 9191) {
|
||||
return ZINT_ERROR_TOO_LONG;
|
||||
|
110
backend/hanxin.c
110
backend/hanxin.c
@ -331,21 +331,15 @@ int lookup_text2(char input) {
|
||||
void calculate_binary(char binary[], char mode[], int source[], int length, int eci, int debug) {
|
||||
int block_length;
|
||||
int position = 0;
|
||||
int i, p, count, encoding_value;
|
||||
int i, count, encoding_value;
|
||||
int first_byte, second_byte;
|
||||
int third_byte, fourth_byte;
|
||||
int glyph;
|
||||
int submode;
|
||||
|
||||
if (eci != 3) {
|
||||
strcat(binary, "1000"); // ECI
|
||||
for (p = 0; p < 8; p++) {
|
||||
if (eci & (0x80 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(8, 4, binary); // ECI
|
||||
bin_append(eci, 8, binary);
|
||||
}
|
||||
|
||||
do {
|
||||
@ -358,7 +352,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
case 'n':
|
||||
/* Numeric mode */
|
||||
/* Mode indicator */
|
||||
strcat(binary, "0001");
|
||||
bin_append(1, 4, binary);
|
||||
|
||||
if (debug) {
|
||||
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++) {
|
||||
if (encoding_value & (0x200 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(encoding_value, 10, binary);
|
||||
|
||||
if (debug) {
|
||||
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) */
|
||||
switch (count) {
|
||||
case 1:
|
||||
strcat(binary, "1111111101");
|
||||
bin_append(1021, 10, binary);
|
||||
break;
|
||||
case 2:
|
||||
strcat(binary, "1111111110");
|
||||
bin_append(1022, 10, binary);
|
||||
break;
|
||||
case 3:
|
||||
strcat(binary, "1111111111");
|
||||
bin_append(1023, 10, binary);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -422,7 +410,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
/* Text mode */
|
||||
if (position != 0) {
|
||||
/* Mode indicator */
|
||||
strcat(binary, "0010");
|
||||
bin_append(2, 4, binary);
|
||||
|
||||
if (debug) {
|
||||
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) {
|
||||
/* Change submode */
|
||||
strcat(binary, "111110");
|
||||
bin_append(62, 6, binary);
|
||||
submode = getsubmode((char) source[i + position]);
|
||||
if (debug) {
|
||||
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]);
|
||||
}
|
||||
|
||||
for (p = 0; p < 6; p++) {
|
||||
if (encoding_value & (0x20 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(encoding_value, 6, binary);
|
||||
|
||||
if (debug) {
|
||||
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 */
|
||||
strcat(binary, "111111");
|
||||
bin_append(63, 6, binary);
|
||||
|
||||
if (debug) {
|
||||
printf("\n");
|
||||
@ -474,16 +456,10 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
case 'b':
|
||||
/* Binary Mode */
|
||||
/* Mode indicator */
|
||||
strcat(binary, "0011");
|
||||
bin_append(3, 4, binary);
|
||||
|
||||
/* Count indicator */
|
||||
for (p = 0; p < 13; p++) {
|
||||
if (block_length & (0x1000 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(block_length, 13, binary);
|
||||
|
||||
if (debug) {
|
||||
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) {
|
||||
|
||||
/* 8-bit bytes with no conversion */
|
||||
for (p = 0; p < 8; p++) {
|
||||
if (source[i + position] & (0x80 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
bin_append(source[i + position], 8, binary);
|
||||
|
||||
if (debug) {
|
||||
printf("%d ", source[i + position]);
|
||||
@ -516,7 +486,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
case '1':
|
||||
/* Region 1 encoding */
|
||||
/* Mode indicator */
|
||||
strcat(binary, "0100");
|
||||
bin_append(4, 4, binary);
|
||||
|
||||
if (debug) {
|
||||
printf("Region 1\n");
|
||||
@ -547,19 +517,12 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
printf("%d ", glyph);
|
||||
}
|
||||
|
||||
for (p = 0; p < 12; p++) {
|
||||
if (glyph & (0x800 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
|
||||
bin_append(glyph, 12, binary);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Terminator */
|
||||
strcat(binary, "111111111111");
|
||||
bin_append(4095, 12, binary);
|
||||
|
||||
if (debug) {
|
||||
printf("\n");
|
||||
@ -569,7 +532,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
case '2':
|
||||
/* Region 2 encoding */
|
||||
/* Mode indicator */
|
||||
strcat(binary, "0101");
|
||||
bin_append(5, 4, binary);
|
||||
|
||||
if (debug) {
|
||||
printf("Region 2\n");
|
||||
@ -587,19 +550,12 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
printf("%d ", glyph);
|
||||
}
|
||||
|
||||
for (p = 0; p < 12; p++) {
|
||||
if (glyph & (0x800 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
|
||||
bin_append(glyph, 12, binary);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Terminator */
|
||||
strcat(binary, "111111111111");
|
||||
bin_append(4095, 12, binary);
|
||||
|
||||
if (debug) {
|
||||
printf("\n");
|
||||
@ -608,7 +564,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
case 'd':
|
||||
/* Double byte encoding */
|
||||
/* Mode indicator */
|
||||
strcat(binary, "0110");
|
||||
bin_append(6, 4, binary);
|
||||
|
||||
if (debug) {
|
||||
printf("Double byte\n");
|
||||
@ -630,19 +586,12 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
printf("%d ", glyph);
|
||||
}
|
||||
|
||||
for (p = 0; p < 15; p++) {
|
||||
if (glyph & (0x4000 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
|
||||
bin_append(glyph, 15, binary);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Terminator */
|
||||
strcat(binary, "111111111111111");
|
||||
bin_append(32767, 15, binary);
|
||||
/* Terminator sequence of length 12 is a mistake
|
||||
- confirmed by Wang Yi */
|
||||
|
||||
@ -661,7 +610,7 @@ void calculate_binary(char binary[], char mode[], int source[], int length, int
|
||||
while (i < block_length) {
|
||||
|
||||
/* Mode indicator */
|
||||
strcat(binary, "0111");
|
||||
bin_append(7, 4, binary);
|
||||
|
||||
first_byte = (source[i + position] & 0xff00) >> 8;
|
||||
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);
|
||||
}
|
||||
|
||||
for (p = 0; p < 15; p++) {
|
||||
if (glyph & (0x4000 >> p)) {
|
||||
strcat(binary, "1");
|
||||
} else {
|
||||
strcat(binary, "0");
|
||||
}
|
||||
}
|
||||
|
||||
bin_append(glyph, 15, binary);
|
||||
i += 2;
|
||||
}
|
||||
|
||||
|
393
backend/rss.c
393
backend/rss.c
@ -1169,7 +1169,7 @@ int general_rules(char field[], char type[]) {
|
||||
|
||||
/* 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 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;
|
||||
#ifndef _MSC_VER
|
||||
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_type = (char*) _alloca(strlen(source) + 1);
|
||||
#endif
|
||||
int remainder, d1, d2, value;
|
||||
int remainder, d1, d2;
|
||||
char padstring[40];
|
||||
|
||||
read_posn = 0;
|
||||
value = 0;
|
||||
|
||||
/* Decide whether a compressed data field is required and if so what
|
||||
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");
|
||||
read_posn = 0;
|
||||
break;
|
||||
case 3: strcat(binary_string, "0100");
|
||||
read_posn = strlen(source);
|
||||
break;
|
||||
case 4: strcat(binary_string, "0101");
|
||||
case 3: // 0100
|
||||
case 4: // 0101
|
||||
bin_append(4 + (encoding_method - 3), 4, binary_string);
|
||||
read_posn = strlen(source);
|
||||
break;
|
||||
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");
|
||||
read_posn = 23;
|
||||
break;
|
||||
case 7: strcat(binary_string, "0111000");
|
||||
read_posn = strlen(source);
|
||||
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");
|
||||
default: /* modes 7 to 14 */
|
||||
bin_append(56 + (encoding_method - 7), 7, binary_string);
|
||||
read_posn = strlen(source);
|
||||
break;
|
||||
}
|
||||
@ -1395,73 +1373,28 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
if (encoding_method == 1) {
|
||||
/* Encoding method field "1" - general item identification data */
|
||||
char group[4];
|
||||
int group_val;
|
||||
|
||||
group[0] = source[2];
|
||||
group[1] = '\0';
|
||||
group_val = atoi(group);
|
||||
|
||||
mask = 0x08;
|
||||
for (j = 0; j < 4; j++) {
|
||||
strcat(binary_string, (group_val & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append(atoi(group), 4, binary_string);
|
||||
|
||||
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;
|
||||
}
|
||||
bin_append(atoi(group), 10, binary_string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (encoding_method == 3) {
|
||||
if ((encoding_method == 3) || (encoding_method == 4)) {
|
||||
/* Encoding method field "0100" - variable weight item
|
||||
(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
|
||||
0,001 pound increment) */
|
||||
char group[4];
|
||||
int group_val;
|
||||
char weight_str[7];
|
||||
|
||||
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[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;
|
||||
}
|
||||
bin_append(atoi(group), 10, binary_string);
|
||||
}
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
weight_str[i] = source[20 + i];
|
||||
}
|
||||
weight_str[6] = '\0';
|
||||
group_val = atoi(weight_str);
|
||||
|
||||
if (source[19] == '3') {
|
||||
group_val = group_val + 10000;
|
||||
}
|
||||
|
||||
mask = 0x4000;
|
||||
for (j = 0; j < 15; j++) {
|
||||
strcat(binary_string, (group_val & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
if ((encoding_method == 4) && (source[19] == '3')) {
|
||||
bin_append(atoi(weight_str) + 10000, 15, binary_string);
|
||||
} else {
|
||||
bin_append(atoi(weight_str), 15, binary_string);
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
/* 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[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;
|
||||
}
|
||||
bin_append(atoi(group), 10, binary_string);
|
||||
}
|
||||
|
||||
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[6] = '\0';
|
||||
group_val = atoi(weight_str);
|
||||
|
||||
mask = 0x80000;
|
||||
for (j = 0; j < 20; j++) {
|
||||
strcat(binary_string, (group_val & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append(atoi(weight_str), 20, binary_string);
|
||||
|
||||
if (strlen(source) == 34) {
|
||||
/* Date information is included */
|
||||
@ -1550,88 +1492,7 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
group_val = 38400;
|
||||
}
|
||||
|
||||
mask = 0x8000;
|
||||
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;
|
||||
}
|
||||
bin_append(group_val, 16, binary_string);
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
if (general_field_type[0] == ALPHA) {
|
||||
strcat(binary_string, "0000"); /* Alphanumeric latch */
|
||||
bin_append(0, 4, binary_string); /* Alphanumeric latch */
|
||||
last_mode = ALPHA;
|
||||
}
|
||||
if (general_field_type[0] == ISOIEC) {
|
||||
strcat(binary_string, "0000"); /* Alphanumeric latch */
|
||||
strcat(binary_string, "00100"); /* ISO/IEC 646 latch */
|
||||
bin_append(0, 4, binary_string); /* Alphanumeric latch */
|
||||
bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */
|
||||
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 (last_mode != NUMERIC) {
|
||||
strcat(binary_string, "000"); /* Numeric latch */
|
||||
bin_append(0, 3, binary_string); /* Numeric latch */
|
||||
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;
|
||||
}
|
||||
|
||||
value = (11 * d1) + d2 + 8;
|
||||
|
||||
mask = 0x40;
|
||||
for (j = 0; j < 7; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
if (debug) {
|
||||
printf("%d", !!(value & mask));
|
||||
}
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append((11 * d1) + d2 + 8, 7, binary_string);
|
||||
|
||||
i += 2;
|
||||
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 (i != 0) {
|
||||
if (last_mode == NUMERIC) {
|
||||
strcat(binary_string, "0000"); /* Alphanumeric latch */
|
||||
bin_append(0, 4, binary_string); /* Alphanumeric latch */
|
||||
}
|
||||
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')) {
|
||||
|
||||
value = general_field[i] - 43;
|
||||
|
||||
mask = 0x10;
|
||||
for (j = 0; j < 5; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append(general_field[i] - 43, 5, binary_string);
|
||||
}
|
||||
|
||||
if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
|
||||
|
||||
value = general_field[i] - 33;
|
||||
|
||||
mask = 0x20;
|
||||
for (j = 0; j < 6; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append(general_field[i] - 33, 6, binary_string);
|
||||
}
|
||||
|
||||
last_mode = ALPHA;
|
||||
|
||||
if (general_field[i] == '[') {
|
||||
strcat(binary_string, "01111");
|
||||
bin_append(15, 5, binary_string);
|
||||
last_mode = NUMERIC;
|
||||
} /* 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] == '-') strcat(binary_string, "111100"); /* minus or hyphen */
|
||||
if (general_field[i] == '.') strcat(binary_string, "111101"); /* period or full stop */
|
||||
if (general_field[i] == '/') strcat(binary_string, "111110"); /* slash or solidus */
|
||||
|
||||
if (general_field[i] == '*') bin_append(58, 6, binary_string); /* asterisk */
|
||||
if (general_field[i] == ',') bin_append(59, 6, binary_string); /* comma */
|
||||
if (general_field[i] == '-') bin_append(60, 6, binary_string); /* minus or hyphen */
|
||||
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++;
|
||||
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 (i != 0) {
|
||||
if (last_mode == NUMERIC) {
|
||||
strcat(binary_string, "0000"); /* Alphanumeric latch */
|
||||
strcat(binary_string, "00100"); /* ISO/IEC 646 latch */
|
||||
bin_append(0, 4, binary_string); /* Alphanumeric latch */
|
||||
bin_append(4, 5, binary_string); /* ISO/IEC 646 latch */
|
||||
}
|
||||
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')) {
|
||||
|
||||
value = general_field[i] - 43;
|
||||
|
||||
mask = 0x10;
|
||||
for (j = 0; j < 5; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append(general_field[i] - 43, 5, binary_string);
|
||||
}
|
||||
|
||||
if ((general_field[i] >= 'A') && (general_field[i] <= 'Z')) {
|
||||
|
||||
value = general_field[i] - 1;
|
||||
|
||||
mask = 0x40;
|
||||
for (j = 0; j < 7; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append(general_field[i] - 1, 7, binary_string);
|
||||
}
|
||||
|
||||
if ((general_field[i] >= 'a') && (general_field[i] <= 'z')) {
|
||||
|
||||
value = general_field[i] - 7;
|
||||
|
||||
mask = 0x40;
|
||||
for (j = 0; j < 7; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
bin_append(general_field[i] - 7, 7, binary_string);
|
||||
}
|
||||
}
|
||||
|
||||
last_mode = ISOIEC;
|
||||
|
||||
if (general_field[i] == '[') {
|
||||
strcat(binary_string, "01111");
|
||||
bin_append(15, 5, binary_string);
|
||||
last_mode = NUMERIC;
|
||||
} /* 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] == 37) strcat(binary_string, "11101010"); /* percent sign */
|
||||
if (general_field[i] == '&') strcat(binary_string, "11101011"); /* ampersand */
|
||||
if (general_field[i] == 39) strcat(binary_string, "11101100"); /* apostrophe */
|
||||
if (general_field[i] == '(') strcat(binary_string, "11101101"); /* left parenthesis */
|
||||
if (general_field[i] == ')') strcat(binary_string, "11101110"); /* right parenthesis */
|
||||
if (general_field[i] == '*') strcat(binary_string, "11101111"); /* asterisk */
|
||||
if (general_field[i] == '+') strcat(binary_string, "11110000"); /* plus sign */
|
||||
if (general_field[i] == ',') strcat(binary_string, "11110001"); /* comma */
|
||||
if (general_field[i] == '-') strcat(binary_string, "11110010"); /* minus or hyphen */
|
||||
if (general_field[i] == '.') strcat(binary_string, "11110011"); /* period or full stop */
|
||||
if (general_field[i] == '/') strcat(binary_string, "11110100"); /* slash or solidus */
|
||||
if (general_field[i] == ':') strcat(binary_string, "11110101"); /* colon */
|
||||
if (general_field[i] == ';') strcat(binary_string, "11110110"); /* semicolon */
|
||||
if (general_field[i] == '<') strcat(binary_string, "11110111"); /* less-than sign */
|
||||
if (general_field[i] == '=') strcat(binary_string, "11111000"); /* equals sign */
|
||||
if (general_field[i] == '>') strcat(binary_string, "11111001"); /* greater-than sign */
|
||||
if (general_field[i] == '?') strcat(binary_string, "11111010"); /* question mark */
|
||||
if (general_field[i] == '_') strcat(binary_string, "11111011"); /* underline or low line */
|
||||
if (general_field[i] == ' ') strcat(binary_string, "11111100"); /* space */
|
||||
|
||||
if (general_field[i] == '!') bin_append(232, 8, binary_string); /* exclamation mark */
|
||||
if (general_field[i] == 34) bin_append(233, 8, binary_string); /* quotation mark */
|
||||
if (general_field[i] == 37) bin_append(234, 8, binary_string); /* percent sign */
|
||||
if (general_field[i] == '&') bin_append(235, 8, binary_string); /* ampersand */
|
||||
if (general_field[i] == 39) bin_append(236, 8, binary_string); /* apostrophe */
|
||||
if (general_field[i] == '(') bin_append(237, 8, binary_string); /* left parenthesis */
|
||||
if (general_field[i] == ')') bin_append(238, 8, binary_string); /* right parenthesis */
|
||||
if (general_field[i] == '*') bin_append(239, 8, binary_string); /* asterisk */
|
||||
if (general_field[i] == '+') bin_append(240, 8, binary_string); /* plus sign */
|
||||
if (general_field[i] == ',') bin_append(241, 8, binary_string); /* comma */
|
||||
if (general_field[i] == '-') bin_append(242, 8, binary_string); /* minus or hyphen */
|
||||
if (general_field[i] == '.') bin_append(243, 8, binary_string); /* period or full stop */
|
||||
if (general_field[i] == '/') bin_append(244, 8, binary_string); /* slash or solidus */
|
||||
if (general_field[i] == ':') bin_append(245, 8, binary_string); /* colon */
|
||||
if (general_field[i] == ';') bin_append(246, 8, binary_string); /* semicolon */
|
||||
if (general_field[i] == '<') bin_append(247, 8, binary_string); /* less-than sign */
|
||||
if (general_field[i] == '=') bin_append(248, 8, binary_string); /* equals sign */
|
||||
if (general_field[i] == '>') bin_append(249, 8, binary_string); /* greater-than sign */
|
||||
if (general_field[i] == '?') bin_append(250, 8, binary_string); /* question mark */
|
||||
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++;
|
||||
break;
|
||||
@ -1948,34 +1768,15 @@ int rss_binary_string(struct zint_symbol *symbol, char source[], char binary_str
|
||||
|
||||
if (last_mode == NUMERIC) {
|
||||
if ((remainder >= 4) && (remainder <= 6)) {
|
||||
value = ctoi(general_field[i]);
|
||||
value++;
|
||||
|
||||
mask = 0x08;
|
||||
for (j = 0; j < 4; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append(ctoi(general_field[i]) + 1, 4, binary_string);
|
||||
} else {
|
||||
d1 = ctoi(general_field[i]);
|
||||
d2 = 10;
|
||||
|
||||
value = (11 * d1) + d2 + 8;
|
||||
|
||||
mask = 0x40;
|
||||
for (j = 0; j < 7; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append((11 * d1) + d2 + 8, 7, binary_string);
|
||||
}
|
||||
} else {
|
||||
value = general_field[i] - 43;
|
||||
|
||||
mask = 0x10;
|
||||
for (j = 0; j < 5; j++) {
|
||||
strcat(binary_string, (value & mask) ? "1" : "0");
|
||||
mask = mask >> 1;
|
||||
}
|
||||
bin_append(general_field[i] - 43, 5, binary_string);
|
||||
}
|
||||
|
||||
remainder = 12 - (strlen(binary_string) % 12);
|
||||
|
Loading…
Reference in New Issue
Block a user