change private function calls
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 5 Dec 2022 12:58:15 +0000 (13:58 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 5 Dec 2022 12:58:15 +0000 (13:58 +0100)
code.c
compress.c
debug.h
fprintf.c
fprintf.h

diff --git a/code.c b/code.c
index 6f04c182c78267dd6f5e5a0124a6cc59764fe5f1..70b170ec1857b88391215f1095769c6342651536 100644 (file)
--- a/code.c
+++ b/code.c
@@ -46,7 +46,7 @@ int codcpy (char *dst, size_t n, char *src)
             return i;
         }
     }
-    VERBOSE (ERROR, _fprintf (stdout, "Buffer too short\n"));
+    VERBOSE (ERROR, myfprintf (stdout, "Buffer too short\n"));
 
     return -1;
 }
index 91f0d0e1d1ea993550114da81dc9664796f2576b..26e922e180572abed2891a8039f7b1b409617538 100644 (file)
@@ -1,9 +1,10 @@
 /* depend: */
 /* cflags: */
-/* linker: code.o debug.o fprintf.o */
+/* linker: atoi.o code.o debug.o fprintf.o */
 
 #include <malloc.h>
 #include <stdio.h>
+#include "atoi.h"
 #include "code.h"
 #include "debug.h"
 #include "fprintf.h"
@@ -23,11 +24,11 @@ char *progname = NULL;
 void usage (int ret)
 {
     FILE *fd = ret ? stderr : stdout;
-    _fprintf (fd, "usage: %s\n", progname);
-    _fprintf (fd, " -h : help message\n");
-    _fprintf (fd, " -i <file>: input file\n");
-    _fprintf (fd, " -o <file>: output file\n");
-    _fprintf (fd, " -v : verbose level (%d)\n", verbose);
+    myfprintf (fd, "usage: %s\n", progname);
+    myfprintf (fd, " -h : help message\n");
+    myfprintf (fd, " -i <file>: input file\n");
+    myfprintf (fd, " -o <file>: output file\n");
+    myfprintf (fd, " -v : verbose level (%d)\n", verbose);
 
     exit (ret);
 }
@@ -53,19 +54,19 @@ int *create_table (char *filename)
     /* memory allocation */
     table = (int *) calloc (NB_BYTES, sizeof (int));
     if (table == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't allocate memory\n"));
+        VERBOSE (ERROR, myfprintf (stdout, "can't allocate memory\n"));
         return NULL;
     }
-    VERBOSE (INFO, _fprintf (stdout, "memory allocated\n"));
+    VERBOSE (INFO, myfprintf (stdout, "memory allocated\n"));
 
     /* open file */
     fid = fopen (filename, "rb");
     if (fid == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't open file '%s'\n", filename));
+        VERBOSE (ERROR, myfprintf (stdout, "can't open file '%s'\n", filename));
         free (table);
         return NULL;
     }
-    VERBOSE (INFO, _fprintf (stdout, "file '%s' opened\n", filename));
+    VERBOSE (INFO, myfprintf (stdout, "file '%s' opened\n", filename));
 
     /* read file */
     while (!feof (fid)) {
@@ -90,10 +91,10 @@ void print_occ_table (int *table)
 {
     int i;
 
-    _fprintf (stdout, "Occurence table\n");
+    myfprintf (stdout, "Occurence table\n");
     for (i = 0; i < NB_BYTES; i++) {
         if (table[i]) {
-            _fprintf (stdout, "0x%02x '%c': %d\n", i, ((i < 32) || (i > 127)) ? '.' : i, table[i]);
+            myfprintf (stdout, "0x%02x '%c': %d\n", i, ((i < 32) || (i > 127)) ? '.' : i, table[i]);
         }
     }
 }
@@ -128,7 +129,7 @@ leaf_t **init_forest (int *table)
     /* allocate memory */
     leafs = (leaf_t **) calloc (nb_leafs + 1, sizeof (leaf_t *));
     if (leafs == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't allocate memory\n"));
+        VERBOSE (ERROR, myfprintf (stdout, "can't allocate memory\n"));
         return NULL;
     }
 
@@ -137,7 +138,7 @@ leaf_t **init_forest (int *table)
         if (table[i] > 0) {
             leafs[l] = (leaf_t *) calloc (1, sizeof (leaf_t));
             if (leafs[l] == NULL) {
-                VERBOSE (ERROR, _fprintf (stdout, "can't allocate memory\n"));
+                VERBOSE (ERROR, myfprintf (stdout, "can't allocate memory\n"));
                 return NULL;
             }
             leafs[l]->occ = table[i];
@@ -195,12 +196,12 @@ leaf_t *create_tree (leaf_t **leafs)
 
         /* create branch */
         if ((last == -1) || (ante == -1)) {
-            VERBOSE (ERROR, _fprintf (stdout, "error during tree building\n"));
+            VERBOSE (ERROR, myfprintf (stdout, "error during tree building\n"));
             return NULL;
         }
         branch = (leaf_t *) calloc (1, sizeof (leaf_t));
         if (branch == NULL) {
-            VERBOSE (ERROR, _fprintf (stdout, "can't allocate memory\n"));
+            VERBOSE (ERROR, myfprintf (stdout, "can't allocate memory\n"));
             return NULL;
         }
         branch->left = leafs[last];
@@ -256,7 +257,7 @@ code_t *create_code (leaf_t *root)
     /* allocate table */
     table = (code_t *) calloc (NB_BYTES, sizeof (code_t));
     if (table == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't allocate memory\n"));
+        VERBOSE (ERROR, myfprintf (stdout, "can't allocate memory\n"));
         return NULL;
     }
 
@@ -274,13 +275,13 @@ void print_code_table (code_t *codes)
     char *code;
     int i;
 
-    _fprintf (stdout, "Code table\n");
+    myfprintf (stdout, "Code table\n");
     for (i = 0; i < NB_BYTES; i++) {
         code = (char *)(codes + i);
         if (codlen (code) == 0) {
             continue;
         }
-        _fprintf (stdout, "0x%02x '%c': %s\n", i, ((i < 32) || (i > 127)) ? '.' : i, code);
+        myfprintf (stdout, "0x%02x '%c': %s\n", i, ((i < 32) || (i > 127)) ? '.' : i, code);
     }
 }
 
@@ -391,9 +392,9 @@ void print_header (byte_t *header)
     length = (header[3] << 8) + header[4];
     VERBOSE (DEBUG, PRINTF ("lengh: %d\n", length));
     for (i = 0; i < length + 6; i++) {
-        _fprintf (stdout, "%02x", header[i]);
+        myfprintf (stdout, "%02x", header[i]);
     }
-    _fprintf (stdout, "\n");
+    myfprintf (stdout, "\n");
 }
 
 /* write crompressed file */
@@ -413,18 +414,18 @@ int write_compress (char *output, char *input, code_t *codes, byte_t *header)
     /* open input file */
     fin = fopen (input, "rb");
     if (fin == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't open file '%s' for reading\n", input));
+        VERBOSE (ERROR, myfprintf (stdout, "can't open file '%s' for reading\n", input));
         return 1;
     }
-    VERBOSE (INFO, _fprintf (stdout, "file '%s' opened\n", input));
+    VERBOSE (INFO, myfprintf (stdout, "file '%s' opened\n", input));
 
     /* open output file */
     fout = fopen (output, "wb");
     if (fin == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't open file '%s' for writing\n", output));
+        VERBOSE (ERROR, myfprintf (stdout, "can't open file '%s' for writing\n", output));
         return 1;
     }
-    VERBOSE (INFO, _fprintf (stdout, "file '%s' opened\n", output));
+    VERBOSE (INFO, myfprintf (stdout, "file '%s' opened\n", output));
 
     /* write header */
     length = (header[3] << 8) + header[4];
@@ -499,10 +500,10 @@ code_t *read_header (char *filename) {
     /* open file */
     fid = fopen (filename, "rb");
     if (fid == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't open file '%s'\n", filename));
+        VERBOSE (ERROR, myfprintf (stdout, "can't open file '%s'\n", filename));
         return NULL;
     }
-    VERBOSE (INFO, _fprintf (stdout, "file '%s' opened\n", filename));
+    VERBOSE (INFO, myfprintf (stdout, "file '%s' opened\n", filename));
 
     /* read magic number */
     nb = fread (buffer, 1, 6, fid);
@@ -523,7 +524,7 @@ code_t *read_header (char *filename) {
     }
     fclose (fid);
     if (mode == 0) {
-        VERBOSE (ERROR, _fprintf (stdout, "incorrect file\n"));
+        VERBOSE (ERROR, myfprintf (stdout, "incorrect file\n"));
         return NULL;
     }
 
@@ -552,14 +553,14 @@ code_t *read_header (char *filename) {
     }
     if (((mode == 1) && (size - 256 != (l + 7) / 8)) ||
         ((mode == 2) && (size - 2 * nb - 1 != (l + 7) / 8))) {
-        VERBOSE (ERROR, _fprintf (stdout, "incorrect code table length\n"));
+        VERBOSE (ERROR, myfprintf (stdout, "incorrect code table length\n"));
         return NULL;
     }
 
     /* allocate table */
     table = (code_t *) calloc (NB_BYTES, sizeof (code_t));
     if (table == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't allocate memory\n"));
+        VERBOSE (ERROR, myfprintf (stdout, "can't allocate memory\n"));
         return NULL;
     }
 
@@ -605,25 +606,25 @@ int write_decompress (char *output, char *input, code_t *codes)
     /* open file for reading */
     fin = fopen (input, "rb");
     if (fin == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't open file '%s' for reading\n", input));
+        VERBOSE (ERROR, myfprintf (stdout, "can't open file '%s' for reading\n", input));
         return 1;
     }
-    VERBOSE (INFO, _fprintf (stdout, "file '%s' opened\n", input));
+    VERBOSE (INFO, myfprintf (stdout, "file '%s' opened\n", input));
 
     /* read magic number */
     nb = fread (bufhea, 1, 6, fin);
     if (nb != 6) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't read file\n"));
+        VERBOSE (ERROR, myfprintf (stdout, "can't read file\n"));
         fclose (fin);
         return 1;
     }
     size = (bufhea[3] << 8) + bufhea[4];
-    VERBOSE (DEBUG, _fprintf (stdout, "table size: %d\n", size));
+    VERBOSE (DEBUG, myfprintf (stdout, "table size: %d\n", size));
     rem = bufhea[5];
-    VERBOSE (DEBUG, _fprintf (stdout, "remainder: %d\n", rem));
+    VERBOSE (DEBUG, myfprintf (stdout, "remainder: %d\n", rem));
     nb = fread (bufhea, 1, size, fin);
     if (nb != size) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't read file\n"));
+        VERBOSE (ERROR, myfprintf (stdout, "can't read file\n"));
         fclose (fin);
         return 1;
     }
@@ -631,10 +632,10 @@ int write_decompress (char *output, char *input, code_t *codes)
     /* open file for writing */
     fout = fopen (output, "wb");
     if (fout == NULL) {
-        VERBOSE (ERROR, _fprintf (stdout, "can't open file '%s' for writing\n", output));
+        VERBOSE (ERROR, myfprintf (stdout, "can't open file '%s' for writing\n", output));
         return 2;
     }
-    VERBOSE (INFO, _fprintf (stdout, "file '%s' opened\n", output));
+    VERBOSE (INFO, myfprintf (stdout, "file '%s' opened\n", output));
 
     /* write file */
     pt = bufout;
@@ -708,7 +709,7 @@ int main (int argc, char *argv[])
     while (argc-- > 1) {
         arg = *(++argv);
         if (arg[0] != '-') {
-            _fprintf (stderr, "%s: invalid option -- %s\n", progname, arg);
+            myfprintf (stderr, "%s: invalid option -- %s\n", progname, arg);
             usage (1);
         }
         c = arg[1];
@@ -731,11 +732,11 @@ int main (int argc, char *argv[])
         case 'v':
             arg = (arg[2]) ? arg + 2 : (--argc > 0 ) ? *(++argv) : NULL;
             if (arg == NULL) {
-                _fprintf (stderr, "%s: missing verbose level\n", progname);
+                myfprintf (stderr, "%s: missing verbose level\n", progname);
                 usage (1);
             }
-            verbose = atoi (arg);
-            VERBOSE (INFO, _fprintf (stdout, "verbose: %d\n", verbose));
+            verbose = myatoi (arg);
+            VERBOSE (INFO, myfprintf (stdout, "verbose: %d\n", verbose));
             break;
         case 'h':
         default:
@@ -743,7 +744,7 @@ int main (int argc, char *argv[])
         }
     }
     if ((input == NULL) || (output == NULL)) {
-        _fprintf (stderr, "%s: missing file\n", progname);
+        myfprintf (stderr, "%s: missing file\n", progname);
         usage (1);
     }
     VERBOSE (DEBUG, PRINTF ("end processing arguments\n"));
diff --git a/debug.h b/debug.h
index 64ec161eb9d09bb1b5a664ab5982783106a556b4..a0d26f7c35ebc990b2d3b255671b6d83af2f50a7 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -23,7 +23,7 @@
 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
 #define VERBOSE(level, statement...) do { if (level <= verbose) { statement; } } while(0)
-#define PRINTF(args...) do { _fprintf (stdout, args); fflush (stdout); } while (0)
+#define PRINTF(args...) do { myfprintf (stdout, args); fflush (stdout); } while (0)
 
 /* gobal variables */
 
index 47b19c7124019bbae80bd40614ac109da52864ee..405957e8b388bd7a5fcea194a209ed956a6685e8 100644 (file)
--- a/fprintf.c
+++ b/fprintf.c
@@ -26,7 +26,7 @@ inline unsigned int nextpow10 (unsigned int x) {
 
 /* simple fprintf function */
 
-size_t _fprintf (FILE *fid, const char *fmt, ...)
+size_t myfprintf (FILE *fid, const char *fmt, ...)
 {
     char buffer[1024 + 1] = { 0 };
     char *str = buffer;
index 053620efa57cb46257cc9942d80907f5f47a818e..1820f1b9ecfc6d291e94c504fe5bc643f3c9cac3 100644 (file)
--- a/fprintf.h
+++ b/fprintf.h
@@ -4,7 +4,7 @@
 #include <stddef.h>
 #include <stdio.h>
 
-size_t _fprintf (FILE *fid, const char *fmt, ...);
+size_t myfprintf (FILE *fid, const char *fmt, ...);
 
 #endif /* __FPRINTF_H__ */