265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
throw 'key "'+key+'" not known in dictionary';
});
this.registerSubCommand("dict", "keys", function (interp, args) {
if(args.length < 2 || args.length > 3)
throw 'wrong # args: should be "dict keys dictionary ?globPattern?"';
var dict = args[1].toList();
var pattern = ".*";
if(args.length == 3) pattern = "^"+args[2].toString().replace(/\*/g,".*");
var res = [];
for (var i=0;i < dict.length;i+=2) {
if(dict[i].toString().match(pattern)) res.push(dict[i]);
}
return res;
});
this.registerSubCommand("dict", "set", function (interp, args) {
this.arity(args, 4);
var name = args[1];
|
>
|
|
|
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
throw 'key "'+key+'" not known in dictionary';
});
this.registerSubCommand("dict", "keys", function (interp, args) {
if(args.length < 2 || args.length > 3)
throw 'wrong # args: should be "dict keys dictionary ?globPattern?"';
var dict = args[1].toList();
var pattern = ".*";
if(args.length == 3)
pattern = "^"+args[2].toString().replace(/\*/g,".*");
var res = [];
for (var i = 0; i < dict.length; i+=2) {
if(dict[i].toString().match(pattern)) res.push(dict[i]);
}
return res;
});
this.registerSubCommand("dict", "set", function (interp, args) {
this.arity(args, 4);
var name = args[1];
|
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
|
return stat.atime.getTime()/1000;
})
this.registerSubCommand("file", "dirname", function (interp, args) {
this.arity(args, 2);
return interp.dirname(args[1].toString());
});
this.dirname = function(p) { // also used in [glob]
//require("path"); //not working :(
//return path.dirname(p.toString());
if(p == ".") p = process.cwd();
p = p.split("/");
p.pop();
if(p == "") return("/");
return p.join("/");
};
this.registerSubCommand("file", "exists", function (interp, args) {
this.arity(args, 2);
var file = args[1].toString();
try {var fd = fs.openSync(file,"r");} catch(e) {return 0;}
fs.closeSync(fd);
return 1;
});
this.registerSubCommand("file", "extension", function (interp, args) {
this.arity(args, 2);
var fn = args[1].toString();
var res = fn.split(".").pop();
res = (res == fn)? "" : "."+res;
return res;
});
this.registerSubCommand("file", "mtime", function (interp, args) {
this.arity(args, 2);
var stat = fs.statSync(args[1].toString());
return stat.mtime.getTime()/1000;
})
this.registerSubCommand("file", "size", function (interp, args) {
this.arity(args, 2);
var stat = fs.statSync(args[1].toString());
return stat.size;
})
this.registerSubCommand("file", "tail", function (interp, args) {
this.arity(args, 2);
return args[1].toString().split("/").pop();
});
this.registerCommand("for", function (interp, args) {
this.arity(args, 5);
interp.eval(args[1].toString());
|
|
|
<
<
<
<
<
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
|
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
return stat.atime.getTime()/1000;
})
this.registerSubCommand("file", "dirname", function (interp, args) {
this.arity(args, 2);
return interp.dirname(args[1].toString());
});
this.dirname = function(p) { // also used in [glob]
var path = require("path");
return path.dirname(p.toString());
};
this.registerSubCommand("file", "exists", function (interp, args) {
this.arity(args, 2);
var file = args[1].toString();
try {var fd = fs.openSync(file,"r");} catch(e) {return 0;}
fs.closeSync(fd);
return 1;
});
this.registerSubCommand("file", "extension", function (interp, args) {
this.arity(args, 2);
var fn = args[1].toString();
var res = fn.split(".").pop();
res = (res == fn)? "" : "."+res;
return res;
});
this.registerSubCommand("file", "join", function (interp, args) {
this.arity(args, 2, Infinity);
args.shift();
var res = "", sep = "";
for (var arg in args) {
var part = args[arg].toString();
if(part.match("^[/]"))
res = part; else res = res+sep+part;
sep = "/";
}
return res;
});
this.registerSubCommand("file", "mtime", function (interp, args) {
this.arity(args, 2);
var stat = fs.statSync(args[1].toString());
return stat.mtime.getTime()/1000;
});
this.registerSubCommand("file", "size", function (interp, args) {
this.arity(args, 2);
var stat = fs.statSync(args[1].toString());
return stat.size;
});
this.registerSubCommand("file", "split", function (interp, args) {
this.arity(args, 2);
var path = args[1].toString().split("/");
if(path[0] == "") path[0] = "/";
return path;
});
this.registerSubCommand("file", "tail", function (interp, args) {
this.arity(args, 2);
return args[1].toString().split("/").pop();
});
this.registerCommand("for", function (interp, args) {
this.arity(args, 5);
interp.eval(args[1].toString());
|
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
//interp.buf = "";
//while(interp.buf == "") {
//interp.timeout = setTimeout(function(){}, 10000);
// if(interp.getsing==0) break;
//}
return; // result will be in interp.buf when done
});
this.gets = function(char) {
try {
if(char.match(/foo[\r\n]/)) {
this.getsing = 0;
puts("received: "+this.buf);
} else {
puts("<"+char+">"+this.getsing);
this.buf += char;
}
} catch(e) {puts(e)};
}
this.registerCommand("glob", function (interp, args) {
this.arity(args, 2, Infinity);
args.shift();
var res = [];
var prefix = "";
var dir = ".";
for (var arg in args) {
|
|
|
|
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
|
//interp.buf = "";
//while(interp.buf == "") {
//interp.timeout = setTimeout(function(){}, 10000);
// if(interp.getsing==0) break;
//}
return; // result will be in interp.buf when done
});
/* this.gets = function(char) {
try {
if(char.match(/foo[\r\n]/)) {
this.getsing = 0;
puts("received: "+this.buf);
} else {
puts("<"+char+">"+this.getsing);
this.buf += char;
}
} catch(e) {puts(e)};
}*/
this.registerCommand("glob", function (interp, args) {
this.arity(args, 2, Infinity);
args.shift();
var res = [];
var prefix = "";
var dir = ".";
for (var arg in args) {
|