Skip to content

Commit

Permalink
use loop instead of copy/pasts
Browse files Browse the repository at this point in the history
  • Loading branch information
stsp committed Aug 25, 2024
1 parent 856fd63 commit 85fdda8
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -3828,33 +3828,19 @@ static void perform_truename(const char *arg)
findclose(ffh);
s = _truename(FINDDATA_T_FILENAME(ff), truebuf);
}
if (!strchr(arg, '.'))
if (!s && !strchr(arg, '.'))
{
if (!s)
const char *elst[] = { "com", "exe", "bat", NULL };
const char **p;
for (p = elst; *p; p++)
{
snprintf(buf2, sizeof(buf2), "%s.com", arg);
if (findfirst_f(buf2, &ff, 0, &ffh) == 0)
{
findclose(ffh);
s = _truename(FINDDATA_T_FILENAME(ff), truebuf);
}
}
if (!s)
{
snprintf(buf2, sizeof(buf2), "%s.exe", arg);
if (findfirst_f(buf2, &ff, 0, &ffh) == 0)
{
findclose(ffh);
s = _truename(FINDDATA_T_FILENAME(ff), truebuf);
}
}
if (!s)
{
snprintf(buf2, sizeof(buf2), "%s.bat", arg);
snprintf(buf2, sizeof(buf2), "%s.%s", arg, *p);
if (findfirst_f(buf2, &ff, 0, &ffh) == 0)
{
findclose(ffh);
s = _truename(FINDDATA_T_FILENAME(ff), truebuf);
if (s)
break;
}
}
}
Expand Down

0 comments on commit 85fdda8

Please sign in to comment.