Support files as argumetns, make error reporting more informative
This commit is contained in:
parent
e3f971c636
commit
9dd3cb9f3b
21
src/main.c
21
src/main.c
|
@ -5,19 +5,34 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void)
|
main(int argc, char* argv[argc + 1])
|
||||||
{
|
{
|
||||||
puts("This is " PACKAGE_STRING ".");
|
puts(PACKAGE_STRING);
|
||||||
|
|
||||||
FILE* imagefile = fopen("test.hvif", "rb");
|
if (argc < 2) {
|
||||||
|
if (argc > 0) printf("Usage: %s FILE\n", argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE* imagefile = fopen(argv[1], "rb");
|
||||||
if (!imagefile) {
|
if (!imagefile) {
|
||||||
fputs("fopen failed.\n", stderr);
|
fputs("fopen failed.\n", stderr);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
hvif_result result = hvif_from_file(imagefile);
|
hvif_result result = hvif_from_file(imagefile);
|
||||||
|
fclose(imagefile);
|
||||||
|
|
||||||
if (result.status != SUCCESS) {
|
if (result.status != SUCCESS) {
|
||||||
fputs("Reading image failed.\n", stderr);
|
fputs("Reading image failed.\n", stderr);
|
||||||
|
switch (result.status) {
|
||||||
|
case ERROR_NOMEM: fputs("Out of memory.\n", stderr); break;
|
||||||
|
case ERROR_EOF: fputs("File ended prematurely.\n", stderr); break;
|
||||||
|
case ERROR_STYLE: fputs("Incorrect style definition.\n", stderr); break;
|
||||||
|
case ERROR_PATH: fputs("Incorrect path definition.\n", stderr); break;
|
||||||
|
case ERROR_SHAPE: fputs("Incorrect shape definition.\n", stderr); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
puts("Reading image succeeded.");
|
puts("Reading image succeeded.");
|
||||||
|
|
Loading…
Reference in New Issue