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

tueda / form / 15241916852

25 May 2025 08:59PM UTC coverage: 47.908% (-2.8%) from 50.743%
15241916852

push

github

tueda
ci: build arm64-windows binaries

39009 of 81425 relevant lines covered (47.91%)

1079780.1 hits per line

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

80.39
/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
#ifdef WITHFLOAT
61
        ,{(UBYTE *)"defaultprecision",      NUMERICALVALUE, 0, (LONG)DEFAULTPRECISION}
62
#endif
63
        ,{(UBYTE *)"define",                   DEFINEVALUE, 0, (LONG)0}
64
        ,{(UBYTE *)"dotchar",                  STRINGVALUE, 0, (LONG)dotchar}
65
        ,{(UBYTE *)"factorizationcache",    NUMERICALVALUE, 0, (LONG)FBUFFERSIZE}
66
        ,{(UBYTE *)"filepatches",           NUMERICALVALUE, 0, (LONG)MAXFPATCHES}
67
        ,{(UBYTE *)"functionlevels",        NUMERICALVALUE, 0, (LONG)MAXFLEVELS}
68
        ,{(UBYTE *)"hidesize",              NUMERICALVALUE, 0, (LONG)0}
69
        ,{(UBYTE *)"incdir",                     PATHVALUE, 0, (LONG)curdirp}
70
        ,{(UBYTE *)"indentspace",           NUMERICALVALUE, 0, (LONG)INDENTSPACE}
71
        ,{(UBYTE *)"insidefirst",               ONOFFVALUE, 0, (LONG)1}
72
        ,{(UBYTE *)"jumpratio",             NUMERICALVALUE, 0, (LONG)JUMPRATIO}
73
        ,{(UBYTE *)"largepatches",          NUMERICALVALUE, 0, (LONG)MAXPATCHES}
74
        ,{(UBYTE *)"largesize",             NUMERICALVALUE, 0, (LONG)LARGEBUFFER}
75
        ,{(UBYTE *)"maxnumbersize",         NUMERICALVALUE, 0, (LONG)0}
76
/*        ,{(UBYTE *)"maxnumbersize",         NUMERICALVALUE, 0, (LONG)MAXNUMBERSIZE} */
77
        ,{(UBYTE *)"maxtermsize",           NUMERICALVALUE, 0, (LONG)MAXTER}
78
#ifdef WITHFLOAT
79
        ,{(UBYTE *)"maxweight",             NUMERICALVALUE, 0, (LONG)MAXWEIGHT}
80
#endif
81
        ,{(UBYTE *)"maxwildcards",          NUMERICALVALUE, 0, (LONG)MAXWILDC}
82
        ,{(UBYTE *)"nospacesinnumbers",         ONOFFVALUE, 0, (LONG)0}
83
        ,{(UBYTE *)"numstorecaches",        NUMERICALVALUE, 0, (LONG)NUMSTORECACHES}
84
        ,{(UBYTE *)"nwritefinalstatistics",     ONOFFVALUE, 0, (LONG)0}
85
        ,{(UBYTE *)"nwriteprocessstatistics",   ONOFFVALUE, 0, (LONG)0}
86
        ,{(UBYTE *)"nwritestatistics",          ONOFFVALUE, 0, (LONG)0}
87
        ,{(UBYTE *)"nwritethreadstatistics",    ONOFFVALUE, 0, (LONG)0}
88
        ,{(UBYTE *)"oldfactarg",                ONOFFVALUE, 0, (LONG)NEWFACTARG}
89
        ,{(UBYTE *)"oldgcd",                    ONOFFVALUE, 0, (LONG)1}
90
        ,{(UBYTE *)"oldorder",                  ONOFFVALUE, 0, (LONG)0}
91
        ,{(UBYTE *)"oldparallelstatistics",     ONOFFVALUE, 0, (LONG)0}
92
        ,{(UBYTE *)"parentheses",           NUMERICALVALUE, 0, (LONG)MAXPARLEVEL}
93
        ,{(UBYTE *)"path",                       PATHVALUE, 0, (LONG)curdirp}
94
        ,{(UBYTE *)"procedureextension",       STRINGVALUE, 0, (LONG)procedureextension}
95
        ,{(UBYTE *)"processbucketsize",     NUMERICALVALUE, 0, (LONG)DEFAULTPROCESSBUCKETSIZE}
96
        ,{(UBYTE *)"resettimeonclear",          ONOFFVALUE, 0, (LONG)1}
97
        ,{(UBYTE *)"scratchsize",           NUMERICALVALUE, 0, (LONG)SCRATCHSIZE}
98
        ,{(UBYTE *)"shmwinsize",            NUMERICALVALUE, 0, (LONG)SHMWINSIZE}
99
        ,{(UBYTE *)"sizestorecache",        NUMERICALVALUE, 0, (LONG)SIZESTORECACHE}
100
        ,{(UBYTE *)"smallextension",        NUMERICALVALUE, 0, (LONG)SMALLOVERFLOW}
101
        ,{(UBYTE *)"smallsize",             NUMERICALVALUE, 0, (LONG)SMALLBUFFER}
102
        ,{(UBYTE *)"sortiosize",            NUMERICALVALUE, 0, (LONG)SORTIOSIZE}
103
        ,{(UBYTE *)"sorttype",                 STRINGVALUE, 0, (LONG)lowfirst}
104
        ,{(UBYTE *)"spectatorsize",         NUMERICALVALUE, 0, (LONG)SPECTATORSIZE}
105
        ,{(UBYTE *)"subfilepatches",        NUMERICALVALUE, 0, (LONG)SMAXFPATCHES}
106
        ,{(UBYTE *)"sublargepatches",       NUMERICALVALUE, 0, (LONG)SMAXPATCHES}
107
        ,{(UBYTE *)"sublargesize",          NUMERICALVALUE, 0, (LONG)SLARGEBUFFER}
108
        ,{(UBYTE *)"subsmallextension",     NUMERICALVALUE, 0, (LONG)SSMALLOVERFLOW}
109
        ,{(UBYTE *)"subsmallsize",          NUMERICALVALUE, 0, (LONG)SSMALLBUFFER}
110
        ,{(UBYTE *)"subsortiosize",         NUMERICALVALUE, 0, (LONG)SSORTIOSIZE}
111
        ,{(UBYTE *)"subtermsinsmall",       NUMERICALVALUE, 0, (LONG)STERMSSMALL}
112
        ,{(UBYTE *)"tempdir",                  STRINGVALUE, 0, (LONG)curdirp}
113
        ,{(UBYTE *)"tempsortdir",              STRINGVALUE, 0, (LONG)cursortdirp}
114
        ,{(UBYTE *)"termsinsmall",          NUMERICALVALUE, 0, (LONG)TERMSSMALL}
115
    ,{(UBYTE *)"threadbucketsize",      NUMERICALVALUE, 0, (LONG)DEFAULTTHREADBUCKETSIZE}
116
    ,{(UBYTE *)"threadloadbalancing",       ONOFFVALUE, 0, (LONG)DEFAULTTHREADLOADBALANCING}
117
    ,{(UBYTE *)"threads",               NUMERICALVALUE, 0, (LONG)DEFAULTTHREADS}
118
        ,{(UBYTE *)"threadscratchoutsize",  NUMERICALVALUE, 0, (LONG)THREADSCRATCHOUTSIZE}
119
        ,{(UBYTE *)"threadscratchsize",     NUMERICALVALUE, 0, (LONG)THREADSCRATCHSIZE}
120
    ,{(UBYTE *)"threadsortfilesynch",       ONOFFVALUE, 0, (LONG)0}
121
        ,{(UBYTE *)"totalsize",                 ONOFFVALUE, 0, (LONG)2}
122
        ,{(UBYTE *)"workspace",             NUMERICALVALUE, 0, (LONG)WORKBUFFER}
123
        ,{(UBYTE *)"wtimestats",                ONOFFVALUE, 0, (LONG)2}
124
};
125

126
/*
127
          #] Includes : 
128
        #[ Setups :
129
                 #[ DoSetups :
130
*/
131

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

175
/*
176
                 #] DoSetups : 
177
                 #[ ProcessOption :
178
*/
179

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

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

332
/*
333
                 #] ProcessOption : 
334
                 #[ GetSetupPar :
335
*/
336

337
SETUPPARAMETERS *GetSetupPar(UBYTE *s)
59,257✔
338
{
339
        int hi, med, lo, i;
59,257✔
340
        lo = 0;
59,257✔
341
        hi = sizeof(setupparameters)/sizeof(SETUPPARAMETERS);
59,257✔
342
        do {
299,876✔
343
                med = ( hi + lo ) / 2;
299,876✔
344
                i = StrICmp(s,(UBYTE *)setupparameters[med].parameter);
299,876✔
345
                if ( i == 0 ) return(setupparameters+med);
299,876✔
346
                if ( i < 0 ) hi = med-1;
240,619✔
347
                else         lo = med+1;
121,749✔
348
        } while ( hi >= lo );
240,619✔
349
        return(0);
350
}
351

352
/*
353
                 #] GetSetupPar : 
354
                 #[ RecalcSetups :
355
*/
356

357
int RecalcSetups(VOID)
886✔
358
{
359
        SETUPPARAMETERS *sp, *sp1;
886✔
360

361
        sp1 = GetSetupPar((UBYTE *)"threads");
886✔
362
        if ( AM.totalnumberofthreads > 1 ) sp1->value = AM.totalnumberofthreads - 1;
886✔
363
        else sp1->value = 0;
300✔
364
/*
365
        if ( sp1->value > 0 ) AM.totalnumberofthreads = sp1->value+1;
366
        if ( AM.totalnumberofthreads == 0 ) AM.totalnumberofthreads = 1;
367
*/
368
        sp  = GetSetupPar((UBYTE *)"filepatches");
886✔
369
        if ( sp->value < AM.totalnumberofthreads-1 )
886✔
370
                sp->value = AM.totalnumberofthreads - 1;
×
371

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

399
/*
400
                 #] RecalcSetups : 
401
                 #[ AllocSetups :
402
*/
403

404
int AllocSetups(VOID)
886✔
405
{
406
        SETUPPARAMETERS *sp;
886✔
407
        LONG LargeSize, SmallSize, SmallEsize, TermsInSmall, IOsize;
886✔
408
        int MaxPatches, MaxFpatches, error = 0, i, size;
886✔
409
        UBYTE *s;
886✔
410
#ifndef WITHPTHREADS
411
        int j;
296✔
412
#endif
413
        sp = GetSetupPar((UBYTE *)"threads");
886✔
414
        if ( sp->value > 0 ) AM.totalnumberofthreads = sp->value+1;
886✔
415

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

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

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

626
        sp = GetSetupPar((UBYTE *)"maxwildcards");
886✔
627
        AM.MaxWildcards = sp->value;
886✔
628
#ifdef WITHPTHREADS
629
#else
630
        AT.WildMask = (WORD *)Malloc1((LONG)AM.MaxWildcards*sizeof(WORD),"maxwildcards");
296✔
631
#endif
632

633
        sp = GetSetupPar((UBYTE *)"compresssize");
886✔
634
        if ( sp->value < 2*AM.MaxTer ) sp->value = 2*AM.MaxTer;
886✔
635
        AM.CompressSize = sp->value;
886✔
636
#ifndef WITHPTHREADS
637
        AR.CompressBuffer = (WORD *)Malloc1((AM.CompressSize+10)*sizeof(WORD),"compresssize");
296✔
638
        AR.CompressPointer = AR.CompressBuffer;
296✔
639
        AR.ComprTop = AR.CompressBuffer + AM.CompressSize;
296✔
640
#endif
641
        sp = GetSetupPar((UBYTE *)"bracketindexsize");
886✔
642
        if ( sp->value < 20*AM.MaxTer ) sp->value = 20*AM.MaxTer;
886✔
643
        AM.MaxBracketBufferSize = sp->value/sizeof(WORD);
886✔
644

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

672
        sp = GetSetupPar((UBYTE *)"totalsize");
886✔
673
        if ( sp->value != 2 ) AM.PrintTotalSize = sp->value;
886✔
674

675
        sp = GetSetupPar((UBYTE *)"continuationlines");
886✔
676
        AM.FortranCont = sp->value;
886✔
677
        sp = GetSetupPar((UBYTE *)"oldorder");
886✔
678
        AM.OldOrderFlag = sp->value;
886✔
679
        sp = GetSetupPar((UBYTE *)"resettimeonclear");
886✔
680
        AM.resetTimeOnClear = sp->value;
886✔
681
        sp = GetSetupPar((UBYTE *)"nospacesinnumbers");
886✔
682
        AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers = sp->value;
886✔
683
        sp = GetSetupPar((UBYTE *)"indentspace");
886✔
684
        AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace = sp->value;
886✔
685
        sp = GetSetupPar((UBYTE *)"jumpratio");
886✔
686
        AM.jumpratio = sp->value;
886✔
687
        sp = GetSetupPar((UBYTE *)"nwritestatistics");
886✔
688
        AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag = 1-sp->value;
886✔
689
        sp = GetSetupPar((UBYTE *)"nwritefinalstatistics");
886✔
690
        AC.FinalStats = AM.gFinalStats = AM.ggFinalStats = 1-sp->value;
886✔
691
        sp = GetSetupPar((UBYTE *)"nwritethreadstatistics");
886✔
692
        AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats = 1-sp->value;
886✔
693
        sp = GetSetupPar((UBYTE *)"nwriteprocessstatistics");
886✔
694
        AC.ProcessStats = AM.gProcessStats = AM.ggProcessStats = 1-sp->value;
886✔
695
        sp = GetSetupPar((UBYTE *)"oldparallelstatistics");
886✔
696
        AC.OldParallelStats = AM.gOldParallelStats = AM.ggOldParallelStats = sp->value;
886✔
697
        sp = GetSetupPar((UBYTE *)"oldfactarg");
886✔
698
        AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag = sp->value;
886✔
699
        sp = GetSetupPar((UBYTE *)"oldgcd");
886✔
700
        AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag = sp->value;
886✔
701
        sp = GetSetupPar((UBYTE *)"wtimestats");
886✔
702
        if ( sp->value == 2 ) sp->value = AM.ggWTimeStatsFlag;
886✔
703
        AC.WTimeStatsFlag = AM.gWTimeStatsFlag = AM.ggWTimeStatsFlag = sp->value;
886✔
704
#ifdef WITHFLOAT
705
        sp = GetSetupPar((UBYTE *)"maxweight");
886✔
706
        AC.MaxWeight = AM.gMaxWeight = AM.ggMaxWeight = sp->value;
886✔
707
        sp = GetSetupPar((UBYTE *)"defaultprecision");
886✔
708
        AC.DefaultPrecision = AM.gDefaultPrecision = AM.ggDefaultPrecision = sp->value;
886✔
709
#endif
710
        sp = GetSetupPar((UBYTE *)"sorttype");
886✔
711
        if ( StrICmp((UBYTE *)"lowfirst",(UBYTE *)sp->value) == 0 ) {
886✔
712
                AC.lSortType = SORTLOWFIRST;
886✔
713
        }
714
        else if ( StrICmp((UBYTE *)"highfirst",(UBYTE *)sp->value) == 0 ) {
×
715
                AC.lSortType = SORTHIGHFIRST;
×
716
        }
717
        else {
718
                MesPrint("  Illegal SortType specification: %s",(UBYTE *)sp->value);
×
719
                error = -2;
×
720
        }
721

722
        sp = GetSetupPar((UBYTE *)"processbucketsize");
886✔
723
        AM.hProcessBucketSize = AM.gProcessBucketSize =
886✔
724
        AC.ProcessBucketSize = AC.mProcessBucketSize = sp->value;
886✔
725
/*
726
        The store caches (code installed 15-aug-2006 JV)
727
*/
728
        sp = GetSetupPar((UBYTE *)"numstorecaches");
886✔
729
        AM.NumStoreCaches = sp->value;
886✔
730
        sp = GetSetupPar((UBYTE *)"sizestorecache");
886✔
731
        AM.SizeStoreCache = sp->value;
886✔
732
        /* Make sure this is a multiple of sizeof(WORD). */
733
        AM.SizeStoreCache = ((AM.SizeStoreCache+sizeof(WORD)-1)/sizeof(WORD))*sizeof(WORD);
886✔
734
#ifndef WITHPTHREADS
735
/*
736
        Install the store caches (15-aug-2006 JV)
737
        Note that in the case of PTHREADS this is done in InitializeOneThread
738
*/
739
        AT.StoreCache = AT.StoreCacheAlloc = 0;
296✔
740
        if ( AM.NumStoreCaches > 0 ) {
296✔
741
                STORECACHE sa, sb;
296✔
742
                size = sizeof(struct StOrEcAcHe)+AM.SizeStoreCache;
296✔
743
                size = ((size-1)/sizeof(size_t)+1)*sizeof(size_t);
296✔
744
                AT.StoreCacheAlloc = (STORECACHE)Malloc1(size*AM.NumStoreCaches,"StoreCaches");
296✔
745
                AT.StoreCache = AT.StoreCacheAlloc;
296✔
746
                sa = AT.StoreCache;
296✔
747
                for ( j = 0; j < AM.NumStoreCaches; j++ ) {
1,480✔
748
                        sb = (STORECACHE)(VOID *)((UBYTE *)sa+size);
1,184✔
749
                        if ( j == AM.NumStoreCaches-1 ) {
1,184✔
750
                                sa->next = 0;
296✔
751
                        }
752
                        else {
753
                                sa->next = sb;
888✔
754
                        }
755
                        SETBASEPOSITION(sa->position,-1);
1,184✔
756
                        SETBASEPOSITION(sa->toppos,-1);
1,184✔
757
                        sa = sb;
1,184✔
758
                }                
759
        }
760
#endif
761

762
/*
763
        And now some order sensitive things
764
*/
765
        if ( AM.Path == 0 ) {
886✔
766
                sp = GetSetupPar((UBYTE *)"path");
12✔
767
                AM.Path = strDup1((UBYTE *)(sp->value),"path");
12✔
768
        }
769
        if ( AM.IncDir == 0 ) {
886✔
770
                sp = GetSetupPar((UBYTE *)"incdir");
886✔
771
                AM.IncDir = strDup1((UBYTE *)(sp->value),"incdir");
886✔
772
        }
773
/*
774
        if ( AM.TempDir == 0 ) {
775
                sp = GetSetupPar((UBYTE *)"tempdir");
776
                AM.TempDir = strDup1((UBYTE *)(sp->value),"tempdir");
777
        }
778
*/
779
        return(error);
886✔
780
}
781

782
/*
783
                 #] AllocSetups : 
784
                 #[ WriteSetup :
785

786
        The routine writes the values of the setup parameters.
787
        We should do this better. (JV, 21-may-2008)
788
        The way it should be done is:
789
                a: write the raw values.
790
                b: give readjusted values.
791
                c: give derived values.
792
        Because this is a difficult subject, it would be nice to have a LaTeX
793
        document that explains this all exactly. There should then be a 
794
        mechanism to poke the values of the setup into the LaTeX document.
795
        probably the easiest way is to make a file with lots of \def definitions
796
        and have that included into the LaTeX file.
797
*/
798

799
VOID WriteSetup(VOID)
×
800
{
801
        int n = sizeof(setupparameters)/sizeof(SETUPPARAMETERS);
×
802
        SETUPPARAMETERS *sp;
×
803
        MesPrint(" The setup parameters are:");
×
804
        for ( sp = setupparameters; n > 0; n--, sp++ ) {
×
805
                switch(sp->type){
×
806
                        case NUMERICALVALUE:
×
807
                                MesPrint("   %s: %l",sp->parameter,sp->value);
×
808
                                break;
×
809
                        case PATHVALUE:
×
810
                                if ( StrICmp(sp->parameter,(UBYTE *)"path") == 0 && AM.Path ) {
×
811
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(AM.Path));
×
812
                                        break;
×
813
                                }
814
                                if ( StrICmp(sp->parameter,(UBYTE *)"incdir") == 0 && AM.IncDir ) {
×
815
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(AM.IncDir));
×
816
                                        break;
×
817
                                }
818
                                /* fall through */
819
                        case STRINGVALUE:
820
                                if ( StrICmp(sp->parameter,(UBYTE *)"tempdir") == 0 && AM.TempDir ) {
×
821
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(AM.TempDir));
×
822
                                }
823
                                else if ( StrICmp(sp->parameter,(UBYTE *)"tempsortdir") == 0 && AM.TempSortDir ) {
×
824
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(AM.TempSortDir));
×
825
                                }
