24#define WIN32_LEAN_AND_MEAN
32#define VERSION_BUILDNUM "VERSION_LOCALBUILDNUM"
33#define VERSION_STRING "LOCAL_BUILD_STRING"
34#define VERSION_BUILDUSER "VERSION_BUILDUSER"
35#define VERSION_BUILDLOC "VERSION_BUILDLOC"
36#define FORMAT "#define " VERSION_STRING " \"%d\"\n"
37#define COMMENTS "// Do not modify this file by hand. Auto-created and\n// Updated by versionUpdate.\n"
38#define NUMFMT "#define %s %d\n"
39#define STRFMT "#define %s \"%s\"\n"
41static void writeVersion(
char *file,
int build)
43 FILE *filePtr = fopen(file,
"w");
49 unsigned long bufSize = UNLEN + 1;
50 char userName[UNLEN + 1];
51 if (!GetUserName(userName, &bufSize))
53 strcpy(userName,
"unknown");
56 bufSize = MAX_COMPUTERNAME_LENGTH + 1;
57 char computerName[MAX_COMPUTERNAME_LENGTH + 1];
58 if (!GetComputerName(computerName, &bufSize))
60 strcpy(computerName,
"unknown");
63 printf(
"Build is by %s at %s\n", userName, computerName);
66 fprintf(filePtr,
FORMAT, build);
74 printf(
"Cannot write file\n");
79 printf(
"No file to write\n");
83static void usage(
char *progname)
87 printf (
"Usage: %s versionfile.h", progname);
95static char*
strtrim(
char* buffer)
99 char * source = buffer;
100 while ((*source != 0) && ((
unsigned char)*source <= 32))
105 if (source != buffer)
107 strcpy(buffer, source);
111 for (
int index = strlen(buffer)-1; index >= 0; index--)
113 if ((*source != 0) && ((
unsigned char)buffer[index] <= 32))
115 buffer[index] =
'\0';
128 HINSTANCE hPrevInstance,
139 char * token = strtok(lpCmdLine,
" ");
140 while (argc < 20 && token !=
NULL)
143 token = strtok(
NULL,
" ");
154 char *target = argv[argc-1];
158 filePtr = fopen(target,
"r+");
162 char *stringPtr =
NULL;
164 while (!feof(filePtr))
166 fread(buffer, 256, 1, filePtr);
172 ptr = strtok(stringPtr,
" ");
173 ptr = strtok(
NULL,
"\n");
183 printf (
"Local build is %d\n", build);
184 writeVersion(target, build);
188 printf (
"Local build is 0. Oops, didn't find a string of the format: '#define VERSION \"x.y.z\"'");
196 printf (
"Local build is %d\n", build);
197 writeVersion(target, build);
char * strtrim(char *buffer)
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#define VERSION_BUILDUSER