• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vermaseren / form / 11836029626

14 Nov 2024 11:09AM UTC coverage: 53.453% (+0.02%) from 53.438%
11836029626

push

github

jodavies
Remove the old sort allocation code

32 of 32 new or added lines in 2 files covered. (100.0%)

80 existing lines in 2 files now uncovered.

39797 of 74453 relevant lines covered (53.45%)

1080064.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.41
/sources/setfile.c
1
/** @file setfile.c
2
 * 
3
 *  The routines that deal with the setup parameters.
4
 */
5
/* #[ License : */
6
/*
7
 *   Copyright (C) 1984-2023 J.A.M. Vermaseren
8
 *   When using this file you are requested to refer to the publication
9
 *   J.A.M.Vermaseren "New features of FORM" math-ph/0010025
10
 *   This is considered a matter of courtesy as the development was paid
11
 *   for by FOM the Dutch physics granting agency and we would like to
12
 *   be able to track its scientific use to convince FOM of its value
13
 *   for the community.
14
 *
15
 *   This file is part of FORM.
16
 *
17
 *   FORM is free software: you can redistribute it and/or modify it under the
18
 *   terms of the GNU General Public License as published by the Free Software
19
 *   Foundation, either version 3 of the License, or (at your option) any later
20
 *   version.
21
 *
22
 *   FORM is distributed in the hope that it will be useful, but WITHOUT ANY
23
 *   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24
 *   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
25
 *   details.
26
 *
27
 *   You should have received a copy of the GNU General Public License along
28
 *   with FORM.  If not, see <http://www.gnu.org/licenses/>.
29
 */
30
/* #] License : */ 
31
/*
32
          #[ Includes :
33

34
        Routines that deal with settings and the setup file
35
*/
36

37
#include "form3.h"
38

39
char curdirp[] = ".";
40
char cursortdirp[] = ".";
41
char commentchar[] = "*";
42
char dotchar[] = "_";
43
char highfirst[] = "highfirst";
44
char lowfirst[] = "lowfirst";
45
char procedureextension[] = "prc";
46

47
#define NUMERICALVALUE 0
48
#define STRINGVALUE 1
49
#define PATHVALUE 2
50
#define ONOFFVALUE 3
51
#define DEFINEVALUE 4
52

53
SETUPPARAMETERS setupparameters[] = 
54
{
55
         {(UBYTE *)"bracketindexsize",      NUMERICALVALUE, 0, (LONG)MAXBRACKETBUFFERSIZE}
56
        ,{(UBYTE *)"commentchar",              STRINGVALUE, 0, (LONG)commentchar}
57
        ,{(UBYTE *)"compresssize",          NUMERICALVALUE, 0, (LONG)COMPRESSBUFFER}
58
        ,{(UBYTE *)"constindex",            NUMERICALVALUE, 0, (LONG)NUMFIXED}
59
        ,{(UBYTE *)"continuationlines",     NUMERICALVALUE, 0, (LONG)FORTRANCONTINUATIONLINES}
60
        ,{(UBYTE *)"define",                   DEFINEVALUE, 0, (LONG)0}
61
        ,{(UBYTE *)"dotchar",                  STRINGVALUE, 0, (LONG)dotchar}
62
        ,{(UBYTE *)"factorizationcache",    NUMERICALVALUE, 0, (LONG)FBUFFERSIZE}
63
        ,{(UBYTE *)"filepatches",           NUMERICALVALUE, 0, (LONG)MAXFPATCHES}
64
        ,{(UBYTE *)"functionlevels",        NUMERICALVALUE, 0, (LONG)MAXFLEVELS}
65
        ,{(UBYTE *)"hidesize",              NUMERICALVALUE, 0, (LONG)0}
66
        ,{(UBYTE *)"incdir",                     PATHVALUE, 0, (LONG)curdirp}
67
        ,{(UBYTE *)"indentspace",           NUMERICALVALUE, 0, (LONG)INDENTSPACE}
68
        ,{(UBYTE *)"insidefirst",               ONOFFVALUE, 0, (LONG)1}
69
        ,{(UBYTE *)"jumpratio",             NUMERICALVALUE, 0, (LONG)JUMPRATIO}
70
        ,{(UBYTE *)"largepatches",          NUMERICALVALUE, 0, (LONG)MAXPATCHES}
71
        ,{(UBYTE *)"largesize",             NUMERICALVALUE, 0, (LONG)LARGEBUFFER}
72
        ,{(UBYTE *)"maxnumbersize",         NUMERICALVALUE, 0, (LONG)0}
73
/*        ,{(UBYTE *)"maxnumbersize",         NUMERICALVALUE, 0, (LONG)MAXNUMBERSIZE} */
74
        ,{(UBYTE *)"maxtermsize",           NUMERICALVALUE, 0, (LONG)MAXTER}
75
        ,{(UBYTE *)"maxwildcards",          NUMERICALVALUE, 0, (LONG)MAXWILDC}
76
        ,{(UBYTE *)"nospacesinnumbers",         ONOFFVALUE, 0, (LONG)0}
77
        ,{(UBYTE *)"numstorecaches",        NUMERICALVALUE, 0, (LONG)NUMSTORECACHES}
78
        ,{(UBYTE *)"nwritefinalstatistics",     ONOFFVALUE, 0, (LONG)0}
79
        ,{(UBYTE *)"nwriteprocessstatistics",   ONOFFVALUE, 0, (LONG)0}
80
        ,{(UBYTE *)"nwritestatistics",          ONOFFVALUE, 0, (LONG)0}
81
        ,{(UBYTE *)"nwritethreadstatistics",    ONOFFVALUE, 0, (LONG)0}
82
        ,{(UBYTE *)"oldfactarg",                ONOFFVALUE, 0, (LONG)NEWFACTARG}
83
        ,{(UBYTE *)"oldgcd",                    ONOFFVALUE, 0, (LONG)1}
84
        ,{(UBYTE *)"oldorder",                  ONOFFVALUE, 0, (LONG)0}
85
        ,{(UBYTE *)"oldparallelstatistics",     ONOFFVALUE, 0, (LONG)0}
86
        ,{(UBYTE *)"parentheses",           NUMERICALVALUE, 0, (LONG)MAXPARLEVEL}
87
        ,{(UBYTE *)"path",                       PATHVALUE, 0, (LONG)curdirp}
88
        ,{(UBYTE *)"procedureextension",       STRINGVALUE, 0, (LONG)procedureextension}
89
        ,{(UBYTE *)"processbucketsize",     NUMERICALVALUE, 0, (LONG)DEFAULTPROCESSBUCKETSIZE}
90
        ,{(UBYTE *)"resettimeonclear",          ONOFFVALUE, 0, (LONG)1}
91
        ,{(UBYTE *)"scratchsize",           NUMERICALVALUE, 0, (LONG)SCRATCHSIZE}
92
        ,{(UBYTE *)"shmwinsize",            NUMERICALVALUE, 0, (LONG)SHMWINSIZE}
93
        ,{(UBYTE *)"sizestorecache",        NUMERICALVALUE, 0, (LONG)SIZESTORECACHE}
94
        ,{(UBYTE *)"smallextension",        NUMERICALVALUE, 0, (LONG)SMALLOVERFLOW}
95
        ,{(UBYTE *)"smallsize",             NUMERICALVALUE, 0, (LONG)SMALLBUFFER}
96
        ,{(UBYTE *)"sortiosize",            NUMERICALVALUE, 0, (LONG)SORTIOSIZE}
97
        ,{(UBYTE *)"sorttype",                 STRINGVALUE, 0, (LONG)lowfirst}
98
        ,{(UBYTE *)"spectatorsize",         NUMERICALVALUE, 0, (LONG)SPECTATORSIZE}
99
        ,{(UBYTE *)"subfilepatches",        NUMERICALVALUE, 0, (LONG)SMAXFPATCHES}
100
        ,{(UBYTE *)"sublargepatches",       NUMERICALVALUE, 0, (LONG)SMAXPATCHES}
101
        ,{(UBYTE *)"sublargesize",          NUMERICALVALUE, 0, (LONG)SLARGEBUFFER}
102
        ,{(UBYTE *)"subsmallextension",     NUMERICALVALUE, 0, (LONG)SSMALLOVERFLOW}
103
        ,{(UBYTE *)"subsmallsize",          NUMERICALVALUE, 0, (LONG)SSMALLBUFFER}
104
        ,{(UBYTE *)"subsortiosize",         NUMERICALVALUE, 0, (LONG)SSORTIOSIZE}
105
        ,{(UBYTE *)"subtermsinsmall",       NUMERICALVALUE, 0, (LONG)STERMSSMALL}
106
        ,{(UBYTE *)"tempdir",                  STRINGVALUE, 0, (LONG)curdirp}
107
        ,{(UBYTE *)"tempsortdir",              STRINGVALUE, 0, (LONG)cursortdirp}
108
        ,{(UBYTE *)"termsinsmall",          NUMERICALVALUE, 0, (LONG)TERMSSMALL}
109
    ,{(UBYTE *)"threadbucketsize",      NUMERICALVALUE, 0, (LONG)DEFAULTTHREADBUCKETSIZE}
110
    ,{(UBYTE *)"threadloadbalancing",       ONOFFVALUE, 0, (LONG)DEFAULTTHREADLOADBALANCING}
111
    ,{(UBYTE *)"threads",               NUMERICALVALUE, 0, (LONG)DEFAULTTHREADS}
112
        ,{(UBYTE *)"threadscratchoutsize",  NUMERICALVALUE, 0, (LONG)THREADSCRATCHOUTSIZE}
113
        ,{(UBYTE *)"threadscratchsize",     NUMERICALVALUE, 0, (LONG)THREADSCRATCHSIZE}
114
    ,{(UBYTE *)"threadsortfilesynch",       ONOFFVALUE, 0, (LONG)0}
115
        ,{(UBYTE *)"totalsize",                 ONOFFVALUE, 0, (LONG)2}
116
        ,{(UBYTE *)"workspace",             NUMERICALVALUE, 0, (LONG)WORKBUFFER}
117
        ,{(UBYTE *)"wtimestats",                ONOFFVALUE, 0, (LONG)2}
118
};
119

120
/*
121
          #] Includes : 
122
        #[ Setups :
123
                 #[ DoSetups :
124
*/
125

126
int DoSetups()
1,828✔
127
{
128
        UBYTE *setbuffer, *s, *t, *u /*, c */;
1,828✔
129
        int errors = 0;
1,828✔
130
        setbuffer = LoadInputFile((UBYTE *)setupfilename,SETUPFILE);
1,828✔
131
        if ( setbuffer ) {
1,828✔
132
/*
133
                The contents of the file are now in setbuffer.
134
                Each line is commentary or a single command.
135
                The buffer is terminated with a zero.
136
*/
137
                s = setbuffer;
138
                while ( *s ) {
×
139
                        if ( *s == ' ' || *s == '\t' || *s == '*' || *s == '#' || *s == '\n' ) {
×
140
                                while ( *s && *s != '\n' ) s++;
×
141
                        }
142
                        else if ( tolower(*s) < 'a' || tolower(*s) > 'z' ) {
×
143
                                t = s;
×
144
                                while ( *s && *s != '\n' ) s++;
×
145
/*
146
                                c = *s; *s = 0;
147
                                Error1("Setup file: Illegal statement: ",t);
148
                                errors++; *s = c;
149
*/
150
                        }
151
                        else {
152
                                t = s; /* name of the option */
×
153
                                while ( tolower(*s) >= 'a' && tolower(*s) <= 'z' ) s++;
×
154
                                *s++ = 0;
×
155
                                while ( *s == ' ' || *s == '\t' ) s++;
×
156
                                u = s; /* 'value' of the option */
×
157
                                while ( *s && *s != '\n' && *s != '\r' ) s++;
×
158
                                if ( *s ) *s++ = 0;
×
159
                                errors += ProcessOption(t,u,0);
×
160
                        }
161
                        while ( *s == '\n' || *s == '\r' ) s++;
×
162
                }
163
                M_free(setbuffer,"setup file buffer");
×
164
        }
165
        if ( errors ) return(1);
×
166
        else return(0);
1,828✔
167
}
168

169
/*
170
                 #] DoSetups : 
171
                 #[ ProcessOption :
172
*/
173

174
static char *proop1[3] = { "Setup file", "Setups in .frm file", "Setup in environment" };
175

176
int ProcessOption(UBYTE *s1, UBYTE *s2, int filetype)
198✔
177
{
178
        SETUPPARAMETERS *sp;
198✔
179
        int n, giveback = 0, error = 0;
198✔
180
        UBYTE *s, *t, *s2ret;
198✔
181
        LONG x;
198✔
182
        sp = GetSetupPar(s1);
198✔
183
        if ( sp ) {
198✔
184
/*
185
                We check now whether there are `' variables to be looked up in the
186
                environment. This is new (30-may-2008). This is only allowed in s2.
187
*/
188
restart:;
198✔
189
                {
190
                        UBYTE *s3,*s4,*s5,*s6, c, *start;
198✔
191
                        int n1,n2,n3;
198✔
192
                        s = s2;
198✔
193
                        while ( *s ) {
802✔
194
                                if ( *s == '\\' ) s += 2;
604✔
195
                                else if ( *s == '`' ) {
604✔
196
                                        start = s; s++;
×
197
                                        while ( *s && *s != '\'' ) {
×
198
                                                if ( *s == '\\' ) s++;
×
199
                                                s++;
×
200
                                        }
201
                                        if ( *s == 0 ) {
×
202
                                                MesPrint("%s: Illegal use of ` character for parameter %s"
×
203
                                                ,proop1[filetype],s1);
204
                                                return(1);
×
205
                                        }
206
                                        c = *s; *s = 0;
×
207
                                        s3 = (UBYTE *)getenv((char *)(start+1));
×
208
                                        if ( s3 == 0 ) {
×
209
                                                MesPrint("%s: Cannot find environment variable %s for parameter %s"
×
210
                                                ,proop1[filetype],start+1,s1);
211
                                                return(1);
×
212
                                                
213
                                        }
214
                                        *s = c; s++;
×
215
                                        n1 = start - s2; s4 = s3; n2 = 0;
×
216
                                        while ( *s4 ) {
×
217
                                                if ( *s4 == '\\' ) { s4++; n2++; }
×
218
                                                s4++; n2++;
×
219
                                        }
220
                                        s4 = s; n3 = 0;
221
                                        while ( *s4 ) {
×
222
                                                if ( *s4 == '\\' ) { s4++; n3++; }
×
223
                                                s4++; n3++;
×
224
                                        }
225
                                        s4 = (UBYTE *)Malloc1((n1+n2+n3+1)*sizeof(UBYTE),"environment in setup");
×
226
                                        s5 = s2; s6 = s4;
×
227
                                        while ( n1-- > 0 ) *s6++ = *s5++;
×
228
                                        s5 = s3;
229
                                        while ( n2-- > 0 ) *s6++ = *s5++;
×
230
                                        s5 = s;
231
                                        while ( n3-- > 0 ) *s6++ = *s5++;
×
232
                                        *s6 = 0;
×
233
                                        if ( giveback ) M_free(s2,"environment in setup");
×
234
                                        s2 = s4;
×
235
                                        giveback = 1;
×
236
                                        goto restart;
×
237
                                }
238
                                else s++;
604✔
239
                        }
240
                }
241
                n = sp->type;
198✔
242
                s2ret = s2;
198✔
243
                switch ( n ) {
198✔
244
                        case NUMERICALVALUE:
245
                                ParseNumber(x,s2);
526✔
246
                                if ( *s2 == 'K' ) { x = x * 1000; s2++; }
156✔
247
                                else if ( *s2 == 'M' ) { x = x * 1000000; s2++; }
90✔
248
                                else if ( *s2 == 'G' ) { x = x * 1000000000; s2++; }
90✔
249
                                else if ( *s2 == 'T' ) { x = x * 1000000000000; s2++; }
90✔
250
                                if ( *s2 && *s2 != ' ' && *s2 != '\t' ) {
156✔
251
                                        MesPrint("%s: Numerical value expected for parameter %s"
×
252
                                        ,proop1[filetype],s1);
253
                                        error = 1; break;
×
254
                                }
255
                                sp->value = x;
156✔
256
                                sp->flags = USEDFLAG;
156✔
257
                                break;
156✔
258
                        case STRINGVALUE:
×
259
                                if ( StrICmp(s1,(UBYTE *)"tempsortdir") == 0 ) AM.havesortdir = 1;
×
260
                                s = s2; t = s2;
261
                                while ( *s ) {
×
262
                                        if ( *s == ' ' || *s == '\t' ) break;
×
263
                                        if ( *s == '\\' ) s++;
×
264
                                        *t++ = *s++;
×
265
                                }
266
                                *t = 0;
×
267
                                if ( sp->flags == USEDFLAG && sp->value != 0 )
×
268
                                                M_free((VOID *)(sp->value),"Process option");
×
269
                                sp->value = (LONG)strDup1(s2,"Process option");
×
270
                                sp->flags = USEDFLAG;
×
271
                                break;
×
272
                        case PATHVALUE:
42✔
273
                                if ( StrICmp(s1,(UBYTE *)"incdir") == 0 ) {
42✔
274
                                        AM.IncDir = 0;
14✔
275
                                }
276
                                else if ( StrICmp(s1,(UBYTE *)"path") == 0 ) {
28✔
277
                                        if ( AM.Path ) M_free(AM.Path,"path");
28✔
278
                                        AM.Path = 0;
28✔
279
                                }
280
                                else {
281
                                        MesPrint("Setups: %s not yet implemented",s1);
×
282
                                        error = 1;
×
283
                                        break;
×
284
                                }
285
                                if ( sp->flags == USEDFLAG && sp->value != 0 )
42✔
286
                                        M_free((VOID *)(sp->value),"Process option");
×
287
                                sp->value = (LONG)strDup1(s2,"Process option");
42✔
288
                                sp->flags = USEDFLAG;
42✔
289
                                break;
42✔
290
                        case ONOFFVALUE:
291
                                if ( tolower(*s2) == 'o' && tolower(s2[1]) == 'n'
×
292
                                && ( s2[2] == 0 || s2[2] == ' ' || s2[2] == '\t' ) )
×
293
                                        sp->value = 1;
×
294
                                else if ( tolower(*s2) == 'o' && tolower(s2[1]) == 'f'
×
295
                                && tolower(s2[2]) == 'f'
×
296
                                && ( s2[3] == 0 || s2[3] == ' ' || s2[3] == '\t' ) )
×
297
                                        sp->value = 0;
×
298
                                else {
299
                                        MesPrint("%s: Unrecognized option for parameter %s: %s"
×
300
                                        ,proop1[filetype],s1,s2);
301
                                        error = 1; break;
×
302
                                }
303
                                sp->flags = USEDFLAG;
×
304
                                break;
×
305
                        case DEFINEVALUE:
×
306
/*
307
                                if ( sp->value ) M_free((UBYTE *)(sp->value),"Process option");
308
                                sp->value = (LONG)strDup1(s2,"Process option");
309
*/
310
                                if ( TheDefine(s2,2) ) error = 1;
×
311
                                break;
312
                        default:
×
313
                                Error1("Error in setupparameter table for:",s1);
×
314
                                error = 1;
×
315
                                break;
×
316
                }
317
        }
318
        else {
319
                MesPrint("%s: Keyword not recognized: %s",proop1[filetype],s1);
×
320
                error = 1;
×
321
        }
322
        if ( giveback ) M_free(s2ret,"environment in setup");
198✔
323
        return(error);
324
}
325

326
/*
327
                 #] ProcessOption : 
328
                 #[ GetSetupPar :
329
*/
330

331
SETUPPARAMETERS *GetSetupPar(UBYTE *s)
115,754✔
332
{
333
        int hi, med, lo, i;
115,754✔
334
        lo = 0;
115,754✔
335
        hi = sizeof(setupparameters)/sizeof(SETUPPARAMETERS);
115,754✔
336
        do {
594,856✔
337
                med = ( hi + lo ) / 2;
594,856✔
338
                i = StrICmp(s,(UBYTE *)setupparameters[med].parameter);
594,856✔
339
                if ( i == 0 ) return(setupparameters+med);
594,856✔
340
                if ( i < 0 ) hi = med-1;
479,102✔
341
                else         lo = med+1;
233,759✔
342
        } while ( hi >= lo );
479,102✔
343
        return(0);
344
}
345

346
/*
347
                 #] GetSetupPar : 
348
                 #[ RecalcSetups :
349
*/
350

351
int RecalcSetups()
1,828✔
352
{
353
        SETUPPARAMETERS *sp, *sp1;
1,828✔
354

355
        sp1 = GetSetupPar((UBYTE *)"threads");
1,828✔
356
        if ( AM.totalnumberofthreads > 1 ) sp1->value = AM.totalnumberofthreads - 1;
1,828✔
357
        else sp1->value = 0;
1,282✔
358
/*
359
        if ( sp1->value > 0 ) AM.totalnumberofthreads = sp1->value+1;
360
        if ( AM.totalnumberofthreads == 0 ) AM.totalnumberofthreads = 1;
361
*/
362
        sp  = GetSetupPar((UBYTE *)"filepatches");
1,828✔
363
        if ( sp->value < AM.totalnumberofthreads-1 )
1,828✔
364
                sp->value = AM.totalnumberofthreads - 1;
×
365

366
        sp  = GetSetupPar((UBYTE *)"smallsize");
1,828✔
367
        sp1 = GetSetupPar((UBYTE *)"smallextension");
1,828✔
368
        if ( 6*sp1->value < 7*sp->value ) sp1->value = (7*sp->value)/6;
1,828✔
369
        sp = GetSetupPar((UBYTE *)"termsinsmall");
1,828✔
370
        sp->value = ( sp->value + 15 ) & (-16L);
1,828✔
371
#ifdef WITHPTHREADS
372
        {
373
        SETUPPARAMETERS *sp2;
548✔
374
        LONG totalsize, minimumsize;
548✔
375
        sp = GetSetupPar((UBYTE *)"largesize");
548✔
376
        totalsize = sp1->value+sp->value;
548✔
377
        sp2 = GetSetupPar((UBYTE *)"maxtermsize");
548✔
378
        AM.MaxTer = sp2->value*sizeof(WORD);
548✔
379
        if ( AM.MaxTer < 200*(LONG)(sizeof(WORD)) ) AM.MaxTer = 200*(LONG)(sizeof(WORD));
548✔
380
        if ( AM.MaxTer > MAXPOSITIVE - 200*(LONG)(sizeof(WORD)) ) AM.MaxTer = MAXPOSITIVE - 200*(LONG)(sizeof(WORD));
548✔
381
        AM.MaxTer /= sizeof(WORD);
548✔
382
        AM.MaxTer *= sizeof(WORD);
548✔
383
        minimumsize = (AM.totalnumberofthreads-1)*(AM.MaxTer+
548✔
384
                NUMBEROFBLOCKSINSORT*MINIMUMNUMBEROFTERMS*AM.MaxTer);
385
        if ( totalsize < minimumsize ) {
548✔
386
                sp->value = minimumsize - sp1->value;
387
        }
388
        }
389
#endif
390
        return(0);
1,828✔
391
}
392

393
/*
394
                 #] RecalcSetups : 
395
                 #[ AllocSetups :
396
*/
397

398
int AllocSetups()
1,828✔
399
{
400
        SETUPPARAMETERS *sp;
1,828✔
401
        LONG LargeSize, SmallSize, SmallEsize, TermsInSmall, IOsize;
1,828✔
402
        int MaxPatches, MaxFpatches, error = 0, i, size;
1,828✔
403
        UBYTE *s;
1,828✔
404
#ifndef WITHPTHREADS
405
        int j;
1,280✔
406
#endif
407
        sp = GetSetupPar((UBYTE *)"threads");
1,828✔
408
        if ( sp->value > 0 ) AM.totalnumberofthreads = sp->value+1;
1,828✔
409

410
        AM.OutBuffer = (UBYTE *)Malloc1(AM.OutBufSize+1,"OutputBuffer");
1,828✔
411
        AP.PreAssignStack =(LONG *)Malloc1(AP.MaxPreAssignLevel*sizeof(LONG *),"PreAssignStack");
1,828✔
412
        for ( i = 0; i < AP.MaxPreAssignLevel; i++ ) AP.PreAssignStack[i] = 0;
9,140✔
413
        AC.iBuffer = (UBYTE *)Malloc1(AC.iBufferSize+1,"statement buffer");
1,828✔
414
        AC.iStop = AC.iBuffer + AC.iBufferSize-2;
1,828✔
415
        AP.preStart = (UBYTE *)Malloc1(AP.pSize,"instruction buffer");
1,828✔
416
        AP.preStop = AP.preStart + AP.pSize - 3;
1,828✔
417
        /* AP.PreIfStack is already allocated in StartPrepro(), but to be sure we
418
           "if" the freeing */
419
        if ( AP.PreIfStack ) M_free(AP.PreIfStack,"PreIfStack");
1,828✔
420
        AP.PreIfStack = (int *)Malloc1(AP.MaxPreIfLevel*sizeof(int),
1,828✔
421
                                "Preprocessor if stack");
422
        AP.PreIfStack[0] = EXECUTINGIF;
1,828✔
423
        sp = GetSetupPar((UBYTE *)"insidefirst");
1,828✔
424
        AM.ginsidefirst = AC.minsidefirst = AC.insidefirst = sp->value;
1,828✔
425
/*
426
        We need to consider eliminating this variable
427
*/
428
        sp = GetSetupPar((UBYTE *)"maxtermsize");
1,828✔
429
        AM.MaxTer = sp->value*sizeof(WORD);
1,828✔
430
        if ( AM.MaxTer < 200*(LONG)(sizeof(WORD)) ) AM.MaxTer = 200*(LONG)(sizeof(WORD));
1,828✔
431
        if ( AM.MaxTer > MAXPOSITIVE - 200*(LONG)(sizeof(WORD)) ) AM.MaxTer = MAXPOSITIVE - 200*(LONG)(sizeof(WORD));
1,828✔
432
        AM.MaxTer /= (LONG)sizeof(WORD);
1,828✔
433
        AM.MaxTer *= (LONG)sizeof(WORD);
1,828✔
434
/*
435
        Allocate workspace.
436
*/
437
        sp = GetSetupPar((UBYTE *)"workspace");
1,828✔
438
        AM.WorkSize = sp->value;
1,828✔
439
#ifdef WITHPTHREADS
440
#else
441
        AT.WorkSpace = (WORD *)Malloc1(AM.WorkSize*sizeof(WORD),(char *)(sp->parameter));
1,280✔
442
        AT.WorkTop = AT.WorkSpace + AM.WorkSize;
1,280✔
443
        AT.WorkPointer = AT.WorkSpace;
1,280✔
444
#endif
445
/*
446
        Fixed indices
447
*/
448
        sp = GetSetupPar((UBYTE *)"constindex");
1,828✔
449
        if ( ( sp->value+100+5*WILDOFFSET ) > MAXPOSITIVE ) {
1,828✔
450
                MesPrint("Setting of %s in setupfile too large","constindex");
×
451
                AM.OffsetIndex = MAXPOSITIVE - 5*WILDOFFSET - 100;
×
452
                MesPrint("value corrected to maximum allowed: %d",AM.OffsetIndex);
×
453
        }
454
        else AM.OffsetIndex = sp->value + 1;
1,828✔
455
        AC.FixIndices = (WORD *)Malloc1((AM.OffsetIndex)*sizeof(WORD),(char *)(sp->parameter));
1,828✔
456
        AM.WilInd = AM.OffsetIndex + WILDOFFSET;
1,828✔
457
        AM.DumInd = AM.OffsetIndex + 2*WILDOFFSET;
1,828✔
458
        AM.IndDum = AM.DumInd + WILDOFFSET;
1,828✔
459
#ifndef WITHPTHREADS
460
        AR.CurDum = AN.IndDum = AM.IndDum;
1,280✔
461
#endif
462
        AM.mTraceDum = AM.IndDum + 2*WILDOFFSET;
1,828✔
463

464
        sp = GetSetupPar((UBYTE *)"parentheses");
1,828✔
465
        AM.MaxParLevel = sp->value+1;
1,828✔
466
        AC.tokenarglevel = (WORD *)Malloc1((sp->value+1)*sizeof(WORD),(char *)(sp->parameter));
1,828✔
467
/*
468
        Space during calculations
469
*/
470
        sp = GetSetupPar((UBYTE *)"maxnumbersize");
1,828✔
471
/*
472
        size = ( sp->value + 11 ) & (-4);
473
        AM.MaxTal = size - 2;
474
        if ( AM.MaxTal > (AM.MaxTer/sizeof(WORD)-2)/2 )
475
                                AM.MaxTal = (AM.MaxTer/sizeof(WORD)-2)/2;
476
        if ( AM.MaxTal < (AM.MaxTer/sizeof(WORD)-2)/4 )
477
                                AM.MaxTal = (AM.MaxTer/sizeof(WORD)-2)/4;
478
*/
479
/*
480
        There is too much confusion about MaxTal cq maxnumbersize.
481
        It seems better to fix it at its maximum value. This way we only worry
482
        about maxtermsize. This can be understood better by the 'innocent' user.
483
*/
484
        if ( sp->value == 0 ) {
1,828✔
485
                AM.MaxTal = (AM.MaxTer/sizeof(WORD)-2)/2;
1,828✔
486
        }
487
        else {
488
                size = ( sp->value + 11 ) & (-4);
×
489
                AM.MaxTal = size - 2;
×
490
                if ( (size_t)AM.MaxTal > (size_t)((AM.MaxTer/sizeof(WORD)-2)/2) )
×
491
                                        AM.MaxTal = (AM.MaxTer/sizeof(WORD)-2)/2;
×
492
        }
493
        AM.MaxTal &= -sizeof(WORD)*2;
1,828✔
494

495
        sp->value = AM.MaxTal;
1,828✔
496
        AC.cmod = (UWORD *)Malloc1(AM.MaxTal*4*sizeof(UWORD),(char *)(sp->parameter));
1,828✔
497
        AM.gcmod = AC.cmod + AM.MaxTal;
1,828✔
498
        AC.powmod = AM.gcmod + AM.MaxTal;
1,828✔
499
        AM.gpowmod = AC.powmod + AM.MaxTal;
1,828✔
500
/*
501
        The IO buffers for the input and output expressions.
502
        Fscr[2] will be assigned in a later stage for hiding expressions from
503
        the regular action. That will make the program faster.
504
*/
505
        sp = GetSetupPar((UBYTE *)"scratchsize");
1,828✔
506
        AM.ScratSize = sp->value/sizeof(WORD);
1,828✔
507
        if ( AM.ScratSize < 4*AM.MaxTer ) AM.ScratSize = 4*AM.MaxTer;
1,828✔
508
        AM.HideSize = AM.ScratSize;
1,828✔
509
        sp = GetSetupPar((UBYTE *)"hidesize");
1,828✔
510
        if ( sp->value > 0 ) {
1,828✔
511
                AM.HideSize = sp->value/sizeof(WORD);
×
512
                if ( AM.HideSize < 4*AM.MaxTer ) AM.HideSize = 4*AM.MaxTer;
×
513
        }
514
        sp = GetSetupPar((UBYTE *)"factorizationcache");
1,828✔
515
        AM.fbuffersize = sp->value;
1,828✔
516
#ifdef WITHPTHREADS
517
        sp = GetSetupPar((UBYTE *)"threadscratchsize");
548✔
518
        AM.ThreadScratSize = sp->value/sizeof(WORD);
548✔
519
        sp = GetSetupPar((UBYTE *)"threadscratchoutsize");
548✔
520
        AM.ThreadScratOutSize = sp->value/sizeof(WORD);
548✔
521
#endif
522
#ifndef WITHPTHREADS
523
        for ( j = 0; j < 2; j++ ) {
3,840✔
524
                WORD *ScratchBuf;
2,560✔
525
                ScratchBuf = (WORD *)Malloc1(AM.ScratSize*sizeof(WORD),"scratchsize");
2,560✔
526
                AR.Fscr[j].POsize = AM.ScratSize * sizeof(WORD);
2,560✔
527
                AR.Fscr[j].POfull = AR.Fscr[j].POfill = AR.Fscr[j].PObuffer = ScratchBuf;
2,560✔
528
                AR.Fscr[j].POstop = AR.Fscr[j].PObuffer + AM.ScratSize;
2,560✔
529
                PUTZERO(AR.Fscr[j].POposition);
2,560✔
530
        }
531
        AR.Fscr[2].PObuffer = 0;
1,280✔
532
#endif
533
        sp = GetSetupPar((UBYTE *)"threadbucketsize");
1,828✔
534
        AC.ThreadBucketSize = AM.gThreadBucketSize = AM.ggThreadBucketSize = sp->value;
1,828✔
535
        sp = GetSetupPar((UBYTE *)"threadloadbalancing");
1,828✔
536
        AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing = sp->value;
1,828✔
537
        sp = GetSetupPar((UBYTE *)"threadsortfilesynch");
1,828✔
538
        AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch = sp->value;
1,828✔
539
/*
540
     The size for shared memory window for oneside MPI2 communications
541
*/
542
        sp = GetSetupPar((UBYTE *)"shmwinsize");
1,828✔
543
        AM.shmWinSize = sp->value/sizeof(WORD);
1,828✔
544
        if ( AM.shmWinSize < 4*AM.MaxTer ) AM.shmWinSize = 4*AM.MaxTer;
1,828✔
545
/*
546
        The sort buffer
547
*/
548
        sp = GetSetupPar((UBYTE *)"smallsize");
1,828✔
549
        SmallSize = sp->value;
1,828✔
550
        sp = GetSetupPar((UBYTE *)"smallextension");
1,828✔
551
        SmallEsize = sp->value;
1,828✔
552
        sp = GetSetupPar((UBYTE *)"largesize");
1,828✔
553
        LargeSize = sp->value;
1,828✔
554
        sp = GetSetupPar((UBYTE *)"termsinsmall");
1,828✔
555
        TermsInSmall = sp->value;
1,828✔
556
        sp = GetSetupPar((UBYTE *)"largepatches");
1,828✔
557
        MaxPatches = sp->value;
1,828✔
558
        sp = GetSetupPar((UBYTE *)"filepatches");
1,828✔
559
        MaxFpatches = sp->value;
1,828✔
560
        sp = GetSetupPar((UBYTE *)"sortiosize");
1,828✔
561
        IOsize = sp->value;
1,828✔
562
        if ( IOsize < AM.MaxTer ) { IOsize = AM.MaxTer; sp->value = IOsize; }
1,828✔
563
#ifndef WITHPTHREADS
564
#ifdef WITHZLIB
565
        for ( j = 0; j < 2; j++ ) { AR.Fscr[j].ziosize = IOsize; }
3,840✔
566
#endif
567
#endif
568
        AM.S0 = 0;
1,828✔
569
        AM.S0 = AllocSort(LargeSize,SmallSize,SmallEsize,TermsInSmall
1,828✔
570
                                        ,MaxPatches,MaxFpatches,IOsize);
571
        /* AM.S0->file.ziosize was already set to a (larger) value by AllocSort, here it is re-set. */
572
#ifdef WITHZLIB
573
        AM.S0->file.ziosize = IOsize;
1,828✔
574
#ifndef WITHPTHREADS
575
        AR.FoStage4[0].ziosize = IOsize;
1,280✔
576
        AR.FoStage4[1].ziosize = IOsize;
1,280✔
577
        AT.S0 = AM.S0;
1,280✔
578
#endif
579
#else
580
#ifndef WITHPTHREADS
581
        AT.S0 = AM.S0;
582
#endif
583
#endif
584
#ifndef WITHPTHREADS
585
        AR.FoStage4[0].POsize   = ((IOsize+sizeof(WORD)-1)/sizeof(WORD))*sizeof(WORD);
1,280✔
586
        AR.FoStage4[1].POsize   = ((IOsize+sizeof(WORD)-1)/sizeof(WORD))*sizeof(WORD);
1,280✔
587
#endif
588
        sp = GetSetupPar((UBYTE *)"subsmallsize");
1,828✔
589
        AM.SSmallSize = sp->value;
1,828✔
590
        sp = GetSetupPar((UBYTE *)"subsmallextension");
1,828✔
591
        AM.SSmallEsize = sp->value;
1,828✔
592
        sp = GetSetupPar((UBYTE *)"sublargesize");
1,828✔
593
        AM.SLargeSize = sp->value;
1,828✔
594
        sp = GetSetupPar((UBYTE *)"subtermsinsmall");
1,828✔
595
        AM.STermsInSmall = sp->value;
1,828✔
596
        sp = GetSetupPar((UBYTE *)"sublargepatches");
1,828✔
597
        AM.SMaxPatches = sp->value;
1,828✔
598
        sp = GetSetupPar((UBYTE *)"subfilepatches");
1,828✔
599
        AM.SMaxFpatches = sp->value;
1,828✔
600
        sp = GetSetupPar((UBYTE *)"subsortiosize");
1,828✔
601
        AM.SIOsize = sp->value;
1,828✔
602
        /* As for IOsize, make sure SIOsize is at least as large as AM.MaxTer. */
603
        if ( AM.SIOsize < AM.MaxTer ) { AM.SIOsize = AM.MaxTer; sp->value = AM.SIOsize; }
1,828✔
604
        sp = GetSetupPar((UBYTE *)"spectatorsize");
1,828✔
605
        AM.SpectatorSize = sp->value;
1,828✔
606
/*
607
        The next code is just for the moment (26-jan-1997) because we have
608
        the new parts combined with the old. Once the old parts are gone
609
        from the program, we can eliminate this code too.
610
*/
611
        sp = GetSetupPar((UBYTE *)"functionlevels");
1,828✔
612
        AM.maxFlevels = sp->value + 1;
1,828✔
613
#ifdef WITHPTHREADS
614
#else
615
        AT.Nest = (NESTING)Malloc1((LONG)sizeof(struct NeStInG)*AM.maxFlevels,"functionlevels");
1,280✔
616
        AT.NestStop = AT.Nest + AM.maxFlevels;
1,280✔
617
        AT.NestPoin = AT.Nest;
1,280✔
618
#endif
619

620
        sp = GetSetupPar((UBYTE *)"maxwildcards");
1,828✔
621
        AM.MaxWildcards = sp->value;
1,828✔
622
#ifdef WITHPTHREADS
623
#else
624
        AT.WildMask = (WORD *)Malloc1((LONG)AM.MaxWildcards*sizeof(WORD),"maxwildcards");
1,280✔
625
#endif
626

627
        sp = GetSetupPar((UBYTE *)"compresssize");
1,828✔
628
        if ( sp->value < 2*AM.MaxTer ) sp->value = 2*AM.MaxTer;
1,828✔
629
        AM.CompressSize = sp->value;
1,828✔
630
#ifndef WITHPTHREADS
631
        AR.CompressBuffer = (WORD *)Malloc1((AM.CompressSize+10)*sizeof(WORD),"compresssize");
1,280✔
632
        AR.CompressPointer = AR.CompressBuffer;
1,280✔
633
        AR.ComprTop = AR.CompressBuffer + AM.CompressSize;
1,280✔
634
#endif
635
        sp = GetSetupPar((UBYTE *)"bracketindexsize");
1,828✔
636
        if ( sp->value < 20*AM.MaxTer ) sp->value = 20*AM.MaxTer;
1,828✔
637
        AM.MaxBracketBufferSize = sp->value/sizeof(WORD);
1,828✔
638

639
        sp = GetSetupPar((UBYTE *)"dotchar");
1,828✔
640
        AO.FortDotChar = ((UBYTE *)(sp->value))[0];
1,828✔
641
        sp = GetSetupPar((UBYTE *)"commentchar");
1,828✔
642
        AP.cComChar = AP.ComChar = ((UBYTE *)(sp->value))[0];
1,828✔
643
        sp = GetSetupPar((UBYTE *)"procedureextension");
1,828✔
644
/*
645
        Check validity first.
646
*/
647
        s = (UBYTE *)(sp->value);
1,828✔
648
        if ( FG.cTable[*s] != 0 ) {
1,828✔
649
                MesPrint("  Illegal string for procedure extension %s",(UBYTE *)sp->value);
×
UNCOV
650
                error = -2;
×
651
        }
652
        else {
653
                s++;
1,828✔
654
                while ( *s ) {
5,484✔
655
                        if ( *s == ' ' || *s == '\t' || *s == '\n' ) {
3,656✔
656
                                MesPrint("  Illegal string for procedure extension %s",(UBYTE *)sp->value);
×
657
                                error = -2;
×
UNCOV
658
                                break;
×
659
                        }
660
                        s++;
3,656✔
661
                }
662
        }
663
        AP.cprocedureExtension = strDup1((UBYTE *)(sp->value),"procedureExtension");
1,828✔
664
        AP.procedureExtension = strDup1(AP.cprocedureExtension,"procedureExtension");
1,828✔
665

666
        sp = GetSetupPar((UBYTE *)"totalsize");
1,828✔
667
        if ( sp->value != 2 ) AM.PrintTotalSize = sp->value;
1,828✔
668

669
        sp = GetSetupPar((UBYTE *)"continuationlines");
1,828✔
670
        AM.FortranCont = sp->value;
1,828✔
671
        sp = GetSetupPar((UBYTE *)"oldorder");
1,828✔
672
        AM.OldOrderFlag = sp->value;
1,828✔
673
        sp = GetSetupPar((UBYTE *)"resettimeonclear");
1,828✔
674
        AM.resetTimeOnClear = sp->value;
1,828✔
675
        sp = GetSetupPar((UBYTE *)"nospacesinnumbers");
1,828✔
676
        AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers = sp->value;
1,828✔
677
        sp = GetSetupPar((UBYTE *)"indentspace");
1,828✔
678
        AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace = sp->value;
1,828✔
679
        sp = GetSetupPar((UBYTE *)"jumpratio");
1,828✔
680
        AM.jumpratio = sp->value;
1,828✔
681
        sp = GetSetupPar((UBYTE *)"nwritestatistics");
1,828✔
682
        AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag = 1-sp->value;
1,828✔
683
        sp = GetSetupPar((UBYTE *)"nwritefinalstatistics");
1,828✔
684
        AC.FinalStats = AM.gFinalStats = AM.ggFinalStats = 1-sp->value;
1,828✔
685
        sp = GetSetupPar((UBYTE *)"nwritethreadstatistics");
1,828✔
686
        AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats = 1-sp->value;
1,828✔
687
        sp = GetSetupPar((UBYTE *)"nwriteprocessstatistics");
1,828✔
688
        AC.ProcessStats = AM.gProcessStats = AM.ggProcessStats = 1-sp->value;
1,828✔
689
        sp = GetSetupPar((UBYTE *)"oldparallelstatistics");
1,828✔
690
        AC.OldParallelStats = AM.gOldParallelStats = AM.ggOldParallelStats = sp->value;
1,828✔
691
        sp = GetSetupPar((UBYTE *)"oldfactarg");
1,828✔
692
        AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag = sp->value;
1,828✔
693
        sp = GetSetupPar((UBYTE *)"oldgcd");
1,828✔
694
        AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag = sp->value;
1,828✔
695
        sp = GetSetupPar((UBYTE *)"wtimestats");
1,828✔
696
        if ( sp->value == 2 ) sp->value = AM.ggWTimeStatsFlag;
1,828✔
697
        AC.WTimeStatsFlag = AM.gWTimeStatsFlag = AM.ggWTimeStatsFlag = sp->value;
1,828✔
698
        sp = GetSetupPar((UBYTE *)"sorttype");
1,828✔
699
        if ( StrICmp((UBYTE *)"lowfirst",(UBYTE *)sp->value) == 0 ) {
1,828✔
700
                AC.lSortType = SORTLOWFIRST;
1,828✔
701
        }
702
        else if ( StrICmp((UBYTE *)"highfirst",(UBYTE *)sp->value) == 0 ) {
×
UNCOV
703
                AC.lSortType = SORTHIGHFIRST;
×
704
        }
705
        else {
706
                MesPrint("  Illegal SortType specification: %s",(UBYTE *)sp->value);
×
UNCOV
707
                error = -2;
×
708
        }
709

710
        sp = GetSetupPar((UBYTE *)"processbucketsize");
1,828✔
711
        AM.hProcessBucketSize = AM.gProcessBucketSize =
1,828✔
712
        AC.ProcessBucketSize = AC.mProcessBucketSize = sp->value;
1,828✔
713
/*
714
        The store caches (code installed 15-aug-2006 JV)
715
*/
716
        sp = GetSetupPar((UBYTE *)"numstorecaches");
1,828✔
717
        AM.NumStoreCaches = sp->value;
1,828✔
718
        sp = GetSetupPar((UBYTE *)"sizestorecache");
1,828✔
719
        AM.SizeStoreCache = sp->value;
1,828✔
720
#ifndef WITHPTHREADS
721
/*
722
        Install the store caches (15-aug-2006 JV)
723
        Note that in the case of PTHREADS this is done in InitializeOneThread
724
*/
725
        AT.StoreCache = AT.StoreCacheAlloc = 0;
1,280✔
726
        if ( AM.NumStoreCaches > 0 ) {
1,280✔
727
                STORECACHE sa, sb;
1,280✔
728
                size = sizeof(struct StOrEcAcHe)+AM.SizeStoreCache;
1,280✔
729
                size = ((size-1)/sizeof(size_t)+1)*sizeof(size_t);
1,280✔
730
                AT.StoreCacheAlloc = (STORECACHE)Malloc1(size*AM.NumStoreCaches,"StoreCaches");
1,280✔
731
                AT.StoreCache = AT.StoreCacheAlloc;
1,280✔
732
                sa = AT.StoreCache;
1,280✔
733
                for ( j = 0; j < AM.NumStoreCaches; j++ ) {
6,400✔
734
                        sb = (STORECACHE)(VOID *)((UBYTE *)sa+size);
5,120✔
735
                        if ( j == AM.NumStoreCaches-1 ) {
5,120✔
736
                                sa->next = 0;
1,280✔
737
                        }
738
                        else {
739
                                sa->next = sb;
3,840✔
740
                        }
741
                        SETBASEPOSITION(sa->position,-1);
5,120✔
742
                        SETBASEPOSITION(sa->toppos,-1);
5,120✔
743
                        sa = sb;
5,120✔
744
                }                
745
        }
746
#endif
747

748
/*
749
        And now some order sensitive things
750
*/
751
        if ( AM.Path == 0 ) {
1,828✔
752
                sp = GetSetupPar((UBYTE *)"path");
28✔
753
                AM.Path = strDup1((UBYTE *)(sp->value),"path");
28✔
754
        }
755
        if ( AM.IncDir == 0 ) {
1,828✔
756
                sp = GetSetupPar((UBYTE *)"incdir");
1,828✔
757
                AM.IncDir = strDup1((UBYTE *)(sp->value),"incdir");
1,828✔
758
        }
759
/*
760
        if ( AM.TempDir == 0 ) {
761
                sp = GetSetupPar((UBYTE *)"tempdir");
762
                AM.TempDir = strDup1((UBYTE *)(sp->value),"tempdir");
763
        }
764
*/
765
        return(error);
1,828✔
766
}
767

768
/*
769
                 #] AllocSetups : 
770
                 #[ WriteSetup :
771

772
        The routine writes the values of the setup parameters.
773
        We should do this better. (JV, 21-may-2008)
774
        The way it should be done is:
775
                a: write the raw values.
776
                b: give readjusted values.
777
                c: give derived values.
778
        Because this is a difficult subject, it would be nice to have a LaTeX
779
        document that explains this all exactly. There should then be a 
780
        mechanism to poke the values of the setup into the LaTeX document.
781
        probably the easiest way is to make a file with lots of \def definitions
782
        and have that included into the LaTeX file.
783
*/
784

UNCOV
785
VOID WriteSetup()
×
786
{
787
        int n = sizeof(setupparameters)/sizeof(SETUPPARAMETERS);
×
788
        SETUPPARAMETERS *sp;
×
789
        MesPrint(" The setup parameters are:");
×
790
        for ( sp = setupparameters; n > 0; n--, sp++ ) {
×
791
                switch(sp->type){
×
792
                        case NUMERICALVALUE:
×
793
                                MesPrint("   %s: %l",sp->parameter,sp->value);
×
794
                                break;
×
795
                        case PATHVALUE:
×
796
                                if ( StrICmp(sp->parameter,(UBYTE *)"path") == 0 && AM.Path ) {
×
797
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(AM.Path));
×
UNCOV
798
                                        break;
×
799
                                }
800
                                if ( StrICmp(sp->parameter,(UBYTE *)"incdir") == 0 && AM.IncDir ) {
×
801
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(AM.IncDir));
×
UNCOV
802
                                        break;
×
803
                                }
804
                                /* fall through */
805
                        case STRINGVALUE:
806
                                if ( StrICmp(sp->parameter,(UBYTE *)"tempdir") == 0 && AM.TempDir ) {
×
UNCOV
807
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(AM.TempDir));
×
808
                                }
