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 * @ignore 658 */ 659 loaded_module = { 660 }; 661 662 /** 663 * Include specified module<br/> 664 * 注意:以下的 code 中,CeL.warn 不一定會被執行(可能會、可能不會),因為執行時 code.log 尚未被 include。<br/> 665 * 此時應該改用 CeL.use('code.log', callback);<br/> 666 * code in head/script/: 667 * <pre> 668 * CeL.use('code.log'); 669 * CeL.warn('a WARNING'); 670 * </pre> 671 * ** 在指定 callback 時 namespace 無效! 672 * @param {String} module module name 673 * @param {Function} [callback] callback function 674 * @param {Object, Boolean} [extend_to] extend to which namespace<br/> 675 * false: just load, don't extend to CeL<br/> 676 * this: extend to global<br/> 677 * object: extend to specified namespace that you can use [namespace]._func_ to run it<br/> 678 * (others, including undefined): extend to root of this library. e.g., call CeL._function_name_ and we can get the specified function. 679 * @return error object or null(no error, OK) 680 * @example 681 * CeL.use('code.log', function(){..}); 682 * CeL.use(['code.log', 'code.debug']); 683 */ 684 CeL.use = function(module, callback, extend_to){ 685 var i, l, module_path; 686 687 if (!module) 688 return; 689 690 /* 691 if (arguments.length > 3) { 692 l = arguments.length; 693 namespace = arguments[--l]; 694 callback = arguments[--l]; 695 --l; 696 for (i = 0; i < l; i++) 697 this.use(arguments[i], callback, namespace); 698 return; 699 } 700 */ 701 702 if (module instanceof Array) { 703 var error; 704 for (i = 0, l=module.length; i < l; i++) 705 if(error=this.use(module[i], callback, extend_to)) 706 return error; 707 return null; 708 } 709 710 if (!(module_path = this.get_module_path(module)) || this.is_loaded(module)) 711 return null; 712 713 //this.log(this.Class+'.use ['+module+']:\ntry to load ['+module_path+'].'); 714 715 // including code 716 try { 717 if (callback && typeof window !== 'undefined') { 718 // TODO: 在指定 callback 時使 namespace 依然有效。 719 this.include_resource(module_path, { 720 module : module, 721 callback : callback, 722 global : this 723 }); 724 return null; 725 } else 726 // this.log('load ['+module_path+']'), 727 // this.log('load 728 // ['+module_path+']:\n'+this.get_file(module_path, 729 // this.env.source_encoding)), 730 this.eval(this.get_file(module_path, 731 this.env.source_encoding)); 732 } catch (e) { 733 // http://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html 734 // http://reference.sitepoint.com/javascript/DOMException 735 if (e.constructor == '[object DOMException]' && e.code === 1012) 736 this.log(this.Class + '.use:\n' + e.message + '\n' 737 + module_path 738 + '\n\n程式可能呼叫了一個不存在的,或是繞經上層目錄的檔案?\n請嘗試使用相對路徑或 ' 739 + this.Class 740 + '.use(module, callback function, namespace)'); 741 if ((e instanceof Error) && (e.number & 0xFFFF) == 5) { 742 this.log(this.Class + '.use: 檔案可能不存在?\n' + module_path 743 + '\n' + e.message); 744 } else 745 this 746 .log(this.Class 747 + '.use: Cannot load [' 748 + module 749 + ']!\n[' 750 + (e.constructor) 751 + '] ' 752 + (e.number ? (e.number & 0xFFFF) : e.code) 753 + ': ' 754 + e.message 755 + '\n抱歉!在載入其他網頁時發生錯誤,有些功能可能失常。\n重新讀取(reload),或是過段時間再嘗試或許可以解決問題。'); 756 //this.log('Cannot load [' + module + ']!', this.log.ERROR, e); 757 758 return e; 759 } 760 761 762 // 處理 extend to namespace 763 if (!extend_to && extend_to !== false 764 || typeof namespace !== 'function' 765 || !(extend_to instanceof Object)) 766 extend_to = this; 767 768 if (extend_to) { 769 var ns = this.get_module(module), kw = this.env.not_to_extend_keyword, no_extend = {}; 770 // this.log(this.Class + '.use [' + module + ']:\nextend\n' + ns); 771 772 if (kw in ns) { 773 l = ns[kw]; 774 if (typeof l === 'string') { 775 no_extend[l] = 1; 776 } else if (l instanceof Array) { 777 for (i in l) 778 no_extend[i] = 1; 779 } else if (l instanceof Object) { 780 no_extend = l; 781 } 782 no_extend[kw] = 1; 783 } 784 785 // '*': 完全不 extend 786 if (!no_extend['*']) { 787 no_extend.Class = 1; 788 l = []; 789 for (i in ns) 790 if (!(i in no_extend)) 791 l.push(i); 792 793 //this.log(this.Class + '.use [' + module + ']:\nextend\n' + l + '\n\nto:\n' + (extend_to.Class || extend_to)); 794 this.extend(l, extend_to, ns); 795 } 796 797 } 798 799 }; 800 801 802 /* 803 bad: sometimes doesn't work. e.g. Google Maps API in IE 804 push inside window.onload: 805 window.onload=function(){ 806 include_resource(p); 807 setTimeout('init();',2000); 808 }; 809 810 way 3: ref. dojo.provide();, dojo.require(); 811 document.write('<script type="text/javascript" src="'+encodeURI(p)+'"><\/script>'); 812 813 TODO: 814 encode 815 816 */ 817 ; 818 /** 819 * include other JavaScript/CSS files 820 * @param {String} resource path 821 * @param {Function, Object} callback callback function / {callback: callback function, module: module name, global: global object when run callback} 822 * @param {Boolean} [use_write] use document.write() instead of insert a element 823 * @param {Boolean} [is_css] is a .css file 824 */ 825 CeL.include_resource = function(path, callback, use_write, is_css) { 826 var _s = arguments.callee, s, t; 827 //if(!_f.loaded)_f.loaded={},_f.count=0; 828 829 if (path instanceof Array) { 830 for (s = 0, t = path.length; s < t; s++) 831 _f(path[s], callback, use_write, is_css); 832 return; 833 } 834 835 if(path in _s.loaded) 836 return; 837 838 if(typeof c==='undefined') 839 is_css=/\.css$/i.test(path); 840 841 t='text/'+(is_css?'css':'javascript'); 842 /*@cc_on 843 w=1; // IE hack 844 @*/ 845 if (!use_write) 846 try { 847 // Dynamic Loading 848 // http://code.google.com/apis/ajax/documentation/#Dynamic 849 s = document.createElement(is_css ? 'link' : 'script'); 850 s.type = t; 851 if (is_css) 852 s.href = path, s.rel = 'stylesheet'; 853 else 854 s.src = path; 855 (document.getElementsByTagName('head')[0] || document.body.parentNode 856 .appendChild(document.createElement('head'))) 857 .appendChild(s); 858 //this.log('include_resource: HTML:\n' + document.getElementsByTagName('html')[0].innerHTML); 859 } catch (e) { 860 use_write = 1; 861 } 862 863 if (use_write) 864 document.write(is_css ? '<link type="' + t 865 + '" rel="stylesheet" href="' + path + '"><\/link>' 866 : '<script type="' + t + '" src="' + path 867 + '"><\/script>' // language="JScript" 868 ); 869 870 _s.loaded[path] = _s.count++; 871 872 if(callback) 873 _s.wait_to_call(callback); 874 }; 875 876 /** 877 * 已經 include_resource 了哪些 JavaScript 檔(存有其路徑) 878 * loaded{路徑} = count 879 */ 880 CeL.include_resource.loaded = {}; 881 882 /** 883 * 已經 include_resource 了多少個 JavaScript 檔 884 * @type Number 885 */ 886 CeL.include_resource.count = 0; 887 888 CeL.include_resource.wait_to_call = function(callback) { 889 //alert('include_resource.wait_to_call:\n' + CeL.to_module_name(callback.module)); 890 891 if (typeof callback === 'function') 892 // 不是 module,僅僅為指定 function 的話,直接等一下再看看。 893 // TODO: 等太久時 error handle 894 window.setTimeout(callback, 200); 895 896 else if (callback.global.is_loaded(callback.module)) 897 callback.callback(); 898 899 else { 900 /** 901 * the function it self, not 'this'. 902 * @inner 903 * @ignore 904 */ 905 var _s = arguments.callee; 906 window.setTimeout(function() { 907 _s(callback); 908 }, 10); 909 } 910 }; 911 912 CeL.get_module = function(module_name) { 913 module_name = this.split_module_name(module_name); 914 915 // TODO: test module_name.length 916 if(!module_name) 917 return null; 918 919 var i = 0, l = module_name.length, namespace = this; 920 // 一層一層 call namespace 921 while (i < l) 922 try { 923 namespace = namespace[module_name[i++]]; 924 } catch (e) { 925 return null; 926 } 927 928 return namespace; 929 }; 930 931 /** 932 * 預先準備好下層 module 定義時的環境。<br/> 933 * 請盡量先 call 上層 namespace 再定義下層的。 934 * @param {String} module_name module name 935 * @param {Function} code_for_including 若欲 include 整個 module 時,需囊括之 code。 936 * @return null invalid module 937 * @return {Object} 下層 module 之 namespace 938 */ 939 CeL.setup_module = function(module_name, code_for_including) { 940 module_name = this.split_module_name(module_name); 941 942 // TODO: test module_name.length 943 if(!module_name) 944 return null; 945 946 var i = 0, l = module_name.length - 1, namespace = this, name; 947 // 一層一層準備好 namespace 948 for (; i < l; i++) { 949 if (!namespace[name = module_name[i]]) 950 namespace[name] = new Function( 951 '// module namespace of ' + 952 this.to_module_name(module_name.slice(0, i + 1))); 953 namespace = namespace[name]; 954 } 955 // namespace 這時是 modele 的 parent modele。 956 957 if ( 958 // 尚未被定義或宣告過 959 !namespace[name = module_name[l]] || 960 // 可能是之前簡單定義過,例如被上面處理過。這時重新定義,並把原先的 member 搬過來。 961 !namespace[name].Class) { 962 963 // 保留原先的 namespace,for 重新定義 964 l = namespace[name]; 965 966 // extend code, 起始 namespace 967 // TODO: code_for_including(this, load_arguments) 968 namespace = namespace[name] = code_for_including(this); 969 970 // 把原先的 member 搬過來 971 if (l) { 972 delete l.Class; 973 // may use: this.extend() 974 for (i in l) 975 namespace[i] = l[i]; 976 } 977 namespace.Class = this.to_module_name(module_name); 978 } 979 980 /* 981 l=[]; 982 for(i in namespace) 983 l.push(i); 984 WScript.Echo('Get members:\n'+l.join(', ')); 985 */ 986 987 this.set_loaded(namespace.Class, code_for_including); 988 989 return namespace; 990 }; 991 992 993 // 並沒有對 module 做完善的審核! 994 CeL.split_module_name = function(module_name) { 995 if (typeof module_name === 'string') 996 module_name = module_name.replace(/\.\.+|\\\\+|\/\/+/g, '.').split(/\.|\\|\/|::/); 997 998 if (module_name instanceof Array) { 999 // 去除 library name 1000 if (module_name.length>1 && this.Class == module_name[0]) 1001 module_name.shift(); 1002 return module_name; 1003 } else 1004 return null; 1005 }; 1006 1007 1008 CeL.to_module_name = function(module, separator) { 1009 if (typeof module === 'function') 1010 module = module.Class; 1011 1012 if (typeof module === 'string') 1013 module = this.split_module_name(module); 1014 1015 var name = ''; 1016 if (module instanceof Array) { 1017 if (typeof separator !== 'string') 1018 separator = this.env.module_name_separator; 1019 if (module[0] != this.Class) 1020 name = this.Class + separator; 1021 name += module.join(separator); 1022 } 1023 1024 return name; 1025 }; 1026 1027 // TODO 1028 CeL.unload = function(module, g){ 1029 }; 1030 1031 1032 /** 1033 * 判斷 module 是否存在,以及是否破損。 1034 * @param {String} module_name module name 1035 * @return {Boolean} module 是否存在以及良好。 1036 */ 1037 CeL.is_loaded = function(module_name) { 1038 // var _s = arguments.callee; 1039 //this.log('is_loaded: test ' + this.to_module_name(module_name)); 1040 return loaded_module[this.to_module_name(module_name)] ? true 1041 : false; 1042 }; 1043 1044 1045 1046 CeL.set_loaded = function(module_name, code_for_including) { 1047 //this.log('set_loaded: ' + this.to_module_name(module_name)); 1048 loaded_module[this.to_module_name(module_name)] = code_for_including || true; 1049 }; 1050 1051 1052 1053 // initial 1054 1055 //temporary decoration incase we call for nothing 1056 CeL.log = function(){ 1057 if(debug) 1058 //arguments.callee.function_to_call.apply(null,arguments); 1059 arguments.callee.function_to_call.apply(global, arguments); 1060 }; 1061 1062 1063 CeL.log.function_to_call = 1064 typeof JSalert==='function'?JSalert: 1065 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);}: 1066 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);}: 1067 function(){}; 1068 1069 CeL.initial_env(); 1070 1071 1072 /* 1073 var test_obj=CeL(2,'test: initial'); 1074 1075 test_obj.test_print('OK!'); 1076 */ 1077 ; 1078 1079 1080 1081 //setTool(),oldVadapter(); // 當用此檔debug時請執行此行 1082 //alert(ScriptEngine()+' '+ScriptEngineMajorVersion()+'.'+ScriptEngineMinorVersion()+'.'+ScriptEngineBuildVersion()); 1083 1084 1085 1086 /* initialization of function.js 1087 僅僅執行此檔時欲執行的程序。 1088 1089 setTool(),oldVadapter(); // 當用此檔debug時請執行此行 1090 1091 利用.js加上此段與init(),以及.hta(<script type="text/javascript" src="~.js"></script>),可造出GUI/none GUI兩種可選擇之介面。 1092 if(typeof args=='object')init();else window.onload=init; 1093 */ 1094 //args=args.concat(['turnCode.js']); 1095 var _library_onload; 1096 if (typeof _library_onload === 'undefined'){ 1097 _library_onload = function() { 1098 //WScript.Echo(CeL.env.ScriptName); 1099 //CeL.log(CeL.env.ScriptName); 1100 if (1 && CeL.env.ScriptName === 'ce') { 1101 //WScript.Echo(CeL.env.ScriptName); 1102 CeL.use('OS.Windows.registry'); 1103 //CeL.log(CeL.registryF); 1104 1105 var _p = CeL.registryF.getValue(CeL._iF.p) || '(null)'; 1106 if (_p != CeL.env.library_base_path) { 1107 CeL.log('Change path of [' + CeL.env.ScriptName + '] from:\n' + _p 1108 + '\n to\n' + CeL.env.library_base_path + '\n\n' + CeL._iF.p); 1109 CeL.registryF.setValue.cid = 1; 1110 CeL.registryF.setValue(CeL._iF.p, CeL.env.library_base_path, 0, 0, 1); 1111 CeL.registryF.setValue.cid = 0; 1112 } 1113 1114 if (typeof args === 'object') {// args instanceof Array 1115 // getEnvironment(); 1116 // alert('Get arguments ['+args.length+']\n'+args.join('\n')); 1117 if (args.length) { 1118 var i = 0, p, enc, f, backupDir = dBasePath('kanashimi\\www\\cgi-bin\\program\\log\\'); 1119 if (!fso.FolderExists(backupDir)) 1120 try { 1121 fso.CreateFolder(backupDir); 1122 } catch (e) { 1123 backupDir = dBasePath('kanashimi\\www\\cgi-bin\\game\\log\\'); 1124 } 1125 if (!fso.FolderExists(backupDir)) 1126 try { 1127 fso.CreateFolder(backupDir); 1128 } catch (e) { 1129 if (2 == alert( 1130 '無法建立備份資料夾[' + backupDir + ']!\n接下來的操作將不會備份!', 1131 0, 0, 1 + 48)) 1132 WScript.Quit(); 1133 backupDir = ''; 1134 } 1135 // addCode.report=true; // 是否加入報告 1136 for (; i < args.length; i++) 1137 if ((f = dealShortcut(args[i], 1)) 1138 .match(/\.(js|vbs|hta|s?html?|txt|wsf|pac)$/i) 1139 && isFile(f)) { 1140 p = alert( 1141 '是否以預設編碼[' 1142 + ((enc = autodetectEncode(f)) == simpleFileDformat ? '內定語系(' + simpleFileDformat + ')' 1143 : enc) + ']處理下面檔案?\n' + f, 1144 0, 0, 3 + 32); 1145 if (p == 2) 1146 break; 1147 else if (p == 6) { 1148 if (backupDir) 1149 fso.CopyFile(f, backupDir + getFN(f), true); 1150 addCode(f); 1151 } 1152 } 1153 } else if (1 == alert('We will generate a reduced [' 1154 + CeL.env.ScriptName + ']\n to [' + CeL.env.ScriptName 1155 + '.reduced.js].\nBut it takes several time.', 0, 0, 1156 1 + 32)) 1157 reduceScript(0, CeL.env.ScriptName + '.reduced.js'); 1158 }//else window.onload=init; 1159 1160 //CeL._iF=undefined; 1161 } // if(1&&CeL.env.ScriptName==='function'){ 1162 }; // _library_onload 1163 } 1164 1165 1166 1167 /* 1168 1169 // test WinShell http://msdn.microsoft.com/en-us/library/bb787810(VS.85).aspx 1170 if (0) { 1171 alert(WinShell.Windows().Item(0).FullName); 1172 1173 var i, cmd, t = '', objFolder = WinShell.NameSpace(0xa), objFolderItem = objFolder 1174 .Items().Item(), colVerbs = objFolderItem.Verbs(); // 假如出意外,objFolder==null 1175 for (i = 0; i < colVerbs.Count; i++) { 1176 t += colVerbs.Item(i) + '\n'; 1177 if (('' + colVerbs.Item(i)).indexOf('&R') != -1) 1178 cmd = colVerbs.Item(i); 1179 } 1180 objFolderItem.InvokeVerb('' + cmd); 1181 alert('Commands:\n' + t); 1182 1183 // objShell.NameSpace(FolderFrom).CopyHere(FolderTo,0); // copy folder 1184 // objFolderItem=objShell.NameSpace(FolderFrom).ParseName("clock.avi");objFolderItem.Items().Item().InvokeVerb([動作]); 1185 // objShell.NameSpace(FolderFromPath).Items.Item(mName).InvokeVerb(); 1186 1187 // Sets or gets the date and time that a file was last modified. 1188 // http://msdn.microsoft.com/en-us/library/bb787825(VS.85).aspx 1189 // objFolderItem.ModifyDate = "01/01/1900 6:05:00 PM"; 1190 // objShell.NameSpace("C:\Temp").ParseName("Test.Txt").ModifyDate = 1191 // DateAdd("d", -1, Now()) CDate("19 October 2007") 1192 1193 // Touch displays or sets the created, access, and modified times of one or 1194 // more files. http://www.stevemiller.net/apps/ 1195 } 1196 1197 // 測試可寫入的字元:0-128,最好用1-127,因為許多編輯器會將\0轉成' ',\128又不確定 1198 if (0) { 1199 var t = '', f = 'try.js', i = 0; 1200 for (; i < 128; i++) 1201 t += String.fromCharCode(i); 1202 if (simpleWrite(f, t)) 1203 alert('Write error!\n有此local無法相容的字元?'); 1204 else if (simpleRead(f) != t) 1205 alert('內容不同!'); 1206 else if (simpleWrite(f, dQuote(t) + ';')) 1207 alert('Write error 2!\n有此local無法相容的字元?'); 1208 else if (eval(simpleRead(f)) != t) 1209 alert('eval內容不同!'); 1210 else 1211 alert('OK!'); 1212 } 1213 */ 1214 1215 1216 if(_library_onload) 1217 _library_onload(); 1218 1219 1220 })() // (function(){ 1221 //) // void( 1222 ; 1223 1224 1225 //}catch(e){WScript.Echo('There are some error in function.js!\n'+e.message);throw e;} 1226 1227 1228 1229 1230 1231 //CeL.use('code.log'); 1232 //CeL.warn('test_print: ' + CeL.code.log.Class); 1233 1234 //]]> 1235 1236 1237 1238 if (typeof CeL === 'function'){ 1239 1240 /** 1241 * 本 module 之 name(id),<span style="text-decoration:line-through;">不設定時會從呼叫時之 path 取得</span>。 1242 * @type String 1243 * @constant 1244 * @inner 1245 * @ignore 1246 */ 1247 var module_name = 'IO.Windows.file'; 1248 1249 //=================================================== 1250 /** 1251 * 若欲 include 整個 module 時,需囊括之 code。 1252 * @type Function 1253 * @param {Function} library_namespace namespace of library 1254 * @param load_arguments 呼叫時之 argument(s) 1255 * @return 1256 * @name CeL.IO.Windows.file 1257 * @constant 1258 * @inner 1259 * @ignore 1260 */ 1261 var code_for_including = function(library_namespace, load_arguments) { 1262 1263 1264 /** 1265 * null module constructor 1266 * @class Windows 下,檔案操作相關之 function。 1267 */ 1268 CeL.IO.Windows.file 1269 = function() { 1270 // null module constructor 1271 }; 1272 1273 /** 1274 * for JSDT: 有 prototype 才會將之當作 Class 1275 */ 1276 CeL.IO.Windows.file 1277 .prototype = { 1278 }; 1279 1280 1281 1282 /* 1283 JScript only ------------------------------------------------------- 1284 */ 1285 1286 CeL.IO.Windows.file 1287 . 1288 /** 1289 * FileSystemObject Object I/O mode enumeration 1290 * @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> 1291 * @memberOf CeL.IO.Windows.file 1292 */ 1293 iomode = { 1294 // * @_description <a href="#.iomode">iomode</a>: Open a file for reading only. You can't write to this file. 1295 /** 1296 * Open a file for reading only. You can't write to this file. 1297 * @memberOf CeL.IO.Windows.file 1298 */ 1299 ForReading : 1, 1300 /** 1301 * Open a file for writing. 1302 * @memberOf CeL.IO.Windows.file 1303 */ 1304 ForWriting : 2, 1305 /** 1306 * Open a file and write to the end of the file. 1307 * @memberOf CeL.IO.Windows.file 1308 */ 1309 ForAppending : 8 1310 }; 1311 1312 CeL.IO.Windows.file 1313 . 1314 /** 1315 * FileSystemObject Object file open format enumeration 1316 * @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> 1317 * @memberOf CeL.IO.Windows.file 1318 */ 1319 open_format = { 1320 /** 1321 * Opens the file using the system default. 1322 * @memberOf CeL.IO.Windows.file 1323 */ 1324 TristateUseDefault : -2, 1325 /** 1326 * Opens the file as Unicode. 1327 * @memberOf CeL.IO.Windows.file 1328 */ 1329 TristateTrue : -1, 1330 /** 1331 * Opens the file as ASCII. 1332 * @memberOf CeL.IO.Windows.file 1333 */ 1334 TristateFalse : 0 1335 }; 1336 1337 1338 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, 1339 /** 1340 * FileSystemObject 1341 */ 1342 fso = WScript.CreateObject("Scripting.FileSystemObject"), 1343 // XMLHttp, 1344 WinShell // initWScriptObj 1345 , args, ScriptHost; 1346 1347 1348 /* ↑JScript only ------------------------------------------------------- 1349 */ 1350 1351 1352 1353 1354 /* 1355 1356 return {Object} report 1357 .list files matched 1358 .succeed success items 1359 .failed failed items 1360 .log log text 1361 .undo undo data 1362 1363 usage example: 1364 move_file() get file list array of current dir. 1365 move_file(0,0,'dir') get file list array of dir. 1366 move_file('*.*','*.jpg','dir') Error! Please use RegExp('.*\..*') or turnWildcardToRegExp('*.*') 1367 move_file(/file(\d+).jpg/,0,'dir') get file list array of dir/file(\d+).jpg 1368 move_file(f1,move_file.f.remove) delete f1 1369 move_file('f1','f2') [f1]->[f2] 1370 move_file('f1','f2','.',move_file.f.copy|move_file.f.reverse) copy [./f2] to [./f1] 1371 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 1372 1373 prog example: 1374 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;} 1375 var vol=11,doMove=move_file(new RegExp('(\\d+)\\('+vol+'\\)\\.pdf'),'$1.pdf'); 1376 write_to_file('move.log','-'.x(60)+new_line+doMove.log,open_format.TristateTrue,ForAppending); 1377 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 1378 alert('Done '+doMove.succeed+'/'+doMove.list.length); 1379 1380 for Win98, turn lower case: 1381 move_file(/^[A-Z\d.]+$/,function($0){return '_mv_tmp_'+$0.toLowerCase();},'.',move_file.f.include_folder|move_file.f.include_subfolder); 1382 alert(move_file(/^_mv_tmp_/,'','.',move_file.f.include_folder|move_file.f.include_subfolder).log); 1383 1384 1385 for(var i=0,j,n,m;i<40;i++) 1386 if(!fso.FileExists(n='0000'+(i>9?'':'0')+i+'.pdf'))for(j=0;j<25;j++) 1387 if(fso.FileExists(m='0000'+(i>9?'':'0')+i+'('+j+').pdf')){try{fso.MoveFile(m,n);}catch(e){}break;} 1388 1389 TODO: 1390 move newer 把新檔移到目的地,舊檔移到 bak。 1391 1392 */ 1393 CeL.IO.Windows.file 1394 . 1395 /** 1396 * move/rename files, ** use RegExp, but no global flag **<br/> 1397 * 可用 move_file_filter() 來排除不要的<br/> 1398 * 本函數可能暫時改變目前工作目錄! 1399 * @param from 1400 * @param to 1401 * @param base_path 1402 * @param flag 1403 * @param {Function} filter 可用 filter() 來排除不要的 1404 * @return {Object} report 1405 * @since 2004/4/12 17:25 1406 * @requires path_separator,fso,WshShell,new_line,Enumerator 1407 * @memberOf CeL.IO.Windows.file 1408 */ 1409 move_file = function(from, to, base_path, flag, filter) { 1410 var _s = arguments.callee, _f = _s.f 1411 // '.?': 一定會match 1412 default_from = new RegExp('.?'), t, CurrentDirectory, report = {}; 1413 // alert(typeof from+','+from.constructor); 1414 if (flag & _f.reverse) 1415 //flag-=_f.reverse, 1416 t = from, from = to, to = t; 1417 if (!from) 1418 from = default_from; 1419 else if (typeof from != 'string' 1420 && (typeof from != 'object' || !(from instanceof RegExp) 1421 && !(from = '' + from))) 1422 from = default_from; 1423 report.list = [], report.succeed = report.failed = 0, 1424 report.undo = report.log = ''; 1425 1426 if (!base_path) 1427 base_path = '.' + path_separator; 1428 else if (typeof get_folder === 'function') 1429 base_path = get_folder(base_path); 1430 1431 if ((base_path = '' + base_path).slice( 1432 // -1, or try: base_path.length-path_separator.length 1433 -1) != path_separator) 1434 base_path += path_separator; 1435 1436 if (typeof fso === 'undefined') 1437 fso = new ActiveXObject("Scripting.FileSystemObject"); 1438 else if (typeof fso !== 'object') 1439 throw new Error(1, 'fso was already seted!'); 1440 try { 1441 dir = fso.GetFolder(base_path); 1442 } catch (e) { 1443 throw new Error(e.number, 1444 'move_file(): 基準路徑不存在\n' + e.description); 1445 } 1446 1447 // TODO: 對from不存在與為folder之處裡:fuzzy 1448 1449 if (flag & _f.include_subfolder) { 1450 CurrentDirectory = WshShell.CurrentDirectory; 1451 for ( var i = new Enumerator(dir.SubFolders); !i.atEnd(); i 1452 .moveNext()) 1453 _s(from, to, i.item(), flag); 1454 if (base_path) 1455 // 改變目前工作目錄 1456 WshShell.CurrentDirectory = base_path; 1457 } 1458 // if(flag&_f.include_folder){} 1459 var i, f = new Enumerator(dir.Files), use_exact = typeof from === 'string', overwrite = flag 1460 & _f.overwrite, not_test = !(flag & _f.Test), func = flag 1461 & _f.copy ? 'copy' : to === _f.remove || flag & _f.remove 1462 && !to ? 'delete' : from != default_from || to ? 'move' 1463 : 'list'; 1464 // if(func=='delete')to=_f.remove; // 反正不是用這個判別的 1465 //alert('use_exact: '+use_exact+'\nbase_path: '+base_path+'\nfrom: '+from); 1466 // BUG: 這樣順序會亂掉,使得 traverse (遍歷)不完全 1467 for (; !f.atEnd(); f.moveNext()) 1468 if (i = f.item(), use_exact && i.Name == from || !use_exact 1469 && from.test(i.Name)) { 1470 report.list.push(i.Name); 1471 1472 if (typeof filter == 'function' && !filter(i.Name)) 1473 continue; 1474 t = func == 'copy' || func == 'move' ? i.Name.replace(from, 1475 typeof to === 'object' ? to.source : to) : ''; 1476 1477 if (t) 1478 try { 1479 report.log += func + ' [' + i.Name + ']' 1480 + (t ? ' to [' + t + '] ' : ''); 1481 var u = ''; 1482 t = (base_path == default_from ? base_path : '') 1483 + t; 1484 if (func == 'delete') { 1485 if (not_test) 1486 i.Delete(overwrite); 1487 } else if (!fso.FileExists(t) || overwrite) { 1488 if (not_test) { 1489 if (overwrite && fso.FileExists(t)) 1490 fso.DeleteFile(t); 1491 if (func == 'copy') 1492 // Copy() 用的是 FileSystemObject.CopyFile or FileSystemObject.CopyFolder, 亦可用萬用字元(wildcard characters) 1493 i.Copy(t, overwrite); 1494 else 1495 i.Move(t); 1496 } 1497 u = 'move ' + t + ' ' + i.Name + new_line; 1498 } else { 1499 report.log += ': target existing, '; 1500 throw 1; 1501 } 1502 report.log += 'succeed.' + new_line, 1503 report.undo += u, report.succeed++; 1504 } catch (e) { 1505 report.log += 'failed.' + new_line, report.failed++; 1506 } 1507 //alert(i.Name+','+t); 1508 } 1509 1510 if (flag & _f.include_subfolder && CurrentDirectory) 1511 WshShell.CurrentDirectory = CurrentDirectory; 1512 report.log += new_line + (not_test ? '' : '(test)') + func + ' [' 1513 + from + '] to [' + to + ']' + new_line 1514 + (typeof gDate == 'function' ? gDate() + ' ' : '') 1515 + 'done ' + report.succeed + '/' + report.list.length 1516 + new_line; 1517 return report; 1518 }; 1519 1520 //var move_file.f; 1521 //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'); 1522 CeL.IO.Windows.file 1523 . 1524 /** 1525 * <a href="#.move_file">move_file</a> 的 flag enumeration 1526 * @constant 1527 * @memberOf CeL.IO.Windows.file 1528 */ 1529 move_file.f = { 1530 /** 1531 * null flag 1532 * @memberOf CeL.IO.Windows.file 1533 */ 1534 none : 0, 1535 /** 1536 * overwrite target 1537 * @memberOf CeL.IO.Windows.file 1538 */ 1539 overwrite : 1, 1540 /** 1541 * If source don't exist but target exist, than reverse. 1542 * @deprecated TODO 1543 * @memberOf CeL.IO.Windows.file 1544 */ 1545 fuzzy : 2, 1546 /** 1547 * reverse source and target 1548 * @memberOf CeL.IO.Windows.file 1549 */ 1550 reverse : 4, 1551 /** 1552 * include folder 1553 * @memberOf CeL.IO.Windows.file 1554 */ 1555 include_folder : 8, 1556 /** 1557 * include sub-folder 1558 * @memberOf CeL.IO.Windows.file 1559 */ 1560 include_subfolder : 16, 1561 /** 1562 * Just do a test 1563 * @memberOf CeL.IO.Windows.file 1564 */ 1565 Test : 32, 1566 /** 1567 * copy, instead of move the file 1568 * @memberOf CeL.IO.Windows.file 1569 */ 1570 copy : 64, 1571 /** 1572 * 當 target 指定此 flag,或包含此 flag 而未指定 target 時,remove the source。 1573 * @memberOf CeL.IO.Windows.file 1574 */ 1575 remove : 128 1576 }; 1577 1578 CeL.IO.Windows.file 1579 . 1580 /** 1581 * move file 1582 * @requires fso,get_folder,getFN,initWScriptObj 1583 * @memberOf CeL.IO.Windows.file 1584 */ 1585 mv = function(from, to, dir, onlyFN, reverse) { 1586 if (!from || !to || from == to) 1587 return new Error(1, 'filename error.'); 1588 var e; 1589 dir = get_folder(dir); 1590 1591 if (reverse) 1592 e = from, from = to, to = e; 1593 e = function(_i) { 1594 return fso.FileExists(_i) ? _i : dir ? dir 1595 + (onlyFN ? getFN(_i) : _i) : null; 1596 }; 1597 1598 try { 1599 // alert('mv():\n'+dir+'\n\n'+e(from)+'\n→\n'+e(to)); 1600 fso.MoveFile(e(from), e(to)); 1601 return; 1602 } catch (e) { 1603 e.message = 'mv():\n' + from + '\n→\n' 1604 + to// +'\n\n'+e.message 1605 ; 1606 return e; 1607 } 1608 }; 1609 1610 1611 /* 1612 function mv(from,to,dir,onlyFN,reverse){ 1613 var e,_f,_t; 1614 dir=get_folder(dir); 1615 1616 if(reverse)e=from,from=to,to=e; 1617 _f=from; 1618 _t=to; 1619 to=0; 1620 e=function(_i){ 1621 return fso.FileExists(_i)?_i:dir&&fso.FileExists(_i=dir+(onlyFN?getFN(_i):_i))?_i:0; 1622 }; 1623 1624 try{ 1625 if(!(_f=e(_f)))to=1;else if(!(_t=e(_t)))to=2; 1626 else{ 1627 alert('mv():\n'+dir+'\n\n'+_f+'\n→\n'+_t); 1628 fso.MoveFile(_f,_t); 1629 return; 1630 } 1631 }catch(e){return e;} 1632 return e||new Error(to,(to==1?'移動するファイルは存在しない':'移動先が既存した')+':\n'+_f+'\n→\n'+_t); 1633 } 1634 1635 1636 function mv(from,to,dir,onlyFN,reverse){ 1637 var e,_f,_t; 1638 dir=get_folder(dir); 1639 1640 if(reverse)e=from,from=to,to=e; 1641 _f=from,_t=to,to=e=0; 1642 1643 try{ 1644 if(!fso.FileExists(_f)&&(!dir||!fso.FileExists(_f=dir+(onlyFN?getFN(_f):_f))))to=1; 1645 else if(fso.FileExists(_t)&&(!dir||fso.FileExists(_t=dir+(onlyFN?getFN(_t):_t))))to=2; 1646 else{ 1647 alert('mv():\n'+dir+'\n'+_f+'\n→\n'+_t); 1648 //fso.MoveFile(_f,_t); 1649 return; 1650 } 1651 }catch(e){} 1652 return e||new Error(to,(to==1?'移動するファイルは存在しない':'移動先が既存した')+':\n'+_f+'\n→\n'+_t); 1653 } 1654 1655 */ 1656 1657 1658 /* 1659 1660 下面一行調到檔案頭 1661 var get_file_details_items,get_file_details_get_object=-62.262; 1662 */ 1663 CeL.IO.Windows.file 1664 . 1665 /** 1666 * get file details (readonly) 1667 * @example 1668 * get_file_details('path'); 1669 * get_file_details('file/folder name',parentDir); 1670 * get_file_details('path',get_file_details_get_object); 1671 * @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> 1672 * @memberOf CeL.IO.Windows.file 1673 */ 1674 get_file_details = function(fileObj, parentDirObj) { 1675 var i, n, r; 1676 // WinShell=new ActiveXObject("Shell.Application"); 1677 if (typeof WinShell == 'undefined' || !fileObj) 1678 return; 1679 1680 // deal with fileObj & parentDirObj 1681 if (parentDirObj === get_file_details_get_object) 1682 parentDirObj = 0, n = 1; 1683 // else n=''; 1684 if (!parentDirObj) { 1685 // fileObj is path 1686 if (typeof fileObj != 'string') 1687 return; 1688 if (i = fileObj.lastIndexOf('/') + 1) 1689 parentDirObj = fileObj.slice(0, i - 1), fileObj = fileObj 1690 .slice(i); 1691 else 1692 return; 1693 } 1694 if (typeof parentDirObj == 'string') 1695 parentDirObj = WinShell.NameSpace(parentDirObj); 1696 if (typeof fileObj == 'string' && fileObj) 1697 fileObj = parentDirObj.ParseName(fileObj); 1698 if (n) 1699 // just get [(object)parentDirObj,(object)fileObj] 1700 return [ parentDirObj, fileObj ]; 1701 1702 // get item name 1703 if (typeof get_file_details_items != 'object') { 1704 get_file_details_items = []; 1705 for (i = 0, j; i < 99; i++) 1706 // scan cols 1707 if (n = WinShell.NameSpace(0).GetDetailsOf(null, i)) 1708 get_file_details_items[i] = n; 1709 } 1710 1711 // main process 1712 //for(i=0,r=[];i<get_file_details_items.length;i++) 1713 r = []; 1714 for (i in get_file_details_items) { 1715 //if(get_file_details_items[i]) 1716 r[get_file_details_items[i]] = r[i] = parentDirObj 1717 .GetDetailsOf(fileObj, i); 1718 } 1719 1720 return r; 1721 }; 1722 1723 1724 1725 1726 CeL.IO.Windows.file 1727 . 1728 /* 1729 TODO 1730 未來:change_attributes(path,'-ReadOnly&-Hidden&-System') 1731 1732 下面調到檔案頭 1733 setObjValue('Attribute','Normal=0,none=0,ReadOnly=1,Hidden=2,System=4,Volume=8,Directory=16,Archive=32,Alias=64,Compressed=128','int'); 1734 setObjValue('AttributeV','0=Normal,1=ReadOnly,2=Hidden,4=System,8=Volume,16=Directory,32=Archive,64=Alias,128=Compressed'); 1735 */ 1736 /** 1737 * 改變檔案之屬性 1738 * @param F file path 1739 * @param A attributes, 屬性 1740 * @example 1741 * change_attributes(path,'-ReadOnly'); 1742 * @memberOf CeL.IO.Windows.file 1743 */ 1744 change_attributes = function(F, A) { 1745 if (!F) 1746 return -1; 1747 if (typeof F === 'string') 1748 try { 1749 F = fso.GetFile(F); 1750 } catch (e) { 1751 return -2; 1752 } 1753 var a; 1754 try { 1755 a = F.Attributes; 1756 } catch (e) { 1757 return -3; 1758 } 1759 if (typeof A === 'undefined') 1760 A = a; 1761 else if (A === '' || A == 'Archive') 1762 A = 32; 1763 else if (A == 'Normal') 1764 A = 0; 1765 else if (isNaN(A)) 1766 if (A.charAt(0) === 'x' || A.charAt(0) === '-') 1767 if (A = -Attribute[A.substr(1)], A && a % (A << 2)) 1768 A = a + A; 1769 else 1770 A = a; 1771 else if (A = Attribute[A], A && a % (A << 2) == 0) 1772 A = a + A; 1773 else 1774 A = a; 1775 else if (AttributeV[A]) 1776 if (a % (A << 2) == 0) 1777 A = a + A; 1778 else 1779 A = a; 1780 else if (AttributeV[-A]) 1781 if (a % (A << 2)) 1782 A = a + A; 1783 else 1784 A = a; 1785 if (a != A) 1786 try { 1787 F.Attributes = A; 1788 } catch (e) { 1789 popErr(e); 1790 // 70:防寫(沒有使用權限) 1791 return 70 == (e.number & 0xFFFF) ? -8 : -9; 1792 } 1793 return F.Attributes; 1794 }; 1795 1796 1797 1798 1799 1800 CeL.IO.Windows.file 1801 . 1802 /** 1803 * 開檔處理<br/> 1804 * 測試是否已開啟資料檔之測試與重新開啟資料檔 1805 * @param FN file name 1806 * @param NOTexist if NOT need exist 1807 * @param io_mode IO mode 1808 * @return 1809 * @requires fso,WshShell,iomode 1810 * @memberOf CeL.IO.Windows.file 1811 */ 1812 openDataTest = function(FN, NOTexist, io_mode) { 1813 if (!FN) 1814 return 3; 1815 if (NOTexist && !fso.FileExists(FN)) 1816 return 0; 1817 if (!io_mode) 1818 io_mode = _.iomode.ForAppending; 1819 for (;;) 1820 try { 1821 var Fs = fso.OpenTextFile(FN, ForAppending); 1822 Fs.Close(); 1823 break; 1824 } catch (e) { 1825 // 對執行時檔案已經開啟之處理 1826 //if(typeof e=='object'&&e.number&&(e.number&0xFFFF)==70) 1827 if ((e.number & 0xFFFF) != 70) { 1828 return pErr(e, 0, 1829 '開啟資料檔 [<green>' + FN + '<\/>] 時發生錯誤!'), 1830 6 == alert( 1831 '開啟資料檔 [' + FN + ']時發生不明錯誤,\n 是否中止執行?', 1832 0, ScriptName + ' 測試是否已開啟資料檔:發生不明錯誤!', 1833 4 + 48) ? 1 : 0; 1834 } 1835 if (2 == WshShell.Popup( 1836 '★資料檔:\n\ ' + FN + '\n 無法寫入!\n\n可能原因與解決方法:\n ①資料檔已被開啟。執行程式前請勿以其他程式開啟資料檔!\n ②資料檔被設成唯讀,請取消唯讀屬性。', 1837 0, ScriptName + ':資料檔開啟發生錯誤!', 5 + 48)) 1838 return 2; 1839 } 1840 return 0; 1841 }; 1842 1843 CeL.IO.Windows.file 1844 . 1845 /** 1846 * 1847 * @param FN 1848 * @param format 1849 * @param io_mode 1850 * @return 1851 */ 1852 open_template = function(FN, format, io_mode) { 1853 /** 1854 * file 1855 * @inner 1856 * @ignore 1857 */ 1858 var F, 1859 /** 1860 * file streams 1861 * @inner 1862 * @ignore 1863 */ 1864 Fs; 1865 if (!io_mode) 1866 io_mode = _.iomode.ForReading; 1867 if (!format) 1868 //format=autodetectEncode(FN); 1869 format = _.open_format.TristateUseDefault;// TristateTrue 1870 try { 1871 F = fso.GetFile(FN); 1872 //Fs=_.open_file(FN,format,io_mode); 1873 Fs = F.OpenAsTextStream(io_mode, format); 1874 } catch (e) { 1875 // 指定的檔案不存在? 1876 pErr(e); 1877 // quit(); 1878 } 1879 return Fs; 1880 }; 1881 1882 //var openOut.f; // default format 1883 function openOut(FN,io_mode,format){ 1884 var OUT,OUTs,_f=arguments.callee.f; 1885 if(!io_mode)io_mode=_.iomode.ForWriting; 1886 if(!format)format=_f=='string'&&_f?_f:_.open_format.TristateUseDefault; 1887 try{ 1888 OUT=fso.GetFile(FN); 1889 } 1890 catch(e){try{ 1891 //指定的檔案不存在 1892 var tmp=fso.CreateTextFile(FN,true); 1893 tmp.Close(); 1894 OUT=fso.GetFile(FN); 1895 }catch(e){pErr(e);}} 1896 1897 try{OUTs=OUT.OpenAsTextStream(io_mode,format);}catch(e){pErr(e);} 1898 1899 return OUTs; 1900 }; 1901 1902 1903 1904 1905 1906 1907 1908 // 2007/5/31 21:5:16 1909 compressF.tool={ 1910 WinRAR:{path:'"%ProgramFiles%\\WinRAR\\WinRAR.exe"',ext:'rar' 1911 ,c:{cL:'$path $cmd $s $archive -- $files',cmd:'a' // cL:command line, c:compress, s:switch 1912 ,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等 1913 //,l:'-ilog logFN' 1914 } 1915 ,u:{cL:'$path $cmd $archive $eF $eTo',cmd:'e'} // uncompress 1916 ,t:{cL:'$path $cmd $archive',cmd:'t'} // test 1917 } 1918 ,'7-Zip':{path:'"%ProgramFiles%\\7-Zip\\7zg.exe"',ext:'7z' 1919 ,c:{cL:'$path $cmd $s $archive $files',cmd:'u',s:'-mx9 -ms -mhe -mmt -uy2'} // compress 1920 ,u:{cL:'$path $cmd $archive $eF $_e',cmd:'e',_e:function(fO){return fO.eTo?'-o'+fO.eTo:'';}} // uncompress 1921 ,t:{cL:'$path $cmd $archive',cmd:'t'} // test 1922 } 1923 } 1924 /* 1925 test: 1926 var base='C:\\kanashimi\\www\\cgi-bin\\program\\misc\\'; 1927 compress(base+'jit','_jit.htm',{tool:'7-Zip',s:''}); 1928 uncompress(base+'jit',base,{tool:'7-Zip'}); 1929 1930 1931 fO={ 1932 tool:'WinRAR' // or '7-Zip' 1933 ,m:'c' // method 1934 ,s:'' // switch 1935 ,archive:'' // archive file 1936 ,files='' // what to compress 1937 ,eTo='' // where to uncompress 1938 ,eF='' // what to uncompress 1939 ,rcL=1 // rebuild command line 1940 } 1941 */ 1942 // solid, overwrite, compressLevel, password 1943 function compressF(fO){ // flags object 1944 // 參數檢查: 未完全 1945 if(!fO)fO={}; 1946 if(typeof fO!='object')return; 1947 if(!fO.tool)fO.tool='WinRAR'; 1948 //if(!fO.m)fO.m='c';//method 1949 if(!fO.m||!fO.archive&&(fO.m!='c'||fO.m=='c'&&!fO.files))return; 1950 if(fO.m=='c'){ 1951 if(typeof fO.files!='object')fO.files=fO.files?[fO.files]:fO.archive.replace(/\..+$/,''); 1952 if(!fO.archive)fO.archive=fO.files[0].replace(/[\\\/]$/,'')+_t.ext; 1953 fO.files='"'+fO.files.join('" "')+'"'; 1954 } 1955 var i,_t=compressF.tool[fO.tool],_m,_c; 1956 if(!_t||!(_m=_t[fO.m]))return; 1957 else if(!/\.[a-z]+$/.test(fO.archive))fO.archive+='.'+_t.ext; 1958 //if(fO.bD)fO.archive=fO.bD+(/[\\\/]$/.test(fO.bD)?'':'\\')+fO.archive; // base directory, work directory, base folder 1959 if(!/["']/.test(fO.archive))fO.archive='"'+fO.archive+'"'; 1960 //alert('compressF(): check OK.'); 1961 // 構築 command line 1962 if(_m._cL&&!fO.rcL)_c=_m._cL; // rebuild command line 1963 else{ 1964 _c=_m.cL.replace(/\$path/,_t.path); 1965 for(i in _m)if(typeof fO[i]=='undefined')_c=_c.replace(new RegExp('\\$'+i),typeof _m[i]=='function'?_m[i](fO):_m[i]||''); 1966 _m._cL=_c; 1967 //alert('compressF():\n'+_c); 1968 } 1969 for(i in fO)_c=_c.replace(new RegExp('\\$'+i),fO[i]||''); 1970 if(_c.indexOf('$')!=-1){alert('compressF() error:\n'+_c);return;} 1971 alert('compressF() '+(_c.indexOf('$')==-1?'run':'error')+':\n'+_c); 1972 // run 1973 WshShell.Run(_c,0,true); 1974 } 1975 //compress[generateCode.dLK]='compressF'; 1976 function compress(archive,files,fO){ // compress file path, what to compress, flags object 1977 if(!fO)fO={};else if(typeof fO!='object')return; 1978 if(!fO.m)fO.m='c'; 1979 if(archive)fO.archive=archive; 1980 if(files)fO.files=files; 1981 return compressF(fO); 1982 } 1983 //uncompress[generateCode.dLK]='uncompressF'; 1984 function uncompress(archive,eTo,fO){ // compress file path, where to uncompress, flags object 1985 if(!fO)fO={};else if(typeof fO!='object')return; 1986 if(!fO.m)fO.m='u'; 1987 if(!fO.eF)fO.eF=''; 1988 if(archive)fO.archive=archive; 1989 if(eTo)fO.eTo=eTo; 1990 return compressF(fO); 1991 }; 1992 1993 1994 1995 1996 1997 1998 1999 /* 2000 轉換捷徑, 傳回shortcut的Object. true path 2001 http://msdn2.microsoft.com/en-us/library/xk6kst2k.aspx 2002 http://yuriken.hp.infoseek.co.jp/index3.html 2003 */ 2004 var p; 2005 //dealShortcut[generateCode.dLK]='initWScriptObj';//,parseINI 2006 function dealShortcut(path,rtPath){ 2007 if(typeof path!='string')path=''; 2008 else if(/\.(lnk|url)$/i.test(path)){ 2009 var sc=WshShell.CreateShortcut(path),p=sc.TargetPath,_i; 2010 // 檔名有可能是不被容許的字元(不一定總是有'?'),這時只有.url以文字儲存還讀得到。 2011 if(/*(''+sc).indexOf('?')!=-1*/!p&&/\.url$/i.test(path)&&typeof parseINI=='function'){ 2012 p=parseINI(path,0,1); 2013 sc={_emu:p}; 2014 sc.TargetPath=(p=p.InternetShortcut).URL; 2015 for(_i in p)sc[_i]=p[_i]; 2016 /* 2017 URL File Format (.url) http://www.cyanwerks.com/file-format-url.html 2018 [DEFAULT] 2019 BASEURL=http://so.7walker.net/guide.php 2020 [DOC#n(#n#n#n…)] 2021 [DOC#4#5] 2022 BASEURL=http://www.someaddress.com/frame2.html 2023 [DOC_adjustiframe] 2024 BASEURL=http://so.7walker.net/guide.php 2025 ORIGURL=http://so.7walker.net/guide.php 2026 [InternetShortcut] 2027 URL=http://so.7walker.net/guide.php 2028 Modified=50A8FD7702D1C60106 2029 WorkingDirectory=C:\WINDOWS\ 2030 ShowCommand= // 規定Internet Explorer啟動後窗口的初始狀態:7表示最小化,3表示最大化;如果沒有ShowCommand這一項的話則表示正常大小。 2031 IconIndex=1 // IconFile和IconIndex用來為Internet快捷方式指定圖標 2032 IconFile=C:\WINDOWS\SYSTEM\url.dll 2033 Hotkey=1601 2034 2035 Hotkey: 2036 下面加起來: Fn 單獨 || (Fn || base) 擇一 + additional 擇2~3 2037 base: 2038 0=0x30(ASCII) 2039 9=0x39(ASCII) 2040 A=0x41(ASCII) 2041 Z=0x5a(ASCII) 2042 ;=0xba 2043 = 2044 , 2045 - 2046 . 2047 / 2048 `=0xc0 2049 [=0xdb 2050 \ 2051 ] 2052 '=0xde 2053 2054 Fn: 2055 F1=0x70 2056 .. 2057 F12=0x7b 2058 2059 additional: 2060 Shift=0x100 2061 Ctrl=0x200 2062 Alt=0x400 2063 2064 */ 2065 p=p.URL; 2066 } 2067 if(!rtPath)return sc; 2068 path=/^file:/i.test(p)?p.replace(/^[^:]+:\/+/,'').replace(/[\/]/g,'\\'):p; // /\.url$/i.test(path)?'':p; 2069 } 2070 return rtPath?path:null; 2071 }; 2072 2073 //filepath=OpenFileDialog(); 基於安全,IE無法指定初始值或型態 2074 //OpenFileDialog[generateCode.dLK]='IEA'; 2075 function OpenFileDialog(){ 2076 var IE=new IEA,o; 2077 if(!IE.OK(1))return null; 2078 IE.write('<input id="file" type="file"/>');// value="'+dP+'" useless 2079 with(IE.getE('file'))focus(),click(),o=value; 2080 //IE.setDialog(200,400).show(1); 2081 IE.quit(); 2082 return o||null; 2083 }; 2084 2085 2086 // 是否為檔案 2087 function isFile(p,c){//file path,create 2088 if(!p)return 0; 2089 if(typeof fso=='undefined') 2090 fso=new ActiveXObject("Scripting.FileSystemObject"); 2091 if(fso.FileExists(p)) 2092 return true; 2093 2094 p=getFN(p); 2095 if(c)try{c=fso.CreateTextFile(p,true);c.Close();}catch(e){} 2096 return fso.FileExists(p); 2097 }; 2098 // 是否為目錄 2099 function isFolder(p,c){if(!p)return 0;//path,create return 0:not,1:absolute,2:relative path 2100 if(fso.FolderExists(p=turnToPath(p)))return isAbsPath(p)?1:2; 2101 if(c)try{fso.CreateFolder(p);return isAbsPath(p)?1:2;}catch(e){} 2102 return 0; 2103 } 2104 // get directory name of a path 2105 function get_folder(FP,mode){ // mode=0:path,1:filename 2106 if(typeof FP=='object'&&typeof FP.Path=='string') 2107 if(typeof FP.IsRootFolder!='undefined')return FP.Path; 2108 else FP=FP.Path; 2109 if(typeof FP!='string')return ''; 2110 //else if(/^[a-z]$/i.test(FP))FP+=':\\'; 2111 //if(FP.slice(-1)!='\\')FP+='\\'; 2112 var i=FP.lastIndexOf('\\'); 2113 if(i==-1)i=FP.lastIndexOf('/'); 2114 return i==-1?FP:mode?FP.substr(i+1):FP.slice(0,i+1); 2115 } 2116 2117 2118 2119 // 取得下一個序號的檔名,如輸入pp\aa.txt將嘗試pp\aa.txt→pp\aa[pattern].txt 2120 function getNextSerialFN(FP,bs,pattern){ // FP:file path,bs:begin serial,pattern:增添主檔名的模式,包含Ser的部分將被轉換為序號 2121 if(!FP)return;if(isNaN(bs))if(!fso.FileExists(FP))return FP;else bs=0; 2122 var i=FP.lastIndexOf('.'),base,ext,Ser=':s:'; 2123 if(i==-1)base=FP,ext='';else base=FP.slice(0,i),ext=FP.substr(i); //fso.GetBaseName(filespec);fso.GetExtensionName(path);fso.GetTempName(); 2124 if(!pattern)pattern='_'+Ser;i=pattern.indexOf(Ser); 2125 if(i==-1)base+=pattern;else base+=pattern.slice(0,i),ext=pattern.substr(i+Ser.length)+ext; 2126 for(i=bs||0;i<999;i++)if(!fso.FileExists(base+i+ext))return base+i+ext; 2127 return; 2128 } 2129 2130 2131 CeL.IO.Windows.file 2132 . 2133 /** 2134 * 轉換以 adTypeBinary 讀到的資料 2135 * @example 2136 * // 較安全的讀檔: 2137 * t=translate_AdoStream_binary_data(read_all_file(FP,'binary')); 2138 * write_to_file(FP,t,'iso-8859-1'); 2139 * @see 2140 * <a href="http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html">Hawk's W3 Laboratory : Disposable WSH : 番外編:文字エンコーディングとADODB.Stream</a> 2141 * @memberOf CeL.IO.Windows.file 2142 */ 2143 translate_AdoStream_binary_data=function(data,len,type){ 2144 var _s = arguments.callee,_i=0,charArray,val,DOM=_s.XMLDOM,pos,txt; 2145 if(!DOM) 2146 try{ 2147 DOM=_s.XMLDOM=(new ActiveXObject("Microsoft.XMLDOM")).createElement('tmp'); // 要素名は何でも良い 2148 DOM.dataType='bin.hex'; 2149 }catch(e){return;} 2150 if(data!==0)DOM.nodeTypedValue=data,txt=DOM.text,pos=0;//binary data 2151 else pos=_s.pos,txt=_s.text; 2152 if(isNaN(len)||len>txt.length/2)len=txt.length/2; 2153 2154 if(type){ 2155 for(val=0;_i<len;i++)val=0x100*val+parseInt(txt.substr(pos,2),16),pos+=2; 2156 _s.pos=pos; 2157 return val; 2158 } 2159 2160 /* 2161 if(!(len>0)||len!=parseInt(len)) 2162 alert(pos+','+_i+'==0~len='+len+','+txt.slice(0,8)); 2163 */ 2164 charArray=new Array(parseInt(len)); // Error 5029 [RangeError] (facility code 10): 陣列長度必須是一有限的正整數 2165 for(;_i<len;_i++) // 極慢!用charString+=更慢。 2166 try{ 2167 //if(_i%100000==0)alert(i); 2168 //if(_i==40)alert(String.fromCharCode(parseInt(txt.substr(pos,2),16))+'\n'+charArray.join('')); 2169 charArray.push(String.fromCharCode(parseInt(txt.substr(pos,2),16))),pos+=2; 2170 //charArray[_i]=String.fromCharCode((t.charCodeAt(_i<<1)<<8)+t.charCodeAt((_i<<1)+1)); 2171 }catch(e){ 2172 e.description='translate_AdoStream_binary_data: 輸入了錯誤的資料:\n'+e.description; 2173 throw e; 2174 } 2175 if(!data)_s.pos=pos; 2176 return charArray.join(''); 2177 }; 2178 2179 CeL.IO.Windows.file 2180 . 2181 /** 2182 * 轉換以 adTypeBinary 讀到的資料 2183 * @param data 以 adTypeBinary 讀到的資料 2184 * @param pos position 2185 * @since 2007/9/19 20:58:26 2186 * @memberOf CeL.IO.Windows.file 2187 */ 2188 Ado_binary = function(data,pos){ 2189 this.newDOM(); 2190 2191 if(typeof data=='string'){ 2192 if(!data||typeof getFP=='function'&&!(data=getFP(data)))return; 2193 this.newFS(data); 2194 this.setPos(pos||0); 2195 }else this.setData(data,pos); 2196 }; 2197 CeL.IO.Windows.file 2198 . 2199 /** 2200 * @memberOf CeL.IO.Windows.file 2201 */ 2202 Ado_binary.prototype={ 2203 /** 2204 * 設定 data 2205 * 2206 * @param data binary data 2207 * @param pos 2208 * @return 2209 * @memberOf CeL.IO.Windows.file 2210 */ 2211 setData : function(data, pos) { 2212 this.DOM.nodeTypedValue = data,// binary data 2213 this.bt = this.DOM.text;// binary text 2214 if (!this.AdoS) 2215 this.len = this.bt.length / 2; 2216 this.setPos(pos || 0); 2217 }, 2218 setPos : function(p) { 2219 if (!isNaN(p)) { 2220 if (p < 0) 2221 p = 0; 2222 else if (p > this.len) 2223 p = this.len; 2224 this.pos = p; 2225 } 2226 return this.pos; 2227 }, 2228 testLen : function(len) { 2229 if (!len || len < 0) 2230 len = this.len; 2231 if (this.pos + len > this.len) 2232 len = this.len - this.pos; 2233 return len; 2234 }, 2235 /** 2236 * read data 2237 * @private 2238 * @param len length 2239 * @return 2240 * @memberOf CeL.IO.Windows.file 2241 */ 2242 readData : function(len) { 2243 this.AdoS.Position = this.pos; 2244 var _data = this.AdoS.Read(len); 2245 // 讀 binary data 用 'iso-8859-1' 會 error encoding. 2246 this.setData(_data, this.AdoS.Position); 2247 }, 2248 read : function(len) { 2249 var charArray = new Array(len = this.testLen(len)), _i = 0; 2250 this.readData(len); 2251 for (; _i < len; _i++) 2252 try { 2253 charArray.push(String.fromCharCode(parseInt(this.bt 2254 .substr(2 * _i, 2), 16))); 2255 // charArray[i]=String.fromCharCode((t.charCodeAt(i<<1)<<8)+t.charCodeAt((i<<1)+1)); 2256 } catch (e) { 2257 this.retErr(e); 2258 } 2259 return charArray.join(''); 2260 }, 2261 readNum : function(len) { 2262 len = this.testLen(len); 2263 this.readData(len); 2264 var val = 0, _i = len; 2265 for (; _i > 0;) 2266 try { 2267 val = 0x100 * val 2268 + parseInt(this.bt.substr(2 * (--_i), 2), 16); 2269 } catch (e) { 2270 this.retErr(e); 2271 } 2272 return val; 2273 }, 2274 readHEX : function(len) { 2275 len = this.testLen(len); 2276 this.readData(len); 2277 return this.bt; 2278 }, 2279 retErr : function(e) { 2280 e.description = 'translate_AdoStream_binary_data: 輸入了錯誤的資料:\n' + e.description; 2281 throw e; 2282 }, 2283 /** 2284 * @private 2285 * @return 2286 * @memberOf CeL.IO.Windows.file 2287 */ 2288 newDOM : function() { 2289 this.DOM = null; 2290 // try{ 2291 this.DOM = (new ActiveXObject("Microsoft.XMLDOM")) 2292 .createElement('tmp' + Math.random()); // 要素名は何でも良い 2293 // }catch(e){return;} 2294 this.DOM.dataType = 'bin.hex'; 2295 }, 2296 /** 2297 * @private 2298 * @param FP 2299 * @return 2300 * @memberOf CeL.IO.Windows.file 2301 */ 2302 newFS : function(FP) { 2303 if (FP) 2304 this.FP = FP; 2305 else if (!(FP = this.FP)) 2306 return; 2307 var _i = _.open_file.returnADO; 2308 _.open_file.returnADO = true; 2309 this.AdoS = _.open_file(FP, 'binary'); 2310 _.open_file.returnADO = _i; 2311 if (!this.AdoS) 2312 return; 2313 this.AdoS.LoadFromFile(FP); 2314 this.len = this.AdoS.Size; 2315 }, 2316 /** 2317 * 實際上沒多大效用。實用解決法:少用 AdoStream.Write() 2318 * @return 2319 * @memberOf CeL.IO.Windows.file 2320 */ 2321 renew : function() { 2322 this.bt = this.data = 0; 2323 this.newDOM(); 2324 if (this.AdoS && this.FP) { 2325 this.pos = this.AdoS.Position; 2326 this.AdoS.Close(); 2327 this.AdoS = null; 2328 this.newFS(); 2329 } 2330 }, 2331 destory : function(e) { 2332 if (this.AdoS) 2333 this.AdoS.Close(); 2334 this.AdoS = this.pos = this.bt = this.data = 0; 2335 } 2336 }; // Ado_binary.prototype={ 2337 2338 2339 /* 2340 // 速度過慢,放棄。 2341 //_.open_file.returnADO=true; 2342 function dealBinary(FP,func,interval){ 2343 var t,fs=_.open_file(FP,'binary',ForReading); 2344 if(!fs)return; 2345 AdoStream.LoadFromFile(FP); 2346 if(!interval)interval=1; 2347 //alert(fs.size) 2348 while(!fs.EOS) 2349 if(func(translate_AdoStream_binary_data(fs.Read(interval))))return; 2350 func(); 2351 fs.Close(); 2352 } 2353 */ 2354 2355 /* 配合simple系列使用 2356 http://thor.prohosting.com/~mktaka/html/utf8.html 2357 http://www.andrewu.co.uk/webtech/comment/?703 2358 http://www.blueidea.com/bbs/NewsDetail.asp?id=1488978 2359 http://www.blueidea.com/bbs/NewsDetail.asp?GroupName=WAP+%BC%BC%CA%F5%D7%A8%C0%B8&DaysPrune=5&lp=1&id=1524739 2360 C# http://www.gotdotnet.com/team/clr/bcl/TechArticles/TechArticles/IOFAQ/FAQ.aspx 2361 http://www.sqlxml.org/faqs.aspx?faq=2 2362 http://www.imasy.or.jp/~hir/hir/tech/js_tips.html 2363 2364 ADODB.Stream 最大問題:不能append 2365 http://msdn2.microsoft.com/en-us/library/ms808792.aspx 2366 http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoenumerations.asp 2367 http://study.99net.net/study/web/asp/1067048121.html http://www.6to23.com/s11/s11d5/20031222114950.htm 2368 http://blog.csdn.net/dfmz007/archive/2004/07/23/49373.aspx 2369 */ 2370 var AdoStream,AdoEnums; // ADO Enumerated Constants http://msdn.microsoft.com/library/en-us/ado270/htm/mdmscadoenumerations.asp 2371 /* 搬到前面 2372 setObjValue('AdoEnums','adTypeBinary=1,adTypeText=2' // StreamTypeEnum 2373 +',adReadAll=-1,adReadLine=-2' // StreamReadEnum http://msdn2.microsoft.com/en-us/library/ms806462.aspx 2374 +',adSaveCreateNotExist=1,adSaveCreateOverWrite=2' // SaveOptionsEnum 2375 +',adCR=13,adCRLF=-1,adLF=10' // LineSeparatorsEnum 2376 ,'int'); 2377 */ 2378 AdoEnums = { 2379 adTypeBinary : 1, 2380 adTypeText : 2, 2381 adReadAll : -1, 2382 adReadLine : -2, 2383 adSaveCreateNotExist : 1, 2384 adSaveCreateOverWrite : 2, 2385 adCR : 13, 2386 adCRLF : -1, 2387 adLF : 10 2388 }; 2389 2390 2391 //_.open_file[generateCode.dLK]='AdoEnums,simpleFileErr,ForReading,ForWriting,ForAppending,TristateUseDefault';//AdoStream 2392 CeL.IO.Windows.file 2393 . 2394 /** 2395 * 提供給 <a href="#.read_all_file">read_all_file</a>, <a href="#.write_to_file">write_to_file</a> 使用的簡易開檔函數 2396 * @param FN file path 2397 * @param format open format, e.g., open_format.TristateUseDefault 2398 * @param io_mode open mode, e.g., iomode.ForWriting 2399 * @memberOf CeL.IO.Windows.file 2400 */ 2401 open_file=function(FN,format,io_mode){ 2402 //if(!FN||typeof isAbsPath=='function'&&typeof getFN=='function'&&!isAbsPath(FN)&&!(FN=getFN(FN)))return; 2403 //if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return; 2404 var _s = arguments.callee; 2405 if(typeof format=='string'){ 2406 if(!_s.returnADO&&typeof AdoStream!='undefined') 2407 try{AdoStream.Close();AdoStream=null;}catch(e){} 2408 try{ 2409 AdoStream=new ActiveXObject("ADODB.Stream");//var objStream=Server.CreateObject("ADODB.Stream"); // ASPの場合,Err.Number=-2147221005表不支援 2410 }catch(e){simpleFileErr=e;AdoStream=null;} 2411 if(AdoStream){ 2412 //AdoStream.Mode=3; // read write 2413 if(format=='binary')AdoStream.Type=AdoEnums.adTypeBinary; // 以二進位方式操作 2414 else{ 2415 AdoStream.Type=AdoEnums.adTypeText; 2416 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 2417 } 2418 AdoStream.Open(); 2419 //AdoStream.Position=0,AdoStream.LineSeparator=AdoEnums.adLF; 2420 if(_s.returnADO){var _A=AdoStream;AdoStream=null;return _A;} 2421 return 0; 2422 } 2423 format=0; 2424 } 2425 var fs; 2426 // 使用某些防毒軟體(如諾頓 Norton)時,.OpenTextFile() 可能會被攔截,因而延宕。 2427 try{ 2428 if(io_mode==_.iomode.ForAppending&&!fso.FileExists(FN))io_mode=_.iomode.ForWriting; // 無此檔時改 writing 2429 fs=fso.OpenTextFile(FN,io_mode||_.iomode.ForReading,io_mode==_.iomode.ForWriting/*create*/,format||_.open_format.TristateUseDefault); 2430 }catch(e){ 2431 simpleFileErr=e; 2432 try{fs.Close();}catch(e){} 2433 return -1; 2434 } 2435 return fs; 2436 }; 2437 CeL.IO.Windows.file 2438 .open_file.returnADO=false; 2439 CeL.IO.Windows.file 2440 .open_file.error; 2441 2442 // 若是僅使用普通的開檔方法(_.open_format.TristateTrue/_.open_format.TristateFalse等,不使用ADODB.Stream),直接引用下兩函數與fso段定義即可。否則還需要引入_.open_file(),setObjValue(),dQuote() 2443 var simpleFileErr,simpleFileAutodetectEncode=-5.4,simpleFileDformat=_.open_format.TristateUseDefault;//_autodetect autodetectEncode(file) 2444 //_.read_all_file[generateCode.dLK]=_.write_to_file[generateCode.dLK]='simpleFileErr,simpleFileAutodetectEncode,simpleFileDformat,initWScriptObj';//_.open_file,autodetectEncode,getFP,_.open_format.TristateUseDefault 2445 //_.read_all_file[generateCode.dLK]+=',ForReading';_.write_to_file[generateCode.dLK]+=',ForWriting'; 2446 //_.read_all_file[generateCode.dLK]+=',translate_AdoStream_binary_data'; // for _.read_all_file(FP,'binary') 2447 CeL.IO.Windows.file 2448 . 2449 /** 2450 * 讀取檔案 2451 * @param FN file path 2452 * @param format open encode = simpleFileDformat 2453 * @param io_mode open IO mode = ForReading 2454 * @param func do this function per line, or [func, maxsize] (TODO) 2455 * @return {String} 檔案內容 2456 * @memberOf CeL.IO.Windows.file 2457 */ 2458 read_all_file=function(FN,format,io_mode,func){ 2459 simpleFileErr=0;if(format==simpleFileAutodetectEncode) 2460 format=typeof autodetectEncode=='function'?autodetectEncode(FN):simpleFileDformat; 2461 if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return; 2462 //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;} 2463 var a,fs;//,i,s=0,t; 2464 if(typeof _.open_file!='function') 2465 //{if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return; 2466 try{fs=fso.OpenTextFile(FN,io_mode||_.iomode.ForReading,false/*create*/,format||simpleFileDformat);} 2467 catch(e){simpleFileErr=e;return;} 2468 else if(fs=_.open_file(FN,format||simpleFileDformat,io_mode||_.iomode.ForReading),fs===-1)return; 2469 2470 //if(func instanceof Array)s=func[1],func=func[0]; 2471 if(fs!==0)try{ 2472 if(func) 2473 while(!fs.AtEndOfStream)func(fs.ReadLine()); 2474 /* 2475 while(!fs.AtEndOfStream){ 2476 for(t='',i=0;!fs.AtEndOfStream&&(!t||i<s);i++) 2477 t+=fs.ReadLine(); 2478 a+=func(t); 2479 } 2480 */ 2481 else a=fs.ReadAll(); 2482 fs.Close(); 2483 }catch(e){simpleFileErr=e;try{fs.Close();}catch(e){}return;} 2484 else if(typeof AdoStream!='undefined'&&AdoStream) 2485 try{ 2486 AdoStream.LoadFromFile(FN); 2487 if(AdoStream.Type==AdoEnums.adTypeBinary){ 2488 a=AdoStream.Read(AdoEnums.adReadAll); // 讀 binary data 用 'iso-8859-1' 會 error encoding. 2489 if(_.read_all_file.turnBinToStr&&typeof translate_AdoStream_binary_data=='function')a=translate_AdoStream_binary_data(a); 2490 }else if(func) 2491 while(!AdoStream.EOS)func(AdoStream.ReadText(AdoEnums.adReadLine)); 2492 /* 2493 while(!AdoStream.EOS){ 2494 for(t='',i=0;!AdoStream.AtEndOfStream&&(!t||i<s);i++) 2495 t+=AdoStream.ReadText(AdoEnums.adReadLine); 2496 a+=func(t); 2497 } 2498 */ 2499 else a=AdoStream.ReadText(AdoEnums.adReadAll); 2500 AdoStream.Close(); 2501 }catch(e){ 2502 simpleFileErr=e; 2503 try{AdoStream.Close();}catch(e){} 2504 return; 2505 } 2506 else simpleFileErr=new Error(1,'unknown error!'),simpleFileErr.name='unknownError'; 2507 return a; 2508 }; 2509 CeL.IO.Windows.file 2510 .read_all_file.turnBinToStr=true; 2511 2512 2513 CeL.IO.Windows.file 2514 . 2515 /** 2516 * 將 content 寫入 file 2517 * ** ADODB.Stream does not support appending! 2518 * @param FN file path 2519 * @param content content to write 2520 * @param format open format = simpleFileDformat 2521 * @param io_mode write mode = ForWriting, e.g., ForAppending 2522 * @param N_O DO NOT overwrite 2523 * @return error No. 2524 * @memberOf CeL.IO.Windows.file 2525 */ 2526 write_to_file = function(FN, content, format, io_mode, N_O) { 2527 simpleFileErr = 0; 2528 if (format == simpleFileAutodetectEncode) 2529 format = typeof autodetectEncode == 'function' ? autodetectEncode(FN) 2530 : simpleFileDformat; 2531 if (!FN || typeof getFP == 'function' && !(FN = getFP(FN))) 2532 return 2; 2533 //var fs;try{fs=fso.OpenTextFile(FN,iomode||ForWriting,true,format||TristateUseDefault);}catch(e){return 2;}if(!fs)return 3; 2534 //try{fs.Write(content);}catch(e){return e.number&0xFFFF==5?5:4;} // 5:content中有此local無法相容的字元,例如在中文中寫入日文假名 2535 var fs; 2536 if (typeof _.open_file != 'function') 2537 // {if(!FN||typeof getFP=='function'&&!(FN=getFP(FN)))return 2; 2538 try { 2539 fs = fso.OpenTextFile(FN, io_mode || _.iomode.ForWriting, 2540 true/* create */, format || simpleFileDformat); 2541 if (!fs) 2542 return 3; 2543 } catch (e) { 2544 simpleFileErr = e; 2545 return 2; 2546 } 2547 else if (fs = _.open_file(FN, format || simpleFileDformat, io_mode 2548 || _.iomode.ForWriting), fs === -1) 2549 return 3; 2550 else if (!fs && isNaN(fs)) 2551 return 2; 2552 if (fs !== 0) 2553 try { 2554 fs.Write(content); 2555 fs.Close(); 2556 } catch (e) { 2557 simpleFileErr = e; 2558 try { 2559 fs.Close(); 2560 } catch (e) { 2561 } 2562 return simpleFileErr.number & 0xFFFF == 5 ? 5 : 4; 2563 } 2564 // AdoStream.SaveToFile()需在AdoStream.Write之後! 2565 else if (typeof AdoStream != 'undefined' && AdoStream) 2566 try { 2567 if (AdoStream.Type == AdoEnums.adTypeText) 2568 AdoStream.WriteText(content); 2569 else 2570 AdoStream.Write(content); 2571 AdoStream.SaveToFile(FN, io_mode 2572 || AdoEnums.adSaveCreateOverWrite); 2573 AdoStream.Close(); 2574 } catch (e) { 2575 simpleFileErr = e; 2576 try { 2577 AdoStream.Close(); 2578 } catch (e) { 2579 } 2580 return 6; 2581 } 2582 else { 2583 simpleFileErr = new Error(1, 'unknown error!'), 2584 simpleFileErr.name = 'unknownError'; 2585 return 1; 2586 } 2587 }; 2588 2589 // TODO: unfinished 2590 //simpleDealFile[generateCode.dLK]='autodetectEncode,_.read_all_file,_.write_to_file'; 2591 CeL.IO.Windows.file 2592 . 2593 simpleDealFile=function(inFN,func,outFN,format,io_mode,N_O){ 2594 if(!inFN)return; 2595 if(!outFN)outFN=inFN; 2596 var e=autodetectEncode(inFN),i=_.read_all_file(inFN,e),o=_.read_all_file(outFN,e),t=func(i,inFN); 2597 if(typeof t=='string'&&o!=t)return _.write_to_file(outFN,t,e,N_O); 2598 }; 2599 2600 /* 2601 var autodetectEncodeSP,autodetectEncodeCode; // 特殊字元,各種編碼及判別所需最短長度 2602 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,' 2603 +'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,' 2604 +'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,' 2605 +'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,' 2606 +'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,' 2607 +'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,' 2608 +'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,' 2609 +'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,' 2610 +'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,' 2611 +'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,' 2612 +'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,' 2613 +'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,' 2614 +'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,' 2615 +'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,' 2616 +'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,' 2617 +'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,' 2618 +'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,' 2619 +'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,' 2620 +'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,' 2621 +'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,' 2622 +'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,' 2623 +'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,' 2624 +'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,' 2625 +'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,' 2626 +'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,' 2627 +'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,' 2628 +'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,' 2629 +'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,' 2630 +'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,' 2631 +'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,' 2632 +'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,' 2633 +'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,' 2634 +'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,' 2635 +'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,' 2636 +'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,' 2637 +'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,' 2638 +'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,' 2639 +'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,' 2640 +'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,' 2641 +'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,' 2642 +'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,' 2643 +'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,' 2644 +'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,' 2645 +'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,' 2646 +'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,' 2647 +'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,' 2648 +'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,' 2649 +'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,' 2650 +'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,' 2651 +'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,' 2652 +'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,' 2653 +'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,' 2654 +'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,' 2655 +'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,' 2656 +'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,' 2657 +'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,' 2658 +'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,' 2659 +'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,' 2660 +'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,' 2661 +'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,' 2662 +'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,' 2663 +'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,' 2664 +'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,' 2665 +'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,' 2666 +'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,' 2667 +'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,' 2668 +'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); 2669 // HKEY_CLASSES_ROOT\MIME\Database\Charset 2670 // 將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字 2671 setObjValue('autodetectEncodeCode','GB2312=3000,Big5=3000,shift_jis=900,iso-8859-1=2000',1); 2672 2673 2674 TODO: 2675 只檢測常用的幾個字,無法判別才廣泛測試。 2676 */ 2677 //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)); 2678 /* 自動判別檔案(或字串)之編碼 文字エンコーディング判定を行う 2679 http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html 2680 http://www.ericphelps.com/q193998/ 2681 http://hp.vector.co.jp/authors/VA003334/ado/adostream.htm 2682 */ 2683 //autodetectEncode[generateCode.dLK]='isFile,simpleFileDformat,_.open_file,autodetectStringEncode,autodetectHTMLEncode'; 2684 CeL.IO.Windows.file 2685 . 2686 autodetectEncode=function(FN,isHTML){ 2687 var t,code; 2688 if(typeof ActiveXObject=='undefined'){alert("autodetectEncode: Can't find ActiveXObject!");return;} 2689 //if(typeof autodetectHTMLEncode!='function')isHTML=false; 2690 if(!isFile(FN))return FN.length<64?simpleFileDformat:(t=autodetectStringEncode(FN))?t:(isHTML||typeof isHTML=='undefined')&&(t=autodetectHTMLEncode(FN))?t:simpleFileDformat; 2691 _.open_file(FN,'iso-8859-1'); // 讀 binary data 用 'iso-8859-1' 會 error encoding. 2692 if(!AdoEnums||!AdoStream)return simpleFileDformat; 2693 AdoStream.LoadFromFile(FN); 2694 t=AdoStream.ReadText(3);//Read(3);// 2695 //alert(FN+'\n'+t.charCodeAt(0)+','+t.charCodeAt(1)+','+t.charCodeAt(2)); 2696 2697 //if(typeof t!='string')return simpleFileDformat;//t=''+t; // 此時type通常是unknown,不能用+= 2698 // Unicode的Byte Order Mark(BOM)在UTF-16LE(little endian)裏,它是以FF-FE這兩個bytes表達,在BE(big endian)裏,是FEFF。而在UTF-8裏,它是以EF-BB-BF這三個bytes表達。 2699 if(t.slice(0,2)=='\xFF\xFE')code='unicodeFFFE'; 2700 else if(t.slice(0,2)=='\xFE\xFF')code='unicode'; 2701 else if(t=='\xEF\xBB\xBF')code='UTF-8'; 2702 else{ 2703 // 即使是用OpenTextFile(_.open_format.TristateFalse),UTF-8還是會被轉換而判別不出來。 2704 // from http://www.hawk.34sp.com/stdpls/dwsh/charset_adodb.html 2705 var l,codes={},reg=new RegExp(),stream=new ActiveXObject("ADODB.Stream"); 2706 codes['iso-8859-1']='[\\x09\\x0a\\x0d\\x20-\\x7e]'; 2707 codes['big5']=codes['iso-8859-1']+ 2708 '|[\\xa4-\\xc6\\xc9-\\xf9][\\x40-\\xfe]'; // http://www.cns11643.gov.tw/web/word/big5/index.html 2709 codes['shift_jis']=codes['iso-8859-1']+ 2710 '|[\\x81-\\x9f\\xe0-\\xef\\xfa-\\xfc][\\x40-\\x7e\\x80-\\xfc]|[\\xa1-\\xdf]'; // http://hp.vector.co.jp/authors/VA013241/misc/shiftjis.html 2711 codes['euc-jp']=codes['iso-8859-1']+ 2712 '|\\x8f[\\xa1-\\xfe][\\xa1-\\xfe]|[\\xa1-\\xfe][\\xa1-\\xfe]|\\x8e[\\xa1-\\xdf]'; 2713 codes['utf-8']=codes['iso-8859-1']+ 2714 '|[\\xc0-\\xdf][\\x80-\\xbf]|[\\xe0-\\xef][\\x80-\\xbf]{2}|[\\xf0-\\xf7][\\x80-\\xbf]{3}'+ 2715 '|[\\xf8-\\xfb][\\x80-\\xbf]{4}|[\\xfc-\\xfd][\\x80-\\xbf]{5}'; 2716 codes['gb2312']=codes['iso-8859-1']+ // GBK 2717 '|[\\xa1-\\xf7][\\xa1-\\xfe]'; // http://zh.wikipedia.org/wiki/GB_18030 http://zh.wikipedia.org/wiki/GB_2312 2718 2719 stream.type=AdoEnums.adTypeBinary; 2720 stream.open(); 2721 stream.loadFromFile(FN); 2722 stream.position=0; 2723 t=stream.read(); 2724 stream.close(); 2725 stream=null; 2726 2727 t=translate_AdoStream_binary_data(t,4e3); 2728 2729 for(var _e in codes){ 2730 reg=new RegExp('^(?:'+codes[_e]+')'); 2731 var l=0,s=t; 2732 while(l!=s.length)l=s.length,s=s.replace(reg,""); 2733 if(s==""){code=_e;break;} 2734 } 2735 2736 } 2737 //sl('autodetectEncode: coding: ['+code+'] in parse 1.'); 2738 2739 // 假如是HTML檔,判斷是否有charset設定。這個判別放在unicode之後,其他自動判別之前。 2740 if(isHTML||typeof isHTML=='undefined'&&/\.s?html?$/i.test(FN)){ 2741 if(AdoStream.Type==AdoEnums.adTypeBinary)_.open_file(FN,'iso-8859-1'); 2742 AdoStream.Position=0,AdoStream.Charset='iso-8859-1'; // 讀 binary data 用 'iso-8859-1' 會 error encoding. 2743 if(t=autodetectHTMLEncode(AdoStream.ReadText(4e3)))code=t; 2744 } 2745 //sl('autodetectEncode: coding: ['+code+'] in parse 2.'); 2746 2747 //autodetectEncodeCode.GB2312=900000; // 4 test 2748 if(!code)for(var i in autodetectEncodeCode){ 2749 if(AdoStream.Type==AdoEnums.adTypeBinary)_.open_file(FN,'iso-8859-1'); 2750 if(AdoStream.Position=0,i==autodetectStringEncode(AdoStream.ReadText(autodetectEncodeCode[AdoStream.Charset=i]))){code=i;break;} 2751 } 2752 2753 AdoStream.Close(); 2754 return code||simpleFileDformat; // ascii=iso-8859-1,_autodetect,_autodetect_all 2755 }; 2756 2757 // 判斷HTML檔是否有charset設定 2758 function autodetectHTMLEncode(fc){ // file contents 2759 var t; 2760 if( fc.match(/<\s*meta\s+([^>]+)>/i) 2761 && ((t=RegExp.$1).match(/content="([^"]+)"/i)||t.match(/content=([^\w]+)/i)) 2762 && (t=RegExp.$1).match(/charset=([\w-]{2,})/i) 2763 || fc.match(/<\?\s*xml\s[^>]+\sencoding\s*=\s*["']([a-z\d\-]+)["']/i) 2764 ) 2765 return RegExp.$1; 2766 }; 2767 CeL.IO.Windows.file 2768 . 2769 /** 2770 * 靠常用字自動判別字串之編碼 string,預設編碼 2771 */ 2772 autodetectStringEncode=function(str){ 2773 if(typeof str!='string'||!(str=str.replace(/\s+/g,'')))return; 2774 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; 2775 //if(len>9000)len=9000; 2776 //var unknownC=''; 2777 2778 // char分類 2779 for(;i<len;i++) 2780 if(c=str.charCodeAt(i),c<0x80)ascii++; 2781 else if(c<0x100)asciiHigh++; 2782 else if(c>0x3040&&c<0x30ff)kana++; 2783 else if(c==0x30fb||c>0xff65&&c<0xff9e)halfwidthKatakana++; 2784 else if(c>=0x1100&&c<0x11fa||c>=0xac00&&c<0xad00||c>=0xd700&&c<0xd7a4)Hangul++; 2785 else if(c>0x4dff&&c<0x9fa6){kanji++,a=autodetectEncodeSP[c];if(a=='C')jianhuazi++;else if(a=='J')kokuji++;} 2786 else if(c>0xfa00&&c<0xfa6b){if(autodetectEncodeSP[c]=='J')kokuji++;} 2787 else if(c>0x2010&&c<0x2610||c>=0xfe30&&c<0xfe70||c>0xff00&&c<0xff5f)symbol++; 2788 else if(c>=0x3000&&c<0x3400||c>0x33ff&&c<0x4db6) 2789 if(autodetectEncodeSP[c]=='J')kokuji++;else symbol++; 2790 else unknown++;//,unknownC+=str.charAt(i); 2791 2792 //alert('len='+len+'\nkana='+kana+'\nkokuji='+kokuji+'\njianhuazi='+jianhuazi+'\nhalfwidthKatakana='+halfwidthKatakana+'\nHangul='+Hangul+'\nascii='+ascii+'\nasciiHigh='+asciiHigh+'\nkanji='+kanji+'\nsymbol='+symbol+'\nunknown='+unknown); 2793 //if(unknownC)alert('unknown:\n'+unknownC.slice(0,200));//alert(unknownC.slice(0,200)+'\n'+str.slice(0,1000)); 2794 // 依各種常用字母之條件判別 2795 return ascii+asciiHigh==len?'iso-8859-1' 2796 :unknown>.05*(len-ascii)?''//unicode // unknown不能太多 2797 :kana>.2*len&&kanji+kana+symbol>3*halfwidthKatakana?'shift_jis' 2798 :kanji+symbol>.7*(len-ascii)&&kana<.05*(len-ascii)? jianhuazi>.1*kanji?'GB2312':'Big5' 2799 :Hangul+symbol>.7*(len-ascii)?'korean'//ks_c_5601 2800 :kanji>.2*(len-ascii)? jianhuazi>.1*kanji?kokuji>.02*kanji?'unicode':'GB2312':kokuji>.02*kanji?'shift_jis':'Big5' 2801 :'';//unicode 2802 }; 2803 2804 /* 2805 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 2806 http://www.theorem.ca/~mvcorks/cgi-bin/unicode.pl.cgi?start=F900&end=FAFF http://homepage1.nifty.com/nomenclator/unicode/normalization.htm 2807 2808 Unicode的漢字大致是以康熙部首排序,不過間中有部分字排錯部首筆劃 2809 第一批在1993年加進Unicode的, 2810 於中國內地、台灣、南韓及日本已有字集的漢字, 2811 編碼於U+4E00至U+9FA5, 2812 亦有部分南韓重覆漢字被編到U+F900至U+FA0B、 2813 兩個Big-5重覆漢字被編到U+FA0C至U+FA0D、 2814 日本廠商漢字被編到U+FA0E至U+FA2D 2815 2816 全形符號(只限鍵盤上那94個)位於U+FF01至U+FF5E 2817 中日韓專用符號放到了U+3000至U+33FF內, 2818 其餘有部分符號放到了U+2XXX及U+FE30至U+FE6F 2819 2820 第二批在1999年加進Unicode的, 2821 加進了新加坡用漢字、南韓PKS C 5700-2 1994、 2822 部分CNS11643第三、四、十五字面等用字、 2823 未包括在第一批字的數個GB字集用字, 2824 被編入U+3400至U+4DB5 2825 2826 第三批在2001年加進Unicode的, 2827 加進了CNS11643第三、四、五、六、七、十五字面所有字、 2828 香港增補字集用字、四庫全書、辭海、辭源、康熙字典、 2829 漢語大字典、漢語大詞典內的所有用字, 2830 被編入U+20000至U+2A6D6 2831 JIS-X0213漢字被加到U+FA30至U+FA6A 2832 CNS11643重覆漢字被加到U+2F800至U+2FA1D 2833 2834 简化字总表 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 2835 简化字分布似乎並無規範,只好以array判斷: 2836 2837 <div id="dataGB"> 2838 http://cdns.twnic.net.tw/cjktable/simtab.html 2839 簡化字總表之 UNICODE 碼表 2840 </div> 2841 <div id="dataJP"> 2842 http://homepage2.nifty.com/TAB01645/ohara/index_j2.htm 2843 JIS区点索引 2844 </div> 2845 2846 <script type="text/javascript"> 2847 var i=0,c=0,autodetectEncodeSP=[],m=document.getElementById('dataGB').innerHTML.match(/\([0-9A-F]{4},\w*\)/g),t="setObjValue('autodetectEncodeSP','"; 2848 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); 2849 if(m[i].indexOf('T')==-1)autodetectEncodeSP[parseInt(m[i].substr(1,4),16)]='C'; 2850 for(i=0,m=document.getElementById('dataJP').innerHTML.match(/【.】/g);i<m.length;i++) 2851 autodetectEncodeSP[parseInt(m[i].charCodeAt(1))]=autodetectEncodeSP[parseInt(m[i].charCodeAt(1))]?0:'J'; 2852 2853 m=[];for(i in autodetectEncodeSP)m.push(parseInt(i));m.sort(); 2854 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/>+'";} 2855 alert(c+'字'); 2856 document.getElementById('dataJP').innerHTML=''; 2857 document.getElementById('dataGB').innerHTML=t.slice(0,-1)+"',1,16);"; 2858 </script> 2859 2860 2861 和製漢字(国字)は、和語(ヤマトコトバ)に相当する漢字が無い場合に新規につくられたもので、奈良時代から作られた。ほとんどは訓読みしかない。魚篇や木篇が多い。 2862 http://homepage2.nifty.com/TAB01645/ohara/index.htm 2863 http://zh.wiktionary.org/wiki/%E8%BE%BB 2864 http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=8fbb 2865 http://jprs.jp/doc/rule/saisoku-1-wideusejp-furoku-4.html 2866 http://m2000.idv.tw/informer/zhi/char-root.htm 2867 http://www.ajisai.sakura.ne.jp/~dindi/chrc/ref/wincode2.txt 2868 http://cs-people.bu.edu/butta1/personal/hkscs/hkscs-oct.html 2869 http://www.nobi.or.jp/i/kotoba/kanji/wasei-kanji.html 2870 http://www.melma.com/mag/52/m00011552/a00000066.html 2871 2872 2873 韓語字母/諺文 2874 http://www.sinica.edu.tw/~cytseng/Korean%20reader/hangul.htm 2875 http://www.unicode.org/charts/normalization/ 2876 2877 old: 2878 // 自動判別檔案(或字串)之編碼 2879 function autodetectEncode(FN){ 2880 if(!isFile(FN))return FN.length>64?autodetectStringEncode(FN):simpleFileDformat; 2881 _.open_file(FN,'iso-8859-1'); 2882 if(!AdoEnums)return simpleFileDformat; 2883 //AdoStream.Type=AdoEnums.adTypeBinary; 2884 AdoStream.LoadFromFile(FN); 2885 var t=AdoStream.ReadText(3),code; 2886 // Unicode的Byte Order Mark(BOM)在UTF-16LE(little endian)裏,它是以FF-FE這兩個bytes表達,在BE(big endian)裏,是FEFF。而在UTF-8裏,它是以EF-BB-BF這三個bytes表達。 2887 if(t.slice(0,2)=='\xFF\xFE')code='unicodeFFFE'; 2888 if(t.slice(0,2)=='\xFE\xFF')code='unicode'; 2889 if(t=='\xEF\xBB\xBF')code='UTF-8'; 2890 if(code){AdoStream.Close();return code;} 2891 2892 if(!code)with(AdoStream){ 2893 // 將sjis排在gb與Big5前面是因為sjis常符合gb,且sjis之判定相當嚴。 2894 if(!code)Position=0,Charset='shift_jis',code=autodetectStringEncode(ReadText(900),Charset); 2895 // 將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字 2896 if(!code)Position=0,Charset='GB2312',code=autodetectStringEncode(ReadText(2000),Charset); 2897 if(!code)Position=0,Charset='Big5',code=autodetectStringEncode(ReadText(2000),Charset); 2898 } 2899 2900 AdoStream.Close(); 2901 return code||simpleFileDformat; // ascii=iso-8859-1,_autodetect,_autodetect_all 2902 } 2903 // 靠常用字自動判別字串之編碼 string,預設編碼 2904 function autodetectStringEncode(str,dcode){ 2905 var code; 2906 if(str.length>9000)str=str.slice(0,9000); 2907 2908 // 將sjis排在gb與Big5前面是因為sjis常符合gb,且sjis之判定相當嚴。 2909 if(dcode=='shift_jis'||!dcode&&!code){ 2910 // http://www.asahi-net.or.jp/~hc3j-tkg/unicode/ http://www.unicode.org/Public/UNIDATA/DerivedCoreProperties.txt 2911 var i=0,c,k=0,u=0,h=0;//h_=u_=k_=''; 2912 for(;i<str.length;i++)if(c=str.charCodeAt(i),c>0xFF) 2913 if(c==0x30FB||c>0xFF65&&c<0xFF9E)h++;//,h_+=str.charAt(i);//||c==0xE134 // HALFWIDTH KATAKANA LETTER等可能不是日文文件中會出現的char 2914 else if(c>0x3040&&c<0x30FF)k++;//,k_+=str.charAt(i); // kana 2915 else u++;//,u_+=str.charAt(i); // unknown kanji 2916 //alert(k+','+u+','+h+'\n*'+k_+'\n*'+u_+'\n*'+h_);//alert(u_.charCodeAt(2)); 2917 if(k+u>2*h)code='shift_jis'; // HALFWIDTH KATAKANA LETTER數目比漢字少時判別為shift_jis 2918 } 2919 2920 // 將gb排在Big5前面是因為gb常用字在Big5中常常是0x8000之後的常用字,Big5常用字卻常常是gb中奇怪字碼與罕用字 2921 if(dcode=='Big5'||dcode=='GB2312'||!dcode&&!code){ 2922 var i=0,c,k=0,u=0;//k_=u_=''; 2923 for(;i<str.length;i++)if(c=str.charCodeAt(i),c>0xFF) 2924 if(c>0x4DFF&&c<0x9FA6||c>0xFF00&&c<0xFF5F||c>0x33ff&&c<0x4DB6||c==0x2605||c==0x2606)k++;//,k_+=str.charAt(i); // 2605,6:★☆ 2925 else u++;//,u_+=str.charAt(i); 2926 //alert(k+','+u+'\n'+k_+'\n*'+u_); 2927 if(k>5*u)code=dcode||'Big5'; // 漢字比不認識的字多時判定 2928 } 2929 2930 if(dcode=='iso-8859-1'||dcode=='ascii'||!dcode&&!code){ 2931 } 2932 2933 return code; 2934 } 2935 */ 2936 2937 2938 /* 將 iso-8859-1 轉成utf-8 2939 To use: 2940 .. 2941 translated=turnBinStr(original); 2942 .. 2943 translated=turnBinStr(); // delete temp file 2944 */ 2945 turnBinStr.temp_file='turnBinStr.tmp'; // temp file name 2946 function turnBinStr(t,_enc){ 2947 if(typeof t!='undefined'){ 2948 if(!turnBinStr.tmpF)turnBinStr.tmpF=getFP(turnBinStr.temp_file,1); 2949 2950 //t+=''; 2951 //if(t.replace(/[^\x00-\x7f]+/g,''))return t; 2952 //var _q=t.replace(/[^?]+/g,'').length,_t,_j=0; 2953 _.write_to_file(turnBinStr.tmpF,''+t,'iso-8859-1'); 2954 //alert(turnBinStr.tmpF+'\n'+simpleFileErr.description+'\n'+t+'\n'+_.read_all_file(turnBinStr.tmpF,'utf-8')); 2955 return _.read_all_file(turnBinStr.tmpF,'utf-8'); 2956 /* 2957 if(!_enc)_enc='utf-8,Big5,shift_jis,euc-jp,GB2312'.split(','); 2958 else if(!(_enc instanceof Array))_enc=[_enc]; 2959 for(;_j<_enc.length;_j++) 2960 if((_t=_.read_all_file(turnBinStr.tmpF,_enc[_j])).replace(/[^?]+/g,'').length==_q) 2961 return _t;//'['+_enc[_j]+']'+ 2962 return t; 2963 */ 2964 } 2965 try{fso.DeleteFile(turnBinStr.tmpF);}catch(e){} // 有時會出錯 2966 } 2967 2968 2969 2970 2971 2972 //folder_info[generateCode.dLK]='initWScriptObj'; 2973 // 需同時修改if(traverseSubDirectory==folder_info.f.noNewObj)段落之return! 2974 2975 //setObjValue('folder_info.f','noNewObj=-1,files,dirs,fsize,size,Tsize=3,Tfiles,Tdirs',1); 2976 CeL.IO.Windows.file 2977 . 2978 /** 2979 * Get the infomation of folder 2980 * @param folder_path folder path 2981 * @param file_filter 2982 * @param traverseSubDirectory 2983 * @return 2984 * @example 2985 * var finfo=new folder_info(path or folder object,extFilter,0/1); 2986 * @deprecated 以 <a href="#.traverse_file_system">traverse_file_system</a> 代替 2987 * @memberOf CeL.IO.Windows.file 2988 */ 2989 folder_info=function(folder_path,file_filter,traverseSubDirectory){ 2990 var dir,filesCount,subDirectorysCount,total_size_of_files,total_size_of_this_folder,total_filesCount,total_subDirectorysCount; 2991 filesCount=subDirectorysCount=total_size_of_files=total_size_of_this_folder=total_filesCount=total_subDirectorysCount=0; 2992 if(typeof traverseSubDirectory=='undefined')traverseSubDirectory=1; 2993 2994 if(typeof folder_path=='object')dir=folder_path; 2995 else if(folder_path){ 2996 if(!folder_path.slice(-1)!=path_separator)folder_path+=path_separator; 2997 try{dir=fso.GetFolder(folder_path);}catch(e){dir=0;} 2998 } 2999 3000 if(dir){ 3001 total_subDirectorysCount=subDirectorysCount=dir.SubFolders.Count; 3002 var i,t,f=new Enumerator(dir.SubFolders); 3003 if(traverseSubDirectory||traverseSubDirectory==folder_info.f.noNewObj)for(;!f.atEnd();f.moveNext()){ 3004 i=f.item(); 3005 t=folder_info(i,file_filter,folder_info.f.noNewObj); 3006 //alert(i.path+'\n'+t[folder_info.f.size]+','+t[folder_info.f.Tfiles]+','+t[folder_info.f.Tdirs]); 3007 total_size_of_this_folder+=t[folder_info.f.size]; 3008 total_filesCount+=t[folder_info.f.Tfiles]; 3009 total_subDirectorysCount+=(t[folder_info.f.Tdirs]||0); 3010 } 3011 3012 //alert(dir.files.Count+'\n'+total_filesCount); 3013 total_filesCount+=(filesCount=dir.files.Count); 3014 f=new Enumerator(dir.files); 3015 for(;!f.atEnd();f.moveNext()){ 3016 i=f.item(); 3017 if(file_filter&&!file_filter.test(i.name))continue; 3018 //if(traverseSubDirectory!=folder_info.f.noNewObj)alert(i.name+': '+i.size+' / '+total_size_of_files); 3019 total_size_of_files+=i.size; 3020 } 3021 3022 total_size_of_this_folder+=total_size_of_files; 3023 } 3024 3025 //alert(dir.path+'\nfile filter: '+file_filter+'\n'+filesCount+','+subDirectorysCount+','+total_size_of_files+','+total_size_of_this_folder+','+total_filesCount+','+total_subDirectorysCount); 3026 if(traverseSubDirectory==folder_info.f.noNewObj) 3027 return [filesCount,subDirectorysCount,total_size_of_files,total_size_of_this_folder,total_filesCount,total_subDirectorysCount]; 3028 3029 this.files=this[folder_info.f.files]=filesCount; 3030 this.dirs=this[folder_info.f.dirs]=subDirectorysCount; 3031 this.fsize=this[folder_info.f.fsize]=total_size_of_files; 3032 this.size=this[folder_info.f.size]=total_size_of_this_folder; 3033 this.Tfiles=this[folder_info.f.Tfiles]=total_filesCount; 3034 this.Tdirs=this[folder_info.f.Tdirs]=total_subDirectorysCount; 3035 return this; 3036 }; 3037 CeL.IO.Windows.file 3038 . 3039 /** 3040 * <a href="#.folder_info">folder_info</a> 的 flag enumeration 3041 * @memberOf CeL.IO.Windows.file 3042 * @constant 3043 */ 3044 folder_info.f={ 3045 noNewObj:-1, 3046 files:0, 3047 dirs:1, 3048 fsize:2, 3049 size:3, 3050 Tsize:3, 3051 Tfiles:4, 3052 Tdirs:5 3053 }; 3054 3055 3056 /* list files of folder 改編自 folder_info() 3057 var files=new listFile(path or folder object,extFilter,flag); 3058 3059 */ 3060 //listFile[generateCode.dLK]='initWScriptObj'; 3061 // 需同時修改if(flag==listFile.f.noNewObj)段落之return! 3062 3063 //setObjValue('listFile.f','ignoreCase=1',1); 3064 listFile.f={ 3065 ignoreCase:1 3066 }; 3067 3068 function listFile(folder_path,file_filter,flag){ 3069 var files=[]; 3070 if(typeof flag=='undefined')flag=0; 3071 3072 if(typeof folder_path=='object')dir=folder_path; 3073 else if(folder_path){ 3074 if(!folder_path.slice(-1)!=path_separator)folder_path+=path_separator; 3075 try{dir=fso.GetFolder(folder_path);}catch(e){dir=0;} 3076 } 3077 3078 if(dir){ 3079 var i,f=new Enumerator(dir.files); 3080 for(;!f.atEnd();f.moveNext()){ 3081 i=f.item(); 3082 if(file_filter&&!file_filter.test(i.name))continue; 3083 files.push(i.name); 3084 } 3085 } 3086 3087 return files; 3088 } 3089 3090 3091 3092 3093 3094 3095 /* 3096 in UNIX: 3097 iconv -l 3098 iconv -c -f UTF-16 -t BIG5-HKSCS function.js 3099 3100 */ 3101 /** 3102 * 將編碼為fromCode之檔案fileName中所有不合編碼toCode之char以encodeFunction轉換 3103 * @param fileName 3104 * @param toCode 3105 * @param fromCode 3106 * @param encodeFunction 3107 * @return 3108 * @memberOf CeL.IO.Windows.file 3109 */ 3110 function iconv_file(fileName,toCode,fromCode,encodeFunction){ 3111 return iconv(_.read_all_file(fileName,fromCode),toCode,encodeFunction); 3112 } 3113 /* 將string text中所有不合編碼toCode之char以encodeFunction轉換 3114 3115 TODO: 3116 一次寫入多 bytes 3117 */ 3118 //var iconvError=[]; 3119 function iconv(text,toCode,encodeFunction){ 3120 if(!text)return ''; 3121 //alert('iconv: ['+toCode+']\n'+text.slice(0,200)); 3122 if(/utf-?(8|16)/i.test(toCode)) 3123 return HTMLToUnicode(text,1); 3124 if(_.open_file(0,toCode||simpleFileDformat)!==0) 3125 return text; 3126 //AdoStream.Type=AdoEnums.adTypeText; 3127 if(!encodeFunction)encodeFunction=toHTML; 3128 //iconvError=[]; 3129 3130 var charToSet,i=0,t=''; 3131 for(;i<text.length;i++)try{ 3132 charToSet=text.charAt(i); 3133 if(charToSet.charCodeAt(0)<256){t+=charToSet;continue;} // 對於過小的,直接匯入。 3134 AdoStream.Position=0; 3135 AdoStream.WriteText(charToSet); 3136 AdoStream.Position=0; 3137 t+=charToSet==AdoStream.ReadText(AdoEnums.adReadAll)?charToSet:encodeFunction(charToSet); 3138 }catch(e){ 3139 //iconvError.push(e.description); 3140 t+=encodeFunction(charToSet); 3141 } 3142 3143 try{AdoStream.Close();}catch(e){} 3144 return t; 3145 } 3146 3147 3148 3149 //--------------------------------------------------- 3150 3151 3152 /* 3153 var driverProperty,folderProperty,fileProperty; 3154 setObjValue('driverProperty','AvailableSpace,DriveLetter,DriveType,FileSystem,FreeSpace,IsReady,Path,RootFolder,SerialNumber,ShareName,TotalSize,VolumeName',1,setObjValueFlag.array); 3155 setObjValue('folderProperty','Attributes,DateCreated,DateLastAccessed,DateLastModified,Drive,Name,ParentFolder,Path,ShortName,ShortPath,Size,Type,Files,IsRootFolder,SubFolders',1,setObjValueFlag.array);//Files起為Folder property 3156 fileProperty=folderProperty.slice(0,12);//folderProperty.sort(); 3157 */ 3158 3159 3160 //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'); 3161 /* 3162 3163 _.traverse_file_system(FS_function_array) 省略path會當作所有Drives 3164 _.traverse_file_system(FS_function_array,'c:') c:→c:\→sub dir of c:\ 3165 _.traverse_file_system(FS_function_array,'c:\\') c:\→sub dir of c:\ 3166 _.traverse_file_system(FS_function_array,'c:\\cc') c:\cc,cc為dir→sub dir of c:\cc\ 3167 _.traverse_file_system(FS_function_array,'c:\\cc\\') c:\cc\→sub dir of c:\cc\ 3168 _.traverse_file_system(FS_function_array,['c:\\cc\\','d:\\dd']) c:\cc\→sub dir of c:\cc\→d:\dd→sub dir of d:\dd 3169 _.traverse_file_system([,folderFunction],'.'); 3170 3171 3172 _.traverse_file_system([,folderFunction],basePath); 3173 function folderFunction(folderItem){ 3174 t=folderItem.Path.slice(same_length(basePath,folderItem.Path)); 3175 //if(t==folderItem.Name) // 僅單層subdir次目錄 3176 //if(t.indexOf(path_separator)==t.lastIndexOf(path_separator)) // 僅單層及次層subdir次目錄 3177 if(t.replace(new RegExp('[^'+path_separator_RegExp+']','g'),'').length<3) // 僅3層subdir以下 3178 ; 3179 } 3180 3181 3182 // itemType=0:file/1:folder/2:driver 3183 function fsoFunction(fsi,itemType){if(!itemType){}} 3184 function fileFunction(fileItem){} 3185 function folderFunction(folderItem){} 3186 function driverFunction(driverItem){} 3187 3188 filter: 3189 file_filter 僅單一 filter 時預設當作 file_filter, should has NO global flag. 3190 [file_filter,folder_filter] 3191 file_filter 篩選檔案, should has NO global flag. 3192 folder_filter 篩選資料夾, should has NO global flag. 3193 3194 3195 tip: 3196 使用相對路徑,如'..'開頭時需用getFP()調整過。 3197 用folder.Size==0可判別是否為empty folder 3198 3199 TODO: 3200 限定traverse深度幾層,sort=8,preOrder=0,widthFirst=0,postOrder=16,depthFirst=16 3201 */ 3202 //_.traverse_file_system.stop=false; 3203 3204 //_.traverse_file_system[generateCode.dLK]='initWScriptObj'; 3205 CeL.IO.Windows.file 3206 . 3207 /** 3208 * 巡覽 file system 的公用函數 3209 * @param FS_function_array file system handle function array 3210 * @param path target path 3211 * @param filter filter 3212 * @param flag see <a href="#.traverse_file_system.f">flag</a> 3213 * @return 3214 * @memberOf CeL.IO.Windows.file 3215 * @see <a href="http://msdn.microsoft.com/library/en-us/script56/html/0fa93e5b-b657-408d-9dd3-a43846037a0e.asp">FileSystemObject</a> 3216 */ 3217 traverse_file_system = function(FS_function_array, path, filter, flag){ 3218 var _s = arguments.callee, _f = _s.f; 3219 3220 // initial 3221 // 預設 flag 3222 // if(isNaN(flag))flag=_f.traverse; 3223 3224 //library_namespace.log('traverse_file_system:\n[' + path + ']'); 3225 if (FS_function_array === _f.get_object) 3226 // or FS_function_array=[,,]: 可以使用 Array 常值中的空白元素來建立零星稀疏的陣列。 3227 FS_function_array = new Array(_f.func_length), 3228 flag = _f.get_object; 3229 else { 3230 /* 3231 if (FS_function_array instanceof Array && FS_function_array.length == 1) 3232 FS_function_array = FS_function_array[0]; 3233 */ 3234 if (typeof FS_function_array === 'function') { 3235 var i = FS_function_array; 3236 FS_function_array = [ i, i, i ]; 3237 } 3238 } 3239 //library_namespace.log('traverse_file_system: fso:\n[' + fso + ']'); 3240 if (typeof fso !== 'object' || !(FS_function_array instanceof Array) 3241 || !FS_function_array.length) 3242 return; 3243 //library_namespace.log('traverse_file_system: FS_function_array:\n[' + FS_function_array + ']'); 3244 if (!filter) 3245 filter = []; 3246 else if (filter instanceof RegExp) 3247 // filter=[filter,filter]; 通常我們輸入的只會指定 file filter 3248 filter = [ filter, ]; 3249 else if (typeof filter !== 'object') 3250 filter = [ filter, ]; 3251 3252 //library_namespace.log('traverse_file_system: FS_function_array:\n[' + FS_function_array + ']'); 3253 var item, iType, fc, i, traverse = !(flag & _f.no_traverse), objBuf = [], typeBuf = [], folder_filter = filter[1], testFilter = function( 3254 f) { 3255 try { 3256 // f instanceof RegExp 3257 f.test(''); 3258 } 3259 catch (e) { 3260 // throw new Error(e.number,'traverse_file_system: 錯誤的 filter:\n'+f+'\n'+e.description); 3261 e.description = 'traverse_file_system: 錯誤的 filter:\n' + f + '\n' 3262 + e.description; 3263 throw e; 3264 } 3265 }; 3266 if (filter = filter[0]) 3267 if (typeof filter === 'string') 3268 filter = new RegExp(filter); 3269 else 3270 testFilter(filter); 3271 if (folder_filter) 3272 if (typeof folder_filter === 'string') 3273 folder_filter = new RegExp(folder_filter); 3274 else 3275 testFilter(folder_filter); 3276 // if(flag!=_f.get_object)alert(filter+'\n'+folder_filter); 3277 // 至此 filter 代表 file_filter, vs. folder_filter 3278 3279 3280 // 轉換輸入之各項成fso object 3281 if (!path) { // 取得各個driver code 3282 if (flag === _f.get_object) 3283 return; 3284 for ( var drivers = new Enumerator(fso.Drives); !drivers.atEnd(); drivers 3285 .moveNext()) 3286 objBuf.push(drivers.item()), typeBuf 3287 .push(_f.driver); 3288 objBuf.reverse(), typeBuf.reverse(); 3289 } else if (typeof path === 'object') 3290 if (path.length) { 3291 for (i = 0; i < path.length; i++) 3292 if (item = _s(_f.get_object, 3293 '' + path[i], filter, flag)) 3294 objBuf.push(item[0]), typeBuf.push(item[1]); 3295 } else { 3296 item = typeof path.IsReady !== 'undefined' ? _f.driver 3297 : typeof path.IsRootFolder !== 'undefined' ? _f.folder 3298 : typeof path.Path !== 'undefined' ? _f.file 3299 : _f.NULL; 3300 if (_f.NULL != -1) 3301 objBuf.push(path), typeBuf.push(item); 3302 } 3303 else { 3304 i = true; // fault 3305 if (i) 3306 try { 3307 objBuf.push(fso.GetFolder(path)), typeBuf 3308 .push(_f.folder), i = false; 3309 } catch (e) { 3310 }// fso.FolderExists() 3311 if (i) 3312 try { 3313 objBuf.push(fso.GetFile(path)), typeBuf 3314 .push(_f.file), i = false; 3315 } catch (e) { 3316 }// fso.FileExists() 3317 if (i && path == fso.GetDriveName(path)) 3318 try { 3319 objBuf.push(fso.GetDrive(path)), typeBuf 3320 .push(_f.driver), i = false; 3321 } catch (e) { 3322 } 3323 } 3324 if (flag == _f.get_object) 3325 return objBuf[0] ? [ objBuf[0], typeBuf[0] ] : 0; 3326 3327 // FS_function_array.length=_f.func_length; 3328 for (i = 0; i < _f.func_length; i++) 3329 // 可以安排僅對folder或是file作用之function 3330 if (typeof FS_function_array[i] !== 'function') 3331 FS_function_array[i] = function() {}; 3332 //alert(objBuf.length+','+typeBuf.length+'\n'+typeBuf); 3333 // main loop 3334 while (!_s.stop && objBuf.length) 3335 if (item = objBuf.pop()) // fsoFunction執行途中可能將此項目刪除 3336 switch (iType = typeBuf.pop()) { 3337 case _f.folder: 3338 if (!folder_filter || folder_filter.test(item.Name)) 3339 FS_function_array[iType](item, iType); 3340 // if(traverse||traverse!==0){ 3341 // if(!traverse)traverse=0; // 加上次一層: 會連這次一層之檔案都加上去。 3342 if (traverse) 3343 for (fc = new Enumerator(item.SubFolders); !fc.atEnd(); fc 3344 .moveNext()) 3345 if (i = fc.item(), !folder_filter 3346 || folder_filter.test(i.Name)) 3347 objBuf.push(i), typeBuf 3348 .push(_f.folder); 3349 // } 3350 // try 以防item已經被刪除 3351 try { 3352 fc = new Enumerator(item.Files); 3353 } catch (e) { 3354 fc = 0; 3355 } 3356 if (fc) { 3357 // for(;!fc.atEnd();fc.moveNext())if(i=fc.item(),!filter||filter.test(i.Name))FS_function_array[_f.file](i,_f.file); 3358 // 因為檔案可能因改名等改變順序,因此用.moveNext()的方法可能有些重複,有些漏掉未處理。 3359 for (item = []; !fc.atEnd(); fc.moveNext()) 3360 item.push(fc.item()); 3361 for (i in item) 3362 if (i = item[i], !filter || filter.test(i.Name)) 3363 FS_function_array[_f.file](i, 3364 _f.file); 3365 } 3366 break; 3367 case _f.file: 3368 if (!filter || filter.test(item.Name)) 3369 FS_function_array[iType](item, iType); 3370 break; 3371 case _f.driver: 3372 if (!item.IsReady) 3373 break; 3374 FS_function_array[iType](item, iType); 3375 if (traverse) 3376 objBuf.push(item.RootFolder), typeBuf 3377 .push(_f.folder); 3378 // break; 3379 //default:break; 3380 } 3381 3382 }; 3383 3384 3385 //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 3386 CeL.IO.Windows.file 3387 . 3388 /** 3389 * <a href="#.traverse_file_system">traverse_file_system</a> 的 flag enumeration 3390 * @memberOf CeL.IO.Windows.file 3391 * @constant 3392 */ 3393 traverse_file_system.f = { 3394 /** 3395 * return object 3396 * @memberOf CeL.IO.Windows.file 3397 */ 3398 get_object : -2, 3399 /** 3400 * null flag 3401 * @private 3402 * @memberOf CeL.IO.Windows.file 3403 */ 3404 NULL : -1, 3405 /** 3406 * 用於指示 file 3407 * @private 3408 * @memberOf CeL.IO.Windows.file 3409 */ 3410 file : 0, 3411 /** 3412 * 用於指示 folder 3413 * @private 3414 * @memberOf CeL.IO.Windows.file 3415 */ 3416 folder : 1, 3417 /** 3418 * 用於指示 driver 3419 * @private 3420 * @memberOf CeL.IO.Windows.file 3421 */ 3422 driver : 2, 3423 /** 3424 * handle function 應有的長度 3425 * @private 3426 * @memberOf CeL.IO.Windows.file 3427 */ 3428 func_length : 3, 3429 /** 3430 * 深入下層子目錄及檔案 3431 * @memberOf CeL.IO.Windows.file 3432 */ 3433 traverse : 0, 3434 /** 3435 * 不深入下層子目錄及檔案 3436 * @memberOf CeL.IO.Windows.file 3437 */ 3438 no_traverse : 4 3439 }; 3440 3441 3442 return ( 3443 CeL.IO.Windows.file 3444 ); 3445 }; 3446 3447 //=================================================== 3448 3449 CeL.setup_module(module_name, code_for_including); 3450 3451 }; 3452 3453 3454 //WScript.Echo(this.Class); 3455 3456 // 若 library base 尚未 load 或本 module 已經 loaded 則跳過。 3457 if (typeof CeL === 'function'){ 3458 3459 /** 3460 * 本 module 之 name(id),<span style="text-decoration:line-through;">不設定時會從呼叫時之 path 取得</span>。 3461 * @type String 3462 * @constant 3463 * @inner 3464 * @ignore 3465 */ 3466 var module_name = 'code.log'; 3467 3468 //var do_before_including = function() {}; 3469 3470 /* to include: 3471 include code_for_including 3472 <div id="debug_panel"></div> 3473 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);}; 3474 3475 http://www.comsharp.com/GetKnowledge/zh-CN/TeamBlogTimothyPage_K742.aspx 3476 3477 if possible, use Firebug Lite instead. 3478 http://benalman.com/projects/javascript-debug-console-log/ 3479 */ 3480 3481 3482 // =================================================== 3483 /** 3484 * 若欲 include 整個 module 時,需囊括之 code。通常即 CeL。 3485 * @type Function 3486 * @param {Function} library_namespace namespace of library 3487 * @param load_arguments 呼叫時之 argument(s) 3488 * @return 3489 * @constant 3490 * @inner 3491 * @ignore 3492 */ 3493 var code_for_including = function(library_namespace, load_arguments) { 3494 //WScript.Echo(this); 3495 3496 var 3497 3498 // class private ----------------------------------- 3499 3500 // class name, 需要用到這個都不是好方法。 3501 //cn='Debug.log', 3502 3503 /** 3504 * private storage pool 3505 * @ignore 3506 */ 3507 p=[], 3508 3509 /** 3510 * default write/show log function 3511 * @ignore 3512 * @param {string} id element id 3513 */ 3514 w = function(id) { 3515 var o, m, c, _p = p[id], _t = _p.instance, 3516 /** 3517 * buffer 3518 */ 3519 b = _p.buf, 3520 B = _p.board, F = _p.do_function, level; 3521 3522 if (_p.clean) 3523 _t.clear(), _p.clean = 0; 3524 3525 if (!B && !F) 3526 return; 3527 3528 while (b.length) { 3529 m = b.shift(); // 預防 MP 時重複顯示 3530 if (F) 3531 F(m); 3532 3533 c = 0; 3534 if ((m instanceof Object) && !(m instanceof Array)) 3535 c = m.l in _t.className_set ? _t.className_set[m.l] : 0, 3536 m = m.m; 3537 _p.lbuf.push(m); 3538 3539 if (B) { // && typeof document==='object' 3540 o = _p.instance.log_tag; 3541 if (o) { 3542 o = document.createElement(o); 3543 if (c) 3544 o.className = c; 3545 o.innerHTML = typeof m === 'string' ? 3546 // for character (null) 3547 m.replace(/\x00/g, 3548 '<span class="control_character">\\x00</span>') 3549 : m; 3550 } else 3551 o = document.createTextNode(m); 3552 B.appendChild(o); 3553 } 3554 } 3555 3556 //if(_t.auto_hide)B.style.display=B.innerHTML?'block':'none'; 3557 if (B && _t.auto_scroll) 3558 with (B) 3559 scrollTop = scrollHeight - clientHeight; 3560 }, 3561 3562 3563 /** 3564 * save log 3565 * @ignore 3566 * @param m message 3567 * @param {string} id element id 3568 * @param force force to clean the message area 3569 */ 3570 s = function(m, id, force) { 3571 var _p = p[id], _t = _p.instance, f = _p.logF, s = _t.save_log; 3572 if (!s || typeof s == 'function' && !s(m, l)) 3573 return; 3574 3575 if (m) 3576 _p.sbuf 3577 .push(m = (_t.save_date && typeof gDate == 'function' ? _t.save_new_line 3578 + gDate() + _t.save_new_line 3579 : '') 3580 + m); 3581 3582 if (force || _t.flush || _p.sbufL > _t.save_limit) 3583 try { 3584 if (f 3585 || _t.log_file 3586 && (f = _p.logF = fso.OpenTextFile(_t.log_file, 3587 8/* ForAppending */, true/* create */, 3588 _t.log_encoding))) 3589 f.Write(_p.sbuf.join(_t.save_new_line)), _p.sbuf = [], 3590 _p.sbufL = 0, _t.error_message = 0; 3591 } catch (e) { 3592 _t.error_message = e;// err(e); 3593 } 3594 else if (m) 3595 _p.sbufL += m.length; 3596 }, 3597 3598 // instance constructor --------------------------- 3599 // (document object) 3600 /* 3601 3602 _=this 3603 3604 3605 TODO: 3606 set class in each input 3607 input array 3608 show file path & directory functional 可從 FSO operation.hta 移植 3609 增加 group 以便在多次輸入時亦可 trigger 或排版 3610 3611 count 3612 c.f.: GLog 3613 3614 dependency: 3615 3616 */ 3617 /** 3618 * initial a log tool's instance/object 3619 * @class log function 3620 * @see usage: <a href="#.extend">CeL.code.log.extend</a> 3621 * @since 2008/8/20 23:9:48 3622 * @requires gDate(),NewLine,fso 3623 3624 * @constructor 3625 * @name CeL.code.log 3626 * @param {String, object HTMLElement} obj message area element or id 3627 */ 3628 _tmp;CeL.code.log 3629 = function(obj) { 3630 // Initial instance object. You can set it yourself. 3631 /** 3632 * 表示是 warning/error message 之 className 3633 * @name CeL.code.log.prototype.className_set 3634 */ 3635 this.className_set = { 3636 /** 3637 * @description 當呼叫 {@link CeL.code.log.prototype.warn} 時使用的 className 3638 * @name CeL.code.log.prototype.className_set.warn 3639 */ 3640 warn : 'debug_warn', 3641 /** 3642 * @description 當呼叫 {@link CeL.code.log.prototype.err} 時使用的 className 3643 * @name CeL.code.log.prototype.className_set.err 3644 */ 3645 err : 'debug_err' 3646 }; 3647 3648 this.id = p.length; 3649 p.push( { 3650 instance : this, 3651 /** 3652 * write buffer 3653 */ 3654 buf : [], 3655 /** 3656 * save buffer when we need to save the messages 3657 */ 3658 sbuf : [], 3659 /** 3660 * length of save buffer 3661 */ 3662 sbufL : 0, 3663 /** 3664 * now logged buffer 3665 */ 3666 lbuf : [] 3667 }); 3668 this.set_board(obj); 3669 }; 3670 3671 3672 3673 // class public interface --------------------------- 3674 3675 CeL.code.log 3676 . 3677 /** 3678 * do the log action 3679 * @memberOf CeL.code.log 3680 * @private 3681 */ 3682 do_log = function(id) { 3683 /* 這段應該只在 module namespace 重複定義時才會發生 3684 var I=p[id]; 3685 if(!I){ 3686 alert('.do_log: not exist: ['+id+']'); 3687 return; 3688 } 3689 I=I.instance; 3690 */ 3691 var I=p[id].instance; 3692 if(I.do_log)I.do_log(); 3693 }; 3694 3695 3696 CeL.code.log 3697 . 3698 /** 3699 * new extend instance 3700 * @param {String, object HTMLElement} [obj] message area element or id 3701 * @return {Array} [ log function, warning function, error function, instance of this module ] 3702 * @example 3703 * // status logger 3704 * var SL=new CeL.code.log('log'),sl=SL[1],warn=SL[2],err=SL[3]; 3705 * sl(msg); 3706 * sl(msg,clear); 3707 * @memberOf CeL.code.log 3708 * @since 2009/8/24 20:15:31 3709 */ 3710 extend = function(obj) { 3711 //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);}); 3712 /** 3713 * new instance 3714 * @type CeL.code.log 3715 * @inner 3716 * @ignore 3717 */ 3718 var o = new _( 3719 obj || 3720 // 預設以訊息框代替 3721 new Function('m', 3722 (typeof JSalert === 'function' ? 'JSalert': 3723 typeof WScript === 'object' ? 'WScript.Echo': 3724 'alert') + 3725 "(typeof m==='object'?'['+m.l+'] '+m.m:m);")); 3726 3727 return [ o, function() { 3728 o.log.apply(o, arguments); 3729 }, function() { 3730 o.warn.apply(o, arguments); 3731 }, function() { 3732 o.err.apply(o, arguments); 3733 } ]; 3734 3735 }; 3736 3737 3738 3739 /* 3740 _.option_open=function(p){ 3741 3742 }; 3743 3744 _.option_file=function(p){ 3745 }; 3746 3747 _.option_folder=function(p){ 3748 }; 3749 */ 3750 3751 // class constructor --------------------------- 3752 3753 3754 CeL.code.log 3755 .prototype={ 3756 3757 // instance public interface ------------------- 3758 3759 /** 3760 * 當執行寫檔案或任何錯誤發生時之錯誤訊息。<br/> 3761 * while error occurred.. should read only 3762 * @name CeL.code.log.prototype.error_message 3763 */ 3764 error_message : '', 3765 3766 /** 3767 * 超過這長度才 save。<=0 表示 autoflash,非數字則不紀錄。 3768 * @name CeL.code.log.prototype.save_limit 3769 * @type Number 3770 */ 3771 save_limit : 4000, 3772 3773 /** 3774 * 在 log 結束時執行,相當於 VB 中 DoEvent() 或 。 3775 * @name CeL.code.log.prototype.do_event 3776 */ 3777 do_event : library_namespace.DoNoting || null, 3778 3779 3780 /** 3781 * log 時使用之 tagName, 可用 div / span 等。若不設定會用 document.createTextNode 3782 * @name CeL.code.log.prototype.log_tag 3783 */ 3784 log_tag : 'div', 3785 3786 3787 /** 3788 * boolean or function(message, log level) return save or not 3789 * @name CeL.code.log.prototype.save_log 3790 * @type Boolean 3791 */ 3792 save_log:false, 3793 /** 3794 * save log to this file path 3795 * @name CeL.code.log.prototype.log_file 3796 * @type Boolean 3797 */ 3798 log_file:false, 3799 /** 3800 * auto save log. 若未設定,記得在 onunload 時 .save() 3801 * @name CeL.code.log.prototype.flush 3802 * @type Boolean 3803 */ 3804 flush:false, 3805 /** 3806 * 在 save log 時 add date 3807 * @name CeL.code.log.prototype.save_date 3808 * @type Boolean 3809 */ 3810 save_date:true, 3811 /** 3812 * 在 save log 時的換行 3813 * @name CeL.code.log.prototype.save_new_line 3814 * @type string 3815 */ 3816 save_new_line : library_namespace.env.new_line || '\r\n', 3817 /** 3818 * 在 save log 時的 encoding 3819 * @name CeL.code.log.prototype.log_encoding 3820 */ 3821 log_encoding:-1,//TristateTrue 3822 3823 3824 /** 3825 * 自動捲動 3826 * @name CeL.code.log.prototype.auto_scroll 3827 * @type Boolean 3828 */ 3829 auto_scroll:true, 3830 /** 3831 * 沒有內容時自動隱藏 3832 * @deprecated TODO 3833 * @name CeL.code.log.prototype.auto_hide 3834 * @type Boolean 3835 */ 3836 auto_hide:false, 3837 3838 /** 3839 * 等待多久才顯示 log。若為 0 則直接顯示。<br/> 3840 * (WScript 沒有 setTimeout) 3841 * @name CeL.code.log.prototype.interval 3842 */ 3843 interval : typeof setTimeout === 'undefined' ? 0 : 1, 3844 3845 /** 3846 * log function (no delay) 3847 * @name CeL.code.log.prototype.do_log 3848 */ 3849 do_log:function(level){ 3850 //if(p[this.id].th)clearTimeout(p[this.id].th); 3851 p[this.id].th=0; // reset timeout handle 3852 w(this.id); 3853 }, 3854 3855 /** 3856 * class 預設作 log 之 function, (String message, clean) 3857 * @name CeL.code.log.prototype. 3858 */ 3859 log:function(m,clean,level){ 3860 var t=this,_p=p[t.id]; 3861 //var msg_head=(arguments.callee.caller+'').match(/function\s([^\(]+)/);if(msg_head)msg_head=msg_head[1]+' '; 3862 s(m,t.id,level); 3863 3864 if(level) 3865 m={m:m,l:level}; 3866 3867 if(clean)_p.clean=1,_p.buf=[m]; // clean log next time 3868 else _p.buf.push(m); 3869 //window.status=m; 3870 3871 if(!t.interval) 3872 t.do_log(); 3873 else if(!_p.th) 3874 if(typeof setTimeout==='undefined') 3875 t.interval=0,t.do_log(); 3876 else 3877 //_p.th=setTimeout(cn+'.do_log('+t.id+');',t.interval); 3878 _p.th=setTimeout(function(){_.do_log(t.id);},t.interval); 3879 3880 if(t.do_event) 3881 t.do_event(); 3882 }, 3883 3884 /* 3885 TODO: 3886 other methods: INFO,DEBUG,WARNING,ERROR,FATAL,UNKNOWN 3887 */ 3888 3889 /** 3890 * save message 3891 * @name CeL.code.log.prototype.save 3892 */ 3893 save:function(){ 3894 s('',this.id,1/*force*/); 3895 }, 3896 3897 // ** important ** 這邊不能作 object 之 initialization,否則因為 object 只會 copy reference,因此 new 時東西會一樣。initialization 得在 _() 中作! 3898 //className_set:{}, 3899 3900 /** 3901 * log a warning 3902 * @name CeL.code.log.prototype.warn 3903 */ 3904 warn:function(m,clean){ 3905 this.log(m,clean,'warn'); 3906 }, 3907 3908 /** 3909 * 表示是錯誤 error message 3910 * @name CeL.code.log.prototype.error_prefix 3911 */ 3912 error_prefix:'<em>!! Error !!</em> ', 3913 /** 3914 * deal with error object 3915 * @name CeL.code.log.prototype.err 3916 */ 3917 err:function(e,clean){ 3918 // from popErr() 3919 var NL=this.save_new_line,T=typeof e,m=e instanceof Error?'Error '+(e.number&0xFFFF)+(e.name?' ['+e.name+']':'') 3920 +' (facility code '+(e.number>>16&0x1FFF)+'):'+NL+e.description.replace(/\r?\n/g,'<br/>') 3921 +(!e.message||e.message==e.description?'':NL+NL+e.message.replace(/\r?\n/g,'<br/>')):!e||T=='string'?e:'('+T+')'+e; 3922 3923 this.log(this.error_prefix+m,clean,'err'); 3924 }, 3925 3926 3927 /** 3928 * 設定寫入到哪<br/>set log board for each instance (document object) 3929 * @name CeL.code.log.prototype.set_board 3930 */ 3931 set_board:function(o){ 3932 var _p=p[this.id]; 3933 if(o) 3934 if(typeof o==='function') 3935 _p.do_function=o; 3936 3937 else if(typeof o!=='object') 3938 if(o=typeof document==='object'?document.getElementById(o):0) 3939 _p.board=o; 3940 3941 return _p.board; 3942 }, 3943 3944 /** 3945 * 獲取當前 buffer 中的 log 3946 * @name CeL.code.log.prototype.get_log 3947 */ 3948 get_log:function(){ 3949 return p[this.id].lbuf; 3950 }, 3951 3952 /** 3953 * show/hide log board 3954 * @name CeL.code.log.prototype.trigger 3955 */ 3956 trigger:function(s){ 3957 var _s=p[this.id].board.style; 3958 if(typeof s==='undefined') 3959 s=_s.display=='none'; 3960 _s.display=s?'block':'none'; 3961 }, 3962 3963 /** 3964 * clear log board 3965 * @name CeL.code.log.prototype.clear_board 3966 */ 3967 clear_board:function(b){ 3968 b.innerHTML=''; 3969 }, 3970 3971 /** 3972 * 清除全部訊息 clear message 3973 * @name CeL.code.log.prototype.clear 3974 */ 3975 clear:function(){ 3976 var _p=p[this.id]; 3977 if(_p.board)this.clear_board(_p.board); 3978 _p.lbuf=[]; 3979 } 3980 3981 }; 3982 3983 3984 /** 3985 * 不 extend 的 member 3986 * @ignore 3987 */ 3988 CeL.code.log 3989 .no_extend = '*'; 3990 3991 return ( 3992 CeL.code.log 3993 ); 3994 }; 3995 3996 // =================================================== 3997 3998 /** 3999 * modele namespace 4000 * @type CeL.code.log 4001 * @inner 4002 * @ignore 4003 */ 4004 var ns = CeL.setup_module(module_name, code_for_including); 4005 4006 //WScript.Echo(n.extend); 4007 4008 //code_for_including[generateCode.dLK]='*var Debug={log:code_for_including()};'; 4009 4010 4011 // 為本 library 用 4012 if (!CeL.Log) { 4013 var o = ns.extend(); 4014 4015 // override CeL.log 4016 CeL.Log=o[0]; 4017 4018 CeL.log = o[1]; 4019 CeL.warn = o[2]; 4020 CeL.err = o[3]; 4021 } 4022 4023 } 4024 4025