The encoding tool & file names with spaces

Post Reply
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

The encoding tool & file names with spaces

Post by Robert »

The menu item "Tools -> Encode File List" reports an error if a file name includes embedded spaces.

So does Pac, but if you enclose the name in ' or " Pac works. The native tool does not.

Personally I hate file names with spaces, but I can't always choose what files I am given.


Do people think this is a bug that should be fixed? I am quite happy to continue using Pac.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: The encoding tool & file names with spaces

Post by Josef Templ »

I think this is a feature that should be added and documented.
The fix in StdCoder.ReadPath would look like this:

Code: Select all

	PROCEDURE ReadPath(rd: TextModels.Reader; VAR path: ARRAY OF CHAR; VAR len: INTEGER);
		VAR i, l: INTEGER; ch: CHAR; quote: CHAR;
	BEGIN
		i := 0; l := LEN(path) - 1;
		REPEAT rd.ReadChar(ch) UNTIL rd.eot OR (ch > " ");
		IF (ch = "'") OR (ch = '"') THEN quote := ch; rd.ReadChar(ch) ELSE quote := 0X END;
		WHILE ~rd.eot & (i < l) & ((quote = 0X) & (ch > " ") OR (quote # 0X) & (ch # quote) & (ch >= " ")) DO
			path[i] := ch; INC(i); rd.ReadChar(ch)
		END;
		path[i] := 0X; len := i
	END ReadPath;
Note that a scanner cannot be used here easily because a scanner does not support the path format.
Therefore I extended ReadPath with a check for single or double quotes.
The extra check for (ch >= " ") is for breaking strings at end-of-line or rulers. It could also be removed.
My tests did not show any unwanted side effects or follow-up problems so far.

- Josef
Post Reply