Skip to content
Snippets Groups Projects
Commit 37dc6b28 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

libify the filelist (e.g. FILES.BBS) parsing logic in addfiles.js

... for (soon) reuse in fileman.js
parent 048f4320
No related branches found
No related tags found
1 merge request!455Update branch with changes from master
...@@ -3,14 +3,13 @@ ...@@ -3,14 +3,13 @@
require("sbbsdefs.js", 'LEN_FDESC'); require("sbbsdefs.js", 'LEN_FDESC');
lib = load({}, "filelist_lib.js");
"use strict"; "use strict";
const default_excludes = [ const default_excludes = lib.filenames.concat([
"FILES.BBS",
"FILE_ID.DIZ", "FILE_ID.DIZ",
"DESCRIPT.ION", ]);
"SFFILES.BBS"
];
function datestr(t) function datestr(t)
{ {
...@@ -197,7 +196,7 @@ for(var d = 0; d < dir_list.length; d++) { ...@@ -197,7 +196,7 @@ for(var d = 0; d < dir_list.length; d++) {
alert("Error " + f.error + " (" + strerror(f.error) + ") opening " + f.name); alert("Error " + f.error + " (" + strerror(f.error) + ") opening " + f.name);
exit(1); exit(1);
} }
file_list = parse_file_list(f.readAll()); file_list = lib.parse(f.readAll(), desc_off, verbosity);
f.close(); f.close();
} }
else { else {
...@@ -301,41 +300,3 @@ if(missing.length) { ...@@ -301,41 +300,3 @@ if(missing.length) {
alert(missing[i]); alert(missing[i]);
} }
} }
// Parse a FILES.BBS (or similar) file listing file
// Note: file descriptions must begin with an alphabetic character
function parse_file_list(lines)
{
var file_list = [];
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
var match = line.match(/(^[\w]+[\w\-\!\#\.]*)\W+[^A-Za-z]*(.*)/);
// writeln('fname line match: ' + JSON.stringify(match));
if(match && match.length > 1) {
var file = { name: match[1], desc: match[2] };
if(desc_off)
file.desc = line.substring(desc_off).trim();
if(file.desc && file.desc.length > LEN_FDESC)
file.extdesc = word_wrap(file.desc, 45);
file_list.push(file);
continue;
}
match = line.match(/\W+\|\s+(.*)/);
if(!match) {
if(verbosity)
alert("Ignoring line: " + line);
continue;
}
// writeln('match: ' + JSON.stringify(match));
if(match && match.length > 1 && file_list.length) {
var file = file_list[file_list.length - 1];
if(!file.extdesc)
file.extdesc = file.desc + "\n";
file.extdesc += match[1] + "\n";
var combined = file.desc + " " + match[1].trim();
if(combined.length <= LEN_FDESC)
file.desc = combined;
}
}
return file_list;
}
// Library to deal with lists of files (e.g. FILES.BBS files)
require("sbbsdefs.js", 'LEN_FDESC');
"use strict";
const filenames = [
"FILES.BBS",
"DESCRIPT.ION",
"00_INDEX.TXT",
"SFFILES.BBS"
];
// Parse a FILES.BBS (or similar) file listing file
// Returns an array of file-metadata-objects suitable for FileBase.add()
// Note: file descriptions must begin with an alphabetic character
// unless desc_offset (description char-offset) is specified
function parse(lines, desc_offset, verbosity)
{
var file_list = [];
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
var match = line.match(/(^[\w]+[\w\-\!\#\.]*)\W+[^A-Za-z]*(.*)/);
// writeln('fname line match: ' + JSON.stringify(match));
if(match && match.length > 1) {
var file = { name: match[1], desc: match[2] };
if(desc_offset)
file.desc = line.substring(desc_offset).trim();
if(file.desc && file.desc.length > LEN_FDESC)
file.extdesc = word_wrap(file.desc, 45);
file_list.push(file);
continue;
}
match = line.match(/\W+\|\s+(.*)/);
if(!match) {
if(verbosity)
alert("Ignoring line: " + line);
continue;
}
// writeln('match: ' + JSON.stringify(match));
if(match && match.length > 1 && file_list.length) {
var file = file_list[file_list.length - 1];
if(!file.extdesc)
file.extdesc = file.desc + "\n";
file.extdesc += match[1] + "\n";
var combined = file.desc + " " + match[1].trim();
if(combined.length <= LEN_FDESC)
file.desc = combined;
}
}
return file_list;
}
this;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment