Show
Ignore:
Timestamp:
12/21/06 12:17:13 (2 years ago)
Author:
Jan-Klaas Kollhof
Message:

moving experimental branch to the trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk

    • Property svn:ignore set to
      build
  • trunk/jsolait/jsolait.wsf

    r65 r85  
    55        JavaScript O Lait for WSH. 
    66         
    7        Copyright (c) 2005 Jan-Klaas Kollhof 
     7       Copyright (c) 2005-2006 Jan-Klaas Kollhof 
    88        
    99       This file is part of jsolait 
     
    2525 
    2626    <runtime> 
    27         <named name="compile" helpstring="Specifies to run a the lang.parser on it." many="false" required="0" /> 
    2827        <unnamed name="filename" helpstring="The scriptfiles to run." many="false" required="1" /> 
    2928        <named name="script-args" helpstring="Specifies arguments to pass to the module/script being run. This may be text or a JSON encoded object" many="false" required="0" /> 
     
    3130     
    3231    <script language="JavaScript" src="./jsolait.js" /> 
     32    <script language="JavaScript" src="./packages/packages.pth" /> 
     33 
    3334     
    3435    <script language="JavaScript"> <![CDATA[ 
    35      
    36     Module("jsolaitws", "0.0.1", function(mod){ 
    37              
    3836        var fs= new ActiveXObject("Scripting.FileSystemObject"); 
    39         var wshShell= new ActiveXObject("WScript.Shell"); 
    40         var ForReading = 1, ForWriting = 2; 
     37 
     38        jsolait.__sourceURI__ = 'file://' + WScript.scriptFullName.slice(0,-3) + "js"; 
     39        jsolait.baseURI = 'file://' + fs.getParentFolderName(WScript.scriptFullName); 
     40        jsolait.moduleSearchURIs = ["%(baseURI)s/lib"].concat(ModuleSearchPaths); 
    4141         
     42         
     43        setTimeout=function(fn){ 
     44            fn(); 
     45        }; 
     46 
     47 
    4248        print = function(m){ 
    4349            var s=[]; 
     
    4854            WScript.echo(s.join(" ")); 
    4955        } 
    50          
    51         pprint=function(m, indent){ 
     56         
     57        pprint= function(m, indent){ 
    5258            var m = m.split("\n"); 
    5359             
     
    7278        } 
    7379        pprint.indent=0; 
    74          
     80 
    7581        Error.prototype.toString=function(){ 
    76             return this.name +": " + this.message; 
     82            s="" 
     83            for(var key in this){ 
     84                s+='\n' + key+':' + this[key]  
     85            } 
     86            return   s; 
    7787        } 
     88 
     89        __wsFinished__=false; 
     90        try{    
     91            jsolait.loadModule("wscript", function(jsolaitws,err){ 
     92                jsolaitws.run( function(err){ 
     93                    __wsFinished__=true; 
     94                    if(err){ 
     95                        print(''+err); 
     96                        throw err; 
     97                    } 
    7898                 
    79         LogError=1; 
    80         LogWarn=2; 
    81         LogInfo=4; 
    82         Error.prototype.toTraceString=function(){ 
    83             return this.message 
     99                }); 
     100            }); 
     101        }catch(e){ 
     102            throw e; 
    84103        } 
    85104         
    86         log=function(msg, level){ 
    87             level = level==null?LogInfo:level; 
    88             if(typeof msg !="string"){ 
    89                 level = LogError; 
    90                  
    91                 msg = msg.toTraceString(); 
    92             } 
    93              
    94             if(level & log.level){ 
    95                 print(msg); 
    96             } 
     105        while(!__wsFinished__){ 
     106            WScript.sleep(0); 
    97107        } 
    98         log.level = LogInfo | LogWarn | LogError;     
    99          
    100         mod.run=function(){ 
    101             mod.__sourceURI__ = 'file://' + WScript.scriptFullName; 
    102             jsolait.__sourceURI__ = 'file://' + WScript.scriptFullName.slice(0,-3) + "js"; 
    103                          
    104             ///The location where jsolait is installed. 
    105             jsolait.baseURI = 'file://' + fs.getParentFolderName(WScript.scriptFullName); 
    106          
    107             if (WScript.arguments.unnamed.length==0){ 
    108                 WScript.Arguments.ShowUsage();                                               
    109                 return; 
    110             }else{ 
    111                 //var fileName=fs.getAbsolutePathName(WScript.arguments.unnamed.item(0)); 
    112                 var fileName=WScript.arguments.unnamed.item(0); 
    113                 //todo:check if file exists 
    114             } 
    115                          
    116             //get the base of the file to execute 
    117             var fileBase= fs.getParentFolderName(fileName); 
    118              
    119             //make sure the search path is updated to include the fileBase 
    120             jsolait.moduleSearchURIs = [fileBase,  "%(baseURI)s/lib"]; 
    121              
    122             //change working dir to the file's location 
    123             //todo:is it OK to change cwd? 
    124             if(fileBase.slice(0, 'file://'.length) == 'file://'){ 
    125                 wshShell.currentDirectory = fileBase.slice('file://'.length); 
    126             } 
    127              
    128              
    129             if(WScript.arguments.named.exists("compile")){ 
    130                 var lang = imprt('lang'); 
    131                 var s = jsolait.loadURI(fileName); 
    132                 var p = new lang.Parser(s); 
    133                      
    134                 try{ 
    135                     p.parseStatements(p.next()); 
    136                 }catch(e){ 
    137                     var l=p.getPosition(); 
    138                     throw fileName + '(' + (l[0] ) + ',' +l[1] + ') ' +   e + ' near:\n' + p._working.slice(0,200); 
    139                 }  
    140      
    141             }else{ 
    142                 try{//load the script if it is not the main jsolait or jsolaitws module that has already been loaded. 
    143                     if(fileName.toLowerCase() != jsolait.__sourceURI__.toLowerCase()  && 
    144                                 fileName.toLowerCase() != mod.__sourceURI__.toLowerCase()){ 
    145                         var src = jsolait.loadURI(fileName); 
    146                         src = 'Module.currentURI="%s";\n%s\nModule.currentURI=null;\n'.format(src.__sourceURI__.replace(/\\/g, '\\\\'), src); 
    147                         var f=new Function("",src); //todo should it use globalEval ? 
    148                         f(); 
    149                     } 
    150                 }catch(e){ 
    151                     log(e); 
    152                     return; 
    153                 } 
    154                  
    155                 //if the loaded file contained a module then run it's __main__ method 
    156                 for(var mn in jsolait.modules){ 
    157                     var modl =jsolait.modules[mn]; 
    158                     if(modl.__sourceURI__.toLowerCase() == fileName.toLowerCase()){ 
    159                         if(modl.__main__){ 
    160                             //todo find arguments 
    161                             if(WScript.arguments.named.exists("script-args")){ 
    162                                 var args = WScript.arguments.named.Item("script-args"); 
    163                                 switch(args.slice(0,1)){ 
    164                                     case "{": case "'":  case "[":  case '"': 
    165                                         break; 
    166                                     default: 
    167                                         args = repr(args); 
    168                                 } 
    169                                 f=new Function( "return " + args); 
    170                                 args = [f()]; 
    171                             }else{ 
    172                                 var args =[]; 
    173                             } 
    174                              
    175                             try{ 
    176                                 modl.__main__.apply(modl,args); 
    177                             }catch(e){ 
    178                                 throw new mod.Exception("runing %s  __main__()  failed\n".format(modl),e) 
    179                             } 
    180                         } 
    181                         return; 
    182                     } 
    183                 } 
    184             } 
    185         } 
    186     }); 
    187  
    188     try{ 
    189         imprt("jsolaitws").run(); 
    190     }catch(e){ 
    191         log(e,LogError); 
    192     } 
    193         
     108            
    194109    ]]> 
    195110    </script>