Difference between revisions of "Buildrev"
From Francois Louw
Line 2: | Line 2: | ||
Please note that this program is very basic, and apart from file checking it does not do any other checking. | Please note that this program is very basic, and apart from file checking it does not do any other checking. | ||
+ | |||
+ | Usage of the program is | ||
+ | |||
+ | <source> | ||
+ | buildrev build.h | ||
+ | </source> | ||
The format for the header file is as follows: | The format for the header file is as follows: | ||
+ | <source lang="c"> | ||
+ | #define BUILD 1 | ||
+ | </source> | ||
+ | |||
+ | The #define and the BUILD is not important and can be changed to <source lang="c">int build= 1</source> if needed. | ||
+ | |||
+ | The code looks for the third field (separated by space) and increases that value. | ||
+ | |||
+ | Here is the [http://aeif.info/files/buildrev/buildrev.c code] | ||
− | <source lang=" | + | <source lang="c"> |
− | // | + | //Build Revision |
+ | //2012-11-20 | ||
+ | //Published under GNU GENERAL PUBLIC LICENSE V3 | ||
+ | //Copyright 2012 Francois Louw | ||
+ | //A copy of the licence can be found at http://aeif.info/gpl-3.0.txt | ||
− | + | #include <stdio.h> | |
+ | #include <string.h> | ||
− | + | int main(int argc, char *argv[]) | |
{ | { | ||
− | + | FILE *f; | |
− | + | int i = 0; | |
− | + | char d[20] = {0}; | |
− | + | char b[20] = {0}; | |
− | + | ||
+ | if (argc != 2) | ||
+ | { | ||
+ | printf("Usage is %s <filename.h>\n", argv[0]); | ||
+ | return -1; | ||
+ | } | ||
+ | |||
+ | f = NULL; | ||
+ | f = fopen(argv[1], "r"); | ||
+ | if (f != NULL) | ||
+ | { | ||
+ | fscanf(f, "%s %s %d",d, b, &i); | ||
+ | fclose(f); | ||
+ | f = NULL; | ||
+ | } else | ||
+ | { | ||
+ | printf("Build file not found, creating default"); | ||
+ | strcpy(d, "#define"); | ||
+ | strcpy(b, "BUILD"); | ||
+ | } | ||
+ | |||
+ | f = fopen(argv[1], "w"); | ||
+ | if (f == NULL) | ||
+ | { | ||
+ | printf("ERROR: Cannot open output file for writing\n"); | ||
+ | return -1; | ||
+ | } | ||
+ | |||
+ | //increase build number | ||
+ | i++; | ||
+ | |||
+ | fprintf(f, "%s %s %d\n", d, b, i); | ||
+ | printf("Build number %d\n", i); | ||
+ | fclose(f); | ||
+ | |||
+ | return 0; | ||
} | } | ||
</source> | </source> |