added ability to force output to stdout, wrote an additional test for this functionality
This commit is contained in:
parent
532f439961
commit
70a4153bd3
@ -95,7 +95,7 @@ static int freeCCtx(adaptCCtx* ctx)
|
|||||||
int const allJobsCondError = pthread_cond_destroy(&ctx->allJobsCompleted_cond);
|
int const allJobsCondError = pthread_cond_destroy(&ctx->allJobsCompleted_cond);
|
||||||
int const jobWriteMutexError = pthread_mutex_destroy(&ctx->jobWrite_mutex);
|
int const jobWriteMutexError = pthread_mutex_destroy(&ctx->jobWrite_mutex);
|
||||||
int const jobWriteCondError = pthread_cond_destroy(&ctx->jobWrite_cond);
|
int const jobWriteCondError = pthread_cond_destroy(&ctx->jobWrite_cond);
|
||||||
int const fileCloseError = ctx->dstFile != NULL ? fclose(ctx->dstFile) : 0;
|
int const fileCloseError = (ctx->dstFile != NULL && ctx->dstFile != stdout) ? fclose(ctx->dstFile) : 0;
|
||||||
if (ctx->jobs){
|
if (ctx->jobs){
|
||||||
freeCompressionJobs(ctx);
|
freeCompressionJobs(ctx);
|
||||||
free(ctx->jobs);
|
free(ctx->jobs);
|
||||||
@ -448,7 +448,7 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compressFilenames(const char** filenameTable, unsigned numFiles)
|
static int compressFilenames(const char** filenameTable, unsigned numFiles, unsigned forceStdout)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
unsigned fileNum;
|
unsigned fileNum;
|
||||||
@ -459,7 +459,13 @@ static int compressFilenames(const char** filenameTable, unsigned numFiles)
|
|||||||
DISPLAY("Error: output filename is too long\n");
|
DISPLAY("Error: output filename is too long\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
ret |= compressFilename(filename, outFile);
|
if (!forceStdout) {
|
||||||
|
ret |= compressFilename(filename, outFile);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret |= compressFilename(filename, stdoutmark);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -503,6 +509,7 @@ int main(int argCount, const char* argv[])
|
|||||||
const char** filenameTable = (const char**)malloc(argCount*sizeof(const char*));
|
const char** filenameTable = (const char**)malloc(argCount*sizeof(const char*));
|
||||||
unsigned filenameIdx = 0;
|
unsigned filenameIdx = 0;
|
||||||
filenameTable[0] = stdinmark;
|
filenameTable[0] = stdinmark;
|
||||||
|
unsigned forceStdout = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int argNum;
|
int argNum;
|
||||||
|
|
||||||
@ -538,6 +545,9 @@ int main(int argCount, const char* argv[])
|
|||||||
case 'p':
|
case 'p':
|
||||||
g_useProgressBar = 1;
|
g_useProgressBar = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
forceStdout = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
DISPLAY("Error: invalid argument provided\n");
|
DISPLAY("Error: invalid argument provided\n");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
@ -551,7 +561,7 @@ int main(int argCount, const char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* error checking with number of files */
|
/* error checking with number of files */
|
||||||
if (filenameIdx > 1 && outFilename != NULL) {
|
if (filenameIdx > 1 && (outFilename != NULL && strcmp(outFilename, stdoutmark))) {
|
||||||
DISPLAY("Error: multiple input files provided, cannot use specified output file\n");
|
DISPLAY("Error: multiple input files provided, cannot use specified output file\n");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto _main_exit;
|
goto _main_exit;
|
||||||
@ -562,7 +572,7 @@ int main(int argCount, const char* argv[])
|
|||||||
ret |= compressFilename(filenameTable[0], outFilename);
|
ret |= compressFilename(filenameTable[0], outFilename);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ret |= compressFilenames(filenameTable, filenameIdx);
|
ret |= compressFilenames(filenameTable, filenameIdx, forceStdout);
|
||||||
}
|
}
|
||||||
_main_exit:
|
_main_exit:
|
||||||
free(filenameTable);
|
free(filenameTable);
|
||||||
|
@ -140,9 +140,17 @@ diff tests/test512.pdf tests/tmp512
|
|||||||
diff tests/test1024.pdf tests/tmp1024
|
diff tests/test1024.pdf tests/tmp1024
|
||||||
diff tests/test2048.pdf tests/tmp2048
|
diff tests/test2048.pdf tests/tmp2048
|
||||||
|
|
||||||
|
rm -f tests/*.zst tests/tmp*
|
||||||
echo "Running Args Tests"
|
echo "Running Args Tests"
|
||||||
./multi -h
|
./multi -h
|
||||||
./multi -i22 -p -s -otmp.zst tests/test2048.pdf
|
./multi -i22 -p -s -otmp.zst tests/test2048.pdf
|
||||||
|
rm tmp*
|
||||||
|
|
||||||
|
echo "Running Tests With Multiple Files > stdout"
|
||||||
|
./multi tests/* -c > tmp.zst
|
||||||
|
zstd -d tmp.zst
|
||||||
|
rm tmp*
|
||||||
|
|
||||||
echo "finished with tests"
|
echo "finished with tests"
|
||||||
|
|
||||||
make clean
|
make clean
|
||||||
|
Loading…
Reference in New Issue
Block a user