Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Add version output
Browse files Browse the repository at this point in the history
  • Loading branch information
Androbin committed Jan 31, 2018
1 parent 856a4da commit 0e32540
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
10 changes: 10 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
genrule(
name = "gen_version",
outs = ["version.txt"],
cmd = "cat bazel-out/volatile-status.txt | cut -c 17- > $@",
stamp = 1
)

cc_library(
name = "butteraugli_lib",
srcs = [
Expand All @@ -21,4 +28,7 @@ cc_binary(
"@jpeg_archive//:jpeg",
"@png_archive//:png",
],
data = [
":gen_version",
],
)
28 changes: 24 additions & 4 deletions butteraugli/butteraugli_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,33 @@ void CreateHeatMapImage(const ImageF& distmap, double good_threshold,
}
}

char* ReadVersion(char* argv) {
FILE* file = fopen("version.txt", "r");
char* buffer = new char[13];
fread(buffer, 1, 13, file);
fclose(file);
return buffer;
}

// main() function, within butteraugli namespace for convenience.
int Run(int argc, char* argv[]) {
if (argc != 3 && argc != 4) {
bool valid_syntax = false;

if (argc == 2) {
if (strcmp(argv[1], "--version") == 0) {
fprintf(stdout, "%s version %s\n", argv[0], ReadVersion(argv[0]));
return 0;
}
} else if (argc == 3 || argc == 4) {
valid_syntax = true;
}

if (!valid_syntax) {
fprintf(stderr,
"Usage: %s {image1.(png|jpg|jpeg)} {image2.(png|jpg|jpeg)} "
"[heatmap.ppm]\n",
argv[0]);
"Usage:\n"
"%s {image1.(png|jpg|jpeg)} {image2.(png|jpg|jpeg)} [heatmap.ppm]\n"
"%s --version\n",
argv[0], argv[0]);
return 1;
}

Expand Down

0 comments on commit 0e32540

Please sign in to comment.