809
                                else if ( StrICmp(sp->parameter,(UBYTE *)"tempsortdir") == 0 && AM.TempSortDir ) {
×
UNCOV
810
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(AM.TempSortDir));
×
811
                                }
812
                                else {
UNCOV
813
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(sp->value));
×
814
                                }
815
                                break;
816
                        case ONOFFVALUE:
×
817
                                if ( sp->value == 0 )
×
818
                                        MesPrint("   %s: OFF",sp->parameter);
×
819
                                else if ( sp->value == 1 )
×
UNCOV
820
                                        MesPrint("   %s: ON",sp->parameter);
×
821
                                break;
822
                        case DEFINEVALUE:
823
/*
824
                                MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(sp->value));
825
*/
826
                                break;
827
                }
828
        }
×
829
        AC.SetupFlag = 0;
×
UNCOV
830
}
×
831

832
/*
833
                 #] WriteSetup : 
834
                 #[ AllocSort :
835

836
                Routine allocates a complete struct for sorting.
837
                To be used for the main allocation of the sort buffers, and
838
                in a later stage for the function and subroutine sort buffers.
839
*/
840
SORTING *AllocSort(LONG inLargeSize, LONG inSmallSize, LONG inSmallEsize, LONG inTermsInSmall,
4,889✔
841
                   int inMaxPatches, int inMaxFpatches, LONG inIOsize)
