From 85fdda8a9b759473b455774858b1569f3844d6d4 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Sun, 25 Aug 2024 20:37:25 +0300 Subject: [PATCH] use loop instead of copy/pasts --- src/command.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/src/command.c b/src/command.c index 83ba606..0e50e98 100644 --- a/src/command.c +++ b/src/command.c @@ -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; } } }