File: ewipe

package info (click to toggle)
ewipe 1.2.0-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 356 kB
  • ctags: 65
  • sloc: tcl: 5,289; makefile: 44
file content (3501 lines) | stat: -rwxr-xr-x 88,111 bytes parent folder | download | duplicates (6)
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
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "--" "$@"

#                                                 #
#     EWIPE : Extended WIPE (Editor for WIPE)     #
#                                                 #
#   Copyright (C) 1997-2000  Hiromasa Sekishita   #
#                                                 #
#              This program conforms              #
#      GNU GENERAL PUBLIC LICENSE Version 2.      # 
#                                                 #

#              EWIPE Version 1.2.0                #

#                                                 #
#  If you want to use this program in the         # 
#  other directory, please change the path as     #
#  follows.                                       #
#    ex.                                          #
#     set PATH /usr/local/lib/ewipe               #
#                                                 #
#  (Japanese)                                     #
#  ewipe Τǥ쥯ȥʳȤ       #
#  ˤϡʬѹƲ         #
#   㡧                                          #
#     set PATH /usr/local/lib/ewipe               #
#                                                 #

set PATH /usr/lib/ewipe

###################################################

# setting ewipe path

if {[info exists env(EWIPEPATH)]} {
    set PATH $env(EWIPEPATH)
}
lappend auto_path $PATH

# Tcl/Tk version check

if {[info tclversion] < 7.6} {
    puts stderr "EWIPE requires Tcl7.6/Tk4.2"
    exit
}

# enabling kanji handling (Tcl 8.3 or later)
if {[info tclversion] > 8.2} {
     proc kanji {args} {}
     tk useinputmethods 1
}

# check arguments for ewipe

proc argvcheck {} {
    global version
    global filename
    global filedir
    global argc argv
    global pwd
    global Viewmode 
    global Option

    for {set i 0} {$i < $argc} {incr i} {
        set argi [lindex $argv $i]
        switch -regexp -- $argi {
            {^-(V|[Vv]ersion)$} {
                puts stderr "EWIPE Version $version"
                exit
            }
            {^-(h|help)$} {
                puts stderr "Usage: ewipe \[option\] \[filename\]"
                puts stderr ""
                puts stderr "  -v, -view                 View Mode"
                puts stderr "  -V, -Version, -version    show version\
			infomation"
		puts stderr "  -e                        for English" 
                puts stderr "  -h, -help                 show this help"
		exit
            }
            {^-(v|view)$} {
                incr i
                if {$argc <= $i} {
                    puts stderr "ewipe: option \`$argi\' requires a filename"
                    exit
                }
		set filename [lindex $argv $i]
		if {[file exists $filename] != 1} {
		    puts stderr "ewipe: Can't find \`$filename\'"
		    exit
		} else {
		    set Viewmode 1
		    set filedir [file dirname $filename]
		    if {[catch {cd $filedir}] == 1} {
			puts stderr "ewipe: no such directory \`$filedir\'"
			exit
		    }
		    set filedir [pwd]
		    cd $pwd
		    break
		}
            }
            {^-e$} {
		set Option(LANG) eng
            }
            {^-} {
                puts stderr "ewipe: unknown option \`$argi\'"
		puts stderr "Try \`ewipe -h\' or \`ewipe -help\` for more\
			information."
                exit
	    }
            default {
                set filename $argi
		if {[file isdirectory $filename] == 1} {
		    puts stderr "ewipe: \`$filename\' is a directory"
		    exit
		}
		set filedir [file dirname $filename]
		if {[catch {cd $filedir}] == 1} {
		    puts stderr "ewipe: no such directory \`$filedir\'"
		    exit
		}
		set filedir [pwd]
		cd $pwd
                break
            }
        }
    }
    readfile
}

# եɹ

proc readfile {} {
    global filename
    global docpages
    global docpagesorg
    global tcl_platform
    global Option

    set docpages {}
    set docpagesorg {}

    wm title . "EWIPE - $filename"
    if {[file exists $filename] != 1} {return}
    set file [open $filename r]
    while {![eof $file]} {
        set line [gets $file]
	if {$line == "option:"} {
	    set err 1
	    while {![eof $file]} {
		set line "[gets $file]"
		if {$line == ":end"} {set err 0; break}
		setoption $line
	    }
	} else {
	    append docpages "$line\n"
	}
    }
    close $file

    if {$Option(LANG) == "eng"} {
	set Option(lang) eng
    }
    if {[catch {llength $docpages}] == 1} {
	puts stderr "unmatched error \`\{\' or \`\}\'"
	set docpages {}
    }
    set docpagesorg $docpages

    if {$tcl_platform(platform) == "windows"} {
	set kcode {}
	catch {set kcode [kanji code $docpages]}
	if {$kcode == "EUC"} {
	    set docpages [kanji conversion EUC SJIS $docpages]
	}
    }
}

# եɤ߹

proc readdotfile {} {
    global Option
    global env
    
    # ǥե
    set Option(lang) eng        ;# ɽ (jpn:ܸ  eng:Ѹ)
    set Option(pagen) 0         ;# ڡֹɽ (for Viewer) (0:off  1:on)
    set Option(time) 0          ;# ɽ (0:off  1:on)
    set Option(timemode) 1      ;# ֤ɽˡ (0:   1:в)
    set Option(pathtype) 1      ;# ѥη (0:Хѥ  1:Хѥ)
    set Option(htmlcolor) 0     ;# HTML ϻʸ (0:Υ  1:顼)
    set Option(htmlfont) 0      ;# HTML ϻʸ礭 (0:  1:)
    set Option(viewersize) 0    ;# Viewer  (0:640x480  1:800x600)
    set Option(vredraw) 0       ;# Viewer μư (0:off  1:on)
    set Option(saveoptions) 1   ;# ץ¸ (0:off  1:on)
    set Option(background) {}   ;# ط
    set Option(bgtype) 0        ;# طʤɽˡ (0:̾  1:طʤ)
    set Option(titletype) 0     ;# ȥη (0 - 1)
    set Option(pointer) normal  ;# ݥ󥿤̾
    set Option(pointerfg) white ;# ݥ󥿤ʿ
    set Option(pointerbg) black ;# ݥ󥿤طʿ
    set Option(penleft) white   ;# Υڥο
    set Option(penright) red    ;# Υڥο
    set Option(backup) 1        ;# Хååץե (0:ʤ  1:) 
    set Option(startpage) {}
    set Option(LANG) jpn        ;#
    
    set filename "$env(HOME)/.ewipe"
    if {[file exists $filename] != 1} {return}
    
    set file [open $filename r]
    while {![eof $file]} {
        set str "[gets $file]"

        if {$str == "startpage:"} {
	    set err 1
	    while {![eof $file]} {
		set str "[gets $file]"
		if {$str == ":end"} {set err 0; break}
		append Option(startpage) "$str\n"
	    }
	    if {$err == 1} {
		set Option(startpage) {}
	    }
	} elseif {$str == "option:"} {
	    set err 1
	    while {![eof $file]} {
		set str "[gets $file]"
		if {$str == ":end"} {set err 0; break}
		setoption $str
	    }
	}
    }
    close $file
}

# ץ

proc setoption {str} {
    global Option
    set str0 [lindex $str 0]
    set str1 [lindex $str 1]
    
    switch $str0 {
	lang {
	    if {$str1 == "jpn" || $str1 == "eng"} {
		set Option(lang) $str1
	    }
	}
	pagen {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(pagen) $str1
	    }
	}
	time {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(time) $str1
	    }
	}
	timemode {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(timemode) $str1
	    }
	}
	pathtype {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(pathtype) $str1
	    }
	}
	htmlcolor {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(htmlcolor) $str1
	    }
	}
	htmlfont {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(htmlfont) $str1
	    }
	}
	viewersize {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(viewersize) $str1
	    }
	}
	vredraw {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(vredraw) $str1
	    }
	}
	vredraw {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(saveoptions) $str1
	    }
	}
	background {
	    set Option(background) $str1
	}
	bgtype {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(bgtype) $str1
	    }
	}
	titletype {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(titletype) $str1
	    }
	}
	pointer {
	    set Option(pointer) $str1
	}
	pointerfg {
	    set Option(pointerfg) $str1
	}
	pointerbg {
	    set Option(pointerbg) $str1
	}
	penleft {
	    set Option(penleft) $str1
	}
	penright {
	    set Option(penright) $str1
	}
	backup {
	    if {$str1 == 0 || $str1 == 1} {
		set Option(backup) $str1
	    }
	}
    }
}

# ӥ塼ɥɽ

proc call_viewer {mode} {
    global Option
    global Viewmode
    global cp
    
    if {$mode == "view"} {
	wm withdraw .
	if {[winfo exists .view] == 0} {
	    viewer $cp
	} else {
	    view_showcanvas $cp
	}
    } elseif {$mode == "normal"} {
	if {$Viewmode == 0} {
	    if {[winfo exists .view] == 0} {
		viewer $cp
	    } else {
		view_showcanvas $cp
	    }
	}
    } elseif {$mode == "pagen"} {
	if {[winfo exists .view] == 1} {
	    if {$Option(pagen) == 1} {
		set Option(pagen) 0
	    } else {
		set Option(pagen) 1
	    }
	    show_pagen
	}
    } elseif {$mode == "time"} {
	if {[winfo exists .view] == 1} {
	    if {$Option(time) == 1} {
		set Option(time) 0
	    } else {
		set Option(time) 1
	    }
	    toggle_time
	}
    }
}

# 

proc new {} {
    global filename
    global docpages
    global docpagesorg
    global message
    global Option
    
    if {$docpages != $docpagesorg} {
        set result [tk_dialog .d New $message(load) warning \
		0 $message(ok) $message(no)]
        if {$result == 1} {return}
    }
    set filename {}
    wm title . "EWIPE"
    init
    changelang $Option(lang)
    changesize
    if {[winfo exists .view] == 1} {
	resetview 0
    }
}

# ɹ

proc load {} {
    global filename
    global filedir
    global docpages
    global docpagesorg
    global maxp
    global cursor
    global mode
    global message
    global pwd
    global Option
    
    if {$docpages != $docpagesorg} {
        set result [tk_dialog .d Load $message(load) warning \
		0 $message(ok) $message(no)]
        if {$result == 1} {return}
    }
    set oldname $filename

    set filename [fileDialog . Load open wipe $pwd {}]
    if {$filename == {}} {
	set filename $oldname
	return
    }
    set filedir [file dirname $filename]

    init
    readfile
    set maxp [llength $docpages]
    changelang $Option(lang)
    changesize
    if {[winfo exists .view] == 1} {
	resetview 0
    }
}

# ¸

proc save {} {
    global docpages
    global docpagesorg
    global filename
    global message
    global pwd
    global Option
    
    set oldname $filename

    if {$filename == {}} {set filename $pwd}
    set filename [fileDialog . Save save wipe $filename *.ewp]
    if {$filename == {}} {
	set filename $oldname
	return 0
    }
    if {[file exists $filename] && $Option(backup) == 1} {
	exec cp $filename $filename~
    }
    set file [open $filename w]
    output $file
    close $file
    wm title . "EWIPE - $filename"
    set docpagesorg $docpages
    return 1
}

# 

proc init {} {
    global docpages
    global docpagesorg
    global cp
    global maxp
    global cursor
    global mode
    global clip
    global Option
    
    set cp 0
    set cursor {}
    set clip(line) {}
    set clip(page) {}
    ctrlbutton disabled
    
    readdotfile
    if {$Option(startpage) == {}} {
        set docpages {}
    } else {
        set docpages $Option(startpage)
    }
    set docpagesorg $docpages
    set maxp [llength $docpages]
    set mode page
}

# 
 
proc output {fd} {
    global commandlist
    global docpages
    global Option

    if {$Option(saveoptions) == 1} {
	puts $fd "option:"
	puts $fd "  lang $Option(lang)"
	puts $fd "  pagen $Option(pagen)"
	puts $fd "  time $Option(time)"
	puts $fd "  timemode $Option(timemode)"
	puts $fd "  pathtype $Option(pathtype)"
	puts $fd "  htmlcolor $Option(htmlcolor)"
	puts $fd "  htmlfont $Option(htmlfont)"
	puts $fd "  viewersize $Option(viewersize)"
	puts $fd "  vredraw $Option(vredraw)"
	puts $fd "  saveoptions $Option(saveoptions)"
	puts $fd "  background $Option(background)"
	puts $fd "  bgtype $Option(bgtype)"
	puts $fd "  titletype $Option(titletype)"
	puts $fd "  pointer $Option(pointer)"
	puts $fd "  pointerfg $Option(pointerfg)"
	puts $fd "  pointerbg $Option(pointerbg)"
	puts $fd "  penleft $Option(penleft)"
	puts $fd "  penright $Option(penright)"
	puts $fd ":end\n"
    }

    foreach i $docpages {
	puts $fd "{"
	foreach j $i {
	    set str0 [lindex $j 0]
	    if {[lsearch $commandlist $str0] != -1} {
		set str1 [lindex $j 1]
		set str2 [lindex $j 2]
		set str3 [lindex $j 3]
		if {$str3 != {}} {
		    set str $str0
		    lappend str $str1
		    lappend str $str2
		    lappend str $str3
		    puts $fd "    \{$str\}"
		} elseif {$str2 != {}} {
		    set str $str0
		    lappend str $str1
		    lappend str $str2
		    puts $fd "    \{$str\}"
		} else {
		    set str $str0
		    lappend str $str1
		    puts $fd "    \{$str\}"
		}
	    } else {
		puts $fd "    {$j}"
	    }
	}
	puts $fd "}\n"
    }
}

# HTML 
 
proc outputHTML {} {
    global commandlist
    global docpages
    global message
    global Option
    global pwd
    
    set htmlfile [fileDialog . "Save as HTML" save html $pwd *.html]
    if {$htmlfile == {}} {
	return 0
    }

    if {$Option(lang) == "jpn"} {
	set contents "ܼ"
	set next "ڡ"
	set prev "ڡ"
    } elseif {$Option(lang) == "eng"} {
	set contents "Table of Contents"
	set next "next"
	set prev "prev"
    }
    set list [split [string trim $htmlfile "/"] "/"]
    set s [expr [llength $list] - 1]
    set file [split [lindex $list $s] "."]
    set htmlname [lindex $file 0]

    set fd [open $htmlfile w]

    puts $fd "<HTML>\n<HEAD>"
    puts $fd "  <TITLE>$htmlname</TITLE>"
    puts $fd "</HEAD>"

    puts $fd "<BODY "
    if {$Option(background) != {}} {
        puts $fd "BACKGROUND=\"$Option(background)\" "
    } elseif {$Option(htmlcolor) == 1} {
        puts $fd "BGCOLOR=\"#27408B\" "
    }
    if {$Option(htmlcolor) == 1} {
	puts $fd "TEXT=\"#FFFFFF\" ALINK=\"#FFFF00\" VLINK=\"#C0C0C0\" LINK=\"#E0E0E0\">"
    } else {
	puts $fd ">"
    }
    puts $fd "<A NAME=\"contents\"></A>"
    puts $fd "<H1>$contents</H1>"
    puts $fd "<OL>"
    set page 1
    foreach i $docpages {
	set label [lindex [lindex $i 0] 0]
	if {[lsearch $commandlist $label] != -1} {
	    if {$label != "text" && $label != "textbox"} {
		set title [lindex [lindex $i 0] 1]
	    } else {
		set title {}
	    }
	} else {
	    set title {}
	}
	puts $fd "  <A HREF=\"#page-$page\"><LI>$title</A>"
	incr page
    }
    puts $fd "</OL>"
    puts $fd "<HR>\n<P>"
    puts $fd "<CENTER>"
    puts $fd "  <A HREF=\"#page-1\">\[$next\]</A>"
    puts $fd "</CENTER>\n<P>"
    
    set maxpage [llength $docpages]
    set page 1
    foreach i $docpages {
	puts $fd "<A NAME=\"page-$page\"></A>"
	puts $fd "<HR NOSHADE>\n<P>"
	if {$Option(htmlcolor) == 1} {
	    puts $fd "<FONT COLOR=\"#00FF00\">"
	} else {
	    puts $fd "<FONT COLOR=\"#FF0000\">"
	}
	puts $fd "  <DIV ALIGN=\"RIGHT\">page $page / $maxpage</DIV>"
	puts $fd "</FONT>\n<P>"

	if {$Option(htmlfont) == 1} {
	    puts $fd "<FONT SIZE = 5>\n<P>"
	}

	foreach j $i {
	    if {[lindex $j 0] == "move"} {
		set j [lindex $j 1]
	    }
	    set str0 [lindex [lindex $j 0] 0]
	    set str1 [lindex $j 1]
	    set str2 [lindex $j 2]

	    set colormode 0
	    if {$Option(htmlcolor) == 1} {
		set color [name2rgb $str2 r]
		if {$color != -1} {
		    set colormode 1
		    puts $fd "<FONT COLOR=\"$color\">"
		}
	    }
	    
	    switch $str0 {
		title {
		    puts $fd "<CENTER>"
		    if {$Option(htmlcolor) == 1} {
			puts $fd "<FONT COLOR=\"#FFFF00\">"
		    }
		    puts $fd "<H1>$str1</H1>"
		    if {$str2 != {}} {
			if {$Option(htmlfont) == 1} {
			    puts $fd "    <H1>$str2</H1>"
			} else {
			    puts $fd "    <H2>$str2</H2>"
			}
		    }
		    if {$Option(htmlcolor) == 1} {
			puts $fd "</FONT>"
		    }
		    puts $fd "</CENTER>"
		}
		item {
		    puts $fd "<UL>"
		    puts $fd "  <LI>$str1"
		    puts $fd "</UL>"
		}
		subitem {
		    puts $fd "<UL>"
		    puts $fd "  <UL>"
		    puts $fd "    <LI>$str1"
		    puts $fd "  </UL>"
		    puts $fd "</UL>"
		}
		subsubitem {
		    puts $fd "<UL>"
		    puts $fd "  <UL>"
		    puts $fd "    <UL>"
		    puts $fd "      <LI>$str1"
		    puts $fd "    </UL>"
		    puts $fd "  </UL>"
		    puts $fd "</UL>"
		}
		subsubsubitem {
		    puts $fd "<UL>"
		    puts $fd "  <UL>"
		    puts $fd "    <UL>"
		    puts $fd "      <UL>"
		    puts $fd "        <LI>$str1"
		    puts $fd "      </UL>"
		    puts $fd "    </UL>"
		    puts $fd "  </UL>"
		    puts $fd "</UL>"
		}
		left {
		    puts $fd "$str1<P>"
		}
		center {
		    puts $fd "<CENTER>"
		    puts $fd "  $str1<P>"
		    puts $fd "</CENTER>"
		}
		right {
		    puts $fd "<DIV ALIGN=\"RIGHT\">"
		    puts $fd "  $str1"
		    puts $fd "</DIV>"
		}
		pict {
		    puts $fd "<CENTER>"
		    puts $fd "  <IMG SRC=\"$str1\" ALT=\"$str1\"></P>"
		    puts $fd "</CENTER>"
		}
		animation {
		    set str1 [lindex $str1 0]
		    puts $fd "<CENTER>"
		    puts $fd "  <IMG SRC=\"$str1\" ALT=\"$str1\"></P>"
		    puts $fd "</CENTER>"
		}
		pp {
		    puts $fd "$str1<P>"
		}
		rp {
		    puts $fd "<DIV ALIGN=\"RIGHT\">"
		    puts $fd "  $str1"
		    puts $fd "</DIV>"
		}
		symbol {
		    if {$str1 == "uparrow"} {
			    puts $fd "<CENTER></CENTER><P>"
		    } elseif {$str1 == "downarrow"} {
			puts $fd "<CENTER></CENTER><P>"
		    } elseif {$str1 == "updownarrow"} {
			puts $fd "<CENTER></CENTER><P>"
		    } elseif {$str1 == "cdot"} {
			puts $fd "<CENTER></CENTER><P>"
		    } elseif {$str1 == "vdots"} {
			puts $fd "<CENTER></CENTER><P>"
		    }
		}
		text {
                    puts $fd "<PRE>"
		    set str1 [string trim $str1 "\n"]
		    set strlist [split $str1 "\n"]
		    foreach i $strlist {
			puts $fd "$i<BR>"
		    }
                    puts $fd "</PRE>"
		    puts $fd "<P>"
		}
		textbox {
                    puts $fd "<PRE>"
		    set str1 [string trim $str1 "\n"]
		    set strlist [split $str1 "\n"]
		    foreach i $strlist {
			puts $fd "  $i<BR>"
		    }
                    puts $fd "</PRE>"
		    puts $fd "<P>"
		}
		message {
		    set str1 [string trim $str1 "\n"]
		    set strlist [split $str1 "\n"]
		    foreach i $strlist {
			puts $fd "  $i<BR>"
		    }
		    puts $fd "<P>"
		}
		label {
		    puts $fd "<CENTER>"
		    puts $fd "  $str2<P>"
		    puts $fd "</CENTER>"
		}
                table {
                    puts $fd "<DIV ALIGN=\"CENTER\"><TABLE BORDER>"
                    set define [lindex $str1 0]
                    set define [view_cutcode $define]
                    set col [expr [llength $define] * 2 + 1] 
                    set line [llength $str1]
		    
                    for {set i 0} {$i < [llength $define]} {incr i} {
                        switch -exact [lindex $define $i] {
                            l {set align($i) "left"}
                            c {set align($i) "center"}
                            r {set align($i) "right"}
                        }
                    }

                    for {set i 2} {$i < $line} {incr i 2} {
                        puts $fd " <TR>"
                        set textlist [lindex $str1 $i]
                        if {$textlist != {}} { 
                            for {set j 1} {$j < $col} {incr j 2} {
                                set column 1
                                set nextj $j
                                if {[lindex $textlist [expr $j + 1]] == "_"} {
                                    for {set k [expr $j + 1]} \
                                            {[lindex $textlist $k] == "_" && $k < $col} \
                                            {incr k 2} {
                                        incr column
                                    }
                                    set nextj [expr $k + 1]
                                }
                                set data [lindex $textlist $j]
                                set pos [expr $j / 2]
                                puts $fd "  <TD COLSPAN=\"$column\" ALIGN=\"$align($pos)\">$data</TD>"
                                set j $nextj
                            }
                        }
                        puts $fd " </TR>"
                    }
                    puts $fd "</TABLE></DIV>"
                }
	    }
	    if {$colormode == 1} {
		puts $fd "</FONT>"
	    }
	}

	if {$Option(htmlfont) == 1} {
	    puts $fd "</FONT>\n<P>"
	}

	puts $fd "<P>\n<HR>\n<P>"
	puts $fd "<CENTER>"
	puts $fd "  <A HREF=\"#page-[expr $page-1]\">\[ $prev \]</A>"
	puts $fd "  <A HREF=\"#contents\">\[ $contents \]</A>"
	if {$page < $maxpage} {
	    puts $fd "  <A HREF=\"#page-[expr $page+1]\">\[ $next \]</A>"
	}
	puts $fd "</CENTER>"
	incr page
	puts $fd "<P>"
    }
    puts $fd "</BODY>\n</HTML>"

    close $fd
}

# mgp ǡ
 
proc outputMGP {} {
    global commandlist
    global docpages
    global message
    global Option
    global pwd

    set mgpfile [fileDialog . "Save as MGP" save mgp $pwd *.mgp]
    if {$mgpfile == {}} {
        return 0
    }

    set list [split [string trim $mgpfile "/"] "/"]
    set s [expr [llength $list] - 1]
    set file [split [lindex $list $s] "."]
    set mgpname [lindex $file 0]

    set fd [open $mgpfile w]
    kanji outputCode $fd JIS

    puts $fd "%% This file is generated by EWIPE"
    puts $fd "%%"
    puts $fd {%include "default.mgp"}

    set maxpage [llength $docpages]
    set page 1

    foreach i $docpages {
	puts $fd "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
	puts $fd "%page"
	puts $fd {}

	set str [lindex $i 0]
	
	if {[lindex [lindex $str 0] 0] == "title"} {
	    puts $fd [lindex $str 1]
	    puts $fd {}
	    if {[lindex $str 2] != {}} {
		puts $fd {}
		puts $fd [lindex $str 2]
	    }
	} else {
	    puts $fd {}
	    puts $fd {}
	}
	set i [lreplace $i 0 0]

	foreach j $i {
	    set str0 [lindex [lindex $j 0] 0]
	    set str1 [lindex $j 1]
	    set str2 [lindex $j 2]
	    set str3 [lindex $j 3]
	    
	    switch $str0 {
		title {
		    puts $fd "%center"
		    puts $fd $str1
		    if {$str2 != {}} {
			puts $fd $str2
		    }
		    puts $fd "%left"
		}
		item {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "\t$str1"
		    e2m_endcolorsize $fd
		}
		subitem {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "\t\t$str1"
		    e2m_endcolorsize $fd
		}
		subsubitem {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "\t\t\t$str1"
		    e2m_endcolorsize $fd
		}
		subsubsubitem {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "        - $str1"
		    e2m_endcolorsize $fd
		}
		left {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "%left"
		    puts $fd $str1
		    e2m_endcolorsize $fd
		}
		center {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "%center"
		    puts $fd $str1
		    puts $fd "%left"
		    e2m_endcolorsize $fd
		}
		right {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "%right"
		    puts $fd $str1
		    puts $fd "%left"
		    e2m_endcolorsize $fd
		}
		pict {
		    puts $fd "%center"
		    puts $fd "%IMAGE \"$str1\""
		    puts $fd "%left"
		}
		pp {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "%left"
		    puts $fd $str1
		    e2m_endcolorsize $fd
		}
		rp {
		    e2m_colorsize $str2 $str3 $fd
		    puts $fd "%right"
		    puts $fd $str1
		    puts $fd "%left"
		    e2m_endcolorsize $fd
		}
		symbol {
		    if {$str1 == "uparrow"} {
			puts $fd "%center"
			puts $fd ""
			puts $fd "%left"
		    } elseif {$str1 == "downarrow"} {
			puts $fd "%center"
			puts $fd ""
			puts $fd "%left"
		    } elseif {$str1 == "updownarrow"} {
			puts $fd "%center"
			puts $fd ""
			puts $fd "%left"
		    } elseif {$str1 == "cdot"} {
			puts $fd "%center"
			puts $fd ""
			puts $fd "%left"
		    } elseif {$str1 == "vdots"} {
			puts $fd "%center"
			puts $fd ""
			puts $fd "%left"
		    }
		}
		text {
		    puts $fd "%left"
		    puts $fd $str1
		}
		textbox {
		    puts $fd "%left"
		    puts $fd $str1
		}
		table {
		}
		animation {
		    puts $fd "%center"
		    set count 0
		    foreach k $str1 {
			if {$count == 0} {
			    puts $fd "%mark, image \"$k\""
			    puts $fd {}
			    incr count
			} elseif {$count == 1} {
			    puts $fd "%pause, again, mark, image \"$k\""
			    puts $fd {}
			    incr count
			} else {
			    if {$str2 == "-1"} { 
				puts $fd "%pause, again, mark, image \"$k\""
			    } else {
				puts $fd "%again, mark, image \"$k\""
			    }
			    puts $fd {}
			    incr count
			}
		    }
		    puts $fd "%left"
		}
		move {
		    e2m_colorsize [lindex $str1 2] [lindex $str1 3] $fd
		    if {$str2 == "nw" || $str2 == "w" || $str2 == "sw" || \
			    $str2 == "n" || $str2 == "s"} {
			puts $fd "%lcutin"
		    } else {
			puts $fd "%rcutin"
		    }
		    puts $fd [lindex $str1 1]
		    e2m_endcolorsize $fd
		}
		pause {
		    puts $fd "%pause"
		}
		exec {
		    puts $fd "%xsystem \"$str1\"" 
		}
		figure {
		}
		label {
		}
		message {
		}
		cleft {
		}
		prog {
		}
	    }
	}
    }
    close $fd
}

# եȥ

proc e2m_colorsize {color size fd} {
    if {$size != ""} {
	set fsize [expr [lindex $size 0] / 3]
    } else {
	set fsize 7
    }
    if {$color == ""} {
	set color white
    }
    puts $fd "%SIZE $fsize,FORE \"$color\""
}

# ǥեȿ

proc e2m_endcolorsize {fd} {
    puts $fd "%SIZE 7,FORE \"white\""
}

# λ

proc exitewipe {} {
    global docpages
    global docpagesorg
    global message
    global view_ps
    global tcl_platform

    set s 1
    if {$docpages != {} && $docpages != $docpagesorg} {
        set result [tk_dialog .d Exit $message(exit) warning \
		0 $message(save) $message(no) $message(cancel)]
        if {$result == 0} {set s [save]}
        if {$result == 1} {set s 1}
        if {$result == 2} {return}
    }
    if {$s == 1} {
	if {$tcl_platform(platform) != "windows"} {
	    if {[info exists view_ps] == 1} {
		foreach i $view_ps(id) {
		    if {[lsearch [exec ps] [lindex $view_ps(id) $i]] == -1} {
			exec kill $i
		    }
		}
	    }
	}
	exit
    }
}

# ٥

proc makelabel {label} {
    global docpages
    global cp
    global maxp
    global cursor
    global newcursor

    set cursor $newcursor
    set curpage [lindex $docpages $cp]
    set curpage [linsert $curpage $cursor "$label {}"]
    
    if {[lindex $docpages $cp] != {}} {
	set docpages [lreplace $docpages $cp $cp $curpage]
    } else {
	lappend docpages $curpage
	incr maxp
    }
    if {$label != "pause"} {
	resetpage
	edittext
    } else {
	insertpause
    }
}

# ƥ

proc inputtext {x y m} {
    global docpages
    global cp
    global maxp
    global lnum
    global cursor
    global newcursor
    global scrY
    global Option
    global tcl_platform

    if {[winfo exists .fe] == 1} {return}

    if {$y != {}} {
	set x [.fc.c canvasx $x]
	set y [.fc.c canvasy $y]

	set wy $lnum
	for {set i 0} {$i < $lnum} {incr i} {
	    if {$y < $scrY($i)} {
		set wy $i
		break
	    }
	}
	set newcursor $wy
    } else {
	if {$cursor == {}} {
	    set newcursor 0
	} else {
	    if {$m == 1} {
		set newcursor [expr $cursor + 1]
	    } else {
		set newcursor $cursor
	    }
	}
    }

    if {$newcursor == 0} {
	makelabel title
    } else {
	set x [winfo pointerx .]
	set y [winfo pointery .]
	
	.pmml post [expr $x - 5] [expr $y - 5]
	focus .pmml
	if {$tcl_platform(platform) == "windows"} {
	    update
	    tkwait visibility .pmml
	}
        bind .pmml <FocusOut> {
            .pmml unpost
        }
    }
}

# edit ܥ

proc edittext {} {
    global cursor

    if {[lindex [.fc.c.lb1($cursor) configure -text] 4] == "   "} {
	return
    } elseif {[lindex [.fc.c.lb1($cursor) configure -text] 4] == "title"} {
	changetitle
    } elseif {[lindex [.fc.c.lb1($cursor) configure -text] 4] == "pict"} {
	changefile
    } elseif {[lindex [.fc.c.lb1($cursor) configure -text] 4] == "symbol"} {
	update
	popupmenu symbol
    } elseif {[lindex [.fc.c.lb1($cursor) configure -text] 4] == "table"} {
	changetable
    } elseif {[lindex [.fc.c.lb1($cursor) configure -text] 4] == "animation"} {
	changeanimation
    } elseif {[lindex [.fc.c.lb1($cursor) configure -text] 4] == "pause"} {
	insertpause
    } else {
	changetext
    }
}

# ƥѹ

proc changetext {} {
    global docpages
    global cp
    global cursor
    global message
    global str2 str3
    global deffonts
    global work

    set curpage [lindex $docpages $cp]
    set line [lindex $curpage $cursor]
    if {[lindex $line 0] == "move"} {
	set text [lindex [lindex $line 1] 1]
    } else {
	set text [lindex $line 1]
    }
    toplevel .fe
    wm title .fe edit

    text .fe.tt -width 56 -height 5
    frame .fe.fb1
    set str2 [lindex $line 2]
    if {$str2 == {}} {
	set str2 default
    }
    set str3 [lindex [lindex $line 3] 0]
    if {$str3 == {}} {
	set str3 default
    }
    tk_optionMenu .fe.fb1.mc str2 default white yellow green orange red \
	    skyblue gray
    eval [concat {tk_optionMenu .fe.fb1.mf str3 default} $deffonts]
    frame .fe.fb2
    button .fe.fb2.bo -text $message(ok) -command {
	set str1 [.fe.tt get 1.0 "end - 1 chars"]
	set str1 [string trim $str1 "\n"]
	destroy .fe
	set curpage [lindex $docpages $cp]
	set line [lindex $curpage $cursor]
	if {[lindex $line 0] == "move"} {
	    set str0 [lindex [lindex $line 1] 0]
	    set strd {}
	    lappend strd $str0
	    lappend strd $str1
	    set str2 [lindex [lindex $line 1] 2]
	    if {$str2 != {}} {
		lappend strd $str2
	    }
	    set str3 [lindex [lindex $line 1] 3]
	    if {$str3 != {}} {
		lappend strd $str3
	    }
	    set str [lindex $line 0]
	    lappend str $strd
 	    lappend str [lindex $line 2]
	    set curpage [lreplace $curpage $cursor $cursor $str]
	    set docpages [lreplace $docpages $cp $cp $curpage]
   	} else {
	    set str0 [lindex $line 0]
	    set str {}
	    lappend str $str0
	    lappend str $str1
	    # set str2 [lindex $line 2]
	    if {$str2 != "default"} {
		lappend str $str2
	    } else {
		if {$str3 != "default"} {
		    lappend str {}
		}
	    }
	    # set str3 [lindex $line 3]
	    if {$str3 != "default"} {
		lappend str $str3
	    }
	    set curpage [lreplace $curpage $cursor $cursor $str]
	    set docpages [lreplace $docpages $cp $cp $curpage]
	    
	    if {$str3 != "default"} {
		set work(fonts) $str3
		changefont {}
	    }
	}
	ctrlbutton normal
	ctrlcobutton $cursor
	resetpage
    }
    button .fe.fb2.bc -text $message(cancel) -command {
	destroy .fe
	ctrlbutton normal
	ctrlcobutton $cursor
	resetpage
    }
    pack .fe.fb1.mc .fe.fb1.mf -side left
    pack .fe.fb2.bo .fe.fb2.bc -side left
    if {[lindex $line 0] == "move"} {
	pack .fe.tt .fe.fb2
    } else {
	pack .fe.fb1 .fe.tt .fe.fb2
    }
    .fe.tt insert 1.0 $text

    wm withdraw .fe
    update idletasks
    set x [expr [winfo x .] + ([winfo width .] - [winfo reqwidth .fe]) / 2]
    set y [expr [winfo y .] + ([winfo height .] - [winfo reqheight .fe]) / 2]

    wm geometry .fe +$x+$y
    wm deiconify .fe

    focus .fe.tt
    update
    grab .fe
    tkwait window .fe
}

# ȥѹ

proc changetitle {} {
    global docpages
    global cp
    global cursor
    global message

    set curpage [lindex $docpages $cp]
    set text1 [lindex [lindex $curpage $cursor] 1]
    set text2 [lindex [lindex $curpage $cursor] 2]
    toplevel .fe
    wm title .fe title

    frame .fe.tt
    frame .fe.ts
    label .fe.tt.lb -text "  title  "
    label .fe.ts.lb -text "sub title"
    text .fe.tt.en -width 48 -height 2
    text .fe.ts.en -width 48 -height 2
    frame .fe.fb
    button .fe.fb.bo -text $message(ok) -command {
	set str1 [.fe.tt.en get 1.0 "end - 1 chars"]
	set str2 [.fe.ts.en get 1.0 "end - 1 chars"]
	set str1 [string trim $str1 "\n"]
	set str2 [string trim $str2 "\n"]
	destroy .fe
	set curpage [lindex $docpages $cp]
	if {$str2 == {}} {
	    set str title
	    lappend str $str1
	    set curpage [lreplace $curpage $cursor $cursor $str]
	} else {
	    set str title
	    lappend str $str1
	    lappend str $str2
	    set curpage [lreplace $curpage $cursor $cursor $str]
	}
	set docpages [lreplace $docpages $cp $cp $curpage]
	ctrlbutton normal
	ctrlcobutton $cursor
	resetpage
    }
    button .fe.fb.bc -text $message(cancel) -command {
	destroy .fe
	ctrlbutton normal
	ctrlcobutton $cursor
	resetpage
    }
    pack .fe.tt.lb .fe.tt.en -side left
    pack .fe.ts.lb .fe.ts.en -side left
    pack .fe.fb.bo .fe.fb.bc -side left
    pack .fe.tt .fe.ts .fe.fb
    .fe.tt.en insert 1.0 $text1
    .fe.ts.en insert 1.0 $text2

    wm withdraw .fe
    update idletasks
    set x [expr [winfo x .] + ([winfo width .] - [winfo reqwidth .fe]) / 2]
    set y [expr [winfo y .] + ([winfo height .] - [winfo reqheight .fe]) / 2]

    wm geometry .fe +$x+$y
    wm deiconify .fe

    focus .fe.tt.en
    update
    grab .fe
    tkwait window .fe
}

# եѹ

proc changefile {} {
    global filedir
    global docpages
    global cp
    global cursor
    global message
    global filedir
    global Option
    global pwd
    
    set curpage [lindex $docpages $cp]

    toplevel .fe
    wm title .fe pict

    entry .fe.en -width 60
    frame .fe.fb
    button .fe.fb.bo -text $message(ok) -command {
        set str1 [.fe.en get]
        destroy .fe
        if {$str1 == {}} {return}
        set curpage [lindex $docpages $cp]
        set str0 [lindex [lindex $curpage $cursor] 0]
	set str $str0
	lappend str $str1
        set curpage [lreplace $curpage $cursor $cursor $str]
        set docpages [lreplace $docpages $cp $cp $curpage]
        resetpage
        ctrlbutton normal
        ctrlcobutton $cursor
    }
    button .fe.fb.bb -text $message(browse) -command {
	set initfile [.fe.en get]
	if {[file exists $initfile] == 0} {
	    set initfile {}
	} else {
	    set afile [file tail $initfile]
	    cd [file dirname $initfile]
	    set adir [pwd]
	    cd $pwd
	    set initfile $adir/$afile
	}
	set fname [fileDialog .fe "Select GIF File" open image $initfile {}]
        if {$fname != ""} {
	    if {$Option(pathtype) == 1} {
		set fname [relativepath $filedir $fname] 
	    }
            .fe.en delete 0 end
            .fe.en insert 0 $fname
        }
    }
    button .fe.fb.bc -text $message(cancel) -command {
        destroy .fe
    }
    pack .fe.fb.bo .fe.fb.bb .fe.fb.bc -side left
    pack .fe.en .fe.fb
    set text [lindex [lindex $curpage $cursor] 1]
    .fe.en insert 0 $text

    wm withdraw .fe
    update idletasks
    set x [expr [winfo x .] + ([winfo width .] - [winfo reqwidth .fe]) / 2]
    set y [expr [winfo y .] + ([winfo height .] - [winfo reqheight .fe]) / 2]

    wm geometry .fe +$x+$y
    wm deiconify .fe

    focus .fe.en
    update
    grab .fe
    tkwait window .fe
}

# animation 

proc changeanimation {} {
    global filedir
    global docpages
    global cp
    global cursor
    global message
    global filedir
    global Option
    global pwd
    
    set curpage [lindex $docpages $cp]
    
    toplevel .fe
    wm title .fe animation
    
    entry .fe.en -width 60
    frame .fe.fb
    button .fe.fb.bo -text $message(ok) -command {
        set str1 [.fe.en get]
        destroy .fe
        if {$str1 == {}} {return}
        set curpage [lindex $docpages $cp]
        set str0 [lindex [lindex $curpage $cursor] 0]
	set str $str0
	lappend str $str1
	set str2 [lindex [lindex $curpage $cursor] 2]
	if {$str2 != {}} {
	    lappend str $str2
	}
        set curpage [lreplace $curpage $cursor $cursor $str]
        set docpages [lreplace $docpages $cp $cp $curpage]
        resetpage
        ctrlbutton normal
        ctrlcobutton $cursor
    }
    button .fe.fb.bb -text $message(browse) -command {
	set initfile [lindex [.fe.en get] 0]
	if {[file exists $initfile] == 0} {
	    set initfile {}
	} else {
	    set afile [file tail $initfile]
	    cd [file dirname $initfile]
	    set adir [pwd]
	    cd $pwd
	    set initfile $adir/$afile
	}
	set fname [fileDialog .fe "Select GIF File" open image $initfile {}]
        if {$fname != ""} {
	    if {$Option(pathtype) == 1} {
		set fname [relativepath $filedir $fname] 
	    }
            .fe.en insert end "$fname "
        }
    }
    button .fe.fb.bc -text $message(cancel) -command {
        destroy .fe
    }
    pack .fe.fb.bo .fe.fb.bb .fe.fb.bc -side left
    pack .fe.en .fe.fb
    set text [lindex [lindex $curpage $cursor] 1]
    .fe.en insert 0 $text

    wm withdraw .fe
    update idletasks
    set x [expr [winfo x .] + ([winfo width .] - [winfo reqwidth .fe]) / 2]
    set y [expr [winfo y .] + ([winfo height .] - [winfo reqheight .fe]) / 2]

    wm geometry .fe +$x+$y
    wm deiconify .fe

    focus .fe.en
    update
    grab .fe
    tkwait window .fe
}

# pause 

proc insertpause {} {
    global docpages
    global cp
    global cursor
    
    set curpage [lindex $docpages $cp]
    set str pause
    set curpage [lreplace $curpage $cursor $cursor $str]
    set docpages [lreplace $docpages $cp $cp $curpage]
    resetpage
    ctrlbutton normal
    ctrlcobutton $cursor
}

# ˥塼ɽ

proc popupmenu {select} {
    global tcl_platform
    
    set x [winfo pointerx .]
    set y [winfo pointery .]

    switch $select {
	label {
	    .pml post $x $y
	    focus .pml
	    if {$tcl_platform(platform) == "windows"} {
		update
		tkwait visibility .pml
	    }
	    bind .pml <FocusOut> {
		.pml unpost
	    }
	}
	color {
	    .pmc post $x $y
	    focus .pmc
	    if {$tcl_platform(platform) == "windows"} {
		update
		tkwait visibility .pmc
	    }
	    bind .pmc <FocusOut> {
		.pmc unpost
	    }
	}
	font {
	    .pmf post $x $y
	    focus .pmf
	    if {$tcl_platform(platform) == "windows"} {
		update
		tkwait visibility .pmf
	    }
	    bind .pmf <FocusOut> {
		.pmf unpost
	    }
	}
	symbol {
	    .pms post $x $y
	    focus .pms
	    if {$tcl_platform(platform) == "windows"} {
		update
		tkwait visibility .pms
	    }
	    bind .pms <FocusOut> {
		.pms unpost
	    }
	}
	attr {
	    .pma post $x $y
	    focus .pma
	    if {$tcl_platform(platform) == "windows"} {
		update
		tkwait visibility .pma
	    }
	    bind .pma <FocusOut> {
		.pma unpost
	    }
	}
    }
}

# ɽ

proc changetable {} {
    global docpages
    global cp
    global cursor
    
    set curpage [lindex $docpages $cp]
    set str1 [edittable [lindex [lindex $curpage $cursor] 1]]
    if {$str1 == {}} {return}
    
    set str table
    lappend str $str1
    set curpage [lreplace $curpage $cursor $cursor $str]
    set docpages [lreplace $docpages $cp $cp $curpage]
    resetpage
    ctrlbutton normal
    ctrlcobutton $cursor
}

# ե

proc fileDialog {w title operation type initfile ext} {
    set file ""
    if {$type == "image"} {
        set types {
            {"Image Files"   {.gif}       }
            {"All Files"     *            }
        }
    } elseif {$type == "html"} {
        set types {
            {"HTML Files"   {.html .htm}   }
            {"All Files"    *              }
	}
    } elseif {$type == "mgp"} {
        set types {
            {"MGP Files"   {.mgp}         }
            {"All Files"    *              }
	}
    } elseif {$type == "wipe"} {
        set types {
            {"EWIPE Files"   {.ewp .wipe}   }
            {"All Files"    *             }
	}
    } elseif {$type == {}} {
        set types {
            {"All Files"    *         }
	}
    }
    if {[file exists $initfile] == 1} {
	if {[file isfile $initfile]} {
	    set initd [file dirname $initfile]
	    if {$initd == "."} {set initd {}} 
	    set initf [file tail $initfile]
	} else {
	    set initd $initfile
	    set initf $ext
	}
    } else {
	set initd [file dirname $initfile]
	if {$initd == "."} {set initd {}} 
	set initf [file tail $initfile]
    }

    if {$operation == "open"} {
        set file [tk_getOpenFile -title $title -filetypes $types -parent $w \
		-initialdir $initd]
    } elseif {$operation == "save" } {
        set file [tk_getSaveFile -title $title -filetypes $types -parent $w \
                -initialdir $initd -initialfile $initf]
    }
    if {$file != ""} { 
	return $file
    }
}

# ٥ѹ

proc changelabel {x} {
    global commandlist
    global docpages
    global cp
    global cursor
    
    .fc.c.lb1($cursor) configure -text $x
    set curpage [lindex $docpages $cp]

    set str [lindex [lindex $curpage $cursor] 0]

    if {[lsearch $commandlist $str] != -1} {
	if {$str != $x} {
	    set pattern [checklabel $str $x]
	} else {
	    set pattern 2
	}
	set str1 [lindex [lindex $curpage $cursor] 1]
	set str2 [lindex [lindex $curpage $cursor] 2]
	set str3 [lindex [lindex $curpage $cursor] 3]
	if {$pattern == 0} {
	    set str $x
	    lappend str {}
	} elseif {$pattern == 1} {
	    set str $x
	    lappend str $str1
	} elseif {$pattern == 2} {
	    set str $x
	    lappend str $str1
	    if {$str2 != {}} {
		lappend str $str2
	    }
	    if {$str3 != {}} {
		lappend str $str3
	    }
	}
    } else {
	set str $x
	lappend str {}
    }
    set curpage [lreplace $curpage $cursor $cursor $str]
    set docpages [lreplace $docpages $cp $cp $curpage]
    resetpage
    ctrlbutton normal
    ctrlcobutton $cursor
}

# ٥å

proc checklabel {old new} {
    if {$old == "title" || $old == "textbox"} {
	if {$new == "table" || $new == "pict" || $new == "symbol" \
		|| $new == "animation"} {
	    return 0
	} else {
	    return 1
	}
    } elseif {$old == "table" || $old == "pict"|| $old == "symbol" \
	    || $old == "animation"} {
	return 0
    } else {
	if {$new == "table" || $new == "pict" || $new == "symbol" \
		|| $new == "animation"} {
	    return 0
	} elseif {$new == "title" || $new == "textbox"} {
	    return 1
	} else {
	    return 2
	}
    }
}

# ٥ܺ

proc setlabelopt {} {
    global docpages
    global cp
    global cursor
    global message

    set curpage [lindex $docpages $cp]
    set line [lindex $curpage $cursor]
    set text [lindex [lindex $line 0] 1]

    toplevel .fe
    wm title .fe label
    
    text .fe.tt -width 40 -height 1
    frame .fe.fb
    button .fe.fb.bo -text $message(ok) -command {
	set str1 [.fe.tt get 1.0 "end - 1 chars"]
	set str1 [string trim $str1 "\n"]
	destroy .fe
	set curpage [lindex $docpages $cp]
	set line [lindex $curpage $cursor]
	set str0 [lindex [lindex $line 0] 0]
	set str $str0
	lappend str $str1
	set line [lreplace $line 0 0 $str]
	set curpage [lreplace $curpage $cursor $cursor $line]
	set docpages [lreplace $docpages $cp $cp $curpage]
	ctrlbutton normal
	ctrlcobutton $cursor
	resetpage
    }
    button .fe.fb.bd -text $message(default) -command {
	destroy .fe
	set curpage [lindex $docpages $cp]
	set line [lindex $curpage $cursor]
	set str [lindex [lindex $line 0] 0]
	set line [lreplace $line 0 0 $str]
	set curpage [lreplace $curpage $cursor $cursor $line]
	set docpages [lreplace $docpages $cp $cp $curpage]
	ctrlbutton normal
	ctrlcobutton $cursor
	resetpage
    }
    button .fe.fb.bc -text $message(cancel) -command {
	destroy .fe
	ctrlbutton normal
	ctrlcobutton $cursor
	resetpage
    }
    pack .fe.fb.bo .fe.fb.bd .fe.fb.bc -side left
    pack .fe.tt .fe.fb
    .fe.tt insert 1.0 $text
    
    wm withdraw .fe
    update idletasks
    set x [expr [winfo x .] + ([winfo width .] - [winfo reqwidth .fe]) / 2]
    set y [expr [winfo y .] + ([winfo height .] - [winfo reqheight .fe]) / 2]

    wm geometry .fe +$x+$y
    wm deiconify .fe

    focus .fe.tt
    update
    grab .fe
    tkwait window .fe
}

# ƥѹ
 
proc changeitem {x} {
    global docpages
    global cp
    global cursor
    
    set curpage [lindex $docpages $cp]
    set str [lindex [lindex $curpage $cursor] 0]
    set str0 [lindex [lindex $curpage $cursor] 0]
    set str1 [lindex [lindex $curpage $cursor] 2]
    set str $str0
    lappend str $x
    if {$str1 != {}} {
	lappend str $str1
    }
    set curpage [lreplace $curpage $cursor $cursor $str]
    set docpages [lreplace $docpages $cp $cp $curpage]
    resetpage
    ctrlbutton normal
    ctrlcobutton $cursor
}

# ʸѹ

proc changecolor {x} {
    global docpages
    global cp
    global cursor

    set curpage [lindex $docpages $cp]
    set color [lindex [lindex $curpage $cursor] 2]
    if {$color == {}} {
	set color white
    }
    if {$x == "etc"} {
	set x [tk_chooseColor -initialcolor $color]
    }
    if {$x == {}} return
    set str0 [lindex [lindex $curpage $cursor] 0]
    set str1 [lindex [lindex $curpage $cursor] 1]
    set str3 [lindex [lindex $curpage $cursor] 3]
    if {$x == "white" && $str3 == {}} {
	set str {}
	lappend str $str0
	lappend str $str1
	set curpage [lreplace $curpage $cursor $cursor $str]
    } else {
	set str {}
	lappend str $str0
	lappend str $str1
	lappend str $x
	if {$str3 != {}} {
		lappend str $str3
	}
	set curpage [lreplace $curpage $cursor $cursor $str]
    }
    set docpages [lreplace $docpages $cp $cp $curpage]
    resetpage
    ctrlbutton normal
    ctrlcobutton $cursor
}


# եȥå

proc checkfont {} {
    global docpages
    global cp
    global cursor
    global work

    set curpage [lindex $docpages $cp]

    set str0 [lindex [lindex $curpage $cursor] 0]
    set str3 [lindex [lindex $curpage $cursor] 3]

    if {$str3 == {}} {
	if {$str0 == "text" || $str0 == "textbox"} {
	    set work(fonts) 16
	    set work(fontt) rm
	    set work(kfonts) 16
	    set work(kfontt) mc
	} else {
	    set work(fonts) 24
	    set work(fontt) rm
	    set work(kfonts) 24
	    set work(kfontt) mc
	}
    } else {
	set work(fonts) [lindex $str3 0]
	set work(fontt) [lindex $str3 1]
	set work(kfonts) [lindex $str3 2]
	set work(kfontt) [lindex $str3 3]
    }
}

# եѹ

proc changefont {x} {
    global docpages
    global cp
    global cursor
    global work
    global Str
    global Str2
    global message

    set curpage [lindex $docpages $cp]
    set fontlist [lindex [lindex $curpage $cursor] 3]
    set work(fontt) [lindex $fontlist 1]
    set work(kfontt) [lindex $fontlist 3]
    set work(fontsold) [lindex $fontlist 0]
    set work(kfontsold) [lindex $fontlist 2]
    if {$x == "etc"} {
	toplevel .fe
	wm title .fe font
	
	frame .fe.en1
	frame .fe.en2
	label .fe.en1.lb -text "ascii font "
	label .fe.en2.lb -text "kanji font "
	entry .fe.en1.en -width 40
	entry .fe.en2.en -width 40
	frame .fe.fb
	button .fe.fb.bo -text $message(ok) -command {
	    set Str [.fe.en1.en get]
	    set Str2 [.fe.en2.en get]
    	    if {$Str == {} && $Str2 == {}} {return}
	    destroy .fe
	}
	button .fe.fb.bc -text $message(cancel) -command {
	    set Str {}
	    set Str2 {}
	    destroy .fe
	}
	pack .fe.en1.lb .fe.en1.en -side left
	pack .fe.en2.lb .fe.en2.en -side left
	pack .fe.fb.bo .fe.fb.bc -side left
	pack .fe.en1 .fe.en2 .fe.fb

	.fe.en1.en delete 0 end
	if {$work(fontsold) == "u"} {
	    .fe.en1.en insert 0 $work(fontt)
	}
	.fe.en2.en delete 0 end
	if {$work(kfontsold) == "u"} {
	    .fe.en2.en insert 0 $work(kfontt)
	}
	wm withdraw .fe
	update idletasks
	set wx [expr [winfo x .] + ([winfo width .] - \
	    [winfo reqwidth .fe]) / 2]
	set wy [expr [winfo y .] + ([winfo height .] - \
	    [winfo reqheight .fe])/2]
	
	wm geometry .fe +$wx+$wy
	wm deiconify .fe

	update
	focus .fe.en1.en
	grab .fe
	tkwait window .fe
    } else {
	set Str def
    }
    if {$Str == {} && $Str2 == {}} {
	return
    } else {
	if {$x == "etc"} {
	    set work(fonts) u
	    set work(fontt) $Str
	    set work(kfonts) u
	    set work(kfontt) $Str2
	} else {
	    set work(fontt) rm
	    set work(kfonts) $work(fonts)
	    set work(kfontt) mc
	}
    }
    set str0 [lindex [lindex $curpage $cursor] 0]
    set str1 [lindex [lindex $curpage $cursor] 1]
    set str2 [lindex [lindex $curpage $cursor] 2]

    set changed 0
    if {$str0 == "text" || $str0 == "textbox"} {
	if {$work(fonts) != 16} {
	    set changed 1
	}
    } else {
	if {$work(fonts) != 24} {
	    set changed 1
	}
    }
	
    if {$changed == 1} {
	set str3 "$work(fonts) $work(fontt) $work(kfonts) $work(kfontt)"
	set str {}
	lappend str $str0
	lappend str $str1
	if {$str2 == {}} {set str2 "white"}
	lappend str $str2
	lappend str $str3
    } else {
	set str {}
	lappend str $str0
	lappend str $str1
	if {$str2 != {} && $str2 != "white"} { 
	    lappend str $str2
	}
    }

    set curpage [lreplace $curpage $cursor $cursor $str]

    set docpages [lreplace $docpages $cp $cp $curpage]
    resetpage
    ctrlbutton normal
    ctrlcobutton $cursor
}

# °ѹ

proc changeattr {x} {
    global docpages
    global cp
    global cursor

    set curpage [lindex $docpages $cp]
    set line [lindex $curpage $cursor]

    set str0 [lindex $line 0]
    if {$str0 == "move"} {
	set line [lindex $line 1]
    }

    if {$x != "none"} {
	set str0 [lindex $x 0]
	set str1 $line
	set str2 [lindex $x 1]
	set str $str0
	lappend str $str1
	lappend str $str2
    } else {
	set str $line
    }
    set curpage [lreplace $curpage $cursor $cursor $str]
    set docpages [lreplace $docpages $cp $cp $curpage]
    resetpage
    ctrlbutton normal
    ctrlcobutton $cursor
}

# ط

proc selectbg {} {
    global message
    global filedir
    global Option
    global pwd

    toplevel .fe
    wm title .fe background
    
    entry .fe.en -width 60
    frame .fe.fb
    button .fe.fb.bo -text $message(ok) -command {
        set Option(background) [.fe.en get]
        destroy .fe
	changebg
    }
    button .fe.fb.bb -text $message(browse) -command {
	set initfile [.fe.en get]
	if {[file exists $initfile] == 0} {
	    set initfile $pwd
	} else {
	    set afile [file tail $initfile]
	    cd [file dirname $initfile]
	    set adir [pwd]
	    cd $pwd
	    set initfile $adir/$afile
	}
	set fname [fileDialog . "Select Background" open image $initfile {}]
	if {$fname != ""} {
	    if {$Option(pathtype) == 1} {
		set fname [relativepath $filedir $fname] 
	    }
            .fe.en delete 0 end
            .fe.en insert 0 $fname
	}
    }
    button .fe.fb.bc -text $message(cancel) -command {
        destroy .fe
    }
    pack .fe.fb.bo .fe.fb.bb .fe.fb.bc -side left
    pack .fe.en .fe.fb
    
    .fe.en insert 0 $Option(background)
    
    wm withdraw .fe
    update idletasks
    set x [expr [winfo x .] + ([winfo width .] - [winfo reqwidth .fe]) / 2]
    set y [expr [winfo y .] + ([winfo height .] - [winfo reqheight .fe]) / 2]
    
    wm geometry .fe +$x+$y
    wm deiconify .fe

    focus .fe.en
    update
    grab .fe
    tkwait window .fe
}

# طѹ

proc changebg {} {
    global cp

    if {[winfo exists .view] == 1} {
	resetview $cp
    }
}

# Ժڡ

proc deleteline {} {
    global docpages
    global cp
    global maxp
    global cursor
    global mode
    global clip

    if {$mode == "page"} {
	set x $cursor
	set curpage [lindex $docpages $cp]
	set clip(line) [lindex $curpage $x]
	set curpage [lreplace $curpage $x $x]
	set docpages [lreplace $docpages $cp $cp $curpage]
	if {[lindex $docpages $cp] == {}} { 
	    set docpages [lreplace $docpages $cp $cp]
	    incr maxp -1
	    if {$maxp == 0} {
		set cp 0
	    } elseif {$cp >= $maxp} {
		set cp [expr $maxp - 1]
	    }
	}
	resetpage
    } elseif {$mode == "contents"} {
	set clip(page) [lindex $docpages $cursor]
	set docpages [lreplace $docpages $cursor $cursor]
	incr maxp -1
	showtitle
    }
}

# ԥڡ

proc pasteline {} {
    global docpages
    global lnum
    global cp
    global maxp
    global cursor
    global mode
    global clip

    if {$mode == "page"} {
	set curpage [lindex $docpages $cp]
	if {$clip(line) == {}} {return}
	set str $clip(line)
	set curpage [linsert $curpage $cursor $str]
	set docpages [lreplace $docpages $cp $cp $curpage]
	resetpage
	ctrlbutton normal
	ctrlcobutton $cursor
    } elseif {$mode == "contents"} {
	if {$clip(page) == {}} {return}
	set str $clip(page)
	set docpages [linsert $docpages $cursor $str]
	incr maxp
	showtitle
    }
}

# Ը

proc exchangeline {s e} {
    global docpages
    global cp

    set curpage [lindex $docpages $cp]
    set sline [lindex $curpage $s]
    set eline [lindex $curpage $e]
    set curpage [lreplace $curpage $s $s]
    set curpage [linsert $curpage $s $eline]
    set curpage [lreplace $curpage $e $e]
    set curpage [linsert $curpage $e $sline]
    set docpages [lreplace $docpages $cp $cp $curpage]
    resetpage
}

# ư

proc move {n} {
    global lnum
    global cursor
    global mode

    if {$mode == "page"} {
	if {$n == "up"} {
	    if {$cursor == 0} {return}
	    incr cursor -1
	    exchangeline [expr $cursor+1] $cursor
	} elseif {$n == "down"} {
	    if {$cursor == [expr $lnum-1]} {return}
	    incr cursor
	    exchangeline [expr $cursor-1] $cursor
	}
    } elseif {$mode == "contents"} {
	if {$n == "up"} {
	    if {$cursor == 0} {return}
	    incr cursor -1
	    exchangepage [expr $cursor+1] $cursor
	} elseif {$n == "down"} {
	    if {$cursor == [expr $lnum-1]} {return}
	    incr cursor
	    exchangepage [expr $cursor-1] $cursor
	}
    }
}

# ڡ

proc exchangepage {s e} {
    global docpages
    global cp
    global cursor

    set spage [lindex $docpages $s]
    set epage [lindex $docpages $e]
    set docpages [lreplace $docpages $s $s]
    set docpages [linsert $docpages $s $epage]
    set docpages [lreplace $docpages $e $e]
    set docpages [linsert $docpages $e $spage]
    set cursor $e
    set cp $e
    showtitle
}

# ڡư

proc movepage {s e} {
    global docpages
    global cp
    global cursor

    set spage [lindex $docpages $s]
    if {$s < $e} {
	set docpages [linsert $docpages $e $spage]
	set docpages [lreplace $docpages $s $s]
	set cursor [expr $e-1]
	set cp $cursor
    } else {
	set docpages [lreplace $docpages $s $s]
	set docpages [linsert $docpages $e $spage]
	set cursor $e
	set cp $cursor
    }
    showtitle
}

# ڡ

proc createpage {m} {
    global docpages
    global cp
    global maxp
    global cursor

    if {[winfo exists .fe] == 1} {return}
    if {$maxp != 0} {
	if {$m == 1} {
	    incr cp
	}
	lappend curpage "title {}"
	set docpages [linsert $docpages $cp $curpage]
	incr maxp
    } else {
	set curpage {}
	set curpage [linsert $curpage 0 "title {}"]
	lappend docpages $curpage
	incr maxp
    }
    ctrlbutton normal
    set cursor 0
    resetpage
    ctrlbutton normal
    ctrlcobutton $cursor
    changetitle
}

# ڡ

proc jumppage {} {
    global cp
    global maxp
    global cursor
    global mode

    set err 0
    set jp [.fb2.ep get]
    set jp [lindex [split $jp "/"] 0]
    if {[regexp {[a-z]+} $jp]} {
	set err 1
    }
    set jp [string trimleft $jp 0]
    if {$jp == {}} {set jp 0}
    if {[llength $jp] > 3} {
	set err 1
    }
    if {$err == 0} {
	set jp [expr $jp-1]
    }
    if {$jp >= 0 && $jp < $maxp && $err == 0} {
	set cp $jp
	if {$mode == "contents"} {
	    .fb2.bi configure -state normal
	    .fb2.ba configure -state normal
	    .fb2.bn configure -state normal
	    .fb2.bp configure -state normal
	    .fb2.bt configure -text index -command showtitle
	    set cursor {}
	    set mode page
	    ctrlbutton disabled
	}
	resetpage
    } else {
	resetpage
    }
}


# ڡɽ

proc nextpage {n} {
    global cp
    global maxp
    global cursor

    if {$n == 1} {
    	if {$cp < [expr $maxp-1]} {
	    incr cp
	    set cursor {}
	    ctrlbutton disabled
	    initpage
	    showpage
	}
    } elseif {$n == -1} {
	if {$cp > 0} {
	    incr cp -1
	    set cursor {}
	    ctrlbutton disabled
	    initpage
	    showpage
	}
    }
}

# ڡɽ 

proc resetpage {} {
    global view_skip

    set view_skip 1 
    initpage
    showpage
}

# ڡ

proc initpage {} {
    global lnum
    global cp
    global maxp

    .fb2.ep delete 0 end
    if {$maxp == 0} {
	.fb2.ep insert 0 "0/0"
    } else {
	.fb2.ep insert 0 "[expr $cp+1]/[expr $maxp]"
    }
    for {set i 0} {$i < $lnum} {incr i} {
	if {[winfo exists .fc.c.lb1($i)]} {destroy .fc.c.lb1($i)}
	if {[winfo exists .fc.c.lb2($i)]} {destroy .fc.c.lb2($i)}
	if {[winfo exists .fc.c.titletext]} {destroy .fc.c.titletext}
    }
    .fc.c delete all
    set lnum 0
    focus .
}

# ɥѹ

proc changesize {} {
    global Option
    
    if {$Option(viewersize) == 1} {
	.fc.c configure -height 500
	wm geometry . {}
	wm minsize . 590 580
	wm maxsize . 640 620
    } else {
	.fc.c configure -height 400
	wm geometry . {}
	wm minsize . 590 480
	wm maxsize . 640 520
    }
    if {[winfo exists .view] == 1} {
	setval
	call_viewer normal
    }
    ctrlbutton disabled
    resetpage
}

# ڡɽ

proc showpage {} {
    global commandlist
    global docpages
    global lnum
    global cp
    global maxp
    global cursor
    global mode
    global scrY
    global Id1 Id2
    global message
    global Option

    .fb2.bt configure -text $message(contents) -command showtitle
    set page [lindex $docpages $cp]    
    set scrY(0) 20

    set width 56
    set wlen 392
	
    foreach i $page {
	set line $i
	set str0 [lindex [lindex $line 0] 0]
	if {[lsearch $commandlist $str0] != -1} {
	    if {$str0 == "move"} {
		set text "move [lindex $line 2]"
		set line [lindex $line 1]
		set str0 [lindex $line 0]
		.fc.c create text 510 $scrY($lnum) -text $text \
			-anchor nw -fill yellow
	    }
	    if {$str0 == "text" || $str0 == "textbox" || $str0 == "table" \
		    || $str0 == "animation"} {
		set str1 [string range [lindex $line 1] 0 [expr $width - 1]]
	    } else {
		set str1 [lindex $line 1]
	    }
	    set color [lindex $line 2]
	    if {$str0 == "title"} {
		set color yellow
		set str2 [lindex $line 2]
		if {$str2 != {}} {
		    set str1 "$str1  -  $str2"
		}
	    }
	    if {$str0 == "animation"} {set color white}
	    if {$color == {}} {set color white}
	    regsub -all "\[\t\n\]" $str1 { } str1
	    regsub -all "\ +\ *" $str1 { } str1
	    set str1 [string trim $str1 { }]
	    set n [string length $str1]
	    set l [expr $n / ($width + 1) + 1]
	    label .fc.c.lb1($lnum) -width 10 -text $str0 \
		    -anchor w -bg RoyalBlue4 -fg white
	    label .fc.c.lb2($lnum) -relief raised -width $width -heigh $l \
		    -wraplength $wlen -text $str1 -justify left -anchor w \
		    -bg RoyalBlue4 -fg $color
	    .fc.c create window 10 $scrY($lnum) -window .fc.c.lb1($lnum) \
		    -anchor nw
	    .fc.c create window 100 $scrY($lnum) -window .fc.c.lb2($lnum) \
		    -anchor nw
	    set dy [expr 30 + ($l-1) * 15]
	} else {
	    set str [string range $line 0 [expr $width - 1]]
	    label .fc.c.lb1($lnum) -width 10 -text "   " \
		    -anchor w  -bg RoyalBlue4 -fg white
	    label .fc.c.lb2($lnum) -relief raised -width $width -height 1 \
		    -text $str -anchor nw -justify left -bg RoyalBlue4 \
		    -fg white
	    .fc.c create window 10 $scrY($lnum) -window .fc.c.lb1($lnum) \
		    -anchor nw
	    .fc.c create window 100 $scrY($lnum) -window .fc.c.lb2($lnum) \
		    -anchor nw
	    set dy 30
	}
	set Id1(.fc.c.lb1($lnum)) $lnum
	set Id2(.fc.c.lb2($lnum)) $lnum
	setbind $lnum $str0
  	incr lnum
	set scrY($lnum) [expr $scrY([expr $lnum-1]) + $dy]
    }

    .fc.c configure -scrollregion "0 0 560 [expr $scrY($lnum) + 10]"

    if {$cursor != {} && $cursor >= $lnum && $lnum != 0} {
	set cursor [expr $lnum -1]
	set mw .fc.c.lb2($cursor)
    }
    if {$lnum == 0} {
	set cursor {}
	ctrlbutton disabled
    }
    if {$cursor != {}} {
	.fc.c.lb2($cursor) configure -bg #A9A9A9
	.fc.c.lb1($cursor) configure -bg #A9A9A9
    }
    bind .fc.c <Double-Button-1> {
	inputtext %x %y 0
    }
    
    if {$Option(vredraw) == 1} {
	call_viewer normal
    }
    ctrlpabutton
}

# Х

proc setbind {n label} {
    global docpages
    global cp
    global Id1
    global Id2
    global lnum

    bind .fc.c.lb1($n) <1> {
	set mw %W
	focus $mw
	if {$cursor == {}} {
	    $mw configure -bg #A9A9A9
	    .fc.c.lb2($Id1($mw)) configure -bg #A9A9A9
	    set cursor $Id1($mw)
	    ctrlbutton normal
	    ctrlcobutton $Id1($mw)
	} elseif {$cursor != $Id1($mw)} {
	    $mw configure -bg #A9A9A9
	    .fc.c.lb2($Id1($mw)) configure -bg #A9A9A9
	    .fc.c.lb2($cursor) configure -bg RoyalBlue4
	    .fc.c.lb1($cursor) configure -bg RoyalBlue4
	    set cursor $Id1($mw)
	    ctrlbutton normal	
	    ctrlcobutton $Id1($mw)
	}
    }
    bind .fc.c.lb1($n) <3> {
	set mw %W
	focus $mw
	if {$cursor == $Id1($mw)} {
	    set str [lindex [$mw configure -text] 4]
	    if {$str == "item" || $str == "subitem" || $str == "subsubitem" \
		    || $str == "subsubsubitem"} {
		if {[lindex [lindex [lindex $docpages $cp] $Id1($mw)] 0] \
			!= "move"} {
		    setlabelopt
		    return
		}
	    }
	    $mw configure -bg RoyalBlue4
	    .fc.c.lb2($Id1($mw)) configure -bg RoyalBlue4
	    set cursor {}
	    ctrlbutton disabled
	}
    }
    bind .fc.c.lb2($n) <1> {
	set mw %W
	focus $mw
	if {$cursor == {}} {
	    $mw configure -bg #A9A9A9
	    .fc.c.lb1($Id2($mw)) configure -bg #A9A9A9
	    set cursor $Id2($mw)
	    ctrlbutton normal
	    ctrlcobutton $Id2($mw)
	} elseif {$cursor != $Id2($mw)} {
	    $mw configure -bg #A9A9A9
	    .fc.c.lb1($Id2($mw)) configure -bg #A9A9A9
	    .fc.c.lb2($cursor) configure -bg RoyalBlue4
	    .fc.c.lb1($cursor) configure -bg RoyalBlue4
	    set cursor $Id2($mw)
	    ctrlbutton normal	
	    ctrlcobutton $Id2($mw)
	}
    }
    bind .fc.c.lb2($n) <3> {
	set mw %W
	focus $mw
	if {$cursor == $Id2($mw)} {
	    $mw configure -bg RoyalBlue4
	    .fc.c.lb1($Id2($mw)) configure -bg RoyalBlue4
	    set cursor {}
	    ctrlbutton disabled
	}
    }
    bind .fc.c.lb2($n) <Double-Button-1> {
	edittext
    }
    if {[lindex [lindex [lindex $docpages $cp] $n] 0] != "move"} {
	bind .fc.c.lb1($n) <Double-Button-1> {
	    popupmenu label
	}
    }
}

# ȥɽ

proc showtitle {} {
    global docpages
    global lnum
    global cp
    global maxp
    global cursor
    global mode
    global Id
    global message

    if {$maxp == 0} {
	.fb2.bp configure -state normal
	.fb2.bn configure -state normal
	.fb2.bi configure -state normal
	.fb2.ba configure -state normal
	.fb2.bt configure -text $message(contents) -command showtitle
	set cp 0
	set mode page
	ctrlbutton disabled
	resetpage
	return
    }
    if {$cp == $maxp} {set cp [expr $maxp - 1]}

    set mode contents
    set cursor $cp 
    ctrlbutton normal 
    .fb2.bp configure -state disabled
    .fb2.bn configure -state disabled
    .fb2.bi configure -state disabled
    .fb2.ba configure -state disabled
    .fb2.bt configure -text $message(page) -command {
	.fb2.bp configure -state normal
	.fb2.bn configure -state normal
	.fb2.bi configure -state normal
	.fb2.ba configure -state normal
	.fb2.bt configure -text $message(contents) -command showtitle
	set cp $cursor
	set cursor {}
	set mode page
	ctrlbutton disabled
	resetpage
	return
    }
    bind .fc.c <<Double-Button-1> ""
    initpage
    .fb2.ep delete 0 end
    .fb2.ep insert 0 [expr $cursor + 1]
    set p [llength $docpages]
    set col [expr ($p-1) / 10 + 1]
    set tw [expr 530 / $col]
    label .fc.c.titletext -width 54 -anchor w -bg black -fg white 
    .fc.c create window 60 20 -window .fc.c.titletext -anchor w
    foreach page $docpages {
        set str [lindex [lindex $page 0] 1]
	regsub -all "\[\t\n\]" $str { } str
	regsub -all "\ +\ *" $str { } str
	set str [string trim $str { }]
	label .fc.c.lb1($lnum) -relief raised -width [expr 68/$col-2] \
		-text $str -anchor w -bg white
	if {$p <= 50} {
	    .fc.c create text [expr $lnum/10 * $tw + 10] \
		    [expr 60+($lnum%10)*30] -text [expr $lnum+1] \
		    -anchor nw -fill white
	} else {
	    if {[expr $lnum % 10] == 0} {
		.fc.c create text [expr $lnum/10 * $tw + 30] 40 \
			-text [expr $lnum+1] -anchor nw -fill white
	    }
	}
	.fc.c create window [expr $lnum/10 * $tw + 30] \
		[expr 60+($lnum%10)*30] -window .fc.c.lb1($lnum) -anchor nw
	set Id(.fc.c.lb1($lnum)) $lnum
	bind .fc.c.lb1($lnum) <1> {
	    set mw %W
	    if {$Id($mw) != $cursor} {
		$mw configure -bg #A9A9A9
		.fc.c.lb1($cursor) configure -bg white
		set cursor $Id($mw)
		set cp $cursor
		.fb2.ep delete 0 end
		.fb2.ep insert 0 [expr $cp + 1]
		set str [lindex [lindex [lindex $docpages $cp] 0] 1]
		regsub -all "\[\t\n\]" $str { } str
		regsub -all "\ +\ *" $str { } str
		set str [string trim $str { }]
		.fc.c.titletext configure -text $str
	    }
	}
	bind .fc.c.lb1($lnum) <2> {
	    set mw %W	    
	    movepage $cursor $Id($mw)
	}
	bind .fc.c.lb1($lnum) <Double-Button-1> {
	    set mw %W	    
	    .fb2.bp configure -state normal
	    .fb2.bn configure -state normal
	    .fb2.ba configure -state normal
	    .fb2.bi configure -state normal
	    .fb2.bt configure -text index -command showtitle
	    set cp $cursor
	    set cursor {}
	    set mode page
	    ctrlbutton disabled
	    resetpage
	}
	incr lnum
    }
    if {$cursor >= $lnum && $lnum != 0} {
	set cursor [expr $lnum -1]
	set mw .fc.c.lb1($cursor)
    }
    if {$lnum == 0} {
	set cursor {}
	ctrlbutton disabled
    }

    if {$cursor != {}} {
	.fc.c.lb1($cursor) configure -bg #A9A9A9
	set str [lindex [lindex [lindex $docpages $cp] 0] 1]
	regsub -all "\[\t\n\]" $str { } str
	regsub -all "\ +\ *" $str { } str
	set str [string trim $str { }]
	.fc.c.titletext configure -text $str
    }
}

# ܥ

proc ctrlbutton {state} {
    global cursor
    global mode

    if {$mode == "page"} {
	.fb1.bl configure -state $state
	.fb1.bi configure -state normal
	.fb1.ba configure -state normal
	.fb1.be configure -state $state
	.fb1.bo configure -state $state
	.fb1.bf configure -state $state
	.fb1.bt configure -state $state
    } elseif {$mode == "contents"} { 
	.fb1.bl configure -state disabled
	.fb1.bi configure -state disabled
	.fb1.ba configure -state disabled
	.fb1.be configure -state disabled
	.fb1.bo configure -state disabled
	.fb1.bf configure -state disabled
	.fb1.bt configure -state disabled
    }
    .fb1.bc configure -state $state
    .fb1.bp configure -state $state
    .fb1.bu configure -state $state
    .fb1.bd configure -state $state 
}

# 顼ѹܥ & եѹܥ

proc ctrlcobutton {n} {
    global docpages
    global cp

    set str [lindex [.fc.c.lb1($n) configure -text] 4]
    if {$str == "title" || $str == "pict" || $str == "textbox" \
	    || $str == "animation" || $str == "pause" \
	    || $str == "   "} {
	.fb1.bo configure -state disabled
    }
    if {$str == "title" || $str == "pict" || $str == "symbol" \
	    || $str == "animation" || $str == "pause" \
	    || $str == "   "} {
	.fb1.bf configure -state disabled
    }
    if {$str == "title" || $str == "pict" || $str == "symbol" \
	    || $str == "table" || $str == "animation" \
	    || $str == "text" || $str == "textbox" || $str == "pause" \
	    || $str == "   "} {
	.fb1.bt configure -state disabled
    }

    set str [lindex [lindex [lindex $docpages $cp] $n] 0]
    if {$str == "move"} {
	.fb1.bl configure -state disabled
	.fb1.bo configure -state disabled
	.fb1.bf configure -state disabled
    }
}

# ڡѹܥ

proc ctrlpabutton {} {
    global cp
    global maxp

    if {$maxp == 0 || $maxp == 1} {
 	.fb2.bp configure -state disabled
 	.fb2.bn configure -state disabled
    } elseif {$cp == 0} {
 	.fb2.bp configure -state disabled
 	.fb2.bn configure -state normal
    } elseif {$cp == ($maxp-1)} {
 	.fb2.bp configure -state normal
 	.fb2.bn configure -state disabled
    } else {
 	.fb2.bp configure -state normal
 	.fb2.bn configure -state normal
    }
    if {$maxp == 0} {
	.fb2.bt configure -state disabled
    } else {
	.fb2.bt configure -state normal
    }
}

# Viewer  bind 

proc viewredraw {} {
    global Option

    if {[winfo exists .view] == 1} {
	view_setbind 1
    }
}

# ˥塼

proc checkmenu {} {
    global Option
    
    if {$Option(background) == {}} {
	.fm.mbo.m entryconfigure 8 -state disabled
    } else {
	.fm.mbo.m entryconfigure 8 -state normal
    }
    if {$Option(LANG) == "eng"} {
	.fm.mbo.m entryconfigure 0 -state disabled
    } else {
	.fm.mbo.m entryconfigure 0 -state normal
    }
}

# ɽѹ

proc changelang {lang} {
    global message
    global Option
    global deffonts
    global work

    set Option(lang) $lang

    if {$lang == "jpn"} {
	set message(page) "ɽ"
	set message(contents) " ܼ "

	set message(ok) λ
	set message(cancel) 󥻥
	set message(no) 
	set message(save) ¸
	set message(browse) ...
	set message(select) 
	set message(etc) ¾
	set message(default) ǥե
	set message(load) "ԽƤ˴ޤǤ"
	set message(exit) "λ˥ե¸ޤ"

	# ˥塼
	.fm.mbf configure -text ե
	.fm.mbf.m delete 0 end
	.fm.mbf.m add command -label  -command new
	.fm.mbf.m add command -label ɹ -command load
	.fm.mbf.m add command -label ¸ -command save
	.fm.mbf.m add separator
	.fm.mbf.m add command -label "HTML ¸" -command outputHTML
	.fm.mbf.m add command -label "MGP ¸" -command outputMGP
	.fm.mbf.m add separator
	.fm.mbf.m add command -label "EWIPE ˤĤ" -command aboutEWIPE
	.fm.mbf.m add separator
	.fm.mbf.m add command -label λ -command exitewipe

	.fm.mbo configure -text ץ
	.fm.mbo.m delete 0 end
	.fm.mbo.m add cascade -label ɽ -menu .fm.mbo.m.lang
	.fm.mbo.m.lang delete 0 end
	.fm.mbo.m.lang add command -label ܸ -command "changelang jpn"
	.fm.mbo.m.lang add command -label Ѹ -command "changelang eng"
	.fm.mbo.m add cascade -label ѥΥ -menu .fm.mbo.m.path
	.fm.mbo.m.path delete 0 end
	.fm.mbo.m.path add radiobutton -label Хѥ -value 0 \
		-variable Option(pathtype)
	.fm.mbo.m.path add radiobutton -label Хѥ -value 1 \
		-variable Option(pathtype)
	.fm.mbo.m add separator
	.fm.mbo.m add cascade -label ڡֹ -menu .fm.mbo.m.pnum
	.fm.mbo.m.pnum delete 0 end
	.fm.mbo.m.pnum add radiobutton -label off -value 0 \
		-variable Option(pagen) -command "call_viewer pagen"
	.fm.mbo.m.pnum add radiobutton -label on -value 1 \
		-variable Option(pagen) -command "call_viewer pagen"
	.fm.mbo.m add cascade -label "" -menu .fm.mbo.m.time
	.fm.mbo.m.time delete 0 end
	.fm.mbo.m.time add radiobutton -label off -value 0 \
		-variable Option(time) -command "call_viewer time"
	.fm.mbo.m.time add radiobutton -label on -value 1 \
		-variable Option(time) -command "call_viewer time"
	.fm.mbo.m add cascade -label "֤Υ" -menu .fm.mbo.m.timetype
	.fm.mbo.m.timetype delete 0 end
	.fm.mbo.m.timetype add radiobutton -label "" -value 0 \
		-variable Option(timemode)
	.fm.mbo.m.timetype add radiobutton -label "в" -value 1 \
		-variable Option(timemode)
	.fm.mbo.m add command -label ݥ -command setpointer
	.fm.mbo.m add command -label "ط" -command selectbg
	.fm.mbo.m add cascade -label "طʤΥ" -menu .fm.mbo.m.bgtype
	.fm.mbo.m.bgtype delete 0 end
	.fm.mbo.m.bgtype add radiobutton -label  -value 0 \
		-variable Option(bgtype) -command changebg
	.fm.mbo.m.bgtype add radiobutton -label  -value 1 \
		-variable Option(bgtype) -command changebg
	.fm.mbo.m add cascade -label "ȥΥ" \
		-menu .fm.mbo.m.titletype
	.fm.mbo.m.titletype delete 0 end
	.fm.mbo.m.titletype add radiobutton -label box -value 0 \
		-variable Option(titletype) \
		-command "set view_skip 1; call_viewer normal"
	.fm.mbo.m.titletype add radiobutton -label line -value 1 \
		-variable Option(titletype) \
		-command "set view_skip 1; call_viewer normal"
	.fm.mbo.m add separator
	.fm.mbo.m add cascade -label "HTML 顼" -menu .fm.mbo.m.htmlc
	.fm.mbo.m.htmlc delete 0 end
	.fm.mbo.m.htmlc add radiobutton -label Υ -value 0 \
		-variable Option(htmlcolor)
	.fm.mbo.m.htmlc add radiobutton -label 顼 -value 1 \
		-variable Option(htmlcolor)
	.fm.mbo.m add cascade -label "HTML " -menu .fm.mbo.m.htmls
	.fm.mbo.m.htmls delete 0 end
	.fm.mbo.m.htmls add radiobutton -label  -value 0 \
		-variable Option(htmlfont)
	.fm.mbo.m.htmls add radiobutton -label  -value 1 \
		-variable Option(htmlfont)
	.fm.mbo.m add separator
	.fm.mbo.m add cascade -label "Viewer " -menu .fm.mbo.m.vsize
	.fm.mbo.m.vsize delete 0 end
	.fm.mbo.m.vsize add radiobutton -label 640x480 -value 0 \
		-variable Option(viewersize) -command changesize 
	.fm.mbo.m.vsize add radiobutton -label 800x600 -value 1 \
		-variable Option(viewersize)  -command changesize
	.fm.mbo.m add cascade -label "Viewer " -menu .fm.mbo.m.view
	.fm.mbo.m.view delete 0 end
	.fm.mbo.m.view add radiobutton -label off -value 0 \
		-variable Option(vredraw) -command viewredraw
	.fm.mbo.m.view add radiobutton -label on -value 1 \
		-variable Option(vredraw) -command viewredraw
	.fm.mbo.m add command -label "View ⡼" -command "call_viewer view"
	.fm.mbo.m add separator
	.fm.mbo.m add cascade -label "ץ¸" -menu .fm.mbo.m.save
	.fm.mbo.m.save delete 0 end
	.fm.mbo.m.save add radiobutton -label off -value 0 \
		-variable Option(saveoptions)
	.fm.mbo.m.save add radiobutton -label on -value 1 \
		-variable Option(saveoptions)

	# Խޥɥܥ
	.fb1.bl configure -text ٥
	.fb1.bi configure -text 
	.fb1.ba configure -text ɲ
	.fb1.bc configure -text 
	.fb1.bp configure -text Ž
	.fb1.be configure -text Խ
	.fb1.bu configure -text 
	.fb1.bd configure -text 
	.fb1.bo configure -text 
	.fb1.bf configure -text ʸ 
	.fb1.bt configure -text °
   
	# ڡܥ	
	.fb2.bv configure -text Viewer
	.fb2.bt configure -text $message(contents)
	.fb2.bp configure -text 
	.fb2.bn configure -text 
	.fb2.bi configure -text 
	.fb2.ba configure -text ɲ
    } elseif {$lang == "eng"} {
	set message(page) "  page  "
	set message(contents) "contents"

	set message(ok) Ok
	set message(cancel) Cancel
	set message(no) No
	set message(save) Save
	set message(browse) Browse...
	set message(select) Select
	set message(etc) etc
	set message(default) default
	set message(load) "File modified, do you want to load (new) ?"
	set message(exit) "Do you want to save before exit ?"

	# ˥塼
	.fm.mbf configure -text File
	.fm.mbf.m delete 0 end
	.fm.mbf.m add command -label New -command new
	.fm.mbf.m add command -label Load -command load
	.fm.mbf.m add command -label Save -command save
	.fm.mbf.m add separator
	.fm.mbf.m add command -label "Save as HTML" -command outputHTML
	.fm.mbf.m add command -label "Save as MGP" -command outputMGP
	.fm.mbf.m add separator
	.fm.mbf.m add command -label "About EWIPE" -command aboutEWIPE
	.fm.mbf.m add separator
	.fm.mbf.m add command -label Exit -command exitewipe

	.fm.mbo configure -text Option
	.fm.mbo.m delete 0 end
	.fm.mbo.m add cascade -label Language -menu .fm.mbo.m.lang
	.fm.mbo.m.lang delete 0 end
	.fm.mbo.m.lang add command -label Japanese -command "changelang jpn"
	.fm.mbo.m.lang add command -label English -command "changelang eng"
	.fm.mbo.m add cascade -label "Path type" -menu .fm.mbo.m.path
	.fm.mbo.m.path delete 0 end
	.fm.mbo.m.path add radiobutton -label "absolute path" -value 0 \
		-variable Option(pathtype)
	.fm.mbo.m.path add radiobutton -label "relative path" -value 1 \
		-variable Option(pathtype)
	.fm.mbo.m add separator
	.fm.mbo.m add cascade -label "Page number" -menu .fm.mbo.m.pnum
	.fm.mbo.m.pnum delete 0 end
	.fm.mbo.m.pnum add radiobutton -label off -value 0 \
		-variable Option(pagen) -command "call_viewer pagen"
	.fm.mbo.m.pnum add radiobutton -label on -value 1 \
		-variable Option(pagen) -command "call_viewer pagen"
	.fm.mbo.m add cascade -label "Time" -menu .fm.mbo.m.time
	.fm.mbo.m.time delete 0 end
	.fm.mbo.m.time add radiobutton -label off -value 0 \
		-variable Option(time) -command "call_viewer time"
	.fm.mbo.m.time add radiobutton -label on -value 1 \
		-variable Option(time) -command "call_viewer time"
	.fm.mbo.m add cascade -label "Time type" -menu .fm.mbo.m.timetype
	.fm.mbo.m.timetype delete 0 end
	.fm.mbo.m.timetype add radiobutton -label "time" -value 0 \
		-variable Option(timemode)
	.fm.mbo.m.timetype add radiobutton -label "passed time" -value 1 \
		-variable Option(timemode)
	.fm.mbo.m add command -label "Pointer" -command setpointer
	.fm.mbo.m add command -label "Select background" -command selectbg
	.fm.mbo.m add cascade -label "Background type" -menu .fm.mbo.m.bgtype
	.fm.mbo.m.bgtype delete 0 end
	.fm.mbo.m.bgtype add radiobutton -label normal -value 0 \
		-variable Option(bgtype) -command changebg
	.fm.mbo.m.bgtype add radiobutton -label tiled -value 1 \
		-variable Option(bgtype) -command changebg
	.fm.mbo.m add cascade -label "Title type" \
		-menu .fm.mbo.m.titletype
	.fm.mbo.m.titletype delete 0 end
	.fm.mbo.m.titletype add radiobutton -label box -value 0 \
		-variable Option(titletype) \
		-command "set view_skip 1; call_viewer normal"
	.fm.mbo.m.titletype add radiobutton -label line -value 1 \
		-variable Option(titletype) \
		-command "set view_skip 1; call_viewer normal"
	.fm.mbo.m add separator
	.fm.mbo.m add cascade -label "HTML color" -menu .fm.mbo.m.htmlc
	.fm.mbo.m.htmlc delete 0 end
	.fm.mbo.m.htmlc add radiobutton -label Mono -value 0 \
		-variable Option(htmlcolor)
	.fm.mbo.m.htmlc add radiobutton -label Color -value 1 \
		-variable Option(htmlcolor)
	.fm.mbo.m add cascade -label "HTML size" -menu .fm.mbo.m.htmls
	.fm.mbo.m.htmls delete 0 end
	.fm.mbo.m.htmls add radiobutton -label Normal -value 0 \
		-variable Option(htmlfont)
	.fm.mbo.m.htmls add radiobutton -label Large -value 1 \
		-variable Option(htmlfont)
	.fm.mbo.m add separator
	.fm.mbo.m add cascade -label "Viewer size" -menu .fm.mbo.m.vsize
	.fm.mbo.m.vsize delete 0 end
	.fm.mbo.m.vsize add radiobutton -label 640x480 -value 0 \
		-variable Option(viewersize) -command changesize
	.fm.mbo.m.vsize add radiobutton -label 800x600 -value 1 \
		-variable Option(viewersize) -command changesize
	.fm.mbo.m add cascade -label "Viewer redraw" -menu .fm.mbo.m.view
	.fm.mbo.m.view delete 0 end
	.fm.mbo.m.view add radiobutton -label off -value 0 \
		-variable Option(vredraw) -command viewredraw
	.fm.mbo.m.view add radiobutton -label on -value 1 \
		-variable Option(vredraw) -command viewredraw
	.fm.mbo.m add command -label "View mode" -command "call_viewer view"
	.fm.mbo.m add separator
	.fm.mbo.m add cascade -label "Save options" -menu .fm.mbo.m.save
	.fm.mbo.m.save delete 0 end
	.fm.mbo.m.save add radiobutton -label off -value 0 \
		-variable Option(saveoptions)
	.fm.mbo.m.save add radiobutton -label on -value 1 \
		-variable Option(saveoptions)

	# Խޥɥܥ
	.fb1.bl configure -text label
	.fb1.bi configure -text insert
	.fb1.ba configure -text add
	.fb1.bc configure -text cut
	.fb1.bp configure -text paste
	.fb1.be configure -text edit
	.fb1.bu configure -text up
	.fb1.bd configure -text down
	.fb1.bo configure -text color
	.fb1.bf configure -text font
	.fb1.bt configure -text attr

	# ڡܥ
	.fb2.bv configure -text Viewer
	.fb2.bt configure -text $message(contents)
	.fb2.bp configure -text prev
	.fb2.bn configure -text next
	.fb2.bi configure -text insertpage
	.fb2.ba configure -text addpage
    }

    .pml delete 0 end
    .pml add command -label title -command "changelabel title"
    .pml add command -label item -command "changelabel item"
    .pml add command -label subitem -command "changelabel subitem"
    .pml add command -label subsubitem -command "changelabel subsubitem"
    .pml add command -label subsubsubitem -command "changelabel subsubsubitem"
    .pml add separator
    .pml add command -label left -command "changelabel left"
    .pml add command -label center -command "changelabel center"
    .pml add command -label right -command "changelabel right"
    .pml add separator
    .pml add command -label pict -command "changelabel pict"
    .pml add command -label symbol -command "changelabel symbol"
    .pml add command -label text -command "changelabel text"
    .pml add command -label textbox -command "changelabel textbox"
    .pml add command -label table -command "changelabel table"
    .pml add command -label animation -command "changelabel animation"
    .pml add separator
    .pml add command -label $message(cancel)

    .pmml delete 0 end
    .pmml add command -label title -command "makelabel title"
    .pmml add command -label item -command "makelabel item"
    .pmml add command -label subitem -command "makelabel subitem"
    .pmml add command -label subsubitem -command "makelabel subsubitem"
    .pmml add command -label subsubsubitem -command "makelabel subsubsubitem"
    .pmml add separator
    .pmml add command -label left -command "makelabel left"
    .pmml add command -label center -command "makelabel center"
    .pmml add command -label right -command "makelabel right"
    .pmml add separator
    .pmml add command -label pict -command "makelabel pict"
    .pmml add command -label symbol -command "makelabel symbol"
    .pmml add command -label text -command "makelabel text"
    .pmml add command -label textbox -command "makelabel textbox"
    .pmml add command -label table -command "makelabel table"
    .pmml add command -label animation -command "makelabel animation"
    .pmml add separator
    .pmml add command -label pause -command "makelabel pause"
    .pmml add separator
    .pmml add command -label $message(cancel)
    
    .pmc delete 0 end
    .pmc add command -label white -command "changecolor white"
    .pmc add command -label yellow -command "changecolor yellow"
    .pmc add command -label green -command "changecolor green"
    .pmc add command -label orange -command "changecolor orange"
    .pmc add command -label red -command "changecolor red"
    .pmc add command -label skyblue -command "changecolor skyblue"
    .pmc add command -label gray -command "changecolor gray"
    .pmc add separator
    .pmc add command -label $message(etc) -command "changecolor etc"
    .pmc add separator
    .pmc add command -label $message(cancel)
    
    .pmf delete 0 end
    foreach i $deffonts {
	.pmf add radiobutton -label $i -variable work(fonts) \
		-value $i -command "changefont {}"
    }
    .pmf add separator
    .pmf add radiobutton -label $message(etc) -variable work(fonts) \
		-value u -command "changefont etc"
    .pmf add separator
    .pmf add command -label $message(cancel)
    
    .pms delete 0 end
    .pms add command -label downarrow -command "changeitem downarrow"
    .pms add command -label uparrow -command "changeitem uparrow"
    .pms add command -label updownarrow -command "changeitem updownarrow"
    .pms add command -label cdot -command "changeitem cdot"
    .pms add command -label vdots -command "changeitem vdots"
    .pms add separator
    .pms add command -label $message(cancel)

    .pma delete 0 end
    .pma add command -label none -command "changeattr none"
    .pma add separator
    .pma add command -label "move nw" -command "changeattr {move nw}"
    .pma add command -label "move n" -command "changeattr {move n}"
    .pma add command -label "move ne" -command "changeattr {move ne}"
    .pma add command -label "move w" -command "changeattr {move w}"
    .pma add command -label "move e" -command "changeattr {move e}"
    .pma add command -label "move sw" -command "changeattr {move sw}"
    .pma add command -label "move s" -command "changeattr {move s}"
    .pma add command -label "move se" -command "changeattr {move se}"
    .pma add separator
    .pma add command -label $message(cancel)
}

# ̾  RGB Ѵ (mode  n:rgb  name  r:name  rgb)

proc name2rgb {color mode} {
    set colormap {{white #FFFFFF} {yellow #FFFF00} {green #00FF00} \
	    {orange #FFA500} {red #FF0000} {skyblue #88CEEB} \
	    {gray #BEBEBE} {RoyalBlue4 #27408B}}
    set rcolor -1
    
    if {$mode == "n"} {
	foreach i $colormap {
	    if {[lindex $i 1] == $color} {
		set rcolor [lindex $i 0]
		break
	    }
	}
    } elseif {$mode == "r"} {
	foreach i $colormap {
	    if {[lindex $i 0] == $color} {
		set rcolor [lindex $i 1]
		break
	    }
	}
    }
    return $rcolor
}

# absolute -> relative

proc relativepath {abspath absfile} {

    set pathlist [split $abspath "/"]
    set filelist [split $absfile "/"]
    
    for {set i 0} {$i < [expr [llength $pathlist] ]} {incr i} {
	lappend newlist ".."
    }
    for {set i 0} {$i < [llength $filelist]} {incr i} {
	if {[lindex $filelist $i] == [lindex $pathlist $i]} {
	    set newlist [lreplace $newlist 0 0]
	} else {
	    set p $i
	    break
	}
    }
    for {set i $p} {$i < [llength $filelist]} {incr i} {
	lappend newlist [lindex $filelist $i]
    }
    foreach i $newlist {
	append relpath "$i/"
    }
    set relpath [string trimright $relpath "/"]
    return $relpath
}

# EWIPE С

proc aboutEWIPE {} {
    global message
    global version

    toplevel .fe
    wm title .fe "about EWIPE"

    frame .fe.ft -relief raised -borderwidth 2
    label .fe.ft.tt1 -text "EWIPE Version $version"
    label .fe.ft.tt2 -text "Copyright (C) 1997-2000 Hiromasa Sekishita"
    button .fe.bo -text $message(ok) -command {
	destroy .fe
    }
    pack .fe.ft.tt1 .fe.ft.tt2 -padx 5 -pady 5
    pack .fe.ft .fe.bo -padx 5 -pady 5

    wm withdraw .fe
    update idletasks
    set x [expr [winfo x .] + ([winfo width .] - [winfo reqwidth .fe]) / 2]
    set y [expr [winfo y .] + ([winfo height .] - [winfo reqheight .fe]) / 2]

    wm geometry .fe +$x+$y
    wm deiconify .fe

    focus .fe.bo
    update
    grab .fe
    tkwait window .fe
}

wm title . "EWIPE"

# ˥塼

frame .fm -relief raised -bd 2
menubutton .fm.mbf -text File -menu .fm.mbf.m
menu .fm.mbf.m -tearoff 0
menubutton .fm.mbo -text Option -menu .fm.mbo.m
menu .fm.mbo.m -tearoff 0 -postcommand checkmenu
menu .fm.mbo.m.lang -tearoff 0
menu .fm.mbo.m.pnum -tearoff 0
menu .fm.mbo.m.time -tearoff 0
menu .fm.mbo.m.timetype -tearoff 0
menu .fm.mbo.m.path -tearoff 0
menu .fm.mbo.m.htmlc -tearoff 0
menu .fm.mbo.m.htmls -tearoff 0
menu .fm.mbo.m.vsize -tearoff 0
menu .fm.mbo.m.view -tearoff 0
menu .fm.mbo.m.save -tearoff 0
menu .fm.mbo.m.bgtype -tearoff 0
menu .fm.mbo.m.titletype -tearoff 0
pack .fm.mbf .fm.mbo -side left
pack .fm -side top -fill x

# Խޥɥܥ
frame .fb1
button .fb1.bl -command "popupmenu label"
button .fb1.bi -command "inputtext {} {} 0"
button .fb1.ba -command "inputtext {} {} 1"
button .fb1.bc -command deleteline
button .fb1.bp -command pasteline
button .fb1.be -command edittext
button .fb1.bu -command "move up"
button .fb1.bd -command "move down"
button .fb1.bo -command "popupmenu color"
button .fb1.bf -command "popupmenu font"
button .fb1.bt -command "popupmenu attr"
pack .fb1.bl .fb1.bi .fb1.ba .fb1.bc .fb1.bp .fb1.be .fb1.bu \
	.fb1.bd .fb1.bo .fb1.bf .fb1.bt -side left

menu .pml -tearoff 0
menu .pmml -tearoff 0
menu .pmc -tearoff 0
menu .pmf -tearoff 0 -postcommand checkfont
menu .pms -tearoff 0
menu .pma -tearoff 0

# ɽ
frame .fc
canvas .fc.c -height 400 -width 590 -bg RoyalBlue3 \
        -yscrollcommand ".fc.vs set" -scrollregion "0 0 590 400"
scrollbar .fc.vs -orient vertical -command ".fc.c yview"

pack .fc.c .fc.vs -side left -fill y


# ڡܥ
frame .fb2
button .fb2.bv -command "call_viewer normal" 
button .fb2.bt -command showtitle
entry .fb2.ep -width 7 -justify center
button .fb2.bp -command "set view_skip 1; nextpage -1"
button .fb2.bn -command "set view_skip 1; nextpage 1"
button .fb2.bi -command "createpage 0"
button .fb2.ba -command "createpage 1"
pack .fb2.bv .fb2.bt .fb2.ep .fb2.bp .fb2.bn .fb2.bi .fb2.ba \
	-side left

pack .fb1 .fc .fb2 -fill x

# 
set commandlist {title item subitem subsubitem subsubsubitem \
	right center left pict symbol text textbox table \
	pp rp animation move pause}
set lnum 0                    ;# Կ
set cp 0                      ;# ɽƤڡ
set cursor {}                 ;# 
set clip(line) {}             ;# åȹԵ 
set clip(page) {}             ;# åȥڡ
set pwd [pwd]                 ;# ưǥ쥯ȥ
set filedir [pwd]             ;# Խեǥ쥯ȥ
set Viewmode 0                ;# ⡼ (1: Viewer only)
set view_skip 0

set version "1.2.0"           ;# EWIPE Version

readdotfile

set filename {}                ;# ե̾
set docpages {}
if {$argv != ""} {
    argvcheck
}
definefont

if {$docpages == {}} {
    if {$Option(startpage) == {}} {
	set docpages {}
    } else {
	set docpages $Option(startpage)
    }
    set docpagesorg $docpages
}
set maxp [llength $docpages]  ;# ڡ
set mode page                 ;# ɽ⡼
changelang $Option(lang)      ;# ɽ

changesize

if {$Viewmode == 1} {
    call_viewer view
}
ctrlbutton disabled
bind .fb2.ep <Any-Return> "jumppage"