Merge pull request #341 from iburinoc/exematch

Ignore extensions in exe name matching
This commit is contained in:
Yann Collet 2017-03-24 20:42:27 -07:00 committed by GitHub
commit 84246b974e

View File

@ -242,10 +242,19 @@ static void waitEnter(void)
static const char* lastNameFromPath(const char* path) static const char* lastNameFromPath(const char* path)
{ {
const char* name = strrchr(path, '/'); const char* name = path;
if (name==NULL) name = strrchr(path, '\\'); /* windows */ if (strrchr(name, '/')) name = strrchr(name, '/') + 1;
if (name==NULL) return path; if (strrchr(name, '\\')) name = strrchr(name, '\\') + 1; /* windows */
return name+1; return name;
}
/*! exeNameMatch() :
@return : a non-zero value if exeName matches test, excluding the extension
*/
static int exeNameMatch(const char* exeName, const char* test)
{
return !strncmp(exeName, test, strlen(test)) &&
(exeName[strlen(test)] == '\0' || exeName[strlen(test)] == '.');
} }
/*! readU32FromChar() : /*! readU32FromChar() :
@ -298,7 +307,7 @@ int main(int argc, const char** argv)
LZ4IO_setOverwrite(0); LZ4IO_setOverwrite(0);
/* lz4cat predefined behavior */ /* lz4cat predefined behavior */
if (!strcmp(exeName, LZ4CAT)) { if (exeNameMatch(exeName, LZ4CAT)) {
mode = om_decompress; mode = om_decompress;
LZ4IO_setOverwrite(1); LZ4IO_setOverwrite(1);
LZ4IO_setRemoveSrcFile(0); LZ4IO_setRemoveSrcFile(0);
@ -307,7 +316,7 @@ int main(int argc, const char** argv)
displayLevel=1; displayLevel=1;
multiple_inputs=1; multiple_inputs=1;
} }
if (!strcmp(exeName, UNLZ4)) { mode = om_decompress; } if (exeNameMatch(exeName, UNLZ4)) { mode = om_decompress; }
/* command switches */ /* command switches */
for(i=1; i<argc; i++) { for(i=1; i<argc; i++) {