-#include <stddef.h>
-#include <stdio.h>
-
#include "debug.h"
-#include "fprintf.h"
+#include "fdprintf.h"
#include "code.h"
+/* constants */
+
+#define NB_LEAFS ((NB_BYTES + 1) * NB_BYTES / 2)
+
/* concatenate code */
-int codcat (char *dst, size_t n, char *src)
+int codcat (char *dst, int n, char *src)
{
while ((*dst != 0) && (n > 0)) {
n--;
dst++;
}
-
+
return (n > 0) ? codcpy (dst, n, src) : -1;
}
int codcmp (char *cod1, char *cod2)
{
- int i = -1;
-
- do {
- i++;
- if (cod1[i] != cod2[i]) {
- return (cod1[i] < cod2[i]) ? -1 : 1;
+ while ((*cod1 != 0) || (*cod2 != 0)) {
+ int test = *cod1++ - *cod2++;
+ if (test != 0) {
+ return (test < 0) ? -1 : 1;
}
- } while (cod1[i] != 0);
+ }
return 0;
}
/* copy code */
-int codcpy (char *dst, size_t n, char *src)
+int codcpy (char *dst, int n, char *src)
{
- size_t i;
+ int i;
for (i = 0; i < n; i++) {
dst[i] = src[i];
return i;
}
}
- VERBOSE (ERROR, myfprintf (stdout, "Buffer too short\n"));
+ VERBOSE (ERROR, PRINTERR ("Buffer too short\n"));
return -1;
}
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: */