aboutsummaryrefslogtreecommitdiff
path: root/development/bacon/bacon.bac
blob: 416a981af0f4f01b70a34bbf06c3eb434948d7f3 (plain)
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
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
'  ____         ____
' | __ )  __ _ / ___|___  _ __
' |  _ \ / _` | |   / _ \| '_ \
' | |_) | (_| | |__| (_) | | | |   --= A BaCon BASIC-to-C converter =--
' |____/ \__,_|\____\___/|_| |_|
'
' Peter van Eerten - March 2009/April 2011. License: GPL version 3.
'
'----------------------------------------------------------------------------------------------
' CREDITS:
'   - James C. Fuller for endless testing and patiently pointing to many issues
'   - John Spikowksi for giving some hints to improve the language
'   - Vovchik for providing ideas, programs and hints
'
'----------------------------------------------------------------------------------------------
'
' Though BaCon is much more powerful than KSH or BASH, this program follows the same structure
' and approach as the existing shell script implementations where possible.
'
' The reason for this is maintainability and consistency: a bug should show up in all versions
' and should be solved in all versions.
'
'----------------------------------------------------------------------------------------------
' GLOBAL INITIALIZATIONS
'----------------------------------------------------------------------------------------------

TRAP LOCAL

' Lower bound of array starts with 1
OPTION BASE 1

' Prevent parse errors
OPTION COLLAPSE TRUE

' Version of BACON
CONST g_VERSION$ = "1.0 build 22"

' Link flags
IF INSTR(OS$, "OSF1") OR INSTR(OS$, "BSD") THEN g_LDFLAGS$ = "-lm"
ELSE g_LDFLAGS$ = "-lm -ldl"

'  Solaris
IF INSTR(OS$, "SunOS" ) THEN g_LDFLAGS$ = CONCAT$(g_LDFLAGS$, " -lnsl -lsocket")

' Global to define '$'-replacement
CONST g_STRINGSIGN$ = "__b2c__string_var"

'----------------------------------------------------------------------------------------------

FUNCTION Check_Declared(STRING filename$, STRING v$, NUMBER position)

    LOCAL txt$, needle$
    LOCAL expr
    LOCAL thefile TYPE FILE*

    needle$ = REPLACE$(v$, "*", "\\*")

    OPEN filename$ FOR READING AS thefile

    SEEK thefile OFFSET position

    WHILE NOT(ENDFILE(thefile)) DO

        READLN txt$ FROM thefile
        IF NOT(ENDFILE(thefile)) AND LEN(txt$) > 0 AND NOT(INSTR(txt$, " noparse ")) THEN
            expr = REGEX(txt$, "DIR|FILE|int|long|float|double|char|void|STRING|NUMBER|FLOATING")
	    IF ISTRUE(expr) THEN
		IF INSTR(needle$, "[") THEN
		    expr = REGEX(txt$, CONCAT$(" ", LEFT$(needle$, INSTR(needle$, "[")-1), "\\[|,", LEFT$(needle$, INSTR(needle$, "[")-1), "\\[" ))
		ELSE
		    expr = REGEX(txt$, CONCAT$(" ", needle$, ",| ", needle$, ";|\\*", needle$, " |,", needle$, ",|,", needle$, ";| ", needle$, " +="))
		END IF
		IF ISTRUE(expr) THEN BREAK
	    ENDIF
        ENDIF
    WEND

    CLOSE FILE thefile

    RETURN expr

END FUNCTION

'----------------------------------------------------------------------------------------------

FUNCTION Check_Type$(STRING filename$, STRING v$, NUMBER position)

    LOCAL txt$, needle$
    LOCAL expr
    LOCAL thefile TYPE FILE*

    needle$ = CHOP$(REPLACE$(v$, "*", "\\*"))

    OPEN filename$ FOR READING AS thefile

    SEEK thefile OFFSET position

    WHILE NOT(ENDFILE(thefile)) DO

        READLN txt$ FROM thefile
        IF NOT(ENDFILE(thefile)) AND LEN(txt$) > 0 AND NOT(INSTR(txt$, " noparse ")) THEN
            expr = REGEX(txt$, "DIR|FILE|int|long|float|double|char|void|STRING|NUMBER|FLOATING")
	    IF ISTRUE(expr) THEN
		IF INSTR(needle$, "[") THEN
		    IF INSTR(needle$, g_STRINGSIGN$) THEN
			expr = REGEX(txt$, CONCAT$(" *", LEFT$(needle$, INSTR(needle$, "[")-1), "\\["))
		    ELSE
			expr = REGEX(txt$, CONCAT$(" ", LEFT$(needle$, INSTR(needle$, "[")-1), "\\["))
		    ENDIF
		ELSE
		    expr = REGEX(txt$, CONCAT$(" ", needle$, ",| ", needle$, ";|,", needle$, ",|,", needle$, ";| ", needle$, " +="))
		END IF
		IF ISTRUE(expr) THEN BREAK
	    ENDIF
        ENDIF
    WEND

    CLOSE FILE thefile

    IF ISTRUE(expr) THEN RETURN txt$

    RETURN ""

END FUNCTION

'----------------------------------------------------------------------------------------------

FUNCTION Search(STRING file$, STRING line$, NUMBER position)

    LOCAL found
    LOCAL txt$
    LOCAL handle TYPE FILE*

    found = -1

    OPEN file$ FOR READING AS handle

    SEEK handle OFFSET position

    WHILE NOT(ENDFILE(handle)) DO
        READLN txt$ FROM handle
	IF INSTR(txt$, line$) THEN
	    found = TRUE
	    BREAK
	ENDIF
    WEND
    CLOSE FILE handle

    RETURN found

END FUNCTION

'----------------------------------------------------------------------------------------------

SUB Print_Element (STRING arg$)

    LOCAL len, check

    ' Get part just before '('
    len = INSTR(arg$, "(")-1
    IF len < 0 THEN len = LEN(arg$)

    ' Check on string by reference variable
    check = Search(g_HFILE$, CONCAT$("char *", arg$, " = NULL;"), g_HEADER_SEARCHPOS)
    IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	check = Search(g_CFILE$, CONCAT$("char *", arg$, " = NULL;"), 0)
    ENDIF

    ' Check if var is string var
    IF INSTR(MID$(arg$, 1, len), g_STRINGSIGN$) OR INSTR(MID$(arg$, 1, len), CHR$(34)) OR REGEX(MID$(arg$, 1, len), "gettext|ngettext") OR check >= 0 THEN
	WRITELN "__b2c__assign = ", arg$, "; if(__b2c__assign != NULL) fprintf(stdout, \"%s\", __b2c__assign);" TO g_CFILE
    ELSE
	WRITELN "fprintf(stdout, \"%s\", STR", g_STRINGSIGN$, "(", arg$, "));" TO g_CFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Print(STRING arg$)

    LOCAL exp$, form$
    LOCAL x, in_string, in_func, pos, escaped

    ' Check if argument
    IF ISTRUE(LEN(arg$)) THEN

	' Omit semicolon if there is one
	IF EQUAL(RIGHT$(arg$, 1), ";") THEN
	    exp$ = LEFT$(arg$, LEN(arg$) - 1)
	ELSE
	    exp$ = arg$
	END IF

	' If there is a FORMAT argument
	IF INSTR(exp$, " FORMAT ") THEN
	    form$ = MID$(exp$, INSTR(exp$, " FORMAT ") + 8)
	    WRITELN "fprintf(stdout, ", form$, ", ", LEFT$(exp$, INSTR(exp$, " FORMAT ")), ");" TO g_CFILE
	ELSE
	    ' Start miniparser
	    in_string = FALSE
	    in_func = 0
	    pos = 1
	    escaped = 0

	    FOR x = 1 TO LEN(exp$)
		IF EQUAL(MID$(exp$, x, 1), ",") THEN
		    IF ISFALSE(in_string) AND ISFALSE(in_func) THEN
			Print_Element(CHOP$(MID$(exp$, pos, x-pos)))
			pos = x + 1
			escaped = FALSE
		    END IF
		ELIF EQUAL(MID$(exp$, x, 1), "\\") THEN
		    escaped = TRUE
		ELIF EQUAL(MID$(exp$, x, 1), CHR$(34)) THEN
		    IF ISFALSE(escaped) THEN
			in_string = NOT(in_string)
		    END IF
		    escaped = FALSE
		ELIF EQUAL(MID$(exp$, x, 1), "(") THEN
		    IF ISFALSE(in_string) THEN
			INCR in_func
		    END IF
		    escaped = FALSE
		ELIF EQUAL(MID$(exp$, x, 1), ")") THEN
		    IF ISFALSE(in_string) THEN
			DECR in_func
		    END IF
		    escaped = FALSE
		ELSE
		    escaped = FALSE
		ENDIF
	    NEXT
	    Print_Element(CHOP$(MID$(exp$, pos)))

	    ' If line ends with ';' then skip newline
	    IF ISFALSE(EQUAL(RIGHT$(arg$, 1), ";")) THEN
		WRITELN "fprintf(stdout, \"\\n\");" TO g_CFILE
	    END IF
	END IF

    ELSE
	WRITELN "fprintf(stdout, \"\\n\");" TO g_CFILE
    END IF

    ' Flush print buffer
    WRITELN "fflush(stdout);" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Input(STRING arg$)

    LOCAL x, in_string, in_func, pos, check, escaped
    LOCAL type$

    ' Check if we have an argument at all
    IF ISFALSE(LEN(arg$)) THEN
	PRINT NL$, "ERROR: empty INPUT at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Start miniparser
    in_string = FALSE
    in_func = 0
    pos = 1
    escaped = 0

    FOR x = 1 TO LEN(arg$)
	IF ISTRUE(EQUAL(MID$(arg$, x, 1), ",")) THEN
	    IF ISFALSE(in_string) AND ISFALSE(in_func) THEN
		Print_Element(CHOP$(MID$(arg$, pos, x-pos)))
		pos = x+1
		escaped = FALSE
	    END IF
	ELIF EQUAL(MID$(arg$, x, 1), "\\") THEN
	    escaped = TRUE
	ELIF ISTRUE(EQUAL(MID$(arg$, x, 1), CHR$(34))) THEN
	    IF ISFALSE(escaped) THEN
		in_string = NOT(in_string)
	    END IF
	    escaped = FALSE
	ELIF ISTRUE(EQUAL(MID$(arg$, x, 1), "(")) THEN
	    IF ISFALSE(in_string) THEN
		INCR in_func
	    END IF
	    escaped = FALSE
	ELIF ISTRUE(EQUAL(MID$(arg$, x, 1), ")")) THEN
	    IF ISFALSE(in_string) THEN
		DECR in_func
	    END IF
	    escaped = FALSE
	ELSE
	    escaped = FALSE
	ENDIF
    NEXT
    arg$ = CHOP$(MID$(arg$, pos))

    ' Check type of var, string?
    IF INSTR(arg$, g_STRINGSIGN$) THEN

	IF NOT(REGEX(arg$, "\\[.*\\]")) THEN
	    ' Is variable declared already?
	    check = Search(g_HFILE$, CONCAT$("char *", arg$, " = NULL;"), g_HEADER_SEARCHPOS)
	    IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
		check = Search(g_CFILE$, CONCAT$("char *", arg$, " = NULL;"), 0)
	    ENDIF
	    IF check < 0 THEN WRITELN "char *", arg$, " = NULL;" TO g_HFILE
	END IF

	' Translate function to C function
	WRITELN "__b2c__counter = 1; do{ memset(__b2c__input__buffer, '\\0', ", g_BUFFER_SIZE, ");" TO g_CFILE
	WRITELN "__b2c__assign = fgets(__b2c__input__buffer, ", g_BUFFER_SIZE, ", stdin);" TO g_CFILE

	' Make sure internal var is copied to var of program
	WRITELN arg$, " = (char*)realloc(", arg$, ", (", g_BUFFER_SIZE, "+1)*__b2c__counter*sizeof(char));" TO g_CFILE
	WRITELN "if(__b2c__counter == 1) strncpy(", arg$, ", __b2c__input__buffer, ", g_BUFFER_SIZE, ");" TO g_CFILE
	WRITELN "else strncat(", arg$, ", __b2c__input__buffer, ", g_BUFFER_SIZE, "); __b2c__counter++;" TO g_CFILE
	WRITELN "} while (!strstr(__b2c__input__buffer, \"\\n\") && strlen(__b2c__input__buffer));" TO g_CFILE
	' Cut off last newline
	WRITELN "if (strlen(__b2c__input__buffer))", arg$, "[strlen(", arg$, ")-1] = '\\0';" TO g_CFILE
    ' Var is numeric or stringarray
    ELSE
	' Variable may not be array, these should be defined with DECLARE
	IF NOT(REGEX(arg$, "\\[.*\\]")) AND NOT(INSTR(arg$, ".")) THEN

	    ' Is variable declared already?
	    check = Check_Declared(g_HFILE$, arg$, g_HEADER_SEARCHPOS)
	    IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, arg$, 0)

	    IF ISFALSE(check) THEN WRITELN "long ", arg$, ";" TO g_HFILE
	END IF

	' Get the type
	type$ = Check_Type$(g_HFILE$, arg$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(LEN(type$)) THEN
	    type$ = Check_Type$(g_CFILE$, arg$, 0)
	END IF

	' Translate function to C function - we do not need endless buffer here because numbers never can have more than 10 digits anyway
	WRITELN "memset(__b2c__input__buffer, '\\0', ", g_BUFFER_SIZE, "); __b2c__assign = fgets(__b2c__input__buffer, ", g_BUFFER_SIZE, ", stdin);" TO g_CFILE

	' Make sure internal var is copied to var of program
	IF INSTR(type$, "double ") OR INSTR(type$, "float ") OR INSTR(type$, "FLOATING ") THEN
	    WRITELN arg$, " = atof(__b2c__input__buffer);" TO g_CFILE
	ELIF INSTR(type$, "long ") OR INSTR(type$, "NUMBER ") THEN
	    WRITELN arg$, " = atol(__b2c__input__buffer);" TO g_CFILE
	ELSE
	    WRITELN arg$, " = atoi(__b2c__input__buffer);" TO g_CFILE
	END IF
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_For(STRING arg$)

    LOCAL var$, tmp$, from$, to$, step$
    LOCAL check

    ' Get the variablename without (surrounding) spaces
    var$ = CHOP$(LEFT$(arg$, INSTR(arg$, "=") - 1))
    tmp$ = CHOP$(MID$(arg$, INSTR(arg$, "=") + 1))

    ' Do we have a STRING var?
    IF INSTR(var$, g_STRINGSIGN$) THEN
	PRINT NL$, "ERROR: variable in FOR statement at line ", g_COUNTER, " in file '", g_CURFILE$, "' cannot be string!"
	END 1
    END IF

    ' Check if TO is available
    IF NOT(INSTR(tmp$, " TO ")) THEN
	PRINT NL$, "ERROR: missing TO in FOR statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the starting and ending value
    from$ = CHOP$(LEFT$(tmp$, INSTR(tmp$, " TO ") - 1))
    to$ = CHOP$(MID$(tmp$, INSTR(tmp$, " TO ") + 3))

    ' Check if there is a STEP
    IF ISTRUE(INSTR(to$, " STEP ")) THEN
	step$ = CHOP$(MID$(to$, INSTR(to$, " STEP ") + 5))
	to$ = CHOP$(LEFT$(to$, INSTR(to$, " STEP ") - 1))
    ELSE
	step$ = "1"
    END IF

    ' Variable may not be array, these should be defined with DECLARE
    IF NOT(REGEX(var$, "\\[.*\\]")) AND ISFALSE(INSTR(var$, ".")) THEN

	' Is variable declared already?
	check = Check_Declared(g_HFILE$, var$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, var$, 0)

	IF ISFALSE(check) THEN WRITELN "long ", var$, ";" TO g_HFILE
    END IF

    ' Translate function to C function
    IF VAL(step$) < 0 THEN
	WRITELN "for(", var$," = ", from$, "; ", var$, " >= ", to$, ";", var$, " += ", step$, "){" TO g_CFILE
    ELSE
	WRITELN "for(", var$," = ", from$, "; ", var$, " <= ", to$, ";", var$, " += ", step$, "){" TO g_CFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_While (STRING arg$)

    ' Check if DO is available
    IF ISFALSE(INSTRREV(arg$, " DO")) THEN
	WRITELN "while(", Parse_Equation$(arg$), "){" TO g_CFILE
    ELSE
	WRITELN "while(", Parse_Equation$(LEFT$(arg$, INSTRREV(arg$, " DO"))), "){" TO g_CFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------
' $1: name of ASSOC variable
' $2: name of index
' $3: actual value to assign
' $4: recursion level

SUB Relate_Recurse(STRING var$, STRING str$, STRING tmp$, NUMBER lvl)

    LOCAL rel$
    LOCAL ctr

    ' Check endless recursion
    INCR lvl
    IF lvl > g_RELATE_CTR THEN
	PRINT NL$, "ERROR: Endless recursion in RELATE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Now add relation
    FOR ctr = 0 TO g_RELATE_CTR
	IF EQUAL(LEFT$(g_RELATE$[ctr], LEN(var$)), var$) THEN
	    rel$ = MID$(g_RELATE$[ctr], INSTR(g_RELATE$[ctr], " ")+1)
	    WRITELN "if(__b2c__", rel$, "_exist (", str$, " == NULL) __b2c__", rel$, "__add(", str$, ";" TO g_CFILE
	    IF INSTR(rel$, g_STRINGSIGN$) THEN
		WRITELN "__b2c__", rel$, "_exist(", str$, "->value = realloc(__b2c__", rel$, "_exist(", str$, "->value, (strlen(", tmp$, ")+1)*sizeof(char));" TO g_CFILE
		WRITELN "strcpy(__b2c__", rel$, "_exist(", str$, "->value, ", tmp$, ");" TO g_CFILE
	    ELSE
		WRITELN "__b2c__", rel$, "_exist(", str$, "->value = ", tmp$, ";" TO g_CFILE
	    END IF
	    Relate_Recurse(rel$, str$, tmp$, lvl)
	END IF
    NEXT

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Let(STRING arg$)

    LOCAL check, ctr
    LOCAL var$, tmp$, str$, lft$, rel$, ptr$

    ' Check if we have an argument at all
    IF NOT(INSTR(arg$, "=")) THEN
	PRINT NL$, "ERROR: could not parse line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename without surrounding spaces
    var$ = CHOP$(LEFT$(arg$, INSTR(arg$, "=") - 1))
    tmp$ = CHOP$(MID$(arg$, INSTR(arg$, "=") + 1))

    ' Check if var is string var, exclude RECORD elements
    IF REGEX(var$, CONCAT$(g_STRINGSIGN$, "$")) AND NOT(INSTR(var$, ".")) THEN
	' Is variable declared already?
	check = Search(g_HFILE$, CONCAT$("char *", var$, " = NULL;"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", var$, " = NULL;"), 0)
	ENDIF

	IF check < 0 AND NOT(REGEX(g_PROTOTYPE$, CONCAT$(".* ", var$, "[ ,)]+"))) THEN
	    WRITELN "char *", var$, " = NULL;" TO g_HFILE
	END IF

    ' Assume number, exclude RECORD elements
    ELIF NOT(REGEX(var$, "\\[.*\\]")) AND NOT(INSTR(var$, ".")) AND NOT(EQUAL(var$, "ERROR")) AND NOT(REGEX(var$, "\\(.*\\)")) THEN

	' Is variable declared already?
	check = Check_Declared(g_HFILE$, var$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, var$, 0)

	IF ISFALSE(check) AND NOT(REGEX(g_PROTOTYPE$, CONCAT$(".* ", var$, "[ ,)]+"))) THEN
	    IF INSTR(tmp$, ".") AND NOT(INSTR(tmp$, CHR$(34))) THEN WRITELN "double ", var$, ";" TO g_HFILE
	    ELSE WRITELN "long ", var$, ";" TO g_HFILE
	END IF
    END IF

    ' Check if there is associative array assignment
    IF REGEX(var$, "\\(.*\\)$") THEN
	lft$ = LEFT$(var$, INSTR(var$, "(") - 1)
	str$ = MID$(var$, INSTR(var$, "(") + 1)
	WRITELN "if(__b2c__", lft$, "_exist (", str$, " == NULL) __b2c__", lft$, "__add(", str$, ";" TO g_CFILE
	IF INSTR(lft$, g_STRINGSIGN$) THEN
	    WRITELN "__b2c__", lft$, "_exist(", str$, "->value = realloc(__b2c__", lft$, "_exist(", str$, "->value, (strlen(", tmp$, ")+1)*sizeof(char));" TO g_CFILE
	    WRITELN "strcpy(__b2c__", lft$, "_exist(", str$, "->value, ", tmp$, ");" TO g_CFILE
	ELSE
	    WRITELN "__b2c__", lft$, "_exist(", str$, "->value = ", tmp$, ";" TO g_CFILE
	END IF
	' Check for relations
	Relate_Recurse(lft$, str$, tmp$, -1)

    ' Do we have a STRING variable not STRING array?
    ELIF INSTR(var$, g_STRINGSIGN$) AND NOT(REGEX(var$, CONCAT$(".*\\[.*", g_STRINGSIGN$, ".*\\].*"))) THEN
	WRITELN "__b2c__assign = (char*) strdup (", tmp$, "); ", g_WITHVAR$, var$, " = (char*)realloc(", g_WITHVAR$, var$, ", (strlen(__b2c__assign)+1)*sizeof(char));" TO g_CFILE
	WRITELN "strcpy(", g_WITHVAR$, var$, ", __b2c__assign); free(__b2c__assign);" TO g_CFILE
	' Also check if string var already is used for IMPORT, if so, perform dlopen again
	ptr$ = REPLACE$(REPLACE$(var$, CHR$(34), ""), "-", "")
	ptr$ = REPLACE$(REPLACE$(REPLACE$(ptr$, ".", ""), "/", ""), "_", "")
	check = Search(g_CFILE$, CONCAT$("void* __b2c__dlopen__pointer_", ptr$, ";"), 0)
	IF check >= 0 THEN
	    WRITELN "__b2c__dlopen__pointer_", ptr$, " = dlopen(", var$, ", RTLD_LAZY);" TO g_CFILE
	END IF

    ELSE
	WRITELN g_WITHVAR$, arg$, ";" TO g_CFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Open(STRING arg$)

    LOCAL check
    LOCAL file$, tmp$, mode$, handle$

    ' Check if FOR is available
    IF NOT(INSTR(arg$, " FOR ")) THEN
	PRINT NL$, "ERROR: missing FOR in OPEN statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if AS is available
    IF NOT(INSTR(arg$, " AS ")) THEN
	PRINT NL$, "ERROR: missing AS in OPEN statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the file, mode and handle
    file$ = CHOP$(LEFT$(arg$, INSTR(arg$, " FOR ") - 1))
    tmp$ = CHOP$(MID$(arg$, INSTR(arg$, " FOR ") + 5))

    mode$ = CHOP$(LEFT$(tmp$, INSTR(tmp$, " AS ") - 1))
    handle$ = CHOP$(MID$(tmp$, INSTR(tmp$, " AS ") + 4))

    ' Check if var is string var
    IF INSTR(handle$, g_STRINGSIGN$) AND NOT(EQUAL(mode$, "MEMORY")) THEN
	PRINT NL$, "ERROR: variable for OPEN at line ", g_COUNTER, " in file '", g_CURFILE$, "' cannot be string!"
	END 1
    END IF

    ' Check if variable was declared
    IF NOT(INSTR(handle$, ".")) THEN
	check = Check_Declared(g_HFILE$, handle$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, handle$, 0)
    END IF

    ' File or dir?
    IF EQUAL(mode$, "DIRECTORY") THEN
	IF ISFALSE(check) THEN
	    WRITELN "DIR* ", handle$, ";" TO g_HFILE
	END IF
    ELIF EQUAL(mode$, "MEMORY") THEN
	IF ISFALSE(check) THEN
	    WRITELN "char* ", handle$, ";" TO g_HFILE
	END IF
	check = Check_Declared(g_HFILE$, CONCAT$("__b2c_mem_", handle$, ";"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, CONCAT$("__b2c_mem_", handle$, ";"), 0)
	IF ISFALSE(check) THEN
	    WRITELN "long __b2c_mem_", handle$, ";" TO g_HFILE
	END IF
    ELIF EQUAL(mode$, "NETWORK") OR EQUAL(mode$, "SERVER") THEN
	IF ISFALSE(check) THEN
	    WRITELN "int ", handle$, ";" TO g_HFILE
	END IF
    ELSE
	IF ISFALSE(check) THEN
	    WRITELN "FILE* ", handle$, ";" TO g_HFILE
	END IF
    END IF

    ' Convert to C syntax
    IF EQUAL(mode$, "READING") THEN
	WRITELN handle$, " = fopen(", file$, ", \"r\");" TO g_CFILE
	WRITELN "if(", handle$, " == NULL){if(!__b2c__trap){ERROR = 2; if(!__b2c__catch_set) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    ELIF EQUAL(mode$, "WRITING") THEN
	WRITELN handle$, " = fopen(", file$, ", \"w\");" TO g_CFILE
	WRITELN "if(", handle$, " == NULL){if(!__b2c__trap){ERROR = 2; if(!__b2c__catch_set) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    ELIF EQUAL(mode$, "APPENDING") THEN
	WRITELN handle$, " = fopen(", file$, ", \"a\");" TO g_CFILE
	WRITELN "if(", handle$, " == NULL){if(!__b2c__trap){ERROR = 2; if(!__b2c__catch_set) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    ELIF EQUAL(mode$, "READWRITE") THEN
	WRITELN handle$, " = fopen(", file$, ", \"r+\");" TO g_CFILE
	WRITELN "if(", handle$, " == NULL){if(!__b2c__trap){ERROR = 2; if(!__b2c__catch_set) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    ELIF EQUAL(mode$, "DIRECTORY") THEN
	WRITELN handle$, " = opendir(", file$, ");" TO g_CFILE
	WRITELN "if(", handle$, " == NULL){if(!__b2c__trap){ERROR = 2; if(!__b2c__catch_set) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    ELIF EQUAL(mode$, "MEMORY") THEN
	WRITELN handle$, " = (char*)", file$, "; __b2c_mem_", handle$, " = ", file$, ";" TO g_CFILE
	WRITELN "if(!__b2c__trap){__b2c__memory__check(", handle$, "); if(ERROR) {if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    ELIF EQUAL(mode$, "NETWORK") THEN
	' Network code
	WRITELN "if (strstr(", file$, ", \":\") == NULL){ERROR = 10; fprintf(stderr, \"ERROR: %s: '%s'\\n\", ERR", g_STRINGSIGN$, "(ERROR), ", file$, "); exit(ERROR);}" TO g_CFILE
	WRITELN "strncpy(__b2c__data_client, ", file$, ", ", g_BUFFER_SIZE, ");__b2c__host = strtok(__b2c__data_client, \":\"); __b2c__port = strtok(NULL, \":\");__b2c__he = gethostbyname(__b2c__host);" TO g_CFILE
	WRITELN "if (__b2c__he == NULL || __b2c__he->h_addr == NULL) {if(!__b2c__trap){ERROR = 11;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
	WRITELN handle$, " = socket(PF_INET, SOCK_STREAM, 0);" TO g_CFILE
	WRITELN "if (", handle$, " == -1) {if(!__b2c__trap){ERROR = 12;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
	WRITELN "__b2c__to.tv_sec = ", g_OPTION_SOCKET, "; __b2c__to.tv_usec = 0; setsockopt(", handle$, ", SOL_SOCKET, SO_SNDTIMEO, &__b2c__to, sizeof(struct timeval));" TO g_CFILE
	WRITELN "setsockopt(", handle$, ", SOL_SOCKET, SO_REUSEADDR, &__b2c__yes, sizeof(int)); __b2c__addr.sin_family = AF_INET; __b2c__addr.sin_port = htons((long)atol(__b2c__port));" TO g_CFILE
	WRITELN "__b2c__addr.sin_addr = *((struct in_addr *)__b2c__he->h_addr); memset(&(__b2c__addr.sin_zero), '\\0', sizeof(__b2c__addr.sin_zero));" TO g_CFILE
	WRITELN "__b2c__result = connect(", handle$, ", (struct sockaddr *)&__b2c__addr, sizeof(struct sockaddr));" TO g_CFILE
	WRITELN "if(__b2c__result == -1) {if(!__b2c__trap){ERROR = 13;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    ELIF EQUAL(mode$, "SERVER") THEN
	' Network code
	WRITELN "if (strstr(", file$, ", \":\") == NULL){ERROR = 10; fprintf(stderr, \"ERROR: %s: '%s'\\n\", ERR", g_STRINGSIGN$, "(ERROR), ", file$, "); exit(ERROR);}" TO g_CFILE
	WRITELN "if(strcmp(__b2c__data_server, ", file$, ")) {strncpy(__b2c__data_server, ", file$, ", ", g_BUFFER_SIZE, ");__b2c__host = strtok(__b2c__data_server, \":\"); __b2c__port = strtok(NULL, \":\");__b2c__he = gethostbyname(__b2c__host);" TO g_CFILE
	WRITELN "if (__b2c__he == NULL || __b2c__he->h_addr == NULL) {if(!__b2c__trap){ERROR = 11;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
	WRITELN "__b2c__handle = socket(AF_INET, SOCK_STREAM, 0);" TO g_CFILE
	WRITELN "if (__b2c__handle == -1) {if(!__b2c__trap){ERROR = 12;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
	WRITELN "__b2c__to.tv_sec = ", g_OPTION_SOCKET, "; __b2c__to.tv_usec = 0; setsockopt(__b2c__handle, SOL_SOCKET, SO_SNDTIMEO, &__b2c__to, sizeof(struct timeval));" TO g_CFILE
	WRITELN "setsockopt(__b2c__handle, SOL_SOCKET, SO_REUSEADDR, &__b2c__yes, sizeof(int));__b2c__addr.sin_family = AF_INET; __b2c__addr.sin_port = htons((long)atol(__b2c__port));" TO g_CFILE
	WRITELN "__b2c__addr.sin_addr = *((struct in_addr *)__b2c__he->h_addr);memset(&(__b2c__addr.sin_zero), '\\0', sizeof(__b2c__addr.sin_zero));" TO g_CFILE
	WRITELN "__b2c__result = bind(__b2c__handle, (struct sockaddr *)&__b2c__addr, sizeof(struct sockaddr));" TO g_CFILE
	WRITELN "if(__b2c__result == -1){if(!__b2c__trap){ERROR = 17;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
	WRITELN "__b2c__result = listen(__b2c__handle, ", g_MAX_BACKLOG, ");" TO g_CFILE
	WRITELN "if(__b2c__result == -1){if(!__b2c__trap){ERROR = 18;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
	WRITELN "strncpy(__b2c__data_server, ", file$, ", ", g_BUFFER_SIZE, "); /* Restore data because of strtok */} __b2c__result = accept(__b2c__handle, NULL, 0);" TO g_CFILE
	WRITELN "if(__b2c__result == -1){if(!__b2c__trap){ERROR = 19;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
	WRITELN handle$, "= __b2c__result;" TO g_CFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Seek(STRING arg$)

    LOCAL dim

    ' Check if we have an argument at all
    IF ISFALSE(LEN(arg$)) THEN
	PRINT NL$, "ERROR: empty SEEK at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if OFFSET is available
    IF NOT(INSTR(arg$, " OFFSET ")) THEN
	PRINT NL$, "ERROR: missing OFFSET in SEEK statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename, filedescriptor
    SPLIT arg$ BY " " TO element$ SIZE dim

    ' Convert to C function
    IF dim EQ 3 THEN
	WRITELN "fseek(", element$[1], ", ", element$[3], ", SEEK_SET);" TO g_CFILE
    ELIF dim EQ 5 THEN
	IF EQUAL(element$[5], "START") THEN
	    WRITELN "fseek(", element$[1], ", ", element$[3], ", SEEK_SET);" TO g_CFILE
	ELIF EQUAL(element$[4], "CURRENT") THEN
	    WRITELN "fseek(", element$[1], ", ", element$[3], ", SEEK_CUR);" TO g_CFILE
	ELIF EQUAL(element$[4], "END") THEN
	    WRITELN "fseek(", element$[1], ", ", element$[3], ", SEEK_END);" TO g_CFILE
	END IF
    ELSE
	PRINT NL$, "ERROR: erroneous SEEK statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Copy(STRING arg$)

    LOCAL from$, to$

    ' Check if we have an argument at all
    IF ISFALSE(LEN(arg$)) THEN
	PRINT NL$, "ERROR: empty COPY at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if TO is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: Missing TO in COPY statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the filename and copyname
    from$ = CHOP$(MID$(arg$, 1, INSTR(arg$, " TO ") - 1))
    to$ = CHOP$(MID$(arg$, INSTR(arg$, " TO ") + 4))

    ' Translate to C function
    WRITELN "__b2c__inFile = fopen(", from$, ", \"r\"); __b2c__outFile = fopen(", to$, ", \"w\"); __b2c__Byte = 0;" TO g_CFILE
    WRITELN "if (__b2c__inFile != NULL && __b2c__outFile != NULL){while(__b2c__Byte!=EOF){" TO g_CFILE
    WRITELN "__b2c__Byte=fgetc(__b2c__inFile); if(__b2c__Byte!=EOF){" TO g_CFILE
    WRITELN "fputc(__b2c__Byte,__b2c__outFile); }}" TO g_CFILE
    WRITELN "fclose(__b2c__inFile); fclose(__b2c__outFile);}" TO g_CFILE
    WRITELN "else { if(!__b2c__trap){ERROR = 2; if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Rename(STRING arg$)

    LOCAL from$, to$

    ' Check if we have an argument at all
    IF ISFALSE(LEN(arg$)) THEN
	PRINT NL$, "ERROR: empty RENAME at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if TO is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: Missing TO in RENAME statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the filename and copyname
    from$ = CHOP$(MID$(arg$, 1, INSTR(arg$, " TO ") - 1))
    to$ = CHOP$(MID$(arg$, INSTR(arg$, " TO ") + 4))

    ' Translate to C function
    WRITELN "if(rename(", from$, ", ", to$, ") < 0) {if(!__b2c__trap){ERROR = 9; if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Readln(STRING arg$)

    LOCAL dim, check

    ' Check if FROM is available
    IF NOT(INSTR(arg$, " FROM ")) THEN
	PRINT NL$, "ERROR: missing FROM in READLN statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename, filedescriptor
    SPLIT arg$ BY " " TO element$ SIZE dim

    ' Check if var is string var
    IF NOT(INSTR(element$[1], g_STRINGSIGN$)) THEN
	PRINT NL$, "ERROR: variable for READLN at line ", g_COUNTER, " in file '", g_CURFILE$, "' must be string!"
	END 1
    END IF

    ' Check if var is string var, exclude RECORD elements
    IF NOT(REGEX(element$[1], "\\[.*\\]")) THEN
	' Is variable declared already?
	check = Search(g_HFILE$, CONCAT$("char *", element$[1], " = NULL;"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", element$[1], " = NULL;"), 0)
	ENDIF

	IF check < 0 THEN WRITELN "char *", element$[1], " = NULL;" TO g_HFILE
    END IF

    ' Translate function to C function
    WRITELN "__b2c__counter = 1; do{ memset(__b2c__input__buffer, '\\0', ", g_BUFFER_SIZE, ");" TO g_CFILE
    WRITELN "__b2c__assign = fgets(__b2c__input__buffer, ", g_BUFFER_SIZE, ", ", element$[3], ");" TO g_CFILE

    ' Make sure internal var is copied to var of program
    WRITELN element$[1], " = (char*)realloc(", element$[1], ", (", g_BUFFER_SIZE, "+1)*__b2c__counter*sizeof(char));" TO g_CFILE
    WRITELN "if(__b2c__counter == 1) strncpy(", element$[1], ", __b2c__input__buffer, ", g_BUFFER_SIZE, ");" TO g_CFILE
    WRITELN "else strncat(", element$[1], ", __b2c__input__buffer, ", g_BUFFER_SIZE, "); __b2c__counter++;" TO g_CFILE
    WRITELN "} while (!strstr(__b2c__input__buffer, \"\\n\") && strlen(__b2c__input__buffer));" TO g_CFILE
    ' Cut off last newline
    WRITELN "if (strlen(__b2c__input__buffer))", element$[1], "[strlen(", element$[1], ")-1]='\\0';" TO g_CFILE
    ' Cut off CR if available
    WRITELN "if(strlen(", element$[1], ")>0 && ", element$[1], "[strlen(", element$[1], ")-1]=='\\r') ", element$[1], "[strlen(", element$[1], ")-1]='\\0';" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Writeln(STRING arg$)

    LOCAL in_string, in_func, pos, escaped, x, len
    LOCAL var$, to$

    ' Check if FROM is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: missing TO in WRITELN statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename, filedescriptor
    var$ = LEFT$(arg$, INSTRREV(arg$, " TO "))
    to$ = CHOP$(MID$(arg$, INSTRREV(arg$, " TO ") + 4))

    ' Start miniparser
    in_string = FALSE
    in_func = 0
    pos = 1
    escaped = 0

    FOR x = 1 TO LEN(var$)
	IF ISTRUE(EQUAL(MID$(var$, x, 1), ",")) THEN
	    IF ISFALSE(in_string) AND ISFALSE(in_func) THEN
		len = INSTR(MID$(var$, pos, x-pos), "(")-1
		IF len < 0 THEN len = x-pos
		IF INSTR(MID$(var$, pos, len), g_STRINGSIGN$) OR INSTR(MID$(var$, pos, len), CHR$(34)) THEN
		    WRITELN "fprintf(", to$, ", \"%s\", ", MID$(var$, pos, x-pos), ");" TO g_CFILE
		ELSE
		    WRITELN "fprintf(", to$, ", \"%s\", STR", g_STRINGSIGN$, "(", MID$(var$, pos, x-pos), "));" TO g_CFILE
		END IF
		pos = x+1
		escaped = FALSE
	    END IF
	ELIF EQUAL(MID$(var$, x, 1), "\\") THEN
	    escaped = TRUE
	ELIF ISTRUE(EQUAL(MID$(var$, x, 1), CHR$(34))) THEN
	    IF ISFALSE(escaped) THEN
		in_string = NOT(in_string)
	    END IF
	    escaped = FALSE
	ELIF ISTRUE(EQUAL(MID$(var$, x, 1), "(")) THEN
	    IF ISFALSE(in_string) THEN
		INCR in_func
	    END IF
	    escaped = FALSE
	ELIF ISTRUE(EQUAL(MID$(var$, x, 1), ")")) THEN
	    IF ISFALSE(in_string) THEN
		DECR in_func
	    END IF
	    escaped = FALSE
	ELSE
	    escaped = FALSE
	ENDIF
    NEXT
    var$ = MID$(var$, pos)

    ' Write last element to file
    len = INSTR(var$, "(")-1
    IF len < 0 THEN len = LEN(var$)
    IF INSTR(LEFT$(var$, len), g_STRINGSIGN$) OR INSTR(LEFT$(var$, len), CHR$(34)) THEN
	WRITELN "fprintf(", to$, ", \"%s\\n\", ", var$, ");" TO g_CFILE
    ELSE
	WRITELN "fprintf(", to$, ", \"%s\\n\", STR", g_STRINGSIGN$, "(", var$, "));" TO g_CFILE
    END IF
    WRITELN "fflush(", to$, ");" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Getbyte(STRING arg$)

    LOCAL dim, check
    LOCAL var$, to$, size$

    ' Check if FROM is available
    IF NOT(INSTR(arg$, " FROM ")) THEN
	PRINT NL$, "ERROR: missing FROM in GETBYTE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename, filedescriptor
    var$ = CHOP$(LEFT$(arg$, INSTRREV(arg$, " FROM ")))
    to$ = CHOP$(MID$(arg$, INSTRREV(arg$, " FROM ") + 6))

    ' Check if SIZE is available
    IF INSTR(to$, " SIZE ") THEN
	size$ = MID$(to$, INSTR(to$, " SIZE ") + 6)
	to$ = MID$(to$, 1, INSTR(to$, " SIZE "))
    ELSE
	size$ = "1"
    END IF

    ' Declare variable if not done yet, assuming long
    IF NOT(INSTR(var$, ".")) THEN
	check = Check_Declared(g_HFILE$, var$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, var$, 0)

	IF ISFALSE(check) THEN WRITELN "long ", var$, ";" TO g_HFILE
    END IF

    ' Translate function to C function
    WRITELN "if(!__b2c__trap){__b2c__memory__check((char *)", var$, "); if(ERROR) {if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    WRITELN "__b2c__counter = fread((void*)", var$, ", sizeof(", g_OPTION_MEMTYPE$, "), ", size$, ", ", to$, ");" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Putbyte(STRING arg$)

    LOCAL dim
    LOCAL var$, to$, size$

    ' Check if FROM is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: missing TO in PUTBYTE statement at line at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename, filedescriptor
    var$ = LEFT$(arg$, INSTRREV(arg$, " TO "))
    to$ = CHOP$(MID$(arg$, INSTRREV(arg$, " TO ") + 4))

    ' Check if SIZE is available
    IF INSTR(to$, " SIZE ") THEN
	size$ = MID$(to$, INSTR(to$, " SIZE ") + 6)
	to$ = MID$(to$, 1, INSTR(to$, " SIZE "))
    ELSE
	size$ = "1"
    END IF

    ' Translate function to C function
    WRITELN "if(!__b2c__trap){__b2c__memory__check((char *)", var$, "); if(ERROR){if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    WRITELN "__b2c__counter = fwrite((void*)", var$, ", sizeof(", g_OPTION_MEMTYPE$, "), ", size$, ", ", to$, ");" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Getfile(STRING arg$)

    LOCAL dim, check

    ' Check if FROM is available
    IF NOT(INSTR(arg$, " FROM ")) THEN
	PRINT NL$, "ERROR: missing FROM in GETFILE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename, filedescriptor
    SPLIT arg$ BY " " TO element$ SIZE dim

    ' Translate function to C function
    WRITELN "__b2c__dir = readdir(", element$[3], ");" TO g_CFILE

    ' Check if variable is declared
    IF NOT(INSTR(element$[1], "[")) AND NOT(INSTR(element$[1], "]")) THEN
	check = Search(g_HFILE$, CONCAT$("char *", element$[1], " = NULL;"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", element$[1], " = NULL;"), 0)
	ENDIF
    END IF

    IF check < 0 AND NOT(REGEX(element$[1], "\\[.*\\]")) AND NOT(INSTR(element$[1], ".")) THEN WRITELN "char *", element$[1], " = NULL;" TO g_HFILE

    ' Always realloc VAR to correct size, maybe it was resized somewhere else
    WRITELN "if(__b2c__dir != NULL) {", element$[1], " = realloc(", element$[1], ", (strlen(__b2c__dir->d_name)+1)*sizeof(char));" TO g_CFILE
    ' Make sure internal var is copied to var of program
    WRITELN "strcpy(", element$[1], ", __b2c__dir->d_name); ", element$[1], "[strlen(__b2c__dir->d_name)] = '\\0';}" TO g_CFILE
    WRITELN "else {", element$[1], " = realloc(", element$[1], ", sizeof(char)); ", element$[1], "[0] = '\\0';}" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Receive(STRING arg$)

    LOCAL dim, check
    LOCAL size$, chunk$

    ' Check if FROM is available
    IF NOT(INSTR(arg$, " FROM ")) THEN
	PRINT NL$, "ERROR: Missing FROM in RECEIVE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get filedescriptor
    SPLIT CHOP$(arg$) BY " " TO element$ SIZE dim

    ' Check for optional chunksize
    SELECT dim
	CASE 5
	    chunk$ = element$[5]
	    size$ = ""
	CASE 7
	    chunk$ = element$[5]
	    size$ = element$[7]
	DEFAULT
	    chunk$ = STR$(g_BUFFER_SIZE)
	    size$ = ""
    END SELECT

    ' Variable may not be array, these should be defined with DECLARE
    IF LEN(size$) > 0 AND NOT(REGEX(size$, "\\[.*\\]")) AND NOT(INSTR(size$, ".")) THEN
	check = Check_Declared(g_HFILE$, size$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, size$, 0)

	IF ISFALSE(check) THEN WRITELN "long ", size$, ";" TO g_HFILE
    END IF

    ' Check if variable is declared
    IF INSTR(element$[1], g_STRINGSIGN$) THEN
	check = Search(g_HFILE$, CONCAT$("char *", element$[1], " = NULL;"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", element$[1], " = NULL;"), 0)
	ENDIF

	IF check < 0 THEN WRITELN "char *", element$[1], " = NULL;" TO g_HFILE
	WRITELN element$[1], " = (char*)realloc(", element$[1], ", (", chunk$, "+1)*sizeof(char)); memset(", element$[1], ", '\\0', sizeof(char)*(", chunk$, "+1));" TO g_CFILE
    END IF

    ' Translate function to C function
    IF LEN(size$) EQ 0 THEN
	WRITELN "if(recv(", element$[3], ", (void*)", element$[1], ", ", chunk$, ", 0) < 0) {if(!__b2c__trap){ERROR = 14;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    ELSE
	WRITELN "if((", size$, " = recv(", element$[3], ", (void*)", element$[1], ", ", chunk$,", 0)) < 0) {if(!__b2c__trap){ERROR = 14;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Send(STRING arg$)

    LOCAL to$, var$, chunk$

    ' Check if TO is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: Missing TO in SEND statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename without surrounding spaces
    var$ = LEFT$(arg$, INSTR(arg$, " TO "))

    ' Get filedescriptor
    to$ = CHOP$(MID$(arg$, INSTR(arg$, " TO ") + 4))

    IF INSTR(to$, " CHUNK ") THEN
	chunk$ = MID$(to$, INSTR(to$, " CHUNK ") + 7)
	to$ = MID$(to$, 1, INSTR(to$, " CHUNK ") - 1)
    ELSE
	chunk$ = CONCAT$("strlen(", var$, ")")
    END IF

    ' Translate function to C function
    WRITELN "if(send(", to$, ", (void*)", var$, ", ", chunk$, ", 0) < 0) {if(!__b2c__trap){ERROR = 15; if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Getline(STRING arg$)

    LOCAL dim, check

    ' Check if FROM is available
    IF NOT(INSTR(arg$, " FROM ")) THEN
	PRINT NL$, "ERROR: missing FROM in GETLINE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename, filedescriptor
    SPLIT arg$ BY " " TO element$ SIZE dim

    ' Check if var is string var
    IF NOT(INSTR(element$[1], g_STRINGSIGN$)) THEN
	PRINT NL$, "ERROR: variable for GETLINE at line $g_COUNTER in file ", g_COUNTER, " in file '", g_CURFILE$, "' must be string!"
	END 1
    END IF

    ' Check if variable is declared
    IF NOT(INSTR(element$[1], "[")) AND NOT(INSTR(element$[1], "]")) THEN
	' Is variable declared already?
	check = Search(g_HFILE$, CONCAT$("char *", element$[1], " = NULL;"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", element$[1], " = NULL;"), 0)
	ENDIF

	IF check < 0 THEN WRITELN "char *", element$[1], " = NULL;" TO g_HFILE
    END IF

    ' Translate function to C function
    WRITELN "if (", element$[3], " == NULL ||", CONCAT$("*", element$[3]) , " == '\\0') {", element$[1], " = (char*)realloc(", element$[1], ", 2*sizeof(char)); strcpy(", element$[1], ", \"\");}" TO g_CFILE
    WRITELN "else { __b2c__assign = ", element$[3], "; while(*", element$[3], " != '\\0' && *", element$[3], " != '\\n') ", element$[3], "++;" TO g_CFILE

    ' Make sure internal var is copied to var of program
    WRITELN element$[1], " = (char*)realloc(", element$[1], ", (", element$[3], "-__b2c__assign+1)*sizeof(char));" TO g_CFILE
    WRITELN "strncpy(", element$[1], ", __b2c__assign, ", element$[3], "-__b2c__assign);" TO g_CFILE

    ' Make sure to end the string
    WRITELN element$[1], "[(", element$[3], "-__b2c__assign)] = '\\0'; ", element$[3], "++;}" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Putline(STRING arg$)

    LOCAL in_string, in_func, pos, escaped, x, len
    LOCAL var$, to$

    ' Check if TO is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: missing TO in PUTLINE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the variablename, filedescriptor
    var$ = CHOP$(LEFT$(arg$, INSTR(arg$, " TO ")))
    to$ = CHOP$(MID$(arg$, INSTR(arg$, " TO ") + 4))

    ' Start miniparser
    in_string = FALSE
    in_func = 0
    pos = 1
    escaped = 0

    FOR x = 1 TO LEN(var$)
	IF ISTRUE(EQUAL(MID$(var$, x, 1), ",")) THEN
	    IF ISFALSE(in_string) AND ISFALSE(in_func) THEN
		len = INSTR(MID$(var$, pos, x-pos), "(")-1
		IF len < 0 THEN len = x-pos
		IF INSTR(MID$(var$, pos, len), g_STRINGSIGN$) OR INSTR(MID$(var$, pos, len), CHR$(34)) THEN
		    WRITELN "strcat(", to$, ", ", CHOP$(MID$(var$, pos, x-pos)), ");", to$, "+=strlen(", CHOP$(MID$(var$, pos, x-pos)), ");" TO g_CFILE
		ELSE
		    WRITELN "strcat(", to$, ", STR", g_STRINGSIGN$, "(", CHOP$(MID$(var$, pos, x-pos)), "));", to$, "+=strlen(STR", g_STRINGSIGN$, "(", CHOP$(MID$(var$, pos, x-pos)), "));" TO g_CFILE
		END IF
		pos = x+1
		escaped = FALSE
	    END IF
	ELIF EQUAL(MID$(var$, x, 1), "\\") THEN
	    escaped = TRUE
	ELIF ISTRUE(EQUAL(MID$(var$, x, 1), CHR$(34))) THEN
	    IF ISFALSE(escaped) THEN
		in_string = NOT(in_string)
	    END IF
	    escaped = FALSE
	ELIF ISTRUE(EQUAL(MID$(var$, x, 1), "(")) THEN
	    IF ISFALSE(in_string) THEN
		INCR in_func
	    END IF
	    escaped = FALSE
	ELIF ISTRUE(EQUAL(MID$(var$, x, 1), ")")) THEN
	    IF ISFALSE(in_string) THEN
		DECR in_func
	    END IF
	    escaped = FALSE
	ELSE
	    escaped = FALSE
	ENDIF
    NEXT
    var$ = MID$(var$, pos)

    ' Check if var is string var
    len = INSTR(MID$(var$, pos, x-pos), "(")-1
    IF len < 0 THEN len = x-pos
    IF INSTR(LEFT$(var$, len), g_STRINGSIGN$) OR INSTR(LEFT$(var$, len), CHR$(34)) THEN
	WRITELN "strcat(", to$, ", ", var$, "); strcat(", to$, ", \"\\n\"); ", to$, "+=strlen(", var$, ")+1;" TO g_CFILE
    ELSE
	WRITELN "strcat(", to$, ", STR", g_STRINGSIGN$, "(", var$, ")); strcat(", to$, ", \"\\n\"); ", to$, "+=strlen(STR", g_STRINGSIGN$, "(", var$, "))+1;" TO g_CFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_SubFunc(STRING arg$)

    LOCAL x, dim, check
    LOCAL arg_s$, dim$, arr$, size$

    ' Check argument
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty SUB/FUNCTION at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if we are in a sub already
    IF LEN(g_FUNCNAME$) > 0 THEN
	PRINT NL$, "ERROR: cannot define a SUB/FUNCTION within a SUB/FUNCTION at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the funcname
    IF INSTR(arg$, "(") THEN
	g_ORIGFUNCNAME$ = CHOP$(LEFT$(arg$, INSTR(arg$, "(")))
	g_PROTOTYPE$ = CHOP$(LEFT$(arg$, INSTR(arg$, "(")))
    ELSE
	g_ORIGFUNCNAME$ = CHOP$(CONCAT$(arg$, "("))
	g_PROTOTYPE$ = CHOP$(CONCAT$(arg$, "("))
    END IF

    ' Start miniparser to duplicate string arguments
    arg_s$ = CHOP$(MID$(arg$, INSTR(arg$, "(") + 1))

    SPLIT arg_s$ BY "," TO element$ SIZE dim

    x = 1
    WHILE dim > 1 DO
	IF INSTR(element$[x], "STRING ") OR INSTR(element$[x], "char* ") THEN
	    element$[x] = CHOP$(element$[x])
            arr$ = MID$(element$[x], INSTR(element$[x], " ")+1, INSTR(element$[x], "[") - INSTR(element$[x], " ")-1)
            dim$ = MID$(element$[x], INSTR(element$[x], "[")+1, INSTR(element$[x], "]") - INSTR(element$[x], "[")-1)
            IF NOT(INSTR(element$[x], g_STRINGSIGN$)) AND REGEX(element$[x], ".*\\[.*\\].*") THEN
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c_", arr$, "[", dim$, "+", STR$(g_OPTION_BASE),"],")
	        g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, " char** ", arr$, " = __b2c_", arr$, ";")
		g_PROTOTYPE$ = CONCAT$(g_PROTOTYPE$, " ", element$[x], ",")
            ELIF NOT(INSTR(element$[x], g_STRINGSIGN$)) THEN
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ",")
		g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "char *", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), " = __b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ";")
		g_PROTOTYPE$ = CONCAT$(g_PROTOTYPE$, " ", element$[x], ",")
	    ELIF REGEX(element$[x], ".*\\[.*\\].*") THEN
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c_", arr$, "[", dim$, "+", STR$(g_OPTION_BASE),"],")
		IF LEN(dim$) < 1 THEN
		    PRINT NL$, "ERROR: cannot pass string array without dimension at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		    END 1
		END IF
                g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "char *", arr$, "[", dim$, "+", STR$(g_OPTION_BASE),"] = { NULL };")
                g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "for(__b2c__ctr=0; __b2c__ctr<", dim$, "+", STR$(g_OPTION_BASE), "; __b2c__ctr++){if(__b2c_", arr$, "[__b2c__ctr]!=NULL) ", arr$, "[__b2c__ctr] = strdup(__b2c_", arr$, "[__b2c__ctr]);}")
	        g_STRINGARRAYS$ = CONCAT$(g_STRINGARRAYS$, "for(__b2c__ctr=0; __b2c__ctr<", dim$, "+", STR$(g_OPTION_BASE), "; __b2c__ctr++)if(", arr$, "[__b2c__ctr]!=NULL){free(", arr$, "[__b2c__ctr]);}")
		g_PROTOTYPE$=CONCAT$(g_PROTOTYPE$, "char *__b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ",")
	    ELSE
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ",")
		g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "char *", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), " = strdup(__b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ");")
		g_LOCALSTRINGS$ = CONCAT$(g_LOCALSTRINGS$, " ", CHOP$(MID$(element$[x], INSTR(element$[x], " "))))
		g_PROTOTYPE$ = CONCAT$(g_PROTOTYPE$, " ", element$[x], ",")
	    END IF
	ELSE
	    element$[x] = CHOP$(element$[x])
	    IF REGEX(element$[x], ".*\\[.*\\].*\\].*") THEN
		PRINT NL$, "ERROR: cannot pass multidimensional numeric array at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		END 1
	    ELIF REGEX(element$[x], ".*\\[\\].*") THEN
		g_ORIGFUNCNAME$ = CHOP$(CONCAT$(g_ORIGFUNCNAME$, " ", element$[x], ","))
	    ELIF REGEX(element$[x], ".*\\[.*\\].*") THEN
		dim$ = MID$(element$[x], INSTR(element$[x], "[")+1, INSTR(element$[x], "]") - INSTR(element$[x], "[")-1)
		IF LEN(dim$) < 1 THEN
		    PRINT NL$, "ERROR: cannot pass numeric array without dimension at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		    END 1
		END IF
		arr$ = MID$(element$[x], INSTR(element$[x], " ")+1, INSTR(element$[x], "[") - INSTR(element$[x], " ") - 1)
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, MID$(element$[x], 1, INSTR(element$[x], " "))," __b2c_", arr$, "[", dim$, "+", STR$(g_OPTION_BASE),"],")
                g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, MID$(element$[x], 1, INSTR(element$[x], " ")), " ", arr$, "[", dim$, "+", STR$(g_OPTION_BASE), "] = { 0 };")
                g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "for(__b2c__ctr=0; __b2c__ctr<", dim$, "+", STR$(g_OPTION_BASE), "; __b2c__ctr++){", arr$, "[__b2c__ctr] = __b2c_", arr$, "[__b2c__ctr];}")
	    ELIF INSTR(element$[x], "VAR ") THEN
	        PRINT NL$, "ERROR: variable argument list cannot be followed by other arguments at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		END 1
	    ELSE
		g_ORIGFUNCNAME$ = CHOP$(CONCAT$(g_ORIGFUNCNAME$, " ", element$[x], ","))
	    END IF
	    g_PROTOTYPE$ = CONCAT$(g_PROTOTYPE$, " ", CHOP$(element$[x]), ",")
	END IF
	INCR x
	DECR dim
    WEND

    ' Last token in the sequence of arguments
    IF ISTRUE(dim) THEN
	element$[x] = CHOP$(LEFT$(element$[x], INSTR(element$[x], ")") - 1))
	IF INSTR(element$[x], "STRING ") OR INSTR(element$[x], "char* ") THEN
	    arr$ = MID$(element$[x], INSTR(element$[x], " ")+1, INSTR(element$[x], "[") - INSTR(element$[x], " ")-1)
	    dim$ = MID$(element$[x], INSTR(element$[x], "[")+1, INSTR(element$[x], "]") - INSTR(element$[x], "[")-1)
            IF NOT(INSTR(element$[x], g_STRINGSIGN$)) AND REGEX(element$[x], ".*\\[.*\\].*") THEN
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c_", arr$, "[", dim$, "+", STR$(g_OPTION_BASE),"])")
	        g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, " char** ", arr$, " = __b2c_", arr$, ";")
		g_PROTOTYPE$ = CONCAT$(g_PROTOTYPE$, " ", element$[x], ")")
            ELIF NOT(INSTR(element$[x], g_STRINGSIGN$)) THEN
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ")")
		g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "char *", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), " = __b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ";")
		g_PROTOTYPE$ = CONCAT$(g_PROTOTYPE$, " ", element$[x], ")")
	    ELIF REGEX(element$[x], ".*\\[.*\\].*") THEN
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c_", arr$, "[", dim$, "+", STR$(g_OPTION_BASE),"])")
		IF LEN(dim$) < 1 THEN
		    PRINT NL$, "ERROR: cannot pass string array without dimension at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		    END 1
		END IF
                g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "char *", arr$, "[", dim$, "+", STR$(g_OPTION_BASE),"] = { NULL };")
                g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "for(__b2c__ctr=0; __b2c__ctr<", dim$, "+", STR$(g_OPTION_BASE), "; __b2c__ctr++){if(__b2c_", arr$, "[__b2c__ctr]!=NULL) ", arr$, "[__b2c__ctr] = strdup(__b2c_", arr$, "[__b2c__ctr]);}")
	        g_STRINGARRAYS$ = CONCAT$(g_STRINGARRAYS$, "for(__b2c__ctr=0; __b2c__ctr<", dim$, "+", STR$(g_OPTION_BASE), "; __b2c__ctr++)if(", arr$, "[__b2c__ctr]!=NULL){free(", arr$, "[__b2c__ctr]);}")
		g_PROTOTYPE$=CONCAT$(g_PROTOTYPE$, "char *__b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ")")
	    ELSE
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ")")
		g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "char *", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), " = strdup(__b2c_", CHOP$(MID$(element$[x], INSTR(element$[x], " "))), ");")
		g_LOCALSTRINGS$ = CONCAT$(g_LOCALSTRINGS$, " ", CHOP$(MID$(element$[x], INSTR(element$[x], " "))))
		g_PROTOTYPE$ = CONCAT$(g_PROTOTYPE$, " ", element$[x], ")")
	    END IF
	ELSE
	    IF INSTR(g_ORIGFUNCNAME$, element$[x]) OR LEN(element$[x]) EQ 0 THEN element$[x] = "void "
	    IF REGEX(element$[x], ".*\\[.*\\].*\\].*") THEN
		PRINT NL$, "ERROR: cannot pass multidimensional numeric array at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		END 1
	    ELIF REGEX(element$[x], ".*\\[\\].*") THEN
		g_ORIGFUNCNAME$ = CHOP$(CONCAT$(g_ORIGFUNCNAME$, " ", element$[x], ")"))
	    ELIF REGEX(element$[x], ".*\\[.*\\].*") THEN
		dim$ = MID$(element$[x], INSTR(element$[x], "[")+1, INSTR(element$[x], "]") - INSTR(element$[x], "[")-1)
		IF LEN(dim$) < 1 THEN
		    PRINT NL$, "ERROR: cannot pass numeric array without dimension at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		    END 1
		END IF
		arr$ = MID$(element$[x], INSTR(element$[x], " ")+1, INSTR(element$[x], "[") - INSTR(element$[x], " ") - 1)
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, MID$(element$[x], 1, INSTR(element$[x], " "))," __b2c_", arr$, "[", dim$, "+", STR$(g_OPTION_BASE),"])")
                g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, MID$(element$[x], 1, INSTR(element$[x], " ")), " ", arr$, "[", dim$, "+", STR$(g_OPTION_BASE), "] = { 0 };")
                g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "for(__b2c__ctr=0; __b2c__ctr<", dim$, "+", STR$(g_OPTION_BASE), "; __b2c__ctr++){", arr$, "[__b2c__ctr] = __b2c_", arr$, "[__b2c__ctr];}")
	    ELIF INSTR(element$[x], "VAR ") THEN
		IF INSTR(g_PROTOTYPE$, ",") THEN
		    PRINT NL$, "ERROR: variable argument list cannot be preceded by other arguments at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		    END 1
		END IF
		IF NOT(INSTR(element$[x], " SIZE ")) THEN
		    PRINT NL$, "ERROR: variable argument list lacks SIZE argument at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		    END 1
		END IF
		arr$ = MID$(element$[x], INSTR(element$[x], " ") + 1):arr$ = CHOP$(LEFT$(arr$, INSTR(arr$, "SIZE ")-1)):size$ = CHOP$(MID$(element$[x], INSTR(element$[x], "SIZE ") + 5))
		IF NOT(INSTR(arr$, g_STRINGSIGN$)) THEN
		    PRINT NL$, "ERROR: variable argument list is not string at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
		    END 1
		END IF
		check = Check_Declared(g_HFILE$, size$, g_HEADER_SEARCHPOS)
		IF ISFALSE(check) THEN g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, " long ", size$, ";")
		g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "long __b2c__var_", arr$, " = ", STR$(g_OPTION_BASE), "; va_list __b2c__ap; char **", arr$, " = NULL; char* __b2c__va = NULL; ", arr$, " = (char **)realloc(", arr$, ", (__b2c__var_", arr$, "+1) * sizeof(char*));")
		g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "va_start(__b2c__ap, __b2c__name); ", arr$, "[__b2c__var_", arr$, "] = strdup(__b2c__name); while (", arr$, "[__b2c__var_", arr$, "] != NULL) {__b2c__var_", arr$, "++; ", arr$, " = (char **)realloc(", arr$, ", (__b2c__var_", arr$, "+1) * sizeof(char*));")
		g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "__b2c__va = va_arg(__b2c__ap, char*); if(__b2c__va != NULL) ", arr$, "[__b2c__var_", arr$, "] = strdup(__b2c__va); else ", arr$, "[__b2c__var_", arr$, "] = NULL; }")
		g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, "va_end(__b2c__ap); ", size$, " = __b2c__var_", arr$, " - ", STR$(g_OPTION_BASE), "; if(__b2c__var_", arr$, " > 0) __b2c__var_", arr$, "--;")
		g_PROTOTYPE$ = CONCAT$("__", g_PROTOTYPE$)
		g_ORIGFUNCNAME$ = CONCAT$(g_ORIGFUNCNAME$, "char *__b2c__name, ...)")
		element$[x] = "char*, ..."
		g_STRINGARRAYS$ = CONCAT$(g_STRINGARRAYS$, "if(", arr$, " != NULL) {for(__b2c__ctr=", STR$(g_OPTION_BASE), "; __b2c__ctr<=__b2c__var_", arr$, "; __b2c__ctr++) if(", arr$, "[__b2c__ctr]!=NULL){free(", arr$, "[__b2c__ctr]);} free(", arr$, ");}")
	    ELSE
		g_ORIGFUNCNAME$ = CHOP$(CONCAT$(g_ORIGFUNCNAME$, " ", element$[x], ")"))
	    END IF
	    g_PROTOTYPE$ = CONCAT$(g_PROTOTYPE$, " ", element$[x], ")")
	END IF
    END IF

    ' Get original function name
    IF INSTR(g_ORIGFUNCNAME$, " (") THEN
	g_FUNCNAME$ = LEFT$(g_ORIGFUNCNAME$, INSTR(g_ORIGFUNCNAME$, " (") - 1)
    ELIF INSTR(g_ORIGFUNCNAME$, "(") THEN
	g_FUNCNAME$ = LEFT$(g_ORIGFUNCNAME$, INSTR(g_ORIGFUNCNAME$, "(") - 1)
    ELSE
	g_FUNCNAME$ = g_ORIGFUNCNAME$
    END IF

    ' Close the current C file
    CLOSE FILE g_CFILE

    ' Add macro in case of VAR argument
    IF INSTR(element$[x], " ...") THEN
	WRITELN "#define ", g_FUNCNAME$, "(...) __", g_FUNCNAME$, "(\"", g_FUNCNAME$, "\", __VA_ARGS__, NULL)" TO g_HFILE
	g_ORIGFUNCNAME$ = CONCAT$("__", g_ORIGFUNCNAME$)
    END IF

    ' Make symbol known to parser
    g_IMPORTED$ = CONCAT$(g_FUNCNAME$, " ", g_IMPORTED$)

    ' Switch to header file
    g_COPY_CFILE$ = g_CFILE$
    g_CFILE$ = CONCAT$(LEFT$(g_CFILE$, INSTR(g_CFILE$, ".c")), g_FUNCNAME$, ".tmp")

    ' Save CATCH routine
    g_ORIGCATCHGOTO$ = g_CATCHGOTO$
    g_CATCHGOTO$ = "__B2C__PROGRAM__EXIT"

    ' Open temp C file
    OPEN g_CFILE$ FOR WRITING AS g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Endsub()

    LOCAL tmp_HFILE TYPE FILE*
    LOCAL line$
    LOCAL dim, x

    ' Close the current C file
    CLOSE FILE g_CFILE

    ' Put prototype to header file
    WRITELN "void ", g_PROTOTYPE$, "; /* noparse */" TO g_HFILE
    g_PROTOTYPE$ = ""

    ' Open temporary header file
    OPEN CONCAT$(g_TEMPDIR$, "/", LEFT$(g_CURFILE$, INSTR(g_CURFILE$, ".bac")), g_FUNCNAME$, ".h") FOR WRITING AS tmp_HFILE

    ' Get original function name
    WRITELN "/* Created with BaCon ", g_VERSION$, " - (c) Peter van Eerten - GPL v3 */" TO tmp_HFILE
    WRITELN "/* noparse ", g_CURFILE$, " BACON LINE ", g_COUNTER, " */" TO tmp_HFILE
    IF INSTR(g_ORIGFUNCNAME$, " (") THEN
	WRITELN "void ", g_ORIGFUNCNAME$, " {" TO tmp_HFILE
    ELIF INSTR(g_ORIGFUNCNAME$, "(") THEN
	WRITELN "void ", g_ORIGFUNCNAME$, " {" TO tmp_HFILE
    ELSE
	WRITELN "void ", g_FUNCNAME$, "(void) {" TO tmp_HFILE
    END IF

    ' Finalize sub
    WRITELN g_STRINGARGS$ TO tmp_HFILE
    OPEN g_CFILE$ FOR READING AS g_CFILE
    WHILE NOT(ENDFILE(g_CFILE)) DO
        READLN line$ FROM g_CFILE
        IF NOT(ENDFILE(g_CFILE)) THEN WRITELN line$ TO tmp_HFILE
    WEND
    CLOSE FILE g_CFILE

    ' Free strings variables if there are any
    SPLIT g_LOCALSTRINGS$ BY " " TO element$ SIZE dim
    FOR x = 1 TO dim
	IF LEN(element$[x]) > 0 THEN WRITELN "if(", element$[x], " != NULL) free(", element$[x], ");" TO tmp_HFILE
    NEXT
    WRITELN g_STRINGARRAYS$ TO tmp_HFILE
    WRITELN "__B2C__PROGRAM__EXIT: ;" TO tmp_HFILE
    WRITELN "}" TO tmp_HFILE

	CLOSE FILE tmp_HFILE
	
    ' Include header file
    IF NOT(INSTR(g_INCLUDE_FILES$, CONCAT$(LEFT$(g_CURFILE$, INSTR(g_CURFILE$, ".bac")), g_FUNCNAME$, ".h"))) THEN
	g_INCLUDE_FILES$ = CONCAT$(g_INCLUDE_FILES$, " ", LEFT$(g_CURFILE$, INSTR(g_CURFILE$, ".bac")), g_FUNCNAME$, ".h")
    END IF

    ' Add to total filelist
    g_TMP_FILES$ = CONCAT$(g_TMP_FILES$, " ", g_TEMPDIR$, "/", LEFT$(g_CURFILE$, INSTR(g_CURFILE$, ".bac")), g_FUNCNAME$, ".h")

    ' Delete temp funcfile
    DELETE FILE g_CFILE$

    ' Restore mainfile
    g_CFILE$ = g_COPY_CFILE$
    OPEN g_CFILE$ FOR APPENDING AS g_CFILE

    ' Restore CATCH routine
    g_CATCHGOTO$ = g_ORIGCATCHGOTO$

    ' Reset variables
    g_ORIGFUNCNAME$ = ""
    g_FUNCNAME$ = ""
    g_LOCALSTRINGS$ = ""
    g_STRINGARRAYS$ = ""
    g_STRINGARGS$ = ""

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Endfunction()

    IF ISFALSE(LEN(g_FUNCTYPE$)) THEN
	PRINT NL$, "ERROR: function '", g_FUNCNAME$, "' was defined without returning a value or string!"
	END 1
    END IF

    ' Close the current C file
    CLOSE FILE g_CFILE

    ' Put prototype to header file
    WRITELN g_FUNCTYPE$, " ", g_PROTOTYPE$, "; /* noparse */" TO g_HFILE
    g_PROTOTYPE$ = ""

    ' Open temporary header file
    OPEN CONCAT$(g_TEMPDIR$, "/", LEFT$(g_CURFILE$, INSTR(g_CURFILE$, ".bac")), g_FUNCNAME$, ".h") FOR WRITING AS tmp_HFILE

    ' Get original function name
    WRITELN "/* Created with BaCon ", g_VERSION$, " - (c) Peter van Eerten - GPL v3 */" TO tmp_HFILE
    WRITELN "/* noparse ", g_CURFILE$, " BACON LINE ", g_COUNTER, " */" TO tmp_HFILE
    IF NOT(INSTR(g_ORIGFUNCNAME$, "(")) THEN
	WRITELN g_FUNCTYPE$, " ", g_FUNCNAME$, "(void) {" TO tmp_HFILE
    ELSE
	WRITELN g_FUNCTYPE$, " ", g_ORIGFUNCNAME$, " {" TO tmp_HFILE
    END IF

    ' Add function body
    WRITELN g_STRINGARGS$ TO tmp_HFILE
    OPEN g_CFILE$ FOR READING AS g_CFILE
    WHILE NOT(ENDFILE(g_CFILE)) DO
        READLN line$ FROM g_CFILE
        IF NOT(ENDFILE(g_CFILE)) THEN WRITELN line$ TO tmp_HFILE
    WEND
    CLOSE FILE g_CFILE

    WRITELN "__B2C__PROGRAM__EXIT: ;" TO tmp_HFILE

    ' Make sure the function always returns something
    IF INSTR(g_FUNCTYPE$, "char*") THEN WRITELN "return (\"\");}" TO tmp_HFILE
    ELSE WRITELN "return (0);}" TO tmp_HFILE

	CLOSE FILE tmp_HFILE
	
    ' Include header file
    IF NOT(INSTR(g_INCLUDE_FILES$, CONCAT$(LEFT$(g_CURFILE$, INSTR(g_CURFILE$, ".bac")), g_FUNCNAME$, ".h"))) THEN
	g_INCLUDE_FILES$ = CONCAT$(g_INCLUDE_FILES$, " ", LEFT$(g_CURFILE$, INSTR(g_CURFILE$, ".bac")), g_FUNCNAME$, ".h")
    END IF

    ' Add to total filelist
    g_TMP_FILES$ = CONCAT$(g_TMP_FILES$, " ", g_TEMPDIR$, "/", LEFT$(g_CURFILE$, INSTR(g_CURFILE$, ".bac")), g_FUNCNAME$, ".h")

    ' Delete temp funcfile
    DELETE FILE g_CFILE$

    ' Restore mainfile
    g_CFILE$ = g_COPY_CFILE$
    OPEN g_CFILE$ FOR APPENDING AS g_CFILE

    ' Restore CATCH routine
    g_CATCHGOTO$ = g_ORIGCATCHGOTO$

    ' Clear function variables
    g_ORIGFUNCNAME$ = ""
    g_FUNCNAME$ = ""
    g_FUNCTYPE$ = ""
    g_LOCALSTRINGS$ = ""
    g_STRINGARRAYS$ = ""
    g_STRINGARGS$ = ""

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Return(STRING arg$)

    LOCAL type$, thearg$
    LOCAL dim, x

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty RETURN at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    type$ = Check_Type$(g_CFILE$, arg$, 0)

   ' Check type of var, func using string but returning a value? See also PRINT miniparser
    IF REGEX(arg$, "^VAL *\\(|^INSTR *\\(|^LEN *\\(|^SEARCH *\\(|^ASC *\\(|^FILE *\\(|^REGEX *\\(|^INSTRREV *\\(") THEN
	g_FUNCTYPE$ = "double "
	thearg$ = arg$

    ' Check type of var, string or normal string?
    ELIF INSTR(arg$, g_STRINGSIGN$) OR INSTR(arg$, CHR$(34)) OR INSTR(g_FUNCNAME$, g_STRINGSIGN$) THEN
	g_FUNCTYPE$ = "char* "
	WRITELN "__b2c__rbuffer_ptr++; if(__b2c__rbuffer_ptr >= ", g_MAX_RBUFFERS, ") __b2c__rbuffer_ptr=0; if(", arg$, " != NULL)" TO g_CFILE
	WRITELN " {__b2c__rbuffer[__b2c__rbuffer_ptr] = (char*)realloc(__b2c__rbuffer[__b2c__rbuffer_ptr], (strlen(", arg$, ")+1)*sizeof(char));" TO g_CFILE
	WRITELN "strcpy(__b2c__rbuffer[__b2c__rbuffer_ptr], ", arg$, ");}" TO g_CFILE
	WRITELN "else {__b2c__rbuffer[__b2c__rbuffer_ptr] = (char*)realloc(__b2c__rbuffer[__b2c__rbuffer_ptr], 2*sizeof(char));" TO g_CFILE
	WRITELN "strcpy(__b2c__rbuffer[__b2c__rbuffer_ptr], \"\");}" TO g_CFILE
	thearg$ = "__b2c__rbuffer[__b2c__rbuffer_ptr]"

    ' Check if float
    ELIF INSTR(arg$, ".") THEN
	g_FUNCTYPE$ = "double "
	thearg$ = arg$

    ' Check if no alpha chars (then integer value)
    ELIF REGEX(arg$, "[0-9]") THEN
	g_FUNCTYPE$ = "long "
	thearg$ = arg$

    ' Assume variable, check if declared before
    ELIF ISTRUE(LEN(type$)) THEN
	IF INSTR(type$, "DIR* ") THEN
		g_FUNCTYPE$ = "DIR* "
	ELIF INSTR(type$, "FILE ") THEN
		g_FUNCTYPE$ = "FILE* "
	ELIF INSTR(type$, "int* ") THEN
		g_FUNCTYPE$ = "int* "
	ELIF INSTR(type$, "float* ") THEN
		g_FUNCTYPE$ = "float* "
	ELIF INSTR(type$, "double* ") THEN
		g_FUNCTYPE$ = "double* "
	ELIF INSTR(type$, "char* ") OR INSTR(type$, "STRING ") THEN
		g_FUNCTYPE$ = "char* "
	ELIF INSTR(type$, "long* ") THEN
		g_FUNCTYPE$ = "long* "
	ELIF INSTR(type$, "void* ") THEN
		g_FUNCTYPE$ = "void* "
	ELIF INSTR(type$, "int ") THEN
		g_FUNCTYPE$ = "int "
	ELIF INSTR(type$, "float ") THEN
		g_FUNCTYPE$ = "float "
	ELIF INSTR(type$, "double ") OR INSTR(type$, "FLOATING ") THEN
		g_FUNCTYPE$ = "double "
	ELIF INSTR(type$, "char ") THEN
		g_FUNCTYPE$ = "char "
	ELIF INSTR(type$, "long ") OR INSTR(type$, "NUMBER ") THEN
		g_FUNCTYPE$ = "long "
	ELIF INSTR(type$, "void ") THEN
		g_FUNCTYPE$ = "void "
	END IF
	thearg$ = arg$

    ' Not declared, assume integer variable
    ELSE
	g_FUNCTYPE$ = "long "
	thearg$ = arg$
    END IF

    ' Free strings variables if there are any
    SPLIT g_LOCALSTRINGS$ BY " " TO element$ SIZE dim
    FOR x = 1 TO dim
	IF LEN(element$[x]) > 0 THEN WRITELN "if(", element$[x], " != NULL) free(", element$[x], ");" TO g_CFILE
    NEXT
    WRITELN g_STRINGARRAYS$ TO g_CFILE

    ' The actual return value
    WRITELN "return (", thearg$, ");" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Deffn(STRING arg$)

    LOCAL sym$

    ' Check if we have an argument at all
    IF ISFALSE(LEN(arg$)) THEN
	PRINT NL$, "ERROR: empty DEF FN at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Translate to C macro
    sym$ = CHOP$(MID$(arg$, INSTR(arg$, " ")))

    WRITELN "#define ", LEFT$(sym$, INSTR(sym$, "=") -1), " (", MID$(sym$, INSTR(sym$, "=") + 1), ")" TO g_HFILE

    ' Make symbol known to parser
    g_IMPORTED$ = CONCAT$(LEFT$(sym$, INSTR(sym$, "(") - 1), " ", g_IMPORTED$)

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Const(STRING arg$)

    ' Check if we have an argument at all
    IF ISFALSE(LEN(arg$)) THEN
	PRINT NL$, "ERROR: empty CONST at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    WRITELN "#define ", LEFT$(arg$, INSTR(arg$, "=") - 1), " (", MID$(arg$, INSTR(arg$, "=") + 1), ")" TO g_HFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Push(STRING arg$)

    LOCAL type$

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty PUSH at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    IF NOT(INSTR(arg$, ".")) THEN
	type$ = Check_Type$(g_HFILE$, arg$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(LEN(type$)) THEN
	    type$ = Check_Type$(g_CFILE$, arg$, 0)
	END IF
    END IF

    ' Allocate space for type
    WRITELN "__b2c__typestack = (int*)realloc(__b2c__typestack, (__b2c__stackptr+1)*sizeof(int));" TO g_CFILE

    ' Check type of var, string?
    IF INSTR(arg$, g_STRINGSIGN$) THEN
	WRITELN "__b2c__stringstack = (char**)realloc(__b2c__stringstack, (__b2c__stackptr+1)*sizeof(char*));" TO g_CFILE
	WRITELN "if(__b2c__stackptr == 0){ __b2c__stringstack[__b2c__stackptr] = realloc(__b2c__stringstack[__b2c__stackptr], (strlen(", arg$, ")+1)*sizeof(char));" TO g_CFILE
	WRITELN "strcpy(__b2c__stringstack[__b2c__stackptr], ", arg$, ");} else __b2c__stringstack[__b2c__stackptr] = strdup(", arg$, ");" TO g_CFILE
	WRITELN "__b2c__typestack[__b2c__stackptr] = 1;" TO g_CFILE
    ' Check if it is a normal string
    ELIF INSTR(arg$, CHR$(34)) THEN
	WRITELN "__b2c__stringstack = (char**)realloc(__b2c__stringstack, (__b2c__stackptr+1)*sizeof(char*));" TO g_CFILE
	WRITELN "if(__b2c__stackptr == 0){ __b2c__stringstack[__b2c__stackptr] = realloc(__b2c__stringstack[__b2c__stackptr], (strlen(", arg$, ")+1)*sizeof(char));" TO g_CFILE
	WRITELN "strcpy(__b2c__stringstack[__b2c__stackptr], ", arg$, ");} else __b2c__stringstack[__b2c__stackptr] = strdup(", arg$, ");" TO g_CFILE
	WRITELN "__b2c__typestack[__b2c__stackptr] = 1;" TO g_CFILE
    ' Check if float
    ELIF INSTR(arg$, ".") THEN
	WRITELN "__b2c__doublestack = (double*)realloc(__b2c__doublestack, (__b2c__stackptr+1)*sizeof(double));" TO g_CFILE
	WRITELN "__b2c__doublestack[__b2c__stackptr] = ", arg$, ";" TO g_CFILE
	WRITELN "__b2c__typestack[__b2c__stackptr] = 2;" TO g_CFILE
    ' Check if no alpha chars (then integer value)
    ELIF NOT(REGEX(arg$, "[a-zA-Z]")) THEN
	WRITELN "__b2c__longstack = (long*)realloc(__b2c__longstack, (__b2c__stackptr+1)*sizeof(long));" TO g_CFILE
	WRITELN "__b2c__longstack[__b2c__stackptr] = ", arg$, ";" TO g_CFILE
	WRITELN "__b2c__typestack[__b2c__stackptr] = 3;" TO g_CFILE
    ' Assume variable, check if declared before
    ELIF ISTRUE(LEN(type$)) THEN
	IF REGEX(type$, "double .*") THEN
	    WRITELN "__b2c__doublestack = (double*)realloc(__b2c__doublestack, (__b2c__stackptr+1)*sizeof(double));" TO g_CFILE
	    WRITELN "__b2c__doublestack[__b2c__stackptr] = ", arg$, ";" TO g_CFILE
	    WRITELN "__b2c__typestack[__b2c__stackptr] = 2;" TO g_CFILE
	ELSE
	    WRITELN "__b2c__longstack = (long*)realloc(__b2c__longstack, (__b2c__stackptr+1)*sizeof(long));" TO g_CFILE
	    WRITELN "__b2c__longstack[__b2c__stackptr] = ", arg$, ";" TO g_CFILE
	    WRITELN "__b2c__typestack[__b2c__stackptr] = 3;" TO g_CFILE
	END IF
    ' Not declared, assume integer variable
    ELSE
	WRITELN "__b2c__longstack = (long*)realloc(__b2c__longstack, (__b2c__stackptr+1)*sizeof(long));" TO g_CFILE
	WRITELN "__b2c__longstack[__b2c__stackptr] = ", arg$, ";" TO g_CFILE
	WRITELN "__b2c__typestack[__b2c__stackptr] = 3;" TO g_CFILE
    END IF

    ' Increase stackpointer
    WRITELN "__b2c__stackptr++;" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Pull(STRING arg$)

    LOCAL check
    LOCAL type$

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty PULL at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Argument must be a variable
    IF NOT(REGEX(arg$, "[a-zA-Z]+.*")) THEN
	PRINT NL$, "ERROR: argument in PULL statement at line ", g_COUNTER, " in file '", g_CURFILE$, "' is not a variable!"
	END 1
    END IF

    ' Decrease stackpointer again
    WRITELN "__b2c__stackptr--;" TO g_CFILE
    WRITELN "if(__b2c__stackptr < 0) __b2c__stackptr=0;" TO g_CFILE

    ' Get the last value from stack
    IF INSTR(arg$, g_STRINGSIGN$) THEN
	check = Search(g_HFILE$, CONCAT$("char *", arg$, " = NULL;"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", arg$, " = NULL;"), 0)
	ENDIF

	IF check < 0 THEN WRITELN "char *", arg$, " = NULL;" TO g_HFILE

	WRITELN "if(__b2c__typestack[__b2c__stackptr] == 1) {" TO g_CFILE
	WRITELN arg$, " = (char*)realloc(", arg$, ", (strlen(__b2c__stringstack[__b2c__stackptr])+1)*sizeof(char));" TO g_CFILE
	WRITELN "strcpy(", arg$, ", __b2c__stringstack[__b2c__stackptr]); if(__b2c__stackptr > 0) free(__b2c__stringstack[__b2c__stackptr]);}" TO g_CFILE
    ELSE
	' Variable may not be array, these should be defined with DECLARE
	IF NOT(REGEX(arg$, "\\[.*\\]")) AND NOT(INSTR(arg$, ".")) THEN
	    ' Not declared? Assume long
	    check = Check_Declared(g_HFILE$, arg$, g_HEADER_SEARCHPOS)
	    IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, arg$, 0)

	    IF ISFALSE(check) THEN WRITELN "long ", arg$, "; /* pull */" TO g_HFILE
	END IF

	' See how var was declared
	type$ = Check_Type$(g_HFILE$, arg$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(LEN(type$)) THEN
	    type$ = Check_Type$(g_CFILE$, arg$, 0)
	END IF

	' Make sure internal var is copied to var of program
	IF INSTR(type$, "double ") OR INSTR(type$, "float ") OR INSTR(type$, "FLOATING ") THEN
	    WRITELN "if(__b2c__typestack[__b2c__stackptr] == 2) ", arg$, "=__b2c__doublestack[__b2c__stackptr];" TO g_CFILE
	ELIF INSTR(type$, "long ") OR INSTR(type$, "int ") OR INSTR(type$, "NUMBER ") THEN
	    WRITELN "if(__b2c__typestack[__b2c__stackptr] == 3) ", arg$, "=__b2c__longstack[__b2c__stackptr];" TO g_CFILE
	ELSE
	    WRITELN "if(__b2c__typestack[__b2c__stackptr] == 1) {" TO g_CFILE
	    WRITELN arg$, " = (char*)realloc(", arg$, ", (strlen(__b2c__stringstack[__b2c__stackptr])+1)*sizeof(char));" TO g_CFILE
	    WRITELN "strcpy(", arg$, ", __b2c__stringstack[__b2c__stackptr]); if(__b2c__stackptr > 0) free(__b2c__stringstack[__b2c__stackptr]);}" TO g_CFILE
	END IF
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Import(STRING arg$)

    LOCAL lib$, type$, sym$, tmp$, token$, alias$
    LOCAL check

    ' Check if FROM is available
    IF NOT(INSTR(arg$, " FROM ")) THEN
	PRINT NL$, "ERROR: missing FROM in IMPORT statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the symbolname without surrounding spaces and doublequotes
    IF INSTR(arg$, "(") THEN
	sym$ = REPLACE$((CHOP$(LEFT$(arg$, INSTR(arg$, "(") - 1))), CHR$(34), "")
	tmp$ = CHOP$(MID$(arg$, INSTR(arg$, " FROM ") + 6))
	token$ = CHOP$(MID$(arg$, 1, INSTRREV(arg$, ")") - 1))
    ELSE
	sym$ = REPLACE$((CHOP$(MID$(arg$, 1, INSTR(arg$, " FROM ") - 1))), CHR$(34), "")
	tmp$ = CHOP$(MID$(arg$, INSTR(arg$, " FROM ") + 6))
	token$ = ""
    END IF

    ' Check if TYPE is available
    IF NOT(INSTR(arg$, " TYPE ")) THEN
	PRINT NL$, "ERROR: missing TYPE in IMPORT statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get library and type
    lib$ = CHOP$(MID$(tmp$, 1, INSTR(tmp$, " TYPE ")))
    type$ = CHOP$(MID$(tmp$, INSTR(tmp$, " TYPE ") + 6))

    ' Check if ALIAS is there
    IF INSTR(type$, " ALIAS ") THEN
	alias$ = REPLACE$(MID$(type$, INSTR(type$, " ALIAS ") + 7), CHR$(34), "")
	WRITELN "#define ", alias$, " ", sym$ TO g_HFILE
	g_IMPORTED$ = CONCAT$(alias$, " ", g_IMPORTED$)
	type$ = LEFT$(type$, INSTR(type$, " ALIAS ") - 1)
    ENDIF

    ptr$ = REPLACE$(REPLACE$(lib$, CHR$(34), ""), "-", "")
    ptr$ = REPLACE$(REPLACE$(REPLACE$(ptr$, ".", ""), "/", ""), "_", "")

    ' If library is libm or libc, skip dlopen as we're linking with those anyway
    IF NOT(INSTR(lib$, "libc.so") ) AND NOT(INSTR(lib$, "libm.so")) THEN

	' Check if variable was declared
	check = Search(g_CFILE$, CONCAT$("void* __b2c__dlopen__pointer_", ptr$, ";"), 0)
	IF check < 0 THEN
	    WRITELN "void* __b2c__dlopen__pointer_", ptr$, ";" TO g_CFILE
	    WRITELN "__b2c__dlopen__pointer_", ptr$, " = dlopen(", lib$, ", RTLD_LAZY);" TO g_CFILE
	END IF
	WRITELN "if(__b2c__dlopen__pointer_", ptr$, " == NULL){if(!__b2c__trap){ERROR = 3;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE

	' Check if token was declared
	check = Search(g_HFILE$, CONCAT$(type$, "(\\*", sym$, ")"), g_HEADER_SEARCHPOS)
	IF check < 0 THEN
	    WRITELN type$, "(*", sym$, ")(", MID$(token$, INSTR(token$, "(") + 1), ");" TO g_HFILE
	END IF

	' Translate to C function
	WRITELN "*(", type$, "**) (&", sym$, ") = dlsym(__b2c__dlopen__pointer_", ptr$, ", \"", sym$, "\");" TO g_CFILE
	WRITELN "if(", sym$, " == NULL) {if(!__b2c__trap){ERROR = 4;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
    END IF

    ' Make symbol known to parser
    g_IMPORTED$ = CONCAT$(sym$, " ", g_IMPORTED$)

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Declare(STRING arg$)

    LOCAL var$, type$, new$, value$
    LOCAL i, dim, check, option

    '  Check on a GLOBAL RECORD
    IF INSTR(arg$, "RECORD ") THEN
	' Translate to C typedef struct
	g_RECORDNAME$ = CONCAT$("RECORD_", STR$(g_COUNTER))
	WRITELN "struct ", g_RECORDNAME$, "{" TO g_HFILE
	g_RECORDVAR$ = MID$(CHOP$(arg$), INSTR(CHOP$(arg$), " ") + 1)
	' Store current function name
	IF LEN(g_FUNCNAME$) > 0 THEN
	    g_RECORDCACHE$ = g_FUNCNAME$
	    g_FUNCNAME$ = ""
	END IF
    ELSE
	' Get the variablename and type
	IF INSTR(arg$, " TYPE ") THEN
	    var$ = CHOP$(MID$(arg$, 1, INSTR(arg$, " TYPE ")))
	    type$ = CHOP$(MID$(arg$, INSTR(arg$, " TYPE ") + 6))
	ELIF INSTR(arg$, " ASSOC ") THEN
	    var$ = CHOP$(MID$(arg$, 1, INSTR(arg$, " ASSOC ")))
	    type$ = CHOP$(MID$(arg$, INSTR(arg$, " ASSOC ") + 7))
	ELSE
	    var$ = CHOP$(arg$)
	    type$ = "long"
	END IF

	' Check if variable was already declared
	IF NOT(INSTR(var$, ".")) THEN check = Check_Declared(g_HFILE$, var$, g_HEADER_SEARCHPOS)
	ELSE check = FALSE

	IF ISTRUE(check) THEN
	    PRINT NL$, "ERROR: variable in DECLARE or GLOBAL statement at line ", g_COUNTER, " in file '", g_CURFILE$, "' was defined previously!"
	    END 1
	END IF

	' If array, increase dimensions when OPTION BASE is set
	IF REGEX(var$, "\\[.*\\]") AND NOT(INSTR(var$, "=")) THEN
	    new$ = ""
	    REPEAT
		new$ = CONCAT$(new$, LEFT$(var$, INSTR(var$, "[") - 1), "[")
		value$ = MID$(var$, INSTR(var$, "[") + 1)
		new$ = CONCAT$(new$, MID$(value$, 1, INSTR(value$, "]") - 1), "+", STR$(g_OPTION_BASE), "]")
		var$ = MID$(var$, INSTR(var$, "]") + 1)
	    UNTIL NOT(REGEX(var$, "\\[.*\\]"))
	    var$ = new$
	END IF

	' Check for associative array
	IF INSTR(arg$, " ASSOC ") THEN
	    SPLIT var$ BY "," TO str$ SIZE dim
	    FOR i = 1 TO dim
		WRITELN "struct __b2c__", CHOP$(str$[i]), "_type {char *key; /* noparse */ ", type$, " value; /* noparse */ };" TO g_HFILE
		WRITELN "struct __b2c__", CHOP$(str$[i]), "_type *__b2c__", CHOP$(str$[i]), " = { NULL }; long __b2c__", CHOP$(str$[i]), "_idx = 0;" TO g_HFILE

		WRITELN "static int __b2c__", CHOP$(str$[i]), "_comp(const void *__b2c__m1, const void *__b2c__m2){ " TO g_HFILE
		WRITELN "struct __b2c__", CHOP$(str$[i]), "_type *__b2c__mi1 = (struct __b2c__", CHOP$(str$[i]), "_type *) __b2c__m1;" TO g_HFILE
		WRITELN "struct __b2c__", CHOP$(str$[i]), "_type *__b2c__mi2 = (struct __b2c__", CHOP$(str$[i]), "_type *) __b2c__m2;" TO g_HFILE
		WRITELN "if(__b2c__mi1->key == NULL && __b2c__mi2->key == NULL) return 0;" TO g_HFILE
		WRITELN "if(__b2c__mi1->key == NULL && __b2c__mi2->key != NULL) return -1;" TO g_HFILE
		WRITELN "if(__b2c__mi1->key != NULL && __b2c__mi2->key == NULL) return 1;" TO g_HFILE
		WRITELN "return strcmp(__b2c__mi1->key, __b2c__mi2->key); }" TO g_HFILE

		WRITELN "struct __b2c__", CHOP$(str$[i]), "_type * __b2c__", CHOP$(str$[i]), "_exist (char *__b2c__index){struct __b2c__", CHOP$(str$[i]), "_type __b2c__", CHOP$(str$[i]), "_key, *__b2c__", CHOP$(str$[i]), "__result;" TO g_HFILE
		WRITELN "qsort(__b2c__", CHOP$(str$[i]), ", __b2c__", CHOP$(str$[i]), "_idx, sizeof(struct __b2c__", CHOP$(str$[i]), "_type), __b2c__", CHOP$(str$[i]), "_comp);" TO g_HFILE
		WRITELN "__b2c__", CHOP$(str$[i]), "_key.key = __b2c__index; __b2c__", CHOP$(str$[i]), "__result = bsearch(&__b2c__", CHOP$(str$[i]), "_key, __b2c__", CHOP$(str$[i]), "," TO g_HFILE
		WRITELN "__b2c__", CHOP$(str$[i]), "_idx, sizeof(struct __b2c__", CHOP$(str$[i]), "_type), __b2c__", CHOP$(str$[i]), "_comp);" TO g_HFILE
		WRITELN "return(__b2c__", CHOP$(str$[i]), "__result); }" TO g_HFILE

		WRITELN "void __b2c__", CHOP$(str$[i]), "__add(char *__b2c__index){__b2c__", CHOP$(str$[i]), "_idx++;" TO g_HFILE
		WRITELN "__b2c__", CHOP$(str$[i]), " = (struct __b2c__", CHOP$(str$[i]), "_type *) realloc (__b2c__", CHOP$(str$[i]), ", __b2c__", CHOP$(str$[i]), "_idx * sizeof (struct __b2c__", CHOP$(str$[i]), "_type));" TO g_HFILE
		WRITELN "__b2c__", CHOP$(str$[i]), "[__b2c__", CHOP$(str$[i]), "_idx - 1].key = strdup (__b2c__index); __b2c__", CHOP$(str$[i]), "[__b2c__", CHOP$(str$[i]), "_idx-1].value = 0;}" TO g_HFILE

		WRITELN "void __b2c__", CHOP$(str$[i]), "__del(char *__b2c__index){struct __b2c__", CHOP$(str$[i]), "_type *__b2c__", CHOP$(str$[i]), "__location = __b2c__", CHOP$(str$[i]), "_exist(__b2c__index);" TO g_HFILE
		WRITELN "if(__b2c__", CHOP$(str$[i]), "__location != NULL) {free(__b2c__", CHOP$(str$[i]), "__location->key); __b2c__", CHOP$(str$[i]), "__location->key = NULL;} }" TO g_HFILE

		WRITELN type$, " ", CHOP$(str$[i]), "(char *__b2c__index){struct __b2c__", CHOP$(str$[i]), "_type __b2c__", CHOP$(str$[i]), "_key, *__b2c__", CHOP$(str$[i]), "__result;" TO g_HFILE
		WRITELN "qsort(__b2c__", CHOP$(str$[i]), ", __b2c__", CHOP$(str$[i]), "_idx, sizeof(struct __b2c__", CHOP$(str$[i]), "_type), __b2c__", CHOP$(str$[i]), "_comp);" TO g_HFILE
		WRITELN "__b2c__", CHOP$(str$[i]), "_key.key = __b2c__index; __b2c__", CHOP$(str$[i]), "__result = bsearch(&__b2c__", CHOP$(str$[i]), "_key, __b2c__", CHOP$(str$[i]), "," TO g_HFILE
		WRITELN "__b2c__", CHOP$(str$[i]), "_idx, sizeof(struct __b2c__", CHOP$(str$[i]), "_type), __b2c__", CHOP$(str$[i]), "_comp);" TO g_HFILE
		IF INSTR(str$[i], g_STRINGSIGN$) OR INSTR(type$, "STRING") OR INSTR(type$, "char*") THEN
		    WRITELN "if(__b2c__", CHOP$(str$[i]), "__result == NULL) return(\"\"); return __b2c__", CHOP$(str$[i]), "__result->value;}" TO g_HFILE
		ELSE
		    WRITELN "if(__b2c__", CHOP$(str$[i]), "__result == NULL) return(0); return __b2c__", CHOP$(str$[i]), "__result->value;}" TO g_HFILE
		END IF
	    NEXT

	' Check if var is string var
	ELIF ( INSTR(var$, g_STRINGSIGN$) OR REGEX(type$, "STRING|char\\*") ) AND NOT(INSTR(var$, "=")) THEN
	    check = Search(g_HFILE$, CONCAT$("char *", var$, " = NULL;"), g_HEADER_SEARCHPOS)
	    IF check < 0 THEN
		SPLIT CHOP$(var$) BY "," TO str$ SIZE dim
		FOR i = 1 TO dim
		    IF INSTR(str$[i], "[") THEN
			WRITELN "char *", CHOP$(str$[i]), " = { NULL };" TO g_HFILE
		    ELSE
			WRITELN "char *", CHOP$(str$[i]), " = NULL; " TO g_HFILE
			' Pointer var should not be initialized
			IF INSTR(var$, g_STRINGSIGN$) THEN WRITELN CHOP$(str$[i]), " = calloc(1, sizeof(char));" TO g_CFILE
		    END IF
		NEXT
	    END IF
        ' Var is string array assignment
	ELIF ( INSTR(var$, g_STRINGSIGN$) OR REGEX(type$, "STRING|char\\*") ) AND INSTR(var$, "=") THEN
            WRITELN "char* ", MID$(var$, 1, INSTR(var$, "{")) TO g_HFILE
            option = g_OPTION_BASE
            WHILE option > 0
                WRITELN " \"\", " TO g_HFILE
                DECR option
            WEND
	    WRITELN MID$(var$, INSTR(var$, "{")+1), ";" TO g_HFILE

	' Assume char assignment or number
	ELSE
	    IF INSTR(var$, "[") AND NOT(INSTR(var$, "=")) THEN
		SPLIT var$ BY "," TO str$ SIZE dim
		FOR i = 1 TO dim
		    WRITELN type$, " ", str$[i], " = { 0 };" TO g_HFILE
		NEXT
	    ELIF INSTR(var$, "[") AND INSTR(var$, "=") THEN
                WRITELN type$, " ", MID$(var$, 1, INSTR(var$, "{")) TO g_HFILE
                option = g_OPTION_BASE
                WHILE option > 0
                    WRITELN " 0, " TO g_HFILE
                    DECR option
                WEND
	        WRITELN MID$(var$, INSTR(var$, "{")+1), ";" TO g_HFILE
	    ELIF NOT(INSTR(var$, "=")) AND NOT(INSTR(var$, "(")) AND REGEX(type$, "char|short|int|long|double|float|NUMBER|FLOATING") THEN
		WRITELN type$, " ", var$, ";" TO g_HFILE
		WRITELN REPLACE$(var$, ",", "="), " = 0;" TO g_CFILE
	    ELSE
		WRITELN type$, " ", var$, ";" TO g_HFILE
            END IF
	ENDIF
    ENDIF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Local(STRING arg$)

    LOCAL var$, type$, new$, value$, dim$
    LOCAL check, i, dim, option

    ' Get the variablename and type
    IF INSTR(arg$, " TYPE ") THEN
	var$ = CHOP$(MID$(arg$, 1, INSTR(arg$, " TYPE ")))
	type$ = CHOP$(MID$(arg$, INSTR(arg$, " TYPE ") + 6))
    ELSE
	var$ = CHOP$(arg$)
	IF INSTR(var$, g_STRINGSIGN$) THEN
	    type$ = "char*"
	ELSE
	    type$ = "long"
	END IF
    END IF

    check = 0

    ' Check if variable was already declared
    IF NOT(INSTR(var$, ".")) THEN
	IF LEN(g_FUNCNAME$) > 0 THEN check = Check_Declared(g_CFILE$, var$, 0)
	ELSE check = Check_Declared(g_HFILE$, var$, g_HEADER_SEARCHPOS)
    END IF

    IF ISTRUE(check) THEN
	PRINT NL$, "ERROR: variable in LOCAL statement at line ", g_COUNTER, " in file '", g_CURFILE$, "' was defined previously!"
	END 1
    END IF

    ' If array, increase dimensions when OPTION BASE is set
    IF REGEX(var$, "\\[.*\\]") AND NOT(INSTR(var$, "=")) THEN
	new$ = ""
	REPEAT
	    new$ = CONCAT$(new$, LEFT$(var$, INSTR(var$, "[") - 1), "[")
	    value$ = MID$(var$, INSTR(var$, "[") + 1)
	    new$ = CONCAT$(new$, MID$(value$, 1, INSTR(value$, "]") - 1), "+", STR$(g_OPTION_BASE), "]")
	    var$ = MID$(var$, INSTR(var$, "]") + 1)
	UNTIL NOT(REGEX(var$, "\\[.*\\]"))
	var$ = new$
    END IF

    ' Check if var is string var
    IF ( REGEX(type$, "STRING|char\\*$") OR INSTR(var$, g_STRINGSIGN$) ) AND NOT(INSTR(var$, "=")) AND NOT(REGEX(type$, ".+\\[.+\\$\\]")) THEN
	check = Search(g_HFILE$, CONCAT$("char *", var$, " = NULL;"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", var$, " = NULL;"), 0)
	ENDIF

	IF check < 0 THEN
	    SPLIT var$ BY "," TO str$ SIZE dim
	    FOR i = 1 TO dim
		' Check on multidimensional stringarrays
		IF REGEX(str$[i], "\\[.*\\]\\[") THEN
		    PRINT NL$, "ERROR: multidimensional stringarrays at line ", g_COUNTER, " in file '", g_CURFILE$, "' are not supported!"
		    END 1
		END IF

		' Are we in a function?
		IF ISTRUE(LEN(g_FUNCNAME$)) THEN
		    IF ISTRUE(LEN(g_RECORDNAME$)) THEN
			IF REGEX(str$[i], "\\[.*\\]") THEN
			    WRITELN "char *", CHOP$(str$[i]), ";" TO g_CFILE
			    dim$ = MID$(str$[i], INSTR(str$[i], "[") + 1)
			    g_STRINGARRAYS$ = CONCAT$(g_STRINGARRAYS$, " for(__b2c__ctr=0; __b2c__ctr<", LEFT$(dim$, INSTR(dim$, "]") - 1), "; __b2c__ctr++)if(", g_RECORDVAR$, ".", LEFT$(str$[i], INSTR(str$[i], "[")-1), "[__b2c__ctr]!=NULL){free(", g_RECORDVAR$, ".", LEFT$(str$[i], INSTR(str$[i], "[")-1), "[__b2c__ctr]);}")
			ELSE
			    WRITELN "char *", CHOP$(str$[i]), "; /* noparse */" TO g_CFILE
			END IF
		    ELSE
			IF REGEX(str$[i], "\\[.*\\]") THEN
			    WRITELN "char *", CHOP$(str$[i]), " = { NULL};" TO g_CFILE
			    dim$ = MID$(str$[i], INSTR(str$[i], "[") + 1)
			    g_STRINGARRAYS$ = CONCAT$(g_STRINGARRAYS$, " for(__b2c__ctr=0; __b2c__ctr<", LEFT$(dim$, INSTR(dim$, "]") - 1), "; __b2c__ctr++)if(", g_WITHVAR$, LEFT$(str$[i], INSTR(str$[i], "[")-1), "[__b2c__ctr]!=NULL){free(", g_WITHVAR$, LEFT$(str$[i], INSTR(str$[i], "[")-1), "[__b2c__ctr]);}")
			ELSE
			    WRITELN "char *", CHOP$(str$[i]), " = NULL;" TO g_CFILE
			    ' Pointer var should not be initialized
			    IF INSTR(var$, g_STRINGSIGN$) THEN
				WRITELN CHOP$(str$[i]), " = calloc(1, sizeof(char));" TO g_CFILE
				g_LOCALSTRINGS$ = CONCAT$(g_LOCALSTRINGS$, " ", CHOP$(str$[i]))
			    END IF
			END IF
		    END IF
		' We are in the mainprogram
		ELSE
		    IF ISTRUE(LEN(g_RECORDNAME$)) THEN
			WRITELN "char *", CHOP$(str$[i]), "; /* noparse */" TO g_HFILE
		    ELSE
			IF REGEX(str$[i], "\\[.*\\]") THEN
			    WRITELN "char *", CHOP$(str$[i]), " = { NULL };" TO g_CFILE
			ELSE
			    WRITELN "char *", CHOP$(str$[i]), " = NULL; " TO g_HFILE
			    ' Pointer var should not be initialized
			    IF INSTR(var$, g_STRINGSIGN$) THEN WRITELN CHOP$(str$[i]), " = calloc(1, sizeof(char));" TO g_CFILE
			END IF
		    END IF
		END IF
	    NEXT
	END IF
    ELIF ( INSTR(var$, g_STRINGSIGN$) OR REGEX(type$, "STRING|char\\*") ) AND INSTR(var$, "=") THEN
	IF ISTRUE(LEN(g_FUNCNAME$)) THEN
            ' String array assignment
            WRITELN "char* ", MID$(var$, 1, INSTR(var$, "{")) TO g_CFILE
            option = g_OPTION_BASE
            WHILE option > 0
                WRITELN " \"\", " TO g_CFILE
                DECR option
            WEND
	    WRITELN MID$(var$, INSTR(var$, "{")+1), ";" TO g_CFILE
        ELSE
            ' String array assignment
            WRITELN "char* ", MID$(var$, 1, INSTR(var$, "{")) TO g_HFILE
            option = g_OPTION_BASE
            WHILE option > 0
                WRITELN " \"\", " TO g_HFILE
                DECR option
            WEND
	    WRITELN MID$(var$, INSTR(var$, "{")+1), ";" TO g_HFILE
        END IF
    ' Assume number
    ELSE
	IF ISTRUE(LEN(g_FUNCNAME$)) THEN
	    IF ISTRUE(LEN(g_RECORDNAME$)) THEN
		WRITELN type$, " ", var$, "; /* noparse */" TO g_CFILE
	    ELSE
		IF INSTR(var$, "[") AND NOT(INSTR(var$, "=")) THEN
		    SPLIT var$ BY "," TO str$ SIZE dim
		    FOR i = 1 TO dim
			WRITELN type$, " ", str$[i], " = { 0 };" TO g_CFILE
		    NEXT
		ELIF INSTR(var$, "[") AND NOT(INSTR(var$, "=")) THEN
                    ' Numeric array assignment
                    WRITELN type$, " ", MID$(var$, 1, INSTR(var$, "{")) TO g_CFILE
                    option = g_OPTION_BASE
                    WHILE option > 0
                        WRITELN " 0, " TO g_CFILE
                        DECR option
                    WEND
	            WRITELN MID$(var$, INSTR(var$, "{")+1), ";" TO g_CFILE
		ELIF NOT(INSTR(var$, "=")) AND NOT(INSTR(var$, "(")) AND REGEX(type$, "char|short|int|long|double|float|NUMBER|FLOATING") THEN
		    WRITELN type$, " ", var$, ";" TO g_CFILE
		    WRITELN REPLACE$(var$, ",", "="), " = 0;" TO g_CFILE
		ELSE
		    WRITELN type$, " ", var$, ";" TO g_CFILE
		END IF
	    END IF
	ELSE
	    IF ISTRUE(LEN(g_RECORDNAME$)) THEN
		WRITELN type$, " ", var$, "; /* noparse */" TO g_HFILE
	    ELSE
		IF INSTR(var$, "[") AND NOT(INSTR(var$, "=")) THEN
		    SPLIT var$ BY "," TO str$ SIZE dim
		    FOR i = 1 TO dim
			WRITELN type$, " ", str$[i], " = { 0 };" TO g_HFILE
		    NEXT
		ELIF INSTR(var$, "[") AND INSTR(var$, "=") THEN
                    ' Numeric array assignment
                    WRITELN type$, " ", MID$(var$, 1, INSTR(var$, "{")) TO g_HFILE
                    option = g_OPTION_BASE
                    WHILE option > 0
                        WRITELN " 0, " TO g_HFILE
                        DECR option
                    WEND
	            WRITELN MID$(var$, INSTR(var$, "{")+1), ";" TO g_HFILE
                ELIF NOT(INSTR(var$, "=")) AND NOT(INSTR(var$, "(")) AND REGEX(type$, "char|short|int|long|double|float|NUMBER|FLOATING") THEN
		    WRITELN type$, " ", var$, ";" TO g_HFILE
		    WRITELN REPLACE$(var$, ",", "="), " = 0;" TO g_CFILE
		ELSE
		    WRITELN type$, " ", var$, ";" TO g_HFILE
                END IF
	    END IF
	END IF
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Read(STRING arg$)

    LOCAL check
    LOCAL type$

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty READ at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check type of var, string?
    IF EQUAL(RIGHT$(arg$, LEN(g_STRINGSIGN$)), g_STRINGSIGN$) THEN
	check = Search(g_HFILE$, CONCAT$("char *", arg$, " = NULL;"), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", arg$, " = NULL;"), 0)
	ENDIF

	IF check < 0 THEN WRITELN "char *", arg$, " = NULL;" TO g_HFILE

	' Convert to C
	WRITELN arg$, " = (char*)realloc(", arg$, ", (strlen(__b2c__stringarray[__b2c__stringarray_ptr])+1)*sizeof(char));" TO g_CFILE
	WRITELN "strcpy(", arg$, ", __b2c__stringarray[__b2c__stringarray_ptr]);" TO g_CFILE
	WRITELN "__b2c__stringarray_ptr++;" TO g_CFILE
    ELSE
	' Variable may not be array, these should be defined with DECLARE
	IF NOT(REGEX(arg$, "\\[.*\\]")) AND NOT(INSTR(arg$, ".")) THEN
	    ' Not declared? Assume long
	    check = Check_Declared(g_HFILE$, arg$, g_HEADER_SEARCHPOS)
	    IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, arg$, 0)

	    IF ISFALSE(check) THEN WRITELN "long ", arg$, ";" TO g_HFILE
	END IF

	' See how var was declared
	type$ = Check_Type$(g_HFILE$, arg$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(LEN(type$)) THEN
	    type$ = Check_Type$(g_CFILE$, arg$, 0)
	END IF

	' Convert to C
	IF INSTR(type$, "double ") OR INSTR(type$, "FLOATING ") THEN
	    WRITELN arg$, " = __b2c__floatarray[__b2c__floatarray_ptr];" TO g_CFILE
	    WRITELN "__b2c__floatarray_ptr++;" TO g_CFILE
	ELIF INSTR(type$, "float ") THEN
	    WRITELN arg$, " = (float)__b2c__floatarray[__b2c__floatarray_ptr];" TO g_CFILE
	    WRITELN "__b2c__floatarray_ptr++;" TO g_CFILE
	ELIF INSTR(type$, "long ") OR INSTR(type$, "NUMBER ") THEN
	    WRITELN arg$, " = __b2c__floatarray[__b2c__floatarray_ptr];" TO g_CFILE
	    WRITELN "__b2c__floatarray_ptr++;" TO g_CFILE
	ELIF INSTR(type$, "int ") THEN
	    WRITELN arg$, " = (int)__b2c__floatarray[__b2c__floatarray_ptr];" TO g_CFILE
	    WRITELN "__b2c__floatarray_ptr++;" TO g_CFILE
	ELSE
	    WRITELN arg$, " = (char*)realloc(", arg$, ", (strlen(__b2c__stringarray[__b2c__stringarray_ptr])+1)*sizeof(char));" TO g_CFILE
	    WRITELN "strcpy(", arg$, ", __b2c__stringarray[__b2c__stringarray_ptr]);" TO g_CFILE
	    WRITELN "__b2c__stringarray_ptr++;" TO g_CFILE
	END IF
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Color(STRING arg$)

    LOCAL dim
    LOCAL BFG$, COL$

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty COLOR at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    SPLIT arg$ BY " " TO element$ SIZE dim

    ' Check if we need to reset
    IF EQUAL(element$[1], "RESET") THEN
	WRITELN "fprintf(stdout,\"\\033[0m\");" TO g_CFILE
    ELIF EQUAL(element$[1], "INTENSE") THEN
	WRITELN "fprintf(stdout,\"\\033[1m\");" TO g_CFILE
    ELIF EQUAL(element$[1], "INVERSE") THEN
	WRITELN "fprintf(stdout,\"\\033[7m\");" TO g_CFILE
    ELIF EQUAL(element$[1], "NORMAL") THEN
	WRITELN "fprintf(stdout,\"\\033[22m\");" TO g_CFILE
    ' Check if TO is available
    ELIF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: Missing TO in COLOR statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    ELSE
	' Get the target and colorname
	SELECT element$[1]
	    CASE "FG"
		BFG$ = "3"
	    CASE "BG"
		BFG$ = "4"
	    DEFAULT
		IF REGEX(element$[1], "0|1") THEN BFG$ = STR$(VAL(element$[1]) + 3)
		ELSE BFG$ = element$[1]
	END SELECT

	SELECT element$[3]
	    CASE "BLACK"
		COL$ = "0"
	    CASE "RED"
		COL$ = "1"
	    CASE "GREEN"
		COL$ = "2"
	    CASE "YELLOW"
		COL$ = "3"
	    CASE "BLUE"
		COL$ = "4"
	    CASE "MAGENTA"
		COL$ = "5"
	    CASE "CYAN"
		COL$ = "6"
	    CASE "WHITE"
		COL$ = "7"
	    DEFAULT
		COL$ = element$[3]
	END SELECT

	' Now select color
	WRITELN "fprintf(stdout,\"\\033[%ld%ldm\", (long)", BFG$, ", (long)", COL$, ");" TO g_CFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Gotoxy(STRING arg$)

    LOCAL dim

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty GOTOXY at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the target and colorname
    SPLIT arg$ BY "," TO element$ SIZE dim

    IF dim EQ 1 THEN
	PRINT NL$, "ERROR: missing coordinate in GOTOXY at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Translate to C
    WRITELN "fprintf(stdout, \"\\033[%ld;%ldH\",(long)(", CHOP$(element$[2]), "), (long)(", CHOP$(element$[1]), ")); fflush(stdout);" TO g_CFILE

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Split(STRING arg$)

    LOCAL source$, rest$, by$, to$, size$
    LOCAL check

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty SPLIT at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if BY is available
    IF NOT(INSTR(arg$, " BY ")) THEN
	PRINT NL$, "ERROR: Missing BY in SPLIT statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if TO is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: Missing TO in SPLIT statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if SIZE is available
    IF NOT(INSTR(arg$, " SIZE ")) THEN
	PRINT NL$, "ERROR: Missing SIZE in SPLIT statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the source string
    source$ = CHOP$(LEFT$(arg$, INSTR(arg$, " BY ") - 1))
    rest$ = MID$(arg$, INSTR(arg$, " BY ") + 4)

    by$ = CHOP$(LEFT$(rest$, INSTR(rest$, " TO ") - 1))
    rest$ = MID$(rest$, INSTR(rest$, " TO ") + 4)

    to$ = CHOP$(LEFT$(rest$, INSTR(rest$, " SIZE ") - 1))
    size$ = CHOP$(MID$(rest$, INSTR(rest$, " SIZE ") + 6))

    ' Variable may not be array, these should be defined with DECLARE
    IF NOT(REGEX(size$, "\\[.*\\]")) AND NOT(INSTR(size$, ".")) THEN
	check = Check_Declared(g_HFILE$, size$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, size$, 0)

	IF ISFALSE(check) THEN WRITELN "long ", size$, ";" TO g_HFILE
    END IF

    ' Translate to C code
    IF ISTRUE(LEN(g_FUNCNAME$)) THEN
	IF NOT(INSTR(g_STRINGARGS$, CONCAT$("**", to$))) THEN
	    g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, " char **", to$, " = NULL; int __b2c__split__", to$, " = ", STR$(g_OPTION_BASE), ";")
	END IF
    ELSE
	check = Search(g_HFILE$, CONCAT$(to$, " = NULL;"), g_HEADER_SEARCHPOS)
	IF check < 0 THEN
	    WRITELN "char **", to$, " = NULL; int __b2c__split__", to$, " = ", g_OPTION_BASE, ";" TO g_HFILE
	END IF
    END IF

    ' If the split array was used before in a loop, clear it
    WRITELN "if(", to$, " != NULL) {for(__b2c__ctr=", g_OPTION_BASE, "; __b2c__ctr<=__b2c__split__", to$, "; __b2c__ctr++) if(", to$, "[__b2c__ctr]!=NULL)" TO g_CFILE
    WRITELN "{free(", to$, "[__b2c__ctr]);} free(", to$, "); ", to$, " = NULL;} __b2c__split__", to$, " = ", g_OPTION_BASE, ";" TO g_CFILE

    ' Run the SPLIT code
    WRITELN "if (", source$, " != NULL && strlen(", source$, ") > 0 && ", by$, " != NULL && strlen(", by$, ")>0){__b2c__split_tmp = strdup(", source$, "); __b2c__split_ptr = __b2c__split_tmp; while((__b2c__split = strstr(__b2c__split_tmp, ", by$, ")) != NULL)" TO g_CFILE
    WRITELN "{if(__b2c__split-__b2c__split_tmp >= 0) {", to$, " = (char **)realloc(", to$, ", (__b2c__split__", to$, " + 1) * sizeof(char*)); if(__b2c__split-__b2c__split_tmp == 0) {", to$, "[__b2c__split__", to$, "] = calloc(1, sizeof(char)); if (__b2c__collapse == 0)" TO g_CFILE
    WRITELN "__b2c__split__", to$, "++; else free(", to$, "[__b2c__split__", to$, "]);} else ", to$, "[__b2c__split__", to$, "++] = __b2c__strndup(__b2c__split_tmp, __b2c__split-__b2c__split_tmp);}" TO g_CFILE
    WRITELN "__b2c__split_tmp = __b2c__split + strlen(", by$, ");} if(strlen(__b2c__split_tmp) >= 0) {", to$, " = (char **)realloc(", to$, ", (__b2c__split__", to$, " + 1) * sizeof(char*)); if(strlen(__b2c__split_tmp) == 0) {" TO g_CFILE
    WRITELN to$, "[__b2c__split__", to$, "] = calloc(1, sizeof(char)); if (__b2c__collapse == 0) __b2c__split__", to$, "++; else free(", to$, "[__b2c__split__", to$, "]);}" TO g_CFILE
    WRITELN "else ", to$, "[__b2c__split__", to$, "++] = strdup(__b2c__split_tmp);} free(__b2c__split_ptr);} ", size$, " = __b2c__split__", to$, " - ", g_OPTION_BASE, "; if(__b2c__split__", to$, " > 0) __b2c__split__", to$, "--;" TO g_CFILE

    ' Add declared array to array list if we are in a function
    IF ISTRUE(LEN(g_FUNCNAME$)) AND NOT(INSTR(g_STRINGARRAYS$, CONCAT$(to$, "["))) THEN
	g_STRINGARRAYS$ = CONCAT$(g_STRINGARRAYS$, " if(", to$, "!= NULL){for(__b2c__ctr=", STR$(g_OPTION_BASE), ";__b2c__ctr<=__b2c__split__", to$, ";__b2c__ctr++) if(", to$, "[__b2c__ctr]!=NULL){free(", to$, "[__b2c__ctr]);}free(", to$, ");}")
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Sort(STRING arg$)

    LOCAL dim$, type$, var$, down$
    LOCAL check

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty SORT at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

     ' Check on SIZE argument
    IF INSTR(arg$, "SIZE") THEN
	dim$ = CHOP$(MID$(arg$, INSTR(arg$, "SIZE") + 5))
	var$ = CHOP$(LEFT$(arg$, INSTR(arg$, "SIZE") - 1))
    ELSE
	var$ = arg$
    END IF

    ' Check on DOWN argument
    IF INSTR(arg$, "DOWN") THEN
	IF LEN(dim$) > 0 THEN dim$ = CHOP$(LEFT$(dim$, INSTR(dim$, "DOWN") - 1))
	var$ = CHOP$(LEFT$(var$, INSTR(var$, "DOWN") - 1))
	down$ = "_down"
    ELSE
	down$ = ""
    END IF

    ' Declared before?
    IF INSTR(var$, g_STRINGSIGN$) THEN
	check = Search(g_HFILE$, CONCAT$("char *", var$, "["), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("char *", var$, "["), 0)
	ENDIF
    ELSE
	check = Check_Declared(g_HFILE$, var$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, var$, 0)
    END IF

    ' Verify if the array was declared at SPLIT
    IF check < 0 THEN
	check = Search(g_HFILE$, CONCAT$("__b2c__split__", var$), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND check < 0 THEN
	    check = Search(g_CFILE$, CONCAT$("__b2c__split__", var$), 0)
	ENDIF
	IF ISFALSE(check) THEN
	    PRINT NL$, "ERROR: argument to SORT not an array at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	    END 1
	ELIF LEN(dim$) IS 0 THEN
	    dim$ = CONCAT$("__b2c__split__", var$, "+1")
	END IF
    ELIF LEN(dim$) IS 0 THEN
	' See how var was declared
	type$ = Check_Type$(g_HFILE$, CONCAT$(var$, "["), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(LEN(type$)) THEN
	    type$ = Check_Type$(g_CFILE$, CONCAT$(var$, "["), 0)
	ENDIF
	dim$ = MID$(type$, INSTR(type$, "[") + 1, INSTR(type$, "]") - INSTR(type$, "[") - 1)
    END IF

    ' Check if we have a string
    IF INSTR(var$, g_STRINGSIGN$) THEN
	WRITELN "qsort(&", var$, "[", g_OPTION_BASE, "], ", dim$, "-", g_OPTION_BASE, ", sizeof(char*), __b2c__sortstr", down$, ");" TO g_CFILE
    ' It is a value
    ELSE
	' See how var was declared
	type$ = Check_Type$(g_HFILE$, CONCAT$(var$, "["), g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(LEN(type$)) THEN type$ = Check_Type$(g_CFILE$, CONCAT$(var$, "["), 0)

	IF INSTR(type$, "double ") OR INSTR(type$, "FLOATING ") THEN
	    WRITELN "qsort(&", var$, "[", g_OPTION_BASE, "], ", dim$, "-", g_OPTION_BASE, ", sizeof(double), __b2c__sortnrd", down$, ");" TO g_CFILE
	ELIF INSTR(type$, "float ") THEN
	    WRITELN "qsort(&", var$, "[", g_OPTION_BASE, "], ", dim$, "-", g_OPTION_BASE, ", sizeof(float), __b2c__sortnrf", down$, ");" TO g_CFILE
	ELIF INSTR(type$, "long ") OR INSTR(type$, "NUMBER ") THEN
	    WRITELN "qsort(&", var$, "[", g_OPTION_BASE, "], ", dim$, "-", g_OPTION_BASE, ", sizeof(long), __b2c__sortnrl", down$, ");" TO g_CFILE
	ELSE
	    WRITELN "qsort(&", var$, "[", g_OPTION_BASE, "], ", dim$, "-", g_OPTION_BASE, ", sizeof(int), __b2c__sortnri", down$, ");" TO g_CFILE
	END IF
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Alias(STRING arg$)

    LOCAL dim

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty ALIAS at at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the target and colorname
    SPLIT REPLACE$(arg$, CHR$(34), "") BY "TO" TO element$ SIZE dim

    IF dim EQ 1 THEN
	PRINT NL$, "ERROR: missing TO in ALIAS statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Translate to C
    WRITELN "#define ", element$[2], " ", element$[1] TO g_HFILE
    g_IMPORTED$ = CONCAT$(element$[2], " ", g_IMPORTED$)

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Lookup(STRING arg$)

    LOCAL source$, rest$, to$, size$
    LOCAL check

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty LOOKUP at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if TO is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: Missing TO in LOOKUP statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if SIZE is available
    IF NOT(INSTR(arg$, " SIZE ")) THEN
	PRINT NL$, "ERROR: Missing SIZE in LOOKUP statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the source string
    source$ = CHOP$(LEFT$(arg$, INSTR(arg$, " TO ") - 1))
    rest$ = MID$(arg$, INSTR(arg$, " TO ") + 4)

    to$ = CHOP$(LEFT$(rest$, INSTR(rest$, " SIZE ") - 1))
    size$ = CHOP$(MID$(rest$, INSTR(rest$, " SIZE ") + 6))

    ' Variable may not be array, these should be defined with DECLARE
    IF NOT(REGEX(size$, "\\[.*\\]")) AND NOT(INSTR(size$, ".")) THEN
	check = Check_Declared(g_HFILE$, size$, g_HEADER_SEARCHPOS)
	IF LEN(g_FUNCNAME$) > 0 AND ISFALSE(check) THEN check = Check_Declared(g_CFILE$, size$, 0)

	IF ISFALSE(check) THEN WRITELN "long ", size$, ";" TO g_HFILE
    END IF

    ' Translate to C code
    IF ISTRUE(LEN(g_FUNCNAME$)) THEN
	IF NOT(INSTR(g_STRINGARGS$, CONCAT$("**", to$))) THEN
	    g_STRINGARGS$ = CONCAT$(g_STRINGARGS$, " char **", to$, " = NULL; int __b2c__split__", to$, " = ", STR$(g_OPTION_BASE), ";")
	END IF
    ELSE
	check = Search(g_HFILE$, CONCAT$(to$, " = NULL;"), g_HEADER_SEARCHPOS)
	IF check < 0 THEN
	    WRITELN "char **", to$, " = NULL; int __b2c__split__", to$, " = ", g_OPTION_BASE, ";" TO g_HFILE
	END IF
    END IF

    ' If the split array was used before in a loop, clear it
    WRITELN "if(", to$, " != NULL) {for(__b2c__ctr=", g_OPTION_BASE, "; __b2c__ctr <= __b2c__split__", to$, "; __b2c__ctr++) if(", to$, "[__b2c__ctr]!=NULL)" TO g_CFILE
    WRITELN "{free(", to$, "[__b2c__ctr]);} free(", to$, "); ", to$, " = NULL;} __b2c__split__", to$, " = ", g_OPTION_BASE, ";" TO g_CFILE

    ' Run the LOOKUP code
    WRITELN "for(__b2c__ctr = ", g_OPTION_BASE, "; __b2c__ctr < __b2c__", source$, "_idx + ", g_OPTION_BASE, "; __b2c__ctr++)" TO g_CFILE
    WRITELN "{", to$, " = (char **)realloc(", to$, ", (__b2c__split__", to$, " + 1) * sizeof(char*));" TO g_CFILE
    WRITELN to$, "[__b2c__split__", to$, "++] = strdup(__b2c__", source$, "[__b2c__ctr-", g_OPTION_BASE, "].key);} ",  size$, " = __b2c__split__", to$, " - ", g_OPTION_BASE, ";if(__b2c__split__", to$, " > 0) __b2c__split__", to$, "--;" TO g_CFILE

    ' Add declared array to array list if we are in a function
    IF ISTRUE(LEN(g_FUNCNAME$)) AND NOT(INSTR(g_STRINGARRAYS$, CONCAT$(to$, "["))) THEN
	g_STRINGARRAYS$ = CONCAT$(g_STRINGARRAYS$, " if(", to$, "!= NULL){for(__b2c__ctr=", STR$(g_OPTION_BASE), ";__b2c__ctr<=__b2c__split__", to$, ";__b2c__ctr++) if(", to$, "[__b2c__ctr]!=NULL){free(", to$, "[__b2c__ctr]);}free(", to$, ");}")
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Relate(STRING arg$)

    LOCAL source$, to$, txt$
    LOCAL declared, dim, i
    LOCAL thefile TYPE FILE*

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty RELATE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Check if TO is available
    IF NOT(INSTR(arg$, " TO ")) THEN
	PRINT NL$, "ERROR: Missing TO in RELATE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Get the source string
    source$ = CHOP$(LEFT$(arg$, INSTR(arg$, " TO ") - 1))
    to$ = CHOP$(MID$(arg$, INSTR(arg$, " TO ") + 4))

    ' CHeck if declared as ASSOC
    OPEN g_HFILE$ FOR READING AS thefile
    SEEK thefile OFFSET g_HEADER_SEARCHPOS

    WHILE NOT(ENDFILE(thefile)) DO
	READLN txt$ FROM thefile
        IF NOT(ENDFILE(thefile)) AND LEN(txt$) > 0 AND NOT(INSTR(txt$, " noparse ")) THEN
            declared = REGEX(txt$, CONCAT$("__b2c__", source$, "_type"))
	    IF ISTRUE(declared) THEN BREAK
	END IF
    WEND
    IF NOT(declared) THEN
	PRINT NL$, "ERROR: Variable ", source$, " not declared in RELATE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Assign relations
    SPLIT to$ BY "," TO str$ SIZE dim

    FOR i = 1 TO dim

	SEEK thefile OFFSET g_HEADER_SEARCHPOS
	WHILE NOT(ENDFILE(thefile)) DO
	    READLN txt$ FROM thefile
	    IF NOT(ENDFILE(thefile)) AND LEN(txt$) > 0 AND NOT(INSTR(txt$, " noparse ")) THEN
		declared = REGEX(txt$, CONCAT$("__b2c__", CHOP$(str$[i]), "_type"))
		IF ISTRUE(declared) THEN BREAK
	    END IF
	WEND
	IF NOT(declared) THEN
	    PRINT NL$, "ERROR: Variable ", CHOP$(str$[i]), " not declared in RELATE statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	    END 1
	END IF

	g_RELATE$[g_RELATE_CTR] = CONCAT$(source$, " ", CHOP$(str$[i]))
	INCR g_RELATE_CTR

    NEXT

    CLOSE FILE thefile

END SUB

'----------------------------------------------------------------------------------------------

SUB Handle_Data(STRING arg$)

    LOCAL in_string, pos, escaped, x

    ' Check if we have an argument at all
    IF ISFALSE(LEN(CHOP$(arg$))) THEN
	PRINT NL$, "ERROR: empty DATA at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
	END 1
    END IF

    ' Start miniparser
    in_string = FALSE
    pos = 1
    escaped = 0

    FOR x = 1 TO LEN(arg$)
	IF ISTRUE(EQUAL(MID$(arg$, x, 1), ",")) THEN
	    IF ISFALSE(in_string) THEN
		IF INSTR(MID$(arg$, pos, x-pos), CHR$(34)) THEN
		    WRITELN MID$(arg$, pos, x-pos), ", " TO STRINGARRAYFILE
		ELSE
		    WRITELN MID$(arg$, pos, x-pos), ", " TO FLOATARRAYFILE
		END IF
		pos = x+1
		escaped = FALSE
	    END IF
	ELIF EQUAL(MID$(arg$, x, 1), "\\") THEN
	    escaped = TRUE
	ELIF ISTRUE(EQUAL(MID$(arg$, x, 1), CHR$(34))) THEN
	    IF ISFALSE(escaped) THEN
		in_string = NOT(in_string)
	    END IF
	    escaped = FALSE
	ELSE
	    escaped = FALSE
	ENDIF
    NEXT
    arg$ = MID$(arg$, pos)

    ' Write last element to file
    IF INSTR(arg$, CHR$(34)) THEN
	WRITELN arg$, ", " TO STRINGARRAYFILE
    ELSE
	WRITELN arg$, ", " TO FLOATARRAYFILE
    END IF

END SUB

'----------------------------------------------------------------------------------------------
'
' Simple parser to tokenize line.
'
' Each line should begin with a statement.
' The rest of the line may contain functions, these are
'   converted using C macros.
'
'----------------------------------------------------------------------------------------------

SUB Parse_Line(STRING statement$)

    LOCAL inc$, copy_curfile$, total$, txt$, exp$
    LOCAL dim, i, found, copy_counter, to_parse, size
    LOCAL newfile TYPE FILE*

    SPLIT statement$ BY " " TO element$ SIZE dim

    IF dim > 0 THEN

	' Check if enclosed IF/ELIF/ELSE needs to be closed
	IF g_IF_PARSE IS 1 THEN
	    IF NOT(EQUAL(element$[1], "ELIF")) AND NOT(EQUAL(element$[1], "ELSE")) THEN
		WRITELN "}" TO g_CFILE
		g_IF_PARSE = 0
	    END IF
	END IF

	' In TRACE MODE show linenr and code
	IF g_TRACE IS 1 AND NOT(INSTR(statement$, "FUNCTION ")) AND NOT(INSTR(statement$, "SUB ")) THEN
	    WRITELN "if(__b2c__getch() == 27) exit(EXIT_SUCCESS); /* noparse */" TO g_CFILE
	    txt$ = REPLACE$(statement$, CHR$(34), "'")
	    WRITELN "fprintf(stderr, \"", g_CURFILE$, " %d: ", txt$, "\\n\", ", g_COUNTER, "); /* noparse */" TO g_CFILE
	END IF

	' See if we need to pass C code
	IF ISTRUE(g_USE_C) THEN
	    IF EQUAL(LEFT$(statement$, 8), "END USEC") OR EQUAL(element$[1], "ENDUSEC") THEN
		g_USE_C = 0
	    ELSE
		WRITELN statement$ TO g_CFILE
	    END IF

	ELIF EQUAL(LEFT$(element$[1], 2), "#!") THEN
	    'Do nothing

	ELIF EQUAL(LEFT$(element$[1], 1), "'") THEN
	    'Do nothing

	ELIF EQUAL(LEFT$(element$[1], 3), "REM") THEN
	    'Do nothing

	ELSE
	    SELECT element$[1]
		CASE "USEC"
		    g_USE_C = 1

		CASE "PRINT"
		    Handle_Print(MID$(statement$, INSTR(statement$, "PRINT") + 5))

		CASE "INPUT"
		    Handle_Input(MID$(statement$, INSTR(statement$, "INPUT") + 5))

		CASE "FOR"
                    INCR g_LOOPCTR
		    Handle_For(MID$(statement$, INSTR(statement$, "FOR") + 3))

		CASE "NEXT"
		    WRITELN "}" TO g_CFILE
                    IF g_LOOPCTR > 0 THEN
                        DECR g_LOOPCTR
                        IF g_LOOPCTR > 0 THEN
                            WRITELN "if(__b2c__break_ctr) {__b2c__break_ctr--; if (!__b2c__break_ctr){if(__b2c__break_flag == 1) break; else continue;} else break; }" TO g_CFILE
                        END IF
                    END IF

		CASE "IF"
		    ' Check if THEN is available
		    g_IF_PARSE = 0
		    IF ISFALSE(INSTRREV(statement$, " THEN")) THEN
			PRINT NL$, "ERROR: missing THEN in IF statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE			
			' Translate function to C function
                        exp$ = Parse_Equation$(MID$(statement$, INSTR(statement$, "IF") + 2, INSTRREV(statement$, " THEN") - (INSTR(statement$, "IF") + 2)))
			WRITELN "if(", exp$, "){" TO g_CFILE
			IF LEN(CHOP$(MID$(statement$, INSTRREV(statement$, " THEN") + 5))) > 0 THEN
			    CALL Tokenize(MID$(statement$, INSTRREV(statement$, " THEN") + 5))
			    g_IF_PARSE = 1
			END IF
		    ENDIF

		CASE "ELIF"
		    ' Check if THEN is available
		    g_IF_PARSE = 0
		    IF ISFALSE(INSTRREV(statement$, " THEN")) THEN
			PRINT NL$, "ERROR: missing THEN in ELIF statement at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Translate function to C function
                        exp$ = Parse_Equation$(MID$(statement$, INSTR(statement$, "ELIF") + 4, INSTRREV(statement$, " THEN") - (INSTR(statement$, "ELIF") + 4)))
			WRITELN "} else if(", exp$, "){" TO g_CFILE
			IF LEN(CHOP$(MID$(statement$, INSTRREV(statement$, " THEN") + 5))) > 0 THEN
			    CALL Tokenize(MID$(statement$, INSTRREV(statement$, " THEN") + 5))
			    g_IF_PARSE = 1
			END IF
		    END IF

		CASE "ELSE"
		    ' Translate function to C function
		    g_IF_PARSE = 0
		    WRITELN "} else {" TO g_CFILE
		    IF LEN(CHOP$(MID$(statement$, INSTR(statement$, " ELSE") + 5))) > 0 THEN
			CALL Tokenize(MID$(statement$, INSTR(statement$, " ELSE") + 5))
			g_IF_PARSE = 1
		    END IF

		CASE "ENDIF"
		    WRITELN "}" TO g_CFILE

		CASE "WHILE"
                    INCR g_LOOPCTR
		    Handle_While(MID$(statement$, INSTR(statement$, "WHILE") + 5))

		CASE "WEND"
		    WRITELN "}" TO g_CFILE
                    IF g_LOOPCTR > 0 THEN
                        DECR g_LOOPCTR
                        IF g_LOOPCTR > 0 THEN
                            WRITELN "if(__b2c__break_ctr) {__b2c__break_ctr--; if (!__b2c__break_ctr){if(__b2c__break_flag == 1) break; else continue;} else break; }" TO g_CFILE
                        END IF
                    END IF

		CASE "BREAK"
                    ' Check argument
		    IF dim > 1 AND VAL(MID$(statement$, INSTR(statement$, "BREAK") + 5)) NE 0 THEN
                         WRITELN "__b2c__break_ctr = ", MID$(statement$, INSTR(statement$, "BREAK") + 5), "-1; __b2c__break_flag = 1;" TO g_CFILE
                    END IF

		    WRITELN "break;" TO g_CFILE

		CASE "CONTINUE"
                    ' Check argument
		    IF dim > 1 AND VAL(MID$(statement$, INSTR(statement$, "CONTINUE") + 8)) NE 0 THEN
                         WRITELN "__b2c__break_ctr = ", MID$(statement$, INSTR(statement$, "CONTINUE") + 8), "-1; __b2c__break_flag = 2;" TO g_CFILE
                    END IF
                    IF VAL(MID$(statement$, INSTR(statement$, "CONTINUE") + 8)) > 1 THEN
		        WRITELN "break;" TO g_CFILE
                    ELSE
		        WRITELN "continue;" TO g_CFILE
                    END IF

		CASE "REPEAT"
                    INCR g_LOOPCTR
		    WRITELN "do{" TO g_CFILE

		CASE  "UNTIL"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty UNTIL at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Convert to legal C code
                        exp$ = Parse_Equation$(MID$(statement$, INSTR(statement$, "UNTIL") + 5) )
			WRITELN "} while(!(", exp$, "));" TO g_CFILE
                        IF g_LOOPCTR > 0 THEN
                            DECR g_LOOPCTR
                            IF g_LOOPCTR > 0 THEN
                                WRITELN "if(__b2c__break_ctr) {__b2c__break_ctr--; if (!__b2c__break_ctr){if(__b2c__break_flag == 1) break; else continue;} else break; }" TO g_CFILE
                            END IF
                        END IF
		    END IF

		CASE "LET"
		    Handle_Let(MID$(statement$, INSTR(statement$, "LET") + 3))

		CASE "SYSTEM"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty SYSTEM at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			WRITELN "SYSTEM (", MID$(statement$, INSTR(statement$, "SYSTEM") + 6), ");" TO g_CFILE
		    END IF

		CASE "SLEEP"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty SLEEP at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			WRITELN "usleep(", MID$(statement$, INSTR(statement$, "SLEEP") + 5), "*1000);" TO g_CFILE
		    END IF

		CASE "OPEN"
		    Handle_Open(MID$(statement$, INSTR(statement$, "OPEN") + 4))

		CASE "CLOSE"
		    ' Check argument
		    IF dim NE 3 THEN
			PRINT NL$, "ERROR: erroneous CLOSE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			SELECT element$[2]
			    CASE "FILE"
				WRITELN "fclose(", element$[3], ");" TO g_CFILE
			    CASE "DIRECTORY"
				WRITELN "closedir(", element$[3], ");" TO g_CFILE
			    CASE "MEMORY"
				WRITELN element$[3], " = NULL;" TO g_CFILE
			    CASE "NETWORK";
			    CASE "SERVER"
				WRITELN "close(", element$[3], ");" TO g_CFILE
			END SELECT
		    END IF

		CASE "REWIND"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty REWIND at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			WRITELN "rewind(", element$[2], ");" TO g_CFILE
		    END IF

		CASE "MEMREWIND"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty MEMREWIND at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			WRITELN element$[2], " = (char*)__b2c_mem_", element$[2], ";" TO g_CFILE
		    END IF

		CASE "SEEK"
		    Handle_Seek(CHOP$(MID$(statement$, INSTR(statement$, "SEEK") + 4)))

		CASE "READLN"
		    Handle_Readln(CHOP$(MID$(statement$, INSTR(statement$, "READLN") + 6)))

		CASE "WRITELN"
		    Handle_Writeln(MID$(statement$, INSTR(statement$, "WRITELN") + 7))

		CASE "GETBYTE"
		    Handle_Getbyte(CHOP$(MID$(statement$, INSTR(statement$, "GETBYTE") + 7)))

		CASE "PUTBYTE"
		    Handle_Putbyte(CHOP$(MID$(statement$, INSTR(statement$, "PUTBYTE") + 7)))

		CASE "GETFILE"
		    Handle_Getfile(CHOP$(MID$(statement$, INSTR(statement$, "GETFILE") + 7)))

		CASE "GETLINE"
		    Handle_Getline(CHOP$(MID$(statement$, INSTR(statement$, "GETLINE") + 7)))

		CASE "PUTLINE"
		    Handle_Putline(MID$(statement$, INSTR(statement$, "PUTLINE") + 7))

		CASE "END"
		    IF dim > 1 THEN
			SELECT element$[2]
			    CASE "IF"
				WRITELN "}" TO g_CFILE
			    CASE "RECORD"
				IF LEN(g_FUNCNAME$) > 0 THEN
				    WRITELN "};" TO g_CFILE
				    WRITELN "struct ", g_RECORDNAME$, " ", g_RECORDVAR$, " = { } ;" TO g_CFILE
				ELSE
				    WRITELN "};" TO g_HFILE
				    WRITELN "struct ", g_RECORDNAME$, " ", g_RECORDVAR$, " = { } ;" TO g_HFILE
				END IF
				g_RECORDNAME$ = ""
				g_RECORDVAR$ = ""
				' Restore function name if GLOBAL was used
				IF LEN(g_RECORDCACHE$) > 0 THEN
				    g_FUNCNAME$ = g_RECORDCACHE$
				    g_RECORDCACHE$ = ""
				ENDIF
			    CASE "FUNCTION"
				Handle_Endfunction
			    CASE "SUB"
				Handle_Endsub
			    CASE "WITH"
				g_WITHVAR$ = ""
			    CASE "SELECT"
				IF g_SELECTVAR_CTR IS 0 THEN
				    PRINT NL$, "ERROR: invalid END SELECT at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
				    END 1
				ELSE
				    WRITELN "}" TO g_CFILE
				    g_SELECTVAR$[g_SELECTVAR_CTR] = ""
				    g_IN_CASE[g_SELECTVAR_CTR] = 0
				    g_CASE_FALL$ = ""
				    DECR g_SELECTVAR_CTR
				END IF
			    DEFAULT
				WRITELN "exit(", element$[2], ");" TO g_CFILE
			END SELECT
		    ELSE
			WRITELN "exit(EXIT_SUCCESS);" TO g_CFILE
		    END IF

		CASE "SUB"
		    Handle_SubFunc(MID$(statement$, INSTR(statement$, "SUB") + 3))

		CASE "ENDSUB"
		    Handle_Endsub

		CASE "ENDWITH"
		    g_WITHVAR$ = ""

		CASE "ENDSELECT"
		    IF g_SELECTVAR_CTR IS 0 THEN
			PRINT NL$, "ERROR: invalid END SELECT at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			WRITELN "}" TO g_CFILE
			g_SELECTVAR$[g_SELECTVAR_CTR] = ""
			g_IN_CASE[g_SELECTVAR_CTR] = 0
			g_CASE_FALL$ = ""
			DECR g_SELECTVAR_CTR
		    END IF

		CASE "CALL"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty CALL at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			exp$ = MID$(statement$, INSTR(statement$, "CALL ") + 5)
			IF INSTR(statement$, " TO ") THEN
			    IF INSTR(MID$(exp$, INSTR(exp$, " TO ") + 4), g_STRINGSIGN$) THEN
				WRITELN MID$(exp$, INSTR(exp$, " TO ") + 4), " = realloc(", MID$(exp$, INSTR(exp$, " TO ") + 4), ", (strlen(", MID$(exp$, 1, INSTR(exp$, " TO ") - 1), ")+1)*sizeof(char));" TO g_CFILE
				WRITELN "strcpy(", MID$(exp$, INSTR(exp$, " TO ") + 4), "," TO g_CFILE
			    ELSE
				WRITELN MID$(exp$, INSTR(exp$, " TO") + 3), "=" TO g_CFILE
			    END IF
			    IF INSTR(exp$, "(") THEN
				WRITELN MID$(exp$, 1, INSTR(exp$, " TO ") - 1) TO g_CFILE
			    ELSE
				WRITELN MID$(exp$, 1, INSTR(exp$, " TO ") - 1), "()" TO g_CFILE
			    END IF
			    IF INSTR(MID$(exp$, INSTR(exp$, " TO ") + 4), g_STRINGSIGN$) THEN
				WRITELN ");" TO g_CFILE
			    ELSE
				WRITELN ";" TO g_CFILE
			    END IF
			ELSE
			    IF INSTR(exp$, "(") THEN
				WRITELN exp$, ";" TO g_CFILE
			    ELSE
				WRITELN exp$, "();" TO g_CFILE
			    END IF
			END IF
		    END IF

		CASE "FUNCTION"
		    Handle_SubFunc(MID$(statement$, INSTR(statement$, "FUNCTION") + 8))

		CASE "ENDFUNCTION"
		    Handle_Endfunction

		CASE "RETURN"
		    Handle_Return(MID$(statement$, INSTR(statement$, "RETURN") + 6))

		CASE "IMPORT"
		    Handle_Import(MID$(statement$, INSTR(statement$, "IMPORT") + 6))

		CASE "DECLARE"
		    Handle_Declare(MID$(statement$, INSTR(statement$, "DECLARE") + 7))

		CASE "GLOBAL"
		    Handle_Declare(MID$(statement$, INSTR(statement$, "GLOBAL") + 6))

		CASE "LOCAL"
		    Handle_Local(MID$(statement$, INSTR(statement$, "LOCAL") + 5))

		CASE "DATA"
		    Handle_Data(MID$(statement$, INSTR(statement$, "DATA") + 4))

		CASE "RESTORE"
		    WRITELN "if(__b2c__floatarray_ptr > 0) __b2c__floatarray_ptr = 0;" TO g_CFILE
		    WRITELN "if(__b2c__stringarray_ptr > 0) __b2c__stringarray_ptr = 0;" TO g_CFILE

		CASE "READ"
		    Handle_Read(CHOP$(MID$(statement$, INSTR(statement$, "READ") + 4)))

		CASE "PUSH"
		    Handle_Push(CHOP$(MID$(statement$, INSTR(statement$, "PUSH") + 4)))

		CASE "PULL"
		    Handle_Pull(CHOP$(MID$(statement$, INSTR(statement$, "PULL") + 4)))

		CASE "SEED"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty DATA at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			WRITELN "srandom((unsigned int)", element$[2], ");" TO g_CFILE
		    END IF

		CASE "DEF"
		    Handle_Deffn(CHOP$(MID$(statement$, INSTR(statement$, "DEF") + 3)))

		CASE "CONST"
		    Handle_Const(CHOP$(MID$(statement$, INSTR(statement$, "CONST") + 5)))

		CASE "INCLUDE"
		    ' Get rid of doublequotes if they are there
		    inc$ = REPLACE$((CHOP$(MID$(statement$, INSTR(statement$, " ") + 1))), CHR$(34), "")
		    ' See if there are arguments
		    IF INSTR(inc$, ",") THEN
			SPLIT MID$(inc$, INSTR(inc$, ",")+1) BY "," TO element$ SIZE size
			FOR i = 1 TO size
			    element$[i] = REPLACE$(element$[i], g_STRINGSIGN$, "")
			NEXT
			inc$ = MID$(inc$, 1, INSTR(inc$, ",")-1)
		    ELSE
			to_parse = 2
		    END IF

		    ' Check argument
		    IF NOT(FILEEXISTS(inc$)) OR dim EQ 1 OR FILETYPE(inc$) != 1 THEN
			PRINT NL$, "ERROR: missing file '", inc$, "' for INCLUDE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Start walking through program
			copy_counter = g_COUNTER
			g_COUNTER = 1
			' Assign new file
			copy_curfile$ = g_CURFILE$
			' Get rid of absolute path
			g_CURFILE$ = MID$(inc$, INSTRREV(inc$, "/") + 1)
			OPEN inc$ FOR READING AS newfile

			WHILE NOT(ENDFILE(newfile)) DO
			    PRINT "\rStarting conversion... ", g_COUNTER, " ";
			    READLN txt$ FROM newfile
			    ' See if we need to enable flag
			    IF size > 0 THEN
				FOR i = 1 TO size
				    IF ( to_parse = 0 AND REGEX(CHOP$(MID$(txt$, INSTR(txt$, " "))), CONCAT$("^", CHOP$(element$[i]))) AND REGEX(txt$, "SUB|FUNCTION") ) OR REGEX(txt$, "INCLUDE$") THEN
					to_parse = 1
					BREAK
				    END IF
				NEXT
			    END IF
			    ' Line is not empty?
			    IF NOT(ENDFILE(newfile)) AND LEN(txt$) > 0 AND to_parse > 0 THEN
				IF EQUAL(RIGHT$(txt$, 2), CONCAT$(" ", CHR$(92))) AND NOT(EQUAL(LEFT$(txt$, 3), "REM")) AND NOT(EQUAL(LEFT$(txt$, 1), CHR$(39))) THEN
				    total$ = CONCAT$(total$, LEFT$(txt$, LEN(txt$)-2))
				ELSE
				    WRITELN "/* noparse ", inc$, " BACON LINE ", g_COUNTER, " */" TO g_HFILE
				    WRITELN "/* noparse ", inc$, " BACON LINE ", g_COUNTER, " */" TO g_CFILE
				    total$ = CHOP$(CONCAT$(total$, txt$))
				    IF NOT(EQUAL(LEFT$(total$, 3), "REM")) AND NOT(EQUAL( LEFT$(total$, 1), CHR$(39) )) THEN
					CALL Tokenize(total$)
				    END IF
				    LET total$ = ""
				END IF
			    ENDIF
			    ' See if we need to stop parsing
			    IF to_parse = 1 AND INSTR(txt$, "END") AND REGEX(txt$, "SUB|FUNCTION") THEN to_parse = 0
			    ' Increase line number
			    INCR g_COUNTER
			WEND
			CLOSE FILE newfile

			' Restore original counter
			g_COUNTER = copy_counter
			' Restore original file
			g_CURFILE$ = copy_curfile$
		    END IF

		CASE "POKE"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty POKE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			exp$ = MID$(statement$, INSTR(statement$, "POKE") + 4)
			WRITELN "if (!__b2c__trap){__b2c__memory__check((char*)", MID$(exp$, 1, INSTR(exp$, ",")-1), "); if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} }" TO g_CFILE
			WRITELN "*(", g_OPTION_MEMTYPE$, "*)(", MID$(exp$, 1, INSTR(exp$, ",")-1), ") = ( ", g_OPTION_MEMTYPE$, ")", MID$(exp$, INSTR(exp$, ",")+1), ";" TO g_CFILE
		    END IF

		CASE "RESIZE"
		   ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty RESIZE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Resolve this with C macro because of casting to (char)
			exp$ = MID$(statement$, INSTR(statement$, "RESIZE") + 6)
			WRITELN MID$(exp$, 1, INSTR(exp$, ",") - 1), " = (long)RESIZE(", exp$, ");" TO g_CFILE
		    END IF

		CASE "COPY"
		    Handle_Copy(MID$(statement$, INSTR(statement$, "COPY") + 4))

		CASE "DELETE"
		   ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty DELETE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Translate to C function
			IF EQUAL(element$[2], "FILE") THEN
			    WRITELN "if (unlink(", MID$(statement$, INSTR(statement$, " FILE ") + 6), ")==-1){if(!__b2c__trap){ERROR = 7;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
			ELIF EQUAL(element$[2], "DIRECTORY") THEN
			    WRITELN "if (rmdir(", MID$(statement$, INSTR(statement$, " DIRECTORY ") + 11), ") == -1){if(!__b2c__trap){ERROR = 20;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
			ELSE
			    PRINT NL$, "ERROR: erronuous argument for DELETE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			    END 1
			END IF
		    END IF

		CASE "RENAME"
		    Handle_Rename(MID$(statement$, INSTR(statement$, "RENAME") + 6))

		CASE "MAKEDIR"
		   ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty MAKEDIR at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Translate to C function
			WRITELN "if(__b2c__makedir(", MID$(statement$, INSTR(statement$, "MAKEDIR") + 7), ") != 0){if(!__b2c__trap){ERROR = 21;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
		    END IF

		CASE "CHANGEDIR"
		   ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty CHANGEDIR at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Translate to C function
			WRITELN "if(chdir(", MID$(statement$, INSTR(statement$, "CHANGEDIR") + 9), ") == -1){if(!__b2c__trap) {ERROR = 22;if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
		    END IF

		CASE "FREE"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty FREE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Translate to C function
			IF REGEX(element$[2], "\\(.*\\)") THEN
			    exp$ = MID$(element$[2], INSTR(element$[2], " ")+1)
			    IF INSTR(exp$, g_STRINGSIGN$) THEN
				WRITELN "if(__b2c__", MID$(exp$, 1, INSTR(exp$, "(")-1), "_exist(", MID$(element$[2], INSTR(element$[2], "(")+1)," != NULL) {free(__b2c__", MID$(exp$, 1, INSTR(exp$, "(")-1), "_exist(", MID$(element$[2], INSTR(element$[2], "(")+1), "->value);" TO g_CFILE
				WRITELN " __b2c__", MID$(exp$, 1, INSTR(exp$, "(")-1), "_exist(", MID$(element$[2], INSTR(element$[2], "(")+1), "->value = NULL; __b2c__", MID$(exp$, 1, INSTR(exp$, "(")-1), "__del(", MID$(element$[2], INSTR(element$[2], "(")+1), "; }" TO g_CFILE
			    ELSE
				WRITELN "if(__b2c__", MID$(exp$, 1, INSTR(exp$, "(")-1), "_exist(", MID$(element$[2], INSTR(element$[2], "(")+1)," != NULL) {__b2c__", MID$(exp$, 1, INSTR(exp$, "(")-1), "_exist(", MID$(element$[2], INSTR(element$[2], "(")+1), "->value = 0;" TO g_CFILE
				WRITELN "__b2c__", MID$(exp$, 1, INSTR(exp$, "(")-1), "__del(", MID$(element$[2], INSTR(element$[2], "(")+1), ";}" TO g_CFILE
			    ENDIF
			ELSE
			    WRITELN "if(!__b2c__trap){__b2c__memory__check((char *)", element$[2], ");" TO g_CFILE
			    WRITELN "if(ERROR) {if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} } free((void*)", element$[2], ");" TO g_CFILE
			END IF
		    END IF

		CASE "GOTO"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty GOTO at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Translate to C label
			WRITELN "goto ", element$[2], ";" TO g_CFILE
		    END IF

		CASE "LABEL"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty LABEL at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Translate to C label
			WRITELN element$[2], ":" TO g_CFILE
			WRITELN ";" TO g_CFILE
		    END IF

		CASE "TRAP"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty TRAP at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			IF EQUAL(element$[2], "SYSTEM") THEN
			    WRITELN "/* Error catching is enabled */" TO g_CFILE
			    WRITELN "__b2c__trap = 1;" TO g_CFILE
			    WRITELN "signal(SIGILL, __b2c__catch_signal);" TO g_CFILE
			    WRITELN "signal(SIGABRT, __b2c__catch_signal);" TO g_CFILE
			    WRITELN "signal(SIGFPE, __b2c__catch_signal);" TO g_CFILE
			    WRITELN "signal(SIGSEGV, __b2c__catch_signal);" TO g_CFILE
			ELIF EQUAL(element$[2], "LOCAL") THEN
			    WRITELN "/* Error catching is disabled */" TO g_CFILE
			    WRITELN "__b2c__trap = 0;" TO g_CFILE
			    WRITELN "signal(SIGILL, SIG_DFL);" TO g_CFILE
			    WRITELN "signal(SIGABRT, SIG_DFL);" TO g_CFILE
			    WRITELN "signal(SIGFPE, SIG_DFL);" TO g_CFILE
			    WRITELN "signal(SIGSEGV, SIG_DFL);" TO g_CFILE
			ELSE
			    PRINT NL$, "ERROR: invalid argument for TRAP at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			    END 1
			END IF
		    END IF

		CASE "CATCH"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty CATCH at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELIF EQUAL(element$[2], "GOTO") THEN
			WRITELN "__b2c__catch_set = 1;" TO g_CFILE
			g_CATCHGOTO$ = element$[3]
		    ELIF EQUAL(element$[2], "RESET") THEN
			WRITELN "__b2c__catch_set = 0;" TO g_CFILE
			g_CATCHGOTO$ = "__B2C__PROGRAM__EXIT"
		    ELSE
			PRINT NL$, "ERROR: CATCH without GOTO or RESET at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    END IF

		CASE "RESUME"
		    WRITELN "longjmp(__b2c__jump, 1);" TO g_CFILE

		CASE "CLEAR"
		    WRITELN "fprintf(stdout,\"\\033[2J\"); fprintf(stdout,\"\\033[0;0f\");fflush(stdout);" TO g_CFILE

		CASE "COLOR"
		    Handle_Color(CHOP$(MID$(statement$, INSTR(statement$, "COLOR") + 5)))

		CASE "GOTOXY"
		    Handle_Gotoxy(CHOP$(MID$(statement$, INSTR(statement$, "GOTOXY") + 6)))

		CASE "RECEIVE"
		    Handle_Receive(CHOP$(MID$(statement$, INSTR(statement$, "RECEIVE") + 7)))

		CASE "SEND"
		    Handle_Send(MID$(statement$, INSTR(statement$, "SEND") + 4))

		CASE "RECORD"
		   ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty RECORD at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELIF ISTRUE(LEN(g_RECORDNAME$)) THEN
			PRINT NL$, "ERROR: cannot define a record within a record!"
			END 1
		    ELSE
			' Translate to C typedef struct
			IF ISTRUE(LEN(g_FUNCNAME$)) THEN
			    g_RECORDNAME$ = CONCAT$("RECORD_", g_FUNCNAME$, "_", STR$(g_COUNTER))
			    WRITELN "struct ", g_RECORDNAME$, "{" TO g_CFILE
			ELSE
			    g_RECORDNAME$ = CONCAT$("RECORD_", STR$(g_COUNTER))
			    WRITELN "struct ", g_RECORDNAME$, "{" TO g_HFILE
			END IF
			g_RECORDVAR$ = element$[2]
		    END IF

		CASE "WITH"
		   ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty WITH at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELIF ISTRUE(LEN(g_RECORDNAME$)) THEN
			PRINT NL$, "ERROR: cannot define a WITH within a WITH!"
			END 1
		    ELSE
			g_WITHVAR$ = element$[2]
		    END IF

		CASE "SPLIT"
		    Handle_Split(MID$(statement$, INSTR(statement$, "SPLIT") + 5))

		CASE "SELECT"
		   ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty SELECT at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			INCR g_SELECTVAR_CTR
			g_SELECTVAR$[g_SELECTVAR_CTR] = MID$(statement$, INSTR(statement$, "SELECT") + 6)
			g_IN_CASE[g_SELECTVAR_CTR] = 0
			g_CASE_FALL$ = ""
		    END IF

		CASE "CASE"
		   ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty CASE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			IF ISTRUE(g_IN_CASE[g_SELECTVAR_CTR]) THEN
			    IF INSTR(g_SELECTVAR$[g_SELECTVAR_CTR], g_STRINGSIGN$) THEN
				IF EQUAL(RIGHT$(statement$, 1), ";") THEN
				    exp$ = MID$(statement$, INSTR(statement$, "CASE") + 4)
				    g_CASE_FALL$ = CONCAT$("|| !strcmp(", g_SELECTVAR$[g_SELECTVAR_CTR], ", ", LEFT$(exp$, LEN(exp$)-1), ") ", g_CASE_FALL$)
				ELSE
				    WRITELN "} else if (!strcmp(", g_SELECTVAR$[g_SELECTVAR_CTR], ", ", MID$(statement$, INSTR(statement$, "CASE") + 4), ") ", g_CASE_FALL$, "){" TO g_CFILE
				    g_CASE_FALL$ = ""
				END IF
			    ELSE
				IF EQUAL(RIGHT$(statement$, 1), ";") THEN
				    exp$ = MID$(statement$, INSTR(statement$, "CASE") + 4)
				    g_CASE_FALL$ = CONCAT$("|| ", g_SELECTVAR$[g_SELECTVAR_CTR], " == (", LEFT$(exp$, LEN(exp$)-1), ")", g_CASE_FALL$)
				ELSE
				    WRITELN "} else if (", g_SELECTVAR$[g_SELECTVAR_CTR], " == (", MID$(statement$, INSTR(statement$, "CASE") + 4), ") ", g_CASE_FALL$, "){" TO g_CFILE
				    g_CASE_FALL$ = ""
				END IF
			    END IF
			ELSE
			    IF INSTR(g_SELECTVAR$[g_SELECTVAR_CTR], g_STRINGSIGN$) THEN
				IF EQUAL(RIGHT$(statement$, 1), ";") THEN
				    exp$ = MID$(statement$, INSTR(statement$, "CASE") + 4)
				    g_CASE_FALL$ = CONCAT$("|| !strcmp(", g_SELECTVAR$[g_SELECTVAR_CTR], ", ", LEFT$(exp$, LEN(exp$)-1), ") ", g_CASE_FALL$)
				ELSE
				    WRITELN "if (!strcmp(", g_SELECTVAR$[g_SELECTVAR_CTR], ", ", MID$(statement$, INSTR(statement$, "CASE") + 4),") ", g_CASE_FALL$, "){" TO g_CFILE
				    g_IN_CASE[g_SELECTVAR_CTR] = 1
				    g_CASE_FALL$ = ""
				END IF
			    ELSE
				IF EQUAL(RIGHT$(statement$, 1), ";") THEN
				    exp$ = MID$(statement$, INSTR(statement$, "CASE") + 4)
				    g_CASE_FALL$ = CONCAT$("|| ", g_SELECTVAR$[g_SELECTVAR_CTR], " == (", LEFT$(exp$, LEN(exp$)-1), ")", g_CASE_FALL$)
				ELSE
				    WRITELN "if (", g_SELECTVAR$[g_SELECTVAR_CTR], " == (", MID$(statement$, INSTR(statement$, "CASE") + 4), ") ", g_CASE_FALL$, "){" TO g_CFILE
				    g_IN_CASE[g_SELECTVAR_CTR] = 1
				    g_CASE_FALL$ = ""
				END IF
			    END IF
			END IF
		    END IF

		CASE "DEFAULT"
		    IF ISTRUE(g_IN_CASE[g_SELECTVAR_CTR]) THEN
			WRITELN "} else {" TO g_CFILE
		    ELSE
			PRINT NL$, "ERROR: cannot use DEFAULT without previous CASE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    END IF
		    g_IN_CASE[g_SELECTVAR_CTR] = 0
		    g_CASE_FALL$ = ""

		CASE "SETENVIRON"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty SETENVIRON at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Resolve this with C macro
			WRITELN "SETENVIRON(", MID$(statement$, INSTR(statement$, "SETENVIRON") + 10), ");" TO g_CFILE
		    END IF

		CASE "SORT"
		    Handle_Sort(CHOP$(MID$(statement$, INSTR(statement$, "SORT") + 4)))

		CASE "STOP"
		    WRITELN "kill(getpid(), SIGSTOP);" TO g_CFILE

		CASE "TRACE"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty TRACE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			IF EQUAL(element$[2], "ON") THEN g_TRACE = 1
			ELIF EQUAL(element$[2], "OFF") THEN g_TRACE =0
		    ENDIF

		CASE "OPTION"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty OPTION at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			IF EQUAL(element$[2], "BASE") AND dim IS 3 THEN
			    IF REGEX(element$[3], "[0-9]") THEN
				g_OPTION_BASE = VAL(element$[3])
			    ELSE
				PRINT NL$, "ERROR: invalid argument to OPTION BASE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
				END 1
			    END IF
			ELIF EQUAL(element$[2], "COMPARE") AND dim IS 3 THEN
			    IF REGEX(element$[3], "[0-1]|TRUE|FALSE") THEN
			        WRITELN "__b2c__option_compare = ", element$[3], ";" TO g_CFILE
			    ELSE
				PRINT NL$, "ERROR: invalid argument to OPTION COMPARE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
				END 1
			    END IF
			ELIF EQUAL(element$[2], "SOCKET") AND dim IS 3 THEN
			    IF REGEX(element$[3], "[0-9]") THEN
				g_OPTION_SOCKET = VAL(element$[3])
			    ELSE
				PRINT NL$, "ERROR: invalid argument to OPTION SOCKET at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
				END 1
			    END IF
                        ELIF EQUAL(element$[2], "MEMSTREAM") AND dim IS 3 THEN
			    IF REGEX(element$[3], "[0-1]|TRUE|FALSE") THEN
			        WRITELN "__b2c__option_memstream = ", element$[3], ";" TO g_CFILE
			    ELSE
				PRINT NL$, "ERROR: invalid argument to OPTION MEMSTREAM at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
				END 1
			    END IF
			ELIF EQUAL(element$[2], "MEMTYPE") AND dim IS 3 THEN
			    IF REGEX(statement$, ".*short.*") THEN
                                WRITELN "__b2c__memtype = 2;" TO g_CFILE
				g_OPTION_MEMTYPE$ = "short"
			    ELIF REGEX(statement$, ".*int.*") THEN
                                WRITELN "__b2c__memtype = 3;" TO g_CFILE
				g_OPTION_MEMTYPE$ = "int"
			    ELIF REGEX(statement$, ".*long.*|.*NUMBER.*") THEN
                                WRITELN "__b2c__memtype = 4;" TO g_CFILE
				g_OPTION_MEMTYPE$ = "long"
			    ELIF REGEX(statement$, ".*float.*") THEN
                                WRITELN "__b2c__memtype = 5;" TO g_CFILE
				g_OPTION_MEMTYPE$ = "float"
			    ELIF REGEX(statement$, ".*double.*|.*FLOATING.*") THEN
                                WRITELN "__b2c__memtype = 6;" TO g_CFILE
				g_OPTION_MEMTYPE$ = "double"
			    ELIF REGEX(statement$, ".*void.*|.*char\\*.*|.*STRING.*") THEN
                                WRITELN "__b2c__memtype = 7;" TO g_CFILE
				g_OPTION_MEMTYPE$ = "char*"
			    ELIF REGEX(statement$, ".*char.*") THEN
                                WRITELN "__b2c__memtype = 1;" TO g_CFILE
				g_OPTION_MEMTYPE$ = "char"
			    ELSE
				PRINT NL$, "ERROR: invalid argument to OPTION MEMTYPE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
				END 1
			    END IF
                       ELIF EQUAL(element$[2], "COLLAPSE") AND dim IS 3 THEN
			    IF REGEX(element$[3], "[0-1]|TRUE|FALSE") THEN
			        WRITELN "__b2c__collapse = ", element$[3], ";" TO g_CFILE
			    ELSE
				PRINT NL$, "ERROR: invalid argument to OPTION COLLAPSE at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
				END 1
			    END IF
                        ELIF EQUAL(element$[2], "INTERNATIONAL") AND dim IS 3 THEN
			    IF REGEX(element$[3], "[0-1]|TRUE|FALSE") THEN
				WRITELN "#include <libintl.h>" TO g_HFILE
				WRITELN "#include <locale.h>" TO g_HFILE
				WRITELN "setlocale(LC_ALL, \"\");" TO g_CFILE
				WRITELN "if(bindtextdomain(\"", LEFT$(g_SOURCEFILE$, INSTR(g_SOURCEFILE$, ".")-1), "\",\"/usr/share/locale\")==NULL){if(!__b2c__trap){ERROR = 6; if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
				WRITELN "if(textdomain(\"", LEFT$(g_SOURCEFILE$, INSTR(g_SOURCEFILE$, ".")-1), "\")==NULL){if(!__b2c__trap){ERROR = 6; if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
			    ELSE
				PRINT NL$, "ERROR: invalid argument to OPTION INTERNATIONAL at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
				END 1
			    END IF
			ELSE
			    PRINT NL$, "ERROR: argument to OPTION at line ", g_COUNTER, " in file '", g_CURFILE$, "' not recognized!"
			    END 1
			END IF
		    END IF

		CASE "PROTO"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty PROTO at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			exp$ = MID$(REPLACE$(statement$, CHR$(34), ""), INSTR(statement$, "PROTO") + 5)
			' Check if ALIAS is there
			IF INSTR(exp$, " ALIAS ") THEN
			    WRITELN "#define ", MID$(exp$, INSTR(exp$, " ALIAS ") + 7), " ", MID$(exp$, 1, INSTR(exp$, " ALIAS ")) TO g_HFILE
			    g_IMPORTED$ = CONCAT$(MID$(exp$, INSTR(exp$, " ALIAS ") + 7), " ", g_IMPORTED$)
			    g_IMPORTED$ = CONCAT$(MID$(exp$, 1, INSTR(exp$, " ALIAS ")), " ", g_IMPORTED$)
			ELSE
			    g_IMPORTED$ = CONCAT$(REPLACE$(exp$, ",", " "), " ", g_IMPORTED$)
			END IF
		    END IF

		CASE "INCR"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty INC at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Walk through commas
			SPLIT CHOP$(MID$(statement$, INSTR(statement$, "INCR") + 4)) BY "," TO sym$ SIZE dim
			IF dim IS 1 THEN
			    WRITELN sym$[1], " = ", sym$[1], " + 1;" TO g_CFILE
			ELSE
			    WRITELN sym$[1], " = ", sym$[1], " + (", CHOP$(MID$(statement$, INSTR(statement$, ",") + 1)), ");" TO g_CFILE
			END IF
		    END IF

		CASE "DECR"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty INC at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Walk through commas
			SPLIT CHOP$(MID$(statement$, INSTR(statement$, "DECR") + 4)) BY "," TO sym$ SIZE dim
			IF dim IS 1 THEN
			    WRITELN sym$[1], " = ", sym$[1], " - 1;" TO g_CFILE
			ELSE
			    WRITELN sym$[1], " = ", sym$[1], " - (", CHOP$(MID$(statement$, INSTR(statement$, ",") + 1)), ");" TO g_CFILE
			END IF
		    END IF

		CASE "ALARM"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty ALARM at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Walk through commas
			SPLIT CHOP$(MID$(statement$, INSTR(statement$, "ALARM") + 5)) BY "," TO sym$ SIZE dim
			IF dim IS 2 THEN
			    WRITELN "signal(SIGALRM, (void*)", sym$[1], ");" TO g_CFILE
			    WRITELN "alarm(", sym$[2], ");" TO g_CFILE
			ELSE
			    PRINT NL$, "ERROR: missing argument in ALARM at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			    END 1
			END IF
		    END IF

		CASE "CURSOR"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty CURSOR at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			IF EQUAL(element$[2], "ON") THEN WRITELN "fprintf(stdout,\"\\033[?25h\"); fflush(stdout);" TO g_CFILE
			ELIF EQUAL(element$[2], "OFF") THEN WRITELN "fprintf(stdout,\"\\033[?25l\"); fflush(stdout);" TO g_CFILE
		    ENDIF

		CASE "ALIAS"
		    Handle_Alias(CHOP$(MID$(statement$, INSTR(statement$, "ALIAS") + 5)))

		CASE "LOOKUP"
		    Handle_Lookup(CHOP$(MID$(statement$, INSTR(statement$, "LOOKUP") + 6)))

		CASE "RELATE"
		    Handle_Relate(CHOP$(MID$(statement$, INSTR(statement$, "RELATE") + 6)))

		CASE "TEXTDOMAIN"
		    ' Check argument
		    IF dim EQ 1 THEN
			PRINT NL$, "ERROR: empty TEXTDOMAIN at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			END 1
		    ELSE
			' Walk through commas
			SPLIT CHOP$(MID$(statement$, INSTR(statement$, "TEXTDOMAIN") + 10)) BY "," TO sym$ SIZE dim
			IF dim IS 2 THEN
			    WRITELN "if(bindtextdomain(", sym$[1], ",", sym$[2], ")==NULL){if(!__b2c__trap){ERROR = 6; if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
			    WRITELN "if(textdomain(", sym$[1], ")==NULL){if(!__b2c__trap){ERROR = 6; if(!__b2c__catch_set){fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} if(!setjmp(__b2c__jump)) goto ", g_CATCHGOTO$, ";} }" TO g_CFILE
			ELSE
			    PRINT NL$, "ERROR: missing argument in TEXTDOMAIN at line ", g_COUNTER, " in file '", g_CURFILE$, "'!"
			    END 1
			END IF
		    END IF

		DEFAULT
		    ' Check on imported symbols first
		    IF INSTR(element$[1], "(") THEN element$[1] = LEFT$(element$[1], INSTR(element$[1], "(") - 1)

		    SPLIT CHOP$(g_IMPORTED$) BY " " TO sym$ SIZE dim
		    found = FALSE

		    FOR i = 1 TO dim
			IF EQUAL(sym$[i], element$[1]) THEN
			    IF REGEX(statement$, "\\(.*\\)") THEN WRITELN statement$, ";" TO g_CFILE
			    ELSE WRITELN statement$, "();" TO g_CFILE
			    found = TRUE
			    BREAK
			END IF
		    NEXT
		    ' Not an imported symbol? Check if assignment
		    IF NOT(found) THEN Handle_Let(statement$)
	    END SELECT
	END IF
    END IF

END SUB

'----------------------------------------------------------------------------------------------

SUB Tokenize (STRING current$)

    LOCAL dim, i, is_string, is_escaped
    LOCAL token$

    ' Initialize parser
    is_string = FALSE
    is_escaped = FALSE
    token$ = ""

    ' See if there are colons
    FOR i = 1 TO LEN(current$)
	IF EQUAL(MID$(current$, i, 5), "INTL$") THEN
	    IF ISFALSE(is_string) THEN
		token$ = CONCAT$(token$, "gettext")
		INCR i, 5
	    END IF
	ELIF EQUAL(MID$(current$, i, 5), "NNTL$") THEN
	    IF ISFALSE(is_string) THEN
		token$ = CONCAT$(token$, "ngettext")
		INCR i, 5
	    END IF
	END IF
	SELECT MID$(current$, i, 1)
	    ' Separator
	    CASE ":"
		IF ISFALSE(is_string) THEN
		    token$ = CONCAT$(token$, CHR$(10))
		ELSE
		    token$ = CONCAT$(token$, ":")
		END IF
	    ' String symbol
	    CASE "$"
		IF ISFALSE(is_string) OR REGEX(current$, "IMPORT.*FROM.*TYPE.*") THEN
		    token$ = CONCAT$(token$, g_STRINGSIGN$)
		    is_escaped = FALSE
		ELSE
		    token$ = CONCAT$(token$, "$")
		END IF
	    ' Escape symbol
	    CASE CHR$(92)
		token$ = CONCAT$(token$, CHR$(92))
		is_escaped = NOT(is_escaped)
	    ' Quote symbol
	    CASE CHR$(34)
		token$ = CONCAT$(token$, CHR$(34))
		IF ISFALSE(is_escaped) THEN is_string = NOT(is_string)
		is_escaped = FALSE
	    DEFAULT
		token$ = CONCAT$(token$, MID$(current$, i, 1))
		is_escaped = FALSE
	END SELECT
    NEXT
    ' Split into separate statements
    SPLIT token$ BY CHR$(10) TO element$ SIZE dim
    ' Start parsing
    FOR i = 1 TO dim
	Parse_Line(CHOP$(element$[i]))
    NEXT

END SUB

'----------------------------------------------------------------------------------------------

FUNCTION Parse_Equation$(STRING current$)

    LOCAL dim, i, j, is_string, is_escaped, is_equation, opctr
    LOCAL token$, term$, eq$, total$, type$
    LOCAL logop$[32]

    ' Initialize parser
    is_string = FALSE
    is_escaped = FALSE
    opctr = 1

    ' First split into separate chunks OR/AND
    FOR i = 1 TO LEN(current$)
        IF EQUAL(MID$(current$, i, 5), " AND ") THEN
            IF ISFALSE(is_string) THEN
		token$ = CONCAT$(token$, CHR$(10))
                logop$[opctr] = " AND "
                INCR opctr : INCR i, 4
            ELSE
		token$ = CONCAT$(token$, " ")
            END IF
        ELIF EQUAL(MID$(current$, i, 4), " OR ") THEN
            IF ISFALSE(is_string) THEN
		token$ = CONCAT$(token$, CHR$(10))
                logop$[opctr] = " OR "
                INCR opctr : INCR i, 3
            ELSE
		token$ = CONCAT$(token$, " ")
            END IF
        ELIF EQUAL(MID$(current$, i, 1), CHR$(92)) THEN
	    token$ = CONCAT$(token$, CHR$(92))
	    is_escaped = NOT(is_escaped)
        ELIF EQUAL(MID$(current$, i, 1), CHR$(34)) THEN
	    token$ = CONCAT$(token$, CHR$(34))
	    IF ISFALSE(is_escaped) THEN is_string = NOT(is_string)
	    is_escaped = FALSE
	ELSE
	    token$ = CONCAT$(token$, MID$(current$, i, 1))
	    is_escaped = FALSE
	END IF
    NEXT
    logop$[opctr] = ""
    opctr = 1

    ' Split into separate chunks
    SPLIT token$ BY CHR$(10) TO element$ SIZE dim

    ' Start parsing
    FOR j = 1 TO dim

        eq$ = "!"
        token$ = ""

        ' Check if this is a string
        IF INSTR(element$[j], "(") THEN
            type$ = MID$(element$[j], 1, INSTR(element$[j], "("))
        ELSE
            type$ = element$[j]
        END IF

        ' See if there are equal signs
        FOR i = 1 TO LEN(element$[j])

	    SELECT MID$(element$[j], i, 1)
	        ' Separator
	        CASE "="
		    IF ISFALSE(is_string) THEN
                        IF INSTR(type$, g_STRINGSIGN$) OR INSTR(type$, CHR$(34)) THEN
                            term$ = token$
                            token$ = ""
                        ELIF NOT(is_equation) THEN
		            token$ = CONCAT$(token$, "==")
                        ELSE
		            token$ = CONCAT$(token$, "=")
                            is_equation = 0
                        END IF
		    ELSE
		        token$ = CONCAT$(token$, "=")
		    END IF
                ' Negation
	        CASE "!"
		    IF ISFALSE(is_string) THEN
                        IF INSTR(type$, g_STRINGSIGN$) OR INSTR(type$, CHR$(34)) THEN
                            eq$ = ""
                        ELIF NOT(is_equation) THEN
		            token$ = CONCAT$(token$, "!=")
                            INCR i
                        ELSE
		            token$ = CONCAT$(token$, "!")
                            is_equation = 0
                        END IF
                    ELSE
		        token$ = CONCAT$(token$, "!")
                    END IF
	        ' Comparison symbols
	        CASE "<"
		    token$ = CONCAT$(token$, "<")
                    is_equation = 1
	        CASE ">"
		    token$ = CONCAT$(token$, ">")
                    is_equation = 1
	        CASE "#"
		    token$ = CONCAT$(token$, "#")
                    is_equation = 1
	        ' Escape symbol
	        CASE CHR$(92)
		    token$ = CONCAT$(token$, CHR$(92))
		    is_escaped = NOT(is_escaped)
	        ' Quote symbol
	        CASE CHR$(34)
		    token$ = CONCAT$(token$, CHR$(34))
		    IF ISFALSE(is_escaped) THEN is_string = NOT(is_string)
		    is_escaped = FALSE
	        DEFAULT
		    token$ = CONCAT$(token$, MID$(element$[j], i, 1))
		    is_escaped = FALSE
	    END SELECT
        NEXT

        ' Construct string equation
        IF INSTR(type$, g_STRINGSIGN$) OR INSTR(type$, CHR$(34)) THEN token$ = CONCAT$("((__b2c__option_compare == 0) ? ", eq$, "strcmp(", term$, ",", token$, ") : ", eq$, "strcasecmp(", term$, ",", token$, "))")

        total$ = CONCAT$(total$, token$)

        ' Restore logical operator
        total$ = CONCAT$(total$, logop$[opctr])
        INCR opctr
    NEXT

    RETURN total$

END FUNCTION

'----------------------------------------------------------------------------------------------

SUB Download_File(STRING name$)

    LOCAL total$, dat$
    LOCAL length, mynet
    LOCAL baconfile TYPE FILE*

    PRINT "Fetching file... ";

    OPEN CONCAT$(LEFT$(name$, INSTR(name$, "/")-1), ":80") FOR NETWORK AS mynet
    SEND CONCAT$("GET /", MID$(name$, INSTR(name$, "/")+1), " HTTP/1.1\r\nHost: ", LEFT$(name$, INSTR(name$, "/")-1), "\r\n\r\n") TO mynet

    RECEIVE dat$ FROM mynet

    ' Get the filesize from the HTTP header
    IF NOT(INSTR(dat$, "Content-Length:")) THEN
        PRINT "ERROR: file not found! Check URL and try again."
        END 1
    END IF

    dat$ = MID$(dat$, INSTR(dat$, "Content-Length:")+15)
    length = VAL(LEFT$(dat$, INSTR(dat$, NL$)))

    ' As long as there is data, get it
    WHILE WAIT(mynet, 1000)
	total$ = CONCAT$(total$, dat$)
	RECEIVE dat$ FROM mynet
        IF LEN(dat$) = 0 THEN BREAK
    WEND
    total$ = CONCAT$(total$, dat$)

    CLOSE NETWORK mynet

    ' Write to file
    OPEN MID$(name$, INSTR(name$, "/")+1) FOR WRITING AS baconfile
	WRITELN MID$(total$, INSTR(total$, "\r\n\r\n")+4) TO baconfile
    CLOSE FILE baconfile

    IF FILELEN(MID$(name$, INSTR(name$, "/")+1)) != length+1 THEN
        PRINT "ERROR: file could not be downloaded. Try again later."
        END 1
    END IF

    PRINT "done."

END SUB

'----------------------------------------------------------------------------------------------
'
' Main program
'
'----------------------------------------------------------------------------------------------

' Default BACON settings
LET g_MAX_DIGITS = 32

' Maximum of internal buffers needed for string processing
LET g_MAX_BUFFERS = 32

' This is the size for static buffers like fgets, read etc.
LET g_BUFFER_SIZE = 512

' Maximum RETURN buffers
LET g_MAX_RBUFFERS = 32

LET g_NO_COMPILE = 0
LET g_TMP_PRESERVE = 0
LET g_USE_C = 0
LET g_MAX_BACKLOG = 4
LET g_CPP = 0
LET g_SHEBANG = FALSE
LET g_XGETTEXT = 0

g_TEMPDIR$ = "."
g_CCNAME$ = "cc"
g_CCFLAGS$ = ""
g_INCFILES$ = ""
g_INCLUDE_FILES$ = ""
LET g_TRACE = 0
LET g_OPTION_BASE = 0
LET g_OPTION_SOCKET = 5
LET g_OPTION_MEMTYPE$ = "char"
LET g_IF_PARSE = 0

' Some global declarations
g_CURFILE$ = ""
g_FUNCNAME$ = ""
g_FUNCTYPE$ = ""
g_PROTOTYPE$ = ""
g_TMP_FILES$ = ""
g_LOCALSTRINGS$ = ""
g_STRINGARRAYS$ = ""
g_STRINGARGS$ = ""
g_BINEXT$ = ""
g_RECORDCACHE$ = ""
LET g_LOOPCTR = 0
g_ERRORTXT$ = ""

' Always create a final label
g_CATCHGOTO$ = "__B2C__PROGRAM__EXIT"

' Records
g_RECORDNAME$ = ""
g_RECORDVAR$ = ""
g_WITHVAR$ = ""

' Select/Case currently 16 levels deep
DECLARE g_SELECTVAR$[16]
DECLARE g_IN_CASE[16]
g_SELECTVAR_CTR = 0

' Relate currently 256
DECLARE g_RELATE$[256]
g_RELATE_CTR = 0

SPLIT CHOP$(ARGUMENT$) BY " " TO args$ SIZE amount

IF amount < 2 THEN
    PRINT "ERROR: no filename? Run with '-h' to see usage."
    END
ENDIF

i = 1

WHILE i <= amount DO

    SELECT LEFT$(args$[i], 2)

	' Compiler option
	CASE "-c"
	    INCR i
	    IF LEN(args$[i]) > 0 THEN g_CCNAME$ = args$[i]

	' Include option
	CASE "-i"
	    INCR i
	    IF NOT(FILEEXISTS(args$[i])) AND NOT(FILEEXISTS(CONCAT$("/usr/include/", args$[i]))) THEN
		PRINT NL$, "ERROR: included C header file from -i option not found!"
		END 1
	    END IF
	    IF LEN(args$[i]) > 0 THEN
		IF NOT(FILEEXISTS(CONCAT$("/usr/include/", args$[i]))) THEN
		    g_INCFILES$ = CONCAT$("#include \"", args$[i], "\"", NL$, g_INCFILES$)
		ELSE
		    g_INCFILES$ = CONCAT$("#include <", args$[i], ">", NL$, g_INCFILES$)
		END IF
	    END IF

	' Library flags
	CASE "-l"
	    IF LEN(args$[i]) > 2 THEN
		g_LDFLAGS$ = CONCAT$(g_LDFLAGS$, " -l", MID$(args$[i], 3))
	    ELSE
		INCR i
		IF i <= amount THEN g_LDFLAGS$ = CONCAT$(g_LDFLAGS$, " -l", args$[i])
	    END IF

	' Compiler flags
	CASE "-o"
	    INCR i
	    IF LEN(args$[i]) > 0 THEN g_CCFLAGS$ = CONCAT$(g_CCFLAGS$, " ", args$[i])

	' Temporary directory
	CASE "-d"
	    INCR i
	    IF LEN(args$[i]) > 0 THEN
		IF NOT(FILEEXISTS(args$[i])) THEN MAKEDIR args$[i]
		g_TEMPDIR$ = args$[i]
	    END IF

	' Help option
	CASE "-h";
	CASE "-?"
	    PRINT NL$, "USAGE: bacon [options] program[.bac]"
	    PRINT NL$, "OPTIONS:"
	    PRINT NL$, " -c <compiler>", TAB$(1), "Compiler to use (default: ", g_CCNAME$, ")"
	    PRINT " -l <flags>", TAB$(1), "Pass libraries to linker"
	    PRINT " -o <options>", TAB$(1), "Pass compiler options"
	    PRINT " -i <include>", TAB$(1), "Add include file to C code"
	    PRINT " -d <tmpdir>", TAB$(1), "Temporary directory (default: ", g_TEMPDIR$, ")"
	    PRINT " -x ", TAB$(2), "Extract gettext strings"
	    PRINT " -f ", TAB$(2), "Create Shared Object"
	    PRINT " -n ", TAB$(2), "Do not compile, only convert"
	    PRINT " -j ", TAB$(2), "Invoke C Preprocessor"
	    PRINT " -p ", TAB$(2), "Preserve temporary files"
	    PRINT " -b ", TAB$(2), "Execute from shebang"
	    PRINT " -v ", TAB$(2), "Show version"
	    PRINT " -h ", TAB$(2), "Show help", NL$
	    END

	' Version option
	CASE "-v"
	    PRINT NL$, "BaCon version ", g_VERSION$, " - (c) Peter van Eerten - GPL v3.", NL$
	    END

	' Preserve option
	CASE "-p"
	    g_TMP_PRESERVE = 1

	' Gettext option
	CASE "-x"
	    g_XGETTEXT = 1

	' No compile option
	CASE "-n"
	    g_NO_COMPILE = 1

	' Invoke C Preprocessor
	CASE "-j"
	    g_CPP = 1

	' Shared library
	CASE "-f"
	    g_CCFLAGS$ = CONCAT$(g_CCFLAGS$, " -shared -rdynamic")
	    IF INSTR(OS$, "x86_64") THEN g_CCFLAGS$ = CONCAT$(g_CCFLAGS$, " -fPIC")
	    g_BINEXT$ = ".so"

	' use shebang
	CASE "-b"
	    g_SHEBANG = TRUE
	    g_TEMPDIR$ = "/tmp"

	' This is the sourcefile
	DEFAULT
	    g_SOURCEFILE$ = args$[i]

    END SELECT

    INCR i

WEND

IF LEFT$(g_SOURCEFILE$, 7) = "http://" THEN
    g_SOURCEFILE$ = MID$(g_SOURCEFILE$, 8)
    Download_File(g_SOURCEFILE$)
    g_SOURCEFILE$ = MID$(g_SOURCEFILE$, INSTR(g_SOURCEFILE$, "/")+1)
ELIF NOT(EQUAL(RIGHT$(g_SOURCEFILE$, 4), ".bac")) THEN
    g_SOURCEFILE$ = CONCAT$(g_SOURCEFILE$, ".bac")
END IF

IF ISFALSE(FILEEXISTS(g_SOURCEFILE$)) THEN
    PRINT "ERROR: file not found!"
    END ERROR
END IF

' Change the working directory
IF INSTR(g_SOURCEFILE$, "/") THEN CHANGEDIR MID$(g_SOURCEFILE$, 1, INSTRREV(g_SOURCEFILE$, "/")-1)

' Now create the global filenames where to write to
g_CFILE$ = CONCAT$(g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".c")
g_HFILE$ = CONCAT$(g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".h")
STRINGARRAYFILE$ = CONCAT$(g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".string.h")
FLOATARRAYFILE$ = CONCAT$(g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".float.h")

' Check to overwrite
IF FILEEXISTS(g_CFILE$) OR FILEEXISTS(g_HFILE$) THEN
    IF FILEEXISTS(g_CFILE$) THEN DELETE FILE g_CFILE$
    IF FILEEXISTS(g_HFILE$) THEN DELETE FILE g_HFILE$
    IF FILEEXISTS(STRINGARRAYFILE$) THEN DELETE FILE STRINGARRAYFILE$
    IF FILEEXISTS(FLOATARRAYFILE$) THEN DELETE FILE FLOATARRAYFILE$
END IF

IF NOT(g_SHEBANG) THEN PRINT "Starting conversion...";

' Add to total file list
g_TMP_FILES$ = CONCAT$(g_TMP_FILES$, " ", g_CFILE$)
g_TMP_FILES$ = CONCAT$(g_TMP_FILES$, " ", g_HFILE$)
g_TMP_FILES$ = CONCAT$(g_TMP_FILES$, " ", STRINGARRAYFILE$)
g_TMP_FILES$ = CONCAT$(g_TMP_FILES$, " ", FLOATARRAYFILE$)

' Create new sourcefile
OPEN g_CFILE$ FOR WRITING AS g_CFILE

' Create basic C file
WRITELN "/* Created with BaCon ", g_VERSION$, " - (c) Peter van Eerten - GPL v3 */" TO g_CFILE
WRITELN "#include \"", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".h\"" TO g_CFILE
WRITELN "int main(int argc, const char **argv)" TO g_CFILE
WRITELN "{" TO g_CFILE
WRITELN "/* Default is: system traps signals */" TO g_CFILE
WRITELN "signal(SIGILL, __b2c__catch_signal);" TO g_CFILE
WRITELN "signal(SIGABRT, __b2c__catch_signal);" TO g_CFILE
WRITELN "signal(SIGFPE, __b2c__catch_signal);" TO g_CFILE
WRITELN "signal(SIGSEGV, __b2c__catch_signal);" TO g_CFILE
WRITELN "/* Make sure internal string buffers are empty */" TO g_CFILE
WRITELN "__b2c__sbuffer_ptr=0;" TO g_CFILE
WRITELN "__b2c__rbuffer_ptr=0;" TO g_CFILE

' Put arguments into reserved variable ARGUMENT
WRITELN "/* Setup the reserved variable 'ARGUMENT' */" TO g_CFILE
WRITELN "for(__b2c__counter=0; __b2c__counter < argc; __b2c__counter++)" TO g_CFILE
WRITELN "{__b2c__arglen += strlen(argv[__b2c__counter]) + 1;} __b2c__arglen++;" TO g_CFILE
WRITELN "ARGUMENT", g_STRINGSIGN$, " = (char*)calloc(__b2c__arglen, sizeof(char));" TO g_CFILE
WRITELN "for(__b2c__counter=0; __b2c__counter < argc; __b2c__counter++)" TO g_CFILE
WRITELN "{strcat(ARGUMENT", g_STRINGSIGN$, ", argv[__b2c__counter]); if(__b2c__counter != argc - 1) strcat(ARGUMENT", g_STRINGSIGN$, ", \" \");}" TO g_CFILE
WRITELN "/* By default seed random generator */" TO g_CFILE
WRITELN "srandom((unsigned int)time(NULL));" TO g_CFILE
WRITELN "/* Initialize internal stackpointer */" TO g_CFILE
WRITELN "__b2c__typestack = (int*)calloc(1, sizeof(int));" TO g_CFILE
WRITELN "__b2c__stringstack = (char**)realloc(__b2c__stringstack, sizeof(char*)); __b2c__stringstack[0] = calloc(1, sizeof(char));" TO g_CFILE
WRITELN "/* Rest of the program */" TO g_CFILE

' Create new headerfile
OPEN g_HFILE$ FOR WRITING AS g_HFILE

' Create basic H file, functions are converted using macros
WRITELN "/* Created with BaCon ", g_VERSION$, " - (c) Peter van Eerten - GPL v3 */" TO g_HFILE
WRITELN "#include <stdio.h>" TO g_HFILE
WRITELN "#include <stdlib.h>" TO g_HFILE
WRITELN "#include <stdarg.h>" TO g_HFILE
WRITELN "#include <sys/time.h>" TO g_HFILE
WRITELN "#include <sys/stat.h>" TO g_HFILE
WRITELN "#include <sys/types.h>" TO g_HFILE
WRITELN "#include <sys/wait.h>" TO g_HFILE
WRITELN "#include <sys/socket.h>" TO g_HFILE
WRITELN "#include <sys/utsname.h>" TO g_HFILE
WRITELN "#include <dirent.h>" TO g_HFILE
WRITELN "#include <setjmp.h>" TO g_HFILE
WRITELN "#include <netdb.h>" TO g_HFILE
IF INSTR(OS$, "BSD") THEN
    WRITELN "#include <netinet/in.h>" TO g_HFILE
END IF
WRITELN "#include <arpa/inet.h>" TO g_HFILE
WRITELN "#include <signal.h>" TO g_HFILE
WRITELN "static jmp_buf __b2c__jump;" TO g_HFILE
WRITELN "static int __b2c__trap = 1;" TO g_HFILE
WRITELN "static int __b2c__catch_set = 0;" TO g_HFILE
WRITELN "static int ERROR = 0;" TO g_HFILE
WRITELN "static int __b2c__option_compare = 0;" TO g_HFILE
WRITELN "static int __b2c__option_memstream = 0;" TO g_HFILE
WRITELN "static int __b2c__memtype = 1;" TO g_HFILE
WRITELN "static int __b2c__collapse = 0;" TO g_HFILE
WRITELN "int __b2c__break_ctr = 0;" TO g_HFILE
WRITELN "int __b2c__break_flag = 0;" TO g_HFILE
WRITELN "int RETVAL = 0;" TO g_HFILE
WRITELN "char __b2c__chop_default[] = \"\\r\\n\\t \";" TO g_HFILE
WRITELN "char VERSION", g_STRINGSIGN$, "[] = \"", g_VERSION$, "\";" TO g_HFILE

' Add user include files
WRITELN "/* User include files */" TO g_HFILE
WRITELN g_INCFILES$ TO g_HFILE

WRITELN "/* READ/DATA include files */" TO g_HFILE
WRITELN "int __b2c__stringarray_ptr = 0;" TO g_HFILE
WRITELN "#include \"", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".string.h\"" TO g_HFILE
WRITELN "int __b2c__floatarray_ptr = 0;" TO g_HFILE
WRITELN "#include \"", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".float.h\"" TO g_HFILE
WRITELN "int __b2c__ctr;" TO g_HFILE

WRITELN "/* Math functions */" TO g_HFILE
WRITELN "extern double round(double __b2c__x);" TO g_HFILE
WRITELN "extern long int lrint(double __b2c__x);" TO g_HFILE
WRITELN "#include <math.h>" TO g_HFILE
WRITELN "#define SQR(__b2c__x) sqrt(__b2c__x)" TO g_HFILE
WRITELN "#define POW(__b2c__x, __b2c__y) pow(__b2c__x, __b2c__y)" TO g_HFILE
WRITELN "#define SIN(__b2c__x) sin(__b2c__x)" TO g_HFILE
WRITELN "#define COS(__b2c__x) cos(__b2c__x)" TO g_HFILE
WRITELN "#define TAN(__b2c__x) tan(__b2c__x)" TO g_HFILE
WRITELN "#define ATN(__b2c__x) atan(__b2c__x)" TO g_HFILE
WRITELN "#define LOG(__b2c__x) log(__b2c__x)" TO g_HFILE
WRITELN "#define EXP(__b2c__x) exp(__b2c__x)" TO g_HFILE
WRITELN "#define SGN(__b2c__x) (__b2c__x == 0 ? 0 : (__b2c__x < 0 ? -1 : 1))" TO g_HFILE
WRITELN "#define ROUND(__b2c__x) lrint(__b2c__x)" TO g_HFILE
WRITELN "#define INT(__b2c__x) lrint(__b2c__x)" TO g_HFILE
WRITELN "#define MOD(__b2c__x, __b2c__y) ((long)__b2c__x % (long)__b2c__y)" TO g_HFILE
WRITELN "#define EVEN(__b2c__x) ((__b2c__x % 2 == 0) ? 1 : 0)" TO g_HFILE
WRITELN "#define ODD(__b2c__x) ((__b2c__x % 2 != 0) ? 1 : 0)" TO g_HFILE
WRITELN "#define FLOOR(__b2c__x) (long)floor(__b2c__x)" TO g_HFILE
WRITELN "#define ABS(__b2c__x) (long)abs(__b2c__x)" TO g_HFILE
WRITELN "#define RND random()" TO g_HFILE
IF INSTR(OS$, "SunOS") THEN
    WRITELN "#define MAXRANDOM 2147483647" TO g_HFILE
ELSE
    WRITELN "#define MAXRANDOM RAND_MAX" TO g_HFILE
END IF
WRITELN "#define RANDOM(__b2c__x) ((__b2c__x != 0) ? random()/(MAXRANDOM/__b2c__x) : 0)" TO g_HFILE
WRITELN "/* Other functions */" TO g_HFILE
WRITELN "#define VAL(__b2c__x) ((__b2c__x != NULL) ? atof(__b2c__x) : 0)" TO g_HFILE
WRITELN "/* Unix functions */" TO g_HFILE
WRITELN "#include <unistd.h>" TO g_HFILE
WRITELN "#define SYSTEM(__b2c__x) do {if (__b2c__x != NULL) {RETVAL = system(__b2c__x); if(WIFEXITED(RETVAL)) RETVAL = WEXITSTATUS(RETVAL);} else RETVAL=0;} while(0)" TO g_HFILE
WRITELN "/* String functions */" TO g_HFILE
WRITELN "#include <string.h>" TO g_HFILE
WRITELN "char *__b2c__strndup(const char *__b2c__s, size_t __b2c__n){size_t __b2c__avail;" TO g_HFILE
WRITELN "char *__b2c__p; if (!__b2c__s) return 0; __b2c__avail = strlen(__b2c__s) + 1;" TO g_HFILE
WRITELN "if (__b2c__avail > __b2c__n + 1) __b2c__avail = __b2c__n + 1; __b2c__p = malloc(__b2c__avail);" TO g_HFILE
WRITELN "memcpy(__b2c__p, __b2c__s, __b2c__avail); __b2c__p[__b2c__avail - 1] = '\\0'; return __b2c__p;}" TO g_HFILE
WRITELN "char __b2c__input__buffer[", g_BUFFER_SIZE, "];" TO g_HFILE
WRITELN "char* __b2c__sbuffer[", g_MAX_BUFFERS, "] = { NULL };" TO g_HFILE
WRITELN "int __b2c__sbuffer_ptr;" TO g_HFILE
WRITELN "char* __b2c__rbuffer[", g_MAX_RBUFFERS, "] = { NULL };" TO g_HFILE
WRITELN "int __b2c__rbuffer_ptr;" TO g_HFILE
WRITELN "/* Temporary pointer to perform assignments */" TO g_HFILE
WRITELN "char *__b2c__assign = NULL;" TO g_HFILE
WRITELN "char *__b2c__split = NULL; char *__b2c__split_tmp = NULL; char *__b2c__split_ptr = NULL;" TO g_HFILE
WRITELN "char *ERR", g_STRINGSIGN$, "(int);" TO g_HFILE
WRITELN "/* Functions for sort */" TO g_HFILE
WRITELN "int __b2c__sortnrd(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{if (*(double*)__b2c__a==*(double*)__b2c__b) return 0; else if (*(double*)__b2c__a < *(double*)__b2c__b) return -1; else return 1;}" TO g_HFILE
WRITELN "int __b2c__sortnrd_down(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{if (*(double*)__b2c__a==*(double*)__b2c__b) return 0; else if (*(double*)__b2c__a < *(double*)__b2c__b) return 1; else return -1;}" TO g_HFILE
WRITELN "int __b2c__sortnrf(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{if (*(float*)__b2c__a==*(float*)__b2c__b) return 0; else if (*(float*)__b2c__a < *(float*)__b2c__b) return -1; else return 1;}" TO g_HFILE
WRITELN "int __b2c__sortnrf_down(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{if (*(float*)__b2c__a==*(float*)__b2c__b) return 0; else if (*(float*)__b2c__a < *(float*)__b2c__b) return 1; else return -1;}" TO g_HFILE
WRITELN "int __b2c__sortnrl(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{if (*(long*)__b2c__a==*(long*)__b2c__b) return 0; else if (*(long*)__b2c__a < *(long*)__b2c__b) return -1; else return 1;}" TO g_HFILE
WRITELN "int __b2c__sortnrl_down(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{if (*(long*)__b2c__a==*(long*)__b2c__b) return 0; else if (*(long*)__b2c__a < *(long*)__b2c__b) return 1; else return -1;}" TO g_HFILE
WRITELN "int __b2c__sortnri(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{if (*(int*)__b2c__a==*(int*)__b2c__b) return 0; else if (*(int*)__b2c__a < *(int*)__b2c__b) return -1; else return 1;}" TO g_HFILE
WRITELN "int __b2c__sortnri_down(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{if (*(int*)__b2c__a==*(int*)__b2c__b) return 0; else if (*(int*)__b2c__a < *(int*)__b2c__b) return 1; else return -1;}" TO g_HFILE
WRITELN "int __b2c__sortstr(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{return strcmp(*(char **) __b2c__a, *(char **) __b2c__b);}" TO g_HFILE
WRITELN "int __b2c__sortstr_down(const void *__b2c__a, const void *__b2c__b)" TO g_HFILE
WRITELN "{return strcmp(*(char **) __b2c__b, *(char **) __b2c__a);}" TO g_HFILE
WRITELN "/* Actual functions */" TO g_HFILE
WRITELN "char* __b2c__curdir(void){__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_BUFFER_SIZE, "*sizeof(char));" TO g_HFILE
WRITELN "return (getcwd(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_BUFFER_SIZE, "));}" TO g_HFILE
WRITELN "#define CURDIR", g_STRINGSIGN$, " __b2c__curdir()" TO g_HFILE
WRITELN "char* __b2c__reverse(char *__b2c__s){int __b2c__i; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__s)+2)*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, strlen(__b2c__s)+1);" TO g_HFILE
WRITELN "for(__b2c__i=0;__b2c__i<strlen(__b2c__s);__b2c__i++){__b2c__sbuffer[__b2c__sbuffer_ptr][__b2c__i]=__b2c__s[strlen(__b2c__s)-1-__b2c__i];}" TO g_HFILE
WRITELN "return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define REVERSE", g_STRINGSIGN$, "(x) ((x != NULL) ? __b2c__reverse(x) : \"null\")" TO g_HFILE
WRITELN "char* __b2c__str(double d){__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, "*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, ", g_MAX_DIGITS, ");" TO g_HFILE
WRITELN "if(floor(d) == d) snprintf(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%ld\", (long)d); else snprintf(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%.10g\", d);" TO g_HFILE
WRITELN "return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define STR", g_STRINGSIGN$, "(x) __b2c__str(x)" TO g_HFILE
WRITELN "char* __b2c__concat(char *__b2c__first, ...){char *__b2c__tmp; va_list __b2c__ap; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "if(__b2c__first != NULL) { __b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__first)+1)*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, (strlen(__b2c__first)+1)*sizeof(char)); strcpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__first);}" TO g_HFILE
WRITELN "else {__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], 2*sizeof(char)); strcpy(__b2c__sbuffer[__b2c__sbuffer_ptr], \"\");} va_start(__b2c__ap, __b2c__first);" TO g_HFILE
WRITELN "while((__b2c__tmp = va_arg(__b2c__ap, char *)) != NULL) {__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__tmp)+strlen(__b2c__sbuffer[__b2c__sbuffer_ptr])+1)*sizeof(char));" TO g_HFILE
WRITELN "strcat(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__tmp);} va_end(__b2c__ap); return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define CONCAT", g_STRINGSIGN$, "(...) __b2c__concat(__VA_ARGS__, (char*)NULL)" TO g_HFILE
WRITELN "char* __b2c__left(char *__b2c__src, long __b2c__n){if(__b2c__src == NULL || __b2c__n > strlen(__b2c__src) || __b2c__n < 0) return(__b2c__src);" TO g_HFILE
WRITELN "__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__src)+1)*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, (strlen(__b2c__src)+1)*sizeof(char)); strncpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__src, (__b2c__n));" TO g_HFILE
WRITELN "return (__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define LEFT", g_STRINGSIGN$, "(__b2c__x, __b2c__y) __b2c__left(__b2c__x, __b2c__y)" TO g_HFILE
WRITELN "char* __b2c__right(char *__b2c__src, long __b2c__n){if(__b2c__src == NULL || __b2c__n > strlen(__b2c__src) || __b2c__n < 0) return(__b2c__src);" TO g_HFILE
WRITELN "__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__src)+1)*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, (strlen(__b2c__src)+1)*sizeof(char)); strcpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__src+ strlen(__b2c__src)- __b2c__n);" TO g_HFILE
WRITELN "return (__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define RIGHT", g_STRINGSIGN$, "(__b2c__x, __b2c__y) __b2c__right(__b2c__x, __b2c__y)" TO g_HFILE
WRITELN "char* __b2c__mid(char *__b2c__src, ...){ va_list __b2c__ap; long __b2c__start, __b2c__end; if(__b2c__src == NULL || strlen(__b2c__src) == 0) return(\"\");" TO g_HFILE
WRITELN "__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__src)+1)*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, (strlen(__b2c__src)+1)*sizeof(char)); va_start(__b2c__ap, __b2c__src);" TO g_HFILE
WRITELN "__b2c__start = va_arg(__b2c__ap, long); if(__b2c__start < 1) return(__b2c__src); if(__b2c__start > strlen(__b2c__src)) return(\"\"); __b2c__end = va_arg(__b2c__ap, long); if((__b2c__end) < 0 || (__b2c__end) > strlen (__b2c__src)) __b2c__end = strlen(__b2c__src)-__b2c__start+1;" TO g_HFILE
WRITELN "strncpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__src+(long)(__b2c__start)-1, (__b2c__end)); va_end(__b2c__ap); return (__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define MID", g_STRINGSIGN$, "(__b2c__string, ...) __b2c__mid(__b2c__string, __VA_ARGS__, -1)" TO g_HFILE
WRITELN "long __b2c__instr(char *__b2c__first, ...){char *__b2c__tmp; char *__b2c__res; int __b2c__pos; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "va_list __b2c__ap; if(__b2c__first == NULL) return (0); __b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__first)+1)*sizeof(char));" TO g_HFILE
WRITELN "strcpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__first); va_start(__b2c__ap, __b2c__first);" TO g_HFILE
WRITELN "__b2c__tmp = va_arg(__b2c__ap, char *); if(__b2c__tmp == NULL || strlen(__b2c__tmp) == 0) return (0);__b2c__pos = va_arg(__b2c__ap, int);" TO g_HFILE
WRITELN "if(__b2c__pos <= 0) __b2c__pos = 1; va_end(__b2c__ap); __b2c__res = strstr(__b2c__sbuffer[__b2c__sbuffer_ptr] + __b2c__pos - 1, __b2c__tmp);" TO g_HFILE
WRITELN "if(__b2c__res == NULL) return (0); return (__b2c__res - __b2c__sbuffer[__b2c__sbuffer_ptr] + 1);}" TO g_HFILE
WRITELN "#define INSTR(...) __b2c__instr(__VA_ARGS__, -1)" TO g_HFILE
WRITELN "long __b2c__instrrev(char *__b2c__first, ...){char *__b2c__tmp; char *__b2c__res = NULL; int __b2c__pos; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "va_list __b2c__ap; if(__b2c__first == NULL) return (0); __b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__first)+1)*sizeof(char));" TO g_HFILE
WRITELN "strcpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__first); va_start(__b2c__ap, __b2c__first);" TO g_HFILE
WRITELN "__b2c__tmp = va_arg(__b2c__ap, char *); if(__b2c__tmp == NULL || strlen(__b2c__tmp) == 0) return (0);__b2c__pos = va_arg(__b2c__ap, int);" TO g_HFILE
WRITELN "if(__b2c__pos <= 0) __b2c__pos = 1; va_end(__b2c__ap); while(__b2c__res == NULL && __b2c__pos <= strlen(__b2c__sbuffer[__b2c__sbuffer_ptr])) {" TO g_HFILE
WRITELN "__b2c__res = strstr(__b2c__sbuffer[__b2c__sbuffer_ptr] + strlen(__b2c__sbuffer[__b2c__sbuffer_ptr]) - __b2c__pos, __b2c__tmp); __b2c__pos+=1;}" TO g_HFILE
WRITELN "if(__b2c__res == NULL) return (0); return (__b2c__res - __b2c__sbuffer[__b2c__sbuffer_ptr] + 1);}" TO g_HFILE
WRITELN "#define INSTRREV(...) __b2c__instrrev(__VA_ARGS__, -1)" TO g_HFILE
WRITELN "char* __b2c__spc(int __b2c__x){__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__x*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, __b2c__x*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 32, __b2c__x); return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define SPC", g_STRINGSIGN$, "(x) ((x > -1) ? __b2c__spc(x) : \"\")" TO g_HFILE
WRITELN "char* __b2c__tab(int __b2c__x){__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__x*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, __b2c__x*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 9, __b2c__x); return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define TAB", g_STRINGSIGN$, "(x) ((x > -1) ? __b2c__tab(x) : \"\")" TO g_HFILE
WRITELN "char* __b2c__fill(unsigned long __b2c__x, unsigned char __b2c__y){__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__x*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, __b2c__x*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__y, __b2c__x); return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define FILL", g_STRINGSIGN$, "(x, y) ((y > -1 && y < 256) ? __b2c__fill(x, y) : \"\")" TO g_HFILE
WRITELN "char* __b2c__chop(char *__b2c__src, ...){char *__b2c__tmp, *__b2c__str; int __b2c__i, __b2c__loc = 0; va_list __b2c__ap; if(strlen(__b2c__src) == 0) return(__b2c__src);" TO g_HFILE
WRITELN "va_start (__b2c__ap, __b2c__src); __b2c__str = va_arg (__b2c__ap, char*); if(__b2c__str == 0) __b2c__str = (char*)__b2c__chop_default; else __b2c__loc = va_arg (__b2c__ap, int); va_end (__b2c__ap);" TO g_HFILE
WRITELN "if(__b2c__loc == 0 || __b2c__loc == 1) {while (*__b2c__src != '\\0') {for(__b2c__i = 0; __b2c__i < strlen(__b2c__str); __b2c__i++) {if (*__b2c__src == *(__b2c__str+__b2c__i)) {__b2c__src++; break; } }" TO g_HFILE
WRITELN "if(__b2c__i == strlen(__b2c__str)) break;} if (*__b2c__src == '\\0') return(\"\");} __b2c__tmp = __b2c__src + strlen(__b2c__src) - 1;" TO g_HFILE
WRITELN "if(__b2c__loc == 0 || __b2c__loc == 2) {while (__b2c__tmp >= __b2c__src && *__b2c__tmp != '\\0') {for(__b2c__i = 0; __b2c__i < strlen(__b2c__str); __b2c__i++) {if (*__b2c__tmp == *(__b2c__str+__b2c__i))" TO g_HFILE
WRITELN "{__b2c__tmp--; break; } } if(__b2c__i == strlen(__b2c__str)) break;} } __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__src)+1)*sizeof(char));" TO g_HFILE
WRITELN "for(__b2c__i = 0; __b2c__i <= __b2c__tmp - __b2c__src; __b2c__i++) __b2c__sbuffer[__b2c__sbuffer_ptr][__b2c__i]=__b2c__src[__b2c__i];" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr][__b2c__i] = '\\0'; return (__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define CHOP", g_STRINGSIGN$, "(...) __b2c__chop(__VA_ARGS__, 0)" TO g_HFILE
WRITELN "char* __b2c__replace(char* __b2c__x, char* __b2c__y, char* __b2c__z){" TO g_HFILE
WRITELN "char *__b2c__tmp, *__b2c__buf, *__b2c__haystack, *__b2c__dup = NULL; __b2c__sbuffer_ptr++;" TO g_HFILE
WRITELN "if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0; __b2c__haystack = strdup(__b2c__x); __b2c__dup = __b2c__haystack;" TO g_HFILE
WRITELN "__b2c__buf = calloc(1, sizeof(char)); while((__b2c__tmp = strstr(__b2c__haystack, __b2c__y)) != NULL) {*__b2c__tmp = '\\0';" TO g_HFILE
WRITELN "__b2c__buf = realloc(__b2c__buf, (strlen(__b2c__buf) + strlen(__b2c__haystack) + strlen(__b2c__z) + 1)*sizeof(char));" TO g_HFILE
WRITELN "strcat(__b2c__buf, __b2c__haystack);strcat(__b2c__buf, __b2c__z);__b2c__haystack = __b2c__tmp+strlen(__b2c__y);}" TO g_HFILE
WRITELN "__b2c__buf = realloc(__b2c__buf, (strlen(__b2c__buf) + strlen(__b2c__haystack) + 1)*sizeof(char));strcat(__b2c__buf, __b2c__haystack);" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], (strlen(__b2c__buf)+1)*sizeof(char));" TO g_HFILE
WRITELN "strcpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__buf);free(__b2c__buf);free(__b2c__dup);return (__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define REPLACE", g_STRINGSIGN$, "(x, y, z)((x!=NULL && y!=NULL && z!= NULL) ? __b2c__replace(x, y, z) : 0)" TO g_HFILE
WRITELN "#define LEN(x) ((x != NULL) ? strlen(x) : 0)" TO g_HFILE
WRITELN "#define EQUAL(__b2c__x, __b2c__y) ((__b2c__x != NULL && __b2c__y != NULL && __b2c__option_compare == 0) ? !strcmp(__b2c__x, __b2c__y) : ((__b2c__x != NULL && __b2c__y != NULL && __b2c__option_compare == 1) ? !strcasecmp(__b2c__x, __b2c__y) : 0) )" TO g_HFILE
WRITELN "char* __b2c__getenv(char *__b2c__env){static char* __b2c__tmp; __b2c__tmp = getenv(__b2c__env); if (__b2c__tmp == NULL)" TO g_HFILE
WRITELN "{return \"\";} return __b2c__tmp;}" TO g_HFILE
WRITELN "#define GETENVIRON", g_STRINGSIGN$, "(x) ((x != NULL) ? __b2c__getenv(x) : \"null\")" TO g_HFILE
WRITELN "#define SETENVIRON(x, y) if(x != NULL && y != NULL) setenv(x, y, 1)" TO g_HFILE
WRITELN "/* CHAR functions */" TO g_HFILE
WRITELN "#include <ctype.h>" TO g_HFILE
WRITELN "char* __b2c__ucase(char *__b2c__s){int __b2c__i; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], strlen(__b2c__s)*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, strlen(__b2c__s)*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "for(__b2c__i=0; __b2c__i < strlen(__b2c__s); __b2c__i++){__b2c__sbuffer[__b2c__sbuffer_ptr][__b2c__i]=toupper(__b2c__s[__b2c__i]);}" TO g_HFILE
WRITELN "return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define UCASE", g_STRINGSIGN$, "(x) ((x != NULL) ? __b2c__ucase(x) : \"null\")" TO g_HFILE
WRITELN "char* __b2c__lcase(char *__b2c__s){int __b2c__i; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], strlen(__b2c__s)*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, strlen(__b2c__s)*sizeof(char)+1*sizeof(char));" TO g_HFILE
WRITELN "for(__b2c__i=0; __b2c__i < strlen(__b2c__s); __b2c__i++){__b2c__sbuffer[__b2c__sbuffer_ptr][__b2c__i]=tolower(__b2c__s[__b2c__i]);}" TO g_HFILE
WRITELN "return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define LCASE", g_STRINGSIGN$, "(x) ((x != NULL) ? __b2c__lcase(x) : \"null\")" TO g_HFILE
WRITELN "/* I/O functions */" TO g_HFILE
WRITELN "FILE *__b2c__inFile; FILE *__b2c__outFile; int __b2c__Byte; struct dirent *__b2c__dir;" TO g_HFILE
WRITELN "char* __b2c__dec2hex(int __b2c__i){__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ");" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, ", g_MAX_DIGITS, ");" TO g_HFILE
WRITELN "snprintf(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%X\", __b2c__i); return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "long __b2c__hex2dec(char *__b2c__h){unsigned int __b2c__i; if(sscanf(__b2c__h, \"%X\", &__b2c__i) == EOF && !__b2c__trap){ERROR = 5;" TO g_HFILE
WRITELN "fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} return(long)(__b2c__i);}" TO g_HFILE
WRITELN "unsigned char __b2c__char2asc(char *__b2c__c){return (unsigned char)*__b2c__c;}" TO g_HFILE
WRITELN "char* __b2c__asc2char(int __b2c__i){__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], 2*sizeof(char));" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, 2*sizeof(char)); snprintf(__b2c__sbuffer[__b2c__sbuffer_ptr], 2, \"%c\", __b2c__i);" TO g_HFILE
WRITELN "return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "/* Function FILEEXISTS contributed by Armando Rivera */ " TO g_HFILE
WRITELN "long __b2c__fileexists(const char *__b2c__x) {struct stat __b2c__buf; if (stat(__b2c__x, &__b2c__buf) != -1) return 1; return 0;}" TO g_HFILE
WRITELN "#define FILEEXISTS(x) __b2c__fileexists(x)" TO g_HFILE
WRITELN "long __b2c__filelen(const char *__b2c__x) {struct stat __b2c__buf; if(stat(__b2c__x, &__b2c__buf) < 0 && !__b2c__trap){ERROR = 24; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}" TO g_HFILE
WRITELN "if(__b2c__x == NULL || stat(__b2c__x, &__b2c__buf) < 0) return -1; else return(long)(__b2c__buf.st_size);}" TO g_HFILE
WRITELN "#define FILELEN(x) __b2c__filelen(x)" TO g_HFILE
WRITELN "long __b2c__filetype(const char *__b2c__x) {struct stat __b2c__buf; if(__b2c__x == NULL) return 0; if(stat(__b2c__x, &__b2c__buf) < 0 && !__b2c__trap)" TO g_HFILE
WRITELN "{ERROR = 24; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}" TO g_HFILE
WRITELN "if (S_ISREG(__b2c__buf.st_mode)) return 1; if (S_ISDIR(__b2c__buf.st_mode)) return 2;" TO g_HFILE
WRITELN "if (S_ISCHR(__b2c__buf.st_mode)) return 3; if (S_ISBLK(__b2c__buf.st_mode)) return 4; if (S_ISFIFO(__b2c__buf.st_mode)) return 5;" TO g_HFILE
WRITELN "if (S_ISLNK(__b2c__buf.st_mode)) return 6; if (S_ISSOCK(__b2c__buf.st_mode)) return 7; return 0;}" TO g_HFILE
WRITELN "#define FILETYPE(x) __b2c__filetype(x)" TO g_HFILE
WRITELN "long __b2c__search(FILE* __b2c__x, char* __b2c__y){long __b2c__off, __b2c__pos; char* __b2c__ptr; size_t __b2c__tot;" TO g_HFILE
WRITELN "if(__b2c__x == NULL && !__b2c__trap){ERROR = 2; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}" TO g_HFILE
WRITELN "if(__b2c__y == NULL && !__b2c__trap){ERROR = 25; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}" TO g_HFILE
WRITELN "__b2c__pos = ftell(__b2c__x); __b2c__ptr = (char*)malloc((strlen(__b2c__y)+1)*sizeof(char)); __b2c__off = 0; do {" TO g_HFILE
WRITELN "fseek(__b2c__x, __b2c__off, SEEK_SET);memset(__b2c__ptr, 0, sizeof(char)*(strlen(__b2c__y)+1));" TO g_HFILE
WRITELN "__b2c__tot = fread(__b2c__ptr, sizeof(char), strlen(__b2c__y), __b2c__x);__b2c__off+=1;" TO g_HFILE
WRITELN "} while(!feof(__b2c__x) && strncmp(__b2c__ptr, __b2c__y, strlen(__b2c__y)));" TO g_HFILE
WRITELN "if(strncmp(__b2c__ptr, __b2c__y, strlen(__b2c__y))) __b2c__off = 0; fseek(__b2c__x, __b2c__pos, SEEK_SET); free(__b2c__ptr); return (--__b2c__off);}" TO g_HFILE
WRITELN "#define SEARCH(x, y) __b2c__search(x, y)" TO g_HFILE
WRITELN "char *__b2c__exec(char *__b2c__x, ...){int __b2c__r, __b2c__len, __b2c__i, __b2c__page; int __b2c__wpipe[2], __b2c__rpipe[2]; char *__b2c__str, *__b2c__ans = NULL; va_list __b2c__ap;" TO g_HFILE
WRITELN "va_start(__b2c__ap, __b2c__x); __b2c__str = va_arg (__b2c__ap, char*); va_end(__b2c__ap); if (pipe (__b2c__rpipe) < 0 || pipe (__b2c__wpipe) < 0){if(!__b2c__trap) {ERROR=29;fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}}" TO g_HFILE
WRITELN "if ((__b2c__r = fork ()) < 0){if(!__b2c__trap) {ERROR=29;fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}} else if (__b2c__r == 0){" TO g_HFILE
WRITELN "close(__b2c__wpipe[1]);close (__b2c__rpipe[0]);dup2 (__b2c__wpipe[0], STDIN_FILENO);close (__b2c__wpipe[0]);dup2 (__b2c__rpipe[1], STDOUT_FILENO);close (__b2c__rpipe[1]); __b2c__r = system (__b2c__x); if(WIFEXITED(__b2c__r)) RETVAL = WEXITSTATUS(__b2c__r); else RETVAL=0; exit(RETVAL);}" TO g_HFILE
WRITELN "else{close (__b2c__wpipe[0]);close (__b2c__rpipe[1]); __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_BUFFER_SIZE, "*sizeof(char) + 1);__b2c__ans = (char*)malloc(", g_BUFFER_SIZE, " *sizeof(char)); __b2c__len = 0;__b2c__page = 0;" TO g_HFILE
WRITELN "if(__b2c__str!=NULL) __b2c__i = write(__b2c__wpipe[1], __b2c__str, strlen(__b2c__str)+1); wait(&RETVAL); RETVAL = WEXITSTATUS(RETVAL); do{__b2c__i = read (__b2c__rpipe[0], __b2c__ans, ", g_BUFFER_SIZE, ");if (__b2c__i == -1 && !__b2c__trap){ERROR=30;fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}" TO g_HFILE
WRITELN "if (__b2c__i == 0)break;if (__b2c__len + __b2c__i > ", g_BUFFER_SIZE, " *__b2c__page + 1){__b2c__page++;__b2c__sbuffer[__b2c__sbuffer_ptr] = realloc (__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_BUFFER_SIZE, "*__b2c__page + 1);" TO g_HFILE
WRITELN "if (__b2c__sbuffer[__b2c__sbuffer_ptr] == NULL && !__b2c__trap){ERROR=6; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } memcpy (__b2c__sbuffer[__b2c__sbuffer_ptr] + __b2c__len, __b2c__ans, __b2c__i);" TO g_HFILE
WRITELN " __b2c__len += __b2c__i;} while (__b2c__i > 0); __b2c__sbuffer[__b2c__sbuffer_ptr][__b2c__len] = '\\0';close (__b2c__wpipe[1]);" TO g_HFILE
WRITELN "close (__b2c__rpipe[0]);free (__b2c__ans);} return (__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define EXEC", g_STRINGSIGN$, "(...) __b2c__exec(__VA_ARGS__, (char*)NULL)" TO g_HFILE
WRITELN "#define ENDFILE(x) feof(x)" TO g_HFILE
WRITELN "#define TELL(x) ftell(x)" TO g_HFILE
WRITELN "#define HEX", g_STRINGSIGN$, "(x) __b2c__dec2hex(x)" TO g_HFILE
WRITELN "#define DEC(x) __b2c__hex2dec(x)" TO g_HFILE
WRITELN "#define ASC(x) __b2c__char2asc(x)" TO g_HFILE
WRITELN "#define CHR", g_STRINGSIGN$, "(__b2c__x) __b2c__asc2char(__b2c__x)" TO g_HFILE
WRITELN "#define MEMTELL(x) (long)x" TO g_HFILE
WRITELN "/* Dynamic loading, errors */" TO g_HFILE
WRITELN "#include <dlfcn.h>" TO g_HFILE
WRITELN "#include <errno.h>" TO g_HFILE
WRITELN "/* GETKEY */" TO g_HFILE
WRITELN "#include <termios.h>" TO g_HFILE
WRITELN "long __b2c__getch(){long __b2c__ch; struct termios __b2c__oldt, __b2c__newt; tcgetattr(STDIN_FILENO, &__b2c__oldt);" TO g_HFILE
WRITELN "__b2c__newt = __b2c__oldt; __b2c__newt.c_lflag &= ~(ICANON | ECHO); __b2c__newt.c_cc[VMIN]=1; __b2c__newt.c_cc[VTIME]=0; tcsetattr(STDIN_FILENO, TCSANOW, &__b2c__newt);" TO g_HFILE
WRITELN "__b2c__ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &__b2c__oldt); return __b2c__ch;} " TO g_HFILE
WRITELN "#define GETKEY __b2c__getch()" TO g_HFILE
WRITELN "long __b2c__getxy(int __b2c__type){char __b2c__asw[", g_BUFFER_SIZE, "]; struct termios __b2c__old, __b2c__new; int __b2c__len, __b2c__x, __b2c__y; ssize_t __b2c__tot;" TO g_HFILE
WRITELN "tcgetattr(STDIN_FILENO, &__b2c__old); __b2c__new = __b2c__old;__b2c__new.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &__b2c__new);" TO g_HFILE
WRITELN "__b2c__tot = write(STDOUT_FILENO, \"\\033[6n\", strlen(\"\\033[6n\")); __b2c__len = read(STDIN_FILENO, __b2c__asw, ", g_BUFFER_SIZE, ");__b2c__asw[__b2c__len] = '\\0'; " TO g_HFILE
WRITELN "tcsetattr(STDIN_FILENO, TCSANOW, &__b2c__old); sscanf(__b2c__asw, \"\\033[%d;%dR\", &__b2c__y, &__b2c__x); if (!__b2c__type) return(long)__b2c__x; return(long)__b2c__y;}" TO g_HFILE
WRITELN "#define GETX __b2c__getxy(0)" TO g_HFILE
WRITELN "#define GETY __b2c__getxy(1)" TO g_HFILE
WRITELN "long __b2c__screen(int __b2c__type){long __b2c__x; fprintf(stdout,\"\\033[s\"); fprintf(stdout,\"\\033[?25l\"); fprintf(stdout,\"\\033[999;999H\"); fflush(stdout);" TO g_HFILE
WRITELN "__b2c__x = __b2c__getxy(__b2c__type); fprintf(stdout,\"\\033[u\"); fprintf(stdout,\"\\033[?25h\"); fflush(stdout); return(__b2c__x); }" TO g_HFILE
WRITELN "#define COLUMNS __b2c__screen(0)" TO g_HFILE
WRITELN "#define ROWS __b2c__screen(1)" TO g_HFILE
WRITELN "/* Constants, logical stuff */" TO g_HFILE
WRITELN "#define PI 3.14159265" TO g_HFILE
WRITELN "#define NOT(__b2c__x) (!(__b2c__x))" TO g_HFILE
WRITELN "#define AND &&" TO g_HFILE
WRITELN "#define OR ||" TO g_HFILE
WRITELN "#define EQ ==" TO g_HFILE
WRITELN "#define IS ==" TO g_HFILE
WRITELN "#define NE !=" TO g_HFILE
WRITELN "#define ISNOT !=" TO g_HFILE
WRITELN "#define TRUE 1" TO g_HFILE
WRITELN "#define FALSE 0" TO g_HFILE
WRITELN "#define NL", g_STRINGSIGN$, " \"\\n\"" TO g_HFILE
WRITELN "#define STRING char*" TO g_HFILE
WRITELN "#define NUMBER long" TO g_HFILE
WRITELN "#define FLOATING double" TO g_HFILE
WRITELN "#define ISTRUE(__b2c__x) (__b2c__x!=0)" TO g_HFILE
WRITELN "#define ISFALSE(__b2c__x) (__b2c__x==0)" TO g_HFILE
WRITELN "#define SIZEOF(__b2c__x) sizeof(__b2c__x)" TO g_HFILE
WRITELN "/* Date and time */" TO g_HFILE
WRITELN "#include <time.h>" TO g_HFILE
WRITELN "#define NOW (long)time(NULL)" TO g_HFILE
WRITELN "long __b2c__time(time_t __b2c__now, int __b2c__which){struct tm *ts; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr],", g_MAX_DIGITS, ");" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, ", g_MAX_DIGITS, "); ts = localtime(&__b2c__now); switch(__b2c__which) { case 1: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%d\", ts); break;" TO g_HFILE
WRITELN "case 2: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%m\", ts); break; case 3: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%Y\", ts); break;" TO g_HFILE
WRITELN "case 4: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%H\", ts); break; case 5: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%M\", ts); break;" TO g_HFILE
WRITELN "case 6: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%S\", ts); break; case 7: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%W\", ts); break;}" TO g_HFILE
WRITELN "return(atol(__b2c__sbuffer[__b2c__sbuffer_ptr]));}" TO g_HFILE
WRITELN "#define DAY(x) __b2c__time(x, 1)" TO g_HFILE
WRITELN "#define MONTH(x) __b2c__time(x, 2)" TO g_HFILE
WRITELN "#define YEAR(x) __b2c__time(x, 3)" TO g_HFILE
WRITELN "#define HOUR(x) __b2c__time(x, 4)" TO g_HFILE
WRITELN "#define MINUTE(x) __b2c__time(x, 5)" TO g_HFILE
WRITELN "#define SECOND(x) __b2c__time(x, 6)" TO g_HFILE
WRITELN "#define WEEK(x) __b2c__time(x, 7)" TO g_HFILE
WRITELN "char* __b2c__datename(time_t __b2c__now, int __b2c__which){struct tm *ts; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ");" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, ", g_MAX_DIGITS, "); ts = localtime(&__b2c__now); switch(__b2c__which){case 1: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%A\", ts); break;" TO g_HFILE
WRITELN "case 2: strftime(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_MAX_DIGITS, ", \"%B\", ts); break;} return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define WEEKDAY", g_STRINGSIGN$, "(x) __b2c__datename(x, 1)" TO g_HFILE
WRITELN "#define MONTH", g_STRINGSIGN$, "(x) __b2c__datename(x, 2)" TO g_HFILE
WRITELN "unsigned long __b2c__epoch(int __b2c__year, int __b2c__month, int __b2c__day, int __b2c__hour, int __b2c__minute, int __b2c__second){" TO g_HFILE
WRITELN "struct tm tm; time_t __b2c__t; tm.tm_year = __b2c__year - 1900; tm.tm_mon = __b2c__month - 1; tm.tm_mday = __b2c__day;" TO g_HFILE
WRITELN "tm.tm_hour = __b2c__hour; tm.tm_min = __b2c__minute; tm.tm_sec = __b2c__second;" TO g_HFILE
WRITELN "tm.tm_isdst = -1; __b2c__t = mktime(&tm); if (__b2c__t == -1) return (0); return(long) __b2c__t; }" TO g_HFILE
WRITELN "#define TIMEVALUE(x,y,z,a,b,c) __b2c__epoch(x,y,z,a,b,c)" TO g_HFILE
WRITELN "char* __b2c__os(void){struct utsname __b2c__buf; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_BUFFER_SIZE, ");" TO g_HFILE
WRITELN "memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, ", g_BUFFER_SIZE, "); if(uname(&__b2c__buf) < 0 && !__b2c__trap) {ERROR = 26; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}" TO g_HFILE
WRITELN "strcpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__buf.sysname); strcat(__b2c__sbuffer[__b2c__sbuffer_ptr], \" \");" TO g_HFILE
WRITELN "strcat(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__buf.machine); return(__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define OS", g_STRINGSIGN$, " __b2c__os()" TO g_HFILE
WRITELN "/* Peek and Poke */" TO g_HFILE
WRITELN "struct stat __b2c__sb;" TO  g_HFILE
WRITELN "void __b2c__memory__check(void* __b2c__x) {if (stat(__b2c__x, &__b2c__sb) == -1 && errno == EFAULT) {ERROR = 1;} }" TO g_HFILE
WRITELN "long __b2c__malloc(long __b2c__x) {void *__b2c__mem; if(__b2c__x==0) return(0); switch(__b2c__memtype) {case 1: __b2c__mem = calloc(__b2c__x+__b2c__option_memstream, sizeof(char)); break;" TO g_HFILE
WRITELN "case 2: __b2c__mem = calloc(__b2c__x+__b2c__option_memstream, sizeof(short)); break; case 3: __b2c__mem = calloc(__b2c__x+__b2c__option_memstream, sizeof(int)); break;" TO g_HFILE
WRITELN "case 4: __b2c__mem = calloc(__b2c__x+__b2c__option_memstream, sizeof(long)); break; case 5: __b2c__mem = calloc(__b2c__x+__b2c__option_memstream, sizeof(float)); break;" TO g_HFILE
WRITELN "case 6: __b2c__mem = calloc(__b2c__x+__b2c__option_memstream, sizeof(double)); break; case 7: __b2c__mem = calloc(__b2c__x+__b2c__option_memstream, sizeof(char)); break;}" TO g_HFILE
WRITELN "if(__b2c__mem == NULL && !__b2c__trap) {ERROR = 6; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} return(long)__b2c__mem;}" TO g_HFILE
WRITELN "#define MEMORY(__b2c__x) __b2c__malloc(__b2c__x)" TO g_HFILE
WRITELN "void *__b2c__realloc(void* __b2c__x, long __b2c__y) {if(__b2c__x == NULL) return (NULL); if(!__b2c__trap) {__b2c__memory__check((char*)__b2c__x);" TO g_HFILE
WRITELN "if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } switch(__b2c__memtype) {case 1: __b2c__x = realloc((void*)__b2c__x, sizeof(char)*(__b2c__y+1)); break;" TO g_HFILE
WRITELN "case 2: __b2c__x = realloc((void*)__b2c__x, sizeof(short)*(__b2c__y+1)); break; case 3: __b2c__x = realloc((void*)__b2c__x, sizeof(int)*(__b2c__y+1)); break;" TO g_HFILE
WRITELN "case 4: __b2c__x = realloc((void*)__b2c__x, sizeof(long)*(__b2c__y+1)); break; case 5: __b2c__x = realloc((void*)__b2c__x, sizeof(float)*(__b2c__y+1)); break;" TO g_HFILE
WRITELN "case 6: __b2c__x = realloc((void*)__b2c__x, sizeof(double)*(__b2c__y+1)); break; case 7: __b2c__x = realloc((void*)__b2c__x, sizeof(char)*(__b2c__y+1)); break;}" TO g_HFILE
WRITELN "if(__b2c__x == NULL && !__b2c__trap) {ERROR = 6; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} return (__b2c__x);}" TO g_HFILE
WRITELN "#define RESIZE(__b2c__x, __b2c__y) __b2c__realloc((void*)__b2c__x, __b2c__y)" TO g_HFILE
WRITELN "char __b2c__peek(char* __b2c__x) {if(!__b2c__trap) {__b2c__memory__check((char*) __b2c__x); if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } return((char)*__b2c__x);}" TO g_HFILE
WRITELN "short __b2c__peeks(short* __b2c__x) {if(!__b2c__trap) {__b2c__memory__check((short*) __b2c__x); if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } return((short)*__b2c__x);}" TO g_HFILE
WRITELN "int __b2c__peeki(int* __b2c__x) {if(!__b2c__trap) {__b2c__memory__check((int*) __b2c__x); if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } return((int)*__b2c__x);}" TO g_HFILE
WRITELN "long __b2c__peekl(long* __b2c__x) {if(!__b2c__trap) {__b2c__memory__check((long*) __b2c__x); if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } return((long)*__b2c__x);}" TO g_HFILE
WRITELN "float __b2c__peekf(float* __b2c__x) {if(!__b2c__trap) {__b2c__memory__check((float*) __b2c__x); if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } return((float)*__b2c__x);}" TO g_HFILE
WRITELN "double __b2c__peekd(double* __b2c__x) {if(!__b2c__trap) {__b2c__memory__check((double*) __b2c__x); if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } return((double)*__b2c__x);}" TO g_HFILE
WRITELN "char __b2c__peekv(char* __b2c__x) {if(!__b2c__trap) {__b2c__memory__check((char*) __b2c__x); if(ERROR) {fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);} } return((char)*__b2c__x);}" TO g_HFILE
WRITELN "#define PEEK(__b2c__x) (__b2c__memtype==1 ? (unsigned char)__b2c__peek((char*)__b2c__x) : (__b2c__memtype==2 ? (unsigned short)__b2c__peeks((short*)__b2c__x) : (__b2c__memtype==3 ? (unsigned int)__b2c__peeki((int*)__b2c__x) : \\" TO g_HFILE
WRITELN "(__b2c__memtype==4 ? (unsigned long)__b2c__peekl((long*)__b2c__x) : ( __b2c__memtype==5 ? (float)__b2c__peekf((float*)__b2c__x) : (__b2c__memtype==6 ? (double)__b2c__peekd((double*)__b2c__x) : (unsigned char)__b2c__peekv((char*)__b2c__x) ))))))" TO g_HFILE
WRITELN "#define ADDRESS(__b2c__x) (long)(&__b2c__x)" TO g_HFILE
WRITELN "/* Network variables and functions */" TO g_HFILE
WRITELN "struct timeval __b2c__to; struct hostent *__b2c__he;  char *__b2c__host; char *__b2c__port; int __b2c__yes = 1; struct sockaddr_in __b2c__addr; " TO g_HFILE
WRITELN "int __b2c__result; char __b2c__data_client[", g_BUFFER_SIZE, "] = { 0 }; char __b2c__data_server[", g_BUFFER_SIZE, "] = { 0 }; int __b2c__handle;" TO g_HFILE
WRITELN "long __b2c__netpeek(int __b2c__fd, int __b2c__usec){fd_set __b2c__rfds; struct timeval __b2c__tv; long __b2c__retval; struct termios __b2c__oldt, __b2c__newt;" TO g_HFILE
WRITELN "if(__b2c__fd == STDIN_FILENO){tcgetattr(STDIN_FILENO, &__b2c__oldt); __b2c__newt = __b2c__oldt; __b2c__newt.c_lflag &= ~(ICANON | ECHO); __b2c__newt.c_cc[VMIN]=1; __b2c__newt.c_cc[VTIME]=0; tcsetattr(STDIN_FILENO, TCSANOW, &__b2c__newt);}" TO g_HFILE
WRITELN "FD_ZERO(&__b2c__rfds); FD_SET(__b2c__fd, &__b2c__rfds);__b2c__tv.tv_usec = (__b2c__usec%1000)*1000; __b2c__tv.tv_sec = __b2c__usec/1000;" TO g_HFILE
WRITELN "__b2c__retval = select(__b2c__fd + 1, &__b2c__rfds, NULL, NULL, &__b2c__tv); if (__b2c__retval == -1 && !__b2c__trap) {ERROR = 16; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR);}" TO g_HFILE
WRITELN "if(__b2c__fd == STDIN_FILENO){if(__b2c__retval) if(read(__b2c__fd, &__b2c__retval, 1)==0) __b2c__retval=0; tcsetattr(STDIN_FILENO, TCSANOW, &__b2c__oldt);} return(__b2c__retval);}" TO g_HFILE
WRITELN "#define WAIT(x, y) __b2c__netpeek(x, y)" TO g_HFILE
WRITELN "char* __b2c__nethost(char* __b2c__host) {int __b2c__y; int __b2c__flag = 0; struct in_addr __b2c__address; __b2c__sbuffer_ptr++; if(__b2c__sbuffer_ptr >= ", g_MAX_BUFFERS, ") __b2c__sbuffer_ptr=0;" TO g_HFILE
WRITELN "__b2c__sbuffer[__b2c__sbuffer_ptr] = (char*)realloc(__b2c__sbuffer[__b2c__sbuffer_ptr], ", g_BUFFER_SIZE, "); memset(__b2c__sbuffer[__b2c__sbuffer_ptr], 0, ", g_BUFFER_SIZE, ");" TO g_HFILE
WRITELN "for(__b2c__y=0; __b2c__y < strlen(__b2c__host); __b2c__y++) {if(isalpha(*(__b2c__host+__b2c__y))) {__b2c__flag = 1; break;}} if(__b2c__flag) __b2c__he = gethostbyname(__b2c__host); " TO g_HFILE
WRITELN "else {if(inet_aton(__b2c__host, &__b2c__address)) __b2c__he = gethostbyaddr((void*)&__b2c__address, sizeof(struct in_addr), AF_INET); } if (__b2c__he == NULL || __b2c__he->h_addr == NULL || __b2c__he->h_name == NULL)" TO g_HFILE
WRITELN "{if(!__b2c__trap){ERROR = 11; fprintf(stderr, \"%s\\n\", ERR", g_STRINGSIGN$, "(ERROR)); exit(ERROR); } else strncpy(__b2c__sbuffer[__b2c__sbuffer_ptr], \"Host not found\", ", g_BUFFER_SIZE ,"-1); } else {if(__b2c__flag) {__b2c__addr.sin_addr = *((struct in_addr *)__b2c__he->h_addr);" TO g_HFILE
WRITELN "strncpy(__b2c__sbuffer[__b2c__sbuffer_ptr], inet_ntoa(__b2c__addr.sin_addr), ", g_BUFFER_SIZE, "-1);} else strncpy(__b2c__sbuffer[__b2c__sbuffer_ptr], __b2c__he->h_name, ", g_BUFFER_SIZE, "-1);} return (__b2c__sbuffer[__b2c__sbuffer_ptr]);}" TO g_HFILE
WRITELN "#define HOST", g_STRINGSIGN$, "(__b2c__x) __b2c__nethost(__b2c__x)" TO g_HFILE
WRITELN "/* Regex */" TO g_HFILE
WRITELN "#include <regex.h>" TO g_HFILE
WRITELN "long __b2c__regex(char* __b2c__x, char* __b2c__y){regex_t __b2c__reg; int __b2c__reti; char __b2c__buf[100]; __b2c__reti = regcomp(&__b2c__reg, __b2c__y, REG_EXTENDED|REG_NOSUB);" TO g_HFILE
WRITELN "if(!__b2c__trap && __b2c__reti){ERROR=27; fprintf(stderr, \"%s: \", ERR", g_STRINGSIGN$, "(ERROR)); regerror(__b2c__reti, &__b2c__reg, __b2c__buf, sizeof(__b2c__buf)); fprintf(stderr, \"%s\\n\", __b2c__buf);" TO g_HFILE
WRITELN "exit(ERROR);} __b2c__reti = regexec(&__b2c__reg, __b2c__x, 0, NULL, 0);" TO g_HFILE
WRITELN "regfree(&__b2c__reg); if( !__b2c__reti ) return (1); else return (0);}" TO g_HFILE
WRITELN "#define REGEX(x, y) __b2c__regex(x, y)" TO g_HFILE
WRITELN "/* Declare reserved variable 'ARGUMENT' */" TO g_HFILE
WRITELN "int __b2c__counter;" TO g_HFILE
WRITELN "int __b2c__arglen = 0;" TO g_HFILE
WRITELN "char *ARGUMENT", g_STRINGSIGN$, ";" TO g_HFILE
WRITELN "/* Initialize stack arrays and pointer */" TO g_HFILE
WRITELN "char **__b2c__stringstack = NULL; double *__b2c__doublestack = NULL;" TO g_HFILE
WRITELN "long *__b2c__longstack = NULL; int *__b2c__typestack = NULL;" TO g_HFILE
WRITELN "int __b2c__stackptr = 0;" TO g_HFILE
' Signal function
WRITELN "/* Signal trapping activated with TRAP */" TO g_HFILE
WRITELN "void __b2c__catch_signal(int sig){" TO g_HFILE
WRITELN "switch (sig) {case SIGABRT: fprintf(stderr, \"ERROR: signal ABORT received - internal error. Try to compile the program with TRAP LOCAL to find the cause.\\n\"); break;" TO g_HFILE
WRITELN "case SIGFPE: fprintf(stderr, \"ERROR: signal for FPE received - division by zero? Examine the calculations in the program.\\n\"); break;" TO g_HFILE
WRITELN "case SIGSEGV: fprintf(stderr, \"ERROR: signal for SEGMENTATION FAULT received - memory invalid or array out of bounds? Try to compile the program with TRAP LOCAL to find the cause.\\n\"); break;" TO g_HFILE
WRITELN "case SIGILL: fprintf(stderr, \"ERROR: signal for ILLEGAL INSTRUCTION received - executing the program on other hardware? Try to recompile the program from scratch.\\n\"); break;} exit(sig);}" TO g_HFILE
' Makedir function
WRITELN "int __b2c__makedir(char* __b2c__in){char *__b2c__i, *__b2c__dir; if(__b2c__in == NULL || strlen(__b2c__in)==0) return 0; if(*__b2c__in != '/'){__b2c__dir = (char*)malloc((strlen(__b2c__in)+2)*sizeof(char));" TO g_HFILE
WRITELN "strncpy(__b2c__dir, \"./\", 2); __b2c__dir = strcat(__b2c__dir, __b2c__in);} else __b2c__dir = strdup(__b2c__in); __b2c__i = __b2c__dir; do { __b2c__i++; while(*__b2c__i != '/' && *__b2c__i != '\\0') __b2c__i++;" TO g_HFILE
WRITELN "if(*__b2c__i == '/') {*__b2c__i = '\\0'; mkdir(__b2c__dir, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); *__b2c__i = '/';} else if (*__b2c__i == '\\0') mkdir(__b2c__dir, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);" TO g_HFILE
WRITELN "if(errno != EEXIST && errno != 0) {free(__b2c__dir); return errno;} } while (*__b2c__i != '\\0'); free(__b2c__dir); return 0;}" TO g_HFILE
' Add error function
WRITELN "/* Initialize error function */" TO g_HFILE
WRITELN "char *ERR", g_STRINGSIGN$, "(int __b2c__nr){static char __b2c__warn[", g_BUFFER_SIZE, "] = { 0 }; const char* __b2c__err;" TO g_HFILE
WRITELN "switch(__b2c__nr){" TO g_HFILE
WRITELN "case 0: strcpy(__b2c__warn,\"Success\"); break;" TO g_HFILE
WRITELN "case 1: strcpy(__b2c__warn,\"Trying to access illegal memory: \"); strncat(__b2c__warn,strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 2: strcpy(__b2c__warn,\"Error opening file: \"); strncat(__b2c__warn,strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 3: strcpy(__b2c__warn, \"Could not open library \"); __b2c__err = dlerror(); if(__b2c__err!=NULL) strncat(__b2c__warn, __b2c__err, ", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 4: strcpy(__b2c__warn, \"Symbol not found in library \"); __b2c__err = dlerror(); if(__b2c__err!=NULL) strncat(__b2c__warn, __b2c__err, ", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 5: strcpy(__b2c__warn, \"Wrong hexvalue: \"); strncat(__b2c__warn, strerror(errno), ", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 6: strcpy(__b2c__warn, \"Unable to claim memory.\"); break;" TO g_HFILE
WRITELN "case 7: strcpy(__b2c__warn, \"Unable to delete file: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 8: strcpy(__b2c__warn, \"Could not open directory: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 9: strcpy(__b2c__warn, \"Unable to rename file: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 10: strcpy(__b2c__warn, \"NETWORK argument should contain colon with port number\"); break;" TO g_HFILE
WRITELN "case 11: strcpy(__b2c__warn, \"Could not resolve hostname!\"); break;" TO g_HFILE
WRITELN "case 12: strcpy(__b2c__warn, \"Socket error: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 13: strcpy(__b2c__warn, \"Unable to open address: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 14: strcpy(__b2c__warn, \"Error reading from socket: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 15: strcpy(__b2c__warn, \"Error sending to socket: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 16: strcpy(__b2c__warn, \"Error checking socket: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 17: strcpy(__b2c__warn, \"Unable to bind the specified socket address: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 18: strcpy(__b2c__warn, \"Unable to listen to socket address: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 19: strcpy(__b2c__warn, \"Cannot accept incoming connection: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 20: strcpy(__b2c__warn, \"Unable to remove directory: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 21: strcpy(__b2c__warn, \"Unable to create directory: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 22: strcpy(__b2c__warn, \"Unable to change to directory: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 23: strcpy(__b2c__warn, \"GETENVIRON argument does not exist as environment variable\"); break;" TO g_HFILE
WRITELN "case 24: strcpy(__b2c__warn, \"Unable to stat file: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 25: strcpy(__b2c__warn, \"Search contains illegal string\"); break;" TO g_HFILE
WRITELN "case 26: strcpy(__b2c__warn, \"Cannot return OS name: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 27: strcpy(__b2c__warn, \"Illegal regex expression\"); break;" TO g_HFILE
WRITELN "case 28: strcpy(__b2c__warn, \"Unable to create bidirectional pipes: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 29: strcpy(__b2c__warn, \"Unable to fork process: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "case 30: strcpy(__b2c__warn, \"Cannot read from pipe: \"); strncat(__b2c__warn, strerror(errno),", g_BUFFER_SIZE-48, "); break;" TO g_HFILE
WRITELN "}; ERROR = 0; return(__b2c__warn);}" TO g_HFILE
WRITELN "/* User program definitions */" TO g_HFILE

' Set fileposition for search in header file
g_HEADER_SEARCHPOS = FILELEN(g_HFILE$)

' Initialize the arrayfiles for DATA statement
OPEN STRINGARRAYFILE$ FOR WRITING AS STRINGARRAYFILE
WRITELN "char* __b2c__stringarray[] = {" TO STRINGARRAYFILE
OPEN FLOATARRAYFILE$ FOR WRITING AS FLOATARRAYFILE
WRITELN "double __b2c__floatarray[] = {" TO FLOATARRAYFILE

' There are no imported symbols yet
LET g_IMPORTED$ = ""

' Check if the C Preprocessor needs to run
IF ISTRUE(g_CPP) THEN
    IF ISTRUE(LEN(EXEC$("which cpp 2>/dev/null"))) THEN
	SYSTEM CONCAT$("cpp -P -w ", g_SOURCEFILE$, " ", g_SOURCEFILE$, ".cpp")
	FEED$ = CONCAT$(g_SOURCEFILE$, ".cpp")
	g_TMP_FILES$ = CONCAT$(g_TMP_FILES$, " ", g_SOURCEFILE$, ".cpp")
    ELSE
	PRINT "ERROR: the C Preprocessor 'cpp' not found on this system! Exiting..."
	END 1
    END IF
ELSE
    FEED$ = g_SOURCEFILE$
END IF
LET g_CURFILE$ = MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1)

' Initialize
LET total$ = ""
LET g_COUNTER = 1

' Read source program
OPEN FEED$ FOR READING AS g_SOURCEFILE

WHILE NOT(ENDFILE(g_SOURCEFILE)) DO

    IF NOT(g_SHEBANG) THEN PRINT "\rStarting conversion... ", g_COUNTER, "   ";

    READLN line$ FROM g_SOURCEFILE

    ' Line is not empty?
    IF NOT(ENDFILE(g_SOURCEFILE)) AND LEN(line$) > 0 THEN

	IF EQUAL(RIGHT$(line$, 2), " \\") AND NOT(EQUAL(LEFT$(line$, 3), "REM")) AND NOT(EQUAL(LEFT$(line$, 1), CHR$(39))) THEN
	    total$ = CONCAT$(total$, LEFT$(line$, LEN(line$) - 2))
	ELSE
	    WRITELN "/* noparse ", FEED$, " BACON LINE ", g_COUNTER, " */" TO g_HFILE
	    WRITELN "/* noparse ", FEED$, " BACON LINE ", g_COUNTER, " */" TO g_CFILE
	    total$ = CHOP$(CONCAT$(total$, line$))
	    IF NOT(EQUAL(LEFT$(total$, 3), "REM")) AND NOT(EQUAL( LEFT$(total$, 1), CHR$(39) )) THEN
		Tokenize(total$)
	    END IF
	    LET total$ = ""
	END IF
    ENDIF

    INCR g_COUNTER
WEND

CLOSE FILE g_SOURCEFILE

' Check if enclosed IF/ELIF/ELSE needs to be closed
IF g_IF_PARSE IS 1 THEN WRITELN "}" TO g_CFILE

' Finalize main C-file
WRITELN "__B2C__PROGRAM__EXIT:" TO g_CFILE
WRITELN "return 0;" TO g_CFILE
WRITELN "}" TO g_CFILE

' Finalize STRING ARRAY file for DATA
WRITELN " \"\" };" TO STRINGARRAYFILE

' Finalize FLOAT ARRAY file for DATA
WRITELN " 0.0};" TO FLOATARRAYFILE

' Include functions and subs
SPLIT CHOP$(g_INCLUDE_FILES$) BY " " TO incfiles$ SIZE dim
FOR i = 1 TO dim
    IF LEN(incfiles$[i]) > 0 THEN WRITELN "#include \"", incfiles$[i], CHR$(34) TO g_HFILE
NEXT

' Close all filehandles
CLOSE FILE FLOATARRAYFILE
CLOSE FILE STRINGARRAYFILE
CLOSE FILE g_HFILE
CLOSE FILE g_CFILE

IF NOT(g_SHEBANG) THEN PRINT "\rStarting conversion... done.   "

' Start indentation
IF ISTRUE(g_TMP_PRESERVE) THEN
    IF ISTRUE(LEN(EXEC$("which indent 2>/dev/null"))) THEN
	PRINT "Applying indentation... ";
	SPLIT CHOP$(g_TMP_FILES$) BY " " TO tmpfiles$ SIZE dim
	FOR i = 1 TO dim
	    IF NOT(REGEX(tmpfiles$[i], ".*\\.cpp")) THEN
		IF ISTRUE(INSTR(OS$, "Darwin")) OR ISTRUE(INSTR(OS$, "BSD")) THEN
		    RENAME tmpfiles$[i] TO CONCAT$(tmpfiles$[i], ".BAK")
		    SYSTEM CONCAT$("indent ", tmpfiles$[i], ".BAK ", tmpfiles$[i])
		    DELETE FILE CONCAT$(tmpfiles$[i], ".BAK")
		ELSE
		    SYSTEM CONCAT$("indent ", tmpfiles$[i])
		    DELETE FILE CONCAT$(tmpfiles$[i], "~")
		END IF
	    END IF
	NEXT i
	PRINT "done."
    ELSE
	PRINT "WARNING: 'indent' not found on this system!"
	PRINT "Generated source code cannot be beautified."
    END IF
END IF

' Check if we need to run xgettext
IF g_XGETTEXT THEN
    IF ISTRUE(LEN(EXEC$("which xgettext 2>/dev/null"))) THEN
	PRINT "Executing xgettext... ";
	SYSTEM CONCAT$("xgettext -d ", LEFT$(g_SOURCEFILE$, INSTR(g_SOURCEFILE$, ".")-1), " -s -o ", LEFT$(g_SOURCEFILE$, INSTR(g_SOURCEFILE$, ".")-1), ".pot ", g_TMP_FILES$)
	IF NOT(FILEEXISTS(CONCAT$(LEFT$(g_SOURCEFILE$, INSTR(g_SOURCEFILE$, ".")-1), ".pot"))) THEN
	    PRINT "WARNING: catalog file not created!"
	ELSE
	    PRINT "done."
	END IF
    ELSE
	PRINT "WARNING: 'xgettext' not found on this system!"
    END IF
END IF

' Start compilation
IF ISFALSE(g_NO_COMPILE) THEN

    IF ISFALSE(LEN(EXEC$(CONCAT$("which ", g_CCNAME$, " 2>/dev/null")))) THEN
	PRINT "WARNING: '", g_CCNAME$, "' not found on this system!"
	PRINT "Generated source code cannot be compiled."
	END 0
    END IF

    ' Make sure GCC uses English localization
    SETENVIRON "LANG", "C"

    IF NOT(g_SHEBANG) THEN
	PRINT "Starting compilation... ";
	SYSTEM CONCAT$(g_CCNAME$, " ", g_CCFLAGS$, " -o ", LEFT$(g_SOURCEFILE$, LEN(g_SOURCEFILE$) - 4), g_BINEXT$, " ", g_CFILE$, " ", g_LDFLAGS$, " > ", g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".log 2>&1")
    ELSE
	SYSTEM CONCAT$(g_CCNAME$, " ", g_CCFLAGS$, " -o ", CONCAT$(g_TEMPDIR$, "/", LEFT$(g_SOURCEFILE$, LEN(g_SOURCEFILE$) - 4)), g_BINEXT$, " ", g_CFILE$, " ", g_LDFLAGS$, " > ", g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".log 2>&1")
    END IF

    ' Add temp file
    g_TMP_FILES$ = CONCAT$(g_TMP_FILES$, " ", g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".log")

    IF ISFALSE(FILELEN(CONCAT$(g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".log"))) THEN
	IF g_SHEBANG THEN
	    SYSTEM CONCAT$(g_TEMPDIR$, "/", LEFT$(g_SOURCEFILE$, LEN(g_SOURCEFILE$) - 4))
	ELSE
	    PRINT "done."
	    PRINT "Program '", LEFT$(g_SOURCEFILE$, LEN(g_SOURCEFILE$) - 4), g_BINEXT$, "' ready."
	END IF
    ELSE
	' Only print first error
	PRINT "Compiler emits messages!"
	OPEN CONCAT$(g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".log") FOR READING AS errlog
	WHILE NOT(ENDFILE(errlog)) DO
	    READLN g_ERROR$ FROM errlog
	    IF (NOT(INSTR(g_ERROR$, "from ")) OR INSTR(g_ERROR$, "from") > INSTR(g_ERROR$, "error:")) AND REGEX(g_ERROR$, "[0-9]+") AND REGEX(g_ERROR$, "\\: error\\:") THEN
		g_ERRORTXT$ = CONCAT$("Cause:", NL$, TAB$(1), MID$(g_ERROR$, INSTR(g_ERROR$, "error:") + 6))
		g_FILE_LINE$ = MID$(g_ERROR$, 1, INSTR(g_ERROR$, "error:") - 1)
		BREAK
	    ELIF (NOT(INSTR(g_ERROR$, "from ")) OR INSTR(g_ERROR$, "from") > INSTR(g_ERROR$, "Error:")) AND REGEX(g_ERROR$, "[0-9]+") AND REGEX(g_ERROR$, "\\: Error\\:") THEN
		g_ERRORTXT$ = CONCAT$("Cause:", NL$, TAB$(1), MID$(g_ERROR$, INSTRREV(g_ERROR$, ":") + 1))
		g_FILE_LINE$ = MID$(g_ERROR$, INSTR(g_ERROR$, "Error: ") + 7)
		BREAK
	    ELIF (NOT(INSTR(g_ERROR$, "from ")) OR INSTR(g_ERROR$, "from") > INSTR(g_ERROR$, "warning:")) AND REGEX(g_ERROR$, "[0-9]+") AND REGEX(g_ERROR$, "\\: warning\\:") THEN
		g_ERRORTXT$ = CONCAT$("Cause:", NL$, TAB$(1), MID$(g_ERROR$, INSTR(g_ERROR$, "warning:") + 8))
		g_FILE_LINE$ = MID$(g_ERROR$, 1, INSTR(g_ERROR$, "warning:") - 1)
		BREAK
	    ELIF (NOT(INSTR(g_ERROR$, "from ")) OR INSTR(g_ERROR$, "from") > INSTR(g_ERROR$, ":")) AND REGEX(g_ERROR$, "[0-9]+\\:") THEN
		g_ERRORTXT$ = CONCAT$("Cause:", NL$, TAB$(1), MID$(g_ERROR$, INSTRREV(g_ERROR$, ":") + 1))
		g_FILE_LINE$ = MID$(g_ERROR$, 1, INSTRREV(g_ERROR$, ":") - 1)
		BREAK
	    END IF
	WEND
	CLOSE FILE errlog

	' Restore $-symbol if there is any
	g_ERRORTXT$ = REPLACE$(g_ERRORTXT$, g_STRINGSIGN$, "$")

	' Get the file where the error is
	g_FILE$ = MID$(g_FILE_LINE$, 1, INSTR(g_FILE_LINE$, ":") - 1)
	' Tru64Unix helper
	g_FILE$ = MID$(g_FILE$, 1, INSTR(g_FILE$, ",") - 1)

	' Non-gcc or parse problem (file does not exist)
	IF ISFALSE(LEN(g_ERROR$)) OR ISTRUE(INSTR(g_CCFLAGS$, "Wall")) OR NOT(FILEEXISTS(g_FILE$)) THEN
	    PRINT
	    SYSTEM CONCAT$("cat ", g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".log")
	    PRINT
	ELSE
	    ' Get the error string from the logfile
	    IF INSTR(g_FILE_LINE$, "line") THEN
		g_LINE = VAL(MID$(g_FILE_LINE$, INSTR(g_FILE_LINE$, "line") + 4))
	    ELSE
		g_LINE = VAL(MID$(g_FILE_LINE$, INSTR(g_FILE_LINE$, ":") + 1))
	    END IF
	    ' Initiate error file name and error line in C code
	    g_FEED$ = MID$(g_FILE_LINE$, 1, INSTR(g_FILE_LINE$, ":")-1)
	    g_CURLINE$ = CONCAT$(STR$(g_LINE), " ")
	    g_COUNTER = 1
	    OPEN g_FILE$ FOR READING AS errlog
	    WHILE NOT(ENDFILE(errlog)) DO
		READLN line$ FROM errlog
		IF INSTR(line$, "BACON LINE") AND INSTR(line$, "noparse") THEN
		    g_CURLINE$ = MID$(line$, INSTR(line$, "BACON LINE") + 10)
		    g_FEED$ = MID$(line$, INSTR(line$, "noparse") + 7)
		    g_FEED$ = CHOP$(MID$(g_FEED$, 1, INSTR(g_FEED$, " BACON LINE")))
		END IF
		IF g_COUNTER IS g_LINE THEN
		    COUNTER = 1
		    OPEN g_FEED$ FOR READING AS g_SOURCEFILE
		    WHILE NOT(ENDFILE(g_SOURCEFILE)) DO
			READLN line$ FROM g_SOURCEFILE
			IF COUNTER IS VAL(MID$(g_CURLINE$, 1, INSTRREV(g_CURLINE$, " "))) THEN
			    PRINT NL$, "Problem:", NL$, TAB$(1), " file '", g_FEED$, "' line ", COUNTER, ": ", CHOP$(line$)
			    PRINT g_ERRORTXT$, NL$
			    BREAK
			END IF
			INCR COUNTER
		    WEND
		    CLOSE FILE g_SOURCEFILE
		    BREAK
		END IF
		INCR g_COUNTER
	    WEND
	    CLOSE FILE errlog
	END IF
	' Preserve temp files
	g_TMP_PRESERVE = 1
    END IF
END IF

' Cleanup
IF ISFALSE(g_TMP_PRESERVE) THEN
    SPLIT CHOP$(g_TMP_FILES$) BY " " TO tmpfiles$ SIZE dim
    FOR i = 1 TO dim
	SYSTEM CONCAT$("rm ", tmpfiles$[i])
    NEXT i
ELIF g_CPP IS 1 THEN
    RENAME CONCAT$(g_SOURCEFILE$, ".cpp") TO CONCAT$(g_TEMPDIR$, "/", MID$(g_SOURCEFILE$, INSTRREV(g_SOURCEFILE$, "/") + 1), ".cpp")
END IF