File: fwebmac.web

package info (click to toggle)
fweb 1.60beta-11
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 4,348 kB
  • ctags: 5,018
  • sloc: ansic: 38,347; makefile: 393; sh: 163
file content (2557 lines) | stat: -rw-r--r-- 76,699 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
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
@z --- fwebmac.web ---
$Id: fwebmac.web,v 1.53.1.13 1996/09/14 12:43:41 krommes Exp krommes $
$Revision: 1.53.1.13 $

Copyright (C) 1987 Princeton University

Original authors:  D. Knuth, S. Levy

Upgraded by J.A. Krommes for FWEB.

@x-----------------------------------------------------------------------------

\Title{fwebmac-1.60-$\beta$}
\author{John A. Krommes\\(after D. Knuth and S. Levy)}
\date{December 31, 1996}

\numberdefsfalse
\numbercodefalse

@Lx

@* INTRODUCTION.  These are the standard macros for \FWEB\ (v.~1.52)
listings (in addition to those of \.{PLAIN.TEX} and/or \LaTeX).  Beginning
with v.~1.50, \LaTeXe\ is supported.

WARNING: Some of these macros are not independent of stuff hard-coded
into \FWEAVE. In other words, if you change something here, you may also need
to recompile \FWEAVE. So caution!

@ Print a comment at the beginning of the \.{.sty} file that is created.
@A
% --- THIS IS fwebmac.sty ---

% DO NOT EDIT THIS FILE; it is generated automatically from fwebmac.web.
% This file must be included into all .tex files produced by FWEAVE. 
% You can weave fwebmac.web to see discussions of the fwebmac.sty logic.

% ---------------------------------------------------------------------------

@ First, we have a flag |\FWEBisloaded| that prevents \.{fwebmac.sty} from
being loaded twice.  For the use of this flag, see the Dirty Tricks
appendix of the \TeX book. 

@A
% If it's not defined yet, load in the macros.
\ifx\FWEBisloaded\relax\endinput\else\let\FWEBisloaded\relax\fi

@ \FWEB\ can be run either in stand-alone mode (the usual application), or
\FWEAVE\ output can be incorporated into a \LaTeX\ document.  To
distinguish, we need a flag, |\FWEBstandalone|.  This is true by default;
however, it is made false when the package \.{fwebinsert} is invoked.

@A
\newif\ifFWEBstandalone
\FWEBstandalonetrue

@ We need to refer to various internal macros, so we make '\.{@@}' an
ordinary letter.
@f `\@@ 11
@A
\catcode`\@@=11

@ Here's something for trickery with catcodes.
@A
\chardef\other=12

@ One can comment stuff out by bracketing it with |\comment...\endcomment|.
@A
\long\def\comment#1\endcomment{}

@*1 The current version.
Various things need to know the current version number and date. 
@A
\def\FWEBversion{$REVISION}
\def\FWEBdate{September 23, 1995}

@*1 Defining robust macros.
Robust commands are useful; we provide our own version if the \LaTeXe\
|\DeclareRobustCommand| isn't available.  (However, at present our own
version just defines a macro with $n$~arguments; it doesn't actually make
it robust for \TeX\ or ordinary \LaTeX.)

@A
\newcount\W@@count
\newcount\W@@counta
\newtoks\W@@tk

\ifx\DeclareRobustCommand\undefined

	\def\DeclareRobustCommand#1{\@@ifnextchar[%
{\W@@argdef#1}{\W@@argdef#1[0]}}

	\def\W@@argdef#1[#2]{\W@@tk={}%
	\W@@count=0
	\loop
	\ifnum\W@@count<#2
		\advance\W@@count by1
		\edef\next{\W@@tk={\the\W@@tk########\the\W@@count}}\next
	\repeat
	\edef\next{\def\noexpand#1\the\W@@tk}\next}

\fi

\ifx\@@ifnextchar\undefined

	\def\@@ifnextchar#1#2#3{\let\@@tempe#1
	\def\@@tempa{#2}%
	\def\@@tempb{#3}%
	\futurelet\@@tempc\@@ifnch}

	\def\@@ifnch{\ifx\@@tempc\@@sptoken
		\let\@@tempd\@@xifnch
	\else
		\ifx\@@tempc\@@tempe
			\let\@@tempd\@@tempa
		\else
			\let\@@tempd\@@tempb
		\fi
	\fi
	\@@tempd
	}

	{\def\:{\global\let\@@sptoken= } \: }

	\def\@@xifnch{\futurelet\@@tempc\@@ifnch}

\fi


\let\DRC\DeclareRobustCommand

@*1 Printing ``\TeX'' and ``\LaTeX'', and distinguishing between them.
\FWEB\ now offers full \LaTeX\ support.  Here's how to refer to it.
[Note the use of |\W@@t| (defined in \WEBsection{syn} below) rather than
|\@@|; the latter is used for other things in \FWEB.]
@A
\def\TeX{T\kern-0.1667em\lower0.5ex\hbox{E}\kern-0.125emX\W@@t}

\ifx\LaTeX\undefined
	\def\LaTeX{L\kern-0.36em\raise0.3ex\hbox{\Csc a}\kern-0.15em\TeX}
\fi

\newif\ifnoLaTeXe% By default, we have \LaTeXe.

\ifx\LaTeXe\undefined
	\noLaTeXetrue
	\def\LaTeXe{\LaTeX 2$_\varepsilon$}
\fi

@ One needs to distinguish whether or not \LaTeX\ is loaded.  Assuming that
only \TeX\ or \LaTeX\ will be used, one way of doing this is to
discriminate on whether |\pageno| is defined.  

@A
\newif\ifLaTeXisloaded

\ifx\pageno\undefined
	\LaTeXisloadedtrue
\fi

@*1 Convenience macros such as \.{\\FWEAVE} or \.{\\Fortran}.
Here's how to refer to the individual processors.  The user may wish to
redefine these.  Note that we use the primitive |\Wtypewriter|, since the
user can change the usual typewriter macro ``|\.|'' to something else.

@A
\DRC\WEB{\Wtypewriter{WEB}}
\DRC\FWEB{\Wtypewriter{FWEB}}
\DRC\CWEB{\Wtypewriter{CWEB}}
\DRC\TANGLE{\Wtypewriter{TANGLE}}	\let\Tangle\TANGLE
\DRC\WEAVE{\Wtypewriter{WEAVE}}		\let\Weave\WEAVE
\DRC\FTANGLE{\Wtypewriter{FTANGLE}}
\DRC\FWEAVE{\Wtypewriter{FWEAVE}}

@ Here's how one can refer to the individual languages.  The user may also wish
to redefine these.
@A
\DRC\C{C\W@@t}
\DRC\Cpp{\C{\tt ++}}
\DRC\FORTRAN{{\Csc Fortran}}	\let\Fortran\FORTRAN
\DRC\MAKE{{\tt MAKE}}		\let\Make\MAKE
\DRC\RATFOR{{\Csc Ratfor}}	\let\Ratfor\RATFOR
\DRC\UNIX{{\SC UNIX}}		\let\Unix\UNIX


@*1 Synonyms for macros such as \.{\\@@} usurped by \FWEB.
\modlabel{syn}
Now define a few things not known to \TeX, and remember some Plain \TeX\
stuff used for other purposes by \FWEB. 

@A
\ifLaTeXisloaded
\else
	\let\@@\relax
	\let\\\relax
	\let\protect\relax
\fi

\let\amp\&
\let\at\@@ 
\let\bslash\\
\let\caret\^
\let\dollar\$
\let\dstar\*
\let\equals\=
\let\leftbrace\{
\let\period\.
\let\rightbrace\}
\let\vertbar|
\let\PM\#
\let\PC\%

@
@A
\let\W@@t\@@
\let\W@@S\S

@ (The following was for Plain \TeX, and is probably obsolete.) 
Additionally, the TeXbook manual macro package \.{manmac} redefines the
following stuff: 

 |\iftitle \titlefont \rhead \pagewidth \pageheight \output|

\noindent If you want to include \.{manmac.tex} to get various macro
definitions, the best scheme is to use the `\.{-w}'~command-line option to
prevent \FWEAVE\ from outputting |\input fwebmac.sty| as the first output line.
Then include both files explicitly, in this order:

	|\input manmac|
	|\input fwebmac.sty|

\noindent You can do this by defining the first limbo text command as
follows:

 |@@l "\\input manmac \\input fwebmac.sty"|

@*1 Paragraph skip and indentation for \TeX\ text.

@A
\dimen0=\normalbaselineskip
\parskip=\dimen0 plus 1pt minus 6pt

% If you don't like spaces between paragraphs, change |\pardimen| to |0pt|.
\newskip\pardimen
\pardimen=\parskip 

%\pardimen 0pt% No stretch between paragraphs

% Indentation for the \TeX\ part is handled in a separate variable
% |\TeXindent| (the style-file parameter \.{indent.TeX}) from the variable
% |\notch| (the style-file parameter \.{indent.code}) used for
% definition and code parts.  
\newdimen\TeXindent
\TeXindent 1em% For paragraphs in the \TeX\ part.

@*1 Page numbering.
If \LaTeX\ is loaded, we equate |\pageno| to \LaTeX's counter so that the
|\label| macro works correctly.  

@A 
\ifLaTeXisloaded
	\let\pageno\c@@page% \WEB\ has its own name for the page number.
\fi

@* FONTS. Several fonts have been declared in addition to the standard ones of
\.{PLAIN} format:
$$\vbox{\halign{\.{\\#}\quad\hfil&---\quad#\hfil\cr
titlefont&\titlefont Title.\cr
ttitlefont&\ttitlefont Title.\cr
SC&\SC SMALL CAPS.\cr
Csc&\Csc CAPS/Small caps.\cr
tentex&\tentex \TeX\ extended character set, including~'\.{\ }'.\cr
bfit&\bfit Bold-faced italic.\cr
}}$$
The main font used for text is called |\mainfont|, which is |\let| to |\tenrm|.
The font used for comments is called |\cmntfont|.  By default, this is
|\let| to |\mainfont|.

@A
\ifnoLaTeXe
	\ifx\tenrm\undefined
		\font\tenrm=cmr10
	\fi
	\ifx\itfam\undefined
		\chardef\itfam4
	\fi
	\ifx\small\undefined
		\let\small\relax
	\fi
	\let\mainfont\tenrm \let\cmntfont\tenrm
	\font\eightrm=cmr8 \let\SC\eightrm 

	\font\titlefont=cmssbx10 scaled \magstep2% Sans serif
	\font\ttitlefont=cmtt10 scaled\magstep2% Typewriter type

	\font\tentex=cmtex10 % \TeX\ \.{extended char.\ set} (used in strings)
	\let\extendedtex\tentex
	\font\Csc=cmcsc10 % Caps/small caps.
	\font\tenbfit=cmbxti10 % \&{Intrinsic functions}
	\let\bfit\tenbfit % Doesn't work right in titles.

% Used for module-number subscript:
	\font\seventi=cmti7
	\font\sevenrm=cmr7
	\font\sevenbf=cmbx7

% For special handling of array indices:
	\font\sevenit=cmti7
	\scriptfont\itfam=\sevenit

@%\font\fiveit=cmti5
@%\scriptscriptfont\itfam=\fiveit
	\scriptscriptfont\itfam=\sevenit

	\def\mathrm#1{{\rm #1}}
	\def\mathit#1{{\it #1}}

\else % \LaTeXe
	\def\mainfont{\normalsize\usefont{OT1}{\rmdefault}{m}{n}}
	\let\cmntfont\mainfont

	\def\eightrm{\footnotesize\usefont{OT1}{\rmdefault}{m}{n}}
	\let\SC\eightrm

	\def\titlefont{\Large\usefont{OT1}{\sfdefault}{\bfdefault}{n}}
	\def\ttitlefont{\Large\usefont{OT1}{\ttdefault}{m}{n}}

	\def\extendedtex{\usefont{OT1}{\ttdefault}{m}{n}}
	\def\tentex{\normalsize\extendedtex}

	\def\Csc{\usefont{OT1}{\rmdefault}{m}{\scdefault}}

	\def\bfit{\usefont{OT1}{\rmdefault}{\bfdefault}{\itdefault}}
	\def\tenbfit{\normalsize\bfit}

	\def\seventi{\scriptsize\usefont{OT1}{\rmdefault}{m}{\itdefault}}
	\def\sevenrm{\scriptsize\usefont{OT1}{\rmdefault}{m}{n}}
	\def\sevenbf{\scriptsize\usefont{OT1}{\rmdefault}{\bfdefault}{n}}

	\def\fiveti{\tiny\usefont{OT1}{\rmdefault}{m}{\itdefault}}
	\def\fiverm{\tiny\usefont{OT1}{\rmdefault}{m}{n}}
	\def\fivebf{\tiny\usefont{OT1}{\rmdefault}{\bfdefault}{n}}

	\def\tensy{\normalsize\usefont{OT1}{cmsy}{m}{n}}

%	\def\pbf{\fontfamily{\rmdefault}\fontseries{\bfdefault}\fontshape{n}%
%		\selectfont}
%	\def\ptt{\fontfamily{\ttdefault}\fontseries{m}\fontshape{n}\selectfont}
\fi

@* HIGHLIGHTING MACROS.  
These are used for displaying identifiers, reserved words, intrinsic
functions, etc.  

@*1 The primitive highlighting macros.
Typically the user (or \FWEB\ automatically) does not
actually type these macros directly.  Instead of saying ``|\Wshort{x}|'',
one says ``|\|x|''.  The associations between the short-hand convenience
macros such as `|\||', `|\&|', etc.\ are made by an equating procedure
carried out by the |\Wbegin| macro (see \WEBsection{Wbegin} below).  The
short-hand names are style-file 
parameters that can be changed by the user.  For more information, consult
the on-line documentation, menu item |fwebmac params|.

@A
\DRC\Wshort[1]{\leavevmode\hbox{$#1$}}% One-letter identifiers such
	% as~\Wshort{x} look better this way.

\DRC\Wid[1]{\leavevmode\hbox{\it#1\/\kern.05em}}% Italic type for ordinary
	% identifiers such as \Wid{test}.

\DRC\WID[1]{\leavevmode\hbox{\small\it#1\/\kern.05em}}% For all \WID{UPPERCASE}.

% By default, macros are formatted the same way as ordinary identifiers.
% However, one can change the following definitions to get special effects.
% Either make your own version of |fwebmac.sty| (use a change file with
% |fwebmac.web|), or redefine |\WidD| and/or |\WidM| with an \.{@@l} command.
\let\WidD\Wid % Outer macro
\let\WIDD\WID % Upper-case outer macro

\let\WidM\Wid % FWEB macro
\let\WIDM\WID % Upper-case FWEB macro

\DRC\Wreserved[1]{\leavevmode\hbox{\def\\{\tt\WBS}\bf#1\/}}% Boldface type
	% for reserved words such as \Wreserved{int}.

\DRC\WRESERVED[1]{\leavevmode\hbox{\def\\{\tt\WBS}\small\bf#1\/}}% Boldface type
	% for upper-case reserved words such as \WRESERVED{INTEGER}.


\DRC\Wintrinsic[1]{\leavevmode\hbox{\def\\{\tt\WBS}\bfit#1\/\kern.05em}}%
	% Library/intrinsic function name such as \@@{sin}.

@*1 Equating abbreviations to the primitive highlighting macros.
In the following, we use |\gdef| instead of |\global\let| because we
might want to change the definition of, e.g., |\WidM| with an \.{@@l}
command, which comes {\it after} the |\Wbegin| statement.

@A
\def\W@@twodef#1#2#3#4{\gdef#1{#3}\gdef#2{#4}}

\def\Wequate#1#2#3#4#5#6#7#8#9{%
	\W@@twodef#1\Wreserved\WRESERVED% |\&| by default.
	\gdef#2{\Wshort}% |\|| by default.
% Don't reorder the following four statements! In case arguments 3--6 are
% identical, one wants the ordinary identifier to win.
	\W@@twodef#5\WidM\WIDM% |\\| by default.
	\W@@twodef#4\WidD\WIDD% |\\| by default.
	\W@@twodef#3\Wid\WID% |\\| by default.
	\gdef#6{\Wintrinsic}% |\@@| by default.
	\W@@twodef#7\Wkeyword\WKEYWORD% |\.| by default.
	\gdef#8{\Wtypewriter}% |\.| by default.
	% \#9 is for future use.
	}

@ Identifiers that are recognized as function or macro names are followed
by the construction\hfil\break
\.{\\WIN\{{\it name}\_{\it type}\}\{{\it module}\_{\it number}\}}.  The
cases for the first argument correspond to 
$$\vbox{\halign{#\hfil&\ ---\ #\hfil\cr
0&Generic name, defined by \.{@@[}.\cr
1&Function name.\cr
2&\WEB\ macro (\.{@@m}).\cr
3&Outer macro (\.{@@d}).\cr
4&Reserved name defined with~\.{@@`}.\cr
5&|@c typedef| name.\cr
}}$$
If the name was defined in the current module, the second argument will be
zero; otherwise it will be the section number in which the name was
defined.  The macro shows how to display the 0~state differently (here with
a bullet).   Also, note how combinations of underlining and fonts are used
to distinguish the various kinds of identifiers.

@A
\def\W@@zero{0}% For the comparison in |\WIN| below.

\DRC\WIN[2]{\ifmmode\def\ZZ{}\else\def\ZZ{\null$\null}\fi
	\ZZ_{\def\W@@rg{#2}\ifx\W@@rg\W@@zero{\bullet}\else\W@@IN{#1}{#2}\fi}\ZZ}


% Format the module-number subscript.
\gdef\W@@IN#1#2{%
	\ifcase#1
	 \underline{\hbox{\sevenrm\Wmodtrans{#2}}}% Generic name (\.{@@[}). [0]
	\or\hbox{\sevenrm\Wmodtrans{#2}}% Function name. [1]
	\or\underline{\hbox{\seventi\Wmodtrans{#2}}}% WEB macro. [2]
	\or\hbox{\seventi\Wmodtrans{#2}}% Outer macro. [3]
	\or\underline{\hbox{\sevenbf\Wmodtrans{#2}}}% \.{@@`}. [4]
	\or\hbox{\sevenbf\Wmodtrans{#2}}% \&{typedef}. [5]
	\else{\Wmodtrans{#2}}% Error trap.
	\fi
	}


@* STRINGS. Strings are indicated by ``\.{\\.\{\dots\}}''.  You can also
use this for typewriter type; remember to escape the appropriate symbols:
``\.{\ \\\#\%\$\^\_\{\}\~\&}''.  The string macro itself does not surround
its contents with an |\hbox|, in order that long strings can be broken by
discretionaries (done automatically by \FWEAVE).

@A
\DRC\Wtypewriter[1]{\relax\ifmmode\gdef\YY{\null$\null}\else\gdef\YY{}\fi
	\YY{\leavevmode\W@@INITSTR#1}\YY}

% The following are for certain \Fortran\ keywords.
\let\Wkeyword\Wtypewriter
\let\WKEYWORD\Wtypewriter

@*1 Nucleus for the string macro.
Here is the nucleus for the string macro~|\.| (more precisely, for
|\Wtypewriter|).

@A
\def\W@@INITSTR{%
	\extendedtex % Typewriter type for strings.  (We don't say
%|\tentex| here so the font can grow in a title.)
	\let\\=\WBS % Backslash in a string: '\.\\'.
	\let\'=\WRQ % Right quote in a string: '\.\''.
	\let\`=\WLQ % Left quote in a string: '\.\`'.
	\let\{=\WLB % Left brace in a string: '\.\WLB'.
	\let\}=\WRB % Right brace in a string: '\.\WRB'.
	\let\~=\WTL % Tilde in a string: '\.\~'.
	\let\ =\WSP % Space in a string: '\.\ '.
	\let\_=\WUL % Underline in a string: '\.\_'.
	\let\&=\WAM % Ampersand in a string: '\.\&'.
	\def\0{\discretionary{\WBS}{}{}}% \FWEB\ inserts this automatically every
	  % so often so very long strings will break. Broken strings will
	  % be marked by a backslash.
	\def\1{,\0}% \FWEB\ replaces commas in strings by this, so strings
		% tend to break after commas.
	\let\2\space % Ordinary space after control sequences in \TeX.
	\def\3{\space\space}% Translation of a tab in \TeX.
	}

@*1 Characters for strings.
@A
\DRC\#{\hbox{\tt\char35}}% Parameter sign: '\#'.
\DRC\${\hbox{\tt\char36}}% Dollar sign: '\$'.
\DRC\%{\hbox{\tt\char37}}% Percent sign: '\%'.
\DRC\^{\ifmmode\raise0.45ex\hbox{$\,\scriptstyle\mathchar"25E\,$}%
	\else\char`^ \fi}% Pointer or 
	% hat: '\^'. 
	% Circumflex accents can be obtained from |\^^D| instead of |\^|.
\let\Caret\^% For proper indexing of |@c++ operator ^|.
\def\AT!{@@}% Knuth's abbreviation for the at sign for control text: '\AT!'

@ The following funny business about asterisks is in case one wants to be
clever and make~`\.*' an active character (for example, for complex
conjugation). 
@A
\chardef\asterisk=`\*
\DRC\ast{\ifmmode{\displaystyle\mathchar"2203}\else\asterisk\fi} 

@ More stuff for strings.
@A
\chardef\WAM=`\&% Ampersand character in a string: '\.\&'.
\chardef\WBS=`\\% Backslash in a string: '\.\\'.
\DRC\WttBS{{\tt\WBS}}% Literal backslash: '\WttBS'.
\chardef\WLB=`\{% Left brace in a string: '\.\WLB'.
\DRC\WLQ{{\tt\char'22}}% Left quote in a string: '\.\`'.
\chardef\WRB=`\}% Right brace in a string: '\.\WRB'.
\DRC\WRQ{{\tt\char'23}}% Right quote in a string: '\.\''.
\DRC\WSP{{\tt\char`\ }}% (Visible) space in a string: '\.\ '.
\chardef\WTL=`\~% Tilde in a string: '\.\~'.
\chardef\WUL=`\_% Underline character in a string: '\.\_'.

@ Left quote outside a string:
@A
\DRC\WLQx{\hbox{\WLQ}}

@* INDENTATION, LINEBREAKS, etc{.}.  These commands are mostly handled by the
macros~|\1| to~|\8|.

@*1 Demonstration of the indentation scheme.
First, here are some macros to draw vertical lines to show off the indentation
scheme.

@A
\newbox\rulebox
\newcount\ruleno

\def\rules#1{\leavevmode
	\ruleno=0
	\rlap{\vtop to 0pt{\null
		\def\R{\setbox0=\hbox{\the\ruleno}%
			\rlap{\vrule height0pt depth#1}%
			\kern-0.5\wd0\copy0\kern-0.5\wd0
			\advance\ruleno by1
			\hskip1em}
		\rlap{\R\R\R\R\R\R\R}
		\vss}}}

@ The indentation scheme is as follows.  The unit of indentation is
|\notch|.
@A
\newdimen\notch

@ Here is typical output.

\setbox\rulebox\vtop{\null
\ifnoLaTeXe
\else
	\let\\\>
\fi
\WY $\WP\WE{if}\WO{1}{}$\par
\WP\WMd$\@|A\WIN2{0}$\5
$\WO{2}{}$\par
\WP\WE{endif}\par
\WP\WMD$\\{ALPHA}$\5
$\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+%
\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+%
\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+%
\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+%
\\{xxx}+\\{yyy}+\\{xxx}{}$\par
\WY\WP$\\{main}(\,)$\1\1\6
\&{int} \1\\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, %
\\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, %
\\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde}, \\{abcde};\2%
\2\2\1\6
$\{{}$\6
\WE{if}$\WO{1111}+\WO{2222}+\WO{1111}+\WO{2222}+\WO{1111}+\WO{2222}+\WO{1111}+%
\WO{2222}+\WO{1111}+\WO{2222}+\\{aaaa}+\\{bbbb}+\WO{1111}+\WO{2222}+\WO{1111}+%
\WO{2222}+\WO{1111}+\WO{2222}+\WO{1111}+\WO{2222}+\WO{1111}+\WO{2222}$\WPs\7
$\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+%
\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+%
\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\{yyy}+\\{xxx}+\\z;{}$%
\7
\WE{endif}\WPs\6
$\}$\2\WY\par
}

\vbox{\noindent\rules{\dp\rulebox}\box\rulebox}

@*1 Indentation conventions.
Preprocessor commands in the definition part are far left, definition-part
commands such  
as~\.{@@m} are indented one notch, function names are at two notches, and
the body of functions is at three notches.  This distance is given the
special name |\W@@globalindent|:

@A
\newcount\W@@globalindent
\W@@globalindent=3 % Global indentation in notches.

@ The current indentation is called |\W@@ind|.  One also sometimes needs to save
and restore that.
@A
\newcount\W@@ind % Current indentation in notches.
\newcount\W@@lastind % Used for preprocessor commands.
\def\W@@saveind{\global\W@@lastind=\W@@ind}

@*1 Backspacing.
Each output line of code is a separate paragraph.  The scheme proceeds by
first setting |\W@@ind|~to the appropriate hanging indentation, then
backspacing appropriately.  Here are the backspace quantities.  Note that
one can't initialize the boxes here, because the value of |\notch| isn't
known until after |\Wbegin| (it's the style-file parameter \.{indent.code}).

@A
\newbox\b@@k  
\newbox\b@@kk 

\def\W@@setboxes#1{\notch=#1
	\setbox\b@@k=\hbox to -\notch{}% Backspace one notch.
	\setbox\b@@kk=\hbox to -2\notch{}% Backspace two notches.
	}

@ In order to implement the line-break macro |@@/| appropriately, the
|\WBK| macro is emitted.  This must deal with the fact that sometimes, but
not always, the hanging indentation is changed in the middle of the line
(as in a variable declaration like `|@c int i,j;|'.  Therefore, |\WBK|
computes the proper indentation at the point of its first occurence in the
line, and uses that for all subsequent instances of |\WBK| within that same
line.

@A
\newif\ifW@@firstbreak

\newcount\W@@BK

\def\WBK{\hfil\break
\ifW@@firstbreak
	\W@@BK=\W@@ind
	\advance\W@@BK by -1 % Compensate for globals outdented by 1 from body.
	\W@@firstbreakfalse % Reset by |\6|.
\fi
\hangindent\W@@BK\notch
\ignorespaces}

@*1 The macros |\1| to |\8|.
When there's the possibility that a line of code may be continued, we
advance the indentation and set |\hangindent|.
@A
\def\1{\global\advance\W@@ind by1\hangindent\W@@ind\notch}% Indent one more notch

@ Here we cancel the above.  One doesn't need to reset |\hangindent| because
this will always be followed by a~|\6| or~|\7|, which already does that.
@A
\def\2{\global\advance\W@@ind by-1{}}% Indent one less notch

@ Now we provide for an optional break within a statement.  (Note that the
argument is multiplied by~10.)
@A
\def\3#1{\hfil\penalty#10\hfilneg}% Optional break within a statement.

@ A simple command to backspace one notch.
@A
\def\4{\copy\b@@k \ignorespaces}% Backspace one notch

@ Optional break (the |\yskipfalse| may be obsolete).
@A
\def\5{\hfil\penalty-1\hfilneg \kern2.5\notch\copy\b@@kk
	\yskipfalse\ignorespaces}

@ The next command forces a line break.
@A
\def\6{\ifmmode\else\par
	\hangindent\W@@ind\notch \noindent \kern\W@@ind\notch \copy\b@@kk \ignorespaces\fi}

@ This also forces a line break, but also adds some extra vertical space.
@A
\def\7{\WY\6}% Forced break and a little extra space.

@ No indentation.
@A
\def\8{\hskip-\W@@ind\notch \hskip 2\notch}

@
@A
\newif\ifyskip
\def\yskip{\medskip}

@* PREPROCESSOR COMMANDS.  The preprocessor commands are built out of the
previous ones.

First, we define a guaranteed space.
@A
\def\W@@Hspace{\hbox{ }}

@ Start a preprocessor command such as \.{@@\#if}.  When these are issued
in the code section (rather than in the definition section), one must
remember the present level of indentation.  That's restored with~|\WPs|.

@A
\DRC\WPR[1]{\copy\b@@kk \W@@saveind%	|\global\advance\W@@ind by 2|
	\1\Wreserved{@@#1}\W@@Hspace}

\DRC\WPs{\global\W@@ind=\W@@lastind}

@ The definition commands such as~\.{@@m} are similar, except that they
also take a language argument.
@A
\def\W@@defin#1#2{\4\W@@saveind
	\1\Wreserved{#1}\hbox{$^{\mathrm{#2}}$}\W@@Hspace}% Begin @@d, @@m, or @@f.

@* VARIOUS NUCLEII.
Here are some miscellaneous macros used by the innards of this macro package.

@A
\def\note#1#2.{\WY\noindent{\hangindent2em\baselineskip10pt\footnotesize
#1 #2.\par}}

@*1 Star macros.
@A
\def\W@@lapstar{\rlap{*}}

\newif\ifW@@modchanged

\def\W@@checkstar{\edef\W@@temp{\noexpand\W@@isstar\modstar\noexpand\*\relax}%
\W@@temp}

\def\W@@isstar#1\*#2\relax{\ifx#2\*\W@@modchangedtrue\else\W@@modchangedfalse\fi}

@*1 Printing the current include file.
If there's a current include file, it's printed at the start of each
section.  The macro |\WIF| is emitted by \FWEAVE\ and stores the current
include-file name into |\W@@includefile|.  |\WIF@@name| actually prints it,
according to the macro |\WIFfmt|.

@A
\def\W@@includefile{}

\def\WIF#1{\gdef\W@@includefile{#1}}

\def\WIF@@name{\ifx\W@@includefile\empty
	\else
		\W@@prninclude
	\fi}

\def\W@@prninclude{\ifLaTeXisloaded\else\ \fi
		\WIFfmt{\W@@includefile} }

\def\WIFfmt#1{[{\tt#1}]}

\def\W@@startsection{\WQ
	\W@@checkstar
	{\let\*=\W@@lapstar
	\ifLaTeXisloaded
		\leavevmode
	\else
		\noindent
		\bf\modstar.%
	\fi
	\WIF@@name% Print name of current include file, if there is one.
	\ifLaTeXisloaded\else\quad\fi
	}}

@* HARD-CODED MACROS.  
We now describe various macros hard-coded into \FWEAVE, and their support macros.

@*1 Comments.
Comments are C-style.  The long comment construction `|/* ...*/|' 
is output as `|\WC{ ... }|'; the short comment is output as `|\Wc{ ...}|'. 
The |\WC| and~|\Wc| macros aren't simply defined with an argument
whose text would be the comment because one wants the comment to be a group
and the user might be wanting to change catcodes inside that group; the
argument form would absorb catcodes before they were changed.

@A
\def\W@@skipbrace#1{\catcode`\{=1 }

\DRC\WC{\W@@cmnt{/\ast}{\W@@finishcomment}}% Long
\DRC\Wc{\W@@cmnt{//}{\XX}}% Short
\DRC\Wci{\W@@cmnt{}{\XX}}% No comment symbol at all; for special effects.

\def\W@@cmnt#1#2{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi% C-style cmnt
	\XX\hfil\penalty-1\hfilneg
	\ifyskip\else\quad\fi$#1\,$%
	\bgroup\cmntfont % The user can redefine the comment font |\cmntfont|.
		\aftergroup#2%
		\catcode`\{=\other\W@@skipbrace}

\def\W@@finishcomment{$\,\ast/$\XX}

\def\Wx#1{\kern-0.5\notch\hbox{\tt\%}}

@ Compiler directives are essentially comments, but are formatted more like
preprocessor commands.
@A
\def\WCDIR#1{\WPR?\Wtypewriter{#1}\WPs}

@*1 Code mode.  Code mode is entered by vertical bars, giving an effect
such as |@c x=y|.  Because we make |\WCD| a robust command, code mode may
be used inside the names of starred sections (\LaTeXe\ only).

@A
\DRC\WCD[1]{\ifmmode\hbox\fi{\ignorespaces#1}}

@*1 Definitions. Various definition section stuff.
@A
\def\WD#1{\W@@defin{@@D}{#1}}% Outer macro definition: `\.{@@D}' 
\def\Wd#1{\W@@defin{@@d}{#1}}% Outer macro definition: `\.{@@d}' 
\def\WUd#1{\W@@defin{@@u}{#1}}% Undef outer macro: `\.{@@u}'.
\def\WMD{\W@@defin{@@M}{}}% WEB macro definition: `\.{@@M}'.
\def\WMd{\W@@defin{@@m}{}}% WEB macro definition: `\.{@@m}'.
\def\WE#1{\WPR{\##1}}% WEB preprocessor command: `\.{@@\#if\dots}'.

\def\Wf#1{\W@@defin{@@f}{#1}}% Format definition: `\.{@@f}'.
\def\WF#1{\W@@defin{@@F}{#1}}% Format definition: `\.{@@F}'.

\def\Wl#1{\W@@defin{@@l}{#1}}% Limbo text definition: `\.{@@l}'.
\def\Wv#1{\W@@defin{@@v}{#1}}% Operator overloading: `\.{@@v}'.
\def\WWW#1{\W@@defin{@@W}{#1}}% Identifier overloading:  `\.{@@W}'.
\def\Ww#1{\W@@defin{@@w}{#1}}% Identifier overloading:  `\.{@@w}'.

@*1 Sections.  
\FWEB\ supports both page number or section-number references.
The style-file entry \.{encap.prefix} defines a \TeX\ macro---empty by
default for TeX, ``|\M|'' by default for \LaTeX.  When this macro is
non-empty, it encloses the integer section numbers that are spit out by \FWEAVE.
The |\Wbegin| macro uses |\W@@modequate| to define this macro to
|\Wmodtrans|, which is the primitive that actually interprets the section
number.  For \TeX, |\Wmodtrans| is just the identity, so one gets ordinary
section numbers.  For \LaTeX, |\Wmodtrans| converts into either page or
section numbers, depending on the setting of |\ifpagerefs|.  

@*2 Customizing the referencing style.
(As an example, the current document is produced with the non-default
settings |\numberdefsfalse| and |\numbercodefalse|.)
@A
\newif\ifpagerefs% Page references or module-number references?
\pagerefsfalse

\newif\ifnumberTeX% Do we start the \TeX\ part of unnamed sections with
% a section number? 
\numberTeXfalse

\newif\ifnumberdefs% As above, but for the definition part.
\numberdefstrue

\newif\ifnumbercode% As above, but for the code part.
\numbercodetrue

% The following works in conjunction with the \LaTeXe\ package |fwebnum|.
\newif\ifnumberunnamed% Number unnamed section?
\numberunnamedfalse

\newskip\Wuparindent
\let\Wrefstepcounter\refstepcounter

% The following flag is explained in \WEBsection{strip}.
\newif\ifstripzeros
\stripzerostrue % By default, we're bold.

\def\W@@modequate#1{\def\W@@temp{#1}%
\ifx\W@@temp\empty\else
	\gdef#1{\Wmodtrans}%
\fi}

@*2 Sectioning commands.  
When LaTeX is selected with ``\.{-PL}'' (this is now the default), we use
LaTeX's sectioning commands.  The |\W@@depth| macro is defined at the
bottom of the \.{aux} file to be the maximum depth of the \.{@@*}$n$
commands, plus~1.  In other words, it's the effective level of the unnamed
sections.

@A
\newcount\W@@ssmax% Maximum depth of the \.{@@*}$n$ commands.
\newcount\W@@lsmax% Max. local (per section) depth of the \.{@@*}$n$ commands.

\def\W@@maxdepth#1{{\count0=#1 
	\advance\count0 by\W@@ssmin%
	\xdef\W@@depth{\the\count0}}}

\def\Wunnamed#1#2{\csname ifnumber#1\endcsname
	\gdef\Wnewoutname{#2}%
	\ifx\Woutname\Wnewoutname\else
		\8\.{"#2"} \Wscrap ${}\equiv{}$\6%
		\global\let\Woutname\Wnewoutname
	\fi\fi}

@ The |\W@@Lvmode| macro is basically a redefinition of \LaTeX's |\addpenalty|
command to include the |\vfil| and |\vfilneg| commands.  This is supposed
to encourage it to break between sections.

When |\secpenalty| is non-negative, however, |\addpenalty| is not
redefined, and breaking at sections is not encouraged.  The tricky thing is
to set |\secpenalty| at the appropriate place.  The solution is to use the
style-file and say ``\.{doc.preamble "\\secpenalty0"}''.  This is executed
just before the |\W@@raggedbottom| command during |\Wbegin|.

@A
\newcount\secpenalty
\secpenalty=-500 % Strongly encourage breaks at sections.

% Although the following is used only in \LaTeX, don't put it inside the
% |\ifLaTeXisloaded| because of \TeX's |\if| parsing.
\def\W@@Lvmode#1{%
\if@@minipage\else
\if@@nobreak\else
\ifdim\lastskip=\z@@
	\vfil
	\penalty#1\relax
	\vfilneg
\else
	\@@tempskipb\lastskip
	\vskip-\lastskip
	\vfil
	\penalty#1
	\vfilneg
	\vskip\@@tempskipb
\fi\fi\fi}

\ifLaTeXisloaded

	\def\W@@raggedbottom{\def\@@textbottom{\vskip\z@@ \vfil}%
		\let\@@texttop\relax
% Very strongly encourage to break at beginning of sections.
		\@@secpenalty=\secpenalty
		\ifnum\secpenalty<0
			\def\addpenalty##1{%
				\ifvmode
					\W@@Lvmode{##1}%
				\else
					\@@noitemerr
				\fi}
		\fi
		}

@ The deepest named section is \.{1.1.1}, corresponding to a
sub-sub-section.  The associated unnamed section will then be a
sub-sub-sub-section, which we must declare.
@A
	\newcounter{subsubsubsection}

	\gdef\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}

	\gdef\cl@@subsubsubsection{\@@elt{paragraph}}
	\gdef\l@@subsubsubsection{\@@dottedtocline{4}{3.8em}{3.2em}}
	\gdef\subsubsubsectionmark#1{}

 \ifnoLaTeXe
	\gdef\paragraph{\@@startsection{paragraph}{5}{\z@@}{3.25ex plus1ex
minus.2ex}{-1em}{\reset@@font\normalsize\bf}}
 \fi

% After the \.{aux} file is read, we must set things up based on the depth
% parameter |\W@@depth|. 
	\gdef\W@@setsecdepth{%
		\@@ifundefined{W@@depth}{\gdef\W@@depth{1}}{}%
		\setcounter{secnumdepth}{\W@@depth}%
		\setcounter{tocdepth}{\W@@depth}%
% Redefine appropriate section heading to begin the unnamed section.
% At the moment, this only works right if the major sections don't go down
% any deeper than 1.1.1.
		\ifnumberunnamed
			\Wuparindent0pt
			\addtocounter{secnumdepth}{1}%
			\gdef\WRefstepcounter##1{}%
		\else
			\Wuparindent-\TeXindent
			\global\let\WRefstepcounter\Wrefstepcounter
		\fi
		\ifcase\W@@depth % Level 0; should never happen.
		\or % Level 1
			\def\subsection{\WRefstepcounter{subsection}%
\@@startsection{subsection}{2}{\z@@}{-3.25ex plus-1ex minus-.2ex}{\Wuparindent}
{\reset@@font \normalsize \bf}}%
			\let\Wunnamedsect\subsection
		\or % Level 2
			\def\subsubsection{\WRefstepcounter{subsubsection}%
\@@startsection{subsubsection}{3}{\z@@}{-3.25ex plus-1ex minus-.2ex}
{\Wuparindent}{\reset@@font \normalsize \bf}}%
			\let\Wunnamedsect\subsubsection
		\or % Level 3
			\def\subsubsubsection{%
\WRefstepcounter{subsubsubsection}%
\@@startsection{subsubsubsection}{4}{\z@@}{-3.25ex plus-1ex minus-.2ex}
{\Wuparindent}{\reset@@font \normalsize \bf}}%
			\let\Wunnamedsect\subsubsubsection
		\else
			\let\Wunnamedsect\paragraph
		\fi
		}

@*2 Converting module numbers into section or page numbers.
Here is the primitive macro that converts a module number into \LaTeX's
section number or page number.  This works by label information written
to the \.{aux} file by the \FWEAVE\ section macros |\WM| and |\WN|.
@A
	\gdef\Wmodtrans#1{\@@ifundefined{r@@#1}
		{\W@@split{\##1}{\##1}{0}{0}}
		{\expandafter\expandafter\expandafter
			\W@@split\csname r@@#1\endcsname{#1}}%
		}

@ Here we convert the \.{aux} label info into a page or section number.
Pages are not too complicated.  The real problem comes with ensuring that
the unnamed sections are numbered at the deepest depth of the file, but
only for the particular section.  Because the mechanism is complicated, we
introduce a flag |\stripzeros| that can turn it off if it doesn't work.
\modlabel{strip}
@A
	\gdef\W@@split#1#2#3#4{%
		\ifpagerefs
			#2%
			\@@ifundefined{W@@#3}%
				{\setcounter{W@@tempcounter}{#4}%
				\addtocounter{W@@tempcounter}{-#3}%
\ifnum\value{W@@tempcounter}>25 \setcounter{W@@tempcounter}{25}\fi
				\hbox{\alph{W@@tempcounter}}}
				{}%
		\else
			\ifstripzeros
				\W@@strip#1.,%
			\else
				#1
			\fi
		\fi
		}

@ In order to know how to strip, each major section at level 0 writes out
to the \.{aux} file a line of the form |\Lastdepth{lastsect}{maxdepth}|.
When the \.{aux} file is read in,  |\Lastdepth| defines macros of the form
|\l@@lastsect|. These can then be used to control the zero stripping.

For example, the raw section number might be \S4.0.0.1, because the
maximum depth |\W@@depth| for some section (not necessarily \S4) was 3.
However, if \S4 had no subsections at all (a last depth of 1), we can
number the unnamed section \S4.1---i.e., we want to strip off $3 - 1 = 2$
units of `\.{.0}'.  This is what |\W@@STRIP| does.  The intermediate macros
beginning with |\W@@strip| take care of various subsidiary annoyances.

|\W@@strip| picks off the level-0 section number from its argument.  It
must also watch out for an argument of the form |\#5|, which arises when
the \LaTeX\ section number is undefined.
@A

	\def\W@@strip#1.#2,{\W@@first#1\relax \W@@tempc{#1}{#2}}

	\def\W@@first#1#2\relax{\ifx#1\#\def\W@@tempc##1##2{##1}\else
\def\W@@tempc##1##2{\W@@Strip{##1.##2}
{\@@ifundefined{l@@##1}{0}{\csname l@@##1\endcsname}}}\fi}

@ |\W@@Strip| gets two arguments of the form `\.{4.0.0.1.}' and the last
maximum depth.
@A
	\def\W@@Strip#1#2{\W@@STRIP#1\relax{#2}}

@ |\W@@STRIP| kills off the final dot, figures out how many zeros to strip,
constructs a macro definition with the appropriate template, then applies
it to the section number.
@A
	\def\W@@STRIP#1.\relax#2{{%
\W@@tk={}\W@@count=0
\W@@counta=\W@@depth
\advance\W@@counta by-#2 % How many zeros to strip.
\loop
\ifnum\W@@count<\W@@counta
	\advance\W@@count by1
	\edef\next{\W@@tk={\the\W@@tk.0}}\next % Build template `\.{.0.0\dots}'.
\repeat
% We must worry about the possibility that there are no zeros at all.
\let\eat\let
\edef\next{\def\noexpand\reduce####1\the\W@@tk####2\eat####3\eat
{\noexpand\W@@preface{####1}####2}}%
\next
\edef\next{\noexpand\reduce#1\eat\the\W@@tk\eat\eat\relax}%
\def\eat##1{}%
\next}}

	\global\let\modno\empty
	\global\let\W@@name\empty

	\def\W@@preface#1{\ifFWEBstandalone#1\else
		\ifcase\W@@ssmin\relax% |\relax| terminates expansion of |\W@@ssmin|
			\thesection
		\or
			\thesection.#1%
		\or
			\thesubsection.#1%
		\or
			\thesubsubsection.#1%
		\fi
		\fi}

@*2 Beginning of unnamed section.
@A
	\def\WM#1.{\WMN#1.%
		\W@@mark{{\oldmodno}{\oldWname}}{{\modno}{\W@@name}}%
		\ifon
			\advance\W@@ss by10 %
			\W@@start{\ifnumberTeX\Wmodtrans{\modno}\fi}% ????
			\advance\W@@ss by-10 %
			\ignorespaces}
\else % No \LaTeX; for \TeX, one just gets module numbers.
	\def\Wmodtrans#1{#1}

	\outer\def\WM#1.{\WMN#1.\W@@mark\ifon\Wskip\W@@startsection\ignorespaces}
\fi % End of no \LaTeX.

@*2 Beginning of starred section.
Starred sections  (begun with~`\.{@@*}')
have associated level numbers, where 0~denotes the most significant level,
1~denotes a subsection, 2~denotes a subsubsection, and so on.  One can
indicate the level number in several ways.  By default, one can say
``\.{@@*3\ Section name.}'' or equivalently ``\.{@@*...\ Section name.}''
to set the level number to~3.  Alternatively, if one replaces the line below
``\.{\\W@@dotsafterfalse}'' with ``\.{\\W@@dotsaftertrue}'', one can instead say
``\.{@@*\ Section name....}'' (but don't do it).

\begin{itemize}
\item
For \TeX:  By default, major sections get a page break;
subsections don't.  Sections and subsections can be formatted in different
ways in the table of contents by enhancing the definition of~|\WZ|
(inside~|\Wcon|) to include an |\ifcase| construction.  

\item
For \LaTeX:  The appropriate \LaTeX\ section command is used.

\end{itemize}

@A
\newcount\W@@ss % Counter for the dots.

\newif\ifW@@dotsafter % Do subsection dots come after or before the section name?
\W@@dotsafterfalse

\ifW@@dotsafter % ``@@* NAME...''
	\def\W@@before/#1.{\W@@defname{#1}\W@@dot}%
	\def\W@@fter{\W@@Nss}%
\else % ``@@*.. NAME.'' or ``@@*2 NAME.''
	\def\W@@before/ {\futurelet\next\W@@check}%
	\def\W@@fter#1.{\W@@defname{#1}\W@@Nss}% Done after figuring out level.
	\def\W@@fter@@#1 #2.{\W@@defname{#2}\W@@Nss}%
\fi

\def\W@@check{\ifx\next.\def\next{\W@@dot.}% Count arbitrary dots.
	\else\ifx\next1\W@@sectionnum1%
	\else\ifx\next2\W@@sectionnum2%
	\else\ifx\next3\W@@sectionnum3%
	\else\ifx\next4\W@@sectionnum4% Highest numerical level allowed.
	\else\let\next\W@@fter
	\fi\fi\fi\fi\fi
	\next}%

% Assign numerical section number.
\def\W@@sectionnum#1{\W@@ss#1%
	\advance\W@@ss by\W@@ssmin
	\let\next\W@@fter@@}

@ By default, the full section name is used as a headline.  Sometimes that
might be too long.  To deal with that, an optional argument may be used, as
follows:
\begin{verbatim}
	@@* [Short headline]Full section name.
\end{verbatim}
Then the optional argument will be used instead.  (There should be no
brace-protected periods inside the optional argument, because the whole
construction up to the final period is absorbed at once.)
@A
\def\W@@defname#1{\@@ifnextchar[{\W@@getname}{\W@@getname[#1]}#1.}

\def\W@@getname[#1]#2.{\gdef\W@@name{#1}% Running headline (short name).
	\gdef\W@@longname{#2}}% Remember name of section (used in |\W@@start|).

\def\W@@ssmin{0}% The lowest (top) level.

\def\WN#1.{\WMN#1.\W@@ss=\W@@ssmin \W@@before/}% Begin a starred section.

@ Here we set up to output the maximum local section depth to the table of
contents.  For more explanation, see \WEBsection{strip}.
@A
% Put this here, not inside |\ifLaTeXisloaded|.
\def\W@@outlsmax#1{\if@@filesw
	{%
% The following doesn't work if one uses something like |\Roman| for
% |\thesection|.  If we only used LaTeX, it would be trivial to fix by
% replacing |\@@currentlabel| by |\c@@section| (I think).
	\ifLaTeXisloaded
		\expandafter\W@@major\c@@section.\relax
	\else
		\expandafter\W@@major\@@currentlabel.\relax
	\fi
	\advance\W@@count by#1
	\advance\W@@count by-1
	\advance\W@@lsmax by1
	\edef\@@tempa{\ifFWEBstandalone
		\write\@@auxout{\string\Lastdepth{\the\W@@count}%
		{\the\W@@lsmax}}%
		\fi}% 
	\expandafter}\@@tempa
	\fi
	\W@@lsmax=0
	}

\ifLaTeXisloaded

	\def\W@@major#1.#2\relax{\W@@count=#1}% Get the major section.

	\def\Lastdepth#1#2{\edef\@@tempc{\gdef\expandafter\noexpand
\csname l@@#1\endcsname{#2}}\@@tempc}

\else
	\def\W@@outlsmax#1{}
\fi

@ Here we count the periods before or after the section name.
@A
\def\W@@dot{\futurelet\next\W@@Ns}

\def\W@@Ns{\ifx\next.%
	\advance\W@@ss by 1
	\let\next\W@@next
\else
	\let\next\W@@fter
\fi
\next}

\def\W@@next#1{\W@@dot}

@ Now actually begin the section.  Note the use of~|\ifcase| to
conditionally format the sections and subsections.  Also, the construction
|\ifon...\fi| brackets the section to conditionally suppress printing.
Finally, we make an entry in the table of contents for all starred names.
The first argument of the \.{\\WZ}~macro is the level number for this
section.  This can be used to format the table of contents in various ways.

The order of expansion is an issue in the~|\write| to the table of contents
file~|\W@@cont|.  One wants the macro~|\WZ| to be sent unexpanded, so we
|\let|~it equal to a primitive.  Also, it's possible that a~|\WIN| will
appear inside of~|\W@@name| (if the user included certain kind of code inside
the section name).  This shouldn't be expanded until later, so we turn that
into the temporarily unexpandable macro~|\WIM|.  (This is presumably
unnecessary for \LaTeXe, since |\WIN| is made robust.)

@A
% Page break for major sections.
\ifLaTeXisloaded
	\let\Wsectionbreak\relax
\else
	\def\Wsectionbreak{\ifcase\W@@ss\vfil\eject\fi}
\fi

% Running headline.
\def\rhead{\ifcase\W@@ss
		\uppercase{\ignorespaces\W@@name}%
	\else
		\ignorespaces\W@@name%
	\fi}% Define running headline.

\let\WZ\let % Now one can |\send| the control sequence |\WZ|
\let\WIM\let % This macro is made temporarily unexpandable; see |\WZ|.

\def\W@@Llabel#1{\@@bsphack
	\if@@filesw
		{\let\thepage\relax
		\let\W@@botmodno\relax
		\def\protect{\noexpand\noexpand\noexpand}%
		\edef\@@tempa{\ifFWEBstandalone
			\write\@@auxout{\string\Newlabel{#1}%
			{{\@@currentlabel}{\thepage}}{\W@@botmodno}}%
			\fi}%
		\expandafter}\@@tempa
		\if@@nobreak
			\ifvmode
				\nobreak
			\fi
		\fi
	\fi
	\@@esphack}

\ifLaTeXisloaded
	\gdef\W@@Nss{%
		\W@@mark{{\oldmodno}{\oldWname}}{{\modno}{\W@@name}}%
% Can't put this in |\WMN| since |\rhead| must be defined first. 
		\message{*\modno}% Progress report to the terminal.
		\ifon
			\ifnum\W@@ss>\W@@ssmax
				\global\W@@ssmax=\W@@ss% Keep track of max depth.
			\fi
			\ifnum\W@@ss>\W@@lsmax
				\global\W@@lsmax=\W@@ss% Maximum local depth.
			\fi
			\W@@start{\W@@longname}%
			\ignorespaces
		}

	\def\steppagemodule{\noexpand\expandafter\expandafter\expandafter
{\addtocounter{pagemodule}{1}}\thepagemodule}

	\let\Wlabel\W@@Llabel

@ If the section name is exactly ``\.{INDEX}'' (or more precisely the
 contents of the style-file parameter |index.name|), we	issue the
|\beforeindex| command.  By default, this is defined as follows:  If
\.{multicol.sty} is not loaded, we switch into 
|\twocolumn| mode, thereby starting the index on a new page.  If it is
loaded, we just issue a |\newpage| command.  Later, after the beginning of
the \.{INDEX} section is executed, the |\startsection| command will begin
the multi-column mode.
@A
	\gdef\beforeindex{\ifx\multicols\undefined\twocolumn\else\newpage\fi}

	\gdef\W@@start#1{%
		{\let\protect\noexpand \xdef\Wupname{\W@@name}}%
		\ifx\Wupname\INDEX\beforeindex\fi
% Select the appropriate \LaTeX\ section command.
		\ifcase\W@@ss
			\let\Wsect\section % Level 0
		\or
			\let\Wsect\subsection % Level 1
		\or
			\let\Wsect\subsubsection % Level 2
		\else
			\let\Wsect\Wunnamedsect
		\fi
		\Wsect{#1}% LaTeX section heading.
		\ifnum\W@@ss=0 \W@@outlsmax{0}\fi
		\W@@mark{{\modno}{\W@@name}}{{\modno}{\W@@name}}%
		\Wlabel{\modno}% Section number to aux file.
		\@@ifundefined{r@@\modno}
			{\expandafter\xdef\csname r@@\modno\endcsname
				{{\@@currentlabel}{\thepage}{-1}}}
			{}% For present run.
%	\message{modno=\modno [\csname r@@\modno\endcsname]} % Debugging.
		\W@@startsection
		}
\else % No \LaTeX

\def\W@@Nss{%
	\let\protect\noexpand
	\W@@mark%Can't put this in |\WMN| since |\rhead| must be defined first. 
	\Wsectionbreak % Typeset the break between sections.
	\message{*\modno}% Progress report to the terminal.
	\ifon
		\ifcase\W@@ss\else\Wskip\fi
		\W@@startsection{\bf\ignorespaces\W@@name.\quad}%
		{\def\WIN{\WIM}%
		\edef\next{\write\W@@cont{\WZ{\the\W@@ss}{\W@@name}%
		{\modno}{\noexpand\the\pageno}}}\next}%
			% To contents file |CONTENTS.tex|.
		\ignorespaces}
\fi

@ The marks that are emitted just before |\Wsectionbreak| are of the form
``{\it modno}|\else|{\it section name}''.   Both  parts are used in the
page headers.  In handling the section name, one must take care to avoid
expanding the macro~|\WIN| prematurely.  This is done just as in~|\W@@Nss|
above. 

@A
\def\W@@markN{\def\W@@mark{{\def\WIN{\WIM}%
		\mark{\modno\noexpand\else\rhead}}}}

\ifx\selectfont\undefined
	\W@@markN
\else
	\def\W@@mark{{\def\WIN{\WIM}\let\protect\noexpand
		\mark{\modno\noexpand\else\rhead}}}
\fi

\def\Wmodno{\iftrue\topmark\fi}% Extracts the left-hand part of the mark.

\def\Whead{{\let\WIM\WIN
	\expandafter\iffalse\topmark\fi}}% Extracts the right-hand part.

@ Common code for |\WM|, |\WN|.  
@A
\def\WMN#1.{\par
	\parskip=\pardimen % Reset to \TeX\ spacing
	\parindent=\TeXindent
	{\ifLaTeXisloaded
		\global\let\oldmodno\modno
		\global\let\oldWname\W@@name
		\xdef\@@currentlabel{\modno}%
		\global\let\Woutname\empty
		\addtocounter{pagemodule}{1}%
	\fi
	\xdef\modstar{#1}%
	\let\*=\empty
	\xdef\modno{#1}%
	}%
	\ifx\modno\modstar 
		\global\onmaybe 
	\else
		\global\ontrue 
	\fi
	}

%\let\MN\WMN % Backward compatibility.  Commented out for v1.60.

@*1 Nuweb mode.
When the `N' mode is in effect, code to be transcribed verbatim will be
bracketed by |\WBM|\dots|\WEM|.

@A
\def\Wscrap{{\footnotesize\Wmodtrans{\modno}%
	\ifW@@modchanged*\fi}}

{\gdef\@@verbatim{\if@@minipage \else \vskip \parskip \fi
\leftskip 
 \@@totalleftmargin \rightskip \z@@ \parindent \z@@ \parfillskip \@@flushglue
\parskip \z@@ \@@@@par \@@tempswafalse \def \par {\if@@tempswa \hbox {}\fi
\@@tempswatrue  
\@@@@par \penalty \interlinepenalty }\obeylines \tt \catcode ``=13
\@@noligs \let \do \@@makeother \dospecials}}

{\catcode`/=0 /catcode`/\=12 /catcode`/^^I=13 
/gdef/WBM{%/8/kern/notch
/begingroup
/parindent/W@@globalindent/notch /advance/parindent by-1/notch
/def/par{/endgraf/leavevmode}%
/catcode`^^I=13 /def^^I{/leavevmode/penalty10000/ / / / / / / / }%
/catcode``=13 /@@noligs /tt 
/let/do/@@makeother /dospecials 
/@@vobeyspaces/frenchspacing/obeylines 
/W@@M}
/gdef/W@@M#1\WEM{#1/endgroup}}

@*1 Constants.  Various kinds of constants are handled:  decimal~(|@c 10|),
hexadecimal~(|@c 0xA|), octal~(|@c 012|), boolean~(|@c 0b1010|), 
floating-point (|@c 1.5e-35|), double-precision (|@n @e3.2d100|),
long (|@c 99999L|), unsigned (|@c 99999U|),
unsigned long (|@c 999999UL|), and Hollerith (|@r 3Habc|).

@A
\def\WDP#1{\ifx E#1\else{\tt#1}\fi}% Used in the exponent macro below.

\DRC\WO[1]{%
	{% Make the next definitions local.
	\let\-\_%
	\let\d\$%
	\def\\{\let\_\-\let\$\d}%
	\def\?{\kern.2em}%
	\def\###1{\kern0.1em{\tt \ifcase##1F\or L\or U\or UL\else?\fi}}%C~constant. 
	\def\^##1{\cdot 10^{\aftergroup}\aftergroup\WDP\aftergroup##1}% Power of ten
	\def\_{_{\\\rm\aftergroup}}% Fortran-90 kind parameter.
	\def\%{{\rm H}\hbox{\aftergroup}\Wtypewriter{\aftergroup}}% Hollerith constant
	\def\&{0{\tt b}}% Binary constant.
	\def\~{\hbox{\rm\char'23\kern-.2em\it\aftergroup\?\aftergroup}}% Octal
	\def\`{\hbox{\rm\char"7D\tt\aftergroup}}#1}}% Double quotes for hex constant


@*1 Code mode.  Either begin the code section, or a preprocessor or
definition command.

The following command sets up~|\W@@ind|.  This somewhat peculiar construction
is for historical reasons.  Again, the global indentation is for the body
of functions.  The natural hanging indentation for continued lines is one
more notch; hence the |\1|.

@A
\def\WPr{\global\W@@ind=\W@@globalindent \1}

@ Now enter code mode.  Note that |\leavevmode| starts a new indented
paragraph; we then move in one more notch.
@A
\def\WP{\parskip=0pt \parindent=\notch
	\rightskip=0pt plus 100pt minus 10pt 
	\sfcode`;=3000
	\pretolerance 10000
@#if 0
	\hyphenpenalty 10000 \exhyphenpenalty 10000 % If one turns these on, the
	% discretionary breaks in strings won't work!
	\global\W@@ind=\W@@globalindent \1\ \unskip}
@#endif
	\WPr
	\W@@firstbreaktrue % Reset to true by |\6|.
	\leavevmode\kern\notch}

@ Here we leave code mode.  The |\Wend| macros can be redefined for special
effects at the end of a code or definition part.

@A
\def\WQ{\rightskip=0pt
	\sfcode`;=1500 \pretolerance 200 \hyphenpenalty 50 \exhyphenpenalty 50 }

\def\Wendd{\par}% End of definition part.
\def\Wendc{\par}% End of code part.

@* MISCELLANEOUS OPERATORS.
Most of these are also hard-coded into \FWEAVE, and emitted automatically.
@A
\def\WA{\note{See also}}% Cross-reference for multiply defined section names.
	% English!

\def\Wauto[#1]{\Wtypewriter{[#1]}\ }

\DRC\WB{\mathopen{\Wtypewriter{@@/\ast}}}% Begin controlled comment.

\let\WG\ge % Greater than or equal sign: '$\WG$'.

\DRC\WI{\neq}% Unequal sign: '$\WI$'.  (Better reserve |\ne| for the
		% electron density~$n_e$.) 

\DRC\WJ{\Wtypewriter{@@\&}}% TANGLE's join operation: '\WJ'.

\let\WK\gets % Left arrow: '$\WK$'.

% The next one is used for statement labels in \Fortran\ and \Ratfor.
\let\Wlbl\llap

% The above puts the label on the same line as the things it's labeling. 
% Some other choices, courtesy of Bart Childs, are

% \def\Wlbl{\hskip-\notch} % jut into the left white space
% \def\Wlbl{} % Maintains indentation.

% To put the statement label on the previous line, use the `|-n:|' option.

\let\WL\le % Less than or equal sign: '$\WL$'.

\let\WLA\langle % Opening of template:  '$\WLA$'.
\let\WRA\rangle % Closing of template:  '$\WRA$'.

\DRC\WTLD{\.{@@\~}}

\def\Wskip{\vfil\penalty-100\vfilneg \vskip12ptminus3pt}% See |\WM|, etc.

\def\Wskipped#1{\8\mathhexbox278.\quad\Wtypewriter{@@I "#1"}\ \ {\it Section(s)
skipped}\dots\WP} 

\let\WPtr\Rightarrow % Fortran's stupid pointer assignment statement:
		% '$\WPtr$'. 

\let\WR=\lnot % Logical not: '$\WR$'.

\let\WS=\equiv % Equivalence sign: '$\WS$'.
\let\WSQ=\equiv % This symbol is used when defining a section name.

\DRC\WT{\mathclose{\Wtypewriter{@@\ast/}}}% Terminate controlled comment.

\def\WU{\note{This code is used in}}% Cross-reference for uses of sections.
	% English!

\let\WV\lor % Logical or: '$\WV$'.

\let\WW=\land % Logical and: '$\WW$'.

@*1 Formatting a section name.
Here's how to format a section name. Argument~1 is the name, argument~2
is the section number, and argument~3 is the language symbol.
@A
\ifLaTeXisloaded
\else
	\let\footnotesize\eightrm
\fi

\def\WX#1#2\X#3\X{\ifmmode\gdef\XX{\null$\null}\else\gdef\XX{}\fi
	\XX$\langle\,$#2{\footnotesize\kern.5em#1}%
$\,\rangle^{\mathrm{#3}}$\XX}

@
@A
\def\WY{\par
	\yskip
	\parskip=0pt} 

@
The following were for Pascal.
@<Unused@>=

\def\){\hbox{\Wtypewriter{@@\$}}}% sign for string pool check sum
\def\]{\hbox{\Wtypewriter{@@\\}}}% sign for forced line break

@*1 Questions and colons.
For C's construction `|@c x ? 1 : 0|'.
@A
\DRC\?{\mathrel?}

@ Colons have several uses.
@A
\DRC\Colon{\ifmmode\colon\else:\fi}

\DRC\WCC{\mathord{::}}% For C:  '$x\WCC y$'.
\DRC\WCF{{}\mathbin{::}{}}% For \Fortran:  '$x\WCF y$'.


@*1 Verbatim strings.
Verbatim strings are boxed for emphasis, like this:  \Wequals{This is a
verbatim string.}

@A
\DRC\=[1]{\kern2pt\hbox{\vrule\vtop{\vbox{\hrule
	\hbox{\strut\kern2pt\Wtypewriter{#1}\kern2pt}}
	\hrule}\vrule}\kern2pt}

\let\Wequals\=

@ 
@A
\let\~=\ignorespaces
\let\*=*

@*1 Accreting to modules.
The following symbol is used to denote accretions to already-existing
modules. 
@A
\def\WPQ{\mathrel{+\mathord\equiv}}% '$\WPQ$'.

@*1 Exponentiation.
The exponentiation macros strip away outer parentheses from the argument,
turning ``|x^(a+b)|'' into ``|@n x^(a+b)|''.
@A
\def\W@@LP{(}% Must be |\def|, not |\let|.
\def\W@@ISL#1#2]{\def\next{#1}}
\DRC\WEE[1]{\W@@ISL#1]\ifx\next\W@@LP\WEXP[#1]\else\WEXP[(#1)]\fi}
\def\WEXP[(#1)]{^{#1}}

@#if 0
\def\WEE{\mathord{\hbox{\tt\^}}}% Poor-man's exponentiation; above is better.
@#endif

@*1 \Fortran.
@A
\let\WSlSl\parallel% Concatenation: '$\WSlSl$'.

\DRC\WEQV{\mathrel{?{=}}}% `$x\WEQV y$'.
\DRC\NEQV{\not\equiv}% `$x\NEQV y$'.

@ For \Fortran--90's `|@n (/a,b,c/)|'.
@A
\DRC\WLS{\mathopen{({/}}}
\DRC\WSR{\mathclose{{/})}}

@ The standard \Fortran\ \.{.FALSE.} and \.{.TRUE.} operators.
@A
\DRC\FALSE{{\cal F}}% '$\FALSE$'.
\DRC\TRUE{{\cal T}}% '$\TRUE$'.

@ Block/loop numbers in \Fortran.  {\it Note:  One can't replace the
|\bgroup| and |\egroup| by braces because of peculiarities of~|\Wc|.  Also,
if one puts an explicit comment on a line that will be labelled by
|\Wblock|, with the following definition one will get two comments side by
side.  However, this could be modified by setting a counter to the block
number and making a fancier definition of~|\WC| and~|\Wc|.}
@A
\def\Wblock#1{\Wc\bgroup\ Block #1\egroup}% `\Wblock{99}'

@*1 Macro tokens.
@A
\def\WNN{\hbox{\#\#}}% '\WNN'.
\def\WNP{\hbox{\#!}}% '\WNP'.
\def\WNC{\hbox{\#:}}% '\WNC'.
\def\WND{\hbox{\#.}}% '\WND'.
\def\WNq{\hbox{\#\tt'}}% '\WNq'.
\def\WNQ{\hbox{\#\tt"}}% '\WNQ'.

@*1 C operators.
@A
\mathchardef\TLD="0218 % '$\TLD$'.

\DRC\WPP{\mathord{++}}% '$\WPP$'.
\DRC\WMM{\mathord{--}}% '$\WMM$'.

\DRC\WMG{\mathord{\to}}% '$\WMG$'.

\DRC\Wcp{\mathrel{+{=}}} \let\PE\Wcp % `$x\PE y$'.
\DRC\Wcm{\mathrel{-{=}}} \let\ME\Wcm % `$x\ME y$'.
\DRC\Wcs{\mathrel{\ast{=}}} \let\TE\Wcs % `$x\Wcs y$'.
\DRC\Wcv{\mathrel{/{=}}} \let\FE\Wcv % `$x\FE y$'.
\DRC\Wcd{\mathrel{\%{=}}} \let\CE\Wcd % `$x\Wcd y$'.
\DRC\Wcx{\mathrel{\^\!{=}}}% `$x\Wcx y$'.
\DRC\Wca{\mathrel{\amp{=}}}% `$x\Wca y$'.
\DRC\Wco{\mathrel{\WOR{=}}}% `$x\Wco y$'.
\DRC\Wcg{\mathrel{\WGG\!{=}}}% `$x\Wcg y$'.
\DRC\Wcl{\mathrel{\WLL\!{=}}}% `$x\Wcl y$'.

@ More C operators.
@A
\DRC\WMOD{\mathrel{\%}}% `$x\WMOD y$'.
\DRC\WOR{{\,|\,}}% `$x\WOR y$'.
\DRC\WAND{{\,\amp\,}}% `$x\WAND y$.

\DRC\WGG{\mathrel{>\!>}}% `$x\WGG y$'.
\DRC\WLL{\mathrel{<\!<}}% `$x\WLL y$'.

\DRC\WHE{\mathrel{\uparrow=}}% `$x\WHE y$'.

@*1 Braces.
We allow braces to be easily displayed outside of math mode.
@A
\let\openbraces=\{
\let\closebraces=\}
\def\{{\ifmmode\openbraces\else$\openbraces$\fi}
\def\}{\ifmmode\closebraces\else$\closebraces$\fi}

@*1 Metacomments.
@A
% Print the meta-comment symbols.
%\def\WBM{\6\8\Wreserved{@@(}}
%\def\WEM{\6\8\Wreserved{@@)}}

% Don't print the meta-comment symbols.
%\def\WBM{}
%\def\WEM{}

@* OVERLOADING OPERATORS.  Operator overloading is annoying because several
languages may be in use simultaneously.  Therefore, when we define an
overloaded  macro name, we append to it the language symbol, creating
macros such as |\op_C|.  These macros are typically defined automatically
at the beginning of the output file from information contained in
\.{@@v}~commands. 

@A
\newif\ifop
\newbox\dotbox

\def\Wunknown#1{\={??#1??}}% For unknown dot constant.

{\catcode`\_=11

\gdef\newop#1#2#3{%
	\edef\next{\def\expandafter\noexpand\csname _#1_#2\endcsname}%
	\next{#3}}

\gdef\newbinop#1#2#3{%
	\edef\next{\def\expandafter\noexpand\csname _#1_#2\endcsname}%
	\next{\mathrel{#3}}}

\gdef\newunop#1#2#3{%
	\edef\next{\def\expandafter\noexpand\csname _#1_#2\endcsname}%
	\next{\mathbin{#3}}}

\gdef\Wop#1#2{\setbox\dotbox\hbox{\tt .#1.}%
	\edef\nxt{\expandafter\noexpand\csname _#1_#2\endcsname}%
	\edef\ifnxt{\noexpand\ifx\expandafter\noexpand\csname _#1_#2\endcsname}%
	\ifnxt\empty
		\def\next{\box\dotbox}% Macro not defined; just use \.{.NAME.}.
	\else
		\def\next{\futurelet\nextchar\W@@q}% Be careful about |\WEE|.
	\fi
	\next}%
}

\global\let\Wb\Wop
\global\let\Wu\Wop

\let\Lbrace{

\def\W@@q{\ifx\nextchar\Lbrace
		\let\next\nxt % There's an argument coming up.
	\else
		\ifop
			\def\next{\nxt{}\equiv\box\dotbox}%
		\else
			\let\next\nxt
		\fi
	\fi
	\opfalse
	\next}

@ The following macro translates overloaded identifiers into their \TeX\
equivalents.
@A
\DRC\WTeX[1]{\ [{\ifmmode\def\XX{}\else\def\XX{\null$\null}\fi
\XX#1\XX}]\ }

@* ACTIVE ARRAY INDICES.
The following is for special handling of array indices, when the |-W[|
option is used.
@A
\newtoks\W@@ARRAYarga
\newtoks\W@@ARRAYargb

\DRC\WXA[1]{\begingroup
% We don't want the identifiers to be in hboxes, because we want to get
% |\scriptstyle| for subscripts.  (One should always be in math mode here.)
	\def\Wshort##1{##1}%
	\def\Wid##1{\mathit{##1\/\kern.05em}}%
	\global\W@@ARRAYarga{#1}%
	\futurelet\W@@next\WARRAYm}

\def\WARRAYm{\ifx\W@@next\WXA
		\global\let\W@@next\WARRAYn% Multiple indices in C:  a[i][j][k]
	\else
		\global\let\W@@next\relax
		\WARRAY{\the\W@@ARRAYarga}% Typeset the accumulated indices.
	\fi
	\endgroup
	\W@@next}

\def\WARRAYn#1#2{\W@@ARRAYargb{#2}%
	\edef\W@@next{\noexpand\WXA{\the\W@@ARRAYarga,\the\W@@ARRAYargb}}%Concatenate
	\W@@next}

% Change the following definition---e.g., |\let\WARRAY\WSUB|---to get
% indices printed in interesting ways. 
\DRC\WARRAY[1]{[#1]}% Default definition.
\DRC\WSUB[1]{_{\scriptstyle#1}}% E.g., subscript indices.

@* MISCELLANEOUS MACROS.
@*1 Handle the \.{@@o}~command.
@A
\def\Wouto#1#2{\Wreserved{@@#1}\W@@Hspace\Wtypewriter{#2}}
\def\Wout#1{\Wouto{o}{#1}}
\def\WOut#1{\Wouto{O}{#1}}

@*1 Symbolic labels.
Assign a symbolic name to a module.  This scheme has no forward
referencing at present for plain \TeX, although this could easily be
extended.  For \LaTeX, forward referencing works because the \.{aux}~file
is used.
@A
% Label a section with an identifying name.
\def\modlabel#1{%
	\ifLaTeXisloaded
		\label{MOD#1}%
	\else
		\edef\next{\gdef\expandafter\noexpand\csname MOD#1\endcsname{\modno}}%
		\next
	\fi}

% Print the number of a labelled section.
\def\Wmodule#1{\ifLaTeXisloaded
		\ref{MOD#1}%
	\else
		\csname MOD#1\endcsname
	\fi} 

% Examples of references to sections.  
\def\WEBsection#1{section~\Wmodule{#1}}% |\section| is used by \LaTeX.
\def\WEBmodule#1{module~\Wmodule{#1}}
\let\module\WEBmodule% For backward compatibility.

@*1 Language commands.
 Language commands are printed in the left margin, following Knuth's
solution in Appendix~A of the \TeX book.  They are actually printed one
line down, because the language command is gobbled up before the line break
is emitted.

@A
\def\strutdepth{\dp\strutbox}

\def\W@@marginal#1{\strut\vadjust{\kern-\strutdepth\W@@specialmargin{#1}}}

\def\W@@specialmargin#1{\vtop to\strutdepth{
	\baselineskip\strutdepth
	\vss\llap{#1 }\null}}

\def\LANGUAGE#1{\W@@marginal{\smash{\vtop{\hbox{%
	\hbox{\tt @@L\lowercase{#1}:\enspace}}\null}}}\ignorespaces}

% Use the next one if you don't want language changes to be printed.
@#if 0
	\def\LANGUAGE#1{\relax\ignorespaces}
@#endif


@* PAGE FORMAT.
Now we deal with the overall page format.

@*1 Listing the changed modules.
If you want to list only the modules that have changed,
together with the index, put the command `|\let\maybe=\iffalse|' in
the limbo section before the first module of the \.{WEB} file. It's
customary to make this the first change in the change file.

@A
\newif\ifon 
\def\onmaybe{\let\ifon=\maybe} \let\maybe=\iftrue

@ Some flags, and the number of the table of contents.
@A
\newif\iftitle \newif\ifpagesaved

\newcount\contentspageno

@*1 Headers.
Top line on left-hand pages:
@A
\def\Wmodhd#1{ [#1]}

\newif\ifW@@headers
\W@@headerstrue% Stand-alone setting (might be changed in fwebinsert.sty).

\def\WsetLmarks{
	\def\Wsecrange##1##2{%
		\def\W@@tempa{##1}\def\W@@tempb{##2}%
		\ifx\W@@tempa\W@@tempb
			\W@@S\Wmodtrans{##1}\Wmodhd{\###1}%
		\else
		    \W@@S\Wmodtrans{##1}--\W@@S\Wmodtrans{##2}%
\Wmodhd{\###1--\###2}%
		\fi}

	\gdef\@@leftmark##1##2##3##4{%
		\let\protect\relax
		\qquad\mainfont##2
		\hfill
		\Wtitle\qquad
		\ifnum##1>0%
		  \mainfont\Wsecrange{##1}{##3}% 
		\fi
		}

	\gdef\@@rightmark##1##2##3##4{%
		\let\protect\relax
		\ifnum##1>0
			\mainfont\Wsecrange{##1}{##3}%
		\fi
		\qquad\mainfont\Wtitle
		\hfill 
		\mainfont##2\qquad
		}

	\gdef\leftmark{%
\ifnoLaTeXe
\else
	\let\protect\@@unexpandable@@protect
\fi
\edef\W@@tempb{\expandafter\iftrue\botmark\fi}%
\edef\W@@tempa{\expandafter\iffalse\topmark\fi}%
\expandafter\expandafter\expandafter\@@leftmark\expandafter\W@@tempa\W@@tempb{}{}}

	\gdef\rightmark{%
\ifnoLaTeXe
\else
	\let\protect\@@unexpandable@@protect
\fi
\edef\W@@tempb{\expandafter\iftrue\botmark\fi}%
\edef\W@@tempa{\expandafter\iffalse\topmark\fi}%
\expandafter\expandafter\expandafter\@@rightmark\expandafter\W@@tempa\W@@tempb{}{}}

	\gdef\W@@markN{\gdef\W@@mark####1####2{{\def\WIN{\WIM}%
		\mark{####1\noexpand\else####2}}}}

	\ifx\selectfont\undefined
		\W@@markN
	\else
		\gdef\W@@mark##1##2{{%\def\WIN{\WIM}%
			\let\protect\@@unexpandable@@protect
			\mark{##1\noexpand\else##2}}}
	\fi
}

\ifLaTeXisloaded
\else
\def\lheader{\mainfont\the\pageno\eightrm\qquad\Whead\hfill\Wtitle\qquad
	\ifnum\pageno=\contentspageno\else
		\W@@S\mainfont\Wmodno
	\fi}

\def\rheader{\ifnum\pageno=\contentspageno\else
		\W@@S\mainfont\Wmodno
	\fi
	\eightrm\qquad\Wtitle\hfill\Whead
	\qquad\mainfont\the\pageno}
\fi

@*1 Page dimensions.
Here are the page dimensions (in inches).
@A
\def\pagewidtho{6.5}% The width of each page
\def\pageheighto{8.7}% The height of each page
\def\fullpageheighto{9}% Page height including headlines

\newdimen\pagewidth \pagewidth\pagewidtho in
\newdimen\pageheight \pageheight\pageheighto in
\newdimen\fullpageheight \fullpageheight\fullpageheighto in

\newdimen\pageshift \pageshift=0in% Shift righthand pages wrt lefthand ones

% Use after changing page size.
\def\setpage{\hsize\pagewidth 
	\vsize\pageheight
	\ifLaTeXisloaded
		\oddsidemargin=0pt
		\evensidemargin=0pt
		\topmargin=0pt
	\fi
	}
	
\ifLaTeXisloaded
\else
\def\magnify#1{\mag=#1
	\pagewidth\pagewidtho truein
	\pageheight\pageheighto truein
	\fullpageheight\fullpageheighto truein
	\setpage}

\fi

@*1 Plain \TeX\ output routine.
Here is the output routine for plain \TeX.  (For \LaTeX, we use its own
routine.) 
@A
\def\page{\box255 }

\newif\ifidenticalpageheads

\def\normaloutput#1#2#3{
	\ifodd\pageno\hoffset=\pageshift\fi
	\shipout\vbox
		{
		\vbox to\fullpageheight
			{
			\iftitle\global\titlefalse
			\else \hbox to\pagewidth
				{\vbox to10pt{}%
				\ifidenticalpageheads#2\else
				\ifodd\pageno
					#3% Pg nos alternate left \& right.
				\else#2\fi
				\fi
				}%	
			\fi
			\vfill#1% Parameter |#1| is the page itself.
			}
		}
	\global\advance\pageno by1}

\def\W@@name{{FWEB} OUTPUT}% This section name is reset by starred sections.

@ Here we provide a storage place for |\output|. If one includes a macro
package, such as \.{manmac}, that overrides the definition of |\output|
{\it after} \.{fwebmac.sty},  one can get back the \.{fwebmac.sty} definition by
saying 
		|\input manmac|
		|\output\Woutput|
@A
\newtoks\Woutput
\Woutput\output% Remember \FWEB's definition.


@*1 Time and date.
It's very useful to know exactly when one made the run.
@A
\newcount\minutes
\newcount\hours

\hours=\time
\divide\hours by 60
\multiply\hours by 60
\minutes=\time
\advance\minutes by -\hours
\divide\hours by 60

\def\Time{\the\hours:\ifnum\minutes<10 0\fi\the\minutes}

\def\Date{\ifcase\month\or
	January\or February\or March\or April\or May\or June\or
	July\or August\or September\or October\or November\or December\fi
	\space\number\day, \number\year}


@*1 Optional title for the code.
An optional title can be defined by the user in his limbo section.  The
syntax is `|\Title[short]{long}|', where the optional short argument is for
the running heads in the document and is by default prefaced with
|\large\tt|; the required long argument is for the 
title page and is by defualt prefaced with |\ttitlefont|.

@A
\def\Wtitle{}% Short title for running heads.  Can redefine after |\Title|.j

\def\Title{\@@ifnextchar[\W@@@@Title\W@@Title}
\def\W@@Title#1{\W@@@@Title[#1]{#1}}
\def\W@@@@Title[#1]#2{\gdef\Wtitle{{\large\tt#1}}\title{{\ttitlefont#2}}}


@* TABLE OF CONTENTS. An entry is made in the table of contents for each
starred section.  

@*1 |\topofcontents| and |\botofcontents|.
One can customize things with |\topofcontents| and
|botofcontents|.  For more information, see the on-line documentation, menu
item ``Table of contents''.

@A
\ifLaTeXisloaded
	\def\topofcontents{}% We use \LaTeX's defaults.
\else
	\def\topofcontents{\centerline{\titlefont\Wtitle}
	  \vfill} % This is the default.
\fi

@ End the table of contents page:
@A
@#if 0
\def\botofcontents{\vfill}% This makes the bottom of the contents page empty.
@#endif

\ifLaTeXisloaded
	\def\botofcontents{}
\else
\def\botofcontents{\vfill
@#if 0
	\rightline{My Name}% You can personalize your output here, for example.
@#endif
	\rightline{\Date}
	\rightline{\Time}}
\fi

\ifLaTeXisloaded
	\contentspageno=1
	\pageno=\contentspageno
\else
	\contentspageno=0% Default page number for table of contents
\fi

@*1 Opening the contents file; the |\Wbegin| macro.
\modlabel{Wbegin}
Here we actually open up the contents file, which is the argument to
|\Wbegin|.  The |\Wbegin| macro is issued automatically just before the
stuff for the first module.  Also, \LaTeX\ does its own thing with the
|\end| command, so we redefine it.  To finish up the document, we write to
the \.{aux} file ``|\W@@maxdepth{|$n$|}|'', where $n$~is the maximum
section depth that was achieved.

Whereas \LaTeX\ writes a |\newlabel| line to the table of contents in
response to a |\label| command, we write a |\Newlabel| command for every
section.  That macro is patterned after |\newlabel|, but has an extra
argument that is |\W@@botmodno|.  The |\Newlabel| information is read both by
the \FWEB\ processors (to correlate \LaTeX\ section numbers with integer
module numbers) and by |\FWEBend| to check whether labels have changed.
@A 
\newwrite\W@@cont % For the table of contents.

\ifLaTeXisloaded
	\def\Wfirst#1#2#3#4#5{#1}

	\def\W@@output{\setcounter{pagemodule}{0}%
		\xdef\W@@botmodno{\expandafter\Wfirst\botmark}}

	\def\W@@botmodno{0}

	\def\Newlabel#1#2#3{%
		\ifFWEBstandalone
			\@@ifundefined{r@@#1}{}%
				{\@@warning {Label `#1' multiply defined}}
		\fi
		\global\@@namedef{r@@#1}{#2{#3}}
		\global\W@@lpha=#3
		\ifnum\W@@lpha=\W@@ref\global\advance\W@@pmcount by1
		\else
			\ifnum\W@@pmcount=1
			\edef\next{\gdef\csname W@@\the\W@@ref\endcsname{}}\next
			\fi
			\W@@ref=\W@@lpha
			\W@@pmcount=1
		\fi}
\fi

@ The arguments to |\Wbegin| are various style-file parameters, as follows:
$$\vbox{\halign{{\tt \##}\hfil& --- \vtop{\hsize0.75\hsize \noindent
\strut\tt #\strut}\hfil\cr 
1&LaTeX.class.options;LaTeX.package.options\cr
2&LaTeX.class;LaTeX.package\cr
3&indent.TeX\cr
4&indent.code\cr
5&contents.TeX\cr
6&\{format.reserved format.RESERVED\} \{format.short\_id\} \{format.id
format.ID\} \{format.outer\_macro format.OUTER\_MACRO\} \{format.WEB\_macro
format.WEB\_MACRO\} \{format.intrinsic\} \{format.keyword format.KEYWORD\}
\{format.typewriter\}\cr
7&encap.prefix\cr
8&\{doc.preamble;doc.postamble\}\cr
9&index.name\cr
}}$$

@A
\newcount\W@@ref
\W@@ref=-1

\newcount\W@@lpha

\newcount\W@@pmcount
\W@@pmcount=1

\outer\def\Wbegin[#1]#2#3#4#5#6#7#8#9{\edef\contentsfile{#5}%
	\def\readcontents{\input\contentsfile}%
	\Wequate#6
	\W@@modequate{#7}%
	\edef\INDEX{#9}%
	\def\W@@splitprms##1##2[##3;##4]{\def##1{##3}\def##2{##4}}%
	\W@@splitprms\W@@preamble\W@@postamble[#8]%
	\ifLaTeXisloaded
		  \ifFWEBstandalone
		\def\FWEBend{% \LaTeX\ redefines |\end|.
			  \global\advance\W@@ssmax by1
	  \immediate\write\@@auxout{\string\W@@maxdepth{\the\W@@ssmax}}%
			  \W@@postamble
			  \W@@makeatend% Override |\makeatletter|
			  \end{document}%
			}%
			\def\W@@ssmin{0}
		\else
			\def\FWEBend{}
			% |\W@@ssmin| isn't defined; it's set by |fweblevel|.
		  \fi
		\W@@splitprms\W@@prma\W@@prmb[#1]%
		\W@@splitprms\W@@prmc\W@@prmd[#2]%
		\ifnoLaTeXe
		   \edef\W@@temp{\noexpand\documentstyle[\W@@prma]{\W@@prmc}}%
			\W@@temp
		\else
			\ifFWEBstandalone
				\documentclass[\W@@prma]{\W@@prmc}%
				\usepackage[\W@@prmb]{\W@@prmd}%
			\fi
		\fi
% Set up defaults.
		\ifFWEBstandalone
			\textwidth\pagewidth
			\textheight\pageheight
		\fi
		\TeXindent#3
		\title{}%
		\author{}%
		\date{\today\\[3pt]\Time}%
		\pagestyle{myheadings}%
% |\Wbegin| might be called more than once if one is using package
% \.{fwebinsert}. 
		\ifx\c@@pagemodule\undefined
			\newcounter{pagemodule}%
			\newcounter{W@@tempcounter}%
		\fi
		\gdef\cl@@section{\@@elt{subsection}\cl@@subsection}
		\gdef\cl@@subsection{\@@elt{subsubsection}\cl@@subsubsection}
		\gdef\cl@@subsubsection{\@@elt{subsubsubsection}}
		\xdef\normaloutput##1##2##3{\the\output \noexpand\W@@output}%
		\ifW@@headers
			\WsetLmarks
		\else
			\def\W@@markN{}%
			\def\W@@mark##1##2{}%
		\fi
		\W@@preamble
		\W@@raggedbottom
		\ifFWEBstandalone
			\begin{document}
		\else
			\begingroup
			\makeatletter
			\@@input{\jobname.aux}
				%|\jobname| is redefined in \.{fwebinsert.sty}.
			\endgroup
		\fi
		\W@@setsecdepth
	\else % Plain \TeX.
		\immediate\openout\W@@cont=\contentsfile
		\def\FWEBend{\W@@postamble\end}
		\TeXindent#3
		\W@@preamble
	\fi
	\W@@setboxes{#4}% Set dimensions of backspace boxes.
% Here we print out a garbage page, so that the first |\topmark| won't be null.
	\ifFWEBstandalone
		\output
			{\setbox0=\page% The first page is garbage
			\global\output{\normaloutput\page\lheader\rheader}%
			}%
		\setpage
		\vbox to \vsize{}
	\fi
	}

@ We need to insert an extra test for changed labels that depends on the
|\Newlabel| information in the \.{.aux} file.  Now the \.{.aux} file is
read by the \.{\\end\{document\}} command; the reading is immediately
preceded by ``|\makeatletter|''.  To insert the new test, we augment that
command to include the appropriate redefinition of |\Newlabel|.  We must
also provide a cousin |\W@@testdef| to |\@@testdef| that recognizes the
extended name definitions (including |\W@@botmodno|) that we use for the
\FWEB\ section. 
@A
\def\W@@makeatend{\let\W@@makeatletter\makeatletter
	\def\makeatletter{\def\Newlabel{\W@@testdef r}%
	\W@@makeatletter}}

\def\W@@testdef#1#2#3#4{\def\reserved@@a{#3{#4}}%
\expandafter\ifx\csname#1@@#2\endcsname
		\reserved@@a
	\else
		\@@tempswatrue
	\fi
}

@
@A
\def\Wch{\note{The following sections were changed by the change file:}
	\let\*=\relax}% English!

@* MACROS for the INDEX.
The index is written by default into \.{INDEX.tex}, but that
name can be overridden with the style-file parameter \.{index.tex}.

@*1 Beginning the index.
Here we begin the index.  In \LaTeX, if \.{multicol.sty} is not loaded, by
this time we should be in |\twocolumn| mode (from the |\beforeindex|
command).  If it is loaded, we begin multi-columns.  It's ended with the
|\Wfin| command.
@A
% The following two lines are for \TeX\ only.
\newbox\Sbox % Saved box preceding the index
\newbox\Lbox % Lefthand column in the index

\ifLaTeXisloaded
	\def\startindex{\ifx\multicols\undefined
				\medskip
			\else
				\begin{multicols}{2}%
			\fi
			}
\else
	\def\startindex{\par\vskip6pt plus 1fil}
\fi

@ The name of the |\Winx| macro is really the style-file parameter
 \.{index.preamble}. 
@A
\def\Winx{\startindex
\ifLaTeXisloaded
\else
	\write\W@@cont{ }% Ensure that the contents file isn't empty
	\closeout\W@@cont % The contents information has been fully gathered
	\output{\ifpagesaved\normaloutput{\box\Sbox}\lheader\rheader\fi
		\global\setbox\Sbox=\page \global\pagesavedtrue}
	\pagesavedfalse \eject % Eject the page-so-far and predecessors
	\setbox\Sbox\vbox{\unvbox\Sbox}% Take it out of its box
	\vsize=\pageheight \advance\vsize by -\ht\Sbox % The remaining height
	\hsize=.5\pagewidth \advance\hsize by -10pt
		% Column width for the index (20pt between cols)
	\parfillskip 0pt plus .6\hsize % Try to avoid almost empty lines
	\def\lr{L}% This tells whether the left or right column is next
	\output{\if L\lr\global\setbox\Lbox=\page \gdef\lr{R}
		\else\normaloutput{\vbox to\pageheight{\box\Sbox\vss
		\hbox to\pagewidth{\box\Lbox\hfil\page}}}\lheader\rheader
		\global\vsize\pageheight\gdef\lr{L}\global\pagesavedfalse\fi}
%	\message{Index:}
\fi
	\outer\def\:##1, {\par\hangindent2em\noindent##1:\kern1em}% Index entry
	\def\[##1]{$\underline{##1}$}% Underlined index item
	\def\(##1){$^{\rm ##1}$}% Language marker
	\let\Windexspace\medskip % Spacing between letter groups in index.
	\rm 
	{\ifFWEBstandalone\let\glbl\global\else\let\glbl\empty\fi
	\glbl\parskip 0pt plus .5pt
	\glbl\rightskip0pt plus 2.5em 
	\glbl\tolerance 10000
	\glbl\let\*=\W@@lapstar
	\glbl\hyphenpenalty 10000 
	\glbl\parindent0pt
	}
	}

@*1 Ending the index.  
The name of the |\Wfin| macro is the style-file parameter \.{index.postamble}.
@A
\ifLaTeXisloaded
	\def\Wfin{\ifx\multicols\undefined\else\end{multicols}\fi}
\else
	\let\Wfin\relax
\fi

@*1 Using |makeindex|.  
The |\pg| macro (more generally, the name given by the style-file entry
\.{makeindex.page}) is used in the |.idx| file written in response to the
`|-XI|' option.  The first argument is either empty or an integer file id
filled in by \.{idxmerge}; the second is a possible macro that should act
on the third argument, which is the page number itself.  This example uses
the macro the macro |\pgfmt| to turn the integer id into an uppercase Roman
numeral.  For more information about the use of |\pg|, see the info
documentation, menu item \.{Using makeindex}.

@A
\def\pgfmt#1{\uppercase\expandafter{\romannumeral#1}}

\def\pg#1#2#3{\def\temp{#1}%
\ifx\temp\empty% For the case where \.{idxmerge} hasn't been run.
\else
	\pgfmt{#1}.%
\fi
#2{#3}%
}

@ The macros |\topofindex| and |\botofindex| are used in the preamble and
postamble of the \.{.ind} file constructed by \.{makeindex}.  A sample
that reads in the list of names written out by \.{idxmerge} can be found in
\.{/fweb/manual/idx.tex}.

@A
\def\topofindex{}
\def\botofindex{}


@* MACROS for the MODULE LIST.

@*1 Beginning the module list. This is the style file entry
\.{modules.preamble}. 
[Presently the |\mark| doesn't work right (at least in \LaTeX) for the first
page of the module list.  This is because |\onecolumn| and the mark are
somehow issued out of order. (But just putting the |\mark| before
|\onecolumn| doesn't work either.)]
@A
\def\Wmods{
\ifLaTeXisloaded
	\W@@outlsmax{1}%
	\onecolumn
	\parfillskip 0pt plus 1fil
	\def\W@@name{Names of the Sections}
	\W@@mark{{0}{\W@@name}}{{0}{\W@@name}}
\else
	\par\vfill\eject 
	\ifpagesaved\null\vfill\eject\fi % Output a null index column
	\if L\lr\else\null\vfill\eject\fi % Finish the current page
	\parfillskip 0pt plus 1fil
	\def\rhead{Names of the Sections}
	\output{\normaloutput\page\lheader\rheader}
	\setpage
\fi
	\def\note##1##2.{\quad{\footnotesize##1 ##2.}}
	\def\WU{\note{Used in}}% Cross-reference for uses of sections. English!
	\def\:{\par\hangindent 2em}\let\*=*}


@* TERMINATION.

@*1 Miscellaneous run info.
@A
\def\Winfo#1#2#3#4{\bigskip
	\:{{\bf COMMAND LINE:}\ \ \Wtypewriter{#1}.}\smallskip
	\:{{\bf WEB FILE:}\ \ \Wtypewriter{#2}.}\smallskip
	\:{{\bf CHANGE FILE:}\ \ \Wtypewriter{#3}.}\smallskip
	\:{{\bf GLOBAL LANGUAGE:}\ \ \Wtypewriter{\rm #4}.}\bigskip}

\def\Wkwd#1#2{\:{\leavevmode{\bf \dollar#1:}\ \ \Wtypewriter{"#2"}}}

@*1 Finish the section names,  do the table of contents, and terminate.
@A
\ifLaTeXisloaded
	\def\W@@settoc#1{}%

	\def\Wtoc#1{\begingroup
		\W@@settoc{#1}%
		\def\Newlabel##1##2##3{}%
		\setcounter{tocdepth}{\W@@depth}%
		\thispagestyle{empty}%
		\def\W@@name{Table of Contents}% English!
		\W@@mark{{0}{\W@@name}}{{0}{\W@@name}}%
		\pagenumbering{roman}%
		\maketitle
		\topofcontents
		\tableofcontents
		\botofcontents
		\W@@mark{{1}{}}{{1}{}}% Still testing!
		\newpage
		\endgroup
		\pagenumbering{arabic}%
		\pageno=1
		\gdef\W@@name{}%
		\W@@mark{{1}{\W@@name}}{{1}{\W@@name}}%
		}

	\def\Wcon#1{\newpage
		\let\WIM\WIN % Restore the proper definition.
		\pageno=\contentspageno 
		\Wtoc{#1}%
		\FWEBend
		}

% Put the following command into \.{limbo.end} to have the Table of
% Contents appear at the beginning.  (This is the default.)
	\def\FWEBtoc{\ifFWEBstandalone\Wtoc{}\fi
			\gdef\Wcon##1{\FWEBend}}
\else
\def\Wcon#1{\par\vfill\eject
	\rightskip 0pt \hyphenpenalty 50 \tolerance 200
	\setpage
	\output{\normaloutput\page\lheader\rheader}
	\titletrue % Prepare to output the table of contents
	\pageno=\contentspageno 
	\def\rhead{Table of Contents}% English!
	\topofcontents
	\catcode`\@@=11
	\hbox to\hsize{\hfil Section\hbox to3em{\hss Page}}
	\def\WZ##1##2##3##4{\hbox to\hsize{\kern##1em\ignorespaces##2
		\leaders\hbox to .5em{.\hfil}\hfil\ ##3\hbox to3em{\hss##4}}}
	\let\WIM\WIN % Restore the proper definition.
	\readcontents\relax % Read the contents info.
	\botofcontents 
	\FWEBend}

\def\FWEBtoc{\message{! Front Table of Contents is only supported with LaTeX.}}
\fi


@ The |\begintt| and |\endtt| verbatim constructions, borrowed from \TeX.
@A
\newskip\ttglue

\ttglue=0.5em plus 0.25em minus 0.15em

\def\ttother{\catcode`\\=\other \catcode`\{=\other \catcode`\}=\other
	\catcode`\$=\other \catcode`\&=\other \catcode`\#=\other
	\catcode`\%=\other \catcode`\~=\other \catcode`\_=\other
	\catcode`\^=\other}

\def\ttverbatim{\begingroup \ttother \obeyspaces \obeylines \tt}

{\obeyspaces\gdef {\ }}

\def\begintt{$$\let\par=\endgraf
	\ttverbatim
	\parskip=0pt
	\rightskip=-\parindent
	\ttfinish}

\def\Begintt{\bgroup
	\let\par=\endgraf
	\ttverbatim
	\parskip=0pt
	\rightskip=-\parindent
	\ttFinish}

{\catcode`\|=0
	|catcode`|\=\other
	|obeylines%
	|gdef|ttfinish#1^^M#2\endtt{#1|vbox{#2}|endgroup$$}%
	|gdef|ttFinish#1\Endtt{#1|endgroup|egroup}}

\let\verticalbar|

\def\activebar{\catcode`\|=\active}

{\activebar
\gdef\normalbar{\activebar
	\let|\verticalbar}}

%\activebar

{\obeylines%
\gdef\ttbar{\activebar%
	{\obeylines\gdef|{\ttverbatim%
		\spaceskip=\ttglue%
		\let^^M=\ \let|=\endgroup}}}}

\let\WCX\Begintt

@
@A
\catcode`\@@=12

@* \INDEX.