test: diffimg
echo $(GRAPH) | dot -Tpng:cg >hello1.png
echo $(GRAPH) | dot -Tpng:cg >hello2.png
- ./diffimg hello1.png hello2.png >test1.png
+ if `./diffimg hello1.png hello2.png >test1.png`;then echo same;else echo different;fi
echo $(GRAPH) | dot -Grankdir=LR -Tpng:cg >hello2.png
- ./diffimg hello1.png hello2.png >test2.png
+ if `./diffimg hello1.png hello2.png >test2.png`;then echo same;else echo different;fi
dist: clean
mkdir diffimg-$(VERSION)
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <sysexits.h>
#include <gd.h>
#define NOT(v) (!(v))
ext = strrchr(filename, '.');
if (!ext) {
fprintf(stderr, "Filename \"%s\" has no file extension.\n", filename);
- exit(-1);
+ exit(EX_USAGE);
}
rc = stat(filename, &statbuf);
if (rc) {
fprintf(stderr, "Failed to stat \"%s\"\n", filename);
- exit(-1);
+ exit(EX_NOINPUT);
}
if (strcasecmp(ext, ".ps") == 0) {
ext = ".png";
free(tmp);
if (!f) {
fprintf(stderr, "Failed to open converted \"%s%s\"\n", filename, ext);
- exit(-1);
+ exit(EX_NOINPUT);
}
}
else {
f = fopen(filename, "rb");
if (!f) {
fprintf(stderr, "Failed to open \"%s\"\n", filename);
- exit(-1);
+ exit(EX_NOINPUT);
}
}
im = 0;
fclose(f);
if (!im) {
fprintf(stderr, "Loading image from file \"%s\" failed!\n", filename);
- exit(-1);
+ exit(EX_DATAERR);
}
return im;
}
if (argc < 3) {
fprintf(stderr, "Usage: diffimg image1 image2 [outimage]\n");
- exit(-1);
+ exit(EX_USAGE);
}
A = imageLoad(argv[1]);
B = imageLoad(argv[2]);
minSX = (gdImageSX(A) < gdImageSX(B)) ? gdImageSX(A) : gdImageSX(B);
minSY = (gdImageSY(A) < gdImageSY(B)) ? gdImageSY(A) : gdImageSY(B);
maxSX = (gdImageSX(A) > gdImageSX(B)) ? gdImageSX(A) : gdImageSX(B);
- maxSY = (gdImageSX(A) > gdImageSX(B)) ? gdImageSX(A) : gdImageSX(B);
+ maxSY = (gdImageSY(A) > gdImageSY(B)) ? gdImageSY(A) : gdImageSY(B);
C = gdImageCreatePalette (maxSX, maxSY);
gdImageDestroy(B);
gdImageDestroy(C);
- return (rc ? 0 : 1);
+ return (rc ? EXIT_FAILURE : EXIT_SUCCESS);
}