Personal tools
User menu

Buildrev

From Francois Louw

Jump to: navigation, search

Back To All Projects Page

Back To Main Page


Download Windows executable with source

This application is quite handy and small. It is coded in simple C. Every time it runs it reads the given header file and increments the build number.

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

buildrev.exe <filename.h>

The format for the header file is as follows:

#define BUILD 1

The #define and the BUILD is not important and can be changed to

int build= 1

The code looks for the third field (separated by space) and increases that value.

Here is the code released under the GPL 3 license

//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\n");
		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;	
}

The code is pretty straightforward and does not need much explanation.

Please read here for more information on copyrights of my projects.