826
                                else {
827
                                        MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(sp->value));
×
828
                                }
829
                                break;
830
                        case ONOFFVALUE:
×
831
                                if ( sp->value == 0 )
×
832
                                        MesPrint("   %s: OFF",sp->parameter);
×
833
                                else if ( sp->value == 1 )
×
834
                                        MesPrint("   %s: ON",sp->parameter);
×
835
                                break;
836
                        case DEFINEVALUE:
837
/*
838
                                MesPrint("   %s: '%s'",sp->parameter,(UBYTE *)(sp->value));
839
*/
840
                                break;
841
                }
842
        }
843
        AC.SetupFlag = 0;
×
844
}
×
845

846
/*
847
                 #] WriteSetup : 
848
                 #[ AllocSort :
849

850
                Routine allocates a complete struct for sorting.
851
                To be used for the main allocation of the sort buffers, and
852
                in a later stage for the function and subroutine sort buffers.
853
                The level arg denotes a main buffer allocation (0) or a sub-buffer
854
                allocation (1), used only for printing warning messages for buffer
855
                size adjustments in DEBUGGING mode.
856
*/
857
SORTING *AllocSort(LONG inLargeSize, LONG inSmallSize, LONG inSmallEsize, LONG inTermsInSmall,
3,572✔
858
                   int inMaxPatches, int inMaxFpatches, LONG inIOsize, int level)
