Permalink
Browse files

load libs later, added forEach

  • Loading branch information...
1 parent c50b406 commit ca931563a355d2c7c75f7e6d700cb278432df333 @micha committed Jun 26, 2009
Showing with 16 additions and 1 deletion.
  1. +16 −1 jsawk
View
17 jsawk
@@ -942,6 +942,17 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
window.put = function(record) {
IS = IS.slice(0, $_+1).concat([record]).concat(IS.slice($_+1));
};
+ window.forEach = function(ary, fun) {
+ fun = eval("function(index,item) { "+fun+"; }");
+ for (var i=0; i<ary.length; i++) {
+ try {
+ fun.call(ary[i], i, ary[i]);
+ } catch (e) {
+ err("jsawk: js error: "+e);
+ quit(3);
+ }
+ }
+ };
})(window.print);
(function(argv) {
@@ -957,6 +968,7 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
var fun = "";
var noprint = false;
var end = ".";
+ var libs = [];
var befores = [];
var afters = [];
var queries = [];
@@ -982,7 +994,7 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
break;
case "-f":
if (argv.length < 1) usage();
- load(argv.shift());
+ libs.push(argv.shift());
break;
case "-b":
if (argv.length < 1) usage();
@@ -1023,6 +1035,9 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
if (wrapped)
IS = [ IS ];
+ for (i in libs)
+ load(libs[i]);
+
var f = makeFilter(fun);
for (i in queries)

0 comments on commit ca93156

Please sign in to comment.