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

tueda / form / 12516247166

27 Dec 2024 12:47PM UTC coverage: 50.678% (-0.05%) from 50.724%
12516247166

push

github

tueda
debug

42035 of 82946 relevant lines covered (50.68%)

1401654.15 hits per line

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

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

38
#include "form3.h"
39
#include "inivar.h"
40

41
#ifdef TRAPSIGNALS
42
#include "portsignals.h"
43
#else
44
#include <signal.h>
45
#endif
46

47
/*
48
 * A macro for translating the contents of `x' into a string after expanding.
49
 */
50
#define STRINGIFY(x)  STRINGIFY__(x)
51
#define STRINGIFY__(x) #x
52

53
/*
54
 * FORMNAME = "FORM" or "TFORM" or "ParFORM".
55
 */
56
#if defined(WITHPTHREADS)
57
        #define FORMNAME "TFORM"
58
#elif defined(WITHMPI)
59
        #define FORMNAME "ParFORM"
60
#else
61
        #define FORMNAME "FORM"
62
#endif
63

64
/*
65
 * VERSIONSTR is the version information printed in the header line.
66
 */
67
#ifdef HAVE_CONFIG_H
68
        /* We have also version.h. */
69
        #include "version.h"
70
        #ifndef REPO_VERSION
71
                #define REPO_VERSION STRINGIFY(REPO_MAJOR_VERSION) "." STRINGIFY(REPO_MINOR_VERSION)
72
        #endif
73
        #ifndef REPO_DATE
74
                /* The build date, instead of the repo date. */
75
                #define REPO_DATE __DATE__
76
        #endif
77
        #ifdef REPO_REVISION
78
                #define VERSIONSTR FORMNAME " " REPO_VERSION " (" REPO_DATE ", " REPO_REVISION ")"
79
        #else
80
                #define VERSIONSTR FORMNAME " " REPO_VERSION " (" REPO_DATE ")"
81
        #endif
82
        #define MAJORVERSION REPO_MAJOR_VERSION
83
        #define MINORVERSION REPO_MINOR_VERSION
84
#else
85
        /*
86
         * Otherwise, form3.h defines MAJORVERSION, MINORVERSION and PRODUCTIONDATE,
87
         * possibly BETAVERSION.
88
         */
89
        #ifdef BETAVERSION
90
                #define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION) "Beta"
91
        #else
92
                #define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION)
93
        #endif
94
        #define VERSIONSTR FORMNAME " " VERSIONSTR__ " (" PRODUCTIONDATE ")"
95
#endif
96

97
/*
98
                 #] includes : 
99
                 #[ PrintHeader :
100
*/
101

102
/**
103
 * Prints the header line of the output.
104
 *
105
 * @param  with_full_info  True for printing also runtime information.
106
 */
107
static void PrintHeader(int with_full_info)
1,896✔
108
{
109
#ifdef WITHMPI
110
        if ( PF.me == MASTER && !AM.silent ) {
1,037✔
111
#else
112
        if ( !AM.silent ) {
859✔
113
#endif
114
                char buffer1[250], buffer2[80], *s = buffer1, *t = buffer2;
280,869✔
115
                WORD length, n;
116
                for ( n = 0; n < 250; n++ ) buffer1[n] = ' ';
280,869✔
117
                /*
118
                 * NOTE: we expect that the compiler optimizes strlen("string literal")
119
                 * to just a number.
120
                 */
121
                if ( strlen(VERSIONSTR) <= 100 ) {
1,119✔
122
                        strcpy(s,VERSIONSTR);
1,119✔
123
                        s += strlen(VERSIONSTR);
1,119✔
124
                        *s = 0;
1,119✔
125
                }
126
                else {
127
                        /*
128
                         * Truncate when it is too long.
129
                         */
130
                        strncpy(s,VERSIONSTR,97);
131
                        s[97] = '.';
132
                        s[98] = '.';
133
                        s[99] = ')';
134
                        s[100] = '\0';
135
                        s += 100;
136
                }
137
/*
138
                By now we omit the message about 32/64 bits. It should all be 64.
139

140
                s += snprintf(s,250-(s-buffer1)," %d-bits",(WORD)(sizeof(WORD)*16));
141
                *s = 0;
142
*/
143
                if ( with_full_info ) {
1,119✔
144
#if defined(WITHPTHREADS) || defined(WITHMPI)
145
#if defined(WITHPTHREADS)
146
                        int nworkers = AM.totalnumberofthreads-1;
572✔
147
#elif defined(WITHMPI)
148
                        int nworkers = PF.numtasks-1;
260✔
149
#endif
150
                        s += snprintf(s,250-(s-buffer1)," %d worker",nworkers);
832✔
151
                        *s = 0;
832✔
152
/*                        while ( *s ) s++; */
153
                        if ( nworkers != 1 ) {
832✔
154
                                *s++ = 's';
832✔
155
                                *s = '\0';
832✔
156
                        }
157
#endif
158

159
                        snprintf(t,80-(t-buffer2),"Run: %s",MakeDate());
1,119✔
160
                        while ( *t ) t++;
34,689✔
161

162
                        /*
163
                         * Align the date to the right, if it fits in a line.
164
                         */
165
                        length = (s-buffer1) + (t-buffer2);
1,119✔
166
                        if ( length+2 <= AC.LineLength ) {
1,119✔
167
                                for ( n = AC.LineLength-length; n > 0; n-- ) *s++ = ' ';
×
168
                                *s = 0;
×
169
                                strcat(s,buffer2);
×
170
                                while ( *s ) s++;
×
171
                        }
172
                        else {
173
                                *s = 0;
1,119✔
174
                                strcat(s,"  ");
1,119✔
175
                                while ( *s ) s++;
3,357✔
176
                                *s = 0;
1,119✔
177
                                strcat(s,buffer2);
1,119✔
178
                                while ( *s ) s++;
34,689✔
179
                        }
180
                }
181

182
                /*
183
                 * If the header information doesn't fit in a line, we need to extend
184
                 * the line length temporarily.
185
                 */
186
                length = s-buffer1;
1,119✔
187
                if ( length <= AC.LineLength ) {
1,119✔
188
                        MesPrint("%s",buffer1);
×
189
                }
190
                else {
191
                        WORD oldLineLength = AC.LineLength;
1,119✔
192
                        AC.LineLength = length;
1,119✔
193
                        MesPrint("%s",buffer1);
1,119✔
194
                        AC.LineLength = oldLineLength;
1,119✔
195
                }
196
        }
197
}
1,896✔
198

199
/*
200
                 #] PrintHeader : 
201
                 #[ DoTail :
202

203
                Routine reads the command tail and handles the commandline options.
204
                It sets the flags for later actions and stored pathnames for
205
                the setup file, include/prc/sub directories etc.
206
                Finally the name of the program is passed on.
207
                Note that we do not support interactive use yet. This will come
208
                to pass in the distant future when we can couple STedi to FORM.
209
                Routine made 23-feb-1993 by J.Vermaseren
210
*/
211

212
#ifdef WITHINTERACTION
213
static UBYTE deflogname[] = "formsession.log";
214
#endif
215

216
#define TAKEPATH(x) if(s[1]== '=' ){x=s+2;} else{x=*argv++;argc--;}
217

218
int DoTail(int argc, UBYTE **argv)
1,903✔
219
{
220
        int errorflag = 0, onlyversion = 1;
1,903✔
221
        UBYTE *s, *t, *copy;
1,903✔
222
        int threadnum = 0;
1,903✔
223
        argc--; argv++;
1,903✔
224
        AM.ClearStore = 0;
1,903✔
225
        AM.TimeLimit = 0;
1,903✔
226
        AM.LogType = -1;
1,903✔
227
        AM.HoldFlag = AM.qError = AM.Interact = AM.FileOnlyFlag = 0;
1,903✔
228
        AM.InputFileName = AM.LogFileName = AM.IncDir = AM.TempDir = AM.TempSortDir =
1,903✔
229
        AM.SetupDir = AM.SetupFile = AM.Path = 0;
1,903✔
230
        AM.FromStdin = 0;
1,903✔
231
        if ( argc < 1 ) {
1,903✔
232
                onlyversion = 0;
×
233
                goto printversion;
×
234
        }
235
        while ( argc >= 1 ) {
4,378✔
236
                s = *argv++; argc--;
2,475✔
237
                if ( *s == '-' || ( *s == '/' && ( argc > 0 || AM.Interact ) ) ) {
2,475✔
238
                        s++;
572✔
239
                        switch (*s) {
572✔
240
                                case 'c': /* Error checking only */
×
241
                                                        AM.qError = 1;   break;
×
242
                                case 'C': /* Next arg is filename of log file */
×
243
                                                        TAKEPATH(AM.LogFileName)  break;
×
244
                                case 'D':
×
245
                                case 'd': /* Next arg is define preprocessor var. */
246
                                                        t = copy = strDup1(*argv,"Dotail");
×
247
                                                        while ( *t && *t != '=' ) t++;
×
248
                                                        if ( *t == 0 ) {
×
249
                                                                if ( PutPreVar(copy,(UBYTE *)"1",0,0) < 0 ) return(-1);
×
250
                                                        }
251
                                                        else {
252
                                                                *t++ = 0;
×
253
                                                                if ( PutPreVar(copy,t,0,0) < 0 ) return(-1);
×
254
                                                                t[-1] = '=';
×
255
                                                        }
256
                                                        M_free(copy,"-d prevar");
×
257
                                                        argv++; argc--; break;
×
258
                                case 'f': /* Output only to regular log file */
×
259
                                                        AM.FileOnlyFlag = 1; AM.LogType = 0; break;
×
260
                                case 'F': /* Output only to log file. Further like L. */
×
261
                                                        AM.FileOnlyFlag = 1; AM.LogType = 1; break;
×
262
                                case 'h': /* For old systems: wait for key before exit */
×
263
                                                        AM.HoldFlag = 1; break;
×
264
#ifdef WITHINTERACTION
265
                                case 'i': /* Interactive session (not used yet) */
266
                                                        AM.Interact = 1; break;
267
#endif
268
                                case 'I': /* Next arg is dir for inc/prc/sub files */
×
269
                                                        TAKEPATH(AM.IncDir)  break;
×
270
                                case 'l': /* Make regular log file */
×
271
                                                        if ( s[1] == 'l' ) AM.LogType = 1; /*compatibility! */
×
272
                                                        else               AM.LogType = 0;
×
273
                                                        break;
274
                                case 'L': /* Make log file with only final statistics */
×
275
                                                        AM.LogType = 1;  break;
×
276
                                case 'M': /* Multirun. Name of tempfiles will contain PID */
×
277
                                                        AM.MultiRun = 1;
×
278
                                                        break;
×
279
                                case 'm': /* Read number of threads */
572✔
280
                                case 'w': /* Read number of workers */
281
                                                        t = s++;
572✔
282
                                                        threadnum = 0;
572✔
283
                                                        while ( *s >= '0' && *s <= '9' )
1,144✔
284
                                                                threadnum = 10*threadnum + *s++ - '0';
572✔
285
                                                        if ( *s ) {
572✔
286
#ifdef WITHMPI
287
                                                                if ( PF.me == MASTER )
288
#endif
289
                                                                printf("Illegal value for option m or w: %s\n",t);
×
290
                                                                errorflag++;
×
291
                                                        }
292
/*                                                        if ( threadnum == 1 ) threadnum = 0; */
293
                                                        threadnum++;
572✔
294
                                                        break;
572✔
295
                                case 'W': /* Print the wall-clock time on the master. */
×
296
                                                        AM.ggWTimeStatsFlag = 1;
×
297
                                                        break;
×
298
/*
299
                                case 'n':
300
                                                        Reserved for number of slaves without MPI
301
*/
302
                                case 'p':
×
303
#ifdef WITHEXTERNALCHANNEL
304
                                        /*There are two possibilities: -p|-pipe*/                
305
                                        if(s[1]=='i'){
×
306
                                                if( (s[2]=='p')&&(s[3]=='e')&&(s[4]=='\0') ){
×
307
                                                        argc--;
×
308
                                                        /*Initialize pre-set external channels, see 
309
                                                                the file extcmd.c:*/
310
                                                        if(initPresetExternalChannels(*argv++,AX.timeout)<1){
×
311
#ifdef WITHMPI
312
                                                                if ( PF.me == MASTER )
313
#endif
314
                                                                printf("Error initializing preset external channels\n");
×
315
                                                                errorflag++;
×
316
                                                        }
317
                                                        AX.timeout=-1;/*This indicates that preset channels 
×
318
                                                                                                        are initialized from cmdline*/
319
                                                }else{
320
#ifdef WITHMPI
321
                                                        if ( PF.me == MASTER )
322
#endif
323
                                                        printf("Illegal option in call of FORM: %s\n",s);
×
324
                                                        errorflag++;
×
325
                                                }
326
                                        }else
327
#else
328
                                        if ( s[1] ) {
329
                                                if ( ( s[1]=='i' ) && ( s[2] == 'p' ) && (s[3] == 'e' )
330
                                                && ( s[4] == '\0' ) ){
331
#ifdef WITHMPI
332
                                                        if ( PF.me == MASTER )
333
#endif
334
                                                        printf("Illegal option: Pipes not supported on this system.\n");
335
                                                }
336
                                                else {
337
#ifdef WITHMPI
338
                                                        if ( PF.me == MASTER )
339
#endif
340
                                                        printf("Illegal option: %s\n",s);
341
                                                }
342
                                                errorflag++;
343
                                        }
344
                                        else
345
#endif
346
                                        {
347
                                                         /* Next arg is a path variable like in environment */
348
                                                TAKEPATH(AM.Path)
×
349
                                        }
350
                                        break;
351
                                case 'q': /* Quiet option. Only output. Same as -si */
×
352
                                                        AM.silent = 1; break;
×
353
                                case 'R': /* recover from saved snapshot */
×
354
                                                        AC.CheckpointFlag = -1;
×
355
                                                        break;
×
356
                                case 's': /* Next arg is dir with form.set to be used */
×
357
                                                        if ( ( s[1] == 'o' ) && ( s[2] == 'r' ) && ( s[3] == 't' ) ) {
×
358
                                                                if(s[4]== '=' ) {
×
359
                                                                        AM.TempSortDir = s+5;
×
360
                                                                }
361
                                                                else {
362
                                                                        AM.TempSortDir = *argv++;
×
363
                                                                        argc--;
×
364
                                                                }
365
                                                        }
366
                                                        else if ( s[1] == 'i' ) { /* compatibility: silent/quiet */
×
367
                                                                AM.silent = 1;
×
368
                                                        }
369
                                                        else {
370
                                                                TAKEPATH(AM.SetupDir)
×
371
                                                        }
372
                                                        break;
373
                                case 'S': /* Next arg is setup file */
×
374
                                                        TAKEPATH(AM.SetupFile) break;
×
375
                                case 't': /* Next arg is directory for temp files */
×
376
                                                        if ( s[1] == 's' ) {
×
377
                                                                s++;
×
378
                                                                AM.havesortdir = 1;
×
379
                                                                TAKEPATH(AM.TempSortDir)
×
380
                                                        }
381
                                                        else {
382
                                                                TAKEPATH(AM.TempDir)
×
383
                                                        }
384
                                                        break;
385
                                case 'T': /* Print the total size used at end of job */
×
386
                                                        AM.PrintTotalSize = 1; break;
×
387
                                case 'v':
388
printversion:;
×
389
#ifdef WITHMPI
390
                                                        if ( PF.me == MASTER )
391
#endif
392
                                                                PrintHeader(0);
×
393
                                                        if ( onlyversion ) return(1);
×
394
                                                        goto NoFile;
×
395
                                case 'y': /* Preprocessor dumps output. No compilation. */
×
396
                                                        AP.PreDebug = PREPROONLY;   break;
×
397
                                case 'z': /* The number following is a time limit in sec. */
×
398
                                                        t = s++;
×
399
                                                        AM.TimeLimit = 0;
×
400
                                                        while ( *s >= '0' && *s <= '9' )
×
401
                                                                AM.TimeLimit = 10*AM.TimeLimit + *s++ - '0';
×
402
                                                        break;
403
                                case 'Z': /* Removes the .str file on crash, no matter its contents */
×
404
                                                        AM.ClearStore = 1;   break;
×
405
                                case '\0': /* "-" to use STDIN for the input. */
×
406
#ifdef WITHMPI
407
                                                        /* At the moment, ParFORM doesn't implement STDIN broadcasts. */
408
                                                        if ( PF.me == MASTER )
409
                                                                printf("Sorry, reading STDIN as input is currently not supported by ParFORM\n");
410
                                                        errorflag++;
411
#endif
412
                                                        AM.FromStdin = 1;
×
413
                                                        AC.NoShowInput = 1; // disable input echoing by default
×
414
                                                        break;
×
415
                                default:
×
416
                                                if ( FG.cTable[*s] == 1 ) {
×
417
                                                        AM.SkipClears = 0; t = s;
×
418
                                                        while ( FG.cTable[*t] == 1 )
×
419
                                                                AM.SkipClears = 10*AM.SkipClears + *t++ - '0';
×
420
                                                        if ( *t != 0 ) {
×
421
#ifdef WITHMPI
422
                                                                if ( PF.me == MASTER )
423
#endif
424
                                                                printf("Illegal numerical option in call of FORM: %s\n",s);
×
425
                                                                errorflag++;
×
426
                                                        }
427
                                                }
428
                                                else {
429
#ifdef WITHMPI
430
                                                        if ( PF.me == MASTER )
431
#endif
432
                                                        printf("Illegal option in call of FORM: %s\n",s);
×
433
                                                        errorflag++;
×
434
                                                }
435
                                                break;
436
                        }
437
                }
438
                else if ( argc == 0 && !AM.Interact ) AM.InputFileName = argv[-1];
1,903✔
439
                else {
440
#ifdef WITHMPI
441
                        if ( PF.me == MASTER )
442
#endif
443
                        printf("Illegal option in call of FORM: %s\n",s);
×
444
                        errorflag++;
×
445
                }
446
        }
447
        AM.totalnumberofthreads = threadnum;
1,903✔
448
        if ( AM.InputFileName ) {
1,903✔
449
                if ( AM.FromStdin ) {
1,903✔
450
                        printf("STDIN and the input filename cannot be specified simultaneously\n");
×
451
                        errorflag++;
×
452
                }
453
                s = AM.InputFileName;
1,903✔
454
                while ( *s ) s++;
12,129✔
455
                if ( s < AM.InputFileName+4 ||
1,903✔
456
                s[-4] != '.' || s[-3] != 'f' || s[-2] != 'r' || s[-1] != 'm' ) {
1,903✔
457
                        t = (UBYTE *)Malloc1((s-AM.InputFileName)+5,"adding .frm");
×
458
                        s = AM.InputFileName;
×
459
                        AM.InputFileName = t;
×
460
                        while ( *s ) *t++ = *s++;
×
461
                        *t++ = '.'; *t++ = 'f'; *t++ = 'r'; *t++ = 'm'; *t = 0;
×
462
                }
463
                if ( AM.LogType >= 0 && AM.LogFileName == 0 ) {
1,903✔
464
                        AM.LogFileName = strDup1(AM.InputFileName,"name of logfile");
×
465
                        s = AM.LogFileName;
×
466
                        while ( *s ) s++;
×
467
                        s[-3] = 'l'; s[-2] = 'o'; s[-1] = 'g';
×
468
                }
469
        }
470
#ifdef WITHINTERACTION
471
        else if ( AM.Interact ) {
472
                if ( AM.LogType >= 0 ) {
473
/*
474
                        We may have to do better than just taking a name.
475
                        It is not unique! This will be left for later.
476
*/
477
                        AM.LogFileName = deflogname;
478
                }
479
        }
480
#endif
481
        else if ( AM.FromStdin ) {
×
482
                /* Do nothing. */
483
        }
484
        else {
485
NoFile:
×
486
#ifdef WITHMPI
487
                if ( PF.me == MASTER )
488
#endif
489
                printf("No filename specified in call of FORM\n");
×
490
                errorflag++;
×
491
        }
492
        if ( AM.Path == 0 ) AM.Path = (UBYTE *)getenv("FORMPATH");
1,903✔
493
        if ( AM.Path ) {
1,903✔
494
                /*
495
                 * AM.Path is taken from argv or getenv. Reallocate it to avoid invalid
496
                 * frees when AM.Path has to be changed.
497
                 */
498
                AM.Path = strDup1(AM.Path,"DoTail Path");
1,903✔
499
        }
500
        return(errorflag);
501
}
502

503
/*
504
                 #] DoTail : 
505
                 #[ OpenInput :
506

507
                Major task here after opening is to skip the proper number of
508
                .clear instructions if so desired without using interpretation
509
*/
510

511
int OpenInput(VOID)
1,903✔
512
{
513
        int oldNoShowInput = AC.NoShowInput;
1,903✔
514
        UBYTE c;
1,903✔
515
        if ( !AM.Interact ) {
1,903✔
516
                if ( AM.FromStdin ) {
1,903✔
517
                        if ( OpenStream(0,INPUTSTREAM,0,PRENOACTION) == 0 ) {
×
518
                                Error0("Cannot open STDIN");
×
519
                                return(-1);
×
520
                        }
521
                }
522
                else {
523
                if ( OpenStream(AM.InputFileName,FILESTREAM,0,PRENOACTION) == 0 ) {
1,903✔
524
                        Error1("Cannot open file",AM.InputFileName);
×
525
                        return(-1);
×
526
                }
527
                if ( AC.CurrentStream->inbuffer <= 0 ) {
1,903✔
528
                        Error1("No input in file",AM.InputFileName);
×
529
                        return(-1);
×
530
                }
531
                }
532
                AC.NoShowInput = 1;
1,903✔
533
                while ( AM.SkipClears > 0 ) {
1,903✔
534
                        c = GetInput();
×
535
                        if ( c == ENDOFINPUT ) {
×
536
                                Error0("Not enough .clear instructions in input file");
×
537
                        }
538
                        if ( c == '\\' ) {
×
539
                                c = GetInput();
×
540
                                if ( c == ENDOFINPUT )
×
541
                                        Error0("Not enough .clear instructions in input file");
×
542
                                continue;
×
543
                        }
544
                        if ( c == ' ' || c == '\t' ) continue;
×
545
                        if ( c == '.' ) {
×
546
                                c = GetInput();
×
547
                                if ( tolower(c) == 'c' ) {
×
548
                                        c = GetInput();
×
549
                                        if ( tolower(c) == 'l' ) {
×
550
                                                c = GetInput();
×
551
                                                if ( tolower(c) == 'e' ) {
×
552
                                                        c = GetInput();
×
553
                                                        if ( tolower(c) == 'a' ) {
×
554
                                                                c = GetInput();
×
555
                                                                if ( tolower(c) == 'r' ) {
×
556
                                                                        c = GetInput();
×
557
                                                                        if ( FG.cTable[c] > 2 ) {
×
558
                                                                                AM.SkipClears--;
×
559
                                                                        }
560
                                                                }
561
                                                        }
562
                                                }
563
                                        }
564
                                }
565
                                while ( c != '\n' && c != '\r' && c != ENDOFINPUT ) {
×
566
                                        c = GetInput();
×
567
                                        if ( c == '\\' ) c = GetInput();
×
568
                                }
569
                        }
570
                        else if ( c == '\n' || c == '\r' ) continue;
×
571
                        else {
572
                                while ( ( c = GetInput() ) != '\n' && c != '\r' ) {
×
573
                                        if ( c == ENDOFINPUT ) {
×
574
                                                Error0("Not enough .clear instructions in input file");
×
575
                                        }
576
                                }
577
                        }
578
                }
579
                AC.NoShowInput = oldNoShowInput;
1,903✔
580
        }
581
        if ( AM.LogFileName ) {
1,903✔
582
#ifdef WITHMPI
583
                if ( PF.me != MASTER ) {
584
                        /*
585
                         * Only the master writes to the log file. On slaves, we need
586
                         * a dummy handle, without opening the file.
587
                         */
588
                        extern FILES **filelist;  /* in tools.c */
589
                        int i = CreateHandle();
590
                        RWLOCKW(AM.handlelock);
591
                        filelist[i] = (FILES *)123;  /* Must be nonzero to prevent a reuse in CreateHandle. */
592
                        UNRWLOCK(AM.handlelock);
593
                        AC.LogHandle = i;
594
                }
595
                else
596
#endif
597
                if ( AC.CheckpointFlag != -1 ) {
×
598
                        if ( ( AC.LogHandle = CreateLogFile((char *)(AM.LogFileName)) ) < 0 ) {
×
599
                                Error1("Cannot create logfile",AM.LogFileName);
×
600
                                return(-1);
×
601
                        }
602
                }
603
                else {
604
                        if ( ( AC.LogHandle = OpenAddFile((char *)(AM.LogFileName)) ) < 0 ) {
×
605
                                Error1("Cannot re-open logfile",AM.LogFileName);
×
606
                                return(-1);
×
607
                        }
608
                }
609
        }
610
        return(0);
611
}
612

613
/*
614
                 #] OpenInput : 
615
                 #[ ReserveTempFiles :
616

617
                Order of preference:
618
                a: if there is a path in the commandtail, take that.
619
                b: if none, try in the form.set file.
620
                c: if still none, try in the environment for the variable FORMTMP
621
                d: if still none, try the current directory.
622

623
                The parameter indicates action in the case of multithreaded running.
624
                par = 0 : We just run on a single processor. Keep everything normal.
625
                par = 1 : Multithreaded running startup phase 1.
626
                par = 2 : Multithreaded running startup phase 2.
627
*/
628

629
UBYTE *emptystring = (UBYTE *)".";
630
UBYTE *defaulttempfilename = (UBYTE *)"xformxxx.str";
631

632
VOID ReserveTempFiles(int par)
4,185✔
633
{
634
        GETIDENTITY
2,856✔
635
        SETUPPARAMETERS *sp;
4,185✔
636
        UBYTE *s, *t, *tenddir, *tenddir2, c;        
4,185✔
637
        int i = 0;
4,185✔
638
        WORD j;
4,185✔
639
        if ( par == 0 || par == 1 ) {
4,185✔
640
        if ( AM.TempDir == 0 ) {
1,903✔
641
                sp = GetSetupPar((UBYTE *)"tempdir");
1,903✔
642
                if ( ( sp->flags & USEDFLAG ) != USEDFLAG ) {
1,903✔
643
                        AM.TempDir = (UBYTE *)getenv("FORMTMP");
1,903✔
644
                        if ( AM.TempDir == 0 ) AM.TempDir = emptystring;
1,903✔
645
                }
646
                else AM.TempDir = (UBYTE *)(sp->value);
×
647
        }
648
        if ( AM.TempSortDir == 0 ) {
1,903✔
649
                if ( AM.havesortdir ) {
1,903✔
650
                        sp = GetSetupPar((UBYTE *)"tempsortdir");
7✔
651
                        AM.TempSortDir = (UBYTE *)(sp->value);
7✔
652
                }
653
                else {
654
                        AM.TempSortDir = (UBYTE *)getenv("FORMTMPSORT");
1,896✔
655
                        if ( AM.TempSortDir == 0 ) AM.TempSortDir = AM.TempDir;
1,896✔
656
                }
657
        }
658
/*
659
        We have now in principle a path but we will use its first element only.
660
        Later that should become more complicated. Then we will use a path and
661
        when one device is full we can continue on the next one.
662
*/
663
        s = AM.TempDir; i = 200;   /* Some extra for VMS */
1,903✔
664
        while ( *s && *s != ':' ) { if ( *s == '\\' ) s++; s++; i++; }
3,806✔
665
        FG.fnamesize = sizeof(UBYTE)*(i+14);
1,903✔
666
        FG.fname = (char *)Malloc1(FG.fnamesize,"name for temporary files");
1,903✔
667
        s = AM.TempDir; t = (UBYTE *)FG.fname;
1,903✔
668
        while ( *s && *s != ':' ) { if ( *s == '\\' ) s++; *t++ = *s++; }
3,806✔
669
        if ( (char *)t > FG.fname && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
1,903✔
670
                *t++ = SEPARATOR;
1,903✔
671
        *t = 0;
1,903✔
672
        tenddir = t;
1,903✔
673
        FG.fnamebase = t-(UBYTE *)(FG.fname);
1,903✔
674

675
        s = AM.TempSortDir; i = 200;   /* Some extra for VMS */
1,903✔
676
        while ( *s && *s != ':' ) { if ( *s == '\\' ) s++; s++; i++; }
3,855✔
677

678
        FG.fname2size = sizeof(UBYTE)*(i+14);
1,903✔
679
        FG.fname2 = (char *)Malloc1(FG.fname2size,"name for sort files");
1,903✔
680
        s = AM.TempSortDir; t = (UBYTE *)FG.fname2;
1,903✔
681
        while ( *s && *s != ':' ) { if ( *s == '\\' ) s++; *t++ = *s++; }
3,855✔
682
        if ( (char *)t > FG.fname2 && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
1,903✔
683
                *t++ = SEPARATOR;
1,903✔
684
        *t = 0;
1,903✔
685
        tenddir2 = t;
1,903✔
686
        FG.fname2base = t-(UBYTE *)(FG.fname2);
1,903✔
687

688
        t = tenddir;
1,903✔
689
        s = defaulttempfilename;
1,903✔
690
#ifdef WITHMPI
691
        { 
692
          int iii;
1,041✔
693
#ifdef SMP
694
          /* Very dirty quick-hack for the qcm smp machine at TTP */
695
          M_free(FG.fname,"name for temporary files");
696
          if(PF.me == 0){
697
      /*[04nov2003 mt] To avoid segfault with -fast optimization option*/
698
                /*[04nov2003 mt]:*/ /*NOTE, this is only a temporary stub!*/
699
                /*FG.fname = "/formswap/xxxxxxxxxxxxxxxxxxxxx";*/
700
                FG.fname = calloc(128,1);
701
                strcpy(FG.fname,"/formswap/xxxxxxxxxxxxxxxxxxxxx");
702
                /*:[04nov2003 mt]*/
703
                t = (UBYTE *)FG.fname + 10;
704
                FG.fnamebase = t-FG.fname;
705
          }
706
          else{
707
                /*[04nov2003 mt]:*/
708
                /*FG.fname = "/formswapx/xxxxxxxxxxxxxxxxxxxxx";*/
709
                FG.fname = calloc(128,1);
710
                strcpy(FG.fname,"/formswapx/xxxxxxxxxxxxxxxxxxxxx");
711
                /*:[04nov2003 mt]*/
712
                FG.fname[9] = '0' + PF.me;
713
                t = (UBYTE *)FG.fname + 11;
714
                FG.fnamebase = t-FG.fname;
715
          }
716
#else
717
          iii = snprintf((char*)t,FG.fnamesize-((char*)t-FG.fname),"%d",PF.me);
1,041✔
718
          t+= iii;
1,041✔
719
          s+= iii; /* in case defaulttmpfilename is too short */
1,041✔
720
#endif
721
        }
722
#endif
723
        while ( *s ) *t++ = *s++;
23,698✔
724
        *t = 0;
1,903✔
725
/*
726
                There are problems when running many FORM jobs at the same time
727
                from make or minos. If they start up simultaneously, occasionally
728
                they can make the same .str file. We prevent this with first trying
729
                a file that contains the digits of the pid. If this file
730
                has already been taken we fall back on the old scheme.
731
                The whole is controlled with the -M (MultiRun) parameter in the
732
                command tail.
733
*/
734
        if ( AM.MultiRun ) {
1,903✔
735
                int num = ((int)GetPID())%100000;
×
736
                t += 2;
×
737
                *t = 0;
×
738
                t[-1] = 'r';
×
739
                t[-2] = 't';
×
740
                t[-3] = 's';
×
741
                t[-4] = '.';
×
742
                t[-5] = (UBYTE)('0' + num%10);
×
743
                t[-6] = (UBYTE)('0' + (num/10)%10);
×
744
                t[-7] = (UBYTE)('0' + (num/100)%10);
×
745
                t[-8] = (UBYTE)('0' + (num/1000)%10);
×
746
                t[-9] = (UBYTE)('0' + num/10000);
×
747
                if ( ( AC.StoreHandle = CreateFile((char *)FG.fname) ) < 0 ) {
×
748
                        t[-5] = 'x'; t[-6] = 'x'; t[-7] = 'x'; t[-8] = 'x'; t[-9] = 'x';
×
749
                        goto classic;
×
750
                }
751
        }
752
        else
753
        {
754
classic:;
1,903✔
755
          for(;;) {
1,942✔
756
                if ( ( AC.StoreHandle = OpenFile((char *)FG.fname) ) < 0 ) {
1,942✔
757
                        if ( ( AC.StoreHandle = CreateFile((char *)FG.fname) ) >= 0 ) break;
1,903✔
758
                }
759
                else CloseFile(AC.StoreHandle);
39✔
760
                c = t[-5];
39✔
761
                if ( c == 'x' ) t[-5] = '0';
39✔
762
                else if ( c == '9' ) {
7✔
763
                        t[-5] = '0';
×
764
                        c = t[-6];
×
765
                        if ( c == 'x' ) t[-6] = '0';
×
766
                        else if ( c == '9' ) {
×
767
                                t[-6] = '0';
×
768
                                c = t[-7];
×
769
                                if ( c == 'x' ) t[-7] = '0';
×
770
                                else if ( c == '9' ) {
×
771
/*
772
                                        Note that we tried 1111 names!
773
*/
774
                                        MesPrint("Name space for temp files exhausted");
×
775
                                        t[-7] = 0;
×
776
                                        MesPrint("Please remove files of the type %s or try a different directory"
×
777
                                                ,FG.fname);
778
                                        Terminate(-1);
×
779
                                }
780
                                else t[-7] = (UBYTE)(c+1);
×
781
                        }
782
                        else t[-6] = (UBYTE)(c+1);
×
783
                }
784
                else t[-5] = (UBYTE)(c+1);
7✔
785
          }
786
        }
787
/*
788
        Now we should make sure that the tempsortdir cq tempsortfilename makes it
789
        into a similar construction.
790
*/
791
        s = tenddir; t = tenddir2; while ( *s ) *t++ = *s++;
24,739✔
792
        *t = 0;
1,903✔
793

794
/*
795
        Now we should assign a name to the main sort file and the two stage 4 files.
796
*/
797
        AM.S0->file.name = (char *)Malloc1(sizeof(char)*(i+14),"name for temporary files");
1,903✔
798
        s = (UBYTE *)AM.S0->file.name;
1,903✔
799
        t = (UBYTE *)FG.fname2;
1,903✔
800
        i = 1;
1,903✔
801
        while ( *t ) { *s++ = *t++; i++; }
28,594✔
802
        s[-2] = 'o'; *s = 0;
1,903✔
803
        }
804
/*
805
        Try to create the sort file already, so we can Terminate earlier if this fails.
806
*/
807
#ifdef WITHPTHREADS
808
        if ( par <= 1 ) {
2,856✔
809
#endif
810
        if ( ( AM.S0->file.handle = CreateFile((char *)AM.S0->file.name) ) < 0 ) {
1,903✔
811
                MesPrint("Could not create sort file: %s", AM.S0->file.name);
7✔
812
                Terminate(-1);
7✔
813
        };
1,896✔
814
        /* Close and clean up the test file */
815
        CloseFile(AM.S0->file.handle);
1,896✔
816
        AM.S0->file.handle = -1;
1,896✔
817
        remove(AM.S0->file.name);
1,896✔
818
#ifdef WITHPTHREADS
819
        }
820
#endif
821
/*
822
        With the stage4 and scratch file names we have to be a bit more careful.
823
        They are to be allocated after the threads are initialized when there
824
        are threads of course.
825
*/
826
        if ( par == 0 ) {
4,178✔
827
                s = (UBYTE *)((void *)(FG.fname2)); i = 0;
1,324✔
828
                while ( *s ) { s++; i++; }
19,860✔
829
                s = (UBYTE *)Malloc1(sizeof(char)*(i+1),"name for stage4 file a");
1,324✔
830
                AR.FoStage4[1].name = (char *)s;
1,324✔
831
                t = (UBYTE *)FG.fname2;
1,324✔
832
                while ( *t ) *s++ = *t++;
19,860✔
833
                s[-2] = '4'; s[-1] = 'a'; *s = 0;
1,324✔
834
                s = (UBYTE *)((void *)(FG.fname)); i = 0;
1,324✔
835
                while ( *s ) { s++; i++; }
19,860✔
836
                s = (UBYTE *)Malloc1(sizeof(char)*(i+1),"name for stage4 file b");
1,324✔
837
                AR.FoStage4[0].name = (char *)s;
1,324✔
838
                t = (UBYTE *)FG.fname;
1,324✔
839
                while ( *t ) *s++ = *t++;
19,860✔
840
                s[-2] = '4'; s[-1] = 'b'; *s = 0;
1,324✔
841
                for ( j = 0; j < 3; j++ ) {
5,296✔
842
                        s = (UBYTE *)Malloc1(sizeof(char)*(i+1),"name for scratch file");
3,972✔
843
                        AR.Fscr[j].name = (char *)s;
3,972✔
844
                        t = (UBYTE *)FG.fname;
3,972✔
845
                        while ( *t ) *s++ = *t++;
59,580✔
846
                        s[-2] = 'c'; s[-1] = (UBYTE)('0'+j); *s = 0;
3,972✔
847
                }
848
        }
849
#ifdef WITHPTHREADS
850
        else if ( par == 2 ) {
2,854✔
851
                size_t tname;
2,282✔
852
                s = (UBYTE *)((void *)(FG.fname2)); i = 0;
2,282✔
853
                while ( *s ) { s++; i++; }
34,230✔
854
                tname = sizeof(char)*(i+12);
2,282✔
855
                s = (UBYTE *)Malloc1(tname,"name for stage4 file a");
2,282✔
856
                snprintf((char *)s,tname,"%s.%d",FG.fname2,AT.identity);
2,282✔
857
                s[i-2] = '4'; s[i-1] = 'a';
2,282✔
858
                AR.FoStage4[1].name = (char *)s;
2,282✔
859
                s = (UBYTE *)((void *)(FG.fname)); i = 0;
2,282✔
860
                while ( *s ) { s++; i++; }
34,230✔
861
                tname = sizeof(char)*(i+12);
2,282✔
862
                s = (UBYTE *)Malloc1(tname,"name for stage4 file b");
2,282✔
863
                snprintf((char *)s,tname,"%s.%d",FG.fname,AT.identity);
2,282✔
864
                s[i-2] = '4'; s[i-1] = 'b';
2,282✔
865
                AR.FoStage4[0].name = (char *)s;
2,282✔
866
                if ( AT.identity == 0 ) {
2,282✔
867
                        for ( j = 0; j < 3; j++ ) {
2,288✔
868
                                s = (UBYTE *)Malloc1(sizeof(char)*(i+1),"name for scratch file");
1,716✔
869
                                AR.Fscr[j].name = (char *)s;
1,716✔
870
                                t = (UBYTE *)FG.fname;
1,716✔
871
                                while ( *t ) *s++ = *t++;
25,740✔
872
                                s[-2] = 'c'; s[-1] = (UBYTE)('0'+j); *s = 0;
1,716✔
873
                        }
874
                }
875
        }
876
#endif
877
}
4,178✔
878

879
/*
880
                 #] ReserveTempFiles : 
881
                 #[ StartVariables :
882
*/
883

884
#ifdef WITHPTHREADS
885
ALLPRIVATES *DummyPointer = 0;
886
#endif
887

888
VOID StartVariables(VOID)
1,903✔
889
{
890
        int i, ii;
1,903✔
891
        PUTZERO(AM.zeropos);
1,903✔
892
        StartPrepro();
1,903✔
893
/*
894
        The module counter:
895
*/
896
        AC.CModule=0;
1,903✔
897
#ifdef WITHPTHREADS
898
/*
899
        We need a value in AB because in the startup some routines may call AB[0].
900
*/
901
        AB = (ALLPRIVATES **)&DummyPointer;
574✔
902
#endif
903
/*
904
        separators used to delimit arguments in #call and #do, by default ',' and '|':
905
        Be sure, it is en empty set:
906
*/
907
        set_sub(AC.separators,AC.separators,AC.separators);
1,903✔
908
        set_set(',',AC.separators);
1,903✔
909
        set_set('|',AC.separators);
1,903✔
910

911
        AM.BracketFactors[0] = 8;
1,903✔
912
        AM.BracketFactors[1] = SYMBOL;
1,903✔
913
        AM.BracketFactors[2] = 4;
1,903✔
914
        AM.BracketFactors[3] = FACTORSYMBOL;
1,903✔
915
        AM.BracketFactors[4] = 1;
1,903✔
916
        AM.BracketFactors[5] = 1;
1,903✔
917
        AM.BracketFactors[6] = 1;
1,903✔
918
        AM.BracketFactors[7] = 3;
1,903✔
919

920
        AM.SkipClears = 0;
1,903✔
921
        AC.Cnumpows = 0;
1,903✔
922
        AC.OutputMode = 72;
1,903✔
923
        AC.OutputSpaces = NORMALFORMAT;
1,903✔
924
        AC.LineLength = 79;
1,903✔
925
        AM.gIsFortran90 = AC.IsFortran90 = ISNOTFORTRAN90;
1,903✔
926
        AM.gFortran90Kind = AC.Fortran90Kind = 0;
1,903✔
927
        AM.gCnumpows = 0;
1,903✔
928
        AC.exprfillwarning = 0;
1,903✔
929
        AM.gLineLength = 79;
1,903✔
930
        AM.OutBufSize = 80;
1,903✔
931
        AM.MaxStreamSize = MAXFILESTREAMSIZE;
1,903✔
932
        AP.MaxPreAssignLevel = 4;
1,903✔
933
        AC.iBufferSize = 512;
1,903✔
934
        AP.pSize = 128;
1,903✔
935
        AP.MaxPreIfLevel = 10;
1,903✔
936
        AP.cComChar = AP.ComChar = '*';
1,903✔
937
        AP.firstnamespace = 0;
1,903✔
938
        AP.lastnamespace = 0;
1,903✔
939
        AP.fullnamesize = 127;
1,903✔
940
        AP.fullname = (UBYTE *)Malloc1((AP.fullnamesize+1)*sizeof(UBYTE),"AP.fullname");
1,903✔
941
        AM.OffsetVector = -2*WILDOFFSET+MINSPEC;
1,903✔
942
        AC.cbufList.num = 0;
1,903✔
943
        AM.hparallelflag = AM.gparallelflag =
1,903✔
944
        AC.parallelflag = AC.mparallelflag = PARALLELFLAG;
1,903✔
945
#ifdef WITHMPI
946
        if ( PF.numtasks < 2 ) AM.hparallelflag |= NOPARALLEL_NPROC;
1,041✔
947
#endif
948
        AC.tablefilling = 0;
1,903✔
949
        AC.models = 0;
1,903✔
950
        AC.nummodels = 0;
1,903✔
951
        AC.ModelLevel = 0;
1,903✔
952
        AC.modelspace = 0;
1,903✔
953
        AM.resetTimeOnClear = 1;
1,903✔
954
        AM.gnumextrasym = AM.ggnumextrasym = 0;
1,903✔
955
        AM.havesortdir = 0;
1,903✔
956
        AM.SpectatorFiles = 0;
1,903✔
957
        AM.NumSpectatorFiles = 0;
1,903✔
958
        AM.SizeForSpectatorFiles = 0;
1,903✔
959
/*
960
        Information for the lists of variables. Part of error message and size:
961
*/
962
        AP.ProcList.message = "procedure";
1,903✔
963
        AP.ProcList.size = sizeof(PROCEDURE);
1,903✔
964
        AP.LoopList.message = "doloop";
1,903✔
965
        AP.LoopList.size = sizeof(DOLOOP);
1,903✔
966
        AP.PreVarList.message = "PreVariable";
1,903✔
967
        AP.PreVarList.size = sizeof(PREVAR);
1,903✔
968
        AC.SymbolList.message = "symbol";
1,903✔
969
        AC.SymbolList.size = sizeof(struct SyMbOl);
1,903✔
970
        AC.IndexList.message = "index";
1,903✔
971
        AC.IndexList.size = sizeof(struct InDeX);
1,903✔
972
        AC.VectorList.message = "vector";
1,903✔
973
        AC.VectorList.size = sizeof(struct VeCtOr);
1,903✔
974
        AC.FunctionList.message = "function";
1,903✔
975
        AC.FunctionList.size = sizeof(struct FuNcTiOn);
1,903✔
976
        AC.SetList.message = "set";
1,903✔
977
        AC.SetList.size = sizeof(struct SeTs);
1,903✔
978
        AC.SetElementList.message = "set element";
1,903✔
979
        AC.SetElementList.size = sizeof(WORD);
1,903✔
980
        AC.ExpressionList.message = "expression";
1,903✔
981
        AC.ExpressionList.size = sizeof(struct ExPrEsSiOn);
1,903✔
982
        AC.cbufList.message = "compiler buffer";
1,903✔
983
        AC.cbufList.size = sizeof(CBUF);
1,903✔
984
        AC.ChannelList.message = "channel buffer";
1,903✔
985
        AC.ChannelList.size = sizeof(CHANNEL);
1,903✔
986
        AP.DollarList.message = "$-variable";
1,903✔
987
        AP.DollarList.size = sizeof(struct DoLlArS);
1,903✔
988
        AC.DubiousList.message = "ambiguous variable";
1,903✔
989
        AC.DubiousList.size = sizeof(struct DuBiOuS);
1,903✔
990
        AC.TableBaseList.message = "list of tablebases";
1,903✔
991
        AC.TableBaseList.size = sizeof(DBASE);
1,903✔
992
        AC.TestValue = 0;
1,903✔
993
        AC.InnerTest = 0;
1,903✔
994

995
        AC.AutoSymbolList.message = "autosymbol";
1,903✔
996
        AC.AutoSymbolList.size = sizeof(struct SyMbOl);
1,903✔
997
        AC.AutoIndexList.message = "autoindex";
1,903✔
998
        AC.AutoIndexList.size = sizeof(struct InDeX);
1,903✔
999
        AC.AutoVectorList.message = "autovector";
1,903✔
1000
        AC.AutoVectorList.size = sizeof(struct VeCtOr);
1,903✔
1001
        AC.AutoFunctionList.message = "autofunction";
1,903✔
1002
        AC.AutoFunctionList.size = sizeof(struct FuNcTiOn);
1,903✔
1003
        AC.PotModDolList.message = "potentially modified dollar";
1,903✔
1004
        AC.PotModDolList.size = sizeof(WORD);
1,903✔
1005
        AC.ModOptDolList.message = "moduleoptiondollar";
1,903✔
1006
        AC.ModOptDolList.size = sizeof(MODOPTDOLLAR);
1,903✔
1007

1008
        AO.FortDotChar = '_';
1,903✔
1009
        AO.ErrorBlock = 0;
1,903✔
1010
        AC.firstconstindex = 1;
1,903✔
1011
        AO.Optimize.mctsconstant.fval = 1.0;
1,903✔
1012
        AO.Optimize.horner = O_MCTS;
1,903✔
1013
        AO.Optimize.hornerdirection = O_FORWARDORBACKWARD;
1,903✔
1014
        AO.Optimize.method = O_GREEDY;
1,903✔
1015
        AO.Optimize.mctstimelimit = 0;
1,903✔
1016
        AO.Optimize.mctsnumexpand = 1000;
1,903✔
1017
        AO.Optimize.mctsnumkeep = 10;
1,903✔
1018
        AO.Optimize.mctsnumrepeat = 1;
1,903✔
1019
        AO.Optimize.greedytimelimit = 0;
1,903✔
1020
        AO.Optimize.greedyminnum = 10;
1,903✔
1021
        AO.Optimize.greedymaxperc = 5;
1,903✔
1022
        AO.Optimize.printstats = 0;
1,903✔
1023
        AO.Optimize.debugflags = 0;
1,903✔
1024
        AO.OptimizeResult.code = NULL;
1,903✔
1025
        AO.inscheme = 0;
1,903✔
1026
        AO.schemenum = 0;
1,903✔
1027
        AO.wpos = 0;
1,903✔
1028
        AO.wpoin = 0;
1,903✔
1029
        AO.wlen = 0;
1,903✔
1030
        AM.dollarzero = 0;
1,903✔
1031
         AC.doloopstack = 0;
1,903✔
1032
         AC.doloopstacksize = 0;
1,903✔
1033
         AC.dolooplevel = 0;
1,903✔
1034
/*
1035
        Set up the main name trees:
1036
*/
1037
        AC.varnames  = MakeNameTree();
1,903✔
1038
        AC.exprnames = MakeNameTree();
1,903✔
1039
        AC.dollarnames = MakeNameTree();
1,903✔
1040
        AC.autonames = MakeNameTree();
1,903✔
1041
        AC.activenames = &(AC.varnames);
1,903✔
1042
        AP.preError = 0;
1,903✔
1043
/*
1044
        Initialize the compiler:
1045
*/
1046
        inictable();
1,903✔
1047
        AM.rbufnum = inicbufs();                /* Regular compiler buffer */
1,903✔
1048
#ifndef WITHPTHREADS
1049
        AT.ebufnum = inicbufs();                /* Buffer for extras during execution */
1,329✔
1050
        AT.fbufnum = inicbufs();                /* Buffer for caching in factorization */
1,329✔
1051
        AT.allbufnum = inicbufs();                /* Buffer for id,all */
1,329✔
1052
        AT.aebufnum = inicbufs();                /* Buffer for id,all */
1,329✔
1053
        AN.tryterm = 0;
1,329✔
1054
#else
1055
        AS.MasterSort = 0;
574✔
1056
#endif
1057
        AM.dbufnum = inicbufs();                /* Buffer for dollar variables */
1,903✔
1058
        AM.sbufnum = inicbufs();                /* Subterm buffer for polynomials and optimization */
1,903✔
1059
        AC.ffbufnum = inicbufs();                /* Buffer number for user defined factorizations */
1,903✔
1060
        AM.zbufnum = inicbufs();                /* For very special values */
1,903✔
1061
        {
1062
                CBUF *C = cbuf+AM.zbufnum;
1,903✔
1063
                WORD one[5] = {4,1,1,3,0};
1,903✔
1064
                WORD zero = 0;
1,903✔
1065
                AddRHS(AM.zbufnum,1);
1,903✔
1066
                AM.zerorhs = C->numrhs;
1,903✔
1067
                AddNtoC(AM.zbufnum,1,&zero,17);
1,903✔
1068
                AddRHS(AM.zbufnum,1);
1,903✔
1069
                AM.onerhs = C->numrhs;
1,903✔
1070
                AddNtoC(AM.zbufnum,5,one,17);
1,903✔
1071
        }
1072
        AP.inside.inscbuf = inicbufs();        /* For the #inside instruction */
1,903✔
1073
/*
1074
        Enter the built in objects
1075
*/
1076
        AC.Symbols = &(AC.SymbolList);
1,903✔
1077
        AC.Indices = &(AC.IndexList);
1,903✔
1078
        AC.Vectors = &(AC.VectorList);
1,903✔
1079
        AC.Functions = &(AC.FunctionList);
1,903✔
1080
        AC.vetofilling = 0;
1,903✔
1081

1082
        AddDollar((UBYTE *)"$",DOLUNDEFINED,0,0);
1,903✔
1083

1084
        cbuf[AM.dbufnum].mnumlhs = cbuf[AM.dbufnum].numlhs;
1,903✔
1085
        cbuf[AM.dbufnum].mnumrhs = cbuf[AM.dbufnum].numrhs;
1,903✔
1086

1087
        AddSymbol((UBYTE *)"i_",-MAXPOWER,MAXPOWER,VARTYPEIMAGINARY,0);
1,903✔
1088
        AM.numpi = AddSymbol((UBYTE *)"pi_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1,903✔
1089
/*
1090
        coeff_ should have the number COEFFSYMBOL and den_ the number DENOMINATOR
1091
    and the three should be in this order!
1092
*/
1093
        AddSymbol((UBYTE *)"coeff_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1,903✔
1094
        AddSymbol((UBYTE *)"num_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1,903✔
1095
        AddSymbol((UBYTE *)"den_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1,903✔
1096
        AddSymbol((UBYTE *)"xarg_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1,903✔
1097
        AddSymbol((UBYTE *)"dimension_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1,903✔
1098
        AddSymbol((UBYTE *)"factor_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1,903✔
1099
        AddSymbol((UBYTE *)"sep_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1,903✔
1100
        i = BUILTINSYMBOLS;  /* update this in ftypes.h when we add new symbols */
1,903✔
1101
/*
1102
        Next we add a number of dummy symbols for ensuring that the user defined
1103
        symbols start at a fixed given number FIRSTUSERSYMBOL
1104
        We do want to give them unique names though that the user cannot access.
1105
*/
1106
        {
1107
                char dumstr[20];
1,903✔
1108
                for ( ; i < FIRSTUSERSYMBOL; i++ ) {
24,739✔
1109
                        snprintf(dumstr,20,":%d:",i);
20,933✔
1110
                        AddSymbol((UBYTE *)dumstr,-MAXPOWER,MAXPOWER,VARTYPENONE,0);
20,933✔
1111
                }
1112
        }
1113

1114
        AddIndex((UBYTE *)"iarg_",4,0);
1,903✔
1115
        AddVector((UBYTE *)"parg_",VARTYPENONE,0);
1,903✔
1116

1117
        AM.NumFixedFunctions = sizeof(fixedfunctions)/sizeof(struct fixedfun);
1,903✔
1118
        for ( i = 0; i < AM.NumFixedFunctions; i++ ) {
199,815✔
1119
                ii = AddFunction((UBYTE *)fixedfunctions[i].name
197,912✔
1120
                                         ,fixedfunctions[i].commu
1121
                                         ,fixedfunctions[i].tensor
1122
                                         ,fixedfunctions[i].complx
1123
                                         ,fixedfunctions[i].symmetric
1124
                                         ,0,-1,-1);
1125
                if ( fixedfunctions[i].tensor == GAMMAFUNCTION )
197,912✔
1126
                                                        functions[ii].flags |= COULDCOMMUTE;
9,515✔
1127
        }
1128
/*
1129
        Next we add a number of dummy functions for ensuring that the user defined
1130
        functions start at a fixed given number FIRSTUSERFUNCTION.
1131
        We do want to give them unique names though that the user cannot access.
1132
*/
1133
        {
1134
                char dumstr[20];
1135
                for ( ; i < FIRSTUSERFUNCTION-FUNCTION; i++ ) {
51,381✔
1136
                        snprintf(dumstr,20,"::%d::",i);
49,478✔
1137
                        AddFunction((UBYTE *)dumstr,0,0,0,0,0,-1,-1);
49,478✔
1138
                }
1139
        }
1140
        AM.NumFixedSets = sizeof(fixedsets)/sizeof(struct fixedset);
1,903✔
1141
        for ( i = 0; i < AM.NumFixedSets; i++ ) {
26,642✔
1142
                ii = AddSet((UBYTE *)fixedsets[i].name,fixedsets[i].dimension);
24,739✔
1143
                Sets[ii].type = fixedsets[i].type;
24,739✔
1144
        }
1145
        AM.RepMax = MAXREPEAT;
1,903✔
1146
#ifndef WITHPTHREADS
1147
        AT.RepCount = (int *)Malloc1((LONG)((AM.RepMax+3)*sizeof(int)),"repeat buffers");
1,329✔
1148
        AN.RepPoint = AT.RepCount;
1,329✔
1149
        AT.RepTop = AT.RepCount + AM.RepMax;
1,329✔
1150
        AN.polysortflag = 0;
1,329✔
1151
        AN.subsubveto = 0;
1,329✔
1152
#endif
1153
        AC.NumWildcardNames = 0;
1,903✔
1154
        AC.WildcardBufferSize = 50;
1,903✔
1155
        AC.WildcardNames = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,"argument list names");
1,903✔
1156
#ifndef WITHPTHREADS
1157
        AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*sizeof(WORD)/2
1,329✔
1158
                                ,"argument list names");
1159
        AT.WildcardBufferSize = AC.WildcardBufferSize;
1,329✔
1160
        AR.CompareRoutine = (COMPAREDUMMY)(&Compare1);
1,329✔
1161
        AT.nfac = AT.nBer = 0;
1,329✔
1162
        AT.factorials = 0;
1,329✔
1163
        AT.bernoullis = 0;
1,329✔
1164
        AR.wranfia = 0;
1,329✔
1165
        AR.wranfcall = 0;
1,329✔
1166
        AR.wranfnpair1 = NPAIR1;
1,329✔
1167
        AR.wranfnpair2 = NPAIR2;
1,329✔
1168
        AR.wranfseed = 0;
1,329✔
1169
#endif
1170
        AM.atstartup = 1;
1,903✔
1171
        AM.oldnumextrasymbols = strDup1((UBYTE *)"OLDNUMEXTRASYMBOLS_","oldnumextrasymbols");
1,903✔
1172
        PutPreVar((UBYTE *)"VERSION_",(UBYTE *)STRINGIFY(MAJORVERSION),0,0);
1,903✔
1173
        PutPreVar((UBYTE *)"SUBVERSION_",(UBYTE *)STRINGIFY(MINORVERSION),0,0);
1,903✔
1174
        PutPreVar((UBYTE *)"DATE_",(UBYTE *)MakeDate(),0,0);
1,903✔
1175
        PutPreVar((UBYTE *)"random_",(UBYTE *)"________",(UBYTE *)"?a",0);
1,903✔
1176
        PutPreVar((UBYTE *)"optimminvar_",(UBYTE *)("0"),0,0);
1,903✔
1177
        PutPreVar((UBYTE *)"optimmaxvar_",(UBYTE *)("0"),0,0);
1,903✔
1178
        PutPreVar(AM.oldnumextrasymbols,(UBYTE *)("0"),0,0);
1,903✔
1179
        PutPreVar((UBYTE *)"optimvalue_",(UBYTE *)("0"),0,0);
1,903✔
1180
        PutPreVar((UBYTE *)"optimscheme_",(UBYTE *)("0"),0,0);
1,903✔
1181
        PutPreVar((UBYTE *)"tolower_",(UBYTE *)("0"),(UBYTE *)("?a"),0);
1,903✔
1182
        PutPreVar((UBYTE *)"toupper_",(UBYTE *)("0"),(UBYTE *)("?a"),0);
1,903✔
1183
        PutPreVar((UBYTE *)"takeleft_",(UBYTE *)("0"),(UBYTE *)("?a"),0);
1,903✔
1184
        PutPreVar((UBYTE *)"takeright_",(UBYTE *)("0"),(UBYTE *)("?a"),0);
1,903✔
1185
        PutPreVar((UBYTE *)"keepleft_",(UBYTE *)("0"),(UBYTE *)("?a"),0);
1,903✔
1186
        PutPreVar((UBYTE *)"keepright_",(UBYTE *)("0"),(UBYTE *)("?a"),0);
1,903✔
1187
        PutPreVar((UBYTE *)"SYSTEMERROR_",(UBYTE *)("0"),0,0);
1,903✔
1188
/*
1189
        Next are a few 'constants' for diagram generation
1190
*/
1191
        PutPreVar((UBYTE *)"ONEPI_",(UBYTE *)("1"),0,0);
1,903✔
1192
        PutPreVar((UBYTE *)"WITHOUTINSERTIONS_",(UBYTE *)("2"),0,0);
1,903✔
1193
        PutPreVar((UBYTE *)"NOTADPOLES_",(UBYTE *)("4"),0,0);
1,903✔
1194
        PutPreVar((UBYTE *)"SYMMETRIZE_",(UBYTE *)("8"),0,0);
1,903✔
1195
        PutPreVar((UBYTE *)"TOPOLOGIESONLY_",(UBYTE *)("16"),0,0);
1,903✔
1196
        PutPreVar((UBYTE *)"NONODES_",(UBYTE *)("32"),0,0);
1,903✔
1197
        PutPreVar((UBYTE *)"WITHEDGES_",(UBYTE *)("64"),0,0);
1,903✔
1198
/*                Note that CHECKEXTERN is 128 */
1199
        PutPreVar((UBYTE *)"WITHBLOCKS_",(UBYTE *)("256"),0,0);
1,903✔
1200
                PutPreVar((UBYTE *)"WITHONEPISETS_",(UBYTE *)("512"),0,0);
1,903✔
1201
        PutPreVar((UBYTE *)"NOSNAILS_",(UBYTE *)("1024"),0,0);
1,903✔
1202
        PutPreVar((UBYTE *)"NOEXTSELF_",(UBYTE *)("2048"),0,0);
1,903✔
1203

1204
        {
1205
                char buf[41];  /* up to 128-bit */
1,903✔
1206
                LONG pid;
1,903✔
1207
#ifndef WITHMPI
1208
                pid = GetPID();
862✔
1209
#else
1210
                pid = ( PF.me == MASTER ) ? GetPID() : (LONG)0;
1,041✔
1211
                pid = PF_BroadcastNumber(pid);
1,041✔
1212
#endif
1213
                LongCopy(pid,buf);
1,903✔
1214
                PutPreVar((UBYTE *)"PID_",(UBYTE *)buf,0,0);
1,903✔
1215
        }
1216
        AM.atstartup = 0;
1,903✔
1217
        AP.MaxPreTypes = 10;
1,903✔
1218
        AP.NumPreTypes = 0;
1,903✔
1219
        AP.PreTypes = (int *)Malloc1(sizeof(int)*(AP.MaxPreTypes+1),"preprocessor types");
1,903✔
1220
        AP.inside.buffer = 0;
1,903✔
1221
        AP.inside.size = 0;
1,903✔
1222

1223
        AC.SortType = AC.lSortType = AM.gSortType = SORTLOWFIRST;
1,903✔
1224
#ifdef WITHPTHREADS
1225
#else
1226
        AR.SortType = AC.SortType;
1,329✔
1227
#endif
1228
        AC.LogHandle = -1;
1,903✔
1229
        AC.SetList.numtemp        = AC.SetList.num;
1,903✔
1230
        AC.SetElementList.numtemp = AC.SetElementList.num;
1,903✔
1231

1232
        GetName(AC.varnames,(UBYTE *)"exp_",&AM.expnum,NOAUTO);
1,903✔
1233
        GetName(AC.varnames,(UBYTE *)"denom_",&AM.denomnum,NOAUTO);
1,903✔
1234
        GetName(AC.varnames,(UBYTE *)"fac_",&AM.facnum,NOAUTO);
1,903✔
1235
        GetName(AC.varnames,(UBYTE *)"invfac_",&AM.invfacnum,NOAUTO);
1,903✔
1236
        GetName(AC.varnames,(UBYTE *)"sum_",&AM.sumnum,NOAUTO);
1,903✔
1237
        GetName(AC.varnames,(UBYTE *)"sump_",&AM.sumpnum,NOAUTO);
1,903✔
1238
        GetName(AC.varnames,(UBYTE *)"term_",&AM.termfunnum,NOAUTO);
1,903✔
1239
        GetName(AC.varnames,(UBYTE *)"match_",&AM.matchfunnum,NOAUTO);
1,903✔
1240
        GetName(AC.varnames,(UBYTE *)"count_",&AM.countfunnum,NOAUTO);
1,903✔
1241
        AM.termfunnum += FUNCTION;
1,903✔
1242
        AM.matchfunnum += FUNCTION;
1,903✔
1243
        AM.countfunnum += FUNCTION;
1,903✔
1244

1245
        AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats = 1;
1,903✔
1246
        AC.FinalStats = AM.gFinalStats = AM.ggFinalStats = 1;
1,903✔
1247
        AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag = 1;
1,903✔
1248
        AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag = 1;
1,903✔
1249
        AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing = 1;
1,903✔
1250
        AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch = 0;
1,903✔
1251
        AC.ProcessStats = AM.gProcessStats = AM.ggProcessStats = 1;
1,903✔
1252
        AC.OldParallelStats = AM.gOldParallelStats = AM.ggOldParallelStats = 0;
1,903✔
1253
        AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag = NEWFACTARG;
1,903✔
1254
        AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag = 1;
1,903✔
1255
        AC.WTimeStatsFlag = AM.gWTimeStatsFlag = AM.ggWTimeStatsFlag = 0;
1,903✔
1256
        AM.gcNumDollars = AP.DollarList.num;
1,903✔
1257
        AC.SizeCommuteInSet = AM.gSizeCommuteInSet = 0;
1,903✔
1258
#ifdef WITHFLOAT
1259
        AC.MaxWeight = AM.gMaxWeight = AM.ggMaxWeight = MAXWEIGHT;
1,903✔
1260
        AC.DefaultPrecision = AM.gDefaultPrecision = AM.ggDefaultPrecision = DEFAULTPRECISION;
1,903✔
1261
#endif
1262
        AC.CommuteInSet = 0;
1,903✔
1263

1264
        AM.PrintTotalSize = 0;
1,903✔
1265

1266
        AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers = 0;
1,903✔
1267
        AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace = INDENTSPACE;
1,903✔
1268
        AO.BlockSpaces = 0;
1,903✔
1269
        AO.OptimizationLevel = 0;
1,903✔
1270
        PUTZERO(AS.MaxExprSize);
1,903✔
1271
        PUTZERO(AC.StoreFileSize);
1,903✔
1272

1273
#ifdef WITHPTHREADS
1274
        AC.inputnumbers = 0;
574✔
1275
        AC.pfirstnum = 0;
574✔
1276
        AC.numpfirstnum = AC.sizepfirstnum = 0;
574✔
1277
#endif
1278
        AC.MemDebugFlag = 1;
1,903✔
1279

1280
#ifdef WITHEXTERNALCHANNEL
1281
        AX.currentExternalChannel=0;
1,903✔
1282
        AX.killSignal=SIGKILL;
1,903✔
1283
        AX.killWholeGroup=1;
1,903✔
1284
        AX.daemonize=1;
1,903✔
1285
        AX.currentPrompt=0;
1,903✔
1286
        AX.timeout=1000;/*One second to initialize preset channels*/
1,903✔
1287
        AX.shellname=strDup1((UBYTE *)"/bin/sh -c","external channel shellname");
1,903✔
1288
        AX.stderrname=strDup1((UBYTE *)"/dev/null","external channel stderrname");
1,903✔
1289
#endif
1290
}
1,903✔
1291

1292
/*
1293
                 #] StartVariables : 
1294
                 #[ StartMore :
1295
*/
1296

1297
VOID StartMore(VOID)
1,903✔
1298
{
1299
#ifdef WITHEXTERNALCHANNEL
1300
        /*If env.variable "FORM_PIPES" is defined, we have to initialize 
1301
                corresponding pre-set external channels, see file extcmd.c.*/
1302
        /*This line must be after all setup settings: in future, timeout
1303
                could be changed at setup.*/
1304
        if(AX.timeout>=0)/*if AX.timeout<0, this was done by cmdline option -pipe*/
1,903✔
1305
                initPresetExternalChannels((UBYTE*)getenv("FORM_PIPES"),AX.timeout);
1,903✔
1306
#endif
1307

1308
#ifdef WITHMPI
1309
/*
1310
        Define preprocessor variable PARALLELTASK_ as a process number, 0 is the master
1311
        Define preprocessor variable NPARALLELTASKS_ as a total number of processes
1312
*/
1313
        {
1314
                UBYTE buf[32];
1,041✔
1315
                snprintf((char*)buf,32,"%d",PF.me);
1,041✔
1316
                PutPreVar((UBYTE *)"PARALLELTASK_",buf,0,0);
1,041✔
1317
                snprintf((char*)buf,32,"%d",PF.numtasks);
1,041✔
1318
                PutPreVar((UBYTE *)"NPARALLELTASKS_",buf,0,0);
1,041✔
1319
        }
1320
#else
1321
        PutPreVar((UBYTE *)"PARALLELTASK_",(UBYTE *)"0",0,0);
862✔
1322
        PutPreVar((UBYTE *)"NPARALLELTASKS_",(UBYTE *)"1",0,0);
862✔
1323
#endif
1324

1325
        PutPreVar((UBYTE *)"NAME_",AM.InputFileName ? AM.InputFileName : (UBYTE *)"STDIN",0,0);
3,806✔
1326
}
1,903✔
1327

1328
/*
1329
                 #] StartMore : 
1330
                 #[ IniVars :
1331

1332
                This routine initializes the parameters that may change during the run.
1333
*/
1334

1335
WORD IniVars(VOID)
1,896✔
1336
{
1337
#ifdef WITHPTHREADS
1338
        GETIDENTITY
572✔
1339
#else
1340
        WORD *t;
1,324✔
1341
#endif
1342
        WORD *fi, i, one = 1;
1,896✔
1343
        CBUF *C = cbuf+AC.cbufnum;
1,896✔
1344

1345
#ifdef WITHPTHREADS
1346
        UBYTE buf[32];
572✔
1347
        snprintf((char*)buf,32,"%d",AM.totalnumberofthreads);
572✔
1348
        PutPreVar((UBYTE *)"NTHREADS_",buf,0,1);
572✔
1349
#else
1350
        PutPreVar((UBYTE *)"NTHREADS_",(UBYTE *)"1",0,1);
1,324✔
1351
#endif
1352

1353
        AC.ShortStats = 0;
1,896✔
1354
        AC.WarnFlag = 1;
1,896✔
1355
        AR.SortType = AC.SortType = AC.lSortType = AM.gSortType;
1,896✔
1356
        AC.OutputMode = 72;
1,896✔
1357
        AC.OutputSpaces = NORMALFORMAT;
1,896✔
1358
        AR.Eside = 0;
1,896✔
1359
        AC.DumNum = 0;
1,896✔
1360
        AC.ncmod = AM.gncmod = 0;
1,896✔
1361
        AC.modmode = AM.gmodmode = 0;
1,896✔
1362
        AC.npowmod = AM.gnpowmod = 0;
1,896✔
1363
        AC.halfmod = 0; AC.nhalfmod = 0;
1,896✔
1364
        AC.modinverses = 0;
1,896✔
1365
        AC.lPolyFun = AM.gPolyFun = 0;
1,896✔
1366
        AC.lPolyFunInv = AM.gPolyFunInv = 0;
1,896✔
1367
        AC.lPolyFunType = AM.gPolyFunType = 0;
1,896✔
1368
        AC.lPolyFunExp = AM.gPolyFunExp = 0;
1,896✔
1369
        AC.lPolyFunVar = AM.gPolyFunVar = 0;
1,896✔
1370
        AC.lPolyFunPow = AM.gPolyFunPow = 0;
1,896✔
1371
        AC.DirtPow = 0;
1,896✔
1372
        AC.lDefDim = AM.gDefDim = 4;
1,896✔
1373
        AC.lDefDim4 = AM.gDefDim4 = 0;
1,896✔
1374
        AC.lUnitTrace = AM.gUnitTrace = 4;
1,896✔
1375
        AC.NamesFlag = AM.gNamesFlag = 0;
1,896✔
1376
        AC.CodesFlag = AM.gCodesFlag = 0;
1,896✔
1377
        AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols = 0;
1,896✔
1378
        AC.extrasym = (UBYTE *)Malloc1(2*sizeof(UBYTE),"extrasym");
1,896✔
1379
        AM.gextrasym = (UBYTE *)Malloc1(2*sizeof(UBYTE),"extrasym");
1,896✔
1380
        AM.ggextrasym = (UBYTE *)Malloc1(2*sizeof(UBYTE),"extrasym");
1,896✔
1381
        AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] = 'Z';
1,896✔
1382
        AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0;
1,896✔
1383
        AC.TokensWriteFlag = AM.gTokensWriteFlag = 0;
1,896✔
1384
        AC.SetupFlag = 0;
1,896✔
1385
        AC.LineLength = AM.gLineLength = 79;
1,896✔
1386
        AC.NwildC = 0;
1,896✔
1387
        AC.OutputMode = 0;
1,896✔
1388
        AM.gOutputMode = 0;
1,896✔
1389
        AC.OutputSpaces = NORMALFORMAT;
1,896✔
1390
        AM.gOutputSpaces = NORMALFORMAT;
1,896✔
1391
        AC.OutNumberType = RATIONALMODE;
1,896✔
1392
        AM.gOutNumberType = RATIONALMODE;
1,896✔
1393
#ifdef WITHZLIB
1394
        AR.gzipCompress = GZIPDEFAULT;
1,896✔
1395
        AR.FoStage4[0].ziobuffer = 0;
1,896✔
1396
        AR.FoStage4[1].ziobuffer = 0;
1,896✔
1397
#endif
1398
        AR.BracketOn = 0;
1,896✔
1399
        AC.bracketindexflag = 0;
1,896✔
1400
        AT.bracketindexflag = 0;
1,896✔
1401
        AT.bracketinfo = 0;
1,896✔
1402
        AO.IsBracket = 0;
1,896✔
1403
        AM.gfunpowers = AC.funpowers = COMFUNPOWERS;
1,896✔
1404
        AC.parallelflag = AM.gparallelflag;
1,896✔
1405
        AC.properorderflag = AM.gproperorderflag = PROPERORDERFLAG;
1,896✔
1406
        AC.ProcessBucketSize = AC.mProcessBucketSize = AM.gProcessBucketSize;
1,896✔
1407
    AC.ThreadBucketSize = AM.gThreadBucketSize;
1,896✔
1408
        AC.ShortStatsMax = 0;
1,896✔
1409
        AM.gShortStatsMax = 0;
1,896✔
1410
        AM.ggShortStatsMax = 0;
1,896✔
1411

1412
        GlobalSymbols     = NumSymbols;
1,896✔
1413
        GlobalIndices     = NumIndices;
1,896✔
1414
        GlobalVectors     = NumVectors;
1,896✔
1415
        GlobalFunctions   = NumFunctions;
1,896✔
1416
        GlobalSets        = NumSets;
1,896✔
1417
        GlobalSetElements = NumSetElements;
1,896✔
1418
        AC.modpowers = (UWORD *)0;
1,896✔
1419

1420
        i = AM.OffsetIndex;
1,896✔
1421
        fi = AC.FixIndices;
1,896✔
1422
        if ( i > 0 ) do { *fi++ = one; } while ( --i >= 0 );
248,376✔
1423
        AR.sLevel = -1;
1,896✔
1424
        AM.Ordering[0] = 5;
1,896✔
1425
        AM.Ordering[1] = 6;
1,896✔
1426
        AM.Ordering[2] = 7;
1,896✔
1427
        AM.Ordering[3] = 0;
1,896✔
1428
        AM.Ordering[4] = 1;
1,896✔
1429
        AM.Ordering[5] = 2;
1,896✔
1430
        AM.Ordering[6] = 3;
1,896✔
1431
        AM.Ordering[7] = 4;
1,896✔
1432
        for ( i = 8; i < 15; i++ ) AM.Ordering[i] = i;
15,168✔
1433
        AM.gUniTrace[0] = 
1,896✔
1434
        AC.lUniTrace[0] = SNUMBER;
1,896✔
1435
        AM.gUniTrace[1] = 
1,896✔
1436
        AC.lUniTrace[1] = 
1,896✔
1437
        AM.gUniTrace[2] = 
1,896✔
1438
        AC.lUniTrace[2] = 4;
1,896✔
1439
        AM.gUniTrace[3] = 
1,896✔
1440
        AC.lUniTrace[3] = 1;
1,896✔
1441
#ifdef WITHPTHREADS
1442
        AS.Balancing = 0;
572✔
1443
#else
1444
        AT.MinVecArg[0] = 7+ARGHEAD;
1,324✔
1445
        AT.MinVecArg[ARGHEAD] = 7;
1,324✔
1446
        AT.MinVecArg[1+ARGHEAD] = INDEX;
1,324✔
1447
        AT.MinVecArg[2+ARGHEAD] = 3;
1,324✔
1448
        AT.MinVecArg[3+ARGHEAD] = 0;
1,324✔
1449
        AT.MinVecArg[4+ARGHEAD] = 1;
1,324✔
1450
        AT.MinVecArg[5+ARGHEAD] = 1;
1,324✔
1451
        AT.MinVecArg[6+ARGHEAD] = -3;
1,324✔
1452
        t = AT.FunArg;
1,324✔
1453
        *t++ = 4+ARGHEAD+FUNHEAD;
1,324✔
1454
        for ( i = 1; i < ARGHEAD; i++ ) *t++ = 0;
2,648✔
1455
        *t++ = 4+FUNHEAD;
1,324✔
1456
        *t++ = 0;
1,324✔
1457
        *t++ = FUNHEAD;
1,324✔
1458
        for ( i = 2; i < FUNHEAD; i++ ) *t++ = 0;
2,648✔
1459
        *t++ = 1; *t++ = 1; *t++ = 3;
1,324✔
1460

1461
#ifdef WITHMPI
1462
        AS.printflag = 0;
1,037✔
1463
#endif
1464

1465
        AT.comsym[0] = 8;
1,324✔
1466
        AT.comsym[1] = SYMBOL;
1,324✔
1467
        AT.comsym[2] = 4;
1,324✔
1468
        AT.comsym[3] = 0;
1,324✔
1469
        AT.comsym[4] = 1;
1,324✔
1470
        AT.comsym[5] = 1;
1,324✔
1471
        AT.comsym[6] = 1;
1,324✔
1472
        AT.comsym[7] = 3;
1,324✔
1473
        AT.comnum[0] = 4;
1,324✔
1474
        AT.comnum[1] = 1;
1,324✔
1475
        AT.comnum[2] = 1;
1,324✔
1476
        AT.comnum[3] = 3;
1,324✔
1477
        AT.comfun[0] = FUNHEAD+4;
1,324✔
1478
        AT.comfun[1] = FUNCTION;
1,324✔
1479
        AT.comfun[2] = FUNHEAD;
1,324✔
1480
        AT.comfun[3] = 0;
1,324✔
1481
#if FUNHEAD == 4
1482
        AT.comfun[4] = 0;
1483
#endif
1484
        AT.comfun[FUNHEAD+1] = 1;
1,324✔
1485
        AT.comfun[FUNHEAD+2] = 1;
1,324✔
1486
        AT.comfun[FUNHEAD+3] = 3;
1,324✔
1487
        AT.comind[0] = 7;
1,324✔
1488
        AT.comind[1] = INDEX;
1,324✔
1489
        AT.comind[2] = 3;
1,324✔
1490
        AT.comind[3] = 0;
1,324✔
1491
        AT.comind[4] = 1;
1,324✔
1492
        AT.comind[5] = 1;
1,324✔
1493
        AT.comind[6] = 3;
1,324✔
1494
        AT.locwildvalue[0] = SUBEXPRESSION;
1,324✔
1495
        AT.locwildvalue[1] = SUBEXPSIZE;
1,324✔
1496
        for ( i = 2; i < SUBEXPSIZE; i++ ) AT.locwildvalue[i] = 0;
5,296✔
1497
        AT.mulpat[0] = TYPEMULT;
1,324✔
1498
        AT.mulpat[1] = SUBEXPSIZE+3;
1,324✔
1499
        AT.mulpat[2] = 0;
1,324✔
1500
        AT.mulpat[3] = SUBEXPRESSION;
1,324✔
1501
        AT.mulpat[4] = SUBEXPSIZE;
1,324✔
1502
        AT.mulpat[5] = 0;
1,324✔
1503
        AT.mulpat[6] = 1;
1,324✔
1504
        for ( i = 7; i < SUBEXPSIZE+5; i++ ) AT.mulpat[i] = 0;
5,296✔
1505
        AT.proexp[0] = SUBEXPSIZE+4;
1,324✔
1506
        AT.proexp[1] = EXPRESSION;
1,324✔
1507
        AT.proexp[2] = SUBEXPSIZE;
1,324✔
1508
        AT.proexp[3] = -1;
1,324✔
1509
        AT.proexp[4] = 1;
1,324✔
1510
        for ( i = 5; i < SUBEXPSIZE+1; i++ ) AT.proexp[i] = 0;
2,648✔
1511
        AT.proexp[SUBEXPSIZE+1] = 1;
1,324✔
1512
        AT.proexp[SUBEXPSIZE+2] = 1;
1,324✔
1513
        AT.proexp[SUBEXPSIZE+3] = 3;
1,324✔
1514
        AT.proexp[SUBEXPSIZE+4] = 0;
1,324✔
1515
        AT.dummysubexp[0] = SUBEXPRESSION;
1,324✔
1516
        AT.dummysubexp[1] = SUBEXPSIZE+4;
1,324✔
1517
        for ( i = 2; i < SUBEXPSIZE; i++ ) AT.dummysubexp[i] = 0;
5,296✔
1518
        AT.dummysubexp[SUBEXPSIZE] = WILDDUMMY;
1,324✔
1519
        AT.dummysubexp[SUBEXPSIZE+1] = 4;
1,324✔
1520
        AT.dummysubexp[SUBEXPSIZE+2] = 0;
1,324✔
1521
        AT.dummysubexp[SUBEXPSIZE+3] = 0;
1,324✔
1522

1523
        AT.inprimelist = -1;
1,324✔
1524
        AT.sizeprimelist = 0;
1,324✔
1525
        AT.primelist = 0;
1,324✔
1526
        AT.LeaveNegative = 0;
1,324✔
1527
        AT.TrimPower = 0;
1,324✔
1528
        AN.SplitScratch = 0;
1,324✔
1529
        AN.SplitScratchSize = AN.InScratch = 0;
1,324✔
1530
        AN.SplitScratch1 = 0;
1,324✔
1531
        AN.SplitScratchSize1 = AN.InScratch1 = 0;
1,324✔
1532
        AN.idfunctionflag = 0;
1,324✔
1533
#endif
1534
        AO.OutputLine = AO.OutFill = BufferForOutput;
1,896✔
1535
        AO.FactorMode = 0;
1,896✔
1536
        C->Pointer = C->Buffer;
1,896✔
1537

1538
        AP.PreOut = 0;
1,896✔
1539
        AP.ComChar = AP.cComChar;
1,896✔
1540
        AC.cbufnum = AM.rbufnum;                /* Select the default compiler buffer */
1,896✔
1541
        AC.HideLevel = 0;
1,896✔
1542
        AP.PreAssignFlag = 0;
1,896✔
1543
        return(0);
1,896✔
1544
}
1545

1546
/*
1547
                 #] IniVars : 
1548
                 #[ Signal handlers :
1549
*/
1550
/*[28apr2004 mt]:*/
1551
#ifdef TRAPSIGNALS
1552

1553
static int exitInProgress = 0;
1554
static int trappedTerminate = 0;
1555

1556
/*INTSIGHANDLER : some systems require a signal handler to return an integer,
1557
  so define the macro INTSIGHANDLER if compiler fails:*/
1558
#ifdef INTSIGHANDLER
1559
static int onErrSig(int i)
1560
#else
1561
static VOID onErrSig(int i)
139✔
1562
#endif
1563
{
1564
        if (exitInProgress){
139✔
1565
                signal(i,SIG_DFL);/* Use default behaviour*/
×
1566
                raise (i);/*reproduce trapped signal*/
×
1567
#ifdef INTSIGHANDLER
1568
                return(i);
1569
#else
1570
                return;
×
1571
#endif
1572
        }
1573
        trappedTerminate = 1;
139✔
1574
        /*[13jul2005 mt]*//*Terminate(-1) on signal is here:*/
1575
        Terminate(-1);
139✔
1576
}
1577

1578
#ifdef INTSIGHANDLER
1579
static VOID setNewSig(int i, int (*handler)(int))
1580
#else
1581
static VOID setNewSig(int i, void (*handler)(int))
28,545✔
1582
#endif
1583
{
1584
        if(! (i<NSIG) )/* Invalid signal -- see comments in the file */
28,545✔
1585
                return;
1586
        if ( signal(i,SIG_IGN) !=SIG_IGN)
24,739✔
1587
        /* if compiler fails here, try to define INTSIGHANDLER):*/
1588
                signal(i,handler);
24,739✔
1589
}
1590

1591
VOID setSignalHandlers(VOID)
1,903✔
1592
{
1593
        /* Reset various unrecoverable error signals:*/
1594
        setNewSig(SIGSEGV,onErrSig);
1,903✔
1595
        setNewSig(SIGFPE,onErrSig);
1,903✔
1596
        setNewSig(SIGILL,onErrSig);
1,903✔
1597
        setNewSig(SIGEMT,onErrSig);
1,903✔
1598
        setNewSig(SIGSYS,onErrSig);
1,903✔
1599
        setNewSig(SIGPIPE,onErrSig);
1,903✔
1600
        setNewSig(SIGLOST,onErrSig);
1,903✔
1601
        setNewSig(SIGXCPU,onErrSig);
1,903✔
1602
        setNewSig(SIGXFSZ,onErrSig);
1,903✔
1603

1604
        /* Reset interrupt signals:*/
1605
        setNewSig(SIGTERM,onErrSig);
1,903✔
1606
        setNewSig(SIGINT,onErrSig);
1,903✔
1607
        setNewSig(SIGQUIT,onErrSig);
1,903✔
1608
        setNewSig(SIGHUP,onErrSig);
1,903✔
1609
        setNewSig(SIGALRM,onErrSig);
1,903✔
1610
        setNewSig(SIGVTALRM,onErrSig);
1,903✔
1611
/*        setNewSig(SIGPROF,onErrSig); */  /* Why did Tentukov forbid profilers?? */
1612
}
1,903✔
1613

1614
#endif
1615
/*:[28apr2004 mt]*/
1616
/*
1617
                 #] Signal handlers : 
1618
                 #[ main :
1619
*/
1620

1621
#ifdef WITHPTHREADS
1622
ALLPRIVATES *ABdummy[10];
1623
#endif
1624

1625
int main(int argc, char **argv)
1,903✔
1626
{
1627
        int retval;
1,903✔
1628
        bzero((VOID *)(&A),sizeof(A)); /* make sure A is initialized at zero */
1,903✔
1629
        iniTools();
1,903✔
1630
#ifdef TRAPSIGNALS
1631
        setSignalHandlers();
1,903✔
1632
#endif
1633
#ifdef WINDOWS
1634
        _setmode(_fileno(stdout),O_BINARY);
1635
#endif
1636

1637
#ifdef WITHPTHREADS
1638
        AB = ABdummy;
574✔
1639
        StartHandleLock();
574✔
1640
        BeginIdentities();
574✔
1641
#else
1642
        AM.SumTime = TimeCPU(0);
1,329✔
1643
        TimeWallClock(0);
1,329✔
1644
#endif
1645

1646
#ifdef WITHMPI
1647
        if ( PF_Init(&argc,&argv) ) exit(-1);
1,041✔
1648
#endif
1649

1650
        StartFiles();
1,903✔
1651
        StartVariables();
1,903✔
1652
#ifdef WITHMPI
1653
        /*
1654
         * Here MesPrint() is ready. We turn on AS.printflag to print possible
1655
         * errors occurring on slaves in the initialization. With AS.printflag = -1
1656
         * MesPrint() does not use the synchronized output. This may lead broken
1657
         * texts in the output somewhat, but it is safer to implement in this way
1658
         * for the situation in which some of MesPrint() calls use MLOCK()-MUNLOCK()
1659
         * and some do not. In future if we set AS.printflag = 1 and modify the
1660
         * source code such that all MesPrint() calls are sandwiched by MLOCK()-
1661
         * MUNLOCK(), we need also to modify the code for the master to catch
1662
         * messages corresponding to MUNLOCK() calls at some point.
1663
         *
1664
         * AS.printflag will be set to 0 in IniVars() to prevent slaves from
1665
         * printing redundant errors in the preprocessor and compiler (e.g., syntax
1666
         * errors).
1667
         */
1668
        AS.printflag = -1;
1,041✔
1669
#endif
1670

1671
        if ( ( retval = DoTail(argc,(UBYTE **)argv) ) != 0 ) {
1,903✔
1672
                if ( retval > 0 ) Terminate(0);
×
1673
                else              Terminate(-1);
×
1674
        }
1675
        if ( DoSetups() ) Terminate(-2);
1,903✔
1676
#ifdef WITHMPI
1677
        /* It is messy if all errors in OpenInput() on slaves are printed. */
1678
        AS.printflag = 0;
1,041✔
1679
#endif
1680
        if ( OpenInput() ) Terminate(-3);
1,903✔
1681
#ifdef WITHMPI
1682
        AS.printflag = -1;
1,041✔
1683
#endif
1684
        if ( TryEnvironment() ) Terminate(-2);
1,903✔
1685
        if ( TryFileSetups() ) Terminate(-2);
1,903✔
1686
        if ( MakeSetupAllocs() ) Terminate(-2);
1,903✔
1687
        StartMore();
1,903✔
1688
        InitRecovery();
1,903✔
1689
        CheckRecoveryFile();
1,903✔
1690
        if ( AM.totalnumberofthreads == 0 ) AM.totalnumberofthreads = 1;
1,903✔
1691
        AS.MultiThreaded = 0;
1,903✔
1692
#ifdef WITHPTHREADS
1693
        if ( AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1;
574✔
1694
        ReserveTempFiles(1);
574✔
1695
        StartAllThreads(AM.totalnumberofthreads);
572✔
1696
        IniFbufs();
572✔
1697
#else
1698
        ReserveTempFiles(0);
1,329✔
1699
        IniFbuffer(AT.fbufnum);
1,324✔
1700
#endif
1701
        if ( !AM.FromStdin ) PrintHeader(1);
1,896✔
1702
        IniVars();
1,896✔
1703
        Globalize(1);
1,896✔
1704
#ifdef WITH_ALARM
1705
        if ( AM.TimeLimit > 0 ) alarm(AM.TimeLimit);
1,896✔
1706
#endif
1707
        TimeCPU(0);
1,896✔
1708
        TimeChildren(0);
1,896✔
1709
        TimeWallClock(0);
1,896✔
1710
        PreProcessor();
1,896✔
1711
        Terminate(0);
×
1712
        return(0);
1713
}
1714
/*
1715
                 #] main : 
1716
                 #[ CleanUp :
1717

1718
                if par < 0 we have to keep the storage file.
1719
                when par > 0 we ran into a .clear statement.
1720
                In that case we keep the zero level input and the log file.
1721

1722
*/
1723

1724
VOID CleanUp(WORD par)
×
1725
{
1726
        GETIDENTITY
1727
        int i;
×
1728

1729
        if ( FG.fname ) {
×
1730
        CleanUpSort(0);
×
1731
        for ( i = 0; i < 3; i++ ) {
×
1732
                if ( AR.Fscr[i].handle >= 0 ) {
×
1733
                        if ( AR.Fscr[i].name ) {
×
1734
/*
1735
                                If there are more threads referring to the same file
1736
                                only the one with the name is the owner of the file.
1737
*/
1738
                                CloseFile(AR.Fscr[i].handle);
×
1739
                                remove(AR.Fscr[i].name);
×
1740
                        }
1741
                        AR.Fscr[i].handle = - 1;
×
1742
                        AR.Fscr[i].POfill = 0;
×
1743
                }
1744
        }
1745
        if ( par > 0 ) {
×
1746
/*
1747
        Close all input levels above the lowest?
1748
*/
1749
        }
×
1750
        if ( AC.StoreHandle >= 0 && par <= 0 ) {
×
1751
#ifdef TRAPSIGNALS
1752
                if ( trappedTerminate ) { /* We don't throw .str if it has contents */
×
1753
                        POSITION pos;
×
1754
                        PUTZERO(pos);
×
1755
                        SeekFile(AC.StoreHandle,&pos,SEEK_END);
×
1756
                        if ( ISNOTZEROPOS(pos) ) {
×
1757
                                CloseFile(AC.StoreHandle);
×
1758
                                goto dontremove;
×
1759
                        }
1760
                }
1761
                CloseFile(AC.StoreHandle);
×
1762
                if ( par >= 0 || AR.StoreData.Handle < 0 || AM.ClearStore ) {
×
1763
                        remove(FG.fname);
×
1764
                }
1765
dontremove:;
×
1766
#else
1767
                CloseFile(AC.StoreHandle);
1768
                if ( par >= 0 || AR.StoreData.Handle < 0 || AM.ClearStore > 0 ) {
1769
                        remove(FG.fname);
1770
                }
1771
#endif
1772
        }
1773
        }
1774
        ClearSpectators(CLEARMODULE);
×
1775
/*
1776
        Remove recovery file on exit if everything went well
1777
*/
1778
        if ( par == 0 ) {
×
1779
                DeleteRecoveryFile();
×
1780
        }
1781
/*
1782
        Now the final message concerning the total time
1783
*/
1784
        if ( AC.LogHandle >= 0 && par <= 0 ) {
×
1785
                WORD lh = AC.LogHandle;
×
1786
                AC.LogHandle = -1;
×
1787
#ifdef WITHMPI
1788
                if ( PF.me == MASTER )  /* Only the master opened the real file. */
1789
#endif
1790
                CloseFile(lh);
×
1791
        }
1792
}
×
1793

1794
/*
1795
                 #] CleanUp : 
1796
                 #[ Terminate :
1797
*/
1798

1799
static int firstterminate = 1;
1800

1801
VOID Terminate(int errorcode)
2,039✔
1802
{
1803
        if ( errorcode && firstterminate ) {
2,039✔
1804
                firstterminate = 0;
136✔
1805
#ifdef WITHPTHREADS
1806
                MesPrint("Program terminating in thread %w at &");
64✔
1807
#elif defined(WITHMPI)
1808
                MesPrint("Program terminating in process %w at &");
40✔
1809
#else
1810
                MesPrint("Program terminating at &");
32✔
1811
#endif
1812
                Crash();
136✔
1813
        }
1814
#ifdef TRAPSIGNALS
1815
        exitInProgress=1;
1,903✔
1816
#endif
1817
#ifdef WITHEXTERNALCHANNEL
1818
/*
1819
        This function can be called from the error handler, so it is better to
1820
        clean up all started processes before any activity:
1821
*/
1822
        closeAllExternalChannels();
1,903✔
1823
        AX.currentExternalChannel=0;
1,903✔
1824
        /*[08may2006 mt]:*/
1825
        AX.killSignal=SIGKILL;
1,903✔
1826
        AX.killWholeGroup=1;
1,903✔
1827
        AX.daemonize=1;
1,903✔
1828
        /*:[08may2006 mt]*/
1829
        if(AX.currentPrompt){
1,903✔
1830
                M_free(AX.currentPrompt,"external channel prompt");
7✔
1831
                AX.currentPrompt=0;
7✔
1832
        }
1833
        /*[08may2006 mt]:*/
1834
        if(AX.shellname){
1,903✔
1835
                M_free(AX.shellname,"external channel shellname");
1,903✔
1836
                AX.shellname=0;
1,903✔
1837
        }
1838
        if(AX.stderrname){
1,903✔
1839
                M_free(AX.stderrname,"external channel stderrname");
1,903✔
1840
                AX.stderrname=0;
1,903✔
1841
        }
1842
        /*:[08may2006 mt]*/
1843
#endif
1844
#ifdef WITHPTHREADS
1845
        if ( !WhoAmI() && !errorcode ) {
574✔
1846
                TerminateAllThreads();
510✔
1847
        }
1848
#endif
1849
        if ( AC.FinalStats ) {
1,903✔
1850
                if ( AM.PrintTotalSize ) {
1,892✔
1851
                        MesPrint("Max. space for expressions: %19p bytes",&(AS.MaxExprSize));
×
1852
                }
1853
                PrintRunningTime();
1,892✔
1854
        }
1855
#ifdef WITHMPI
1856
        if ( AM.HoldFlag && PF.me == MASTER ) {
1,041✔
1857
                WriteFile(AM.StdOut,(UBYTE *)("Hit any key "),12);
1858
                PF_FlushStdOutBuffer();
1859
                getchar();
1860
        }
1861
#else
1862
        if ( AM.HoldFlag ) {
862✔
1863
                WriteFile(AM.StdOut,(UBYTE *)("Hit any key "),12);
1864
                getchar();
1865
        }
1866
#endif
1867
#ifdef WITHMPI
1868
        PF_Terminate(errorcode);
1,041✔
1869
#endif
1870
        //CleanUp(errorcode);
1871
        M_print();
1,903✔
1872
#ifdef VMS
1873
        P_term(errorcode? 0: 1);
1874
#else
1875
        P_term(errorcode);
1,903✔
1876
#endif
1877
}
1878

1879
/*
1880
                 #] Terminate : 
1881
                 #[ PrintRunningTime :
1882
*/
1883

1884
VOID PrintRunningTime(VOID)
1,948✔
1885
{
1886
#if (defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))) || defined(WITHMPI)
1887
        LONG mastertime;
1,654✔
1888
        LONG workertime;
1,654✔
1889
        LONG wallclocktime;
1,654✔
1890
        LONG totaltime;
1,654✔
1891
#if defined(WITHPTHREADS)
1892
        if ( AB[0] != 0 ) {
586✔
1893
                workertime = GetWorkerTimes();
584✔
1894
#else
1895
        workertime = PF_GetSlaveTimes();  /* must be called on all processors */
1,068✔
1896
        if ( PF.me == MASTER ) {
1,068✔
1897
#endif
1898
                mastertime = AM.SumTime + TimeCPU(1);
851✔
1899
                wallclocktime = TimeWallClock(1);
851✔
1900
                totaltime = mastertime+workertime;
851✔
1901
                if ( !AM.silent ) {
851✔
1902
                MesPrint("  %l.%2i sec + %l.%2i sec: %l.%2i sec out of %l.%2i sec",
851✔
1903
                        mastertime/1000,(WORD)((mastertime%1000)/10),
851✔
1904
                        workertime/1000,(WORD)((workertime%1000)/10),
851✔
1905
                        totaltime/1000,(WORD)((totaltime%1000)/10),
851✔
1906
                        wallclocktime/100,(WORD)(wallclocktime%100));
851✔
1907
                }
1908
        }
1909
#else
1910
        LONG mastertime = AM.SumTime + TimeCPU(1);
294✔
1911
        LONG wallclocktime = TimeWallClock(1);
294✔
1912
        if ( !AM.silent ) {
294✔
1913
        MesPrint("  %l.%2i sec out of %l.%2i sec",
294✔
1914
                mastertime/1000,(WORD)((mastertime%1000)/10),
294✔
1915
                wallclocktime/100,(WORD)(wallclocktime%100));
294✔
1916
        }
1917
#endif
1918
}
1,948✔
1919

1920
/*
1921
                 #] PrintRunningTime : 
1922
                 #[ GetRunningTime :
1923
*/
1924

1925
LONG GetRunningTime(VOID)
1,896✔
1926
{
1927
#if defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))
1928
        LONG mastertime;
572✔
1929
        if ( AB[0] != 0 ) {
572✔
1930
/* 
1931
#if ( defined(APPLE64) || defined(APPLE32) )
1932
                mastertime = AM.SumTime + TimeCPU(1);
1933
                return(mastertime);
1934
#else
1935
*/
1936
                LONG workertime = GetWorkerTimes();
572✔
1937
                mastertime = AM.SumTime + TimeCPU(1);
572✔
1938
                return(mastertime+workertime);
572✔
1939
/*
1940
#endif
1941
*/
1942
        }
1943
        else {
1944
                return(AM.SumTime + TimeCPU(1));
1945
        }
1946
#elif defined(WITHMPI)
1947
        LONG mastertime, t = 0;
1,037✔
1948
        LONG workertime = PF_GetSlaveTimes();  /* must be called on all processors */
1,037✔
1949
        if ( PF.me == MASTER ) {
1,037✔
1950
                mastertime = AM.SumTime + TimeCPU(1);
260✔
1951
                t = mastertime + workertime;
260✔
1952
        }
1953
        return PF_BroadcastNumber(t);  /* must be called on all processors */
1,037✔
1954
#else
1955
        return(AM.SumTime + TimeCPU(1));
287✔
1956
#endif
1957
}
1958

1959
/*
1960
                 #] GetRunningTime : 
1961
*/
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