File: startup.c

package info (click to toggle)
form 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 8,312 kB
  • sloc: ansic: 110,546; cpp: 20,395; sh: 5,874; makefile: 545
file content (2231 lines) | stat: -rw-r--r-- 64,491 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
/** @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 attempts some cleanup.
 *	Here is the routine that analyses the command tail.
 */
/* #[ License : */
/*
 *   Copyright (C) 1984-2026 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
#ifdef ENABLE_BACKTRACE
	#include <execinfo.h>
#ifdef LINUX
	#include <stdint.h>
	#include <inttypes.h>
#endif
#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) "." STRINGIFY(REPO_PATCH_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
	#define PATCHVERSION REPO_PATCH_VERSION
#else
	/*
	 * Otherwise, form3.h defines MAJORVERSION, MINORVERSION, PATCHVERSION
	 * and PRODUCTIONDATE, possibly BETAVERSION.
	 */
	#ifdef BETAVERSION
		#define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION) "." STRINGIFY(PATCHVERSION) "Beta"
	#else
		#define VERSIONSTR__ STRINGIFY(MAJORVERSION) "." STRINGIFY(MINORVERSION) "." STRINGIFY(PATCHVERSION)
	#endif
	#define VERSIONSTR FORMNAME " " VERSIONSTR__ " (" PRODUCTIONDATE ")"
#endif

/*
 		#] includes : 
 		#[ PrintHeader :
*/

/**
 * Prints build information.
 *
 * @note As a configure-time assumption, the C and C++ compilers are from
 *       the same vendor and have the same version.
 */
static void PrintBuildInfo(void) {
#if defined(__INTEL_LLVM_COMPILER)
	MesPrint("Compiler: Intel LLVM oneAPI %d",__INTEL_LLVM_COMPILER);
#elif defined(__INTEL_COMPILER)
	MesPrint("Compiler: Intel Classic %d",__INTEL_COMPILER);
#elif defined(__clang__) && defined(__apple_build_version__)
	MesPrint("Compiler: Apple Clang %d.%d.%d (build %d)",__clang_major__,__clang_minor__,__clang_patchlevel__,__apple_build_version__);
#elif defined(__clang__)
	MesPrint("Compiler: Clang %d.%d.%d",__clang_major__,__clang_minor__,__clang_patchlevel__);
#elif defined(__GNUC__)
	MesPrint("Compiler: GCC %d.%d.%d",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);
#elif defined(_MSC_VER)
	MesPrint("Compiler: MSVC %d",_MSC_VER);
#else
	MesPrint("Compiler: Unknown");
#endif

#if defined(__x86_64__) || defined(_M_X64)
	MesPrint("Architecture: x86_64");
#elif defined(__i386__) || defined(_M_IX86)
	MesPrint("Architecture: x86 (32-bit)");
#elif defined(__aarch64__) || defined(_M_ARM64)
	MesPrint("Architecture: arm64");
#elif defined(__arm__) || defined(_M_ARM)
	MesPrint("Architecture: arm (32-bit)");
#else
	MesPrint("Architecture: Unknown");
#endif
}

/**
 * Prints the header line of the output.
 *
 * @param  par  Controls the output mode
 *              (0: default,
 *               1: including runtime information,
 *               2: including verbose version information).
 */
static void PrintHeader(int par)
{
#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;
		}
/*
		By now we omit the message about 32/64 bits. It should all be 64.

		s += snprintf(s,250-(s-buffer1)," %d-bits",(WORD)(sizeof(WORD)*16));
		*s = 0;
*/
		if ( par == 1 ) {
#if defined(WITHPTHREADS) || defined(WITHMPI)
#if defined(WITHPTHREADS)
			int nworkers = AM.totalnumberofthreads-1;
#elif defined(WITHMPI)
			int nworkers = PF.numtasks-1;
#endif
			s += snprintf(s,250-(s-buffer1)," %d worker",nworkers);
			*s = 0;
/*			while ( *s ) s++; */
			if ( nworkers != 1 ) {
				*s++ = 's';
				*s = '\0';
			}
#endif

			snprintf(t,80-(t-buffer2),"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;
		}

		if ( par == 2 ) {
			PrintFeatureList();
			PrintBuildInfo();
		}
	}
#ifdef WINDOWS
	PrintDeprecation("the native Windows version", "issues/623");
#endif
#if BITSINWORD == 16
	PrintDeprecation("the 32-bit version", "issues/624");
#endif
#ifdef WITHMPI
	PrintDeprecation("the MPI version (ParFORM)", "issues/625");
#endif
	if ( AC.CheckpointFlag ) {
		PrintDeprecation("the checkpoint mechanism", "issues/626");
	}
}

/*
 		#] 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;
	/* Always use MultiRun, "-M" option is now ignored. */
	AM.MultiRun = 1;
	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;
				case 'i':
							if ( StrCmp(s, (UBYTE *)"ignore-deprecation") == 0 ) {
								AM.IgnoreDeprecation = 1;
								break;
							}
#ifdef WITHINTERACTION
							/* Interactive session (not used yet) */
							AM.Interact = 1;
							break;
#else
							goto IllegalOption;
#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 */
							/* This option is now ignored. We always use MultiRun. */
							/* 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': /* Print version information */
							AC.FinalStats = 0;
							if ( s[1] == 'v' ) {  /* verbose version information */
								PrintHeader(2);
								return(1);
							}
