Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
zilf
zilf
Commits
13f99c3fa6f8
Commit
c4938f53
authored
Jan 17, 2021
by
Jesse McGrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change include file searching to try a lowercase version of the filename.
parent
4d4d06ff127a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
13 deletions
+42
-13
src/Zilf/Interpreter/Context.cs
src/Zilf/Interpreter/Context.cs
+42
-13
No files found.
src/Zilf/Interpreter/Context.cs
View file @
13f99c3f
...
...
@@ -708,30 +708,59 @@ namespace Zilf.Interpreter
public
void
HandleError
(
ZilErrorBase
ex
)
=>
DiagnosticManager
.
Handle
(
ex
.
Diagnostic
??
throw
new
ArgumentException
(
"Missing diagnostic"
,
nameof
(
ex
)));
private
static
readonly
string
[]
IncludeFileExtensions
=
{
".zil"
,
".mud"
,
".ZIL"
,
".MUD"
};
/// <exception cref="FileNotFoundException">The file wasn't found in any include path.</exception>
public
string
FindIncludeFile
(
string
name
)
{
// ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
foreach
(
var
path
in
IncludePaths
)
{
var
combined
=
Path
.
Combine
(
path
,
name
);
foreach
(
var
nameVariant
in
GetIncludeFileNameVariants
(
name
))
{
var
combined
=
Path
.
Combine
(
path
,
nameVariant
);
if
(
FileExists
(
combined
))
return
combined
;
}
}
if
(!
string
.
IsNullOrEmpty
(
Path
.
GetExtension
(
combined
)))
continue
;
throw
new
FileNotFoundException
();
}
combined
=
Path
.
ChangeExtension
(
combined
,
".zil"
);
if
(
FileExists
(
combined
))
return
combined
;
[
SuppressMessage
(
"Globalization"
,
"CA1308:Normalize strings to uppercase"
,
Justification
=
"This method looks for a lowercase filename when the source specifies an uppercase filename."
)]
private
static
IEnumerable
<
string
>
GetIncludeFileNameVariants
(
string
name
)
{
// try the name as-is
yield
return
name
;
combined
=
Path
.
ChangeExtension
(
combined
,
".mud"
);
if
(
FileExists
(
combined
))
return
combined
;
// try adding a .zil or .mud extension
bool
hasExtension
=
!
string
.
IsNullOrEmpty
(
Path
.
GetExtension
(
name
));
if
(!
hasExtension
)
{
foreach
(
var
ext
in
IncludeFileExtensions
)
{
yield
return
Path
.
ChangeExtension
(
name
,
ext
);
}
}
throw
new
FileNotFoundException
();
// try lowercasing the name
var
lower
=
name
.
ToLowerInvariant
();
if
(
lower
!=
name
)
{
yield
return
lower
;
// try adding a .zil or .mud extension
if
(!
hasExtension
)
{
foreach
(
var
ext
in
IncludeFileExtensions
)
{
yield
return
Path
.
ChangeExtension
(
lower
,
ext
);
}
}
}
}
/// <summary>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment