[0001]
[0002]
[0003]
[0004]
[0005]
[0006]
[0007]
[0008]
[0009]
[0010]
[0011]
[0012]
[0013]
[0014]
[0015]
[0016]
[0017]
[0018]
[0019]
[0020]
[0021]
[0022]
[0023]
[0024]
[0025]
[0026]
[0027]
[0028]
[0029]
[0030]
[0031]
[0032]
[0033]
[0034]
[0035]
[0036]
[0037]
[0038]
[0039]
[0040]
[0041]
[0042]
[0043]
[0044]
[0045]
[0046]
[0047]
[0048]
[0049]
[0050]
[0051]
[0052]
[0053]
[0054]
[0055]
[0056]
[0057]
[0058]
[0059]
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091]
[0092]
[0093]
[0094]
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106]
[0107]
[0108]
[0109]
[0110]
[0111]
[0112]
[0113]
[0114]
[0115]
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122]
[0123]
[0124]
[0125]
[0126]
[0127]
[0128]
[0129]
[0130]
[0131]
[0132]
[0133]
[0134]
[0135]
[0136]
[0137]
[0138]
[0139]
[0140]
[0141]
[0142]
[0143]
[0144]
[0145]
[0146]
[0147]
[0148]
[0149]
[0150]
[0151]
[0152]
[0153]
[0154]
[0155]
[0156]
[0157]
[0158]
[0159]
[0160]
[0161]
[0162]
[0163]
[0164]
[0165]
[0166]
[0167]
[0168]
[0169]
[0170]
[0171]
[0172]
[0173]
[0174]
[0175]
[0176]
[0177]
[0178]
[0179]
[0180]
[0181]
[0182]
[0183]
[0184]
[0185]
[0186]
[0187]
[0188]
[0189]
[0190]
[0191]
[0192]
[0193]
[0194]
[0195]
[0196]
[0197]
[0198]
[0199]
[0200]
[0201]
[0202]
[0203]
[0204]
[0205]
[0206]
[0207]
[0208]
[0209]
[0210]
[0211]
[0212]
[0213]
[0214]
[0215]
[0216]
[0217]
[0218]
[0219]
[0220]
[0221]
[0222]
[0223]
[0224]
[0225]
[0226]
[0227]
[0228]
[0229]
[0230]
[0231]
[0232]
[0233]
[0234]
[0235]
[0236]
[0237]
[0238]
[0239]
[0240]
[0241]
[0242]
[0243]
[0244]
[0245]
[0246]
[0247]
[0248]
[0249]
[0250]
[0251]
[0252]
[0253]
[0254]
[0255]
[0256]
[0257]
[0258]
[0259]
[0260]
[0261]
[0262]
[0263]
[0264]
[0265]
[0266]
[0267]
[0268]
[0269]
[0270]
[0271]
[0272]
[0273]
[0274]
[0275]
[0276]
[0277]
[0278]
[0279]
[0280]
[0281]
[0282]
[0283]
[0284]
[0285]
[0286]
[0287]
[0288]
[0289]
[0290]
[0291]
[0292]
[0293]
[0294]
[0295]
[0296]
[0297]
[0298]
[0299]
[0300]
[0301]
[0302]
[0303]
[0304]
[0305]
[0306]
[0307]
[0308]
[0309]
[0310]
[0311]
[0312]
[0313]
[0314]
[0315]
[0316]
[0317]
[0318]
[0319]
[0320]
[0321]
[0322]
[0323]
[0324]
[0325]
[0326]
[0327]
[0328]
[0329]
[0330]
[0331]
[0332]
[0333]
[0334]
[0335]
[0336]
[0337]
[0338]
[0339]
[0340]
[0341]
[0342]
[0343]
[0344]
[0345]
[0346]
[0347]
[0348]
[0349]
[0350]
[0351]
[0352]
[0353]
[0354]
[0355]
[0356]
[0357]
[0358]
[0359]
[0360]
[0361]
[0362]
[0363]
[0364]
[0365]
[0366]
[0367]
[0368]
[0369]
[0370]
[0371]
[0372]
[0373]
[0374]
[0375]
[0376]
[0377]
[0378]
[0379]
[0380]
[0381]
[0382]
[0383]
[0384]
[0385]
[0386]
[0387]
[0388]
[0389]
[0390]
[0391]
[0392]
[0393]
[0394]
[0395]
[0396]
[0397]
[0398]
[0399]
[0400]
[0401]
[0402]
[0403]
[0404]
[0405]
[0406]
[0407]
[0408]
[0409]
[0410]
[0411]
[0412]
[0413]
[0414]
[0415]
[0416]
[0417]
[0418]
[0419]
[0420]
[0421]
[0422]
[0423]
[0424]
[0425]
[0426]
[0427]
[0428]
[0429]
[0430]
[0431]
[0432]
[0433]
[0434]
[0435]
[0436]
[0437]
[0438]
[0439]
[0440]
[0441]
[0442]
[0443]
[0444]
[0445]
[0446]
[0447]
[0448]
[0449]
[0450]
[0451]
[0452]
[0453]
[0454]
[0455]
[0456]
[0457]
[0458]
[0459]
[0460]
[0461]
[0462]
[0463]
[0464]
[0465]
[0466]
[0467]
[0468]
[0469]
[0470]
[0471]
[0472]
[0473]
[0474]
[0475]
[0476]
[0477]
[0478]
[0479]
[0480]
[0481]
[0482]
[0483]
[0484]
[0485]
[0486]
[0487]
[0488]
[0489]
[0490]
[0491]
[0492]
[0493]
[0494]
[0495]
[0496]
[0497]
[0498]
[0499]
[0500]
[0501]
[0502]
[0503]
[0504]
[0505]
[0506]
[0507]
[0508]
[0509]
[0510]
[0511]
[0512]
[0513]
[0514]
[0515]
[0516]
[0517]
[0518]
[0519]
[0520]
[0521]
[0522]
[0523]
[0524]
[0525]
[0526]
[0527]
[0528]
[0529]
[0530]
[0531]
[0532]
[0533]
[0534]
[0535]
[0536]
[0537]
[0538]
[0539]
[0540]
[0541]
[0542]
[0543]
[0544]
[0545]
[0546]
[0547]
[0548]
[0549]
[0550]
[0551]
[0552]
[0553]
[0554]
[0555]
[0556]
[0557]
[0558]
[0559]
[0560]
[0561]
[0562]
[0563]
[0564]
[0565]
[0566]
[0567]
[0568]
[0569]
[0570]
[0571]
[0572]
[0573]
[0574]
[0575]
[0576]
[0577]
[0578]
[0579]
[0580]
[0581]
[0582]
[0583]
[0584]
[0585]
[0586]
[0587]
[0588]
[0589]
[0590]
[0591]
[0592]
[0593]
[0594]
[0595]
[0596]
[0597]
[0598]
[0599]
[0600]
[0601]
[0602]
[0603]
[0604]
[0605]
[0606]
[0607]
[0608]
[0609]
[0610]
[0611]
[0612]
[0613]
[0614]
[0615]
[0616]
[0617]
[0618]
[0619]
[0620]
[0621]
[0622]
[0623]
[0624]
[0625]
[0626]
[0627]
[0628]
[0629]
[0630]
[0631]
[0632]
[0633]
[0634]
[0635]
[0636]
[0637]
[0638]
[0639]
[0640]
[0641]
[0642]
[0643]
[0644]
[0645]
[0646]
[0647]
[0648]
[0649]
[0650]
[0651]
[0652]
[0653]
[0654]
[0655]
[0656]
[0657]
[0658]
[0659]
[0660]
[0661]
[0662]
[0663]
[0664]
[0665]
[0666]
[0667]
[0668]
[0669]
[0670]
[0671]
[0672]
[0673]
[0674]
[0675]
[0676]
[0677]
[0678]
[0679]
[0680]
[0681]
[0682]
[0683]
[0684]
[0685]
[0686]
[0687]
[0688]
[0689]
[0690]
[0691]
[0692]
[0693]
[0694]
[0695]
[0696]
[0697]
[0698]
[0699]
[0700]
[0701]
[0702]
[0703]
[0704]
[0705]
[0706]
[0707]
[0708]
[0709]
[0710]
[0711]
[0712]
[0713]
[0714]
[0715]
[0716]
[0717]
[0718]
[0719]
[0720]
[0721]
[0722]
[0723]
[0724]
[0725]
[0726]
[0727]
[0728]
[0729]
[0730]
[0731]
[0732]
[0733]
[0734]
[0735]
[0736]
[0737]
[0738]
[0739]
[0740]
[0741]
[0742]
[0743]
[0744]
[0745]
[0746]
[0747]
[0748]
[0749]
[0750]
[0751]
[0752]
[0753]
[0754]
[0755]
[0756]
[0757]
[0758]
[0759]
[0760]
[0761]
[0762]
[0763]
[0764]
[0765]
[0766]
[0767]
[0768]
[0769]
[0770]
[0771]
[0772]
[0773]
[0774]
[0775]
[0776]
[0777]
[0778]
[0779]
[0780]
[0781]
[0782]
[0783]
[0784]
[0785]
[0786]
[0787]
[0788]
[0789]
[0790]
[0791]
[0792]
[0793]
[0794]
[0795]
[0796]
[0797]
[0798]
[0799]
[0800]
[0801]
[0802]
[0803]
[0804]
[0805]
[0806]
[0807]
[0808]
[0809]
[0810]
[0811]
[0812]
[0813]
[0814]
[0815]
[0816]
[0817]
[0818]
[0819]
[0820]
[0821]
[0822]
[0823]
[0824]
[0825]
[0826]
[0827]
[0828]
[0829]
[0830]
[0831]
[0832]
[0833]
[0834]
[0835]
[0836]
[0837]
[0838]
[0839]
[0840]
[0841]
[0842]
[0843]
[0844]
[0845]
[0846]
[0847]
[0848]
[0849]
[0850]
[0851]
[0852]
[0853]
[0854]
[0855]
[0856]
[0857]
[0858]
[0859]
[0860]
[0861]
[0862]
[0863]
[0864]
[0865]
[0866]
[0867]
[0868]
[0869]
[0870]
[0871]
[0872]
[0873]
[0874]
[0875]
[0876]
[0877]
[0878]
[0879]
[0880]
[0881]
[0882]
[0883]
[0884]
[0885]
[0886]
[0887]
[0888]
[0889]
[0890]
[0891]
[0892]
[0893]
[0894]
[0895]
[0896]
[0897]
[0898]
[0899]
[0900]
[0901]
[0902]
[0903]
[0904]
[0905]
[0906]
[0907]
[0908]
[0909]
[0910]
[0911]
[0912]
[0913]
[0914]
[0915]
[0916]
[0917]
[0918]
[0919]
[0920]
[0921]
[0922]
[0923]
[0924]
[0925]
[0926]
[0927]
[0928]
[0929]
[0930]
[0931]
[0932]
[0933]
[0934]
[0935]
[0936]
[0937]
[0938]
[0939]
[0940]
[0941]
[0942]
[0943]
[0944]
[0945]
[0946]
[0947]
[0948]
[0949]
[0950]
[0951]
[0952]
[0953]
[0954]
[0955]
[0956]
[0957]
[0958]
[0959]
[0960]
[0961]
[0962]
[0963]
[0964]
[0965]
[0966]
[0967]
[0968]
[0969]
[0970]
[0971]
[0972]
[0973]
[0974]
[0975]
[0976]
[0977]
[0978]
[0979]
[0980]
[0981]
[0982]
[0983]
[0984]
[0985]
[0986]
[0987]
[0988]
[0989]
[0990]
[0991]
[0992]
[0993]
[0994]
[0995]
[0996]
[0997]
[0998]
[0999]
[1000]
[1001]
[1002]
[1003]
[1004]
[1005]
[1006]
[1007]
[1008]
[1009]
[1010]
[1011]
[1012]
[1013]
[1014]
[1015]
[1016]
[1017]
[1018]
[1019]
[1020]
[1021]
[1022]
[1023]
[1024]
[1025]
[1026]
[1027]
[1028]
[1029]
[1030]
[1031]
[1032]
[1033]
[1034]
[1035]
[1036]
[1037]
[1038]
[1039]
[1040]
[1041]
[1042]
[1043]
[1044]
[1045]
[1046]
[1047]
[1048]
[1049]
[1050]
[1051]
[1052]
[1053]
[1054]
[1055]
[1056]
[1057]
[1058]
[1059]
[1060]
[1061]
[1062]
[1063]
[1064]
[1065]
[1066]
[1067]
[1068]
[1069]
[1070]
[1071]
[1072]
[1073]
[1074]
[1075]
[1076]
[1077]
[1078]
[1079]
[1080]
[1081]
[1082]
[1083]
[1084]
[1085]
[1086]
[1087]
[1088]
[1089]
[1090]
[1091]
[1092]
[1093]
[1094]
[1095]
[1096]
[1097]
[1098]
[1099]
[1100]
[1101]
[1102]
[1103]
[1104]
[1105]
[1106]
[1107]
[1108]
[1109]
[1110]
[1111]
[1112]
[1113]
[1114]
[1115]
[1116]
[1117]
[1118]
[1119]
[1120]
[1121]
[1122]
[1123]
[1124]
[1125]
[1126]
[1127]
[1128]
[1129]
[1130]
[1131]
[1132]
[1133]
[1134]
[1135]
[1136]
[1137]
[1138]
[1139]
[1140]
[1141]
[1142]
[1143]
[1144]
[1145]
[1146]
[1147]
[1148]
[1149]
[1150]
[1151]
[1152]
[1153]
[1154]
[1155]
[1156]
[1157]
[1158]
[1159]
[1160]
[1161]
[1162]
[1163]
[1164]
[1165]
[1166]
[1167]
[1168]
[1169]
[1170]
[1171]
[1172]
[1173]
[1174]
[1175]
[1176]
[1177]
[1178]
[1179]
[1180]
[1181]
[1182]
[1183]
[1184]
[1185]
[1186]
[1187]
[1188]
[1189]
[1190]
[1191]
[1192]
[1193]
[1194]
[1195]
[1196]
[1197]
[1198]
[1199]
[1200]
[1201]
[1202]
[1203]
[1204]
[1205]
[1206]
[1207]
[1208]
[1209]
[1210]
[1211]
[1212]
[1213]
[1214]
[1215]
[1216]
[1217]
[1218]
[1219]
[1220]
[1221]
[1222]
[1223]
[1224]
[1225]
[1226]
[1227]
[1228]
[1229]
[1230]
[1231]
[1232]
[1233]
[1234]
[1235]
[1236]
[1237]
[1238]
[1239]
[1240]
[1241]
[1242]
[1243]
[1244]
[1245]
[1246]
[1247]
[1248]
[1249]
[1250]
[1251]
[1252]
[1253]
[1254]
[1255]
[1256]
[1257]
[1258]
[1259]
[1260]
[1261]
[1262]
[1263]
[1264]
[1265]
[1266]
[1267]
[1268]
[1269]
[1270]
[1271]
[1272]
[1273]
[1274]
[1275]
[1276]
[1277]
[1278]
[1279]
[1280]
[1281]
[1282]
[1283]
[1284]
[1285]
[1286]
[1287]
[1288]
[1289]
[1290]
[1291]
[1292]
[1293]
[1294]
[1295]
[1296]
[1297]
[1298]
[1299]
[1300]
[1301]
[1302]
[1303]
[1304]
[1305]
[1306]
[1307]
[1308]
[1309]
[1310]
[1311]
[1312]
[1313]
[1314]
[1315]
[1316]
[1317]
[1318]
[1319]
[1320]
[1321]
[1322]
[1323]
[1324]
[1325]
[1326]
[1327]
[1328]
[1329]
[1330]
[1331]
[1332]
[1333]
[1334]
[1335]
[1336]
[1337]
[1338]
[1339]
[1340]
[1341]
[1342]
[1343]
[1344]
[1345]
[1346]
[1347]
[1348]
[1349]
[1350]
[1351]
[1352]
[1353]
[1354]
[1355]
[1356]
[1357]
[1358]
[1359]
[1360]
[1361]
[1362]
[1363]
[1364]
[1365]
[1366]
[1367]
[1368]
[1369]
[1370]
[1371]
[1372]
[1373]
[1374]
[1375]
[1376]
[1377]
[1378]
[1379]
[1380]
[1381]
[1382]
[1383]
[1384]
[1385]
[1386]
[1387]
[1388]
[1389]
[1390]
[1391]
[1392]
[1393]
[1394]
[1395]
[1396]
[1397]
[1398]
[1399]
[1400]
[1401]
[1402]
[1403]
[1404]
[1405]
[1406]
[1407]
[1408]
[1409]
[1410]
[1411]
[1412]
[1413]
[1414]
[1415]
[1416]
[1417]
[1418]
[1419]
[1420]
[1421]
[1422]
[1423]
[1424]
[1425]
[1426]
[1427]
[1428]
[1429]
[1430]
[1431]
[1432]
[1433]
[1434]
[1435]
[1436]
[1437]
[1438]
[1439]
[1440]
[1441]
[1442]
[1443]
[1444]
[1445]
[1446]
[1447]
[1448]
[1449]
[1450]
[1451]
[1452]
[1453]
[1454]
[1455]
[1456]
[1457]
[1458]
[1459]
[1460]
[1461]
[1462]
[1463]
[1464]
[1465]
[1466]
[1467]
[1468]
[1469]
[1470]
[1471]
[1472]
[1473]
[1474]
[1475]
[1476]
[1477]
[1478]
[1479]
[1480]
[1481]
[1482]
[1483]
[1484]
[1485]
[1486]
[1487]
[1488]
[1489]
[1490]
[1491]
[1492]
[1493]
[1494]
[1495]
[1496]
[1497]
[1498]
[1499]
[1500]
[1501]
[1502]
[1503]
[1504]
[1505]
[1506]
[1507]
[1508]
[1509]
[1510]
[1511]
[1512]
[1513]
[1514]
[1515]
[1516]
[1517]
[1518]
[1519]
[1520]
[1521]
[1522]
[1523]
[1524]
[1525]
[1526]
[1527]
[1528]
[1529]
[1530]
[1531]
[1532]
[1533]
[1534]
[1535]
[1536]
[1537]
[1538]
[1539]
[1540]
[1541]
[1542]
[1543]
[1544]
[1545]
[1546]
[1547]
[1548]
[1549]
[1550]
[1551]
[1552]
[1553]
[1554]
[1555]
[1556]
[1557]
[1558]
[1559]
[1560]
[1561]
[1562]
[1563]
[1564]
[1565]
[1566]
[1567]
[1568]
[1569]
[1570]
[1571]
[1572]
[1573]
[1574]
[1575]
[1576]
[1577]
[1578]
[1579]
[1580]
[1581]
[1582]
[1583]
[1584]
[1585]
[1586]
[1587]
[1588]
[1589]
[1590]
[1591]
[1592]
[1593]
[1594]
[1595]
[1596]
[1597]
[1598]
[1599]
[1600]
[1601]
[1602]
[1603]
[1604]
[1605]
[1606]
[1607]
[1608]
[1609]
[1610]
[1611]
[1612]
[1613]
[1614]
[1615]
[1616]
[1617]
[1618]
[1619]
[1620]
[1621]
[1622]
[1623]
[1624]
[1625]
[1626]
[1627]
[1628]
[1629]
[1630]
[1631]
[1632]
[1633]
[1634]
[1635]
[1636]
[1637]
[1638]
[1639]
[1640]
[1641]
[1642]
[1643]
[1644]
[1645]
[1646]
[1647]
[1648]
[1649]
[1650]
[1651]
[1652]
[1653]
[1654]
[1655]
[1656]
[1657]
[1658]
[1659]
[1660]
[1661]
[1662]
[1663]
[1664]
[1665]
[1666]
[1667]
[1668]
[1669]
[1670]
[1671]
[1672]
[1673]
[1674]
[1675]
[1676]
[1677]
[1678]
[1679]
[1680]
[1681]
[1682]
[1683]
[1684]
[1685]
[1686]
[1687]
[1688]
[1689]
[1690]
[1691]
[1692]
[1693]
[1694]
[1695]
[1696]
[1697]
[1698]
[1699]
[1700]
[1701]
[1702]
[1703]
[1704]
[1705]
[1706]
[1707]
[1708]
[1709]
[1710]
[1711]
[1712]
[1713]
[1714]
[1715]
[1716]
[1717]
[1718]
[1719]
[1720]
[1721]
[1722]
[1723]
[1724]
[1725]
[1726]
[1727]
[1728]
[1729]
[1730]
[1731]
[1732]
[1733]
[1734]
[1735]
[1736]
[1737]
[1738]
[1739]
[1740]
[1741]
[1742]
[1743]
[1744]
[1745]
[1746]
[1747]
[1748]
[1749]
[1750]
[1751]
[1752]
[1753]
[1754]
[1755]
[1756]
[1757]
[1758]
[1759]
[1760]
[1761]
[1762]
[1763]
[1764]
[1765]
[1766]
[1767]
[1768]
[1769]
[1770]
[1771]
[1772]
[1773]
[1774]
[1775]
[1776]
[1777]
[1778]
[1779]
[1780]
[1781]
[1782]
[1783]
[1784]
[1785]
[1786]
[1787]
[1788]
[1789]
[1790]
[1791]
[1792]
[1793]
[1794]
[1795]
[1796]
[1797]
[1798]
[1799]
[1800]
[1801]
[1802]
[1803]
[1804]
[1805]
[1806]
[1807]
[1808]
[1809]
[1810]
[1811]
[1812]
[1813]
[1814]
[1815]
[1816]
[1817]
[1818]
[1819]
[1820]
[1821]
[1822]
[1823]
[1824]
[1825]
[1826]
[1827]
[1828]
[1829]
[1830]
[1831]
[1832]
[1833]
[1834]
[1835]
[1836]
[1837]
[1838]
[1839]
[1840]
[1841]
[1842]
[1843]
[1844]
[1845]
[1846]
[1847]
[1848]
[1849]
[1850]
[1851]
[1852]
[1853]
[1854]
[1855]
[1856]
[1857]
[1858]
[1859]
[1860]
[1861]
[1862]
[1863]
[1864]
[1865]
[1866]
[1867]
[1868]
[1869]
[1870]
[1871]
[1872]
[1873]
[1874]
[1875]
[1876]
[1877]
[1878]
[1879]
[1880]
[1881]
[1882]
[1883]
[1884]
[1885]
[1886]
[1887]
[1888]
[1889]
[1890]
[1891]
[1892]
[1893]
[1894]
[1895]
[1896]
[1897]
[1898]
[1899]
[1900]
[1901]
[1902]
[1903]
[1904]
[1905]
[1906]
[1907]
[1908]
[1909]
[1910]
[1911]
[1912]
[1913]
[1914]
[1915]
[1916]
[1917]
[1918]
[1919]
[1920]
[1921]
[1922]
[1923]
[1924]
[1925]
[1926]
[1927]
[1928]
[1929]
[1930]
[1931]
[1932]
[1933]
[1934]
[1935]
[1936]
[1937]
[1938]
[1939]
[1940]
[1941]
[1942]
[1943]
[1944]
[1945]
[1946]
[1947]
[1948]
[1949]
[1950]
[1951]
[1952]
[1953]
[1954]
[1955]
[1956]
[1957]
[1958]
[1959]
[1960]
[1961]
[1962]
[1963]
[1964]
[1965]
[1966]
[1967]
[1968]
[1969]
[1970]
[1971]
[1972]
[1973]
[1974]
[1975]
[1976]
[1977]
[1978]
[1979]
[1980]
[1981]
[1982]
[1983]
[1984]
[1985]
[1986]
[1987]
[1988]
[1989]
[1990]
[1991]
[1992]
[1993]
[1994]
[1995]
[1996]
[1997]
[1998]
[1999]
[2000]
[2001]
[2002]
[2003]
[2004]
[2005]
[2006]
[2007]
[2008]
[2009]
[2010]
[2011]
[2012]
[2013]
[2014]
[2015]
[2016]
[2017]
[2018]
[2019]
[2020]
[2021]
[2022]
[2023]
[2024]
[2025]
[2026]
[2027]
[2028]
[2029]
[2030]
[2031]
[2032]
[2033]
[2034]
[2035]
[2036]
[2037]
[2038]
[2039]
[2040]
[2041]
[2042]
[2043]
[2044]
[2045]
[2046]
[2047]
[2048]
[2049]
[2050]
[2051]
[2052]
[2053]
[2054]
[2055]
[2056]
[2057]
[2058]
[2059]
[2060]
[2061]
[2062]
[2063]
[2064]
[2065]
[2066]
[2067]
[2068]
[2069]
[2070]
[2071]
[2072]
[2073]
[2074]
[2075]
[2076]
[2077]
[2078]
[2079]
[2080]
[2081]
[2082]
[2083]
[2084]
[2085]
[2086]
[2087]
[2088]
[2089]
[2090]
[2091]
[2092]
[2093]
[2094]
[2095]
[2096]
[2097]
[2098]
[2099]
[2100]
[2101]
[2102]
[2103]
[2104]
[2105]
[2106]
[2107]
[2108]
[2109]
[2110]
[2111]
[2112]
[2113]
[2114]
[2115]
[2116]
[2117]
[2118]
[2119]
[2120]
[2121]
[2122]
[2123]
[2124]
[2125]
[2126]
[2127]
[2128]
[2129]
[2130]
[2131]
[2132]
[2133]
[2134]
[2135]
[2136]
[2137]
[2138]
[2139]
[2140]
[2141]
[2142]
[2143]
[2144]
[2145]
[2146]
[2147]
[2148]
[2149]
[2150]
[2151]
[2152]
[2153]
[2154]
[2155]
[2156]
[2157]
[2158]
[2159]
[2160]
[2161]
[2162]
[2163]
[2164]
[2165]
[2166]
[2167]
[2168]
[2169]
[2170]
[2171]
[2172]
[2173]
[2174]
[2175]
[2176]
[2177]
[2178]
[2179]
[2180]
[2181]
[2182]
[2183]
[2184]
[2185]
[2186]
[2187]
[2188]
[2189]
[2190]
[2191]
[2192]
[2193]
[2194]
[2195]
[2196]
[2197]
[2198]
[2199]
[2200]
[2201]
[2202]
[2203]
[2204]
[2205]
[2206]
[2207]
[2208]
[2209]
[2210]
[2211]
[2212]
[2213]
[2214]
[2215]
[2216]
[2217]
[2218]
[2219]
[2220]
[2221]
[2222]
[2223]
[2224]
[2225]
[2226]
[2227]
[2228]
[2229]
[2230]
[2231]
[2232]
[2233]
[2234]
[2235]
[2236]
[2237]
[2238]
[2239]
[2240]
[2241]
[2242]
[2243]
[2244]
[2245]
[2246]
[2247]
[2248]
[2249]
[2250]
[2251]
[2252]
[2253]
[2254]
[2255]
[2256]
[2257]
[2258]
[2259]
[2260]
[2261]
[2262]
[2263]
[2264]
[2265]
[2266]
[2267]
[2268]
[2269]
[2270]
[2271]
[2272]
[2273]
[2274]
[2275]
[2276]
[2277]
[2278]
[2279]
[2280]
[2281]
[2282]
[2283]
[2284]
[2285]
[2286]
[2287]
[2288]
[2289]
[2290]
[2291]
[2292]
[2293]
[2294]
[2295]
[2296]
[2297]
[2298]
[2299]
[2300]
[2301]
[2302]
[2303]
[2304]
[2305]
[2306]
[2307]
[2308]
[2309]
[2310]
[2311]
[2312]
[2313]
[2314]
[2315]
[2316]
[2317]
[2318]
[2319]
[2320]
[2321]
[2322]
[2323]
[2324]
[2325]
[2326]
[2327]
[2328]
[2329]
[2330]
[2331]
[2332]
[2333]
[2334]
[2335]
[2336]
[2337]
[2338]
[2339]
[2340]
[2341]
[2342]
[2343]
[2344]
[2345]
[2346]
[2347]
[2348]
[2349]
[2350]
[2351]
[2352]
[2353]
[2354]
[2355]
[2356]
[2357]
[2358]
[2359]
[2360]
[2361]
[2362]
[2363]
[2364]
[2365]
[2366]
[2367]
[2368]
[2369]
[2370]
[2371]
[2372]
[2373]
[2374]
[2375]
[2376]
[2377]
[2378]
[2379]
[2380]
[2381]
[2382]
[2383]
[2384]
[2385]
[2386]
[2387]
[2388]
[2389]
[2390]
[2391]
[2392]
[2393]
[2394]
[2395]
[2396]
[2397]
[2398]
[2399]
[2400]
[2401]
[2402]
[2403]
[2404]
[2405]
[2406]
[2407]
[2408]
[2409]
[2410]
[2411]
[2412]
[2413]
[2414]
[2415]
[2416]
[2417]
[2418]
[2419]
[2420]
[2421]
[2422]
[2423]
[2424]
[2425]
[2426]
[2427]
[2428]
[2429]
[2430]
[2431]
[2432]
[2433]
[2434]
[2435]
[2436]
[2437]
[2438]
[2439]
[2440]
[2441]
[2442]
[2443]
[2444]
[2445]
[2446]
[2447]
[2448]
[2449]
[2450]
[2451]
[2452]
[2453]
[2454]
[2455]
[2456]
[2457]
[2458]
[2459]
[2460]
[2461]
[2462]
[2463]
[2464]
[2465]
[2466]
[2467]
[2468]
[2469]
[2470]
[2471]
[2472]
[2473]
[2474]
[2475]
[2476]
[2477]
[2478]
[2479]
[2480]
[2481]
[2482]
[2483]
[2484]
[2485]
[2486]
[2487]
[2488]
[2489]
[2490]
[2491]
[2492]
[2493]
[2494]
[2495]
[2496]
[2497]
[2498]
[2499]
[2500]
[2501]
[2502]
[2503]
[2504]
[2505]
[2506]
[2507]
[2508]
[2509]
[2510]
[2511]
[2512]
[2513]
[2514]
[2515]
[2516]
[2517]
[2518]
[2519]
[2520]
[2521]
[2522]
[2523]
[2524]
[2525]
[2526]
[2527]
[2528]
[2529]
[2530]
[2531]
[2532]
[2533]
[2534]
[2535]
[2536]
[2537]
[2538]
[2539]
[2540]
[2541]
[2542]
[2543]
[2544]
[2545]
[2546]
[2547]
[2548]
[2549]
[2550]
[2551]
[2552]
[2553]
[2554]
[2555]
[2556]
[2557]
[2558]
[2559]
[2560]
[2561]
[2562]
[2563]
[2564]
[2565]
[2566]
[2567]
[2568]
[2569]
[2570]
[2571]
[2572]
[2573]
[2574]
[2575]
[2576]
[2577]
[2578]
[2579]
[2580]
[2581]
[2582]
[2583]
[2584]
[2585]
[2586]
[2587]
[2588]
[2589]
[2590]
[2591]
[2592]
[2593]
[2594]
[2595]
[2596]
[2597]
[2598]
[2599]
[2600]
[2601]
[2602]
[2603]
[2604]
[2605]
[2606]
[2607]
[2608]
[2609]
[2610]
[2611]
[2612]
[2613]
[2614]
[2615]
[2616]
[2617]
[2618]
[2619]
[2620]
[2621]
[2622]
[2623]
[2624]
[2625]
[2626]
[2627]
[2628]
[2629]
[2630]
[2631]
[2632]
[2633]
[2634]
[2635]
[2636]
[2637]
[2638]
[2639]
[2640]
[2641]
[2642]
[2643]
[2644]
[2645]
[2646]
[2647]
[2648]
[2649]
[2650]
[2651]
[2652]
[2653]
[2654]
[2655]
[2656]
[2657]
[2658]
[2659]
[2660]
[2661]
[2662]
[2663]
[2664]
[2665]
[2666]
[2667]
[2668]
[2669]
[2670]
[2671]
[2672]
[2673]
[2674]
[2675]
[2676]
[2677]
[2678]
[2679]
[2680]
[2681]
[2682]
[2683]
[2684]
[2685]
[2686]
[2687]
[2688]
[2689]
[2690]
[2691]
[2692]
[2693]
[2694]
[2695]
[2696]
[2697]
[2698]
[2699]
[2700]
[2701]
[2702]
[2703]
[2704]
[2705]
[2706]
[2707]
[2708]
[2709]
[2710]
[2711]
[2712]
[2713]
[2714]
[2715]
[2716]
[2717]
[2718]
[2719]
[2720]
[2721]
[2722]
[2723]
[2724]
[2725]
[2726]
[2727]
[2728]
[2729]
[2730]
[2731]
[2732]
[2733]
[2734]
[2735]
[2736]
[2737]
[2738]
[2739]
[2740]
[2741]
[2742]
[2743]
[2744]
[2745]
[2746]
[2747]
[2748]
[2749]
[2750]
[2751]
[2752]
[2753]
[2754]
[2755]
[2756]
[2757]
[2758]
[2759]
[2760]
[2761]
[2762]
[2763]
[2764]
[2765]
[2766]
[2767]
[2768]
[2769]
[2770]
[2771]
[2772]
[2773]
[2774]
[2775]
[2776]
[2777]
[2778]
[2779]
[2780]
[2781]
[2782]
[2783]
[2784]
[2785]
[2786]
[2787]
[2788]
[2789]
[2790]
[2791]
[2792]
[2793]
[2794]
[2795]
[2796]
[2797]
[2798]
[2799]
[2800]
[2801]
[2802]
[2803]
[2804]
[2805]
[2806]
[2807]
[2808]
[2809]
[2810]
[2811]
[2812]
[2813]
[2814]
[2815]
[2816]
[2817]
[2818]
[2819]
[2820]
[2821]
[2822]
[2823]
[2824]
[2825]
[2826]
[2827]
[2828]
[2829]
[2830]
[2831]
[2832]
[2833]
[2834]
[2835]
[2836]
[2837]
[2838]
[2839]
[2840]
[2841]
[2842]
[2843]
[2844]
[2845]
[2846]
[2847]
[2848]
[2849]
[2850]
[2851]
[2852]
[2853]
[2854]
[2855]
[2856]
[2857]
[2858]
[2859]
[2860]
[2861]
[2862]
[2863]
[2864]
[2865]
[2866]
[2867]
[2868]
[2869]
[2870]
[2871]
[2872]
[2873]
[2874]
[2875]
[2876]
[2877]
[2878]
[2879]
[2880]
[2881]
[2882]
[2883]
[2884]
[2885]
[2886]
[2887]
[2888]
[2889]
[2890]
[2891]
[2892]
[2893]
[2894]
[2895]
[2896]
[2897]
[2898]
[2899]
[2900]
[2901]
[2902]
[2903]
[2904]
[2905]
[2906]
[2907]
[2908]
[2909]
[2910]
[2911]
[2912]
[2913]
[2914]
[2915]
[2916]
[2917]
[2918]
[2919]
[2920]
[2921]
[2922]
[2923]
[2924]
[2925]
[2926]
[2927]
[2928]
[2929]
[2930]
[2931]
[2932]
[2933]
[2934]
[2935]
[2936]
[2937]
[2938]
[2939]
[2940]
[2941]
[2942]
[2943]
[2944]
[2945]
[2946]
[2947]
[2948]
[2949]
[2950]
[2951]
[2952]
[2953]
[2954]
[2955]
[2956]
[2957]
[2958]
[2959]
[2960]
[2961]
[2962]
[2963]
[2964]
[2965]
[2966]
[2967]
[2968]
[2969]
[2970]
[2971]
[2972]
[2973]
[2974]
[2975]
[2976]
[2977]
[2978]
[2979]
[2980]
[2981]
[2982]
[2983]
[2984]
[2985]
[2986]
[2987]
[2988]
[2989]
[2990]
[2991]
[2992]
[2993]
[2994]
[2995]
[2996]
[2997]
[2998]
[2999]
[3000]
[3001]
[3002]
[3003]
[3004]
[3005]
[3006]
[3007]
[3008]
[3009]
[3010]
[3011]
[3012]
[3013]
[3014]
[3015]
[3016]
[3017]
[3018]
[3019]
[3020]
[3021]
[3022]
[3023]
[3024]
[3025]
[3026]
[3027]
[3028]
[3029]
[3030]
[3031]
[3032]
[3033]
[3034]
[3035]
[3036]
[3037]
[3038]
[3039]
[3040]
[3041]
[3042]
[3043]
[3044]
[3045]
[3046]
[3047]
[3048]
[3049]
[3050]
[3051]
[3052]
[3053]
[3054]
[3055]
[3056]
[3057]
[3058]
[3059]
[3060]
[3061]
[3062]
[3063]
[3064]
[3065]
[3066]
[3067]
[3068]
[3069]
[3070]
[3071]
[3072]
[3073]
[3074]
[3075]
[3076]
[3077]
[3078]
[3079]
[3080]
[3081]
[3082]
[3083]
[3084]
[3085]
[3086]
[3087]
[3088]
[3089]
[3090]
[3091]
[3092]
[3093]
[3094]
[3095]
[3096]
[3097]
[3098]
[3099]
[3100]
[3101]
[3102]
[3103]
[3104]
[3105]
[3106]
[3107]
[3108]
[3109]
[3110]
[3111]
[3112]
[3113]
[3114]
[3115]
[3116]
[3117]
[3118]
[3119]
[3120]
[3121]
[3122]
[3123]
[3124]
[3125]
[3126]
[3127]
[3128]
[3129]
[3130]
[3131]
[3132]
[3133]
[3134]
[3135]
[3136]
[3137]
[3138]
[3139]
[3140]
[3141]
[3142]
[3143]
[3144]
[3145]
[3146]
[3147]
[3148]
[3149]
[3150]
[3151]
[3152]
[3153]
[3154]
[3155]
[3156]
[3157]
[3158]
[3159]
[3160]
[3161]
[3162]
[3163]
[3164]
[3165]
[3166]
[3167]
[3168]
[3169]
[3170]
[3171]
[3172]
[3173]
[3174]
[3175]
[3176]
[3177]
[3178]
[3179]
[3180]
[3181]
[3182]
[3183]
[3184]
[3185]
[3186]
[3187]
[3188]
[3189]
[3190]
[3191]
[3192]
[3193]
[3194]
[3195]
[3196]
[3197]
[3198]
[3199]
[3200]
[3201]
[3202]
[3203]
[3204]
[3205]
[3206]
[3207]
[3208]
[3209]
[3210]
[3211]
[3212]
[3213]
[3214]
[3215]
[3216]
[3217]
[3218]
[3219]
[3220]
[3221]
[3222]
[3223]
[3224]
[3225]
[3226]
[3227]
[3228]
[3229]
[3230]
[3231]
[3232]
[3233]
[3234]
[3235]
[3236]
[3237]
[3238]
[3239]
[3240]
[3241]
[3242]
[3243]
[3244]
[3245]
[3246]
[3247]
[3248]
[3249]
[3250]
[3251]
[3252]
[3253]
[3254]
[3255]
[3256]
[3257]
[3258]
[3259]
[3260]
[3261]
[3262]
[3263]
[3264]
[3265]
[3266]
[3267]
[3268]
[3269]
[3270]
[3271]
[3272]
[3273]
[3274]
[3275]
[3276]
[3277]
[3278]
[3279]
[3280]
[3281]
[3282]
[3283]
[3284]
[3285]
[3286]
[3287]
[3288]
[3289]
[3290]
[3291]
[3292]
[3293]
[3294]
[3295]
[3296]
[3297]
[3298]
[3299]
[3300]
[3301]
[3302]
[3303]
[3304]
[3305]
[3306]
[3307]
[3308]
[3309]
[3310]
[3311]
[3312]
[3313]
[3314]
[3315]
[3316]
[3317]
[3318]
[3319]
[3320]
[3321]
[3322]
[3323]
[3324]
[3325]
[3326]
[3327]
[3328]
[3329]
[3330]
[3331]
[3332]
[3333]
[3334]
[3335]
[3336]
[3337]
[3338]
[3339]
[3340]
[3341]
[3342]
[3343]
[3344]
[3345]
[3346]
[3347]
[3348]
[3349]
[3350]
[3351]
[3352]
[3353]
[3354]
[3355]
[3356]
[3357]
[3358]
[3359]
[3360]
[3361]
[3362]
[3363]
[3364]
[3365]
[3366]
[3367]
[3368]
[3369]
[3370]
[3371]
[3372]
[3373]
[3374]
[3375]
[3376]
[3377]
[3378]
[3379]
[3380]
[3381]
[3382]
[3383]
[3384]
[3385]
[3386]
[3387]
[3388]
[3389]
[3390]
[3391]
[3392]
[3393]
[3394]
[3395]
[3396]
[3397]
[3398]
[3399]
[3400]
[3401]
[3402]
[3403]
[3404]
[3405]
[3406]
[3407]
[3408]
[3409]
[3410]
[3411]
[3412]
[3413]
[3414]
[3415]
[3416]
[3417]
[3418]
[3419]
[3420]
[3421]
[3422]
[3423]
[3424]
[3425]
[3426]
[3427]
[3428]
[3429]
[3430]
[3431]
[3432]
[3433]
[3434]
[3435]
[3436]
[3437]
[3438]
[3439]
[3440]
[3441]
[3442]
[3443]
[3444]
[3445]
[3446]
[3447]
[3448]
[3449]
[3450]
[3451]
[3452]
[3453]
[3454]
[3455]
[3456]
[3457]
[3458]
[3459]
[3460]
[3461]
[3462]
[3463]
[3464]
[3465]
[3466]
[3467]
[3468]
[3469]
[3470]
[3471]
[3472]
[3473]
[3474]
[3475]
[3476]
[3477]
[3478]
[3479]
[3480]
[3481]
[3482]
[3483]
[3484]
[3485]
[3486]
[3487]
[3488]
[3489]
[3490]
[3491]
[3492]
[3493]
[3494]
[3495]
[3496]
[3497]
[3498]
[3499]
[3500]
[3501]
[3502]
[3503]
[3504]
[3505]
[3506]
[3507]
[3508]
[3509]
[3510]
[3511]
[3512]
[3513]
[3514]
[3515]
[3516]
[3517]
[3518]
[3519]
[3520]
[3521]
[3522]
[3523]
[3524]
[3525]
[3526]
[3527]
[3528]
[3529]
[3530]
[3531]
[3532]
[3533]
[3534]
[3535]
[3536]
[3537]
[3538]
[3539]
[3540]
[3541]
[3542]
[3543]
[3544]
[3545]
[3546]
[3547]
[3548]
[3549]
[3550]
[3551]
[3552]
[3553]
[3554]
[3555]
[3556]
[3557]
[3558]
[3559]
[3560]
[3561]
[3562]
[3563]
[3564]
[3565]
[3566]
[3567]
[3568]
[3569]
[3570]
[3571]
[3572]
[3573]
[3574]
[3575]
[3576]
[3577]
[3578]
[3579]
[3580]
[3581]
[3582]
[3583]
[3584]
[3585]
[3586]
[3587]
[3588]
[3589]
[3590]
[3591]
[3592]
[3593]
[3594]
[3595]
[3596]
[3597]
[3598]
[3599]
[3600]
[3601]
[3602]
[3603]
[3604]
[3605]
[3606]
[3607]
[3608]
[3609]
[3610]
[3611]
[3612]
[3613]
[3614]
[3615]
[3616]
[3617]
[3618]
[3619]
[3620]
[3621]
[3622]
[3623]
[3624]
[3625]
[3626]
[3627]
[3628]
[3629]
[3630]
[3631]
[3632]
[3633]
[3634]
[3635]
[3636]
[3637]
[3638]
[3639]
[3640]
[3641]
[3642]
[3643]
[3644]
[3645]
[3646]
[3647]
[3648]
[3649]
[3650]
[3651]
[3652]
[3653]
[3654]
[3655]
[3656]
[3657]
[3658]
[3659]
[3660]
[3661]
[3662]
[3663]
[3664]
[3665]
[3666]
[3667]
[3668]
[3669]
[3670]
[3671]
[3672]
[3673]
[3674]
[3675]
[3676]
[3677]
[3678]
[3679]
[3680]
[3681]
[3682]
[3683]
[3684]
[3685]
[3686]
[3687]
[3688]
[3689]
[3690]
[3691]
[3692]
[3693]
[3694]
[3695]
[3696]
[3697]
[3698]
[3699]
[3700]
[3701]
[3702]
[3703]
[3704]
[3705]
[3706]
[3707]
[3708]
[3709]
[3710]
[3711]
[3712]
[3713]
[3714]
[3715]
[3716]
[3717]
[3718]
[3719]
[3720]
[3721]
[3722]
[3723]
[3724]
[3725]
[3726]
[3727]
[3728]
[3729]
[3730]
[3731]
[3732]
[3733]
[3734]
[3735]
[3736]
[3737]
[3738]
[3739]
[3740]
[3741]
[3742]
[3743]
[3744]
[3745]
[3746]
[3747]
[3748]
[3749]
[3750]
[3751]
[3752]
[3753]
[3754]
[3755]
[3756]
[3757]
[3758]
[3759]
[3760]
[3761]
[3762]
[3763]
[3764]
[3765]
[3766]
[3767]
[3768]
[3769]
[3770]
[3771]
[3772]
[3773]
[3774]
[3775]
[3776]
[3777]
[3778]
[3779]
[3780]
[3781]
[3782]
[3783]
[3784]
[3785]
[3786]
[3787]
[3788]
[3789]
[3790]
[3791]
[3792]
[3793]
[3794]
[3795]
[3796]
[3797]
[3798]
[3799]
[3800]
[3801]
[3802]
[3803]
[3804]
[3805]
[3806]
[3807]
[3808]
[3809]
[3810]
[3811]
[3812]
[3813]
[3814]
[3815]
[3816]
[3817]
[3818]
[3819]
[3820]
[3821]
[3822]
[3823]
[3824]
[3825]
[3826]
[3827]
[3828]
[3829]
[3830]
[3831]
[3832]
[3833]
[3834]
[3835]
[3836]
[3837]
[3838]
[3839]
[3840]
[3841]
[3842]
[3843]
[3844]
[3845]
[3846]
[3847]
[3848]
[3849]
[3850]
[3851]
[3852]
[3853]
[3854]
[3855]
[3856]
[3857]
[3858]
[3859]
[3860]
[3861]
[3862]
[3863]
[3864]
[3865]
[3866]
[3867]
[3868]
[3869]
[3870]
[3871]
[3872]
[3873]
[3874]
[3875]
[3876]
[3877]
[3878]
[3879]
[3880]
[3881]
[3882]
[3883]
[3884]
[3885]
[3886]
[3887]
[3888]
[3889]
[3890]
[3891]
[3892]
[3893]
[3894]
[3895]
[3896]
[3897]
[3898]
[3899]
[3900]
[3901]
[3902]
[3903]
[3904]
[3905]
[3906]
[3907]
[3908]
[3909]
[3910]
[3911]
[3912]
[3913]
[3914]
[3915]
[3916]
[3917]
[3918]
[3919]
[3920]
[3921]
[3922]
[3923]
[3924]
[3925]
[3926]
[3927]
[3928]
[3929]
[3930]
[3931]
[3932]
[3933]
[3934]
[3935]
[3936]
[3937]
[3938]
[3939]
[3940]
[3941]
[3942]
[3943]
[3944]
[3945]
[3946]
[3947]
[3948]
[3949]
[3950]
[3951]
[3952]
[3953]
[3954]
[3955]
[3956]
[3957]
[3958]
[3959]
[3960]
[3961]
[3962]
[3963]
[3964]
[3965]
[3966]
[3967]
[3968]
[3969]
[3970]
[3971]
[3972]
[3973]
[3974]
[3975]
[3976]
[3977]
[3978]
[3979]
[3980]
[3981]
[3982]
[3983]
[3984]
[3985]
[3986]
[3987]
[3988]
[3989]
[3990]
[3991]
[3992]
[3993]
[3994]
[3995]
[3996]
[3997]
[3998]
[3999]
[4000]
[4001]
[4002]
[4003]
[4004]
[4005]
[4006]
[4007]
[4008]
[4009]
[4010]
[4011]
[4012]
[4013]
[4014]
[4015]
[4016]
[4017]
[4018]
[4019]
[4020]
[4021]
[4022]
[4023]
[4024]
[4025]
[4026]
[4027]
[4028]
[4029]
[4030]
[4031]
[4032]
[4033]
[4034]
[4035]
[4036]
[4037]
[4038]
[4039]
[4040]
[4041]
[4042]
[4043]
[4044]
[4045]
[4046]
[4047]
[4048]
[4049]
[4050]
[4051]
[4052]
[4053]
[4054]
[4055]
[4056]
[4057]
[4058]
[4059]
[4060]
[4061]
[4062]
[4063]
[4064]
[4065]
[4066]
[4067]
[4068]
[4069]
[4070]
[4071]
[4072]
[4073]
[4074]
[4075]
[4076]
[4077]
[4078]
[4079]
[4080]
[4081]
[4082]
[4083]
[4084]
[4085]
[4086]
[4087]
[4088]
[4089]
[4090]
[4091]
[4092]
[4093]
[4094]
[4095]
[4096]
[4097]
[4098]
[4099]
[4100]
[4101]
[4102]
[4103]
[4104]
[4105]
[4106]
[4107]
[4108]
[4109]
[4110]
[4111]
[4112]
[4113]
[4114]
[4115]
[4116]
[4117]
[4118]
[4119]
[4120]
[4121]
[4122]
[4123]
[4124]
[4125]
[4126]
[4127]
[4128]
[4129]
[4130]
[4131]
[4132]
[4133]
[4134]
[4135]
[4136]
[4137]
[4138]
[4139]
[4140]
[4141]
[4142]
[4143]
[4144]
[4145]
[4146]
[4147]
[4148]
[4149]
[4150]
[4151]
[4152]
[4153]
[4154]
[4155]
[4156]
[4157]
[4158]
[4159]
[4160]
[4161]
[4162]
[4163]
[4164]
[4165]
[4166]
[4167]
[4168]
[4169]
[4170]
[4171]
[4172]
[4173]
[4174]
[4175]
[4176]
[4177]
[4178]
[4179]
[4180]
[4181]
[4182]
[4183]
[4184]
[4185]
[4186]
[4187]
[4188]
[4189]
[4190]
[4191]
[4192]
[4193]
[4194]
[4195]
[4196]
[4197]
[4198]
[4199]
[4200]
[4201]
[4202]
[4203]
[4204]
[4205]
[4206]
[4207]
[4208]
[4209]
[4210]
[4211]
[4212]
[4213]
[4214]
[4215]
[4216]
[4217]
[4218]
[4219]
[4220]
[4221]
[4222]
[4223]
[4224]
[4225]
[4226]
[4227]
[4228]
[4229]
[4230]
[4231]
[4232]
[4233]
[4234]
[4235]
[4236]
[4237]
[4238]
[4239]
[4240]
[4241]
[4242]
[4243]
[4244]
[4245]
[4246]
[4247]
[4248]
[4249]
[4250]
[4251]
[4252]
[4253]
[4254]
[4255]
[4256]
[4257]
[4258]
[4259]
[4260]
[4261]
[4262]
[4263]
[4264]
[4265]
[4266]
[4267]
[4268]
[4269]
[4270]
[4271]
[4272]
[4273]
[4274]
[4275]
[4276]
[4277]
[4278]
[4279]
[4280]
[4281]
[4282]
[4283]
[4284]
[4285]
[4286]
[4287]
[4288]
[4289]
[4290]
[4291]
[4292]
[4293]
[4294]
[4295]
[4296]
[4297]
[4298]
[4299]
[4300]
[4301]
[4302]
[4303]
[4304]
[4305]
[4306]
[4307]
[4308]
[4309]
[4310]
[4311]
[4312]
[4313]
[4314]
[4315]
[4316]
[4317]
[4318]
[4319]
[4320]
[4321]
[4322]
[4323]
[4324]
[4325]
[4326]
[4327]
[4328]
[4329]
[4330]
[4331]
[4332]
[4333]
[4334]
[4335]
[4336]
[4337]
[4338]
[4339]
[4340]
[4341]
[4342]
[4343]
[4344]
[4345]
[4346]
[4347]
[4348]
[4349]
[4350]
[4351]
[4352]
[4353]
[4354]
[4355]
[4356]
[4357]
[4358]
[4359]
[4360]
[4361]
[4362]
[4363]
[4364]
[4365]
[4366]
[4367]
[4368]
[4369]
[4370]
[4371]
[4372]
[4373]
[4374]
[4375]
[4376]
[4377]
[4378]
[4379]
[4380]
[4381]
[4382]
[4383]
[4384]
[4385]
[4386]
[4387]
[4388]
[4389]
[4390]
[4391]
[4392]
[4393]
[4394]
[4395]
[4396]
[4397]
[4398]
[4399]
[4400]
[4401]
[4402]
[4403]
[4404]
[4405]
[4406]
[4407]
[4408]
[4409]
[4410]
[4411]
[4412]
[4413]
[4414]
[4415]
[4416]
[4417]
[4418]
[4419]
[4420]
[4421]
[4422]
[4423]
[4424]
[4425]
[4426]
[4427]
[4428]
[4429]
[4430]
[4431]
[4432]
[4433]
[4434]
[4435]
[4436]
[4437]
[4438]
[4439]
[4440]
[4441]
[4442]
[4443]
[4444]
[4445]
[4446]
[4447]
[4448]
[4449]
[4450]
[4451]
[4452]
[4453]
[4454]
[4455]
[4456]
[4457]
[4458]
[4459]
[4460]
[4461]
[4462]
[4463]
[4464]
[4465]
[4466]
[4467]
[4468]
[4469]
[4470]
[4471]
[4472]
[4473]
[4474]
[4475]
[4476]
[4477]
[4478]
[4479]
[4480]
[4481]
[4482]
[4483]
[4484]
[4485]
[4486]
[4487]
[4488]
[4489]
[4490]
[4491]
[4492]
[4493]
[4494]
[4495]
[4496]
[4497]
[4498]
[4499]
[4500]
[4501]
[4502]
[4503]
[4504]
[4505]
[4506]
[4507]
[4508]
[4509]
[4510]
[4511]
[4512]
[4513]
[4514]
[4515]
[4516]
[4517]
[4518]
[4519]
[4520]
[4521]
[4522]
[4523]
[4524]
[4525]
[4526]
[4527]
[4528]
[4529]
[4530]
[4531]
[4532]
[4533]
[4534]
[4535]
[4536]
[4537]
[4538]
[4539]
[4540]
[4541]
[4542]
[4543]
[4544]
[4545]
[4546]
[4547]
[4548]
[4549]
[4550]
[4551]
[4552]
[4553]
[4554]
[4555]
[4556]
[4557]
[4558]
[4559]
[4560]
[4561]
[4562]
[4563]
[4564]
[4565]
[4566]
[4567]
[4568]
[4569]
[4570]
[4571]
[4572]
[4573]
[4574]
[4575]
[4576]
[4577]
[4578]
[4579]
[4580]
[4581]
[4582]
[4583]
[4584]
[4585]
[4586]
[4587]
[4588]
[4589]
[4590]
[4591]
[4592]
[4593]
[4594]
[4595]
[4596]
[4597]
[4598]
[4599]
[4600]
[4601]
[4602]
[4603]
[4604]
[4605]
[4606]
[4607]
[4608]
[4609]
[4610]
[4611]
[4612]
[4613]
[4614]
[4615]
[4616]
[4617]
[4618]
[4619]
[4620]
[4621]
[4622]
[4623]
[4624]
[4625]
[4626]
[4627]
[4628]
[4629]
[4630]
[4631]
[4632]
[4633]
[4634]
[4635]
[4636]
[4637]
[4638]
[4639]
[4640]
[4641]
[4642]
[4643]
[4644]
[4645]
[4646]
[4647]
[4648]
[4649]
[4650]
[4651]
[4652]
[4653]
[4654]
[4655]
[4656]
[4657]
[4658]
[4659]
[4660]
[4661]
[4662]
[4663]
[4664]
[4665]
[4666]
[4667]
[4668]
[4669]
[4670]
[4671]
[4672]
[4673]
[4674]
[4675]
[4676]
[4677]
[4678]
[4679]
[4680]
[4681]
[4682]
[4683]
[4684]
[4685]
[4686]
[4687]
[4688]
[4689]
[4690]
[4691]
[4692]
[4693]
[4694]
[4695]
[4696]
[4697]
[4698]
[4699]
[4700]
[4701]
[4702]
[4703]
[4704]
[4705]
[4706]
[4707]
[4708]
[4709]
[4710]
[4711]
[4712]
[4713]
[4714]
[4715]
[4716]
[4717]
[4718]
[4719]
[4720]
[4721]
[4722]
[4723]
[4724]
[4725]
[4726]
[4727]
[4728]
[4729]
[4730]
[4731]
[4732]
[4733]
[4734]
[4735]
[4736]
[4737]
[4738]
[4739]
[4740]
[4741]
[4742]
[4743]
[4744]
[4745]
[4746]
[4747]
[4748]
[4749]
[4750]
[4751]
[4752]
[4753]
[4754]
[4755]
[4756]
[4757]
[4758]
[4759]
[4760]
[4761]
[4762]
[4763]
[4764]
[4765]
[4766]
[4767]
[4768]
[4769]
[4770]
[4771]
[4772]
[4773]
[4774]
[4775]
[4776]
[4777]
[4778]
[4779]
[4780]
[4781]
[4782]
[4783]
[4784]
[4785]
[4786]
[4787]
[4788]
[4789]
[4790]
[4791]
[4792]
[4793]
[4794]
[4795]
[4796]
[4797]
[4798]
[4799]
[4800]
[4801]
[4802]
[4803]
[4804]
[4805]
[4806]
[4807]
[4808]
[4809]
[4810]
[4811]
[4812]
[4813]
[4814]
[4815]
[4816]
[4817]
[4818]
[4819]
[4820]
[4821]
[4822]
[4823]
[4824]
[4825]
[4826]
[4827]
[4828]
[4829]
[4830]
[4831]
[4832]
[4833]
[4834]
[4835]
[4836]
[4837]
[4838]
[4839]
[4840]
[4841]
[4842]
[4843]
[4844]
[4845]
[4846]
[4847]
[4848]
[4849]
[4850]
[4851]
[4852]
[4853]
[4854]
[4855]
[4856]
[4857]
[4858]
[4859]
[4860]
[4861]
[4862]
[4863]
[4864]
[4865]
[4866]
[4867]
[4868]
[4869]
[4870]
[4871]
[4872]
[4873]
[4874]
[4875]
[4876]
[4877]
[4878]
[4879]
[4880]
[4881]
[4882]
[4883]
[4884]
[4885]
[4886]
[4887]
[4888]
[4889]
[4890]
[4891]
[4892]
[4893]
[4894]
[4895]
[4896]
[4897]
[4898]
[4899]
[4900]
[4901]
[4902]
[4903]
[4904]
[4905]
[4906]
[4907]
[4908]
[4909]
[4910]
[4911]
[4912]
[4913]
[4914]
[4915]
[4916]
[4917]
[4918]
[4919]
[4920]
[4921]
[4922]
[4923]
[4924]
[4925]
[4926]
[4927]
[4928]
[4929]
[4930]
[4931]
[4932]
[4933]
[4934]
[4935]
[4936]
[4937]
[4938]
[4939]
[4940]
[4941]
[4942]
[4943]
[4944]
[4945]
[4946]
[4947]
[4948]
[4949]
[4950]
[4951]
[4952]
[4953]
[4954]
[4955]
[4956]
[4957]
[4958]
[4959]
[4960]
[4961]
[4962]
[4963]
[4964]
[4965]
[4966]
[4967]
[4968]
[4969]
[4970]
[4971]
[4972]
[4973]
[4974]
[4975]
[4976]
[4977]
[4978]
[4979]
[4980]
[4981]
[4982]
[4983]
[4984]
[4985]
[4986]
[4987]
[4988]
[4989]
[4990]
[4991]
[4992]
[4993]
[4994]
[4995]
[4996]
[4997]
[4998]
[4999]
[5000]
[5001]
[5002]
[5003]
[5004]
[5005]
[5006]
[5007]
[5008]
[5009]
[5010]
[5011]
[5012]
[5013]
[5014]
[5015]
[5016]
[5017]
[5018]
[5019]
[5020]
[5021]
[5022]
[5023]
[5024]
[5025]
[5026]
[5027]
[5028]
[5029]
[5030]
[5031]
[5032]
[5033]
[5034]
[5035]
[5036]
[5037]
[5038]
[5039]
[5040]
[5041]
[5042]
[5043]
[5044]
[5045]
[5046]
[5047]
[5048]
[5049]
[5050]
[5051]
[5052]
[5053]
[5054]
[5055]
[5056]
[5057]
[5058]
[5059]
[5060]
[5061]
[5062]
[5063]
[5064]
[5065]
[5066]
[5067]
[5068]
[5069]
[5070]
[5071]
[5072]
[5073]
[5074]
[5075]
[5076]
[5077]
[5078]
[5079]
[5080]
[5081]
[5082]
[5083]
[5084]
[5085]
[5086]
[5087]
[5088]
[5089]
[5090]
[5091]
[5092]
[5093]
[5094]
[5095]
[5096]
[5097]
[5098]
[5099]
[5100]
[5101]
[5102]
[5103]
[5104]
[5105]
[5106]
[5107]
[5108]
[5109]
[5110]
[5111]
[5112]
[5113]
[5114]
[5115]
[5116]
[5117]
[5118]
[5119]
[5120]
[5121]
[5122]
[5123]
[5124]
[5125]
[5126]
[5127]
[5128]
[5129]
[5130]
[5131]
[5132]
[5133]
[5134]
[5135]
[5136]
[5137]
[5138]
[5139]
[5140]
[5141]
[5142]
[5143]
[5144]
[5145]
[5146]
[5147]
[5148]
[5149]
[5150]
[5151]
[5152]
[5153]
[5154]
[5155]
[5156]
[5157]
[5158]
[5159]
[5160]
[5161]
[5162]
[5163]
[5164]
[5165]
[5166]
[5167]
[5168]
[5169]
[5170]
[5171]
[5172]
[5173]
[5174]
[5175]
[5176]
[5177]
[5178]
[5179]
[5180]
[5181]
[5182]
[5183]
[5184]
[5185]
[5186]
[5187]
[5188]
[5189]
[5190]
[5191]
[5192]
[5193]
[5194]
[5195]
[5196]
[5197]
[5198]
[5199]
[5200]
[5201]
[5202]
[5203]
[5204]
[5205]
[5206]
[5207]
[5208]
[5209]
[5210]
[5211]
[5212]
[5213]
[5214]
[5215]
[5216]
[5217]
[5218]
[5219]
[5220]
[5221]
[5222]
[5223]
[5224]
[5225]
[5226]
[5227]
[5228]
[5229]
[5230]
[5231]
[5232]
[5233]
[5234]
[5235]
[5236]
[5237]
[5238]
[5239]
[5240]
[5241]
[5242]
[5243]
[5244]
[5245]
[5246]
[5247]
[5248]
[5249]
[5250]
[5251]
[5252]
[5253]
[5254]
[5255]
[5256]
[5257]
[5258]
[5259]
[5260]
[5261]
[5262]
[5263]
[5264]
[5265]
[5266]
[5267]
[5268]
[5269]
[5270]
[5271]
[5272]
[5273]
[5274]
[5275]
[5276]
[5277]
[5278]
[5279]
[5280]
[5281]
[5282]
[5283]
[5284]
[5285]
[5286]
[5287]
[5288]
[5289]
[5290]
[5291]
[5292]
[5293]
[5294]
[5295]
[5296]
[5297]
[5298]
[5299]
[5300]
[5301]
[5302]
[5303]
[5304]
[5305]
[5306]
[5307]
[5308]
[5309]
[5310]
[5311]
[5312]
[5313]
[5314]
[5315]
[5316]
[5317]
[5318]
[5319]
[5320]
[5321]
[5322]
[5323]
[5324]
[5325]
[5326]
[5327]
[5328]
[5329]
[5330]
[5331]
[5332]
[5333]
[5334]
[5335]
[5336]
[5337]
[5338]
[5339]
[5340]
[5341]
[5342]
[5343]
[5344]
[5345]
[5346]
[5347]
[5348]
[5349]
[5350]
[5351]
[5352]
[5353]
[5354]
[5355]
[5356]
[5357]
[5358]
[5359]
[5360]
[5361]
[5362]
[5363]
[5364]
[5365]
[5366]
[5367]
[5368]
[5369]
[5370]
[5371]
[5372]
[5373]
[5374]
[5375]
[5376]
[5377]
[5378]
[5379]
[5380]
[5381]
[5382]
[5383]
[5384]
[5385]
[5386]
[5387]
[5388]
[5389]
[5390]
[5391]
[5392]
[5393]
[5394]
[5395]
[5396]
[5397]
[5398]
[5399]
[5400]
[5401]
[5402]
[5403]
[5404]
[5405]
[5406]
[5407]
[5408]
[5409]
[5410]
[5411]
[5412]
[5413]
[5414]
[5415]
[5416]
[5417]
[5418]
[5419]
[5420]
[5421]
[5422]
[5423]
[5424]
[5425]
[5426]
[5427]
[5428]
[5429]
[5430]
[5431]
[5432]
[5433]
[5434]
[5435]
[5436]
[5437]
[5438]
[5439]
[5440]
[5441]
[5442]
[5443]
[5444]
[5445]
[5446]
[5447]
[5448]
[5449]
[5450]
[5451]
[5452]
[5453]
[5454]
[5455]
[5456]
[5457]
[5458]
[5459]
[5460]
[5461]
[5462]
[5463]
[5464]
[5465]
[5466]
[5467]
[5468]
[5469]
[5470]
[5471]
[5472]
[5473]
[5474]
[5475]
[5476]
[5477]
[5478]
[5479]
[5480]
[5481]
[5482]
[5483]
[5484]
[5485]
[5486]
[5487]
[5488]
[5489]
[5490]
[5491]
[5492]
[5493]
[5494]
[5495]
[5496]
[5497]
[5498]
[5499]
[5500]
[5501]
[5502]
[5503]
[5504]
[5505]
[5506]
[5507]
[5508]
[5509]
[5510]
[5511]
[5512]
[5513]
[5514]
[5515]
[5516]
[5517]
[5518]
[5519]
[5520]
[5521]
[5522]
[5523]
[5524]
[5525]
[5526]
[5527]
[5528]
[5529]
[5530]
[5531]
[5532]
[5533]
[5534]
[5535]
[5536]
[5537]
[5538]
[5539]
[5540]
[5541]
[5542]
[5543]
[5544]
[5545]
[5546]
[5547]
[5548]
[5549]
[5550]
[5551]
[5552]
[5553]
[5554]
[5555]
[5556]
[5557]
[5558]
[5559]
[5560]
[5561]
[5562]
[5563]
[5564]
[5565]
[5566]
[5567]
[5568]
[5569]
[5570]
[5571]
[5572]
[5573]
[5574]
[5575]
[5576]
[5577]
[5578]
[5579]
[5580]
[5581]
[5582]
[5583]
[5584]
[5585]
[5586]
[5587]
[5588]
[5589]
[5590]
[5591]
[5592]
[5593]
[5594]
[5595]
[5596]
[5597]
[5598]
[5599]
[5600]
[5601]
[5602]
[5603]
[5604]
[5605]
[5606]
[5607]
[5608]
[5609]
[5610]
[5611]
[5612]
[5613]
[5614]
[5615]
[5616]
[5617]
[5618]
[5619]
[5620]
[5621]
[5622]
[5623]
[5624]
[5625]
[5626]
[5627]
[5628]
[5629]
[5630]
[5631]
[5632]
[5633]
[5634]
[5635]
[5636]
[5637]
[5638]
[5639]
[5640]
[5641]
[5642]
[5643]
[5644]
[5645]
[5646]
[5647]
[5648]
[5649]
[5650]
[5651]
[5652]
[5653]
[5654]
[5655]
[5656]
[5657]
[5658]
[5659]
[5660]
[5661]
[5662]
[5663]
[5664]
[5665]
[5666]
[5667]
[5668]
[5669]
[5670]
[5671]
[5672]
[5673]
[5674]
[5675]
[5676]
[5677]
[5678]
[5679]
[5680]
[5681]
[5682]
[5683]
[5684]
[5685]
[5686]
[5687]
[5688]
[5689]
[5690]
[5691]
[5692]
[5693]
[5694]
[5695]
[5696]
[5697]
[5698]
[5699]
[5700]
[5701]
[5702]
[5703]
[5704]
[5705]
[5706]
[5707]
[5708]
[5709]
[5710]
[5711]
[5712]
[5713]
[5714]
[5715]
[5716]
[5717]
[5718]
[5719]
[5720]
[5721]
[5722]
[5723]
[5724]
[5725]
[5726]
[5727]
[5728]
[5729]
[5730]
[5731]
[5732]
[5733]
[5734]
[5735]
[5736]
[5737]
[5738]
[5739]
[5740]
[5741]
[5742]
[5743]
[5744]
[5745]
[5746]
[5747]
[5748]
[5749]
[5750]
[5751]
[5752]
[5753]
[5754]
[5755]
[5756]
[5757]
[5758]
[5759]
[5760]
[5761]
[5762]
[5763]
[5764]
[5765]
[5766]
[5767]
[5768]
[5769]
[5770]
[5771]
[5772]
[5773]
[5774]
[5775]
[5776]
[5777]
[5778]
[5779]
[5780]
[5781]
[5782]
[5783]
[5784]
[5785]
[5786]
[5787]
[5788]
[5789]
[5790]
[5791]
[5792]
[5793]
[5794]
[5795]
[5796]
[5797]
[5798]
[5799]
[5800]
[5801]
[5802]
[5803]
[5804]
[5805]
[5806]
[5807]
[5808]
[5809]
[5810]
[5811]
[5812]
[5813]
[5814]
[5815]
[5816]
[5817]
[5818]
[5819]
[5820]
[5821]
[5822]
[5823]
[5824]
[5825]
[5826]
[5827]
[5828]
[5829]
[5830]
[5831]
[5832]
[5833]
[5834]
[5835]
[5836]
[5837]
[5838]
[5839]
[5840]
[5841]
[5842]
[5843]
[5844]
[5845]
[5846]
[5847]
[5848]
[5849]
[5850]
[5851]
[5852]
[5853]
[5854]
[5855]
[5856]
[5857]
[5858]
[5859]
[5860]
[5861]
[5862]
[5863]
[5864]
[5865]
[5866]
[5867]
[5868]
[5869]
[5870]
[5871]
[5872]
[5873]
[5874]
[5875]
[5876]
[5877]
[5878]
[5879]
[5880]
[5881]
[5882]
[5883]
[5884]
[5885]
[5886]
[5887]
[5888]
[5889]
[5890]
[5891]
[5892]
[5893]
[5894]
[5895]
[5896]
[5897]
[5898]
[5899]
[5900]
[5901]
[5902]
[5903]
[5904]
[5905]
[5906]
[5907]
[5908]
[5909]
[5910]
[5911]
[5912]
[5913]
[5914]
[5915]
[5916]
[5917]
[5918]
[5919]
[5920]
[5921]
[5922]
[5923]
[5924]
[5925]
[5926]
[5927]
[5928]
[5929]
[5930]
[5931]
[5932]
[5933]
[5934]
[5935]
[5936]
[5937]
[5938]
[5939]
[5940]
[5941]
[5942]
[5943]
[5944]
[5945]
[5946]
[5947]
[5948]
[5949]
[5950]
[5951]
[5952]
[5953]
[5954]
[5955]
[5956]
[5957]
[5958]
[5959]
[5960]
[5961]
[5962]
[5963]
[5964]
[5965]
[5966]
[5967]
[5968]
[5969]
[5970]
[5971]
[5972]
[5973]
[5974]
[5975]
[5976]
[5977]
[5978]
[5979]
[5980]
[5981]
[5982]
[5983]
[5984]
[5985]
[5986]
[5987]
[5988]
[5989]
[5990]
[5991]
[5992]
[5993]
[5994]
[5995]
[5996]
[5997]
[5998]
[5999]
[6000]
[6001]
[6002]
[6003]
[6004]
[6005]
[6006]
[6007]
[6008]
[6009]
[6010]
[6011]
[6012]
[6013]
[6014]
[6015]
[6016]
[6017]
[6018]
[6019]
[6020]
[6021]
[6022]
[6023]
[6024]
[6025]
[6026]
[6027]
[6028]
[6029]
[6030]
[6031]
[6032]
[6033]
[6034]
[6035]
[6036]
[6037]
[6038]
[6039]
[6040]
[6041]
[6042]
[6043]
[6044]
[6045]
[6046]
[6047]
[6048]
[6049]
[6050]
[6051]
[6052]
[6053]
[6054]
[6055]
[6056]
[6057]
[6058]
[6059]
[6060]
[6061]
[6062]
[6063]
[6064]
[6065]
[6066]
[6067]
[6068]
[6069]
[6070]
[6071]
[6072]
[6073]
[6074]
[6075]
[6076]
[6077]
[6078]
[6079]
[6080]
[6081]
[6082]
[6083]
[6084]
[6085]
[6086]
[6087]
[6088]
[6089]
[6090]
[6091]
[6092]
[6093]
[6094]
[6095]
[6096]
[6097]
[6098]
[6099]
[6100]
[6101]
[6102]
[6103]
[6104]
[6105]
[6106]
[6107]
[6108]
[6109]
[6110]
[6111]
[6112]
[6113]
[6114]
[6115]
[6116]
[6117]
[6118]
[6119]
[6120]
[6121]
[6122]
[6123]
[6124]
[6125]
[6126]
[6127]
[6128]
[6129]
[6130]
[6131]
[6132]
[6133]
[6134]
[6135]
[6136]
[6137]
[6138]
[6139]
[6140]
[6141]
[6142]
[6143]
[6144]
[6145]
[6146]
[6147]
[6148]
[6149]
[6150]
[6151]
[6152]
[6153]
[6154]
[6155]
[6156]
[6157]
[6158]
[6159]
[6160]
[6161]
[6162]
[6163]
[6164]
[6165]
[6166]
[6167]
[6168]
[6169]
[6170]
[6171]
[6172]
[6173]
[6174]
[6175]
[6176]
[6177]
[6178]
[6179]
[6180]
[6181]
[6182]
[6183]
[6184]
[6185]
[6186]
[6187]
[6188]
[6189]
[6190]
[6191]
[6192]
[6193]
[6194]
[6195]
[6196]
[6197]
[6198]
[6199]
[6200]
[6201]
[6202]
[6203]
[6204]
[6205]
[6206]
[6207]
[6208]
[6209]
[6210]
[6211]
[6212]
[6213]
[6214]
[6215]
[6216]
[6217]
[6218]
[6219]
[6220]
[6221]
[6222]
[6223]
[6224]
[6225]
[6226]
[6227]
[6228]
[6229]
[6230]
[6231]
[6232]
[6233]
[6234]
[6235]
[6236]
[6237]
[6238]
[6239]
[6240]
[6241]
[6242]
[6243]
[6244]
[6245]
[6246]
[6247]
[6248]
[6249]
[6250]
[6251]
[6252]
[6253]
[6254]
[6255]
[6256]
[6257]
[6258]
[6259]
[6260]
[6261]
[6262]
[6263]
[6264]
[6265]
[6266]
[6267]
[6268]
[6269]
[6270]
[6271]
[6272]
[6273]
[6274]
[6275]
[6276]
[6277]
[6278]
[6279]
[6280]
[6281]
[6282]
[6283]
[6284]
[6285]
[6286]
[6287]
[6288]
[6289]
[6290]
[6291]
[6292]
[6293]
[6294]
[6295]
[6296]
[6297]
[6298]
[6299]
[6300]
[6301]
[6302]
[6303]
[6304]
[6305]
[6306]
[6307]
[6308]
[6309]
[6310]
[6311]
[6312]
[6313]
[6314]
[6315]
[6316]
[6317]
[6318]
[6319]
[6320]
[6321]
[6322]
[6323]
[6324]
[6325]
[6326]
[6327]
[6328]
[6329]
[6330]
[6331]
[6332]
[6333]
[6334]
[6335]
[6336]
[6337]
[6338]
[6339]
[6340]
[6341]
[6342]
[6343]
[6344]
[6345]
[6346]
[6347]
[6348]
[6349]
[6350]
[6351]
[6352]
[6353]
[6354]
[6355]
[6356]
[6357]
[6358]
[6359]
[6360]
[6361]
[6362]
[6363]
[6364]
[6365]
[6366]
[6367]
[6368]
[6369]
[6370]
[6371]
[6372]
[6373]
[6374]
[6375]
[6376]
[6377]
[6378]
[6379]
[6380]
[6381]
[6382]
[6383]
[6384]
[6385]
[6386]
[6387]
[6388]
[6389]
[6390]
[6391]
[6392]
[6393]
[6394]
[6395]
[6396]
[6397]
[6398]
[6399]
[6400]
[6401]
[6402]
[6403]
[6404]
[6405]
[6406]
[6407]
[6408]
[6409]
[6410]
[6411]
[6412]
[6413]
[6414]
[6415]
[6416]
[6417]
[6418]
[6419]
[6420]
[6421]
[6422]
[6423]
[6424]
[6425]
[6426]
[6427]
[6428]
[6429]
[6430]
[6431]
[6432]
[6433]
[6434]
[6435]
[6436]
[6437]
[6438]
[6439]
[6440]
[6441]
[6442]
[6443]
[6444]
[6445]
[6446]
[6447]
[6448]
[6449]
[6450]
[6451]
[6452]
[6453]
[6454]
[6455]
[6456]
[6457]
[6458]
[6459]
[6460]
[6461]
[6462]
[6463]
[6464]
[6465]
[6466]
[6467]
[6468]
[6469]
[6470]
[6471]
[6472]
[6473]
[6474]
[6475]
[6476]
[6477]
[6478]
[6479]
[6480]
[6481]
[6482]
[6483]
[6484]
[6485]
[6486]
[6487]
[6488]
[6489]
[6490]
[6491]
[6492]
[6493]
[6494]
[6495]
[6496]
[6497]
[6498]
[6499]
[6500]
[6501]
[6502]
[6503]
[6504]
[6505]
[6506]
[6507]
[6508]
[6509]
[6510]
[6511]
[6512]
[6513]
[6514]
[6515]
[6516]
[6517]
[6518]
[6519]
[6520]
[6521]
[6522]
[6523]
[6524]
[6525]
[6526]
[6527]
[6528]
[6529]
[6530]
[6531]
[6532]
[6533]
[6534]
[6535]
[6536]
[6537]
[6538]
[6539]
[6540]
[6541]
[6542]
[6543]
[6544]
[6545]
[6546]
[6547]
[6548]
[6549]
[6550]
[6551]
[6552]
[6553]
[6554]
[6555]
[6556]
[6557]
[6558]
[6559]
[6560]
[6561]
[6562]
[6563]
[6564]
[6565]
[6566]
[6567]
[6568]
[6569]
[6570]
[6571]
[6572]
[6573]
[6574]
[6575]
[6576]
[6577]
[6578]
[6579]
[6580]
[6581]
[6582]
[6583]
[6584]
[6585]
[6586]
[6587]
[6588]
[6589]
[6590]
[6591]
[6592]
[6593]
[6594]
[6595]
[6596]
[6597]
[6598]
[6599]
[6600]
[6601]
[6602]
[6603]
[6604]
[6605]
[6606]
[6607]
[6608]
[6609]
[6610]
[6611]
[6612]
[6613]
[6614]
[6615]
[6616]
[6617]
[6618]
[6619]
[6620]
[6621]
[6622]
[6623]
[6624]
[6625]
[6626]
[6627]
[6628]
[6629]
[6630]
[6631]
[6632]
[6633]
[6634]
[6635]
[6636]
[6637]
[6638]
[6639]
[6640]
[6641]
[6642]
[6643]
[6644]
[6645]
[6646]
[6647]
[6648]
[6649]
[6650]
[6651]
[6652]
[6653]
[6654]
[6655]
[6656]
[6657]
[6658]
[6659]
[6660]
[6661]
[6662]
[6663]
[6664]
[6665]
[6666]
[6667]
[6668]
[6669]
[6670]
[6671]
[6672]
[6673]
[6674]
[6675]
[6676]
[6677]
[6678]
[6679]
[6680]
[6681]
[6682]
[6683]
[6684]
[6685]
[6686]
[6687]
[6688]
[6689]
[6690]
[6691]
[6692]
[6693]
[6694]
[6695]
[6696]
[6697]
[6698]
[6699]
[6700]
[6701]
[6702]
[6703]
[6704]
[6705]
[6706]
[6707]
[6708]
[6709]
[6710]
[6711]
[6712]
[6713]
[6714]
[6715]
[6716]
[6717]
[6718]
[6719]
[6720]
[6721]
[6722]
[6723]
[6724]
[6725]
[6726]
[6727]
[6728]
[6729]
[6730]
[6731]
[6732]
[6733]
[6734]
[6735]
[6736]
[6737]
[6738]
[6739]
[6740]
[6741]
[6742]
[6743]
[6744]
[6745]
[6746]
[6747]
[6748]
[6749]
[6750]
[6751]
[6752]
[6753]
[6754]
[6755]
[6756]
[6757]
[6758]
[6759]
[6760]
[6761]
[6762]
[6763]
[6764]
[6765]
[6766]
[6767]
[6768]
[6769]
[6770]
[6771]
[6772]
[6773]
[6774]
[6775]
[6776]
[6777]
[6778]
[6779]
[6780]
[6781]
[6782]
[6783]
[6784]
[6785]
[6786]
[6787]
[6788]
[6789]
[6790]
[6791]
[6792]
[6793]
[6794]
[6795]
[6796]
[6797]
[6798]
[6799]
[6800]
[6801]
[6802]
[6803]
[6804]
[6805]
[6806]
[6807]
[6808]
[6809]
[6810]
[6811]
[6812]
[6813]
[6814]
[6815]
[6816]
[6817]
[6818]
[6819]
[6820]
[6821]
[6822]
[6823]
[6824]
[6825]
[6826]
[6827]
[6828]
[6829]
[6830]
[6831]
[6832]
[6833]
[6834]
[6835]
[6836]
[6837]
/*****************************************************************************/
/*
                                CgiLib.c

For C Language scripts these functions provide a number of common CGI
activities as a simple object code module.  One objective is the reasonably
transparent, core support for WASD CGI and CGIplus, VMS Apache (CSWS),
Purveyor, "vanilla" CGI (e.g. Netscape FastTrack), and OSU DECnet-based
scripting.  Of course all this is basically from the perspective of the WASD
environment.

THESE ROUTINES ARE NOT DESIGNED TO BE THREAD-SAFE!

*** NOTE ***
------------
As of version 1.7 CGILIB only supports compilation into an object module as
described immediately below.  IT NO LONGER SUPPORTS THE DIRECT #include!
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As of version 1.5 CGILIB was reworked to allow compilation into an object
module by defining the macro CGILIB_OBJECT_MODULE for inclusion at link-time
rather than at compilation time.  This is obviously a more elegant way to
build code and the author can only plead being brain-dead during the period it
exploded from a handful of original functions just separated from application
code for convenience to the far more extensive collection currently present. 
It *should* also allow for the pre-1.5 behaviour of source-code-inclusion for
backward compatibility - but no absolute guarantees!  A number of additional
functions have been provided to allow 'Set'ting of run-time characteristics
that previously could be pre-configured at compilation using macros.  See a
number of WASD scripts for hints of how to use as an object module.


USING IN YOUR CODE
------------------
Build as an object module, It may then be linked against the rest of the
application.

  $ CC CGILIB /DECC /STANDARD=RELAXED_ANSI /INCLUDE=[]

Once compiled it may linked as an object module directly

  $ LINK /EXEC=HT_EXE:APPLICATION.EXE APPLICATION,[.OBJ_AXP]CGILIB.OBJ

or if it has been placed into an object library

  $ LINK /EXEC=HT_EXE:APPLICATION.EXE APPLICATION,[.OBJ_AXP]CGILIB.OLB/LIBRARY

or to the WASD_CGILIBSHR32 sharable image (if installed and defined)

  $ LINK /EXEC=HT_EXE:APPLICATION.EXE APPLICATION,SYS$INPUT/OPTIONS
  WASD_CGILIBSHR32/SHARE


To change the default size of the CGIplus variable stream record buffer add an
appropriate definition before #including the CGILIB header file, as shown in
the following example:

  #define CGILIB_CGIPLUS_RECORD_SIZE 4096


FUNCTIONALITY 
-------------
Functions and global storage beginning 'CgiLib__' are for internal CGILIB use
only, and should not directly be called by script code.


SCRIPTING ENVIRONMENT
---------------------
A number of functions are used to initialize and support behaviour in the
various scripting environments.  It should always be called before the use of
any other functions.

  void CgiLibEnvironmentInit (int argc,
                              char *argv[],
                              int DoResponseCgi);

The above function initializes the scripting environment detected according to
various environment variables characteristic to each.  The 'argc' and 'argv'
standard C command-line parameters are only needed if the script is to support
the OSU environment (zero and NULL may be substituted otherwise).  Parameter
'DoResponseCgi' "forces" the functions to return a CGI response regardless of
which environment it is executing in.

  int CgiLibEnvironmentIsApache ();
  int CgiLibEnvironmentIsCgi ();
  int CgiLibEnvironmentIsCgiPlus ();
  int CgiLibEnvironmentIsWasd ();
  int CgiLibEnvironmentWasdVersion ();
  int CgiLibEnvironmentIsOsu ();
  int CgiLibEnvironmentIsPurveyor ();

Each of these functions returns true or false depending on which environment
the script is executing in.

  CgiLibEnvironmentBinaryOut ();
  CgiLibEnvironmentRecordOut ();

The above functions ensure the <stdout> stream is appropriately set for either
binary (non-record, no translation of newline characters, etc.) or standard
output.  Generally WASD and OSU always function in binary mode while standard
CGI environments normally accept record-oriented output.  Binary mode should
always be used for non-textual output.

  char* CgiLibEnvironmentName ();
  char* CgiLibEnvironmentVersion ();
  char* CgiLibEnvironmentSetVarNone (char*);
  int CgiLibEnvironmentSetDebug (int);
  int CgiLibEnvironmentWasdVersion ();

These five functions set the run-time characteristsic of the CGILIB
environment.  The first and second return a string identifying the server and
CGILIB environment.  The third accepts a pointer to either NULL or a string
(most usually ""). The fourth turns CGILIB debug on or off.  The fifth returns
an integer representing the WASD server version (e.g. 80201 for v8.2.1). 

  void CgiLibInit (int argc, char* argv[], void ProcessRequest(void));

This function can be used to execute a script function without the script
needing to concern itself with whether it's been called in a standard CGI or
CGIplus environment.


REQUEST RESPONSES
-----------------
These functions allow HTTP response headers and defacto WASD error and
"success" report pages to be generated.

  int CgiLibResponseHeader (int StatusCode,
                            char *ContentType,
                            ...);

The above function generates an HTTP response header.  In most environments
these will be CGI-compliant responses.  This allows the server to provide
whatever additional header fields it deems required.  On an OSU server this
will always be a full NPH HTTP response.  This function also handles 302
(redirection, see also  'CgiLibResponseRedirect()') and 401 (authentication)
responses.  Supply NULL for 'ContentType' parameter and the location URL or
authentication header line as parameter three.  The third can be a 'printf()'
format string with associated parameter supplied following.  This can also be
used to supply additional newline terminated header lines into the response. 
If a specific character set is required, begin the format string with ";
charset=" and then the charset string, followed by a newline character.

  int CgiLibResponseRedirect (char *FormatString, ...);

This function generates an HTTP 302 redirect response.  If the format string
begins  "%!" then the redirect is made absolute with the appropriate local
server host name and if necessary port prefixing whatever are supplied as
parameters.  If the "%!" does not precede the format string then it can either
be a full absolute or local redirection URL, it's just appended to the
"Location: " field name.  The format string can be for a 'printf()' with
associated parameters supplied.  Strings fed to this function must be
URL-encoded if necessary.

  int CgiLibResponseError (char *SrcFileName,
                           int SrcLineNumber,
                           int StatusValue,
                           char *FormatString,
                           ...);

Generates a WASD format error report.  If 'StatusValue' is non-zero then it is
assumed to be a VMS status code and a message is generated from it.  If zero
then only the format string is used.  The format string may be a plain-text
message or contain 'printf()' formatting characters with any associated
parameters. 

  int CgiLibResponseSuccess (char *FormatString, ...);

Generates a "success" report in the usual WASD format.  The format string may
be a plain-text message or contain 'printf()' formatting characters with any
associated parameters. 

  int CgiLibResponseGetStatus ()

Returns the HTTP response status (e.g. 200, 404) after being set by response
generation (or 0).

  char* CgiLibResponseSetBody (char *string)
  char* CgiLibResponseSetCharset (char *string)
  char* CgiLibResponseSetDefaultCharset (char *string)
  char* CgiLibResponseSetErrorMessage (char *string)
  int CgiLibResponseSetErrorStatus (int status)
  char* CgiLibResponseSetErrorTitle (char *string)
  char* CgiLibResponseSetErrorInfo (char *string)
  char* CgiLibResponseSetSoftwareID (char *string)
  char* CgiLibResponseSetSuccessMessage (char *string)
  int CgiLibResponseSetSuccessStatus (int status)
  char* CgiLibResponseSetSuccessTitle (char *string)

The above collection of functions allow various response strings and status
codes to be set at run-time.  Note that these functions do not allocate
storage, whatever they are called with must point to something permanent. 

  int CgiLibResponseSetBufferRecords (int);
  int CgiLibResponseSetRecordMode (int);
  int CgiLibResponseSetStreamMode (int);

Tell the WASD server that these CGI response characteristics should be
enabled/disabled.  Must be used prior to CgiLibResponseHeader().  Returns
previous value.


NOTE ON CSWS V1.0-1 CGI RESPONSE
--------------------------------
12-JAN-2001: There seems to be a bug in the Apache 1.3.12 CGI engine, confirmed
by Compaq VMS Engineering with the ASF.  If the request has a "Pragma:
no-cache" field (i.e. [RELOAD] button) and the script returns a "Status: nnn"
response status line, with a trailing "Last-Modified: date" field, the CSWS
server returns a header but no body.  Although I haven't tried all the
in-and-outs of possible field combinations this one's a sure winner.

Hence this library introduces a fudge, not returning the "Status: nnn" field
for responses where it is not absolutely required, when Apache is detected. 
This reults in a "Content-Type: xxxxx", "Location: URL", etc., being returned
as the first line and seems to work well enough and without the original
problem.


CGI VARIABLES
-------------
This library provides a simple, uniform mechanism for access to CGI variable
values transparently in the WASD CGI and CGIplus environments, as well as OSU
(via the request dialog phase) and "vanilla" CGI environments (e.g. Netscape
FastTrack).  CGI variables names are always assumed to be in upper-case and to
be preceded by "WWW_".  It will automatically detect and adjust behaviour
according to whether the CGI variables are actually prefixed with "WWW_" (as
with WASD, OSU and Purveyor) or not (as with Netscape FastTrack).

  char* CgiVar (char *VarName);
  char* CgiLibVar (char *VarName);

Simply call the CgiLibVar() function (or CgiVar() for backward-compatibility)
with the CGI variable name to be accessed and if that CGI variable exists a
pointer to the value will be returned.  Non-existant variables return
CGILIB_NONE, which is by default an empty string ("").  The values pointed to
should NOT be modified in any way (copy the value if this is required).

  char* CgiLibVarNull (char *VarName);

Function CgiLibVarNull() will always return NULL if the CGI variable does not
exist, or a pointer to the variable string value.  This may be used to
differentiate between a CGI variable containing an empty value and not actually
existing at all.

  int CgiLibVarByDesc
  (
  struct dsc$descriptor *NameDsc,
  struct dsc$descriptor *ValueDsc,
  short int *Length
  );

This function may be used to obtain CGI variables using VMS descriptors. 
Returns zero and a space-filled value descriptor if the variable does not
exist, one and a space padded value if it does.  The 'Length' address parameter
is optional and if supplied the actual length of the variable value string
(excluding any padding spaces) is set.


CGIPLUS
-------
In the WASD CGIplus environment supplying an empty variable name,
CgiLibVar(""), will cause the function to block until the arrival of a request,
upon which it just returns a CGILIB_NONE pointer, allowing start-of-request
synchronization.  This also resets the variables in preparation for reading the
CGI data stream of the next request, an alternative to calling with a NULL
parameter at the end of request processing.

Supplying a wildcard variable name, CgiLibVar ("*"), returns each CGIplus
variable 'name=value' string in turn, with end-of-variables being indicated by
a NULL pointer.

  CgiLibCgiPlusEOF ();

This function will output a suitably flushed (to make it a single record)
CGIplus end-of-file indicator telling the server the script is finished
servicing the response.

  CgiLibCgiPlusESC ();
  CgiLibCgiPlusEOT ();

These two functions output records to delimit the beginning and and
(respectively) of a CGIplus callout.

  void CgiLibCgiPlusInGets (char *String, int SizeOfString);

This CGIplus function allows a single string to be read from the CGIPLUSIN
stream.  This is intended for a script in callout mode to read a single record
response from the server.  If the record read overflows the string buffer
provided it is truncated and null-terminated.

  char *CgiLibCgiPlusCallout (char *Format, ...);

The above function allows a CGIplus callout to be performed with a format
string and variable number of arguments.  If the format string (callout) does
not begin with a '!' or '#' (no response expected) then a callout response is
read into static storage and and a pointer to that returned.

  void CgiLibCgiPlusSetVarRecord ();
  void CgiLibCgiPlusSetVarStruct ();

The two functions above switch the CGI variable stream between 'record' mode
(the default, where each CGI variable occupies an individual I/O on CGIPLUSIN
stream) and 'struct' mode (the CGI variables are I/Oed as a single, binary
structure).  'Struct' mode is SIGNIFICANTLY more efficient and has lower
latency.  The WASD HTTPd version is detected and for 7.2 and following the
stream is automatically switched to 'struct' mode if neither of the functions
have been used to explicitly set the mode.  CGILIB may also be forced to retain
'record' mode by creating the environment variable CGILIB_CGIPLUS_VAR_RECORD
(e.g. define it as a logical, assign symbol).  This facility may be useful for
performance comparisons, etc.  See [SRC.HTTPD]CGI.C for information on the
internal structure of the 'struct' stream.

Transfering the CGIplus variables as a single structure (rather than as
per-variable records) can double the throughput!!  Demonstrated using the
[SRC.CGIPLUS]CGIPLUSTEST.C program.  This indicates that there is much less
than half the overhead for performing this using the 'struct' method!


FORM-ENCODED PARSE
------------------

  char* CgiLibFormEncodedParse (char *String, int *Context);

This function parses a "application/x-www-form-urlencoded" string into it's
decoded, constituent name and value pairs.  It can be passed *any* urlencoded
string including QUERY_STRING CGI variables and POSTed request bodies.  It
returns a dynamically allocated string comprising a "name=value" pair, in much
the same format as a CgiLibVar("*") call.  When the form fields are exhausted
it returns a pointer to NULL.  The form field name is not prefixed by
"WWW_FORM", or anything else.  This buffer is reused with each call and so
should not be modified, any contents should be copied as with CgiLibVar()
constraints.  The 'Context' parameter should be initialized to zero before the
initial call.  At the end of a parse it is reinitialized to zero.


URL-DECODE
----------

  int CgiLibUrlDecode (char *String);

Decodes a URL-encoded string (i.e. string containing "+" substituted for spaces
and other forbidden characters encoded using the "%xx" hexadecimal scheme). 
Resultant string is always the same size or smaller so it can be done IN-SITU! 
Returns the size of the resultant string.


URL-ENCODE
----------

  int CgiLibUrlEncode (char *PlainString,
                       int NumberOfChars,
                       char *EncodedString,
                       int SizeOfEncodedString);

URL-encode all non-alpha-numeric characters. If 'EncodedString' is NULL
sufficient memory will be dynamically allocated to hold the encoded string. 
For fixed size 'EncodedString' it will not overflow the supplied string but
does not return any indication it reached the limit.  Returns the length of the
encoded string or a pointer to the encoded string (which should be cast to
(char*) by the calling routine).

If 'NumberOfChars' is -1 all characters up to the null are copied.  If
'SizeOfEncodedString' is -1 the target storage if considered "big enough".


URL-ENCODE FILE NAME
--------------------

  int CgiLibUrlEncodeFileName (char *FileName,
                               char *EncodedString,
                               int SizeOfEncodedString,
                               int RelaxedEncode,
                               int ForceLower);

URL-encode (%nn) a possibly extended specification file name.  This can be done
in two ways.  Leave the VMS extended file specification escape sequences in
place (e.g. "^_") but encode absolutely forbidden characters (.e.g ' ', '?',
"%", etc.), called 'RelaxedEncode' here.  Or a strict encode, where the
extended escaped sequences are first un-escaped into characters, then those
charaters URL-encoded as necessary.  If 'ForceLower' true, and no extended file
specification characters were found (e.g. lower-case, escaped characters) then
replace all upper-case alphabetics with lower-case.

If 'SizeOfEncodedString' is -1 the target storage if considered "big enough".
If 'EncodedString' is NULL sufficient memory will be dynamically allocated to
hold the encoded string.


HTML-ESCAPE
-----------

  int CgiLibHtmlEscape (char *PlainString,
                        int NumberOfChars,
                        char *EscapedString,
                        int SizeOfEscapedString);

This function escapes characters forbidden to occur in HTML documents (i.e.
'<', '>' and '&').  If 'EscapedString' is NULL sufficient memory will be
dynamically allocated to hold the encoded string.  For fixed size
'EscapedString' it will not overflow the supplied string but does not return
any indication it reached the limit.  Returns the length of the escaped string
or a pointer to the encoded string (which should be cast to (char*) by the
calling routine).

  int CgiLibAnchorHtmlEscape (char *PlainString,
                              int NumberOfChars,
                              char *EscapedString,
                              int SizeOfEscapedString,
                              int AnchorUrls);

With this function 'AnchorUrls' may be used to turn HTML URLs into HTML anchors
in the text by  calling with CGILIB_ANCHOR_WEB.  It will also attempt to detect
mail addresses (anything like 'this@wherever.host.name') and create "mailto:"
links out of them, call with CGILIB_ANCHOR_MAIL.  To get both use a bit-wise OR.
Normally this will open the link in the same page.  To split the link into a
left half that opens target="_top" and a right half that opens target="_blank"
bitwise OR in CGILIB_ANCHOR_SPLIT.

If 'NumberOfChars' is -1 all characters up to the null are copied.  If
'SizeOfEscapedString' is -1 the target storage if considered "big enough".

  int CgiLibHtmlDeEntify (char *String)

Converts numeric HTML entities in a string into their character equivalents
(e.g. "&#38" to '&', "&#00; to 0x00, etc.)  Also converts common alphabetic
entities (e.g. "&amp;", &nbsp;", &lt;", etc.) but not all (any that are not
recognised are left untouched).  Does not URL-decode!   Resultant string is
always the same size or smaller so it can be done IN-SITU!  Returns the size of
the resultant string.


VEEMEM
------

Virtual memory support functions using the LIB$*_VM_* routines.

Use CgiLibVeeMemInit(), CgiLibVeeMemCalloc(), CgiLibVeeMemRealloc(),
CgiLibVeeMemFree() and CgiLibVeeMemReset() to manage application dynamic
memory.  Using CgiLibVeeMemReset() at the conclusion of processing releases
*all* zone allocated memory in one fell swoop.  This significantly simplifies
memory management and reduces the chances of memory leaks.

CgiLibVeeMemInUse() controls whether applicable CGILIB functions also use
VeeMem.  CGILIB functions that are VeeMem-capable: CgiLibUrlEncode(),
CgiLibUrlEncodeFileName(), CgiLibHtmlEscape(), CgiLibAnchorHtmlEscape(),
CgiLibFormEnocdedParse(), CgiLibFaoPrint(), CgiLibVarByDesc() .

CAUTION: All allocated memory must no longer be in use before zone reset!!

Storage that needs to persist across VeeMemReset() should be calloc()ed.

CgiLibVeeMemContinue() is used to control behaviour on memory allocation
failure.  CGIlib usually just exits with an error status when a memory
allocation fails. With some memory allocation it's better to know that it
failed.  Calling this with either 1 (continue returning the expected result
when failed) or 0 (just exit with the error status) allows fine-grained
behaviour control when using functions that employ dynamic memory.  Works for
both CgiLibVeeMem..() allocated memory and calloc()/realloc() etc.  Returns the
previous state.


MISCELLANEOUS
-------------

  char* CgiLibHttpStatusCodeText (int StatusCode);

Returns a string to a "standard" status code meaning, e.g. 200 "Success".

  char* CgiLibFaoPrint (FILE *StreamPtr, char *FormatString, ...);

This is really just a convenience function and has little to do with CGI
scripting.  VMS $FAO-formatted print statement.  Output is either to the
specified stream, or if stream pointer NULL return a pointer to a dynamic
buffer buffer containing the formatted output (requires caller to dispose of it
as necessary).

  char* CgiLibXUACompatible (char* ContentPtr);

Set and return the MSIE "X-UA-Compatible" compatibility HTML meta field. 

  http://blogs.msdn.com/b/askie/archive/2009/03/23/understanding-compatibility-modes-in-internet-explorer-8.aspx

The meta string is designed to allow being directly included in the response
<head>..</head> data.  It should be the first field following the opening
<head>.  If 'ContentPtr' is NULL return the current value of the meta string
(will be an empty string if uninitialised).  If 'ContentPtr' is to an empty
string it defaults to "IE=edge".  If a non-empty string the meta content=".."
will contain the string parameter.  If the string pointer has the value
(char*)(-1) then reset the meta to NULL.  Setting this value also results in
CGILIB <head>..</head> data containing the meta.


PROCESSING POSTED REQUESTS
--------------------------
The processing POSTed request bodies can often be tiresome to code without the
use of a library.  The functions provided by CGILIB attempt to provide the
basic function required.

  char* CgiLibReadRequestBody (char **BodyPtrPtr, int *BodyLength);

The above function will read a POSTed request body into a single array of char
(doesn't matter whether it's text or binary).  Returns NULL if it's not a POST,
a pointer if it is.  The caller must free() this memory when finished with it.
This works with WASD, "vanilla" CGI and OSU environments.  With OSU it _must_
be called before initializing output (with CgiLibOsuStdoutCgi/Raw()) which
takes the script out of dialog and into output phase.

  int CgiLibFormRequestBody (char *BodyPtr, int BodyLength);

This takes a "application/x-www-form-urlencoded" or "multipart/form-data" body
(which could have been read with the preceding function) and decodes the form
fields inserting them into the list of CGI variables as if they were
"WWW_FORM_" values processed from the query string.  The values may then be
accessed as if standard CGI variables using CgiLibVar("WWW_FORM_...").  The
ability to access the contents of such POSTed requests in this fashion is a
*VERY USEFUL CAPABILITY*.

   int CgiLibBodyIsFormUrlEncoded ();
   int CgiLibBodyIsMultipartFormData ();

These functions return true if the request body is
"application/x-www-form-urlencoded" and "multipart/form-data" respectively.


NOTE ON MULTIPART/FORM-DATA:  As it is possible to POST un-encoded characters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~  with this method (all characters from 0x00 to
0xff are transmitted un-encoded) non-printable characters (0x00-0x1f,
0x7f-0x9f, 0xff) are HTML-entified (i.e. 0x00 becomes "&#0;", 0x01 "&#1;",
etc.) before storage as variables.  These would need to be de-entified before
use (with CgiLibHtmlDeEntify()).  "multipart/form-data" is generated using the
"<input type=file>" HTML form tag. If the field is an upload ("type=file") and
there is an associated content-type and file name (as there should be) these
are placed in variables with the same name as the field with
"_MIME_CONTENT_TYPE" and "_MIME_FILENAME" added.


OSU ENVIRONMENT
---------------
The OSU (DECthreads) HTTP server DECnet-based scripting environment is
supported semi-transparently.

  CgiLibOsuInit (int argc, char *argv[]);

When OSU is detected the CgiLibOsuInit() initializes the OSU request
information (by engaging in the dialog phase) storing CGI-like variables for
later access by CgiLibVar().  It must be supplied with command line arguments.

Supplying a wildcard variable name (i.e. "*") to CgiLibVar() returns each OSU
variable 'name=value' string in turn, with no more being indicated by a NULL
pointer.

  CgiLibOsuStdoutRaw ();

The function CgiLibStdoutRaw() reopen()s <stdout> to NET_LINK.  An explicit
used of this function is not required if CgiLibEnvironmentInit() has been
called.                                                       

Script responses are designed to be returned in OSU "raw" mode; the script
taking care of the full response header and correctly carriage-controlled data
stream, text or binary!!  The script standard output stream is reopened in
binary mode (no translation of '\n') with a maximum record size set to 4096
bytes (failure to set this results in the OSU server reporting
%SYSTEM-F-DATAOVERUN errors).  The binary output is enclosed by suitably
fflushed() "<DNETRAW>" and "</DNETRAW>" control tags (the flush make them
individual records as required by OSU).  If in debug the script output is
placed into "text" mode.

  CgiLibOsuStdoutCgi ();

This function reopen()s <stdout> to NET_LINK.  An explicit used of this
function is not required if CgiLibEnvironmentInit() has been called.

Script responses are designed to be returned in OSU "CGI" mode;  very similar
to other implementations where the output begins with a CGI-compliant header.
The script standard output stream is reopened in binary mode (no translation of
'\n') with a maximum record size set to 4096. The script output is enclosed by
suitably fflushed() "<DNETCGI>" and "</DNETCGI>" control tags (the flush make
them individual records as required by OSU).  If in debug the script output is
placed into "text" mode.


COPYRIGHT
---------
Copyright (C) 1999-2021 Mark G.Daniel

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


VERSION HISTORY (update CGILIB_VERSION as well!)
---------------
05-JUN-2021  MGD  v2.0.0, CgiLibCgiPlusCallout()
                          bugfix; CgiLibCgiPlusInGets() absorb empty lines
22-MAY-2020  MGD  v1.9.9, bugfix; CgiLib__ApacheSetSockOpt() LIB$M_FIS_MIXEDCASE
08-FEB-2020  MGD  v1.9.8, CgiLibAnchorHtmlEscape() handle NULL string
22-MAY-2018  MGD  v1.9.7, CgiLib__ApacheSetSockOpt() both VSI and HP(E) symbols
23-DEC-2017  MGD  v1.9.6, CgiLibVeeMemContinue() allocation failure behaviour
16-OCT-2013  MGD  v1.9.5, CgiLibXUACompatible() <meta "X-UA-Compatible">
09-JUN-2013  MGD  v1.9.4, tweak HTML a little
25-FEB-2012  MGD  V1.9.3, CgiLibUrlDecode() decode URL-encoded 8 bit UTF-8
04-JAN-2011  MGD  v1.9.2, bugfix; CgiLibHttpStatusCodeText() 203/204 transposed
04-MAR-2010  MGD  v1.9.1, CgiLibReadRequestBody() accomodate CgiLibVeeMem..()
                          CgiLibVeeMem..() to use void* rather than char*
23-MAY-2009  MGD  v1.9.0, CgiLibVeeMem..() functions
19-MAY-2009  MGD  v1.8.21, bugfix; CgiLib__ApacheExitRecordMode()
                             flush stream before reverting to record mode
11-MAR-2009  MGD  v1.8.20, bugfix; CgiLibResponseHeader() make "text/"
                             content-type detection case-insensitive
21-JAN-2009  MGD  v1.8.19, bugfix; CgiLib__ApacheExitRecordMode()
                             allow for both Apache versions 1.n and 2.n 
12-NOV-2008  MGD  v1.8.18, CgiLibHtmlEscape() retain empty URLs as text
19-OCT-2008  MGD  v1.8.17, CgiLibOsuInit() noticed OSU had no SERVER_ADDR
21-JUL-2008  MGD  v1.8.16, CgiLibAnchorHtmlEscape() soyMAIL hack
                             to make "mailto:"s access soyMAIL as mail agent
                           bugfix; CgiLib__BodyMultipartFormData() boundary=
                           bugfix; CgiLib__VarList() use offsets rather than
                             pointers when realloc() exhausted storage
13-APR-2008  MGD  v1.8.15, bugfix; CgiLibResponseSet[Default]Charset()
                           do not allow a null pointer charset to be set
10-APR-2008  JPP  v1.8.14, bugfix; CgiLib__VarList() storage overflow 
28-MAR-2008  MGD  v1.8.13, CgiLibHtmlDeEntify() enhance entity scope
03-APR-2007  MGD  v1.8.12, add CgiLibResponseGetStatus() and assoc code
                           emulate CGI variable REQUEST_URI for OSU
26-MAR-2007  MGD  v1.8.11, bugfix; CgiLibOsuInit() <DNETHDR> no URL-decode
12-JAN-2007  MGD  v1.8.10, CgiLib__VarList() kludge to obfuscate FORM_
                           variables for soyMAIL purposes
30-OCT-2006  MGD  v1.8.9, bugfix; CgiLib__GetPathTranslated()
21-APR-2006  MGD  v1.8.8, CgiLibAnchorHtmlEscape() allow for 'split anchors'
                          (left side of anchor opens target=_top, right side
                          opens target=_blank) using CGILIB_ANCHOR_SPLIT
27-MAR-2006  MGD  v1.8.7, CgiLibResponseRedirect() Purveyor (at least v1.2.2)
                          seems to require a full URL for the "Location:" 
16-MAR-2006  MGD  v1.8.6, bugfix; CgiLibResponseRedirect() OSU seems to need
                          a "Content-Type:.." in with the "Status: 302"!?
02-MAR-2006  MGD  v1.8.5, bugfix; CgiLibEnvironmentInit() for VMS Apache V2.n
                          and later (as with Apache V1.n) freopen("mrs=16384")
25-JAN-2006  MGD  v1.8.4, bugfix; when URL-encoded decoding use unsigned char
                          to prevent sign bit issues with the likes of %FC,
                          bugfix; CgiLibEnvironmentName() static storage
30-SEP-2005  MGD  v1.8.3, only generate a "100 Continue" if there was an
                          appropriate "Expect: 100-continue" request header
07-SEP-2005  MGD  v1.8.2, CgiLibBodyIsFormUrlEncoded()
                          CgiLibBodyIsMultipartFormData()
                          add file:// to CgiLibAnchorHtmlEscape()
19-MAY-2005  MGD  v1.8.1, bugfix; APACHE$INPUT seems to return -1 rather
                          than 0 (as HTTP$INPUT) when input stream exhausted
                          CgiLibReadRequestBody() check read against length
04-MAY-2005  MGD  v1.8.0, support SWS 2.0 along with CSWS 1.2/1.3,
                          CgiLib__ApacheSetSockOpt() for SWS 2.0 BG control
22-JAN-2005  MGD  v1.7.4, CgiLibResponseSetBufferRecords(),
                          CgiLibResponseSetRecordMode(),
                          CgiLibResponseSetStreamMode()
12-DEC-2004  MGD  v1.7.3, bugfix; CgiLib__PrepareRequest() check for
                          content-type "multipart/form-data"
21-OCT-2004  MGD  v1.7.2, detection of WASD server request body unencode
                          using a CGI variable CONTENT_LENGTH set to "?",
                          CgiLibEnvironmentWasdVersion()
07-OCT-2004  JFP  v1.7.1, options file and build procedure for sharable image
25-SEP-2004  MGD  v1.7.0, HTTP/1.1 compliance,
                          obsolete ability to #include CGILIB source
                          new function CgiLibFaoPrint()
20-MAY-2004  MGD  v1.6.13, bugfix; (introduced with 1.6.12)
                           with CGIplus ensure body is read for each request
26-JAN-2004  MGD  v1.6.12, bugfix; CgiLibReadRequestBody() if the body has
                           already been read then just return the ptr (CSWS)
23-DEC-2003  MGD  v1.6.11, minor conditional mods to support IA64
14-JUN-2003  MGD  v1.6.10, bugfix; CgiLibVarByDesc() (jpp@esme.fr)
                           bugfix; CgiLib_PrepareRequest() (jpp@esme.fr)
24-MAR-2003  MGD  v1.6.9, (courtesy Jean-Pierre Petit, jpp@esme.fr) 
                          CgiLibFormRequestBody() use strstr() on
                          "..form-urlencoded" to accomodate some browsers,
                          CgiLibInit(), CgiLib__PrepareRequest() and
                          CgiLibVarByDesc()
03-MAR-2003  MGD  v1.6.8, CgiLib__BodyMultipartFormData() now entifies only
                          'control' characters (backward compatibility via
                          environment variable CGILIB_MULTIPART_ISPRINT
30-DEC-2002  MGD  v1.6.7, bugfix; freopen() in CgiLibEnvironmentInit() 
11-OCT-2002  MGD  v1.6.6, refine use of APACHE$FIXBG bit toggling (also
                          ensuring SYS$OUTPUT returns to record mode on exit)
11-SEP-2002  MGD  v1.6.5, bugfix; CgiLibResponseHeader() 'charset='
                          supplied is parameter format string
15-AUG-2002  MGD  v1.6.4, add debug content-type to CGIplus CgiLib__GetVar()
                          (somewhat unsuccessfully, see note),
                          bugfix; query string key values for non-WWW prefix
22-APR-2002  MGD  v1.6.3, CSWS APACHE_SHARED_SOCKET to APACHE$SHARED_SOCKET,
                          bugfix; more aspects of "WWW_"-less CGI variables 
27-JUN-2001  MGD  v1.6.2, bugfix; adjust CgiLib__SetEnvironment()
                          GATEWAY_INTERFACE detection (for OSU)
03-MAY-2001  MGD  v1.6.1, bugfix; some aspects of "WWW_"-less CGI variables
07-APR-2001  MGD  v1.6.0, provide for streamed CGIplus variables,
                          bugfix; refine changes from 1.5.3
22-MAR-2001  MGD  v1.5.3, refine CgiLib__GetVar() to allow environments
                          without "WWW_" CGI variable prefix to be supported
08-JAN-2001  MGD  v1.5.2, CSWS V1.0-1 (VMS Apache) "fixbg" support (see note
                          above), APACHE_INPUT becomes APACHE$INPUT,
                          bugfix; encode/escape terminate empty result string,
                          bugfix; CgiLib__GetKey()
09-DEC-2000  MGD  v1.5.1, bugfix; CgiLibResponseHeader() charset
28-OCT-2000  MGD  v1.5.0, make CGILIB available as an object module,
                          add 'Set' functions to parallel previous macros,
                          make adjustments for RELAXED_ANSI compilation
24-JUN-2000  MGD  v1.4.2, make CgiLibVar() real function (not #define),
                          bugfix; CgiLibResponseError(),
                          bugfix; form fields in non-CGIplus environments
                                  (Imre Fazekas, fazekas@datex-sw.hu)
30-MAY-2000  MGD  v1.4.1, explicitly exit SS$_INSFMEM if allocation fails
09-APR-2000  MGD  v1.4.0, VMS Apache environment (1.3.9 BETA),
                          CgiLibEnvironmentName() returns WWW_SERVER_SOFTWARE,
                          modify report format inline with WASD changes
19-FEB-2000  MGD  v1.3.0, CgiLibUrlEncodeFileName(),
                          CgiLibHtmlDeEntify(),
                          CgiLibFormRequestBody() will now also
                          process "multipart/form-data" bodies,
                          change CgiLib__VarList() data structure to use
                          full integers instead of short integers for lengths,
                          bugfix; worst-case %nn in URL-encodes
24-SEP-1999  MGD  v1.2.0, changes to support Purveyor,
                          CgiLibCgiPlus...(), CgiLibEnvironment...(),
                          CgiLibResponse...(), CgiLibAnchorHtmlEscape()
26-JUN-1999  MGD  v1.1.0, support POSTed body forms under standard CGI
24-APR-1999  MGD  v1.0.0, initial '#include'able code module
*/
/*****************************************************************************/

#define CGILIB_VERSION "2.0.0"
#ifdef __ALPHA
#   define CGILIB_SOFTWAREID "CGILIB AXP-" CGILIB_VERSION
#endif
#ifdef __ia64
#   define CGILIB_SOFTWAREID "CGILIB IA64-" CGILIB_VERSION
#endif
#ifdef __x86_64
#   define CGILIB_SOFTWAREID "CGILIB X86-" CGILIB_VERSION
#endif

/* standard C headers */
#include <ctype.h>
#include <errno.h>
#include <file.h>
#include <fcntl.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

/* VMS headers */
#include <descrip.h>
#include <libdef.h>
#include <lib$routines.h>
#include <libvmdef.h>
#include <stsdef.h>
#include <ssdef.h>
#include <starlet.h>

/* required for OSU server address */

/**
HP C V7.1-015 on OpenVMS Alpha V8.3 reports the following (apparently) because
of a nesting error in RESOLV.H due to the __CRTL_VER constraint that WASD
applications are built with.  This does not happen with Compaq C V6.4-005 on
OpenVMS Alpha V7.3-2 for instance.  Just avoid the error by pretending the
header file is already loaded.  Doesn't *seem* to cause side-effects.

#pragma __member_alignment __restore
........^
%CC-W-ALIGNPOP, This "restore" has underflowed the member alignment's stack. No corresponding "save" was found.
at line number 451 in module RESOLV of text library SYS$COMMON:[SYSLIB]DECC$RTLD
**/

#define __RESOLV_LOADED 1
#include <netdb.h>

/* module header */
#ifndef CGILIB_OBJECT_MODULE
#define CGILIB_OBJECT_MODULE
#endif
#ifdef CGILIB_OBJECT_MODULE
#include <cgilib.h>
#else
#error   *** CGILIB V1.7 #include at compile time is no longer supported ***
#endif

/* just modifies the handling of a couple of things */
#define CGILIB_DEVELOPMENT 1
#define CGILIB_VARLIST_DEBUG 0

/******************/
/* global storage */
/******************/

int  CgiLib__Debug,
     CgiLib__CgiPrefixWWW,
     CgiLib__CgiPlusLoadVariables = 1,
     CgiLib__CgiPlusUsageCount,
     CgiLib__CgiPlusVarRecord,
     CgiLib__CgiPlusVarStruct,
     CgiLib__Environment,
     CgiLib__EnvironmentStdoutType = CGILIB_ENVIRONMENT_STDOUT_RECORD,
     CgiLib__ApacheVersion,
     CgiLib__HttpProtocolVersion,
     CgiLib__BodyIsFormUrlEncoded,
     CgiLib__BodyIsMultipartFormData,
     CgiLib__ResponseBufferRecords,
     CgiLib__ResponseCount,
     CgiLib__ResponseCgi,
     CgiLib__ResponseErrorStatus,
     CgiLib__ResponseRecordMode,
     CgiLib__ResponseStatusCode,
     CgiLib__ResponseStreamMode,
     CgiLib__ResponseSuccessStatus,
     CgiLib__VeeMemCurrent,
     CgiLib__VeeMemInUse,
     CgiLib__VeeMemPeak,
     CgiLib__VeeMemContinue,
     CgiLib__WasdVersion;

unsigned long  CgiLib__VeeMemZoneId;

char  *CgiLib__CgiPlusEofPtr,
      *CgiLib__CgiPlusEotPtr,
      *CgiLib__CgiPlusEscPtr,
      *CgiLib__HttpProtocolVersionPtr,
      *CgiLib__QueryStringPtr,
      *CgiLib__ResponseBodyPtr,
      *CgiLib__ResponseCharsetPtr,
      *CgiLib__ResponseDefCharsetPtr,
      *CgiLib__ResponseErrorInfoPtr,
      *CgiLib__ResponseErrorMessagePtr,
      *CgiLib__ResponseErrorTitlePtr,
      *CgiLib__ResponseSoftwareIdPtr,
      *CgiLib__ResponseSuccessMsgPtr,
      *CgiLib__ResponseSuccessTitlePtr,
      *CgiLib__soyMAILhack,
      *CgiLib__VarNonePtr = CGILIB_NONE,
      *CgiLib__XUACompatiblePtr;

char  CgiLib__SoftwareID [] = CGILIB_SOFTWAREID,
      CgiLib__VarEmpty [] = "";

FILE  *CgiLib__CgiPlusInFile;

/*****************************************************************************/

                              /**************/
                              /* INITIALIZE */
                              /**************/

/*****************************************************************************/
/*
(jpp@esme.fr)  Wrapper function for transparently handling a script without
it needing to concern itself with whether it's been called in a standard CGI or
CGIplus environment.
*/

void CgiLibInit
(
int argc,
char* argv[],
void ProcessRequest(void)
)
{
   int  Debug,
        IsCgiPlus;

   /*********/
   /* begin */
   /*********/

   Debug = (getenv ("CGILIB_DEBUG") != NULL);
   CgiLibEnvironmentSetDebug (Debug);

   CgiLibEnvironmentInit (argc, argv, 0);

   IsCgiPlus = CgiLibEnvironmentIsCgiPlus ();

   if (IsCgiPlus)
   {
      for (;;)
      {
         /* block waiting for the next request */
         CgiLibVar ("");
         CgiLib__PrepareRequest (ProcessRequest);
         CgiLibCgiPlusEOF ();
      }
   }
   else
       CgiLib__PrepareRequest (ProcessRequest);
}

/*****************************************************************************/
/*
(jpp@esme.fr)  Support function for CgiLibInit().
*/

void CgiLib__PrepareRequest (void ProcessRequest(void))

{
   int  PostBufferCount;
   char  *PostBufferPtr,
         *CgiRequestMethodPtr,
         *CgiContentTypePtr;

   /*********/
   /* begin */
   /*********/

   CgiRequestMethodPtr = CgiLibVar ("WWW_REQUEST_METHOD");
   if (!strcmp (CgiRequestMethodPtr, "POST"))
   {
      CgiContentTypePtr = CgiLibVar ("WWW_CONTENT_TYPE");
      if (strstr (CgiContentTypePtr, "application/x-www-form-urlencoded") ||
          strstr (CgiContentTypePtr, "multipart/form-data"))
      {
         /* is URL form encoded, turn that into pseudo CGI variables */
         CgiLibReadRequestBody (&PostBufferPtr, &PostBufferCount);
         CgiLibFormRequestBody (PostBufferPtr, PostBufferCount);
         if (PostBufferPtr == NULL || PostBufferCount == 0)
         {
            CgiLibResponseError (__FILE__, __LINE__, 0, "No body in the POST!");
            return;
         }
         if (CgiLib__VeeMemInUse)
            CgiLibVeeMemFree (PostBufferPtr);
         else
            free (PostBufferPtr);
      }
   }
   ProcessRequest ();
}

/*****************************************************************************/
/*
Initialize the scripting environment.  Parameter 'DoResponseCgi' if true sets
the script do return CGI compliant responses regardless of whether it can
support others or not.
*/

void CgiLibEnvironmentInit
(
int argc,
char *argv[],
int DoResponseCgi
)
{
   int  OsuBodyLength;
   char  *OsuBodyPtr,
         *OsuMethodPtr;

   /*********/
   /* begin */
   /*********/

   CgiLib__ResponseBodyPtr = CGILIB_RESPONSE_BODY;
   CgiLib__ResponseCharsetPtr = CGILIB_RESPONSE_CHARSET;
   CgiLib__ResponseDefCharsetPtr = CGILIB_RESPONSE_DEFAULT_CHARSET;
   CgiLib__ResponseErrorInfoPtr = CGILIB_RESPONSE_ERROR_INFO;
   CgiLib__ResponseErrorMessagePtr = CGILIB_RESPONSE_ERROR_MESSAGE;
   CgiLib__ResponseErrorStatus = CGILIB_RESPONSE_ERROR_STATUS;
   CgiLib__ResponseErrorTitlePtr = CGILIB_RESPONSE_ERROR_TITLE;
   CgiLib__ResponseSoftwareIdPtr = CGILIB_RESPONSE_SOFTWAREID;
   CgiLib__ResponseSuccessMsgPtr = CGILIB_RESPONSE_SUCCESS_MESSAGE;
   CgiLib__ResponseSuccessStatus = CGILIB_RESPONSE_SUCCESS_STATUS;
   CgiLib__ResponseSuccessTitlePtr = CGILIB_RESPONSE_SUCCESS_TITLE;

   if (CgiLib__VarNonePtr != NULL && !CgiLib__VarNonePtr[0])
      CgiLib__VarNonePtr = CgiLib__VarEmpty;

   if (CgiLib__Debug)
   {
      /* force it to CGI compliant response */
      DoResponseCgi = 1;
      /* CGI interfaces object to this non-CGI output before the header */
      /** if (CgiLib__Debug) fprintf (stdout, "CgiLibEnvironmentInit()\n"); **/
   }

   CgiLib__EnvironmentStdoutType = CGILIB_ENVIRONMENT_STDOUT_RECORD;

   CgiLib__CgiPlusEofPtr =
      CgiLib__CgiPlusEotPtr =
      CgiLib__CgiPlusEscPtr = NULL;

   CgiLib__ResponseCgi = DoResponseCgi;

   CgiLib__SetEnvironment ();

   if (CgiLib__Environment == CGILIB_ENVIRONMENT_OSU)
   {
      /*******************/
      /* OSU environment */
      /*******************/

      /* OSU is always sent as a binary stream ... *always* */
      CgiLib__EnvironmentStdoutType = CGILIB_ENVIRONMENT_STDOUT_BINARY;

      CgiLibOsuInit (argc, argv);

      OsuMethodPtr = CgiLib__GetVar ("WWW_REQUEST_METHOD", "");
      if (strcmp (OsuMethodPtr, "POST") ||
          strcmp (OsuMethodPtr, "PUT"))
      {
         /* any body MUST be read before terminating the dialog phase! */
         CgiLibReadRequestBody (&OsuBodyPtr, &OsuBodyLength);
      }

      if (CgiLib__ResponseCgi = DoResponseCgi)
         CgiLibOsuStdoutCgi ();
      else
         CgiLibOsuStdoutRaw ();
   }
   else

#ifdef BLAH
   if (CgiLib__Debug)
   {
      /* debug output is plain-text */
      fputs (
"Content-Type: text/plain\nScript-Control: X-content-encoding-gzip=0\n\n",
             stdout);
      /* this works with WASD, Apache, doesn't with OSU, others? */
      if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE ||
          CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS ||
          CgiLib__Environment == CGILIB_ENVIRONMENT_WASD)
      {
         fputs ("$ SHOW PROCESS /ALL\n", stdout);
         system ("show process/all");
         fputs ("$ SHOW LOG /PROCESS *\n", stdout);
         system ("show log /process *");
         fputs ("$ SHOW SYMBOL *\n", stdout);
         system ("show symbol *");
      }
   }
   else
#endif
   if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE ||
       CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS ||
       CgiLib__Environment == CGILIB_ENVIRONMENT_WASD)
   {
      /*
         WASD CGI/CGIplus and Apache default is a binary stream.
         Binary streams are more efficient because the C-RTL buffers
         multiple '\n'-delimited records up to the size of the stdout device
         buffer capacity, then QIOs, rather that QIOing each '\n' record.
      */

      CgiLib__EnvironmentStdoutType = CGILIB_ENVIRONMENT_STDOUT_BINARY;
      if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE)
      {
         if (CgiLib__ApacheVersion == 1)
            CgiLib__ApacheFixBg(1);
         else
         {
            /* SWS 2.0 (and hopefully later :-) binary mode and buffer size */
            CgiLib__ApacheSetSockOpt(0);
            CgiLib__ApacheSetSockOpt(16384);
         }
         stdout = freopen ("SYS$OUTPUT:", "w", stdout, "ctx=bin", "mrs=16384");
      }
      else
         stdout = freopen ("SYS$OUTPUT:", "w", stdout, "ctx=bin");
      if (stdout == NULL) exit (vaxc$errno);
   }

   CgiLib__ResponseCount = 0;
}

/*****************************************************************************/
/*
Determine which environment we're executing within.
*/

void CgiLib__SetEnvironment ()

{
   char  *cptr;

   /*********/
   /* begin */
   /*********/

   /* CGI interfaces object to this non-CGI output before the header */
   /** if (CgiLib__Debug) fprintf (stdout, "CgiLib__EnvironmentCheck()\n"); **/

   /* look for WASD request body I/O stream logical */
   if (getenv ("HTTP$INPUT") != NULL)
   {
      /* look for CGIplus stream logical */
      if ((CgiLib__CgiPlusEofPtr = getenv("CGIPLUSEOF")) != NULL)
      {
         CgiLib__Environment = CGILIB_ENVIRONMENT_CGIPLUS;
         return;
      }
   }

#if CGILIB_DEVELOPMENT

   if (getenv ("CGILIB__ENVIRONMENT") != NULL)
   {
      CgiLib__Environment = atoi (getenv ("CGILIB__ENVIRONMENT"));
      CgiLib__CgiPrefixWWW = 1;
      return;
   }

#endif

   CgiLib__Environment = 0;

   if (getenv ("WWWEXEC_RUNDOWN_STRING") != NULL)
   {
      /* OSU environment */
      CgiLib__Environment = CGILIB_ENVIRONMENT_OSU;
      CgiLib__CgiPrefixWWW = 1;
      return;
   }

   /* determine if CGI variables begin with or without "WWW_" */
   cptr = getenv ("WWW_GATEWAY_INTERFACE");
   if (cptr == NULL)
      CgiLib__CgiPrefixWWW = 0;
   else
      CgiLib__CgiPrefixWWW = 1;

   if (getenv ("HTTP$INPUT") != NULL)
   {
      /* WASD request body I/O stream logical detected, CGIplus? */
      if ((CgiLib__CgiPlusEofPtr = getenv("CGIPLUSEOF")) != NULL)
      {
         CgiLib__Environment = CGILIB_ENVIRONMENT_CGIPLUS;
         return;
      }

      CgiLib__Environment = CGILIB_ENVIRONMENT_WASD;
      return;
   }

   /* the first is CSWS 1.2/1.3, the other two for SWS 2.0 */
   if (getenv ("APACHE$SHARED_SOCKET") != NULL ||
       getenv ("APACHE$PARENT_PID") != NULL ||
       getenv ("APACHE$SERVER_TAG") != NULL)
   {
      CgiLib__Environment = CGILIB_ENVIRONMENT_APACHE;
      /* note whether it's CSWS version 1.2/1.3 or SWS 2.0 */
      if (getenv ("APACHE$SHARED_SOCKET") != NULL)
         CgiLib__ApacheVersion = 1;
      else
         CgiLib__ApacheVersion = 2;
      return;
   }

   if ((cptr = getenv ("WWW_SERVER_SOFTWARE")) != NULL)
   {
      if (strstr (cptr, "Purveyor") != NULL)
      {
         CgiLib__Environment = CGILIB_ENVIRONMENT_PURVEYOR;
         return;
      }
   }

   /* assume vanilla CGI */
   CgiLib__Environment = CGILIB_ENVIRONMENT_CGI;
}

/*****************************************************************************/

                         /*************************/
                         /* OUTPUT STREAM CONTROL */
                         /*************************/

/*****************************************************************************/
/*
Set the <stdout> stream to binary mode (no translation of '\n', etc.)
*/

void CgiLibEnvironmentBinaryOut ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibEnvironmentBinaryOut()\n");

   CgiLib__EnvironmentStdoutType = CGILIB_ENVIRONMENT_STDOUT_BINARY;

   if (CgiLib__Environment == CGILIB_ENVIRONMENT_OSU) return;

   if (CgiLib__Debug) return;

   if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE)
   {
      if (CgiLib__ApacheVersion == 1)
         CgiLib__ApacheFixBg(1);
      else
         CgiLib__ApacheSetSockOpt(0);
   }

   if ((stdout = freopen ("SYS$OUTPUT:", "w", stdout, "ctx=bin")) == NULL)
      exit (vaxc$errno);
}

/*****************************************************************************/
/*
Set the <stdout> stream is back to record mode.
*/

/* for backward compatibility */
#pragma inline(CgiLibEnvironmentStandardOut)
void CgiLibEnvironmentStandardOut () { CgiLibEnvironmentRecordOut(); }

void CgiLibEnvironmentRecordOut ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibEnvironmentRecordOut()\n");

   CgiLib__EnvironmentStdoutType = CGILIB_ENVIRONMENT_STDOUT_RECORD;

   if (CgiLib__Environment == CGILIB_ENVIRONMENT_OSU) return;

   if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE)
   {
      if (CgiLib__ApacheVersion == 1)
         CgiLib__ApacheFixBg(0);
      else
         CgiLib__ApacheSetSockOpt(1);
   }

   if ((stdout = freopen ("SYS$OUTPUT:", "w", stdout, "ctx=rec")) == NULL)
      exit (vaxc$errno);
}

/*****************************************************************************/
/*
For SWS version 2.0!  Based on information provided in private communication
with Richard Barry (thanks Rick) this function calls the apache$$setsockopt()
function to adjust the BG device's characteristics suitable for binary and
record output.  To select binary mode call with a parameter of 0, record mode
with 1, toggle the modes with -1, and set the BG device buffer size with any
value greater than 255 and less than or equal to 65535.

This is based on a function description provided by Rick, but makes the 
sharable image activation and symbol resolution dynamic to allow the object
module to be linked on systems without VMS Apache and/or the APACHE$APR_SHRP
shareable image available.
*/

void CgiLib__ApacheSetSockOpt (int OptionValue)

{
#define OPT_CCLBIT    1
#define OPT_BUFSIZ    2
#define OPT_SHAREABLE 3
#define LIB$M_FIS_MIXEDCASE 0x10

   static int  IsBin;
   static unsigned short  SysOutputChannel;
   static int (*ApacheSetSockOpt)(unsigned short, int, int*, int);

   static $DESCRIPTOR (StdOutputDsc, "SYS$OUTPUT");
   static $DESCRIPTOR (ApacheAprShrpImageDsc, "APACHE$APR_SHRP");
   static $DESCRIPTOR (HpeApacheSetSockOptDsc, "APACHE$$SETSOCKOPT");
   static $DESCRIPTOR (VsiApacheSetSockOptDsc, "apr$$setsockopt");

   int  status;
   char  *aptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLib__ApacheSetSockOpt() %d\n", OptionValue);

   if (SysOutputChannel)
      status = SS$_NORMAL;
   else
   {
#ifndef __VAX
      /* first look for the VSI Apache symbol */
      aptr = VsiApacheSetSockOptDsc.dsc$a_pointer;
      lib$establish (CgiLib__ApacheSetSockOptHandler);
      status = lib$find_image_symbol (&ApacheAprShrpImageDsc,
                                      &VsiApacheSetSockOptDsc,
                                      &ApacheSetSockOpt, 0,
                                      LIB$M_FIS_MIXEDCASE);
      if (CgiLib__Debug)
         fprintf (stdout, "lib$find_image_symbol() %%X%08.08X\n", status);
      lib$revert ();
      if (!(status & 1))
#endif /* __VAX */
      {
         /* second look for the HP(E) Apache symbol */
         aptr = HpeApacheSetSockOptDsc.dsc$a_pointer;
         lib$establish (CgiLib__ApacheSetSockOptHandler);
         status = lib$find_image_symbol (&ApacheAprShrpImageDsc,
                                         &HpeApacheSetSockOptDsc,
                                         &ApacheSetSockOpt, 0, 0);
         if (CgiLib__Debug)
            fprintf (stdout, "lib$find_image_symbol() %%X%08.08X\n", status);
         lib$revert ();
      }
      if (status & 1)
      {
         status = sys$assign (&StdOutputDsc, &SysOutputChannel, 0, 0);
         atexit (&CgiLib__ApacheExitRecordMode);
      }
   }

   if (status & 1)
   {
      if (OptionValue > 255)
         status = ApacheSetSockOpt (SysOutputChannel, OPT_BUFSIZ, 
                                    &OptionValue, sizeof(OptionValue));
      else
         status = ApacheSetSockOpt (SysOutputChannel, OPT_CCLBIT, 
                                    &OptionValue, sizeof(OptionValue));
   }

   if (status & 1) return;

   /* let's make it a bit more obvious than when delving through error logs */
   fprintf (stdout,
"Content-Type: text/plain\r\n\
\r\n\
*** ERROR ACTIVATING %s in APACHE$APR_SHRP ***\n\
\n", aptr);

   exit (status);

#if 0
   static int  IsBin;
   static unsigned long flags = LIB$M_FIS_MIXEDCASE;
   static unsigned short  SysOutputChannel;
   static int (*ApacheSetSockOpt)(unsigned short, int, int*, int);

   static $DESCRIPTOR (StdOutputDsc, "SYS$OUTPUT");
   static $DESCRIPTOR (ApacheAprShrpImageDsc, "APACHE$APR_SHRP");
   static $DESCRIPTOR (HpeApacheSetSockOptDsc, "APACHE$SETSOCKOPT");
   static $DESCRIPTOR (VsiApacheSetSockOptDsc, "apr$$setsockopt");

   int  status;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLib__ApacheSetSockOpt() %d\n", OptionValue);
/**
CgiLib__Debug = 1;
printf("content-type: text/plain\n");
fflush (stdout);
puts ("\n");
fflush (stdout);
**/

   if (SysOutputChannel)
      status = SS$_NORMAL;
   else
   {
      lib$establish (CgiLib__ApacheSetSockOptHandler);
      status = lib$find_image_symbol (&ApacheAprShrpImageDsc,
                                      &ApacheSetSockOptDsc,
                                      &ApacheSetSockOpt,
                                      0,
                                      flags);
      if (CgiLib__Debug)
         fprintf (stdout, "lib$find_image_symbol() %%X%08.08X\n", status);
      lib$revert ();
      if (status & 1)
      {
         status = sys$assign (&StdOutputDsc, &SysOutputChannel, 0, 0);
         atexit (&CgiLib__ApacheExitRecordMode);
      }
#endif
}

/*****************************************************************************/
/*
Just continue, to report an error if the image couldn't be activated or the
required symbol not found.
*/

int CgiLib__ApacheSetSockOptHandler ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__ApacheSetSockOptHandler()\n");

   return (SS$_CONTINUE);
}

/*****************************************************************************/
/*
For CSWS version 1.2 and 1.3!  According to "Compaq Secure Web Server Version
1.0-1 for OpenVMS Alpha (based on Apache 1.3.12) Version 1.0-1 Release Notes"
this is required to support the transfer of any binary content in excess of 32
kbytes.  This is based on a code snippet in these release notes, but makes the
sharable image activation and symbol resolution dynamic to allow the object
module to be linked on systems without VMS Apache and/or the APACHE$FIXBG.EXE
shareable image available. 'WantBin' if one sets to binary, if 0 resets to
record mode.  This toggling has it's limitations but that's the way
APACHE$FIXBG.C works!  This function assumes the environment starts out in
record mode.
*/

void CgiLib__ApacheFixBg (int WantBin)

{
   static int  IsBin;
   static unsigned short  SysOutputChannel;
   static int (*ApacheFixBg)(unsigned short, int);

   static $DESCRIPTOR (StdOutputDsc, "SYS$OUTPUT");
   static $DESCRIPTOR (ApacheFixBgImageDsc, "APACHE$FIXBG");
   static $DESCRIPTOR (ApacheFixBgDsc, "APACHE$FIXBG");

   int  status;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLib__ApacheFixBg() %d %d\n", WantBin, IsBin);

   /* if want binary and already binary just return */
   if (WantBin && IsBin) return;
   /* if want record and already record just return */
   if (!WantBin && !IsBin) return;

   IsBin = !IsBin;

   if (SysOutputChannel)
      status = SS$_NORMAL;
   else
   {
      lib$establish (CgiLib__ApacheFixBgHandler);
      status = lib$find_image_symbol (&ApacheFixBgImageDsc, &ApacheFixBgDsc,
                                      &ApacheFixBg, 0);
      if (CgiLib__Debug)
         fprintf (stdout, "lib$find_image_symbol() %%X%08.08X\n", status);
      lib$revert ();
      if (status & 1)
      {
         status = sys$assign (&StdOutputDsc, &SysOutputChannel, 0, 0);
         atexit (&CgiLib__ApacheExitRecordMode);
      }
   }

   if (status & 1) status = ApacheFixBg (SysOutputChannel, 1);

   if (status & 1) return;

   /* let's make it a bit more obvious than when delving through error logs */
   fprintf (stdout,
"Content-Type: text/plain\r\n\
\r\n\
*** ERROR ACTIVATING apache$fixbg() in APACHE$FIXBG ***\n\
\n");

   exit (status);
}

/*****************************************************************************/
/*
Just continue, to report an error if the image couldn't be activated or the
required symbol not found.
*/

int CgiLib__ApacheFixBgHandler ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__ApacheFixBgHandler()\n");

   return (SS$_CONTINUE);
}

/*****************************************************************************/
/*
Set the Apache <stdout> stream is back to record mode.
*/

void CgiLib__ApacheExitRecordMode ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__ApacheExitRecordMode()\n");

   fflush (stdout);
   if (CgiLib__ApacheVersion == 1)
      CgiLib__ApacheFixBg(0);
   else
      CgiLib__ApacheSetSockOpt(1);
}

/*****************************************************************************/

                          /**********************/
                          /* SERVER ENVIRONMENT */
                          /**********************/

/*****************************************************************************/
/*
Return true or false depending on whether the statement is true or false!
*/

int CgiLibEnvironmentIsApache ()

{
   return (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE);
}

int CgiLibEnvironmentIsCgi ()

{
   return (CgiLib__Environment == CGILIB_ENVIRONMENT_CGI);
}

int CgiLibEnvironmentIsCgiPlus ()

{
   return (CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS);
}

int CgiLibEnvironmentIsOsu ()

{
   return (CgiLib__Environment == CGILIB_ENVIRONMENT_OSU);
}

int CgiLibEnvironmentIsPurveyor ()

{
   return (CgiLib__Environment == CGILIB_ENVIRONMENT_PURVEYOR);
}

int CgiLibEnvironmentIsWasd ()

{
   return (CgiLib__Environment == CGILIB_ENVIRONMENT_WASD);
}

/*****************************************************************************/
/*
Return a pointer to a string with the name of the scripting environment.
For the WASD server append whether it's CGI or CGIplus.
*/

char* CgiLibEnvironmentName ()

{
   static char  Environment [64];

   char  *cptr, *sptr, *zptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibEnvironmentName()\n");

   if (CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS &&
       CgiLib__CgiPlusLoadVariables)
   {
      /* with CGIplus we can't use a variable before the stream is read from */
      return ("WASD (CGIplus)");
   }

   cptr = CgiLib__GetVar ("WWW_SERVER_SOFTWARE", "");
   if (!*cptr) return ("(unknown)");

   zptr = (sptr = Environment) + sizeof(Environment)-1;
   while (*cptr && sptr < zptr) *sptr++ = *cptr++;
   if (CgiLib__Environment == CGILIB_ENVIRONMENT_WASD) cptr = " (CGI)";
   if (CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS) cptr = " (CGIplus)";
   while (*cptr && sptr < zptr) *sptr++ = *cptr++;
   *sptr = '\0';
   return (Environment);
}

/*****************************************************************************/
/*
Return a pointer to a string with the version of CGILIB.
*/

char* CgiLibEnvironmentVersion ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibEnvironmentVersion()\n");

   return (CgiLib__SoftwareID);
}

/*****************************************************************************/
/*
If WASD, from the SERVER_SOFTWARE containing something like "HTTPd-WASD/8.2.1
OpenVMS/AXP SSL" return a number like 080201 (80,201).
*/

int CgiLibEnvironmentWasdVersion ()

{
   char  *cptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibEnvironmentWasdVersion()\n");

   if (CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS ||
       CgiLib__Environment == CGILIB_ENVIRONMENT_WASD)
   {
      if (!CgiLib__WasdVersion)
      {
         cptr = CgiLib__GetVar ("WWW_SERVER_SOFTWARE", "");
         if (cptr)
         {
            while (*cptr && !isdigit(*cptr)) cptr++;
            CgiLib__WasdVersion = atoi(cptr) * 10000;
            while (*cptr && isdigit(*cptr)) cptr++;
            if (*cptr) cptr++;
            CgiLib__WasdVersion += atoi(cptr) * 100;
            while (*cptr && isdigit(*cptr)) cptr++;
            if (*cptr) cptr++;
            CgiLib__WasdVersion += atoi(cptr);
         }
      }
   }

   if (CgiLib__Debug) fprintf (stdout, "%d\n", CgiLib__WasdVersion);

   return (CgiLib__WasdVersion);
}

/*****************************************************************************/
/*
Set or reset the CGILIB debug.  Return previous value.
*/

int CgiLibEnvironmentSetDebug (int SetDebug)

{
   int  PrevDebug;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibEnvironmentSetDebug()\n");

   PrevDebug = CgiLib__Debug;
   CgiLib__Debug = SetDebug;
   return (PrevDebug);
}

/*****************************************************************************/
/*
Set the string value used when a CGI variable return NONE.  This is usually ""
(empty string) or NULL (zero). Return previous value.
*/

char* CgiLibEnvironmentSetVarNone (char* VarNonePtr)

{
   char  *PrevVarNonePtr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibEnvironmentSetVarNone()\n");

   PrevVarNonePtr = CgiLib__VarNonePtr;
   CgiLib__VarNonePtr = VarNonePtr;
   return (PrevVarNonePtr);
}

/*****************************************************************************/
/*
Returns an integer 11 if the current request HTTP protocol version is 1.1, 10
if it's 1.0, or 0 if it's unknown or otherwise not determined, as provided by
the SERVER_PROTOCOL CGI variable.
*/

int CgiLibHttpProtocolVersion ()

{
   static int  UsageCount;
   char  *cptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibHttpProtocolVersion()\n");

   if (!UsageCount || UsageCount != CgiLib__CgiPlusUsageCount)
   {
      UsageCount = CgiLib__CgiPlusUsageCount;
      /* a misnomer, it's really request protocol, but never mind */
      cptr = CgiLib__GetVar ("WWW_SERVER_PROTOCOL", "");
      if (!strcmp (cptr, "HTTP/1.1"))
      {
         CgiLib__HttpProtocolVersion = 11;
         CgiLib__HttpProtocolVersionPtr = "HTTP/1.1";
      }
      else
      if (!strcmp (cptr, "HTTP/1.0"))
      {
         CgiLib__HttpProtocolVersion = 10;
         CgiLib__HttpProtocolVersionPtr = "HTTP/1.0";
      }
      else
      {
         CgiLib__HttpProtocolVersion = 0;
         CgiLib__HttpProtocolVersionPtr = "HTTP/?.?";
      }
   }

   if (CgiLib__Debug)
      fprintf (stdout, "|%s| %d\n",
               CgiLib__HttpProtocolVersionPtr,
               CgiLib__HttpProtocolVersion);
   return (CgiLib__HttpProtocolVersion);
}

/*****************************************************************************/
/*
Set and return the MSIE "X-UA-Compatible" compatibility HTML meta field. 
*/

char* CgiLibXUACompatible (char* ContentPtr)

{
   static char  MetaHttpEquiv [] = "<meta http-equiv=\"X-UA-Compatible\" "
                                   "content=\"%s\">\n";
   static char  MetaXUA [sizeof(MetaHttpEquiv)+64];

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibXUACompatible()\n");

   if (ContentPtr == NULL) return (CgiLib__XUACompatiblePtr ?
                                   CgiLib__XUACompatiblePtr : "");
   if (ContentPtr == (char*)(-1)) return (CgiLib__XUACompatiblePtr = NULL);
   if (!*ContentPtr) ContentPtr = "IE=edge";
   if (strlen(ContentPtr) > 64) return (CgiLib__XUACompatiblePtr = NULL);
   sprintf (CgiLib__XUACompatiblePtr = MetaXUA, MetaHttpEquiv, ContentPtr);
   return (CgiLib__XUACompatiblePtr);
}

/****************************************************************************/

                             /*****************/
                             /* HTTP RESPONSE */
                             /*****************/

/****************************************************************************/
/*
Generate a full HTTP (WASD and OSU) or CGI response header appropriate to the
environment.  302 (redirection) and 401 (authentication) responses are handled. 
Supply NULL for content parameters and the location URL or authentication
header line as parameter three.  The third can be a 'printf()' format string
with associated parameter supplied following.  This can also be used to supply
additional newline terminated header lines into the response.  If a specific
character set is required begin this format string with "; charset=" and then
charset string, followed by a newline character.
*/ 

int CgiLibResponseHeader
(
int StatusCode,
char *ContentType,
...
)
{
   static FILE  *ResponseStdout = NULL;

   int  argcnt,
        charcnt,
        ContentTypeText;
   char  *CharsetPtr,
         *ContentTypeNewLine,
         *FormatStringPtr,
         *RequestTimeGmtPtr,
         *ServerSoftwarePtr;
   va_list  argptr;

   /*********/
   /* begin */
   /*********/

   va_count (argcnt);

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibResponseHeader() %d %d |%s|\n",
               argcnt, StatusCode, ContentType);

   if (!CgiLib__Environment) CgiLib__SetEnvironment ();

   if (ResponseStdout == NULL)
   {
      if (CgiLib__Environment == CGILIB_ENVIRONMENT_CGI ||
          CgiLib__Environment == CGILIB_ENVIRONMENT_PURVEYOR)
      {
         /* open a permanent, record-oriented <stdout> stream */
         if ((ResponseStdout = fopen ("SYS$OUTPUT:", "w", "ctx=rec")) == NULL)
            exit (vaxc$errno);
      }
      else
         ResponseStdout = stdout;
   }

   if (argcnt > 2)
   {
      /* more response header line(s)/information has been included */
      va_start (argptr, ContentType);
      FormatStringPtr = (char*)va_arg (argptr, char*);
      if (CgiLib__Debug) fprintf (stdout, "|%s|\n", FormatStringPtr);
   }
   else
      FormatStringPtr = NULL;

   ContentTypeNewLine = "\n";
   if (ContentType == NULL) ContentType = "";
   if (!ContentType[0]) ContentType = "text/plain";
   if ((ContentTypeText = !strncmp (ContentType, "text/", 5)) ||
       (ContentTypeText = !strncmp (ContentType, "TEXT/", 5)))
   {
      if (FormatStringPtr != NULL &&
          (!strncmp (FormatStringPtr, ";charset=", 9) ||
           !strncmp (FormatStringPtr, "; charset=", 10)))
      {
         /* caller has specifically included a character set specification */
         CharsetPtr = ContentTypeNewLine = "";
      }
      else
      {
         /* check script, request and server, before using default */
         if ((CharsetPtr = CgiLib__ResponseCharsetPtr) == NULL)
         {
            /* there is no script-enforced character set */
            CharsetPtr = CgiLib__GetVar ("WWW_REQUEST_CHARSET", "");
            if (!CharsetPtr[0])
               CharsetPtr = CgiLib__GetVar ("WWW_SERVER_CHARSET", "");
            if (!CharsetPtr[0])
               CharsetPtr = CgiLib__ResponseDefCharsetPtr;
         }
      }
   }
   else
      CharsetPtr = "";

   CgiLib__ResponseStatusCode = StatusCode;

   if (!CgiLib__ResponseCgi &&
       CgiLib__Environment == CGILIB_ENVIRONMENT_OSU)
   {
      /* full response header (only for OSU these days) */
      ServerSoftwarePtr = CgiLib__GetVar ("WWW_SERVER_SOFTWARE", "");
      if (!ServerSoftwarePtr[0])
         ServerSoftwarePtr = CgiLib__ResponseSoftwareIdPtr;
      RequestTimeGmtPtr = CgiLibVarNull ("REQUEST_TIME_GMT");
      CgiLibHttpProtocolVersion ();

      if (StatusCode == 302)
      {
         charcnt = fprintf (ResponseStdout,
"%s 302 %s\n\
Server: %s\n\
%s%s%s\
Location: ",
            CgiLib__HttpProtocolVersionPtr,
            CgiLibHttpStatusCodeText(StatusCode),
            ServerSoftwarePtr,
            RequestTimeGmtPtr == NULL ? "" : "Date: ",
            RequestTimeGmtPtr == NULL ? "" : RequestTimeGmtPtr,
            RequestTimeGmtPtr == NULL ? "" : "\n");
      }
      else
      if (StatusCode == 401)
      {
         charcnt = fprintf (ResponseStdout,
"%s 401 %s\n\
Server: %s\n\
%s%s%s",
            CgiLib__HttpProtocolVersionPtr,
            CgiLibHttpStatusCodeText(StatusCode),
            ServerSoftwarePtr,
            RequestTimeGmtPtr == NULL ? "" : "Date: ",
            RequestTimeGmtPtr == NULL ? "" : RequestTimeGmtPtr,
            RequestTimeGmtPtr == NULL ? "" : "\n");
        if (argcnt > 2) fprintf (stdout, "WWW-Authenticate: ");
      }
      else
      if (ContentTypeText)
      {
         charcnt = fprintf (ResponseStdout,
"%s %d %s\n\
Server: %s\n\
%s%s%s\
Content-Type: %s%s%s%s",
            CgiLib__HttpProtocolVersionPtr,
            StatusCode, CgiLibHttpStatusCodeText(StatusCode),
            ServerSoftwarePtr,
            RequestTimeGmtPtr == NULL ? "" : "Date: ",
            RequestTimeGmtPtr == NULL ? "" : RequestTimeGmtPtr,
            RequestTimeGmtPtr == NULL ? "" : "\n",
            ContentType, CharsetPtr[0] ? "; charset=" : "", CharsetPtr,
            ContentTypeNewLine);
      }
      else
      {
         charcnt = fprintf (ResponseStdout,
"%s %d %s\n\
Server: %s\n\
%s%s%s\
Content-Type: %s\n",
            CgiLib__HttpProtocolVersionPtr,
            StatusCode, CgiLibHttpStatusCodeText(StatusCode),
            ServerSoftwarePtr,
            RequestTimeGmtPtr == NULL ? "" : "Date: ",
            RequestTimeGmtPtr == NULL ? "" : RequestTimeGmtPtr,
            RequestTimeGmtPtr == NULL ? "" : "\n",
            ContentType);
      }
   }
   else
   {
      /* vanilla CGI environment/response */
      if (StatusCode == 302)
      {
         if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE)
            charcnt = fprintf (ResponseStdout, "Location: ");
         else
            charcnt = fprintf (ResponseStdout,
"Status: 302 %s\n\
Location: ",
               CgiLibHttpStatusCodeText(StatusCode));
      }
      else
      if (StatusCode == 401)
      {
         charcnt = fprintf (ResponseStdout,
"Status: 401 %s\n",
            CgiLibHttpStatusCodeText(StatusCode));
        if (argcnt > 2) fprintf (stdout, "WWW-Authenticate: ");
      }
      else
      if (ContentTypeText)
      {
         ServerSoftwarePtr = CgiLib__GetVar ("WWW_SERVER_SOFTWARE", "");
         if (strstr (ServerSoftwarePtr, "WASD/5.") != NULL ||
             strstr (ServerSoftwarePtr, "WASD/6.0") != NULL)
         {
            /* bit of backward compatibility for WASD 5.n and 6.0 */
            charcnt = fprintf (ResponseStdout, "Content-Type: %s%s%s%s",
               ContentType, CharsetPtr[0] ? "; charset=" : "", CharsetPtr,
               ContentTypeNewLine);
         }
         else
         {
            /* all others, including WASD 6.1ff */
            if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE &&
                StatusCode / 100 == 2)
               charcnt = fprintf (ResponseStdout, "Content-Type: %s%s%s%s",
                                  ContentType, CharsetPtr[0] ?
                                  "; charset=" : "", CharsetPtr,
                                  ContentTypeNewLine);
            else
               charcnt = fprintf (ResponseStdout,
"Status: %d %s\n\
Content-Type: %s%s%s%s",
                  StatusCode, CgiLibHttpStatusCodeText(StatusCode),
                  ContentType, CharsetPtr[0] ?
                  "; charset=" : "", CharsetPtr,
                  ContentTypeNewLine);
         }
      }
      else
      {
         if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE &&
             StatusCode / 100 == 2)
            charcnt = fprintf (ResponseStdout, "Content-Type: %s\n",
                               ContentType);
         else
            charcnt = fprintf (ResponseStdout,
"Status: %d %s\n\
Content-Type: %s\n",
               StatusCode, CgiLibHttpStatusCodeText(StatusCode),
               ContentType);
      }
   }

   if (argcnt > 2)
   {
      /* more response header line(s)/information has been included */
      charcnt += vfprintf (ResponseStdout, FormatStringPtr, argptr);
      va_end (argptr);
   }

   if (StatusCode == 302 ||
       (StatusCode == 401 && argcnt > 2))
   {
      fputs ("\n", ResponseStdout);
      charcnt++;
   }

   if (CgiLib__Environment == CGILIB_ENVIRONMENT_WASD ||
       CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS)
   {
      if (CgiLib__ResponseStreamMode > 0)
         charcnt = fprintf (ResponseStdout,
                            "Script-Control: X-stream-mode=1\n");
      else
      if (CgiLib__ResponseStreamMode < 0)
         charcnt = fprintf (ResponseStdout,
                            "Script-Control: X-stream-mode=0\n");
      else
      if (CgiLib__ResponseRecordMode > 0)
         charcnt = fprintf (ResponseStdout,
                            "Script-Control: X-record-mode=1\n");
      else
      if (CgiLib__ResponseRecordMode < 0)
         charcnt = fprintf (ResponseStdout,
                            "Script-Control: X-record-mode=0\n");
      else
      if (CgiLib__EnvironmentStdoutType == CGILIB_ENVIRONMENT_STDOUT_BINARY)
         charcnt = fprintf (ResponseStdout,
                            "Script-Control: X-stream-mode=1\n");
      else
      if (CgiLib__EnvironmentStdoutType == CGILIB_ENVIRONMENT_STDOUT_RECORD)
         charcnt = fprintf (ResponseStdout,
                            "Script-Control: X-record-mode=1\n");

      if (CgiLib__ResponseBufferRecords > 0)
         charcnt = fprintf (ResponseStdout,
                            "Script-Control: X-buffer-records=1\n");
      else
      if (CgiLib__ResponseBufferRecords < 0)
         charcnt = fprintf (ResponseStdout,
                            "Script-Control: X-buffer-records=0\n");
   }

   fputs ("\n", ResponseStdout);
   charcnt++;

   fflush (ResponseStdout);

   CgiLib__ResponseCount += charcnt;

   return (charcnt);
}

/****************************************************************************/
/*
Generate an HTTP 302 redirect response.  If the format string begins "%!" then
the redirect is made absolute with the appropriate local server host name and
if necessary port prefixing whatever are supplied as parameters.  If the "%!"
does not precede the format string then it can either be a full absolute or
local redirection URL, it's just appended to the "Location: " field name.  The
format string can be for a 'printf()' with associated parameters supplied.
Strings fed to this function must be appropriately URL-encoded if necessary.
*/

int CgiLibResponseRedirect
(
char *FormatString,
...
)
{
   int  argcnt,
        charcnt;
   char  *FormatStringPtr,
         *HttpHostPtr,
         *HostPortPtr,
         *RequestTimeGmtPtr,
         *SchemePtr,
         *ServerNamePtr,
         *ServerPortPtr,
         *ServerSoftwarePtr;
   char  HostPort [256];
   va_list  argptr;

   /*********/
   /* begin */
   /*********/

   va_count (argcnt);

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibResponseRedirect() %d |%s|\n",
               argcnt, FormatString);

   FormatStringPtr = FormatString;

   if (*(USHORTPTR)FormatStringPtr == '%!' ||
       CgiLib__Environment == CGILIB_ENVIRONMENT_PURVEYOR)
   {
      if (*(USHORTPTR)FormatStringPtr == '%!') FormatStringPtr += 2;

      if (CgiLib__Environment == CGILIB_ENVIRONMENT_PURVEYOR)
      {
         /* Purveyor requires a full URL (scheme://server:port/path) */
         SchemePtr = CgiLibVarNull ("SECURITY_STATUS");
         if (!SchemePtr)
            SchemePtr = "http://";
         else
         if (strstr (SchemePtr, "SSL"))
            SchemePtr = "https://";
         else
            SchemePtr = "http://";
      }
      else
         SchemePtr = "//";

      HttpHostPtr = CgiLib__GetVar ("WWW_HTTP_HOST", "");
      if (HttpHostPtr[0])
      {
         /* use the request supplied host[:port] */
         HostPortPtr = HttpHostPtr;
      }
      else
      {
         /* build it up from the server name and port */
         ServerNamePtr = CgiLib__GetVar ("WWW_SERVER_NAME", "");
         ServerPortPtr = CgiLib__GetVar ("WWW_SERVER_PORT", "");
         if (!strcmp (ServerPortPtr, "80") &&
             !strcmp (ServerPortPtr, "443")) 
            HostPortPtr = ServerNamePtr;
         else
            sprintf (HostPortPtr = HostPort, "%s:%s",
                     ServerNamePtr, ServerPortPtr);
      }
   }
   else
      HostPortPtr = SchemePtr = "";

   CgiLib__ResponseStatusCode = 302;

   if (!CgiLib__ResponseCgi &&
       CgiLib__Environment == CGILIB_ENVIRONMENT_OSU)
   {
      /* full response header (only for OSU these days) */
      ServerSoftwarePtr = CgiLib__GetVar ("WWW_SERVER_SOFTWARE", "");
      if (!ServerSoftwarePtr[0])
         ServerSoftwarePtr = CgiLib__ResponseSoftwareIdPtr;
      RequestTimeGmtPtr = CgiLibVarNull ("REQUEST_TIME_GMT");
      CgiLibHttpProtocolVersion ();

      charcnt = fprintf (stdout,
"%s 302 %s\n\
Server: %s\n\
%s%s%s\
Content-Type: text/html\n\
Location: %s%s",
         CgiLib__HttpProtocolVersionPtr,
         CgiLibHttpStatusCodeText(302), ServerSoftwarePtr,
         RequestTimeGmtPtr == NULL ? "" : "Date: ",
         RequestTimeGmtPtr == NULL ? "" : RequestTimeGmtPtr,
         RequestTimeGmtPtr == NULL ? "" : "\n",
         SchemePtr, HostPortPtr);
   }
   else
   {
      /* vanilla CGI environment/response */
      charcnt = fprintf (stdout,
"Status: 302 %s\n\
%s\
Location: %s%s",
         CgiLibHttpStatusCodeText(302),
         CgiLib__Environment == CGILIB_ENVIRONMENT_OSU ?
            "Content-Type: text/html\n" : "",
         SchemePtr, HostPortPtr);
   }

   va_start (argptr, FormatString);
   vfprintf (stdout, FormatStringPtr, argptr);
   va_end (argptr);

   fputs ("\n\n", stdout);
   charcnt += 2;

   return (charcnt);
}

/*****************************************************************************/
/*
Generate an error report in the quasi-standard WASD format.  If 'StatusValue'
is non-zero then it is assumed to be a VMS status code and a message generated
from it.  If zero then only the format string is used.  The format string may
be a plain-text message or contain 'printf()' formatting characters with any
associated parameters. 
*/

int CgiLibResponseError
(
char *SrcFileName,
int SrcLineNumber,
int StatusValue,
char *FormatString,
...
)
{
   int  argcnt,
        charcnt,
        status,
        FullResponse;
   short int  Length;
   char  *cptr, *sptr, *zptr;
   char  FileName [128];
   va_list  argptr;

   /*********/
   /* begin */
   /*********/

   va_count (argcnt);

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibResponseError() %d %d\n", argcnt, StatusValue);

   FullResponse = !CgiLib__ResponseCount;

   charcnt = 0;

   /* 
      The source file format provided by the "__FILE__" macro will be
      "device:[directory]name.type;ver".  Reduce that to "name.type".
   */
   zptr = (sptr = FileName) + sizeof(FileName)-1;
   for (cptr = SrcFileName; *cptr; cptr++);
   while (cptr > SrcFileName && *cptr != ']') cptr--;
   if (*cptr == ']')
   {
      cptr++;
      while (*cptr && *cptr != ';' && sptr < zptr) *sptr++ = *cptr++;
      *sptr = '\0';
   }
   else
   {
      /* assume it's just a module name */
      strncpy (FileName, cptr, sizeof(FileName));
      FileName[sizeof(FileName)-1] = '\0';
   }

   if (FullResponse)
   {
      CgiLib__ResponseStatusCode = CgiLib__ResponseErrorStatus;
      CgiLibResponseHeader (CgiLib__ResponseErrorStatus, "text/html");
      charcnt += fprintf (stdout,
"<html>\n\
<head>\n\
%s\
<meta name=\"generator\" content=\"%s\">\n\
<meta name=\"module\" content=\"%s\">\n\
<meta name=\"line\" content=\"%d\">\n\
<meta name=\"environment\" content=\"%s\">\n\
<title>%s %d %s</title>\n\
</head>\n\
<body%s%s>\n",
         CgiLib__XUACompatiblePtr ? CgiLib__XUACompatiblePtr : "",
         CgiLib__ResponseSoftwareIdPtr, FileName, SrcLineNumber,
         CgiLibEnvironmentName(),
         CgiLib__ResponseErrorTitlePtr, CgiLib__ResponseErrorStatus,
         CgiLibHttpStatusCodeText(CgiLib__ResponseErrorStatus),
         CgiLib__ResponseBodyPtr ? " " : "", CgiLib__ResponseBodyPtr);
   }
   else
   /* this is a kludge originally for soyMAIL */
   if (StatusValue != -1)
   {
      charcnt += fprintf (stdout,
"\n<p><hr size=\"3\" width=\"100%%\" noshade>\n\
<!-- SoftwareID: %s Module: %s Line: %d -->\n",
          CgiLib__ResponseSoftwareIdPtr, FileName, SrcLineNumber);
   }

   charcnt += fprintf (stdout,
"<font size=\"+1\"><b>%s %d</b> &nbsp;-&nbsp; %s</font>\n",
      CgiLib__ResponseErrorTitlePtr,
      CgiLib__ResponseErrorStatus,
      CgiLib__ResponseErrorMessagePtr);

   if (StatusValue && StatusValue != -1 /* see kludge above */)
   {
#     pragma message __save
#     pragma message disable (ADDRCONSTEXT)
      char  StatusMsg [256];
      $DESCRIPTOR (StatusMsgDsc, StatusMsg);

      /* cater for VAX environment as best we can */
#     pragma message disable (IMPLICITFUNC)
#     ifdef CGILIB_OBJECT_MODULE
#        ifdef __VAX
#           define SYS$GETMSG sys$getmsg
#        endif
#     endif
      status = sys$getmsg (StatusValue, &Length, &StatusMsgDsc, 1, 0);
#     pragma message __restore

      if (status & 1)
      {
         StatusMsg[Length] = '\0';
         StatusMsg[0] = toupper(StatusMsg[0]);
         charcnt += fprintf (stdout, "<p><!-- %%X%08.08X -->%s ... ",
                             StatusValue, StatusMsg);
      }
      else
         exit (status);
   }
   else
   {
      fputs ("<p>", stdout);
      charcnt += 4;
   }

   va_start (argptr, FormatString);
   charcnt += vfprintf (stdout, FormatString, argptr);
   va_end (argptr);

   fputs ("\n", stdout);
   charcnt++;

   if (CgiLib__ResponseErrorInfoPtr != NULL &&
       CgiLib__ResponseErrorInfoPtr[0])
      charcnt += fprintf (stdout, "<p>%s", CgiLib__ResponseErrorInfoPtr);

   cptr = CgiLib__GetVar ("WWW_SERVER_SIGNATURE", "");
   if (cptr[0])
      charcnt += fprintf (stdout,
         "<p><hr width=\"85%%\" align=\"left\" size=\"2\" noshade>\n%s", cptr);

   if (FullResponse)
   {
      fputs (
"</body>\n\
</html>\n",
         stdout);
      charcnt += 16;
   }

   CgiLib__ResponseCount += charcnt;

   return (charcnt);
}

/*****************************************************************************/
/*
Generate a "success" report in the defacto standard WASD format.  The format
string may be a plain-text message or contain 'printf()' formatting characters
with any associated parameters. 
*/

int CgiLibResponseSuccess
(
char *FormatString,
...
)
{
   int  argcnt,
        charcnt;
   short int  Length;
   char  *cptr;
   va_list  argptr;

   /*********/
   /* begin */
   /*********/

   va_count (argcnt);

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSuccess() %d\n", argcnt);

   charcnt = 0;

   CgiLib__ResponseStatusCode = CgiLib__ResponseSuccessStatus;
   CgiLibResponseHeader (CgiLib__ResponseSuccessStatus, "text/html");
   charcnt += fprintf (stdout,
"<html>\n\
<head>\n\
%s\
<meta name=\"generator\" content=\"%s\">\n\
<meta name=\"environment\" content=\"%s\">\n\
<title>%s %d %s</title>\n\
</head>\n\
<body%s%s>\n\
<font size=\"+1\"><b>%s %d</b> &nbsp;-&nbsp; %s</font>\n\
<p>",
      CgiLib__XUACompatiblePtr ? CgiLib__XUACompatiblePtr : "",
      CgiLib__ResponseSoftwareIdPtr,
      CgiLibEnvironmentName(),
      CgiLib__ResponseSuccessTitlePtr, CgiLib__ResponseSuccessStatus,
      CgiLibHttpStatusCodeText(CgiLib__ResponseSuccessStatus),
      CgiLib__ResponseBodyPtr ? " " : "", CgiLib__ResponseBodyPtr,
      CgiLib__ResponseSuccessTitlePtr,
      CgiLib__ResponseSuccessStatus,
      CgiLib__ResponseSuccessMsgPtr);

   va_start (argptr, FormatString);
   charcnt += vfprintf (stdout, FormatString, argptr);
   va_end (argptr);

   cptr = CgiLib__GetVar ("WWW_SERVER_SIGNATURE", "");
   if (cptr[0])
      charcnt += fprintf (stdout,
         "<p><hr width=\"85%%\" align=\"left\" size=\"2\" noshade>\n%s", cptr);

   fputs (
"</body>\n\
</html>\n",
      stdout);
   charcnt += 17;

   CgiLib__ResponseCount += charcnt;

   return (charcnt);
}

/*****************************************************************************/
/*
Return the HTTP status code (e.g. 200, 302) set by response generation.
*/

int CgiLibResponseGetStatus ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseGetStatus()\n");

   return (CgiLib__ResponseStatusCode);
}

/*****************************************************************************/
/*
Tell the WASD server via the CGI response that it should interpret the response
body as being discrete records requiring carriage-control.  Return the previous
value.
*/

int CgiLibResponseSetRecordMode (int enable)

{
   int  prevalue;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibResponseSetRecordMode() %d\n", enable);

   prevalue = CgiLib__ResponseRecordMode;

   if (enable)
      CgiLib__ResponseRecordMode = 1;
   else
      CgiLib__ResponseRecordMode = -1;
   CgiLib__ResponseStreamMode = 0;

   return (prevalue > 0);
}

/*****************************************************************************/
/*
Tell the WASD server via the CGI response that it should consider the response
body as already containing all required carriage-control.  Return the previous
value.
*/

int CgiLibResponseSetStreamMode (int enable)

{
   int  prevalue;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibResponseSetStreamMode() %d\n", enable);

   prevalue = CgiLib__ResponseStreamMode;

   if (enable)
      CgiLib__ResponseStreamMode = 1;
   else
      CgiLib__ResponseStreamMode = -1;
   CgiLib__ResponseRecordMode = 0;

   return (prevalue > 0);
}

/*****************************************************************************/
/*
Tell the WASD server via the CGI response to buffer discrete records, flushing
only when full.  Return the previous value.
*/

int CgiLibResponseSetBufferRecords (int enable)

{
   int  prevalue;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibResponseSetBufferRecords() %d\n", enable);

   prevalue = CgiLib__ResponseBufferRecords;

   if (enable)
      CgiLib__ResponseBufferRecords = 1;
   else
      CgiLib__ResponseBufferRecords = -1;

   return (prevalue > 0);
}

/*****************************************************************************/
/*
Return the a pointer to abbreviated meaning of the supplied HTTP status code.
These are typical of those included on the response header status line.
*/

char* CgiLibHttpStatusCodeText (int StatusCode)

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibHttpStatusCodeText() %d\n", StatusCode);

   switch (StatusCode)
   {
      case 000 : return ("Script Error!");
      case 100 : return ("Continue"); /* (HTTP/1.1) */
      case 101 : return ("Switching Protocols"); /* (HTTP/1.1) */
      case 200 : return ("OK");
      case 201 : return ("Created");
      case 202 : return ("Accepted");
      case 203 : return ("Non-authoritative"); /* (HTTP/1.1) */
      case 204 : return ("No Content");
      case 205 : return ("Reset Content"); /* (HTTP/1.1) */
      case 206 : return ("Partial Content"); /* (HTTP/1.1) */
      case 300 : return ("Multiple Choices"); /* (HTTP/1.1) */
      case 301 : return ("Moved Permanently");
      case 302 : return ("Found (Moved Temporarily)");
      case 303 : return ("See Other"); /* (HTTP/1.1) */
      case 304 : return ("Not Modified");
      case 305 : return ("Use Proxy"); /* (HTTP/1.1) */
      case 306 : return ("Temporary Redirect"); /* (HTTP/1.1) */
      case 400 : return ("Bad Request");
      case 401 : return ("Authorization Required");
      case 402 : return ("Payment Required"); /* (HTTP/1.1) */
      case 403 : return ("Forbidden");
      case 404 : return ("Not Found");
      case 405 : return ("Method Not Allowed"); /* (HTTP/1.1) */
      case 406 : return ("Not Acceptable"); /* (HTTP/1.1) */
      case 407 : return ("Proxy Authentication Required"); /* (HTTP/1.1) */
      case 408 : return ("Request Timeout"); /* (HTTP/1.1) */
      case 409 : return ("Conflict"); /* (HTTP/1.1) */
      case 410 : return ("Gone"); /* (HTTP/1.1) */
      case 411 : return ("Length Required"); /* (HTTP/1.1) */
      case 412 : return ("Precondition Failed"); /* (HTTP/1.1) */
      case 413 : return ("Request entity too large"); /* (HTTP/1.1) */
      case 414 : return ("Request URI Too Long"); /* (HTTP/1.1) */
      case 415 : return ("Unsupported Media Type"); /* (HTTP/1.1) */
      case 416 : return ("Requested Range Not Satisfiable"); /* (HTTP/1.1) */
      case 417 : return ("Expectation Failed"); /* (HTTP/1.1) */
      case 500 : return ("Internal Error");
      case 501 : return ("Not Implemented");
      case 502 : return ("Bad Gateway");
      case 503 : return ("Service Unavailable");
      case 504 : return ("Gateway Timeout"); /* (HTTP/1.1) */
      case 505 : return ("HTTP Version Not Supported"); /* (HTTP/1.1) */
      default :  return ("Unknown Code!");
   }
}

/*****************************************************************************/
/*
Set the <body> tag parameters.  Returns pointer to any previous.
*/

char* CgiLibResponseSetBody (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetBody()\n");

   sptr = CgiLib__ResponseBodyPtr;
   CgiLib__ResponseBodyPtr = cptr;
   return (sptr);
}

/*****************************************************************************/
/*
Set the response character set.  Returns pointer to any previous.
*/

char* CgiLibResponseSetCharset (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibResponseSetCharset() |%s|\n", cptr);

   sptr = CgiLib__ResponseCharsetPtr;
   if (!(CgiLib__ResponseCharsetPtr = cptr))
      CgiLib__ResponseCharsetPtr = CgiLib__ResponseDefCharsetPtr;
   return (sptr);
}

/*****************************************************************************/
/*
Set the default character set.  Returns pointer to any previous.
*/

char* CgiLibResponseSetDefaultCharset (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetDefaultCharset()\n");

   sptr = CgiLib__ResponseDefCharsetPtr;
   if (!(CgiLib__ResponseDefCharsetPtr = cptr))
      CgiLib__ResponseDefCharsetPtr = CGILIB_RESPONSE_DEFAULT_CHARSET;
   return (sptr);
}

/*****************************************************************************/
/*
Set the error message.  Returns pointer to any previous.
*/

char* CgiLibResponseSetErrorMessage (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetErrorMessage()\n");

   sptr = CgiLib__ResponseErrorMessagePtr;
   CgiLib__ResponseErrorMessagePtr = cptr;
   return (sptr);
}

/*****************************************************************************/
/*
Set the error HTTP status code.  Returns pointer to any previous.
*/

int CgiLibResponseSetErrorStatus (int status)

{
   int  pstatus;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetErrorStatus()\n");

   pstatus = CgiLib__ResponseErrorStatus;
   CgiLib__ResponseErrorStatus = status;
   return (pstatus);
}

/*****************************************************************************/
/*
Set the error <title> string.  Returns pointer to any previous.
*/

char* CgiLibResponseSetErrorTitle (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetErrorTitle()\n");

   sptr = CgiLib__ResponseErrorTitlePtr;
   CgiLib__ResponseErrorTitlePtr = cptr;
   return (sptr);
}

/*****************************************************************************/
/*
Set the error additional information string.  Returns pointer to any previous.
*/

char* CgiLibResponseSetErrorInfo (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetErrorInfo()\n");

   sptr = CgiLib__ResponseErrorInfoPtr;
   CgiLib__ResponseErrorInfoPtr = cptr;
   return (sptr);
}

/*****************************************************************************/
/*
Set the success message string.  Returns pointer to any previous.
*/

char* CgiLibResponseSetSuccessMessage (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetSuccessMessage()\n");

   sptr = CgiLib__ResponseSuccessMsgPtr;
   CgiLib__ResponseSuccessMsgPtr = cptr;
   return (sptr);
}

/*****************************************************************************/
/*
Set the success HTTP status code.  Returns pointer to any previous.
*/

int CgiLibResponseSetSuccessStatus (int status)

{
   int  pstatus;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetSuccessStatus()\n");

   pstatus = CgiLib__ResponseSuccessStatus;
   CgiLib__ResponseSuccessStatus = status;
   return (pstatus);
}

/*****************************************************************************/
/*
Set the success <title> string.  Returns pointer to any previous.
*/

char* CgiLibResponseSetSuccessTitle (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetSuccessTitle()\n");

   sptr = CgiLib__ResponseSuccessTitlePtr;
   CgiLib__ResponseSuccessTitlePtr = cptr;
   return (sptr);
}

/*****************************************************************************/
/*
Set the software ID string.  Returns pointer to any previous.
*/

char* CgiLibResponseSetSoftwareID (char *cptr)

{
   char  *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibResponseSetSoftwareID()\n");

   sptr = CgiLib__ResponseSoftwareIdPtr;
   CgiLib__ResponseSoftwareIdPtr = cptr;
   if (CgiLib__Debug) fprintf (stdout, "|%s|%s|\n", cptr, sptr);
   return (sptr);
}

/*****************************************************************************/

                        /**************************/
                        /* URL/HTML ENCODE/DECODE */
                        /**************************/

/*****************************************************************************/
/*
Decode URL-encoded string.  Resultant string is always the same size or smaller
so it can be done in-situ!  Returns the size of the resultant string.
*/

int CgiLibUrlDecode (char *String)

{
   unsigned char  ch,
                  pch = 0;
   char  *cptr, *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibUrlDecode() |%s|\n", String);

   cptr = sptr = String;
   while (*cptr)
   {
      switch (*cptr)
      {
         case '+' :

            *sptr++ = ' ';
            cptr++;
            pch = 0;
            continue;

         case '%' :

            cptr++;

            while (*cptr == '\r' || *cptr == '\n') cptr++;
            ch = 0;
            if (*cptr >= '0' && *cptr <= '9')
               ch = (*cptr - (int)'0') << 4;
            else
            if (toupper(*cptr) >= 'A' && toupper(*cptr) <= 'F')
               ch = (toupper(*cptr) - (int)'A' + 10) << 4;
            else
            {
               *String = '\0';
               return (-1);
            }
            if (*cptr) cptr++;
            while (*cptr == '\r' || *cptr == '\n') cptr++;
            if (*cptr >= '0' && *cptr <= '9')
               ch += (*cptr - (int)'0');
            else
            if (toupper(*cptr) >= 'A' && toupper(*cptr) <= 'F')
               ch += (toupper(*cptr) - (int)'A' + 10);
            else
            {
               *String = '\0';
               return (-1);
            }
            if (*cptr) cptr++;

            /* if URL-encoded 8 bit UTF-8 (e.g. %C3%A9) */
            if (pch == 0xc2 && ch >= 0x80 && ch <= 0xbf)
            {
               *(sptr-1) = ch;
               pch = 0;
            }
            else
            if (pch == 0xc3 && ch >= 0x80 && ch <= 0xbf)
            {
               *(sptr-1) = ch + 0x40;
               pch = 0;
            }
            else
               *sptr++ = pch = ch;

            continue;

         case '\r' :
         case '\n' :

            cptr++;
            pch = 0;
            continue;

         default :
            
            *sptr++ = *cptr++;
            pch = 0;

      }
   }
   *sptr = '\0';

   if (CgiLib__Debug) fprintf (stdout, "|%s|\n", String);
   return (sptr-String);
}

/****************************************************************************/
/*
URL-encode (nearly) all non-alpha-numeric characters. If 'EncodedString' is
NULL sufficient memory will be dynamically allocated to hold the encoded
string.  For fixed size 'EncodedString' it will not overflow the supplied
string but does not return any indication it reached the limit.  Returns the
length of the encoded string or a pointer to the encoded string (which should
be cast to (char*) by the calling routine). 
*/ 
 
int CgiLibUrlEncode
(
char *PlainString,
int NumberOfChars,
char *EncodedString,
int SizeOfEncodedString
)
{
   static char  EmptyString [] = "",
                HexDigits [] = "0123456789abcdef";

   int  ccnt,
        CurrentLength,
        EncodedSize;
   char  *cptr, *sptr, *zptr,
         *EncodedPtr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibUrlEncode() |%s| %d\n",
               PlainString, NumberOfChars);

   if (!*(cptr = PlainString))
   {
      if (EncodedString == NULL)
         return ((int)EmptyString);
      else
      {
         EncodedString[0] = '\0';
         return (0);
      }
   }

   if (EncodedString == NULL)
   {
      sptr = zptr = EncodedPtr = NULL;
      EncodedSize = 0;
   }
   else
   {
      sptr = EncodedPtr = EncodedString;
      if (SizeOfEncodedString == -1)
         zptr = (char*)INT_MAX;
      else
         zptr = sptr + SizeOfEncodedString - 1;
   }

   if (NumberOfChars == -1)
      ccnt = INT_MAX;
   else
      ccnt = NumberOfChars;

   while (*cptr && ccnt)
   {
      if (EncodedString == NULL && sptr >= zptr)
      {
         /* out of storage (or first use) get more (or some) memory */
         CurrentLength = sptr - EncodedPtr;
         if (CgiLib__VeeMemInUse)
            EncodedPtr = CgiLibVeeMemRealloc (EncodedPtr,
                                              EncodedSize+CGILIB_ENCODED_CHUNK);
         else
            EncodedPtr = realloc (EncodedPtr,
                                  EncodedSize+CGILIB_ENCODED_CHUNK);
         if (!EncodedPtr)
            if (CgiLib__VeeMemContinue)
               return ((int)NULL);
            else
               exit (vaxc$errno);
         EncodedSize += CGILIB_ENCODED_CHUNK;
         /* recalculate pointers */
         sptr = EncodedPtr + CurrentLength;
         /* three allows a worst-case %nn encoding without failing */
         zptr = EncodedPtr + EncodedSize - 3;
      }
      else
      if (sptr >= zptr)
         break;

      if (isalnum(*cptr) ||
          *cptr == '/' ||
          *cptr == '-' ||
          *cptr == '_' ||
          *cptr == '.' ||
          /* strictly, the following characters should be encoded */
          *cptr == '$' ||
          *cptr == '*' ||
          *cptr == ';' ||
          *cptr == '~' ||
          *cptr == '^')
      {
         *sptr++ = *cptr++;
         ccnt--;
         continue;
      }

      if (sptr < zptr) *sptr++ = '%';
      if (sptr < zptr) *sptr++ = HexDigits[(*cptr & 0xf0) >> 4];
      if (sptr < zptr) *sptr++ = HexDigits[*cptr & 0x0f];
      cptr++;
      ccnt--;
   }
   *sptr = '\0';
   if (CgiLib__Debug)
      fprintf (stdout, "%d |%s|\n", sptr-EncodedPtr, EncodedPtr);

   if (EncodedString == NULL)
      return ((int)EncodedPtr);
   else
      return (sptr - EncodedPtr);
}
 
/*****************************************************************************/
/*
URL-encode (%nn) a possibly extended specification file name.  This can be done
in two ways.  Leave the VMS extended file specification escape sequences in
place (e.g. "^_") but encode absolutely forbidden characters (.e.g ' ', '?',
"%", etc.), called 'RelaxedEncode' here.  Or a strict encode, where the
extended escaped sequences are first un-escaped into characters, then those
charaters URL-encoded as necessary. If 'ForceLower' true, and no extended file
specification characters were found (e.g. lower-case, escaped characters) then
replace all upper-case alphabetics with lower-case.

If 'EncodedString' is NULL sufficient memory will be dynamically allocated to
hold the encoded string.  For fixed size 'EncodedString' it will not overflow
the supplied string but does not return any indication it reached the limit. 
Returns the length of the encoded string or a pointer to the encoded string
(which should be cast to (char*) by the calling routine). 
*/ 

int CgiLibUrlEncodeFileName
(
char *FileName,
char *EncodedString,
int SizeOfEncodedString,
int RelaxedEncode,
int ForceLower
)
{
   static char  EmptyString [] = "",
                HexDigits [] = "0123456789abcdef";

   int  CurrentLength,
        EncodedSize,
        HitExtended;
   unsigned char  ch;
   char  *cptr, *sptr, *zptr,
         *EncodedPtr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibUrlEncodeFileName() |%s| %d %d\n",
               FileName, RelaxedEncode, ForceLower);

   if (!*(cptr = FileName))
   {
      if (EncodedString == NULL)
         return ((int)EmptyString);
      else
      {
         EncodedString[0] = '\0';
         return (0);
      }
   }

   if (EncodedString == NULL)
   {
      sptr = zptr = EncodedPtr = NULL;
      EncodedSize = 0;
   }
   else
   {
      sptr = EncodedPtr = EncodedString;
      if (SizeOfEncodedString == -1)
         zptr = (char*)INT_MAX;
      else
         zptr = sptr + SizeOfEncodedString - 1;
   }

   HitExtended = 0;
   cptr = FileName;
   while (ch = *cptr)
   {
      if (EncodedString == NULL && sptr >= zptr)
      {
         /* out of storage (or first use) get more (or some) memory */
         CurrentLength = sptr - EncodedPtr;
         if (CgiLib__VeeMemInUse)
            EncodedPtr = CgiLibVeeMemRealloc (EncodedPtr,
                                              EncodedSize+CGILIB_ENCODED_CHUNK);
         else
            EncodedPtr = realloc (EncodedPtr,
                                  EncodedSize+CGILIB_ENCODED_CHUNK);
         if (!EncodedPtr)
            if (CgiLib__VeeMemContinue)
               return ((int)NULL);
            else
               exit (vaxc$errno);
         EncodedSize += CGILIB_ENCODED_CHUNK;
         /* recalculate pointers */
         sptr = EncodedPtr + CurrentLength;
         /* three allows a worst-case %nn encoding without failing */
         zptr = EncodedPtr + EncodedSize - 3;
      }
      else
      if (sptr >= zptr)
         break;

      if (islower(ch)) HitExtended = 1;

      if (!RelaxedEncode && ch == '^')
      {
         /* extended file specification escape character */
         HitExtended = 1;
         ch = *++cptr;
         switch (ch)
         {
            case '!' :
            case '#' :
            case '&' :
            case '\'' :
            case '`' :
            case '(' :
            case ')' :
            case '+' :
            case '@' :
            case '{' :
            case '}' :
            case '.' :
            case ',' :
            case ';' :
            case '[' :
            case ']' :
            case '%' :
            case '^' :
            case '=' :
            case ' ' :
               break;
            case '_' :
               ch = ' ';
               break;
            default :
               if (isxdigit (ch))
               {
                  ch = 0;
                  if (*cptr >= '0' && *cptr <= '9')
                     ch = (*cptr - (int)'0') << 4;
                  else
                  if (tolower(*cptr) >= 'a' && tolower(*cptr) <= 'f')
                     ch = (tolower(*cptr) - (int)'a' + 10) << 4;
                  cptr++;   
                  if (*cptr >= '0' && *cptr <= '9')
                     ch += (*cptr - (int)'0');
                  else
                  if (tolower(*cptr) >= 'a' && tolower(*cptr) <= 'f')
                     ch += (tolower(*cptr) - (int)'a' + 10);
               }
               else
                  ch = *cptr;
         }
      }

      /* URL-encode if necessary */
      if (isalnum(ch) ||
          ch == '/' ||
          ch == '-' ||
          ch == '_' ||
          ch == '.' ||
          ch == '$' ||
          ch == '*' ||
          ch == ':' ||
          ch == ';' ||
          (RelaxedEncode &&
           (ch == ',' ||
            ch == '\'' ||
            ch == '=' ||
            ch == '~' ||
            ch == '^' ||
            ch == '[' ||
            ch == ']' ||
            ch == '(' ||
            ch == ')' ||
            ch == '{' ||
            ch == '}' )))
         *sptr++ = ch;
      else
      {
         if (sptr < zptr) *sptr++ = '%';
         if (sptr < zptr) *sptr++ = HexDigits[(ch & 0xf0) >> 4];
         if (sptr < zptr) *sptr++ = HexDigits[ch & 0x0f];
      }
      if (*cptr) cptr++;
   }

   *sptr = '\0';

   /* if it's not an extended specification then force to lower-case */
   if (ForceLower && !HitExtended)
      for (sptr = EncodedPtr; *sptr; sptr++)
         if (isupper(*sptr)) *sptr = tolower(*sptr);

   if (CgiLib__Debug)
      fprintf (stdout, "%d |%s|\n", sptr-EncodedPtr, EncodedPtr);

   if (EncodedString == NULL)
      return ((int)EncodedPtr);
   else
      return (sptr - EncodedPtr);
}

/****************************************************************************/
/*
Escape plain-text characters forbidden to occur in HTML documents (i.e. '<',
'>' and '&').  If 'EscapedString' is NULL sufficient memory will be dynamically
allocated to hold the encoded string.  For fixed size 'EscapedString' it will
not overflow the supplied string but does not return any indication it reached
the limit.  Returns the length of the escaped string or a pointer to the
encoded string (which should be cast to (char*) by the calling routine).
'AnchorUrls' may be used to turn HTML URLs into HTML anchors in the text by
calling with CGILIB_ANCHOR_WEB.  It will also attempt to detect mail addresses
(anything like 'this@wherever.host.name') and create "mailto:" links out of
them, call with CGILIB_ANCHOR_MAIL.  To get both use a bit-wise OR.
*/ 
 
int CgiLibHtmlEscape
(
char *PlainString,
int NumberOfChars,
char *EscapedString,
int SizeOfEscapedString
)
{
   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibHtmlEscape() |%s| %d\n",
               PlainString, NumberOfChars);

   return (CgiLibAnchorHtmlEscape (PlainString, NumberOfChars,
                                   EscapedString, SizeOfEscapedString,
                                   CGILIB_ANCHOR_NONE));
}

int CgiLibAnchorHtmlEscape
(
char *PlainString,
int NumberOfChars,
char *EscapedString,
int SizeOfEscapedString,
int AnchorUrls
)
{
   static char  EmptyString [] = "";

   int  ccnt, len, tcnt,
        AtCount,
        CurrentLength,
        EscapedSize,
        PeriodCount,
        SchemeLength,
        SplitAnchor,
        SplitCount,
        UrlEscapedLength,
        UrlOriginalLength,
        UrlSplitEscapedLength,
        WasMailAddress,
        WasMailtoLink;
   char  *cptr, *sptr, *tptr, *zptr,
         *EscapedPtr,
         *UrlAnchorPtr,
         *UrlEscapedPtr,
         *UrlOriginalPtr,
         *UrlSplitEscapedPtr;
   char  UrlOriginal [1024+128];

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibAnchorHtmlEscape() |%s| %d %d\n",
               PlainString, NumberOfChars, AnchorUrls);

   if (!PlainString)
   {
      if (EscapedString == NULL) return ((int)NULL);
      if (SizeOfEscapedString >= 1) *EscapedString = '\0';
      return (0);
   }

   if (!*(cptr = PlainString))
   {
      if (EscapedString == NULL)
         return ((int)EmptyString);
      else
      {
         EscapedString[0] = '\0';
         return (0);
      }
   }

   if (EscapedString == NULL)
   {
      sptr = zptr = EscapedPtr = NULL;
      EscapedSize = 0;
   }
   else
   {
      sptr = EscapedPtr = EscapedString;
      if (SizeOfEscapedString == -1)
         zptr = (char*)INT_MAX;
      else
         zptr = sptr + SizeOfEscapedString - 1;
   }

   if (NumberOfChars == -1)
      ccnt = INT_MAX;
   else
      ccnt = NumberOfChars;

   while (*cptr && ccnt)
   {
      if (AnchorUrls != CGILIB_ANCHOR_NONE)
      {
         UrlOriginalLength = WasMailAddress = WasMailtoLink = SchemeLength = 0;
         UrlOriginal[0] = '\0';

         if ((AnchorUrls & CGILIB_ANCHOR_MASK1 & CGILIB_ANCHOR_WEB) &&
             ccnt >= 6 &&
             (cptr[3] == ':' || cptr[4] == ':' ||
              cptr[5] == ':' || cptr[6] == ':') &&
             (!memcmp (cptr, "http://", SchemeLength = 7) ||
              !memcmp (cptr, "https://", SchemeLength = 8) ||
              !memcmp (cptr, "mailto:", SchemeLength = 7) ||
              !memcmp (cptr, "file://", SchemeLength = 7) ||
              !memcmp (cptr, "ftp://", SchemeLength = 6) ||
              !memcmp (cptr, "gopher://", SchemeLength = 9) ||
              !memcmp (cptr, "news://", SchemeLength = 7) ||
              !memcmp (cptr, "wais://", SchemeLength = 7)))
         {
            /***********/
            /* web URL */
            /***********/

            if (!memcmp (cptr, "mailto:", 7))
            {
               WasMailAddress = WasMailtoLink = 1;
               if (CgiLib__soyMAILhack)
               {
                  /* don't need the scheme */
                  cptr += SchemeLength;
                  ccnt -= SchemeLength;
               }
            }

            tptr = UrlOriginal;
            while (ccnt && *cptr && !isspace(*cptr) &&
                   tptr < UrlOriginal+sizeof(UrlOriginal)-1)
            {
               *tptr++ = *cptr++;
               ccnt--;
            }
            if (tptr < UrlOriginal+sizeof(UrlOriginal)-1)
            {
               /* if trailed by what is probably textual punctuation */
               while (tptr > UrlOriginal &&
                      (tptr[-1] == '.' ||
                       tptr[-1] == ',' ||
                       tptr[-1] == ')' ||
                       tptr[-1] == ']' ||
                       tptr[-1] == '>' ||
                       tptr[-1] == '\"' ||
                       tptr[-1] == '\'' ||
                       tptr[-1] == '!'))
               {
                  tptr--;
                  cptr--;
                  ccnt++;
               }
            }
            *tptr = '\0';
            UrlOriginalLength = tptr - UrlOriginal;

            if (!UrlOriginalLength ||
                UrlOriginalLength == SchemeLength)
            {
               /* just and empty scheme, replace the text */
               cptr -= SchemeLength;
               ccnt += SchemeLength;
               UrlOriginalLength = WasMailAddress = WasMailtoLink = 0;
               UrlOriginal[0] = '\0';
            }
         }
         else
         if ((AnchorUrls & CGILIB_ANCHOR_MASK1 & CGILIB_ANCHOR_MAIL) &&
             isalnum (*cptr))
         {
            /************************************/
            /* look for a possible mail address */
            /************************************/

            AtCount = PeriodCount = 0;
            tcnt = ccnt;
            tptr = cptr;
            while (ccnt && *cptr &&
                   (isalnum(*cptr) || *cptr == '@' || *cptr == '.' ||
                                      *cptr == '_' || *cptr == '-'))
            {
               if (*cptr == '@')
               {
                  PeriodCount = 0;
                  AtCount++;
               }
               else
               if (*cptr == '.')
                  PeriodCount++;
               ccnt--;
               cptr++;
            }
            /* mail addresses shouldn't have a trailing period! */
            if (*(cptr-1) == '.' && PeriodCount) PeriodCount--;
            ccnt = tcnt;
            cptr = tptr;
            if (WasMailAddress = (AtCount == 1 && PeriodCount >= 1))
            {
               /***************************/
               /* mail address (probably) */
               /***************************/

               tptr = UrlOriginal;
               if (!CgiLib__soyMAILhack)
               {
                  /* fudge the scheme */
                  strcpy (tptr, "mailto:");
                  tptr += 7;
               }
               while (ccnt && *cptr &&
                      (isalnum(*cptr) || *cptr == '@' || *cptr == '.' ||
                                         *cptr == '_' || *cptr == '-') &&
                      tptr < UrlOriginal+sizeof(UrlOriginal)-1)
               {
                  ccnt--;
                  *tptr++ = *cptr++;
               }
               /* mail addresses shouldn't have a trailing period! */
               if (*(cptr-1) == '.')
               {
                  ccnt++;
                  cptr--;
                  tptr--;
               }
               *tptr = '\0';
               UrlOriginalLength = tptr - UrlOriginal;
            }
         }

         if (UrlOriginalLength)
         {
            /***************************/
            /* make URL into an anchor */
            /***************************/

            if ((len = UrlOriginalLength) > sizeof(UrlOriginal)-1)
               exit (SS$_BUGCHECK);
            UrlOriginalPtr = UrlOriginal;

            if (len >= 2 &&
                (!WasMailAddress || (WasMailAddress && CgiLib__soyMAILhack)) &&
                AnchorUrls != CGILIB_ANCHOR_ALL &&
                AnchorUrls & CGILIB_ANCHOR_MASK2 & CGILIB_ANCHOR_SPLIT)
            {
               SplitAnchor = 1;
               SplitCount = 2;
               len /= 2;
            }
            else
            {
               SplitAnchor = 0;
               SplitCount = 1;
            }

            UrlEscapedPtr = (char*)CgiLibHtmlEscape (UrlOriginalPtr,
                                                     -1, NULL, 0);
            UrlEscapedLength = strlen(UrlEscapedPtr);

            while (SplitCount--)
            {
               UrlSplitEscapedPtr = (char*)CgiLibHtmlEscape (UrlOriginalPtr,
                                                             len, NULL, 0);
               UrlSplitEscapedLength = strlen(UrlSplitEscapedPtr);

               if (SplitCount)
               {
                  UrlOriginalPtr += len;
                  len = strlen(UrlOriginalPtr);
               }

               if (CgiLib__Debug)
                  fprintf (stdout, "Url |%s|%s|\n", UrlOriginal, UrlEscapedPtr);

               if (WasMailAddress && CgiLib__soyMAILhack)
               {
                  if (CgiLib__VeeMemInUse)
                     tptr = UrlAnchorPtr =
                        CgiLibVeeMemCalloc (UrlEscapedLength +
                                            UrlSplitEscapedLength +
                                            strlen(CgiLib__soyMAILhack) + 64);
                  else
                     tptr = UrlAnchorPtr =
                        calloc (1, UrlEscapedLength +
                                   UrlSplitEscapedLength +
                                   strlen(CgiLib__soyMAILhack) + 64);
               }
               else
               {
                  if (CgiLib__VeeMemInUse)
                     tptr = UrlAnchorPtr =
                        CgiLibVeeMemCalloc (UrlEscapedLength +
                                            UrlSplitEscapedLength + 64);
                  else
                     tptr = UrlAnchorPtr =
                        calloc (1, UrlEscapedLength +
                                   UrlSplitEscapedLength + 64);
               }
               if (tptr == NULL)
                  if (CgiLib__VeeMemContinue)
                     return ((int)NULL);
                  else
                     exit (vaxc$errno);

               strcpy (tptr, "<a href=\"");
               tptr += 9;

               if (WasMailAddress && CgiLib__soyMAILhack)
               {
                  strcpy (tptr, CgiLib__soyMAILhack); 
                  while (*tptr) tptr++;
               }

               strcpy (tptr, UrlEscapedPtr);
               tptr += UrlEscapedLength;

               if (!SplitAnchor || SplitCount)
               {
                  strcpy (tptr, "\" target=\"_top\">");
                  tptr += 16;
               }
               else
               {
                  strcpy (tptr, "\" target=\"_blank\">");
                  tptr += 18;
               }

               if (WasMailAddress && !WasMailtoLink && !CgiLib__soyMAILhack)
               {
                  /* don't need the introduced "mailto:" in the text */
                  strcpy (tptr, UrlSplitEscapedPtr+7);
                  tptr += UrlSplitEscapedLength-7;
               }
               else
               {
                  strcpy (tptr, UrlSplitEscapedPtr);
                  tptr += UrlSplitEscapedLength;
               }

               strcpy (tptr, "</A>");

               if (CgiLib__Debug)
                  fprintf (stdout, "UrlAnchorPtr |%s|\n", UrlAnchorPtr);

               for (tptr = UrlAnchorPtr; *tptr; *sptr++ = *tptr++)
               {
                  if (EscapedString == NULL && sptr >= zptr)
                  {
                     /* out of storage (or first use) get memory */
                     CurrentLength = sptr - EscapedPtr;
                     if (CgiLib__VeeMemInUse)
                        EscapedPtr = CgiLibVeeMemRealloc (EscapedPtr,
                                                          EscapedSize +
                                                          CGILIB_ESCAPED_CHUNK);
                     else
                        EscapedPtr = realloc (EscapedPtr,
                                              EscapedSize +
                                              CGILIB_ESCAPED_CHUNK);
                     if (!EscapedPtr)
                        if (CgiLib__VeeMemContinue)
                           return ((int)NULL);
                        else
                           exit (vaxc$errno);
                     EscapedSize += CGILIB_ESCAPED_CHUNK;
                     /* recalculate pointers */
                     sptr = EscapedPtr + CurrentLength;
                     zptr = EscapedPtr + EscapedSize - 1;
                  }
                  else
                  if (sptr >= zptr)
                     break;            
               }

               if (CgiLib__VeeMemInUse)
                  CgiLibVeeMemFree (UrlSplitEscapedPtr);
               else
                  free (UrlSplitEscapedPtr);
            }

            if (CgiLib__VeeMemInUse)
               CgiLibVeeMemFree (UrlEscapedPtr);
            else
               free (UrlEscapedPtr);
            continue;
         }
      }

      /********************/
      /* simple character */
      /********************/

      /* 'sptr+6' is the "worst-case" character substitution */
      if (EscapedString == NULL && sptr+6 >= zptr)
      {
         /* out of storage (or first use) get more (or some) memory */
         CurrentLength = sptr - EscapedPtr;
         if (CgiLib__VeeMemInUse)
            EscapedPtr = CgiLibVeeMemRealloc (EscapedPtr,
                                              EscapedSize+CGILIB_ESCAPED_CHUNK);
         else
            EscapedPtr = realloc (EscapedPtr,
                                  EscapedSize+CGILIB_ESCAPED_CHUNK);
         if (!EscapedPtr)
            if (CgiLib__VeeMemContinue)
               return ((int)NULL);
            else
               exit (vaxc$errno);
         EscapedSize += CGILIB_ESCAPED_CHUNK;
         /* recalculate pointers */
         sptr = EscapedPtr + CurrentLength;
         zptr = EscapedPtr + EscapedSize - 1;
      }
      else
      if (sptr+6 >= zptr)
         break;

      switch (*cptr)
      {
         case '<' :
            memcpy (sptr, "&lt;", 4); sptr += 4; cptr++; ccnt--; continue;
         case '>' :
            memcpy (sptr, "&gt;", 4); sptr += 4; cptr++; ccnt--; continue;
         case '&' :
            memcpy (sptr, "&amp;", 5); sptr += 5; cptr++; ccnt--; continue;
         case '"' :
            memcpy (sptr, "&quot;", 6); sptr += 6; cptr++; ccnt--; continue;
         default :
            *sptr++ = *cptr++;
            ccnt--;
       }
   }
   *sptr = '\0';
   if (CgiLib__Debug)
      fprintf (stdout, "%d |%s|\n", sptr-EscapedPtr, EscapedPtr);

   if (EscapedString == NULL)
      return ((int)EscapedPtr);
   else
      return (sptr - EscapedPtr);
}
 
/*****************************************************************************/
/*
Convert numeric HTML entities in a string into their character equivalents
(e.g. "&#38" to '&', "&#00; to 0x00, etc.)  Also converts common alphabetic
entities (e.g. "&amp;", &nbsp;", &lt;", etc.) but not all (any that are not
recognised are left untouched).  Does not URL-decode!   Resultant string is
always the same size or smaller so it can be done in-situ!  Returns the size of
the resultant string.
*/

int CgiLibHtmlDeEntify (char *String)

{
   struct HtmlEntityStruct
   {
      char  *ent;
      int  len,
           val;
   } HtmlEntity [] =
   {
      { "amp;",    4, '&' },
      { "lt;",     3, '<' },
      { "gt;",     3, '>' },
      { "quot;",   5, '\"' },
      { "apos;",   5, '\'' },
      { "nbsp;",   5, 160 },
      { "iexcl;",  6, 161 },
      { "cent;",   5, 162 },
      { "pound;",  6, 163 },
      { "curren;", 7, 164 },
      { "yen;",    4, 165 },
      { "brvbar;", 7, 166 },
      { "sect;",   5, 167 },
      { "uml;",    4, 168 },
      { "copy;",   5, 169 },
      { "ordf;",   5, 170 },
      { "laquo;",  6, 171 },
      { "not;",    4, 172 },
      { "shy;",    4, 173 },
      { "reg;",    4, 174 },
      { "macr;",   5, 175 },
      { "deg;",    4, 176 },
      { "plusmn;", 7, 177 },
      { "sup2;",   5, 178 },
      { "sup3;",   5, 179 },
      { "acute;",  6, 180 },
      { "micro;",  6, 181 },
      { "para;",   5, 182 },
      { "middot;", 7, 183 },
      { "cedil;",  6, 184 },
      { "sup1;",   5, 185 },
      { "ordm;",   5, 186 },
      { "raquo;",  6, 187 },
      { "frac14;", 7, 188 },
      { "frac12;", 7, 189 },
      { "frac34;", 7, 190 },
      { "iquest;", 7, 191 },
      { "Agrave;", 7, 192 },
      { "Aacute;", 7, 193 },
      { "Acirc;",  6, 194 },
      { "Atilde;", 7, 195 },
      { "Auml;",   5, 196 },
      { "Aring;",  6, 197 },
      { "AElig;",  6, 198 },
      { "Ccedil;", 7, 199 },
      { "Egrave;", 7, 200 },
      { "Eacute;", 7, 201 },
      { "Ecirc;",  6, 202 },
      { "Euml;",   5, 203 },
      { "Igrave;", 7, 204 },
      { "Iacute;", 7, 205 },
      { "Icirc;",  6, 206 },
      { "Iuml;",   5, 207 },
      { "ETH;",    4, 208 },
      { "Ntilde;", 7, 209 },
      { "Ograve;", 7, 210 },
      { "Oacute;", 7, 211 },
      { "Ocirc;",  6, 212 },
      { "Otilde;", 7, 213 },
      { "Ouml;",   5, 214 },
      { "times;",  6, 215 },
      { "Oslash;", 7, 216 },
      { "Ugrave;", 7, 217 },
      { "Uacute;", 7, 218 },
      { "Ucirc;",  6, 219 },
      { "Uuml;",   5, 220 },
      { "Yacute;", 7, 221 },
      { "THORN;",  6, 222 },
      { "szlig;",  6, 223 },
      { "agrave;", 7, 224 },
      { "aacute;", 7, 225 },
      { "acirc;",  6, 226 },
      { "atilde;", 7, 227 },
      { "auml;",   5, 228 },
      { "aring;",  6, 229 },
      { "aelig;",  6, 230 },
      { "ccedil;", 7, 231 },
      { "egrave;", 7, 232 },
      { "eacute;", 7, 233 },
      { "ecirc;",  6, 234 },
      { "euml;",   5, 235 },
      { "igrave;", 7, 236 },
      { "iacute;", 7, 237 },
      { "icirc;",  6, 238 },
      { "iuml;",   5, 239 },
      { "eth;",    4, 240 },
      { "ntilde;", 7, 241 },
      { "ograve;", 7, 242 },
      { "oacute;", 7, 243 },
      { "ocirc;",  6, 244 },
      { "otilde;", 7, 245 },
      { "ouml;",   5, 246 },
      { "divide;", 7, 247 },
      { "oslash;", 7, 248 },
      { "ugrave;", 7, 249 },
      { "uacute;", 7, 250 },
      { "ucirc;",  6, 251 },
      { "uuml;",   5, 252 },
      { "yacute;", 7, 253 },
      { "thorn;",  6, 254 },
      { "yuml;",   5, 255 },
      { NULL, 0, 0 }
   };

   int  idx;
   unsigned char  ch;
   char  *cptr, *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibHtmlDeEntify() |%s|\n", String);

   cptr = sptr = String;
   while (*cptr)
   {
      if (*cptr != '&')
      {
         *sptr++ = *cptr++;
         continue;
      }
      cptr++;
      if (*cptr == '#')
      {
         cptr++;
         if (isdigit(*cptr))
            ch = atoi(cptr);
         else
            ch = (unsigned char)256;
         if (ch > 255)
	 {
	    if (CgiLib__Debug) fprintf (stdout, "%d |%s|\n", ch, cptr);
            return (-1);
	 }
         *sptr++ = ch & 0xff;
         while (*cptr && *cptr != ';') cptr++;
         if (*cptr) cptr++;
         continue;
      }
      for (idx = 0; HtmlEntity[idx].ent; idx++)
      {
         if (!memcmp (cptr, HtmlEntity[idx].ent, HtmlEntity[idx].len))
         {
            *sptr++ = HtmlEntity[idx].val;
            cptr += HtmlEntity[idx].len;
            break;
         }
      }
      if (HtmlEntity[idx].ent) continue;
      *sptr++ = '&';
      *sptr++ = *cptr++;
   }
   *sptr = '\0';

   if (CgiLib__Debug) fprintf (stdout, "|%s|\n", String);
   return (sptr-String);
}

/*****************************************************************************/
/*
This function parses a "application/x-www-form-urlencoded" string into it's
decoded, constituent name and value pairs.  It can be passed *any* urlencoded
string including QUERY_STRING CGI variables and POSTed request bodies.  It
returns a dynamically allocated string comprising a "name=value" pair, in much
the same format as a CgiLibVar("*") call.  When the form fields are exhausted
it returns a pointer to NULL.  The form field name is not prefixed by
"WWW_FORM", or anything else.  This buffer is reused with each call and so
should not be modified, any contents should be copied as with CgiLibVar()
constraints.  The 'Context' parameter should be initialized to zero before the
initial call.  At the end of a parse it is reinitialized to zero.
*/

char* CgiLibFormEncodedParse
(
char *String,
int *Context
)
{
   static int  BufferSize = 0;
   static char  *BufferPtr = NULL;

   char  *cptr, *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibFormEncodedParse()\n");

   /* get the 'current distance from the start of the string' */
   cptr = sptr = String + *Context;
   if (!*cptr)
   {
      /* end of string */
      if (CgiLib__VeeMemInUse)
         CgiLibVeeMemFree (BufferPtr);
      else
         free (BufferPtr);
      BufferPtr = NULL;
      BufferSize = 0;
      *Context = 0;
      return (NULL);
   }
   while (*sptr && *sptr != '&') sptr++;

   if (BufferSize < sptr - cptr + 1)
   {
      BufferSize = sptr - cptr + 1;
      if (CgiLib__VeeMemInUse)
         BufferPtr = CgiLibVeeMemRealloc (BufferPtr, BufferSize);
      else
         BufferPtr = realloc (BufferPtr, BufferSize);
      if (!BufferPtr)
         if (CgiLib__VeeMemContinue)
            return (NULL);
         else
            exit (vaxc$errno);
   }

   memcpy (BufferPtr, cptr, sptr-cptr);
   BufferPtr[sptr-cptr] = '\0';
   CgiLibUrlDecode (BufferPtr);

   /* set the 'new distance from the start of the string' */
   if (*sptr) sptr++;
   *Context = sptr - String;

   return (BufferPtr);
}

/****************************************************************************/
/*
This is really just a convenience function and has little to do with CGI
scripting.  VMS $FAO-formatted print statement.  Output is either to the
specified stream, or if stream pointer NULL return a pointer to a dynamic
buffer buffer containing the formatted output (requires caller to dispose of it
as necessary).  Will accomodate up to 64 $FAO directives and resultant strings
to 32kB in size.
*/

char* CgiLibFaoPrint
(
FILE *StreamPtr,
char *FormatString,
...
)
{
/* size of allocated buffer */
#define CGILIB_FAO_BUFFER_ARG    64
#define CGILIB_FAO_BUFFER_MIN   256
#define CGILIB_FAO_BUFFER_MAX 32768

   static $DESCRIPTOR (BufferDsc, "");
   static $DESCRIPTOR (FormatFaoDsc, "");

   int  argcnt, blen, status;
   unsigned short  slen;
   unsigned long  *vecptr;
   unsigned long  FaoVector [CGILIB_FAO_BUFFER_ARG];
   char  *bptr;
   va_list  argptr;

   /*********/
   /* begin */
   /*********/

   va_count (argcnt);

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibFaoPrint() |%s| %d\n", FormatString, argcnt);

   if (argcnt > CGILIB_FAO_BUFFER_ARG+2) return ("[CgiLibFaoPrint():argovf]");

   vecptr = FaoVector;
   va_start (argptr, FormatString);
   for (argcnt -= 2; argcnt; argcnt--)
      *vecptr++ = va_arg (argptr, unsigned long);
   va_end (argptr);

   FormatFaoDsc.dsc$a_pointer = FormatString;
   FormatFaoDsc.dsc$w_length = strlen(FormatString);

   /* start modestly and work up to it if necessary */
   for (blen = CGILIB_FAO_BUFFER_MIN; blen < CGILIB_FAO_BUFFER_MAX; blen *= 2)
   {
      if (CgiLib__VeeMemInUse)
         bptr = CgiLibVeeMemCalloc (blen);
      else
         bptr = calloc (1, blen);
      if (bptr == NULL)
         if (CgiLib__VeeMemContinue)
            return (NULL);
         else
            exit (vaxc$errno);

      BufferDsc.dsc$a_pointer = bptr;
      BufferDsc.dsc$w_length = blen;

      status = sys$faol (&FormatFaoDsc, &slen, &BufferDsc, &FaoVector);
      if (status == SS$_BUFFEROVF)
      {
         if (CgiLib__VeeMemInUse)
            CgiLibVeeMemFree (bptr);
         else
            free (bptr);
         continue;
      }
      if (!(status & 1))
         sprintf (bptr, "[CgiLibFaoPrint():%%X%08.08X]\n", status);
      break;
   }
   if (blen >= CGILIB_FAO_BUFFER_MAX)
   {
      if (CgiLib__VeeMemInUse)
         bptr = CgiLibVeeMemCalloc (64);
      else
         bptr = calloc (1, 64);
      if (bptr == NULL)
         if (CgiLib__VeeMemContinue)
            return (NULL);
         else
            exit (vaxc$errno);
      sprintf (bptr, "[CgiLibFaoPrint():%%X%08.08X]\n", status);
   }

   if (CgiLib__Debug) fprintf (stdout, "|%s|\n", bptr);
   if (StreamPtr != NULL)
   {
      fwrite (bptr, slen, 1, StreamPtr);
      if (CgiLib__VeeMemInUse)
         CgiLibVeeMemFree (bptr);
      else
         free (bptr);
      bptr = NULL;
   }
   return (bptr);

#undef CGILIB_FAO_BUFFER_ARG
#undef CGILIB_FAO_BUFFER_MIN
#undef CGILIB_FAO_BUFFER_MAX
}

/*****************************************************************************/

                           /********************/
                           /* CGIPLUS SPECIFIC */
                           /********************/

/*****************************************************************************/
/*
For CGIplus output the "end-of-file" record (end of script output).
*/

void CgiLibCgiPlusEOF ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibCgiPlusEOF()\n");

   if (CgiLib__Environment != CGILIB_ENVIRONMENT_CGIPLUS) return;

   /* CGI EOF must be in a record by itself ... flush! */
   fflush (stdout);
   fputs (CgiLib__CgiPlusEofPtr, stdout);
   fflush (stdout);

   /* reset these ready for any subsequent request */
   CgiLib__ResponseCount = CgiLib__ResponseStatusCode = 0;
}

/*****************************************************************************/
/*
For CGIplus output the "end-of-text" record (end of CGIplus callout).
*/

void CgiLibCgiPlusEOT ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibCgiPlusEOT()\n");

   if (CgiLib__Environment != CGILIB_ENVIRONMENT_CGIPLUS) return;

   if (CgiLib__CgiPlusEotPtr == NULL)
      CgiLib__CgiPlusEotPtr = getenv("CGIPLUSEOT");

   /* CGI EOT must be in a record by itself ... flush! */
   fflush (stdout);
   fputs (CgiLib__CgiPlusEotPtr, stdout);
   fflush (stdout);
}

/*****************************************************************************/
/*
For CGIplus output the "escape" record (start of CGIplus callout).
*/

void CgiLibCgiPlusESC ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibCgiPlusESC()\n");

   if (CgiLib__Environment != CGILIB_ENVIRONMENT_CGIPLUS) return;

   if (CgiLib__CgiPlusEscPtr == NULL)
      CgiLib__CgiPlusEscPtr = getenv("CGIPLUSESC");

   /* CGI ESC must be in a record by itself ... flush! */
   fflush (stdout);
   fputs (CgiLib__CgiPlusEscPtr, stdout);
   fflush (stdout);
}

/*****************************************************************************/
/*
Provide a callout to WASD server.
*/

char* CgiLibCgiPlusCallout (char *fmt, ...)

{
   static char  CalloutResponse [256];

   int  retval;
   char  *cptr;
   char  buf [256];
   va_list  ap;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibCgiPlusCallout()\n");

   if (CgiLib__Environment != CGILIB_ENVIRONMENT_CGIPLUS) return (NULL);

   CgiLibCgiPlusESC();

   va_start (ap, fmt);
   retval = vsnprintf (buf, sizeof(buf), fmt, ap);
   va_end (ap);

   if (retval >= 0) fputs (buf, stdout);

   CgiLibCgiPlusEOT();

   if (buf[0] == '!' || buf[0] == '#') return (NULL);

   memset (CalloutResponse, 0, sizeof(CalloutResponse));
   CgiLibCgiPlusInGets (CalloutResponse, sizeof(CalloutResponse));
   *(strchr (CalloutResponse, '\n')) = '\0';

   return (CalloutResponse);
}

/*****************************************************************************/
/*
Read a record (string) from the CGIPLUSIN stream.  If the buffer is too small
the record will be truncated, but will always be null-terminated.  This
function is provided to allow a CGIplus callout to read a single record
response from the server.
*/

void CgiLibCgiPlusInGets
(
char *String,
int SizeOfString
)
{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibCgiPlusInGets()\n");

   /* the CGIplus input stream should always have been opened by now! */
   if (CgiLib__CgiPlusInFile == NULL) exit (SS$_BUGCHECK);

   if (fgets (String, SizeOfString, CgiLib__CgiPlusInFile) == NULL)
      exit (vaxc$errno);
   /* absorb intermediate empty lines that seem to be present */
   if (String[0] == '\n' && !String[1])
      if (fgets (String, SizeOfString, CgiLib__CgiPlusInFile) == NULL)
         exit (vaxc$errno);
   String[SizeOfString-1] = '\0';
}

/*****************************************************************************/
/*
Switch CGIplus variable stream into 'record' mode.  In this mode each CGI
variable "name=value" pair is transmitted as an individual I/O.
*/

void CgiLibCgiPlusSetVarRecord ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibCgiPlusSetVarRecord()\n");

   CgiLibCgiPlusESC ();
   fflush (stdout);
   fputs ("!CGIPLUS: record\n", stdout);
   fflush (stdout);
   CgiLibCgiPlusEOT ();
   fflush (stdout);
   CgiLib__CgiPlusVarRecord = 1;
   CgiLib__CgiPlusVarStruct = 0;
}

/*****************************************************************************/
/*
Switch CGIplus variable stream into 'struct' mode.  In this mode all CGI
variables are transmitted in a single I/O.  The "name=value" pairs must be
explicitly parsed from the buffer.
*/

void CgiLibCgiPlusSetVarStruct ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibCgiPlusSetVarStruct()\n");

   CgiLibCgiPlusESC ();
   fflush (stdout);
   fputs ("!CGIPLUS: struct\n", stdout);
   fflush (stdout);
   CgiLibCgiPlusEOT ();
   fflush (stdout);
   CgiLib__CgiPlusVarRecord = 0;
   CgiLib__CgiPlusVarStruct = 1;
}

/*****************************************************************************/

                             /*****************/
                             /* CGI VARIABLES */
                             /*****************/

/*****************************************************************************/
/*
(jpp@esme.fr)  Return a CGI variable by descriptor.  Takes an optional third
pointer to short int parameter to receive the string length short.
*/

int CgiLibVarByDesc
(
struct dsc$descriptor *NameDsc,
struct dsc$descriptor *ValueDsc,
...
)
{
   int  idx, argcnt;
   char  *name,
         *value;
   unsigned short  *slenptr;
   va_list  argptr;

   /*********/
   /* begin */
   /*********/

   va_count (argcnt);
   if (argcnt > 2)
   {
      va_start (argptr, ValueDsc);
      slenptr = (unsigned short*)va_arg (argptr, unsigned short*);
   }
   else
      slenptr = NULL;

   if (CgiLib__VeeMemInUse)
      name = CgiLibVeeMemCalloc (NameDsc->dsc$w_length+1);
   else
      name = calloc (1, NameDsc->dsc$w_length+1);
   if (!name)
      if (CgiLib__VeeMemContinue)
         return (0);
      else
         exit (vaxc$errno);

   for (idx = 0; idx < NameDsc->dsc$w_length; idx++)
      name[idx] = (NameDsc->dsc$a_pointer)[idx];
   name[idx] = '\0';
   value = CgiLibVarNull (name);
   if (CgiLib__VeeMemInUse)
      CgiLibVeeMemFree (name);
   else
      free (name);
   if (value)
   {
      for (idx = 0; idx < ValueDsc->dsc$w_length && value[idx]; idx++)
         (ValueDsc->dsc$a_pointer)[idx] = value[idx];
      if (slenptr) *slenptr = (unsigned short)idx;
      memset (ValueDsc->dsc$a_pointer+idx, ' ', ValueDsc->dsc$w_length-idx);
      return (1);
   }
   else
   {
      memset (ValueDsc->dsc$a_pointer, ' ', ValueDsc->dsc$w_length);
      if (slenptr) *slenptr = 0;
      return (0);
   }
}

/*****************************************************************************/
/*
Get a CGI variable from a DCL symbol or from the CGIplus stream.  Returns a
pointer to the string value if the CGI variables exists or a pointer to
'NonePtr' if not.  Adjusts behaviour according to CGI or CGIplus environments
and to whether symbols are prefixd with "WWW_" or not.
*/

char* CgiVar (char *VarName)
{
   return (CgiLib__GetVar (VarName, CgiLib__VarNonePtr));
}

char* CgiLibVar (char *VarName)
{
   return (CgiLib__GetVar (VarName, CgiLib__VarNonePtr));
}

char* CgiLibVarNull (char *VarName)
{
   return (CgiLib__GetVar (VarName, NULL));
}

char* CgiLibVeeMemVar (char *VarName)
{
   char  *cptr, *sptr;

   if (!CgiLib__VeeMemZoneId) return (NULL);

   cptr = CgiLib__GetVar (VarName, CgiLib__VarNonePtr);

   sptr = CgiLibVeeMemCalloc (strlen(cptr));
   if (!sptr)
      if (CgiLib__VeeMemContinue)
         return (NULL);
      else
         exit (vaxc$errno);
   strcpy (sptr, cptr);

   if (sptr[0] && CgiLib__BodyIsMultipartFormData &&
       (!strncmp (VarName, "form_", 5) || !strncmp (VarName, "FORM_", 5)))
      CgiLibHtmlDeEntify (sptr);

   return (sptr);
}

char* CgiLibVeeMemVarNull (char *VarName)
{
   char  *cptr, *sptr;

   if (!CgiLib__VeeMemZoneId) return (NULL);

   if (!(cptr = CgiLib__GetVar (VarName, NULL))) return (cptr);
   sptr = CgiLibVeeMemCalloc (strlen(cptr));
   if (!sptr)
      if (CgiLib__VeeMemContinue)
         return (NULL);
      else
         exit (vaxc$errno);
   strcpy (sptr, cptr);

   if (sptr[0] && CgiLib__BodyIsMultipartFormData &&
       (!strncmp (VarName, "form_", 5) || !strncmp (VarName, "FORM_", 5)))
      CgiLibHtmlDeEntify (sptr);

   return (sptr);
}

char* CgiLib__GetVar
(
char *VarName,
char *NonePtr
)
{
   static int  CgiPrefixChecked = 0,
               HttpMethodPost = 0,
               VarStructCallout = 0;
   static char  *HttpMethodPtr = NULL;
   static char  WwwVarName [256] = "WWW_";

   char  *cptr;
   unsigned short  Length;
   int  VersionNumber;

   /*********/
   /* begin */
   /*********/

/**
15-AUG-2002  MGD  This debug header *should* work!  However ...
it's as if any <stdout> from CGILIB after the end of the previous request
is absorbed, whereas <stdout> from immediately following the CgiLibVar("")
start-of-CGIplus-request isn't.  This is most peculiar.  I cannot resolve
it and *suspect* something in the C-RTL (of course :^)  The usage-counter
shows that this function is definitely being called.  The work-around is
to put the debug content-type header <stdout> into the script proper.
**/

   /* provide debug response header (subsequent requests) */
   if (CgiLib__Debug && CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS &&
       VarName && !VarName[0] && CgiLib__CgiPlusUsageCount)
      fputs (
"Content-Type: text/plain\nScript-Control: X-content-encoding-gzip=0\n\n",
             stdout);

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__GetVar() |%s|\n", VarName);

   if (!CgiLib__Environment) CgiLib__SetEnvironment ();

   if (CgiLib__Environment != CGILIB_ENVIRONMENT_CGIPLUS)
   {
      /***************************/
      /* non-CGIplus environment */
      /***************************/

      if (VarName != NULL &&
          VarName[0] &&
          VarName[0] != '*' &&
          CgiLib__CgiPrefixWWW &&
          memcmp (VarName, "WWW_", 4))
      {
         /* variable name does not begin with "WWW_", make one that does */
         strncpy (WwwVarName+4, VarName, sizeof(WwwVarName)-5);
         (VarName = WwwVarName)[sizeof(WwwVarName)-1] = '\0';
      }
      else
      if (!CgiLib__CgiPrefixWWW &&
          !memcmp (VarName, "WWW_", 4))
      {
         /* variables do not begin with "WWW_" and this one does */
         VarName += 4;
      }

      /* a POSTed body can be turned into _FORM_ variables */
      if (VarName[0] == '*')
         return (CgiLib__VarList (VarName, NULL, NonePtr));

      if (CgiLib__Environment == CGILIB_ENVIRONMENT_OSU)
      {
         /*******************/
         /* OSU environment */
         /*******************/

         return (CgiLib__VarList (VarName, NULL, NonePtr));
      }

      if (CgiLib__Environment == CGILIB_ENVIRONMENT_WASD)
      {
         /********************/
         /* WASD environment */
         /********************/

         if ((cptr = getenv(VarName)) == NULL)
         {

            /* a POSTed body can be turned into _FORM_ variables */
            return (CgiLib__VarList (VarName, NULL, NonePtr));
         }
         else
         {
            if (CgiLib__Debug) fprintf (stdout, "|%s=%s|\n", VarName, cptr);
            return (cptr);
         }
      }

      /*************************************/
      /* Purveyor, vanilla CGI environment */
      /*************************************/

      if (!strcmp (VarName, "WWW_PATH_TRANSLATED") ||
          !strcmp (VarName, "PATH_TRANSLATED"))
         return (CgiLib__GetPathTranslated (NonePtr));

      if (!strncmp (VarName, "WWW_KEY_", 8) ||
          !strncmp (VarName, "KEY_", 4) ||
          !strncmp (VarName, "WWW_FORM_", 9) ||
          !strncmp (VarName, "FORM_", 5))
      {
         if (HttpMethodPtr == NULL)
         {
            if (CgiLib__CgiPrefixWWW)
               HttpMethodPtr = getenv("WWW_REQUEST_METHOD");
            else
               HttpMethodPtr = getenv("REQUEST_METHOD");
            if (HttpMethodPtr != NULL &&
                !strcmp (HttpMethodPtr, "POST"))
               HttpMethodPost = 1;
            else
               HttpMethodPost = 0;
         }

         if (HttpMethodPost)
         {
            /* a POSTed body can be turned into _FORM_ variables */
            return (CgiLib__VarList (VarName, NULL, NonePtr));
         }

         if (!strncmp (VarName, "WWW_KEY_", 8) ||
             !strncmp (VarName, "KEY_", 4))
            return (CgiLib__GetKey (VarName, NonePtr));

         if (!strncmp (VarName, "WWW_FORM_", 9) ||
             !strncmp (VarName, "FORM_", 5))
            return (CgiLib__GetForm (VarName, NonePtr));
      }

      if ((cptr = getenv(VarName)) == NULL)
      {
         if (CgiLib__Debug) fprintf (stdout, "|%s|=CGILIB_NONE\n", VarName);
         return (NonePtr);
      }
      else
      {
         if (CgiLib__Debug) fprintf (stdout, "|%s=%s|\n", VarName, cptr);
         return (cptr);
      }
   }

   /***********************/
   /* CGIplus environment */
   /***********************/

   if (VarName == NULL || !VarName[0])
   {
      /* end of request or waiting for next, reinitialize */
      CgiLib__CgiPlusLoadVariables = 1;
      CgiLib__VarList (NULL, NULL, NULL);

      /* if just initializing then return now */
      if (VarName == NULL) return (NULL);
   }

   if (CgiLib__CgiPlusLoadVariables)
   {
      /* read lines containing CGIplus variables from <CGIPLUSIN> */
      int  StructLength;
      char  CgiPlusRecord [CGILIB_CGIPLUS_RECORD_SIZE];

      CgiLib__CgiPlusUsageCount++;

      if (CgiLib__Debug)
         fprintf (stdout, "CGIplus usage: %d\n", CgiLib__CgiPlusUsageCount);

      if (CgiLib__CgiPlusInFile == NULL)
         if ((CgiLib__CgiPlusInFile = 
             fopen (getenv("CGIPLUSIN"), "r", "ctx=rec")) == NULL)
            exit (vaxc$errno);

      CgiLib__CgiPlusLoadVariables = 0;

      /* get the starting sentinal record */
      for (;;)
      {
         cptr = fgets (CgiPlusRecord, sizeof(CgiPlusRecord),
                       CgiLib__CgiPlusInFile);
         if (cptr == NULL) exit (vaxc$errno);
         /* if the starting record is detected then break */
         if (*(USHORTPTR)cptr == '!\0' ||
             *(USHORTPTR)cptr == '!\n' ||
             (*(USHORTPTR)cptr == '!!' && isdigit(*(cptr+2)))) break;
      }

      if (*(USHORTPTR)cptr == '!!')
      {
         /********************/
         /* CGIplus 'struct' */
         /********************/

         /* CGIplus variables transmitted as 'struct'ure */
         StructLength = atoi(cptr+2);
         if (StructLength <= 0 || StructLength > sizeof(CgiPlusRecord))
         {
            fprintf (stdout, "%%CGILIB-E-STRUCT, CGIplus \'struct\' error\n");
            exit (SS$_BUGCHECK | STS$M_INHIB_MSG);
         }
         if (!fread (CgiPlusRecord, 1, StructLength, CgiLib__CgiPlusInFile))
            exit (vaxc$errno);

         /* explicitly parse the "name=value" pairs from the single I/O */
         cptr = CgiPlusRecord;
         for (;;)
         {
            if (!(Length = *(USHORTPTR)cptr)) break;
            cptr += sizeof(short);
            CgiLib__VarList (cptr, "", NULL);
            cptr += Length;
         }
      }
      else
      {
         /*******************/
         /* CGIplus records */
         /*******************/

         /* CGIplus variables transmitted in records */
         while (fgets (CgiPlusRecord,
                       sizeof(CgiPlusRecord),
                       CgiLib__CgiPlusInFile) != NULL)
         {
            if (CgiLib__Debug) fprintf (stdout, "|%s|\n", CgiPlusRecord);
            /* first empty record (line) terminates variables */
            if (CgiPlusRecord[0] == '\n') break;
            CgiLib__VarList (CgiPlusRecord, "", NULL);
         }
      }

      if (!CgiPrefixChecked)
      {
         /* must have the CGI variables beginning with or without "WWW_" */
         CgiPrefixChecked = 1;
         cptr = CgiLib__VarList ("WWW_GATEWAY_INTERFACE", NULL, NULL);
         if (cptr == NULL)
         {
            cptr = CgiLib__VarList ("GATEWAY_INTERFACE", NULL, NULL);
            if (cptr == NULL)
            {
               fprintf (stdout, "%%CGILIB-E-CGI, no [WWW_]GATEWAY_INTERFACE\n");
               exit (SS$_BUGCHECK | STS$M_INHIB_MSG);
            }
            CgiLib__CgiPrefixWWW = 0;
         }
         else
            CgiLib__CgiPrefixWWW = 1;
      }

      if (!(VarStructCallout ||
            CgiLib__CgiPlusVarStruct ||
            CgiLib__CgiPlusVarRecord))
      {
         /* attempt to switch CGI variable 'record' to 'struct' mode */
         VarStructCallout = 1;
         fflush (stdout);
         CgiLibCgiPlusESC ();
         fflush (stdout);
         /* the leading '!' means we won't need to read a response */
         fputs ("!CGIPLUS: struct\n", stdout);
         fflush (stdout);
         CgiLibCgiPlusEOT ();
         fflush (stdout);
      }
   }

   /* if waiting for next request return now it's arrived */
   if (!VarName[0]) return (NULL);

   if (VarName[0] != '*' &&
       CgiLib__CgiPrefixWWW &&
       memcmp (VarName, "WWW_", 4))
   {
      /* variable name does not begin with "WWW_", make one that does */
      strncpy (WwwVarName+4, VarName, sizeof(WwwVarName)-5);
      (VarName = WwwVarName)[sizeof(WwwVarName)-1] = '\0';
   }
   else
   if (!CgiLib__CgiPrefixWWW &&
       !memcmp (VarName, "WWW_", 4))
   {
      /* variables do not begin with "WWW_" and this one does */
      VarName += 4;
   }

   /* get a CGIplus variable */
   return (CgiLib__VarList (VarName, NULL, NonePtr));
}

/*****************************************************************************/
/*
Set or get a CGI variable.  Used to store CGIplus variables (read from
CGIPLUSIN stream), OSU variables (created individually during dialog phase) and
the pseudo-CGI-variables from a form-URL-encoded body.

Implemented using a simple list in allocated memory.  Each entry comprises a
total-length-of-entry int, followed by a length-of-variable-name int,
followed by a null-terminated string comprising the variable name, an equate
symbol, and the variable value string.

If 'VarValue' is NULL then get 'VarName', returning a pointer to it's string
value, or if not found to CGILIB_NONE (usually "").  Successive calls with
'VarName' set to "*" (via CgiLibVar() of course) returns each of the list's
entries in turn, a NULL indicating end-of-list.  The list can be reset (for
CGIplus use) with 'VarName' equal to NULL.  If 'VarValue' is not NULL then
store the value against the name (duplicated variables names result in
duplicated entries, not overwriting!)
*/

char* CgiLib__VarList 
(
char *VarName,
char *VarValue,
char *NonePtr
)
{
   static int  ListNextOffset = 0,
               ListSize = 0;

   static char  *NextPtr = NULL,
                *ListPtr = NULL;

   int  LengthOffset,
        VarNameLength,
        VarNameLengthOffset,
        VarNameOffset;
   unsigned int  Length;
   char  *cptr, *sptr, *zptr,
         *LengthPtr;

   /*********/
   /* begin */
   /*********/

   if (CGILIB_VARLIST_DEBUG)
      fprintf (stdout, "CgiLib__VarList() |%s|%s|%s|\n",
               VarName, VarValue, NonePtr);

   if (VarName == NULL)
   {
      /* initialize */
      NextPtr = NULL;
      ListNextOffset = 0;
      return (NULL);
   }

   if (VarValue != NULL)
   {
      /******************************/
      /* manipulate variable values */
      /******************************/

      if (VarName[0] == '!' && !strcmp (VarName, "!FORM_"))
      {
         /****************/
         /* special case */
         /****************/

         /*
            Remove from access the current FORM_ variables, 'hiding' them
            by changing the variable name from 'FORM_' to '!ORM_'. This leaves
            the current values intact and any existing pointers still valid.
            A kludge to allow soyMAIL v1.3 to re-process POSTed content.
         */
         cptr = ListPtr;
         for (;;)
         {
            if (!(Length = *((int*)(sptr = cptr)))) return (NULL);
            cptr = sptr + Length;
            sptr += sizeof(int) + sizeof(int);
            if (CGILIB_VARLIST_DEBUG) fprintf (stdout, "|%s|\n", sptr);
            if (!strncmp (sptr, "FORM_", 5)) *sptr = '!';
         }
         return (NULL);
      }

      /******************/
      /* add a variable */
      /******************/

      if (ListPtr == NULL)
      {
         /* always allow extra space (allows sloppier/faster code ;^) */
         ListPtr = realloc (ListPtr, CGILIB_VARLIST_CHUNK+16);
         if (!ListPtr) exit (SS$_INSFMEM);
         ListSize = CGILIB_VARLIST_CHUNK;
      }

      /* point to next "[total-len][var-name-len]var-name=var-value" storage */
      sptr = ListPtr + ListNextOffset;
      /* offset to where the total length is stored */
      LengthOffset = sptr - ListPtr;
      /* offset to where the length of the variable name is stored */
      VarNameLengthOffset = LengthOffset + sizeof(int);
      /* now point to the start of the "var-name=var-value" string */
      VarNameOffset = VarNameLengthOffset + sizeof(int);
      /* so we don't over-run the list storage */
      sptr = ListPtr + VarNameOffset;
      zptr = ListPtr + ListSize;

      /* CGIplus, stream has "name=value\n\0" */
      cptr = VarName;
      while (*cptr && *(USHORTPTR)cptr != '\n\0')
      {
         while (*cptr && *(USHORTPTR)cptr != '\n\0' && sptr < zptr)
         {
            if (VarNameLengthOffset && *cptr == '=')
            {
               /* store the length of the CGIplus variable name */
               *((int*)(ListPtr+VarNameLengthOffset)) =
                  sptr - ListPtr - VarNameOffset;
               VarNameLengthOffset = 0;
            }
            *sptr++ = *cptr++;
         }
         if (VarNameLengthOffset && !*cptr)
         {
            /* store the length of the CGI variable name */
            *((int*)(ListPtr+VarNameLengthOffset)) =
               sptr - ListPtr - VarNameOffset;
            VarNameLengthOffset = 0;
            *sptr++ = '=';
            cptr = VarValue;
         }
         if (sptr >= zptr)
         {
            /* out of storage, get more memory */
            Length = sptr - ListPtr;
            ListPtr = realloc (ListPtr, ListSize+CGILIB_VARLIST_CHUNK+16);
            if (!ListPtr) exit (SS$_INSFMEM);
            ListSize += CGILIB_VARLIST_CHUNK;
            /* recalculate pointers */
            sptr = ListPtr + Length;
            zptr = ListPtr + ListSize;
         }
      }
      /* terminate the "name=value" */
      *sptr++ = '\0';

      /* insert the length of this name=value pair immediately before it */
      *((int*)(ListPtr+LengthOffset)) = sptr - ListPtr - LengthOffset;

      /* adjust the value of the current variable storage space used */
      ListNextOffset = sptr - ListPtr;

      /* ensure the list is terminated with a zero length entry */
      *((int*)(ListPtr+ListNextOffset)) = 0;

      if (CGILIB_VARLIST_DEBUG)
      {
         fprintf (stdout, "ListPtr: %d ListSize: %d ListNextOffset: %d\n",
                  ListPtr, ListSize, ListNextOffset);
         sptr = ListPtr;
         for (sptr = ListPtr; Length = *((int*)sptr); sptr += Length)
         {
            fprintf (stdout, "%5d %2d |%s|\n",
               Length, *((int*)(sptr+sizeof(int))),
               sptr+sizeof(int)+sizeof(int));
         }
      }

      return (NULL);
   }

if (VarName[0] == '+')
{
fprintf(stdout,"<!-- %u %d %d\n", ListPtr, ListSize, ListNextOffset);
CgiLibVeeMemShow(NULL);
fprintf(stdout,"-->\n");
}

   if (ListPtr == NULL)
   {
      if (CgiLib__Debug)
         fprintf (stdout, "|%s|=CGILIB_NONE (empty list)\n", VarName);
      if (VarName[0] == '*') return (NULL);
      return (NonePtr);
   }

   if (VarName[0] == '*')
   {
      /*****************************************/
      /* return each stored line one at a time */
      /*****************************************/

      if (NextPtr == NULL) NextPtr = ListPtr;
      for (;;)
      {
         if (!(Length = *((int*)(sptr = NextPtr))))
         {
            if (CgiLib__Debug) fprintf (stdout, "|*|=NULL\n");
            return (NextPtr = NULL);
         }
         NextPtr = sptr + Length;
         sptr += sizeof(int) + sizeof(int);
         if (CGILIB_VARLIST_DEBUG) fprintf (stdout, "|%s|\n", sptr);
         if (!VarName[1]) return (sptr);
      }
      return (NULL);
   }

   /*************************************************/
   /* search variable strings for required variable */
   /*************************************************/

   VarNameLength = strlen(VarName);

   for (sptr = LengthPtr = ListPtr;
        Length = *((int*)sptr);
        sptr = LengthPtr = LengthPtr + Length)
   {
      if (CGILIB_VARLIST_DEBUG)
         fprintf (stdout, "%d %d\n", Length, *((int*)sptr+4));
      /* step over the total-length int */
      sptr += sizeof(int);
      if (*((int*)sptr) != VarNameLength) continue;
      /* step over the var-name-length int */
      sptr += sizeof(int);
      /* simple comparison between supplied and in-string variable names */
      cptr = VarName;
      if (CGILIB_VARLIST_DEBUG) fprintf (stdout, "|%s|%s|\n", cptr, sptr);
      while (*cptr && *sptr && *sptr != '=')
      {
         if (toupper(*cptr) != toupper(*sptr)) break;
         cptr++;
         sptr++;
      }
      if (*cptr || *sptr != '=') continue;
      /* found, return a pointer to the value */
      if (CgiLib__Debug) fprintf (stdout, "|%s=%s|\n", VarName, sptr+1);
      return (sptr+1);
   }

   /* not found */
   if (CgiLib__Debug) fprintf (stdout, "|%s|=CGILIB_NONE\n", VarName);
   return (NonePtr);
}  

/*****************************************************************************/
/*
For "standard" CGI environment (e.g. Netscape FastTrack) derive the
"KEY_COUNT", "KEY_1" ... "KEY_n" variables from "QUERY_STRING".
*/

char* CgiLib__GetKey
(
char *VarName,
char *NonePtr
)
{
   int  KeyCount,
        VarKeyCount;
   char  *aptr, *cptr, *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__GetKey() |%s|\n", VarName);

   if (!VarName[0]) return (NonePtr);

   /* step over the "WWW_" */
   if (CgiLib__CgiPrefixWWW) VarName += 4;

   if ((cptr = CgiLib__QueryStringPtr) == NULL)
   {
      if (CgiLib__CgiPrefixWWW)
         CgiLib__QueryStringPtr = cptr = getenv ("WWW_QUERY_STRING");
      else
         CgiLib__QueryStringPtr = cptr = getenv ("QUERY_STRING");
      if (CgiLib__Debug) fprintf (stdout, "query_string |%s|\n", cptr);
      if (cptr == NULL) return (NonePtr);
   }

   if (!strcmp (VarName, "KEY_COUNT"))
   {
      KeyCount = 0;
      for (sptr = cptr; *sptr; sptr++)
      {
         if (*sptr == '=') return (NonePtr);
         if (*sptr == '+') KeyCount++;
      }
      if (sptr == cptr) return ("0");
      KeyCount++;
      if (CgiLib__VeeMemInUse)
         aptr = CgiLibVeeMemCalloc (16);
      else
         aptr = calloc (1, 16);
      if (aptr == NULL)
         if (CgiLib__VeeMemContinue)
            return (NonePtr);
         else
            exit (vaxc$errno);
      sprintf (aptr, "%d", KeyCount);
      if (CgiLib__Debug) fprintf (stdout, "|%s=%s|\n", VarName, aptr);
      return (aptr);
   }
 
   VarKeyCount = atoi (VarName+4);
   if (CgiLib__Debug) fprintf (stdout, "VarKeyCount: %d\n", VarKeyCount);
   KeyCount = 1;
   while (*cptr && VarKeyCount)
   {
      if (CgiLib__Debug) fprintf (stdout, "|%s|\n", cptr);
      sptr = cptr;
      while (*cptr && *cptr != '+')
      {
         if (*cptr == '=') return (NonePtr);
         cptr++;
      }
      if (KeyCount == VarKeyCount)
      {
         if (CgiLib__VeeMemInUse)
            aptr = CgiLibVeeMemCalloc (cptr - sptr + 1);
         else
            aptr = calloc (1, cptr - sptr + 1);
         if (aptr == NULL)
            if (CgiLib__VeeMemContinue)
               return (NonePtr);
            else
               exit (vaxc$errno);
         memcpy (aptr, sptr, cptr-sptr);
         aptr[cptr-sptr] = '\0';
         CgiLibUrlDecode (aptr);
         if (CgiLib__Debug) fprintf (stdout, "|%s=%s|\n", VarName, aptr);
         return (aptr);
      }
      if (*cptr) cptr++;
      KeyCount++;
   }

   if (CgiLib__Debug) fprintf (stdout, "|%s|=CGILIB_NONE\n", VarName);
   return (NonePtr);
}

/*****************************************************************************/
/*
For "standard" CGI environment (e.g. Netscape FastTrack, Purveyor, Apache)
derive the "FORM_xxxxx" variables from "QUERY_STRING".
*/

char* CgiLib__GetForm
(
char *VarName,
char *NonePtr
)
{
   char  *aptr, *cptr, *sptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__GetForm() |%s|\n", VarName);

   if (!VarName[0]) return (NonePtr);

   /* step over the "WWW_" (as necessary) and the "FORM_" */
   if (!strncmp (VarName, "WWW_", 4)) VarName += 4;
   VarName += 5;

   if ((cptr = CgiLib__QueryStringPtr) == NULL)
   {
      if (CgiLib__CgiPrefixWWW)
         CgiLib__QueryStringPtr = cptr = getenv ("WWW_QUERY_STRING");
      else
         CgiLib__QueryStringPtr = cptr = getenv ("QUERY_STRING");
      if (CgiLib__Debug) fprintf (stdout, "|%s|\n", cptr);
      if (cptr == NULL) return (NonePtr);
   }

   while (*cptr)
   {
      sptr = cptr;
      while (*cptr && *cptr != '=') cptr++;
      if (!*cptr) return (NonePtr);
      *cptr = '\0';
      aptr = VarName;
      while (*aptr && *sptr && toupper(*aptr) == toupper(*sptr))
      {
         aptr++;
         sptr++;
      }
      if (*aptr || *sptr)
      {
         *cptr++ = '=';
         while (*cptr && *cptr != '&') cptr++;
         if (*cptr) cptr++;
         continue;
      }
      *cptr++ = '=';

      sptr = cptr;
      while (*cptr && *cptr != '&') cptr++;
      if (CgiLib__VeeMemInUse)
         aptr = CgiLibVeeMemCalloc (cptr - sptr + 1);
      else
         aptr = calloc (1, cptr - sptr + 1);
      if (aptr == NULL)
         if (CgiLib__VeeMemContinue)
            return (NonePtr);
         else
            exit (vaxc$errno);
      memcpy (aptr, sptr, cptr-sptr);
      aptr[cptr-sptr] = '\0';
      CgiLibUrlDecode (aptr);
      if (CgiLib__Debug) fprintf (stdout, "|%s=%s|\n", VarName, aptr);
      return (aptr);
   }

   if (CgiLib__Debug) fprintf (stdout, "|%s|=CGILIB_NONE\n", VarName);
   return (NonePtr);
}

/*****************************************************************************/
/*
For vanilla CGI environment (e.g. Apache, OSU) get the "PATH_TRANSLATED"
variable and check if it's in Unix-style or VMS-style format.
Convert to a VMS specification as necessary.
*/

char* CgiLib__GetPathTranslated (char *NonePtr)
   
{
   int  scnt, Length;
   char  *aptr, *cptr, *sptr, *zptr;
   char  PathTranslated [256];

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__GetPathTranslated()\n");

   if (CgiLib__CgiPrefixWWW)
      cptr = aptr = getenv ("WWW_PATH_TRANSLATED");
   else
      cptr = aptr = getenv ("PATH_TRANSLATED");
   if (cptr == NULL) return (NonePtr);

   if (*cptr == '/')
   {
      /* unix-style specification */
      scnt = 0;
      for (aptr = cptr; *aptr; aptr++) if (*aptr == '/') scnt++;
      zptr = (sptr = PathTranslated) + sizeof(PathTranslated)-1;
      cptr++;
      if (scnt == 1)
      {
         /* just a filename, e.g. "/file.txt" */
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
      }
      else
      if (scnt == 2)
      {
         /* logical plus file name, e.g. "/this/file.txt" */
         while (*cptr && *cptr != '/' && sptr < zptr) *sptr++ = *cptr++;
         if (sptr < zptr) *sptr++ = ':';
         if (*cptr) cptr++;
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
      }
      else
      {
         /* full file spec, e.g. "/device/dir1/file.txt" */
         while (*cptr && *cptr != '/' && sptr < zptr) *sptr++ = *cptr++;
         if (*cptr) cptr++;
         if (sptr < zptr) *sptr++ = ':';
         if (sptr < zptr) *sptr++ = '[';
         while (*cptr && *cptr != '/' && sptr < zptr) *sptr++ = *cptr++;
         if (*cptr) cptr++;
         for (scnt -= 3; scnt; scnt--)
         {
            if (sptr < zptr) *sptr++ = '.';
            while (*cptr && *cptr != '/' && sptr < zptr) *sptr++ = *cptr++;
            if (*cptr) cptr++;
         }
         if (sptr < zptr) *sptr++ = ']';
         while (*cptr && sptr < zptr) *sptr++ = *cptr++;
      }
      *sptr = '\0';
      if (CgiLib__VeeMemInUse)
         aptr = CgiLibVeeMemCalloc (Length = (sptr - PathTranslated) + 1);
      else
         aptr = calloc (1, Length = (sptr - PathTranslated) + 1);
      if (aptr == NULL)
         if (CgiLib__VeeMemContinue)
            return (NULL);
         else
            exit (vaxc$errno);
      strcpy (aptr, PathTranslated);
   }

   if (CgiLib__Debug) fprintf (stdout, "|PATH_TRANSLATED=%s|\n", aptr);
   return (aptr);
}

/*****************************************************************************/

                             /****************/
                             /* OSU SPECIFIC */
                             /****************/

/*****************************************************************************/
/*
Initialize the OSU variable list using the request network dialog phase.
*/

void CgiLibOsuInit
(
int argc,
char *argv[]
)
{
   int  ContentLengthSet,
        ContentTypeSet,
        IpAddress,
        KeyCount;
   char  *cptr, *sptr, *zptr;
   char  PathInfo [512],
         PathTranslated [512],
         Scratch [256],
         ScriptName [256],
         SymbolName [256];
   struct hostent  *HostEntryPtr;

   /*********/
   /* begin */
   /*********/

   if (argc < 4)
   {
      fprintf (stdout, "%%CGILIB-E-OSU, P1=<method> P2=<path> P3=<protocol>\n");
      exit (SS$_INSFARG | STS$M_INHIB_MSG);
   }

   if (CgiLib__Debug)
   {
      /* let's have a look at what's available! */
      fprintf (stdout, "CgiLibOsuInit()\n----------\n");
      CgiLib__OsuQueryNetLink ("<DNETARG>", 1);
      CgiLib__OsuQueryNetLink ("<DNETARG2>", 1);
      CgiLib__OsuQueryNetLink ("<DNETHOST>", 1);
      CgiLib__OsuQueryNetLink ("<DNETID>", 1);
      CgiLib__OsuQueryNetLink ("<DNETID2>", 1);
      CgiLib__OsuQueryNetLink ("<DNETRQURL>", 1);
      CgiLib__OsuQueryNetLink ("<DNETBINDIR>", 1);
      CgiLib__OsuQueryNetLink ("<DNETPATH>", 1);
      CgiLib__OsuQueryNetLink ("<DNETHDR>", 999);
      fprintf (stdout, "----------\n");
   }

   /**********/
   /* basics */
   /**********/

   CgiLib__VarList ("WWW_GATEWAY_INTERFACE", "CGI/1.1", NULL);
   CgiLib__VarList ("WWW_REQUEST_METHOD", argv[1], NULL);
   CgiLib__VarList ("WWW_SERVER_PROTOCOL", argv[3], NULL);

   /********************************************************/
   /* SCRIPT_NAME, PATH_INFO, PATH_TRANSLATED, REQUEST_URI */
   /********************************************************/

   strcpy (sptr = ScriptName, CgiLib__OsuQueryNetLink ("<DNETPATH>", 1));
   cptr = CgiLib__OsuQueryNetLink ("<DNETRQURL>", 1);

   CgiLib__VarList ("WWW_REQUEST_URI", cptr, NULL);

   while (*cptr && *cptr && *cptr == *sptr) { cptr++; sptr++; }
   while (*cptr && *cptr != '/' && *cptr != '?') *sptr++ = *cptr++;
   *sptr = '\0';
   CgiLibUrlDecode (ScriptName);
   CgiLib__VarList ("WWW_SCRIPT_NAME", ScriptName, NULL);

   /* continue to get the path information from the request URL */
   sptr = PathInfo;
   while (*cptr && *cptr != '?') *sptr++ = *cptr++;
   *sptr = '\0';
   CgiLibUrlDecode (PathInfo);

   if (*PathInfo && *(USHORTPTR)PathInfo != '/\0')
   {
      CgiLib__OsuQueryNetLink ("<DNETXLATE>", 0);
      sptr = CgiLib__OsuQueryNetLink (PathInfo, 1);

      cptr = PathTranslated;
      if (*sptr == '/') sptr++;
      while (*sptr && *sptr != '/') *cptr++ = toupper(*sptr++);
      if (*sptr)
      {
         sptr++;
         *cptr++ = ':';
         *cptr++ = '[';
      }
      while (*sptr) *cptr++ = toupper(*sptr++);
      *cptr-- = '\0';
      while (cptr > PathTranslated && *cptr != '/') cptr--;
      if (*cptr == '/')
      {
         *cptr-- = ']';
         while (cptr >= PathTranslated)
         {
            if (*cptr == '/') *cptr = '.';
            if (*(ULONGPTR)cptr == '....')
               memmove (cptr, cptr+1, strlen(cptr)); 
            cptr--;
         }
      }

      CgiLib__VarList ("WWW_PATH_INFO", PathInfo, NULL);
      CgiLib__VarList ("WWW_PATH_TRANSLATED", PathTranslated, NULL);
   }
   else
   {
      CgiLib__VarList ("WWW_PATH_INFO", "/", NULL);
      CgiLib__VarList ("WWW_PATH_TRANSLATED", "", NULL);
   }

   /***********************************/
   /* QUERY_STRING, FORM_..., KEY_... */
   /***********************************/

   cptr = CgiLib__OsuQueryNetLink ("<DNETARG>", 1);
   if (*cptr == '?') cptr++;
   CgiLib__VarList ("WWW_QUERY_STRING", cptr, NULL);

   KeyCount = 0;
   sptr = cptr;
   while (*cptr && *cptr != '=') cptr++;
   if (*cptr)
   {
      /* FORM-formatted query string */
      while (*cptr)
      {
         *cptr++ = '\0';
         sprintf (SymbolName, "WWW_FORM_%s", sptr);
         sptr = cptr;
         while (*cptr && *cptr != '&') cptr++;
         if (*cptr) *cptr++ = '\0';
         CgiLibUrlDecode (SymbolName);
         CgiLibUrlDecode (sptr);
         CgiLib__VarList (SymbolName, sptr, NULL);
         sptr = cptr;
         while (*cptr && *cptr != '=') cptr++;
      }
   }
   else
   {
      /* ISQUERY-formatted query string */
      cptr = sptr;
      while (*cptr && *cptr != '+') cptr++;
      while (*sptr)
      {
         *cptr++ = '\0';
         sprintf (SymbolName, "WWW_KEY_%d", ++KeyCount);
         CgiLibUrlDecode (sptr);
         CgiLib__VarList (SymbolName, sptr, NULL);
         sptr = cptr;
         while (*cptr && *cptr != '+') cptr++;
      }
   }
   sprintf (Scratch, "%d", KeyCount);
   CgiLib__VarList ("WWW_KEY_COUNT", Scratch, NULL);

   /**********************************************/
   /* SERVER_SOFTWARE, SERVER_NAME, SERVER_PORT, */
   /* REMOTE_HOST, REMOTE_ADDR, REMOTE_USER      */
   /**********************************************/

   cptr = sptr = CgiLib__OsuQueryNetLink ("<DNETID2>", 1);

   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';
   CgiLib__VarList ("WWW_SERVER_SOFTWARE", sptr, NULL);

   sptr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';
   CgiLib__VarList ("WWW_SERVER_NAME", sptr, NULL);

   /* just derive the absent server address from the host address */
   if (HostEntryPtr = gethostbyname (sptr))
   {
      memcpy (&IpAddress, HostEntryPtr->h_addr, 4);
      sprintf (Scratch, "%d.%d.%d.%d",
               *(unsigned char*)&IpAddress,
               *((unsigned char*)(&IpAddress)+1),
               *((unsigned char*)(&IpAddress)+2),
               *((unsigned char*)(&IpAddress)+3));
      CgiLib__VarList ("WWW_SERVER_ADDR", Scratch, NULL);
   }

   sptr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';
   CgiLib__VarList ("WWW_SERVER_PORT", sptr, NULL);

   /* skip over client port */
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';

   /* host address */
   sptr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';
   for (zptr = sptr; *zptr && *zptr != '.'; zptr++);
   if (*zptr != '.')
   {
      IpAddress = atoi(sptr);
      sprintf (Scratch, "%d.%d.%d.%d",
               *(unsigned char*)&IpAddress,
               *((unsigned char*)(&IpAddress)+1),
               *((unsigned char*)(&IpAddress)+2),
               *((unsigned char*)(&IpAddress)+3));
      sptr = Scratch;
   }
   CgiLib__VarList ("WWW_REMOTE_ADDR", sptr, NULL);
   CgiLib__VarList ("WWW_REMOTE_HOST", sptr, NULL);

   sptr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr) *cptr++ = '\0';
   CgiLib__VarList ("WWW_REMOTE_USER", sptr, NULL);

   sptr = cptr;
   while (*cptr && !isspace(*cptr)) cptr++;
   if (*cptr)
   {
      /* DNS-resolved host name */
      *cptr++ = '\0';
      CgiLib__VarList ("WWW_REMOTE_HOST", sptr, NULL);
   }

   /******************************************/
   /* CONTENT_LENGTH, CONTENT_TYPE, HTTP_... */
   /******************************************/

   ContentLengthSet = ContentTypeSet = 0;

   cptr = sptr = CgiLib__OsuQueryNetLink ("<DNETHDR>", 999);
   while (*cptr)
   {
      while (*cptr && *cptr != ':')
      {
         if (isalnum(*cptr))
            *cptr = toupper(*cptr);
         else
            *cptr = '_';
         cptr++;
      }
      if (*cptr)
      {
         *cptr++ = '\0';
         sprintf (SymbolName, "WWW_HTTP_%s", sptr);
         while (*cptr && isspace(*cptr) && *cptr != '\n') *cptr++;
         sptr = cptr;
         while (*cptr && *cptr != '\n') *cptr++;
         if (*cptr) *cptr++ = '\0';
/** 26-MAR-2007
         CgiLibUrlDecode (SymbolName);
         CgiLibUrlDecode (sptr);
**/
         if (!strcmp (SymbolName+9, "CONTENT_TYPE"))
         {
            ContentTypeSet = 1;
            CgiLib__VarList ("WWW_CONTENT_TYPE", sptr, NULL);
         }
         else
         if (!strcmp (SymbolName+9, "CONTENT_LENGTH"))
         {
            ContentLengthSet = 1;
            CgiLib__VarList ("WWW_CONTENT_LENGTH", sptr, NULL);
         }
         else
            CgiLib__VarList (SymbolName, sptr, NULL);
         sptr = cptr;
      }
   }

   if (!ContentTypeSet)
      CgiLib__VarList ("WWW_CONTENT_TYPE", "", NULL);

   if (!ContentLengthSet)
      CgiLib__VarList ("WWW_CONTENT_LENGTH", "0", NULL);
}  

/*****************************************************************************/
/*
Reopen <stdout> to NET_LINK: in binary mode.  This is much more efficient as the
CRTL buffers individual prints into a stream.  Output an appropriate
output-phase tag and establish an exit function to complete the output dialog.
*/

void CgiLibOsuStdoutCgi ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibOsuStdoutCgi()\n");

   /* reopen so that '\r' and '\n' are not filtered, maximum record size */
   if ((stdout =
       freopen ("NET_LINK:", "w", stdout, "ctx=bin", "mrs=4096")) == NULL)
      exit (vaxc$errno);
 
   if (CgiLib__Debug)
   {
      fputs ("<DNETTEXT>", stdout);
      fflush(stdout);
      fputs ("200 Debug", stdout);
   }
   else
      fputs ("<DNETCGI>", stdout);
   fflush(stdout);

   atexit (&CgiLib__OsuExitCgi);
}  

void CgiLib__OsuExitCgi ()

{
   if (CgiLib__Debug) fprintf (stdout, "CgiLib__OsuExitCgi()\n");

   fflush(stdout);
   if (CgiLib__Debug)
      fputs ("</DNETTEXT>", stdout);
   else
      fputs ("</DNETCGI>", stdout);
   fflush(stdout);
}  

/*****************************************************************************/
/*
Reopen <stdout> to NET_LINK: in binary mode.  This is much more efficient as the
CRTL buffers individual prints into a stream.  Output an appropriate
output-phase tag and establish an exit function to complete the output dialog.
*/

void CgiLibOsuStdoutRaw ()

{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibOsuStdoutRaw()\n");

   /* reopen so that '\r' and '\n' are not filtered, maximum record size */
   if ((stdout =
       freopen ("NET_LINK:", "w", stdout, "ctx=bin", "mrs=4096")) == NULL)
      exit (vaxc$errno);

   if (CgiLib__Debug)
   {
      fputs ("<DNETTEXT>", stdout);
      fflush(stdout);
      fputs ("200 Debug", stdout);
   }
   else
      fputs ("<DNETRAW>", stdout);
   fflush (stdout);

   atexit (&CgiLib__OsuExitRaw);
}  

void CgiLib__OsuExitRaw ()

{
   if (CgiLib__Debug) fprintf (stdout, "CgiLib__OsuExitRaw()\n");

   fflush (stdout);
   if (CgiLib__Debug)
      fputs ("</DNETTEXT>", stdout);
   else
      fputs ("</DNETRAW>", stdout);
   fflush (stdout);
}  

/*****************************************************************************/
/*
Write a single record to the OSU network link, then if expecting a response
wait for one or more records to be returned.  A single line response has no
carriage control.  A multi-line response has each record concatenated into a
single string of newline-separated records.  Returns pointer to static storage!
Open files to the link if first call.
*/

char* CgiLib__OsuQueryNetLink
(
char *Query,
int ResponseLinesExpected
)
{
   static char  Response [4096];
   static FILE  *NetLinkRead,
                *NetLinkWrite;

   int  status;
   char  *cptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLib__OsuQueryNetLink() |%s|\n", Query);

   if (NetLinkRead == NULL)
   {
      /*************************/
      /* first call, open link */
      /*************************/

      if ((NetLinkRead = fopen ("NET_LINK:", "r", "ctx=rec")) == NULL)
      {
         status = vaxc$errno;
         fprintf (stdout, "%%CGILIB-E-BODYREAD, read open error\n");
         exit (status);
      }
      if ((NetLinkWrite = fopen ("NET_LINK:", "w", "ctx=bin")) == NULL)
      {
         status = vaxc$errno;
         fprintf (stdout, "%%CGILIB-E-BODYREAD, write open error\n");
         exit (status);
      }
   }

   if (Query != NULL)
   {
      /*********/
      /* write */
      /*********/

      if (fputs (Query, NetLinkWrite) == EOF)
      {
         status = vaxc$errno;
         fprintf (stdout, "%%CGILIB-E-BODYREAD, write error\n");
         exit (status);
      }
      fflush (NetLinkWrite);
   }

   if (ResponseLinesExpected > 1)
   {
      /**************************/
      /* multiple line response */
      /**************************/

      cptr = Response;
      for (;;)
      {
         if (fgets (cptr, sizeof(Response)-(cptr-Response), NetLinkRead) == NULL)
         {
            status = vaxc$errno;
            fprintf (stdout, "%%CGILIB-E-BODYREAD, read error\n");
            exit (status);
         }
         /** if (CgiLib__Debug) fprintf (stdout, "cptr |%s|\n", cptr); **/
         if (*cptr != '\n')
         {
            while (*cptr) cptr++;
            continue;
         }
         *cptr = '\0';
         break;
      }
   }
   else
   if (ResponseLinesExpected > 0)
   {
      /************************/
      /* single line response */
      /************************/

      if (fgets (Response, sizeof(Response), NetLinkRead) == NULL)
      {
         status = vaxc$errno;
         fprintf (stdout, "%%CGILIB-E-BODYREAD, read error\n");
         exit (status);
      }

      for (cptr = Response; *cptr; cptr++);
      if (cptr > Response)
      {
         if (*--cptr == '\n')
            *cptr = '\0';
         else
            cptr++;
      }
   }
   else
      *(cptr = Response) = '\0';

   if (CgiLib__Debug) fprintf (stdout, "%d |%s|\n", cptr-Response, Response);
   return (Response);
}  

/*****************************************************************************/

                        /***************************/
                        /* REQUEST BODY PROCESSING */
                        /***************************/

/*****************************************************************************/
/*
Read a POSTed request body into a single array of char (doesn't matter whether
it's text or binary).  Returns NULL if it's not a POST, a pointer if it is. 
The caller can free() this memory when finished with it or it is implicitly
freed when called again (i.e. CGIplus).  Note: the OSU DECnet scripting stream
is NET_LINK:, the WASD CGI DECnet scripting stream is NET$LINK, the two should
not be confused.  Will processes an RFC2068 (HTTP/1.1) "Transfer-Encoding:
chunked" request body from 'chunked' format into a binary bag of bytes.
*/

char* CgiLibReadRequestBody
(
char **BodyPtrPtr,
int *BodyLengthPtr
)
{
   static int  BodyReadFd = 0,
               BufferCount = 0,
               InitializeEnvironment = 1,
               PrevUsageCount;
   static char  *BufferPtr = NULL;

   int  status,
        BufferSize,
        ChunkLength,
        ContentLength,
        ContentUnEncoded,
        EncodingChunked,
        ReadCount;
   char  *cptr, *sptr, *zptr,
         *RequestTimeGmtPtr,
         *ServerSoftwarePtr;
   char  ChunkString [32];

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibReadRequestBody()\n");

   if (InitializeEnvironment)
   {
      InitializeEnvironment = 0;

      if (!CgiLib__Environment) CgiLib__SetEnvironment ();

      cptr = CgiLib__GetVar ("WWW_REQUEST_METHOD", "");
      if (strcmp (cptr, "POST"))
      {
         *BodyPtrPtr = NULL;
         *BodyLengthPtr = 0;
         if (CgiLib__Debug)
            fprintf (stdout, "%d %d\n", *BodyLengthPtr, *BodyPtrPtr);
         return (NULL);
      }

      if (CgiLib__Environment == CGILIB_ENVIRONMENT_WASD)
      {
         if (getenv ("NET$LINK") != NULL)
            BodyReadFd = open ("NET$LINK:", O_RDONLY, 0, "ctx=bin");
         else
            BodyReadFd = open ("HTTP$INPUT:", O_RDONLY, 0, "ctx=bin");
      }
      else
      if (CgiLib__Environment == CGILIB_ENVIRONMENT_APACHE)
         BodyReadFd = open ("APACHE$INPUT:", O_RDONLY, 0, "ctx=bin");
      else
      if (CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS)
         BodyReadFd = open ("HTTP$INPUT:", O_RDONLY, 0, "ctx=bin");
      else
      if (CgiLib__Environment == CGILIB_ENVIRONMENT_OSU)
         BodyReadFd = open ("NET_LINK:", O_RDONLY, 0, "ctx=bin");
      else
      /* vanilla CGI environment */
      if (getenv ("WWW_IN") != NULL)
      {
         /* Purveyor, Cern? */
         BodyReadFd = open ("WWW_IN:", O_RDONLY, 0, "ctx=bin");
      }
      else
         BodyReadFd = open ("SYS$INPUT:", O_RDONLY, 0, "ctx=bin");

      if (BodyReadFd == -1)
      {
         status = vaxc$errno;
         fprintf (stdout, "%%CGILIB-E-BODYREAD, binary read open error\n");
         exit (status);
      }
   }
   else
   /* if not CGIplus or if multiple calls in the one CGIplus request */
   if (CgiLib__Environment != CGILIB_ENVIRONMENT_CGIPLUS ||
       CgiLib__CgiPlusUsageCount == PrevUsageCount)
   {
      /* body has already been read by call from CgiLibEnvironmentInit() */
      *BodyPtrPtr = BufferPtr;
      *BodyLengthPtr = BufferCount;
      if (CgiLib__Debug)
         fprintf (stdout, "%d %d\n", *BodyLengthPtr, *BodyPtrPtr);
      return (BufferPtr);
   }

   PrevUsageCount = CgiLib__CgiPlusUsageCount;

   if (BufferPtr)
   {
      /* if called again (i.e. CGIplus) */
      free (BufferPtr);
      BufferPtr = NULL;
   }

   cptr = CgiLib__GetVar ("WWW_CONTENT_TYPE", "");

   CgiLib__BodyIsFormUrlEncoded = CgiLib__BodyIsMultipartFormData = 0;
   if (!strncmp (cptr, "application/x-www-form-urlencoded", 33))
      CgiLib__BodyIsFormUrlEncoded = 1;
   else
   if (!strncmp (cptr, "multipart/form-data;", 20))
      CgiLib__BodyIsMultipartFormData = 1;

   cptr = CgiLib__GetVar ("WWW_CONTENT_LENGTH", "");
   if (*cptr == '?')
   {
      ContentUnEncoded = 1;
      ContentLength = 0;
   }
   else
   {
      ContentUnEncoded = 0;
      ContentLength = atoi(cptr);
   }
   if (CgiLib__Debug)
      fprintf (stdout, "ContentLength: %d ContentUnEncoded: %d\n",
               ContentLength, ContentUnEncoded);

   if (ContentUnEncoded)
      EncodingChunked = 0;
   else
   {
      cptr = CgiLib__GetVar ("WWW_HTTP_TRANSFER_ENCODING", "");
      if (cptr[0] && strstr (cptr, "chunked"))
         EncodingChunked = 1;
      else
         EncodingChunked = 0;
   }

   if ((CgiLib__Environment == CGILIB_ENVIRONMENT_CGIPLUS ||
        CgiLib__Environment == CGILIB_ENVIRONMENT_WASD) &&
       CgiLibHttpProtocolVersion() == 11 &&
       !CgiLib__ResponseCount)
   {
      cptr = CgiLib__GetVar ("WWW_HTTP_EXPECT", "");
      if (cptr[0] && strstr (cptr, "100-continue") ||
                     strstr (cptr, "100-Continue"))
      {
         /* supply a "100 Continue" interim response header */
         RequestTimeGmtPtr =  CgiLib__GetVar ("REQUEST_TIME_GMT", NULL); 
         ServerSoftwarePtr =  CgiLib__GetVar ("SERVER_SOFTWARE", "");
         fprintf (stdout,
"%s 100 %s\n\
Server: %s\n\
%s%s%s\
\n",
               CgiLib__HttpProtocolVersionPtr,
               CgiLibHttpStatusCodeText(100),
               ServerSoftwarePtr,
               RequestTimeGmtPtr == NULL ? "" : "Date: ",
               RequestTimeGmtPtr == NULL ? "" : RequestTimeGmtPtr,
               RequestTimeGmtPtr == NULL ? "" : "\n");
         fflush(stdout);
      }
   }

   if (EncodingChunked)
   {
      /************************/
      /* chunked request body */
      /************************/

      BufferPtr = NULL;
      BufferSize = 0;
      for (;;)
      {
         /* read one character at a time until the size string is available */
         for (zptr=(sptr=ChunkString)+sizeof(ChunkString); sptr < zptr; sptr++)
         {
            if (ReadCount = read (BodyReadFd, sptr, 1) < 0)
            {
               status = vaxc$errno;
               fprintf (stdout, "%%CGILIB-E-CHUNK, binary read error\n");
               exit (status);
            }
            if (!isxdigit(*sptr)) break;
         }
         if (sptr >= zptr)
         {
            fprintf (stdout, "%%CGILIB-E-CHUNK, size overflow\n");
            exit (SS$_BUGCHECK);
         }
         *sptr = '\0';
         if (!ChunkString[0])
         {
            fprintf (stdout, "%%CGILIB-E-CHUNK, no size\n");
            exit (SS$_BUGCHECK);
         }

         ChunkLength = strtol (ChunkString, NULL, 16);
         if (CgiLib__Debug)
            fprintf (stdout, "|%s| %d\n", ChunkString, ChunkLength);
         /* zero length chunk, end of chunked body */
         if (!ChunkLength) break;

         /* skip to the end of the chunk size line (one character at a time) */
         for (;;)
         {
            ChunkString[0] = '\0';
            if (read (BodyReadFd, ChunkString, 1) < 0) break;
            if (ChunkString[0] == '\n') break;
         }
         if (ChunkString[0] != '\n')
         {
            fprintf (stdout, "%%CGILIB-E-CHUNK, format error\n");
            exit (SS$_BUGCHECK);
         }

         if (CgiLib__VeeMemInUse)
            BufferPtr = CgiLibVeeMemRealloc (BufferPtr,
                                             BufferSize+ChunkLength+1);
         else
            BufferPtr = realloc (BufferPtr, BufferSize+ChunkLength+1);
         if (!BufferPtr)
            if (CgiLib__VeeMemContinue)
               return (NULL);
            else
               exit (vaxc$errno);
         BufferSize += ChunkLength;

         while (BufferCount < BufferSize)
         {
            if (CgiLib__Environment == CGILIB_ENVIRONMENT_OSU)
               CgiLib__OsuQueryNetLink ("<DNETINPUT>", 0);

            ReadCount = read (BodyReadFd,
                              BufferPtr+BufferCount,
                              BufferSize-BufferCount);
            if (CgiLib__Debug) fprintf (stdout, "ReadCount: %d\n", ReadCount);
            if (!ReadCount) break;

            if (ReadCount == -1)
            {
               status = vaxc$errno;
               fprintf (stdout, "%%CGILIB-E-CHUNK, binary read error\n");
               exit (status);
            }

            BufferCount += ReadCount;
         }

         /* skip over the trailing <CR><LF> (one character at a time) */
         for (;;)
         {
            ChunkString[0] = '\0';
            if (read (BodyReadFd, ChunkString, 1) < 0) break;
            if (ChunkString[0] == '\n') break;
         }
         if (ChunkString[0] != '\n')
         {
            fprintf (stdout, "%%CGILIB-E-CHUNK, format error\n");
            exit (SS$_BUGCHECK);
         }
      }
   }
   else
   {
      /**************************/
      /* unchunked request body */
      /**************************/

      /* an ambit quantity (it doubles each time it's about the overflow) */
      if (ContentUnEncoded) ContentLength = 8192;

      if (!ContentLength)
      {
         *BodyPtrPtr = NULL;
         *BodyLengthPtr = 0;
         return (NULL);
      }

      if (CgiLib__VeeMemInUse)
         BufferPtr = CgiLibVeeMemCalloc (ContentLength+1);
      else
         BufferPtr = calloc (1, ContentLength+1);
      if (!BufferPtr)
         if (CgiLib__VeeMemContinue)
            return (NULL);
         else
            exit (vaxc$errno);
      BufferSize = ContentLength;
      BufferCount = 0;

      while (BufferCount < BufferSize)
      {
         if (CgiLib__Environment == CGILIB_ENVIRONMENT_OSU)
            CgiLib__OsuQueryNetLink ("<DNETINPUT>", 0);

         ReadCount = read (BodyReadFd,
                           BufferPtr+BufferCount,
                           BufferSize-BufferCount);
         if (CgiLib__Debug)
            fprintf (stdout, "ReadCount: %d ContentLength: %d\n",
                     ReadCount, ContentLength);
         if (!ReadCount) break;

         if (ReadCount == -1)
         {
            status = vaxc$errno;
            fprintf (stdout, "%%CGILIB-E-BODYREAD, binary read error\n");
            exit (status);
         }

         BufferCount += ReadCount;

         if (ContentUnEncoded)
         {
            if (BufferCount >= BufferSize)
            {
               ContentLength *= 2;
               if (CgiLib__VeeMemInUse)
                  BufferPtr = CgiLibVeeMemRealloc (BufferPtr, ContentLength+1);
               else
                  BufferPtr = realloc (BufferPtr, ContentLength+1);
               if (!BufferPtr)
                  if (CgiLib__VeeMemContinue)
                     return (NULL);
                  else
                     exit (vaxc$errno);
               BufferSize = ContentLength;
            }
         }
         else
         if (BufferCount == ContentLength)
            break;
      }
   }

   if (CgiLib__Debug)
      fprintf (stdout, "size: %d count: %d\n", BufferSize, BufferCount);

   /* terminate with a null in case it's text (not counted in 'BufferCount') */
   BufferPtr[BufferCount] = '\0';
   /** if (CgiLib__Debug) fprintf (stdout, "|%s|\n", BufferPtr); **/

   *BodyPtrPtr = BufferPtr;
   *BodyLengthPtr = BufferCount;
   if (CgiLib__Debug) fprintf (stdout, "%d %d\n", *BodyLengthPtr, *BodyPtrPtr);

   return (BufferPtr);
}

/*****************************************************************************/
/*
Return true if the body of the request is "application/x-www-form-urlencoded".
*/

int CgiLibBodyIsFormUrlEncoded ()
{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibBodyIsFormUrlEncoded() %d\n",
               CgiLib__BodyIsFormUrlEncoded);

   return (CgiLib__BodyIsFormUrlEncoded);
}

/*****************************************************************************/
/*
Return true if the body of the request is "multipart/form-data".
*/

int CgiLibBodyIsMultipartFormData ()
{
   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibBodyIsMultipartFormData() %d\n",
               CgiLib__BodyIsMultipartFormData);

   return (CgiLib__BodyIsMultipartFormData);
}

/*****************************************************************************/
/*
Converts the POSTed body parameter into "WWW_FORM_field-name" CGI variables
accessable from the variable list.  Field names are limited to 255 characters,
after which they are truncated.
*/

int CgiLibFormRequestBody
(
char *BodyPtr,
int BodyLength
)
{
   char  *cptr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibFormRequestBody()\n");

   if (!BodyLength) return (0);

   cptr = CgiLib__GetVar ("WWW_CONTENT_TYPE", "");

   if (strstr (cptr, "application/x-www-form-urlencoded"))
      return (CgiLib__BodyFormUrlEncoded (BodyPtr, BodyLength));

   if (!strncmp (cptr, "multipart/form-data;", 20))
      return (CgiLib__BodyMultipartFormData (BodyPtr, BodyLength, cptr+20));

   return (0);
}

/*****************************************************************************/
/*
Converts the POSTed url-form-encoded body parameter into "WWW_FORM_field-name"
CGI variables accessable from the variable list.
*/

int CgiLib__BodyFormUrlEncoded
(
char *BodyPtr,
int BodyLength
)
{
   static char  VarName [256] = "WWW_FORM_";

   int  VarCount;
   char  *cptr, *sptr, *zptr,
         *BufferPtr,
         *VarValuePtr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__FormUrlEncoded()\n");

   /* no need for any CgiLibVeeMem..() functionality */
   cptr = BufferPtr = calloc (1, BodyLength+1);
   if (!BufferPtr) exit (SS$_INSFMEM);
   memcpy (cptr, BodyPtr, BodyLength);
   cptr[BodyLength] = '\0';

   VarCount = 0;
   while (*cptr)
   {
      zptr = (sptr = VarName) + sizeof(VarName)-1;
      sptr += 9;
      while (*cptr && *cptr != '=' && sptr < zptr) *sptr++ = toupper(*cptr++);
      if (sptr >= zptr) while (*cptr && *cptr != '=') cptr++;
      if (!*cptr)
      {
         free (BufferPtr);
         return (VarCount);
      }
      *sptr = '\0';
      VarValuePtr = ++cptr;
      while (*cptr && *cptr != '&') cptr++;
      if (*cptr) *cptr++ = '\0';
      if (VarName[9]) CgiLibUrlDecode (VarName+9);
      if (VarValuePtr[0]) CgiLibUrlDecode (VarValuePtr);
      if (CgiLib__CgiPrefixWWW)
         CgiLib__VarList (VarName, VarValuePtr, NULL);
      else
         CgiLib__VarList (VarName+4, VarValuePtr, NULL);
      VarCount++;
   }

   free (BufferPtr);
   return (VarCount);
}

/*****************************************************************************/
/*
Converts the POSTed MIME multipart form-data body parameters into
"WWW_FORM_field-name" CGI variables accessable from the variable list.  As it
is possible to POST unencoded characters with this method (all characters
from 0x00 to 0xff are transmitted unencoded) non-printable characters are
HTML-entified (i.e. 0x00 becomes "&#0;", 0x01 "&#1;", etc.) before storage as
variables.  These of course would need to be de-entified before use (with
CgiLibHtmlDeEntify()).  If the field is an upload ("type=file") and there is
an associated content-type and file name (as there should be) these are placed
in variables with the same name as the field with "_MIME_CONTENT_TYPE" and
"_MIME_FILENAME" added.

This is an incomplete MIME decode and may be a bit brain-dead, I don't know
much about it at all.  Seems to work with the big-three browsers I've tried
it on, NetNav, MSIE and Opera.
*/

int CgiLib__BodyMultipartFormData
(
char *BodyPtr,
int BodyLength,
char *BoundaryPtr                                                 
)
{
   static int  CheckedEntifyIsprint,
               IsprintEntify;

   static char  VarName [256] = "WWW_FORM_";

   int  BoundaryLength,
        BufferSize,
        ContentLength,
        VarCount,
        VarNameLength;
   unsigned char  ch;
   char  *bptr, *cptr, *sptr, *zptr,
         *BufferPtr,
         *ContentTypePtr,
         *EndBodyPtr,
         *EndHeaderPtr,
         *StartHeaderPtr;
   char  Boundary [256],
         ContentType [256],
         FileName [256];

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLib__BodyMultipartFormData()\n");

   if (!CheckedEntifyIsprint)
   {
      /* v1.6.7 used isprint(), this allows selected backward compatibility */
      CheckedEntifyIsprint = 1;
      if (getenv ("CGILIB_MULTIPART_ISPRINT")) IsprintEntify = 1;
   }

   zptr = (sptr = Boundary) + sizeof(Boundary)-1;
   for (cptr = BoundaryPtr; *cptr && *(ULONGPTR)cptr != 'ary='; cptr++);
   if (!*cptr) return (0);
   cptr += sizeof(unsigned long);
   if (*cptr == '\"')
   {
      cptr++;
      while (*cptr && *cptr != '\"' && sptr < zptr) *sptr++ = *cptr++;
   }
   else
      while (*cptr && sptr < zptr) *sptr++ = *cptr++;
   *sptr = '\0';
   BoundaryLength = sptr - Boundary;

   if (CgiLib__Debug)
      fprintf (stdout, "Boundary %d |%s|\n",
               BoundaryLength, Boundary);

   /***************************/
   /* loop through body parts */
   /***************************/

   VarCount = 0;
   EndBodyPtr = (cptr = BodyPtr) + BodyLength;
   while (cptr < EndBodyPtr)
   {
      if (CgiLib__Debug) fprintf (stdout, "|%.128s|\n", cptr);

      if ((cptr = strstr (cptr, Boundary)) == NULL) return (0);
      cptr += BoundaryLength;
      if (*(USHORTPTR)cptr == '--') break;
      if (*(USHORTPTR)cptr != '\r\n') return (0);
      cptr += 2;

      /***********************/
      /* process part header */
      /***********************/

      /* note the start and end of the part header information */
      StartHeaderPtr = cptr;
      if ((EndHeaderPtr = strstr (cptr, "\r\n\r\n")) == NULL) return (0);

      if ((cptr = strstr (StartHeaderPtr, "Content-Disposition:")) == NULL)
         return (0);
      cptr += 20;

      if ((cptr = strstr (StartHeaderPtr, "form-data;")) == NULL)
         return (0);
      cptr += 10;

      if ((cptr = strstr (StartHeaderPtr, "name=")) == NULL) return (0);
      if (cptr > EndHeaderPtr) return (0);
      cptr += 5;
      ch = '\0';
      if (*cptr == '\"') ch = *cptr++;
      /* minus 19, one for the terminating null, 18 for max "_MIME_..." */
      zptr = (sptr = VarName) + sizeof(VarName)-19;
      sptr += 9;
      while (*cptr && *cptr != ch && sptr < zptr) *sptr++ = toupper(*cptr++);
      if (sptr >= zptr) while (*cptr && *cptr != ch) cptr++;
      if (*cptr) cptr++;   
      *sptr = '\0'; 
      VarNameLength = sptr - VarName;
      if (CgiLib__Debug) fprintf (stdout, "VarName |%s|\n", VarName);

      FileName[0] = '\0';
      if ((cptr = strstr (StartHeaderPtr, "filename=")) != NULL &&
          cptr < EndHeaderPtr)
      {
         cptr += 9;
         ch = '\0';
         if (*cptr == '\"') ch = *cptr++;
         zptr = (sptr = FileName) + sizeof(FileName)-1;
         while (*cptr && *cptr != ch && sptr < zptr) *sptr++ = *cptr++;
         if (sptr >= zptr) while (*cptr && *cptr != ch) cptr++;
         if (*cptr) cptr++;   
         *sptr = '\0';
         if (CgiLib__Debug) fprintf (stdout, "FileName |%s|\n", FileName);
      }

      ContentType[0] = '\0';
      if ((cptr = strstr (StartHeaderPtr, "Content-Type:")) != NULL &&
          cptr < EndHeaderPtr)
      {
         for (cptr += 13; *cptr && isspace(*cptr); cptr++);
         zptr = (sptr = ContentType) + sizeof(ContentType)-1;
         while (*cptr && !isspace(*cptr) && sptr < zptr) *sptr++ = *cptr++;
         *sptr = '\0';
         if (CgiLib__Debug)
            fprintf (stdout, "ContentType |%s|\n", ContentType);
      }

      /**************************/
      /* retrieve the part data */
      /**************************/

      sptr = cptr = EndHeaderPtr + 4;
      for (;;)
      {
         /* find the next boundary */
         if (CgiLib__Debug) fprintf (stdout, "|%.72s|\n", sptr);
         for (;;)
         {
            if (sptr >= EndBodyPtr) return (0);
            while (sptr < EndBodyPtr && *sptr != '\r') sptr++;
            if (!strncmp (sptr, "\r\n--", 4)) break;
            sptr++;
         }
         /* if end of body, break; */
         if (!sptr[4]) break;
         /* if not end of body then should be a boundary */
         if (!strncmp (sptr+4, Boundary, BoundaryLength)) break;
         /* nope, must have been data */
         sptr += 4;
      }

      if (CgiLib__Debug)
         fprintf (stdout, "start: %d end: %d bytes: %d\n",
                  cptr, sptr, sptr-cptr);

      /* get a worst-case value for HTML-entifying all unacceptable chars */
      BufferSize = sptr - cptr + 1;
      if (IsprintEntify)
      {
         /* pre-v1.6.7 */
         for (bptr = cptr; bptr < sptr; bptr++)
            if ((!isprint(*bptr) && !isspace(*bptr)) || *bptr == '&')
               BufferSize += 5;
      }
      else
      {
         /* current default method */
         for (bptr = cptr; bptr < sptr; bptr++)
            if ((unsigned char)*bptr <= 0x1f ||
                ((unsigned char)*bptr >= 0x7f &&
                 (unsigned char)*bptr <= 0x9f) ||
                (unsigned char)*bptr == 0xff ||
                *bptr == '&')
               BufferSize += 5;
      }
      if (CgiLib__Debug) fprintf (stdout, "BufferSize: %d\n", BufferSize);

      /* no need for any CgiLibVeeMem..() functionality */
      bptr = BufferPtr = calloc (1, BufferSize);
      if (!BufferPtr) exit (SS$_INSFMEM);

      if (IsprintEntify)
      {
         /* pre-v1.6.7 */
         while (cptr < sptr)
         {
            if ((isprint (*cptr) || isspace(*cptr)) && *cptr != '&')
            {
               *bptr++ = *cptr++;
               continue;
            }
            bptr += sprintf (bptr, "&#%u;", *cptr++ & 0xff);
         }
      }
      else
      {
         /* current default method */
         while (cptr < sptr)
         {
            if (!((unsigned char)*cptr <= 0x1f ||
                  ((unsigned char)*cptr >= 0x7f &&
                   (unsigned char)*cptr <= 0x9f) ||
                  (unsigned char)*cptr == 0xff ||
                  *cptr == '&'))
            {
               *bptr++ = *cptr++;
               continue;
            }
            bptr += sprintf (bptr, "&#%u;", *cptr++ & 0xff);
         }
      }
      *bptr = '\0';
      if (CgiLib__Debug) fprintf (stdout, "BufferPtr |%s|\n", BufferPtr);

      /******************************/
      /* store associated variables */
      /******************************/

      if (CgiLib__CgiPrefixWWW)
         CgiLib__VarList (VarName, BufferPtr, NULL);
      else
         CgiLib__VarList (VarName+4, BufferPtr, NULL);
      VarCount++;

      free (BufferPtr);

      /* if a file name associated with the field (i.e. and upload) */
      if (ContentType[0])
      {
         strcpy (VarName + VarNameLength, "_MIME_CONTENT_TYPE");
         if (CgiLib__CgiPrefixWWW)
            CgiLib__VarList (VarName, ContentType, NULL);
         else
            CgiLib__VarList (VarName+4, ContentType, NULL);
         VarCount++;
      }

      /* if a file name associated with the field (i.e. and upload) */
      if (FileName[0])
      {
         strcpy (VarName + VarNameLength, "_MIME_FILENAME");
         if (CgiLib__CgiPrefixWWW)
            CgiLib__VarList (VarName, FileName, NULL);
         else
            CgiLib__VarList (VarName+4, FileName, NULL);
         VarCount++;
      }

      /* step over the "\r\n--" */
      cptr += 4;
   }

   return (VarCount);
}

/*****************************************************************************/

                           /********************/
                           /* VEEMEM FUNCTIONS */
                           /********************/

/*****************************************************************************/
/*
Enable/disable (1/0) VeeMem for applicable CGILIB functions.  Return the
previous setting.  Any call resets VeeMem memory.  This only enables/disables
VeeMem for CGILIB functions, an application can use VeeMem without CGILIB also
using it (but there is not much point if you're also using the applicable
CGILIB functions - see CGILIB prologue).
*/ 

int CgiLibVeeMemInUse (int OffOn)

{
   int  PrevVeeMemInUse;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibVeeMemInUse() %d\n", OffOn);

   PrevVeeMemInUse = CgiLib__VeeMemInUse;

   CgiLibVeeMemInit ();

   CgiLib__VeeMemInUse = OffOn;

   return (PrevVeeMemInUse);
}

/*****************************************************************************/
/*
The first call initialises the virtual memory zone.  Subsequent calls (and
there should be one at the conclusion of each request processed) releases back
into the virtual memory zone all of the individually allocated memory chunks.
*/ 

int CgiLibVeeMemInit ()

{
   static $DESCRIPTOR (ZoneNameDsc, "CGILIB_VEEMEM_ZONE");
   static unsigned long  Algorithm = LIB$K_VM_QUICK_FIT,
                 AlgorithmArg = 64,
                 Flags = LIB$M_VM_BOUNDARY_TAGS |
                         LIB$M_VM_GET_FILL0 |
                         LIB$M_VM_TAIL_LARGE,
                 ExtendSize = 512,
                 InitialSize = 512,
                 BlockSize = 64;

   int  status;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibVeeMemInit() %d\n", CgiLib__VeeMemZoneId);

   if (CgiLib__VeeMemZoneId)
      status = lib$reset_vm_zone (&CgiLib__VeeMemZoneId);
   else
      status = lib$create_vm_zone (&CgiLib__VeeMemZoneId,
                                   &Algorithm, &AlgorithmArg, &Flags,
                                   &ExtendSize, &InitialSize, &BlockSize,
                                   0, 0, 0, &ZoneNameDsc, 0, 0);

   CgiLib__VeeMemCurrent = CgiLib__VeeMemPeak = 0;

   return (status);
}

/*****************************************************************************/
/*
Allocate memory from the zone.
*/ 

void* CgiLibVeeMemCalloc (unsigned long ChunkSize)

{
   int  status;
   unsigned long  BaseAddress;
   void  *ChunkPtr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibVeeMemCalloc() %u\n", ChunkSize);

   vaxc$errno = 0;
   ChunkSize += sizeof(unsigned long) + CGILIB_VEEMEM_EBROOM;
   status = lib$get_vm (&ChunkSize, &BaseAddress, &CgiLib__VeeMemZoneId);
   if (!(status & 1))
   {
      vaxc$errno = status;
      return (NULL);
   }
   ChunkSize -= sizeof(unsigned long) + CGILIB_VEEMEM_EBROOM;
   *(ULONGPTR)BaseAddress = ChunkSize;
   ChunkPtr = (void*)(BaseAddress + sizeof(unsigned long));

   CgiLib__VeeMemCurrent += ChunkSize;
   if (CgiLib__VeeMemCurrent > CgiLib__VeeMemPeak)
      CgiLib__VeeMemPeak = CgiLib__VeeMemCurrent;
   if (CgiLib__Debug)
      fprintf (stdout, "current:%u peak:%u\n",
               CgiLib__VeeMemCurrent, CgiLib__VeeMemPeak);

   return (ChunkPtr);
}

/*****************************************************************************/
/*
Expand (or even contract) an individual a general-use chunk.  See VmGet().
*/ 

void* CgiLibVeeMemRealloc
(
void *ChunkPtr,
unsigned long ChunkSize
)
{
   int  status,
        CurrentChunkSize;
   unsigned long  BaseAddress,
                  CurrentBaseAddress;
   void  *CurrentChunkPtr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibVeeMemRealloc() %d\n", ChunkSize);

   vaxc$errno = 0;

   if (!ChunkSize) return (NULL);

   if (!ChunkPtr) return (CgiLibVeeMemCalloc (ChunkSize));

   CurrentChunkPtr = ChunkPtr;
   CurrentBaseAddress = (unsigned long)CurrentChunkPtr;
   CurrentBaseAddress -= sizeof(unsigned long);
   CurrentChunkSize = *(ULONGPTR)CurrentBaseAddress;

   /* if already large enough */
   if (CurrentChunkSize >= ChunkSize) return (ChunkPtr);

   /* allocate a new, larger chunk */
   ChunkSize += sizeof(unsigned long) + CGILIB_VEEMEM_EBROOM;
   status = lib$get_vm (&ChunkSize, &BaseAddress, &CgiLib__VeeMemZoneId);
   if (!(status & 1))
   {
      vaxc$errno = status;
      return (NULL);
   }
   ChunkSize -= sizeof(unsigned long) + CGILIB_VEEMEM_EBROOM;
   *(ULONGPTR)BaseAddress = ChunkSize;
   ChunkPtr = (void*)(BaseAddress + sizeof(unsigned long));

   /* copy the existing chunk into the new chunk */
   memcpy (ChunkPtr, CurrentChunkPtr, CurrentChunkSize);

   /* free the previous chunk */
   status = lib$free_vm (0, &CurrentBaseAddress, &CgiLib__VeeMemZoneId);
   if (!(status & 1))
   {
      vaxc$errno = status;
      return (NULL);
   }

   CgiLib__VeeMemCurrent -= CurrentChunkSize;
   CgiLib__VeeMemCurrent += ChunkSize;
   if (CgiLib__VeeMemCurrent > CgiLib__VeeMemPeak)
      CgiLib__VeeMemPeak = CgiLib__VeeMemCurrent;
   if (CgiLib__Debug)
      fprintf (stdout, "current:%u peak:%u\n",
               CgiLib__VeeMemCurrent, CgiLib__VeeMemPeak);

   return (ChunkPtr);
}

/*****************************************************************************/
/*
Explicitly release memory back into the zone.
*/ 

void CgiLibVeeMemFree (void *ChunkPtr)

{
   int  status,
        ChunkSize;
   unsigned long  BaseAddress;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibVeeMemFree()\n");

   vaxc$errno = 0;
   if (!ChunkPtr) return;

   BaseAddress = (unsigned long)ChunkPtr;
   BaseAddress -= sizeof(unsigned long);
   ChunkSize = *(ULONGPTR)BaseAddress;

   status = lib$free_vm (0, &BaseAddress, &CgiLib__VeeMemZoneId);
   if (!(status & 1)) vaxc$errno = status;

   CgiLib__VeeMemCurrent -= ChunkSize;
   if (CgiLib__Debug)
      fprintf (stdout, "chunk:%u current:%u peak:%u\n",
               ChunkSize, CgiLib__VeeMemCurrent, CgiLib__VeeMemPeak);
}

/*****************************************************************************/
/*
CGIlib usually just exits with an error status when a memory allocation fails.
With some memory allocation it's better to know that it failed.  Calling this
with either 1 (continue returning the expected result when failed) or 0 (just
exit with the error status) allows fine-grained behaviour control when using
functions that employ dynamic memory.  Works for both CgiLibVeeMem..()
allocated memory and calloc()/realloc() etc.  Returns the previous state.
*/ 

int CgiLibVeeMemContinue (int OffOn)

{
   int  WasOffOn;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug)
      fprintf (stdout, "CgiLibVeeMemContinue() %d\n", OffOn);

   WasOffOn = CgiLib__VeeMemContinue;
   CgiLib__VeeMemContinue = OffOn;
   return (WasOffOn);
}

/*****************************************************************************/
/*
Show (debug) the virtual memory zone.
(Just not interested in the user-arg parameter.)
Casting from (void*) to avoid compiler message %CC-I-PROTOSCOPE.
*/ 

int CgiLibVeeMemShow (void *StrDscPtr)

{
   static unsigned long  DetailLevel = 3;
   static int  veeMemZone = 0;

   int  status;
   unsigned long  FindContext,
                  ZoneId;
   struct dsc$descriptor  *DscPtr;

   /*********/
   /* begin */
   /*********/

   if (CgiLib__Debug) fprintf (stdout, "CgiLibVeeMemShow()\n");

   if (StrDscPtr)
   {
      /* action-routine */
      DscPtr = (struct dsc$descriptor*)StrDscPtr;
#if 0
      if (!veeMemZone)
      {
         if (DscPtr->dsc$w_length < 53) return (SS$_NORMAL);
         if (memcmp (DscPtr->dsc$a_pointer+21,
            "Zone name = \"CGILIB_VEEMEM_ZONE\"", 32)) return (SS$_NORMAL);
         veeMemZone = 1;
         fputs ("\n", stdout);
      }
#endif
      fprintf (stdout, "%*.*s\n",
               DscPtr->dsc$w_length, DscPtr->dsc$w_length,
               DscPtr->dsc$a_pointer);
      return (SS$_NORMAL);
   }

   FindContext = 0;
   while ((status = lib$find_vm_zone (&FindContext, &ZoneId)) == SS$_NORMAL)
   {
      status = lib$show_vm_zone (&ZoneId, &DetailLevel, &CgiLibVeeMemShow, 0);
      if (!(status & 1)) break;
   }
   if (status != LIB$_NOTFOU) return (status);
   fflush (stdout);

   veeMemZone = 0;
   return (SS$_NORMAL);
}

/*****************************************************************************/