MOD modification de jsmin.js pour traiter le js depuis stdin
[euphorik.git] / tools / jsmin.js
index 55ee654..95c275b 100644 (file)
@@ -1,3 +1,5 @@
+#!/usr/bin/env rhino
+\r
 /* jsmin.js - 2006-08-31
 Author: Franck Marcia
 This work is an adaptation of jsminc.c published by Douglas Crockford.
@@ -324,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));
+\r
+importPackage(java.io);
+(function (a) {\r
+   // in is a reserved javascript word, so we need to use [] for access\r
+   var readingIn = new BufferedReader(new InputStreamReader(java.lang.System["in"]));\r
+   var sInput = "";\r
+   var str = "";\r
+   while(str != null) {\r
+      sInput += str + '\n';
+      \r
+      str = readingIn.readLine();\r
+   }
+   print(jsmin(sInput));
 })(arguments);
\ No newline at end of file