File: ptkdb.pm

package info (click to toggle)
libdevel-ptkdb-perl 1.1091-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 488 kB
  • ctags: 375
  • sloc: perl: 6,170; makefile: 4
file content (4426 lines) | stat: -rw-r--r-- 131,107 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426

package DB ;

##
## Expedient fix for perl 5.8.0.  True DB::DB is further down.
## 
##
sub DB {}



use Tk ;

#
# If you've loaded this file via a browser
# select "Save As..." from your file menu
#
#        ptkdb Perl Tk perl Debugger
#
#          Copyright 1998, 2003, Andrew E. Page
#         All rights reserved.
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of either:
#
# a) the GNU General Public License as published by the Free
# Software Foundation; either version 1, or (at your option) any
# later version, or
#
# b) the "Artistic License" which comes with this Kit.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either
#    the GNU General Public License or the Artistic License for more details.
#


####################################
### Sample .Xresources for ptkdb ###
####################################
#  /*
#   * Perl Tk Debugger XResources.  
#   * Note... These resources are subject to change.  
#   *
#   * Use 'xfontsel' to select different fonts.
#   *
#   * Append these resource to ~/.Xdefaults | ~/.Xresources
#   * and use xrdb -override ~/.Xdefaults | ~/.Xresources
#   * to activate them.  
#   */
# /* Set Value to se to place scrollbars on the right side of windows 
#   CAUTION:  extra whitespace at the end of the line is causing
#   failures with Tk800.011.
# */
# ptkdb*scrollbars: sw
# 
# /* controls where the code pane is oriented, down the left side, or across the top */
# /* values can be set to left, right, top, bottom */
# ptkdb*codeside: left
# /*
# * Background color for the balloon
# * CAUTION:  For certain versions of Tk trailing
# * characters after the color produces an error
# */
# ptkdb.frame2.frame1.rotext.balloon.background: green
# ptkdb.frame2.frame1.rotext.balloon.font: fixed                       /* Hot Variable Balloon Font */
# 
# 
# ptkdb.frame*font: fixed                           /* Menu Bar */
# ptkdb.frame.menubutton.font: fixed                /* File menu */
# ptkdb.frame2.frame1.rotext.font: fixed            /* Code Pane */
# ptkdb.notebook.datapage.frame1.hlist.font: fixed  /* Expression Notebook Page */
#              
# ptkdb.notebook.subspage*font: fixed               /* Subroutine Notebook Page */
# ptkdb.notebook.brkptspage*entry.font: fixed       /* Delete Breakpoint Buttons */
# ptkdb.notebook.brkptspage*button.font: fixed      /* Breakpoint Expression Entries */
# ptkdb.notebook.brkptspage*button1.font: fixed     /* Breakpoint Expression Entries */
# ptkdb.notebook.brkptspage*checkbutton.font: fixed /* Breakpoint Checkbuttons */
# ptkdb.notebook.brkptspage*label.font: fixed       /* Breakpoint "Cond" label */
#              
# ptkdb.toplevel.frame.textundo.font: fixed         /* Eval Expression Entry Window */
# ptkdb.toplevel.frame1.text.font: fixed            /* Eval Expression Results Window */
# ptkdb.toplevel.button.font:  fixed                /* "Eval..." Button */
# ptkdb.toplevel.button1.font: fixed                /* "Clear Eval" Button */
# ptkdb.toplevel.button2.font: fixed                /* "Clear Results" Button */
# ptkdb.toplevel.button3.font: fixed                /* "Clear Dismiss" Button */
# 
# 
#  /*
#   * Background color for where the debugger has stopped 
#   */  
#  ptkdb*stopcolor: blue
#
#  /*
#   * Background color for set breakpoints  
#   */
#  ptkdb*breaktagcolor: red
#
#  /*
#   * Font for where the debugger has stopped
#   */
#  ptkdb*stopfont: -*-fixed-bold-*-*-*-*-*-*-*-*-*-*-*
#
#  /*
#   * Background color for the search tag
#   */  
#  ptkdb*searchtagcolor: green

use strict ;
use vars qw($VERSION @dbline %dbline);


#
# This package is the main_window object
# for the debugger.  We start with the Devel::
# prefix because we want to install it with 
# the DB:: package that is required to be in a Devel/
# subdir of a directory in the @INC set.  
#
package Devel::ptkdb ;

##
## do this check once, rather than repeating the string comparison again and again
##


my $isWin32 = $^O eq 'MSWin32' ;

=head1 NAME

Devel::ptkdb - Perl debugger using a Tk GUI

=head1 DESCRIPTION

  ptkdb is a debugger for perl that uses perlTk for a user interface.
  Features include:

    Hot Variable Inspection
    Breakpoint Control Panel
    Expression List
    Subroutine Tree
    

=begin html

    <body bgcolor=white>

=end html

=head1 SYNOPSIS

To debug a script using ptkdb invoke perl like this:

    perl -d:ptkdb myscript.pl

=head1 Usage

    perl -d:ptkdb myscript.pl

=head1 Code Pane

=over 4

=item Line Numbers

 Line numbers are presented on the left side of the window. Lines that
 have lines through them are not breakable. Lines that are plain text
 are breakable. Clicking on these line numbers will insert a
 breakpoint on that line and change the line number color to
 $ENV{'PTKDB_BRKPT_COLOR'} (Defaults to Red). Clicking on the number
 again will remove the breakpoint.  If you disable the breakpoint with
 the controls on the BrkPt notebook page the color will change to
 $ENV{'PTKDB_DISABLEDBRKPT_COLOR'}(Defaults to Green).

=item Cursor Motion

If you place the cursor over a variable (i.e. $myVar, @myVar, or
%myVar) and pause for a second the debugger will evaluate the current
value of the variable and pop a balloon up with the evaluated
result. I<This feature is not available with Tk400.>

If Data::Dumper(standard with perl5.00502)is available it will be used
to format the result.  If there is an active selection, the text of
that selection will be evaluated.

=back

=head1 Notebook Pane

=over 2

=item Exprs

 This is a list of expressions that are evaluated each time the
 debugger stops. The results of the expresssion are presented
 hierarchically for expression that result in hashes or lists.  Double
 clicking on such an expression will cause it to collapse; double
 clicking again will cause the expression to expand. Expressions are
 entered through B<Enter Expr> entry, or by Alt-E when text is
 selected in the code pane.

 The B<Quick Expr> entry, will take an expression, evaluate it, and
 replace the entries contents with the result.  The result is also
 transfered to the 'clipboard' for pasting.

=item Subs

 Displays a list of all the packages invoked with the script
 heirarchially. At the bottom of the heirarchy are the subroutines
 within the packages.  Double click on a package to expand
 it. Subroutines are listed by their full package names.

=item BrkPts

 Presents a list of the breakpoints current in use. The pushbutton
 allows a breakpoint to be 'disabled' without removing it. Expressions
 can be applied to the breakpoint.  If the expression evaluates to be
 'true'(results in a defined value that is not 0) the debugger will
 stop the script.  Pressing the 'Goto' button will set the text pane
 to that file and line where the breakpoint is set.  Pressing the
 'Delete' button will delete the breakpoint.

=back

=head1 Menus

=head2 File Menu

=over

=item About...

Presents a dialog box telling you about the version of ptkdb.  It
recovers your OS name, version of perl, version of Tk, and some other
information

=item Open

Presents a list of files that are part of the invoked perl
script. Selecting a file from this list will present this file in the
text window.

=item Save Config...

Requires Data::Dumper. Prompts for a filename to save the
configuration to. Saves the breakpoints, expressions, eval text and
window geometry. If the name given as the default is used and the
script is reinvoked, this configuration will be reloaded
automatically.

    B<NOTE:>  You may find this preferable to using 

=item Restore Config...

Requires Data::Dumper.  Prompts for a filename to restore a configuration saved with
the "Save Config..." menu item.  

=item Goto Line...

Prompts for a line number.  Pressing the "Okay" button sends the window to the line number entered.
item Find Text...

Prompts for text to search for.  Options include forward search,
backwards search, and regular expression searching.

=item Quit

 Causes the debugger and the target script to exit. 

=back

=head2 Control Menu

=over

=item Run

The debugger allows the script to run to the next breakpoint or until the script exits.
item Run To Here

Runs the debugger until it comes to wherever the insertion cursor
in text window is placed.

=item Set Breakpoint

Sets a breakpoint on the line at the insertion cursor.  
item Clear Breakpoint

Remove a breakpoint on the at the insertion cursor.

=item Clear All Breakpoints

Removes all current breakpoints

=item Step Over

Causes the debugger to step over the next line.  If the line is a
subroutine call it steps over the call, stopping when the subroutine
returns.

=item Step In

Causes the debugger to step into the next line.  If the line is a
subroutine call it steps into the subroutine, stopping at the first
executable line within the subroutine.

=item Return

Runs the script until it returns from the currently executing
subroutine.  

=item Restart

Saves the breakpoints and expressions in a temporary file and restarts
the script from the beginning.  CAUTION: This feature will not work
properly with debugging of CGI Scripts.

=item Stop On Warning

When C<-w> is enabled the debugger will stop when warnings such as, "Use
of uninitialized value at undef_warn.pl line N" are encountered.  The debugger
will stop on the NEXT line of execution since the error can't be detected
until the current line has executed.  

This feature can be turned on at startup by adding:

$DB::ptkdb::stop_on_warning = 1 ;

to a .ptkdbrc file

=back

=head2 Data Menu

=over

=item Enter Expression

When an expression is entered in the "Enter Expression:" text box,
selecting this item will enter the expression into the expression
list.  Each time the debugger stops this expression will be evaluated
and its result updated in the list window.

=item Delete Expression

 Deletes the highlighted expression in the expression window.

=item Delete All Expressions

 Delete all expressions in the expression window.

=item Expression Eval Window

Pops up a two pane window. Expressions of virtually unlimitted length
can be entered in the top pane.  Pressing the 'Eval' button will cause
the expression to be evaluated and its placed in the lower pane. If
Data::Dumper is available it will be used to format the resulting
text.  Undo is enabled for the text in the upper pane.

HINT:  You can enter multiple expressions by separating them with commas.  

=item Use Data::Dumper for Eval Window

Enables or disables the use of Data::Dumper for formatting the results
of expressions in the Eval window.  

=back

=head2 Stack Menu

Maintains a list of the current subroutine stack each time the
debugger stops. Selecting an item from this menu will set the text in
the code window to that particular subourtine entry point.

=head2 Bookmarks Menu

Maintains a list of bookmarks.  The booksmarks are saved in ~/.ptkdb_bookmarks

=over

=item Add Bookmark

Adds a bookmark to the bookmark list.  

=back

=head1 Options

Here is a list of the current active XResources options. Several of
these can be overridden with environmental variables. Resources can be
added to .Xresources or .Xdefaults depending on your X configuration.
To enable these resources you must either restart your X server or use
the xrdb -override resFile command.  xfontsel can be used to select
fonts.

    /*
    * Perl Tk Debugger XResources.   
    * Note... These resources are subject to change.   
    *
    * Use 'xfontsel' to select different fonts.
    *
    * Append these resource to ~/.Xdefaults | ~/.Xresources
    * and use xrdb -override ~/.Xdefaults | ~/.Xresources
    * to activate them. 
    */
    /* Set Value to se to place scrollbars on the right side of windows 
  CAUTION:  extra whitespace at the end of the line is causing
    failures with Tk800.011.
    
    sw -> puts scrollbars on left, se puts scrollars on the right
    
    */
    ptkdb*scrollbars: sw
    /* controls where the code pane is oriented, down the left side, or across the top */
    /* values can be set to left, right, top, bottom */
    ptkdb*codeside: left
    
    /*
    * Background color for the balloon
    * CAUTION:  For certain versions of Tk trailing
    * characters after the color produces an error
    */
    ptkdb.frame2.frame1.rotext.balloon.background: green
    ptkdb.frame2.frame1.rotext.balloon.font: fixed                       /* Hot Variable Balloon Font */
    
    
    ptkdb.frame*font: fixed                           /* Menu Bar */
    ptkdb.frame.menubutton.font: fixed                /* File menu */
    ptkdb.frame2.frame1.rotext.font: fixed            /* Code Pane */
    ptkdb.notebook.datapage.frame1.hlist.font: fixed  /* Expression Notebook Page */
    
    ptkdb.notebook.subspage*font: fixed               /* Subroutine Notebook Page */
    ptkdb.notebook.brkptspage*entry.font: fixed       /* Delete Breakpoint Buttons */
    ptkdb.notebook.brkptspage*button.font: fixed      /* Breakpoint Expression Entries */
    ptkdb.notebook.brkptspage*button1.font: fixed     /* Breakpoint Expression Entries */
    ptkdb.notebook.brkptspage*checkbutton.font: fixed /* Breakpoint Checkbuttons */
    ptkdb.notebook.brkptspage*label.font: fixed       /* Breakpoint Checkbuttons */
    
    ptkdb.toplevel.frame.textundo.font: fixed         /* Eval Expression Entry Window */
    ptkdb.toplevel.frame1.text.font: fixed            /* Eval Expression Results Window */
    ptkdb.toplevel.button.font:  fixed                /* "Eval..." Button */
    ptkdb.toplevel.button1.font: fixed                /* "Clear Eval" Button */
    ptkdb.toplevel.button2.font: fixed                /* "Clear Results" Button */
    ptkdb.toplevel.button3.font: fixed                /* "Clear Dismiss" Button */
    
    /*
    * Background color for where the debugger has stopped 
    */  
    ptkdb*stopcolor: blue
    
    /*
    * Background color for set breakpoints  
    */
    ptkdb*breaktagcolor*background: yellow
    ptkdb*disabledbreaktagcolor*background: white
    /*
    * Font for where the debugger has stopped
    */
    ptkdb*stopfont: -*-fixed-bold-*-*-*-*-*-*-*-*-*-*-*
    
    /*
    * Background color for the search tag
    */  
    ptkdb*searchtagcolor: green

=head1 Environmental Variables

=over 4

=item PTKDB_BRKPT_COLOR

Sets the background color of a set breakpoint

=item PTKDB_DISABLEDBRKPT_COLOR

Sets the background color of a disabled breakpoint

=item PTKDB_CODE_FONT

Sets the font of the Text in the code pane.

=item PTKDB_CODE_SIDE

Sets which side the code pane is packed onto.  Defaults to 'left'.
Can be set to 'left', 'right', 'top', 'bottom'.  

Overrides the Xresource ptkdb*codeside: I<side>.

=item PTKDB_EXPRESSION_FONT

 Sets the font used in the expression notebook page.

=item PTKDB_EVAL_FONT

 Sets the font used in the Expression Eval Window

=item PTKDB_EVAL_DUMP_INDENT

 Sets the value used for Data::Dumper 'indent' setting. See man Data::Dumper

=item PTKDB_SCROLLBARS_ONRIGHT

 A non-zero value Sets the scrollbars of all windows to be on the
 right side of the window. Useful for Windows users using ptkdb in an
 X environment.

=item PTKDB_LINENUMBER_FORMAT

Sets the format of line numbers on the left side of the window.  Default value is %05d.  useful
if you have a script that contains more than 99999 lines.  

=item PTKDB_DISPLAY

Sets the X display that the ptkdb window will appear on when invoked.  Useful for debugging CGI
scripts on remote systems.  

=item PTKDB_BOOKMARKS_PATH

Sets the path of the bookmarks file.  Default is $ENV{'HOME'}/.ptkdb_bookmarks

=item PTKDB_STOP_TAG_COLOR

Sets the color that highlights the line where the debugger is stopped 

=back

=head1 FILES

=head2 .ptkdbrc

If this file is present in ~/ or in the directory where perl is
invoked the file will be read and executed as a perl script before the
debugger makes its initial stop at startup.  There are several 'api'
calls that can be used with such scripts. There is an internal
variable $DB::no_stop_at_start that may be set to non-zero to prevent
the debugger from stopping at the first line of the script.  This is
useful for debugging CGI scripts.

There is a system ptkdbrc file in $PREFIX/lib/perl5/$VERS/Devel/ptkdbrc

=over 4

=item brkpt($fname, @lines)

Sets breakspoints on the list of lines in $fname.  A warning message
is generated if a line is not breakable.

=item condbrkpt($fname, @($line, $expr) ) 

Sets conditional breakpoints in $fname on pairs of $line and $expr. A
warning message is generated if a line is not breakable.  NOTE: the
validity of the expression will not be determined until execution of
that particular line.

=item brkonsub(@names)

Sets a breakpoint on each subroutine name listed. A warning message is
generated if a subroutine does not exist.  NOTE: for a script with no
other packages the default package is "main::" and the subroutines
would be "main::mySubs".

=item brkonsub_regex(@regExprs)

Uses the list of @regExprs as a list of regular expressions to set breakpoints.  Sets breakpoints 
on every subroutine that matches any of the listed regular expressions.

=item textTagConfigure(tag, ?option?, ?value?)

Allows the user to format the text in the code window. The option
value pairs are the same values as the option for the tagConfigure
method documented in Tk::Text. Currently the following tags are in
effect:

    
    'code'               Format for code in the text pane
    'stoppt'             Format applied to the line where the debugger is currently stopped
    'breakableLine'      Format applied to line numbers where the code is 'breakable'
    'nonbreakableLine'   Format applied to line numbers where the code is no breakable
    'breaksetLine'       Format applied to line numbers were a breakpoint is set
    'breakdisabledLine'  Format applied to line numbers were a disabled breakpoint is set
    'search_tag'         Format applied to text when located by a search.  

 Example:

 #
 # Turns off the overstrike on lines that you can't set a breakpoint on
 # and makes the text color yellow. 
 #
    textTagConfigure('nonbreakableLine', -overstrike => 0, -foreground => "yellow") ;

=item add_exprs(@exprList)

Add a list of expressions to the 'Exprs' window. NOTE: use the single
quote character \' to prevent the expression from being "evaluated" in
the string context.


  Example:

    #
    # Adds the $_ and @_ expressions to the active list
    #

    add_exprs('$_', '@_') ;

=back

=head1 NOTES

=head2 Debugging Other perlTk Applications

ptkdb can be used to debug other perlTk applications if some cautions
are observed. Basically, do not click the mouse in the application's
window(s) when you've entered the debugger and do not click in the
debugger's window(s) while the application is running.  Doing either
one is not necessarily fatal, but it can confuse things that are going
on and produce unexpected results.

Be aware that most perlTk applications have a central event loop.
User actions, such as mouse clicks, key presses, window exposures, etc
will generate 'events' that the script will process. When a perlTk
application is running, its 'MainLoop' call will accept these events
and then dispatch them to appropriate callbacks associated with the
appropriate widgets.

Ptkdb has its own event loop that runs whenever you've stopped at a
breakpoint and entered the debugger. However, it can accept events
that are generated by other perlTk windows and dispatch their
callbacks.  The problem here is that the application is supposed to be
'stopped', and logically the application should not be able to process
events.

A future version of ptkdb will have an extension that will 'filter'
events so that application events are not processed while the debugger
is active, and debugger events will not be processed while the target
script is active.

=head2 Debugging CGI Scripts

One advantage of ptkdb over the builtin debugger(-d) is that it can be
used to debug CGI perl scripts as they run on a web server. Be sure
that that your web server's perl instalation includes Tk.

Change your

  #! /usr/local/bin/perl

to

  #! /usr/local/bin/perl -d:ptkdb

TIP: You can debug scripts remotely if you're using a unix based
Xserver and where you are authoring the script has an Xserver.  The
Xserver can be another unix workstation, a Macintosh or Win32 platform
with an appropriate X package.  In your script insert the
following BEGIN subroutine:

    sub BEGIN {
      $ENV{'DISPLAY'} = "myHostname:0.0" ;
    }

Be sure that your web server has permission to open windows on your
Xserver (see the xhost manpage).

Access your web page with your browswer and 'submit' the script as
normal.  The ptkdb window should appear on myHostname's monitor. At
this point you can start debugging your script.  Be aware that your
browser may timeout waiting for the script to run.

To expedite debugging you may want to setup your breakpoints in
advance with a .ptkdbrc file and use the $DB::no_stop_at_start
variable.  NOTE: for debugging web scripts you may have to have the
.ptkdbrc file installed in the server account's home directory (~www)
or whatever username your webserver is running under.  Also try
installing a .ptkdbrc file in the same directory as the target script.

=head1 KNOWN PROBLEMS

=over

=item I<Breakpoint Controls>

If the size of the right hand pane is too small the breakpoint controls
are not visible.  The breakpoints are still there, the window may have
to be enlarged in order for them to be visible.  

=item Balloons and Tk400

The Balloons in Tk400 will not work with ptkdb.  All other functions
are supported, but the Balloons require Tk800 or higher.

=back

=head1 AUTHOR

Andrew E. Page, aepage@users.sourceforge.net

=head1 ACKNOWLEDGEMENTS

Matthew Persico    For suggestions, and beta testing.

=head1 BUG REPORTING

Please report bugs through the following URL:

http://sourceforge.net/tracker/?atid=437609&group_id=43854&func=browse

=cut


require 5.004 ;


##
## Perform a check to see if we have the Tk library, if not, attempt
## to load it for the user
##

sub BEGIN {

eval {
require Tk  ;
} ;
if( $@ ) {
print << "__PTKDBTK_INSTALL__" ;
***
*** The PerlTk library could not be found.  Ptkdb requires the PerlTk library.
***
Preferably Tk800.015 or better: 

In order to install this the following conditions must be met:

1.  You have to have access to a C compiler.
2.  You must have sufficient permissions to install the libraries on your system.

To install PerlTk:

a  Download the Tk library source from http://www.perl.com/CPAN/modules/by-category/08_User_Interfaces/Tk
b  Uncompress the archive and run "perl Makefile.PL"
c  run "make install"

   If this process completes successfully ptkdb should be operational now.  

We can attempt to run the CPAN module for you.  This will, after some questions, download
and install the Tk library automatically.  

Would you like to run the CPAN module? (y/n) 
__PTKDBTK_INSTALL__

my $answer = <STDIN> ;
chomp $answer ;
if( $answer =~ /y|yes/i) {
  require CPAN ;
  CPAN::install Tk ;
} # if

} # if $@


} # end of sub BEGIN 

use Tk 800 ;
use Data::Dumper ;
use FileHandle ;

require Tk::Dialog;
require Tk::TextUndo ;
require Tk::ROText;
require Tk::NoteBook ;
require Tk::HList ;
require Tk::Table ;

use vars qw(@dbline) ;

use Config ;

sub DoBugReport {
	my($str) = 'sourceforge.net/tracker/?atid=437609&group_id=43854&func=browse' ;
	my(@browsers) = qw/netscape mozilla/ ;
	my($fh, $pid, $sh) ;
	
	if( $isWin32 ) {
	    $sh = '' ;
	    @browsers = '"' . $ENV{'PROGRAMFILES'} . '\\Internet Explorer\\IEXPLORE.EXE' . '"' ;
	    
	}
	else {
	    $sh = 'sh' ;
	    $str = "\'http://" . $str . "\'" ;
	}

	$fh = new FileHandle() ;

	for( @browsers ) {
	    $pid = open($fh, "$sh $_ $str 2&> /dev/null |") ;
	    sleep(2) ; 
	     waitpid $pid, 0 ;
	     return if( $? == 0 ) ;
	} 

	print "##\n" ;
	print "## Please submit a bug report through the following URL:\n" ;
	print '##    http://sourceforge.net/tracker/?atid=437609&group_id=43854&func=browse', "\n" ;
	print "##\n" ;	
}

#
# Check to see if the package actually
# exists. If it does import the routines
# and return a true value ;
#
# NOTE:  this needs to be above the 'BEGIN' subroutine,
# otherwise it will not have been compiled by the time
# that it is called by sub BEGIN.
#
sub check_avail {
  my ($mod, @list) = @_ ;

  eval {
    require $mod ; import $mod @list ;
  } ;

  return 0 if $@ ;
  return 1 ;

} # end of check_avail

sub BEGIN {

 $DB::on = 0 ;     
   
 $DB::subroutine_depth = 0 ; # our subroutine depth counter
 $DB::step_over_depth = -1 ;

   #
   # the bindings and font specs for these operations have been placed here
   # to make them accessible to people who might want to customize the 
   # operations.  REF The 'bind.html' file, included in the perlTk FAQ has
   # a fairly good explanation of the binding syntax.  
   # 

   #
   # These lists of key bindings will be applied
   # to the "Step In", "Step Out", "Return" Commands
   #
 $Devel::ptkdb::pathSep = '\x00' ;
 $Devel::ptkdb::pathSepReplacement = "\0x01" ;

 @Devel::ptkdb::step_in_keys = ( '<Shift-F9>', '<Alt-s>', '<Button-3>' ) ; # step into a subroutine
 @Devel::ptkdb::step_over_keys = ( '<F9>', '<Alt-n>', '<Shift-Button-3>' ) ; # step over a subroutine
 @Devel::ptkdb::return_keys   = ( '<Alt-u>', '<Control-Button-3>' ) ; # return from a subroutine
 @Devel::ptkdb::toggle_breakpt_keys = ( '<Alt-b>' ) ; # set or unset a breakpoint

   # Fonts used in the displays
   
   #
   # NOTE:   The environmental variable syntax here works like this:
   # $ENV{'NAME'} accesses the environmental variable "NAME"
   #
   # $ENV{'NAME'} || 'string' results in  $ENV{'NAME'} or 'string' if  $ENV{'NAME'} is not defined.  
   #
   #
   
 @Devel::ptkdb::button_font = $ENV{'PTKDB_BUTTON_FONT'} ? ( "-font" => $ENV{'PTKDB_CODE_FONT'} ) : () ; # font for buttons
 @Devel::ptkdb::code_text_font = $ENV{'PTKDB_CODE_FONT'} ? ( "-font" => $ENV{'PTKDB_CODE_FONT'} ) : () ;

 @Devel::ptkdb::expression_text_font = $ENV{'PTKDB_EXPRESSION_FONT'} ? ( "-font" => $ENV{'PTKDB_EXPRESSION_FONT'} ) : () ;
 @Devel::ptkdb::eval_text_font = $ENV{'PTKDB_EVAL_FONT'} ? ( -font => $ENV{'PTKDB_EVAL_FONT'} ) : () ; # text for the expression eval window

 $Devel::ptkdb::eval_dump_indent = $ENV{'PTKDB_EVAL_DUMP_INDENT'} || 1 ;

   #
   # Windows users are more used to having scroll bars on the right.
   # If they've set PTKDB_SCROLLBARS_ONRIGHT to a non-zero value
   # this will configure our scrolled windows with scrollbars on the right
   #
   # this can also be done by setting:
   #
   # ptkdb*scrollbars: se
   #
   # in the .Xdefaults/.Xresources file on X based systems
   #
   if( exists $ENV{'PTKDB_SCROLLBARS_ONRIGHT'} && $ENV{'PTKDB_SCROLLBARS_ONRIGHT'} ) {
   @Devel::ptkdb::scrollbar_cfg = ('-scrollbars' => 'se') ;
   }
   else {
   @Devel::ptkdb::scrollbar_cfg = ( ) ;
   }

   #
   # Controls how far an expression result will be 'decomposed'.   Setting it
   # to 0 will take it down only one level, setting it to -1 will make it 
   # decompose it all the way down. However, if you have a situation where
   # an element is a ref   back to the array or a root of the array
   # you could hang the debugger by making it recursively evaluate an expression
   #
 $Devel::ptkdb::expr_depth = -1 ;
 $Devel::ptkdb::add_expr_depth = 1 ; # how much further to expand an expression when clicked

 $Devel::ptkdb::linenumber_format = $ENV{'PTKDB_LINENUMBER_FORMAT'} || "%05d " ;
 $Devel::ptkdb::linenumber_length = 5 ;

 $Devel::ptkdb::linenumber_offset = length sprintf($Devel::ptkdb::linenumber_format, 0) ;
 $Devel::ptkdb::linenumber_offset -= 1 ;

   #
   # Check to see if "Data Dumper" is available
   # if it is we can save breakpoints and other 
   # various "functions". This call will also
   # load the subroutines needed.
   #
 $Devel::ptkdb::DataDumperAvailable = 1 ; # assuming that it is now
 $Devel::ptkdb::useDataDumperForEval = $Devel::ptkdb::DataDumperAvailable ;

   #
   # DB Options (things not directly involving the window)
   #

   # Flag to disable us from intercepting $SIG{'INT'}

 $DB::sigint_disable = defined $ENV{'PTKDB_SIGINT_DISABLE'} && $ENV{'PTKDB_SIGINT_DISABLE'} ;
#
# Possibly for debugging perl CGI Web scripts on
# remote machines.  
#
   $ENV{'DISPLAY'} = $ENV{'PTKDB_DISPLAY'} if exists $ENV{'PTKDB_DISPLAY'} ;

 } # end of BEGIN

##
## subroutine provided to the user for initializing
## files in .ptkdbrc
##
sub brkpt {
  my ($fName, @idx) = @_ ;
  my($offset) ;
  local(*dbline) = $main::{'_<' . $fName} ;

  $offset = $dbline[1] =~ /use\s+.*Devel::_?ptkdb/ ? 1 : 0 ;

  for( @idx ) {
    if( !&DB::checkdbline($fName, $_ + $offset) ) {
      my ($package, $filename, $line) = caller ;
      print "$filename:$line:  $fName line $_ is not breakable\n" ;
      next ;
    }
  $DB::window->insertBreakpoint($fName, $_, 1) ; # insert a simple breakpoint
  }
} # end of brkpt

#
# Set conditional breakpoint(s)
#
sub condbrkpt {
  my ($fname) = shift ;
  my($offset) ;
  local(*dbline) = $main::{'_<' . $fname} ;

  $offset = $dbline[1] =~ /use\s+.*Devel::_?ptkdb/ ? 1 : 0 ;

  while( @_ ) { # arg loop
    my($index, $expr) = splice @_, 0, 2 ; # take args 2 at a time

    if( !&DB::checkdbline($fname, $index + $offset) ) {
      my ($package, $filename, $line) = caller ;
      print "$filename:$line:  $fname line $index is not breakable\n" ;
      next ;
    }
  $DB::window->insertBreakpoint($fname, $index, 1, $expr) ; # insert a simple breakpoint
  } # end of arg loop

} # end of conditionalbrkpt

sub brkonsub {
  my(@names) = @_ ;
  
  for( @names ) {
    
    # get the filename and line number range of the target subroutine
    
    if( !exists $DB::sub{$_} ) {
      print "No subroutine $_.  Try main::$_\n" ;
      next ;
    }

  $DB::sub{$_} =~ /(.*):([0-9]+)-([0-9]+)$/o ; # file name will be in $1, start line $2, end line $3

    for( $2..$3 ) {
      next unless &DB::checkdbline($1, $_) ;
    $DB::window->insertBreakpoint($1, $_, 1) ;
      last ; # only need the one breakpoint
    }
  } # end of name loop

} # end of brkonsub

#
# set breakpoints on subroutines matching a regular
# expression
#
sub brkonsub_regex {
  my(@regexps) = @_ ;
  my($regexp, @subList) ;

  #
  # accumulate matching subroutines
  #
  foreach $regexp ( @regexps ) {
    study $regexp ;
    push @subList, grep /$regexp/, keys %DB::sub ;
  } # end of brkonsub_regex

  brkonsub(@subList) ; # set breakpoints on matching subroutines

} # end of brkonsub_regex

#
# Allow the user Access to our tag configurations
#
sub textTagConfigure {
  my ($tag, @config) = @_ ;

 $DB::window->{'text'}->tagConfigure($tag, @config) ;
  
} # end of textTagConfigure

##
## Change the tabs in the text field
##
sub setTabs {
  
 $DB::window->{'text'}->configure(-tabs => [ @_ ]) ;

}

#
# User .ptkdbrc API
# allows the user to add expressions to
# the expression list window.  
#
sub add_exprs {
  push @{$DB::window->{'expr_list'}}, map { 'expr' => $_, 'depth' => $Devel::ptkdb::expr_depth }, @_ ;
} # end of add_exprs


##
## register a subroutine reference that will be called whenever
## ptkdb sets up it's windows
##
sub register_user_window_init {
  push @{$DB::window->{'user_window_init_list'}}, @_ ;
} # end of register_user_window_init

##
## register a subroutine reference that will be called whenever
## ptkdb enters from code
##
sub register_user_DB_entry {
  push @{$DB::window->{'user_window_DB_entry_list'}}, @_ ;
} # end of register_user_DB_entry

sub get_notebook_widget {
  return $DB::window->{'notebook'} ;
} # end of get_notebook_widget


#
# Run files provided by the user
#
sub do_user_init_files {
  use vars qw($dbg_window) ;
  local $dbg_window = shift ;

  eval {
    do "$Config{'installprivlib'}/Devel/ptkdbrc" ;
  } if -e "$Config{'installprivlib'}/Devel/ptkdbrc" ;

  if( $@ ) {
    print "System init file $Config{'installprivlib'}/ptkdbrc failed: $@\n" ;
  }

  eval {
    do "$ENV{'HOME'}/.ptkdbrc" ;
  } if exists $ENV{'HOME'} && -e "$ENV{'HOME'}/.ptkdbrc" ;

  if( $@ ) {
    print "User init file $ENV{'HOME'}/.ptkdbrc failed: $@\n" ;
  }

  eval {
    do ".ptkdbrc" ;
  } if -e ".ptkdbrc" ;

  if( $@ ) {
    print "User init file .ptkdbrc failed: $@\n" ;
  }

  &set_stop_on_warning() ;
}

#
# Constructor for our Devel::ptkdb
#
sub new {
  my($type) = @_ ;
  my($self) = {} ;
  
  bless $self, $type ;

  # Current position of the executing program

  $self->{DisableOnLeave} = [] ; # List o' Widgets to disable when leaving the debugger

  $self->{current_file} = "" ; 
  $self->{current_line} = -1 ; # initial value indicating we haven't set our line/tag
  $self->{window_pos_offset} = 10 ; # when we enter how far from the top of the text are we positioned down
  $self->{search_start} = "0.0" ;
  $self->{fwdOrBack} = 1 ;
  $self->{BookMarksPath} = $ENV{'PTKDB_BOOKMARKS_PATH'} || "$ENV{'HOME'}/.ptkdb_bookmarks" || '.ptkdb_bookmarks'  ;

  $self->{'expr_list'} = [] ; # list of expressions to eval in our window fields:  {'expr'} The expr itself {'depth'} expansion depth


  $self->{'brkPtCnt'} = 0 ;
  $self->{'brkPtSlots'} = [] ; # open slots for adding breakpoints to the table 

  $self->{'main_window'} = undef ;

  $self->{'user_window_init_list'} = [] ;
  $self->{'user_window_DB_entry_list'} = [] ;

  $self->{'subs_list_cnt'} = 0 ;

  $self->setup_main_window() ;

  return $self ;

} # end of new

sub setup_main_window {
  my($self) = @_ ;

  # Main Window
  

  $self->{main_window} = MainWindow->new() ;
  $self->{main_window}->geometry($ENV{'PTKDB_GEOMETRY'} || "800x600") ;

  $self->setup_options() ; # must be done after MainWindow and before other frames are setup

  $self->{main_window}->bind('<Control-c>', \&DB::dbint_handler) ;

  #
  # Bind our 'quit' routine to a close command from the window manager (Alt-F4) 
  # 
  $self->{main_window}->protocol('WM_DELETE_WINDOW', sub { $self->close_ptkdb_window() ; } ) ;

  # Menu bar

  $self->setup_menu_bar() ;

  #
  # setup Frames
  #
  # Setup our Code, Data, and breakpoints

  $self->setup_frames() ;

}

#
# Check for changes to the bookmarks and quit
#
sub DoQuit {
	my($self) = @_ ;

  $self->save_bookmarks($self->{BookMarksPath}) if $Devel::ptkdb::DataDumperAvailable && $self->{'bookmarks_changed'};
	$self->{main_window}->destroy if $self->{main_window} ; 
	$self->{main_window} = undef if defined $self->{main_window} ; 

	exit ;
}

#
# This supports the File -> Open menu item
# We create a new window and list all of the files
# that are contained in the program.  We also
# pick up all of the perlTk files that are supporting
# the debugger.  
#
sub DoOpen {
  my $self = shift ;
  my ($topLevel, $listBox, $frame, $selectedFile, @fList) ;

  #
  # subroutine we call when we've selected a file
  #

  my $chooseSub = sub { $selectedFile = $listBox->get('active') ;
                        print "attempting to open $selectedFile\n" ;
                      $DB::window->set_file($selectedFile, 0) ;
                        destroy $topLevel ; 
                      } ;

  #
  # Take the list the files and resort it.  
  # we put all of the local files first, and
  # then list all of the system libraries.
  #
  @fList = sort { 
    # sort comparison function block
    my $fa = substr($a, 0, 1) ;
    my $fb = substr($b, 0, 1) ;

    return $a cmp $b if ($fa eq '/') && ($fb eq '/') ;

    return -1 if ($fb eq '/') && ($fa ne '/') ;
    return 1 if ($fa eq '/' ) && ($fb ne '/') ;

    return $a cmp $b ;

  } grep s/^_<//, keys %main:: ;

  #
  # Create a list box with all of our files
  # to select from
  #
  $topLevel = $self->{main_window}->Toplevel(-title => "File Select", -overanchor => 'cursor') ;

  $listBox = $topLevel->Scrolled('Listbox', 
                               @Devel::ptkdb::scrollbar_cfg,
                               @Devel::ptkdb::expression_text_font,
                                -width => 30)->pack(-side => 'top', -fill => 'both', -expand => 1) ;


  # Bind a double click on the mouse button to the same action
  # as pressing the Okay button

  $listBox->bind('<Double-Button-1>' => $chooseSub) ;
  
  $listBox->insert('end', @fList) ;

  $topLevel->Button( -text => "Okay", -command => $chooseSub, @Devel::ptkdb::button_font,
                     )->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  $topLevel->Button( -text => "Cancel", @Devel::ptkdb::button_font,
                     -command => sub { destroy $topLevel ; } )->pack(-side => 'left', -fill => 'both', -expand => 1) ;
} # end of DoOpen

sub do_tabs {
  my($tabs_str) ;
  my($w, $result, $tabs_cfg) ;
  require Tk::Dialog ;

  $w = $DB::window->{'main_window'}->DialogBox(-title => "Tabs", -buttons => [qw/Okay Cancel/]) ;
  
  $tabs_cfg = $DB::window->{'text'}->cget(-tabs) ;

  $tabs_str = join " ", @$tabs_cfg if $tabs_cfg ;

  $w->add('Label', -text => 'Tabs:')->pack(-side => 'left') ;

  $w->add('Entry', -textvariable => \$tabs_str)->pack(-side => 'left')->selectionRange(0,'end') ;

  $result = $w->Show() ;

  return unless $result eq 'Okay' ;

 $DB::window->{'text'}->configure(-tabs => [ split /\s/, $tabs_str ]) ;
}

sub close_ptkdb_window {
  my($self) = @_ ;

  $DB::window->{'event'} = 'run' ;
  $self->{current_file} = "" ; # force a file reset
  $self->{'main_window'}->destroy ;
  $self->{'main_window'} = undef ;
}

sub setup_menu_bar {
  my ($self) = @_ ;
  my $mw = $self->{main_window} ;
  my ($mb, $items) ;
  
  #
  # We have menu items/features that are not available if the Data::DataDumper module
  # isn't present.  For any feature that requires it we add this option list.
  #
  my @dataDumperEnableOpt = ( state => 'disabled' ) unless $Devel::ptkdb::DataDumperAvailable ;


  $self->{menu_bar} = $mw->Frame(-relief => 'raised', -borderwidth => '1')->pack(-side => 'top', -fill => 'x') ;

  $mb = $self->{menu_bar} ;

  # file menu in menu bar

  $items = [ [ 'command' => 'About...', -command => sub { $self->DoAbout() ; } ],
						 [ 'command' => 'Bug Report...', -command => \&DoBugReport ],
             "-",

             [ 'command' => 'Open', -accelerator => 'Alt+O',
               -underline => 0,
               -command => sub { $self->DoOpen() ; } ],

             [ 'command' => 'Save Config...', 
               -underline => 0,
               -command => \&DB::SaveState,
               @dataDumperEnableOpt ],

             [ 'command' => 'Restore Config...',
               -underline => 0,
               -command => \&DB::RestoreState,
               @dataDumperEnableOpt ],

             [ 'command' => 'Goto Line...',
               -underline => 0,
               -accelerator => 'Alt-g',
               -command => sub { $self->GotoLine() ; },
               @dataDumperEnableOpt ] ,

             [ 'command' => 'Find Text...',
               -accelerator => 'Ctrl-f',
               -underline => 0,
               -command => sub { $self->FindText() ; } ],

             [ 'command' => "Tabs...", -command => \&do_tabs ],

             "-",

             [ 'command' => 'Close Window and Run', -accelerator => 'Alt+W',
               -underline => 6, -command => sub { $self->close_ptkdb_window ; } ],
             
             [ 'command' => 'Quit...', -accelerator => 'Alt+Q',
               -underline => 0,
               -command => sub { $self->DoQuit } ]
             ] ;

                 
  $mw->bind('<Alt-g>' =>  sub { $self->GotoLine() ; }) ;
  $mw->bind('<Control-f>' => sub { $self->FindText() ; }) ;
  $mw->bind('<Control-r>' => \&Devel::ptkdb::DoRestart) ;
  $mw->bind('<Alt-q>' => sub { $self->{'event'} = 'quit' } ) ;
  $mw->bind('<Alt-w>' => sub { $self->close_ptkdb_window ; }) ;

  $self->{file_menu_button} = $mb->Menubutton(-text => 'File',
                                              -underline => 0,
                                              -menuitems => $items
                                              )->pack(-side =>, 'left',
                                                      -anchor => 'nw',
                                                      -padx => 2) ;

  # Control Menu

  my $runSub = sub { $DB::step_over_depth = -1 ; $self->{'event'} = 'run' } ;

  my $runToSub = sub { $DB::window->{'event'} = 'run' if  $DB::window->SetBreakPoint(1) ; } ;

  my $stepOverSub = sub { &DB::SetStepOverBreakPoint(0) ; 
                        $DB::single = 1 ; 
                        $DB::window->{'event'} = 'step' ; 
                        } ;
  

  my $stepInSub = sub { 
                      $DB::step_over_depth = -1 ; 
                      $DB::single = 1 ; 
                      $DB::window->{'event'} = 'step' ; } ;


  my $returnSub =  sub { 
    &DB::SetStepOverBreakPoint(-1) ;
    $self->{'event'} = 'run' ;
  } ;


  $items = [ [ 'command' => 'Run', -accelerator => 'Alt+r', -underline => 0, -command => $runSub ],
             [ 'command' => 'Run To Here', -accelerator => 'Alt+t', -underline => 5, -command => $runToSub ],
             '-',
             [ 'command' =>  'Set Breakpoint', -underline => 4, -command => sub { $self->SetBreakPoint ; }, -accelerator => 'Ctrl-b' ],
             [ 'command' => 'Clear Breakpoint', -command => sub { $self->UnsetBreakPoint } ],
             [ 'command' => 'Clear All Breakpoints', -underline => 6, -command => sub {     
             $DB::window->removeAllBreakpoints($DB::window->{current_file}) ;
               &DB::clearalldblines() ;
             } ],
             '-',
             [ 'command' => 'Step Over', -accelerator => 'Alt+N', -underline => 0, -command => $stepOverSub ],
             [ 'command' => 'Step In', -accelerator => 'Alt+S', -underline => 5, -command => $stepInSub ],
             [ 'command' => 'Return', -accelerator => 'Alt+U', -underline => 3, -command => $returnSub ],
             '-',
             [ 'command' => 'Restart...', -accelerator => 'Ctrl-r', -underline => 0, -command => \&Devel::ptkdb::DoRestart ],
             '-',
             [ 'checkbutton' => 'Stop On Warning', -variable => \$DB::ptkdb::stop_on_warning, -command => \&set_stop_on_warning ]

             
               ] ; # end of control menu items

  
  $self->{control_menu_button} = $mb->Menubutton(-text => 'Control',
                                                 -underline => 0,
                                                 -menuitems => $items,
                                                 )->pack(-side =>, 'left',
                                                         -padx => 2) ;


  $mw->bind('<Alt-r>' => $runSub) ;
  $mw->bind('<Alt-t>', $runToSub) ;
  $mw->bind('<Control-b>', sub { $self->SetBreakPoint ; }) ;

  for( @Devel::ptkdb::step_over_keys ) {
    $mw->bind($_ => $stepOverSub );
  }

  for( @Devel::ptkdb::step_in_keys ) {
    $mw->bind($_ => $stepInSub );
  }

  for( @Devel::ptkdb::return_keys ) {
    $mw->bind($_ => $returnSub );
  }

  # Data Menu

  $items = [ [ 'command' => 'Enter Expression', -accelerator => 'Alt+E', -command => sub { $self->EnterExpr() } ],
             [ 'command' => 'Delete Expression', -accelerator => 'Ctrl+D', -command => sub { $self->deleteExpr() } ],
             [ 'command' => 'Delete All Expressions',  -command => sub { 
                                       $self->deleteAllExprs() ;
                                       $self->{'expr_list'} = [] ; # clears list by dropping ref to it, replacing it with a new one  
                                     } ],
             '-',
             [ 'command' => 'Expression Eval Window...', -accelerator => 'F8', -command => sub { $self->setupEvalWindow() ; } ],
             [ 'checkbutton' => "Use DataDumper for Eval Window?", -variable => \$Devel::ptkdb::useDataDumperForEval, @dataDumperEnableOpt ]
              ] ;


  $self->{data_menu_button} = $mb->Menubutton(-text => 'Data', -menuitems => $items,
                                              -underline => 0,
                                              )->pack(-side => 'left',
                                                      -padx => 2) ;

  $mw->bind('<Alt-e>' => sub { $self->EnterExpr() } ) ;
  $mw->bind('<Control-d>' => sub { $self->deleteExpr() } );
  $mw->bind('<F8>', sub { $self->setupEvalWindow() ; }) ;
  #
  # Stack menu
  #
  $self->{stack_menu} = $mb->Menubutton(-text => 'Stack',
                                        -underline => 2,
                                        )->pack(-side => 'left',
                                                -padx => 2) ;

  #
  # Bookmarks menu
  #
  $self->{bookmarks_menu} = $mb->Menubutton(-text => 'Bookmarks',
                                            -underline => 0,
                                            @dataDumperEnableOpt
                                            )->pack(-side => 'left',
                                                    -padx => 2) ;
  $self->setup_bookmarks_menu() ;

  #
  # Windows Menu
  #
  my($bsub) = sub { $self->{'text'}->focus() } ;
  my($csub) = sub { $self->{'quick_entry'}->focus() } ;
  my($dsub) = sub { $self->{'entry'}->focus() } ;

  $items = [ [ 'command' => 'Code Pane', -accelerator => 'Alt+0', -command => $bsub ],
             [ 'command' => 'Quick Entry', -accelerator => 'F9', -command => $csub ],
             [ 'command' => 'Expr Entry', -accelerator => 'F11', -command => $dsub ]
             ] ;

  $mb->Menubutton(-text => 'Windows', -menuitems => $items
                  )->pack(-side => 'left',
                          -padx => 2) ;

  $mw->bind('<Alt-0>', $bsub) ;
  $mw->bind('<F9>', $csub) ;
  $mw->bind('<F11>', $dsub) ;

  #
  # Bar for some popular controls
  #

  $self->{button_bar} = $mw->Frame()->pack(-side => 'top') ;

  $self->{stepin_button} = $self->{button_bar}->Button(-text, => "Step In", @Devel::ptkdb::button_font,
                                                       -command => $stepInSub) ;
  $self->{stepin_button}->pack(-side => 'left') ;

  $self->{stepover_button} = $self->{button_bar}->Button(-text, => "Step Over", @Devel::ptkdb::button_font,
                                                         -command => $stepOverSub) ;
  $self->{stepover_button}->pack(-side => 'left') ;

  $self->{return_button} = $self->{button_bar}->Button(-text, => "Return", @Devel::ptkdb::button_font,
                                                       -command => $returnSub) ;
  $self->{return_button}->pack(-side => 'left') ;

  $self->{run_button} = $self->{button_bar}->Button(-background => 'green', -text, => "Run", @Devel::ptkdb::button_font,
                                                    -command => $runSub) ;
  $self->{run_button}->pack(-side => 'left') ;

  $self->{run_to_button} = $self->{button_bar}->Button(-text, => "Run To", @Devel::ptkdb::button_font,
                                                       -command => $runToSub) ;
  $self->{run_to_button}->pack(-side => 'left') ;

  $self->{breakpt_button} = $self->{button_bar}->Button(-text, => "Break", @Devel::ptkdb::button_font,
                                                        -command => sub { $self->SetBreakPoint ; } ) ;
  $self->{breakpt_button}->pack(-side => 'left') ;

  push @{$self->{DisableOnLeave}}, @$self{'stepin_button', 'stepover_button', 'return_button', 'run_button', 'run_to_button', 'breakpt_button'} ;
  
} # end of setup_menu_bar

sub edit_bookmarks {
  my ($self) = @_ ;

  my ($top) =  $self->{main_window}->Toplevel(-title => "Edit Bookmarks") ;
  
  my $list = $top->Scrolled('Listbox', -selectmode => 'multiple')->pack(-side => 'top', -fill => 'both', -expand => 1) ;
  
  my $deleteSub = sub {
    my $cnt = 0 ;
    for( $list->curselection ) {
      $list->delete($_ - $cnt++) ;
    }
  } ;

  my $okaySub = sub {
    $self->{'bookmarks'} = [ $list->get(0, 'end') ]  ; # replace the bookmarks
  } ;
  
  my $frm = $top->Frame()->pack(-side => 'top', -fill => 'x', -expand => 1 ) ;
  
  my $deleteBtn = $frm->Button(-text => 'Delete', -command => $deleteSub)->pack(-side => 'left', -fill => 'x', -expand => 1 ) ;
  my $cancelBtn = $frm->Button(-text => 'Cancel', -command => sub { destroy $top ; })->pack(-side  =>'left', -fill => 'x', -expand => 1 ) ;
  my $dismissBtn = $frm->Button(-text => 'Okay', -command => $okaySub)->pack(-side => 'left', -fill => 'x', -expand => 1 ) ;
  
  $list->insert('end', @{$self->{'bookmarks'}}) ;

} # end of edit_bookmarks

sub setup_bookmarks_menu {
  my ($self) = @_ ;

  #
  # "Add bookmark" item
  #
  my $bkMarkSub = sub { $self->add_bookmark() ; } ;

  $self->{'bookmarks_menu'}->command(-label => "Add Bookmark",
                                     -accelerator => 'Alt+k',
                                     -command => $bkMarkSub
                                     ) ;

  $self->{'main_window'}->bind('<Alt-k>', $bkMarkSub) ;

  $self->{'bookmarks_menu'}->command(-label => "Edit Bookmarks", 
                                     -command => sub { $self->edit_bookmarks() } ) ;

  $self->{'bookmarks_menu'}->separator() ;

  #
  # Check to see if there is a bookmarks file
  #
  return unless -e $self->{BookMarksPath} && -r $self->{BookMarksPath} ;
  
  use vars qw($ptkdb_bookmarks) ;
  local($ptkdb_bookmarks) ; # ref to hash of bookmark entries

  do $self->{BookMarksPath} ; # eval the file

  $self->add_bookmark_items(@$ptkdb_bookmarks) ;

} # end of setup_bookmarks_menu

#
# $item = "$fname:$lineno"
#
sub add_bookmark_items {
  my($self, @items) = @_ ;
  my($menu) = ( $self->{'bookmarks_menu'} ) ;

  $self->{'bookmarks_changed'} = 1 ;

  for( @items ) {
    my $item = $_ ;
    $menu->command( -label => $_,
                    -command => sub { $self->bookmark_cmd($item) }) ;
    push @{$self->{'bookmarks'}}, $item ;
  }
} # end of add_bookmark_item

#
# Invoked from the "Add Bookmark" command
#
sub add_bookmark {
  my($self) = @_ ;
  
  my $line = $self->get_lineno() ;
  my $fname = $self->{'current_file'} ;
  $self->add_bookmark_items("$fname:$line") ;

} # end of add_bookmark

#
# Command executed when someone selects
# a bookmark
#
sub bookmark_cmd {
  my ($self, $item) = @_ ;

  $item =~ /(.*):([0-9]+)$/ ;

  $self->set_file($1,$2) ;

} # end of bookmark_cmd

sub save_bookmarks {
  my($self, $pathName) = @_ ;

  return unless $Devel::ptkdb::DataDumperAvailable ; # we can't save without the data dumper
  local(*F) ;

  eval {
    open F, ">$pathName" || die "open failed" ;
    my $d = Data::Dumper->new([ $self->{'bookmarks'} ], 
                              [  'ptkdb_bookmarks' ]) ;

    $d->Indent(2) ; # make it more editable for people  

    my $str ;
    if( $d->can('Dumpxs') ) {
      $str = $d->Dumpxs() ;
    }
    else {
      $str = $d->Dump() ;
    }

    print F $str || die "outputing bookmarks failed" ;
    close(F) ;
  } ;

  if( $@ ) {
    $self->DoAlert("Couldn't save bookmarks file $@") ;
    return ;
  }

} # end of save_bookmarks 

#
# This is our callback from a double click in our
# HList.  A click in an expanded item will delete
# the children beneath it, and the next time it
# updates, it will only update that entry to that
# depth.  If an item is 'unexpanded' such as 
# a hash or a list, it will expand it one more
# level.  How much further an item is expanded is
# controled by package variable $Devel::ptkdb::add_expr_depth
#
sub expr_expand {
  my ($path) = @_ ;
  my $hl = $DB::window->{'data_list'} ;
  my ($parent, $root, $index, @children, $depth) ;

  $parent = $path ;
  $root = $path ;
  $depth = 0 ;

  for( $root = $path ; defined $parent && $parent ne "" ; $parent = $hl->infoParent($root) ) {
    $root = $parent ;
    $depth += 1 ;
  } #end of root search

  #
  # Determine the index of the root of our expression
  #
  $index = 0 ;
  for( @{$DB::window->{'expr_list'}} ) {
    last if $_->{'expr'} eq $root ;
    $index += 1 ;
  }

  #
  # if we have children we're going to delete them
  #

  @children = $hl->infoChildren($path) ;

  if( scalar @children > 0 ) {

    $hl->deleteOffsprings($path) ;

  $DB::window->{'expr_list'}->[$index]->{'depth'} = $depth - 1 ; # adjust our depth
  }
  else {
    #
    # Delete the existing tree and insert a new one
    #
    $hl->deleteEntry($root) ;
    $hl->add($root, -at => $index) ;
  $DB::window->{'expr_list'}->[$index]->{'depth'} += $Devel::ptkdb::add_expr_depth ;
    #
    # Force an update on our expressions
    #
  $DB::window->{'event'} = 'update' ;
  }
} # end of expr_expand

sub line_number_from_coord {
  my($txtWidget, $coord) = @_ ;
  my($index) ;
  
  $index = $txtWidget->index($coord) ;

  # index is in the format of lineno.column

  $index =~ /([0-9]*)\.([0-9]*)/o ;

  #
  # return a list of (col, line).  Why
  # backwards?  
  #

  return ($2 ,$1) ;
  
} # end of line_number_from_coord

#
# It may seem as if $txtWidget and $self are
# erroneously reversed, but this is a result
# of the calling syntax of the text-bind callback.  
#
sub set_breakpoint_tag {
  my($txtWidget, $self, $coord, $value) = @_ ;
  my($idx) ;

  $idx = line_number_from_coord($txtWidget, $coord) ;

  $self->insertBreakpoint($self->{'current_file'}, $idx, $value) ;

} # end of set_breakpoint_tag

sub clear_breakpoint_tag {
  my($txtWidget, $self, $coord) = @_ ;
  my($idx) ;

  $idx = line_number_from_coord($txtWidget, $coord) ;
  
  $self->removeBreakpoint($self->{'current_file'}, $idx) ;

} # end of clear_breakpoint_tag

sub change_breakpoint_tag {
  my($txtWidget, $self, $coord, $value) = @_ ;
  my($idx, $brkPt, @tagSet) ;

  $idx = line_number_from_coord($txtWidget, $coord) ;

  #
  # Change the value of the breakpoint
  #
  @tagSet = ( "$idx.0", "$idx.$Devel::ptkdb::linenumber_length" ) ;

  $brkPt = &DB::getdbline($self->{'current_file'}, $idx + $self->{'line_offset'}) ;
  return unless $brkPt ;

  #
  # Check the breakpoint tag
  #

  if ( $txtWidget ) {
    $txtWidget->tagRemove('breaksetLine', @tagSet ) ;
    $txtWidget->tagRemove('breakdisabledLine', @tagSet ) ;
  }

  $brkPt->{'value'} = $value ;
  
  if ( $txtWidget ) {
    if ( $brkPt->{'value'} ) {
      $txtWidget->tagAdd('breaksetLine', @tagSet ) ;
    }
    else {
      $txtWidget->tagAdd('breakdisabledLine', @tagSet ) ;    
    }
  }

} # end of change_breakpoint_tag

#
# God Forbid anyone comment something complex and tightly optimized.
#
#  We can get a list of the subroutines from the interpreter
# by querrying the *DB::sub typeglob:  keys %DB::sub
#
# The list appears broken down by module:
#
#  main::BEGIN
#  main::mySub
#  main::otherSub
#  Tk::Adjuster::Mapped
#  Tk::Adjuster::Packed
#  Tk::Button::BEGIN
#  Tk::Button::Enter
#  
#  We would like to break this list down into a heirarchy.
#
#         main                             Tk
#  |        |       |                       |
# BEGIN   mySub  OtherSub          |                 |
#                               Adjuster           Button 
#                             |         |        |        |
#                           Mapped    Packed   BEGIN    Enter
#
#
#  We translate this list into a heirarchy of hashes(say three times fast).
# We take each entry and split it into elements.  Each element is a leaf in the tree.  
# We traverse the tree with the inner for loop.  
# With each branch we check to see if it already exists or
# we create it.  When we reach the last element, this becomes our entry.
# 

#
# An incoming list is potentially 'large' so we
# pass in the ref to it instead.
#
#  New entries can be inserted by providing a $topH
# hash ref to an existing tree.  
#
sub tree_split {
  my ($listRef, $separator, $topH) = @_ ; 
  my ($h, $list_elem) ;

  $topH = {} unless $topH ;

  foreach $list_elem ( @$listRef ) {
    $h = $topH ;
    for( split /$separator/o, $list_elem ) { # Tk::Adjuster::Mapped  -> ( Tk Adjuster Mapped )
      $h->{$_} or $h->{$_} = {} ; # either we have an entry for this OR we create one
      $h = $h->{$_} ;
    }
    @$h{'name', 'path'} = ($_, $list_elem) ; # the last leaf is our entry
  } # end of tree_split loop

  return $topH ;

} # end of tree_split

#
# callback executed when someone double clicks
# an entry in the 'Subs' Tk::Notebook page.
#
sub sub_list_cmd {
  my ($self, $path) = @_ ;
  my ($h) ;
  my $sub_list = $self->{'sub_list'} ;

  if (  $sub_list->info('children', $path)  ) {
    #
    # Delete the children
    #
    $sub_list->deleteOffsprings($path) ;
    return ;
  }

  #
  # split the path up into elements
  # end descend through the tree.
  #
  $h = $Devel::ptkdb::subs_tree ; 
  for ( split /\./o, $path ) {
    $h = $h->{$_} ; # next level down
  }

  #
  # if we don't have a 'name' entry we
  # still have levels to decend through.
  #
  if ( !exists $h->{'name'} ) {
    #
    # Add the next level paths
    #   
    for ( sort keys %$h ) {

      if ( exists $h->{$_}->{'path'} ) {
        $sub_list->add($path . '.' . $_, -text => $h->{$_}->{'path'}) ;
      }
      else {
        $sub_list->add($path . '.' . $_, -text => $_) ;
      }
    }
    return ;
  }

 $DB::sub{$h->{'path'}} =~ /(.*):([0-9]+)-[0-9]+$/o ; # file name will be in $1, line number will be in $2 */

  $self->set_file($1, $2) ;

} # end of sub_list_cmd

sub fill_subs_page {
  my($self) = @_ ;

  $self->{'sub_list'}->delete('all') ; # clear existing entries

  my @list = keys %DB::sub ;

 $Devel::ptkdb::subs_tree = tree_split(\@list, "::") ;

  # setup to level of list

  for ( sort keys %$Devel::ptkdb::subs_tree ) {
    $self->{'sub_list'}->add($_, -text => $_) ;
  } # end of top level loop
}

sub setup_subs_page {
  my($self) = @_ ;

  $self->{'subs_page_activated'} = 1 ;

  $self->{'sub_list'} = $self->{'subs_page'}->Scrolled('HList',  -command => sub { $self->sub_list_cmd(@_) ; } ) ;

  $self->fill_subs_page() ;

  $self->{'sub_list'}->pack(-side => 'left', -fill => 'both', -expand => 1
                            ) ;

  $self->{'subs_list_cnt'} = scalar keys %DB::sub ;


} # end of setup_subs_page


sub check_search_request {
  my($entry, $self, $searchButton, $regexBtn) = @_ ;
  my($txt) = $entry->get ;

  if( $txt =~ /^\s*[0-9]+\s*$/ ) {
    $self->DoGoto($entry) ;
    return ;
  }

  if( $txt =~ /\.\*/ ) { # common regex search pattern
    $self->FindSearch($entry, $regexBtn, 1) ;
    return ;
  }

  # vanilla search
  $self->FindSearch($entry, $searchButton, 0) ;
}

sub setup_search_panel {
  my ($self, $parent, @packArgs) = @_ ;
  my ($frm, $srchBtn, $regexBtn, $entry) ;

  $frm = $parent->Frame() ;

  $frm->Button(-text => 'Goto', -command => sub { $self->DoGoto($entry) })->pack(-side => 'left') ;
  $srchBtn = $frm->Button(-text => 'Search', -command => sub { $self->FindSearch($entry, $srchBtn, 0) ; }
                          )->pack(-side => 'left' ) ;

  $regexBtn = $frm->Button(-text => 'Regex',
                           -command => sub { $self->FindSearch($entry, $regexBtn, 1) ; }
                           )->pack(-side => 'left',
                                   ) ;


  $entry = $frm->Entry(-width => 50)->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  $entry->bind('<Return>', sub { check_search_request($entry, $self, $srchBtn, $regexBtn) ; } ) ;

  $frm->pack(@packArgs) ;

} # end of setup search_panel

sub setup_breakpts_page {
  my ($self) = @_ ;
  require Tk::Table ;

  $self->{'breakpts_page'} = $self->{'notebook'}->add("brkptspage", -label => "BrkPts") ;

  $self->{'breakpts_table'} = $self->{'breakpts_page'}->Table(-columns => 1, -scrollbars => 'se')->
      pack(-side => 'top', -fill => 'both', -expand => 1
           )   ;

  $self->{'breakpts_table_data'} = { } ; # controls addressed by "fname:lineno"

} # end of setup_breakpts_page

sub setup_frames {
  my ($self) = @_ ;
  my $mw = $self->{'main_window'} ;
  my ($txt, $place_holder, $frm) ;
  require Tk::ROText ;
  require Tk::NoteBook ;
  require Tk::HList ;
  require Tk::Balloon ;
  require Tk::Adjuster ;

  # get the side that we want to put the code pane on
  
  my($codeSide) = $ENV{'PTKDB_CODE_SIDE'} || $mw->optionGet("codeside", "") || 'left' ;

  

  $mw->update ; # force geometry manager to map main_window
  $frm = $mw->Frame(-width => $mw->reqwidth()) ; # frame for our code pane and search controls

  $self->setup_search_panel($frm, -side => 'top', -fill => 'x') ;

  #
  # Text window for the code of our currently viewed file
  #
  $self->{'text'} = $frm->Scrolled('ROText',
                                   -wrap => "none",
                                 @Devel::ptkdb::scrollbar_cfg,
                                 @Devel::ptkdb::code_text_font
                                   ) ;


  $txt = $self->{'text'} ;
  for( $txt->children ) {
    next unless (ref $_) =~ /ROText$/ ;
    $self->{'text'} = $_ ;
    last ;
  }

  $frm->packPropagate(0) ;
  $txt->packPropagate(0) ;

  $frm->packAdjust(-side => $codeSide, -fill => 'both', -expand => 1) ;
  $txt->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  # $txt->form(-top => [ $self->{'menu_bar'} ], -left => '%0', -right => '%50') ;
  # $frm->form(-top => [ $self->{'menu_bar'} ], -left => '%50', -right => '%100') ;

  $self->configure_text() ;

  #
  # Notebook
  #

  $self->{'notebook'} = $mw->NoteBook() ;
  $self->{'notebook'}->packPropagate(0) ;
  $self->{'notebook'}->pack(-side => $codeSide, -fill => 'both', -expand => 1) ;

  #
  # an hlist for the data entries
  #
  $self->{'data_page'} = $self->{'notebook'}->add("datapage", -label => "Exprs") ;

  #
  # frame, entry and label for quick expressions
  #
  my $frame = $self->{'data_page'}->Frame()->pack(-side => 'top', -fill => 'x') ;
  
  my $label = $frame->Label(-text => "Quick Expr:")->pack(-side => 'left') ;
  
  $self->{'quick_entry'} = $frame->Entry()->pack(-side => 'left', -fill => 'x', -expand => 1) ;

  $self->{'quick_entry'}->bind('<Return>', sub { $self->QuickExpr() ; } ) ;
  

  #
  # Entry widget for expressions and breakpoints
  #
  $frame = $self->{'data_page'}->Frame()->pack(-side => 'top', -fill => 'x') ;

  $label = $frame->Label(-text => "Enter Expr:")->pack(-side => 'left') ;

  $self->{'entry'} = $frame->Entry()->pack(-side => 'left', -fill => 'x', -expand => 1) ;

  $self->{'entry'}->bind('<Return>', sub { $self->EnterExpr() }) ;

  #
  # Hlist for data expressions
  #


  $self->{data_list} = $self->{'data_page'}->Scrolled('HList',
                                                    @Devel::ptkdb::scrollbar_cfg, 
                                                      separator => $Devel::ptkdb::pathSep,
                                                    @Devel::ptkdb::expression_text_font,
                                                      -command => \&Devel::ptkdb::expr_expand,
                                                      -selectmode => 'multiple'
                                                      ) ;

  $self->{data_list}->pack(-side => 'top', -fill => 'both', -expand => 1
                           ) ;


  $self->{'subs_page_activated'} = 0 ;
  $self->{'subs_page'} = $self->{'notebook'}->add("subspage", -label => "Subs", -createcmd => sub { $self->setup_subs_page }) ;

  $self->setup_breakpts_page() ;    

} # end of setup_frames



sub configure_text {
  my($self) = @_ ;
  my($txt, $mw) = ($self->{'text'}, $self->{'main_window'}) ;
  my($place_holder) ;

  $self->{'expr_balloon'} = $txt->Balloon();
  $self->{'balloon_expr'} = ' ' ; # initial expression

  # If Data::Dumper is available setup a dumper for the balloon
  
  if ( $Devel::ptkdb::DataDumperAvailable ) {
    $self->{'balloon_dumper'} = new Data::Dumper([$place_holder]) ;
    $self->{'balloon_dumper'}->Terse(1) ;
    $self->{'balloon_dumper'}->Indent($Devel::ptkdb::eval_dump_indent) ;

    $self->{'quick_dumper'} = new Data::Dumper([$place_holder]) ;
    $self->{'quick_dumper'}->Terse(1) ;
    $self->{'quick_dumper'}->Indent(0) ;
  }
  
  $self->{'expr_ballon_msg'} = ' ' ;
  
  $self->{'expr_balloon'}->attach($txt, -initwait => 300,
                                  -msg => \$self->{'expr_ballon_msg'},
                                  -balloonposition => 'mouse',
                                  -postcommand => \&Devel::ptkdb::balloon_post,
                                  -motioncommand => \&Devel::ptkdb::balloon_motion ) ;
  
  # tags for the text
  
  my @stopTagConfig = ( -foreground => 'white', -background  => $mw->optionGet("stopcolor", "background") || $ENV{'PTKDB_STOP_TAG_COLOR'} || 'blue' ) ;
  
  my $stopFnt = $mw->optionGet("stopfont", "background") || $ENV{'PTKDB_STOP_TAG_FONT'} ;
  push @stopTagConfig, ( -font => $stopFnt ) if $stopFnt ; # user may not have specified a font, if not, stay with the default
  
  $txt->tagConfigure('stoppt', @stopTagConfig) ;
  $txt->tagConfigure('search_tag', "-background" => $mw->optionGet("searchtagcolor", "background") || "green") ;
  
  $txt->tagConfigure("breakableLine", -overstrike => 0) ;
  $txt->tagConfigure("nonbreakableLine", -overstrike => 1) ;
  $txt->tagConfigure("breaksetLine", -background => $mw->optionGet("breaktagcolor", "background") || $ENV{'PTKDB_BRKPT_COLOR'} || 'red') ;
  $txt->tagConfigure("breakdisabledLine", -background => $mw->optionGet("disabledbreaktagcolor", "background") || $ENV{'PTKDB_DISABLEDBRKPT_COLOR'} || 'green') ;
  
  $txt->tagBind("breakableLine", '<Button-1>', [ \&Devel::ptkdb::set_breakpoint_tag, $self, Ev('@'), 1 ]  ) ;
  $txt->tagBind("breakableLine", '<Shift-Button-1>', [ \&Devel::ptkdb::set_breakpoint_tag, $self, Ev('@'), 0 ]  ) ;
  
  $txt->tagBind("breaksetLine", '<Button-1>',  [ \&Devel::ptkdb::clear_breakpoint_tag, $self, Ev('@') ]  ) ;
  $txt->tagBind("breaksetLine", '<Shift-Button-1>',  [ \&Devel::ptkdb::change_breakpoint_tag, $self, Ev('@'), 0 ]  ) ;
  
  $txt->tagBind("breakdisabledLine", '<Button-1>', [ \&Devel::ptkdb::clear_breakpoint_tag, $self, Ev('@') ]  ) ;
  $txt->tagBind("breakdisabledLine", '<Shift-Button-1>', [ \&Devel::ptkdb::change_breakpoint_tag, $self, Ev('@'), 1 ]  ) ;
  
} # end of configure_text


sub setup_options {
  my ($self) = @_ ;
  my $mw = $self->{main_window} ;

  return unless $mw->can('appname') ;
  
  $mw->appname("ptkdb") ;
  $mw->optionAdd("stopcolor" => 'cyan', 60 ) ;
  $mw->optionAdd("stopfont" => 'fixed', 60 ) ;
  $mw->optionAdd("breaktag" => 'red', 60 ) ;
  $mw->optionAdd("searchtagcolor" => 'green') ;
  
  $mw->optionClear ; #  necessary to reload xresources

} # end of setup_options

sub DoAlert {
  my($self, $msg, $title) = @_ ;
  my($dlg) ;
  my $okaySub = sub {
    destroy $dlg ;
  } ;

  $dlg = $self->{main_window}->Toplevel(-title => $title || "Alert", -overanchor => 'cursor') ;

  $dlg->Label( -text => $msg )->pack( -side => 'top' ) ;

  $dlg->Button( -text => "Okay", -command => $okaySub )->pack( -side => 'top' )->focus   ;
  $dlg->bind('<Return>', $okaySub) ;

} # end of DoAlert

sub simplePromptBox {
  my ($self, $title, $defaultText, $okaySub, $cancelSub) = @_ ;
  my ($top, $entry, $okayBtn) ;

  $top = $self->{main_window}->Toplevel(-title => $title, -overanchor => 'cursor' ) ;

 $Devel::ptkdb::promptString = $defaultText ;

  $entry = $top->Entry('-textvariable' => \$Devel::ptkdb::promptString)->pack(-side => 'top', -fill => 'both', -expand => 1) ;
  
  
  $okayBtn = $top->Button( -text => "Okay", @Devel::ptkdb::button_font, -command => sub {  &$okaySub() ; $top->destroy ;}
                           )->pack(-side => 'left', -fill => 'both', -expand => 1) ;
  
  $top->Button( -text => "Cancel", -command => sub { &$cancelSub() if $cancelSub ; $top->destroy() }, @Devel::ptkdb::button_font,
                )->pack(-side => 'left', -fill => 'both', -expand => 1) ;
  
  $entry->icursor('end') ;
  
  $entry->selectionRange(0, 'end') if $entry->can('selectionRange') ; # some win32 Tk installations can't do this

  $entry->focus() ;

  return $top ;
  
} # end of simplePromptBox

sub get_entry_text {
  my($self) = @_ ;
  
  return $self->{entry}->get() ; # get the text in the entry
} # end of get_entry_text


#
# Clear any text that is in the entry field.  If there
# was any text in that field return it.  If there
# was no text then return any selection that may be active.  
#
sub clear_entry_text {
  my($self) = @_ ;
  my $str =  $self->{'entry'}->get() ;
  $self->{'entry'}->delete(0, 'end') ;

  #
  # No String
  # Empty String
  # Or a string that is only whitespace
  #
  if( !$str || $str eq "" || $str =~ /^\s+$/ ) {
    #
    # If there is no string or the string is just white text
    # Get the text in the selction( if any)
    # 
    if( $self->{'text'}->tagRanges('sel') ) { # check to see if 'sel' tag exists (return undef value)
      $str = $self->{'text'}->get("sel.first", "sel.last") ; # get the text between the 'first' and 'last' point of the sel (selection) tag
    }
    # If still no text, bring the focus to the entry
    elsif( !$str || $str eq "" || $str =~ /^\s+$/ ) {
      $self->{'entry'}->focus() ;
      $str = "" ;
    }
  }
  #
  # Erase existing text
  #
  return $str ;
} # end of clear_entry_text

sub brkPtCheckbutton {
  my ($self, $fname, $idx, $brkPt) = @_ ;
  my ($widg) ;

  change_breakpoint_tag($self->{'text'}, $self, "$idx.0", $brkPt->{'value'}) if $fname eq $self->{'current_file'} ;

} # end of brkPtCheckbutton

#
# insert a breakpoint control into our breakpoint list.  
# returns a handle to the control
#
#  Expression, if defined, is to be evaluated at the breakpoint
# and execution stopped if it is non-zero/defined.
#
# If action is defined && True then it will be evalled
# before continuing.  
#
sub insertBreakpoint {
  my ($self, $fname, @brks) = @_ ;
  my ($btn, $cnt, $item) ;

  my($offset) ;

  local(*dbline) = $main::{'_<' . $fname} ;

  $offset = $dbline[1] =~ /use\s+.*Devel::_?ptkdb/ ? 1 : 0 ;

  while( @brks ) {
    my($index, $value, $expression) = splice @brks, 0, 3 ; # take args 3 at a time

    my $brkPt = {} ; 
    my $txt = &DB::getdbtextline($fname, $index) ;
    @$brkPt{'type', 'line',  'expr',      'value', 'fname', 'text'} =
        ('user',   $index, $expression, $value,   $fname,  "$txt") ;

    &DB::setdbline($fname, $index + $offset, $brkPt) ;
    $self->add_brkpt_to_brkpt_page($brkPt) ;

    next unless $fname eq $self->{'current_file'} ;

    $self->{'text'}->tagRemove("breakableLine", "$index.0", "$index.$Devel::ptkdb::linenumber_length") ;    
    $self->{'text'}->tagAdd($value ? "breaksetLine" : "breakdisabledLine",  "$index.0", "$index.$Devel::ptkdb::linenumber_length") ;
  } # end of loop
} # end of insertBreakpoint

sub add_brkpt_to_brkpt_page { 
  my($self, $brkPt) = @_ ;
  my($btn, $fname, $index, $frm, $upperFrame, $lowerFrame) ; 
  my ($row, $btnName, $width) ;
  # 
  # Add the breakpoint to the breakpoints page 
  # 
  ($fname, $index) = @$brkPt{'fname', 'line'} ; 
  return if exists $self->{'breakpts_table_data'}->{"$fname:$index"} ; 
  $self->{'brkPtCnt'} += 1 ; 

  $btnName = $fname ;
  $btnName =~ s/.*\/([^\/]*)$/$1/o ; 

  # take the last leaf of the pathname 
  
  $frm = $self->{'breakpts_table'}->Frame(-relief => 'raised') ; 
  $upperFrame = $frm->Frame()->pack(-side => 'top', '-fill' => 'x', -expand => 1) ; 

  
  $btn = $upperFrame->Checkbutton(-text => "$btnName:$index",
                                  -variable => \$brkPt->{'value'}, # CAUTION value tracking
                                  -command => sub { $self->brkPtCheckbutton($fname, $index, $brkPt) }) ;

  $btn->pack(-side => 'left') ;

  $btn = $upperFrame->Button(-text => "Delete", -command => sub { $self->removeBreakpoint($fname, $index) ; } ) ;
  $btn->pack(-side => 'left', -fill => 'x', -expand => 1) ;
  
  $btn = $upperFrame->Button(-text => "Goto", -command => sub { $self->set_file($fname, $index) ; } ) ;
  $btn->pack(-side => 'left', -fill => 'x', -expand => 1) ;

  $lowerFrame = $frm->Frame()->pack(-side => 'top', '-fill' => 'x', -expand => 1) ;

  $lowerFrame->Label(-text => "Cond:")->pack(-side => 'left') ;
  
  $btn = $lowerFrame->Entry(-textvariable => \$brkPt->{'expr'}) ;
  $btn->pack(-side => 'left', -fill => 'x', -expand => 1) ;
  
  $frm->pack(-side => 'top', -fill => 'x', -expand => 1) ;

  $row = pop @{$self->{'brkPtSlots'}} or $row = $self->{'brkPtCnt'} ;

  $self->{'breakpts_table'}->put($row, 1, $frm) ;
  
  $self->{'breakpts_table_data'}->{"$fname:$index"}->{'frm'} = $frm ;
  $self->{'breakpts_table_data'}->{"$fname:$index"}->{'row'} = $row ;

  $self->{'main_window'}->update ;

  $width = $frm->width ;

  if ( $width > $self->{'breakpts_table'}->width ) {
    $self->{'notebook'}->configure(-width => $width) ;
  }
  
} # end of add_brkpt_to_brkpt_page

sub remove_brkpt_from_brkpt_page {
  my($self, $fname, $idx) = @_ ;
  my($table) ;

  $table = $self->{'breakpts_table'} ;

  # Delete the breakpoint control in the breakpoints window

  $table->put($self->{'breakpts_table_data'}->{"$fname:$idx"}->{'row'}, 1) ; # delete?

  #
  # Add this now empty slot to the list of ones we have open
  #

  push @{$self->{'brkPtSlots'}}, $self->{'breakpts_table_data'}->{"$fname:$idx"}->{'row'} ;

  $self->{'brkPtSlots'} = [ sort { $b <=> $a } @{$self->{'brkPtSlots'}} ] ;
  
  delete $self->{'breakpts_table_data'}->{"$fname:$idx"} ;
  
  $self->{'brkPtCnt'} -= 1 ;

} # end of remove_brkpt_from_brkpt_page


#
# Supporting the "Run To Here..." command
#
sub insertTempBreakpoint {
  my ($self, $fname, $index) = @_ ;
  my($offset) ;
  local(*dbline) = $main::{'_<' . $fname} ;

  $offset = $dbline[1] =~ /use\s+.*Devel::_?ptkdb/ ? 1 : 0 ;

  return if( &DB::getdbline($fname, $index + $offset) ) ; # we already have a breakpoint here

  &DB::setdbline($fname, $index + $offset, {'type' => 'temp', 'line' => $index, 'value' => 1 } ) ;

} # end of insertTempBreakpoint

sub reinsertBreakpoints {
  my ($self, $fname) = @_ ;
  my ($brkPt) ;

  foreach $brkPt ( &DB::getbreakpoints($fname) ) {
    #
    # Our breakpoints are indexed by line
    # therefore we can have 'gaps' where there
    # lines, but not breaks set for them.
    #
    next unless defined $brkPt ;
    
    $self->insertBreakpoint($fname, @$brkPt{'line', 'value', 'expr'}) if( $brkPt->{'type'} eq 'user' ) ;
    $self->insertTempBreakpoint($fname, $brkPt->{line}) if( $brkPt->{'type'} eq 'temp' ) ;
  } # end of reinsert loop

} # end of reinsertBreakpoints

sub removeBreakpointTags {
  my ($self, @brkPts) = @_ ;
  my($idx, $brkPt) ;
  
  foreach $brkPt (@brkPts) {

    $idx = $brkPt->{'line'} ;

    if ( $brkPt->{'value'} ) {
      $self->{'text'}->tagRemove("breaksetLine", "$idx.0", "$idx.$Devel::ptkdb::linenumber_length") ;
    }
    else {
      $self->{'text'}->tagRemove("breakdisabledLine", "$idx.0", "$idx.$Devel::ptkdb::linenumber_length") ; 
    }
    
    $self->{'text'}->tagAdd("breakableLine", "$idx.0", "$idx.$Devel::ptkdb::linenumber_length") ;         
  }
} # end of removeBreakpointTags

#
# Remove a breakpoint from the current window
#
sub removeBreakpoint {
  my ($self, $fname, @idx) = @_ ;
  my ($idx, $chkIdx, $i, $j, $info) ;
  my($offset) ;
  local(*dbline) = $main::{'_<' . $fname} ;

  $offset = $dbline[1] =~ /use\s+.*Devel::_?ptkdb/ ? 1 : 0 ;

  foreach $idx (@idx) { # end of removal loop
    next unless defined $idx ;
    my $brkPt = &DB::getdbline($fname, $idx + $offset) ;
    next unless $brkPt ; # if we do not have an entry
    &DB::cleardbline($fname, $idx + $offset) ;

    $self->remove_brkpt_from_brkpt_page($fname, $idx) ;

    next unless $brkPt->{fname} eq $self->{'current_file'}  ; # if this isn't our current file there will be no controls

    # Delete the ext associated with the breakpoint expression (if any)    

    $self->removeBreakpointTags($brkPt) ;
  } # end of remove loop
  
  return ;
} # end of removeBreakpoint

sub removeAllBreakpoints {
  my ($self, $fname) = @_ ;
  
  $self->removeBreakpoint($fname, &DB::getdblineindexes($fname)) ;

} # end of removeAllBreakpoints

#
# Delete expressions prior to an update
#
sub deleteAllExprs {
  my ($self) = @_ ;
  $self->{'data_list'}->delete('all') ;
} # end of deleteAllExprs

sub EnterExpr {
  my ($self) = @_ ;
  my $str = $self->clear_entry_text() ;
  if( $str && $str ne "" && $str !~ /^\s+$/ ) { # if there is an expression and it's more than white space
    $self->{'expr'} = $str ;
    $self->{'event'} = 'expr' ;
  }
} # end of EnterExpr

#
#
#
sub QuickExpr {
  my ($self) = @_ ;

  my $str = $self->{'quick_entry'}->get() ;

  if( $str && $str ne "" && $str !~ /^\s+$/ ) { # if there is an expression and it's more than white space
    $self->{'qexpr'} = $str ;
    $self->{'event'} = 'qexpr' ;
  }
} # end of QuickExpr

sub deleteExpr {
  my ($self) = @_ ;
  my ($entry, $i, @indexes) ;
  my @sList = $self->{'data_list'}->info('select') ;

  #
  # if we're deleteing a top level expression
  # we have to take it out of the list of expressions
  #

  foreach $entry ( @sList ) {
    next if ($entry =~ /\//) ; # goto next expression if we're not a top level ( expr/entry)
    $i = 0 ;
    grep { push @indexes, $i if ($_->{'expr'} eq $entry) ; $i++ ; } @{$self->{'expr_list'}} ;
  } # end of check loop
  
  # now take out our list of indexes ;

  for( 0..$#indexes ) {
       splice @{$self->{'expr_list'}}, $indexes[$_] - $_, 1 ;
     }

  for( @sList ) {
    $self->{'data_list'}->delete('entry', $_) ;
  }
} # end of deleteExpr

sub fixExprPath {
  my(@pathList) = @_ ;
  
  for (@pathList) {
    s/$Devel::ptkdb::pathSep/$Devel::ptkdb::pathSepReplacement/go ;
  } # end of path list

  return $pathList[0] unless wantarray ;
  return @pathList ;

} # end of fixExprPath

##
##  Inserts an expression($theRef) into an HList Widget($dl).  If the expression
## is an array, blessed array, hash, or blessed hash(typical object), then this
## routine is called recursively, adding the members to the next level of heirarchy,
## prefixing array members with a [idx] and the hash members with the key name.
## This continues until the entire expression is decomposed to it's atomic constituents.
## Protection is given(with $reusedRefs) to ensure that 'circular' references within
## arrays or hashes(i.e. where a member of a array or hash contains a reference to a
## parent element within the heirarchy.  
##
#
# Returns 1 if sucessfully added 0 if not
#
sub insertExpr {
  my($self, $reusedRefs, $dl, $theRef, $name, $depth, $dirPath) = @_ ;
  my($label, $type, $result, $selfCnt, @circRefs) ;
  local($^W) = 0 ; # spare us uncessary warnings about comparing strings with ==  

  #
  # Add data new data entries to the bottom
  # 
  $dirPath = "" unless defined $dirPath ;

  $label = "" ;
  $selfCnt = 0 ;

  while( ref $theRef eq 'SCALAR' ) {
    $theRef = $$theRef ;
  }
 REF_CHECK: for( ; ; ) {
   push @circRefs, $theRef ;
   $type = ref $theRef ;
   last unless ($type eq "REF")  ;
   $theRef = $$theRef ; # dref again
   
   $label .= "\\" ; # append a 
   if( grep $_ == $theRef, @circRefs ) {
     $label .= "(circular)" ;
     last ;
   }
 }

  if( !$type || $type eq "" || $type eq "GLOB" || $type eq "CODE") {
    eval {
      if( !defined $theRef ) {
        $dl->add($dirPath . $name, -text => "$name = $label" . "undef") ;
      }
      else {
        $dl->add($dirPath . $name, -text => "$name = $label$theRef") ;
      }
    } ;
    $self->DoAlert($@), return 0 if $@ ;
    return 1 ;
  }

  if( $type eq 'ARRAY' or "$theRef" =~ /ARRAY/ ) {
    my ($r, $idx) ;
    $idx = 0 ;
    eval {
      $dl->add($dirPath . $name, -text => "$name = $theRef") ;
    } ;
    if( $@ ) {
      $self->DoAlert($@) ;
      return 0 ;
    }
    $result = 1 ;
    foreach $r ( @{$theRef} ) {

      if( grep $_ == $r, @$reusedRefs ) { # check to make sure that we're not doing a single level self reference
        eval {
          $dl->add($dirPath .  fixExprPath($name) . $Devel::ptkdb::pathSep . "__ptkdb_self_path" . $selfCnt++, -text => "[$idx] = $r REUSED ADDR") ;
        } ;
        $self->DoAlert($@) if( $@ ) ;
        next ;
      }
      
      push @$reusedRefs, $r ;
      $result = $self->insertExpr($reusedRefs, $dl, $r, "[$idx]", $depth-1, $dirPath . fixExprPath($name) . $Devel::ptkdb::pathSep) unless $depth == 0 ;
      pop @$reusedRefs ;

      return 0 unless $result ;
      $idx += 1 ;
    }
    return 1 ;
  } # end of array case

  if(  "$theRef" !~ /HASH\050\060x[0-9a-f]*\051/o ) {
    eval {
      $dl->add($dirPath . fixExprPath($name), -text => "$name = $theRef") ;
    } ;
    if( $@ ) {
      $self->DoAlert($@) ;
      return 0 ;
    }
    return 1 ;
  }
# 
# Anything else at this point is
# either a 'HASH' or an object
# of some kind.
#
  my($r, @theKeys, $idx) ;
  $idx = 0 ;
  @theKeys = sort keys %{$theRef} ;
  $dl->add($dirPath . $name, -text => "$name = " . "$theRef") ;
  $result = 1 ;

  foreach $r ( @$theRef{@theKeys} ) { # slice out the values with the sorted list

    if( grep $_ == $r, @$reusedRefs ) { # check to make sure that we're not doing a single level self reference
      eval {
        $dl->add($dirPath .  fixExprPath($name) . $Devel::ptkdb::pathSep . "__ptkdb_self_path" . $selfCnt++, -text => "$theKeys[$idx++] = $r REUSED ADDR") ;
      } ;
      print "bad path $@\n" if( $@ ) ;
      next ;
    }

    push @$reusedRefs, $r ;

    $result = $self->insertExpr($reusedRefs,                              # recursion protection
                                $dl,                                      # data list widget
                                $r,                                       # reference whose value is displayed
                                $theKeys[$idx],                           # name
                                $depth-1,                                 # remaining expansion depth
                                $dirPath . $name . $Devel::ptkdb::pathSep # path to add to
                                ) unless $depth == 0 ;

    pop @$reusedRefs ;

    return 0 unless $result ;
    $idx += 1 ;
  } # end of ref add loop

  return 1 ;
} # end of insertExpr

#
# We're setting the line where we are stopped.  
# Create a tag for this and set it as bold.  
#
sub set_line {
  my ($self, $lineno) = @_ ;
  my $text = $self->{'text'} ;

  return if( $lineno <= 0 ) ;

  if( $self->{current_line} > 0 ) {
    $text->tagRemove('stoppt', "$self->{current_line}.0 linestart", "$self->{current_line}.0 lineend") ;
  }
  $self->{current_line} = $lineno - $self->{'line_offset'} ;
  $text->tagAdd('stoppt', "$self->{current_line}.0 linestart", "$self->{current_line}.0 lineend") ;

  $self->{'text'}->see("$self->{current_line}.0 linestart") ;
} # end of set_line

#
# Set the file that is in the code window.
#
# $fname the 'new' file to view
# $line the line number we're at
# $brkPts any breakpoints that may have been set in this file
#

use Carp ;

sub set_file {
  my ($self, $fname, $line) = @_ ;
  my ($lineStr, $offset, $text, $i, @text, $noCode, $title) ;
  my (@breakableTagList, @nonBreakableTagList) ;

  return unless $fname ;  # we're getting an undef here on 'Restart...'

  local(*dbline) = $main::{'_<' . $fname};

  #
  # with the #! /usr/bin/perl -d:ptkdb at the header of the file
  # we've found that with various combinations of other options the
  # files haven't come in at the right offsets
  #
  $offset = 0 ;
  $offset = 1 if $dbline[1] =~ /use\s+.*Devel::_?ptkdb/ ;
  $self->{'line_offset'} = $offset ;

  $text = $self->{'text'} ;
   
  if( $fname eq $self->{current_file} ) {
    $self->set_line($line) ;
    return ;
  } ;

	$title = $fname ; # removing the - messes up stashes on -e invocations
  $title =~ s/^\-// ; # Tk does not like leadiing '-'s 
  $self->{main_window}->configure('-title' => $title) ;

  # Erase any existing text

  $text->delete('0.0','end') ;
  
  my $len = $Devel::ptkdb::linenumber_length ;

  #
  # This is the tightest loop we have in the ptkdb code.
  # It is here where performance is the most critical.
  # The map block formats perl code for display.  Since
  # the file could be potentially large, we will try
  # to make this loop as thin as possible. 
  #
  # NOTE:  For a new perl individual this may appear as
  # if it was intentionally obfuscated.  This is not
  # not the case.  The following code is the result
  # of an intensive effort to optimize this code.
  # Prior versions of this code were quite easier
  # to read, but took 3 times longer.
  # 

  $lineStr = " " x 200 ; # pre-allocate space for $lineStr
  $i = 1 ;

  local($^W) = 0 ; # spares us useless warnings under -w when checking $dbline[$_] != 0
  #
  # The 'map' call will build list of 'string', 'tag' pairs
  # that will become arguments to the 'insert' call.  Passing
  # the text to insert "all at once" rather than one insert->('end', 'string', 'tag')
  # call at time provides a MASSIVE savings in execution time.
  #
  $noCode = ($#dbline - ($offset + 1)) < 0 ;

  $text->insert('end', map {
    #
    # build collections of tags representing
    # the line numbers for breakable and 
    # non-breakable lines.  We apply these
    # tags after we've built the text
    #
    
    ($_ != 0 && push @breakableTagList, "$i.0", "$i.$len") || push @nonBreakableTagList, "$i.0", "$i.$len" ;

    $lineStr = sprintf($Devel::ptkdb::linenumber_format, $i++) . $_ ; # line number + text of the line

		substr $lineStr, -2, 1, '' if $isWin32 ; # removes the CR from win32 instances

		$lineStr .= "\n" unless /\n$/o ; # append a \n if there isn't one already

    ($lineStr, 'code') ; # return value for block, a string,tag pair for text insert
    
  } @dbline[$offset+1 .. $#dbline] ) unless $noCode ;
            
  #
  # Apply the tags that we've collected
  # NOTE:  it was attempted to incorporate these
  # operations into the 'map' block above, but that
  # actually degraded performance.  
  #
  $text->tagAdd("breakableLine", @breakableTagList) if @breakableTagList ; # apply tag to line numbers where the lines are breakable
  $text->tagAdd("nonbreakableLine", @nonBreakableTagList) if @nonBreakableTagList ; # apply tag to line numbers where the lines are not breakable.  
            
  #
    # Reinsert breakpoints (if info provided)
    #

    $self->set_line($line) ;
    $self->{current_file} = $fname ;
    return $self->reinsertBreakpoints($fname) ;
} # end of set_file

#
# Get the current line that the insert cursor is in
#
sub get_lineno {
  my ($self) = @_ ; 
  my ($info) ;
  
  $info = $self->{'text'}->index('insert') ; # get the location for the insertion point
  $info =~ s/\..*$/\.0/ ;

  return int $info ;
} # end of get_lineno

sub DoGoto {
  my ($self, $entry) = @_ ;

  my $txt = $entry->get() ;
  
  $txt =~ s/(\d*).*/$1/ ; # take the first blob of digits
  if( $txt eq "" ) {
    print "invalid text range\n" ;
    return if $txt eq "" ;
  }
  
  $self->{'text'}->see("$txt.0") ;
  
  $entry->selectionRange(0, 'end') if $entry->can('selectionRange')

    } # end of DoGoto

sub GotoLine {
  my ($self) = @_ ;
  my ($topLevel) ;

  if( $self->{goto_window} ) {
    $self->{goto_window}->raise() ;
    $self->{goto_text}->focus() ;
    return ;
  }

  #
  # Construct a dialog that has an
  # entry field, okay and cancel buttons
  #
  my $okaySub = sub { $self->DoGoto($self->{'goto_text'}) } ;
  
  $topLevel = $self->{main_window}->Toplevel(-title => "Goto Line?", -overanchor => 'cursor') ;

  $self->{goto_text} = $topLevel->Entry()->pack(-side => 'top', -fill => 'both', -expand => 1) ;

  $self->{goto_text}->bind('<Return>', $okaySub) ; # make a CR do the same thing as pressing an okay

  $self->{goto_text}->focus() ;

  # Bind a double click on the mouse button to the same action
  # as pressing the Okay button

  $topLevel->Button( -text => "Okay", -command => $okaySub, @Devel::ptkdb::button_font,
                     )->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  #
  # Subroutone called when the 'Dismiss'
  # button is pushed.
  #
  my $dismissSub = sub {
    delete $self->{goto_text} ;
    destroy {$self->{goto_window}} ;
    delete $self->{goto_window} ; # remove the entry from our hash so we won't
  } ;

  $topLevel->Button( -text => "Dismiss", @Devel::ptkdb::button_font,
                     -command => $dismissSub )->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  $topLevel->protocol('WM_DELETE_WINDOW', sub { destroy $topLevel ; } ) ;

  $self->{goto_window} = $topLevel ;

} # end of GotoLine


#
# Subroutine called when the 'okay' button is pressed
#
sub FindSearch {
  my ($self, $entry, $btn, $regExp) = @_ ;
  my (@switches, $result) ;
  my $txt = $entry->get() ;

  return if $txt eq "" ; 

  push @switches, "-forward" if $self->{fwdOrBack} eq "forward" ;
  push @switches, "-backward" if $self->{fwdOrBack} eq "backward" ;
  
  if( $regExp ) {
    push @switches, "-regexp" ;
  }
  else {
    push @switches, "-nocase" ; # if we're not doing regex we may as well do caseless search
  }

  $result = $self->{'text'}->search(@switches, $txt, $self->{search_start}) ;

  # untag the previously found text

  $self->{'text'}->tagRemove('search_tag', @{$self->{search_tag}}) if defined $self->{search_tag} ;

  if( !$result || $result eq "" ) {
    # No Text was found
    $btn->flash() ;
    $btn->bell() ;

    delete $self->{search_tag} ;
    $self->{'search_start'} = "0.0" ;
  }
  else { # text found
    $self->{'text'}->see($result) ;
    # set the insertion of the text as well
    $self->{'text'}->markSet('insert' => $result) ;
    my $len = length $txt ;

    if( $self->{fwdOrBack} ) {
      $self->{search_start}  = "$result +$len chars"  ;
      $self->{search_tag} = [ $result, $self->{search_start} ]  ;
    }
    else {
      # backwards search 
      $self->{search_start}  = "$result -$len chars"  ;
      $self->{search_tag} = [ $result, "$result +$len chars"  ]  ;
    }

    # tag the newly found text

    $self->{'text'}->tagAdd('search_tag', @{$self->{search_tag}}) ;
  } # end of text found

  $entry->selectionRange(0, 'end') if $entry->can('selectionRange') ;

} # end of FindSearch


#
# Support for the Find Text... Menu command
#
sub FindText {
  my ($self) = @_ ;
  my ($top, $entry, $rad1, $rad2, $chk, $regExp, $frm, $okayBtn) ;

  #
  # if we already have the Find Text Window
  # open don't bother openning another, bring
  # the existing one to the front.  
  #
  if( $self->{find_window} ) {
    $self->{find_window}->raise() ;
    $self->{find_text}->focus() ;
    return ;
  }

  $self->{search_start} = $self->{'text'}->index('insert') if( $self->{search_start} eq "" ) ;

  #
  # Subroutine called when the 'Dismiss' button
  # is pushed.  
  #
  my $dismissSub = sub {
    $self->{'text'}->tagRemove('search_tag', @{$self->{search_tag}}) if defined $self->{search_tag} ;
    $self->{search_start} = "" ;
    destroy {$self->{find_window}} ; 
    delete $self->{search_tag} ;
    delete $self->{find_window} ;
  } ;

  #
  # Construct a dialog that has an entry field, forward, backward, regex option, okay and cancel buttons
  #
  $top = $self->{main_window}->Toplevel(-title => "Find Text?") ;

  $self->{find_text} = $top->Entry()->pack(-side => 'top', -fill => 'both', -expand => 1) ;

  
  $frm = $top->Frame()->pack(-side => 'top', -fill => 'both', -expand => 1) ;

  $self->{fwdOrBack} = 'forward' ;
  $rad1 = $frm->Radiobutton(-text => "Forward", -value => 1, -variable => \$self->{fwdOrBack}) ;
  $rad1->pack(-side => 'left', -fill => 'both', -expand => 1) ;
  $rad2 = $frm->Radiobutton(-text => "Backward", -value => 0, -variable => \$self->{fwdOrBack}) ;
  $rad2->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  $regExp = 0 ;
  $chk = $frm->Checkbutton(-text => "RegExp", -variable => \$regExp) ;
  $chk->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  # Okay and cancel buttons

  # Bind a double click on the mouse button to the same action
  # as pressing the Okay button

  $okayBtn = $top->Button( -text => "Okay", -command => sub { $self->FindSearch($self->{find_text}, $okayBtn, $regExp) ; }, 
                         @Devel::ptkdb::button_font,
                           )->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  $self->{find_text}->bind('<Return>', sub { $self->FindSearch($self->{find_text}, $okayBtn, $regExp) ; }) ;

  $top->Button( -text => "Dismiss", @Devel::ptkdb::button_font,
                -command => $dismissSub)->pack(-side => 'left', -fill => 'both', -expand => 1) ;

  $top->protocol('WM_DELETE_WINDOW', $dismissSub) ;

  $self->{find_text}->focus() ;

  $self->{find_window} = $top ;

} # end of FindText

sub main_loop {
  my ($self) = @_ ;
  my ($evt, $str, $result) ;
  my $i = 0;
 SWITCH: for ($self->{'event'} = 'null' ; ; $self->{'event'} = undef ) {

   Tk::DoOneEvent(0);
   next unless $self->{'event'} ;

   $evt = $self->{'event'} ;
   $evt =~ /step/o && do { last SWITCH ; } ;
   $evt =~ /null/o && do { next SWITCH ; } ;
   $evt =~ /run/o && do { last SWITCH ; } ;
   $evt =~ /quit/o && do { $self->DoQuit ; } ;
   $evt =~ /expr/o && do { return $evt ; } ; # adds an expression to our expression window
   $evt =~ /qexpr/o && do { return $evt ; } ; # does a 'quick' expression
   $evt =~ /update/o && do { return $evt ; } ; # forces an update on our expression window
   $evt =~ /reeval/o && do { return $evt ; } ; # updated the open expression eval window
   $evt =~ /balloon_eval/ && do { return $evt } ;
 } # end of switch block
  return $evt ;
} # end of main_loop

#
# $subStackRef   A reference to the current subroutine stack
#

sub goto_sub_from_stack {
  my ($self, $f, $lineno) = @_ ;
  $self->set_file($f, $lineno) ;
} # end of goto_sub_from_stack ;

sub refresh_stack_menu {
  my ($self) = @_ ;
  my ($str, $name, $i, $sub_offset, $subStack) ;

  #
  # CAUTION:  In the effort to 'rationalize' the code
  # are moving some of this function down from DB::DB
  # to here.  $sub_offset represents how far 'down'
  # we are from DB::DB.  The $DB::subroutine_depth is
  # tracked in such a way that while we are 'in' the debugger
  # it will not be incremented, and thus represents the stack depth
  # of the target program.  
  #
  $sub_offset = 1 ;
  $subStack = [] ;

  # clear existing entries

  for( $i = 0 ; $i <= $DB::subroutine_depth ; $i++ ) {
    my ($package, $filename, $line, $subName) = caller $i+$sub_offset ;
    last if !$subName ;
    push @$subStack, { 'name' => $subName, 'pck' => $package, 'filename' => $filename, 'line' => $line } ;
  }

  $self->{stack_menu}->menu->delete(0, 'last') ; # delete existing menu items

  for( $i = 0 ; $subStack->[$i] ; $i++ ) {

    $str = defined $subStack->[$i+1] ? "$subStack->[$i+1]->{name}" : "MAIN" ;

    my ($f, $line) = ($subStack->[$i]->{filename}, $subStack->[$i]->{line}) ; # make copies of the values for use in 'sub'
    $self->{stack_menu}->command(-label => $str, -command => sub { $self->goto_sub_from_stack($f, $line) ; } ) ;
  }
} # end of refresh_stack_menu

no strict ;

sub get_state {
  my ($self, $fname) = @_ ;
  my ($val) ;
  local($files, $expr_list, $eval_saved_text, $main_win_geometry) ;
  
  do "$fname"  ;

  if( $@ ) {
    $self->DoAlert($@) ;
    return ( undef ) x 4 ; # return a list of 4 undefined values
  }

  return ($files, $expr_list, $eval_saved_text, $main_win_geometry) ;
} # end of get_state

use strict ;

sub restoreStateFile {
  my ($self, $fname) = @_ ;
  local(*F) ;
  my ($saveCurFile, $s, @n, $n) ;

  if (!(-e $fname && -r $fname)) {
    $self->DoAlert("$fname does not exist") ;
    return ;
  }

  my ($files, $expr_list, $eval_saved_text, $main_win_geometry) = $self->get_state($fname) ;
  my ($f, $brks) ;

  return unless defined $files || defined $expr_list ;

  &DB::restore_breakpoints_from_save($files) ;

  #
  # This should force the breakpoints to be restored
  #
  $saveCurFile = $self->{current_file} ;

  @$self{ 'current_file', 'expr_list', 'eval_saved_text' } =
      ( ""             , $expr_list,  $eval_saved_text) ;

  $self->set_file($saveCurFile, $self->{current_line}) ;

  $self->{'event'} = 'update' ;

  if ( $main_win_geometry && $self->{'main_window'} ) { 
    # restore the height and width of the window
    $self->{main_window}->geometry( $main_win_geometry ) ;
  }
} # end of retstoreState

sub updateEvalWindow {
  my ($self, @result) = @_ ;
  my ($leng, $str, $d) ;

  $leng = 0 ;
  for( @result ) {
    if( $self->{hexdump_evals} ) {
      # eventually put hex dumper code in here
			
			$self->{eval_results}->insert('end', hexDump($_)) ;

    }
    elsif( !$Devel::ptkdb::DataDumperAvailable || !$Devel::ptkdb::useDataDumperForEval ) {
      $str = "$_\n" ;
    }
    else {
      $d = Data::Dumper->new([ $_ ]) ;
      $d->Indent($Devel::ptkdb::eval_dump_indent) ;
      $d->Terse(1) ;
      if( Data::Dumper->can('Dumpxs') ) { 
        $str = $d->Dumpxs( $_ ) ;
      }
      else {
        $str = $d->Dump( $_ ) ;
      }
    }
    $leng += length $str ;
    $self->{eval_results}->insert('end', $str) ;
  }
} # end of updateEvalWindow


##
## converts non printable chars to '.' for a string
##
sub printablestr {
    return join "", map { (ord($_) >= 32 && ord($_) < 127) ? $_ : '.' } split //, $_[0] ;
}

##
## hex dump utility function
##
sub hexDump {
    my(@retList) ;
    my($width) = 8 ;
    my($offset) ;
    my($len, $fmt, $n, @elems) ;

    for( @_ ) {
	my($str) ;
	$len = length $_ ;
	
	while($len) {
	    $n = $len >= $width ? $width : $len ;

	    $fmt = "\n%04X  " . ("%02X " x $n ) . ( '   ' x ($width - $n) ) . " %s" ;
	    @elems = map ord, split //, (substr $_, $offset, $n) ;
	    $str .= sprintf($fmt, $offset, @elems, printablestr(substr $_, $offset, $n)) ;
	    $offset += $width ;

	    $len -= $n ;
	} # while

	push @retList, $str ;
    } # for

    return $retList[0] unless wantarray ;
    return @retList ;
} # end of hd


sub setupEvalWindow {
  my($self) = @_ ;
  my($top, $dismissSub) ;
  my $f ;
  $self->{eval_window}->focus(), return if exists $self->{eval_window} ; # already running this window?

  $top = $self->{main_window}->Toplevel(-title => "Evaluate Expressions...") ;
  $self->{eval_window} = $top ;
  $self->{eval_text} = $top->Scrolled('TextUndo',
                                    @Devel::ptkdb::scrollbar_cfg,
                                    @Devel::ptkdb::eval_text_font,
                                      width => 50,
                                      height => 10,
                                      -wrap => "none",
                                      )->packAdjust(-side => 'top', -fill => 'both', -expand => 1) ;

  $self->{eval_text}->insert('end', $self->{eval_saved_text}) if exists $self->{eval_saved_text} && defined $self->{eval_saved_text} ;

  $top->Label(-text, "Results:")->pack(-side => 'top', -fill => 'both', -expand => 'n') ;

  $self->{eval_results} = $top->Scrolled('Text',
                                       @Devel::ptkdb::scrollbar_cfg,
                                         width => 50,
                                         height => 10,
                                         -wrap => "none",
                                       @Devel::ptkdb::eval_text_font
                                         )->pack(-side => 'top', -fill => 'both', -expand => 1) ;

  my $btn = $top->Button(-text => 'Eval...', -command => sub { $DB::window->{event} = 'reeval' ; }
                         )->pack(-side => 'left', -fill => 'x', -expand => 1) ;

  $dismissSub = sub { 
    $self->{eval_saved_text} = $self->{eval_text}->get('0.0', 'end') ;
    $self->{eval_window}->destroy ;
    delete $self->{eval_window} ;
  } ;

  $top->protocol('WM_DELETE_WINDOW', $dismissSub ) ;

  $top->Button(-text => 'Clear Eval', -command => sub { $self->{eval_text}->delete('0.0', 'end') }
               )->pack(-side => 'left', -fill => 'x', -expand => 1) ;

  $top->Button(-text => 'Clear Results', -command => sub { $self->{eval_results}->delete('0.0', 'end') }
               )->pack(-side => 'left', -fill => 'x', -expand => 1) ;

  $top->Button(-text => 'Dismiss', -command => $dismissSub)->pack(-side => 'left', -fill => 'x', -expand => 1) ;
	$top->Checkbutton(-text => 'Hex', -variable => \$self->{hexdump_evals})->pack(-side => 'left') ;

} # end of setupEvalWindow ;

sub filterBreakPts {
  my ($breakPtsListRef, $fname) = @_ ;
  my $dbline = $main::{'_<' . $fname}; # breakable lines
  local($^W) = 0 ;
  #
  # Go through the list of breaks and take out any that
  # are no longer breakable
  #

  for( @$breakPtsListRef ) {
    next unless defined $_ ;

    next if $dbline->[$_->{'line'}] != 0 ; # still breakable

    $_ = undef ;
  }
} # end of filterBreakPts

sub DoAbout {
  my $self = shift ;
  my $str = "ptkdb $DB::VERSION\nCopyright 1998,2003 by Andrew E. Page\nFeedback to aepage\@users.sourceforge.net\n\n" ;
  my $threadString = "" ;
  
  $threadString = "Threads Available" if $Config::Config{usethreads} ;
  $threadString = " Thread Debugging Enabled" if $DB::usethreads ;
  
  $str .= <<"__STR__" ;
  This program is free software; you can redistribute it and/or modify
      it under the terms of either:

      a) the GNU General Public License as published by the Free
    Software Foundation; either version 1, or (at your option) any
    later version, or

    b) the "Artistic License" which comes with this Kit.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either
    the GNU General Public License or the Artistic License for more details.

    OS $^O
    Tk Version $Tk::VERSION
    Perl Version $]
Data::Dumper Version $Data::Dumper::VERSION
    $threadString
__STR__

    $self->DoAlert($str, "About ptkdb") ;
} # end of DoAbout

#
# return 1 if succesfully set,
# return 0 if otherwise
#
sub SetBreakPoint {
  my ($self, $isTemp) = @_ ;
  my $dbw = $DB::window ;
  my $lineno = $dbw->get_lineno() ;
  my $expr = $dbw->clear_entry_text() ;
  local($^W) = 0 ;

  if( !&DB::checkdbline($DB::window->{current_file}, $lineno + $self->{'line_offset'}) ) {
    $dbw->DoAlert("line $lineno in $DB::window->{current_file} is not breakable") ;
    return 0 ;
  }

  if( !$isTemp ) {
    $dbw->insertBreakpoint($DB::window->{current_file}, $lineno, 1, $expr) ;
    return 1 ;
  }
  else {
    $dbw->insertTempBreakpoint($DB::window->{current_file}, $lineno) ;
    return 1 ;
  }

  return 0 ;
} # end of SetBreakPoint

sub UnsetBreakPoint {
  my ($self) = @_ ;
  my $lineno = $self->get_lineno() ;
  
  $self->removeBreakpoint($DB::window->{current_file}, $lineno) ;
} # end of UnsetBreakPoint

sub balloon_post {
  my $self = $DB::window ;
  my $txt = $DB::window->{'text'} ;

  return 0 if ($self->{'expr_ballon_msg'} eq "") || ($self->{'balloon_expr'} eq "") ; # don't post for an empty string

  return $self->{'balloon_coord'} ;
}

sub balloon_motion {
  my ($txt, $x, $y) = @_ ;
  my ($offset_x, $offset_y) = ($x + 4, $y + 4) ;
  my $self = $DB::window ;
  my $txt2 = $self->{'text'} ;
  my $data ;

  $self->{'balloon_coord'} = "$offset_x,$offset_y" ;

  $x -= $txt->rootx ;
  $y -= $txt->rooty ;
  #
  # Post an event that will cause us to put up a popup
  #
  
  if( $txt2->tagRanges('sel') ) { # check to see if 'sel' tag exists (return undef value)
    $data = $txt2->get("sel.first", "sel.last") ; # get the text between the 'first' and 'last' point of the sel (selection) tag
  }
  else {
    $data = $DB::window->retrieve_text_expr($x, $y) ;
  }

  if( !$data ) {
    $self->{'balloon_expr'} = "" ;
    return 0 ; 
  }
  
  return 0 if ($data eq $self->{'balloon_expr'}) ; # nevermind if it's the same expression

  $self->{'event'} = 'balloon_eval' ;
  $self->{'balloon_expr'} = $data ;

  return 1 ; # ballon will be canceled and a new one put up(maybe)
} # end of balloon_motion

sub retrieve_text_expr {
  my($self, $x, $y) = @_ ;
  my $txt = $self->{'text'} ;

  my $coord = "\@$x,$y" ;

  my($idx, $col, $data, $offset) ;

  ($col, $idx) = line_number_from_coord($txt, $coord) ;

  $offset = $Devel::ptkdb::linenumber_length + 1 ; # line number text + 1 space

  return undef if $col < $offset ; # no posting

  $col -= $offset ;

  local(*dbline) = $main::{'_<' . $self->{current_file}} ;   

  return undef if( !defined $dbline[$idx] || $dbline[$idx] == 0 ) ; # no executable text, no real variable(?)
  
  $data = $dbline[$idx] ;
  
  # if we're sitting over white space, leave
  my $len = length $data ;
  return unless $data && $col && $len > 0 ;

  return if substr($data, $col, 1) =~ /\s/ ;

  # walk backwards till we find some whitespace

  $col = $len if $len < $col ;
  while( --$col >= 0 ) {
    last if  substr($data, $col, 1) =~ /[\s\$\@\%]/ ;
  }

  substr($data, $col) =~ /^([\$\@\%][a-zA-Z0-9_]+)/ ;

  return $1 ;
}

#
# after DB::eval get's us a result
#
sub code_motion_eval {
  my ($self, @result) = @_ ;
  my $str ;

  if( exists $self->{'balloon_dumper'} ) {

    my $d = $self->{'balloon_dumper'} ;

    $d->Reset() ;
    $d->Values( [ $#result == 0 ? @result : \@result ] ) ;      

                  if( $d->can('Dumpxs') ) {
                    $str = $d->Dumpxs() ;
                  }
                  else {
                    $str = $d->Dump() ;
                  }

                  chomp($str) ;
                }
                else {
                  $str = "@result" ;
                }

                #
                # Cut the string down to 1024 characters to keep from
                # overloading the balloon window
                #
                
                $self->{'expr_ballon_msg'} = "$self->{'balloon_expr'} = " . substr $str, 0, 1024 ;
              } # end of code motion eval

#
# Subroutine called when we enter DB::DB()
# In other words when the target script 'stops'
# in the Debugger
#
sub EnterActions {
  my($self) = @_ ;

#  $self->{'main_window'}->Unbusy() ;

} # end of EnterActions

#
# Subroutine called when we return from DB::DB()
# When the target script resumes.  
#
sub LeaveActions {
  my($self) = @_ ;
  
  #  $self->{'main_window'}->Busy() ;
} # end of LeaveActions


sub BEGIN {
 $Devel::ptkdb::scriptName = $0 ;
 @Devel::ptkdb::script_args = @ARGV ; # copy args

}

##
## Save the ptkdb state file and restart the debugger
##
sub DoRestart {
  my($fname) ;

  $fname = $ENV{'TMP'} || $ENV{'TMPDIR'} || $ENV{'TMP_DIR'} || $ENV{'TEMP'} || $ENV{'HOME'} ;
  $fname .= '/' if $fname ;
  $fname = "" unless $fname ;

  $fname .= "ptkdb_restart_state$$" ;

  # print "saving temp state file $fname\n" ;
  
  &DB::save_state_file($fname) ;

  $ENV{'PTKDB_RESTART_STATE_FILE'} = $fname ;

  ##
  ## build up the command to do the restart
  ##

  $fname = "perl -w -d:ptkdb $Devel::ptkdb::scriptName @Devel::ptkdb::script_args" ;

  # print "$$ doing a restart with $fname\n" ;

  exec $fname ;

} # end of DoRestart

##
## Enables/Disables the feature where we stop
## if we've encountered a perl warning such as:
## "Use of uninitialized value at undef_warn.pl line N"
##

sub stop_on_warning_cb {
  &$DB::ptkdb::warn_sig_save() if $DB::ptkdb::warn_sig_save ; # call any previously registered warning
 $DB::window->DoAlert(@_) ;
 $DB::single = 1 ; # forces debugger to stop next time
}

sub set_stop_on_warning {

  if( $DB::ptkdb::stop_on_warning ) {
    
    return if $DB::ptkdb::warn_sig_save == \&stop_on_warning_cb ; # prevents recursion

    $DB::ptkdb::warn_sig_save = $SIG{'__WARN__'} if $SIG{'__WARN__'} ;
    $SIG{'__WARN__'} = \&stop_on_warning_cb ;
     }
  else {
    ##
    ## Restore any previous warning signal
    ##
    local($^W) = 0 ;
    $SIG{'__WARN__'} = $DB::ptkdb::warn_sig_save ;
  }
} # end of set_stop_on_warning

1 ; # end of Devel::ptkdb

package DB ;

use vars '$VERSION', '$header' ;

$VERSION = '1.1091' ;
$header = "ptkdb.pm version $DB::VERSION";
$DB::window->{current_file} = "" ;

#
# Here's the clue...
# eval only seems to eval the context of
# the executing script while in the DB
# package.  When we had updateExprs in the Devel::ptkdb
# package eval would turn up an undef result.
#

sub updateExprs {
  my ($package) = @_ ;
  #
  # Update expressions
  # 
 $DB::window->deleteAllExprs() ;
  my ($expr, @result);

  foreach $expr ( @{$DB::window->{'expr_list'}} ) {
    next if length $expr == 0 ;

    @result = &DB::dbeval($package, $expr->{'expr'}) ;

    if(  @result == 1 ) {
      $DB::window->insertExpr([ $result[0] ], $DB::window->{'data_list'}, $result[0], $expr->{'expr'}, $expr->{'depth'}) ;
      }
    else {
      $DB::window->insertExpr([ \@result ], $DB::window->{'data_list'}, \@result, $expr->{'expr'}, $expr->{'depth'}) ;
      }
  }

} # end of updateExprs

no strict ; # turning strict off (shame shame) because we keep getting errrs for the local(*dbline)

#
# returns true if line is breakable
#
use Carp ;
sub checkdbline($$) { 
  my ($fname, $lineno) = @_ ;

  return 0 unless $fname; # we're getting an undef here on 'Restart...'

  local($^W) = 0 ; # spares us warnings under -w
  local(*dbline) = $main::{'_<' . $fname} ;

  my $flag = $dbline[$lineno] != 0 ;

  return $flag;
  
} # end of checkdbline

#
# sets a breakpoint 'through' a magic 
# variable that perl is able to interpert
#
sub setdbline($$$) {
  my ($fname, $lineno, $value) = @_ ;
  local(*dbline) = $main::{'_<' . $fname};

  $dbline{$lineno} = $value ;
} # end of setdbline

sub getdbline($$) {
  my ($fname, $lineno) = @_ ;
  local(*dbline) = $main::{'_<' . $fname};
  return $dbline{$lineno} ;
} # end of getdbline

sub getdbtextline {
  my ($fname, $lineno) = @_ ;
  local(*dbline) = $main::{'_<' . $fname};
  return $dbline[$lineno] ;
} # end of getdbline


sub cleardbline($$;&) {
  my ($fname, $lineno, $clearsub) = @_ ;
  local(*dbline) = $main::{'_<' . $fname};
  my $value ; # just in case we want it for something

  $value = $dbline{$lineno} ;
  delete $dbline{$lineno} ;
  &$clearsub($value) if $value && $clearsub ;

  return $value ;
} # end of cleardbline

sub clearalldblines(;&) {
  my ($clearsub) = @_ ;
  my ($key, $value, $brkPt, $dbkey) ;
  local(*dbline) ;

  while ( ($key, $value) = each %main:: )  { # key loop
    next unless $key =~ /^_</ ;
    *dbline = $value ;

    foreach $dbkey (keys %dbline) {
      $brkPt = $dbline{$dbkey} ;
      delete $dbline{$dbkey} ;
      next unless $brkPt && $clearSub ;
      &$clearsub($brkPt) ; # if specificed, call the sub routine to clear the breakpoint
    }

  } # end of key loop

} # end of clearalldblines

sub getdblineindexes {
  my ($fname) = @_ ;
  local(*dbline) = $main::{'_<' . $fname} ;
  return keys %dbline ;
} # end of getdblineindexes

sub getbreakpoints {
  my (@fnames) = @_ ;
  my ($fname, @retList) ;

  foreach $fname (@fnames) {
    next unless  $main::{'_<' . $fname} ;
    local(*dbline) = $main::{'_<' . $fname} ;    
    push @retList, values %dbline ;
  }
  return @retList ;
} # end of getbreakpoints

#
# Construct a hash of the files
# that have breakpoints to save
#
sub breakpoints_to_save {
  my ($file, @breaks, $brkPt, $svBrkPt, $list) ;
  my ($brkList) ;

  $brkList = {} ;

  foreach $file ( keys %main:: ) { # file loop
    next unless $file =~ /^_</ && exists $main::{$file} ;
    local(*dbline) = $main::{$file} ;

    next unless @breaks = values %dbline ;
    $list = [] ;
    foreach $brkPt ( @breaks ) {
      
      $svBrkPt = { %$brkPt } ; # make a copy of it's data
      
      push @$list, $svBrkPt ;

    } # end of breakpoint loop

    $brkList->{$file} = $list ;

  } # end of file loop

  return $brkList ;

} # end of breakpoints_to_save

#
# When we restore breakpoints from a state file
# they've often 'moved' because the file
# has been editted.  
#
# We search for the line starting with the original line number,
# then we walk it back 20 lines, then with line right after the
# orginal line number and walk forward 20 lines.  
#
# NOTE: dbline is expected to be 'local'
# when called
#
sub fix_breakpoints {
  my(@brkPts) = @_ ;
  my($startLine, $endLine, $nLines, $brkPt) ;
  my (@retList) ;
  local($^W) = 0 ;

  $nLines = scalar @dbline ;

  foreach $brkPt (@brkPts) {

    $startLine = $brkPt->{'line'} > 20 ? $brkPt->{'line'} - 20 : 0 ;
    $endLine   = $brkPt->{'line'} < $nLines - 20 ? $brkPt->{'line'} + 20 : $nLines ;

    for( (reverse $startLine..$brkPt->{'line'}), $brkPt->{'line'} + 1 .. $endLine ) {
      next unless $brkPt->{'text'} eq $dbline[$_] ;
      $brkPt->{'line'} = $_ ;
      push @retList, $brkPt ;
      last ;
    }
  } # end of breakpoint list
  
  return @retList ;

} # end of fix_breakpoints

#
# Restore breakpoints saved above
#
sub restore_breakpoints_from_save {
  my ($brkList) = @_ ;
  my ($offset, $key, $list, $brkPt, @newList) ;
  
  while ( ($key, $list) = each %$brkList ) { # reinsert loop
    next unless exists $main::{$key} ;
    local(*dbline) = $main::{$key} ;

    $offset = 0 ;
    $offset = 1 if $dbline[1] =~ /use\s+.*Devel::_?ptkdb/ ;

    @newList = fix_breakpoints(@$list) ;
    
    foreach $brkPt ( @newList ) {
      if( !&DB::checkdbline($key, $brkPt->{'line'} + $offset) ) {
        print "Breakpoint $key:$brkPt->{'line'} in config file is not breakable.\n" ;
        next ;
      }
      $dbline{$brkPt->{'line'}} = { %$brkPt } ; # make a fresh copy
    }
  } # end of reinsert loop
  
} # end of restore_breakpoints_from_save ;

use strict ;

sub dbint_handler {
  my($sigName) = @_ ;
 $DB::single = 1 ;
  print "signalled\n" ;
} # end of dbint_handler

#
# Do first time initialization at the startup
# of DB::DB
#
sub Initialize {
  my ($fName) = @_ ;
  return if $DB::ptkdb::isInitialized ;
 $DB::ptkdb::isInitialized = 1 ;

 $DB::window = new Devel::ptkdb ;

 $DB::window->do_user_init_files() ;


 $DB::dbint_handler_save = $SIG{'INT'} unless $DB::sigint_disable ; # saves the old handler
  $SIG{'INT'} = "DB::dbint_handler" unless $DB::sigint_disable ;
  
  # Save the file name we started up with
 $DB::startupFname = $fName ;

  # Check for a 'restart' file

  if( $ENV{'PTKDB_RESTART_STATE_FILE'} && $Devel::ptkdb::DataDumperAvailable && -e $ENV{'PTKDB_RESTART_STATE_FILE'} ) {
    ##
    ## Restore expressions and breakpoints in state file
    ##
    $DB::window->restoreStateFile($ENV{'PTKDB_RESTART_STATE_FILE'}) ;
    unlink $ENV{'PTKDB_RESTART_STATE_FILE'} ; # delete state file

    # print "restoring state from $ENV{'PTKDB_RESTART_STATE_FILE'}\n" ;

    $ENV{'PTKDB_RESTART_STATE_FILE'} = "" ; # clear entry
  }
  else {
    &DB::restoreState($fName) if $Devel::ptkdb::DataDumperAvailable ;
  }

} # end of Initialize 

sub restoreState {
  my($fName) = @_ ;
  my ($stateFile, $files, $expr_list, $eval_saved_text, $main_win_geometry, $restoreName) ;

  $stateFile = makeFileSaveName($fName) ;
  
  if( -e $stateFile && -r $stateFile ) {
    ($files, $expr_list, $eval_saved_text, $main_win_geometry) = $DB::window->get_state($stateFile) ;
    &DB::restore_breakpoints_from_save($files) ;
  $DB::window->{'expr_list'} = $expr_list if defined $expr_list ;
  $DB::window->{eval_saved_text} = $eval_saved_text ;
    
    if ( $main_win_geometry ) { 
      # restore the height and width of the window
    $DB::window->{main_window}->geometry($main_win_geometry) ;
    }
  }

} # end of Restore State

sub makeFileSaveName {
  my ($fName) = @_ ;
  my $saveName = $fName ;

  if(  $saveName =~ /.p[lm]$/ ) {
    $saveName =~ s/.pl$/.ptkdb/ ;
  }
  else {
    $saveName .= ".ptkdb" ;
  }

  return $saveName ;
} # end of makeFileSaveName

sub save_state_file {
  my($fname) = @_ ;
  my($files, $d, $saveStr) ;
      
  $files = &DB::breakpoints_to_save() ;
  
  $d = Data::Dumper->new( [ $files, $DB::window->{'expr_list'}, "" ], 
                          [ "files", "expr_list",  "eval_saved_text" ] ) ;
    
  $d->Purity(1) ;
  if( Data::Dumper->can('Dumpxs') ) {
    $saveStr = $d->Dumpxs() ;
  } else {
    $saveStr = $d->Dump() ;
  }    
  
  local(*F) ;
  open F, ">$fname" || die "Couldn't open file $fname" ;
  
  print F $saveStr || die "Couldn't write file" ;
    
  close F ;
} # end of save_state_file

sub SaveState {
  my($name_in) = @_ ;
  my ($top, $entry, $okayBtn, $win) ;
  my ($fname, $saveSub, $cancelSub, $saveName, $eval_saved_text, $d) ;    
  my ($files, $main_win_geometry);
  #
  # Create our default name
  #
  $win = $DB::window ;
  
  #
  # Extract the height and width of our window
  #
  $main_win_geometry = $win->{main_window}->geometry ;

  if ( defined $win->{save_box} ) {
    $win->{save_box}->raise ;
    $win->{save_box}->focus ;
    return ;
  }

  $saveName = $name_in || makeFileSaveName($DB::startupFname) ;
  
  

  $saveSub = sub {
    $win->{'event'} = 'null' ;

    my $saveStr ;

    delete $win->{save_box} ;

    if( exists $win->{eval_window} ) {
      $eval_saved_text = $win->{eval_text}->get('0.0', 'end') ;
    }
    else {
      $eval_saved_text =  $win->{eval_saved_text} ;
    }
    
    $files = &DB::breakpoints_to_save() ;

    $d = Data::Dumper->new( [ $files, $win->{'expr_list'}, $eval_saved_text,   $main_win_geometry ], 
                            [ "files", "expr_list",        "eval_saved_text",  "main_win_geometry"] ) ;
    
    $d->Purity(1) ;
    if( Data::Dumper->can('Dumpxs') ) {
      $saveStr = $d->Dumpxs() ;
    } else {
      $saveStr = $d->Dump() ;
    }    
    
    local(*F) ;
    eval {
      open F, ">$saveName" || die "Couldn't open file $saveName" ;
      
      print F $saveStr || die "Couldn't write file" ;
      
      close F ;
    } ;
    $win->DoAlert($@) if $@ ;
  } ; # end of save sub

  $cancelSub = sub {
    delete $win->{'save_box'}
  } ; # end of cancel sub
  
  #
  # Create a dialog
  #
  
  $win->{'save_box'} = $win->simplePromptBox("Save Config?", $saveName, $saveSub, $cancelSub) ;

} # end of SaveState

sub RestoreState {
  my ($top, $restoreSub) ;

  $restoreSub = sub {
  $DB::window->restoreStateFile($Devel::ptkdb::promptString) ;
  } ;

  $top = $DB::window->simplePromptBox("Restore Config?", makeFileSaveName($DB::startupFname), $restoreSub) ;

} # end of RestoreState

sub SetStepOverBreakPoint {
  my ($offset) = @_ ;
 $DB::step_over_depth = $DB::subroutine_depth + ($offset ? $offset : 0) ;
} # end of SetStepOverBreakPoint

#
# NOTE:   It may be logical and somewhat more economical
#         lines of codewise to set $DB::step_over_depth_saved 
#         when we enter the subroutine, but this gets called
#         for EVERY callable line of code in a program that
#         is being debugged, so we try to save every line of
#         execution that we can.
#
sub isBreakPoint {
  my ($fname, $line, $package) = @_ ;
  my ($brkPt) ;

  if ( $DB::single && ($DB::step_over_depth < $DB::subroutine_depth) && ($DB::step_over_depth > 0) && !$DB::on) {
  $DB::single = 0  ;
    return 0 ;
  }
  #
  # doing a step over/in
  # 

  if( $DB::single || $DB::signal ) {
  $DB::single = 0 ;
  $DB::signal = 0 ;
  $DB::subroutine_depth = $DB::subroutine_depth ;
    return 1 ;
  }
  #
  # 1st Check to see if there is even a breakpoint there.  
  # 2nd If there is a breakpoint check to see if it's check box control is 'on'
  # 3rd If there is any kind of expression, evaluate it and see if it's true.  
  #
  $brkPt = &DB::getdbline($fname, $line) ;

  return 0 if( !$brkPt || !$brkPt->{'value'} || !breakPointEvalExpr($brkPt, $package) ) ;

  &DB::cleardbline($fname, $line) if( $brkPt->{'type'} eq 'temp' ) ;

 $DB::subroutine_depth = $DB::subroutine_depth ;

  return  1 ;
} # end of isBreakPoint

#
# Check the breakpoint expression to see if it
# is true.  
#
sub breakPointEvalExpr {
  my ($brkPt, $package) = @_ ;
  my (@result) ;

  return 1 unless $brkPt->{expr} ; # return if there is no expression

  no strict ;

  @result = &DB::dbeval($package, $brkPt->{'expr'}) ;

  use strict ;
  
 $DB::window->DoAlert($@) if $@ ;

  return ($result[0] or @result) ; # we could have a case where the 1st element is undefined
  # but subsequent elements are defined

} # end of breakPointEvalExpr

#
# Evaluate the given expression, return the result.
# MUST BE CALLED from within DB::DB in order for it
# to properly interpret the vars
#
sub dbeval {
  my($ptkdb__package, $ptkdb__expr) = @_ ;
  my(@ptkdb__result, $ptkdb__str) ;
  my(@ptkdb_args) ;
  local($^W) = 0 ; # temporarily turn off warnings
  
  no strict ;
  #
  # This substitution is done so that 
  # we return HASH, as opposed to an ARRAY.
  # An expression of %hash results in a
  # list of key/value pairs.  
  #

  $ptkdb__expr =~ s/^\s*%/\\%/o ;

  @_ = @DB::saved_args ; # replace @_ arg array with what we came in with

  @ptkdb__result = eval <<__EVAL__ ;


  \$\@ = \$DB::save_err ;

  package $ptkdb__package ;

  $ptkdb__expr ;

__EVAL__

      @ptkdb__result = ("ERROR ($@)") if $@ ;

  use strict ;

  return @ptkdb__result ;
} # end of dbeval

#
# Call back we give to our 'quit' button
# and binding to the WM_DELETE_WINDOW protocol
# to quit the debugger.  
#
sub dbexit {
  exit ;
} # end of dbexit

#
# This is the primary entry point for the debugger.  When a perl program
# is parsed with the -d(in our case -d:ptkdb) option set the parser will
# insert a call to DB::DB in front of every excecutable statement.  
# 
# Refs:  Progamming Perl 2nd Edition, Larry Wall, O'Reilly & Associates, Chapter 8
#


##
## Since perl 5.8.0 we need to predeclare the sub DB{} at the start of the 
## package or else the compilation fails.  We need to disable warnings though
## since in 5.6.x we get warnings on the sub DB begin redeclared.  Using
## local($^W) = 0 will leave warnings disabled for the rest of the compile
## and we don't want that.
##
my($saveW) ;
sub BEGIN {
  $saveW = $^W ;
  $^W = 0 ;
}

no strict ;
sub DB {
  @DB::saved_args = @_ ; # save arg context
 $DB::save_err = $@ ; # save value of $@
   my ($package, $filename, $line) = caller ;
   my ($stop, $cnt) ;

    $^W = $saveW ;
   unless( $DB::ptkdb::isInitialized ) {
     return if( $filename ne $0 ) ; # not in our target file
     &DB::Initialize($filename) ;
   }

   if (!isBreakPoint($filename, $line, $package) ) {
   $DB::single = 0 ;
     $@ = $DB::save_err ;
     return ;
   }

   if ( !$DB::window ) { # not setup yet
     $@ = $DB::save_err ;
     return ;
   }

 $DB::window->setup_main_window() unless $DB::window->{'main_window'} ;

 $DB::window->EnterActions() ; 

   my ($saveP) ;
   $saveP = $^P ;
   $^P = 0 ;

 $DB::on = 1 ;

#
# The user can specify this variable in one of the startup files,
# this will make the debugger run right after startup without
# the user having to press the 'run' button.  
#
   if( $DB::no_stop_at_start ) {
   $DB::no_stop_at_start = 0 ;
   $DB::on = 0 ;
     $@ = $DB::save_err ;
     return ;
   }

   if( !$DB::sigint_disable ) {
     $SIG{'INT'} = $DB::dbint_handler_save if $DB::dbint_handler_save ; # restore original signal handler
     $SIG{'INT'} = "DB::dbexit" unless   $DB::dbint_handler_save ;
   }

  #$DB::window->{main_window}->raise() ; # bring us to the top make sure OUR event loop runs
 $DB::window->{main_window}->focus() ;

 $DB::window->set_file($filename, $line) ;
   #
   # Refresh the exprs to see if anything has changed
   #
   updateExprs($package) ;

   #
   # Update subs Page if necessary
   #
   $cnt = scalar keys %DB::sub ;
   if ( $cnt != $DB::window->{'subs_list_cnt'} && $DB::window->{'subs_page_activated'} ) {
     $DB::window->fill_subs_page() ;
     $DB::window->{'subs_list_cnt'} = $cnt ;
   }
   #
   # Update the subroutine stack menu
   #
 $DB::window->refresh_stack_menu() ;
   
 $DB::window->{run_flag} = 1 ;

   my ($evt, @result, $r) ;

   for( ; ; ) {
     #
     # we wait here for something to do
     #
     $evt = $DB::window->main_loop() ;

     last if( $evt eq 'step' ) ;

   $DB::single = 0 if ($evt eq 'run' )  ;

     if ($evt eq 'balloon_eval' ) {
     $DB::window->code_motion_eval(&DB::dbeval($package, $DB::window->{'balloon_expr'})) ;
       next ;
     }

     if ( $evt eq 'qexpr' ) {
       my $str ;
       @result = &DB::dbeval($package, $DB::window->{'qexpr'}) ;
     $DB::window->{'quick_entry'}->delete(0, 'end') ; # clear old text
       if (exists $DB::window->{'quick_dumper'}) {
       $DB::window->{'quick_dumper'}->Reset() ;
       $DB::window->{'quick_dumper'}->Values( [ $#result == 0 ? @result : \@result ] ) ;
                                                if( $DB::window->{'quick_dumper'}->can('Dumpxs') ) {
                                                  $str = $DB::window->{'quick_dumper'}->Dumpxs() ;
                                                }
                                                else {
                                                  $str = $DB::window->{'quick_dumper'}->Dump() ;
                                                } 
                                              }
                                              else {
                                                $str = "@result" ;
                                              }
                                            $DB::window->{'quick_entry'}->insert(0, $str) ; #enter the text
                                            $DB::window->{'quick_entry'}->selectionRange(0, 'end') ; # select it
                                              $evt = 'update' ; # force an update on the expressions
                                            }

         if( $evt eq 'expr' ) {
           #
           # Append the new expression to the list
           # but first check to make sure that we don't
           # already have it.
           #
           
           if ( grep $_->{'expr'} eq $DB::window->{'expr'}, @{$DB::window->{'expr_list'}} ) {
           $DB::window->DoAlert("$DB::window->{'expr'} is already listed") ;
             next ;
           }

           @result = &DB::dbeval($package, $DB::window->{expr}) ;

           if(  @result == 1 ) {
             $r = $DB::window->insertExpr([ $result[0] ], $DB::window->{'data_list'}, $result[0], $DB::window->{'expr'}, $Devel::ptkdb::expr_depth) ;
           }
           else {
             $r = $DB::window->insertExpr([ \@result ], $DB::window->{'data_list'}, \@result, $DB::window->{'expr'}, $Devel::ptkdb::expr_depth)  ;
           }
           
           #
           # $r will be 1 if the expression was added succesfully, 0 if not,
           # and it if wasn't added sucessfully it won't be reevalled the 
           # next time through.  
           #
           push @{$DB::window->{'expr_list'}}, { 'expr' => $DB::window->{'expr'}, 'depth' => $Devel::ptkdb::expr_depth } if $r ;
           
           next ;
         }
         if( $evt eq 'update' ) {
           updateExprs($package) ;
           next ;
         }
         if( $evt eq 'reeval' ) {
           #
           # Reevaluate the contents of the expression eval window
           #
           my $txt = $DB::window->{'eval_text'}->get('0.0', 'end') ;
           my @result = &DB::dbeval($package, $txt) ;

         $DB::window->updateEvalWindow(@result) ;

           next ;
         }
         last ;
       }
       $^P = $saveP ;
       $SIG{'INT'} = "DB::dbint_handler"   unless $DB::sigint_disable ; # set our signal handler

     $DB::window->LeaveActions() ;

       $@ = $DB::save_err ;
     $DB::on = 0 ;
     } # end of DB

##
## in this case we do not use local($^W) since we would like warnings
## to be issued past this point, and the localized copy of $^W will not
## go out of scope until  the end of compilation
##
##

#
# This is another place where we'll try and keep the
# code as 'lite' as possible to prevent the debugger
# from slowing down the user's application
#
# When a perl program is parsed with the -d(in our case a -d:ptkdb) option
# the parser will route all subroutine calls through here, setting $DB::sub
# to the name of the subroutine to be called, leaving it to the debugger to
# make the actual subroutine call and do any pre or post processing it may
# need to do.  In our case we take the opportunity to track the depth of the call
# stack so that we can update our 'Stack' menu when we stop.  
#
# Refs:  Progamming Perl 2nd Edition, Larry Wall, O'Reilly & Associates, Chapter 8
#
#
     sub sub {
       my ($result, @result) ;
#
# See NOTES(1)
#
			 $DB::subroutine_depth += 1 unless $DB::on ;
       $DB::single = 0 if ( ($DB::step_over_depth < $DB::subroutine_depth) && ($DB::step_over_depth >= 0) && !$DB::on) ;

       if( wantarray ) {
				 #
				 # array context
				 #
         no strict ; # otherwise perl gripes about calling the sub by the reference
         @result = &$DB::sub ; # call the subroutine by name
         use strict ;

       $DB::subroutine_depth -= 1 unless $DB::on ;
       $DB::single = 1 if ($DB::step_over_depth >= $DB::subroutine_depth && !$DB::on) ;  
         return @result ; 
       }
       elsif(defined wantarray) {

				 #
				 # scalar context
				 #
         no strict ; 
         $result = &$DB::sub ; 
         use strict ;

       $DB::subroutine_depth -= 1 unless $DB::on ;
       $DB::single = 1 if ($DB::step_over_depth >= $DB::subroutine_depth  && !$DB::on) ;
         return $result ; 
       } else {
				 #
				 # void context
				 #
				 
         no strict ; 
         &$DB::sub ; 
         use strict ;

       $DB::subroutine_depth -= 1 unless $DB::on ;
       $DB::single = 1 if ($DB::step_over_depth >= $DB::subroutine_depth && !$DB::on) ;
         return $result ; 

				 return ;
       }
       
     } # end of sub 

1 ; # return true value

# ptkdb.pm,v
# Revision 1.15  2004/03/31 02:08:40  aepage
# fixes for various lacks of backwards compatiblity in Tk804
# Added a 'bug report' item to the File Menu.
#
# Revision 1.14  2003/11/20 01:59:40  aepage
# version fix
#
# Revision 1.12  2003/11/20 01:46:45  aepage
# Hex Dumper and correction of some parameters for Tk804.025_beta6
#
# Revision 1.11  2003/06/26 13:42:49  aepage
# fix for chars at the end of win32 platforms.
#
# Revision 1.10  2003/05/12 14:38:34  aepage
# win32 pushback
#
# Revision 1.9  2003/05/12 13:46:46  aepage
# optmization of win32 line fixing
#
# Revision 1.8  2003/05/11 23:42:20  aepage
# fix to remove stray win32 chars
#
# Revision 1.7  2003/05/11 23:15:26  aepage
# email address changes, fixes for perl 5.8.0
#
# Revision 1.6  2002/11/28 19:17:43  aepage
# Changed many options to widgets and pack from bareword or 'bareword'
# to -bareword to support Tk804.024(Devel).
#
# Revision 1.5  2002/11/25 23:47:03  aepage
# A perl debugger package is required to define a subroutine name 'sub'.
# This routine is a 'proxy' for handling subroutine calls and allows the
# debugger pacakage to track subroutine depth so that it can implement
# 'step over', 'step in' and 'return' functionality.  It must also
# handle the same context as the proxied routine; it must return a
# scalar where a scalar was being expected, an array where an array is
# being expected and a void where a void was being expected.  Ptkdb was
# not handling the case for void.  99.9% of the time this will have no
# ill effects although it is being handled incorrectly. Ref Programming
# Perl 3rd Edition pg 827
#
# Revision 1.4  2002/10/24 17:07:10  aepage
# fix for warning for undefined value assigend to typeglob during restart
#
# Revision 1.3  2002/10/20 23:49:51  aepage
#
# changed email address to aepage@ptkdb.sourceforge.net
# 
# localized $^W in dbeval
# 
# fix for instances where there is no code in a package.
# 
# Initialized $self->{'subs_list_cnt'} in the new constructor to 0 to
# prevent warnings with -w.
#