From a8451bb0bbad2626fc8ec945d2b0739b3c5a9ed6 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 26 Sep 2024 17:23:38 +0200 Subject: [PATCH] add --ingore-null (-n) option --- src/cbook/cbook.h | 1 + src/cbook/cbook_csv.c | 46 +++++++++++++++++++++++------------------- src/cbook/cbook_main.c | 5 +++++ 3 files changed, 31 insertions(+), 21 deletions(-) mode change 100755 => 100644 src/cbook/cbook.h mode change 100755 => 100644 src/cbook/cbook_csv.c mode change 100755 => 100644 src/cbook/cbook_main.c diff --git a/src/cbook/cbook.h b/src/cbook/cbook.h old mode 100755 new mode 100644 index 7d69c06..a4e6768 --- a/src/cbook/cbook.h +++ b/src/cbook/cbook.h @@ -63,6 +63,7 @@ typedef struct { int finished; int unaligned; int ignore_errors; + int ignore_nulls; int debug; size_t err_line; char *err_mess; diff --git a/src/cbook/cbook_csv.c b/src/cbook/cbook_csv.c old mode 100755 new mode 100644 index 86e0424..8dd405c --- a/src/cbook/cbook_csv.c +++ b/src/cbook/cbook_csv.c @@ -441,28 +441,32 @@ static void ascii(book_t *book, FILE *outfile, char *ebcdic, size_t sz) { 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); + } } } } diff --git a/src/cbook/cbook_main.c b/src/cbook/cbook_main.c old mode 100755 new mode 100644 index 49b6e9f..0935cf0 --- a/src/cbook/cbook_main.c +++ b/src/cbook/cbook_main.c @@ -38,6 +38,7 @@ int main(int argc, char **argv) { CBOOK_OUT out_fmt = CBOOK_OUT_MSCSV; int ignore_errors = 0; + int ignore_nulls = 0; int debug = 0; int raw_ebcdic = 0; @@ -55,6 +56,8 @@ int main(int argc, char **argv) { 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; @@ -115,6 +118,7 @@ int main(int argc, char **argv) { 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); @@ -208,6 +212,7 @@ void help(char *program) { 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"); -- 2.27.0