summaryrefslogtreecommitdiff
path: root/lib/HTree.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/HTree.cc')
-rw-r--r--lib/HTree.cc28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/HTree.cc b/lib/HTree.cc
index 3910ce3..985d687 100644
--- a/lib/HTree.cc
+++ b/lib/HTree.cc
@@ -1,12 +1,32 @@
#include <stdio.h>
#include <iostream.h>
+#include <stdlib.h>
+#include <string.h>
#include "config.h"
#include "HTree.h"
+ostream & PrintString(ostream & os, char *str)
+{
+ char t[2];
+
+ t[1] = '\0';
+ while (*str) {
+ if (*str >= 33) {
+ t[0] = *str;
+ os << t;
+ } else {
+ os << "\\" << ((unsigned int) (((unsigned char) *str)));
+ }
+ str++;
+ }
+
+ return os;
+}
+
HTree::HTree(int n_freq, char *n_objet)
{
freq = n_freq;
- objet = n_objet;
+ objet = strdup(n_objet);
left = right = NULL;
}
@@ -25,6 +45,9 @@ HTree::~HTree()
if (right)
delete right;
+
+ if (objet)
+ free(objet);
}
ostream & HTree::Trace(ostream & os, int d)
@@ -39,7 +62,8 @@ ostream & HTree::Trace(ostream & os, int d)
if (objet) {
cmpr[d] = '\0';
- os << objet << " (" << freq << ") = " << cmpr << endl;
+ PrintString(os, objet);
+ os << " (" << freq << ") = " << cmpr << endl;
tsize += freq * strlen(cmpr);
rsize += freq * strlen(objet);
dsize += ((strlen(cmpr) >> 3) + (strlen(cmpr) & 7 ? 1 : 0)) + strlen(objet) + 2;