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
104
107
108
109
110
111
112
113
114
115
118
119
120
121
122
125
126
127
128
131
132
134
135
136
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
203
204
216
217
218
219
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
243
244
245
246
247
248
251
252
255
256
257
258
259
260
261
263
264
265
266
267
268
269
270
271
272
276
277
278
281
282
283
284
285
286
287
288
289
290
291
297
298
299
300
301
302
305
306
307
308
312
313
314
320
329
330
331
332
333
340
341
344
345
346
347
354
355
356
357
360
369
370
373
376
377
378
379
385
386
387
388
389
390
393
394
395
396
397
398
399
406
407
408
409
415
416
417
418
419
420
421
422
423
428
429
430
431
432
444
445
452
468
469
474
475
476
477
478
479
480
483
484
488
494
495
499
500
501
508
509
510
514
515
516
517
518
519
522
523
524
525
526
527
528
534
535
536
537
538
539
540
543
544
545
546
547
548
549
550
556
557
558
559
560
561
562
563
564
565
566
567
568
571
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
599
610
618
619
620
621
624
625
626
627
628
629
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
662
663
667
668
672
673
677
678
682
683
684
685
686
687
688
689
690
691
692
695
696
697
704
705
708
709
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
738
739
740
741
748
749
750
751
752
753
754
755
756
760
761
762
763
764
765
772
773
774
781
782
783
784
785
786
787
788
790
791
792
793
794
795
796
797
798
799
800
801
802
803
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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
858
859
876
882
883
884
885
886
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
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
971
972
973
974
980
981
1002
1003
1004
1005
1006
1007
1008
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1072
1073
1077
1078
1082
1083
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1125
1131
1132
1136
1137
1141
1142
1143
1144
1145
1146
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
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
1218
1222
1223
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
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
1283
1284
1285
1286
1287
1293
1294
1295
1296
1301
1302
1307
1310
1319
1325
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
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
1397
1398
1399
1400
1401
1402
1403
1404
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
1470
1476
1481
1485
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1524
1528
1537
1547
1552
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
1621
1622
1626
1627
1628
1629
1630
1637
1640
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1661
1664
1668
1669
1673
1679
1680
1684
1685
1686
1687
1691
1696
1697
1698
1699
1700
1701
1702
1703
1704
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1726
1727
1745
1751
1765
1766
1770
1771
1772
1773
1774
1775
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1846
1847
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1866
1870
1874
1878
1882
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1906
1915
1916
1923
1924
1935
1936
1937
1940
1943
1944
1945
1946
1947
1948
1949
1950
1954
1958
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1985
1986
1987
1992
1993
1994
1995
1996
1997
2001
2002
2003
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
2045
2046
2051
2055
2056
2057
2058
2059
2062
2063
2064
2065
2066
2067
2068
2071
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2168
2169
2170
2171
2172
2175
2176
2177
2178
2179
2180
2181
2182
2187
2191
2192
2195
2196
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2255
2256
2257
2258
2259
2260
2261
2262
2266
2267
2270
2271
2272
2273
2274
2275
2281
2282
2283
2284
2293
2294
2295
2296
2300
2301
2302
2307
2308
2309
2310
2311
2312
2313
2321
2322
2323
2331
2332
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2396
2397
2398
2399
2400
2401
2402
2403
2404
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2425
2426
2427
2428
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2451
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
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2509
2512
2515
2516
2517
2518
2519
2520
2524
2525
2526
2527
2530
2536
2537
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2599
2605
2606
2612
2613
2614
2615
2616
2619
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2644
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2666
2667
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2688
2689
2692
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2715
2716
2719
2720
2721
2722
2723
2724
2725
2726
2729
2730
2731
2732
2733
2734
2735
2736
2739
2748
2749
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2765
2766
2767
2768
2769
2770
2771
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2787
2788
2789
2790
2791
2792
2793
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2825
2826
2827
2828
2829
2830
2831
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
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
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2909
2910
2911
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2928
2929
2930
2931
2932
2933
2934
2938
2942
2943
2946
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2968
2969
2970
2971
2972
2973
2974
2975
2976
2981
2982
2983
2984
2990
2995
2996
2997
2998
2999
3000
3001
3004
3005
3006
3010
3011
3012
3019
3026
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3047
3048
3049
3055
3056
3057
3058
3059
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3087
3088
3089
3092
3093
3094
3095
3096
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
3149
3150
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
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3221
3222
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
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3337
3338
3339
3340
3343
3344
3350
3351
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3370
3371
3377
3378
3383
3384
3385
3386
3387
3388
3402
3403
3404
3405
3406
3407
3408
3409
3415
3416
3417
3418
3419
3420
3421
3435
3436
3437
3441
3442
3443
3444
3445
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
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
3496
3497
3498
3499
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3548
3549
3550
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3567
3568
3569
3570
3571
3572
3575
3576
3577
3578
3579
3580
3581
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3631
3634
3637
3640
3641
3644
3645
3646
3647
3648
3649
3650
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
3694
3695
3696
3697
3698
3699
3704
3705
3706
3707
3708
3709
3710
3711
3712
3715
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3740
3741
3742
3746
3747
3750
3751
3752
3753
3754
3759
3767
3768
3769
3772
3773
3774
3775
3776
3777
3782
3783
3784
3785
3789
3790
3791
3792
3793
3802
3808
3812
3813
3816
3828
3829
3830
3831
3835
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3858
3859
3860
3864
3865
3868
3869
3870
3871
3872
3873
3874
3875
3876
3880
3881
3886
3887
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3907
3908
3911
3912
3913
3914
3915
3921
3922
3923
3924
3925
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3961
3962
3963
3964
3965
3966
3967
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
4002
4003
4004
4005
4006
4009
4010
4011
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
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
4070
4071
4072
4073
4074
4075
4076
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4093
4094
4103
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4138
4139
4140
4141
4142
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4159
4160
4161
4162
4163
4164
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
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4221
4225
4226
4231
4236
4237
4238
4245
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4285
4286
4287
4288
4289
4290
4291
4292
4293
4296
4299
4300
4301
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4332
4333
4337
4338
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4385
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4406
4407
4408
4409
4412
4413
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4451
4454
4455
4456
4457
4458
4461
4462
4463
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4483
4484
4485
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4506
4507
4515
4516
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4545
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4566
4567
4570
4571
4572
4573
4574
4575
4576
4579
4583
4584
4585
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4657
4658
4659
4660
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4682
4685
4686
4687
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4748
4749
4750
4751
4752
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4767
4768
4769
4770
4771
4772
4775
4776
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4823
4824
4825
4826
4827
4828
4829
4830
4834
4835
4836
4837
4838
4844
4845
4846
4847
4848
4852
4853
4854
4855
4856
4857
4861
4862
4866
4867
4868
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4927
4940
4941
4942
4943
4949
4950
4951
4952
4953
4954
4955
4956
4957
4960
4961
4962
4967
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5020
5021
5022
5023
5024
5025
5026
5027
5028
5034
5035
5036
5037
5038
5039
5042
5043
5044
5045
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5158
5159
5160
5161
5162
5163
5171
5172
5176
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5202
5203
5204
5205
5206
5207
5210
5211
5212
5217
5218
5219
5220
5221
5222
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5253
5254
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5273
5274
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5311
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5406
5407
5408
5409
5415
5416
5417
5418
5419
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5477
5478
5479
5482
5483
5484
5485
5486
5487
5488
5489
5491
5492
5493
5494
5496
5497
5498
5499
5500
5502
5503
5504
5508
5509
5512
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5537
5538
5541
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5559
5560
5561
5562
5563
5564
5565
5567
5568
5569
5570
5571
5572
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5625
5626
5627
5628
5637
5638
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5742
5743
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5759
5763
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5782
5783
5784
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5832
5836
5837
5840
5848
5849
5850
5851
5852
5853
5856
5857
5858
5859
5860
5861
5862
5866
5867
5870
5871
5872
5877
5878
5879
5880
5881
5882
5883
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5904
5905
5910
5911
5912
5913
5914
5915
5918
5922
5923
5928
5929
5930
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5972
5973
5974
5975
5979
5980
5984
5985
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6022
6023
6024
6025
6026
6027
6028
6029
6030
6034
6035
6036
6037
6038
6042
6043
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6062
6063
6064
6065
6066
6072
6076
6077
6078
6079
6080
6081
6082
6083
6084
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6104
6105
6108
6109
6110
6111
6112
6113
6116
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6179
6180
6183
6184
6185
6186
6187
6188
6192
6201
6202
6203
6204
6205
6206
6207
6223
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6273
6274
6275
6276
6277
6278
6279
6280
6284
6285
6286
6287
6290
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6324
6325
6329
6330
6331
6332
6333
6334
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6352
6353
6354
6355
6356
6357
6358
6359
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6396
6397
6398
6399
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6432
6433
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6450
6455
6458
6461
6467
6468
6469
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6492
6493
6494
6495
6496
6497
6498
6499
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6522
6527
6532
6537
6542
6547
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6569
6572
6573
6574
6575
6576
6577
6578
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6612
6613
6614
6615
6616
6617
6618
6619
6628
6629
6630
6634
6635
6636
6637
6638
6641
6642
6643
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6659
6660
6661
6662
6663
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6688
6692
6693
6694
6695
6696
6697
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6737
6738
6739
6740
6741
6747
6748
6753
6754
6755
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6795
6796
6797
6798
6799
6803
6804
6808
6809
6810
6811
6812
6813
6817
6818
6819
6820
6821
6822
6823
6824
6825
6829
6832
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6855
6856
6857
6858
6859
6864
6865
6866
6867
6868
6869
6870
6881
6882
6883
6884
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6916
6919
6922
6925
6928
6932
6933
6934
6939
6940
6941
6942
6943
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6994
6997
6998
6999
7003
7004
7005
7006
7008
7012
7013
7017
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7066
7067
7068
7069
7070
7071
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7101
7102
7105
7111
7112
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7145
7146
7147
7148
7149
7150
7151
7152
7153
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7177
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7212
7213
7214
7215
7216
7217
7218
7219
7222
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7242
7243
7244
7245
7246
7247
7248
7249
7250
7255
7256
7264
7265
7266
7275
7276
7277
7278
7279
7280
7281
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7300
7301
7302
7303
7306
7307
7308
7309
7310
7311
7316
7317
7321
7322
7323
7324
7325
7326
7327
7328
7329
7333
7334
7335
7336
7339
7340
7341
7342
7343
7344
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7384
7389
7390
7391
7392
7393
7394
7395
7420
7421
7422
7423
7424
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7453
7454
7455
7456
7457
7458
7459
7460
7466
7482
7483
7489
7490
7491
7492
7493
7494
7497
7501
7502
7506
7507
7508
7509
7510
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7544
7545
7546
7547
7548
7549
7552
7553
7560
7561
7564
7565
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7619
7620
7621
7622
7623
7624
7625
7626
7627
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7655
7656
7659
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7682
7683
7684
7685
7686
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7715
7716
7717
7718
7719
7720
7721
7724
7725
7726
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7755
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7774
7775
7776
7777
7778
7779
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7816
7817
7818
7819
7820
7821
7822
7825
7826
7835
7836
7837
7838
7847
7848
7851
7854
7856
7857
7858
7859
7860
7861
7862
7863
7866
7867
7868
7869
7872
7873
7874
7875
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7941
7942
7943
7944
7945
7946
7949
7950
7951
7960
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8026
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8186
8187
8188
8189
8190
8191
8192
8195
8199
8202
8205
8208
8210
8211
8212
8213
8214
8215
8218
8221
8222
8226
8227
8228
8229
8230
8231
8232
8233
8234
8238
8241
8243
8244
8245
8254
8255
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8286
8287
8288
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8326
8327
8328
8329
8330
8333
8336
8339
8342
8345
8348
8351
8354
8357
8360
8363
8366
8369
8372
8375
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8397
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8413
8416
8419
8422
8425
8426
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8447
8448
8451
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8469
8470
8471
8472
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8496
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8517
8520
8523
8526
8527
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8545
8546
8549
8550
8551
8554
8557
8560
8563
8566
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8587
8590
8593
8594
8595
8596
8597
8600
8603
8606
8607
8608
8609
8610
8611
8612
8613
8614
8617
8618
8621
8624
8627
8630
8633
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8648
8651
8654
8657
8660
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8704
8708
8709
8710
8711
8717
8718
8719
8720
8732
8735
8738
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8762
8765
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8782
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8798
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8814
8818
8819
8820
8821
8822
8823
8827
8828
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8926
8927
8928
8929
8930
8931
8938
8939
8944
8945
8946
8947
8948
8949
8950
8951
8957
8958
8961
8964
8965
8966
8967
8968
8969
8970
8971
8973
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8996
8998
9001
9002
9003
9004
9009
9010
9011
9012
9016
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9036
9037
9038
9039
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9106
9107
9111
9112
9115
9116
9117
9118
9119
9120
9121
9125
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9142
9145
9148
9151
9152
9153
9154
9155
9158
9159
9160
9161
9162
9163
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9186
9187
9197
9198
9203
9204
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9245
9257
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9291
9292
9293
9294
9295
9296
9299
9302
9303
9304
9308
9309
9310
9313
9314
9315
9331
9351
9370
9371
9372
9373
9374
9382
9383
9384
9385
9390
9391
9392
9396
9397
9405
9406
9407
9408
9409
9410
9414
9420
9421
9424
9425
9426
9427
9428
9429
9435
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9465
9466
9467
9481
9482
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9504
9505
9508
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9553
9554
9555
9556
9557
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9591
9595
9596
9597
9598
9599
9600
9601
9602
9603
9614
9615
9616
9624
9625
9626
9631
9632
9633
9634
9635
9636
9637
9638
9641
9642
9643
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9704
9705
9706
9707
9708
9709
9710
9711
9712
9716
9724
9732
9742
9748
9751
9752
9753
9754
9755
9764
9765
9772
9773
9774
9775
9776
9777
9778
9779
9780
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9803
9804
9805
9813
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9836
9839
9842
9845
9848
9851
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9903
9904
9905
9906
9909
9910
9915
9916
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10053
10054
10055
10056
10057
10058
10059
10060
10061
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10083
10084
10093
10098
10099
10103
10104
10105
10106
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10156
10157
10158
10162
10166
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10181
10183
10185
10186
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10262
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10277
10278
10279
10280
10281
10282
10283
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10303
10306
10307
10308
10309
10310
10311
10312
10313
10314
10320
10321
10322
10323
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10346
10347
10348
10349
10351
10354
10355
10356
10357
10358
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10384
10385
10386
10387
10388
10389
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10516
10519
10520
10521
10522
10523
10524
10525
10526
10527
10531
10535
10536
10540
10543
10550
10551
10552
10553
10554
10555
10557
10561
10562
10563
10564
10565
10566
10567
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10609
10610
10611
10612
10613
10614
10615
10616
10617
10620
10623
10624
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10655
10656
10657
10658
10661
10662
10663
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10680
10684
10685
10686
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10794
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10814
10817
10820
10829
10838
10843
10844
10848
10849
10850
10851
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10870
10871
10872
10873
10875
10883
10890
10898
10899
10900
10901
10902
10903
10904
10905
10910
10911
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10927
10928
10929
10930
10931
10938
10939
10940
10943
10944
10945
10946
10947
10948
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10985
10988
10989
10990
10991
10995
10996
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11070
11071
11072
11073
11074
11075
11082
11083
11084
11086
11087
11088
11089
11092
11095
11104
11107
11113
11115
11116
11117
11122
11123
11129
11130
11131
11132
11133
11136
11137
11138
11139
11140
11141
11142
11154
11155
11156
11160
11161
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11180
11181
11182
11183
11186
11187
11191
11192
11193
11194
11197
11198
11202
11203
11204
11205
11206
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11233
11234
11235
11236
11237
11238
11239
11240
11243
11244
11245
11246
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11269
11270
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11314
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11347
11348
11352
11353
11354
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11390
11391
11392
11393
11396
11397
11400
11401
11402
11403
11404
11405
11406
11409
11413
11416
11417
11418
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11472
11473
11474
11475
11476
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11522
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11555
11559
11560
11561
11562
11563
11564
11565
11566
11567
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11585
11586
11589
11590
11591
11592
11593
11594
11597
11600
11604
11605
11606
11607
11608
11609
11610
11611
11616
11617
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11692
11693
11694
11695
11696
11697
11698
11701
11702
11703
11704
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11719
11720
11721
11722
11723
11724
11725
11726
11729
11730
11731
11732
11733
11734
11739
11740
11741
11742
11743
11744
11745
11746
11753
11761
11762
11763
11764
11765
11766
11767
11768
11769
11772
11773
11774
11775
11776
11777
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11795
11796
11797
11798
11799
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11815
11816
11817
11818
11819
11820
11828
11829
11830
11831
11844
11845
11846
11847
11848
11849
11850
11851
11854
11855
11859
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11876
11877
11878
11879
11880
11884
11893
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11943
11944
11946
11947
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11963
11967
11968
11969
11980
11981
11985
11986
11987
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12016
12017
12018
12022
12023
12024
12028
12029
12030
12034
12035
12036
12037
12038
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12062
12063
12064
12065
12066
12067
12079
12080
12087
12088
12089
12090
12091
12092
12093
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12137
12138
12139
12142
12143
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12176
12177
12180
12181
12184
12187
12190
12191
12194
12195
12198
12199
12200
12203
12204
12205
12208
12209
12210
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12230
12231
12232
12233
12234
12235
12236
12237
12243
12244
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12260
12264
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12291
12292
12293
12294
12297
12300
12301
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12322
12323
12324
12327
12330
12333
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12357
12358
12359
12360
12362
12368
12369
12376
12377
12378
12379
12383
12384
12385
12386
12389
12393
12394
12397
12402
12403
12406
12413
12414
12417
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12436
12437
12438
12439
12442
12445
12451
12455
12456
12459
12462
12463
12464
12465
12466
12471
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12488
12489
12490
12491
12492
12495
12496
12497
12498
12503
12505
12507
12509
12510
12511
12512
12513
12514
12515
12516
12517
12520
12521
12522
12523
12524
12528
12529
12530
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12547
12548
12549
12550
12557
12558
12559
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12596
12597
12598
12599
12600
12601
12602
12603
12604
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12635
12638
12639
12640
12641
12642
12643
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12674
12675
12676
12677
12678
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12716
12720
12723
12724
12725
12726
12729
12732
12733
12736
12737
12738
12739
12740
12741
12742
12745
12746
12747
12748
12752
12753
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12779
12780
12786
12789
12790
12791
12792
12793
12794
12795
12799
12800
12801
12802
12803
12804
12805
12806
12810
12811
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12840
12841
12845
12848
12851
12855
12858
12862
12868
12869
12872
12878
12890
12891
12892
12893
12894
12897
12898
12899
12900
12904
12905
12908
12911
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12926
12929
12930
12931
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12950
12951
12952
12956
12960
12961
12969
12970
12971
12972
12973
12974
12975
12978
12981
12984
12985
12986
12987
12988
12989
12990
12991
12994
12995
13001
13006
13007
13008
13009
13010
13014
13023
13024
13025
13028
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13045
13046
13051
13055
13056
13057
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13107
13111
13112
13113
13114
13115
13116
13117
13118
13119
13122
13123
13126
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13167
13171
13172
13173
13174
13175
13176
13177
13178
13179
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13202
13205
13208
13211
13214
13217
13220
13221
13225
13226
13227
13228
13229
13241
13242
13247
13248
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13267
13268
13269
13270
13273
13274
13275
13276
13277
13280
13281
13282
13283
13284
13285
13288
13289
13292
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13309
13314
13315
13316
13317
13322
13326
13329
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13360
13363
13364
13365
13366
13367
13368
13369
13370
13371
13376
13377
13381
13382
13383
13387
13388
13389
13397
13398
13399
13400
13401
13402
13406
13407
13408
13412
13413
13414
13418
13419
13420
13421
13422
13423
13424
13425
13426
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13488
13489
13490
13491
13492
13493
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13523
13524
13525
13526
13527
13528
13529
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13547
13548
13551
13554
13555
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13580
13583
13586
13590
13591
13592
13595
13598
13599
13600
13601
13605
13606
13607
13608
13609
13610
13611
13612
13615
13616
13621
13622
13623
13624
13625
13626
13627
13628
13629
13633
13634
13635
13636
13637
13638
13646
13647
13648
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13672
13675
13678
13684
13687
13688
13689
13693
13694
13695
13698
13699
13702
13703
13704
13705
13708
13709
13710
13711
13712
13713
13714
13718
13719
13720
13721
13722
13723
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13762
13763
13764
13765
13766
13767
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13788
13789
13792
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13819
13820
13824
13825
13830
13831
13832
13833
13834
13835
13836
13837
13838
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13856
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13874
13875
13876
13877
13878
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13917
13918
13919
13920
13922
13923
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13956
13957
13958
13959
13960
13961
13962
13963
13964
13969
13972
13975
13976
13977
13981
13982
13983
13987
13988
13989
13990
13991
13992
13993
13994
13995
13999
14000
14001
14002
14010
14011
14012
14013
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14085
14086
14091
14094
14097
14098
14102
14103
14104
14105
14106
14107
14108
14109
14113
14116
14119
14120
14121
14122
14123
14124
14128
14129
14130
14131
14132
14133
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14161
14162
14163
14166
14169
14170
14171
14172
14175
14176
14180
14181
14182
14183
14184
14185
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14227
14228
14231
14232
14233
14234
14235
14236
14237
14238
14239
14243
14246
14250
14251
14254
14255
14256
14257
14258
14259
14260
14261
14265
14266
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14282
14285
14286
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14330
14333
14334
14335
14336
14339
14343
14348
14349
14350
14351
14352
14353
14354
14355
14356
14360
14361
14362
14363
14364
14373
14376
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14398
14399
14402
14405
14408
14409
14410
14411
14412
14413
14414
14418
14421
14424
14427
14428
14429
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14449
14453
14454
14455
14456
14457
14458
14459
14460
14461
14464
14465
14466
14469
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14485
14490
14491
14492
14493
14494
14495
14496
14497
14498
14507
14508
14509
14510
14511
14512
14513
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14536
14537
14538
14539
14540
14541
14542
14543
14544
14548
14551
14552
14556
14560
14561
14564
14567
14570
14571
14574
14577
14578
14579
14580
14581
14586
14587
14590
14591
14592
14596
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14618
14619
14622
14627
14628
14629
14636
14639
14640
14641
14651
14652
14653
14660
14661
14662
14663
14666
14669
14670
14671
14672
14673
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14697
14698
14701
14702
14706
14707
14708
14709
14710
14711
14712
14715
14718
14719
14720
14724
14725
14726
14727
14728
14732
14733
14734
14738
14739
14740
14741
14742
14743
14744
14748
14751
14754
14755
14756
14757
14758
14759
14760
14761
14762
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14797
14798
14799
14800
14805
14806
14807
14808
14809
14810
14811
14812
14816
14817
14818
14819
14820
14821
14822
14823
14824
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14862
14863
14864
14865
14866
14867
14868
14869
14873
14874
14875
14876
14877
14878
14879
14882
14883
14884
14885
14886
14887
14888
14889
14896
14899
14902
14903
14904
14905
14906
14907
14908
14915
14916
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14937
14938
14942
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14995
14996
14997
15000
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15043
15044
15049
15050
15054
15055
15062
15063
15064
15065
15069
15073
15074
15075
15076
15077
15081
15082
15086
15089
15092
15093
15094
15101
15102
15106
15107
15108
15111
15112
15113
15114
15115
15125
15128
15135
15136
15140
15143
15144
15145
15146
15147
15150
15151
15154
15155
15156
15157
15164
15165
15169
15170
15171
15172
15173
15180
15186
15187
15188
15189
15190
15191
15192
15193
15194
15197
15198
15199
15200
15201
15202
15203
15207
15208
15209
15210
15214
15225
15226
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15277
15280
15281
15282
15283
15291
15292
15293
15294
15298
15301
15305
15306
15307
15308
15309
15310
15311
15312
15314
15315
15316
15319
15320
15321
15325
15326
15332
15333
15334
15335
15338
15341
15342
15343
15347
15348
15354
15355
15356
15357
15365
15366
15367
15368
15369
15370
15374
15381
15382
15386
15391
15395
15396
15397
15398
15399
15400
15401
15402
15403
15407
15408
15427
15428
15429
15430
15431
15432
15436
15439
15443
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15474
15475
15476
15477
15478
15481
15482
15483
15484
15488
15492
15493
15494
15495
15496
15497
15502
15503
15504
15505
15506
15507
15508
15509
15512
15513
15516
15519
15520
15524
15525
15526
15527
15528
15529
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15545
15546
15549
15550
15551
15555
15561
15565
15566
15569
15570
15571
15572
15573
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15606
15607
15608
15611
15612
15613
15614
15618
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15652
15653
15654
15655
15656
15657
15658
15659
15660
15664
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15692
15693
15697
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15730
15731
15732
15736
15737
15738
15739
15740
15744
15749
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15776
15777
15778
15781
15784
15785
15786
15793
15794
15795
15796
15797
15798
15799
15803
15804
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15837
15841
15842
15843
15844
15845
15846
15847
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15865
15866
15867
15868
15869
15870
15871
15872
15873
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15902
15903
15904
15905
15906
15907
15911
15912
15913
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15996
16000
16001
16002
16003
16004
16005
16006
16007
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16028
16038
16039
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16145
16146
16147
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16164
16165
16166
16167
16168
16169
16170
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16191
16192
16193
16194
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16222
16223
16224
16225
16226
16227
16228
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16257
16258
16259
16260
16261
16262
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16303
16304
16305
16306
16307
16308
16309
16310
16315
16316
16317
16318
16322
16323
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16367
16368
16369
16370
16371
16372
16373
16374
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16395
16396
16397
16401
16409
16410
16411
16412
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
/* ... */
#define JIM_OPTIMIZATION
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>
#include <errno.h>
#include <time.h>
#include <setjmp.h>
#include "jim.h"
#include "jimautoconf.h"
#include "utf8.h"
13 includes
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
#ifdef HAVE_CRT_EXTERNS_H
#include <crt_externs.h>
#endif
#include <math.h>
#ifndef TCL_LIBRARY
#define TCL_LIBRARY "."
#endif
#ifndef TCL_PLATFORM_OS
#define TCL_PLATFORM_OS "unknown"
#endif
#ifndef TCL_PLATFORM_PLATFORM
#define TCL_PLATFORM_PLATFORM "unknown"
#endif
#ifndef TCL_PLATFORM_PATH_SEPARATOR
#define TCL_PLATFORM_PATH_SEPARATOR ":"
#endif
#ifdef JIM_MAINTAINER
#define JIM_DEBUG_COMMAND
#define JIM_DEBUG_PANIC
/* ... */#endif
/* ... */
#define JIM_INTEGER_SPACE 24
const char *jim_tt_name(int type);
#ifdef JIM_DEBUG_PANIC
static void JimPanicDump(int fail_condition, const char *fmt, ...);
#define JimPanic(X) JimPanicDump X
/* ... */#else
#define JimPanic(X)
#endif
#ifdef JIM_OPTIMIZATION
static int JimIsWide(Jim_Obj *objPtr);
#define JIM_IF_OPTIM(X) X
/* ... */#else
#define JIM_IF_OPTIM(X)
#endif
/* ... */
/* ... */
static char JimEmptyStringRep[] = "";
/* ... */
static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action);
static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int listindex, Jim_Obj *newObjPtr,
int flags);
static int Jim_ListIndices(Jim_Interp *interp, Jim_Obj *listPtr, Jim_Obj *const *indexv, int indexc,
Jim_Obj **resultObj, int flags);
static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands);
static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr);
static void SetDictSubstFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
static void JimSetFailedEnumResult(Jim_Interp *interp, const char *arg, const char *badtype,
const char *prefix, const char *const *tablePtr, const char *name);
static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv);
static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr);
static int JimSign(jim_wide w);
static void JimPrngSeed(Jim_Interp *interp, unsigned char *seed, int seedLen);
static void JimRandomBytes(Jim_Interp *interp, void *dest, unsigned int len);
static int JimSetNewVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr, Jim_Var *var);
static Jim_Var *JimFindVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr);
#define JimWideValue(objPtr) (objPtr)->internalRep.wideValue
#define JimObjTypeName(O) ((O)->typePtr ? (O)->typePtr->name : "none")
static int utf8_tounicode_case(const char *s, int *uc, int upper)
{
int l = utf8_tounicode(s, uc);
if (upper) {
*uc = utf8_upper(*uc);
}if (upper) { ... }
return l;
}{ ... }
#define JIM_CHARSET_SCAN 2
#define JIM_CHARSET_GLOB 0
/* ... */
static const char *JimCharsetMatch(const char *pattern, int plen, int c, int flags)
{
int not = 0;
int pchar;
int match = 0;
int nocase = 0;
int n;
if (flags & JIM_NOCASE) {
nocase++;
c = utf8_upper(c);
}if (flags & JIM_NOCASE) { ... }
if (flags & JIM_CHARSET_SCAN) {
if (*pattern == '^') {
not++;
pattern++;
plen--;
}if (*pattern == '^') { ... }
if (*pattern == ']') {
goto first;
}if (*pattern == ']') { ... }
}if (flags & JIM_CHARSET_SCAN) { ... }
while (plen && *pattern != ']') {
if (pattern[0] == '\\') {
first:
n = utf8_tounicode_case(pattern, &pchar, nocase);
pattern += n;
plen -= n;
}if (pattern[0] == '\\') { ... }
else {
int start;
int end;
n = utf8_tounicode_case(pattern, &start, nocase);
pattern += n;
plen -= n;
if (pattern[0] == '-' && plen > 1) {
n = 1 + utf8_tounicode_case(pattern + 1, &end, nocase);
pattern += n;
plen -= n;
if ((c >= start && c <= end) || (c >= end && c <= start)) {
match = 1;
}if ((c >= start && c <= end) || (c >= end && c <= start)) { ... }
continue;
}if (pattern[0] == '-' && plen > 1) { ... }
pchar = start;
}else { ... }
if (pchar == c) {
match = 1;
}if (pchar == c) { ... }
}while (plen && *pattern != ']') { ... }
if (not) {
match = !match;
}if (not) { ... }
return match ? pattern : NULL;
}{ ... }
/* ... */
static int JimGlobMatch(const char *pattern, int plen, const char *string, int slen, int nocase)
{
int c;
int pchar;
int n;
const char *p;
while (plen) {
switch (pattern[0]) {
case '*':
while (pattern[1] == '*' && plen) {
pattern++;
plen--;
}while (pattern[1] == '*' && plen) { ... }
pattern++;
plen--;
if (!plen) {
return 1;
}if (!plen) { ... }
while (slen) {
if (JimGlobMatch(pattern, plen, string, slen, nocase))
return 1;
n = utf8_tounicode(string, &c);
string += n;
slen -= n;
}while (slen) { ... }
return 0;
case '*':
case '?':
n = utf8_tounicode(string, &c);
string += n;
slen -= n;
break;
case '?':
case '[': {
n = utf8_tounicode(string, &c);
string += n;
slen -= n;
p = JimCharsetMatch(pattern + 1, plen - 1, c, nocase ? JIM_NOCASE : 0);
if (!p) {
return 0;
}if (!p) { ... }
plen -= p - pattern;
pattern = p;
if (!plen) {
continue;
}if (!plen) { ... }
break;
...}case '[':
case '\\':
if (pattern[1]) {
pattern++;
plen--;
}if (pattern[1]) { ... }
case '\\':
default:
n = utf8_tounicode_case(string, &c, nocase);
string += n;
slen -= n;
utf8_tounicode_case(pattern, &pchar, nocase);
if (pchar != c) {
return 0;
}if (pchar != c) { ... }
break;default
}switch (pattern[0]) { ... }
n = utf8_tounicode_case(pattern, &pchar, nocase);
pattern += n;
plen -= n;
if (!slen) {
while (*pattern == '*' && plen) {
pattern++;
plen--;
}while (*pattern == '*' && plen) { ... }
break;
}if (!slen) { ... }
}while (plen) { ... }
if (!plen && !slen) {
return 1;
}if (!plen && !slen) { ... }
return 0;
}{ ... }
/* ... */
static int JimStringCompareUtf8(const char *s1, int l1, const char *s2, int l2, int nocase)
{
int minlen = l1;
if (l2 < l1) {
minlen = l2;
}if (l2 < l1) { ... }
while (minlen) {
int c1, c2;
s1 += utf8_tounicode_case(s1, &c1, nocase);
s2 += utf8_tounicode_case(s2, &c2, nocase);
if (c1 != c2) {
return JimSign(c1 - c2);
}if (c1 != c2) { ... }
minlen--;
}while (minlen) { ... }
if (l1 < l2) {
return -1;
}if (l1 < l2) { ... }
if (l1 > l2) {
return 1;
}if (l1 > l2) { ... }
return 0;
}{ ... }
/* ... */
static int JimStringFirst(const char *s1, int l1, const char *s2, int l2, int idx)
{
int i;
int l1bytelen;
if (!l1 || !l2 || l1 > l2) {
return -1;
}if (!l1 || !l2 || l1 > l2) { ... }
if (idx < 0)
idx = 0;
s2 += utf8_index(s2, idx);
l1bytelen = utf8_index(s1, l1);
for (i = idx; i <= l2 - l1; i++) {
int c;
if (memcmp(s2, s1, l1bytelen) == 0) {
return i;
}if (memcmp(s2, s1, l1bytelen) == 0) { ... }
s2 += utf8_tounicode(s2, &c);
}for (i = idx; i <= l2 - l1; i++) { ... }
return -1;
}{ ... }
/* ... */
static int JimStringLast(const char *s1, int l1, const char *s2, int l2)
{
const char *p;
if (!l1 || !l2 || l1 > l2)
return -1;
for (p = s2 + l2 - 1; p != s2 - 1; p--) {
if (*p == *s1 && memcmp(s1, p, l1) == 0) {
return p - s2;
}if (*p == *s1 && memcmp(s1, p, l1) == 0) { ... }
}for (p = s2 + l2 - 1; p != s2 - 1; p--) { ... }
return -1;
}{ ... }
#ifdef JIM_UTF8
/* ... */
static int JimStringLastUtf8(const char *s1, int l1, const char *s2, int l2)
{
int n = JimStringLast(s1, utf8_index(s1, l1), s2, utf8_index(s2, l2));
if (n > 0) {
n = utf8_strlen(s2, n);
}if (n > 0) { ... }
return n;
}JimStringLastUtf8 (const char *s1, int l1, const char *s2, int l2) { ... }
/* ... */#endif
/* ... */
static int JimCheckConversion(const char *str, const char *endptr)
{
if (str[0] == '\0' || str == endptr) {
return JIM_ERR;
}if (str[0] == '\0' || str == endptr) { ... }
if (endptr[0] != '\0') {
while (*endptr) {
if (!isspace(UCHAR(*endptr))) {
return JIM_ERR;
}if (!isspace(UCHAR(*endptr))) { ... }
endptr++;
}while (*endptr) { ... }
}if (endptr[0] != '\0') { ... }
return JIM_OK;
}{ ... }
/* ... */
static int JimNumberBase(const char *str, int *base, int *sign)
{
int i = 0;
*base = 0;
while (isspace(UCHAR(str[i]))) {
i++;
}while (isspace(UCHAR(str[i]))) { ... }
if (str[i] == '-') {
*sign = -1;
i++;
}if (str[i] == '-') { ... }
else {
if (str[i] == '+') {
i++;
}if (str[i] == '+') { ... }
*sign = 1;
}else { ... }
if (str[i] != '0') {
return 0;
}if (str[i] != '0') { ... }
switch (str[i + 1]) {
case 'x': case 'X': *base = 16; break;
case 'o': case 'O': *base = 8; break;
case 'b': case 'B': *base = 2; break;
case 'd': case 'D': *base = 10; break;
default: return 0;
}switch (str[i + 1]) { ... }
i += 2;
if (str[i] != '-' && str[i] != '+' && !isspace(UCHAR(str[i]))) {
return i;
}if (str[i] != '-' && str[i] != '+' && !isspace(UCHAR(str[i]))) { ... }
*base = 0;
return 0;
}{ ... }
/* ... */
static long jim_strtol(const char *str, char **endptr)
{
int sign;
int base;
int i = JimNumberBase(str, &base, &sign);
if (base != 0) {
long value = strtol(str + i, endptr, base);
if (endptr == NULL || *endptr != str + i) {
return value * sign;
}if (endptr == NULL || *endptr != str + i) { ... }
}if (base != 0) { ... }
return strtol(str, endptr, 10);
}{ ... }
/* ... */
static jim_wide jim_strtoull(const char *str, char **endptr)
{
#ifdef HAVE_LONG_LONG
int sign;
int base;
int i = JimNumberBase(str, &base, &sign);
if (base != 0) {
jim_wide value = strtoull(str + i, endptr, base);
if (endptr == NULL || *endptr != str + i) {
return value * sign;
}if (endptr == NULL || *endptr != str + i) { ... }
}if (base != 0) { ... }
return strtoull(str, endptr, 10);/* ... */
#else
return (unsigned long)jim_strtol(str, endptr);
#endif
}{ ... }
int Jim_StringToWide(const char *str, jim_wide * widePtr, int base)
{
char *endptr;
if (base) {
*widePtr = strtoull(str, &endptr, base);
}if (base) { ... }
else {
*widePtr = jim_strtoull(str, &endptr);
}else { ... }
return JimCheckConversion(str, endptr);
}{ ... }
int Jim_StringToDouble(const char *str, double *doublePtr)
{
char *endptr;
errno = 0;
*doublePtr = strtod(str, &endptr);
return JimCheckConversion(str, endptr);
}{ ... }
static jim_wide JimPowWide(jim_wide b, jim_wide e)
{
jim_wide res = 1;
if (b == 1) {
return 1;
}if (b == 1) { ... }
if (e < 0) {
if (b != -1) {
return 0;
}if (b != -1) { ... }
/* ... */
e = -e;
}if (e < 0) { ... }
while (e)
{
if (e & 1) {
res *= b;
}if (e & 1) { ... }
e >>= 1;
b *= b;
}while (e) { ... }
return res;
}{ ... }
/* ... */
#ifdef JIM_DEBUG_PANIC
static void JimPanicDump(int condition, const char *fmt, ...)
{
va_list ap;
if (!condition) {
return;
}if (!condition) { ... }
va_start(ap, fmt);
fprintf(stderr, "\nJIM INTERPRETER PANIC: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n\n");
va_end(ap);
#if defined(HAVE_BACKTRACE)
{
void *array[40];
int size, i;
char **strings;
size = backtrace(array, 40);
strings = backtrace_symbols(array, size);
for (i = 0; i < size; i++)
fprintf(stderr, "[backtrace] %s\n", strings[i]);
fprintf(stderr, "[backtrace] Include the above lines and the output\n");
fprintf(stderr, "[backtrace] of 'nm <executable>' in the bug report.\n");
}/* ... */
defined (HAVE_BACKTRACE) { ... }#endif
exit(1);
}JimPanicDump (int condition, const char *fmt, ...) { ... }
/* ... */#endif
/* ... */
void *Jim_Alloc(int size)
{
return size ? malloc(size) : NULL;
}{ ... }
void Jim_Free(void *ptr)
{
free(ptr);
}{ ... }
void *Jim_Realloc(void *ptr, int size)
{
return realloc(ptr, size);
}{ ... }
char *Jim_StrDup(const char *s)
{
return strdup(s);
}{ ... }
char *Jim_StrDupLen(const char *s, int l)
{
char *copy = Jim_Alloc(l + 1);
memcpy(copy, s, l + 1);
copy[l] = 0;
return copy;
}{ ... }
/* ... */
static jim_wide JimClock(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (jim_wide) tv.tv_sec * 1000000 + tv.tv_usec;
}{ ... }
/* ... */
static void JimExpandHashTableIfNeeded(Jim_HashTable *ht);
static unsigned int JimHashTableNextPower(unsigned int size);
static Jim_HashEntry *JimInsertHashEntry(Jim_HashTable *ht, const void *key, int replace);
-------------------------- private prototypes
unsigned int Jim_IntHashFunction(unsigned int key)
{
key += ~(key << 15);
key ^= (key >> 10);
key += (key << 3);
key ^= (key >> 6);
key += ~(key << 11);
key ^= (key >> 16);
return key;
}{ ... }
unsigned int Jim_GenHashFunction(const unsigned char *string, int length)
{
unsigned result = 0;
string += length;
while (length--) {
result += (result << 3) + (unsigned char)(*--string);
}while (length--) { ... }
return result;
}{ ... }
-------------------------- hash functions
/* ... */
static void JimResetHashTable(Jim_HashTable *ht)
{
ht->table = NULL;
ht->size = 0;
ht->sizemask = 0;
ht->used = 0;
ht->collisions = 0;
#ifdef JIM_RANDOMISE_HASH
/* ... */
ht->uniq = (rand() ^ time(NULL) ^ clock());/* ... */
#else
ht->uniq = 0;
#endif
}{ ... }
static void JimInitHashTableIterator(Jim_HashTable *ht, Jim_HashTableIterator *iter)
{
iter->ht = ht;
iter->index = -1;
iter->entry = NULL;
iter->nextEntry = NULL;
}{ ... }
int Jim_InitHashTable(Jim_HashTable *ht, const Jim_HashTableType *type, void *privDataPtr)
{
JimResetHashTable(ht);
ht->type = type;
ht->privdata = privDataPtr;
return JIM_OK;
}{ ... }
void Jim_ExpandHashTable(Jim_HashTable *ht, unsigned int size)
{
Jim_HashTable n;
unsigned int realsize = JimHashTableNextPower(size), i;
/* ... */
if (size <= ht->used)
return;
Jim_InitHashTable(&n, ht->type, ht->privdata);
n.size = realsize;
n.sizemask = realsize - 1;
n.table = Jim_Alloc(realsize * sizeof(Jim_HashEntry *));
n.uniq = ht->uniq;
memset(n.table, 0, realsize * sizeof(Jim_HashEntry *));
/* ... */
n.used = ht->used;
for (i = 0; ht->used > 0; i++) {
Jim_HashEntry *he, *nextHe;
if (ht->table[i] == NULL)
continue;
he = ht->table[i];
while (he) {
unsigned int h;
nextHe = he->next;
h = Jim_HashKey(ht, he->key) & n.sizemask;
he->next = n.table[h];
n.table[h] = he;
ht->used--;
he = nextHe;
}while (he) { ... }
}for (i = 0; ht->used > 0; i++) { ... }
assert(ht->used == 0);
Jim_Free(ht->table);
*ht = n;
}{ ... }
/* ... */
int Jim_AddHashEntry(Jim_HashTable *ht, const void *key, void *val)
{
Jim_HashEntry *entry = JimInsertHashEntry(ht, key, 0);;
if (entry == NULL)
return JIM_ERR;
Jim_SetHashKey(ht, entry, key);
Jim_SetHashVal(ht, entry, val);
return JIM_OK;
}{ ... }
int Jim_ReplaceHashEntry(Jim_HashTable *ht, const void *key, void *val)
{
int existed;
Jim_HashEntry *entry;
/* ... */
entry = JimInsertHashEntry(ht, key, 1);
if (entry->key) {
/* ... */
if (ht->type->valDestructor && ht->type->valDup) {
void *newval = ht->type->valDup(ht->privdata, val);
ht->type->valDestructor(ht->privdata, entry->u.val);
entry->u.val = newval;
}if (ht->type->valDestructor && ht->type->valDup) { ... }
else {
Jim_FreeEntryVal(ht, entry);
Jim_SetHashVal(ht, entry, val);
}else { ... }
existed = 1;
}if (entry->key) { ... }
else {
Jim_SetHashKey(ht, entry, key);
Jim_SetHashVal(ht, entry, val);
existed = 0;
}else { ... }
return existed;
}{ ... }
/* ... */
int Jim_DeleteHashEntry(Jim_HashTable *ht, const void *key)
{
if (ht->used) {
unsigned int h = Jim_HashKey(ht, key) & ht->sizemask;
Jim_HashEntry *prevHe = NULL;
Jim_HashEntry *he = ht->table[h];
while (he) {
if (Jim_CompareHashKeys(ht, key, he->key)) {
if (prevHe)
prevHe->next = he->next;
else
ht->table[h] = he->next;
ht->used--;
Jim_FreeEntryKey(ht, he);
Jim_FreeEntryVal(ht, he);
Jim_Free(he);
return JIM_OK;
}if (Jim_CompareHashKeys(ht, key, he->key)) { ... }
prevHe = he;
he = he->next;
}while (he) { ... }
}if (ht->used) { ... }
return JIM_ERR;
}{ ... }
/* ... */
void Jim_ClearHashTable(Jim_HashTable *ht)
{
unsigned int i;
for (i = 0; ht->used > 0; i++) {
Jim_HashEntry *he, *nextHe;
he = ht->table[i];
while (he) {
nextHe = he->next;
Jim_FreeEntryKey(ht, he);
Jim_FreeEntryVal(ht, he);
Jim_Free(he);
ht->used--;
he = nextHe;
}while (he) { ... }
ht->table[i] = NULL;
}for (i = 0; ht->used > 0; i++) { ... }
}{ ... }
/* ... */
int Jim_FreeHashTable(Jim_HashTable *ht)
{
Jim_ClearHashTable(ht);
Jim_Free(ht->table);
JimResetHashTable(ht);
return JIM_OK;
}{ ... }
Jim_HashEntry *Jim_FindHashEntry(Jim_HashTable *ht, const void *key)
{
Jim_HashEntry *he;
unsigned int h;
if (ht->used == 0)
return NULL;
h = Jim_HashKey(ht, key) & ht->sizemask;
he = ht->table[h];
while (he) {
if (Jim_CompareHashKeys(ht, key, he->key))
return he;
he = he->next;
}while (he) { ... }
return NULL;
}{ ... }
Jim_HashTableIterator *Jim_GetHashTableIterator(Jim_HashTable *ht)
{
Jim_HashTableIterator *iter = Jim_Alloc(sizeof(*iter));
JimInitHashTableIterator(ht, iter);
return iter;
}{ ... }
Jim_HashEntry *Jim_NextHashEntry(Jim_HashTableIterator *iter)
{
while (1) {
if (iter->entry == NULL) {
iter->index++;
if (iter->index >= (signed)iter->ht->size)
break;
iter->entry = iter->ht->table[iter->index];
}if (iter->entry == NULL) { ... }
else {
iter->entry = iter->nextEntry;
}else { ... }
if (iter->entry) {
/* ... */
iter->nextEntry = iter->entry->next;
return iter->entry;
}if (iter->entry) { ... }
}while (1) { ... }
return NULL;
}{ ... }
----------------------------- API implementation
static void JimExpandHashTableIfNeeded(Jim_HashTable *ht)
{
/* ... */
if (ht->size == 0)
Jim_ExpandHashTable(ht, JIM_HT_INITIAL_SIZE);
if (ht->size == ht->used)
Jim_ExpandHashTable(ht, ht->size * 2);
}{ ... }
static unsigned int JimHashTableNextPower(unsigned int size)
{
unsigned int i = JIM_HT_INITIAL_SIZE;
if (size >= 2147483648U)
return 2147483648U;
while (1) {
if (i >= size)
return i;
i *= 2;
}while (1) { ... }
}{ ... }
/* ... */
static Jim_HashEntry *JimInsertHashEntry(Jim_HashTable *ht, const void *key, int replace)
{
unsigned int h;
Jim_HashEntry *he;
JimExpandHashTableIfNeeded(ht);
h = Jim_HashKey(ht, key) & ht->sizemask;
he = ht->table[h];
while (he) {
if (Jim_CompareHashKeys(ht, key, he->key))
return replace ? he : NULL;
he = he->next;
}while (he) { ... }
he = Jim_Alloc(sizeof(*he));
he->next = ht->table[h];
ht->table[h] = he;
ht->used++;
he->key = NULL;
return he;
}{ ... }
------------------------- private functions
static unsigned int JimStringCopyHTHashFunction(const void *key)
{
return Jim_GenHashFunction(key, strlen(key));
}{ ... }
static void *JimStringCopyHTDup(void *privdata, const void *key)
{
return Jim_StrDup(key);
}{ ... }
static int JimStringCopyHTKeyCompare(void *privdata, const void *key1, const void *key2)
{
return strcmp(key1, key2) == 0;
}{ ... }
static void JimStringCopyHTKeyDestructor(void *privdata, void *key)
{
Jim_Free(key);
}{ ... }
static const Jim_HashTableType JimPackageHashTableType = {
JimStringCopyHTHashFunction,
JimStringCopyHTDup,
NULL,
JimStringCopyHTKeyCompare,
JimStringCopyHTKeyDestructor,
NULL
...};
typedef struct AssocDataValue
{
Jim_InterpDeleteProc *delProc;
void *data;
...} AssocDataValue;
static void JimAssocDataHashTableValueDestructor(void *privdata, void *data)
{
AssocDataValue *assocPtr = (AssocDataValue *) data;
if (assocPtr->delProc != NULL)
assocPtr->delProc((Jim_Interp *)privdata, assocPtr->data);
Jim_Free(data);
}{ ... }
static const Jim_HashTableType JimAssocDataHashTableType = {
JimStringCopyHTHashFunction,
JimStringCopyHTDup,
NULL,
JimStringCopyHTKeyCompare,
JimStringCopyHTKeyDestructor,
JimAssocDataHashTableValueDestructor
...};
/* ... */
void Jim_InitStack(Jim_Stack *stack)
{
stack->len = 0;
stack->maxlen = 0;
stack->vector = NULL;
}{ ... }
void Jim_FreeStack(Jim_Stack *stack)
{
Jim_Free(stack->vector);
}{ ... }
int Jim_StackLen(Jim_Stack *stack)
{
return stack->len;
}{ ... }
void Jim_StackPush(Jim_Stack *stack, void *element)
{
int neededLen = stack->len + 1;
if (neededLen > stack->maxlen) {
stack->maxlen = neededLen < 20 ? 20 : neededLen * 2;
stack->vector = Jim_Realloc(stack->vector, sizeof(void *) * stack->maxlen);
}if (neededLen > stack->maxlen) { ... }
stack->vector[stack->len] = element;
stack->len++;
}{ ... }
void *Jim_StackPop(Jim_Stack *stack)
{
if (stack->len == 0)
return NULL;
stack->len--;
return stack->vector[stack->len];
}{ ... }
void *Jim_StackPeek(Jim_Stack *stack)
{
if (stack->len == 0)
return NULL;
return stack->vector[stack->len - 1];
}{ ... }
void Jim_FreeStackElements(Jim_Stack *stack, void (*freeFunc) (void *ptr))
{
int i;
for (i = 0; i < stack->len; i++)
freeFunc(stack->vector[i]);
}{ ... }
/* ... */
#define JIM_TT_NONE 0
#define JIM_TT_STR 1
#define JIM_TT_ESC 2
#define JIM_TT_VAR 3
#define JIM_TT_DICTSUGAR 4
#define JIM_TT_CMD 5
#define JIM_TT_SEP 6
#define JIM_TT_EOL 7
#define JIM_TT_EOF 8
#define JIM_TT_LINE 9
#define JIM_TT_WORD 10
#define JIM_TT_SUBEXPR_START 11
#define JIM_TT_SUBEXPR_END 12
#define JIM_TT_SUBEXPR_COMMA 13
#define JIM_TT_EXPR_INT 14
#define JIM_TT_EXPR_DOUBLE 15
#define JIM_TT_EXPR_BOOLEAN 16
#define JIM_TT_EXPRSUGAR 17
#define JIM_TT_EXPR_OP 20
#define TOKEN_IS_SEP(type) (type >= JIM_TT_SEP && type <= JIM_TT_EOF)
#define TOKEN_IS_EXPR_START(type) (type == JIM_TT_NONE || type == JIM_TT_SUBEXPR_START || type == JIM_TT_SUBEXPR_COMMA)
#define TOKEN_IS_EXPR_OP(type) (type >= JIM_TT_EXPR_OP)
22 defines
/* ... */
struct JimParseMissing {
int ch;
int line;
...};
/* ... */
struct JimParserCtx
{
const char *p;
int len;
int linenr;
const char *tstart;
const char *tend;
int tline;
int tt;
int eof;
int inquote;
int comment;
struct JimParseMissing missing;
...};
static int JimParseScript(struct JimParserCtx *pc);
static int JimParseSep(struct JimParserCtx *pc);
static int JimParseEol(struct JimParserCtx *pc);
static int JimParseCmd(struct JimParserCtx *pc);
static int JimParseQuote(struct JimParserCtx *pc);
static int JimParseVar(struct JimParserCtx *pc);
static int JimParseBrace(struct JimParserCtx *pc);
static int JimParseStr(struct JimParserCtx *pc);
static int JimParseComment(struct JimParserCtx *pc);
static void JimParseSubCmd(struct JimParserCtx *pc);
static int JimParseSubQuote(struct JimParserCtx *pc);
static Jim_Obj *JimParserGetTokenObj(Jim_Interp *interp, struct JimParserCtx *pc);
/* ... */
static void JimParserInit(struct JimParserCtx *pc, const char *prg, int len, int linenr)
{
pc->p = prg;
pc->len = len;
pc->tstart = NULL;
pc->tend = NULL;
pc->tline = 0;
pc->tt = JIM_TT_NONE;
pc->eof = 0;
pc->inquote = 0;
pc->linenr = linenr;
pc->comment = 1;
pc->missing.ch = ' ';
pc->missing.line = linenr;
}{ ... }
static int JimParseScript(struct JimParserCtx *pc)
{
while (1) {
if (!pc->len) {
pc->tstart = pc->p;
pc->tend = pc->p - 1;
pc->tline = pc->linenr;
pc->tt = JIM_TT_EOL;
if (pc->inquote) {
pc->missing.ch = '"';
}if (pc->inquote) { ... }
pc->eof = 1;
return JIM_OK;
}if (!pc->len) { ... }
switch (*(pc->p)) {
case '\\':
if (*(pc->p + 1) == '\n' && !pc->inquote) {
return JimParseSep(pc);
}if (*(pc->p + 1) == '\n' && !pc->inquote) { ... }
pc->comment = 0;
return JimParseStr(pc);case '\\':
case ' ':
case '\t':
case '\r':
case '\f':
if (!pc->inquote)
return JimParseSep(pc);
pc->comment = 0;
return JimParseStr(pc);case '\f':
case '\n':
case ';':
pc->comment = 1;
if (!pc->inquote)
return JimParseEol(pc);
return JimParseStr(pc);case ';':
case '[':
pc->comment = 0;
return JimParseCmd(pc);case '[':
case '$':
pc->comment = 0;
if (JimParseVar(pc) == JIM_ERR) {
pc->tstart = pc->tend = pc->p++;
pc->len--;
pc->tt = JIM_TT_ESC;
}if (JimParseVar(pc) == JIM_ERR) { ... }
return JIM_OK;case '$':
case '#':
if (pc->comment) {
JimParseComment(pc);
continue;
}if (pc->comment) { ... }
return JimParseStr(pc);case '#':
default:
pc->comment = 0;
return JimParseStr(pc);default
}switch (*(pc->p)) { ... }
return JIM_OK;
}while (1) { ... }
}{ ... }
static int JimParseSep(struct JimParserCtx *pc)
{
pc->tstart = pc->p;
pc->tline = pc->linenr;
while (isspace(UCHAR(*pc->p)) || (*pc->p == '\\' && *(pc->p + 1) == '\n')) {
if (*pc->p == '\n') {
break;
}if (*pc->p == '\n') { ... }
if (*pc->p == '\\') {
pc->p++;
pc->len--;
pc->linenr++;
}if (*pc->p == '\\') { ... }
pc->p++;
pc->len--;
}while (isspace(UCHAR(*pc->p)) || (*pc->p == '\\' && *(pc->p + 1) == '\n')) { ... }
pc->tend = pc->p - 1;
pc->tt = JIM_TT_SEP;
return JIM_OK;
}{ ... }
static int JimParseEol(struct JimParserCtx *pc)
{
pc->tstart = pc->p;
pc->tline = pc->linenr;
while (isspace(UCHAR(*pc->p)) || *pc->p == ';') {
if (*pc->p == '\n')
pc->linenr++;
pc->p++;
pc->len--;
}while (isspace(UCHAR(*pc->p)) || *pc->p == ';') { ... }
pc->tend = pc->p - 1;
pc->tt = JIM_TT_EOL;
return JIM_OK;
}{ ... }
/* ... */
/* ... */
static void JimParseSubBrace(struct JimParserCtx *pc)
{
int level = 1;
pc->p++;
pc->len--;
while (pc->len) {
switch (*pc->p) {
case '\\':
if (pc->len > 1) {
if (*++pc->p == '\n') {
pc->linenr++;
}if (*++pc->p == '\n') { ... }
pc->len--;
}if (pc->len > 1) { ... }
break;
case '\\':
case '{':
level++;
break;
case '{':
case '}':
if (--level == 0) {
pc->tend = pc->p - 1;
pc->p++;
pc->len--;
return;
}if (--level == 0) { ... }
break;
case '}':
case '\n':
pc->linenr++;
break;case '\n':
}switch (*pc->p) { ... }
pc->p++;
pc->len--;
}while (pc->len) { ... }
pc->missing.ch = '{';
pc->missing.line = pc->tline;
pc->tend = pc->p - 1;
}{ ... }
/* ... */
static int JimParseSubQuote(struct JimParserCtx *pc)
{
int tt = JIM_TT_STR;
int line = pc->tline;
pc->p++;
pc->len--;
while (pc->len) {
switch (*pc->p) {
case '\\':
if (pc->len > 1) {
if (*++pc->p == '\n') {
pc->linenr++;
}if (*++pc->p == '\n') { ... }
pc->len--;
tt = JIM_TT_ESC;
}if (pc->len > 1) { ... }
break;
case '\\':
case '"':
pc->tend = pc->p - 1;
pc->p++;
pc->len--;
return tt;
case '"':
case '[':
JimParseSubCmd(pc);
tt = JIM_TT_ESC;
continue;
case '[':
case '\n':
pc->linenr++;
break;
case '\n':
case '$':
tt = JIM_TT_ESC;
break;case '$':
}switch (*pc->p) { ... }
pc->p++;
pc->len--;
}while (pc->len) { ... }
pc->missing.ch = '"';
pc->missing.line = line;
pc->tend = pc->p - 1;
return tt;
}{ ... }
/* ... */
static void JimParseSubCmd(struct JimParserCtx *pc)
{
int level = 1;
int startofword = 1;
int line = pc->tline;
pc->p++;
pc->len--;
while (pc->len) {
switch (*pc->p) {
case '\\':
if (pc->len > 1) {
if (*++pc->p == '\n') {
pc->linenr++;
}if (*++pc->p == '\n') { ... }
pc->len--;
}if (pc->len > 1) { ... }
break;
case '\\':
case '[':
level++;
break;
case '[':
case ']':
if (--level == 0) {
pc->tend = pc->p - 1;
pc->p++;
pc->len--;
return;
}if (--level == 0) { ... }
break;
case ']':
case '"':
if (startofword) {
JimParseSubQuote(pc);
if (pc->missing.ch == '"') {
return;
}if (pc->missing.ch == '"') { ... }
continue;
}if (startofword) { ... }
break;
case '"':
case '{':
JimParseSubBrace(pc);
startofword = 0;
continue;
case '{':
case '\n':
pc->linenr++;
break;case '\n':
}switch (*pc->p) { ... }
startofword = isspace(UCHAR(*pc->p));
pc->p++;
pc->len--;
}while (pc->len) { ... }
pc->missing.ch = '[';
pc->missing.line = line;
pc->tend = pc->p - 1;
}{ ... }
static int JimParseBrace(struct JimParserCtx *pc)
{
pc->tstart = pc->p + 1;
pc->tline = pc->linenr;
pc->tt = JIM_TT_STR;
JimParseSubBrace(pc);
return JIM_OK;
}{ ... }
static int JimParseCmd(struct JimParserCtx *pc)
{
pc->tstart = pc->p + 1;
pc->tline = pc->linenr;
pc->tt = JIM_TT_CMD;
JimParseSubCmd(pc);
return JIM_OK;
}{ ... }
static int JimParseQuote(struct JimParserCtx *pc)
{
pc->tstart = pc->p + 1;
pc->tline = pc->linenr;
pc->tt = JimParseSubQuote(pc);
return JIM_OK;
}{ ... }
static int JimParseVar(struct JimParserCtx *pc)
{
pc->p++;
pc->len--;
#ifdef EXPRSUGAR_BRACKET
if (*pc->p == '[') {
JimParseCmd(pc);
pc->tt = JIM_TT_EXPRSUGAR;
return JIM_OK;
}if (*pc->p == '[') { ... }
/* ... */#endif
pc->tstart = pc->p;
pc->tt = JIM_TT_VAR;
pc->tline = pc->linenr;
if (*pc->p == '{') {
pc->tstart = ++pc->p;
pc->len--;
while (pc->len && *pc->p != '}') {
if (*pc->p == '\n') {
pc->linenr++;
}if (*pc->p == '\n') { ... }
pc->p++;
pc->len--;
}while (pc->len && *pc->p != '}') { ... }
pc->tend = pc->p - 1;
if (pc->len) {
pc->p++;
pc->len--;
}if (pc->len) { ... }
}if (*pc->p == '{') { ... }
else {
while (1) {
if (pc->p[0] == ':' && pc->p[1] == ':') {
while (*pc->p == ':') {
pc->p++;
pc->len--;
}while (*pc->p == ':') { ... }
continue;
}if (pc->p[0] == ':' && pc->p[1] == ':') { ... }
/* ... */
if (isalnum(UCHAR(*pc->p)) || *pc->p == '_' || UCHAR(*pc->p) >= 0x80) {
pc->p++;
pc->len--;
continue;
}if (isalnum(UCHAR(*pc->p)) || *pc->p == '_' || UCHAR(*pc->p) >= 0x80) { ... }
break;
}while (1) { ... }
if (*pc->p == '(') {
int count = 1;
const char *paren = NULL;
pc->tt = JIM_TT_DICTSUGAR;
while (count && pc->len) {
pc->p++;
pc->len--;
if (*pc->p == '\\' && pc->len >= 1) {
pc->p++;
pc->len--;
}if (*pc->p == '\\' && pc->len >= 1) { ... }
else if (*pc->p == '(') {
count++;
}else if (*pc->p == '(') { ... }
else if (*pc->p == ')') {
paren = pc->p;
count--;
}else if (*pc->p == ')') { ... }
}while (count && pc->len) { ... }
if (count == 0) {
pc->p++;
pc->len--;
}if (count == 0) { ... }
else if (paren) {
paren++;
pc->len += (pc->p - paren);
pc->p = paren;
}else if (paren) { ... }
#ifndef EXPRSUGAR_BRACKET
if (*pc->tstart == '(') {
pc->tt = JIM_TT_EXPRSUGAR;
}if (*pc->tstart == '(') { ... }
/* ... */#endif
}if (*pc->p == '(') { ... }
pc->tend = pc->p - 1;
}else { ... }
/* ... */
if (pc->tstart == pc->p) {
pc->p--;
pc->len++;
return JIM_ERR;
}if (pc->tstart == pc->p) { ... }
return JIM_OK;
}{ ... }
static int JimParseStr(struct JimParserCtx *pc)
{
if (pc->tt == JIM_TT_SEP || pc->tt == JIM_TT_EOL ||
pc->tt == JIM_TT_NONE || pc->tt == JIM_TT_STR) {
if (*pc->p == '{') {
return JimParseBrace(pc);
}if (*pc->p == '{') { ... }
if (*pc->p == '"') {
pc->inquote = 1;
pc->p++;
pc->len--;
pc->missing.line = pc->tline;
}if (*pc->p == '"') { ... }
}if (pc->tt == JIM_TT_SEP || pc->tt == JIM_TT_EOL || pc->tt == JIM_TT_NONE || pc->tt == JIM_TT_STR) { ... }
pc->tstart = pc->p;
pc->tline = pc->linenr;
while (1) {
if (pc->len == 0) {
if (pc->inquote) {
pc->missing.ch = '"';
}if (pc->inquote) { ... }
pc->tend = pc->p - 1;
pc->tt = JIM_TT_ESC;
return JIM_OK;
}if (pc->len == 0) { ... }
switch (*pc->p) {
case '\\':
if (!pc->inquote && *(pc->p + 1) == '\n') {
pc->tend = pc->p - 1;
pc->tt = JIM_TT_ESC;
return JIM_OK;
}if (!pc->inquote && *(pc->p + 1) == '\n') { ... }
if (pc->len >= 2) {
if (*(pc->p + 1) == '\n') {
pc->linenr++;
}if (*(pc->p + 1) == '\n') { ... }
pc->p++;
pc->len--;
}if (pc->len >= 2) { ... }
else if (pc->len == 1) {
pc->missing.ch = '\\';
}else if (pc->len == 1) { ... }
break;case '\\':
case '(':
if (pc->len > 1 && pc->p[1] != '$') {
break;
}if (pc->len > 1 && pc->p[1] != '$') { ... }
case '(':
case ')':
if (*pc->p == '(' || pc->tt == JIM_TT_VAR) {
if (pc->p == pc->tstart) {
pc->p++;
pc->len--;
}if (pc->p == pc->tstart) { ... }
pc->tend = pc->p - 1;
pc->tt = JIM_TT_ESC;
return JIM_OK;
}if (*pc->p == '(' || pc->tt == JIM_TT_VAR) { ... }
break;
case ')':
case '$':
case '[':
pc->tend = pc->p - 1;
pc->tt = JIM_TT_ESC;
return JIM_OK;case '[':
case ' ':
case '\t':
case '\n':
case '\r':
case '\f':
case ';':
if (!pc->inquote) {
pc->tend = pc->p - 1;
pc->tt = JIM_TT_ESC;
return JIM_OK;
}if (!pc->inquote) { ... }
else if (*pc->p == '\n') {
pc->linenr++;
}else if (*pc->p == '\n') { ... }
break;case ';':
case '"':
if (pc->inquote) {
pc->tend = pc->p - 1;
pc->tt = JIM_TT_ESC;
pc->p++;
pc->len--;
pc->inquote = 0;
return JIM_OK;
}if (pc->inquote) { ... }
break;case '"':
}switch (*pc->p) { ... }
pc->p++;
pc->len--;
}while (1) { ... }
return JIM_OK;
}{ ... }
static int JimParseComment(struct JimParserCtx *pc)
{
while (*pc->p) {
if (*pc->p == '\\') {
pc->p++;
pc->len--;
if (pc->len == 0) {
pc->missing.ch = '\\';
return JIM_OK;
}if (pc->len == 0) { ... }
if (*pc->p == '\n') {
pc->linenr++;
}if (*pc->p == '\n') { ... }
}if (*pc->p == '\\') { ... }
else if (*pc->p == '\n') {
pc->p++;
pc->len--;
pc->linenr++;
break;
}else if (*pc->p == '\n') { ... }
pc->p++;
pc->len--;
}while (*pc->p) { ... }
return JIM_OK;
}{ ... }
static int xdigitval(int c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return -1;
}{ ... }
static int odigitval(int c)
{
if (c >= '0' && c <= '7')
return c - '0';
return -1;
}{ ... }
/* ... */
static int JimEscape(char *dest, const char *s, int slen)
{
char *p = dest;
int i, len;
for (i = 0; i < slen; i++) {
switch (s[i]) {
case '\\':
switch (s[i + 1]) {
case 'a':
*p++ = 0x7;
i++;
break;case 'a':
case 'b':
*p++ = 0x8;
i++;
break;case 'b':
case 'f':
*p++ = 0xc;
i++;
break;case 'f':
case 'n':
*p++ = 0xa;
i++;
break;case 'n':
case 'r':
*p++ = 0xd;
i++;
break;case 'r':
case 't':
*p++ = 0x9;
i++;
break;case 't':
case 'u':
case 'U':
case 'x':
/* ... */
{
unsigned val = 0;
int k;
int maxchars = 2;
i++;
if (s[i] == 'U') {
maxchars = 8;
}if (s[i] == 'U') { ... }
else if (s[i] == 'u') {
if (s[i + 1] == '{') {
maxchars = 6;
i++;
}if (s[i + 1] == '{') { ... }
else {
maxchars = 4;
}else { ... }
}else if (s[i] == 'u') { ... }
for (k = 0; k < maxchars; k++) {
int c = xdigitval(s[i + k + 1]);
if (c == -1) {
break;
}if (c == -1) { ... }
val = (val << 4) | c;
}for (k = 0; k < maxchars; k++) { ... }
if (s[i] == '{') {
if (k == 0 || val > 0x1fffff || s[i + k + 1] != '}') {
i--;
k = 0;
}if (k == 0 || val > 0x1fffff || s[i + k + 1] != '}') { ... }
else {
k++;
}else { ... }
}if (s[i] == '{') { ... }
if (k) {
if (s[i] == 'x') {
*p++ = val;
}if (s[i] == 'x') { ... }
else {
p += utf8_fromunicode(p, val);
}else { ... }
i += k;
break;
}if (k) { ... }
*p++ = s[i];
...}
break;case 'x':
case 'v':
*p++ = 0xb;
i++;
break;case 'v':
case '\0':
*p++ = '\\';
i++;
break;case '\0':
case '\n':
*p++ = ' ';
do {
i++;
...} while (s[i + 1] == ' ' || s[i + 1] == '\t');
break;case '\n':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
{
int val = 0;
int c = odigitval(s[i + 1]);
val = c;
c = odigitval(s[i + 2]);
if (c == -1) {
*p++ = val;
i++;
break;
}if (c == -1) { ... }
val = (val * 8) + c;
c = odigitval(s[i + 3]);
if (c == -1) {
*p++ = val;
i += 2;
break;
}if (c == -1) { ... }
val = (val * 8) + c;
*p++ = val;
i += 3;
...}
break;case '7':
default:
*p++ = s[i + 1];
i++;
break;default
}switch (s[i + 1]) { ... }
break;case '\\':
default:
*p++ = s[i];
break;default
}switch (s[i]) { ... }
}for (i = 0; i < slen; i++) { ... }
len = p - dest;
*p = '\0';
return len;
}{ ... }
/* ... */
static Jim_Obj *JimParserGetTokenObj(Jim_Interp *interp, struct JimParserCtx *pc)
{
const char *start, *end;
char *token;
int len;
start = pc->tstart;
end = pc->tend;
len = (end - start) + 1;
if (len < 0) {
len = 0;
}if (len < 0) { ... }
token = Jim_Alloc(len + 1);
if (pc->tt != JIM_TT_ESC) {
memcpy(token, start, len);
token[len] = '\0';
}if (pc->tt != JIM_TT_ESC) { ... }
else {
len = JimEscape(token, start, len);
}else { ... }
return Jim_NewStringObjNoAlloc(interp, token, len);
}{ ... }
/* ... */
static int JimParseListSep(struct JimParserCtx *pc);
static int JimParseListStr(struct JimParserCtx *pc);
static int JimParseListQuote(struct JimParserCtx *pc);
static int JimParseList(struct JimParserCtx *pc)
{
if (isspace(UCHAR(*pc->p))) {
return JimParseListSep(pc);
}if (isspace(UCHAR(*pc->p))) { ... }
switch (*pc->p) {
case '"':
return JimParseListQuote(pc);
case '"':
case '{':
return JimParseBrace(pc);
case '{':
default:
if (pc->len) {
return JimParseListStr(pc);
}if (pc->len) { ... }
break;default
}switch (*pc->p) { ... }
pc->tstart = pc->tend = pc->p;
pc->tline = pc->linenr;
pc->tt = JIM_TT_EOL;
pc->eof = 1;
return JIM_OK;
}{ ... }
static int JimParseListSep(struct JimParserCtx *pc)
{
pc->tstart = pc->p;
pc->tline = pc->linenr;
while (isspace(UCHAR(*pc->p))) {
if (*pc->p == '\n') {
pc->linenr++;
}if (*pc->p == '\n') { ... }
pc->p++;
pc->len--;
}while (isspace(UCHAR(*pc->p))) { ... }
pc->tend = pc->p - 1;
pc->tt = JIM_TT_SEP;
return JIM_OK;
}{ ... }
static int JimParseListQuote(struct JimParserCtx *pc)
{
pc->p++;
pc->len--;
pc->tstart = pc->p;
pc->tline = pc->linenr;
pc->tt = JIM_TT_STR;
while (pc->len) {
switch (*pc->p) {
case '\\':
pc->tt = JIM_TT_ESC;
if (--pc->len == 0) {
pc->tend = pc->p;
return JIM_OK;
}if (--pc->len == 0) { ... }
pc->p++;
break;case '\\':
case '\n':
pc->linenr++;
break;case '\n':
case '"':
pc->tend = pc->p - 1;
pc->p++;
pc->len--;
return JIM_OK;case '"':
}switch (*pc->p) { ... }
pc->p++;
pc->len--;
}while (pc->len) { ... }
pc->tend = pc->p - 1;
return JIM_OK;
}{ ... }
static int JimParseListStr(struct JimParserCtx *pc)
{
pc->tstart = pc->p;
pc->tline = pc->linenr;
pc->tt = JIM_TT_STR;
while (pc->len) {
if (isspace(UCHAR(*pc->p))) {
pc->tend = pc->p - 1;
return JIM_OK;
}if (isspace(UCHAR(*pc->p))) { ... }
if (*pc->p == '\\') {
if (--pc->len == 0) {
pc->tend = pc->p;
return JIM_OK;
}if (--pc->len == 0) { ... }
pc->tt = JIM_TT_ESC;
pc->p++;
}if (*pc->p == '\\') { ... }
pc->p++;
pc->len--;
}while (pc->len) { ... }
pc->tend = pc->p - 1;
return JIM_OK;
}{ ... }
/* ... */
Jim_Obj *Jim_NewObj(Jim_Interp *interp)
{
Jim_Obj *objPtr;
if (interp->freeList != NULL) {
objPtr = interp->freeList;
interp->freeList = objPtr->nextObjPtr;
}if (interp->freeList != NULL) { ... }
else {
objPtr = Jim_Alloc(sizeof(*objPtr));
}else { ... }
/* ... */
objPtr->refCount = 0;
/* ... */
objPtr->prevObjPtr = NULL;
objPtr->nextObjPtr = interp->liveList;
if (interp->liveList)
interp->liveList->prevObjPtr = objPtr;
interp->liveList = objPtr;
return objPtr;
}{ ... }
/* ... */
void Jim_FreeObj(Jim_Interp *interp, Jim_Obj *objPtr)
{
JimPanic((objPtr->refCount != 0, "!!!Object %p freed with bad refcount %d, type=%s", objPtr,
objPtr->refCount, objPtr->typePtr ? objPtr->typePtr->name : "<none>"));
Jim_FreeIntRep(interp, objPtr);
if (objPtr->bytes != NULL) {
if (objPtr->bytes != JimEmptyStringRep)
Jim_Free(objPtr->bytes);
}if (objPtr->bytes != NULL) { ... }
if (objPtr->prevObjPtr)
objPtr->prevObjPtr->nextObjPtr = objPtr->nextObjPtr;
if (objPtr->nextObjPtr)
objPtr->nextObjPtr->prevObjPtr = objPtr->prevObjPtr;
if (interp->liveList == objPtr)
interp->liveList = objPtr->nextObjPtr;
#ifdef JIM_DISABLE_OBJECT_POOL
Jim_Free(objPtr);
#else
objPtr->prevObjPtr = NULL;
objPtr->nextObjPtr = interp->freeList;
if (interp->freeList)
interp->freeList->prevObjPtr = objPtr;
interp->freeList = objPtr;
objPtr->refCount = -1;/* ... */
#endif
}{ ... }
void Jim_InvalidateStringRep(Jim_Obj *objPtr)
{
if (objPtr->bytes != NULL) {
if (objPtr->bytes != JimEmptyStringRep)
Jim_Free(objPtr->bytes);
}if (objPtr->bytes != NULL) { ... }
objPtr->bytes = NULL;
}{ ... }
Jim_Obj *Jim_DuplicateObj(Jim_Interp *interp, Jim_Obj *objPtr)
{
Jim_Obj *dupPtr;
dupPtr = Jim_NewObj(interp);
if (objPtr->bytes == NULL) {
dupPtr->bytes = NULL;
}if (objPtr->bytes == NULL) { ... }
else if (objPtr->length == 0) {
/* ... */
dupPtr->bytes = JimEmptyStringRep;
dupPtr->length = 0;
dupPtr->typePtr = NULL;
return dupPtr;
}else if (objPtr->length == 0) { ... }
else {
dupPtr->bytes = Jim_Alloc(objPtr->length + 1);
dupPtr->length = objPtr->length;
memcpy(dupPtr->bytes, objPtr->bytes, objPtr->length + 1);
}else { ... }
dupPtr->typePtr = objPtr->typePtr;
if (objPtr->typePtr != NULL) {
if (objPtr->typePtr->dupIntRepProc == NULL) {
dupPtr->internalRep = objPtr->internalRep;
}if (objPtr->typePtr->dupIntRepProc == NULL) { ... }
else {
objPtr->typePtr->dupIntRepProc(interp, objPtr, dupPtr);
}else { ... }
}if (objPtr->typePtr != NULL) { ... }
return dupPtr;
}{ ... }
/* ... */
const char *Jim_GetString(Jim_Obj *objPtr, int *lenPtr)
{
if (objPtr->bytes == NULL) {
JimPanic((objPtr->typePtr->updateStringProc == NULL, "UpdateStringProc called against '%s' type.", objPtr->typePtr->name));
objPtr->typePtr->updateStringProc(objPtr);
}if (objPtr->bytes == NULL) { ... }
if (lenPtr)
*lenPtr = objPtr->length;
return objPtr->bytes;
}{ ... }
int Jim_Length(Jim_Obj *objPtr)
{
if (objPtr->bytes == NULL) {
Jim_GetString(objPtr, NULL);
}if (objPtr->bytes == NULL) { ... }
return objPtr->length;
}{ ... }
const char *Jim_String(Jim_Obj *objPtr)
{
if (objPtr->bytes == NULL) {
Jim_GetString(objPtr, NULL);
}if (objPtr->bytes == NULL) { ... }
return objPtr->bytes;
}{ ... }
static void JimSetStringBytes(Jim_Obj *objPtr, const char *str)
{
objPtr->bytes = Jim_StrDup(str);
objPtr->length = strlen(str);
}{ ... }
static void FreeDictSubstInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupDictSubstInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static const Jim_ObjType dictSubstObjType = {
"dict-substitution",
FreeDictSubstInternalRep,
DupDictSubstInternalRep,
NULL,
JIM_TYPE_NONE,
...};
static void FreeInterpolatedInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupInterpolatedInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static const Jim_ObjType interpolatedObjType = {
"interpolated",
FreeInterpolatedInternalRep,
DupInterpolatedInternalRep,
NULL,
JIM_TYPE_NONE,
...};
static void FreeInterpolatedInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
Jim_DecrRefCount(interp, objPtr->internalRep.dictSubstValue.indexObjPtr);
}{ ... }
static void DupInterpolatedInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
dupPtr->internalRep = srcPtr->internalRep;
Jim_IncrRefCount(dupPtr->internalRep.dictSubstValue.indexObjPtr);
}{ ... }
/* ... */
static void DupStringInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static int SetStringFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
static const Jim_ObjType stringObjType = {
"string",
NULL,
DupStringInternalRep,
NULL,
JIM_TYPE_REFERENCES,
...};
static void DupStringInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
JIM_NOTUSED(interp);
/* ... */
dupPtr->internalRep.strValue.maxLength = srcPtr->length;
dupPtr->internalRep.strValue.charLength = srcPtr->internalRep.strValue.charLength;
}{ ... }
static int SetStringFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{
if (objPtr->typePtr != &stringObjType) {
if (objPtr->bytes == NULL) {
JimPanic((objPtr->typePtr->updateStringProc == NULL, "UpdateStringProc called against '%s' type.", objPtr->typePtr->name));
objPtr->typePtr->updateStringProc(objPtr);
}if (objPtr->bytes == NULL) { ... }
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &stringObjType;
objPtr->internalRep.strValue.maxLength = objPtr->length;
objPtr->internalRep.strValue.charLength = -1;
}if (objPtr->typePtr != &stringObjType) { ... }
return JIM_OK;
}{ ... }
/* ... */
int Jim_Utf8Length(Jim_Interp *interp, Jim_Obj *objPtr)
{
#ifdef JIM_UTF8
SetStringFromAny(interp, objPtr);
if (objPtr->internalRep.strValue.charLength < 0) {
objPtr->internalRep.strValue.charLength = utf8_strlen(objPtr->bytes, objPtr->length);
}if (objPtr->internalRep.strValue.charLength < 0) { ... }
return objPtr->internalRep.strValue.charLength;/* ... */
#else
return Jim_Length(objPtr);
#endif
}{ ... }
Jim_Obj *Jim_NewStringObj(Jim_Interp *interp, const char *s, int len)
{
Jim_Obj *objPtr = Jim_NewObj(interp);
if (len == -1)
len = strlen(s);
if (len == 0) {
objPtr->bytes = JimEmptyStringRep;
}if (len == 0) { ... }
else {
objPtr->bytes = Jim_StrDupLen(s, len);
}else { ... }
objPtr->length = len;
objPtr->typePtr = NULL;
return objPtr;
}{ ... }
Jim_Obj *Jim_NewStringObjUtf8(Jim_Interp *interp, const char *s, int charlen)
{
#ifdef JIM_UTF8
int bytelen = utf8_index(s, charlen);
Jim_Obj *objPtr = Jim_NewStringObj(interp, s, bytelen);
objPtr->typePtr = &stringObjType;
objPtr->internalRep.strValue.maxLength = bytelen;
objPtr->internalRep.strValue.charLength = charlen;
return objPtr;/* ... */
#else
return Jim_NewStringObj(interp, s, charlen);
#endif
}{ ... }
/* ... */
Jim_Obj *Jim_NewStringObjNoAlloc(Jim_Interp *interp, char *s, int len)
{
Jim_Obj *objPtr = Jim_NewObj(interp);
objPtr->bytes = s;
objPtr->length = (len == -1) ? strlen(s) : len;
objPtr->typePtr = NULL;
return objPtr;
}{ ... }
/* ... */
static void StringAppendString(Jim_Obj *objPtr, const char *str, int len)
{
int needlen;
if (len == -1)
len = strlen(str);
needlen = objPtr->length + len;
if (objPtr->internalRep.strValue.maxLength < needlen ||
objPtr->internalRep.strValue.maxLength == 0) {
needlen *= 2;
if (needlen < 7) {
needlen = 7;
}if (needlen < 7) { ... }
if (objPtr->bytes == JimEmptyStringRep) {
objPtr->bytes = Jim_Alloc(needlen + 1);
}if (objPtr->bytes == JimEmptyStringRep) { ... }
else {
objPtr->bytes = Jim_Realloc(objPtr->bytes, needlen + 1);
}else { ... }
objPtr->internalRep.strValue.maxLength = needlen;
}if (objPtr->internalRep.strValue.maxLength < needlen || objPtr->internalRep.strValue.maxLength == 0) { ... }
memcpy(objPtr->bytes + objPtr->length, str, len);
objPtr->bytes[objPtr->length + len] = '\0';
if (objPtr->internalRep.strValue.charLength >= 0) {
objPtr->internalRep.strValue.charLength += utf8_strlen(objPtr->bytes + objPtr->length, len);
}if (objPtr->internalRep.strValue.charLength >= 0) { ... }
objPtr->length += len;
}{ ... }
/* ... */
void Jim_AppendString(Jim_Interp *interp, Jim_Obj *objPtr, const char *str, int len)
{
JimPanic((Jim_IsShared(objPtr), "Jim_AppendString called with shared object"));
SetStringFromAny(interp, objPtr);
StringAppendString(objPtr, str, len);
}{ ... }
void Jim_AppendObj(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *appendObjPtr)
{
int len;
const char *str = Jim_GetString(appendObjPtr, &len);
Jim_AppendString(interp, objPtr, str, len);
}{ ... }
void Jim_AppendStrings(Jim_Interp *interp, Jim_Obj *objPtr, ...)
{
va_list ap;
SetStringFromAny(interp, objPtr);
va_start(ap, objPtr);
while (1) {
const char *s = va_arg(ap, const char *);
if (s == NULL)
break;
Jim_AppendString(interp, objPtr, s, -1);
}while (1) { ... }
va_end(ap);
}{ ... }
int Jim_StringEqObj(Jim_Obj *aObjPtr, Jim_Obj *bObjPtr)
{
if (aObjPtr == bObjPtr) {
return 1;
}if (aObjPtr == bObjPtr) { ... }
else {
int Alen, Blen;
const char *sA = Jim_GetString(aObjPtr, &Alen);
const char *sB = Jim_GetString(bObjPtr, &Blen);
return Alen == Blen && memcmp(sA, sB, Alen) == 0;
}else { ... }
}{ ... }
/* ... */
int Jim_StringMatchObj(Jim_Interp *interp, Jim_Obj *patternObjPtr, Jim_Obj *objPtr, int nocase)
{
int plen, slen;
const char *pattern = Jim_GetString(patternObjPtr, &plen);
const char *string = Jim_GetString(objPtr, &slen);
return JimGlobMatch(pattern, plen, string, slen, nocase);
}{ ... }
int Jim_StringCompareObj(Jim_Interp *interp, Jim_Obj *firstObjPtr, Jim_Obj *secondObjPtr, int nocase)
{
const char *s1 = Jim_String(firstObjPtr);
int l1 = Jim_Utf8Length(interp, firstObjPtr);
const char *s2 = Jim_String(secondObjPtr);
int l2 = Jim_Utf8Length(interp, secondObjPtr);
return JimStringCompareUtf8(s1, l1, s2, l2, nocase);
}{ ... }
/* ... */
static int JimRelToAbsIndex(int len, int idx)
{
if (idx < 0 && idx > -INT_MAX)
return len + idx;
return idx;
}{ ... }
/* ... */
static void JimRelToAbsRange(int len, int *firstPtr, int *lastPtr, int *rangeLenPtr)
{
int rangeLen;
if (*firstPtr > *lastPtr) {
rangeLen = 0;
}if (*firstPtr > *lastPtr) { ... }
else {
rangeLen = *lastPtr - *firstPtr + 1;
if (rangeLen) {
if (*firstPtr < 0) {
rangeLen += *firstPtr;
*firstPtr = 0;
}if (*firstPtr < 0) { ... }
if (*lastPtr >= len) {
rangeLen -= (*lastPtr - (len - 1));
*lastPtr = len - 1;
}if (*lastPtr >= len) { ... }
}if (rangeLen) { ... }
}else { ... }
if (rangeLen < 0)
rangeLen = 0;
*rangeLenPtr = rangeLen;
}{ ... }
static int JimStringGetRange(Jim_Interp *interp, Jim_Obj *firstObjPtr, Jim_Obj *lastObjPtr,
int len, int *first, int *last, int *range)
{
if (Jim_GetIndex(interp, firstObjPtr, first) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetIndex(interp, firstObjPtr, first) != JIM_OK) { ... }
if (Jim_GetIndex(interp, lastObjPtr, last) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetIndex(interp, lastObjPtr, last) != JIM_OK) { ... }
*first = JimRelToAbsIndex(len, *first);
*last = JimRelToAbsIndex(len, *last);
JimRelToAbsRange(len, first, last, range);
return JIM_OK;
}{ ... }
Jim_Obj *Jim_StringByteRangeObj(Jim_Interp *interp,
Jim_Obj *strObjPtr, Jim_Obj *firstObjPtr, Jim_Obj *lastObjPtr)
{
int first, last;
const char *str;
int rangeLen;
int bytelen;
str = Jim_GetString(strObjPtr, &bytelen);
if (JimStringGetRange(interp, firstObjPtr, lastObjPtr, bytelen, &first, &last, &rangeLen) != JIM_OK) {
return NULL;
}if (JimStringGetRange(interp, firstObjPtr, lastObjPtr, bytelen, &first, &last, &rangeLen) != JIM_OK) { ... }
if (first == 0 && rangeLen == bytelen) {
return strObjPtr;
}if (first == 0 && rangeLen == bytelen) { ... }
return Jim_NewStringObj(interp, str + first, rangeLen);
}{ ... }
Jim_Obj *Jim_StringRangeObj(Jim_Interp *interp,
Jim_Obj *strObjPtr, Jim_Obj *firstObjPtr, Jim_Obj *lastObjPtr)
{
#ifdef JIM_UTF8
int first, last;
const char *str;
int len, rangeLen;
int bytelen;
str = Jim_GetString(strObjPtr, &bytelen);
len = Jim_Utf8Length(interp, strObjPtr);
if (JimStringGetRange(interp, firstObjPtr, lastObjPtr, len, &first, &last, &rangeLen) != JIM_OK) {
return NULL;
}if (JimStringGetRange(interp, firstObjPtr, lastObjPtr, len, &first, &last, &rangeLen) != JIM_OK) { ... }
if (first == 0 && rangeLen == len) {
return strObjPtr;
}if (first == 0 && rangeLen == len) { ... }
if (len == bytelen) {
return Jim_NewStringObj(interp, str + first, rangeLen);
}if (len == bytelen) { ... }
return Jim_NewStringObjUtf8(interp, str + utf8_index(str, first), rangeLen);/* ... */
#else
return Jim_StringByteRangeObj(interp, strObjPtr, firstObjPtr, lastObjPtr);
#endif
}{ ... }
Jim_Obj *JimStringReplaceObj(Jim_Interp *interp,
Jim_Obj *strObjPtr, Jim_Obj *firstObjPtr, Jim_Obj *lastObjPtr, Jim_Obj *newStrObj)
{
int first, last;
const char *str;
int len, rangeLen;
Jim_Obj *objPtr;
len = Jim_Utf8Length(interp, strObjPtr);
if (JimStringGetRange(interp, firstObjPtr, lastObjPtr, len, &first, &last, &rangeLen) != JIM_OK) {
return NULL;
}if (JimStringGetRange(interp, firstObjPtr, lastObjPtr, len, &first, &last, &rangeLen) != JIM_OK) { ... }
if (last < first) {
return strObjPtr;
}if (last < first) { ... }
str = Jim_String(strObjPtr);
objPtr = Jim_NewStringObjUtf8(interp, str, first);
if (newStrObj) {
Jim_AppendObj(interp, objPtr, newStrObj);
}if (newStrObj) { ... }
Jim_AppendString(interp, objPtr, str + utf8_index(str, last + 1), len - last - 1);
return objPtr;
}{ ... }
/* ... */
static void JimStrCopyUpperLower(char *dest, const char *str, int uc)
{
while (*str) {
int c;
str += utf8_tounicode(str, &c);
dest += utf8_getchars(dest, uc ? utf8_upper(c) : utf8_lower(c));
}while (*str) { ... }
*dest = 0;
}{ ... }
/* ... */
static Jim_Obj *JimStringToLower(Jim_Interp *interp, Jim_Obj *strObjPtr)
{
char *buf;
int len;
const char *str;
str = Jim_GetString(strObjPtr, &len);
#ifdef JIM_UTF8
/* ... */
len *= 2;/* ... */
#endif
buf = Jim_Alloc(len + 1);
JimStrCopyUpperLower(buf, str, 0);
return Jim_NewStringObjNoAlloc(interp, buf, -1);
}{ ... }
/* ... */
static Jim_Obj *JimStringToUpper(Jim_Interp *interp, Jim_Obj *strObjPtr)
{
char *buf;
const char *str;
int len;
str = Jim_GetString(strObjPtr, &len);
#ifdef JIM_UTF8
/* ... */
len *= 2;/* ... */
#endif
buf = Jim_Alloc(len + 1);
JimStrCopyUpperLower(buf, str, 1);
return Jim_NewStringObjNoAlloc(interp, buf, -1);
}{ ... }
/* ... */
static Jim_Obj *JimStringToTitle(Jim_Interp *interp, Jim_Obj *strObjPtr)
{
char *buf, *p;
int len;
int c;
const char *str;
str = Jim_GetString(strObjPtr, &len);
#ifdef JIM_UTF8
/* ... */
len *= 2;/* ... */
#endif
buf = p = Jim_Alloc(len + 1);
str += utf8_tounicode(str, &c);
p += utf8_getchars(p, utf8_title(c));
JimStrCopyUpperLower(p, str, 0);
return Jim_NewStringObjNoAlloc(interp, buf, -1);
}{ ... }
/* ... */
static const char *utf8_memchr(const char *str, int len, int c)
{
#ifdef JIM_UTF8
while (len) {
int sc;
int n = utf8_tounicode(str, &sc);
if (sc == c) {
return str;
}if (sc == c) { ... }
str += n;
len -= n;
}while (len) { ... }
return NULL;/* ... */
#else
return memchr(str, c, len);
#endif
}{ ... }
/* ... */
static const char *JimFindTrimLeft(const char *str, int len, const char *trimchars, int trimlen)
{
while (len) {
int c;
int n = utf8_tounicode(str, &c);
if (utf8_memchr(trimchars, trimlen, c) == NULL) {
break;
}if (utf8_memchr(trimchars, trimlen, c) == NULL) { ... }
str += n;
len -= n;
}while (len) { ... }
return str;
}{ ... }
/* ... */
static const char *JimFindTrimRight(const char *str, int len, const char *trimchars, int trimlen)
{
str += len;
while (len) {
int c;
int n = utf8_prev_len(str, len);
len -= n;
str -= n;
n = utf8_tounicode(str, &c);
if (utf8_memchr(trimchars, trimlen, c) == NULL) {
return str + n;
}if (utf8_memchr(trimchars, trimlen, c) == NULL) { ... }
}while (len) { ... }
return NULL;
}{ ... }
static const char default_trim_chars[] = " \t\n\r";
static int default_trim_chars_len = sizeof(default_trim_chars);
static Jim_Obj *JimStringTrimLeft(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *trimcharsObjPtr)
{
int len;
const char *str = Jim_GetString(strObjPtr, &len);
const char *trimchars = default_trim_chars;
int trimcharslen = default_trim_chars_len;
const char *newstr;
if (trimcharsObjPtr) {
trimchars = Jim_GetString(trimcharsObjPtr, &trimcharslen);
}if (trimcharsObjPtr) { ... }
newstr = JimFindTrimLeft(str, len, trimchars, trimcharslen);
if (newstr == str) {
return strObjPtr;
}if (newstr == str) { ... }
return Jim_NewStringObj(interp, newstr, len - (newstr - str));
}{ ... }
static Jim_Obj *JimStringTrimRight(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *trimcharsObjPtr)
{
int len;
const char *trimchars = default_trim_chars;
int trimcharslen = default_trim_chars_len;
const char *nontrim;
if (trimcharsObjPtr) {
trimchars = Jim_GetString(trimcharsObjPtr, &trimcharslen);
}if (trimcharsObjPtr) { ... }
SetStringFromAny(interp, strObjPtr);
len = Jim_Length(strObjPtr);
nontrim = JimFindTrimRight(strObjPtr->bytes, len, trimchars, trimcharslen);
if (nontrim == NULL) {
return Jim_NewEmptyStringObj(interp);
}if (nontrim == NULL) { ... }
if (nontrim == strObjPtr->bytes + len) {
return strObjPtr;
}if (nontrim == strObjPtr->bytes + len) { ... }
if (Jim_IsShared(strObjPtr)) {
strObjPtr = Jim_NewStringObj(interp, strObjPtr->bytes, (nontrim - strObjPtr->bytes));
}if (Jim_IsShared(strObjPtr)) { ... }
else {
strObjPtr->bytes[nontrim - strObjPtr->bytes] = 0;
strObjPtr->length = (nontrim - strObjPtr->bytes);
}else { ... }
return strObjPtr;
}{ ... }
static Jim_Obj *JimStringTrim(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *trimcharsObjPtr)
{
Jim_Obj *objPtr = JimStringTrimLeft(interp, strObjPtr, trimcharsObjPtr);
strObjPtr = JimStringTrimRight(interp, objPtr, trimcharsObjPtr);
if (objPtr != strObjPtr && objPtr->refCount == 0) {
Jim_FreeNewObj(interp, objPtr);
}if (objPtr != strObjPtr && objPtr->refCount == 0) { ... }
return strObjPtr;
}{ ... }
#ifdef HAVE_ISASCII
#define jim_isascii isascii
#else
static int jim_isascii(int c)
{
return !(c & ~0x7f);
}jim_isascii (int c) { ... }
/* ... */#endif
static int JimStringIs(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *strClass, int strict)
{
static const char * const strclassnames[] = {
"integer", "alpha", "alnum", "ascii", "digit",
"double", "lower", "upper", "space", "xdigit",
"control", "print", "graph", "punct", "boolean",
NULL
...};
enum {
STR_IS_INTEGER, STR_IS_ALPHA, STR_IS_ALNUM, STR_IS_ASCII, STR_IS_DIGIT,
STR_IS_DOUBLE, STR_IS_LOWER, STR_IS_UPPER, STR_IS_SPACE, STR_IS_XDIGIT,
STR_IS_CONTROL, STR_IS_PRINT, STR_IS_GRAPH, STR_IS_PUNCT, STR_IS_BOOLEAN,
...};
int strclass;
int len;
int i;
const char *str;
int (*isclassfunc)(int c) = NULL;
if (Jim_GetEnum(interp, strClass, strclassnames, &strclass, "class", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetEnum(interp, strClass, strclassnames, &strclass, "class", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) { ... }
str = Jim_GetString(strObjPtr, &len);
if (len == 0) {
Jim_SetResultBool(interp, !strict);
return JIM_OK;
}if (len == 0) { ... }
switch (strclass) {
case STR_IS_INTEGER:
{
jim_wide w;
Jim_SetResultBool(interp, JimGetWideNoErr(interp, strObjPtr, &w) == JIM_OK);
return JIM_OK;
...}
case STR_IS_INTEGER:
case STR_IS_DOUBLE:
{
double d;
Jim_SetResultBool(interp, Jim_GetDouble(interp, strObjPtr, &d) == JIM_OK && errno != ERANGE);
return JIM_OK;
...}
case STR_IS_DOUBLE:
case STR_IS_BOOLEAN:
{
int b;
Jim_SetResultBool(interp, Jim_GetBoolean(interp, strObjPtr, &b) == JIM_OK);
return JIM_OK;
...}
case STR_IS_BOOLEAN:
case STR_IS_ALPHA: isclassfunc = isalpha; break;
case STR_IS_ALNUM: isclassfunc = isalnum; break;
case STR_IS_ASCII: isclassfunc = jim_isascii; break;
case STR_IS_DIGIT: isclassfunc = isdigit; break;
case STR_IS_LOWER: isclassfunc = islower; break;
case STR_IS_UPPER: isclassfunc = isupper; break;
case STR_IS_SPACE: isclassfunc = isspace; break;
case STR_IS_XDIGIT: isclassfunc = isxdigit; break;
case STR_IS_CONTROL: isclassfunc = iscntrl; break;
case STR_IS_PRINT: isclassfunc = isprint; break;
case STR_IS_GRAPH: isclassfunc = isgraph; break;
case STR_IS_PUNCT: isclassfunc = ispunct; break;
default:
return JIM_ERR;default
}switch (strclass) { ... }
for (i = 0; i < len; i++) {
if (!isclassfunc(UCHAR(str[i]))) {
Jim_SetResultBool(interp, 0);
return JIM_OK;
}if (!isclassfunc(UCHAR(str[i]))) { ... }
}for (i = 0; i < len; i++) { ... }
Jim_SetResultBool(interp, 1);
return JIM_OK;
}{ ... }
/* ... */
/* ... */
static const Jim_ObjType comparedStringObjType = {
"compared-string",
NULL,
NULL,
NULL,
JIM_TYPE_REFERENCES,
...};
/* ... */
int Jim_CompareStringImmediate(Jim_Interp *interp, Jim_Obj *objPtr, const char *str)
{
if (objPtr->typePtr == &comparedStringObjType && objPtr->internalRep.ptr == str) {
return 1;
}if (objPtr->typePtr == &comparedStringObjType && objPtr->internalRep.ptr == str) { ... }
else {
if (strcmp(str, Jim_String(objPtr)) != 0)
return 0;
if (objPtr->typePtr != &comparedStringObjType) {
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &comparedStringObjType;
}if (objPtr->typePtr != &comparedStringObjType) { ... }
objPtr->internalRep.ptr = (char *)str;
return 1;
}else { ... }
}{ ... }
static int qsortCompareStringPointers(const void *a, const void *b)
{
char *const *sa = (char *const *)a;
char *const *sb = (char *const *)b;
return strcmp(*sa, *sb);
}{ ... }
/* ... */
static void FreeSourceInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupSourceInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static const Jim_ObjType sourceObjType = {
"source",
FreeSourceInternalRep,
DupSourceInternalRep,
NULL,
JIM_TYPE_REFERENCES,
...};
void FreeSourceInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
Jim_DecrRefCount(interp, objPtr->internalRep.sourceValue.fileNameObj);
}{ ... }
void DupSourceInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
dupPtr->internalRep.sourceValue = srcPtr->internalRep.sourceValue;
Jim_IncrRefCount(dupPtr->internalRep.sourceValue.fileNameObj);
}{ ... }
static void JimSetSourceInfo(Jim_Interp *interp, Jim_Obj *objPtr,
Jim_Obj *fileNameObj, int lineNumber)
{
JimPanic((Jim_IsShared(objPtr), "JimSetSourceInfo called with shared object"));
JimPanic((objPtr->typePtr != NULL, "JimSetSourceInfo called with typed object"));
Jim_IncrRefCount(fileNameObj);
objPtr->internalRep.sourceValue.fileNameObj = fileNameObj;
objPtr->internalRep.sourceValue.lineNumber = lineNumber;
objPtr->typePtr = &sourceObjType;
}{ ... }
/* ... */
static const Jim_ObjType scriptLineObjType = {
"scriptline",
NULL,
NULL,
NULL,
JIM_NONE,
...};
static Jim_Obj *JimNewScriptLineObj(Jim_Interp *interp, int argc, int line)
{
Jim_Obj *objPtr;
#ifdef DEBUG_SHOW_SCRIPT
char buf[100];
snprintf(buf, sizeof(buf), "line=%d, argc=%d", line, argc);
objPtr = Jim_NewStringObj(interp, buf, -1);/* ... */
#else
objPtr = Jim_NewEmptyStringObj(interp);
#endif
objPtr->typePtr = &scriptLineObjType;
objPtr->internalRep.scriptLineValue.argc = argc;
objPtr->internalRep.scriptLineValue.line = line;
return objPtr;
}{ ... }
/* ... */
static void FreeScriptInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupScriptInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static const Jim_ObjType scriptObjType = {
"script",
FreeScriptInternalRep,
DupScriptInternalRep,
NULL,
JIM_TYPE_NONE,
...};
/* ... */
typedef struct ScriptToken
{
Jim_Obj *objPtr;
int type;
...} ScriptToken;
/* ... */
typedef struct ScriptObj
{
ScriptToken *token;
Jim_Obj *fileNameObj;
int len;
int substFlags;
int inUse;
/* ... */
int firstline;
int linenr;
int missing;
...} ScriptObj;
static void JimSetScriptFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
static int JimParseCheckMissing(Jim_Interp *interp, int ch);
static ScriptObj *JimGetScript(Jim_Interp *interp, Jim_Obj *objPtr);
void FreeScriptInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
int i;
struct ScriptObj *script = (void *)objPtr->internalRep.ptr;
if (--script->inUse != 0)
return;
for (i = 0; i < script->len; i++) {
Jim_DecrRefCount(interp, script->token[i].objPtr);
}for (i = 0; i < script->len; i++) { ... }
Jim_Free(script->token);
Jim_DecrRefCount(interp, script->fileNameObj);
Jim_Free(script);
}{ ... }
void DupScriptInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
JIM_NOTUSED(interp);
JIM_NOTUSED(srcPtr);
/* ... */
dupPtr->typePtr = NULL;
}{ ... }
/* ... */
typedef struct
{
const char *token;
int len;
int type;
int line;
...} ParseToken;
/* ... */
typedef struct
{
ParseToken *list;
int size;
int count;
ParseToken static_list[20];
...} ParseTokenList;
static void ScriptTokenListInit(ParseTokenList *tokenlist)
{
tokenlist->list = tokenlist->static_list;
tokenlist->size = sizeof(tokenlist->static_list) / sizeof(ParseToken);
tokenlist->count = 0;
}{ ... }
static void ScriptTokenListFree(ParseTokenList *tokenlist)
{
if (tokenlist->list != tokenlist->static_list) {
Jim_Free(tokenlist->list);
}if (tokenlist->list != tokenlist->static_list) { ... }
}{ ... }
/* ... */
static void ScriptAddToken(ParseTokenList *tokenlist, const char *token, int len, int type,
int line)
{
ParseToken *t;
if (tokenlist->count == tokenlist->size) {
tokenlist->size *= 2;
if (tokenlist->list != tokenlist->static_list) {
tokenlist->list =
Jim_Realloc(tokenlist->list, tokenlist->size * sizeof(*tokenlist->list));
}if (tokenlist->list != tokenlist->static_list) { ... }
else {
tokenlist->list = Jim_Alloc(tokenlist->size * sizeof(*tokenlist->list));
memcpy(tokenlist->list, tokenlist->static_list,
tokenlist->count * sizeof(*tokenlist->list));
}else { ... }
}if (tokenlist->count == tokenlist->size) { ... }
t = &tokenlist->list[tokenlist->count++];
t->token = token;
t->len = len;
t->type = type;
t->line = line;
}{ ... }
/* ... */
static int JimCountWordTokens(struct ScriptObj *script, ParseToken *t)
{
int expand = 1;
int count = 0;
if (t->type == JIM_TT_STR && !TOKEN_IS_SEP(t[1].type)) {
if ((t->len == 1 && *t->token == '*') || (t->len == 6 && strncmp(t->token, "expand", 6) == 0)) {
expand = -1;
t++;
}if ((t->len == 1 && *t->token == '*') || (t->len == 6 && strncmp(t->token, "expand", 6) == 0)) { ... }
else {
if (script->missing == ' ') {
script->missing = '}';
script->linenr = t[1].line;
}if (script->missing == ' ') { ... }
}else { ... }
}if (t->type == JIM_TT_STR && !TOKEN_IS_SEP(t[1].type)) { ... }
while (!TOKEN_IS_SEP(t->type)) {
t++;
count++;
}while (!TOKEN_IS_SEP(t->type)) { ... }
return count * expand;
}{ ... }
/* ... */
static Jim_Obj *JimMakeScriptObj(Jim_Interp *interp, const ParseToken *t)
{
Jim_Obj *objPtr;
if (t->type == JIM_TT_ESC && memchr(t->token, '\\', t->len) != NULL) {
int len = t->len;
char *str = Jim_Alloc(len + 1);
len = JimEscape(str, t->token, len);
objPtr = Jim_NewStringObjNoAlloc(interp, str, len);
}if (t->type == JIM_TT_ESC && memchr(t->token, '\\', t->len) != NULL) { ... }
else {
/* ... */
objPtr = Jim_NewStringObj(interp, t->token, t->len);
}else { ... }
return objPtr;
}{ ... }
/* ... */
static void ScriptObjAddTokens(Jim_Interp *interp, struct ScriptObj *script,
ParseTokenList *tokenlist)
{
int i;
struct ScriptToken *token;
int lineargs = 0;
ScriptToken *linefirst;
int count;
int linenr;
#ifdef DEBUG_SHOW_SCRIPT_TOKENS
printf("==== Tokens ====\n");
for (i = 0; i < tokenlist->count; i++) {
printf("[%2d]@%d %s '%.*s'\n", i, tokenlist->list[i].line, jim_tt_name(tokenlist->list[i].type),
tokenlist->list[i].len, tokenlist->list[i].token);
}for (i = 0; i < tokenlist->count; i++) { ... }
/* ... */#endif
count = tokenlist->count;
for (i = 0; i < tokenlist->count; i++) {
if (tokenlist->list[i].type == JIM_TT_EOL) {
count++;
}if (tokenlist->list[i].type == JIM_TT_EOL) { ... }
}for (i = 0; i < tokenlist->count; i++) { ... }
linenr = script->firstline = tokenlist->list[0].line;
token = script->token = Jim_Alloc(sizeof(ScriptToken) * count);
linefirst = token++;
for (i = 0; i < tokenlist->count; ) {
int wordtokens;
while (tokenlist->list[i].type == JIM_TT_SEP) {
i++;
}while (tokenlist->list[i].type == JIM_TT_SEP) { ... }
wordtokens = JimCountWordTokens(script, tokenlist->list + i);
if (wordtokens == 0) {
if (lineargs) {
linefirst->type = JIM_TT_LINE;
linefirst->objPtr = JimNewScriptLineObj(interp, lineargs, linenr);
Jim_IncrRefCount(linefirst->objPtr);
lineargs = 0;
linefirst = token++;
}if (lineargs) { ... }
i++;
continue;
}if (wordtokens == 0) { ... }
else if (wordtokens != 1) {
token->type = JIM_TT_WORD;
token->objPtr = Jim_NewIntObj(interp, wordtokens);
Jim_IncrRefCount(token->objPtr);
token++;
if (wordtokens < 0) {
i++;
wordtokens = -wordtokens - 1;
lineargs--;
}if (wordtokens < 0) { ... }
}else if (wordtokens != 1) { ... }
if (lineargs == 0) {
linenr = tokenlist->list[i].line;
}if (lineargs == 0) { ... }
lineargs++;
while (wordtokens--) {
const ParseToken *t = &tokenlist->list[i++];
token->type = t->type;
token->objPtr = JimMakeScriptObj(interp, t);
Jim_IncrRefCount(token->objPtr);
/* ... */
JimSetSourceInfo(interp, token->objPtr, script->fileNameObj, t->line);
token++;
}while (wordtokens--) { ... }
}for (i = 0; i < tokenlist->count;) { ... }
if (lineargs == 0) {
token--;
}if (lineargs == 0) { ... }
script->len = token - script->token;
JimPanic((script->len >= count, "allocated script array is too short"));
#ifdef DEBUG_SHOW_SCRIPT
printf("==== Script (%s) ====\n", Jim_String(script->fileNameObj));
for (i = 0; i < script->len; i++) {
const ScriptToken *t = &script->token[i];
printf("[%2d] %s %s\n", i, jim_tt_name(t->type), Jim_String(t->objPtr));
}for (i = 0; i < script->len; i++) { ... }
/* ... */#endif
}{ ... }
/* ... */
int Jim_ScriptIsComplete(Jim_Interp *interp, Jim_Obj *scriptObj, char *stateCharPtr)
{
ScriptObj *script = JimGetScript(interp, scriptObj);
if (stateCharPtr) {
*stateCharPtr = script->missing;
}if (stateCharPtr) { ... }
return script->missing == ' ' || script->missing == '}';
}{ ... }
/* ... */
static int JimParseCheckMissing(Jim_Interp *interp, int ch)
{
const char *msg;
switch (ch) {
case '\\':
case ' ':
return JIM_OK;
case ' ':
case '[':
msg = "unmatched \"[\"";
break;case '[':
case '{':
msg = "missing close-brace";
break;case '{':
case '}':
msg = "extra characters after close-brace";
break;case '}':
case '"':
default:
msg = "missing quote";
break;default
}switch (ch) { ... }
Jim_SetResultString(interp, msg, -1);
return JIM_ERR;
}{ ... }
/* ... */
static void SubstObjAddTokens(Jim_Interp *interp, struct ScriptObj *script,
ParseTokenList *tokenlist)
{
int i;
struct ScriptToken *token;
token = script->token = Jim_Alloc(sizeof(ScriptToken) * tokenlist->count);
for (i = 0; i < tokenlist->count; i++) {
const ParseToken *t = &tokenlist->list[i];
token->type = t->type;
token->objPtr = JimMakeScriptObj(interp, t);
Jim_IncrRefCount(token->objPtr);
token++;
}for (i = 0; i < tokenlist->count; i++) { ... }
script->len = i;
}{ ... }
/* ... */
static void JimSetScriptFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
{
int scriptTextLen;
const char *scriptText = Jim_GetString(objPtr, &scriptTextLen);
struct JimParserCtx parser;
struct ScriptObj *script;
ParseTokenList tokenlist;
int line = 1;
if (objPtr->typePtr == &sourceObjType) {
line = objPtr->internalRep.sourceValue.lineNumber;
}if (objPtr->typePtr == &sourceObjType) { ... }
ScriptTokenListInit(&tokenlist);
JimParserInit(&parser, scriptText, scriptTextLen, line);
while (!parser.eof) {
JimParseScript(&parser);
ScriptAddToken(&tokenlist, parser.tstart, parser.tend - parser.tstart + 1, parser.tt,
parser.tline);
}while (!parser.eof) { ... }
ScriptAddToken(&tokenlist, scriptText + scriptTextLen, 0, JIM_TT_EOF, 0);
script = Jim_Alloc(sizeof(*script));
memset(script, 0, sizeof(*script));
script->inUse = 1;
if (objPtr->typePtr == &sourceObjType) {
script->fileNameObj = objPtr->internalRep.sourceValue.fileNameObj;
}if (objPtr->typePtr == &sourceObjType) { ... }
else {
script->fileNameObj = interp->emptyObj;
}else { ... }
Jim_IncrRefCount(script->fileNameObj);
script->missing = parser.missing.ch;
script->linenr = parser.missing.line;
ScriptObjAddTokens(interp, script, &tokenlist);
ScriptTokenListFree(&tokenlist);
Jim_FreeIntRep(interp, objPtr);
Jim_SetIntRepPtr(objPtr, script);
objPtr->typePtr = &scriptObjType;
}{ ... }
static void JimAddErrorToStack(Jim_Interp *interp, ScriptObj *script);
/* ... */
static ScriptObj *JimGetScript(Jim_Interp *interp, Jim_Obj *objPtr)
{
if (objPtr == interp->emptyObj) {
objPtr = interp->nullScriptObj;
}if (objPtr == interp->emptyObj) { ... }
if (objPtr->typePtr != &scriptObjType || ((struct ScriptObj *)Jim_GetIntRepPtr(objPtr))->substFlags) {
JimSetScriptFromAny(interp, objPtr);
}if (objPtr->typePtr != &scriptObjType || ((struct ScriptObj *)Jim_GetIntRepPtr(objPtr))->substFlags) { ... }
return (ScriptObj *)Jim_GetIntRepPtr(objPtr);
}{ ... }
/* ... */
static int JimScriptValid(Jim_Interp *interp, ScriptObj *script)
{
if (JimParseCheckMissing(interp, script->missing) == JIM_ERR) {
JimAddErrorToStack(interp, script);
return 0;
}if (JimParseCheckMissing(interp, script->missing) == JIM_ERR) { ... }
return 1;
}{ ... }
/* ... */
void Jim_InterpIncrProcEpoch(Jim_Interp *interp)
{
interp->procEpoch++;
while (interp->oldCmdCache) {
Jim_Cmd *next = interp->oldCmdCache->prevCmd;
Jim_Free(interp->oldCmdCache);
interp->oldCmdCache = next;
}while (interp->oldCmdCache) { ... }
interp->oldCmdCacheSize = 0;
}{ ... }
static void JimIncrCmdRefCount(Jim_Cmd *cmdPtr)
{
cmdPtr->inUse++;
}{ ... }
static void JimDecrCmdRefCount(Jim_Interp *interp, Jim_Cmd *cmdPtr)
{
if (--cmdPtr->inUse == 0) {
if (cmdPtr->isproc) {
Jim_DecrRefCount(interp, cmdPtr->u.proc.argListObjPtr);
Jim_DecrRefCount(interp, cmdPtr->u.proc.bodyObjPtr);
Jim_DecrRefCount(interp, cmdPtr->u.proc.nsObj);
if (cmdPtr->u.proc.staticVars) {
Jim_FreeHashTable(cmdPtr->u.proc.staticVars);
Jim_Free(cmdPtr->u.proc.staticVars);
}if (cmdPtr->u.proc.staticVars) { ... }
}if (cmdPtr->isproc) { ... }
else {
if (cmdPtr->u.native.delProc) {
cmdPtr->u.native.delProc(interp, cmdPtr->u.native.privData);
}if (cmdPtr->u.native.delProc) { ... }
}else { ... }
if (cmdPtr->prevCmd) {
JimDecrCmdRefCount(interp, cmdPtr->prevCmd);
}if (cmdPtr->prevCmd) { ... }
if (interp->quitting) {
Jim_Free(cmdPtr);
}if (interp->quitting) { ... }
else {
/* ... */
cmdPtr->prevCmd = interp->oldCmdCache;
interp->oldCmdCache = cmdPtr;
if (++interp->oldCmdCacheSize >= 1000) {
Jim_InterpIncrProcEpoch(interp);
}if (++interp->oldCmdCacheSize >= 1000) { ... }
}else { ... }
}if (--cmdPtr->inUse == 0) { ... }
}{ ... }
/* ... */
static void JimVariablesHTValDestructor(void *interp, void *val)
{
Jim_DecrRefCount(interp, ((Jim_Var *)val)->objPtr);
Jim_Free(val);
}{ ... }
static unsigned int JimObjectHTHashFunction(const void *key)
{
Jim_Obj *keyObj = (Jim_Obj *)key;
int length;
const char *string;
#ifdef JIM_OPTIMIZATION
if (JimIsWide(keyObj) && keyObj->bytes == NULL) {
jim_wide objValue = JimWideValue(keyObj);
if (objValue > INT_MIN && objValue < INT_MAX) {
unsigned result = 0;
unsigned value = (unsigned)objValue;
if (objValue < 0) {
value = (unsigned)-objValue;
}if (objValue < 0) { ... }
do {
result += (result << 3) + (value % 10 + '0');
value /= 10;
...} while (value);
if (objValue < 0) {
result += (result << 3) + '-';
}if (objValue < 0) { ... }
return result;
}if (objValue > INT_MIN && objValue < INT_MAX) { ... }
}if (JimIsWide(keyObj) && keyObj->bytes == NULL) { ... }
/* ... */#endif
string = Jim_GetString(keyObj, &length);
return Jim_GenHashFunction((const unsigned char *)string, length);
}{ ... }
static int JimObjectHTKeyCompare(void *privdata, const void *key1, const void *key2)
{
return Jim_StringEqObj((Jim_Obj *)key1, (Jim_Obj *)key2);
}{ ... }
static void *JimObjectHTKeyValDup(void *privdata, const void *val)
{
Jim_IncrRefCount((Jim_Obj *)val);
return (void *)val;
}{ ... }
static void JimObjectHTKeyValDestructor(void *interp, void *val)
{
Jim_DecrRefCount(interp, (Jim_Obj *)val);
}{ ... }
static const Jim_HashTableType JimVariablesHashTableType = {
JimObjectHTHashFunction,
JimObjectHTKeyValDup,
NULL,
JimObjectHTKeyCompare,
JimObjectHTKeyValDestructor,
JimVariablesHTValDestructor
...};
/* ... */
/* ... */
static const char *Jim_GetStringNoQualifier(Jim_Obj *objPtr, int *length)
{
int len;
const char *str = Jim_GetString(objPtr, &len);
if (len >= 2 && str[0] == ':' && str[1] == ':') {
while (len && *str == ':') {
len--;
str++;
}while (len && *str == ':') { ... }
}if (len >= 2 && str[0] == ':' && str[1] == ':') { ... }
*length = len;
return str;
}{ ... }
static unsigned int JimCommandsHT_HashFunction(const void *key)
{
int len;
const char *str = Jim_GetStringNoQualifier((Jim_Obj *)key, &len);
return Jim_GenHashFunction((const unsigned char *)str, len);
}{ ... }
static int JimCommandsHT_KeyCompare(void *privdata, const void *key1, const void *key2)
{
int len1, len2;
const char *str1 = Jim_GetStringNoQualifier((Jim_Obj *)key1, &len1);
const char *str2 = Jim_GetStringNoQualifier((Jim_Obj *)key2, &len2);
return len1 == len2 && memcmp(str1, str2, len1) == 0;
}{ ... }
static void JimCommandsHT_ValDestructor(void *interp, void *val)
{
JimDecrCmdRefCount(interp, val);
}{ ... }
static const Jim_HashTableType JimCommandsHashTableType = {
JimCommandsHT_HashFunction,
JimObjectHTKeyValDup,
NULL,
JimCommandsHT_KeyCompare,
JimObjectHTKeyValDestructor,
JimCommandsHT_ValDestructor
...};
----------------------- StringCopy Hash Table Type
/* ... */
Jim_Obj *Jim_MakeGlobalNamespaceName(Jim_Interp *interp, Jim_Obj *nameObjPtr)
{
#ifdef jim_ext_namespace
Jim_Obj *resultObj;
const char *name = Jim_String(nameObjPtr);
if (name[0] == ':' && name[1] == ':') {
return nameObjPtr;
}if (name[0] == ':' && name[1] == ':') { ... }
Jim_IncrRefCount(nameObjPtr);
resultObj = Jim_NewStringObj(interp, "::", -1);
Jim_AppendObj(interp, resultObj, nameObjPtr);
Jim_DecrRefCount(interp, nameObjPtr);
return resultObj;/* ... */
#else
return nameObjPtr;
#endif
}{ ... }
/* ... */
static Jim_Obj *JimQualifyName(Jim_Interp *interp, Jim_Obj *objPtr)
{
#ifdef jim_ext_namespace
if (Jim_Length(interp->framePtr->nsObj)) {
int len;
const char *name = Jim_GetString(objPtr, &len);
if (len < 2 || name[0] != ':' || name[1] != ':') {
objPtr = Jim_DuplicateObj(interp, interp->framePtr->nsObj);
Jim_AppendStrings(interp, objPtr, "::", name, NULL);
}if (len < 2 || name[0] != ':' || name[1] != ':') { ... }
}if (Jim_Length(interp->framePtr->nsObj)) { ... }
/* ... */#endif
Jim_IncrRefCount(objPtr);
return objPtr;
}{ ... }
/* ... */
static void JimCreateCommand(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Cmd *cmd)
{
/* ... */
JimPanic((nameObjPtr->refCount == 0, "JimCreateCommand called with zero ref count name"));
/* ... */
if (interp->local) {
Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, nameObjPtr);
if (he) {
cmd->prevCmd = Jim_GetHashEntryVal(he);
Jim_SetHashVal(&interp->commands, he, cmd);
Jim_InterpIncrProcEpoch(interp);
return;
}if (he) { ... }
}if (interp->local) { ... }
/* ... */
Jim_ReplaceHashEntry(&interp->commands, nameObjPtr, cmd);
}{ ... }
int Jim_CreateCommandObj(Jim_Interp *interp, Jim_Obj *cmdNameObj,
Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
{
Jim_Cmd *cmdPtr = Jim_Alloc(sizeof(*cmdPtr));
memset(cmdPtr, 0, sizeof(*cmdPtr));
cmdPtr->inUse = 1;
cmdPtr->u.native.delProc = delProc;
cmdPtr->u.native.cmdProc = cmdProc;
cmdPtr->u.native.privData = privData;
Jim_IncrRefCount(cmdNameObj);
JimCreateCommand(interp, cmdNameObj, cmdPtr);
Jim_DecrRefCount(interp, cmdNameObj);
return JIM_OK;
}{ ... }
int Jim_CreateCommand(Jim_Interp *interp, const char *cmdNameStr,
Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc)
{
return Jim_CreateCommandObj(interp, Jim_NewStringObj(interp, cmdNameStr, -1), cmdProc, privData, delProc);
}{ ... }
static int JimCreateProcedureStatics(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *staticsListObjPtr)
{
int len, i;
len = Jim_ListLength(interp, staticsListObjPtr);
if (len == 0) {
return JIM_OK;
}if (len == 0) { ... }
cmdPtr->u.proc.staticVars = Jim_Alloc(sizeof(Jim_HashTable));
Jim_InitHashTable(cmdPtr->u.proc.staticVars, &JimVariablesHashTableType, interp);
for (i = 0; i < len; i++) {
Jim_Obj *objPtr, *initObjPtr, *nameObjPtr;
Jim_Var *varPtr;
int subLen;
objPtr = Jim_ListGetIndex(interp, staticsListObjPtr, i);
subLen = Jim_ListLength(interp, objPtr);
if (subLen == 1 || subLen == 2) {
/* ... */
nameObjPtr = Jim_ListGetIndex(interp, objPtr, 0);
if (subLen == 1) {
initObjPtr = Jim_GetVariable(interp, nameObjPtr, JIM_NONE);
if (initObjPtr == NULL) {
Jim_SetResultFormatted(interp,
"variable for initialization of static \"%#s\" not found in the local context",
nameObjPtr);
return JIM_ERR;
}if (initObjPtr == NULL) { ... }
}if (subLen == 1) { ... }
else {
initObjPtr = Jim_ListGetIndex(interp, objPtr, 1);
}else { ... }
varPtr = Jim_Alloc(sizeof(*varPtr));
varPtr->objPtr = initObjPtr;
Jim_IncrRefCount(initObjPtr);
varPtr->linkFramePtr = NULL;
if (JimSetNewVariable(cmdPtr->u.proc.staticVars, nameObjPtr, varPtr) != JIM_OK) {
Jim_SetResultFormatted(interp,
"static variable name \"%#s\" duplicated in statics list", nameObjPtr);
Jim_DecrRefCount(interp, initObjPtr);
Jim_Free(varPtr);
return JIM_ERR;
}if (JimSetNewVariable(cmdPtr->u.proc.staticVars, nameObjPtr, varPtr) != JIM_OK) { ... }
}if (subLen == 1 || subLen == 2) { ... }
else {
Jim_SetResultFormatted(interp, "too many fields in static specifier \"%#s\"",
objPtr);
return JIM_ERR;
}else { ... }
}for (i = 0; i < len; i++) { ... }
return JIM_OK;
}{ ... }
#ifdef jim_ext_namespace
static const char *Jim_memrchr(const char *p, int c, int len)
{
int i;
for (i = len; i > 0; i--) {
if (p[i] == c) {
return p + i;
}if (p[i] == c) { ... }
}for (i = len; i > 0; i--) { ... }
return NULL;
}{ ... }
/* ... */#endif
/* ... */
static void JimUpdateProcNamespace(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Obj *nameObjPtr)
{
#ifdef jim_ext_namespace
if (cmdPtr->isproc) {
int len;
const char *cmdname = Jim_GetStringNoQualifier(nameObjPtr, &len);
const char *pt = Jim_memrchr(cmdname, ':', len);
if (pt && pt != cmdname && pt[-1] == ':') {
pt++;
/* ... */
Jim_DecrRefCount(interp, cmdPtr->u.proc.nsObj);
cmdPtr->u.proc.nsObj = Jim_NewStringObj(interp, cmdname, pt - cmdname - 2);
Jim_IncrRefCount(cmdPtr->u.proc.nsObj);
Jim_Obj *tempObj = Jim_NewStringObj(interp, pt, len - (pt - cmdname));
if (Jim_FindHashEntry(&interp->commands, tempObj)) {
Jim_InterpIncrProcEpoch(interp);
}if (Jim_FindHashEntry(&interp->commands, tempObj)) { ... }
Jim_FreeNewObj(interp, tempObj);
}if (pt && pt != cmdname && pt[-1] == ':') { ... }
}if (cmdPtr->isproc) { ... }
/* ... */#endif
}{ ... }
static Jim_Cmd *JimCreateProcedureCmd(Jim_Interp *interp, Jim_Obj *argListObjPtr,
Jim_Obj *staticsListObjPtr, Jim_Obj *bodyObjPtr, Jim_Obj *nsObj)
{
Jim_Cmd *cmdPtr;
int argListLen;
int i;
argListLen = Jim_ListLength(interp, argListObjPtr);
cmdPtr = Jim_Alloc(sizeof(*cmdPtr) + sizeof(struct Jim_ProcArg) * argListLen);
assert(cmdPtr);
memset(cmdPtr, 0, sizeof(*cmdPtr));
cmdPtr->inUse = 1;
cmdPtr->isproc = 1;
cmdPtr->u.proc.argListObjPtr = argListObjPtr;
cmdPtr->u.proc.argListLen = argListLen;
cmdPtr->u.proc.bodyObjPtr = bodyObjPtr;
cmdPtr->u.proc.argsPos = -1;
cmdPtr->u.proc.arglist = (struct Jim_ProcArg *)(cmdPtr + 1);
cmdPtr->u.proc.nsObj = nsObj ? nsObj : interp->emptyObj;
Jim_IncrRefCount(argListObjPtr);
Jim_IncrRefCount(bodyObjPtr);
Jim_IncrRefCount(cmdPtr->u.proc.nsObj);
if (staticsListObjPtr && JimCreateProcedureStatics(interp, cmdPtr, staticsListObjPtr) != JIM_OK) {
goto err;
}if (staticsListObjPtr && JimCreateProcedureStatics(interp, cmdPtr, staticsListObjPtr) != JIM_OK) { ... }
for (i = 0; i < argListLen; i++) {
Jim_Obj *argPtr;
Jim_Obj *nameObjPtr;
Jim_Obj *defaultObjPtr;
int len;
argPtr = Jim_ListGetIndex(interp, argListObjPtr, i);
len = Jim_ListLength(interp, argPtr);
if (len == 0) {
Jim_SetResultString(interp, "argument with no name", -1);
err:
JimDecrCmdRefCount(interp, cmdPtr);
return NULL;
}if (len == 0) { ... }
if (len > 2) {
Jim_SetResultFormatted(interp, "too many fields in argument specifier \"%#s\"", argPtr);
goto err;
}if (len > 2) { ... }
if (len == 2) {
nameObjPtr = Jim_ListGetIndex(interp, argPtr, 0);
defaultObjPtr = Jim_ListGetIndex(interp, argPtr, 1);
}if (len == 2) { ... }
else {
nameObjPtr = argPtr;
defaultObjPtr = NULL;
}else { ... }
if (Jim_CompareStringImmediate(interp, nameObjPtr, "args")) {
if (cmdPtr->u.proc.argsPos >= 0) {
Jim_SetResultString(interp, "'args' specified more than once", -1);
goto err;
}if (cmdPtr->u.proc.argsPos >= 0) { ... }
cmdPtr->u.proc.argsPos = i;
}if (Jim_CompareStringImmediate(interp, nameObjPtr, "args")) { ... }
else {
if (len == 2) {
cmdPtr->u.proc.optArity++;
}if (len == 2) { ... }
else {
cmdPtr->u.proc.reqArity++;
}else { ... }
}else { ... }
cmdPtr->u.proc.arglist[i].nameObjPtr = nameObjPtr;
cmdPtr->u.proc.arglist[i].defaultObjPtr = defaultObjPtr;
}for (i = 0; i < argListLen; i++) { ... }
return cmdPtr;
}{ ... }
int Jim_DeleteCommand(Jim_Interp *interp, Jim_Obj *nameObj)
{
int ret = JIM_OK;
nameObj = JimQualifyName(interp, nameObj);
if (Jim_DeleteHashEntry(&interp->commands, nameObj) == JIM_ERR) {
Jim_SetResultFormatted(interp, "can't delete \"%#s\": command doesn't exist", nameObj);
ret = JIM_ERR;
}if (Jim_DeleteHashEntry(&interp->commands, nameObj) == JIM_ERR) { ... }
Jim_DecrRefCount(interp, nameObj);
return ret;
}{ ... }
int Jim_RenameCommand(Jim_Interp *interp, Jim_Obj *oldNameObj, Jim_Obj *newNameObj)
{
int ret = JIM_ERR;
Jim_HashEntry *he;
Jim_Cmd *cmdPtr;
if (Jim_Length(newNameObj) == 0) {
return Jim_DeleteCommand(interp, oldNameObj);
}if (Jim_Length(newNameObj) == 0) { ... }
oldNameObj = JimQualifyName(interp, oldNameObj);
newNameObj = JimQualifyName(interp, newNameObj);
he = Jim_FindHashEntry(&interp->commands, oldNameObj);
if (he == NULL) {
Jim_SetResultFormatted(interp, "can't rename \"%#s\": command doesn't exist", oldNameObj);
}if (he == NULL) { ... }
else if (Jim_FindHashEntry(&interp->commands, newNameObj)) {
Jim_SetResultFormatted(interp, "can't rename to \"%#s\": command already exists", newNameObj);
}else if (Jim_FindHashEntry(&interp->commands, newNameObj)) { ... }
else {
cmdPtr = Jim_GetHashEntryVal(he);
if (cmdPtr->prevCmd) {
/* ... */
Jim_SetResultFormatted(interp, "can't rename local command \"%#s\"", oldNameObj);
}if (cmdPtr->prevCmd) { ... }
else {
JimIncrCmdRefCount(cmdPtr);
JimUpdateProcNamespace(interp, cmdPtr, newNameObj);
Jim_AddHashEntry(&interp->commands, newNameObj, cmdPtr);
Jim_DeleteHashEntry(&interp->commands, oldNameObj);
Jim_InterpIncrProcEpoch(interp);
ret = JIM_OK;
}else { ... }
}else { ... }
Jim_DecrRefCount(interp, oldNameObj);
Jim_DecrRefCount(interp, newNameObj);
return ret;
}{ ... }
/* ... */
static void FreeCommandInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
Jim_DecrRefCount(interp, objPtr->internalRep.cmdValue.nsObj);
}{ ... }
static void DupCommandInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
dupPtr->internalRep.cmdValue = srcPtr->internalRep.cmdValue;
dupPtr->typePtr = srcPtr->typePtr;
Jim_IncrRefCount(dupPtr->internalRep.cmdValue.nsObj);
}{ ... }
static const Jim_ObjType commandObjType = {
"command",
FreeCommandInternalRep,
DupCommandInternalRep,
NULL,
JIM_TYPE_REFERENCES,
...};
/* ... */
Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
{
Jim_Cmd *cmd;
/* ... */
if (objPtr->typePtr == &commandObjType
&& objPtr->internalRep.cmdValue.procEpoch == interp->procEpoch
#ifdef jim_ext_namespace
&& Jim_StringEqObj(objPtr->internalRep.cmdValue.nsObj, interp->framePtr->nsObj)
#endif
&& objPtr->internalRep.cmdValue.cmdPtr->inUse) {
cmd = objPtr->internalRep.cmdValue.cmdPtr;
}if (objPtr->typePtr == &commandObjType && objPtr->internalRep.cmdValue.procEpoch == interp->procEpoch #ifdef jim_ext_namespace && Jim_StringEqObj(objPtr->internalRep.cmdValue.nsObj, interp->framePtr->nsObj) #endif && objPtr->internalRep.cmdValue.cmdPtr->inUse) { ... }
else {
Jim_Obj *qualifiedNameObj = JimQualifyName(interp, objPtr);
Jim_HashEntry *he = Jim_FindHashEntry(&interp->commands, qualifiedNameObj);
#ifdef jim_ext_namespace
if (he == NULL && Jim_Length(interp->framePtr->nsObj)) {
he = Jim_FindHashEntry(&interp->commands, objPtr);
}if (he == NULL && Jim_Length(interp->framePtr->nsObj)) { ... }
/* ... */#endif
if (he == NULL) {
if (flags & JIM_ERRMSG) {
Jim_SetResultFormatted(interp, "invalid command name \"%#s\"", objPtr);
}if (flags & JIM_ERRMSG) { ... }
Jim_DecrRefCount(interp, qualifiedNameObj);
return NULL;
}if (he == NULL) { ... }
cmd = Jim_GetHashEntryVal(he);
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &commandObjType;
objPtr->internalRep.cmdValue.procEpoch = interp->procEpoch;
objPtr->internalRep.cmdValue.cmdPtr = cmd;
objPtr->internalRep.cmdValue.nsObj = interp->framePtr->nsObj;
Jim_IncrRefCount(interp->framePtr->nsObj);
Jim_DecrRefCount(interp, qualifiedNameObj);
}else { ... }
while (cmd->u.proc.upcall) {
cmd = cmd->prevCmd;
}while (cmd->u.proc.upcall) { ... }
return cmd;
}{ ... }
/* ... */
/* ... */
#define JIM_DICT_SUGAR 100
static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
static const Jim_ObjType variableObjType = {
"variable",
NULL,
NULL,
NULL,
JIM_TYPE_REFERENCES,
...};
/* ... */
static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
{
const char *varName;
Jim_CallFrame *framePtr;
int global;
int len;
Jim_Var *var;
if (objPtr->typePtr == &variableObjType) {
framePtr = objPtr->internalRep.varValue.global ? interp->topFramePtr : interp->framePtr;
if (objPtr->internalRep.varValue.callFrameId == framePtr->id) {
return JIM_OK;
}if (objPtr->internalRep.varValue.callFrameId == framePtr->id) { ... }
}if (objPtr->typePtr == &variableObjType) { ... }
else if (objPtr->typePtr == &dictSubstObjType) {
return JIM_DICT_SUGAR;
}else if (objPtr->typePtr == &dictSubstObjType) { ... }
varName = Jim_GetString(objPtr, &len);
if (len && varName[len - 1] == ')' && strchr(varName, '(') != NULL) {
return JIM_DICT_SUGAR;
}if (len && varName[len - 1] == ')' && strchr(varName, '(') != NULL) { ... }
if (varName[0] == ':' && varName[1] == ':') {
while (*varName == ':') {
varName++;
len--;
}while (*varName == ':') { ... }
global = 1;
framePtr = interp->topFramePtr;
Jim_Obj *tempObj = Jim_NewStringObj(interp, varName, len);
var = JimFindVariable(&framePtr->vars, tempObj);
Jim_FreeNewObj(interp, tempObj);
}if (varName[0] == ':' && varName[1] == ':') { ... }
else {
global = 0;
framePtr = interp->framePtr;
var = JimFindVariable(&framePtr->vars, objPtr);
if (var == NULL && framePtr->staticVars) {
var = JimFindVariable(framePtr->staticVars, objPtr);
}if (var == NULL && framePtr->staticVars) { ... }
}else { ... }
if (var == NULL) {
return JIM_ERR;
}if (var == NULL) { ... }
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &variableObjType;
objPtr->internalRep.varValue.callFrameId = framePtr->id;
objPtr->internalRep.varValue.varPtr = var;
objPtr->internalRep.varValue.global = global;
return JIM_OK;
}{ ... }
------------------------- Commands related functions
static int JimDictSugarSet(Jim_Interp *interp, Jim_Obj *ObjPtr, Jim_Obj *valObjPtr);
static Jim_Obj *JimDictSugarGet(Jim_Interp *interp, Jim_Obj *ObjPtr, int flags);
static int JimSetNewVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr, Jim_Var *var)
{
return Jim_AddHashEntry(ht, nameObjPtr, var);
}{ ... }
static Jim_Var *JimFindVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr)
{
Jim_HashEntry *he = Jim_FindHashEntry(ht, nameObjPtr);
if (he) {
return (Jim_Var *)Jim_GetHashEntryVal(he);
}if (he) { ... }
return NULL;
}{ ... }
static int JimUnsetVariable(Jim_HashTable *ht, Jim_Obj *nameObjPtr)
{
return Jim_DeleteHashEntry(ht, nameObjPtr);
}{ ... }
static Jim_Var *JimCreateVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
{
const char *name;
Jim_CallFrame *framePtr;
int global;
int len;
Jim_Var *var = Jim_Alloc(sizeof(*var));
var->objPtr = valObjPtr;
Jim_IncrRefCount(valObjPtr);
var->linkFramePtr = NULL;
name = Jim_GetString(nameObjPtr, &len);
if (name[0] == ':' && name[1] == ':') {
while (*name == ':') {
name++;
len--;
}while (*name == ':') { ... }
framePtr = interp->topFramePtr;
global = 1;
JimSetNewVariable(&framePtr->vars, Jim_NewStringObj(interp, name, len), var);
}if (name[0] == ':' && name[1] == ':') { ... }
else {
framePtr = interp->framePtr;
global = 0;
JimSetNewVariable(&framePtr->vars, nameObjPtr, var);
}else { ... }
Jim_FreeIntRep(interp, nameObjPtr);
nameObjPtr->typePtr = &variableObjType;
nameObjPtr->internalRep.varValue.callFrameId = framePtr->id;
nameObjPtr->internalRep.varValue.varPtr = var;
nameObjPtr->internalRep.varValue.global = global;
return var;
}{ ... }
/* ... */
/* ... */
int Jim_SetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr)
{
int err;
Jim_Var *var;
switch (SetVariableFromAny(interp, nameObjPtr)) {
case JIM_DICT_SUGAR:
return JimDictSugarSet(interp, nameObjPtr, valObjPtr);
case JIM_DICT_SUGAR:
case JIM_ERR:
JimCreateVariable(interp, nameObjPtr, valObjPtr);
break;
case JIM_ERR:
case JIM_OK:
var = nameObjPtr->internalRep.varValue.varPtr;
if (var->linkFramePtr == NULL) {
Jim_IncrRefCount(valObjPtr);
Jim_DecrRefCount(interp, var->objPtr);
var->objPtr = valObjPtr;
}if (var->linkFramePtr == NULL) { ... }
else {
Jim_CallFrame *savedCallFrame;
savedCallFrame = interp->framePtr;
interp->framePtr = var->linkFramePtr;
err = Jim_SetVariable(interp, var->objPtr, valObjPtr);
interp->framePtr = savedCallFrame;
if (err != JIM_OK)
return err;
}else { ... }
case JIM_OK: }switch (SetVariableFromAny(interp, nameObjPtr)) { ... }
return JIM_OK;
}{ ... }
int Jim_SetVariableStr(Jim_Interp *interp, const char *name, Jim_Obj *objPtr)
{
Jim_Obj *nameObjPtr;
int result;
nameObjPtr = Jim_NewStringObj(interp, name, -1);
Jim_IncrRefCount(nameObjPtr);
result = Jim_SetVariable(interp, nameObjPtr, objPtr);
Jim_DecrRefCount(interp, nameObjPtr);
return result;
}{ ... }
int Jim_SetGlobalVariableStr(Jim_Interp *interp, const char *name, Jim_Obj *objPtr)
{
Jim_CallFrame *savedFramePtr;
int result;
savedFramePtr = interp->framePtr;
interp->framePtr = interp->topFramePtr;
result = Jim_SetVariableStr(interp, name, objPtr);
interp->framePtr = savedFramePtr;
return result;
}{ ... }
int Jim_SetVariableStrWithStr(Jim_Interp *interp, const char *name, const char *val)
{
Jim_Obj *valObjPtr;
int result;
valObjPtr = Jim_NewStringObj(interp, val, -1);
Jim_IncrRefCount(valObjPtr);
result = Jim_SetVariableStr(interp, name, valObjPtr);
Jim_DecrRefCount(interp, valObjPtr);
return result;
}{ ... }
int Jim_SetVariableLink(Jim_Interp *interp, Jim_Obj *nameObjPtr,
Jim_Obj *targetNameObjPtr, Jim_CallFrame *targetCallFrame)
{
const char *varName;
const char *targetName;
Jim_CallFrame *framePtr;
Jim_Var *varPtr;
int len;
int varnamelen;
switch (SetVariableFromAny(interp, nameObjPtr)) {
case JIM_DICT_SUGAR:
Jim_SetResultFormatted(interp, "bad variable name \"%#s\": upvar won't create a scalar variable that looks like an array element", nameObjPtr);
return JIM_ERR;
case JIM_DICT_SUGAR:
case JIM_OK:
varPtr = nameObjPtr->internalRep.varValue.varPtr;
if (varPtr->linkFramePtr == NULL) {
Jim_SetResultFormatted(interp, "variable \"%#s\" already exists", nameObjPtr);
return JIM_ERR;
}if (varPtr->linkFramePtr == NULL) { ... }
varPtr->linkFramePtr = NULL;
break;case JIM_OK:
}switch (SetVariableFromAny(interp, nameObjPtr)) { ... }
varName = Jim_GetString(nameObjPtr, &varnamelen);
if (varName[0] == ':' && varName[1] == ':') {
while (*varName == ':') {
varName++;
varnamelen--;
}while (*varName == ':') { ... }
framePtr = interp->topFramePtr;
}if (varName[0] == ':' && varName[1] == ':') { ... }
else {
framePtr = interp->framePtr;
}else { ... }
targetName = Jim_GetString(targetNameObjPtr, &len);
if (targetName[0] == ':' && targetName[1] == ':') {
while (*targetName == ':') {
targetName++;
len--;
}while (*targetName == ':') { ... }
targetNameObjPtr = Jim_NewStringObj(interp, targetName, len);
targetCallFrame = interp->topFramePtr;
}if (targetName[0] == ':' && targetName[1] == ':') { ... }
Jim_IncrRefCount(targetNameObjPtr);
if (framePtr->level < targetCallFrame->level) {
Jim_SetResultFormatted(interp,
"bad variable name \"%#s\": upvar won't create namespace variable that refers to procedure variable",
nameObjPtr);
Jim_DecrRefCount(interp, targetNameObjPtr);
return JIM_ERR;
}if (framePtr->level < targetCallFrame->level) { ... }
if (framePtr == targetCallFrame) {
Jim_Obj *objPtr = targetNameObjPtr;
while (1) {
if (Jim_Length(objPtr) == varnamelen && memcmp(Jim_String(objPtr), varName, varnamelen) == 0) {
Jim_SetResultString(interp, "can't upvar from variable to itself", -1);
Jim_DecrRefCount(interp, targetNameObjPtr);
return JIM_ERR;
}if (Jim_Length(objPtr) == varnamelen && memcmp(Jim_String(objPtr), varName, varnamelen) == 0) { ... }
if (SetVariableFromAny(interp, objPtr) != JIM_OK)
break;
varPtr = objPtr->internalRep.varValue.varPtr;
if (varPtr->linkFramePtr != targetCallFrame)
break;
objPtr = varPtr->objPtr;
}while (1) { ... }
}if (framePtr == targetCallFrame) { ... }
Jim_SetVariable(interp, nameObjPtr, targetNameObjPtr);
nameObjPtr->internalRep.varValue.varPtr->linkFramePtr = targetCallFrame;
Jim_DecrRefCount(interp, targetNameObjPtr);
return JIM_OK;
}{ ... }
/* ... */
Jim_Obj *Jim_GetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
{
if (interp->safeexpr) {
return nameObjPtr;
}if (interp->safeexpr) { ... }
switch (SetVariableFromAny(interp, nameObjPtr)) {
case JIM_OK:{
Jim_Var *varPtr = nameObjPtr->internalRep.varValue.varPtr;
if (varPtr->linkFramePtr == NULL) {
return varPtr->objPtr;
}if (varPtr->linkFramePtr == NULL) { ... }
else {
Jim_Obj *objPtr;
Jim_CallFrame *savedCallFrame = interp->framePtr;
interp->framePtr = varPtr->linkFramePtr;
objPtr = Jim_GetVariable(interp, varPtr->objPtr, flags);
interp->framePtr = savedCallFrame;
if (objPtr) {
return objPtr;
}if (objPtr) { ... }
}else { ... }
...}
break;
case JIM_OK:
case JIM_DICT_SUGAR:
return JimDictSugarGet(interp, nameObjPtr, flags);case JIM_DICT_SUGAR:
}switch (SetVariableFromAny(interp, nameObjPtr)) { ... }
if (flags & JIM_ERRMSG) {
Jim_SetResultFormatted(interp, "can't read \"%#s\": no such variable", nameObjPtr);
}if (flags & JIM_ERRMSG) { ... }
return NULL;
}{ ... }
Jim_Obj *Jim_GetGlobalVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
{
Jim_CallFrame *savedFramePtr;
Jim_Obj *objPtr;
savedFramePtr = interp->framePtr;
interp->framePtr = interp->topFramePtr;
objPtr = Jim_GetVariable(interp, nameObjPtr, flags);
interp->framePtr = savedFramePtr;
return objPtr;
}{ ... }
Jim_Obj *Jim_GetVariableStr(Jim_Interp *interp, const char *name, int flags)
{
Jim_Obj *nameObjPtr, *varObjPtr;
nameObjPtr = Jim_NewStringObj(interp, name, -1);
Jim_IncrRefCount(nameObjPtr);
varObjPtr = Jim_GetVariable(interp, nameObjPtr, flags);
Jim_DecrRefCount(interp, nameObjPtr);
return varObjPtr;
}{ ... }
Jim_Obj *Jim_GetGlobalVariableStr(Jim_Interp *interp, const char *name, int flags)
{
Jim_CallFrame *savedFramePtr;
Jim_Obj *objPtr;
savedFramePtr = interp->framePtr;
interp->framePtr = interp->topFramePtr;
objPtr = Jim_GetVariableStr(interp, name, flags);
interp->framePtr = savedFramePtr;
return objPtr;
}{ ... }
/* ... */
int Jim_UnsetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags)
{
Jim_Var *varPtr;
int retval;
Jim_CallFrame *framePtr;
retval = SetVariableFromAny(interp, nameObjPtr);
if (retval == JIM_DICT_SUGAR) {
return JimDictSugarSet(interp, nameObjPtr, NULL);
}if (retval == JIM_DICT_SUGAR) { ... }
else if (retval == JIM_OK) {
varPtr = nameObjPtr->internalRep.varValue.varPtr;
if (varPtr->linkFramePtr) {
framePtr = interp->framePtr;
interp->framePtr = varPtr->linkFramePtr;
retval = Jim_UnsetVariable(interp, varPtr->objPtr, JIM_NONE);
interp->framePtr = framePtr;
}if (varPtr->linkFramePtr) { ... }
else {
if (nameObjPtr->internalRep.varValue.global) {
int len;
const char *name = Jim_GetString(nameObjPtr, &len);
while (*name == ':') {
name++;
len--;
}while (*name == ':') { ... }
framePtr = interp->topFramePtr;
Jim_Obj *tempObj = Jim_NewStringObj(interp, name, len);
retval = JimUnsetVariable(&framePtr->vars, tempObj);
Jim_FreeNewObj(interp, tempObj);
}if (nameObjPtr->internalRep.varValue.global) { ... }
else {
framePtr = interp->framePtr;
retval = JimUnsetVariable(&framePtr->vars, nameObjPtr);
}else { ... }
if (retval == JIM_OK) {
framePtr->id = interp->callFrameEpoch++;
}if (retval == JIM_OK) { ... }
}else { ... }
}else if (retval == JIM_OK) { ... }
if (retval != JIM_OK && (flags & JIM_ERRMSG)) {
Jim_SetResultFormatted(interp, "can't unset \"%#s\": no such variable", nameObjPtr);
}if (retval != JIM_OK && (flags & JIM_ERRMSG)) { ... }
return retval;
}{ ... }
-------------------- Variables related functions
/* ... */
static void JimDictSugarParseVarKey(Jim_Interp *interp, Jim_Obj *objPtr,
Jim_Obj **varPtrPtr, Jim_Obj **keyPtrPtr)
{
const char *str, *p;
int len, keyLen;
Jim_Obj *varObjPtr, *keyObjPtr;
str = Jim_GetString(objPtr, &len);
p = strchr(str, '(');
JimPanic((p == NULL, "JimDictSugarParseVarKey() called for non-dict-sugar (%s)", str));
varObjPtr = Jim_NewStringObj(interp, str, p - str);
p++;
keyLen = (str + len) - p;
if (str[len - 1] == ')') {
keyLen--;
}if (str[len - 1] == ')') { ... }
keyObjPtr = Jim_NewStringObj(interp, p, keyLen);
Jim_IncrRefCount(varObjPtr);
Jim_IncrRefCount(keyObjPtr);
*varPtrPtr = varObjPtr;
*keyPtrPtr = keyObjPtr;
}{ ... }
/* ... */
static int JimDictSugarSet(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *valObjPtr)
{
int err;
SetDictSubstFromAny(interp, objPtr);
err = Jim_SetDictKeysVector(interp, objPtr->internalRep.dictSubstValue.varNameObjPtr,
&objPtr->internalRep.dictSubstValue.indexObjPtr, 1, valObjPtr, JIM_MUSTEXIST);
if (err == JIM_OK) {
Jim_SetEmptyResult(interp);
}if (err == JIM_OK) { ... }
else {
if (!valObjPtr) {
if (Jim_GetVariable(interp, objPtr->internalRep.dictSubstValue.varNameObjPtr, JIM_NONE)) {
Jim_SetResultFormatted(interp, "can't unset \"%#s\": no such element in array",
objPtr);
return err;
}if (Jim_GetVariable(interp, objPtr->internalRep.dictSubstValue.varNameObjPtr, JIM_NONE)) { ... }
}if (!valObjPtr) { ... }
Jim_SetResultFormatted(interp, "can't %s \"%#s\": variable isn't array",
(valObjPtr ? "set" : "unset"), objPtr);
}else { ... }
return err;
}{ ... }
/* ... */
static Jim_Obj *JimDictExpandArrayVariable(Jim_Interp *interp, Jim_Obj *varObjPtr,
Jim_Obj *keyObjPtr, int flags)
{
Jim_Obj *dictObjPtr;
Jim_Obj *resObjPtr = NULL;
int ret;
dictObjPtr = Jim_GetVariable(interp, varObjPtr, JIM_ERRMSG);
if (!dictObjPtr) {
return NULL;
}if (!dictObjPtr) { ... }
ret = Jim_DictKey(interp, dictObjPtr, keyObjPtr, &resObjPtr, JIM_NONE);
if (ret != JIM_OK) {
Jim_SetResultFormatted(interp,
"can't read \"%#s(%#s)\": %s array", varObjPtr, keyObjPtr,
ret < 0 ? "variable isn't" : "no such element in");
}if (ret != JIM_OK) { ... }
else if ((flags & JIM_UNSHARED) && Jim_IsShared(dictObjPtr)) {
Jim_SetVariable(interp, varObjPtr, Jim_DuplicateObj(interp, dictObjPtr));
}else if ((flags & JIM_UNSHARED) && Jim_IsShared(dictObjPtr)) { ... }
return resObjPtr;
}{ ... }
static Jim_Obj *JimDictSugarGet(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
{
SetDictSubstFromAny(interp, objPtr);
return JimDictExpandArrayVariable(interp,
objPtr->internalRep.dictSubstValue.varNameObjPtr,
objPtr->internalRep.dictSubstValue.indexObjPtr, flags);
}{ ... }
---------- Dict syntax sugar (similar to array Tcl syntax)
void FreeDictSubstInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
Jim_DecrRefCount(interp, objPtr->internalRep.dictSubstValue.varNameObjPtr);
Jim_DecrRefCount(interp, objPtr->internalRep.dictSubstValue.indexObjPtr);
}{ ... }
static void DupDictSubstInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
dupPtr->internalRep = srcPtr->internalRep;
Jim_IncrRefCount(dupPtr->internalRep.dictSubstValue.varNameObjPtr);
Jim_IncrRefCount(dupPtr->internalRep.dictSubstValue.indexObjPtr);
}{ ... }
static void SetDictSubstFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{
if (objPtr->typePtr != &dictSubstObjType) {
Jim_Obj *varObjPtr, *keyObjPtr;
if (objPtr->typePtr == &interpolatedObjType) {
varObjPtr = objPtr->internalRep.dictSubstValue.varNameObjPtr;
keyObjPtr = objPtr->internalRep.dictSubstValue.indexObjPtr;
Jim_IncrRefCount(varObjPtr);
Jim_IncrRefCount(keyObjPtr);
}if (objPtr->typePtr == &interpolatedObjType) { ... }
else {
JimDictSugarParseVarKey(interp, objPtr, &varObjPtr, &keyObjPtr);
}else { ... }
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &dictSubstObjType;
objPtr->internalRep.dictSubstValue.varNameObjPtr = varObjPtr;
objPtr->internalRep.dictSubstValue.indexObjPtr = keyObjPtr;
}if (objPtr->typePtr != &dictSubstObjType) { ... }
}{ ... }
/* ... */
static Jim_Obj *JimExpandDictSugar(Jim_Interp *interp, Jim_Obj *objPtr)
{
Jim_Obj *resObjPtr = NULL;
Jim_Obj *substKeyObjPtr = NULL;
if (interp->safeexpr) {
return objPtr;
}if (interp->safeexpr) { ... }
SetDictSubstFromAny(interp, objPtr);
if (Jim_SubstObj(interp, objPtr->internalRep.dictSubstValue.indexObjPtr,
&substKeyObjPtr, JIM_NONE)
!= JIM_OK) {
return NULL;
}if (Jim_SubstObj(interp, objPtr->internalRep.dictSubstValue.indexObjPtr, &substKeyObjPtr, JIM_NONE) != JIM_OK) { ... }
Jim_IncrRefCount(substKeyObjPtr);
resObjPtr =
JimDictExpandArrayVariable(interp, objPtr->internalRep.dictSubstValue.varNameObjPtr,
substKeyObjPtr, 0);
Jim_DecrRefCount(interp, substKeyObjPtr);
return resObjPtr;
}{ ... }
/* ... */
static Jim_CallFrame *JimCreateCallFrame(Jim_Interp *interp, Jim_CallFrame *parent, Jim_Obj *nsObj)
{
Jim_CallFrame *cf;
if (interp->freeFramesList) {
cf = interp->freeFramesList;
interp->freeFramesList = cf->next;
cf->argv = NULL;
cf->argc = 0;
cf->procArgsObjPtr = NULL;
cf->procBodyObjPtr = NULL;
cf->next = NULL;
cf->staticVars = NULL;
cf->localCommands = NULL;
cf->tailcallObj = NULL;
cf->tailcallCmd = NULL;
}if (interp->freeFramesList) { ... }
else {
cf = Jim_Alloc(sizeof(*cf));
memset(cf, 0, sizeof(*cf));
Jim_InitHashTable(&cf->vars, &JimVariablesHashTableType, interp);
}else { ... }
cf->id = interp->callFrameEpoch++;
cf->parent = parent;
cf->level = parent ? parent->level + 1 : 0;
cf->nsObj = nsObj;
Jim_IncrRefCount(nsObj);
return cf;
}{ ... }
static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands)
{
if (localCommands) {
Jim_Obj *cmdNameObj;
while ((cmdNameObj = Jim_StackPop(localCommands)) != NULL) {
Jim_HashTable *ht = &interp->commands;
Jim_HashEntry *he = Jim_FindHashEntry(ht, cmdNameObj);
if (he) {
Jim_Cmd *cmd = Jim_GetHashEntryVal(he);
if (cmd->prevCmd) {
Jim_Cmd *prevCmd = cmd->prevCmd;
cmd->prevCmd = NULL;
JimDecrCmdRefCount(interp, cmd);
Jim_SetHashVal(ht, he, prevCmd);
}if (cmd->prevCmd) { ... }
else {
Jim_DeleteHashEntry(ht, cmdNameObj);
}else { ... }
}if (he) { ... }
Jim_DecrRefCount(interp, cmdNameObj);
}while ((cmdNameObj = Jim_StackPop(localCommands)) != NULL) { ... }
Jim_FreeStack(localCommands);
Jim_Free(localCommands);
}if (localCommands) { ... }
return JIM_OK;
}{ ... }
/* ... */
static int JimInvokeDefer(Jim_Interp *interp, int retcode)
{
Jim_Obj *objPtr;
if (JimFindVariable(&interp->framePtr->vars, interp->defer) == NULL) {
return retcode;
}if (JimFindVariable(&interp->framePtr->vars, interp->defer) == NULL) { ... }
objPtr = Jim_GetVariable(interp, interp->defer, JIM_NONE);
if (objPtr) {
int ret = JIM_OK;
int i;
int listLen = Jim_ListLength(interp, objPtr);
Jim_Obj *resultObjPtr;
Jim_IncrRefCount(objPtr);
/* ... */
resultObjPtr = Jim_GetResult(interp);
Jim_IncrRefCount(resultObjPtr);
Jim_SetEmptyResult(interp);
for (i = listLen; i > 0; i--) {
Jim_Obj *scriptObjPtr = Jim_ListGetIndex(interp, objPtr, i - 1);
ret = Jim_EvalObj(interp, scriptObjPtr);
if (ret != JIM_OK) {
break;
}if (ret != JIM_OK) { ... }
}for (i = listLen; i > 0; i--) { ... }
if (ret == JIM_OK || retcode == JIM_ERR) {
Jim_SetResult(interp, resultObjPtr);
}if (ret == JIM_OK || retcode == JIM_ERR) { ... }
else {
retcode = ret;
}else { ... }
Jim_DecrRefCount(interp, resultObjPtr);
Jim_DecrRefCount(interp, objPtr);
}if (objPtr) { ... }
return retcode;
}{ ... }
#define JIM_FCF_FULL 0
#define JIM_FCF_REUSE 1
static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action)
{
JimDeleteLocalProcs(interp, cf->localCommands);
if (cf->procArgsObjPtr)
Jim_DecrRefCount(interp, cf->procArgsObjPtr);
if (cf->procBodyObjPtr)
Jim_DecrRefCount(interp, cf->procBodyObjPtr);
Jim_DecrRefCount(interp, cf->nsObj);
if (action == JIM_FCF_FULL || cf->vars.size != JIM_HT_INITIAL_SIZE)
Jim_FreeHashTable(&cf->vars);
else {
Jim_ClearHashTable(&cf->vars);
}else { ... }
cf->next = interp->freeFramesList;
interp->freeFramesList = cf;
}{ ... }
/* ... */
#if defined(JIM_REFERENCES) && !defined(JIM_BOOTSTRAP)
/* ... */
static void JimReferencesHTValDestructor(void *interp, void *val)
{
Jim_Reference *refPtr = (void *)val;
Jim_DecrRefCount(interp, refPtr->objPtr);
if (refPtr->finalizerCmdNamePtr != NULL) {
Jim_DecrRefCount(interp, refPtr->finalizerCmdNamePtr);
}if (refPtr->finalizerCmdNamePtr != NULL) { ... }
Jim_Free(val);
}{ ... }
static unsigned int JimReferencesHTHashFunction(const void *key)
{
const unsigned long *widePtr = key;
unsigned int intValue = (unsigned int)*widePtr;
return Jim_IntHashFunction(intValue);
}{ ... }
static void *JimReferencesHTKeyDup(void *privdata, const void *key)
{
void *copy = Jim_Alloc(sizeof(unsigned long));
JIM_NOTUSED(privdata);
memcpy(copy, key, sizeof(unsigned long));
return copy;
}{ ... }
static int JimReferencesHTKeyCompare(void *privdata, const void *key1, const void *key2)
{
JIM_NOTUSED(privdata);
return memcmp(key1, key2, sizeof(unsigned long)) == 0;
}{ ... }
static void JimReferencesHTKeyDestructor(void *privdata, void *key)
{
JIM_NOTUSED(privdata);
Jim_Free(key);
}{ ... }
static const Jim_HashTableType JimReferencesHashTableType = {
JimReferencesHTHashFunction,
JimReferencesHTKeyDup,
NULL,
JimReferencesHTKeyCompare,
JimReferencesHTKeyDestructor,
JimReferencesHTValDestructor
...};
/* ... */
/* ... */
#define JIM_REFERENCE_SPACE (35+JIM_REFERENCE_TAGLEN)
static int JimFormatReference(char *buf, Jim_Reference *refPtr, unsigned long id)
{
const char *fmt = "<reference.<%s>.%020lu>";
sprintf(buf, fmt, refPtr->tag, id);
return JIM_REFERENCE_SPACE;
}{ ... }
static void UpdateStringOfReference(struct Jim_Obj *objPtr);
static const Jim_ObjType referenceObjType = {
"reference",
NULL,
NULL,
UpdateStringOfReference,
JIM_TYPE_REFERENCES,
...};
static void UpdateStringOfReference(struct Jim_Obj *objPtr)
{
char buf[JIM_REFERENCE_SPACE + 1];
JimFormatReference(buf, objPtr->internalRep.refValue.refPtr, objPtr->internalRep.refValue.id);
JimSetStringBytes(objPtr, buf);
}{ ... }
/* ... */
static int isrefchar(int c)
{
return (c == '_' || isalnum(c));
}{ ... }
static int SetReferenceFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{
unsigned long value;
int i, len;
const char *str, *start, *end;
char refId[21];
Jim_Reference *refPtr;
Jim_HashEntry *he;
char *endptr;
str = Jim_GetString(objPtr, &len);
if (len < JIM_REFERENCE_SPACE)
goto badformat;
start = str;
end = str + len - 1;
while (*start == ' ')
start++;
while (*end == ' ' && end > start)
end--;
if (end - start + 1 != JIM_REFERENCE_SPACE)
goto badformat;
if (memcmp(start, "<reference.<", 12) != 0)
goto badformat;
if (start[12 + JIM_REFERENCE_TAGLEN] != '>' || end[0] != '>')
goto badformat;
for (i = 0; i < JIM_REFERENCE_TAGLEN; i++) {
if (!isrefchar(start[12 + i]))
goto badformat;
}for (i = 0; i < JIM_REFERENCE_TAGLEN; i++) { ... }
memcpy(refId, start + 14 + JIM_REFERENCE_TAGLEN, 20);
refId[20] = '\0';
value = strtoul(refId, &endptr, 10);
if (JimCheckConversion(refId, endptr) != JIM_OK)
goto badformat;
he = Jim_FindHashEntry(&interp->references, &value);
if (he == NULL) {
Jim_SetResultFormatted(interp, "invalid reference id \"%#s\"", objPtr);
return JIM_ERR;
}if (he == NULL) { ... }
refPtr = Jim_GetHashEntryVal(he);
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &referenceObjType;
objPtr->internalRep.refValue.id = value;
objPtr->internalRep.refValue.refPtr = refPtr;
return JIM_OK;
badformat:
Jim_SetResultFormatted(interp, "expected reference but got \"%#s\"", objPtr);
return JIM_ERR;
}{ ... }
/* ... */
Jim_Obj *Jim_NewReference(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *tagPtr, Jim_Obj *cmdNamePtr)
{
struct Jim_Reference *refPtr;
unsigned long id;
Jim_Obj *refObjPtr;
const char *tag;
int tagLen, i;
Jim_CollectIfNeeded(interp);
refPtr = Jim_Alloc(sizeof(*refPtr));
refPtr->objPtr = objPtr;
Jim_IncrRefCount(objPtr);
refPtr->finalizerCmdNamePtr = cmdNamePtr;
if (cmdNamePtr)
Jim_IncrRefCount(cmdNamePtr);
id = interp->referenceNextId++;
Jim_AddHashEntry(&interp->references, &id, refPtr);
refObjPtr = Jim_NewObj(interp);
refObjPtr->typePtr = &referenceObjType;
refObjPtr->bytes = NULL;
refObjPtr->internalRep.refValue.id = id;
refObjPtr->internalRep.refValue.refPtr = refPtr;
interp->referenceNextId++;
/* ... */
tag = Jim_GetString(tagPtr, &tagLen);
if (tagLen > JIM_REFERENCE_TAGLEN)
tagLen = JIM_REFERENCE_TAGLEN;
for (i = 0; i < JIM_REFERENCE_TAGLEN; i++) {
if (i < tagLen && isrefchar(tag[i]))
refPtr->tag[i] = tag[i];
else
refPtr->tag[i] = '_';
}for (i = 0; i < JIM_REFERENCE_TAGLEN; i++) { ... }
refPtr->tag[JIM_REFERENCE_TAGLEN] = '\0';
return refObjPtr;
}{ ... }
Jim_Reference *Jim_GetReference(Jim_Interp *interp, Jim_Obj *objPtr)
{
if (objPtr->typePtr != &referenceObjType && SetReferenceFromAny(interp, objPtr) == JIM_ERR)
return NULL;
return objPtr->internalRep.refValue.refPtr;
}{ ... }
int Jim_SetFinalizer(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *cmdNamePtr)
{
Jim_Reference *refPtr;
if ((refPtr = Jim_GetReference(interp, objPtr)) == NULL)
return JIM_ERR;
Jim_IncrRefCount(cmdNamePtr);
if (refPtr->finalizerCmdNamePtr)
Jim_DecrRefCount(interp, refPtr->finalizerCmdNamePtr);
refPtr->finalizerCmdNamePtr = cmdNamePtr;
return JIM_OK;
}{ ... }
int Jim_GetFinalizer(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj **cmdNamePtrPtr)
{
Jim_Reference *refPtr;
if ((refPtr = Jim_GetReference(interp, objPtr)) == NULL)
return JIM_ERR;
*cmdNamePtrPtr = refPtr->finalizerCmdNamePtr;
return JIM_OK;
}{ ... }
/* ... */
static const Jim_HashTableType JimRefMarkHashTableType = {
JimReferencesHTHashFunction,
JimReferencesHTKeyDup,
NULL,
JimReferencesHTKeyCompare,
JimReferencesHTKeyDestructor,
NULL
...};
int Jim_Collect(Jim_Interp *interp)
{
int collected = 0;
Jim_HashTable marks;
Jim_HashTableIterator htiter;
Jim_HashEntry *he;
Jim_Obj *objPtr;
if (interp->lastCollectId == (unsigned long)~0) {
return 0;
}if (interp->lastCollectId == (unsigned long)~0) { ... }
interp->lastCollectId = ~0;
/* ... */
Jim_InitHashTable(&marks, &JimRefMarkHashTableType, NULL);
objPtr = interp->liveList;
while (objPtr) {
if (objPtr->typePtr == NULL || objPtr->typePtr->flags & JIM_TYPE_REFERENCES) {
const char *str, *p;
int len;
/* ... */
if (objPtr->typePtr == &referenceObjType) {
Jim_AddHashEntry(&marks, &objPtr->internalRep.refValue.id, NULL);
#ifdef JIM_DEBUG_GC
printf("MARK (reference): %d refcount: %d\n",
(int)objPtr->internalRep.refValue.id, objPtr->refCount);/* ... */
#endif
objPtr = objPtr->nextObjPtr;
continue;
}if (objPtr->typePtr == &referenceObjType) { ... }
/* ... */
p = str = Jim_GetString(objPtr, &len);
if (len < JIM_REFERENCE_SPACE) {
objPtr = objPtr->nextObjPtr;
continue;
}if (len < JIM_REFERENCE_SPACE) { ... }
/* ... */
if (str[0] == ':' && str[1] == ':') {
str +=2;
len -= 2;
}if (str[0] == ':' && str[1] == ':') { ... }
while (1) {
int i;
unsigned long id;
if ((p = strstr(p, "<reference.<")) == NULL)
break;
if (len - (p - str) < JIM_REFERENCE_SPACE)
break;
if (p[41] != '>' || p[19] != '>' || p[20] != '.')
break;
for (i = 21; i <= 40; i++)
if (!isdigit(UCHAR(p[i])))
break;
id = strtoul(p + 21, NULL, 10);
/* ... */
/* ... */
if (p == str && objPtr->refCount == 1 && Jim_FindHashEntry(&interp->commands, objPtr)) {
#ifdef JIM_DEBUG_GC
printf("No MARK: %lu - command with refcount=1\n", id);
#endif
break;
}if (p == str && objPtr->refCount == 1 && Jim_FindHashEntry(&interp->commands, objPtr)) { ... }
Jim_AddHashEntry(&marks, &id, objPtr);
#ifdef JIM_DEBUG_GC
printf("MARK: %lu (type=%s)\n", id, JimObjTypeName(objPtr));
#endif
p += JIM_REFERENCE_SPACE;
}while (1) { ... }
}if (objPtr->typePtr == NULL || objPtr->typePtr->flags & JIM_TYPE_REFERENCES) { ... }
objPtr = objPtr->nextObjPtr;
}while (objPtr) { ... }
/* ... */
JimInitHashTableIterator(&interp->references, &htiter);
while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
const unsigned long *refId;
Jim_Reference *refPtr;
refId = he->key;
/* ... */
if (Jim_FindHashEntry(&marks, refId) == NULL) {
#ifdef JIM_DEBUG_GC
printf("COLLECTING %d\n", (int)*refId);
#endif
collected++;
/* ... */
refPtr = Jim_GetHashEntryVal(he);
if (refPtr->finalizerCmdNamePtr) {
char *refstr = Jim_Alloc(JIM_REFERENCE_SPACE + 1);
Jim_Obj *objv[3], *oldResult;
JimFormatReference(refstr, refPtr, *refId);
objv[0] = refPtr->finalizerCmdNamePtr;
objv[1] = Jim_NewStringObjNoAlloc(interp, refstr, JIM_REFERENCE_SPACE);
objv[2] = refPtr->objPtr;
Jim_IncrRefCount(objv[0]);
/* ... */
oldResult = interp->result;
Jim_IncrRefCount(oldResult);
Jim_EvalObjVector(interp, 3, objv);
Jim_SetResult(interp, oldResult);
Jim_DecrRefCount(interp, oldResult);
Jim_DecrRefCount(interp, objv[0]);
}if (refPtr->finalizerCmdNamePtr) { ... }
Jim_DeleteHashEntry(&interp->references, refId);
}if (Jim_FindHashEntry(&marks, refId) == NULL) { ... }
}while ((he = Jim_NextHashEntry(&htiter)) != NULL) { ... }
Jim_FreeHashTable(&marks);
interp->lastCollectId = interp->referenceNextId;
interp->lastCollectTime = JimClock();
return collected;
}{ ... }
#define JIM_COLLECT_ID_PERIOD 5000000
#define JIM_COLLECT_TIME_PERIOD 300000
void Jim_CollectIfNeeded(Jim_Interp *interp)
{
unsigned long elapsedId;
jim_wide elapsedTime;
elapsedId = interp->referenceNextId - interp->lastCollectId;
elapsedTime = JimClock() - interp->lastCollectTime;
if (elapsedId > JIM_COLLECT_ID_PERIOD || elapsedTime > JIM_COLLECT_TIME_PERIOD) {
Jim_Collect(interp);
}if (elapsedId > JIM_COLLECT_ID_PERIOD || elapsedTime > JIM_COLLECT_TIME_PERIOD) { ... }
}{ ... }
#endif/* ... */
int Jim_IsBigEndian(void)
{
union {
unsigned short s;
unsigned char c[2];
...} uval = {0x0102};
return uval.c[0] == 1;
}{ ... }
/* ... */
Jim_Interp *Jim_CreateInterp(void)
{
Jim_Interp *i = Jim_Alloc(sizeof(*i));
memset(i, 0, sizeof(*i));
i->maxCallFrameDepth = JIM_MAX_CALLFRAME_DEPTH;
i->maxEvalDepth = JIM_MAX_EVAL_DEPTH;
i->lastCollectTime = JimClock();
/* ... */
Jim_InitHashTable(&i->commands, &JimCommandsHashTableType, i);
#ifdef JIM_REFERENCES
Jim_InitHashTable(&i->references, &JimReferencesHashTableType, i);
#endif
Jim_InitHashTable(&i->assocData, &JimAssocDataHashTableType, i);
Jim_InitHashTable(&i->packages, &JimPackageHashTableType, NULL);
i->emptyObj = Jim_NewEmptyStringObj(i);
i->trueObj = Jim_NewIntObj(i, 1);
i->falseObj = Jim_NewIntObj(i, 0);
i->framePtr = i->topFramePtr = JimCreateCallFrame(i, NULL, i->emptyObj);
i->errorFileNameObj = i->emptyObj;
i->result = i->emptyObj;
i->stackTrace = Jim_NewListObj(i, NULL, 0);
i->unknown = Jim_NewStringObj(i, "unknown", -1);
i->defer = Jim_NewStringObj(i, "jim::defer", -1);
i->errorProc = i->emptyObj;
i->currentScriptObj = Jim_NewEmptyStringObj(i);
i->nullScriptObj = Jim_NewEmptyStringObj(i);
Jim_IncrRefCount(i->emptyObj);
Jim_IncrRefCount(i->errorFileNameObj);
Jim_IncrRefCount(i->result);
Jim_IncrRefCount(i->stackTrace);
Jim_IncrRefCount(i->unknown);
Jim_IncrRefCount(i->defer);
Jim_IncrRefCount(i->currentScriptObj);
Jim_IncrRefCount(i->nullScriptObj);
Jim_IncrRefCount(i->errorProc);
Jim_IncrRefCount(i->trueObj);
Jim_IncrRefCount(i->falseObj);
Jim_SetVariableStrWithStr(i, JIM_LIBPATH, TCL_LIBRARY);
Jim_SetVariableStrWithStr(i, JIM_INTERACTIVE, "0");
Jim_SetVariableStrWithStr(i, "tcl_platform(engine)", "Jim");
Jim_SetVariableStrWithStr(i, "tcl_platform(os)", TCL_PLATFORM_OS);
Jim_SetVariableStrWithStr(i, "tcl_platform(platform)", TCL_PLATFORM_PLATFORM);
Jim_SetVariableStrWithStr(i, "tcl_platform(pathSeparator)", TCL_PLATFORM_PATH_SEPARATOR);
Jim_SetVariableStrWithStr(i, "tcl_platform(byteOrder)", Jim_IsBigEndian() ? "bigEndian" : "littleEndian");
Jim_SetVariableStrWithStr(i, "tcl_platform(threaded)", "0");
Jim_SetVariableStrWithStr(i, "tcl_platform(bootstrap)", "0");
Jim_SetVariableStr(i, "tcl_platform(pointerSize)", Jim_NewIntObj(i, sizeof(void *)));
Jim_SetVariableStr(i, "tcl_platform(wordSize)", Jim_NewIntObj(i, sizeof(jim_wide)));
return i;
}{ ... }
void Jim_FreeInterp(Jim_Interp *i)
{
Jim_CallFrame *cf, *cfx;
Jim_Obj *objPtr, *nextObjPtr;
i->quitting = 1;
for (cf = i->framePtr; cf; cf = cfx) {
JimInvokeDefer(i, JIM_OK);
cfx = cf->parent;
JimFreeCallFrame(i, cf, JIM_FCF_FULL);
}for (cf = i->framePtr; cf; cf = cfx) { ... }
Jim_DecrRefCount(i, i->emptyObj);
Jim_DecrRefCount(i, i->trueObj);
Jim_DecrRefCount(i, i->falseObj);
Jim_DecrRefCount(i, i->result);
Jim_DecrRefCount(i, i->stackTrace);
Jim_DecrRefCount(i, i->errorProc);
Jim_DecrRefCount(i, i->unknown);
Jim_DecrRefCount(i, i->defer);
Jim_DecrRefCount(i, i->errorFileNameObj);
Jim_DecrRefCount(i, i->currentScriptObj);
Jim_DecrRefCount(i, i->nullScriptObj);
Jim_InterpIncrProcEpoch(i);
Jim_FreeHashTable(&i->commands);
#ifdef JIM_REFERENCES
Jim_FreeHashTable(&i->references);
#endif
Jim_FreeHashTable(&i->packages);
Jim_Free(i->prngState);
Jim_FreeHashTable(&i->assocData);
if (i->traceCmdObj) {
Jim_DecrRefCount(i, i->traceCmdObj);
}if (i->traceCmdObj) { ... }
/* ... */
#ifdef JIM_MAINTAINER
if (i->liveList != NULL) {
objPtr = i->liveList;
printf("\n-------------------------------------\n");
printf("Objects still in the free list:\n");
while (objPtr) {
const char *type = objPtr->typePtr ? objPtr->typePtr->name : "string";
Jim_String(objPtr);
if (objPtr->bytes && strlen(objPtr->bytes) > 20) {
printf("%p (%d) %-10s: '%.20s...'\n",
(void *)objPtr, objPtr->refCount, type, objPtr->bytes);
}if (objPtr->bytes && strlen(objPtr->bytes) > 20) { ... }
else {
printf("%p (%d) %-10s: '%s'\n",
(void *)objPtr, objPtr->refCount, type, objPtr->bytes ? objPtr->bytes : "(null)");
}else { ... }
if (objPtr->typePtr == &sourceObjType) {
printf("FILE %s LINE %d\n",
Jim_String(objPtr->internalRep.sourceValue.fileNameObj),
objPtr->internalRep.sourceValue.lineNumber);
}if (objPtr->typePtr == &sourceObjType) { ... }
objPtr = objPtr->nextObjPtr;
}while (objPtr) { ... }
printf("-------------------------------------\n\n");
JimPanic((1, "Live list non empty freeing the interpreter! Leak?"));
}if (i->liveList != NULL) { ... }
/* ... */#endif
objPtr = i->freeList;
while (objPtr) {
nextObjPtr = objPtr->nextObjPtr;
Jim_Free(objPtr);
objPtr = nextObjPtr;
}while (objPtr) { ... }
for (cf = i->freeFramesList; cf; cf = cfx) {
cfx = cf->next;
if (cf->vars.table)
Jim_FreeHashTable(&cf->vars);
Jim_Free(cf);
}for (cf = i->freeFramesList; cf; cf = cfx) { ... }
Jim_Free(i);
}{ ... }
/* ... */
Jim_CallFrame *Jim_GetCallFrameByLevel(Jim_Interp *interp, Jim_Obj *levelObjPtr)
{
long level;
const char *str;
Jim_CallFrame *framePtr;
if (levelObjPtr) {
str = Jim_String(levelObjPtr);
if (str[0] == '#') {
char *endptr;
level = jim_strtol(str + 1, &endptr);
if (str[1] == '\0' || endptr[0] != '\0') {
level = -1;
}if (str[1] == '\0' || endptr[0] != '\0') { ... }
}if (str[0] == '#') { ... }
else {
if (Jim_GetLong(interp, levelObjPtr, &level) != JIM_OK || level < 0) {
level = -1;
}if (Jim_GetLong(interp, levelObjPtr, &level) != JIM_OK || level < 0) { ... }
else {
level = interp->framePtr->level - level;
}else { ... }
}else { ... }
}if (levelObjPtr) { ... }
else {
str = "1";
level = interp->framePtr->level - 1;
}else { ... }
if (level == 0) {
return interp->topFramePtr;
}if (level == 0) { ... }
if (level > 0) {
for (framePtr = interp->framePtr; framePtr; framePtr = framePtr->parent) {
if (framePtr->level == level) {
return framePtr;
}if (framePtr->level == level) { ... }
}for (framePtr = interp->framePtr; framePtr; framePtr = framePtr->parent) { ... }
}if (level > 0) { ... }
Jim_SetResultFormatted(interp, "bad level \"%s\"", str);
return NULL;
}{ ... }
/* ... */
static Jim_CallFrame *JimGetCallFrameByInteger(Jim_Interp *interp, Jim_Obj *levelObjPtr)
{
long level;
Jim_CallFrame *framePtr;
if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) {
if (level <= 0) {
level = interp->framePtr->level + level;
}if (level <= 0) { ... }
if (level == 0) {
return interp->topFramePtr;
}if (level == 0) { ... }
for (framePtr = interp->framePtr; framePtr; framePtr = framePtr->parent) {
if (framePtr->level == level) {
return framePtr;
}if (framePtr->level == level) { ... }
}for (framePtr = interp->framePtr; framePtr; framePtr = framePtr->parent) { ... }
}if (Jim_GetLong(interp, levelObjPtr, &level) == JIM_OK) { ... }
Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
return NULL;
}{ ... }
static void JimResetStackTrace(Jim_Interp *interp)
{
Jim_DecrRefCount(interp, interp->stackTrace);
interp->stackTrace = Jim_NewListObj(interp, NULL, 0);
Jim_IncrRefCount(interp->stackTrace);
}{ ... }
static void JimSetStackTrace(Jim_Interp *interp, Jim_Obj *stackTraceObj)
{
int len;
Jim_IncrRefCount(stackTraceObj);
Jim_DecrRefCount(interp, interp->stackTrace);
interp->stackTrace = stackTraceObj;
interp->errorFlag = 1;
/* ... */
len = Jim_ListLength(interp, interp->stackTrace);
if (len >= 3) {
if (Jim_Length(Jim_ListGetIndex(interp, interp->stackTrace, len - 2)) == 0) {
interp->addStackTrace = 1;
}if (Jim_Length(Jim_ListGetIndex(interp, interp->stackTrace, len - 2)) == 0) { ... }
}if (len >= 3) { ... }
}{ ... }
static void JimAppendStackTrace(Jim_Interp *interp, const char *procname,
Jim_Obj *fileNameObj, int linenr)
{
if (strcmp(procname, "unknown") == 0) {
procname = "";
}if (strcmp(procname, "unknown") == 0) { ... }
if (!*procname && !Jim_Length(fileNameObj)) {
return;
}if (!*procname && !Jim_Length(fileNameObj)) { ... }
if (Jim_IsShared(interp->stackTrace)) {
Jim_DecrRefCount(interp, interp->stackTrace);
interp->stackTrace = Jim_DuplicateObj(interp, interp->stackTrace);
Jim_IncrRefCount(interp->stackTrace);
}if (Jim_IsShared(interp->stackTrace)) { ... }
if (!*procname && Jim_Length(fileNameObj)) {
int len = Jim_ListLength(interp, interp->stackTrace);
if (len >= 3) {
Jim_Obj *objPtr = Jim_ListGetIndex(interp, interp->stackTrace, len - 3);
if (Jim_Length(objPtr)) {
objPtr = Jim_ListGetIndex(interp, interp->stackTrace, len - 2);
if (Jim_Length(objPtr) == 0) {
ListSetIndex(interp, interp->stackTrace, len - 2, fileNameObj, 0);
ListSetIndex(interp, interp->stackTrace, len - 1, Jim_NewIntObj(interp, linenr), 0);
return;
}if (Jim_Length(objPtr) == 0) { ... }
}if (Jim_Length(objPtr)) { ... }
}if (len >= 3) { ... }
}if (!*procname && Jim_Length(fileNameObj)) { ... }
Jim_ListAppendElement(interp, interp->stackTrace, Jim_NewStringObj(interp, procname, -1));
Jim_ListAppendElement(interp, interp->stackTrace, fileNameObj);
Jim_ListAppendElement(interp, interp->stackTrace, Jim_NewIntObj(interp, linenr));
}{ ... }
int Jim_SetAssocData(Jim_Interp *interp, const char *key, Jim_InterpDeleteProc * delProc,
void *data)
{
AssocDataValue *assocEntryPtr = (AssocDataValue *) Jim_Alloc(sizeof(AssocDataValue));
assocEntryPtr->delProc = delProc;
assocEntryPtr->data = data;
return Jim_AddHashEntry(&interp->assocData, key, assocEntryPtr);
}{ ... }
void *Jim_GetAssocData(Jim_Interp *interp, const char *key)
{
Jim_HashEntry *entryPtr = Jim_FindHashEntry(&interp->assocData, key);
if (entryPtr != NULL) {
AssocDataValue *assocEntryPtr = Jim_GetHashEntryVal(entryPtr);
return assocEntryPtr->data;
}if (entryPtr != NULL) { ... }
return NULL;
}{ ... }
int Jim_DeleteAssocData(Jim_Interp *interp, const char *key)
{
return Jim_DeleteHashEntry(&interp->assocData, key);
}{ ... }
int Jim_GetExitCode(Jim_Interp *interp)
{
return interp->exitCode;
}{ ... }
/* ... */
static void UpdateStringOfInt(struct Jim_Obj *objPtr);
static int SetIntFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags);
static const Jim_ObjType intObjType = {
"int",
NULL,
NULL,
UpdateStringOfInt,
JIM_TYPE_NONE,
...};
/* ... */
static const Jim_ObjType coercedDoubleObjType = {
"coerced-double",
NULL,
NULL,
UpdateStringOfInt,
JIM_TYPE_NONE,
...};
static void UpdateStringOfInt(struct Jim_Obj *objPtr)
{
char buf[JIM_INTEGER_SPACE + 1];
jim_wide wideValue = JimWideValue(objPtr);
int pos = 0;
if (wideValue == 0) {
buf[pos++] = '0';
}if (wideValue == 0) { ... }
else {
char tmp[JIM_INTEGER_SPACE];
int num = 0;
int i;
if (wideValue < 0) {
buf[pos++] = '-';
i = wideValue % 10;
/* ... */
tmp[num++] = (i > 0) ? (10 - i) : -i;
wideValue /= -10;
}if (wideValue < 0) { ... }
while (wideValue) {
tmp[num++] = wideValue % 10;
wideValue /= 10;
}while (wideValue) { ... }
for (i = 0; i < num; i++) {
buf[pos++] = '0' + tmp[num - i - 1];
}for (i = 0; i < num; i++) { ... }
}else { ... }
buf[pos] = 0;
JimSetStringBytes(objPtr, buf);
}{ ... }
static int SetIntFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
{
jim_wide wideValue;
const char *str;
if (objPtr->typePtr == &coercedDoubleObjType) {
objPtr->typePtr = &intObjType;
return JIM_OK;
}if (objPtr->typePtr == &coercedDoubleObjType) { ... }
str = Jim_String(objPtr);
if (Jim_StringToWide(str, &wideValue, 0) != JIM_OK) {
if (flags & JIM_ERRMSG) {
Jim_SetResultFormatted(interp, "expected integer but got \"%#s\"", objPtr);
}if (flags & JIM_ERRMSG) { ... }
return JIM_ERR;
}if (Jim_StringToWide(str, &wideValue, 0) != JIM_OK) { ... }
if ((wideValue == JIM_WIDE_MIN || wideValue == JIM_WIDE_MAX) && errno == ERANGE) {
Jim_SetResultString(interp, "Integer value too big to be represented", -1);
return JIM_ERR;
}if ((wideValue == JIM_WIDE_MIN || wideValue == JIM_WIDE_MAX) && errno == ERANGE) { ... }
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &intObjType;
objPtr->internalRep.wideValue = wideValue;
return JIM_OK;
}{ ... }
#ifdef JIM_OPTIMIZATION
static int JimIsWide(Jim_Obj *objPtr)
{
return objPtr->typePtr == &intObjType;
}{ ... }
/* ... */#endif
int Jim_GetWide(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
{
if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
return JIM_ERR;
*widePtr = JimWideValue(objPtr);
return JIM_OK;
}{ ... }
int Jim_GetWideExpr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
{
int ret = JIM_OK;
if (objPtr->typePtr == &intObjType) {
*widePtr = JimWideValue(objPtr);
}if (objPtr->typePtr == &intObjType) { ... }
else {
/* ... */
JimPanic((interp->safeexpr, "interp->safeexpr is set"));
interp->safeexpr++;
ret = Jim_EvalExpression(interp, objPtr);
interp->safeexpr--;
if (ret == JIM_OK) {
ret = Jim_GetWide(interp, Jim_GetResult(interp), widePtr);
}if (ret == JIM_OK) { ... }
if (ret != JIM_OK) {
/* ... */
Jim_SetResultFormatted(interp, "expected integer expression but got \"%#s\"", objPtr);
}if (ret != JIM_OK) { ... }
}else { ... }
return ret;
}{ ... }
static int JimGetWideNoErr(Jim_Interp *interp, Jim_Obj *objPtr, jim_wide * widePtr)
{
if (objPtr->typePtr != &intObjType && SetIntFromAny(interp, objPtr, JIM_NONE) == JIM_ERR)
return JIM_ERR;
*widePtr = JimWideValue(objPtr);
return JIM_OK;
}{ ... }
int Jim_GetLong(Jim_Interp *interp, Jim_Obj *objPtr, long *longPtr)
{
jim_wide wideValue;
int retval;
retval = Jim_GetWide(interp, objPtr, &wideValue);
if (retval == JIM_OK) {
*longPtr = (long)wideValue;
return JIM_OK;
}if (retval == JIM_OK) { ... }
return JIM_ERR;
}{ ... }
Jim_Obj *Jim_NewIntObj(Jim_Interp *interp, jim_wide wideValue)
{
Jim_Obj *objPtr;
objPtr = Jim_NewObj(interp);
objPtr->typePtr = &intObjType;
objPtr->bytes = NULL;
objPtr->internalRep.wideValue = wideValue;
return objPtr;
}{ ... }
/* ... */
#define JIM_DOUBLE_SPACE 30
static void UpdateStringOfDouble(struct Jim_Obj *objPtr);
static int SetDoubleFromAny(Jim_Interp *interp, Jim_Obj *objPtr);
static const Jim_ObjType doubleObjType = {
"double",
NULL,
NULL,
UpdateStringOfDouble,
JIM_TYPE_NONE,
...};
#ifndef HAVE_ISNAN
#undef isnan
#define isnan(X) ((X) != (X))
/* ... */#endif
#ifndef HAVE_ISINF
#undef isinf
#define isinf(X) (1.0 / (X) == 0.0)
/* ... */#endif
static void UpdateStringOfDouble(struct Jim_Obj *objPtr)
{
double value = objPtr->internalRep.doubleValue;
if (isnan(value)) {
JimSetStringBytes(objPtr, "NaN");
return;
}if (isnan(value)) { ... }
if (isinf(value)) {
if (value < 0) {
JimSetStringBytes(objPtr, "-Inf");
}if (value < 0) { ... }
else {
JimSetStringBytes(objPtr, "Inf");
}else { ... }
return;
}if (isinf(value)) { ... }
{
char buf[JIM_DOUBLE_SPACE + 1];
int i;
int len = sprintf(buf, "%.12g", value);
for (i = 0; i < len; i++) {
if (buf[i] == '.' || buf[i] == 'e') {
#if defined(JIM_SPRINTF_DOUBLE_NEEDS_FIX)
/* ... */
char *e = strchr(buf, 'e');
if (e && (e[1] == '-' || e[1] == '+') && e[2] == '0') {
e += 2;
memmove(e, e + 1, len - (e - buf));
}if (e && (e[1] == '-' || e[1] == '+') && e[2] == '0') { ... }
/* ... */#endif
break;
}if (buf[i] == '.' || buf[i] == 'e') { ... }
}for (i = 0; i < len; i++) { ... }
if (buf[i] == '\0') {
buf[i++] = '.';
buf[i++] = '0';
buf[i] = '\0';
}if (buf[i] == '\0') { ... }
JimSetStringBytes(objPtr, buf);
...}
}{ ... }
static int SetDoubleFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{
double doubleValue;
jim_wide wideValue;
const char *str;
#ifdef HAVE_LONG_LONG
#define MIN_INT_IN_DOUBLE -(1LL << 53)
#define MAX_INT_IN_DOUBLE -(MIN_INT_IN_DOUBLE + 1)
if (objPtr->typePtr == &intObjType
&& JimWideValue(objPtr) >= MIN_INT_IN_DOUBLE
&& JimWideValue(objPtr) <= MAX_INT_IN_DOUBLE) {
objPtr->typePtr = &coercedDoubleObjType;
return JIM_OK;
}if (objPtr->typePtr == &intObjType && JimWideValue(objPtr) >= MIN_INT_IN_DOUBLE && JimWideValue(objPtr) <= MAX_INT_IN_DOUBLE) { ... }
/* ... */#endif
/* ... */
str = Jim_String(objPtr);
if (Jim_StringToWide(str, &wideValue, 10) == JIM_OK) {
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &coercedDoubleObjType;
objPtr->internalRep.wideValue = wideValue;
return JIM_OK;
}if (Jim_StringToWide(str, &wideValue, 10) == JIM_OK) { ... }
else {
if (Jim_StringToDouble(str, &doubleValue) != JIM_OK) {
Jim_SetResultFormatted(interp, "expected floating-point number but got \"%#s\"", objPtr);
return JIM_ERR;
}if (Jim_StringToDouble(str, &doubleValue) != JIM_OK) { ... }
Jim_FreeIntRep(interp, objPtr);
}else { ... }
objPtr->typePtr = &doubleObjType;
objPtr->internalRep.doubleValue = doubleValue;
return JIM_OK;
}{ ... }
int Jim_GetDouble(Jim_Interp *interp, Jim_Obj *objPtr, double *doublePtr)
{
if (objPtr->typePtr == &coercedDoubleObjType) {
*doublePtr = JimWideValue(objPtr);
return JIM_OK;
}if (objPtr->typePtr == &coercedDoubleObjType) { ... }
if (objPtr->typePtr != &doubleObjType && SetDoubleFromAny(interp, objPtr) == JIM_ERR)
return JIM_ERR;
if (objPtr->typePtr == &coercedDoubleObjType) {
*doublePtr = JimWideValue(objPtr);
}if (objPtr->typePtr == &coercedDoubleObjType) { ... }
else {
*doublePtr = objPtr->internalRep.doubleValue;
}else { ... }
return JIM_OK;
}{ ... }
Jim_Obj *Jim_NewDoubleObj(Jim_Interp *interp, double doubleValue)
{
Jim_Obj *objPtr;
objPtr = Jim_NewObj(interp);
objPtr->typePtr = &doubleObjType;
objPtr->bytes = NULL;
objPtr->internalRep.doubleValue = doubleValue;
return objPtr;
}{ ... }
/* ... */
static int SetBooleanFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags);
int Jim_GetBoolean(Jim_Interp *interp, Jim_Obj *objPtr, int * booleanPtr)
{
if (objPtr->typePtr != &intObjType && SetBooleanFromAny(interp, objPtr, JIM_ERRMSG) == JIM_ERR)
return JIM_ERR;
*booleanPtr = (int) JimWideValue(objPtr);
return JIM_OK;
}{ ... }
static const char * const jim_true_false_strings[8] = {
"1", "true", "yes", "on",
"0", "false", "no", "off"
...};
static const int jim_true_false_lens[8] = {
1, 4, 3, 2,
1, 5, 2, 3,
...};
static int SetBooleanFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
{
int index = Jim_FindByName(Jim_String(objPtr), jim_true_false_strings,
sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings));
if (index < 0) {
if (flags & JIM_ERRMSG) {
Jim_SetResultFormatted(interp, "expected boolean but got \"%#s\"", objPtr);
}if (flags & JIM_ERRMSG) { ... }
return JIM_ERR;
}if (index < 0) { ... }
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &intObjType;
objPtr->internalRep.wideValue = index < 4 ? 1 : 0;
return JIM_OK;
}{ ... }
/* ... */
static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec);
static void ListAppendElement(Jim_Obj *listPtr, Jim_Obj *objPtr);
static void FreeListInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupListInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static void UpdateStringOfList(struct Jim_Obj *objPtr);
static int SetListFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
/* ... */
static const Jim_ObjType listObjType = {
"list",
FreeListInternalRep,
DupListInternalRep,
UpdateStringOfList,
JIM_TYPE_NONE,
...};
void FreeListInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
int i;
for (i = 0; i < objPtr->internalRep.listValue.len; i++) {
Jim_DecrRefCount(interp, objPtr->internalRep.listValue.ele[i]);
}for (i = 0; i < objPtr->internalRep.listValue.len; i++) { ... }
Jim_Free(objPtr->internalRep.listValue.ele);
}{ ... }
void DupListInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
int i;
JIM_NOTUSED(interp);
dupPtr->internalRep.listValue.len = srcPtr->internalRep.listValue.len;
dupPtr->internalRep.listValue.maxLen = srcPtr->internalRep.listValue.maxLen;
dupPtr->internalRep.listValue.ele =
Jim_Alloc(sizeof(Jim_Obj *) * srcPtr->internalRep.listValue.maxLen);
memcpy(dupPtr->internalRep.listValue.ele, srcPtr->internalRep.listValue.ele,
sizeof(Jim_Obj *) * srcPtr->internalRep.listValue.len);
for (i = 0; i < dupPtr->internalRep.listValue.len; i++) {
Jim_IncrRefCount(dupPtr->internalRep.listValue.ele[i]);
}for (i = 0; i < dupPtr->internalRep.listValue.len; i++) { ... }
dupPtr->typePtr = &listObjType;
}{ ... }
/* ... */
#define JIM_ELESTR_SIMPLE 0
#define JIM_ELESTR_BRACE 1
#define JIM_ELESTR_QUOTE 2
static unsigned char ListElementQuotingType(const char *s, int len)
{
int i, level, blevel, trySimple = 1;
if (len == 0)
return JIM_ELESTR_BRACE;
if (s[0] == '"' || s[0] == '{') {
trySimple = 0;
goto testbrace;
}if (s[0] == '"' || s[0] == '{') { ... }
for (i = 0; i < len; i++) {
switch (s[i]) {
case ' ':
case '$':
case '"':
case '[':
case ']':
case ';':
case '\\':
case '\r':
case '\n':
case '\t':
case '\f':
case '\v':
trySimple = 0;
case '\v':
case '{':
case '}':
goto testbrace;case '}':
}switch (s[i]) { ... }
}for (i = 0; i < len; i++) { ... }
return JIM_ELESTR_SIMPLE;
testbrace:
if (s[len - 1] == '\\')
return JIM_ELESTR_QUOTE;
level = 0;
blevel = 0;
for (i = 0; i < len; i++) {
switch (s[i]) {
case '{':
level++;
break;case '{':
case '}':
level--;
if (level < 0)
return JIM_ELESTR_QUOTE;
break;case '}':
case '[':
blevel++;
break;case '[':
case ']':
blevel--;
break;case ']':
case '\\':
if (s[i + 1] == '\n')
return JIM_ELESTR_QUOTE;
else if (s[i + 1] != '\0')
i++;
break;case '\\':
}switch (s[i]) { ... }
}for (i = 0; i < len; i++) { ... }
if (blevel < 0) {
return JIM_ELESTR_QUOTE;
}if (blevel < 0) { ... }
if (level == 0) {
if (!trySimple)
return JIM_ELESTR_BRACE;
for (i = 0; i < len; i++) {
switch (s[i]) {
case ' ':
case '$':
case '"':
case '[':
case ']':
case ';':
case '\\':
case '\r':
case '\n':
case '\t':
case '\f':
case '\v':
return JIM_ELESTR_BRACE;
break;case '\v':
}switch (s[i]) { ... }
}for (i = 0; i < len; i++) { ... }
return JIM_ELESTR_SIMPLE;
}if (level == 0) { ... }
return JIM_ELESTR_QUOTE;
}{ ... }
/* ... */
static int BackslashQuoteString(const char *s, int len, char *q)
{
char *p = q;
while (len--) {
switch (*s) {
case ' ':
case '$':
case '"':
case '[':
case ']':
case '{':
case '}':
case ';':
case '\\':
*p++ = '\\';
*p++ = *s++;
break;case '\\':
case '\n':
*p++ = '\\';
*p++ = 'n';
s++;
break;case '\n':
case '\r':
*p++ = '\\';
*p++ = 'r';
s++;
break;case '\r':
case '\t':
*p++ = '\\';
*p++ = 't';
s++;
break;case '\t':
case '\f':
*p++ = '\\';
*p++ = 'f';
s++;
break;case '\f':
case '\v':
*p++ = '\\';
*p++ = 'v';
s++;
break;case '\v':
default:
*p++ = *s++;
break;default
}switch (*s) { ... }
}while (len--) { ... }
*p = '\0';
return p - q;
}{ ... }
static void JimMakeListStringRep(Jim_Obj *objPtr, Jim_Obj **objv, int objc)
{
#define STATIC_QUOTING_LEN 32
int i, bufLen, realLength;
const char *strRep;
char *p;
unsigned char *quotingType, staticQuoting[STATIC_QUOTING_LEN];
if (objc > STATIC_QUOTING_LEN) {
quotingType = Jim_Alloc(objc);
}if (objc > STATIC_QUOTING_LEN) { ... }
else {
quotingType = staticQuoting;
}else { ... }
bufLen = 0;
for (i = 0; i < objc; i++) {
int len;
strRep = Jim_GetString(objv[i], &len);
quotingType[i] = ListElementQuotingType(strRep, len);
switch (quotingType[i]) {
case JIM_ELESTR_SIMPLE:
if (i != 0 || strRep[0] != '#') {
bufLen += len;
break;
}if (i != 0 || strRep[0] != '#') { ... }
quotingType[i] = JIM_ELESTR_BRACE;
case JIM_ELESTR_SIMPLE:
case JIM_ELESTR_BRACE:
bufLen += len + 2;
break;case JIM_ELESTR_BRACE:
case JIM_ELESTR_QUOTE:
bufLen += len * 2;
break;case JIM_ELESTR_QUOTE:
}switch (quotingType[i]) { ... }
bufLen++;
}for (i = 0; i < objc; i++) { ... }
bufLen++;
p = objPtr->bytes = Jim_Alloc(bufLen + 1);
realLength = 0;
for (i = 0; i < objc; i++) {
int len, qlen;
strRep = Jim_GetString(objv[i], &len);
switch (quotingType[i]) {
case JIM_ELESTR_SIMPLE:
memcpy(p, strRep, len);
p += len;
realLength += len;
break;case JIM_ELESTR_SIMPLE:
case JIM_ELESTR_BRACE:
*p++ = '{';
memcpy(p, strRep, len);
p += len;
*p++ = '}';
realLength += len + 2;
break;case JIM_ELESTR_BRACE:
case JIM_ELESTR_QUOTE:
if (i == 0 && strRep[0] == '#') {
*p++ = '\\';
realLength++;
}if (i == 0 && strRep[0] == '#') { ... }
qlen = BackslashQuoteString(strRep, len, p);
p += qlen;
realLength += qlen;
break;case JIM_ELESTR_QUOTE:
}switch (quotingType[i]) { ... }
if (i + 1 != objc) {
*p++ = ' ';
realLength++;
}if (i + 1 != objc) { ... }
}for (i = 0; i < objc; i++) { ... }
*p = '\0';
objPtr->length = realLength;
if (quotingType != staticQuoting) {
Jim_Free(quotingType);
}if (quotingType != staticQuoting) { ... }
}{ ... }
static void UpdateStringOfList(struct Jim_Obj *objPtr)
{
JimMakeListStringRep(objPtr, objPtr->internalRep.listValue.ele, objPtr->internalRep.listValue.len);
}{ ... }
static int SetListFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
{
struct JimParserCtx parser;
const char *str;
int strLen;
Jim_Obj *fileNameObj;
int linenr;
if (objPtr->typePtr == &listObjType) {
return JIM_OK;
}if (objPtr->typePtr == &listObjType) { ... }
if (Jim_IsDict(objPtr) && objPtr->bytes == NULL) {
Jim_Dict *dict = objPtr->internalRep.dictValue;
/* ... */
objPtr->typePtr = &listObjType;
objPtr->internalRep.listValue.len = dict->len;
objPtr->internalRep.listValue.maxLen = dict->maxLen;
objPtr->internalRep.listValue.ele = dict->table;
Jim_Free(dict->ht);
Jim_Free(dict);
return JIM_OK;
}if (Jim_IsDict(objPtr) && objPtr->bytes == NULL) { ... }
if (objPtr->typePtr == &sourceObjType) {
fileNameObj = objPtr->internalRep.sourceValue.fileNameObj;
linenr = objPtr->internalRep.sourceValue.lineNumber;
}if (objPtr->typePtr == &sourceObjType) { ... }
else {
fileNameObj = interp->emptyObj;
linenr = 1;
}else { ... }
Jim_IncrRefCount(fileNameObj);
str = Jim_GetString(objPtr, &strLen);
/* ... */
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &listObjType;
objPtr->internalRep.listValue.len = 0;
objPtr->internalRep.listValue.maxLen = 0;
objPtr->internalRep.listValue.ele = NULL;
if (strLen) {
JimParserInit(&parser, str, strLen, linenr);
while (!parser.eof) {
Jim_Obj *elementPtr;
JimParseList(&parser);
if (parser.tt != JIM_TT_STR && parser.tt != JIM_TT_ESC)
continue;
elementPtr = JimParserGetTokenObj(interp, &parser);
JimSetSourceInfo(interp, elementPtr, fileNameObj, parser.tline);
ListAppendElement(objPtr, elementPtr);
}while (!parser.eof) { ... }
}if (strLen) { ... }
Jim_DecrRefCount(interp, fileNameObj);
return JIM_OK;
}{ ... }
Jim_Obj *Jim_NewListObj(Jim_Interp *interp, Jim_Obj *const *elements, int len)
{
Jim_Obj *objPtr;
objPtr = Jim_NewObj(interp);
objPtr->typePtr = &listObjType;
objPtr->bytes = NULL;
objPtr->internalRep.listValue.ele = NULL;
objPtr->internalRep.listValue.len = 0;
objPtr->internalRep.listValue.maxLen = 0;
if (len) {
ListInsertElements(objPtr, 0, len, elements);
}if (len) { ... }
return objPtr;
}{ ... }
/* ... */
static void JimListGetElements(Jim_Interp *interp, Jim_Obj *listObj, int *listLen,
Jim_Obj ***listVec)
{
*listLen = Jim_ListLength(interp, listObj);
*listVec = listObj->internalRep.listValue.ele;
}{ ... }
static int JimSign(jim_wide w)
{
if (w == 0) {
return 0;
}if (w == 0) { ... }
else if (w < 0) {
return -1;
}else if (w < 0) { ... }
return 1;
}{ ... }
struct lsort_info {
jmp_buf jmpbuf;
Jim_Obj *command;
Jim_Interp *interp;
enum {
JIM_LSORT_ASCII,
JIM_LSORT_NOCASE,
JIM_LSORT_INTEGER,
JIM_LSORT_REAL,
JIM_LSORT_COMMAND
...} type;
int order;
Jim_Obj **indexv;
int indexc;
int unique;
int (*subfn)(Jim_Obj **, Jim_Obj **);
...};
static struct lsort_info *sort_info;
static int ListSortIndexHelper(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
{
Jim_Obj *lObj, *rObj;
if (Jim_ListIndices(sort_info->interp, *lhsObj, sort_info->indexv, sort_info->indexc, &lObj, JIM_ERRMSG) != JIM_OK ||
Jim_ListIndices(sort_info->interp, *rhsObj, sort_info->indexv, sort_info->indexc, &rObj, JIM_ERRMSG) != JIM_OK) {
longjmp(sort_info->jmpbuf, JIM_ERR);
}if (Jim_ListIndices(sort_info->interp, *lhsObj, sort_info->indexv, sort_info->indexc, &lObj, JIM_ERRMSG) != JIM_OK || Jim_ListIndices(sort_info->interp, *rhsObj, sort_info->indexv, sort_info->indexc, &rObj, JIM_ERRMSG) != JIM_OK) { ... }
return sort_info->subfn(&lObj, &rObj);
}{ ... }
static int ListSortString(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
{
return Jim_StringCompareObj(sort_info->interp, *lhsObj, *rhsObj, 0) * sort_info->order;
}{ ... }
static int ListSortStringNoCase(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
{
return Jim_StringCompareObj(sort_info->interp, *lhsObj, *rhsObj, 1) * sort_info->order;
}{ ... }
static int ListSortInteger(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
{
jim_wide lhs = 0, rhs = 0;
if (Jim_GetWide(sort_info->interp, *lhsObj, &lhs) != JIM_OK ||
Jim_GetWide(sort_info->interp, *rhsObj, &rhs) != JIM_OK) {
longjmp(sort_info->jmpbuf, JIM_ERR);
}if (Jim_GetWide(sort_info->interp, *lhsObj, &lhs) != JIM_OK || Jim_GetWide(sort_info->interp, *rhsObj, &rhs) != JIM_OK) { ... }
return JimSign(lhs - rhs) * sort_info->order;
}{ ... }
static int ListSortReal(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
{
double lhs = 0, rhs = 0;
if (Jim_GetDouble(sort_info->interp, *lhsObj, &lhs) != JIM_OK ||
Jim_GetDouble(sort_info->interp, *rhsObj, &rhs) != JIM_OK) {
longjmp(sort_info->jmpbuf, JIM_ERR);
}if (Jim_GetDouble(sort_info->interp, *lhsObj, &lhs) != JIM_OK || Jim_GetDouble(sort_info->interp, *rhsObj, &rhs) != JIM_OK) { ... }
if (lhs == rhs) {
return 0;
}if (lhs == rhs) { ... }
if (lhs > rhs) {
return sort_info->order;
}if (lhs > rhs) { ... }
return -sort_info->order;
}{ ... }
static int ListSortCommand(Jim_Obj **lhsObj, Jim_Obj **rhsObj)
{
Jim_Obj *compare_script;
int rc;
jim_wide ret = 0;
compare_script = Jim_DuplicateObj(sort_info->interp, sort_info->command);
Jim_ListAppendElement(sort_info->interp, compare_script, *lhsObj);
Jim_ListAppendElement(sort_info->interp, compare_script, *rhsObj);
rc = Jim_EvalObj(sort_info->interp, compare_script);
if (rc != JIM_OK || Jim_GetWide(sort_info->interp, Jim_GetResult(sort_info->interp), &ret) != JIM_OK) {
longjmp(sort_info->jmpbuf, rc);
}if (rc != JIM_OK || Jim_GetWide(sort_info->interp, Jim_GetResult(sort_info->interp), &ret) != JIM_OK) { ... }
return JimSign(ret) * sort_info->order;
}{ ... }
/* ... */
static void ListRemoveDuplicates(Jim_Obj *listObjPtr, int (*comp)(Jim_Obj **lhs, Jim_Obj **rhs))
{
int src;
int dst = 0;
Jim_Obj **ele = listObjPtr->internalRep.listValue.ele;
for (src = 1; src < listObjPtr->internalRep.listValue.len; src++) {
if (comp(&ele[dst], &ele[src]) == 0) {
Jim_DecrRefCount(sort_info->interp, ele[dst]);
}if (comp(&ele[dst], &ele[src]) == 0) { ... }
else {
dst++;
}else { ... }
ele[dst] = ele[src];
}for (src = 1; src < listObjPtr->internalRep.listValue.len; src++) { ... }
dst++;
if (dst < listObjPtr->internalRep.listValue.len) {
ele[dst] = ele[src];
}if (dst < listObjPtr->internalRep.listValue.len) { ... }
listObjPtr->internalRep.listValue.len = dst;
}{ ... }
static int ListSortElements(Jim_Interp *interp, Jim_Obj *listObjPtr, struct lsort_info *info)
{
struct lsort_info *prev_info;
typedef int (qsort_comparator) (const void *, const void *);
int (*fn) (Jim_Obj **, Jim_Obj **);
Jim_Obj **vector;
int len;
int rc;
JimPanic((Jim_IsShared(listObjPtr), "ListSortElements called with shared object"));
SetListFromAny(interp, listObjPtr);
prev_info = sort_info;
sort_info = info;
vector = listObjPtr->internalRep.listValue.ele;
len = listObjPtr->internalRep.listValue.len;
switch (info->type) {
case JIM_LSORT_ASCII:
fn = ListSortString;
break;case JIM_LSORT_ASCII:
case JIM_LSORT_NOCASE:
fn = ListSortStringNoCase;
break;case JIM_LSORT_NOCASE:
case JIM_LSORT_INTEGER:
fn = ListSortInteger;
break;case JIM_LSORT_INTEGER:
case JIM_LSORT_REAL:
fn = ListSortReal;
break;case JIM_LSORT_REAL:
case JIM_LSORT_COMMAND:
fn = ListSortCommand;
break;case JIM_LSORT_COMMAND:
default:
fn = NULL;
JimPanic((1, "ListSort called with invalid sort type"));
return -1; default
}switch (info->type) { ... }
if (info->indexc) {
info->subfn = fn;
fn = ListSortIndexHelper;
}if (info->indexc) { ... }
if ((rc = setjmp(info->jmpbuf)) == 0) {
qsort(vector, len, sizeof(Jim_Obj *), (qsort_comparator *) fn);
if (info->unique && len > 1) {
ListRemoveDuplicates(listObjPtr, fn);
}if (info->unique && len > 1) { ... }
Jim_InvalidateStringRep(listObjPtr);
}if ((rc = setjmp(info->jmpbuf)) == 0) { ... }
sort_info = prev_info;
return rc;
}{ ... }
static void ListEnsureLength(Jim_Obj *listPtr, int idx)
{
assert(idx >= 0);
if (idx >= listPtr->internalRep.listValue.maxLen) {
if (idx < 4) {
idx = 4;
}if (idx < 4) { ... }
listPtr->internalRep.listValue.ele = Jim_Realloc(listPtr->internalRep.listValue.ele,
sizeof(Jim_Obj *) * idx);
listPtr->internalRep.listValue.maxLen = idx;
}if (idx >= listPtr->internalRep.listValue.maxLen) { ... }
}{ ... }
/* ... */
static void ListInsertElements(Jim_Obj *listPtr, int idx, int elemc, Jim_Obj *const *elemVec)
{
int currentLen = listPtr->internalRep.listValue.len;
int requiredLen = currentLen + elemc;
int i;
Jim_Obj **point;
if (requiredLen > listPtr->internalRep.listValue.maxLen) {
if (currentLen) {
requiredLen *= 2;
}if (currentLen) { ... }
ListEnsureLength(listPtr, requiredLen);
}if (requiredLen > listPtr->internalRep.listValue.maxLen) { ... }
if (idx < 0) {
idx = currentLen;
}if (idx < 0) { ... }
point = listPtr->internalRep.listValue.ele + idx;
memmove(point + elemc, point, (currentLen - idx) * sizeof(Jim_Obj *));
for (i = 0; i < elemc; ++i) {
point[i] = elemVec[i];
Jim_IncrRefCount(point[i]);
}for (i = 0; i < elemc; ++i) { ... }
listPtr->internalRep.listValue.len += elemc;
}{ ... }
/* ... */
static void ListAppendElement(Jim_Obj *listPtr, Jim_Obj *objPtr)
{
ListInsertElements(listPtr, -1, 1, &objPtr);
}{ ... }
/* ... */
static void ListAppendList(Jim_Obj *listPtr, Jim_Obj *appendListPtr)
{
ListInsertElements(listPtr, -1,
appendListPtr->internalRep.listValue.len, appendListPtr->internalRep.listValue.ele);
}{ ... }
void Jim_ListAppendElement(Jim_Interp *interp, Jim_Obj *listPtr, Jim_Obj *objPtr)
{
JimPanic((Jim_IsShared(listPtr), "Jim_ListAppendElement called with shared object"));
SetListFromAny(interp, listPtr);
Jim_InvalidateStringRep(listPtr);
ListAppendElement(listPtr, objPtr);
}{ ... }
void Jim_ListAppendList(Jim_Interp *interp, Jim_Obj *listPtr, Jim_Obj *appendListPtr)
{
JimPanic((Jim_IsShared(listPtr), "Jim_ListAppendList called with shared object"));
SetListFromAny(interp, listPtr);
SetListFromAny(interp, appendListPtr);
Jim_InvalidateStringRep(listPtr);
ListAppendList(listPtr, appendListPtr);
}{ ... }
int Jim_ListLength(Jim_Interp *interp, Jim_Obj *objPtr)
{
SetListFromAny(interp, objPtr);
return objPtr->internalRep.listValue.len;
}{ ... }
void Jim_ListInsertElements(Jim_Interp *interp, Jim_Obj *listPtr, int idx,
int objc, Jim_Obj *const *objVec)
{
JimPanic((Jim_IsShared(listPtr), "Jim_ListInsertElement called with shared object"));
SetListFromAny(interp, listPtr);
if (idx >= 0 && idx > listPtr->internalRep.listValue.len)
idx = listPtr->internalRep.listValue.len;
else if (idx < 0)
idx = 0;
Jim_InvalidateStringRep(listPtr);
ListInsertElements(listPtr, idx, objc, objVec);
}{ ... }
Jim_Obj *Jim_ListGetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx)
{
SetListFromAny(interp, listPtr);
if ((idx >= 0 && idx >= listPtr->internalRep.listValue.len) ||
(idx < 0 && (-idx - 1) >= listPtr->internalRep.listValue.len)) {
return NULL;
}if ((idx >= 0 && idx >= listPtr->internalRep.listValue.len) || (idx < 0 && (-idx - 1) >= listPtr->internalRep.listValue.len)) { ... }
if (idx < 0)
idx = listPtr->internalRep.listValue.len + idx;
return listPtr->internalRep.listValue.ele[idx];
}{ ... }
int Jim_ListIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx, Jim_Obj **objPtrPtr, int flags)
{
*objPtrPtr = Jim_ListGetIndex(interp, listPtr, idx);
if (*objPtrPtr == NULL) {
if (flags & JIM_ERRMSG) {
Jim_SetResultString(interp, "list index out of range", -1);
}if (flags & JIM_ERRMSG) { ... }
return JIM_ERR;
}if (*objPtrPtr == NULL) { ... }
return JIM_OK;
}{ ... }
/* ... */
static int Jim_ListIndices(Jim_Interp *interp, Jim_Obj *listPtr,
Jim_Obj *const *indexv, int indexc, Jim_Obj **resultObj, int flags)
{
int i;
int static_idxes[5];
int *idxes = static_idxes;
int ret = JIM_OK;
if (indexc > sizeof(static_idxes) / sizeof(*static_idxes)) {
idxes = Jim_Alloc(indexc * sizeof(*idxes));
}if (indexc > sizeof(static_idxes) / sizeof(*static_idxes)) { ... }
/* ... */
for (i = 0; i < indexc; i++) {
ret = Jim_GetIndex(interp, indexv[i], &idxes[i]);
if (ret != JIM_OK) {
goto err;
}if (ret != JIM_OK) { ... }
}for (i = 0; i < indexc; i++) { ... }
for (i = 0; i < indexc; i++) {
Jim_Obj *objPtr = Jim_ListGetIndex(interp, listPtr, idxes[i]);
if (!objPtr) {
if (flags & JIM_ERRMSG) {
if (idxes[i] < 0 || idxes[i] > Jim_ListLength(interp, listPtr)) {
Jim_SetResultFormatted(interp, "index \"%#s\" out of range", indexv[i]);
}if (idxes[i] < 0 || idxes[i] > Jim_ListLength(interp, listPtr)) { ... }
else {
Jim_SetResultFormatted(interp, "element %#s missing from sublist \"%#s\"", indexv[i], listPtr);
}else { ... }
}if (flags & JIM_ERRMSG) { ... }
return -1;
}if (!objPtr) { ... }
listPtr = objPtr;
}for (i = 0; i < indexc; i++) { ... }
*resultObj = listPtr;
err:
if (idxes != static_idxes)
Jim_Free(idxes);
return ret;
}{ ... }
static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx,
Jim_Obj *newObjPtr, int flags)
{
SetListFromAny(interp, listPtr);
if ((idx >= 0 && idx >= listPtr->internalRep.listValue.len) ||
(idx < 0 && (-idx - 1) >= listPtr->internalRep.listValue.len)) {
if (flags & JIM_ERRMSG) {
Jim_SetResultString(interp, "list index out of range", -1);
}if (flags & JIM_ERRMSG) { ... }
return JIM_ERR;
}if ((idx >= 0 && idx >= listPtr->internalRep.listValue.len) || (idx < 0 && (-idx - 1) >= listPtr->internalRep.listValue.len)) { ... }
if (idx < 0)
idx = listPtr->internalRep.listValue.len + idx;
Jim_DecrRefCount(interp, listPtr->internalRep.listValue.ele[idx]);
listPtr->internalRep.listValue.ele[idx] = newObjPtr;
Jim_IncrRefCount(newObjPtr);
return JIM_OK;
}{ ... }
/* ... */
int Jim_ListSetIndex(Jim_Interp *interp, Jim_Obj *varNamePtr,
Jim_Obj *const *indexv, int indexc, Jim_Obj *newObjPtr)
{
Jim_Obj *varObjPtr, *objPtr, *listObjPtr;
int shared, i, idx;
varObjPtr = objPtr = Jim_GetVariable(interp, varNamePtr, JIM_ERRMSG | JIM_UNSHARED);
if (objPtr == NULL)
return JIM_ERR;
if ((shared = Jim_IsShared(objPtr)))
varObjPtr = objPtr = Jim_DuplicateObj(interp, objPtr);
for (i = 0; i < indexc - 1; i++) {
listObjPtr = objPtr;
if (Jim_GetIndex(interp, indexv[i], &idx) != JIM_OK)
goto err;
objPtr = Jim_ListGetIndex(interp, listObjPtr, idx);
if (objPtr == NULL) {
Jim_SetResultFormatted(interp, "index \"%#s\" out of range", indexv[i]);
goto err;
}if (objPtr == NULL) { ... }
if (Jim_IsShared(objPtr)) {
objPtr = Jim_DuplicateObj(interp, objPtr);
ListSetIndex(interp, listObjPtr, idx, objPtr, JIM_NONE);
}if (Jim_IsShared(objPtr)) { ... }
Jim_InvalidateStringRep(listObjPtr);
}for (i = 0; i < indexc - 1; i++) { ... }
if (Jim_GetIndex(interp, indexv[indexc - 1], &idx) != JIM_OK)
goto err;
if (ListSetIndex(interp, objPtr, idx, newObjPtr, JIM_ERRMSG) == JIM_ERR)
goto err;
Jim_InvalidateStringRep(objPtr);
Jim_InvalidateStringRep(varObjPtr);
if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK)
goto err;
Jim_SetResult(interp, varObjPtr);
return JIM_OK;
err:
if (shared) {
Jim_FreeNewObj(interp, varObjPtr);
}if (shared) { ... }
return JIM_ERR;
}{ ... }
Jim_Obj *Jim_ListJoin(Jim_Interp *interp, Jim_Obj *listObjPtr, const char *joinStr, int joinStrLen)
{
int i;
int listLen = Jim_ListLength(interp, listObjPtr);
Jim_Obj *resObjPtr = Jim_NewEmptyStringObj(interp);
for (i = 0; i < listLen; ) {
Jim_AppendObj(interp, resObjPtr, Jim_ListGetIndex(interp, listObjPtr, i));
if (++i != listLen) {
Jim_AppendString(interp, resObjPtr, joinStr, joinStrLen);
}if (++i != listLen) { ... }
}for (i = 0; i < listLen;) { ... }
return resObjPtr;
}{ ... }
Jim_Obj *Jim_ConcatObj(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
int i;
/* ... */
for (i = 0; i < objc; i++) {
if (!Jim_IsList(objv[i]))
break;
}for (i = 0; i < objc; i++) { ... }
if (i == objc) {
Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0);
for (i = 0; i < objc; i++)
ListAppendList(objPtr, objv[i]);
return objPtr;
}if (i == objc) { ... }
else {
int len = 0, objLen;
char *bytes, *p;
for (i = 0; i < objc; i++) {
len += Jim_Length(objv[i]);
}for (i = 0; i < objc; i++) { ... }
if (objc)
len += objc - 1;
p = bytes = Jim_Alloc(len + 1);
for (i = 0; i < objc; i++) {
const char *s = Jim_GetString(objv[i], &objLen);
while (objLen && isspace(UCHAR(*s))) {
s++;
objLen--;
len--;
}while (objLen && isspace(UCHAR(*s))) { ... }
while (objLen && isspace(UCHAR(s[objLen - 1]))) {
if (objLen > 1 && s[objLen - 2] == '\\') {
break;
}if (objLen > 1 && s[objLen - 2] == '\\') { ... }
objLen--;
len--;
}while (objLen && isspace(UCHAR(s[objLen - 1]))) { ... }
memcpy(p, s, objLen);
p += objLen;
if (i + 1 != objc) {
if (objLen)
*p++ = ' ';
else {
/* ... */
len--;
}else { ... }
}if (i + 1 != objc) { ... }
}for (i = 0; i < objc; i++) { ... }
*p = '\0';
return Jim_NewStringObjNoAlloc(interp, bytes, len);
}else { ... }
}{ ... }
/* ... */
Jim_Obj *Jim_ListRange(Jim_Interp *interp, Jim_Obj *listObjPtr, Jim_Obj *firstObjPtr,
Jim_Obj *lastObjPtr)
{
int first, last;
int len, rangeLen;
if (Jim_GetIndex(interp, firstObjPtr, &first) != JIM_OK ||
Jim_GetIndex(interp, lastObjPtr, &last) != JIM_OK)
return NULL;
len = Jim_ListLength(interp, listObjPtr);
first = JimRelToAbsIndex(len, first);
last = JimRelToAbsIndex(len, last);
JimRelToAbsRange(len, &first, &last, &rangeLen);
if (first == 0 && last == len) {
return listObjPtr;
}if (first == 0 && last == len) { ... }
return Jim_NewListObj(interp, listObjPtr->internalRep.listValue.ele + first, rangeLen);
}{ ... }
/* ... */
static void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static void UpdateStringOfDict(struct Jim_Obj *objPtr);
static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
/* ... */
/* ... */
static const Jim_ObjType dictObjType = {
"dict",
FreeDictInternalRep,
DupDictInternalRep,
UpdateStringOfDict,
JIM_TYPE_NONE,
...};
/* ... */
static void JimFreeDict(Jim_Interp *interp, Jim_Dict *dict)
{
int i;
for (i = 0; i < dict->len; i++) {
Jim_DecrRefCount(interp, dict->table[i]);
}for (i = 0; i < dict->len; i++) { ... }
Jim_Free(dict->table);
Jim_Free(dict->ht);
Jim_Free(dict);
}{ ... }
enum {
DICT_HASH_FIND = -1,
DICT_HASH_REMOVE = -2,
DICT_HASH_ADD = -3,
...};
/* ... */
static int JimDictHashFind(Jim_Dict *dict, Jim_Obj *keyObjPtr, int op_tvoffset)
{
unsigned h = (JimObjectHTHashFunction(keyObjPtr) + dict->uniq);
unsigned idx = h & dict->sizemask;
int tvoffset = 0;
unsigned peturb = h;
if (dict->len) {
while ((tvoffset = dict->ht[idx].offset)) {
if (tvoffset == -1) {
/* ... */
if (op_tvoffset == DICT_HASH_ADD) {
tvoffset = 0;
break;
}if (op_tvoffset == DICT_HASH_ADD) { ... }
}if (tvoffset == -1) { ... }
else if (dict->ht[idx].hash == h) {
if (Jim_StringEqObj(keyObjPtr, dict->table[tvoffset - 1])) {
break;
}if (Jim_StringEqObj(keyObjPtr, dict->table[tvoffset - 1])) { ... }
}else if (dict->ht[idx].hash == h) { ... }
peturb >>= 5;
idx = (5 * idx + 1 + peturb) & dict->sizemask;
}while ((tvoffset = dict->ht[idx].offset)) { ... }
}if (dict->len) { ... }
switch (op_tvoffset) {
case DICT_HASH_FIND:
break;case DICT_HASH_FIND:
case DICT_HASH_REMOVE:
if (tvoffset) {
dict->ht[idx].offset = -1;
}if (tvoffset) { ... }
break;case DICT_HASH_REMOVE:
case DICT_HASH_ADD:
if (tvoffset == 0) {
dict->ht[idx].offset = dict->len + 1;
dict->ht[idx].hash = h;
}if (tvoffset == 0) { ... }
break;case DICT_HASH_ADD:
default:
assert(tvoffset);
dict->ht[idx].offset = op_tvoffset;
break;default
}switch (op_tvoffset) { ... }
return tvoffset;
}{ ... }
/* ... */
static void JimDictExpandHashTable(Jim_Dict *dict, unsigned int size)
{
int i;
struct JimDictHashEntry *prevht = dict->ht;
int prevsize = dict->size;
dict->size = JimHashTableNextPower(size);
dict->sizemask = dict->size - 1;
dict->ht = Jim_Alloc(dict->size * sizeof(*dict->ht));
memset(dict->ht, 0, dict->size * sizeof(*dict->ht));
for (i = 0; i < prevsize; i++) {
if (prevht[i].offset > 0) {
unsigned h = prevht[i].hash;
unsigned idx = h & dict->sizemask;
unsigned peturb = h;
while (dict->ht[idx].offset) {
peturb >>= 5;
idx = (5 * idx + 1 + peturb) & dict->sizemask;
}while (dict->ht[idx].offset) { ... }
dict->ht[idx].offset = prevht[i].offset;
dict->ht[idx].hash = h;
}if (prevht[i].offset > 0) { ... }
}for (i = 0; i < prevsize; i++) { ... }
Jim_Free(prevht);
}{ ... }
/* ... */
static int JimDictAdd(Jim_Dict *dict, Jim_Obj *keyObjPtr)
{
/* ... */
if (dict->size <= dict->len) {
/* ... */
JimDictExpandHashTable(dict, dict->size ? dict->size * 2 : 8);
}if (dict->size <= dict->len) { ... }
return JimDictHashFind(dict, keyObjPtr, DICT_HASH_ADD);
}{ ... }
/* ... */
static Jim_Dict *JimDictNew(Jim_Interp *interp, int table_size, int ht_size)
{
Jim_Dict *dict = Jim_Alloc(sizeof(*dict));
memset(dict, 0, sizeof(*dict));
if (ht_size) {
JimDictExpandHashTable(dict, ht_size);
}if (ht_size) { ... }
if (table_size) {
dict->table = Jim_Alloc(table_size * sizeof(*dict->table));
dict->maxLen = table_size;
}if (table_size) { ... }
#ifdef JIM_RANDOMISE_HASH
/* ... */
dict->uniq = (rand() ^ time(NULL) ^ clock());/* ... */
#endif
return dict;
}{ ... }
static void FreeDictInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
JimFreeDict(interp, objPtr->internalRep.dictValue);
}{ ... }
static void DupDictInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
Jim_Dict *oldDict = srcPtr->internalRep.dictValue;
int i;
Jim_Dict *newDict = JimDictNew(interp, oldDict->maxLen, oldDict->size);
for (i = 0; i < oldDict->len; i++) {
newDict->table[i] = oldDict->table[i];
Jim_IncrRefCount(newDict->table[i]);
}for (i = 0; i < oldDict->len; i++) { ... }
newDict->len = oldDict->len;
newDict->uniq = oldDict->uniq;
memcpy(newDict->ht, oldDict->ht, sizeof(*oldDict->ht) * oldDict->size);
dupPtr->internalRep.dictValue = newDict;
dupPtr->typePtr = &dictObjType;
}{ ... }
static void UpdateStringOfDict(struct Jim_Obj *objPtr)
{
JimMakeListStringRep(objPtr, objPtr->internalRep.dictValue->table, objPtr->internalRep.dictValue->len);
}{ ... }
static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
{
int listlen;
if (objPtr->typePtr == &dictObjType) {
return JIM_OK;
}if (objPtr->typePtr == &dictObjType) { ... }
if (Jim_IsList(objPtr) && Jim_IsShared(objPtr)) {
/* ... */
Jim_String(objPtr);
}if (Jim_IsList(objPtr) && Jim_IsShared(objPtr)) { ... }
/* ... */
listlen = Jim_ListLength(interp, objPtr);
if (listlen % 2) {
Jim_SetResultString(interp, "missing value to go with key", -1);
return JIM_ERR;
}if (listlen % 2) { ... }
else {
Jim_Dict *dict = JimDictNew(interp, 0, listlen);
int i;
dict->table = objPtr->internalRep.listValue.ele;
dict->maxLen = objPtr->internalRep.listValue.maxLen;
for (i = 0; i < listlen; i += 2) {
int tvoffset = JimDictAdd(dict, dict->table[i]);
if (tvoffset) {
Jim_DecrRefCount(interp, dict->table[tvoffset]);
dict->table[tvoffset] = dict->table[i + 1];
Jim_DecrRefCount(interp, dict->table[i]);
}if (tvoffset) { ... }
else {
if (dict->len != i) {
/* ... */
dict->table[dict->len++] = dict->table[i];
dict->table[dict->len++] = dict->table[i + 1];
}if (dict->len != i) { ... }
else {
dict->len += 2;
}else { ... }
}else { ... }
}for (i = 0; i < listlen; i += 2) { ... }
objPtr->typePtr = &dictObjType;
objPtr->internalRep.dictValue = dict;
return JIM_OK;
}else { ... }
}{ ... }
/* ... */
static int DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
{
Jim_Dict *dict = objPtr->internalRep.dictValue;
if (valueObjPtr == NULL) {
int tvoffset = JimDictHashFind(dict, keyObjPtr, DICT_HASH_REMOVE);
if (tvoffset) {
/* ... */
Jim_DecrRefCount(interp, dict->table[tvoffset - 1]);
Jim_DecrRefCount(interp, dict->table[tvoffset]);
dict->len -= 2;
if (tvoffset != dict->len + 1) {
dict->table[tvoffset - 1] = dict->table[dict->len];
dict->table[tvoffset] = dict->table[dict->len + 1];
JimDictHashFind(dict, dict->table[tvoffset - 1], tvoffset);
}if (tvoffset != dict->len + 1) { ... }
return JIM_OK;
}if (tvoffset) { ... }
return JIM_ERR;
}if (valueObjPtr == NULL) { ... }
else {
int tvoffset = JimDictAdd(dict, keyObjPtr);
if (tvoffset) {
Jim_IncrRefCount(valueObjPtr);
Jim_DecrRefCount(interp, dict->table[tvoffset]);
dict->table[tvoffset] = valueObjPtr;
}if (tvoffset) { ... }
else {
/* ... */
if (dict->maxLen == dict->len) {
if (dict->maxLen < 4) {
dict->maxLen = 4;
}if (dict->maxLen < 4) { ... }
else {
dict->maxLen *= 2;
}else { ... }
dict->table = Jim_Realloc(dict->table, dict->maxLen * sizeof(*dict->table));
}if (dict->maxLen == dict->len) { ... }
Jim_IncrRefCount(keyObjPtr);
Jim_IncrRefCount(valueObjPtr);
dict->table[dict->len++] = keyObjPtr;
dict->table[dict->len++] = valueObjPtr;
}else { ... }
return JIM_OK;
}else { ... }
}{ ... }
/* ... */
int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr,
Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr)
{
JimPanic((Jim_IsShared(objPtr), "Jim_DictAddElement called with shared object"));
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
return JIM_ERR;
}if (SetDictFromAny(interp, objPtr) != JIM_OK) { ... }
Jim_InvalidateStringRep(objPtr);
return DictAddElement(interp, objPtr, keyObjPtr, valueObjPtr);
}{ ... }
Jim_Obj *Jim_NewDictObj(Jim_Interp *interp, Jim_Obj *const *elements, int len)
{
Jim_Obj *objPtr;
int i;
JimPanic((len % 2, "Jim_NewDictObj() 'len' argument must be even"));
objPtr = Jim_NewObj(interp);
objPtr->typePtr = &dictObjType;
objPtr->bytes = NULL;
objPtr->internalRep.dictValue = JimDictNew(interp, len, len);
for (i = 0; i < len; i += 2)
DictAddElement(interp, objPtr, elements[i], elements[i + 1]);
return objPtr;
}{ ... }
/* ... */
int Jim_DictKey(Jim_Interp *interp, Jim_Obj *dictPtr, Jim_Obj *keyPtr,
Jim_Obj **objPtrPtr, int flags)
{
int tvoffset;
Jim_Dict *dict;
if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
return -1;
}if (SetDictFromAny(interp, dictPtr) != JIM_OK) { ... }
dict = dictPtr->internalRep.dictValue;
tvoffset = JimDictHashFind(dict, keyPtr, DICT_HASH_FIND);
if (tvoffset == 0) {
if (flags & JIM_ERRMSG) {
Jim_SetResultFormatted(interp, "key \"%#s\" not known in dictionary", keyPtr);
}if (flags & JIM_ERRMSG) { ... }
return JIM_ERR;
}if (tvoffset == 0) { ... }
*objPtrPtr = dict->table[tvoffset];
return JIM_OK;
}{ ... }
/* ... */
Jim_Obj **Jim_DictPairs(Jim_Interp *interp, Jim_Obj *dictPtr, int *len)
{
if (Jim_IsList(dictPtr)) {
Jim_Obj **table;
JimListGetElements(interp, dictPtr, len, &table);
if (*len % 2 == 0) {
return table;
}if (*len % 2 == 0) { ... }
}if (Jim_IsList(dictPtr)) { ... }
if (SetDictFromAny(interp, dictPtr) != JIM_OK) {
*len = 1;
return NULL;
}if (SetDictFromAny(interp, dictPtr) != JIM_OK) { ... }
*len = dictPtr->internalRep.dictValue->len;
return dictPtr->internalRep.dictValue->table;
}{ ... }
int Jim_DictKeysVector(Jim_Interp *interp, Jim_Obj *dictPtr,
Jim_Obj *const *keyv, int keyc, Jim_Obj **objPtrPtr, int flags)
{
int i;
if (keyc == 0) {
*objPtrPtr = dictPtr;
return JIM_OK;
}if (keyc == 0) { ... }
for (i = 0; i < keyc; i++) {
Jim_Obj *objPtr;
int rc = Jim_DictKey(interp, dictPtr, keyv[i], &objPtr, flags);
if (rc != JIM_OK) {
return rc;
}if (rc != JIM_OK) { ... }
dictPtr = objPtr;
}for (i = 0; i < keyc; i++) { ... }
*objPtrPtr = dictPtr;
return JIM_OK;
}{ ... }
/* ... */
int Jim_SetDictKeysVector(Jim_Interp *interp, Jim_Obj *varNamePtr,
Jim_Obj *const *keyv, int keyc, Jim_Obj *newObjPtr, int flags)
{
Jim_Obj *varObjPtr, *objPtr, *dictObjPtr;
int shared, i;
varObjPtr = objPtr = Jim_GetVariable(interp, varNamePtr, flags);
if (objPtr == NULL) {
if (newObjPtr == NULL && (flags & JIM_MUSTEXIST)) {
return JIM_ERR;
}if (newObjPtr == NULL && (flags & JIM_MUSTEXIST)) { ... }
varObjPtr = objPtr = Jim_NewDictObj(interp, NULL, 0);
if (Jim_SetVariable(interp, varNamePtr, objPtr) != JIM_OK) {
Jim_FreeNewObj(interp, varObjPtr);
return JIM_ERR;
}if (Jim_SetVariable(interp, varNamePtr, objPtr) != JIM_OK) { ... }
}if (objPtr == NULL) { ... }
if ((shared = Jim_IsShared(objPtr)))
varObjPtr = objPtr = Jim_DuplicateObj(interp, objPtr);
for (i = 0; i < keyc; i++) {
dictObjPtr = objPtr;
if (SetDictFromAny(interp, dictObjPtr) != JIM_OK) {
goto err;
}if (SetDictFromAny(interp, dictObjPtr) != JIM_OK) { ... }
if (i == keyc - 1) {
if (Jim_DictAddElement(interp, objPtr, keyv[keyc - 1], newObjPtr) != JIM_OK) {
if (newObjPtr || (flags & JIM_MUSTEXIST)) {
goto err;
}if (newObjPtr || (flags & JIM_MUSTEXIST)) { ... }
}if (Jim_DictAddElement(interp, objPtr, keyv[keyc - 1], newObjPtr) != JIM_OK) { ... }
break;
}if (i == keyc - 1) { ... }
Jim_InvalidateStringRep(dictObjPtr);
if (Jim_DictKey(interp, dictObjPtr, keyv[i], &objPtr,
newObjPtr ? JIM_NONE : JIM_ERRMSG) == JIM_OK) {
/* ... */
if (Jim_IsShared(objPtr)) {
objPtr = Jim_DuplicateObj(interp, objPtr);
DictAddElement(interp, dictObjPtr, keyv[i], objPtr);
}if (Jim_IsShared(objPtr)) { ... }
}if (Jim_DictKey(interp, dictObjPtr, keyv[i], &objPtr, newObjPtr ? JIM_NONE : JIM_ERRMSG) == JIM_OK) { ... }
else {
/* ... */
if (newObjPtr == NULL) {
goto err;
}if (newObjPtr == NULL) { ... }
/* ... */
objPtr = Jim_NewDictObj(interp, NULL, 0);
DictAddElement(interp, dictObjPtr, keyv[i], objPtr);
}else { ... }
}for (i = 0; i < keyc; i++) { ... }
Jim_InvalidateStringRep(objPtr);
Jim_InvalidateStringRep(varObjPtr);
if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK) {
goto err;
}if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK) { ... }
Jim_SetResult(interp, varObjPtr);
return JIM_OK;
err:
if (shared) {
Jim_FreeNewObj(interp, varObjPtr);
}if (shared) { ... }
return JIM_ERR;
}{ ... }
/* ... */
static void UpdateStringOfIndex(struct Jim_Obj *objPtr);
static int SetIndexFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
static const Jim_ObjType indexObjType = {
"index",
NULL,
NULL,
UpdateStringOfIndex,
JIM_TYPE_NONE,
...};
static void UpdateStringOfIndex(struct Jim_Obj *objPtr)
{
if (objPtr->internalRep.intValue == -1) {
JimSetStringBytes(objPtr, "end");
}if (objPtr->internalRep.intValue == -1) { ... }
else {
char buf[JIM_INTEGER_SPACE + 1];
if (objPtr->internalRep.intValue >= 0 || objPtr->internalRep.intValue == -INT_MAX) {
sprintf(buf, "%d", objPtr->internalRep.intValue);
}if (objPtr->internalRep.intValue >= 0 || objPtr->internalRep.intValue == -INT_MAX) { ... }
else {
sprintf(buf, "end%d", objPtr->internalRep.intValue + 1);
}else { ... }
JimSetStringBytes(objPtr, buf);
}else { ... }
}{ ... }
static int SetIndexFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{
jim_wide idx;
int end = 0;
const char *str;
Jim_Obj *exprObj = objPtr;
JimPanic((objPtr->refCount == 0, "SetIndexFromAny() called with zero refcount object"));
str = Jim_String(objPtr);
if (strncmp(str, "end", 3) == 0) {
end = 1;
str += 3;
idx = 0;
switch (*str) {
case '\0':
exprObj = NULL;
break;
case '\0':
case '-':
case '+':
/* ... */
exprObj = Jim_NewStringObj(interp, str, -1);
break;
case '+':
default:
goto badindex;default
}switch (*str) { ... }
}if (strncmp(str, "end", 3) == 0) { ... }
if (exprObj) {
int ret;
Jim_IncrRefCount(exprObj);
ret = Jim_GetWideExpr(interp, exprObj, &idx);
Jim_DecrRefCount(interp, exprObj);
if (ret != JIM_OK) {
goto badindex;
}if (ret != JIM_OK) { ... }
}if (exprObj) { ... }
if (end) {
if (idx > 0) {
idx = INT_MAX;
}if (idx > 0) { ... }
else {
idx--;
}else { ... }
}if (end) { ... }
else if (idx < 0) {
idx = -INT_MAX;
}else if (idx < 0) { ... }
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &indexObjType;
objPtr->internalRep.intValue = idx;
return JIM_OK;
badindex:
Jim_SetResultFormatted(interp,
"bad index \"%#s\": must be intexpr or end?[+-]intexpr?", objPtr);
return JIM_ERR;
}{ ... }
int Jim_GetIndex(Jim_Interp *interp, Jim_Obj *objPtr, int *indexPtr)
{
if (objPtr->typePtr == &intObjType) {
jim_wide val = JimWideValue(objPtr);
if (val < 0)
*indexPtr = -INT_MAX;
else if (val > INT_MAX)
*indexPtr = INT_MAX;
else
*indexPtr = (int)val;
return JIM_OK;
}if (objPtr->typePtr == &intObjType) { ... }
if (objPtr->typePtr != &indexObjType && SetIndexFromAny(interp, objPtr) == JIM_ERR)
return JIM_ERR;
*indexPtr = objPtr->internalRep.intValue;
return JIM_OK;
}{ ... }
/* ... */
static const char * const jimReturnCodes[] = {
"ok",
"error",
"return",
"break",
"continue",
"signal",
"exit",
"eval",
NULL
...};
#define jimReturnCodesSize (sizeof(jimReturnCodes)/sizeof(*jimReturnCodes) - 1)
static const Jim_ObjType returnCodeObjType = {
"return-code",
NULL,
NULL,
NULL,
JIM_TYPE_NONE,
...};
/* ... */
const char *Jim_ReturnCode(int code)
{
if (code < 0 || code >= (int)jimReturnCodesSize) {
return "?";
}if (code < 0 || code >= (int)jimReturnCodesSize) { ... }
else {
return jimReturnCodes[code];
}else { ... }
}{ ... }
static int SetReturnCodeFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{
int returnCode;
jim_wide wideValue;
if (JimGetWideNoErr(interp, objPtr, &wideValue) != JIM_ERR)
returnCode = (int)wideValue;
else if (Jim_GetEnum(interp, objPtr, jimReturnCodes, &returnCode, NULL, JIM_NONE) != JIM_OK) {
Jim_SetResultFormatted(interp, "expected return code but got \"%#s\"", objPtr);
return JIM_ERR;
}else if (Jim_GetEnum(interp, objPtr, jimReturnCodes, &returnCode, NULL, JIM_NONE) != JIM_OK) { ... }
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &returnCodeObjType;
objPtr->internalRep.intValue = returnCode;
return JIM_OK;
}{ ... }
int Jim_GetReturnCode(Jim_Interp *interp, Jim_Obj *objPtr, int *intPtr)
{
if (objPtr->typePtr != &returnCodeObjType && SetReturnCodeFromAny(interp, objPtr) == JIM_ERR)
return JIM_ERR;
*intPtr = objPtr->internalRep.intValue;
return JIM_OK;
}{ ... }
/* ... */
static int JimParseExprOperator(struct JimParserCtx *pc);
static int JimParseExprNumber(struct JimParserCtx *pc);
static int JimParseExprIrrational(struct JimParserCtx *pc);
static int JimParseExprBoolean(struct JimParserCtx *pc);
enum
{
JIM_EXPROP_MUL = JIM_TT_EXPR_OP,
JIM_EXPROP_DIV,
JIM_EXPROP_MOD,
JIM_EXPROP_SUB,
JIM_EXPROP_ADD,
JIM_EXPROP_LSHIFT,
JIM_EXPROP_RSHIFT,
JIM_EXPROP_ROTL,
JIM_EXPROP_ROTR,
JIM_EXPROP_LT,
JIM_EXPROP_GT,
JIM_EXPROP_LTE,
JIM_EXPROP_GTE,
JIM_EXPROP_NUMEQ,
JIM_EXPROP_NUMNE,
JIM_EXPROP_BITAND,
JIM_EXPROP_BITXOR,
JIM_EXPROP_BITOR,
JIM_EXPROP_LOGICAND,
JIM_EXPROP_LOGICOR,
JIM_EXPROP_TERNARY,
JIM_EXPROP_COLON,
JIM_EXPROP_POW,
JIM_EXPROP_STREQ,
JIM_EXPROP_STRNE,
JIM_EXPROP_STRIN,
JIM_EXPROP_STRNI,
JIM_EXPROP_STRLT,
JIM_EXPROP_STRGT,
JIM_EXPROP_STRLE,
JIM_EXPROP_STRGE,
JIM_EXPROP_NOT,
JIM_EXPROP_BITNOT,
JIM_EXPROP_UNARYMINUS,
JIM_EXPROP_UNARYPLUS,
JIM_EXPROP_FUNC_INT,
JIM_EXPROP_FUNC_WIDE,
JIM_EXPROP_FUNC_ABS,
JIM_EXPROP_FUNC_DOUBLE,
JIM_EXPROP_FUNC_ROUND,
JIM_EXPROP_FUNC_RAND,
JIM_EXPROP_FUNC_SRAND,
JIM_EXPROP_FUNC_SIN,
JIM_EXPROP_FUNC_COS,
JIM_EXPROP_FUNC_TAN,
JIM_EXPROP_FUNC_ASIN,
JIM_EXPROP_FUNC_ACOS,
JIM_EXPROP_FUNC_ATAN,
JIM_EXPROP_FUNC_ATAN2,
JIM_EXPROP_FUNC_SINH,
JIM_EXPROP_FUNC_COSH,
JIM_EXPROP_FUNC_TANH,
JIM_EXPROP_FUNC_CEIL,
JIM_EXPROP_FUNC_FLOOR,
JIM_EXPROP_FUNC_EXP,
JIM_EXPROP_FUNC_LOG,
JIM_EXPROP_FUNC_LOG10,
JIM_EXPROP_FUNC_SQRT,
JIM_EXPROP_FUNC_POW,
JIM_EXPROP_FUNC_HYPOT,
JIM_EXPROP_FUNC_FMOD,
...};
/* ... */
struct JimExprNode {
int type;
struct Jim_Obj *objPtr;
struct JimExprNode *left;
struct JimExprNode *right;
struct JimExprNode *ternary;
...};
typedef struct Jim_ExprOperator
{
const char *name;
int (*funcop) (Jim_Interp *interp, struct JimExprNode *opnode);
unsigned char precedence;
unsigned char arity;
unsigned char attr;
unsigned char namelen;
...} Jim_ExprOperator;
static int JimExprGetTerm(Jim_Interp *interp, struct JimExprNode *node, Jim_Obj **objPtrPtr);
static int JimExprGetTermBoolean(Jim_Interp *interp, struct JimExprNode *node);
static int JimExprEvalTermNode(Jim_Interp *interp, struct JimExprNode *node);
static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprNode *node)
{
int intresult = 1;
int rc, bA = 0;
double dA, dC = 0;
jim_wide wA, wC = 0;
Jim_Obj *A;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
}if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) { ... }
if ((A->typePtr != &doubleObjType || A->bytes) && JimGetWideNoErr(interp, A, &wA) == JIM_OK) {
switch (node->type) {
case JIM_EXPROP_FUNC_INT:
case JIM_EXPROP_FUNC_WIDE:
case JIM_EXPROP_FUNC_ROUND:
case JIM_EXPROP_UNARYPLUS:
wC = wA;
break;case JIM_EXPROP_UNARYPLUS:
case JIM_EXPROP_FUNC_DOUBLE:
dC = wA;
intresult = 0;
break;case JIM_EXPROP_FUNC_DOUBLE:
case JIM_EXPROP_FUNC_ABS:
wC = wA >= 0 ? wA : -wA;
break;case JIM_EXPROP_FUNC_ABS:
case JIM_EXPROP_UNARYMINUS:
wC = -wA;
break;case JIM_EXPROP_UNARYMINUS:
case JIM_EXPROP_NOT:
wC = !wA;
break;case JIM_EXPROP_NOT:
default:
abort();default
}switch (node->type) { ... }
}if ((A->typePtr != &doubleObjType || A->bytes) && JimGetWideNoErr(interp, A, &wA) == JIM_OK) { ... }
else if ((rc = Jim_GetDouble(interp, A, &dA)) == JIM_OK) {
switch (node->type) {
case JIM_EXPROP_FUNC_INT:
case JIM_EXPROP_FUNC_WIDE:
wC = dA;
break;case JIM_EXPROP_FUNC_WIDE:
case JIM_EXPROP_FUNC_ROUND:
wC = dA < 0 ? (dA - 0.5) : (dA + 0.5);
break;case JIM_EXPROP_FUNC_ROUND:
case JIM_EXPROP_FUNC_DOUBLE:
case JIM_EXPROP_UNARYPLUS:
dC = dA;
intresult = 0;
break;case JIM_EXPROP_UNARYPLUS:
case JIM_EXPROP_FUNC_ABS:
#ifdef JIM_MATH_FUNCTIONS
dC = fabs(dA);
#else
dC = dA >= 0 ? dA : -dA;
#endif
intresult = 0;
break;case JIM_EXPROP_FUNC_ABS:
case JIM_EXPROP_UNARYMINUS:
dC = -dA;
intresult = 0;
break;case JIM_EXPROP_UNARYMINUS:
case JIM_EXPROP_NOT:
wC = !dA;
break;case JIM_EXPROP_NOT:
default:
abort();default
}switch (node->type) { ... }
}else if ((rc = Jim_GetDouble(interp, A, &dA)) == JIM_OK) { ... }
else if ((rc = Jim_GetBoolean(interp, A, &bA)) == JIM_OK) {
switch (node->type) {
case JIM_EXPROP_NOT:
wC = !bA;
break;case JIM_EXPROP_NOT:
default:
abort();default
}switch (node->type) { ... }
}else if ((rc = Jim_GetBoolean(interp, A, &bA)) == JIM_OK) { ... }
if (rc == JIM_OK) {
if (intresult) {
Jim_SetResultInt(interp, wC);
}if (intresult) { ... }
else {
Jim_SetResult(interp, Jim_NewDoubleObj(interp, dC));
}else { ... }
}if (rc == JIM_OK) { ... }
Jim_DecrRefCount(interp, A);
return rc;
}{ ... }
static double JimRandDouble(Jim_Interp *interp)
{
unsigned long x;
JimRandomBytes(interp, &x, sizeof(x));
return (double)x / (double)~0UL;
}{ ... }
static int JimExprOpIntUnary(Jim_Interp *interp, struct JimExprNode *node)
{
jim_wide wA;
Jim_Obj *A;
int rc;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
}if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) { ... }
rc = Jim_GetWide(interp, A, &wA);
if (rc == JIM_OK) {
switch (node->type) {
case JIM_EXPROP_BITNOT:
Jim_SetResultInt(interp, ~wA);
break;case JIM_EXPROP_BITNOT:
case JIM_EXPROP_FUNC_SRAND:
JimPrngSeed(interp, (unsigned char *)&wA, sizeof(wA));
Jim_SetResult(interp, Jim_NewDoubleObj(interp, JimRandDouble(interp)));
break;case JIM_EXPROP_FUNC_SRAND:
default:
abort();default
}switch (node->type) { ... }
}if (rc == JIM_OK) { ... }
Jim_DecrRefCount(interp, A);
return rc;
}{ ... }
static int JimExprOpNone(Jim_Interp *interp, struct JimExprNode *node)
{
JimPanic((node->type != JIM_EXPROP_FUNC_RAND, "JimExprOpNone only support rand()"));
Jim_SetResult(interp, Jim_NewDoubleObj(interp, JimRandDouble(interp)));
return JIM_OK;
}{ ... }
#ifdef JIM_MATH_FUNCTIONS
static int JimExprOpDoubleUnary(Jim_Interp *interp, struct JimExprNode *node)
{
int rc;
double dA, dC;
Jim_Obj *A;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
}if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) { ... }
rc = Jim_GetDouble(interp, A, &dA);
if (rc == JIM_OK) {
switch (node->type) {
case JIM_EXPROP_FUNC_SIN:
dC = sin(dA);
break;case JIM_EXPROP_FUNC_SIN:
case JIM_EXPROP_FUNC_COS:
dC = cos(dA);
break;case JIM_EXPROP_FUNC_COS:
case JIM_EXPROP_FUNC_TAN:
dC = tan(dA);
break;case JIM_EXPROP_FUNC_TAN:
case JIM_EXPROP_FUNC_ASIN:
dC = asin(dA);
break;case JIM_EXPROP_FUNC_ASIN:
case JIM_EXPROP_FUNC_ACOS:
dC = acos(dA);
break;case JIM_EXPROP_FUNC_ACOS:
case JIM_EXPROP_FUNC_ATAN:
dC = atan(dA);
break;case JIM_EXPROP_FUNC_ATAN:
case JIM_EXPROP_FUNC_SINH:
dC = sinh(dA);
break;case JIM_EXPROP_FUNC_SINH:
case JIM_EXPROP_FUNC_COSH:
dC = cosh(dA);
break;case JIM_EXPROP_FUNC_COSH:
case JIM_EXPROP_FUNC_TANH:
dC = tanh(dA);
break;case JIM_EXPROP_FUNC_TANH:
case JIM_EXPROP_FUNC_CEIL:
dC = ceil(dA);
break;case JIM_EXPROP_FUNC_CEIL:
case JIM_EXPROP_FUNC_FLOOR:
dC = floor(dA);
break;case JIM_EXPROP_FUNC_FLOOR:
case JIM_EXPROP_FUNC_EXP:
dC = exp(dA);
break;case JIM_EXPROP_FUNC_EXP:
case JIM_EXPROP_FUNC_LOG:
dC = log(dA);
break;case JIM_EXPROP_FUNC_LOG:
case JIM_EXPROP_FUNC_LOG10:
dC = log10(dA);
break;case JIM_EXPROP_FUNC_LOG10:
case JIM_EXPROP_FUNC_SQRT:
dC = sqrt(dA);
break;case JIM_EXPROP_FUNC_SQRT:
default:
abort();default
}switch (node->type) { ... }
Jim_SetResult(interp, Jim_NewDoubleObj(interp, dC));
}if (rc == JIM_OK) { ... }
Jim_DecrRefCount(interp, A);
return rc;
}JimExprOpDoubleUnary (Jim_Interp *interp, struct JimExprNode *node) { ... }
/* ... */#endif
static int JimExprOpIntBin(Jim_Interp *interp, struct JimExprNode *node)
{
jim_wide wA, wB;
int rc;
Jim_Obj *A, *B;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
}if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) { ... }
if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) {
Jim_DecrRefCount(interp, A);
return rc;
}if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) { ... }
rc = JIM_ERR;
if (Jim_GetWide(interp, A, &wA) == JIM_OK && Jim_GetWide(interp, B, &wB) == JIM_OK) {
jim_wide wC;
rc = JIM_OK;
switch (node->type) {
case JIM_EXPROP_LSHIFT:
wC = wA << wB;
break;case JIM_EXPROP_LSHIFT:
case JIM_EXPROP_RSHIFT:
wC = wA >> wB;
break;case JIM_EXPROP_RSHIFT:
case JIM_EXPROP_BITAND:
wC = wA & wB;
break;case JIM_EXPROP_BITAND:
case JIM_EXPROP_BITXOR:
wC = wA ^ wB;
break;case JIM_EXPROP_BITXOR:
case JIM_EXPROP_BITOR:
wC = wA | wB;
break;case JIM_EXPROP_BITOR:
case JIM_EXPROP_MOD:
if (wB == 0) {
wC = 0;
Jim_SetResultString(interp, "Division by zero", -1);
rc = JIM_ERR;
}if (wB == 0) { ... }
else {
/* ... */
int negative = 0;
if (wB < 0) {
wB = -wB;
wA = -wA;
negative = 1;
}if (wB < 0) { ... }
wC = wA % wB;
if (wC < 0) {
wC += wB;
}if (wC < 0) { ... }
if (negative) {
wC = -wC;
}if (negative) { ... }
}else { ... }
break;case JIM_EXPROP_MOD:
case JIM_EXPROP_ROTL:
case JIM_EXPROP_ROTR:{
unsigned long uA = (unsigned long)wA;
unsigned long uB = (unsigned long)wB;
const unsigned int S = sizeof(unsigned long) * 8;
uB %= S;
if (node->type == JIM_EXPROP_ROTR) {
uB = S - uB;
}if (node->type == JIM_EXPROP_ROTR) { ... }
wC = (unsigned long)(uA << uB) | (uA >> (S - uB));
break;
...}case JIM_EXPROP_ROTR:
default:
abort();default
}switch (node->type) { ... }
Jim_SetResultInt(interp, wC);
}if (Jim_GetWide(interp, A, &wA) == JIM_OK && Jim_GetWide(interp, B, &wB) == JIM_OK) { ... }
Jim_DecrRefCount(interp, A);
Jim_DecrRefCount(interp, B);
return rc;
}{ ... }
static int JimExprOpBin(Jim_Interp *interp, struct JimExprNode *node)
{
int rc = JIM_OK;
double dA, dB, dC = 0;
jim_wide wA, wB, wC = 0;
Jim_Obj *A, *B;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
}if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) { ... }
if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) {
Jim_DecrRefCount(interp, A);
return rc;
}if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) { ... }
if ((A->typePtr != &doubleObjType || A->bytes) &&
(B->typePtr != &doubleObjType || B->bytes) &&
JimGetWideNoErr(interp, A, &wA) == JIM_OK && JimGetWideNoErr(interp, B, &wB) == JIM_OK) {
switch (node->type) {
case JIM_EXPROP_POW:
case JIM_EXPROP_FUNC_POW:
if (wA == 0 && wB < 0) {
Jim_SetResultString(interp, "exponentiation of zero by negative power", -1);
rc = JIM_ERR;
goto done;
}if (wA == 0 && wB < 0) { ... }
wC = JimPowWide(wA, wB);
goto intresult;case JIM_EXPROP_FUNC_POW:
case JIM_EXPROP_ADD:
wC = wA + wB;
goto intresult;case JIM_EXPROP_ADD:
case JIM_EXPROP_SUB:
wC = wA - wB;
goto intresult;case JIM_EXPROP_SUB:
case JIM_EXPROP_MUL:
wC = wA * wB;
goto intresult;case JIM_EXPROP_MUL:
case JIM_EXPROP_DIV:
if (wB == 0) {
Jim_SetResultString(interp, "Division by zero", -1);
rc = JIM_ERR;
goto done;
}if (wB == 0) { ... }
else {
/* ... */
if (wB < 0) {
wB = -wB;
wA = -wA;
}if (wB < 0) { ... }
wC = wA / wB;
if (wA % wB < 0) {
wC--;
}if (wA % wB < 0) { ... }
goto intresult;
}else { ... }
case JIM_EXPROP_DIV: case JIM_EXPROP_LT:
wC = wA < wB;
goto intresult;case JIM_EXPROP_LT:
case JIM_EXPROP_GT:
wC = wA > wB;
goto intresult;case JIM_EXPROP_GT:
case JIM_EXPROP_LTE:
wC = wA <= wB;
goto intresult;case JIM_EXPROP_LTE:
case JIM_EXPROP_GTE:
wC = wA >= wB;
goto intresult;case JIM_EXPROP_GTE:
case JIM_EXPROP_NUMEQ:
wC = wA == wB;
goto intresult;case JIM_EXPROP_NUMEQ:
case JIM_EXPROP_NUMNE:
wC = wA != wB;
goto intresult;case JIM_EXPROP_NUMNE:
}switch (node->type) { ... }
}if ((A->typePtr != &doubleObjType || A->bytes) && (B->typePtr != &doubleObjType || B->bytes) && JimGetWideNoErr(interp, A, &wA) == JIM_OK && JimGetWideNoErr(interp, B, &wB) == JIM_OK) { ... }
if (Jim_GetDouble(interp, A, &dA) == JIM_OK && Jim_GetDouble(interp, B, &dB) == JIM_OK) {
switch (node->type) {
#ifndef JIM_MATH_FUNCTIONS
case JIM_EXPROP_POW:
case JIM_EXPROP_FUNC_POW:
case JIM_EXPROP_FUNC_ATAN2:
case JIM_EXPROP_FUNC_HYPOT:
case JIM_EXPROP_FUNC_FMOD:
Jim_SetResultString(interp, "unsupported", -1);
rc = JIM_ERR;
goto done;/* ... */
#else
case JIM_EXPROP_POW:
case JIM_EXPROP_FUNC_POW:
dC = pow(dA, dB);
goto doubleresult;case JIM_EXPROP_FUNC_POW:
case JIM_EXPROP_FUNC_ATAN2:
dC = atan2(dA, dB);
goto doubleresult;case JIM_EXPROP_FUNC_ATAN2:
case JIM_EXPROP_FUNC_HYPOT:
dC = hypot(dA, dB);
goto doubleresult;case JIM_EXPROP_FUNC_HYPOT:
case JIM_EXPROP_FUNC_FMOD:
dC = fmod(dA, dB);
goto doubleresult;/* ... */
#endif
case JIM_EXPROP_ADD:
dC = dA + dB;
goto doubleresult;case JIM_EXPROP_ADD:
case JIM_EXPROP_SUB:
dC = dA - dB;
goto doubleresult;case JIM_EXPROP_SUB:
case JIM_EXPROP_MUL:
dC = dA * dB;
goto doubleresult;case JIM_EXPROP_MUL:
case JIM_EXPROP_DIV:
if (dB == 0) {
#ifdef INFINITY
dC = dA < 0 ? -INFINITY : INFINITY;
#else
dC = (dA < 0 ? -1.0 : 1.0) * strtod("Inf", NULL);
#endif
}if (dB == 0) { ... }
else {
dC = dA / dB;
}else { ... }
goto doubleresult;case JIM_EXPROP_DIV:
case JIM_EXPROP_LT:
wC = dA < dB;
goto intresult;case JIM_EXPROP_LT:
case JIM_EXPROP_GT:
wC = dA > dB;
goto intresult;case JIM_EXPROP_GT:
case JIM_EXPROP_LTE:
wC = dA <= dB;
goto intresult;case JIM_EXPROP_LTE:
case JIM_EXPROP_GTE:
wC = dA >= dB;
goto intresult;case JIM_EXPROP_GTE:
case JIM_EXPROP_NUMEQ:
wC = dA == dB;
goto intresult;case JIM_EXPROP_NUMEQ:
case JIM_EXPROP_NUMNE:
wC = dA != dB;
goto intresult;case JIM_EXPROP_NUMNE:
}switch (node->type) { ... }
}if (Jim_GetDouble(interp, A, &dA) == JIM_OK && Jim_GetDouble(interp, B, &dB) == JIM_OK) { ... }
else {
int i = Jim_StringCompareObj(interp, A, B, 0);
switch (node->type) {
case JIM_EXPROP_LT:
wC = i < 0;
goto intresult;case JIM_EXPROP_LT:
case JIM_EXPROP_GT:
wC = i > 0;
goto intresult;case JIM_EXPROP_GT:
case JIM_EXPROP_LTE:
wC = i <= 0;
goto intresult;case JIM_EXPROP_LTE:
case JIM_EXPROP_GTE:
wC = i >= 0;
goto intresult;case JIM_EXPROP_GTE:
case JIM_EXPROP_NUMEQ:
wC = i == 0;
goto intresult;case JIM_EXPROP_NUMEQ:
case JIM_EXPROP_NUMNE:
wC = i != 0;
goto intresult;case JIM_EXPROP_NUMNE:
}switch (node->type) { ... }
}else { ... }
rc = JIM_ERR;
done:
Jim_DecrRefCount(interp, A);
Jim_DecrRefCount(interp, B);
return rc;
intresult:
Jim_SetResultInt(interp, wC);
goto done;
doubleresult:
Jim_SetResult(interp, Jim_NewDoubleObj(interp, dC));
goto done;
}{ ... }
static int JimSearchList(Jim_Interp *interp, Jim_Obj *listObjPtr, Jim_Obj *valObj)
{
int listlen;
int i;
listlen = Jim_ListLength(interp, listObjPtr);
for (i = 0; i < listlen; i++) {
if (Jim_StringEqObj(Jim_ListGetIndex(interp, listObjPtr, i), valObj)) {
return 1;
}if (Jim_StringEqObj(Jim_ListGetIndex(interp, listObjPtr, i), valObj)) { ... }
}for (i = 0; i < listlen; i++) { ... }
return 0;
}{ ... }
static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprNode *node)
{
Jim_Obj *A, *B;
jim_wide wC;
int comp, rc;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
}if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) { ... }
if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) {
Jim_DecrRefCount(interp, A);
return rc;
}if ((rc = JimExprGetTerm(interp, node->right, &B)) != JIM_OK) { ... }
switch (node->type) {
case JIM_EXPROP_STREQ:
case JIM_EXPROP_STRNE:
wC = Jim_StringEqObj(A, B);
if (node->type == JIM_EXPROP_STRNE) {
wC = !wC;
}if (node->type == JIM_EXPROP_STRNE) { ... }
break;case JIM_EXPROP_STRNE:
case JIM_EXPROP_STRLT:
case JIM_EXPROP_STRGT:
case JIM_EXPROP_STRLE:
case JIM_EXPROP_STRGE:
comp = Jim_StringCompareObj(interp, A, B, 0);
if (node->type == JIM_EXPROP_STRLT) {
wC = comp == -1;
}if (node->type == JIM_EXPROP_STRLT) { ... } else if (node->type == JIM_EXPROP_STRGT) {
wC = comp == 1;
}else if (node->type == JIM_EXPROP_STRGT) { ... } else if (node->type == JIM_EXPROP_STRLE) {
wC = comp == -1 || comp == 0;
}else if (node->type == JIM_EXPROP_STRLE) { ... } else {
wC = comp == 0 || comp == 1;
}else { ... }
break;case JIM_EXPROP_STRGE:
case JIM_EXPROP_STRIN:
wC = JimSearchList(interp, B, A);
break;case JIM_EXPROP_STRIN:
case JIM_EXPROP_STRNI:
wC = !JimSearchList(interp, B, A);
break;case JIM_EXPROP_STRNI:
default:
abort();default
}switch (node->type) { ... }
Jim_SetResultInt(interp, wC);
Jim_DecrRefCount(interp, A);
Jim_DecrRefCount(interp, B);
return rc;
}{ ... }
static int ExprBool(Jim_Interp *interp, Jim_Obj *obj)
{
long l;
double d;
int b;
int ret = -1;
Jim_IncrRefCount(obj);
if (Jim_GetLong(interp, obj, &l) == JIM_OK) {
ret = (l != 0);
}if (Jim_GetLong(interp, obj, &l) == JIM_OK) { ... }
else if (Jim_GetDouble(interp, obj, &d) == JIM_OK) {
ret = (d != 0);
}else if (Jim_GetDouble(interp, obj, &d) == JIM_OK) { ... }
else if (Jim_GetBoolean(interp, obj, &b) == JIM_OK) {
ret = (b != 0);
}else if (Jim_GetBoolean(interp, obj, &b) == JIM_OK) { ... }
Jim_DecrRefCount(interp, obj);
return ret;
}{ ... }
static int JimExprOpAnd(Jim_Interp *interp, struct JimExprNode *node)
{
int result = JimExprGetTermBoolean(interp, node->left);
if (result == 1) {
result = JimExprGetTermBoolean(interp, node->right);
}if (result == 1) { ... }
if (result == -1) {
return JIM_ERR;
}if (result == -1) { ... }
Jim_SetResultInt(interp, result);
return JIM_OK;
}{ ... }
static int JimExprOpOr(Jim_Interp *interp, struct JimExprNode *node)
{
int result = JimExprGetTermBoolean(interp, node->left);
if (result == 0) {
result = JimExprGetTermBoolean(interp, node->right);
}if (result == 0) { ... }
if (result == -1) {
return JIM_ERR;
}if (result == -1) { ... }
Jim_SetResultInt(interp, result);
return JIM_OK;
}{ ... }
static int JimExprOpTernary(Jim_Interp *interp, struct JimExprNode *node)
{
int result = JimExprGetTermBoolean(interp, node->left);
if (result == 1) {
return JimExprEvalTermNode(interp, node->right);
}if (result == 1) { ... }
else if (result == 0) {
return JimExprEvalTermNode(interp, node->ternary);
}else if (result == 0) { ... }
return JIM_ERR;
}{ ... }
enum
{
OP_FUNC = 0x0001,
OP_RIGHT_ASSOC = 0x0002,
...};
/* ... */
#define OPRINIT_ATTR(N, P, ARITY, F, ATTR) {N, F, P, ARITY, ATTR, sizeof(N) - 1}
#define OPRINIT(N, P, ARITY, F) OPRINIT_ATTR(N, P, ARITY, F, 0)
static const struct Jim_ExprOperator Jim_ExprOperators[] = {
OPRINIT("*", 110, 2, JimExprOpBin),
OPRINIT("/", 110, 2, JimExprOpBin),
OPRINIT("%", 110, 2, JimExprOpIntBin),
OPRINIT("-", 100, 2, JimExprOpBin),
OPRINIT("+", 100, 2, JimExprOpBin),
OPRINIT("<<", 90, 2, JimExprOpIntBin),
OPRINIT(">>", 90, 2, JimExprOpIntBin),
OPRINIT("<<<", 90, 2, JimExprOpIntBin),
OPRINIT(">>>", 90, 2, JimExprOpIntBin),
OPRINIT("<", 80, 2, JimExprOpBin),
OPRINIT(">", 80, 2, JimExprOpBin),
OPRINIT("<=", 80, 2, JimExprOpBin),
OPRINIT(">=", 80, 2, JimExprOpBin),
OPRINIT("==", 70, 2, JimExprOpBin),
OPRINIT("!=", 70, 2, JimExprOpBin),
OPRINIT("&", 50, 2, JimExprOpIntBin),
OPRINIT("^", 49, 2, JimExprOpIntBin),
OPRINIT("|", 48, 2, JimExprOpIntBin),
OPRINIT("&&", 10, 2, JimExprOpAnd),
OPRINIT("||", 9, 2, JimExprOpOr),
OPRINIT_ATTR("?", 5, 3, JimExprOpTernary, OP_RIGHT_ASSOC),
OPRINIT_ATTR(":", 5, 3, NULL, OP_RIGHT_ASSOC),
OPRINIT_ATTR("**", 120, 2, JimExprOpBin, OP_RIGHT_ASSOC),
OPRINIT("eq", 60, 2, JimExprOpStrBin),
OPRINIT("ne", 60, 2, JimExprOpStrBin),
OPRINIT("in", 55, 2, JimExprOpStrBin),
OPRINIT("ni", 55, 2, JimExprOpStrBin),
/* ... */
OPRINIT("lt", 75, 2, JimExprOpStrBin),
OPRINIT("gt", 75, 2, JimExprOpStrBin),
OPRINIT("le", 75, 2, JimExprOpStrBin),
OPRINIT("ge", 75, 2, JimExprOpStrBin),
OPRINIT_ATTR("!", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR("~", 150, 1, JimExprOpIntUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR(" -", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR(" +", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR("int", 200, 1, JimExprOpNumUnary, OP_FUNC),
OPRINIT_ATTR("wide", 200, 1, JimExprOpNumUnary, OP_FUNC),
OPRINIT_ATTR("abs", 200, 1, JimExprOpNumUnary, OP_FUNC),
OPRINIT_ATTR("double", 200, 1, JimExprOpNumUnary, OP_FUNC),
OPRINIT_ATTR("round", 200, 1, JimExprOpNumUnary, OP_FUNC),
OPRINIT_ATTR("rand", 200, 0, JimExprOpNone, OP_FUNC),
OPRINIT_ATTR("srand", 200, 1, JimExprOpIntUnary, OP_FUNC),
#ifdef JIM_MATH_FUNCTIONS
OPRINIT_ATTR("sin", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("cos", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("tan", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("asin", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("acos", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("atan", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("atan2", 200, 2, JimExprOpBin, OP_FUNC),
OPRINIT_ATTR("sinh", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("cosh", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("tanh", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("ceil", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("floor", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("exp", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("log", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("log10", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("sqrt", 200, 1, JimExprOpDoubleUnary, OP_FUNC),
OPRINIT_ATTR("pow", 200, 2, JimExprOpBin, OP_FUNC),
OPRINIT_ATTR("hypot", 200, 2, JimExprOpBin, OP_FUNC),
OPRINIT_ATTR("fmod", 200, 2, JimExprOpBin, OP_FUNC),/* ... */
#endif
...};
#undef OPRINIT
#undef OPRINIT_ATTR
#define JIM_EXPR_OPERATORS_NUM \
(sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator))...
static int JimParseExpression(struct JimParserCtx *pc)
{
while (1) {
while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) {
if (*pc->p == '\n') {
pc->linenr++;
}if (*pc->p == '\n') { ... }
pc->p++;
pc->len--;
}while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) { ... }
if (*pc->p == '#') {
JimParseComment(pc);
continue;
}if (*pc->p == '#') { ... }
break;
}while (1) { ... }
pc->tline = pc->linenr;
pc->tstart = pc->p;
if (pc->len == 0) {
pc->tend = pc->p;
pc->tt = JIM_TT_EOL;
pc->eof = 1;
return JIM_OK;
}if (pc->len == 0) { ... }
switch (*(pc->p)) {
case '(':
pc->tt = JIM_TT_SUBEXPR_START;
goto singlechar;case '(':
case ')':
pc->tt = JIM_TT_SUBEXPR_END;
goto singlechar;case ')':
case ',':
pc->tt = JIM_TT_SUBEXPR_COMMA;
singlechar:
pc->tend = pc->p;
pc->p++;
pc->len--;
break;case ',':
case '[':
return JimParseCmd(pc);case '[':
case '$':
if (JimParseVar(pc) == JIM_ERR)
return JimParseExprOperator(pc);
else {
if (pc->tt == JIM_TT_EXPRSUGAR) {
return JIM_ERR;
}if (pc->tt == JIM_TT_EXPRSUGAR) { ... }
return JIM_OK;
}else { ... }
break;case '$':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
return JimParseExprNumber(pc);case '.':
case '"':
return JimParseQuote(pc);case '"':
case '{':
return JimParseBrace(pc);
case '{':
case 'N':
case 'I':
case 'n':
case 'i':
if (JimParseExprIrrational(pc) == JIM_ERR)
if (JimParseExprBoolean(pc) == JIM_ERR)
return JimParseExprOperator(pc);
break;case 'i':
case 't':
case 'f':
case 'o':
case 'y':
if (JimParseExprBoolean(pc) == JIM_ERR)
return JimParseExprOperator(pc);
break;case 'y':
default:
return JimParseExprOperator(pc);
break;default
}switch (*(pc->p)) { ... }
return JIM_OK;
}{ ... }
static int JimParseExprNumber(struct JimParserCtx *pc)
{
char *end;
pc->tt = JIM_TT_EXPR_INT;
jim_strtoull(pc->p, (char **)&pc->p);
if (strchr("eENnIi.", *pc->p) || pc->p == pc->tstart) {
/* ... */
if (strtod(pc->tstart, &end)) { }
if (end == pc->tstart)
return JIM_ERR;
if (end > pc->p) {
pc->tt = JIM_TT_EXPR_DOUBLE;
pc->p = end;
}if (end > pc->p) { ... }
}if (strchr("eENnIi.", *pc->p) || pc->p == pc->tstart) { ... }
pc->tend = pc->p - 1;
pc->len -= (pc->p - pc->tstart);
return JIM_OK;
}{ ... }
static int JimParseExprIrrational(struct JimParserCtx *pc)
{
const char *irrationals[] = { "NaN", "nan", "NAN", "Inf", "inf", "INF", NULL };
int i;
for (i = 0; irrationals[i]; i++) {
const char *irr = irrationals[i];
if (strncmp(irr, pc->p, 3) == 0) {
pc->p += 3;
pc->len -= 3;
pc->tend = pc->p - 1;
pc->tt = JIM_TT_EXPR_DOUBLE;
return JIM_OK;
}if (strncmp(irr, pc->p, 3) == 0) { ... }
}for (i = 0; irrationals[i]; i++) { ... }
return JIM_ERR;
}{ ... }
static int JimParseExprBoolean(struct JimParserCtx *pc)
{
int i;
for (i = 0; i < sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings); i++) {
if (strncmp(pc->p, jim_true_false_strings[i], jim_true_false_lens[i]) == 0) {
pc->p += jim_true_false_lens[i];
pc->len -= jim_true_false_lens[i];
pc->tend = pc->p - 1;
pc->tt = JIM_TT_EXPR_BOOLEAN;
return JIM_OK;
}if (strncmp(pc->p, jim_true_false_strings[i], jim_true_false_lens[i]) == 0) { ... }
}for (i = 0; i < sizeof(jim_true_false_strings) / sizeof(*jim_true_false_strings); i++) { ... }
return JIM_ERR;
}{ ... }
static const struct Jim_ExprOperator *JimExprOperatorInfoByOpcode(int opcode)
{
static Jim_ExprOperator dummy_op;
if (opcode < JIM_TT_EXPR_OP) {
return &dummy_op;
}if (opcode < JIM_TT_EXPR_OP) { ... }
return &Jim_ExprOperators[opcode - JIM_TT_EXPR_OP];
}{ ... }
static int JimParseExprOperator(struct JimParserCtx *pc)
{
int i;
const struct Jim_ExprOperator *bestOp = NULL;
int bestLen = 0;
for (i = 0; i < (signed)JIM_EXPR_OPERATORS_NUM; i++) {
const struct Jim_ExprOperator *op = &Jim_ExprOperators[i];
if (op->name[0] != pc->p[0]) {
continue;
}if (op->name[0] != pc->p[0]) { ... }
if (op->namelen > bestLen && strncmp(op->name, pc->p, op->namelen) == 0) {
bestOp = op;
bestLen = op->namelen;
}if (op->namelen > bestLen && strncmp(op->name, pc->p, op->namelen) == 0) { ... }
}for (i = 0; i < (signed)JIM_EXPR_OPERATORS_NUM; i++) { ... }
if (bestOp == NULL) {
return JIM_ERR;
}if (bestOp == NULL) { ... }
if (bestOp->attr & OP_FUNC) {
const char *p = pc->p + bestLen;
int len = pc->len - bestLen;
while (len && isspace(UCHAR(*p))) {
len--;
p++;
}while (len && isspace(UCHAR(*p))) { ... }
if (*p != '(') {
return JIM_ERR;
}if (*p != '(') { ... }
}if (bestOp->attr & OP_FUNC) { ... }
pc->tend = pc->p + bestLen - 1;
pc->p += bestLen;
pc->len -= bestLen;
pc->tt = (bestOp - Jim_ExprOperators) + JIM_TT_EXPR_OP;
return JIM_OK;
}{ ... }
const char *jim_tt_name(int type)
{
static const char * const tt_names[JIM_TT_EXPR_OP] =
{ "NIL", "STR", "ESC", "VAR", "ARY", "CMD", "SEP", "EOL", "EOF", "LIN", "WRD", "(((", ")))", ",,,", "INT",
"DBL", "BOO", "$()" ...};
if (type < JIM_TT_EXPR_OP) {
return tt_names[type];
}if (type < JIM_TT_EXPR_OP) { ... }
else if (type == JIM_EXPROP_UNARYMINUS) {
return "-VE";
}else if (type == JIM_EXPROP_UNARYMINUS) { ... }
else if (type == JIM_EXPROP_UNARYPLUS) {
return "+VE";
}else if (type == JIM_EXPROP_UNARYPLUS) { ... }
else {
const struct Jim_ExprOperator *op = JimExprOperatorInfoByOpcode(type);
static char buf[20];
if (op->name) {
return op->name;
}if (op->name) { ... }
sprintf(buf, "(%d)", type);
return buf;
}else { ... }
}{ ... }
/* ... */
static void FreeExprInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupExprInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr);
static const Jim_ObjType exprObjType = {
"expression",
FreeExprInternalRep,
DupExprInternalRep,
NULL,
JIM_TYPE_NONE,
...};
struct ExprTree
{
struct JimExprNode *expr;
struct JimExprNode *nodes;
int len;
int inUse;
...};
static void ExprTreeFreeNodes(Jim_Interp *interp, struct JimExprNode *nodes, int num)
{
int i;
for (i = 0; i < num; i++) {
if (nodes[i].objPtr) {
Jim_DecrRefCount(interp, nodes[i].objPtr);
}if (nodes[i].objPtr) { ... }
}for (i = 0; i < num; i++) { ... }
Jim_Free(nodes);
}{ ... }
static void ExprTreeFree(Jim_Interp *interp, struct ExprTree *expr)
{
ExprTreeFreeNodes(interp, expr->nodes, expr->len);
Jim_Free(expr);
}{ ... }
static void FreeExprInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
struct ExprTree *expr = (void *)objPtr->internalRep.ptr;
if (expr) {
if (--expr->inUse != 0) {
return;
}if (--expr->inUse != 0) { ... }
ExprTreeFree(interp, expr);
}if (expr) { ... }
}{ ... }
static void DupExprInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
JIM_NOTUSED(interp);
JIM_NOTUSED(srcPtr);
dupPtr->typePtr = NULL;
}{ ... }
struct ExprBuilder {
int parencount;
int level;
ParseToken *token;
ParseToken *first_token;
Jim_Stack stack;
Jim_Obj *exprObjPtr;
Jim_Obj *fileNameObj;
struct JimExprNode *nodes;
struct JimExprNode *next;
...};
#ifdef DEBUG_SHOW_EXPR
static void JimShowExprNode(struct JimExprNode *node, int level)
{
int i;
for (i = 0; i < level; i++) {
printf(" ");
}for (i = 0; i < level; i++) { ... }
if (TOKEN_IS_EXPR_OP(node->type)) {
printf("%s\n", jim_tt_name(node->type));
if (node->left) {
JimShowExprNode(node->left, level + 1);
}if (node->left) { ... }
if (node->right) {
JimShowExprNode(node->right, level + 1);
}if (node->right) { ... }
if (node->ternary) {
JimShowExprNode(node->ternary, level + 1);
}if (node->ternary) { ... }
}if (TOKEN_IS_EXPR_OP(node->type)) { ... }
else {
printf("[%s] %s\n", jim_tt_name(node->type), Jim_String(node->objPtr));
}else { ... }
}JimShowExprNode (struct JimExprNode *node, int level) { ... }
/* ... */#endif
#define EXPR_UNTIL_CLOSE 0x0001
#define EXPR_FUNC_ARGS 0x0002
#define EXPR_TERNARY 0x0004
/* ... */
static int ExprTreeBuildTree(Jim_Interp *interp, struct ExprBuilder *builder, int precedence, int flags, int exp_numterms) {
int rc;
struct JimExprNode *node;
int exp_stacklen = builder->stack.len + exp_numterms;
if (builder->level++ > 200) {
Jim_SetResultString(interp, "Expression too complex", -1);
return JIM_ERR;
}if (builder->level++ > 200) { ... }
while (builder->token->type != JIM_TT_EOL) {
ParseToken *t = builder->token++;
int prevtt;
if (t == builder->first_token) {
prevtt = JIM_TT_NONE;
}if (t == builder->first_token) { ... }
else {
prevtt = t[-1].type;
}else { ... }
if (t->type == JIM_TT_SUBEXPR_START) {
if (builder->stack.len == exp_stacklen) {
Jim_SetResultFormatted(interp, "unexpected open parenthesis in expression: \"%#s\"", builder->exprObjPtr);
return JIM_ERR;
}if (builder->stack.len == exp_stacklen) { ... }
builder->parencount++;
rc = ExprTreeBuildTree(interp, builder, 0, EXPR_UNTIL_CLOSE, 1);
if (rc != JIM_OK) {
return rc;
}if (rc != JIM_OK) { ... }
}if (t->type == JIM_TT_SUBEXPR_START) { ... }
else if (t->type == JIM_TT_SUBEXPR_END) {
if (!(flags & EXPR_UNTIL_CLOSE)) {
if (builder->stack.len == exp_stacklen && builder->level > 1) {
builder->token--;
builder->level--;
return JIM_OK;
}if (builder->stack.len == exp_stacklen && builder->level > 1) { ... }
Jim_SetResultFormatted(interp, "unexpected closing parenthesis in expression: \"%#s\"", builder->exprObjPtr);
return JIM_ERR;
}if (!(flags & EXPR_UNTIL_CLOSE)) { ... }
builder->parencount--;
if (builder->stack.len == exp_stacklen) {
break;
}if (builder->stack.len == exp_stacklen) { ... }
}else if (t->type == JIM_TT_SUBEXPR_END) { ... }
else if (t->type == JIM_TT_SUBEXPR_COMMA) {
if (!(flags & EXPR_FUNC_ARGS)) {
if (builder->stack.len == exp_stacklen) {
builder->token--;
builder->level--;
return JIM_OK;
}if (builder->stack.len == exp_stacklen) { ... }
Jim_SetResultFormatted(interp, "unexpected comma in expression: \"%#s\"", builder->exprObjPtr);
return JIM_ERR;
}if (!(flags & EXPR_FUNC_ARGS)) { ... }
else {
if (builder->stack.len > exp_stacklen) {
Jim_SetResultFormatted(interp, "too many arguments to math function");
return JIM_ERR;
}if (builder->stack.len > exp_stacklen) { ... }
}else { ... }
}else if (t->type == JIM_TT_SUBEXPR_COMMA) { ... }
else if (t->type == JIM_EXPROP_COLON) {
if (!(flags & EXPR_TERNARY)) {
if (builder->level != 1) {
builder->token--;
builder->level--;
return JIM_OK;
}if (builder->level != 1) { ... }
Jim_SetResultFormatted(interp, ": without ? in expression: \"%#s\"", builder->exprObjPtr);
return JIM_ERR;
}if (!(flags & EXPR_TERNARY)) { ... }
if (builder->stack.len == exp_stacklen) {
builder->token--;
builder->level--;
return JIM_OK;
}if (builder->stack.len == exp_stacklen) { ... }
}else if (t->type == JIM_EXPROP_COLON) { ... }
else if (TOKEN_IS_EXPR_OP(t->type)) {
const struct Jim_ExprOperator *op;
if (TOKEN_IS_EXPR_OP(prevtt) || TOKEN_IS_EXPR_START(prevtt)) {
if (t->type == JIM_EXPROP_SUB) {
t->type = JIM_EXPROP_UNARYMINUS;
}if (t->type == JIM_EXPROP_SUB) { ... }
else if (t->type == JIM_EXPROP_ADD) {
t->type = JIM_EXPROP_UNARYPLUS;
}else if (t->type == JIM_EXPROP_ADD) { ... }
}if (TOKEN_IS_EXPR_OP(prevtt) || TOKEN_IS_EXPR_START(prevtt)) { ... }
op = JimExprOperatorInfoByOpcode(t->type);
if (op->precedence < precedence || (!(op->attr & OP_RIGHT_ASSOC) && op->precedence == precedence)) {
builder->token--;
break;
}if (op->precedence < precedence || (!(op->attr & OP_RIGHT_ASSOC) && op->precedence == precedence)) { ... }
if (op->attr & OP_FUNC) {
if (builder->token->type != JIM_TT_SUBEXPR_START) {
Jim_SetResultString(interp, "missing arguments for math function", -1);
return JIM_ERR;
}if (builder->token->type != JIM_TT_SUBEXPR_START) { ... }
builder->token++;
if (op->arity == 0) {
if (builder->token->type != JIM_TT_SUBEXPR_END) {
Jim_SetResultString(interp, "too many arguments for math function", -1);
return JIM_ERR;
}if (builder->token->type != JIM_TT_SUBEXPR_END) { ... }
builder->token++;
goto noargs;
}if (op->arity == 0) { ... }
builder->parencount++;
rc = ExprTreeBuildTree(interp, builder, 0, EXPR_FUNC_ARGS | EXPR_UNTIL_CLOSE, op->arity);
}if (op->attr & OP_FUNC) { ... }
else if (t->type == JIM_EXPROP_TERNARY) {
rc = ExprTreeBuildTree(interp, builder, op->precedence, EXPR_TERNARY, 2);
}else if (t->type == JIM_EXPROP_TERNARY) { ... }
else {
/* ... */
rc = ExprTreeBuildTree(interp, builder, op->precedence, 0, 1);
}else { ... }
if (rc != JIM_OK) {
return rc;
}if (rc != JIM_OK) { ... }
noargs:
node = builder->next++;
node->type = t->type;
if (op->arity >= 3) {
node->ternary = Jim_StackPop(&builder->stack);
if (node->ternary == NULL) {
goto missingoperand;
}if (node->ternary == NULL) { ... }
}if (op->arity >= 3) { ... }
if (op->arity >= 2) {
node->right = Jim_StackPop(&builder->stack);
if (node->right == NULL) {
goto missingoperand;
}if (node->right == NULL) { ... }
}if (op->arity >= 2) { ... }
if (op->arity >= 1) {
node->left = Jim_StackPop(&builder->stack);
if (node->left == NULL) {
missingoperand:
Jim_SetResultFormatted(interp, "missing operand to %s in expression: \"%#s\"", op->name, builder->exprObjPtr);
builder->next--;
return JIM_ERR;
}if (node->left == NULL) { ... }
}if (op->arity >= 1) { ... }
Jim_StackPush(&builder->stack, node);
}else if (TOKEN_IS_EXPR_OP(t->type)) { ... }
else {
Jim_Obj *objPtr = NULL;
if (!TOKEN_IS_EXPR_START(prevtt) && !TOKEN_IS_EXPR_OP(prevtt)) {
Jim_SetResultFormatted(interp, "missing operator in expression: \"%#s\"", builder->exprObjPtr);
return JIM_ERR;
}if (!TOKEN_IS_EXPR_START(prevtt) && !TOKEN_IS_EXPR_OP(prevtt)) { ... }
if (t->type == JIM_TT_EXPR_INT || t->type == JIM_TT_EXPR_DOUBLE) {
char *endptr;
if (t->type == JIM_TT_EXPR_INT) {
objPtr = Jim_NewIntObj(interp, jim_strtoull(t->token, &endptr));
}if (t->type == JIM_TT_EXPR_INT) { ... }
else {
objPtr = Jim_NewDoubleObj(interp, strtod(t->token, &endptr));
}else { ... }
if (endptr != t->token + t->len) {
Jim_FreeNewObj(interp, objPtr);
objPtr = NULL;
}if (endptr != t->token + t->len) { ... }
}if (t->type == JIM_TT_EXPR_INT || t->type == JIM_TT_EXPR_DOUBLE) { ... }
if (!objPtr) {
objPtr = Jim_NewStringObj(interp, t->token, t->len);
if (t->type == JIM_TT_CMD) {
JimSetSourceInfo(interp, objPtr, builder->fileNameObj, t->line);
}if (t->type == JIM_TT_CMD) { ... }
}if (!objPtr) { ... }
node = builder->next++;
node->objPtr = objPtr;
Jim_IncrRefCount(node->objPtr);
node->type = t->type;
Jim_StackPush(&builder->stack, node);
}else { ... }
}while (builder->token->type != JIM_TT_EOL) { ... }
if (builder->stack.len == exp_stacklen) {
builder->level--;
return JIM_OK;
}if (builder->stack.len == exp_stacklen) { ... }
if ((flags & EXPR_FUNC_ARGS)) {
Jim_SetResultFormatted(interp, "too %s arguments for math function", (builder->stack.len < exp_stacklen) ? "few" : "many");
}if ((flags & EXPR_FUNC_ARGS)) { ... }
else {
if (builder->stack.len < exp_stacklen) {
if (builder->level == 0) {
Jim_SetResultFormatted(interp, "empty expression");
}if (builder->level == 0) { ... }
else {
Jim_SetResultFormatted(interp, "syntax error in expression \"%#s\": premature end of expression", builder->exprObjPtr);
}else { ... }
}if (builder->stack.len < exp_stacklen) { ... }
else {
Jim_SetResultFormatted(interp, "extra terms after expression");
}else { ... }
}else { ... }
return JIM_ERR;
}{ ... }
static struct ExprTree *ExprTreeCreateTree(Jim_Interp *interp, const ParseTokenList *tokenlist, Jim_Obj *exprObjPtr, Jim_Obj *fileNameObj)
{
struct ExprTree *expr;
struct ExprBuilder builder;
int rc;
struct JimExprNode *top = NULL;
builder.parencount = 0;
builder.level = 0;
builder.token = builder.first_token = tokenlist->list;
builder.exprObjPtr = exprObjPtr;
builder.fileNameObj = fileNameObj;
builder.nodes = Jim_Alloc(sizeof(struct JimExprNode) * (tokenlist->count - 1));
memset(builder.nodes, 0, sizeof(struct JimExprNode) * (tokenlist->count - 1));
builder.next = builder.nodes;
Jim_InitStack(&builder.stack);
rc = ExprTreeBuildTree(interp, &builder, 0, 0, 1);
if (rc == JIM_OK) {
top = Jim_StackPop(&builder.stack);
if (builder.parencount) {
Jim_SetResultString(interp, "missing close parenthesis", -1);
rc = JIM_ERR;
}if (builder.parencount) { ... }
}if (rc == JIM_OK) { ... }
Jim_FreeStack(&builder.stack);
if (rc != JIM_OK) {
ExprTreeFreeNodes(interp, builder.nodes, builder.next - builder.nodes);
return NULL;
}if (rc != JIM_OK) { ... }
expr = Jim_Alloc(sizeof(*expr));
expr->inUse = 1;
expr->expr = top;
expr->nodes = builder.nodes;
expr->len = builder.next - builder.nodes;
assert(expr->len <= tokenlist->count - 1);
return expr;
}{ ... }
/* ... */
static int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr)
{
int exprTextLen;
const char *exprText;
struct JimParserCtx parser;
struct ExprTree *expr;
ParseTokenList tokenlist;
int line;
Jim_Obj *fileNameObj;
int rc = JIM_ERR;
if (objPtr->typePtr == &sourceObjType) {
fileNameObj = objPtr->internalRep.sourceValue.fileNameObj;
line = objPtr->internalRep.sourceValue.lineNumber;
}if (objPtr->typePtr == &sourceObjType) { ... }
else {
fileNameObj = interp->emptyObj;
line = 1;
}else { ... }
Jim_IncrRefCount(fileNameObj);
exprText = Jim_GetString(objPtr, &exprTextLen);
ScriptTokenListInit(&tokenlist);
JimParserInit(&parser, exprText, exprTextLen, line);
while (!parser.eof) {
if (JimParseExpression(&parser) != JIM_OK) {
ScriptTokenListFree(&tokenlist);
Jim_SetResultFormatted(interp, "syntax error in expression: \"%#s\"", objPtr);
expr = NULL;
goto err;
}if (JimParseExpression(&parser) != JIM_OK) { ... }
ScriptAddToken(&tokenlist, parser.tstart, parser.tend - parser.tstart + 1, parser.tt,
parser.tline);
}while (!parser.eof) { ... }
#ifdef DEBUG_SHOW_EXPR_TOKENS
{
int i;
printf("==== Expr Tokens (%s) ====\n", Jim_String(fileNameObj));
for (i = 0; i < tokenlist.count; i++) {
printf("[%2d]@%d %s '%.*s'\n", i, tokenlist.list[i].line, jim_tt_name(tokenlist.list[i].type),
tokenlist.list[i].len, tokenlist.list[i].token);
}for (i = 0; i < tokenlist.count; i++) { ... }
...}/* ... */
#endif
if (JimParseCheckMissing(interp, parser.missing.ch) == JIM_ERR) {
ScriptTokenListFree(&tokenlist);
Jim_DecrRefCount(interp, fileNameObj);
return JIM_ERR;
}if (JimParseCheckMissing(interp, parser.missing.ch) == JIM_ERR) { ... }
expr = ExprTreeCreateTree(interp, &tokenlist, objPtr, fileNameObj);
ScriptTokenListFree(&tokenlist);
if (!expr) {
goto err;
}if (!expr) { ... }
#ifdef DEBUG_SHOW_EXPR
printf("==== Expr ====\n");
JimShowExprNode(expr->expr, 0);/* ... */
#endif
rc = JIM_OK;
err:
Jim_DecrRefCount(interp, fileNameObj);
Jim_FreeIntRep(interp, objPtr);
Jim_SetIntRepPtr(objPtr, expr);
objPtr->typePtr = &exprObjType;
return rc;
}{ ... }
static struct ExprTree *JimGetExpression(Jim_Interp *interp, Jim_Obj *objPtr)
{
if (objPtr->typePtr != &exprObjType) {
if (SetExprFromAny(interp, objPtr) != JIM_OK) {
return NULL;
}if (SetExprFromAny(interp, objPtr) != JIM_OK) { ... }
}if (objPtr->typePtr != &exprObjType) { ... }
return (struct ExprTree *) Jim_GetIntRepPtr(objPtr);
}{ ... }
#ifdef JIM_OPTIMIZATION
static Jim_Obj *JimExprIntValOrVar(Jim_Interp *interp, struct JimExprNode *node)
{
if (node->type == JIM_TT_EXPR_INT)
return node->objPtr;
else if (node->type == JIM_TT_VAR)
return Jim_GetVariable(interp, node->objPtr, JIM_NONE);
else if (node->type == JIM_TT_DICTSUGAR)
return JimExpandDictSugar(interp, node->objPtr);
else
return NULL;
}{ ... }
/* ... */#endif
/* ... */
static int JimExprEvalTermNode(Jim_Interp *interp, struct JimExprNode *node)
{
if (TOKEN_IS_EXPR_OP(node->type)) {
const struct Jim_ExprOperator *op = JimExprOperatorInfoByOpcode(node->type);
return op->funcop(interp, node);
}if (TOKEN_IS_EXPR_OP(node->type)) { ... }
else {
Jim_Obj *objPtr;
switch (node->type) {
case JIM_TT_EXPR_INT:
case JIM_TT_EXPR_DOUBLE:
case JIM_TT_EXPR_BOOLEAN:
case JIM_TT_STR:
Jim_SetResult(interp, node->objPtr);
return JIM_OK;
case JIM_TT_STR:
case JIM_TT_VAR:
objPtr = Jim_GetVariable(interp, node->objPtr, JIM_ERRMSG);
if (objPtr) {
Jim_SetResult(interp, objPtr);
return JIM_OK;
}if (objPtr) { ... }
return JIM_ERR;
case JIM_TT_VAR:
case JIM_TT_DICTSUGAR:
objPtr = JimExpandDictSugar(interp, node->objPtr);
if (objPtr) {
Jim_SetResult(interp, objPtr);
return JIM_OK;
}if (objPtr) { ... }
return JIM_ERR;
case JIM_TT_DICTSUGAR:
case JIM_TT_ESC:
if (interp->safeexpr) {
return JIM_ERR;
}if (interp->safeexpr) { ... }
if (Jim_SubstObj(interp, node->objPtr, &objPtr, JIM_NONE) == JIM_OK) {
Jim_SetResult(interp, objPtr);
return JIM_OK;
}if (Jim_SubstObj(interp, node->objPtr, &objPtr, JIM_NONE) == JIM_OK) { ... }
return JIM_ERR;
case JIM_TT_ESC:
case JIM_TT_CMD:
if (interp->safeexpr) {
return JIM_ERR;
}if (interp->safeexpr) { ... }
return Jim_EvalObj(interp, node->objPtr);
case JIM_TT_CMD:
default:
return JIM_ERR;default
}switch (node->type) { ... }
}else { ... }
}{ ... }
static int JimExprGetTerm(Jim_Interp *interp, struct JimExprNode *node, Jim_Obj **objPtrPtr)
{
int rc = JimExprEvalTermNode(interp, node);
if (rc == JIM_OK) {
*objPtrPtr = Jim_GetResult(interp);
Jim_IncrRefCount(*objPtrPtr);
}if (rc == JIM_OK) { ... }
return rc;
}{ ... }
static int JimExprGetTermBoolean(Jim_Interp *interp, struct JimExprNode *node)
{
if (JimExprEvalTermNode(interp, node) == JIM_OK) {
return ExprBool(interp, Jim_GetResult(interp));
}if (JimExprEvalTermNode(interp, node) == JIM_OK) { ... }
return -1;
}{ ... }
int Jim_EvalExpression(Jim_Interp *interp, Jim_Obj *exprObjPtr)
{
struct ExprTree *expr;
int retcode = JIM_OK;
Jim_IncrRefCount(exprObjPtr);
expr = JimGetExpression(interp, exprObjPtr);
if (!expr) {
retcode = JIM_ERR;
goto done;
}if (!expr) { ... }
#ifdef JIM_OPTIMIZATION
/* ... */
if (!interp->safeexpr) {
Jim_Obj *objPtr;
/* ... */
switch (expr->len) {
case 1:
objPtr = JimExprIntValOrVar(interp, expr->expr);
if (objPtr) {
Jim_SetResult(interp, objPtr);
goto done;
}if (objPtr) { ... }
break;
case 1:
case 2:
if (expr->expr->type == JIM_EXPROP_NOT) {
objPtr = JimExprIntValOrVar(interp, expr->expr->left);
if (objPtr && JimIsWide(objPtr)) {
Jim_SetResult(interp, JimWideValue(objPtr) ? interp->falseObj : interp->trueObj);
goto done;
}if (objPtr && JimIsWide(objPtr)) { ... }
}if (expr->expr->type == JIM_EXPROP_NOT) { ... }
break;
case 2:
case 3:
objPtr = JimExprIntValOrVar(interp, expr->expr->left);
if (objPtr && JimIsWide(objPtr)) {
Jim_Obj *objPtr2 = JimExprIntValOrVar(interp, expr->expr->right);
if (objPtr2 && JimIsWide(objPtr2)) {
jim_wide wideValueA = JimWideValue(objPtr);
jim_wide wideValueB = JimWideValue(objPtr2);
int cmpRes;
switch (expr->expr->type) {
case JIM_EXPROP_LT:
cmpRes = wideValueA < wideValueB;
break;case JIM_EXPROP_LT:
case JIM_EXPROP_LTE:
cmpRes = wideValueA <= wideValueB;
break;case JIM_EXPROP_LTE:
case JIM_EXPROP_GT:
cmpRes = wideValueA > wideValueB;
break;case JIM_EXPROP_GT:
case JIM_EXPROP_GTE:
cmpRes = wideValueA >= wideValueB;
break;case JIM_EXPROP_GTE:
case JIM_EXPROP_NUMEQ:
cmpRes = wideValueA == wideValueB;
break;case JIM_EXPROP_NUMEQ:
case JIM_EXPROP_NUMNE:
cmpRes = wideValueA != wideValueB;
break;case JIM_EXPROP_NUMNE:
default:
goto noopt;default
}switch (expr->expr->type) { ... }
Jim_SetResult(interp, cmpRes ? interp->trueObj : interp->falseObj);
goto done;
}if (objPtr2 && JimIsWide(objPtr2)) { ... }
}if (objPtr && JimIsWide(objPtr)) { ... }
break;case 3:
}switch (expr->len) { ... }
}if (!interp->safeexpr) { ... }
noopt:/* ... */
#endif
/* ... */
expr->inUse++;
retcode = JimExprEvalTermNode(interp, expr->expr);
Jim_FreeIntRep(interp, exprObjPtr);
exprObjPtr->typePtr = &exprObjType;
Jim_SetIntRepPtr(exprObjPtr, expr);
done:
Jim_DecrRefCount(interp, exprObjPtr);
return retcode;
}{ ... }
int Jim_GetBoolFromExpr(Jim_Interp *interp, Jim_Obj *exprObjPtr, int *boolPtr)
{
int retcode = Jim_EvalExpression(interp, exprObjPtr);
if (retcode == JIM_OK) {
switch (ExprBool(interp, Jim_GetResult(interp))) {
case 0:
*boolPtr = 0;
break;
case 0:
case 1:
*boolPtr = 1;
break;
case 1:
case -1:
retcode = JIM_ERR;
break;case -1:
}switch (ExprBool(interp, Jim_GetResult(interp))) { ... }
}if (retcode == JIM_OK) { ... }
return retcode;
}{ ... }
/* ... */
/* ... */
/* ... */
typedef struct ScanFmtPartDescr
{
const char *arg;
const char *prefix;
size_t width;
int pos;
char type;
char modifier;
...} ScanFmtPartDescr;
/* ... */
typedef struct ScanFmtStringObj
{
jim_wide size;
char *stringRep;
size_t count;
size_t convCount;
size_t maxPos;
const char *error;
char *scratch;
ScanFmtPartDescr descr[1];
...} ScanFmtStringObj;
static void FreeScanFmtInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
static void DupScanFmtInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static void UpdateStringOfScanFmt(Jim_Obj *objPtr);
static const Jim_ObjType scanFmtStringObjType = {
"scanformatstring",
FreeScanFmtInternalRep,
DupScanFmtInternalRep,
UpdateStringOfScanFmt,
JIM_TYPE_NONE,
...};
void FreeScanFmtInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
{
JIM_NOTUSED(interp);
Jim_Free((char *)objPtr->internalRep.ptr);
objPtr->internalRep.ptr = 0;
}{ ... }
void DupScanFmtInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
{
size_t size = (size_t) ((ScanFmtStringObj *) srcPtr->internalRep.ptr)->size;
ScanFmtStringObj *newVec = (ScanFmtStringObj *) Jim_Alloc(size);
JIM_NOTUSED(interp);
memcpy(newVec, srcPtr->internalRep.ptr, size);
dupPtr->internalRep.ptr = newVec;
dupPtr->typePtr = &scanFmtStringObjType;
}{ ... }
static void UpdateStringOfScanFmt(Jim_Obj *objPtr)
{
JimSetStringBytes(objPtr, ((ScanFmtStringObj *) objPtr->internalRep.ptr)->stringRep);
}{ ... }
/* ... */
static int SetScanFmtFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{
ScanFmtStringObj *fmtObj;
char *buffer;
int maxCount, i, approxSize, lastPos = -1;
const char *fmt = Jim_String(objPtr);
int maxFmtLen = Jim_Length(objPtr);
const char *fmtEnd = fmt + maxFmtLen;
int curr;
Jim_FreeIntRep(interp, objPtr);
for (i = 0, maxCount = 0; i < maxFmtLen; ++i)
if (fmt[i] == '%')
++maxCount;
approxSize = sizeof(ScanFmtStringObj)
+(maxCount + 1) * sizeof(ScanFmtPartDescr)
+maxFmtLen * sizeof(char) + 3 + 1
+ maxFmtLen * sizeof(char) + 1
+ maxFmtLen * sizeof(char)
+(maxCount + 1) * sizeof(char)
+1;
fmtObj = (ScanFmtStringObj *) Jim_Alloc(approxSize);
memset(fmtObj, 0, approxSize);
fmtObj->size = approxSize;
fmtObj->maxPos = 0;
fmtObj->scratch = (char *)&fmtObj->descr[maxCount + 1];
fmtObj->stringRep = fmtObj->scratch + maxFmtLen + 3 + 1;
memcpy(fmtObj->stringRep, fmt, maxFmtLen);
buffer = fmtObj->stringRep + maxFmtLen + 1;
objPtr->internalRep.ptr = fmtObj;
objPtr->typePtr = &scanFmtStringObjType;
for (i = 0, curr = 0; fmt < fmtEnd; ++fmt) {
int width = 0, skip;
ScanFmtPartDescr *descr = &fmtObj->descr[curr];
fmtObj->count++;
descr->width = 0;
if (*fmt != '%' || fmt[1] == '%') {
descr->type = 0;
descr->prefix = &buffer[i];
for (; fmt < fmtEnd; ++fmt) {
if (*fmt == '%') {
if (fmt[1] != '%')
break;
++fmt;
}if (*fmt == '%') { ... }
buffer[i++] = *fmt;
}for (; fmt < fmtEnd; ++fmt) { ... }
buffer[i++] = 0;
}if (*fmt != '%' || fmt[1] == '%') { ... }
++fmt;
if (fmt >= fmtEnd)
goto done;
descr->pos = 0;
if (*fmt == '*') {
descr->pos = -1;
++fmt;
}if (*fmt == '*') { ... }
else
fmtObj->convCount++;
if (sscanf(fmt, "%d%n", &width, &skip) == 1) {
fmt += skip;
if (descr->pos != -1 && *fmt == '$') {
int prev;
++fmt;
descr->pos = width;
width = 0;
if ((lastPos == 0 && descr->pos > 0)
|| (lastPos > 0 && descr->pos == 0)) {
fmtObj->error = "cannot mix \"%\" and \"%n$\" conversion specifiers";
return JIM_ERR;
}if ((lastPos == 0 && descr->pos > 0) || (lastPos > 0 && descr->pos == 0)) { ... }
for (prev = 0; prev < curr; ++prev) {
if (fmtObj->descr[prev].pos == -1)
continue;
if (fmtObj->descr[prev].pos == descr->pos) {
fmtObj->error =
"variable is assigned by multiple \"%n$\" conversion specifiers";
return JIM_ERR;
}if (fmtObj->descr[prev].pos == descr->pos) { ... }
}for (prev = 0; prev < curr; ++prev) { ... }
if (descr->pos < 0) {
fmtObj->error =
"\"%n$\" conversion specifier is negative";
return JIM_ERR;
}if (descr->pos < 0) { ... }
if (sscanf(fmt, "%d%n", &width, &skip) == 1) {
descr->width = width;
fmt += skip;
}if (sscanf(fmt, "%d%n", &width, &skip) == 1) { ... }
if (descr->pos > 0 && (size_t) descr->pos > fmtObj->maxPos)
fmtObj->maxPos = descr->pos;
}if (descr->pos != -1 && *fmt == '$') { ... }
else {
descr->width = width;
}else { ... }
}if (sscanf(fmt, "%d%n", &width, &skip) == 1) { ... }
if (lastPos == -1)
lastPos = descr->pos;
if (*fmt == '[') {
int swapped = 1, beg = i, end, j;
descr->type = '[';
descr->arg = &buffer[i];
++fmt;
if (*fmt == '^')
buffer[i++] = *fmt++;
if (*fmt == ']')
buffer[i++] = *fmt++;
while (*fmt && *fmt != ']')
buffer[i++] = *fmt++;
if (*fmt != ']') {
fmtObj->error = "unmatched [ in format string";
return JIM_ERR;
}if (*fmt != ']') { ... }
end = i;
buffer[i++] = 0;
while (swapped) {
swapped = 0;
for (j = beg + 1; j < end - 1; ++j) {
if (buffer[j] == '-' && buffer[j - 1] > buffer[j + 1]) {
char tmp = buffer[j - 1];
buffer[j - 1] = buffer[j + 1];
buffer[j + 1] = tmp;
swapped = 1;
}if (buffer[j] == '-' && buffer[j - 1] > buffer[j + 1]) { ... }
}for (j = beg + 1; j < end - 1; ++j) { ... }
}while (swapped) { ... }
}if (*fmt == '[') { ... }
else {
if (fmt < fmtEnd && strchr("hlL", *fmt))
descr->modifier = tolower((int)*fmt++);
if (fmt >= fmtEnd) {
fmtObj->error = "missing scan conversion character";
return JIM_ERR;
}if (fmt >= fmtEnd) { ... }
descr->type = *fmt;
if (strchr("efgcsndoxui", *fmt) == 0) {
fmtObj->error = "bad scan conversion character";
return JIM_ERR;
}if (strchr("efgcsndoxui", *fmt) == 0) { ... }
else if (*fmt == 'c' && descr->width != 0) {
fmtObj->error = "field width may not be specified in %c " "conversion";
return JIM_ERR;
}else if (*fmt == 'c' && descr->width != 0) { ... }
else if (*fmt == 'u' && descr->modifier == 'l') {
fmtObj->error = "unsigned wide not supported";
return JIM_ERR;
}else if (*fmt == 'u' && descr->modifier == 'l') { ... }
}else { ... }
curr++;
}for (i = 0, curr = 0; fmt < fmtEnd; ++fmt) { ... }
done:
return JIM_OK;
}{ ... }
#define FormatGetCnvCount(_fo_) \
((ScanFmtStringObj*)((_fo_)->internalRep.ptr))->convCount...
#define FormatGetMaxPos(_fo_) \
((ScanFmtStringObj*)((_fo_)->internalRep.ptr))->maxPos...
#define FormatGetError(_fo_) \
((ScanFmtStringObj*)((_fo_)->internalRep.ptr))->error...
/* ... */
static Jim_Obj *JimScanAString(Jim_Interp *interp, const char *sdescr, const char *str)
{
char *buffer = Jim_StrDup(str);
char *p = buffer;
while (*str) {
int c;
int n;
if (!sdescr && isspace(UCHAR(*str)))
break;
n = utf8_tounicode(str, &c);
if (sdescr && !JimCharsetMatch(sdescr, strlen(sdescr), c, JIM_CHARSET_SCAN))
break;
while (n--)
*p++ = *str++;
}while (*str) { ... }
*p = 0;
return Jim_NewStringObjNoAlloc(interp, buffer, p - buffer);
}{ ... }
/* ... */
static int ScanOneEntry(Jim_Interp *interp, const char *str, int pos, int str_bytelen,
ScanFmtStringObj * fmtObj, long idx, Jim_Obj **valObjPtr)
{
const char *tok;
const ScanFmtPartDescr *descr = &fmtObj->descr[idx];
size_t scanned = 0;
size_t anchor = pos;
int i;
Jim_Obj *tmpObj = NULL;
*valObjPtr = 0;
if (descr->prefix) {
/* ... */
for (i = 0; pos < str_bytelen && descr->prefix[i]; ++i) {
if (isspace(UCHAR(descr->prefix[i])))
while (pos < str_bytelen && isspace(UCHAR(str[pos])))
++pos;
else if (descr->prefix[i] != str[pos])
break;
else
++pos;
}for (i = 0; pos < str_bytelen && descr->prefix[i]; ++i) { ... }
if (pos >= str_bytelen) {
return -1;
}if (pos >= str_bytelen) { ... }
else if (descr->prefix[i] != 0)
return 0;
}if (descr->prefix) { ... }
if (descr->type != 'c' && descr->type != '[' && descr->type != 'n')
while (isspace(UCHAR(str[pos])))
++pos;
scanned = pos - anchor;
if (descr->type == 'n') {
*valObjPtr = Jim_NewIntObj(interp, anchor + scanned);
}if (descr->type == 'n') { ... }
else if (pos >= str_bytelen) {
return -1;
}else if (pos >= str_bytelen) { ... }
else if (descr->type == 'c') {
int c;
scanned += utf8_tounicode(&str[pos], &c);
*valObjPtr = Jim_NewIntObj(interp, c);
return scanned;
}else if (descr->type == 'c') { ... }
else {
if (descr->width > 0) {
/* ... */
size_t sLen = utf8_strlen(&str[pos], str_bytelen - pos);
size_t tLen = descr->width > sLen ? sLen : descr->width;
tmpObj = Jim_NewStringObjUtf8(interp, str + pos, tLen);
tok = tmpObj->bytes;
}if (descr->width > 0) { ... }
else {
tok = &str[pos];
}else { ... }
switch (descr->type) {
case 'd':
case 'o':
case 'x':
case 'u':
case 'i':{
char *endp;
jim_wide w;
int base = descr->type == 'o' ? 8
: descr->type == 'x' ? 16 : descr->type == 'i' ? 0 : 10;
if (base == 0) {
w = jim_strtoull(tok, &endp);
}if (base == 0) { ... }
else {
w = strtoull(tok, &endp, base);
}else { ... }
if (endp != tok) {
*valObjPtr = Jim_NewIntObj(interp, w);
scanned += endp - tok;
}if (endp != tok) { ... }
else {
/* ... */
scanned = *tok ? 0 : -1;
}else { ... }
break;
...}case 'i':
case 's':
case '[':{
*valObjPtr = JimScanAString(interp, descr->arg, tok);
scanned += Jim_Length(*valObjPtr);
break;
...}case '[':
case 'e':
case 'f':
case 'g':{
char *endp;
double value = strtod(tok, &endp);
if (endp != tok) {
*valObjPtr = Jim_NewDoubleObj(interp, value);
scanned += endp - tok;
}if (endp != tok) { ... }
else {
/* ... */
scanned = *tok ? 0 : -1;
}else { ... }
break;
...}case 'g':
}switch (descr->type) { ... }
/* ... */
if (tmpObj) {
Jim_FreeNewObj(interp, tmpObj);
}if (tmpObj) { ... }
}else { ... }
return scanned;
}{ ... }
/* ... */
Jim_Obj *Jim_ScanString(Jim_Interp *interp, Jim_Obj *strObjPtr, Jim_Obj *fmtObjPtr, int flags)
{
size_t i, pos;
int scanned = 1;
const char *str = Jim_String(strObjPtr);
int str_bytelen = Jim_Length(strObjPtr);
Jim_Obj *resultList = 0;
Jim_Obj **resultVec = 0;
int resultc;
Jim_Obj *emptyStr = 0;
ScanFmtStringObj *fmtObj;
JimPanic((fmtObjPtr->typePtr != &scanFmtStringObjType, "Jim_ScanString() for non-scan format"));
fmtObj = (ScanFmtStringObj *) fmtObjPtr->internalRep.ptr;
if (fmtObj->error != 0) {
if (flags & JIM_ERRMSG)
Jim_SetResultString(interp, fmtObj->error, -1);
return 0;
}if (fmtObj->error != 0) { ... }
emptyStr = Jim_NewEmptyStringObj(interp);
Jim_IncrRefCount(emptyStr);
resultList = Jim_NewListObj(interp, NULL, 0);
if (fmtObj->maxPos > 0) {
for (i = 0; i < fmtObj->maxPos; ++i)
Jim_ListAppendElement(interp, resultList, emptyStr);
JimListGetElements(interp, resultList, &resultc, &resultVec);
}if (fmtObj->maxPos > 0) { ... }
for (i = 0, pos = 0; i < fmtObj->count; ++i) {
ScanFmtPartDescr *descr = &(fmtObj->descr[i]);
Jim_Obj *value = 0;
if (descr->type == 0)
continue;
if (scanned > 0)
scanned = ScanOneEntry(interp, str, pos, str_bytelen, fmtObj, i, &value);
if (scanned == -1 && i == 0)
goto eof;
pos += scanned;
if (value == 0)
value = Jim_NewEmptyStringObj(interp);
if (descr->pos == -1) {
Jim_FreeNewObj(interp, value);
}if (descr->pos == -1) { ... }
else if (descr->pos == 0)
Jim_ListAppendElement(interp, resultList, value);
else if (resultVec[descr->pos - 1] == emptyStr) {
Jim_DecrRefCount(interp, resultVec[descr->pos - 1]);
Jim_IncrRefCount(value);
resultVec[descr->pos - 1] = value;
}else if (resultVec[descr->pos - 1] == emptyStr) { ... }
else {
Jim_FreeNewObj(interp, value);
goto err;
}else { ... }
}for (i = 0, pos = 0; i < fmtObj->count; ++i) { ... }
Jim_DecrRefCount(interp, emptyStr);
return resultList;
eof:
Jim_DecrRefCount(interp, emptyStr);
Jim_FreeNewObj(interp, resultList);
return (Jim_Obj *)EOF;
err:
Jim_DecrRefCount(interp, emptyStr);
Jim_FreeNewObj(interp, resultList);
return 0;
}{ ... }
/* ... */
static void JimPrngInit(Jim_Interp *interp)
{
#define PRNG_SEED_SIZE 256
int i;
unsigned int *seed;
time_t t = time(NULL);
interp->prngState = Jim_Alloc(sizeof(Jim_PrngState));
seed = Jim_Alloc(PRNG_SEED_SIZE * sizeof(*seed));
for (i = 0; i < PRNG_SEED_SIZE; i++) {
seed[i] = (rand() ^ t ^ clock());
}for (i = 0; i < PRNG_SEED_SIZE; i++) { ... }
JimPrngSeed(interp, (unsigned char *)seed, PRNG_SEED_SIZE * sizeof(*seed));
Jim_Free(seed);
}{ ... }
static void JimRandomBytes(Jim_Interp *interp, void *dest, unsigned int len)
{
Jim_PrngState *prng;
unsigned char *destByte = (unsigned char *)dest;
unsigned int si, sj, x;
if (interp->prngState == NULL)
JimPrngInit(interp);
prng = interp->prngState;
for (x = 0; x < len; x++) {
prng->i = (prng->i + 1) & 0xff;
si = prng->sbox[prng->i];
prng->j = (prng->j + si) & 0xff;
sj = prng->sbox[prng->j];
prng->sbox[prng->i] = sj;
prng->sbox[prng->j] = si;
*destByte++ = prng->sbox[(si + sj) & 0xff];
}for (x = 0; x < len; x++) { ... }
}{ ... }
static void JimPrngSeed(Jim_Interp *interp, unsigned char *seed, int seedLen)
{
int i;
Jim_PrngState *prng;
if (interp->prngState == NULL)
JimPrngInit(interp);
prng = interp->prngState;
for (i = 0; i < 256; i++)
prng->sbox[i] = i;
for (i = 0; i < seedLen; i++) {
unsigned char t;
t = prng->sbox[i & 0xFF];
prng->sbox[i & 0xFF] = prng->sbox[seed[i]];
prng->sbox[seed[i]] = t;
}for (i = 0; i < seedLen; i++) { ... }
prng->i = prng->j = 0;
/* ... */
for (i = 0; i < 256; i += seedLen) {
JimRandomBytes(interp, seed, seedLen);
}for (i = 0; i < 256; i += seedLen) { ... }
}{ ... }
static int Jim_IncrCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_wide wideValue, increment = 1;
Jim_Obj *intObjPtr;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?increment?");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
if (argc == 3) {
if (Jim_GetWideExpr(interp, argv[2], &increment) != JIM_OK)
return JIM_ERR;
}if (argc == 3) { ... }
intObjPtr = Jim_GetVariable(interp, argv[1], JIM_UNSHARED);
if (!intObjPtr) {
wideValue = 0;
}if (!intObjPtr) { ... }
else if (Jim_GetWide(interp, intObjPtr, &wideValue) != JIM_OK) {
return JIM_ERR;
}else if (Jim_GetWide(interp, intObjPtr, &wideValue) != JIM_OK) { ... }
if (!intObjPtr || Jim_IsShared(intObjPtr)) {
intObjPtr = Jim_NewIntObj(interp, wideValue + increment);
if (Jim_SetVariable(interp, argv[1], intObjPtr) != JIM_OK) {
Jim_FreeNewObj(interp, intObjPtr);
return JIM_ERR;
}if (Jim_SetVariable(interp, argv[1], intObjPtr) != JIM_OK) { ... }
}if (!intObjPtr || Jim_IsShared(intObjPtr)) { ... }
else {
Jim_InvalidateStringRep(intObjPtr);
JimWideValue(intObjPtr) = wideValue + increment;
/* ... */
if (argv[1]->typePtr != &variableObjType) {
Jim_SetVariable(interp, argv[1], intObjPtr);
}if (argv[1]->typePtr != &variableObjType) { ... }
}else { ... }
Jim_SetResult(interp, intObjPtr);
return JIM_OK;
}{ ... }
/* ... */
#define JIM_EVAL_SARGV_LEN 8
#define JIM_EVAL_SINTV_LEN 8
static int JimTraceCallback(Jim_Interp *interp, const char *type, int argc, Jim_Obj *const *argv)
{
JimPanic((interp->traceCmdObj == NULL, "xtrace invoked with no object"));
int ret;
Jim_Obj *nargv[7];
Jim_Obj *traceCmdObj = interp->traceCmdObj;
Jim_Obj *resultObj = Jim_GetResult(interp);
ScriptObj *script = JimGetScript(interp, interp->currentScriptObj);
nargv[0] = traceCmdObj;
nargv[1] = Jim_NewStringObj(interp, type, -1);
nargv[2] = script->fileNameObj;
nargv[3] = Jim_NewIntObj(interp, script->linenr);
nargv[4] = resultObj;
nargv[5] = argv[0];
nargv[6] = Jim_NewListObj(interp, argv + 1, argc - 1);
interp->traceCmdObj = NULL;
Jim_IncrRefCount(resultObj);
ret = Jim_EvalObjVector(interp, 7, nargv);
Jim_DecrRefCount(interp, resultObj);
if (ret == JIM_OK || ret == JIM_RETURN) {
interp->traceCmdObj = traceCmdObj;
Jim_SetEmptyResult(interp);
ret = JIM_OK;
}if (ret == JIM_OK || ret == JIM_RETURN) { ... }
else {
Jim_DecrRefCount(interp, traceCmdObj);
}else { ... }
return ret;
}{ ... }
static int JimUnknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retcode;
/* ... */
if (interp->unknown_called > 50) {
return JIM_ERR;
}if (interp->unknown_called > 50) { ... }
/* ... */
if (Jim_GetCommand(interp, interp->unknown, JIM_NONE) == NULL)
return JIM_ERR;
interp->unknown_called++;
retcode = Jim_EvalObjPrefix(interp, interp->unknown, argc, argv);
interp->unknown_called--;
return retcode;
}{ ... }
static int JimInvokeCommand(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
int retcode;
Jim_Cmd *cmdPtr;
void *prevPrivData;
Jim_Obj *tailcallObj = NULL;
#if 0
printf("invoke");
int j;
for (j = 0; j < objc; j++) {
printf(" '%s'", Jim_String(objv[j]));
}for (j = 0; j < objc; j++) { ... }
printf("\n");/* ... */
#endif
cmdPtr = Jim_GetCommand(interp, objv[0], JIM_ERRMSG);
if (cmdPtr == NULL) {
return JimUnknown(interp, objc, objv);
}if (cmdPtr == NULL) { ... }
JimIncrCmdRefCount(cmdPtr);
if (interp->evalDepth == interp->maxEvalDepth) {
Jim_SetResultString(interp, "Infinite eval recursion", -1);
retcode = JIM_ERR;
goto out;
}if (interp->evalDepth == interp->maxEvalDepth) { ... }
interp->evalDepth++;
prevPrivData = interp->cmdPrivData;
tailcall:
if (!interp->traceCmdObj ||
(retcode = JimTraceCallback(interp, "cmd", objc, objv)) == JIM_OK) {
Jim_SetEmptyResult(interp);
if (cmdPtr->isproc) {
retcode = JimCallProcedure(interp, cmdPtr, objc, objv);
}if (cmdPtr->isproc) { ... }
else {
interp->cmdPrivData = cmdPtr->u.native.privData;
retcode = cmdPtr->u.native.cmdProc(interp, objc, objv);
}else { ... }
}if (!interp->traceCmdObj || (retcode = JimTraceCallback(interp, "cmd", objc, objv)) == JIM_OK) { ... }
if (tailcallObj) {
Jim_DecrRefCount(interp, tailcallObj);
tailcallObj = NULL;
}if (tailcallObj) { ... }
if (retcode == JIM_EVAL && interp->framePtr->tailcallObj) {
JimDecrCmdRefCount(interp, cmdPtr);
cmdPtr = interp->framePtr->tailcallCmd;
interp->framePtr->tailcallCmd = NULL;
tailcallObj = interp->framePtr->tailcallObj;
interp->framePtr->tailcallObj = NULL;
/* ... */
objc = tailcallObj->internalRep.listValue.len;
objv = tailcallObj->internalRep.listValue.ele;
goto tailcall;
}if (retcode == JIM_EVAL && interp->framePtr->tailcallObj) { ... }
interp->cmdPrivData = prevPrivData;
interp->evalDepth--;
out:
JimDecrCmdRefCount(interp, cmdPtr);
if (interp->framePtr->tailcallObj) {
/* ... */
JimDecrCmdRefCount(interp, interp->framePtr->tailcallCmd);
Jim_DecrRefCount(interp, interp->framePtr->tailcallObj);
interp->framePtr->tailcallCmd = NULL;
interp->framePtr->tailcallObj = NULL;
}if (interp->framePtr->tailcallObj) { ... }
return retcode;
}{ ... }
/* ... */
int Jim_EvalObjVector(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
int i, retcode;
for (i = 0; i < objc; i++)
Jim_IncrRefCount(objv[i]);
retcode = JimInvokeCommand(interp, objc, objv);
for (i = 0; i < objc; i++)
Jim_DecrRefCount(interp, objv[i]);
return retcode;
}{ ... }
/* ... */
int Jim_EvalObjPrefix(Jim_Interp *interp, Jim_Obj *prefix, int objc, Jim_Obj *const *objv)
{
int ret;
Jim_Obj **nargv = Jim_Alloc((objc + 1) * sizeof(*nargv));
nargv[0] = prefix;
memcpy(&nargv[1], &objv[0], sizeof(nargv[0]) * objc);
ret = Jim_EvalObjVector(interp, objc + 1, nargv);
Jim_Free(nargv);
return ret;
}{ ... }
static void JimAddErrorToStack(Jim_Interp *interp, ScriptObj *script)
{
if (!interp->errorFlag) {
interp->errorFlag = 1;
Jim_IncrRefCount(script->fileNameObj);
Jim_DecrRefCount(interp, interp->errorFileNameObj);
interp->errorFileNameObj = script->fileNameObj;
interp->errorLine = script->linenr;
JimResetStackTrace(interp);
interp->addStackTrace++;
}if (!interp->errorFlag) { ... }
if (interp->addStackTrace > 0) {
JimAppendStackTrace(interp, Jim_String(interp->errorProc), script->fileNameObj, script->linenr);
/* ... */
if (Jim_Length(script->fileNameObj)) {
interp->addStackTrace = 0;
}if (Jim_Length(script->fileNameObj)) { ... }
Jim_DecrRefCount(interp, interp->errorProc);
interp->errorProc = interp->emptyObj;
Jim_IncrRefCount(interp->errorProc);
}if (interp->addStackTrace > 0) { ... }
}{ ... }
static int JimSubstOneToken(Jim_Interp *interp, const ScriptToken *token, Jim_Obj **objPtrPtr)
{
Jim_Obj *objPtr;
int ret = JIM_ERR;
switch (token->type) {
case JIM_TT_STR:
case JIM_TT_ESC:
objPtr = token->objPtr;
break;case JIM_TT_ESC:
case JIM_TT_VAR:
objPtr = Jim_GetVariable(interp, token->objPtr, JIM_ERRMSG);
break;case JIM_TT_VAR:
case JIM_TT_DICTSUGAR:
objPtr = JimExpandDictSugar(interp, token->objPtr);
break;case JIM_TT_DICTSUGAR:
case JIM_TT_EXPRSUGAR:
ret = Jim_EvalExpression(interp, token->objPtr);
if (ret == JIM_OK) {
objPtr = Jim_GetResult(interp);
}if (ret == JIM_OK) { ... }
else {
objPtr = NULL;
}else { ... }
break;case JIM_TT_EXPRSUGAR:
case JIM_TT_CMD:
ret = Jim_EvalObj(interp, token->objPtr);
if (ret == JIM_OK || ret == JIM_RETURN) {
objPtr = interp->result;
}if (ret == JIM_OK || ret == JIM_RETURN) { ... } else {
objPtr = NULL;
}else { ... }
break;case JIM_TT_CMD:
default:
JimPanic((1,
"default token type (%d) reached " "in Jim_SubstObj().", token->type));
objPtr = NULL;
break;default
}switch (token->type) { ... }
if (objPtr) {
*objPtrPtr = objPtr;
return JIM_OK;
}if (objPtr) { ... }
return ret;
}{ ... }
/* ... */
static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * token, int tokens, int flags)
{
int totlen = 0, i;
Jim_Obj **intv;
Jim_Obj *sintv[JIM_EVAL_SINTV_LEN];
Jim_Obj *objPtr;
char *s;
if (tokens <= JIM_EVAL_SINTV_LEN)
intv = sintv;
else
intv = Jim_Alloc(sizeof(Jim_Obj *) * tokens);
/* ... */
for (i = 0; i < tokens; i++) {
switch (JimSubstOneToken(interp, &token[i], &intv[i])) {
case JIM_OK:
case JIM_RETURN:
break;case JIM_RETURN:
case JIM_BREAK:
if (flags & JIM_SUBST_FLAG) {
tokens = i;
continue;
}if (flags & JIM_SUBST_FLAG) { ... }
case JIM_BREAK:
case JIM_CONTINUE:
if (flags & JIM_SUBST_FLAG) {
intv[i] = NULL;
continue;
}if (flags & JIM_SUBST_FLAG) { ... }
case JIM_CONTINUE:
default:
while (i--) {
Jim_DecrRefCount(interp, intv[i]);
}while (i--) { ... }
if (intv != sintv) {
Jim_Free(intv);
}if (intv != sintv) { ... }
return NULL;default
}switch (JimSubstOneToken(interp, &token[i], &intv[i])) { ... }
Jim_IncrRefCount(intv[i]);
Jim_String(intv[i]);
totlen += intv[i]->length;
}for (i = 0; i < tokens; i++) { ... }
if (tokens == 1 && intv[0] && intv == sintv) {
intv[0]->refCount--;
return intv[0];
}if (tokens == 1 && intv[0] && intv == sintv) { ... }
/* ... */
objPtr = Jim_NewStringObjNoAlloc(interp, NULL, 0);
if (tokens == 4 && token[0].type == JIM_TT_ESC && token[1].type == JIM_TT_ESC
&& token[2].type == JIM_TT_VAR) {
objPtr->typePtr = &interpolatedObjType;
objPtr->internalRep.dictSubstValue.varNameObjPtr = token[0].objPtr;
objPtr->internalRep.dictSubstValue.indexObjPtr = intv[2];
Jim_IncrRefCount(intv[2]);
}if (tokens == 4 && token[0].type == JIM_TT_ESC && token[1].type == JIM_TT_ESC && token[2].type == JIM_TT_VAR) { ... }
else if (tokens && intv[0] && intv[0]->typePtr == &sourceObjType) {
JimSetSourceInfo(interp, objPtr, intv[0]->internalRep.sourceValue.fileNameObj, intv[0]->internalRep.sourceValue.lineNumber);
}else if (tokens && intv[0] && intv[0]->typePtr == &sourceObjType) { ... }
s = objPtr->bytes = Jim_Alloc(totlen + 1);
objPtr->length = totlen;
for (i = 0; i < tokens; i++) {
if (intv[i]) {
memcpy(s, intv[i]->bytes, intv[i]->length);
s += intv[i]->length;
Jim_DecrRefCount(interp, intv[i]);
}if (intv[i]) { ... }
}for (i = 0; i < tokens; i++) { ... }
objPtr->bytes[totlen] = '\0';
if (intv != sintv) {
Jim_Free(intv);
}if (intv != sintv) { ... }
return objPtr;
}{ ... }
/* ... */
static int JimEvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
{
int retcode = JIM_OK;
JimPanic((Jim_IsList(listPtr) == 0, "JimEvalObjList() invoked on non-list."));
if (listPtr->internalRep.listValue.len) {
Jim_IncrRefCount(listPtr);
retcode = JimInvokeCommand(interp,
listPtr->internalRep.listValue.len,
listPtr->internalRep.listValue.ele);
Jim_DecrRefCount(interp, listPtr);
}if (listPtr->internalRep.listValue.len) { ... }
return retcode;
}{ ... }
int Jim_EvalObjList(Jim_Interp *interp, Jim_Obj *listPtr)
{
SetListFromAny(interp, listPtr);
return JimEvalObjList(interp, listPtr);
}{ ... }
int Jim_EvalObj(Jim_Interp *interp, Jim_Obj *scriptObjPtr)
{
int i;
ScriptObj *script;
ScriptToken *token;
int retcode = JIM_OK;
Jim_Obj *sargv[JIM_EVAL_SARGV_LEN], **argv = NULL;
Jim_Obj *prevScriptObj;
/* ... */
if (Jim_IsList(scriptObjPtr) && scriptObjPtr->bytes == NULL) {
return JimEvalObjList(interp, scriptObjPtr);
}if (Jim_IsList(scriptObjPtr) && scriptObjPtr->bytes == NULL) { ... }
Jim_IncrRefCount(scriptObjPtr);
script = JimGetScript(interp, scriptObjPtr);
if (!JimScriptValid(interp, script)) {
Jim_DecrRefCount(interp, scriptObjPtr);
return JIM_ERR;
}if (!JimScriptValid(interp, script)) { ... }
/* ... */
Jim_SetEmptyResult(interp);
token = script->token;
#ifdef JIM_OPTIMIZATION
/* ... */
if (script->len == 0) {
Jim_DecrRefCount(interp, scriptObjPtr);
return JIM_OK;
}if (script->len == 0) { ... }
if (script->len == 3
&& token[1].objPtr->typePtr == &commandObjType
&& token[1].objPtr->internalRep.cmdValue.cmdPtr->isproc == 0
&& token[1].objPtr->internalRep.cmdValue.cmdPtr->u.native.cmdProc == Jim_IncrCoreCommand
&& token[2].objPtr->typePtr == &variableObjType) {
Jim_Obj *objPtr = Jim_GetVariable(interp, token[2].objPtr, JIM_NONE);
if (objPtr && !Jim_IsShared(objPtr) && objPtr->typePtr == &intObjType) {
JimWideValue(objPtr)++;
Jim_InvalidateStringRep(objPtr);
Jim_DecrRefCount(interp, scriptObjPtr);
Jim_SetResult(interp, objPtr);
return JIM_OK;
}if (objPtr && !Jim_IsShared(objPtr) && objPtr->typePtr == &intObjType) { ... }
}if (script->len == 3 && token[1].objPtr->typePtr == &commandObjType && token[1].objPtr->internalRep.cmdValue.cmdPtr->isproc == 0 && token[1].objPtr->internalRep.cmdValue.cmdPtr->u.native.cmdProc == Jim_IncrCoreCommand && token[2].objPtr->typePtr == &variableObjType) { ... }
/* ... */#endif
/* ... */
script->inUse++;
prevScriptObj = interp->currentScriptObj;
interp->currentScriptObj = scriptObjPtr;
interp->errorFlag = 0;
argv = sargv;
/* ... */
for (i = 0; i < script->len && retcode == JIM_OK; ) {
int argc;
int j;
argc = token[i].objPtr->internalRep.scriptLineValue.argc;
script->linenr = token[i].objPtr->internalRep.scriptLineValue.line;
if (argc > JIM_EVAL_SARGV_LEN)
argv = Jim_Alloc(sizeof(Jim_Obj *) * argc);
i++;
/* ... */
for (j = 0; j < argc; j++) {
long wordtokens = 1;
int expand = 0;
Jim_Obj *wordObjPtr = NULL;
if (token[i].type == JIM_TT_WORD) {
wordtokens = JimWideValue(token[i++].objPtr);
if (wordtokens < 0) {
expand = 1;
wordtokens = -wordtokens;
}if (wordtokens < 0) { ... }
}if (token[i].type == JIM_TT_WORD) { ... }
if (wordtokens == 1) {
/* ... */
switch (token[i].type) {
case JIM_TT_ESC:
case JIM_TT_STR:
wordObjPtr = token[i].objPtr;
break;case JIM_TT_STR:
case JIM_TT_VAR:
wordObjPtr = Jim_GetVariable(interp, token[i].objPtr, JIM_ERRMSG);
break;case JIM_TT_VAR:
case JIM_TT_EXPRSUGAR:
retcode = Jim_EvalExpression(interp, token[i].objPtr);
if (retcode == JIM_OK) {
wordObjPtr = Jim_GetResult(interp);
}if (retcode == JIM_OK) { ... }
else {
wordObjPtr = NULL;
}else { ... }
break;case JIM_TT_EXPRSUGAR:
case JIM_TT_DICTSUGAR:
wordObjPtr = JimExpandDictSugar(interp, token[i].objPtr);
break;case JIM_TT_DICTSUGAR:
case JIM_TT_CMD:
retcode = Jim_EvalObj(interp, token[i].objPtr);
if (retcode == JIM_OK) {
wordObjPtr = Jim_GetResult(interp);
}if (retcode == JIM_OK) { ... }
break;case JIM_TT_CMD:
default:
JimPanic((1, "default token type reached " "in Jim_EvalObj()."));default
}switch (token[i].type) { ... }
}if (wordtokens == 1) { ... }
else {
/* ... */
wordObjPtr = JimInterpolateTokens(interp, token + i, wordtokens, JIM_NONE);
}else { ... }
if (!wordObjPtr) {
if (retcode == JIM_OK) {
retcode = JIM_ERR;
}if (retcode == JIM_OK) { ... }
break;
}if (!wordObjPtr) { ... }
Jim_IncrRefCount(wordObjPtr);
i += wordtokens;
if (!expand) {
argv[j] = wordObjPtr;
}if (!expand) { ... }
else {
int len = Jim_ListLength(interp, wordObjPtr);
int newargc = argc + len - 1;
int k;
if (len > 1) {
if (argv == sargv) {
if (newargc > JIM_EVAL_SARGV_LEN) {
argv = Jim_Alloc(sizeof(*argv) * newargc);
memcpy(argv, sargv, sizeof(*argv) * j);
}if (newargc > JIM_EVAL_SARGV_LEN) { ... }
}if (argv == sargv) { ... }
else {
argv = Jim_Realloc(argv, sizeof(*argv) * newargc);
}else { ... }
}if (len > 1) { ... }
for (k = 0; k < len; k++) {
argv[j++] = wordObjPtr->internalRep.listValue.ele[k];
Jim_IncrRefCount(wordObjPtr->internalRep.listValue.ele[k]);
}for (k = 0; k < len; k++) { ... }
/* ... */
Jim_DecrRefCount(interp, wordObjPtr);
j--;
argc += len - 1;
}else { ... }
}for (j = 0; j < argc; j++) { ... }
if (retcode == JIM_OK && argc) {
retcode = JimInvokeCommand(interp, argc, argv);
if (Jim_CheckSignal(interp)) {
retcode = JIM_SIGNAL;
}if (Jim_CheckSignal(interp)) { ... }
}if (retcode == JIM_OK && argc) { ... }
while (j-- > 0) {
Jim_DecrRefCount(interp, argv[j]);
}while (j-- > 0) { ... }
if (argv != sargv) {
Jim_Free(argv);
argv = sargv;
}if (argv != sargv) { ... }
}for (i = 0; i < script->len && retcode == JIM_OK;) { ... }
if (retcode == JIM_ERR) {
JimAddErrorToStack(interp, script);
}if (retcode == JIM_ERR) { ... }
else if (retcode != JIM_RETURN || interp->returnCode != JIM_ERR) {
interp->addStackTrace = 0;
}else if (retcode != JIM_RETURN || interp->returnCode != JIM_ERR) { ... }
interp->currentScriptObj = prevScriptObj;
/* ... */
Jim_FreeIntRep(interp, scriptObjPtr);
scriptObjPtr->typePtr = &scriptObjType;
Jim_SetIntRepPtr(scriptObjPtr, script);
Jim_DecrRefCount(interp, scriptObjPtr);
return retcode;
}{ ... }
static int JimSetProcArg(Jim_Interp *interp, Jim_Obj *argNameObj, Jim_Obj *argValObj)
{
int retcode;
const char *varname = Jim_String(argNameObj);
if (*varname == '&') {
Jim_Obj *objPtr;
Jim_CallFrame *savedCallFrame = interp->framePtr;
interp->framePtr = interp->framePtr->parent;
objPtr = Jim_GetVariable(interp, argValObj, JIM_ERRMSG);
interp->framePtr = savedCallFrame;
if (!objPtr) {
return JIM_ERR;
}if (!objPtr) { ... }
objPtr = Jim_NewStringObj(interp, varname + 1, -1);
Jim_IncrRefCount(objPtr);
retcode = Jim_SetVariableLink(interp, objPtr, argValObj, interp->framePtr->parent);
Jim_DecrRefCount(interp, objPtr);
}if (*varname == '&') { ... }
else {
retcode = Jim_SetVariable(interp, argNameObj, argValObj);
}else { ... }
return retcode;
}{ ... }
/* ... */
static void JimSetProcWrongArgs(Jim_Interp *interp, Jim_Obj *procNameObj, Jim_Cmd *cmd)
{
Jim_Obj *argmsg = Jim_NewStringObj(interp, "", 0);
int i;
for (i = 0; i < cmd->u.proc.argListLen; i++) {
Jim_AppendString(interp, argmsg, " ", 1);
if (i == cmd->u.proc.argsPos) {
if (cmd->u.proc.arglist[i].defaultObjPtr) {
Jim_AppendString(interp, argmsg, "?", 1);
Jim_AppendObj(interp, argmsg, cmd->u.proc.arglist[i].defaultObjPtr);
Jim_AppendString(interp, argmsg, " ...?", -1);
}if (cmd->u.proc.arglist[i].defaultObjPtr) { ... }
else {
Jim_AppendString(interp, argmsg, "?arg ...?", -1);
}else { ... }
}if (i == cmd->u.proc.argsPos) { ... }
else {
if (cmd->u.proc.arglist[i].defaultObjPtr) {
Jim_AppendString(interp, argmsg, "?", 1);
Jim_AppendObj(interp, argmsg, cmd->u.proc.arglist[i].nameObjPtr);
Jim_AppendString(interp, argmsg, "?", 1);
}if (cmd->u.proc.arglist[i].defaultObjPtr) { ... }
else {
const char *arg = Jim_String(cmd->u.proc.arglist[i].nameObjPtr);
if (*arg == '&') {
arg++;
}if (*arg == '&') { ... }
Jim_AppendString(interp, argmsg, arg, -1);
}else { ... }
}else { ... }
}for (i = 0; i < cmd->u.proc.argListLen; i++) { ... }
Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s%#s\"", procNameObj, argmsg);
}{ ... }
#ifdef jim_ext_namespace
/* ... */
int Jim_EvalNamespace(Jim_Interp *interp, Jim_Obj *scriptObj, Jim_Obj *nsObj)
{
Jim_CallFrame *callFramePtr;
int retcode;
callFramePtr = JimCreateCallFrame(interp, interp->framePtr, nsObj);
callFramePtr->argv = &interp->emptyObj;
callFramePtr->argc = 0;
callFramePtr->procArgsObjPtr = NULL;
callFramePtr->procBodyObjPtr = scriptObj;
callFramePtr->staticVars = NULL;
callFramePtr->fileNameObj = interp->emptyObj;
callFramePtr->line = 0;
Jim_IncrRefCount(scriptObj);
interp->framePtr = callFramePtr;
if (interp->framePtr->level == interp->maxCallFrameDepth) {
Jim_SetResultString(interp, "Too many nested calls. Infinite recursion?", -1);
retcode = JIM_ERR;
}if (interp->framePtr->level == interp->maxCallFrameDepth) { ... }
else {
retcode = Jim_EvalObj(interp, scriptObj);
}else { ... }
interp->framePtr = interp->framePtr->parent;
JimFreeCallFrame(interp, callFramePtr, JIM_FCF_REUSE);
return retcode;
}{ ... }
#endif/* ... */
/* ... */
static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc, Jim_Obj *const *argv)
{
Jim_CallFrame *callFramePtr;
int i, d, retcode, optargs;
ScriptObj *script;
if (argc - 1 < cmd->u.proc.reqArity ||
(cmd->u.proc.argsPos < 0 && argc - 1 > cmd->u.proc.reqArity + cmd->u.proc.optArity)) {
JimSetProcWrongArgs(interp, argv[0], cmd);
return JIM_ERR;
}if (argc - 1 < cmd->u.proc.reqArity || (cmd->u.proc.argsPos < 0 && argc - 1 > cmd->u.proc.reqArity + cmd->u.proc.optArity)) { ... }
if (Jim_Length(cmd->u.proc.bodyObjPtr) == 0) {
return JIM_OK;
}if (Jim_Length(cmd->u.proc.bodyObjPtr) == 0) { ... }
if (interp->framePtr->level == interp->maxCallFrameDepth) {
Jim_SetResultString(interp, "Too many nested calls. Infinite recursion?", -1);
return JIM_ERR;
}if (interp->framePtr->level == interp->maxCallFrameDepth) { ... }
callFramePtr = JimCreateCallFrame(interp, interp->framePtr, cmd->u.proc.nsObj);
callFramePtr->argv = argv;
callFramePtr->argc = argc;
callFramePtr->procArgsObjPtr = cmd->u.proc.argListObjPtr;
callFramePtr->procBodyObjPtr = cmd->u.proc.bodyObjPtr;
callFramePtr->staticVars = cmd->u.proc.staticVars;
script = JimGetScript(interp, interp->currentScriptObj);
callFramePtr->fileNameObj = script->fileNameObj;
callFramePtr->line = script->linenr;
Jim_IncrRefCount(cmd->u.proc.argListObjPtr);
Jim_IncrRefCount(cmd->u.proc.bodyObjPtr);
interp->framePtr = callFramePtr;
optargs = (argc - 1 - cmd->u.proc.reqArity);
i = 1;
for (d = 0; d < cmd->u.proc.argListLen; d++) {
Jim_Obj *nameObjPtr = cmd->u.proc.arglist[d].nameObjPtr;
if (d == cmd->u.proc.argsPos) {
Jim_Obj *listObjPtr;
int argsLen = 0;
if (cmd->u.proc.reqArity + cmd->u.proc.optArity < argc - 1) {
argsLen = argc - 1 - (cmd->u.proc.reqArity + cmd->u.proc.optArity);
}if (cmd->u.proc.reqArity + cmd->u.proc.optArity < argc - 1) { ... }
listObjPtr = Jim_NewListObj(interp, &argv[i], argsLen);
if (cmd->u.proc.arglist[d].defaultObjPtr) {
nameObjPtr =cmd->u.proc.arglist[d].defaultObjPtr;
}if (cmd->u.proc.arglist[d].defaultObjPtr) { ... }
retcode = Jim_SetVariable(interp, nameObjPtr, listObjPtr);
if (retcode != JIM_OK) {
goto badargset;
}if (retcode != JIM_OK) { ... }
i += argsLen;
continue;
}if (d == cmd->u.proc.argsPos) { ... }
if (cmd->u.proc.arglist[d].defaultObjPtr == NULL || optargs-- > 0) {
retcode = JimSetProcArg(interp, nameObjPtr, argv[i++]);
}if (cmd->u.proc.arglist[d].defaultObjPtr == NULL || optargs-- > 0) { ... }
else {
retcode = Jim_SetVariable(interp, nameObjPtr, cmd->u.proc.arglist[d].defaultObjPtr);
}else { ... }
if (retcode != JIM_OK) {
goto badargset;
}if (retcode != JIM_OK) { ... }
}for (d = 0; d < cmd->u.proc.argListLen; d++) { ... }
if (interp->traceCmdObj == NULL ||
(retcode = JimTraceCallback(interp, "proc", argc, argv)) == JIM_OK) {
retcode = Jim_EvalObj(interp, cmd->u.proc.bodyObjPtr);
}if (interp->traceCmdObj == NULL || (retcode = JimTraceCallback(interp, "proc", argc, argv)) == JIM_OK) { ... }
badargset:
retcode = JimInvokeDefer(interp, retcode);
interp->framePtr = interp->framePtr->parent;
JimFreeCallFrame(interp, callFramePtr, JIM_FCF_REUSE);
if (retcode == JIM_RETURN) {
if (--interp->returnLevel <= 0) {
retcode = interp->returnCode;
interp->returnCode = JIM_OK;
interp->returnLevel = 0;
}if (--interp->returnLevel <= 0) { ... }
}if (retcode == JIM_RETURN) { ... }
else if (retcode == JIM_ERR) {
interp->addStackTrace++;
Jim_DecrRefCount(interp, interp->errorProc);
interp->errorProc = argv[0];
Jim_IncrRefCount(interp->errorProc);
}else if (retcode == JIM_ERR) { ... }
return retcode;
}{ ... }
int Jim_EvalSource(Jim_Interp *interp, const char *filename, int lineno, const char *script)
{
int retval;
Jim_Obj *scriptObjPtr;
scriptObjPtr = Jim_NewStringObj(interp, script, -1);
Jim_IncrRefCount(scriptObjPtr);
if (filename) {
Jim_Obj *prevScriptObj;
JimSetSourceInfo(interp, scriptObjPtr, Jim_NewStringObj(interp, filename, -1), lineno);
prevScriptObj = interp->currentScriptObj;
interp->currentScriptObj = scriptObjPtr;
retval = Jim_EvalObj(interp, scriptObjPtr);
interp->currentScriptObj = prevScriptObj;
}if (filename) { ... }
else {
retval = Jim_EvalObj(interp, scriptObjPtr);
}else { ... }
Jim_DecrRefCount(interp, scriptObjPtr);
return retval;
}{ ... }
int Jim_Eval(Jim_Interp *interp, const char *script)
{
return Jim_EvalObj(interp, Jim_NewStringObj(interp, script, -1));
}{ ... }
int Jim_EvalGlobal(Jim_Interp *interp, const char *script)
{
int retval;
Jim_CallFrame *savedFramePtr = interp->framePtr;
interp->framePtr = interp->topFramePtr;
retval = Jim_Eval(interp, script);
interp->framePtr = savedFramePtr;
return retval;
}{ ... }
int Jim_EvalFileGlobal(Jim_Interp *interp, const char *filename)
{
int retval;
Jim_CallFrame *savedFramePtr = interp->framePtr;
interp->framePtr = interp->topFramePtr;
retval = Jim_EvalFile(interp, filename);
interp->framePtr = savedFramePtr;
return retval;
}{ ... }
#include <sys/stat.h>
int Jim_EvalFile(Jim_Interp *interp, const char *filename)
{
FILE *fp;
char *buf;
Jim_Obj *scriptObjPtr;
Jim_Obj *prevScriptObj;
struct stat sb;
int retcode;
int readlen;
if (stat(filename, &sb) != 0 || (fp = fopen(filename, "rt")) == NULL) {
Jim_SetResultFormatted(interp, "couldn't read file \"%s\": %s", filename, strerror(errno));
return JIM_ERR;
}if (stat(filename, &sb) != 0 || (fp = fopen(filename, "rt")) == NULL) { ... }
if (sb.st_size == 0) {
fclose(fp);
return JIM_OK;
}if (sb.st_size == 0) { ... }
buf = Jim_Alloc(sb.st_size + 1);
readlen = fread(buf, 1, sb.st_size, fp);
if (ferror(fp)) {
fclose(fp);
Jim_Free(buf);
Jim_SetResultFormatted(interp, "failed to load file \"%s\": %s", filename, strerror(errno));
return JIM_ERR;
}if (ferror(fp)) { ... }
fclose(fp);
buf[readlen] = 0;
scriptObjPtr = Jim_NewStringObjNoAlloc(interp, buf, readlen);
JimSetSourceInfo(interp, scriptObjPtr, Jim_NewStringObj(interp, filename, -1), 1);
Jim_IncrRefCount(scriptObjPtr);
prevScriptObj = interp->currentScriptObj;
interp->currentScriptObj = scriptObjPtr;
retcode = Jim_EvalObj(interp, scriptObjPtr);
if (retcode == JIM_RETURN) {
if (--interp->returnLevel <= 0) {
retcode = interp->returnCode;
interp->returnCode = JIM_OK;
interp->returnLevel = 0;
}if (--interp->returnLevel <= 0) { ... }
}if (retcode == JIM_RETURN) { ... }
if (retcode == JIM_ERR) {
interp->addStackTrace++;
}if (retcode == JIM_ERR) { ... }
interp->currentScriptObj = prevScriptObj;
Jim_DecrRefCount(interp, scriptObjPtr);
return retcode;
}{ ... }
/* ... */
static void JimParseSubst(struct JimParserCtx *pc, int flags)
{
pc->tstart = pc->p;
pc->tline = pc->linenr;
if (pc->len == 0) {
pc->tend = pc->p;
pc->tt = JIM_TT_EOL;
pc->eof = 1;
return;
}if (pc->len == 0) { ... }
if (*pc->p == '[' && !(flags & JIM_SUBST_NOCMD)) {
JimParseCmd(pc);
return;
}if (*pc->p == '[' && !(flags & JIM_SUBST_NOCMD)) { ... }
if (*pc->p == '$' && !(flags & JIM_SUBST_NOVAR)) {
if (JimParseVar(pc) == JIM_OK) {
return;
}if (JimParseVar(pc) == JIM_OK) { ... }
pc->tstart = pc->p;
flags |= JIM_SUBST_NOVAR;
}if (*pc->p == '$' && !(flags & JIM_SUBST_NOVAR)) { ... }
while (pc->len) {
if (*pc->p == '$' && !(flags & JIM_SUBST_NOVAR)) {
break;
}if (*pc->p == '$' && !(flags & JIM_SUBST_NOVAR)) { ... }
if (*pc->p == '[' && !(flags & JIM_SUBST_NOCMD)) {
break;
}if (*pc->p == '[' && !(flags & JIM_SUBST_NOCMD)) { ... }
if (*pc->p == '\\' && pc->len > 1) {
pc->p++;
pc->len--;
}if (*pc->p == '\\' && pc->len > 1) { ... }
pc->p++;
pc->len--;
}while (pc->len) { ... }
pc->tend = pc->p - 1;
pc->tt = (flags & JIM_SUBST_NOESC) ? JIM_TT_STR : JIM_TT_ESC;
}{ ... }
/* ... */
/* ... */
static int SetSubstFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr, int flags)
{
int scriptTextLen;
const char *scriptText = Jim_GetString(objPtr, &scriptTextLen);
struct JimParserCtx parser;
struct ScriptObj *script = Jim_Alloc(sizeof(*script));
ParseTokenList tokenlist;
ScriptTokenListInit(&tokenlist);
JimParserInit(&parser, scriptText, scriptTextLen, 1);
while (1) {
JimParseSubst(&parser, flags);
if (parser.eof) {
break;
}if (parser.eof) { ... }
ScriptAddToken(&tokenlist, parser.tstart, parser.tend - parser.tstart + 1, parser.tt,
parser.tline);
}while (1) { ... }
script->inUse = 1;
script->substFlags = flags;
script->fileNameObj = interp->emptyObj;
Jim_IncrRefCount(script->fileNameObj);
SubstObjAddTokens(interp, script, &tokenlist);
ScriptTokenListFree(&tokenlist);
#ifdef DEBUG_SHOW_SUBST
{
int i;
printf("==== Subst ====\n");
for (i = 0; i < script->len; i++) {
printf("[%2d] %s '%s'\n", i, jim_tt_name(script->token[i].type),
Jim_String(script->token[i].objPtr));
}for (i = 0; i < script->len; i++) { ... }
...}/* ... */
#endif
Jim_FreeIntRep(interp, objPtr);
Jim_SetIntRepPtr(objPtr, script);
objPtr->typePtr = &scriptObjType;
return JIM_OK;
}{ ... }
static ScriptObj *Jim_GetSubst(Jim_Interp *interp, Jim_Obj *objPtr, int flags)
{
if (objPtr->typePtr != &scriptObjType || ((ScriptObj *)Jim_GetIntRepPtr(objPtr))->substFlags != flags)
SetSubstFromAny(interp, objPtr, flags);
return (ScriptObj *) Jim_GetIntRepPtr(objPtr);
}{ ... }
/* ... */
int Jim_SubstObj(Jim_Interp *interp, Jim_Obj *substObjPtr, Jim_Obj **resObjPtrPtr, int flags)
{
ScriptObj *script;
JimPanic((substObjPtr->refCount == 0, "Jim_SubstObj() called with zero refcount object"));
script = Jim_GetSubst(interp, substObjPtr, flags);
Jim_IncrRefCount(substObjPtr);
/* ... */
script->inUse++;
*resObjPtrPtr = JimInterpolateTokens(interp, script->token, script->len, flags);
script->inUse--;
Jim_DecrRefCount(interp, substObjPtr);
if (*resObjPtrPtr == NULL) {
return JIM_ERR;
}if (*resObjPtrPtr == NULL) { ... }
return JIM_OK;
}{ ... }
/* ... */
void Jim_WrongNumArgs(Jim_Interp *interp, int argc, Jim_Obj *const *argv, const char *msg)
{
Jim_Obj *objPtr;
Jim_Obj *listObjPtr;
JimPanic((argc == 0, "Jim_WrongNumArgs() called with argc=0"));
listObjPtr = Jim_NewListObj(interp, argv, argc);
if (msg && *msg) {
Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp, msg, -1));
}if (msg && *msg) { ... }
Jim_IncrRefCount(listObjPtr);
objPtr = Jim_ListJoin(interp, listObjPtr, " ", 1);
Jim_DecrRefCount(interp, listObjPtr);
Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s\"", objPtr);
}{ ... }
/* ... */
typedef void JimHashtableIteratorCallbackType(Jim_Interp *interp, Jim_Obj *listObjPtr,
Jim_Obj *keyObjPtr, void *value, Jim_Obj *patternObjPtr, int type);
#define JimTrivialMatch(pattern) (strpbrk((pattern), "*[?\\") == NULL)
/* ... */
static Jim_Obj *JimHashtablePatternMatch(Jim_Interp *interp, Jim_HashTable *ht, Jim_Obj *patternObjPtr,
JimHashtableIteratorCallbackType *callback, int type)
{
Jim_HashEntry *he;
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
if (patternObjPtr && JimTrivialMatch(Jim_String(patternObjPtr))) {
he = Jim_FindHashEntry(ht, patternObjPtr);
if (he) {
callback(interp, listObjPtr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he),
patternObjPtr, type);
}if (he) { ... }
}if (patternObjPtr && JimTrivialMatch(Jim_String(patternObjPtr))) { ... }
else {
Jim_HashTableIterator htiter;
JimInitHashTableIterator(ht, &htiter);
while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
callback(interp, listObjPtr, Jim_GetHashEntryKey(he), Jim_GetHashEntryVal(he),
patternObjPtr, type);
}while ((he = Jim_NextHashEntry(&htiter)) != NULL) { ... }
}else { ... }
return listObjPtr;
}{ ... }
#define JIM_CMDLIST_COMMANDS 0
#define JIM_CMDLIST_PROCS 1
#define JIM_CMDLIST_CHANNELS 2
/* ... */
static void JimCommandMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
Jim_Obj *keyObj, void *value, Jim_Obj *patternObj, int type)
{
Jim_Cmd *cmdPtr = (Jim_Cmd *)value;
if (type == JIM_CMDLIST_PROCS && !cmdPtr->isproc) {
return;
}if (type == JIM_CMDLIST_PROCS && !cmdPtr->isproc) { ... }
Jim_IncrRefCount(keyObj);
if (type != JIM_CMDLIST_CHANNELS || Jim_AioFilehandle(interp, keyObj)) {
int match = 1;
if (patternObj) {
int plen, slen;
const char *pattern = Jim_GetStringNoQualifier(patternObj, &plen);
const char *str = Jim_GetStringNoQualifier(keyObj, &slen);
match = JimGlobMatch(pattern, plen, str, slen, 0);
}if (patternObj) { ... }
if (match) {
Jim_ListAppendElement(interp, listObjPtr, keyObj);
}if (match) { ... }
}if (type != JIM_CMDLIST_CHANNELS || Jim_AioFilehandle(interp, keyObj)) { ... }
Jim_DecrRefCount(interp, keyObj);
}{ ... }
static Jim_Obj *JimCommandsList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int type)
{
return JimHashtablePatternMatch(interp, &interp->commands, patternObjPtr, JimCommandMatch, type);
}{ ... }
#define JIM_VARLIST_GLOBALS 0
#define JIM_VARLIST_LOCALS 1
#define JIM_VARLIST_VARS 2
#define JIM_VARLIST_MASK 0x000f
#define JIM_VARLIST_VALUES 0x1000
5 defines
/* ... */
static void JimVariablesMatch(Jim_Interp *interp, Jim_Obj *listObjPtr,
Jim_Obj *keyObj, void *value, Jim_Obj *patternObj, int type)
{
Jim_Var *varPtr = (Jim_Var *)value;
if ((type & JIM_VARLIST_MASK) != JIM_VARLIST_LOCALS || varPtr->linkFramePtr == NULL) {
if (patternObj == NULL || Jim_StringMatchObj(interp, patternObj, keyObj, 0)) {
Jim_ListAppendElement(interp, listObjPtr, keyObj);
if (type & JIM_VARLIST_VALUES) {
Jim_ListAppendElement(interp, listObjPtr, varPtr->objPtr);
}if (type & JIM_VARLIST_VALUES) { ... }
}if (patternObj == NULL || Jim_StringMatchObj(interp, patternObj, keyObj, 0)) { ... }
}if ((type & JIM_VARLIST_MASK) != JIM_VARLIST_LOCALS || varPtr->linkFramePtr == NULL) { ... }
}{ ... }
static Jim_Obj *JimVariablesList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int mode)
{
if (mode == JIM_VARLIST_LOCALS && interp->framePtr == interp->topFramePtr) {
/* ... */
return interp->emptyObj;
}if (mode == JIM_VARLIST_LOCALS && interp->framePtr == interp->topFramePtr) { ... }
else {
Jim_CallFrame *framePtr = (mode == JIM_VARLIST_GLOBALS) ? interp->topFramePtr : interp->framePtr;
return JimHashtablePatternMatch(interp, &framePtr->vars, patternObjPtr, JimVariablesMatch,
mode);
}else { ... }
}{ ... }
static int JimInfoLevel(Jim_Interp *interp, Jim_Obj *levelObjPtr,
Jim_Obj **objPtrPtr, int info_level_cmd)
{
Jim_CallFrame *targetCallFrame;
targetCallFrame = JimGetCallFrameByInteger(interp, levelObjPtr);
if (targetCallFrame == NULL) {
return JIM_ERR;
}if (targetCallFrame == NULL) { ... }
if (targetCallFrame == interp->topFramePtr) {
Jim_SetResultFormatted(interp, "bad level \"%#s\"", levelObjPtr);
return JIM_ERR;
}if (targetCallFrame == interp->topFramePtr) { ... }
if (info_level_cmd) {
*objPtrPtr = Jim_NewListObj(interp, targetCallFrame->argv, targetCallFrame->argc);
}if (info_level_cmd) { ... }
else {
Jim_Obj *listObj = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, listObj, targetCallFrame->argv[0]);
Jim_ListAppendElement(interp, listObj, targetCallFrame->fileNameObj);
Jim_ListAppendElement(interp, listObj, Jim_NewIntObj(interp, targetCallFrame->line));
*objPtrPtr = listObj;
}else { ... }
return JIM_OK;
}{ ... }
/* ... */
static int Jim_PutsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "?-nonewline? string");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
if (argc == 3) {
if (!Jim_CompareStringImmediate(interp, argv[1], "-nonewline")) {
Jim_SetResultString(interp, "The second argument must " "be -nonewline", -1);
return JIM_ERR;
}if (!Jim_CompareStringImmediate(interp, argv[1], "-nonewline")) { ... }
else {
fputs(Jim_String(argv[2]), stdout);
}else { ... }
}if (argc == 3) { ... }
else {
puts(Jim_String(argv[1]));
}else { ... }
return JIM_OK;
}{ ... }
static int JimAddMulHelper(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int op)
{
jim_wide wideValue, res;
double doubleValue, doubleRes;
int i;
res = (op == JIM_EXPROP_ADD) ? 0 : 1;
for (i = 1; i < argc; i++) {
if (Jim_GetWide(interp, argv[i], &wideValue) != JIM_OK)
goto trydouble;
if (op == JIM_EXPROP_ADD)
res += wideValue;
else
res *= wideValue;
}for (i = 1; i < argc; i++) { ... }
Jim_SetResultInt(interp, res);
return JIM_OK;
trydouble:
doubleRes = (double)res;
for (; i < argc; i++) {
if (Jim_GetDouble(interp, argv[i], &doubleValue) != JIM_OK)
return JIM_ERR;
if (op == JIM_EXPROP_ADD)
doubleRes += doubleValue;
else
doubleRes *= doubleValue;
}for (; i < argc; i++) { ... }
Jim_SetResult(interp, Jim_NewDoubleObj(interp, doubleRes));
return JIM_OK;
}{ ... }
static int JimSubDivHelper(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int op)
{
jim_wide wideValue, res = 0;
double doubleValue, doubleRes = 0;
int i = 2;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "number ?number ... number?");
return JIM_ERR;
}if (argc < 2) { ... }
else if (argc == 2) {
/* ... */
if (Jim_GetWide(interp, argv[1], &wideValue) != JIM_OK) {
if (Jim_GetDouble(interp, argv[1], &doubleValue) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetDouble(interp, argv[1], &doubleValue) != JIM_OK) { ... }
else {
if (op == JIM_EXPROP_SUB)
doubleRes = -doubleValue;
else
doubleRes = 1.0 / doubleValue;
Jim_SetResult(interp, Jim_NewDoubleObj(interp, doubleRes));
return JIM_OK;
}else { ... }
}if (Jim_GetWide(interp, argv[1], &wideValue) != JIM_OK) { ... }
if (op == JIM_EXPROP_SUB) {
res = -wideValue;
Jim_SetResultInt(interp, res);
}if (op == JIM_EXPROP_SUB) { ... }
else {
doubleRes = 1.0 / wideValue;
Jim_SetResult(interp, Jim_NewDoubleObj(interp, doubleRes));
}else { ... }
return JIM_OK;
}else if (argc == 2) { ... }
else {
if (Jim_GetWide(interp, argv[1], &res) != JIM_OK) {
if (Jim_GetDouble(interp, argv[1], &doubleRes)
!= JIM_OK) {
return JIM_ERR;
}if (Jim_GetDouble(interp, argv[1], &doubleRes) != JIM_OK) { ... }
else {
goto trydouble;
}else { ... }
}if (Jim_GetWide(interp, argv[1], &res) != JIM_OK) { ... }
}else { ... }
for (i = 2; i < argc; i++) {
if (Jim_GetWide(interp, argv[i], &wideValue) != JIM_OK) {
doubleRes = (double)res;
goto trydouble;
}if (Jim_GetWide(interp, argv[i], &wideValue) != JIM_OK) { ... }
if (op == JIM_EXPROP_SUB)
res -= wideValue;
else {
if (wideValue == 0) {
Jim_SetResultString(interp, "Division by zero", -1);
return JIM_ERR;
}if (wideValue == 0) { ... }
res /= wideValue;
}else { ... }
}for (i = 2; i < argc; i++) { ... }
Jim_SetResultInt(interp, res);
return JIM_OK;
trydouble:
for (; i < argc; i++) {
if (Jim_GetDouble(interp, argv[i], &doubleValue) != JIM_OK)
return JIM_ERR;
if (op == JIM_EXPROP_SUB)
doubleRes -= doubleValue;
else
doubleRes /= doubleValue;
}for (; i < argc; i++) { ... }
Jim_SetResult(interp, Jim_NewDoubleObj(interp, doubleRes));
return JIM_OK;
}{ ... }
static int Jim_AddCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimAddMulHelper(interp, argc, argv, JIM_EXPROP_ADD);
}{ ... }
static int Jim_MulCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimAddMulHelper(interp, argc, argv, JIM_EXPROP_MUL);
}{ ... }
static int Jim_SubCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimSubDivHelper(interp, argc, argv, JIM_EXPROP_SUB);
}{ ... }
static int Jim_DivCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimSubDivHelper(interp, argc, argv, JIM_EXPROP_DIV);
}{ ... }
static int Jim_SetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?newValue?");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
if (argc == 2) {
Jim_Obj *objPtr;
objPtr = Jim_GetVariable(interp, argv[1], JIM_ERRMSG);
if (!objPtr)
return JIM_ERR;
Jim_SetResult(interp, objPtr);
return JIM_OK;
}if (argc == 2) { ... }
if (Jim_SetVariable(interp, argv[1], argv[2]) != JIM_OK)
return JIM_ERR;
Jim_SetResult(interp, argv[2]);
return JIM_OK;
}{ ... }
/* ... */
static int Jim_UnsetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int i = 1;
int complain = 1;
while (i < argc) {
if (Jim_CompareStringImmediate(interp, argv[i], "--")) {
i++;
break;
}if (Jim_CompareStringImmediate(interp, argv[i], "--")) { ... }
if (Jim_CompareStringImmediate(interp, argv[i], "-nocomplain")) {
complain = 0;
i++;
continue;
}if (Jim_CompareStringImmediate(interp, argv[i], "-nocomplain")) { ... }
break;
}while (i < argc) { ... }
while (i < argc) {
if (Jim_UnsetVariable(interp, argv[i], complain ? JIM_ERRMSG : JIM_NONE) != JIM_OK
&& complain) {
return JIM_ERR;
}if (Jim_UnsetVariable(interp, argv[i], complain ? JIM_ERRMSG : JIM_NONE) != JIM_OK && complain) { ... }
i++;
}while (i < argc) { ... }
return JIM_OK;
}{ ... }
static int Jim_WhileCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "condition body");
return JIM_ERR;
}if (argc != 3) { ... }
while (1) {
int boolean, retval;
if ((retval = Jim_GetBoolFromExpr(interp, argv[1], &boolean)) != JIM_OK)
return retval;
if (!boolean)
break;
if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) {
switch (retval) {
case JIM_BREAK:
goto out;
break;case JIM_BREAK:
case JIM_CONTINUE:
continue;
break;case JIM_CONTINUE:
default:
return retval;default
}switch (retval) { ... }
}if ((retval = Jim_EvalObj(interp, argv[2])) != JIM_OK) { ... }
}while (1) { ... }
out:
Jim_SetEmptyResult(interp);
return JIM_OK;
}{ ... }
static int Jim_ForCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retval;
int boolean = 1;
Jim_Obj *varNamePtr = NULL;
Jim_Obj *stopVarNamePtr = NULL;
if (argc != 5) {
Jim_WrongNumArgs(interp, 1, argv, "start test next body");
return JIM_ERR;
}if (argc != 5) { ... }
if ((retval = Jim_EvalObj(interp, argv[1])) != JIM_OK) {
return retval;
}if ((retval = Jim_EvalObj(interp, argv[1])) != JIM_OK) { ... }
/* ... */
retval = Jim_GetBoolFromExpr(interp, argv[2], &boolean);
/* ... */
#ifdef JIM_OPTIMIZATION
/* ... */
if (retval == JIM_OK && boolean) {
ScriptObj *incrScript;
struct ExprTree *expr;
jim_wide stop, currentVal;
Jim_Obj *objPtr;
int cmpOffset;
expr = JimGetExpression(interp, argv[2]);
incrScript = JimGetScript(interp, argv[3]);
if (incrScript == NULL || incrScript->len != 3 || !expr || expr->len != 3) {
goto evalstart;
}if (incrScript == NULL || incrScript->len != 3 || !expr || expr->len != 3) { ... }
if (incrScript->token[1].type != JIM_TT_ESC) {
goto evalstart;
}if (incrScript->token[1].type != JIM_TT_ESC) { ... }
if (expr->expr->type == JIM_EXPROP_LT) {
cmpOffset = 0;
}if (expr->expr->type == JIM_EXPROP_LT) { ... }
else if (expr->expr->type == JIM_EXPROP_LTE) {
cmpOffset = 1;
}else if (expr->expr->type == JIM_EXPROP_LTE) { ... }
else {
goto evalstart;
}else { ... }
if (expr->expr->left->type != JIM_TT_VAR) {
goto evalstart;
}if (expr->expr->left->type != JIM_TT_VAR) { ... }
if (expr->expr->right->type != JIM_TT_VAR && expr->expr->right->type != JIM_TT_EXPR_INT) {
goto evalstart;
}if (expr->expr->right->type != JIM_TT_VAR && expr->expr->right->type != JIM_TT_EXPR_INT) { ... }
if (!Jim_CompareStringImmediate(interp, incrScript->token[1].objPtr, "incr")) {
goto evalstart;
}if (!Jim_CompareStringImmediate(interp, incrScript->token[1].objPtr, "incr")) { ... }
if (!Jim_StringEqObj(incrScript->token[2].objPtr, expr->expr->left->objPtr)) {
goto evalstart;
}if (!Jim_StringEqObj(incrScript->token[2].objPtr, expr->expr->left->objPtr)) { ... }
if (expr->expr->right->type == JIM_TT_EXPR_INT) {
if (Jim_GetWideExpr(interp, expr->expr->right->objPtr, &stop) == JIM_ERR) {
goto evalstart;
}if (Jim_GetWideExpr(interp, expr->expr->right->objPtr, &stop) == JIM_ERR) { ... }
}if (expr->expr->right->type == JIM_TT_EXPR_INT) { ... }
else {
stopVarNamePtr = expr->expr->right->objPtr;
Jim_IncrRefCount(stopVarNamePtr);
stop = 0;
}else { ... }
varNamePtr = expr->expr->left->objPtr;
Jim_IncrRefCount(varNamePtr);
objPtr = Jim_GetVariable(interp, varNamePtr, JIM_NONE);
if (objPtr == NULL || Jim_GetWide(interp, objPtr, ¤tVal) != JIM_OK) {
goto testcond;
}if (objPtr == NULL || Jim_GetWide(interp, objPtr, ¤tVal) != JIM_OK) { ... }
while (retval == JIM_OK) {
if (stopVarNamePtr) {
objPtr = Jim_GetVariable(interp, stopVarNamePtr, JIM_NONE);
if (objPtr == NULL || Jim_GetWide(interp, objPtr, &stop) != JIM_OK) {
goto testcond;
}if (objPtr == NULL || Jim_GetWide(interp, objPtr, &stop) != JIM_OK) { ... }
}if (stopVarNamePtr) { ... }
if (currentVal >= stop + cmpOffset) {
break;
}if (currentVal >= stop + cmpOffset) { ... }
retval = Jim_EvalObj(interp, argv[4]);
if (retval == JIM_OK || retval == JIM_CONTINUE) {
retval = JIM_OK;
objPtr = Jim_GetVariable(interp, varNamePtr, JIM_ERRMSG);
if (objPtr == NULL) {
retval = JIM_ERR;
goto out;
}if (objPtr == NULL) { ... }
if (!Jim_IsShared(objPtr) && objPtr->typePtr == &intObjType) {
currentVal = ++JimWideValue(objPtr);
Jim_InvalidateStringRep(objPtr);
}if (!Jim_IsShared(objPtr) && objPtr->typePtr == &intObjType) { ... }
else {
if (Jim_GetWide(interp, objPtr, ¤tVal) != JIM_OK ||
Jim_SetVariable(interp, varNamePtr, Jim_NewIntObj(interp,
++currentVal)) != JIM_OK) {
goto evalnext;
}if (Jim_GetWide(interp, objPtr, ¤tVal) != JIM_OK || Jim_SetVariable(interp, varNamePtr, Jim_NewIntObj(interp, ++currentVal)) != JIM_OK) { ... }
}else { ... }
}if (retval == JIM_OK || retval == JIM_CONTINUE) { ... }
}while (retval == JIM_OK) { ... }
goto out;
}if (retval == JIM_OK && boolean) { ... }
evalstart:/* ... */
#endif
while (boolean && (retval == JIM_OK || retval == JIM_CONTINUE)) {
retval = Jim_EvalObj(interp, argv[4]);
if (retval == JIM_OK || retval == JIM_CONTINUE) {
JIM_IF_OPTIM(evalnext:)
retval = Jim_EvalObj(interp, argv[3]);
if (retval == JIM_OK || retval == JIM_CONTINUE) {
JIM_IF_OPTIM(testcond:)
retval = Jim_GetBoolFromExpr(interp, argv[2], &boolean);
}if (retval == JIM_OK || retval == JIM_CONTINUE) { ... }
}if (retval == JIM_OK || retval == JIM_CONTINUE) { ... }
}while (boolean && (retval == JIM_OK || retval == JIM_CONTINUE)) { ... }
JIM_IF_OPTIM(out:)
if (stopVarNamePtr) {
Jim_DecrRefCount(interp, stopVarNamePtr);
}if (stopVarNamePtr) { ... }
if (varNamePtr) {
Jim_DecrRefCount(interp, varNamePtr);
}if (varNamePtr) { ... }
if (retval == JIM_CONTINUE || retval == JIM_BREAK || retval == JIM_OK) {
Jim_SetEmptyResult(interp);
return JIM_OK;
}if (retval == JIM_CONTINUE || retval == JIM_BREAK || retval == JIM_OK) { ... }
return retval;
}{ ... }
static int Jim_LoopCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retval;
jim_wide i;
jim_wide limit;
jim_wide incr = 1;
Jim_Obj *bodyObjPtr;
if (argc < 4 || argc > 6) {
Jim_WrongNumArgs(interp, 1, argv, "var ?first? limit ?incr? body");
return JIM_ERR;
}if (argc < 4 || argc > 6) { ... }
retval = Jim_GetWideExpr(interp, argv[2], &i);
if (argc > 4 && retval == JIM_OK) {
retval = Jim_GetWideExpr(interp, argv[3], &limit);
}if (argc > 4 && retval == JIM_OK) { ... }
if (argc > 5 && retval == JIM_OK) {
Jim_GetWideExpr(interp, argv[4], &incr);
}if (argc > 5 && retval == JIM_OK) { ... }
if (retval != JIM_OK) {
return retval;
}if (retval != JIM_OK) { ... }
if (argc == 4) {
limit = i;
i = 0;
}if (argc == 4) { ... }
bodyObjPtr = argv[argc - 1];
retval = Jim_SetVariable(interp, argv[1], Jim_NewIntObj(interp, i));
while (((i < limit && incr > 0) || (i > limit && incr < 0)) && retval == JIM_OK) {
retval = Jim_EvalObj(interp, bodyObjPtr);
if (retval == JIM_OK || retval == JIM_CONTINUE) {
Jim_Obj *objPtr = Jim_GetVariable(interp, argv[1], JIM_ERRMSG);
retval = JIM_OK;
i += incr;
if (objPtr && !Jim_IsShared(objPtr) && objPtr->typePtr == &intObjType) {
if (argv[1]->typePtr != &variableObjType) {
if (Jim_SetVariable(interp, argv[1], objPtr) != JIM_OK) {
return JIM_ERR;
}if (Jim_SetVariable(interp, argv[1], objPtr) != JIM_OK) { ... }
}if (argv[1]->typePtr != &variableObjType) { ... }
JimWideValue(objPtr) = i;
Jim_InvalidateStringRep(objPtr);
/* ... */
if (argv[1]->typePtr != &variableObjType) {
if (Jim_SetVariable(interp, argv[1], objPtr) != JIM_OK) {
retval = JIM_ERR;
break;
}if (Jim_SetVariable(interp, argv[1], objPtr) != JIM_OK) { ... }
}if (argv[1]->typePtr != &variableObjType) { ... }
}if (objPtr && !Jim_IsShared(objPtr) && objPtr->typePtr == &intObjType) { ... }
else {
objPtr = Jim_NewIntObj(interp, i);
retval = Jim_SetVariable(interp, argv[1], objPtr);
if (retval != JIM_OK) {
Jim_FreeNewObj(interp, objPtr);
}if (retval != JIM_OK) { ... }
}else { ... }
}if (retval == JIM_OK || retval == JIM_CONTINUE) { ... }
}while (((i < limit && incr > 0) || (i > limit && incr < 0)) && retval == JIM_OK) { ... }
if (retval == JIM_OK || retval == JIM_CONTINUE || retval == JIM_BREAK) {
Jim_SetEmptyResult(interp);
return JIM_OK;
}if (retval == JIM_OK || retval == JIM_CONTINUE || retval == JIM_BREAK) { ... }
return retval;
}{ ... }
/* ... */
typedef struct {
Jim_Obj *objPtr;
int idx;
...} Jim_ListIter;
/* ... */
static void JimListIterInit(Jim_ListIter *iter, Jim_Obj *objPtr)
{
iter->objPtr = objPtr;
iter->idx = 0;
}{ ... }
/* ... */
static Jim_Obj *JimListIterNext(Jim_Interp *interp, Jim_ListIter *iter)
{
if (iter->idx >= Jim_ListLength(interp, iter->objPtr)) {
return NULL;
}if (iter->idx >= Jim_ListLength(interp, iter->objPtr)) { ... }
return iter->objPtr->internalRep.listValue.ele[iter->idx++];
}{ ... }
/* ... */
static int JimListIterDone(Jim_Interp *interp, Jim_ListIter *iter)
{
return iter->idx >= Jim_ListLength(interp, iter->objPtr);
}{ ... }
static int JimForeachMapHelper(Jim_Interp *interp, int argc, Jim_Obj *const *argv, int doMap)
{
int result = JIM_OK;
int i, numargs;
Jim_ListIter twoiters[2];
Jim_ListIter *iters;
Jim_Obj *script;
Jim_Obj *resultObj;
if (argc < 4 || argc % 2 != 0) {
Jim_WrongNumArgs(interp, 1, argv, "varList list ?varList list ...? script");
return JIM_ERR;
}if (argc < 4 || argc % 2 != 0) { ... }
script = argv[argc - 1];
numargs = (argc - 1 - 1);
if (numargs == 2) {
iters = twoiters;
}if (numargs == 2) { ... }
else {
iters = Jim_Alloc(numargs * sizeof(*iters));
}else { ... }
for (i = 0; i < numargs; i++) {
JimListIterInit(&iters[i], argv[i + 1]);
if (i % 2 == 0 && JimListIterDone(interp, &iters[i])) {
result = JIM_ERR;
}if (i % 2 == 0 && JimListIterDone(interp, &iters[i])) { ... }
}for (i = 0; i < numargs; i++) { ... }
if (result != JIM_OK) {
Jim_SetResultString(interp, "foreach varlist is empty", -1);
goto empty_varlist;
}if (result != JIM_OK) { ... }
if (doMap) {
resultObj = Jim_NewListObj(interp, NULL, 0);
}if (doMap) { ... }
else {
resultObj = interp->emptyObj;
}else { ... }
Jim_IncrRefCount(resultObj);
while (1) {
for (i = 0; i < numargs; i += 2) {
if (!JimListIterDone(interp, &iters[i + 1])) {
break;
}if (!JimListIterDone(interp, &iters[i + 1])) { ... }
}for (i = 0; i < numargs; i += 2) { ... }
if (i == numargs) {
break;
}if (i == numargs) { ... }
for (i = 0; i < numargs; i += 2) {
Jim_Obj *varName;
JimListIterInit(&iters[i], argv[i + 1]);
while ((varName = JimListIterNext(interp, &iters[i])) != NULL) {
Jim_Obj *valObj = JimListIterNext(interp, &iters[i + 1]);
if (!valObj) {
valObj = interp->emptyObj;
}if (!valObj) { ... }
Jim_IncrRefCount(valObj);
result = Jim_SetVariable(interp, varName, valObj);
Jim_DecrRefCount(interp, valObj);
if (result != JIM_OK) {
goto err;
}if (result != JIM_OK) { ... }
}while ((varName = JimListIterNext(interp, &iters[i])) != NULL) { ... }
}for (i = 0; i < numargs; i += 2) { ... }
switch (result = Jim_EvalObj(interp, script)) {
case JIM_OK:
if (doMap) {
Jim_ListAppendElement(interp, resultObj, interp->result);
}if (doMap) { ... }
break;case JIM_OK:
case JIM_CONTINUE:
break;case JIM_CONTINUE:
case JIM_BREAK:
goto out;case JIM_BREAK:
default:
goto err;default
}switch (result = Jim_EvalObj(interp, script)) { ... }
}while (1) { ... }
out:
result = JIM_OK;
Jim_SetResult(interp, resultObj);
err:
Jim_DecrRefCount(interp, resultObj);
empty_varlist:
if (numargs > 2) {
Jim_Free(iters);
}if (numargs > 2) { ... }
return result;
}{ ... }
static int Jim_ForeachCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimForeachMapHelper(interp, argc, argv, 0);
}{ ... }
static int Jim_LmapCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimForeachMapHelper(interp, argc, argv, 1);
}{ ... }
static int Jim_LassignCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int result = JIM_ERR;
int i;
Jim_ListIter iter;
Jim_Obj *resultObj;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "varList list ?varName ...?");
return JIM_ERR;
}if (argc < 2) { ... }
JimListIterInit(&iter, argv[1]);
for (i = 2; i < argc; i++) {
Jim_Obj *valObj = JimListIterNext(interp, &iter);
result = Jim_SetVariable(interp, argv[i], valObj ? valObj : interp->emptyObj);
if (result != JIM_OK) {
return result;
}if (result != JIM_OK) { ... }
}for (i = 2; i < argc; i++) { ... }
resultObj = Jim_NewListObj(interp, NULL, 0);
while (!JimListIterDone(interp, &iter)) {
Jim_ListAppendElement(interp, resultObj, JimListIterNext(interp, &iter));
}while (!JimListIterDone(interp, &iter)) { ... }
Jim_SetResult(interp, resultObj);
return JIM_OK;
}{ ... }
static int Jim_IfCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int boolean, retval, current = 1, falsebody = 0;
if (argc >= 3) {
while (1) {
if (current >= argc)
goto err;
if ((retval = Jim_GetBoolFromExpr(interp, argv[current++], &boolean))
!= JIM_OK)
return retval;
if (current >= argc)
goto err;
if (Jim_CompareStringImmediate(interp, argv[current], "then"))
current++;
if (current >= argc)
goto err;
if (boolean)
return Jim_EvalObj(interp, argv[current]);
if (++current >= argc) {
Jim_SetResult(interp, Jim_NewEmptyStringObj(interp));
return JIM_OK;
}if (++current >= argc) { ... }
falsebody = current++;
if (Jim_CompareStringImmediate(interp, argv[falsebody], "else")) {
if (current != argc - 1)
goto err;
return Jim_EvalObj(interp, argv[current]);
}if (Jim_CompareStringImmediate(interp, argv[falsebody], "else")) { ... }
else if (Jim_CompareStringImmediate(interp, argv[falsebody], "elseif"))
/* ... */
continue;
else if (falsebody != argc - 1)
goto err;
return Jim_EvalObj(interp, argv[falsebody]);
}while (1) { ... }
return JIM_OK;
}if (argc >= 3) { ... }
err:
Jim_WrongNumArgs(interp, 1, argv, "condition ?then? trueBody ?elseif ...? ?else? falseBody");
return JIM_ERR;
}{ ... }
/* ... */
int Jim_CommandMatchObj(Jim_Interp *interp, Jim_Obj *commandObj, Jim_Obj *patternObj,
Jim_Obj *stringObj, int flags)
{
Jim_Obj *parms[5];
int argc = 0;
long eq;
int rc;
parms[argc++] = commandObj;
if (flags & JIM_NOCASE) {
parms[argc++] = Jim_NewStringObj(interp, "-nocase", -1);
}if (flags & JIM_NOCASE) { ... }
if (flags & JIM_OPT_END) {
parms[argc++] = Jim_NewStringObj(interp, "--", -1);
}if (flags & JIM_OPT_END) { ... }
parms[argc++] = patternObj;
parms[argc++] = stringObj;
rc = Jim_EvalObjVector(interp, argc, parms);
if (rc != JIM_OK || Jim_GetLong(interp, Jim_GetResult(interp), &eq) != JIM_OK) {
eq = -rc;
}if (rc != JIM_OK || Jim_GetLong(interp, Jim_GetResult(interp), &eq) != JIM_OK) { ... }
return eq;
}{ ... }
static int Jim_SwitchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
enum { SWITCH_EXACT, SWITCH_GLOB, SWITCH_RE, SWITCH_CMD };
int matchOpt = SWITCH_EXACT, opt = 1, patCount, i;
int match_flags = 0;
Jim_Obj *command = NULL, *scriptObj = NULL, *strObj;
Jim_Obj **caseList;
if (argc < 3) {
wrongnumargs:
Jim_WrongNumArgs(interp, 1, argv, "?options? string "
"pattern body ... ?default body? or " "{pattern body ?pattern body ...?}");
return JIM_ERR;
}if (argc < 3) { ... }
for (opt = 1; opt < argc; ++opt) {
const char *option = Jim_String(argv[opt]);
if (*option != '-')
break;
else if (strncmp(option, "--", 2) == 0) {
++opt;
break;
}else if (strncmp(option, "--", 2) == 0) { ... }
else if (strncmp(option, "-exact", 2) == 0)
matchOpt = SWITCH_EXACT;
else if (strncmp(option, "-glob", 2) == 0)
matchOpt = SWITCH_GLOB;
else if (strncmp(option, "-regexp", 2) == 0) {
matchOpt = SWITCH_RE;
match_flags |= JIM_OPT_END;
}else if (strncmp(option, "-regexp", 2) == 0) { ... }
else if (strncmp(option, "-command", 2) == 0) {
matchOpt = SWITCH_CMD;
if ((argc - opt) < 2)
goto wrongnumargs;
command = argv[++opt];
}else if (strncmp(option, "-command", 2) == 0) { ... }
else {
Jim_SetResultFormatted(interp,
"bad option \"%#s\": must be -exact, -glob, -regexp, -command procname or --",
argv[opt]);
return JIM_ERR;
}else { ... }
if ((argc - opt) < 2)
goto wrongnumargs;
}for (opt = 1; opt < argc; ++opt) { ... }
strObj = argv[opt++];
patCount = argc - opt;
if (patCount == 1) {
JimListGetElements(interp, argv[opt], &patCount, &caseList);
}if (patCount == 1) { ... }
else
caseList = (Jim_Obj **)&argv[opt];
if (patCount == 0 || patCount % 2 != 0)
goto wrongnumargs;
for (i = 0; scriptObj == NULL && i < patCount; i += 2) {
Jim_Obj *patObj = caseList[i];
if (!Jim_CompareStringImmediate(interp, patObj, "default")
|| i < (patCount - 2)) {
switch (matchOpt) {
case SWITCH_EXACT:
if (Jim_StringEqObj(strObj, patObj))
scriptObj = caseList[i + 1];
break;case SWITCH_EXACT:
case SWITCH_GLOB:
if (Jim_StringMatchObj(interp, patObj, strObj, 0))
scriptObj = caseList[i + 1];
break;case SWITCH_GLOB:
case SWITCH_RE:
command = Jim_NewStringObj(interp, "regexp", -1);
case SWITCH_RE:
case SWITCH_CMD:{
int rc = Jim_CommandMatchObj(interp, command, patObj, strObj, match_flags);
/* ... */
if (argc - opt == 1) {
JimListGetElements(interp, argv[opt], &patCount, &caseList);
}if (argc - opt == 1) { ... }
if (rc < 0) {
return -rc;
}if (rc < 0) { ... }
if (rc)
scriptObj = caseList[i + 1];
break;
...}case SWITCH_CMD:
}switch (matchOpt) { ... }
}if (!Jim_CompareStringImmediate(interp, patObj, "default") || i < (patCount - 2)) { ... }
else {
scriptObj = caseList[i + 1];
}else { ... }
}for (i = 0; scriptObj == NULL && i < patCount; i += 2) { ... }
for (; i < patCount && Jim_CompareStringImmediate(interp, scriptObj, "-"); i += 2)
scriptObj = caseList[i + 1];
if (scriptObj && Jim_CompareStringImmediate(interp, scriptObj, "-")) {
Jim_SetResultFormatted(interp, "no body specified for pattern \"%#s\"", caseList[i - 2]);
return JIM_ERR;
}if (scriptObj && Jim_CompareStringImmediate(interp, scriptObj, "-")) { ... }
Jim_SetEmptyResult(interp);
if (scriptObj) {
return Jim_EvalObj(interp, scriptObj);
}if (scriptObj) { ... }
return JIM_OK;
}{ ... }
static int Jim_ListCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *listObjPtr;
listObjPtr = Jim_NewListObj(interp, argv + 1, argc - 1);
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}{ ... }
static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
int ret;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "list ?index ...?");
return JIM_ERR;
}if (argc < 2) { ... }
ret = Jim_ListIndices(interp, argv[1], argv + 2, argc - 2, &objPtr, JIM_NONE);
if (ret < 0) {
/* ... */
ret = JIM_OK;
Jim_SetEmptyResult(interp);
}if (ret < 0) { ... }
else if (ret == JIM_OK) {
Jim_SetResult(interp, objPtr);
}else if (ret == JIM_OK) { ... }
return ret;
}{ ... }
static int Jim_LlengthCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "list");
return JIM_ERR;
}if (argc != 2) { ... }
Jim_SetResultInt(interp, Jim_ListLength(interp, argv[1]));
return JIM_OK;
}{ ... }
static int Jim_LsearchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
static const char * const options[] = {
"-bool", "-not", "-nocase", "-exact", "-glob", "-regexp", "-all", "-inline", "-command",
"-stride", "-index", NULL
...};
enum
{ OPT_BOOL, OPT_NOT, OPT_NOCASE, OPT_EXACT, OPT_GLOB, OPT_REGEXP, OPT_ALL, OPT_INLINE,
OPT_COMMAND, OPT_STRIDE, OPT_INDEX ...};
int i;
int opt_bool = 0;
int opt_not = 0;
int opt_all = 0;
int opt_inline = 0;
int opt_match = OPT_EXACT;
int listlen;
int rc = JIM_OK;
Jim_Obj *listObjPtr = NULL;
Jim_Obj *commandObj = NULL;
Jim_Obj *indexObj = NULL;
int match_flags = 0;
long stride = 1;
if (argc < 3) {
wrongargs:
Jim_WrongNumArgs(interp, 1, argv,
"?-exact|-glob|-regexp|-command 'command'? ?-bool|-inline? ?-not? ?-nocase? ?-all? ?-stride len? ?-index val? list value");
return JIM_ERR;
}if (argc < 3) { ... }
for (i = 1; i < argc - 2; i++) {
int option;
if (Jim_GetEnum(interp, argv[i], options, &option, NULL, JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetEnum(interp, argv[i], options, &option, NULL, JIM_ERRMSG) != JIM_OK) { ... }
switch (option) {
case OPT_BOOL:
opt_bool = 1;
opt_inline = 0;
break;case OPT_BOOL:
case OPT_NOT:
opt_not = 1;
break;case OPT_NOT:
case OPT_NOCASE:
match_flags |= JIM_NOCASE;
break;case OPT_NOCASE:
case OPT_INLINE:
opt_inline = 1;
opt_bool = 0;
break;case OPT_INLINE:
case OPT_ALL:
opt_all = 1;
break;case OPT_ALL:
case OPT_REGEXP:
opt_match = option;
match_flags |= JIM_OPT_END;
break;case OPT_REGEXP:
case OPT_COMMAND:
if (i >= argc - 2) {
goto wrongargs;
}if (i >= argc - 2) { ... }
commandObj = argv[++i];
case OPT_COMMAND:
case OPT_EXACT:
case OPT_GLOB:
opt_match = option;
break;case OPT_GLOB:
case OPT_INDEX:
if (i >= argc - 2) {
goto wrongargs;
}if (i >= argc - 2) { ... }
indexObj = argv[++i];
break;case OPT_INDEX:
case OPT_STRIDE:
if (i >= argc - 2) {
goto wrongargs;
}if (i >= argc - 2) { ... }
if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) { ... }
if (stride < 1) {
Jim_SetResultString(interp, "stride length must be at least 1", -1);
return JIM_ERR;
}if (stride < 1) { ... }
break;case OPT_STRIDE:
}switch (option) { ... }
}for (i = 1; i < argc - 2; i++) { ... }
argc -= i;
if (argc < 2) {
goto wrongargs;
}if (argc < 2) { ... }
argv += i;
listlen = Jim_ListLength(interp, argv[0]);
if (listlen % stride) {
Jim_SetResultString(interp, "list size must be a multiple of the stride length", -1);
return JIM_ERR;
}if (listlen % stride) { ... }
if (opt_all) {
listObjPtr = Jim_NewListObj(interp, NULL, 0);
}if (opt_all) { ... }
if (opt_match == OPT_REGEXP) {
commandObj = Jim_NewStringObj(interp, "regexp", -1);
}if (opt_match == OPT_REGEXP) { ... }
if (commandObj) {
Jim_IncrRefCount(commandObj);
}if (commandObj) { ... }
for (i = 0; i < listlen; i += stride) {
int eq = 0;
Jim_Obj *searchListObj;
Jim_Obj *objPtr;
int offset;
if (indexObj) {
int indexlen = Jim_ListLength(interp, indexObj);
if (stride == 1) {
searchListObj = Jim_ListGetIndex(interp, argv[0], i);
}if (stride == 1) { ... }
else {
searchListObj = Jim_NewListObj(interp, argv[0]->internalRep.listValue.ele + i, stride);
}else { ... }
Jim_IncrRefCount(searchListObj);
rc = Jim_ListIndices(interp, searchListObj, indexObj->internalRep.listValue.ele, indexlen, &objPtr, JIM_ERRMSG);
if (rc != JIM_OK) {
Jim_DecrRefCount(interp, searchListObj);
rc = JIM_ERR;
goto done;
}if (rc != JIM_OK) { ... }
offset = 0;
}if (indexObj) { ... }
else {
searchListObj = argv[0];
offset = i;
objPtr = Jim_ListGetIndex(interp, searchListObj, i);
Jim_IncrRefCount(searchListObj);
}else { ... }
/* ... */
switch (opt_match) {
case OPT_EXACT:
eq = Jim_StringCompareObj(interp, argv[1], objPtr, match_flags) == 0;
break;
case OPT_EXACT:
case OPT_GLOB:
eq = Jim_StringMatchObj(interp, argv[1], objPtr, match_flags);
break;
case OPT_GLOB:
case OPT_REGEXP:
case OPT_COMMAND:
eq = Jim_CommandMatchObj(interp, commandObj, argv[1], objPtr, match_flags);
if (eq < 0) {
Jim_DecrRefCount(interp, searchListObj);
rc = JIM_ERR;
goto done;
}if (eq < 0) { ... }
break;case OPT_COMMAND:
}switch (opt_match) { ... }
if ((!opt_bool && eq == !opt_not) || (opt_bool && (eq || opt_all))) {
Jim_Obj *resultObj;
if (opt_bool) {
resultObj = Jim_NewIntObj(interp, eq ^ opt_not);
}if (opt_bool) { ... }
else if (!opt_inline) {
resultObj = Jim_NewIntObj(interp, i);
}else if (!opt_inline) { ... }
else if (stride == 1) {
resultObj = objPtr;
}else if (stride == 1) { ... }
else if (opt_all) {
ListInsertElements(listObjPtr, -1, stride,
searchListObj->internalRep.listValue.ele + offset);
resultObj = NULL;
}else if (opt_all) { ... }
else {
resultObj = Jim_NewListObj(interp, searchListObj->internalRep.listValue.ele + offset, stride);
}else { ... }
if (opt_all) {
if (stride == 1) {
Jim_ListAppendElement(interp, listObjPtr, resultObj);
}if (stride == 1) { ... }
}if (opt_all) { ... }
else {
Jim_SetResult(interp, resultObj);
Jim_DecrRefCount(interp, searchListObj);
goto done;
}else { ... }
}if ((!opt_bool && eq == !opt_not) || (opt_bool && (eq || opt_all))) { ... }
Jim_DecrRefCount(interp, searchListObj);
}for (i = 0; i < listlen; i += stride) { ... }
if (opt_all) {
Jim_SetResult(interp, listObjPtr);
listObjPtr = NULL;
}if (opt_all) { ... }
else {
if (opt_bool) {
Jim_SetResultBool(interp, opt_not);
}if (opt_bool) { ... }
else if (!opt_inline) {
Jim_SetResultInt(interp, -1);
}else if (!opt_inline) { ... }
}else { ... }
done:
if (listObjPtr) {
Jim_FreeNewObj(interp, listObjPtr);
}if (listObjPtr) { ... }
if (commandObj) {
Jim_DecrRefCount(interp, commandObj);
}if (commandObj) { ... }
return rc;
}{ ... }
static int Jim_LappendCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *listObjPtr;
int new_obj = 0;
int i;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?value value ...?");
return JIM_ERR;
}if (argc < 2) { ... }
listObjPtr = Jim_GetVariable(interp, argv[1], JIM_UNSHARED);
if (!listObjPtr) {
listObjPtr = Jim_NewListObj(interp, NULL, 0);
new_obj = 1;
}if (!listObjPtr) { ... }
else if (Jim_IsShared(listObjPtr)) {
listObjPtr = Jim_DuplicateObj(interp, listObjPtr);
new_obj = 1;
}else if (Jim_IsShared(listObjPtr)) { ... }
for (i = 2; i < argc; i++)
Jim_ListAppendElement(interp, listObjPtr, argv[i]);
if (Jim_SetVariable(interp, argv[1], listObjPtr) != JIM_OK) {
if (new_obj)
Jim_FreeNewObj(interp, listObjPtr);
return JIM_ERR;
}if (Jim_SetVariable(interp, argv[1], listObjPtr) != JIM_OK) { ... }
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}{ ... }
static int Jim_LinsertCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int idx, len;
Jim_Obj *listPtr;
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "list index ?element ...?");
return JIM_ERR;
}if (argc < 3) { ... }
listPtr = argv[1];
if (Jim_IsShared(listPtr))
listPtr = Jim_DuplicateObj(interp, listPtr);
if (Jim_GetIndex(interp, argv[2], &idx) != JIM_OK)
goto err;
len = Jim_ListLength(interp, listPtr);
if (idx >= len)
idx = len;
else if (idx < 0)
idx = len + idx + 1;
Jim_ListInsertElements(interp, listPtr, idx, argc - 3, &argv[3]);
Jim_SetResult(interp, listPtr);
return JIM_OK;
err:
if (listPtr != argv[1]) {
Jim_FreeNewObj(interp, listPtr);
}if (listPtr != argv[1]) { ... }
return JIM_ERR;
}{ ... }
static int Jim_LreplaceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int first, last, len, rangeLen;
Jim_Obj *listObj;
Jim_Obj *newListObj;
if (argc < 4) {
Jim_WrongNumArgs(interp, 1, argv, "list first last ?element ...?");
return JIM_ERR;
}if (argc < 4) { ... }
if (Jim_GetIndex(interp, argv[2], &first) != JIM_OK ||
Jim_GetIndex(interp, argv[3], &last) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetIndex(interp, argv[2], &first) != JIM_OK || Jim_GetIndex(interp, argv[3], &last) != JIM_OK) { ... }
listObj = argv[1];
len = Jim_ListLength(interp, listObj);
first = JimRelToAbsIndex(len, first);
last = JimRelToAbsIndex(len, last);
JimRelToAbsRange(len, &first, &last, &rangeLen);
/* ... */
/* ... */
if (first > len) {
first = len;
}if (first > len) { ... }
newListObj = Jim_NewListObj(interp, listObj->internalRep.listValue.ele, first);
ListInsertElements(newListObj, -1, argc - 4, argv + 4);
ListInsertElements(newListObj, -1, len - first - rangeLen, listObj->internalRep.listValue.ele + first + rangeLen);
Jim_SetResult(interp, newListObj);
return JIM_OK;
}{ ... }
static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "listVar ?index ...? value");
return JIM_ERR;
}if (argc < 3) { ... }
else if (argc == 3) {
if (Jim_SetVariable(interp, argv[1], argv[2]) != JIM_OK)
return JIM_ERR;
Jim_SetResult(interp, argv[2]);
return JIM_OK;
}else if (argc == 3) { ... }
return Jim_ListSetIndex(interp, argv[1], argv + 2, argc - 3, argv[argc - 1]);
}{ ... }
static int Jim_LsortCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const argv[])
{
static const char * const options[] = {
"-ascii", "-nocase", "-increasing", "-decreasing", "-command", "-integer", "-real", "-index", "-unique",
"-stride", NULL
...};
enum {
OPT_ASCII, OPT_NOCASE, OPT_INCREASING, OPT_DECREASING, OPT_COMMAND, OPT_INTEGER, OPT_REAL, OPT_INDEX, OPT_UNIQUE,
OPT_STRIDE
...};
Jim_Obj *resObj;
int i;
int retCode;
int shared;
long stride = 1;
struct lsort_info info;
if (argc < 2) {
wrongargs:
Jim_WrongNumArgs(interp, 1, argv, "?options? list");
return JIM_ERR;
}if (argc < 2) { ... }
info.type = JIM_LSORT_ASCII;
info.order = 1;
info.indexc = 0;
info.unique = 0;
info.command = NULL;
info.interp = interp;
for (i = 1; i < (argc - 1); i++) {
int option;
if (Jim_GetEnum(interp, argv[i], options, &option, NULL, JIM_ENUM_ABBREV | JIM_ERRMSG)
!= JIM_OK)
return JIM_ERR;
switch (option) {
case OPT_ASCII:
info.type = JIM_LSORT_ASCII;
break;case OPT_ASCII:
case OPT_NOCASE:
info.type = JIM_LSORT_NOCASE;
break;case OPT_NOCASE:
case OPT_INTEGER:
info.type = JIM_LSORT_INTEGER;
break;case OPT_INTEGER:
case OPT_REAL:
info.type = JIM_LSORT_REAL;
break;case OPT_REAL:
case OPT_INCREASING:
info.order = 1;
break;case OPT_INCREASING:
case OPT_DECREASING:
info.order = -1;
break;case OPT_DECREASING:
case OPT_UNIQUE:
info.unique = 1;
break;case OPT_UNIQUE:
case OPT_COMMAND:
if (i >= (argc - 2)) {
Jim_SetResultString(interp, "\"-command\" option must be followed by comparison command", -1);
return JIM_ERR;
}if (i >= (argc - 2)) { ... }
info.type = JIM_LSORT_COMMAND;
info.command = argv[i + 1];
i++;
break;case OPT_COMMAND:
case OPT_STRIDE:
if (i >= argc - 2) {
goto wrongargs;
}if (i >= argc - 2) { ... }
if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetLong(interp, argv[++i], &stride) != JIM_OK) { ... }
if (stride < 2) {
Jim_SetResultString(interp, "stride length must be at least 2", -1);
return JIM_ERR;
}if (stride < 2) { ... }
break;case OPT_STRIDE:
case OPT_INDEX:
if (i >= (argc - 2)) {
badindex:
Jim_SetResultString(interp, "\"-index\" option must be followed by list index", -1);
return JIM_ERR;
}if (i >= (argc - 2)) { ... }
JimListGetElements(interp, argv[i + 1], &info.indexc, &info.indexv);
if (info.indexc == 0) {
goto badindex;
}if (info.indexc == 0) { ... }
i++;
break;case OPT_INDEX:
}switch (option) { ... }
}for (i = 1; i < (argc - 1); i++) { ... }
resObj = argv[argc - 1];
if (stride > 1) {
Jim_Obj *tmpListObj;
Jim_Obj **elements;
int listlen;
int i;
JimListGetElements(interp, resObj, &listlen, &elements);
if (listlen % stride) {
Jim_SetResultString(interp, "list size must be a multiple of the stride length", -1);
return JIM_ERR;
}if (listlen % stride) { ... }
tmpListObj = Jim_NewListObj(interp, NULL, 0);
Jim_IncrRefCount(tmpListObj);
for (i = 0; i < listlen; i += stride) {
Jim_ListAppendElement(interp, tmpListObj, Jim_NewListObj(interp, elements + i, stride));
}for (i = 0; i < listlen; i += stride) { ... }
retCode = ListSortElements(interp, tmpListObj, &info);
if (retCode == JIM_OK) {
resObj = Jim_NewListObj(interp, NULL, 0);
for (i = 0; i < listlen; i += stride) {
Jim_ListAppendList(interp, resObj, Jim_ListGetIndex(interp, tmpListObj, i / stride));
}for (i = 0; i < listlen; i += stride) { ... }
Jim_SetResult(interp, resObj);
}if (retCode == JIM_OK) { ... }
Jim_DecrRefCount(interp, tmpListObj);
}if (stride > 1) { ... }
else {
if ((shared = Jim_IsShared(resObj))) {
resObj = Jim_DuplicateObj(interp, resObj);
}if ((shared = Jim_IsShared(resObj))) { ... }
retCode = ListSortElements(interp, resObj, &info);
if (retCode == JIM_OK) {
Jim_SetResult(interp, resObj);
}if (retCode == JIM_OK) { ... }
else if (shared) {
Jim_FreeNewObj(interp, resObj);
}else if (shared) { ... }
}else { ... }
return retCode;
}{ ... }
static int Jim_AppendCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *stringObjPtr;
int i;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?value ...?");
return JIM_ERR;
}if (argc < 2) { ... }
if (argc == 2) {
stringObjPtr = Jim_GetVariable(interp, argv[1], JIM_ERRMSG);
if (!stringObjPtr)
return JIM_ERR;
}if (argc == 2) { ... }
else {
int new_obj = 0;
stringObjPtr = Jim_GetVariable(interp, argv[1], JIM_UNSHARED);
if (!stringObjPtr) {
stringObjPtr = Jim_NewEmptyStringObj(interp);
new_obj = 1;
}if (!stringObjPtr) { ... }
else if (Jim_IsShared(stringObjPtr)) {
new_obj = 1;
stringObjPtr = Jim_DuplicateObj(interp, stringObjPtr);
}else if (Jim_IsShared(stringObjPtr)) { ... }
for (i = 2; i < argc; i++) {
Jim_AppendObj(interp, stringObjPtr, argv[i]);
}for (i = 2; i < argc; i++) { ... }
if (Jim_SetVariable(interp, argv[1], stringObjPtr) != JIM_OK) {
if (new_obj) {
Jim_FreeNewObj(interp, stringObjPtr);
}if (new_obj) { ... }
return JIM_ERR;
}if (Jim_SetVariable(interp, argv[1], stringObjPtr) != JIM_OK) { ... }
}else { ... }
Jim_SetResult(interp, stringObjPtr);
return JIM_OK;
}{ ... }
#if defined(JIM_DEBUG_COMMAND) && !defined(JIM_BOOTSTRAP)
/* ... */
static Jim_Obj *JimGetExprAsList(Jim_Interp *interp, struct JimExprNode *node)
{
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp, jim_tt_name(node->type), -1));
if (TOKEN_IS_EXPR_OP(node->type)) {
if (node->left) {
Jim_ListAppendElement(interp, listObjPtr, JimGetExprAsList(interp, node->left));
}if (node->left) { ... }
if (node->right) {
Jim_ListAppendElement(interp, listObjPtr, JimGetExprAsList(interp, node->right));
}if (node->right) { ... }
if (node->ternary) {
Jim_ListAppendElement(interp, listObjPtr, JimGetExprAsList(interp, node->ternary));
}if (node->ternary) { ... }
}if (TOKEN_IS_EXPR_OP(node->type)) { ... }
else {
Jim_ListAppendElement(interp, listObjPtr, node->objPtr);
}else { ... }
return listObjPtr;
}JimGetExprAsList (Jim_Interp *interp, struct JimExprNode *node) { ... }
/* ... */#endif
#if defined(JIM_DEBUG_COMMAND) && !defined(JIM_BOOTSTRAP)
static int Jim_DebugCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
static const char * const options[] = {
"refcount", "objcount", "objects", "invstr", "scriptlen", "exprlen",
"exprbc", "show",
NULL
...};
enum
{
OPT_REFCOUNT, OPT_OBJCOUNT, OPT_OBJECTS, OPT_INVSTR, OPT_SCRIPTLEN,
OPT_EXPRLEN, OPT_EXPRBC, OPT_SHOW,
...};
int option;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "subcommand ?...?");
return JIM_ERR;
}if (argc < 2) { ... }
if (Jim_GetEnum(interp, argv[1], options, &option, "subcommand", JIM_ERRMSG) != JIM_OK)
return Jim_CheckShowCommands(interp, argv[1], options);
if (option == OPT_REFCOUNT) {
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "object");
return JIM_ERR;
}if (argc != 3) { ... }
Jim_SetResultInt(interp, argv[2]->refCount);
return JIM_OK;
}if (option == OPT_REFCOUNT) { ... }
else if (option == OPT_OBJCOUNT) {
int freeobj = 0, liveobj = 0;
char buf[256];
Jim_Obj *objPtr;
if (argc != 2) {
Jim_WrongNumArgs(interp, 2, argv, "");
return JIM_ERR;
}if (argc != 2) { ... }
objPtr = interp->freeList;
while (objPtr) {
freeobj++;
objPtr = objPtr->nextObjPtr;
}while (objPtr) { ... }
objPtr = interp->liveList;
while (objPtr) {
liveobj++;
objPtr = objPtr->nextObjPtr;
}while (objPtr) { ... }
sprintf(buf, "free %d used %d", freeobj, liveobj);
Jim_SetResultString(interp, buf, -1);
return JIM_OK;
}else if (option == OPT_OBJCOUNT) { ... }
else if (option == OPT_OBJECTS) {
Jim_Obj *objPtr, *listObjPtr, *subListObjPtr;
if (argc != 2) {
Jim_WrongNumArgs(interp, 2, argv, "");
return JIM_ERR;
}if (argc != 2) { ... }
objPtr = interp->liveList;
listObjPtr = Jim_NewListObj(interp, NULL, 0);
while (objPtr) {
char buf[128];
const char *type = objPtr->typePtr ? objPtr->typePtr->name : "";
subListObjPtr = Jim_NewListObj(interp, NULL, 0);
sprintf(buf, "%p", objPtr);
Jim_ListAppendElement(interp, subListObjPtr, Jim_NewStringObj(interp, buf, -1));
Jim_ListAppendElement(interp, subListObjPtr, Jim_NewStringObj(interp, type, -1));
Jim_ListAppendElement(interp, subListObjPtr, Jim_NewIntObj(interp, objPtr->refCount));
Jim_ListAppendElement(interp, subListObjPtr, objPtr);
Jim_ListAppendElement(interp, listObjPtr, subListObjPtr);
objPtr = objPtr->nextObjPtr;
}while (objPtr) { ... }
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}else if (option == OPT_OBJECTS) { ... }
else if (option == OPT_INVSTR) {
Jim_Obj *objPtr;
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "object");
return JIM_ERR;
}if (argc != 3) { ... }
objPtr = argv[2];
if (objPtr->typePtr != NULL)
Jim_InvalidateStringRep(objPtr);
Jim_SetEmptyResult(interp);
return JIM_OK;
}else if (option == OPT_INVSTR) { ... }
else if (option == OPT_SHOW) {
const char *s;
int len, charlen;
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "object");
return JIM_ERR;
}if (argc != 3) { ... }
s = Jim_GetString(argv[2], &len);
#ifdef JIM_UTF8
charlen = utf8_strlen(s, len);
#else
charlen = len;
#endif
char buf[256];
snprintf(buf, sizeof(buf), "refcount: %d, type: %s\n"
"chars (%d):",
argv[2]->refCount, JimObjTypeName(argv[2]), charlen);
Jim_SetResultFormatted(interp, "%s <<%s>>\n", buf, s);
snprintf(buf, sizeof(buf), "bytes (%d):", len);
Jim_AppendString(interp, Jim_GetResult(interp), buf, -1);
while (len--) {
snprintf(buf, sizeof(buf), " %02x", (unsigned char)*s++);
Jim_AppendString(interp, Jim_GetResult(interp), buf, -1);
}while (len--) { ... }
return JIM_OK;
}else if (option == OPT_SHOW) { ... }
else if (option == OPT_SCRIPTLEN) {
ScriptObj *script;
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "script");
return JIM_ERR;
}if (argc != 3) { ... }
script = JimGetScript(interp, argv[2]);
if (script == NULL)
return JIM_ERR;
Jim_SetResultInt(interp, script->len);
return JIM_OK;
}else if (option == OPT_SCRIPTLEN) { ... }
else if (option == OPT_EXPRLEN) {
struct ExprTree *expr;
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "expression");
return JIM_ERR;
}if (argc != 3) { ... }
expr = JimGetExpression(interp, argv[2]);
if (expr == NULL)
return JIM_ERR;
Jim_SetResultInt(interp, expr->len);
return JIM_OK;
}else if (option == OPT_EXPRLEN) { ... }
else if (option == OPT_EXPRBC) {
struct ExprTree *expr;
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "expression");
return JIM_ERR;
}if (argc != 3) { ... }
expr = JimGetExpression(interp, argv[2]);
if (expr == NULL)
return JIM_ERR;
Jim_SetResult(interp, JimGetExprAsList(interp, expr->expr));
return JIM_OK;
}else if (option == OPT_EXPRBC) { ... }
else {
Jim_SetResultString(interp,
"bad option. Valid options are refcount, " "objcount, objects, invstr", -1);
return JIM_ERR;
}else { ... }
}Jim_DebugCoreCommand (Jim_Interp *interp, int argc, Jim_Obj *const *argv) { ... }
/* ... */#endif
static int Jim_EvalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int rc;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "arg ?arg ...?");
return JIM_ERR;
}if (argc < 2) { ... }
if (argc == 2) {
rc = Jim_EvalObj(interp, argv[1]);
}if (argc == 2) { ... }
else {
rc = Jim_EvalObj(interp, Jim_ConcatObj(interp, argc - 1, argv + 1));
}else { ... }
if (rc == JIM_ERR) {
interp->addStackTrace++;
}if (rc == JIM_ERR) { ... }
return rc;
}{ ... }
static int Jim_UplevelCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc >= 2) {
int retcode;
Jim_CallFrame *savedCallFrame, *targetCallFrame;
const char *str;
savedCallFrame = interp->framePtr;
str = Jim_String(argv[1]);
if ((str[0] >= '0' && str[0] <= '9') || str[0] == '#') {
targetCallFrame = Jim_GetCallFrameByLevel(interp, argv[1]);
argc--;
argv++;
}if ((str[0] >= '0' && str[0] <= '9') || str[0] == '#') { ... }
else {
targetCallFrame = Jim_GetCallFrameByLevel(interp, NULL);
}else { ... }
if (targetCallFrame == NULL) {
return JIM_ERR;
}if (targetCallFrame == NULL) { ... }
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv - 1, "?level? command ?arg ...?");
return JIM_ERR;
}if (argc < 2) { ... }
interp->framePtr = targetCallFrame;
if (argc == 2) {
retcode = Jim_EvalObj(interp, argv[1]);
}if (argc == 2) { ... }
else {
retcode = Jim_EvalObj(interp, Jim_ConcatObj(interp, argc - 1, argv + 1));
}else { ... }
interp->framePtr = savedCallFrame;
return retcode;
}if (argc >= 2) { ... }
else {
Jim_WrongNumArgs(interp, 1, argv, "?level? command ?arg ...?");
return JIM_ERR;
}else { ... }
}{ ... }
static int Jim_ExprCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retcode;
if (argc == 2) {
retcode = Jim_EvalExpression(interp, argv[1]);
}if (argc == 2) { ... }
#ifndef JIM_COMPAT
else {
Jim_WrongNumArgs(interp, 1, argv, "expression");
retcode = JIM_ERR;
}else { ... }
/* ... */#else
else if (argc > 2) {
Jim_Obj *objPtr;
objPtr = Jim_ConcatObj(interp, argc - 1, argv + 1);
Jim_IncrRefCount(objPtr);
retcode = Jim_EvalExpression(interp, objPtr);
Jim_DecrRefCount(interp, objPtr);
}else if (argc > 2) { ... }
else {
Jim_WrongNumArgs(interp, 1, argv, "expression ?...?");
return JIM_ERR;
}else { ... }
/* ... */#endif
return retcode;
}{ ... }
static int Jim_BreakCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "");
return JIM_ERR;
}if (argc != 1) { ... }
return JIM_BREAK;
}{ ... }
static int Jim_ContinueCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "");
return JIM_ERR;
}if (argc != 1) { ... }
return JIM_CONTINUE;
}{ ... }
static int Jim_ReturnCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int i;
Jim_Obj *stackTraceObj = NULL;
Jim_Obj *errorCodeObj = NULL;
int returnCode = JIM_OK;
long level = 1;
for (i = 1; i < argc - 1; i += 2) {
if (Jim_CompareStringImmediate(interp, argv[i], "-code")) {
if (Jim_GetReturnCode(interp, argv[i + 1], &returnCode) == JIM_ERR) {
return JIM_ERR;
}if (Jim_GetReturnCode(interp, argv[i + 1], &returnCode) == JIM_ERR) { ... }
}if (Jim_CompareStringImmediate(interp, argv[i], "-code")) { ... }
else if (Jim_CompareStringImmediate(interp, argv[i], "-errorinfo")) {
stackTraceObj = argv[i + 1];
}else if (Jim_CompareStringImmediate(interp, argv[i], "-errorinfo")) { ... }
else if (Jim_CompareStringImmediate(interp, argv[i], "-errorcode")) {
errorCodeObj = argv[i + 1];
}else if (Jim_CompareStringImmediate(interp, argv[i], "-errorcode")) { ... }
else if (Jim_CompareStringImmediate(interp, argv[i], "-level")) {
if (Jim_GetLong(interp, argv[i + 1], &level) != JIM_OK || level < 0) {
Jim_SetResultFormatted(interp, "bad level \"%#s\"", argv[i + 1]);
return JIM_ERR;
}if (Jim_GetLong(interp, argv[i + 1], &level) != JIM_OK || level < 0) { ... }
}else if (Jim_CompareStringImmediate(interp, argv[i], "-level")) { ... }
else {
break;
}else { ... }
}for (i = 1; i < argc - 1; i += 2) { ... }
if (i != argc - 1 && i != argc) {
Jim_WrongNumArgs(interp, 1, argv,
"?-code code? ?-errorinfo stacktrace? ?-level level? ?result?");
}if (i != argc - 1 && i != argc) { ... }
if (stackTraceObj && returnCode == JIM_ERR) {
JimSetStackTrace(interp, stackTraceObj);
}if (stackTraceObj && returnCode == JIM_ERR) { ... }
if (errorCodeObj && returnCode == JIM_ERR) {
Jim_SetGlobalVariableStr(interp, "errorCode", errorCodeObj);
}if (errorCodeObj && returnCode == JIM_ERR) { ... }
interp->returnCode = returnCode;
interp->returnLevel = level;
if (i == argc - 1) {
Jim_SetResult(interp, argv[i]);
}if (i == argc - 1) { ... }
return level == 0 ? returnCode : JIM_RETURN;
}{ ... }
static int Jim_TailcallCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (interp->framePtr->level == 0) {
Jim_SetResultString(interp, "tailcall can only be called from a proc or lambda", -1);
return JIM_ERR;
}if (interp->framePtr->level == 0) { ... }
else if (argc >= 2) {
Jim_CallFrame *cf = interp->framePtr->parent;
Jim_Cmd *cmdPtr = Jim_GetCommand(interp, argv[1], JIM_ERRMSG);
if (cmdPtr == NULL) {
return JIM_ERR;
}if (cmdPtr == NULL) { ... }
JimPanic((cf->tailcallCmd != NULL, "Already have a tailcallCmd"));
JimIncrCmdRefCount(cmdPtr);
cf->tailcallCmd = cmdPtr;
JimPanic((cf->tailcallObj != NULL, "Already have a tailcallobj"));
cf->tailcallObj = Jim_NewListObj(interp, argv + 1, argc - 1);
Jim_IncrRefCount(cf->tailcallObj);
return JIM_EVAL;
}else if (argc >= 2) { ... }
return JIM_OK;
}{ ... }
static int JimAliasCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *cmdList;
Jim_Obj *prefixListObj = Jim_CmdPrivData(interp);
cmdList = Jim_DuplicateObj(interp, prefixListObj);
Jim_ListInsertElements(interp, cmdList, Jim_ListLength(interp, cmdList), argc - 1, argv + 1);
return JimEvalObjList(interp, cmdList);
}{ ... }
static void JimAliasCmdDelete(Jim_Interp *interp, void *privData)
{
Jim_Obj *prefixListObj = privData;
Jim_DecrRefCount(interp, prefixListObj);
}{ ... }
static int Jim_AliasCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *prefixListObj;
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "newname command ?args ...?");
return JIM_ERR;
}if (argc < 3) { ... }
prefixListObj = Jim_NewListObj(interp, argv + 2, argc - 2);
Jim_IncrRefCount(prefixListObj);
Jim_SetResult(interp, argv[1]);
return Jim_CreateCommandObj(interp, argv[1], JimAliasCmd, prefixListObj, JimAliasCmdDelete);
}{ ... }
static int Jim_ProcCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Cmd *cmd;
if (argc != 4 && argc != 5) {
Jim_WrongNumArgs(interp, 1, argv, "name arglist ?statics? body");
return JIM_ERR;
}if (argc != 4 && argc != 5) { ... }
if (argc == 4) {
cmd = JimCreateProcedureCmd(interp, argv[2], NULL, argv[3], NULL);
}if (argc == 4) { ... }
else {
cmd = JimCreateProcedureCmd(interp, argv[2], argv[3], argv[4], NULL);
}else { ... }
if (cmd) {
Jim_Obj *nameObjPtr = JimQualifyName(interp, argv[1]);
JimCreateCommand(interp, nameObjPtr, cmd);
JimUpdateProcNamespace(interp, cmd, nameObjPtr);
Jim_DecrRefCount(interp, nameObjPtr);
Jim_SetResult(interp, argv[1]);
return JIM_OK;
}if (cmd) { ... }
return JIM_ERR;
}{ ... }
static int Jim_XtraceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "callback");
return JIM_ERR;
}if (argc != 2) { ... }
if (interp->traceCmdObj) {
Jim_DecrRefCount(interp, interp->traceCmdObj);
interp->traceCmdObj = NULL;
}if (interp->traceCmdObj) { ... }
if (Jim_Length(argv[1])) {
interp->traceCmdObj = argv[1];
Jim_IncrRefCount(interp->traceCmdObj);
}if (Jim_Length(argv[1])) { ... }
return JIM_OK;
}{ ... }
static int Jim_LocalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retcode;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "cmd ?args ...?");
return JIM_ERR;
}if (argc < 2) { ... }
interp->local++;
retcode = Jim_EvalObjVector(interp, argc - 1, argv + 1);
interp->local--;
if (retcode == 0) {
Jim_Obj *cmdNameObj = Jim_GetResult(interp);
if (Jim_GetCommand(interp, cmdNameObj, JIM_ERRMSG) == NULL) {
return JIM_ERR;
}if (Jim_GetCommand(interp, cmdNameObj, JIM_ERRMSG) == NULL) { ... }
if (interp->framePtr->localCommands == NULL) {
interp->framePtr->localCommands = Jim_Alloc(sizeof(*interp->framePtr->localCommands));
Jim_InitStack(interp->framePtr->localCommands);
}if (interp->framePtr->localCommands == NULL) { ... }
Jim_IncrRefCount(cmdNameObj);
Jim_StackPush(interp->framePtr->localCommands, cmdNameObj);
}if (retcode == 0) { ... }
return retcode;
}{ ... }
static int Jim_UpcallCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "cmd ?args ...?");
return JIM_ERR;
}if (argc < 2) { ... }
else {
int retcode;
Jim_Cmd *cmdPtr = Jim_GetCommand(interp, argv[1], JIM_ERRMSG);
if (cmdPtr == NULL || !cmdPtr->isproc || !cmdPtr->prevCmd) {
Jim_SetResultFormatted(interp, "no previous command: \"%#s\"", argv[1]);
return JIM_ERR;
}if (cmdPtr == NULL || !cmdPtr->isproc || !cmdPtr->prevCmd) { ... }
cmdPtr->u.proc.upcall++;
JimIncrCmdRefCount(cmdPtr);
retcode = Jim_EvalObjVector(interp, argc - 1, argv + 1);
cmdPtr->u.proc.upcall--;
JimDecrCmdRefCount(interp, cmdPtr);
return retcode;
}else { ... }
}{ ... }
static int Jim_ApplyCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "lambdaExpr ?arg ...?");
return JIM_ERR;
}if (argc < 2) { ... }
else {
int ret;
Jim_Cmd *cmd;
Jim_Obj *argListObjPtr;
Jim_Obj *bodyObjPtr;
Jim_Obj *nsObj = NULL;
Jim_Obj **nargv;
int len = Jim_ListLength(interp, argv[1]);
if (len != 2 && len != 3) {
Jim_SetResultFormatted(interp, "can't interpret \"%#s\" as a lambda expression", argv[1]);
return JIM_ERR;
}if (len != 2 && len != 3) { ... }
if (len == 3) {
#ifdef jim_ext_namespace
nsObj = Jim_ListGetIndex(interp, argv[1], 2);/* ... */
#else
Jim_SetResultString(interp, "namespaces not enabled", -1);
return JIM_ERR;/* ... */
#endif
}if (len == 3) { ... }
argListObjPtr = Jim_ListGetIndex(interp, argv[1], 0);
bodyObjPtr = Jim_ListGetIndex(interp, argv[1], 1);
cmd = JimCreateProcedureCmd(interp, argListObjPtr, NULL, bodyObjPtr, nsObj);
if (cmd) {
nargv = Jim_Alloc((argc - 2 + 1) * sizeof(*nargv));
nargv[0] = Jim_NewStringObj(interp, "apply lambdaExpr", -1);
Jim_IncrRefCount(nargv[0]);
memcpy(&nargv[1], argv + 2, (argc - 2) * sizeof(*nargv));
ret = JimCallProcedure(interp, cmd, argc - 2 + 1, nargv);
Jim_DecrRefCount(interp, nargv[0]);
Jim_Free(nargv);
JimDecrCmdRefCount(interp, cmd);
return ret;
}if (cmd) { ... }
return JIM_ERR;
}else { ... }
}{ ... }
static int Jim_ConcatCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_SetResult(interp, Jim_ConcatObj(interp, argc - 1, argv + 1));
return JIM_OK;
}{ ... }
static int Jim_UpvarCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int i;
Jim_CallFrame *targetCallFrame;
if (argc > 3 && (argc % 2 == 0)) {
targetCallFrame = Jim_GetCallFrameByLevel(interp, argv[1]);
argc--;
argv++;
}if (argc > 3 && (argc % 2 == 0)) { ... }
else {
targetCallFrame = Jim_GetCallFrameByLevel(interp, NULL);
}else { ... }
if (targetCallFrame == NULL) {
return JIM_ERR;
}if (targetCallFrame == NULL) { ... }
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "?level? otherVar localVar ?otherVar localVar ...?");
return JIM_ERR;
}if (argc < 3) { ... }
for (i = 1; i < argc; i += 2) {
if (Jim_SetVariableLink(interp, argv[i + 1], argv[i], targetCallFrame) != JIM_OK)
return JIM_ERR;
}for (i = 1; i < argc; i += 2) { ... }
return JIM_OK;
}{ ... }
static int Jim_GlobalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int i;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?varName ...?");
return JIM_ERR;
}if (argc < 2) { ... }
if (interp->framePtr->level == 0)
return JIM_OK;
for (i = 1; i < argc; i++) {
const char *name = Jim_String(argv[i]);
if (name[0] != ':' || name[1] != ':') {
if (Jim_SetVariableLink(interp, argv[i], argv[i], interp->topFramePtr) != JIM_OK)
return JIM_ERR;
}if (name[0] != ':' || name[1] != ':') { ... }
}for (i = 1; i < argc; i++) { ... }
return JIM_OK;
}{ ... }
/* ... */
static Jim_Obj *JimStringMap(Jim_Interp *interp, Jim_Obj *mapListObjPtr,
Jim_Obj *objPtr, int nocase)
{
int numMaps;
const char *str, *noMatchStart = NULL;
int strLen, i;
Jim_Obj *resultObjPtr;
numMaps = Jim_ListLength(interp, mapListObjPtr);
if (numMaps % 2) {
Jim_SetResultString(interp, "list must contain an even number of elements", -1);
return NULL;
}if (numMaps % 2) { ... }
str = Jim_String(objPtr);
strLen = Jim_Utf8Length(interp, objPtr);
resultObjPtr = Jim_NewStringObj(interp, "", 0);
while (strLen) {
for (i = 0; i < numMaps; i += 2) {
Jim_Obj *eachObjPtr;
const char *k;
int kl;
eachObjPtr = Jim_ListGetIndex(interp, mapListObjPtr, i);
k = Jim_String(eachObjPtr);
kl = Jim_Utf8Length(interp, eachObjPtr);
if (strLen >= kl && kl) {
int rc;
rc = JimStringCompareUtf8(str, kl, k, kl, nocase);
if (rc == 0) {
if (noMatchStart) {
Jim_AppendString(interp, resultObjPtr, noMatchStart, str - noMatchStart);
noMatchStart = NULL;
}if (noMatchStart) { ... }
Jim_AppendObj(interp, resultObjPtr, Jim_ListGetIndex(interp, mapListObjPtr, i + 1));
str += utf8_index(str, kl);
strLen -= kl;
break;
}if (rc == 0) { ... }
}if (strLen >= kl && kl) { ... }
}for (i = 0; i < numMaps; i += 2) { ... }
if (i == numMaps) {
int c;
if (noMatchStart == NULL)
noMatchStart = str;
str += utf8_tounicode(str, &c);
strLen--;
}if (i == numMaps) { ... }
}while (strLen) { ... }
if (noMatchStart) {
Jim_AppendString(interp, resultObjPtr, noMatchStart, str - noMatchStart);
}if (noMatchStart) { ... }
return resultObjPtr;
}{ ... }
static int Jim_StringCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int len;
int opt_case = 1;
int option;
static const char * const options[] = {
"bytelength", "length", "compare", "match", "equal", "is", "byterange", "range", "replace",
"map", "repeat", "reverse", "index", "first", "last", "cat",
"trim", "trimleft", "trimright", "tolower", "toupper", "totitle", NULL
...};
enum
{
OPT_BYTELENGTH, OPT_LENGTH, OPT_COMPARE, OPT_MATCH, OPT_EQUAL, OPT_IS, OPT_BYTERANGE, OPT_RANGE, OPT_REPLACE,
OPT_MAP, OPT_REPEAT, OPT_REVERSE, OPT_INDEX, OPT_FIRST, OPT_LAST, OPT_CAT,
OPT_TRIM, OPT_TRIMLEFT, OPT_TRIMRIGHT, OPT_TOLOWER, OPT_TOUPPER, OPT_TOTITLE
...};
static const char * const nocase_options[] = {
"-nocase", NULL
...};
static const char * const nocase_length_options[] = {
"-nocase", "-length", NULL
...};
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "option ?arguments ...?");
return JIM_ERR;
}if (argc < 2) { ... }
if (Jim_GetEnum(interp, argv[1], options, &option, NULL,
JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK)
return Jim_CheckShowCommands(interp, argv[1], options);
switch (option) {
case OPT_LENGTH:
case OPT_BYTELENGTH:
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "string");
return JIM_ERR;
}if (argc != 3) { ... }
if (option == OPT_LENGTH) {
len = Jim_Utf8Length(interp, argv[2]);
}if (option == OPT_LENGTH) { ... }
else {
len = Jim_Length(argv[2]);
}else { ... }
Jim_SetResultInt(interp, len);
return JIM_OK;
case OPT_BYTELENGTH:
case OPT_CAT:{
Jim_Obj *objPtr;
if (argc == 3) {
objPtr = argv[2];
}if (argc == 3) { ... }
else {
int i;
objPtr = Jim_NewStringObj(interp, "", 0);
for (i = 2; i < argc; i++) {
Jim_AppendObj(interp, objPtr, argv[i]);
}for (i = 2; i < argc; i++) { ... }
}else { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
...}
case OPT_CAT:
case OPT_COMPARE:
case OPT_EQUAL:
{
long opt_length = -1;
int n = argc - 4;
int i = 2;
while (n > 0) {
int subopt;
if (Jim_GetEnum(interp, argv[i++], nocase_length_options, &subopt, NULL,
JIM_ENUM_ABBREV) != JIM_OK) {
badcompareargs:
Jim_WrongNumArgs(interp, 2, argv, "?-nocase? ?-length int? string1 string2");
return JIM_ERR;
}if (Jim_GetEnum(interp, argv[i++], nocase_length_options, &subopt, NULL, JIM_ENUM_ABBREV) != JIM_OK) { ... }
if (subopt == 0) {
opt_case = 0;
n--;
}if (subopt == 0) { ... }
else {
if (n < 2) {
goto badcompareargs;
}if (n < 2) { ... }
if (Jim_GetLong(interp, argv[i++], &opt_length) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetLong(interp, argv[i++], &opt_length) != JIM_OK) { ... }
n -= 2;
}else { ... }
}while (n > 0) { ... }
if (n) {
goto badcompareargs;
}if (n) { ... }
argv += argc - 2;
if (opt_length < 0 && option != OPT_COMPARE && opt_case) {
Jim_SetResultBool(interp, Jim_StringEqObj(argv[0], argv[1]));
}if (opt_length < 0 && option != OPT_COMPARE && opt_case) { ... }
else {
const char *s1 = Jim_String(argv[0]);
int l1 = Jim_Utf8Length(interp, argv[0]);
const char *s2 = Jim_String(argv[1]);
int l2 = Jim_Utf8Length(interp, argv[1]);
if (opt_length >= 0) {
if (l1 > opt_length) {
l1 = opt_length;
}if (l1 > opt_length) { ... }
if (l2 > opt_length) {
l2 = opt_length;
}if (l2 > opt_length) { ... }
}if (opt_length >= 0) { ... }
n = JimStringCompareUtf8(s1, l1, s2, l2, !opt_case);
Jim_SetResultInt(interp, option == OPT_COMPARE ? n : n == 0);
}else { ... }
return JIM_OK;
...}
case OPT_EQUAL:
case OPT_MATCH:
if (argc != 4 &&
(argc != 5 ||
Jim_GetEnum(interp, argv[2], nocase_options, &opt_case, NULL,
JIM_ENUM_ABBREV) != JIM_OK)) {
Jim_WrongNumArgs(interp, 2, argv, "?-nocase? pattern string");
return JIM_ERR;
}if (argc != 4 && (argc != 5 || Jim_GetEnum(interp, argv[2], nocase_options, &opt_case, NULL, JIM_ENUM_ABBREV) != JIM_OK)) { ... }
if (opt_case == 0) {
argv++;
}if (opt_case == 0) { ... }
Jim_SetResultBool(interp, Jim_StringMatchObj(interp, argv[2], argv[3], !opt_case));
return JIM_OK;
case OPT_MATCH:
case OPT_MAP:{
Jim_Obj *objPtr;
if (argc != 4 &&
(argc != 5 ||
Jim_GetEnum(interp, argv[2], nocase_options, &opt_case, NULL,
JIM_ENUM_ABBREV) != JIM_OK)) {
Jim_WrongNumArgs(interp, 2, argv, "?-nocase? mapList string");
return JIM_ERR;
}if (argc != 4 && (argc != 5 || Jim_GetEnum(interp, argv[2], nocase_options, &opt_case, NULL, JIM_ENUM_ABBREV) != JIM_OK)) { ... }
if (opt_case == 0) {
argv++;
}if (opt_case == 0) { ... }
objPtr = JimStringMap(interp, argv[2], argv[3], !opt_case);
if (objPtr == NULL) {
return JIM_ERR;
}if (objPtr == NULL) { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
...}
case OPT_MAP:
case OPT_RANGE:
case OPT_BYTERANGE:{
Jim_Obj *objPtr;
if (argc != 5) {
Jim_WrongNumArgs(interp, 2, argv, "string first last");
return JIM_ERR;
}if (argc != 5) { ... }
if (option == OPT_RANGE) {
objPtr = Jim_StringRangeObj(interp, argv[2], argv[3], argv[4]);
}if (option == OPT_RANGE) { ... }
else
{
objPtr = Jim_StringByteRangeObj(interp, argv[2], argv[3], argv[4]);
}else { ... }
if (objPtr == NULL) {
return JIM_ERR;
}if (objPtr == NULL) { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
...}
case OPT_BYTERANGE:
case OPT_REPLACE:{
Jim_Obj *objPtr;
if (argc != 5 && argc != 6) {
Jim_WrongNumArgs(interp, 2, argv, "string first last ?string?");
return JIM_ERR;
}if (argc != 5 && argc != 6) { ... }
objPtr = JimStringReplaceObj(interp, argv[2], argv[3], argv[4], argc == 6 ? argv[5] : NULL);
if (objPtr == NULL) {
return JIM_ERR;
}if (objPtr == NULL) { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
...}
case OPT_REPLACE:
case OPT_REPEAT:{
Jim_Obj *objPtr;
jim_wide count;
if (argc != 4) {
Jim_WrongNumArgs(interp, 2, argv, "string count");
return JIM_ERR;
}if (argc != 4) { ... }
if (Jim_GetWideExpr(interp, argv[3], &count) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetWideExpr(interp, argv[3], &count) != JIM_OK) { ... }
objPtr = Jim_NewStringObj(interp, "", 0);
if (count > 0) {
while (count--) {
Jim_AppendObj(interp, objPtr, argv[2]);
}while (count--) { ... }
}if (count > 0) { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
...}
case OPT_REPEAT:
case OPT_REVERSE:{
char *buf, *p;
const char *str;
int i;
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "string");
return JIM_ERR;
}if (argc != 3) { ... }
str = Jim_GetString(argv[2], &len);
buf = Jim_Alloc(len + 1);
assert(buf);
p = buf + len;
*p = 0;
for (i = 0; i < len; ) {
int c;
int l = utf8_tounicode(str, &c);
memcpy(p - l, str, l);
p -= l;
i += l;
str += l;
}for (i = 0; i < len;) { ... }
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, buf, len));
return JIM_OK;
...}
case OPT_REVERSE:
case OPT_INDEX:{
int idx;
const char *str;
if (argc != 4) {
Jim_WrongNumArgs(interp, 2, argv, "string index");
return JIM_ERR;
}if (argc != 4) { ... }
if (Jim_GetIndex(interp, argv[3], &idx) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetIndex(interp, argv[3], &idx) != JIM_OK) { ... }
str = Jim_String(argv[2]);
len = Jim_Utf8Length(interp, argv[2]);
idx = JimRelToAbsIndex(len, idx);
if (idx < 0 || idx >= len || str == NULL) {
Jim_SetResultString(interp, "", 0);
}if (idx < 0 || idx >= len || str == NULL) { ... }
else if (len == Jim_Length(argv[2])) {
Jim_SetResultString(interp, str + idx, 1);
}else if (len == Jim_Length(argv[2])) { ... }
else {
int c;
int i = utf8_index(str, idx);
Jim_SetResultString(interp, str + i, utf8_tounicode(str + i, &c));
}else { ... }
return JIM_OK;
...}
case OPT_INDEX:
case OPT_FIRST:
case OPT_LAST:{
int idx = 0, l1, l2;
const char *s1, *s2;
if (argc != 4 && argc != 5) {
Jim_WrongNumArgs(interp, 2, argv, "subString string ?index?");
return JIM_ERR;
}if (argc != 4 && argc != 5) { ... }
s1 = Jim_String(argv[2]);
s2 = Jim_String(argv[3]);
l1 = Jim_Utf8Length(interp, argv[2]);
l2 = Jim_Utf8Length(interp, argv[3]);
if (argc == 5) {
if (Jim_GetIndex(interp, argv[4], &idx) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetIndex(interp, argv[4], &idx) != JIM_OK) { ... }
idx = JimRelToAbsIndex(l2, idx);
if (idx < 0) {
idx = 0;
}if (idx < 0) { ... }
}if (argc == 5) { ... }
else if (option == OPT_LAST) {
idx = l2;
}else if (option == OPT_LAST) { ... }
if (option == OPT_FIRST) {
Jim_SetResultInt(interp, JimStringFirst(s1, l1, s2, l2, idx));
}if (option == OPT_FIRST) { ... }
else {
#ifdef JIM_UTF8
Jim_SetResultInt(interp, JimStringLastUtf8(s1, l1, s2, idx));
#else
Jim_SetResultInt(interp, JimStringLast(s1, l1, s2, idx));
#endif
}else { ... }
return JIM_OK;
...}
case OPT_LAST:
case OPT_TRIM:
case OPT_TRIMLEFT:
case OPT_TRIMRIGHT:{
Jim_Obj *trimchars;
if (argc != 3 && argc != 4) {
Jim_WrongNumArgs(interp, 2, argv, "string ?trimchars?");
return JIM_ERR;
}if (argc != 3 && argc != 4) { ... }
trimchars = (argc == 4 ? argv[3] : NULL);
if (option == OPT_TRIM) {
Jim_SetResult(interp, JimStringTrim(interp, argv[2], trimchars));
}if (option == OPT_TRIM) { ... }
else if (option == OPT_TRIMLEFT) {
Jim_SetResult(interp, JimStringTrimLeft(interp, argv[2], trimchars));
}else if (option == OPT_TRIMLEFT) { ... }
else if (option == OPT_TRIMRIGHT) {
Jim_SetResult(interp, JimStringTrimRight(interp, argv[2], trimchars));
}else if (option == OPT_TRIMRIGHT) { ... }
return JIM_OK;
...}
case OPT_TRIMRIGHT:
case OPT_TOLOWER:
case OPT_TOUPPER:
case OPT_TOTITLE:
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "string");
return JIM_ERR;
}if (argc != 3) { ... }
if (option == OPT_TOLOWER) {
Jim_SetResult(interp, JimStringToLower(interp, argv[2]));
}if (option == OPT_TOLOWER) { ... }
else if (option == OPT_TOUPPER) {
Jim_SetResult(interp, JimStringToUpper(interp, argv[2]));
}else if (option == OPT_TOUPPER) { ... }
else {
Jim_SetResult(interp, JimStringToTitle(interp, argv[2]));
}else { ... }
return JIM_OK;
case OPT_TOTITLE:
case OPT_IS:
if (argc == 4 || (argc == 5 && Jim_CompareStringImmediate(interp, argv[3], "-strict"))) {
return JimStringIs(interp, argv[argc - 1], argv[2], argc == 5);
}if (argc == 4 || (argc == 5 && Jim_CompareStringImmediate(interp, argv[3], "-strict"))) { ... }
Jim_WrongNumArgs(interp, 2, argv, "class ?-strict? str");
return JIM_ERR;case OPT_IS:
}switch (option) { ... }
return JIM_OK;
}{ ... }
static int Jim_TimeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
long i, count = 1;
jim_wide start, elapsed;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "script ?count?");
return JIM_ERR;
}if (argc < 2) { ... }
if (argc == 3) {
if (Jim_GetLong(interp, argv[2], &count) != JIM_OK)
return JIM_ERR;
}if (argc == 3) { ... }
if (count < 0)
return JIM_OK;
i = count;
start = JimClock();
while (i-- > 0) {
int retval;
retval = Jim_EvalObj(interp, argv[1]);
if (retval != JIM_OK) {
return retval;
}if (retval != JIM_OK) { ... }
}while (i-- > 0) { ... }
elapsed = JimClock() - start;
if (elapsed < count * 10) {
Jim_SetResult(interp, Jim_NewDoubleObj(interp, elapsed * 1.0 / count));
}if (elapsed < count * 10) { ... }
else {
Jim_SetResultInt(interp, count == 0 ? 0 : elapsed / count);
}else { ... }
Jim_AppendString(interp, Jim_GetResult(interp)," microseconds per iteration", -1);
return JIM_OK;
}{ ... }
static int Jim_ExitCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
long exitCode = 0;
if (argc > 2) {
Jim_WrongNumArgs(interp, 1, argv, "?exitCode?");
return JIM_ERR;
}if (argc > 2) { ... }
if (argc == 2) {
if (Jim_GetLong(interp, argv[1], &exitCode) != JIM_OK)
return JIM_ERR;
Jim_SetResult(interp, argv[1]);
}if (argc == 2) { ... }
interp->exitCode = exitCode;
return JIM_EXIT;
}{ ... }
static int JimMatchReturnCodes(Jim_Interp *interp, Jim_Obj *retcodeListObj, int rc)
{
int len = Jim_ListLength(interp, retcodeListObj);
int i;
for (i = 0; i < len; i++) {
int returncode;
if (Jim_GetReturnCode(interp, Jim_ListGetIndex(interp, retcodeListObj, i), &returncode) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetReturnCode(interp, Jim_ListGetIndex(interp, retcodeListObj, i), &returncode) != JIM_OK) { ... }
if (rc == returncode) {
return JIM_OK;
}if (rc == returncode) { ... }
}for (i = 0; i < len; i++) { ... }
return -1;
}{ ... }
static int JimCatchTryHelper(Jim_Interp *interp, int istry, int argc, Jim_Obj *const *argv)
{
static const char * const wrongargs_catchtry[2] = {
"?-?no?code ... --? script ?resultVarName? ?optionVarName?",
"?-?no?code ... --? script ?on codes vars script? ... ?finally script?"
...};
int exitCode = 0;
int i;
int sig = 0;
int ok;
Jim_Obj *finallyScriptObj = NULL;
Jim_Obj *msgVarObj = NULL;
Jim_Obj *optsVarObj = NULL;
Jim_Obj *onScriptObj = NULL;
int idx;
jim_wide ignore_mask = (1 << JIM_EXIT) | (1 << JIM_EVAL) | (1 << JIM_SIGNAL);
static const int max_ignore_code = sizeof(ignore_mask) * 8;
JimPanic((istry != 0 && istry != 1, "wrong args to JimCatchTryHelper"));
/* ... */
Jim_SetGlobalVariableStr(interp, "errorCode", Jim_NewStringObj(interp, "NONE", -1));
for (i = 1; i < argc - 1; i++) {
const char *arg = Jim_String(argv[i]);
jim_wide option;
int ignore;
if (strcmp(arg, "--") == 0) {
i++;
break;
}if (strcmp(arg, "--") == 0) { ... }
if (*arg != '-') {
break;
}if (*arg != '-') { ... }
if (strncmp(arg, "-no", 3) == 0) {
arg += 3;
ignore = 1;
}if (strncmp(arg, "-no", 3) == 0) { ... }
else {
arg++;
ignore = 0;
}else { ... }
if (Jim_StringToWide(arg, &option, 10) != JIM_OK) {
option = -1;
}if (Jim_StringToWide(arg, &option, 10) != JIM_OK) { ... }
if (option < 0) {
option = Jim_FindByName(arg, jimReturnCodes, jimReturnCodesSize);
}if (option < 0) { ... }
if (option < 0) {
goto wrongargs;
}if (option < 0) { ... }
if (ignore) {
ignore_mask |= ((jim_wide)1 << option);
}if (ignore) { ... }
else {
ignore_mask &= (~((jim_wide)1 << option));
}else { ... }
}for (i = 1; i < argc - 1; i++) { ... }
idx = i;
if (argc - idx < 1) {
wrongargs:
Jim_WrongNumArgs(interp, 1, argv, wrongargs_catchtry[istry]);
return JIM_ERR;
}if (argc - idx < 1) { ... }
if ((ignore_mask & (1 << JIM_SIGNAL)) == 0) {
sig++;
}if ((ignore_mask & (1 << JIM_SIGNAL)) == 0) { ... }
interp->signal_level += sig;
if (Jim_CheckSignal(interp)) {
exitCode = JIM_SIGNAL;
}if (Jim_CheckSignal(interp)) { ... }
else {
exitCode = Jim_EvalObj(interp, argv[idx]);
interp->errorFlag = 0;
}else { ... }
interp->signal_level -= sig;
/* ... */
idx++;
if (istry) {
while (idx < argc) {
if (Jim_CompareStringImmediate(interp, argv[idx], "on")) {
int ret;
if (idx + 4 > argc) {
goto wrongargs;
}if (idx + 4 > argc) { ... }
ret = JimMatchReturnCodes(interp, argv[idx + 1], exitCode);
if (ret > JIM_OK) {
goto wrongargs;
}if (ret > JIM_OK) { ... }
if (ret == JIM_OK) {
msgVarObj = Jim_ListGetIndex(interp, argv[idx + 2], 0);
optsVarObj = Jim_ListGetIndex(interp, argv[idx + 2], 1);
onScriptObj = argv[idx + 3];
}if (ret == JIM_OK) { ... }
idx += 4;
}if (Jim_CompareStringImmediate(interp, argv[idx], "on")) { ... }
else if (Jim_CompareStringImmediate(interp, argv[idx], "finally")) {
if (idx + 2 != argc) {
goto wrongargs;
}if (idx + 2 != argc) { ... }
finallyScriptObj = argv[idx + 1];
idx += 2;
}else if (Jim_CompareStringImmediate(interp, argv[idx], "finally")) { ... }
else {
goto wrongargs;
}else { ... }
}while (idx < argc) { ... }
}if (istry) { ... }
else {
if (argc - idx >= 1) {
msgVarObj = argv[idx];
idx++;
if (argc - idx >= 1) {
optsVarObj = argv[idx];
idx++;
}if (argc - idx >= 1) { ... }
}if (argc - idx >= 1) { ... }
}else { ... }
if (exitCode >= 0 && exitCode < max_ignore_code && (((unsigned jim_wide)1 << exitCode) & ignore_mask)) {
if (finallyScriptObj) {
Jim_EvalObj(interp, finallyScriptObj);
}if (finallyScriptObj) { ... }
return exitCode;
}if (exitCode >= 0 && exitCode < max_ignore_code && (((unsigned jim_wide)1 << exitCode) & ignore_mask)) { ... }
if (sig && exitCode == JIM_SIGNAL) {
if (interp->signal_set_result) {
interp->signal_set_result(interp, interp->sigmask);
}if (interp->signal_set_result) { ... }
else if (!istry) {
Jim_SetResultInt(interp, interp->sigmask);
}else if (!istry) { ... }
interp->sigmask = 0;
}if (sig && exitCode == JIM_SIGNAL) { ... }
ok = 1;
if (msgVarObj && Jim_Length(msgVarObj)) {
if (Jim_SetVariable(interp, msgVarObj, Jim_GetResult(interp)) != JIM_OK) {
ok = 0;
}if (Jim_SetVariable(interp, msgVarObj, Jim_GetResult(interp)) != JIM_OK) { ... }
}if (msgVarObj && Jim_Length(msgVarObj)) { ... }
if (ok && optsVarObj && Jim_Length(optsVarObj)) {
Jim_Obj *optListObj = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-code", -1));
Jim_ListAppendElement(interp, optListObj,
Jim_NewIntObj(interp, exitCode == JIM_RETURN ? interp->returnCode : exitCode));
Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-level", -1));
Jim_ListAppendElement(interp, optListObj, Jim_NewIntObj(interp, interp->returnLevel));
if (exitCode == JIM_ERR) {
Jim_Obj *errorCode;
Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorinfo",
-1));
Jim_ListAppendElement(interp, optListObj, interp->stackTrace);
errorCode = Jim_GetGlobalVariableStr(interp, "errorCode", JIM_NONE);
if (errorCode) {
Jim_ListAppendElement(interp, optListObj, Jim_NewStringObj(interp, "-errorcode", -1));
Jim_ListAppendElement(interp, optListObj, errorCode);
}if (errorCode) { ... }
}if (exitCode == JIM_ERR) { ... }
if (Jim_SetVariable(interp, optsVarObj, optListObj) != JIM_OK) {
ok = 0;
}if (Jim_SetVariable(interp, optsVarObj, optListObj) != JIM_OK) { ... }
}if (ok && optsVarObj && Jim_Length(optsVarObj)) { ... }
if (ok && onScriptObj) {
exitCode = Jim_EvalObj(interp, onScriptObj);
}if (ok && onScriptObj) { ... }
if (finallyScriptObj) {
Jim_Obj *prevResultObj = Jim_GetResult(interp);
Jim_IncrRefCount(prevResultObj);
int ret = Jim_EvalObj(interp, finallyScriptObj);
if (ret == JIM_OK) {
Jim_SetResult(interp, prevResultObj);
}if (ret == JIM_OK) { ... }
else {
exitCode = ret;
}else { ... }
Jim_DecrRefCount(interp, prevResultObj);
}if (finallyScriptObj) { ... }
if (!istry) {
Jim_SetResultInt(interp, exitCode);
exitCode = JIM_OK;
}if (!istry) { ... }
return exitCode;
}{ ... }
static int Jim_CatchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimCatchTryHelper(interp, 0, argc, argv);
}{ ... }
static int Jim_TryCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
return JimCatchTryHelper(interp, 1, argc, argv);
}{ ... }
#if defined(JIM_REFERENCES) && !defined(JIM_BOOTSTRAP)
static int Jim_RefCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 3 && argc != 4) {
Jim_WrongNumArgs(interp, 1, argv, "string tag ?finalizer?");
return JIM_ERR;
}if (argc != 3 && argc != 4) { ... }
if (argc == 3) {
Jim_SetResult(interp, Jim_NewReference(interp, argv[1], argv[2], NULL));
}if (argc == 3) { ... }
else {
Jim_SetResult(interp, Jim_NewReference(interp, argv[1], argv[2], argv[3]));
}else { ... }
return JIM_OK;
}{ ... }
static int Jim_GetrefCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Reference *refPtr;
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "reference");
return JIM_ERR;
}if (argc != 2) { ... }
if ((refPtr = Jim_GetReference(interp, argv[1])) == NULL)
return JIM_ERR;
Jim_SetResult(interp, refPtr->objPtr);
return JIM_OK;
}{ ... }
static int Jim_SetrefCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Reference *refPtr;
if (argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "reference newValue");
return JIM_ERR;
}if (argc != 3) { ... }
if ((refPtr = Jim_GetReference(interp, argv[1])) == NULL)
return JIM_ERR;
Jim_IncrRefCount(argv[2]);
Jim_DecrRefCount(interp, refPtr->objPtr);
refPtr->objPtr = argv[2];
Jim_SetResult(interp, argv[2]);
return JIM_OK;
}{ ... }
static int Jim_CollectCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 1) {
Jim_WrongNumArgs(interp, 1, argv, "");
return JIM_ERR;
}if (argc != 1) { ... }
Jim_SetResultInt(interp, Jim_Collect(interp));
while (interp->freeList) {
Jim_Obj *nextObjPtr = interp->freeList->nextObjPtr;
Jim_Free(interp->freeList);
interp->freeList = nextObjPtr;
}while (interp->freeList) { ... }
return JIM_OK;
}{ ... }
static int Jim_FinalizeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "reference ?finalizerProc?");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
if (argc == 2) {
Jim_Obj *cmdNamePtr;
if (Jim_GetFinalizer(interp, argv[1], &cmdNamePtr) != JIM_OK)
return JIM_ERR;
if (cmdNamePtr != NULL)
Jim_SetResult(interp, cmdNamePtr);
}if (argc == 2) { ... }
else {
if (Jim_SetFinalizer(interp, argv[1], argv[2]) != JIM_OK)
return JIM_ERR;
Jim_SetResult(interp, argv[2]);
}else { ... }
return JIM_OK;
}{ ... }
static int JimInfoReferences(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *listObjPtr;
Jim_HashTableIterator htiter;
Jim_HashEntry *he;
listObjPtr = Jim_NewListObj(interp, NULL, 0);
JimInitHashTableIterator(&interp->references, &htiter);
while ((he = Jim_NextHashEntry(&htiter)) != NULL) {
char buf[JIM_REFERENCE_SPACE + 1];
Jim_Reference *refPtr = Jim_GetHashEntryVal(he);
const unsigned long *refId = he->key;
JimFormatReference(buf, refPtr, *refId);
Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp, buf, -1));
}while ((he = Jim_NextHashEntry(&htiter)) != NULL) { ... }
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}{ ... }
#endif/* ... */
static int Jim_RenameCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "oldName newName");
return JIM_ERR;
}if (argc != 3) { ... }
return Jim_RenameCommand(interp, argv[1], argv[2]);
}{ ... }
#define JIM_DICTMATCH_KEYS 0x0001
#define JIM_DICTMATCH_VALUES 0x002
/* ... */
int Jim_DictMatchTypes(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *patternObj, int match_type, int return_types)
{
Jim_Obj *listObjPtr;
Jim_Dict *dict;
int i;
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
return JIM_ERR;
}if (SetDictFromAny(interp, objPtr) != JIM_OK) { ... }
dict = objPtr->internalRep.dictValue;
listObjPtr = Jim_NewListObj(interp, NULL, 0);
for (i = 0; i < dict->len; i += 2 ) {
Jim_Obj *keyObj = dict->table[i];
Jim_Obj *valObj = dict->table[i + 1];
if (patternObj) {
Jim_Obj *matchObj = (match_type == JIM_DICTMATCH_KEYS) ? keyObj : valObj;
if (!Jim_StringMatchObj(interp, patternObj, matchObj, 0)) {
continue;
}if (!Jim_StringMatchObj(interp, patternObj, matchObj, 0)) { ... }
}if (patternObj) { ... }
if (return_types & JIM_DICTMATCH_KEYS) {
Jim_ListAppendElement(interp, listObjPtr, keyObj);
}if (return_types & JIM_DICTMATCH_KEYS) { ... }
if (return_types & JIM_DICTMATCH_VALUES) {
Jim_ListAppendElement(interp, listObjPtr, valObj);
}if (return_types & JIM_DICTMATCH_VALUES) { ... }
}for (i = 0; i < dict->len; i += 2) { ... }
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}{ ... }
int Jim_DictSize(Jim_Interp *interp, Jim_Obj *objPtr)
{
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
return -1;
}if (SetDictFromAny(interp, objPtr) != JIM_OK) { ... }
return objPtr->internalRep.dictValue->len / 2;
}{ ... }
/* ... */
Jim_Obj *Jim_DictMerge(Jim_Interp *interp, int objc, Jim_Obj *const *objv)
{
Jim_Obj *objPtr = Jim_NewDictObj(interp, NULL, 0);
int i;
JimPanic((objc == 0, "Jim_DictMerge called with objc=0"));
for (i = 0; i < objc; i++) {
Jim_Obj **table;
int tablelen;
int j;
/* ... */
table = Jim_DictPairs(interp, objv[i], &tablelen);
if (tablelen && !table) {
Jim_FreeNewObj(interp, objPtr);
return NULL;
}if (tablelen && !table) { ... }
for (j = 0; j < tablelen; j += 2) {
DictAddElement(interp, objPtr, table[j], table[j + 1]);
}for (j = 0; j < tablelen; j += 2) { ... }
}for (i = 0; i < objc; i++) { ... }
return objPtr;
}{ ... }
int Jim_DictInfo(Jim_Interp *interp, Jim_Obj *objPtr)
{
char buffer[100];
Jim_Obj *output;
Jim_Dict *dict;
if (SetDictFromAny(interp, objPtr) != JIM_OK) {
return JIM_ERR;
}if (SetDictFromAny(interp, objPtr) != JIM_OK) { ... }
dict = objPtr->internalRep.dictValue;
snprintf(buffer, sizeof(buffer), "%d entries in table, %d buckets", dict->len, dict->size);
output = Jim_NewStringObj(interp, buffer, -1);
Jim_SetResult(interp, output);
return JIM_OK;
}{ ... }
static int Jim_EvalEnsemble(Jim_Interp *interp, const char *basecmd, const char *subcmd, int argc, Jim_Obj *const *argv)
{
Jim_Obj *prefixObj = Jim_NewStringObj(interp, basecmd, -1);
Jim_AppendString(interp, prefixObj, " ", 1);
Jim_AppendString(interp, prefixObj, subcmd, -1);
return Jim_EvalObjPrefix(interp, prefixObj, argc, argv);
}{ ... }
/* ... */
static int JimDictWith(Jim_Interp *interp, Jim_Obj *dictVarName, Jim_Obj *const *keyv, int keyc, Jim_Obj *scriptObj)
{
int i;
Jim_Obj *objPtr;
Jim_Obj *dictObj;
Jim_Obj **dictValues;
int len;
int ret = JIM_OK;
dictObj = Jim_GetVariable(interp, dictVarName, JIM_ERRMSG);
if (dictObj == NULL || Jim_DictKeysVector(interp, dictObj, keyv, keyc, &objPtr, JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}if (dictObj == NULL || Jim_DictKeysVector(interp, dictObj, keyv, keyc, &objPtr, JIM_ERRMSG) != JIM_OK) { ... }
dictValues = Jim_DictPairs(interp, objPtr, &len);
if (len && dictValues == NULL) {
return JIM_ERR;
}if (len && dictValues == NULL) { ... }
for (i = 0; i < len; i += 2) {
if (Jim_SetVariable(interp, dictValues[i], dictValues[i + 1]) == JIM_ERR) {
return JIM_ERR;
}if (Jim_SetVariable(interp, dictValues[i], dictValues[i + 1]) == JIM_ERR) { ... }
}for (i = 0; i < len; i += 2) { ... }
if (Jim_Length(scriptObj)) {
ret = Jim_EvalObj(interp, scriptObj);
if (ret == JIM_OK && Jim_GetVariable(interp, dictVarName, 0) != NULL) {
Jim_Obj **newkeyv = Jim_Alloc(sizeof(*newkeyv) * (keyc + 1));
for (i = 0; i < keyc; i++) {
newkeyv[i] = keyv[i];
}for (i = 0; i < keyc; i++) { ... }
for (i = 0; i < len; i += 2) {
objPtr = Jim_GetVariable(interp, dictValues[i], 0);
newkeyv[keyc] = dictValues[i];
Jim_SetDictKeysVector(interp, dictVarName, newkeyv, keyc + 1, objPtr, 0);
}for (i = 0; i < len; i += 2) { ... }
Jim_Free(newkeyv);
}if (ret == JIM_OK && Jim_GetVariable(interp, dictVarName, 0) != NULL) { ... }
}if (Jim_Length(scriptObj)) { ... }
return ret;
}{ ... }
static int Jim_DictCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
int rc;
int types = JIM_DICTMATCH_KEYS;
int option;
static const char * const options[] = {
"create", "get", "set", "unset", "exists", "keys", "size", "info",
"merge", "with", "append", "lappend", "incr", "remove", "values", "for",
"replace", "update", "getwithdefault", NULL
...};
enum
{
OPT_CREATE, OPT_GET, OPT_SET, OPT_UNSET, OPT_EXISTS, OPT_KEYS, OPT_SIZE, OPT_INFO,
OPT_MERGE, OPT_WITH, OPT_APPEND, OPT_LAPPEND, OPT_INCR, OPT_REMOVE, OPT_VALUES, OPT_FOR,
OPT_REPLACE, OPT_UPDATE, OPT_GETDEF,
...};
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "subcommand ?arguments ...?");
return JIM_ERR;
}if (argc < 2) { ... }
if (Jim_GetEnum(interp, argv[1], options, &option, "subcommand", JIM_ERRMSG) != JIM_OK) {
if (Jim_CompareStringImmediate(interp, argv[1], "getdef") == 0) {
return Jim_CheckShowCommands(interp, argv[1], options);
}if (Jim_CompareStringImmediate(interp, argv[1], "getdef") == 0) { ... }
option = OPT_GETDEF;
}if (Jim_GetEnum(interp, argv[1], options, &option, "subcommand", JIM_ERRMSG) != JIM_OK) { ... }
switch (option) {
case OPT_GET:
if (argc < 3) {
Jim_WrongNumArgs(interp, 2, argv, "dictionary ?key ...?");
return JIM_ERR;
}if (argc < 3) { ... }
if (Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr,
JIM_ERRMSG) != JIM_OK) {
return JIM_ERR;
}if (Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_ERRMSG) != JIM_OK) { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
case OPT_GET:
case OPT_GETDEF:
if (argc < 5) {
Jim_WrongNumArgs(interp, 2, argv, "dictionary ?key ...? key default");
return JIM_ERR;
}if (argc < 5) { ... }
rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 4, &objPtr, JIM_ERRMSG);
if (rc == -1) {
return JIM_ERR;
}if (rc == -1) { ... }
if (rc == JIM_ERR) {
Jim_SetResult(interp, argv[argc - 1]);
}if (rc == JIM_ERR) { ... }
else {
Jim_SetResult(interp, objPtr);
}else { ... }
return JIM_OK;
case OPT_GETDEF:
case OPT_SET:
if (argc < 5) {
Jim_WrongNumArgs(interp, 2, argv, "varName key ?key ...? value");
return JIM_ERR;
}if (argc < 5) { ... }
return Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 4, argv[argc - 1], JIM_ERRMSG);
case OPT_SET:
case OPT_EXISTS:
if (argc < 4) {
Jim_WrongNumArgs(interp, 2, argv, "dictionary key ?key ...?");
return JIM_ERR;
}if (argc < 4) { ... }
else {
int rc = Jim_DictKeysVector(interp, argv[2], argv + 3, argc - 3, &objPtr, JIM_NONE);
if (rc < 0) {
return JIM_ERR;
}if (rc < 0) { ... }
Jim_SetResultBool(interp, rc == JIM_OK);
return JIM_OK;
}else { ... }
case OPT_EXISTS:
case OPT_UNSET:
if (argc < 4) {
Jim_WrongNumArgs(interp, 2, argv, "varName key ?key ...?");
return JIM_ERR;
}if (argc < 4) { ... }
if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_NONE) != JIM_OK) {
return JIM_ERR;
}if (Jim_SetDictKeysVector(interp, argv[2], argv + 3, argc - 3, NULL, JIM_NONE) != JIM_OK) { ... }
return JIM_OK;
case OPT_UNSET:
case OPT_VALUES:
types = JIM_DICTMATCH_VALUES;
case OPT_VALUES:
case OPT_KEYS:
if (argc != 3 && argc != 4) {
Jim_WrongNumArgs(interp, 2, argv, "dictionary ?pattern?");
return JIM_ERR;
}if (argc != 3 && argc != 4) { ... }
return Jim_DictMatchTypes(interp, argv[2], argc == 4 ? argv[3] : NULL, types, types);
case OPT_KEYS:
case OPT_SIZE:
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "dictionary");
return JIM_ERR;
}if (argc != 3) { ... }
else if (Jim_DictSize(interp, argv[2]) < 0) {
return JIM_ERR;
}else if (Jim_DictSize(interp, argv[2]) < 0) { ... }
Jim_SetResultInt(interp, Jim_DictSize(interp, argv[2]));
return JIM_OK;
case OPT_SIZE:
case OPT_MERGE:
if (argc == 2) {
return JIM_OK;
}if (argc == 2) { ... }
objPtr = Jim_DictMerge(interp, argc - 2, argv + 2);
if (objPtr == NULL) {
return JIM_ERR;
}if (objPtr == NULL) { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
case OPT_MERGE:
case OPT_UPDATE:
if (argc < 6 || argc % 2) {
argc = 2;
}if (argc < 6 || argc % 2) { ... }
break;
case OPT_UPDATE:
case OPT_CREATE:
if (argc % 2) {
Jim_WrongNumArgs(interp, 2, argv, "?key value ...?");
return JIM_ERR;
}if (argc % 2) { ... }
objPtr = Jim_NewDictObj(interp, argv + 2, argc - 2);
Jim_SetResult(interp, objPtr);
return JIM_OK;
case OPT_CREATE:
case OPT_INFO:
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "dictionary");
return JIM_ERR;
}if (argc != 3) { ... }
return Jim_DictInfo(interp, argv[2]);
case OPT_INFO:
case OPT_WITH:
if (argc < 4) {
Jim_WrongNumArgs(interp, 2, argv, "dictVar ?key ...? script");
return JIM_ERR;
}if (argc < 4) { ... }
return JimDictWith(interp, argv[2], argv + 3, argc - 4, argv[argc - 1]);case OPT_WITH:
}switch (option) { ... }
return Jim_EvalEnsemble(interp, "dict", options[option], argc - 2, argv + 2);
}{ ... }
static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
static const char * const options[] = {
"-nobackslashes", "-nocommands", "-novariables", NULL
...};
enum
{ OPT_NOBACKSLASHES, OPT_NOCOMMANDS, OPT_NOVARIABLES };
int i;
int flags = JIM_SUBST_FLAG;
Jim_Obj *objPtr;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "?options? string");
return JIM_ERR;
}if (argc < 2) { ... }
for (i = 1; i < (argc - 1); i++) {
int option;
if (Jim_GetEnum(interp, argv[i], options, &option, NULL,
JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetEnum(interp, argv[i], options, &option, NULL, JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) { ... }
switch (option) {
case OPT_NOBACKSLASHES:
flags |= JIM_SUBST_NOESC;
break;case OPT_NOBACKSLASHES:
case OPT_NOCOMMANDS:
flags |= JIM_SUBST_NOCMD;
break;case OPT_NOCOMMANDS:
case OPT_NOVARIABLES:
flags |= JIM_SUBST_NOVAR;
break;case OPT_NOVARIABLES:
}switch (option) { ... }
}for (i = 1; i < (argc - 1); i++) { ... }
if (Jim_SubstObj(interp, argv[argc - 1], &objPtr, flags) != JIM_OK) {
return JIM_ERR;
}if (Jim_SubstObj(interp, argv[argc - 1], &objPtr, flags) != JIM_OK) { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
}{ ... }
#ifdef jim_ext_namespace
static int JimIsGlobalNamespace(Jim_Obj *objPtr)
{
int len;
const char *str = Jim_GetString(objPtr, &len);
return len >= 2 && str[0] == ':' && str[1] == ':';
}{ ... }
/* ... */#endif
static int Jim_InfoCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int cmd;
Jim_Obj *objPtr;
int mode = 0;
static const char * const commands[] = {
"body", "statics", "commands", "procs", "channels", "exists", "globals", "level", "frame", "locals",
"vars", "version", "patchlevel", "complete", "args", "hostname",
"script", "source", "stacktrace", "nameofexecutable", "returncodes",
"references", "alias", NULL
...};
enum
{ INFO_BODY, INFO_STATICS, INFO_COMMANDS, INFO_PROCS, INFO_CHANNELS, INFO_EXISTS, INFO_GLOBALS, INFO_LEVEL,
INFO_FRAME, INFO_LOCALS, INFO_VARS, INFO_VERSION, INFO_PATCHLEVEL, INFO_COMPLETE, INFO_ARGS,
INFO_HOSTNAME, INFO_SCRIPT, INFO_SOURCE, INFO_STACKTRACE, INFO_NAMEOFEXECUTABLE,
INFO_RETURNCODES, INFO_REFERENCES, INFO_ALIAS,
...};
#ifdef jim_ext_namespace
int nons = 0;
if (argc > 2 && Jim_CompareStringImmediate(interp, argv[1], "-nons")) {
argc--;
argv++;
nons = 1;
}if (argc > 2 && Jim_CompareStringImmediate(interp, argv[1], "-nons")) { ... }
/* ... */#endif
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "subcommand ?args ...?");
return JIM_ERR;
}if (argc < 2) { ... }
if (Jim_GetEnum(interp, argv[1], commands, &cmd, "subcommand", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
return Jim_CheckShowCommands(interp, argv[1], commands);
}if (Jim_GetEnum(interp, argv[1], commands, &cmd, "subcommand", JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) { ... }
switch (cmd) {
case INFO_EXISTS:
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "varName");
return JIM_ERR;
}if (argc != 3) { ... }
Jim_SetResultBool(interp, Jim_GetVariable(interp, argv[2], 0) != NULL);
break;
case INFO_EXISTS:
case INFO_ALIAS:{
Jim_Cmd *cmdPtr;
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "command");
return JIM_ERR;
}if (argc != 3) { ... }
if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
return JIM_ERR;
}if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) { ... }
if (cmdPtr->isproc || cmdPtr->u.native.cmdProc != JimAliasCmd) {
Jim_SetResultFormatted(interp, "command \"%#s\" is not an alias", argv[2]);
return JIM_ERR;
}if (cmdPtr->isproc || cmdPtr->u.native.cmdProc != JimAliasCmd) { ... }
Jim_SetResult(interp, (Jim_Obj *)cmdPtr->u.native.privData);
return JIM_OK;
...}
case INFO_ALIAS:
case INFO_CHANNELS:
mode++;
#ifndef jim_ext_aio
Jim_SetResultString(interp, "aio not enabled", -1);
return JIM_ERR;/* ... */
#endif
case INFO_CHANNELS:
case INFO_PROCS:
mode++;
case INFO_PROCS:
case INFO_COMMANDS:
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "?pattern?");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
#ifdef jim_ext_namespace
if (!nons) {
if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
}if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) { ... }
}if (!nons) { ... }
/* ... */#endif
Jim_SetResult(interp, JimCommandsList(interp, (argc == 3) ? argv[2] : NULL, mode));
break;
case INFO_COMMANDS:
case INFO_VARS:
mode++;
case INFO_VARS:
case INFO_LOCALS:
mode++;
case INFO_LOCALS:
case INFO_GLOBALS:
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "?pattern?");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
#ifdef jim_ext_namespace
if (!nons) {
if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) {
return Jim_EvalPrefix(interp, "namespace info", argc - 1, argv + 1);
}if (Jim_Length(interp->framePtr->nsObj) || (argc == 3 && JimIsGlobalNamespace(argv[2]))) { ... }
}if (!nons) { ... }
/* ... */#endif
Jim_SetResult(interp, JimVariablesList(interp, argc == 3 ? argv[2] : NULL, mode));
break;
case INFO_GLOBALS:
case INFO_SCRIPT:
if (argc != 2) {
Jim_WrongNumArgs(interp, 2, argv, "");
return JIM_ERR;
}if (argc != 2) { ... }
Jim_SetResult(interp, JimGetScript(interp, interp->currentScriptObj)->fileNameObj);
break;
case INFO_SCRIPT:
case INFO_SOURCE:{
jim_wide line;
Jim_Obj *resObjPtr;
Jim_Obj *fileNameObj;
if (argc != 3 && argc != 5) {
Jim_WrongNumArgs(interp, 2, argv, "source ?filename line?");
return JIM_ERR;
}if (argc != 3 && argc != 5) { ... }
if (argc == 5) {
if (Jim_GetWide(interp, argv[4], &line) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetWide(interp, argv[4], &line) != JIM_OK) { ... }
resObjPtr = Jim_NewStringObj(interp, Jim_String(argv[2]), Jim_Length(argv[2]));
JimSetSourceInfo(interp, resObjPtr, argv[3], line);
}if (argc == 5) { ... }
else {
if (argv[2]->typePtr == &sourceObjType) {
fileNameObj = argv[2]->internalRep.sourceValue.fileNameObj;
line = argv[2]->internalRep.sourceValue.lineNumber;
}if (argv[2]->typePtr == &sourceObjType) { ... }
else if (argv[2]->typePtr == &scriptObjType) {
ScriptObj *script = JimGetScript(interp, argv[2]);
fileNameObj = script->fileNameObj;
line = script->firstline;
}else if (argv[2]->typePtr == &scriptObjType) { ... }
else {
fileNameObj = interp->emptyObj;
line = 1;
}else { ... }
resObjPtr = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, resObjPtr, fileNameObj);
Jim_ListAppendElement(interp, resObjPtr, Jim_NewIntObj(interp, line));
}else { ... }
Jim_SetResult(interp, resObjPtr);
break;
...}
case INFO_SOURCE:
case INFO_STACKTRACE:
Jim_SetResult(interp, interp->stackTrace);
break;
case INFO_STACKTRACE:
case INFO_LEVEL:
case INFO_FRAME:
switch (argc) {
case 2:
Jim_SetResultInt(interp, interp->framePtr->level);
break;
case 2:
case 3:
if (JimInfoLevel(interp, argv[2], &objPtr, cmd == INFO_LEVEL) != JIM_OK) {
return JIM_ERR;
}if (JimInfoLevel(interp, argv[2], &objPtr, cmd == INFO_LEVEL) != JIM_OK) { ... }
Jim_SetResult(interp, objPtr);
break;
case 3:
default:
Jim_WrongNumArgs(interp, 2, argv, "?levelNum?");
return JIM_ERR;default
}switch (argc) { ... }
break;
case INFO_FRAME:
case INFO_BODY:
case INFO_STATICS:
case INFO_ARGS:{
Jim_Cmd *cmdPtr;
if (argc != 3) {
Jim_WrongNumArgs(interp, 2, argv, "procname");
return JIM_ERR;
}if (argc != 3) { ... }
if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) {
return JIM_ERR;
}if ((cmdPtr = Jim_GetCommand(interp, argv[2], JIM_ERRMSG)) == NULL) { ... }
if (!cmdPtr->isproc) {
Jim_SetResultFormatted(interp, "command \"%#s\" is not a procedure", argv[2]);
return JIM_ERR;
}if (!cmdPtr->isproc) { ... }
switch (cmd) {
case INFO_BODY:
Jim_SetResult(interp, cmdPtr->u.proc.bodyObjPtr);
break;case INFO_BODY:
case INFO_ARGS:
Jim_SetResult(interp, cmdPtr->u.proc.argListObjPtr);
break;case INFO_ARGS:
case INFO_STATICS:
if (cmdPtr->u.proc.staticVars) {
Jim_SetResult(interp, JimHashtablePatternMatch(interp, cmdPtr->u.proc.staticVars,
NULL, JimVariablesMatch, JIM_VARLIST_LOCALS | JIM_VARLIST_VALUES));
}if (cmdPtr->u.proc.staticVars) { ... }
break;case INFO_STATICS:
}switch (cmd) { ... }
break;
...}
case INFO_ARGS:
case INFO_VERSION:
case INFO_PATCHLEVEL:{
char buf[(JIM_INTEGER_SPACE * 2) + 1];
sprintf(buf, "%d.%d", JIM_VERSION / 100, JIM_VERSION % 100);
Jim_SetResultString(interp, buf, -1);
break;
...}
case INFO_PATCHLEVEL:
case INFO_COMPLETE:
if (argc != 3 && argc != 4) {
Jim_WrongNumArgs(interp, 2, argv, "script ?missing?");
return JIM_ERR;
}if (argc != 3 && argc != 4) { ... }
else {
char missing;
Jim_SetResultBool(interp, Jim_ScriptIsComplete(interp, argv[2], &missing));
if (missing != ' ' && argc == 4) {
Jim_SetVariable(interp, argv[3], Jim_NewStringObj(interp, &missing, 1));
}if (missing != ' ' && argc == 4) { ... }
}else { ... }
break;
case INFO_COMPLETE:
case INFO_HOSTNAME:
return Jim_Eval(interp, "os.gethostname");
case INFO_HOSTNAME:
case INFO_NAMEOFEXECUTABLE:
return Jim_Eval(interp, "{info nameofexecutable}");
case INFO_NAMEOFEXECUTABLE:
case INFO_RETURNCODES:
if (argc == 2) {
int i;
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
for (i = 0; jimReturnCodes[i]; i++) {
Jim_ListAppendElement(interp, listObjPtr, Jim_NewIntObj(interp, i));
Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp,
jimReturnCodes[i], -1));
}for (i = 0; jimReturnCodes[i]; i++) { ... }
Jim_SetResult(interp, listObjPtr);
}if (argc == 2) { ... }
else if (argc == 3) {
long code;
const char *name;
if (Jim_GetLong(interp, argv[2], &code) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetLong(interp, argv[2], &code) != JIM_OK) { ... }
name = Jim_ReturnCode(code);
if (*name == '?') {
Jim_SetResultInt(interp, code);
}if (*name == '?') { ... }
else {
Jim_SetResultString(interp, name, -1);
}else { ... }
}else if (argc == 3) { ... }
else {
Jim_WrongNumArgs(interp, 2, argv, "?code?");
return JIM_ERR;
}else { ... }
break;case INFO_RETURNCODES:
case INFO_REFERENCES:
#ifdef JIM_REFERENCES
return JimInfoReferences(interp, argc, argv);
#else
Jim_SetResultString(interp, "not supported", -1);
return JIM_ERR;/* ... */
#endifcase INFO_REFERENCES:
}switch (cmd) { ... }
return JIM_OK;
}{ ... }
static int Jim_ExistsCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
int result = 0;
static const char * const options[] = {
"-command", "-proc", "-alias", "-var", NULL
...};
enum
{
OPT_COMMAND, OPT_PROC, OPT_ALIAS, OPT_VAR
...};
int option;
if (argc == 2) {
option = OPT_VAR;
objPtr = argv[1];
}if (argc == 2) { ... }
else if (argc == 3) {
if (Jim_GetEnum(interp, argv[1], options, &option, NULL, JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) {
return JIM_ERR;
}if (Jim_GetEnum(interp, argv[1], options, &option, NULL, JIM_ERRMSG | JIM_ENUM_ABBREV) != JIM_OK) { ... }
objPtr = argv[2];
}else if (argc == 3) { ... }
else {
Jim_WrongNumArgs(interp, 1, argv, "?option? name");
return JIM_ERR;
}else { ... }
if (option == OPT_VAR) {
result = Jim_GetVariable(interp, objPtr, 0) != NULL;
}if (option == OPT_VAR) { ... }
else {
Jim_Cmd *cmd = Jim_GetCommand(interp, objPtr, JIM_NONE);
if (cmd) {
switch (option) {
case OPT_COMMAND:
result = 1;
break;
case OPT_COMMAND:
case OPT_ALIAS:
result = cmd->isproc == 0 && cmd->u.native.cmdProc == JimAliasCmd;
break;
case OPT_ALIAS:
case OPT_PROC:
result = cmd->isproc;
break;case OPT_PROC:
}switch (option) { ... }
}if (cmd) { ... }
}else { ... }
Jim_SetResultBool(interp, result);
return JIM_OK;
}{ ... }
static int Jim_SplitCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *str, *splitChars, *noMatchStart;
int splitLen, strLen;
Jim_Obj *resObjPtr;
int c;
int len;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "string ?splitChars?");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
str = Jim_GetString(argv[1], &len);
if (len == 0) {
return JIM_OK;
}if (len == 0) { ... }
strLen = Jim_Utf8Length(interp, argv[1]);
if (argc == 2) {
splitChars = " \n\t\r";
splitLen = 4;
}if (argc == 2) { ... }
else {
splitChars = Jim_String(argv[2]);
splitLen = Jim_Utf8Length(interp, argv[2]);
}else { ... }
noMatchStart = str;
resObjPtr = Jim_NewListObj(interp, NULL, 0);
if (splitLen) {
Jim_Obj *objPtr;
while (strLen--) {
const char *sc = splitChars;
int scLen = splitLen;
int sl = utf8_tounicode(str, &c);
while (scLen--) {
int pc;
sc += utf8_tounicode(sc, &pc);
if (c == pc) {
objPtr = Jim_NewStringObj(interp, noMatchStart, (str - noMatchStart));
Jim_ListAppendElement(interp, resObjPtr, objPtr);
noMatchStart = str + sl;
break;
}if (c == pc) { ... }
}while (scLen--) { ... }
str += sl;
}while (strLen--) { ... }
objPtr = Jim_NewStringObj(interp, noMatchStart, (str - noMatchStart));
Jim_ListAppendElement(interp, resObjPtr, objPtr);
}if (splitLen) { ... }
else {
/* ... */
Jim_Obj **commonObj = NULL;
#define NUM_COMMON (128 - 9)
while (strLen--) {
int n = utf8_tounicode(str, &c);
#ifdef JIM_OPTIMIZATION
if (c >= 9 && c < 128) {
c -= 9;
if (!commonObj) {
commonObj = Jim_Alloc(sizeof(*commonObj) * NUM_COMMON);
memset(commonObj, 0, sizeof(*commonObj) * NUM_COMMON);
}if (!commonObj) { ... }
if (!commonObj[c]) {
commonObj[c] = Jim_NewStringObj(interp, str, 1);
}if (!commonObj[c]) { ... }
Jim_ListAppendElement(interp, resObjPtr, commonObj[c]);
str++;
continue;
}if (c >= 9 && c < 128) { ... }
/* ... */#endif
Jim_ListAppendElement(interp, resObjPtr, Jim_NewStringObjUtf8(interp, str, 1));
str += n;
}while (strLen--) { ... }
Jim_Free(commonObj);
}else { ... }
Jim_SetResult(interp, resObjPtr);
return JIM_OK;
}{ ... }
static int Jim_JoinCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *joinStr;
int joinStrLen;
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "list ?joinString?");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
if (argc == 2) {
joinStr = " ";
joinStrLen = 1;
}if (argc == 2) { ... }
else {
joinStr = Jim_GetString(argv[2], &joinStrLen);
}else { ... }
Jim_SetResult(interp, Jim_ListJoin(interp, argv[1], joinStr, joinStrLen));
return JIM_OK;
}{ ... }
static int Jim_FormatCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "formatString ?arg arg ...?");
return JIM_ERR;
}if (argc < 2) { ... }
objPtr = Jim_FormatString(interp, argv[1], argc - 2, argv + 2);
if (objPtr == NULL)
return JIM_ERR;
Jim_SetResult(interp, objPtr);
return JIM_OK;
}{ ... }
static int Jim_ScanCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *listPtr, **outVec;
int outc, i;
if (argc < 3) {
Jim_WrongNumArgs(interp, 1, argv, "string format ?varName varName ...?");
return JIM_ERR;
}if (argc < 3) { ... }
if (argv[2]->typePtr != &scanFmtStringObjType)
SetScanFmtFromAny(interp, argv[2]);
if (FormatGetError(argv[2]) != 0) {
Jim_SetResultString(interp, FormatGetError(argv[2]), -1);
return JIM_ERR;
}if (FormatGetError(argv[2]) != 0) { ... }
if (argc > 3) {
int maxPos = FormatGetMaxPos(argv[2]);
int count = FormatGetCnvCount(argv[2]);
if (maxPos > argc - 3) {
Jim_SetResultString(interp, "\"%n$\" argument index out of range", -1);
return JIM_ERR;
}if (maxPos > argc - 3) { ... }
else if (count > argc - 3) {
Jim_SetResultString(interp, "different numbers of variable names and "
"field specifiers", -1);
return JIM_ERR;
}else if (count > argc - 3) { ... }
else if (count < argc - 3) {
Jim_SetResultString(interp, "variable is not assigned by any "
"conversion specifiers", -1);
return JIM_ERR;
}else if (count < argc - 3) { ... }
}if (argc > 3) { ... }
listPtr = Jim_ScanString(interp, argv[1], argv[2], JIM_ERRMSG);
if (listPtr == 0)
return JIM_ERR;
if (argc > 3) {
int rc = JIM_OK;
int count = 0;
if (listPtr != 0 && listPtr != (Jim_Obj *)EOF) {
int len = Jim_ListLength(interp, listPtr);
if (len != 0) {
JimListGetElements(interp, listPtr, &outc, &outVec);
for (i = 0; i < outc; ++i) {
if (Jim_Length(outVec[i]) > 0) {
++count;
if (Jim_SetVariable(interp, argv[3 + i], outVec[i]) != JIM_OK) {
rc = JIM_ERR;
}if (Jim_SetVariable(interp, argv[3 + i], outVec[i]) != JIM_OK) { ... }
}if (Jim_Length(outVec[i]) > 0) { ... }
}for (i = 0; i < outc; ++i) { ... }
}if (len != 0) { ... }
Jim_FreeNewObj(interp, listPtr);
}if (listPtr != 0 && listPtr != (Jim_Obj *)EOF) { ... }
else {
count = -1;
}else { ... }
if (rc == JIM_OK) {
Jim_SetResultInt(interp, count);
}if (rc == JIM_OK) { ... }
return rc;
}if (argc > 3) { ... }
else {
if (listPtr == (Jim_Obj *)EOF) {
Jim_SetResult(interp, Jim_NewListObj(interp, 0, 0));
return JIM_OK;
}if (listPtr == (Jim_Obj *)EOF) { ... }
Jim_SetResult(interp, listPtr);
}else { ... }
return JIM_OK;
}{ ... }
static int Jim_ErrorCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc != 2 && argc != 3) {
Jim_WrongNumArgs(interp, 1, argv, "message ?stacktrace?");
return JIM_ERR;
}if (argc != 2 && argc != 3) { ... }
Jim_SetResult(interp, argv[1]);
if (argc == 3) {
JimSetStackTrace(interp, argv[2]);
return JIM_ERR;
}if (argc == 3) { ... }
interp->addStackTrace++;
return JIM_ERR;
}{ ... }
static int Jim_LrangeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
if (argc != 4) {
Jim_WrongNumArgs(interp, 1, argv, "list first last");
return JIM_ERR;
}if (argc != 4) { ... }
if ((objPtr = Jim_ListRange(interp, argv[1], argv[2], argv[3])) == NULL)
return JIM_ERR;
Jim_SetResult(interp, objPtr);
return JIM_OK;
}{ ... }
static int Jim_LrepeatCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *objPtr;
jim_wide count;
if (argc < 2 || Jim_GetWideExpr(interp, argv[1], &count) != JIM_OK || count < 0) {
Jim_WrongNumArgs(interp, 1, argv, "count ?value ...?");
return JIM_ERR;
}if (argc < 2 || Jim_GetWideExpr(interp, argv[1], &count) != JIM_OK || count < 0) { ... }
if (count == 0 || argc == 2) {
Jim_SetEmptyResult(interp);
return JIM_OK;
}if (count == 0 || argc == 2) { ... }
argc -= 2;
argv += 2;
objPtr = Jim_NewListObj(interp, NULL, 0);
ListEnsureLength(objPtr, argc * count);
while (count--) {
ListInsertElements(objPtr, -1, argc, argv);
}while (count--) { ... }
Jim_SetResult(interp, objPtr);
return JIM_OK;
}{ ... }
char **Jim_GetEnviron(void)
{
#if defined(HAVE__NSGETENVIRON)
return *_NSGetEnviron();
#else
#if !defined(NO_ENVIRON_EXTERN)
extern char **environ;
#endif
return environ;/* ... */
#endif
}{ ... }
void Jim_SetEnviron(char **env)
{
#if defined(HAVE__NSGETENVIRON)
*_NSGetEnviron() = env;
#else
#if !defined(NO_ENVIRON_EXTERN)
extern char **environ;
#endif
environ = env;/* ... */
#endif
}{ ... }
static int Jim_EnvCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
const char *key;
const char *val;
if (argc == 1) {
char **e = Jim_GetEnviron();
int i;
Jim_Obj *listObjPtr = Jim_NewListObj(interp, NULL, 0);
for (i = 0; e[i]; i++) {
const char *equals = strchr(e[i], '=');
if (equals) {
Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp, e[i],
equals - e[i]));
Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp, equals + 1, -1));
}if (equals) { ... }
}for (i = 0; e[i]; i++) { ... }
Jim_SetResult(interp, listObjPtr);
return JIM_OK;
}if (argc == 1) { ... }
if (argc > 3) {
Jim_WrongNumArgs(interp, 1, argv, "varName ?default?");
return JIM_ERR;
}if (argc > 3) { ... }
key = Jim_String(argv[1]);
val = getenv(key);
if (val == NULL) {
if (argc < 3) {
Jim_SetResultFormatted(interp, "environment variable \"%#s\" does not exist", argv[1]);
return JIM_ERR;
}if (argc < 3) { ... }
val = Jim_String(argv[2]);
}if (val == NULL) { ... }
Jim_SetResult(interp, Jim_NewStringObj(interp, val, -1));
return JIM_OK;
}{ ... }
static int Jim_SourceCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int retval;
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "fileName");
return JIM_ERR;
}if (argc != 2) { ... }
retval = Jim_EvalFile(interp, Jim_String(argv[1]));
if (retval == JIM_RETURN)
return JIM_OK;
return retval;
}{ ... }
static int Jim_LreverseCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj *revObjPtr, **ele;
int len;
if (argc != 2) {
Jim_WrongNumArgs(interp, 1, argv, "list");
return JIM_ERR;
}if (argc != 2) { ... }
JimListGetElements(interp, argv[1], &len, &ele);
revObjPtr = Jim_NewListObj(interp, NULL, 0);
ListEnsureLength(revObjPtr, len);
len--;
while (len >= 0)
ListAppendElement(revObjPtr, ele[len--]);
Jim_SetResult(interp, revObjPtr);
return JIM_OK;
}{ ... }
static int JimRangeLen(jim_wide start, jim_wide end, jim_wide step)
{
jim_wide len;
if (step == 0)
return -1;
if (start == end)
return 0;
else if (step > 0 && start > end)
return -1;
else if (step < 0 && end > start)
return -1;
len = end - start;
if (len < 0)
len = -len;
if (step < 0)
step = -step;
len = 1 + ((len - 1) / step);
/* ... */
if (len > INT_MAX)
len = INT_MAX;
return (int)((len < 0) ? -1 : len);
}{ ... }
static int Jim_RangeCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_wide start = 0, end, step = 1;
int len, i;
Jim_Obj *objPtr;
if (argc < 2 || argc > 4) {
Jim_WrongNumArgs(interp, 1, argv, "?start? end ?step?");
return JIM_ERR;
}if (argc < 2 || argc > 4) { ... }
if (argc == 2) {
if (Jim_GetWideExpr(interp, argv[1], &end) != JIM_OK)
return JIM_ERR;
}if (argc == 2) { ... }
else {
if (Jim_GetWideExpr(interp, argv[1], &start) != JIM_OK ||
Jim_GetWideExpr(interp, argv[2], &end) != JIM_OK)
return JIM_ERR;
if (argc == 4 && Jim_GetWideExpr(interp, argv[3], &step) != JIM_OK)
return JIM_ERR;
}else { ... }
if ((len = JimRangeLen(start, end, step)) == -1) {
Jim_SetResultString(interp, "Invalid (infinite?) range specified", -1);
return JIM_ERR;
}if ((len = JimRangeLen(start, end, step)) == -1) { ... }
objPtr = Jim_NewListObj(interp, NULL, 0);
ListEnsureLength(objPtr, len);
for (i = 0; i < len; i++)
ListAppendElement(objPtr, Jim_NewIntObj(interp, start + i * step));
Jim_SetResult(interp, objPtr);
return JIM_OK;
}{ ... }
static int Jim_RandCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
jim_wide min = 0, max = 0, len, maxMul;
if (argc < 1 || argc > 3) {
Jim_WrongNumArgs(interp, 1, argv, "?min? max");
return JIM_ERR;
}if (argc < 1 || argc > 3) { ... }
if (argc == 1) {
max = JIM_WIDE_MAX;
}if (argc == 1) { ... } else if (argc == 2) {
if (Jim_GetWideExpr(interp, argv[1], &max) != JIM_OK)
return JIM_ERR;
}else if (argc == 2) { ... } else if (argc == 3) {
if (Jim_GetWideExpr(interp, argv[1], &min) != JIM_OK ||
Jim_GetWideExpr(interp, argv[2], &max) != JIM_OK)
return JIM_ERR;
}else if (argc == 3) { ... }
len = max-min;
if (len < 0) {
Jim_SetResultString(interp, "Invalid arguments (max < min)", -1);
return JIM_ERR;
}if (len < 0) { ... }
maxMul = JIM_WIDE_MAX - (len ? (JIM_WIDE_MAX%len) : 0);
while (1) {
jim_wide r;
JimRandomBytes(interp, &r, sizeof(jim_wide));
if (r < 0 || r >= maxMul) continue;
r = (len == 0) ? 0 : r%len;
Jim_SetResultInt(interp, min+r);
return JIM_OK;
}while (1) { ... }
}{ ... }
static const struct {
const char *name;
Jim_CmdProc *cmdProc;
...} Jim_CoreCommandsTable[] = {
{"alias", Jim_AliasCoreCommand},
{"set", Jim_SetCoreCommand},
{"unset", Jim_UnsetCoreCommand},
{"puts", Jim_PutsCoreCommand},
{"+", Jim_AddCoreCommand},
{"*", Jim_MulCoreCommand},
{"-", Jim_SubCoreCommand},
{"/", Jim_DivCoreCommand},
{"incr", Jim_IncrCoreCommand},
{"while", Jim_WhileCoreCommand},
{"loop", Jim_LoopCoreCommand},
{"for", Jim_ForCoreCommand},
{"foreach", Jim_ForeachCoreCommand},
{"lmap", Jim_LmapCoreCommand},
{"lassign", Jim_LassignCoreCommand},
{"if", Jim_IfCoreCommand},
{"switch", Jim_SwitchCoreCommand},
{"list", Jim_ListCoreCommand},
{"lindex", Jim_LindexCoreCommand},
{"lset", Jim_LsetCoreCommand},
{"lsearch", Jim_LsearchCoreCommand},
{"llength", Jim_LlengthCoreCommand},
{"lappend", Jim_LappendCoreCommand},
{"linsert", Jim_LinsertCoreCommand},
{"lreplace", Jim_LreplaceCoreCommand},
{"lsort", Jim_LsortCoreCommand},
{"append", Jim_AppendCoreCommand},
#if defined(JIM_DEBUG_COMMAND) && !defined(JIM_BOOTSTRAP)
{"debug", Jim_DebugCoreCommand}defined (JIM_BOOTSTRAP) { ... },
#endif
{"eval", Jim_EvalCoreCommand},
{"uplevel", Jim_UplevelCoreCommand},
{"expr", Jim_ExprCoreCommand},
{"break", Jim_BreakCoreCommand},
{"continue", Jim_ContinueCoreCommand},
{"proc", Jim_ProcCoreCommand},
{"xtrace", Jim_XtraceCoreCommand},
{"concat", Jim_ConcatCoreCommand},
{"return", Jim_ReturnCoreCommand},
{"upvar", Jim_UpvarCoreCommand},
{"global", Jim_GlobalCoreCommand},
{"string", Jim_StringCoreCommand},
{"time", Jim_TimeCoreCommand},
{"exit", Jim_ExitCoreCommand},
{"catch", Jim_CatchCoreCommand},
{"try", Jim_TryCoreCommand},
#ifdef JIM_REFERENCES
{"ref", Jim_RefCoreCommand},
{"getref", Jim_GetrefCoreCommand},
{"setref", Jim_SetrefCoreCommand},
{"finalize", Jim_FinalizeCoreCommand},
{"collect", Jim_CollectCoreCommand},/* ... */
#endif
{"rename", Jim_RenameCoreCommand},
{"dict", Jim_DictCoreCommand},
{"subst", Jim_SubstCoreCommand},
{"info", Jim_InfoCoreCommand},
{"exists", Jim_ExistsCoreCommand},
{"split", Jim_SplitCoreCommand},
{"join", Jim_JoinCoreCommand},
{"format", Jim_FormatCoreCommand},
{"scan", Jim_ScanCoreCommand},
{"error", Jim_ErrorCoreCommand},
{"lrange", Jim_LrangeCoreCommand},
{"lrepeat", Jim_LrepeatCoreCommand},
{"env", Jim_EnvCoreCommand},
{"source", Jim_SourceCoreCommand},
{"lreverse", Jim_LreverseCoreCommand},
{"range", Jim_RangeCoreCommand},
{"rand", Jim_RandCoreCommand},
{"tailcall", Jim_TailcallCoreCommand},
{"local", Jim_LocalCoreCommand},
{"upcall", Jim_UpcallCoreCommand},
{"apply", Jim_ApplyCoreCommand},
{NULL, NULL},
...};
void Jim_RegisterCoreCommands(Jim_Interp *interp)
{
int i = 0;
while (Jim_CoreCommandsTable[i].name != NULL) {
Jim_CreateCommand(interp,
Jim_CoreCommandsTable[i].name, Jim_CoreCommandsTable[i].cmdProc, NULL, NULL);
i++;
}while (Jim_CoreCommandsTable[i].name != NULL) { ... }
}{ ... }
/* ... */
void Jim_MakeErrorMessage(Jim_Interp *interp)
{
Jim_Obj *argv[2];
argv[0] = Jim_NewStringObj(interp, "errorInfo", -1);
argv[1] = interp->result;
Jim_EvalObjVector(interp, 2, argv);
}{ ... }
/* ... */
static char **JimSortStringTable(const char *const *tablePtr)
{
int count;
char **tablePtrSorted;
for (count = 0; tablePtr[count]; count++) {
}for (count = 0; tablePtr[count]; count++) { ... }
tablePtrSorted = Jim_Alloc(sizeof(char *) * (count + 1));
memcpy(tablePtrSorted, tablePtr, sizeof(char *) * count);
qsort(tablePtrSorted, count, sizeof(char *), qsortCompareStringPointers);
tablePtrSorted[count] = NULL;
return tablePtrSorted;
}{ ... }
static void JimSetFailedEnumResult(Jim_Interp *interp, const char *arg, const char *badtype,
const char *prefix, const char *const *tablePtr, const char *name)
{
char **tablePtrSorted;
int i;
if (name == NULL) {
name = "option";
}if (name == NULL) { ... }
Jim_SetResultFormatted(interp, "%s%s \"%s\": must be ", badtype, name, arg);
tablePtrSorted = JimSortStringTable(tablePtr);
for (i = 0; tablePtrSorted[i]; i++) {
if (tablePtrSorted[i + 1] == NULL && i > 0) {
Jim_AppendString(interp, Jim_GetResult(interp), "or ", -1);
}if (tablePtrSorted[i + 1] == NULL && i > 0) { ... }
Jim_AppendStrings(interp, Jim_GetResult(interp), prefix, tablePtrSorted[i], NULL);
if (tablePtrSorted[i + 1]) {
Jim_AppendString(interp, Jim_GetResult(interp), ", ", -1);
}if (tablePtrSorted[i + 1]) { ... }
}for (i = 0; tablePtrSorted[i]; i++) { ... }
Jim_Free(tablePtrSorted);
}{ ... }
/* ... */
int Jim_CheckShowCommands(Jim_Interp *interp, Jim_Obj *objPtr, const char *const *tablePtr)
{
if (Jim_CompareStringImmediate(interp, objPtr, "-commands")) {
int i;
char **tablePtrSorted = JimSortStringTable(tablePtr);
Jim_SetResult(interp, Jim_NewListObj(interp, NULL, 0));
for (i = 0; tablePtrSorted[i]; i++) {
Jim_ListAppendElement(interp, Jim_GetResult(interp), Jim_NewStringObj(interp, tablePtrSorted[i], -1));
}for (i = 0; tablePtrSorted[i]; i++) { ... }
Jim_Free(tablePtrSorted);
return JIM_OK;
}if (Jim_CompareStringImmediate(interp, objPtr, "-commands")) { ... }
return JIM_ERR;
}{ ... }
/* ... */
static const Jim_ObjType getEnumObjType = {
"get-enum",
NULL,
NULL,
NULL,
JIM_TYPE_REFERENCES
...};
int Jim_GetEnum(Jim_Interp *interp, Jim_Obj *objPtr,
const char *const *tablePtr, int *indexPtr, const char *name, int flags)
{
const char *bad = "bad ";
const char *const *entryPtr = NULL;
int i;
int match = -1;
int arglen;
const char *arg;
if (objPtr->typePtr == &getEnumObjType) {
if (objPtr->internalRep.ptrIntValue.ptr == tablePtr && objPtr->internalRep.ptrIntValue.int1 == flags) {
*indexPtr = objPtr->internalRep.ptrIntValue.int2;
return JIM_OK;
}if (objPtr->internalRep.ptrIntValue.ptr == tablePtr && objPtr->internalRep.ptrIntValue.int1 == flags) { ... }
}if (objPtr->typePtr == &getEnumObjType) { ... }
arg = Jim_GetString(objPtr, &arglen);
*indexPtr = -1;
for (entryPtr = tablePtr, i = 0; *entryPtr != NULL; entryPtr++, i++) {
if (Jim_CompareStringImmediate(interp, objPtr, *entryPtr)) {
match = i;
goto found;
}if (Jim_CompareStringImmediate(interp, objPtr, *entryPtr)) { ... }
if (flags & JIM_ENUM_ABBREV) {
/* ... */
if (strncmp(arg, *entryPtr, arglen) == 0) {
if (*arg == '-' && arglen == 1) {
break;
}if (*arg == '-' && arglen == 1) { ... }
if (match >= 0) {
bad = "ambiguous ";
goto ambiguous;
}if (match >= 0) { ... }
match = i;
}if (strncmp(arg, *entryPtr, arglen) == 0) { ... }
}if (flags & JIM_ENUM_ABBREV) { ... }
}for (entryPtr = tablePtr, i = 0; *entryPtr != NULL; entryPtr++, i++) { ... }
if (match >= 0) {
found:
Jim_FreeIntRep(interp, objPtr);
objPtr->typePtr = &getEnumObjType;
objPtr->internalRep.ptrIntValue.ptr = (void *)tablePtr;
objPtr->internalRep.ptrIntValue.int1 = flags;
objPtr->internalRep.ptrIntValue.int2 = match;
*indexPtr = match;
return JIM_OK;
}if (match >= 0) { ... }
ambiguous:
if (flags & JIM_ERRMSG) {
JimSetFailedEnumResult(interp, arg, bad, "", tablePtr, name);
}if (flags & JIM_ERRMSG) { ... }
return JIM_ERR;
}{ ... }
int Jim_FindByName(const char *name, const char * const array[], size_t len)
{
int i;
for (i = 0; i < (int)len; i++) {
if (array[i] && strcmp(array[i], name) == 0) {
return i;
}if (array[i] && strcmp(array[i], name) == 0) { ... }
}for (i = 0; i < (int)len; i++) { ... }
return -1;
}{ ... }
int Jim_IsDict(Jim_Obj *objPtr)
{
return objPtr->typePtr == &dictObjType;
}{ ... }
int Jim_IsList(Jim_Obj *objPtr)
{
return objPtr->typePtr == &listObjType;
}{ ... }
/* ... */
void Jim_SetResultFormatted(Jim_Interp *interp, const char *format, ...)
{
int len = strlen(format);
int extra = 0;
int n = 0;
const char *params[5];
int nobjparam = 0;
Jim_Obj *objparam[5];
char *buf;
va_list args;
int i;
va_start(args, format);
for (i = 0; i < len && n < 5; i++) {
int l;
if (strncmp(format + i, "%s", 2) == 0) {
params[n] = va_arg(args, char *);
l = strlen(params[n]);
}if (strncmp(format + i, "%s", 2) == 0) { ... }
else if (strncmp(format + i, "%#s", 3) == 0) {
Jim_Obj *objPtr = va_arg(args, Jim_Obj *);
params[n] = Jim_GetString(objPtr, &l);
objparam[nobjparam++] = objPtr;
Jim_IncrRefCount(objPtr);
}else if (strncmp(format + i, "%#s", 3) == 0) { ... }
else {
if (format[i] == '%') {
i++;
}if (format[i] == '%') { ... }
continue;
}else { ... }
n++;
extra += l;
}for (i = 0; i < len && n < 5; i++) { ... }
len += extra;
buf = Jim_Alloc(len + 1);
len = snprintf(buf, len + 1, format, params[0], params[1], params[2], params[3], params[4]);
va_end(args);
Jim_SetResult(interp, Jim_NewStringObjNoAlloc(interp, buf, len));
for (i = 0; i < nobjparam; i++) {
Jim_DecrRefCount(interp, objparam[i]);
}for (i = 0; i < nobjparam; i++) { ... }
}{ ... }
/* ... */
int Jim_CheckAbiVersion(Jim_Interp *interp, int abi_version)
{
if (abi_version != JIM_ABI_VERSION) {
Jim_SetResultString(interp, "ABI version mismatch", -1);
return JIM_ERR;
}if (abi_version != JIM_ABI_VERSION) { ... }
return JIM_OK;
}{ ... }
#ifndef jim_ext_package
int Jim_PackageProvide(Jim_Interp *interp, const char *name, const char *ver, int flags)
{
return JIM_OK;
}Jim_PackageProvide (Jim_Interp *interp, const char *name, const char *ver, int flags) { ... }
/* ... */#endif
#ifndef jim_ext_aio
FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *fhObj)
{
Jim_SetResultString(interp, "aio not enabled", -1);
return NULL;
}Jim_AioFilehandle (Jim_Interp *interp, Jim_Obj *fhObj) { ... }
/* ... */#endif
/* ... */