clean compress
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 19 Dec 2022 14:54:18 +0000 (15:54 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 19 Dec 2022 14:54:18 +0000 (15:54 +0100)
atoi.c
atoi.h
code.c
compress.c
fdprintf.c [new file with mode: 0644]
fdprintf.h [new file with mode: 0644]
fprintf.c [deleted file]
fprintf.h [deleted file]
makefile

diff --git a/atoi.c b/atoi.c
index fd3fedda75ea88941ccddeee7dc76e39858e27aa..554702086f1139d9787efeb680de4bd182998871 100644 (file)
--- a/atoi.c
+++ b/atoi.c
@@ -1,6 +1,6 @@
 #include "atoi.h"
 
-int myatoi (char *str)
+int atoi (char *str)
 {
     int i = 0;
     int s = 1;
diff --git a/atoi.h b/atoi.h
index 74d58c3c20f7e06da774c7b9bcb7a99bd60a308b..11b8a46ba6aaca84f6db763ef617de60ebac80f5 100644 (file)
--- a/atoi.h
+++ b/atoi.h
@@ -1,7 +1,7 @@
 #ifndef __ATOI_H__
 #define __ATOI_H__
 
-int myatoi (char *str);
+int atoi (char *str);
 
 #endif /* __ATOI_H__ */
 
diff --git a/code.c b/code.c
index 934bfe9f04dd15a431212307c89a3f2ce8900404..5872443387b8048521ab189618e3ff813e8995f5 100644 (file)
--- a/code.c
+++ b/code.c
@@ -1,5 +1,5 @@
 #include "debug.h"
-#include "fprintf.h"
+#include "fdprintf.h"
 
 #include "code.h"
 
index d27f8e5740982070b6383f5cc10cbef86ad52fd5..4b91bbf02e73dfbd38626dc76889c31f734ba466 100644 (file)
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: atoi.o code.o debug.o fprintf.o */
+/* linker: atoi.o code.o debug.o fdprintf.o */
 
 #include <fcntl.h>
 #include <unistd.h>
@@ -8,7 +8,7 @@
 #include "atoi.h"
 #include "code.h"
 #include "debug.h"
-#include "fprintf.h"
+#include "fdprintf.h"
 
 /* constants */
 
@@ -31,7 +31,7 @@ char *progname = NULL;
 
 int usage (int ret)
 {
-    int fd = ret ? _fderr : _fdout;
+    int fd = ret ? stdfderr : stdfdout;
     fdprintf (fd, "usage: %s\n", progname);
     fdprintf (fd, " -h : help message\n");
     fdprintf (fd, " -i <file>: input file\n");
@@ -713,7 +713,7 @@ int main (int argc, char *argv[])
                 PRINTERR ("%s: missing verbose level\n", progname);
                 return usage (1);
             }
-            verbose = myatoi (arg);
+            verbose = atoi (arg);
             VERBOSE (INFO, PRINTOUT ("verbose: %d\n", verbose));
             break;
         case 'h':
diff --git a/fdprintf.c b/fdprintf.c
new file mode 100644 (file)
index 0000000..238878d
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+  File name        : fprintf.c
+  Date of creation : 05/12/2022
+  Version          : 1.0
+  Copyright        : Soft'n'design
+  Author           : Laurent Mazet <mazet@softndesign.org>
+
+  Description      : This file contains embedded printf
+
+  History          :
+  - initial version
+*/
+
+#include <stdarg.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include "fdprintf.h"
+
+int stdfdout = STDOUT_FILENO;
+int stdfderr = STDERR_FILENO;
+
+unsigned int nextpow (unsigned int x, int base) {
+    unsigned int n = 0;
+    while (x) {
+        n++;
+        x = x / base;
+    }
+    return (n == 0) ? 1 : n;
+}
+
+/* simple fprintf function */
+
+int fdprintf (int fd, const char *fmt, ...)
+{
+    char buffer[1024 + 1] = { 0 };
+    char *str = buffer;
+
+    va_list ap;
+    va_start (ap, fmt);
+    while (*fmt) {
+        char *s;
+        int d = 0;
+        unsigned int u;
+        char c = *fmt++;
+
+        /* copy standard char */
+        if (c != '%') {
+            *str++ = c;
+        } else {
+            int t = 0;
+               char w = '0';
+            int i, sz = 0;
+            void *p = NULL;
+
+            /* stamp */
+            if ((*fmt == ' ') || (*fmt == '0')) {
+                w = *fmt++;
+            }
+
+            /* size */
+            if ((*fmt >= '1') && (*fmt <= '9')) {
+                sz = *fmt++ - '0';
+            }
+
+            /* process format char */
+            switch (*fmt++) {
+            case 'c': /* char */
+                c = (char) va_arg (ap, int);
+                *str++ = c;
+                break;
+            case 'd': /* int */
+                d = va_arg (ap, int);
+                if (d < 0) {
+                    *str++ = '-';
+                    d = -d;
+                }
+                t = 1;
+                /* fall through */
+            case 'u': /* unsigned int */
+                u = (t) ? (unsigned int)d : va_arg (ap, unsigned int);
+                for (i = nextpow (u, 10), s = str; i > 0; i--, s++) {
+                    str[i - 1] = '0' + (u % 10);
+                    u /= 10;
+                }
+                str = s;
+                break;
+            case 'p': /* pointer */
+                *str++ = '0';
+                *str++ = 'x';
+                w = '0';
+                sz = sizeof (void *) * 2;
+                p = va_arg (ap, void *);
+                /* fall through */
+            case 'x': /* integer hexa */
+                if (!p) {
+                    u = va_arg (ap, unsigned int);
+                    if (sz == 0) {
+                        sz = nextpow (u, 16);
+                    }
+                } else {
+                    u = (uintptr_t)p;
+                }
+                for (i = sz, t = 1; i > 0; i--) {
+                    char x = (char)((u >> (i * 4 - 4)) & 0xf);
+                    if ((t == 1) && (x == 0)) {
+                        *str++ = w;
+                    } else {
+                        *str++ = (x > 9) ? 'a' + x - 10 : '0' + x;
+                        t = 0;
+                    }
+                }
+                break;
+            case 's': /* string */
+                s = va_arg (ap, char *);
+                while (s && *s)
+                    *str++ = *s++;
+                break;
+            default:
+                *str++ = '?';
+            }
+        }
+    }
+    va_end (ap);
+
+    /* output string */
+    int n = str - buffer;
+    if (n < (int)sizeof (buffer) - 1) {
+        return write (fd, buffer, n);
+    }
+    return 0;
+}
+
+/* vim: set ts=4 sw=4 et: */
diff --git a/fdprintf.h b/fdprintf.h
new file mode 100644 (file)
index 0000000..3094ef7
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __FDPRINTF_H__
+#define __FDPRINTF_H__
+
+int fdprintf (int fd, const char *fmt, ...);
+
+extern int stdfdout;
+extern int stdfderr;
+
+#define PRINTOUT(fmt...) fdprintf (stdfdout, fmt)
+#define PRINTERR(fmt...) fdprintf (stdfderr, fmt)
+
+#endif /* __FDPRINTF_H__ */
+
+/* vim: set ts=4 sw=4 et: */
diff --git a/fprintf.c b/fprintf.c
deleted file mode 100644 (file)
index ff4f035..0000000
--- a/fprintf.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
-  File name        : fprintf.c
-  Date of creation : 05/12/2022
-  Version          : 1.0
-  Copyright        : Soft'n'design
-  Author           : Laurent Mazet <mazet@softndesign.org>
-
-  Description      : This file contains embedded printf
-
-  History          :
-  - initial version
-*/
-
-#include <stdarg.h>
-#include <stdint.h>
-#include <unistd.h>
-
-#include "fprintf.h"
-
-int _fdout = STDOUT_FILENO;
-int _fderr = STDERR_FILENO;
-
-unsigned int nextpow (unsigned int x, int base) {
-    unsigned int n = 0;
-    while (x) {
-        n++;
-        x = x / base;
-    }
-    return (n == 0) ? 1 : n;
-}
-
-/* simple fprintf function */
-
-int fdprintf (int fd, const char *fmt, ...)
-{
-    char buffer[1024 + 1] = { 0 };
-    char *str = buffer;
-
-    va_list ap;
-    va_start (ap, fmt);
-    while (*fmt) {
-        char *s;
-        int d = 0;
-        unsigned int u;
-        char c = *fmt++;
-
-        /* copy standard char */
-        if (c != '%') {
-            *str++ = c;
-        } else {
-            int t = 0;
-               char w = '0';
-            int i, sz = 0;
-            void *p = NULL;
-
-            /* stamp */
-            if ((*fmt == ' ') || (*fmt == '0')) {
-                w = *fmt++;
-            }
-
-            /* size */
-            if ((*fmt >= '1') && (*fmt <= '9')) {
-                sz = *fmt++ - '0';
-            }
-
-            /* process format char */
-            switch (*fmt++) {
-            case 'c': /* char */
-                c = (char) va_arg (ap, int);
-                *str++ = c;
-                break;
-            case 'd': /* int */
-                d = va_arg (ap, int);
-                if (d < 0) {
-                    *str++ = '-';
-                    d = -d;
-                }
-                t = 1;
-                /* fall through */
-            case 'u': /* unsigned int */
-                u = (t) ? (unsigned int)d : va_arg (ap, unsigned int);
-                for (i = nextpow (u, 10), s = str; i > 0; i--, s++) {
-                    str[i - 1] = '0' + (u % 10);
-                    u /= 10;
-                }
-                str = s;
-                break;
-            case 'p': /* pointer */
-                *str++ = '0';
-                *str++ = 'x';
-                w = '0';
-                sz = sizeof (void *) * 2;
-                p = va_arg (ap, void *);
-                /* fall through */
-            case 'x': /* integer hexa */
-                if (!p) {
-                    u = va_arg (ap, unsigned int);
-                    if (sz == 0) {
-                        sz = nextpow (u, 16);
-                    }
-                } else {
-                    u = (uintptr_t)p;
-                }
-                for (i = sz, t = 1; i > 0; i--) {
-                    char x = (char)((u >> (i * 4 - 4)) & 0xf);
-                    if ((t == 1) && (x == 0)) {
-                        *str++ = w;
-                    } else {
-                        *str++ = (x > 9) ? 'a' + x - 10 : '0' + x;
-                        t = 0;
-                    }
-                }
-                break;
-            case 's': /* string */
-                s = va_arg (ap, char *);
-                while (s && *s)
-                    *str++ = *s++;
-                break;
-            default:
-                *str++ = '?';
-            }
-        }
-    }
-    va_end (ap);
-
-    /* output string */
-    int n = str - buffer;
-    if (n < (int)sizeof (buffer) - 1) {
-        return write (fd, buffer, n);
-    }
-    return 0;
-}
-
-/* vim: set ts=4 sw=4 et: */
diff --git a/fprintf.h b/fprintf.h
deleted file mode 100644 (file)
index 8c2bb0b..0000000
--- a/fprintf.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef __FPRINTF_H__
-#define __FPRINTF_H__
-
-int fdprintf (int fd, const char *fmt, ...);
-
-extern int _fdout;
-extern int _fderr;
-
-#define PRINTOUT(fmt...) fdprintf (_fdout, fmt)
-#define PRINTERR(fmt...) fdprintf (_fderr, fmt)
-
-#endif /* __FPRINTF_H__ */
-
-/* vim: set ts=4 sw=4 et */
index 918645fa9f1701a4ad552c9032073d2f49ecec92..997c6d7fa56281800ee0b62f1d0251141c4af1bc 100644 (file)
--- a/makefile
+++ b/makefile
@@ -98,7 +98,7 @@ valgrind_%: %
 
 %.ld: %.c
        $(call TITLE, "Building $@")
-       echo ${<:.c=.exe}: $(shell ./getcomments.pl -p='linker:\s' -f='%' $< | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') >> $@
+       echo ${<:.c=.exe}: $(shell ./getcomments.pl -p='linker:\s' -f='%' $< | awk '{for (i=1;i<=NF;i++) if ($$(i) ~ /.o$$/) printf " %s", $$(i)}') > $@
        $(call PASS, SUCCESS)
 
 %.o: %.c