-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathxlib.js
More file actions
125 lines (108 loc) · 3.25 KB
/
xlib.js
File metadata and controls
125 lines (108 loc) · 3.25 KB
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
// Copyright 2017 bin jin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Framework
// If the function names conform to the specifications:
// External call function.
// Error handling.
// Display help information.
// Print the functions list.
//
// e.g.
// // [brief_introduction] //[description_1] //[description_2] ...
// function [script_name_without_suffix]_[function_name](){
// ...
// [function_body]
// //
// setErr "[error_description]" // exit and display [error_description]
// ...
// setErr 1 // return false status
// }
////////////////////////////////////////
/***************************************
* Framework *
***************************************/
// Make Error code Or Output error info
function setErr(desc){
throw desc;
}
// Test script run with cscript.exe
function iCscript() {
return "\\cscript.exe" == WScript.FullName.slice(-12);
}
// This script name, e.g. lib
function gScriptName(){
var sname = WScript.ScriptName;
return sname.substring(0, sname.lastIndexOf('.'));
}
// Print strng, like WScript.Echo
function printLine(desc){
if(iCscript()){
WScript.StdOut.WriteLine(desc);
} else {
WScript.Echo(desc);
}
}
function errLine(desc) {
if(iCscript()){
WScript.StdErr.WriteLine(desc);
} else {
WScript.Echo(desc);
}
}
function BKDRHash(key) {
// 31 131 1313 13131 131313
var seed = 131, hash = 0;
for (i = 0; i < key.length; i++) {
hash = hash * seed + key.charCodeAt(i);
}
return hash & 0xFFFFFFFE;
}
function trim(str){
return str.replace(/(^\s*)|(\s*$)/g,"");
}
// Print sort string
function sortPrint(str){
return str.split("\r\n").sort().join("\r\n");
}
// Search this script function
function gfuncAnno(method){
var line, str;
var text = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(WScript.ScriptFullName);
while (text.AtEndOfStream){
line = trim(text);
str = line.toLowerCase();
};
}
// eval("WScript.Echo(0)");
// Object
var objArgs = WScript.Arguments;
for (i = 0; i < objArgs.length; i++){
WScript.Echo(objArgs(i));
}
var a = new Array();
a['test'] = 6;
for (var i in a) {
WScript.Echo(a[i])
}
// var input = "";
// while (!WScript.StdIn.AtEndOfLine)
// {
// input += WScript.StdIn.Read(1);
// }
// WScript.Echo(input);
/***************************************
* Framework *
***************************************/
////////////////////////////////////////