859
{
860
        DUMMYUSE(level); /* This is only used in DEBUGGING mode */
3,572✔
861
        LONG LargeSize = inLargeSize;
3,572✔
862
        LONG SmallSize = inSmallSize;
3,572✔
863
        LONG SmallEsize = inSmallEsize;
3,572✔
864
        LONG TermsInSmall = inTermsInSmall;
3,572✔
865
        int MaxPatches = inMaxPatches;
3,572✔
866
        int MaxFpatches = inMaxFpatches;
3,572✔
867
        LONG IOsize = inIOsize;
3,572✔
868

869
        LONG longer,terms2insmall,sortsize,longerp;
3,572✔
870
        LONG IObuffersize = IOsize;
3,572✔
871
        LONG IOtry;
3,572✔
872
        SORTING *sort;
3,572✔
873
        int fname2Size = 0, j = 0;
3,572✔
874
        char *s;
3,572✔
875
        if ( AM.S0 != 0 ) {
3,572✔
876
                s = FG.fname2; fname2Size = 0;
2,686✔
877
                while ( *s ) { s++; fname2Size++; }
40,290✔
878
                fname2Size += 16;
2,686✔
879
        }
880
        if ( MaxFpatches < 4 ) MaxFpatches = 4;
3,572✔
881
        longer = MaxPatches > MaxFpatches ? MaxPatches : MaxFpatches;
3,572✔
882
        longerp = longer;
3,572✔
883
        while ( (1 << j) < longerp ) j++;
30,178✔
884
        longerp = (1 << j) + 1; 
3,572✔
885
        longerp += sizeof(WORD*) - (longerp%sizeof(WORD *));
3,572✔
886
        longer++;
3,572✔
887
        longer += sizeof(WORD*) - (longer%sizeof(WORD *));
3,572✔
888
        if ( SmallSize < 16*AM.MaxTer ) SmallSize = 16*AM.MaxTer+16;
3,572✔
889
        TermsInSmall = (TermsInSmall+15) & (-16L);
3,572✔
890
        terms2insmall = 2*TermsInSmall;  /* Used to be just + 100 rather than *2 */
3,572✔
891
        if ( SmallEsize < (SmallSize*3)/2 ) SmallEsize = (SmallSize*3)/2;
3,572✔
892
        if ( LargeSize > 0 && LargeSize < 2*SmallSize ) LargeSize = 2*SmallSize;
3,572✔
893
        SmallEsize = (SmallEsize+15) & (-16L);
3,572✔
894
        if ( LargeSize < 0 ) LargeSize = 0;
3,572✔
895
        sortsize = sizeof(SORTING);
3,572✔
896
        sortsize = (sortsize+15)&(-16L);
3,572✔
897
        IObuffersize = (IObuffersize+sizeof(WORD)-1)/sizeof(WORD);
3,572✔
898
/*
899
        The next statement fixes a bug. In the rare case that we have a
900
        problem here, we expand the size of the large buffer or the 
901
        small extension
902
*/
903
        if ( (ULONG)( LargeSize+SmallEsize ) < MaxFpatches*((IObuffersize
3,572✔
904
                +COMPINC)*sizeof(WORD)+2*AM.MaxTer) ) {
3,572✔
905
                if ( LargeSize == 0 ) 
6✔
906
                        SmallEsize = MaxFpatches*((IObuffersize+COMPINC)*sizeof(WORD)+2*AM.MaxTer);
×
907
                else
908
                        LargeSize  = MaxFpatches*((IObuffersize+COMPINC)*sizeof(WORD)+2*AM.MaxTer)
6✔
909
                                - SmallEsize;
6✔
910
        }
911

912
        IOtry = ((LargeSize+SmallEsize)/MaxFpatches-2*AM.MaxTer)/sizeof(WORD)-COMPINC;
3,572✔
913

914
        /* Here both IObuffersize and IOtry are in units of sizeof(WORD). */
915
        if ( IObuffersize < IOtry ) {
3,572✔
916
                IObuffersize = IOtry;
942✔
917
        }
918

919
#if DEBUGGING
920
        char *prefix;
3,572✔
921
        if ( level == 0 ) { prefix = ""; }
3,572✔
922
        else { prefix = "Sub"; }
934✔
923
        if ( LargeSize != inLargeSize ) { MesPrint("Warning: %sLargeSize adjusted: %l -> %l", prefix, inLargeSize, LargeSize); }
3,572✔
924
        if ( SmallSize != inSmallSize ) { MesPrint("Warning: %sSmallSize adjusted: %l -> %l", prefix, inSmallSize, SmallSize); }
3,572✔
925
        if ( SmallEsize != inSmallEsize ) {MesPrint("Warning: %sSmallEsize adjusted: %l -> %l", prefix, inSmallEsize, SmallEsize); }
3,572✔
926
        if ( TermsInSmall != inTermsInSmall ) { MesPrint("Warning: %sTermsInSmall adjusted: %l -> %l", prefix, inTermsInSmall, TermsInSmall); }
3,572✔
927
        if ( MaxPatches != inMaxPatches ) { MesPrint("Warning: MaxPatches adjusted: %d -> %d", inMaxPatches, MaxPatches); }
3,572✔
928
        if ( MaxFpatches != inMaxFpatches ) {MesPrint("Warning: MaxFPatches adjusted: %d -> %d", inMaxFpatches, MaxFpatches); }
3,572✔
929
        /* This one is always changed if the LargeSize has not been... */
930
        /* if ( IObuffersize != inIOsize/(LONG)sizeof(WORD) ) { MesPrint("Warning: IOsize adjusted: %l -> %l", inIOsize/sizeof(WORD), IObuffersize); } */
931
#endif
932

933
        /* Allocate separate buffers for most struct members, for better testing and debugging with valgrind. */
934
        sort = Malloc1(sizeof(*sort), "AllocSort: sorting struct");
3,572✔
935

936
        sort->LargeSize = LargeSize/sizeof(WORD);
3,572✔
937
        sort->SmallSize = SmallSize/sizeof(WORD);
3,572✔
938
        sort->SmallEsize = SmallEsize/sizeof(WORD);
3,572✔
939
        sort->MaxPatches = MaxPatches;
3,572✔
940
        sort->MaxFpatches = MaxFpatches;
3,572✔
941
        sort->TermsInSmall = TermsInSmall;
3,572✔
942
        sort->Terms2InSmall = terms2insmall;
3,572✔
943

944
        sort->sPointer     = Malloc1(sizeof(*(sort->sPointer    ))*terms2insmall, "AllocSort: sPointer");
3,572✔
945
        sort->Patches      = Malloc1(sizeof(*(sort->Patches     ))*longer, "AllocSort: Patches");
3,572✔
946
        sort->pStop        = Malloc1(sizeof(*(sort->pStop       ))*longer, "AllocSort: pStop");
3,572✔
947
        sort->poina        = Malloc1(sizeof(*(sort->poina       ))*longerp, "AllocSort: poina");
3,572✔
948
        sort->poin2a       = Malloc1(sizeof(*(sort->poin2a      ))*longerp, "AllocSort: poin2a");
3,572✔
949

950
        sort->fPatches     = Malloc1(sizeof(*(sort->fPatches    ))*longer, "AllocSort: fPatches");
3,572✔
951
        sort->fPatchesStop = Malloc1(sizeof(*(sort->fPatchesStop))*longer, "AllocSort: fPatchesStop");
3,572✔
952
        sort->inPatches    = Malloc1(sizeof(*(sort->inPatches   ))*longer, "AllocSort: inPatches");
3,572✔
953
        sort->tree         = Malloc1(sizeof(*(sort->tree        ))*longerp, "AllocSort: tree");
3,572✔
954
        sort->used         = Malloc1(sizeof(*(sort->used        ))*longerp, "AllocSort: used");
3,572✔
955

956
#ifdef WITHZLIB
957
        sort->fpcompressed   = Malloc1(sizeof(*(sort->fpcompressed  ))*(longerp+2), "AllocSort: fpcompressed");
3,572✔
958
        sort->fpincompressed = Malloc1(sizeof(*(sort->fpincompressed))*(longerp+2), "AllocSort: fpincompressed");
3,572✔
959
        sort->zsparray = 0;
3,572✔
960
#endif
961

962
        sort->ktoi         = Malloc1(sizeof(*(sort->ktoi))*(longerp+2), "AllocSort: ktoi");
3,572✔
963

964
        // The combined Large buffer and Small buffer (+ extension) are used.
965
        // They must be allocated together.
966
        sort->lBuffer      = Malloc1(sizeof(*(sort->lBuffer))*(sort->LargeSize+sort->SmallEsize), "AllocSort: lBuffer+sBuffer");
3,572✔
967
        sort->lTop = sort->lBuffer+sort->LargeSize;
3,572✔
968

969
        sort->sBuffer = sort->lTop;
3,572✔
970
        if ( sort->LargeSize == 0 ) { sort->lBuffer = 0; sort->lTop = 0; }
3,572✔
971
        sort->sTop = sort->sBuffer + sort->SmallSize;
3,572✔
972
        sort->sTop2 = sort->sBuffer + sort->SmallEsize;
3,572✔
973
        sort->sHalf = sort->sBuffer + (LONG)((sort->SmallSize+sort->SmallEsize)>>1);
3,572✔
974

975
        sort->file.PObuffer = Malloc1(IObuffersize*sizeof(*(sort->file.PObuffer))+fname2Size+16, "AllocSort: PObuffer");
3,572✔
976
        sort->file.POstop = sort->file.PObuffer+IObuffersize;
3,572✔
977
        sort->file.POsize = IObuffersize * sizeof(WORD);
3,572✔
978
        sort->file.POfill = sort->file.POfull = sort->file.PObuffer;
3,572✔
979
        sort->file.active = 0;
3,572✔
980
        sort->file.handle = -1;
3,572✔
981
        PUTZERO(sort->file.POposition);
3,572✔
982
#ifdef WITHPTHREADS
983
        sort->file.pthreadslock = dummylock;
3,041✔
984
#endif
985
#ifdef WITHZLIB
986
        sort->file.ziosize = IObuffersize*sizeof(WORD);
3,572✔
987
        sort->file.ziobuffer = 0;
3,572✔
988
#endif
989
        if ( AM.S0 != 0 ) {
3,572✔
990
                sort->file.name = (char *)(sort->file.PObuffer + IObuffersize);
2,686✔
991
                AllocSortFileName(sort);
2,686✔
992
        }
993
        else sort->file.name = 0;
886✔
994
        sort->cBuffer = 0;
3,572✔
995
        sort->cBufferSize = 0;
3,572✔
996
        sort->f = 0;
3,572✔
997
        sort->PolyWise = 0;
3,572✔
998

999
        return(sort);
3,572✔
1000
}
1001

