remove skeleton file
[compress.git] / code.c
CommitLineData
c9987f3b 1#include "debug.h"
46fb351f 2#include "fdprintf.h"
c9987f3b
LM
3
4#include "code.h"
5
c84ea202
LM
6/* constants */
7
8#define NB_LEAFS ((NB_BYTES + 1) * NB_BYTES / 2)
9
c9987f3b
LM
10/* concatenate code */
11
92fc2c44 12int codcat (char *dst, int n, char *src)
c9987f3b
LM
13{
14 while ((*dst != 0) && (n > 0)) {
15 n--;
16 dst++;
17 }
c84ea202 18
c9987f3b
LM
19 return (n > 0) ? codcpy (dst, n, src) : -1;
20}
21
22/* compare 2 codes */
23
24int codcmp (char *cod1, char *cod2)
25{
2cbffab5
LM
26 while ((*cod1 != 0) || (*cod2 != 0)) {
27 int test = *cod1++ - *cod2++;
28 if (test != 0) {
29 return (test < 0) ? -1 : 1;
c9987f3b 30 }
2cbffab5 31 }
c9987f3b
LM
32
33 return 0;
34}
35
36/* copy code */
37
92fc2c44 38int codcpy (char *dst, int n, char *src)
c9987f3b 39{
92fc2c44 40 int i;
c9987f3b
LM
41
42 for (i = 0; i < n; i++) {
43 dst[i] = src[i];
44 if (src[i]== 0) {
45 return i;
46 }
47 }
c84ea202 48 VERBOSE (ERROR, PRINTERR ("Buffer too short\n"));
c9987f3b
LM
49
50 return -1;
51}
52
53/* code length */
54
55int codlen (char *code)
56{
57 int i = 0;
58
59 while (code[i] != 0) {
60 i++;
61 }
62
63 return i;
64}
65
c84ea202
LM
66/* get leaf(s) */
67
68leaf_t *getleaf (int n)
69{
70 static leaf_t leafs[NB_LEAFS] = {0};
71 static int pos = 0;
72 leaf_t *pt = (void *)0;
73
74 if (pos + n < NB_LEAFS) {
75 pt = leafs + pos;
76 pos += n;
77 } else {
78 VERBOSE (ERROR, PRINTERR ("No more leaf avaliable\n"));
79 }
80
81 return pt;
82}
83
84/* vim: set ts=4 sw=4 et: */