Added double buffered strings

This commit is contained in:
hooper114 2008-10-06 07:15:07 +00:00
parent d2fb2fa06b
commit 285c2c8555

View File

@ -43,13 +43,13 @@ static char *EANsetA[10] = {"3211", "2221", "2122", "1411", "1132", "1231", "111
static char *EANsetB[10] = {"1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121", static char *EANsetB[10] = {"1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121",
"2113"}; /* Representation set B (EN Table 1) */ "2113"}; /* Representation set B (EN Table 1) */
char upc_check(unsigned char source[]) char upc_check(char source[])
{ /* Calculate the correct check digit for a UPC barcode */ { /* Calculate the correct check digit for a UPC barcode */
unsigned int i, count, check_digit; unsigned int i, count, check_digit;
count = 0; count = 0;
for (i = 0; i < ustrlen(source); i++) for (i = 0; i < strlen(source); i++)
{ {
count += ctoi(source[i]); count += ctoi(source[i]);
@ -64,16 +64,16 @@ char upc_check(unsigned char source[])
return itoc(check_digit); return itoc(check_digit);
} }
void upca_draw(unsigned char source[], char dest[]) void upca_draw(char source[], char dest[])
{ /* UPC A is usually used for 12 digit numbers, but this function takes a source of any length */ { /* UPC A is usually used for 12 digit numbers, but this function takes a source of any length */
unsigned int i, half_way; unsigned int i, half_way;
half_way = ustrlen(source) / 2; half_way = strlen(source) / 2;
/* start character */ /* start character */
concat (dest, "111"); concat (dest, "111");
for(i = 0; i <= ustrlen(source); i++) for(i = 0; i <= strlen(source); i++)
{ {
if (i == half_way) if (i == half_way)
{ {
@ -92,12 +92,14 @@ void upca_draw(unsigned char source[], char dest[])
void upca(struct zint_symbol *symbol, unsigned char source[], char dest[]) void upca(struct zint_symbol *symbol, unsigned char source[], char dest[])
{ /* Make a UPC A barcode when we haven't been given the check digit */ { /* Make a UPC A barcode when we haven't been given the check digit */
int length; int length;
char gtin[15];
length = ustrlen(source); strcpy(gtin, (char*)source);
source[length] = upc_check(source); length = strlen(gtin);
source[length + 1] = '\0'; gtin[length] = upc_check(gtin);
upca_draw(source, dest); gtin[length + 1] = '\0';
strcpy(symbol->text, (char*)source); upca_draw(gtin, dest);
strcpy(symbol->text, gtin);
} }
void upce(struct zint_symbol *symbol, unsigned char source[], char dest[]) void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
@ -181,7 +183,7 @@ void upce(struct zint_symbol *symbol, unsigned char source[], char dest[])
/* Get the check digit from the expanded UPCA code */ /* Get the check digit from the expanded UPCA code */
check_digit = upc_check((unsigned char*)equivalent); check_digit = upc_check(equivalent);
/* Use the number system and check digit information to choose a parity scheme */ /* Use the number system and check digit information to choose a parity scheme */
if(num_system == 1) { if(num_system == 1) {
@ -279,14 +281,14 @@ void add_on(unsigned char source[], char dest[], int mode)
/* ************************ EAN-13 ****************** */ /* ************************ EAN-13 ****************** */
char ean_check(unsigned char source[]) char ean_check(char source[])
{ /* Calculate the correct check digit for a EAN-13 barcode */ { /* Calculate the correct check digit for a EAN-13 barcode */
int i; int i;
unsigned int h, count, check_digit; unsigned int h, count, check_digit;
count = 0; count = 0;
h = ustrlen(source); h = strlen(source);
for (i = h - 1; i >= 0; i--) for (i = h - 1; i >= 0; i--)
{ {
count += ctoi(source[i]); count += ctoi(source[i]);
@ -305,16 +307,18 @@ void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[])
{ {
unsigned int length, i, half_way; unsigned int length, i, half_way;
char parity[6]; char parity[6];
char gtin[15];
strcpy(parity, ""); strcpy(parity, "");
strcpy(gtin, (char*)source);
/* Add the appropriate check digit */ /* Add the appropriate check digit */
length = ustrlen(source); length = strlen(gtin);
source[length] = ean_check(source); gtin[length] = ean_check(gtin);
source[length + 1] = '\0'; gtin[length + 1] = '\0';
/* Get parity for first half of the symbol */ /* Get parity for first half of the symbol */
lookup(NASET, EAN13Parity, source[0], parity); lookup(NASET, EAN13Parity, gtin[0], parity);
/* Now get on with the cipher */ /* Now get on with the cipher */
half_way = 7; half_way = 7;
@ -322,7 +326,7 @@ void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[])
/* start character */ /* start character */
concat (dest, "111"); concat (dest, "111");
for(i = 1; i <= ustrlen(source); i++) for(i = 1; i <= strlen(gtin); i++)
{ {
if (i == half_way) if (i == half_way)
{ {
@ -333,30 +337,32 @@ void ean13(struct zint_symbol *symbol, unsigned char source[], char dest[])
if(((i > 1) && (i < 7)) && (parity[i - 2] == 'B')) if(((i > 1) && (i < 7)) && (parity[i - 2] == 'B'))
{ {
lookup(NESET, EANsetB, source[i], dest); lookup(NESET, EANsetB, gtin[i], dest);
} }
else else
{ {
lookup(NESET, EANsetA, source[i], dest); lookup(NESET, EANsetA, gtin[i], dest);
} }
} }
/* stop character */ /* stop character */
concat (dest, "111"); concat (dest, "111");
strcpy(symbol->text, (char*)source); strcpy(symbol->text, gtin);
} }
void ean8(struct zint_symbol *symbol, unsigned char source[], char dest[]) void ean8(struct zint_symbol *symbol, unsigned char source[], char dest[])
{ /* Make an EAN-8 barcode when we haven't been given the check digit */ { /* Make an EAN-8 barcode when we haven't been given the check digit */
/* EAN-8 is basically the same as UPC-A but with fewer digits */ /* EAN-8 is basically the same as UPC-A but with fewer digits */
int length; int length;
char gtin[10];
length = ustrlen(source); strcpy(gtin, (char*)source);
source[length] = upc_check(source); length = strlen(gtin);
source[length + 1] = '\0'; gtin[length] = upc_check(gtin);
upca_draw(source, dest); gtin[length + 1] = '\0';
strcpy(symbol->text, (char*)source); upca_draw(gtin, dest);
strcpy(symbol->text, gtin);
} }
char isbn13_check(unsigned char source[]) /* For ISBN(13) only */ char isbn13_check(unsigned char source[]) /* For ISBN(13) only */