mirror of
https://git.code.sf.net/p/zint/code
synced 2025-05-20 10:15:10 -04:00
Make CLI errors more consistent
Should now output errors and warnings in a consistent and predictable fashion. This is not a neat solution, but functional for now.
This commit is contained in:
parent
ae57d413bf
commit
d2161ffb20
2 changed files with 58 additions and 46 deletions
|
@ -344,7 +344,7 @@ int batch_process(struct zint_symbol *symbol, char *filename, int mirror_mode, c
|
|||
posn++;
|
||||
}
|
||||
if (posn > 7090) {
|
||||
fprintf(stderr, "103 on line %d: Input data too long\n", line_count);
|
||||
fprintf(stderr, "On line %d: Error 103: Input data too long\n", line_count);
|
||||
fflush(stderr);
|
||||
do {
|
||||
character = fgetc(file);
|
||||
|
@ -353,7 +353,7 @@ int batch_process(struct zint_symbol *symbol, char *filename, int mirror_mode, c
|
|||
} while ((!feof(file)) && (line_count < 2000000000));
|
||||
|
||||
if (character != '\n') {
|
||||
fprintf(stderr, "warning 104: No newline at end of file\n");
|
||||
fprintf(stderr, "Warning 104: No newline at end of file\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
@ -503,7 +503,7 @@ int main(int argc, char **argv) {
|
|||
my_symbol->scale = (float) (atof(optarg));
|
||||
if (my_symbol->scale < 0.01) {
|
||||
/* Zero and negative values are not permitted */
|
||||
fprintf(stderr, "105: Invalid scale value\n");
|
||||
fprintf(stderr, "Warning 105: Invalid scale value\n");
|
||||
fflush(stderr);
|
||||
my_symbol->scale = 1.0;
|
||||
}
|
||||
|
@ -512,7 +512,7 @@ int main(int argc, char **argv) {
|
|||
my_symbol->dot_size = (float) (atof(optarg));
|
||||
if (my_symbol->dot_size < 0.01) {
|
||||
/* Zero and negative values are not permitted */
|
||||
fprintf(stderr, "106: Invalid dot radius value\n");
|
||||
fprintf(stderr, "Warning 106: Invalid dot radius value\n");
|
||||
fflush(stderr);
|
||||
my_symbol->dot_size = 4.0F / 5.0F;
|
||||
}
|
||||
|
@ -520,26 +520,26 @@ int main(int argc, char **argv) {
|
|||
if (!strcmp(long_options[option_index].name, "border")) {
|
||||
error_number = validator(NESET, optarg);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
fprintf(stderr, "107: Invalid border width\n");
|
||||
fprintf(stderr, "Error 107: Invalid border width\n");
|
||||
exit(1);
|
||||
}
|
||||
if ((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) {
|
||||
my_symbol->border_width = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "108: Border width out of range\n");
|
||||
fprintf(stderr, "Warning 108: Border width out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
if (!strcmp(long_options[option_index].name, "height")) {
|
||||
error_number = validator(NESET, optarg);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
fprintf(stderr, "109: Invalid symbol height\n");
|
||||
fprintf(stderr, "Error 109: Invalid symbol height\n");
|
||||
exit(1);
|
||||
}
|
||||
if ((atoi(optarg) >= 1) && (atoi(optarg) <= 1000)) {
|
||||
my_symbol->height = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "110: Symbol height out of range\n");
|
||||
fprintf(stderr, "Warning 110: Symbol height out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ int main(int argc, char **argv) {
|
|||
if ((atoi(optarg) >= 1) && (atoi(optarg) <= 66)) {
|
||||
my_symbol->option_2 = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "111: Number of columns out of range\n");
|
||||
fprintf(stderr, "Warning 111: Number of columns out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
@ -556,7 +556,7 @@ int main(int argc, char **argv) {
|
|||
if ((atoi(optarg) >= 1) && (atoi(optarg) <= 44)) {
|
||||
my_symbol->option_1 = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "112: Number of rows out of range\n");
|
||||
fprintf(stderr, "Warning 112: Number of rows out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
@ -564,7 +564,7 @@ int main(int argc, char **argv) {
|
|||
if ((atoi(optarg) >= 1) && (atoi(optarg) <= 84)) {
|
||||
my_symbol->option_2 = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "113: Invalid Version\n");
|
||||
fprintf(stderr, "Warning 113: Invalid Version\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
@ -572,7 +572,7 @@ int main(int argc, char **argv) {
|
|||
if ((atoi(optarg) >= 1) && (atoi(optarg) <= 8)) {
|
||||
my_symbol->option_1 = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "114: ECC level out of range\n");
|
||||
fprintf(stderr, "Warning 114: ECC level out of range\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
@ -580,7 +580,7 @@ int main(int argc, char **argv) {
|
|||
if (strlen(optarg) <= 90) {
|
||||
strcpy(my_symbol->primary, optarg);
|
||||
} else {
|
||||
fprintf(stderr, "115: Primary data string too long");
|
||||
fprintf(stderr, "Error 115: Primary data string too long");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
@ -588,7 +588,7 @@ int main(int argc, char **argv) {
|
|||
if ((optarg[0] >= '0') && (optarg[0] <= '6')) {
|
||||
my_symbol->option_1 = optarg[0] - '0';
|
||||
} else {
|
||||
fprintf(stderr, "116: Invalid mode\n");
|
||||
fprintf(stderr, "Warning 116: Invalid mode\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
@ -596,7 +596,7 @@ int main(int argc, char **argv) {
|
|||
/* Only certain inputs allowed */
|
||||
error_number = validator(NESET, optarg);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
fprintf(stderr, "117: Invalid rotation parameter\n");
|
||||
fprintf(stderr, "Error 117: Invalid rotation parameter\n");
|
||||
exit(1);
|
||||
}
|
||||
switch (atoi(optarg)) {
|
||||
|
@ -626,7 +626,7 @@ int main(int argc, char **argv) {
|
|||
if ((atoi(optarg) >= 0) && (atoi(optarg) <= 999999)) {
|
||||
my_symbol->eci = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "118: Invalid ECI code\n");
|
||||
fprintf(stderr, "Warning 118: Invalid ECI code\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
@ -655,7 +655,7 @@ int main(int argc, char **argv) {
|
|||
case 'b':
|
||||
error_number = validator(NESET, optarg);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
fprintf(stderr, "119: Invalid barcode type\n");
|
||||
fprintf(stderr, "Error 119: Invalid barcode type\n");
|
||||
exit(1);
|
||||
}
|
||||
my_symbol->symbology = atoi(optarg);
|
||||
|
@ -664,13 +664,13 @@ int main(int argc, char **argv) {
|
|||
case 'w':
|
||||
error_number = validator(NESET, optarg);
|
||||
if (error_number == ZINT_ERROR_INVALID_DATA) {
|
||||
fprintf(stderr, "120: Invalid whitespace value\n");
|
||||
fprintf(stderr, "Error 120: Invalid whitespace value\n");
|
||||
exit(1);
|
||||
}
|
||||
if ((atoi(optarg) >= 0) && (atoi(optarg) <= 1000)) {
|
||||
my_symbol->whitespace_width = atoi(optarg);
|
||||
} else {
|
||||
fprintf(stderr, "121: Whitespace value out of range");
|
||||
fprintf(stderr, "Warning 121: Whitespace value out of range");
|
||||
fflush(stderr);
|
||||
}
|
||||
break;
|
||||
|
@ -682,22 +682,23 @@ int main(int argc, char **argv) {
|
|||
strcat(my_symbol->outfile, filetype);
|
||||
}
|
||||
error_number = ZBarcode_Encode(my_symbol, (unsigned char*) optarg, strlen(optarg));
|
||||
if (error_number < 5) {
|
||||
generated = 1;
|
||||
if (error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
}
|
||||
if (error_number < 5) {
|
||||
error_number = ZBarcode_Print(my_symbol, rotate_angle);
|
||||
|
||||
if (error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
ZBarcode_Delete(my_symbol);
|
||||
return 1;
|
||||
}
|
||||
error_number = ZBarcode_Print(my_symbol, rotate_angle);
|
||||
}
|
||||
generated = 1;
|
||||
if (error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
ZBarcode_Delete(my_symbol);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "122: Cannot define data in batch mode");
|
||||
fprintf(stderr, "Warning 122: Can't define data in batch mode");
|
||||
fflush(stderr);
|
||||
}
|
||||
break;
|
||||
|
@ -705,19 +706,19 @@ int main(int argc, char **argv) {
|
|||
case 'i': /* Take data from file */
|
||||
if (batch_mode == 0) {
|
||||
error_number = ZBarcode_Encode_File(my_symbol, optarg);
|
||||
if (error_number < 5) {
|
||||
if (error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
}
|
||||
error_number = ZBarcode_Print(my_symbol, rotate_angle);
|
||||
}
|
||||
generated = 1;
|
||||
if (error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
ZBarcode_Delete(my_symbol);
|
||||
return 1;
|
||||
}
|
||||
if (error_number < 5) {
|
||||
error_number = ZBarcode_Print(my_symbol, rotate_angle);
|
||||
if (error_number != 0) {
|
||||
fprintf(stderr, "%s\n", my_symbol->errtxt);
|
||||
fflush(stderr);
|
||||
ZBarcode_Delete(my_symbol);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Take each line of text as a separate data set */
|
||||
|
@ -748,13 +749,13 @@ int main(int argc, char **argv) {
|
|||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "123: ?? getopt error 0%o\n", c);
|
||||
fprintf(stderr, "Error 123: ?? getopt error 0%o\n", c);
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
fprintf(stderr, "125: Invalid option\n");
|
||||
fprintf(stderr, "Error 125: Invalid option\n");
|
||||
while (optind < argc)
|
||||
fprintf(stderr, "%s", argv[optind++]);
|
||||
fprintf(stderr, "\n");
|
||||
|
@ -762,7 +763,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (generated == 0) {
|
||||
fprintf(stderr, "124: No data received, no symbol generated\n");
|
||||
fprintf(stderr, "Warning 124: No data received, no symbol generated\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue