File: perpet.c

package info (click to toggle)
intercal 30:0.30-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,044 kB
  • sloc: ansic: 8,936; sh: 1,274; yacc: 1,073; lex: 518; lisp: 460; makefile: 435; perl: 295
file content (2100 lines) | stat: -rw-r--r-- 70,417 bytes parent folder | download | duplicates (2)
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
/****************************************************************************

NAME
   perpet.c -- main routine for C-INTERCAL compiler.

DESCRIPTION
   This is where all the dirty work begins and ends.

LICENSE TERMS
    Copyright (C) 1996 Eric S. Raymond

    This program 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 2 of the License, or
    (at your option) any later version.

    This program 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 this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

****************************************************************************/
/*LINTLIBRARY */
#include "config.h" /* AIS: Generated by autoconf */
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <string.h>
#include <signal.h>
#include <time.h>
#include <assert.h>
#include "ick.h"
#include "feh.h"
#include "parser.h"
#include "sizes.h"
#include "ick_lose.h"
#include "uncommon.h"

/* AIS: split ICKDATADIR from ICKLIBDIR */
#ifndef ICKINCLUDEDIR
# define ICKINCLUDEDIR "/usr/local/include"
#endif
#ifndef ICKSYSDIR
# ifdef ICKDATADIR
#  define ICKSYSDIR ICKDATADIR
# else
#  define ICKSYSDIR "/usr/local/share"
# endif
#endif
#ifndef ICKCSKELDIR
# ifdef ICKDATADIR
#  define ICKCSKELDIR ICKDATADIR
# else
#  define ICKCSKELDIR "/usr/local/share"
# endif
#endif
#ifndef ICKLIBDIR
# define ICKLIBDIR "/usr/local/lib"
#endif
#ifndef ICKBINDIR
# define ICKBINDIR "/usr/local/bin"
#endif
#ifndef CC
# define CC "gcc"
#endif

#define ARGSTRING "abcdefghlmoptuvwxyCEFHOPUYX@"

/* unused st variable quiets a GCC4 warning */
#define ICK_SYSTEM(x) do{int st;if(showsystem)fprintf(stderr,"%s\n",x); \
    st=system(x);}while(0)

#ifdef USE_YYRESTART
/* function supplied by lex */
extern void yyrestart(FILE*);

#endif /* USE_YYRESTART */

/* function created by yacc */
extern int yyparse(void);

int yydebug;

/* compilation options */
bool compile_only; 	/* just compile into C, don't run the linker */
bool ick_traditional;	/* insist on strict INTERCAL-72 conformance */
bool nocompilerbug;	/* disable error IE774 */
bool yukdebug;          /* AIS: Use the yuk debugger. */
bool yukprofile;        /* AIS: Use the yuk profiler. */
bool useprintflow;      /* AIS: Add +printflow support. */
extern bool ick_coreonerr;   /* AIS: Dump core on IE778. (defined in ick_lose.c) */
bool multithread;       /* AIS: Allow multithreading and backtracking. */
bool variableconstants; /* AIS: Allow anything on the left of an assignment. */
bool createsused;       /* AIS: Allow the use of CREATE. */
bool useickec;          /* AIS: Link together INTERCAL and C. */
static bool nosyslib;   /* AIS: Don't link syslib under any circumstances. */
static bool showsystem; /* AIS: Show the command lines in system() calls */
bool cdebug;            /* AIS: Pass -g to our C compiler, and leave C code. */
int optdebug;           /* AIS: Debug the optimizer. Value is 0, 1, 2, or 3. */
bool flowoptimize;      /* AIS: Do flow optimizations (in INTERCAL!). */
bool coopt;             /* AIS: The constant-output optimization. This should
			   mean that INTERCAL will beat any other language at
			   many benchmark programs (!) */
extern bool ick_printfopens; /* AIS: Print messages whenever attempting to open a
			       file: from uncommon.c */
extern bool ick_checkforbugs;/* AIS: Try to find possible bugs in the source code */
bool pickcompile;       /* AIS: Compile for PIC? */
/*@-exportlocal@*/      /* AIS: relevant to the lexer */
bool clclex;            /* AIS: 1 means use CLC-INTERCAL meanings for @, ? */
/*@=exportlocal@*/
bool ick_clcsemantics;       /* AIS: CLC semantics for I/O, abstaining GIVE UP, &c*/
static bool outtostdout;     /* AIS: Output on stdout rather than the output file */

/* AIS: Autodetected compilation options */
int compucomecount;    /* Computed COME FROM count */
bool compucomesused;   /* Are computed COME FROMs used? */
bool gerucomesused;    /* Is COME FROM gerund used? */
bool nextfromsused;    /* Is NEXT FROM used? */
bool opoverused;       /* Is operand overloading used? */
/*@null@*/ node* firstslat=0;      /* The first slat expression in the program */
/*@null@*/ node* prevslat=0;       /* The last slat expression used so far */

static bool dooptimize;	/* do optimizations? (controlled by -O) */
static bool ick_clockface;	/* set up output to do IIII for IV */

#define SKELETON  "ick-wrap.c"
#define PSKELETON "pickwrap.c"
#define SYSLIB    "syslib"

/* numeric base defaults, exported to other files */

#define DEFAULT_BASE 2
#define DEFAULT_SMALL_DIGITS 16
#define DEFAULT_LARGE_DIGITS 32
#define DEFAULT_MAX_SMALL 0xffffL
#define DEFAULT_MAX_LARGE 0xffffffffL

int ick_Base;
int ick_Small_digits;
int ick_Large_digits;
unsigned int ick_Max_small;
unsigned int ick_Max_large;

int ick_lineno;	/* after yyparse, this is the total number of statements */

/* currently supported numeric bases, not exported */
static const int maxbase = 7;
static const int smallsizes[8] = {0, 0, 16, 10, 8, 6, 6, 5};
static const unsigned int maxsmalls[8] =
{0, 0, 65535, 59048, 65535, 15624, 46655, 16806};

/*@observer@*/ static const char *compiler;

atom *oblist = NULL, *obdex;
int obcount = 0;
int nonespots, ntwospots, ntails, nhybrids;
int nmeshes; /* AIS */

tuple *tuples = NULL;
int tuplecount = 0;

tuple *optuple = NULL; /* AIS: Tuple being optimized */

/*
 * mappings from magic line ranges to system library components are
 * declared here.
 */
struct linerange_t {
    int start, end;
    char *libname;
};
/* Note! "syslib" must be last in this list, as other parts of perpet.c
   care about whether syslib in particular was included. */
struct linerange_t lineranges[] = {
    {5000, 5699, "floatlib"},  /* the floating-point support */
    {1000, 1999, "syslib"},    /* the system library */
    {0, 0, NULL},
};

extern const assoc varstores[]; /* AIS: Need to know this for PIC compilation */

#ifndef HAVE_UNISTD_H
/* AIS: We don't have unistd.h, so we can't use getopt. Write our own version
   that's less general but good enough. */
int optind=1;
int optopt;
int getopt(int argc, char * const *argv, const char *options)
{
  if(optind>argc) return EOF; /* Out of command line */
  if(!argv[optind]) return EOF; /* Out of command line */
  while(!strcmp(argv[optind],"-"))
  {
    optind++; /* Go to ick_next argument */
    if(!argv[optind]) return EOF;
  }
  if(*(argv[optind])!='-') return EOF; /* this arg is not an option */
  optopt=argv[optind][1];
  memmove(argv[optind]+1,argv[optind]+2,strlen(argv[optind]+1));
  if(optopt=='-') {optind++; return EOF;} /* -- means end of options */
  if(strchr(options, optopt)) return optopt; /* valid option */
  return '?'; /* invalid option */
}
#endif

static int myfgetc(FILE* in)
{
  char c;
  size_t dummy;
  dummy = fread(&c,1,1,in);
  if(feof(in)) return EOF;
  return (int)c;
}

static void abend(int signim)
{
  /*@-noeffect@*/ (void) signim; /*@=noeffect@*/
  ick_lose(IE778, iyylineno, (const char *)NULL);
}
static void print_usage(const char *prog, const char *options)
{
  fprintf(stderr,"Usage: %s [-%s] <file> [<file> ...]\n",prog,options);
  fprintf(stderr,"\t-b\t:reduce the probability of E774 to zero\n");
  fprintf(stderr,"\t-c\t:compile INTERCAL to C, but don't compile C\n");
  fprintf(stderr,"\t-d\t:print yacc debugging information (implies -c)\n");
  fprintf(stderr,"\t-e\t:link together INTERCAL and C files as one program\n");
  fprintf(stderr,"\t\t (without this option, all INTERCAL files produce\n");
  fprintf(stderr,"\t\t separate output files; with it, the first file given\n");
  fprintf(stderr,"\t\t must be the only INTERCAL file) (prevents -mypPf)\n");
  fprintf(stderr,"\t-E\t:never include system libraries (prevents -P)\n");
  fprintf(stderr,"\t-t\t:traditional mode, accept only INTERCAL-72\n");
  fprintf(stderr,"\t-C\t:clockface output (e.g. use IIII instead of IV)\n");
  fprintf(stderr,"\t-O\t:optimize expresssions in generated code\n");
  /* AIS: Changed the help message for the previous line (because the
     function of -O has changed). I wrote the next group of options. */
  fprintf(stderr,"\t-f\t:optimize control flow in generated code "
	  "(prevents -yp)\n");
#ifdef HAVE_PROG_SH
# ifdef HAVE_SYS_INTERPRETER
  fprintf(stderr,"\t-F\t:optimize everything in generated code for\n"
	  "\t\t speed, regardless of how slow the compiler becomes or how\n"
	  "\t\t large the object file becomes. Implies -fO, "
	  "prevents -cdeghpyH\n");
# else
  fprintf(stderr,"\t-F\t:unsupported on computers without #! support\n");
# endif
#else
  fprintf(stderr,"\t-F\t:unsupported on computers without sh or bash\n");
#endif
  fprintf(stderr,"\t-h\t:print optimizer debugging information "
	  "(implies -cO)\n");
  fprintf(stderr,"\t-H\t:print verbose optimizer debugging information "
	  "(implies -cO)\n");
  fprintf(stderr,"\t-hH\t:print optimizer debugging information in a\n"
	  "\t\t different form (implies -cO)\n");
#ifdef HAVE_UNISTD_H
  fprintf(stderr,"\t-y\t:run the yuk debugger on the code (prevents -fme)\n");
  fprintf(stderr,"\t-p\t:run the yuk profiler on the code (prevents -fme)\n");
#else
  fprintf(stderr,"\t-y\t:unsupported on computers without <unistd.h>\n");
  fprintf(stderr,"\t-p\t:unsupported on computers without <unistd.h>\n");
#endif
  fprintf(stderr,"\t-w\t:add support for the +printflow option\n");
  fprintf(stderr,"\t-m\t:allow multithreading and backtracking\n"
	  "\t\t (prevents -ype, implies -w)\n");
  fprintf(stderr,"\t-a\t:allow the use of CREATE (prevents -P)\n");
  fprintf(stderr,"\t-v\t:allow anything on the left of an assignment. This "
	  "is required\n\t\t if you want operand overloading to change "
	  "meshes.\n\t\t (prevents -fFOP)\n");
  fprintf(stderr,"\t-P\t:compile PIC-INTERCAL rather than INTERCAL\n");
  fprintf(stderr,"\t\t (prevents -amFvxeE, implies -cfO)\n");
  fprintf(stderr,"\t-o\t:output to stdout rather than .c (implies -c)\n");
  fprintf(stderr,"\t-X\t:interpret ambiguous syntax as Princeton not\n"
	  "\t\t Atari (i.e. CLC-INTERCAL not C-INTERCAL)\n");
  fprintf(stderr,"\t-x\t:use CLC-INTERCAL rules for I/O and abstaining\n"
	  "\t\t from a GIVE UP by label (prevents -P)\n");
  fprintf(stderr,"\t-u\t:print a message whenever the compiler tries to "
	  "open a file\n");
  fprintf(stderr,"\t-U\t:dump core on IE778 after printing an error\n");
  fprintf(stderr,"\t-Y\t:display the command line used whenever an external\n"
	  "\t\t program is invoked\n");
  fprintf(stderr,"\t-g\t:compile to both debuggable executable and C\n");
  fprintf(stderr,"\t-l\t:attempt to report likely bugs "
	  "and nonportabilities (implies -O)\n");
  /* AIS: End of options I added. */
  fprintf(stderr,"\t<file>\tINTERCAL source file (use extension .i\n");
  fprintf(stderr,"\t\tfor base 2 or .3i, etc., for base 3, etc.).\n");
}

#if __DJGPP__
/* AIS: Determine whether an environment variable exists (this is used to
   find a temp directory) */
static int isenv(char* e)
{
  char* x=getenv(e);
  return x != NULL && *x != '\0';
}
#endif

extern int	optind;		/* set by getopt */

/**
 * This parses command line options.
 * @param argc What do you think?
 * @param argv Likewise.
 * @note May (directly) call ick_lose() with IE111 and IE256.
 */
static void parse_options(int argc, char *argv[])
{
  int		c;

  /* getopt is POSIX, and I provide my own version if the POSIX version
     isn't found, so the unrecog warning is a false positive. */
  /*@-unrecog@*/
  while ((c = getopt(argc, argv, ARGSTRING)) != EOF)
    /*@=unrecog@*/
  {
    switch (c)
    {
    case 'b':
      nocompilerbug = true;
      break;

    case 'c':
      compile_only = true;
      /* AIS */ coopt = false;
      break;

    case 'o': /* AIS */
      compile_only = true;
      outtostdout = true;
      coopt = false;
      break;

    case 'd':
	yydebug = 1;
	compile_only = true;
      /* AIS */ coopt = false;
      break;

    case 'e': /* AIS */
      useickec = true;
      multithread = pickcompile = coopt = yukdebug = yukprofile = false;
      break;

    case 'E': /* AIS */
      nosyslib = true;
      pickcompile = false;
      break;

    case 'C':
      ick_clockface = true;
      break;

    case 't':
      ick_traditional = true;
      if(multithread) ick_lose(IE111, 1, (const char*) NULL); /* AIS */
      if(pickcompile) ick_lose(IE111, 1, (const char*) NULL); /* AIS */
      break;

    case 'O':
      dooptimize = true;
      variableconstants = false; /* AIS */
      break;

    case 'f': /* By AIS */
      flowoptimize = true;
      yukdebug = yukprofile = false;
      variableconstants = false;
      break;

    case 'F': /* By AIS */
      coopt = flowoptimize = dooptimize = true;
      variableconstants = useickec = false;
      yukdebug = yukprofile = outtostdout = compile_only = cdebug = false;
      yydebug = 0;
      if(pickcompile) ick_lose(IE256, 1, (const char*) NULL);
      break;

    case 'h': /* By AIS */
      optdebug|=1;
      compile_only=dooptimize=true;
      coopt=false;
      break;

    case 'H': /* By AIS */
      optdebug|=2;
      compile_only=dooptimize=true;
      coopt=false;
      break;

    case 'y': /* By AIS */
#ifdef HAVE_UNISTD_H
      yukdebug=true;
      multithread=flowoptimize=coopt=useickec=false;
#endif
      break;

    case 'p': /* By AIS */
#ifdef HAVE_UNISTD_H
      yukprofile=true;
      multithread=flowoptimize=coopt=useickec=false;
#endif
      break;

    case 'w': /* By AIS */
      useprintflow = true;
      break;

    case 'm': /* By AIS */
      multithread=true;
      yukprofile=false;
      yukdebug=false;
      useickec=false;
      if(ick_traditional) ick_lose(IE111, 1, (const char*) NULL);
      break;

    case 'a': /* By AIS */
      createsused=true;
      pickcompile=false;
      break;

    case 'v': /* By AIS */
      variableconstants=true;
      dooptimize=false;
      flowoptimize=false;
      coopt=false;
      pickcompile=false;
      break;

    case 'l': /* By AIS */
      ick_checkforbugs=true;
      dooptimize=true;
      break;

    case 'U': /* By AIS */
      ick_coreonerr=true;
      break;

    case 'u': /* By AIS */
      ick_printfopens=true;
      break;

    case 'Y': /* By AIS */
      showsystem=true;
      break;

    case 'P': /* By AIS */
      pickcompile=true;
      multithread=coopt=variableconstants=createsused=false;
      ick_clcsemantics=useickec=nosyslib=false;
      compile_only=true;
      dooptimize=flowoptimize=true; /* needed for PICs */
      break;

    case 'X': /* By AIS */
      clclex=true;
      break;

    case 'x': /* By AIS */
      ick_clcsemantics=true;
      pickcompile=false;
      break;

    case 'g': /* By AIS */
      cdebug=true;
      coopt=false;
      break;

    case '?':
    default:
    case '@':
      print_usage(argv[0], ARGSTRING);
      exit(EXIT_FAILURE);
      /*@-unreachable@*/ break; /*@=unreachable@*/
    }
  }
}


/**
 * This code handles archives (for -e).
 * @param libbuf Pointer to a buffer to which extra files to link in prelink()
 *               will be added. Need to be initialized up to the first zero byte.
 * @param libbuf_size Size of the buffer libbuf.
 * @param library The cmd line argument used for the library (but without the
 *                extension).
 */
static void handle_archive(char *libbuf, size_t libbuf_size,
                           /*@observer@*/ const char* library)
{
  /* AIS: request for a library. Given a filename of the form
     libwhatever.a, it adds  -lwhatever to libbuf (that's with
     a preceding space). If the filename doesn't start with lib,
     it instead adds a space and the filename to libbuf. */
  if(library[0]=='l'&&library[1]=='i'&&
      library[2]=='b')
      (void) ick_snprintf_or_die(libbuf+strlen(libbuf),libbuf_size - strlen(libbuf),
			" -l%s",library+3);
  else
      (void) ick_snprintf_or_die(libbuf+strlen(libbuf),libbuf_size - strlen(libbuf),
			" %s.a",library);
}


/**
 * This handles Befunge 98 (for -e).
 * @param libbuf Pointer to a buffer to which extra files to link in prelink()
 *               will be added. Need to be initialized up to the first zero byte.
 * @param libbuf_size Size of the buffer libbuf.
 * @param libdir The ick library directory.
 * @param argv0 Should be argv[0], which wasn't modified.
 * @param filename The file name  of the Befunge file (but without the extension).
 * @note May (directly) call ick_lose() with IE888 and IE899.
 */
static void handle_befunge98(char *libbuf, size_t libbuf_size,
                             /*@observer@*/ const char* libdir,
                             /*@observer@*/ const char* argv0,
                             /*@observer@*/ const char* filename)
{
  /* AIS: Compile the .b98 file into a .cio so that it can be used
     later, and include the necessary libraries to use it, or error
     if the libraries aren't installed yet. I use a somewhat dubious
     trick here: the .b98 file's .cio, and the necessary libraries,
     are added in the libraries section of the command line, whereas
     the space on the command line where the .b98 file was is used
     for the expansion library ecto_b98. This is because ecto_b98
     requires preprocessing/prelinking/interprocessing or whatever
     you want to call it, whereas unlike for other .cios, the .cio
     produced from the Befunge file doesn't.
   */

#define MARKERMAX 128

  FILE* of;
  int x,y,jlb;
  char outputfilename[BUFSIZ];
  int markerposns[MARKERMAX][2];
  int markercount=0;

  /* Error if libick_ecto_b98.a is missing. It might be, and not
     just due to installation problems. */
  if(!ick_findandtestopen("libick_ecto_b98.a",libdir,"rb",argv0))
    ick_lose(IE899,-1,(const char *)NULL);

  /* Compile the .b98 file into a .cio. It's open on stdin right now,
     so we just need to handle the output side of things. */

  (void) ick_snprintf_or_die(outputfilename, sizeof outputfilename, "%s.cio", filename);

  if(!((of = ick_debfopen(outputfilename,"w"))))
    ick_lose(IE888,-1,(const char *)NULL);

  fprintf(of,"const unsigned char* ick_iffi_befungeString=\n\"");

  x=0; y=0; jlb=0;
  for(;;)
  {
    int c=getchar();
    if(c==EOF) break;
    if(c==0xB7)
    {
      /* Middot (0xB7) has special handling. */
      c='M';
      markerposns[markercount][0]=x;
      markerposns[markercount++][1]=y;
    }
    if(c=='\r') {jlb = 1; x=0; y++; c='\n';}
    else if(c=='\n' && jlb) {jlb = 0; continue;}
    else if(c=='\n') {x=0; y++; jlb = 0;}
    else x++;
    fprintf(of,"\\x%x",(unsigned int)c);
    if(!x) fprintf(of,"\"\n\"");
  }
  fprintf(of,"\";\n\nint ick_iffi_markercount=%d;\n"
	  "long long ick_iffi_markerposns[][2]={\n",markercount);
  if(!markercount) fprintf(of,"{0,0}\n");
  while(markercount--) fprintf(of,"{%d,%d},\n",
			       markerposns[markercount][0],
			       markerposns[markercount][1]);
  fprintf(of,"};\n");

  (void) fclose(of);

  /* Put the libraries and .cio file in the command line. */
  (void) ick_snprintf_or_die(libbuf+strlen(libbuf),libbuf_size - strlen(libbuf),
		      " %s.cio -lick_ecto_b98 -lm -lncurses", filename);
}


/**
 * This computes what type the INTERCAL source file is.
 * It will change various globals.
 * @param chp A pointer to the first letter of the extension of the file. Note
 *            that it won't be changed, but can't be const char* due to being
 *            passed as the second parameter to strtol() as well.
 * @note May (directly) call ick_lose() with IE111, IE256 and IE998.
 */
static void find_intercal_base(char* chp)
{
  /* wwp: reset the base variables to defaults, because if the  */
  /* sourcefile has extension .i they will not be reset in the  */
  /* following chunk of code. but i don't want to modify the    */
  /* following chunk of code because i think it is very clever; */
  /* grabs the base on the first pass, then validates the rest  */
  /* of the extension on the second.                            */
  ick_Base = DEFAULT_BASE;
  ick_Small_digits = DEFAULT_SMALL_DIGITS;
  ick_Large_digits = DEFAULT_LARGE_DIGITS;
  ick_Max_small = (unsigned)DEFAULT_MAX_SMALL;
  ick_Max_large = (unsigned)DEFAULT_MAX_LARGE;

  /* determine the file type from the extension */
  while (strcmp(chp,"i"))
  {
    ick_Base = (int)strtol(chp,&chp,10);
    if (ick_Base < 2 || ick_Base > maxbase)
      ick_lose(IE998, 1, (const char *)NULL);
    else if (ick_traditional && ick_Base != 2)
      ick_lose(IE111, 1, (const char *)NULL);
    else if (pickcompile && ick_Base != 2)
      ick_lose(IE256, 1, (const char *)NULL); /* AIS */
    ick_Small_digits = smallsizes[ick_Base];
    ick_Large_digits = 2 * ick_Small_digits;
    ick_Max_small = maxsmalls[ick_Base];
    if (ick_Max_small == 0xffff)
      ick_Max_large = (unsigned)0xffffffffLU;
    else
      ick_Max_large = (ick_Max_small + 1) * (ick_Max_small + 1) - 1;
  }
}


/**
 * This checks if we automagically need to include syslib
 * @param buffer Output buffer that may be modified to contain the path of
 *               syslib.i or syslib.Ni (where N is 3-7).
 * @param size Size of buffer.
 * @param needsyslib Pointer to the bool needsyslib declared in main().
 * @param argv0 Should be argv[0], which wasn't modified.
 * @param ick_sysdir The ick data directory.
 * @note May (directly) call ick_lose() with IE127.
 */
static void check_syslib(/*@partial@*/ char *buffer,
                         size_t size,
                         /*@out@*/ bool *needsyslib,
                         /*@observer@*/ const char *argv0,
                         /*@observer@*/ const char *ick_sysdir)
{
    tuple *tp;
    struct linerange_t *lp;

    if (nosyslib || pickcompile) { 
	*needsyslib = false;
	return;
    }

    /*
     * magical inclusion of system libraries is done here
     */
    for (lp = lineranges; lp->start; lp++)
    {
	*needsyslib = false;
	for (tp = tuples; tp->type; tp++) {
	    /*
	     * If some label in the specified range is defined,
	     * then assume the library we seek is already there, so we
	     * can stop searching.
	     */
	    if (tp->label >= lp->start && tp->label <= lp->end) {
		*needsyslib = false;
		goto breakout;
	    }
	    /*
	     * If some label in the specified range is being
	     * called, we might need the library.
	     */
	    if (tp->type == NEXT &&
		tp->u.target >= lp->start && tp->u.target <= lp->end)
		*needsyslib = true;
	}
	if (*needsyslib) {
	    if (ick_Base == 2)
		(void) ick_snprintf_or_die(buffer, size,
					   "%s.i", lp->libname);
	    else
		(void) ick_snprintf_or_die(buffer, size,
					   "%s%d.%di", lp->libname, ick_Base, ick_Base);
	    if (ick_findandfreopen(buffer, ick_sysdir, "r", argv0, stdin) == NULL)
		ick_lose(IE127, 1, (const char*) NULL);
#ifdef USE_YYRESTART
	    yyrestart(stdin);
#endif /* USE_YYRESTART */
	    (void) yyparse();
	    textlinecount=iyylineno;
	}
    breakout:
	;
    }
}

/**
 * This code propagates type information up the expression tree.
 * It also does some unrelated stuff such as checking for WRITE IN and disabling
 * coopt if that is found.
 */
static void propagate_typeinfo(void)
{
  tuple *tp;
  /*
   * Now propagate type information up the expression tree.
   * We need to do this because the unary-logical operations
   * are sensitive to the type widths of their operands, so
   * we have to generate different code depending on the
   * deducible type of the operand.
   */
  for (tp = tuples; tp->type; tp++)
  {
    if (tp->type == GETS || tp->type == RESIZE
	|| tp->type == WRITE_IN || tp->type == READ_OUT
	|| tp->type == FROM || tp->type == MANYFROM
	|| tp->type == FORGET || tp->type == RESUME
	|| tp->type == COMPUCOME || tp->type == UNKNOWN)
      typecast(tp->type == MANYFROM ? tp->u.node->lval : tp->u.node);
    if (tp->type == WRITE_IN) coopt = false; /* AIS: may as well do
					        this here */
  }
}


/**
 * This runs the optimiser.
 */
static void run_optimiser(void)
{
  tuple *tp;
  /* perform optimizations */
  if (dooptimize)
    for (tp = tuples; tp->type; tp++)
    {
      /* AIS: Allow breaching of the only specification on tuples
	  at this point; I've checked that tuples isn't reallocated
	  during the block, so this is fine. */
      /*@-onlytrans@*/
      optuple = tp;
      /*@=onlytrans@*/
      if (tp->type == GETS || tp->type == RESIZE
	  || tp->type == FORGET || tp->type == RESUME
	  || tp->type == FROM || tp->type == COMPUCOME)
	optimize(tp->u.node);
      if (tp->type == MANYFROM) optimize(tp->u.node->lval);
    } /* AIS: Added FROM and MANYFROM support. */

  /* AIS: perform flow optimizations */
  if (flowoptimize) optimizef();
}


/**
 * Generate random line number for E774.
 * @returns A random line number, or -1 for no random bug generated.
 */
static int randomise_bugline(void)
{
  /* decide if and where to place the compiler bug */
#ifdef USG
  if (!nocompilerbug && lrand48() % 10 == 0)
    return (int)(lrand48() % ick_lineno);
#else
  if (!nocompilerbug && rand() % 10 == 0)
    return rand() % ick_lineno;
#endif
  else
    return -1;
}


/**
 * This opens the outfile.
 * @param filename The filename to open.
 * @returns A pointer to a FILE for the filename. If the global outtostdout is
 * set then it will return stdout.
 * @note May (directly) call ick_lose() with IE888.
 */
static /*@dependent@*/ FILE* open_outfile(/*@observer@*/ const char * filename)
{
  FILE *ofp;
  /* AIS: ofp holds fopened storage if !outtostdout, and local-copy
     storage if outtostdout, and this is not a bug, although it
     confuses Splint. */
  /*@-branchstate@*/
  if(outtostdout) ofp=stdout; /* AIS */
  else if((ofp = ick_debfopen(filename, "w")) == (FILE *)NULL)
    ick_lose(IE888, 1, (const char *)NULL);
  /*@=branchstate@*/
  return ofp;
}


/**
 * This generates the CC command line.
 * @param buffer Output buffer.
 * @param size Size of the output buffer.
 * @param sourcefile The name of the C file.
 * @param includedir The ick include directory.
 * @param path The path of the ick binary (execuding filename).
 * @param libdir The ick library directory.
 * @param outputfile The name of the output file.
 */
static void gen_cc_command(char* buffer, size_t size,
                           /*@observer@*/ const char* sourcefile,
                           /*@observer@*/ const char* includedir,
                           /*@observer@*/ const char* path,
                           /*@observer@*/ const char* libdir,
                           /*@observer@*/ const char* outputfile)
{
  (void) ick_snprintf_or_die(buffer, size,
			     "%s %s%s-I%s -I%s -I%s/../include -L%s -L%s -L%s/../lib -O%c -o %s" EXEEXT " -lick%s%s",
#ifdef __DJGPP__
			     "",
#else
			     compiler,
#endif
#ifdef HAVE_CLOCK_GETTIME /* implies -lrt is available */
			     sourcefile, yukdebug||yukprofile?" -lyuk -lrt ":" ",
#else
			     sourcefile, yukdebug||yukprofile?" -lyuk ":" ",
#endif
			     includedir, path, path, libdir, path, path,
			     cdebug?'0':coopt?'3':'2', /* AIS: If coopting, optimize as much as possible
							   JH: [d]on't optimise when compiling with debugger support */
			     outputfile, multithread?"mt":"", cdebug?" -g":"");
  /* AIS: Possibly link in the debugger yuk and/or libickmt.a here. */
  /* AIS: Added -g support. */
  /* AIS: Added argv[0] (now path) to the -I, -L settings. */
}


/**
 * This generates the actual C code.
 * @param ifp This should be opened to either ick-wrap.c or pickwrap.c.
 * @param ofp The out file.
 * @param source_name_stem Source name stem
 * @param needsyslib Pointer to the needsyslib bool in main().
 * @param bugline What line number to add a random bug to.
 * @param compilercommand The compiler command line.
 * @note May (directly) call ick_lose() with IE256.
 */
static void generate_code(FILE *ifp, FILE *ofp,
                          /*@observer@*/  const char* source_name_stem,
                          bool *needsyslib,
                          int bugline,
                          /*@observer@*/ const char* compilercommand)
{
  int maxabstain;
  int           c, i;
  tuple   *tp;
  atom    *op;
  while ((c = myfgetc(ifp)) != EOF)
    if (c != (int)'$')
      (void) fputc(c, ofp);
    else switch(myfgetc(ifp))
	 {
	 case 'A':	/* source name stem */
	   (void) fputs(source_name_stem, ofp);
	   break;

	 case 'B':	/* # of statements */
	   (void) fprintf(ofp, "%d", ick_lineno);
	   break;

	 case 'C':	/* initial abstentions */
	   /* AIS: Modified to check for coopt, pickcompile */
	   maxabstain = 0;
	   for (tp = tuples; tp->type; tp++)
	     if (((tp->exechance <= 0 || tp->exechance >= 101)
		  && tp - tuples + 1 > maxabstain)
		 || coopt || pickcompile)
	       maxabstain = tp - tuples + 1;
	   if (maxabstain)
	   {
	     if(!pickcompile) (void) fprintf(ofp, " = {");
	     for (tp = tuples; tp < tuples + maxabstain; tp++)
	     {
	       if(tp->exechance != 100 && tp->exechance != -100)
	       { /* AIS: The double-oh-seven operator prevents
		    coopt working. However, syslib contains a
		    double-oh-seven. feh.c has checked that that
		    isn't referenced; if it isn't, we can allow
		    one double-oh-seven if syslib was
		    automagically inclulded. */
		 if(*needsyslib) *needsyslib = false; else coopt = false;
	       }
	       if(!pickcompile)
	       {
		 if (tp->exechance > 0)
		 {
		   (void) fprintf(ofp, "0, ");
		   tp->initabstain=0; /* AIS: -f might not be
					 given, so we can't rely
					 on dekludge.c doing
					 this */
		 }
		 else {
		   (void) fprintf(ofp, "1, ");
		   tp->exechance = -tp->exechance;
		   tp->initabstain=true; /* AIS: As above */
		   /* AIS: If the line was ick_abstained, we need to
		      swap ONCEs and AGAINs on it round, to suit
		      the code degenerator. */
		   if(tp->onceagainflag == onceagain_ONCE)
		     tp->onceagainflag = onceagain_AGAIN;
		   else if(tp->onceagainflag == onceagain_AGAIN)
		     tp->onceagainflag = onceagain_ONCE;
		 }
		 if(tp->exechance >= 101)
		 {
		   /* AIS: This line has a MAYBE */
		   tp->maybe = true;
		   tp->exechance /= 100;
		 }
		 else tp->maybe = false;
	       }
	       else /* AIS: hardcoded abstain bits for PICs */
	       {
		 if(!tp->abstainable) continue;
		 if(tp->exechance > 0)
		   (void) fprintf(ofp, "ICK_INT1 ICKABSTAINED(%d)=0;\n",(int)(tp-tuples));
		 else
		   (void) fprintf(ofp, "ICK_INT1 ICKABSTAINED(%d)=1;\n",(int)(tp-tuples));
	       }
	     }
	     if(!pickcompile) (void) fprintf(ofp, "}");
	   }
	   break;

	 case 'D':	/* linetypes array for abstention handling */
	   maxabstain = 0;
	   for (tp = tuples; tp->type; tp++)
	     if (tp->type == ENABLE || tp->type == DISABLE || tp->type == MANYFROM)
	       maxabstain++;
	   if (maxabstain || /* AIS */ gerucomesused)
	   {
	     int j=0; /* AIS */
	     /* AIS: Changed to use enablersm1 */
	     i = 0;
	     for (;i < (int)(sizeof(enablersm1)/sizeof(char *));i++)
	       (void) fprintf(ofp,
			      "#define %s\t%d\n",
			      enablersm1[i], i);

	     (void) fprintf(ofp, "int linetype[] = {\n");
	     for (tp = tuples; tp->type; tp++)
	       if(tp->ppnewtype) /* AIS */
		 (void) fprintf(ofp,"    %s,\n",
				enablers[tp->ppnewtype - GETS]);
	       else if(tp->preproc) /* AIS */
		 (void) fprintf(ofp,"    PREPROC,\n");
	       else if (tp->type >= GETS && tp->type <= FROM)
		 /* AIS: FROM added */
		 (void) fprintf(ofp,
				"    %s,\n",
				enablers[tp->type - GETS]);
	       else
		 /* AIS: I didn't change this code, but relied on
		    it when implementing just-in-case compilation;
		    SPLATTERED and UNKNOWN (the two types of
		    syntax error, unsalvageable and salvageable
		    respectively) both become UNKNOWN in the
		    linetypes array. */
		 (void) fprintf(ofp, " UNKNOWN,\n");
	     (void) fprintf(ofp, "};\n");
	     /* AIS: Implement the reverse of this array too (i.e.
		from line types to lines); this significantly
		speeds up up reinstate/abstain on gerunds. Joris
		Huizer originally suggested the optimisation in
		question; this implements the same algorithm in a
		more maintainable way. (I didn't want to have to
		keep five copies of the command list in sync; two
		is bad enough!) */
	     (void) fprintf(ofp, "int revlinetype[] = {\n");
	     for(i=0;i < (int)(sizeof(enablersm1)/sizeof(char *));i++)
	     {
	       (void) fprintf(ofp,"/* %s */",enablersm1[i]);
	       for (tp = tuples; tp->type; tp++)
	       {
		 if((tp->ppnewtype && tp->ppnewtype-GETS == i-1) ||
		    (!tp->ppnewtype && tp->preproc &&
		     i-1 == PREPROC-GETS) ||
		    (!tp->ppnewtype && !tp->preproc &&
		     tp->type >= GETS && tp->type <= FROM &&
		     tp->type-GETS == i-1) ||
		    (!i && !tp->ppnewtype && !tp->preproc &&
		     (tp->type < GETS || tp->type > FROM)))
		   (void) fprintf(ofp, " %ld,",(long)(tp-tuples));
	       }
	       (void) fprintf(ofp,"\n");
	     }
	     (void) fprintf(ofp, "};\n");
	     (void) fprintf(ofp, "int revlineindex[] = {\n");
	     for(i=0;i < (int)(sizeof(enablersm1)/sizeof(char *));i++)
	     {
	       (void) fprintf(ofp,"/* %s */",enablersm1[i]);
	       (void) fprintf(ofp," %d,\n",j);
	       for (tp = tuples; tp->type; tp++)
	       {
		 if((tp->ppnewtype && tp->ppnewtype-GETS == i-1) ||
		    (!tp->ppnewtype && tp->preproc &&
		     i-1 == PREPROC-GETS) ||
		    (!tp->ppnewtype && !tp->preproc &&
		     tp->type >= GETS && tp->type <= FROM &&
		     tp->type-GETS == i-1) ||
		    (!i && !tp->ppnewtype && !tp->preproc &&
		     (tp->type < GETS || tp->type > FROM)))
		   j++;
	       }
	     }
	     (void) fprintf(ofp, "/* end */ %d\n};\n",j);
	   }
	   break;

	 case 'E':	/* extern to intern map */
	   if(!pickcompile)
	   {
	     (void) fprintf(ofp,"int ick_Base = %d;\n",ick_Base);
	     (void) fprintf(ofp,"int ick_Small_digits = %d;\n",
			    ick_Small_digits);
	     (void) fprintf(ofp,"int ick_Large_digits = %d;\n",
			    ick_Large_digits);
	     (void) fprintf(ofp,"unsigned int ick_Max_small = 0x%x;\n",
			    ick_Max_small);
	     (void) fprintf(ofp,"unsigned int ick_Max_large = 0x%x;\n",
			    ick_Max_large);
	     if (yukprofile || yukdebug || multithread || useickec)
	     { /* AIS: yuk.c, multithreading require all these to exist */
	       if(!nonespots) nonespots = 1;
	       if(!ntwospots) ntwospots = 1;
	       if(!ntails) ntails = 1;
	       if(!nhybrids) nhybrids = 1;
	     }
	     else if(opoverused)
	     {
	       /* AIS: The operand-overloading code requires onespot and
		  twospot variables to exist. */
	       if(!nonespots) nonespots = 1;
	       if(!ntwospots) ntwospots = 1;
	     }
	     /* AIS:I de-staticed all these so they could be accessed by
		yuk and cesspool, and added all the mentions of yuk and
		multithread. Then I changed it so the variables would be
		allocated dynamically, to speed up multithreading. (It's
		an O(1) change to the speed of ordinary programs, so I
		thought I could get away with it. The order is wrt the
		number of lines in the program. The change is O(n) wrt
		the number of variables, but again I hope that doesn't
		matter, and I won't get the entire INTERCAL community
		angry with me for daring to implement an extension that
		slows down existing programs.) */
	     if (variableconstants) /* AIS */
	     {
	       int temp=0;
	       (void) fprintf(ofp, "ick_type32 meshes[%d] = {",nmeshes);
	       while(temp<nmeshes)
	       {
		 (void) fprintf(ofp, "%luLU, ", varextern((unsigned long)temp,MESH));
		 temp++;
	       }
	       (void) fprintf(ofp, "};\n");
	     }

	     if (nonespots)
	     {
	       (void) fprintf(ofp,
			      "ick_type16* ick_onespots;\n");
	       (void) fprintf(ofp,
			      "bool* ick_oneforget;\n");
	       if(yukprofile || yukdebug)
	       {
		 (void) fprintf(ofp,
				"ick_type16 oneold[%d];\n",
				nonespots);
		 (void) fprintf(ofp,
				"signed char onewatch[%d];\n",
				nonespots);
	       }
	       if(multithread)
	       {
		 (void) fprintf(ofp,
				"int onespotcount = %d;\n",
				nonespots);
	       }
	       if(multithread || opoverused || useickec) /* AIS */
	       {
		 int temp=nonespots;
		 (void) fprintf(ofp,
				"ick_overop* ick_oo_onespots = 0;\n");
		 if(opoverused)
		   while(temp--)
		     (void) fprintf(ofp,
				    "ick_type32 og1spot%d(ick_type32 t)\n{\n  (void)t;\n  return ick_onespots[%d];\n}\n"
				    "void os1spot%d(ick_type32 val, void(*f)())\n{\n  (void)f;\n  ick_assign((void*)"
				    "(ick_onespots+%d), ick_ONESPOT, ick_oneforget[%d], val);\n}\n",temp,temp,temp,temp,temp);
	       }
	     }
	     if (ntwospots)
	     {
	       (void) fprintf(ofp,
			      "ick_type32* ick_twospots;\n");
	       (void) fprintf(ofp,
			      "bool* ick_twoforget;\n");
	       if(yukprofile || yukdebug)
	       {
		 (void) fprintf(ofp,
				"ick_type32 twoold[%d];\n",
				ntwospots);
		 (void) fprintf(ofp,
				"signed char twowatch[%d];\n",
				ntwospots);
	       }
	       if(multithread)
	       {
		 (void) fprintf(ofp,
				"int twospotcount = %d;\n",
				ntwospots);
	       }
	       if(multithread || opoverused || useickec) /* AIS */
	       {
		 int temp=ntwospots;
		 (void) fprintf(ofp,
				"ick_overop* ick_oo_twospots = 0;\n");
		 if(opoverused)
		   while(temp--)
		     (void) fprintf(ofp,
				    "ick_type32 og2spot%d(ick_type32 t)\n{\n  (void)t;\n  return ick_twospots[%d];\n}\n"
				    "void os2spot%d(ick_type32 val, void(*f)())\n{\n  (void)f;\n  ick_assign((void*)"
				    "(ick_twospots+%d), ick_TWOSPOT, ick_twoforget[%d], val);\n}\n",temp,temp,temp,temp,temp);
	       }
	     }
	     if (ntails)
	     {
	       (void) fprintf(ofp,
			      "ick_array* ick_tails;\n");
	       (void) fprintf(ofp,
			      "bool* ick_tailforget;\n");
	       if(multithread)
	       {
		 (void) fprintf(ofp,
				"int tailcount = %d;\n",
				ntails);
	       }
	     }
	     if (nhybrids)
	     {
	       (void) fprintf(ofp,
			      "ick_array* ick_hybrids;\n");
	       (void) fprintf(ofp,
			      "bool* ick_hyforget;\n");
	       if(multithread)
	       {
		 (void) fprintf(ofp,
				"int hybridcount = %d;\n",
				nhybrids);
	       }
	     }
	     if (yydebug || compile_only)
	     {
	       assert(oblist != NULL);
	       for (op = oblist; op < obdex; op++)
		 if(op->type!=MESH) /* AIS: Added this check */
		   (void) fprintf(ofp, " /* %s %lu -> %lu */\n",
				  nameof(op->type, vartypes),
				  op->extindex,
				  op->intindex);
	     }
	     if (yukdebug || yukprofile)
	     { /* AIS: drop intern to extern map into the program */
	       (void) fprintf(ofp, "\nyukvar yukvars[]={\n");
	       assert(oblist != NULL);
	       for (op = oblist; op < obdex; op++)
		 if(op->type!=MESH) /* AIS: Added this check */
		   (void) fprintf(ofp,"    {%s,%lu,%lu},\n",
				  nameof(op->type, vartypes),
				  op->extindex,
				  op->intindex);
	       (void) fprintf(ofp,"    {YUKEND,0,0}};\n");
	     }
	     else if(useickec)
	     { /* AIS: likewise, but with different identifiers */
	       (void) fprintf(ofp, "\nick_ec_var ick_ec_vars[]={\n");
	       assert(oblist != NULL);
	       for (op = oblist; op < obdex; op++)
		 if(op->type!=MESH)
		   (void) fprintf(ofp,"    {%s,%lu,%lu},\n",
				  nameof(op->type, vartypes),
				  op->extindex,
				  op->intindex);
	       (void) fprintf(ofp,"    {ICK_EC_VARS_END,0,0}};\n");
	     }
	   }
	   else
	   {
	     /* Compiling for PIC */
	     /* Arrays not supported on PICs */
	     if(ntails || nhybrids)
	       ick_lose(IE256, iyylineno, (const char*) NULL);
	     /* and neither are variable constants */
	     if(variableconstants)
	       ick_lose(IE256, iyylineno, (const char*) NULL);
	     assert(oblist != NULL);
	     for (op = oblist; op < obdex; op++)
	     {
	       (void) fprintf(ofp, " /* %s %lu -> %lu */\n",
			      nameof(op->type, vartypes),
			      op->extindex,
			      op->intindex);
	       (void) fprintf(ofp, "#define %s%lu %s[%lu]\n",
			      nameof(op->type, vartypes),
			      op->extindex,
			      nameof(op->type, varstores),
			      op->intindex);
	       if(op->ignorable)
		 (void) fprintf(ofp, "ICK_INT1 ignore%s%lu = 0;\n",
				nameof(op->type, varstores),
				op->intindex);
	     }
	     (void) fprintf(ofp, "#include \"pick1.h\"\n");
	     if(nonespots)
	     {
	       (void) fprintf(ofp,
			      "ICK_INT16 ick_onespots[%d];\n"
			      "ICK_INT16 onespotsstash[%d];\n",
			      nonespots,
			      nonespots);
	       if(opoverused) /* AIS */
	       {
		 int temp=nonespots;
		 (void) fprintf(ofp,"ick_overop* ick_oo_onespots;\n");
		 while(temp--)
		   (void) fprintf(ofp,
				  "ick_type32 og1spot%d(ick_type32 t)\n{\n  (void)t;\n  return ick_onespots[%d];\n}\n"
				  "void os1spot%d(ick_type32 val,void(*f)())\n{\n  (void)f;\n  if(!ignoreonespots%d)"
				  " ick_onespots[%d]=val;\n}\n",temp,temp,temp,temp,temp);
	       }
	     }
	     if(ntwospots)
	     {
	       (void) fprintf(ofp,
			      "ICK_INT32 ick_twospots[%d];\n"
			      "ICK_INT32 twospotsstash[%d];\n",
			      ntwospots,
			      ntwospots);
	       if(opoverused) /* AIS */
	       {
		 int temp=ntwospots;
		 (void) fprintf(ofp,"ick_overop* ick_oo_twospots;\n");
		 while(temp--)
		   (void) fprintf(ofp,
				  "ick_type32 og2spot%d(ick_type32 t)\n{\n  (void)t;\n  return ick_twospots[%d];\n}\n"
				  "void os2spot%d(ick_type32 val,void(*f)())\n{\n  (void)f;\n  if(!ignoretwospots%d)"
				  " ick_twospots[%d]=val;\n}\n",temp,temp,temp,temp,temp);
	       }
	     }
	     (void) fprintf(ofp, "#include \"pick2.h\"\n");
	   }
	   break;

	 case 'F':	/* set options from command line */
	   if (ick_clockface)
	     (void) fprintf(ofp, "ick_clockface(true);\n");
	   if (ick_clcsemantics) /* AIS */
	     (void) fprintf(ofp, "ick_setclcsemantics(true);\n");
	   break;

	 case 'G':	/* degenerated code */
	   for (tp = tuples, i = 0; tp->type; tp++, i++)
	   {
	     emit(tp, ofp);
	     if (i == bugline)
	       (void) fprintf(ofp, "    ick_lose(IE774, ick_lineno, "
			      "(char *)NULL);\n");
	   }
	   break;

	 case 'H':	/* COMPUCOME, and dispatching for resumes */
	   /* AIS: Added COMPUCOME here. This line must be fully guarded
	      to prevent a longjmp to an uninitialised buffer (it's
	      guarded by a ick_lose() in ick-wrap.c.) Also checks for
	      multithread; programs that mix normal and computed COME
	      FROM need to use the same conventions for both, so even
	      if no computed COME FROMs are used, the normal ones need
	      this line so that COME FROMs can be handled consistently.*/
	   if(compucomesused || multithread)
	   {
	     (void) fprintf(ofp, "CCFL: ; CCF%d: longjmp(ick_cjb,1);\n",
			    compucomecount);
	   }
	   break;

	 case 'J':	/* # of source file lines */
	   (void) fprintf(ofp, "%d", iyylineno);
	   break;

	 case 'K':       /* AIS: yuk information (or not) */
	   if(yukdebug||yukprofile)
	   {
	     (void) fprintf(ofp, "#include \"config.h\"\n\n");
	     (void) fprintf(ofp, "#include \"yuk.h\"\n\n");
	     (void) fprintf(ofp, "char* textlines[] = {\n");
	     emittextlines(ofp); /* from feh.c */
	     (void) fprintf(ofp, "\"\"};\n\n");
	     (void) fprintf(ofp, "char* yukexplain[] = {\n");
	     for (tp = tuples; tp->type; tp++)
	     {
	       if (tp->type == GETS || tp->type == FORGET || tp->type == RESUME
		   || tp->type == FROM || tp->type == COMPUCOME
		   || tp->type == MANYFROM)
	       {
		 (void) fprintf(ofp, "\"");
		 explexpr(tp->type == MANYFROM ? tp->u.node->lval :
			  tp->type == GETS ? tp->u.node->rval : tp->u.node, ofp);
		 (void) fprintf(ofp, "\",\n");
	       }
	       else (void) fprintf(ofp, "0,");
	     }
	     (void) fprintf(ofp, "0};\n\n");
	     (void) fprintf(ofp, "int lineofaboff[] = {\n");
	     for (tp = tuples; tp->type; tp++)
	     {
	       fprintf(ofp,"%d,",tp->ick_lineno);
	     }
	     (void) fprintf(ofp, "-1};\n\n");
	     /*@+boolint@*/
	     (void) fprintf(ofp, "int yukopts = %d;\n", yukprofile+yukdebug*2);
	     /*@=boolint@*/
	     (void) fprintf(ofp, "yptimer ypexectime[%d];\n", ick_lineno);
	     (void) fprintf(ofp, "ypcounter ypexecount[%d];\n",ick_lineno);
	     (void) fprintf(ofp, "ypcounter ypabscount[%d];\n",ick_lineno);
	   }
	   break;

	 case 'L': /* AIS: increase Emacs compatibility */
	   (void) fprintf(ofp,
			  "/* -*- mode:c; compile-command:\"%s%s%s\" -*- */",
#ifdef __DJGPP__
			  compiler," ",
#else
			  "","",
#endif
			  compilercommand);
	   break;

	 case 'M': /* AIS: place new features defines in program */
	   /* This is needed even in a non-multithread program, to let
	      the header files know it's non-multithread */
	     (void) fprintf(ofp, "#define MULTITHREAD %d\n", multithread?1:0);
	   /* Likewise, to let the header files know whether it
	      overloads operands (I don't think this is used at
	      the moment, though) */
	   (void) fprintf(ofp, "#define OPOVERUSED %d\n",opoverused?1:0);
	   /* and whether to use the ICK_EC code */
	   if(useickec)
	     (void) fprintf(ofp, "#define ICK_EC 1\n");
	   break;

	 case 'N':	/* allocate variables */
	   /* AIS:I de-staticed all these so they could be accessed by
	      yuk and cesspool, and added all the mentions of yuk and
	      multithread. Then I changed it so the variables would be
	      allocated dynamically, to speed up multithreading (it's
	      an O(1) change to the speed of ordinary programs, so I
	      thought I could get away with it). At this point, the
	      'E' case must already have been done. calloc sets all
	      the integer values to 0, as before. In the case of
	      arrays, it will not zero pointers, but the number-of-
	      dimensions value will become 0, which can serve as a
	      'deallocated' flag. */
	   if (nonespots)
	   {
	     if(!pickcompile) /* AIS */
	     {
	       (void) fprintf(ofp,
			      "    ick_onespots = calloc("
			      "%d, sizeof *ick_onespots);\n",
			      nonespots);
	       (void) fprintf(ofp,
			      "    ick_oneforget = calloc("
			      "%d, sizeof *ick_oneforget);\n",
			      nonespots);
	     }
	     if(opoverused)
	     {
	       int temp=nonespots;
	       (void) fprintf(ofp,
			      "    ick_oo_onespots=malloc(%d*sizeof*ick_oo_onespots);\n",temp);
	       while(temp--)
		 (void) fprintf(ofp,
				"    ick_oo_onespots[%d].get=og1spot%d;\n    ick_oo_onespots[%d].set=os1spot%d;\n",
				temp,temp,temp,temp);
	     }
	   }
	   if (ntwospots)
	   {
	     if(!pickcompile)
	     {
	       (void) fprintf(ofp,
			      "    ick_twospots = calloc("
			      "%d, sizeof *ick_twospots);\n",
			      ntwospots);
	       (void) fprintf(ofp,
			      "    ick_twoforget = calloc("
			      "%d, sizeof *ick_twoforget);\n",
			      ntwospots);
	     }
	     if(opoverused)
	     {
	       int temp=ntwospots;
	       (void) fprintf(ofp,
			      "    ick_oo_twospots=malloc(%d*sizeof*ick_oo_twospots);\n",temp);
	       while(temp--)
		 (void) fprintf(ofp,
				"    ick_oo_twospots[%d].get=og2spot%d;\n    ick_oo_twospots[%d].set=os2spot%d;\n",
				temp,temp,temp,temp);
	     }
	   }
	   if (ntails&&!pickcompile)
	   {
	     (void) fprintf(ofp,
			    "    ick_tails = calloc("
			    "%d, sizeof *ick_tails);\n",
			    ntails);
	     (void) fprintf(ofp,
			    "    ick_tailforget = calloc("
			    "%d, sizeof *ick_tailforget);\n",
			    ntails);
	   }
	   if (nhybrids&&!pickcompile)
	   {
	     (void) fprintf(ofp,
			    "    ick_hybrids = calloc("
			    "%d, sizeof *ick_hybrids);\n",
			    nhybrids);
	     (void) fprintf(ofp,
			    "    ick_hyforget = calloc("
			    "%d, sizeof *ick_hyforget);\n",
			    nhybrids);
	   }
	   break;
	 case 'O': /* AIS; for GERUCOME and operand overloading */
	   if(gerucomesused || nextfromsused)
	     fprintf(ofp,"unsigned truelineno = 0;\n");
	   if(opoverused)
	     fprintf(ofp,"%s trueval;\n",
		     pickcompile?"ICK_INT32":"ick_type32");
	   break;
	 case 'P': /* AIS: for operand overloading */
	   if(opoverused)
	     emitslatproto(ofp);
	   break;
	 case 'Q': /* AIS: for operand overloading */
	   if(opoverused)
	     emitslat(ofp);
	   break;
	 }
}


/**
 * This runs the C compiler, and may invoke yuk.
 * @param cc_command The compiler command line to use. Constructed by gen_cc_command().
 * @param oldstdin The previous stdin, used for yuk.
 * @param yukcmdstr The command line to use for running yuk.
 * @param sourcefile The output filename.
 * @param binaryname The name of the binary.
 */
static void run_cc_and_maybe_debugger(/*@observer@*/ const char *cc_command,
                                      int oldstdin,
                                      /*@observer@*/ const char *yukcmdstr,
                                      /*@observer@*/ const char *sourcefile,
                                      /*@observer@*/ const char *binaryname)
{
#ifndef __DJGPP__
  /* OK, now sic the C compiler on the results */
  if (!compile_only&&!yukdebug&&!yukprofile&&!useickec)
  {
    /* AIS: buf2 now assigned elsewhere so $L works */
    ICK_SYSTEM(cc_command);
    /* AIS: no unlink if cdebug */ if(!cdebug) (void) unlink(sourcefile);
  }
  else if(!compile_only&&!useickec)
  { /* AIS: run, then delete all output but yuk.out */
    /* Note that the output must be deleted for copyright
       reasons (so as not to GPL a non-GPL file automatically) */
    ICK_SYSTEM(cc_command);
#ifdef HAVE_UNISTD_H
    (void) dup2(oldstdin,0); /* restore stdin */
#endif
    ICK_SYSTEM(yukcmdstr);
    (void) unlink(sourcefile);
    (void) unlink(binaryname);
  }
#else /* we are using DJGPP */
  /* OK, now sic the C compiler on the results */
  if (!compile_only&&!useickec)
  {
    /* AIS: buf2 now assigned elsewhere so $L works */
    /* AIS: This changes somewhat for DJGPP, due to the
       command-line cap. It creates a temporary file
       with the arguments needed to give gcc. */
    FILE* rsp;
    /* Use current dir as temp if needed */
    const char* tempfn="gcc @ickgcc.rsp";
    /* Four tries are used to find a temp directory.
       ICKTEMP is the preferred environment variable to check;
       if, as expected, this isn't set, try TMPDIR (which DJGPP
       sets to its own temp directory, at least when running under
       bash), TEMP and TMP (in that order). DJGPP offers /dev/env
       as a method of accessing environment variables in filenames.*/
    if(isenv("TMP")) tempfn="gcc @/dev/env/TMP/ickgcc.rsp";
    if(isenv("TEMP")) tempfn="gcc @/dev/env/TEMP/ickgcc.rsp";
    if(isenv("TMPDIR")) tempfn="gcc @/dev/env/TMPDIR/ickgcc.rsp";
    if(isenv("ICKTEMP")) tempfn="gcc @/dev/env/ICKTEMP/ickgcc.rsp";
    rsp=ick_debfopen(tempfn+5,"w");
    fprintf(rsp,"%s\n",cc_command);
    fclose(rsp);
    ICK_SYSTEM(tempfn);
    remove(tempfn+5);
    if(yukdebug || yukprofile)
    {
      char buffer[BUFSIZ];
#ifdef HAVE_UNISTD_H
      dup2(oldstdin,0); /* restore stdin */
#endif
/* FIXME: This looks broken (the buf2 usage and such). */
      ick_snprintf_or_die(buffer, sizeof(buffer), "%s" EXEEXT,binaryname);
      ICK_SYSTEM(yukcmdstr);
      remove(sourcefile);
      remove(buffer);
    }
    else if(!cdebug)
    {
      remove(sourcefile);
    }
  }
#endif
}


/**
 * This runs coopt.sh if -F is given and the program can be "coopted".
 * @param cooptsh Path to coopt.sh
 * @param binaryname The output binary filename.
 */
static void run_coopt(/*@observer@*/ /*@null@*/ /*@unused@*/ const char* cooptsh,
                      /*@observer@*/ /*@unused@*/ const char* binaryname)
{
  /* Note: Params are marked unused because they may not be used if sh isn't supported. */
  /* Assume that sh exists if #! does; sh is needed to run autoconf, so this would
     otherwise have to be set by hand anyway. */
#ifdef HAVE_SYS_INTERPRETER
  if(coopt) /* AIS */
  {
    /* The constant-output optimizer is a form of post-processor.
       IMPORTANT NOTE: This MUST NOT be run if the input program
       takes any input or is affected in any way by the state of
       the system, as the degenerated program may be wrong. At the
       moment, the only INTERCAL command that takes input is
       WRITE IN. Double-oh-sevens screw this up, too. */
    if(cooptsh)
    {
      char commandlinebuf[BUFSIZ];
      (void) ick_snprintf_or_die(commandlinebuf, sizeof commandlinebuf,
	                         "sh %s %s", cooptsh, binaryname);
      ICK_SYSTEM(commandlinebuf); /* replaces the output executable if
	                             neccesary */
    }
  }
#endif
}


/**
 * This is for -e, runs prelinking.
 * @param argc Exactly what you think.
 * @param argv Also what you think.
 * @param oldoptind The original optind.
 * @param libdir The ick library directory.
 * @param includedir The ick include directory.
 * @param path The path of the ick binary (execuding filename).
 * @param libbuf A string with -lfoo to add to compiler command line.
 * @note May (directly) call ick_lose() with IE666. IE778 and IE888.
 */
static void prelink(int argc, char *argv[], int oldoptind,
                    /*@observer@*/ const char* libdir,
                    /*@observer@*/ const char *includedir,
                    /*@observer@*/ const char* path,
                    /*@observer@*/ const char* libbuf)
{
  char buffer[BUFSIZ];
  FILE* cioin;
  FILE* cioallec;
  char* buf2ptr;
  long remspace;
  const char* tempfn="ickectmp.c";
  int needc=89;
#if __DJGPP__
  /* Look for a temp directory, as above. */
  if(isenv("TMP")) tempfn="/dev/env/TMP/ickectmp.c";
  if(isenv("TEMP")) tempfn="/dev/env/TEMP/ickectmp.c";
  if(isenv("TMPDIR")) tempfn="/dev/env/TMPDIR/ickectmp.c";
  if(isenv("ICKTEMP")) tempfn="/dev/env/ICKTEMP/ickectmp.c";
#else
  tempfn="/tmp/ickectmp.c"; /* always a valid temporary folder on POSIX */
#endif
  cioallec=ick_debfopen(tempfn,"w");
  if(cioallec == NULL)
    ick_lose(IE888, -1, (const char*) NULL);
  (void) fprintf(cioallec,"void ick_doresume(unsigned short,int);\n");
  (void) fprintf(cioallec,"extern int ick_global_checkmode;\n");
  (void) fprintf(cioallec,"void ick_allecfuncs(void)\n{\n");

  /* Here, we run the C preprocessor on the files in question, then our
     own preprocessor, and finally link all the files together into one
     executable. */
  for(optind=oldoptind; optind < argc; optind++)
  {
    int thisneedc = argv[optind][strlen(argv[optind])+2]=='9'?99:
      argv[optind][strlen(argv[optind])+2]=='1'?11:89;
    if(needc==89 || thisneedc==11)
      needc=thisneedc;
    (void) ick_snprintf_or_die(buffer, sizeof buffer,
			       "%s --std=c%d -E -DICK_HAVE_STDINT_H=%d "
			       "-I%s -I%s -I%s/../include "
			       "-x c %s.c%c%c > %s.cio",
			       compiler, thisneedc,
			       ICK_HAVE_STDINT_H+1-1,
			       includedir, path, path, argv[optind],
                               thisneedc==99?'9':thisneedc==11?'1':' ',
                               thisneedc==99?'9':thisneedc==11?'1':' ',
			       argv[optind]);
    if(*(argv[optind]) && /* there is some file to compile */
       (argv[optind][strlen(argv[optind])+2]=='\0' /* a .c or .i file */
        ||argv[optind][strlen(argv[optind])+3]!='o')) /* not a .cio file */
      ICK_SYSTEM(buffer); /* run the C preprocessor */
    buf2ptr = strrchr(buffer,'>'); /* get the .cio's filename */
    cioin=NULL;
    /* Do our preprocessing, by editing the file in place using rb+. */
    if(buf2ptr != NULL && buf2ptr[1] != '\0' && buf2ptr[2] != '\0')
      cioin=ick_debfopen(buf2ptr+2,"rb+");
    if(cioin)
    {
      int inchar=fgetc(cioin);
      int toparencount=0;
      /* The ppnums are replacements for strings in the .cio file.
	 The choice of 65538 means that we don't clash with any
	 line numbers in the program, but do clash with the other
	 C-INTERCAL preprocessor (that handles WHILE); that isn't a
	 problem because external calls are inconsistent with
	 multithreading anyway. */
      static long ppnum1=65538L*2L;
      static long ppnum2=65538L*2L;
      static long ppnum3=65538L*2L;
      static long ppnum6=65538L*2L;
      long ciopos=0L;
      /*@+charintliteral@*/ /* literal chars are ints */
      while(inchar != EOF)
      {
	if(inchar=='I')
	{
	  /* Look for the ICK_EC_PP_ string that indicates preprocessing
	     is needed. This method of doing it works as long as the
	     ICK_EC_PP_ string is never preceded by something which looks
	     like part of the same string, but luckily, it never is. */
	  if((inchar=fgetc(cioin))!='C') continue;
	  if((inchar=fgetc(cioin))!='K') continue;
	  if((inchar=fgetc(cioin))!='_') continue;
	  if((inchar=fgetc(cioin))!='E') continue;
	  if((inchar=fgetc(cioin))!='C') continue;
	  if((inchar=fgetc(cioin))!='_') continue;
	  if((inchar=fgetc(cioin))!='P') continue;
	  if((inchar=fgetc(cioin))!='P') continue;
	  if((inchar=fgetc(cioin))!='_') continue;
	  inchar=fgetc(cioin);
	  toparencount=0;
	  if(inchar=='0')
	  {
	    fprintf(cioallec,"#undef X\n");
	    fprintf(cioallec,"#define X ");
	    while(fputc(fgetc(cioin),cioallec) != ')') toparencount++;
	  }
	  (void) fseek(cioin,ciopos,SEEK_SET);
	  switch(inchar)
	  {
	  case '0': /* a function exists */
	    fprintf(cioin,"            ");
	    fprintf(cioallec,"\nvoid X(void); X();\n"
		    "if(ick_global_checkmode==5) ick_doresume(1,-1);\n");
	    while(toparencount--) (void) fputc(' ',cioin);
	    break;
	  case '1':
	    fprintf(cioin,"%-11ld",ppnum1++/2);
	    break;
	  case '2':
	    fprintf(cioin,"%-11ld",ppnum2++/2);
	    break;
	  case '3':
	    fprintf(cioin,"%-11ld",ppnum3++/2);
	    break;
	  case '4':
	    fprintf(cioin,"%-11d",optind);
	    break;
	  case '6':
	    fprintf(cioin,"%-11ld",ppnum6++/2);
	    break;
	  default:
	    ick_lose(IE778, -1, (const char*) NULL);
	  }
	  (void) fseek(cioin,0L,SEEK_CUR); /* synch the file */
	}
	ciopos=ftell(cioin);
	inchar=fgetc(cioin);
      }
      /*@=charintliteral@*/
      (void) fclose(cioin);
    }
  }
  fprintf(cioallec,"if(ick_global_checkmode==2)\n");
  fprintf(cioallec,"  ick_global_checkmode=4;\n");
  fprintf(cioallec,"};\n");
  (void) fclose(cioallec);

  /* NOTE: buffer changes use around here. */

  /* This command line needs some explanation, and is specific to gcc and
     GNU ld. The -x causes gcc to interpret the .cio files as C; the
     -Wl,-z,muldefs is an instruction to GNU ld, telling it to link in the
     first main found and ignore the others.  (That way, there can be a
     main function in each .cio, but the .cios can be linked in any order,
     with the right main function foremost each time.)
   */
  (void) ick_snprintf_or_die(buffer, sizeof buffer,
			     "%s -L%s -L%s -L%s/../lib -O2 -o %s" EXEEXT "%s "
#ifndef __DJGPP__
			     "-Wl,-z,muldefs "
#endif
			     "-DICK_HAVE_STDINT_H=%d -x c --std=c%d %s", compiler, libdir,
			     path, path, argv[oldoptind], cdebug?" -g":"", ICK_HAVE_STDINT_H+1==2?1:0,
			     needc,tempfn);
  remspace = (long)(sizeof buffer - strlen(buffer) - 1);
  for(optind=oldoptind; optind < argc; optind++)
  {
    if(!*(argv[optind])) continue;
    remspace -= strlen(argv[optind]) - 5; /* 5 for <space>.cio */
    if(remspace <= 0)
      ick_lose(IE666, -1, (const char*)NULL);
    strcat(buffer," ");
    strcat(buffer,argv[optind]);
    strcat(buffer,".cio");
  }
  remspace -= strlen(libbuf);
  if(remspace <= 0)
    ick_lose(IE666, -1, (const char*)NULL);
  strcat(buffer,libbuf);
  remspace -= strlen(" -lickec");
  if(remspace <= 0)
    ick_lose(IE666, -1, (const char*)NULL);
  strcat(buffer," -lickec");
  ICK_SYSTEM(buffer);
  (void) remove(tempfn);
}


/*@-redef@*/
int main(int argc, char *argv[])
/*@=redef@*/
{
  char	buf[BUFSIZ], buf2[BUFSIZ], *chp, yukcmdstr[BUFSIZ], path[BUFSIZ],
    libbuf[BUFSIZ];
  /*@-shadow@*/ /* no it doesn't, cesspool isn't linked to perpet */
  const char	*includedir, *libdir, *ick_sysdir, *ick_cskeldir;
  /*@=shadow@*/
  /* AIS: removed getenv(), added ick_sysdir */
  const char        *cooptsh; /* AIS */
  FILE	*ifp, *ofp;
  int		/* nextcount, AIS */ bugline;
  bool        needsyslib, firstfile;
  int         oldoptind;
#ifdef HAVE_UNISTD_H
  int         oldstdin; /* AIS: for keeping track of where stdin was */
#endif
  if (!(includedir = getenv("ICKINCLUDEDIR")))
    includedir = ICKINCLUDEDIR;
  if (!(libdir = getenv("ICKLIBDIR")))
    libdir = ICKLIBDIR;
  if (!(ick_sysdir = getenv("ICKSYSDIR")))
    ick_sysdir = ICKSYSDIR;
  if (!(ick_cskeldir = getenv("ICKCSKELDIR")))
    ick_cskeldir = ICKCSKELDIR;
/*
  AIS: nothing actually uses this at the moment,
  commenting it out for future use

  if (!(bindir = getenv("ICKBINDIR")))
  bindir = ICKBINDIR;
*/
  if (!(compiler = getenv("CC")))
    compiler = CC;

  /* Parse the options. */
  parse_options(argc, argv);

  (void) signal(SIGSEGV, abend);
#ifdef SIGBUS
  (void) signal(SIGBUS, abend);
#endif /* SIGBUS */

  if (!nocompilerbug) {
#ifdef USG
    srand48(time(NULL) + getpid());
#else
    srand((unsigned)time(NULL));
#endif /* UNIX */
  }

  /* AIS: New function for enhanced file-finding */
  ifp = ick_findandfopen(pickcompile?PSKELETON:SKELETON,
			 ick_cskeldir, "r", argv[0]);
  if(!ifp) ick_lose(IE999, 1, (const char *)NULL);

  /* now substitute in tokens in the skeleton */

  /* AIS: This doesn't actually seem to do anything, and buf is
     uninitialised at this point, so it's actually dangerous
     because it's undefined behaviour.
     buf[strlen(buf) - 2] = '\0'; */

  /* AIS: Save the old stdin, if we can */
#ifdef HAVE_UNISTD_H
  oldstdin=dup(0);
#endif

  oldoptind=optind; /* AIS */
  *libbuf = '\0'; /* AIS */
  /* Begin file loop */
  for (firstfile = true; optind < argc; optind++, firstfile = false)
  {
    /* AIS: Read as binary to pick up Latin-1 and UTF-8 better */
    if (/* AIS */ strrchr(argv[optind],'.') != NULL &&
	freopen(argv[optind], "rb", stdin) == (FILE *)NULL &&
	/* AIS */ strcmp(strchr(argv[optind],'.')+1,"a"))
	ick_lose(IE777, 1, (const char *)NULL);
    else
    {
      /* strip off the file extension */
      if(!(chp = strrchr(argv[optind],'.')))
      {
	if(useickec && firstfile == false) /* By AIS */
	{
	  /* the filename indicates a request for an expansion library,
	     along the same lines as CLC-INTERCAL's preloads. Search for
	     it in the usual places, then make a copy in a temp directory
	     and substitute that on the command line. */
	  const char* tempfn;
	  FILE* fromcopy;
	  FILE* tocopy;
	  int c2;
	fixexpansionlibrary:
	  tempfn="%s.c";
	  (void) ick_snprintf_or_die(buf2, sizeof buf2, "%s.c", argv[optind]);
	  fromcopy = ick_findandfopen(buf2,ick_cskeldir,"rb",argv[0]);
	  if(!fromcopy) /* same error as for syslib */
	    ick_lose(IE127, 1, (const char*) NULL);
#if __DJGPP__
	  /* Look for a temp directory to store a copy of the C file,
	     the resulting .cio, .o files, etc. */
	  if(isenv("TMP")) tempfn="/dev/env/TMP/%s.c";
	  if(isenv("TEMP")) tempfn="/dev/env/TEMP/%s.c";
	  if(isenv("TMPDIR")) tempfn="/dev/env/TMPDIR/%s.c";
	  if(isenv("ICKTEMP")) tempfn="/dev/env/ICKTEMP/%s.c";
#else
	  tempfn="/tmp/%s.c"; /* always valid on POSIX */
#endif
	  /*@-formatconst@*/ /* all possibilities are fine */
	  (void) ick_snprintf_or_die(buf2, sizeof buf2, tempfn, argv[optind]);
	  /*@=formatconst@*/
	  if((tocopy = fopen(buf2,"wb")) == NULL)
	    ick_lose(IE888, 1, (const char*) NULL);

	  for(;;)
	  {
	    c2=fgetc(fromcopy);
	    if(c2==EOF) break;
	    (void) fputc(c2,tocopy);
	  }
	  (void) fclose(fromcopy); (void) fclose(tocopy);
	  /*@+onlytrans@*/
	  /* this is a memory leak that will need sorting out later,
	     thus the explicit turn-warning-on */
	  argv[optind]=malloc(sizeof(buf2)+1);
	  /*@=onlytrans@*/
	  if(!(argv[optind]))
	    ick_lose(IE888, 1, (const char*) NULL);
	  strcpy(argv[optind],buf2);
	  *(strrchr(argv[optind],'.')) = '\0';
	  continue;
	}

	ick_lose(IE998, 1, (const char *)NULL);
      }
      *chp++ = '\0';

      /* Beginning of block that figures out file type from extension. */
      if(useickec && (!strcmp(chp,"c") || !strcmp(chp,"cio") ||
		      !strcmp(chp,"c99") || !strcmp(chp,"c11"))) /* AIS */
      {
	if(firstfile != false) /* need exactly 1 INTERCAL file */
	  ick_lose(IE998, 1, (const char *)NULL);
	continue; /* don't process C or cio files further yet */
      }

      if(useickec && !strcmp(chp,"a"))
      {
	/* AIS: request for a library. Given a filename of the form
	   libwhatever.a, it adds  -lwhatever to libbuf (that's with
	   a preceding space). If the filename doesn't start with lib,
	   it instead adds a space and the filename to libbuf. */
	handle_archive(libbuf, sizeof libbuf,
	               argv[optind] /* Archive name without extension. */);
	*argv[optind]='\0';
	continue;
      }

      if(useickec && !strcmp(chp,"b98"))
      {
	handle_befunge98(libbuf, sizeof libbuf, libdir, argv[0],
	                 argv[optind] /* Filename without extension. */);
	/* Sort out the ecto_b98 expansion library. */
	argv[optind] = "ecto_b98";
	goto fixexpansionlibrary;
      }

      if(useickec && firstfile == false) /* AIS */
	ick_lose(IE998, 1, (const char *)NULL);

      /* determine the file type from the extension */
      /* AN: chp isn't used again after this it seems? */
      find_intercal_base(chp);

      /* End of block that figures out file type from extension. */

      /* zero out tuple and oblist storage */
      treset();
      politesse = 0;
      /* JH: default to no op-overusage and no computed come from */
      opoverused = false;
      compucomesused = false;
      compucomecount = 0;
      gerucomesused = false; /* AIS: you forgot this one */
      /* AIS: ensure that at least one variable exists, to prevent
	 NULL pointers later on */
      (void) intern(ick_ONESPOT, 1); /* mention .1 */

      /* reset the lex/yacc environment */
      if (!firstfile)
      {
#ifdef NEED_YYRESTART
	yyrestart(stdin);
#endif /* NEED_YYRESTART */
	iyylineno = 1;
      }

      /* compile tuples from current input source */
      (void) yyparse();

      if(variableconstants)
      {
	/* AIS: Up to 4 extra meshes may be needed by feh.c. */
	(void) intern(MESH, 0xFFFFFFFFLU);
	(void) intern(MESH, 0xFFFFLU);
	(void) intern(MESH, 0xAAAAAAAALU);
	(void) intern(MESH, 0x55555555LU);
      }


      /*
       * Miss Manners lives.
       */
      if (ick_lineno > 2)
      {
	if (politesse == 0 || (ick_lineno - 1) / politesse >= 5)
	  ick_lose(IE079, iyylineno, (const char *)NULL);
	else if (ick_lineno / politesse < 3)
	  ick_lose(IE099, iyylineno, (const char *)NULL);
      }

      /* Check if we should auto add the system library. */
      check_syslib(buf2, sizeof buf2, &needsyslib, argv[0], ick_sysdir);

      /*
       * Now propagate type information up the expression tree.
       * We need to do this because the unary-logical operations
       * are sensitive to the type widths of their operands, so
       * we have to generate different code depending on the
       * deducible type of the operand.
       */
      propagate_typeinfo();

      codecheck();	/* check for compile-time errors */
      /* AIS: And importantly, sort out line number references */
      run_optimiser();

      /* decide if and where to place the compiler bug */
      bugline = randomise_bugline();

      /* set up the generated C output file name */
      (void) ick_snprintf_or_die(buf, sizeof buf, "%s.c", argv[optind]);
      /* Open output file. */
      ofp = open_outfile(buf /* Output filename */);

      (void) fseek(ifp,0L,0);	/* rewind skeleton file */

      /* AIS: Before changing argv[0], locate coopt.sh. */
      /* AN: Even though argv[0] isn't changed any more this breaks if moved out
       * of the per-file loop since ick_findandtestopen() returns a pointer to a
       * static buffer. Should be fixed.
       */
      cooptsh = ick_findandtestopen("coopt.sh", ick_sysdir, "rb", argv[0]);
      /* AIS: and calculate yukcmdstr. */
      (void) ick_snprintf_or_die(yukcmdstr, sizeof yukcmdstr, "%s%s" EXEEXT " %s %s",
				 strchr(argv[optind],'/')||strchr(argv[optind],'\\')?
				 "":"./",argv[optind],ick_sysdir,argv[0]);

      /* AIS: Remove the filename from argv[0], leaving only a directory.
	 If this would leave it blank, change argv[0] to '.'.
	 This is so gcc can find the includes/libraries the same way that
	 ick_findandfreopen does. */
      /* JH: use a copy of argv[0] for the path, to ensure argv[0] is
       * available for the next round
       */
      strcpy(path,argv[0]);
      if(strchr(path,'/')) *(strrchr(path,'/')) = '\0';
      else strcpy(path,".");

      /* Generate the compiler command. */
      gen_cc_command(buf2 /* output */, sizeof buf2, buf /* Source filename. */,
		     includedir, path, libdir, argv[optind] /* Output binary filename. */);

      textlinecount=0; /* AIS: If there are no files, there's
			  no need to free any textlines */
      /* Generate code using ick-wrap.c (or pickwrap.c) */
      generate_code(ifp, ofp, argv[optind] /* Source file name stem. */,
                    &needsyslib, bugline, buf2 /* CC command. */);

      if(!outtostdout) (void) fclose(ofp);

      /* OK, now sic the C compiler on the results */
      /* Also: if -y was given, run debugger */
      run_cc_and_maybe_debugger(buf2, oldstdin, yukcmdstr, buf /* C file name */,
                                argv[optind] /* Binary filename */);

      /* Run the constant-output optimizer (a form of post-processor). */
      run_coopt(cooptsh, argv[optind]);

    }
  }
  /* Here ends the per-file loop. */
  (void) fclose(ifp);

  if(!compile_only && useickec) /* AIS */
    prelink(argc, argv, oldoptind, libdir, includedir, path, libbuf);

  /* AIS: Free malloc'd memory. */
  if(textlines)
  {
    /* Marking what textlines points to as only would be the 'right'
       way to do this (because it is only), but I can't figure out the
       syntax to do it, so instead I'm supressing the warning that comes
       up because it isn't marked as only. */
    /*@-unqualifiedtrans@*/
    while(textlinecount--) free(textlines[textlinecount]);
    free(textlines);
    /*@=unqualifiedtrans@*/
  }

#ifdef HAVE_UNISTD_H
  (void) close(oldstdin); /* AIS */
#endif
  /* This point is the very end of the program. So it's correct for
     normal DO NOT FREE UNDER ANY CIRCUMSTANCES globals to be free
     at this point, so supressing the warning given as a result. */
  /*@-globstate@*/
  return 0;
  /*@=globstate@*/
}

/* perpet.c ends here */