updated zwrapbench to use FileNamesTable* abstraction

This commit is contained in:
Yann Collet 2019-11-05 17:25:20 -08:00
parent b09f59390b
commit 7977899538

View File

@ -74,7 +74,7 @@ static U32 g_compressibilityDefault = 50;
#define DEFAULT_DISPLAY_LEVEL 2 #define DEFAULT_DISPLAY_LEVEL 2
#define DISPLAY(...) fprintf(displayOut, __VA_ARGS__) #define DISPLAY(...) fprintf(displayOut, __VA_ARGS__)
#define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); }
static int g_displayLevel = DEFAULT_DISPLAY_LEVEL; /* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */ static unsigned g_displayLevel = DEFAULT_DISPLAY_LEVEL; /* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */
static FILE* displayOut; static FILE* displayOut;
#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ #define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \
@ -848,7 +848,7 @@ static unsigned readU32FromChar(const char** stringPtr)
{ {
unsigned result = 0; unsigned result = 0;
while ((**stringPtr >='0') && (**stringPtr <='9')) while ((**stringPtr >='0') && (**stringPtr <='9'))
result *= 10, result += **stringPtr - '0', (*stringPtr)++ ; result *= 10, result += (unsigned)(**stringPtr - '0'), (*stringPtr)++ ;
return result; return result;
} }
@ -865,24 +865,18 @@ int main(int argCount, char** argv)
int cLevel = ZSTDCLI_CLEVEL_DEFAULT; int cLevel = ZSTDCLI_CLEVEL_DEFAULT;
int cLevelLast = 1; int cLevelLast = 1;
unsigned recursive = 0; unsigned recursive = 0;
const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */ FileNamesTable* filenames = UTIL_allocateFileNamesTable((size_t)argCount);
unsigned filenameIdx = 0;
const char* programName = argv[0]; const char* programName = argv[0];
const char* dictFileName = NULL; const char* dictFileName = NULL;
char* dynNameSpace = NULL; char* dynNameSpace = NULL;
#ifdef UTIL_HAS_CREATEFILELIST
const char** fileNamesTable = NULL;
char* fileNamesBuf = NULL;
unsigned fileNamesNb;
#endif
/* init */ /* init */
if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); } if (filenames==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); }
displayOut = stderr; displayOut = stderr;
/* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */ /* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */
{ size_t pos; { size_t pos;
for (pos = (int)strlen(programName); pos > 0; pos--) { if (programName[pos] == '/') { pos++; break; } } for (pos = strlen(programName); pos > 0; pos--) { if (programName[pos] == '/') { pos++; break; } }
programName += pos; programName += pos;
} }
@ -930,14 +924,14 @@ int main(int argCount, char** argv)
case 'b': case 'b':
/* first compression Level */ /* first compression Level */
argument++; argument++;
cLevel = readU32FromChar(&argument); cLevel = (int)readU32FromChar(&argument);
break; break;
/* range bench (benchmark only) */ /* range bench (benchmark only) */
case 'e': case 'e':
/* last compression Level */ /* last compression Level */
argument++; argument++;
cLevelLast = readU32FromChar(&argument); cLevelLast = (int)readU32FromChar(&argument);
break; break;
/* Modify Nb Iterations (benchmark only) */ /* Modify Nb Iterations (benchmark only) */
@ -964,7 +958,7 @@ int main(int argCount, char** argv)
/* Pause at the end (-p) or set an additional param (-p#) (hidden option) */ /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */
case 'p': argument++; case 'p': argument++;
if ((*argument>='0') && (*argument<='9')) { if ((*argument>='0') && (*argument<='9')) {
BMK_setAdditionalParam(readU32FromChar(&argument)); BMK_setAdditionalParam((int)readU32FromChar(&argument));
} else } else
main_pause=1; main_pause=1;
break; break;
@ -984,7 +978,7 @@ int main(int argCount, char** argv)
} }
/* add filename to list */ /* add filename to list */
filenameTable[filenameIdx++] = argument; UTIL_refFilename(filenames, argument);
} }
/* Welcome message (if verbose) */ /* Welcome message (if verbose) */
@ -992,28 +986,16 @@ int main(int argCount, char** argv)
#ifdef UTIL_HAS_CREATEFILELIST #ifdef UTIL_HAS_CREATEFILELIST
if (recursive) { if (recursive) {
fileNamesTable = UTIL_createFileList(filenameTable, filenameIdx, &fileNamesBuf, &fileNamesNb, 1); filenames = UTIL_expandFileNamesTable(filenames, 1);
if (fileNamesTable) {
unsigned u;
for (u=0; u<fileNamesNb; u++) DISPLAYLEVEL(4, "%u %s\n", u, fileNamesTable[u]);
free((void*)filenameTable);
filenameTable = fileNamesTable;
filenameIdx = fileNamesNb;
}
} }
#endif #endif
BMK_setNotificationLevel(g_displayLevel); BMK_setNotificationLevel(g_displayLevel);
BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast); BMK_benchFiles(filenames->fileNames, (unsigned)filenames->tableSize, dictFileName, cLevel, cLevelLast);
_end: _end:
if (main_pause) waitEnter(); if (main_pause) waitEnter();
free(dynNameSpace); free(dynNameSpace);
#ifdef UTIL_HAS_CREATEFILELIST UTIL_freeFileNamesTable(filenames);
if (fileNamesTable)
UTIL_freeFileList(fileNamesTable, fileNamesBuf);
else
#endif
free((void*)filenameTable);
return operationResult; return operationResult;
} }