Is it possible to have the version number of a compile auto increment and be a part of the code to be retrieved at run time? Thanks
Sean, I quickly put together a dos program some time ago to increment what I call a 'build' number. I have used it for years, it may not be the most robust, but works for me. Im sure that there are other ways, but like you, I was looking for something simple to do just what you wanted. What the program does, is looks for a string in a file and increments the number following by 1. In this case I have "BUILD_NUMBER" in my version.h file like this:
#define BUILD_NUMBER 321
c:\util\incbld .\version.h
printf("Version %s, build: %d\r\n", VERSION_STRING, (uint)BUILD_NUMBER);
#include <stdio.h> #include <string.h> #define SEARCH_STRING "BUILD_NUMBER" main(int argc, char *argv[]) { FILE *fp; unsigned int i, number; char str[128], str2[64]; char *foundstr; int temp; if(argc <= 1) { printf("Increment Build number, Ver: 1.0 by: D. Marten \n"); printf(" Usage: incbld <filename) \n"); printf(" where filename is name of file to search for string\n"); printf(" BUILD_NUMBER (ususally contained in a headder file. \n"); printf(" The number following will be incremented by 1 and saved. \n\n\n"); exit(1); } fp=fopen(argv[1], "r+"); if(fp==NULL) { printf("error opening file %s. \n", argv[1]); exit(1); } *str = 0; while(!feof(fp)) { if((foundstr=strstr(str, SEARCH_STRING)) != NULL) /* if string found */ { sscanf(foundstr, "%*s %s", str2); number = atoi(str2); number++; temp = ftell(fp) - strlen(foundstr)+strlen(SEARCH_STRING) ; fseek(fp, (long)temp, SEEK_SET); fprintf(fp," %-4d\n", (int)number); fflush(fp); fseek(fp, 0L, SEEK_END); } fgets(str, 127, fp); } fclose(fp); return(0); }
Excellent!!!! It works great and is the perfect small solution I was looking for. Thanks David. Sean
View all questions in Keil forum