summaryrefslogtreecommitdiff
path: root/utils/testid.cc
blob: 72f30ae58ab3f0e1ea5ee733f6d52da9f3f87617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "IdTable.h"
#include "String.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

IvlIdTableOf <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) {
			IvlIdIter hi = table;
			while (++hi)
				printf ("%d: %s\n", hi.CurId (), *hi);
			continue;
		}
		
		/* delete */
		if (*s == '-') {
			bool found;
			IvlID id = (IvlID) (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 */
		IvlID id = table.Store (NewString (s));
		printf ("-> %d\n", id);
	}
	
}