cstring_grow_to(ascii_line, sz); // should be enough in most cases
for (size_t i = 0 ; i < sz ; i++) {
- unsigned char byte = ebcdic[i];
- byte = ascii_car(byte);
- if (byte) {
- if (byte == '"') // double the quotes
- cstring_add_car(ascii_line, byte);
- cstring_add_car(ascii_line, byte);
+ unsigned char rbyte = ebcdic[i];
+ if (rbyte == '\0' && book->ignore_nulls) {
+ // Ignore NULL
} else {
- // Unknown char -> 0x2117 = (P) or ℗
- cstring_add_car(ascii_line, 0x21);
- cstring_add_car(ascii_line, 0x17);
-
- char bit[100];
- sprintf(bit, "%zu", i+1);
- char byte2[3];
- sprintf(byte2, "%02X", byte);
- cstring_t *tmp = new_cstring();
- cstring_add(tmp, "Bad character: ");
- cstring_add(tmp, "Byte ");
- cstring_add(tmp, bit);
- cstring_add(tmp, " = 0x");
- cstring_add(tmp, byte2);
- book->err_mess = cstring_convert(tmp);
+ unsigned char byte = ascii_car(rbyte);
+ if (byte) {
+ if (byte == '"') // double the quotes
+ cstring_add_car(ascii_line, byte);
+ cstring_add_car(ascii_line, byte);
+ } else {
+ // Unknown char -> 0x2117 = (P) or ℗
+ cstring_add_car(ascii_line, 0x21);
+ cstring_add_car(ascii_line, 0x17);
+
+ char bit[100];
+ sprintf(bit, "%zu", i+1);
+ char byte2[3];
+ sprintf(byte2, "%02X", rbyte);
+ cstring_t *tmp = new_cstring();
+ cstring_add(tmp, "Bad character: ");
+ cstring_add(tmp, "Byte ");
+ cstring_add(tmp, bit);
+ cstring_add(tmp, " = 0x");
+ cstring_add(tmp, byte2);
+ book->err_mess = cstring_convert(tmp);
+ }
}
}
}
CBOOK_OUT out_fmt = CBOOK_OUT_MSCSV;
int ignore_errors = 0;
+ int ignore_nulls = 0;
int debug = 0;
int raw_ebcdic = 0;
raw_ebcdic = 1;
} else if (!strcmp("--ignore-errors", arg)||!strcmp("-i", arg)){
ignore_errors = 1;
+ } else if (!strcmp("--ignore-null", arg)||!strcmp("-n", arg)){
+ ignore_nulls = 1;
} else if (!strcmp("--help", arg) || !strcmp("-h", arg)) {
help(argv[0]);
return 0;
book->raw_ebcdic = raw_ebcdic;
book->out_fmt = out_fmt;
book->ignore_errors = ignore_errors;
+ book->ignore_nulls = ignore_nulls;
book->debug = debug;
if (!read_book(book_file, book)) {
fprintf(stderr, "Failure to read book: %s\n", book_filename);
printf("\t-c / --output-csv : output is CSV\n");
printf("\t-d / --debug : add lot of DEBUG information\n");
printf("\t-i / --ignore-errors : ignore errors and continue\n");
+ printf("\t-n / --ignore-null : ignore NULL char values\n");
printf("\t-r / --raw-ebcdic : consider input to be raw EBCDIC\n");
printf("\tBOOK.PLI : a data description include book (in PL/1)\n");
printf("\tIN.DATA : the text/binary input file, defaults to stdin\n");