forked from vermaseren/form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartup.c
1898 lines (1809 loc) · 51.4 KB
/
startup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file startup.c
*
* This file contains the main program.
* It also deals with the very early stages of the startup of FORM
* and the final stages when the program attemps some cleanup.
* Here is the routine that analyses the command tail.
*/
/* #[ License : */
/*
* Copyright (C) 1984-2022 J.A.M. Vermaseren
* When using this file you are requested to refer to the publication
* J.A.M.Vermaseren "New features of FORM" math-ph/0010025
* This is considered a matter of courtesy as the development was paid
* for by FOM the Dutch physics granting agency and we would like to
* be able to track its scientific use to convince FOM of its value
* for the community.
*
* This file is part of FORM.
*
* FORM is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* FORM is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with FORM. If not, see <http://www.gnu.org/licenses/>.
*/
/* #] License : */
/*
#[ includes :
*/
#include "form3.h"
#include "inivar.h"
#ifdef TRAPSIGNALS
#include "portsignals.h"
#else
#include <signal.h>
#endif
/*
* A macro for translating the contents of `x' into a string after expanding.
*/
#define STRINGIFY(x) STRINGIFY__(x)
#define STRINGIFY__(x) #x
/*
* FORMNAME = "FORM" or "TFORM" or "ParFORM".
*/
#if defined(WITHPTHREADS)
#define FORMNAME "TFORM"
#elif defined(WITHMPI)
#define FORMNAME "ParFORM"
#else
#define FORMNAME "FORM"
#endif
/*
* VERSIONSTR is the version information printed in the header line.
*/
#ifdef HAVE_CONFIG_H
/* We have also version.h. */
#include "version.h"
#ifndef REPO_VERSION
#define REPO_VERSION STRINGIFY(REPO_MAJOR_VERSION) "." STRINGIFY(REPO_MINOR_VERSION)
#endif
#ifndef REPO_DATE
/* The build date, instead of the repo date. */
#define REPO_DATE __DATE__
#endif
#ifdef REPO_REVISION
#define VERSIONSTR FORMNAME " " REPO_VERSION " (" REPO_DATE ", " REPO_REVISION ")"
#else
#define VERSIONSTR FORMNAME " " REPO_VERSION " (" REPO_DATE ")"
#endif
#define MAJORVERSION REPO_MAJOR_VERSION
#define MINORVERSION REPO_MINOR_VERSION
#else
/*
* Otherwise, form3.h defines MAJORVERSION, MINORVERSION and PRODUCTIONDATE,
* possibly BETAVERSION.
*/
#ifdef BETAVERSION
#define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION) "Beta"
#else
#define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION)
#endif
#define VERSIONSTR FORMNAME " " VERSIONSTR__ " (" PRODUCTIONDATE ")"
#endif
/*
#] includes :
#[ PrintHeader :
*/
/**
* Prints the header line of the output.
*
* @param with_full_info True for printing also runtime information.
*/
static void PrintHeader(int with_full_info)
{
#ifdef WITHMPI
if ( PF.me == MASTER && !AM.silent ) {
#else
if ( !AM.silent ) {
#endif
char buffer1[250], buffer2[80], *s = buffer1, *t = buffer2;
WORD length, n;
for ( n = 0; n < 250; n++ ) buffer1[n] = ' ';
/*
* NOTE: we expect that the compiler optimizes strlen("string literal")
* to just a number.
*/
if ( strlen(VERSIONSTR) <= 100 ) {
strcpy(s,VERSIONSTR);
s += strlen(VERSIONSTR);
*s = 0;
}
else {
/*
* Truncate when it is too long.
*/
strncpy(s,VERSIONSTR,97);
s[97] = '.';
s[98] = '.';
s[99] = ')';
s[100] = '\0';
s += 100;
}
s += sprintf(s," %d-bits",(WORD)(sizeof(WORD)*16));
/* while ( *s ) s++; */
*s = 0;
if ( with_full_info ) {
#if defined(WITHPTHREADS) || defined(WITHMPI)
#if defined(WITHPTHREADS)
int nworkers = AM.totalnumberofthreads-1;
#elif defined(WITHMPI)
int nworkers = PF.numtasks-1;
#endif
s += sprintf(s," %d worker",nworkers);
*s = 0;
/* while ( *s ) s++; */
if ( nworkers != 1 ) {
*s++ = 's';
*s = '\0';
}
#endif
sprintf(t,"Run: %s",MakeDate());
while ( *t ) t++;
/*
* Align the date to the right, if it fits in a line.
*/
length = (s-buffer1) + (t-buffer2);
if ( length+2 <= AC.LineLength ) {
for ( n = AC.LineLength-length; n > 0; n-- ) *s++ = ' ';
*s = 0;
strcat(s,buffer2);
while ( *s ) s++;
}
else {
*s = 0;
strcat(s," ");
while ( *s ) s++;
*s = 0;
strcat(s,buffer2);
while ( *s ) s++;
}
}
/*
* If the header information doesn't fit in a line, we need to extend
* the line length temporarily.
*/
length = s-buffer1;
if ( length <= AC.LineLength ) {
MesPrint("%s",buffer1);
}
else {
WORD oldLineLength = AC.LineLength;
AC.LineLength = length;
MesPrint("%s",buffer1);
AC.LineLength = oldLineLength;
}
}
}
/*
#] PrintHeader :
#[ DoTail :
Routine reads the command tail and handles the commandline options.
It sets the flags for later actions and stored pathnames for
the setup file, include/prc/sub directories etc.
Finally the name of the program is passed on.
Note that we do not support interactive use yet. This will come
to pass in the distant future when we can couple STedi to FORM.
Routine made 23-feb-1993 by J.Vermaseren
*/
#ifdef WITHINTERACTION
static UBYTE deflogname[] = "formsession.log";
#endif
#define TAKEPATH(x) if(s[1]== '=' ){x=s+2;} else{x=*argv++;argc--;}
int DoTail(int argc, UBYTE **argv)
{
int errorflag = 0, onlyversion = 1;
UBYTE *s, *t, *copy;
int threadnum = 0;
argc--; argv++;
AM.ClearStore = 0;
AM.TimeLimit = 0;
AM.LogType = -1;
AM.HoldFlag = AM.qError = AM.Interact = AM.FileOnlyFlag = 0;
AM.InputFileName = AM.LogFileName = AM.IncDir = AM.TempDir = AM.TempSortDir =
AM.SetupDir = AM.SetupFile = AM.Path = 0;
AM.FromStdin = 0;
if ( argc < 1 ) {
onlyversion = 0;
goto printversion;
}
while ( argc >= 1 ) {
s = *argv++; argc--;
if ( *s == '-' || ( *s == '/' && ( argc > 0 || AM.Interact ) ) ) {
s++;
switch (*s) {
case 'c': /* Error checking only */
AM.qError = 1; break;
case 'C': /* Next arg is filename of log file */
TAKEPATH(AM.LogFileName) break;
case 'D':
case 'd': /* Next arg is define preprocessor var. */
t = copy = strDup1(*argv,"Dotail");
while ( *t && *t != '=' ) t++;
if ( *t == 0 ) {
if ( PutPreVar(copy,(UBYTE *)"1",0,0) < 0 ) return(-1);
}
else {
*t++ = 0;
if ( PutPreVar(copy,t,0,0) < 0 ) return(-1);
t[-1] = '=';
}
M_free(copy,"-d prevar");
argv++; argc--; break;
case 'f': /* Output only to regular log file */
AM.FileOnlyFlag = 1; AM.LogType = 0; break;
case 'F': /* Output only to log file. Further like L. */
AM.FileOnlyFlag = 1; AM.LogType = 1; break;
case 'h': /* For old systems: wait for key before exit */
AM.HoldFlag = 1; break;
#ifdef WITHINTERACTION
case 'i': /* Interactive session (not used yet) */
AM.Interact = 1; break;
#endif
case 'I': /* Next arg is dir for inc/prc/sub files */
TAKEPATH(AM.IncDir) break;
case 'l': /* Make regular log file */
if ( s[1] == 'l' ) AM.LogType = 1; /*compatibility! */
else AM.LogType = 0;
break;
case 'L': /* Make log file with only final statistics */
AM.LogType = 1; break;
case 'M': /* Multirun. Name of tempfiles will contain PID */
AM.MultiRun = 1;
break;
case 'm': /* Read number of threads */
case 'w': /* Read number of workers */
t = s++;
threadnum = 0;
while ( *s >= '0' && *s <= '9' )
threadnum = 10*threadnum + *s++ - '0';
if ( *s ) {
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("Illegal value for option m or w: %s\n",t);
errorflag++;
}
/* if ( threadnum == 1 ) threadnum = 0; */
threadnum++;
break;
case 'W': /* Print the wall-clock time on the master. */
AM.ggWTimeStatsFlag = 1;
break;
/*
case 'n':
Reserved for number of slaves without MPI
*/
case 'p':
#ifdef WITHEXTERNALCHANNEL
/*There are two possibilities: -p|-pipe*/
if(s[1]=='i'){
if( (s[2]=='p')&&(s[3]=='e')&&(s[4]=='\0') ){
argc--;
/*Initialize pre-set external channels, see
the file extcmd.c:*/
if(initPresetExternalChannels(*argv++,AX.timeout)<1){
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("Error initializing preset external channels\n");
errorflag++;
}
AX.timeout=-1;/*This indicates that preset channels
are initialized from cmdline*/
}else{
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("Illegal option in call of FORM: %s\n",s);
errorflag++;
}
}else
#else
if ( s[1] ) {
if ( ( s[1]=='i' ) && ( s[2] == 'p' ) && (s[3] == 'e' )
&& ( s[4] == '\0' ) ){
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("Illegal option: Pipes not supported on this system.\n");
}
else {
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("Illegal option: %s\n",s);
}
errorflag++;
}
else
#endif
{
/* Next arg is a path variable like in environment */
TAKEPATH(AM.Path)
}
break;
case 'q': /* Quiet option. Only output. Same as -si */
AM.silent = 1; break;
case 'R': /* recover from saved snapshot */
AC.CheckpointFlag = -1;
break;
case 's': /* Next arg is dir with form.set to be used */
if ( ( s[1] == 'o' ) && ( s[2] == 'r' ) && ( s[3] == 't' ) ) {
if(s[4]== '=' ) {
AM.TempSortDir = s+5;
}
else {
AM.TempSortDir = *argv++;
argc--;
}
}
else if ( s[1] == 'i' ) { /* compatibility: silent/quiet */
AM.silent = 1;
}
else {
TAKEPATH(AM.SetupDir)
}
break;
case 'S': /* Next arg is setup file */
TAKEPATH(AM.SetupFile) break;
case 't': /* Next arg is directory for temp files */
if ( s[1] == 's' ) {
s++;
AM.havesortdir = 1;
TAKEPATH(AM.TempSortDir)
}
else {
TAKEPATH(AM.TempDir)
}
break;
case 'T': /* Print the total size used at end of job */
AM.PrintTotalSize = 1; break;
case 'v':
printversion:;
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
PrintHeader(0);
if ( onlyversion ) return(1);
goto NoFile;
case 'y': /* Preprocessor dumps output. No compilation. */
AP.PreDebug = PREPROONLY; break;
case 'z': /* The number following is a time limit in sec. */
t = s++;
AM.TimeLimit = 0;
while ( *s >= '0' && *s <= '9' )
AM.TimeLimit = 10*AM.TimeLimit + *s++ - '0';
break;
case 'Z': /* Removes the .str file on crash, no matter its contents */
AM.ClearStore = 1; break;
case '\0': /* "-" to use STDIN for the input. */
#ifdef WITHMPI
/* At the moment, ParFORM doesn't implement STDIN broadcasts. */
if ( PF.me == MASTER )
printf("Sorry, reading STDIN as input is currently not supported by ParFORM\n");
errorflag++;
#endif
AM.FromStdin = 1;
AC.NoShowInput = 1; // disable input echoing by default
break;
default:
if ( FG.cTable[*s] == 1 ) {
AM.SkipClears = 0; t = s;
while ( FG.cTable[*t] == 1 )
AM.SkipClears = 10*AM.SkipClears + *t++ - '0';
if ( *t != 0 ) {
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("Illegal numerical option in call of FORM: %s\n",s);
errorflag++;
}
}
else {
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("Illegal option in call of FORM: %s\n",s);
errorflag++;
}
break;
}
}
else if ( argc == 0 && !AM.Interact ) AM.InputFileName = argv[-1];
else {
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("Illegal option in call of FORM: %s\n",s);
errorflag++;
}
}
AM.totalnumberofthreads = threadnum;
if ( AM.InputFileName ) {
if ( AM.FromStdin ) {
printf("STDIN and the input filename cannot be specified simultaneously\n");
errorflag++;
}
s = AM.InputFileName;
while ( *s ) s++;
if ( s < AM.InputFileName+4 ||
s[-4] != '.' || s[-3] != 'f' || s[-2] != 'r' || s[-1] != 'm' ) {
t = (UBYTE *)Malloc1((s-AM.InputFileName)+5,"adding .frm");
s = AM.InputFileName;
AM.InputFileName = t;
while ( *s ) *t++ = *s++;
*t++ = '.'; *t++ = 'f'; *t++ = 'r'; *t++ = 'm'; *t = 0;
}
if ( AM.LogType >= 0 && AM.LogFileName == 0 ) {
AM.LogFileName = strDup1(AM.InputFileName,"name of logfile");
s = AM.LogFileName;
while ( *s ) s++;
s[-3] = 'l'; s[-2] = 'o'; s[-1] = 'g';
}
}
#ifdef WITHINTERACTION
else if ( AM.Interact ) {
if ( AM.LogType >= 0 ) {
/*
We may have to do better than just taking a name.
It is not unique! This will be left for later.
*/
AM.LogFileName = deflogname;
}
}
#endif
else if ( AM.FromStdin ) {
/* Do nothing. */
}
else {
NoFile:
#ifdef WITHMPI
if ( PF.me == MASTER )
#endif
printf("No filename specified in call of FORM\n");
errorflag++;
}
if ( AM.Path == 0 ) AM.Path = (UBYTE *)getenv("FORMPATH");
if ( AM.Path ) {
/*
* AM.Path is taken from argv or getenv. Reallocate it to avoid invalid
* frees when AM.Path has to be changed.
*/
AM.Path = strDup1(AM.Path,"DoTail Path");
}
return(errorflag);
}
/*
#] DoTail :
#[ OpenInput :
Major task here after opening is to skip the proper number of
.clear instructions if so desired without using interpretation
*/
int OpenInput()
{
int oldNoShowInput = AC.NoShowInput;
UBYTE c;
if ( !AM.Interact ) {
if ( AM.FromStdin ) {
if ( OpenStream(0,INPUTSTREAM,0,PRENOACTION) == 0 ) {
Error0("Cannot open STDIN");
return(-1);
}
}
else {
if ( OpenStream(AM.InputFileName,FILESTREAM,0,PRENOACTION) == 0 ) {
Error1("Cannot open file",AM.InputFileName);
return(-1);
}
if ( AC.CurrentStream->inbuffer <= 0 ) {
Error1("No input in file",AM.InputFileName);
return(-1);
}
}
AC.NoShowInput = 1;
while ( AM.SkipClears > 0 ) {
c = GetInput();
if ( c == ENDOFINPUT ) {
Error0("Not enough .clear instructions in input file");
}
if ( c == '\\' ) {
c = GetInput();
if ( c == ENDOFINPUT )
Error0("Not enough .clear instructions in input file");
continue;
}
if ( c == ' ' || c == '\t' ) continue;
if ( c == '.' ) {
c = GetInput();
if ( tolower(c) == 'c' ) {
c = GetInput();
if ( tolower(c) == 'l' ) {
c = GetInput();
if ( tolower(c) == 'e' ) {
c = GetInput();
if ( tolower(c) == 'a' ) {
c = GetInput();
if ( tolower(c) == 'r' ) {
c = GetInput();
if ( FG.cTable[c] > 2 ) {
AM.SkipClears--;
}
}
}
}
}
}
while ( c != '\n' && c != '\r' && c != ENDOFINPUT ) {
c = GetInput();
if ( c == '\\' ) c = GetInput();
}
}
else if ( c == '\n' || c == '\r' ) continue;
else {
while ( ( c = GetInput() ) != '\n' && c != '\r' ) {
if ( c == ENDOFINPUT ) {
Error0("Not enough .clear instructions in input file");
}
}
}
}
AC.NoShowInput = oldNoShowInput;
}
if ( AM.LogFileName ) {
#ifdef WITHMPI
if ( PF.me != MASTER ) {
/*
* Only the master writes to the log file. On slaves, we need
* a dummy handle, without opening the file.
*/
extern FILES **filelist; /* in tools.c */
int i = CreateHandle();
RWLOCKW(AM.handlelock);
filelist[i] = (FILES *)123; /* Must be nonzero to prevent a reuse in CreateHandle. */
UNRWLOCK(AM.handlelock);
AC.LogHandle = i;
}
else
#endif
if ( AC.CheckpointFlag != -1 ) {
if ( ( AC.LogHandle = CreateLogFile((char *)(AM.LogFileName)) ) < 0 ) {
Error1("Cannot create logfile",AM.LogFileName);
return(-1);
}
}
else {
if ( ( AC.LogHandle = OpenAddFile((char *)(AM.LogFileName)) ) < 0 ) {
Error1("Cannot re-open logfile",AM.LogFileName);
return(-1);
}
}
}
return(0);
}
/*
#] OpenInput :
#[ ReserveTempFiles :
Order of preference:
a: if there is a path in the commandtail, take that.
b: if none, try in the form.set file.
c: if still none, try in the environment for the variable FORMTMP
d: if still none, try the current directory.
The parameter indicates action in the case of multithreaded running.
par = 0 : We just run on a single processor. Keep everything normal.
par = 1 : Multithreaded running startup phase 1.
par = 2 : Multithreaded running startup phase 2.
*/
UBYTE *emptystring = (UBYTE *)".";
UBYTE *defaulttempfilename = (UBYTE *)"xformxxx.str";
VOID ReserveTempFiles(int par)
{
GETIDENTITY
SETUPPARAMETERS *sp;
UBYTE *s, *t, *tenddir, *tenddir2, c;
int i = 0;
WORD j;
if ( par == 0 || par == 1 ) {
if ( AM.TempDir == 0 ) {
sp = GetSetupPar((UBYTE *)"tempdir");
if ( ( sp->flags & USEDFLAG ) != USEDFLAG ) {
AM.TempDir = (UBYTE *)getenv("FORMTMP");
if ( AM.TempDir == 0 ) AM.TempDir = emptystring;
}
else AM.TempDir = (UBYTE *)(sp->value);
}
if ( AM.TempSortDir == 0 ) {
if ( AM.havesortdir ) {
sp = GetSetupPar((UBYTE *)"tempsortdir");
AM.TempSortDir = (UBYTE *)(sp->value);
}
else {
AM.TempSortDir = (UBYTE *)getenv("FORMTMPSORT");
if ( AM.TempSortDir == 0 ) AM.TempSortDir = AM.TempDir;
}
}
/*
We have now in principle a path but we will use its first element only.
Later that should become more complicated. Then we will use a path and
when one device is full we can continue on the next one.
*/
s = AM.TempDir; i = 200; /* Some extra for VMS */
while ( *s && *s != ':' ) { if ( *s == '\\' ) s++; s++; i++; }
FG.fname = (char *)Malloc1(sizeof(UBYTE)*(i+14),"name for temporary files");
s = AM.TempDir; t = (UBYTE *)FG.fname;
while ( *s && *s != ':' ) { if ( *s == '\\' ) s++; *t++ = *s++; }
if ( (char *)t > FG.fname && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
*t++ = SEPARATOR;
*t = 0;
tenddir = t;
FG.fnamebase = t-(UBYTE *)(FG.fname);
s = AM.TempSortDir; i = 200; /* Some extra for VMS */
while ( *s && *s != ':' ) { if ( *s == '\\' ) s++; s++; i++; }
FG.fname2 = (char *)Malloc1(sizeof(UBYTE)*(i+14),"name for sort files");
s = AM.TempSortDir; t = (UBYTE *)FG.fname2;
while ( *s && *s != ':' ) { if ( *s == '\\' ) s++; *t++ = *s++; }
if ( (char *)t > FG.fname2 && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
*t++ = SEPARATOR;
*t = 0;
tenddir2 = t;
FG.fname2base = t-(UBYTE *)(FG.fname2);
t = tenddir;
s = defaulttempfilename;
#ifdef WITHMPI
{
int iii;
#ifdef SMP
/* Very dirty quick-hack for the qcm smp machine at TTP */
M_free(FG.fname,"name for temporary files");
if(PF.me == 0){
/*[04nov2003 mt] To avoid segfault with -fast optimization option*/
/*[04nov2003 mt]:*/ /*NOTE, this is only a temporary stub!*/
/*FG.fname = "/formswap/xxxxxxxxxxxxxxxxxxxxx";*/
FG.fname = calloc(128,1);
strcpy(FG.fname,"/formswap/xxxxxxxxxxxxxxxxxxxxx");
/*:[04nov2003 mt]*/
t = (UBYTE *)FG.fname + 10;
FG.fnamebase = t-FG.fname;
}
else{
/*[04nov2003 mt]:*/
/*FG.fname = "/formswapx/xxxxxxxxxxxxxxxxxxxxx";*/
FG.fname = calloc(128,1);
strcpy(FG.fname,"/formswapx/xxxxxxxxxxxxxxxxxxxxx");
/*:[04nov2003 mt]*/
FG.fname[9] = '0' + PF.me;
t = (UBYTE *)FG.fname + 11;
FG.fnamebase = t-FG.fname;
}
#else
iii = sprintf((char*)t,"%d",PF.me);
t+= iii;
s+= iii; /* in case defaulttmpfilename is too short */
#endif
}
#endif
while ( *s ) *t++ = *s++;
*t = 0;
/*
There are problems when running many FORM jobs at the same time
from make or minos. If they start up simultaneously, occasionally
they can make the same .str file. We prevent this with first trying
a file that contains the digits of the pid. If this file
has already been taken we fall back on the old scheme.
The whole is controled with the -M (MultiRun) parameter in the
command tail.
*/
if ( AM.MultiRun ) {
int num = ((int)GetPID())%100000;
t += 2;
*t = 0;
t[-1] = 'r';
t[-2] = 't';
t[-3] = 's';
t[-4] = '.';
t[-5] = (UBYTE)('0' + num%10);
t[-6] = (UBYTE)('0' + (num/10)%10);
t[-7] = (UBYTE)('0' + (num/100)%10);
t[-8] = (UBYTE)('0' + (num/1000)%10);
t[-9] = (UBYTE)('0' + num/10000);
if ( ( AC.StoreHandle = CreateFile((char *)FG.fname) ) < 0 ) {
t[-5] = 'x'; t[-6] = 'x'; t[-7] = 'x'; t[-8] = 'x'; t[-9] = 'x';
goto classic;
}
}
else
{
classic:;
for(;;) {
if ( ( AC.StoreHandle = OpenFile((char *)FG.fname) ) < 0 ) {
if ( ( AC.StoreHandle = CreateFile((char *)FG.fname) ) >= 0 ) break;
}
else CloseFile(AC.StoreHandle);
c = t[-5];
if ( c == 'x' ) t[-5] = '0';
else if ( c == '9' ) {
t[-5] = '0';
c = t[-6];
if ( c == 'x' ) t[-6] = '0';
else if ( c == '9' ) {
t[-6] = '0';
c = t[-7];
if ( c == 'x' ) t[-7] = '0';
else if ( c == '9' ) {
/*
Note that we tried 1111 names!
*/
MesPrint("Name space for temp files exhausted");
t[-7] = 0;
MesPrint("Please remove files of the type %s or try a different directory"
,FG.fname);
Terminate(-1);
}
else t[-7] = (UBYTE)(c+1);
}
else t[-6] = (UBYTE)(c+1);
}
else t[-5] = (UBYTE)(c+1);
}
}
/*
Now we should make sure that the tempsortdir cq tempsortfilename makes it
into a similar construction.
*/
s = tenddir; t = tenddir2; while ( *s ) *t++ = *s++;
*t = 0;
/*
Now we should asign a name to the main sort file and the two stage 4 files.
*/
AM.S0->file.name = (char *)Malloc1(sizeof(char)*(i+14),"name for temporary files");
s = (UBYTE *)AM.S0->file.name;
t = (UBYTE *)FG.fname2;
i = 1;
while ( *t ) { *s++ = *t++; i++; }
s[-2] = 'o'; *s = 0;
}
/*
With the stage4 and scratch file names we have to be a bit more careful.
They are to be allocated after the threads are initialized when there
are threads of course.
*/
if ( par == 0 ) {
s = (UBYTE *)((void *)(FG.fname2)); i = 0;
while ( *s ) { s++; i++; }
s = (UBYTE *)Malloc1(sizeof(char)*(i+1),"name for stage4 file a");
AR.FoStage4[1].name = (char *)s;
t = (UBYTE *)FG.fname2;
while ( *t ) *s++ = *t++;
s[-2] = '4'; s[-1] = 'a'; *s = 0;
s = (UBYTE *)((void *)(FG.fname)); i = 0;
while ( *s ) { s++; i++; }
s = (UBYTE *)Malloc1(sizeof(char)*(i+1),"name for stage4 file b");
AR.FoStage4[0].name = (char *)s;
t = (UBYTE *)FG.fname;
while ( *t ) *s++ = *t++;
s[-2] = '4'; s[-1] = 'b'; *s = 0;
for ( j = 0; j < 3; j++ ) {
s = (UBYTE *)Malloc1(sizeof(char)*(i+1),"name for scratch file");
AR.Fscr[j].name = (char *)s;
t = (UBYTE *)FG.fname;
while ( *t ) *s++ = *t++;
s[-2] = 'c'; s[-1] = (UBYTE)('0'+j); *s = 0;
}
}
#ifdef WITHPTHREADS
else if ( par == 2 ) {
s = (UBYTE *)((void *)(FG.fname2)); i = 0;
while ( *s ) { s++; i++; }
s = (UBYTE *)Malloc1(sizeof(char)*(i+12),"name for stage4 file a");
sprintf((char *)s,"%s.%d",FG.fname2,AT.identity);
s[i-2] = '4'; s[i-1] = 'a';
AR.FoStage4[1].name = (char *)s;
s = (UBYTE *)((void *)(FG.fname)); i = 0;
while ( *s ) { s++; i++; }
s = (UBYTE *)Malloc1(sizeof(char)*(i+12),"name for stage4 file b");
sprintf((char *)s,"%s.%d",FG.fname,AT.identity);
s[i-2] = '4'; s[i-1] = 'b';
AR.FoStage4[0].name = (char *)s;
if ( AT.identity == 0 ) {
for ( j = 0; j < 3; j++ ) {
s = (UBYTE *)Malloc1(sizeof(char)*(i+1),"name for scratch file");
AR.Fscr[j].name = (char *)s;
t = (UBYTE *)FG.fname;
while ( *t ) *s++ = *t++;
s[-2] = 'c'; s[-1] = (UBYTE)('0'+j); *s = 0;
}
}
}
#endif
}
/*
#] ReserveTempFiles :
#[ StartVariables :
*/
#ifdef WITHPTHREADS
ALLPRIVATES *DummyPointer = 0;
#endif
VOID StartVariables()
{
int i, ii;
PUTZERO(AM.zeropos);
StartPrepro();
/*
The module counter:
*/
AC.CModule=0;
#ifdef WITHPTHREADS
/*
We need a value in AB because in the startup some routines may call AB[0].
*/
AB = (ALLPRIVATES **)&DummyPointer;
#endif
/*
separators used to delimit arguments in #call and #do, by default ',' and '|':
Be sure, it is en empty set:
*/
set_sub(AC.separators,AC.separators,AC.separators);
set_set(',',AC.separators);
set_set('|',AC.separators);
AM.BracketFactors[0] = 8;
AM.BracketFactors[1] = SYMBOL;
AM.BracketFactors[2] = 4;
AM.BracketFactors[3] = FACTORSYMBOL;
AM.BracketFactors[4] = 1;
AM.BracketFactors[5] = 1;
AM.BracketFactors[6] = 1;
AM.BracketFactors[7] = 3;
AM.SkipClears = 0;
AC.Cnumpows = 0;
AC.OutputMode = 72;
AC.OutputSpaces = NORMALFORMAT;
AC.LineLength = 79;
AM.gIsFortran90 = AC.IsFortran90 = ISNOTFORTRAN90;
AM.gFortran90Kind = AC.Fortran90Kind = 0;
AM.gCnumpows = 0;
AC.exprfillwarning = 0;
AM.gLineLength = 79;
AM.OutBufSize = 80;
AM.MaxStreamSize = MAXFILESTREAMSIZE;
AP.MaxPreAssignLevel = 4;
AC.iBufferSize = 512;
AP.pSize = 128;
AP.MaxPreIfLevel = 10;
AP.cComChar = AP.ComChar = '*';
AM.OffsetVector = -2*WILDOFFSET+MINSPEC;
AC.cbufList.num = 0;
AM.hparallelflag = AM.gparallelflag =
AC.parallelflag = AC.mparallelflag = PARALLELFLAG;
#ifdef WITHMPI
if ( PF.numtasks < 2 ) AM.hparallelflag |= NOPARALLEL_NPROC;
#endif
AC.tablefilling = 0;
AM.resetTimeOnClear = 1;
AM.gnumextrasym = AM.ggnumextrasym = 0;
AM.havesortdir = 0;
AM.SpectatorFiles = 0;
AM.NumSpectatorFiles = 0;
AM.SizeForSpectatorFiles = 0;
/*
Information for the lists of variables. Part of error message and size:
*/
AP.ProcList.message = "procedure";
AP.ProcList.size = sizeof(PROCEDURE);
AP.LoopList.message = "doloop";
AP.LoopList.size = sizeof(DOLOOP);
AP.PreVarList.message = "PreVariable";
AP.PreVarList.size = sizeof(PREVAR);
AC.SymbolList.message = "symbol";
AC.SymbolList.size = sizeof(struct SyMbOl);
AC.IndexList.message = "index";
AC.IndexList.size = sizeof(struct InDeX);
AC.VectorList.message = "vector";
AC.VectorList.size = sizeof(struct VeCtOr);
AC.FunctionList.message = "function";
AC.FunctionList.size = sizeof(struct FuNcTiOn);
AC.SetList.message = "set";
AC.SetList.size = sizeof(struct SeTs);
AC.SetElementList.message = "set element";
AC.SetElementList.size = sizeof(WORD);
AC.ExpressionList.message = "expression";
AC.ExpressionList.size = sizeof(struct ExPrEsSiOn);
AC.cbufList.message = "compiler buffer";
AC.cbufList.size = sizeof(CBUF);
AC.ChannelList.message = "channel buffer";
AC.ChannelList.size = sizeof(CHANNEL);
AP.DollarList.message = "$-variable";
AP.DollarList.size = sizeof(struct DoLlArS);
AC.DubiousList.message = "ambiguous variable";
AC.DubiousList.size = sizeof(struct DuBiOuS);
AC.TableBaseList.message = "list of tablebases";
AC.TableBaseList.size = sizeof(DBASE);
AC.TestValue = 0;
AC.InnerTest = 0;
AC.AutoSymbolList.message = "autosymbol";
AC.AutoSymbolList.size = sizeof(struct SyMbOl);
AC.AutoIndexList.message = "autoindex";
AC.AutoIndexList.size = sizeof(struct InDeX);
AC.AutoVectorList.message = "autovector";
AC.AutoVectorList.size = sizeof(struct VeCtOr);
AC.AutoFunctionList.message = "autofunction";
AC.AutoFunctionList.size = sizeof(struct FuNcTiOn);
AC.PotModDolList.message = "potentially modified dollar";
AC.PotModDolList.size = sizeof(WORD);
AC.ModOptDolList.message = "moduleoptiondollar";
AC.ModOptDolList.size = sizeof(MODOPTDOLLAR);
AO.FortDotChar = '_';
AO.ErrorBlock = 0;
AC.firstconstindex = 1;
AO.Optimize.mctsconstant.fval = 1.0;
AO.Optimize.horner = O_MCTS;
AO.Optimize.hornerdirection = O_FORWARDORBACKWARD;
AO.Optimize.method = O_GREEDY;
AO.Optimize.mctstimelimit = 0;
AO.Optimize.mctsnumexpand = 1000;
AO.Optimize.mctsnumkeep = 10;
AO.Optimize.mctsnumrepeat = 1;
AO.Optimize.greedytimelimit = 0;
AO.Optimize.greedyminnum = 10;
AO.Optimize.greedymaxperc = 5;
AO.Optimize.printstats = 0;
AO.Optimize.debugflags = 0;
AO.OptimizeResult.code = NULL;
AO.inscheme = 0;
AO.schemenum = 0;
AO.wpos = 0;
AO.wpoin = 0;
AO.wlen = 0;
AM.dollarzero = 0;