Commit a169c230 by Rudolf

Do not redefine bit

parent 9c75370d
...@@ -7,25 +7,24 @@ ...@@ -7,25 +7,24 @@
static int write_entries(struct BIT_BUFFER *bitbuf, struct tree *parent) static int write_entries(struct BIT_BUFFER *bitbuf, struct tree *parent)
{ {
int bit;
if (parent->left) { if (parent->left) {
int bit = 1; bit = 1;
bb_write(bitbuf, &bit, 1); bb_write(bitbuf, &bit, 1);
write_entries(bitbuf, parent->left); write_entries(bitbuf, parent->left);
} }
if (!parent->left) { if (!parent->left) {
int bit = 0; bit = 0;
bb_write(bitbuf, &bit, 1); /* This means now we have 8 bits of char. */ bb_write(bitbuf, &bit, 1); /* This means now we have 8 bits of char. */
bb_writebyte(bitbuf, parent->ch); bb_writebyte(bitbuf, parent->ch);
fprintf(stderr, "%x\n", parent->ch);
} }
if (parent->right) { if (parent->right) {
/* Why should we write this - we can save more bits. */ /* Why should we write this if we can save more bits. */
//int bit = 0; //bit = 0;
//bb_write(bitbuf, &bit, 1); //bb_write(bitbuf, &bit, 1);
bb_writebyte(bitbuf, parent->right->ch); bb_writebyte(bitbuf, parent->right->ch);
fprintf(stderr, "%x\n", parent->right->ch);
} }
} }
......
...@@ -7,24 +7,6 @@ ...@@ -7,24 +7,6 @@
#include "header.h" #include "header.h"
#include "tree.h" #include "tree.h"
void print_char(char c)
{
switch (c) {
case '\n':
printf("\\n\n");
break;
case '\r':
printf("\\r\n");
break;
case '\t':
printf("\\t\n");
break;
default:
printf("%c\n", c);
break;
}
}
void free_tree(struct tree *parent) void free_tree(struct tree *parent)
{ {
while (parent != NULL) { while (parent != NULL) {
......
...@@ -26,3 +26,21 @@ void __printb(void *value, size_t size) ...@@ -26,3 +26,21 @@ void __printb(void *value, size_t size)
} }
printf("\n"); printf("\n");
} }
void print_char(char c)
{
switch (c) {
case '\n':
printf("\\n\n");
break;
case '\r':
printf("\\r\n");
break;
case '\t':
printf("\\t\n");
break;
default:
printf("%c\n", c);
break;
}
}
...@@ -16,3 +16,5 @@ void __printb(void *value, size_t size); ...@@ -16,3 +16,5 @@ void __printb(void *value, size_t size);
typeof(value) _v = value; \ typeof(value) _v = value; \
__printb((typeof(_v) *) &_v, sizeof(_v)); \ __printb((typeof(_v) *) &_v, sizeof(_v)); \
}) })
void print_char(char c);
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
struct tree *insert_simple_tree(int character, int frequency) struct tree *insert_simple_tree(int character, int frequency)
{ {
struct tree *new = malloc(sizeof(struct tree)); struct tree *new = malloc(sizeof(struct tree));
//printf("Created %p\n", new);
new->left = NULL; new->left = NULL;
new->right = NULL; new->right = NULL;
new->ch = character; new->ch = character;
...@@ -22,7 +21,6 @@ struct tree *insert_simple_tree(int character, int frequency) ...@@ -22,7 +21,6 @@ struct tree *insert_simple_tree(int character, int frequency)
struct tree *insert_proper_tree(struct tree *left, struct tree *right) struct tree *insert_proper_tree(struct tree *left, struct tree *right)
{ {
struct tree *new = malloc(sizeof(*new)); struct tree *new = malloc(sizeof(*new));
//printf("Created %p\n", new);
new->left = left; new->left = left;
new->right = right; new->right = right;
new->ch = 0; new->ch = 0;
...@@ -142,7 +140,7 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out, ...@@ -142,7 +140,7 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out,
} }
free(bit); free(bit);
} }
fprintf(stdout, "\n");
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment