Adriaan van Os wrote:
Brian Wichmann wrote:
If you do reset(t, 'myfile ');
it fails due to the trailing space. If one is attempting to use something very close the ISO 7185, then removing the trailing spaces is virtually impossible. Of course, it is easy to do the following:
procedure MyReset(var T: text; F: <some string type>); var i: integer; begin i := 1; while F[i] <> ' ' do i := i + 1; reset(T, F[1..i-1]); end;
Hence I would like to suggest that reset removes trailing spaces, as on my old machine.... (ISO 7185, with very minimal additions).
This is absurd.
- a filesystem may allow spaces in file- and pathnames
- reset(t, 'myfile ') instead of reset(t, 'myfile') when the filename
is 'myfile' is simply an application error
- the procedure MyReset doesn't remove trailing spaces, think of 'my
file'
The latter problem is fixable, of course, by counting spaces from the end instead of from the beginning. But otherwise I agree with Adriaan. Many file systems do support file names with trailing spaces, and by trimming spaces we'd make Pascal programs incapable of handling such files (and worse, even doing strange, possibly dangerous, things, if both files, say 'myfile' and 'myfile ' actually exist).
FWIW, I consider the issue of trailing spaces one of the biggest flaws in ISO Pascal (even in 10206 WRT string comparisons, but much more so in 7185). Even if one doesn't "believe" in file names with (trailing) spaces, there are other situations where one might want to have trailing spaces in a string variable, such as when composing an output text out of strings ...
BTW, putting a Chr (0) after the file name happens to solve the problem in GPC (because it passes the file name to the OS via a C-string, which is terminated by the 0 character), but that's more a kludge than anything, and perhaps we should forbid it in future GPC versions (by raising an error if file names etc. contain a 0 character).
I wonder if other ISO 7185 users have come across this problem, and what they do about it.
Brian, did you find this problem in an actual program, or just by trying some corner-cases?
Of course, the 2nd parameter to Reset is non-ISO already, so if one is willing do use this, one might as well use another non-ISO-7185 function, such as Trim (from 10206), which seems designed for solving such issues.
Frank