refactor for long commands

This commit is contained in:
Yann Collet 2016-10-14 14:41:17 -07:00
parent d7b120ab5c
commit 70077bc9bb

View File

@ -189,6 +189,14 @@ static unsigned readU32FromChar(const char** stringPtr)
return result; return result;
} }
static unsigned longCommandWArg(const char** stringPtr, const char* longCommand)
{
size_t const comSize = strlen(longCommand);
unsigned const result = !strncmp(*stringPtr, longCommand, comSize);
if (result) *stringPtr += comSize;
return result;
}
#define CLEAN_RETURN(i) { operationResult = (i); goto _end; } #define CLEAN_RETURN(i) { operationResult = (i); goto _end; }
@ -276,21 +284,9 @@ int main(int argCount, const char* argv[])
if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; } if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; }
/* long commands with arguments */ /* long commands with arguments */
if (!strncmp(argument, "--memlimit=", strlen("--memlimit="))) { if (longCommandWArg(&argument, "--memlimit=")) { memLimit = readU32FromChar(&argument); continue; }
argument += strlen("--memlimit="); if (longCommandWArg(&argument, "--memory=")) { memLimit = readU32FromChar(&argument); continue; }
memLimit = readU32FromChar(&argument); if (longCommandWArg(&argument, "--memlimit-decompress=")) { memLimit = readU32FromChar(&argument); continue; }
continue;
}
if (!strncmp(argument, "--memory=", strlen("--memory="))) {
argument += strlen("--memory=");
memLimit = readU32FromChar(&argument);
continue;
}
if (!strncmp(argument, "--memlimit-decompress=", strlen("--memlimit-decompress="))) {
argument += strlen("--memlimit-decompress=");
memLimit = readU32FromChar(&argument);
continue;
}
/* '-' means stdin/stdout */ /* '-' means stdin/stdout */
if (!strcmp(argument, "-")){ if (!strcmp(argument, "-")){