source: git/factory/ftest/ftest_util.m4 @ f8ec08

fieker-DuValspielwiese
Last change on this file since f8ec08 was c46699, checked in by Jens Schmidt <schmidt@…>, 27 years ago
* ftest_util.m4 (_ftestOutput): bug fix * ftest_util.m4 (ftestGetInVar): checks for non existing arguments now git-svn-id: file:///usr/local/Singular/svn/trunk@766 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.3 KB
Line 
1dnl $Id: ftest_util.m4,v 1.5 1997-10-01 11:09:25 schmidt Exp $
2dnl
3dnl ftest_util.m4 - m4 macros used by the factory test environment.
4dnl
5dnl "External" macro start with prefix `ftest', "internal" macros
6dnl with prefix `_'.
7dnl
8dnl Note: mind the ';'!
9dnl
10dnl do not output anything of this library
11divert(-1)
12
13#
14# - internal macros.
15#
16
17#
18# _stripTWS() - strip trailing white space from $1.
19#
20define(`_stripTWS', `dnl
21patsubst(`$1', `[       ]*$')')
22
23#
24# _qstripTWS() - strip trailing white space from $1, return
25#   quoted result.
26#
27define(`_qstripTWS', `dnl
28ifelse(
29  translit(`$1', `      '), `', ,
30  `patsubst(`$1', `\(.*[^       ]\)[    ]*$', ``\1'')')')
31
32
33#
34# - external macros.
35#
36
37#
38# ftestSetNameOfGame() - set name of game.
39#
40# $1: name of algorithm
41# $2: usage of algorithm
42#
43# These are stored in the macros `ftestAlgorithm' and
44# `ftestUsage', resp.  Leave notice on creator of this file.
45#
46define(`ftestSetNameOfGame', `dnl
47define(`ftestAlgorithm',``$1'')dnl
48define(`ftestUsage',``$2'')dnl
49`/* This file was automatically generated by m4 using the ftest_util.m4 library */'')
50
51#
52# ftestPreprocInit() - initial preprocessor directives.
53#
54define(`ftestPreprocInit', `dnl
55`#include <unistd.h>
56
57#define TIMING
58#include <timing.h>
59
60#include <factory.h>
61
62#include "ftest_util.h"
63#include "ftest_io.h"
64'')
65
66#
67# ftestGlobalInit() - global initialization.
68#
69define(`ftestGlobalInit', `dnl
70`TIMING_DEFINE_PRINT( ftestTimer )'')
71
72#
73# ftestMainInit() - initialization in main().
74#
75define(`ftestMainInit', `dnl
76`int optind = 0;
77    ftestStatusT check = UndefinedResult;
78
79    ftestSetName( argv[0], "'ftestAlgorithm`",
80        'ftestUsage`);
81
82    ftestSignalCatch()'')
83
84#
85# ftestMainExit() - clean up in main().
86#
87define(`ftestMainExit', `dnl
88`return check'')
89
90#
91# ftestOutVar() - declare output variable.
92#
93# $1: type of output variable
94# $2: name of output variable
95#
96# Stores type of variable in macro _ftestOutType_<name>.
97#
98define(`ftestOutVar', `dnl
99define(`_ftestOutType_'_qstripTWS(`$2'), `$1')dnl
100`$1 '_qstripTWS(`$2')')
101
102#
103# ftestInVar() - declare input variable.
104#
105# $1: type of input variable
106# $2: name of input variable
107#
108# Stores type of variable in macro _ftestInType_<name>.
109#
110define(`ftestInVar', `dnl
111define(`_ftestInType_'_qstripTWS(`$2'), `$1')dnl
112`$1 '_qstripTWS(`$2')`;
113    bool ftestArgGiven$2= false'')
114
115#
116# ftestGetOpts() - read options.
117#
118define(`ftestGetOpts', `dnl
119`ftestGetOpts( argc, argv, optind )'')
120
121#
122# ftestGetEnv() - read environment.
123#
124define(`ftestGetEnv', `dnl
125`ftestGetEnv( argc, argv, optind );
126    ftestPrintEnv()'')
127
128#
129# ftestGetInVar() - read variable from command line.
130#
131# $1: name of input variable
132# $2: default for optional command line arguments
133#
134define(`ftestGetInVar', `dnl
135ifelse(`$#', `1',
136  ``if ( argv[ optind ] ) {
137        ftestArgGiven$1= true;
138        $1= ftestGet'_stripTWS(`_ftestInType_$1')`( argv[ optind++ ] );
139    } else
140        ftestError( CommandlineError,
141                    "expected '_stripTWS(`_ftestInType_$1')` at position %d in commandline\n",
142                    optind )'',
143  ``if ( argv[ optind ] ) {
144        ftestArgGiven$1 = true;
145        $1 = ftestGet'_stripTWS(`_ftestInType_$1')`( argv[ optind++ ] );
146    } else
147        $1 = '_qstripTWS(`$2')')')
148
149#
150# ftestArgGiven() - check whether an argument was given.
151#
152# $1: name of input variable
153#
154define(`ftestArgGiven', `dnl
155`ftestArgGiven'_qstripTWS(`$1')')
156
157#
158# ftestSetEnv() - set factory environment.
159#
160define(`ftestSetEnv', `dnl
161`ftestSetEnv();
162    ftestPrintEnv()'')
163
164#
165# ftestRun() - run test.
166#
167# $1: code to execute
168#
169define(`ftestRun', `dnl
170`if ( ftestAlarm )
171        alarm( ftestAlarm );
172    while ( ftestCircle > 0 ) {
173        TIMING_START(ftestTimer);
174        $1
175        TIMING_END(ftestTimer);
176        ftestCircle--;
177    }'')
178
179#
180# ftestCheck() - run check.
181#
182# $1: check function (with parameters) to call
183#
184define(`ftestCheck', `dnl
185`check = '_qstripTWS(`$1')')
186
187#
188# ftestOuput() - print results.
189#
190# Expands to code to print timer and check.  Then, for each
191# argument pair `resultName, result', expands to print this
192# pair.
193#
194
195# internal auxiliary function
196define(`_ftestOutput', `dnl
197ifelse(`$#', `0', ,
198  `$#', `1', ,
199``;
200    ftestPrintResult( $1, '_qstripTWS(`$2')` )'_ftestOutput(shift(shift($@)))')')
201
202define(`ftestOutput', `dnl
203`ftestPrintTimer( timing_ftestTimer_time );
204    ftestPrintCheck( check )'_ftestOutput($@)')
205
206# set comment character
207changecom(`//');
208
209dnl switch on output again
210divert`'dnl
Note: See TracBrowser for help on using the repository browser.