Self incrementing version define

Thanks to JScript’s conditional compilation feature it is possible to execute code in comments, this allows you to create valid c header files with embedded JScript. This can come in handy in a custom build step

/*@cc_on@*//*@if (!@_jscript)@
============================*/

#define APPVER_BLD 1

/*============================
@else 
var FSO=new ActiveXObject("Scripting.FileSystemObject");
var lines=[],hF=FSO.OpenTextFile(WScript.ScriptFullName,1,false);
for(;!hF.AtEndOfStream;){lines.push(hF.ReadLine());}hF.Close();
if (lines.length) {
	hF=FSO.OpenTextFile(WScript.ScriptFullName,2,false);
	for(var line,i=0;i<lines.length;++i) {
		if (((line=lines[i]).indexOf("#def"+"ine"))!=-1) {
			line=line.split(" ");
			line[2]=parseInt(line[2])+1;
			line=line.join(" ");
		}
		hF.WriteLine(line);
	}
}
@end @*/
Advertisements

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s