-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsh-works.js
2341 lines (2016 loc) · 70.3 KB
/
wsh-works.js
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
/* =========================================================================
* WSH-Works is WSH(Windows Script Host) javascript wrapper library
* (c) 2009-2014 Jeong-Ho, Eun
* =========================================================================
*
* Copyright (c) 2009-2014 Jeong-Ho, Eun
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ========================================================================= */
function Excel() {
this.excel = new ActiveXObject("Excel.Application");
this.books = function (filename) {
var fs = new FileSystem();
var isExist = fs.exists(filename);
if (isExist) {
this.excel.Workbooks.Open(filename, false, false);
return new Book(this.excel.ActiveWorkbook, false, filename);
} else {
var workbook = this.excel.Workbooks.Add();
return new Book(workbook, true, filename);
}
}
this.visible = function(value) {
//Setter
if (arguments.length > 0)
{
this.excel.Visible = arguments[0];
} else {
//Getter
return this.excel.Visible;
}
}
this.quit = function() {
this.excel.Quit();
}
function Book(workBook, isNew, filename) {
this.book = workBook;
this.isNew = isNew;
this.filename = filename;
this.book.Saved = true; // 저장 가능토록 설정
this.sheets = function(index) {
if (index == null) { // index가 없다면, 전체 Collections을 반환
var cnt = this.book.Worksheets.Count;
var colls = new Array();
for (var i = 0; i < cnt; i++) {
colls[i] = new Sheet(this.book.Worksheets(i + 1));
}
return colls;
} else {
if (index <= 0)
throw new Error('Index is bigger than 0');
return new Sheet(this.book.Worksheets(index));
}
}
this.sheetsCount = function() {
return this.book.Worksheets.Count;
}
this.close = function() {
this.book.Close(true); // 기본적으로 변경되면 덮어쓰게 함
}
this.save = function() {
if (this.isNew) {
println(this.filename);
this.book.SaveAs(this.filename);
} else {
this.book.Save();
}
}
this.saveAs = function(filename) {
this.book.SaveAs(filename);
}
this.name = function() {
//Setter
if (arguments.length > 0)
{
this.book.Name = arguments[0];
} else {
//Getter
return this.book.Name;
}
}
this.toString = function() {
return "Book: "+ this.book.Name;
}
}
function Sheet(workSheet) {
this.sheet = workSheet;
this.name = function() {
//Setter
if (arguments.length > 0)
{
this.sheet.Name = arguments[0];
} else {
//Getter
return this.sheet.Name;
}
}
this.cells = function(xy, y) {
if (typeof(xy) == "number") { // xy가 일반 숫자인 x와 두번째 y값이 들어오면 x,y 좌표로 반환한다.
var x = xy;
return new Cell(this.sheet.Cells(x, y));
}
var re = new RegExp("([a-zA-Z~]+)([0-9~]+)","ig");
var arr = re.exec(xy);
var column = RegExp.$1; // Column
var row = RegExp.$2; // Row
column = this.itos(column);
row = parseInt(row);
return new Cell(this.sheet.Cells(row, column), xy);
}
this.itos = function(value) {
var ASCII = {"A":65, "B":66, "C":67, "D":68, "E":69, "F":70, "G":71,
"H":72, "I":73, "J":74, "K":75, "L":76, "M":77, "N":78,
"O":79, "P":80, "Q":81, "R":82, "S":83, "T":84, "U":85,
"V":86, "W":87, "X":88, "Y":89, "Z":90};
var str = value.toUpperCase();
var x = 0;
for (var i = 0; i < str.length; i++)
{
var j = (ASCII[ str.charAt(str.length - 1 - i) ] - 64);
x += j + i * 26;
}
return x;
}
this.toString = function() {
return "Sheet: " + this.sheet.Name;
}
}
function Cell(cell, xy) {
this.cell = cell;
this.xy = xy;
this.value = function() {
//Setter
if (arguments.length > 0)
{
this.cell.value = arguments[0];
} else {
//Getter
return this.cell.value;
}
}
this.getValue = function() {
return this.cell.value;
}
this.setValue = function(value) {
return this.cell.value = value;
}
this.color = function() { // 5 : blue
//Setter
if (arguments.length > 0)
{
this.cell.Interior.colorIndex = arguments[0];
} else {
//Getter
return this.cell.Interior.colorIndex;
}
}
this.font = function() {
return new Font(this.cell);
}
this.toString = function() {
return "Cell: " + this.xy;
}
}
function Font(cell) {
this.cell = cell;
this.bold = function() {
//Setter
if (arguments.length > 0)
{
this.cell.Font.Bold = arguments[0];
} else {
//Getter
return this.cell.Font.Bold;
}
}
this.name = function() {
//Setter
if (arguments.length > 0)
{
this.cell.Font.Name = arguments[0];
} else {
//Getter
return this.cell.Font.Name;
}
}
this.size = function() {
//Setter
if (arguments.length > 0)
{
this.cell.Font.Size = arguments[0];
} else {
//Getter
return this.cell.Font.Size;
}
}
}
}
function InternetExplorer() {
this.ie = new ActiveXObject("InternetExplorer.Application");
this.nevigate = function(url) {
this.ie.Navigate(url);
}
this.quit = function() {
this.ie.Quit();
}
this.visible = function(value) {
if (value == null)
return this.ie.Visible;
else
this.ie.Visible = value;
}
this.addressBar = function(value) {
if (value == null)
return this.ie.addressBar;
else
this.ie.addressBar = value;
}
this.menuBar = function(value) {
if (value == null)
return this.ie.MenuBar;
else
this.ie.MenuBar = value;
}
this.statusBar = function(value) {
if (value == null)
return this.ie.StatusBar;
else
this.ie.StatusBar = value;
}
this.toolBar = function(value) {
if (value == null)
return this.ie.ToolBar;
else
this.ie.ToolBar = value;
}
}
// 샘플
// var reg = new Registry();
// var sub_key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\빵집_is1";
// var value_name = "UninstallString";
// var val = reg.GetExpandedStringValue(reg.HKLM, sub_key, value_name);
// WScript.Echo(val);
function Registry(computer) {
if(!computer) {
computer = ".";
}
var locator = new ActiveXObject("WbemScripting.SWbemLocator");
var server = locator.ConnectServer(computer, "root\\default");
this.stdregprov = server.Get("StdRegProv");
this.HKCR = 0x80000000; // HKEY_CLASSES_ROOT
this.HKCU = 0x80000001; // HKEY_CURRENT_USER
this.HKLM = 0x80000002; // HKEY_LOCAL_MACHINE
this.HKUS = 0x80000003; // HKEY_USERS
this.HKCC = 0x80000005; // HKEY_CURRENT_CONFIG
this.REG_SZ = 1;
this.REG_EXPAND_SZ = 2;
this.REG_BINARY = 3;
this.REG_DWORD = 4;
this.REG_MULTI_SZ = 7;
this.do_method = function(method_name, hkey, key, value_name) {
var in_param = this.stdregprov.Methods_.Item(method_name).InParameters.SpawnInstance_();
in_param.hDefKey = hkey;
in_param.sSubKeyName = key;
if(value_name != null)
{
in_param.sValueName = value_name;
}
var out = this.stdregprov.ExecMethod_(method_name, in_param);
return out;
},
this.EnumKey = function(hkey, key) {
var out_param = this.do_method("EnumKey", hkey, key);
var names = [];
if(out_param.sNames != null)
{
names = out_param.sNames.toArray();
}
return names;
},
this.EnumValues = function(hkey, key) {
var out_param = this.do_method("EnumValues", hkey, key);
var value_names = [];
if(out_param.sNames != null)
{
value_names = out_param.sNames.toArray();
}
var value_types = [];
if(out_param.Types != null)
{
value_types = out_param.Types.toArray();
}
return {
Names: value_names,
Types: value_types
};
},
this.GetStringValue = function(hkey, key, name) {
// REG_SZ
var out_param = this.do_method("GetStringValue", hkey, key, name);
// 존재하지 않으면 null
return out_param.sValue;
},
this.GetExpandedStringValue = function(hkey, key, name) {
// REG_EXPAND_SZ
var out_param = this.do_method("GetExpandedStringValue", hkey, key, name);
// 존재하지 않으면 null
return out_param.sValue;
},
this.GetDWORDValue = function(hkey, key, name) {
// REG_DWORD
var out_param = this.do_method("GetDWORDValue", hkey, key, name);
// 존재하지 않으면 null
return out_param.uValue;
}
}
/**
* 특정 문자열로 시작하는지 여부를 반환한다.
*/
String.prototype.startsWith = function(str) {
var p = this.indexOf(str);
if (p == 0)
return true;
return false;
}
/**
* 특정 문자열로 끝나는지 여부를 반환한다.
*/
String.prototype.endsWith = function(str) {
var p = this.lastIndexOf(str);
if (p + str.length == this.length)
return true;
return false;
}
/**
* String 객체의 trim을 앞뒤 공백 모두를 제거 할 수 있도록 재정의를 한다.
*/
String.prototype.trim = function() {
return this.replace(/(^\s+)|\s+$/g, "");
}
/**
* 문자열 전체에 대하여 replace All을 수행한다.
*/
String.prototype.replaceAll = function(from, to){
return this.replace(new RegExp(from, "g"), to);
}
function println(str) {
System.println(str);
}
var System = {
desktopPath : function() {
var wsh = new ActiveXObject("WScript.Shell");
return wsh.SpecialFolders.Item("Desktop");
},
homePath : function(){
var WshShell = new ActiveXObject("WScript.Shell");
var WshSysEnv = WshShell.Environment("PROCESS");
var HOMEPATH = WshSysEnv("HOMEPATH");
return HOMEPATH;
},
PROCESS_RUNNING : 0,
exec : function(command) {
var wsh = new ActiveXObject("WScript.Shell");
return new Exec(wsh.Exec(command));
function Exec(wshScriptExec) {
this.wse = wshScriptExec;
this.exitCode = function() {
return this.wse.ExitCode;
}
this.processID = function() {
return this.wse.ProcessID;
}
this.status = function() {
return this.wse.Status;
}
this.stdErr = function() {
return this.wse.StdErr;
}
this.stdErr = function() {
return this.wse.StdErr;
}
this.stdIn = function() {
return this.wse.stdIn;
}
this.stdOut = function() {
return this.wse.stdOut;
}
this.terminate = function() {
this.wse.Terminate();
}
}
},
sleep : function(time) {
WScript.Sleep(time);
},
println : function(str) {
var value = String(str);
WScript.Echo(value);
},
/**
* 프로세스 Kill
* [예제]
* System.killProcess("iexplore.exe");
* param processName 프로세스명
*/
killProcess : function(processName) {
var computer = '.';
var WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + computer + "\\root\\cimv2");
var processList = WMIService.ExecQuery("Select * From Win32_Process Where Name = '"+processName+"'");
//WScript.Echo('Found ' + processList.Count + ' processes.');
var enumr = new Enumerator(processList);
while (!enumr.atEnd()) {
enumr.item().Terminate();
enumr.moveNext();
}
},
/**
* 로컬 IP를 획득한다.
*/
getLocalIP : function() {
var computer = '.';
var WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + computer + "\\root\\cimv2");
var netConfigSet = WMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration");
var enumr = new Enumerator(netConfigSet);
while (!enumr.atEnd()) {
if (enumr.item().IPAddress != null) {
var ipAddresses = enumr.item().IPAddress.toArray();
for (k = 0; k < ipAddresses.length; k++) {
return ipAddresses[k];
}
}
enumr.moveNext();
}
},
sleep : function(millsec) {
WScript.Sleep(millsec);
}
}
function StringBuffer() {
this.buffer = new Array();
this.append = function(str) {
this.buffer[this.buffer.length] = str;
return this;
}
this.toString = function() {
return this.buffer.join("");
}
this.clear = function() {
for (var i in this.buffer) {
delete this.buffer[i];
}
}
this.length = function() {
var len = 0;
for(var i = 0 ; i < this.buffer.length ; i++) {
if (this.buffer[i] != null)
len += this.buffer[i].length;
}
return len;
}
this.charAt = function(index) {
var idx = index;
for(var i = 0 ; i < this.buffer.length ; i++) {
if (this.buffer[i] != null) {
if (idx <= this.buffer[i].length - 1)
return String(this.buffer[i]).charAt(idx);
else
idx -= this.buffer[i].length;
}
}
return null;
}
this.substring = function(start, end) {
var s = this.toString();
if (end != null && end > 0 && end > start)
return s.substring(start, end);
else
return s.substring(start);
}
}
function HashMap() {
this.length = 0;
this.items = new Array();
for (var i = 0; i < arguments.length; i += 2) {
if (typeof(arguments[i + 1]) != 'undefined') {
this.items[arguments[i]] = arguments[i + 1];
this.length++;
}
}
this.remove = function(key) {
var tmp;
if (typeof(this.items[key]) != 'undefined') {
this.length--;
var tmp = this.items[key];
delete this.items[key];
}
return tmp;
}
this.get = function(key) {
return this.items[key];
}
this.put = function(key, value) {
var tmp;
if (typeof(value) != 'undefined') {
if (typeof(this.items[key]) == 'undefined') {
this.length++;
}
else {
tmp = this.items[key];
}
this.items[key] = value;
}
return tmp;
}
this.containsKey = function(key) {
return typeof(this.items[key]) != 'undefined';
}
this.clear = function() {
for (var i in this.items) {
delete this.items[i];
}
this.length = 0;
}
}
function Iterator(values) {
this.enums = new Enumerator(values);
this.enums.moveFirst();
this.hasNext = function() {
return !this.enums.atEnd();
}
this.next = function() {
var value = this.enums.item();
this.enums.moveNext();
return value;
}
}
function Properties() {
this.load = function(filename) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(filename, 1);
while (!file.AtEndOfStream){
var line = file.ReadLine();
if (line != null && line.length > 0)
{
line = line.replace(/#.+$/g, "");
line = line.trim();
var p = line.indexOf("=");
if (p > - 1) {
var key = line.substring(0, p).trim();
var value = line.substring(p + 1, line.length).trim();
this.put(key, value);
}
}
}
}
}
Properties.prototype = new HashMap(); //상속
///////////////////////////////////////////////////////////////////////////////
/**
* 값을 저장하는 리스트 객체이다.
* @author Eun Jeong-Ho, [email protected]
* @since 2004. 6. 4.
*/
function List() {
this.table = new Array();
/**
* 리스트을 초기화한다.
*/
this.clear = function() {
for (var i in this.table) {
delete this.table[i];
}
}
/**
* 요소를 추가한다.
* @param o 추가할 요소
*/
this.add = function(idx, o) {
if (o == null) {
var o = idx;
this.table[this.table.length] = o;
} else {
this.table[idx] = o;
}
}
/**
* 요소를 교체한다.
* @param idx 인덱스
* @param o 추가할 요소
* @return Object 기존에 저장된 요소
*/
this.set = function(idx, o) {
var oldval = this.table[idx];
this.table[idx] = o;
return oldval;
}
/**
* 요소를 포함하고 있는지 여부를 반환한다.
* @param o 테스트할 요소
* @return true, false
*/
this.contains = function(o) {
for (var i = 0; i < this.table.length; i++) {
if (this.table[i] == o)
return true;
}
return false;
}
/**
* 리스트내에 인덱스에 있는 객체를 반환한다.
* @param idx 인덱스
* @return 객체
*/
this.get = function(idx) {
return this.table[idx];
}
/**
* 찾고자하는 요소의 인덱스번호를 반환하다. 없다면 -1을 반환한다.
* @param o 찾고자하는 요소
* @return 인덱스번호 또는 -1
*/
this.indexOf = function(o) {
for (var i = 0; i < this.table.length; i++) {
if (this.table[i] == o)
return i;
}
return -1;
}
/**
* 리스트내에 요소가 있는지 여부를 반환한다.
* @returns true, false
*/
this.isEmpty = function() {
return (this.table.length == 0) ? true : false;
}
/**
* 리스트내에 사이즈를 반환한다.
* @returns 사이즈
*/
this.size = function() {
return this.table.length;
}
/**
* 리스트내의 인덱스에 해당하는 요소를 지운다.
* remove(idx)에 해당하며
* 또는 인덱스내에 같은 객체를 찾아서 지운다.
* remove(object)에 해당한다.
* 이것의 판단 기준은 파라미터 idx가 number 타입일경우는
* 전자로 판단하여 처리하며, 나머지경우에 후자로 처리된다.
* @param idx 인덱스번호 또는 객체
*/
this.remove = function(idx) {
if (typeof(idx) == "number") {
var bit1 = this.table.splice(0, idx);
var bit2 = this.table.splice(idx + 1, this.table.length);
this.table = bit1.concat(bit2);
} else {
var o = idx;
for (var i = 0; i < this.table.length; i++) {
if (this.table[i] == o)
this.remove(i);
}
}
}
/**
* 리스트안의 값을 배열로 반환한다.
* @returns Array of value
*/
this.toArray = function() {
return this.table.slice(0, this.table.length);
}
/**
* 지정된 fromIndex와 toIndex 사이의 인덱스에 위치한
* 객체들을 List 형태로 반환한다.
* 단, fromIndex의 객체는 포함되지만, toIndex의 객체는 포함되는 않는다.
* @param fromIndex 시작인덱스
* @param toIndex 끝인덱스
* @param List
*/
this.subList = function(fromIndex, toIndex) {
var list = new List();
for (var i = fromIndex; i < toIndex; i++) {
list.add(this.table[i]);
}
return list;
}
/**
* 객체를 표현하는 문자열을 반환한다.
* @return String 표현되는 문자열
*/
this.toString = function() {
var buf = new StringBuffer();
buf.append("{");
for (var i = 0; i < this.table.length - 1; i++) {
var val = this.table[i];
buf.append(val.toString()).append(",");
}
buf.append(this.table[this.table.length - 1]).append("}");
return buf.toString();
}
}
///////////////////////////////////////////////////////////////////////////////
/**
* 값을 저장하는 큐 객체이다.
* @author Eun Jeong-Ho, [email protected]
* @since 2004. 6. 4.
*/
function Queue() {
/**
* 요소를 추가한다.
* @param o 추가할 요소
*/
this.push = function(o) {
this.add(o);
}
/**
* 요소를 빼낸다.
* @return 빼낸 요소
*/
this.pop = function() {
var val = this.get(0);
this.remove(0);
return val;
}
/**
* 맨위 요소를 확인한다.
* pop과 비슷하지만, 요소를 지우지는 않는다.
* @return 빼낸 요소
*/
this.peek = function() {
return this.get(0);
}
}
Queue.prototype = new List(); //상속
///////////////////////////////////////////////////////////////////////////////
/**
* 값을 저장하는 스택 객체이다.
* @author Eun Jeong-Ho, [email protected]
* @since 2004. 6. 4.
*/
function Stack() {
/**
* 요소를 추가한다.
* @param o 추가할 요소
*/
this.push = function(o) {
this.add(o);
}
/**
* 요소를 빼낸다.
* @return 빼낸 요소
*/
this.pop = function() {
var idx = this.size() - 1;
var val = this.get(idx);
this.remove(idx);
return val;
}
/**
* 맨위 요소를 확인한다.
* pop과 비슷하지만, 요소를 지우지는 않는다.
* @return 빼낸 요소
*/
this.peek = function() {
var idx = this.size() - 1;
return this.get(idx);
}
}
Stack.prototype = new List(); //상속
// http://msdn.microsoft.com/en-us/library/ms678086(VS.85).aspx
function ODBC(dsnName, userId, password) {
this.conn = new ActiveXObject("ADODB.Connection");
this.dsn = dsnName;
this.id = userId;
this.pwd = password;
this.query = "DSN=" + this.dsn + ";UID=" + this.id + ";PWD=" + this.pwd;
this.dsnName = function() {
//Setter
if (arguments.length > 0) {
this.dsn = arguments[0];
} else {
//Getter
return this.dsn;
}
}
this.userId = function() {
//Setter
if (arguments.length > 0) {
this.id = arguments[0];
} else {
//Getter
return this.id;
}
}
this.password = function() {
//Setter
if (arguments.length > 0) {
this.pwd = arguments[0];
} else {
//Getter
return this.pwd;
}
}
this.connect = function() {
this.conn.Open(this.query);
return this;
}
this.execute = function(sql, hash) {
if (hash == null)
return new ResultSet(this.conn.Execute(sql));
else {
var pattern = /\$\{([a-zA-Z_][a-zA-Z0-9_\x5F]*)\}/g;
var query = sql;
var match;
while ((match = pattern.exec(query)) != null) {
var key = match[1];
var value = hash[key];
query = query.substring(0, match.index) + value + query.substring(match.lastIndex, query.length);
}
return new ResultSet(this.conn.Execute(query));
}
}
this.close = function() {
if (this.conn != null)
this.conn.Close();
}
function ResultSet(rs) {
this.rs = rs;
if (!this.rs.EOF) {
rs.MoveFirst();
}
this.isFirst = true;
this.close = function() {