1 //<![CDATA[
  2 
  3 
  4 /**
  5  * @name	Colorless echo JavaScript kit/library base framework
  6  * @fileoverview
  7  * 本檔案包含了呼叫其他 library 需要用到的 function,以及常用 base functions。<br/>
  8  * <br/>
  9  * Copyright (C) 2002-, kanashimi <kanasimi@gmail.com>. All Rights Reserved.<br/>
 10  * <br/>
 11  * This file is in tab wide of 4 chars, documentation with JsDoc Toolkit (<a href="http://code.google.com/p/jsdoc-toolkit/wiki/TagReference">tags</a>).<br/>
 12  * <br/>
 13  * <br/>Please visit <a href="http://lyrics.meicho.com.tw/program/">Colorless echo program room</a> for more informations.
 14  * @since	自 function.js 0.2 改寫
 15  * @since	JavaScript 1.2
 16  * @since	2009/11/17 01:02:36
 17  * @author	kanasimi@gmail.com
 18  * @version	$Id: ce.js,v 0.2 2009/11/26 18:37:11 kanashimi Exp $
 19  */
 20 
 21 
 22 /*
 23 引用:參照
 24 function addCode
 25 
 26 單一JS引用:
 27 //	[function.js]_iF
 28 function _iF(){}_iF.p='HKCU\\Software\\Colorless echo\\function.js.path';if(typeof WScript=="object")try{eval(getU((new ActiveXObject("WScript.Shell")).RegRead(_iF.p)));}catch(e){}
 29 function getU(p,enc){var o;try{o=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){o=new XMLHttpRequest();}if(o)with(o){open('GET',p,false);if(enc&&o.overrideMimeType)overrideMimeType('text/xml;charset='+enc);send(null);return responseText;}}
 30 //	[function.js]End
 31 
 32 
 33 初始化:參照
 34 initialization of function.js
 35 
 36 <script type="text/javascript" src="path/to/function.js"></script>
 37 <script type="application/javascript;version=1.7" src="path/to/function.js"></script>
 38 
 39 
 40 */
 41 
 42 
 43 //try{
 44 
 45 if (typeof CeL !== 'function')
 46 //void(
 47 (function(){
 48 
 49 var
 50 	/**
 51 	 * debug level
 52 	 * @ignore
 53 	 */
 54 	debug = 1
 55 
 56 	,global
 57 
 58 	//,window
 59 
 60 	/**
 61 	 * Will speed up references to undefined, and allows redefining its name. (from jQuery)
 62 	 * 用在 return undefined
 63 	 */
 64 	//,undefined
 65 
 66 	,_CeL
 67 
 68 	,CeL
 69 
 70 	,loaded_module
 71 
 72 	//,_base_function_to_extend
 73 	;
 74 
 75 
 76 //		members of library	-----------------------------------------------
 77 ;
 78 
 79 
 80 /**
 81  * Global Scope object<br/>
 82  * 於 CeL.eval 使用
 83  * @ignore
 84  */
 85 global = this;	//	isWeb()?window:this;
 86 
 87 
 88 /*
 89 var _Global=(function(){return this;})();
 90 _Global.JustANumber=2;	//	var _GlobalPrototype=_Global.constructor.prototype;_GlobalPrototype.JustANumber=2;
 91 if(typeof _Global=='undefined')_Global=this;
 92 for(i in _Global)alert(i);
 93 */
 94 
 95 //	若已經定義過,跳過。
 96 if(typeof (global.CeL) !== 'undefined')
 97 	return;
 98 
 99 
100 /**
101  * Will speed up references to DOM: window, and allows redefining its name. (from jQuery)
102  * @ignore
103  */
104 //window = this;
105 
106 
107 /**
108  * 本 JavaScript framework 的框架基本宣告<br/>
109  * base name-space declaration of JavaScript library framework
110  * @example
111  * //	判別是否已經 load 過
112  * if(typeof CeL !== 'function' || CeL.Class !== 'CeL')
113  * 	;	//	CeL has not been loaded
114  * @name	CeL
115  * @class	Colorless echo JavaScript kit/library: base name-space declaration
116  */
117 CeL = function(){
118 	//	function CeL	//	declaration for debug
119 	//this.global = arguments[0] || arguments.callee.ce_doc;
120 	return new (arguments.callee.init.apply(null, arguments));
121 };
122 
123 /**
124  * JavaScript library framework main class name.
125  * @see	<a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">ECMA-262</a>: Class: A string value indicating the kind of this object.
126  * @constant
127  */
128 CeL.Class = 'CeL';
129 
130 
131 /**
132  * Map over main name-space in case of overwrite (from jQuery)
133  * @ignore
134  */
135 _CeL = global.CeL;
136 global[CeL.Class] = CeL;
137 
138 
139 /**
140  * framework main prototype definition
141  * for JSDT: 有 prototype 才會將之當作 Class
142  */
143 CeL.prototype = {
144 };
145 
146 
147 
148 
149 // 取得執行script之path,在.hta中取代 WScript.ScriptFullName,%20的部分最好再加其他的…
150 CeL.get_script_full_name = function(){
151 	return	typeof WScript === 'object'? WScript.ScriptFullName
152 			: typeof location === 'object'? unescape(location.pathname)
153 			: '';
154 };
155 // 取得執行script之名稱
156 CeL.get_script_name = function(){
157 	var n, i, j;
158 
159 	if (typeof WScript === 'object') {
160 		n = WScript.ScriptName;
161 		i = n.lastIndexOf('.');
162 		return i == -1 ? n : n.slice(0, i);
163 	}
164 
165 	if (typeof location === 'object') {
166 		n = unescape(location.pathname), j = n.lastIndexOf('.');
167 		if (!(i = n.lastIndexOf('\\') + 1))
168 			i = n.lastIndexOf('/') + 1;	//	location.pathname在.hta中會回傳'\'形式的path
169 		return i < j ? n.slice(i, j) : n.substr(i);
170 	}
171 
172 	return typeof document === 'object' ? document.title : '';
173 };
174 
175 
176 
177 
178 /**
179  * 取得/設定環境變數 enumeration<br/>
180  * (雖然不喜歡另開 namespace,但以 2009 當下的 JsDoc Toolkit 來說,似乎沒辦法創造 enumeration。)
181  * @class	環境變數 (environment variables) 與程式會用到的 library 相關變數。
182  * @param name	環境變數名稱
183  * @param value	環境變數之值
184  * @return	舊環境變數之值
185  */
186 CeL.env = function(name, value) {
187 	if (!name)
188 		return undefined;
189 
190 	var _s = arguments.callee, v = _s[name];
191 	if (arguments.length > 1)
192 		_s[name] = value;
193 	return isNaN(v) ? '' + v : v;
194 };
195 
196 /**
197  * Setup environment variables
198  * @param	{string}[OS_type]	type of OS
199  * @return	environment variables set
200  */
201 CeL.initial_env = function(OS_type){
202 	//this.env = {};
203 	var OS, env = this.env;
204 
205 	/**
206 	 * library main file base name<br/>
207 	 * full path: {@link CeL.env.registry_path} + {@link CeL.env.main_script}
208 	 * @name	CeL.env.main_script
209 	 */
210 	env.main_script = 'ce.js';
211 
212 	/**
213 	 * module 中的這 member 定義了哪些 member 不被 extend
214 	 * @name	CeL.env.not_to_extend_keyword
215 	 */
216 	env.not_to_extend_keyword = 'no_extend';
217 
218 	/**
219 	 * 本 library source 檔案使用之 encoding<br/>
220 	 * 不使用會產生語法錯誤
221 	 * @name	CeL.env.source_encoding
222 	 */
223 	env.source_encoding = 'UTF-16';
224 
225 	/**
226 	 * default global object
227 	 * @name	CeL.env.global
228 	 */
229 	env.global = global;
230 
231 	/**
232 	 * creator group
233 	 * @name	CeL.env.company
234 	 */
235 	env.company = 'Colorless echo';
236 		env.registry_key = 'HKCU\\Software\\' + env.company + '\\' + this.Class
237 				+ '.path';
238 	//if(typeof WScript==='object')
239 	try {
240 		/**
241 		 * 存放在 registry 中的 path
242 		 * @name	CeL.env.registry_path
243 		 */
244 		env.registry_path = (WScript.CreateObject("WScript.Shell"))
245 				.RegRead(env.registry_key).replace(/[^\\\/]+$/, '');
246 		// this.log(env.registry_path);
247 	} catch (e) {
248 		// this.log(e.message);
249 	}
250 
251 
252 	//條件式編譯(条件コンパイル) for version>=4, 用 /*@ and @*/ to 判別
253 	/*@cc_on
254 	@if(@_PowerPC||@_mac)
255 	 OS='Mac';
256 	@else
257 	 @if(@_win32||@_win64||@_win16)
258 	  OS='DOS';
259 	 @else
260 	  OS='unix';	//	unknown
261 	 @end
262 	@end@*/
263 
264 	/**
265 	 * 本次執行所在 OS 平台
266 	 * @name	CeL.env.OS
267 	 */
268 	env.OS = OS = typeof OS_type === 'string' ? OS_type
269 			// 假如未設定則取預設值
270 			: (OS || 'unix');
271 
272 	/**
273 	 * 文件預設 new line
274 	 * @name	CeL.env.new_line
275 	 */
276 	env.new_line=		OS == 'unix' ? '\n' : OS == 'Mac' ? '\r' : '\r\n';	//	in VB: vbCrLf
277 	/**
278 	 * file system 預設 path separator<br/>
279 	 * platform-dependent path separator character, 決定目錄(directory)分隔
280 	 * @name	CeL.env.path_separator
281 	 */
282 	env.path_separator	=	OS == 'unix' ? '/' : '\\';
283 	/**
284 	 * 預設 module name separator
285 	 * @name	CeL.env.module_name_separator
286 	 */
287 	env.module_name_separator='.';
288 	/**
289 	 * path_separator in 通用(regular)運算式
290 	 * @name	CeL.env.path_separator_RegExp
291 	 */
292 	env.path_separator_RegExp = this.to_RegExp_pattern ? this
293 			.to_RegExp_pattern(env.path_separator)
294 			: (env.path_separator == '\\' ? '\\' : '') + env.path_separator;
295 	/**
296 	 * 預設語系
297 	 * 0x404:中文-台灣,0x0411:日文-日本
298 	 * @name	CeL.env.locale
299 	 * @see	<a href="http://msdn.microsoft.com/zh-tw/library/system.globalization.cultureinfo(VS.80).aspx">CultureInfo 類別</a>
300 	 */
301 	env.locale = 0x404;
302 
303 	/**
304 	 * script name
305 	 * @name	CeL.env.script_name
306 	 */
307 	env.script_name = this.get_script_name();
308 	/**
309 	 * base path of library
310 	 * @name	CeL.env.library_base_path
311 	 */
312 	env.library_base_path = this.get_script_full_name(); // 以reg代替
313 
314 	return env;
315 };
316 
317 
318 
319 
320 /**
321  * Tell if it's now debugging.
322  * @param {int}[debug_level]	if it's now in this debug level.
323  * @type	boolean
324  * @return	It's now debugging or in specified debug level.
325  */
326 CeL.is_debug = function(debug_level){
327 	return typeof debug_level === 'undefined' ? debug
328 				: debug == debug_level;
329 };
330 
331 /**
332  * Set debug level
333  * @param {int}[debug_level]	The debug level to set.
334  * @type	int
335  * @return	debug level now
336  */
337 CeL.set_debug = function(debug_level){
338 	if(typeof debug_level === 'undefined')
339 		debug_level = 1;
340 
341 	if(!isNaN(debug_level))
342 		debug = debug_level;
343 
344 	return debug;
345 };
346 
347 
348 /*
349 CeL.extend(function f_name(){}, object || string, initial arguments);
350 CeL.extend({name:function(){},.. }, object || string);
351 CeL.extend([function1,function12,..], object || string);
352 
353 set .name
354 */
355 
356 /**
357  * 延展物件 (learned from jQuery)
358  * @since	2009/11/25 21:17:44
359  * @param	variable_set	variable set
360  * @param	namespace	extend to what namespace
361  * @param	from_namespace	When inputing function names, we need a base namespace to search these functions.
362  * @return	CeL
363  * @see	<a href="http://blog.darkthread.net/blogs/darkthreadtw/archive/2009/03/01/jquery-extend.aspx" accessdate="2009/11/17 1:24" title="jQuery.extend的用法 - 黑暗執行緒">jQuery.extend的用法</a>
364  */
365 CeL.extend = function(variable_set, namespace, from_namespace){
366 /*
367 	if(this.is_debug())
368 		throw new Error(1, 'UNDO');
369 */
370 	var _s, i, l;
371 
372 	if(typeof namespace === 'undefined' || namespace === null)
373 		namespace = this;
374 
375 	if(typeof from_namespace === 'undefined')
376 		from_namespace = this;
377 
378 	if(typeof variable_set === 'function'){
379 		if(this.parse_function){
380 		}else{
381 			CeL.log('Warning: Please include ' + this.Class + '.parse_function() first!');
382 		}
383 
384 	}else if(typeof variable_set === 'string'){
385 		if(namespace === from_namespace)
386 			;
387 		else if(variable_set in from_namespace){
388 			//CeL.log('CeL.extend:\nextend (' + (typeof variable_set) + ') ' + variable_set + '\n=' + from_namespace[variable_set] + '\n\nto:\n' + namespace);
389 			namespace[variable_set] = from_namespace[variable_set];
390 		}else
391 			try{
392 				namespace[variable_set] = eval(variable_set);
393 				//CeL.log('CeL.extend:\n' + variable_set + ' = ' + namespace[variable_set]);
394 			}catch(e){
395 				CeL.log('CeL.extend:\n' + e.message);
396 			}
397 
398 	}else if(variable_set instanceof Array){
399 		for (_s = arguments.callee, i = 0, l = variable_set.length; i < l; i++) {
400 			_s(variable_set[i], namespace, from_namespace);
401 		}
402 
403 	}else if(variable_set instanceof Object){
404 		for(i in variable_set){
405 			namespace[i] = variable_set[i];
406 		}
407 	}
408 
409 	return this;
410 };
411 
412 
413 /**
414  * Get file resource<br/>
415  * 用於 include JavaScript 檔之類需求時,取得檔案內容之輕量級函數。<br/>
416  * 除 Ajax,本函數亦可用在 CScript 執行中。
417  * @example
418  * //	get contents of [path/to/file]:
419  * var file_contents = CeL.get_file('path/to/file');
420  * @param	{String} path	URI / full path. <em style="text-decoration:line-through;">不能用相對path!</em>
421  * @param	{String} [encoding]	file encoding
422  * @return	{String} data	content of path
423  * @return	{undefined}	when error occurred: no Ajax function, ..
424  * @throws	uncaught exception @ Firefox: 0x80520012 (NS_ERROR_FILE_NOT_FOUND), <a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/#exceptions">NETWORK_ERR</a> exception
425  * @throws	'Access to restricted URI denied' 當 access 到上一層目錄時
426  * @see
427  * <a href=http://blog.joycode.com/saucer/archive/2006/10/03/84572.aspx">Cross Site AJAX</a><br/>
428  * <a href="http://domscripting.com/blog/display/91">Cross-domain Ajax</a>
429  */
430 CeL.get_file = function(path, encoding){
431 	//with(typeof window.XMLHttpRequest=='undefined'?new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest()){
432 
433 	/**
434 	 * XMLHttpRequest object
435 	 */
436 	var o;
437 
438 	try{
439 		o = new ActiveXObject('Microsoft.XMLHTTP');
440 	}catch(e){
441 		o = new XMLHttpRequest();
442 	}
443 
444 	if(o)with(o){
445 		open('GET', path, false);
446 
447 		if (encoding && o.overrideMimeType)
448 			/*
449 			 * old: overrideMimeType('text/xml;charset='+encoding);
450 			 * 但這樣會被當作 XML 解析,產生語法錯誤。
451 			 */
452 			overrideMimeType('application/json;charset=' + encoding);
453 
454 
455 		send(null);
456 		/*
457 		try {
458 			send(null);
459 		} catch (e) {
460 			//	file not found
461 			//	uncaught exception @ Firefox: 0x80520012 (NS_ERROR_FILE_NOT_FOUND)
462 			return undefined;
463 		}
464 		*/
465 
466 		return responseText;
467 	}//	else: This browser does not support XMLHttpRequest.
468 
469 	return undefined;	//	This function must return a result of type any
470 };
471 
472 /**
473  * 本 library 專用之 evaluate()
474  * @param code	code to eval
475  * @return	value that eval() returned
476  */
477 CeL.eval = function(code) {
478 	/*
479 		JSC eval() takes an optional second argument which can be 'unsafe'.
480 		Mozilla/SpiderMonkey eval() takes an optional second argument which is the scope object for new symbols.
481 
482 		use window.execScript(code,"JavaScript") in IE: window.execScript()將直接使用全局上下文環境,因此,execScript(Str)中的字符串Str可以影響全局變量。——也包括聲明全局變量、函數以及對象構造器。
483 	*/
484 	//this.log(global.eval);
485 	//this.log(global && global.eval && global.eval !== arguments.callee);
486 	//global.eval(code);
487 	return global && global.eval && global.eval !== arguments.callee ? global.eval.call(global, code) : eval(code);
488 };
489 
490 /*	得知相對basePath
491 <script type="text/javascript" src="../baseFunc.js"></script>
492 var basePath=getBasePath('baseFunc.js');	//	引數為本.js檔名	若是更改.js檔名,亦需要同步更動此值!
493 */
494 CeL.get_base_path = function(JSFN){
495 	if(!JSFN)
496 		return (typeof WScript === 'object'
497 					? WScript.ScriptFullName
498 					: location.href
499 				).replace(/[^\/\\]+$/, '');
500 
501 	if (typeof document!=='object')
502 			return '';
503 
504 	//	form dojo: d.config.baseUrl = src.substring(0, m.index);
505 	var i, j, b, o = document.getElementsByTagName('script');
506 
507 	for (i in o)
508 		try {
509 			j = o[i].getAttribute('src');
510 			i = j.indexOf(JSFN);
511 			if (i != -1)
512 				b = j.slice(0, i);
513 		} catch (e) {
514 		}
515 
516 	return b || '';	//	this.log()
517 };
518 
519 
520 /**
521  * get the path of specified module
522  * @param {String} module_name	module name
523  * @return	{String} module path
524  */
525 CeL.get_module_path = function(module_name){
526 	if(!module_name)
527 		return module_name;
528 
529 	//this.log(this.Class+'.get_module_path: load ['+module_name+']');
530 	var module_path = this.env.registry_path
531 				|| this.get_base_path(this.env.main_script)
532 				|| this.get_base_path()
533 				;
534 	module_path += this.split_module_name(module_name).join(/\//.test(module_path)?'/':'\\') + '.js';
535 	//this.log(module_path);
536 
537 	if (this.getFP)
538 		return this.getFP(module_path, 1);
539 
540 	//this.log(module_name+': '+module_path);
541 
542 	return module_path;
543 };
544 
545 
546 /*
547 sample to test:
548 
549 ./a/b
550 ./a/b/
551 ../a/b
552 ../a/b/
553 a/../b		./b
554 a/./b		a/b
555 /../a/b		/a/b
556 /./a/b		/a/b
557 /a/./b		/a/b
558 /a/../b		/b
559 /a/../../../b	/b
560 /a/b/..		/a
561 /a/b/../	/a/
562 a/b/..		a
563 a/b/../		a/
564 a/..		.
565 ./a/b/../../../a.b/../c	../c
566 ../../../a.b/../c	../../../c
567 
568 */
569 
570 //	2009/11/23 22:12:5
571 CeL.deprecated_simplify_path = function(path){
572 	if(typeof path === 'string'){
573 		path = path.replace(/\s+$|^\s+/,'').replace(/\/\/+/g,'/');
574 
575 		var p, is_absolute = '/' === path.charAt(0);
576 
577 		while( path !== (p=path.replace(/\/\.(\/|$)/g,function($0,$1){return $1;})) )
578 			path = p;
579 		CeL.log('1. '+p);
580 
581 		while( path !== (p=path.replace(/\/([^\/]+)\/\.\.(\/|$)/g,function($0,$1,$2){alert([$0,$1,$2].join('\n'));return $1 === '..'? $0: $2;})) )
582 			path = p;
583 		CeL.log('2. '+p);
584 
585 		if(is_absolute)
586 			path = path.replace(/^(\/\.\.)+/g,'');
587 		else
588 			path = path.replace(/^(\.\/)+/g,'');
589 		CeL.log('3. '+p);
590 
591 		if(!path)
592 			path = '.';
593 	}
594 
595 	return path;
596 };
597 
598 /**
599  * 轉化所有 /., /.., //
600  * @since	2009/11/23 22:32:52
601  * @param {string} path	欲轉化之 path
602  * @return	{string} path
603  */
604 CeL.simplify_path = function(path){
605 	if(typeof path === 'string'){
606 		var i, j, l, is_absolute, head;
607 
608 		path = path
609 			.replace(/^[\w\d\-]+:\/\//,function($0){head = $0; return '';})
610 			//.replace(/\s+$|^\s+/g,'')
611 			//.replace(/\/\/+/g,'/')
612 			.split('/');
613 
614 		i = 0;
615 		l = path.length;
616 		is_absolute = !path[0];
617 
618 		for(;i<l;i++){
619 			if(path[i] === '.')
620 				path[i] = '';
621 
622 			else if(path[i] === '..'){
623 				j=i;
624 				while(j>0)
625 					if(path[--j] && path[j]!='..'){
626 						path[i] = path[j] = '';	//	相消
627 						break;
628 					}
629 			}
630 		}
631 
632 		if(!is_absolute && !path[0])
633 			path[0] = '.';
634 
635 		path = path.join('/')
636 			.replace(/\/\/+/g,'/')
637 			.replace(is_absolute? /^(\/\.\.)+/g: /^(\.\/)+/g,'')
638 			;
639 
640 		if(!path)
641 			path = '.';
642 
643 		if(head)
644 			path = head + path;
645 	}
646 
647 	return path;
648 };
649 
650 
651 
652 
653 
654 /**
655  * 已經 include 之函式或 class
656  * @inner
657  */
658 loaded_module = {
659 };
660 
661 /**
662  * Include specified module<br/>
663  * 注意:以下的 code 中,CeL.warn 不一定會被執行(可能會、可能不會),因為執行時 code.log 尚未被 include。<br/>
664  * 此時應該改用 CeL.use('code.log', callback);<br/>
665  * code in head/script/:
666  * <pre>
667  * CeL.use('code.log');
668  * CeL.warn('a WARNING');
669  * </pre>
670  * @param	{String} module	module name
671  * @param	{Function} [callback]	callback function
672  * @param	{Object, Boolean} [extend_to]	extend to which namespace<br/>
673  * false:	just load, don't extend to CeL<br/>
674  * this:	extend to global<br/>
675  * object:	extend to specified namespace that you can use [namespace]._func_ to run it<br/>
676  * (others, including undefined):	extend to root of this library. e.g., call CeL._function_name_ and we can get the specified function.
677  * @return
678  * @example
679  * CeL.use('code.log', function(){..});
680  * CeL.use(['code.log', 'code.debug']);
681  */
682 CeL.use = function(module, callback, extend_to){
683 	var i, l, module_path;
684 
685 	if (!module)
686 		return;
687 
688 	/*
689 	if (arguments.length > 3) {
690 		l = arguments.length;
691 		namespace = arguments[--l];
692 		callback = arguments[--l];
693 		--l;
694 		for (i = 0; i < l; i++)
695 			this.use(arguments[i], callback, namespace);
696 		return;
697 	}
698 	*/
699 
700 	if (module instanceof Array) {
701 		for (i = 0,l=module.length; i < l; i++)
702 			this.use(module[i], callback, extend_to);
703 		return;
704 	}
705 
706 	if (!(module_path = this.get_module_path(module)) || this.is_loaded(module))
707 		return;
708 
709 	//this.log(this.Class+'.use ['+module+']:\ntry to load ['+module_path+'].');
710 
711 	try {
712 		if (callback && typeof window !== 'undefined')
713 			this.include_resource(module_path, {
714 				module : module,
715 				callback : callback,
716 				global : this
717 			});
718 		else
719 			//this.log('load ['+module_path+']'),
720 			//this.log('load ['+module_path+']:\n'+this.get_file(module_path, this.env.source_encoding)),
721 			this.eval(this.get_file(module_path,
722 							this.env.source_encoding));
723 	} catch (e) {
724 		//	http://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html
725 		//	http://reference.sitepoint.com/javascript/DOMException
726 		if(e.constructor == '[object DOMException]' && e.code === 1012)
727 			this.log(e.message+'\n'+module_path
728 				+'\n\n程式可能呼叫了一個不存在的,或是繞經上層目錄的檔案?\n請嘗試使用相對路徑或 '
729 				+this.Class+'.use(module, callback function, namespace)');
730 		else
731 			this.log(
732 				this.Class+'.use: Cannot load [' + module
733 				+ ']!\n['+(e.constructor)+'] '+(e.number||e.code)+': '+e.message
734 				+'\n抱歉!在載入其他網頁時發生錯誤,有些功能可能失常。\n重新讀取(reload),或是過段時間再嘗試或許可以解決問題。'
735 			);
736 		//this.log('Cannot load [' + module + ']!', this.log.ERROR, e);
737 
738 		return;
739 	}
740 
741 	//	處理 extend to namespace
742 	if (!extend_to && extend_to !== false
743 			|| typeof namespace !== 'function'
744 			|| !(extend_to instanceof Object))
745 		extend_to = this;
746 
747 	if (extend_to) {
748 		var ns = this.get_module(module), kw = this.env.not_to_extend_keyword, no_extend = {};
749 		// this.log(this.Class + '.use [' + module + ']:\nextend\n' + ns);
750 
751 		if (kw in ns) {
752 			l = ns[kw];
753 			if (typeof l === 'string') {
754 				no_extend[l] = 1;
755 			} else if (l instanceof Array) {
756 				for (i in l)
757 					no_extend[i] = 1;
758 			} else if (l instanceof Object) {
759 				no_extend = l;
760 			}
761 			no_extend[kw] = 1;
762 		}
763 
764 		//	'*': 完全不 extend
765 		if (!no_extend['*']) {
766 			no_extend.Class = 1;
767 			l = [];
768 			for (i in ns)
769 				if (!(i in no_extend))
770 					l.push(i);
771 
772 			//this.log(this.Class + '.use [' + module + ']:\nextend\n' + l + '\n\nto:\n' + (extend_to.Class || extend_to));
773 			this.extend(l, extend_to, ns);
774 		}
775 
776 	}
777 
778 };
779 
780 
781 /*
782 bad: sometimes doesn't work. e.g. Google Maps API in IE
783 push inside window.onload:
784 window.onload=function(){
785 include_resource(p);
786 setTimeout('init();',2000);
787 };
788 
789 way 3:	ref. dojo.provide();, dojo.require();
790 document.write('<script type="text/javascript" src="'+encodeURI(p)+'"><\/script>');
791 
792 TODO:
793 encode
794 
795 */
796 ;
797 /**
798  * include other JavaScript/CSS files
799  * @param {String} resource path
800  * @param {Function, Object} callback	callback function / 	{callback: callback function, module: module name, global: global object when run callback}
801  * @param {Boolean} [use_write]	use document.write() instead of insert a element
802  * @param {Boolean} [is_css]	is a .css file
803  */
804 CeL.include_resource = function(path, callback, use_write, is_css) {
805 	var _s = arguments.callee, s, t;
806 	//if(!_f.loaded)_f.loaded={},_f.count=0;
807 
808 	if (path instanceof Array) {
809 		for (s = 0, t = path.length; s < t; s++)
810 			_f(path[s], callback, use_write, is_css);
811 		return;
812 	}
813 
814 	if(path in _s.loaded)
815 		return;
816 
817 	if(typeof c==='undefined')
818 		is_css=/\.css$/i.test(path);
819 
820 	t='text/'+(is_css?'css':'javascript');
821 /*@cc_on
822 w=1;	//	IE hack
823 @*/
824 	if (!use_write)
825 		try {
826 			// Dynamic Loading
827 			// http://code.google.com/apis/ajax/documentation/#Dynamic
828 			s = document.createElement(is_css ? 'link' : 'script');
829 			s.type = t;
830 			if (is_css)
831 				s.href = path, s.rel = 'stylesheet';
832 			else
833 				s.src = path;
834 			(document.getElementsByTagName('head')[0] || document.body.parentNode
835 					.appendChild(document.createElement('head')))
836 					.appendChild(s);
837 			//this.log('include_resource: HTML:\n' + document.getElementsByTagName('html')[0].innerHTML);
838 		} catch (e) {
839 			use_write = 1;
840 		}
841 
842 	if (use_write)
843 		document.write(is_css ? '<link type="' + t
844 				+ '" rel="stylesheet" href="' + path + '"><\/link>'
845 				: '<script type="' + t + '" src="' + path
846 				+ '"><\/script>' //	language="JScript"
847 		);
848 
849 	_s.loaded[path] = _s.count++;
850 
851 	if(callback)
852 		_s.wait_to_call(callback);
853 };
854 
855 /**
856  * 已經 include_resource 了哪些 JavaScript 檔(存有其路徑)
857  * loaded{路徑} = count
858  */
859 CeL.include_resource.loaded = {};
860 
861 /**
862  * 已經 include_resource 了多少個 JavaScript 檔
863  * @type Number
864  */
865 CeL.include_resource.count = 0;
866 
867 CeL.include_resource.wait_to_call = function(callback) {
868 	//alert('include_resource.wait_to_call:\n' + CeL.to_module_name(callback.module));
869 
870 	if (typeof callback === 'function')
871 		//	不是 module,僅僅為指定 function 的話,直接等一下再看看。
872 		//	TODO: 等太久時 error handle
873 		window.setTimeout(callback, 200);
874 
875 	else if (callback.global.is_loaded(callback.module))
876 		callback.callback();
877 
878 	else {
879 		/**
880 		 * the function it self, not 'this'.
881 		 * @inner
882 		 * @ignore
883 		 */
884 		var _s = arguments.callee;
885 		window.setTimeout(function() {
886 			_s(callback);
887 		}, 10);
888 	}
889 };
890 
891 CeL.get_module = function(module_name) {
892 	module_name = this.split_module_name(module_name);
893 
894 	//	TODO: test module_name.length
895 	if(!module_name)
896 		return null;
897 
898 	var i = 0, l = module_name.length, namespace = this;
899 	//	一層一層 call namespace
900 	while (i < l)
901 		try {
902 			namespace = namespace[module_name[i++]];
903 		} catch (e) {
904 			return null;
905 		}
906 
907 	return namespace;
908 };
909 
910 /**
911  * 預先準備好下層 module 定義時的環境。<br/>
912  * 請盡量先 call 上層 namespace 再定義下層的。
913  * @param	{String} module_name	module name
914  * @param	{Function} code_for_including	若欲 include 整個 module 時,需囊括之 code。
915  * @return	null	invalid module
916  * @return	{Object}	下層 module 之 namespace
917  */
918 CeL.setup_module = function(module_name, code_for_including) {
919 	module_name = this.split_module_name(module_name);
920 
921 	//	TODO: test module_name.length
922 	if(!module_name)
923 		return null;
924 
925 	var i = 0, l = module_name.length - 1, namespace = this, name;
926 	//	一層一層準備好 namespace
927 	for (; i < l; i++) {
928 		if (!namespace[name = module_name[i]])
929 			namespace[name] = new Function(
930 					'//	module namespace of ' +
931 					this.to_module_name(module_name.slice(0, i + 1)));
932 		namespace = namespace[name];
933 	}
934 	//	namespace 這時是 modele 的 parent modele。
935 
936 	if (
937 			// 尚未被定義或宣告過
938 			!namespace[name = module_name[l]] ||
939 			// 可能是之前簡單定義過,例如被上面處理過。這時重新定義,並把原先的 member 搬過來。
940 			!namespace[name].Class) {
941 
942 		//	保留原先的 namespace,for 重新定義
943 		l = namespace[name];
944 
945 		// extend code, 起始 namespace
946 		//	TODO: code_for_including(this, load_arguments)
947 		namespace = namespace[name] = code_for_including(this);
948 
949 		// 把原先的 member 搬過來
950 		if (l) {
951 			delete l.Class;
952 			//	may use: this.extend() 
953 			for (i in l)
954 				namespace[i] = l[i];
955 		}
956 		namespace.Class = this.to_module_name(module_name);
957 	}
958 
959 /*
960 	l=[];
961 	for(i in namespace)
962 		l.push(i);
963 	WScript.Echo('Get members:\n'+l.join(', '));
964 */
965 
966 	this.set_loaded(namespace.Class, code_for_including);
967 
968 	return namespace;
969 };
970 
971 
972 //	並沒有對 module 做完善的審核!
973 CeL.split_module_name = function(module_name) {
974 	if (typeof module_name === 'string')
975 		module_name = module_name.replace(/\.\.+|\\\\+|\/\/+/g, '.').split(/\.|\\|\/|::/);
976 
977 	if (module_name instanceof Array) {
978 		//	去除 library name
979 		if (module_name.length>1 && this.Class == module_name[0])
980 			module_name.shift();
981 		return module_name;
982 	} else
983 		return null;
984 };
985 
986 
987 CeL.to_module_name = function(module, separator) {
988 	if (typeof module === 'function')
989 		module = module.Class;
990 
991 	if (typeof module === 'string')
992 		module = this.split_module_name(module);
993 
994 	var name = '';
995 	if (module instanceof Array) {
996 		if (typeof separator !== 'string')
997 			separator = this.env.module_name_separator;
998 		if (module[0] != this.Class)
999 			name = this.Class + separator;
1000 		name += module.join(separator);
1001 	}
1002 
1003 	return name;
1004 };
1005 
1006 //	TODO
1007 CeL.unload = function(module, g){
1008 };
1009 
1010 
1011 /**
1012  * 判斷 module 是否存在,以及是否破損。
1013  * @param	{String} module_name	module name
1014  * @return	{Boolean} module 是否存在以及良好。
1015  */
1016 CeL.is_loaded = function(module_name) {
1017 	// var _s = arguments.callee;
1018 	//this.log('is_loaded: test ' + this.to_module_name(module_name));
1019 	return loaded_module[this.to_module_name(module_name)] ? true
1020 			: false;
1021 };
1022 
1023 
1024 
1025 CeL.set_loaded = function(module_name, code_for_including) {
1026 	//this.log('set_loaded: ' + this.to_module_name(module_name));
1027 	loaded_module[this.to_module_name(module_name)] = code_for_including || true;
1028 };
1029 
1030 
1031 
1032 //	initial
1033 
1034 //temporary decoration incase we call for nothing
1035 CeL.log = function(){
1036 if(debug)
1037 	//arguments.callee.function_to_call.apply(null,arguments);
1038 	arguments.callee.function_to_call.apply(global, arguments);
1039 };
1040 
1041 
1042 CeL.log.function_to_call =
1043 	typeof JSalert==='function'?JSalert:
1044 	typeof WScript==='object'?function(m){m=''+m;if(m.length>2000)m=m.slice(0,1000)+'\n\n..\n\n'+m.slice(-1000);WScript.Echo(m);}:
1045 	typeof alert==='object' || typeof alert==='function'? function(m){m=''+m;if(m.length>2000)m=m.slice(0,1000)+'\n\n..\n\n'+m.slice(-1000);alert(m);}:
1046 	function(){};
1047 
1048 CeL.initial_env();
1049 
1050 
1051 /*
1052 var test_obj=CeL(2,'test: initial');
1053 
1054 test_obj.test_print('OK!');
1055 */
1056 ;
1057 
1058 
1059 
1060 //setTool(),oldVadapter();	//	當用此檔debug時請執行此行
1061 //alert(ScriptEngine()+' '+ScriptEngineMajorVersion()+'.'+ScriptEngineMinorVersion()+'.'+ScriptEngineBuildVersion());
1062 
1063 
1064 
1065 /*	initialization of function.js
1066 	僅僅執行此檔時欲執行的程序。
1067 
1068 setTool(),oldVadapter();	//	當用此檔debug時請執行此行
1069 
1070 	利用.js加上此段與init(),以及.hta(<script type="text/javascript" src="~.js"></script>),可造出GUI/none GUI兩種可選擇之介面。
1071 	if(typeof args=='object')init();else window.onload=init;
1072 */
1073 //args=args.concat(['turnCode.js']);
1074 var _library_onload;
1075 if (typeof _library_onload === 'undefined')
1076 	_library_onload = function() {
1077 		//WScript.Echo(CeL.env.ScriptName);
1078 		//CeL.log(CeL.env.ScriptName);
1079 		if (1 && CeL.env.ScriptName === 'ce') {
1080 			//WScript.Echo(CeL.env.ScriptName);
1081 			CeL.use('OS.Windows.registry');
1082 			//CeL.log(CeL.registryF);
1083 
1084 			var _p = CeL.registryF.getValue(CeL._iF.p) || '(null)';
1085 			if (_p != CeL.env.library_base_path) {
1086 				CeL.log('Change path of [' + CeL.env.ScriptName + '] from:\n' + _p
1087 						+ '\n to\n' + CeL.env.library_base_path + '\n\n' + CeL._iF.p);
1088 				CeL.registryF.setValue.cid = 1;
1089 				CeL.registryF.setValue(CeL._iF.p, CeL.env.library_base_path, 0, 0, 1);
1090 				CeL.registryF.setValue.cid = 0;
1091 			}
1092 
1093 			if (typeof args === 'object') {// args instanceof Array
1094 				// getEnvironment();
1095 				// alert('Get arguments ['+args.length+']\n'+args.join('\n'));
1096 				if (args.length) {
1097 					var i = 0, p, enc, f, backupDir = dBasePath('kanashimi\\www\\cgi-bin\\program\\log\\');
1098 					if (!fso.FolderExists(backupDir))
1099 						try {
1100 							fso.CreateFolder(backupDir);
1101 						} catch (e) {
1102 							backupDir = dBasePath('kanashimi\\www\\cgi-bin\\game\\log\\');
1103 						}
1104 					if (!fso.FolderExists(backupDir))
1105 						try {
1106 							fso.CreateFolder(backupDir);
1107 						} catch (e) {
1108 							if (2 == alert(
1109 									'無法建立備份資料夾[' + backupDir + ']!\n接下來的操作將不會備份!',
1110 									0, 0, 1 + 48))
1111 								WScript.Quit();
1112 							backupDir = '';
1113 						}
1114 					// addCode.report=true; // 是否加入報告
1115 					for (; i < args.length; i++)
1116 						if ((f = dealShortcut(args[i], 1))
1117 								.match(/\.(js|vbs|hta|s?html?|txt|wsf|pac)$/i)
1118 								&& isFile(f)) {
1119 							p = alert(
1120 									'是否以預設編碼['
1121 											+ ((enc = autodetectEncode(f)) == simpleFileDformat ? '內定語系(' + simpleFileDformat + ')'
1122 													: enc) + ']處理下面檔案?\n' + f,
1123 									0, 0, 3 + 32);
1124 							if (p == 2)
1125 								break;
1126 							else if (p == 6) {
1127 								if (backupDir)
1128 									fso.CopyFile(f, backupDir + getFN(f), true);
1129 								addCode(f);
1130 							}
1131 						}
1132 				} else if (1 == alert('We will generate a reduced ['
1133 						+ CeL.env.ScriptName + ']\n  to [' + CeL.env.ScriptName
1134 						+ '.reduced.js].\nBut it takes several time.', 0, 0,
1135 						1 + 32))
1136 					reduceScript(0, CeL.env.ScriptName + '.reduced.js');
1137 			}//else window.onload=init;
1138 
1139 			//CeL._iF=undefined;
1140 		} //	if(1&&CeL.env.ScriptName==='function'){
1141 	}; //	_library_onload
1142 
1143 
1144 
1145 
1146 
1147 /*
1148 
1149 //	test WinShell	http://msdn.microsoft.com/en-us/library/bb787810(VS.85).aspx
1150 if (0) {
1151 	alert(WinShell.Windows().Item(0).FullName);
1152 
1153 	var i, cmd, t = '', objFolder = WinShell.NameSpace(0xa), objFolderItem = objFolder
1154 			.Items().Item(), colVerbs = objFolderItem.Verbs(); // 假如出意外,objFolder==null
1155 	for (i = 0; i < colVerbs.Count; i++) {
1156 		t += colVerbs.Item(i) + '\n';
1157 		if (('' + colVerbs.Item(i)).indexOf('&R') != -1)
1158 			cmd = colVerbs.Item(i);
1159 	}
1160 	objFolderItem.InvokeVerb('' + cmd);
1161 	alert('Commands:\n' + t);
1162 
1163 	// objShell.NameSpace(FolderFrom).CopyHere(FolderTo,0); // copy folder
1164 	// objFolderItem=objShell.NameSpace(FolderFrom).ParseName("clock.avi");objFolderItem.Items().Item().InvokeVerb([動作]);
1165 	// objShell.NameSpace(FolderFromPath).Items.Item(mName).InvokeVerb();
1166 
1167 	// Sets or gets the date and time that a file was last modified.
1168 	// http://msdn.microsoft.com/en-us/library/bb787825(VS.85).aspx
1169 	// objFolderItem.ModifyDate = "01/01/1900 6:05:00 PM";
1170 	// objShell.NameSpace("C:\Temp").ParseName("Test.Txt").ModifyDate =
1171 	// DateAdd("d", -1, Now()) CDate("19 October 2007")
1172 
1173 	// Touch displays or sets the created, access, and modified times of one or
1174 	// more files. http://www.stevemiller.net/apps/
1175 }
1176 
1177 //	測試可寫入的字元:0-128,最好用1-127,因為許多編輯器會將\0轉成' ',\128又不確定
1178 if (0) {
1179 	var t = '', f = 'try.js', i = 0;
1180 	for (; i < 128; i++)
1181 		t += String.fromCharCode(i);
1182 	if (simpleWrite(f, t))
1183 		alert('Write error!\n有此local無法相容的字元?');
1184 	else if (simpleRead(f) != t)
1185 		alert('內容不同!');
1186 	else if (simpleWrite(f, dQuote(t) + ';'))
1187 		alert('Write error 2!\n有此local無法相容的字元?');
1188 	else if (eval(simpleRead(f)) != t)
1189 		alert('eval內容不同!');
1190 	else
1191 		alert('OK!');
1192 }
1193 */
1194 
1195 
1196 if(_library_onload)
1197 	_library_onload();
1198 
1199 
1200 })()	//	(function(){
1201 //)	//	void(
1202 ;
1203 
1204 
1205 //}catch(e){WScript.Echo('There are some error in function.js!\n'+e.message);throw e;}
1206 
1207 
1208 
1209 
1210 
1211 //CeL.use('code.log');
1212 //CeL.warn('test_print: ' + CeL.code.log.Class);
1213 
1214 //]]>
1215 
1216 
1217 
1218 if (typeof CeL === 'function'){
1219 
1220 /**
1221  * 本 module 之 name(id),<span style="text-decoration:line-through;">不設定時會從呼叫時之 path 取得</span>。
1222  * @type	String
1223  * @constant
1224  * @inner
1225  * @ignore
1226  */
1227 var module_name = 'IO.Windows.file';
1228 
1229 //===================================================
1230 /**
1231  * 若欲 include 整個 module 時,需囊括之 code。
1232  * @type	Function
1233  * @param	{Function} library_namespace	namespace of library
1234  * @param	load_arguments	呼叫時之 argument(s)
1235  * @return
1236  * @name	CeL.IO.Windows.file
1237  * @constant
1238  * @inner
1239  * @ignore
1240  */
1241 var code_for_including = function(library_namespace, load_arguments) {
1242 
1243 
1244 /**
1245  * null module constructor
1246  * @class	Windows 下,檔案操作相關之 function。
1247  */
1248 CeL.IO.Windows.file
1249 = function() {
1250 	//	null module constructor
1251 };
1252 
1253 /**
1254  * for JSDT: 有 prototype 才會將之當作 Class
1255  */
1256 CeL.IO.Windows.file
1257 .prototype = {
1258 };
1259 
1260 
1261 
1262 /*
1263 	JScript only	-------------------------------------------------------
1264 */
1265 
1266 CeL.IO.Windows.file
1267 .
1268 /**
1269  * FileSystemObject Object I/O mode enumeration
1270  * @see	<a href="http://msdn.microsoft.com/en-us/library/314cz14s%28VS.85%29.aspx" accessdate="2009/11/28 17:42" title="OpenTextFile Method">OpenTextFile Method</a>
1271  * @memberOf	CeL.IO.Windows.file
1272  */
1273 iomode = {
1274 	// * @_description <a href="#.iomode">iomode</a>: Open a file for reading only. You can't write to this file.
1275 	/**
1276 	 * Open a file for reading only. You can't write to this file.
1277 	 * @memberOf	CeL.IO.Windows.file
1278 	 */
1279 	ForReading : 1,
1280 	/**
1281 	 * Open a file for writing.
1282 	 * @memberOf	CeL.IO.Windows.file
1283 	 */
1284 	ForWriting : 2,
1285 	/**
1286 	 * Open a file and write to the end of the file.
1287 	 * @memberOf	CeL.IO.Windows.file
1288 	 */
1289 	ForAppending : 8
1290 };
1291 
1292 CeL.IO.Windows.file
1293 .
1294 /**
1295  * FileSystemObject Object file open format enumeration
1296  * @see	<a href="http://msdn.microsoft.com/en-us/library/314cz14s%28VS.85%29.aspx" accessdate="2009/11/28 17:42" title="OpenTextFile Method">OpenTextFile Method</a>
1297  * @memberOf	CeL.IO.Windows.file
1298  */
1299 open_format = {
1300 	/**
1301 	 * Opens the file using the system default.
1302 	 * @memberOf	CeL.IO.Windows.file
1303 	 */
1304 	TristateUseDefault : -2,
1305 	/**
1306 	 * Opens the file as Unicode.
1307 	 * @memberOf	CeL.IO.Windows.file
1308 	 */
1309 	TristateTrue : -1,
1310 	/**
1311 	 * Opens the file as ASCII.
1312 	 * @memberOf	CeL.IO.Windows.file
1313 	 */
1314 	TristateFalse : 0
1315 };
1316 
1317 
1318 var path_separator = library_namespace.env.path_separator, path_separator_RegExp = library_namespace.env.path_separator_RegExp, new_line = library_namespace.env.new_line, WshShell,
1319 /**
1320  * FileSystemObject
1321  */
1322 fso = WScript.CreateObject("Scripting.FileSystemObject"),
1323 // XMLHttp,
1324 WinShell // initWScriptObj
1325 , args, ScriptHost;
1326 
1327 
1328 /*	↑JScript only	-------------------------------------------------------
1329 */
1330 
1331 
1332 
1333 
1334 /*
1335 
1336 return {Object} report
1337 	.list	files matched
1338 	.succeed	success items
1339 	.failed	failed items
1340 	.log	log text
1341 	.undo	undo data
1342 
1343 usage example:
1344 	move_file()	get file list array of current dir.
1345 	move_file(0,0,'dir')	get file list array of dir.
1346 	move_file('*.*','*.jpg','dir')	Error! Please use RegExp('.*\..*') or turnWildcardToRegExp('*.*')
1347 	move_file(/file(\d+).jpg/,0,'dir')	get file list array of dir/file(\d+).jpg
1348 	move_file(f1,move_file.f.remove)	delete f1
1349 	move_file('f1','f2')	[f1]->[f2]
1350 	move_file('f1','f2','.',move_file.f.copy|move_file.f.reverse)	copy [./f2] to [./f1]
1351 	move_file(/file(\d+).jpg/,/file ($1).jpg/,'dir')	[dir/file(\d+).jpg]->[dir/file ($1).jpg]	can't use fuzzy or reverse in this time
1352 
1353 prog example:
1354 	function move_file_filter(fn){var n=fn.match(/0000(\d+)\(\d\)\.pdf/);if(!n)return true;n=n[1];if(n!=0&&n!=1&&n!=7&&n!=10&&n!=13&&n!=15&&n!=26&&n!=28)return true;try{n=fn.match(/(\d+)\(\d\)\.pdf/);FileSystemObject.MoveFile(n[1]+'('+(n[1]?vol-1:vol-2)+').pdf',n[1]+'.pdf');}catch(e){}return;}
1355 	var vol=11,doMove=move_file(new RegExp('(\\d+)\\('+vol+'\\)\\.pdf'),'$1.pdf');
1356 	write_to_file('move.log','-'.x(60)+new_line+doMove.log,open_format.TristateTrue,ForAppending);
1357 	write_to_file('move.undo.'+vol+'.txt',doMove.undo,open_format.TristateTrue),write_to_file('move.undo.'+vol+'.bat',doMove.undo);//bat不能用open_format.TristateTrue
1358 	alert('Done '+doMove.succeed+'/'+doMove.list.length);
1359 
1360 	for Win98, turn lower case:
1361 	move_file(/^[A-Z\d.]+$/,function($0){return '_mv_tmp_'+$0.toLowerCase();},'.',move_file.f.include_folder|move_file.f.include_subfolder);
1362 	alert(move_file(/^_mv_tmp_/,'','.',move_file.f.include_folder|move_file.f.include_subfolder).log);
1363 
1364 
1365 for(var i=0,j,n,m;i<40;i++)
1366  if(!fso.FileExists(n='0000'+(i>9?'':'0')+i+'.pdf'))for(j=0;j<25;j++)
1367   if(fso.FileExists(m='0000'+(i>9?'':'0')+i+'('+j+').pdf')){try{fso.MoveFile(m,n);}catch(e){}break;}
1368 
1369 TODO:
1370 move newer	把新檔移到目的地,舊檔移到 bak。
1371 
1372 */
1373 CeL.IO.Windows.file
1374 .
1375 /**
1376  * move/rename files, ** use RegExp, but no global flag **<br/>
1377  * 可用 move_file_filter() 來排除不要的<br/>
1378  * 本函數可能暫時改變目前工作目錄!
1379  * @param from
1380  * @param to
1381  * @param base_path
1382  * @param flag
1383  * @param {Function} filter	可用 filter() 來排除不要的
1384  * @return	{Object} report
1385  * @since	2004/4/12 17:25
1386  * @requires	path_separator,fso,WshShell,new_line,Enumerator
1387  * @memberOf	CeL.IO.Windows.file
1388  */
1389 move_file = function(from, to, base_path, flag, filter) {
1390 	var _s = arguments.callee, _f = _s.f
1391 	// '.?': 一定會match
1392 	default_from = new RegExp('.?'), t, CurrentDirectory, report = {};
1393 	// alert(typeof from+','+from.constructor);
1394 	if (flag & _f.reverse)
1395 		//flag-=_f.reverse,
1396 		t = from, from = to, to = t;
1397 	if (!from)
1398 		from = default_from;
1399 	else if (typeof from != 'string'
1400 		&& (typeof from != 'object' || !(from instanceof RegExp)
1401 				&& !(from = '' + from)))
1402 		from = default_from;
1403 	report.list = [], report.succeed = report.failed = 0,
1404 	report.undo = report.log = '';
1405 
1406 	if (!base_path)
1407 		base_path = '.' + path_separator;
1408 	else if (typeof get_folder === 'function')
1409 		base_path = get_folder(base_path);
1410 
1411 	if ((base_path = '' + base_path).slice(
1412 			// -1, or try: base_path.length-path_separator.length
1413 			-1) != path_separator)
1414 		base_path += path_separator;
1415 
1416 	if (typeof fso === 'undefined')
1417 		fso = new ActiveXObject("Scripting.FileSystemObject");
1418 	else if (typeof fso !== 'object')
1419 		throw new Error(1, 'fso was already seted!');
1420 	try {
1421 		dir = fso.GetFolder(base_path);
1422 	} catch (e) {
1423 		throw new Error(e.number,
1424 				'move_file(): 基準路徑不存在\n' + e.description);
1425 	}
1426 
1427 	// TODO: 對from不存在與為folder之處裡:fuzzy
1428 
1429 	if (flag & _f.include_subfolder) {
1430 		CurrentDirectory = WshShell.CurrentDirectory;
1431 		for ( var i = new Enumerator(dir.SubFolders); !i.atEnd(); i
1432 		.moveNext())
1433 			_s(from, to, i.item(), flag);
1434 		if (base_path)
1435 			// 改變目前工作目錄
1436 			WshShell.CurrentDirectory = base_path;
1437 	}
1438 	// if(flag&_f.include_folder){}
1439 	var i, f = new Enumerator(dir.Files), use_exact = typeof from === 'string', overwrite = flag
1440 	& _f.overwrite, not_test = !(flag & _f.Test), func = flag
1441 	& _f.copy ? 'copy' : to === _f.remove || flag & _f.remove
1442 			&& !to ? 'delete' : from != default_from || to ? 'move'
1443 					: 'list';
1444 	// if(func=='delete')to=_f.remove; // 反正不是用這個判別的
1445 	//alert('use_exact: '+use_exact+'\nbase_path: '+base_path+'\nfrom: '+from);
1446 	// BUG: 這樣順序會亂掉,使得 traverse (遍歷)不完全
1447 	for (; !f.atEnd(); f.moveNext())
1448 		if (i = f.item(), use_exact && i.Name == from || !use_exact
1449 				&& from.test(i.Name)) {
1450 			report.list.push(i.Name);
1451 
1452 			if (typeof filter == 'function' && !filter(i.Name))
1453 				continue;
1454 			t = func == 'copy' || func == 'move' ? i.Name.replace(from,
1455 					typeof to === 'object' ? to.source : to) : '';
1456 
1457 			if (t)
1458 				try {
1459 					report.log += func + ' [' + i.Name + ']'
1460 					+ (t ? ' to [' + t + '] ' : '');
1461 					var u = '';
1462 					t = (base_path == default_from ? base_path : '')
1463 					+ t;
1464 					if (func == 'delete') {
1465 						if (not_test)
1466 							i.Delete(overwrite);
1467 					} else if (!fso.FileExists(t) || overwrite) {
1468 						if (not_test) {
1469 							if (overwrite && fso.FileExists(t))
1470 								fso.DeleteFile(t);
1471 							if (func == 'copy')
1472 								//	Copy() 用的是 FileSystemObject.CopyFile or FileSystemObject.CopyFolder, 亦可用萬用字元(wildcard characters)
1473 								i.Copy(t, overwrite);
1474 							else
1475 								i.Move(t);
1476 						}
1477 						u = 'move	' + t + '	' + i.Name + new_line;
1478 					} else {
1479 						report.log += ': target existing, ';
1480 						throw 1;
1481 					}
1482 					report.log += 'succeed.' + new_line,
1483 					report.undo += u, report.succeed++;
1484 				} catch (e) {
1485 					report.log += 'failed.' + new_line, report.failed++;
1486 				}
1487 				//alert(i.Name+','+t);
1488 		}
1489 
1490 	if (flag & _f.include_subfolder && CurrentDirectory)
1491 		WshShell.CurrentDirectory = CurrentDirectory;
1492 	report.log += new_line + (not_test ? '' : '(test)') + func + ' ['
1493 	+ from + '] to [' + to + ']' + new_line
1494 	+ (typeof gDate == 'function' ? gDate() + '	' : '')
1495 	+ 'done ' + report.succeed + '/' + report.list.length
1496 	+ new_line;
1497 	return report;
1498 };
1499 
1500 //var move_file.f;
1501 //setObjValue('move_file.f','none=0,overwrite=1,fuzzy=2,reverse=4,include_folder=8,include_subfolder=16,Test=32,copy=64,remove=128','int');
1502 CeL.IO.Windows.file
1503 .
1504 /**
1505  * <a href="#.move_file">move_file</a> 的 flag enumeration
1506  * @constant
1507  * @memberOf	CeL.IO.Windows.file
1508  */
1509 move_file.f = {
1510 		/**
1511 		 * null flag
1512 		 * @memberOf CeL.IO.Windows.file
1513 		 */
1514 		none : 0,
1515 		/**
1516 		 * overwrite target
1517 		 * @memberOf CeL.IO.Windows.file
1518 		 */
1519 		overwrite : 1,
1520 		/**
1521 		 * If source don't exist but target exist, than reverse.
1522 		 * @deprecated	TODO
1523 		 * @memberOf CeL.IO.Windows.file
1524 		 */
1525 		fuzzy : 2,
1526 		/**
1527 		 * reverse source and target
1528 		 * @memberOf CeL.IO.Windows.file
1529 		 */
1530 		reverse : 4,
1531 		/**
1532 		 * include folder
1533 		 * @memberOf CeL.IO.Windows.file
1534 		 */
1535 		include_folder : 8,
1536 		/**
1537 		 * include sub-folder
1538 		 * @memberOf CeL.IO.Windows.file
1539 		 */
1540 		include_subfolder : 16,
1541 		/**
1542 		 * Just do a test
1543 		 * @memberOf CeL.IO.Windows.file
1544 		 */
1545 		Test : 32,
1546 		/**
1547 		 * copy, instead of move the file
1548 		 * @memberOf CeL.IO.Windows.file
1549 		 */
1550 		copy : 64,
1551 		/**
1552 		 * 當 target 指定此 flag,或包含此 flag 而未指定 target 時,remove the source。
1553 		 * @memberOf CeL.IO.Windows.file
1554 		 */
1555 		remove : 128
1556 };
1557 
1558 CeL.IO.Windows.file
1559 .
1560 /**
1561  * move file
1562  * @requires	fso,get_folder,getFN,initWScriptObj
1563  * @memberOf	CeL.IO.Windows.file
1564  */
1565 mv = function(from, to, dir, onlyFN, reverse) {
1566 	if (!from || !to || from == to)
1567 		return new Error(1, 'filename error.');
1568 	var e;
1569 	dir = get_folder(dir);
1570 
1571 	if (reverse)
1572 		e = from, from = to, to = e;
1573 	e = function(_i) {
1574 		return fso.FileExists(_i) ? _i : dir ? dir
1575 				+ (onlyFN ? getFN(_i) : _i) : null;
1576 	};
1577 
1578 	try {
1579 		// alert('mv():\n'+dir+'\n\n'+e(from)+'\n→\n'+e(to));
1580 		fso.MoveFile(e(from), e(to));
1581 		return;
1582 	} catch (e) {
1583 		e.message = 'mv():\n' + from + '\n→\n' 
1584 				+ to// +'\n\n'+e.message
1585 				;
1586 		return e;
1587 	}
1588 };
1589 
1590 
1591 /*
1592 function mv(from,to,dir,onlyFN,reverse){
1593  var e,_f,_t;
1594  dir=get_folder(dir);
1595 
1596  if(reverse)e=from,from=to,to=e;
1597  _f=from;
1598  _t=to;
1599  to=0;
1600  e=function(_i){
1601   return fso.FileExists(_i)?_i:dir&&fso.FileExists(_i=dir+(onlyFN?getFN(_i):_i))?_i:0;
1602  };
1603 
1604  try{
1605   if(!(_f=e(_f)))to=1;else if(!(_t=e(_t)))to=2;
1606   else{
1607    alert('mv():\n'+dir+'\n\n'+_f+'\n→\n'+_t);
1608    fso.MoveFile(_f,_t);
1609    return;
1610   }
1611  }catch(e){return e;}
1612  return e||new Error(to,(to==1?'移動するファイルは存在しない':'移動先が既存した')+':\n'+_f+'\n→\n'+_t);
1613 }
1614 
1615 
1616 function mv(from,to,dir,onlyFN,reverse){
1617  var e,_f,_t;
1618  dir=get_folder(dir);
1619 
1620  if(reverse)e=from,from=to,to=e;
1621  _f=from,_t=to,to=e=0;
1622 
1623  try{
1624   if(!fso.FileExists(_f)&&(!dir||!fso.FileExists(_f=dir+(onlyFN?getFN(_f):_f))))to=1;
1625   else if(fso.FileExists(_t)&&(!dir||fso.FileExists(_t=dir+(onlyFN?getFN(_t):_t))))to=2;
1626   else{
1627    alert('mv():\n'+dir+'\n'+_f+'\n→\n'+_t);
1628    //fso.MoveFile(_f,_t);
1629    return;
1630   }
1631  }catch(e){}
1632  return e||new Error(to,(to==1?'移動するファイルは存在しない':'移動先が既存した')+':\n'+_f+'\n→\n'+_t);
1633 }
1634 
1635 */
1636 
1637 
1638 /*
1639 
1640 下面一行調到檔案頭
1641 var get_file_details_items,get_file_details_get_object=-62.262;
1642 */
1643 CeL.IO.Windows.file
1644 .
1645 /**
1646  * get file details (readonly)
1647  * @example
1648  * get_file_details('path');
1649  * get_file_details('file/folder name',parentDir);
1650  * get_file_details('path',get_file_details_get_object);
1651  * @see	<a href="http://msdn.microsoft.com/en-us/library/bb787870%28VS.85%29.aspx" accessdate="2009/11/29 22:52" title="GetDetailsOf Method (Folder)">GetDetailsOf Method (Folder)</a>
1652  * @memberOf	CeL.IO.Windows.file
1653  */
1654 get_file_details = function(fileObj, parentDirObj) {
1655 	var i, n, r;
1656 	// WinShell=new ActiveXObject("Shell.Application");
1657 	if (typeof WinShell == 'undefined' || !fileObj)
1658 		return;
1659 
1660 	// deal with fileObj & parentDirObj
1661 	if (parentDirObj === get_file_details_get_object)
1662 		parentDirObj = 0, n = 1;
1663 	// else n='';
1664 	if (!parentDirObj) {
1665 		// fileObj is path
1666 		if (typeof fileObj != 'string')
1667 			return;
1668 		if (i = fileObj.lastIndexOf('/') + 1)
1669 			parentDirObj = fileObj.slice(0, i - 1), fileObj = fileObj
1670 			.slice(i);
1671 		else
1672 			return;
1673 	}
1674 	if (typeof parentDirObj == 'string')
1675 		parentDirObj = WinShell.NameSpace(parentDirObj);
1676 	if (typeof fileObj == 'string' && fileObj)
1677 		fileObj = parentDirObj.ParseName(fileObj);
1678 	if (n)
1679 		// just get [(object)parentDirObj,(object)fileObj]
1680 		return [ parentDirObj, fileObj ];
1681 
1682 	// get item name
1683 	if (typeof get_file_details_items != 'object') {
1684 		get_file_details_items = [];
1685 		for (i = 0, j; i < 99; i++)
1686 			// scan cols
1687 			if (n = WinShell.NameSpace(0).GetDetailsOf(null, i))
1688 				get_file_details_items[i] = n;
1689 	}
1690 
1691 	// main process
1692 	//for(i=0,r=[];i<get_file_details_items.length;i++)
1693 	r = [];
1694 	for (i in get_file_details_items) {
1695 		//if(get_file_details_items[i])
1696 		r[get_file_details_items[i]] = r[i] = parentDirObj
1697 		.GetDetailsOf(fileObj, i);
1698 	}
1699 
1700 	return r;
1701 };
1702 
1703 
1704 
1705 
1706 CeL.IO.Windows.file
1707 .
1708 /*
1709 TODO
1710 	未來:change_attributes(path,'-ReadOnly&-Hidden&-System')
1711 
1712 下面調到檔案頭
1713 setObjValue('Attribute','Normal=0,none=0,ReadOnly=1,Hidden=2,System=4,Volume=8,Directory=16,Archive=32,Alias=64,Compressed=128','int');
1714 setObjValue('AttributeV','0=Normal,1=ReadOnly,2=Hidden,4=System,8=Volume,16=Directory,32=Archive,64=Alias,128=Compressed');
1715 */
1716 /**
1717  * 改變檔案之屬性
1718  * @param	F	file path
1719  * @param	A	attributes, 屬性
1720  * @example
1721  * change_attributes(path,'-ReadOnly');
1722  * @memberOf	CeL.IO.Windows.file
1723  */
1724 change_attributes = function(F, A) {
1725 	if (!F)
1726 		return -1;
1727 	if (typeof F === 'string')
1728 		try {
1729 			F = fso.GetFile(F);
1730 		} catch (e) {
1731 			return -2;
1732 		}
1733 	var a;
1734 	try {
1735 		a = F.Attributes;
1736 	} catch (e) {
1737 		return -3;
1738 	}
1739 	if (typeof A === 'undefined')
1740 		A = a;
1741 	else if (A === '' || A == 'Archive')
1742 		A = 32;
1743 	else if (A == 'Normal')
1744 		A = 0;
1745 	else if (isNaN(A))
1746 		if (A.charAt(0) === 'x' || A.charAt(0) === '-')
1747 			if (A = -Attribute[A.substr(1)], A && a % (A << 2))
1748 				A = a + A;
1749 			else
1750 				A = a;
1751 		else if (A = Attribute[A], A && a % (A << 2) == 0)
1752 			A = a + A;
1753 		else
1754 			A = a;
1755 	else if (AttributeV[A])
1756 		if (a % (A << 2) == 0)
1757 			A = a + A;
1758 		else
1759 			A = a;
1760 	else if (AttributeV[-A])
1761 		if (a % (A << 2))
1762 			A = a + A;
1763 		else
1764 			A = a;
1765 	if (a != A)
1766 		try {
1767 			F.Attributes = A;
1768 		} catch (e) {
1769 			popErr(e);
1770 			//	70:防寫(沒有使用權限)
1771 			return 70 == (e.number & 0xFFFF) ? -8 : -9;
1772 		}
1773 	return F.Attributes;
1774 };
1775 
1776 
1777 
1778 
1779 
1780 CeL.IO.Windows.file
1781 .
1782 /**
1783  * 開檔處理<br/>
1784  * 測試是否已開啟資料檔之測試與重新開啟資料檔
1785  * @param FN	file name
1786  * @param NOTexist	if NOT need exist
1787  * @param io_mode	IO mode
1788  * @return
1789  * @requires	fso,WshShell,iomode
1790  * @memberOf	CeL.IO.Windows.file
1791  */
1792 openDataTest = function(FN, NOTexist, io_mode) {
1793 	if (!FN)
1794 		return 3;
1795 	if (NOTexist && !fso.FileExists(FN))
1796 		return 0;
1797 	if (!io_mode)
1798 		io_mode = _.iomode.ForAppending;
1799 	for (;;)
1800 		try {
1801 			var Fs = fso.OpenTextFile(FN, ForAppending);
1802 			Fs.Close();
1803 			break;
1804 		} catch (e) {
1805 			// 對執行時檔案已經開啟之處理
1806 			//if(typeof e=='object'&&e.number&&(e.number&0xFFFF)==70)
1807 			if ((e.number & 0xFFFF) != 70) {
1808 				return pErr(e, 0,
1809 						'開啟資料檔 [<green>' + FN + '<\/>] 時發生錯誤!'),
1810 						6 == alert(
1811 								'開啟資料檔 [' + FN + ']時發生不明錯誤,\n	是否中止執行?',
1812 								0, ScriptName + ' 測試是否已開啟資料檔:發生不明錯誤!',
1813 								4 + 48) ? 1 : 0;
1814 			}
1815 			if (2 == WshShell.Popup(
1816 					'★資料檔:\n\	' + FN + '\n	無法寫入!\n\n可能原因與解決方法:\n	①資料檔已被開啟。執行程式前請勿以其他程式開啟資料檔!\n	②資料檔被設成唯讀,請取消唯讀屬性。',
1817 					0, ScriptName + ':資料檔開啟發生錯誤!', 5 + 48))
1818 				return 2;
1819 		}
1820 	return 0;
1821 };
1822 
1823 CeL.IO.Windows.file
1824 .
1825 /**
1826  * 
1827  * @param FN
1828  * @param format
1829  * @param io_mode
1830  * @return
1831  */
1832 open_template = function(FN, format, io_mode) {
1833 	/**
1834 	 * file
1835 	 * @inner
1836 	 * @ignore
1837 	 */
1838 	var F,
1839 	/**
1840 	 * file streams
1841 	 * @inner
1842 	 * @ignore
1843 	 */
1844 	Fs;
1845 	if (!io_mode)
1846 		io_mode = _.iomode.ForReading;
1847 	if (!format)
1848 		//format=autodetectEncode(FN);
1849 		format = _.open_format.TristateUseDefault;// TristateTrue
1850 	try {
1851 		F = fso.GetFile(FN);
1852 		//Fs=_.open_file(FN,format,io_mode);
1853 		Fs = F.OpenAsTextStream(io_mode, format);
1854 	} catch (e) {
1855 		// 指定的檔案不存在?
1856 		pErr(e);
1857 		// quit();
1858 	}
1859 	return Fs;
1860 };
1861 
1862 //var openOut.f;	//	default format
1863 function openOut(FN,io_mode,format){
1864  var OUT,OUTs,_f=arguments.callee.f;
1865  if(!io_mode)io_mode=_.iomode.ForWriting;
1866  if(!format)format=_f=='string'&&_f?_f:_.open_format.TristateUseDefault;
1867  try{
1868   OUT=fso.GetFile(FN);
1869  }
1870  catch(e){try{
1871   //指定的檔案不存在
1872   var tmp=fso.CreateTextFile(FN,true);
1873   tmp.Close();
1874   OUT=fso.GetFile(FN);
1875  }catch(e){pErr(e);}}
1876 
1877  try{OUTs=OUT.OpenAsTextStream(io_mode,format);}catch(e){pErr(e);}
1878 
1879  return OUTs;
1880 };
1881 
1882 
1883 
1884 
1885 
1886 
1887 
1888 //	2007/5/31 21:5:16
1889 compressF.tool={
1890 	WinRAR:{path:'"%ProgramFiles%\\WinRAR\\WinRAR.exe"',ext:'rar'
1891 		,c:{cL:'$path $cmd $s $archive -- $files',cmd:'a'	//	cL:command line, c:compress, s:switch
1892 			,s:'-u -dh -m5 -os -r -ts'	// -rr1p -s<N> -ap -as -ep1 -tl -x<f> -x@<lf> -z<f>  -p[p] -hp[p]	//	rar等
1893 			//,l:'-ilog logFN'
1894 		}
1895 		,u:{cL:'$path $cmd $archive $eF $eTo',cmd:'e'}	//	uncompress
1896 		,t:{cL:'$path $cmd $archive',cmd:'t'}	//	test
1897 	}
1898 	,'7-Zip':{path:'"%ProgramFiles%\\7-Zip\\7zg.exe"',ext:'7z'
1899 		,c:{cL:'$path $cmd $s $archive $files',cmd:'u',s:'-mx9 -ms -mhe -mmt -uy2'}	//	compress
1900 		,u:{cL:'$path $cmd $archive $eF $_e',cmd:'e',_e:function(fO){return fO.eTo?'-o'+fO.eTo:'';}}	//	uncompress
1901 		,t:{cL:'$path $cmd $archive',cmd:'t'}	//	test
1902 	}
1903 }
1904 /*
1905 test:
1906 var base='C:\\kanashimi\\www\\cgi-bin\\program\\misc\\';
1907 compress(base+'jit','_jit.htm',{tool:'7-Zip',s:''});
1908 uncompress(base+'jit',base,{tool:'7-Zip'});
1909 
1910 
1911 fO={
1912 	tool:'WinRAR'	//	or '7-Zip'
1913 	,m:'c'	//	method
1914 	,s:''	//	switch
1915 	,archive:''	//	archive file
1916 	,files=''	//	what to compress
1917 	,eTo=''	//	where to uncompress
1918 	,eF=''	//	what to uncompress
1919 	,rcL=1	//	rebuild command line
1920 }
1921 */
1922 // solid, overwrite, compressLevel, password
1923 function compressF(fO){	//	flags object
1924  // 參數檢查: 未完全
1925  if(!fO)fO={};
1926  if(typeof fO!='object')return;
1927  if(!fO.tool)fO.tool='WinRAR';
1928  //if(!fO.m)fO.m='c';//method
1929  if(!fO.m||!fO.archive&&(fO.m!='c'||fO.m=='c'&&!fO.files))return;
1930  if(fO.m=='c'){
1931   if(typeof fO.files!='object')fO.files=fO.files?[fO.files]:fO.archive.replace(/\..+$/,'');
1932   if(!fO.archive)fO.archive=fO.files[0].replace(/[\\\/]$/,'')+_t.ext;
1933   fO.files='"'+fO.files.join('" "')+'"';
1934  }
1935  var i,_t=compressF.tool[fO.tool],_m,_c;
1936  if(!_t||!(_m=_t[fO.m]))return;
1937  else if(!/\.[a-z]+$/.test(fO.archive))fO.archive+='.'+_t.ext;
1938  //if(fO.bD)fO.archive=fO.bD+(/[\\\/]$/.test(fO.bD)?'':'\\')+fO.archive;	//	base directory, work directory, base folder
1939  if(!/["']/.test(fO.archive))fO.archive='"'+fO.archive+'"';
1940  //alert('compressF(): check OK.');
1941  // 構築 command line
1942  if(_m._cL&&!fO.rcL)_c=_m._cL;	//	rebuild command line
1943  else{
1944   _c=_m.cL.replace(/\$path/,_t.path);
1945   for(i in _m)if(typeof fO[i]=='undefined')_c=_c.replace(new RegExp('\\$'+i),typeof _m[i]=='function'?_m[i](fO):_m[i]||'');
1946   _m._cL=_c;
1947   //alert('compressF():\n'+_c);
1948  }
1949  for(i in fO)_c=_c.replace(new RegExp('\\$'+i),fO[i]||'');
1950  if(_c.indexOf('$')!=-1){alert('compressF() error:\n'+_c);return;}
1951  alert('compressF() '+(_c.indexOf('$')==-1?'run':'error')+':\n'+_c);
1952  // run
1953  WshShell.Run(_c,0,true);
1954 }
1955 //compress[generateCode.dLK]='compressF';
1956 function compress(archive,files,fO){	//	compress file path, what to compress, flags object
1957  if(!fO)fO={};else if(typeof fO!='object')return;
1958  if(!fO.m)fO.m='c';
1959  if(archive)fO.archive=archive;
1960  if(files)fO.files=files;
1961  return compressF(fO);
1962 }
1963 //uncompress[generateCode.dLK]='uncompressF';
1964 function uncompress(archive,eTo,fO){	//	compress file path, where to uncompress, flags object
1965  if(!fO)fO={};else if(typeof fO!='object')return;
1966  if(!fO.m)fO.m='u';
1967  if(!fO.eF)fO.eF='';
1968  if(archive)fO.archive=archive;
1969  if(eTo)fO.eTo=eTo;
1970  return compressF(fO);
1971 };
1972 
1973 
1974 
1975 
1976 
1977 
1978 
1979 /*
1980 	轉換捷徑, 傳回shortcut的Object. true path
1981 	http://msdn2.microsoft.com/en-us/library/xk6kst2k.aspx
1982 	http://yuriken.hp.infoseek.co.jp/index3.html
1983 */
1984 var p;
1985 //dealShortcut[generateCode.dLK]='initWScriptObj';//,parseINI
1986 function dealShortcut(path,rtPath){
1987  if(typeof path!='string')path='';
1988  else if(/\.(lnk|url)$/i.test(path)){
1989   var sc=WshShell.CreateShortcut(path),p=sc.TargetPath,_i;
1990   //	檔名有可能是不被容許的字元(不一定總是有'?'),這時只有.url以文字儲存還讀得到。
1991   if(/*(''+sc).indexOf('?')!=-1*/!p&&/\.url$/i.test(path)&&typeof parseINI=='function'){
1992    p=parseINI(path,0,1);
1993    sc={_emu:p};
1994    sc.TargetPath=(p=p.InternetShortcut).URL;
1995    for(_i in p)sc[_i]=p[_i];
1996 /*
1997 URL File Format (.url)	http://www.cyanwerks.com/file-format-url.html
1998 [DEFAULT]
1999 BASEURL=http://so.7walker.net/guide.php
2000 [DOC#n(#n#n#n…)]
2001 [DOC#4#5]
2002 BASEURL=http://www.someaddress.com/frame2.html
2003 [DOC_adjustiframe]
2004 BASEURL=http://so.7walker.net/guide.php
2005 ORIGURL=http://so.7walker.net/guide.php
2006 [InternetShortcut]
2007 URL=http://so.7walker.net/guide.php
2008 Modified=50A8FD7702D1C60106
2009 WorkingDirectory=C:\WINDOWS\
2010 ShowCommand=	//	規定Internet Explorer啟動後窗口的初始狀態:7表示最小化,3表示最大化;如果沒有ShowCommand這一項的話則表示正常大小。
2011 IconIndex=1	//	IconFile和IconIndex用來為Internet快捷方式指定圖標
2012 IconFile=C:\WINDOWS\SYSTEM\url.dll
2013 Hotkey=1601
2014 
2015 Hotkey:
2016 下面加起來: Fn 單獨 || (Fn || base) 擇一 + additional 擇2~3
2017 base:
2018 0=0x30(ASCII)
2019 9=0x39(ASCII)
2020 A=0x41(ASCII)
2021 Z=0x5a(ASCII)
2022 ;=0xba
2023 =
2024 ,
2025 -
2026 .
2027 /
2028 `=0xc0
2029 [=0xdb
2030 \
2031 ]
2032 '=0xde
2033 
2034 Fn:
2035 F1=0x70
2036 ..
2037 F12=0x7b
2038 
2039 additional:
2040 Shift=0x100
2041 Ctrl=0x200
2042 Alt=0x400
2043 
2044 */
2045    p=p.URL;
2046   }
2047   if(!rtPath)return sc;
2048   path=/^file:/i.test(p)?p.replace(/^[^:]+:\/+/,'').replace(/[\/]/g,'\\'):p;	//	/\.url$/i.test(path)?'':p;
2049  }
2050  return rtPath?path:null;
2051 };
2052 
2053 //filepath=OpenFileDialog();	基於安全,IE無法指定初始值或型態
2054 //OpenFileDialog[generateCode.dLK]='IEA';
2055 function OpenFileDialog(){
2056  var IE=new IEA,o;
2057  if(!IE.OK(1))return null;
2058  IE.write('<input id="file" type="file"/>');// value="'+dP+'"	useless
2059  with(IE.getE('file'))focus(),click(),o=value;
2060  //IE.setDialog(200,400).show(1);
2061  IE.quit();
2062  return o||null;
2063 };
2064 
2065 
2066 //	是否為檔案
2067 function isFile(p,c){//file path,create
2068  if(!p)return 0;
2069  if(typeof fso=='undefined')
2070   fso=new ActiveXObject("Scripting.FileSystemObject");
2071  if(fso.FileExists(p))
2072   return true;
2073 
2074  p=getFN(p);
2075  if(c)try{c=fso.CreateTextFile(p,true);c.Close();}catch(e){}
2076  return fso.FileExists(p);
2077 };
2078 //	是否為目錄
2079 function isFolder(p,c){if(!p)return 0;//path,create	return 0:not,1:absolute,2:relative path
2080  if(fso.FolderExists(p=turnToPath(p)))return isAbsPath(p)?1:2;
2081  if(c)try{fso.CreateFolder(p);return isAbsPath(p)?1:2;}catch(e){}
2082  return 0;
2083 }
2084 //	get directory name of a path
2085 function get_folder(FP,mode){	//	mode=0:path,1:filename
2086  if(typeof FP=='object'&&typeof FP.Path=='string')
2087   if(typeof FP.IsRootFolder!='undefined')return FP.Path;
2088   else FP=FP.Path;
2089  if(typeof FP!='string')return '';
2090  //else if(/^[a-z]$/i.test(FP))FP+=':\\';
2091  //if(FP.slice(-1)!='\\')FP+='\\';
2092  var i=FP.lastIndexOf('\\');
2093  if(i==-1)i=FP.lastIndexOf('/');
2094  return i==-1?FP:mode?FP.substr(i+1):FP.slice(0,i+1);
2095 }
2096 
2097 
2098 
2099 //	取得下一個序號的檔名,如輸入pp\aa.txt將嘗試pp\aa.txt→pp\aa[pattern].txt
2100 function getNextSerialFN(FP,bs,pattern){	//	FP:file path,bs:begin serial,pattern:增添主檔名的模式,包含Ser的部分將被轉換為序號
2101  if(!FP)return;if(isNaN(bs))if(!fso.FileExists(FP))return FP;else bs=0;
2102  var i=FP.lastIndexOf('.'),base,ext,Ser=':s:';
2103  if(i==-1)base=FP,ext='';else base=FP.slice(0,i),ext=FP.substr(i);	//fso.GetBaseName(filespec);fso.GetExtensionName(path);fso.GetTempName();
2104  if(!pattern)pattern='_'+Ser;i=pattern.indexOf(Ser);
2105  if(i==-1)base+=pattern;else base+=pattern.slice(0,i),ext=pattern.substr(i+Ser.length)+ext;
2106  for(i=bs||0;i<999;i++)if(!fso.FileExists(base+i+ext))return base+i+ext;
2107  return;
2108 }
2109 
2110 
2111 CeL.IO.Windows.file
2112 .
2113 /**
2114  * 轉換以 adTypeBinary 讀到的資料
2115  * @example
2116  * //	較安全的讀檔:
2117  * t=translate_AdoStream_binary_data(read_all_file(FP,'binary'));
2118  * write_to_file(FP,t,'iso-8859-1');
2119  * @see
2120  * <a href="http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html">Hawk's W3 Laboratory : Disposable WSH : 番外編:文字エンコーディングとADODB.Stream</a>
2121  * @memberOf	CeL.IO.Windows.file
2122  */
2123 translate_AdoStream_binary_data=function(data,len,type){
2124 	var _s = arguments.callee,_i=0,charArray,val,DOM=_s.XMLDOM,pos,txt;
2125  if(!DOM)
2126   try{
2127 	DOM=_s.XMLDOM=(new ActiveXObject("Microsoft.XMLDOM")).createElement('tmp');	//	要素名は何でも良い
2128 	DOM.dataType='bin.hex';
2129   }catch(e){return;}
2130  if(data!==0)DOM.nodeTypedValue=data,txt=DOM.text,pos=0;//binary data
2131  else pos=_s.pos,txt=_s.text;
2132  if(isNaN(len)||len>txt.length/2)len=txt.length/2;
2133 
2134  if(type){
2135   for(val=0;_i<len;i++)val=0x100*val+parseInt(txt.substr(pos,2),16),pos+=2;
2136   _s.pos=pos;
2137   return val;
2138  }
2139 
2140 /*
2141  if(!(len>0)||len!=parseInt(len))
2142   alert(pos+','+_i+'==0~len='+len+','+txt.slice(0,8));
2143 */
2144  charArray=new Array(parseInt(len));	//	Error 5029 [RangeError] (facility code 10): 陣列長度必須是一有限的正整數
2145  for(;_i<len;_i++)	//	極慢!用charString+=更慢。
2146   try{
2147    //if(_i%100000==0)alert(i);
2148    //if(_i==40)alert(String.fromCharCode(parseInt(txt.substr(pos,2),16))+'\n'+charArray.join(''));
2149    charArray.push(String.fromCharCode(parseInt(txt.substr(pos,2),16))),pos+=2;
2150    //charArray[_i]=String.fromCharCode((t.charCodeAt(_i<<1)<<8)+t.charCodeAt((_i<<1)+1));
2151   }catch(e){
2152    e.description='translate_AdoStream_binary_data: 輸入了錯誤的資料:\n'+e.description;
2153    throw e;
2154   }
2155  if(!data)_s.pos=pos;
2156  return charArray.join('');
2157 };
2158 
2159 CeL.IO.Windows.file
2160 .
2161 /**
2162  * 轉換以 adTypeBinary 讀到的資料
2163  * @param	data	以 adTypeBinary 讀到的資料
2164  * @param	pos	position
2165  * @since	2007/9/19 20:58:26
2166  * @memberOf	CeL.IO.Windows.file
2167  */
2168 Ado_binary = function(data,pos){
2169  this.newDOM();
2170 
2171  if(typeof data=='string'){
2172   if(!data||typeof getFP=='function'&&!(data=getFP(data)))return;
2173   this.newFS(data);
2174   this.setPos(pos||0);
2175  }else this.setData(data,pos);
2176 };
2177 CeL.IO.Windows.file
2178 .
2179 /**
2180  * @memberOf	CeL.IO.Windows.file
2181  */
2182 Ado_binary.prototype={
2183 /**
2184  * 設定 data
2185  * 
2186  * @param data	binary data
2187  * @param pos
2188  * @return
2189  * @memberOf	CeL.IO.Windows.file
2190  */
2191 setData : function(data, pos) {
2192 	this.DOM.nodeTypedValue = data,// binary data
2193 	this.bt = this.DOM.text;// binary text
2194 	if (!this.AdoS)
2195 		this.len = this.bt.length / 2;
2196 	this.setPos(pos || 0);
2197 },
2198 setPos : function(p) {
2199 	if (!isNaN(p)) {
2200 		if (p < 0)
2201 			p = 0;
2202 		else if (p > this.len)
2203 			p = this.len;
2204 		this.pos = p;
2205 	}
2206 	return this.pos;
2207 },
2208 testLen : function(len) {
2209 	if (!len || len < 0)
2210 		len = this.len;
2211 	if (this.pos + len > this.len)
2212 		len = this.len - this.pos;
2213 	return len;
2214 },
2215 /**
2216  * read data
2217  * @private
2218  * @param len	length
2219  * @return
2220  * @memberOf	CeL.IO.Windows.file
2221  */
2222 readData : function(len) {
2223 	this.AdoS.Position = this.pos;
2224 	var _data = this.AdoS.Read(len);
2225 	//	讀 binary data 用 'iso-8859-1' 會 error encoding.
2226 	this.setData(_data, this.AdoS.Position);
2227 },
2228 read : function(len) {
2229 	var charArray = new Array(len = this.testLen(len)), _i = 0;
2230 	this.readData(len);
2231 	for (; _i < len; _i++)
2232 		try {
2233 			charArray.push(String.fromCharCode(parseInt(this.bt
2234 					.substr(2 * _i, 2), 16)));
2235 			// charArray[i]=String.fromCharCode((t.charCodeAt(i<<1)<<8)+t.charCodeAt((i<<1)+1));
2236 		} catch (e) {
2237 			this.retErr(e);
2238 		}
2239 		return charArray.join('');
2240 },
2241 readNum : function(len) {
2242 	len = this.testLen(len);
2243 	this.readData(len);
2244 	var val = 0, _i = len;
2245 	for (; _i > 0;)
2246 		try {
2247 			val = 0x100 * val
2248 			+ parseInt(this.bt.substr(2 * (--_i), 2), 16);
2249 		} catch (e) {
2250 			this.retErr(e);
2251 		}
2252 		return val;
2253 },
2254 readHEX : function(len) {
2255 	len = this.testLen(len);
2256 	this.readData(len);
2257 	return this.bt;
2258 },
2259 retErr : function(e) {
2260 	e.description = 'translate_AdoStream_binary_data: 輸入了錯誤的資料:\n' + e.description;
2261 	throw e;
2262 },
2263 /**
2264  * @private
2265  * @return
2266  * @memberOf	CeL.IO.Windows.file
2267  */
2268 newDOM : function() {
2269 	this.DOM = null;
2270 	// try{
2271 	this.DOM = (new ActiveXObject("Microsoft.XMLDOM"))
2272 	.createElement('tmp' + Math.random()); // 要素名は何でも良い
2273 	// }catch(e){return;}
2274 	this.DOM.dataType = 'bin.hex';
2275 },
2276 /**
2277  * @private
2278  * @param FP
2279  * @return
2280  * @memberOf	CeL.IO.Windows.file
2281  */
2282 newFS : function(FP) {
2283 	if (FP)
2284 		this.FP = FP;
2285 	else if (!(FP = this.FP))
2286 		return;
2287 	var _i = _.open_file.returnADO;
2288 	_.open_file.returnADO = true;
2289 	this.AdoS = _.open_file(FP, 'binary');
2290 	_.open_file.returnADO = _i;
2291 	if (!this.AdoS)
2292 		return;
2293 	this.AdoS.LoadFromFile(FP);
2294 	this.len = this.AdoS.Size;
2295 },
2296 /**
2297  * 實際上沒多大效用。實用解決法:少用 AdoStream.Write()
2298  * @return
2299  * @memberOf	CeL.IO.Windows.file
2300  */
2301 renew : function() {
2302 	this.bt = this.data = 0;
2303 	this.newDOM();
2304 	if (this.AdoS && this.FP) {
2305 		this.pos = this.AdoS.Position;
2306 		this.AdoS.Close();
2307 		this.AdoS = null;
2308 		this.newFS();
2309 	}
2310 },
2311 destory : function(e) {
2312 	if (this.AdoS)
2313 		this.AdoS.Close();
2314 	this.AdoS = this.pos = this.bt = this.data = 0;
2315 }
2316 }; //	Ado_binary.prototype={
2317 
2318 
2319 /*
2320 //	速度過慢,放棄。
2321 //_.open_file.returnADO=true;
2322 function dealBinary(FP,func,interval){
2323  var t,fs=_.open_file(FP,'binary',ForReading);
2324  if(!fs)return;
2325  AdoStream.LoadFromFile(FP);
2326  if(!interval)interval=1;
2327  //alert(fs.size)
2328  while(!fs.EOS)
2329   if(func(translate_AdoStream_binary_data(fs.Read(interval))))return;
2330  func();
2331  fs.Close();
2332 }
2333 */
2334 
2335 /*	配合simple系列使用
2336 http://thor.prohosting.com/~mktaka/html/utf8.html
2337 http://www.andrewu.co.uk/webtech/comment/?703
2338 http://www.blueidea.com/bbs/NewsDetail.asp?id=1488978
2339 http://www.blueidea.com/bbs/NewsDetail.asp?GroupName=WAP+%BC%BC%CA%F5%D7%A8%C0%B8&DaysPrune=5&lp=1&id=1524739
2340 C#	http://www.gotdotnet.com/team/clr/bcl/TechArticles/TechArticles/IOFAQ/FAQ.aspx
2341 http://www.sqlxml.org/faqs.aspx?faq=2
2342 http://www.imasy.or.jp/~hir/hir/tech/js_tips.html
2343 
2344 ADODB.Stream	最大問題:不能append
2345 http://msdn2.microsoft.com/en-us/library/ms808792.aspx
2346 http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoenumerations.asp
2347 http://study.99net.net/study/web/asp/1067048121.html	http://www.6to23.com/s11/s11d5/20031222114950.htm
2348 http://blog.csdn.net/dfmz007/archive/2004/07/23/49373.aspx
2349 */
2350 var AdoStream,AdoEnums;	//	ADO Enumerated Constants	http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoenumerations.asp
2351 /*	搬到前面
2352 setObjValue('AdoEnums','adTypeBinary=1,adTypeText=2'	//	StreamTypeEnum
2353 +',adReadAll=-1,adReadLine=-2'	//	StreamReadEnum	http://msdn2.microsoft.com/en-us/library/ms806462.aspx
2354 +',adSaveCreateNotExist=1,adSaveCreateOverWrite=2'	//	SaveOptionsEnum
2355 +',adCR=13,adCRLF=-1,adLF=10'	//	LineSeparatorsEnum
2356 ,'int');
2357 */
2358 AdoEnums = {
2359 	adTypeBinary : 1,
2360 	adTypeText : 2,
2361 	adReadAll : -1,
2362 	adReadLine : -2,
2363 	adSaveCreateNotExist : 1,
2364 	adSaveCreateOverWrite : 2,
2365 	adCR : 13,
2366 	adCRLF : -1,
2367 	adLF : 10
2368 };
2369 
2370 
2371 //_.open_file[generateCode.dLK]='AdoEnums,simpleFileErr,ForReading,ForWriting,ForAppending,TristateUseDefault';//AdoStream
2372 CeL.IO.Windows.file
2373 .
2374 /**
2375  * 提供給 <a href="#.read_all_file">read_all_file</a>, <a href="#.write_to_file">write_to_file</a> 使用的簡易開檔函數
2376  * @param FN	file path
2377  * @param format	open format, e.g., open_format.TristateUseDefault
2378  * @param io_mode	open mode, e.g., iomode.ForWriting
2379  * @memberOf	CeL.IO.Windows.file
2380  */
2381 open_file=function(FN,format,io_mode){
2382  //if(!FN||typeof isAbsPath=='function'&&typeof getFN=='function'&&!isAbsPath(FN)&&!(FN=getFN(FN)))return;
2383  //if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return;
2384 	var _s = arguments.callee;
2385  if(typeof format=='string'){
2386   if(!_s.returnADO&&typeof AdoStream!='undefined')
2387    try{AdoStream.Close();AdoStream=null;}catch(e){}
2388   try{
2389    AdoStream=new ActiveXObject("ADODB.Stream");//var objStream=Server.CreateObject("ADODB.Stream");	//	ASPの場合,Err.Number=-2147221005表不支援
2390   }catch(e){simpleFileErr=e;AdoStream=null;}
2391   if(AdoStream){
2392    //AdoStream.Mode=3;	//	read write
2393    if(format=='binary')AdoStream.Type=AdoEnums.adTypeBinary;	//	以二進位方式操作
2394    else{
2395     AdoStream.Type=AdoEnums.adTypeText;
2396     try{AdoStream.Charset=format;}catch(e){throw new Error(e.number,'open_file: Error format:\n	('+typeof format+') ['+format+']\n'+e.description);}	//	UTF-8,unicode,shift_jis,Big5,GB2312,ascii=iso-8859-1,_autodetect,_autodetect_all..	HKEY_CLASSES_ROOT\MIME\Database\Charset
2397    }
2398    AdoStream.Open();
2399    //AdoStream.Position=0,AdoStream.LineSeparator=AdoEnums.adLF;
2400    if(_s.returnADO){var _A=AdoStream;AdoStream=null;return _A;}
2401    return 0;
2402   }
2403   format=0;
2404  }
2405  var fs;
2406  //	使用某些防毒軟體(如諾頓 Norton)時,.OpenTextFile() 可能會被攔截,因而延宕。
2407  try{
2408   if(io_mode==_.iomode.ForAppending&&!fso.FileExists(FN))io_mode=_.iomode.ForWriting;	//	無此檔時改 writing
2409   fs=fso.OpenTextFile(FN,io_mode||_.iomode.ForReading,io_mode==_.iomode.ForWriting/*create*/,format||_.open_format.TristateUseDefault);
2410  }catch(e){
2411   simpleFileErr=e;
2412   try{fs.Close();}catch(e){}
2413   return -1;
2414  }
2415  return fs;
2416 };
2417 CeL.IO.Windows.file
2418 .open_file.returnADO=false;
2419 CeL.IO.Windows.file
2420 .open_file.error;
2421 
2422 //	若是僅使用普通的開檔方法(_.open_format.TristateTrue/_.open_format.TristateFalse等,不使用ADODB.Stream),直接引用下兩函數與fso段定義即可。否則還需要引入_.open_file(),setObjValue(),dQuote()
2423 var simpleFileErr,simpleFileAutodetectEncode=-5.4,simpleFileDformat=_.open_format.TristateUseDefault;//_autodetect	autodetectEncode(file)
2424 //_.read_all_file[generateCode.dLK]=_.write_to_file[generateCode.dLK]='simpleFileErr,simpleFileAutodetectEncode,simpleFileDformat,initWScriptObj';//_.open_file,autodetectEncode,getFP,_.open_format.TristateUseDefault
2425 //_.read_all_file[generateCode.dLK]+=',ForReading';_.write_to_file[generateCode.dLK]+=',ForWriting';
2426 //_.read_all_file[generateCode.dLK]+=',translate_AdoStream_binary_data';	//	for _.read_all_file(FP,'binary')
2427 CeL.IO.Windows.file
2428 .
2429 /**
2430  * 讀取檔案
2431  * @param FN	file path
2432  * @param format	open encode = simpleFileDformat
2433  * @param io_mode	open IO mode = ForReading
2434  * @param func	do this function per line, or [func, maxsize] (TODO)
2435  * @return {String} 檔案內容
2436  * @memberOf	CeL.IO.Windows.file
2437  */
2438 read_all_file=function(FN,format,io_mode,func){
2439  simpleFileErr=0;if(format==simpleFileAutodetectEncode)
2440   format=typeof autodetectEncode=='function'?autodetectEncode(FN):simpleFileDformat;
2441  if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return;
2442  //var a,fs;try{fs=fso.OpenTextFile(FN,io_mode||_.iomode.ForReading,false,format||simpleFileDformat),a=fs.ReadAll(),fs.Close();}catch(e){simpleFileErr=e;return;}
2443  var a,fs;//,i,s=0,t;
2444  if(typeof _.open_file!='function')
2445   //{if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return;
2446   try{fs=fso.OpenTextFile(FN,io_mode||_.iomode.ForReading,false/*create*/,format||simpleFileDformat);}
2447   catch(e){simpleFileErr=e;return;}
2448  else if(fs=_.open_file(FN,format||simpleFileDformat,io_mode||_.iomode.ForReading),fs===-1)return;
2449 
2450  //if(func instanceof Array)s=func[1],func=func[0];
2451  if(fs!==0)try{
2452   if(func)
2453    while(!fs.AtEndOfStream)func(fs.ReadLine());
2454 /*
2455    while(!fs.AtEndOfStream){
2456     for(t='',i=0;!fs.AtEndOfStream&&(!t||i<s);i++)
2457      t+=fs.ReadLine();
2458     a+=func(t);
2459    }
2460 */
2461   else a=fs.ReadAll();
2462   fs.Close();
2463  }catch(e){simpleFileErr=e;try{fs.Close();}catch(e){}return;}
2464  else if(typeof AdoStream!='undefined'&&AdoStream)
2465   try{
2466    AdoStream.LoadFromFile(FN);
2467    if(AdoStream.Type==AdoEnums.adTypeBinary){
2468     a=AdoStream.Read(AdoEnums.adReadAll);	//	讀 binary data 用 'iso-8859-1' 會 error encoding.
2469     if(_.read_all_file.turnBinToStr&&typeof translate_AdoStream_binary_data=='function')a=translate_AdoStream_binary_data(a);
2470    }else if(func)
2471     while(!AdoStream.EOS)func(AdoStream.ReadText(AdoEnums.adReadLine));
2472 /*
2473     while(!AdoStream.EOS){
2474      for(t='',i=0;!AdoStream.AtEndOfStream&&(!t||i<s);i++)
2475       t+=AdoStream.ReadText(AdoEnums.adReadLine);
2476      a+=func(t);
2477     }
2478 */
2479    else a=AdoStream.ReadText(AdoEnums.adReadAll);
2480    AdoStream.Close();
2481   }catch(e){
2482    simpleFileErr=e;
2483    try{AdoStream.Close();}catch(e){}
2484    return;
2485   }
2486  else simpleFileErr=new Error(1,'unknown error!'),simpleFileErr.name='unknownError';
2487  return a;
2488 };
2489 CeL.IO.Windows.file
2490 .read_all_file.turnBinToStr=true;
2491 
2492 
2493 CeL.IO.Windows.file
2494 .
2495 /**
2496  * 將 content 寫入 file
2497  * ** ADODB.Stream does not support appending!
2498  * @param FN	file path
2499  * @param content	content to write
2500  * @param format	open format = simpleFileDformat
2501  * @param io_mode	write mode = ForWriting, e.g., ForAppending
2502  * @param N_O	DO NOT overwrite
2503  * @return error No.
2504  * @memberOf	CeL.IO.Windows.file
2505  */
2506 write_to_file = function(FN, content, format, io_mode, N_O) {
2507 	simpleFileErr = 0;
2508 	if (format == simpleFileAutodetectEncode)
2509 		format = typeof autodetectEncode == 'function' ? autodetectEncode(FN)
2510 				: simpleFileDformat;
2511 		if (!FN || typeof getFP == 'function' && !(FN = getFP(FN)))
2512 			return 2;
2513 		//var fs;try{fs=fso.OpenTextFile(FN,iomode||ForWriting,true,format||TristateUseDefault);}catch(e){return 2;}if(!fs)return 3;
2514 		//try{fs.Write(content);}catch(e){return e.number&0xFFFF==5?5:4;}	//	5:content中有此local無法相容的字元,例如在中文中寫入日文假名
2515 		var fs;
2516 		if (typeof _.open_file != 'function')
2517 			// {if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return 2;
2518 			try {
2519 				fs = fso.OpenTextFile(FN, io_mode || _.iomode.ForWriting,
2520 						true/* create */, format || simpleFileDformat);
2521 				if (!fs)
2522 					return 3;
2523 			} catch (e) {
2524 				simpleFileErr = e;
2525 				return 2;
2526 			}
2527 			else if (fs = _.open_file(FN, format || simpleFileDformat, io_mode
2528 					|| _.iomode.ForWriting), fs === -1)
2529 				return 3;
2530 			else if (!fs && isNaN(fs))
2531 				return 2;
2532 		if (fs !== 0)
2533 			try {
2534 				fs.Write(content);
2535 				fs.Close();
2536 			} catch (e) {
2537 				simpleFileErr = e;
2538 				try {
2539 					fs.Close();
2540 				} catch (e) {
2541 				}
2542 				return simpleFileErr.number & 0xFFFF == 5 ? 5 : 4;
2543 			}
2544 			// AdoStream.SaveToFile()需在AdoStream.Write之後!
2545 			else if (typeof AdoStream != 'undefined' && AdoStream)
2546 				try {
2547 					if (AdoStream.Type == AdoEnums.adTypeText)
2548 						AdoStream.WriteText(content);
2549 					else
2550 						AdoStream.Write(content);
2551 					AdoStream.SaveToFile(FN, io_mode
2552 							|| AdoEnums.adSaveCreateOverWrite);
2553 					AdoStream.Close();
2554 				} catch (e) {
2555 					simpleFileErr = e;
2556 					try {
2557 						AdoStream.Close();
2558 					} catch (e) {
2559 					}
2560 					return 6;
2561 				}
2562 				else {
2563 					simpleFileErr = new Error(1, 'unknown error!'),
2564 					simpleFileErr.name = 'unknownError';
2565 					return 1;
2566 				}
2567 };
2568 
2569 //	TODO: unfinished
2570 //simpleDealFile[generateCode.dLK]='autodetectEncode,_.read_all_file,_.write_to_file';
2571 CeL.IO.Windows.file
2572 .
2573 simpleDealFile=function(inFN,func,outFN,format,io_mode,N_O){
2574  if(!inFN)return;
2575  if(!outFN)outFN=inFN;
2576  var e=autodetectEncode(inFN),i=_.read_all_file(inFN,e),o=_.read_all_file(outFN,e),t=func(i,inFN);
2577  if(typeof t=='string'&&o!=t)return _.write_to_file(outFN,t,e,N_O);
2578 };
2579 
2580 /*
2581 var autodetectEncodeSP,autodetectEncodeCode;	//	特殊字元,各種編碼及判別所需最短長度
2582 setObjValue('autodetectEncodeSP','3005=J,3006=J,3402=J,3447=C,3468=J,3473=C,359e=C,360e=C,361a=C,3918=C,396e=C,39cf=C,39d0=C,39df=C,3a73=C,3b4e=C,3b77=J,3c6e=C,3ce0=C,3f57=J,4056=C,415f=C,42c6=J,4302=J,4337=C,43ac=C,43b1=C,43dd=C,44be=J,44d4=J,44d6=C,464c=C,4661=C,4723=C,4729=C,477c=C,478d=C,4947=C,497a=C,497d=C,'
2583 +'4982=C,4983=C,4985=C,4986=C,499b=C,499f=C,49b0=J,49b6=C,49b7=C,4c77=C,4c9f=C,4ca0=C,4ca1=C,4ca2=C,4ca3=C,4d13=C,4d14=C,4d15=C,4d16=C,4d17=C,4d18=C,4d19=C,4dae=C,4e12=J,4e13=C,4e1a=C,4e1b=C,4e1c=C,4e1d=C,4e24=C,4e25=C,4e27=C,4e28=J,4e2a=C,4e34=C,4e3a=C,4e3c=J,4e3d=C,4e3e=C,4e49=C,'
2584 +'4e4c=C,4e50=C,4e54=C,4e60=C,4e61=C,4e62=J,4e66=C,4e70=C,4e71=C,4e8f=C,4e9a=C,4ea7=C,4ea9=C,4eb2=C,4eb5=C,4ebf=C,4ec5=C,4ece=C,4ed0=J,4ed1=C,4ed3=C,4eea=C,4eec=C,4f17=C,4f1b=C,4f1d=J,4f1e=C,4f1f=C,4f20=C,4f24=C,4f25=C,4f26=C,4f27=C,4f2a=C,4f65=C,4f66=J,4fa0=C,4fa1=J,4fa4=J,4fa5=C,'
2585 +'4fa6=C,4fa7=C,4fa8=C,4fa9=C,4faa=C,4fac=C,4fb0=J,4fe3=J,4fe4=J,4fe5=J,4fe6=C,4fe7=J,4fe8=C,4fe9=C,4fea=C,4fed=C,5039=J,503a=C,503b=J,503e=C,5051=J,507b=C,507e=C,507f=C,50a5=C,50a7=C,50a8=C,50a9=C,50cd=J,50de=C,50f2=J,5170=C,5173=C,5174=C,517b=C,517d=C,5181=C,5188=C,5199=C,519b=C,'
2586 +'519c=C,51af=C,51b2=C,51bb=C,51e4=C,51e7=J,51e9=J,51ea=J,51eb=C,51ed=C,51ee=J,51ef=C,51fb=C,51ff=C,520d=C,5218=C,5219=C,521a=C,521b=C,522b=C,522c=C,522d=C,523d=C,523f=C,5240=C,5242=C,5250=C,5251=C,5257=C,5267=C,5273=C,529d=C,529e=C,52a1=C,52a8=C,52b1=C,52b2=C,52b3=C,52bf=C,52cb=C,'
2587 +'52da=C,5301=J,5302=J,5307=J,5326=C,532e=C,533b=C,534e=C,534f=C,5355=C,5356=C,5362=C,5364=C,536b=C,5385=C,5386=C,5389=C,538b=C,538c=C,538d=C,5395=C,53a0=C,53a3=C,53bf=C,53c2=C,53c6=C,53c7=C,53cc=C,53d1=C,53d8=C,53f6=C,53f7=C,53f9=C,53fa=J,53fd=C,540b=J,5413=C,5417=C,542f=C,544e=J,'
2588 +'544f=J,5452=C,5453=C,5455=C,5456=C,5457=C,5458=C,545b=C,545c=C,5484=J,5491=J,5499=C,549b=C,549c=J,549d=C,54cd=C,54d1=C,54d2=C,54d3=C,54d4=C,54d5=C,54d7=C,54d8=J,54d9=C,54dd=C,54df=C,54e9=J,5500=J,551b=C,551d=C,5520=C,5521=C,5522=C,5553=C,5567=C,556c=C,556d=C,556e=C,5570=C,5578=C,'
2589 +'55b0=J,55b7=C,55bd=C,55be=C,55eb=C,55f3=C,5624=C,5631=C,565c=C,565d=C,5678=J,567a=J,56a3=C,56c9=J,56ce=J,56e2=C,56ed=C,56f2=J,56f4=C,56f5=C,56fe=C,5706=C,5715=J,5726=J,5737=J,5738=J,5739=C,573a=C,5746=J,5757=C,575a=C,575b=C,575c=C,575d=C,575e=C,575f=C,5760=C,5784=C,5786=C,5788=J,'
2590 +'5789=J,5792=C,57a4=J,57a6=C,57a9=C,57ab=C,57ac=J,57ad=C,57b0=J,57b2=C,57b3=J,57d6=J,57d8=C,57d9=C,57da=C,5811=C,5815=C,5840=J,5870=J,5899=C,58b8=J,58b9=J,58d7=J,58e5=J,58ee=C,58f0=C,58f3=C,58f6=C,58f8=C,5904=C,5907=C,5934=C,5939=C,593a=C,5941=C,594b=C,5956=C,5986=C,5987=C,5988=C,'
2591 +'598b=J,599b=J,59a9=C,59aa=C,59ab=C,59c9=J,5a04=C,5a05=C,5a06=C,5a07=C,5a08=C,5a32=C,5a34=C,5a47=J,5a72=J,5a73=C,5a74=C,5a75=C,5a76=C,5aac=J,5ad2=C,5ad4=C,5af1=C,5b00=C,5b36=J,5b59=C,5b66=C,5b6a=C,5b93=J,5b9e=C,5ba0=C,5ba1=C,5baa=C,5bbd=C,5bbe=C,5bc9=J,5bdd=C,5bf9=C,5bfb=C,5bfc=C,'
2592 +'5bff=C,5c06=C,5c14=C,5c18=C,5c1d=C,5c27=C,5c34=C,5c3d=C,5c42=C,5c5e=C,5c61=C,5c66=C,5c76=J,5c7f=C,5c81=C,5c82=C,5c96=C,5c97=C,5c98=C,5c9a=C,5c9b=C,5cbc=J,5cbd=C,5cbe=J,5cbf=C,5cc3=C,5cc4=C,5cc5=J,5ce0=J,5ce1=C,5ce3=C,5ce4=C,5ce6=C,5d02=C,5d03=C,5d10=C,5d2c=C,5d2d=C,5d58=C,5d59=J,'
2593 +'5d5a=C,5d5d=C,5d76=J,5dc5=C,5de9=C,5def=C,5e01=C,5e05=C,5e08=C,5e0f=C,5e10=C,5e1c=C,5e26=C,5e27=C,5e2e=C,5e3b=C,5e3c=C,5e7f=C,5e83=J,5e86=C,5e90=C,5e91=C,5e93=C,5e94=C,5e99=C,5e9e=C,5e9f=C,5ebc=C,5f00=C,5f03=C,5f16=J,5f20=C,5f25=C,5f2f=C,5f39=C,5f41=J,5f45=J,5f52=C,5f53=C,5f55=C,'
2594 +'5f7b=C,5f84=C,5f95=C,5fa4=J,5fc6=C,5fdc=J,5fe7=C,5ff0=J,5ffe=C,6001=C,6002=C,6003=C,6004=C,6005=C,6006=C,603a=J,603b=C,603c=C,603f=C,604b=C,6073=C,6076=C,6077=J,6078=C,6079=C,607a=C,607b=C,607c=C,607d=C,60ab=C,60ac=C,60ad=C,60af=C,60e7=C,60e8=C,60e9=C,60eb=C,60ec=C,60ed=C,60ee=C,'
2595 +'60ef=C,6124=C,6126=C,6151=C,6164=C,61d1=C,61d2=C,6206=C,620b=C,620f=C,6217=C,6218=C,6256=J,6267=C,6268=J,6269=C,626a=C,626b=C,626c=C,629a=C,629f=C,62a0=C,62a1=C,62a2=C,62a4=C,62a5=C,62c5=C,62df=C,62e2=C,62e3=C,62e5=C,62e6=C,62e7=C,62e8=C,62e9=C,630a=J,6317=J,6318=J,631a=C,631b=C,'
2596 +'631c=C,631d=C,631e=C,631f=C,6320=C,6321=C,6322=C,6324=C,6325=C,6326=C,6327=J,635e=C,635f=C,6361=C,6363=C,6364=J,6386=C,63b3=C,63b4=C,63b5=J,63b7=C,63b8=C,63ba=C,63bc=C,63fd=C,63ff=C,6400=C,6401=C,6402=C,6405=C,643e=J,6444=C,6445=C,6446=C,6448=C,644a=C,6484=C,64b5=C,64b7=C,64ba=C,'
2597 +'64d3=C,64de=C,6512=C,654c=C,655b=C,6570=C,658b=C,6593=C,65a9=C,65ad=C,65e0=C,65e7=C,65f6=C,65f7=C,65f8=C,6619=C,663c=C,663d=C,663e=C,6653=C,6654=C,6655=C,6682=C,6683=J,66a7=C,66fb=J,6722=J,672f=C,6740=C,6741=J,6742=C,6743=C,6761=C,6762=J,6763=J,6764=J,6765=C,6766=J,6768=C,678c=J,'
2598 +'679e=C,67a0=J,67a1=J,67a2=C,67a3=C,67a5=C,67a6=J,67a7=C,67a8=C,67a9=J,67aa=C,67ab=C,67ad=C,67d5=J,67e0=C,67fd=C,67fe=J,6802=J,6803=J,6807=C,6808=C,6809=C,680a=C,680b=C,680c=C,680d=J,680e=C,680f=C,6811=C,682c=J,6837=C,683e=C,685b=J,685c=J,685d=J,6861=C,6862=C,6863=C,6864=C,6865=C,'
2599 +'6866=C,6867=C,6868=C,6869=C,6898=C,68a6=C,68ba=J,68bb=J,68c0=C,68c2=C,6917=J,6919=J,691a=J,691b=J,691f=C,6920=C,6921=J,6923=J,6924=C,6925=J,6926=J,6928=J,692a=J,692d=C,693f=J,697c=C,697e=J,697f=J,6980=J,6981=J,6984=C,6987=C,6988=C,6989=C,698a=J,69c7=J,69da=C,69db=C,69dd=J,69df=C,'
2600 +'69e0=C,6a2b=J,6a2e=J,6a2f=C,6a30=J,6a31=C,6a3b=J,6a67=J,6a72=J,6a73=J,6a78=J,6a79=C,6a7c=C,6ab0=J,6ae4=J,6b1f=J,6b22=C,6b24=C,6b27=C,6b7c=C,6b87=C,6b8b=C,6b92=C,6b93=C,6b9a=C,6ba1=C,6ba8=C,6bb4=C,6bbb=C,6bc2=C,6bd5=C,6bd9=C,6bdf=J,6be1=C,6bee=J,6bf5=C,6c07=C,6c17=J,6c22=C,6c29=C,'
2601 +'6c47=C,6c49=C,6c62=J,6c64=C,6c9f=C,6ca3=C,6ca4=C,6ca5=C,6ca6=C,6ca7=C,6ca8=C,6ca9=C,6caa=C,6cea=C,6cf7=C,6cf8=C,6cfa=C,6cfb=C,6cfc=C,6cfd=C,6cfe=C,6d43=C,6d45=C,6d46=C,6d47=C,6d48=C,6d49=C,6d4a=C,6d4b=C,6d4d=C,6d4e=C,6d4f=C,6d50=C,6d51=C,6d52=C,6d53=C,6d54=C,6d55=C,6d9b=C,6d9c=J,'
2602 +'6d9d=C,6d9e=C,6d9f=C,6da0=C,6da1=C,6da2=C,6da4=C,6da6=C,6da7=C,6da8=C,6da9=C,6e0a=C,6e0d=C,6e0e=C,6e10=C,6e11=C,6e14=C,6e17=C,6e7e=C,6e7f=C,6e82=J,6e83=C,6e85=C,6e87=C,6ed7=C,6ede=C,6edf=C,6ee0=C,6ee1=C,6ee4=C,6ee5=C,6ee6=C,6ee8=C,6ee9=C,6eea=C,6f47=C,6f4b=C,6f4d=C,6f57=J,6f59=C,'
2603 +'6f76=J,6f9c=C,6fbe=C,6fd1=C,6fd2=C,6ff9=J,704f=C,7067=C,706d=C,706f=C,7075=C,707e=C,707f=C,7080=C,7089=C,709c=C,709d=C,70b9=C,70bb=J,70bc=C,70bd=C,70c1=C,70c2=C,70c3=C,70db=C,70e6=C,70e7=C,70e8=C,70e9=C,70eb=C,70ec=C,70ed=C,7116=C,7118=C,7144=J,7173=J,7194=J,7195=J,71f5=J,7231=C,'
2604 +'7232=C,7237=C,7240=C,724d=C,7275=C,727a=C,728a=C,72b6=C,72b7=C,72b8=C,72b9=C,72c6=J,72c8=C,72de=C,72ec=C,72ed=C,72ee=C,72ef=C,72f1=C,72f2=C,7303=C,730e=C,7315=C,7321=C,732b=C,732e=C,7341=C,736d=C,7391=C,739b=C,73ae=C,73af=C,73b0=C,73b1=C,73ba=C,73c6=J,73d1=C,73f2=C,740e=C,740f=C,'
2605 +'7410=C,7411=J,743c=C,7443=J,7477=C,748e=C,74d2=C,74e7=J,74e9=J,74ea=J,74ef=C,74f0=J,74f1=J,74f2=J,74f8=J,74fc=J,7505=J,7523=C,7535=C,753b=C,753c=J,7545=C,7551=J,7560=J,7569=J,7573=J,7574=C,757d=J,7596=C,7597=C,759f=C,75a0=C,75a1=C,75ac=C,75ae=C,75af=C,75c7=J,75c8=C,75c9=C,75e8=C,'
2606 +'75eb=C,7605=C,7606=C,7617=C,7618=C,762a=C,762b=C,762e=C,763b=C,763e=C,763f=C,764c=J,765e=C,7663=C,7667=C,766a=J,766b=C,7691=C,76b1=C,76b2=C,76cf=C,76d0=C,76d1=C,76d6=C,76d8=C,770d=C,7750=C,7751=C,7792=C,7798=C,77a9=C,77eb=C,77f6=C,77fe=C,77ff=C,7800=C,7801=C,7816=C,7817=C,781a=C,'
2607 +'781c=C,783a=C,783b=C,783e=C,7840=C,7855=C,7856=C,7857=C,7859=C,785a=C,7872=J,7874=J,7877=C,788d=C,7897=J,789b=C,789c=C,78b5=J,78b8=C,7935=J,793c=C,794e=C,7962=C,796f=C,7977=C,7978=C,7985=C,79ef=C,79f0=C,79fd=C,7a23=C,7a2d=C,7a33=C,7a43=J,7a51=C,7a5d=J,7a77=C,7a83=C,7a8d=C,7a8e=C,'
2608 +'7a9c=C,7a9d=C,7aa5=C,7aa6=C,7aad=C,7ac8=C,7acd=J,7acf=J,7ad3=J,7ad5=J,7ad6=C,7ade=C,7ae1=J,7aea=C,7af0=J,7b02=J,7b03=C,7b0b=C,7b14=C,7b15=C,7b39=J,7b3a=C,7b3c=C,7b3d=J,7b3e=C,7b5a=C,7b5b=C,7b79=C,7b7e=C,7b80=C,7b93=C,7ba5=J,7ba6=C,7ba7=C,7ba8=C,7ba9=C,7baa=C,7bab=C,7bcf=J,7bd1=C,'
2609 +'7bd3=C,7bee=C,7c13=J,7c16=C,7c17=J,7c31=J,7c41=C,7c4f=J,7c74=C,7c75=J,7c7b=C,7c7e=J,7c81=J,7c82=J,7c8d=J,7c8f=J,7c90=J,7c9c=C,7c9d=C,7ca0=J,7ca8=J,7caa=C,7cab=J,7cad=J,7cae=C,7cc0=J,7cc1=C,7cce=J,7cd8=J,7d25=C,7d26=J,7d27=C,7d5d=C,7d76=C,7d77=C,7d89=C,7d9b=J,7dab=C,7db3=C,7dd1=C,'
2610 +'7dd5=J,7dfc=C,7e05=J,7e27=C,7e28=J,7e4a=J,7e67=J,7e6e=C,7e83=J,7e90=J,7ea0=C,7ea1=C,7ea2=C,7ea3=C,7ea4=C,7ea5=C,7ea6=C,7ea7=C,7ea8=C,7ea9=C,7eaa=C,7eab=C,7eac=C,7ead=C,7eaf=C,7eb0=C,7eb1=C,7eb2=C,7eb3=C,7eb4=C,7eb5=C,7eb6=C,7eb7=C,7eb8=C,7eb9=C,7eba=C,7ebc=C,7ebd=C,7ebe=C,7ebf=C,'
2611 +'7ec0=C,7ec1=C,7ec2=C,7ec3=C,7ec4=C,7ec5=C,7ec6=C,7ec7=C,7ec8=C,7ec9=C,7eca=C,7ecb=C,7ecc=C,7ecd=C,7ece=C,7ecf=C,7ed0=C,7ed1=C,7ed2=C,7ed3=C,7ed4=C,7ed5=C,7ed6=C,7ed7=C,7ed8=C,7ed9=C,7eda=C,7edb=C,7edc=C,7edd=C,7ede=C,7edf=C,7ee0=C,7ee1=C,7ee2=C,7ee3=C,7ee5=C,7ee6=C,7ee7=C,7ee8=C,'
2612 +'7ee9=C,7eea=C,7eeb=C,7eed=C,7eee=C,7eef=C,7ef0=C,7ef2=C,7ef3=C,7ef4=C,7ef5=C,7ef6=C,7ef7=C,7ef8=C,7efa=C,7efb=C,7efc=C,7efd=C,7efe=C,7eff=C,7f00=C,7f01=C,7f02=C,7f03=C,7f04=C,7f05=C,7f06=C,7f07=C,7f08=C,7f09=C,7f0a=C,7f0c=C,7f0e=C,7f11=C,7f12=C,7f13=C,7f14=C,7f15=C,7f16=C,7f17=C,'
2613 +'7f18=C,7f19=C,7f1a=C,7f1b=C,7f1c=C,7f1d=C,7f1e=C,7f1f=C,7f20=C,7f21=C,7f22=C,7f23=C,7f24=C,7f25=C,7f26=C,7f27=C,7f28=C,7f29=C,7f2a=C,7f2b=C,7f2c=C,7f2d=C,7f2e=C,7f2f=C,7f30=C,7f31=C,7f32=C,7f33=C,7f34=C,7f35=C,7f3c=J,7f42=C,7f4e=C,7f57=C,7f5a=C,7f62=C,7f74=C,7f81=C,7f9f=C,7faa=J,'
2614 +'7fd8=C,7fda=C,8022=C,8027=C,802e=C,8038=C,8042=C,804b=C,804c=C,804d=C,8054=C,8062=J,8069=C,806a=C,8083=C,80a0=C,80a4=C,80be=C,80bf=C,80c0=C,80c1=C,80c6=C,80e7=C,80e8=C,80ea=C,80eb=C,80f1=J,80f6=C,8109=C,810d=C,810f=C,8110=C,8111=C,8113=C,8114=C,8135=J,8136=C,8138=C,8156=C,8158=C,'
2615 +'817a=J,817b=C,817e=C,8191=C,81a4=J,81b5=J,81cd=J,81dc=C,8206=C,8220=J,822e=J,8230=C,8231=C,823b=C,8249=J,825d=J,8260=J,8270=C,8273=C,827a=C,8282=C,8297=C,829c=C,82a6=C,82c1=C,82c5=J,82c7=C,82c8=C,82cb=C,82cd=C,82cf=C,830e=C,830f=C,8311=C,8314=C,8315=C,834e=J,835a=C,835b=C,835c=C,'
2616 +'835e=C,835f=C,8360=C,8361=C,8363=C,8364=C,8365=C,8366=C,8367=C,8368=C,8369=C,836a=C,836b=C,836c=C,836d=C,836e=C,836f=C,83b1=C,83b2=C,83b3=C,83b4=C,83b7=C,83b8=C,83b9=C,83ba=C,83bc=C,8419=J,841a=C,841d=C,8421=J,8422=J,8424=C,8425=C,8426=C,8427=C,8428=C,8429=J,8464=C,8485=J,8487=C,'
2617 +'8489=C,848b=C,848c=C,8493=C,84d9=J,84da=J,84dc=J,84dd=C,84df=C,84e3=C,84e6=C,8534=C,8536=J,8537=C,8539=C,853a=C,853c=C,8552=C,8572=C,8574=C,85ae=C,85d3=C,85f4=C,8612=J,8630=J,8645=J,864f=C,8651=C,8672=J,867d=C,867e=C,867f=C,8680=C,8681=C,8682=C,86ab=J,86ac=C,86ca=C,86ce=C,86cf=C,'
2618 +'86ee=C,86ef=J,86f0=C,86f1=C,86f2=C,86f3=C,86f4=C,8717=C,8747=C,8748=C,8749=C,877c=C,877e=C,87a7=J,87a8=C,87a9=J,87cf=C,87d0=J,87f5=J,8845=C,8846=C,8854=C,8865=C,886c=C,8884=C,8885=C,889c=C,88ad=C,88b0=J,88c3=J,88c4=J,88c5=C,88c6=C,88e2=C,88e3=C,88e4=C,88e5=C,8902=J,8904=J,891b=C,'
2619 +'891c=J,8934=C,8947=C,8977=J,898e=C,89c1=C,89c2=C,89c3=C,89c4=C,89c5=C,89c6=C,89c7=C,89c8=C,89c9=C,89ca=C,89cb=C,89cc=C,89ce=C,89cf=C,89d0=C,89d1=C,89de=C,8a29=C,8a33=J,8a5f=C,8a89=C,8a8a=C,8aac=C,8aad=J,8aae=J,8ada=J,8b21=C,8b2d=C,8ba1=C,8ba2=C,8ba3=C,8ba4=C,8ba5=C,8ba6=C,8ba7=C,'
2620 +'8ba8=C,8ba9=C,8baa=C,8bab=C,8bad=C,8bae=C,8baf=C,8bb0=C,8bb2=C,8bb3=C,8bb4=C,8bb5=C,8bb6=C,8bb7=C,8bb8=C,8bb9=C,8bba=C,8bbb=C,8bbc=C,8bbd=C,8bbe=C,8bbf=C,8bc0=C,8bc1=C,8bc2=C,8bc3=C,8bc4=C,8bc5=C,8bc6=C,8bc7=C,8bc8=C,8bc9=C,8bca=C,8bcb=C,8bcc=C,8bcd=C,8bce=C,8bcf=C,8bd1=C,8bd2=C,'
2621 +'8bd3=C,8bd4=C,8bd5=C,8bd6=C,8bd7=C,8bd8=C,8bd9=C,8bda=C,8bdb=C,8bdd=C,8bde=C,8bdf=C,8be0=C,8be1=C,8be2=C,8be3=C,8be4=C,8be5=C,8be6=C,8be7=C,8be8=C,8be9=C,8beb=C,8bec=C,8bed=C,8bee=C,8bef=C,8bf0=C,8bf1=C,8bf2=C,8bf3=C,8bf4=C,8bf5=C,8bf6=C,8bf7=C,8bf8=C,8bf9=C,8bfa=C,8bfb=C,8bfc=C,'
2622 +'8bfd=C,8bfe=C,8bff=C,8c00=C,8c01=C,8c02=C,8c03=C,8c04=C,8c05=C,8c06=C,8c07=C,8c08=C,8c09=C,8c0a=C,8c0b=C,8c0c=C,8c0d=C,8c0e=C,8c0f=C,8c10=C,8c11=C,8c12=C,8c13=C,8c14=C,8c15=C,8c16=C,8c17=C,8c18=C,8c19=C,8c1a=C,8c1b=C,8c1c=C,8c1d=C,8c1e=C,8c1f=C,8c20=C,8c21=C,8c22=C,8c23=C,8c24=C,'
2623 +'8c25=C,8c26=C,8c27=C,8c28=C,8c29=C,8c2a=C,8c2b=C,8c2c=C,8c2d=C,8c2e=C,8c2f=C,8c30=C,8c31=C,8c32=C,8c33=C,8c34=C,8c35=C,8c36=C,8c6e=C,8cae=J,8ceb=C,8cec=J,8d0b=C,8d1c=C,8d1d=C,8d1e=C,8d1f=C,8d21=C,8d22=C,8d23=C,8d24=C,8d25=C,8d26=C,8d27=C,8d28=C,8d29=C,8d2a=C,8d2b=C,8d2c=C,8d2d=C,'
2624 +'8d2e=C,8d2f=C,8d30=C,8d31=C,8d32=C,8d33=C,8d34=C,8d35=C,8d36=C,8d37=C,8d38=C,8d39=C,8d3a=C,8d3b=C,8d3c=C,8d3d=C,8d3e=C,8d3f=C,8d41=C,8d42=C,8d43=C,8d44=C,8d45=C,8d46=C,8d48=C,8d49=C,8d4a=C,8d4b=C,8d4c=C,8d4d=C,8d4e=C,8d4f=C,8d50=C,8d52=C,8d53=C,8d54=C,8d55=C,8d56=C,8d57=C,8d58=C,'
2625 +'8d59=C,8d5a=C,8d5b=C,8d5c=C,8d5d=C,8d5e=C,8d60=C,8d61=C,8d62=C,8d63=C,8d6a=C,8d71=J,8d75=C,8d8b=C,8db1=C,8db8=C,8dc3=C,8dc4=C,8def=J,8df4=J,8df5=C,8df7=C,8df8=C,8df9=C,8dfb=C,8e0c=C,8e2c=C,8e2f=C,8e51=C,8e52=C,8e7f=C,8e8f=C,8e9c=C,8eae=J,8eaf=C,8eb5=J,8ebb=J,8ebe=J,8ec5=J,8ec8=J,'
2626 +'8ee4=C,8ef2=C,8f4c=J,8f66=C,8f67=C,8f68=C,8f69=C,8f6b=C,8f6c=C,8f6d=C,8f6e=C,8f6f=C,8f70=C,8f71=C,8f72=C,8f73=C,8f74=C,8f76=C,8f77=C,8f78=C,8f79=C,8f7a=C,8f7b=C,8f7c=C,8f7d=C,8f7e=C,8f7f=C,8f82=C,8f83=C,8f84=C,8f85=C,8f86=C,8f87=C,8f88=C,8f89=C,8f8a=C,8f8b=C,8f8d=C,8f8e=C,8f8f=C,'
2627 +'8f90=C,8f91=C,8f93=C,8f94=C,8f95=C,8f96=C,8f97=C,8f98=C,8f99=C,8f9a=C,8f9e=C,8fa9=C,8fab=C,8fb7=J,8fb9=C,8fbb=J,8fbc=J,8fbd=C,8fbe=C,8fc1=C,8fc7=C,8fc8=C,8fd0=C,8fd8=C,8fd9=C,8fda=J,8fdb=C,8fdc=C,8fdd=C,8fde=C,8fdf=C,8fe9=C,8ff9=C,9009=C,900a=C,9012=C,9026=C,9027=J,903b=C,9056=J,'
2628 +'9057=C,9093=C,909d=C,90ac=C,90ae=C,90b9=C,90ba=C,90bb=C,90cf=C,90d0=C,90d1=C,90d2=J,90d3=C,90e6=C,90e7=C,90f8=C,915b=J,915d=C,9171=C,917d=C,917e=C,917f=C,9196=C,91ca=C,91d7=J,91fa=C,91fb=J,91fe=C,9208=C,920e=C,9225=J,9226=J,9228=J,9229=J,922c=J,9239=J,923e=J,9255=C,9262=C,926b=J,'
2629 +'9274=C,9286=J,92ab=J,92ae=C,92af=J,92b1=C,92c5=J,92e5=C,92ed=C,92f2=J,9307=C,9332=C,9335=J,933a=J,933e=C,9340=C,9341=C,9344=J,9369=C,9384=C,9386=J,9387=C,93b8=C,93b9=J,93bf=C,93e5=J,93f0=C,941d=C,9420=J,9421=J,9426=C,9427=C,942f=C,9453=J,9454=C,9465=C,9479=C,9486=C,9487=C,9488=C,'
2630 +'9489=C,948a=C,948b=C,948c=C,948d=C,948e=C,948f=C,9490=C,9492=C,9493=C,9494=C,9495=C,9496=C,9497=C,9498=C,9499=C,949a=C,949b=C,949d=C,949e=C,949f=C,94a0=C,94a1=C,94a2=C,94a4=C,94a5=C,94a6=C,94a7=C,94a8=C,94a9=C,94aa=C,94ab=C,94ac=C,94ad=C,94ae=C,94af=C,94b0=C,94b1=C,94b2=C,94b3=C,'
2631 +'94b4=C,94b5=C,94b6=C,94b7=C,94b9=C,94ba=C,94bb=C,94bc=C,94bd=C,94be=C,94bf=C,94c0=C,94c1=C,94c2=C,94c3=C,94c4=C,94c5=C,94c6=C,94c8=C,94c9=C,94ca=C,94cb=C,94cc=C,94cd=C,94ce=C,94cf=C,94d0=C,94d1=C,94d2=C,94d3=C,94d5=C,94d7=C,94d9=C,94db=C,94dc=C,94dd=C,94de=C,94df=C,94e0=C,94e1=C,'
2632 +'94e2=C,94e3=C,94e4=C,94e5=C,94e7=C,94e8=C,94e9=C,94ea=C,94eb=C,94ec=C,94ed=C,94ee=C,94ef=C,94f0=C,94f1=C,94f2=C,94f3=C,94f5=C,94f6=C,94f7=C,94f8=C,94f9=C,94fa=C,94fc=C,94fd=C,94fe=C,94ff=C,9500=C,9501=C,9502=C,9503=C,9504=C,9505=C,9506=C,9507=C,9508=C,9509=C,950b=C,950c=C,950e=C,'
2633 +'950f=C,9510=C,9511=C,9512=C,9513=C,9514=C,9515=C,9517=C,9518=C,9519=C,951a=C,951b=C,951d=C,951e=C,951f=C,9521=C,9522=C,9523=C,9524=C,9525=C,9526=C,9527=C,9528=C,952b=C,952d=C,952e=C,952f=C,9530=C,9531=C,9532=C,9534=C,9535=C,9536=C,9537=C,9538=C,9539=C,953b=C,953c=C,953e=C,953f=C,'
2634 +'9540=C,9541=C,9542=C,9543=C,9544=C,9545=C,9547=C,9549=C,954a=C,954b=C,954c=C,954d=C,954e=C,954f=C,9550=C,9551=C,9552=C,9553=C,9554=C,9556=C,9557=C,9558=C,955a=C,955b=C,955c=C,955d=C,955e=C,9562=C,9563=C,9564=C,9565=C,9566=C,9567=C,9568=C,9569=C,956a=C,956b=C,956c=C,956d=C,956e=C,'
2635 +'956f=C,9570=C,9571=C,9572=C,9573=C,9574=C,9576=C,957f=C,9584=J,9587=J,958a=J,9596=J,95a0=J,95a7=C,95aa=J,95b2=C,95b8=J,95e6=J,95e8=C,95e9=C,95ea=C,95ed=C,95ee=C,95ef=C,95f0=C,95f1=C,95f2=C,95f4=C,95f5=C,95f7=C,95f8=C,95f9=C,95fa=C,95fb=C,95fc=C,95fd=C,95fe=C,95ff=C,9600=C,9601=C,'
2636 +'9602=C,9603=C,9604=C,9605=C,9606=C,9608=C,9609=C,960a=C,960b=C,960c=C,960d=C,960e=C,960f=C,9610=C,9611=C,9612=C,9614=C,9615=C,9616=C,9617=C,9619=C,961a=C,961f=C,9633=C,9634=C,9635=C,9636=C,9645=C,9646=C,9647=C,9648=C,9649=C,9655=C,9668=C,9669=C,968f=C,9690=C,96b6=C,96be=C,96cf=C,'
2637 +'96e0=C,96eb=J,96f3=C,96fe=C,9701=C,972d=C,974d=J,974e=J,974f=J,9753=C,9765=C,9779=J,9786=J,9790=J,9791=C,9792=C,979c=J,97af=C,97bd=C,97e6=C,97e7=C,97e8=C,97e9=C,97ea=C,97eb=C,97ec=C,97f5=C,983d=C,9854=C,986c=C,9875=C,9876=C,9877=C,9878=C,9879=C,987a=C,987b=C,987c=C,987d=C,987e=C,'
2638 +'987f=C,9880=C,9881=C,9882=C,9883=C,9884=C,9885=C,9886=C,9887=C,9888=C,9889=C,988a=C,988b=C,988c=C,988d=C,988f=C,9890=C,9891=C,9893=C,9894=C,9896=C,9897=C,9898=C,9899=C,989b=C,989c=C,989d=C,989e=C,989f=C,98a0=C,98a1=C,98a2=C,98a4=C,98a5=C,98a6=C,98a7=C,98aa=J,98ce=C,98d2=C,98d3=C,'
2639 +'98d4=C,98d5=C,98d7=C,98d8=C,98d9=C,98de=C,98e8=C,98ff=C,9904=C,990d=C,990e=C,990f=C,9919=J,991c=C,9936=C,9937=C,9942=J,994a=C,9962=C,9965=C,9966=C,9967=C,9968=C,9969=C,996a=C,996b=C,996c=C,996d=C,996e=C,996f=C,9970=C,9971=C,9972=C,9973=C,9974=C,9975=C,9976=C,9977=C,9978=C,9979=C,'
2640 +'997a=C,997b=C,997c=C,997d=C,997f=C,9981=C,9983=C,9984=C,9985=C,9986=C,9987=C,9988=C,9989=C,998a=C,998b=C,998d=C,998e=C,998f=C,9990=C,9991=C,9992=C,9993=C,9994=C,9995=C,99e1=C,99f2=J,9a6b=J,9a6c=C,9a6d=C,9a6e=C,9a6f=C,9a70=C,9a71=C,9a73=C,9a74=C,9a75=C,9a76=C,9a77=C,9a78=C,9a79=C,'
2641 +'9a7a=C,9a7b=C,9a7c=C,9a7d=C,9a7e=C,9a7f=C,9a80=C,9a81=C,9a82=C,9a84=C,9a85=C,9a86=C,9a87=C,9a88=C,9a8a=C,9a8b=C,9a8c=C,9a8e=C,9a8f=C,9a90=C,9a91=C,9a92=C,9a93=C,9a96=C,9a97=C,9a98=C,9a9a=C,9a9b=C,9a9c=C,9a9d=C,9a9e=C,9a9f=C,9aa0=C,9aa1=C,9aa2=C,9aa4=C,9aa5=C,9aa7=C,9ac5=C,9acb=C,'
2642 +'9acc=C,9aea=J,9b13=C,9b47=C,9b49=C,9b5d=J,9b5e=J,9b6c=J,9b74=J,9b78=J,9b79=J,9b81=C,9b84=J,9b8d=C,9b8e=C,9b95=J,9b96=J,9b97=J,9b98=J,9b9d=C,9b9f=J,9ba3=C,9bb1=J,9bb4=J,9bba=C,9bce=J,9bcf=J,9bd0=J,9bd1=J,9bd2=J,9be1=J,9bf0=J,9bf1=J,9bf2=J,9bf3=J,9bff=C,9c02=C,9c04=J,9c0c=C,9c10=C,'
2643 +'9c12=J,9c18=J,9c1f=C,9c21=J,9c27=C,9c2e=J,9c2f=J,9c30=J,9c35=C,9c39=J,9c45=C,9c47=J,9c48=J,9c5a=J,9c69=J,9c6a=J,9c6b=J,9c70=J,9c7c=C,9c7d=C,9c7f=C,9c81=C,9c82=C,9c85=C,9c86=C,9c87=C,9c88=C,9c8a=C,9c8b=C,9c8d=C,9c8e=C,9c8f=C,9c90=C,9c91=C,9c92=C,9c94=C,9c96=C,9c97=C,9c99=C,9c9a=C,'
2644 +'9c9b=C,9c9c=C,9c9d=C,9c9e=C,9c9f=C,9ca0=C,9ca1=C,9ca2=C,9ca3=C,9ca4=C,9ca5=C,9ca6=C,9ca7=C,9ca8=C,9ca9=C,9cab=C,9cad=C,9cae=C,9cb0=C,9cb1=C,9cb2=C,9cb3=C,9cb5=C,9cb6=C,9cb7=C,9cb8=C,9cbb=C,9cbd=C,9cbf=C,9cc1=C,9cc3=C,9cc4=C,9cc5=C,9cc6=C,9cc7=C,9cca=C,9ccc=C,9ccd=C,9cce=C,9ccf=C,'
2645 +'9cd1=C,9cd2=C,9cd3=C,9cd4=C,9cd5=C,9cd6=C,9cd7=C,9cd8=C,9cd9=C,9cdb=C,9cdc=C,9cdd=C,9cde=C,9cdf=C,9ce2=C,9ce3=C,9cec=C,9cf0=J,9cfe=C,9d2b=J,9d30=J,9d34=C,9d46=J,9d47=J,9d48=J,9d64=J,9d6e=C,9d93=C,9da5=C,9dab=J,9dc0=C,9dc4=C,9dc9=C,9e0a=C,9e1f=C,9e20=C,9e21=C,9e22=C,9e23=C,9e25=C,'
2646 +'9e26=C,9e27=C,9e28=C,9e29=C,9e2a=C,9e2b=C,9e2c=C,9e2d=C,9e2e=C,9e2f=C,9e30=C,9e31=C,9e32=C,9e33=C,9e35=C,9e36=C,9e37=C,9e38=C,9e39=C,9e3a=C,9e3b=C,9e3c=C,9e3d=C,9e3e=C,9e3f=C,9e41=C,9e42=C,9e43=C,9e44=C,9e45=C,9e46=C,9e47=C,9e48=C,9e49=C,9e4a=C,9e4b=C,9e4c=C,9e4f=C,9e50=C,9e51=C,'
2647 +'9e52=C,9e55=C,9e56=C,9e57=C,9e58=C,9e59=C,9e5a=C,9e5b=C,9e5c=C,9e5e=C,9e61=C,9e63=C,9e64=C,9e65=C,9e66=C,9e67=C,9e68=C,9e69=C,9e6a=C,9e6b=C,9e6c=C,9e6d=C,9e6f=C,9e70=C,9e73=C,9e7e=C,9e91=J,9ea6=C,9eaf=C,9eb8=C,9ebd=C,9ebf=J,9ec9=C,9ee1=C,9ee9=C,9efe=C,9f0b=C,9f0d=C,9f21=J,9f50=C,'
2648 +'9f51=C,9f7f=C,9f80=C,9f83=C,9f84=C,9f85=C,9f86=C,9f87=C,9f88=C,9f89=C,9f8a=C,9f8b=C,9f8c=C,9f99=C,9f9a=C,9f9b=C,9f9f=C,fa0f=J,fa13=J,fa20=J,fa21=J,fa24=J,fa29=J',1,16);
2649 //	HKEY_CLASSES_ROOT\MIME\Database\Charset
2650 //	將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字
2651 setObjValue('autodetectEncodeCode','GB2312=3000,Big5=3000,shift_jis=900,iso-8859-1=2000',1);
2652 
2653 
2654 TODO:
2655 只檢測常用的幾個字,無法判別才廣泛測試。
2656 */
2657 //var FN='I:\\Documents and Settings\\kanashimi\\My Documents\\kanashimi\\www\\cgi-bin\\game\\sjis.txt',enc=autodetectEncode(FN);alert('['+enc+'] '+FN+'\n'+_.read_all_file(FN,enc).slice(0,900));
2658 /*	自動判別檔案(或字串)之編碼	文字エンコーディング判定を行う
2659 	http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html
2660 	http://www.ericphelps.com/q193998/
2661 	http://hp.vector.co.jp/authors/VA003334/ado/adostream.htm
2662 */
2663 //autodetectEncode[generateCode.dLK]='isFile,simpleFileDformat,_.open_file,autodetectStringEncode,autodetectHTMLEncode';
2664 CeL.IO.Windows.file
2665 .
2666 autodetectEncode=function(FN,isHTML){
2667  var t,code;
2668  if(typeof ActiveXObject=='undefined'){alert("autodetectEncode: Can't find ActiveXObject!");return;}
2669  //if(typeof autodetectHTMLEncode!='function')isHTML=false;
2670  if(!isFile(FN))return FN.length<64?simpleFileDformat:(t=autodetectStringEncode(FN))?t:(isHTML||typeof isHTML=='undefined')&&(t=autodetectHTMLEncode(FN))?t:simpleFileDformat;
2671  _.open_file(FN,'iso-8859-1');	//	讀 binary data 用 'iso-8859-1' 會 error encoding.
2672  if(!AdoEnums||!AdoStream)return simpleFileDformat;
2673  AdoStream.LoadFromFile(FN);
2674  t=AdoStream.ReadText(3);//Read(3);//
2675  //alert(FN+'\n'+t.charCodeAt(0)+','+t.charCodeAt(1)+','+t.charCodeAt(2));
2676 
2677  //if(typeof t!='string')return simpleFileDformat;//t=''+t;	//	此時type通常是unknown,不能用+=
2678  //	Unicode的Byte Order Mark(BOM)在UTF-16LE(little endian)裏,它是以FF-FE這兩個bytes表達,在BE(big endian)裏,是FEFF。而在UTF-8裏,它是以EF-BB-BF這三個bytes表達。
2679  if(t.slice(0,2)=='\xFF\xFE')code='unicodeFFFE';
2680  else if(t.slice(0,2)=='\xFE\xFF')code='unicode';
2681  else if(t=='\xEF\xBB\xBF')code='UTF-8';
2682  else{
2683   // 即使是用OpenTextFile(_.open_format.TristateFalse),UTF-8還是會被轉換而判別不出來。
2684   //	from http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html
2685   var l,codes={},reg=new RegExp(),stream=new ActiveXObject("ADODB.Stream");
2686   codes['iso-8859-1']='[\\x09\\x0a\\x0d\\x20-\\x7e]';
2687   codes['big5']=codes['iso-8859-1']+
2688 	'|[\\xa4-\\xc6\\xc9-\\xf9][\\x40-\\xfe]';	//	http://www.cns11643.gov.tw/web/word/big5/index.html
2689   codes['shift_jis']=codes['iso-8859-1']+
2690 	'|[\\x81-\\x9f\\xe0-\\xef\\xfa-\\xfc][\\x40-\\x7e\\x80-\\xfc]|[\\xa1-\\xdf]';	//	http://hp.vector.co.jp/authors/VA013241/misc/shiftjis.html
2691   codes['euc-jp']=codes['iso-8859-1']+
2692 	'|\\x8f[\\xa1-\\xfe][\\xa1-\\xfe]|[\\xa1-\\xfe][\\xa1-\\xfe]|\\x8e[\\xa1-\\xdf]';
2693   codes['utf-8']=codes['iso-8859-1']+
2694 	'|[\\xc0-\\xdf][\\x80-\\xbf]|[\\xe0-\\xef][\\x80-\\xbf]{2}|[\\xf0-\\xf7][\\x80-\\xbf]{3}'+
2695 	'|[\\xf8-\\xfb][\\x80-\\xbf]{4}|[\\xfc-\\xfd][\\x80-\\xbf]{5}';
2696   codes['gb2312']=codes['iso-8859-1']+	//	GBK
2697 	'|[\\xa1-\\xf7][\\xa1-\\xfe]';	//	http://zh.wikipedia.org/wiki/GB_18030	http://zh.wikipedia.org/wiki/GB_2312
2698 
2699   stream.type=AdoEnums.adTypeBinary;
2700   stream.open();
2701   stream.loadFromFile(FN);
2702   stream.position=0;
2703   t=stream.read();
2704   stream.close();
2705   stream=null;
2706 
2707   t=translate_AdoStream_binary_data(t,4e3);
2708 
2709   for(var _e in codes){
2710    reg=new RegExp('^(?:'+codes[_e]+')');
2711    var l=0,s=t;
2712    while(l!=s.length)l=s.length,s=s.replace(reg,"");
2713    if(s==""){code=_e;break;}
2714   }
2715 
2716  }
2717  //sl('autodetectEncode: coding: ['+code+'] in parse 1.');
2718 
2719  //	假如是HTML檔,判斷是否有charset設定。這個判別放在unicode之後,其他自動判別之前。
2720  if(isHTML||typeof isHTML=='undefined'&&/\.s?html?$/i.test(FN)){
2721   if(AdoStream.Type==AdoEnums.adTypeBinary)_.open_file(FN,'iso-8859-1');
2722   AdoStream.Position=0,AdoStream.Charset='iso-8859-1';	//	讀 binary data 用 'iso-8859-1' 會 error encoding.
2723   if(t=autodetectHTMLEncode(AdoStream.ReadText(4e3)))code=t;
2724  }
2725  //sl('autodetectEncode: coding: ['+code+'] in parse 2.');
2726 
2727  //autodetectEncodeCode.GB2312=900000;	// 4 test
2728  if(!code)for(var i in autodetectEncodeCode){
2729   if(AdoStream.Type==AdoEnums.adTypeBinary)_.open_file(FN,'iso-8859-1');
2730   if(AdoStream.Position=0,i==autodetectStringEncode(AdoStream.ReadText(autodetectEncodeCode[AdoStream.Charset=i]))){code=i;break;}
2731  }
2732 
2733  AdoStream.Close();
2734  return code||simpleFileDformat;	//	ascii=iso-8859-1,_autodetect,_autodetect_all
2735 };
2736 
2737 //	判斷HTML檔是否有charset設定
2738 function autodetectHTMLEncode(fc){	//	file contents
2739  var t;
2740  if( fc.match(/<\s*meta\s+([^>]+)>/i)
2741 	&& ((t=RegExp.$1).match(/content="([^"]+)"/i)||t.match(/content=([^\w]+)/i))
2742 	&& (t=RegExp.$1).match(/charset=([\w-]{2,})/i)
2743 	|| fc.match(/<\?\s*xml\s[^>]+\sencoding\s*=\s*["']([a-z\d\-]+)["']/i)
2744 	)
2745  return RegExp.$1;
2746 };
2747 CeL.IO.Windows.file
2748 .
2749 /**
2750  * 靠常用字自動判別字串之編碼	string,預設編碼
2751  */
2752 autodetectStringEncode=function(str){
2753  if(typeof str!='string'||!(str=str.replace(/\s+/g,'')))return;
2754  var len=str.length,i=0,c,a,kana=0,jianhuazi=0,halfwidthKatakana=0,Hangul=0,ascii=0,asciiHigh=0,kanji=0,kokuji=0,symbol=0,unknown=0;
2755  //if(len>9000)len=9000;
2756  //var unknownC='';
2757 
2758  //	char分類
2759  for(;i<len;i++)
2760   if(c=str.charCodeAt(i),c<0x80)ascii++;
2761   else if(c<0x100)asciiHigh++;
2762   else if(c>0x3040&&c<0x30ff)kana++;
2763   else if(c==0x30fb||c>0xff65&&c<0xff9e)halfwidthKatakana++;
2764   else if(c>=0x1100&&c<0x11fa||c>=0xac00&&c<0xad00||c>=0xd700&&c<0xd7a4)Hangul++;
2765   else if(c>0x4dff&&c<0x9fa6){kanji++,a=autodetectEncodeSP[c];if(a=='C')jianhuazi++;else if(a=='J')kokuji++;}
2766   else if(c>0xfa00&&c<0xfa6b){if(autodetectEncodeSP[c]=='J')kokuji++;}
2767   else if(c>0x2010&&c<0x2610||c>=0xfe30&&c<0xfe70||c>0xff00&&c<0xff5f)symbol++;
2768   else if(c>=0x3000&&c<0x3400||c>0x33ff&&c<0x4db6)
2769    if(autodetectEncodeSP[c]=='J')kokuji++;else symbol++;
2770   else unknown++;//,unknownC+=str.charAt(i);
2771 
2772  //alert('len='+len+'\nkana='+kana+'\nkokuji='+kokuji+'\njianhuazi='+jianhuazi+'\nhalfwidthKatakana='+halfwidthKatakana+'\nHangul='+Hangul+'\nascii='+ascii+'\nasciiHigh='+asciiHigh+'\nkanji='+kanji+'\nsymbol='+symbol+'\nunknown='+unknown);
2773  //if(unknownC)alert('unknown:\n'+unknownC.slice(0,200));//alert(unknownC.slice(0,200)+'\n'+str.slice(0,1000));
2774  //	依各種常用字母之條件判別
2775  return ascii+asciiHigh==len?'iso-8859-1'
2776 	:unknown>.05*(len-ascii)?''//unicode	//	unknown不能太多
2777 	:kana>.2*len&&kanji+kana+symbol>3*halfwidthKatakana?'shift_jis'
2778 	:kanji+symbol>.7*(len-ascii)&&kana<.05*(len-ascii)?	jianhuazi>.1*kanji?'GB2312':'Big5'
2779 	:Hangul+symbol>.7*(len-ascii)?'korean'//ks_c_5601
2780 	:kanji>.2*(len-ascii)?	jianhuazi>.1*kanji?kokuji>.02*kanji?'unicode':'GB2312':kokuji>.02*kanji?'shift_jis':'Big5'
2781 	:'';//unicode
2782 };
2783 
2784 /*
2785 http://bbs.ee.ntu.edu.tw/boards/Linux/7/9/58.html	http://libai.math.ncu.edu.tw/~shann//Chinese/big5.html	http://wiki.debian.org.tw/index.php/Big5Variants	http://leoboard.cpatch.org/cgi-bin/topic.cgi?forum=20&topic=64&changemode=1
2786 http://www.theorem.ca/~mvcorks/cgi-bin/unicode.pl.cgi?start=F900&end=FAFF	http://homepage1.nifty.com/nomenclator/unicode/normalization.htm
2787 
2788 Unicode的漢字大致是以康熙部首排序,不過間中有部分字排錯部首筆劃
2789 第一批在1993年加進Unicode的,
2790 於中國內地、台灣、南韓及日本已有字集的漢字,
2791 編碼於U+4E00至U+9FA5,
2792 亦有部分南韓重覆漢字被編到U+F900至U+FA0B、
2793 兩個Big-5重覆漢字被編到U+FA0C至U+FA0D、
2794 日本廠商漢字被編到U+FA0E至U+FA2D
2795 
2796 全形符號(只限鍵盤上那94個)位於U+FF01至U+FF5E
2797 中日韓專用符號放到了U+3000至U+33FF內,
2798 其餘有部分符號放到了U+2XXX及U+FE30至U+FE6F
2799 
2800 第二批在1999年加進Unicode的,
2801 加進了新加坡用漢字、南韓PKS C 5700-2 1994、
2802 部分CNS11643第三、四、十五字面等用字、
2803 未包括在第一批字的數個GB字集用字,
2804 被編入U+3400至U+4DB5
2805 
2806 第三批在2001年加進Unicode的,
2807 加進了CNS11643第三、四、五、六、七、十五字面所有字、
2808 香港增補字集用字、四庫全書、辭海、辭源、康熙字典、
2809 漢語大字典、漢語大詞典內的所有用字,
2810 被編入U+20000至U+2A6D6
2811 JIS-X0213漢字被加到U+FA30至U+FA6A
2812 CNS11643重覆漢字被加到U+2F800至U+2FA1D
2813 
2814 简化字总表	http://cdns.twnic.net.tw/cjktable/	http://www.sxyw.cn/YuWenGongZuo/gfzs22.htm	http://huayuqiao.org/articles/xieshiya/Simplified/6_XinJiaPoTiaoZhengJianTiZi-XP.htm	http://www.hk-place.com/vp.php?board=2&id=333-9
2815 简化字分布似乎並無規範,只好以array判斷:
2816 
2817 <div id="dataGB">
2818 http://cdns.twnic.net.tw/cjktable/simtab.html
2819 簡化字總表之 UNICODE 碼表
2820 </div>
2821 <div id="dataJP">
2822 http://homepage2.nifty.com/TAB01645/ohara/index_j2.htm
2823 JIS区点索引
2824 </div>
2825 
2826 <script type="text/javascript">
2827 var i=0,c=0,autodetectEncodeSP=[],m=document.getElementById('dataGB').innerHTML.match(/\([0-9A-F]{4},\w*\)/g),t="setObjValue('autodetectEncodeSP','";
2828 for(;i<m.length;i++)//if(m[i].indexOf('C')!=-1&&m[i].slice(m[i].indexOf(',')+1).indexOf('T')==-1)t+=m[i].substr(1,5);
2829  if(m[i].indexOf('T')==-1)autodetectEncodeSP[parseInt(m[i].substr(1,4),16)]='C';
2830 for(i=0,m=document.getElementById('dataJP').innerHTML.match(/【.】/g);i<m.length;i++)
2831  autodetectEncodeSP[parseInt(m[i].charCodeAt(1))]=autodetectEncodeSP[parseInt(m[i].charCodeAt(1))]?0:'J';
2832 
2833 m=[];for(i in autodetectEncodeSP)m.push(parseInt(i));m.sort();
2834 for(i=0;i<m.length;i++)if(autodetectEncodeSP[m[i]]){t+=m[i].toString(16)+'='+autodetectEncodeSP[m[i]]+',',c++;if(c%40==0)t+="'<br/>+'";}
2835 alert(c+'字');
2836 document.getElementById('dataJP').innerHTML='';
2837 document.getElementById('dataGB').innerHTML=t.slice(0,-1)+"',1,16);";
2838 </script>
2839 
2840 
2841 和製漢字(国字)は、和語(ヤマトコトバ)に相当する漢字が無い場合に新規につくられたもので、奈良時代から作られた。ほとんどは訓読みしかない。魚篇や木篇が多い。
2842 http://homepage2.nifty.com/TAB01645/ohara/index.htm
2843 http://zh.wiktionary.org/wiki/%E8%BE%BB
2844 http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=8fbb
2845 http://jprs.jp/doc/rule/saisoku-1-wideusejp-furoku-4.html
2846 http://m2000.idv.tw/informer/zhi/char-root.htm
2847 http://www.ajisai.sakura.ne.jp/~dindi/chrc/ref/wincode2.txt
2848 http://cs-people.bu.edu/butta1/personal/hkscs/hkscs-oct.html
2849 http://www.nobi.or.jp/i/kotoba/kanji/wasei-kanji.html
2850 http://www.melma.com/mag/52/m00011552/a00000066.html
2851 
2852 
2853 韓語字母/諺文
2854 http://www.sinica.edu.tw/~cytseng/Korean%20reader/hangul.htm
2855 http://www.unicode.org/charts/normalization/
2856 
2857 old:
2858 //	自動判別檔案(或字串)之編碼
2859 function autodetectEncode(FN){
2860  if(!isFile(FN))return FN.length>64?autodetectStringEncode(FN):simpleFileDformat;
2861  _.open_file(FN,'iso-8859-1');
2862  if(!AdoEnums)return simpleFileDformat;
2863  //AdoStream.Type=AdoEnums.adTypeBinary;
2864  AdoStream.LoadFromFile(FN);
2865  var t=AdoStream.ReadText(3),code;
2866  //	Unicode的Byte Order Mark(BOM)在UTF-16LE(little endian)裏,它是以FF-FE這兩個bytes表達,在BE(big endian)裏,是FEFF。而在UTF-8裏,它是以EF-BB-BF這三個bytes表達。
2867  if(t.slice(0,2)=='\xFF\xFE')code='unicodeFFFE';
2868  if(t.slice(0,2)=='\xFE\xFF')code='unicode';
2869  if(t=='\xEF\xBB\xBF')code='UTF-8';
2870  if(code){AdoStream.Close();return code;}
2871 
2872  if(!code)with(AdoStream){
2873   //	將sjis排在gb與Big5前面是因為sjis常符合gb,且sjis之判定相當嚴。
2874   if(!code)Position=0,Charset='shift_jis',code=autodetectStringEncode(ReadText(900),Charset);
2875   //	將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字
2876   if(!code)Position=0,Charset='GB2312',code=autodetectStringEncode(ReadText(2000),Charset);
2877   if(!code)Position=0,Charset='Big5',code=autodetectStringEncode(ReadText(2000),Charset);
2878  }
2879 
2880  AdoStream.Close();
2881  return code||simpleFileDformat;	//	ascii=iso-8859-1,_autodetect,_autodetect_all
2882 }
2883 //	靠常用字自動判別字串之編碼	string,預設編碼
2884 function autodetectStringEncode(str,dcode){
2885  var code;
2886  if(str.length>9000)str=str.slice(0,9000);
2887 
2888  //	將sjis排在gb與Big5前面是因為sjis常符合gb,且sjis之判定相當嚴。
2889  if(dcode=='shift_jis'||!dcode&&!code){
2890   //	http://www.asahi-net.or.jp/~hc3j-tkg/unicode/	http://www.unicode.org/Public/UNIDATA/DerivedCoreProperties.txt
2891   var i=0,c,k=0,u=0,h=0;//h_=u_=k_='';
2892   for(;i<str.length;i++)if(c=str.charCodeAt(i),c>0xFF)
2893 	if(c==0x30FB||c>0xFF65&&c<0xFF9E)h++;//,h_+=str.charAt(i);//||c==0xE134	//	HALFWIDTH KATAKANA LETTER等可能不是日文文件中會出現的char
2894 	else if(c>0x3040&&c<0x30FF)k++;//,k_+=str.charAt(i);	//	kana
2895 	else u++;//,u_+=str.charAt(i);	//	unknown kanji
2896   //alert(k+','+u+','+h+'\n*'+k_+'\n*'+u_+'\n*'+h_);//alert(u_.charCodeAt(2));
2897   if(k+u>2*h)code='shift_jis';	//	HALFWIDTH KATAKANA LETTER數目比漢字少時判別為shift_jis
2898  }
2899 
2900 //	將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字
2901  if(dcode=='Big5'||dcode=='GB2312'||!dcode&&!code){
2902   var i=0,c,k=0,u=0;//k_=u_='';
2903   for(;i<str.length;i++)if(c=str.charCodeAt(i),c>0xFF)
2904 	if(c>0x4DFF&&c<0x9FA6||c>0xFF00&&c<0xFF5F||c>0x33ff&&c<0x4DB6||c==0x2605||c==0x2606)k++;//,k_+=str.charAt(i);	//	2605,6:★☆
2905 	else u++;//,u_+=str.charAt(i);
2906   //alert(k+','+u+'\n'+k_+'\n*'+u_);
2907   if(k>5*u)code=dcode||'Big5';	//	漢字比不認識的字多時判定
2908  }
2909 
2910  if(dcode=='iso-8859-1'||dcode=='ascii'||!dcode&&!code){
2911  }
2912 
2913  return code;
2914 }
2915 */
2916 
2917 
2918 /*	將 iso-8859-1 轉成utf-8
2919 To use:
2920 ..
2921 translated=turnBinStr(original);
2922 ..
2923 translated=turnBinStr();	//	delete temp file
2924 */
2925 turnBinStr.temp_file='turnBinStr.tmp';	//	temp file name
2926 function turnBinStr(t,_enc){
2927  if(typeof t!='undefined'){
2928   if(!turnBinStr.tmpF)turnBinStr.tmpF=getFP(turnBinStr.temp_file,1);
2929 
2930   //t+='';
2931   //if(t.replace(/[^\x00-\x7f]+/g,''))return t;
2932   //var _q=t.replace(/[^?]+/g,'').length,_t,_j=0;
2933   _.write_to_file(turnBinStr.tmpF,''+t,'iso-8859-1');
2934   //alert(turnBinStr.tmpF+'\n'+simpleFileErr.description+'\n'+t+'\n'+_.read_all_file(turnBinStr.tmpF,'utf-8'));
2935   return _.read_all_file(turnBinStr.tmpF,'utf-8');
2936 /*
2937   if(!_enc)_enc='utf-8,Big5,shift_jis,euc-jp,GB2312'.split(',');
2938   else if(!(_enc instanceof Array))_enc=[_enc];
2939   for(;_j<_enc.length;_j++)
2940    if((_t=_.read_all_file(turnBinStr.tmpF,_enc[_j])).replace(/[^?]+/g,'').length==_q)
2941     return _t;//'['+_enc[_j]+']'+
2942   return t;
2943 */
2944  }
2945  try{fso.DeleteFile(turnBinStr.tmpF);}catch(e){}	//	有時會出錯
2946 }
2947 
2948 
2949 
2950 
2951 
2952 //folder_info[generateCode.dLK]='initWScriptObj';
2953 //	需同時修改if(traverseSubDirectory==folder_info.f.noNewObj)段落之return!
2954 
2955 //setObjValue('folder_info.f','noNewObj=-1,files,dirs,fsize,size,Tsize=3,Tfiles,Tdirs',1);
2956 CeL.IO.Windows.file
2957 .
2958 /**
2959  * Get the infomation of folder
2960  * @param folder_path	folder path
2961  * @param file_filter
2962  * @param traverseSubDirectory
2963  * @return
2964  * @example
2965  * var finfo=new folder_info(path or folder object,extFilter,0/1);
2966  * @deprecated	以 <a href="#.traverse_file_system">traverse_file_system</a> 代替
2967  * @memberOf	CeL.IO.Windows.file
2968  */
2969 folder_info=function(folder_path,file_filter,traverseSubDirectory){
2970  var dir,filesCount,subDirectorysCount,total_size_of_files,total_size_of_this_folder,total_filesCount,total_subDirectorysCount;
2971  filesCount=subDirectorysCount=total_size_of_files=total_size_of_this_folder=total_filesCount=total_subDirectorysCount=0;
2972  if(typeof traverseSubDirectory=='undefined')traverseSubDirectory=1;
2973 
2974  if(typeof folder_path=='object')dir=folder_path;
2975  else if(folder_path){
2976   if(!folder_path.slice(-1)!=path_separator)folder_path+=path_separator;
2977   try{dir=fso.GetFolder(folder_path);}catch(e){dir=0;}
2978  }
2979 
2980  if(dir){
2981   total_subDirectorysCount=subDirectorysCount=dir.SubFolders.Count;
2982   var i,t,f=new Enumerator(dir.SubFolders);
2983   if(traverseSubDirectory||traverseSubDirectory==folder_info.f.noNewObj)for(;!f.atEnd();f.moveNext()){
2984    i=f.item();
2985    t=folder_info(i,file_filter,folder_info.f.noNewObj);
2986    //alert(i.path+'\n'+t[folder_info.f.size]+','+t[folder_info.f.Tfiles]+','+t[folder_info.f.Tdirs]);
2987    total_size_of_this_folder+=t[folder_info.f.size];
2988    total_filesCount+=t[folder_info.f.Tfiles];
2989    total_subDirectorysCount+=(t[folder_info.f.Tdirs]||0);
2990   }
2991 
2992   //alert(dir.files.Count+'\n'+total_filesCount);
2993   total_filesCount+=(filesCount=dir.files.Count);
2994   f=new Enumerator(dir.files);
2995   for(;!f.atEnd();f.moveNext()){
2996    i=f.item();
2997    if(file_filter&&!file_filter.test(i.name))continue;
2998    //if(traverseSubDirectory!=folder_info.f.noNewObj)alert(i.name+': '+i.size+' / '+total_size_of_files);
2999    total_size_of_files+=i.size;
3000   }
3001 
3002   total_size_of_this_folder+=total_size_of_files;
3003  }
3004 
3005  //alert(dir.path+'\nfile filter: '+file_filter+'\n'+filesCount+','+subDirectorysCount+','+total_size_of_files+','+total_size_of_this_folder+','+total_filesCount+','+total_subDirectorysCount);
3006  if(traverseSubDirectory==folder_info.f.noNewObj)
3007   return [filesCount,subDirectorysCount,total_size_of_files,total_size_of_this_folder,total_filesCount,total_subDirectorysCount];
3008 
3009  this.files=this[folder_info.f.files]=filesCount;
3010  this.dirs=this[folder_info.f.dirs]=subDirectorysCount;
3011  this.fsize=this[folder_info.f.fsize]=total_size_of_files;
3012  this.size=this[folder_info.f.size]=total_size_of_this_folder;
3013  this.Tfiles=this[folder_info.f.Tfiles]=total_filesCount;
3014  this.Tdirs=this[folder_info.f.Tdirs]=total_subDirectorysCount;
3015  return this;
3016 };
3017 CeL.IO.Windows.file
3018 .
3019 /**
3020  * <a href="#.folder_info">folder_info</a> 的 flag enumeration
3021  * @memberOf	CeL.IO.Windows.file
3022  * @constant
3023  */
3024 folder_info.f={
3025 	noNewObj:-1,
3026 	files:0,
3027 	dirs:1,
3028 	fsize:2,
3029 	size:3,
3030 	Tsize:3,
3031 	Tfiles:4,
3032 	Tdirs:5
3033 };
3034 
3035 
3036 /*	list files of folder	改編自 folder_info()
3037 	var files=new listFile(path or folder object,extFilter,flag);
3038 
3039 */
3040 //listFile[generateCode.dLK]='initWScriptObj';
3041 //	需同時修改if(flag==listFile.f.noNewObj)段落之return!
3042 
3043 //setObjValue('listFile.f','ignoreCase=1',1);
3044 listFile.f={
3045 	ignoreCase:1
3046 };
3047 
3048 function listFile(folder_path,file_filter,flag){
3049  var files=[];
3050  if(typeof flag=='undefined')flag=0;
3051 
3052  if(typeof folder_path=='object')dir=folder_path;
3053  else if(folder_path){
3054   if(!folder_path.slice(-1)!=path_separator)folder_path+=path_separator;
3055   try{dir=fso.GetFolder(folder_path);}catch(e){dir=0;}
3056  }
3057 
3058  if(dir){
3059   var i,f=new Enumerator(dir.files);
3060   for(;!f.atEnd();f.moveNext()){
3061    i=f.item();
3062    if(file_filter&&!file_filter.test(i.name))continue;
3063    files.push(i.name);
3064   }
3065  }
3066 
3067  return files;
3068 }
3069 
3070 
3071 
3072 
3073 
3074 
3075 /*
3076 in UNIX:
3077 iconv -l
3078 iconv -c -f UTF-16 -t BIG5-HKSCS function.js
3079 
3080 */
3081 /**
3082  * 將編碼為fromCode之檔案fileName中所有不合編碼toCode之char以encodeFunction轉換
3083  * @param fileName
3084  * @param toCode
3085  * @param fromCode
3086  * @param encodeFunction
3087  * @return
3088  * @memberOf	CeL.IO.Windows.file
3089  */
3090 function iconv_file(fileName,toCode,fromCode,encodeFunction){
3091  return iconv(_.read_all_file(fileName,fromCode),toCode,encodeFunction);
3092 }
3093 /*	將string text中所有不合編碼toCode之char以encodeFunction轉換
3094 
3095 TODO:
3096 一次寫入多 bytes
3097 */
3098 //var iconvError=[];
3099 function iconv(text,toCode,encodeFunction){
3100  if(!text)return '';
3101  //alert('iconv: ['+toCode+']\n'+text.slice(0,200));
3102  if(/utf-?(8|16)/i.test(toCode))
3103   return HTMLToUnicode(text,1);
3104  if(_.open_file(0,toCode||simpleFileDformat)!==0)
3105   return text;
3106  //AdoStream.Type=AdoEnums.adTypeText;
3107  if(!encodeFunction)encodeFunction=toHTML;
3108  //iconvError=[];
3109 
3110  var charToSet,i=0,t='';
3111  for(;i<text.length;i++)try{
3112   charToSet=text.charAt(i);
3113   if(charToSet.charCodeAt(0)<256){t+=charToSet;continue;}	//	對於過小的,直接匯入。
3114   AdoStream.Position=0;
3115   AdoStream.WriteText(charToSet);
3116   AdoStream.Position=0;
3117   t+=charToSet==AdoStream.ReadText(AdoEnums.adReadAll)?charToSet:encodeFunction(charToSet);
3118  }catch(e){
3119   //iconvError.push(e.description);
3120   t+=encodeFunction(charToSet);
3121  }
3122 
3123  try{AdoStream.Close();}catch(e){}
3124  return t;
3125 }
3126 
3127 
3128 
3129 //---------------------------------------------------
3130 
3131 
3132 /*
3133 var driverProperty,folderProperty,fileProperty;
3134 setObjValue('driverProperty','AvailableSpace,DriveLetter,DriveType,FileSystem,FreeSpace,IsReady,Path,RootFolder,SerialNumber,ShareName,TotalSize,VolumeName',1,setObjValueFlag.array);
3135 setObjValue('folderProperty','Attributes,DateCreated,DateLastAccessed,DateLastModified,Drive,Name,ParentFolder,Path,ShortName,ShortPath,Size,Type,Files,IsRootFolder,SubFolders',1,setObjValueFlag.array);//Files起為Folder property
3136 fileProperty=folderProperty.slice(0,12);//folderProperty.sort();
3137 */
3138 
3139 
3140 //var kkk='';_.traverse_file_system(function(fileItem,itemType){kkk+=(itemType==_.traverse_file_system.f.driver?fileItem.DriveLetter+':('+fileItem.VolumeName+')':fileItem.Name+(itemType==_.traverse_file_system.f.folder?path_separator:''))+'\n';},'I:\\Documents and Settings\\kanashimi\\My Documents\\kanashimi\\www\\cgi-bin\\program');_.write_to_file('tmp.txt',kkk,'unicode');
3141 /*
3142 
3143 _.traverse_file_system(FS_function_array)	省略path會當作所有Drives
3144 _.traverse_file_system(FS_function_array,'c:')	c:→c:\→sub dir of c:\
3145 _.traverse_file_system(FS_function_array,'c:\\')	c:\→sub dir of c:\
3146 _.traverse_file_system(FS_function_array,'c:\\cc')	c:\cc,cc為dir→sub dir of c:\cc\
3147 _.traverse_file_system(FS_function_array,'c:\\cc\\')	c:\cc\→sub dir of c:\cc\
3148 _.traverse_file_system(FS_function_array,['c:\\cc\\','d:\\dd'])	c:\cc\→sub dir of c:\cc\→d:\dd→sub dir of d:\dd
3149 _.traverse_file_system([,folderFunction],'.');
3150 
3151 
3152 _.traverse_file_system([,folderFunction],basePath);
3153 function folderFunction(folderItem){
3154  t=folderItem.Path.slice(same_length(basePath,folderItem.Path));
3155  //if(t==folderItem.Name)	//	僅單層subdir次目錄
3156  //if(t.indexOf(path_separator)==t.lastIndexOf(path_separator))	//	僅單層及次層subdir次目錄
3157  if(t.replace(new RegExp('[^'+path_separator_RegExp+']','g'),'').length<3)	//	僅3層subdir以下
3158   ;
3159 }
3160 
3161 
3162 //	itemType=0:file/1:folder/2:driver
3163 function fsoFunction(fsi,itemType){if(!itemType){}}
3164 function fileFunction(fileItem){}
3165 function folderFunction(folderItem){}
3166 function driverFunction(driverItem){}
3167 
3168 filter:
3169 	file_filter	僅單一 filter 時預設當作 file_filter, should has NO global flag.
3170 	[file_filter,folder_filter]
3171 file_filter	篩選檔案, should has NO global flag.
3172 folder_filter	篩選資料夾, should has NO global flag.
3173 
3174 
3175 tip:
3176 使用相對路徑,如'..'開頭時需用getFP()調整過。
3177 用folder.Size==0可判別是否為empty folder
3178 
3179 TODO:
3180 限定traverse深度幾層,sort=8,preOrder=0,widthFirst=0,postOrder=16,depthFirst=16
3181 */
3182 //_.traverse_file_system.stop=false;
3183 
3184 //_.traverse_file_system[generateCode.dLK]='initWScriptObj';
3185 CeL.IO.Windows.file
3186 .
3187 /**
3188  * 巡覽 file system 的公用函數
3189  * @param FS_function_array	file system handle function array
3190  * @param path	target path
3191  * @param filter	filter
3192  * @param flag	see <a href="#.traverse_file_system.f">flag</a>
3193  * @return
3194  * @memberOf	CeL.IO.Windows.file
3195  * @see	<a href="http://msdn.microsoft.com/library/en-us/script56/html/0fa93e5b-b657-408d-9dd3-a43846037a0e.asp">FileSystemObject</a>
3196  */
3197 traverse_file_system = function(FS_function_array, path, filter, flag){
3198 	var _s = arguments.callee, _f = _s.f;
3199 
3200 	// initial
3201 	// 預設 flag
3202 	// if(isNaN(flag))flag=_f.traverse;
3203 
3204 	//library_namespace.log('traverse_file_system:\n[' + path + ']');
3205 	if (FS_function_array === _f.get_object)
3206 		// or FS_function_array=[,,]:	可以使用 Array 常值中的空白元素來建立零星稀疏的陣列。
3207 		FS_function_array = new Array(_f.func_length),
3208 		flag = _f.get_object;
3209 	else {
3210 		/*
3211 		if (FS_function_array instanceof Array && FS_function_array.length == 1)
3212 			FS_function_array = FS_function_array[0];
3213 		*/
3214 		if (typeof FS_function_array === 'function') {
3215 			var i = FS_function_array;
3216 			FS_function_array = [ i, i, i ];
3217 		}
3218 	}
3219 	//library_namespace.log('traverse_file_system: fso:\n[' + fso + ']');
3220 	if (typeof fso !== 'object' || !(FS_function_array instanceof Array)
3221 			|| !FS_function_array.length)
3222 		return;
3223 	//library_namespace.log('traverse_file_system: FS_function_array:\n[' + FS_function_array + ']');
3224 	if (!filter)
3225 		filter = [];
3226 	else if (filter instanceof RegExp)
3227 		// filter=[filter,filter]; 通常我們輸入的只會指定 file filter
3228 		filter = [ filter, ];
3229 	else if (typeof filter !== 'object')
3230 		filter = [ filter, ];
3231 
3232 	//library_namespace.log('traverse_file_system: FS_function_array:\n[' + FS_function_array + ']');
3233 	var item, iType, fc, i, traverse = !(flag & _f.no_traverse), objBuf = [], typeBuf = [], folder_filter = filter[1], testFilter = function(
3234 			f) {
3235 		try {
3236 			// f instanceof RegExp
3237 			f.test('');
3238 		}
3239 		catch (e) {
3240 			// throw new Error(e.number,'traverse_file_system: 錯誤的 filter:\n'+f+'\n'+e.description);
3241 			e.description = 'traverse_file_system: 錯誤的 filter:\n' + f + '\n'
3242 			+ e.description;
3243 			throw e;
3244 		}
3245 	};
3246 	if (filter = filter[0])
3247 		if (typeof filter === 'string')
3248 			filter = new RegExp(filter);
3249 		else
3250 			testFilter(filter);
3251 	if (folder_filter)
3252 		if (typeof folder_filter === 'string')
3253 			folder_filter = new RegExp(folder_filter);
3254 		else
3255 			testFilter(folder_filter);
3256 	// if(flag!=_f.get_object)alert(filter+'\n'+folder_filter);
3257 	// 至此 filter 代表 file_filter, vs. folder_filter
3258 
3259 
3260 	// 轉換輸入之各項成fso object
3261 	if (!path) { // 取得各個driver code
3262 		if (flag === _f.get_object)
3263 			return;
3264 		for ( var drivers = new Enumerator(fso.Drives); !drivers.atEnd(); drivers
3265 		.moveNext())
3266 			objBuf.push(drivers.item()), typeBuf
3267 			.push(_f.driver);
3268 		objBuf.reverse(), typeBuf.reverse();
3269 	} else if (typeof path === 'object')
3270 		if (path.length) {
3271 			for (i = 0; i < path.length; i++)
3272 				if (item = _s(_f.get_object,
3273 						'' + path[i], filter, flag))
3274 					objBuf.push(item[0]), typeBuf.push(item[1]);
3275 		} else {
3276 			item = typeof path.IsReady !== 'undefined' ? _f.driver
3277 					: typeof path.IsRootFolder !== 'undefined' ? _f.folder
3278 							: typeof path.Path !== 'undefined' ? _f.file
3279 									: _f.NULL;
3280 			if (_f.NULL != -1)
3281 				objBuf.push(path), typeBuf.push(item);
3282 		}
3283 	else {
3284 		i = true; // fault
3285 		if (i)
3286 			try {
3287 				objBuf.push(fso.GetFolder(path)), typeBuf
3288 				.push(_f.folder), i = false;
3289 			} catch (e) {
3290 			}// fso.FolderExists()
3291 			if (i)
3292 				try {
3293 					objBuf.push(fso.GetFile(path)), typeBuf
3294 					.push(_f.file), i = false;
3295 				} catch (e) {
3296 				}// fso.FileExists()
3297 				if (i && path == fso.GetDriveName(path))
3298 					try {
3299 						objBuf.push(fso.GetDrive(path)), typeBuf
3300 						.push(_f.driver), i = false;
3301 					} catch (e) {
3302 					}
3303 	}
3304 	if (flag == _f.get_object)
3305 		return objBuf[0] ? [ objBuf[0], typeBuf[0] ] : 0;
3306 
3307 		// FS_function_array.length=_f.func_length;
3308 		for (i = 0; i < _f.func_length; i++)
3309 			// 可以安排僅對folder或是file作用之function
3310 			if (typeof FS_function_array[i] !== 'function')
3311 				FS_function_array[i] = function() {};
3312 			//alert(objBuf.length+','+typeBuf.length+'\n'+typeBuf);
3313 			// main loop
3314 			while (!_s.stop && objBuf.length)
3315 				if (item = objBuf.pop()) // fsoFunction執行途中可能將此項目刪除
3316 					switch (iType = typeBuf.pop()) {
3317 					case _f.folder:
3318 						if (!folder_filter || folder_filter.test(item.Name))
3319 							FS_function_array[iType](item, iType);
3320 						// if(traverse||traverse!==0){
3321 						// if(!traverse)traverse=0; // 加上次一層: 會連這次一層之檔案都加上去。
3322 						if (traverse)
3323 							for (fc = new Enumerator(item.SubFolders); !fc.atEnd(); fc
3324 							.moveNext())
3325 								if (i = fc.item(), !folder_filter
3326 										|| folder_filter.test(i.Name))
3327 									objBuf.push(i), typeBuf
3328 									.push(_f.folder);
3329 						// }
3330 						// try 以防item已經被刪除
3331 						try {
3332 							fc = new Enumerator(item.Files);
3333 						} catch (e) {
3334 							fc = 0;
3335 						}
3336 						if (fc) {
3337 							// for(;!fc.atEnd();fc.moveNext())if(i=fc.item(),!filter||filter.test(i.Name))FS_function_array[_f.file](i,_f.file);
3338 							// 因為檔案可能因改名等改變順序,因此用.moveNext()的方法可能有些重複,有些漏掉未處理。
3339 							for (item = []; !fc.atEnd(); fc.moveNext())
3340 								item.push(fc.item());
3341 							for (i in item)
3342 								if (i = item[i], !filter || filter.test(i.Name))
3343 									FS_function_array[_f.file](i,
3344 											_f.file);
3345 						}
3346 						break;
3347 					case _f.file:
3348 						if (!filter || filter.test(item.Name))
3349 							FS_function_array[iType](item, iType);
3350 						break;
3351 					case _f.driver:
3352 						if (!item.IsReady)
3353 							break;
3354 						FS_function_array[iType](item, iType);
3355 						if (traverse)
3356 							objBuf.push(item.RootFolder), typeBuf
3357 							.push(_f.folder);
3358 						// break;
3359 						//default:break;
3360 					}
3361 
3362 };
3363 
3364 
3365 //setObjValue('traverse_file_system.f','get_object=-2,NULL=-1,file,folder,driver,func_length,traverse=0,no_traverse=4',1);//,sort=8,preOrder=0,widthFirst=0,postOrder=16,depthFirst=16
3366 CeL.IO.Windows.file
3367 .
3368 /**
3369  * <a href="#.traverse_file_system">traverse_file_system</a> 的 flag enumeration
3370  * @memberOf	CeL.IO.Windows.file
3371  * @constant
3372  */
3373 traverse_file_system.f = {
3374 		/**
3375 		 * return object
3376 		 * @memberOf	CeL.IO.Windows.file
3377 		 */
3378 		get_object : -2,
3379 		/**
3380 		 * null flag
3381 		 * @private
3382 		 * @memberOf	CeL.IO.Windows.file
3383 		 */
3384 		NULL : -1,
3385 		/**
3386 		 * 用於指示 file
3387 		 * @private
3388 		 * @memberOf	CeL.IO.Windows.file
3389 		 */
3390 		file : 0,
3391 		/**
3392 		 * 用於指示 folder
3393 		 * @private
3394 		 * @memberOf	CeL.IO.Windows.file
3395 		 */
3396 		folder : 1,
3397 		/**
3398 		 * 用於指示 driver
3399 		 * @private
3400 		 * @memberOf	CeL.IO.Windows.file
3401 		 */
3402 		driver : 2,
3403 		/**
3404 		 * handle function 應有的長度
3405 		 * @private
3406 		 * @memberOf	CeL.IO.Windows.file
3407 		 */
3408 		func_length : 3,
3409 		/**
3410 		 * 深入下層子目錄及檔案
3411 		 * @memberOf	CeL.IO.Windows.file
3412 		 */
3413 		traverse : 0,
3414 		/**
3415 		 * 不深入下層子目錄及檔案
3416 		 * @memberOf	CeL.IO.Windows.file
3417 		 */
3418 		no_traverse : 4
3419 };
3420 
3421 
3422 return (
3423 	CeL.IO.Windows.file
3424 );
3425 };
3426 
3427 //===================================================
3428 
3429 CeL.setup_module(module_name, code_for_including);
3430 
3431 };
3432 
3433 
3434 //WScript.Echo(this.Class);
3435 
3436 //	若 library base 尚未 load 或本 module 已經 loaded 則跳過。
3437 if (typeof CeL === 'function'){
3438 
3439 /**
3440  * 本 module 之 name(id),<span style="text-decoration:line-through;">不設定時會從呼叫時之 path 取得</span>。
3441  * @type	String
3442  * @constant
3443  * @inner
3444  * @ignore
3445  */
3446 var module_name = 'code.log';
3447 
3448 //var do_before_including = function() {};
3449 
3450 /*	to include:
3451 	include code_for_including
3452 	<div id="debug_panel"></div>
3453 	var SL=new Debug.log('debug_panel'),sl=function(){SL.log.apply(SL,arguments);},err=function(){SL.err.apply(SL,arguments);},warn=function(){SL.warn.apply(SL,arguments);};
3454 
3455 	http://www.comsharp.com/GetKnowledge/zh-CN/TeamBlogTimothyPage_K742.aspx
3456 
3457 	if possible, use Firebug Lite instead.
3458 	http://benalman.com/projects/javascript-debug-console-log/
3459 */
3460 
3461 
3462 //	===================================================
3463 /**
3464  * 若欲 include 整個 module 時,需囊括之 code。通常即 CeL。
3465  * @type	Function
3466  * @param	{Function} library_namespace	namespace of library
3467  * @param	load_arguments	呼叫時之 argument(s)
3468  * @return
3469  * @constant
3470  * @inner
3471  * @ignore
3472  */
3473 var code_for_including = function(library_namespace, load_arguments) {
3474 //WScript.Echo(this);
3475 
3476 var
3477 
3478 //	class private	-----------------------------------
3479 
3480 //	class name, 需要用到這個都不是好方法。
3481 //cn='Debug.log',
3482 
3483 /**
3484  * private storage pool
3485  * @ignore
3486  */
3487 p=[],
3488 
3489 /**
3490  * default write/show log function
3491  * @ignore
3492  * @param	{string} id	element id
3493  */
3494 w = function(id) {
3495 	var o, m, c, _p = p[id], _t = _p.instance,
3496 	/**
3497 	 * buffer
3498 	 */
3499 	b = _p.buf,
3500 	B = _p.board, F = _p.do_function, level;
3501 
3502 	if (_p.clean)
3503 		_t.clear(), _p.clean = 0;
3504 
3505 	if (!B && !F)
3506 		return;
3507 
3508 	while (b.length) {
3509 		m = b.shift(); // 預防 MP 時重複顯示
3510 		if (F)
3511 			F(m);
3512 
3513 		c = 0;
3514 		if ((m instanceof Object) && !(m instanceof Array))
3515 			c = m.l in _t.className_set ? _t.className_set[m.l] : 0,
3516 					m = m.m;
3517 		_p.lbuf.push(m);
3518 
3519 		if (B) { // && typeof document==='object'
3520 			o = _p.instance.log_tag;
3521 			if (o) {
3522 				o = document.createElement(o);
3523 				if (c)
3524 					o.className = c;
3525 				o.innerHTML = typeof m === 'string' ?
3526 						// for character (null)
3527 						m.replace(/\x00/g,
3528 						'<span class="control_character">\\x00</span>')
3529 						: m;
3530 			} else
3531 				o = document.createTextNode(m);
3532 			B.appendChild(o);
3533 		}
3534 	}
3535 
3536 	//if(_t.auto_hide)B.style.display=B.innerHTML?'block':'none';
3537 	if (B && _t.auto_scroll)
3538 		with (B)
3539 			scrollTop = scrollHeight - clientHeight;
3540 },
3541 
3542 
3543 /**
3544  * save log
3545  * @ignore
3546  * @param	m	message
3547  * @param	{string} id	element id
3548  * @param	force	force to clean the message area
3549  */
3550 s = function(m, id, force) {
3551 	var _p = p[id], _t = _p.instance, f = _p.logF, s = _t.save_log;
3552 	if (!s || typeof s == 'function' && !s(m, l))
3553 		return;
3554 
3555 	if (m)
3556 		_p.sbuf
3557 				.push(m = (_t.save_date && typeof gDate == 'function' ? _t.save_new_line
3558 						+ gDate() + _t.save_new_line
3559 						: '')
3560 						+ m);
3561 
3562 	if (force || _t.flush || _p.sbufL > _t.save_limit)
3563 		try {
3564 			if (f
3565 					|| _t.log_file
3566 					&& (f = _p.logF = fso.OpenTextFile(_t.log_file,
3567 							8/* ForAppending */, true/* create */,
3568 							_t.log_encoding)))
3569 				f.Write(_p.sbuf.join(_t.save_new_line)), _p.sbuf = [],
3570 						_p.sbufL = 0, _t.error_message = 0;
3571 		} catch (e) {
3572 			_t.error_message = e;// err(e);
3573 		}
3574 	else if (m)
3575 		_p.sbufL += m.length;
3576 },
3577 
3578 //	instance constructor	---------------------------
3579 //	(document object)
3580 /*
3581 
3582 _=this
3583 
3584 
3585 TODO:
3586 set class in each input
3587 input array
3588 show file path & directory functional	可從 FSO operation.hta 移植
3589 增加 group 以便在多次輸入時亦可 trigger 或排版
3590 
3591 count
3592 c.f.: GLog
3593 
3594 dependency:
3595 
3596 */
3597 /**
3598  * initial a log tool's instance/object
3599  * @class	log function
3600  * @see	usage: <a href="#.extend">CeL.code.log.extend</a>
3601  * @since	2008/8/20 23:9:48
3602  * @requires	gDate(),NewLine,fso
3603 
3604  * @constructor
3605  * @name	CeL.code.log
3606  * @param	{String, object HTMLElement} obj	message area element or id
3607  */
3608 _tmp;CeL.code.log
3609 = function(obj) {
3610 	// Initial instance object. You can set it yourself.
3611 	/**
3612 	 * 表示是 warning/error message 之 className
3613 	 * @name	CeL.code.log.prototype.className_set
3614 	 */
3615 	this.className_set = {
3616 			/**
3617 			 * @description	當呼叫 {@link CeL.code.log.prototype.warn} 時使用的 className
3618 			 * @name	CeL.code.log.prototype.className_set.warn
3619 			 */
3620 			warn : 'debug_warn',
3621 			/**
3622 			 * @description	當呼叫 {@link CeL.code.log.prototype.err} 時使用的 className
3623 			 * @name	CeL.code.log.prototype.className_set.err
3624 			 */
3625 			err : 'debug_err'
3626 	};
3627 
3628 	this.id = p.length;
3629 	p.push( {
3630 		instance : this,
3631 		/**
3632 		 * write buffer
3633 		 */
3634 		buf : [],
3635 		/**
3636 		 * save buffer when we need to save the messages
3637 		 */
3638 		sbuf : [],
3639 		/**
3640 		 * length of save buffer
3641 		 */
3642 		sbufL : 0,
3643 		/**
3644 		 * now logged buffer
3645 		 */
3646 		lbuf : []
3647 	}); 
3648 	this.set_board(obj);
3649 };
3650 
3651 
3652 
3653 //	class public interface	---------------------------
3654 
3655 CeL.code.log
3656 .
3657 /**
3658  * do the log action
3659  * @memberOf	CeL.code.log
3660  * @private
3661  */
3662 do_log = function(id) {
3663 /*	這段應該只在 module namespace 重複定義時才會發生
3664  var I=p[id];
3665  if(!I){
3666   alert('.do_log: not exist: ['+id+']');
3667   return;
3668  }
3669  I=I.instance;
3670 */
3671  var I=p[id].instance;
3672  if(I.do_log)I.do_log();
3673 };
3674 
3675 
3676 CeL.code.log
3677 .
3678 /**
3679  * new extend instance
3680  * @param	{String, object HTMLElement} [obj]	message area element or id
3681  * @return	{Array} [ log function, warning function, error function, instance of this module ]
3682  * @example
3683  * //	status logger
3684  * var SL=new CeL.code.log('log'),sl=SL[1],warn=SL[2],err=SL[3];
3685  * sl(msg);
3686  * sl(msg,clear);
3687  * @memberOf	CeL.code.log
3688  * @since	2009/8/24 20:15:31
3689  */
3690 extend = function(obj) {
3691 	//CeL.Log=new CeL.code.log(function(m){var F=typeof JSalert==='function'?JSalert:typeof alert==='function'?alert:WScript.Echo;F(typeof m==='object'?'['+m.l+'] '+m.m:m);});
3692 	/**
3693 	 * new instance
3694 	 * @type	CeL.code.log
3695 	 * @inner
3696 	 * @ignore
3697 	 */
3698 	var o = new _(
3699 			obj ||
3700 			//	預設以訊息框代替
3701 			new Function('m',
3702 					(typeof JSalert === 'function' ? 'JSalert':
3703 						typeof WScript === 'object' ? 'WScript.Echo':
3704 					'alert') +
3705 			"(typeof m==='object'?'['+m.l+'] '+m.m:m);"));
3706 
3707 	return [ o, function() {
3708 		o.log.apply(o, arguments);
3709 	}, function() {
3710 		o.warn.apply(o, arguments);
3711 	}, function() {
3712 		o.err.apply(o, arguments);
3713 	} ];
3714 
3715 };
3716 
3717 
3718 
3719 /*
3720 _.option_open=function(p){
3721 
3722 };
3723 
3724 _.option_file=function(p){
3725 };
3726 
3727 _.option_folder=function(p){
3728 };
3729 */
3730 
3731 //	class constructor	---------------------------
3732 
3733 
3734 CeL.code.log
3735 .prototype={
3736 
3737 //	instance public interface	-------------------
3738 
3739 /**
3740  * 當執行寫檔案或任何錯誤發生時之錯誤訊息。<br/>
3741  * while error occurred.. should read only
3742  * @name	CeL.code.log.prototype.error_message
3743  */
3744 error_message : '',
3745 
3746 /**
3747  * 超過這長度才 save。<=0 表示 autoflash,非數字則不紀錄。
3748  * @name	CeL.code.log.prototype.save_limit
3749  * @type	Number
3750  */
3751 save_limit : 4000,
3752 
3753 /**
3754  * 在 log 結束時執行,相當於 VB 中 DoEvent() 或 。
3755  * @name	CeL.code.log.prototype.do_event
3756  */
3757 do_event : library_namespace.DoNoting || null,
3758 
3759 
3760 /**
3761  * log 時使用之 tagName, 可用 div / span 等。若不設定會用 document.createTextNode
3762  * @name	CeL.code.log.prototype.log_tag
3763  */
3764 log_tag : 'div',
3765 
3766 
3767 /**
3768  * boolean or function(message, log level) return save or not
3769  * @name	CeL.code.log.prototype.save_log
3770  * @type	Boolean
3771  */
3772 save_log:false,
3773 /**
3774  * save log to this file path
3775  * @name	CeL.code.log.prototype.log_file
3776  * @type	Boolean
3777  */
3778 log_file:false,
3779 /**
3780  * auto save log. 若未設定,記得在 onunload 時 .save()
3781  * @name	CeL.code.log.prototype.flush
3782  * @type	Boolean
3783  */
3784 flush:false,
3785 /**
3786  * 在 save log 時 add date
3787  * @name	CeL.code.log.prototype.save_date
3788  * @type	Boolean
3789  */
3790 save_date:true,
3791 /**
3792  * 在 save log 時的換行
3793  * @name	CeL.code.log.prototype.save_new_line
3794  * @type	string
3795  */
3796 save_new_line : library_namespace.env.new_line || '\r\n',
3797 /**
3798  * 在 save log 時的 encoding
3799  * @name	CeL.code.log.prototype.log_encoding
3800  */
3801 log_encoding:-1,//TristateTrue
3802 
3803 
3804 /**
3805  * 自動捲動
3806  * @name	CeL.code.log.prototype.auto_scroll
3807  * @type	Boolean
3808  */
3809 auto_scroll:true,
3810 /**
3811  * 沒有內容時自動隱藏
3812  * @deprecated	TODO
3813  * @name	CeL.code.log.prototype.auto_hide
3814  * @type	Boolean
3815  */
3816 auto_hide:false,
3817 
3818 /**
3819  * 等待多久才顯示 log。若為 0 則直接顯示。<br/>
3820  * (WScript 沒有 setTimeout)
3821  * @name	CeL.code.log.prototype.interval
3822  */
3823 interval : typeof setTimeout === 'undefined' ? 0 : 1,
3824 
3825 /**
3826  * log function (no delay)
3827  * @name	CeL.code.log.prototype.do_log
3828  */
3829 do_log:function(level){
3830  //if(p[this.id].th)clearTimeout(p[this.id].th);
3831  p[this.id].th=0;	//	reset timeout handle
3832  w(this.id);
3833 },
3834 
3835 /**
3836  * class 預設作 log 之 function, (String message, clean)
3837  * @name	CeL.code.log.prototype.
3838  */
3839 log:function(m,clean,level){
3840  var t=this,_p=p[t.id];
3841  //var msg_head=(arguments.callee.caller+'').match(/function\s([^\(]+)/);if(msg_head)msg_head=msg_head[1]+' ';
3842  s(m,t.id,level);
3843 
3844  if(level)
3845   m={m:m,l:level};
3846 
3847  if(clean)_p.clean=1,_p.buf=[m];	//	clean log next time
3848  else _p.buf.push(m);
3849  //window.status=m;
3850 
3851  if(!t.interval)
3852   t.do_log();
3853  else if(!_p.th)
3854   if(typeof setTimeout==='undefined')
3855    t.interval=0,t.do_log();
3856   else
3857    //_p.th=setTimeout(cn+'.do_log('+t.id+');',t.interval);
3858    _p.th=setTimeout(function(){_.do_log(t.id);},t.interval);
3859 
3860  if(t.do_event)
3861   t.do_event();
3862 },
3863 
3864 /*
3865 TODO:
3866 other methods: INFO,DEBUG,WARNING,ERROR,FATAL,UNKNOWN
3867 */
3868 
3869 /**
3870  * save message
3871  * @name	CeL.code.log.prototype.save
3872  */
3873 save:function(){
3874  s('',this.id,1/*force*/);
3875 },
3876 
3877 //	** important ** 這邊不能作 object 之 initialization,否則因為 object 只會 copy reference,因此 new 時東西會一樣。initialization 得在 _() 中作!
3878 //className_set:{},
3879 
3880 /**
3881  * log a warning
3882  * @name	CeL.code.log.prototype.warn
3883  */
3884 warn:function(m,clean){
3885  this.log(m,clean,'warn');
3886 },
3887 
3888 /**
3889  * 表示是錯誤 error message
3890  * @name	CeL.code.log.prototype.error_prefix
3891  */
3892 error_prefix:'<em>!! Error !!</em> ',
3893 /**
3894  * deal with error object
3895  * @name	CeL.code.log.prototype.err
3896  */
3897 err:function(e,clean){
3898  //	from popErr()
3899  var NL=this.save_new_line,T=typeof e,m=e instanceof Error?'Error '+(e.number&0xFFFF)+(e.name?' ['+e.name+']':'')
3900 	+' (facility code '+(e.number>>16&0x1FFF)+'):'+NL+e.description.replace(/\r?\n/g,'<br/>')
3901 	+(!e.message||e.message==e.description?'':NL+NL+e.message.replace(/\r?\n/g,'<br/>')):!e||T=='string'?e:'('+T+')'+e;
3902 
3903  this.log(this.error_prefix+m,clean,'err');
3904 },
3905 
3906 
3907 /**
3908  * 設定寫入到哪<br/>set log board for each instance (document object)
3909  * @name	CeL.code.log.prototype.set_board
3910  */
3911 set_board:function(o){
3912  var _p=p[this.id];
3913  if(o)
3914   if(typeof o==='function')
3915    _p.do_function=o;
3916 
3917   else if(typeof o!=='object')
3918    if(o=typeof document==='object'?document.getElementById(o):0)
3919     _p.board=o;
3920 
3921  return _p.board;
3922 },
3923 
3924 /**
3925  * 獲取當前 buffer 中的 log
3926  * @name	CeL.code.log.prototype.get_log
3927  */
3928 get_log:function(){
3929  return p[this.id].lbuf;
3930 },
3931 
3932 /**
3933  * show/hide log board
3934  * @name	CeL.code.log.prototype.trigger
3935  */
3936 trigger:function(s){
3937  var _s=p[this.id].board.style;
3938  if(typeof s==='undefined')
3939   s=_s.display=='none';
3940  _s.display=s?'block':'none';
3941 },
3942 
3943 /**
3944  * clear log board
3945  * @name	CeL.code.log.prototype.clear_board
3946  */
3947 clear_board:function(b){
3948  b.innerHTML='';
3949 },
3950 
3951 /**
3952  * 清除全部訊息 clear message
3953  * @name	CeL.code.log.prototype.clear
3954  */
3955 clear:function(){
3956  var _p=p[this.id];
3957  if(_p.board)this.clear_board(_p.board);
3958  _p.lbuf=[];
3959 }
3960 
3961 };
3962 
3963 
3964 /**
3965  * 不 extend 的 member
3966  * @ignore
3967  */
3968 CeL.code.log
3969 .no_extend = '*';
3970 
3971 return (
3972 	CeL.code.log
3973 );
3974 };
3975 
3976 //	===================================================
3977 
3978 /**
3979  * modele namespace
3980  * @type	CeL.code.log
3981  * @inner
3982  * @ignore
3983  */
3984 var ns = CeL.setup_module(module_name, code_for_including);
3985 
3986 //WScript.Echo(n.extend);
3987 
3988 //code_for_including[generateCode.dLK]='*var Debug={log:code_for_including()};';
3989 
3990 
3991 //	為本 library 用
3992 if (!CeL.Log) {
3993 	var o = ns.extend();
3994 
3995 	// override CeL.log
3996 	CeL.Log=o[0];
3997 
3998 	CeL.log = o[1];
3999 	CeL.warn = o[2];
4000 	CeL.err = o[3];
4001 }
4002 
4003 }
4004 
4005