summaryrefslogtreecommitdiff
path: root/Source/DOH/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'Source/DOH/hash.c')
-rw-r--r--Source/DOH/hash.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/Source/DOH/hash.c b/Source/DOH/hash.c
index 87f8e3c40..241383327 100644
--- a/Source/DOH/hash.c
+++ b/Source/DOH/hash.c
@@ -42,6 +42,7 @@ typedef struct KeyValue {
} KeyValue;
static KeyValue *root = 0;
+static int max_expand = 1;
/* Find or create a key in the interned key table */
static DOH *find_key(DOH *doh_c) {
@@ -362,7 +363,7 @@ static DohIterator Hash_nextiter(DohIterator iter) {
}
/* -----------------------------------------------------------------------------
- * Hash_keys(DOH *)
+ * Hash_keys()
*
* Return a list of keys
* ----------------------------------------------------------------------------- */
@@ -379,6 +380,26 @@ static DOH *Hash_keys(DOH *so) {
}
/* -----------------------------------------------------------------------------
+ * DohSetMaxHashExpand()
+ *
+ * Controls how many Hash objects are displayed in full in Hash_str
+ * ----------------------------------------------------------------------------- */
+
+void DohSetMaxHashExpand(int count) {
+ max_expand = count;
+}
+
+/* -----------------------------------------------------------------------------
+ * DohGetMaxHashExpand()
+ *
+ * Returns how many Hash objects are displayed in full in Hash_str
+ * ----------------------------------------------------------------------------- */
+
+int DohGetMaxHashExpand(void) {
+ return max_expand;
+}
+
+/* -----------------------------------------------------------------------------
* Hash_str()
*
* Create a string representation of a hash table (mainly for debugging).
@@ -388,7 +409,8 @@ static DOH *Hash_str(DOH *ho) {
int i, j;
HashNode *n;
DOH *s;
- static int indent = 4;
+ static int expanded = 0;
+ static const char *tab = " ";
Hash *h = (Hash *) ObjData(ho);
s = NewStringEmpty();
@@ -396,22 +418,35 @@ static DOH *Hash_str(DOH *ho) {
Printf(s, "Hash(0x%x)", ho);
return s;
}
+ if (expanded >= max_expand) {
+ /* replace each hash attribute with a '.' */
+ Printf(s, "Hash(0x%x) {", ho);
+ for (i = 0; i < h->hashsize; i++) {
+ n = h->hashtable[i];
+ while (n) {
+ Putc('.', s);
+ n = n->next;
+ }
+ }
+ Putc('}', s);
+ return s;
+ }
ObjSetMark(ho, 1);
- Printf(s, "Hash {\n");
+ Printf(s, "Hash(0x%x) {\n", ho);
for (i = 0; i < h->hashsize; i++) {
n = h->hashtable[i];
while (n) {
- for (j = 0; j < indent; j++)
- Putc(' ', s);
- indent += 4;
+ for (j = 0; j < expanded + 1; j++)
+ Printf(s, tab);
+ expanded += 1;
Printf(s, "'%s' : %s, \n", n->key, n->object);
- indent -= 4;
+ expanded -= 1;
n = n->next;
}
}
- for (j = 0; j < (indent - 4); j++)
- Putc(' ', s);
- Printf(s, "}\n");
+ for (j = 0; j < expanded; j++)
+ Printf(s, tab);
+ Printf(s, "}");
ObjSetMark(ho, 0);
return s;
}