printversion:;
							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 {
IllegalOption:
#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(void)
{
	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";
/* This is the length of the above default, but with 7 spaces for PID digits
   instead of the "xxx". (Previously FORM used 5 digits and this value was 14) */
#define DEFAULTFNAMELENGTH 16

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 != PATHSEPARATOR ) { if ( *s == '\\' ) s++; s++; i++; }
	FG.fnamesize = sizeof(UBYTE)*(i+DEFAULTFNAMELENGTH);
	FG.fname = (char *)Malloc1(FG.fnamesize,"name for temporary files");
	s = AM.TempDir; t = (UBYTE *)FG.fname;
	while ( *s && *s != PATHSEPARATOR ) { 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 != PATHSEPARATOR ) { if ( *s == '\\' ) s++; s++; i++; }

	FG.fname2size = sizeof(UBYTE)*(i+DEFAULTFNAMELENGTH);
	FG.fname2 = (char *)Malloc1(FG.fname2size,"name for sort files");
	s = AM.TempSortDir; t = (UBYTE *)FG.fname2;
	while ( *s && *s != PATHSEPARATOR ) { 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;
		iii = snprintf((char*)t,FG.fnamesize-((char*)t-FG.fname),"%d",PF.me);
		t+= iii;
		s+= iii; /* in case defaulttmpfilename is too short */
	}
#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 controlled with the -M (MultiRun) parameter in the
		command tail.
*/
	if ( AM.MultiRun ) {
		int num = ((int)GetPID())%10000000;
		t += 4;
		*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)%10);
		t[-10] = (UBYTE)('0' + (num/100000)%10);
		t[-11] = (UBYTE)('0' + num/1000000);
		if ( ( AC.StoreHandle = CreateFile((char *)FG.fname) ) < 0 ) {
			t[-5] = 'x'; t[-6] = 'x'; t[-7] = 'x'; t[-8] = 'x'; t[-9] = 'x'; t[-10] = 'x'; t[-11] = '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 assign a name to the main sort file and the two stage 4 files.
*/
	AM.S0->file.name = (char *)Malloc1(sizeof(char)*(i+DEFAULTFNAMELENGTH),"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;
	}
/*
	Try to create the sort file already, so we can Terminate earlier if this fails.
*/
#ifdef WITHPTHREADS
	if ( par <= 1 ) {
#endif
	if ( ( AM.S0->file.handle = CreateFile((char *)AM.S0->file.name) ) < 0 ) {
		MesPrint("Could not create sort file: %s", AM.S0->file.name);
		Terminate(-1);
	};
	/* Close and clean up the test file */
	CloseFile(AM.S0->file.handle);
	AM.S0->file.handle = -1;
	remove(AM.S0->file.name);
#ifdef WITHPTHREADS
	}
#endif
/*
	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++; }
		/* +1 for null terminator */
		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++; }
		/* +1 for null terminator */
		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++ ) {
			/* +1 for null terminator */
			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 ) {
		size_t tname;
		s = (UBYTE *)((void *)(FG.fname2)); i = 0;
		while ( *s ) { s++; i++; }
		/* +1 for null terminator, +10 for 32bit int, +1 for "." */
		tname = sizeof(char)*(i+12);
		s = (UBYTE *)Malloc1(tname,"name for stage4 file a");
		snprintf((char *)s,tname,"%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++; }
		/* +1 for null terminator, +10 for 32bit int, +1 for "." */
		tname = sizeof(char)*(i+12);
		s = (UBYTE *)Malloc1(tname,"name for stage4 file b");
		snprintf((char *)s,tname,"%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++ ) {
				/* +1 for null terminator */
				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(void)
{
	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 = '*';
	AP.firstnamespace = 0;
	AP.lastnamespace = 0;
	AP.fullnamesize = 127;
	AP.fullname = (UBYTE *)Malloc1((AP.fullnamesize+1)*sizeof(UBYTE),"AP.fullname");
	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;
	AC.models = 0;
	AC.nummodels = 0;
	AC.ModelLevel = 0;
	AC.modelspace = 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;
 	AC.doloopstack = 0;
 	AC.doloopstacksize = 0;
 	AC.dolooplevel = 0;
/*
	Set up the main name trees:
*/
	AC.varnames  = MakeNameTree();
	AC.exprnames = MakeNameTree();
	AC.dollarnames = MakeNameTree();
	AC.autonames = MakeNameTree();
	AC.activenames = &(AC.varnames);
	AP.preError = 0;
/*
	Initialize the compiler:
*/
	inictable();
	AM.rbufnum = inicbufs();		/* Regular compiler buffer */
#ifndef WITHPTHREADS
	AT.ebufnum = inicbufs();		/* Buffer for extras during execution */
	AT.fbufnum = inicbufs();		/* Buffer for caching in factorization */
	AT.allbufnum = inicbufs();		/* Buffer for id,all */
	AT.aebufnum = inicbufs();		/* Buffer for id,all */
	AN.tryterm = 0;
#else
	AS.MasterSort = 0;
#endif
	AM.dbufnum = inicbufs();		/* Buffer for dollar variables */
	AM.sbufnum = inicbufs();		/* Subterm buffer for polynomials and optimization */
	AC.ffbufnum = inicbufs();		/* Buffer number for user defined factorizations */
	AM.zbufnum = inicbufs();		/* For very special values */
	{
		CBUF *C = cbuf+AM.zbufnum;
		WORD one[5] = {4,1,1,3,0};
		WORD zero = 0;
		AddRHS(AM.zbufnum,1);
		AM.zerorhs = C->numrhs;
		AddNtoC(AM.zbufnum,1,&zero,17);
		AddRHS(AM.zbufnum,1);
		AM.onerhs = C->numrhs;
		AddNtoC(AM.zbufnum,5,one,17);
	}
	AP.inside.inscbuf = inicbufs();	/* For the #inside instruction */
/*
	Enter the built in objects
*/
	AC.Symbols = &(AC.SymbolList);
	AC.Indices = &(AC.IndexList);
	AC.Vectors = &(AC.VectorList);
	AC.Functions = &(AC.FunctionList);
	AC.vetofilling = 0;

	AddDollar((UBYTE *)"$",DOLUNDEFINED,0,0);

	cbuf[AM.dbufnum].mnumlhs = cbuf[AM.dbufnum].numlhs;
	cbuf[AM.dbufnum].mnumrhs = cbuf[AM.dbufnum].numrhs;

	AddSymbol((UBYTE *)"i_",-MAXPOWER,MAXPOWER,VARTYPEIMAGINARY,0);
	AddSymbol((UBYTE *)"pi_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
/*
	coeff_ should have the number COEFFSYMBOL and den_ the number DENOMINATOR
    and the three should be in this order!
*/
	AddSymbol((UBYTE *)"coeff_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	AddSymbol((UBYTE *)"num_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	AddSymbol((UBYTE *)"den_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	AddSymbol((UBYTE *)"xarg_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	AddSymbol((UBYTE *)"dimension_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	AddSymbol((UBYTE *)"factor_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	AddSymbol((UBYTE *)"sep_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	AddSymbol((UBYTE *)"ee_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	AddSymbol((UBYTE *)"em_",-MAXPOWER,MAXPOWER,VARTYPENONE,0);
	i = BUILTINSYMBOLS;  /* update this in ftypes.h when we add new symbols */
/*
	Next we add a number of dummy symbols for ensuring that the user defined
	symbols start at a fixed given number FIRSTUSERSYMBOL
	We do want to give them unique names though that the user cannot access.
*/
	{
		char dumstr[20];
		for ( ; i < FIRSTUSERSYMBOL; i++ ) {
			snprintf(dumstr,20,":%d:",i);
			AddSymbol((UBYTE *)dumstr,-MAXPOWER,MAXPOWER,VARTYPENONE,0);
		}
	}

	AddIndex((UBYTE *)"iarg_",4,0);
	AddVector((UBYTE *)"parg_",VARTYPENONE,0);

	AM.NumFixedFunctions = sizeof(fixedfunctions)/sizeof(struct fixedfun);
	for ( i = 0; i < AM.NumFixedFunctions; i++ ) {
		ii = AddFunction((UBYTE *)fixedfunctions[i].name
		                         ,fixedfunctions[i].commu
		                         ,fixedfunctions[i].tensor
		                         ,fixedfunctions[i].complx
		                         ,fixedfunctions[i].symmetric
		                         ,0,-1,-1);
		if ( fixedfunctions[i].tensor == GAMMAFUNCTION )
							functions[ii].flags |= COULDCOMMUTE;
	}
/*
	Next we add a number of dummy functions for ensuring that the user defined
	functions start at a fixed given number FIRSTUSERFUNCTION.
	We do want to give them unique names though that the user cannot access.
*/
	{
		char dumstr[20];
		for ( ; i < FIRSTUSERFUNCTION-FUNCTION; i++ ) {
			snprintf(dumstr,20,"::%d::",i);
			AddFunction((UBYTE *)dumstr,0,0,0,0,0,-1,-1);
		}
	}
	AM.NumFixedSets = sizeof(fixedsets)/sizeof(struct fixedset);
	for ( i = 0; i < AM.NumFixedSets; i++ ) {
		ii = AddSet((UBYTE *)fixedsets[i].name,fixedsets[i].dimension);
		Sets[ii].type = fixedsets[i].type;
	}
	AM.RepMax = MAXREPEAT;
#ifndef WITHPTHREADS
	AT.RepCount = (int *)Malloc1((LONG)((AM.RepMax+3)*sizeof(int)),"repeat buffers");
	AN.RepPoint = AT.RepCount;
	AT.RepTop = AT.RepCount + AM.RepMax;
	AN.polysortflag = 0;
	AN.subsubveto = 0;
#endif
	AC.NumWildcardNames = 0;
	AC.WildcardBufferSize = 50;
	AC.WildcardNames = (UBYTE *)Malloc1((LONG)AC.WildcardBufferSize,"argument list names");
#ifndef WITHPTHREADS
	AT.WildArgTaken = (WORD *)Malloc1((LONG)AC.WildcardBufferSize*sizeof(WORD)/2
				,"argument list names");
	AT.WildcardBufferSize = AC.WildcardBufferSize;
	AR.CompareRoutine = (COMPAREDUMMY)(&Compare1);
	AT.nfac = AT.nBer = 0;
	AT.factorials = 0;
	AT.bernoullis = 0;
	AR.wranfia = 0;
	AR.wranfcall = 0;
	AR.wranfnpair1 = NPAIR1;
	AR.wranfnpair2 = NPAIR2;
	AR.wranfseed = 0;
#endif
	AM.atstartup = 1;
	AM.oldnumextrasymbols = strDup1((UBYTE *)"OLDNUMEXTRASYMBOLS_","oldnumextrasymbols");
	PutPreVar((UBYTE *)"VERSION_",(UBYTE *)STRINGIFY(MAJORVERSION),0,0);
	PutPreVar((UBYTE *)"SUBVERSION_",(UBYTE *)STRINGIFY(MINORVERSION),0,0);
	PutPreVar((UBYTE *)"SUBSUBVERSION_",(UBYTE *)STRINGIFY(PATCHVERSION),0,0);
	PutPreVar((UBYTE *)"DATE_",(UBYTE *)MakeDate(),0,0);
	PutPreVar((UBYTE *)"random_",(UBYTE *)"________",0,0);
	PutPreVar((UBYTE *)"optimminvar_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"optimmaxvar_",(UBYTE *)("0"),0,0);
	PutPreVar(AM.oldnumextrasymbols,(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"optimvalue_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"optimscheme_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"tolower_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"toupper_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"takeleft_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"takeright_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"keepleft_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"keepright_",(UBYTE *)("0"),0,0);
	PutPreVar((UBYTE *)"SYSTEMERROR_",(UBYTE *)("0"),0,0);
/*
	Next are the flags to control diagram generation filters
*/
	#define STR2(x) #x
	#define STR(x) STR2(x)
	PutPreVar((UBYTE *)"TOPOLOGIESONLY_" ,(UBYTE*)(STR(TOPOLOGIESONLY)) ,0,0);
	PutPreVar((UBYTE *)"WITHOUTNODES_"   ,(UBYTE*)(STR(WITHOUTNODES))   ,0,0);
	PutPreVar((UBYTE *)"WITHEDGES_"      ,(UBYTE*)(STR(WITHEDGES))      ,0,0);
	PutPreVar((UBYTE *)"WITHBLOCKS_"     ,(UBYTE*)(STR(WITHBLOCKS))     ,0,0);
	PutPreVar((UBYTE *)"WITHONEPISETS_"  ,(UBYTE*)(STR(WITHONEPISETS))  ,0,0);
	PutPreVar((UBYTE *)"WITHSYMMETRIZEI_",(UBYTE*)(STR(WITHSYMMETRIZEI)),0,0);
	PutPreVar((UBYTE *)"WITHSYMMETRIZEF_",(UBYTE*)(STR(WITHSYMMETRIZEF)),0,0);
	// This is not an "option" preprocessor var but is set by "external" particle definitions
//	PutPreVar((UBYTE *)"CHECKEXTERN_"    ,(UBYTE*)(STR(CHECKEXTERN))    ,0,0);
	PutPreVar((UBYTE *)"ONEPI_"          ,(UBYTE*)(STR(ONEPARTI))       ,0,0);
	PutPreVar((UBYTE *)"ONEPR_"          ,(UBYTE*)(STR(ONEPARTR))       ,0,0);
	PutPreVar((UBYTE *)"ONSHELL_"        ,(UBYTE*)(STR(ONSHELL))        ,0,0);
	PutPreVar((UBYTE *)"OFFSHELL_"       ,(UBYTE*)(STR(OFFSHELL))       ,0,0);
	PutPreVar((UBYTE *)"NOSIGMA_"        ,(UBYTE*)(STR(NOSIGMA))        ,0,0);
	PutPreVar((UBYTE *)"SIGMA_"          ,(UBYTE*)(STR(SIGMA))          ,0,0);
	PutPreVar((UBYTE *)"NOSNAIL_"        ,(UBYTE*)(STR(NOSNAIL))        ,0,0);
	PutPreVar((UBYTE *)"SNAIL_"          ,(UBYTE*)(STR(SNAIL))          ,0,0);
	PutPreVar((UBYTE *)"NOTADPOLE_"      ,(UBYTE*)(STR(NOTADPOLE))      ,0,0);
	PutPreVar((UBYTE *)"TADPOLE_"        ,(UBYTE*)(STR(TADPOLE))        ,0,0);
	PutPreVar((UBYTE *)"SIMPLE_"         ,(UBYTE*)(STR(SIMPLE))         ,0,0);
	PutPreVar((UBYTE *)"NOTSIMPLE_"      ,(UBYTE*)(STR(NOTSIMPLE))      ,0,0);
	PutPreVar((UBYTE *)"BIPART_"         ,(UBYTE*)(STR(BIPART))         ,0,0);
	PutPreVar((UBYTE *)"NONBIPART_"      ,(UBYTE*)(STR(NONBIPART))      ,0,0);
	PutPreVar((UBYTE *)"CYCLI_"          ,(UBYTE*)(STR(CYCLI))          ,0,0);
	PutPreVar((UBYTE *)"CYCLR_"          ,(UBYTE*)(STR(CYCLR))          ,0,0);
	PutPreVar((UBYTE *)"FLOOP_"          ,(UBYTE*)(STR(FLOOP))          ,0,0);
	PutPreVar((UBYTE *)"NOTFLOOP_"       ,(UBYTE*)(STR(NOTFLOOP))       ,0,0);

	{
		char buf[41];  /* up to 128-bit */
		LONG pid;
#ifndef WITHMPI
		pid = GetPID();
#else
		pid = ( PF.me == MASTER ) ? GetPID() : (LONG)0;
		pid = PF_BroadcastNumber(pid);
#endif
		LongCopy(pid,buf);
		PutPreVar((UBYTE *)"PID_",(UBYTE *)buf,0,0);
	}
	AM.atstartup = 0;
	AP.MaxPreTypes = 10;
	AP.NumPreTypes = 0;
	AP.PreTypes = (int *)Malloc1(sizeof(int)*(AP.MaxPreTypes+1),"preprocessor types");
	AP.inside.buffer = 0;
	AP.inside.size = 0;

	AC.SortType = AC.lSortType = AM.gSortType = SORTLOWFIRST;
#ifdef WITHPTHREADS
#else
	AR.SortType = AC.SortType;
#endif
	AC.LogHandle = -1;
	AC.SetList.numtemp        = AC.SetList.num;
	AC.SetElementList.numtemp = AC.SetElementList.num;

	GetName(AC.varnames,(UBYTE *)"exp_",&AM.expnum,NOAUTO);
	GetName(AC.varnames,(UBYTE *)"denom_",&AM.denomnum,NOAUTO);
	GetName(AC.varnames,(UBYTE *)"fac_",&AM.facnum,NOAUTO);
	GetName(AC.varnames,(UBYTE *)"invfac_",&AM.invfacnum,NOAUTO);
	GetName(AC.varnames,(UBYTE *)"sum_",&AM.sumnum,NOAUTO);
	GetName(AC.varnames,(UBYTE *)"sump_",&AM.sumpnum,NOAUTO);
	GetName(AC.varnames,(UBYTE *)"term_",&AM.termfunnum,NOAUTO);
	GetName(AC.varnames,(UBYTE *)"match_",&AM.matchfunnum,NOAUTO);
	GetName(AC.varnames,(UBYTE *)"count_",&AM.countfunnum,NOAUTO);
	AM.termfunnum += FUNCTION;
	AM.matchfunnum += FUNCTION;
	AM.countfunnum += FUNCTION;

	AC.ThreadStats = AM.gThreadStats = AM.ggThreadStats = 1;
	AC.FinalStats = AM.gFinalStats = AM.ggFinalStats = 1;
	AC.StatsFlag = AM.gStatsFlag = AM.ggStatsFlag = 1;
	AC.ThreadsFlag = AM.gThreadsFlag = AM.ggThreadsFlag = 1;
	AC.ThreadBalancing = AM.gThreadBalancing = AM.ggThreadBalancing = 1;
	AC.ThreadSortFileSynch = AM.gThreadSortFileSynch = AM.ggThreadSortFileSynch = 0;
	AC.ProcessStats = AM.gProcessStats = AM.ggProcessStats = 1;
	AC.OldParallelStats = AM.gOldParallelStats = AM.ggOldParallelStats = 0;
	AC.OldFactArgFlag = AM.gOldFactArgFlag = AM.ggOldFactArgFlag = NEWFACTARG;
	AC.OldGCDflag = AM.gOldGCDflag = AM.ggOldGCDflag = 1;
	AC.WTimeStatsFlag = AM.gWTimeStatsFlag = AM.ggWTimeStatsFlag = 0;
	AM.gcNumDollars = AP.DollarList.num;
	AC.SizeCommuteInSet = AM.gSizeCommuteInSet = 0;
#ifdef WITHFLOAT
	AC.MaxWeight = AM.gMaxWeight = AM.ggMaxWeight = MAXWEIGHT;
	AC.DefaultPrecision = AM.gDefaultPrecision = AM.ggDefaultPrecision = DEFAULTPRECISION;
#endif
	AC.CommuteInSet = 0;

	AM.PrintTotalSize = 0;

	AO.NoSpacesInNumbers = AM.gNoSpacesInNumbers = AM.ggNoSpacesInNumbers = 0;
	AO.IndentSpace = AM.gIndentSpace = AM.ggIndentSpace = INDENTSPACE;
	AO.BlockSpaces = 0;
	AO.OptimizationLevel = 0;
	PUTZERO(AS.MaxExprSize);
	PUTZERO(AC.StoreFileSize);

#ifdef WITHPTHREADS
	AC.inputnumbers = 0;
	AC.pfirstnum = 0;
	AC.numpfirstnum = AC.sizepfirstnum = 0;
#endif
	AC.MemDebugFlag = 1;

#ifdef WITHEXTERNALCHANNEL
	AX.currentExternalChannel=0;
	AX.killSignal=SIGKILL;
	AX.killWholeGroup=1;
	AX.daemonize=1;
	AX.currentPrompt=0;
	AX.timeout=1000;/*One second to initialize preset channels*/
	AX.shellname=strDup1((UBYTE *)"/bin/sh -c","external channel shellname");
	AX.stderrname=strDup1((UBYTE *)"/dev/null","external channel stderrname");
#endif
}

/*
 		#] StartVariables : 
 		#[ StartMore :
*/

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

#ifdef WITHMPI
/*
	Define preprocessor variable PARALLELTASK_ as a process number, 0 is the master
	Define preprocessor variable NPARALLELTASKS_ as a total number of processes
*/
	{
		UBYTE buf[32];
		snprintf((char*)buf,32,"%d",PF.me);
		PutPreVar((UBYTE *)"PARALLELTASK_",buf,0,0);
		snprintf((char*)buf,32,"%d",PF.numtasks);
		PutPreVar((UBYTE *)"NPARALLELTASKS_",buf,0,0);
	}
#else
	PutPreVar((UBYTE *)"PARALLELTASK_",(UBYTE *)"0",0,0);
	PutPreVar((UBYTE *)"NPARALLELTASKS_",(UBYTE *)"1",0,0);
#endif

	PutPreVar((UBYTE *)"NAME_",AM.InputFileName ? AM.InputFileName : (UBYTE *)"STDIN",0,0);
}

/*
 		#] StartMore : 
 		#[ IniVars :

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

void IniVars(void)
{
#ifdef WITHPTHREADS
	GETIDENTITY
#else
	WORD *t;
#endif
	WORD *fi, i, one = 1;
	CBUF *C = cbuf+AC.cbufnum;

#ifdef WITHPTHREADS
	UBYTE buf[32];
	snprintf((char*)buf,32,"%d",AM.totalnumberofthreads);
	PutPreVar((UBYTE *)"NTHREADS_",buf,0,1);
#else
	PutPreVar((UBYTE *)"NTHREADS_",(UBYTE *)"1",0,1);
#endif

	AC.ShortStats = 0;
	AC.WarnFlag = 1;
	AR.SortType = AC.SortType = AC.lSortType = AM.gSortType;
	AC.OutputMode = 72;
	AC.OutputSpaces = NORMALFORMAT;
	AR.Eside = 0;
	AC.DumNum = 0;
	AC.ncmod = AM.gncmod = 0;
	AC.modmode = AM.gmodmode = 0;
	AC.npowmod = AM.gnpowmod = 0;
	AC.halfmod = 0; AC.nhalfmod = 0;
	AC.modinverses = 0;
	AC.lPolyFun = AM.gPolyFun = 0;
	AC.lPolyFunInv = AM.gPolyFunInv = 0;
	AC.lPolyFunType = AM.gPolyFunType = 0;
	AC.lPolyFunExp = AM.gPolyFunExp = 0;
	AC.lPolyFunVar = AM.gPolyFunVar = 0;
	AC.lPolyFunPow = AM.gPolyFunPow = 0;
#ifdef WITHFLINT
	AC.FlintPolyFlag = 1;
#else
	AC.FlintPolyFlag = 0;
#endif
	AC.DirtPow = 0;
	AC.lDefDim = AM.gDefDim = 4;
	AC.lDefDim4 = AM.gDefDim4 = 0;
	AC.lUnitTrace = AM.gUnitTrace = 4;
	AC.NamesFlag = AM.gNamesFlag = 0;
	AC.CodesFlag = AM.gCodesFlag = 0;
	/* Printing a backtrace on crash is on by default for both normal and debug
		modes if FORM has been compiled with backtrace support. */
#ifdef ENABLE_BACKTRACE
	AC.PrintBacktraceFlag = 1;
#else
	AC.PrintBacktraceFlag = 0;
#endif
	/* Human-readable statistics are off by default */
	AC.HumanStatsFlag = 0;
	AC.extrasymbols = AM.gextrasymbols = AM.ggextrasymbols = 0;
	AC.extrasym = (UBYTE *)Malloc1(2*sizeof(UBYTE),"extrasym");
	AM.gextrasym = (UBYTE *)Malloc1(2*sizeof(UBYTE),"extrasym");
	AM.ggextrasym = (UBYTE *)Malloc1(2*sizeof(UBYTE),"extrasym");
	AC.extrasym[0] = AM.gextrasym[0] = AM.ggextrasym[0] = 'Z';
	AC.extrasym[1] = AM.gextrasym[1] = AM.ggextrasym[1] = 0;
	AC.TokensWriteFlag = AM.gTokensWriteFlag = 0;
	AC.SetupFlag = 0;
	AC.LineLength = AM.gLineLength = 79;
	AC.NwildC = 0;
	AC.OutputMode = 0;
	AM.gOutputMode = 0;
	AC.OutputSpaces = NORMALFORMAT;
	AM.gOutputSpaces = NORMALFORMAT;
	AC.OutNumberType = RATIONALMODE;
	AM.gOutNumberType = RATIONALMODE;
#ifdef WITHZLIB
	AR.gzipCompress = GZIPDEFAULT;
	AR.FoStage4[0].ziobuffer = 0;
	AR.FoStage4[1].ziobuffer = 0;
#ifdef WITHZSTD
	/* Zstd compression is on by default, if we have compiled with it */
	ZWRAP_useZSTDcompression(1);
#endif
#endif
	AR.BracketOn = 0;
	AC.bracketindexflag = 0;
	AT.bracketindexflag = 0;
	AT.bracketinfo = 0;
	AO.IsBracket = 0;
	AM.gfunpowers = AC.funpowers = COMFUNPOWERS;
	AC.parallelflag = AM.gparallelflag;
	AC.properorderflag = AM.gproperorderflag = PROPERORDERFLAG;
	AC.ProcessBucketSize = AC.mProcessBucketSize = AM.gProcessBucketSize;
    AC.ThreadBucketSize = AM.gThreadBucketSize;
	AC.ShortStatsMax = 0;
	AM.gShortStatsMax = 0;
	AM.ggShortStatsMax = 0;

	GlobalSymbols     = NumSymbols;
	GlobalIndices     = NumIndices;
	GlobalVectors     = NumVectors;
	GlobalFunctions   = NumFunctions;
	GlobalSets        = NumSets;
	GlobalSetElements = NumSetElements;
	AC.modpowers = (UWORD *)0;

	i = AM.OffsetIndex;
	fi = AC.FixIndices;
	if ( i > 0 ) do { *fi++ = one; } while ( --i >= 0 );
	AR.sLevel = -1;
	AM.Ordering[0] = 5;
	AM.Ordering[1] = 6;
	AM.Ordering[2] = 7;
	AM.Ordering[3] = 0;
	AM.Ordering[4] = 1;
	AM.Ordering[5] = 2;
	AM.Ordering[6] = 3;
	AM.Ordering[7] = 4;
	for ( i = 8; i < 15; i++ ) AM.Ordering[i] = i;
	AM.gUniTrace[0] = 
	AC.lUniTrace[0] = SNUMBER;
	AM.gUniTrace[1] = 
	AC.lUniTrace[1] = 
	AM.gUniTrace[2] = 
	AC.lUniTrace[2] = 4;
	AM.gUniTrace[3] = 
	AC.lUniTrace[3] = 1;
#ifdef WITHPTHREADS
	AS.Balancing = 0;
#else
	AT.MinVecArg[0] = 7+ARGHEAD;
	AT.MinVecArg[ARGHEAD] = 7;
	AT.MinVecArg[1+ARGHEAD] = INDEX;
	AT.MinVecArg[2+ARGHEAD] = 3;
	AT.MinVecArg[3+ARGHEAD] = 0;
	AT.MinVecArg[4+ARGHEAD] = 1;
	AT.MinVecArg[5+ARGHEAD] = 1;
	AT.MinVecArg[6+ARGHEAD] = -3;
	t = AT.FunArg;
	*t++ = 4+ARGHEAD+FUNHEAD;
	for ( i = 1; i < ARGHEAD; i++ ) *t++ = 0;
	*t++ = 4+FUNHEAD;
	*t++ = 0;
	*t++ = FUNHEAD;
	for ( i = 2; i < FUNHEAD; i++ ) *t++ = 0;
	*t++ = 1; *t++ = 1; *t++ = 3;

#ifdef WITHMPI
	AS.printflag = 0;
#endif

	AT.comsym[0] = 8;
	AT.comsym[1] = SYMBOL;
	AT.comsym[2] = 4;
	AT.comsym[3] = 0;
	AT.comsym[4] = 1;
	AT.comsym[5] = 1;
	AT.comsym[6] = 1;
	AT.comsym[7] = 3;
	AT.comnum[0] = 4;
	AT.comnum[1] = 1;
	AT.comnum[2] = 1;
	AT.comnum[3] = 3;
	AT.comfun[0] = FUNHEAD+4;
	AT.comfun[1] = FUNCTION;
	AT.comfun[2] = FUNHEAD;
	AT.comfun[3] = 0;
#if FUNHEAD == 4
	AT.comfun[4] = 0;
#endif
	AT.comfun[FUNHEAD+1] = 1;
	AT.comfun[FUNHEAD+2] = 1;
	AT.comfun[FUNHEAD+3] = 3;
	AT.comind[0] = 7;
	AT.comind[1] = INDEX;
	AT.comind[2] = 3;
	AT.comind[3] = 0;
	AT.comind[4] = 1;
	AT.comind[5] = 1;
	AT.comind[6] = 3;
	AT.locwildvalue[0] = SUBEXPRESSION;
	AT.locwildvalue[1] = SUBEXPSIZE;
	for ( i = 2; i < SUBEXPSIZE; i++ ) AT.locwildvalue[i] = 0;
	AT.mulpat[0] = TYPEMULT;
	AT.mulpat[1] = SUBEXPSIZE+3;
	AT.mulpat[2] = 0;
	AT.mulpat[3] = SUBEXPRESSION;
	AT.mulpat[4] = SUBEXPSIZE;
	AT.mulpat[5] = 0;
	AT.mulpat[6] = 1;
	for ( i = 7; i < SUBEXPSIZE+5; i++ ) AT.mulpat[i] = 0;
	AT.proexp[0] = SUBEXPSIZE+4;
	AT.proexp[1] = EXPRESSION;
	AT.proexp[2] = SUBEXPSIZE;
	AT.proexp[3] = -1;
	AT.proexp[4] = 1;
	for ( i = 5; i < SUBEXPSIZE+1; i++ ) AT.proexp[i] = 0;
	AT.proexp[SUBEXPSIZE+1] = 1;
	AT.proexp[SUBEXPSIZE+2] = 1;
	AT.proexp[SUBEXPSIZE+3] = 3;
	AT.proexp[SUBEXPSIZE+4] = 0;
	AT.dummysubexp[0] = SUBEXPRESSION;
	AT.dummysubexp[1] = SUBEXPSIZE+4;
	for ( i = 2; i < SUBEXPSIZE; i++ ) AT.dummysubexp[i] = 0;
	AT.dummysubexp[SUBEXPSIZE] = WILDDUMMY;
	AT.dummysubexp[SUBEXPSIZE+1] = 4;
	AT.dummysubexp[SUBEXPSIZE+2] = 0;
	AT.dummysubexp[SUBEXPSIZE+3] = 0;

	AT.inprimelist = -1;
	AT.sizeprimelist = 0;
	AT.primelist = 0;
	AT.LeaveNegative = 0;
	AT.TrimPower = 0;
	AN.SplitScratch = 0;
	AN.SplitScratchSize = AN.InScratch = 0;
	AN.SplitScratch1 = 0;
	AN.SplitScratchSize1 = AN.InScratch1 = 0;
	AN.idfunctionflag = 0;
#endif
	AO.OutputLine = AO.OutFill = BufferForOutput;
	AO.FactorMode = 0;
	C->Pointer = C->Buffer;

	AP.PreOut = 0;
	AP.ComChar = AP.cComChar;
	AC.cbufnum = AM.rbufnum;		/* Select the default compiler buffer */
	AC.HideLevel = 0;
	AP.PreAssignFlag = 0;
}

/*
 		#] IniVars : 
 		#[ Signal handlers :
*/
/*[28apr2004 mt]:*/
#ifdef TRAPSIGNALS

static int exitInProgress = 0;
static int trappedTerminate = 0;

/*INTSIGHANDLER : some systems require a signal handler to return an integer,
  so define the macro INTSIGHANDLER if compiler fails:*/
#ifdef INTSIGHANDLER
static int onErrSig(int i)
#else
static void onErrSig(int i)
#endif
{
	if (exitInProgress){
		signal(i,SIG_DFL);/* Use default behaviour*/
		raise (i);/*reproduce trapped signal*/
#ifdef INTSIGHANDLER
		return(i);
#else
		return;
#endif
	}
	trappedTerminate = 1;
	/*[13jul2005 mt]*//*TerminateImpl(-1) on signal is here:*/
	Terminate(-1);
}

#ifdef INTSIGHANDLER
static void setNewSig(int i, int (*handler)(int))
#else
static void setNewSig(int i, void (*handler)(int))
#endif
{
	if(! (i<NSIG) )/* Invalid signal -- see comments in the file */
		return;
	if ( signal(i,SIG_IGN) !=SIG_IGN)
	/* if compiler fails here, try to define INTSIGHANDLER):*/
		signal(i,handler);
}

void setSignalHandlers(void)
{
	/* Reset various unrecoverable error signals:*/
	setNewSig(SIGSEGV,onErrSig);
	setNewSig(SIGFPE,onErrSig);
	setNewSig(SIGILL,onErrSig);
	setNewSig(SIGEMT,onErrSig);
	setNewSig(SIGSYS,onErrSig);
	setNewSig(SIGPIPE,onErrSig);
	setNewSig(SIGLOST,onErrSig);
	setNewSig(SIGXCPU,onErrSig);
	setNewSig(SIGXFSZ,onErrSig);

	/* Reset interrupt signals:*/
	setNewSig(SIGTERM,onErrSig);
	setNewSig(SIGINT,onErrSig);
	setNewSig(SIGQUIT,onErrSig);
	setNewSig(SIGHUP,onErrSig);
	setNewSig(SIGALRM,onErrSig);
	setNewSig(SIGVTALRM,onErrSig);
/*	setNewSig(SIGPROF,onErrSig); */  /* Why did Tentukov forbid profilers?? */
}

#endif
/*:[28apr2004 mt]*/
/*
 		#] Signal handlers : 
 		#[ main :
*/

#ifdef WITHPTHREADS
ALLPRIVATES *ABdummy[10];
#endif

int main(int argc, char **argv)
{
	int retval;
	bzero((void *)(&A),sizeof(A)); /* make sure A is initialized at zero */
	iniTools();
#ifdef TRAPSIGNALS
	setSignalHandlers();
#endif
#ifdef WINDOWS
	_setmode(_fileno(stdout),O_BINARY);
#endif

#ifdef WITHPTHREADS
	AB = ABdummy;
	StartHandleLock();
	BeginIdentities();
#else
	AM.SumTime = TimeCPU(0);
	TimeWallClock(0);
#endif

#ifdef WITHMPI
	if ( PF_Init(&argc,&argv) ) exit(-1);
#endif

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

	if ( ( retval = DoTail(argc,(UBYTE **)argv) ) != 0 ) {
		if ( retval > 0 ) Terminate(0);
		else              Terminate(-1);
	}
	if ( DoSetups() ) Terminate(-2);
#ifdef WITHMPI
	/* It is messy if all errors in OpenInput() on slaves are printed. */
	AS.printflag = 0;
#endif
	if ( OpenInput() ) Terminate(-3);
#ifdef WITHMPI
	AS.printflag = -1;
#endif
	if ( TryEnvironment() ) Terminate(-2);
	if ( TryFileSetups() ) Terminate(-2);
	if ( MakeSetupAllocs() ) Terminate(-2);
	StartMore();
	InitRecovery();
	CheckRecoveryFile();
	if ( AM.totalnumberofthreads == 0 ) AM.totalnumberofthreads = 1;
	AS.MultiThreaded = 0;
#ifdef WITHPTHREADS
	if ( AM.totalnumberofthreads > 1 ) AS.MultiThreaded = 1;
	ReserveTempFiles(1);
	StartAllThreads(AM.totalnumberofthreads);
	IniFbufs();
#else
	ReserveTempFiles(0);
	IniFbuffer(AT.fbufnum);
#endif
	if ( !AM.FromStdin ) PrintHeader(1);
	IniVars();
	Globalize(1);
#ifdef WITH_ALARM
	if ( AM.TimeLimit > 0 ) alarm(AM.TimeLimit);
#endif
#ifdef WITHFLINT
	flint_check_version();
#endif
	TimeCPU(0);
	TimeChildren(0);
	TimeWallClock(0);
	PreProcessor();
	Terminate(0);
	return(0);
}
/*
 		#] main : 
 		#[ CleanUp :

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

*/

void CleanUp(WORD par)
{
	GETIDENTITY
	int i;

	if ( FG.fname ) {
#ifdef WITHPTHREADS
	if ( B ) {
#endif
	CleanUpSort(0);
	for ( i = 0; i < 3; i++ ) {
		if ( AR.Fscr[i].handle >= 0 ) {
			if ( AR.Fscr[i].name ) {
/*
				If there are more threads referring to the same file
				only the one with the name is the owner of the file.
*/
				CloseFile(AR.Fscr[i].handle);
				remove(AR.Fscr[i].name);
			}
			AR.Fscr[i].handle = - 1;
			AR.Fscr[i].POfill = 0;
		}
	}
#ifdef WITHPTHREADS
	}
#endif
	if ( par > 0 ) {
/*
	Close all input levels above the lowest?
*/
	}
	if ( AC.StoreHandle >= 0 && par <= 0 ) {
#ifdef TRAPSIGNALS
		if ( trappedTerminate ) { /* We don't throw .str if it has contents */
			POSITION pos;
			PUTZERO(pos);
			SeekFile(AC.StoreHandle,&pos,SEEK_END);
			if ( ISNOTZEROPOS(pos) ) {
				CloseFile(AC.StoreHandle);
				goto dontremove;
			}
		}
		CloseFile(AC.StoreHandle);
#ifdef WITHPTHREADS
	if ( B )
#endif
		if ( par >= 0 || AR.StoreData.Handle < 0 || AM.ClearStore ) {
			remove(FG.fname);
		}
dontremove:;
#else
		CloseFile(AC.StoreHandle);
#ifdef WITHPTHREADS
	if ( B )
#endif
		if ( par >= 0 || AR.StoreData.Handle < 0 || AM.ClearStore > 0 ) {
			remove(FG.fname);
		}
#endif
	}
	}
	ClearSpectators(CLEARMODULE);
/*
	Remove recovery file on exit if everything went well
*/
	if ( par == 0 ) {
		DeleteRecoveryFile();
	}
/*
	Now the final message concerning the total time
*/
	if ( AC.LogHandle >= 0 && par <= 0 ) {
		WORD lh = AC.LogHandle;
		AC.LogHandle = -1;
#ifdef WITHMPI
		if ( PF.me == MASTER )  /* Only the master opened the real file. */
#endif
		CloseFile(lh);
	}
}

/*
 		#] CleanUp : 
 		#[ TerminateImpl :
*/

static int firstterminate = 1;

void TerminateImpl(int errorcode, const char* file, int line, const char* function)
{
	if ( errorcode && firstterminate ) {
		firstterminate = 0;

		MLOCK(ErrorMessageLock);
#ifdef WITHPTHREADS
		MesPrint("Program terminating in thread %w at &");
#elif defined(WITHMPI)
		MesPrint("Program terminating in process %w at &");
#else
		MesPrint("Program terminating at &");
#endif
		MesPrint("Terminate called from %s:%d (%s)", file, line, function);

		if ( AC.PrintBacktraceFlag ) {
#ifdef ENABLE_BACKTRACE
			void *stack[64];
			int stacksize, stop = 0;
			stacksize = backtrace(stack, sizeof(stack)/sizeof(stack[0]));

			/* First check whether eu-addr2line is available */
			if ( !system("command -v eu-addr2line > /dev/null 2>&1") ) {
				MesPrint("Backtrace:");
				for (int i = 0; i < stacksize && !stop; i++) {
					FILE *fp;
					char cmd[512];
					// Leave an initial space
					cmd[0] = ' ';
					MesPrint("%#%2d:%", i);
					snprintf(cmd+1, sizeof(cmd)-1, "eu-addr2line -s --pretty-print -f -i '%p' --pid=%d\n", stack[i], getpid());
					fp = popen(cmd+1, "r");
					while ( fgets(cmd+1, sizeof(cmd)-1, fp) != NULL ) {
						MesPrint("%s", cmd);
						/* Don't show functions lower than "main" (or thread equivalent) */
						if ( strstr(cmd, " main ") || strstr(cmd, " RunThread ") || strstr(cmd, " RunSortBot ") ) {
							stop = 1;
						}
					}
					pclose(fp);
				}
			}
#ifdef LINUX
			else if ( !system("command -v addr2line > /dev/null 2>&1") ) {
				/* Get the executable path. */
				char exe_path[PATH_MAX];
				{
					ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
					if ( len != -1 ) {
						exe_path[len] = '\0';
					}
					else {
						goto backtrace_fallback;
					}
				}
				/* Assume PIE binary and get the base address. */
				uintptr_t base_address = 0;
				{
					char line[256];
					FILE *maps = fopen("/proc/self/maps", "r");
					if ( !maps ) {
						goto backtrace_fallback;
					}
					/* See the format used by nommu_region_show() in fs/proc/nommu.c of the Linux source. */
					if ( fgets(line, sizeof(line), maps) ) {
						sscanf(line, "%" SCNxPTR "-", &base_address);
					}
					else {
						fclose(maps);
						goto backtrace_fallback;
					}
					fclose(maps);
				}
				char **strings;
				strings = backtrace_symbols(stack, stacksize);
				MesPrint("Backtrace:");
				for ( int i = 0; i < stacksize && !stop; i++ ) {
					FILE *fp;
					char cmd[PATH_MAX + 512];
					// Leave an initial space
					cmd[0] = ' ';
					uintptr_t addr = (uintptr_t)stack[i] - base_address;
					MesPrint("%#%2d:%", i);
					snprintf(cmd+1, sizeof(cmd)-1, "addr2line -e \"%s\" -i -p -s -f -C 0x%" PRIxPTR, exe_path, addr);
					fp = popen(cmd+1, "r");
					while ( fgets(cmd+1, sizeof(cmd)-1, fp) != NULL ) {
						MesPrint("%s", cmd);
						/* Don't show functions lower than "main" */
						if ( strstr(cmd, " main ") || strstr(cmd, " RunThread ") || strstr(cmd, " RunSortBot ") ) {
							stop = 1;
						}
					}
					pclose(fp);
				}
				free(strings);
			}
#endif
			else {
				/* eu-addr2line not found */
#ifdef LINUX
backtrace_fallback: ;
#endif
				char **strings;
				strings = backtrace_symbols(stack, stacksize);
				MesPrint("Backtrace:");
				for ( int i = 0; i < stacksize && !stop; i++ ) {
					char *p = strings[i];
					while ( *p && *p != '(' ) p++;
					MesPrint("%#%2d: %s\n", i, p);
					/* Don't show functions lower than "main" (or thread equivalent) */
					if ( strstr(p, "(main+") || strstr(p, "(RunThread+") || strstr(p, "(RunSortBot+") ) {
						stop = 1;
					}
				}
#ifdef LINUX
				MesPrint("Please install addr2line or eu-addr2line for readable stack information.");
#else
				MesPrint("Please install eu-addr2line for readable stack information.");
#endif
				free(strings);
			}
#else
			MesPrint("FORM compiled without backtrace support.");
#endif
		} /* if ( AC.PrintBacktraceFlag) { */

		MUNLOCK(ErrorMessageLock);

		Crash();
	}
#ifdef TRAPSIGNALS
	exitInProgress=1;
#endif
#ifdef WITHEXTERNALCHANNEL
/*
	This function can be called from the error handler, so it is better to
	clean up all started processes before any activity:
*/
	closeAllExternalChannels();
	AX.currentExternalChannel=0;
	/*[08may2006 mt]:*/
	AX.killSignal=SIGKILL;
	AX.killWholeGroup=1;
	AX.daemonize=1;
	/*:[08may2006 mt]*/
	if(AX.currentPrompt){
		M_free(AX.currentPrompt,"external channel prompt");
		AX.currentPrompt=0;
	}
	/*[08may2006 mt]:*/
	if(AX.shellname){
		M_free(AX.shellname,"external channel shellname");
		AX.shellname=0;
	}
	if(AX.stderrname){
		M_free(AX.stderrname,"external channel stderrname");
		AX.stderrname=0;
	}
	/*:[08may2006 mt]*/
#endif
#ifdef WITHPTHREADS
	if ( !WhoAmI() && !errorcode ) {
		TerminateAllThreads();
	}
#endif
	if ( AC.FinalStats ) {
		if ( AM.PrintTotalSize ) {
			MesPrint("Max. space for expressions: %19p bytes",&(AS.MaxExprSize));
		}
		PrintRunningTime();
	}
#ifdef WITHMPI
	if ( AM.HoldFlag && PF.me == MASTER ) {
		WriteFile(AM.StdOut,(UBYTE *)("Hit any key "),12);
		PF_FlushStdOutBuffer();
		getchar();
	}
#else
	if ( AM.HoldFlag ) {
		WriteFile(AM.StdOut,(UBYTE *)("Hit any key "),12);
		getchar();
	}
#endif
#ifdef WITHMPI
	PF_Terminate(errorcode);
#endif
/*
	We are about to terminate the program. If we are using flint, call the cleanup function.
	This keeps valgrind happy.
*/
#ifdef WITHFLINT
	flint_final_cleanup_master();
#endif
	CleanUp(errorcode);
	M_print();
#ifdef VMS
	P_term(errorcode? 0: 1);
#else
	P_term(errorcode);
#endif
}

/*
 		#] TerminateImpl : 
 		#[ PrintDeprecation :
*/

/**
 * Prints a deprecation warning for a given feature.
 *
 * @param feature  The name of the deprecated feature.
 * @param issue    The associated issue, e.g., "issues/700".
 */
void PrintDeprecation(const char *feature, const char *issue) {
#ifdef WITHMPI
	if ( PF.me != MASTER ) return;
#endif
	if ( AM.IgnoreDeprecation ) return;

	UBYTE *e = (UBYTE *)getenv("FORM_IGNORE_DEPRECATION");
	if ( e && e[0] && StrCmp(e, (UBYTE *)"0") && StrICmp(e, (UBYTE *)"false") && StrICmp(e, (UBYTE *)"no") ) return;

	MesPrint("DeprecationWarning: We are considering deprecating %s.", feature);
	MesPrint("If you want this support to continue, leave a comment at:");
	MesPrint("");
	MesPrint("    https://github.com/form-dev/form/%s", issue);
	MesPrint("");
	MesPrint("Otherwise, it will be discontinued in the future.");
	MesPrint("To suppress this warning, use the -ignore-deprecation command line option or");
	MesPrint("set the environment variable FORM_IGNORE_DEPRECATION=1.");
}

/*
 		#] PrintDeprecation : 
 		#[ PrintRunningTime :
*/

void PrintRunningTime(void)
{
#if (defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))) || defined(WITHMPI)
	LONG mastertime;
	LONG workertime;
	LONG wallclocktime;
	LONG totaltime;
#if defined(WITHPTHREADS)
	if ( AB[0] != 0 ) {
		workertime = GetWorkerTimes();
#else
	workertime = PF_GetSlaveTimes();  /* must be called on all processors */
	if ( PF.me == MASTER ) {
#endif
		mastertime = AM.SumTime + TimeCPU(1);
		wallclocktime = TimeWallClock(1);
		totaltime = mastertime+workertime;
		if ( !AM.silent ) {
		MesPrint("  %l.%2i sec + %l.%2i sec: %l.%2i sec out of %l.%2i sec",
			mastertime/1000,(WORD)((mastertime%1000)/10),
			workertime/1000,(WORD)((workertime%1000)/10),
			totaltime/1000,(WORD)((totaltime%1000)/10),
			wallclocktime/100,(WORD)(wallclocktime%100));
		}
	}
#else
	LONG mastertime = AM.SumTime + TimeCPU(1);
	LONG wallclocktime = TimeWallClock(1);
	if ( !AM.silent ) {
	MesPrint("  %l.%2i sec out of %l.%2i sec",
		mastertime/1000,(WORD)((mastertime%1000)/10),
		wallclocktime/100,(WORD)(wallclocktime%100));
	}
#endif
}

/*
 		#] PrintRunningTime : 
 		#[ GetRunningTime :
*/

LONG GetRunningTime(void)
{
#if defined(WITHPTHREADS) && (defined(WITHPOSIXCLOCK) || defined(WINDOWS))
	LONG mastertime;
	if ( AB[0] != 0 ) {
/* 
#if ( defined(APPLE64) || defined(APPLE32) )
		mastertime = AM.SumTime + TimeCPU(1);
		return(mastertime);
#else
*/
		LONG workertime = GetWorkerTimes();
		mastertime = AM.SumTime + TimeCPU(1);
		return(mastertime+workertime);
/*
#endif
*/
	}
	else {
		return(AM.SumTime + TimeCPU(1));
	}
#elif defined(WITHMPI)
	LONG mastertime, t = 0;
	LONG workertime = PF_GetSlaveTimes();  /* must be called on all processors */
	if ( PF.me == MASTER ) {
		mastertime = AM.SumTime + TimeCPU(1);
		t = mastertime + workertime;
	}
	return PF_BroadcastNumber(t);  /* must be called on all processors */
#else
	return(AM.SumTime + TimeCPU(1));
#endif
}

/*
 		#] GetRunningTime : 
*/