summaryrefslogtreecommitdiff
path: root/utils/testlist.cc
blob: 934c28f75f39e7a1adf3ac33d7e6830bfc5f39c6 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include "String.h"
#include "List.h"

main ()
{
#ifdef CPLUS_BUG19
	IvlList l;
#else
	IvlListOf <char> l;
#endif
	char c;
	char s[80];
	while ((c = getchar ()) != EOF) {
		switch (c) {
		case 'a':
			scanf (" %s", s);
			l.Append (NewString (s));
			break;
		case 'p':
			scanf (" %s", s);
			l.Prepend (NewString (s));
			break;
		case '+':
			l.RemoveFirst ();
			break;
		case '-':
			l.RemoveLast ();
			break;
		case '\n':
			continue;
		case 'i':
			{
			int i;
			scanf (" %d %s", &i, s);
#ifdef CPLUS_BUG19
			IvlListIter lj (l);
#else
			IvlListIterOf <char> lj (l);
#endif
			while ((i-- > 0) && ++lj)
				;
			l.InsertBefore (lj, NewString (s));
			break;
			}
		case 'j':
			{
			int i;
			scanf (" %d %s", &i, s);
#ifdef CPLUS_BUG19
			IvlListIter lj (l);
#else
			IvlListIterOf <char> lj (l);
#endif
			while ((i-- > 0) && ++lj)
				;
			l.InsertAfter (lj, NewString (s));
			break;
			}
		}
#ifdef CPLUS_BUG19
		IvlListIter li (l);
		while (++li) {
			char* pt = (char*) *li;
			printf ("%s ", pt);
		}
#else
		IvlListIterOf <char> li (l);
		while (++li) {
			char* pt = *li;
			printf ("%s ", pt);
		}
#endif
		printf ("\n");
	}
}