Skip to content

Commit

Permalink
load libs later, added forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
micha committed Jun 26, 2009
1 parent c50b406 commit ca93156
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion jsawk
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -957,6 +968,7 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
var fun = "";
var noprint = false;
var end = ".";
var libs = [];
var befores = [];
var afters = [];
var queries = [];
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ca93156

Please sign in to comment.