Author: dgorbachev Date: Sat Jun 13 01:42:32 2009 New Revision: 41397
URL: http://svn.reactos.org/svn/reactos?rev=41397&view=rev Log: Fix bug #4558 ("buildno" is not compatible with SVN 1.6).
Modified: trunk/reactos/tools/buildno/buildno.cpp
Modified: trunk/reactos/tools/buildno/buildno.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/buildno/buildno.cpp?r... ============================================================================== --- trunk/reactos/tools/buildno/buildno.cpp [iso-8859-1] (original) +++ trunk/reactos/tools/buildno/buildno.cpp [iso-8859-1] Sat Jun 13 01:42:32 2009 @@ -45,38 +45,35 @@ return i; }
-char * -GetRev(void) +long +GetRev(char *Revision, size_t length) { - static char Unknown[] = "UNKNOWN"; - static char Revision[10]; /* 999999999 revisions should be enough for everyone... */ - - /* SVN 1.4.x-1.5.x */ + long revno = 0; + char *p; + FILE *fp = NULL; - char ch; - size_t count = 0, chars = 0; fp = fopen(".svn/entries", "r"); if (fp != NULL) { - ch=fgetc(fp); - if (ch == 56 || ch == 57) /* some kind of header? */ - { - while((ch=fgetc(fp)) != EOF) + if (fgets(Revision, length, fp) != NULL) + { + /* If the first character of the file is not a digit, + then it is probably in XML format. */ + if (isdigit(Revision[0])) { - if (ch == 10) - count++; /* seems to used as a seperator */ - if (count > 3) - break; - if ((count == 3) && (chars < sizeof(Revision))) + while (fgets(Revision, length, fp) != NULL) { - if (chars != 0) - Revision[chars - 1] = ch; - chars++; + revno = strtol(Revision, &p, 10); + if (revno != 0) + { + *p = '\0'; + fclose(fp); + return revno; + } } } - fclose(fp); - return Revision; - } + } + fclose(fp); }
try @@ -113,20 +110,21 @@ } if ("revision" == Attribute->name) { - if (sizeof(Revision) <= Attribute->value.length() + 1) + if (length <= Attribute->value.length() + 1) { strcpy(Revision, "revtoobig"); } else { strcpy(Revision, Attribute->value.c_str()); + revno = strtol(Revision, NULL, 10); } GotRevision = true; } if (GotName && GotKind && GotRevision) { delete head; - return Revision; + return revno; } } } @@ -139,11 +137,12 @@ ; }
- return Unknown; + strcpy(Revision, "UNKNOWN"); + return revno; }
void -write_h (int build, char *buildstr) +write_h (int build, char *buildstr, long revno) { FILE *h = NULL; char* s; @@ -159,7 +158,7 @@ s = s + sprintf (s, "#define _INC_REACTOS_BUILDNO\n" );
s = s + sprintf (s, "#define KERNEL_VERSION_BUILD\t%d\n", build); - s = s + sprintf (s, "#define KERNEL_VERSION_BUILD_HEX\t0x%x\n", atoi(GetRev())); + s = s + sprintf (s, "#define KERNEL_VERSION_BUILD_HEX\t0x%lx\n", revno); s = s + sprintf (s, "#define KERNEL_VERSION_BUILD_STR\t"%s"\n", buildstr); s = s + sprintf (s, "#define KERNEL_VERSION_BUILD_RC\t"%s\0"\n", buildstr); s = s + sprintf (s, "#define KERNEL_RELEASE_RC\t"%d.%d", @@ -285,7 +284,8 @@ int quiet = FALSE;
int build = 0; - char buildstr[64]; + long revno; + char buildstr[64], revision[10];
time_t t1 = 0; struct tm * t1_tm = NULL; @@ -382,7 +382,8 @@ build_tag = new_build_tag; }
- sprintf(buildstr, "%d-r%s", build, GetRev()); + revno = GetRev(revision, sizeof(revision)); + sprintf(buildstr, "%d-r%s", build, revision);
if (! quiet) { @@ -399,7 +400,7 @@ /* (Over)write the include file, unless the user switched on -p. */ if (! print_only) { - write_h (build, buildstr); + write_h (build, buildstr, revno); } else {