1002
/*
1003
                 #] AllocSort : 
1004
                 #[ AllocSortFileName :
1005
*/
1006

1007
VOID AllocSortFileName(SORTING *sort)
2,686✔
1008
{
1009
        GETIDENTITY
2,451✔
1010
        char *s, *t;
2,686✔
1011
/*
1012
                This is not the allocation before the tempfiles are determined.
1013
                Hence we can use the name in FG.fname2 and modify the tail
1014
*/
1015
        s = FG.fname2; t = sort->file.name;
2,686✔
1016
        while ( *s ) *t++ = *s++;
40,290✔
1017
#ifdef WITHPTHREADS
1018
        t[-2] = 'F';
2,451✔
1019
        snprintf(t-1,FG.fname2size-(t-1-FG.fname2),"%d.%d",identity,AN.filenum);
2,451✔
1020
#else
1021
        t[-2] = 'f';
235✔
1022
        snprintf(t-1,FG.fname2size-(t-1-FG.fname2),"%d",AN.filenum);
235✔
1023
#endif
1024
        AN.filenum++;
2,686✔
1025
}
2,686✔
1026

1027
/*
1028
                 #] AllocSortFileName : 
1029
                 #[ AllocFileHandle :
1030
*/
1031

1032
FILEHANDLE *AllocFileHandle(WORD par,char *name)
132✔
1033
{
1034
        GETIDENTITY
88✔
1035
        LONG allocation, Ssize;
132✔
1036
        FILEHANDLE *fh;
132✔
1037
        int i = 0;
132✔
1038
        char *s, *t;
132✔
1039

1040
        s = FG.fname2; i = 0;
132✔
1041
        while ( *s ) { s++; i++; }
1,980✔
1042
        if ( par == 0 ) { i += 16; Ssize = AM.SIOsize; }
132✔
1043
        else { s = name; while ( *s ) { i++; s++; } i+= 2; Ssize = AM.SpectatorSize; }
255✔
1044

1045
        allocation = sizeof(FILEHANDLE) + (Ssize+1)*sizeof(WORD) + i*sizeof(char)
132✔
1046
                        +FG.fname2size+20;
132✔
1047
        fh = (FILEHANDLE *)Malloc1(allocation,"FileHandle");
132✔
1048

1049
        fh->PObuffer = (WORD *)(fh+1);
132✔
1050
        fh->POstop = fh->PObuffer+Ssize;
132✔
1051
        fh->POsize = Ssize * sizeof(WORD);
132✔
1052
        fh->active = 0;
132✔
1053
        fh->handle = -1;
132✔
1054
        PUTZERO(fh->POposition);
132✔
1055
#ifdef WITHPTHREADS
1056
        fh->pthreadslock = dummylock;
88✔
1057
#endif
1058
        if ( par == 0 ) {        /* sort file */
132✔
1059
          if ( AM.S0 != 0 ) {
99✔
1060
                fh->name = (char *)(fh->POstop + 1);
99✔
1061
                s = FG.fname2; t = fh->name;
99✔
1062
                while ( *s ) *t++ = *s++;
1,485✔
1063
#ifdef WITHPTHREADS
1064
                t[-2] = 'F';
66✔
1065
                snprintf(t-1,20,"%d-%d",identity,AN.filenum);
66✔
1066
#else
1067
                t[-2] = 'f';
33✔
1068
                snprintf(t-1,20,"%d",AN.filenum);
33✔
1069
#endif
1070
                AN.filenum++;
99✔
1071
          }
1072
          else fh->name = 0;
×
1073
        }
1074
        else {        /* Spectator file */
1075
                fh->name = (char *)(fh->POstop + 1);
33✔
1076
                s = FG.fname; t = fh->name;
33✔
1077
                for ( i  = 0; i < FG.fnamebase; i++ ) *t++ = *s++;
99✔
1078
                s = name;
1079
                while ( *s ) *t++ = *s++;
255✔
1080
                *t = 0;
33✔
1081
        }
1082
        fh->POfill = fh->POfull = fh->PObuffer;
132✔
1083
        return(fh);
132✔
1084
}
1085

