summaryrefslogtreecommitdiff
path: root/utils/testid.cc
blob: bb79cedf195b43c6c6d8ee487843c6533636fe50 (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>

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);
	}
	
}