add --ingore-null (-n) option
authorNiki Roo <niki@nikiroo.be>
Thu, 26 Sep 2024 15:23:38 +0000 (17:23 +0200)
committerNiki Roo <niki@nikiroo.be>
Thu, 26 Sep 2024 15:23:38 +0000 (17:23 +0200)
src/cbook/cbook.h [changed mode: 0755->0644]
src/cbook/cbook_csv.c [changed mode: 0755->0644]
src/cbook/cbook_main.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 7d69c06..a4e6768
@@ -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;
old mode 100755 (executable)
new mode 100644 (file)
index 86e0424..8dd405c
@@ -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);
+                       }
                }
        }
 }
old mode 100755 (executable)
new mode 100644 (file)
index 49b6e9f..0935cf0
@@ -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");