X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=tools%2Fjsmin.js;h=95c275b621d1241b2913487b9d84b1533a5f08c8;hp=a49c2bfe3fc1e7654d5f0cdde299dcaa821f715e;hb=5d9992368bb386d2e606ae037c5478fe10ac70e8;hpb=c0bb356766fa4cd2e724b06a1720f89a5d163680 diff --git a/tools/jsmin.js b/tools/jsmin.js index a49c2bf..95c275b 100644 --- a/tools/jsmin.js +++ b/tools/jsmin.js @@ -1,3 +1,5 @@ +#!/usr/bin/env rhino + /* jsmin.js - 2006-08-31 Author: Franck Marcia This work is an adaptation of jsminc.c published by Douglas Crockford. @@ -121,6 +123,16 @@ function jsmin(comment, input, level) { function next() { var c = get(); + + if (c === ";" && peek() === ";") { + for (;;) { + c = get(); + if (c <= '\n') { + return c; + } + } + } + if (c == '/') { switch (peek()) { case '/': @@ -314,16 +326,17 @@ function jsmin(comment, input, level) { return comment + ret; } - -(function (a) { - if (!a[0]) { - print("Usage: jsmin.js file.js"); - quit(1); - } - var input = readFile(a[0]); - if (!input) { - print("jslint: Couldn't open file '" + a[0] + "'."); - quit(1); - } - print(jsmin(input)); + +importPackage(java.io); +(function (a) { + // in is a reserved javascript word, so we need to use [] for access + var readingIn = new BufferedReader(new InputStreamReader(java.lang.System["in"])); + var sInput = ""; + var str = ""; + while(str != null) { + sInput += str + '\n'; + + str = readingIn.readLine(); + } + print(jsmin(sInput)); })(arguments); \ No newline at end of file