Allow escape character processing in batch mode

Suggested by Martin Zizka, Fixes #96
This commit is contained in:
Robin Stuart 2018-03-30 11:40:44 +01:00
parent 9a5e5f3a9a
commit e6618f1a1b
2 changed files with 31 additions and 16 deletions

View File

@ -893,6 +893,7 @@ int escape_char_process(struct zint_symbol *symbol, unsigned char *input_string,
int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int in_length) { int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int in_length) {
int error_number, error_buffer, i; int error_number, error_buffer, i;
int input_mode = symbol->input_mode;
#ifdef _MSC_VER #ifdef _MSC_VER
unsigned char* local_source; unsigned char* local_source;
#endif #endif
@ -1064,7 +1065,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
} }
/* Start acting on input mode */ /* Start acting on input mode */
if (symbol->input_mode == GS1_MODE) { if (input_mode == GS1_MODE) {
for (i = 0; i < in_length; i++) { for (i = 0; i < in_length; i++) {
if (source[i] == '\0') { if (source[i] == '\0') {
strcpy(symbol->errtxt, "219: NULL characters not permitted in GS1 mode"); strcpy(symbol->errtxt, "219: NULL characters not permitted in GS1 mode");
@ -1088,24 +1089,24 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
local_source[in_length] = '\0'; local_source[in_length] = '\0';
} }
if (symbol->input_mode & ESCAPE_MODE) { if (input_mode & ESCAPE_MODE) {
error_number = escape_char_process(symbol, local_source, &in_length); error_number = escape_char_process(symbol, local_source, &in_length);
if (error_number != 0) { if (error_number != 0) {
error_tag(symbol->errtxt, error_number); error_tag(symbol->errtxt, error_number);
return error_number; return error_number;
} }
symbol->input_mode -= ESCAPE_MODE; input_mode -= ESCAPE_MODE;
} }
if ((symbol->input_mode < 0) || (symbol->input_mode > 2)) { if ((input_mode < 0) || (input_mode > 2)) {
symbol->input_mode = DATA_MODE; input_mode = DATA_MODE;
} }
if ((symbol->eci != 3) && (symbol->eci != 26)) { if ((symbol->eci != 3) && (symbol->eci != 26)) {
symbol->input_mode = DATA_MODE; input_mode = DATA_MODE;
} }
if (symbol->input_mode == UNICODE_MODE) { if (input_mode == UNICODE_MODE) {
strip_bom(local_source, &in_length); strip_bom(local_source, &in_length);
} }
@ -1129,7 +1130,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
} }
if ((error_number == ZINT_ERROR_INVALID_DATA) && (supports_eci(symbol->symbology) if ((error_number == ZINT_ERROR_INVALID_DATA) && (supports_eci(symbol->symbology)
&& (symbol->input_mode == UNICODE_MODE))) { && (input_mode == UNICODE_MODE))) {
/* Try another ECI mode */ /* Try another ECI mode */
symbol->eci = get_best_eci(local_source, in_length); symbol->eci = get_best_eci(local_source, in_length);

View File

@ -199,7 +199,7 @@ int batch_process(struct zint_symbol *symbol, char *filename, int mirror_mode, c
char number[12], reverse_number[12]; char number[12], reverse_number[12];
int inpos, local_line_count; int inpos, local_line_count;
char format_string[127], reversed_string[127], format_char; char format_string[127], reversed_string[127], format_char;
int format_len, i; int format_len, i, o;
char adjusted[2]; char adjusted[2];
memset(buffer, 0, sizeof (unsigned char) * 7100); memset(buffer, 0, sizeof (unsigned char) * 7100);
@ -300,9 +300,12 @@ int batch_process(struct zint_symbol *symbol, char *filename, int mirror_mode, c
} }
} else { } else {
/* Name the output file from the data being processed */ /* Name the output file from the data being processed */
for (i = 0; (i < posn && i < 250); i++) { i = 0;
o = 0;
do {
//for (i = 0; (i < posn && i < 250); i++) {
if (buffer[i] < 0x20) { if (buffer[i] < 0x20) {
output_file[i] = '_'; output_file[o] = '_';
} else { } else {
switch (buffer[i]) { switch (buffer[i]) {
case 0x21: // ! case 0x21: // !
@ -313,19 +316,30 @@ int batch_process(struct zint_symbol *symbol, char *filename, int mirror_mode, c
case 0x3c: // < case 0x3c: // <
case 0x3e: // > case 0x3e: // >
case 0x3f: // ? case 0x3f: // ?
case 0x5c: // Backslash
case 0x7c: // | case 0x7c: // |
case 0x7f: // DEL case 0x7f: // DEL
output_file[i] = '_'; output_file[o] = '_';
break; break;
default: default:
output_file[i] = buffer[i]; output_file[o] = buffer[i];
} }
} }
}
// Skip escape characters
if ((buffer[i] == 0x5c) && (symbol->input_mode & ESCAPE_MODE)) {
i++;
if (buffer[i] == 'x') {
i += 2;
}
}
i++;
o++;
} while (i < posn && o < 250);
/* Add file extension */ /* Add file extension */
output_file[i] = '.'; output_file[o] = '.';
output_file[i + 1] = '\0'; output_file[o + 1] = '\0';
strcat(output_file, filetype); strcat(output_file, filetype);
} }