1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 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
|
#ifndef VMS
ERROR -- CKVFIO.C is used only on the OpenVMS(tm) Operating System
#endif /* VMS */
#ifdef __ALPHA
# define CKVFIO_OS_ARCH_STRING " OpenVMS(tm) Alpha(tm)"
/* do nothing */
#else
# ifdef VAX
# define CKVFIO_OS_ARCH_STRING " OpenVMS(tm) VAX(tm)"
# else
# ifdef __GNUC__
# define CKVFIO_OS_ARCH_STRING " OpenVMS(tm) VAX(tm) (GCC)"
# else
# ERROR -- CKVTIO.C unknown architecture, neither VAX(tm) nor Alpha(tm)
# endif /* __GNUC__ */
# endif /* VAX */
#endif /* __ALPHA */
char *ckzv = "File support, 6.1.147, 7 May 1998";
char *ckzsys = CKVFIO_OS_ARCH_STRING;
/* C K V F I O -- Kermit file system support for VAX/VMS. */
/*
Author: Frank da Cruz <fdc@columbia.edu>
Columbia University Academic Information Systems, New York City.
Copyright (C) 1985, 1998, Trustees of Columbia University in the City of New
York. The C-Kermit software may not be, in whole or in part, licensed or
sold for profit as a software product itself, nor may it be included in or
distributed with commercial products or otherwise distributed by commercial
concerns to their clients or customers without written permission of the
Office of Kermit Development and Distribution, Columbia University. This
copyright notice must not be removed, altered, or obscured.
*/
/*
Originally adapted to VMS by:
Stew Rubenstein, Harvard University Chemical Labs, 1985,
Contributors:
Frank da Cruz (fdc), Columbia University Center, New York, NY (1985-present)
Stew Rubenstein, Harvard University Chemical Labs, Cambridge, MA (1985)
Martin Minow (MM), Digital Equipment Corporation, Maynard MA (1985)
Dan Schullman (DS), Digital Equipment Corporation, Maynard MA (1985)
Mark Buda (MAB), Digital Equipment Corporation, Nashua, NH (1989-90)
Terry Kennedy (TMK), St. Peter's College, Jersey City, NJ (1990-present)
William Bader (WB), Lehigh University, Bethlehem, PA (1990-93)
Gary Mussar (GM), Bell-Northern Research, Ottawa, Canada (1991)
James Sturdevant (JS) (1992)
Tarjei T. Jensen (ttj), Norwegian Hydrographic Service (1993-94)
Mark Berryman (mb), SAIC (1994)
Martin PJ Zinzer (mpjz), Gesellschaft fuer Schwerionenforschung GSI Darmstadt
*/
/* Edit history
* 003 20-Mar-85 MM fixed fprintf bug in zsout.c
* 004 21-Mar-84 MM create text files in variable-stream.
* 005 8-May-85 MM filled in zkself (not tested), fixed other minor bugs
* 006 5-Jul-85 DS handle version number in zltor, zrtol
* 007 11-Jul-85 fdc fix zclose() to give return codes
* 008 19-Mar-86 fdc Fix system() for "!", zopeni() for REMOTE commands.
* 008 17-Sep-87 fdc Define PWDCMD.
* 009 (???)
* 010 24-Jan-88 fdc Add zgtdir() function, even tho it doesn't work...
* 011 14-Feb-89 mab Make zgtdir() work in V2/V3 C envirements,
* Make zkself work using delprc() using Will Wood's changes.
* 012 26-Feb-89 mab Add function that searches for kermit.ini file in various
* ways
* 013 05-Mar-89 mab Add Barry Archers enhancements/fixes.
* 014 15-Mar-89 mab Check for non-null data, not array of pointers in
* zkermini
* 015 04-Apr-89 mab Add latent support for attribute packet. Clean up
* file name translation code.
* 016 05-Apr-89 mab Add PWP code to optimize packetizing.
* 017 16-Apr-89 mab PWP changes broke REMOTE command. Fixed.
* 018 18-Apr-89 mab #ifdef chkfn. This removes a lot of overhead.
* Add code to gtdir() for V4.x.
* 019 12-Jun-89 mab Add PWP's encode logic
* 020 09-Jul-89 mab Add logic to check for system() availability
* 021 10-Jul-89 mab Fix SHOW USER USERNAME. Added space after 'SHOW USER'.
* 022 27-Sep-89 mab Added zmail/zprint, plus added changes from CKUFIO.C
* 023 01-Dec-89 mab Add RMS file support
* 024 20-Jul-90 wb Add support for old VAX C & VMS versions + zstrip & rename
* 025 29-Jul-90 tmk Change space command to show avail, not used (match spec)
* 026 29-Jul-90 tmk Hack out the RMS stuff - it can come back when it works
* 027 29-Jul-90 tmk Likewise the VMS V3 stuff - ancient history
* 028 29-Jul-90 tmk Replace the attribute stuff. It now works.
* 029 31-Jul-90 tmk Fix CWD command (via hack)
* 030 31-Jul-90 tmk Fix assorted bugs preventing remote commands from working
* 031 31-Jul-90 tmk Correctly handle interrupted remote commands
* 032 04-Aug-90 tmk Start work on full RMS support for input files
* 033 04-Aug-90 tmk Tack LF on end of subprocess output lines
* 034 04-Aug-90 tmk Complete work on full RMS support for input files
* 035 04-Aug-90 tmk Add support for Fortran CC, fill in recfm data
* 036 05-Aug-90 tmk Add trailing CRLF on print format files
* 037 12-Aug-90 tmk Start work on full RMS support for output files
* 038 12-Aug-90 tmk Honor first free byte (FFB) on SENDs
* 039 13-Aug-90 tmk Finished first cut of full RMS support for output files
* 040 29-Sep-90 tmk Add iswild() from FDC for edit 157
* 041 06-Oct-90 tmk Add filetype IMAGE support for outbound transfers. Note
* that this doesn't currently work as the receiver overrides
* it (must talk to fdc).
* 042 06-Oct-90 tmk Make logfiles MRS=80. Being able to edit them outweighs
* any use for un-split lines.
* 043 17-Oct-90 wb Make zclosf() remove delete mailboxes & deassign channels
* used to talk to the subprocess, so quotas are not used
* up after repeated mailbox use (installed by fdc).
* 044 19-Oct-90 fdc Changed zxcmd() to use the fp[] arrays in the normal way,
* and zsyscmd to call zxcmd(ZIFILE) rather than
* zxcmd(ZSYSFN). Got rid of all calls to system(), used
* zsyscmd() instead, so commands like DIR could be
* interrupted. Made zoutdump() return(-1) rather than
* exit() when "line too long for buffer", and increased
* line output buffer from 1K to 4K.
* 045 01-Nov-90 tmk Corrected behavior of error check on $create call so a
* file supersede would work properly.
* 046 01-Nov-90 tmk Clone binary flag to ofile_bmode so we have a consistent
* view of this flag during file operations - the binary flag
* tends to toggle when we don't want/expect it to.
* 047 01-Nov-90 tmk Make IMAGE mode work. Note that image mode is only used
* when VMS is sending a file, and includes all record
* control characters not normally sent. Only useful in
* unusual circumstances.
* 048 01-Nov-90 tmk Remove spurious \n from zsoutl() which caused debug logs
* to have spurious <CR>'s when viewed with editors.
* 049 02-Nov-90 fdc Adapt to dynamic allocation of file i/o buffers. Changes
* are within #ifdef DYNAMIC..#else..#endif brackets.
* 050 02-Nov-90 fdc Make zsyscmd() close inferior process.
* 051 ??-???-?? ??? Add ckermit_init logical, return 0 on wildcard operations.
* 052 24-Dec-90 tmk Fix performance problems after 32Kb w/ ASCII receives, fix
2-nulls-per-32Kb in binary mode bug (actually in ckcker.h,
this is a placeholder).
* 053 13-Jan-91 tmk Add support for SET FILE RECORD-LENGTH.
* 054 14-Jan-91 tmk Fix cases of /x/CR/LF/y/ and /x/CR/LF/y/CR/LF/ in ASCII
* file receives.
* 055 16-Jan-91 tmk Log requested file type to debug log when receiving.
* 056 16-Jan-91 tmk Add support for all zstime() functions.
* 057 17-Jan-91 tmk Add support for zchkspa() function.
* 058 17-Jan-91 tmk Move debug() call into if clause in zxpand, per fdc.
* 059 18-Jan-91 tmk Support remote (DECnet) file accesses.
* 060 18-Jan-91 tmk Fix READ command.
* 061 30-Jan-91 tmk Support creation of UNDEFINED file types for brain-dead
* BASIC implementation.
* 062 30-Jan-91 tmk Fix REMOTE commands when VERIFY is set.
* 063 29-Mar-91 tmk Add padding factor for received text files to accomodate
* space taken up by record delimiters (per fdc).
* 064 29-Mar-91 gm Remove unnecessary mem-mem moves during ASCII receives.
* (Installed by tmk. To back out, #define OLD_WAY).
* 065 30-Mar-91 tmk First pass at implementing LABELED. Send only, dummy
* data records.
* 066 02-Apr-91 tmk Finish first pass at LABELED. Send VMS filename, attri-
* butes. Still need ACL's, "hidden" char. longword, recep-
* tion.
* 067 09-Apr-91 tmk LABELED bugfixes - VMSFILE is 70 bytes, not 74, use the
* xab$w_lrl field instead of rab$w_rsz, fab$w_deq instead
* of xab$w_rsz, fab$b_bks instead of xab$b_bkz, always pro-
* cess an even multiple of 512 bytes when LABELED.
* 068 14-Apr-91 tmk Don't use C definition of fab$b_journal as it doesn't ex-
* ist before C V3.1. Compute it ourselves instead.
* 069 15-Apr-91 tmk Initial work on retrieving ACL information for LABELED.
* 070 16-Apr-91 tmk Make edits 066-069 compatible with DECnet.
* 071 21-May-91 tmk Address R. Weiner QAR item 2 (filesize).
* 072 21-Jun-91 tmk Check (and prohibit) spawns from captive accounts.
* 073 21-Jun-91 tmk Fix session logging (for Charlie Luce/DECUServe).
* 074 21-Jun-91 tmk Rework 071 to only apply to SPAWN/PUSH and not to the
* pseudo-builtins like DEL, SPACE, WHO, PWD, etc.
* 075 21-Jun-91 tmk Fix possible endless loop when flushing output file in
* zclosf() after zoutdump() error.
* 076 21-Jun-91 tmk First pass on handling inbound LABELED files.
* 077 14-Nov-91 tmk Fix zprint(), zmail() (need to use system() for these).
* This is a partial backout of 044.
* 078 14-Nov-91 tmk Various cleanups. Delete files after successful mailing
* or printing, remove dead code inside #ifdef COMMENT and
* #ifdef OLD_WAY, fix typo in spawning message, make sure
* all source lines < 80 chars.
* 079 22-Nov-91 fdc Change zmail(), zprint() error return values to improve
* error reporting.
* 080 18-Jan-92 tmk Fix REMOTE so output from a remote command correctly dis-
* plays on terminal. This has been broken since 040 or so.
* 081 10-Jun-92 tmk Add William Bader's fix for fixed-length files which have
* record attributes.
* 082 03-Jul-92 tmk Fix really bad bug introduced in 081 (which made *all*
* fixed-format files be sent as text).
* 083 15-Jul-92 jah Fix fencepost error in zoutdump when line breaks at 32K.
* 084 03-Aug-92 fdc Remove current directory from init file search.
* 085 26-Aug-92 tmk Add Bernd Onasch's fix for fgen().
* 086 28-Aug-92 tmk Fix bug reported by Bill Hoelzer where C-K would execute
* a file named "." as a C-K initialization file.
* 087 04-Sep-92 tmk Fix bug reported by Chuck McMichael where C-K would not
* set the FFB properly when receiving a labeled file which
* did not have the FFB on a record boundary.
* 088 09-Sep-92 tmk Fix Hunter Goatley's problem with SPAWN command ignoring
* Ctrl-C.
* 089 11-Sep-92 js Fixed malloc() in zmail().
* 090 28-Oct-92 tmk Fix null-byte error introduced by 087. Gee, this looked
* so simple when I designed it.
* 091 02-Nov-92 tmk Start work on fixing spawn/push/remote commands, due to
* popular whining.
* 092 03-Nov-92 tmk Finish up initial 091 work. Vote for Kermit!
* 093 03-Nov-92 fdc Change zkermini() to work with "-y" command-line option.
* 094 04-Nov-92 tmk Make zxpand() not return all files if given null string.
* 095 05-Nov-92 fdc Make zxcmd(), zclose(), etc, handle ZRFILE (OPEN !READ).
* 096 17-Feb-93 fdc prevent zopeno from calling zstime if date struct is NULL,
* and add support for ZMFILE (misc output file).
* 097 08-Apr-93 tmk Correctly handle "international VMS" which uses <> instead
* of [] for directory delimiters.
* 098 16-May-93 fdc ANSIfication for GNU CC, from James Sturdevant, plus
* add FAB$M_PRN to list of text-file types, for VMS batch
* logs.
* 099 07-Jun-93 fdc Fix calculation of file size in zchki(), fix declaration
* of mbxnam[] (add one to size) to prevent overflow, which
* would result in failure of server to respond to REMOTE
* directory, etc. Both fixes from Bill Glass.
* 100 21-Jun-93 fdc file_date[] and attr_date[] declarations in zstime()
* changed from long to unsigned long to prevent signed date
* comparisons, which could prevent SET FILE COLLISION
* UPDATE from working. From James Sturdevant.
* 101 8-Aug-93 fdc Add types to all function declarations.
* 102 18-Aug-93 ttj Minor updates in zsattr() and do_label_recv() mainly to
* quieten the compiler (which had every reason to complain).
* 103 5-Nov-93 wb Add isdir() function.
* 104 8-Nov-93 wb Add zfcdate() function.
* 105 25-Nov-93 fdc Correct record format for session log; change name of
* password structure member of zattr struct.
* 106 22-Dec-93 tmk Correct fd "leakage" in OPEN READ/CLOSE READ pairs.
* 107 26-Feb-94 mb Addition of zmkdir() routine.
* 108 27-Mar-94 tmk Increase max record size for logs from 80 to 254.
* Add support for file append operations.
* Make zkself() retry a few times to avoid zombies on BYE.
* 109 5-Apr-94 tmk Fix xx->lengthk not being set in zsattr().
* 110 8-Jun-94 tmk Use private fab in zchki (fixes OPEN READ bug).
* 111 17-Jun-94 tmk Let zsattr() work even if there is no rights database.
* 112 7-Jul-94 js A couple small ANSIfications for gcc.
* 113 7-Aug-94 fdc Make zshcmd()/zsyscmd() return proper return code, with
* help from Larry Henry at TWG. Still not quite right...
* 114 29-Sep-94 fdc Increase max wildcard matches from 500 to 4096.
* 115 4-Oct-94 mb Add support for RESEND.
* 116 26-Oct-94 mb Minor fix to 115.
* 117 1-Nov-94 wb A couple #ifdefs added to allow compilation in VMS v4.
* 118 25-Feb-95 mpjz Fix for DECC on VAX.
* 119 11-May-96 fdc Change znewn() to change version to x+1, or add ;0.
* 120 31-May-96 fdc Fix zfnqfp() to remove trailing .; if directory name.
* 121 12-Jun-96 fdc Prevent dereferencing null pointer in do_label_recv().
* 122 23-Jun-96 fdc Fix a bug in do_label_recv that I introduced in edit 121.
* 123 21-Aug-96 fdc Separate ZRFILE from ZIFILE so now we can have both.
* 124 21-Aug-96 fdc Fix includes for getenv & strcpy for DECC vs VAXC.
* 125 25-Aug-96 mpjz More DECC/VAX fixes.
* 126 05-Sep-96 fdc Remove #module, remove refs to xaballdef$$_fill_7.
* 127 06-Sep-96 fdc Recover from interrupted labeled-mode receives.
* 128 06-Sep-96 fdc Recover from the previous edit.
* 129 06-Sep-96 fdc Fix zchki() to return -2 if blah.DIR;n is a directory.
* 130 06-Sep-96 fdc Fixes to isdir(), zstrip(), zchdir().
* 131 17-Feb-97 fdc Another fix to isdir() (free() was called too early).
* 132 14-Jul-97 fdc fgen() malloc'd but never freed filenames; isdir()
* now handles directory files too (like [FOO]BAR.DIR;1).
* 133 14-Jul-97 mb New isdir() function uses sys$parse().
* 134 15-Jul-97 fdc Added cvtdir(); rewrote zchdir() to use it & new isdir().
* 135 14-Aug-97 fdc zopeni: Change mainline binary variable when switching
* automatically from text to binary mode (cosmetic only).
* 136 24-Aug-97 fdc zhome: Return SYS$LOGIN value rather than HOME value.
* 137 04-Sep-97 fdc zchdir: use sys$setddir() rather than chdir() because
* VMS 6.2 CRTL chdir() has bugs.
* 138 06-Sep-97 fdc zchdir again -- try one, then the other. Add startupdir.
* 139 04-Nov-97 fdc Handle absolute/relative/standard/literal dir names.
* 140 12-Dec-97 fdc Fix fgen() to report directories if not told not to.
* 141 1-Jan-98 fdc Send and set file protections: zsattr(), zstime().
* 142 15-Jan-98 fdc Raised max number of files (MAXWLD) from 4K to 1024K.
* and made the mtchs[] array dynamic.
* 143 29-Jan-98 fdc Make zshcmd() (RUN command) return proper status,
* ditto for zxcmd(), and make both set pexitstat.
* Also, added ckvmserrstr().
* 144 8-Feb-98 lh Add diagnostic message when SPAWN fails; handle files
* with odd fixed record length; isdir() improvements.
* 145 8-Feb-98 fdc Slightly better handling of failures in zrmdir().
* 146 3-May-98 fdc Fix out-of-bounds cdate[] array reference.
* 147 7-May-98 lh another isdir() update; expanded mb (Apr-98) version.
* lh Add REL_DIR item for do_label transfers.
* lh FTN CC to handle zero-length records and overprinting.
* lh Fix zltor for fspath and no match.
* fdc Fix zmkdir to return 1 if >0 directories were created.
*/
/* Definitions of some VMS system commands */
char *DIRCMD = "directory "; /* For directory listing */
char *DIRCM2 = "directory "; /* For directory listing, no args */
char *DELCMD = "delete "; /* For file deletion */
char *TYPCMD = "type "; /* For typing a file */
char *SPACMD = "show quota "; /* Space/quota of current directory */
char *SPACM2 = "show quota "; /* Space/quota of specified dir */
char *WHOCMD = "show users "; /* For seeing who's logged in */
char *PWDCMD = "show default "; /* For seeing current directory */
/*
Functions (n is one of the predefined file numbers from ckermi.h):
zopeni(n,name) -- Opens an existing file for input.
zopeno(n,name) -- Opens a new file for output.
zclose(n) -- Closes a file.
zchin(n) -- Gets the next character from an input file.
zsout(n,s) -- Write a null-terminated string to output file, buffered.
zsoutl(n,s) -- Like zsout, but appends a line terminator.
zsoutx(n,s,x) -- Write x characters to output file, unbuffered.
zchout(n,c) -- Add a character to an output file, unbuffered.
zchki(name) -- Check if named file exists and is readable, return size.
zchko(name) -- Check if named file can be created.
zchkspa(name,n) -- Check if n bytes available to create new file, name.
znewn(name,s) -- Make a new unique file name based on the given name.
zdelet(name) -- Delete the named file.
zxpand(string) -- Expands the given wildcard string into a list of files.
znext(string) -- Returns the next file from the list in "string".
zxcmd(n,cmd) -- Execute the command in a lower fork on file number n.
zclosf() -- Close input file associated with zxcmd()'s lower fork.
zrtol(n1,n2) -- Convert remote filename into local form.
zltor(n1,n2) -- Convert local filename into remote form.
zchdir(dirnam) -- Change working directory.
zhome() -- Return pointer to home directory name string.
zkself() -- Log self out
zsattr(struc zattr *) -- Return attributes for file which is being sent.
zkermini(n1,n2) -- Find kermit.ini using default scanning process
*/
/* Includes */
#define CKVFIO_C
#include "ckcdeb.h"
#include "ckcasc.h"
#include "ckcker.h"
#include "ckvvms.h"
#include <stdio.h>
#include <types.h>
#include <stat.h>
#include <ctype.h>
#include <time.h>
#include <errno.h>
#include <rms.h>
#include <ssdef.h>
#include <descrip.h>
#include <dvidef.h>
#include <dcdef.h>
#include <iodef.h>
#include <jpidef.h>
#include <signal.h>
#include <string.h>
#include <syidef.h>
#ifndef OLD_VMS
#include <uaidef.h>
#endif /* OLD_VMS */
/* rms.h above includes nam, fab, xab and rmsdef */
/* vms v4 headers do not check against multiple inclusion */
/* ifndefs below prevent multiple declaration of FAB and NAM structs */
#ifndef FAB$C_BID
#include <fab.h> /* These are needed for isdir() */
#endif /* FAB$C_BID */
#ifndef NAM$C_BID
#include <nam.h>
#endif /* NAM$C_BID */
#include <lnmdef.h>
#include <rmsdef.h>
#ifndef MAXWLD
#define MAXWLD 102400 /* Maximum wildcard filenames */
#endif /* MAXWLD */
/* external def. of things used in buffered file input and output */
#ifdef DYNAMIC
extern CHAR *zinbuffer, *zoutbuffer;
#else
extern CHAR zinbuffer[], zoutbuffer[];
#endif /* DYNAMIC */
static CHAR rinbuffer[INBUFSIZE], *rinptr;
static int rincnt;
extern CHAR *zinptr, *zoutptr;
extern int zincnt, zoutcnt;
extern int binary;
extern int frecl;
extern int rcflag;
extern long vernum;
/* Declarations */
FILE *fp[ZNFILS] = { /* File pointers */
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
static long iflen = -1; /* Input file length */
static long rflen = -1;
static long oflen = -1; /* Output file length */
static int fcount; /* Number of files in wild group */
static char nambuf[255]; /* maximum size of a file spec */
static char cwdbuf[NAM$C_MAXRSS];
static struct iosb_struct tmpiosb; /* For QIOW */
extern unsigned long vms_status; /* Used by CHECK_ERR */
extern unsigned long vms_lasterr;
static int cflag; /* Flag indicating console in use */
int check_spawn(void);
int do_label_recv(void);
int do_label_send(char *name);
int fgen(char *pat, char *resarry[], int len);
static int rinfill(void);
#ifdef COMMENT
#ifdef __DECC
#include <stdlib.h>
#else
char *getenv(), *strcpy();
#endif /* __DEC */
#else
/* Recommended by Lee Tibbert */
#ifdef __DECC
#include <stdlib.h>
#include <string.h>
#else
char *getenv(), *strcpy();
#endif /* __DECC */
#endif /* COMMENT */
#ifdef __DECC
#include <lib$routines.h>
#include <starlet.h>
#endif /* __DECC */
int pexitstat = -2; /* Process exit status */
unsigned long pexitlong = -2L; /* ULONG version of same */
#ifdef COMMENT
/* static */ /* Not static any more! */
char *mtchs[MAXWLD], /* Matches found for filename */
**mtchptr; /* Pointer to current match */
#else
char **mtchs = NULL, **mtchptr = NULL;
#endif /* COMMENT */
static unsigned short mbx_chan; /* Mailbox chan for REMOTE commands */
static int subprocess_input = 0, sub_count;
static char *sub_ptr, sub_buf[SUB_BUF_SIZE];
#define SUPERSAFE /* For safe subprocesses */
static unsigned long sub_pid;
/*
* Structures for input (SEND) file
*/
static struct FAB fab_ifile; /* For SEND file */
static struct RAB rab_ifile;
static struct XABDAT xabdat_ifile;
static struct XABFHC xabfhc_ifile;
static struct XABPRO xabpro_ifile;
static struct XABALL xaball_ifile;
static int ifile_bmode; /* For SEND file */
static int ifile_bcount;
static char aclbuf[512];
static unsigned long xuchar = 0;
static struct FAB fab_rfile; /* For OPEN READ file */
static struct RAB rab_rfile;
static struct XABDAT xabdat_rfile;
static struct XABFHC xabfhc_rfile;
static struct XABPRO xabpro_rfile;
static struct XABALL xaball_rfile;
static int rfile_bmode; /* For READ file */
static int rfile_bcount;
static char raclbuf[512];
/*
* Structures for output (RECEIVE) file
*/
static struct FAB fab_ofile;
static struct RAB rab_ofile;
static struct XABDAT xabdat_ofile;
static struct XABFHC xabfhc_ofile;
static struct XABPRO xabpro_ofile;
static struct XABALL xaball_ofile;
static struct XABRDT xabrdt_ofile;
static int ofile_dump;
static int ofile_bmode;
static int ofile_lblopts;
static int ofile_lblproc = 0;
static char revdat[8];
static unsigned short revnum;
static char ofile_vmsname[CKMAXPATH+1];
static char ofile_vmsacl[512];
static int ofile_acllen;
static short ofile_ffb;
char startupdir[NAM$C_MAXRSS+1];
/*
* Common RMS items
*/
static unsigned long int rms_sts;
/* I S W I L D -- Tells whether filespec "str" is wild */
/* Returns 0 if not wild, 1 if wild */
int
iswild(str) char *str; {
char c;
while ((c = *str++) != '\0')
if (c == '*' || c == '%') return(1);
return(0);
}
#ifdef CK_TMPDIR
/* I S D I R -- Tells if string pointer s is the name of a directory. */
/*
Returns:
0 if s is not a directory or doesn't exist
Nonzero if it is a directory:
1 if the string is a directory specification, e.g., [FOO.BAR]
2 if it is the name of a directory file, like [FOO]BAR.DIR;1
*/
int
isdir(s) char *s; {
#ifdef COMMENT /* Frank's version */
int x;
int i, s_len;
char *full_name = NULL;
char *p = NULL;
static char dot_dir[] = ".dir";
static char zero_dir[] = "[000000]";
char name_buf[255]; /* Was 512 but that's too big */
char tmpbuf[255]; /* for unsigned char... */
struct FAB fab;
struct NAM nam;
struct dsc$descriptor_s indesc;
$DESCRIPTOR(lnmtable, "LNM$FILE_DEV");
int new_len;
int serial_num;
struct {
short length;
short code;
char *address;
int *len;
int term;
} itemlist;
if (!s) return(0);
if (!*s) return(0);
/* Determine if this is something we can SET DEFAULT to... */
s_len = strlen(s);
debug(F111,"isdir",s,s_len);
/* Does it look like a directory name? */
if (s[s_len-1] != ':' && s[s_len-1] != ']' && s[s_len-1] != '>') {
#ifdef COMMENT
/*
Bad idea. No, the user really has to include the colon, otherwise the
intention is ambiguous.
*/
p = tmpbuf; /* No, maybe it's a logical name */
strncpy(tmpbuf,getenv(s),254);
if (*p) {
s = p;
s_len = strlen(s);
if (s < 1) /* No definition */
return(0);
/* It is a logical name, but does it look like a dir name? */
if (s[s_len-1] != ':' && s[s_len-1] != ']' && s[s_len-1] != '>')
return(0); /* No, it doesn't */
}
#else
/* Check for "DEV:[FOO]BLAH.DIR;1"... */
if (zchki(s) == -2) { /* It's a directory */
int i;
char * p = NULL; /* Pointer to period */
debug(F111,"isdir zchki",s,-2);
/* Note: This does not handle "FOO.DIR.1"... */
for (i = s_len; i > 0; i--) {
if (s[i] == '.')
p = s+i;
else if (s[i] == ']' || s[i] == '>')
break;
}
debug(F110,"isdir p",p,0);
if (p) {
if ((*(p+1) == 'D' || *(p+1) == 'd') &&
(*(p+2) == 'I' || *(p+2) == 'i') &&
(*(p+3) == 'R' || *(p+3) == 'r') &&
(*(p+4) == ';' || *(p+4) == NUL || *(p+4) == SP))
return(2);
}
}
return(0);
#endif /* */
}
/* Check that the directory part is valid... */
if (s[s_len-1] == ']' || s[s_len-1] == '>') {
fab = cc$rms_fab;
nam = cc$rms_nam;
fab.fab$l_dna = 0;
fab.fab$b_dns = 0;
fab.fab$l_fna = s;
fab.fab$b_fns = s_len;
fab.fab$l_fop = 0;
fab.fab$w_ifi = 0;
fab.fab$l_nam = &nam;
nam.nam$l_esa = name_buf;
nam.nam$b_ess = sizeof(name_buf);
nam.nam$b_nop = 0;
nam.nam$l_rlf = 0;
nam.nam$l_rsa = 0;
nam.nam$b_rsl = 0;
nam.nam$l_fnb = 0;
i = sys$parse(&fab, 0, 0);
if (!(i & 1)) vms_lasterr = i;
#ifdef COMMENT
printf("parse returned %d 0x%x, nam fnb is %d 0x%x\n",
i, i, nam.nam$l_fnb, nam.nam$l_fnb);
#endif /* COMMENT */
if ((i & 1) == 0) return(0);
}
/* Check that the logical name is valid */
i = s_len - 1;
while (i >= 0 && s[i] != ':') i--;
if (i >= 0 && s[i] == ':') {
if (i == 0) return(0); /* Single colon (:) */
if (s[i-1] == ':') {
if (i > 1) return(1); /* DECnet node name (blah::) */
else return(0); /* or :: alone. */
}
s_len = i;
full_name = malloc(s_len + 1);
if (!full_name) return(0);
/* Logicals must be upper case */
for (i = 0; i < s_len; i++) {
full_name[i] = s[i];
if (full_name[i] >= 'a' && full_name[i] <= 'z')
full_name[i] -= ('a' - 'A');
}
indesc.dsc$w_length = s_len;
indesc.dsc$a_pointer = full_name;
indesc.dsc$b_class = DSC$K_CLASS_S;
indesc.dsc$b_dtype = DSC$K_DTYPE_T;
itemlist.length = new_len = sizeof(name_buf);
itemlist.code = LNM$_STRING;
itemlist.address = name_buf;
itemlist.len = &new_len;
itemlist.term = 0;
i = sys$trnlnm(0, &lnmtable, &indesc, 0, &itemlist);
if (!(i & 1)) vms_lasterr = i;
if (i != SS$_NORMAL || new_len < 0) new_len = 0;
if (new_len >= sizeof(name_buf)) new_len = sizeof(name_buf) - 1;
name_buf[new_len] = '\0';
#ifdef COMMENT
printf("trnlnm result %d 0x%x, '%.*s'\n", i, i, new_len, name_buf);
#endif /* COMMENT */
if (new_len == 0) {
/* Could still be a device name. */
/* Only disks have serial numbers... */
serial_num = 0;
itemlist.length = new_len = sizeof(serial_num);
itemlist.code = DVI$_SERIALNUM;
itemlist.address = (char *) &serial_num;
itemlist.len = &new_len;
itemlist.term = 0;
i = sys$getdvi(0, 0, &indesc, &itemlist, 0, 0, 0, 0);
if (!(i & 1)) vms_lasterr = i;
#ifdef COMMENT
printf("getdvi ret %d 0x%x, serial %d len %d\n",
i, i, serial_num, new_len);
#endif /* COMMENT */
free(full_name);
return(((i & 1) == 1 && new_len > 0) ? 1: 0);
} else if (name_buf[new_len-1] == ':' ||
name_buf[new_len-1] == ']' ||
name_buf[new_len-1] == '>') {
/* Check returned value */
if (new_len > 2 &&
(name_buf[new_len-1] == ']' || name_buf[new_len-1] == '>') &&
name_buf[new_len-2] == '.') {
/* Remove trailing dot in directory of logical name */
name_buf[new_len-2] = name_buf[new_len-1];
name_buf[new_len-1] = '\0';
}
free(full_name);
return( isdir(name_buf) );
} else {
/* Logical name is just a random string signifying nothing */
free(full_name);
return(0);
}
}
return(1);
#else /* Mark Berryman's version... */
/* Searching for a file ".;" in the specified directory handles both local
* and DECNET references and determines whether a ".DIR;1" file is indeed
* a directory. No test is performed for multiple directories matching a
* wildcard expansion; cmifi2 does that after a isdir call.
*/
unsigned int retval, status, srch_lst=0;
struct FAB path_fab;
struct NAM path_nam;
const char *directory_type = ".DIR";
char ch, *path =s;
char expanded_name[NAM$C_MAXRSS];
char resultant_name[NAM$C_MAXRSS];
path_fab = cc$rms_fab;
path_fab.fab$l_fna = path;
path_fab.fab$b_fns = strlen(path);
path_fab.fab$l_nam = &path_nam;
path_nam = cc$rms_nam;
path_nam.nam$l_esa = (char *) &expanded_name;
path_nam.nam$b_ess = sizeof(expanded_name);
path_nam.nam$l_rsa = (char *) &resultant_name;
path_nam.nam$b_rss = sizeof(resultant_name);
path_nam.nam$b_nop = NAM$M_SRCHXABS | NAM$M_NOCONCEAL;
/* remote node DISPLAY w/o OPEN */
/* show physical device & root */
retval = 1; /* default type return value */
/* PARSE the string */
status = sys$parse(&path_fab,0,0);
if (!(status & 1)) { /* any $PARSE errors are fatal */
debug(F111,"isdir $PARSE", path, status);
vms_lasterr = status;
return (0);
}
/* a directory may be specified as "lnm:foo.dir". Do a $SEARCH to traverse
* a search list logical and locate the file; pass on the resultant name
* to determine whether the file is a directory file.
*/
srch_lst = path_nam.nam$l_fnb & NAM$M_SEARCH_LIST;
if (srch_lst) {
status = sys$search(&path_fab,0,0);
if (!(status & 1)) {
vms_lasterr = status;
debug(F101," isdir srch_lst status", "", status);
return(0);
}
*(path_nam.nam$l_ver + path_nam.nam$b_ver) = '\0';
debug(F110, " isdir srch_lst result", path_nam.nam$l_node,0);
}
/* Was a file name given ? */
if (path_nam.nam$b_name == 0) {
if (path_nam.nam$b_type != 1) return(0);
/* Parse returns a file name of ".;" if no filename is given. However,
* that is a valid filename. Testing gets complicated; the following
* will not catch the case of such a file name passed as a logical,
* but will otherwise return(0) when given a file name as "." or ";"
*/
if ( *path_nam.nam$l_dir == '[' ) ch = (int)']';
else ch = (int)'>';
if (strchr(path,ch)) { /* directory in path */
if (*(strchr(path,ch)+1) == '.' ||
*(strchr(path,ch)+1) == ';' ) {
debug(F111,"isdir file w/ zero length name" ,path, 0);
return(0);
}
}
else { /* no directory specification */
if (strchr(path,(int)'.') || strchr(path,(int)';') )
return(0);
}
if (srch_lst) return(retval); /* already did the SEARCH for ".;" */
}
else {
/* If a filename was in the path, a directory will only be something.dir */
/* Check to see if a directory was specified as a filename.
This is done as follows:
a) The result of the parse has been returned in a string pointed
to by path_nam.nam$l_esa in the form of device:[dir.dir]name.type;
nam$l_dev ==> start of device
nam$l_dir ==> first [
nam$l_name ==> first char after closing ]
nam$l_type ==> period between name and type
nam$l_ver ==> the semicolon
b) Zero-terminate the TYPE by replacing the ; with a zero
c) Make sure TYPE is .DIR
d) replace the closing ] with a .
e) replace the . that starts the file TYPE with a ]
f) reparse
*/
*path_nam.nam$l_ver = '\0'; /* zero terminate file TYPE */
if (!strcmp(path_nam.nam$l_type, directory_type)) {
*path_nam.nam$l_type = *(path_nam.nam$l_name-1); /* copy the ] */
*(path_nam.nam$l_name-1) = '.'; /* then change to . */
path_fab.fab$l_fna = path_nam.nam$l_node; /* point FAB to result*/
path_fab.fab$b_fns = path_nam.nam$l_type+1-path_nam.nam$l_node;
status = sys$parse(&path_fab,0,0); /* parse new string */
if (!(status & 1)) {
debug(F111,"isdir second $PARSE", path, status);
vms_lasterr = status;
return (0);
}
retval = 2;
}
else return(0); /* non-directory filename specified */
}
/* Access the directory */
status = sys$search(&path_fab,0,0);
if ( !((status == RMS$_FNF) || (status & 1))) {
switch (status) {
case RMS$_DNF:
debug(F100," isdir SEARCH RMS$_DNF", "", 0);
break;
case RMS$_FND:
if (path_fab.fab$l_stv == SS$_BADIRECTORY) {
debug(F100," isdir .DIR file not a directory", "" ,0);
break;
}
else {
debug(F101,"isdir directory access RMS$_FND stv","",
path_fab.fab$l_stv);
vms_lasterr = status;
break;
}
default:
retval = 0;
debug(F101,"isdir $SEARCH status","", status);
vms_lasterr = status;
}
return(0);
}
*(path_nam.nam$l_ver + path_nam.nam$b_ver) = '\0';
debug(F110," isdir final string", path_nam.nam$l_node,0);
debug(F101,"isdir directory code","",retval);
return(retval);
#endif /* COMMENT */
}
#endif /* CK_TMPDIR */
/* Z K S E L F -- Log self out. */
int
zkself() {
int i;
unsigned long int rms_s;
/*
We need a better way. If C-Kermit was spawned, this does not log out the
whole job. It also does not hang up LAT terminal sessions.
*/
for (i = 0; i < 10; i++) {
rms_s = sys$delprc(0,0); /* Maybe some output is still */
if (!(rms_s & 1)) vms_lasterr = rms_s;
debug(F101,"zkself rms_s","",rms_s);
if (rms_s == SS$_NORMAL) /* queued; try a few times... */
exit(1);
sleep(1);
}
exit(rms_s == SS$_NORMAL);
return(0); /* dummy - required as this is called in a non-void context */
}
/* Z O P E N I -- Open an existing file for input. */
int
zopeni(n,name) int n; char *name; {
debug(F111,"zopeni",name,n);
debug(F101,"zopeni fp","",(int) fp[n]);
if (chkfn(n)) return(0);
if (n == ZSYSFN) { /* Input from a system function? */
debug(F110,"zopeni called with ZSYSFN, failing!",name,0);
*nambuf = '\0'; /* No filename. */
return(0); /* fail. */
}
zincnt = 0; /* Initializing these couldn't hurt */
zinptr = zinbuffer;
if (n == ZSTDIO) { /* Standard input? */
if (isatty(0)) {
ermsg("?Terminal input not allowed\n");
debug(F110,"zopeni attempted input from unredirected stdin","",0);
return(0);
}
fp[ZIFILE] = stdin;
return(1);
}
/*
* We open the file but waffle on the access mode we're going to use. We then
* inspect the file characteristics to see if the organization is fixed or un-
* defined. If it is, we convert to block mode operation. This is needed since
* VMS maintains a "first free byte" field to tell us how much of the last rec-
* ord really contains data, but won't terminate reads at that point. Thus, if
* we want to SEND the exact same file we RECEIVEd, we have to honor the FFB
* internally.
*/
if (n == ZIFILE) {
ifile_bmode = 0; /* 0 = not binary */
ifile_bcount = 0;
fab_ifile = cc$rms_fab;
fab_ifile.fab$b_fac = FAB$M_BRO | FAB$M_GET;
/*
* Some non-VMS DECnet implementations don't allow switching modes, so set
* block-I/O only mode if the user said SET FILE TYPE IMAGE or LABELED.
*/
if (binary == XYFT_I || binary == XYFT_L)
fab_ifile.fab$b_fac = FAB$M_BIO | FAB$M_GET;
fab_ifile.fab$l_fna = name;
fab_ifile.fab$b_fns = strlen(name);
fab_ifile.fab$l_xab = (char *)&xabdat_ifile;
rab_ifile = cc$rms_rab;
rab_ifile.rab$l_fab = &fab_ifile;
xabdat_ifile = cc$rms_xabdat;
xabdat_ifile.xab$l_nxt = (char *)&xabfhc_ifile;
xabfhc_ifile = cc$rms_xabfhc;
xabfhc_ifile.xab$l_nxt = (char *)&xabpro_ifile;
xabpro_ifile = cc$rms_xabpro;
memset(&aclbuf, 0, sizeof(aclbuf));
xabpro_ifile.xab$l_aclsts = SS$_NORMAL; /* Oh Joy! DECnet */
xabpro_ifile.xab$l_aclbuf = (char *)&aclbuf;
xabpro_ifile.xab$w_aclsiz = sizeof(aclbuf);
xabpro_ifile.xab$l_aclctx = 0;
xabpro_ifile.xab$l_nxt = (char *)&xaball_ifile;
xaball_ifile = cc$rms_xaball;
rms_sts = sys$open(&fab_ifile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zopeni $open failed, status","",rms_sts);
debug(F101,"zopeni $open failed, stv","",fab_ifile.fab$l_stv);
return(0);
}
if (!(xabpro_ifile.xab$l_aclsts & 1)) {
if (xabpro_ifile.xab$l_aclsts != SS$_ACLEMPTY) {
debug(F101,"zopeni $open ACL failed, status","",
xabpro_ifile.xab$l_aclsts);
return(0);
}
}
/* We have the file opened. See if it's fixed or undefined format... */
iflen = ((xabfhc_ifile.xab$l_ebk-1)*512)+xabfhc_ifile.xab$w_ffb;
if (fab_ifile.fab$b_rfm == FAB$C_UDF) {
debug(F100,"zopeni undefined file format - using blk I/O","",0);
ifile_bmode = 1;
}
if (fab_ifile.fab$b_rfm == FAB$C_FIX) {
if ((fab_ifile.fab$b_rat & (FAB$M_FTN | FAB$M_CR | FAB$M_PRN))
== 0) {
/* But it may be changed later, for BINARY mode and odd record length */
debug(F100,"zopeni fixed file format - using blk I/O","",0);
ifile_bmode = 1;
}
}
debug(F101,"zopeni binary flag at open","",binary);
if (binary == XYFT_I) {
debug(F100,"zopeni using IMAGE mode by user request","",0);
ifile_bmode = 1;
}
if (binary == XYFT_L) {
debug(F100,"zopeni using LABELED mode by user request","",0);
ifile_bmode = 2;
}
debug(F101,"zopeni ifile_bmode","",ifile_bmode);
debug(F101,"zopeni binary","",binary);
if (ifile_bmode == 1 && binary == XYFT_T) {
debug(F100,"zopeni autoswitch from TEXT to BINARY","",0);
binary = XYFT_B;
} else if (ifile_bmode == 0 && binary == XYFT_B) {
debug(F100,"zopeni autoswitch from BINARY to TEXT","",0);
binary = XYFT_T;
}
/*
* In BINARY mode, for the case of fixed record length format with odd
* length records, use record i/o to suppress the RMS NUL pad ala Kermit-32
*/
if ((fab_ifile.fab$b_rfm == FAB$C_FIX) &&
(fab_ifile.fab$w_mrs | 1) &&
(binary == XYFT_B)) {
ifile_bmode = 0;
debug(F100,"zopeni record i/o for BINARY, Odd Fixed RL","",0);
}
rab_ifile.rab$l_rop = 0;
rms_sts = sys$connect(&rab_ifile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zopeni $connect failed, status","",rms_sts);
return(0);
}
debug(F100,"zopeni RMS operations completed ok","",0);
fp[n] = fopen("NLA0:","r"); /* it wants a fp, give it one */
zincnt = 0; /* reset input buffer */
if (binary == XYFT_L)
do_label_send(name); /* make a file label */
return(1);
} else if (n == ZRFILE) { /* READ file */
rfile_bmode = 0;
rfile_bcount = 0;
fab_rfile = cc$rms_fab;
/* Always READ in text mode */
fab_rfile.fab$b_fac = FAB$M_BRO | FAB$M_GET;
fab_rfile.fab$l_fna = name;
fab_rfile.fab$b_fns = strlen(name);
fab_rfile.fab$l_xab = (char *)&xabdat_rfile;
rab_rfile = cc$rms_rab;
rab_rfile.rab$l_fab = &fab_rfile;
xabdat_rfile = cc$rms_xabdat;
xabdat_rfile.xab$l_nxt = (char *)&xabfhc_rfile;
xabfhc_rfile = cc$rms_xabfhc;
xabfhc_rfile.xab$l_nxt = (char *)&xabpro_rfile;
xabpro_rfile = cc$rms_xabpro;
memset(&raclbuf, 0, sizeof(raclbuf)); /* Do we need this for READ? */
xabpro_rfile.xab$l_aclsts = SS$_NORMAL; /* Oh Joy! DECnet */
xabpro_rfile.xab$l_aclbuf = (char *)&raclbuf;
xabpro_rfile.xab$w_aclsiz = sizeof(raclbuf);
xabpro_rfile.xab$l_aclctx = 0;
xabpro_rfile.xab$l_nxt = (char *)&xaball_rfile;
xaball_rfile = cc$rms_xaball;
rms_sts = sys$open(&fab_rfile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zopeni $open ZRFILE failed, status","",rms_sts);
debug(F101,"zopeni $open ZRFILE failed, stv","",
fab_rfile.fab$l_stv);
return(0);
}
#ifdef COMMENT /* who needs it */
if (!(xabpro_rfile.xab$l_aclsts & 1)) {
if (xabpro_rfile.xab$l_aclsts != SS$_ACLEMPTY) {
debug(F101,"zopeni $open ACL failed, status","",
xabpro_rfile.xab$l_aclsts);
return(0);
}
}
#endif /* COMMENT */
/* We have the file opened. See if it's fixed or undefined format... */
rflen = ((xabfhc_rfile.xab$l_ebk-1)*512)+xabfhc_rfile.xab$w_ffb;
if (fab_rfile.fab$b_rfm == FAB$C_UDF) {
debug(F100,"zopeni ZRFILE undefined file format - fail","",0);
return(0);
}
if (fab_rfile.fab$b_rfm == FAB$C_FIX) {
if ((fab_rfile.fab$b_rat & (FAB$M_FTN | FAB$M_CR | FAB$M_PRN))
== 0) {
debug(F100,"zopeni ZRFILE fixed file format - fail","",0);
return(0);
}
}
rab_rfile.rab$l_rop = 0;
rms_sts = sys$connect(&rab_rfile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zopeni $connect failed, status","",rms_sts);
return(0);
}
debug(F100,"zopeni RFILE RMS operations completed ok","",0);
fp[n] = fopen("NLA0:","r"); /* it wants a fp, give it one */
rincnt = 0; /* reset input buffer */
return(1);
}
zincnt = 0; /* Reset input buffer */
fp[n] = fopen(name,"r"); /* Real file. */
debug(F111,"zopeni", name, (int) fp[n]);
if (fp[n] == NULL) perror("zopeni");
return((fp[n] != NULL) ? 1 : 0);
}
/* Z O P E N O -- Open a new file for output. */
int
zopeno(n,name,zz,fcb)
int n; char *name; struct zattr *zz; struct filinfo *fcb; {
/*
As of Version 5A, the attribute structure and the file information
structure are included in the arglist.
*/
int x;
int fildes;
int writeover = 0;
extern int rs_len;
char p[4];
if (n != ZDFILE)
debug(F111,"zopeno",name,n);
x = chkfn(n);
if (n != ZDFILE)
debug(F101,"zopeno chkfn","",x);
if (x != 0)
return(0);
zoutcnt = 0; /* Reset output buffer */
zoutptr = zoutbuffer;
cflag = 0; /* Default to not using console */
ofile_lblproc = 0;
/* Open terminal or STDIO */
if ((n == ZCTERM) || (n == ZSTDIO)) {
fp[ZOFILE] = stdout;
cflag = 1; /* Say using console */
debug(F101,"zopeno fp[]=stdout", "", (int) fp[n]);
return(1);
}
/*
Open Debug, Transaction, Packet, Session logfile, or a Write file.
The only other possibility at this point is the output file, so we test that.
*/
#ifdef DEBUG
if (deblog) {
if (fcb)
debug(F101,"zopeno fcb disposition", "", fcb->dsp);
if (zz)
debug(F111,"zopeno zz disposition",zz->disp.val,zz->disp.len);
}
#endif /* DEBUG */
if (n != ZOFILE) {
strcpy(p,"w"); /* Assume write/create mode */
if (fcb) { /* If called with an FCB... */
if (fcb->dsp == XYFZ_A) /* Does it say Append? */
strcpy(p,"a"); /* Yes. */
}
if (n != ZSFILE)
/* was mrs = 80; 254 is max record size for EDT */
fp[n] = fopen(name, p, "rat=cr", "rfm=var", "mrs=254");
else
fp[n] = fopen(name, p, "ctx=stm", "rfm=stm");
if (fp[n] == NULL) { /* Failed */
if (n != ZDFILE)
debug(F101,"zopeno VAXCRTL failed errno","",errno);
perror(name); /* Print system error message */
} else { /* Didn't fail */
debug(F100,"zopeno VAXCRTL ok", "", 0);
}
return((fp[n] != NULL) ? 1 : 0);
}
/* Open a file to store data being RECEIVEd */
if (n == ZOFILE) {
#ifdef DEBUG
if (deblog)
switch (binary) {
case XYFT_T:
debug(F100,"zopeno receiving TEXT file","",0);
break;
case XYFT_B:
debug(F100,"zopeno receiving BINARY file","",0);
break;
case XYFT_I:
debug(F100,"zopeno receiving IMAGE file-program bug!","",0);
break;
case XYFT_L:
debug(F100,"zopeno receiving LABELED file","",0);
break;
case XYFT_U:
debug(F100,"zopeno receiving UNDEFINED file","",0);
break;
default:
debug(F101,"zopeno unknown file type","",binary);
}
#endif /* DEBUG */
ofile_bmode = binary;
ofile_dump = 0;
ofile_ffb = -1;
fab_ofile = cc$rms_fab;
fab_ofile.fab$l_fna = name;
fab_ofile.fab$b_fns = strlen(name);
fab_ofile.fab$l_fop = FAB$M_MXV;
fab_ofile.fab$b_fac = FAB$M_PUT;
/*
Note that we could actually implement a true overwrite (step on existing
file version) operation here by testing for a new XYFZ_* type as well in
the line below, and then simply not doing a RAB$M_EOF about 25 lines down
from here. We might also have to do something to reset the file allocation
so we aren't left with a large number of "leftover" blocks if the new file
is smaller than the old one.
*/
if (fcb) {
if (fcb->dsp == XYFZ_A) {
fab_ofile.fab$l_fop = FAB$M_CIF;
/*
This is for RESEND. If the output mode is APPEND and the incoming
attributes structure (zz) says "Resend", then we know this file is
being resent.
*/
if (*(zz->disp.val) == 'R' && ofile_bmode)
writeover = 1;
debug(F101,"zopeno APPENDing, writeover","",writeover);
if (writeover)
debug(F101,"zopeno RESEND, rs_len","",rs_len);
/*
So if writeover != 0, we can take rs_len to be the length of the existing
file to keep, and to write over the rest, which normally should be the final
block.
*/
}
}
if (ofile_bmode) {
fab_ofile.fab$b_fac = FAB$M_BIO;
debug(F101,"zopeno using record size","",frecl);
fab_ofile.fab$w_mrs = frecl;
if (ofile_bmode == XYFT_U)
fab_ofile.fab$b_rfm = FAB$C_UDF;
else
fab_ofile.fab$b_rfm = FAB$C_FIX;
} else {
fab_ofile.fab$b_rat = FAB$M_CR;
fab_ofile.fab$b_rfm = FAB$C_VAR;
}
fab_ofile.fab$b_shr = FAB$M_NIL;
fab_ofile.fab$l_xab = (char *)&xabdat_ofile;
rab_ofile = cc$rms_rab;
rab_ofile.rab$l_fab = &fab_ofile;
if (fcb)
if ((fcb->dsp == XYFZ_A) && (writeover == 0))
rab_ofile.rab$l_rop = RAB$M_EOF;
xabdat_ofile = cc$rms_xabdat;
xabdat_ofile.xab$l_nxt = (char *)&xabfhc_ofile;
xabfhc_ofile = cc$rms_xabfhc;
#ifndef THIS_IS_WRONG
xabfhc_ofile.xab$l_nxt = (char *)&xabpro_ofile;
xabpro_ofile = cc$rms_xabpro;
#endif /* THIS_IS_WRONG */
if (zz)
zstime(name, zz, 2); /* Set creation date from A packet */
if (ofile_bmode == XYFT_L) { /* DEFER OPEN IF LABELED <-- NOTE */
ofile_lblproc = 0; /* (Haven't processed labels yet.) */
ofile_lblopts = fcb->lblopts;
debug(F101,"zopeno lblopts","",ofile_lblopts);
debug(F100,"zopeno RMS operations deferred","",0);
} else {
rms_sts = sys$create(&fab_ofile);
if (!(rms_sts & 1)) {
vms_lasterr = rms_sts;
debug(F101,"zopeno $create failed, status","",rms_sts);
return(0);
}
rms_sts = sys$connect(&rab_ofile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zopeno $connect failed, status","",rms_sts);
return(0);
}
if (writeover == 1) { /* if resend ... */
rab_ofile.rab$l_bkt = (unsigned long) rs_len >> 9;
rms_sts = sys$space(&rab_ofile);/* space forward to last */
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
rab_ofile.rab$l_bkt = 0; /* complete block */
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zopeno $space failed, status","",rms_sts);
return(0);
}
}
debug(F100,"zopeno RMS operations completed ok","",0);
}
fp[n] = fopen("NLA0:","r"); /* CK wants a fp, give it one */
return(1);
}
}
/* Z C L O S E -- Close the given file. */
/* Returns 0 if arg out of range, 1 if successful, -1 if close failed. */
int
zclose(n) int n; {
int x = 0;
debug(F101,"zclose n","",n);
if (chkfn(n) < 1)
return(0);
/* If this is the subprocess file, close it to flush output */
if ((n == ZIFILE || (n == ZRFILE)) && (subprocess_input != 0)) {
debug(F100, "zclose calling zclosf", "", 0);
return (zclosf(n));
}
if (n == ZIFILE) { /* Input (e.g. SEND) file */
rms_sts = sys$close(&fab_ifile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zclose ZIFILE $close failed, status","",rms_sts);
return(-1);
}
debug(F100,"zclose ZIFILE RMS operations completed ok","",0);
x = fclose(fp[n]); /* Close the dummy C library file */
fp[n] = NULL; /* Mark it closed */
iflen = -1; /* Invalidate length */
return(1);
} else if (n == ZRFILE) { /* READ file */
rms_sts = sys$close(&fab_rfile); /* Close it */
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) { /* Check status */
debug(F101,"zclose ZRFILE $close failed, status","",rms_sts);
return(-1);
}
debug(F100,"zclose ZRFILE RMS operations completed ok","",0);
x = fclose(fp[n]); /* Close the dummy C-Library file */
fp[n] = NULL; /* and mark it closed */
rflen = -1; /* invalidate its length */
return(1);
}
if (n == ZOFILE) { /* Output (e.g. RECEIVE) file */
ofile_dump = 1; /* Force complete dump */
while (zoutcnt != 0) {
rms_sts = zoutdump(); /* Flush buffers to disk */
if (rms_sts != 0) {
x = fclose(fp[n]); /* Close the associated dummy file */
fp[n] = NULL; /* Mark it closed */
iflen = -1; /* Invalidate length */
return(-1);
}
}
if (ofile_bmode == XYFT_L) { /* Update revisions if labeled */
memmove(&xabrdt_ofile.xab$q_rdt, revdat, 8);
memmove(&xabrdt_ofile.xab$w_rvn, &revnum, 2);
debug(F100,"zclose ZOFILE updated labeled revision count","",0);
}
if (cflag != 1) { /* Not console */
rms_sts = sys$close(&fab_ofile); /* So close */
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zclose ZOFILE $close failed, status","",rms_sts);
return(-1);
}
x = fclose(fp[n]); /* Close the associated dummy file */
} else /* Console */
cflag = 0; /* So not console any more */
ofile_lblproc = 0; /* Done with this file's labels */
debug(F100,"zclose ZOFILE RMS operations completed ok","",0);
fp[n] = NULL; /* Mark it closed */
iflen = -1; /* Invalidate length */
return(1);
}
if ((fp[n] != stdout) && (fp[n] != stdin)) /* Other kind of file */
x = fclose(fp[n]); /* C-Libary close */
fp[n] = NULL; /* Mark it closed */
iflen = -1; /* Invalidate file length */
debug(F101,"zclose OTHER x","",x);
if (x == EOF) /* If we got a close error */
return (-1); /* fail */
else /* otherwise */
return (1); /* succeed */
}
int
get_subprc_line() {
struct iosb_struct subiosb;
unsigned int sts;
/*
* Someone complained that subprocess deletion would hang the Kermit server.
* This can be triggered by sending something silly like REMOTE HOST STOP/ID=0.
* If SUPERSAFE is defined we will check to make sure the subprocess still
* exists before every read from the mailbox. This will slow things down a bit,
* but should stop the "C-Kermit just dies" reports.
*/
#ifdef SUPERSAFE
unsigned short pid;
struct itmlstdef {
short int buflen;
short int itmcod;
char *bufaddr;
long int *retlen;
};
struct itmlstdef itmlst[] = {
4, JPI$_PID, NULL, 0,
0, 0, 0, 0
};
itmlst[0].bufaddr = (char *)&pid;
sts = sys$getjpiw(0, &sub_pid, 0, &itmlst, 0, 0, 0);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"get_subprc_line sys$getjpiw status", "", sts);
if (sts == SS$_NONEXPR)
return(-1);
#endif /* SUPERSAFE */
sts = sys$qiow(QIOW_EFN, mbx_chan, IO$_READVBLK, &subiosb, 0, 0, sub_buf,
sizeof(sub_buf), 0, 0, 0, 0);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"get_subprc_line sys$qiow status", "", sts);
if (sts != SS$_NORMAL)
return(-1);
debug(F101,"get_subprc_line sys$qiow subiosb.status", "", subiosb.status);
if (subiosb.status == SS$_ENDOFFILE)
return(-1);
if (subiosb.status != SS$_NORMAL)
return(-1);
sub_buf[subiosb.size] = '\r';
sub_buf[subiosb.size + 1] = '\n';
sub_buf[subiosb.size + 2] = '\0';
sub_count = subiosb.size + 2;
sub_ptr = sub_buf;
return(0);
}
/* Z C H I N -- Get a character from the input file. */
/* Returns -1 if EOF, 0 otherwise with character returned in argument */
int
zchin(n,c) int n, *c; {
int a = -1;
#ifdef DEBUG
if (chkfn(n) < 1) return(-1);
#endif /* DEBUG */
if (n == ZIFILE) {
if (subprocess_input) {
if (--sub_count < 0)
if (get_subprc_line()) return(-1);
a = *sub_ptr++;
} else {
a = zminchar();
}
} else if (n == ZRFILE) {
a = ((--rincnt)>=0) ? ((int)(*rinptr++) & 0377) : rinfill();
}
if (a == -1)
return(-1);
*c = (unsigned char)a;
return(0);
}
/* Z S I N L -- Read a line from a file. */
/*
Writes the line into the address provided by the caller.
n is the Kermit "channel number".
Writing terminates when newline is encountered, newline is not copied.
Writing also terminates upon EOF or if length x is exhausted.
Returns 0 on success, -1 on EOF or error.
*/
int
zsinl(n,s,x) int n, x; char *s; {
int a, z = 0;
int old;
if (chkfn(n) < 1) { /* Make sure file is open */
return(-1);
}
a = -1;
while (x--) {
old = a; /* Previous character */
if (zchin(n,&a) < 0) /* Read a character from the file */
return(-1); /* Signal EOF if problem */
a = a & 0377;
#ifdef NLCHAR
if (a == (char) NLCHAR) break; /* Single-character line terminator */
#else
if (a == '\r') {
continue;
}
if (old == '\r') {
if (a == '\n') break;
else *s++ = '\r';
}
#endif /* NLCHAR */
*s = a;
s++;
}
*s = '\0';
return(z);
}
/* Z I N F I L L -- Read a line from a file. */
/*
* (re)fill the buffered file input buffer with data. All file input
* should go through this routine, usually by calling the zminchar()
* macro (defined in ckcker.h).
*/
int
zinfill() {
char cchar;
int linelen;
if (subprocess_input) {
if (get_subprc_line()) return(-1);
/*
* The size problem should never happen. sub_buf of a size greater then
* 1k is highly unlikely to be needed.
*/
if (INBUFSIZE < SUB_BUF_SIZE) {
fprintf(stderr,"zinfill: sub_buf too large for zinbuffer");
exit(BAD_EXIT);
}
zinptr = sub_buf;
zincnt = sub_count;
} else {
if (ifile_bmode != 0) {
rab_ifile.rab$l_rop = RAB$M_BIO; /* block mode I/O */
#ifdef DYNAMIC
rab_ifile.rab$l_ubf = zinbuffer;
#else
/* NOTE: Might need "(char *)&zinbuffer" here */
rab_ifile.rab$l_ubf = &zinbuffer;
#endif /* DYNAMIC */
/*
There is a serious flaw here, namely that reading blocks rather than
records *includes* the record pad byte (NUL) when the record has an
odd length. All RMS records are stored on even-numbered byte boundaries.
Kermit-32 did it right, sigh. So we need a total rewrite to allow for
odd-length records. Hmmm.. I wonder what the impact on RESEND is...
*/
rab_ifile.rab$w_usz = 512;
rms_sts = sys$read(&rab_ifile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts == RMS$_EOF)
return(-1); /* end of file */
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zinfill $read failed, status","",rms_sts);
return(-1); /* fatal */
}
ifile_bcount++; /* Say another block read */
zincnt = 512;
zinptr = zinbuffer;
if (rab_ifile.rab$l_bkt != 0) { /* If just a file position... */
ifile_bcount = rab_ifile.rab$l_bkt; /* update block counter */
}
if (ifile_bcount == xabfhc_ifile.xab$l_ebk) {
if (ifile_bmode == 1) /* BINARY but not LABELED */
zincnt = xabfhc_ifile.xab$w_ffb;
}
if (rab_ifile.rab$l_bkt != 0) { /* If just a file position... */
return(0); /*...then done */
}
zincnt--; /* one less char in buffer */
return((int)(*zinptr++) & 0377); /* because we return the first */
}
/* if we reached this point, we want to do record IO; first initialize RAB */
if (fab_ifile.fab$b_rat & FAB$M_FTN) {
#ifdef DYNAMIC
rab_ifile.rab$l_ubf = zinbuffer+2;
#else
/* NOTE: Might need "(char *)&zinbuffer+2" here */
rab_ifile.rab$l_ubf = &zinbuffer+2;
#endif /* DYNAMIC */
rab_ifile.rab$w_usz = INBUFSIZE-4; /* space for carriage ctl */
} else {
#ifdef DYNAMIC
rab_ifile.rab$l_ubf = zinbuffer;
#else
/* NOTE: Might need "(char *)&zinbuffer" here */
rab_ifile.rab$l_ubf = &zinbuffer;
#endif
rab_ifile.rab$w_usz = INBUFSIZE-2; /* space for possible CR/LF */
}
rab_ifile.rab$l_rop = 0; /* now do the record I/O */
rms_sts = sys$get(&rab_ifile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts == RMS$_EOF)
return(-1); /* end of file */
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zinfill $get failed, status","",rms_sts);
return(-1); /* fatal */
}
/*
* Do assorted contortions with Fortran carriage control to make it formatted
* ASCII instead, since many systems don't know about Fortran format in files.
*/
if (fab_ifile.fab$b_rat & FAB$M_FTN) {
linelen = rab_ifile.rab$w_rsz;
if (linelen > 0) {
linelen --; /* sans control code */
cchar = zinbuffer[2]; /* control code */
} else { /* zero length record */
cchar = ' '; /* space to give <LF><CR> */
}
switch (cchar) {
case '\0': /* data */
zinptr = zinbuffer+3;
zincnt = linelen;
break;
case '+': /* data<CR> */
zinbuffer[linelen+3] = '\r'; /* insert return */
zinptr = zinbuffer+3;
zincnt = linelen+1; /* count it */
break;
case '$': /* <LF>data */
zinbuffer[2] = '\n'; /* insert newline */
zinptr = zinbuffer+2;
zincnt = linelen+1; /* count it */
break;
case ' ': /* <LF>data<CR> */
zinbuffer[2] = '\n'; /* insert newline */
zinbuffer[linelen+3] = '\r'; /* insert return */
zinptr = zinbuffer+2;
zincnt = linelen+2; /* count 'em */
break;
case '0': /* <LF><CR><LF>data<CR> */
zinbuffer[0] = '\n'; /* insert 1st newline */
zinbuffer[1] = '\r'; /* insert 1st return */
zinbuffer[2] = '\n'; /* insert 2nd newline */
zinbuffer[linelen+3] = '\r'; /* insert 2nd return */
zinptr = zinbuffer;
zincnt = linelen+4; /* count 'em */
break;
case '1': /* <FF>data<CR> */
zinbuffer[2] = '\f'; /* insert formfeed */
zinbuffer[linelen+3] = '\r'; /* insert return */
zinptr = zinbuffer+2;
zincnt = linelen+2; /* count 'em */
break;
default: /* <LF>data<CR> */
zinbuffer[2] = '\n'; /* insert newline */
zinbuffer[linelen+3] = '\r'; /* insert return */
zinptr = zinbuffer+2;
zincnt = linelen+2; /* count 'em */
break;
}
} else {
zincnt = rab_ifile.rab$w_rsz;
zinptr = zinbuffer; /* reset pointer */
}
/*
* Here we see if we need to insert CR/LF pairs at the record boundary. For
* the moment, we will add them if the file has "carriage return carriage
* control" when looked at by a DIRECTORY command. As of edit 036 we also do
* this for "print file carriage control" files. I'm open to comments de-
* scribing cases where this doesn't work...
*/
if (fab_ifile.fab$b_rat & (FAB$M_CR | FAB$M_PRN)) {
zinbuffer[zincnt] = '\r';
zinbuffer[zincnt + 1] = '\n';
zincnt += 2;
}
}
/*
* And finally return the record
*/
zincnt--; /* one less char in buffer */
return((int)(*zinptr++) & 0377); /* because we return the first */
}
static int
rinfill() {
char cchar;
int linelen;
if (rfile_bmode != 0) {
rab_rfile.rab$l_rop = RAB$M_BIO; /* block mode I/O */
#ifdef DYNAMIC
rab_rfile.rab$l_ubf = rinbuffer;
#else
/* NOTE: Might need "(char *)&rinbuffer" here */
rab_rfile.rab$l_ubf = &rinbuffer;
#endif /* DYNAMIC */
rab_rfile.rab$w_usz = 512;
rms_sts = sys$read(&rab_rfile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts == RMS$_EOF)
return(-1); /* end of file */
if (rms_sts != RMS$_NORMAL) {
debug(F101,"rinfill $read failed, status","",rms_sts);
return(-1); /* fatal */
}
rfile_bcount++; /* Say another block read */
rincnt = 512;
rinptr = rinbuffer;
if (rab_rfile.rab$l_bkt != 0) { /* If just a file position... */
rfile_bcount = rab_rfile.rab$l_bkt; /* update block counter */
}
if (rfile_bcount == xabfhc_rfile.xab$l_ebk) {
if (rfile_bmode == 1) /* BINARY but not LABELED */
rincnt = xabfhc_rfile.xab$w_ffb;
}
if (rab_rfile.rab$l_bkt != 0) { /* If just a file position... */
return(0); /*...then done */
}
rincnt--; /* one less char in buffer */
return((int)(*rinptr++) & 0377); /* because we return the first */
}
if (fab_rfile.fab$b_rat & FAB$M_FTN) {
#ifdef DYNAMIC
rab_rfile.rab$l_ubf = rinbuffer+2;
#else
/* NOTE: Might need "(char *)&rinbuffer" here */
rab_rfile.rab$l_ubf = &rinbuffer+2;
#endif
rab_rfile.rab$w_usz = INBUFSIZE-4; /* space for carriage ctl */
} else {
#ifdef DYNAMIC
rab_rfile.rab$l_ubf = rinbuffer;
#else
/* NOTE: Might need "(char *)&rinbuffer" here */
rab_rfile.rab$l_ubf = &rinbuffer;
#endif
rab_rfile.rab$w_usz = INBUFSIZE-2; /* space for possible CR/LF */
}
rab_rfile.rab$l_rop = 0; /* doing record I/O */
rms_sts = sys$get(&rab_rfile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts == RMS$_EOF)
return(-1); /* end of file */
if (rms_sts != RMS$_NORMAL) {
debug(F101,"rinfill $get failed, status","",rms_sts);
return(-1); /* fatal */
}
/*
* Do assorted contortions with Fortran carriage control to make it formatted
* ASCII instead, since many systems don't know about Fortran format in files.
*/
if (fab_rfile.fab$b_rat & FAB$M_FTN) {
linelen = rab_rfile.rab$w_rsz-1; /* sans control code */
cchar = rinbuffer[2]; /* control code */
switch (cchar) {
case '\0': /* data<CR> */
case '+':
rinbuffer[linelen+3] = '\r';/* insert return */
rinptr = rinbuffer+3;
rincnt = linelen+1; /* count it */
break;
case '$': /* <LF>data<CR> */
case ' ':
rinbuffer[2] = '\n'; /* insert newline */
rinbuffer[linelen+3] = '\r';/* insert return */
rinptr = rinbuffer+2;
rincnt = linelen+2; /* count 'em */
break;
case '0': /* <LF><CR><LF>data<CR> */
rinbuffer[0] = '\n'; /* insert 1st newline */
rinbuffer[1] = '\r'; /* insert 1st return */
rinbuffer[2] = '\n'; /* insert 2nd newline */
rinbuffer[linelen+3] = '\r';/* insert 2nd return */
rinptr = rinbuffer;
rincnt = linelen+4; /* count 'em */
break;
case '1': /* <FF>data<CR> */
rinbuffer[2] = '\f'; /* insert formfeed */
rinbuffer[linelen+3] = '\r';/* insert return */
rinptr = rinbuffer+2;
rincnt = linelen+2; /* count 'em */
break;
default: /* <LF>data<CR> */
rinbuffer[2] = '\n'; /* insert newline */
rinbuffer[linelen+3] = '\r';/* insert return */
rinptr = rinbuffer+2;
rincnt = linelen+2; /* count 'em */
break;
}
} else {
rincnt = rab_rfile.rab$w_rsz;
rinptr = rinbuffer; /* reset pointer */
}
/*
* Here we see if we need to insert CR/LF pairs at the record boundary. For
* the moment, we will add them if the file has "carriage return carriage
* control" when looked at by a DIRECTORY command. As of edit 036 we also do
* this for "print file carriage control" files. I'm open to comments de-
* scribing cases where this doesn't work...
*/
if (fab_rfile.fab$b_rat & (FAB$M_CR | FAB$M_PRN)) {
rinbuffer[rincnt] = '\r';
rinbuffer[rincnt + 1] = '\n';
rincnt += 2;
}
rincnt--; /* one less char in buffer */
return((int)(*rinptr++) & 0377); /* because we return the first */
}
/* Z F S E E K -- Seek to a given position with an input file */
/* Assumes block-mode I/O being used */
int
zfseek(long pos) {
long offset;
rab_ifile.rab$l_bkt = (unsigned long) pos >> 9; /* Get block number */
rab_ifile.rab$l_bkt++; /* VBN's are 1-based */
offset = (unsigned long) pos & 511; /* Get offset with block */
if (zinfill() != 0) { /* Read in the block */
rab_ifile.rab$l_bkt = 0; /* Sequentially from now on */
return(-1);
}
rab_ifile.rab$l_bkt = 0; /* Sequentially from now on */
if (offset != 0) { /* if not block boundary... */
zincnt = zincnt - offset; /* ...adjust count and pointer */
zinptr = zinptr + offset;
}
return(0);
}
/* Z S O U T -- Write a string to the given file, buffered. */
int
zsout(n,s) int n; char *s; {
#ifdef DEBUG
if (chkfn(n) < 1) return(-1);
#endif
fputs(s, fp[n]); /* Don't use fprintf here MM */
return(0);
}
/* Z S O U T L -- Write string to file, with line terminator, buffered. */
int
zsoutl(n,s) int n; char *s; {
#ifdef DEBUG
if (chkfn(n) < 1) return(-1);
#endif
fputs(s, fp[n]); /* Don't use fprintf MM */
putc('\n', fp[n]);
return(0);
}
/* Z S O U T X -- Write x characters to file, unbuffered. */
int
zsoutx(n,s,x) int n, x; char *s; {
#ifdef DEBUG
if (chkfn(n) < 1) return(-1);
#endif
return(write(fileno(fp[n]),s,x));
}
/* Z C H O U T -- Add a character to the given file. */
int
#ifdef CK_ANSIC
zchout(register int n, char c)
#else
zchout(n,c) register int n; char c;
#endif /* CK_ANSIC */
/* zchout */ {
#ifdef DEBUG
if (chkfn(n) < 1) return(-1);
#endif
if (n == ZSFILE) {
return(write(fileno(fp[n]),&c,1)); /* Use unbuffered for session log */
} else {
if (putc(c,fp[n]) == EOF) /* If true, maybe there was an error */
return(ferror(fp[n]) ? -1 : 0); /* Check to make sure */
else /* Otherwise... */
return(0); /* There was no error. */
}
}
/* Z O U T D U M P -- dump buffered output characters to file. */
/* Buffered file output, buffer dump */
/*
No, this isn't an entry in the 199x Obfuscated C programming contest, nor
did we get it at an all-night convenience store. VMS requires that stream
format files be written as records, so we have to do _lots_ of contortions
to make sure we write whole lines as records. Not pretty. - TMK
*/
int
zoutdump() {
int ocnt;
int wrote_one_line = 0;
CHAR *optr, *srcptr, *endptr;
char csave;
debug(F101,"zoutdump zoutcnt","",zoutcnt);
debug(F101,"zoutdump ofile_bmode","",ofile_bmode);
/*
Well, this could be to the console. If it is, chop it into itty-bitty parts
(the VMS CRTL can't handle a %s spec bigger than 512 bytes) and print it.
*/
if (cflag == 1) { /* If we're dumping to console */
endptr = zoutbuffer + zoutcnt;
for (optr = zoutbuffer; optr < endptr; optr += 511) {
if (optr+511 < endptr) { /* More than 511, break up */
csave = *(optr+511);
*(optr+511) = '\0';
printf("%s", optr);
*(optr+511) = csave;
} else {
*endptr = '\0'; /* Make sure null-terminated */
printf("%s", optr);
}
}
zoutcnt = 0;
zoutptr = zoutbuffer;
return(0);
}
/* Do we need to processed TYPE LABELED contortions? */
if (ofile_bmode == XYFT_L) { /* Is it labeled? */
if (ofile_lblproc == 0) { /* I've never gone this way before? */
rms_sts = do_label_recv(); /* Beyond revolving rainbow door... */
if (rms_sts == -1)
return(-1); /* Got a hard error in label proc. */
if (rms_sts == 1 && ofile_dump != 1)
return(0); /* Exit so we can fill up the buffer */
}
}
/*
* Well, we could be lucky...
*/
if (zoutcnt == 0)
return(0);
/*
* Oh well. See if doing binary - that's easy...
*/
if (ofile_bmode) {
if (zoutcnt == OBUFSIZE) {
#ifdef DYNAMIC
rab_ofile.rab$l_rbf = zoutbuffer;
#else
/* NOTE: Might need "(char *)&zoutbuffer" here */
rab_ofile.rab$l_rbf = &zoutbuffer;
#endif /* DYNAMIC */
rab_ofile.rab$w_rsz = OBUFSIZE;
if (ofile_ffb != -1 && ofile_dump == 1) {
/*
* Only do this when doing _last_ file segment.
*/
xabfhc_ofile.xab$w_ffb = ofile_ffb;
if (ofile_ffb)
rab_ofile.rab$w_rsz -= (512 - ofile_ffb);
debug(F101,"zoutdump ofile_ffb","",(int)ofile_ffb);
debug(F101,"zoutdump rab$w_rsz","",rab_ofile.rab$w_rsz);
}
rms_sts = sys$write(&rab_ofile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zoutdump $write failed, status","",rms_sts);
return(-1);
}
} else {
#ifdef DYNAMIC
rab_ofile.rab$l_rbf = zoutbuffer;
#else
/* NOTE: Might need "(char *)&zoutbuffer" here */
rab_ofile.rab$l_rbf = &zoutbuffer;
#endif
rab_ofile.rab$w_rsz = zoutcnt;
xabfhc_ofile.xab$w_ffb = (zoutcnt & 511)+1;
if (ofile_ffb != -1) {
xabfhc_ofile.xab$w_ffb = ofile_ffb;
if (ofile_ffb)
rab_ofile.rab$w_rsz -= (512 - ofile_ffb);
debug(F101,"zoutdump ofile_ffb","",(int)ofile_ffb);
debug(F101,"zoutdump rab$w_rsz","",rab_ofile.rab$w_rsz);
}
rms_sts = sys$write(&rab_ofile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zoutdump $write failed, status","",rms_sts);
return(-1);
}
}
debug(F100,"zoutdump RMS operations completed ok","",0);
zoutcnt = 0;
zoutptr = zoutbuffer;
return(0);
}
/*
* Must be ASCII. This is harder, and weirder... It's actually easier than
* it looks, but there's (unfortunately) no really easy way to _implement_
* it. (sigh, whimper, groan)
*/
srcptr = zoutbuffer; /* Points to first line in buffer */
endptr = zoutbuffer + zoutcnt; /* Points to location after last char */
zoutdump_ascii:
/* Scan through buffer until we find a CR or we run out of chars */
for (optr = srcptr; optr < endptr; optr++) if (*optr == CR) break;
/* If there are at least 2 chars left in the buffer when we stop */
/* scanning, then it is assumed the above loop terminated because */
/* it found the CR and that both the CR and LF are present in the */
/* buffer (situation normal. */
/* If there are not 2 chars left in the buffer, we have one of two */
/* cases which we treat identically: */
/* 1) If there are 0 chars left in the buffer, then the line's */
/* terminating CR LF are yet to come. So... we copy the data */
/* to the front of the buffer and exit (next time it should be */
/* there.) */
/* 2) If there is one char left in the buffer, we have the case of*/
/* a line with the CR but no LF present. So... do the same */
/* because the LF will be coming next time. */
if (optr+2 > endptr) { /* drat! ran off the end */
if (ofile_dump && (srcptr == endptr)) {
/* If the beginning and end ptrs are the same, then there the */
/* is empty. Good news, 'cause we're clsoing up. */
zoutcnt = 0; /* No looping, please. */
zoutptr = zoutbuffer;
}
else if (ofile_dump) { /* but it's cool, we're closing up */
/* Oops, we've got a line with no LF and maybe no CR. Well */
/* write it out and exit abnormally. */
rab_ofile.rab$l_rbf = srcptr;
rab_ofile.rab$w_rsz = optr-srcptr;
rms_sts = sys$put(&rab_ofile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
zoutcnt = 0;
zoutptr = zoutbuffer;
if (rms_sts != RMS$_NORMAL) {
debug(F101, "zoutdump $put failed, status","",rms_sts);
return(-1);
}
} else if (wrote_one_line) { /* it's still cool, we did one... */
zoutcnt = optr - srcptr; /* number of chars left */
if (optr < endptr) zoutcnt++; /*[jah083] including CR if present */
if (zoutcnt) memmove(zoutbuffer, srcptr, zoutcnt);
/* Move'em to front of buffer*/
zoutptr = zoutbuffer+zoutcnt;
} else { /* WRONG!!! */
/* We've got a buffer full of chars with no LF (it may or may */
/* not have a terminating CR. In either case its just plain too*/
/* long. I suppose we could check here for the optr+1 == endptr*/
/* which indicates that there was a CR but no LF so we could */
/* issue a "line barely too long", but, is it useful? */
debug(F100, "zoutdump: line too long","",0);
zoutcnt = 0; /* No looping, please. */
zoutptr = zoutbuffer;
return(-1);
}
debug(F101, "zoutdump exiting, zoutcnt","",zoutcnt);
return(0);
}
/* We now have a line that we can write, so... */
rab_ofile.rab$l_rbf = srcptr;
rab_ofile.rab$w_rsz = optr-srcptr;
rms_sts = sys$put(&rab_ofile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101, "zoutdump $put failed, status","",rms_sts);
return(-1);
}
srcptr = optr + 2; /* Account for CR, LF */
wrote_one_line = 1;
goto zoutdump_ascii;
}
/* C H K F N -- Internal function to verify file number is ok. */
/*
Returns:
-1: File number n is out of range
0: n is in range, but file is not open
1: n in range and file is open
*/
int
chkfn(n) int n; {
int x;
if (n != ZDFILE)
debug(F101,"chkfn","",n);
switch (n) {
case ZCTERM:
case ZSTDIO:
case ZIFILE:
case ZOFILE:
case ZDFILE:
case ZTFILE:
case ZPFILE:
case ZSFILE:
break;
case ZSYSFN: /* System functions */
return(0);
case ZRFILE: /* READ and WRITE files */
case ZWFILE:
case ZMFILE:
break;
default:
debug(F101,"chkfn: file number out of range","",n);
fprintf(stderr,"?File number out of range - %d\n",n);
return(-1);
}
x = (fp[n] == NULL) ? 0 : 1;
if (n != ZDFILE)
debug(F101,"chkfn return","",x);
return(x);
}
/* Z C H K I -- Check if input file exists and is readable. */
/*
Returns:
>= 0 if the file can be read (returns the size).
-1 if file doesn't exist or can't be accessed,
-2 if file exists but is not readable (e.g. a directory file).
-3 if file exists but protected against read access.
*/
/* NOTE: THIS CURRENTLY DOES NOT RETURN -2 */
long
zchki(name) char *name; {
struct stat statbuf;
int x; long y;
struct FAB fab_chki;
struct XABFHC xabfhc_chki;
long iflen = -1L;
#ifdef COMMENT /* No longer needed - fdc, July 1997 */
/* This is _really_ bad. But there's a fundamental assumption in the upper
* levels that one can call zchki() without any context to validate file-
* names, directory names, etc. which would be painful (to the other imple-
* mentations) to change. So, if we get an argument which ends in ':', '>',
* or ']', we'll return an immediate OK with a size of 0. Bad directory
* names will be caught in zchdir anyway. This has the nice side-effect that
* saying (for example) GET dir-spec will implicitly get all files in that
* directory. Not bad for a total kludge, huh? (tmk)
*/
x = strlen(name);
if (name[x-1] == ':')
return(0);
if (name[x-1] == ']')
return(0);
if (name[x-1] == '>')
return(0);
#endif /* COMMENT */
#ifdef COMMENT
/* I don't know why I ever thought this worked -- stat() returns -1 on dirs */
#ifdef __DECC /* DEC C */
#ifndef __DECC_VER /* version < 5.0 */
/*
In DECC 5.0 (?) and higher, S_ISDIR() seems to be a library function
rather than a macro (contrary to POSIX.1), and so we can't use #ifdef to
see if it is defined. On the other hand, in DEC C 5.3, the S_IFMT and
S_IFDIR definitions have been removed, so we can't always use the following
ruse. In VAXC 3.1, we also have to do it....
*/
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif /* __DECC_VER */
#else /* VAXC */
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif /* __DECC */
x = stat((char *)name,&statbuf);
debug(F111,"zchki stat",name,x);
debug(F111,"zchki S_ISDIR",name,S_ISDIR(statbuf.st_mode));
if (x > -1 && S_ISDIR(statbuf.st_mode))
return(-2);
/*
It's needed because the following RMS$blah code does not detect that
a file (such as SYS$SYSDEVICE[USER]TEMP.DIR;1) is a directory. So, for
example, when we go to send such a file, it actually sends the directory
itself. The real fix is to make the following code return -2 if it is a
directory.
*/
#else
if (isdir(name))
return(-2);
#endif /* COMMENT */
fab_chki = cc$rms_fab;
fab_chki.fab$b_fac = FAB$M_BIO;
fab_chki.fab$l_fna = name;
fab_chki.fab$b_fns = strlen(name);
fab_chki.fab$l_xab = (char *)&xabfhc_chki;
xabfhc_chki = cc$rms_xabfhc;
rms_sts = sys$open(&fab_chki);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts == RMS$_PRV) /* No privs */
return(-3);
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zchki $open failed, status","",rms_sts);
return(-1);
}
iflen = ((xabfhc_chki.xab$l_ebk-1)*512)+xabfhc_chki.xab$w_ffb;
rms_sts = sys$close(&fab_chki);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zchki $close failed, status","",rms_sts);
return(-1);
}
strcpy(nambuf,name); /* preserve name */
debug(F111,"zchki access ok:",name,(int) iflen); /* Yes */
return( (iflen > -1) ? iflen : 0 );
}
/* Z C H K O -- Check if output file can be created. */
/*
Returns -1 if write permission for the file would be denied, 0 otherwise.
*/
int
zchko(name) char *name; {
/*
This really needs to be filled in. What if it's a device or logical name?
*/
return(0); /* Always creates new version */
}
/* Z C H K S P A -- Check if there is enough space to store the file. */
/*
Call with file specification f, size n in bytes.
Returns -1 on error, 0 if not enough space, 1 if enough space.
*/
int
zchkspa(f,n) char *f; long n; {
/*
* This is complicated. The user could have specified an explicit path when
* sending the file, or could have done a CWD, or could be using the default
* directory. If not the latter, the path may not even be a disk device, as
* CWD LPA0: is perfect legal for uploading to the lineprinter. After that,
* if it's a disk, we should check the user's quota. However, the user may
* have SYSPRV, EXQUOTA, BYPASS, or maybe even GRPPRV, and it would be hard
* to properly check for all these cases. So, if the file will fit on the
* disk, we'll accept it.
*/
char *zgtdir();
struct itmlstdef {
short int buflen;
short int itmcod;
char *bufaddr;
long int *retlen;
};
static char device[64];
struct dsc$descriptor_s
dev_desc = {sizeof(device), DSC$K_DTYPE_T, DSC$K_CLASS_S,
(char *)&device};
unsigned long freeblocks, devclass, fileblocks;
long freelength, classlength;
struct itmlstdef itmlst[] =
{4,DVI$_FREEBLOCKS,0,0,4,DVI$_DEVCLASS,0,0,0,0,0,0};
int rms_sts;
/* First, figure out the device we're interested in */
strcpy(device, zgtdir()); /* Handles default or CWD */
if (strchr(f, ':')) /* If user specified path */
strncpy(device, f, 63);
debug(F110,"zchkspa target device is ",device,0);
/* Next, ask for free block count and device type (disk vs. non-disk) */
itmlst[0].bufaddr = (char *)&freeblocks;
itmlst[0].retlen = &freelength;
itmlst[1].bufaddr = (char *)&devclass;
itmlst[1].retlen = &classlength;
rms_sts = sys$getdviw(0,0,&dev_desc,&itmlst,0,0,0,0);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
debug(F101,"zchkspa $getdvi returned rms_sts","",rms_sts);
if (devclass != DC$_DISK)
return(1); /* assume space if not disk */
if (rms_sts != SS$_NORMAL)
return(1); /* assume free space if err */
debug(F101,"zchkspa $getdvi returned freeblocks","",freeblocks);
/* Pad file size if it's a text file */
if (ofile_bmode == XYFT_T)
n += (n/40) * 3;
fileblocks = n / 512 + 1; /* compute file size in blks */
/* we may want some fuzz */
if (fileblocks >= freeblocks)
return(0); /* Won't fit */
else
return(1); /* Will fit */
}
/* Z D E L E T -- Delete the named file. */
int
zdelet(name) char *name; {
return(delete(name));
}
/* Z R T O L -- Convert remote filename into local form. */
VOID
zrtol(name,name2) char *name, *name2; {
nzrtol(name,name2,1,0,CKMAXPATH);
}
/* N Z R T O L -- New zrtol handles native and standard-format pathnames */
VOID
nzrtol(name,name2,fncnv,fnrpath,max)
char *name, *name2; int fncnv, fnrpath, max;
{ /* nzrtol */
int start, sfncnv;
char *np, c;
char *ls = NULL;
static char *spcl_set = "_-$[]<>:.\";";
char tmpbuf[NAM$C_MAXRSS+2], *tmp;
char * dotp = NULL;
debug(F110,"nzrtol name",name,0);
if (!name2) return;
sfncnv = fncnv;
tmpbuf[0] = NUL;
tmpbuf[1] = NUL;
tmpbuf[2] = NUL;
start = 0;
tmp = tmpbuf+start;
{
/* Autodetection of path format */
int lb = 0, rb = 0, sl = 0, bl = 0;
char *p = name;
while (*p) {
if (*p == '[') lb++;
if (*p == ']') rb++;
if (*p == '/') sl++;
if (*p == '\\') bl++;
p++;
}
if (lb == 1 && rb == 1 && !sl) { /* VMS detected */
fncnv = 0;
debug(F100,"nzrtol VMS detected","",0);
} else if (!lb && !rb && sl > 0) { /* UNIX detected */
fncnv = 1;
debug(F100,"nzrtol UNIX detected","",0);
}
}
debug(F101,"nzrtol fncnv","",fncnv);
/* If converting pathnames, convert to VMS format */
if (fncnv) { /* Converting, so assume UNIX format */
np = name; /* Set name pointer */
*tmp++ = '['; /* Insert opening VMS bracket */
if (*np == '/') { /* It's an absolute pathname */
np++; /* Skip past leading slash */
} else { /* Relative pathname */
*tmp++ = '.'; /* Insert '.' here */
}
while (*np) { /* Convert to VMS format */
if (*np == '/') { /* Have directory separator */
*tmp = '.'; /* So use this notation in VMS */
ls = tmp; /* Remember position of last slash */
} else {
*tmp = *np;
}
np++;
tmp++;
}
*tmp = NUL;
if (ls) { /* Replace last slash by */
*ls = ']'; /* closing directory bracket */
} else { /* No slashes */
start += 2; /* So skip past opening "[." */
}
} else { /* Assume VMS format already */
#ifdef COMMENT
/* No, this would ruin any as-name the sender gave */
/* "Be conservative in what you send, liberal in what you receive" */
int flag = 0; /* Copy */
np = name; /* But strip node and device */
while (*np) {
if (*np == '[')
flag = 1;
if (flag)
*tmp++ = *np;
np++;
}
if (!flag)
#endif /* COMMENT */
strncpy(tmp,name,NAM$C_MAXRSS); /* Just copy */
}
tmpbuf[NAM$C_MAXRSS] = NUL; /* Make sure buffer is terminated */
tmp = tmpbuf + start; /* Reset pointer */
name = tmp; /* Treat new string as original arg */
debug(F110,"nzrtol tmp 1",tmp,0);
/* Now we have VMS path format in tmpbuf */
if (fnrpath == PATH_OFF) { /* RECEIVE PATHNAMES OFF */
zstrip(name,&np);
strncpy(tmpbuf,np,NAM$C_MAXRSS);
tmp = tmpbuf;
debug(F110,"nzrtol PATH_OFF",tmp,0);
} else if (fnrpath == PATH_ABS) { /* RECEIVE PATHNAMES ABSOLUTE */
/* Nothing to do */
debug(F110,"nzrtol PATH_ABS",tmp,0);
} else if (isabsolute(name)) { /* RECEIVE PATHNAMES RELATIVE */
int x;
char * bb = NULL;
x = strlen(name);
debug(F111,"nzrtol converting absolute to relative",tmp,x);
if (bb = malloc(x+x+1)) { /* Be safe */
char * b = bb;
np = name;
while (*np) {
*b++ = *np;
if (*np == '[' && *(np+1) != '.')
*b++ = '.';
np++;
}
*b = NUL;
strncpy(tmpbuf,bb,NAM$C_MAXRSS);
tmp = tmpbuf;
free(bb);
}
debug(F110,"nzrtol PATH_REL 1",tmp,0);
} else { /* Ditto */
/* Nothing to do - it's already done */
debug(F110,"nzrtol PATH_REL 2",tmp,0);
}
tmpbuf[NAM$C_MAXRSS] = NUL;
debug(F110,"nzrtol tmp 2",tmp,0);
/* But wait, there's more... */
/* Convert relative name to absolute or else zmkdir won't work */
{
char buf2[NAM$C_MAXRSS+2], *p, *b;
int n = 0, flag = 0;
np = tmp; /* Source pointer */
b = buf2; /* Where to put new name */
while (*np && n < NAM$C_MAXRSS) { /* And substitute it; */
*b++ = *np;
n++;
if (*np == '[' && *(np+1) == '.') {
p = zgtdir(); /* Get current directory */
while (*p && *p != '[') /* The part inside the brackets */
p++;
if (*p = '[') { /* Substitute it in */
p++;
while (*p && *p != ']') {
*b++ = *p++;
if (n++ >= NAM$C_MAXRSS)
break;
}
}
}
np++;
}
*b = NUL;
tmp = buf2;
debug(F110,"nzrtol tmp 3",tmp,0);
}
fncnv = sfncnv; /* Restore original value of this */
if (!fncnv) { /* Now check it; if not converting */
strncpy(name2,tmp,max); /* We're done. */
name2[max-1] = NUL; /* Make sure it's terminated */
debug(F110,"nzrtol name2",name2,0);
return;
}
/* Now convert the characters themselves */
name = tmp;
for (np = name2; c = *name; name++) {
if (islower(c))
c = toupper(c);
else if (c == '~' || c == SP)
c = '_';
else if (!isalnum(c) && !strchr(spcl_set,c))
c = '$';
*np++ = c;
}
*np = NUL; /* End of name */
{ /* Now take care of periods. */
int x;
int ndots = 0;
char * ld = NULL; /* Last dot */
char * nld = NULL; /* Next to last dot */
x = strlen(name2) - 1;
for (; x >= 0; x--) { /* Keep only the last one. */
if (name2[x] == ']' || name2[x] == ':') /* But only do this */
break; /* in the filename part */
if (name2[x] == '.') { /* Turn prior ones to underscore. */
ndots++;
if (ndots == 1)
ld = name2+x;
else if (ndots == 2)
nld = name2+x;
else if (ndots > 2)
name2[x] = '_';
}
}
/*
Finally we check to see if the final dot was really a version-number
introducer; if so, we turn it into a semicolon and keep the next-to-last
dot, otherwise we replace the next-to-last dot with an underscore. Then we
have exactly one dot in the name.
*/
if (nld && ld) { /* We have two dots left */
char *sld = ld; /* Save position of last one */
ld++; /* Point past it */
while (*ld <= '9' && *ld >= '0') /* See if only digits follow */
ld++;
if (*ld) /* No */
*nld = '_'; /* replace previous '.' by '_' */
else /* yes */
*sld = ';'; /* replace '.' by ';' */
}
}
debug(F110,"nzrtol name2 1",name2,0);
/* But wait, there's more -- each dotted segment must be <= 39 chars */
{
char buf3[NAM$C_MAXRSS+2], *p, *b;
int n = 0;
for (b = buf3, p = name2; *p; p++) {
if (*p == '.' ||
*p == '[' ||
*p == ']' ||
*p == ':' ||
*p == '<' ||
*p == '>' ||
*p == ';')
n = 0;
if (n < 39) {
*b++ = *p;
n++;
}
}
*b = '\0';
strncpy(name2,buf3,max);
name2[max-1] = NUL; /* Make sure it's terminated */
}
debug(F110,"nzrtol name2 2",name2,0);
}
/* Z L T O R -- Convert filename from local format to common form. */
VOID
zltor(name,name2) char *name, *name2; {
nzltor(name,name2,1,0,CKMAXPATH);
}
VOID
nzltor(name,name2,fncnv,fnspath,cp_len)
char *name, *name2; int fncnv, fnspath, cp_len;
/* nzltor */ {
char *cp, *pp;
int flag;
struct FAB fab;
struct NAM nam;
char expanded_name[NAM$C_MAXRSS];
char dirbuf[NAM$C_MAXRSS], *p, *q, *q2, *r, *s, *s2;
int long rms_status;
int cur_len = 0;
debug(F111,"zltor fncnv",name,fncnv);
flag = PARSE_NAME|PARSE_TYPE;
if (fnspath == PATH_REL || fnspath == PATH_ABS)
flag |= PARSE_DIRECTORY;
fab = cc$rms_fab;
fab.fab$l_nam = &nam;
fab.fab$l_fna = name;
fab.fab$b_fns = strlen(name);
fab.fab$b_dns = 6;
fab.fab$l_dna = "NONAME";
nam = cc$rms_nam;
nam.nam$l_esa = (char *)&expanded_name;
nam.nam$b_ess = sizeof(expanded_name);
if (!CHECK_ERR("%%CKERMIT-W-ZLTOR",sys$parse(&fab)))
return;
cp = name2; /* Point to result */
*cp = '\0'; /* Initialize it to empty */
if ((PARSE_NODE & flag) && nam.nam$b_node && /* DECnet node:: */
cur_len+nam.nam$b_node < cp_len) {
cur_len += nam.nam$b_node;
strncat(cp, nam.nam$l_node, (int)nam.nam$b_node);
}
if ((PARSE_DEVICE & flag) && nam.nam$b_dev && /* Device: */
cur_len+nam.nam$b_dev < cp_len) {
cur_len += nam.nam$b_dev;
strncat(cp, nam.nam$l_dev, (int)nam.nam$b_dev);
}
/* Directory Name [] */
if ((PARSE_DIRECTORY & flag) && nam.nam$b_dir &&
cur_len+nam.nam$b_dir < cp_len) {
int i; char * tmp;
q = nam.nam$l_dir; /* The directory name from RMS */
i = nam.nam$b_dir; /* Length; string not nul-terminated */
debug(F111,"zltor nam$_dir",q,i);
if (!q) q = "[]";
if (!*q) q = "[]";
if (i < 0) i = 0;
tmp = NULL;
if (i > 0) { /* Copy directory part */
if (tmp = malloc(i+1)) {
p = tmp;
for (; i > 0 ; i--)
*p++ = *q++;
*p = NUL;
}
}
q = tmp;
debug(F111,"zltor directory part",q,i);
s = zgtdir(); /* Get current directory */
debug(F110,"zltor zgtdir",s,0);
if (!s) s = "[]";
if (!*s) s = "[]";
s2 = "";
while (*s && *s != '[')
s++;
if (*s) {
s2 = s+1;
while (*s2 && *s2 != ']') s2++; /* Closing bracket */
}
if (*s2) if (!*(s2+1)) *(s2+1) = NUL;
debug(F110,"zltor current dir",s,0);
/* First change the VMS pathname to relative format if fnspath == PATH_REL */
p = dirbuf; /* Result */
*p++ = *q++; /* Copy left bracket and... */
s++; /* Point past it */
q2 = q; /* Remember this place */
if (fnspath == PATH_REL) { /* Compare this and current dir */
while (*s == *q && *s && *q && *s != ']') {
s++;
q++;
}
}
if ( (*s != ']' && *q != ']' && *q != '.') ||
(*q == ']' && *s != ']') ) { /* No match */
p-- ; /* So rewind source pointer */
} else if (*q == ']' && *s == ']') { /* Current directory */
p = dirbuf; /* So make directory part blank */
} else { /* Not current directory */
while (*q) *p++ = *q++; /* so copy the rest */
}
*p = NUL;
debug(F110,"zltor result 1",dirbuf,0);
/*
VMS directory name is now in dirbuf in either absolute or relative format.
Now change it to standard (UNIX) format if desired.
*/
p = dirbuf; /* Working pointer */
r = dirbuf; /* Result pointer */
if (dirbuf[0]) {
if (fncnv) { /* Converting directory format */
int flag = 0;
if (p[1] == '.') { /* Directory name is relative */
r += 2; /* Point past the leading dot */
p += 2;
}
while (*p) { /* Now convert the rest */
if (*p == '.' || *p == '[' || *p == ']') {
if (!flag) *p = '/';
if (*p == ']')
flag = 1;
}
p++;
}
}
}
debug(F110,"zltor result 2",r,0);
if (tmp) free(tmp);
i = strlen(r);
if (i > 0) {
strncat(cp,r,cp_len);
cur_len += i;
}
}
if ((PARSE_NAME & flag) && nam.nam$b_name &&
cur_len+nam.nam$b_name < cp_len) {
cur_len += nam.nam$b_name;
strncat(cp, nam.nam$l_name, (int)nam.nam$b_name);
}
if ((PARSE_TYPE & flag) && nam.nam$b_type &&
cur_len+nam.nam$b_type < cp_len) {
cur_len += nam.nam$b_type;
strncat(cp, nam.nam$l_type, (int)nam.nam$b_type);
}
if ((PARSE_VERSION & flag) && nam.nam$b_ver &&
cur_len+nam.nam$b_ver < cp_len) {
cur_len += nam.nam$b_ver;
strncat(cp, nam.nam$l_ver, (int)nam.nam$b_ver);
}
if (fncnv && name2[cur_len] == NUL && name2[cur_len-1] == '.')
name2[cur_len-1] = NUL;
name2[cp_len-1] = NUL;
debug(F111,"zltor result",name2,cur_len);
}
/* C V T D I R -- Convert directory name from [FOO]BAR.DIR;1 to [FOO.BAR] */
/*
Call with:
s = pointer to a string that has already been verified as a directory name
q = pointer to where to put result
Returns:
1 on success
0 if no conversion was needed
-1 on failure
*/
int
cvtdir(s,s2) char * s, * s2; {
int i, n;
char dirbuf[NAM$C_MAXRSS+1];
char * p = NULL; /* Pointer to period */
char * o = NULL; /* Pointer to left bracket */
char * r = NULL; /* Pointer to right bracket */
char * v = NULL; /* Pointer to version */
char * c = NULL; /* Pointer to colon */
char * q = NULL;
char * t;
debug(F110,"cvtdir",s,0);
if (!s || !s2)
return(-1);
n = strlen(s);
if (n < 1)
return(-1);
q = malloc(n+1);
if (!q)
return(-1);
t = q;
while (*s) {
*q++ = islower(*s) ? toupper(*s) : *s;
s++;
}
*q = NUL;
s = t;
debug(F111,"cvtdir 2",s,n);
for (i = n; i > 0; i--) {
if (s[i] == ';')
v = s+i;
else if (s[i] == '.')
p = s+i;
else if (s[i] == ':')
c = s+i;
else if (s[i] == ']' || s[i] == '>')
r = s+i;
else if (s[i] == '[' || s[i] == '<')
o = s+i;
}
debug(F110,"cvtdir c",c,0);
debug(F110,"cvtdir r",r,0);
debug(F110,"cvtdir o",o,0);
debug(F110,"cvtdir p",p,0);
debug(F110,"cvtdir v",v,0);
dirbuf[0] = NUL;
if (c) { /* Have colon? */
*c = NUL;
strcat(dirbuf,s);
strcat(dirbuf,":");
s = c+1;
}
debug(F110,"cvtdir 3",dirbuf,0);
if (o) { /* Have opening bracket? */
if (r) {
*r = NUL;
s = r+1;
strcat(dirbuf,"[");
strcat(dirbuf,o+1);
} else
return(-1);
} else
strcat(dirbuf,"[");
debug(F110,"cvtdir 4",dirbuf,0);
if (p) {
if (*(p+1) == 'D' &&
*(p+2) == 'I' &&
*(p+3) == 'R' &&
(*(p+4) == ';' || *(p+4) == '.' || *(p+4) == NUL))
*p = NUL;
else
return(-1);
strcat(dirbuf,".");
strcat(dirbuf,s);
}
strcat(dirbuf,"]");
debug(F110,"cvtdir 5",dirbuf,0);
strcpy(s2,dirbuf);
return(1);
#ifdef COMMENT
if (r && p && v) {
if (*(p+1) == 'D' &&
*(p+2) == 'I' &&
*(p+3) == 'R' &&
*(p+4) == ';') {
*r = NUL;
strcpy(q,s);
strcat(q,".");
*p = NUL;
strcat(q,p);
strcat(q,"]");
}
debug(F110,"cvtdir result",q,0);
return(1);
}
return(0);
#endif /* COMMENT */
}
/* Z C H D I R -- Change directory. */
static int setddir = 0;
/*
This one is for restoring the startup directory in case SYS$SETDDIR() was
ever called -- see comments below in zchdir().
*/
VOID
zrestoredir() {
int status;
struct dsc$descriptor_s indesc;
if (!setddir)
return;
debug(F101,"zrestoredir setddir","",setddir);
indesc.dsc$w_length = (int) strlen((char *)startupdir);
indesc.dsc$a_pointer = (char *)startupdir;
indesc.dsc$b_class = DSC$K_CLASS_S;
indesc.dsc$b_dtype = DSC$K_DTYPE_T;
status = sys$setddir(&indesc, 0, 0);
if (!(status & 1)) vms_lasterr = status;
debug(F111,"zrestoredir sys$setddir",startupdir,status);
return;
}
int
zchdir(dirnam) char *dirnam; {
char dirbuf[NAM$C_MAXRSS+1];
int status;
struct dsc$descriptor_s indesc;
if (!dirnam) /* Watch out for null pointers */
dirnam = "";
debug(F110,"zchdir",dirnam,0);
if (!*dirnam) { /* No arg so back to home directory */
#ifdef COMMENT
strcpy(dirbuf,getenv("HOME"));
dirnam = (char *) dirbuf;
debug(F110,"zchdir home","",0);
if (!isdir(dirnam))
return(0);
#else
dirnam = "SYS$LOGIN"; /* Supply default */
#endif /* COMMENT */
}
#ifdef COMMENT /* Why is this commented out? */
/* We now assume that dirnam is a valid directory name */
status = isdir(dirnam); /* Preverify to prevent C lib traps */
debug(F111,"zchdir isdir 1",dirnam,status);
x = strlen(dirnam);
if (!status) { /* Not a directory */
if (dirnam[0] == '[')
return(0);
if (x > 0 && (dirnam[x-1] == ']' || dirnam[x-1] == ':'))
return(0);
if (*dirnam == '.') /* Be nice - is it a subdirectory */
sprintf(dirbuf,"[%s]",dirnam); /* of the current directory? */
else
sprintf(dirbuf,"[.%s]",dirnam);
status = isdir(dirbuf);
debug(F111,"zchdir isdir 2",dirnam,status);
if (!status)
return(0); /* Nope */
dirnam = dirbuf; /* Ayup */
} /* ( We should really save "ayup" comments for the Maine program :-) */
if (status == 2) { /* It's [FOO]BAR.DIR;1 */
/* Must convert to [FOO.BAR] */
debug(F111,"zchdir malloc",dirnam,x);
if (cvtdir(dirnam,(char *)dirbuf) > 0) {
debug(F110,"zchdir cvtdir",dirbuf,0);
dirnam = dirbuf;
}
}
#endif /* COMMENT */
/*
chdir() works as expected, when it works. It only affects this process
and those below it, and it handles search lists, hidden devices, etc.
EXCEPT in VMS 6.2, in which a bug was introduced in the C runtime library.
So we try chdir() first...
*/
debug(F110,"zchdir chdir",dirnam,0);
status = chdir(dirnam);
debug(F101,"zchdir status","",status);
/*
chdir() fails in VMS 6.2 when given a logical name like SYS$LOGIN that
refers to a search list (e.g. for the SYSMGR ID on a cluster) or to a
hidden device. In this case SYS$SETDDIR works, but it has the unfortunate
side effect of changing the default directory for the whole job, not just
C-Kermit and below.
*/
if (status == 0) { /* chdir() worked */
return(1);
} else { /* chdir() failed */
indesc.dsc$w_length = (int) strlen(dirnam);
indesc.dsc$a_pointer = dirnam;
indesc.dsc$b_class = DSC$K_CLASS_S;
indesc.dsc$b_dtype = DSC$K_DTYPE_T;
status = sys$setddir(&indesc, 0, 0);
if (!(status & 1)) vms_lasterr = status;
debug(F111,"zchdir sys$setddir",dirnam,status);
if (status == RMS$_NORMAL) {
setddir = 1; /* Set this if setddir() ever used */
return(1);
} else
return(0);
}
}
/* Z H O M E -- Return pointer to user's home (login) directory. */
char *
zhome() {
/* return(getenv("HOME")); */ /* No... */
/* return(getenv("SYS$LOGIN")); */ /* No... */
/* return("SYS$LOGIN"); */ /* Maybe - but we need a terminator */
return("SYS$LOGIN:");
}
/* Z G T D I R -- Return pointer to user's current directory. */
char *
zgtdir() {
/* OLD_VMS (pre V5.0) is defined in the build file */
#ifdef OLD_VMS
static char *gtdir_buf = 0;
static char sysdisk[] = "SYS$DISK";
char tmp_buf[NAM$C_MAXRSS+1];
struct dsc$descriptor_s
tmp_buf_dsc = {sizeof(tmp_buf),DSC$K_DTYPE_T,DSC$K_CLASS_S,&tmp_buf},
sysdisk_dsc = {sizeof(sysdisk)-1,DSC$K_DTYPE_T,DSC$K_CLASS_S,&sysdisk};
unsigned short int buf_len;
/*
* Allocate buffer dynamically, first time through. This makes the image
* smaller.
*/
if (!gtdir_buf) gtdir_buf = malloc(NAM$C_MAXRSS+1);
/*
* Translate device name.
*/
lib$sys_trnlog( &sysdisk_dsc,
&buf_len,
&tmp_buf_dsc,
0,
0,
0);
tmp_buf[buf_len] = '\0';
strcpy(gtdir_buf,tmp_buf);
/*
* Get directory name.
*/
sys$setddir( 0, /* New dir addr */
&buf_len, /* length addr */
&tmp_buf_dsc);
tmp_buf[buf_len] = '\0';
strcat(gtdir_buf,tmp_buf);
return(gtdir_buf); /* Can't seem to make LINK find getcwd()... */
/* (wbader: removed &) */
#else
char *getcwd();
char *buf;
buf = cwdbuf;
return(getcwd(buf,100));
#endif
}
/* Z G P I D -- Get process ID (of Kermit) */
long
zgpid() {
unsigned long sts, pid;
struct itmlstdef {
short int buflen;
short int itmcod;
char *bufaddr;
long int *retlen;
};
/* Should maybe this be JPI$_PROC_INDEX instead? */
struct itmlstdef itmlst[] = {
4, JPI$_PID, NULL, 0,
0, 0, 0, 0
};
itmlst[0].bufaddr = (char *)&pid;
sts = sys$getjpiw(0, 0, 0, &itmlst, 0, 0, 0);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"zgpid sys$getjpiw status", "", sts);
if (sts != SS$_NORMAL)
return(0);
else
return(pid);
}
/* Z X C M D -- Run a system command so its output can be read as a file. */
int
zxcmd(filnum, comand) int filnum; char *comand; {
char mbxnam[21], inpchan[6] = "NLA0:";
unsigned long sts, pid;
int one=1;
struct dsc$descriptor_s
mbx_desc = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0},
cmd_line = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0},
inp_desc = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
struct itmlstdef {
short int buflen;
short int itmcod;
char *bufaddr;
long int *retlen;
};
struct itmlstdef itmlst[] = {
4, JPI$_PID, NULL, 0,
0, 0, 0, 0
};
itmlst[0].bufaddr = (char *)&pid;
debug(F101,"zxcmd filnum", "", filnum);
if (filnum != ZIFILE && filnum != ZRFILE)
return(0);
sts = sys$getjpiw(0, 0, 0, &itmlst, 0, 0, 0);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"zxcmd sys$getjpiw status", "", sts);
if (sts != SS$_NORMAL)
return(0);
sprintf(mbxnam,"KERMIT$MBX_%08X", pid);
debug(F110,"zxcmd mailbox logical", mbxnam, 0);
mbx_desc.dsc$w_length = strlen(mbxnam);
mbx_desc.dsc$a_pointer = mbxnam;
sts = sys$crembx(0, &mbx_chan, SUB_BUF_SIZE, 0, 0, 0, &mbx_desc, 0);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"zxcmd sys$crembx status", "", sts);
if (sts != SS$_NORMAL)
return(0);
debug(F101,"zxcmd sys$crembx mbx_chan", "", mbx_chan);
strcat(mbxnam, ":");
mbx_desc.dsc$w_length++;
cmd_line.dsc$w_length = strlen(comand);
cmd_line.dsc$a_pointer = comand;
inp_desc.dsc$w_length = strlen(inpchan);
inp_desc.dsc$a_pointer = inpchan;
sts = lib$spawn(&cmd_line, &inp_desc, &mbx_desc, &one, 0, &sub_pid,
&pexitlong, 0, 0, &mbx_chan);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"zxcmd lib$spawn status", "", sts);
if (sts != SS$_NORMAL)
return(0);
subprocess_input = 1;
sub_count = 0;
fp[filnum] = fopen("NLA0:","r"); /* It wants a fp, give it one */
debug(F101,"zxcmd fp[filnum]", "", fp[filnum]);
fp[ZSYSFN] = fp[filnum]; /* Set ZSYSFN too, so we remember */
return(1);
}
/* Z C L O S F - close the suprocess output file. */
int
zclosf(filnum) int filnum; {
unsigned long sts;
if (subprocess_input != 0) {
sts = sys$delprc(&sub_pid, 0);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"zclosf sys$delprc status", "", sts);
sts = sys$delmbx(mbx_chan);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"zclosf sys$delmbx status", "", sts);
sts = sys$dassgn(mbx_chan);
if (!(sts & 1)) vms_lasterr = sts;
debug(F101,"zclosf sys$dassgn status", "", sts);
sub_ptr = sub_buf; /* flush remaining data */
sub_count = 1;
*sub_buf = '\0';
zincnt = 0;
fclose(fp[filnum]); /* Close the place-holders */
fp[filnum] = fp[ZSYSFN] = NULL;
}
debug(F101,"zxcmd pexitlong","",pexitlong);
subprocess_input = 0; /* Say we're done */
pexitstat = (pexitlong & 0x7fff); /* Set status */
return(pexitstat & 1 ? 1 : -1);
}
/* Z X P A N D -- Expand a wildcard string into an array of strings. */
/*
Returns the number of files that match s, with data structures set up
so that first file (if any) will be returned by the next znext() call.
*/
int
zxpand(s) char * s; {
int x;
if (!s) s = "";
x = strlen(s);
debug(F111,"zxpand",s,x);
if (x <= 0) /* Nothing asked for, */
return(0); /* nothing returned. */
fcount = (mtchs == NULL && /* Kermit */
(mtchs = (char **)malloc(MAXWLD * sizeof(*mtchs))) == NULL)
? 0
: fgen(s,mtchs,MAXWLD); /* Look up the file. */
if (fcount > 0) {
mtchptr = mtchs; /* Save pointer for next. */
debug(F111,"zxpand fcount",mtchs[0],fcount);
}
return(fcount);
}
/* Z N E X T -- Get name of next file from list created by zxpand(). */
/*
Returns >0 if there's another file, with its name copied into the arg string,
or 0 if no more files in list.
*/
int
znext(fn) char *fn; {
if (fcount-- > 0) strcpy(fn,*mtchptr++);
else *fn = '\0';
debug(F111,"znext",fn,fcount+1);
return(fcount+1);
}
/* Z N E W N -- Make a new name for the given file. */
VOID
znewn(fn,s) char *fn, **s; {
static char buf[NAM$C_MAXRSS+8];
int x, flag = 0;
long v = -1L;
x = strlen(fn) - 1;
strncpy(buf, fn, NAM$C_MAXRSS);
while (x >= 0) {
if (buf[x] == ';') {
v = atol(buf+x+1);
sprintf(buf+x+1,"%ld",v+1);
flag = 1;
break;
}
x--;
}
if (!flag) strcat(buf,";0");
*s = buf;
}
struct zfnfp *
zfnqfp(fname, buflen, buf) char * fname; int buflen; char * buf; {
int x = 0, y = 0;
char * cp;
static struct zfnfp fnfp;
struct FAB fab;
struct NAM nam;
char expanded_name[NAM$C_MAXRSS];
int long rms_status;
int cur_len = 0;
int cp_len = buflen;
if (!fname)
return(NULL);
/* initialize the data structure */
cp = fname;
debug(F111,"zfnqfp 1",cp,buflen);
fnfp.len = buflen;
fnfp.fpath = buf;
fnfp.fname = NULL;
fab = cc$rms_fab;
fab.fab$l_nam = &nam;
fab.fab$l_fna = cp;
fab.fab$b_fns = strlen(cp);
fab.fab$l_dna = 0;
nam = cc$rms_nam;
nam.nam$l_esa = (char *)&expanded_name;
nam.nam$b_ess = sizeof(expanded_name);
if (!CHECK_ERR("%%CKERMIT-W-ZFNQFP",
sys$parse(&fab)))
return((struct zfnfp *)-1);
cp = buf;
*cp = '\0'; /* Make a zero length string */
fnfp.fpath = cp;
if (nam.nam$b_node && cur_len+nam.nam$b_node < cp_len) {
cur_len += nam.nam$b_node;
strncat(cp, nam.nam$l_node, (int)nam.nam$b_node);
}
if (nam.nam$b_dev && cur_len+nam.nam$b_dev < cp_len) {
cur_len += nam.nam$b_dev;
strncat(cp, nam.nam$l_dev, (int)nam.nam$b_dev);
}
if (nam.nam$b_dir && cur_len+nam.nam$b_dir < cp_len) {
cur_len += nam.nam$b_dir;
strncat(cp, nam.nam$l_dir, (int)nam.nam$b_dir);
}
if (nam.nam$b_name && cur_len+nam.nam$b_name < cp_len) {
fnfp.fname = buf + cur_len; /* Got it, set pointer */
cur_len += nam.nam$b_name;
strncat(cp, nam.nam$l_name, (int)nam.nam$b_name);
}
if (nam.nam$b_type && cur_len+nam.nam$b_type < cp_len) {
cur_len += nam.nam$b_type;
strncat(cp, nam.nam$l_type, (int)nam.nam$b_type);
}
if (nam.nam$b_ver && cur_len+nam.nam$b_ver < cp_len) {
cur_len += nam.nam$b_ver;
strncat(cp, nam.nam$l_ver, (int)nam.nam$b_ver);
}
debug(F111,"zfnqfp 2",buf,cur_len);
if (cur_len > 1) {
if (buf[cur_len-1] == ';' && buf[cur_len-2] == '.') {
buf[cur_len-2] = NUL;
cur_len -= 2;
}
}
debug(F111,"zfnqfp 3",buf,cur_len);
return(&fnfp);
}
/*
* fgen:
* This is the actual name generator. It is passed a string,
* possibly containing wildcards, and an array of character pointers.
* It finds all the matching filenames and stores them into the array.
* The returned strings are allocated from a static buffer local to
* this module (so the caller doesn't have to worry about deallocating
* them); this means that successive calls to fgen will wipe out
* the results of previous calls. This isn't a problem here
* because we process one wildcard string at a time.
*
* Input: a wildcard string, an array to write names to, the
* length of the array.
* Returns: the number of matches. The array is filled with filenames
* that matched the pattern. If there wasn't enough room in the
* array, -1 is returned.
*/
static int lastcount = 0;
static int mtchsinit = 0;
int
fgen(pat,resarry,len) char *pat, *resarry[]; int len; {
char * p, * f;
int i, x, y;
struct dsc$descriptor_s
file_spec = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0},
result = {0,DSC$K_DTYPE_T,DSC$K_CLASS_D,0},
deflt = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
unsigned long context = 0, status;
int count = 0;
char *def_str = "*.*";
extern int dironly, fileonly;
char dirbuf[NAM$C_MAXRSS+1];
char tmpbuf[NAM$C_MAXRSS+1];
debug(F101,"fgen len","",len);
if (!mtchsinit) { /* Initialize filename array */
mtchsinit = 1;
for (i = 0; i < MAXWLD; i++)
mtchs[i] = NULL;
} else {
for (i = 0; i < lastcount; i++) { /* Free previous filenames */
if (resarry[i]) {
free(resarry[i]);
resarry[i] = NULL;
}
}
}
debug(F110,"fgen pat",pat,0);
debug(F101,"fgen dironly","",dironly);
file_spec.dsc$w_length = strlen(pat);
file_spec.dsc$a_pointer = pat;
deflt.dsc$w_length = sizeof(def_str)-1;
deflt.dsc$a_pointer = def_str;
while (count < len
&& (status = lib$find_file(&file_spec, &result, &context, &deflt))
== RMS$_NORMAL) {
if (!(status & 1)) vms_lasterr = status;
f = tmpbuf;
strncpy(f, result.dsc$a_pointer, result.dsc$w_length);
tmpbuf[result.dsc$w_length] = '\0';
x = isdir(tmpbuf);
debug(F111,"fgen isdir",f,x);
if (x != 0 && fileonly) /* Want files only and not a file */
continue;
if (x == 0 && dironly) /* Want dirs only but not a dir */
continue;
if (dironly) {
if (x == 2) {
y = cvtdir(tmpbuf, (char *)dirbuf);
if (y > 0) f = dirbuf;
}
}
resarry[count] = malloc((int) strlen(f) + 1);
if (resarry[count]) {
strcpy(resarry[count], f);
count++;
lastcount = count;
} else {
debug(F100,"fgen malloc failure","",0);
return(-1);
}
}
#ifdef DVI$_ALT_HOST_TYPE
lib$find_file_end(&context); /* Only on VMS V4 and later */
#endif /* DVI$_ALT_HOST_TYPE */
lib$sfree1_dd(&result);
if (status == RMS$_FNF) /* File Not Found */
return((count <= len) ? 0 : -1);
if (status == RMS$_NMF) /* No More Found */
return(count);
/* Bernd Onasch says that VMS sometimes returns RMS$_NORMAL here, so... */
if (status == RMS$_NORMAL)
return(count);
/* Some other status. Return 0. */
/* Improve this later based on results from following debug stmt. */
debug(F101,"fgen unexpected failure status","",status);
return(0);
}
/* Z R E N A M E -- Rename a file. */
/* Call with old and new names */
/* Returns 0 on success, -1 on failure. */
int
zrename(old,new) char *old, *new; {
int sts;
sts = rename(old,new);
return((sts ? -1 : 0));
}
/* Z C F D A T -- Return a file's modification time. */
char *
zfcdat(name) char *name; {
/*
Returns modification date/time of file whose name is given in the argument
string. Return value is a pointer to a string of the form:
yyyymmdd hh:mm:ss
for example 19931231 23:59:59, which represents the local time (no timezone
or daylight savings time finagling required). Returns an empty string ("")
on failure. The text pointed to by the string pointer is in a static
buffer, and so should be copied to a safe place by the caller before any
subsequent calls to this function.
*/
/*
Contributed by William Bader, 9 Nov 93, based on UNIX version: "It would
probably be possible to get the date by opening the file and requesting a
NAM block like ckvfio.c does, but stat seems to do the trick."
*/
struct stat statbuf;
struct tm *tm;
static char datebuf[20];
datebuf[0] = '\0';
if (name &&
*name &&
stat(name,&statbuf) != -1 &&
(tm = localtime((const time_t *)&statbuf.st_mtime)))
sprintf(datebuf, "%04d%02d%02d %02d:%02d:%02d",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
return(datebuf);
}
/* Z S T I M E -- Set or compare a file's creation date/time. */
/*
* Note: There's an additional value for parameter X on VAX/VMS systems. As
* it's horribly painful to change a file's creation date after-the-fact we
* call zstime with an argument of 2 to pre-set the date when creating the
* file. An argument of 0 (which the main-line code thinks sets the date of
* the output file) returns success but does nothing. Note that an invalid
* or missing attribute packet will cause $bintim to return an error, which
* causes the routine to exit. Since we pre-set the binary time to zero, we
* will create the file "now", or say the incoming file is newer, whichever
* is appropriate.
*/
int
zstime(f,yy,x) char *f; struct zattr *yy; int x; {
int rms_sts;
unsigned short attr_pro = 0;
static char mth[13][4] = { "JAN","FEB","MAR","APR",
"MAY","JUN","JUL","AUG",
"SEP","OCT","NOV","DEC",
""};
static char cdate[23]; /* Creation date yyyymmdd hh:mm:ss.00 */
static char mnum[2];
struct dsc$descriptor_s
bintim_desc = {sizeof(cdate) - 1, DSC$K_DTYPE_T, DSC$K_CLASS_S,
(char *)&cdate};
unsigned long file_date[2], attr_date[2];
char *dptr;
int setperms = 0;
int setdate = 0;
#ifdef DEBUG
char xbuf[24]; /* Hex buffer for debugging only */
#endif /* DEBUG */
debug(F111,"zstime entry",f,x);
if (yy->date.len == 0) { /* No date in struct */
if (yy->lprotect.len != 0) { /* So go do permissions */
goto zsperms;
} else {
debug(F100,"zstime: nothing to do","",0);
return(0);
}
}
/* First, make a system quadword date from our attribute struct parameter */
dptr = yy->date.val;
strcpy(cdate,"dd-mmm-yyyy 00:00:00.00");
attr_date[0]=0; /* Clear time in case of error */
attr_date[1]=0;
strncpy(cdate+7, dptr, 4); /* yyyy */
dptr += 4;
strncpy(mnum, dptr, 2);
strncpy(cdate+3, mth[atoi(mnum)-1], 3); /* mm */
dptr += 2;
strncpy(cdate, dptr, 2); /* dd */
dptr += 3;
strncpy(cdate+12, dptr, 8); /* hhmmss */
cdate[23] = '\0'; /* terminate */
rms_sts = sys$bintim(&bintim_desc, &attr_date); /* Convert to internal */
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != SS$_NORMAL) { /* time format */
debug(F111,"zstime - $bintim returns",cdate,rms_sts);
return(-1);
}
debug(F110,"zstime built",cdate,0);
sprintf(cdate, "%08X%08X", attr_date[1], attr_date[0]);
debug(F110,"zstime $bintim attr_date", cdate, 0);
setdate = 1;
zsperms: /* File protection */
if (x != 1) { /* We're not just comparing dates... */
int i, xx, flag = 0;
char * s;
#ifdef DEBUG
if (deblog) {
debug(F111,"zstime lperms",yy->lprotect.val,yy->lprotect.len);
debug(F111,"zstime gperms",yy->gprotect.val,yy->gprotect.len);
debug(F110,"zstime system id",yy->systemid.val,0);
sprintf(xbuf,"%X",xabpro_ofile.xab$w_pro);
debug(F110,"zstime xabpro_ofile.xab$w_pro 1",xbuf,0);
}
#endif /* DEBUG */
if ((yy->lprotect.len > 0 && /* Have sys-dependent permissions */
yy->systemid.len > 0 && /* from A-packet... */
!strcmp(yy->systemid.val,"D7"))) { /* AND you are VMS like me */
attr_pro = 0;
flag = 1;
s = yy->lprotect.val; /* VMS protections */
xx = yy->lprotect.len;
if (xx < 0) /* Length < 0 means inheritance */
xx = 0 - xx; /* (ignored in VMS) */
if (xx > 4) { /* Bad format - must be 4 bytes */
flag = 0;
} else {
for (i = 0; i < xx; i++) { /* Decode hex string */
if (*s <= '9' && *s >= '0') {
attr_pro = 16 * attr_pro + (int)(*s) - '0';
} else if ((*s <= 'F' && *s >= 'A')) {
attr_pro = 16 * attr_pro + 10 + (int)(*s) - 'A';
} else if ((*s <= 'f' && *s >= 'a')) {
attr_pro = 16 * attr_pro + 10 + (int)(*s) - 'a';
} else {
flag = 0;
break;
}
s++;
}
}
#ifdef DEBUG
if (deblog) {
debug(F101,"zstime VMS local protection flag","",flag);
sprintf(xbuf,"%X",attr_pro);
debug(F111,"zstime VMS local protection",xbuf,attr_pro);
}
#endif /* DEBUG */
} else if (!flag && yy->gprotect.len > 0) { /* Systems differ */
int g; /* Use the generic one */
unsigned long dfpro = 0L, mask = 0L;
unsigned short tmp;
tmp = xabpro_ofile.xab$w_pro;
rms_sts = sys$setdfprot(0,&dfpro); /* Get default protection */
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
#ifdef DEBUG
if (deblog) {
sprintf(xbuf,"%X",dfpro);
debug(F111,"zstime sys$setdfprot",xbuf,rms_sts);
}
#endif /* DEBUG */
if (rms_sts & 1) /* Succeeded so use it */
tmp = dfpro;
tmp &= 0xff0f; /* But remove Owner field */
/* Convert generic protection to number and translate to internal VMS form */
g = xunchar(*(yy->gprotect.val));
attr_pro = 0x0F; /* 1111 Initial value = No access */
if (g & 1) /* 1=Read */
attr_pro &= ~XAB$M_NOREAD; /* 0001 */
if (g & 2) /* 2=Write */
attr_pro &= ~XAB$M_NOWRITE; /* 0010 */
if (g & 4) /* 4=Execute */
attr_pro &= ~XAB$M_NOEXE; /* 0100 */
if (g & 8) /* 8=Append */
attr_pro &= ~XAB$M_NOWRITE; /* 0010 */
if (g & 16) /* 16=Delete */
attr_pro &= ~XAB$M_NODEL; /* 1000 */
mask = attr_pro | /* Don't give S,G,W any */
(attr_pro << 4) | /* more access than Owner... */
(attr_pro << 8) |
(attr_pro << 12);
attr_pro = attr_pro << 4; /* Shift to owner field */
tmp |= attr_pro; /* OR in Owner protection */
attr_pro = tmp | mask; /* Mask off any higher permissions */
flag = 1; /* Flag we have the protection value */
#ifdef DEBUG
if (deblog) {
debug(F101,"zstime g attr_pro 4","",attr_pro);
sprintf(xbuf,"%X",attr_pro);
debug(F111,"zstime generic protections",xbuf,attr_pro);
}
#endif /* DEBUG */
}
if (flag)
setperms = 1;
}
debug(F101,"zstime setperms","",setperms);
debug(F101,"zstime setdate","",setdate);
switch (x) {
case 1: /* Function code 1, compare dates */
if (!setdate) /* Do we have a date? */
return(-1); /* Nothing to do */
fab_ifile = cc$rms_fab;
fab_ifile.fab$b_fac = FAB$M_BIO | FAB$M_GET;
fab_ifile.fab$l_fna = f;
fab_ifile.fab$b_fns = strlen(f);
fab_ifile.fab$l_xab = (char *)&xabdat_ifile;
rab_ifile = cc$rms_rab;
rab_ifile.rab$l_fab = &fab_ifile;
xabdat_ifile = cc$rms_xabdat;
rms_sts = sys$open(&fab_ifile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zstime $open failed, status","",rms_sts);
return(-1);
}
memcpy(file_date, &xabdat_ifile.xab$q_cdt, 8);
sprintf(cdate, "%08x%08x", file_date[1], file_date[0]);
debug(F110,"zstime $bintim file_date", cdate, 0);
rms_sts = sys$close(&fab_ifile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (rms_sts != RMS$_NORMAL) {
debug(F101,"zstime $close failed, status","",rms_sts);
return(-1);
}
if (attr_date[1] < file_date[1]) {
debug(F100,"zstime incoming file is older","",0);
return(1);
}
if (attr_date[1] == file_date[1]) {
if (attr_date[0] <= file_date[0]) {
debug(F100,"zstime incoming file is older, not by much","",0);
return(1);
}
debug(F100,"zstime incoming file is newer","",0);
return(0);
}
break;
case 0: /* Function code 0, set attributes */
return(0); /* Say we did (see comments above) */
case 2: /* Function code 2, really set them */
if (setdate) { /* Do we have a date? */
debug(F100,"zstime setting date","",0);
memcpy(&xabdat_ofile.xab$q_cdt, attr_date, 8); /* File date */
}
if (setperms) { /* File protection... */
debug(F100,"zstime setting protection","",0);
xabpro_ofile.xab$w_pro = attr_pro;
}
return(0);
}
return(-1);
}
/* Z K E R M I N I -- Find initialization file. */
/*
Places name of init file in buffer pointed to by s.
If no init file found, the device name of the null device is used.
returns 0 always.
*/
int
zkermini(s, s_len, def) char *s; int s_len; char *def; {
FILE fd;
struct dsc$descriptor_s
dsc_in = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0},
dsc_out = {0,DSC$K_DTYPE_T,DSC$K_CLASS_D,0},
dsc_def = {0,DSC$K_DTYPE_T,DSC$K_CLASS_S,0};
int max_len;
long unsigned int rms_s;
unsigned long find_file_context = 0;
struct TRNLIST {
char *name; /* ASCII file or logical name */
unsigned char flag; /* Zero to use default filename */
} *p;
static struct TRNLIST slist[] = {
{"", 0}, /* Dummy first entry points to file */
{"ckermit_ini:", 0}, /* CKERMIT_INI: points to directory */
{"ckermit_init", 1}, /* CKERMIT_INIT points to file */
{"sys$login:", 0}, /* CKERMIT.INI in login directory */
{"", 0}
};
p = slist; /* Point to list */
if (rcflag) { /* Name given on command line? */
slist[0].name = def; /* Yes, stuff its name into slist */
slist[1].name = "";
} else { /* No, */
*p++; /* skip past dummy entry. */
}
while(*(p->name)) { /* Search the list top to bottom */
dsc_in.dsc$w_length = strlen(p->name); /* Length of work area */
dsc_in.dsc$a_pointer = p->name; /* Address of string */
if (!(p->flag)) {
dsc_def.dsc$w_length = strlen(def); /* Length of work area */
dsc_def.dsc$a_pointer = def; /* Address of string */
} else {
dsc_def.dsc$w_length = 0; /* Length of work area */
dsc_def.dsc$a_pointer = 0; /* Address of string */
}
rms_s = lib$find_file(
&dsc_in, /* File spec */
&dsc_out, /* Result file spec */
&find_file_context, /* Context */
&dsc_def, /* Default file spec */
0, /* Related spec */
0, /* STV error */
0); /* Flags */
if (!(rms_s & 1)) vms_lasterr = rms_s;
if (rms_s == RMS$_NORMAL) {
max_len = ((unsigned short int) dsc_out.dsc$w_length < s_len ?
(unsigned short int) dsc_out.dsc$w_length : 0);
if (!max_len)
fprintf(stderr,
"%%ZKERMINI out string not long enough, ignoring .ini file\n");
else
strncpy(s,dsc_out.dsc$a_pointer,max_len);
lib$find_file_end(&find_file_context);
lib$sfree1_dd(&dsc_out); /* Return dyno memory */
return(0);
}
p++;
lib$find_file_end(&find_file_context);
}
/*
* No initialization file found. We can't return the null string because the
* runtime library will successfully open it if the file ".;" exists in the
* user's directory. Instead we return the name of the null device.
*/
strcpy(s, "NLA0:"); /* Return null init file */
lib$sfree1_dd(&dsc_out);
return(0);
}
#ifdef COMMENT
static int
parse_fname(cp, cp_len, defnam, flag, fncnv, fnspath)
char *cp; /* Pointer to file spec to parse */
int cp_len; /* Length of cp field */
char *defnam; /* Default file spec */
int flag; /* Flag word PARSE_xxx */
int fncnv; /* Filename conversion */
int fnspath; /* Pathname handling */
{
struct FAB fab;
struct NAM nam;
char expanded_name[NAM$C_MAXRSS];
char dirbuf[NAM$C_MAXRSS], *p, *q, *q2, *r, *s, *s2;
int long rms_status;
int cur_len = 0;
debug(F110,"zltor entry",defnam,0);
fab = cc$rms_fab;
fab.fab$l_nam = &nam;
fab.fab$l_fna = cp;
fab.fab$b_fns = strlen(cp);
if (defnam) {
fab.fab$b_dns = strlen(defnam);
fab.fab$l_dna = defnam;
} else
fab.fab$l_dna = 0;
nam = cc$rms_nam;
nam.nam$l_esa = (char *)&expanded_name;
nam.nam$b_ess = sizeof(expanded_name);
if (!CHECK_ERR("%%CKERMIT-W-PARSE, ",
sys$parse(&fab)))
return(-1);
*cp = '\0'; /* Start with an empty result */
if ((PARSE_NODE & flag) && nam.nam$b_node && /* DECnet node:: */
cur_len+nam.nam$b_node < cp_len) {
cur_len += nam.nam$b_node;
strncat(cp, nam.nam$l_node, (int)nam.nam$b_node);
}
if ((PARSE_DEVICE & flag) && nam.nam$b_dev && /* Device: */
cur_len+nam.nam$b_dev < cp_len) {
cur_len += nam.nam$b_dev;
strncat(cp, nam.nam$l_dev, (int)nam.nam$b_dev);
}
/* Directory Name [] */
if ((PARSE_DIRECTORY & flag) && nam.nam$b_dir &&
cur_len+nam.nam$b_dir < cp_len) {
int i; char * tmp;
q = nam.nam$l_dir; /* The directory name from RMS */
i = nam.nam$b_dir; /* Length; string not nul-terminated */
debug(F111,"zltor nam$_dir",q,i);
if (!q) q = "[]";
if (!*q) q = "[]";
if (i < 0) i = 0;
tmp = NULL;
if (i > 0) { /* Copy directory part */
if (tmp = malloc(i+1)) {
p = tmp;
for ( ; i > 0 ; i--)
*p++ = *q++;
*p = NUL;
}
}
q = tmp;
debug(F111,"zltor directory part",q,i);
s = zgtdir(); /* Get current directory */
debug(F110,"zltor zgtdir",s,0);
if (!s) s = "[]";
if (!*s) s = "[]";
s2 = "";
while (*s && *s != '[')
s++;
if (*s) {
s2 = s+1;
while (*s2 && *s2 != ']') s2++; /* Closing bracket */
}
if (!*s)
s = "[]";
else
if (*s2) if (!*(s2+1)) *(s2+1) = NUL;
debug(F110,"zltor current dir",s,0);
/* First change the VMS pathname to relative format if fnspath == PATH_REL */
p = dirbuf; /* Result */
*p++ = *q++; /* Copy left bracket and... */
s++; /* Point past it */
q2 = q; /* Remember this place */
if (fnspath == PATH_REL) { /* Compare this and current dir */
while (*s == *q && *s && *q && *s != ']') {
s++;
q++;
}
}
if (*s != ']' && *q != ']' && *q != '.') /* No match */
q = q2; /* So rewind source pointer */
while (*q) *p++ = *q++; /* Now copy the rest */
*p = NUL;
debug(F110,"zltor result 1",dirbuf,0);
/*
VMS directory name is now in dirbuf in either absolute or relative format.
Now change it to standard (UNIX) format if desired.
*/
p = dirbuf; /* Working pointer */
r = dirbuf; /* Result pointer */
if (fncnv) { /* Converting directory format */
int flag = 0;
if (p[1] == '.') { /* Directory name is relative */
r += 2; /* Point past the leading dot */
p += 2;
}
while (*p) { /* Now convert the rest */
if (*p == '.' || *p == '[' || *p == ']') {
if (!flag) *p = '/';
if (*p == ']')
flag = 1;
}
p++;
}
}
debug(F110,"zltor result 2",r,0);
if (tmp) free(tmp);
strncat(cp, r, (int)nam.nam$b_dir);
cur_len += strlen(r);
}
if ((PARSE_NAME & flag) && nam.nam$b_name &&
cur_len+nam.nam$b_name < cp_len) {
cur_len += nam.nam$b_name;
strncat(cp, nam.nam$l_name, (int)nam.nam$b_name);
}
if ((PARSE_TYPE & flag) && nam.nam$b_type &&
cur_len+nam.nam$b_type < cp_len) {
cur_len += nam.nam$b_type;
strncat(cp, nam.nam$l_type, (int)nam.nam$b_type);
}
if ((PARSE_VERSION & flag) && nam.nam$b_ver &&
cur_len+nam.nam$b_ver < cp_len) {
cur_len += nam.nam$b_ver;
strncat(cp, nam.nam$l_ver, (int)nam.nam$b_ver);
}
return(cur_len);
}
#endif /* COMMENT */
/* Z G P E R M -- Supposed to return the permissions of the given file... */
/* Not needed in VMS because new version inherits protection of old version */
char *
zgperm(f) char *f; {
return(NULL);
}
/* Z S A T T R -- Fill in a Kermit attribute structure for current file. */
/*
Fills in a Kermit file attribute structure for the file which is to be sent.
Returns 0 on success with the structure filled in, or -1 on failure.
If any string member is null, then it should be ignored.
If any numeric member is -1, then it should be ignored.
*/
int
zsattr(xx) struct zattr *xx; {
long k;
int x;
static char mth[13][4] = {
"JAN","FEB","MAR","APR",
"MAY","JUN","JUL","AUG",
"SEP","OCT","NOV","DEC",
""
};
static char recfm[15]; /* Record format */
static char cdate[20]; /* Creation date [yy]yymmdd[hh:mm[:ss]] */
static char creater_id[31]; /* Creator ID string */
static char genprot; /* Generic protection */
static char gpbuf[2]; /* String representation thereof */
static unsigned short lclprot; /* Local protection */
static char lpbuf[32]; /* String representation thereof */
static long sysparam_size=0; /* Length of system paramater buffer */
static char *sysparam_adr=0; /* Address of system paramater buffer */
char type; /* File type */
short int asctim_retlen;
char asctim_buf[24]; /* Work buffer for ASCTIM() */
struct dsc$descriptor_s
asctim_dsc = {sizeof(asctim_buf),DSC$K_DTYPE_T,DSC$K_CLASS_S,NULL};
/* static long int i; */
static unsigned short id_len;
static struct dsc$descriptor_s id_str =
{31,DSC$K_DTYPE_T,DSC$K_CLASS_S,creater_id};
/* Zero out strings */
type = 0;
recfm[0] = '\0';
cdate[0] = '\0';
creater_id[0] = '\0';
id_len = 0;
genprot = 0; /* Blank protections by default */
gpbuf[0] = '\0';
lclprot = 0;
lpbuf[0] = '\0';
asctim_dsc.dsc$a_pointer = (char *)&asctim_buf;
/* See if we are sending "attributes" from a REMOTE command response */
if (*nambuf == '\0') {
xx->lengthk = 1; /* Number of 1K blocks rounded up */
xx->type.len = 0; /* File type can't be filled in here */
xx->type.val = "";
xx->date.len = strlen(cdate); /* File creation date */
xx->date.val = (char *)&cdate;
xx->creator.len = strlen(creater_id); /* File creator */
xx->creator.val = (char *)&creater_id;
xx->account.len = 0; /* File account */
xx->account.val = "";
xx->area.len = 0; /* File area */
xx->area.val = "";
xx->password.len = 0; /* Area password */
xx->password.val = "";
xx->blksize = -1L; /* File blocksize */
xx->xaccess.len = 0; /* File access */
xx->xaccess.val = "";
xx->encoding.len = 1; /* Transfer syntax */
xx->encoding.val = "A"; /* ASCII */
xx->disp.len = 0; /* Disposition upon arrival */
xx->disp.val = "";
xx->lprotect.len = strlen(lpbuf); /* Local protection */
xx->lprotect.val = (char *)lpbuf;
xx->gprotect.len = strlen(gpbuf); /* Generic protection */
xx->gprotect.val = (char *)gpbuf;
xx->systemid.len = 2; /* System ID for DEC VMS */
xx->systemid.val = "D7";
xx->recfm.len = strlen(recfm); /* Record format */
xx->recfm.val = (char *)&recfm;
xx->sysparam.len = sysparam_size; /* System-dependent parameters */
xx->sysparam.val = sysparam_adr;
xx->length = 1; /* Length */
return(0); /* mumble sweet nothings at it */
}
/* Load the generic protection */
#ifdef COMMENT
x = xabpro_ifile.xab$w_pro >> XAB$V_WLD; /* World protection */
#else
x = (xabpro_ifile.xab$w_pro >> 4) & 0xFF; /* Owner protection */
#endif /* COMMENT */
if (!(x & XAB$M_NOREAD)) genprot |= 1; /* Read */
if (!(x & XAB$M_NOWRITE)) genprot |= 2+8; /* Write (and append) */
if (!(x & XAB$M_NOEXE)) genprot |= 4; /* Execute */
if (!(x & XAB$M_NODEL)) genprot |= 16; /* Delete */
gpbuf[0] = tochar(genprot); /* Generic prot as string */
gpbuf[1] = '\0';
lclprot = xabpro_ifile.xab$w_pro; /* Local-format protection */
sprintf(lpbuf,"%04X",lclprot); /* Convert to hex string */
/* Convert creation date from an internal value to common ascii string */
sys$asctim(&asctim_retlen,&asctim_dsc,&xabdat_ifile.xab$q_cdt,0);
asctim_buf[asctim_retlen] = '\0';
debug(F110,"zsattr asctim_buf",asctim_buf,0);
for (x = 0; strncmp(mth[x], asctim_buf+3,3); x++) /* Find month */
;
strncpy(cdate,asctim_buf+7,4); /* 'yyyy' */
sprintf(cdate+4,"%02d",x+1); /* 'mm' */
strncpy(cdate+6,asctim_buf+0,2); /* 'dd' */
strncpy(cdate+8,asctim_buf+11,9); /* ' hh:mm:ss' */
if (cdate[6] == ' ')
cdate[6] = '0';
debug(F110,"zsattr cdate",cdate,0);
/* Convert the owner UIC into an alpha name */
creater_id[0] = '\0';
rms_sts = sys$idtoasc(xabpro_ifile.xab$l_uic,&id_len,&id_str,0,0,0);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
creater_id[id_len] = '\0'; /* terminating null, please */
debug(F111,"zsattr $idtoasc owner",creater_id,strlen(creater_id));
if (rms_sts == SS$_NOSUCHID ||
#ifdef SS$_NORIGHTSDB /* only vms 5 and higher */
rms_sts == SS$_NORIGHTSDB ||
#endif /* SS$_NORIGHTSDB */
rms_sts == SS$_IVIDENT) {
creater_id[0] = '\0';
rms_sts = SS$_NORMAL; /* if unknown, null it out */
}
if (!(rms_sts & 1)) {
debug(F101,"zsattr $idtoasc failed, status","",rms_sts);
return(-1); /* fatal */
}
/* Fill in the record format blockette */
if (fab_ifile.fab$b_rat & (FAB$M_CR | FAB$M_FTN | FAB$M_PRN)) {
strcpy(recfm,"AMJ");
} else {
strcpy(recfm,"F");
sprintf(recfm+1,"%05d",xabfhc_ifile.xab$w_lrl);
}
debug(F111,"zsattr recfm",recfm,strlen(recfm));
/* Fill in the returned data structure */
xx->lengthk = (iflen/1024)+1; /* Number of 1K blocks rounded up */
xx->type.len = 0; /* File type can't be filled in here */
xx->type.val = "";
xx->date.len = strlen(cdate); /* File creation date */
xx->date.val = (char *)&cdate;
xx->creator.len = strlen(creater_id); /* File creator */
xx->creator.val = (char *)&creater_id;
xx->account.len = 0; /* File account */
xx->account.val = "";
xx->area.len = 0; /* File area */
xx->area.val = "";
xx->password.len = 0; /* Area password */
xx->password.val = "";
xx->blksize = -1L; /* File blocksize */
xx->xaccess.len = 0; /* File access */
xx->xaccess.val = "";
xx->encoding.len = 1; /* Transfer syntax */
xx->encoding.val = "A"; /* ASCII */
xx->disp.len = 0; /* Disposition upon arrival */
xx->disp.val = "";
xx->lprotect.len = strlen(lpbuf); /* Local protection */
xx->lprotect.val = (char *)lpbuf;
xx->gprotect.len = strlen(gpbuf); /* Generic protection */
xx->gprotect.val = (char *)gpbuf;
xx->systemid.len = 2; /* System ID for (Open)VMS */
xx->systemid.val = "D7";
xx->recfm.len = strlen(recfm); /* Record format */
xx->recfm.val = (char *)&recfm;
xx->sysparam.len = sysparam_size; /* System-dependent parameters */
xx->sysparam.val = sysparam_adr;
xx->length = iflen; /* Length */
debug(F111,"zsattr lengthk","",xx->lengthk);
debug(F111,"zsattr length","",xx->length);
return(0);
}
/* Z M K D I R -- Create directory(s) if necessary */
/*
Call with:
A pointer to a file specification that might contain directory
information. The filename is expected to be included.
If the file specification does not include any directory separators,
then it is assumed to be a plain file.
If one or more directories are included in the file specification,
this routine tries to create them if they don't already exist.
Returns:
0 on success, i.e. the directory was created, or didn't need to be.
-1 on failure to create the directory
VMS version by Mark Berryman, Feb 94.
*/
int
zmkdir(path) char *path; {
unsigned int
status,
/* SYS$PARSE(), */
lib$create_dir(),
lib$locc();
struct FAB dir_fab;
struct NAM dir_nam;
struct dsc$descriptor_s expanded_filename;
$DESCRIPTOR(close_bracket,"]");
char expanded_name[NAM$C_MAXRSS];
dir_fab = cc$rms_fab;
dir_fab.fab$l_fna = path;
dir_fab.fab$b_fns = strlen(path);
dir_fab.fab$l_nam = &dir_nam;
dir_nam = cc$rms_nam;
dir_nam.nam$l_esa = (char *) &expanded_name;
dir_nam.nam$b_ess = sizeof(expanded_name);
status = sys$parse(&dir_fab,0,0);
if (!(status & 1)) vms_lasterr = status;
/* If the result of SYS$PARSE is RMS$_NORMAL we need do nothing. */
if (status == RMS$_NORMAL) {
debug(F110,"zmkdir path already exists",path,0);
return 0;
}
debug(F111,"zmkdir status",path,status);
debug(F101,"zmkdir RMS$_DNF","",RMS$_DNF);
/* If the result is anything other than RMS$_DNF, it is fatal. */
if (status != RMS$_DNF)
return -1;
/* The parse succeeded but said the directory didn't exist, so create it. */
expanded_filename.dsc$b_class = DSC$K_CLASS_S;
expanded_filename.dsc$b_dtype = DSC$K_DTYPE_T;
expanded_filename.dsc$a_pointer = (char *) &expanded_name;
expanded_filename.dsc$w_length = dir_nam.nam$b_esl;
/* Strip the resulting specification to include only device and directory */
status = lib$locc(&close_bracket,&expanded_filename);
if (!(status & 1)) vms_lasterr = status;
expanded_filename.dsc$w_length = status;
debug(F110,"zmkdir creating",(char *) &expanded_name,0);
status = lib$create_dir(&expanded_filename,0,0,0,0,0);
if (!(status & 1)) vms_lasterr = status;
debug(F101,"zmkdir final status","",status);
return (status == SS$_CREATED ? 1 : -1);
}
/* Z R M D I R -- Delete a directory */
int
zrmdir(path) char *path; {
unsigned int status;
struct FAB dir_fab;
struct NAM dir_nam;
struct dsc$descriptor_s expanded_filename;
$DESCRIPTOR(close_bracket,"]");
char expanded_name[NAM$C_MAXRSS];
char tmpbuf[NAM$C_MAXRSS];
char * result;
char *p = path;
int lb = 0, rb = 0;
if (!p) p = "";
debug(F110,"zrmdir path 1",path,0);
if (!*p) return(-1);
/*
I'm sure there must be an API for deleting directories, but I don't know
what it is, so if any VMS programmers care to replace this routine by one
that does it right, be my guest (fdc, Nov 1997).
*/
while (*p) {
if (*p == '[') lb++;
else if (*p == ']') rb++;
p++;
}
if (lb != 1 && rb != 1 && p > path && *(p-1) != ':') {
sprintf(tmpbuf,"[.%s]",path);
} else {
strcpy(tmpbuf,path);
}
path = tmpbuf;
debug(F110,"zrmdir path 2",path,0);
dir_fab = cc$rms_fab;
dir_fab.fab$l_fna = path;
dir_fab.fab$b_fns = strlen(path);
dir_fab.fab$l_nam = &dir_nam;
dir_nam = cc$rms_nam;
dir_nam.nam$l_esa = (char *) &expanded_name;
dir_nam.nam$b_ess = sizeof(expanded_name);
status = sys$parse(&dir_fab,0,0);
if (!(status & 1)) vms_lasterr = status;
if (status != RMS$_NORMAL) /* Does not exist */
return(-1);
debug(F100,"zrmdir directory exists",path,0);
{
char * fb = NULL; /* First bracket */
char * lb = NULL; /* Last bracket */
char * lp = NULL; /* Last period */
unsigned long int sts;
p = path;
result = expanded_name;
while (*p) {
if (*p == '[') fb = p;
if (*p == '.') lp = p;
if (*p == ']') lb = p;
p++;
}
if (!fb || !lb) /* No brackets */
return(-1);
if (*(lb+1)) /* Something after right bracket */
return(-1);
if (*lp) { /* Last period */
*lp = ']';
*lb = NUL;
sprintf(result,"%s.DIR;1",path);
} else {
*lb = NUL;
sprintf(result,"[000000]%s.DIR;1",path);
}
if (result[0] = '[' && result[1] == ']')
result += 2;
debug(F110,"zrmdir result",result,0);
/*
Here we set the protection to something that allows us to delete it but
also allows us to access it again in case it can't be deleted, e.g. because
it contained some files.
*/
sprintf(tmpbuf,"set protection=owner:RWED %s",result);
sts = system(tmpbuf);
debug(F111,"zrmdir system() status ",tmpbuf,sts);
#ifdef COMMENT
/* If this failed it doesn't necessarily mean there is no Delete access */
if ((sts&1) != 1)
return(-1);
#endif /* COMMENT */
sprintf(tmpbuf,"delete %s",result); /* delete() won't do it. */
sts = system(tmpbuf);
debug(F111,"zrmdir system() status ",tmpbuf,sts);
if ((sts&1) != 1)
return(-1);
return(0);
}
}
/* Z M A I L -- Send file f as mail to address p. */
/*
Returns 0 on success
2 if mail delivered but temp file can't be deleted
-2 if mail can't be delivered
*/
int
zmail(p,f) char *p; char *f; {
char *zmbuf;
static char spbuf[] = "$ mail %s %s/subj=\"Enclosed file %s\"";
static char spbuf2[] = "%s;";
unsigned long int sts;
zmbuf = malloc(strlen(p)+(2*strlen(f))+sizeof(spbuf));
sprintf(zmbuf,spbuf, f, p, f);
sts = system(zmbuf);
debug(F111,"zmail: system returns status ",zmbuf,sts);
free(zmbuf);
if ((sts&1) != 1) {
debug(F101,"zmail: returning","",-2);
return(-2);
}
zmbuf = malloc(strlen(f)+sizeof(spbuf2));
sprintf(zmbuf,spbuf2, f);
sts = delete(zmbuf);
debug(F111,"zmail: delete returns status ",zmbuf,sts);
free(zmbuf);
if (sts) sts = 2;
debug(F101,"zmail: returning","",sts);
return(sts);
}
/* Z P R I N T -- Print file f with options p. */
/*
Returns 0 on success, -3 on failure.
*/
int
zprint(p,f) char *p; char *f; {
char *zmbuf;
static char spbuf[] = "$ print/delete %s %s";
unsigned long int sts;
zmbuf = malloc(strlen(p)+strlen(f)+sizeof(spbuf));
sprintf(zmbuf,spbuf, p, f);
sts = system(zmbuf);
debug(F111,"zprint: system returns status ",zmbuf,sts);
free(zmbuf);
debug(F101,"zprint: returning","",(sts&1) ? 0 : -3);
return((sts&1) ? 0 : -3);
}
/* Z S Y S C M D -- Execute a DCL command with direct output. */
/*
* Since it's really difficult to have an alternate CLI under VMS (since the
* MCR interface isn't documented and POSIX hasn't published the interface,
* we'll just assume everybody uses DCL and hand it of to zshcmd().
*/
int
zsyscmd(s) char *s; {
return(zshcmd(s));
}
/*
* Dummy function, since SIG_DFL seems to be broken with DEC C
*/
VOID
sig_dum() {
}
/* Z S H C M D -- Execute a default CLI command with direct output. */
/*
* As it's _REALLY_ unlikely that the user is using MCR as his default CLI,
* and DEC doesn't document how to write any other alternate CLIs, use DCL.
*/
#ifndef SS$_EXPRCLM /* VMS doesn't return this yet, but let's */
#define SS$_EXPRCLM 10804 /* be forward-thinking and anticpate VMS */
#endif /* SS$_EXPRCLM */ /* V6.0, which will return it. */
int
zshcmd(s) char *s; {
unsigned long sts, cc;
void (*cct)();
void (*sig_dum_ptr)() = sig_dum;
struct dsc$descriptor_s
cmd_line = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
char *i;
pexitstat = -1;
if (!s) s = "";
debug(F110,"zshcmd",s,0);
if (check_spawn() != 0) {
debug(F100,"zshcmd: spawning prohibited by UAF flags","",0);
return(0);
}
i = strstr(zgtdir(),"::");
if (i != NULL) {
debug(F100,"zshcmd: spawn prohibited on remote node","",0);
printf("Cannot SPAWN with remote node as default directory\n");
if (*s)
printf("therefore, cannot execute the DCL command \"%s\"\n", s);
return(0);
}
cct = signal(SIGINT,sig_dum_ptr); /* Let inferior process catch ^C */
cmd_line.dsc$w_length = strlen(s);
cmd_line.dsc$a_pointer = s;
if (!(*s))
printf("Type LOGOUT to return to VMS C-Kermit.\n\n");
sts = lib$spawn(&cmd_line, 0, 0, 0, 0, 0, &cc, 0, 0, 0, 0, 0);
if (!(sts & 1)) vms_lasterr = sts;
signal(SIGINT,cct);
/*
* Note: We can't check for this beforehand as doing a getjpi for prclm will
* only return the UAF value, not the available value. So we try it and
* print this message if it didn't work.
*/
if ((sts == SS$_EXQUOTA) || (sts == SS$_EXPRCLM)) {
printf(
"Your account does not have sufficient quotas to use this command.\n");
printf(
"Please ask your system manager to increase your UAF PRCLM quota.\n");
}
debug(F101,"zshcmd lib$spawn sts", "", sts);
debug(F101,"zshcmd lib$spawn cc ", "", cc);
debug(F101,"zshcmd lib$spawn SS$_NORMAL", "", SS$_NORMAL);
if (sts == SS$_NORMAL) {
pexitstat = cc;
return((cc & 1) ? 1 : 0); /* Success */
} else {
return(0); /* Failure */
}
}
/* Z S T R I P -- Strip device & directory name from file specification. */
/* Strip pathname from filename "name", return pointer to result in name2 */
static char work[1100]; /* buffer for use by zstrip and zltor */
VOID
zstrip(name,name2) char *name, **name2; {
char *cp, *pp;
char last;
int len;
debug(F110,"zstrip entry",name,0);
pp = work; /* Default return is empty string */
*name2 = work;
*pp = '\0';
if (!name)
return;
if (!*name)
return;
/* NODE::DEV:[DIR] terminates on on final ':', '>' or ']'. */
for (cp = name; *cp; cp++) {
last = *cp;
if (*cp == '/' || *cp == ':' || *cp == '>' || *cp == ']') /* slash? */
pp = work;
else if (*cp == ';') /* Chop off any version number */
break;
else /* Part of filename */
*pp++ = *cp;
}
*pp = '\0'; /* Terminate the string */
debug(F000,"zstrip 2",work,last);
#ifdef COMMENT
/*
This is a bad idea because the result will need to be passed thru zstrip()
again, but zstrip() isn't designed to call itself.
*/
if (work[0] == '\0' && last == ':') { /* Result is empty? */
char * q; /* Maybe it's a logical name */
q = (char *)malloc(1100);
if (q) {
strncpy(q,name,1099);
len = strlen(q);
if (len > 0) {
if (q[len-1] == ':') {
char *t = q;
q[len-1] = '\0';
while (*t) { if (islower(*t)) *t = toupper(*t); t++; }
debug(F110,"zstrip checking",q,0);
pp = getenv(q);
if (!pp) pp = "";
strncpy(work,pp,1099);
debug(F110,"zstrip getenv",work,0);
}
}
free(q);
}
}
debug(F110,"zstrip 3",work,0);
#endif /* COMMENT */
/* The following should allow us to receive files to LPT:, LTA1:, etc. */
if (work[0] == '\0') { /* Still empty? */
debug(F000,"zstrip last",name,last); /* If it's a device name */
if (last == ':') /* put it back */
strncpy(work,name,1099);
}
debug(F110,"zstrip result",*name2,0);
}
int
zchkpath(s) char *s; {
/*
This needs to be replaced with something more intelligent.
The idea is to see if the file, whose specification is pointed to by s,
is in the current directory. This function should return 0 if it s,
nonzero otherwise. Presently we rely on being called with a full
filespec of the form DISK:[DEV]NAME.TYP;V, so this works more or less
by accident. What we really need is to call some kind of VMS service
to get the NODE::DEV:[DIR] of the file, and compare with the current
NODE::DEV:[DIR].
*/
char *p;
p = zgtdir(); /* Get current dir. */
debug(F110,"zchkpath file",s,0);
debug(F110,"zchkpath current dir",p,0);
return(strncmp(p,s,strlen(p))); /* Compare it. */
}
#ifdef OLD_VMS
#ifndef VMS_V46 /* rename() included in VAXCRTL as of VMS v4.6*/
static VOID
descname(desc,name) struct dsc$descriptor_s *desc; char *name; {
desc->dsc$w_length = strlen(name); /* Length of name */
desc->dsc$a_pointer = name; /* Address */
desc->dsc$b_class = DSC$K_CLASS_S; /* String descriptor class */
desc->dsc$b_dtype = DSC$K_DTYPE_T; /* ASCII string data type */
}
/* VMS version of RENAME */
int /* ? */
rename(oldname, newname) char oldname[], newname[]; {
struct dsc$descriptor_s old_desc, new_desc;
int lib$rename_file();
/* Build string descriptors */
descname(&old_desc, oldname);
descname(&new_desc, newname);
/* Call lib$rename_file routine */
return(lib$rename_file(&old_desc, &new_desc, 0,0,0,0,0,0,0,0,0,0));
}
#endif /* !VMS_46 */
#endif /* OLD_VMS */
/*
* Check to see if we have spawn priv's.
*/
int
check_spawn() {
struct itmlstdef {
short int buflen;
short int itmcod;
char *bufaddr;
long int *retlen;
};
struct itmlstdef itmlst[] =
{4,JPI$_UAF_FLAGS,0,0,0,0,0,0};
long uaf_flags_size;
unsigned long uaf_flags;
itmlst[0].bufaddr = (char *)&uaf_flags;
itmlst[0].retlen = &uaf_flags_size;
vms_status = sys$getjpiw(0, 0, 0, &itmlst, 0, 0, 0);
if (!(vms_status & 1)) vms_lasterr = vms_status;
if ((vms_status) != SS$_NORMAL)
return(-1); /* Assume the worst... */
#ifdef UAI$M_CAPTIVE
if (uaf_flags & UAI$M_CAPTIVE) {
printf(
"\nThis command cannot be executed. Your account is CAPTIVE.\n\n");
return(-1);
}
#endif /* UAI$M_CAPTIVE */
#ifdef UAI$M_RESTRICTED /* for pre-V5.2 systems */
if (uaf_flags & UAI$M_RESTRICTED) {
printf(
"\nThis command cannot be executed. Your account is CAPTIVE.\n\n");
return(-1);
}
#endif /* uai$v_restricted */
return(0);
}
/*
* Stuff having to do with SET FILE TYPE LABELED
*/
char *
get_vms_vers() {
static char sysver[9];
int len;
struct itmlst {
short int buflen;
short int code;
char *bufadr;
int *retlen;
} vms_sysver[2];
vms_sysver[0].buflen = 8;
vms_sysver[0].code = SYI$_VERSION;
vms_sysver[0].bufadr = (char *)&sysver;
vms_sysver[0].retlen = &len;
vms_sysver[1].buflen = 0;
vms_sysver[1].code = 0;
sys$getsyiw(0,0,0,&vms_sysver,0,0,0);
sysver[8]='\0';
len = 7;
while (sysver[len] == ' ') {
sysver[len] = '\0';
len--;
}
return(sysver);
}
/* Find where a relative file specification starts in the expanded file
* name. Returns the number of characters preceeding the relative portion
*/
int
fnd_rel(name) char *name; {
int ix=0;
char relnam[NAM$C_MAXRSS];
char *ip;
nzltor(name, relnam, 0, PATH_REL, NAM$C_MAXRSS);
debug(F111, " fnd_rel: absolute name and length", name, strlen(name));
debug(F111, " fnd_rel: relative name and length", relnam, strlen(relnam));
if ( (*relnam == '[') || (*relnam == '<') ) {
ip = strstr(name, &relnam[1]);
if (ip) ix = ip - name;
} else { /* no common path; send as PATH OFF */
ip = strstr(name, relnam);
if (ip) ix = ip - name -1; /* do_label_rcv will use the bracket */
}
return(ix);
}
int
do_label_send(name) char *name; {
int pad_size;
int rel_dspec;
extern int fnspath;
zinptr += sprintf(zinptr,"KERMIT LABELED FILE:02D704VERS");
zinptr += sprintf(zinptr,"%08d%s", strlen(get_vms_vers()), get_vms_vers());
zinptr += sprintf(zinptr,"05KVERS00000008%08ld", vernum);
if (fnspath == PATH_REL) {
rel_dspec = fnd_rel(name);
debug(F101," do_label_send: rel dir at char","", rel_dspec);
zinptr += sprintf(zinptr,"07REL_DIR00000008%08ld", rel_dspec);
}
zinptr += sprintf(zinptr,"07VMSNAME%08d", strlen(name));
zinptr += sprintf(zinptr,"%s", name);
zinptr += sprintf(zinptr,"07VMSFILE%08d", 70);
memmove(zinptr, &xabpro_ifile.xab$w_pro, 2);
zinptr += 2;
memmove(zinptr, &xabpro_ifile.xab$l_uic, 4);
zinptr += 4;
memmove(zinptr, &fab_ifile.fab$b_rfm, 1);
zinptr += 1;
memmove(zinptr, &fab_ifile.fab$b_org, 1);
zinptr += 1;
memmove(zinptr, &fab_ifile.fab$b_rat, 1);
zinptr += 1;
memmove(zinptr, &xuchar, 4); /* Dummy for file chars. */
zinptr += 4;
memmove(zinptr, &fab_ifile.fab$b_fsz, 1);
zinptr += 1;
memmove(zinptr, &xabfhc_ifile.xab$w_lrl, 2);
zinptr += 2;
memmove(zinptr, &fab_ifile.fab$w_mrs, 2);
zinptr += 2;
memmove(zinptr, &xabfhc_ifile.xab$l_ebk, 4);
zinptr += 4;
memmove(zinptr, &xabfhc_ifile.xab$w_ffb, 2);
zinptr += 2;
memmove(zinptr, &xabfhc_ifile.xab$l_hbk, 4);
zinptr += 4;
memmove(zinptr, &fab_ifile.fab$w_deq, 2);
zinptr += 2;
memmove(zinptr, &fab_ifile.fab$b_bks, 1);
zinptr += 1;
memmove(zinptr, &fab_ifile.fab$w_gbc, 2);
zinptr += 2;
memmove(zinptr, &xabfhc_ifile.xab$w_verlimit, 2);
zinptr += 2;
memmove(zinptr, &fab_ifile.fab$b_rfm+1, 1); /* This is fab$b_journal */
zinptr += 1;
memmove(zinptr, &xabdat_ifile.xab$q_cdt, 8);
zinptr += 8;
memmove(zinptr, &xabdat_ifile.xab$q_rdt, 8);
zinptr += 8;
memmove(zinptr, &xabdat_ifile.xab$w_rvn, 2);
zinptr += 2;
memmove(zinptr, &xabdat_ifile.xab$q_edt, 8);
zinptr += 8;
memmove(zinptr, &xabdat_ifile.xab$q_bdt, 8);
zinptr += 8;
if (xabpro_ifile.xab$w_acllen != 0) {
debug(F101, "do_label_send: acllen", "", xabpro_ifile.xab$w_acllen);
zinptr += sprintf(zinptr,"06VMSACL%08d", xabpro_ifile.xab$w_acllen);
memmove(zinptr, &aclbuf, xabpro_ifile.xab$w_acllen);
zinptr += xabpro_ifile.xab$w_acllen;
}
zinptr += sprintf(zinptr,"04DATA00000000");
zincnt = (zinptr - zinbuffer); /* Size of this beast */
zinptr = zinbuffer; /* Reset pointer for readout */
return(1);
}
/*
D O _ L A B E L _ R E C V
Note that we don't honor SET FILE COLLISION APPEND for labeled receives --
the whole point of labeled receives is to generate an exact copy of the
source file, attributes and all.
*/
#define CK_LBLBUFLEN 16
#define CK_VMSFILELEN 70
int
do_label_recv() {
extern int fnrpath; /* (look at this later...) */
char *recv_ptr;
char buffer[CK_LBLBUFLEN+1];
char vmsfile[CK_VMSFILELEN];
char *filptr = vmsfile;
int lblen, alen;
int gotname = 0, gotfile = 0, gotacl = 0, gotrel = 0;
char *i, *j;
unsigned short jnlflg;
debug(F101,"do_label_recv: options","",ofile_lblopts);
ofile_lblproc = 1; /* Don't come here again */
if (strncmp(zoutbuffer,"KERMIT LABELED FILE:02D704VERS",30) != 0)
return(0); /* Just continue if unlabeled */
recv_ptr = zoutbuffer+30; /* start at front of buffer */
memcpy(buffer, recv_ptr, 8);
recv_ptr += 8;
buffer[8] = '\0';
lblen = atoi(buffer);
if (lblen > CK_LBLBUFLEN) {
debug(F101,"do_label_recv: lblen too long 1","",lblen);
return(-1);
}
memcpy(buffer, recv_ptr, lblen);
recv_ptr += lblen;
buffer[lblen] = '\0';
debug(F110,"do_label_recv: file created under {Open}VMS: ",buffer,0);
memcpy(buffer, recv_ptr, 7);
recv_ptr += 7;
if (strncmp(buffer, "05KVERS", 7) != 0) {
debug(F100,"do_label_recv: lost sync at KVERS","",0);
return(-1);
}
memcpy(buffer, recv_ptr, 8);
recv_ptr += 8;
buffer[8] = '\0';
lblen = atoi(buffer);
if (lblen > CK_LBLBUFLEN) {
debug(F101,"do_label_recv: lblen too long 2","",lblen);
return(-1);
}
memcpy(buffer, recv_ptr, lblen);
recv_ptr += lblen;
buffer[lblen] = '\0';
debug(F110,"do_label_recv: file created with C-Kermit/VMS: ",buffer,0);
next_label:
memcpy(buffer, recv_ptr, 2);
recv_ptr += 2;
buffer[2] = '\0';
lblen = atoi(buffer);
if (lblen == 0) {
debug(F100,"do_label_recv: lost sync at next_label: ","",0);
return(-1);
} else if (lblen > CK_LBLBUFLEN) {
debug(F101,"do_label_recv: lblen too long 3","",lblen);
return(-1);
}
memcpy(buffer, recv_ptr, lblen);
recv_ptr += lblen;
buffer[lblen] = '\0';
debug(F110,"do_label_recv: found tag: ",buffer,0);
if (strcmp(buffer, "VMSNAME") == 0) {
memcpy(buffer, recv_ptr, 8);
recv_ptr += 8;
buffer[8] = '\0';
lblen = atoi(buffer);
if (lblen > CKMAXPATH) { /* fdc 23 Jun 96 */
debug(F101,"do_label_recv: lblen too long 4","",lblen);
return(-1);
}
memcpy(ofile_vmsname, recv_ptr, lblen);
recv_ptr += lblen;
ofile_vmsname[lblen] = '\0';
gotname++;
debug(F110,"do_label_recv: loaded file name block as: ",
ofile_vmsname,
0
);
debug(F110,"do_label_recv: ofile_vmsname 2",ofile_vmsname,0);
if ((ofile_lblopts & LBL_PTH) == 0) {
if ( (fnrpath == PATH_REL) && (gotrel > 0) ) {
i = strrchr(ofile_vmsname, '[');
if (i != NULL) {
ofile_vmsname[0] = '[';
} else {
ofile_vmsname[0] = '<';
}
strcpy(&ofile_vmsname[1],&ofile_vmsname[gotrel]);
} else {
i = strstr(ofile_vmsname, "::");
if (i != NULL) {
i += 2;
memmove(ofile_vmsname, i, strlen(ofile_vmsname));
}
i = strrchr(ofile_vmsname, ':');
j = strrchr(ofile_vmsname, ']');
if (j == NULL)
j = strrchr(ofile_vmsname, '>');
if (j > i)
i = j;
if (i) { /* fdc 6-12-96 */
i++;
memmove(ofile_vmsname, i, strlen(ofile_vmsname));
}
}
} else {
i = strstr(ofile_vmsname, "::");
if (i != NULL) {
i += 2;
memmove(ofile_vmsname, i, strlen(ofile_vmsname));
}
}
debug(F110,"do_label_recv: ofile_vmsname 3",ofile_vmsname,0);
if (strchr(ofile_vmsname, ';') != NULL) {
for (alen = strlen(ofile_vmsname);
ofile_vmsname[alen] != ';' && alen > 0;
alen--)
;
ofile_vmsname[alen] = '\0';
}
debug(F110,"do_label_recv: resultant filespec: ",ofile_vmsname,0);
goto next_label;
} else if (strcmp(buffer, "REL_DIR") == 0) {
memcpy(buffer, recv_ptr, 8);
recv_ptr += 8;
buffer[8] = '\0';
lblen = atoi(buffer);
if (lblen > CK_LBLBUFLEN) {
debug(F101,"do_label_recv: lblen too long 5","",lblen);
return(-1);
}
memcpy(buffer, recv_ptr, lblen);
recv_ptr += lblen;
buffer[lblen] = '\0';
gotrel = atoi(buffer);
if ( (gotrel < 3) || (gotrel > NAM$C_MAXRSS) ) {
debug(F101,
"do_label_recv: rel dir head position wrong",
"",
gotrel
);
return(-1);
}
debug(F101,"do_label_recv: relative directory position","", gotrel);
goto next_label;
} else if (strcmp(buffer, "VMSFILE") == 0) {
memcpy(buffer, recv_ptr, 8);
recv_ptr += 8;
buffer[8] = '\0';
lblen = atoi(buffer);
if (lblen > CK_VMSFILELEN) {
debug(F101,"do_label_recv: lblen too long 5","",lblen);
return(-1);
}
memcpy(vmsfile, recv_ptr, lblen);
recv_ptr += lblen;
vmsfile[lblen] = '\0';
gotfile++;
debug(F100,"do_label_recv: loaded file attribute block","",0);
goto next_label;
} else if (strcmp(buffer, "VMSACL") == 0) {
memcpy(buffer, recv_ptr, 8);
recv_ptr += 8;
buffer[8] = '\0';
ofile_acllen = atoi(buffer);
if (ofile_acllen > sizeof(ofile_vmsacl) ) {
debug(F101,"do_label_recv: ofile_acllen too long","",ofile_acllen);
return(-1);
}
memcpy(ofile_vmsacl, recv_ptr, ofile_acllen);
recv_ptr += ofile_acllen;
/* ofile_vmsacl[ofile_acllen] = '\0'; */ /* ACL buffer is binary */
gotacl++;
debug(F100,"do_label_recv: loaded file ACL block","",0);
goto next_label;
} else if (strcmp(buffer, "DATA") == 0) {
memcpy(buffer, recv_ptr, 8);
recv_ptr += 8;
buffer[8] = '\0';
lblen = atoi(buffer);
if (lblen != 0) {
debug(F101,"do_label_recv: length of DATA tag not zero","",lblen);
return(-1);
}
debug(F100,"do_label_recv: positioned at start of file data","",0);
goto all_set;
} else {
debug(F110,"do_label_recv: unrecognized label: ",buffer,0);
memcpy(buffer, recv_ptr, 8);
recv_ptr += 8;
buffer[8] = '\0';
lblen = atoi(buffer);
recv_ptr += lblen;
goto next_label;
}
all_set:
if (gotfile != 1 || gotname != 1) {
debug(F100,"do_label_recv: missing one or more required labels","",0);
return(-1);
}
/* Prep the characteristics */
fab_ofile.fab$b_fac = FAB$M_BIO | FAB$M_PUT;
fab_ofile.fab$l_fop = FAB$M_MXV;
if ((ofile_lblopts & LBL_NAM) != 0) {
fab_ofile.fab$l_fna = ofile_vmsname;
fab_ofile.fab$b_fns = strlen(ofile_vmsname);
}
fab_ofile.fab$l_xab = (char *)&xabdat_ofile;
rab_ofile = cc$rms_rab;
rab_ofile.rab$l_fab = &fab_ofile;
xabdat_ofile = cc$rms_xabdat;
xabdat_ofile.xab$l_nxt = (char *)&xabrdt_ofile;
xabrdt_ofile = cc$rms_xabrdt;
xabrdt_ofile.xab$l_nxt = (char *)&xabfhc_ofile;
xabfhc_ofile = cc$rms_xabfhc;
xabfhc_ofile.xab$l_nxt = (char *)&xabpro_ofile;
xabpro_ofile = cc$rms_xabpro;
xabpro_ofile.xab$l_nxt = (char *)&xaball_ofile;
xaball_ofile = cc$rms_xaball;
/* Load 'em up */
memmove(&xabpro_ofile.xab$w_pro, filptr, 2);
filptr += 2;
if ((ofile_lblopts & LBL_OWN) != 0)
memmove(&xabpro_ofile.xab$l_uic, filptr, 4);
filptr += 4;
memmove(&fab_ofile.fab$b_rfm, filptr, 1);
filptr += 1;
memmove(&fab_ofile.fab$b_org, filptr, 1);
filptr += 1;
memmove(&fab_ofile.fab$b_rat, filptr, 1);
filptr += 1;
filptr += 4; /* reserved */
memmove(&fab_ofile.fab$b_fsz, filptr, 1);
filptr += 1;
memmove(&xabfhc_ofile.xab$w_lrl, filptr, 2);
filptr += 2;
memmove(&fab_ofile.fab$w_mrs, filptr, 2);
filptr += 2;
memmove(&xabfhc_ofile.xab$l_ebk, filptr, 4);
filptr += 4;
/* preserve this as RMS won't remember it for us */
memmove(&ofile_ffb, filptr, 2);
filptr += 2;
memmove(&xaball_ofile.xab$l_alq, filptr, 4);
filptr += 4;
memmove(&xaball_ofile.xab$w_deq, filptr, 2);
filptr += 2;
#ifdef COMMENT /* was: defined(VAX) && defined(__DECC) */
/*
When DEC C first came out for the VAX, the xab$b_bkz definition was missing
and they used xaballdef$$_fill_7 instead. But that was a long time ago.
(This change made for C-Kermit 6.0, 19 Sep 96.)
*/
memmove(&xaball_ofile.xaballdef$$_fill_7, filptr, 1);
#else
memmove(&xaball_ofile.xab$b_bkz, filptr, 1);
#endif /* COMMENT */
filptr += 1;
memmove(&fab_ofile.fab$w_gbc, filptr, 2);
filptr += 2;
memmove(&xabfhc_ofile.xab$w_verlimit, filptr, 2);
filptr += 2;
memmove(&jnlflg, filptr, 1);
if (jnlflg !=0)
debug(F100,"do_label_recv: journaling status removed for file","",0);
filptr += 1;
memmove(&xabdat_ofile.xab$q_cdt, filptr, 8);
filptr += 8;
memmove(&revdat, filptr, 8);
filptr += 8;
memmove(&revnum, filptr, 2);
filptr += 2;
memmove(&xabdat_ofile.xab$q_edt, filptr, 8);
filptr += 8;
if ((ofile_lblopts & LBL_BCK) != 0)
memmove(&xabdat_ofile.xab$q_bdt, filptr, 8);
filptr += 8;
/* ACL's? */
if ((ofile_lblopts & LBL_ACL) != 0 && gotacl != 0) {
xabpro_ofile.xab$l_aclbuf = (char *)&ofile_vmsacl;
xabpro_ofile.xab$w_aclsiz = ofile_acllen;
}
/* Try to create the file */
rms_sts = sys$create(&fab_ofile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (!(rms_sts & 1)) {
debug(F101,"do_label_recv: $create failed, status","",rms_sts);
return(-1);
}
if ((ofile_lblopts & LBL_ACL) != 0 && gotacl != 0) {
if (!(xabpro_ofile.xab$l_aclsts & 1)) {
debug(F101,"do_label_recv: ACL chain failed, status",
"",
xabpro_ofile.xab$l_aclsts
);
return(-1);
}
}
rms_sts = sys$connect(&rab_ofile);
if (!(rms_sts & 1)) vms_lasterr = rms_sts;
if (!(rms_sts & 1)) {
debug(F101,"do_label_recv: $connect failed, status","",rms_sts);
return(-1);
}
/*
Slide the remainder of the data to the head of the buffer and adjust the
counter and pointer. This will cause the buffer to be re-filled to the full
32Kb capacity, which is necessary for proper operation of zoutdump().
*/
zoutcnt -= ((char *)recv_ptr - (char *)zoutbuffer);
debug(F101,"do_label_recv: zoutcnt","",zoutcnt);
memcpy(zoutbuffer, recv_ptr, zoutcnt);
zoutptr = zoutbuffer + zoutcnt;
return(1); /* Go fill some more */
}
static char xxvmsmsg[PMSG_MSG_SIZE];
char *
ckvmserrstr(x) unsigned long x; {
long int n = 0;
struct dsc$descriptor_s b = {
PMSG_BUF_SIZE - 1,
DSC$K_DTYPE_T,
DSC$K_CLASS_S,
NULL
};
if (x < 1) x = vms_lasterr;
b.dsc$a_pointer = (char *)&xxvmsmsg;
if (!((vms_status = sys$getmsg(x, &n, &b, 0, 0)) & 1))
return("%CKERMIT-W-UNKERR, Unknown error");
xxvmsmsg[n] = '\0';
return((char *)xxvmsmsg);
}
/* End of CKVFIO.C */
|