Skip to content

Conversation

@pbakota
Copy link

@pbakota pbakota commented Sep 29, 2025

Fix for Linux path issue #215

I have created a PR which solves the problem on Linux with some tradeoffs. With the PR the path remains as-is (will not be converted) and the unit name is always converted to lower-case for FindFile(..., 'unit'). So on Linux (and on other case-sensitive OSes), the unit filenames must always be written in lower-case. e.g. usprite.pas

@peterdell
Copy link
Contributor

Thanks. The idea is not bad, but in line 269 (nam := FindFile(LowerCase(nam), 'unit')) it is the case that an explicit "IN " was specified. Here the file path must be taken as is. Additionally, units are not the only file type affected by "FindFile". It would probably make more sense to implement the different handling of paths and files in the Normalize directly.
I'll need to consider this and validate the impact on the existing Pascal codebase.

@pbakota
Copy link
Author

pbakota commented Sep 30, 2025

Thank you for your response. The point being is to have path kept as-is. But, it is impossible to keep filenames in their original form, they have to be converted to lower-case or upper-case. Thanks, and keep up the good work on this excellent project.

@tebe6502
Copy link
Owner

tebe6502 commented Oct 2, 2025

The filename with the unit must match the name appearing after the word UNIT exactly.

unit MD5; -> filename ‘MD5.pas’
unit md5; -> filename 'md5.pas'

@pbakota
Copy link
Author

pbakota commented Oct 2, 2025

This is also a viable solution. However, currently the unit filenames must be all written in upper-case, and that is because in Scanner.pas the parsed characters are unconditionally converted to upper-case. And because of that in the line

filePath := FindFile(TokenAt(i).Name + '.pas', 'unit');
the scanner will try to find the unit filename with upper-case not as it written in the source code.

Just a gentle reminder, the line

Result := LowerCase(Result);
can't remain as-is on case-sensitive file systems.

@peterdell
Copy link
Contributor

Hi,
The conversion to lower-case has been removed already as part of 51d4616.

I think tebe's proposal to enforce exactly same unit and file is only one that will always work without breaking somewhere else.

If you can provide a short example where is now still does not work, I can check that.
Maybe the parser does not have a separate token for file names yet and treats them as identifiers.

@pbakota
Copy link
Author

pbakota commented Oct 6, 2025

Thanks for your response. I can confirm that the conversion to lower-case has been solved with that commit you mentioned. However, the unit name problem still exists. I am getting this error:

main.pas (line 3, column 46): Error: E33 - FileNotFound: Cannot find unit 'URANDOM' used by program 'Program' in unit path '/home/user/Sources/Mad-Pascal/base/../lib/'.

The name of the file is uRandom.pas, and I have in my sources uses uGlobal, uSprite, uActor, uRoom, uRandom; my unit name is unit uRandom; But, if I rename the file to be as suggested by the error message to URANDOM.pas it will be found. (note the lower-case .pas which must be writtin in lower-case).

The issue is in Scanner.pas

filePath := FindFile(TokenAt(i).Name + '.pas', 'unit');
with the TokenAt(i).Name. I suspect the problem is with this line
c := UpCase(c);
where any character that parsed with SafeReadChar is converted to upper-case or with this
ch := UpCase(ch);
where the read char is also converted, and it is losing the original case format. There could be other places as well, I did not went through all scanning process, but the point is that in the line where the Scanner.pas is trying to load the unit, the unit file name is already converted to upper-case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants