File: echo.c

package info (click to toggle)
ng 1.5~beta1-14
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,164 kB
  • sloc: ansic: 44,018; asm: 3,150; sh: 2,539; cpp: 1,234; makefile: 578
file content (3216 lines) | stat: -rw-r--r-- 62,565 bytes parent folder | download | duplicates (2)
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
/* $Id: echo.c,v 1.8.2.1 2003/03/02 15:29:37 amura Exp $ */
/*
 *		Echo line reading and writing.
 *
 * Common routines for reading
 * and writing characters in the echo line area
 * of the display screen. Used by the entire
 * known universe.
 */
/*
 * The varargs lint directive comments are 0 an attempt to get lint to shup
 * up about CORRECT usage of varargs.h.  It won't.
 */

/*
 * $Log: echo.c,v $
 * Revision 1.8.2.1  2003/03/02 15:29:37  amura
 * add minibuffer history (thanks to kakugawa)
 *
 * Revision 1.8  2001/01/05 14:07:01  amura
 * first implementation of Hojo Kanji support
 *
 * Revision 1.7  2000/11/19 18:15:11  amura
 * rename sput?() functions because HP-UX have sputl() function
 * in its library
 *
 * Revision 1.6  2000/07/18 12:38:56  amura
 * remove some compile warning
 *
 * Revision 1.5  2000/06/27 01:49:43  amura
 * import to CVS
 *
 * Revision 1.4  2000/06/04  06:21:47  amura
 * To be able to compile without KANJI
 *
 * Revision 1.3  2000/06/01  05:26:18  amura
 * Debug CANNA support
 *
 * Revision 1.2  2000/03/28  02:38:37  amura
 * CANNA support.
 * ,
 *
 * Revision 1.1  2000/03/10  21:32:52  amura
 * Initial revision
 *
 */
/* 90.01.29	Modified for Ng 1.0 by S.Yoshida */

#include	"config.h"	/* 90.12.20  by S.Yoshida */
#include	"def.h"
#include	"key.h"
#ifdef SUPPORT_ANSI
#  include	<stdarg.h>
#else	/* !SUPPPORT_ANSI */
# ifdef	LOCAL_VARARGS
#  include	"varargs.h"
# else
# include	<varargs.h>
# endif
#endif	/* SUPPORT_ANSI */
#ifndef NO_MACRO
#  include	"macro.h"
#endif

static int	veread();
#ifdef SUPPORT_ANSI
VOID		ewprintf(char *fp, ...);
int		message(char *fp,...);
#else
VOID		ewprintf();
int		message();
#endif

static VOID	eformat pro((register char *fp, register va_list *ap));
static VOID	eputi();
static VOID	eputl();
static VOID	eputs();
static VOID	eputc();
#ifndef	NEW_COMPLETE	/* 90.12.10    Sawayanagi Yosirou */
static int	complt();
#endif	/* NEW_COMPLETE */

#ifdef	ADDFUNC	/* 91.01.16  by S.Yoshida */
int	earg_exist = FALSE;		/* Extra argument existing flag. */
char	*earg_text;			/* Extra argument text body.	*/

/*
 * Set extra argument using in veread().
 */
VOID
eargset(earg)
char	*earg;
{
	earg_exist = TRUE;
	earg_text = earg;
}
#endif	/* ADDFUNC */
#ifdef EXTD_DIR
static char *edef_text;			/* Default argument text body */

/*
 * Set extra argument using in veread().
 */
VOID
edefset(earg)
char	*earg;
{
  edef_text = earg;
}
#endif /* EXTD_DIR */

int	epresf	= FALSE;		/* Stuff in echo line flag.	*/
/*
 * Erase the echo line.
 */
VOID
eerase() {
	ttcolor(CTEXT);
	ttmove(nrow-1, 0);
	tteeol();
	ttflush();
	epresf = FALSE;
}

/*
 * Ask "yes" or "no" question.
 * Return ABORT if the user answers the question
 * with the abort ("^G") character. Return FALSE
 * for "no" and TRUE for "yes". No formatting
 * services are available. No newline required.
 */
int
eyorn(sp) char *sp; {
	register int	s;

#ifndef NO_MACRO
	if(inmacro) return TRUE;
#endif
	ewprintf("%s? (y or n) ", sp);
#ifdef FEPCTRL	/* 90.11.26  by K.Takano */
	fepmode_off();
#endif
	for (;;) {
		s = getkey(FALSE);
		if (s == 'y' || s == 'Y') return TRUE;
		if (s == 'n' || s == 'N') return FALSE;
		if (s == CCHR('[') || s == CCHR('G')) return ctrlg(FFRAND, 1);
		ewprintf("Please answer y or n.  %s? (y or n) ", sp);
	}
	/*NOTREACHED*/
}

/*
 * Like eyorn, but for more important question. User must type either all of
 * "yes" or "no", and the trainling newline.
 */
int
eyesno(sp) char *sp; {
	register int	s;
	char		buf[64];

#ifndef NO_MACRO
	if(inmacro) return TRUE;
#endif
	s = ereply("%s? (yes or no) ", buf, sizeof(buf), sp);
	for (;;) {
		if (s == ABORT) return ABORT;
		if (s != FALSE) {
#ifndef NO_MACRO
			if (macrodef) {
			    LINE *lp = maclcur;

			    maclcur = lp->l_bp;
			    maclcur->l_fp = lp->l_fp;
			    free((char *)lp);
			}
#endif
			if ((buf[0] == 'y' || buf[0] == 'Y')
			    &&	(buf[1] == 'e' || buf[1] == 'E')
			    &&	(buf[2] == 's' || buf[2] == 'S')
			    &&	(buf[3] == '\0')) return TRUE;
			if ((buf[0] == 'n' || buf[0] == 'N')
			    &&	(buf[1] == 'o' || buf[0] == 'O')
			    &&	(buf[2] == '\0')) return FALSE;
		}
#ifdef  notyet
		message("Please answer yes or no.");
		ttwait();
		s = ereply("%s? (yes or no) ", buf, sizeof(buf), sp);
#else
		s = ereply("Please answer yes or no.  %s? (yes or no) ",
			   buf, sizeof(buf), sp);
#endif
	}
	/*NOTREACHED*/
}

/*
 * Write out a prompt, and read back a
 * reply. The prompt is now written out with full "ewprintf"
 * formatting, although the arguments are in a rather strange
 * place. This is always a new message, there is no auto
 * completion, and the return is echoed as such.
 */
/*VARARGS 0*/
#ifdef SUPPORT_ANSI
int
ereply(char *fp, char *buf, int nbuf, ... )
{
    int	    i;
    va_list pvar;

    va_start(pvar, nbuf) ;
    i = veread(fp, buf, nbuf, EFNEW|EFCR, &pvar) ;
    va_end(pvar) ;
    return i;
}
#else	/* SUPPORT_ANSI */
int
ereply(va_alist)
va_dcl
{
	va_list pvar;
	register char *fp, *buf;
	register int nbuf;
	register int i;

	va_start(pvar);
	fp = va_arg(pvar, char *);
	buf = va_arg(pvar, char *);
	nbuf = va_arg(pvar, int);
	i = veread(fp, buf, nbuf, EFNEW|EFCR, &pvar);
	va_end(pvar);
	return i;
}
#endif	/* SUPPORT_ANSI */

/*
 * This is the general "read input from the
 * echo line" routine. The basic idea is that the prompt
 * string "prompt" is written to the echo line, and a one
 * line reply is read back into the supplied "buf" (with
 * maximum length "len"). The "flag" contains EFNEW (a
 * new prompt), an EFFUNC (autocomplete), or EFCR (echo
 * the carriage return as CR).
 */
/* VARARGS 0 */
#ifdef SUPPORT_ANSI
int
eread(char *fp, char *buf, int nbuf, int flag, ...)
{
    int	    i;
    va_list pvar;
    va_start(pvar, flag);

    i = veread(fp, buf, nbuf, flag, &pvar);
    va_end(pvar) ;
    return i;
}
#else	/* SUPPORT_ANSI */
int
eread(va_alist)
va_dcl
{
	va_list pvar;
	char *fp, *buf;
	int nbuf, flag, i;
	
	va_start(pvar);
	fp   = va_arg(pvar, char *);
	buf  = va_arg(pvar, char *);
	nbuf = va_arg(pvar, int);
	flag = va_arg(pvar, int);
	i = veread(fp, buf, nbuf, flag, &pvar);
	va_end(pvar);
	return i;
}
#endif	/* SUPPORT_ANSI */

#ifdef	NEW_COMPLETE	/* 90.12.10    Sawayanagi Yosirou */
#include    "complt.h"

#ifdef MINIBUF_EDIT
/* Minibuffer hack from NGSCM by H.Kakugawa */

#define MB_NHISTS		10
#define MB_HIST_FUNC		0
#define MB_HIST_BUF		1
#define MB_HIST_FILE		2
#define MB_HIST_MISC		3
#define MB_HIST_NTYPES		4
/* Note: mb_hist_buf[*][0] plays a special role. */
static char *mb_hist_buf[MB_HIST_NTYPES][MB_NHISTS+1];
#define mb_get_hist_buf(flag)					\
	(((flag)&EFFUNC) ? mb_hist_buf[MB_HIST_FUNC] :		\
	(((flag)&EFBUF)  ? mb_hist_buf[MB_HIST_BUF] :		\
	(((flag)&EFFILE) ? mb_hist_buf[MB_HIST_FILE] :		\
			mb_hist_buf[MB_HIST_MISC])))		\

extern int  refresh();

static int  mb_init();
static int  mb_get_buffer();
static int  mb_bufsize();
static int  mb_pointchar();
static int  mb_pointoverwrite();
static int  mb_point();
static int  mb_iseol();
static int  mb_isbol();
static int  mb_isword();
static int  mb_gotochar();
static int  mb2_gotochar();
static int  mb_insert();
static int  mb2_insert();
static int  mb_insertstr();
static VOID mb_insertcmplmsg();
static int  mb2_insertcmplmsg();
static int  mb_delcmplmsg();
static int  mb_appenddiff();
static int  mb2_appenddiff();
static int  mb_delc();
static int  mb2_delc();
static int  mb_erasec();
static int  mb2_erasec();
static int  mb_killw();
static int  mb_delw();
static int  mb_forwc();
static int  mb_backwc();
static int  mb2_forwc();
static int  mb2_backwc();
static int  mb_forww();
static int  mb_backww();
static int  mb_begl();
static int  mb_endl();
static int  mb_upw();
static int  mb_downw();
static int  mb_cancel();
static int  mb2_cancel();
static int  mb_kill();
static int  mb_yank();
static int  mb_trans();
static int  mb_matchparen();
static int  mb_col();
static int  mb_putchar();
static VOID mb_move();
static VOID mb_movech();
static int  mb_fixlines();
static VOID mb_redisplay();
static VOID mb_refresh();
static VOID mb_flush();
static VOID mb_hist_save();
static char* sformat();
static int  s_put_i();
static int  s_put_l();
static int  s_put_s();
static int  s_put_c();
static VOID chsize();
static VOID chsize2();

#ifdef CANNA
#include <canna/jrkanji.h>
#define CANBUF 1024

extern jrKanjiStatus ks;
static int mb_henkan();
char mbMode[CANBUF];
int  mb_cannamode;
#endif

#ifdef	CLIPBOARD
extern int	send_clipboard();
extern int	receive_clipboard();
#endif

static int veread_complete();

static int
veread(fp, buf, nbuf, flag, ap)
  char    *fp;
  char    *buf;
  int    nbuf;
  int    flag;
  va_list *ap;
{
  int        MetaPrefix, CtluPrefix, nargs, cmp_msg_len, sign, ctluf;
  int        c;
  char       **hist_buf;
  int        hist_idx;
  
#ifdef	ADDFUNC
  /* If an extra argument exists, use it.			*/
  /* This is a very easy way of not getting an argument from	*/
  /* the keyboard.	*/
    if(earg_exist)
      {
	strcpy(buf, earg_text);
	earg_exist = FALSE;
#ifdef EXTD_DIR
        edef_text = NULL;
#endif
	return (TRUE);
      }
#endif	/* ADDFUNC */
#ifndef NO_MACRO
    if(inmacro)
      {
        bcopy (maclcur->l_text, buf, maclcur->l_used);
	buf[maclcur->l_used] = '\0';
	maclcur = maclcur->l_fp;
#ifdef EXTD_DIR
        edef_text = NULL;
#endif
	return (TRUE);
      }
#endif

  mb_init(nbuf, fp, ap);
  cmp_msg_len = 0;
  MetaPrefix  = 0;
  CtluPrefix  = 0;
  nargs       = 1;
  sign        = 1;
  ctluf       = 0;
#ifdef CANNA
  mb_cannamode  = FALSE;
  mbMode[0] = '\0';
#endif
  hist_buf    = mb_get_hist_buf(flag);
  hist_buf[0] = buf;
  hist_idx = 0;

  for (;;){
    ttflush();
    lastflag = thisflag;
    thisflag = 0;

    c = getkey(FALSE); 
#ifdef CANNA
    if(mb_cannamode &&
       (ks.length != 0 || !(c==' '||ISCTRL(c)||ISKANJI(c))) ){
	if (mb_henkan(c))
	    continue;
    }
#endif

    if (CtluPrefix == 1){
      switch (c){
      case CCHR('G'):
	nargs = 1;
	sign  = 1;
	ctluf = 0;
	CtluPrefix = 0;
	thisflag = lastflag;
	continue;
	break;
      case CCHR('U'):
	if (ctluf == 0){
	  ctluf = 1;
	  nargs = 4;
	  sign = 1;
	} else 
	  nargs *= 4;
	break;
      case '0':case '1':case '2':case '3':case '4':
      case '5':case '6':case '7':case '8':case '9':
	if (ctluf == 1){
	  nargs = (c - '0');
	  ctluf = 0;
	} else {
	  nargs = (10*nargs + (c - '0')); 
	}
	break;
      case '-':
	if (ctluf == 1){
	  sign = -1;
	  ctluf = 0;
	  nargs = 0;
	  break;
	} else {
	  hist_buf[0] = NULL; /* reset top of history */
	  return (ABORT);
	}
      default: 
	goto Cmd;
      }
      thisflag = lastflag;
      continue;
    }
Cmd:
    nargs = sign * nargs;
    CtluPrefix = 0;

    if (MetaPrefix == 1){
      switch (c){
      case CCHR('G'):      /* Espace from Meta prefix  */
	break;
      case '<':            /* Beginning of Line */
	mb_begl();
	break;
      case '>':            /* End of Line */
	mb_endl();
	break;
      case 'B': case 'b':  /* Backword word */
	mb_backww(nargs);
	break;
      case 'F': case 'f':  /* Forward word */
	mb_forww(nargs);
	break;
      case 'D': case 'd':  /* Delete word */
	if ((lastflag&CFKILL) == 0)
	  kdelete();
	thisflag |= CFKILL;
	mb_delw(nargs);
	break;
      case 'u': case 'U':  /* Upcase word */
	mb_upw(nargs);
	break;
      case 'l': case 'L':  /* Downcase word */
	mb_downw(nargs);
	break;
      case CCHR('V'):      /* Scroll down completion window */
	if (nargs > 0)
	  while (nargs-- > 0)
	    complete_scroll_down();
	else
	  while (nargs++ < 0)
	    complete_scroll_up();
	break;
      case 'p': case 'P':  /* History, prev */
	if (hist_idx < MB_NHISTS && hist_buf[hist_idx+1] != NULL) {
	  if (hist_idx == 0)
	    mb_get_buffer(buf, nbuf);
	  hist_idx++;
	  mb_begl();
	  mb_kill();
	  mb_insertstr(hist_buf[hist_idx]);
	  mb_begl();
	}
	else {
	  message("Beginning of history; no preceding item");
	  ttwait();
	}
	mb_redisplay();
	break;
      case 'n': case 'N':  /* History, next */
	if (hist_buf[1] == NULL) {
	  message("End of history; no default available");
	  ttwait();
	}
	else if (hist_idx == 0) {
	  message("End of history; no next item");
	  ttwait();
	}
	else {
	    hist_idx--;
	    mb_begl();
	    mb_kill();
	    mb_insertstr(hist_buf[hist_idx]);
	    mb_begl();
	}
	mb_redisplay();
	break;
		    
      default:
	ttbeep();
      }
      MetaPrefix = 0;
    } else {
      switch (c){
      case CCHR('['):    /* META prefix */
	MetaPrefix = 1;
	thisflag = lastflag;
	continue;
      case CCHR('U'):    /* Ctl-U prefix */
	CtluPrefix = 1;
	nargs = 4;
	ctluf = 1;
	sign  = 1;
	thisflag = lastflag;
	continue;
      case ' ':
      case CCHR('I'):    /* SPC/TAB, or completion */
	if (flag & EFAUTO)
	  cmp_msg_len = veread_complete(buf, nbuf, c, flag);
	else 
	  mb_insert(1, (char) c);
	break;
      case CCHR('J'):    /* End of input */
	c = CCHR('M');
      case CCHR('M'):	/* Return, done.	*/
	mb_get_buffer(buf, nbuf);
	if (flag & EFFUNC){
	  int    matchnum;
	  matchnum = complete(buf, flag);
	  if (matchnum != COMPLT_SOLE
	      && matchnum != COMPLT_NOT_UNIQUE){
	    /* complete() will be called again, but i don't mind it */
	    cmp_msg_len = veread_complete(buf, nbuf, (int)CCHR('I'), flag);
	    break;
	  }
	}
	complete_del_list();
	if (flag & EFCR){
	  ttputc(CCHR('M'));
	  ttflush ();
	}
	hist_buf[0] = NULL; /* reset top of history */
#ifndef NO_MACRO
	if (macrodef){
	  LINE *lp;
	  
	  if((lp = lalloc(mb_bufsize())) == NULL)
	    return FALSE;
	  lp->l_fp = maclcur->l_fp;
	  maclcur->l_fp = lp;
	  lp->l_bp = maclcur;
	  maclcur = lp;
	  bcopy(buf, lp->l_text, mb_bufsize());
	}
#endif
	if (mb_bufsize() == 0)
	  return FALSE;
	mb_hist_save(hist_buf, buf);
	return TRUE;
      case CCHR('G'):	/* Abort */
	(VOID) ctrlg(FFRAND, 0);
	mb_flush();
	complete_del_list();
	hist_buf[0] = NULL; /* reset top of history */
	return (ABORT);
      case CCHR('A'):     /* Beginning of line */
	mb_begl();
	break;
      case CCHR('B'):     /* Backword char */
	mb_backwc(nargs);
	break;
      case CCHR('D'):     /* Delete */
	mb_delc(nargs);
	break;
      case CCHR('E'):     /* End of line */
	mb_endl();
	break;
      case CCHR('F'):     /* Forward char */
	mb_forwc(nargs);
	break;
      case CCHR('H'):
      case CCHR('?'):	/* Rubout, erase */
	mb_erasec(nargs);
	break;
      case CCHR('K'):     /* Kill after point */
	if ((lastflag&CFKILL) == 0)
	  kdelete();
	thisflag |= CFKILL;
	mb_kill();
	break;
      case CCHR('L'):     /* redraw */
	refresh(FFRAND, 0);
	update();
	mb_redisplay();
	break;
      case CCHR('N'):     /* Scroll down completion window */
	if (nargs > 0)
	  while (nargs-- > 0)
	    complete_scroll_down();
	else
	  while (nargs++ < 0)
	    complete_scroll_up();
	break;
      case CCHR('P'):     /* Scroll up completion window */
	if (nargs > 0)
	  while (nargs-- > 0)
	    complete_scroll_up();
	else
	  while (nargs++ < 0)
	    complete_scroll_down();
	break;
      case CCHR('T'):	/* Transpose char */
	mb_trans(nargs);
	break;
      case CCHR('W'):	/* Kill a word around point */
	mb_killw(nargs);
	break;
      case CCHR('X'):	/* Kill line */
	mb_cancel();
	break;
      case CCHR('Y'):     /* Yank */
	mb_yank(nargs);
	break;
      case ')':
	mb_matchparen(nargs, '(', ')');
	break;
      case ']':
	mb_matchparen(nargs, '[', ']');
	break;
      case '}':
	mb_matchparen(nargs, '{', '}');
	break;
      case CCHR('\\'):
#ifdef CANNA
      case CCHR('O'):
	mb_cannamode = mb_cannamode ? FALSE : TRUE;
	if (!mb_cannamode)
	  mbMode[0] = '\0';
	break;
#endif
      case CCHR('Q'):	/* Quote next	*/
	c = getkey(FALSE);
      default:		/* All the rest */
	if (mb_insert(nargs, (char) c) < 0)
	  break;
      }
    }
    nargs = 1;
    ctluf = 0;
    sign  = 1;
  }
}

static int
veread_complete(buf, nbuf, c, flag)
  char   *buf;
  int    nbuf, c, flag;
{
  int    matchnum, wflag;

  mb_endl();
  wflag = (c == ' ');
  if (wflag){
    mb2_insert(1, ' ');
    mb_get_buffer(buf, nbuf);
    if (complete(buf, flag) == COMPLT_NO_MATCH){
      mb2_erasec(1);
    } else {
      mb_appenddiff(buf);
      return 0;
    }
  }
  mb_get_buffer(buf, nbuf);
  matchnum = complete(buf, flag);
  mb_appenddiff(buf);
  if (wflag){
    if (matchnum == COMPLT_AMBIGUOUS
	|| matchnum == COMPLT_NOT_UNIQUE)
      complete_list_names(buf, flag);
    else if (matchnum == COMPLT_NO_MATCH) {
      mb_insertcmplmsg(complete_message(matchnum));
      ttwait();
      mb_delcmplmsg();
    }
  } else {
    if (matchnum == COMPLT_AMBIGUOUS)
      complete_list_names(buf, flag);
    else { 
      mb_insertcmplmsg(complete_message(matchnum));
      ttwait();
      mb_delcmplmsg();
    }
  }
  return 0;
}

/*VARARGS 0*/
#ifdef SUPPORT_ANSI
int
message(char *fp,...)
{
  va_list pvar;
  va_start(pvar, fp);
  ewprintf(fp);
  va_end(pvar);
  return 0;
}
#else
int
message(va_alist)
  va_dcl
{
  va_list pvar;
  register char *fp;
  
  va_start(pvar);
  fp = va_arg(pvar, char *);
  ewprintf(fp);
  va_end(pvar);
  return 0;
}
#endif	/* SUPPORT_ANSI */

struct _Line {
  int  idx;
  int  lno;
  struct _Line *prev;
  struct _Line *next;
};

static int   _mb_ccol;
static int   _mb_crow;
static char *_mb_buf      = NULL;
static int  _mb_size      = 0;
static int  _mb_point     = 0;
static int  _mb_gapend    = 0;
static int  _mb_prompt    = 0;
static int  _mb_bufsize   = 0;
struct
  _Line  Line = {0, 0, NULL, NULL};
struct _Line  *CLine;

static int
mb_init(nbuf, fp, ap)
  int  nbuf;
  register char *fp;
  register va_list *ap;
{
  char  *prompt;
  struct _Line   *lp, *lp2;
  char  *sformat();

  prompt = sformat(fp, ap);
  if (_mb_buf == NULL){
    _mb_size = nbuf + strlen(prompt) + 10;
    if ((_mb_buf = malloc(_mb_size)) == NULL)
      return -1;
  }
  if (ttrow != nrow - 1){
    ttcolor(CTEXT);
    epresf = TRUE;
  }

  _mb_ccol = 0;
  _mb_crow = nrow-1;
  _mb_prompt    = 0;
  _mb_point     = 0;
  _mb_gapend    = _mb_size;
  _mb_bufsize   = 0;

  if (Line.next != NULL){
    lp = Line.next;
    while (lp != &Line){
      lp2 = lp->next;
      free(lp);
      lp = lp2;
    }
    Line.prev = NULL;
    Line.next = NULL;
  }
  if ((lp = (struct _Line*) malloc(sizeof(struct _Line))) == NULL)
    return 0;
  Line.prev  = lp;
  Line.next  = lp;
  lp->idx    = 0;
  lp->lno    = 1;
  lp->prev   = &Line;
  lp->next   = &Line;
  CLine      = lp;

  mb_insertstr(prompt);
  _mb_prompt = strlen(prompt);
  free(prompt);
#ifdef EXTD_DIR
  if (edef_text) {
    mb_insertstr(edef_text);
    edef_text = NULL;
  }
#endif
  return 0;
}
static int
mb_get_buffer(buf, nbuf)
  char *buf;
  int nbuf;
{
  register int  i, j;

  j = 0;
  for (i = _mb_prompt; i < _mb_point;){
    if (j >= nbuf-1){
#ifdef	KANJI
      if (ISKANJI(_mb_buf[i])) {
#ifdef	HOJO_KANJI
	if (i>=1 && ISHOJO(_mb_buf[i-1])) buf[j-2] = '\0';
	else
#endif
	buf[j-1] = '\0';
      } else
#endif	/* KANJI */
	buf[j] = '\0';
      return 0;
    }
    buf[j++] = _mb_buf[i++];
  }
  for (i = _mb_gapend; i < _mb_size;){
    if (j >= nbuf-1){
#ifdef	KANJI
	if (ISKANJI(_mb_buf[i])) {
#ifdef	HOJO_KANJI
	if (i>=1 && ISHOJO(_mb_buf[i-1])) buf[j-2] = '\0';
	else
#endif
	buf[j-1] = '\0';
    } else
#endif
	buf[j] = '\0';
      return 0;
    }
    buf[j++] = _mb_buf[i++];
  }
  buf[j] = '\0';
  return mb_bufsize();
}
static int
mb_bufsize()
{
  return _mb_bufsize-_mb_prompt;
}
static int
mb_pointchar()
{
  unsigned int  ch;

  ch = _mb_buf[_mb_point-1];
  return ch;
}
static int
mb_pointoverwrite(ch)
     unsigned int  ch;
{
  _mb_buf[_mb_point-1] = ch;
  return ch;
}
static int
mb_point()
{
  return _mb_point;
}
static int
mb_iseol()
{
  return (_mb_gapend == _mb_size);
}
static int
mb_isbol()
{
  return (_mb_point == _mb_prompt);
}
static int
mb_isword()
{
  return ISWORD(_mb_buf[_mb_gapend]);
}
static int
mb_gotochar(i)
  int  i;
{
  int  col, pt, ocol, opt;
  struct _Line *lp;

  if (i == _mb_point)
    return mb_point();
  ocol = _mb_ccol;
  opt  = _mb_point;
  lp = CLine;
  mb2_gotochar(i);
  if (i < opt)
    mb_fixlines(0, Line.next, 0, &col, &pt);
  else 
    mb_fixlines(ocol, lp, opt, &col, &pt);
  if (lp == CLine)
    ttmove(_mb_crow, _mb_ccol);
  else
    mb_refresh(col, pt);
  return mb_point();
}
static int
mb2_gotochar(i)
  int  i;
{
  if (i != _mb_point)
    mb_move(i-_mb_point);
  return mb_point();
}
static int
mb_insert(n, c)
  int  n;
  char c;
{
  int  col, pt, ocol, opt;
#ifdef	KANJI
  static int  k1 = 0, nnn;
#ifdef	HOJO_KANJI
  static int  k2 = 0;
#endif
#endif
  struct _Line *lp;

#ifndef	KANJI
  if (n < 0)
    return -1;
  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
  mb2_insert(n, c);
  mb_fixlines(ocol, lp, opt, &col, &pt);
  mb_refresh(col, pt);
#else	/* KANJI is TRUE */
  if (k1 == 0){
    if (n < 0)
      return -1;
    if (ISKANJI(c)){
      k1  = c;
      nnn = n;
    } else {
      ocol = _mb_ccol;
      opt  = _mb_point;
      lp   = CLine;
      mb2_insert(n, c);
      mb_fixlines(ocol, lp, opt, &col, &pt);
      mb_refresh(col, pt);
    }
#ifdef	HOJO_KANJI
  } else if (ISHOJO(k1) && k2 == 0) {
    if (ISKANJI(c)) {
      k2 = c;
      nnn = n;
    } else {
      ocol = _mb_ccol;
      opt  = _mb_point;
      lp   = CLine;
      mb2_insert(n, c);
      mb_fixlines(ocol, lp, opt, &col, &pt);
      mb_refresh(col, pt);
    }
#endif	/* HOJO_KANJI */
  } else {
    ocol = _mb_ccol;
    opt  = _mb_point;
    lp   = CLine;
    while (nnn-- > 0){
      mb2_insert(1, k1);
#ifdef	HOJO_KANJI
      if (k2 != 0) mb2_insert(1, k2);
#endif
      mb2_insert(1, c);
    }
    mb_fixlines(ocol, lp, opt, &col, &pt);
    mb_refresh(col, pt);
    k1 = 0;
#ifdef	HOJO_KANJI
    k2 = 0;
#endif
  }
#endif /* NOT KANJI */
  return 0;
}
static int
mb2_insert(n, c)
  int  n;
  char c;
{
  if (n < 0)
    return -1;
  while (n-- > 0)
    mb_putchar(c);
  return mb_point();
}
static int
mb_insertstr(s)
  char *s;
{
  int  col, pt, ocol, opt;
  struct _Line *lp;

  if (*s == '\0')
    return 0;
  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
  while (*s != '\0')
    mb_putchar(*(s++));
  if (mb_fixlines(ocol, lp, opt, &col, &pt) == 0)
    mb_refresh(ocol, opt);
  else
    mb_refresh(col, pt);
  return mb_point();
}

static int _mb_cmpl_msg_len   = 0;

static VOID
mb_insertcmplmsg(s)
  char *s;
{
  int  pt, col;

  mb2_insertcmplmsg(s);
  mb_fixlines(_mb_ccol, CLine, _mb_point, &col, &pt);
  mb_refresh(_mb_ccol, _mb_point);
}
static int
mb2_insertcmplmsg(s)
  char *s;
{
  int  pt;

  _mb_cmpl_msg_len = strlen(s);
  pt = mb_point();
  while (*s != '\0')
    mb_putchar(*(s++));
  mb2_gotochar(pt);
  return pt;
}
static int
mb_delcmplmsg()
{
  int  col, pt;
  struct _Line  *lp;

  if (_mb_cmpl_msg_len == 0)
    return 0;
  _mb_gapend  += _mb_cmpl_msg_len;
  _mb_bufsize -= _mb_cmpl_msg_len;
  _mb_cmpl_msg_len = 0;
  lp = CLine;
  mb_fixlines(_mb_ccol, CLine, _mb_point, &col, &pt);
  if (lp == CLine)
    tteeol();
  else
    mb_refresh(col, pt);
  _mb_cmpl_msg_len = 0;
  return mb_point();
}
static int
mb_appenddiff(buf)
  char *buf;
{
  int  ocol, opt, col, pt;
  struct _Line *lp;

  ocol = _mb_ccol;
  opt  = _mb_point;
  lp = CLine;
  mb2_appenddiff(buf);
  if (mb_fixlines(ocol, lp, opt, &col, &pt) == 0)
    mb_refresh(ocol, opt);
  else
    mb_redisplay();
  return mb_point();
}
static int
mb2_appenddiff(buf)
  char *buf;
{
  int p2;
  char *p1;
  
  for (p1 = buf, p2 = _mb_prompt; p2 < _mb_point; p1++, p2++)
    ;
  while (*p1 != '\0')
    mb_putchar(*(p1++));
  return mb_point();
}
static int
mb_delc(n)
  int  n;
{
  int  col, pt;

  if (n < 0)
    return -1;
  if (mb2_delc(n) < 0)
    return -1;
  mb_fixlines(_mb_ccol, CLine, _mb_point, &col, &pt);
  mb_refresh(col, pt);
  return mb_point();
}
static int
mb2_delc(n)
  int  n;
{
  int  v, m;

  while (n-- > 0){
    if (_mb_gapend == _mb_size)
      break;
    chsize(&_mb_buf[_mb_gapend], &v, &m);
    _mb_gapend  += m;
    _mb_bufsize -= m;
  }
  return mb_point();
}
static int
mb_erasec(n)
  int  n;
{
  int  col, pt;
  struct _Line *lp;

  lp = CLine;
  mb2_erasec(n);
  mb_fixlines(0, Line.next, 0, &col, &pt);
  if (lp == CLine)
    mb_refresh(_mb_ccol, _mb_point); 
  else 
    mb_redisplay();
  return mb_point();
}
static int
mb2_erasec(n)
  int  n;
{
  if (n < 0)
    return -1;
  while (n-- > 0){
    if (_mb_point <= _mb_prompt)
      return -1;
    if (mb2_backwc(1) < 0)
      return -1;
    if (mb2_delc(1) < 0)
      return -1;
  }
  return mb_point();
}
static int
mb_killw(n)
  int   n;
{
  int  col, pt;
  struct _Line *lp;

  if (n < 0)
    return -1;
  lp = CLine;
  while (n-- > 0){
    if (!mb_iseol())
      mb2_forwc(1);
    while (!mb_iseol() && mb_isword())
      mb2_delc(1);
    if (!mb_isbol())
      mb2_backwc(1);
    while (!mb_isbol() && !mb_isword()){
      mb2_delc(1);
      mb2_backwc(1);
    }
    while (!mb_isbol() && mb_isword()){
      mb2_delc(1);
      mb2_backwc(1);
    } 
    if (mb_isbol())
      mb2_delc(1);
  }
  mb_fixlines(0, Line.next, 0, &col, &pt);
  if (CLine != lp)
    mb_refresh(_mb_ccol, _mb_point);    
  else
    mb_refresh(col, pt);
  return mb_point();
}
static int
mb_delw(n)
  int n;
{
  int  v, m, ocol, opt, col, pt, i;
  struct _Line *lp;

  if (n <= 0)
    return mb_point();

  ocol = _mb_ccol;
  opt  = _mb_point;
  lp = CLine;
  while (n-- > 0){
    if (_mb_gapend == _mb_size)
      goto End;
    if (!mb_isword()){
      while (!mb_iseol() && !mb_isword()){
	chsize(&_mb_buf[_mb_gapend], &v, &m);
	for (i = 0; i < m; i++)
	  if (kinsert(_mb_buf[_mb_gapend+i], KFORW) < 0)
	    break;
	_mb_gapend  += m;
	_mb_bufsize -= m;
	if (_mb_gapend == _mb_size)
	  goto End;
      }
    }
    while (!mb_iseol() && mb_isword()){
      chsize(&_mb_buf[_mb_gapend], &v, &m);
      for (i = 0; i < m; i++)
	if (kinsert(_mb_buf[_mb_gapend+i], KFORW) < 0)
	  break;
      _mb_gapend  += m;
      _mb_bufsize -= m;
	if (_mb_gapend == _mb_size)
	  goto End;
    }
  }
End:
#ifdef CLIPBOARD
  send_clipboard();
#endif
  mb_fixlines(_mb_ccol, CLine, _mb_point, &col, &pt);
  mb_refresh(col, pt);
  return mb_point();
}
static int
mb_forwc(n)
  int  n;
{
  int  ocol, opt, col, pt;
  struct _Line  *lp;

  if (n < 0)
    return mb_backwc(-n);
  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
  mb2_forwc(n);
  if (mb_fixlines(ocol, lp, opt, &col, &pt) == 0)
    ttmove(_mb_crow, _mb_ccol);
  else 
    mb_refresh(col, pt);
  return mb_point();
}
static int
mb_backwc(n)
  int  n;
{
  int  col, pt;
  struct _Line  *lp;

  if (n < 0)
    return mb_forwc(-n);
  lp = CLine;
  mb2_backwc(n);
  mb_fixlines(0, Line.next, 0, &col, &pt);
  if (lp == CLine)
    ttmove(_mb_crow, _mb_ccol);
  else 
    mb_refresh(col, pt);
  return mb_point();
}
static int
mb2_forwc(n)
  int  n;
{
  int  v, m;

  if (_mb_gapend == _mb_size)
    return mb_point();
  while ((n-- > 0) && (_mb_gapend < _mb_size)){
    chsize(&_mb_buf[_mb_gapend], &v, &m);
    mb_move(m);
  }
  return mb_point();
}
static int
mb2_backwc(n)
  int  n;
{
  int  m, v;

  if (_mb_point == _mb_prompt)
    return mb_point();
  while ((n-- > 0) && (_mb_point > _mb_prompt)){
    chsize2(&_mb_buf[_mb_point-1], &v, &m);
    mb_move(-m);
  }
  return mb_point();
}
static int
mb_forww(n)
  int n;
{
  int  ocol, opt, col, pt;
  struct _Line  *lp;

  if (n < 0)
    return mb_backww(-n);
  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
  while (n-- > 0){
    /**
    if (!mb_iseol())
      mb2_forwc(1);
      **/
    if (!mb_isword()){
      while (!mb_iseol() && !mb_isword())
	mb2_forwc(1);
    }
    while (!mb_iseol() && mb_isword())
      mb2_forwc(1);
  }
  if (mb_fixlines(ocol, lp, opt, &col, &pt) == 0)
    ttmove(_mb_crow, _mb_ccol);
  else 
    mb_refresh(col, pt);
  return mb_point();
}
static int
mb_backww(n)
  int  n;
{
  int  ocol, opt, col, pt;
  struct _Line  *lp;

  if (n < 0)
    return mb_forww(-n);
  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
  while (n-- > 0){
    if (!mb_isbol())
      mb2_backwc(1);
    if (!mb_isword()){
      while (!mb_isbol() && !mb_isword())
	mb2_backwc(1);
    }
    while (!mb_isbol() && mb_isword())
      mb2_backwc(1);
    if (!mb_isbol())
      mb2_forwc(1);
  }
  mb_fixlines(0, Line.next, 0, &col, &pt);
  if (lp == CLine)
    ttmove(_mb_crow, _mb_ccol);
  else 
    mb_refresh(col, pt);
  return mb_point();
}
static int
mb_begl()
{
  return mb_gotochar(_mb_prompt);
}
static int
mb_endl()
{
  return mb_gotochar(_mb_bufsize);
}
static int  
mb_upw(n)
     int n;
{
  int  ocol, opt, col, pt;
  struct _Line  *lp;

  if (n <= 0)
    return mb_point();

  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
  while (n-- > 0){
    if (!mb_isword()){
      while (!mb_iseol() && !mb_isword())
	mb2_forwc(1);
    }
    while (!mb_iseol() && mb_isword()){
      mb2_forwc(1);
      if (ISLOWER(mb_pointchar()))
	mb_pointoverwrite(TOUPPER(mb_pointchar()));
    }
  }
  if (mb_fixlines(ocol, lp, opt, &col, &pt) == 0)
    mb_refresh(ocol, opt);
  else
    mb_redisplay();
  return mb_point();
}
static int  
mb_downw(n)
     int n;
{
  int  ocol, opt, col, pt;
  struct _Line  *lp;

  if (n <= 0)
    return mb_point();

  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
  while (n-- > 0){
    if (!mb_isword()){
      while (!mb_iseol() && !mb_isword())
	mb2_forwc(1);
    }
    while (!mb_iseol() && mb_isword()){
      mb2_forwc(1);
      if (ISUPPER(mb_pointchar()))
	mb_pointoverwrite(TOLOWER(mb_pointchar()));
    }
  }
  if (mb_fixlines(ocol, lp, opt, &col, &pt) == 0)
    mb_refresh(ocol, opt);
  else
    mb_redisplay();
  return mb_point();
}

static int
mb_cancel()
{
  struct _Line *lp;

  lp = CLine;
  mb2_cancel();
  if (lp == CLine){
    ttmove(_mb_crow, _mb_ccol);
    tteeol();
  } else
    mb_redisplay();
  return mb_point();
}
static int
mb2_cancel()
{
  int  col, pt;

  _mb_point   = _mb_prompt;
  _mb_gapend  = _mb_size;
  _mb_bufsize = _mb_prompt;
  mb_fixlines(0, Line.next, 0, &col, &pt);
  return mb_point();
}
static int
mb_kill()
{
  int col, pt;

  while (_mb_gapend < _mb_size){
    if (kinsert(_mb_buf[_mb_gapend], KFORW) < 0)
      break;
    _mb_gapend++;
    _mb_bufsize--;
  }
#ifdef CLIPBOARD
  send_clipboard();
#endif
  if (mb_fixlines(_mb_ccol, CLine, _mb_point, &col, &pt) == 0)
    tteeol();
  else 
    mb_refresh(col, pt);
  return mb_point();
}
static int
mb_yank(n)
  int  n;
{
  int  col, pt, ocol, opt, i;
  int  ch;
  struct _Line *lp;

  if (n < 0)
    return -1;
  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
#ifdef CLIPBOARD
  receive_clipboard();
#endif
  while (n-- > 0){
    i = 0;
    while ((ch=kremove(i++)) >= 0){
      mb_putchar(ch);
    }
  }
  mb_fixlines(ocol, lp, opt, &col, &pt);
  if (lp == CLine)
    mb_refresh(ocol, opt);
  else
    mb_redisplay();
  return mb_point();
}
static int
mb_trans(n)
  int n;
{
  int  ocol, opt, col, pt, v1, m1, v2, m2, i;
  struct _Line *lp;
  char s[2];

  if (n > 0){
    ocol = 0;
    opt  = _mb_point;
    lp   =  CLine;
    while (n-- > 0){
      if (CLine == Line.next){
	lp   = CLine;
	opt  = 0;
      } else {
	lp   = CLine->prev;
	opt  = lp->idx;
      }
      if (mb_isbol())
	break;
      if (mb_iseol()){
	mb2_backwc(1);
	if (mb_isbol()){
	  mb2_forwc(1);
	  break;
	}
      }
      chsize2(&_mb_buf[_mb_point-1], &v1, &m1);
      for (i = m1-1; i >= 0; i--)
	s[i] = _mb_buf[--_mb_point];
      chsize(&_mb_buf[_mb_gapend], &v2, &m2);
      for (i = 0; i < m2; i++)
	_mb_buf[_mb_point++] = _mb_buf[_mb_gapend++];
      for (i = 0; i < m1; i++)
	_mb_buf[--_mb_gapend] = s[m1-i-1];

      if (mb_iseol())
	break;
      mb2_forwc(1);
    }
    if (mb_fixlines(ocol, lp, opt, &col, &pt) == 0)
      mb_refresh(ocol, opt);
    else 
      mb_redisplay();
  } else if (n < 0){
    while (n++ < 0){
      if (mb_isbol())
	break;
      if (mb_iseol()){
	mb2_backwc(1);
	if (mb_isbol()){
	  mb2_forwc(1);
	  break;
	}
      }
      chsize2(&_mb_buf[_mb_point-1], &v1, &m1);
      for (i = m1-1; i >= 0; i--)
	s[i] = _mb_buf[--_mb_point];
      chsize(&_mb_buf[_mb_gapend], &v2, &m2);
      for (i = 0; i < m2; i++)
	_mb_buf[_mb_point++] = _mb_buf[_mb_gapend++];
      for (i = 0; i < m1; i++)
	_mb_buf[--_mb_gapend] = s[m1-i-1];
      
      if (mb_isbol())
	break;
      mb2_backwc(1);
    }
    if (mb_fixlines(0, Line.next, 0, &col, &pt) == 0)
      mb_refresh(col, pt);
    else 
      mb_redisplay();
  }
  return mb_point();
}
static int
mb_matchparen(n, opar, cpar)
  int  n;
  char opar, cpar;
{
  int  i, dep, dep2, instr, oinstr, point, v, m;
  int  col, ocol, pt, opt, red, match, on;
  struct _Line  *clp, *dlp, *lp;

  if (n <= 0)
    return mb_point();

  instr = 0;
  for (i = _mb_prompt; i < _mb_point; i++){
    if (_mb_buf[i] == '"'){
      if (instr == 0)
	instr = 1;
      else 
	instr = 0;
    } else if (_mb_buf[i] == '\\')
      i++;
  }
  oinstr = instr;

  on    = n;
  match = 0;
  red   = 0;
  ocol = _mb_ccol;
  opt  = _mb_point;
  lp   = CLine;
  clp = dlp = CLine;
  while (n-- > 0){
    clp = CLine;
    point = _mb_point;
    mb_putchar(cpar);
    mb_fixlines(ocol, lp, opt, &col, &pt);
    if (clp != CLine){
      red = 1;
      col = _mb_ccol-1;
    }
    clp = CLine;
    if (red == 0){
      mb_refresh(col, pt);
      dlp = clp;
    }
    dep  = 0;
    dep2 = 0;
    while (point >= _mb_prompt){
      if (instr == 0){
	if (_mb_buf[point] == '"'){
	  if ((point > _mb_prompt) && (_mb_buf[point-1] == '\\'))
	    point--;
	  else {
	    instr = 1;
	    dep2 = dep;
	  }
	} else if ((_mb_buf[point] == cpar) && (oinstr == 0)){
	  dep++;
	} else if ((_mb_buf[point] == opar) && (oinstr == 0)){
	  if (--dep == 0){
	    match++;
	    if (dlp != clp){
	      dlp = clp;
	      red = 1;
	      _mb_ccol = mb_col(clp, point);
	      mb_refresh(0, clp->idx);
	    } else 
	      ttmove(_mb_crow, mb_col(clp, point));
	    ttflush();
	    ttwait();
	    break;
	  }
	}
      } else {
	if (_mb_buf[point] == '"'){
	  if ((point > _mb_prompt) && (_mb_buf[point-1] == '\\'))
	    point--;
	  else {
	    instr = 0;
	    dep = dep2;
	  }
	} else if ((_mb_buf[point] == cpar) && (oinstr == 1)){
	  dep++;
	} else if ((_mb_buf[point] == opar) && (oinstr == 1)){
	  if (--dep == 0){
	    match++;
	    if (dlp != clp){
	      dlp = clp;
	      red = 1;
	      _mb_ccol = mb_col(clp, point);
	      mb_refresh(0, clp->idx);
	    } else 
	      ttmove(_mb_crow, mb_col(clp, point));
	    ttflush();
	    ttwait();
	    break;
	  }
	}
      }
      chsize2(&_mb_buf[point], &v, &m);
      if (point == clp->idx)
	clp = clp->prev; 
      point -= m;
    }
  }
  if (red == 1){
    mb_fixlines(ocol, lp, opt, NULL, NULL);
    mb_redisplay();
  } else 
    ttmove(_mb_crow, _mb_ccol);
  if (match != on)
    ttbeep();
  return mb_point();
}
static int 
mb_col(lp, pt)
  struct _Line *lp;
  int  pt;
{
  int  col, point, v, m;

  col = 0;
  for (point = lp->idx; point < pt; ){
    chsize(&_mb_buf[point], &v, &m);
    col   += v;
    point += m;
  }
  return col;
}
static int
mb_putchar(c)
  char  c;
{
  int  i, more;
  char *new_mb_buf;
  struct _Line *lp;

  if (_mb_point == (_mb_gapend-1)){
    more = _mb_size;
    if ((new_mb_buf = malloc(_mb_size+more)) == NULL)
      return -1;
    for (i = 0; i < _mb_point; i++)
      new_mb_buf[i] = _mb_buf[i];
    for (i = _mb_gapend; i < _mb_size; i++)
      new_mb_buf[i+more] = _mb_buf[i];
    free(_mb_buf);
    _mb_buf     = new_mb_buf;
    _mb_gapend += more;
    _mb_size    = _mb_size + more;
    if (_mb_point != _mb_prompt)
      for (lp = CLine->next; lp != &Line; lp = lp->next)
	lp->idx += more;
  }
  _mb_buf[_mb_point++] = c;
  _mb_bufsize++;
  return 0;
}
static VOID
mb_move(m)
  int m;
{
  if (m > 0){
    while (m > 0){
      _mb_buf[_mb_point++] = _mb_buf[_mb_gapend++];
      --m;
    }
  } else {
    while (m < 0){
      _mb_buf[--_mb_gapend] = _mb_buf[--_mb_point];
      ++m;
    }
  }
}
static VOID
mb_movech(n)
  int n;
{
  int  v, m;

  if (n > 0){
    while (n > 0){
      chsize(&_mb_buf[_mb_point-1], &v, &m);
      while ((m--) > 0) 
	_mb_buf[_mb_point++] = _mb_buf[_mb_gapend++];
      --n;
    }
  } else {
    while (n < 0){
      chsize2(&_mb_buf[_mb_point-1], &v, &m);
      while ((m--) > 0) 
	_mb_buf[--_mb_gapend] = _mb_buf[--_mb_point];
      ++n;
    }
  }
}
static int
mb_fixlines(col, line, point, colp, ptp)
  int  col, point, *colp, *ptp;
  struct _Line *line;
{
  int    v, m, bp, ccol, opt, redraw, lno;
  struct _Line *lp0, *lp1;

  if (colp != NULL) *colp = col;
  if (ptp != NULL)  *ptp  = point; 
  ccol   = col;
  redraw = 0;
  bp     = 1;
  lno    = line->lno;
  for (;;){
    if (point == _mb_point){
      _mb_ccol = col;
      CLine    = line;
      point    = _mb_gapend;
      bp = 0;
    }
    if (point == _mb_size){
      /* ASSRT: line != &Line */
      goto End;
    }
    
    opt   = point;
    chsize(&_mb_buf[point], &v, &m);
    col   += v;
    ccol  += v;
    point += m;
    
    if (col >= (ncol-1)-1){
      if (line->next == &Line){
	if ((lp0 = (struct _Line*) malloc(sizeof (struct _Line))) == NULL)
	  return -1;
	line->next = lp0;
	lp0->next  = &Line;
	Line.prev  = lp0;
	lp0->prev  = line;
      } 
      line      = line->next;
      line->lno = ++lno;
      line->idx = opt;
      if (bp == 1){
	if (colp != NULL) *colp = 0;
	if (ptp != NULL)  *ptp  = line->idx;
	redraw = 1;
      }
      col  = v;
    }
  }

End:
  for (lp0 = line->next; lp0 != &Line; lp0 = lp1){
    lp1 = lp0->next;
    free(lp0);
  }
  line->next = &Line;
  Line.prev  = line;
  if ((_mb_ccol == (ncol-1)-2) && (_mb_gapend < _mb_size)){
    CLine = CLine->next;
    _mb_ccol = 0;
    if (colp != NULL) *colp = 0;
    if (ptp != NULL)  *ptp  = CLine->idx;
    redraw = 1;
  } else
  if ((_mb_ccol == 0) && (_mb_gapend == _mb_size)){
    lp0 = CLine;
    CLine = CLine->prev;
    free(lp0);
    CLine->next = &Line;
    Line.prev   = CLine;
    mb_fixlines(0, CLine, CLine->idx, colp, ptp);
    redraw = 1;
  } 
  return redraw;
}
static VOID
mb_redisplay()
{
  mb_refresh(0, CLine->idx);
}
static VOID
mb_refresh(col, idx)
  int   col, idx;
{
  int  v, m, limit;

  limit = (ncol-1)-2;
  ttmove(_mb_crow, col);
  for ( ; idx < _mb_point; ){
    if (col >= limit)
      break;
    chsize(&_mb_buf[idx], &v, &m);
    while (m-- > 0)
      eputc(_mb_buf[idx++]);
    col += v;
  }
  for (idx = _mb_gapend; idx < _mb_size; ){
    if (col >= limit)
      break;
    chsize(&_mb_buf[idx], &v, &m);
    while (m-- > 0)
      eputc(_mb_buf[idx++]);
    col += v;
  }
  if (CLine->next != &Line){
    for ( ; col <= (ncol-1); col++)
      eputc('\\');
  } else 
    tteeol();
  ttmove(_mb_crow, _mb_ccol);
  mb_flush();
}
static VOID
mb_flush()
{
  ttflush();
}
#ifdef CANNA
static int
mb_henkan( c )
int c;
{
    int ilen;
    int i;
    static char kakutei[CANBUF];
    static int oldlength, oldrevPos;
    int  col, pt;
    struct _Line *lp;
    lp = CLine;

    ilen = jrKanjiString(0, c, kakutei, CANBUF, &ks);

    if (oldrevPos == 0)
	oldrevPos = mb_point();
    if (oldlength == 0)
	oldlength = mb_point();    

    if (ilen < 0)
	return FALSE;
    if (ks.info & KanjiModeInfo){
	jrKanjiControl(0,KC_QUERYMODE, mbMode);
    }
	
    if ( ilen > 0) {
	mb2_gotochar(oldlength);
	while (mb_point() > oldrevPos)
	    mb2_erasec(1);
	mb_fixlines(0, Line.next, 0, &col, &pt);
	if (lp == CLine)
	    mb_refresh(_mb_ccol, _mb_point); 
	else 
	    mb_redisplay();
	mb_insertstr(kakutei);
	oldlength = oldrevPos = 0;
    }
    if ( ks.length > 0) {
	mb2_gotochar(oldlength);
	while (mb_point() > oldrevPos)
	    mb2_erasec(1);
	mb_fixlines(0, Line.next, 0, &col, &pt);
	if (lp == CLine)
	    mb_refresh(_mb_ccol, _mb_point); 
	else 
	    mb_redisplay();
	oldrevPos = mb_point();
	mb_insert( 1, '|');
	mb_insertstr(ks.echoStr);
	mb_insert( 1, '|');
	oldlength = mb_point();
	mb_backwc(1);
    }
    else if ( ks.length == 0 && ilen == 0) {
	mb2_gotochar(oldlength);
	while (mb_point() > oldrevPos)
	    mb2_erasec(1);
	mb_fixlines(0, Line.next, 0, &col, &pt);
	if (lp == CLine)
	    mb_refresh(_mb_ccol, _mb_point); 
	else 
	    mb_redisplay();
	oldlength = oldrevPos = 0;
    }

    return TRUE;
}
#endif /* CANNA */

static char*
sformat(fp, ap)
  register char *fp;
  register va_list *ap;
{
  register char *s;
  register int  n;
  int   c, idx;
  char	kname[NKNAME];
  char	*keyname();
  char	*cp;

  n = ncol + 1;
  if ((s = malloc(n)) == NULL)
    return NULL;
  idx = 0;
  while ((c = *fp++) != '\0'){
    if (c != '%')
      idx = s_put_c(s, idx, n, c);
    else {
      c = *fp++;
      switch (c){
      case 'c':
	(VOID) keyname(kname, va_arg(*ap, int));
	idx = s_put_s(s, idx, n, kname);
	break;
      case 'k':
	cp = kname;
	for(c=0; c < key.k_count; c++) {
	  cp = keyname(cp, key.k_chars[c]);
	  *cp++ = ' ';
	}
	*--cp = '\0';
	idx = s_put_s(s, idx, n, kname);
	break;
      case 'd':
	idx = s_put_i(s, idx, n, va_arg(*ap, int), 10);
	break;
      case 'o':
	idx = s_put_i(s, idx, n, va_arg(*ap, int), 8);
	break;
      case 's':
	idx = s_put_s(s, idx, n, va_arg(*ap, char *));
	break;
      case 'l':/* explicit longword */
	c = *fp++;
	switch(c) {
	case 'd':
	  idx = s_put_l(s, idx, n, (long)va_arg(*ap, long), 10);
	  break;
	default:
	  idx = s_put_c(s, idx, n, c);
	  break;
	}
	break;
      default:
	idx = s_put_c(s, idx, n, c);
      }
    }
  }
  s[idx] = '\0';
  return s;
}

static int
s_put_i(p, idx, n, i, r)
  register char *p;
  register int idx, n;
  register int i;
  register int r;
{
  register int	q;
  
  if(i<0) {
    idx = s_put_c(p, idx, n, '-');
    i = -i;
  }
  if ((q=i/r) != 0)
    idx = s_put_i(p, idx, n, q, r);
  return s_put_c(p, idx, n, i%r+'0');
}

static int
s_put_l(p, idx, n, l, r)
  register char *p;
  register int  idx, n;
  register long l;
  register int  r;
{
  register long	q;
  
  if(l < 0) {
    idx = s_put_c(p, idx, n, '-');
    l = -l;
  }
  if ((q=l/r) != 0)
    idx = s_put_l(p, idx, n, q, r);
  return s_put_c(p, idx, n, (int)(l%r)+'0');
}

static int
s_put_s(p, idx, n,  s)
  register char *p, *s;
  register int idx, n;
{
  register int	c;

  while ((c = *s++) != '\0')
    idx = s_put_c(p, idx, n, c);
  return idx;
}

static int
s_put_c(p, idx, n, c)
  register char *p;
  register int  idx, n;
  register char c;
{
  epresf	= TRUE;

  if (idx < n) {
    if (ISCTRL(c)) {
      idx = s_put_c(p, idx, n, '^');
      c = CCHR(c);
    }
#ifdef	KANJI
#ifdef HANKANA
    {
      static int c1=0;
      
      if (ISKANJI(c)) {
	if (c1==0) c1=1;
	else c1=0;
      } else c1=0;
      if (ISHANKANA(c) && (c1 == 1))
	idx--;
    }
#endif  /* HANKANA */
    p[idx++] = c;
#else	/* NOT KANJI */
    p[idx++] = c;
#endif	/* KANJI */
  }
  return idx;
}

static VOID
chsize(s, visu, mem)
  register char *s;
  register int  *visu, *mem;
{
  if (ISCTRL(*s)){
    *visu = 2;
    *mem  = 1;
#ifdef	KANJI
  } else if (ISKANJI(*s)){
    *mem  = 2;
#ifdef	HOJO_KANJI
    if (ISHOJO(*s)) {
      *mem = 3;
      *visu = 2;
    } else
#endif	/* HOJO_KANJI */
#ifdef	HANKANA
    if (ISHANKANA(*s))
      *visu = 1;
    else 
#endif  /* HANKANA */
    *visu = 2;
#endif	/* KANJI */
  } else {
    *visu = 1;
    *mem  = 1;
  }
}

static VOID
chsize2(s, visu, mem)
  register char *s;
  register int  *visu, *mem;
{
  if (ISCTRL(*s)){
    *visu = 2;
    *mem  = 1;
#ifdef	KANJI
  } else if (ISKANJI(*s)){
    *mem  = 2;
#ifdef	HOJO_KANJI
    if (ISHOJO(*(s-2)) && ISKANJI(*(s-1))) {
      *mem = 3;
      *visu = 2;
    } else
#endif	/* HOJO_KANJI */
#ifdef	HANKANA
    if (ISHANKANA(*(s-1)))
      *visu = 1;
    else 
#endif  /* HANKANA */
    *visu = 2;
#endif	/* KANJI */
  } else {
    *visu = 1;
    *mem  = 1;
  }
}

static VOID
mb_hist_save(hist_buf, buf)
char *hist_buf[];
char *buf;
{
    int i;
    if (hist_buf[MB_NHISTS] != NULL)
	free(hist_buf[MB_NHISTS]);
    /* rotate history */
    for (i = MB_NHISTS; i > 1; i--)
	hist_buf[i] = hist_buf[i-1];
    /* and insert new history to head */
    hist_buf[1] = malloc(strlen(buf)+1);
    strcpy(hist_buf[1], buf);
}
#else   /* NOT MINIBUF_EDIT */
static int veread_del_char ();
static int veread_complete ();

static int
veread(fp, buf, nbuf, flag, ap)
    char    *fp;
    char    *buf;
    int    nbuf;
    int    flag;
    va_list *ap;
{
    int    cpos;
    int    c;

#ifdef	ADDFUNC	/* 91.01.16  by S.Yoshida */
    /* If an extra argument exists, use it.			*/
    /* This is a very easy way of not getting an argument from	*/
    /* the keyboard.	*/
    if(earg_exist)
      {
	strcpy(buf, earg_text);
	earg_exist = FALSE;
        edef_text = NULL;
	return (TRUE);
      }
#endif	/* ADDFUNC */
#ifndef NO_MACRO
    if(inmacro)
      {
        bcopy (maclcur->l_text, buf, maclcur->l_used);
	buf[maclcur->l_used] = '\0';
	maclcur = maclcur->l_fp;
#ifdef EXTD_DIR
        edef_text = NULL;
#endif
	return (TRUE);
      }
#endif
    if ((flag & EFNEW) || ttrow != nrow - 1)
      {
	ttcolor(CTEXT);
	ttmove(nrow - 1, 0);
	epresf = TRUE;
      }
    else
      eputc(' ');
    eformat(fp, ap);
    tteeol();

#ifdef EXTD_DIR
    if (edef_text) {
      strcpy(buf, edef_text);
      edef_text = NULL;
      eputs(buf);
      cpos = strlen(buf);
    } else 
#endif
    {
      buf[0] = '\0';
      cpos = 0;
    }
    for (;;)
      {
	ttflush();
        c = getkey(FALSE);
	tteeol();
        switch (c)
          {
          case ' ':
          case CCHR('I'):
            if (flag & EFAUTO)
	      {
#if 0    /* 90.12.10    Sawayanagi Yosirou */
		if (flag & EFFILE)
		  {
		    char    *p;

		    p = adjustname (buf);
		    while (cpos > 0)
		      cpos = veread_del_char (buf, cpos);
		    strcpy (buf, p);
		    eputs (buf);
		    cpos = strlen (buf);
		  }
#endif
		cpos = veread_complete (buf, cpos, c, flag);
	      }
	    else if (cpos < nbuf - 1)
	      {
		buf[cpos++] = (char) c;
		buf[cpos] = '\0';
		eputc((char) c);
	      }
	    break;
	  case CCHR('J'):
	    c = CCHR('M');	/* and continue		*/
	  case CCHR('M'):	/* Return, done.	*/
	    if (flag & EFFUNC)
	      {
		int    matchnum;

		matchnum = complete (buf, flag);
		eputs (&buf[cpos]);
		tteeol();
		cpos = strlen (buf);
		if (matchnum != COMPLT_SOLE
			&& matchnum != COMPLT_NOT_UNIQUE)
		  {
		    /* complete() will be called again, but i don't mind it */
		    cpos = veread_complete (buf, cpos, (int)CCHR('I'), flag);
		    break;
		  }
	      }
	    complete_del_list ();
	    if (flag & EFCR)
	      {
		ttputc(CCHR('M'));
		ttflush ();
	      }
#ifndef NO_MACRO
	    if (macrodef)
	      {
		LINE *lp;

		if((lp = lalloc(cpos)) == NULL)
		  return FALSE;
		lp->l_fp = maclcur->l_fp;
		maclcur->l_fp = lp;
		lp->l_bp = maclcur;
		maclcur = lp;
		bcopy(buf, lp->l_text, cpos);
	      }
#endif
	    return ((buf[0] == '\0') ? FALSE : TRUE);
	  case CCHR('G'):		/* Bell, abort.		*/
	  case CCHR('['):
	    (VOID) ctrlg(FFRAND, 0);
	    ttflush();
	    complete_del_list ();
	    return (ABORT);
	  case CCHR('N'):
	    complete_scroll_down ();
	    break;
	  case CCHR('P'):
	    complete_scroll_up ();
	    break;
	  case CCHR('H'):
	  case CCHR('?'):	/* Rubout, erase.	*/
	    cpos = veread_del_char (buf, cpos);
	    break;
	  case CCHR('X'):	/* C-X			*/
	  case CCHR('U'):	/* C-U, kill line.	*/
	    while (cpos > 0)
	      cpos = veread_del_char (buf, cpos);
	    break;
	  case CCHR('W'):	/* C-W, kill to beginning of */
				/* previous word	*/
				/* back up to first word character or beginning */
	    while ((cpos > 0) && !ISWORD(buf[cpos - 1]))
	      cpos = veread_del_char (buf, cpos);
	    while ((cpos > 0) && ISWORD(buf[cpos - 1]))
	      cpos = veread_del_char (buf, cpos);
	    break;
	  case CCHR('\\'):
	  case CCHR('Q'):	/* C-Q, quote next	*/
	    c = getkey(FALSE);	/* and continue		*/
          default:		/* All the rest.	*/
	    if (cpos < nbuf - 1)
	      {
		buf[cpos++] = (char) c;
		buf[cpos] = '\0';
		eputc((char) c);
	      }
	  }
      }
}

static int
veread_del_char (buf, cpos)
    char    *buf;
    int    cpos;
{
    if (cpos <= 0)
      return (0);
    ttputc('\b');
    ttputc(' ');
    ttputc('\b');
    --ttcol;
    --cpos;
    if (ISCTRL(buf[cpos]) != FALSE)
      {
	ttputc('\b');
	ttputc(' ');
	ttputc('\b');
	--ttcol;
      }
#ifdef	KANJI	/* 90.01.29  by S.Yoshida */
    else if (ISKANJI(buf[cpos]))
      {
#ifdef HANKANA  /* 92.11.21  by S.Sasaki */
	if (!ISHANKANA(buf[--cpos])) {
	    ttputc('\b');
	    ttputc(' ');
	    ttputc('\b');
	    --ttcol;
	}
#else  /* not HANKANA */
	ttputc('\b');
	ttputc(' ');
	ttputc('\b');
	--ttcol;
	--cpos;
#endif  /* HANKANA */
      }
#endif	/* KANJI */
    buf[cpos] = '\0';
    return (cpos);
}

static int
veread_complete (buf, cpos, c, flag)
    char    *buf;
    int    cpos;
    int    c;
    int    flag;
{
    int    matchnum;
    int    i;
    int    wflag;
    int    cur_ttrow;
    int    cur_ttcol;

    wflag = (c == ' ');
    if (wflag)
      {
	buf[cpos] = ' ';
	buf[cpos + 1] = '\0';
	if (complete (buf, flag) == COMPLT_NO_MATCH)
	  buf[cpos] = '\0';
	else
	  {
	    buf[cpos + 1] = '\0';
	    eputs (&buf[cpos]);
	    tteeol();
	    ++cpos;
	    return (cpos);
	  }
      }
    matchnum = complete (buf, flag);
    if (buf[cpos] == '\0')
      {
	if (wflag)
	  {
	    if (matchnum == COMPLT_AMBIGUOUS
	        || matchnum == COMPLT_NOT_UNIQUE)
	      complete_list_names (buf, flag);
	    else if (matchnum == COMPLT_NO_MATCH)
	      {
		cur_ttrow = ttrow;
		cur_ttcol = ttcol;
		eputs (complete_message (matchnum));
		tteeol();
		ttmove (cur_ttrow, cur_ttcol);
	      }
	  }
	else
	  {
	    if (matchnum == COMPLT_AMBIGUOUS)
	      complete_list_names (buf, flag);
	    else
	      {
		cur_ttrow = ttrow;
		cur_ttcol = ttcol;
		eputs (complete_message (matchnum));
		tteeol();
		ttmove (cur_ttrow, cur_ttcol);
	      }
	  }
      }
    else
      {
	if (wflag)
	  {
	    for (i = cpos + 1; buf[i] != '\0'; i++)
	      {
	        if (i > cpos && ! ISWORD(buf[i - 1]))
	          {
		    buf[i] = '\0';
		    break;
	          }
	      }
	  }
	eputs (&buf[cpos]);
	tteeol();
	cpos = strlen (buf);
      }
    return (cpos);
}
#endif  /* MINIBUF_EDIT */
#else	/* NOT NEW_COMPLETE */
static int veread(fp, buf, nbuf, flag, ap) char *fp; char *buf; va_list *ap; {
	register int	cpos;
	register int	i;
	register int	c;

#ifdef	ADDFUNC	/* 91.01.16  by S.Yoshida */
    /* If extra argument is exist, use it.			*/
    /* This is very easy way to not get argument from keyboard.	*/
    if(earg_exist)
      {
	strcpy(buf, earg_text);
	earg_exist = FALSE;
	return (TRUE);
      }
#endif	/* ADDFUNC */
#ifndef NO_MACRO
	if(inmacro) {
	    bcopy(maclcur->l_text, buf, maclcur->l_used);
	    buf[maclcur->l_used] = '\0';
	    maclcur = maclcur->l_fp;
	    return TRUE;
	}
#endif
	cpos = 0;
	if ((flag&EFNEW)!=0 || ttrow!=nrow-1) {
		ttcolor(CTEXT);
		ttmove(nrow-1, 0);
		epresf = TRUE;
	} else
		eputc(' ');
	eformat(fp, ap);
	tteeol();
	ttflush();
#ifdef FEPCTRL	/* 90.11.26  by K.Takano */
	fepmode_off();
#endif
	for (;;) {
		c = getkey(FALSE);
		if ((flag&EFAUTO) != 0 && (c == ' ' || c == CCHR('I'))) {
			cpos += complt(flag, c, buf, cpos);
			continue;
		}
		switch (c) {
		    case CCHR('J'):
			c = CCHR('M');		/* and continue		*/
		    case CCHR('M'):		/* Return, done.	*/
			if ((flag&EFFUNC) != 0) {
				if ((i = complt(flag, c, buf, cpos)) == 0)
					continue;
				if (i > 0) cpos += i;
			}
			buf[cpos] = '\0';
			if ((flag&EFCR) != 0) {
				ttputc(CCHR('M'));
				ttflush();
			}
#ifndef NO_MACRO
			if(macrodef) {
			    LINE *lp;

			    if((lp = lalloc(cpos)) == NULL) return FALSE;
			    lp->l_fp = maclcur->l_fp;
			    maclcur->l_fp = lp;
			    lp->l_bp = maclcur;
			    maclcur = lp;
			    bcopy(buf, lp->l_text, cpos);
			}
#endif
			goto done;

		    case CCHR('G'):		/* Bell, abort.		*/
		    case CCHR('['):
			eputc(CCHR('G'));
			(VOID) ctrlg(FFRAND, 0);
			ttflush();
			return ABORT;

		    case CCHR('H'):
		    case CCHR('?'):		/* Rubout, erase.	*/
			if (cpos != 0) {
				ttputc('\b');
				ttputc(' ');
				ttputc('\b');
				--ttcol;
				if (ISCTRL(buf[--cpos]) != FALSE) {
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
				}
#ifdef	KANJI	/* 90.01.29  by S.Yoshida */
				else if (ISKANJI(buf[cpos])) {
#ifdef HANKANA  /* 92.11.21  by S.Sasaki  */
					if (!ISHANKANA(buf[--cpos])) {
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
					}

#else  /* HANKANA */
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
					--cpos;
#endif  /* HANKANA */
				}
#endif	/* KANJI */
				ttflush();
			}
			break;

		    case CCHR('X'):		/* C-X			*/
		    case CCHR('U'):		/* C-U, kill line.	*/
			while (cpos != 0) {
				ttputc('\b');
				ttputc(' ');
				ttputc('\b');
				--ttcol;
				if (ISCTRL(buf[--cpos]) != FALSE) {
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
				}
#ifdef	KANJI	/* 90.01.29  by S.Yoshida */
				else if (ISKANJI(buf[cpos])) {
#ifdef HANKANA  /* 92.11.21  by S.Sasaki  */
					if (!ISHANKANA(buf[--cpos])) {
					    ttputc('\b');
					    ttputc(' ');
					    ttputc('\b');
					    --ttcol;
					}
#else  /* HANKANA */
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
					--cpos;
#endif  /* HANKANA */
				}
#endif	/* KANJI */
			}
			ttflush();
			break;

		    case CCHR('W'):		/* C-W, kill to beginning of */
						/* previous word	*/
			/* back up to first word character or beginning */
			while ((cpos > 0) && !ISWORD(buf[cpos - 1])) {
				ttputc('\b');
				ttputc(' ');
				ttputc('\b');
				--ttcol;
				if (ISCTRL(buf[--cpos]) != FALSE) {
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
				}
#ifdef	KANJI	/* 90.01.29  by S.Yoshida */
				else if (ISKANJI(buf[cpos])) {
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
					--cpos;
				}
#endif	/* KANJI */
			}
			while ((cpos > 0) && ISWORD(buf[cpos - 1])) {
				ttputc('\b');
				ttputc(' ');
				ttputc('\b');
				--ttcol;
				if (ISCTRL(buf[--cpos]) != FALSE) {
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
				}
#ifdef	KANJI	/* 90.01.29  by S.Yoshida */
				else if (ISKANJI(buf[cpos])) {
#ifdef HANKANA  /* 92.11.21  by S.Sasaki  */
					if (ISHANKANA(buf[--cpos])) {
					    ttputc('\b');
					    ttputc(' ');
					    ttputc('\b');
					    --ttcol;
					}
#else  /* not HANKANA */
					ttputc('\b');
					ttputc(' ');
					ttputc('\b');
					--ttcol;
					--cpos;
#endif  /* HANKANA */
				}
#endif	/* KANJI */
			}
			ttflush();
			break;

		    case CCHR('\\'):
		    case CCHR('Q'):		/* C-Q, quote next	*/
			c = getkey(FALSE);	/* and continue		*/
		    default:			/* All the rest.	*/
			if (cpos < nbuf-1) {
				buf[cpos++] = (char) c;
				eputc((char) c);
				ttflush();
			}
		}
	}
done:	return buf[0] != '\0';
}

/*
 * do completion on a list of objects.
 */
static int complt(flags, c, buf, cpos)
register char *buf;
register int cpos;
{
	register LIST	*lh, *lh2;
	int		i, nxtra;
	int		nhits, bxtra;
	int		wflag = FALSE;
	int		msglen, nshown;
	char		*msg;

	if ((flags&EFFUNC) != 0) {
	    buf[cpos] = '\0';
	    i = complete_function(buf, c);
	    if(i>0) {
		eputs(&buf[cpos]);
		ttflush();
		return i;
	    }
	    switch(i) {
		case -3:
		    msg = " [Ambiguous]";
		    break;
		case -2:
		    i=0;
		    msg = " [No match]";
		    break;
		case -1:
		case 0:
		    return i;
		default:
		    msg = " [Internal error]";
		    break;
	    }
#ifndef NO_FILECOMP	/* 90.04.04  by K.Maeda */
	} else if ((flags&EFFILE)!=0) {
	    if (c != '\t' && c != ' ') panic("broken complt call: c");
	    buf[cpos] = '\0';
	    i = complete_filename(buf, cpos, c);
	    if(i>0) {
		eputs(&buf[cpos]);
		ttflush();
		return i;
	    }
	    switch(i) {
		case -3:
		    msg = " [Ambiguous]";
		    break;
		case -2:	/* no match */
#ifdef	HUMAN68K	/* 90.11.15    Sawayanagi Yosirou */
		    msg = " [No match]";
		    break;
#else	/* NOT HUMAN68K */
		    i=0;
#endif	/* HUMAN68K */
		case -1:	/* single match */
		case 0:
		    return i;
		default:
		    msg = " [Internal error]";
		    break;
	    }
#endif	/* NO_FILECOMP */
	} else {
	    if ((flags&EFBUF) != 0) lh = &(bheadp->b_list);
	    else panic("broken complt call: flags");

	    if (c == ' ') wflag = TRUE;
	    else if (c != '\t' && c != CCHR('M')) panic("broken complt call: c");

	    nhits = 0;
	    nxtra = HUGE;

	    while (lh != NULL) {
		for (i=0; i<cpos; ++i) {
			if (buf[i] != lh->l_name[i])
				break;
		}
		if (i == cpos) {
			if (nhits == 0)
				lh2 = lh;
			++nhits;
			if (lh->l_name[i] == '\0') nxtra = -1;
			else {
				bxtra = getxtra(lh, lh2, cpos, wflag);
				if (bxtra < nxtra) nxtra = bxtra;
				lh2 = lh;
			}
		}
		lh = lh->l_next;
	    }
	    if (nhits == 0)
		msg = " [No match]";
	    else if (nhits > 1 && nxtra == 0)
		msg = " [Ambiguous]";
	    else {		/* Got a match, do it to it */
		/*
		 * Being lazy - ought to check length, but all things
		 * autocompleted have known types/lengths.
		 */
		if (nxtra < 0 && nhits > 1 && c == ' ') nxtra = 1;
		for (i = 0; i < nxtra; ++i) {
			buf[cpos] = lh2->l_name[cpos];
			eputc(buf[cpos++]);
		}
		ttflush();
		if (nxtra < 0 && c != CCHR('M')) return 0;
		return nxtra;
	    }
	}
	/* Set up backspaces, etc., being mindful of echo line limit */
	msglen = strlen(msg);
	nshown = (ttcol + msglen + 2 > ncol) ?
			ncol - ttcol - 2 : msglen;
	eputs(msg);
	ttcol -= (i = nshown);		/* update ttcol!		*/
	while (i--)			/* move back before msg		*/
		ttputc('\b');
	ttflush();			/* display to user		*/
	i = nshown;
	while (i--)			/* blank out	on next flush	*/
		eputc(' ');
	ttcol -= (i = nshown);		/* update ttcol on BS's		*/
	while (i--)
		ttputc('\b');		/* update ttcol again!		*/
	return 0;
}

/*
 * The "lp1" and "lp2" point to list structures. The
 * "cpos" is a horizontal position in the name.
 * Return the longest block of characters that can be
 * autocompleted at this point. Sometimes the two
 * symbols are the same, but this is normal.
  */
int
getxtra(lp1, lp2, cpos, wflag) register LIST *lp1, *lp2; register int wflag; {
	register int	i;

	i = cpos;
	for (;;) {
		if (lp1->l_name[i] != lp2->l_name[i]) break;
		if (lp1->l_name[i] == '\0') break;
		++i;
		if (wflag && !ISWORD(lp1->l_name[i-1])) break;
	}
	return (i - cpos);
}
#endif	/* NEW_COMPLETE */

/*
 * Special "printf" for the echo line.
 * Each call to "ewprintf" starts a new line in the
 * echo area, and ends with an erase to end of the
 * echo line. The formatting is done by a call
 * to the standard formatting routine.
 */
/*VARARGS 0 */
#ifdef SUPPORT_ANSI
VOID
ewprintf(char *fp, ...)
{
    va_list	pvar;

#ifndef NO_MACRO
    if (inmacro)
	return;
#endif
    va_start(pvar, fp);
    ttcolor(CTEXT);
    ttmove(nrow - 1, 0);
    eformat(fp, &pvar);
    va_end(pvar);
    tteeol();
    ttflush();
    epresf = TRUE;
}
#else	/* SUPPORT_ANSI */
VOID
ewprintf(va_alist)
va_dcl
{
	va_list pvar;
	register char *fp;

#ifndef NO_MACRO
	if(inmacro) return;
#endif
	va_start(pvar);
	fp = va_arg(pvar, char *);
	ttcolor(CTEXT);
	ttmove(nrow-1, 0);
	eformat(fp, &pvar);
	va_end(pvar);
	tteeol();
	ttflush();
	epresf = TRUE;
}
#endif	/* SUPPORT_ANSI */

/*
 * Printf style formatting. This is
 * called by both "ewprintf" and "ereply" to provide
 * formatting services to their clients. The move to the
 * start of the echo line, and the erase to the end of
 * the echo line, is done by the caller.
 * Note: %c works, and prints the "name" of the character.
 * %k prints the name of a key (and takes no arguments).
 */
static VOID
eformat(fp, ap)
register char *fp;
register va_list *ap;
{
	register int c;
	char	kname[NKNAME];
	char	*keyname();
	char	*cp;

	while ((c = *fp++) != '\0') {
		if (c != '%')
			eputc(c);
		else {
			c = *fp++;
			switch (c) {
			case 'c':
				(VOID) keyname(kname, va_arg(*ap, int));
				eputs(kname);
				break;

			case 'k':
				cp = kname;
				for(c=0; c < key.k_count; c++) {
				    cp = keyname(cp, key.k_chars[c]);
				    *cp++ = ' ';
				}
				*--cp = '\0';
				eputs(kname);
				break;

			case 'd':
				eputi(va_arg(*ap, int), 10);
				break;

			case 'o':
				eputi(va_arg(*ap, int), 8);
				break;

			case 's':
				eputs(va_arg(*ap, char *));
				break;

			case 'l':/* explicit longword */
				c = *fp++;
				switch(c) {
				case 'd':
					eputl((long)va_arg(*ap, long), 10);
					break;
				default:
					eputc(c);
					break;
				}
				break;

			default:
				eputc(c);
			}
		}
	}
}

/*
 * Put integer, in radix "r".
 */
static VOID
eputi(i, r)
register int i;
register int r;
{
	register int	q;

	if(i<0) {
	    eputc('-');
	    i = -i;
	}
	if ((q=i/r) != 0)
		eputi(q, r);
	eputc(i%r+'0');
}

/*
 * Put long, in radix "r".
 */
static VOID
eputl(l, r)
register long l;
register int  r;
{
	register long	q;

	if(l < 0) {
	    eputc('-');
	    l = -l;
	}
	if ((q=l/r) != 0)
		eputl(q, r);
	eputc((int)(l%r)+'0');
}

/*
 * Put string.
 */
static VOID
eputs(s)
register char *s;
{
	register int	c;

	while ((c = *s++) != '\0')
		eputc(c);
}

/*
 * Put character. Watch for
 * control characters, and for the line
 * getting too long.
 */
static VOID
eputc(c)
register char c;
{
    epresf	= TRUE;
#ifdef  MINIBUF_EDIT
        if (ttcol <= (ncol-1)-1) 
#else
	if (ttcol+2 < ncol) 
#endif
	  {
		if (ISCTRL(c)) {
			eputc('^');
			c = CCHR(c);
		}
#ifdef	KANJI	/* 90.01.29  by S.Yoshida */
#ifdef	SS_SUPPORT /* 92.11.21  by S.Sasaki */
		{
		    static int c1=0;

		    if (ISKANJI(c)) {
#ifdef	HOJO_KANJI
			if (ISHOJO(c)) {
			    c1 = 2;
			    ttcol--;
			} else
#endif
			if (c1==0) c1=1;
			else c1--;
		    } else c1=0;
#ifdef	HANKANA
		    if (ISHANKANA(c) && c1 == 1)
		        ttcol--;
#endif
		}
#endif  /* SS_SUPPORT */
		kttputc(c);
#else	/* NOT KANJI */
		ttputc(c);
#endif	/* KANJI */
		++ttcol;
	}
}

#ifndef	NEW_COMPLETE	/* 90.12.10    Sawayanagi Yosirou */
#ifndef NO_FILECOMP	/* 90.04.04  by K.Maeda */
int
complete_filename(buf, cpos, c)
char *buf;
int cpos, c;
{
	register int nhits, i, j;
	char *files, *try, *hit;
	int nxtra, wflag, bxtra, res;

	if ((nhits=fffiles(buf, &files)) < 0)
		return -4;	/* error */
	if (nhits == 0) {
		res = -2;	/* no match */
		goto end;
	}

	if (c == ' ') wflag = TRUE;
		else  wflag = FALSE;
	nxtra = HUGE; hit = files;

	for(try=files, i=0; i<nhits; i++) {
		if (try[cpos] == '\0') nxtra = -1;
		else {
			bxtra = cpos;
			for(;;) {
				if (try[bxtra] != hit[bxtra]) break;
				if (try[bxtra] == '\0') break;
				bxtra++;
				if (wflag && !ISWORD(try[bxtra-1])) break;
			}
			if (hit[bxtra] == '\0')
				hit = try;
			bxtra -= cpos;
			if (bxtra < nxtra) nxtra = bxtra;
		}
		try += strlen(try)+1;
	}
	if (nhits > 1 && nxtra == 0) {
		res = -3;	/* ambiguous */
		goto end;
	}
	if (nxtra < 0 && nhits > 1 && c == ' ') nxtra = 1;
	if (nxtra >= 0) {
		for (i=cpos; i<cpos+nxtra; i++)
			buf[i] = hit[i];
		buf[i] = '\0';
		res = nxtra;
	} else { /* sole completion */
		for (i=cpos, j=strlen(files); i<j;) {
			buf[i] = files[i];
			i++;
			if (wflag && !ISWORD(buf[i-1]))
				break;
		}
		buf[i] = '\0';
		res = i-cpos;
	}
end:
	free(files);
	return res;
}
#endif	/* NO_FILECOMP */
#endif	/* NEW_COMPLETE */