Commit 55b4562c by Rudolf

Remove noisy logging

And show useful logs only when DEBUG := 1
parent ae4ef0c8
Showing with 14 additions and 26 deletions
......@@ -13,7 +13,6 @@ static int write_entries(struct BIT_BUFFER *bitbuf, struct tree *parent)
if (left && right) {
bit = 1;
bb_write(bitbuf, &bit, 1);
printf(" 1");
}
if (left)
......@@ -26,8 +25,6 @@ static int write_entries(struct BIT_BUFFER *bitbuf, struct tree *parent)
bit = 0;
bb_write(bitbuf, &bit, 1);
bb_writebyte(bitbuf, parent->ch);
printf(" 0");
printf("%c", parent->ch);
}
return 0;
......@@ -53,7 +50,8 @@ static int read_entry(struct BIT_BUFFER *bitbuf, struct tree *parent)
} else {
int *c = bb_readbyte(bitbuf);
parent->ch = *c;
printf("Found from header %c\n", *c);
if (DEBUG)
printf("Found from encoded header %c\n", *c);
free(c);
}
......
......@@ -33,7 +33,6 @@ struct tree *merge_smallest(struct tree **forest, int length)
struct tree *smallest1 = NULL;
struct tree *smallest2 = NULL;
printf("--\n");
int i1 = 0, i2 = 0;
for (int i = 0; i < length; i++) {
......@@ -43,16 +42,13 @@ struct tree *merge_smallest(struct tree **forest, int length)
if (smallest1 == NULL) {
smallest1 = forest[i];
i1 = i;
printf("init Smallest1 %c:%d\n", smallest1->ch, smallest1->freq);
continue;
} else if (smallest2 == NULL) {
smallest2 = forest[i];
i2 = i;
printf("init Smallest2 %c:%d\n", smallest2->ch, smallest2->freq);
continue;
}
printf("comp %c:%d\n", forest[i]->ch, forest[i]->freq);
if (forest[i]->freq < smallest1->freq) {
smallest1 = forest[i];
i1 = i;
......@@ -64,9 +60,10 @@ struct tree *merge_smallest(struct tree **forest, int length)
forest[i1] = NULL;
forest[i2] = insert_proper_tree(smallest1, smallest2);
printf("Smallest1 %c:%d\n", smallest1->ch, smallest1->freq);
printf("Smallest2 %c:%d\n", smallest2->ch, smallest2->freq);
printf("Merged %c:%d\n", forest[i2]->ch, forest[i2]->freq);
if (DEBUG)
printf("Merged %c:%d and %c:%d\n", smallest1->ch, smallest1->freq,
smallest2->ch, smallest2->freq);
return forest[i2];
}
......@@ -102,7 +99,8 @@ struct tree *create_tree(FILE *file)
}
}
printf("Created initial tree with %d trees\n", ntrees);
if (DEBUG)
printf("Created initial tree with %d trees\n", ntrees);
/* Sort ascending */
for (int i = 0; i < ntrees; i++) {
......@@ -115,10 +113,6 @@ struct tree *create_tree(FILE *file)
}
}
for (int i = 0; i < ntrees; i++) {
printf("ch %c freq %d\n", forest[i]->ch, forest[i]->freq);
}
struct tree *parent = forest[0];
for (int i = 0; i < ntrees-1; i++) {
parent = merge_smallest(forest, ntrees);
......@@ -131,8 +125,8 @@ struct tree *create_tree(FILE *file)
/* This is not needed anymore */
free(forest);
printf("Returning tree\n");
if (DEBUG)
printf("Returning tree\n");
return parent;
}
......@@ -180,20 +174,16 @@ static int write_entry(struct BIT_BUFFER *bitbuf, struct tree *parent,
unsigned char c, int *pathbuf)
{
int length = get_rev_path(parent, c, pathbuf, 0);
printf("Length %d\n", length);
/* The path is in reverse. Now write it out in correct order. */
for (int i = length-1; i >= 0; i--) {
bb_write(bitbuf, &pathbuf[i], 1);
printf("i %d Bit %d\n", i, pathbuf[i]);
}
}
int encode_tree(struct BIT_BUFFER *bitbuf, struct tree *parent, char *buf,
size_t length)
{
printf("Bit pos at %d %d\n", ftell(bitbuf->fp), bitbuf->pos);
/* It makes much more sense to write the count when there is only one
* char. */
if (!parent->left && !parent->right) {
......@@ -237,15 +227,14 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out,
}
while ((bit = bb_read(bitbuf, 1)) != NULL) {
printf("Reading bit %d\n", *bit);
if (*bit == 0)
leaf = leaf->left;
else
leaf = leaf->right;
if (!leaf->left && !leaf->right) {
printf("Found from encoded %c\n", leaf->ch);
if (DEBUG)
printf("Found from encoded tree %c\n", leaf->ch);
fwrite(&leaf->ch, 1, 1, out);
leaf = parent;
}
......@@ -253,7 +242,8 @@ static int read_entries(struct BIT_BUFFER *bitbuf, FILE *out,
free(bit);
if (ftell(bitbuf->fp) == lastbyte && bitbuf->pos + throwaways >= 8) {
printf("Stopping\n");
if (DEBUG)
printf("Stopping\n");
break;
}
}
......
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