[FORMATTING] Fix formatting

svn path=/trunk/; revision=31744
This commit is contained in:
Hervé Poussineau 2008-01-12 17:54:45 +00:00
parent 896d74327d
commit f94c2a7484

View file

@ -1,5 +1,4 @@
/* $Id$ /*
*
* buildno - Generate the build number for ReactOS * buildno - Generate the build number for ReactOS
* *
* Copyright (c) 1999,2000 Emanuele Aliberti * Copyright (c) 1999,2000 Emanuele Aliberti
@ -11,9 +10,9 @@
* The build number is stored in the file * The build number is stored in the file
* <reactos/buildno.h> as a set of macros: * <reactos/buildno.h> as a set of macros:
* *
* KERNEL_VERSION_BUILD base 10 number * KERNEL_VERSION_BUILD base 10 number
* KERNEL_VERSION_BUILD_STR C string * KERNEL_VERSION_BUILD_STR C string
* KERNEL_VERSION_BUILD_RC RC string * KERNEL_VERSION_BUILD_RC RC string
* *
* REVISIONS * REVISIONS
* --------- * ---------
@ -40,245 +39,229 @@ static char * argv0 = "";
static char * filename = ""; static char * filename = "";
static char * kernel_version_build_type = 0; static char * kernel_version_build_type = 0;
#ifdef DBG
void
tm_dump (const char *tag, struct tm * t)
{
printf ("%s->tm_sec = %d\n", tag, t->tm_sec);
printf ("%s->tm_min = %d\n", tag, t->tm_min);
printf ("%s->tm_hour = %d\n", tag, t->tm_hour);
printf ("%s->tm_mday = %d\n", tag, t->tm_mday);
printf ("%s->tm_mon = %d\n", tag, t->tm_mon);
printf ("%s->tm_year = %d\n", tag, t->tm_year);
printf ("%s->tm_wday = %d\n", tag, t->tm_wday);
printf ("%s->tm_yday = %d\n", tag, t->tm_yday);
printf ("%s->tm_isdst = %d\n\n", tag, t->tm_isdst);
}
#endif
int count_wide_string( wchar_t *str ) int count_wide_string( wchar_t *str )
{ {
int i; int i;
for( i = 0; str[i]; i++ )
for( i = 0; str[i]; i++ ); ;
return i;
return i;
} }
char * char *
GetRev(void) GetRev(void)
{ {
static char Unknown[] = "UNKNOWN"; static char Unknown[] = "UNKNOWN";
static char Revision[10]; /* 999999999 revisions should be enough for everyone... */ static char Revision[10]; /* 999999999 revisions should be enough for everyone... */
/* SVN 1.4.x */ /* SVN 1.4.x */
FILE *fp = NULL; FILE *fp = NULL;
char ch; char ch;
size_t count = 0, chars = 0; size_t count = 0, chars = 0;
fp = fopen(".svn/entries", "r"); fp = fopen(".svn/entries", "r");
if (fp != NULL) if (fp != NULL)
{ {
if (fgetc(fp) == 56) /* some kind of header? */ if (fgetc(fp) == 56) /* some kind of header? */
{ {
while((ch=fgetc(fp)) != EOF) while((ch=fgetc(fp)) != EOF)
{ {
if (ch == 10) count++; /* seems to used as a seperator */ if (ch == 10)
if (count > 3) count++; /* seems to used as a seperator */
break; if (count > 3)
if ((count == 3) && (chars < sizeof(Revision))) break;
{ if ((count == 3) && (chars < sizeof(Revision)))
if (chars != 0) {
Revision[chars - 1] = ch; if (chars != 0)
chars++; Revision[chars - 1] = ch;
} chars++;
} }
fclose(fp); }
return Revision; fclose(fp);
} return Revision;
} }
}
try try
{ {
XMLElement *head; XMLElement *head;
try try
{ {
head = XMLLoadFile(".svn/entries"); head = XMLLoadFile(".svn/entries");
} }
catch(XMLFileNotFoundException) catch(XMLFileNotFoundException)
{ {
head = XMLLoadFile("_svn/entries"); head = XMLLoadFile("_svn/entries");
} }
XMLElement *entries = head->subElements[0]; XMLElement *entries = head->subElements[0];
for (size_t i = 0; i < entries->subElements.size(); i++) for (size_t i = 0; i < entries->subElements.size(); i++)
{ {
XMLElement *entry = entries->subElements[i]; XMLElement *entry = entries->subElements[i];
if ("entry" == entry->name) if ("entry" == entry->name)
{ {
bool GotName = false; bool GotName = false;
bool GotKind = false; bool GotKind = false;
bool GotRevision = false; bool GotRevision = false;
for (size_t j = 0; j < entry->attributes.size(); j++) for (size_t j = 0; j < entry->attributes.size(); j++)
{ {
XMLAttribute *Attribute = entry->attributes[j]; XMLAttribute *Attribute = entry->attributes[j];
if ("name" == Attribute->name && "" == Attribute->value) if ("name" == Attribute->name && "" == Attribute->value)
{ {
GotName = true; GotName = true;
} }
if ("kind" == Attribute->name && "dir" == Attribute->value) if ("kind" == Attribute->name && "dir" == Attribute->value)
{ {
GotKind = true; GotKind = true;
} }
if ("revision" == Attribute->name) if ("revision" == Attribute->name)
{ {
if (sizeof(Revision) <= Attribute->value.length() + 1) if (sizeof(Revision) <= Attribute->value.length() + 1)
{ {
strcpy(Revision, "revtoobig"); strcpy(Revision, "revtoobig");
} }
else else
{ {
strcpy(Revision, Attribute->value.c_str()); strcpy(Revision, Attribute->value.c_str());
} }
GotRevision = true; GotRevision = true;
} }
if (GotName && GotKind && GotRevision) if (GotName && GotKind && GotRevision)
{ {
delete head; delete head;
return Revision; return Revision;
} }
} }
} }
} }
delete head; delete head;
} }
catch(...) catch(...)
{ {
; ;
} }
return Unknown; return Unknown;
} }
void void
write_h (int build, char *buildstr) write_h (int build, char *buildstr)
{ {
FILE *h = NULL; FILE *h = NULL;
char* s; char* s;
char* s1; char* s1;
unsigned int length; unsigned int length;
int dllversion = KERNEL_VERSION_MAJOR + 42; int dllversion = KERNEL_VERSION_MAJOR + 42;
s1 = s = (char *) malloc(256 * 1024); s1 = s = (char *) malloc(256 * 1024);
s = s + sprintf (s, "/* Do not edit - Machine generated */\n"); s = s + sprintf (s, "/* Do not edit - Machine generated */\n");
s = s + sprintf (s, "#ifndef _INC_REACTOS_BUILDNO\n" ); s = s + sprintf (s, "#ifndef _INC_REACTOS_BUILDNO\n" );
s = s + sprintf (s, "#define _INC_REACTOS_BUILDNO\n" ); 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\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%x\n", atoi(GetRev()));
s = s + sprintf (s, "#define KERNEL_VERSION_BUILD_STR\t\"%s\"\n", buildstr); 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_VERSION_BUILD_RC\t\"%s\\0\"\n", buildstr);
s = s + sprintf (s, "#define KERNEL_RELEASE_RC\t\"%d.%d", s = s + sprintf (s, "#define KERNEL_RELEASE_RC\t\"%d.%d",
KERNEL_VERSION_MAJOR, KERNEL_VERSION_MINOR); KERNEL_VERSION_MAJOR, KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL) if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\\0\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define KERNEL_RELEASE_STR\t\"%d.%d",
KERNEL_VERSION_MAJOR,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define KERNEL_VERSION_RC\t\"%d.%d",
KERNEL_VERSION_MAJOR,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\\0\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define KERNEL_VERSION_STR\t\"%d.%d",
KERNEL_VERSION_MAJOR,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define REACTOS_DLL_VERSION_MAJOR\t%d\n", dllversion);
s = s + sprintf (s, "#define REACTOS_DLL_RELEASE_RC\t\"%d.%d",
dllversion, KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\\0\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define REACTOS_DLL_RELEASE_STR\t\"%d.%d",
dllversion,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define REACTOS_DLL_VERSION_RC\t\"%d.%d",
dllversion,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\\0\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define REACTOS_DLL_VERSION_STR\t\"%d.%d",
dllversion,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\"\n", kernel_version_build_type);
s = s + sprintf (s, "#endif\n/* EOF */\n");
h = fopen (filename, "wb");
if (h != NULL)
{
fseek(h, 0, SEEK_END);
length = ftell(h);
if (length == strlen(s1))
{ {
char* orig; s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
orig = (char *) malloc(length);
fseek(h, 0, SEEK_SET);
fread(orig, 1, length, h);
if (memcmp(s1, orig, length) == 0)
{
fclose(h);
free(s1);
return;
}
} }
fclose(h); s = s + sprintf (s, "-%s\\0\"\n", kernel_version_build_type);
} s = s + sprintf (s, "#define KERNEL_RELEASE_STR\t\"%d.%d",
KERNEL_VERSION_MAJOR,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define KERNEL_VERSION_RC\t\"%d.%d",
KERNEL_VERSION_MAJOR,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\\0\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define KERNEL_VERSION_STR\t\"%d.%d",
KERNEL_VERSION_MAJOR,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define REACTOS_DLL_VERSION_MAJOR\t%d\n", dllversion);
s = s + sprintf (s, "#define REACTOS_DLL_RELEASE_RC\t\"%d.%d",
dllversion, KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\\0\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define REACTOS_DLL_RELEASE_STR\t\"%d.%d",
dllversion,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define REACTOS_DLL_VERSION_RC\t\"%d.%d",
dllversion,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\\0\"\n", kernel_version_build_type);
s = s + sprintf (s, "#define REACTOS_DLL_VERSION_STR\t\"%d.%d",
dllversion,
KERNEL_VERSION_MINOR);
if (0 != KERNEL_VERSION_PATCH_LEVEL)
{
s = s + sprintf (s, ".%d", KERNEL_VERSION_PATCH_LEVEL);
}
s = s + sprintf (s, "-%s\"\n", kernel_version_build_type);
s = s + sprintf (s, "#endif\n/* EOF */\n");
h = fopen (filename, "wb"); h = fopen (filename, "wb");
if (!h) if (h != NULL)
{ {
fprintf (stderr, fseek(h, 0, SEEK_END);
"%s: can not create file \"%s\"!\n", length = ftell(h);
argv0, if (length == strlen(s1))
filename); {
free(s1); char* orig;
return;
} orig = (char *) malloc(length);
fwrite(s1, 1, strlen(s1), h); fseek(h, 0, SEEK_SET);
fclose (h); fread(orig, 1, length, h);
if (memcmp(s1, orig, length) == 0)
{
fclose(h);
free(s1);
return;
}
}
fclose(h);
}
h = fopen (filename, "wb");
if (!h)
{
fprintf (stderr,
"%s: can not create file \"%s\"!\n",
argv0,
filename);
free(s1);
return;
}
fwrite(s1, 1, strlen(s1), h);
fclose (h);
} }
void void
@ -286,9 +269,10 @@ usage (void)
{ {
fprintf ( fprintf (
stderr, stderr,
"Usage: %s [-{p|q}] path-to-header\n\n -p print version number and exit\n -q run in quiet mode\n", "Usage: %s [-{p|q}] path-to-header\n\n"
argv0 " -p print version number and exit\n"
); " -q run in quiet mode\n",
argv0);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }
@ -296,15 +280,15 @@ usage (void)
int int
main (int argc, char * argv []) main (int argc, char * argv [])
{ {
int i, length; int i, length;
int print_only = FALSE; int print_only = FALSE;
int quiet = FALSE; int quiet = FALSE;
int build = 0; int build = 0;
char buildstr[64]; char buildstr[64];
time_t t1 = 0; time_t t1 = 0;
struct tm * t1_tm = NULL; struct tm * t1_tm = NULL;
argv0 = argv[0]; argv0 = argv[0];
@ -342,13 +326,9 @@ main (int argc, char * argv [])
default: default:
usage (); usage ();
} }
/* /* Set TZ information. */
* Set TZ information.
*/
tzset (); tzset ();
/* /* We are building TODAY! */
* We are building TODAY!
*/
if (! quiet) if (! quiet)
{ {
printf ( "\nReactOS Build Number Generator\n\n"); printf ( "\nReactOS Build Number Generator\n\n");
@ -357,34 +337,28 @@ main (int argc, char * argv [])
/* Convert kernel_version_build_type to a host-friendly string */ /* Convert kernel_version_build_type to a host-friendly string */
length = count_wide_string(KERNEL_VERSION_BUILD_TYPE); length = count_wide_string(KERNEL_VERSION_BUILD_TYPE);
kernel_version_build_type = (char *)malloc(length+1); kernel_version_build_type = (char *)malloc(length+1);
for( i = 0; KERNEL_VERSION_BUILD_TYPE[i]; i++ ) { for( i = 0; KERNEL_VERSION_BUILD_TYPE[i]; i++ )
kernel_version_build_type[i] = KERNEL_VERSION_BUILD_TYPE[i]; {
kernel_version_build_type[i] = KERNEL_VERSION_BUILD_TYPE[i];
} }
kernel_version_build_type[i] = 0; kernel_version_build_type[i] = 0;
time (& t1); /* current build time */ time (& t1); /* current build time */
t1_tm = gmtime (& t1); t1_tm = gmtime (& t1);
#ifdef DBG
tm_dump ("t1", t1_tm);
#endif
t1_tm->tm_year += 1900; t1_tm->tm_year += 1900;
#ifdef DBG
tm_dump ("t1", t1_tm);
#endif
if (! quiet) if (! quiet)
{ {
printf ( printf (
"Current date: %4d-%02d-%02d\n\n", "Current date: %4d-%02d-%02d\n\n",
t1_tm->tm_year, t1_tm->tm_year,
(t1_tm->tm_mon + 1), (t1_tm->tm_mon + 1),
t1_tm->tm_mday t1_tm->tm_mday);
);
} }
/* /*
* Compute build number. * Compute build number.
*/ */
build = t1_tm->tm_year * 10000 + (t1_tm->tm_mon + 1) * 100 + t1_tm->tm_mday; build = t1_tm->tm_year * 10000 + (t1_tm->tm_mon + 1) * 100 + t1_tm->tm_mday;
sprintf(buildstr, "%d-r%s", build, GetRev()); sprintf(buildstr, "%d-r%s", build, GetRev());
@ -393,18 +367,14 @@ main (int argc, char * argv [])
printf ( printf (
"ROS Version : %d.%d", "ROS Version : %d.%d",
KERNEL_VERSION_MAJOR, KERNEL_VERSION_MAJOR,
KERNEL_VERSION_MINOR KERNEL_VERSION_MINOR);
);
if (0 != KERNEL_VERSION_PATCH_LEVEL) if (0 != KERNEL_VERSION_PATCH_LEVEL)
{ {
printf(".%d", KERNEL_VERSION_PATCH_LEVEL); printf(".%d", KERNEL_VERSION_PATCH_LEVEL);
} }
printf("-%s (Build %s)\n\n", kernel_version_build_type, buildstr); printf("-%s (Build %s)\n\n", kernel_version_build_type, buildstr);
} }
/* /* (Over)write the include file, unless the user switched on -p. */
* (Over)write the include file, unless
* the user switched on -p.
*/
if (! print_only) if (! print_only)
{ {
write_h (build, buildstr); write_h (build, buildstr);
@ -419,5 +389,4 @@ main (int argc, char * argv [])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* EOF */ /* EOF */