API overhaul part 1: removal of nullchar

This commit is contained in:
hooper114 2009-09-29 09:45:46 +00:00
parent 4455c6a893
commit 04b9a99241
42 changed files with 1458 additions and 1194 deletions

View file

@ -59,13 +59,12 @@ static char *C128Table[107] = {"212222", "222122", "222221", "121223", "121322",
"411113", "411311", "113141", "114131", "311141", "411131", "211412", "211214", "211232",
"2331112"};
int parunmodd(unsigned char llyth, char nullchar);
int parunmodd(unsigned char llyth);
void grwp(int *indexliste);
void dxsmooth(int *indexliste);
int a3_convert(unsigned char source, char nullchar) {
int a3_convert(unsigned char source) {
/* Annex A section 3 */
if(source == nullchar) { return 64; }
if(source < 32) { return source + 64; }
if((source >= 32) && (source <= 127)) { return source - 32; }
if((source >= 128) && (source <= 159)) { return (source - 128) + 64; }
@ -73,12 +72,8 @@ int a3_convert(unsigned char source, char nullchar) {
return (source - 128) - 32;
}
int character_subset_select(unsigned char source[], int input_position, char nullchar) {
int character_subset_select(unsigned char source[], int input_position) {
/* Section 4.5.2 - Determining the Character Subset Selector in a Row */
if(source[input_position] == nullchar) {
/* NULL character */
return MODEA;
}
if((source[input_position] >= '0') && (source[input_position + 1] <= '9')) {
/* Rule 1 */
@ -99,7 +94,7 @@ int character_subset_select(unsigned char source[], int input_position, char nul
return MODEB;
}
int data_encode_blockf(unsigned char source[], int subset_selector[], int blockmatrix[][62], int *columns_needed, int *rows_needed, int *final_mode, char nullchar, int gs1)
int data_encode_blockf(unsigned char source[], int subset_selector[], int blockmatrix[][62], int *columns_needed, int *rows_needed, int *final_mode, int gs1)
{
int i, j, input_position, input_length, current_mode, current_row, error_number;
int column_position, c, done, exit_status;
@ -120,7 +115,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
if(column_position == 0) {
/* The Beginning of a row */
c = (*columns_needed);
current_mode = character_subset_select(source, input_position, nullchar);
current_mode = character_subset_select(source, input_position);
subset_selector[current_row] = current_mode;
if((current_row == 0) && gs1) {
/* Section 4.4.7.1 */
@ -144,15 +139,15 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
/* Ensure that there is sufficient encodation capacity to continue (using the rules of Annex B.2). */
switch(current_mode) {
case MODEA: /* Table B1 applies */
if(parunmodd(source[input_position], nullchar) == ABORC) {
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
if(parunmodd(source[input_position]) == ABORC) {
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
done = 1;
}
if((parunmodd(source[input_position], nullchar) == SHIFTB) && (c == 1)) {
if((parunmodd(source[input_position]) == SHIFTB) && (c == 1)) {
/* Needs two symbols */
blockmatrix[current_row][column_position] = 100; /* Code B */
column_position++;
@ -184,15 +179,15 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
break;
case MODEB: /* Table B2 applies */
if(parunmodd(source[input_position], nullchar) == ABORC) {
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
if(parunmodd(source[input_position]) == ABORC) {
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
done = 1;
}
if((parunmodd(source[input_position], nullchar) == SHIFTA) && (c == 1)) {
if((parunmodd(source[input_position]) == SHIFTA) && (c == 1)) {
/* Needs two symbols */
blockmatrix[current_row][column_position] = 101; /* Code A */
column_position++;
@ -224,7 +219,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
break;
case MODEC: /* Table B3 applies */
if((parunmodd(source[input_position], nullchar) != ABORC) && (c == 1)) {
if((parunmodd(source[input_position]) != ABORC) && (c == 1)) {
/* Needs two symbols */
blockmatrix[current_row][column_position] = 101; /* Code A */
column_position++;
@ -232,7 +227,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
done = 1;
}
if(((parunmodd(source[input_position], nullchar) == ABORC) && (parunmodd(source[input_position + 1], nullchar) != ABORC))
if(((parunmodd(source[input_position]) == ABORC) && (parunmodd(source[input_position + 1]) != ABORC))
&& (c == 1)) {
/* Needs two symbols */
blockmatrix[current_row][column_position] = 101; /* Code A */
@ -258,7 +253,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
if(done == 0) {
if(((parunmodd(source[input_position], nullchar) == AORB) || (parunmodd(source[input_position], nullchar) == SHIFTA)) && (current_mode == MODEA)) {
if(((parunmodd(source[input_position]) == AORB) || (parunmodd(source[input_position]) == SHIFTA)) && (current_mode == MODEA)) {
/* Annex B section 1 rule 2 */
/* If in Code Subset A and the next data character can be encoded in Subset A encode the next
character. */
@ -268,7 +263,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
column_position++;
c--;
}
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -277,7 +272,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
if(done == 0) {
if(((parunmodd(source[input_position], nullchar) == AORB) || (parunmodd(source[input_position], nullchar) == SHIFTB)) && (current_mode == MODEB)) {
if(((parunmodd(source[input_position]) == AORB) || (parunmodd(source[input_position]) == SHIFTB)) && (current_mode == MODEB)) {
/* Annex B section 1 rule 3 */
/* If in Code Subset B and the next data character can be encoded in subset B, encode the next
character. */
@ -287,7 +282,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
column_position++;
c--;
}
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -296,7 +291,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
if(done == 0) {
if(((parunmodd(source[input_position], nullchar) == ABORC) && (parunmodd(source[input_position + 1], nullchar) == ABORC)) && (current_mode == MODEC)) {
if(((parunmodd(source[input_position]) == ABORC) && (parunmodd(source[input_position + 1]) == ABORC)) && (current_mode == MODEC)) {
/* Annex B section 1 rule 4 */
/* If in Code Subset C and the next data are 2 digits, encode them. */
blockmatrix[current_row][column_position] = (ctoi(source[input_position]) * 10) + ctoi(source[input_position + 1]);
@ -308,7 +303,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
if(done == 0) {
if(((current_mode == MODEA) || (current_mode == MODEB)) && ((parunmodd(source[input_position], nullchar) == ABORC) || (gs1 && (source[input_position] == '[')))) {
if(((current_mode == MODEA) || (current_mode == MODEB)) && ((parunmodd(source[input_position])== ABORC) || (gs1 && (source[input_position] == '[')))) {
/* Count the number of numeric digits */
/* If 4 or more numeric data characters occur together when in subsets A or B:
a. If there is an even number of numeric data characters, insert a Code C character before the
@ -321,7 +316,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
i++;
if(gs1 && (source[input_position + j] == '[')) { i++; }
j++;
} while((parunmodd(source[input_position + j], nullchar) == ABORC) || (gs1 && (source[input_position + j] == '[')));
} while((parunmodd(source[input_position + j]) == ABORC) || (gs1 && (source[input_position + j] == '[')));
i--;
if(i >= 4) {
@ -338,14 +333,14 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
current_mode = MODEC;
} else {
/* Annex B section 1 rule 5b */
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
}
done = 1;
} else {
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -355,7 +350,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
if(done == 0) {
if((current_mode == MODEB) && (parunmodd(source[input_position], nullchar) == SHIFTA)) {
if((current_mode == MODEB) && (parunmodd(source[input_position]) == SHIFTA)) {
/* Annex B section 1 rule 6 */
/* When in subset B and an ASCII control character occurs in the data:
a. If there is a lower case character immediately following the control character, insert a Shift
@ -372,7 +367,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
column_position++;
c--;
}
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -387,7 +382,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
column_position++;
c--;
}
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -398,14 +393,14 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
if(done == 0) {
if((current_mode == MODEA) && (parunmodd(source[input_position], nullchar) == SHIFTB)) {
if((current_mode == MODEA) && (parunmodd(source[input_position]) == SHIFTB)) {
/* Annex B section 1 rule 7 */
/* When in subset A and a lower case character occurs in the data:
a. If following that character, a control character occurs in the data before the occurrence of
another lower case character, insert a Shift character before the lower case character.
b. Otherwise, insert a Code B character before the lower case character to change to subset B. */
if((parunmodd(source[input_position + 1], nullchar) == SHIFTA) &&
(parunmodd(source[input_position + 2], nullchar) == SHIFTB)) {
if((parunmodd(source[input_position + 1]) == SHIFTA) &&
(parunmodd(source[input_position + 2]) == SHIFTB)) {
/* Annex B section 1 rule 7a */
blockmatrix[current_row][column_position] = 98; /* Shift */
column_position++;
@ -416,7 +411,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
column_position++;
c--;
}
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -431,7 +426,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
column_position++;
c--;
}
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -442,8 +437,8 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
}
if(done == 0) {
if((current_mode == MODEC) && ((parunmodd(source[input_position], nullchar) != ABORC) ||
(parunmodd(source[input_position + 1], nullchar) != ABORC))) {
if((current_mode == MODEC) && ((parunmodd(source[input_position]) != ABORC) ||
(parunmodd(source[input_position + 1]) != ABORC))) {
/* Annex B section 1 rule 8 */
/* When in subset C and a non-numeric character (or a single digit) occurs in the data, insert a Code
A or Code B character before that character, following rules 8a and 8b to determine between code
@ -451,7 +446,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
a. If an ASCII control character (eg NUL) occurs in the data before any lower case character, use
Code A.
b. Otherwise use Code B. */
if(parunmodd(source[input_position], nullchar) == SHIFTA) {
if(parunmodd(source[input_position]) == SHIFTA) {
/* Annex B section 1 rule 8a */
blockmatrix[current_row][column_position] = 101; /* Code A */
column_position++;
@ -462,7 +457,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
column_position++;
c--;
}
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -478,7 +473,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
column_position++;
c--;
}
blockmatrix[current_row][column_position] = a3_convert(source[input_position], nullchar);
blockmatrix[current_row][column_position] = a3_convert(source[input_position]);
column_position++;
c--;
input_position++;
@ -573,7 +568,7 @@ int data_encode_blockf(unsigned char source[], int subset_selector[], int blockm
return error_number;
}
int codablock(struct zint_symbol *symbol, unsigned char source[])
int codablock(struct zint_symbol *symbol, unsigned char source[], int length)
{
int error_number, input_length, i, j, k;
int rows_needed, columns_needed;
@ -588,7 +583,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[])
int gs1;
error_number = 0;
input_length = ustrlen(source);
input_length = length;
final_mode = MODEA;
if(input_length > 5450) {
@ -602,7 +597,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[])
estimate_codelength = 0.0;
last_mode = AORB; /* Codablock always starts with Code A */
for(i = 0; i < input_length; i++) {
this_mode = parunmodd(source[i], symbol->nullchar);
this_mode = parunmodd(source[i]);
if(this_mode != last_mode) {
estimate_codelength += 1.0;
}
@ -629,7 +624,7 @@ int codablock(struct zint_symbol *symbol, unsigned char source[])
}
/* Encode the data */
error_number = data_encode_blockf(source, subset_selector, blockmatrix, &columns_needed, &rows_needed, &final_mode, symbol->nullchar, gs1);
error_number = data_encode_blockf(source, subset_selector, blockmatrix, &columns_needed, &rows_needed, &final_mode, gs1);
if(error_number > 0) {
if(error_number == ERROR_TOO_LONG) {
strcpy(symbol->errtxt, "Input data too long");