#define SODIUM_X_F (IS_NUM_F | IS_UX__F | IS_LX__F)
#include <stdio.h>
#include "common.h"
static const char TeleTable[128][16] = {
{ "31313131" }, { "1131313111" }, { "33313111" }, { "1111313131" },
{ "3111313111" }, { "11333131" }, { "13133131" }, { "111111313111" },
{ "31333111" }, { "1131113131" }, { "33113131" }, { "1111333111" },
{ "3111113131" }, { "1113133111" }, { "1311133111" }, { "111111113131" },
{ "3131113111" }, { "11313331" }, { "333331" }, { "111131113111" },
{ "31113331" }, { "1133113111" }, { "1313113111" }, { "1111113331" },
{ "31131331" }, { "113111113111" }, { "3311113111" }, { "1111131331" },
{ "311111113111" }, { "1113111331" }, { "1311111331" }, { "11111111113111" },
{ "31313311" }, { "1131311131" }, { "33311131" }, { "1111313311" },
{ "3111311131" }, { "11333311" }, { "13133311" }, { "111111311131" },
{ "31331131" }, { "1131113311" }, { "33113311" }, { "1111331131" },
{ "3111113311" }, { "1113131131" }, { "1311131131" }, { "111111113311" },
{ "3131111131" }, { "1131131311" }, { "33131311" }, { "111131111131" },
{ "3111131311" }, { "1133111131" }, { "1313111131" }, { "111111131311" },
{ "3113111311" }, { "113111111131" }, { "3311111131" }, { "111113111311" },
{ "311111111131" }, { "111311111311" }, { "131111111311" }, { "11111111111131" },
{ "3131311111" }, { "11313133" }, { "333133" }, { "111131311111" },
{ "31113133" }, { "1133311111" }, { "1313311111" }, { "1111113133" },
{ "313333" }, { "113111311111" }, { "3311311111" }, { "11113333" },
{ "311111311111" }, { "11131333" }, { "13111333" }, { "11111111311111" },
{ "31311133" }, { "1131331111" }, { "33331111" }, { "1111311133" },
{ "3111331111" }, { "11331133" }, { "13131133" }, { "111111331111" },
{ "3113131111" }, { "1131111133" }, { "33111133" }, { "111113131111" },
{ "3111111133" }, { "111311131111" }, { "131111131111" }, { "111111111133" },
{ "31311313" }, { "113131111111" }, { "3331111111" }, { "1111311313" },
{ "311131111111" }, { "11331313" }, { "13131313" }, { "11111131111111" },
{ "3133111111" }, { "1131111313" }, { "33111313" }, { "111133111111" },
{ "3111111313" }, { "111313111111" }, { "131113111111" }, { "111111111313" },
{ "313111111111" }, { "1131131113" }, { "33131113" }, { "11113111111111" },
{ "3111131113" }, { "113311111111" }, { "131311111111" }, { "111111131113" },
{ "3113111113" }, { "11311111111111" }, { "331111111111" }, { "111113111113" },
{ "31111111111111" }, { "111311111113" }, { "131111111113" },
{'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
};
static const char TeleLens[128] = {
8, 10, 8, 10, 10, 8, 8, 12, 8, 10, 8, 10, 10, 10, 10, 12,
10, 8, 6, 12, 8, 10, 10, 10, 8, 12, 10, 10, 12, 10, 10, 14,
8, 10, 8, 10, 10, 8, 8, 12, 8, 10, 8, 10, 10, 10, 10, 12,
10, 10, 8, 12, 10, 10, 10, 12, 10, 12, 10, 12, 12, 12, 12, 14,
10, 8, 6, 12, 8, 10, 10, 10, 6, 12, 10, 8, 12, 8, 8, 14,
8, 10, 8, 10, 10, 8, 8, 12, 10, 10, 8, 12, 10, 12, 12, 12,
8, 12, 10, 10, 12, 8, 8, 14, 10, 10, 8, 12, 10, 12, 12, 12,
12, 10, 8, 14, 10, 12, 12, 12, 10, 14, 12, 12, 14, 12, 12, 16
};
INTERNAL int zint_telepen(struct zint_symbol *symbol, unsigned char source[], int length) {
int i, count, check_digit;
int error_number;
char dest[1145];
char *d = dest;
const int content_segs = symbol->output_options & BARCODE_CONTENT_SEGS;
error_number = 0;
count = 0;
if (length > 69) {
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 390, "Input length %d too long (maximum 69)", length);
}
memcpy(d, TeleTable['_'], 12);
d += 12;
for (i = 0; i < length; i++) {
if (!z_isascii(source[i])) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 391,
"Invalid character at position %d in input, extended ASCII not allowed", i + 1);
}
memcpy(d, TeleTable[source[i]], TeleLens[source[i]]);
d += TeleLens[source[i]];
count += source[i];
}
check_digit = 127 - (count % 127);
if (check_digit == 127) {
check_digit = 0;
}
memcpy(d, TeleTable[check_digit], TeleLens[check_digit]);
d += TeleLens[check_digit];
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
memcpy(d, TeleTable['z'], 12);
d += 12;
z_expand(symbol, dest, d - dest);
if (symbol->output_options & COMPLIANT_HEIGHT) {
(void) z_set_height(symbol, 0.0f, 32.0f, 0, 1 );
} else {
(void) z_set_height(symbol, 0.0f, 50.0f, 0, 1 );
}
z_hrt_cpy_iso8859_1(symbol, source, length);
if (content_segs && z_ct_cpy_cat(symbol, source, length, (char) check_digit, NULL , 0)) {
return ZINT_ERROR_MEMORY;
}
return error_number;
}
INTERNAL int zint_telepen_num(struct zint_symbol *symbol, unsigned char source[], int length) {
int count, check_digit, glyph;
int error_number = 0;
int i;
char dest[1129];
char *d = dest;
unsigned char local_source[137];
const int content_segs = symbol->output_options & BARCODE_CONTENT_SEGS;
count = 0;
if (length > 136) {
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 392, "Input length %d too long (maximum 136)", length);
}
if ((i = z_not_sane(SODIUM_X_F, source, length))) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 393,
"Invalid character at position %d in input (digits and \"X\" only)", i);
}
if (length & 1) {
memcpy(local_source + 1, source, length++);
local_source[0] = '0';
} else {
memcpy(local_source, source, length);
}
z_to_upper(local_source, length);
memcpy(d, TeleTable['_'], 12);
d += 12;
for (i = 0; i < length; i += 2) {
if (local_source[i] == 'X') {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 394, "Invalid odd position %d of \"X\" in Telepen data",
i + 1);
}
if (local_source[i + 1] == 'X') {
glyph = z_ctoi(local_source[i]) + 17;
count += glyph;
} else {
glyph = 10 * z_ctoi(local_source[i]) + z_ctoi(local_source[i + 1]);
glyph += 27;
count += glyph;
}
memcpy(d, TeleTable[glyph], TeleLens[glyph]);
d += TeleLens[glyph];
}
check_digit = 127 - (count % 127);
if (check_digit == 127) {
check_digit = 0;
}
memcpy(d, TeleTable[check_digit], TeleLens[check_digit]);
d += TeleLens[check_digit];
if (symbol->debug & ZINT_DEBUG_PRINT) printf("Check digit: %d\n", check_digit);
memcpy(d, TeleTable['z'], 12);
d += 12;
z_expand(symbol, dest, d - dest);
if (symbol->output_options & COMPLIANT_HEIGHT) {
(void) z_set_height(symbol, 0.0f, 32.0f, 0, 1 );
} else {
(void) z_set_height(symbol, 0.0f, 50.0f, 0, 1 );
}
z_hrt_cpy_nochk(symbol, local_source, length);
if (content_segs && z_ct_cpy_cat(symbol, local_source, length, (char) check_digit, NULL , 0)) {
return ZINT_ERROR_MEMORY;
}
return error_number;
}