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

fieker-DuValspielwiese
Last change on this file since 040544 was 040544, checked in by Jens Schmidt <schmidt@…>, 27 years ago
* ftest_util.m4: cosmetic changes git-svn-id: file:///usr/local/Singular/svn/trunk@896 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.5 KB
Line 
1dnl $Id: ftest_util.m4,v 1.11 1997-11-13 08:37:43 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#
54# In addition, we change m4's comment character.
55#
56define(`ftestPreprocInit', `dnl
57changecom(`//')dnl
58`#include <unistd.h>
59
60#define TIMING
61#include <timing.h>
62
63#include <factory.h>
64
65#include "ftest_util.h"
66#include "ftest_io.h"
67'')
68
69#
70# ftestGlobalInit() - global initialization.
71#
72define(`ftestGlobalInit', `dnl
73`TIMING_DEFINE_PRINT( ftestTimer )'')
74
75#
76# ftestMainInit() - initialization in main().
77#
78define(`ftestMainInit', `dnl
79`int optind = 0;
80    ftestStatusT check = UndefinedResult;
81
82    ftestSetName( argv[0], "'ftestAlgorithm`", 'ftestUsage`);
83
84    ftestSignalCatch()'')
85
86#
87# ftestMainExit() - clean up in main().
88#
89define(`ftestMainExit', `dnl
90`return check'')
91
92#
93# ftestOutVar() - declare output variable.
94#
95# $1: type of output variable
96# $2: name of output variable
97#
98# Stores type of variable in macro _ftestOutType_<name>.
99#
100define(`ftestOutVar', `dnl
101define(`_ftestOutType_'_qstripTWS(`$2'), `$1')dnl
102ifelse(`$1', `int',
103  ``$1 '_qstripTWS(`$2')` = 0;'',
104  ``$1 '_qstripTWS(`$2')`;'')')
105
106#
107# ftestInVar() - declare input variable.
108#
109# $1: type of input variable
110# $2: name of input variable
111#
112# Stores type of variable in macro _ftestInType_<name>.
113#
114define(`ftestInVar', `dnl
115define(`_ftestInType_'_qstripTWS(`$2'), `$1')dnl
116ifelse(`$1', `int',
117  ``$1 '_qstripTWS(`$2')` = 0;'',
118  ``$1 '_qstripTWS(`$2')`;'')`
119    bool ftestArgGiven$2= false'')
120
121#
122# ftestGetOpts() - read options.
123#
124define(`ftestGetOpts', `dnl
125`ftestGetOpts( argc, argv, optind )'')
126
127#
128# ftestGetEnv() - read environment.
129#
130define(`ftestGetEnv', `dnl
131`ftestGetEnv( argc, argv, optind );
132    ftestPrintEnv()'')
133
134#
135# ftestGetInVar() - read variable from command line.
136#
137# $1: name of input variable
138# $2: default for optional command line arguments
139#
140define(`ftestGetInVar', `dnl
141ifelse(`$#', `1',
142  ``if ( argv[ optind ] ) {
143        ftestArgGiven$1= true;
144        $1= ftestGet'_stripTWS(`_ftestInType_$1')`( argv[ optind++ ] );
145    } else
146        ftestError( CommandlineError,
147                    "expected '_stripTWS(`_ftestInType_$1')` at position %d in commandline\n",
148                    optind )'',
149  ``if ( argv[ optind ] ) {
150        ftestArgGiven$1 = true;
151        $1 = ftestGet'_stripTWS(`_ftestInType_$1')`( argv[ optind++ ] );
152    } else
153        $1 = '_qstripTWS(`$2')')')
154
155#
156# ftestArgGiven() - check whether an argument was given.
157#
158# $1: name of input variable
159#
160define(`ftestArgGiven', `dnl
161`ftestArgGiven'_qstripTWS(`$1')')
162
163#
164# ftestSetEnv() - set factory environment.
165#
166define(`ftestSetEnv', `dnl
167`ftestSetEnv();
168    ftestPrintEnv()'')
169
170#
171# ftestRun() - run test.
172#
173# $1: code to execute
174#
175define(`ftestRun', `dnl
176`ftestWriteSeed();                      // save random generator seed
177    if ( ftestAlarm )
178        alarm( ftestAlarm );            // set alarm
179    TIMING_START(ftestTimer);
180    while ( ftestCircle > 0 ) {
181        $1
182        ftestCircle--;
183    };
184    TIMING_END(ftestTimer)'')
185
186#
187# ftestCheck() - run check.
188#
189# $1: check function (with parameters) to call
190#
191define(`ftestCheck', `dnl
192`check = '_qstripTWS(`$1')')
193
194#
195# ftestOuput() - print results.
196#
197# Expands to code to print timer and check.  Then, for each
198# argument pair `resultName, result', expands to print this
199# pair.
200#
201
202# internal auxiliary function
203define(`_ftestOutput', `dnl
204ifelse(`$#', `0', ,
205  `$#', `1', ,
206``;
207    ftestPrintResult( $1, '_qstripTWS(`$2')` )'_ftestOutput(shift(shift($@)))')')
208
209define(`ftestOutput', `dnl
210`ftestPrintTimer( timing_ftestTimer_time );
211    ftestPrintCheck( check )'_ftestOutput($@)')
212
213dnl switch on output again
214divert`'dnl
Note: See TracBrowser for help on using the repository browser.