1086
/*
1087
                 #] AllocFileHandle : 
1088
                 #[ DeAllocFileHandle :
1089

1090
                Made to repair deallocation of AN.filenum. 21-sep-2000
1091
*/
1092

1093
void DeAllocFileHandle(FILEHANDLE *fh)
99✔
1094
{
1095
        GETIDENTITY
66✔
1096
        if ( fh->handle >= 0 ) {
99✔
1097
                CloseFile(fh->handle);
×
1098
                fh->handle = -1;
×
1099
                remove(fh->name);
×
1100
        }
1101
        AN.filenum--; /* free namespace. was forgotten in first reading */
99✔
1102
        M_free(fh,"Temporary FileHandle");
99✔
1103
}
99✔
1104

1105
/*
1106
                 #] DeAllocFileHandle : 
1107
                 #[ MakeSetupAllocs :
1108
*/
1109

1110
int MakeSetupAllocs(VOID)
886✔
1111
{
1112
        if ( RecalcSetups() || AllocSetups() ) return(1);
886✔
1113
        else return(0);
1114
}
1115

1116
/*
1117
                 #] MakeSetupAllocs : 
1118
                 #[ TryFileSetups :
1119

1120
                Routine looks in the input file for a start of the type
1121
                [#-]
1122
                #: setupparameter value
1123
                It keeps looking until the first line that does not start with
1124
                #-, #+ or #:
1125
                Then it rewinds the input.
1126
*/
1127

1128
#define SETBUFSIZE 257
1129

