Corrected issues with loading an invalid tech file. Also corrected

the behavior that extensions other than ".tech*" are not honored in
a tech file name.
This commit is contained in:
Tim Edwards 2021-11-24 10:56:08 -05:00
parent 6b72a51b17
commit c7e59ef461
1 changed files with 22 additions and 6 deletions

View File

@ -428,14 +428,22 @@ TechLoad(filename, initmask)
/* If NULL is passed to argument "filename", this is a reload and */
/* we should read TechFileName verbatim. */
if ((filename == NULL) && (TechFileName != NULL))
if (filename == NULL)
{
tf = PaOpen(TechFileName, "r", (char *)NULL, ".", SysLibPath, &realname);
if (tf == (FILE *) NULL)
if (TechFileName != NULL)
{
TxError("Could not find file '%s' in any of these "
tf = PaOpen(TechFileName, "r", (char *)NULL, ".", SysLibPath, &realname);
if (tf == (FILE *) NULL)
{
TxError("Could not find file '%s' in any of these "
"directories:\n %s\n",
TechFileName, SysLibPath);
return (FALSE);
}
}
else
{
TxError("Invalid technology file load.\n");
return (FALSE);
}
}
@ -460,11 +468,18 @@ TechLoad(filename, initmask)
else
sptr++;
/* If the filename is ".tech", then remove the extension and */
/* process like it was not there at all. */
dptr = strrchr(sptr, '.');
if ((dptr != NULL) && !strncmp(dptr, suffix, strlen(suffix)))
if ((dptr != NULL) && !strcmp(dptr, suffix))
*dptr = '\0';
tf = PaOpen(filename, "r", suffix, ".", SysLibPath, &realname);
/* If a non-standard extension was used, then honor it */
if ((dptr != NULL) && (*dptr != '\0'))
tf = PaOpen(filename, "r", (char *)NULL, ".", SysLibPath, &realname);
else
tf = PaOpen(filename, "r", suffix, ".", SysLibPath, &realname);
if (tf == (FILE *) NULL)
{
/* Try looking for tech files from the last version to */
@ -759,6 +774,7 @@ skipsection:
else if (retval == FALSE)
{
/* On error, remove any existing technology file name */
DBNumPlanes = saveNumPlanes;
freeMagic(TechFileName);
TechFileName = NULL;
}