Added some checks for the config.h inclusion rules in the Wine tree.
This commit is contained in:
parent
bb133bd596
commit
ffca0d6128
|
@ -25,6 +25,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
@ -70,6 +71,19 @@ static const char Usage[] =
|
||||||
" -sxxx Use 'xxx' as separator (default: \"### Dependencies\")\n";
|
" -sxxx Use 'xxx' as separator (default: \"### Dependencies\")\n";
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************
|
||||||
|
* fatal_error
|
||||||
|
*/
|
||||||
|
static void fatal_error( const char *msg, ... )
|
||||||
|
{
|
||||||
|
va_list valist;
|
||||||
|
va_start( valist, msg );
|
||||||
|
vfprintf( stderr, msg, valist );
|
||||||
|
va_end( valist );
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
* xmalloc
|
* xmalloc
|
||||||
*/
|
*/
|
||||||
|
@ -77,10 +91,7 @@ static void *xmalloc( int size )
|
||||||
{
|
{
|
||||||
void *res;
|
void *res;
|
||||||
if (!(res = malloc (size ? size : 1)))
|
if (!(res = malloc (size ? size : 1)))
|
||||||
{
|
fatal_error( "%s: Virtual memory exhausted.\n", ProgramName );
|
||||||
fprintf( stderr, "%s: Virtual memory exhausted.\n", ProgramName );
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +102,7 @@ static void *xmalloc( int size )
|
||||||
static char *xstrdup( const char *str )
|
static char *xstrdup( const char *str )
|
||||||
{
|
{
|
||||||
char *res = strdup( str );
|
char *res = strdup( str );
|
||||||
if (!res)
|
if (!res) fatal_error( "%s: Virtual memory exhausted.\n", ProgramName );
|
||||||
{
|
|
||||||
fprintf( stderr, "%s: Virtual memory exhausted.\n", ProgramName );
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,14 +176,42 @@ static INCL_FILE *add_src_file( const char *name )
|
||||||
static INCL_FILE *add_include( INCL_FILE *pFile, const char *name, int line, int system )
|
static INCL_FILE *add_include( INCL_FILE *pFile, const char *name, int line, int system )
|
||||||
{
|
{
|
||||||
INCL_FILE **p = &firstInclude;
|
INCL_FILE **p = &firstInclude;
|
||||||
|
char *ext;
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
for (pos = 0; pos < MAX_INCLUDES; pos++) if (!pFile->files[pos]) break;
|
for (pos = 0; pos < MAX_INCLUDES; pos++) if (!pFile->files[pos]) break;
|
||||||
if (pos >= MAX_INCLUDES)
|
if (pos >= MAX_INCLUDES)
|
||||||
|
fatal_error( "%s: %s: too many included files, please fix MAX_INCLUDES\n",
|
||||||
|
ProgramName, pFile->name );
|
||||||
|
|
||||||
|
/* enforce some rules for the Wine tree */
|
||||||
|
|
||||||
|
if (!memcmp( name, "../", 3 ))
|
||||||
|
fatal_error( "%s:%d: #include directive with relative path not allowed\n",
|
||||||
|
pFile->filename, line );
|
||||||
|
|
||||||
|
if (!strcmp( name, "config.h" ))
|
||||||
{
|
{
|
||||||
fprintf( stderr, "%s: %s: too many included files, please fix MAX_INCLUDES\n",
|
if ((ext = strrchr( pFile->filename, '.' )) && !strcmp( ext, ".h" ))
|
||||||
ProgramName, pFile->name );
|
fatal_error( "%s:%d: config.h must not be included by a header file\n",
|
||||||
exit(1);
|
pFile->filename, line );
|
||||||
|
if (pos)
|
||||||
|
fatal_error( "%s:%d: config.h must be included before anything else\n",
|
||||||
|
pFile->filename, line );
|
||||||
|
}
|
||||||
|
else if (!strcmp( name, "wine/port.h" ))
|
||||||
|
{
|
||||||
|
if ((ext = strrchr( pFile->filename, '.' )) && !strcmp( ext, ".h" ))
|
||||||
|
fatal_error( "%s:%d: wine/port.h must not be included by a header file\n",
|
||||||
|
pFile->filename, line );
|
||||||
|
if (!pos) fatal_error( "%s:%d: config.h must be included before wine/port.h\n",
|
||||||
|
pFile->filename, line );
|
||||||
|
if (pos > 1)
|
||||||
|
fatal_error( "%s:%d: wine/port.h must be included before everything except config.h\n",
|
||||||
|
pFile->filename, line );
|
||||||
|
if (strcmp( pFile->files[0]->name, "config.h" ))
|
||||||
|
fatal_error( "%s:%d: config.h must be included before wine/port.h\n",
|
||||||
|
pFile->filename, line );
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*p && strcmp( name, (*p)->name )) p = &(*p)->next;
|
while (*p && strcmp( name, (*p)->name )) p = &(*p)->next;
|
||||||
|
@ -317,12 +352,8 @@ static void parse_idl_file( INCL_FILE *pFile, FILE *file )
|
||||||
if (quote == '<') quote = '>';
|
if (quote == '<') quote = '>';
|
||||||
include = p;
|
include = p;
|
||||||
while (*p && (*p != quote)) p++;
|
while (*p && (*p != quote)) p++;
|
||||||
if (!*p)
|
if (!*p) fatal_error( "%s:%d: Malformed #include or import directive\n",
|
||||||
{
|
pFile->filename, line );
|
||||||
fprintf( stderr, "%s:%d: Malformed #include or import directive\n",
|
|
||||||
pFile->filename, line );
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
*p = 0;
|
*p = 0;
|
||||||
add_include( pFile, include, line, (quote == '>') );
|
add_include( pFile, include, line, (quote == '>') );
|
||||||
}
|
}
|
||||||
|
@ -353,12 +384,8 @@ static void parse_c_file( INCL_FILE *pFile, FILE *file )
|
||||||
if (quote == '<') quote = '>';
|
if (quote == '<') quote = '>';
|
||||||
include = p;
|
include = p;
|
||||||
while (*p && (*p != quote)) p++;
|
while (*p && (*p != quote)) p++;
|
||||||
if (!*p)
|
if (!*p) fatal_error( "%s:%d: Malformed #include directive\n",
|
||||||
{
|
pFile->filename, line );
|
||||||
fprintf( stderr, "%s:%d: Malformed #include directive\n",
|
|
||||||
pFile->filename, line );
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
*p = 0;
|
*p = 0;
|
||||||
add_include( pFile, include, line, (quote == '>') );
|
add_include( pFile, include, line, (quote == '>') );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue