Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
37dc6b28
Commit
37dc6b28
authored
10 months ago
by
Rob Swindell
Browse files
Options
Downloads
Patches
Plain Diff
libify the filelist (e.g. FILES.BBS) parsing logic in addfiles.js
... for (soon) reuse in fileman.js
parent
048f4320
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!455
Update branch with changes from master
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
exec/addfiles.js
+5
-44
5 additions, 44 deletions
exec/addfiles.js
exec/load/filelist_lib.js
+54
-0
54 additions, 0 deletions
exec/load/filelist_lib.js
with
59 additions
and
44 deletions
exec/addfiles.js
+
5
−
44
View file @
37dc6b28
...
...
@@ -3,14 +3,13 @@
require
(
"
sbbsdefs.js
"
,
'
LEN_FDESC
'
);
lib
=
load
({},
"
filelist_lib.js
"
);
"
use strict
"
;
const
default_excludes
=
[
"
FILES.BBS
"
,
const
default_excludes
=
lib
.
filenames
.
concat
([
"
FILE_ID.DIZ
"
,
"
DESCRIPT.ION
"
,
"
SFFILES.BBS
"
];
]);
function
datestr
(
t
)
{
...
...
@@ -197,7 +196,7 @@ for(var d = 0; d < dir_list.length; d++) {
alert
(
"
Error
"
+
f
.
error
+
"
(
"
+
strerror
(
f
.
error
)
+
"
) opening
"
+
f
.
name
);
exit
(
1
);
}
file_list
=
parse
_file_list
(
f
.
readAll
());
file_list
=
lib
.
parse
(
f
.
readAll
()
,
desc_off
,
verbosity
);
f
.
close
();
}
else
{
...
...
@@ -301,41 +300,3 @@ if(missing.length) {
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
;
}
This diff is collapsed.
Click to expand it.
exec/load/filelist_lib.js
0 → 100755
+
54
−
0
View file @
37dc6b28
// 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
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment