Brian Wichmann wrote:
The problem arose since I have quite a few old Pascal programs on a machine that I prefer not to use. The one in questions makes checks on HTML files within a directory that the links exist. Hence it opens lots of HTML files which have names of different length. Works fine when reset ignores trailing spaces. Trailing spaces are ignored on Unix command lines....
Actually not. Unix shells strip them, and only so if unquoted. E.g.:
#!/bin/sh
printarg () { echo "The argument is '$1'." }
foo="foo " printarg $foo printarg "$foo"
This script outputs:
The argument is 'foo'. The argument is 'foo '.
In fact, failing to quote shell variables that may contain file names is the major reason why many Unix shell scripts do not work with file names containing spaces. (Which is kind of ironical, sadly, given that the OS itself has supported such file names for several decades while e.g. Dos and earlier versions of Windows didn't.) Whereas scripts that do proper quoting can work with file names containing spaces (trailing or otherwise) just fine.
And files with andd without trailing spaces and otherwise the same file name, can coexist as different files in the same directory:
% ls > "foo" % ls > "foo " % ls -la "foo" -rw------- 1 frank users 4 Dec 29 19:45 foo % ls -la "foo " -rw------- 1 frank users 9 Dec 29 19:45 foo % rm "foo" "foo "
The command line as seen by a Unix program, is an array of strings which can contain any characters except Chr (0).
I could recode the programs in Ada 95, but recompiling with gpc seemed a good option.
Being an old hand at ISO 7185, I like to stick to that.
If you take the view that sticking to ISO 7185 is not required, then obviously, Adriaan below is correct...
I can only repeat myself. ISO 7185 does not have any standard way for a program to specify file names at all, so any such way is already beyond 7185 (Bind is ISO 10206, Assign is UCSD/BP, the 2nd parameter to Reset is an extension of GPC and I think some other compilers). So why not use Trim in this place as well. (I suppose you'd wrap it in a procedure, so it would really be just one place.)
Frank