| 500 | |
| 501 | /* |
| 502 | * GetVersionFromFile -- |
| 503 | * Looks for a match string in a file and then returns the version |
| 504 | * following the match where a version is anything acceptable to |
| 505 | * package provide or package ifneeded. |
| 506 | */ |
| 507 | |
| 508 | static const char * |
| 509 | GetVersionFromFile( |
| 510 | const char *filename, |
| 511 | const char *match, |
| 512 | int numdots) |
| 513 | { |
| 514 | static char szBuffer[100]; |
| 515 | char *szResult = NULL; |
| 516 | FILE *fp = fopen(filename, "rt"); |
| 517 | |
| 518 | if (fp != NULL) { |
| 519 | /* |
| 520 | * Read data until we see our match string. |
| 521 | */ |
| 522 | |
| 523 | while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) { |
| 524 | LPSTR p, q; |
| 525 | |
| 526 | p = strstr(szBuffer, match); |
| 527 | if (p != NULL) { |
| 528 | /* |
| 529 | * Skip to first digit after the match. |
| 530 | */ |
| 531 | |
| 532 | p += strlen(match); |
| 533 | while (*p && !isdigit((unsigned char)*p)) { |
| 534 | ++p; |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * Find ending whitespace. |
| 539 | */ |
| 540 | |
| 541 | q = p; |
| 542 | while (*q && (strchr("0123456789.ab", *q)) && (((!strchr(".ab", *q) |
| 543 | && !strchr("ab", q[-1])) || --numdots))) { |
| 544 | ++q; |
| 545 | } |
| 546 | |
| 547 | *q = 0; |
| 548 | szResult = p; |
| 549 | break; |
| 550 | } |
| 551 | } |
| 552 | fclose(fp); |