aboutsummaryrefslogtreecommitdiff
path: root/pan/reporter.c
blob: d1dee3acdf23d0f8ed5cc429b51f927f51235968 (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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * Further, this software is distributed without any warranty that it is
 * free of the rightful claim of any third person regarding infringement
 * or the like.  Any license provided herein, whether implied or
 * otherwise, applies only to this software file.  Patent licenses, if
 * any, provided herein do not apply to combinations of this program with
 * other software, or any other product whatsoever.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
 * Mountain View, CA  94043, or:
 *
 * http://www.sgi.com
 *
 * For further information regarding this notice, see:
 *
 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
 *
 */
/* $Id: reporter.c,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
/*
 * This is the report generator half of the scanner program.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "reporter.h"
#include "symbol.h"
#include "tag_report.h"
#include "splitstr.h"

/************************************************************************
 *                      Report Generation                               *
 ************************************************************************/

static int scanner_reporter(SYM);
static int iscanner_reporter(SYM);
static int scanner_test_end(SYM, SYM, SYM);
static int iscanner_test_end(SYM, SYM, SYM);

static int (*reporter_func) (SYM) = scanner_reporter;
static int (*test_end_func) (SYM, SYM, SYM) = scanner_test_end;

/*
 * Do the report generation.
 *
 * A problem: I really need multiple cursors.  I'd rather not look into
 * the depths of the current symbol table implimentation (there are the
 * cursors there that I could use) so that a different (faster!) symbol
 * table can be used in the future.
 *
 * I could get a key (tag), get it's sub-keys (TCIDs), then get the key
 * again to reset to the top level, _then_ get the next key.  That would
 * be very inefficient.
 *
 * The solution I chose is to extract all tags into a list (char array),
 * then go thru that list with the cursor free for other levels to use.
 *
 *  (1) make a list (2d char array) of all Tags
 *  (2) search for the first tag that has a "stime" record, and use that as
 *      the date (MMDDYY) that the tests were run.
 *  (3) print the report header
 *  (4) go thru all tags and report each as described at the beginning of
 *      this file
 */
static int scanner_reporter(tags)
SYM tags;
{
	DBT Key, Data;
	SYM Tag, Keys;

	time_t clock;
	struct tm *tm;

	/* a list of tags, a count of the number of tags allocated to the list,
	   and a pointer to go thru the list */
	char **taglist, **tl;
	int ntags;
	int tagcount;		/* how many tags used */

	char key_get[KEYSIZE];
	char *info;

	/*
	 * extract tag names from data
	 */
	ntags = NTAGS_START;
	taglist = (char **)malloc(sizeof(char *) * ntags);
	tagcount = 0;

	tl = taglist;
	sym_seq(tags, &Key, &Data, R_FIRST);
	do {
		if (tagcount == ntags) {
			/* exceeded tag array size -- realloc */
			ntags += NTAGS_START;
			taglist =
			    (char **)realloc(taglist, sizeof(char *) * ntags);
			tl = taglist + tagcount;
		}

		*tl++ = Key.data;
		tagcount++;
	} while (sym_seq(tags, &Key, &Data, R_NEXT) == 0);

	if (tagcount == ntags) {
		/* exceeded tag array size -- realloc */
		ntags += NTAGS_START;
		taglist = (char **)realloc(taglist, sizeof(char *) * ntags);
		tl = taglist + tagcount;
	}

	*tl++ = NULL;
	ntags = tagcount;
	/* Retrieve one "stime" to get the date. */
	for (tl = taglist; *tl != NULL; tl++) {
		strcpy(key_get, *tl);
		strcat(key_get, ",_keys,stime");
		if ((info = (char *)sym_get(tags, key_get)) != NULL) {
			clock = atoi(info);
			tm = gmtime(&clock);
			strftime(key_get, KEYSIZE, "%x", tm);
			sym_put(tags, strdup("_RTS,date"), strdup(key_get), 0);
			break;
		}
	}

	print_header(tags);

	/*
	 * The way that I am using 'Keys' and 'Tag' makes assumptions about the
	 * internals of the sym_* data structure.
	 */
	/* dump 'em all */
	for (tl = taglist; *tl != NULL; tl++) {
		if (!strcmp(*tl, "_RTS"))
			continue;

		strcpy(key_get, *tl);
		strcat(key_get, ",_keys");
		if ((Keys = sym_get(tags, key_get)) == NULL) {
			return 0;
		}

		strcpy(key_get, *tl);
		if ((Tag = sym_get(tags, key_get)) != NULL) {
			tag_report(NULL, Tag, Keys);
		}
	}
	free(taglist);

	return 0;
}

/*
 * End-Of-Test seen, insert this tag into the global tag data.
 * (1) Get the test's tag
 * (2) insert the keywords in the "_keys" tag
 * (3) insert it into the global data under this tag, replacing any existing
 *      data.
 *
 * a "feature" of the key implimentation: I can insert a key tree
 * under another key tree with almost zero brainwork because a SYM
 * is what the DATA area points to.
 */
static int scanner_test_end(alltags, ctag, keys)
SYM alltags, ctag, keys;
{
	static int notag = 0;	/* counter for records with no tag (error) */
	char tagname[KEYSIZE];	/* used when creating name (see above) */
	char *tag;		/* tag name to look things up in */
	char *status;		/* initiation status of old tag */
	SYM rm;			/* pointer to old tag -- to remove it */

	if (alltags == NULL || keys == NULL || ctag == NULL)
		return -1;	/* for really messed up test output */

	/* insert keys into tag */
	sym_put(ctag, "_keys", (void *)keys, 0);

	/* get the tag, or build a new one */
	if ((tag = (char *)sym_get(keys, "tag")) == NULL) {
		/* this is an "impossible" situation: test_output checks for this
		 * and creates a dummy tag. */
		sprintf(tagname, "no_tag_%d", notag++);
		fprintf(stderr, "No TAG key!  Using %s\n", tagname);
		sym_put(keys, "tag", strdup(tagname), 0);
		tag = strdup(tagname);
	}

	/*
	 * Special case: duplicate tag that has an initiation_status failure
	 * is thrown away.
	 */
	if ((rm = (SYM) sym_get(alltags, tag)) != NULL) {
		if ((status =
		     (char *)sym_get(keys, "initiation_status")) != NULL) {
			if (strcmp(status, "ok")) {
				/* do not take new data.  remove new data */
				sym_rm(ctag, RM_KEY | RM_DATA);
				return 1;
			} else {
				/* remove old data in alltags */
				sym_rm(rm, RM_KEY | RM_DATA);
			}
		} else {
			/* new data does not have an initiation_status -- throw it away */
			sym_rm(ctag, RM_KEY | RM_DATA);
			return 1;
		}
	}

	/* put new data.. replaces existing "tag" key if it exists
	 * (it's data should have been removed above) */
	sym_put(alltags, tag, ctag, PUT_REPLACE);

	return 0;
}

static int iscanner_reporter(tags)
SYM tags;
{
	return 0;
}

static int iscanner_test_end(alltags, ctag, keys)
SYM alltags, ctag, keys;
{
	if (alltags == NULL || keys == NULL || ctag == NULL)
		return -1;	/* for really messed up test output */

	/* insert keys into tag */
	sym_put(ctag, "_keys", (void *)keys, 0);

	return tag_report(alltags, ctag, keys);
}

int reporter(SYM s)
{
	return reporter_func(s);
}

int test_end(SYM a, SYM b, SYM c)
{
	return test_end_func(a, b, c);
}

void set_scanner(void)
{
	reporter_func = scanner_reporter;
	test_end_func = scanner_test_end;
}

void set_iscanner(void)
{
	reporter_func = iscanner_reporter;
	test_end_func = iscanner_test_end;
}