import java.io.FileReader;
import java.io.BufferedReader;
import java.io.File;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class jssh {
    public static String version = "1.1.0";
    public static void usage() {
        System.out.println("jssh "+version+" power by smallmuou.\n\n"+"Usage: jssh <javascript.js> [arg1 [arg2 [...]]]\n\nNotes: args must less then 9.");
    }

    public static boolean fileExists(String filename)
    {
        return new File(filename).exists();
    }

    public static boolean isInteger(String value) {
        try {
            Integer.parseInt(value);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    public static boolean isDouble(String value) {
        try {
            Double.parseDouble(value);
            if (value.contains("."))
                return true;
            return false;
        } catch (NumberFormatException e) { 
            return false;
        }
    }

    public static boolean isNumber(String value) {
        return isInteger(value) || isDouble(value);
    }

    public static void main(String[] args) {
         if (args.length > 10 || args.length < 1) {
             usage();
             return;
         }

        if (args[0].equals("--help")) {
            usage();
            return;
        }

        if (!fileExists(args[0])) {
            System.out.println("The javascript file \""+args[0]+"\" does not exist.");
            return;
        }

        String content = readFile(args[0]);
        for (int i = 0; i < args.length; i++) {
            if (isNumber(args[i])) {
                content = content.replace("$"+i, args[i]);
            } else {
                content = content.replace("$"+i, "\""+args[i]+"\"");
            }
        }
        content = content.replace("$n", ""+args.length);

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("js");
        try {
            engine.eval(content);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static String readFile(String fileName) {
        try {
            FileReader reader = new FileReader(fileName);
            BufferedReader bufferedReader = new BufferedReader(reader);
            String line = "";
            StringBuffer  buffer = new StringBuffer();
            while((line=bufferedReader.readLine())!=null){
                buffer.append(line+"\n");
            }
            reader.close();
            return buffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}

@@ -1622,129 +1622,8 @@
 ) %7B%0A
-            if (isNumber(args%5Bi%5D)) %7B%0A                content = content.replace(%22$%22+i, args%5Bi%5D);%0A            %7D else %7B%0A    
     
@@ -1679,38 +1679,24 @@
 s%5Bi%5D+%22%5C%22%22);%0A
-            %7D%0A
         %7D%0A  

update arg to string