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
|
/*1:*/
#line 66 "cwebdir/ctangle.w"
/*5:*/
#line 60 "cwebdir/comm-w2c.h"
#include <ctype.h>
#include <kpathsea/simpletypes.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef HAVE_GETTEXT
#define HAVE_GETTEXT 0
#endif
#line 72 "cwebdir/comm-w2c.h"
#if HAVE_GETTEXT
#include <libintl.h>
#else
#line 76 "cwebdir/comm-w2c.h"
#define gettext(a) a
#endif
#line 78 "cwebdir/comm-w2c.h"
/*:5*/
#line 67 "cwebdir/ctangle.w"
#define banner "This is CTANGLE, Version 4.9" \
\
#define _(s) gettext(s) \
#define and_and 04
#define lt_lt 020
#define gt_gt 021
#define plus_plus 013
#define minus_minus 01
#define minus_gt 031
#define non_eq 032
#define lt_eq 034
#define gt_eq 035
#define eq_eq 036
#define or_or 037
#define dot_dot_dot 016
#define colon_colon 06
#define period_ast 026
#define minus_gt_ast 027 \
#define compress(c) if(loc++<=limit) return c \
#define xisalpha(c) (isalpha((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisdigit(c) (isdigit((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisspace(c) (isspace((int) (c) ) &&((eight_bits) (c) <0200) )
#define xislower(c) (islower((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisupper(c) (isupper((int) (c) ) &&((eight_bits) (c) <0200) )
#define xisxdigit(c) (isxdigit((int) (c) ) &&((eight_bits) (c) <0200) )
#define isxalpha(c) ((c) =='_'||(c) =='$') \
#define ishigh(c) ((eight_bits) (c) > 0177) \
\
#define max_include_depth 10 \
#define max_file_name_length 1024
#define cur_file file[include_depth]
#define cur_file_name file_name[include_depth]
#define cur_line line[include_depth]
#define web_file file[0]
#define web_file_name file_name[0] \
#define length(c) (size_t) ((c+1) ->byte_start-(c) ->byte_start)
#define print_id(c) term_write((c) ->byte_start,length(c) )
#define llink link
#define rlink dummy.Rlink
#define root name_dir->rlink \
#define ilk dummy.Ilk \
#define spotless 0
#define harmless_message 1
#define error_message 2
#define fatal_message 3
#define mark_harmless() if(history==spotless) history= harmless_message
#define mark_error() history= error_message
#define confusion(s) fatal(_("! This can't happen: ") ,s) \
\
#define show_banner flags['b']
#define show_progress flags['p']
#define show_happiness flags['h']
#define show_stats flags['s']
#define make_xrefs flags['x']
#define check_for_change flags['c'] \
#define update_terminal() fflush(stdout)
#define new_line() putchar('\n')
#define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) \
#define buf_size 1000
#define longest_name 10000 \
#define long_buf_size (buf_size+longest_name)
#define max_bytes 1000000 \
#define max_names 10239 \
#define max_sections 4000 \
#define max_texts 10239
#define max_toks 1000000
#define equiv equiv_or_xref \
#define macro 0
#define section_flag max_texts \
#define string 02
#define constant 03
#define join 0177
#define output_defs_flag (2*024000-1) \
#define stack_size 50
#define cur_state stack[stack_size+1] \
#define cur_byte cur_state.byte_field
#define cur_name cur_state.name_field
#define cur_repl cur_state.repl_field
#define cur_section cur_state.section_field
#define cur_end (cur_repl+1) ->tok_start \
#define section_number 0201
#define identifier 0202 \
#define normal 0
#define num_or_id 1
#define post_slash 2
#define unbreakable 3
#define verbatim 4 \
#define max_files 256
#define macro_end (cur_text+1) ->tok_start \
#define C_printf(c,a) fprintf(C_file,c,a)
#define C_putc(c) putc((int) (c) ,C_file) \
#define translit_length 10 \
#define transliterate_utf_eight flags['u'] \
#define ignore 00
#define ord 0302
#define control_text 0303
#define translit_code 0304
#define output_defs_code 0305
#define format_code 0306
#define definition 0307
#define begin_C 0310
#define section_name 0311
#define new_section 0312 \
#define app_repl(c) { \
if(tok_ptr==tok_mem_end) overflow(_("token") ) ; \
else*(tok_ptr++) = (eight_bits) c; \
} \
#define store_id(a) a= id_lookup(id_first,id_loc,'\0') -name_dir; \
app_repl((a/0400) +0200) ; \
app_repl(a%0400) \
#define keep_digit_separators flags['k'] \
#define max_banner 50 \
#line 68 "cwebdir/ctangle.w"
/*3:*/
#line 33 "cwebdir/comm-w2c.h"
typedef uint8_t eight_bits;
typedef uint16_t sixteen_bits;
typedef enum{
ctangle,cweave,ctwill
}cweb;
extern cweb program;
extern int phase;
/*:3*//*6:*/
#line 100 "cwebdir/comm-w2c.h"
extern char section_text[];
extern char*section_text_end;
extern char*id_first;
extern char*id_loc;
/*:6*//*7:*/
#line 118 "cwebdir/comm-w2c.h"
extern char buffer[];
extern char*buffer_end;
extern char*loc;
extern char*limit;
/*:7*//*8:*/
#line 135 "cwebdir/comm-w2c.h"
extern int include_depth;
extern FILE*file[];
extern FILE*change_file;
extern char file_name[][max_file_name_length];
extern char change_file_name[];
extern char*found_filename;
extern int line[];
extern int change_line;
extern int change_depth;
extern boolean input_has_ended;
extern boolean changing;
extern boolean web_file_open;
/*:8*//*10:*/
#line 156 "cwebdir/comm-w2c.h"
extern sixteen_bits section_count;
extern boolean changed_section[];
extern boolean change_pending;
extern boolean print_where;
/*:10*//*11:*/
#line 171 "cwebdir/comm-w2c.h"
typedef struct name_info{
char*byte_start;
struct name_info*link;
union{
struct name_info*Rlink;
eight_bits Ilk;
}dummy;
void*equiv_or_xref;
}name_info;
typedef name_info*name_pointer;
typedef name_pointer*hash_pointer;
extern char byte_mem[];
extern char*byte_mem_end;
extern char*byte_ptr;
extern name_info name_dir[];
extern name_pointer name_dir_end;
extern name_pointer name_ptr;
extern name_pointer hash[];
extern hash_pointer hash_end;
extern hash_pointer h;
/*:11*//*13:*/
#line 216 "cwebdir/comm-w2c.h"
extern int history;
/*:13*//*15:*/
#line 233 "cwebdir/comm-w2c.h"
extern int argc;
extern char**argv;
extern char C_file_name[];
extern char tex_file_name[];
extern char idx_file_name[];
extern char scn_file_name[];
extern char check_file_name[];
extern boolean flags[];
extern const char*use_language;
/*:15*//*16:*/
#line 249 "cwebdir/comm-w2c.h"
extern FILE*C_file;
extern FILE*tex_file;
extern FILE*idx_file;
extern FILE*scn_file;
extern FILE*active_file;
extern FILE*check_file;
/*:16*//*116:*/
#line 553 "cwebdir/ctang-w2c.ch"
extern char cb_banner[];
/*:116*/
#line 69 "cwebdir/ctangle.w"
/*19:*/
#line 122 "cwebdir/ctangle.w"
typedef struct{
eight_bits*tok_start;
sixteen_bits text_link;
}text;
typedef text*text_pointer;
#line 66 "cwebdir/ctang-w2c.ch"
/*:19*//*31:*/
#line 267 "cwebdir/ctangle.w"
typedef struct{
eight_bits*byte_field;
name_pointer name_field;
text_pointer repl_field;
sixteen_bits section_field;
}output_state;
typedef output_state*stack_pointer;
/*:31*/
#line 70 "cwebdir/ctangle.w"
/*20:*/
#line 131 "cwebdir/ctangle.w"
static text text_info[max_texts];
static text_pointer text_info_end= text_info+max_texts-1;
static text_pointer text_ptr;
static eight_bits tok_mem[max_toks];
static eight_bits*tok_mem_end= tok_mem+max_toks-1;
static eight_bits*tok_ptr;
/*:20*//*26:*/
#line 196 "cwebdir/ctangle.w"
static text_pointer last_unnamed;
/*:26*//*32:*/
#line 285 "cwebdir/ctangle.w"
static output_state stack[stack_size+2];
static stack_pointer stack_end= stack+stack_size;
static stack_pointer stack_ptr;
/*:32*//*37:*/
#line 357 "cwebdir/ctangle.w"
static int cur_val;
/*:37*//*42:*/
#line 449 "cwebdir/ctangle.w"
static eight_bits out_state;
static boolean protect;
/*:42*//*45:*/
#line 480 "cwebdir/ctangle.w"
static name_pointer output_files[max_files];
static name_pointer*cur_out_file,*end_output_files,*an_output_file;
static char cur_section_name_char;
static char output_file_name[longest_name+1];
/*:45*//*52:*/
#line 579 "cwebdir/ctangle.w"
static boolean output_defs_seen= false;
/*:52*//*57:*/
#line 693 "cwebdir/ctangle.w"
static char translit[0200][translit_length];
/*:57*//*62:*/
#line 769 "cwebdir/ctangle.w"
static eight_bits ccode[256];
/*:62*//*66:*/
#line 829 "cwebdir/ctangle.w"
static boolean comment_continues= false;
/*:66*//*68:*/
#line 866 "cwebdir/ctangle.w"
static name_pointer cur_section_name;
static boolean no_where;
/*:68*//*82:*/
#line 1183 "cwebdir/ctangle.w"
static text_pointer cur_text;
static eight_bits next_control;
/*:82*/
#line 71 "cwebdir/ctangle.w"
/*4:*/
#line 43 "cwebdir/comm-w2c.h"
extern void common_init(void);
extern void cb_show_banner(void);
extern void print_stats(void);
/*:4*//*9:*/
#line 150 "cwebdir/comm-w2c.h"
extern boolean get_line(void);
extern void check_complete(void);
extern void reset_input(void);
/*:9*//*12:*/
#line 194 "cwebdir/comm-w2c.h"
extern name_pointer id_lookup(const char*,const char*,eight_bits);
extern name_pointer section_lookup(char*,char*,boolean);
extern void print_prefix_name(name_pointer);
extern void print_section_name(name_pointer);
extern void sprint_section_name(char*,name_pointer);
extern boolean names_match(name_pointer,const char*,size_t,eight_bits);
extern void init_node(name_pointer);
/*:12*//*14:*/
#line 219 "cwebdir/comm-w2c.h"
extern int wrap_up(void);
extern void err_print(const char*);
extern void fatal(const char*,const char*);
extern void overflow(const char*);
/*:14*//*30:*/
#line 242 "cwebdir/ctangle.w"
static void store_two_bytes(sixteen_bits);
/*:30*//*35:*/
#line 321 "cwebdir/ctangle.w"
static void push_level(name_pointer);
static void pop_level(boolean);
/*:35*//*39:*/
#line 394 "cwebdir/ctangle.w"
static void get_output(void);
/*:39*//*44:*/
#line 470 "cwebdir/ctangle.w"
static void flush_buffer(void);
/*:44*//*49:*/
#line 547 "cwebdir/ctangle.w"
static void phase_two(void);
/*:49*//*53:*/
#line 582 "cwebdir/ctangle.w"
static void output_defs(void);
static void out_char(eight_bits);
/*:53*//*65:*/
#line 809 "cwebdir/ctangle.w"
static eight_bits skip_ahead(void);
static boolean skip_comment(boolean);
/*:65*//*70:*/
#line 916 "cwebdir/ctangle.w"
static eight_bits get_next(void);
/*:70*//*84:*/
#line 1209 "cwebdir/ctangle.w"
static void scan_repl(eight_bits);
/*:84*//*91:*/
#line 1401 "cwebdir/ctangle.w"
static void scan_section(void);
/*:91*//*99:*/
#line 1478 "cwebdir/ctangle.w"
static void phase_one(void);
/*:99*//*101:*/
#line 1511 "cwebdir/ctangle.w"
static void skip_limbo(void);
/*:101*/
#line 72 "cwebdir/ctangle.w"
/*:1*//*2:*/
#line 81 "cwebdir/ctangle.w"
int main(
int ac,
char**av)
{
argc= ac;argv= av;
program= ctangle;
/*21:*/
#line 139 "cwebdir/ctangle.w"
text_info->tok_start= tok_ptr= tok_mem;
text_ptr= text_info+1;text_ptr->tok_start= tok_mem;
/*:21*//*23:*/
#line 149 "cwebdir/ctangle.w"
init_node(name_dir);
/*:23*//*27:*/
#line 199 "cwebdir/ctangle.w"
last_unnamed= text_info;text_info->text_link= macro;
/*:27*//*46:*/
#line 490 "cwebdir/ctangle.w"
cur_out_file= end_output_files= output_files+max_files;
/*:46*//*58:*/
#line 696 "cwebdir/ctangle.w"
{int i;
for(i= 0;i<0200;i++)
snprintf(translit[i],translit_length,"X%02X",(unsigned int)(0200+i));
}
#line 178 "cwebdir/ctang-w2c.ch"
/*:58*//*63:*/
#line 772 "cwebdir/ctangle.w"
{
int c;
for(c= 0;c<256;c++)ccode[c]= ignore;
}
ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f']
= ccode['*']= new_section;
ccode['@']= (eight_bits)'@';ccode['=']= string;
ccode['d']= ccode['D']= definition;
ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code;
ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C;
ccode['^']= ccode[':']= ccode['.']= ccode['t']= ccode['T']=
ccode['q']= ccode['Q']= control_text;
ccode['h']= ccode['H']= output_defs_code;
ccode['l']= ccode['L']= translit_code;
ccode['&']= join;
ccode['<']= ccode['(']= section_name;
ccode['\'']= ord;
/*:63*//*78:*/
#line 1104 "cwebdir/ctangle.w"
section_text[0]= ' ';
/*:78*//*117:*/
#line 556 "cwebdir/ctang-w2c.ch"
strncpy(cb_banner,banner,max_banner-1);
/*:117*/
#line 88 "cwebdir/ctangle.w"
common_init();
#line 53 "cwebdir/ctang-w2c.ch"
if(show_banner)cb_show_banner();
#line 91 "cwebdir/ctangle.w"
phase_one();
phase_two();
return wrap_up();
}
/*:2*//*24:*/
#line 155 "cwebdir/ctangle.w"
boolean names_match(
name_pointer p,
const char*first,
size_t l,
eight_bits t)
{(void)t;
return length(p)==l&&strncmp(first,p->byte_start,l)==0;
}
/*:24*//*25:*/
#line 168 "cwebdir/ctangle.w"
void
init_node(
name_pointer node)
{
node->equiv= (void*)text_info;
}
/*:25*//*29:*/
#line 232 "cwebdir/ctangle.w"
static void
store_two_bytes(
sixteen_bits x)
{
#line 73 "cwebdir/ctang-w2c.ch"
if(tok_ptr+2> tok_mem_end)overflow(_("token"));
#line 238 "cwebdir/ctangle.w"
*tok_ptr++= x>>8;
*tok_ptr++= x&0377;
}
/*:29*//*34:*/
#line 307 "cwebdir/ctangle.w"
static void
push_level(
name_pointer p)
{
#line 79 "cwebdir/ctang-w2c.ch"
if(stack_ptr==stack_end)overflow(_("stack"));
#line 313 "cwebdir/ctangle.w"
*stack_ptr= cur_state;
stack_ptr++;
if(p!=NULL){
cur_name= p;cur_repl= (text_pointer)p->equiv;
cur_byte= cur_repl->tok_start;cur_section= 0;
}
}
/*:34*//*36:*/
#line 329 "cwebdir/ctangle.w"
static void
pop_level(
boolean flag)
{
if(flag&&cur_repl->text_link<section_flag){
cur_repl= cur_repl->text_link+text_info;
cur_byte= cur_repl->tok_start;return;
}
stack_ptr--;
if(stack_ptr> stack)cur_state= *stack_ptr;
}
/*:36*//*38:*/
#line 364 "cwebdir/ctangle.w"
static void
get_output(void)
{
sixteen_bits a;
restart:if(stack_ptr==stack)return;
if(cur_byte==cur_end){
cur_val= -((int)cur_section);
pop_level(true);
if(cur_val==0)goto restart;
out_char(section_number);return;
}
a= *cur_byte++;
if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
C_putc(a);
else if(a<0200)out_char(a);
else{
a= (a-0200)*0400+*cur_byte++;
switch(a/024000){
case 0:cur_val= (int)a;out_char(identifier);break;
case 1:if(a==output_defs_flag)output_defs();
else/*40:*/
#line 399 "cwebdir/ctangle.w"
{
a-= 024000;
if((a+name_dir)->equiv!=(void*)text_info)push_level(a+name_dir);
else if(a!=0){
#line 85 "cwebdir/ctang-w2c.ch"
fputs(_("\n! Not present: <"),stdout);
#line 405 "cwebdir/ctangle.w"
print_section_name(a+name_dir);err_print(">");
}
goto restart;
}
/*:40*/
#line 385 "cwebdir/ctangle.w"
break;
default:cur_val= (int)a-050000;
if(cur_val> 0)cur_section= (sixteen_bits)cur_val;
out_char(section_number);
}
}
}
/*:38*//*43:*/
#line 457 "cwebdir/ctangle.w"
static void
flush_buffer(void)
{
C_putc('\n');
if(cur_line%100==0&&show_progress){
putchar('.');
if(cur_line%500==0)printf("%d",cur_line);
update_terminal();
}
cur_line++;
}
/*:43*//*48:*/
#line 509 "cwebdir/ctangle.w"
static void
phase_two(void){
phase= 2;
web_file_open= false;
cur_line= 1;
/*33:*/
#line 296 "cwebdir/ctangle.w"
stack_ptr= stack+1;cur_name= name_dir;cur_repl= text_info->text_link+text_info;
cur_byte= cur_repl->tok_start;cur_section= 0;
/*:33*/
#line 515 "cwebdir/ctangle.w"
/*51:*/
#line 575 "cwebdir/ctangle.w"
if(!output_defs_seen)
output_defs();
/*:51*/
#line 516 "cwebdir/ctangle.w"
if(text_info->text_link==macro&&cur_out_file==end_output_files){
#line 97 "cwebdir/ctang-w2c.ch"
fputs(_("\n! No program text was specified."),stdout);mark_harmless();
#line 519 "cwebdir/ctangle.w"
}
else{
if(cur_out_file==end_output_files){
if(show_progress){
#line 103 "cwebdir/ctang-w2c.ch"
printf(_("\nWriting the output file (%s):"),C_file_name);
#line 525 "cwebdir/ctangle.w"
update_terminal();
}
}
else{
if(show_progress){
#line 109 "cwebdir/ctang-w2c.ch"
fputs(_("\nWriting the output files:"),stdout);
#line 531 "cwebdir/ctangle.w"
printf(" (%s)",C_file_name);
update_terminal();
}
if(text_info->text_link==macro)goto writeloop;
}
while(stack_ptr> stack)get_output();
flush_buffer();
writeloop:/*50:*/
#line 137 "cwebdir/ctang-w2c.ch"
if(check_for_change){
fclose(C_file);C_file= NULL;
/*106:*/
#line 436 "cwebdir/ctang-w2c.ch"
if((C_file= fopen(C_file_name,"r"))!=NULL){
/*107:*/
#line 443 "cwebdir/ctang-w2c.ch"
boolean comparison= false;
if((check_file= fopen(check_file_name,"r"))==NULL)
fatal(_("! Cannot open output file "),check_file_name);
/*108:*/
#line 457 "cwebdir/ctang-w2c.ch"
do{
char x[BUFSIZ],y[BUFSIZ];
int x_size= fread(x,sizeof(char),BUFSIZ,C_file);
int y_size= fread(y,sizeof(char),BUFSIZ,check_file);
comparison= (x_size==y_size)&&!memcmp(x,y,x_size);
}while(comparison&&!feof(C_file)&&!feof(check_file));
/*:108*/
#line 450 "cwebdir/ctang-w2c.ch"
fclose(C_file);C_file= NULL;
fclose(check_file);check_file= NULL;
/*:107*/
#line 438 "cwebdir/ctang-w2c.ch"
/*109:*/
#line 468 "cwebdir/ctang-w2c.ch"
if(comparison)
remove(check_file_name);
else{
remove(C_file_name);
rename(check_file_name,C_file_name);
}
/*:109*/
#line 439 "cwebdir/ctang-w2c.ch"
}else
rename(check_file_name,C_file_name);
/*:106*/
#line 140 "cwebdir/ctang-w2c.ch"
}
for(an_output_file= end_output_files;an_output_file> cur_out_file;){
an_output_file--;
sprint_section_name(output_file_name,*an_output_file);
if(check_for_change)/*105:*/
#line 427 "cwebdir/ctang-w2c.ch"
{
if((C_file= fopen(output_file_name,"a"))==NULL)
fatal(_("! Cannot open output file "),output_file_name);
else fclose(C_file);
if((C_file= fopen(check_file_name,"wb"))==NULL)
fatal(_("! Cannot open output file "),check_file_name);
}
/*:105*/
#line 145 "cwebdir/ctang-w2c.ch"
else{
fclose(C_file);
if((C_file= fopen(output_file_name,"wb"))==NULL)
fatal(_("! Cannot open output file "),output_file_name);
}
if(show_progress){printf("\n(%s)",output_file_name);update_terminal();}
cur_line= 1;
stack_ptr= stack+1;
cur_name= *an_output_file;
cur_repl= (text_pointer)cur_name->equiv;
cur_byte= cur_repl->tok_start;
while(stack_ptr> stack)get_output();
flush_buffer();
if(check_for_change){
fclose(C_file);C_file= NULL;
/*110:*/
#line 481 "cwebdir/ctang-w2c.ch"
if(0==strcmp("/dev/stdout",output_file_name))
/*112:*/
#line 508 "cwebdir/ctang-w2c.ch"
{
/*115:*/
#line 539 "cwebdir/ctang-w2c.ch"
char in_buf[BUFSIZ+1];
int in_size;
boolean comparison= true;
if((check_file= fopen(check_file_name,"r"))==NULL)
fatal(_("! Cannot open output file "),check_file_name);
/*:115*/
#line 509 "cwebdir/ctang-w2c.ch"
do{
in_size= fread(in_buf,sizeof(char),BUFSIZ,check_file);
in_buf[in_size]= '\0';
fprintf(stdout,"%s",in_buf);
}while(!feof(check_file));
fclose(check_file);check_file= NULL;
/*111:*/
#line 498 "cwebdir/ctang-w2c.ch"
if(comparison)
remove(check_file_name);
else{
remove(output_file_name);
rename(check_file_name,output_file_name);
}
/*:111*/
#line 516 "cwebdir/ctang-w2c.ch"
}
/*:112*/
#line 483 "cwebdir/ctang-w2c.ch"
else if(0==strcmp("/dev/stderr",output_file_name))
/*113:*/
#line 521 "cwebdir/ctang-w2c.ch"
{
/*115:*/
#line 539 "cwebdir/ctang-w2c.ch"
char in_buf[BUFSIZ+1];
int in_size;
boolean comparison= true;
if((check_file= fopen(check_file_name,"r"))==NULL)
fatal(_("! Cannot open output file "),check_file_name);
/*:115*/
#line 522 "cwebdir/ctang-w2c.ch"
do{
in_size= fread(in_buf,sizeof(char),BUFSIZ,check_file);
in_buf[in_size]= '\0';
fprintf(stderr,"%s",in_buf);
}while(!feof(check_file));
fclose(check_file);check_file= NULL;
/*111:*/
#line 498 "cwebdir/ctang-w2c.ch"
if(comparison)
remove(check_file_name);
else{
remove(output_file_name);
rename(check_file_name,output_file_name);
}
/*:111*/
#line 529 "cwebdir/ctang-w2c.ch"
}
/*:113*/
#line 485 "cwebdir/ctang-w2c.ch"
else if(0==strcmp("/dev/null",output_file_name))
/*114:*/
#line 534 "cwebdir/ctang-w2c.ch"
{
boolean comparison= true;
/*111:*/
#line 498 "cwebdir/ctang-w2c.ch"
if(comparison)
remove(check_file_name);
else{
remove(output_file_name);
rename(check_file_name,output_file_name);
}
/*:111*/
#line 536 "cwebdir/ctang-w2c.ch"
}
/*:114*/
#line 487 "cwebdir/ctang-w2c.ch"
else{
if((C_file= fopen(output_file_name,"r"))!=NULL){
/*107:*/
#line 443 "cwebdir/ctang-w2c.ch"
boolean comparison= false;
if((check_file= fopen(check_file_name,"r"))==NULL)
fatal(_("! Cannot open output file "),check_file_name);
/*108:*/
#line 457 "cwebdir/ctang-w2c.ch"
do{
char x[BUFSIZ],y[BUFSIZ];
int x_size= fread(x,sizeof(char),BUFSIZ,C_file);
int y_size= fread(y,sizeof(char),BUFSIZ,check_file);
comparison= (x_size==y_size)&&!memcmp(x,y,x_size);
}while(comparison&&!feof(C_file)&&!feof(check_file));
/*:108*/
#line 450 "cwebdir/ctang-w2c.ch"
fclose(C_file);C_file= NULL;
fclose(check_file);check_file= NULL;
/*:107*/
#line 490 "cwebdir/ctang-w2c.ch"
/*111:*/
#line 498 "cwebdir/ctang-w2c.ch"
if(comparison)
remove(check_file_name);
else{
remove(output_file_name);
rename(check_file_name,output_file_name);
}
/*:111*/
#line 491 "cwebdir/ctang-w2c.ch"
}else
rename(check_file_name,output_file_name);
}
/*:110*/
#line 162 "cwebdir/ctang-w2c.ch"
}
}
if(check_for_change)
strcpy(check_file_name,"");
#line 570 "cwebdir/ctangle.w"
/*:50*/
#line 539 "cwebdir/ctangle.w"
if(show_happiness){
if(show_progress)new_line();
#line 115 "cwebdir/ctang-w2c.ch"
fputs(_("Done."),stdout);
#line 543 "cwebdir/ctangle.w"
}
}
}
/*:48*//*54:*/
#line 591 "cwebdir/ctangle.w"
static void
output_defs(void)
{
sixteen_bits a;
push_level(NULL);
for(cur_text= text_info+1;cur_text<text_ptr;cur_text++)
if(cur_text->text_link==macro){
cur_byte= cur_text->tok_start;
C_printf("%s","#define ");
out_state= normal;
protect= true;
while(cur_byte<macro_end){
a= *cur_byte++;
if(cur_byte==macro_end&&a=='\n')break;
if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
C_putc(a);
else if(a<0200)out_char(a);
else{
a= (a-0200)*0400+*cur_byte++;
if(a<024000){
cur_val= (int)a;out_char(identifier);
}
#line 172 "cwebdir/ctang-w2c.ch"
else if(a<050000)confusion(_("macro defs have strange char"));
#line 616 "cwebdir/ctangle.w"
else{
cur_val= (int)a-050000;cur_section= (sixteen_bits)cur_val;
out_char(section_number);
}
}
}
protect= false;
flush_buffer();
}
pop_level(false);
}
/*:54*//*55:*/
#line 634 "cwebdir/ctangle.w"
static void
out_char(
eight_bits cur_char)
{
char*j;
restart:
switch(cur_char){
case'\n':if(protect&&out_state!=verbatim)C_putc(' ');
if(protect||out_state==verbatim)C_putc('\\');
flush_buffer();if(out_state!=verbatim)out_state= normal;break;
/*59:*/
#line 204 "cwebdir/ctang-w2c.ch"
#line 703 "cwebdir/ctangle.w"
case identifier:
if(out_state==num_or_id)C_putc(' ');
for(j= (cur_val+name_dir)->byte_start;
j<(cur_val+name_dir+1)->byte_start;j++)
#line 212 "cwebdir/ctang-w2c.ch"
if(ishigh(*j)){
if(transliterate_utf_eight){
if((eight_bits)(*j)>=0360)j+= 3;
else if((eight_bits)(*j)>=0340)j+= 2;
else if((eight_bits)(*j)>=0300)j+= 1;
}
C_printf("%s",translit[(eight_bits)(*j)-0200]);
}
else C_putc(*j);
#line 710 "cwebdir/ctangle.w"
out_state= num_or_id;break;
/*:59*/
#line 645 "cwebdir/ctangle.w"
/*60:*/
#line 712 "cwebdir/ctangle.w"
case section_number:
if(cur_val> 0)C_printf("/*%d:*/",cur_val);
else if(cur_val<0)C_printf("/*:%d*/",-cur_val);
else if(protect){
cur_byte+= 4;
cur_char= (eight_bits)'\n';
goto restart;
}else{
sixteen_bits a;
a= *cur_byte++*0400;
a+= *cur_byte++;
C_printf("\n#line %d \"",(int)a);
cur_val= (int)(*cur_byte++-0200)*0400;
cur_val+= *cur_byte++;
for(j= (cur_val+name_dir)->byte_start;
j<(cur_val+name_dir+1)->byte_start;j++){
if(*j=='\\'||*j=='"')C_putc('\\');
C_putc(*j);
}
C_putc('"');C_putc('\n');
}
break;
/*:60*/
#line 646 "cwebdir/ctangle.w"
/*56:*/
#line 664 "cwebdir/ctangle.w"
case plus_plus:C_putc('+');C_putc('+');out_state= normal;break;
case minus_minus:C_putc('-');C_putc('-');out_state= normal;break;
case minus_gt:C_putc('-');C_putc('>');out_state= normal;break;
case gt_gt:C_putc('>');C_putc('>');out_state= normal;break;
case eq_eq:C_putc('=');C_putc('=');out_state= normal;break;
case lt_lt:C_putc('<');C_putc('<');out_state= normal;break;
case gt_eq:C_putc('>');C_putc('=');out_state= normal;break;
case lt_eq:C_putc('<');C_putc('=');out_state= normal;break;
case non_eq:C_putc('!');C_putc('=');out_state= normal;break;
case and_and:C_putc('&');C_putc('&');out_state= normal;break;
case or_or:C_putc('|');C_putc('|');out_state= normal;break;
case dot_dot_dot:C_putc('.');C_putc('.');C_putc('.');out_state= normal;
break;
case colon_colon:C_putc(':');C_putc(':');out_state= normal;break;
case period_ast:C_putc('.');C_putc('*');out_state= normal;break;
case minus_gt_ast:C_putc('-');C_putc('>');C_putc('*');out_state= normal;
break;
/*:56*/
#line 647 "cwebdir/ctangle.w"
case'=':case'>':C_putc(cur_char);C_putc(' ');
out_state= normal;break;
case join:out_state= unbreakable;break;
case constant:if(out_state==verbatim){
out_state= num_or_id;break;
}
if(out_state==num_or_id)C_putc(' ');out_state= verbatim;break;
case string:if(out_state==verbatim)out_state= normal;
else out_state= verbatim;break;
case'/':C_putc('/');out_state= post_slash;break;
case'*':if(out_state==post_slash)C_putc(' ');
/* fall through */
default:C_putc(cur_char);out_state= normal;break;
}
}
/*:55*//*64:*/
#line 793 "cwebdir/ctangle.w"
static eight_bits
skip_ahead(void)
{
eight_bits c;
while(true){
if(loc> limit&&(get_line()==false))return new_section;
*(limit+1)= '@';
while(*loc!='@')loc++;
if(loc<=limit){
loc++;c= ccode[(eight_bits)*loc];loc++;
if(c!=ignore||*(loc-1)=='>')return c;
}
}
}
/*:64*//*67:*/
#line 832 "cwebdir/ctangle.w"
static boolean skip_comment(
boolean is_long_comment)
{
char c;
while(true){
if(loc> limit){
if(is_long_comment){
if(get_line())return comment_continues= true;
else{
#line 227 "cwebdir/ctang-w2c.ch"
err_print(_("! Input ended in mid-comment"));
#line 843 "cwebdir/ctangle.w"
return comment_continues= false;
}
}
else return comment_continues= false;
}
c= *(loc++);
if(is_long_comment&&c=='*'&&*loc=='/'){
loc++;return comment_continues= false;
}
if(c=='@'){
if(ccode[(eight_bits)*loc]==new_section){
#line 233 "cwebdir/ctang-w2c.ch"
err_print(_("! Section name ended in mid-comment"));loc--;
#line 856 "cwebdir/ctangle.w"
return comment_continues= false;
}
else loc++;
}
}
}
/*:67*//*69:*/
#line 873 "cwebdir/ctangle.w"
static eight_bits
get_next(void)
{
static boolean preprocessing= false;
eight_bits c;
while(true){
if(loc> limit){
if(preprocessing&&*(limit-1)!='\\')preprocessing= false;
if(get_line()==false)return new_section;
else if(print_where&&!no_where){
print_where= false;
/*85:*/
#line 1219 "cwebdir/ctangle.w"
{
eight_bits a;
store_two_bytes(0150000);
if(changing&&include_depth==change_depth){
id_first= change_file_name;
store_two_bytes((sixteen_bits)change_line);
}else{
id_first= cur_file_name;
store_two_bytes((sixteen_bits)cur_line);
}
id_loc= id_first+strlen(id_first);
store_id(a);
}
/*:85*/
#line 885 "cwebdir/ctangle.w"
}
else return(eight_bits)'\n';
}
c= (eight_bits)*loc;
if(comment_continues||(c=='/'&&(*(loc+1)=='*'||*(loc+1)=='/'))){
if(skip_comment(comment_continues||*(loc+1)=='*'))return'\n';
else continue;
}
loc++;
if(xisdigit(c)||c=='.')/*73:*/
#line 957 "cwebdir/ctangle.w"
{
boolean hex_flag= false;
id_first= loc-1;
if(*id_first=='.'&&!xisdigit(*loc))goto mistake;
if(*id_first=='0'){
if(*loc=='x'||*loc=='X'){
hex_flag= true;
loc++;while(xisxdigit(*loc)||*loc=='\'')loc++;
}
else if(*loc=='b'||*loc=='B'){
loc++;while(*loc=='0'||*loc=='1'||*loc=='\'')loc++;goto found;
}
}
while(xisdigit(*loc)||*loc=='\'')loc++;
if(*loc=='.'){
loc++;
while((hex_flag&&xisxdigit(*loc))||xisdigit(*loc)||*loc=='\'')loc++;
}
if(*loc=='e'||*loc=='E'){
if(*++loc=='+'||*loc=='-')loc++;
while(xisdigit(*loc)||*loc=='\'')loc++;
}
else if(hex_flag&&(*loc=='p'||*loc=='P')){
if(*++loc=='+'||*loc=='-')loc++;
while(xisxdigit(*loc)||*loc=='\'')loc++;
}
found:while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L'
||*loc=='f'||*loc=='F')loc++;
id_loc= loc;
return constant;
}
/*:73*/
#line 896 "cwebdir/ctangle.w"
else if(c=='\''||c=='"'
||((c=='L'||c=='u'||c=='U')&&(*loc=='\''||*loc=='"'))
||((c=='u'&&*loc=='8')&&(*(loc+1)=='\''||*(loc+1)=='"')))
/*74:*/
#line 994 "cwebdir/ctangle.w"
{
char delim= (char)c;
id_first= section_text+1;
id_loc= section_text;*++id_loc= delim;
if(delim=='L'||delim=='u'||delim=='U'){
if(delim=='u'&&*loc=='8')*++id_loc= *loc++;
delim= *loc++;*++id_loc= delim;
}
while(true){
if(loc>=limit){
if(*(limit-1)!='\\'){
#line 239 "cwebdir/ctang-w2c.ch"
err_print(_("! String didn't end"));loc= limit;break;
#line 1006 "cwebdir/ctangle.w"
}
if(get_line()==false){
#line 245 "cwebdir/ctang-w2c.ch"
err_print(_("! Input ended in middle of string"));loc= buffer;break;
#line 1010 "cwebdir/ctangle.w"
}
else if(++id_loc<=section_text_end)*id_loc= '\n';
}
if((c= (eight_bits)*loc++)==delim){
if(++id_loc<=section_text_end)*id_loc= (char)c;
break;
}
if(c=='\\'){
if(loc>=limit)continue;
if(++id_loc<=section_text_end)*id_loc= '\\';
c= (eight_bits)*loc++;
}
if(++id_loc<=section_text_end)*id_loc= (char)c;
}
if(id_loc>=section_text_end){
#line 251 "cwebdir/ctang-w2c.ch"
fputs(_("\n! String too long: "),stdout);
#line 1028 "cwebdir/ctangle.w"
term_write(section_text+1,25);
err_print("...");
}
id_loc++;
return string;
}
/*:74*/
#line 900 "cwebdir/ctangle.w"
else if(isalpha((int)c)||isxalpha(c)||ishigh(c))
/*72:*/
#line 948 "cwebdir/ctangle.w"
{
id_first= --loc;
do
++loc;
while(isalpha((int)*loc)||isdigit((int)*loc)
||isxalpha(*loc)||ishigh(*loc));
id_loc= loc;return identifier;
}
/*:72*/
#line 902 "cwebdir/ctangle.w"
else if(c=='@')/*75:*/
#line 1039 "cwebdir/ctangle.w"
switch(c= ccode[(eight_bits)*loc++]){
case ignore:continue;
#line 257 "cwebdir/ctang-w2c.ch"
case translit_code:err_print(_("! Use @l in limbo only"));continue;
#line 1043 "cwebdir/ctangle.w"
case control_text:while((c= skip_ahead())=='@');
if(*(loc-1)!='>')
#line 263 "cwebdir/ctang-w2c.ch"
err_print(_("! Double @ should be used in control text"));
#line 1048 "cwebdir/ctangle.w"
continue;
case section_name:
cur_section_name_char= *(loc-1);
/*77:*/
#line 1084 "cwebdir/ctangle.w"
{
char*k= section_text;
/*79:*/
#line 1106 "cwebdir/ctangle.w"
while(true){
if(loc> limit&&get_line()==false){
#line 281 "cwebdir/ctang-w2c.ch"
err_print(_("! Input ended in section name"));
#line 1110 "cwebdir/ctangle.w"
loc= buffer+1;break;
}
c= (eight_bits)*loc;
/*80:*/
#line 1129 "cwebdir/ctangle.w"
if(c=='@'){
c= (eight_bits)*(loc+1);
if(c=='>'){
loc+= 2;break;
}
if(ccode[(eight_bits)c]==new_section){
#line 293 "cwebdir/ctang-w2c.ch"
err_print(_("! Section name didn't end"));break;
#line 1137 "cwebdir/ctangle.w"
}
if(ccode[(eight_bits)c]==section_name){
#line 299 "cwebdir/ctang-w2c.ch"
err_print(_("! Nesting of section names not allowed"));break;
#line 1141 "cwebdir/ctangle.w"
}
*(++k)= '@';loc++;
}
/*:80*/
#line 1114 "cwebdir/ctangle.w"
loc++;if(k<section_text_end)k++;
if(xisspace(c)){
c= (eight_bits)' ';if(*(k-1)==' ')k--;
}
*k= (char)c;
}
if(k>=section_text_end){
#line 287 "cwebdir/ctang-w2c.ch"
fputs(_("\n! Section name too long: "),stdout);
#line 1123 "cwebdir/ctangle.w"
term_write(section_text+1,25);
printf("...");mark_harmless();
}
if(*k==' '&&k> section_text)k--;
/*:79*/
#line 1086 "cwebdir/ctangle.w"
if(k-section_text> 3&&strncmp(k-2,"...",3)==0)
cur_section_name= section_lookup(section_text+1,k-3,true);
else cur_section_name= section_lookup(section_text+1,k,false);
if(cur_section_name_char=='(')
/*47:*/
#line 494 "cwebdir/ctangle.w"
{
for(an_output_file= cur_out_file;
an_output_file<end_output_files;an_output_file++)
if(*an_output_file==cur_section_name)break;
if(an_output_file==end_output_files){
if(cur_out_file> output_files)
*--cur_out_file= cur_section_name;
#line 91 "cwebdir/ctang-w2c.ch"
else overflow(_("output files"));
#line 503 "cwebdir/ctangle.w"
}
}
/*:47*/
#line 1094 "cwebdir/ctangle.w"
return section_name;
}
/*:77*/
#line 1052 "cwebdir/ctangle.w"
case string:/*81:*/
#line 1151 "cwebdir/ctangle.w"
id_first= loc++;*(limit+1)= '@';*(limit+2)= '>';
while(*loc!='@'||*(loc+1)!='>')loc++;
#line 305 "cwebdir/ctang-w2c.ch"
if(loc>=limit)err_print(_("! Verbatim string didn't end"));
#line 1155 "cwebdir/ctangle.w"
id_loc= loc;loc+= 2;
return string;
/*:81*/
#line 1053 "cwebdir/ctangle.w"
case ord:/*76:*/
#line 1064 "cwebdir/ctangle.w"
id_first= loc;
if(*loc=='\\')
if(*++loc=='\'')loc++;
while(*loc!='\''){
if(*loc=='@'){
if(*(loc+1)!='@')
#line 269 "cwebdir/ctang-w2c.ch"
err_print(_("! Double @ should be used in ASCII constant"));
#line 1072 "cwebdir/ctangle.w"
else loc++;
}
loc++;
if(loc> limit){
#line 275 "cwebdir/ctang-w2c.ch"
err_print(_("! String didn't end"));loc= limit-1;break;
#line 1078 "cwebdir/ctangle.w"
}
}
loc++;
return ord;
/*:76*/
#line 1054 "cwebdir/ctangle.w"
default:return c;
}
/*:75*/
#line 903 "cwebdir/ctangle.w"
else if(xisspace(c)){
if(!preprocessing||loc> limit)continue;
else return(eight_bits)' ';
}
else if(c=='#'&&loc==buffer+1)preprocessing= true;
mistake:/*71:*/
#line 925 "cwebdir/ctangle.w"
switch(c){
case'+':if(*loc=='+')compress(plus_plus);break;
case'-':if(*loc=='-'){compress(minus_minus);}
else if(*loc=='>'){
if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);}
else compress(minus_gt);
}break;
case'.':if(*loc=='*'){compress(period_ast);}
else if(*loc=='.'&&*(loc+1)=='.'){
loc++;compress(dot_dot_dot);
}break;
case':':if(*loc==':')compress(colon_colon);break;
case'=':if(*loc=='=')compress(eq_eq);break;
case'>':if(*loc=='='){compress(gt_eq);}
else if(*loc=='>')compress(gt_gt);break;
case'<':if(*loc=='='){compress(lt_eq);}
else if(*loc=='<')compress(lt_lt);break;
case'&':if(*loc=='&')compress(and_and);break;
case'|':if(*loc=='|')compress(or_or);break;
case'!':if(*loc=='=')compress(non_eq);break;
}
/*:71*/
#line 911 "cwebdir/ctangle.w"
return c;
}
}
/*:69*//*83:*/
#line 1187 "cwebdir/ctangle.w"
static void
scan_repl(
eight_bits t)
{
sixteen_bits a;
if(t==section_name)/*85:*/
#line 1219 "cwebdir/ctangle.w"
{
eight_bits a;
store_two_bytes(0150000);
if(changing&&include_depth==change_depth){
id_first= change_file_name;
store_two_bytes((sixteen_bits)change_line);
}else{
id_first= cur_file_name;
store_two_bytes((sixteen_bits)cur_line);
}
id_loc= id_first+strlen(id_first);
store_id(a);
}
/*:85*/
#line 1193 "cwebdir/ctangle.w"
while(true)switch(a= get_next()){
/*86:*/
#line 1234 "cwebdir/ctangle.w"
case identifier:store_id(a);
if(*buffer=='#'&&(
(id_loc-id_first==5&&strncmp("endif",id_first,5)==0)||
(id_loc-id_first==4&&strncmp("else",id_first,4)==0)||
(id_loc-id_first==4&&strncmp("elif",id_first,4)==0)))
print_where= true;
break;
case section_name:if(t!=section_name)goto done;
else{
/*87:*/
#line 1275 "cwebdir/ctangle.w"
{
char*try_loc= loc;
while(*try_loc==' '&&try_loc<limit)try_loc++;
if(*try_loc=='+'&&try_loc<limit)try_loc++;
while(*try_loc==' '&&try_loc<limit)try_loc++;
#line 341 "cwebdir/ctang-w2c.ch"
if(*try_loc=='=')err_print(_("! Missing `@ ' before a named section"));
#line 1281 "cwebdir/ctangle.w"
}
/*:87*/
#line 1245 "cwebdir/ctangle.w"
a= cur_section_name-name_dir;
app_repl((a/0400)+0250);
app_repl(a%0400);
/*85:*/
#line 1219 "cwebdir/ctangle.w"
{
eight_bits a;
store_two_bytes(0150000);
if(changing&&include_depth==change_depth){
id_first= change_file_name;
store_two_bytes((sixteen_bits)change_line);
}else{
id_first= cur_file_name;
store_two_bytes((sixteen_bits)cur_line);
}
id_loc= id_first+strlen(id_first);
store_id(a);
}
/*:85*/
#line 1249 "cwebdir/ctangle.w"
}
break;
#line 329 "cwebdir/ctang-w2c.ch"
case output_defs_code:if(t!=section_name)err_print(_("! Misplaced @h"));
#line 1253 "cwebdir/ctangle.w"
else{
output_defs_seen= true;
a= output_defs_flag;
app_repl((a/0400)+0200);
app_repl(a%0400);
/*85:*/
#line 1219 "cwebdir/ctangle.w"
{
eight_bits a;
store_two_bytes(0150000);
if(changing&&include_depth==change_depth){
id_first= change_file_name;
store_two_bytes((sixteen_bits)change_line);
}else{
id_first= cur_file_name;
store_two_bytes((sixteen_bits)cur_line);
}
id_loc= id_first+strlen(id_first);
store_id(a);
}
/*:85*/
#line 1259 "cwebdir/ctangle.w"
}
break;
case constant:case string:
/*88:*/
#line 1292 "cwebdir/ctangle.w"
app_repl(a);
while(id_first<id_loc){
if(*id_first=='@'){
if(*(id_first+1)=='@')id_first++;
#line 347 "cwebdir/ctang-w2c.ch"
else err_print(_("! Double @ should be used in string"));
#line 1298 "cwebdir/ctangle.w"
}
else if(a==constant&&*id_first=='\''&&!keep_digit_separators)
id_first++;
app_repl(*id_first++);
}
app_repl(a);
/*:88*/
#line 1263 "cwebdir/ctangle.w"
break;
case ord:
/*89:*/
#line 1310 "cwebdir/ctangle.w"
{
int c= (int)((eight_bits)*id_first);
if(c=='\\'){
c= (int)((eight_bits)*++id_first);
if(c>='0'&&c<='7'){
c-= '0';
if(*(id_first+1)>='0'&&*(id_first+1)<='7'){
c= 8*c+*(++id_first)-'0';
if(*(id_first+1)>='0'&&*(id_first+1)<='7'&&c<32)
c= 8*c+*(++id_first)-'0';
}
}
else switch(c){
case't':c= '\t';break;
case'n':c= '\n';break;
case'b':c= '\b';break;
case'f':c= '\f';break;
case'v':c= '\v';break;
case'r':c= '\r';break;
case'a':c= '\7';break;
case'?':c= '?';break;
case'x':
if(xisdigit(*(id_first+1)))c= (int)(*(++id_first)-'0');
else if(xisxdigit(*(id_first+1))){
++id_first;
c= toupper((int)*id_first)-'A'+10;
}
if(xisdigit(*(id_first+1)))c= 16*c+(int)(*(++id_first)-'0');
else if(xisxdigit(*(id_first+1))){
++id_first;
c= 16*c+toupper((int)*id_first)-(int)'A'+10;
}
break;
case'\\':c= '\\';break;
case'\'':c= '\'';break;
case'\"':c= '\"';break;
#line 353 "cwebdir/ctang-w2c.ch"
default:err_print(_("! Unrecognized escape sequence"));
#line 1347 "cwebdir/ctangle.w"
}
}
app_repl(constant);
if(c>=100)app_repl((int)'0'+c/100);
if(c>=10)app_repl((int)'0'+(c/10)%10);
app_repl((int)'0'+c%10);
app_repl(constant);
}
/*:89*/
#line 1266 "cwebdir/ctangle.w"
break;
case definition:case format_code:case begin_C:if(t!=section_name)goto done;
else{
#line 335 "cwebdir/ctang-w2c.ch"
err_print(_("! @d, @f and @c are ignored in C text"));continue;
#line 1271 "cwebdir/ctangle.w"
}
case new_section:goto done;
/*:86*/
#line 1198 "cwebdir/ctangle.w"
case')':app_repl(a);
if(t==macro)app_repl(' ');
break;
default:app_repl(a);
}
done:next_control= (eight_bits)a;
#line 323 "cwebdir/ctang-w2c.ch"
if(text_ptr> text_info_end)overflow(_("text"));
#line 1206 "cwebdir/ctangle.w"
cur_text= text_ptr;(++text_ptr)->tok_start= tok_ptr;
}
/*:83*//*90:*/
#line 1368 "cwebdir/ctangle.w"
static void
scan_section(void)
{
name_pointer p;
text_pointer q;
sixteen_bits a;
section_count++;no_where= true;
if(*(loc-1)=='*'&&show_progress){
printf("*%d",(int)section_count);update_terminal();
}
next_control= ignore;
while(true){
/*92:*/
#line 1409 "cwebdir/ctangle.w"
while(next_control<definition)
if((next_control= skip_ahead())==section_name){
loc-= 2;next_control= get_next();
}
/*:92*/
#line 1382 "cwebdir/ctangle.w"
if(next_control==definition){
/*93:*/
#line 1416 "cwebdir/ctangle.w"
while((next_control= get_next())=='\n');
if(next_control!=identifier){
#line 359 "cwebdir/ctang-w2c.ch"
err_print(_("! Definition flushed, must start with identifier"));
#line 1420 "cwebdir/ctangle.w"
continue;
}
store_id(a);
if(*loc!='('){
app_repl(string);app_repl(' ');app_repl(string);
}
scan_repl(macro);
cur_text->text_link= macro;
/*:93*/
#line 1384 "cwebdir/ctangle.w"
continue;
}
if(next_control==begin_C){
p= name_dir;break;
}
if(next_control==section_name){
p= cur_section_name;
/*94:*/
#line 1438 "cwebdir/ctangle.w"
while((next_control= get_next())=='+');
if(next_control!='='&&next_control!=eq_eq)
continue;
/*:94*/
#line 1392 "cwebdir/ctangle.w"
break;
}
return;
}
no_where= print_where= false;
/*95:*/
#line 1443 "cwebdir/ctangle.w"
/*96:*/
#line 1448 "cwebdir/ctangle.w"
store_two_bytes((sixteen_bits)(0150000+section_count));
/*:96*/
#line 1444 "cwebdir/ctangle.w"
scan_repl(section_name);
/*97:*/
#line 1452 "cwebdir/ctangle.w"
if(p==name_dir||p==NULL){
last_unnamed->text_link= cur_text-text_info;last_unnamed= cur_text;
}
else if(p->equiv==(void*)text_info)p->equiv= (void*)cur_text;
else{
q= (text_pointer)p->equiv;
while(q->text_link<section_flag)
q= q->text_link+text_info;
q->text_link= cur_text-text_info;
}
cur_text->text_link= section_flag;
/*:97*/
#line 1446 "cwebdir/ctangle.w"
/*:95*/
#line 1398 "cwebdir/ctangle.w"
}
/*:90*//*98:*/
#line 1467 "cwebdir/ctangle.w"
static void
phase_one(void){
phase= 1;
section_count= 0;
reset_input();
skip_limbo();
while(!input_has_ended)scan_section();
check_complete();
}
/*:98*//*100:*/
#line 1483 "cwebdir/ctangle.w"
static void
skip_limbo(void)
{
while(true){
if(loc> limit&&get_line()==false)return;
*(limit+1)= '@';
while(*loc!='@')loc++;
if(loc++<=limit){
char c= *loc++;
switch(ccode[(eight_bits)c]){
case new_section:return;
case translit_code:/*102:*/
#line 1513 "cwebdir/ctangle.w"
while(xisspace(*loc)&&loc<limit)loc++;
loc+= 3;
if(loc> limit||!xisxdigit(*(loc-3))||!xisxdigit(*(loc-2))
||(*(loc-3)>='0'&&*(loc-3)<='7')||!xisspace(*(loc-1)))
#line 379 "cwebdir/ctang-w2c.ch"
err_print(_("! Improper hex number following @l"));
#line 1519 "cwebdir/ctangle.w"
else{
unsigned int i;
char*beg;
sscanf(loc-3,"%x",&i);
while(xisspace(*loc)&&loc<limit)loc++;
beg= loc;
while(loc<limit&&(xisalpha(*loc)||xisdigit(*loc)||isxalpha(*loc)))loc++;
if(loc-beg>=translit_length)
#line 385 "cwebdir/ctang-w2c.ch"
err_print(_("! Replacement string in @l too long"));
#line 1529 "cwebdir/ctangle.w"
else{
strncpy(translit[i-0200],beg,(size_t)(loc-beg));
translit[i-0200][loc-beg]= '\0';
}
}
/*:102*/
#line 1495 "cwebdir/ctangle.w"
break;
case format_code:case'@':break;
case control_text:if(c=='q'||c=='Q'){
while((c= (char)skip_ahead())=='@');
if(*(loc-1)!='>')
#line 365 "cwebdir/ctang-w2c.ch"
err_print(_("! Double @ should be used in control text"));
#line 1501 "cwebdir/ctangle.w"
break;
#line 372 "cwebdir/ctang-w2c.ch"
}/* otherwise fall through */
default:err_print(_("! Double @ should be used in limbo"));
#line 1505 "cwebdir/ctangle.w"
}
}
}
}
/*:100*//*103:*/
#line 1539 "cwebdir/ctangle.w"
void
print_stats(void){
#line 398 "cwebdir/ctang-w2c.ch"
puts(_("\nMemory usage statistics:"));
printf(_("%td names (out of %ld)\n"),
(ptrdiff_t)(name_ptr-name_dir),(long)max_names);
printf(_("%td replacement texts (out of %ld)\n"),
(ptrdiff_t)(text_ptr-text_info),(long)max_texts);
printf(_("%td bytes (out of %ld)\n"),
(ptrdiff_t)(byte_ptr-byte_mem),(long)max_bytes);
printf(_("%td tokens (out of %ld)\n"),
#line 1550 "cwebdir/ctangle.w"
(ptrdiff_t)(tok_ptr-tok_mem),(long)max_toks);
}
#line 411 "cwebdir/ctang-w2c.ch"
/*:103*/
|