1130
int TryFileSetups(VOID)
886✔
1131
{
1132
        LONG oldstreamposition;
886✔
1133
        int oldstream;
886✔
1134
        int error = 0, eqnum;
886✔
1135
        int oldNoShowInput = AC.NoShowInput;
886✔
1136
        UBYTE buff[SETBUFSIZE+1], *s, *t, *u, *settop, c;
886✔
1137
        LONG linenum, prevline;
886✔
1138

1139
        if ( AC.CurrentStream == 0 ) return(error);
886✔
1140
        oldstream = AC.CurrentStream - AC.Streams;
886✔
1141
        oldstreamposition = GetStreamPosition(AC.CurrentStream);
886✔
1142
        linenum = AC.CurrentStream->linenumber;
886✔
1143
        prevline = AC.CurrentStream->prevline;
886✔
1144
        eqnum = AC.CurrentStream->eqnum;
886✔
1145
        AC.NoShowInput = 1;
886✔
1146
        settop = buff + SETBUFSIZE;
886✔
1147
        if ( AC.CurrentStream->type == INPUTSTREAM && oldstreamposition == 0 ) AC.CurrentStream->fileposition = 0;
886✔
1148
        for(;;) {
1,768✔
1149
                c = GetInput();
1,768✔
1150
                if ( c == '*' || c == '\n' ) {
1,768✔
1151
                        while ( c != '\n' && c != ENDOFINPUT ) c = GetInput();
23,140✔
1152
                        if ( c == ENDOFINPUT ) goto eoi;
616✔
1153
                        continue;
616✔
1154
                }
1155
                if ( c == ENDOFINPUT ) goto eoi;
1,152✔
1156
                if ( c != '#' ) break;
1,152✔
1157
                c = GetInput();
335✔
1158
                if ( c == ENDOFINPUT ) goto eoi;
335✔
1159
                if ( c != '-' && c != '+' && c != ':' ) break;
335✔
1160
                if ( c != ':' ) {
266✔
1161
                        while ( c != '\n' && c != ENDOFINPUT ) c = GetInput();
176✔
1162
                        continue;
88✔
1163
                }
1164
                s = buff;
302✔
1165
                while ( ( c = GetInput() ) == ' ' || c == '\t' || c == '\r' ) {}
302✔
1166
                if ( c == ENDOFINPUT ) break;
178✔
1167
                if ( c == LINEFEED ) continue;
178✔
1168
                if ( c == 0 || c == ENDOFINPUT ) break;
178✔
1169
                while ( c != LINEFEED ) {
3,252✔
1170
                        *s++ = c;
3,074✔
1171
                        c = GetInput();
3,074✔
1172
                        if ( c != LINEFEED && c != '\r' ) continue;
3,074✔
1173
                        if ( s >= settop ) {
178✔
1174
                                while ( c != '\n' && c != ENDOFINPUT ) c = GetInput();
×
1175
                                MesPrint("Setups in .frm file: Line too long. setup ignored");
×
1176
                                error++; goto nextline;
×
1177
                        }
1178
                }
1179
                *s++ = '\n';
178✔
1180
                t = s = buff; /* name of the option */
178✔
1181
                while ( tolower(*s) >= 'a' && tolower(*s) <= 'z' ) s++;
2,332✔
1182
                if ( *s != '\n' ) {
178✔
1183
                        *s++ = 0;
172✔
1184
                        while ( *s == ' ' || *s == '\t' ) s++;
235✔
1185
                        u = s; /* 'value' of the option */
857✔
1186
                        while ( *s && *s != '\n' && *s != '\r' ) s++;
857✔
1187
                        if ( *s ) *s++ = 0;
172✔
1188
                }
1189
                else {
1190
                        /* The value is empty. */
1191
                        u = s;
6✔
1192
                        *s++ = 0;
6✔
1193
                }
1194
                error += ProcessOption(t,u,1);
178✔
1195
nextline:;
1196
        }
1197
        AC.NoShowInput = oldNoShowInput;
886✔
1198
        AC.CurrentStream = AC.Streams + oldstream;
886✔
1199
        PositionStream(AC.CurrentStream,oldstreamposition);
886✔
1200
        AC.CurrentStream->linenumber = linenum;
886✔
1201
        AC.CurrentStream->prevline = prevline;
886✔
1202
        AC.CurrentStream->eqnum = eqnum;
886✔
1203
        ClearPushback();
886✔
1204
        if ( AC.CurrentStream->type == INPUTSTREAM ) AC.CurrentStream->fileposition = -1;
886✔
1205
        return(error);
1206
eoi:
×
1207
        MesPrint("Input file without a program.");
×
1208
        return(-1);
×
1209
}
1210

1211
/*
1212
                 #] TryFileSetups : 
1213
                 #[ TryEnvironment :
1214
*/
1215

1216
int TryEnvironment(VOID)
886✔
1217
{
1218
        char *s, *t, *u, varname[100];
886✔
1219
        int i,imax = sizeof(setupparameters)/sizeof(SETUPPARAMETERS);
886✔
1220
        int error = 0;
886✔
1221
        varname[0] = 'F'; varname[1] = 'O'; varname[2] = 'R'; varname[3] = 'M';
886✔
1222
        varname[4] = '_'; varname[5] = 0;
886✔
1223
        for ( i = 0; i < imax; i++ ) {
57,590✔
1224
                t = s = (char *)(setupparameters[i].parameter);
56,704✔
1225
                u = varname+5;
56,704✔
1226
                while ( *s ) { *u++ = (char)(toupper((unsigned char)*s)); s++; }
779,680✔
1227
                *u = 0;
56,704✔
1228
                s = (char *)(getenv(varname));
56,704✔
1229
                if ( s ) {
56,704✔
1230
                        error += ProcessOption((UBYTE *)t,(UBYTE *)s,2);
×
1231
                }
1232
        }
1233
        return(error);
886✔
1234
}
1235

1236
/*
1237
                 #] TryEnvironment : 
1238
        #] Setups :
1239
*/
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

© 2026 Coveralls, Inc