From 69c93c001578184b238699f15b0170dee22ef0d9 Mon Sep 17 00:00:00 2001
From: zesstra <zesstra@zesstra.de>
Date: Thu, 4 Jun 2009 01:29:57 +0200
Subject: [PATCH 14/14] Dump tables strings upon shutdown.

---
 src/main.c     |    5 +++++
 src/mstrings.c |   21 +++++++++++++++++++++
 src/mstrings.h |    4 +++-
 3 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/src/main.c b/src/main.c
index 861f387..362979d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -698,6 +698,11 @@ main (int argc, char **argv)
     tls_global_deinit();
 #endif
 
+#ifdef DUMP_STRINGS
+    // dump strings
+    mstrings_dump_all_strings();
+#endif
+    
     return rc; /* TODO: There are constants for this */
 } /* main() */
 
diff --git a/src/mstrings.c b/src/mstrings.c
index 6458425..95eb2ab 100644
--- a/src/mstrings.c
+++ b/src/mstrings.c
@@ -1862,4 +1862,25 @@ string_dinfo_status (svalue_t *svp, int value)
 #undef ST_NUMBER
 } /* string_dinfo_status() */
 
+void mstrings_dump_all_strings()
+{
+#ifdef DUMP_STRINGS
+    FILE *f = fopen(DUMP_STRINGS, "a");
+    if (!f)
+        return;
+    
+    int i;
+    for(i=0; i < HTABLE_SIZE; i++) {
+        string_t *s = stringtable[i];
+        while (s) {
+            fwrite(get_txt(s), 1, mstrsize(s), f);
+            if (*(get_txt(s)+mstrsize(s)-1) != '\n')
+                fwrite("\n", 1, 1, f);
+            s = s->next;
+        }
+    }
+    
+    fclose(f);
+#endif
+}
 /***************************************************************************/
diff --git a/src/mstrings.h b/src/mstrings.h
index bc95d1f..9acc0be 100644
--- a/src/mstrings.h
+++ b/src/mstrings.h
@@ -6,6 +6,8 @@
 
 #include "hash.h"
 
+#define DUMP_STRINGS "strings.dump"
+
 /* --- Types --- */
 
 /* --- struct string_s : String structure ---
@@ -113,7 +115,7 @@ extern void mstring_gc_table (void);
 
 extern mp_int add_string_status (strbuf_t *sbuf, Bool verbose);
 extern void   string_dinfo_status(svalue_t *svp, int value);
-
+extern void   mstrings_dump_all_strings();
 
 /* --- Inline functions and macros --- */
 static INLINE size_t mstr_mem_size(const string_t * const s) 
-- 
1.6.1

