Usage message, ability to cache the test set
This makes tests slightly quicker by allowing the temporary file to be created beforehand. Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
parent
0df91242a2
commit
4b4700ceca
@ -304,25 +304,106 @@ static int add_one_file(FILE *fp, char *name)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
usage(FILE *fp)
|
||||
{
|
||||
if (fp != NULL) fclose(fp);
|
||||
|
||||
fprintf(stderr,
|
||||
"Usage:\n"
|
||||
" timepng --assemble <assembly> {files}\n"
|
||||
" Read the files into <assembly>, output the count. Options are ignored.\n"
|
||||
" timepng --dissemble <assembly> <count> [options]\n"
|
||||
" Time <count> files from <assembly>, additional files may not be given.\n"
|
||||
" Otherwise:\n"
|
||||
" Read the files into a temporary file and time the decode\n"
|
||||
"Transforms:\n"
|
||||
" --by-image: read by image with png_read_png\n"
|
||||
" --<transform>: implies by-image, use PNG_TRANSFORM_<transform>\n"
|
||||
" Otherwise: read by row using png_read_row (to a single row buffer)\n"
|
||||
"{files}:\n"
|
||||
" PNG files to copy into the assembly and time. Invalid files are skipped\n"
|
||||
" with appropriate error messages. If no files are given the list of files\n"
|
||||
" is read from stdin with each file name terminated by a newline\n"
|
||||
"Output:\n"
|
||||
" For --assemble the output is the name of the assembly file followed by the\n"
|
||||
" count of the files it contains; the arguments for --dissemble. Otherwise\n"
|
||||
" the output is the total decode time in seconds.\n");
|
||||
|
||||
exit(99);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ok = 0;
|
||||
int transforms = -1; /* by row */
|
||||
FILE *fp = tmpfile();
|
||||
|
||||
if (fp != NULL)
|
||||
{
|
||||
int err = 0;
|
||||
int nfiles = 0;
|
||||
int transforms = -1; /* by row */
|
||||
const char *assembly = NULL;
|
||||
FILE *fp;
|
||||
|
||||
/* Remove and handle options first: */
|
||||
if (argc > 2 && strcmp(argv[1], "--assemble") == 0)
|
||||
{
|
||||
/* Just build the test file, argv[2] is the file name. */
|
||||
assembly = argv[2];
|
||||
fp = fopen(assembly, "wb");
|
||||
if (fp == NULL)
|
||||
{
|
||||
perror(assembly);
|
||||
fprintf(stderr, "timepng --assemble %s: could not open for write\n",
|
||||
assembly);
|
||||
usage(NULL);
|
||||
}
|
||||
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
}
|
||||
|
||||
else if (argc > 3 && strcmp(argv[1], "--dissemble") == 0)
|
||||
{
|
||||
fp = fopen(argv[2], "rb");
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
perror(argv[2]);
|
||||
fprintf(stderr, "timepng --dissemble %s: could not open for read\n",
|
||||
argv[2]);
|
||||
usage(NULL);
|
||||
}
|
||||
|
||||
nfiles = atoi(argv[3]);
|
||||
if (nfiles <= 0)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"timepng --dissemble <file> <count>: %s is not a count\n",
|
||||
argv[3]);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
argv += 3;
|
||||
argc -= 3;
|
||||
}
|
||||
|
||||
else /* Else use a temporary file */
|
||||
{
|
||||
fp = tmpfile();
|
||||
|
||||
if (fp == NULL)
|
||||
{
|
||||
perror("tmpfile");
|
||||
fprintf(stderr, "timepng: could not open the temporary file\n");
|
||||
exit(1); /* not a user error */
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the transforms: */
|
||||
while (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-')
|
||||
{
|
||||
const char *opt = *++argv + 2;
|
||||
|
||||
--argc;
|
||||
|
||||
/* Options turn on the by-image processing and maybe set some
|
||||
/* Transforms turn on the by-image processing and maybe set some
|
||||
* transforms:
|
||||
*/
|
||||
if (transforms == -1)
|
||||
@ -353,9 +434,19 @@ int main(int argc, char **argv)
|
||||
OPT(GRAY_TO_RGB);
|
||||
OPT(EXPAND_16);
|
||||
OPT(SCALE_16);
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "timepng %s: unrecognized transform\n", opt);
|
||||
usage(fp);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
/* Handle the files: */
|
||||
if (argc > 1 && nfiles > 0)
|
||||
usage(fp); /* Additional files not valid with --dissemble */
|
||||
|
||||
else if (argc > 1)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -366,7 +457,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
else if (nfiles == 0) /* Read from stdin withoout --dissemble */
|
||||
{
|
||||
char filename[FILENAME_MAX+1];
|
||||
|
||||
@ -397,21 +488,40 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* Perform the test, or produce the --assemble output: */
|
||||
if (!err)
|
||||
{
|
||||
if (nfiles > 0)
|
||||
ok = perform_one_test(fp, nfiles, transforms);
|
||||
|
||||
else
|
||||
fprintf(stderr, "usage: timepng [options] {files}\n"
|
||||
" or: ls files | timepng [options]\n");
|
||||
{
|
||||
if (assembly != NULL)
|
||||
{
|
||||
if (fflush(fp) && !ferror(fp) && fclose(fp))
|
||||
{
|
||||
perror(assembly);
|
||||
fprintf(stderr, "%s: close failed\n", assembly);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf("%s %d\n", assembly, nfiles);
|
||||
fflush(stdout);
|
||||
ok = !ferror(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
ok = perform_one_test(fp, nfiles, transforms);
|
||||
(void)fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
fprintf(stderr, "timepng: could not open temporary file\n");
|
||||
usage(fp);
|
||||
}
|
||||
|
||||
else
|
||||
(void)fclose(fp);
|
||||
|
||||
/* Exit code 0 on success. */
|
||||
return ok == 0;
|
||||
|
Loading…
Reference in New Issue
Block a user