842
{
843
        LONG LargeSize = inLargeSize;
4,889✔
844
        LONG SmallSize = inSmallSize;
4,889✔
845
        LONG SmallEsize = inSmallEsize;
4,889✔
846
        LONG TermsInSmall = inTermsInSmall;
4,889✔
847
        int MaxPatches = inMaxPatches;
4,889✔
848
        int MaxFpatches = inMaxFpatches;
4,889✔
849
        LONG IOsize = inIOsize;
4,889✔
850

851
        LONG longer,terms2insmall,sortsize,longerp;
4,889✔
852
        LONG IObuffersize = IOsize;
4,889✔
853
        LONG IOtry;
4,889✔
854
        SORTING *sort;
4,889✔
855
        int fname2Size = 0, j = 0;
4,889✔
856
        char *s;
4,889✔
857
        if ( AM.S0 != 0 ) {
4,889✔
858
                s = FG.fname2; fname2Size = 0;
3,061✔
859
                while ( *s ) { s++; fname2Size++; }
45,915✔
860
                fname2Size += 16;
3,061✔
861
        }
862
        if ( MaxFpatches < 4 ) MaxFpatches = 4;
4,889✔
863
        longer = MaxPatches > MaxFpatches ? MaxPatches : MaxFpatches;
4,889✔
864
        longerp = longer;
4,889✔
865
        while ( (1 << j) < longerp ) j++;
41,083✔
866
        longerp = (1 << j) + 1; 
4,889✔
867
        longerp += sizeof(WORD*) - (longerp%sizeof(WORD *));
4,889✔
868
        longer++;
4,889✔
869
        longer += sizeof(WORD*) - (longer%sizeof(WORD *));
4,889✔
870
        if ( SmallSize < 16*AM.MaxTer ) SmallSize = 16*AM.MaxTer+16;
4,889✔
871
        TermsInSmall = (TermsInSmall+15) & (-16L);
4,889✔
872
        terms2insmall = 2*TermsInSmall;  /* Used to be just + 100 rather than *2 */
4,889✔
873
        if ( SmallEsize < (SmallSize*3)/2 ) SmallEsize = (SmallSize*3)/2;
4,889✔
874
        if ( LargeSize > 0 && LargeSize < 2*SmallSize ) LargeSize = 2*SmallSize;
4,889✔
875
        SmallEsize = (SmallEsize+15) & (-16L);
4,889✔
876
        if ( LargeSize < 0 ) LargeSize = 0;
4,889✔
877
        sortsize = sizeof(SORTING);
4,889✔
878
        sortsize = (sortsize+15)&(-16L);
4,889✔
879
        IObuffersize = (IObuffersize+sizeof(WORD)-1)/sizeof(WORD);
4,889✔
880
/*
881
        The next statement fixes a bug. In the rare case that we have a
882
        problem here, we expand the size of the large buffer or the 
883
        small extension
884
*/
885
        if ( (ULONG)( LargeSize+SmallEsize ) < MaxFpatches*((IObuffersize
4,889✔
886
                +COMPINC)*sizeof(WORD)+2*AM.MaxTer) ) {
4,889✔
887
                if ( LargeSize == 0 ) 
17✔
UNCOV
888
                        SmallEsize = MaxFpatches*((IObuffersize+COMPINC)*sizeof(WORD)+2*AM.MaxTer);
×
889
                else
890
                        LargeSize  = MaxFpatches*((IObuffersize+COMPINC)*sizeof(WORD)+2*AM.MaxTer)
17✔
891
                                - SmallEsize;
17✔
892
        }
893

894
        IOtry = ((LargeSize+SmallEsize)/MaxFpatches-2*AM.MaxTer)/sizeof(WORD)-COMPINC;
4,889✔
895

896
        /* Here both IObuffersize and IOtry are in units of sizeof(WORD). */
897
        if ( IObuffersize < IOtry ) {
4,889✔
898
                IObuffersize = IOtry;
1,876✔
899
        }
900

901
#if DEBUGGING
902
        if ( LargeSize != inLargeSize ) { MesPrint("Warning: LargeSize adjusted: %l -> %l", inLargeSize, LargeSize); }
4,889✔
903
        if ( SmallSize != inSmallSize ) { MesPrint("Warning: SmallSize adjusted: %l -> %l", inSmallSize, SmallSize); }
4,889✔
904
        if ( SmallEsize != inSmallEsize ) {MesPrint("Warning: SmallEsize adjusted: %l -> %l", inSmallEsize, SmallEsize); }
4,889✔
905
        if ( TermsInSmall != inTermsInSmall ) { MesPrint("Warning: TermsInSmall adjusted: %l -> %l", inTermsInSmall, TermsInSmall); }
4,889✔
906
        if ( MaxPatches != inMaxPatches ) { MesPrint("Warning: MaxPatches adjusted: %d -> %d", inMaxPatches, MaxPatches); }
4,889✔
907
        if ( MaxFpatches != inMaxFpatches ) {MesPrint("Warning: MaxFPatches adjusted: %d -> %d", inMaxFpatches, MaxFpatches); }
4,889✔
908
        /* This one is always changed if the LargeSize has not been... */
909
        /* if ( IObuffersize != inIOsize/(LONG)sizeof(WORD) ) { MesPrint("Warning: IOsize adjusted: %l -> %l", inIOsize/sizeof(WORD), IObuffersize); } */
910
#endif
911

912
        /* Allocate separate buffers for most struct members, for better testing and debugging with valgrind. */
913
        sort = Malloc1(sizeof(*sort), "AllocSort: sorting struct");
4,889✔
914

915
        sort->LargeSize = LargeSize/sizeof(WORD);
4,889✔
916
        sort->SmallSize = SmallSize/sizeof(WORD);
4,889✔
917
        sort->SmallEsize = SmallEsize/sizeof(WORD);
4,889✔
918
        sort->MaxPatches = MaxPatches;
4,889✔
919
        sort->MaxFpatches = MaxFpatches;
4,889✔
920
        sort->TermsInSmall = TermsInSmall;
4,889✔
921
        sort->Terms2InSmall = terms2insmall;
4,889✔
922

923
        sort->sPointer     = Malloc1(sizeof(*(sort->sPointer    ))*terms2insmall, "AllocSort: sPointer");
4,889✔
924
        sort->Patches      = Malloc1(sizeof(*(sort->Patches     ))*longer, "AllocSort: Patches");
4,889✔
925
        sort->pStop        = Malloc1(sizeof(*(sort->pStop       ))*longer, "AllocSort: pStop");
4,889✔
926
        sort->poina        = Malloc1(sizeof(*(sort->poina       ))*longerp, "AllocSort: poina");
4,889✔
927
        sort->poin2a       = Malloc1(sizeof(*(sort->poin2a      ))*longerp, "AllocSort: poin2a");
4,889✔
928

929
        sort->fPatches     = Malloc1(sizeof(*(sort->fPatches    ))*longer, "AllocSort: fPatches");
4,889✔
930
        sort->fPatchesStop = Malloc1(sizeof(*(sort->fPatchesStop))*longer, "AllocSort: fPatchesStop");
4,889✔
931
        sort->inPatches    = Malloc1(sizeof(*(sort->inPatches   ))*longer, "AllocSort: inPatches");
4,889✔
932
        sort->tree         = Malloc1(sizeof(*(sort->tree        ))*longerp, "AllocSort: tree");
4,889✔
933
        sort->used         = Malloc1(sizeof(*(sort->used        ))*longerp, "AllocSort: used");
4,889✔
934

935
#ifdef WITHZLIB
936
        sort->fpcompressed   = Malloc1(sizeof(*(sort->fpcompressed  ))*(longerp+2), "AllocSort: fpcompressed");
4,889✔
937
        sort->fpincompressed = Malloc1(sizeof(*(sort->fpincompressed))*(longerp+2), "AllocSort: fpincompressed");
4,889✔
938
        sort->zsparray = 0;
4,889✔
939
#endif
940

941
        sort->ktoi         = Malloc1(sizeof(*(sort->ktoi))*(longerp+2), "AllocSort: ktoi");
4,889✔
942

943
        // The combined Large buffer and Small buffer (+ extension) are used.
944
        // They must be allocated together.
945
        sort->lBuffer      = Malloc1(sizeof(*(sort->lBuffer))*(sort->LargeSize+sort->SmallEsize), "AllocSort: lBuffer+sBuffer");
4,889✔
946
        sort->lTop = sort->lBuffer+sort->LargeSize;
4,889✔
947

948
        sort->sBuffer = sort->lTop;
4,889✔
949
        if ( sort->LargeSize == 0 ) { sort->lBuffer = 0; sort->lTop = 0; }
4,889✔
950
        sort->sTop = sort->sBuffer + sort->SmallSize;
4,889✔
951
        sort->sTop2 = sort->sBuffer + sort->SmallEsize;
4,889✔
952
        sort->sHalf = sort->sBuffer + (LONG)((sort->SmallSize+sort->SmallEsize)>>1);
4,889✔
953

954
        sort->file.PObuffer = Malloc1(IObuffersize*sizeof(*(sort->file.PObuffer))+fname2Size+16, "AllocSort: PObuffer");
4,889✔
955
        sort->file.POstop = sort->file.PObuffer+IObuffersize;
4,889✔
956
        sort->file.POsize = IObuffersize * sizeof(WORD);
4,889✔
957
        sort->file.POfill = sort->file.POfull = sort->file.PObuffer;
4,889✔
958
        sort->file.active = 0;
4,889✔
959
        sort->file.handle = -1;
4,889✔
960
        PUTZERO(sort->file.POposition);
4,889✔
961
#ifdef WITHPTHREADS
962
        sort->file.pthreadslock = dummylock;
2,837✔
963
#endif
964
#ifdef WITHZLIB
965
        sort->file.ziosize = IObuffersize*sizeof(WORD);
4,889✔
966
        sort->file.ziobuffer = 0;
4,889✔
967
#endif
968
        if ( AM.S0 != 0 ) {
4,889✔
969
                sort->file.name = (char *)(sort->file.PObuffer + IObuffersize);
3,061✔
970
                AllocSortFileName(sort);
3,061✔
971
        }
972
        else sort->file.name = 0;
1,828✔
973
        sort->cBuffer = 0;
4,889✔
974
        sort->cBufferSize = 0;
4,889✔
975
        sort->f = 0;
4,889✔
976
        sort->PolyWise = 0;
4,889✔
977

978
        return(sort);
4,889✔
979
}
980

981
/*
982
                 #] AllocSort : 
983
                 #[ AllocSortFileName :
984
*/
985

986
VOID AllocSortFileName(SORTING *sort)
3,061✔
987
{
988
        GETIDENTITY
2,289✔
989
        char *s, *t;
3,061✔
990
/*
991
                This is not the allocation before the tempfiles are determined.
992
                Hence we can use the name in FG.fname2 and modify the tail
993
*/
994
        s = FG.fname2; t = sort->file.name;
3,061✔
995
        while ( *s ) *t++ = *s++;
45,915✔
996
#ifdef WITHPTHREADS
997
        t[-2] = 'F';
2,289✔
998
        sprintf(t-1,"%d.%d",identity,AN.filenum);
2,289✔
999
#else
1000
        t[-2] = 'f';
772✔
1001
        sprintf(t-1,"%d",AN.filenum);
772✔
1002
#endif
1003
        AN.filenum++;
3,061✔
1004
}
3,061✔
1005

1006
/*
1007
                 #] AllocSortFileName : 
1008
                 #[ AllocFileHandle :
1009
*/
1010

1011
FILEHANDLE *AllocFileHandle(WORD par,char *name)
206✔
1012
{
1013
        GETIDENTITY
88✔
1014
        LONG allocation, Ssize;
206✔
1015
        FILEHANDLE *fh;
206✔
1016
        int i = 0;
206✔
1017
        char *s, *t;
206✔
1018

1019
        s = FG.fname2; i = 0;
206✔
1020
        while ( *s ) { s++; i++; }
3,090✔
1021
        if ( par == 0 ) { i += 16; Ssize = AM.SIOsize; }
206✔
1022
        else { s = name; while ( *s ) { i++; s++; } i+= 2; Ssize = AM.SpectatorSize; }
595✔
1023

1024
        allocation = sizeof(FILEHANDLE) + (Ssize+1)*sizeof(WORD) + i*sizeof(char);
206✔
1025
        fh = (FILEHANDLE *)Malloc1(allocation,"FileHandle");
206✔
1026

1027
        fh->PObuffer = (WORD *)(fh+1);
206✔
1028
        fh->POstop = fh->PObuffer+Ssize;
206✔
1029
        fh->POsize = Ssize * sizeof(WORD);
206✔
1030
        fh->active = 0;
206✔
1031
        fh->handle = -1;
206✔
1032
        PUTZERO(fh->POposition);
206✔
1033
#ifdef WITHPTHREADS
1034
        fh->pthreadslock = dummylock;
88✔
1035
#endif
1036
        if ( par == 0 ) {        /* sort file */
206✔
1037
          if ( AM.S0 != 0 ) {
129✔
1038
                fh->name = (char *)(fh->POstop + 1);
129✔
1039
                s = FG.fname2; t = fh->name;
129✔
1040
                while ( *s ) *t++ = *s++;
1,935✔
1041
#ifdef WITHPTHREADS
1042
                t[-2] = 'F';
66✔
1043
                sprintf(t-1,"%d-%d",identity,AN.filenum);
66✔
1044
#else
1045
                t[-2] = 'f';
63✔
1046
                sprintf(t-1,"%d",AN.filenum);
63✔
1047
#endif
1048
                AN.filenum++;
129✔
1049
          }
UNCOV
1050
          else fh->name = 0;
×
1051
        }
1052
        else {        /* Spectator file */
1053
                fh->name = (char *)(fh->POstop + 1);
77✔
1054
                s = FG.fname; t = fh->name;
77✔
1055
                for ( i  = 0; i < FG.fnamebase; i++ ) *t++ = *s++;
231✔
1056
                s = name;
1057
                while ( *s ) *t++ = *s++;
595✔
1058
                *t = 0;
77✔
1059
        }
1060
        fh->POfill = fh->POfull = fh->PObuffer;
206✔
1061
        return(fh);
206✔
1062
}
1063

1064
/*
1065
                 #] AllocFileHandle : 
1066
                 #[ DeAllocFileHandle :
1067

1068
                Made to repair deallocation of AN.filenum. 21-sep-2000
1069
*/
1070

1071
void DeAllocFileHandle(FILEHANDLE *fh)
129✔
1072
{
1073
        GETIDENTITY
66✔
1074
        if ( fh->handle >= 0 ) {
129✔
UNCOV
1075
                CloseFile(fh->handle);
×
UNCOV
1076
                fh->handle = -1;
×
UNCOV
1077
                remove(fh->name);
×
1078
        }
1079
        AN.filenum--; /* free namespace. was forgotten in first reading */
129✔
1080
        M_free(fh,"Temporary FileHandle");
129✔
1081
}
129✔
1082

1083
/*
1084
                 #] DeAllocFileHandle : 
1085
                 #[ MakeSetupAllocs :
1086
*/
1087

1088
int MakeSetupAllocs()
1,828✔
1089
{
1090
        if ( RecalcSetups() || AllocSetups() ) return(1);
1,828✔
1091
        else return(0);
1092
}
1093

1094
/*
1095
                 #] MakeSetupAllocs : 
1096
                 #[ TryFileSetups :
1097

1098
                Routine looks in the input file for a start of the type
1099
                [#-]
1100
                #: setupparameter value
1101
                It keeps looking until the first line that does not start with
1102
                #-, #+ or #:
1103
                Then it rewinds the input.
1104
*/
1105

1106
#define SETBUFSIZE 257
1107

1108
int TryFileSetups()
1,828✔
1109
{
1110
        LONG oldstreamposition;
1,828✔
1111
        int oldstream;
1,828✔
1112
        int error = 0, eqnum;
1,828✔
1113
        int oldNoShowInput = AC.NoShowInput;
1,828✔
1114
        UBYTE buff[SETBUFSIZE+1], *s, *t, *u, *settop, c;
1,828✔
1115
        LONG linenum, prevline;
1,828✔
1116

1117
        if ( AC.CurrentStream == 0 ) return(error);
1,828✔
1118
        oldstream = AC.CurrentStream - AC.Streams;
1,828✔
1119
        oldstreamposition = GetStreamPosition(AC.CurrentStream);
1,828✔
1120
        linenum = AC.CurrentStream->linenumber;
1,828✔
1121
        prevline = AC.CurrentStream->prevline;
1,828✔
1122
        eqnum = AC.CurrentStream->eqnum;
1,828✔
1123
        AC.NoShowInput = 1;
1,828✔
1124
        settop = buff + SETBUFSIZE;
1,828✔
1125
        if ( AC.CurrentStream->type == INPUTSTREAM && oldstreamposition == 0 ) AC.CurrentStream->fileposition = 0;
1,828✔
1126
        for(;;) {
3,315✔
1127
                c = GetInput();
3,315✔
1128
                if ( c == '*' || c == '\n' ) {
3,315✔
1129
                        while ( c != '\n' && c != ENDOFINPUT ) c = GetInput();
46,945✔
1130
                        if ( c == ENDOFINPUT ) goto eoi;
1,170✔
1131
                        continue;
1,170✔
1132
                }
1133
                if ( c == ENDOFINPUT ) goto eoi;
2,145✔
1134
                if ( c != '#' ) break;
2,145✔
1135
                c = GetInput();
453✔
1136
                if ( c == ENDOFINPUT ) goto eoi;
453✔
1137
                if ( c != '-' && c != '+' && c != ':' ) break;
453✔
1138
                if ( c != ':' ) {
317✔
1139
                        while ( c != '\n' && c != ENDOFINPUT ) c = GetInput();
238✔
1140
                        continue;
119✔
1141
                }
1142
                s = buff;
320✔
1143
                while ( ( c = GetInput() ) == ' ' || c == '\t' || c == '\r' ) {}
320✔
1144
                if ( c == ENDOFINPUT ) break;
198✔
1145
                if ( c == LINEFEED ) continue;
198✔
1146
                if ( c == 0 || c == ENDOFINPUT ) break;
198✔
1147
                while ( c != LINEFEED ) {
3,278✔
1148
                        *s++ = c;
3,080✔
1149
                        c = GetInput();
3,080✔
1150
                        if ( c != LINEFEED && c != '\r' ) continue;
3,080✔
1151
                        if ( s >= settop ) {
198✔
UNCOV
1152
                                while ( c != '\n' && c != ENDOFINPUT ) c = GetInput();
×
UNCOV
1153
                                MesPrint("Setups in .frm file: Line too long. setup ignored");
×
UNCOV
1154
                                error++; goto nextline;
×
1155
                        }
1156
                }
1157
                *s++ = '\n';
198✔
1158
                t = s = buff; /* name of the option */
198✔
1159
                while ( tolower(*s) >= 'a' && tolower(*s) <= 'z' ) s++;
2,490✔
1160
                if ( *s != '\n' ) {
198✔
1161
                        *s++ = 0;
184✔
1162
                        while ( *s == ' ' || *s == '\t' ) s++;
184✔
1163
                        u = s; /* 'value' of the option */
788✔
1164
                        while ( *s && *s != '\n' && *s != '\r' ) s++;
788✔
1165
                        if ( *s ) *s++ = 0;
184✔
1166
                }
1167
                else {
1168
                        /* The value is empty. */
1169
                        u = s;
14✔
1170
                        *s++ = 0;
14✔
1171
                }
1172
                error += ProcessOption(t,u,1);
198✔
1173
nextline:;
1174
        }
1175
        AC.NoShowInput = oldNoShowInput;
1,828✔
1176
        AC.CurrentStream = AC.Streams + oldstream;
1,828✔
1177
        PositionStream(AC.CurrentStream,oldstreamposition);
1,828✔
1178
        AC.CurrentStream->linenumber = linenum;
1,828✔
1179
        AC.CurrentStream->prevline = prevline;
1,828✔
1180
        AC.CurrentStream->eqnum = eqnum;
1,828✔
1181
        ClearPushback();
1,828✔
1182
        if ( AC.CurrentStream->type == INPUTSTREAM ) AC.CurrentStream->fileposition = -1;
1,828✔
1183
        return(error);
UNCOV
1184
eoi:
×
UNCOV
1185
        MesPrint("Input file without a program.");
×
UNCOV
1186
        return(-1);
×
1187
}
1188

1189
/*
1190
                 #] TryFileSetups : 
1191
                 #[ TryEnvironment :
1192
*/
1193

1194
int TryEnvironment()
1,828✔
1195
{
1196
        char *s, *t, *u, varname[100];
1,828✔
1197
        int i,imax = sizeof(setupparameters)/sizeof(SETUPPARAMETERS);
1,828✔
1198
        int error = 0;
1,828✔
1199
        varname[0] = 'F'; varname[1] = 'O'; varname[2] = 'R'; varname[3] = 'M';
1,828✔
1200
        varname[4] = '_'; varname[5] = 0;
1,828✔
1201
        for ( i = 0; i < imax; i++ ) {
115,164✔
1202
                t = s = (char *)(setupparameters[i].parameter);
113,336✔
1203
                u = varname+5;
113,336✔
1204
                while ( *s ) { *u++ = (char)(toupper((unsigned char)*s)); s++; }
1,559,284✔
1205
                *u = 0;
113,336✔
1206
                s = (char *)(getenv(varname));
113,336✔
1207
                if ( s ) {
113,336✔
UNCOV
1208
                        error += ProcessOption((UBYTE *)t,(UBYTE *)s,2);
×
1209
                }
1210
        }
1211
        return(error);
1,828✔
1212
}
1213

1214
/*
1215
                 #] TryEnvironment : 
1216
        #] Setups :
1217
*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc