/*jshint boss: true, rhino: true */
/*globals JSHINT*/

load("jshint.js");

(function (args) {
    var name   = args[0],
        optstr = args[1], // arg1=val1,arg2=val2,...
        predef = args[2], // global1=override,global2,global3,...
        opts   = { rhino: true },
        input;

    if (!name) {
        print('Usage: jshint.js file.js');
        quit(1);
    }

    if (optstr) {
        optstr.split(',').forEach(function (arg) {
            var o = arg.split('=');
            opts[o[0]] = (function (ov) {
                switch (ov) {
                case 'true':
                    return true;
                case 'false':
                    return false;
                default:
                    return ov;
                }
            }(o[1]));
        });
    }

    if (predef) {
        opts.predef = {};
        predef.split(',').forEach(function (arg) {
            var global = arg.split('=');
            opts.predef[global[0]] = (function (override) {
                return (override === 'false') ? false : true;
            }(global[1]));
        });
    }

    input = readFile(name);

    if (!input) {
        print('jshint: Couldn\'t open file ' + name);
        quit(1);
    }

    if (!JSHINT(input, opts)) {
        for (var i = 0, err; err = JSHINT.errors[i]; i += 1) {
            print(err.reason + ' (' + name + ':' + err.line + ':' + err.character + ')');
            print('> ' + (err.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
            print('');
        }
        quit(1);
    }

    quit(0);
}(arguments));

@@ -100,23 +100,21 @@
 var 
+file
 name
-   = args%5B0
+s = %5B
 %5D,%0A 
@@ -130,18 +130,8 @@
 tstr
- = args%5B1%5D
 , //
@@ -173,18 +173,8 @@
 edef
- = args%5B2%5D
 , //
@@ -257,29 +257,364 @@
     
-input;%0A%0A    if (!name
+retval = 0;%0A%0A    args.forEach(function(arg)%7B%0A        if (arg.indexOf(%22=%22) %3E -1)%7B%0A            //first time it's the options%0A            if (!optstr)%7B%0A                optstr = arg;%0A            %7D else if (!predef) %7B%0A                predef = arg;%0A            %7D%0A        %7D else %7B%0A            filenames.push(arg);%0A        %7D%0A    %7D);%0A%0A    if (filenames.length === 0
 ) %7B%0A
@@ -1074,15 +1074,15 @@
    %7D
+)
 (o%5B1%5D)
-)
 ;%0A  
@@ -1089,32 +1089,36 @@
       %7D);%0A    %7D%0A
+    
 %0A    if (predef)
@@ -1373,16 +1373,17 @@
        %7D
+)
 (global%5B
@@ -1385,17 +1385,16 @@
 obal%5B1%5D)
-)
 ;%0A      
@@ -1410,16 +1410,63 @@
  %7D%0A%0A    
+filenames.forEach(function(name)%7B%0A%0A        var 
 input = 
@@ -1482,24 +1482,28 @@
 name);%0A%0A    
+    
 if (!input) 
@@ -1500,24 +1500,28 @@
  (!input) %7B%0A
+    
         prin
@@ -1562,32 +1562,36 @@
  name);%0A        
+    
 quit(1);%0A    %7D%0A%0A
@@ -1575,32 +1575,36 @@
        quit(1);%0A
+    
     %7D%0A%0A    if (!
@@ -1594,24 +1594,28 @@
      %7D%0A%0A    
+    
 if (!JSHINT(
@@ -1626,24 +1626,28 @@
 t, opts)) %7B%0A
+    
         for 
@@ -1692,17 +1692,18 @@
 %5D; i
- += 1) %7B%0A
+++) %7B%0A    
     
@@ -1796,24 +1796,28 @@
             
+    
 print('%3E ' +
@@ -1888,24 +1888,28 @@
             
+    
 print('');%0A 
@@ -1907,32 +1907,36 @@
 nt('');%0A        
+    
 %7D%0A        quit(1
@@ -1925,38 +1925,57 @@
   %7D%0A        
-quit(1);%0A    %7D
+    retval = 1;%0A        %7D%0A    %7D);
 %0A%0A    quit(0
@@ -1973,17 +1973,22 @@
    quit(
-0
+retval
 );%0A%7D(arg
@@ -1996,9 +1996,8 @@
 ments));
-%0A

Allow multiple filenames to be passed in to Rhino CLI