From 4e1da83caa4d378025b639739c641c37c23dc975 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on ChromeOS)" <rob@synchro.net>
Date: Sun, 5 Mar 2023 13:53:17 -0800
Subject: [PATCH] Add support for an optional description character offset
 (number) arg

If all descriptions start a fixed offset and the default parsing
logic (regex) isn't working for the sysop, they can specify the exact
error offset to use for the beginning of each file's description. This
offset is only used for the initial line of the description, not the
continuation lines, but perhaps that could be done if needed.

This is an attempt to address issue #530

I first attempted to use "Lookbehind Assertions" in the regex, but
didn't have any success and decided the brute force method that the
old addfiles utility used might be as simpler solution and provide an
effective work-around for more potential issues with auto-detecting
the beginning of the useful file description.

I also added descriptions of the optional arguments to the help output.
---
 exec/addfiles.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/exec/addfiles.js b/exec/addfiles.js
index da56e7b201..a8018843fc 100755
--- a/exec/addfiles.js
+++ b/exec/addfiles.js
@@ -35,6 +35,7 @@ function archive_date(file)
 var uploader;
 var listfile;
 var date_fmt;
+var desc_off = 0;
 var options = {};
 var exclude = [];
 var include = "*";
@@ -47,7 +48,7 @@ for(var i = 0; i < argc; i++) {
 		while(opt[0] == '-')
 			opt = opt.slice(1);
 		if(opt == '?' || opt.toLowerCase() == "help") {
-			writeln("usage: [-options] [dir-code] [listfile]");
+			writeln("usage: [-options] [dir-code] [listfile] [desc-off]");
 			writeln("options:");
 			writeln("  -all            add files in all libraries/directories (implies -auto)");
 			writeln("  -lib=<name>     add files in all directories of specified library (implies -auto)");
@@ -65,6 +66,10 @@ for(var i = 0; i < argc; i++) {
 			writeln("  -delete         delete list after import");
 			writeln("  -v              increase verbosity of output");
 			writeln("  -debug          enable debug output");
+			writeln("optional:");
+			writeln("  dir-code:       File directory internal code");
+			writeln("  listfile:       Name of listfile (e.g. FILES.BBS)");
+			writeln("  desc-off:       Descripition character offset (number)");
 			exit(0);
 		}
 		if(opt.indexOf("ex=") == 0) {
@@ -119,7 +124,9 @@ for(var i = 0; i < argc; i++) {
 		}
 		options[opt] = true;
 	} else {
-		if(!dir_list.length)
+		if(Number(arg))
+			desc_off = Number(arg);
+		else if(!dir_list.length)
 			dir_list.push(arg);
 		else
 			listfile = arg;
@@ -280,6 +287,8 @@ function parse_file_list(lines)
 //		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);
-- 
GitLab