File: style.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 (1701 lines) | stat: -rw-r--r-- 35,689 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
@z --- style.web ---

FWEB version 1.60-beta (January 1, 1997)

Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]

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


\Title{STYLE.WEB} % Reading the style file for FWEAVE and FTANGLE.

@c
@* INTRODUCTION.
Here we read a style file. Style files are used to customize the output of
\FWEAVE---for example, to adjust the appearance of the index.  The default
style file is called \.{fweb.sty} in the directory set by the environment
variable \.{FWEB\_STYLE\_DIR}, or in the directory of the \WEB\ source.
The name can be changed with the \.{-z}~option: ``\.{-znew\_name}''.

Unlike the rest of the \FWEB\ processors, the style file does not
automatically convert its input into |ASCII|.  That's because most of its
fields are never manipulated internally, but are just written to the output
file.  This may or may not have been a good design decision.

Associations between vocabulary words and internal \FWEB\ fields are made
in \.{map.web}.

\It{We should discuss the detailed scheme here.}

@m _STYLE_
@d _STYLE_h

@A 
@<Include files@>@;
@<Typedef declarations@>@;
@<Global variables@>@;

@I typedefs.hweb

@
@<Include...@>=
#include "map.h"

@ 

@d CMNT_CHAR '%' // The comment character in the style file.

@I mem.hweb

@ We need a few miscellaneous declarations.
@<Glob...@>=

outer_char HUGE *sprm_buf,HUGE *sprm_ptr,HUGE *sprm_end; // For \.{-p} option.
outer_char HUGE *sprm_ptr0; // Marks beginning of command-line \.{-p} options.

boolean from_sprm;
static BUF_SIZE sbuf_len; // Length of line buffer.
static outer_char HUGE *stemp, HUGE *stemp_end,HUGE *tloc; /* Temporary
	hold for the argument, and position in it. */ 
static outer_char cur_char; /* Current character after possible escape
				translation. */
extern ASCII xord[];
extern outer_char xchr[];

@* PROCESSING ARGUMENTS. We begin with a routine that converts the
character representation of an escaped character to the proper byte.  Note
that the escapes \.{'\\\\'}, \.{'\\''}, \.{'\\"'}, and~\.{'\\?'} can be
handled as part of the |default|.  This routine also handles octal and hex
escapes of the form~\.{\\123} or~\.{\\xFF}.  The function takes the address
of a pointer to the first character; when it exits, that pointer has been
updated to the next non-translated character.  We provide separate
functions for escaping |outer_char|s and |ASCII|s.

@d isodigit(c) (isdigit(c) && (c)!='8' && (c)!='9')
	// An |outer_char| octal digit?

@a
outer_char @\
esc_char FCN((ppc))
	CONST outer_char HUGE * HUGE *ppc C1("")@;
{
int k;
unsigned n;
CONST outer_char HUGE *pc = *ppc; // Pointer to first character after~'\.\\'.

if(isodigit(*pc))
	@<Process octal constant@>@;
else if(*pc == 'x' && isxdigit(*(pc+1)))
	@<Process hex constant@>@;
else 
	{ /* Handle ordinary escaped character. */
	switch(*pc)
		{
   	   case 'a': n = '\007'; @+ break;
	   case 'b': n = '\b'; @+ break;
	   case 'f': n = '\f'; @+ break;
	   case 'n': n = '\n'; @+ break;
	   case 'r': n = '\r'; @+ break;
	   case 't': n = '\t'; @+ break;
	   case 'v': n = '\v'; @+ break;
	   default: 
		n = (unsigned)(*pc); // Unknowns, like '\.{\\m}' $\to$~'\.m'.
		break;
		}
	pc++;
	}

*ppc = pc;
return (outer_char)n;
}

@ Octal constants have the form \.{\\123}.
@<Process octal constant@>=
{
n = ctoi(*pc++);
for(k=0; k<2; k++)
	{
	if(!isodigit(*pc)) break;
	n = 8*n + ctoi(*pc++);
	}
}

@ Hex constants have the form \.{\\xFF}.
@<Process hex constant@>=
{
pc++; // Position after \.{'x'}.
n = ctoi(*pc++);
if(isxdigit(*pc)) n = 16*n + ctoi(*pc++);
}

@ The corresponding function for |ASCII|.

@a
ASCII @\
esc_achar FCN((ppc))
	CONST ASCII HUGE * HUGE *ppc C1("")@;
{
int k;
unsigned n;
CONST ASCII HUGE *pc = *ppc; // Pointer to first character after~'\.\\'.

if(isOdigit(*pc))
	@<Process Octal constant@>@;
else if(*pc == @'x' && isXdigit(*(pc+1)))
	@<Process Hex constant@>@;
else 
	{
	switch(*pc)
		{
   	   case @'a': n = @'\007'; @+ break;
	   case @'b': n = @'\b'; @+ break;
	   case @'f': n = @'\f'; @+ break;
	   case @'n': n = @'\n'; @+ break;
	   case @'r': n = @'\r'; @+ break;
	   case @'t': n = @'\t'; @+ break;
	   case @'v': n = @'\v'; @+ break;
	   default: n = *pc; @+ break; // Unknowns, like '\.{\\m}' $\to$~'\.m'.
		}

#if(DEBUG_XCHR)
	n = XCHR(n);
#endif
	pc++;
	}

*ppc = pc; // Advance the pointer to point beyond the end of the constant.

#if(DEBUG_XCHR)
	n = xord[n];
#endif

return (ASCII)n; // Return the value.
}

@ Octal constants have the form \.{\\123}.  The following is for |ASCII|.
@<Process Octal constant@>=
{
n = Ctoi(*pc++);
for(k=0; k<2; k++)
	{
	if(!isOdigit(*pc)) break;
	n = 8*n + Ctoi(*pc++);
	}
}

@ Hex constants have the form \.{\\xFF}.  The following is for |ASCII|.
@<Process Hex constant@>=
{
pc++; // Position after \.{'x'}.
n = Ctoi(*pc++);
if(isXdigit(*pc)) n = 16*n + Ctoi(*pc++);
}

@ Translate a hex |outer_char| into integer.

@m XC(cin,cout) case cin: return 0x##cout@;

@d Ctoi(c) ctoi(XCHR(c)) // For |ASCII|.

@a
int @\
ctoi FCN((c))
	outer_char c C1("")@;
{
switch(c)
	{
   XC('0',0); XC('1',1); XC('2',2); XC('3',3); XC('4',4); XC('5',5);
   XC('6',6); XC('7',7); XC('8',8); XC('9',9); 
   XC('a',a); @+ XC('A',A);
   XC('b',b); @+ XC('B',B);
   XC('c',c); @+ XC('C',C);
   XC('d',d); @+ XC('D',D);
   XC('e',e); @+ XC('E',E);
   XC('f',f); @+ XC('F',F);
   default: return 0;
	}
}

@ Search for a keyword.  Returns address of the relevant |S_MAP| entry.
@a
S_MAP @\
HUGE *find_sty FCN((m,keyword))
	S_MAP HUGE *m C0("Array of map variables")@;
	CONST outer_char HUGE *keyword C1("Search for this keyword")@;
{
for(; *(m->keyword); m++)
	if(STRCMP(keyword,m->keyword) == 0) return m;

return NULL;
}

@ Read one line from style file. 
@a
boolean @\
sty_line(VOID)
{
typedef enum {FROM_INI, FROM_LOCAL, FROM_CMD_LINE} STYLE_MODE;

static STYLE_MODE mode = FROM_INI;

from_sprm = BOOLEAN(mode == FROM_INI || mode == FROM_CMD_LINE);

switch(mode)
	{
   case FROM_INI:
	if(!sty0_line(sprm_ptr0))
		mode++;
	else
		return YES;

   case FROM_LOCAL:
	if(!sty0_line(NULL))
		mode++;
	else
		return YES;

   case FROM_CMD_LINE:
	return sty0_line(sprm_end);
	}

return YES; // Dummy.
}

boolean @\
sty0_line FCN((last_sprm))
	outer_char HUGE *last_sprm C1("")@;
{
int c; /* Single character read from style file. |int| rather than |char|
		because that's what |getc| returns. */

sloc = slimit = sbuf; // Position to beginning of line.

if(last_sprm)
	{ /* Read from the \.{-p} buffer. */
	if(sprm_ptr >= last_sprm) 
		{ /* Nothing more in the \.{-p} buffer. */
		s_line = 0;
		return NO;
		}
	else
		{ /* Copy line from \.{-p} buffer. */
		int n;
		outer_char HUGE *p;

		if((p=(outer_char HUGE *)STRCHR(sprm_ptr,'\n')) == NULL)
			{
			err_print(S,"Trouble in sty_line");
			return NO;
			}
		else n = PTR_DIFF(int, p, sprm_ptr);
	
		STRNCPY(sloc,sprm_ptr,n);
		sprm_ptr += n + 1;
		slimit += n;
		s_line++;
		}
	}
else
	{ /* Read from the local style file. */
	if(!sty_file) 
		@<Attempt to open style file@>@;

	@<Move characters from style file; |return NO| if end-of-file@>@;
	}

return YES;
}

@
@<Attempt to open...@>=
{
outer_char full_sty_name[MAX_FILE_NAME_LENGTH];

/* If there's no style file, do nothing. */
if(!*sty_file_name) 
	return NO;

if(warn_if_absent) 
	{
	STRCPY(full_sty_name, sty_file_name);
	add_prefix(full_sty_name);
	}
else 
	mk_fname(full_sty_name, MAX_FILE_NAME_LENGTH,
				OC(ENV_FWEB_STY), NO,sty_file_name);

if((sty_file = fopen((char *)full_sty_name,"r")) == NULL)
	{
	if(warn_if_absent) 
		{
		err_print(C,"Can't open style file %s",
			full_sty_name);
		}
	return NO;
	}

reading(full_sty_name,YES);
}

@
@<Move characters from style...@>=
{
if(feof(sty_file)) 
	return NO;

s_line++;

while((c = getc(sty_file)) != EOF && c != '\n')
	{
	if(slimit == sbuf_end)
		{
		err_print(S,"Input line too long; max is %lu characters",
			sbuf_len);
		ungetc(c,sty_file);
		break;
		}

	*slimit++ = (outer_char)c; // Put character into buffer.
	}
}

@ Extract the next argument from the style file.  Keywords begin with an
alphabetic character or an underscore.
@a
STY_TYPE @\
next_sty(VOID)
{
outer_char c; /* Single character from the buffer. */

WHILE()
	{
/* If we get to the end of the line or recognize a comment, read the next
line. */
	if(sloc == slimit || (c= *sloc++) == CMNT_CHAR) 
		{
		if(!sty_line()) 
			return S_DONE; // Get more.

		continue;
		}

	if(isalpha(c) || c=='_') 
		@<Style keyword@>@;
	else if(isdigit(c) || c=='-' || c=='+') 
		@<Style number@>@;
	else if(c == '"') 
		@<Style string@>@;
	else if(c == '\'') 
		@<Style character@>@;
	else if(c==' ' || c=='\t' || c=='=') 
		continue;
	else 
		{
		err_print(S,"Invalid style-file field; \
skipping remainder of file");
		longjmp(top_of_style,1);
		}
	}

DUMMY_RETURN(S_DONE);
}

@ Read a keyword into the buffer |stemp|.  Keywords consists of
alphanumeric characters, underscores, or periods.  However, the periods are
made equivalent to underscore so one can things such as ``\.{color.red}''
instead of ``\.{color\_red}''.

@m S_RETURN(t) *tloc = '\0'; return S_##t@; /* Terminate |stemp|, and
					return the appropriate type. */

@<Style keyword@>=
{
sloc--;
tloc = stemp;

while(sloc < slimit 
	   && (isalpha(*sloc) || isdigit(*sloc) || *sloc=='_' || *sloc=='.'))
	{
	cur_char = *sloc++;
	@<Copy and translate style character@>@; 
	}

S_RETURN(KEYWORD);
}

@ Move one character into |stemp|.
@<Copy and translate style char...@>=
{
if(tloc < stemp_end) 
	*tloc++ = (outer_char)CHOICE(cur_char=='.', '_', cur_char);
else
	{
	err_print(S, "Style-file buffer overflow.  \
Try using `-ysb' to increase the size");
	break;
	}
}

@
@<Copy style character@>=
{
if(tloc < stemp_end) 
	*tloc++ = cur_char;
else
	{
	err_print(S, "Style-file buffer overflow.  \
Try using `-ysb' to increase the size");
	break;
	}
}

@ Process a string argument (bracketed by double quotes).  We must allow
for escapes, such as ``\.{\\123}''.
@<Style string@>=
{
tloc = stemp; /* Start of buffer. */

while(*sloc != '"')
	{
	if(sloc == slimit)
		{
		err_print(S, "Missing double quote inserted at end of string.  \
Did you mean to continue the line with '\\'?  \
(No white space is allowed after the '\\'.)");
		S_RETURN(STRING);
		}

	if(*sloc == '\\')
		if(++sloc == slimit)
			{
			sty_line(); // String is continued.
			continue;
			}
		else 
			cur_char = esc_char(&sloc);
	else 
		cur_char = *sloc++;

	@<Copy sty...@>@;
	}

sloc++; // Skip over terminating quote.

S_RETURN(STRING);
}

@ Process a numerical argument.
@<Style number@>=
{
sloc--;
tloc = stemp;

if(*sloc=='+' || *sloc=='-') 
	{
	cur_char = *sloc++; 
	@<Copy sty...@>@;
	}

while(sloc < slimit && isdigit(*sloc)) 
	{
	cur_char = *sloc++; 
	@<Copy sty...@>@;
	}

if(sloc == slimit)
	S_RETURN(INT);

/* We allow the possibility of long integers. */
if(*sloc == 'l' || *sloc == 'L')
	{
	sloc++; // Skip over '\.L'.
	S_RETURN(LONG);
	}

S_RETURN(INT);
}

@ Process a character argument such as~'\.c' or~'\.{\\n}'.
@<Style character@>=
{
tloc = stemp;

/* If the character is escaped, turn the next character into the actual
byte. */
if(*sloc == '\\') 
	{
	sloc++; 
	cur_char = esc_char(&sloc);
	}
else 
	cur_char = *sloc++;

@<Copy sty...@>@;

if(*sloc != '\'')
	err_print(S, "Missing single quote inserted");
else
	sloc++; // Skip over closing quote.

S_RETURN(CHAR);
}

@* READING the STYLE FILE.
The style file is both opened and closed in this module.

@f jmp_buf int

@<Glob...@>=

static CONST outer_char *sty_file_name;
static boolean warn_if_absent;
static FILE *sty_file;
static S_MAP HUGE *map_array = fweb_map; /* Points to the common map
	array for both \FWEAVE\ and \FTANGLE. */
jmp_buf top_of_style; // Environment for the |setjmp|--|longjmp|.

@ It's read line by line into a buffer. The length of that buffer can be
set by dynamic memory allocation with option~\.{-ysb}.

@d ENV_FWEB_STY "FWEB_STYLE_DIR" /* Environment variable that defines
		directory of style file.  */

@a
SRTN @\
read_sty FCN((sty_file_name0,warn_if_absent0))
	CONST outer_char sty_file_name0[] C0("")@;
	boolean warn_if_absent0 C1("")@;
{
sty_file_name = sty_file_name0;
warn_if_absent = warn_if_absent0;

@<Modify defaults based on option settings@>@;

@<Allocate buffers for the style file@>@;

if(setjmp(top_of_style) != 0) goto done_sty;

/* Read the first line of style file. If the file's empty, do nothing. */
if(!sty_line()) goto done_sty;

/* Parse the file. */
WHILE()
	switch(next_sty())
		{
		case S_CMNT: break;

		case S_KEYWORD:
			@<Process style keyword@>@;
			break;

		default:
			err_print(S,"Was expecting keyword or comment here; \
skipping remainder of file"); // Falls through to |case S_DONE@:|.

		case S_DONE:
		 done_sty:
			if(sty_file) fclose(sty_file);
			if(sprm_buf) FREE(sprm_buf);
			FREE_MEM(stemp,"stemp",sbuf_len,outer_char);
			FREE_MEM(sbuf,ABBREV(sbuf_len),sbuf_len,outer_char);
			return;
		}
}

@ In a few cases, the proper defaults depend on command-line options; for
example, which processor will be used to process \FWEAVE's output.
@<Modify defaults...@>=
{
IN_COMMON outer_char HUGE *style_args;

if(TeX_processor == LaTeX_p)
	{
	W_META HUGE *m = &w_style.misc.meta;
	INDEX HUGE *i = &w_style.indx;

	pfrmt->id = pfrmt->id_outer = pfrmt->id_inner = OC("\\>");
	pfrmt->ID = pfrmt->ID_OUTER = pfrmt->ID_INNER = OC("\\WUC");
	pfrmt->RESERVED = OC("\\WRS");

	m->TeX.begin = OC("\\begin{verbatim}");
	m->TeX.end = OC("\\end{verbatim}");	
	m->code.begin = OC("\\WBM ");
	m->code.end = OC("\\WEM ");

	i->encap_prefix = OC("\\M");
	i->encap_infix = OC("{");
	i->encap_suffix = OC("}");
	}

if(prn_style_defaults) 
	see_style(style_args, YES);
}

@ We temporarily allocate buffers for working with the style file.
@<Allocate buffers...@>=
{
ALLOC(outer_char,sbuf,ABBREV(sbuf_len),sbuf_len,0);
sbuf_end = sbuf + sbuf_len;

stemp = GET_MEM("stemp",sbuf_len,outer_char);
stemp_end = stemp + sbuf_len;

/* Reset the \.{-p} buffer. */
sprm_end = sprm_ptr; // Actual end of material in buffer.
sprm_ptr = sprm_buf; // Start at beginning.
}

@ At the very beginning, initializations must be finished.
@a
SRTN ini_style(VOID)
{
ini_colors(NO_COLOR);

@<Finish initializing mappings@>@;
}

@ We've recognized a keyword. Now deal with its arguments.  First, the
argument is copied into the appropriate field.  Then, if an initialization
routine has been defined, that routine is run on the argument.  The
argument might be checked for validity, or it might be changed into
something else.
@<Process style key...@>=
{
S_MAP HUGE *ps; // Returned from |find_sty|.
STY_TYPE type;

/* Is it a valid keyword? */
if((ps = find_sty(map_array,stemp)) == NULL)
	{
	err_print(S,"Invalid style-file keyword; skipping remainder of line");
	sty_line();
	break;
	}

/* Get the next argument. Is its type correct? */
type = ps->type & ~S_MODIFIED;

if(type != next_sty())
	{
	err_print(S,"Argument of keyword \"%s\" has wrong type; \
conversion attempted",ps->keyword);
	}

switch(type)
	{
	case S_INT:
	case S_LONG:
	case S_STRING:
	case S_CHAR:
	break;

	default:
		err_print(S,"Was expecting integer, double-quoted string, \
or single-quoted character here; argument not processed");
		goto processed;
	}

/* Store the argument, check for validity, or process the result in some
way. */
if(ps->init) 
	(*ps->init)(ps); 
else 
	CONFUSION("style keyword","NULL ini fcn");

/* Flag it as modified. */
ps->type |= S_MODIFIED;

processed:;
}

	
@ Initialize a string.  (No error checking.)
@a
SRTN @\
set_str FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
a_str(ps->ptr, (CONST outer_char HUGE *)stemp);
}

@ Here we add a string to an already-existing (non-NULL) one, placing a
newline in between.  If the original string is null, we just initialize it
as usual.

@a
SRTN @\
add_str FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
outer_char HUGE *pa = *(outer_char HUGE **)ps->ptr, HUGE *pb;

if(*pa && (ps->type & S_MODIFIED))
	{
	pb = GET_MEM("add_str", STRLEN(pa) + STRLEN(stemp) + 2, outer_char);
	STRCPY(pb, pa);
	STRCAT(pb, "\n");
	STRCAT(pb, stemp);
	*(outer_char HUGE **)ps->ptr = pb;
	}
else 
	set_str(ps);
}

@ Initialize an integer.  (No error checking.)
@a
SRTN @\
set_int FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
*((int *)ps->ptr) = ATOI(stemp);
}

@ Similarly, initialize a long.  (No error checking.)
@a
SRTN @\
set_long FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
*((long *)ps->ptr) = ATOL(stemp);
}

@ Initialize a character (no error checking).
@a
SRTN @\
set_char FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
*((outer_char *)ps->ptr) = *stemp;
}

@
@<Typedef...@>=

typedef struct
	{
	CONST char *name;
	COLOR value;
	} CLR_MATCH;

CLR_MATCH clr_match[] = {
	{"blue",BLUE},
	{"default",NORMAL},
	{"green",GREEN},
	{"normal",NORMAL},
	{"orange",ORANGE},
	{"red",RED},
	{"yellow",YELLOW},
	{"",NORMAL}
	};

@* VALIDITY CHECKS. 
We begin with an initialization routine for color.  It replaces strings like
\.{"red"} by enumerated values like~|RED|.
@a
SRTN @\
ini_aclr FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
CLR_MATCH HUGE *c;

set_str(ps);

for(c=clr_match; STRCMP(c->name,"") != 0; c++)
	if(STRCMP(c->name,*(outer_char HUGE **)ps->ptr) == 0)
		{
		*(COLOR *)ps->ptr = c->value;
		return;
		}

CLR_PRINTF(warning,("! Color name \"%s\" is invalid; \
replaced by \"default\"\n",(char *)ps->ptr));
mark_harmless;

*(COLOR *)ps->ptr = NORMAL;
}

@ Initialization routine for \.{color.mode}.
@a
SRTN @\
ini_clr FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
set_int(ps);
ini_colors((COLOR_MODE)(*(int *)ps->ptr));
}

@ Initialization routines for file name extension are create via a \WEB\
macro. 

@m EXT_LINK(file,dflt) link0(&wt_style.input_ext.file,OC(dflt),ext_set)

@m INI_EXT(file) 
	SRTN ini_##file FCN((ps))
		CONST S_MAP HUGE *ps C1("")@;
	{
	EXT_LINK(file,(outer_char *)ps->ptr);
	}

@<Unused@>=
/* Actual functions are being created here. */
INI_EXT(web)@;
INI_EXT(change)@;
INI_EXT(hweb)@;
INI_EXT(hchange)@;

@
@a
SRTN @\
ini_ext FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
set_str(ps);
ext_set((CONST outer_char HUGE **)ps->ptr);
}

@ Convert the delimiters for dot constants to |ASCII|.
@a
SRTN @\
ini_dot FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
set_char(ps);
*(ASCII *)ps->ptr = XORD(*(outer_char *)ps->ptr);
}

@
@a
SRTN @\
ini_cchar FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
outer_char c;

set_char(ps);
c = *(outer_char *)ps->ptr;

if(!(c && isprint(c) && c != ' ' && c != '0'))
	{
	*(outer_char *)ps->ptr = CCHAR;
	err_print(S,"Invalid continuation character '%c'; '%c' assumed",
		c,CCHAR);
	}
}

@ Here we check the validity of the line length for Fortran's output.

@a
SRTN @\
ini_output_line_length FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
int output_line_length;

set_int(ps);
output_line_length = *(int *)ps->ptr;

if(output_line_length < MIN_OUTPUT_LINE_LENGTH ||
		output_line_length > MAX_OUTPUT_LINE_LENGTH)
	{
	*(int *)ps->ptr = STANDARD_OUTPUT_LINE_LENGTH;
	err_print(S,"Invalid line length; %d assumed",
		STANDARD_OUTPUT_LINE_LENGTH);
	}
}

@ 
@<Unused@>=
SRTN @\
ini_cdir FCN((ps))
	CONST S_MAP HUGE *ps C1("")@;
{
outer_char *temp;
int n;

temp = GET_MEM("temp_cdir",
	(n=2*STRLEN(*((outer_char HUGE **)ps->ptr)))+1,outer_char); 
esc_buf(temp,temp+n,*((CONST outer_char HUGE **)ps->ptr),stemp,YES);
}

@* INITIALIZING CONTROL CODES.
The control code mapping can be overridden from the style file, although
this is not recommended except in unusual circumstances.

@d ignore 0

@<Glob...@>=

eight_bits ccode[128]; // Meaning of a character following '\.{@@}'.
CONST outer_char *cname[128]; // Associated names of control codes.
CONST ASCII HUGE *at_codes;

@ Here we initialize |ccode| with values that aren't allowed to be changed
by the style file.  The flag |USED_BY_NEITHER| is written into everything
first; if such a control code is encountered during the scan of either
processor, an error message will be issued.

@a
SRTN @\
zero_ccodes(VOID)
@{
int c; // Must be |int|, not |eight_bits|, so the |for| loop will end.

@b
/* Start out by initializing the array to a special flag. */
 for (c=0; c<=127; c++) 
	{
	ccode[c] = USED_BY_NEITHER;
	cname[c] = OC("?");
	}

@<Initialize unchangable codes@>@;
}

@ The following several codes aren't allowed to be changed.
@<Initialize unchangable...@>=
{
ccode[@'@@']=@'@@'; /* `quoted' at sign. This is so fundamental that it
			isn't allowed to be changed by the style file. */

ccode[@'{'] = @'{'; /* Since this is related to the C or \Ratfor\ languages,
			it shouldn't be changed. */
ccode[@'}'] = @'}'; // As above.

ccode[@'>'] = ignore; /* This is historical, and probably dangerous.  But
			it can't be |USED_BY_NEITHER|! */
}

@ The next routine is used by \FWEAVE\ or \FTANGLE\ to initialize the
control code table. Say, for example,
``\.{INI\_CCODE("Aa",begin\_code)}.  If at any point a |ccode|
entry has already been filled in, that means we \It{must} use the default
value. Thus, if the style file has attempted to override that value,
we complain---and abort after we've checked all the initializations.
@a
SRTN @\
ini_ccode FCN((keyword,defaults,code))
	CONST outer_char *keyword C0("The desired keyword.")@;
	CONST outer_char *defaults C0("String of default characters.")@;
	eight_bits code C1("Assign this \FWEB\ universal code")@;
{
CONST outer_char *pc; /* Pointer to the default characters to initialize. */
CONST S_MAP HUGE *m; /* Points to map entry for requested keyword. */
boolean bad_code = NO;
eight_bits cval;
boolean override; /* Are the default values overridden by the style file? */
IN_COMMON outer_char style_file_name[];
ASCII a; // Position in |ccode|.

/* Search for the keyword in the map array. */
if( (m=find_sty(map_array,keyword)) == NULL)
	override = NO; // The keyword isn't even in the table.
else
/* If the style file has set some values for this keyword, and the default
  values for this code are non-zero, then use the values from the style file.
  Otherwise, use the defaults. */
    override = BOOLEAN(*(outer_char **)m->ptr != NULL); 
		// The style file is overriding.

pc = (override && code) ? *(outer_char **)m->ptr : defaults;

/* If we're not ignoring this code completely, assign it to the relevant
values. */
if(code != USED_BY_NEITHER)
   while(*pc)
	{
	if(override && ((cval = ccode[XORD(*pc)]) != USED_BY_NEITHER) )
		{
		printf("! ccode['%c'] already filled with \"%s\"; \
not filled with \"%s\" = \"%s\".\n",
			*pc, (char *)ccode_name(cval), (char *)keyword,
			(char *)ccode_name(code));
		bad_code = YES;
		}

	a = XORD(*pc++);
	ccode[a] = code;
	cname[a] = keyword;
	}

if(bad_code) 
	FATAL(S, 
		"Invalid control code mapping; ",
		"check the style file %s.",
		style_file_name);
}

@ For \FTANGLE, after all the |ccode|s have been assigned, a few of them
must be reinterpreted. For example, by default the codes ``\.{\^.9tT}'' are
all interpreted as |control_text|.
@a
SRTN @\
reassign FCN((old_code,new_code))
	eight_bits old_code C0("")@;
	eight_bits new_code C1("")@;
{
int c;

for(c=0; c<128; c++)
	if(ccode[c] == old_code) 
		ccode[c] = new_code;
}

@ The following array is used for sorting the control-code keywords.
@<Glob...@>=

static CC_BUF HUGE *cc_buf;

@ Here we print out the control code mappings in resonse to \.{-@@}.  They
are printed twice, first alphabetized by the control code, next by the
keyword.  These are printed out side by side.

@a
SRTN @\
prn_codes(VOID)
{
IN_COMMON boolean found_web;
int HUGE *cc_indices;
boolean prn_all = NO;

int k;
int n = 0; // Number of codes to print.

if(!at_codes) 
	return;

puts("Control-code assignments \
([S,D,C]==`Begins [Section,Definition,Code])':");

cc_buf = GET_MEM("cc_buf", 128, CC_BUF);
cc_indices = GET_MEM("cc_indices", 128, int);

if(*at_codes && at_codes[0] == @'*' && at_codes[1] == @'*')
	prn_all = YES;

if(*at_codes && !prn_all)
	{ /* A specific list was given on command line. */
	CONST ASCII *p;

	for(p=at_codes; *p; p++)
		prn0_code(*p, cc_buf, &n);
	}
else
	{ /* Do all of them. */
	ASCII a;

	for(a=0; a<128; a++)
		{
		if(ccode[a] == USED_BY_NEITHER && !prn_all)
			continue;

		prn0_code(a, cc_buf, &n);
		}
	}

FREE_MEM(at_codes, "at_codes", 200, ASCII);

for(k=0; k<n; k++)
	cc_indices[k] = k;

QSORT(cc_indices, n, sizeof(int), cc_cmp);

for(k=0; k<n; k++)
	STRCPY(cc_buf[k][1], cc_buf[cc_indices[k]][0]);
 
for(k=0; k<n; k++)
	printf("%-40s%-40s\n", cc_buf[k][0], cc_buf[k][1]);

FREE_MEM(cc_buf, "cc_buf", 128, CC_BUF);
FREE_MEM(cc_indices, "cc_indices", 128, int);

if(!found_web) 
	wrap_up();
}

@ We alphabetize on the keywords, which follow the `\.{---}'.

@a
int @\
cc_cmp FCN((k0, k1))
	CONST VOID *pk0 C0("")@;
	CONST VOID *pk1 C1("")@;
{
char *s0, *s1;

s0 = strrchr(cc_buf[*(int *)pk0][0], '-');
s1 = strrchr(cc_buf[*(int *)pk1][0], '-');

return STRCMP(s0, s1);
}

@ Print out one control code.
@a
SRTN @\
prn0_code FCN((a, cc_buf, pk))
	ASCII a C0("")@;
	CC_BUF HUGE *cc_buf C0("")@;
	int *pk C1("")@;
{	
ASCII new_module, begin_code, formatt;
ASCII cc = ccode[a];
outer_char c;
int n;
outer_char *letter;

/* The following assumes that these particular codes never change.  This
was easier than including the header files. */
new_module = ccode[@'*'];
begin_code = ccode[@'a'];
formatt = ccode[@'f'];

c = XCHR(a);

if(cc == USED_BY_NEITHER)
	letter = OC("   ");
else if(cc >= new_module)
	letter = OC("[S]");
else if(cc >= begin_code)
	letter = OC("[C]");
else if(cc >= formatt)
	letter = OC("[D]");
else
	letter = OC("   ");

n = NSPRINTF((outer_char *)&cc_buf[*pk][0][0], 
isprint(c) ? "  %s @@%c" : " %s@@'0x%02x'", 
		isprint(c) ? letter : OC(""), c);

switch(c)
	{
   case '/':
	cname[c] = OC("(verbatim comment)");
	break;

   case '>':
	cname[c] = OC("(end of module name)");
	break;

   case '@@':
	cname[c] = OC("(literal '@@')");
	break;
	}

sprintf(&cc_buf[*pk][0][n], " --- %s", (char *)cname[c]);
(*pk)++; // Increment array index.
}

@* COLOR.

@d SET_ACOLOR(field,clr) wt_style.color.field.value = clr

@<Glob...@>=
static outer_char HUGE *termcap; // Name of termcap file.
static outer_char HUGE *tcap_buffer; // Allocated dynamically.

@  Colors are initialized to default values, then overridden for several
built-in palettes.
@a
SRTN @\
ini_colors FCN((color_mode))
	COLOR_MODE color_mode C1("")@;
{
@<Set default colors@>@; // Attach colors to fields.

if(!(termcap=get_termcap())) wt_style.color_mode = color_mode = NO_COLOR;

@<Make default links between bilevel mode and colors@>@;

switch(color_mode)
	{
   case NO_COLOR:
	break;

   case BILEVEL:
	CLR_LINK(YELLOW,md);
	CLR_LINK(GREEN,md);
	CLR_LINK(RED,mdmr);
	break;

   case TRUE_COLOR:
	CLR_LINK(YELLOW,md);
	CLR_LINK(GREEN,us);
	CLR_LINK(BLUE,md);
	CLR_LINK(ORANGE,md);
	CLR_LINK(RED,mdmr);
	break;
	}
}

@ Get control sequence for a color.  This is an ini routine for
\.{color.red} etc.
@a
SRTN @\
ini_bilevel FCN((ps))
	S_MAP HUGE *ps C1("")@;
{
set_str(ps);

if(termcap==NULL) return;

termset(ps->ptr);
}

@ Default color assignments to the various FWEB fields. Change these in the
style file by saying ``\.{color.error = "red"}''.
@<Set default colors@>=
{
SET_ACOLOR(ordinary,NORMAL);
SET_ACOLOR(program_name,YELLOW);
SET_ACOLOR(info,GREEN);
SET_ACOLOR(warning,ORANGE);
SET_ACOLOR(error,RED);
SET_ACOLOR(fatal,RED);
SET_ACOLOR(module_num,ORANGE);
SET_ACOLOR(line_num,ORANGE);
SET_ACOLOR(in_file,YELLOW);
SET_ACOLOR(include_file,BLUE);
SET_ACOLOR(out_file,YELLOW);
SET_ACOLOR(timing,ORANGE);
}

@ Associate a color with a control sequence.

@m CLR_LINK(CLR,id) link0(&wt_style.color._##CLR,OC(#id),termset)

@<Make default links...@>=

CLR_LINK(NORMAL,me);
CLR_LINK(YELLOW,md);
CLR_LINK(GREEN,me);
CLR_LINK(ORANGE,me);
CLR_LINK(RED,mdmr);
CLR_LINK(BLUE,me);

@
@a
SRTN @\
link0 FCN((pp,id,fcn))
	outer_char HUGE **pp C0("")@;
	CONST outer_char HUGE *id C0("")@;
	SRTN (HUGE_FCN_PTR *fcn)PROTO((CONST outer_char HUGE **)) C1("")@;
{
a_str(pp,id); // Allocate space, and store abbreviation string.
(*fcn)((CONST outer_char HUGE **)pp); /* Replace that string by actual escape
					sequences. */
}

@ Similarly, initialize extensions.

@<Finish initializing mappings@>=
{
EXT_LINK(web,"web");
EXT_LINK(change,"ch");
EXT_LINK(hweb,"hweb");
EXT_LINK(hchange,"hch");
}

@ Allocate and store an abbreviation string.
@a
SRTN @\
a_str FCN((pp,id))
	outer_char HUGE **pp C0("")@;
	CONST outer_char HUGE *id C1("")@;
{
@% if(*pp) FREE(*pp); // It's VERY destructive to free memory here!
*((outer_char HUGE * *)pp) = GET_MEM("map_string",STRLEN(id)+1,outer_char); 
STRCPY(*((outer_char HUGE * *)pp),id);
}

@ Open and read the termcap file.

@d ENV_TERM "TERM" // Unix environment variable for terminal type.

@a
outer_char * @\
get_termcap(VOID)
{
#if !HAVE_GETENV
	return NULL;
#else
if((termcap = GETENV(ENV_TERM)) == NULL) return NULL;

tcap_buffer = GET_MEM("tcap_buffer",1024,outer_char);

switch(tgetent(tcap_buffer,termcap))
	{
   case -1:
	printf("! Can't open termcap file %s.\n", (char *)termcap);

   case 0:
	return NULL;
	}

return termcap;
#endif // |HAVE_GETENV|
}

@ On entry, takes as argument a pointer to a string of blank-separated
abbreviations.  On exit, the pointer is changed to point to a |SEQUENCES|
structure that contains the actual escape sequences.

@d NUM_TEMP_PTRS 20

@a
SRTN @\
termset FCN((pid))
	CONST outer_char HUGE **pid C1("")@;
{
outer_char value_buf[500], *area = value_buf; // For |tgetstr|.
outer_char *s;
CONST outer_char HUGE *t;
outer_char id[3];
int k,n;
SEQUENCES HUGE *ps = GET_MEM("termcap struct",1,SEQUENCES);
outer_char *string[NUM_TEMP_PTRS];

if(!termcap) return;

for(t=*pid,n=0; *t; t+=2)
	{
	if(n == NUM_TEMP_PTRS) break;
	while(*t==' ') t++;

/* Put the abbreviation for escape sequence into |id|. */
	STRNCPY(id,t,2);
	TERMINATE(id,2);

/* Get the actual escape sequence from termcap file. */
	if((s=tgetstr(id,&area)) == NULL)
		printf("! Termcap entry \"%s\" not found \
for terminal type \"%s\".\n", (char *)id, (char *)termcap);
	else string[n++] = s;
	}

@<Allocate and initialize memory for the strings@>@;
}

@
@<Allocate and initialize memory for the strings@>=
{
ps->n = (short)n;
ps->string = GET_MEM("termcap strings",n,outer_char *);

for(k=0; k<n; k++)
	{
	ps->string[k] = GET_MEM("termcap string",
		STRLEN(string[k])+1,outer_char);
	STRCPY(ps->string[k],string[k]);
	}

FREE((void *)(*pid));
*pid = (CONST outer_char HUGE *)ps;
}

@ A similar routine processes a blank-delimited list of extensions.
@a
SRTN @\
ext_set FCN((pid))
	CONST outer_char HUGE **pid C1("")@;
{
outer_char id[1000],*p,*p0;
CONST outer_char HUGE *t;
outer_char *string[NUM_TEMP_PTRS];
int k,n;
SEQUENCES HUGE *ps = GET_MEM("termcap struct",1,SEQUENCES);

t = *pid; // Beginning of blank-separated list.
n = 0; // Number of fields found.
p = id; // Start of storage area

while(*t)
	{
	if(n == NUM_TEMP_PTRS) break;
	while(*t == ' ') t++; // Skip initial white space.
	
	p0 = p;
	while(*t != ' ' && *t) *p++ = *t++;
	TERMINATE(p,0);
	p++;
	string[n++] = p0; // Remember where string is.
	}

@<Allocate and init...@>@;
}

@ Used by |tputs|, which is an output routine used to send one character.
We need this intermediate function |put_out| because |putchar| is a macro
on some systems.
@a
int @\
put_out FCN((c))
	int c C1("")@;
{
return putchar(c);
}

@ Output the control sequences corresponding to a color.  This needs to be
generalized for~X.

@m SEND(CLR) tput((SEQUENCES *)wt_style.color._##CLR)

@m CLR_CASE(CLR) 
	case CLR:
	   SEND(CLR);
	   break@;

@a
SRTN @\
set_color FCN((clr))
	COLOR clr C1("")@;
{
color0.last = color0.present; // Save the incoming color, for later restore.

if(wt_style.color_mode != NO_COLOR)
  switch(clr)
	{
	CLR_CASE(NORMAL);
	CLR_CASE(GREEN);
	CLR_CASE(RED);
	CLR_CASE(BLUE);
	CLR_CASE(ORANGE);
	CLR_CASE(YELLOW);

   default:
	SEND(NORMAL);
	break;
	}

color0.present = clr;
}

@ Send each abbreviation in turn.
@a
SRTN @\
tput FCN((ps))
	SEQUENCES *ps C1("")@;
{
int k;

for(k=0; k<ps->n; k++)
	tputs(ps->string[k],1,put_out);
}

@ Print to terminal in particular color.  (This routine is independent of
the particular color mechanism.) \It{Check the variable arguments; they're
not right for Sun-CC yet.}
@<Unused@>=

SRTN @\
clr_printf FCN(VA_ALIST((clr,fmt VA_ARGS)))
	VA_DCL(
	COLOR clr C0("")@;
	outer_char *fmt C2("")@;)@;
{
VA_LIST(arg_ptr)@;

set_color(clr); // Remembers previous color in |color0.last|.

VA_START(arg_ptr,fmt);
vprintf_(fmt,arg_ptr);
va_end(arg_ptr);

set_color(color0.last); // Restore color.
}

@* PRINTING OUT VALUES.
@<Unused@>=
boolean @\
out_map FCN((name))
	outer_char *name C1("")@;
{
outer_char *p;
outer_char key_name[100];
S_MAP *m;

STRCPY(key_name,name);
for(p=key_name; *p; p++)
	if(*p == '.') *p = '_';

for(m=fweb_map; *m->keyword; m++)
	if(STRCMP(m->keyword,key_name) == 0)
		{
		for(p=key_name; *p; p++)
			if(*p == '_') *p = '.';

		printf("%s = ",key_name);
		switch(m->type)
			{
		   case S_STRING:
			if(*(int *)m->ptr < (int)HIGHEST_COLOR)
				printf("%s\n",clr_name[*(int *)m->ptr]);
			else printf("\"%s\"\n",*(char * *)m->ptr);
			break;

		   case S_CHAR:
			printf("'%c'\n",*(char *)m->ptr);
			break;

		   case S_INT:
			printf("%d\n",*(int *)m->ptr);
			break;

		   case S_LONG:
			printf("%ld\n",*(long *)m->ptr);
			break;

		   default:
			printf("INVALID TYPE\n");
			break;
			}

		return YES;
		}

return NO;
}

@ Query the style-file parameters; from \.{-Z}~option.
@a
SRTN @\
see_style FCN((pa,see_all))
	CONST outer_char HUGE *pa C0("")@;
	boolean see_all C1("")@;
{
S_MAP HUGE **s0,HUGE **s,HUGE **s1,HUGE *m;

s0 = GET_MEM("s0",sizeof(fweb_map)/sizeof(S_MAP),S_MAP HUGE *);

/* Fill an array of pointers. */
for(s=s0,m=fweb_map; *(m->keyword); s++,m++)
	*s = m;

/* Sort the array. */
QSORT(s0,s-s0,sizeof(S_MAP HUGE *),cmpr_s_map);

/* Print out the values. */
printf("%s style-file parameters%s%s%s%s:\n",
	see_all ? "Default" : "Modified",
	*pa ? " beginning with \"" : "", (char *)pa, *pa ? "\"" : "",
	see_all ? "\n (null or empty values for colors and \
@@ command codes are misleading)" : "");

if(*pa)
	{ /* Convert \.{'.'} to \.{'\_'}. */
	outer_char HUGE *p;

	for(p=(outer_char HUGE *)pa; *p; p++)
		if(*p == '.')
			*p = '_';
	}

for(s1=s0; s1<s; s1++)
	see_map(*s1,pa,see_all);

FREE_MEM(s0,"s0",sizeof(fweb_map)/sizeof(S_MAP),S_MAP);
}

@
@a
int @\
cmpr_s_map FCN((s0,s1))
	S_MAP HUGE **s0 C0("")@;
	S_MAP HUGE **s1 C1("")@;
{
return STRCMP((*s0)->keyword,(*s1)->keyword);
}

@ Print out an individual style-file parameter.
@a
SRTN @\
see_map FCN((s,pa,see_all))
	S_MAP HUGE *s C0("")@;
	CONST outer_char HUGE *pa C0("")@;
	boolean see_all C1("")@;
{
if(*pa && STRNCMP(pa,s->keyword,STRLEN(pa)) != 0) return;

if(see_all) 
	printf(" ");
else
	{ /* Handled modified parameters. */
	if(s->type & S_MODIFIED) 
		{
		printf("*");
		s->type &= ~S_MODIFIED;
		}

	else return;
	}

printf(" %s = ", (char *)s->keyword);

switch(s->type)
	{
   case S_STRING:
	see_str(*((outer_char **)s->ptr));
	break;

   case S_CHAR:
	printf("'%c'\n",*(outer_char *)s->ptr);
	break;

   case S_INT:
	printf("%d\n",*(int *)s->ptr);
	break;

   case S_LONG:
	printf("%ld\n",*(long *)s->ptr);
	break;

   default:
	break;
	}
}

@
@a
SRTN @\
see_str FCN((s))
	CONST outer_char HUGE *s C1("")@;
{
outer_char c;

if(s==NULL) 
	{
	printf("NULL\n");
	return;
	}
else if(s < (outer_char HUGE *)100) 
	{ /* Horrible kludge to handle stupid color processing. */
	printf("\n");
	return;
	}

printf("\"");

while((c = *s++))
  print_it:
	if(c=='\\') printf("\\\\");
	else if(isprint(c)) printf("%c",c);
	else 
		{
		printf("\\");
		switch(c)
			{
		   case '\a': c = 'a'; goto print_it;
		   case '\b': c = 'b'; goto print_it;
		   case '\f': c = 'f'; goto print_it;
		   case '\n': c = 'n'; goto print_it;
		   case '\r': c = 'r'; goto print_it;
		   case '\t': c = 't'; goto print_it;
		   case '\v': c = 'v'; goto print_it;
		   default:
			printf("%o",c);
			break;
			}
		}

printf("\"\n");
}

@* INDEX.