On 6/13/16 10:50 AM, Norman Megill wrote:
> On 6/12/16 6:12 PM, Stefan O'Rear wrote:
> ...
>> There's an interaction here with the recent decision to use relative
>> paths.
>
> Can you refresh my memory about this decision?
I located this Dec. 2014 thread:
https://groups.google.com/d/msg/metamath/hrtD9_wAcHM/YjC4FaQi8A4J
which has a discussion but didn't seem to come to a definite conclusion.
Was there anything more recent?
>
>> Suppose you have:
>>
>> A.mm:
>>
>> $[ B/C.mm $]
>> $[ D.mm $]
>>
>> B/C.mm:
>>
>> $[ ../D.mm $]
>>
>> Is D included once or twice? (SMM3 picks "once", but it could be
>> persuaded to include a file twice using hard links or a
>> case-insensitive filesystem. Symbolic links do get followed before
>> the reinclude check, but that's more an accident than anything.)
>
> Well, metamath.exe tries to open an included file with respect to the
> current directory regardless of what directory the file with the
> inclusion came from. It simply puts the string between $[ and $] into
> the C language's fopen() function. So the ../D.mm would cause it to
> give a file-not-found error (unless there is a different D.mm one level
> up). In other words, it takes whatever string is in the inclusion
> statement and gives it to the programming language's file-open command.
>
> Perhaps you think this is ugly, but my intent was to make the verifier
> as simple as possible by opening as a file whatever string is given,
> without having to parse and keep track of directory paths with different
> syntax for different OSs. Indeed, just specifying a file outside of the
> current directory already risks making the .mm file non-portable.
Thinking this over, it does seem to be rather inflexible, although it is
how metamath.exe works now. The spec is silent on the issue.
Perhaps we should recognize "/" and ".." in the spec as the standard for
specifying the path. These are honored in HTML URLs, even on Windows,
so it has become more or less a universal and OS-independent de facto
standard if not an actual one.
In a metamath.exe implementation, the path would be set with the "read"
command in metamath.exe and tracked through includes. For example,
"read '../abc/A.mm'" in your example would set the path to "../abc".
"$[ B/C.mm $]" would set the path to "../abc/B" inside of C.mm, so "$[
../D.mm $]" inside of C.mm would become "../abc/B/../D.mm" which
collapses to "../abc/D.mm". The collapsed version is saved for
comparison for the "file already included" condition. When the
inclusion of C.mm is complete, the path would pop back to "../abc", and
when D.mm is included inside of A.mm, its path would be "../abc/D.mm"
which the program then skips since it was already included.
This wouldn't be a terribly difficult to change in metamath.exe,
although I always hate making the spec more complex. It would mean (1)
keeping track of the path through inclusions, with ".." and "/" as the
universal path specifiers, and (2) collapsing relative paths so that
".." does not occur in the middle of a file name, before doing a string
comparison to determine if a file has already been included.
A hard or soft symbolic link to D.mm called Dlink.mm, or a reference to
d.mm in a case-insensitive OS, would cause the above algorithm to
include D.mm twice, since its collapsed path doesn't equal "../abc/D.mm"
using a string comparison in the verifier. We would need to do this to
ensure that all verifiers behave the same way, and not use any
language-specific feature that determines that a symbolic link is the
same file. In particular, I don't think that determining that a file
and a symbolic link to it are the same can be done in a portable way in C.
This may be what Mario intended in the 2014 post, but there didn't seem
to be a consensus that I could find, at least not in that thread.
Norm