-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreqit.js
82 lines (72 loc) · 1.65 KB
/
freqit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// $Id: freqit.js,v 1.6 2016/01/19 06:58:36 deuce Exp $
/*
* Intentionally simple FREQ processor.
* Configure in binkd with the line:
* exec "/sbbs/exec/jsexec freqit *S" *.req *.REQ
*/
load("fidocfg.js");
load("freqit_common.js");
FREQIT.add_file = function(filename, resp, cfg)
{
if (filename === undefined)
return;
if (FREQIT.files >= cfg.maxfiles)
return;
if (FREQIT.added[filename] !== undefined)
return;
resp.writeln('+'+filename);
FREQIT.files++;
FREQIT.added[filename]='';
};
function parse_srif(fname)
{
var f=new File(fname);
var srif={};
var l;
var m;
if (!f.open("r")) {
log(LOG_ERROR, "Unable to find SRIF file '"+f.name+"'");
return undefined;
}
while((l = f.readln(65535))) {
if ((m=l.match(/^\s*([^ ]+)\s+(.*)$/)) !== null)
srif[m[1].toLowerCase()] = m[2];
}
f.close();
return srif;
}
function handle_srif(srif)
{
var req=new File(srif.requestlist);
var resp=new File(srif.responselist);
var m;
var fname;
var pw;
var cfg = new FREQITCfg();
if (!req.open("r"))
return;
if (!resp.open("a"))
return;
resp.position = resp.length;
next_file:
while((fname=req.readln())) {
if ((m=fname.match(/^(.*) !(.*?)$/))!==null) {
pw=m[2];
fname=m[1];
}
// First, check for magic!
for (m in cfg.magic) {
if (m == fname.toLowerCase()) {
FREQIT.handle_magic(cfg.magic[m], resp, srif.remotestatus.toLowerCase() === 'protected', pw, cfg);
continue next_file;
}
}
// Now, check for the file...
FREQIT.handle_regular(fname, resp, srif.remotestatus.toLowerCase() === 'protected', pw, cfg);
}
}
argv.forEach(function(fname) {
var srif = parse_srif(fname);
if (srif !== undefined)
handle_srif(srif);
});