The following example demonstrates using CrossScript to increment a build number:
First, add a JavaScript file to your project called incbuild.js containing the following code:
function incbuild()
{
var file = "buildnum.h"
var text = "#define BUILDNUMBER "
var s = CWSys.readStringFromFile(file);
var n;
if (s == undefined)
n = 1;
else
n = eval(s.substring(text.length)) + 1;
CWSys.writeStringToFile(file, text + n);
}
incbuild();
Add a file called getbuildnum.h to your project containing the following code:
#ifndef GETBUILDNUM_H
#define GETBUILDNUM_H
unsigned getBuildNumber();
#endif
Add a file called getbuildnum.c to your project containing the following code:
#include "getbuildnum.h"
#include "buildnum.h"
unsigned getBuildNumber()
{
return BUILDNUMBER;
}
Now, to combine these: