Commit f25c4d47 authored by Alexandre Julliard's avatar Alexandre Julliard

makedep: Convert to standard Wine lists.

parent 2afa6020
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "wine/port.h" #include "wine/port.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -30,13 +31,14 @@ ...@@ -30,13 +31,14 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#include "wine/list.h"
/* Max first-level includes per file */ /* Max first-level includes per file */
#define MAX_INCLUDES 200 #define MAX_INCLUDES 200
typedef struct _INCL_FILE typedef struct _INCL_FILE
{ {
struct _INCL_FILE *next; struct list entry;
char *name; char *name;
char *filename; char *filename;
struct _INCL_FILE *included_by; /* file that included this one */ struct _INCL_FILE *included_by; /* file that included this one */
...@@ -46,16 +48,16 @@ typedef struct _INCL_FILE ...@@ -46,16 +48,16 @@ typedef struct _INCL_FILE
struct _INCL_FILE *files[MAX_INCLUDES]; struct _INCL_FILE *files[MAX_INCLUDES];
} INCL_FILE; } INCL_FILE;
static INCL_FILE *firstSrc; static struct list sources = LIST_INIT(sources);
static INCL_FILE *firstInclude; static struct list includes = LIST_INIT(includes);
typedef struct _INCL_PATH typedef struct _INCL_PATH
{ {
struct _INCL_PATH *next; struct list entry;
const char *name; const char *name;
} INCL_PATH; } INCL_PATH;
static INCL_PATH *firstPath; static struct list paths = LIST_INIT(paths);
static const char *SrcDir = NULL; static const char *SrcDir = NULL;
static const char *OutputFileName = "Makefile"; static const char *OutputFileName = "Makefile";
...@@ -143,10 +145,7 @@ static int is_generated( const char *name ) ...@@ -143,10 +145,7 @@ static int is_generated( const char *name )
static void add_include_path( const char *name ) static void add_include_path( const char *name )
{ {
INCL_PATH *path = xmalloc( sizeof(*path) ); INCL_PATH *path = xmalloc( sizeof(*path) );
INCL_PATH **p = &firstPath; list_add_tail( &paths, &path->entry );
while (*p) p = &(*p)->next;
*p = path;
path->next = NULL;
path->name = name; path->name = name;
} }
...@@ -158,12 +157,10 @@ static void add_include_path( const char *name ) ...@@ -158,12 +157,10 @@ static void add_include_path( const char *name )
*/ */
static INCL_FILE *add_src_file( const char *name ) static INCL_FILE *add_src_file( const char *name )
{ {
INCL_FILE **p = &firstSrc;
INCL_FILE *file = xmalloc( sizeof(*file) ); INCL_FILE *file = xmalloc( sizeof(*file) );
memset( file, 0, sizeof(*file) ); memset( file, 0, sizeof(*file) );
file->name = xstrdup(name); file->name = xstrdup(name);
while (*p) p = &(*p)->next; list_add_tail( &sources, &file->entry );
*p = file;
return file; return file;
} }
...@@ -175,7 +172,7 @@ static INCL_FILE *add_src_file( const char *name ) ...@@ -175,7 +172,7 @@ 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 *include;
char *ext; char *ext;
int pos; int pos;
...@@ -214,18 +211,19 @@ static INCL_FILE *add_include( INCL_FILE *pFile, const char *name, int line, int ...@@ -214,18 +211,19 @@ static INCL_FILE *add_include( INCL_FILE *pFile, const char *name, int line, int
pFile->filename, line ); pFile->filename, line );
} }
while (*p && strcmp( name, (*p)->name )) p = &(*p)->next; LIST_FOR_EACH_ENTRY( include, &includes, INCL_FILE, entry )
if (!*p) if (!strcmp( name, include->name )) goto found;
{
*p = xmalloc( sizeof(INCL_FILE) ); include = xmalloc( sizeof(INCL_FILE) );
memset( *p, 0, sizeof(INCL_FILE) ); memset( include, 0, sizeof(INCL_FILE) );
(*p)->name = xstrdup(name); include->name = xstrdup(name);
(*p)->included_by = pFile; include->included_by = pFile;
(*p)->included_line = line; include->included_line = line;
(*p)->system = system || pFile->system; include->system = system || pFile->system;
} list_add_tail( &includes, &include->entry );
pFile->files[pos] = *p; found:
return *p; pFile->files[pos] = include;
return include;
} }
...@@ -268,7 +266,9 @@ static FILE *open_include_file( INCL_FILE *pFile ) ...@@ -268,7 +266,9 @@ static FILE *open_include_file( INCL_FILE *pFile )
FILE *file = NULL; FILE *file = NULL;
INCL_PATH *path; INCL_PATH *path;
for (path = firstPath; path; path = path->next) errno = ENOENT;
LIST_FOR_EACH_ENTRY( path, &paths, INCL_PATH, entry )
{ {
char *filename = xmalloc(strlen(path->name) + strlen(pFile->name) + 2); char *filename = xmalloc(strlen(path->name) + strlen(pFile->name) + 2);
strcpy( filename, path->name ); strcpy( filename, path->name );
...@@ -301,9 +301,7 @@ static FILE *open_include_file( INCL_FILE *pFile ) ...@@ -301,9 +301,7 @@ static FILE *open_include_file( INCL_FILE *pFile )
if (!file) if (!file)
{ {
if (pFile->included_by->system) return NULL; /* ignore if included by a system file */ if (pFile->included_by->system) return NULL; /* ignore if included by a system file */
if (firstPath) perror( pFile->name ); perror( pFile->name );
else fprintf( stderr, "%s: %s: File not found\n",
ProgramName, pFile->name );
while (pFile->included_by) while (pFile->included_by)
{ {
fprintf( stderr, " %s was first included from %s:%d\n", fprintf( stderr, " %s was first included from %s:%d\n",
...@@ -504,7 +502,7 @@ static void output_dependencies(void) ...@@ -504,7 +502,7 @@ static void output_dependencies(void)
exit(1); exit(1);
} }
} }
for( pFile = firstSrc; pFile; pFile = pFile->next) LIST_FOR_EACH_ENTRY( pFile, &sources, INCL_FILE, entry )
{ {
column = 0; column = 0;
output_src( file, pFile, &column ); output_src( file, pFile, &column );
...@@ -565,8 +563,7 @@ int main( int argc, char *argv[] ) ...@@ -565,8 +563,7 @@ int main( int argc, char *argv[] )
argc--; argc--;
argv++; argv++;
} }
for (pFile = firstInclude; pFile; pFile = pFile->next) LIST_FOR_EACH_ENTRY( pFile, &includes, INCL_FILE, entry ) parse_file( pFile, 0 );
parse_file( pFile, 0 ); if (!list_empty( &sources )) output_dependencies();
if( firstSrc ) output_dependencies();
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment