0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
| |
function main()
{
try{
debug.setTrace(false);
InsConvertSnipett();
}catch(e){
debug.traceFlash();
throw e;
}
debug.traceFlash();
}
var snipetjs = {};
snipetjs.VER_STR = "00_00_2010021802";
snipetjs.STR_COPYRIGHT = "Copyright (c) 2010 Moca. All right reserved.";
snipetjs.CommandMark = [':'];
snipetjs.CommandPrevIgnoreRe = [
/((http(s))|(ftp)):$/i,
/(TODO|FIXME):$i/i
];
snipetjs.extSupList = [
{nameFilter:'\\snipet.mac.js|', types:'snipet|skr-mac|js|cF'},
{nameFilter:'.mac.js|', types:'skr-mac|wsh-js|js|cF'},
{nameFilter:'.mac.vbs|', types:'skr-mac|wsh-vbs|vbs'},
{nameFilter:'.mac|', types:'skr-mac'},
{nameFilter:'.ppa|', types:'skr-mac|ppa'},
{nameFilter:'.txt|', types:'text'},
{nameFilter:'.htm|', types:'html|css|js|xmlF|xhtml'},
{nameFilter:'.html|', types:'html|css|js|xmlF|xhtml'},
{nameFilter:'.xhtml|', types:'xhtml|xml|xmlF|css|js|html'},
{nameFilter:'.css|', types:'css'},
{nameFilter:'.json|', types:'json|js'},
{nameFilter:'.js|', types:'js|json|cF|html|css'},
{nameFilter:'.bat|', types:'bat'},
{nameFilter:'.cmd|', types:'bat'},
{nameFilter:'.vbs|', types:'wsh-vbs|vbs|'},
{nameFilter:'.pls|', types:'wsh-pls|perls|perl'},
{nameFilter:'.c|', types:'c|cF'},
{nameFilter:'.cpp|', types:'cpp|c|cF'},
{nameFilter:'.cxx|', types:'cpp|c|cF'},
{nameFilter:'.h|', types:'c|cpp|cF'},
{nameFilter:'.rc|', types:'rc'},
{nameFilter:'.cs|', types:'cs|cF'},
{nameFilter:'.vb|', types:'vbnet|vb'},
{nameFilter:'.xaml|', types:'xamlxmlF'},
{nameFilter:'.java|', types:'java|cF'},
{nameFilter:'.jav|', types:'java|cF'},
{nameFilter:'.pl|', types:'perl'},
{nameFilter:'.rb|', types:'ruby'},
{nameFilter:'.py|', types:'python'},
{nameFilter:'.as|', types:'ascript|ecma4s|js|cF'},
{nameFilter:'.mxml|', types:'mxml|xmlF'},
{nameFilter:'.hsp|', types:'hsp'},
{nameFilter:'.shtml|', types:'html|css|js'},
{nameFilter:'.shm|', types:'html|css|js'},
{nameFilter:'.cgi|', types:'perl|html|css|js'},
{nameFilter:'.jsp|', types:'jsp|java|cF|html|css|js'},
{nameFilter:'.php|', types:'php|html|css|js'},
{nameFilter:'.asp|', types:'asp|html|css|js'},
{nameFilter:'.aspx|', types:'vbaspx|html|css|js'},
{nameFilter:'.yaml|', types:'yaml'},
{nameFilter:'.yml|', types:'yaml'},
{nameFilter:'.sql|', types:'sql'},
{nameFilter:'.xml|', types:'xhtml|mathml|svg|xml|xmlF'},
{nameFilter:'.svg|', types:'svg|xml|xmlF'},
{nameFilter:'.xsd|', types:'xsd|xml|xmlF'},
{nameFilter:'.mml|', types:'mathml|xml|xmlF'},
{nameFilter:'.xsl|', types:'xslt|xml|xmlF'},
{nameFilter:'.xslt|', types:'xslt|xml|xmlF'},
{nameFilter:'.bash|', types:'bash'},
{nameFilter:'.sh|', types:'shell'},
{nameFilter:'.mak|', types:'make'},
{nameFilter:'\\makefile|', types:'make'},
{nameFilter:'\\readme|', types:'txt'},
{nameFilter:'\\license|', types:'txt'},
{nameFilter:'||', types:'NONE'}
];
snipetjs.DefaultTypes = ['ALL'];
snipetjs.UnSaveDocTypes = null;
snipetjs.snipBuiltInList = [
{ type:"js", key:"fn", argl:0, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["function $${1}($${2}", ", $${a}", "){\n$${t}\t@@@\n$${t}}\n"]}, help:"function定義引数付"},
{ type:"js", key:"var", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["var $${1}", ", $${a}", ";\n"]}, help:"<変数名...>: var x;"},
{ type:"js", key:"vari", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["var $${1}=0", ", $${a}=0", ";\n"]}, help:"<変数名...>: var n=0;"},
{ type:"js", key:"vars", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["var $${1}=\"\"", ", $${a}=\"\"", ";\n"]}, help:"<変数名...>: var s=\"\";"},
{ type:"js", key:"vara", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["var $${1}=[$${2}", ", $${a}", "];\n"]}, help:"<変数名> [配列要素*]: var a=[];"},
{ type:"js", key:"varo", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["var $${1}={$${2}", ", $${a}", "};\n"]}, help:"<変数名> [名前値対*]: var o={};"},
{ type:"json", key:"arr", argl:0, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["[$${1}", ", $${a}", "]\n"]}, help:"[配列要素*]: [] / [a, b, .. n]"},
{ type:"json", key:"obj", argl:0, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["{$${1}", ", $${a}", "}\n"]}, help:"[名前値対*]: {} / {a, b, .. n}"},
{ type:"json", key:"objv", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["{\"$${2}\": $${1}", ", \"$${a}\": $${1}", "}\n"]}, help:"<v> [名前リスト*]: {\"a\": v, \"b\": v, ..\"n\": v}"},
{ type:"cF", key:"if", argl:0, argm:0, bak:1, rept:"tr", repv: "if( @@@ ){\n$${t}\t\n$${t}}\n", help:"if文空定義"},
{ type:"cF", key:"ifelse", argl:0, argm:0, bak:1, rept:"tr", repv: "if( @@@ ){\n$${t}\t\n$${t}}else{\n$${t}}\n", help:"if,else文空定義"},
{ type:"cF", key:"ifelseif", argl:0, argm:0, bak:1, rept:"tr", repv: "if( @@@ ){\n$${t}\t\n$${t}}else if( ){\n$${t}}\n", help:"if,else if文空定義"},
{ type:"cF", key:"if", argl:1, argm:10, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:[ "if( $${1}", " $${a}", " ){\n$${t}\t@@@\n$${t}}\n"]}, help:"if文"},
{ type:"cF", key:"ifelse", argl:1, argm:10, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:[ "if( $${1}", " $${a}", " ){\n$${t}\t@@@\n$${t}}else{\n$${t}}\n"]}, help:"if,else文"},
{ type:"cF", key:"ifelseif", argl:1, argm:10, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:[ "if( $${1}", " $${a}", " ){\n$${t}\t@@@\n$${t}}else if( ){\n$${t}}\n"]}, help:"if,else if文"},
{ type:"cF", key:"for", argl:0, argm:0, bak:1, rept:"tr", repv: "for( @@@; ; ){\n$${t}\t\n$${t}}\n", help:"for文空定義"},
{ type:"cF", key:"loopn", argl:2, argm:2, bak:1, rept:"tr", repv: "for( $${1} = 0; $${1} < $${2}; ++$${1} ){\n$${t}\t@@@\n$${t}}\n", help:"<ループ変数> <ループ回数>:昇順ループ for(a=0;a<b;++a){}"},
{ type:"cF", key:"loopr", argl:2, argm:2, bak:1, rept:"tr", repv: "for( $${1} = $${2}; 0 <= $${1}; --$${1} ){\n$${t}\t@@@\n$${t}}\n", help:"<ループ変数> <ループ回数>:降順ループ for(a=b;0<=a;--a)}{}"},
{ type:"cF", key:"while", argl:1, argm:10, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["while ($${1}", " $${a}", "){\n$${t}\t@@@\n$${t}}\n"]}, help:"while(){}"},
{ type:"cF", key:"switch", argl:0, argm:1, bak:1, rept:"tr", repv: "switch( $${1} ){\n$${t}case @@@:\n$${t}\tbreak;\n$${t}default:\n$${t}\tbreak;\n$${t}\t\n$${t}}\n", help:"[switch-var] swich case template"},
{ type:"cF", key:"switch", argl:2, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["switch(@@@$${1}){\n", "$${t}case $${a}:\n$${t}\tbreak;\n", "$${t}default:\n$${t}\tbreak;\n$${t}\t\n$${t}}\n"]}, help:"<swich-var> [case-vales*]: swich cases"},
{ type:"cF", key:"switchn", argl:1, argm:1, bak:1, rept:"tr", repv: "switch( @@@ ){\n$$ev{$$eq{$d$ds$${1}{$${t}case :\n$${t}\tbreak;\n}}}$${t}default:\n$${t}\tbreak;\n$${t}}\n", help:"<swich-var> [case-vales*]: swich cases"},
{ type:"cF", key:"do", argl:0, argm:1, bak:1, rept:"tr", repv: "do{\n$${t}\t@@@\n$${t}}while( );\n", help:"do while" },
{ type:"cF", key:"{", argl:0, argm:0, bak:1, rept:"tr", repv: "{\n$${t}\t@@@\n$${t}}\n", help:"{}補完"},
{ type:"c", key:"template", argl:0, argm:0, bak:1, rept:"tr", repv: "#include <stdio.h>\n#include <stdlib.h>\n\nint main(int argc, char **argv){\n\t@@@\n\treturn 0;\n}\n", help:"C mainテンプレート"},
{ type:"cpp", key:"class", argl:1, argm:1, bak:1, rept:"tr", repv: "class $${1}\n$${t}{\n$${t}public:\n$${t}\t$${1}();\n$${t}\t~$${1}();\n$${t}\t@@@\n$${t}private:\n$${t}};\n", help:"class "},
{ type:"cpp", key:"class", argl:2, argm:2, bak:1, rept:"tr", repv: "class $${1}: $${2}\n$${t}{\n$${t}public:\n$${t}\t$${1}();\n$${t}\t~$${1}();\n$${t}\t@@@\n$${t}private:\n$${t}};\n", help:"class "},
{ type:"psF", key:"begin", argl:0, argm:0, bak:1, rept:"tr", repv: "begin\n$${t}\t@@@\n$${t}end\n", help:"begin end補完"},
{ type:"psF", key:"Begin", argl:0, argm:0, bak:1, rept:"tr", repv: "Begin\n$${t}\t@@@\n$${t}End\n", help:"Begin End補完"},
{ type:"html", key:"dtd", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n \"http://www.w3.org/TR/html4/loose.dtd\">\n", help:"DTD HTML HTML 4.01 Transitional" },
{ type:"html", key:"dtd-401", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n \"http://www.w3.org/TR/html4/loose.dtd\">\n", help:"DTD HTML HTML 4.01 Transitional" },
{ type:"html", key:"dtd-401t", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n \"http://www.w3.org/TR/html4/loose.dtd\">\n", help:"DTD HTML HTML 4.01 Transitional" },
{ type:"html", key:"dtd-401tp",argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n", help:"DTD HTML 4.01 Transitional(PUBLIC only)" },
{ type:"html", key:"dtd-401s", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n", help:"DTD HTML 4.01 Strict" },
{ type:"html", key:"dtd-401sp",argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n", help:"DTD HTML 4.01 Strict(PUBLIC only)" },
{ type:"html", key:"dtd-401f", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">\n", help:"DTD HTML 4.01 Frameset" },
{ type:"html", key:"dtd-401fp",argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\">\n", help:"DTD HTML 4.01 Frameset(PUBLIC only)" },
{ type:"html", key:"dtd-5", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html>", help:"HTML5 doctype" },
{ type:"xhtml", key:"dtd", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n", help:"DTD XHTML 1.0 Transitional" },
{ type:"xhtml", key:"dtd-10t", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n", help:"DTD XHTML 1.0 Transitional" },
{ type:"xhtml", key:"dtd-10s", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n", help:"DTD XHTML 1.0 Transitional" },
{ type:"xhtml", key:"dtd-10f", argl:0, argm:0, bak:1, rept:"tx", repv: "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n", help:"DTD XHTML 1.0 Frameset" },
{ type:"html", key:"template", argl:0, argm:0, bak:1, rept:"tx", repv: "<html>\n<head>\n<title>@@@ </title>\n</head>\n<body>\n</body>\n</html>\n", help:"HTML テンプレート" },
{ type:"html", key:"css", argl:0, argm:0, bak:1, rept:"tr", repv: "<link rel=\"stylesheet\" type=\"text/css\" href=\"$${1}@@@.css\">\n", help:"<filename>: link css" },
{ type:"html", key:"script", argl:0, argm:0, bak:1, rept:"tr", repv: "<script type=\"text/javascript\" src=\"@@@$${1}\"></script>\n", help:"<filename>: link js" },
{ type:"html", key:"br", argl:2, argm:2, bak:0, rept:"tx", repv: "<br>\n", help:"HTML改行" },
{ type:"html", key:"urllink", argl:1, argm:2, bak:1, rept:"tr", repv: "<a href=\"$${1}\">@@@$${2}</a>\n", help:"HTML Aリンク作成" },
{ type:"html", key:"table", argl:0, argm:0, bak:1, rept:"tr", repv: "<table>\n$${t}\t<tr><td>@@@</td><td></td></tr>\n$${t}\t<tr><td></td><td></td></tr>\n$${t}</table>\n", help:"HTML table作成" },
{ type:"html", key:"tablen", argl:2, argm:3, bak:1, rept:"tr", repv: "<table>@@@\n$$ev{$$eq{$d$ds$${1}{$${t}\t<tr>$d$ds$${2}{<td>$${3}</td>}</tr>\n}}}$${t}</table>\n", help:"<行数> <列数> [セルの内容]:HTML table作成 tr単位で改行" },
{ type:"html", key:"table-td", argl:2, argm:3, bak:1, rept:"tr", repv: "<table>@@@\n$$ev{$$eq{$d$ds$${1}{$${t}\t<tr>\n$d$ds$${2}{$${t}\t\t<td>$${3}</td>\n}$${t}\t</tr>\n}}}$${t}</table>\n", help:"<行数> <列数> [セルの内容]:HTML table作成 trで改行" },
{ type:"html", key:"trtd", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:0, repe:0, reps:["<tr>", "<td>$${a}</td>", "</tr>\n"]}, help:"<内容>+:tr td を1行分生成"},
{ type:"html", key:"trth", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:0, repe:0, reps:["<tr>", "<th>$${a}</th>", "</tr>\n"]}, help:"<内容>+:tr th を1行分生成"},
{ type:"html", key:"trthtd", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["<tr><th>$${1}</th>", "<td>$${a}</td>", "</tr>\n"]}, help:"<内容>+:tr th td ..を1行分生成"},
{ type:"html", key:"trthtd", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["<tr><th>$${1}</th>", "<td>$${a}</td>", "</tr>\n"]}, help:"<内容>+:tr th td ..を1行分生成"},
{ type:"html", key:"select", argl:0, argm:4, bak:1, rept:"tr", repv: "<select id=\"$${1}\">\n<option value=\"@@@$${2}\" selected>$${2}</option>\n$${t}<option value=\"$${3}\">$${3}</option>\n$${t}<option value=\"$${4}\">$${4}</option>\n$${t}</select>\n", help:"<id> [val-list{1,3}]: HTML ブルダウンメニュー作成(3つ)" },
{ type:"html", key:"selectn", argl:0, argm:20, bak:1, rept:"tm", repv: {repf:2, repe:0, reps:["<select id=\"$${1}\">\n$${t}<option value=\"@@@$${2}\" selected>$${2}</option>\n","$${t}<option value=\"$${a}\">$${a}</option>\n" ,"$${t}</select>\n"]}, help:"<id> [val-list*]: HTML ブルダウンメニュー作成" },
{ type:"xhtml", key:"template", argl:0, argm:0, bak:1, rept:"tx", repv: "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" xml:lang=\"ja\">\n<head>\n<title>@@@ </title>\n</head>\n<body>\n</body>\n</html>\n", help:"XHTML テンプレート" },
{ type:"xhtml", key:"br", argl:2, argm:2, bak:0, rept:"tx", repv: "<br />\n", help:"XHTML改行" },
{ type:"xmlF", key:"tag", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["<$${1}", " $${a}", "=\"$${a}\"", ">@@@</$${1}>\n"]}, help:"TAG 属性"},
{ type:"xmlF", key:"tage", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:1, repe:0, reps:["<$${1}", " $${a}", "=\"$${a}\"", " />@@@\n"]}, help:"TAG 属性(empty tag)"},
{ type:"xmlF", key:"tag-list", argl:1, argm:20, bak:1, rept:"tm", repv: {repf:0, repe:0, reps:["@@@", "<$${a}></$${a}>", "</$${1}>\n"]}, help:"TAG 連続"},
{ type:"xmlF", key:"tag-nest2",argl:2, argm:2, bak:1, rept:"tr", repv: "<$${1}><$${2}>@@@</$${2}></$${1}>\n", help:"TAG 連続"},
{ type:"xmlF", key:"tag-nest3",argl:3, argm:3, bak:1, rept:"tr", repv: "<$${1}><$${2}><$${3}></$${3}>@@@</$${2}></$${1}>\n", help:"TAG 連続"},
{ type:"xmlF", key:"tag-nest4",argl:4, argm:4, bak:1, rept:"tr", repv: "<$${1}><$${2}><$${3}><$${4}>@@@</$${4}></$${3}></$${2}></$${1}>\n", help:"TAG 連続"},
{ type:"xmlF", key:"xml", argl:0, argm:0, bak:1, rept:"tx", repv: "<?xml version=\'1.0\'?>\n", help:"XML宣言"},
{ type:"xmlF", key:"xmleu", argl:0, argm:0, bak:1, rept:"tx", repv: "<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n", help:"XML宣言 UTF-8"},
{ type:"xmlF", key:"xmles", argl:0, argm:0, bak:1, rept:"tx", repv: "<?xml version=\'1.0\' encoding=\'Shift_JIS\'?>\n", help:"XML宣言 Shift_JIS"},
{ type:"xmlF", key:"xmls", argl:0, argm:0, bak:1, rept:"tx", repv: "<?xml version=\'1.0\' standalone=\'yes\'?>\n", help:"XML宣言 standaone "},
{ type:"xmlF", key:"xmleus", argl:0, argm:0, bak:1, rept:"tx", repv: "<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n", help:"XML宣言 UTF-8 standaone "},
{ type:"xmlF", key:"xmless", argl:0, argm:0, bak:1, rept:"tx", repv: "<?xml version=\'1.0\' encoding=\'Shift_JIS\' standalone=\'yes\'?>\n", help:"XML宣言 Shift_JIS standaone"},
{ type:"xmlF", key:"cdata", argl:0, argm:0, bak:1, rept:"tx", repv: "<![CDATA[@@@]]>\n", help:"CDATA"},
{ type:"xmlF", key:"!--", argl:0, argm:0, bak:1, rept:"tx", repv: "<!--@@@-->\n", help:"comment <!-- -->"},
{ type:"ALL", key:"calc", argl:0, argm:20, bak:1, rept:"tr", repv: "$$ev{$$eq{$d$ej{|$${all}}}\n", help:"JavaScriptで計算します"},
{ type:"ALL", key:"snipet-meta", argl:1, argm:20, bak:1, rept:"fn", repv: func_exeMeta, help: "<meta> [arg*]:指定したメタ文字を実行"},
{ type:"ALL", key:"snipet-meta-test", argl:1, argm:20, bak:1, rept:"fn", repv: func_exeMetaTest, help: "<meta> [arg*]:メタ文字を残して指定したメタ文字を実行"},
{ type:"ALL", key:"help", argl:0, argm:1, bak:0, rept:"fn", repv: func_funcHelp, help: "<cmd>:コマンドごとのヘルプを表示 <必須引数> [省略引数] 0以上* 1以上+ 2つ{2} 2つから5つまで{2,5}"}, { type:"ALL", key:"cmd-help", argl:0, argm:1, bak:0, rept:"fn", repv: func_funcHelp, help: "<cmd>:コマンドごとのヘルプを表示 <必須引数> [省略引数] 0以上* 1以上+ 2つ{2} 2つから5つまで{2,5}"},
{ type:"ALL", key:"cmd-type", argl:0, argm:1, bak:0, rept:"fn", repv: func_funcType, help: "<type> <cmd> [cmd-arg*]:指定したtypeでコマンドを実行します。"},
{ type:"ALL", key:"snipet", argl:0, argm:0, bak:0, rept:"tx", repv: "snipet.js へようこそ!\n ヘルプを表示するには :snipet-help\n", help: ""},
{ type:"ALL", key:"snipet-help", argl:0, argm:0, bak:0, rept:"fn", repv: func_viewHelp, help: "snipet関連コマンドのヘルプを表示"},
{ type:"ALL", key:"snipet-find", argl:0, argm:2, bak:0, rept:"fn", repv: func_find, help: "<cmd-part-regex> :cmd(JScript正規表現)に部分一致した有効なコマンド一覧を表示 例:aを含む'a' aで始まる'^a' aで終わる'a$'"},
{ type:"ALL", key:"snipet-lookup", argl:0, argm:2, bak:0, rept:"fn", repv: func_lookUp, help: "[type]:有効なコマンド一覧を表示 typeが省略された場合は現在の文書でのtype-list"},
{ type:"ALL", key:"snipet-type", argl:0, argm:0, bak:0, rept:"fn", repv: func_viewType, help: "現在のファイルで有効なtype一覧を表示"},
{ type:"ALL", key:"snipet-edit", argl:0, argm:0, bak:0, rept:"fn", repv: func_snipetEdit, help: "snipet.mac.jpを開く"},
{ type:"ALL", key:"snipet-version", argl:0, argm:0, bak:0, rept:"fn", repv: func_version, help: "snipet.jsのバージョンを表示"},
{ type:"ALL", key:"snipet-debug-rept-err", argl:0, argm:0, bak:1, rept:"xx", repv: "", help: "rept定義エラーテスト"},
{ type:"snipet", key:"snipet-add", argl:8, argm:8, bak:0, rept:"tr", repv: '\t{ type:"$${1}", $$lp16{ key:"$${2}",} argl:$${3}, argm:$$lp4{ $${4}, }bak:$${5}, rept:"$${6}", repv: $${7}, help:"$${8}"},\n', help:"snipet定義行追加" }
];
snipetjs.snipList = snipetjs.snipBuiltInList;
function func_rep_default_tr(snip, cmdparams)
{
return imp_func_expand_meta(cmdparams, snip.argm, snip.repv, 1);
}
function imp_func_expand_meta(cmdparams, argm, repss, cur)
{
var metap = {cmdparams:cmdparams, argm:argm, cur:cur, repssorg:repss, incvar:1};
debug.trace("func in imp_func_expand_meta()");
debug.traceObject(metap, "metap");
return imp_sub_func_expand_meta(metap, repss, 0, false);
}
function imp_func_unescape(str)
{
var retstr = str;
if(-1 != str.indexOf("$")){
retstr = (str.replace(/\$</g, "{")
.replace(/\$>/g, "}")
.replace(/\$t/g, "\t")
.replace(/\$s/g, " ")
.replace(/\$h/g, "/")
.replace(/\$n/g, "\n")
.replace(/\$d/g, "$") );
debug.trace("unescape() " + str + " => " + retstr);
}
return retstr;
}
function imp_sub_func_expand_meta(metap, repss, repssorg_pos, esc)
{
debug.trace("func in imp_sub_func_expand_meta()");
debug.indentTrace();
debug.trace("repss:" + repss);
debug.trace("repssorg_pos:" + repssorg_pos);
debug.traceFlash();
var snipRet = new RetValues();
var loopFlag = true;
var fi = 0;
var re;
var retArray = [];
var p;
var mtret;
var pushstr;
var i;
snipRet.status = true;
var cs_undefined = "undefined";
while(loopFlag){
if( -1 < (fi = repss.indexOf("$$")) ){
debug.trace("debug:push $$ left = " + repss.substring(0, fi));
pushstr = repss.substring(0, fi);
if(esc){
pushstr = imp_func_unescape(pushstr);
}
retArray.push(pushstr);
pushstr = null;
p = repss.substring(fi);
if(mtret = p.match(/^\$\$\{([0-9]+)\}/)){
debug.trace("debug:$${n} repss = " + p.substring(mtret[0].length));
repss = p.substring(mtret[0].length);
repssorg_pos += mtret[0].length + fi;
p = null;
i = parseInt(mtret[1]);
if(metap.argm < i){
}
if(typeof metap.cmdparams.cmdvars[i] != cs_undefined){
debug.trace("debug:push 1 " + mtret[0] + " => " + metap.cmdparams.cmdvars[i]);
retArray.push(metap.cmdparams.cmdvars[i]);
}
mtret = null;
}else
if(mtret = p.match(/^\$\$\{(a[\-\+][1-9]+[0-9]{0,8})\}/)){
debug.trace("debug:$${a+-i} repss = " + p.substring(mtret[0].length));
repss = p.substring(mtret[0].length);
repssorg_pos += mtret[0].length + fi;
p = null;
i = parseInt(mtret[1].substring(1));
if(metap.argm < metap.cur + i){
}
if(typeof (metap.cmdparams.cmdvars[metap.cur + i]) != cs_undefined){
debug.trace("debug:push 2 " + mtret[0] + " => " + metap.cmdparams.cmdvars[metap.cur + i]);
retArray.push(metap.cmdparams.cmdvars[metap.cur + i]);
}
mtret = null;
}else
if(mtret = p.match(/^\$\$\{a\}/)){
debug.trace("debug:$${a} repss = " + p.substring(mtret[0].length));
repss = p.substring(mtret[0].length);
repssorg_pos += mtret[0].length + fi;
p = null;
if(typeof (metap.cmdparams.cmdvars[metap.cur]) != cs_undefined){
debug.trace("debug:push 3 "+ mtret[0] + " => " + metap.cmdparams.cmdvars[metap.cur]);
retArray.push(metap.cmdparams.cmdvars[metap.cur]);
}
mtret = null;
}else
if(mtret = p.match(/^\$\$\{all}/)){
debug.trace("debug:$${n} repss = " + p.substring(mtret[0].length));
repss = p.substring(mtret[0].length);
repssorg_pos += mtret[0].length + fi;
p = null;
mtret = null;
for( i = 0; i < metap.cmdparams.cmdvars.length; ++i ){
retArray.push(metap.cmdparams.cmdvars[i]);
}
}else
if(mtret = p.match(/^\$\$\{t\}/)){
debug.trace("debug:$${t} repss = " + p.substring(mtret[0].length));
repss = p.substring(mtret[0].length);
repssorg_pos += mtret[0].length + fi;
p = null;
debug.trace("debug:push 4 "+ mtret[0] + " => " + metap.cmdparams.tabs);
mtret = null;
retArray.push(metap.cmdparams.tabs);
}else
if(mtret = p.match(/^\$\$\{i\}/)){
debug.trace("debug:$${inc} repss = " + p.substring(mtret[0].length));
repss = p.substring(mtret[0].length);
repssorg_pos += mtret[0].length + fi;
p = null;
debug.trace("debug:push 4 "+ mtret[0] + " => " + metap.incvar);
mtret = null;
retArray.push(metap.incvar);
metap.incvar += metap.incvar;
}else
if(mtret = p.match(/^\$\$[a-z0-9A-Z_]+\x7b/)){ var pafter = p.substring(mtret[0].length);
var newRepssPos = -1;
var nest = 1;
var maxnest = nest;
var nestPos = [];
var pc;
nestPos.push(-1);
for(var nfi = 0;nfi < pafter.length; ++nfi){
pc = pafter.charCodeAt(nfi);
if(pc === 0x007b){ ++nest;
nestPos.push(nfi);
if(maxnest < nest){
maxnest = nest;
}
}else if(pc === 0x007d){ --nest;
nestPos.pop();
if(0 === nest){
newRepssPos = nfi;
break;
}else if(nest < 0){
snipRet.status = false;
snipRet.errorCode = 100;
snipRet.errorMessge = ("メタ文字列:異常な \x7d が見つかりました index: "
(repssorg_pos + fi + mtret[0].length + nfi) + " 関数"+
mtret[0].substring(0, mtret[0].length - 2) + " in [" + repssorg + "]");
break; }
}
}
if(0 != nest){
snipRet.status = false;
snipRet.errorCode = 100;
snipRet.errorMessge = ("メタ文字列: \x7b に対応する \x7d が見つかりませんでした index: " +
(repssorg_pos + fi + mtret[0].length + nestPos.pop()) + " 関数"+
mtret[0].substring(0, mtret[0].length - 2) + " in [" + metap.repssorg + "]");
}
nestPos = null;
if(false === snipRet.status){ break;
}
var funcParam = "";
if(2 <= maxnest){
var nestOrgPos = repssorg_pos + fi + mtret[0].length;
nestSnipRet = imp_sub_func_expand_meta(metap, pafter.substring(0,newRepssPos), nestOrgPos, true);
if(false === nestSnipRet.status){ CopyErrorRetValues(snipRet, nestSnipRet);
nestSnipRet = null;
break;
}
funcParam = nestSnipRet.retStr;
nestSnipRet = null;
}else{
funcParam = pafter.substring(0,newRepssPos);
debug.trace("funcParam :" + funcParam + "");
if(-1 != funcParam.indexOf("$")){
funcParam = imp_func_unescape(funcParam);
debug.trace("funcParam unescape :" + funcParam);
}
}
p = null;
var meta_rep = imp_func_meta_rep(mtret[0].substring(2,mtret[0].length - 1), funcParam,
metap, repssorg_pos)
debug.trace("debug:push 5 "+ mtret[0].substring(2,mtret[0].length - 1) + " => " + meta_rep);
retArray.push(meta_rep);
meta_rep = null;
debug.trace("debug:func repss = " + pafter.substring(newRepssPos + 1));
repss = pafter.substring(newRepssPos + 1);
repssorg_pos += mtret[0].length + newRepssPos + fi;
pafter = null;
mtret = null;
}else{
debug.trace("debug:push 6 repss = " + repss);
pushstr = repss;
if(esc){
pushstr = imp_func_unescape(pushstr);
}
retArray.push(pushstr);
pushstr = null;
loopFlag = false;
}
}else{
debug.trace("debug:push 7 repss = " + repss);
pushstr = repss;
if(esc){
pushstr = imp_func_unescape(pushstr);
}
retArray.push(pushstr);
pushstr = null;
loopFlag = false;
}
}
if(snipRet.status){
snipRet.retStr = retArray.join("");
}
debug.unindentTrace();
debug.trace("func out imp_sub_func_expand_meta()");
debug.traceObject(snipRet, "snipRet");
return snipRet;
}
snipetjs.metaRepLoopCount = 0;
function imp_func_meta_rep(funcName, param, metap, repss, repssorg_pos){
var s;
var re;
var retStr;
debug.trace("func in imp_func_meta_rep() " + funcName + "{" + param + "}");
if(null != (re = funcName.match(/^lc([0-9]{1,5})$/))){
var ci = parseInt(re[1],10);
retStr = param.substring(0, ci);
}
else if(null != (re = funcName.match(/^rc([0-9]{1,5})$/))){
var ci = parseInt(re[1],10);
if(ci < param.length){
retStr = param.substring(param.length - ci);
}else{
retStr = param;
}
}
else if(null != (re = funcName.match(/^lp[0-9]{1,5}$/))){
var ci = parseInt(re[1],10);
retStr = param.substring(1);
if(retStr.length < ci){
var pad = param.substring(0,1);
if(pad === ""){
pad = " ";
}
while(retStr.length < ci){
retStr += pad;
}
}
}
else if(null != (re = funcName.match(/^rp[0-9]{1,5}$/))){
var ci = parseInt(re[1],10);
retStr = param.substring(1);
if(retStr.length < ci){
var pad = param.substring(0,1);
if(pad === ""){
pad = " ";
}
while(retStr.length < ci){
retStr = pad + retStr;
}
}
}
else if(null != (re = funcName.match(/^ll[0-9]{1,5}$/))){
var ci = parseInt(re[1],10);
retStr = param.substring(1);
if(retStr.length < ci){
var pad = param.substring(0,1);
if(pad === ""){
pad = " ";
}
while(retStr.length < ci){
retStr += pad;
}
}else{
retStr = retStr.substring(0, ci);
}
}
else if(null != (re = funcName.match(/^rl[0-9]{1,5}$/))){
var ci = parseInt(re[1],10);
retStr = param.substring(1);
if(retStr.length < ci){
var pad = param.substring(0,1);
if(pad === ""){
pad = " ";
}
while(retStr.length < ci){
retStr = pad + retStr;
}
}else{
retStr = retStr.substring(retStr.length - ci);
}
}
else if(funcName === "cl"){
retStr = param.toLowerCase();
}
else if(funcName === "cu"){
retStr = param.toUpperCase();
}
else if(funcName === "ct"){
if(1 <= param.length){
param = param.substring(0,1).toUpperCase() + param.substring(1).toLowerCase();
}
retStr = param;
}
else if(funcName === "ccamel"){
if(1 <= param.length){
param = param.replace(/[\-_][a-z]/g, function(r){
return r.charAt(1).toUpperCase();
});
}
retStr = param;
}
else if(funcName === "cunder"){
if(1 <= param.length){
param = param.charAt(0) + param.substring(1).replace(/[A-Z]/g, function(r){
return "_" + r;
});
}
retStr = param;
}
else if(funcName === "chyphen"){
if(1 <= param.length){
param = param.charAt(0) + param.substring(1).replace(/[A-Z]/g, function(r){
return "-" + r;
});
}
retStr = param;
}
else if(funcName === "gsub"){
if(2 <= param.length){
param = param.substring(2).replace(new RegExp(param.charAt(0),g), param.charAt(1));
}
retStr = param;
}
else if(null != (re = funcName.match(/^s([0-9]{1,5})$/))){
var ci = parseInt(re[1],10);
var ms = "";
for(var si = ci; 0 < si; --si){
ms += param;
}
retStr = ms;
}
else if(funcName === "eu"){
var cr = param;
try{
cr = encodeURI(param);
}catch(e){}
retStr = cr;
}
else if(funcName === "euc"){
var cr = param;
try{
cr = encodeURIComponent(param);
}catch(e){}
retStr = cr;
}
else if(funcName === "du"){
var cr = param;
try{
cr = decodeURI(param);
}catch(e){}
retStr = cr;
}
else if(funcName === "duc"){
var cr = param;
try{
cr = decodeURIComponent(param);
}catch(e){}
retStr = cr;
}
else if(funcName === "eq"){
retStr = param;
}
else if(funcName === "ev"){
snipetjs.metaRepLoopCount++;
if(snipetjs.metaRepLoopCount < 1000){
var snipRet = imp_func_expand_meta(metap.cmdparams, metap.argm, param, metap.cur);
snipetjs.metaRepLoopCount--;
if(snipRet.status){
retStr = snipRet.retStr;
snipRet = null;
}else{
retStr = "";
}
}else{
retStr = "再帰の制限を越えました:関数ev";
}
}
else if(funcName === "ej"){
var jsParamPos = param.indexOf("|");
var jsParam = param.substring(0, jsParamPos);
var jsCode = param.substring(jsParamPos + 1);
var evalParam = {};
evalParam.s = jsParam;
snipetjs.metaRepLoopCount++;
if(snipetjs.metaRepLoopCount < 1000){
with(evalParam){
retStr = eval(jsCode);
}
snipetjs.metaRepLoopCount--;
}else{
retStr = "再帰の制限を越えました:関数ej";
}
}else{
retStr = "不明な関数:" + funcName;
}
return retStr;
}
function func_rep_default_tm(snip, cmdparams)
{
var snipRet = new RetValues();
var snipRetMeta;
var vlen = cmdparams.cmdvars.length - snip.repv.repe;
var repsiEnd = snip.repv.reps.length - 1;
snipRetMeta = imp_func_expand_meta(cmdparams, snip.argm, snip.repv.reps[0], 1);
if(snipRetMeta.status){
var retArray = [snipRetMeta.retStr];
snipRetMeta = null;
var repsi = 1;
var i;
for(i = snip.repv.repf + 1; i < vlen; ++i){
snipRetMeta = imp_func_expand_meta(cmdparams, snip.argm, snip.repv.reps[repsi], i);
if(!snipRetMeta.status){
CopyErrorRetValues(snipRet, snipRetMeta);
break;
}
retArray.push(snipRetMeta.retStr);
snipRetMeta = null;
++repsi;
if(!(repsi < repsiEnd)){
repsi = 1;
}
}
snipRetMeta = imp_func_expand_meta(cmdparams, snip.argm, snip.repv.reps[repsiEnd], i);
if(snipRetMeta.status){
retArray.push(snipRetMeta.retStr);
snipRet.retStr = retArray.join("");
snipRet.status = true;
}else{
CopyErrorRetValues(snipRet, snipRetMeta);
}
}else{
snipRet = snipRetMeta;
}
return snipRet;
}
function func_version(snip, cmdparams)
{
var snipRet = new RetValues();
snipRet.retStr = "snipet.js version:" + snipetjs.VER_STR + "\n";
snipRet.status = true;
return snipRet;
}
function func_viewHelp(snip, cmdparams)
{
var snipRet = new RetValues();
var helpc = "\n";
helpc += " " + snipetjs.STR_COPYRIGHT + "\n";
helpc += " " + func_version().retStr;
helpc += " :コマンド 引数1 引数2 .. コロンに続いてコマンド、スペースで区切られた引数を指定します\n";
helpc += " snipet.js では ファイル名に基づいてtypeのリストを定義しています。snipetはtypeごとに指定できます\n";
helpc += " たとえば拡張子「.html」では デフォルトで html css js xmlF ALL の typeが指定されています\n";
helpc += " typeがALLのコマンドはいつでも使用可能です。\n";
helpc += " Fで終わるtypeのコマンドは いくつかのタイプで共通のフォーマット系コマンドです\n";
helpc += " ヘルプで用いる表記 cmd=「snipetコマンド名] arg=「cmdの引数」 type=「タイプ」";
helpc += " <必須引数> [省略引数] *=0以上 +=1以上 {2}=2つ {2,5}=2つから5つまで"
helpc += " :snipet-version snipet.js の version を表示します\n";
helpc += " :snipet-type 現在のファイルで有効なsnipet typeの一覧を表示します\n"
helpc += " :snipet-lookup 現在のファイルで有効なすべてのsnipetの一覧を表示します\n";
helpc += " :snipet-lookup <type> 指定されたtypeに属するsnipetの一覧を表示します\n";
helpc += " :snipet-find <cmd-part> 現在のファイルで有効なsnipetの中からcmdに一致する すべてのsnipetの一覧を表示します\n";
helpc += " :snipet-edit snipetファイルをサクラで開きます。\n";
helpc += " :help [cmd] cmdのヘルプを表示します\n"
helpc += " :cmd-help [cmd] helpの別名です。helpコマンドがオーバーロードされている場合に代わりに使えます\n"
helpc += " :cmd-type <type> <cmd> [arg*] typeで利用可能なcmdを実行します\n"
helpc += " 通常のコマンドは、実行後「元に戻す(Ctrl+Z)」で戻せます\n"
snipRet.retStr += helpc;
snipRet.status = true;
return snipRet;
}
function func_exeMeta(snip, cmdparams)
{
var newCmdparams = {};
var shiftVars = [];
shiftVars[0] = cmdparams.cmdvars[0];
for(var i = 2; i < cmdparams.cmdvars.length; i++){
shiftVars[i - 1] = cmdparams.cmdvars[i];
}
newCmdparams.cmdvars = shiftVars;
newCmdparams.tabs = cmdparams.tabs;
newCmdparams.cmdline = cmdparams.cmdline;
return imp_func_expand_meta(newCmdparams, snip.argm - 1, cmdparams.cmdvars[1], 1);
}
function func_exeMetaTest(snip, cmdparams)
{
biOutputString(cmdparams.tabs + cmdparams.cmdline + "\n");
return func_exeMeta(snip, cmdparams);
}
function func_lookUp(snip, cmdparams, rtype)
{
var snipRet = new RetValues();
var key = null;
if( 1 < cmdparams.cmdvars.length ){
rtype = cmdparams.cmdvars[1].split("|");
}
snipRet.retStr += "\nsnipet-lookup:\n";
if(null != FindSnips(rtype, key, 0, -1,
(function(s){snipRet.retStr += s.type + "/" + s.key + "\t" + s.help + "\n";}), true)){
snipRet.status = true;
}else{
snipRet.errorCode = 1;
snipRet.errorMessge = "snipet-lookup: コマンドが見つかりませんでした" ;
}
return snipRet;
}
function func_find(snip, cmdparams, rtype)
{
var snipRet = new RetValues();
var key = null;
if( 1 < cmdparams.cmdvars.length ){
key = new RegExp(cmdparams.cmdvars[1]);
}
snipRet.retStr += "\nsnipet-find: " + (!rtype?"":rtype.join(",")) + "\n";
if(null != FindSnips(rtype, key, 0, -1,
(function(s){snipRet.retStr += s.type + "/" + s.key + "\t" + s.help + "\n";}), true)){
snipRet.status = true;
}else{
snipRet.errorCode = 1;
snipRet.errorMessge = "snipet-find: コマンドが見つかりませんでした" ;
}
return snipRet;
}
function func_funcHelp(snip, cmdparams, rtype)
{
var snipRet = new RetValues();
var key;
if(1 < cmdparams.cmdvars.length){
key = cmdparams.cmdvars[1];
}else{
key = snip.key;
}
if(null != FindSnips(rtype, key, 0, -1,
(function(s){snipRet.retStr += s.type + "/" + s.key + "\t" + s.help + "\n";return true;}), true)){
snipRet.status = true;
}else{
snipRet.errorCode = 1;
snipRet.errorMessge = "help: コマンド '"+ key + "' が現在のtypeの中から見つかりませんでした";
}
return snipRet;
}
function func_funcType(snip, cmdparams, rtype)
{
var snipRet = new RetValues();
if(1 < cmdparams.cmdvars.length){
if(2 < cmdparams.cmdvars.length){
var newRtype = [cmdparams.cmdvars[1], 'ALL'];
var key;
var newCmdparams = {};
var shiftVars = [];
shiftVars[0] = cmdparams.cmdvars[0];
for(var i = 3; i < cmdparams.cmdvars.length; i++){
shiftVars[i - 2] = cmdparams.cmdvars[i];
}
newCmdparams.cmdvars = shiftVars;
newCmdparams.tabs = cmdparams.tabs;
newCmdparams.cmdline = (cmdparams.cmdline.charAt(0)
+ cmdparams.cmdline.substring(cmdparams.cmdvars[1].length + cmdparams.cmdvars[2].length + snip.key + 4));
if(cmdparams.cmdvars[1] == 'NONE'){
newRtype = null;
}else{
if(-1 < cmdparams.cmdvars[1].indexOf("|")){
newRtype = cmdparams.cmdvars[1].split("|").push('ALL');
}
}
key = cmdparams.cmdvars[2];
debug.trace("fncType:" + newRtype);
snipRet = exeCmd(newRtype, key, newCmdparams);
if(snipRet == null){
snipRet.errorCode = 1;
snipRet.errorMessge = "cmd-type: コマンド '"+ key + "' が見つかりませんでした";
}
}else{
snipRet.errorCode = 2;
snipRet.errorMessge = "cmd-type: <type-list> <cmd> [arg*]:コマンドを指定してください";
}
}else{
snipRet.errorCode = 2;
snipRet.errorMessge = "cmd-type: <type-list>] <cmd> [arg*]:typeを指定してください";
}
return snipRet;
}
function func_viewType(snip, cmdparams, rtype)
{
var snipRet = new RetValues();
var helpc = "";
if(null == rtype){
helpc = "すべてのtype が有効です。";
}else{
helpc = "このファイルで有効なtypeの一覧: " + rtype.join(", ") + "\n";
}
snipRet.retStr = helpc;
snipRet.status = true;
return snipRet;
}
function func_snipetEdit(snip, cmdparams, rtype)
{
Editor.FileOpen( Editor.ExpandParameter("$M") );
var snipRet = new RetValues();
snipRet.retStr = "@@@\n";
snipRet.status = true;
return snipRet;
}
snipetjs.Output = false;
snipetjs.OutpuBuffer = "";
function biOutputString(str, isBuffer,isReplace)
{
if(typeof isBuffer === "undefined"){isBuffer = true}
if(typeof isReplace === "undefined"){isReplace = true}
if(isReplace){
var lineCode = Editor["GetLineCode"]();
if(0 == lineCode){
str = str.replace(/\n/g, "\r\n");
}else if(1 == lineCode){
str = str.replace(/\n/g, "\r");
}
}
var outputStr = "";
if(isBuffer){
if(snipetjs.OutpuBuffer.length + str.length < 5120){
snipetjs.OutpuBuffer += str;
return false;
}else{
outputStr = snipetjs.OutpuBuffer + str;
snipetjs.OutpuBuffer = "";
}
}else{
outputStr = snipetjs.OutpuBuffer + str
}
if(false === snipetjs.Output){
Editor["MoveHistSet"]();
Editor["SelectLine"](0);
snipetjs.Output = true;
}
Editor["InsText"](outputStr);
return true;
}
function RetValues()
{
this.retStr = "";
this.status = false;
this.errorCode = 0;
this.errorMessge = "";
return this;
}
function CopyErrorRetValues(ret, org)
{
if(false === org.status){
ret.status = false;
ret.errorCode = org.errorCode;
ret.errorMessge = org.errorMessge;
}
return ret;
}
function exeCmd(rtype, key, cmdparams)
{
var snipRet = new RetValues();
var rets = null;
var exeSuccess = false;
var snipArgMiss = null;
debug.indentTrace();
if( FindSnips(rtype, key, 0, -1, function(aSnip){
if(aSnip.argl < cmdparams.cmdvars.length && cmdparams.cmdvars.length <= aSnip.argm + 1){
rets = exeSnip(aSnip, cmdparams, rtype);
if(rets.status){
snipRet.retStr += rets.retStr;
snipRet.status = true;
rets.retStr = null;
exeSuccess = true;
return false;
}
}else{
debug.trace("snip:key ", aSnip.key);
debug.trace("snip:argl ", aSnip.argl);
debug.trace("snip:argm ", aSnip.argm);
debug.trace("cmdvars.len ", cmdparams.cmdvars.length);
snipArgMiss = aSnip;
}
return true;
}, true) ){
if(false == exeSuccess){
if(null == rets && snipArgMiss){
snipRet.status = false;
snipRet.errorCode = 2;
snipRet.errorMessge = "引数が一致しません <cmd>=" + snipArgMiss.key;
}else{
CopyErrorRetValues(snipRet, rets);
}
}
}else{
snipRet = null;
}
debug.unindentTrace();
return snipRet;
}
function exeSnip(snip, cmdparams, rtype)
{
debug.trace("exeSnip()");
debug.indentTrace();
debug.traceObject(snip, "snip");
debug.traceObject(cmdparams, "cmdparams");
debug.traceObject(rtype, "rtype");
var exeRet = new RetValues();
var snipRet;
if(snip.rept === "tx"){
exeRet.retStr = snip.repv;
exeRet.status = true;
}else{
if(snip.rept === "tr"){
snipRet = func_rep_default_tr(snip, cmdparams);
}else if(snip.rept === "tm"){
snipRet = func_rep_default_tm(snip, cmdparams);
}else if(snip.rept === "fn"){
snipRet = snip.repv(snip, cmdparams, rtype);
}else{
snipRet = new RetValues()
snipRet.errorCode = 1;
snipRet.errorMessge = "スニペットの定義が不正です。Snip.rept:'" + snip.rept +"'は未定義の種類です。";
}
if(snipRet.status){
exeRet.retStr = snipRet.retStr;
exeRet.status = true;
}else{
CopyErrorRetValues(exeRet, snipRet);
}
}
debug.unindentTrace();
return exeRet;
}
function FindSnips(rtype, key, topIndex, lastIndex, func_lambda, globalFlag)
{
var retValue = null;
if(lastIndex < 0){lastIndex = snipetjs.snipList.length}
if(!globalFlag){globalFlag = false}
if(rtype != null){
debug.trace( "func in FindSnips() typte != null" );
debug.indentTrace();
debug.traceObject( rtype, "rtype" );
var keySlipList = FindSnips(null, key, topIndex, lastIndex, null, true);
debug.traceObject( keySlipList, "keySlipList" );
debug.unindentTrace();
if(null === keySlipList){
return null;
}
for(var k = 0; k < rtype.length; ++k){
for(var i = 0; i < keySlipList.length; ++i){
var aSlip = keySlipList[i];
if( rtype[k] === aSlip.type ){
if(func_lambda){
if(false === func_lambda(aSlip)){
return true;
}
}
if(false === globalFlag){
return aSlip;
}
if(!func_lambda){
if(null == retValue){
retValue = [];
}
retValue.push(aSlip);
}else{
retValue = true;
}
}
}
}
}else{
for(var i = topIndex; i < lastIndex; ++i){
if(key === null || ((key instanceof RegExp) && key.test(snipetjs.snipList[i].key))
|| snipetjs.snipList[i].key === key ){
var aSlip = snipetjs.snipList[i];
if(func_lambda){
if(false == func_lambda(aSlip)){
return true;
}
}
if(false === globalFlag){
return aSlip;
}
if(!func_lambda){
if(null == retValue){
retValue = [];
}
retValue.push(aSlip);
}else{
retValue = true;
}
}
}
}
return retValue;
}
function GetCommandPosition(line)
{
var marki;
var ci;
var resetFlag = true;
var spLine = line;
do{
resetFlag = false;
for(marki = 0; marki < snipetjs.CommandMark.length; ++marki){
ci = spLine.lastIndexOf(snipetjs.CommandMark[marki]);
if(-1 != ci){
var cmdstrPrev = spLine.substring(0,ci);
var ignore = false;
for(var igi =0; igi < snipetjs.CommandPrevIgnoreRe.length; ++igi){
if(-1 != cmdstrPrev.search(snipetjs.CommandPrevIgnoreRe[igi])){
ignore = true;
break;
}
}
if(ignore){
spLine = spLine.substring(0,ci - 1);
if(0 < spLine.length){
resetFlag = true;
break;
}
}
}
}
}while(resetFlag);
return ci;
}
function GetRtype(fileName){
var rtype = snipetjs.DefaultTypes;
if(0 < fileName.length){
var fileNameWithl = "|" + fileName + "|";
for(var i = 0; i < snipetjs.extSupList.length; ++i){
var extSup = snipetjs.extSupList[i];
if( typeof extSup.nameFilter !== "string" && fileName.test(extSup.nameFilter)
|| -1 != fileNameWithl.indexOf(extSup.nameFilter) ){
rtype = extSup.types.split("|");
rtype.push("ALL");
break;
}
}
}else{
rtype = snipetjs.UnSaveDocTypes;
}
return rtype;
}
function InsConvertSnipett()
{
var curline = Editor["GetLineStr"](0);
var cmi = -1;
cmi = GetCommandPosition(curline);
if(0 <= cmi){
var left = curline.substring(0,cmi);
var fileName = Editor["GetFilename"](0).toLowerCase();
var cmdlineWithMark = curline.substring(cmi).replace(/[\r\n]+/, "");
var cmdline = curline.substring(cmi+1);
var cmdvars = cmdline.replace(/[\r\n]+/, "").split(" ");
var rtype = GetRtype(fileName);
biOutputString(left, true, true);
var tabStr = curline.match(/^[ \t]*/)[0];
var keyName = cmdvars[0];
cmdvars[0] = ""; var cmdparams = {cmdvars:cmdvars, tabs:tabStr, cmdline:cmdlineWithMark };
var exeSuccess = false;
var rets;
debug.trace("snipet.js ---- start ------key:" + keyName);
rets = exeCmd(rtype, keyName, cmdparams);
debug.traceObject(rets, "rets");
if(rets && rets.status){
var retexe2 = rets.retStr.replace(/\r\n/g, "\n");
var curIndex = retexe2.lastIndexOf("@@@");
var prevChar = "";
var upCount = -1;
var backCount = 0;
var retexeStr;
if(0 <= curIndex){
if(1 <= curIndex){
prevChar = retexe2.charAt(curIndex - 1);
}
retexe2 = retexe2.substring(curIndex + 3);
curIndex = 0;
for(var npos = retexe2.length - 1; 0 <= npos; --npos){
if(retexe2.charCodeAt(npos) === 0x0a){
upCount++;
backCount = 1;
}else{
backCount++;
}
}
if(0 < backCount && prevChar == "\n"){
backCount = 0;
upCount++;
}
retexeStr = rets.retStr.replace(/@@@/g, "");
}else{
retexeStr = rets.retStr;
}
biOutputString(retexeStr, false, true);
Editor.ReDraw(0);
var c = 0;
if(0 <= upCount){
Editor["GoLineTop"](9);
}
for(var c = 0; c < upCount; c++){
Editor["Up"]();
}
for(var c = 0; c < backCount; c++){
Editor["Left"]();
}
}else{
var errPut = false;
if(rets != null){
if(rets.errorCode != 0){
errPut =true;
biOutputString("error "+rets.errorCode+ ":" + rets.errorMessge + "\n", false, true);
}else{
debug.traceObject(rets, "rets");
biOutputString("unknown error from " + cmdlineWithMark.replace("\r\n", "\n"), false, true);
}
}
}
return true;
}
return false;
}
function msgBox(str)
{
var wss = new my_ActiveXObject("WScript.Shell");
wss["PopUp"](("" + str), void(0), "sakura", 0x30 );
wss = null;
}
var debug = {};
(function()
{
var m_traceStr = "";
var m_traceIndent = 0;
var m_traceIndentStr = "";
var m_msgBoxCount = 0;
var m_msgBoxNormalCount = 10;
var m_msgBoxVisible = true;
var m_bufferSize = 4096;
var m_enableTrace = true;
var m_traceObjectLoop = 10;
var m_traceObjectLoopCurrent = 0;
function traceObject(obj, objName)
{
if(!m_enableTrace){return}
if(m_traceObjectLoop < m_traceObjectLoopCurrent){return}
var maxDepth = 100;
function traceObject_sub(item, currentDepth, objName)
{
if(currentDepth < maxDepth){
indentTrace();
for( var i in item ){
if( typeof(item[i]) === "object" ){
var klass = "";
if( item[i] instanceof Array ){
klass = "(Array)";
}
if( item[i] instanceof RegExp ){
klass = "(RegExp)";
}
debug.trace(objName + "[" + i + "]:"+ typeof(item[i]) +" = \"" + item[i] + "\":" + klass + "");
traceObject_sub(item[i], currentDepth+1, objName+"["+i+"]");
}else{
if( typeof(item[i]) == "function" ){
debug.trace(objName + "[" + i + "]:function = \"###\"");
}else{
debug.trace(objName + "[" + i + "]:"+ typeof(item[i]) +" = \"" + item[i] + "\"");
}
}
}
unindentTrace();
}
}
if(!objName){ objName = "(AC)"; }
if(!(typeof(obj) == "object")){
if( typeof(obj) == "function" ){
debug.trace("TraceObjectName : " + objName + ":function = ###");
}else{
debug.trace("TraceObjectName : " + objName + ":" + typeof(obj) + " = \"" + obj + "\"");
}
}else{
debug.trace("TraceObjectName : " + objName);
traceObject_sub(obj, 1, objName);
}
}
function trace()
{
if(!m_enableTrace) return;
var str;
var arr = [];
arr.push.apply(arr, arguments);
if( 0 < m_traceIndent ){
str = m_traceIndentStr + arr.join();
}else{
str = arr.join();
}
arr = null;
if( 0 < m_traceStr.length ){
m_traceStr += str + "\r\n";
}else{
m_traceStr = str + "\r\n";
}
if( debug.bufferSize <= m_traceStr.length ){
debug.MyTraceOut(m_traceStr);
m_traceStr = "";
}
}
function traceNoFormat(str)
{
if(!m_enableTrace) return;
if( 0 < m_traceStr.length ){
m_traceStr += str;
}else{
m_traceStr = str;
}
if( debug.bufferSize <= m_traceStr.length ){
debug.MyTraceOut(m_traceStr);
m_traceStr = "";
}
}
function traceFlash()
{
if( 0 < m_traceStr.length ){
debug.MyTraceOut(m_traceStr);
m_traceStr = "";
}
}
function MyTraceOut(str)
{
var len = str.length;
var cur = 0;
do{
var outstr = str.substr(cur,30000);
Editor.TraceOut(outstr, 0x02);
cur += outstr.length;
}while(cur < len);
}
function traceMsgBox(str)
{
if( m_msgBoxVisible ){
m_msgBoxCount++;
if(m_msgBoxCount < m_msgBoxNormalCount){
return msgBox();
}else{
var wss = new my_ActiveXObject("WScript.Shell");
var ret = wss["PopUp"](str + "\n[はい]続行 [いいえ]ダイアログなしで続行 [キャンセル]実行中止",
void(0), "sakura debug", 0x33); wss = null;
if( ret == 6 ){
}else if( ret == 7 ){
m_msgBoxVisible = false;
}else if( ret == 2 ){
throw new debug.UserDebugException();
}
}
}
}
function UserDebugException()
{
}
UserDebugException.prototype.toString = function() {
return "デバッグ ダイアログにより中止されました。"
}
function indentTrace()
{
return setIndentTrace(m_traceIndent + 1);
}
function unindentTrace()
{
return setIndentTrace(m_traceIndent - 1);
}
function setIndentTrace(indent)
{
m_traceIndent = indent;
var s = "";
for( var t = 0; t < m_traceIndent; t++ ){
s += " ";
}
m_traceIndentStr = s;
return indent;
}
function setTrace(mode)
{
m_enableTrace = mode;
return m_enableTrace;
}
debug.bufferSize = m_bufferSize;
debug.trace = trace;
debug.traceFlash = traceFlash;
debug.traceObject = traceObject;
debug.indentTrace = indentTrace;
debug.unindentTrace = unindentTrace;
debug.setIndentTrace = setIndentTrace;
debug.traceMsgBox = traceMsgBox;
debug.setTrace = setTrace;
debug.MyTraceOut = MyTraceOut;
debug.UserDebugException = UserDebugException;
})();
my_ActiveXObject = eval("ActiveXObject");
main();
|