summaryrefslogtreecommitdiff
path: root/src/tet3/tcc/systab.c
blob: e4b13308e98978d6819642be7b5c48947a39b70e (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 *	SCCS: @(#)systab.c	1.2 (96/11/04)
 *
 *	UniSoft Ltd., London, England
 *
 * (C) Copyright 1996 X/Open Company Limited
 *
 * All rights reserved.  No part of this source code may be reproduced,
 * stored in a retrieval system, or transmitted, in any form or by any
 * means, electronic, mechanical, photocopying, recording or otherwise,
 * except as stated in the end-user licence agreement, without the prior
 * permission of the copyright owners.
 * A copy of the end-user licence agreement is contained in the file
 * Licence which accompanies this distribution.
 * 
 * X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
 * the UK and other countries.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/************************************************************************

SCCS:   	@(#)systab.c	1.2 96/11/04 TETware release 3.3
NAME:		systab.c
PRODUCT:	TETware
AUTHOR:		Andrew Dingwall, UniSoft Ltd.
DATE CREATED:	August 1996

DESCRIPTION:
	system table administration functions

MODIFICATIONS:

	Aaron Plattner, April 2010
	Fixed warnings when compiled with GCC's -Wall option.

************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include "dtmac.h"
#include "dtmsg.h"
#include "ptab.h"
#include "bstring.h"
#include "error.h"
#include "llist.h"
#include "tet3_config.h"
#include "scentab.h"
#include "dirtab.h"
#include "systab.h"
#include "tcc.h"

#ifndef NOTRACE
#include "ltoa.h"
#endif

static struct systab *systab;		/* head of the system table */

/* static function declarations */
static void syadd PROTOLIST((struct systab *));
static struct systab *syalloc PROTOLIST((void));
#if 0
static void syfree PROTOLIST((struct systab *));
static void syrm PROTOLIST((struct systab *));
#endif
#ifndef TET_LITE	/* -START-LITE-CUT- */
static void ist2 PROTOLIST((struct scentab *, int *, int));
#endif /* !TET_LITE */	/* -END-LITE-CUT- */


/*
**	initsystab() - allocate a tcc system table element for each
**		system mentioned in the scenario tree
*/

void initsystab()
{
#ifdef TET_LITE	/* -LITE-CUT-LINE- */
	register struct systab *sp;

	sp = syalloc();
	sp->sy_sysid = 0;
	syadd(sp);

#else	/* -START-LITE-CUT- */
	int zero = 0;

	ist2(sctree, &zero, 1);

#endif /* TET_LITE */	/* -END-LITE-CUT- */
}


#ifndef TET_LITE	/* -START-LITE-CUT- */

/*
**	ist2() - extend the initsystab() processing for a particular
**		level in the scenario tree
*/

static void ist2(ep, sys, nsys)
register struct scentab *ep;
int *sys, nsys;
{
	register int *ip;
	register struct systab *sp;
	static int *oldsys;

	/*
	** traverse the tree on this level, examining test case elements
	** and descending subtrees
	*/
	for (; ep; ep = ep->sc_forw) {
		ASSERT(ep->sc_magic == SC_MAGIC);
		switch (ep->sc_type) {
		case SC_DIRECTIVE:
			switch (ep->sc_directive) {
			case SD_REMOTE:
			case SD_DISTRIBUTED:
				sys = ep->sc_sys;
				nsys = ep->sc_nsys;
				break;
			}
			/* fall through */
		case SC_SCENARIO:
			ist2(ep->sc_child, sys, nsys);
			break;
		case SC_TESTCASE:
			if (sys == oldsys)
				break;
			for (ip = sys; ip < sys + nsys; ip++)
				if (syfind(*ip) == (struct systab *) 0) {
					sp = syalloc();
					sp->sy_sysid = *ip;
					syadd(sp);
				}
			oldsys = sys;
			break;
		}
	}
}

#endif /* !TET_LITE */	/* -END-LITE-CUT- */


/*
**	syalloc(), syfree() - functions to allocate and free a
**		tcc system table element
*/

static struct systab *syalloc()
{
	register struct systab *sp;

	errno = 0;
	if ((sp = (struct systab *) malloc(sizeof *sp)) == (struct systab *) 0)
		fatal(errno, "can't allocate system table element",
			(char *) 0);

	TRACE2(tet_Tbuf, 6, "allocate systab element = %s", tet_i2x(sp));

	bzero((char *) sp, sizeof *sp);
	sp->sy_magic = SY_MAGIC;
	sp->sy_sysid = -1;
	sp->sy_activity = -1;
#ifndef TET_LITE	/* -START-LITE-CUT- */
	sp->sy_currcfmode = -1;
#endif /* !TET_LITE */	/* -END-LITE-CUT- */

	return(sp);
}

#if 0	/* this function not used anywhere */
static void syfree(sp)
struct systab *sp;
{
	TRACE2(tet_Tbuf, 6, "free systab element = %s", tet_i2x(sp));

	if (sp) {
		ASSERT(sp->sy_magic == SY_MAGIC);
		bzero((char *) sp, sizeof *sp);
		free((char *) sp);
	}
}
#endif

/*
**	syadd() - add a systab element to the tcc system table
*/

static void syadd(sp)
struct systab *sp;
{
	tet_listinsert((struct llist **) &systab, (struct llist *) sp);
}

/*
**	syrm() - remove a systam element from the tcc system table
*/

#if 0	/* this function not used anywhere */
static void syrm(sp)
struct systab *sp;
{
	tet_listremove((struct llist **) &systab, (struct llist *) sp);
}
#endif

/*
**	syfind() - find the systab entry for the named system
**		and return a pointer thereto
**
**	return (struct systab *) 0 if not found
*/

struct systab *syfind(sysid)
int sysid;
{
	register struct systab *sp;

	for (sp = systab; sp; sp = sp->sy_next) {
		ASSERT(sp->sy_magic == SY_MAGIC);
		if (sp->sy_sysid == sysid)
			break;
	}

	return(sp);
}

/*
**	symax() - return the highest sysid in the systab
*/

int symax()
{
	register struct systab *sp;
	register int max = -1;

	for (sp = systab; sp; sp = sp->sy_next) {
		ASSERT(sp->sy_magic == SY_MAGIC);
		if (sp->sy_sysid > max)
			max = sp->sy_sysid;
	}

	return(max);
}