remove calloc calls
[compress.git] / code.c
diff --git a/code.c b/code.c
index 67220e05b02dd97a390f25a7d49409da3872d840..934bfe9f04dd15a431212307c89a3f2ce8900404 100644 (file)
--- a/code.c
+++ b/code.c
@@ -1,11 +1,12 @@
-#include <stddef.h>
-#include <unistd.h>
-
 #include "debug.h"
 #include "fprintf.h"
 
 #include "code.h"
 
+/* constants */
+
+#define NB_LEAFS ((NB_BYTES + 1) * NB_BYTES / 2)
+
 /* concatenate code */
 
 int codcat (char *dst, int n, char *src)
@@ -14,7 +15,7 @@ int codcat (char *dst, int n, char *src)
         n--;
         dst++;
     }
-    
+
     return (n > 0) ? codcpy (dst, n, src) : -1;
 }
 
@@ -46,7 +47,7 @@ int codcpy (char *dst, int n, char *src)
             return i;
         }
     }
-    VERBOSE (ERROR, fdprintf (STDOUT_FILENO, "Buffer too short\n"));
+    VERBOSE (ERROR, PRINTERR ("Buffer too short\n"));
 
     return -1;
 }
@@ -64,4 +65,22 @@ int codlen (char *code)
     return i;
 }
 
-/* vim: set ts=4 sw=4 et */
+/* get leaf(s) */
+
+leaf_t *getleaf (int n)
+{
+    static leaf_t leafs[NB_LEAFS] = {0};
+    static int pos = 0;
+    leaf_t *pt = (void *)0;
+
+    if (pos + n < NB_LEAFS) {
+        pt = leafs + pos;
+        pos += n;
+    } else {
+        VERBOSE (ERROR, PRINTERR ("No more leaf avaliable\n"));
+    }
+
+    return pt;
+}
+
+/* vim: set ts=4 sw=4 et: */