46#ifdef ENABLE_BACKTRACE
57#define STRINGIFY(x) STRINGIFY__(x)
58#define STRINGIFY__(x) #x
63#if defined(WITHPTHREADS)
64 #define FORMNAME "TFORM"
66 #define FORMNAME "ParFORM"
68 #define FORMNAME "FORM"
78 #define REPO_VERSION STRINGIFY(REPO_MAJOR_VERSION) "." STRINGIFY(REPO_MINOR_VERSION) "." STRINGIFY(REPO_PATCH_VERSION)
82 #define REPO_DATE __DATE__
85 #define VERSIONSTR FORMNAME " " REPO_VERSION " (" REPO_DATE ", " REPO_REVISION ")"
87 #define VERSIONSTR FORMNAME " " REPO_VERSION " (" REPO_DATE ")"
89 #define MAJORVERSION REPO_MAJOR_VERSION
90 #define MINORVERSION REPO_MINOR_VERSION
91 #define PATCHVERSION REPO_PATCH_VERSION
98 #define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION) "." STRINGIFY(PATCHVERSION) "Beta"
100 #define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION) "." STRINGIFY(PATCHVERSION)
102 #define VERSIONSTR FORMNAME " " VERSIONSTR__ " (" PRODUCTIONDATE ")"
116static void PrintBuildInfo(
void) {
117#if defined(__INTEL_LLVM_COMPILER)
118 MesPrint(
"Compiler: Intel LLVM oneAPI %d",__INTEL_LLVM_COMPILER);
119#elif defined(__INTEL_COMPILER)
120 MesPrint(
"Compiler: Intel Classic %d",__INTEL_COMPILER);
121#elif defined(__clang__) && defined(__apple_build_version__)
122 MesPrint(
"Compiler: Apple Clang %d.%d.%d (build %d)",__clang_major__,__clang_minor__,__clang_patchlevel__,__apple_build_version__);
123#elif defined(__clang__)
124 MesPrint(
"Compiler: Clang %d.%d.%d",__clang_major__,__clang_minor__,__clang_patchlevel__);
125#elif defined(__GNUC__)
126 MesPrint(
"Compiler: GCC %d.%d.%d",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
127#elif defined(_MSC_VER)
128 MesPrint(
"Compiler: MSVC %d",_MSC_VER);
130 MesPrint(
"Compiler: Unknown");
133#if defined(__x86_64__) || defined(_M_X64)
134 MesPrint(
"Architecture: x86_64");
135#elif defined(__i386__) || defined(_M_IX86)
136 MesPrint(
"Architecture: x86 (32-bit)");
137#elif defined(__aarch64__) || defined(_M_ARM64)
138 MesPrint(
"Architecture: arm64");
139#elif defined(__arm__) || defined(_M_ARM)
140 MesPrint(
"Architecture: arm (32-bit)");
142 MesPrint(
"Architecture: Unknown");
154static void PrintHeader(
int par)
157 if ( PF.me == MASTER && !AM.silent ) {
161 char buffer1[250], buffer2[80], *s = buffer1, *t = buffer2;
163 for ( n = 0; n < 250; n++ ) buffer1[n] =
' ';
168 if ( strlen(VERSIONSTR) <= 100 ) {
169 strcpy(s,VERSIONSTR);
170 s += strlen(VERSIONSTR);
177 strncpy(s,VERSIONSTR,97);
191#if defined(WITHPTHREADS) || defined(WITHMPI)
192#if defined(WITHPTHREADS)
193 int nworkers = AM.totalnumberofthreads-1;
194#elif defined(WITHMPI)
195 int nworkers = PF.numtasks-1;
197 s += snprintf(s,250-(s-buffer1),
" %d worker",nworkers);
200 if ( nworkers != 1 ) {
206 snprintf(t,80-(t-buffer2),
"Run: %s",MakeDate());
212 length = (s-buffer1) + (t-buffer2);
213 if ( length+2 <= AC.LineLength ) {
214 for ( n = AC.LineLength-length; n > 0; n-- ) *s++ =
' ';
234 if ( length <= AC.LineLength ) {
235 MesPrint(
"%s",buffer1);
238 WORD oldLineLength = AC.LineLength;
239 AC.LineLength = length;
240 MesPrint(
"%s",buffer1);
241 AC.LineLength = oldLineLength;
258 if ( AC.CheckpointFlag ) {
276#ifdef WITHINTERACTION
277static UBYTE deflogname[] =
"formsession.log";
280#define TAKEPATH(x) if(s[1]== '=' ){x=s+2;} else{x=*argv++;argc--;}
282int DoTail(
int argc, UBYTE **argv)
284 int errorflag = 0, onlyversion = 1;
291 AM.HoldFlag = AM.qError = AM.Interact = AM.FileOnlyFlag = 0;
292 AM.InputFileName = AM.LogFileName = AM.IncDir = AM.TempDir = AM.TempSortDir =
293 AM.SetupDir = AM.SetupFile = AM.Path = 0;
301 while ( argc >= 1 ) {
303 if ( *s ==
'-' || ( *s ==
'/' && ( argc > 0 || AM.Interact ) ) ) {
307 AM.qError = 1;
break;
309 TAKEPATH(AM.LogFileName) break;
312 t = copy = strDup1(*argv,"Dotail");
313 while ( *t && *t != '=' ) t++;
315 if (
PutPreVar(copy,(UBYTE *)
"1",0,0) < 0 )
return(-1);
319 if (
PutPreVar(copy,t,0,0) < 0 )
return(-1);
322 M_free(copy,
"-d prevar");
323 argv++; argc--;
break;
325 AM.FileOnlyFlag = 1; AM.LogType = 0;
break;
327 AM.FileOnlyFlag = 1; AM.LogType = 1;
break;
329 AM.HoldFlag = 1;
break;
331 if ( StrCmp(s, (UBYTE *)
"ignore-deprecation") == 0 ) {
332 AM.IgnoreDeprecation = 1;
335#ifdef WITHINTERACTION
343 TAKEPATH(AM.IncDir) break;
345 if ( s[1] == 'l' ) AM.LogType = 1;
349 AM.LogType = 1; break;
358 while ( *s >= '0' && *s <= '9' )
359 threadnum = 10*threadnum + *s++ - '0';
362 if ( PF.me == MASTER )
364 printf(
"Illegal value for option m or w: %s\n",t);
371 AM.ggWTimeStatsFlag = 1;
378#ifdef WITHEXTERNALCHANNEL
381 if( (s[2]==
'p')&&(s[3]==
'e')&&(s[4]==
'\0') ){
385 if(initPresetExternalChannels(*argv++,AX.timeout)<1){
387 if ( PF.me == MASTER )
389 printf(
"Error initializing preset external channels\n");
396 if ( PF.me == MASTER )
398 printf(
"Illegal option in call of FORM: %s\n",s);
404 if ( ( s[1]==
'i' ) && ( s[2] ==
'p' ) && (s[3] ==
'e' )
405 && ( s[4] ==
'\0' ) ){
407 if ( PF.me == MASTER )
409 printf(
"Illegal option: Pipes not supported on this system.\n");
413 if ( PF.me == MASTER )
415 printf(
"Illegal option: %s\n",s);
427 AM.silent = 1;
break;
429 AC.CheckpointFlag = -1;
432 if ( ( s[1] ==
'o' ) && ( s[2] ==
'r' ) && ( s[3] ==
't' ) ) {
434 AM.TempSortDir = s+5;
437 AM.TempSortDir = *argv++;
441 else if ( s[1] ==
'i' ) {
445 TAKEPATH(AM.SetupDir)
449 TAKEPATH(AM.SetupFile) break;
454 TAKEPATH(AM.TempSortDir)
461 AM.PrintTotalSize = 1;
break;
470 if ( onlyversion )
return(1);
473 AP.PreDebug = PREPROONLY;
break;
477 while ( *s >=
'0' && *s <=
'9' )
478 AM.TimeLimit = 10*AM.TimeLimit + *s++ -
'0';
481 AM.ClearStore = 1;
break;
485 if ( PF.me == MASTER )
486 printf(
"Sorry, reading STDIN as input is currently not supported by ParFORM\n");
493 if ( FG.cTable[*s] == 1 ) {
494 AM.SkipClears = 0; t = s;
495 while ( FG.cTable[*t] == 1 )
496 AM.SkipClears = 10*AM.SkipClears + *t++ -
'0';
499 if ( PF.me == MASTER )
501 printf(
"Illegal numerical option in call of FORM: %s\n",s);
508 if ( PF.me == MASTER )
510 printf(
"Illegal option in call of FORM: %s\n",s);
516 else if ( argc == 0 && !AM.Interact ) AM.InputFileName = argv[-1];
519 if ( PF.me == MASTER )
521 printf(
"Illegal option in call of FORM: %s\n",s);
525 AM.totalnumberofthreads = threadnum;
526 if ( AM.InputFileName ) {
527 if ( AM.FromStdin ) {
528 printf(
"STDIN and the input filename cannot be specified simultaneously\n");
531 s = AM.InputFileName;
533 if ( s < AM.InputFileName+4 ||
534 s[-4] !=
'.' || s[-3] !=
'f' || s[-2] !=
'r' || s[-1] !=
'm' ) {
535 t = (UBYTE *)Malloc1((s-AM.InputFileName)+5,
"adding .frm");
536 s = AM.InputFileName;
537 AM.InputFileName = t;
538 while ( *s ) *t++ = *s++;
539 *t++ =
'.'; *t++ =
'f'; *t++ =
'r'; *t++ =
'm'; *t = 0;
541 if ( AM.LogType >= 0 && AM.LogFileName == 0 ) {
542 AM.LogFileName = strDup1(AM.InputFileName,
"name of logfile");
545 s[-3] =
'l'; s[-2] =
'o'; s[-1] =
'g';
548#ifdef WITHINTERACTION
549 else if ( AM.Interact ) {
550 if ( AM.LogType >= 0 ) {
555 AM.LogFileName = deflogname;
559 else if ( AM.FromStdin ) {
565 if ( PF.me == MASTER )
567 printf(
"No filename specified in call of FORM\n");
570 if ( AM.Path == 0 ) AM.Path = (UBYTE *)getenv(
"FORMPATH");
576 AM.Path = strDup1(AM.Path,
"DoTail Path");
591 int oldNoShowInput = AC.NoShowInput;
593 if ( !AM.Interact ) {
594 if ( AM.FromStdin ) {
595 if ( OpenStream(0,INPUTSTREAM,0,PRENOACTION) == 0 ) {
596 Error0(
"Cannot open STDIN");
601 if ( OpenStream(AM.InputFileName,FILESTREAM,0,PRENOACTION) == 0 ) {
602 Error1(
"Cannot open file",AM.InputFileName);
605 if ( AC.CurrentStream->inbuffer <= 0 ) {
606 Error1(
"No input in file",AM.InputFileName);
611 while ( AM.SkipClears > 0 ) {
613 if ( c == ENDOFINPUT ) {
614 Error0(
"Not enough .clear instructions in input file");
618 if ( c == ENDOFINPUT )
619 Error0(
"Not enough .clear instructions in input file");
622 if ( c ==
' ' || c ==
'\t' )
continue;
625 if ( tolower(c) ==
'c' ) {
627 if ( tolower(c) ==
'l' ) {
629 if ( tolower(c) ==
'e' ) {
631 if ( tolower(c) ==
'a' ) {
633 if ( tolower(c) ==
'r' ) {
635 if ( FG.cTable[c] > 2 ) {
643 while ( c !=
'\n' && c !=
'\r' && c != ENDOFINPUT ) {
645 if ( c ==
'\\' ) c = GetInput();
648 else if ( c ==
'\n' || c ==
'\r' )
continue;
650 while ( ( c = GetInput() ) !=
'\n' && c !=
'\r' ) {
651 if ( c == ENDOFINPUT ) {
652 Error0(
"Not enough .clear instructions in input file");
657 AC.NoShowInput = oldNoShowInput;
659 if ( AM.LogFileName ) {
661 if ( PF.me != MASTER ) {
666 extern FILES **filelist;
667 int i = CreateHandle();
668 RWLOCKW(AM.handlelock);
669 filelist[i] = (FILES *)123;
670 UNRWLOCK(AM.handlelock);
675 if ( AC.CheckpointFlag != -1 ) {
676 if ( ( AC.LogHandle = CreateLogFile((
char *)(AM.LogFileName)) ) < 0 ) {
677 Error1(
"Cannot create logfile",AM.LogFileName);
682 if ( ( AC.LogHandle = OpenAddFile((
char *)(AM.LogFileName)) ) < 0 ) {
683 Error1(
"Cannot re-open logfile",AM.LogFileName);
707UBYTE *emptystring = (UBYTE *)
".";
708UBYTE *defaulttempfilename = (UBYTE *)
"xformxxx.str";
711#define DEFAULTFNAMELENGTH 16
713void ReserveTempFiles(
int par)
717 UBYTE *s, *t, *tenddir, *tenddir2, c;
720 if ( par == 0 || par == 1 ) {
721 if ( AM.TempDir == 0 ) {
722 sp = GetSetupPar((UBYTE *)
"tempdir");
723 if ( ( sp->flags & USEDFLAG ) != USEDFLAG ) {
724 AM.TempDir = (UBYTE *)getenv(
"FORMTMP");
725 if ( AM.TempDir == 0 ) AM.TempDir = emptystring;
727 else AM.TempDir = (UBYTE *)(sp->value);
729 if ( AM.TempSortDir == 0 ) {
730 if ( AM.havesortdir ) {
731 sp = GetSetupPar((UBYTE *)
"tempsortdir");
732 AM.TempSortDir = (UBYTE *)(sp->value);
735 AM.TempSortDir = (UBYTE *)getenv(
"FORMTMPSORT");
736 if ( AM.TempSortDir == 0 ) AM.TempSortDir = AM.TempDir;
744 s = AM.TempDir; i = 200;
745 while ( *s && *s != PATHSEPARATOR ) {
if ( *s ==
'\\' ) s++; s++; i++; }
746 FG.fnamesize =
sizeof(UBYTE)*(i+DEFAULTFNAMELENGTH);
747 FG.fname = (
char *)Malloc1(FG.fnamesize,
"name for temporary files");
748 s = AM.TempDir; t = (UBYTE *)FG.fname;
749 while ( *s && *s != PATHSEPARATOR ) {
if ( *s ==
'\\' ) s++; *t++ = *s++; }
750 if ( (
char *)t > FG.fname && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
754 FG.fnamebase = t-(UBYTE *)(FG.fname);
756 s = AM.TempSortDir; i = 200;
757 while ( *s && *s != PATHSEPARATOR ) {
if ( *s ==
'\\' ) s++; s++; i++; }
759 FG.fname2size =
sizeof(UBYTE)*(i+DEFAULTFNAMELENGTH);
760 FG.fname2 = (
char *)Malloc1(FG.fname2size,
"name for sort files");
761 s = AM.TempSortDir; t = (UBYTE *)FG.fname2;
762 while ( *s && *s != PATHSEPARATOR ) {
if ( *s ==
'\\' ) s++; *t++ = *s++; }
763 if ( (
char *)t > FG.fname2 && t[-1] != SEPARATOR && t[-1] != ALTSEPARATOR )
767 FG.fname2base = t-(UBYTE *)(FG.fname2);
770 s = defaulttempfilename;
774 iii = snprintf((
char*)t,FG.fnamesize-((
char*)t-FG.fname),
"%d",PF.me);
779 while ( *s ) *t++ = *s++;
791 int num = ((int)GetPID())%10000000;
798 t[-5] = (UBYTE)(
'0' + num%10);
799 t[-6] = (UBYTE)(
'0' + (num/10)%10);
800 t[-7] = (UBYTE)(
'0' + (num/100)%10);
801 t[-8] = (UBYTE)(
'0' + (num/1000)%10);
802 t[-9] = (UBYTE)(
'0' + (num/10000)%10);
803 t[-10] = (UBYTE)(
'0' + (num/100000)%10);
804 t[-11] = (UBYTE)(
'0' + num/1000000);
805 if ( ( AC.StoreHandle = CreateFile((
char *)FG.fname) ) < 0 ) {
806 t[-5] =
'x'; t[-6] =
'x'; t[-7] =
'x'; t[-8] =
'x'; t[-9] =
'x'; t[-10] =
'x'; t[-11] =
'x';
814 if ( ( AC.StoreHandle = OpenFile((
char *)FG.fname) ) < 0 ) {
815 if ( ( AC.StoreHandle = CreateFile((
char *)FG.fname) ) >= 0 )
break;
817 else CloseFile(AC.StoreHandle);
819 if ( c ==
'x' ) t[-5] =
'0';
820 else if ( c ==
'9' ) {
823 if ( c ==
'x' ) t[-6] =
'0';
824 else if ( c ==
'9' ) {
827 if ( c ==
'x' ) t[-7] =
'0';
828 else if ( c ==
'9' ) {
832 MesPrint(
"Name space for temp files exhausted");
834 MesPrint(
"Please remove files of the type %s or try a different directory"
838 else t[-7] = (UBYTE)(c+1);
840 else t[-6] = (UBYTE)(c+1);
842 else t[-5] = (UBYTE)(c+1);
849 s = tenddir; t = tenddir2;
while ( *s ) *t++ = *s++;
855 AM.S0->file.name = (
char *)Malloc1(
sizeof(
char)*(i+DEFAULTFNAMELENGTH),
"name for temporary files");
856 s = (UBYTE *)AM.S0->file.name;
857 t = (UBYTE *)FG.fname2;
859 while ( *t ) { *s++ = *t++; i++; }
868 if ( ( AM.S0->file.handle = CreateFile((
char *)AM.S0->file.name) ) < 0 ) {
869 MesPrint(
"Could not create sort file: %s", AM.S0->file.name);
873 CloseFile(AM.S0->file.handle);
874 AM.S0->file.handle = -1;
875 remove(AM.S0->file.name);
885 s = (UBYTE *)((
void *)(FG.fname2)); i = 0;
886 while ( *s ) { s++; i++; }
888 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for stage4 file a");
889 AR.FoStage4[1].name = (
char *)s;
890 t = (UBYTE *)FG.fname2;
891 while ( *t ) *s++ = *t++;
892 s[-2] =
'4'; s[-1] =
'a'; *s = 0;
893 s = (UBYTE *)((
void *)(FG.fname)); i = 0;
894 while ( *s ) { s++; i++; }
896 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for stage4 file b");
897 AR.FoStage4[0].name = (
char *)s;
898 t = (UBYTE *)FG.fname;
899 while ( *t ) *s++ = *t++;
900 s[-2] =
'4'; s[-1] =
'b'; *s = 0;
901 for ( j = 0; j < 3; j++ ) {
903 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for scratch file");
904 AR.Fscr[j].name = (
char *)s;
905 t = (UBYTE *)FG.fname;
906 while ( *t ) *s++ = *t++;
907 s[-2] =
'c'; s[-1] = (UBYTE)(
'0'+j); *s = 0;
911 else if ( par == 2 ) {
913 s = (UBYTE *)((
void *)(FG.fname2)); i = 0;
914 while ( *s ) { s++; i++; }
916 tname =
sizeof(char)*(i+12);
917 s = (UBYTE *)Malloc1(tname,
"name for stage4 file a");
918 snprintf((
char *)s,tname,
"%s.%d",FG.fname2,AT.identity);
919 s[i-2] =
'4'; s[i-1] =
'a';
920 AR.FoStage4[1].name = (
char *)s;
921 s = (UBYTE *)((
void *)(FG.fname)); i = 0;
922 while ( *s ) { s++; i++; }
924 tname =
sizeof(char)*(i+12);
925 s = (UBYTE *)Malloc1(tname,
"name for stage4 file b");
926 snprintf((
char *)s,tname,
"%s.%d",FG.fname,AT.identity);
927 s[i-2] =
'4'; s[i-1] =
'b';
928 AR.FoStage4[0].name = (
char *)s;
929 if ( AT.identity == 0 ) {
930 for ( j = 0; j < 3; j++ ) {
932 s = (UBYTE *)Malloc1(
sizeof(
char)*(i+1),
"name for scratch file");
933 AR.Fscr[j].name = (
char *)s;
934 t = (UBYTE *)FG.fname;
935 while ( *t ) *s++ = *t++;
936 s[-2] =
'c'; s[-1] = (UBYTE)(
'0'+j); *s = 0;
949ALLPRIVATES *DummyPointer = 0;
965 AB = (ALLPRIVATES **)&DummyPointer;
971 set_sub(AC.separators,AC.separators,AC.separators);
972 set_set(
',',AC.separators);
973 set_set(
'|',AC.separators);
975 AM.BracketFactors[0] = 8;
976 AM.BracketFactors[1] = SYMBOL;
977 AM.BracketFactors[2] = 4;
978 AM.BracketFactors[3] = FACTORSYMBOL;
979 AM.BracketFactors[4] = 1;
980 AM.BracketFactors[5] = 1;
981 AM.BracketFactors[6] = 1;
982 AM.BracketFactors[7] = 3;
987 AC.OutputSpaces = NORMALFORMAT;
989 AM.gIsFortran90 = AC.IsFortran90 = ISNOTFORTRAN90;
990 AM.gFortran90Kind = AC.Fortran90Kind = 0;
992 AC.exprfillwarning = 0;
995 AM.MaxStreamSize = MAXFILESTREAMSIZE;
996 AP.MaxPreAssignLevel = 4;
997 AC.iBufferSize = 512;
999 AP.MaxPreIfLevel = 10;
1000 AP.cComChar = AP.ComChar =
'*';
1001 AP.firstnamespace = 0;
1002 AP.lastnamespace = 0;
1003 AP.fullnamesize = 127;
1004 AP.fullname = (UBYTE *)Malloc1((AP.fullnamesize+1)*
sizeof(UBYTE),
"AP.fullname");
1005 AM.OffsetVector = -2*WILDOFFSET+MINSPEC;
1006 AC.cbufList.num = 0;
1007 AM.hparallelflag = AM.gparallelflag =
1008 AC.parallelflag = AC.mparallelflag = PARALLELFLAG;
1010 if ( PF.numtasks < 2 ) AM.hparallelflag |= NOPARALLEL_NPROC;
1012 AC.tablefilling = 0;
1017 AM.resetTimeOnClear = 1;
1018 AM.gnumextrasym = AM.ggnumextrasym = 0;
1020 AM.SpectatorFiles = 0;
1021 AM.NumSpectatorFiles = 0;
1022 AM.SizeForSpectatorFiles = 0;
1026 AP.ProcList.message =
"procedure";
1028 AP.LoopList.message =
"doloop";
1029 AP.LoopList.size =
sizeof(
DOLOOP);
1030 AP.PreVarList.message =
"PreVariable";
1031 AP.PreVarList.size =
sizeof(
PREVAR);
1032 AC.SymbolList.message =
"symbol";
1033 AC.SymbolList.size =
sizeof(
struct SyMbOl);
1034 AC.IndexList.message =
"index";
1035 AC.IndexList.size =
sizeof(
struct InDeX);
1036 AC.VectorList.message =
"vector";
1037 AC.VectorList.size =
sizeof(
struct VeCtOr);
1038 AC.FunctionList.message =
"function";
1039 AC.FunctionList.size =
sizeof(
struct FuNcTiOn);
1040 AC.SetList.message =
"set";
1041 AC.SetList.size =
sizeof(
struct SeTs);
1042 AC.SetElementList.message =
"set element";
1043 AC.SetElementList.size =
sizeof(WORD);
1044 AC.ExpressionList.message =
"expression";
1045 AC.ExpressionList.size =
sizeof(
struct ExPrEsSiOn);
1046 AC.cbufList.message =
"compiler buffer";
1047 AC.cbufList.size =
sizeof(
CBUF);
1048 AC.ChannelList.message =
"channel buffer";
1049 AC.ChannelList.size =
sizeof(
CHANNEL);
1050 AP.DollarList.message =
"$-variable";
1051 AP.DollarList.size =
sizeof(
struct DoLlArS);
1052 AC.DubiousList.message =
"ambiguous variable";
1053 AC.DubiousList.size =
sizeof(
struct DuBiOuS);
1054 AC.TableBaseList.message =
"list of tablebases";
1055 AC.TableBaseList.size =
sizeof(
DBASE);
1059 AC.AutoSymbolList.message =
"autosymbol";
1060 AC.AutoSymbolList.size =
sizeof(
struct SyMbOl);
1061 AC.AutoIndexList.message =
"autoindex";
1062 AC.AutoIndexList.size =
sizeof(
struct InDeX);
1063 AC.AutoVectorList.message =
"autovector";
1064 AC.AutoVectorList.size =
sizeof(
struct VeCtOr);
1065 AC.AutoFunctionList.message =
"autofunction";
1066 AC.AutoFunctionList.size =
sizeof(
struct FuNcTiOn);
1067 AC.PotModDolList.message =
"potentially modified dollar";
1068 AC.PotModDolList.size =
sizeof(WORD);
1069 AC.ModOptDolList.message =
"moduleoptiondollar";
1072 AO.FortDotChar =
'_';
1074 AC.firstconstindex = 1;
1075 AO.Optimize.mctsconstant.fval = 1.0;
1076 AO.Optimize.horner = O_MCTS;
1077 AO.Optimize.hornerdirection = O_FORWARDORBACKWARD;
1078 AO.Optimize.method = O_GREEDY;
1079 AO.Optimize.mctstimelimit = 0;
1080 AO.Optimize.mctsnumexpand = 1000;
1081 AO.Optimize.mctsnumkeep = 10;
1082 AO.Optimize.mctsnumrepeat = 1;
1083 AO.Optimize.greedytimelimit = 0;
1084 AO.Optimize.greedyminnum = 10;
1085 AO.Optimize.greedymaxperc = 5;
1086 AO.Optimize.printstats = 0;
1087 AO.Optimize.debugflags = 0;
1088 AO.OptimizeResult.code = NULL;
1096 AC.doloopstacksize = 0;
1101 AC.varnames = MakeNameTree();
1102 AC.exprnames = MakeNameTree();
1103 AC.dollarnames = MakeNameTree();
1104 AC.autonames = MakeNameTree();
1105 AC.activenames = &(AC.varnames);
1126 CBUF *C = cbuf+AM.zbufnum;
1127 WORD one[5] = {4,1,1,3,0};
1130 AM.zerorhs = C->numrhs;
1131 AddNtoC(AM.zbufnum,1,&zero,17);
1133 AM.onerhs = C->numrhs;
1140 AC.Symbols = &(AC.SymbolList);
1141 AC.Indices = &(AC.IndexList);
1142 AC.Vectors = &(AC.VectorList);
1143 AC.Functions = &(AC.FunctionList);
1146 AddDollar((UBYTE *)
"$",DOLUNDEFINED,0,0);
1148 cbuf[AM.dbufnum].mnumlhs = cbuf[AM.dbufnum].numlhs;
1149 cbuf[AM.dbufnum].mnumrhs = cbuf[AM.dbufnum].numrhs;
1151 AddSymbol((UBYTE *)
"i_",-MAXPOWER,MAXPOWER,VARTYPEIMAGINARY,0);
1152 AddSymbol((UBYTE *)
"pi_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1157 AddSymbol((UBYTE *)
"coeff_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1158 AddSymbol((UBYTE *)
"num_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1159 AddSymbol((UBYTE *)
"den_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1160 AddSymbol((UBYTE *)
"xarg_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1161 AddSymbol((UBYTE *)
"dimension_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1162 AddSymbol((UBYTE *)
"factor_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1163 AddSymbol((UBYTE *)
"sep_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1164 AddSymbol((UBYTE *)
"ee_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1165 AddSymbol((UBYTE *)
"em_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1174 for ( ; i < FIRSTUSERSYMBOL; i++ ) {
1175 snprintf(dumstr,20,
":%d:",i);
1176 AddSymbol((UBYTE *)dumstr,-MAXPOWER,MAXPOWER,VARTYPENONE,0);
1180 AddIndex((UBYTE *)
"iarg_",4,0);
1181 AddVector((UBYTE *)
"parg_",VARTYPENONE,0);
1183 AM.NumFixedFunctions =
sizeof(fixedfunctions)/
sizeof(
struct fixedfun);
1184 for ( i = 0; i < AM.NumFixedFunctions; i++ ) {
1185 ii = AddFunction((UBYTE *)fixedfunctions[i].
name
1186 ,fixedfunctions[i].commu
1187 ,fixedfunctions[i].tensor
1188 ,fixedfunctions[i].complx
1191 if ( fixedfunctions[i].tensor == GAMMAFUNCTION )
1192 functions[ii].flags |= COULDCOMMUTE;
1201 for ( ; i < FIRSTUSERFUNCTION-FUNCTION; i++ ) {
1202 snprintf(dumstr,20,
"::%d::",i);
1203 AddFunction((UBYTE *)dumstr,0,0,0,0,0,-1,-1);
1206 AM.NumFixedSets =
sizeof(fixedsets)/
sizeof(
struct fixedset);
1207 for ( i = 0; i < AM.NumFixedSets; i++ ) {
1208 ii = AddSet((UBYTE *)fixedsets[i].
name,fixedsets[i].dimension);
1209 Sets[ii].type = fixedsets[i].type;
1211 AM.RepMax = MAXREPEAT;
1213 AT.RepCount = (
int *)Malloc1((LONG)((AM.RepMax+3)*
sizeof(
int)),
"repeat buffers");
1214 AN.RepPoint = AT.RepCount;
1215 AT.RepTop = AT.RepCount + AM.RepMax;
1216 AN.polysortflag = 0;
1219 AC.NumWildcardNames = 0;
1220 AC.WildcardBufferSize = 50;
1221 AC.WildcardNames = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,
"argument list names");
1223 AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*
sizeof(WORD)/2
1224 ,
"argument list names");
1225 AT.WildcardBufferSize = AC.WildcardBufferSize;
1226 AR.CompareRoutine = (COMPAREDUMMY)(&
Compare1);
1227 AT.nfac = AT.nBer = 0;
1232 AR.wranfnpair1 = NPAIR1;
1233 AR.wranfnpair2 = NPAIR2;
1236 AT.NormData = Malloc1(
sizeof(*(AT.NormData)),
"NormData pointers");
1237 AT.NormDataSize = 1;
1238 AT.NormData[0] = AllocNormData();
1242 AM.oldnumextrasymbols = strDup1((UBYTE *)
"OLDNUMEXTRASYMBOLS_",
"oldnumextrasymbols");
1243 PutPreVar((UBYTE *)
"VERSION_",(UBYTE *)STRINGIFY(MAJORVERSION),0,0);
1244 PutPreVar((UBYTE *)
"SUBVERSION_",(UBYTE *)STRINGIFY(MINORVERSION),0,0);
1245 PutPreVar((UBYTE *)
"SUBSUBVERSION_",(UBYTE *)STRINGIFY(PATCHVERSION),0,0);
1246 PutPreVar((UBYTE *)
"DATE_",(UBYTE *)MakeDate(),0,0);
1247 PutPreVar((UBYTE *)
"random_",(UBYTE *)
"________",0,0);
1248 PutPreVar((UBYTE *)
"optimminvar_",(UBYTE *)(
"0"),0,0);
1249 PutPreVar((UBYTE *)
"optimmaxvar_",(UBYTE *)(
"0"),0,0);
1250 PutPreVar(AM.oldnumextrasymbols,(UBYTE *)(
"0"),0,0);
1251 PutPreVar((UBYTE *)
"optimvalue_",(UBYTE *)(
"0"),0,0);
1252 PutPreVar((UBYTE *)
"optimscheme_",(UBYTE *)(
"0"),0,0);
1253 PutPreVar((UBYTE *)
"tolower_",(UBYTE *)(
"0"),0,0);
1254 PutPreVar((UBYTE *)
"toupper_",(UBYTE *)(
"0"),0,0);
1255 PutPreVar((UBYTE *)
"takeleft_",(UBYTE *)(
"0"),0,0);
1256 PutPreVar((UBYTE *)
"takeright_",(UBYTE *)(
"0"),0,0);
1257 PutPreVar((UBYTE *)
"keepleft_",(UBYTE *)(
"0"),0,0);
1258 PutPreVar((UBYTE *)
"keepright_",(UBYTE *)(
"0"),0,0);
1259 PutPreVar((UBYTE *)
"SYSTEMERROR_",(UBYTE *)(
"0"),0,0);
1264 #define STR(x) STR2(x)
1265 PutPreVar((UBYTE *)
"TOPOLOGIESONLY_" ,(UBYTE*)(STR(TOPOLOGIESONLY)) ,0,0);
1266 PutPreVar((UBYTE *)
"WITHOUTNODES_" ,(UBYTE*)(STR(WITHOUTNODES)) ,0,0);
1267 PutPreVar((UBYTE *)
"WITHEDGES_" ,(UBYTE*)(STR(WITHEDGES)) ,0,0);
1268 PutPreVar((UBYTE *)
"WITHBLOCKS_" ,(UBYTE*)(STR(WITHBLOCKS)) ,0,0);
1269 PutPreVar((UBYTE *)
"WITHONEPISETS_" ,(UBYTE*)(STR(WITHONEPISETS)) ,0,0);
1270 PutPreVar((UBYTE *)
"WITHSYMMETRIZEI_",(UBYTE*)(STR(WITHSYMMETRIZEI)),0,0);
1271 PutPreVar((UBYTE *)
"WITHSYMMETRIZEF_",(UBYTE*)(STR(WITHSYMMETRIZEF)),0,0);
1274 PutPreVar((UBYTE *)
"ONEPI_" ,(UBYTE*)(STR(ONEPARTI)) ,0,0);
1275 PutPreVar((UBYTE *)
"ONEPR_" ,(UBYTE*)(STR(ONEPARTR)) ,0,0);
1276 PutPreVar((UBYTE *)
"ONSHELL_" ,(UBYTE*)(STR(ONSHELL)) ,0,0);
1277 PutPreVar((UBYTE *)
"OFFSHELL_" ,(UBYTE*)(STR(OFFSHELL)) ,0,0);
1278 PutPreVar((UBYTE *)
"NOSIGMA_" ,(UBYTE*)(STR(NOSIGMA)) ,0,0);
1279 PutPreVar((UBYTE *)
"SIGMA_" ,(UBYTE*)(STR(SIGMA)) ,0,0);
1280 PutPreVar((UBYTE *)
"NOSNAIL_" ,(UBYTE*)(STR(NOSNAIL)) ,0,0);
1281 PutPreVar((UBYTE *)
"SNAIL_" ,(UBYTE*)(STR(SNAIL)) ,0,0);
1282 PutPreVar((UBYTE *)
"NOTADPOLE_" ,(UBYTE*)(STR(NOTADPOLE)) ,0,0);
1283 PutPreVar((UBYTE *)
"TADPOLE_" ,(UBYTE*)(STR(TADPOLE)) ,0,0);
1284 PutPreVar((UBYTE *)
"SIMPLE_" ,(UBYTE*)(STR(SIMPLE)) ,0,0);
1285 PutPreVar((UBYTE *)
"NOTSIMPLE_" ,(UBYTE*)(STR(NOTSIMPLE)) ,0,0);
1286 PutPreVar((UBYTE *)
"BIPART_" ,(UBYTE*)(STR(BIPART)) ,0,0);
1287 PutPreVar((UBYTE *)
"NONBIPART_" ,(UBYTE*)(STR(NONBIPART)) ,0,0);
1288 PutPreVar((UBYTE *)
"CYCLI_" ,(UBYTE*)(STR(CYCLI)) ,0,0);
1289 PutPreVar((UBYTE *)
"CYCLR_" ,(UBYTE*)(STR(CYCLR)) ,0,0);
1290 PutPreVar((UBYTE *)
"FLOOP_" ,(UBYTE*)(STR(FLOOP)) ,0,0);
1291 PutPreVar((UBYTE *)
"NOTFLOOP_" ,(UBYTE*)(STR(NOTFLOOP)) ,0,0);
1299 pid = ( PF.me == MASTER ) ? GetPID() : (LONG)0;
1303 PutPreVar((UBYTE *)
"PID_",(UBYTE *)buf,0,0);
1306 AP.MaxPreTypes = 10;
1308 AP.PreTypes = (
int *)Malloc1(
sizeof(
int)*(AP.MaxPreTypes+1),
"preprocessor types");
1309 AP.inside.buffer = 0;
1312 AC.SortType = AC.lSortType = AM.gSortType = SORTLOWFIRST;
1315 AR.SortType = AC.SortType;
1318 AC.SetList.numtemp = AC.SetList.num;
1319 AC.SetElementList.numtemp = AC.SetElementList.num;
1321 GetName(AC.varnames,(UBYTE *)
"exp_",&AM.expnum,NOAUTO);
1322 GetName(AC.varnames,(UBYTE *)
"denom_",&AM.denomnum,NOAUTO);
1323 GetName(AC.varnames,(UBYTE *)
"fac_",&AM.facnum,NOAUTO);
1324 GetName(AC.varnames,(UBYTE *)
"invfac_",&AM.invfacnum,NOAUTO);
1325 GetName(AC.varnames,(UBYTE *)
"sum_",&AM.sumnum,NOAUTO);
1326 GetName(AC.varnames,(UBYTE *)
"sump_",&AM.sumpnum,NOAUTO);
1327 GetName(AC.varnames,(UBYTE *)
"term_",&AM.termfunnum,NOAUTO);
1328 GetName(AC.varnames,(UBYTE *)
"match_",&AM.matchfunnum,NOAUTO);
1329 GetName(AC.varnames,(UBYTE *)
"count_",&AM.countfunnum,NOAUTO);
1330 AM.termfunnum += FUNCTION;
1331 AM.matchfunnum += FUNCTION;
1332 AM.countfunnum += FUNCTION;
1334 AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats = 1;
1335 AC.FinalStats = AM.gFinalStats = AM.ggFinalStats = 1;
1336 AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag = 1;
1337 AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag = 1;
1338 AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing = 1;
1339 AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch = 0;
1340 AC.ProcessStats = AM.gProcessStats = AM.ggProcessStats = 1;
1341 AC.OldParallelStats = AM.gOldParallelStats = AM.ggOldParallelStats = 0;
1342 AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag = NEWFACTARG;
1343 AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag = 1;
1344 AC.WTimeStatsFlag = AM.gWTimeStatsFlag = AM.ggWTimeStatsFlag = 0;
1345 AM.gcNumDollars = AP.DollarList.num;
1346 AC.SizeCommuteInSet = AM.gSizeCommuteInSet = 0;
1348 AC.MaxWeight = AM.gMaxWeight = AM.ggMaxWeight = MAXWEIGHT;
1349 AC.DefaultPrecision = AM.gDefaultPrecision = AM.ggDefaultPrecision = DEFAULTPRECISION;
1351 AC.CommuteInSet = 0;
1353 AM.PrintTotalSize = 0;
1355 AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers = 0;
1356 AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace = INDENTSPACE;
1358 AO.OptimizationLevel = 0;
1359 PUTZERO(AS.MaxExprSize);
1360 PUTZERO(AC.StoreFileSize);
1363 AC.inputnumbers = 0;
1365 AC.numpfirstnum = AC.sizepfirstnum = 0;
1367 AC.MemDebugFlag = 1;
1369#ifdef WITHEXTERNALCHANNEL
1370 AX.currentExternalChannel=0;
1371 AX.killSignal=SIGKILL;
1372 AX.killWholeGroup=1;
1376 AX.shellname=strDup1((UBYTE *)
"/bin/sh -c",
"external channel shellname");
1377 AX.stderrname=strDup1((UBYTE *)
"/dev/null",
"external channel stderrname");
1388#ifdef WITHEXTERNALCHANNEL
1394 initPresetExternalChannels((UBYTE*)getenv(
"FORM_PIPES"),AX.timeout);
1404 snprintf((
char*)buf,32,
"%d",PF.me);
1405 PutPreVar((UBYTE *)
"PARALLELTASK_",buf,0,0);
1406 snprintf((
char*)buf,32,
"%d",PF.numtasks);
1407 PutPreVar((UBYTE *)
"NPARALLELTASKS_",buf,0,0);
1410 PutPreVar((UBYTE *)
"PARALLELTASK_",(UBYTE *)
"0",0,0);
1411 PutPreVar((UBYTE *)
"NPARALLELTASKS_",(UBYTE *)
"1",0,0);
1414 PutPreVar((UBYTE *)
"NAME_",AM.InputFileName ? AM.InputFileName : (UBYTE *)
"STDIN",0,0);
1431 WORD *fi, i, one = 1;
1432 CBUF *C = cbuf+AC.cbufnum;
1436 snprintf((
char*)buf,32,
"%d",AM.totalnumberofthreads);
1437 PutPreVar((UBYTE *)
"NTHREADS_",buf,0,1);
1439 PutPreVar((UBYTE *)
"NTHREADS_",(UBYTE *)
"1",0,1);
1444 AR.SortType = AC.SortType = AC.lSortType = AM.gSortType;
1446 AC.OutputSpaces = NORMALFORMAT;
1449 AC.ncmod = AM.gncmod = 0;
1450 AC.modmode = AM.gmodmode = 0;
1451 AC.npowmod = AM.gnpowmod = 0;
1452 AC.halfmod = 0; AC.nhalfmod = 0;
1454 AC.lPolyFun = AM.gPolyFun = 0;
1455 AC.lPolyFunInv = AM.gPolyFunInv = 0;
1456 AC.lPolyFunType = AM.gPolyFunType = 0;
1457 AC.lPolyFunExp = AM.gPolyFunExp = 0;
1458 AC.lPolyFunVar = AM.gPolyFunVar = 0;
1459 AC.lPolyFunPow = AM.gPolyFunPow = 0;
1461 AC.FlintPolyFlag = 1;
1463 AC.FlintPolyFlag = 0;
1466 AC.lDefDim = AM.gDefDim = 4;
1467 AC.lDefDim4 = AM.gDefDim4 = 0;
1468 AC.lUnitTrace = AM.gUnitTrace = 4;
1469 AC.NamesFlag = AM.gNamesFlag = 0;
1470 AC.CodesFlag = AM.gCodesFlag = 0;
1473#ifdef ENABLE_BACKTRACE
1474 AC.PrintBacktraceFlag = 1;
1476 AC.PrintBacktraceFlag = 0;
1479 AC.HumanStatsFlag = 0;
1480 AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols = 0;
1481 AC.extrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1482 AM.gextrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1483 AM.ggextrasym = (UBYTE *)Malloc1(2*
sizeof(UBYTE),
"extrasym");
1484 AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] =
'Z';
1485 AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0;
1486 AC.TokensWriteFlag = AM.gTokensWriteFlag = 0;
1488 AC.LineLength = AM.gLineLength = 79;
1492 AC.OutputSpaces = NORMALFORMAT;
1493 AM.gOutputSpaces = NORMALFORMAT;
1494 AC.OutNumberType = RATIONALMODE;
1495 AM.gOutNumberType = RATIONALMODE;
1497 AR.gzipCompress = GZIPDEFAULT;
1498 AR.FoStage4[0].ziobuffer = 0;
1499 AR.FoStage4[1].ziobuffer = 0;
1502 ZWRAP_useZSTDcompression(1);
1506 AC.bracketindexflag = 0;
1507 AT.bracketindexflag = 0;
1510 AM.gfunpowers = AC.funpowers = COMFUNPOWERS;
1511 AC.parallelflag = AM.gparallelflag;
1512 AC.properorderflag = AM.gproperorderflag = PROPERORDERFLAG;
1513 AC.ProcessBucketSize = AC.mProcessBucketSize = AM.gProcessBucketSize;
1514 AC.ThreadBucketSize = AM.gThreadBucketSize;
1515 AC.ShortStatsMax = 0;
1516 AM.gShortStatsMax = 0;
1517 AM.ggShortStatsMax = 0;
1519 GlobalSymbols = NumSymbols;
1520 GlobalIndices = NumIndices;
1521 GlobalVectors = NumVectors;
1522 GlobalFunctions = NumFunctions;
1523 GlobalSets = NumSets;
1524 GlobalSetElements = NumSetElements;
1525 AC.modpowers = (UWORD *)0;
1529 if ( i > 0 )
do { *fi++ = one; }
while ( --i >= 0 );
1539 for ( i = 8; i < 15; i++ ) AM.Ordering[i] = i;
1541 AC.lUniTrace[0] = SNUMBER;
1545 AC.lUniTrace[2] = 4;
1547 AC.lUniTrace[3] = 1;
1551 AT.MinVecArg[0] = 7+ARGHEAD;
1552 AT.MinVecArg[ARGHEAD] = 7;
1553 AT.MinVecArg[1+ARGHEAD] = INDEX;
1554 AT.MinVecArg[2+ARGHEAD] = 3;
1555 AT.MinVecArg[3+ARGHEAD] = 0;
1556 AT.MinVecArg[4+ARGHEAD] = 1;
1557 AT.MinVecArg[5+ARGHEAD] = 1;
1558 AT.MinVecArg[6+ARGHEAD] = -3;
1560 *t++ = 4+ARGHEAD+FUNHEAD;
1561 for ( i = 1; i < ARGHEAD; i++ ) *t++ = 0;
1565 for ( i = 2; i < FUNHEAD; i++ ) *t++ = 0;
1566 *t++ = 1; *t++ = 1; *t++ = 3;
1573 AT.comsym[1] = SYMBOL;
1584 AT.comfun[0] = FUNHEAD+4;
1585 AT.comfun[1] = FUNCTION;
1586 AT.comfun[2] = FUNHEAD;
1591 AT.comfun[FUNHEAD+1] = 1;
1592 AT.comfun[FUNHEAD+2] = 1;
1593 AT.comfun[FUNHEAD+3] = 3;
1595 AT.comind[1] = INDEX;
1601 AT.locwildvalue[0] = SUBEXPRESSION;
1602 AT.locwildvalue[1] = SUBEXPSIZE;
1603 for ( i = 2; i < SUBEXPSIZE; i++ ) AT.locwildvalue[i] = 0;
1604 AT.mulpat[0] = TYPEMULT;
1605 AT.mulpat[1] = SUBEXPSIZE+3;
1607 AT.mulpat[3] = SUBEXPRESSION;
1608 AT.mulpat[4] = SUBEXPSIZE;
1611 for ( i = 7; i < SUBEXPSIZE+5; i++ ) AT.mulpat[i] = 0;
1612 AT.proexp[0] = SUBEXPSIZE+4;
1613 AT.proexp[1] = EXPRESSION;
1614 AT.proexp[2] = SUBEXPSIZE;
1617 for ( i = 5; i < SUBEXPSIZE+1; i++ ) AT.proexp[i] = 0;
1618 AT.proexp[SUBEXPSIZE+1] = 1;
1619 AT.proexp[SUBEXPSIZE+2] = 1;
1620 AT.proexp[SUBEXPSIZE+3] = 3;
1621 AT.proexp[SUBEXPSIZE+4] = 0;
1622 AT.dummysubexp[0] = SUBEXPRESSION;
1623 AT.dummysubexp[1] = SUBEXPSIZE+4;
1624 for ( i = 2; i < SUBEXPSIZE; i++ ) AT.dummysubexp[i] = 0;
1625 AT.dummysubexp[SUBEXPSIZE] = WILDDUMMY;
1626 AT.dummysubexp[SUBEXPSIZE+1] = 4;
1627 AT.dummysubexp[SUBEXPSIZE+2] = 0;
1628 AT.dummysubexp[SUBEXPSIZE+3] = 0;
1630 AT.inprimelist = -1;
1631 AT.sizeprimelist = 0;
1633 AT.LeaveNegative = 0;
1635 AN.SplitScratch = 0;
1636 AN.SplitScratchSize = AN.InScratch = 0;
1637 AN.SplitScratch1 = 0;
1638 AN.SplitScratchSize1 = AN.InScratch1 = 0;
1639 AN.idfunctionflag = 0;
1641 AO.OutputLine = AO.OutFill = BufferForOutput;
1646 AP.ComChar = AP.cComChar;
1647 AC.cbufnum = AM.rbufnum;
1649 AP.PreAssignFlag = 0;
1659static int exitInProgress = 0;
1660static int trappedTerminate = 0;
1665static int onErrSig(
int i)
1667static void onErrSig(
int i)
1670 if (exitInProgress){
1679 trappedTerminate = 1;
1685static void setNewSig(
int i,
int (*handler)(
int))
1687static void setNewSig(
int i,
void (*handler)(
int))
1692 if ( signal(i,SIG_IGN) !=SIG_IGN)
1697void setSignalHandlers(
void)
1700 setNewSig(SIGSEGV,onErrSig);
1701 setNewSig(SIGFPE,onErrSig);
1702 setNewSig(SIGILL,onErrSig);
1703 setNewSig(SIGEMT,onErrSig);
1704 setNewSig(SIGSYS,onErrSig);
1705 setNewSig(SIGPIPE,onErrSig);
1706 setNewSig(SIGLOST,onErrSig);
1707 setNewSig(SIGXCPU,onErrSig);
1708 setNewSig(SIGXFSZ,onErrSig);
1711 setNewSig(SIGTERM,onErrSig);
1712 setNewSig(SIGINT,onErrSig);
1713 setNewSig(SIGQUIT,onErrSig);
1714 setNewSig(SIGHUP,onErrSig);
1715 setNewSig(SIGALRM,onErrSig);
1716 setNewSig(SIGVTALRM,onErrSig);
1728ALLPRIVATES *ABdummy[10];
1731int main(
int argc,
char **argv)
1734 bzero((
void *)(&A),
sizeof(A));
1737 setSignalHandlers();
1740 _setmode(_fileno(stdout),O_BINARY);
1753 if (
PF_Init(&argc,&argv) ) exit(-1);
1777 if ( ( retval = DoTail(argc,(UBYTE **)argv) ) != 0 ) {
1778 if ( retval > 0 ) Terminate(0);
1781 if ( DoSetups() ) Terminate(-2);
1786 if ( OpenInput() ) Terminate(-3);
1790 if ( TryEnvironment() ) Terminate(-2);
1791 if ( TryFileSetups() ) Terminate(-2);
1792 if ( MakeSetupAllocs() ) Terminate(-2);
1796 if ( AM.totalnumberofthreads == 0 ) AM.totalnumberofthreads = 1;
1797 AS.MultiThreaded = 0;
1799 if ( AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1;
1800 ReserveTempFiles(1);
1801 StartAllThreads(AM.totalnumberofthreads);
1804 ReserveTempFiles(0);
1807 if ( !AM.FromStdin ) PrintHeader(1);
1811 if ( AM.TimeLimit > 0 ) alarm(AM.TimeLimit);
1833void CleanUp(WORD par)
1843 for ( i = 0; i < 3; i++ ) {
1844 if ( AR.Fscr[i].handle >= 0 ) {
1845 if ( AR.Fscr[i].name ) {
1850 CloseFile(AR.Fscr[i].handle);
1851 remove(AR.Fscr[i].name);
1853 AR.Fscr[i].handle = - 1;
1854 AR.Fscr[i].POfill = 0;
1865 if ( AC.StoreHandle >= 0 && par <= 0 ) {
1867 if ( trappedTerminate ) {
1870 SeekFile(AC.StoreHandle,&pos,SEEK_END);
1871 if ( ISNOTZEROPOS(pos) ) {
1872 CloseFile(AC.StoreHandle);
1876 CloseFile(AC.StoreHandle);
1880 if ( par >= 0 || AR.StoreData.Handle < 0 || AM.ClearStore ) {
1885 CloseFile(AC.StoreHandle);
1889 if ( par >= 0 || AR.StoreData.Handle < 0 || AM.ClearStore > 0 ) {
1895 ClearSpectators(CLEARMODULE);
1905 if ( AC.LogHandle >= 0 && par <= 0 ) {
1906 WORD lh = AC.LogHandle;
1909 if ( PF.me == MASTER )
1920static int firstterminate = 1;
1922void TerminateImpl(
int errorcode,
const char* file,
int line,
const char* function)
1925 if ( errorcode && firstterminate && !PF.notMyFault ) {
1927 if ( errorcode && firstterminate ) {
1931 MLOCK(ErrorMessageLock);
1933 MesPrint(
"Program terminating in thread %w at &");
1934#elif defined(WITHMPI)
1935 MesPrint(
"Program terminating in process %w at &");
1937 MesPrint(
"Program terminating at &");
1939 MesPrint(
"Terminate called from %s:%d (%s)", file, line, function);
1941 if ( AC.PrintBacktraceFlag ) {
1942#ifdef ENABLE_BACKTRACE
1944 int stacksize, stop = 0;
1945 stacksize = backtrace(stack,
sizeof(stack)/
sizeof(stack[0]));
1948 if ( !system(
"command -v eu-addr2line > /dev/null 2>&1") ) {
1949 MesPrint(
"Backtrace:");
1950 for (
int i = 0; i < stacksize && !stop; i++) {
1955 MesPrint(
"%#%2d:%", i);
1956 snprintf(cmd+1,
sizeof(cmd)-1,
"eu-addr2line -s --pretty-print -f -i '%p' --pid=%d\n", stack[i], getpid());
1957 fp = popen(cmd+1,
"r");
1958 while ( fgets(cmd+1,
sizeof(cmd)-1, fp) != NULL ) {
1959 MesPrint(
"%s", cmd);
1961 if ( strstr(cmd,
" main ") || strstr(cmd,
" RunThread ") || strstr(cmd,
" RunSortBot ") ) {
1969 else if ( !system(
"command -v addr2line > /dev/null 2>&1") ) {
1971 char exe_path[PATH_MAX];
1973 ssize_t len = readlink(
"/proc/self/exe", exe_path,
sizeof(exe_path) - 1);
1975 exe_path[len] =
'\0';
1978 goto backtrace_fallback;
1982 uintptr_t base_address = 0;
1985 FILE *maps = fopen(
"/proc/self/maps",
"r");
1987 goto backtrace_fallback;
1990 if ( fgets(line,
sizeof(line), maps) ) {
1991 sscanf(line,
"%" SCNxPTR
"-", &base_address);
1995 goto backtrace_fallback;
2000 strings = backtrace_symbols(stack, stacksize);
2001 MesPrint(
"Backtrace:");
2002 for (
int i = 0; i < stacksize && !stop; i++ ) {
2004 char cmd[PATH_MAX + 512];
2007 uintptr_t addr = (uintptr_t)stack[i] - base_address;
2008 MesPrint(
"%#%2d:%", i);
2009 snprintf(cmd+1,
sizeof(cmd)-1,
"addr2line -e \"%s\" -i -p -s -f -C 0x%" PRIxPTR, exe_path, addr);
2010 fp = popen(cmd+1,
"r");
2011 while ( fgets(cmd+1,
sizeof(cmd)-1, fp) != NULL ) {
2012 MesPrint(
"%s", cmd);
2014 if ( strstr(cmd,
" main ") || strstr(cmd,
" RunThread ") || strstr(cmd,
" RunSortBot ") ) {
2026backtrace_fallback: ;
2029 strings = backtrace_symbols(stack, stacksize);
2030 MesPrint(
"Backtrace:");
2031 for (
int i = 0; i < stacksize && !stop; i++ ) {
2032 char *p = strings[i];
2033 while ( *p && *p !=
'(' ) p++;
2034 MesPrint(
"%#%2d: %s\n", i, p);
2036 if ( strstr(p,
"(main+") || strstr(p,
"(RunThread+") || strstr(p,
"(RunSortBot+") ) {
2041 MesPrint(
"Please install addr2line or eu-addr2line for readable stack information.");
2043 MesPrint(
"Please install eu-addr2line for readable stack information.");
2048 MesPrint(
"FORM compiled without backtrace support.");
2052 MUNLOCK(ErrorMessageLock);
2062#ifdef WITHEXTERNALCHANNEL
2067 closeAllExternalChannels();
2068 AX.currentExternalChannel=0;
2070 AX.killSignal=SIGKILL;
2071 AX.killWholeGroup=1;
2074 if(AX.currentPrompt){
2075 M_free(AX.currentPrompt,
"external channel prompt");
2080 M_free(AX.shellname,
"external channel shellname");
2084 M_free(AX.stderrname,
"external channel stderrname");
2090 if ( !WhoAmI() && !errorcode ) {
2091 TerminateAllThreads();
2094 if ( AC.FinalStats ) {
2095 if ( AM.PrintTotalSize ) {
2096 MesPrint(
"Max. space for expressions: %19p bytes",&(AS.MaxExprSize));
2101 if ( AM.HoldFlag && PF.me == MASTER ) {
2102 WriteFile(AM.StdOut,(UBYTE *)(
"Hit any key "),12);
2107 if ( AM.HoldFlag ) {
2108 WriteFile(AM.StdOut,(UBYTE *)(
"Hit any key "),12);
2120 flint_final_cleanup_master();
2125 P_term(errorcode? 0: 1);
2144 if ( PF.me != MASTER )
return;
2146 if ( AM.IgnoreDeprecation )
return;
2148 UBYTE *e = (UBYTE *)getenv(
"FORM_IGNORE_DEPRECATION");
2149 if ( e && e[0] && StrCmp(e, (UBYTE *)
"0") && StrICmp(e, (UBYTE *)
"false") && StrICmp(e, (UBYTE *)
"no") )
return;
2151 MesPrint(
"DeprecationWarning: We are considering deprecating %s.", feature);
2152 MesPrint(
"If you want this support to continue, leave a comment at:");
2154 MesPrint(
" https://github.com/form-dev/form/%s", issue);
2156 MesPrint(
"Otherwise, it will be discontinued in the future.");
2157 MesPrint(
"To suppress this warning, use the -ignore-deprecation command line option or");
2158 MesPrint(
"set the environment variable FORM_IGNORE_DEPRECATION=1.");
2166void PrintRunningTime(
void)
2168#if (defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))) || defined(WITHMPI)
2173#if defined(WITHPTHREADS)
2175 workertime = GetWorkerTimes();
2178 if ( PF.me == MASTER ) {
2180 mastertime = AM.SumTime +
TimeCPU(1);
2182 totaltime = mastertime+workertime;
2184 MesPrint(
" %l.%2i sec + %l.%2i sec: %l.%2i sec out of %l.%2i sec",
2185 mastertime/1000,(WORD)((mastertime%1000)/10),
2186 workertime/1000,(WORD)((workertime%1000)/10),
2187 totaltime/1000,(WORD)((totaltime%1000)/10),
2188 wallclocktime/100,(WORD)(wallclocktime%100));
2192 LONG mastertime = AM.SumTime +
TimeCPU(1);
2195 MesPrint(
" %l.%2i sec out of %l.%2i sec",
2196 mastertime/1000,(WORD)((mastertime%1000)/10),
2197 wallclocktime/100,(WORD)(wallclocktime%100));
2207LONG GetRunningTime(
void)
2209#if defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))
2218 LONG workertime = GetWorkerTimes();
2219 mastertime = AM.SumTime +
TimeCPU(1);
2220 return(mastertime+workertime);
2226 return(AM.SumTime +
TimeCPU(1));
2228#elif defined(WITHMPI)
2229 LONG mastertime, t = 0;
2231 if ( PF.me == MASTER ) {
2232 mastertime = AM.SumTime +
TimeCPU(1);
2233 t = mastertime + workertime;
2237 return(AM.SumTime +
TimeCPU(1));
void DeleteRecoveryFile(void)
int CheckRecoveryFile(void)
void PrintFeatureList(void)
WORD Compare1(PHEAD WORD *, WORD *, WORD)
int PutPreVar(UBYTE *, UBYTE *, UBYTE *, int)
void flint_check_version(void)
int PF_Init(int *argc, char ***argv)
LONG PF_GetSlaveTimes(void)
void PF_PreTerminate(int errorcode)
int PF_Terminate(int errorcode)
void PF_FlushStdOutBuffer(void)
LONG PF_BroadcastNumber(LONG x)
void StartVariables(void)
void PrintDeprecation(const char *feature, const char *issue)