Previous 199869 Revisions Next

r34735 Friday 30th January, 2015 at 00:46:36 UTC by Oliver Stöneberg
[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
[src/build]verinfo.c

trunk/src/build/verinfo.c
r243246r243247
120120//  parse_version_digit
121121//============================================================
122122
123static int parse_version_digit(const char *str, int *position)
123static bool parse_version_digit(const char *str, int *position, int* value)
124124{
125   int value = 0;
125   int res = 0;
126126
127127   while (str[*position] != 0 && !isspace((UINT8)str[*position]) && !isdigit((UINT8)str[*position]))
128128      (*position)++;
129129
130130   if (str[*position] != 0 && isdigit((UINT8)str[*position]))
131131   {
132      sscanf(&str[*position], "%d", &value);
132      res = sscanf(&str[*position], "%d", value);
133133      while (isdigit((UINT8)str[*position]))
134134         (*position)++;
135135   }
136   return value;
136   return res == 1;
137137}
138138
139139
r243246r243247
142142//  parse_version
143143//============================================================
144144
145static int parse_version(char *str, int *version_major, int *version_minor, int *version_micro, const char **version_string)
145static int parse_version(char *str, int *version_major, int *version_minor, const char **version_string)
146146{
147147   char *version;
148148   int position = 0;
149149
150150   // find the version string
151   version = strstr(str, "build_version");
151   version = strstr(str, "BARE_BUILD_VERSION");
152152   if (version != NULL)
153153      version = strchr(version, '"');
154   if (version == NULL)
154   if (version == NULL || *version == '\0' || strchr(version, '.') == NULL)
155155   {
156      fprintf(stderr, "Unable to find build_version string\n");
156      fprintf(stderr, "Unable to find version string\n");
157157      return 1;
158158   }
159159   version++;
160   *strchr(version, ' ') = 0;
160   *strchr(version, '"') = 0;
161161
162162   *version_string = version;
163   *version_major = parse_version_digit(version, &position);
164   *version_minor = parse_version_digit(version, &position);
165   *version_micro = parse_version_digit(version, &position);
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   }
166173   return 0;
167174}
168175
r243246r243247
248255   buffer[size] = 0;
249256
250257   // parse out version string
251   if (parse_version(buffer, &v.version_major, &v.version_minor, &v.version_build, &v.version_string))
258   if (parse_version(buffer, &v.version_major, &v.version_minor, &v.version_string))
252259   {
253      fprintf(stderr, "Error parsing version from '%s'\n", buffer);
260      fprintf(stderr, "Error parsing version\n");
254261      free(buffer);
255262      return 1;
256263   }


Previous 199869 Revisions Next


© 1997-2024 The MAME Team