Commits

Ragnara committed 06eb31f

First commit

  • Participants

Comments (0)

Files changed (3)

+CC=clang -std=c11 -g -Wall -Wextra -Werror -pedantic
+
+
+buildcounter: buildcounter.c
+	buildcounter buildno.h
+	$(CC) -o buildcounter buildcounter.c
+
+clean:
+	rm buildcounter.o
+	rm buildcounter
+

File buildcounter.c

+#include <stdio.h>
+#include <stdlib.h>
+
+#include "buildno.h"
+
+const char *format = "#define BUILDNO %d\n";
+
+void print_usage(const char *argv0)
+{
+    fprintf(stderr, "Usage: %s <filename>\n", argv0);
+    fprintf(stderr, "Build: %d\n", BUILDNO);
+    exit(1);
+}
+
+void read_buffer(int *build, FILE *file)
+{
+    fscanf(file, format, build);
+}
+
+int main(int argc, char **argv)
+{
+    if (argc != 2)
+        print_usage(argv[0]);
+
+    FILE *file;
+    int lastbuild = 0;
+
+    if ((file = fopen(argv[1], "r")))
+    {
+        read_buffer(&lastbuild, file);
+        fclose(file);
+    }
+
+    printf(format, ++lastbuild);
+
+    if ((file = fopen(argv[1], "w")))
+    {
+        fprintf(file, format, lastbuild);
+        fclose(file);
+    }
+    else
+    {
+        perror("could not save last build to file");
+    }
+
+
+    return 0;
+}
+
+#define BUILDNO 4