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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
/*
Copyright (c) 2005 X.Org Foundation LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
*
* Copyright (c) Applied Testing and Technology, Inc. 1995
* All Rights Reserved.
*
* Project: VSW5
*
* File: src/bin/mc/sections.c
*
* Description:
* misc routines for mc utilities
*
* Modifications:
* $Log: sections.c,v $
* Revision 1.1 2005-02-12 14:37:14 anderson
* Initial revision
*
* Revision 8.0 1998/12/23 23:24:17 mar
* Branch point for Release 5.0.2
*
* Revision 7.0 1998/10/30 22:42:26 mar
* Branch point for Release 5.0.2b1
*
* Revision 6.0 1998/03/02 05:16:43 tbr
* Branch point for Release 5.0.1
*
* Revision 5.0 1998/01/26 03:13:15 tbr
* Branch point for Release 5.0.1b1
*
* Revision 4.1 1997/01/22 22:14:29 andy
* Xt6 section now flagged as not needing Athena
*
* Revision 4.0 1995/12/15 08:41:26 tbr
* Branch point for Release 5.0.0
*
* Revision 3.2 1995/12/15 00:38:17 andy
* Prepare for GA Release
*
*/
/*
Portions of this software are based on Xlib and X Protocol Test Suite.
We have used this material under the terms of its copyright, which grants
free use, subject to the conditions below. Note however that those
portions of this software that are based on the original Test Suite have
been significantly revised and that all such revisions are copyright (c)
1995 Applied Testing and Technology, Inc. Insomuch as the proprietary
revisions cannot be separated from the freely copyable material, the net
result is that use of this software is governed by the ApTest copyright.
Copyright (c) 1990, 1991 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.
Copyright 1990, 1991 by UniSoft Group Limited.
Permission to use, copy, modify, distribute, and sell this software and
its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of UniSoft not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission. UniSoft
makes no representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied warranty.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <ctype.h>
#include "string.h"
#include "mc.h"
extern int Cmdname;
extern struct state State;
extern struct settings Settings;
extern int mflag;
/*
* What needs to be defaulted. Note that it is sort of assumed that
* code follows strategy even though this is not tested at present.
*/
#define NEED_STRAT 0x1
#define NEED_CODE 0x2
#if 0
/* Template for sections */
, /* copyright */
, /* header */
, /* assertion */
, /* defassertion */
, /* strategy */
, /* code */
, /* extern code */
, /* extra files */
, /* make files */
#endif
#if 0
/* Template for hooks */
, /* start */
, /* end */
, /* include start hook */
, /* include end hook */
, /* set hook */
, /* comment hook */
#endif
void (*secsw[][NSEC])() = {
{ /* mexpand */
mepcopyright, /* copyright */
mepecho, /* header */
mepecho, /* assertion */
mepecho, /* defassertion */
mepecho, /* strategy */
mepecho, /* code */
mepecho, /* extern code */
mepecho, /* make lines */
mepecho, /* make files */
skip,
},
{ /* mc */
mccopyright, /* copyright */
mcheader, /* header */
mcassertion, /* assertion */
mcdefassertion, /* defassertion */
mcstrategy, /* strategy */
mccode, /* code */
mcexterncode, /* extern code */
skip, /* extra files */
skip, /* make files */
skip,
},
{ /* mmkf */
mmcopyright, /* copyright */
mmheader, /* header */
skip, /* assertion */
skip, /* defassertion */
skip, /* strategy */
skip, /* code */
skip, /* extern code */
mmcfiles, /* extra files */
mmmake, /* make section */
skip,
},
{ /* ma */
macopyright, /* copyright */
maheader, /* header */
maassertion, /* assertion */
madefassertion, /* defassertion */
skip, /* strategy */
skip, /* code */
skip, /* extern code */
skip, /* extra files */
skip, /* make files */
skip,
},
{ /* mas */
mascopyright, /* copyright */
masheader, /* header */
masassertion, /* assertion */
masassertion, /* defassertion */
masstrategy, /* strategy */
skip, /* code */
skip, /* extern code */
skip, /* extra files */
skip, /* make files */
skip,
},
};
void (*hooksw[][NHOOK])() = {
{
mepstart, /* start */
mepend, /* end */
0, /* include start hook */
0, /* include end hook */
mepset, /* set hook */
mepcomment, /* comment hook */
},
{
mcstart, /* start */
mcend, /* end */
mcincstart, /* include start hook */
mcincend, /* include end hook */
0, /* set hook */
0, /* comment hook */
},
{
mmstart, /* start */
mmend, /* end */
mmincstart, /* include start hook */
0, /* include end hook */
0, /* set hook */
0, /* comment hook */
},
{
mastart, /* start */
maend, /* end */
0, /* include start hook */
0, /* include end hook */
0, /* set hook */
macomment, /* comment hook */
},
{
masstart, /* start */
masend, /* end */
0, /* include start hook */
0, /* include end hook */
0, /* set hook */
0, /* comment hook */
},
};
#define NCMDS (sizeof(secsw)/(NSEC*sizeof(void (*)())))
struct secname {
char *name;
int sec;
} secname[] = {
{D_HEADER, SEC_HEADER},
{D_ASSERTION, SEC_ASSERTION},
{D_STRATEGY, SEC_STRATEGY},
{D_CODE, SEC_CODE},
{D_EXTERN, SEC_EXTERNCODE},
{D_CFILE, SEC_FILE},
{D_MAKE, SEC_MAKE},
{D_AVSCODE, SEC_AVSCODE},
};
/*
* Loop through all sections and branch out to the appropriate strategy
* routines.
*/
dosections(fp, buf)
FILE *fp;
char *buf;
{
struct secname *sp;
int sec;
if (State.skipsec == 0)
do1sec(fp, buf, SEC_COPYRIGHT);
while (State.skipsec > 0) {
State.skipsec--;
skip(fp, buf);
}
while (!feof(fp)) {
sec = -1;
for (sp = secname; sp < secname+NELEM(secname); sp++) {
if (strncmp(buf, sp->name, strlen(sp->name)) == 0) {
sec = sp->sec;
break;
}
}
if (sec == -1) {
if (strncmp(buf, D_INCLUDE, strlen(D_INCLUDE)) == 0) {
includefile(buf+strlen(D_INCLUDE), buf);
newline(fp, buf);
continue;
} else {
err("Bad directive\n");
errexit();
}
}
/* XXX Temp because of the push-back line problem */
State.sectype = sec;
if (sec == SEC_ASSERTION) {
assertion(fp, buf);
} else {
do1sec(fp, buf, sec);
}
if (State.abortafter > 0) {
if (--State.abortafter == 0)
break;
}
}
}
/*
* Do an assertion. There are three types of assertion regular, def
* and gc. The gc type are sorted out by gccomps the others
* branch to their own strategies.
*/
assertion(fp, buf)
FILE *fp;
char *buf;
{
char *line;
char *str;
char *type;
int reason;
static char *reasons[] = {
"Temporarily can't be implemented",
"There is no known portable test method for this assertion",
"The statement in the X11 specification is not specific enough to write a test",
"There is no known reliable test method for this assertion",
"Testing the assertion would require setup procedures that involve an unreasonable amount of effort by the user of the test suite.",
"Testing the assertion would require an unreasonable amount of time or resources on most systems",
"Creating a test would require an unreasonable amount of test development time.",
};
/* Check for default error sections */
dodefaults(buf);
State.assertion++;
line = mcstrdup(buf); /* Must not be freed */
str = strtok(line, SEPS);
type = strtok((char*)0, SEPS);
/*
* When in an included error file then the type cannot be allowed
* to overrule the type that the programmer has selected. This is
* because it affects things like Status returns.
*/
if (State.err == ER_NONE)
State.type = type;
if (type == NULL)
type = "NOT-SET";
if (strcmp(type, "def") == 0) {
State.category = CAT_DEF;
do1sec(fp, buf, SEC_DEFASSERT);
} else if (strcmp(type, "gc") == 0) {
/*
* Since this is not a real assertion then undo the
* state changes above.
*/
State.assertion--;
gccomps(fp, buf);
} else {
str = strtok((char*)0, SEPS);
if (str == NULL)
str = "";
State.category = *str;
if (State.category == CAT_B || State.category == CAT_D) {
State.reason = NULL;
str = strtok((char*)0, SEPS);
if (str && isdigit(*str)) {
reason = atoi(str);
if (reason < NELEM(reasons))
State.reason = reasons[reason];
}
}
/* XXX Temp. to get expansion */
State.sectype = SEC_ASSERTION;
/*
* Look ahead to see if there is an error. This is probably
* slightly better than the way it used to be done.
*/
line = mcstrdup(buf);
if (newline(fp, buf) && strncmp(buf, ".ER", 3) == 0) {
/* Back out of the assertion so far */
State.assertion--;
errtext(buf);
newline(fp, buf);
} else {
putbackline(buf);
(void) strcpy(buf, line);
State.defaultreq = NEED_STRAT|NEED_CODE;
do1sec(fp, buf, SEC_ASSERTION);
}
free(line);
}
}
/*
* Do one section.
*/
void do1sec(fp, buf, sec)
FILE *fp;
char *buf;
int sec;
{
char *line;
char *str;
int i;
State.sectype = sec;
if (sec >= NSEC) {
(void) fprintf(stderr, "Internal error: invalid command\n");
errexit();
}
/*
* Any special action that needs to be done at the global level
* for a section.
*/
switch (sec) {
case SEC_STRATEGY:
State.defaultreq &= ~NEED_STRAT;
if (State.discardtest) {
skip(fp, buf);
return;
}
break;
case SEC_CODE:
State.defaultreq &= ~NEED_CODE;
if (State.discardtest) {
skip(fp, buf);
return;
}
if (State.err == ER_VALUE)
valerrdefs();
State.err = 0;
break;
case SEC_AVSCODE:
State.xcms = 1;
break;
case SEC_HEADER:
line = mcstrdup(buf);
if ((str = strtok(line+strlen(D_HEADER), SEPS)) == NULL)
str = "";
/*
* If the name has changed, then reset the assertion number to
* zero.
*/
if (State.name == NULL || strcmp(str, State.name) != 0)
State.assertion = 0;
State.name = str;
State.chap = strtok((char*)0, SEPS);
if (State.name == NULL)
State.name = "NoName";
if (State.chap == NULL)
State.chap = "";
/*
* If we are in macro mode then either take an explicit macro
* name if given, or construct the name by removing the leading
* letter 'X'.
*/
if (mflag) {
if (Settings.macroname)
State.name = Settings.macroname;
if (State.name[0] == 'X')
State.name++;
}
/* Check for xprotocol test */
i = strlen(State.chap);
if (i > 5 && strcmp(State.chap + i - 5, "proto") == 0)
State.xproto = 1;
/* Check for Xt or Shape Extension test */
if (strncmp(State.chap, "Xt", 2) == 0) {
State.xtoolkit = 1;
if (!strncmp(State.chap, "Xt6", 3) == 0) {
State.xtathena = 1;
}
}
if (strncmp(State.chap, "ShapeExt", 8) == 0) {
State.xtoolkit = 1;
}
break;
case SEC_ASSERTION:
case SEC_DEFASSERT:
/*
* Are we interested in this assertion? If not then just skip
* code and strategy until the next assertion.
*/
if (!isassertwanted(State.assertion)) {
State.defaultreq = 0;
State.discardtest = 1;
skip(fp, buf);
return;
}
State.discardtest = 0;
break;
}
if (secsw[Cmdname][sec])
(*secsw[Cmdname][sec])(fp, buf);
}
/*
* Switch out to the command specific hook command.
*/
dohook(buf, hook)
char *buf;
int hook;
{
if (hook >= NHOOK) {
(void) fprintf(stderr, "Internal error: invalid hook\n");
errexit();
}
if (Cmdname >= NCMDS) {
(void) fprintf(stderr, "Internal error: command not implemented\n");
errexit();
}
if (hooksw[Cmdname][hook])
(*hooksw[Cmdname][hook])(buf);
}
/*
* Skip over this section.
*/
void
skip(fp, buf)
FILE *fp;
char *buf;
{
while (newline(fp, buf) != NULL && !SECSTART(buf))
;
}
/*
* Copy the complete section straight to the output, including the
* section start line.
*/
void
echo(fp, buf, fpout)
FILE *fp;
char *buf;
FILE *fpout;
{
fwrite(buf, strlen(buf), 1, fpout);
echon(fp, buf, fpout);
}
/*
* Copy this section straight to the output, without the section start
* line.
*/
void
echon(fp, buf, fpout)
FILE *fp;
char *buf;
FILE *fpout;
{
while (newline(fp, buf) != NULL && !SECSTART(buf))
fwrite(buf, strlen(buf), 1, fpout);
}
/*
* At this point we insert any default code that needs inserting.
*/
void dodefaults(buf)
char *buf;
{
FILE *fp;
int needed;
char *tmpfile;
/*
* If there is any supplied strategy or code then there are no defaults.
*/
if (!State.defaultreq)
return;
needed = State.defaultreq;
State.defaultreq = 0;
if (State.err) {
errcode(buf);
State.err = 0;
return;
}
/* Default code stub */
fp = cretmpfile(F_TDEFCODE, &tmpfile);
switch (State.category) {
case CAT_B: case CAT_D: /* Untested */
if (needed & NEED_STRAT) {
(void) fprintf(fp, ">>STRATEGY\n");
(void) fprintf(fp, "Report UNTESTED\n");
}
if (needed & NEED_CODE) {
(void) fprintf(fp, ">>CODE\n\n");
/*
(void) fprintf(fp, "\treport(\"%s\");\n", State.reason);
*/
(void) fprintf(fp, "\tUNTESTED;\n");
}
break;
default: /* No code written */
if (needed & NEED_STRAT) {
(void) fprintf(fp, ">>STRATEGY\n");
if (needed & NEED_CODE)
(void) fprintf(fp, "Report that no code has been written for this test.\n");
else
(void) fprintf(fp, "No strategy has been written for this test\n");
}
if (needed & NEED_CODE) {
(void) fprintf(fp, ">>CODE\n");
(void) fprintf(fp, "\treport(\"No code written for this assertion.\");\n");
}
break;
}
fclose(fp);
includefile(tmpfile, buf);
}
|