trunk/src/build/verinfo.c
| r243509 | r243510 | |
| 1 | | //============================================================ |
| 2 | | // |
| 3 | | // verinfo.c - Version resource emitter code |
| 4 | | // |
| 5 | | // Copyright Nicola Salmoria and the MAME Team. |
| 6 | | // Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | // |
| 8 | | //============================================================ |
| 9 | | |
| 10 | | #include <stdio.h> |
| 11 | | #include <ctype.h> |
| 12 | | |
| 13 | | #include <string.h> |
| 14 | | #include <stdlib.h> |
| 15 | | |
| 16 | | typedef unsigned char UINT8; |
| 17 | | |
| 18 | | #define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0])) |
| 19 | | #define BUILD_MAME (0) |
| 20 | | #define BUILD_MESS (1) |
| 21 | | #define BUILD_UME (2) |
| 22 | | |
| 23 | | //============================================================ |
| 24 | | // TYPE DEFINITIONS |
| 25 | | //============================================================ |
| 26 | | |
| 27 | | struct version_info |
| 28 | | { |
| 29 | | int version_major; |
| 30 | | int version_minor; |
| 31 | | int version_build; |
| 32 | | int version_subbuild; |
| 33 | | const char *version_string; |
| 34 | | const char *author; |
| 35 | | const char *comments; |
| 36 | | const char *company_name; |
| 37 | | const char *file_description; |
| 38 | | const char *internal_name; |
| 39 | | const char *legal_copyright; |
| 40 | | const char *original_filename; |
| 41 | | const char *product_name; |
| 42 | | }; |
| 43 | | |
| 44 | | |
| 45 | | |
| 46 | | //============================================================ |
| 47 | | // STATIC |
| 48 | | //============================================================ |
| 49 | | |
| 50 | | static int build; |
| 51 | | |
| 52 | | |
| 53 | | //============================================================ |
| 54 | | // emit_version_info |
| 55 | | //============================================================ |
| 56 | | |
| 57 | | static void emit_version_info(const version_info *v) |
| 58 | | { |
| 59 | | printf("VS_VERSION_INFO VERSIONINFO\n"); |
| 60 | | printf("\tFILEVERSION %d,%d,%d,%d\n", v->version_major, v->version_minor, v->version_build, v->version_subbuild); |
| 61 | | printf("\tPRODUCTVERSION %d,%d,%d,%d\n", v->version_major, v->version_minor, v->version_build, v->version_subbuild); |
| 62 | | printf("\tFILEFLAGSMASK 0x3fL\n"); |
| 63 | | #ifdef MAME_DEBUG |
| 64 | | if (v->version_build == 0) |
| 65 | | printf("\tFILEFLAGS VS_FF_DEBUG\n"); |
| 66 | | else |
| 67 | | printf("\tFILEFLAGS VS_FF_PRERELEASE | VS_FF_DEBUG\n"); |
| 68 | | #else |
| 69 | | if (v->version_build == 0) |
| 70 | | printf("\tFILEFLAGS 0x0L\n"); |
| 71 | | else |
| 72 | | printf("\tFILEFLAGS VS_FF_PRERELEASE\n"); |
| 73 | | #endif |
| 74 | | printf("\tFILEOS VOS_NT_WINDOWS32\n"); |
| 75 | | printf("\tFILETYPE VFT_APP\n"); |
| 76 | | printf("\tFILESUBTYPE VFT2_UNKNOWN\n"); |
| 77 | | printf("BEGIN\n"); |
| 78 | | printf("\tBLOCK \"StringFileInfo\"\n"); |
| 79 | | printf("\tBEGIN\n"); |
| 80 | | printf("#ifdef UNICODE\n"); |
| 81 | | printf("\t\tBLOCK \"040904b0\"\n"); |
| 82 | | printf("#else\n"); |
| 83 | | printf("\t\tBLOCK \"040904E4\"\n"); |
| 84 | | printf("#endif\n"); |
| 85 | | printf("\t\tBEGIN\n"); |
| 86 | | if (v->author != NULL) |
| 87 | | printf("\t\t\tVALUE \"Author\", \"%s\\0\"\n", v->author); |
| 88 | | if (v->comments != NULL) |
| 89 | | printf("\t\t\tVALUE \"Comments\", \"%s\\0\"\n", v->comments); |
| 90 | | if (v->company_name != NULL) |
| 91 | | printf("\t\t\tVALUE \"CompanyName\", \"%s\\0\"\n", v->company_name); |
| 92 | | if (v->file_description != NULL) |
| 93 | | printf("\t\t\tVALUE \"FileDescription\", \"%s\\0\"\n", v->file_description); |
| 94 | | printf("\t\t\tVALUE \"FileVersion\", \"%d, %d, %d, %d\\0\"\n", v->version_major, v->version_minor, v->version_build, v->version_subbuild); |
| 95 | | if (v->internal_name != NULL) |
| 96 | | printf("\t\t\tVALUE \"InternalName\", \"%s\\0\"\n", v->internal_name); |
| 97 | | if (v->legal_copyright != NULL) |
| 98 | | printf("\t\t\tVALUE \"LegalCopyright\", \"%s\\0\"\n", v->legal_copyright); |
| 99 | | if (v->original_filename != NULL) |
| 100 | | printf("\t\t\tVALUE \"OriginalFilename\", \"%s\\0\"\n", v->original_filename); |
| 101 | | if (v->product_name != NULL) |
| 102 | | printf("\t\t\tVALUE \"ProductName\", \"%s\\0\"\n", v->product_name); |
| 103 | | printf("\t\t\tVALUE \"ProductVersion\", \"%s\\0\"\n", v->version_string); |
| 104 | | printf("\t\tEND\n"); |
| 105 | | printf("\tEND\n"); |
| 106 | | printf("\tBLOCK \"VarFileInfo\"\n"); |
| 107 | | printf("\tBEGIN\n"); |
| 108 | | printf("#ifdef UNICODE\n"); |
| 109 | | printf("\t\tVALUE \"Translation\", 0x409, 1200\n"); |
| 110 | | printf("#else\n"); |
| 111 | | printf("\t\tVALUE \"Translation\", 0x409, 1252\n"); |
| 112 | | printf("#endif\n"); |
| 113 | | printf("\tEND\n"); |
| 114 | | printf("END\n"); |
| 115 | | } |
| 116 | | |
| 117 | | |
| 118 | | |
| 119 | | //============================================================ |
| 120 | | // parse_version_digit |
| 121 | | //============================================================ |
| 122 | | |
| 123 | | static bool parse_version_digit(const char *str, int *position, int* value) |
| 124 | | { |
| 125 | | int res = 0; |
| 126 | | |
| 127 | | while (str[*position] != 0 && !isspace((UINT8)str[*position]) && !isdigit((UINT8)str[*position])) |
| 128 | | (*position)++; |
| 129 | | |
| 130 | | if (str[*position] != 0 && isdigit((UINT8)str[*position])) |
| 131 | | { |
| 132 | | res = sscanf(&str[*position], "%d", value); |
| 133 | | while (isdigit((UINT8)str[*position])) |
| 134 | | (*position)++; |
| 135 | | } |
| 136 | | return res == 1; |
| 137 | | } |
| 138 | | |
| 139 | | |
| 140 | | |
| 141 | | //============================================================ |
| 142 | | // parse_version |
| 143 | | //============================================================ |
| 144 | | |
| 145 | | static int parse_version(char *str, int *version_major, int *version_minor, const char **version_string) |
| 146 | | { |
| 147 | | char *version; |
| 148 | | int position = 0; |
| 149 | | |
| 150 | | // find the version string |
| 151 | | version = strstr(str, "BARE_BUILD_VERSION"); |
| 152 | | if (version != NULL) |
| 153 | | version = strchr(version, '"'); |
| 154 | | if (version == NULL || *version == '\0' || strchr(version, '.') == NULL) |
| 155 | | { |
| 156 | | fprintf(stderr, "Unable to find version string\n"); |
| 157 | | return 1; |
| 158 | | } |
| 159 | | version++; |
| 160 | | *strchr(version, '"') = 0; |
| 161 | | |
| 162 | | *version_string = version; |
| 163 | | if (!parse_version_digit(version, &position, version_major)) |
| 164 | | { |
| 165 | | fprintf(stderr, "Unable to parse major version\n"); |
| 166 | | return 1; |
| 167 | | } |
| 168 | | if (!parse_version_digit(version, &position, version_minor)) |
| 169 | | { |
| 170 | | fprintf(stderr, "Unable to parse minor version\n"); |
| 171 | | return 1; |
| 172 | | } |
| 173 | | return 0; |
| 174 | | } |
| 175 | | |
| 176 | | |
| 177 | | |
| 178 | | //============================================================ |
| 179 | | // main |
| 180 | | //============================================================ |
| 181 | | static int usage(char *me) |
| 182 | | { |
| 183 | | fprintf(stderr, "Usage: %s [-b mame|mess|ume] <filename>\n", me); |
| 184 | | return 1; |
| 185 | | } |
| 186 | | |
| 187 | | |
| 188 | | //============================================================ |
| 189 | | // main |
| 190 | | //============================================================ |
| 191 | | |
| 192 | | int main(int argc, char *argv[]) |
| 193 | | { |
| 194 | | version_info v; |
| 195 | | char legal_copyright[512]; |
| 196 | | char *buffer; |
| 197 | | size_t size; |
| 198 | | int opt; |
| 199 | | FILE *f; |
| 200 | | |
| 201 | | memset(&v, 0, sizeof(v)); |
| 202 | | build = BUILD_MAME; |
| 203 | | |
| 204 | | // validate parameters |
| 205 | | opt = 1; |
| 206 | | while (opt < argc && *argv[opt] == '-') |
| 207 | | { |
| 208 | | if (!strcmp(argv[opt], "-b")) |
| 209 | | { |
| 210 | | char *p = argv[++opt]; |
| 211 | | if (!strcmp(p,"mame")) |
| 212 | | build = BUILD_MAME; |
| 213 | | else if (!strcmp(p,"mess")) |
| 214 | | build = BUILD_MESS; |
| 215 | | else if (!strcmp(p,"ume")) |
| 216 | | build = BUILD_UME; |
| 217 | | else |
| 218 | | return usage(argv[0]); |
| 219 | | } |
| 220 | | else |
| 221 | | return usage(argv[0]); |
| 222 | | opt++; |
| 223 | | } |
| 224 | | |
| 225 | | if (opt != argc-1 ) |
| 226 | | { |
| 227 | | return usage(argv[0]); |
| 228 | | } |
| 229 | | |
| 230 | | // open the file |
| 231 | | f = fopen(argv[argc-1], "rb"); |
| 232 | | if (f == NULL) |
| 233 | | { |
| 234 | | fprintf(stderr, "Error opening file %s\n", argv[argc-1]); |
| 235 | | return 1; |
| 236 | | } |
| 237 | | |
| 238 | | // get the file size |
| 239 | | fseek(f, 0, SEEK_END); |
| 240 | | size = ftell(f); |
| 241 | | fseek(f, 0, SEEK_SET); |
| 242 | | |
| 243 | | // allocate a buffer |
| 244 | | buffer = (char *)malloc(size + 1); |
| 245 | | if (buffer == NULL) |
| 246 | | { |
| 247 | | fclose(f); |
| 248 | | fprintf(stderr, "Error allocating %ld bytes\n", (long) size + 1); |
| 249 | | return 1; |
| 250 | | } |
| 251 | | |
| 252 | | // read the file contents and NULL-terminate |
| 253 | | fread(buffer, 1, size, f); |
| 254 | | fclose(f); |
| 255 | | buffer[size] = 0; |
| 256 | | |
| 257 | | // parse out version string |
| 258 | | if (parse_version(buffer, &v.version_major, &v.version_minor, &v.version_string)) |
| 259 | | { |
| 260 | | fprintf(stderr, "Error parsing version\n"); |
| 261 | | free(buffer); |
| 262 | | return 1; |
| 263 | | } |
| 264 | | |
| 265 | | if (build == BUILD_MESS) |
| 266 | | { |
| 267 | | // MESS |
| 268 | | v.author = "MESS Team"; |
| 269 | | v.comments = "Multi Emulation Super System"; |
| 270 | | v.company_name = "MESS Team"; |
| 271 | | v.file_description = "Multi Emulation Super System"; |
| 272 | | v.internal_name = "MESS"; |
| 273 | | v.original_filename = "MESS"; |
| 274 | | v.product_name = "MESS"; |
| 275 | | } |
| 276 | | else if (build == BUILD_UME) |
| 277 | | { |
| 278 | | // UME |
| 279 | | v.author = "MAME and MESS Team"; |
| 280 | | v.comments = "Universal Machine Emulator"; |
| 281 | | v.company_name = "MAME and MESS Team"; |
| 282 | | v.file_description = "Universal Machine Emulator"; |
| 283 | | v.internal_name = "UME"; |
| 284 | | v.original_filename = "UME"; |
| 285 | | v.product_name = "UME"; |
| 286 | | } |
| 287 | | else |
| 288 | | { |
| 289 | | // MAME |
| 290 | | v.author = "Nicola Salmoria and the MAME Team"; |
| 291 | | v.comments = "Multiple Arcade Machine Emulator"; |
| 292 | | v.company_name = "MAME Team"; |
| 293 | | v.file_description = "Multiple Arcade Machine Emulator"; |
| 294 | | v.internal_name = "MAME"; |
| 295 | | v.original_filename = "MAME"; |
| 296 | | v.product_name = "MAME"; |
| 297 | | } |
| 298 | | |
| 299 | | // build legal_copyright string |
| 300 | | v.legal_copyright = legal_copyright; |
| 301 | | snprintf(legal_copyright, ARRAY_LENGTH(legal_copyright), "Copyright Nicola Salmoria and the MAME team"); |
| 302 | | |
| 303 | | // emit the info |
| 304 | | emit_version_info(&v); |
| 305 | | |
| 306 | | free(buffer); |
| 307 | | return 0; |
| 308 | | } |
trunk/src/build/verinfo.py
| r0 | r243510 | |
| 1 | #!/usr/bin/python |
| 2 | |
| 3 | from __future__ import with_statement |
| 4 | |
| 5 | import sys |
| 6 | import os |
| 7 | |
| 8 | def usage(): |
| 9 | sys.stderr.write('Usage: verinfo.py [-b mame|mess|ume] <filename>\n') |
| 10 | return 0 |
| 11 | |
| 12 | build = "mame" |
| 13 | |
| 14 | if (len(sys.argv)==1): |
| 15 | usage() |
| 16 | sys.exit(1) |
| 17 | |
| 18 | if (sys.argv[1]=='-b'): |
| 19 | if (sys.argv[2]=='mame'): |
| 20 | build = "mame" |
| 21 | elif (sys.argv[2]=='mess'): |
| 22 | build = "mess" |
| 23 | elif (sys.argv[2]=='ume'): |
| 24 | build = "ume" |
| 25 | else : |
| 26 | usage() |
| 27 | sys.exit(1) |
| 28 | |
| 29 | srcfile = sys.argv[len(sys.argv)-1] |
| 30 | try: |
| 31 | fp = open(srcfile, 'rb') |
| 32 | except IOError: |
| 33 | sys.stderr.write("Unable to open source file '%s'" % srcfile) |
| 34 | sys.exit(1) |
| 35 | |
| 36 | for line in fp.readlines(): |
| 37 | if line.find("BARE_BUILD_VERSION")!=-1 and line.find('"')!=-1 and line.find('.')!=-1: |
| 38 | version_string = line[line.find('"')+1:] |
| 39 | version_string = version_string[0:version_string.find('"')] |
| 40 | break |
| 41 | |
| 42 | version_major = version_string[0:version_string.find('.')] |
| 43 | version_minor = version_string[version_string.find('.')+1:] |
| 44 | version_build = "0" |
| 45 | version_subbuild = "0" |
| 46 | if (build == "mame") : |
| 47 | # MESS |
| 48 | author = "MESS Team"; |
| 49 | comments = "Multi Emulation Super System"; |
| 50 | company_name = "MESS Team"; |
| 51 | file_description = "Multi Emulation Super System"; |
| 52 | internal_name = "MESS"; |
| 53 | original_filename = "MESS"; |
| 54 | product_name = "MESS"; |
| 55 | elif (build == "mess") : |
| 56 | # UME |
| 57 | author = "MAME and MESS Team" |
| 58 | comments = "Universal Machine Emulator" |
| 59 | company_name = "MAME and MESS Team" |
| 60 | file_description = "Universal Machine Emulator" |
| 61 | internal_name = "UME" |
| 62 | original_filename = "UME" |
| 63 | product_name = "UME" |
| 64 | else : |
| 65 | # MAME |
| 66 | author = "Nicola Salmoria and the MAME Team" |
| 67 | comments = "Multiple Arcade Machine Emulator" |
| 68 | company_name = "MAME Team" |
| 69 | file_description = "Multiple Arcade Machine Emulator" |
| 70 | internal_name = "MAME" |
| 71 | original_filename = "MAME" |
| 72 | product_name = "MAME" |
| 73 | |
| 74 | legal_copyright = "Copyright Nicola Salmoria and the MAME team" |
| 75 | |
| 76 | print("VS_VERSION_INFO VERSIONINFO") |
| 77 | print("\tFILEVERSION %s,%s,%s,%s" % (version_major, version_minor, version_build, version_subbuild)) |
| 78 | print("\tPRODUCTVERSION %s,%s,%s,%s" % (version_major, version_minor, version_build, version_subbuild)) |
| 79 | print("\tFILEFLAGSMASK 0x3fL") |
| 80 | if (version_build == 0) : |
| 81 | print("\tFILEFLAGS 0x0L") |
| 82 | else : |
| 83 | print("\tFILEFLAGS VS_FF_PRERELEASE") |
| 84 | print("\tFILEOS VOS_NT_WINDOWS32") |
| 85 | print("\tFILETYPE VFT_APP") |
| 86 | print("\tFILESUBTYPE VFT2_UNKNOWN") |
| 87 | print("BEGIN") |
| 88 | print("\tBLOCK \"StringFileInfo\"") |
| 89 | print("\tBEGIN") |
| 90 | print("#ifdef UNICODE") |
| 91 | print("\t\tBLOCK \"040904b0\"") |
| 92 | print("#else") |
| 93 | print("\t\tBLOCK \"040904E4\"") |
| 94 | print("#endif") |
| 95 | print("\t\tBEGIN") |
| 96 | print("\t\t\tVALUE \"Author\", \"%s\\0\"" % author) |
| 97 | print("\t\t\tVALUE \"Comments\", \"%s\\0\"" % comments) |
| 98 | print("\t\t\tVALUE \"CompanyName\", \"%s\\0\"" % company_name) |
| 99 | print("\t\t\tVALUE \"FileDescription\", \"%s\\0\"" % file_description) |
| 100 | print("\t\t\tVALUE \"FileVersion\", \"%s, %s, %s, %s\\0\"" % (version_major, version_minor, version_build, version_subbuild)) |
| 101 | print("\t\t\tVALUE \"InternalName\", \"%s\\0\"" % internal_name) |
| 102 | print("\t\t\tVALUE \"LegalCopyright\", \"%s\\0\"" % legal_copyright) |
| 103 | print("\t\t\tVALUE \"OriginalFilename\", \"%s\\0\"" % original_filename) |
| 104 | print("\t\t\tVALUE \"ProductName\", \"%s\\0\"" % product_name) |
| 105 | print("\t\t\tVALUE \"ProductVersion\", \"%s\\0\"" % version_string) |
| 106 | print("\t\tEND") |
| 107 | print("\tEND") |
| 108 | print("\tBLOCK \"VarFileInfo\"") |
| 109 | print("\tBEGIN") |
| 110 | print("#ifdef UNICODE") |
| 111 | print("\t\tVALUE \"Translation\", 0x409, 1200") |
| 112 | print("#else") |
| 113 | print("\t\tVALUE \"Translation\", 0x409, 1252") |
| 114 | print("#endif") |
| 115 | print("\tEND") |
| 116 | print("END") |
| | No newline at end of file |