[MT05835] show correct version number in file datils [Oliver Stöneberg]

adjusted verinfo code for new version.c format / also added more
errorhandling and removed some unnecessary code
This commit is contained in:
Oliver Stöneberg 2015-01-30 01:46:36 +01:00
parent e0f37807b1
commit e93a559587

View File

@ -120,20 +120,20 @@ static void emit_version_info(const version_info *v)
// parse_version_digit // parse_version_digit
//============================================================ //============================================================
static int parse_version_digit(const char *str, int *position) static bool parse_version_digit(const char *str, int *position, int* value)
{ {
int value = 0; int res = 0;
while (str[*position] != 0 && !isspace((UINT8)str[*position]) && !isdigit((UINT8)str[*position])) while (str[*position] != 0 && !isspace((UINT8)str[*position]) && !isdigit((UINT8)str[*position]))
(*position)++; (*position)++;
if (str[*position] != 0 && isdigit((UINT8)str[*position])) if (str[*position] != 0 && isdigit((UINT8)str[*position]))
{ {
sscanf(&str[*position], "%d", &value); res = sscanf(&str[*position], "%d", value);
while (isdigit((UINT8)str[*position])) while (isdigit((UINT8)str[*position]))
(*position)++; (*position)++;
} }
return value; return res == 1;
} }
@ -142,27 +142,34 @@ static int parse_version_digit(const char *str, int *position)
// parse_version // parse_version
//============================================================ //============================================================
static int parse_version(char *str, int *version_major, int *version_minor, int *version_micro, const char **version_string) static int parse_version(char *str, int *version_major, int *version_minor, const char **version_string)
{ {
char *version; char *version;
int position = 0; int position = 0;
// find the version string // find the version string
version = strstr(str, "build_version"); version = strstr(str, "BARE_BUILD_VERSION");
if (version != NULL) if (version != NULL)
version = strchr(version, '"'); version = strchr(version, '"');
if (version == NULL) if (version == NULL || *version == '\0' || strchr(version, '.') == NULL)
{ {
fprintf(stderr, "Unable to find build_version string\n"); fprintf(stderr, "Unable to find version string\n");
return 1; return 1;
} }
version++; version++;
*strchr(version, ' ') = 0; *strchr(version, '"') = 0;
*version_string = version; *version_string = version;
*version_major = parse_version_digit(version, &position); if (!parse_version_digit(version, &position, version_major))
*version_minor = parse_version_digit(version, &position); {
*version_micro = parse_version_digit(version, &position); fprintf(stderr, "Unable to parse major version\n");
return 1;
}
if (!parse_version_digit(version, &position, version_minor))
{
fprintf(stderr, "Unable to parse minor version\n");
return 1;
}
return 0; return 0;
} }
@ -248,9 +255,9 @@ int main(int argc, char *argv[])
buffer[size] = 0; buffer[size] = 0;
// parse out version string // parse out version string
if (parse_version(buffer, &v.version_major, &v.version_minor, &v.version_build, &v.version_string)) if (parse_version(buffer, &v.version_major, &v.version_minor, &v.version_string))
{ {
fprintf(stderr, "Error parsing version from '%s'\n", buffer); fprintf(stderr, "Error parsing version\n");
free(buffer); free(buffer);
return 1; return 1;
} }