Add leading zeroes rather than fail

This commit is contained in:
hooper114 2008-10-13 20:29:04 +00:00
parent 3db0fa77e4
commit c6e035bde8
3 changed files with 33 additions and 20 deletions

View file

@ -244,6 +244,7 @@ int itf14(struct zint_symbol *symbol, unsigned char source[])
int i, error_number, h, zeroes;
unsigned int count, check_digit;
char localstr[15];
char checkstr[3];
error_number = 0;
@ -282,8 +283,9 @@ int itf14(struct zint_symbol *symbol, unsigned char source[])
}
check_digit = 10 - (count%10);
if (check_digit == 10) { check_digit = 0; }
localstr[h] = itoc(check_digit);
localstr[h + 1] = '\0';
checkstr[0] = itoc(check_digit);
checkstr[1] = '\0';
concat(localstr, checkstr);
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr);
strcpy(symbol->text, localstr);
return error_number;
@ -328,7 +330,7 @@ int dpleit(struct zint_symbol *symbol, unsigned char source[])
if (check_digit == 10) { check_digit = 0; }
checkstr[0] = itoc(check_digit);
checkstr[1] = '\0';
strcpy(localstr, checkstr);
concat(localstr, checkstr);
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr);
strcpy(symbol->text, localstr);
return error_number;
@ -355,8 +357,8 @@ int dpident(struct zint_symbol *symbol, unsigned char source[])
strcpy(localstr, "");
zeroes = 11 - h;
for(i = 0; i < zeroes; i++)
strcpy(localstr, "0");
strcpy(localstr, (char *)source);
concat(localstr, "0");
concat(localstr, (char *)source);
for (i = 10; i >= 0; i--)
{
@ -371,7 +373,7 @@ int dpident(struct zint_symbol *symbol, unsigned char source[])
if (check_digit == 10) { check_digit = 0; }
checkstr[0] = itoc(check_digit);
checkstr[1] = '\0';
strcpy(localstr, checkstr);
concat(localstr, checkstr);
error_number = interleaved_two_of_five(symbol, (unsigned char *)localstr);
strcpy(symbol->text, localstr);
return error_number;

View file

@ -247,12 +247,14 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[])
int i, error_number;
unsigned int h, count, check_digit;
char localstr[8];
int zeroes;
error_number = 0;
count = 0;
h = ustrlen(source);
if(h != 6) {
if(h > 6) {
strcpy(symbol->errtxt, "Input wrong length [521]");
return ERROR_TOO_LONG;
}
@ -262,23 +264,29 @@ int pharmazentral(struct zint_symbol *symbol, unsigned char source[])
return error_number;
}
for (i = 0; i < h; i++)
strcpy(localstr, "");
zeroes = 6 - h;
for(i = 0; i < zeroes; i++)
concat(localstr, "0");
concat(localstr, (char *)source);
for (i = 0; i < 6; i++)
{
count += (i + 2) * ctoi(source[i]);
count += (i + 2) * ctoi(localstr[i]);
}
for(i = h + 1; i >= 1; i--)
for(i = 7; i >= 1; i--)
{
source[i] = source[i - 1];
localstr[i] = localstr[i - 1];
}
source[0] = '-';
localstr[0] = '-';
check_digit = count%11;
if (check_digit == 11) { check_digit = 0; }
source[h + 1] = itoc(check_digit);
source[h + 2] = '\0';
error_number = c39(symbol, source);
strcpy(symbol->text, (char*)source);
localstr[7] = itoc(check_digit);
localstr[8] = '\0';
error_number = c39(symbol, (unsigned char *)localstr);
strcpy(symbol->text, localstr);
return error_number;
}

View file

@ -872,7 +872,7 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[])
{
/* Add check digit if encoding an NVE18 symbol */
int error_number, zeroes, i, nve_check, total_sum, sourcelen;
unsigned char localstr[20], checkstr[3];
char localstr[20], checkstr[3];
sourcelen = ustrlen(source);
if(sourcelen > 17) {
@ -903,10 +903,11 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[])
}
nve_check = 10 - total_sum%10;
if(nve_check == 10) { nve_check = 0; }
checkstr[1] = '\0';
checkstr[0] = itoc(nve_check);
concat(localstr, checkstr);
error_number = code_128(symbol, localstr);
error_number = code_128(symbol, (unsigned char *)localstr);
return error_number;
}
@ -914,7 +915,7 @@ int nve_18(struct zint_symbol *symbol, unsigned char source[])
int ean_14(struct zint_symbol *symbol, unsigned char source[])
{
/* EAN-14 - A version of EAN-128 */
int input_length, i, count, check_digit;
int input_length, i, j, count, check_digit;
int error_number, zeroes;
unsigned char ean128_equiv[20];
@ -934,7 +935,9 @@ int ean_14(struct zint_symbol *symbol, unsigned char source[])
concat((char*)ean128_equiv, "[01]");
zeroes = 13 - input_length;
for(i = 0; i < zeroes; i++) {
concat(ean128_equiv, "0");
j = ustrlen(ean128_equiv);
ean128_equiv[j] = '0';
ean128_equiv[j + 1] = '\0';
}
concat((char*)ean128_equiv, (char*)source);