summaryrefslogtreecommitdiff
path: root/utils/testid.cc
diff options
context:
space:
mode:
Diffstat (limited to 'utils/testid.cc')
-rw-r--r--utils/testid.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/utils/testid.cc b/utils/testid.cc
new file mode 100644
index 0000000..bb79ced
--- /dev/null
+++ b/utils/testid.cc
@@ -0,0 +1,61 @@
+#include "IdTable.h"
+#include "String.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+CcuIdTableOf <char> table (2);
+
+main ()
+{
+ char line [256];
+ char *s;
+ int i = 0;
+
+ printf ("? to get help\n");
+
+ for (;;) {
+ s = gets (line);
+ if (! s)
+ break;
+ if (strcmp (s, ".") == 0)
+ break;
+
+ /* help */
+ if (strcmp (s, "?") == 0) {
+ printf ("name\tadd name\n");
+ printf ("-id\tdelete name associated to id\n");
+ printf ("#\tdump table\n");
+ printf (".\tquit\n");
+
+ continue;
+ }
+
+ if (strcmp (s, "#") == 0) {
+ CcuIdIter hi = table;
+ while (++hi)
+ printf ("%d: %s\n", hi.CurId (), *hi);
+ continue;
+ }
+
+ /* delete */
+ if (*s == '-') {
+ bool found;
+ CcuID id = (CcuID) (atoi (++s));
+ printf ("searching id %d\n", id);
+ char* info = table.Remove (id, &found);
+ if (! found)
+ printf ("%s not found\n", s);
+ else {
+ printf ("%s had info %s\n", s, info);
+ FreeString (info);
+ }
+ continue;
+ }
+
+ /* add */
+ CcuID id = table.Store (NewString (s));
+ printf ("-> %d\n", id);
+ }
+
+}